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 | 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 | } |
---|
60 | } |
---|
61 | |
---|
62 | /* activate */ |
---|
63 | function plugin_activate() |
---|
64 | { |
---|
65 | global $conf; |
---|
66 | |
---|
67 | if (isset($conf['PY_GVideo'])) |
---|
68 | { |
---|
69 | plugin_install(); |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
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 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | /* uninstall */ |
---|
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() |
---|
98 | { |
---|
99 | global $conf; |
---|
100 | |
---|
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)) |
---|
116 | { |
---|
117 | return; |
---|
118 | } |
---|
119 | |
---|
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 | |
---|
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': |
---|
147 | $video = array( |
---|
148 | 'type' => 'vimeo', |
---|
149 | 'url' => 'http://vimeo.com/'.$file['id'], |
---|
150 | ); |
---|
151 | break; |
---|
152 | case 'dm': |
---|
153 | $video = array( |
---|
154 | 'type' => 'dailymotion', |
---|
155 | 'url' => 'http://dailymotion.com/video/'.$file['id'], |
---|
156 | ); |
---|
157 | break; |
---|
158 | case 'ytube': |
---|
159 | $video = array( |
---|
160 | 'type' => 'youtube', |
---|
161 | 'url' => 'http://youtube.com/watch?v='.$file['id'], |
---|
162 | ); |
---|
163 | break; |
---|
164 | case 'wideo': |
---|
165 | $video = array( |
---|
166 | 'type' => 'wideo', |
---|
167 | 'url' => 'http://wideo.fr/video/'.$file['id'].'.html', |
---|
168 | ); |
---|
169 | break; |
---|
170 | case 'wat': |
---|
171 | $video = array( |
---|
172 | 'type' => 'wat', |
---|
173 | 'url' => null, |
---|
174 | ); |
---|
175 | break; |
---|
176 | case 'gvideo': // closed |
---|
177 | default: |
---|
178 | array_push($images_delete, $img['id']); |
---|
179 | continue; |
---|
180 | } |
---|
181 | |
---|
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)) |
---|
188 | { |
---|
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); |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | $thumb_name = $video['type'].'-'.$file['id'].'-'.uniqid().'.jpg'; |
---|
196 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
197 | copy(gvideo_path.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
198 | add_film_frame($thumb_source); |
---|
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 |
---|
205 | $img['new_path'] = $real_path.$thumb_name; |
---|
206 | rename($img['path'], $img['new_path']); |
---|
207 | array_push($images_updates, array( |
---|
208 | 'id' => $img['id'], |
---|
209 | 'path' => $img['new_path'], |
---|
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, |
---|
218 | 'url' => $video['url'], |
---|
219 | 'type' => $video['type'], |
---|
220 | 'video_id' => $file['id'], |
---|
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, |
---|
235 | array('picture_id', 'url', 'type', 'video_id', 'width', 'height', 'autoplay'), |
---|
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 | ); |
---|
245 | } |
---|
246 | |
---|
247 | ?> |
---|