Changeset 17661 for extensions/gvideo/maintain.inc.php
- Timestamp:
- Aug 29, 2012, 6:00:39 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/gvideo/maintain.inc.php
r17490 r17661 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 3 4 global $prefixeTable; 5 6 define('gvideo_path', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); 7 define('gvideo_table', $prefixeTable.'image_video'); 8 9 define( 10 'gvideo_default_config', 11 serialize(array( 12 'autoplay' => 0, 13 'width' => 640, 14 'height' => 360, 15 'vimeo' => array( 16 'title' => 1, 17 'portrait' => 1, 18 'byline' => 1, 19 'color' => '00adef', 20 ), 21 'dailymotion' => array( 22 'logo' => 1, 23 'title' => 1, 24 'color' => 'F7FFFD', 25 ), 26 'youtube' => array(), 27 'wat' => array(), 28 'wideo' => array(), 29 'videobb' => array(), 30 )) 31 ); 4 include_once(PHPWG_PLUGINS_PATH . 'gvideo/include/install.inc.php'); 32 5 33 6 /* install */ 34 7 function plugin_install() 35 8 { 36 g lobal $conf;9 gvideo_install(); 37 10 38 conf_update_param('gvideo', gvideo_default_config); 39 40 $query = ' 41 CREATE TABLE IF NOT EXISTS `'.gvideo_table.'` ( 42 `picture_id` mediumint(8) NOT NULL, 43 `url` varchar(255) DEFAULT NULL, 44 `type` varchar(64) NOT NULL, 45 `video_id` varchar(64) NOT NULL, 46 `width` smallint(9) DEFAULT NULL, 47 `height` smallint(9) DEFAULT NULL, 48 `autoplay` tinyint(1) DEFAULT NULL 49 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 50 ;'; 51 pwg_query($query); 52 53 pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;'); 54 55 if (isset($conf['PY_GVideo'])) 56 { 57 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;'); 58 unset($conf['PY_GVideo']); 59 60 gvideo_update_24(); 61 } 11 define('gvideo_installed', true); 62 12 } 63 13 … … 65 15 function plugin_activate() 66 16 { 67 global $conf; 68 69 if (isset($conf['PY_GVideo'])) 17 if (!defined('gvideo_installed')) 70 18 { 71 plugin_install(); 72 } 73 else 74 { 75 if (!isset($conf['gvideo'])) 76 { 77 conf_update_param('gvideo', gvideo_default_config); 78 } 79 80 $result = pwg_query('SHOW COLUMNS FROM '.gvideo_table.' LIKE "url";'); 81 if (!pwg_db_num_rows($result)) 82 { 83 pwg_query('ALTER TABLE '.gvideo_table.' ADD `url` VARCHAR(255) DEFAULT NULL;'); 84 } 85 86 $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";'); 87 if (!pwg_db_num_rows($result)) 88 { 89 pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;'); 90 91 $query = ' 92 UPDATE '.IMAGES_TABLE.' 93 SET is_gvideo = 1 94 WHERE id IN( 95 SELECT picture_id FROM '.gvideo_table.' 96 ) 97 ;'; 98 pwg_query($query); 99 } 19 gvideo_install(); 100 20 } 101 21 } … … 103 23 /* uninstall */ 104 24 function plugin_uninstall() 105 { 25 { 26 global $prefixeTable; 27 106 28 pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "gvideo" LIMIT 1;'); 107 pwg_query('DROP TABLE `'. gvideo_table.'`;');29 pwg_query('DROP TABLE `'.$prefixeTable.'image_video`;'); 108 30 pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` DROP `is_gvideo`;'); 109 31 } 110 32 111 112 /**113 * update from 2.3 to 2.4114 */115 function gvideo_update_24()116 {117 global $conf;118 119 // search existing videos120 $query = '121 SELECT *122 FROM '.IMAGES_TABLE.'123 WHERE124 file LIKE "%.gvideo"125 OR file LIKE "%.dm"126 OR file LIKE "%.ytube"127 OR file LIKE "%.wideo"128 OR file LIKE "%.vimeo"129 OR file LIKE "%.wat"130 ;';131 $result = pwg_query($query);132 133 if (!pwg_db_num_rows($result))134 {135 return;136 }137 138 if (!isset($conf['prefix_thumbnail']))139 {140 $conf['prefix_thumbnail'] = 'TN-';141 }142 143 if (!isset($conf['dir_thumbnail']))144 {145 $conf['dir_thumbnail'] = 'thumbnail';146 }147 148 set_time_limit(600);149 include_once(gvideo_path . '/include/functions.inc.php');150 include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');151 152 $videos_inserts = array();153 $images_updates = array();154 $images_delete = array();155 156 while ($img = pwg_db_fetch_assoc($result))157 {158 $file_content = file_get_contents($img['path']);159 list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content);160 $file['type'] = get_extension($img['path']);161 162 switch ($file['type'])163 {164 case 'vimeo':165 $video = array(166 'type' => 'vimeo',167 'url' => 'http://vimeo.com/'.$file['id'],168 );169 break;170 case 'dm':171 $video = array(172 'type' => 'dailymotion',173 'url' => 'http://dailymotion.com/video/'.$file['id'],174 );175 break;176 case 'ytube':177 $video = array(178 'type' => 'youtube',179 'url' => 'http://youtube.com/watch?v='.$file['id'],180 );181 break;182 case 'wideo':183 $video = array(184 'type' => 'wideo',185 'url' => 'http://wideo.fr/video/'.$file['id'].'.html',186 );187 break;188 case 'wat':189 $video = array(190 'type' => 'wat',191 'url' => null,192 );193 break;194 case 'gvideo': // closed195 default:196 array_push($images_delete, $img['id']);197 continue;198 }199 200 $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path']));201 202 // get existing thumbnail203 $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*';204 $thumb = glob($thumb);205 if (!empty($thumb))206 {207 $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]);208 $thumb_source = $conf['data_location'].$thumb_name;209 copy($thumb[0], $thumb_source);210 }211 else212 {213 $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg';214 $thumb_source = $conf['data_location'].$thumb_name;215 copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source);216 add_film_frame($thumb_source);217 }218 219 // update element220 $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']);221 222 // update path and rename the file223 $img['new_path'] = $real_path.$thumb_name;224 rename($img['path'], $img['new_path']);225 array_push($images_updates, array(226 'id' => $img['id'],227 'path' => $img['new_path'],228 'is_gvideo' => 1,229 ));230 231 if (empty($file['width'])) $file['width'] = '';232 if (empty($file['height'])) $file['height'] = '';233 234 // register video235 array_push($videos_inserts, array(236 'picture_id' => $image_id,237 'url' => $video['url'],238 'type' => $video['type'],239 'video_id' => $file['id'],240 'width' => $file['width'],241 'height' => $file['height'],242 'autoplay' => '',243 ));244 245 unset($thumb_source, $thumb_name, $file, $video, $url);246 }247 248 // delete obsolete elements249 delete_elements($images_delete);250 251 // registers videos252 mass_inserts(253 gvideo_table,254 array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'),255 $videos_inserts256 );257 258 // update images259 mass_updates(260 IMAGES_TABLE,261 array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')),262 $images_updates263 );264 }265 266 33 ?>
Note: See TracChangeset
for help on using the changeset viewer.