1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | $video_types = array('google', 'youtube', 'dailymotion', 'wideo', 'vimeo', 'wat'); |
---|
6 | |
---|
7 | function get_video_infos($url, $type) |
---|
8 | { |
---|
9 | switch ($type) |
---|
10 | { |
---|
11 | case "google": |
---|
12 | @preg_match('#\=([\-\+0-9]*)#', $url, $id); |
---|
13 | if (empty($id[1])) return false; |
---|
14 | $video['id'] = $id[1]; |
---|
15 | $video['ext'] = 'gvideo'; |
---|
16 | if ($_POST['thumbnail'] == 'thumb_from_server' and fetchRemote($url, $source)) |
---|
17 | { |
---|
18 | @preg_match("#thumbnailUrl\\\\x3d(http://.*/ThumbnailServer.*)\\\\x26#", $source, $thumb_url); |
---|
19 | $video['thumb_url'] = @urldecode($thumb_url[1]); |
---|
20 | $video['thumb_url'] = @str_replace(array('\x3d', '\x26'), array('=', '&'), $video['thumb_url']); |
---|
21 | } |
---|
22 | return $video; |
---|
23 | |
---|
24 | case "youtube": |
---|
25 | @preg_match('#\=([\-_a-z0-9]*)#i', $url, $id); |
---|
26 | if (empty($id[1])) return false; |
---|
27 | $video['id'] = $id[1]; |
---|
28 | $video['ext'] = 'ytube'; |
---|
29 | if ($_POST['thumbnail'] == 'thumb_from_server') |
---|
30 | { |
---|
31 | $video['thumb_url'] = 'http://img.youtube.com/vi/' . $video['id'] . '/default.jpg'; |
---|
32 | } |
---|
33 | return $video; |
---|
34 | |
---|
35 | case "dailymotion": |
---|
36 | @preg_match('#video/([_a-z0-9]*)#i', $url, $id); |
---|
37 | if (empty($id[1])) return false; |
---|
38 | $video['id'] = $id[1]; |
---|
39 | $video['ext'] = 'dm'; |
---|
40 | if ($_POST['thumbnail'] == 'thumb_from_server') |
---|
41 | { |
---|
42 | $video['thumb_url'] = 'http://www.dailymotion.com/thumbnail/160x120/video/' . $video['id']; |
---|
43 | } |
---|
44 | return $video; |
---|
45 | |
---|
46 | case "wideo": |
---|
47 | @preg_match('#video/([_a-z0-9]*)#i', $url, $id); |
---|
48 | if (empty($id[1])) return false; |
---|
49 | $video['id'] = $id[1]; |
---|
50 | $video['ext'] = 'wideo'; |
---|
51 | if ($_POST['thumbnail'] == 'thumb_from_server' and fetchRemote($url, $source)) |
---|
52 | { |
---|
53 | @preg_match('#link rel\="thumbnail" href\="(.*)"#', $source, $matches); |
---|
54 | $video['thumb_url'] = @str_replace('74x54', '154x114', $matches[1]); |
---|
55 | } |
---|
56 | return $video; |
---|
57 | |
---|
58 | case "vimeo": |
---|
59 | @preg_match('#vimeo.com/([0-9]*)#i', $url, $id); |
---|
60 | if (empty($id[1])) return false; |
---|
61 | $video['id'] = $id[1]; |
---|
62 | $video['ext'] = 'vimeo'; |
---|
63 | if ($_POST['thumbnail'] == 'thumb_from_server' and fetchRemote($url, $source)) |
---|
64 | { |
---|
65 | @preg_match('#link rel="image_src" href="(http://.*?)"#', $source, $matches); |
---|
66 | $video['thumb_url'] = @str_replace('160.jpg', '200.jpg', $matches[1]); |
---|
67 | } |
---|
68 | return $video; |
---|
69 | |
---|
70 | case "wat": |
---|
71 | if (fetchRemote($url, $source)) |
---|
72 | { |
---|
73 | @preg_match('#link rel="video_src" href="http://www.wat.tv/swf2/(.*?)"#i', $source, $id); |
---|
74 | if (empty($id[1])) return false; |
---|
75 | $video['id'] = $id[1]; |
---|
76 | $video['ext'] = 'wat'; |
---|
77 | if ($_POST['thumbnail'] == 'thumb_from_server') |
---|
78 | { |
---|
79 | @preg_match('#link rel="image_src" href="(.*?)"#', $source, $matches); |
---|
80 | $video['thumb_url'] = @str_replace('120x90', '320x240', $matches[1]); |
---|
81 | } |
---|
82 | return $video; |
---|
83 | } |
---|
84 | |
---|
85 | default: |
---|
86 | return false; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | // Creation du nouveau fichier |
---|
91 | if (isset($_POST['submit_add']) and !is_adviser()) |
---|
92 | { |
---|
93 | if (empty($_POST['pywaie_add_name']) or empty($_POST['pywaie_add_url']) or ($_POST['parent'] == 0)) |
---|
94 | { |
---|
95 | array_push($page['errors'], l10n('py_error2'), l10n('py_error3')); |
---|
96 | } |
---|
97 | elseif (!preg_match('/^[a-zA-Z0-9-_.]+$/', $_POST['pywaie_add_name'])) |
---|
98 | { |
---|
99 | array_push($page['errors'], l10n('update_wrong_dirname_info')); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | $py_url = $_POST['pywaie_add_url']; |
---|
104 | if (!substr_count($py_url, "http://")) $py_url = "http://" . $py_url; |
---|
105 | |
---|
106 | // Extraction de l'id et du type |
---|
107 | foreach ($video_types as $type) |
---|
108 | { |
---|
109 | if (substr_count($py_url, $type)) |
---|
110 | { |
---|
111 | $video = get_video_infos($py_url, $type); |
---|
112 | break; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | if (!isset($video) or !$video) |
---|
117 | { |
---|
118 | array_unshift($page['errors'], l10n('py_error5')); |
---|
119 | } |
---|
120 | else |
---|
121 | { |
---|
122 | $cat = $_POST['parent']; |
---|
123 | $video['name'] = str_replace(" ", "_", $_POST['pywaie_add_name']); |
---|
124 | $catpath = get_fulldirs(array($cat)); |
---|
125 | $path_file = $catpath[$cat] . '/' . $video['name'] . '.' . $video['ext']; |
---|
126 | $thefile = substr($path_file, 2); |
---|
127 | if (file_exists($path_file)) |
---|
128 | { |
---|
129 | array_push($page['errors'], sprintf(l10n('py_error6'), $thefile)); |
---|
130 | } |
---|
131 | else |
---|
132 | { |
---|
133 | $file = @fopen($thefile , 'w'); |
---|
134 | |
---|
135 | // Ecriture du fichier et attribution des messages |
---|
136 | if (@!fwrite ($file, stripslashes($video['id']) . '/' . $_POST['pywaie_add_h'] . '/' . $_POST['pywaie_add_w'] . '/' . $_POST['pywaie_add_start'])) |
---|
137 | { |
---|
138 | array_push($page['errors'], sprintf(l10n('py_error7'), $thefile), sprintf(l10n('py_error8'), $catpath[$cat])); |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | // Miniatures |
---|
143 | $thumb_extension = 'NULL'; |
---|
144 | if ($_POST['thumbnail'] == 'thumb_from_server' or $_POST['thumbnail'] == 'thumb_from_user') |
---|
145 | { |
---|
146 | include_once ('thumbnails.php'); |
---|
147 | } |
---|
148 | |
---|
149 | // Synchronisation avec la base de donnees |
---|
150 | $infos['name'] = (!empty($_POST['name']) ? '"' . $_POST['name'] . '"' : 'NULL'); |
---|
151 | $infos['description'] = (!empty($_POST['description']) ? '"' . $_POST['description'] . '"' : 'NULL'); |
---|
152 | $infos['author'] = (!empty($_POST['author']) ? '"' . $_POST['author'] . '"' : 'NULL'); |
---|
153 | |
---|
154 | $query = 'SELECT IF(MAX(id)+1 IS NULL, 1, MAX(id)+1) AS next_element_id FROM ' . IMAGES_TABLE . ' ;'; |
---|
155 | list($next_element_id) = mysql_fetch_array(pwg_query($query)); |
---|
156 | |
---|
157 | pwg_query('INSERT INTO ' . IMAGES_TABLE . ' ( id , file , date_available , date_creation , tn_ext , name , comment , author , hit , filesize , width , height , representative_ext , date_metadata_update , average_rate , has_high , path , storage_category_id , high_filesize ) |
---|
158 | VALUES ( ' . $next_element_id . ', "' . $video['name'] . '.' . $video['ext'] . '", NOW() , NULL , ' . $thumb_extension . ' , ' . $infos['name'] . ' , ' . $infos['description'] . ' , ' . $infos['author'] . ' , 0 , NULL , NULL , NULL , NULL , NULL , NULL , NULL , "' . $path_file . '", ' . $cat . ', NULL);'); |
---|
159 | pwg_query('INSERT INTO ' . IMAGE_CATEGORY_TABLE . ' ( image_id , category_id ) |
---|
160 | VALUES ( ' . $next_element_id . ', ' . $cat . ');'); |
---|
161 | |
---|
162 | $query = 'SELECT representative_picture_id FROM ' . CATEGORIES_TABLE . ' WHERE id =' . $cat . ';'; |
---|
163 | list($result) = mysql_fetch_array(pwg_query($query)); |
---|
164 | if ($result === NULL) |
---|
165 | { |
---|
166 | pwg_query('UPDATE ' . CATEGORIES_TABLE . ' SET representative_picture_id=' . $next_element_id . ' WHERE id = ' . $cat . ' LIMIT 1'); |
---|
167 | } |
---|
168 | |
---|
169 | invalidate_user_cache(); |
---|
170 | array_unshift($page['infos'], sprintf(l10n('py_info3'), $thefile)); |
---|
171 | array_push($page['infos'], sprintf(l10n('py_show_file'), PHPWG_ROOT_PATH . 'picture.php?/' . $next_element_id . '/category/' . $cat)); |
---|
172 | @fclose($file); |
---|
173 | } |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | |
---|
180 | // Affichage de la liste des categories |
---|
181 | $site_locaux = array(); |
---|
182 | $query = ' |
---|
183 | SELECT id , galleries_url |
---|
184 | FROM ' . SITES_TABLE . ' |
---|
185 | ORDER by id'; |
---|
186 | $result = pwg_query($query); |
---|
187 | |
---|
188 | if (mysql_num_rows($result) > 0) |
---|
189 | { |
---|
190 | while (list($id , $galleries_url) = mysql_fetch_row($result)) |
---|
191 | { |
---|
192 | if (!url_is_remote($galleries_url)) array_push($site_locaux , $id); |
---|
193 | } |
---|
194 | } |
---|
195 | if (empty($site_locaux)) |
---|
196 | { |
---|
197 | array_push($page['errors'], l10n('py_error1')); |
---|
198 | $site_locaux = array(0); |
---|
199 | } |
---|
200 | |
---|
201 | $query = ' |
---|
202 | SELECT id,name,uppercats,global_rank |
---|
203 | FROM ' . CATEGORIES_TABLE . ' |
---|
204 | WHERE site_id IN (' . implode("," , $site_locaux) . ');'; |
---|
205 | |
---|
206 | if (isset($_POST['parent'])) $selected = array($_POST['parent']); |
---|
207 | else $selected = array(); |
---|
208 | |
---|
209 | display_select_cat_wrapper($query, $selected , 'category_option_parent', false); |
---|
210 | |
---|
211 | |
---|
212 | // Parametrage du template |
---|
213 | if (isset($_POST['submit_add'])) |
---|
214 | { |
---|
215 | $template->assign(array( |
---|
216 | 'PYWAIE_ADD_NAME' => $_POST['pywaie_add_name'], |
---|
217 | 'PYWAIE_ADD_URL' => $_POST['pywaie_add_url'], |
---|
218 | $_POST['thumbnail'] . '_CHECKED' => 'checked="checked"', |
---|
219 | 'ADD_BAND' => isset($_POST['add_band']) ? 'checked="checked"' : '', |
---|
220 | 'THUMB_RESIZE' => isset($_POST['thumb_resize']) ? 'checked="checked"' : '', |
---|
221 | 'PYWAIE_ADD_START' => $_POST['pywaie_add_start'], |
---|
222 | 'PYWAIE_ADD_W' => $_POST['pywaie_add_w'], |
---|
223 | 'PYWAIE_ADD_H' => $_POST['pywaie_add_h'], |
---|
224 | 'NAME' => $_POST['name'], |
---|
225 | 'AUTHOR' => $_POST['author'], |
---|
226 | 'DESCRIPTION' => $_POST['description'])); |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | $template->assign(array('no_thumb_CHECKED' => 'checked="checked"')); |
---|
231 | } |
---|
232 | |
---|
233 | $template->assign(array( |
---|
234 | 'INFOBULLES_JS' => GVIDEO_PATH . 'admin/infobulles.js', |
---|
235 | 'ICON_INFOBULLE' => GVIDEO_PATH . 'admin/infobulle.png', |
---|
236 | 'DEFAULT_THUMB_W' => $conf['tn_width'], |
---|
237 | 'DEFAULT_THUMB_H' => $conf['tn_height'])); |
---|
238 | |
---|
239 | $template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/add_page.tpl')); |
---|
240 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); |
---|
241 | |
---|
242 | ?> |
---|