1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
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 | ); |
---|
32 | |
---|
33 | /* install */ |
---|
34 | function plugin_install() |
---|
35 | { |
---|
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, |
---|
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 | } |
---|
62 | } |
---|
63 | |
---|
64 | /* activate */ |
---|
65 | function plugin_activate() |
---|
66 | { |
---|
67 | global $conf; |
---|
68 | |
---|
69 | if (isset($conf['PY_GVideo'])) |
---|
70 | { |
---|
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 | } |
---|
100 | } |
---|
101 | } |
---|
102 | |
---|
103 | /* uninstall */ |
---|
104 | function plugin_uninstall() |
---|
105 | { |
---|
106 | pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "gvideo" LIMIT 1;'); |
---|
107 | pwg_query('DROP TABLE `'.gvideo_table.'`;'); |
---|
108 | pwg_query('ALTER TABLE `' . IMAGES_TABLE . '` DROP `is_gvideo`;'); |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | /** |
---|
113 | * update from 2.3 to 2.4 |
---|
114 | */ |
---|
115 | function gvideo_update_24() |
---|
116 | { |
---|
117 | global $conf; |
---|
118 | |
---|
119 | // search existing videos |
---|
120 | $query = ' |
---|
121 | SELECT * |
---|
122 | FROM '.IMAGES_TABLE.' |
---|
123 | WHERE |
---|
124 | 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': // closed |
---|
195 | 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 thumbnail |
---|
203 | $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 | else |
---|
212 | { |
---|
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 element |
---|
220 | $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $img['id']); |
---|
221 | |
---|
222 | // update path and rename the file |
---|
223 | $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 | )); |
---|
229 | |
---|
230 | if (empty($file['width'])) $file['width'] = ''; |
---|
231 | if (empty($file['height'])) $file['height'] = ''; |
---|
232 | |
---|
233 | // register video |
---|
234 | array_push($videos_inserts, array( |
---|
235 | 'picture_id' => $image_id, |
---|
236 | 'url' => $video['url'], |
---|
237 | 'type' => $video['type'], |
---|
238 | 'video_id' => $file['id'], |
---|
239 | 'width' => $file['width'], |
---|
240 | 'height' => $file['height'], |
---|
241 | 'autoplay' => '', |
---|
242 | )); |
---|
243 | |
---|
244 | unset($thumb_source, $thumb_name, $file, $video, $url); |
---|
245 | } |
---|
246 | |
---|
247 | // delete obsolete elements |
---|
248 | delete_elements($images_delete); |
---|
249 | |
---|
250 | // registers videos |
---|
251 | mass_inserts( |
---|
252 | gvideo_table, |
---|
253 | array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'), |
---|
254 | $videos_inserts |
---|
255 | ); |
---|
256 | |
---|
257 | // update images |
---|
258 | mass_updates( |
---|
259 | IMAGES_TABLE, |
---|
260 | array('primary'=>array('id'), 'update'=>array('path')), |
---|
261 | $images_updates |
---|
262 | ); |
---|
263 | } |
---|
264 | |
---|
265 | ?> |
---|