1 | <?php |
---|
2 | defined('GVIDEO_PATH') or die ("Hacking attempt!"); |
---|
3 | |
---|
4 | include_once(GVIDEO_PATH.'include/functions.inc.php'); |
---|
5 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
6 | |
---|
7 | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | Basic checks | |
---|
10 | // +-----------------------------------------------------------------------+ |
---|
11 | check_status(ACCESS_ADMINISTRATOR); |
---|
12 | |
---|
13 | check_input_parameter('image_id', $_GET, false, PATTERN_ID); |
---|
14 | |
---|
15 | $admin_photo_base_url = get_root_url().'admin.php?page=photo-'.$_GET['image_id']; |
---|
16 | $self_url = GVIDEO_ADMIN.'-photo&image_id='.$_GET['image_id']; |
---|
17 | |
---|
18 | // +-----------------------------------------------------------------------+ |
---|
19 | // | Tabs | |
---|
20 | // +-----------------------------------------------------------------------+ |
---|
21 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
---|
22 | $tabsheet = new tabsheet(); |
---|
23 | $tabsheet->set_id('photo'); |
---|
24 | $tabsheet->select('gvideo'); |
---|
25 | $tabsheet->assign(); |
---|
26 | |
---|
27 | $page['active_menu'] = get_active_menu('photo'); |
---|
28 | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | // | Picture infos | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | global $gvideo; // request from GVIDEO_TABLE done when building tabsheet |
---|
33 | |
---|
34 | $query = ' |
---|
35 | SELECT * |
---|
36 | FROM '.IMAGES_TABLE.' |
---|
37 | WHERE id = '.$_GET['image_id'].' |
---|
38 | ;'; |
---|
39 | $picture = pwg_db_fetch_assoc(pwg_query($query)); |
---|
40 | |
---|
41 | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | // | Update properties | |
---|
44 | // +-----------------------------------------------------------------------+ |
---|
45 | if (isset($_POST['save_properties'])) |
---|
46 | { |
---|
47 | $_POST['url'] = trim($_POST['url']); |
---|
48 | |
---|
49 | if ($gvideo['type'] != 'embed') |
---|
50 | { |
---|
51 | // check inputs |
---|
52 | if (empty($_POST['url'])) |
---|
53 | { |
---|
54 | $page['errors'][] = l10n('Please fill the video URL'); |
---|
55 | } |
---|
56 | else if ($gvideo['url']!=$_POST['url']) |
---|
57 | { |
---|
58 | if ( ($video = parse_video_url($_POST['url'], $safe_mode)) === false ) |
---|
59 | { |
---|
60 | $page['errors'][] = l10n('an error happened'); |
---|
61 | } |
---|
62 | } |
---|
63 | else |
---|
64 | { |
---|
65 | $safe_mode = false; |
---|
66 | $video = $gvideo; |
---|
67 | } |
---|
68 | |
---|
69 | if (count($page['errors']) == 0) |
---|
70 | { |
---|
71 | if ($safe_mode === true) |
---|
72 | { |
---|
73 | $page['warnings'][] = l10n('Unable to contact host server'); |
---|
74 | $page['warnings'][] = l10n('Video data like description and thumbnail might be missing'); |
---|
75 | } |
---|
76 | |
---|
77 | if ($gvideo['url'] != $video['url']) |
---|
78 | { |
---|
79 | // download thumbnail |
---|
80 | $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); |
---|
81 | $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; |
---|
82 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
83 | |
---|
84 | if (empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true) |
---|
85 | { |
---|
86 | $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; |
---|
87 | copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
88 | } |
---|
89 | |
---|
90 | // add image and update infos |
---|
91 | $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $_GET['image_id']); |
---|
92 | |
---|
93 | $updates = array( |
---|
94 | 'name' => pwg_db_real_escape_string($video['title']), |
---|
95 | 'author' => pwg_db_real_escape_string($video['author']), |
---|
96 | 'is_gvideo' => 1, |
---|
97 | ); |
---|
98 | |
---|
99 | if ($_POST['sync_description'] and !empty($video['description'])) |
---|
100 | { |
---|
101 | $updates['comment'] = pwg_db_real_escape_string($video['description']); |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | $updates['comment'] = null; |
---|
106 | } |
---|
107 | if ($_POST['sync_tags'] and !empty($video['tags'])) |
---|
108 | { |
---|
109 | set_tags(get_tag_ids(implode(',', $video['tags'])), $image_id); |
---|
110 | } |
---|
111 | |
---|
112 | single_update( |
---|
113 | IMAGES_TABLE, |
---|
114 | $updates, |
---|
115 | array('id' => $_GET['image_id']), |
---|
116 | true |
---|
117 | ); |
---|
118 | } |
---|
119 | |
---|
120 | // register video |
---|
121 | if ($_POST['size_common'] == 'true') |
---|
122 | { |
---|
123 | $_POST['width'] = $_POST['height'] = ''; |
---|
124 | } |
---|
125 | else if (!preg_match('#^([0-9]+)$#', $_POST['width']) or !preg_match('#^([0-9]+)$#', $_POST['height'])) |
---|
126 | { |
---|
127 | $page['errors'][] = l10n('Width and height must be integers'); |
---|
128 | $_POST['width'] = $_POST['height'] = ''; |
---|
129 | } |
---|
130 | if ($_POST['autoplay_common'] == 'true') |
---|
131 | { |
---|
132 | $_POST['autoplay'] = ''; |
---|
133 | } |
---|
134 | |
---|
135 | $updates = array( |
---|
136 | 'url' => $video['url'], |
---|
137 | 'type' => $video['type'], |
---|
138 | 'video_id' => $video['video_id'], |
---|
139 | 'width' => $_POST['width'], |
---|
140 | 'height' => $_POST['height'], |
---|
141 | 'autoplay' => $_POST['autoplay'], |
---|
142 | ); |
---|
143 | } |
---|
144 | } |
---|
145 | else |
---|
146 | { |
---|
147 | $_POST['embed_code'] = trim($_POST['embed_code']); |
---|
148 | |
---|
149 | if (empty($_POST['embed_code'])) |
---|
150 | { |
---|
151 | $page['errors'][] = l10n('Please fill the embed code'); |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | $updates = array( |
---|
156 | 'url' => $_POST['url'], |
---|
157 | 'embed' => stripslashes($_POST['embed_code']), |
---|
158 | ); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | if (isset($updates)) |
---|
163 | { |
---|
164 | single_update( |
---|
165 | GVIDEO_TABLE, |
---|
166 | $updates, |
---|
167 | array('picture_id' => $_GET['image_id']), |
---|
168 | true |
---|
169 | ); |
---|
170 | |
---|
171 | $page['infos'][] = l10n('Video successfully updated'); |
---|
172 | $gvideo = array_merge($gvideo, $updates); |
---|
173 | } |
---|
174 | } |
---|
175 | |
---|
176 | // +-----------------------------------------------------------------------+ |
---|
177 | // | Update thumbnail (from Photo Update) | |
---|
178 | // +-----------------------------------------------------------------------+ |
---|
179 | if (isset($_FILES['photo_update'])) |
---|
180 | { |
---|
181 | if ($_FILES['photo_update']['error'] !== UPLOAD_ERR_OK) |
---|
182 | { |
---|
183 | $page['errors'][] = file_upload_error_message($_FILES['photo_update']['error']); |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | add_uploaded_file( |
---|
188 | $_FILES['photo_update']['tmp_name'], |
---|
189 | $_FILES['photo_update']['name'], |
---|
190 | null, |
---|
191 | null, |
---|
192 | $_GET['image_id'] |
---|
193 | ); |
---|
194 | |
---|
195 | $page['infos'][] = l10n('The thumbnail was updated'); |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | // +-----------------------------------------------------------------------+ |
---|
200 | // | Add film frame | |
---|
201 | // +-----------------------------------------------------------------------+ |
---|
202 | if (function_exists('imagecreatetruecolor') and isset($_GET['add_film_frame'])) |
---|
203 | { |
---|
204 | $thumb_source = $conf['data_location'].$picture['file']; |
---|
205 | |
---|
206 | add_film_frame($picture['path'], $thumb_source); |
---|
207 | add_uploaded_file($thumb_source, $picture['file'], null, null, $_GET['image_id']); |
---|
208 | |
---|
209 | redirect($self_url); |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | // +-----------------------------------------------------------------------+ |
---|
214 | // | Template | |
---|
215 | // +-----------------------------------------------------------------------+ |
---|
216 | if (empty($gvideo['height'])) |
---|
217 | { |
---|
218 | $gvideo['size_common'] = 'true'; |
---|
219 | } |
---|
220 | if (empty($gvideo['autoplay'])) |
---|
221 | { |
---|
222 | $gvideo['autoplay_common'] = 'true'; |
---|
223 | } |
---|
224 | $gvideo['sync_description'] = $conf['gvideo']['sync_description']; |
---|
225 | $gvideo['sync_tags'] = $conf['gvideo']['sync_tags']; |
---|
226 | |
---|
227 | if (function_exists('imagecreatetruecolor')) |
---|
228 | { |
---|
229 | $template->assign('U_ADD_FILM_FRAME', $self_url.'&add_film_frame=1'); |
---|
230 | } |
---|
231 | |
---|
232 | $template->assign(array( |
---|
233 | 'F_ACTION' => $self_url, |
---|
234 | 'GVIDEO' => $gvideo, |
---|
235 | 'TN_SRC' => DerivativeImage::thumb_url($picture).'?'.time(), |
---|
236 | 'TITLE' => render_element_name($picture), |
---|
237 | )); |
---|
238 | |
---|
239 | $template->set_filename('gvideo_content', realpath(GVIDEO_PATH . 'admin/template/photo.tpl')); |
---|