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