コード例 #1
0
 public function testDontReplaceInsideDefaultTags()
 {
     $expected = array('<a href="http://youtu.be/fSUK4WgQ3vk" title="">http://youtu.be/fSUK4WgQ3vk</a>', '<iframe width="420" height="315" src="//www.youtube.com/embed/fSUK4WgQ3vk" frameborder="0" allowfullscreen></iframe>', '<a href="http://youtu.be/fSUK4WgQ3vk">other link</a>', '<img src="http://youtu.be/fSUK4WgQ3vk" alt="" />', '<iframe width="420" height="315" src="//www.youtube.com/embed/fSUK4WgQ3vk" frameborder="0" allowfullscreen></iframe>', '<img src="http://youtu.be/fSUK4WgQ3vk" title="">', '<pre>My   House http://youtu.be/fSUK4WgQ3vk   </pre>', '<code>http://youtu.be/fSUK4WgQ3vk</code>');
     $data = array('<a href="http://youtu.be/fSUK4WgQ3vk" title="">http://youtu.be/fSUK4WgQ3vk</a>', 'http://youtu.be/fSUK4WgQ3vk', '<a href="http://youtu.be/fSUK4WgQ3vk">other link</a>', '<img src="http://youtu.be/fSUK4WgQ3vk" alt="" />', 'http://youtu.be/fSUK4WgQ3vk', '<img src="http://youtu.be/fSUK4WgQ3vk" title="">', '<pre>My   House http://youtu.be/fSUK4WgQ3vk   </pre>', '<code>http://youtu.be/fSUK4WgQ3vk</code>');
     $embera = new \Embera\Embera(array('oembed' => false));
     $result = $embera->autoEmbed(implode(', ', $data));
     $this->assertEquals($result, implode(', ', $expected));
 }
コード例 #2
0
 public function doEmbedToText()
 {
     $text = \Input::get('text');
     $config = array('params' => array('width' => 640, 'height' => 360));
     $embera = new \Embera\Embera($config);
     $res = $embera->autoEmbed($text);
     $info = array('status' => true, 'html' => $res);
     return \Response::json($info);
 }
コード例 #3
0
ファイル: Embed.php プロジェクト: solverat/pimcore
 /**
  * @see Document\Tag\TagInterface::frontend
  * @return string
  */
 public function frontend()
 {
     if ($this->url) {
         $config = $this->getOptions();
         if (!isset($config["params"])) {
             $config["params"] = [];
         }
         foreach (["width", "height"] as $property) {
             if (isset($config[$property])) {
                 $config["params"][$property] = $config[$property];
             }
         }
         $cacheKey = "doc_embed_" . crc32(serialize([$this->url, $config]));
         if (!($html = \Pimcore\Cache::load($cacheKey))) {
             $embera = new \Embera\Embera($config);
             $html = $embera->autoEmbed($this->url);
             \Pimcore\Cache::save($html, $cacheKey, ["embed"], 86400, 1, true);
         }
         return $html;
     }
     return "";
 }
コード例 #4
0
function automedia_run($message)
{
    global $db, $mybb, $cache, $automedia, $width, $height;
    // Spare myshoutbox
    if ($mybb->input['action'] == 'show_shouts' || $mybb->input['action'] == 'full_shoutbox' || THIS_SCRIPT == 'shoutbox.php' || THIS_SCRIPT == 'pspshoutbox.php' || isset($mybb->input['view_mode']) && $mybb->input['view_mode'] == 'window') {
        return;
    }
    /**
     * Get the settings for width and height
     **/
    $width = (int) $mybb->settings['av_width'];
    $height = (int) $mybb->settings['av_height'];
    if ($width < 10 || $width > 1200) {
        $width = "480";
    }
    if ($height < 10 || $height > 1000) {
        $height = "360";
    }
    // Add new MyCode for disabling embedding
    $message = preg_replace("#\\[amoff\\](<a href=\")(http://)(.*?)\" target=\"_blank\">(.*?)(</a>)\\[/amoff\\]#i", '<a class=\'amoff\' href=\'${2}${3}\' id= \'am\' target=\'_blank\'>${4}</a>', $message);
    $message = preg_replace("#\\[amoff\\](http://)(.*?)\\[/amoff\\]#i", '<a class=\'amoff\' href=\'${1}${2}\' id= \'am\' target=\'_blank\'>${1}${2}</a>', $message);
    // Handle [amquote] tags from older plugin versions
    $message = str_replace(array('[amquote]', '[/amquote]'), '', $message);
    /**
     * Apply the permissions
     **/
    /**
     * Get the settings for the forums
     **/
    if ($mybb->settings['av_forums'] != -1) {
        if ($mybb->settings['av_forums'] == '') {
            return;
        }
        global $fid;
        if (isset($fid)) {
            $avfid = (int) $fid;
        } else {
            $avfid = $mybb->get_input('fid', 1);
            if ($mybb->version > "1.8.0") {
                $avfid = $mybb->get_input('fid', MyBB::INPUT_INT);
            }
        }
        // Find the set fid's in settings
        $fids = explode(',', $mybb->settings['av_forums']);
        if (!in_array($avfid, $fids)) {
            return;
        }
    }
    /**
     *Get the settings for the usergroups
     **/
    // Find the excluded groups in settings
    if ($mybb->settings['av_groups'] != '' && $mybb->usergroup['cancp'] != 1) {
        if (is_member($mybb->settings['av_groups']) || $mybb->settings['av_groups'] == -1) {
            return;
        }
    }
    // AutoMedia not disabled in settings?
    if ($mybb->settings['av_enable'] != 0) {
        // Embedding disabled in quotes?
        if ($mybb->settings['av_quote'] != 1) {
            $message = preg_replace("#(<blockquote\\b[^>]*>(?>(?:[^<]++|<(?!\\/?blockquote\\b[^>]*>))+|(?R))*<\\/blockquote>)#isU", "<amquotes>\$1</amquotes>", $message);
            $noembedpattern = '#<amquotes>(.*?)<\\/amquotes>#si';
            $noembed = array();
            preg_match_all($noembedpattern, $message, $quotes);
            foreach ($quotes[1] as $quote) {
                $noembed[] = $quote;
            }
        }
        // Embedding not disabled by using MyCode?
        if (!preg_match('/<a class=\\"amoff\\" href=\\"(.*)\\" id=\\"am\\" target=\\"_blank\\">/isU', $message)) {
            // AutoMedia allowed for guests in settings or disabled in UCP?
            if ($mybb->user['uid'] != 0 && $mybb->user['automedia_use'] != 'N' || $mybb->user['uid'] == 0 && $mybb->settings['av_guest'] == 1) {
                /**
                 * Embed the files/providers not included in Embedly and Embera first
                 **/
                $sitecache = $cache->read('automedia');
                if (is_array($sitecache)) {
                    foreach ($sitecache as $key => $sites) {
                        if ($sites['class'] == "site") {
                            $site = htmlspecialchars_uni($sites['name']);
                            $file = MYBB_ROOT . "inc/plugins/automedia/mediasites/{$site}.php";
                            if (file_exists($file)) {
                                require_once $file;
                                $fctn = "automedia_" . $site;
                                $message = $fctn($message);
                            }
                        }
                    }
                }
                // Use the oEmbed API
                if (isset($mybb->settings['av_embera']) && $mybb->settings['av_embera'] == 1 && version_compare(PHP_VERSION, '5.3.0', '>=')) {
                    preg_match_all("/<a href=\"(https?:\\/\\/[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|\\/)))\" target/i", $message, $post_links);
                    $am_urls = $post_links[1];
                    if (!empty($am_urls)) {
                        // Blacklist sites e.g.: array('Instagram', 'Github') - if empty all providers are allowed
                        $denied_providers = array();
                        // Exclude non SSL providers for forums using HTTPS to avoid mixed content
                        if (automedia_secure()) {
                            $nohttps = array('FunnyOrDie', 'Hq23', 'Clyp', 'Dipity', 'Edocr', 'Hulu', 'MobyPicture', 'VideoFork', 'VideoJug', 'YFrog');
                            // Add the non SSL providers to blacklist
                            $denied_embed = array_merge($denied_providers, $nohttps);
                        } else {
                            $denied_embed = $denied_providers;
                        }
                        // Use the Embera library for embedding
                        require_once MYBB_ROOT . 'inc/plugins/automedia/Lib/Embera/Autoload.php';
                        $config = array('params' => array('width' => $width, 'height' => $height), 'fake' => array('width' => $width, 'height' => $height), 'deny' => $denied_embed);
                        $embera = new \Embera\Embera($config);
                        foreach ($am_urls as $am_url) {
                            // Embera embed
                            $embed_url = $embera->autoEmbed($am_url);
                            if ($embed_url != $am_url) {
                                // Force https embedding if forum uses SSL
                                if (automedia_secure()) {
                                    $embed_url = str_replace('src="http://', 'src="//', $embed_url);
                                }
                                $message = str_replace('<a href="' . $am_url . '" target="_blank">', '<!-- automedia_start --><div class="am_embed">' . $embed_url . '</div><!-- automedia_end -->', $message);
                                $message = preg_replace("#</div><!-- automedia_end -->(.*?)</a>#i", '</div><!-- automedia_end -->', $message);
                            }
                        }
                    }
                }
            }
            // Add embed css class to links for embed.ly embedding
            $message = str_replace("<a href=", '<a class=\'oembed\' href=', $message);
        }
        // Embedding disabled in quotes?
        if ($mybb->settings['av_quote'] != 1) {
            $noembedendpattern = '#<amquotes>(.*?)<\\/amquotes>#si';
            preg_match_all($noembedendpattern, $message, $endquotes);
            $i = 0;
            foreach ($endquotes[1] as $endquote) {
                $message = str_replace($endquote, $noembed[$i], $message);
                $i++;
            }
            $message = str_replace(array('<amquotes>', '</amquotes>'), '', $message);
        }
    }
    return $message;
}
コード例 #5
0
ファイル: TestEmbera.php プロジェクト: MarQuisKnox/Embera
 public function testReplaceOrderOnAutoEmbed()
 {
     $expected = array('<iframe width="420" height="315" src="//www.youtube.com/embed/fSUK4WgQ3vk" frameborder="0" allowfullscreen></iframe>', '<iframe width="420" height="315" src="//www.youtube.com/embed/fSUK4WgQ3vkIII" frameborder="0" allowfullscreen></iframe>', '<iframe width="420" height="315" src="//www.youtube.com/embed/fSUK4WgQ3vkII" frameborder="0" allowfullscreen></iframe>');
     $urls = array('http://youtu.be/fSUK4WgQ3vk', 'http://youtu.be/fSUK4WgQ3vkIII', 'http://youtu.be/fSUK4WgQ3vkII');
     $embera = new \Embera\Embera(array('oembed' => false));
     $result = $embera->autoEmbed(implode(', ', $urls));
     $this->assertEquals($result, implode(', ', $expected));
 }
コード例 #6
0
ファイル: TestEmbera.php プロジェクト: assembledadam/Embera
 public function testEmbedPrefixService()
 {
     $validUrls = array('embed://www.youtube.com/watch?v=MpVHQnIvTXo', 'http://youtu.be/fSUK4WgQ3vk', 'http://vimeo.com/groups/shortfilms/videos/63313811/', 'embed://www.dailymotion.com/video/xzxtaf_red-bull-400-alic-y-stadlober-ganan-en-eslovenia_sport/', 'embed://www.youtube.com/watch?v=T3O1nffTG-k');
     $embera = new \Embera\Embera(array('oembed' => false, 'use_embed_prefix' => false));
     $result = $embera->getUrlInfo($validUrls);
     $this->assertCount(2, $result);
     $embera = new \Embera\Embera(array('oembed' => false, 'use_embed_prefix' => true));
     $result = $embera->getUrlInfo($validUrls);
     $this->assertCount(3, $result);
 }