Camen Design Forum

Image / Video Support

append delete k1ngp1n

Can anyone help with adding in image and video support?

Reply RSS

Replies

append delete #1. tmyusuf

Where you adding video and image ?

append delete #2. k1ngp1n

Was thinking in *functions.php*.

%
/* inline formatting:
           -------------------------------------------------------------------------------------------------------------- */
        $text = preg_replace (
                //example: _italic_ & *bold*
                array ('/(?<=\s|^)_(?!_)(.*?)(?<!_)_(?=\s|$)/m',        '/(?<![*\w])\*(?!\*)(.*?)(?<!\*)\*(?![*\w])/'),
                array ('<em>_$1_</em>',                                 '<strong>*$1*</strong>'),
        $text);
%
append delete #3. Martijn

There is this code I wrote some time ago that you can use to extend your theme to add youtube videos and images to NNF:

http://forum.camendesign.com/embedd_youtube_videos_+1#24b46l14pukd

append delete #4. k1ngp1n

@Martijn

Worked!

Just replace with:

%
function theme_custom ($template) {
        $template->set (array (
                //metadata for IE9+ pinned-sites: <msdn.microsoft.com/library/gg131029>
                //application title (= forum / sub-forum name):
                '//meta[@name="application-name"]/@content'          => SUBFORUM ? SUBFORUM : FORUM_NAME,
                //application URL (where the pinned site opens at)
                '//meta[@name="msapplication-starturl"]/@content'    => FORUM_URL.url (PATH_URL),
                //pinned site / metro colour to use
                '//meta[@name="msapplication-navbutton-color"]/@content, //meta[@name="msapplication-TileColor"]/@content'
                                                                     => METRO_COLOUR, 
                //set the site logo
                'img#nnf_logo@src'                                   => FORUM_PATH.'themes/'.FORUM_THEME.'/img/'.THEME_LOGO,
                
                //set the forum URL for Google search-by-site
                '//input[@name="as_sitesearch"]/@value'              => $_SERVER['HTTP_HOST'],
                //if you're using a Google search, change it to HTTPS if enforced
                '//form[@action="http://google.com/search"]/@action' => FORUM_HTTPS ? 'https://encrypted.google.com/search'
                                                                                    : 'http://google.com/search'
        ));

        foreach ($template->query('//article/div/p[a and count(*)=1 and not(normalize-space(text()))]') as $node) {
        $link = trim($node->nodeValue);
        $replace = false;

        if (
            preg_match('~(?:
                https?://(?:www\.)?youtu(?:be\.com/(?:embed/|watch\?(?:.+&)?v=)|\.be/)([a-z0-9_\-]+) # Parsing YouTube URLs.
                |
                (.+\.(?:png|jpe?g|gif)) # Parsing image URLs.
            )~ixA', $link, $matches)
        ) {
            if (strlen($matches[1])) { // We found a YouTube video.
                $replace = '<iframe width="480" height="360" src="http://www.youtube-nocookie.com/embed/' . $matches[1] . '?autoplay=0&amp;rel=0" frameborder="0" allowfullscreen="allowfullscreen">' . safeHTML($link) . '</iframe>';
            } else if (strlen($matches[2])) { // We found an image link.
                $replace = '<a href="' . safeHTML($link) . '"><img src="' . $matches[2] . '" alt="' . safeHTML($link) . '" /></a>';
            }
        }

        if ($replace) {
            $frag = $node->ownerDocument->createDocumentFragment();
            if (!@$frag->appendXML($replace) || !@$node->parentNode->replaceChild($frag, $node)) {
                throw new Exception("Invalid HTML");
            }
        }
    }
}
%

Reply

(Leave this as-is, it’s a trap!)

There is no need to “register”, just enter the same name + password of your choice every time.

Pro tip: Use markup to add links, quotes and more.

Your friendly neighbourhood moderators: Kroc, Impressed, Martijn