예제 #1
0
파일: ShortCut.php 프로젝트: sebardo/core
 public static function getOpenGraphData($url)
 {
     $returnValues = array();
     //obtengo los datos del enlace con su imagen titulo y descripcion haaa y la url
     $graph = OpenGraph::fetch($url);
     foreach ($graph as $key => $value) {
         switch ($key) {
             case 'title':
                 $returnValues['title'] = $value;
                 break;
             case 'description':
                 $returnValues['description'] = $value;
                 break;
             case 'site_name':
                 $returnValues['siteName'] = $value;
                 break;
             case 'image':
                 $returnValues['image'] = $value;
                 break;
         }
     }
     //Checking video link if youtube or vimeo
     $host = parse_url($url, PHP_URL_HOST);
     if ($host == 'vimeo.com') {
         $path = parse_url($url, PHP_URL_PATH);
         $clip_id = substr($path, 1);
         $returnValues['videoUrl'] = 'http://vimeo.com/moogaloop.swf?clip_id=' . $clip_id;
     }
     if ($host == 'www.youtube.com') {
         $query = parse_url($url, PHP_URL_QUERY);
         $v = explode("=", $query);
         $returnValues['videoUrl'] = 'http://www.youtube.com/v/' . $v[1] . '?version=3&autohide=1';
     }
     if ($host == 'youtu.be') {
         $path = parse_url($url, PHP_URL_PATH);
         $returnValues['videoUrl'] = 'http://www.youtube.com/v' . $path . '?version=3&autohide=1';
     }
     //veo si alguno de los campos esta vacio y mando la funcion con curl
     if (isset($returnValues['title']) && isset($returnValues['description']) && isset($returnValues['image']) && isset($returnValues['siteName'])) {
         return $returnValues;
     }
     $arr = OpenGraph::wget($url);
     if (!isset($returnValues['title'])) {
         $returnValues['title'] = $arr['title'];
     }
     if (!isset($returnValues['description'])) {
         $returnValues['description'] = $arr['description'];
     }
     if (!isset($returnValues['image'])) {
         $returnValues['image'] = $arr['og:image'];
     }
     if (!isset($returnValues['images'])) {
         $returnValues['images'] = $arr['images'][0];
     }
     return $returnValues;
 }