Changeset 19213


Ignore:
Timestamp:
11/28/12 12:49:06 (7 years ago)
Author:
mistic100
Message:
  • add safe mode
  • fix little error when adding video without thumbnail
Location:
extensions/gvideo
Files:
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • extensions/gvideo/admin/add.php

    r19056 r19213  
    1212    array_push($page['errors'], l10n('Please fill the video URL')); 
    1313  } 
    14   if ( !empty($_POST['url']) and ($video = parse_video_url($_POST['url'])) === false ) 
     14  if ( !empty($_POST['url']) and ($video = parse_video_url($_POST['url'], isset($_POST['safe_mode']))) === false ) 
    1515  { 
    16     array_push($page['errors'], l10n('Unable to contact host server')); 
     16    if (isset($_POST['safe_mode'])) 
     17    { 
     18      array_push($page['errors'], l10n('an error happened')); 
     19    } 
     20    else 
     21    { 
     22      array_push($page['errors'], l10n('Unable to contact host server')); 
     23      array_push($page['errors'], l10n('Try in safe-mode')); 
     24    } 
     25    $_POST['safe_mode'] = true; 
    1726  } 
    1827   
     
    2029  { 
    2130    // download thumbnail 
    22     $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.get_extension($video['thumbnail']); 
     31    $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); 
     32    $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; 
    2333    $thumb_source = $conf['data_location'].$thumb_name; 
    24     if (download_remote_file($video['thumbnail'], $thumb_source) !== true) 
     34    if ( empty($video['thumbnail']) or download_remote_file($video['thumbnail'], $thumb_source) !== true ) 
    2535    { 
    2636      $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; 
  • extensions/gvideo/admin/photo.php

    r19056 r19213  
    7272  else if ($gvideo['url']!=$_POST['url']) 
    7373  { 
    74     if( ($video = parse_video_url($_POST['url'])) === false ) 
    75     { 
    76       array_push($page['errors'], l10n('Unable to contact host server')); 
     74    if( ($video = parse_video_url($_POST['url'], isset($_POST['safe_mode']))) === false ) 
     75    { 
     76      if (isset($_POST['safe_mode'])) 
     77      { 
     78        array_push($page['errors'], l10n('an error happened')); 
     79      } 
     80      else 
     81      { 
     82        array_push($page['errors'], l10n('Unable to contact host server')); 
     83        array_push($page['errors'], l10n('Try in safe-mode')); 
     84      } 
    7785    } 
    7886  } 
     
    8997    { 
    9098      // download thumbnail 
    91       $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.get_extension($video['thumbnail']); 
     99      $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); 
     100      $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; 
    92101      $thumb_source = $conf['data_location'].$thumb_name; 
    93       if (download_remote_file($video['thumbnail'], $thumb_source) !== true) 
     102      if ( empty($video['thumbnail']) or download_remote_file($video['thumbnail'], $thumb_source) !== true ) 
    94103      { 
    95104        $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; 
  • extensions/gvideo/admin/template/add.tpl

    r19056 r19213  
    8888 
    8989 
    90 <p style="text-align:left;"><input type="submit" name="add_video" value="{'Add'|@translate}"></p> 
     90<p style="text-align:left;"> 
     91  <label style="font-weight:bold;"><input type="checkbox" name="safe_mode" {if $POST.safe_mode}checked="checked"{/if}> {'Safe-mode'|@translate}</label> 
     92  <a class="showInfo" title="{'In safe-mode, the plugin does\'t try to contact the video host, usefull on some websites where remote connections are blocked.'|@translate}">i</a> 
     93  <br> 
     94  <input type="submit" name="add_video" value="{'Add'|@translate}"> 
     95</p> 
    9196 
    9297<fieldset> 
  • extensions/gvideo/admin/template/photo.tpl

    r19056 r19213  
    9898 
    9999    <p style="margin:0;"> 
     100      <label style="font-weight:bold;"><input type="checkbox" name="safe_mode"> {'Safe-mode'|@translate}</label> 
     101      <br> 
    100102      <input class="submit" type="submit" value="{'Save Settings'|@translate}" name="save_properties"> 
    101103    </p> 
  • extensions/gvideo/include/functions.inc.php

    r19056 r19213  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 
    33 
    4 function parse_video_url($source_url) 
     4function parse_video_url($source_url, $safe_mode=false) 
    55{ 
    66  $source_url = 'http://'.preg_replace('#^http(s?)://#', null, $source_url); 
     
    1010  $url['host'] = explode('.', $url['host']); 
    1111   
    12   $video = array(); 
     12  $video = array( 
     13    'type' => null, 
     14    'video_id' => null, 
     15    'url' => null, 
     16    'title' => null, 
     17    'description' => null, 
     18    'thumbnail' => null, 
     19    'author' => null, 
     20    'tags' => null, 
     21  ); 
     22   
    1323  switch ($url['host'][0]) 
    1424  { 
     
    2636    case 'youtu': // youtu.be (short-url service) 
    2737    { 
    28       if (empty($video)) 
     38      if (empty($video['video_id'])) 
    2939      { 
    3040        $video['type'] = 'youtube'; 
     
    3444      } 
    3545       
    36       $api_url = 'http://gdata.youtube.com/feeds/api/videos/'.$video['video_id'].'?v=2&alt=json'; 
    37       $json = download_remote_file($api_url, true); 
    38       if ($json === false or $json == 'file_error') return false; 
    39        
    40       $json = json_decode($json, true); 
    41       $video = array_merge($video, array( 
    42         'url' => 'http://youtube.com/watch?v='.$video['video_id'], 
    43         'title' => $json['entry']['title']['$t'], 
    44         'description' => $json['entry']['media$group']['media$description']['$t'], 
    45         'thumbnail' => $json['entry']['media$group']['media$thumbnail'][2]['url'], 
    46         'author' => $json['entry']['author'][0]['name']['$t'], 
    47         'tags' => null, 
    48         )); 
     46      $video['url'] = 'http://youtube.com/watch?v='.$video['video_id']; 
     47       
     48      if (!$safe_mode) 
     49      { 
     50        $api_url = 'http://gdata.youtube.com/feeds/api/videos/'.$video['video_id'].'?v=2&alt=json'; 
     51        $json = download_remote_file($api_url, true); 
     52        if ($json === false or $json == 'file_error') return false; 
     53         
     54        $json = json_decode($json, true); 
     55        $video = array_merge($video, array( 
     56          'title' => $json['entry']['title']['$t'], 
     57          'description' => $json['entry']['media$group']['media$description']['$t'], 
     58          'thumbnail' => $json['entry']['media$group']['media$thumbnail'][2]['url'], 
     59          'author' => $json['entry']['author'][0]['name']['$t'], 
     60          )); 
     61      } 
     62      else 
     63      { 
     64        $video['title'] = 'YouTube #'.$video['video_id']; 
     65      } 
     66       
    4967      break; 
    5068    } 
     
    5876      $video['video_id'] = $url['path'][1]; 
    5977       
    60       $api_url = 'http://vimeo.com/api/v2/video/'.$video['video_id'].'.json'; 
    61       $json = download_remote_file($api_url, true); 
    62       if ($json === false or $json == 'file_error') return false; 
    63        
    64       $json = json_decode($json, true); 
    65       $video = array_merge($video, array( 
    66         'url' => 'http://vimeo.com/'.$video['video_id'], 
    67         'title' => $json[0]['title'], 
    68         'description' => $json[0]['description'], 
    69         'thumbnail' => $json[0]['thumbnail_large'], 
    70         'author' => $json[0]['user_name'], 
    71         'tags' => array_map('trim', explode(',', $json[0]['tags'])), 
    72         )); 
     78      $video['url'] = 'http://vimeo.com/'.$video['video_id']; 
     79       
     80      if (!$safe_mode) 
     81      { 
     82        $api_url = 'http://vimeo.com/api/v2/video/'.$video['video_id'].'.json'; 
     83        $json = download_remote_file($api_url, true); 
     84        if ($json === false or $json == 'file_error') return false; 
     85         
     86        $json = json_decode($json, true); 
     87        $video = array_merge($video, array( 
     88          'title' => $json[0]['title'], 
     89          'description' => $json[0]['description'], 
     90          'thumbnail' => $json[0]['thumbnail_large'], 
     91          'author' => $json[0]['user_name'], 
     92          'tags' => array_map('trim', explode(',', $json[0]['tags'])), 
     93          )); 
     94      } 
     95      else 
     96      { 
     97        $video['title'] = 'Vimeo #'.$video['video_id']; 
     98      } 
     99       
    73100      break; 
    74101    } 
     
    83110      $video['video_id'] = $url['path'][2]; 
    84111       
    85       $api_url = 'https://api.dailymotion.com/video/'.$video['video_id'].'?fields=description,thumbnail_large_url,title,owner.username,tags'; // DM doesn't accept non secure connection 
    86       $json = download_remote_file($api_url, true); 
    87       if ($json === false or $json == 'file_error') return false; 
    88        
    89       $json = json_decode($json, true); 
    90       $json['thumbnail_large_url'] = preg_replace('#\?([0-9]+)$#', null, $json['thumbnail_large_url']); 
    91        
    92       $video = array_merge($video, array( 
    93         'url' => 'http://dailymotion.com/video/'.$video['video_id'], 
    94         'title' => $json['title'], 
    95         'description' => $json['description'], 
    96         'thumbnail' => $json['thumbnail_large_url'], 
    97         'author' => $json['owner.username'], 
    98         'tags' => $json['tags'], 
    99         )); 
     112      $video['url'] = 'http://dailymotion.com/video/'.$video['video_id']; 
     113       
     114      if (!$safe_mode) 
     115      { 
     116        $api_url = 'https://api.dailymotion.com/video/'.$video['video_id'].'?fields=description,thumbnail_large_url,title,owner.username,tags'; // DM doesn't accept non secure connection 
     117        $json = download_remote_file($api_url, true); 
     118        if ($json === false or $json == 'file_error') return false; 
     119         
     120        $json = json_decode($json, true); 
     121        $json['thumbnail_large_url'] = preg_replace('#\?([0-9]+)$#', null, $json['thumbnail_large_url']); 
     122         
     123        $video = array_merge($video, array( 
     124          'title' => $json['title'], 
     125          'description' => $json['description'], 
     126          'thumbnail' => $json['thumbnail_large_url'], 
     127          'author' => $json['owner.username'], 
     128          'tags' => $json['tags'], 
     129          )); 
     130      } 
     131      else 
     132      { 
     133        $video['title'] = $video['video_id']; 
     134      } 
     135       
    100136      break; 
    101137    } 
     
    106142      $video['type'] = 'wat'; 
    107143       
     144      // no safe_mode for wat.tv 
    108145      $html = download_remote_file($source_url, true); 
    109146      if ($html === false or $html == 'file_error') return false; 
     
    139176      $video['video_id'] = rtrim($url['path'][2], '.html'); 
    140177       
    141       $html = download_remote_file($source_url, true); 
    142       if ($html === false or $html == 'file_error') return false; 
    143        
    144178      $video['url'] = 'http://wideo.fr/video/'.$video['video_id'].'.html'; 
    145179       
    146       preg_match('#<meta property="og:title" content="([^">]*)" />#', $html, $matches); 
    147       $video['title'] = $matches[1]; 
    148        
    149       preg_match('#<meta property="og:description" content="([^">]*)" />#', $html, $matches); 
    150       $video['description'] = $matches[1]; 
    151        
    152       preg_match('#<meta property="og:image" content="([^">]+)" />#', $html, $matches); 
    153       $video['thumbnail'] = $matches[1]; 
    154        
    155       preg_match('#<li id="li_author">Auteur :  <a href=(?:[^>]*)><span>(.*?)</span></a>#', $html, $matches); 
    156       $video['author'] = $matches[1]; 
    157        
    158       preg_match('#<meta name="keywords" content="([^">]+)" />#', $html, $matches); 
    159       $video['tags'] = array_map('trim', explode(',', $matches[1])); 
     180      if (!$safe_mode) 
     181      { 
     182        $html = download_remote_file($source_url, true); 
     183        if ($html === false or $html == 'file_error') return false; 
     184         
     185        preg_match('#<meta property="og:title" content="([^">]*)" />#', $html, $matches); 
     186        $video['title'] = $matches[1]; 
     187         
     188        preg_match('#<meta property="og:description" content="([^">]*)" />#', $html, $matches); 
     189        $video['description'] = $matches[1]; 
     190         
     191        preg_match('#<meta property="og:image" content="([^">]+)" />#', $html, $matches); 
     192        $video['thumbnail'] = $matches[1]; 
     193         
     194        preg_match('#<li id="li_author">Auteur :  <a href=(?:[^>]*)><span>(.*?)</span></a>#', $html, $matches); 
     195        $video['author'] = $matches[1]; 
     196         
     197        preg_match('#<meta name="keywords" content="([^">]+)" />#', $html, $matches); 
     198        $video['tags'] = array_map('trim', explode(',', $matches[1])); 
     199      } 
     200      else 
     201      { 
     202        $video['title'] = $video['video_id']; 
     203      } 
     204       
    160205      break; 
    161206    } 
  • extensions/gvideo/include/install.inc.php

    r19056 r19213  
    6565  `url` varchar(255) DEFAULT NULL, 
    6666  `type` varchar(64) NOT NULL, 
    67   `video_id` varchar(64) NOT NULL, 
     67  `video_id` varchar(128) NOT NULL, 
    6868  `width` smallint(9) DEFAULT NULL, 
    6969  `height` smallint(9) DEFAULT NULL, 
     
    7373  pwg_query($query); 
    7474   
     75  // update video_id lenght 
     76  $query = 'ALTER TABLE `'.gvideo_table.'` CHANGE `video_id` `video_id` VARCHAR(128) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;'; 
     77  pwg_query($query); 
     78   
    7579  // new collumn in images table 
    7680  $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";'); 
    7781  if (!pwg_db_num_rows($result)) 
    78   {       
     82  { 
    7983    pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;'); 
    8084     
  • extensions/gvideo/language/en_UK/plugin.lang.php

    r19056 r19213  
    2626$lang['Vimeo player'] = 'Vimeo player'; 
    2727$lang['Dailymotion player'] = 'Dailymotion player'; 
     28$lang['Try in safe-mode'] = 'Try in safe-mode'; 
     29$lang['Safe-mode'] = 'Safe-mode'; 
     30$lang['In safe-mode, the plugin does\'t try to contact the video host, usefull on some websites where remote connections are blocked.'] = 'In safe-mode, the plugin does\'t try to contact the video host, usefull on some websites where remote connections are blocked.'; 
     31$lang['Video properties'] = 'Video properties'; 
    2832 
    2933?> 
  • extensions/gvideo/language/fr_FR/plugin.lang.php

    r19056 r19213  
    2626$lang['Vimeo player'] = 'Lecteur Vimeo'; 
    2727$lang['Dailymotion player'] = 'Lecteur Dailymotion'; 
     28$lang['Try in safe-mode'] = 'Essayez en mode sans échec'; 
     29$lang['Safe-mode'] = 'Mode sans échec'; 
     30$lang['In safe-mode, the plugin does\'t try to contact the video host, usefull on some websites where remote connections are blocked.'] = 'En mode sans échec, le plugin n\'essaye pas de contacter l\'hébergeur de la vidéo, utile sur certains sites où les connexions externes sont bloquées.'; 
     31$lang['Video properties'] = 'Propriétés vidéo'; 
    2832 
    2933?> 
Note: See TracChangeset for help on using the changeset viewer.