public static function handle_shortcode($arguments, $url, $parser, $shortcode)
 {
     // get all registered cdn things, and see if any of them have URLs that
     // need to be handled by US, instead of looked up. _if_ we need to handle it,
     // perform relevant transforms etc.
     $contentService = singleton('ContentService');
     /* @var $contentService ContentService */
     $cdns = $contentService->getStoreTypes();
     foreach ($cdns as $name => $types) {
         $reader = $contentService->getReader($name);
         if ($actualReader = $reader->providerOfUrl($url)) {
             if ($actualReader instanceof ContentReader) {
                 $contentId = $actualReader->getContentId();
                 $file = File::get()->filter('CDNFile', $contentId)->first();
                 if ($file) {
                     if ($file instanceof Image && isset($arguments['width']) && isset($arguments['height'])) {
                         // return the formatted image
                         $cached = $file->ResizedImage($arguments['width'], $arguments['height']);
                         if ($cached) {
                             return $cached->forTemplate();
                         }
                     }
                 }
             }
         }
     }
     return parent::handle_shortcode($arguments, $url, $parser, $shortcode);
 }
 public function update(SS_HTTPRequest $request)
 {
     if (!SecurityToken::inst()->checkRequest($request)) {
         return '';
     }
     $url = $request->postVar('URL');
     if (strlen($url)) {
         $info = Oembed::get_oembed_from_url($url);
         $info = Embed\Embed::create($url);
         if ($info) {
             $object = EmbeddedObject::create();
             $object->setFromEmbed($info);
             $this->object = $object;
             // needed to make sure the check in FieldHolder works out
             $object->ID = -1;
             return $this->FieldHolder();
         } else {
             $this->message = _t('EmbeddedObjectField.ERROR', 'Could not look up provided URL: ' . Convert::raw2xml($url));
             return $this->FieldHolder();
         }
     } else {
         $this->object = null;
         return $this->FieldHolder();
     }
 }
 public function testRequestProtocolReflectedInGetOembedFromUrl()
 {
     Config::inst()->update('Oembed', 'providers', array('http://*.silverstripe.com/watch*' => array('http' => 'http://www.silverstripe.com/oembed/', 'https' => 'https://www.silverstripe.com/oembed/?scheme=https'), 'https://*.silverstripe.com/watch*' => array('http' => 'http://www.silverstripe.com/oembed/', 'https' => 'https://www.silverstripe.com/oembed/?scheme=https')));
     Config::inst()->update('Director', 'alternate_protocol', 'http');
     foreach (array('http', 'https') as $protocol) {
         $url = $protocol . '://www.silverstripe.com/watch12345';
         $result = Oembed::get_oembed_from_url($url);
         $this->assertInstanceOf('Oembed_Result', $result);
         $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url=' . urlencode($url), 'Returns http based URLs when request is over http, regardless of source URL');
     }
     Config::inst()->update('Director', 'alternate_protocol', 'https');
     foreach (array('http', 'https') as $protocol) {
         $url = $protocol . '://www.silverstripe.com/watch12345';
         $result = Oembed::get_oembed_from_url($url);
         $this->assertInstanceOf('Oembed_Result', $result);
         $this->assertEquals($result->getOembedURL(), 'https://www.silverstripe.com/oembed/?scheme=https&format=json&url=' . urlencode($url), 'Returns https based URLs when request is over https, regardless of source URL');
     }
     Config::inst()->update('Director', 'alternate_protocol', 'foo');
     foreach (array('http', 'https') as $protocol) {
         $url = $protocol . '://www.silverstripe.com/watch12345';
         $result = Oembed::get_oembed_from_url($url);
         $this->assertInstanceOf('Oembed_Result', $result);
         $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url=' . urlencode($url), 'When request protocol doesn\'t have specific handler, fall back to first option');
     }
 }
 /**
  * Convert a single URL, assumes $url has been verified to be 
  * a real URL
  * 
  * @param string $url 
  */
 public function convertUrl($url)
 {
     $oembed = Oembed::get_oembed_from_url($url, false, $this->oembedOptions);
     if ($oembed) {
         return array('Title' => '', 'Content' => $oembed->forTemplate());
     }
     $graph = OpenGraph::fetch($url);
     if ($graph) {
         foreach ($graph as $key => $value) {
             $data[$key] = Varchar::create_field('Varchar', $value);
         }
         if (isset($data['url'])) {
             return array('Title' => $graph->Title, 'Content' => MicroPost::create()->customise($data)->renderWith('OpenGraphPost'));
         }
     }
     // get the post and take its <title> tag at the very least
     $service = new RestfulService($url);
     $response = $service->request();
     if ($response && $response->getStatusCode() == 200) {
         if (preg_match('/<title>(.*?)<\\/title>/is', $response->getBody(), $matches)) {
             $title = Convert::raw2xml(trim($matches[1]));
             return array('Title' => $title, 'Content' => "<a href='{$url}'>{$title}</a>");
         }
     }
 }
 public function update(SS_HTTPRequest $request)
 {
     if (!SecurityToken::inst()->checkRequest($request)) {
         return '';
     }
     $url = $request->postVar('URL');
     if (strlen($url)) {
         $info = Oembed::get_oembed_from_url($url);
         if ($info && $info->exists()) {
             $object = EmbeddedObject::create();
             $object->Title = $info->title;
             $object->SourceURL = $url;
             $object->Width = $info->width;
             $object->Height = $info->height;
             $object->ThumbURL = $info->thumbnail_url;
             $object->Description = $info->description ? $info->description : $info->title;
             $object->Type = $info->type;
             $object->EmbedHTML = $info->forTemplate();
             $this->object = $object;
             // needed to make sure the check in FieldHolder works out
             $object->ID = -1;
             return $this->FieldHolder();
         } else {
             $this->message = _t('EmbeddedObjectField.ERROR', 'Could not look up provided URL: ' . Convert::raw2xml($url));
             return $this->FieldHolder();
         }
     } else {
         $this->object = null;
         return $this->FieldHolder();
     }
 }
 public function updateEmbedHTML()
 {
     $options = array('width' => $this->Width, 'height' => $this->Height);
     $info = Oembed::get_oembed_from_url($this->SourceURL, false, $options);
     if ($info && $info->exists()) {
         $this->EmbedHTML = $info->forTemplate();
     }
 }
 public static function handle_shortcode($arguments, $url, $parser, $shortcode)
 {
     $result = false;
     if (Director::is_site_url($url) && VideoEmbed::GetByURL($url)) {
         $result = VideoEmbed::GetByURL($url)->forTemplate();
     } else {
         $result = parent::handle_shortcode($arguments, $url, $parser, $shortcode);
     }
     return $result;
 }
 public function GetOembedData(SS_HTTPRequest $request)
 {
     $response = "{}";
     $this->getResponse()->addHeader("Content-Type", "application/json; charset=utf-8");
     $url = $request->postVar('url') ? $request->postVar('url') : $request->getVar("mediaurl");
     if (Director::is_site_url($url) && VideoEmbed::GetByURL($url)) {
         $video = VideoEmbed::GetByURL($url);
         $response = $video->GetOembedJson();
     } else {
         $oembed = Oembed::get_oembed_from_url($url);
         if ($oembed && $oembed->exists()) {
             $response = $oembed->toJson();
         }
     }
     echo $response;
 }
Example #9
0
 function testGetOembedFromUrl()
 {
     Config::inst()->update('Oembed', 'providers', array('http://*.silverstripe.com/watch*' => 'http://www.silverstripe.com/oembed/'));
     $escapedEndpointURL = urlencode("http://www.silverstripe.com/oembed/");
     // Test with valid URL
     $result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345');
     $this->assertTrue($result != false);
     $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url=' . urlencode('http://www.silverstripe.com/watch12345'), 'Triggers on matching URL');
     // Test without www.
     $result = Oembed::get_oembed_from_url('http://silverstripe.com/watch12345');
     $this->assertTrue($result != false);
     $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url=' . urlencode('http://silverstripe.com/watch12345'), 'Triggers on matching URL without www');
     // Test if options make their way to the URL
     $result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345', false, array('foo' => 'bar'));
     $this->assertTrue($result != false);
     $this->assertEquals($result->getOembedURL(), 'http://www.silverstripe.com/oembed/?format=json&url=' . urlencode('http://www.silverstripe.com/watch12345') . '&foo=bar', 'Includes options');
     // Test magic.
     $result = Oembed::get_oembed_from_url('http://www.silverstripe.com/watch12345', false, array('height' => 'foo', 'width' => 'bar'));
     $this->assertTrue($result != false);
     $urlParts = parse_url($result->getOembedURL());
     parse_str($urlParts['query'], $query);
     $this->assertEquals($query['maxheight'], 'foo', 'Magically creates maxheight option');
     $this->assertEquals($query['maxwidth'], 'bar', 'Magically creates maxwidth option');
 }
 public function __construct($url, File $file = null)
 {
     parent::__construct($url, $file);
     $this->oembed = Oembed::get_oembed_from_url($url);
     if (!$this->oembed) {
         $controller = Controller::curr();
         $response = $controller->getResponse();
         $response->addHeader('X-Status', rawurlencode(_t('HtmlEditorField.URLNOTANOEMBEDRESOURCE', "The URL '{url}' could not be turned into a media resource.", "The given URL is not a valid Oembed resource; the embed element couldn't be created.", array('url' => $url))));
         $response->setStatusCode(404);
         throw new SS_HTTPResponse_Exception($response);
     }
 }
 /**
  * Get the embedded media
  * @return false|Oembed_Result
  */
 public function Media()
 {
     if ($this->ExternalMedia) {
         return Oembed::get_oembed_from_url($this->ExternalMedia, false, array('color' => Config::inst()->get('VideoBlock', 'player_color'), 'title' => false, 'portrait' => false, 'byline' => false, 'loop' => false));
     }
     return false;
 }
Example #12
0
 protected function setFromEmbed(&$post)
 {
     if (!isset($post['Link'])) {
         return;
     }
     $cacheKey = $this->getCacheKey(['embed' => $post['Link']]);
     if (!($record = unserialize($this->cache()->load($cacheKey)))) {
         $record = [];
         if (class_exists('Embed\\Embed')) {
             $info = \Embed\Embed::create($post['Link']);
             $record['ObjectName'] = $info->getTitle();
             $record['ObjectURL'] = $info->getUrl();
             $record['ObjectWidth'] = $info->getWidth();
             $record['ObjectHeight'] = $info->getHeight();
             $record['ObjectThumbnail'] = $info->getImage();
             $record['ObjectDescription'] = $info->getDescription();
             $record['ObjectType'] = $info->getType();
             $record['ObjectEmbed'] = $info->getCode();
         } else {
             if ($info = \Oembed::get_oembed_from_url($post['Link'])) {
                 if ($info->hasField('title')) {
                     $record['ObjectName'] = $info->getField('title');
                 }
                 if ($info->hasField('url')) {
                     $record['ObjectURL'] = $info->getField('url');
                 }
                 if ($info->hasField('width')) {
                     $record['ObjectWidth'] = $info->getField('width');
                 }
                 if ($info->hasField('height')) {
                     $record['ObjectHeight'] = $info->getField('height');
                 }
                 if ($info->hasField('thumbnail')) {
                     $record['ObjectThumbnail'] = $info->getField('thumbnail');
                 }
                 if ($info->hasField('description')) {
                     $record['ObjectDescription'] = $this->textParser()->text($info->getField('description'));
                 }
                 if ($info->hasField('type')) {
                     $record['ObjectType'] = $info->getField('type');
                 }
                 $record['ObjectEmbed'] = $info->forTemplate();
             }
         }
         $this->cache()->save(serialize($record), $cacheKey);
     }
     foreach ($record as $key => $value) {
         $post[$key] = $value;
     }
 }
Example #13
0
        echo '<iframe class="twitter-tweet" src="http://twitframe.com/show?url=', urlencode('https://twitter.com/PerezHilton/status/671731077539467265'), '" frameborder="0" width="500" height="720"></iframe>';
        echo '<iframe class="twitter-tweet" src="http://twitframe.com/show?url=', urlencode('https://twitter.com/ANZStadium/status/670454514302906368'), '" frameborder="0" width="500" height="720"></iframe>';
        // echo '<iframe class="tumblr-post" src="https://embed.tumblr.com/embed/post/zPM4x6zcKnJ2mnCWD5dCDQ/131627658976" frameborder="0" width="500" height="720"></iframe>';
        // echo '<iframe class="tumblr-post" src="https://embed.tumblr.com/embed/post/zPM4x6zcKnJ2mnCWD5dCDQ/134872428806" frameborder="0" width="500" height="860"></iframe>';
        // echo '<iframe class="tumblr-post" src="https://embed.tumblr.com/embed/post/zPM4x6zcKnJ2mnCWD5dCDQ/133871813361" frameborder="0" width="500" height="860"></iframe>';
        // echo '<iframe class="tumblr-post" src="https://embed.tumblr.com/embed/post/hxYiedm7s4mX7u4CMyi0aQ/134926222738" frameborder="0" width="500" height="720"></iframe>';
        echo '<iframe class="tumblr-post" src="https://embed.tumblr.com/embed/post/qU9WMukWE04hIZ9JMlCqDg/134948244742" frameborder="0" width="500" height="720"></iframe>';
        echo '<blockquote class="twitter-tweet"><p lang="en" dir="ltr"><a href="https://twitter.com/hashtag/TaylorSwift?src=hash">#TaylorSwift</a> singing <a href="https://twitter.com/hashtag/LoveStory?src=hash">#LoveStory</a> <a href="https://twitter.com/hashtag/voguegoldenticket?src=hash">#voguegoldenticket</a> <a href="https://twitter.com/hashtag/voguexsamsung?src=hash">#voguexsamsung</a> <a href="https://twitter.com/SamsungAU">@samsungau</a> <a href="https://t.co/sel85IZ1Ev">pic.twitter.com/sel85IZ1Ev</a></p>&mdash; Vogue Australia (@vogueaustralia) <a href="https://twitter.com/vogueaustralia/status/670555453898645504">November 28, 2015</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>';
        echo '<blockquote class="twitter-tweet"><p lang="en" dir="ltr"><a href="https://twitter.com/hashtag/TaylorSwift?src=hash">#TaylorSwift</a> isn&#39;t the only celeb with awkward dance moves, and we&#39;ve got the proof!! <a href="https://t.co/dxyFmdRyw3">https://t.co/dxyFmdRyw3</a> <a href="https://t.co/bhx40OMiyp">pic.twitter.com/bhx40OMiyp</a></p>&mdash; Perez Hilton (@PerezHilton) <a href="https://twitter.com/PerezHilton/status/671731077539467265">December 1, 2015</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>';
        echo '<blockquote class="twitter-tweet"><p lang="en" dir="ltr">SO many awesome outfits already on display <a href="https://twitter.com/ANZStadium">@ANZStadium</a>! Swifties are the best! <a href="https://twitter.com/hashtag/1989TourSydney?src=hash">#1989TourSydney</a> <a href="https://twitter.com/hashtag/TaylorSwift?src=hash">#TaylorSwift</a> <a href="https://t.co/Wnz9wsjFDw">pic.twitter.com/Wnz9wsjFDw</a></p>&mdash; ANZ Stadium (@ANZStadium) <a href="https://twitter.com/ANZStadium/status/670454514302906368">November 28, 2015</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>';
        echo '<br>';
        return 'oembed/oscarotero';
    });
    /**
     * Registers the GET route to the jooorooo/oembed package test page.
     */
    Route::get('/oembed/jooorooo', function () {
        $info = Oembed::cache('https://twitter.com/vogueaustralia/statuses/670555453898645504', []);
        echo $info->code;
        $info = Oembed::cache('https://twitter.com/PerezHilton/statuses/671731077539467265', []);
        echo $info->code;
        $info = Oembed::cache('https://twitter.com/ANZStadium/statuses/670454514302906368', []);
        echo $info->code;
        $info = Oembed::cache('https://www.instagram.com/p/9h8POJjvB2/', []);
        echo $info->code;
        $info = Oembed::cache('https://www.instagram.com/p/9h8em8jvCQ/', []);
        echo $info->code;
        echo '<br>';
        return 'oembed/jooorooo';
    });
}
 /**
  *
  * @returns Oembed_Result/bool An Oembed descriptor, or false
  */
 public function GetOembed()
 {
     $res = false;
     if ($this->Type !== 'HTML 5/Flash' && $this->GetUrl()) {
         $options = array();
         if ($this->getWidth()) {
             $options['width'] = $this->getWidth();
         }
         if ($this->getHeight()) {
             $options['height'] = $this->getHeight();
         }
         $options['autoplay'] = $this->getAutoPlay() ? 1 : 0;
         $res = Oembed::get_oembed_from_url($this->GetSettings()->url, false, $options);
     } else {
         $res = new Oembed_Result($this->GetUrl());
         $refObject = new ReflectionObject($res);
         $refProperty = $refObject->getProperty('data');
         $refProperty->setAccessible(true);
         $refProperty->setValue($res, Convert::json2array($this->GetOembedJson()));
         //    }
     }
     return $res;
 }