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 | // check inputs |
---|
48 | if (empty($_POST['url'])) |
---|
49 | { |
---|
50 | $page['errors'][] = l10n('Please fill the video URL'); |
---|
51 | } |
---|
52 | else if ($gvideo['url']!=$_POST['url']) |
---|
53 | { |
---|
54 | if ( ($video = parse_video_url($_POST['url'], isset($_POST['safe_mode']))) === false ) |
---|
55 | { |
---|
56 | if (isset($_POST['safe_mode'])) |
---|
57 | { |
---|
58 | $page['errors'][] = l10n('an error happened'); |
---|
59 | } |
---|
60 | else |
---|
61 | { |
---|
62 | $page['errors'][] = l10n('Unable to contact host server'); |
---|
63 | $page['errors'][] = l10n('Try in safe-mode'); |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | $video = $gvideo; |
---|
70 | } |
---|
71 | |
---|
72 | if (count($page['errors']) == 0) |
---|
73 | { |
---|
74 | |
---|
75 | if ( $gvideo['url'] != $video['url'] ) |
---|
76 | { |
---|
77 | // download thumbnail |
---|
78 | $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); |
---|
79 | $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; |
---|
80 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
81 | |
---|
82 | if (empty($video['thumbnail']) or gvideo_download_remote_file($video['thumbnail'], $thumb_source) !== true) |
---|
83 | { |
---|
84 | $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; |
---|
85 | copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
86 | } |
---|
87 | |
---|
88 | // add image and update infos |
---|
89 | $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $_GET['image_id']); |
---|
90 | |
---|
91 | $updates = array( |
---|
92 | 'name' => pwg_db_real_escape_string($video['title']), |
---|
93 | 'author' => pwg_db_real_escape_string($video['author']), |
---|
94 | 'is_gvideo' => 1, |
---|
95 | ); |
---|
96 | |
---|
97 | if ($_POST['sync_description'] and !empty($video['description'])) |
---|
98 | { |
---|
99 | $updates['comment'] = pwg_db_real_escape_string($video['description']); |
---|
100 | } |
---|
101 | else |
---|
102 | { |
---|
103 | $updates['comment'] = null; |
---|
104 | } |
---|
105 | if ($_POST['sync_tags'] and !empty($video['tags'])) |
---|
106 | { |
---|
107 | set_tags(get_tag_ids(implode(',', $video['tags'])), $image_id); |
---|
108 | } |
---|
109 | |
---|
110 | single_update( |
---|
111 | IMAGES_TABLE, |
---|
112 | $updates, |
---|
113 | array('id' => $_GET['image_id']), |
---|
114 | true |
---|
115 | ); |
---|
116 | } |
---|
117 | |
---|
118 | // register video |
---|
119 | if ($_POST['size_common'] == 'true') |
---|
120 | { |
---|
121 | $_POST['width'] = $_POST['height'] = ''; |
---|
122 | } |
---|
123 | else if (!preg_match('#^([0-9]+)$#', $_POST['width']) or !preg_match('#^([0-9]+)$#', $_POST['height'])) |
---|
124 | { |
---|
125 | $page['errors'][] = l10n('Width and height must be integers'); |
---|
126 | $_POST['width'] = $_POST['height'] = ''; |
---|
127 | } |
---|
128 | if ($_POST['autoplay_common'] == 'true') |
---|
129 | { |
---|
130 | $_POST['autoplay'] = ''; |
---|
131 | } |
---|
132 | |
---|
133 | $updates = array( |
---|
134 | 'url' => $video['url'], |
---|
135 | 'type' => $video['type'], |
---|
136 | 'video_id' => $video['video_id'], |
---|
137 | 'width' => $_POST['width'], |
---|
138 | 'height' => $_POST['height'], |
---|
139 | 'autoplay' => $_POST['autoplay'], |
---|
140 | ); |
---|
141 | |
---|
142 | single_update( |
---|
143 | GVIDEO_TABLE, |
---|
144 | $updates, |
---|
145 | array('picture_id' => $_GET['image_id']), |
---|
146 | true |
---|
147 | ); |
---|
148 | |
---|
149 | $page['infos'][] = l10n('Video successfully updated'); |
---|
150 | $gvideo = array_merge($gvideo, $updates); |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | // +-----------------------------------------------------------------------+ |
---|
155 | // | Update thumbnail (from Photo Update) | |
---|
156 | // +-----------------------------------------------------------------------+ |
---|
157 | if (isset($_FILES['photo_update'])) |
---|
158 | { |
---|
159 | if ($_FILES['photo_update']['error'] !== UPLOAD_ERR_OK) |
---|
160 | { |
---|
161 | $page['errors'][] = file_upload_error_message($_FILES['photo_update']['error']); |
---|
162 | } |
---|
163 | else |
---|
164 | { |
---|
165 | add_uploaded_file( |
---|
166 | $_FILES['photo_update']['tmp_name'], |
---|
167 | $_FILES['photo_update']['name'], |
---|
168 | null, |
---|
169 | null, |
---|
170 | $_GET['image_id'] |
---|
171 | ); |
---|
172 | |
---|
173 | $page['infos'][] = l10n('The thumbnail was updated'); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | // +-----------------------------------------------------------------------+ |
---|
178 | // | Add film frame | |
---|
179 | // +-----------------------------------------------------------------------+ |
---|
180 | if (function_exists('imagecreatetruecolor') and isset($_GET['add_film_frame'])) |
---|
181 | { |
---|
182 | $thumb_source = $conf['data_location'].$picture['file']; |
---|
183 | |
---|
184 | add_film_frame($picture['path'], $thumb_source); |
---|
185 | add_uploaded_file($thumb_source, $picture['file'], null, null, $_GET['image_id']); |
---|
186 | |
---|
187 | redirect($self_url); |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | // +-----------------------------------------------------------------------+ |
---|
192 | // | Template | |
---|
193 | // +-----------------------------------------------------------------------+ |
---|
194 | if (empty($gvideo['height'])) |
---|
195 | { |
---|
196 | $gvideo['size_common'] = 'true'; |
---|
197 | } |
---|
198 | if (empty($gvideo['autoplay'])) |
---|
199 | { |
---|
200 | $gvideo['autoplay_common'] = 'true'; |
---|
201 | } |
---|
202 | $gvideo['sync_description'] = $conf['gvideo']['sync_description']; |
---|
203 | $gvideo['sync_tags'] = $conf['gvideo']['sync_tags']; |
---|
204 | |
---|
205 | if (function_exists('imagecreatetruecolor')) |
---|
206 | { |
---|
207 | $template->assign('U_ADD_FILM_FRAME', $self_url.'&add_film_frame=1'); |
---|
208 | } |
---|
209 | |
---|
210 | $template->assign(array( |
---|
211 | 'F_ACTION' => $self_url, |
---|
212 | 'GVIDEO' => $gvideo, |
---|
213 | 'TN_SRC' => DerivativeImage::thumb_url($picture).'?'.time(), |
---|
214 | 'TITLE' => render_element_name($picture), |
---|
215 | )); |
---|
216 | |
---|
217 | $template->set_filename('gvideo_content', realpath(GVIDEO_PATH . 'admin/template/photo.tpl')); |
---|