[17661] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | global $prefixeTable; |
---|
| 5 | |
---|
| 6 | // defined here only because it's more convenient |
---|
[20804] | 7 | define('gvideo_path', PHPWG_PLUGINS_PATH . GVIDEO_ID . '/'); |
---|
[17661] | 8 | define('gvideo_table', $prefixeTable.'image_video'); |
---|
| 9 | |
---|
| 10 | /** |
---|
| 11 | * installation |
---|
| 12 | */ |
---|
| 13 | function gvideo_install() |
---|
| 14 | { |
---|
| 15 | global $conf; |
---|
| 16 | |
---|
| 17 | // configuration |
---|
| 18 | if (empty($conf['gvideo'])) |
---|
| 19 | { |
---|
| 20 | $gvideo_default_config = serialize(array( |
---|
| 21 | 'autoplay' => 0, |
---|
| 22 | 'width' => 640, |
---|
| 23 | 'height' => 360, |
---|
[19056] | 24 | 'sync_description' => 1, |
---|
| 25 | 'sync_tags' => 1, |
---|
[17661] | 26 | 'vimeo' => array( |
---|
| 27 | 'title' => 1, |
---|
| 28 | 'portrait' => 1, |
---|
| 29 | 'byline' => 1, |
---|
| 30 | 'color' => '00adef', |
---|
| 31 | ), |
---|
| 32 | 'dailymotion' => array( |
---|
| 33 | 'logo' => 1, |
---|
| 34 | 'title' => 1, |
---|
| 35 | 'color' => 'F7FFFD', |
---|
| 36 | ), |
---|
| 37 | 'youtube' => array(), |
---|
| 38 | 'wat' => array(), |
---|
| 39 | 'wideo' => array(), |
---|
| 40 | )); |
---|
| 41 | |
---|
| 42 | conf_update_param('gvideo', $gvideo_default_config); |
---|
| 43 | $conf['gvideo'] = $gvideo_default_config; |
---|
| 44 | } |
---|
[19056] | 45 | else |
---|
| 46 | { |
---|
| 47 | if (is_string($conf['gvideo'])) |
---|
| 48 | { |
---|
| 49 | $conf['gvideo'] = unserialize($conf['gvideo']); |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | if (!isset($conf['gvideo']['sync_description'])) |
---|
| 53 | { |
---|
| 54 | $conf['gvideo']['sync_description'] = 1; |
---|
| 55 | $conf['gvideo']['sync_tags'] = 1; |
---|
| 56 | |
---|
| 57 | conf_update_param('gvideo', serialize($conf['gvideo'])); |
---|
| 58 | } |
---|
| 59 | } |
---|
[17661] | 60 | |
---|
| 61 | // create table |
---|
| 62 | $query = ' |
---|
| 63 | CREATE TABLE IF NOT EXISTS `'.gvideo_table.'` ( |
---|
| 64 | `picture_id` mediumint(8) NOT NULL, |
---|
| 65 | `url` varchar(255) DEFAULT NULL, |
---|
| 66 | `type` varchar(64) NOT NULL, |
---|
[19213] | 67 | `video_id` varchar(128) NOT NULL, |
---|
[17661] | 68 | `width` smallint(9) DEFAULT NULL, |
---|
| 69 | `height` smallint(9) DEFAULT NULL, |
---|
| 70 | `autoplay` tinyint(1) DEFAULT NULL |
---|
| 71 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
| 72 | ;'; |
---|
| 73 | pwg_query($query); |
---|
| 74 | |
---|
[19213] | 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 | |
---|
[17661] | 79 | // new collumn in images table |
---|
| 80 | $result = pwg_query('SHOW COLUMNS FROM '.IMAGES_TABLE.' LIKE "is_gvideo";'); |
---|
| 81 | if (!pwg_db_num_rows($result)) |
---|
[19213] | 82 | { |
---|
[17661] | 83 | pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` ADD `is_gvideo` TINYINT(1) NOT NULL DEFAULT 0;'); |
---|
| 84 | |
---|
| 85 | $query = ' |
---|
| 86 | UPDATE '.IMAGES_TABLE.' |
---|
| 87 | SET is_gvideo = 1 |
---|
| 88 | WHERE id IN( |
---|
| 89 | SELECT picture_id FROM '.gvideo_table.' |
---|
| 90 | ) |
---|
| 91 | ;'; |
---|
| 92 | pwg_query($query); |
---|
| 93 | } |
---|
| 94 | |
---|
[20804] | 95 | // remove old configuration |
---|
[17661] | 96 | if (isset($conf['PY_GVideo'])) |
---|
| 97 | { |
---|
| 98 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;'); |
---|
| 99 | unset($conf['PY_GVideo']); |
---|
[20804] | 100 | } |
---|
[17661] | 101 | |
---|
[20804] | 102 | // updade video files |
---|
| 103 | gvideo_update_24(); |
---|
[17661] | 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | /** |
---|
| 108 | * update from 2.3 to 2.4 |
---|
| 109 | */ |
---|
| 110 | function gvideo_update_24() |
---|
| 111 | { |
---|
| 112 | global $conf; |
---|
| 113 | |
---|
| 114 | // search existing videos |
---|
| 115 | $query = ' |
---|
| 116 | SELECT * |
---|
| 117 | FROM '.IMAGES_TABLE.' |
---|
| 118 | WHERE |
---|
| 119 | file LIKE "%.gvideo" |
---|
| 120 | OR file LIKE "%.dm" |
---|
| 121 | OR file LIKE "%.ytube" |
---|
| 122 | OR file LIKE "%.wideo" |
---|
| 123 | OR file LIKE "%.vimeo" |
---|
| 124 | OR file LIKE "%.wat" |
---|
| 125 | ;'; |
---|
| 126 | $result = pwg_query($query); |
---|
| 127 | |
---|
| 128 | if (!pwg_db_num_rows($result)) |
---|
| 129 | { |
---|
| 130 | return; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | if (!isset($conf['prefix_thumbnail'])) |
---|
| 134 | { |
---|
| 135 | $conf['prefix_thumbnail'] = 'TN-'; |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | if (!isset($conf['dir_thumbnail'])) |
---|
| 139 | { |
---|
| 140 | $conf['dir_thumbnail'] = 'thumbnail'; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | set_time_limit(600); |
---|
[17684] | 144 | include_once(gvideo_path . 'include/functions.inc.php'); |
---|
[17661] | 145 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
| 146 | |
---|
| 147 | $videos_inserts = array(); |
---|
| 148 | $images_updates = array(); |
---|
| 149 | $images_delete = array(); |
---|
| 150 | |
---|
| 151 | while ($img = pwg_db_fetch_assoc($result)) |
---|
| 152 | { |
---|
| 153 | $file_content = file_get_contents($img['path']); |
---|
| 154 | list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content); |
---|
| 155 | $file['type'] = get_extension($img['path']); |
---|
| 156 | |
---|
| 157 | switch ($file['type']) |
---|
| 158 | { |
---|
| 159 | case 'vimeo': |
---|
| 160 | $video = array( |
---|
| 161 | 'type' => 'vimeo', |
---|
| 162 | 'url' => 'http://vimeo.com/'.$file['id'], |
---|
| 163 | ); |
---|
| 164 | break; |
---|
| 165 | case 'dm': |
---|
| 166 | $video = array( |
---|
| 167 | 'type' => 'dailymotion', |
---|
| 168 | 'url' => 'http://dailymotion.com/video/'.$file['id'], |
---|
| 169 | ); |
---|
| 170 | break; |
---|
| 171 | case 'ytube': |
---|
| 172 | $video = array( |
---|
| 173 | 'type' => 'youtube', |
---|
| 174 | 'url' => 'http://youtube.com/watch?v='.$file['id'], |
---|
| 175 | ); |
---|
| 176 | break; |
---|
| 177 | case 'wideo': |
---|
| 178 | $video = array( |
---|
| 179 | 'type' => 'wideo', |
---|
| 180 | 'url' => 'http://wideo.fr/video/'.$file['id'].'.html', |
---|
| 181 | ); |
---|
| 182 | break; |
---|
| 183 | case 'wat': |
---|
| 184 | $video = array( |
---|
| 185 | 'type' => 'wat', |
---|
| 186 | 'url' => null, |
---|
| 187 | ); |
---|
| 188 | break; |
---|
| 189 | case 'gvideo': // closed |
---|
| 190 | default: |
---|
| 191 | array_push($images_delete, $img['id']); |
---|
| 192 | continue; |
---|
| 193 | } |
---|
| 194 | |
---|
| 195 | $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path'])); |
---|
| 196 | |
---|
| 197 | // get existing thumbnail |
---|
| 198 | $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*'; |
---|
| 199 | $thumb = glob($thumb); |
---|
| 200 | if (!empty($thumb)) |
---|
| 201 | { |
---|
| 202 | $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]); |
---|
| 203 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
| 204 | copy($thumb[0], $thumb_source); |
---|
| 205 | } |
---|
| 206 | else |
---|
| 207 | { |
---|
| 208 | $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg'; |
---|
| 209 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
| 210 | copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
| 211 | add_film_frame($thumb_source); |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | // update element |
---|
| 215 | $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']); |
---|
| 216 | |
---|
| 217 | // update path and rename the file |
---|
| 218 | $img['new_path'] = $real_path.$thumb_name; |
---|
[20804] | 219 | rename($img['path'], $img['new_path']); // why ? what's the purpose of this line ? |
---|
[17661] | 220 | array_push($images_updates, array( |
---|
| 221 | 'id' => $img['id'], |
---|
| 222 | 'path' => $img['new_path'], |
---|
| 223 | 'is_gvideo' => 1, |
---|
| 224 | )); |
---|
| 225 | |
---|
| 226 | if (empty($file['width'])) $file['width'] = ''; |
---|
| 227 | if (empty($file['height'])) $file['height'] = ''; |
---|
| 228 | |
---|
| 229 | // register video |
---|
| 230 | array_push($videos_inserts, array( |
---|
| 231 | 'picture_id' => $image_id, |
---|
| 232 | 'url' => $video['url'], |
---|
| 233 | 'type' => $video['type'], |
---|
| 234 | 'video_id' => $file['id'], |
---|
| 235 | 'width' => $file['width'], |
---|
| 236 | 'height' => $file['height'], |
---|
| 237 | 'autoplay' => '', |
---|
| 238 | )); |
---|
| 239 | |
---|
| 240 | unset($thumb_source, $thumb_name, $file, $video, $url); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | // delete obsolete elements |
---|
| 244 | delete_elements($images_delete); |
---|
| 245 | |
---|
| 246 | // registers videos |
---|
| 247 | mass_inserts( |
---|
| 248 | gvideo_table, |
---|
| 249 | array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'), |
---|
| 250 | $videos_inserts |
---|
| 251 | ); |
---|
| 252 | |
---|
| 253 | // update images |
---|
| 254 | mass_updates( |
---|
| 255 | IMAGES_TABLE, |
---|
| 256 | array('primary'=>array('id'), 'update'=>array('path', 'is_gvideo')), |
---|
| 257 | $images_updates |
---|
| 258 | ); |
---|
[20804] | 259 | } |
---|
| 260 | |
---|
| 261 | ?> |
---|