[3609] | 1 | <?php |
---|
[17307] | 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[3609] | 3 | |
---|
[17307] | 4 | global $prefixeTable; |
---|
| 5 | |
---|
[17423] | 6 | define('gvideo_path', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/'); |
---|
[17307] | 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 | ); |
---|
| 32 | |
---|
[17383] | 33 | /* install */ |
---|
[17307] | 34 | function plugin_install() |
---|
[3609] | 35 | { |
---|
[17307] | 36 | global $conf; |
---|
| 37 | |
---|
| 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, |
---|
[17383] | 43 | `url` varchar(255) DEFAULT NULL, |
---|
[17307] | 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, |
---|
[17423] | 48 | `autoplay` tinyint(1) DEFAULT NULL |
---|
[17307] | 49 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
---|
| 50 | ;'; |
---|
| 51 | pwg_query($query); |
---|
| 52 | |
---|
| 53 | if (isset($conf['PY_GVideo'])) |
---|
| 54 | { |
---|
| 55 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PY_GVideo" LIMIT 1;'); |
---|
| 56 | unset($conf['PY_GVideo']); |
---|
| 57 | |
---|
| 58 | gvideo_update_24(); |
---|
| 59 | } |
---|
[3609] | 60 | } |
---|
| 61 | |
---|
[17383] | 62 | /* activate */ |
---|
[3609] | 63 | function plugin_activate() |
---|
| 64 | { |
---|
| 65 | global $conf; |
---|
[17307] | 66 | |
---|
| 67 | if (isset($conf['PY_GVideo'])) |
---|
[3609] | 68 | { |
---|
[17307] | 69 | plugin_install(); |
---|
[3609] | 70 | } |
---|
[17383] | 71 | else |
---|
[3609] | 72 | { |
---|
[17383] | 73 | if (!isset($conf['gvideo'])) |
---|
| 74 | { |
---|
| 75 | conf_update_param('gvideo', gvideo_default_config); |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | $result = pwg_query('SHOW COLUMNS FROM '.gvideo_table.' LIKE "url";'); |
---|
| 79 | if (!pwg_db_num_rows($result)) |
---|
| 80 | { |
---|
| 81 | pwg_query('ALTER TABLE '.gvideo_table.' ADD `url` VARCHAR(255) DEFAULT NULL;'); |
---|
| 82 | } |
---|
[3609] | 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
[17383] | 86 | /* uninstall */ |
---|
[17307] | 87 | function plugin_uninstall() |
---|
| 88 | { |
---|
| 89 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "gvideo" LIMIT 1;'); |
---|
| 90 | pwg_query('DROP TABLE `'.gvideo_table.'`;'); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | /** |
---|
| 95 | * update from 2.3 to 2.4 |
---|
| 96 | */ |
---|
| 97 | function gvideo_update_24() |
---|
[3609] | 98 | { |
---|
| 99 | global $conf; |
---|
| 100 | |
---|
[17307] | 101 | // search existing videos |
---|
| 102 | $query = ' |
---|
| 103 | SELECT * |
---|
| 104 | FROM '.IMAGES_TABLE.' |
---|
| 105 | WHERE |
---|
| 106 | file LIKE "%.gvideo" |
---|
| 107 | OR file LIKE "%.dm" |
---|
| 108 | OR file LIKE "%.ytube" |
---|
| 109 | OR file LIKE "%.wideo" |
---|
| 110 | OR file LIKE "%.vimeo" |
---|
| 111 | OR file LIKE "%.wat" |
---|
| 112 | ;'; |
---|
| 113 | $result = pwg_query($query); |
---|
| 114 | |
---|
| 115 | if (!pwg_db_num_rows($result)) |
---|
[3609] | 116 | { |
---|
[17307] | 117 | return; |
---|
[3609] | 118 | } |
---|
[17307] | 119 | |
---|
[17383] | 120 | if (!isset($conf['prefix_thumbnail'])) |
---|
| 121 | { |
---|
| 122 | $conf['prefix_thumbnail'] = 'TN-'; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | if (!isset($conf['dir_thumbnail'])) |
---|
| 126 | { |
---|
| 127 | $conf['dir_thumbnail'] = 'thumbnail'; |
---|
| 128 | } |
---|
| 129 | |
---|
[17307] | 130 | set_time_limit(600); |
---|
| 131 | include_once(gvideo_path . '/include/functions.inc.php'); |
---|
| 132 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
| 133 | |
---|
| 134 | $videos_inserts = array(); |
---|
| 135 | $images_updates = array(); |
---|
| 136 | $images_delete = array(); |
---|
| 137 | |
---|
| 138 | while ($img = pwg_db_fetch_assoc($result)) |
---|
| 139 | { |
---|
| 140 | $file_content = file_get_contents($img['path']); |
---|
| 141 | list($file['id'], $file['height'], $file['width'], ) = explode('/', $file_content); |
---|
| 142 | $file['type'] = get_extension($img['path']); |
---|
| 143 | |
---|
| 144 | switch ($file['type']) |
---|
| 145 | { |
---|
| 146 | case 'vimeo': |
---|
[17383] | 147 | $video = array( |
---|
| 148 | 'type' => 'vimeo', |
---|
| 149 | 'url' => 'http://vimeo.com/'.$file['id'], |
---|
| 150 | ); |
---|
[17307] | 151 | break; |
---|
| 152 | case 'dm': |
---|
[17383] | 153 | $video = array( |
---|
| 154 | 'type' => 'dailymotion', |
---|
| 155 | 'url' => 'http://dailymotion.com/video/'.$file['id'], |
---|
| 156 | ); |
---|
[17307] | 157 | break; |
---|
| 158 | case 'ytube': |
---|
[17383] | 159 | $video = array( |
---|
| 160 | 'type' => 'youtube', |
---|
| 161 | 'url' => 'http://youtube.com/watch?v='.$file['id'], |
---|
| 162 | ); |
---|
[17307] | 163 | break; |
---|
| 164 | case 'wideo': |
---|
[17383] | 165 | $video = array( |
---|
| 166 | 'type' => 'wideo', |
---|
| 167 | 'url' => 'http://wideo.fr/video/'.$file['id'].'.html', |
---|
| 168 | ); |
---|
[17307] | 169 | break; |
---|
[17383] | 170 | case 'wat': |
---|
[17307] | 171 | $video = array( |
---|
| 172 | 'type' => 'wat', |
---|
[17383] | 173 | 'url' => null, |
---|
[17307] | 174 | ); |
---|
| 175 | break; |
---|
| 176 | case 'gvideo': // closed |
---|
| 177 | default: |
---|
| 178 | array_push($images_delete, $img['id']); |
---|
| 179 | continue; |
---|
| 180 | } |
---|
| 181 | |
---|
[17383] | 182 | $real_path = str_replace($img['file'], null, str_replace('././', './', $img['path'])); |
---|
| 183 | |
---|
| 184 | // get existing thumbnail |
---|
| 185 | $thumb = $real_path.$conf['dir_thumbnail'].'/'.$conf['prefix_thumbnail'].get_filename_wo_extension($img['file']).'.*'; |
---|
| 186 | $thumb = glob($thumb); |
---|
| 187 | if (!empty($thumb)) |
---|
[17307] | 188 | { |
---|
[17383] | 189 | $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.'.get_extension($thumb[0]); |
---|
| 190 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
| 191 | copy($thumb[0], $thumb_source); |
---|
[17307] | 192 | } |
---|
[17383] | 193 | else |
---|
[17307] | 194 | { |
---|
[17383] | 195 | $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg'; |
---|
[17307] | 196 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
[17383] | 197 | copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
| 198 | add_film_frame($thumb_source); |
---|
[17307] | 199 | } |
---|
| 200 | |
---|
| 201 | // update element |
---|
| 202 | $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']); |
---|
| 203 | |
---|
| 204 | // update path and rename the file |
---|
[17383] | 205 | $img['new_path'] = $real_path.$thumb_name; |
---|
[17307] | 206 | rename($img['path'], $img['new_path']); |
---|
| 207 | array_push($images_updates, array( |
---|
| 208 | 'id' => $img['id'], |
---|
[17383] | 209 | 'path' => $img['new_path'], |
---|
[17307] | 210 | )); |
---|
| 211 | |
---|
| 212 | if (empty($file['width'])) $file['width'] = ''; |
---|
| 213 | if (empty($file['height'])) $file['height'] = ''; |
---|
| 214 | |
---|
| 215 | // register video |
---|
| 216 | array_push($videos_inserts, array( |
---|
| 217 | 'picture_id' => $image_id, |
---|
[17383] | 218 | 'url' => $video['url'], |
---|
[17307] | 219 | 'type' => $video['type'], |
---|
[17383] | 220 | 'video_id' => $file['id'], |
---|
[17307] | 221 | 'width' => $file['width'], |
---|
| 222 | 'height' => $file['height'], |
---|
| 223 | 'autoplay' => '', |
---|
| 224 | )); |
---|
| 225 | |
---|
| 226 | unset($thumb_source, $thumb_name, $file, $video, $url); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | // delete obsolete elements |
---|
| 230 | delete_elements($images_delete); |
---|
| 231 | |
---|
| 232 | // registers videos |
---|
| 233 | mass_inserts( |
---|
| 234 | gvideo_table, |
---|
[17383] | 235 | array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'), |
---|
[17307] | 236 | $videos_inserts |
---|
| 237 | ); |
---|
| 238 | |
---|
| 239 | // update images |
---|
| 240 | mass_updates( |
---|
| 241 | IMAGES_TABLE, |
---|
| 242 | array('primary'=>array('id'), 'update'=>array('path')), |
---|
| 243 | $images_updates |
---|
| 244 | ); |
---|
[3609] | 245 | } |
---|
| 246 | |
---|
[3296] | 247 | ?> |
---|