1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based photo gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2012 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!"); |
---|
25 | |
---|
26 | include_once(GVIDEO_PATH.'include/functions.inc.php'); |
---|
27 | |
---|
28 | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | // | Basic checks | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | |
---|
33 | check_status(ACCESS_ADMINISTRATOR); |
---|
34 | |
---|
35 | check_input_parameter('image_id', $_GET, false, PATTERN_ID); |
---|
36 | |
---|
37 | $admin_photo_base_url = get_root_url().'admin.php?page=photo-'.$_GET['image_id']; |
---|
38 | $self_url = GVIDEO_ADMIN.'-photo&image_id='.$_GET['image_id']; |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | Tabs | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
44 | $tabsheet = new tabsheet(); |
---|
45 | $tabsheet->set_id('photo'); |
---|
46 | $tabsheet->select('gvideo'); |
---|
47 | $tabsheet->assign(); |
---|
48 | |
---|
49 | // +-----------------------------------------------------------------------+ |
---|
50 | // | Picture infos | |
---|
51 | // +-----------------------------------------------------------------------+ |
---|
52 | global $gvideo; |
---|
53 | |
---|
54 | $query = ' |
---|
55 | SELECT * |
---|
56 | FROM '.IMAGES_TABLE.' |
---|
57 | WHERE id = '.$_GET['image_id'].' |
---|
58 | ;'; |
---|
59 | $picture = pwg_db_fetch_assoc(pwg_query($query)); |
---|
60 | |
---|
61 | |
---|
62 | // +-----------------------------------------------------------------------+ |
---|
63 | // | Update properties | |
---|
64 | // +-----------------------------------------------------------------------+ |
---|
65 | if (isset($_POST['save_properties'])) |
---|
66 | { |
---|
67 | // check inputs |
---|
68 | if (empty($_POST['url'])) |
---|
69 | { |
---|
70 | array_push($page['errors'], l10n('Please fill the video URL')); |
---|
71 | } |
---|
72 | else if ($gvideo['url']!=$_POST['url']) |
---|
73 | { |
---|
74 | if( ($video = parse_video_url($_POST['url'], isset($_POST['safe_mode']))) === false ) |
---|
75 | { |
---|
76 | if (isset($_POST['safe_mode'])) |
---|
77 | { |
---|
78 | array_push($page['errors'], l10n('an error happened')); |
---|
79 | } |
---|
80 | else |
---|
81 | { |
---|
82 | array_push($page['errors'], l10n('Unable to contact host server')); |
---|
83 | array_push($page['errors'], l10n('Try in safe-mode')); |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | $video = $gvideo; |
---|
90 | } |
---|
91 | |
---|
92 | if (count($page['errors']) == 0) |
---|
93 | { |
---|
94 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
95 | |
---|
96 | if ( $gvideo['url'] != $video['url'] ) |
---|
97 | { |
---|
98 | // download thumbnail |
---|
99 | $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); |
---|
100 | $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; |
---|
101 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
102 | if ( empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true ) |
---|
103 | { |
---|
104 | $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; |
---|
105 | copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
106 | } |
---|
107 | |
---|
108 | // add image and update infos |
---|
109 | $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $_GET['image_id']); |
---|
110 | |
---|
111 | $updates = array( |
---|
112 | 'name' => pwg_db_real_escape_string($video['title']), |
---|
113 | 'author' => pwg_db_real_escape_string($video['author']), |
---|
114 | 'is_gvideo' => 1, |
---|
115 | ); |
---|
116 | |
---|
117 | if ( $_POST['sync_description'] and !empty($video['description']) ) |
---|
118 | { |
---|
119 | $updates['comment'] = pwg_db_real_escape_string($video['description']); |
---|
120 | } |
---|
121 | else |
---|
122 | { |
---|
123 | $updates['comment'] = null; |
---|
124 | } |
---|
125 | if ( $_POST['sync_tags'] and !empty($video['tags']) ) |
---|
126 | { |
---|
127 | set_tags(get_tag_ids(implode(',', $video['tags'])), $image_id); |
---|
128 | } |
---|
129 | |
---|
130 | single_update( |
---|
131 | IMAGES_TABLE, |
---|
132 | $updates, |
---|
133 | array('id' => $_GET['image_id']), |
---|
134 | true |
---|
135 | ); |
---|
136 | } |
---|
137 | |
---|
138 | // register video |
---|
139 | if ($_POST['size_common'] == 'true') |
---|
140 | { |
---|
141 | $_POST['width'] = $_POST['height'] = ''; |
---|
142 | } |
---|
143 | else if ( !preg_match('#^([0-9]+)$#', $_POST['width']) or !preg_match('#^([0-9]+)$#', $_POST['height']) ) |
---|
144 | { |
---|
145 | array_push($page['errors'], l10n('Width and height must be integers')); |
---|
146 | $_POST['width'] = $_POST['height'] = ''; |
---|
147 | } |
---|
148 | if ($_POST['autoplay_common'] == 'true') |
---|
149 | { |
---|
150 | $_POST['autoplay'] = ''; |
---|
151 | } |
---|
152 | |
---|
153 | $updates = array( |
---|
154 | 'url' => $video['url'], |
---|
155 | 'type' => $video['type'], |
---|
156 | 'video_id' => $video['video_id'], |
---|
157 | 'width' => $_POST['width'], |
---|
158 | 'height' => $_POST['height'], |
---|
159 | 'autoplay' => $_POST['autoplay'], |
---|
160 | ); |
---|
161 | |
---|
162 | single_update( |
---|
163 | GVIDEO_TABLE, |
---|
164 | $updates, |
---|
165 | array('picture_id' => $_GET['image_id']), |
---|
166 | true |
---|
167 | ); |
---|
168 | |
---|
169 | array_push($page['infos'], l10n('Video successfully updated')); |
---|
170 | $gvideo = array_merge($gvideo, $updates); |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | // +-----------------------------------------------------------------------+ |
---|
175 | // | Update thumbnail (from Photo Update) | |
---|
176 | // +-----------------------------------------------------------------------+ |
---|
177 | if (isset($_FILES['photo_update'])) |
---|
178 | { |
---|
179 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
180 | |
---|
181 | if ($_FILES['photo_update']['error'] !== UPLOAD_ERR_OK) |
---|
182 | { |
---|
183 | array_push($page['errors'], |
---|
184 | file_upload_error_message($_FILES['photo_update']['error']) |
---|
185 | ); |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | add_uploaded_file( |
---|
190 | $_FILES['photo_update']['tmp_name'], |
---|
191 | $_FILES['photo_update']['name'], |
---|
192 | null, |
---|
193 | null, |
---|
194 | $_GET['image_id'] |
---|
195 | ); |
---|
196 | |
---|
197 | array_push($page['infos'], l10n('The thumbnail was updated')); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | // +-----------------------------------------------------------------------+ |
---|
202 | // | Add film frame | |
---|
203 | // +-----------------------------------------------------------------------+ |
---|
204 | if ( function_exists('imagecreatetruecolor') and isset($_GET['add_film_frame']) ) |
---|
205 | { |
---|
206 | include_once(GVIDEO_PATH . '/include/functions.inc.php'); |
---|
207 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
208 | |
---|
209 | $thumb_source = $conf['data_location'].$picture['file']; |
---|
210 | |
---|
211 | add_film_frame($picture['path'], $thumb_source); |
---|
212 | add_uploaded_file($thumb_source, $picture['file'], null, null, $_GET['image_id']); |
---|
213 | |
---|
214 | redirect($self_url); |
---|
215 | } |
---|
216 | |
---|
217 | |
---|
218 | // +-----------------------------------------------------------------------+ |
---|
219 | // | Template | |
---|
220 | // +-----------------------------------------------------------------------+ |
---|
221 | if (empty($gvideo['height'])) |
---|
222 | { |
---|
223 | $gvideo['size_common'] = 'true'; |
---|
224 | } |
---|
225 | if (empty($gvideo['autoplay'])) |
---|
226 | { |
---|
227 | $gvideo['autoplay_common'] = 'true'; |
---|
228 | } |
---|
229 | $gvideo['sync_description'] = $conf['gvideo']['sync_description']; |
---|
230 | $gvideo['sync_tags'] = $conf['gvideo']['sync_tags']; |
---|
231 | |
---|
232 | if (function_exists('imagecreatetruecolor')) |
---|
233 | { |
---|
234 | $template->assign('U_ADD_FILM_FRAME', $self_url.'&add_film_frame=1'); |
---|
235 | } |
---|
236 | |
---|
237 | $template->assign(array( |
---|
238 | 'F_ACTION' => $self_url, |
---|
239 | 'GVIDEO' => $gvideo, |
---|
240 | 'TN_SRC' => DerivativeImage::thumb_url($picture).'?'.time(), |
---|
241 | 'TITLE' => render_element_name($picture), |
---|
242 | )); |
---|
243 | |
---|
244 | $template->set_filename('gvideo_content', dirname(__FILE__).'/template/photo.tpl'); |
---|
245 | |
---|
246 | ?> |
---|