source: extensions/gvideo/admin/photo.php @ 17687

Last change on this file since 17687 was 17687, checked in by mistic100, 12 years ago

big mistakes on photo properties page

File size: 7.7 KB
Line 
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
24if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!");
25
26include_once(GVIDEO_PATH.'include/functions.inc.php');
27
28
29// +-----------------------------------------------------------------------+
30// | Basic checks                                                          |
31// +-----------------------------------------------------------------------+
32
33check_status(ACCESS_ADMINISTRATOR);
34
35check_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&amp;image_id='.$_GET['image_id'];
39
40// +-----------------------------------------------------------------------+
41// | Tabs                                                                  |
42// +-----------------------------------------------------------------------+
43include_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// +-----------------------------------------------------------------------+
52global $gvideo;
53
54$query = '
55SELECT *
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// +-----------------------------------------------------------------------+
65if (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  if ( !empty($_POST['url']) and ($video = parse_video_url($_POST['url'])) === false )
73  {
74    array_push($page['errors'], l10n('Unable to contact host server'));
75  }
76 
77  if (count($page['errors']) == 0)
78  {
79    include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
80
81    if ( $gvideo['url'] != $video['url'] )
82    {
83      // download thumbnail
84      $thumb_name = $video['type'].'-'.$video['id'].'-'.uniqid().'.'.get_extension($video['thumbnail']);
85      $thumb_source = $conf['data_location'].$thumb_name;
86      if (download_remote_file($video['thumbnail'], $thumb_source) !== true)
87      {
88        $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
89        copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
90      }
91     
92      // add image and update infos
93      $image_id = add_uploaded_file($thumb_source, $thumb_name, null, null, $_GET['image_id']);
94     
95      $updates = array(
96        'name' => pwg_db_real_escape_string($video['title']),
97        'comment' => pwg_db_real_escape_string($video['description']),
98        'author' => pwg_db_real_escape_string($video['author']),
99        'is_gvideo' => 1,
100        );
101     
102      single_update(
103        IMAGES_TABLE,
104        $updates,
105        array('id' => $_GET['image_id']),
106        true
107        );
108    }
109   
110    // register video
111    if ($_POST['size_common'] == 'true')
112    {
113      $_POST['width'] = $_POST['height'] = '';
114    }
115    else if ( !preg_match('#^([0-9]+)$#', $_POST['width']) or !preg_match('#^([0-9]+)$#', $_POST['height']) )
116    {
117      array_push($page['errors'], l10n('Width and height must be integers'));
118      $_POST['width'] = $_POST['height'] = '';
119    }
120    if ($_POST['autoplay_common'] == 'true')
121    {
122      $_POST['autoplay'] = '';
123    }
124   
125    $updates = array(
126      'url' => $video['url'],
127      'type' => $video['type'],
128      'video_id' => $video['id'],
129      'width' => $_POST['width'],
130      'height' => $_POST['height'],
131      'autoplay' => $_POST['autoplay'],
132      );
133     
134    single_update(
135      GVIDEO_TABLE,
136      $updates,
137      array('picture_id' => $_GET['image_id']),
138      true
139      );
140     
141    array_push($page['infos'], l10n('Video successfully updated'));
142    $gvideo = array_merge($gvideo, $updates);
143  }
144}
145
146// +-----------------------------------------------------------------------+
147// | Update thumbnail (from Photo Update)                                  |
148// +-----------------------------------------------------------------------+
149if (isset($_FILES['photo_update']))
150{
151  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
152 
153  if ($_FILES['photo_update']['error'] !== UPLOAD_ERR_OK)
154  {
155    array_push($page['errors'],
156      file_upload_error_message($_FILES['photo_update']['error'])
157      );
158  }
159  else
160  {
161    add_uploaded_file(
162      $_FILES['photo_update']['tmp_name'],
163      $_FILES['photo_update']['name'],
164      null,
165      null,
166      $_GET['image_id']
167      );
168
169    array_push($page['infos'], l10n('The thumbnail was updated'));
170  }
171}
172
173// +-----------------------------------------------------------------------+
174// | Add film frame                                                        |
175// +-----------------------------------------------------------------------+
176if ( function_exists('imagecreatetruecolor') and isset($_GET['add_film_frame']) )
177{
178  include_once(GVIDEO_PATH . '/include/functions.inc.php');
179  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
180 
181  $thumb_source = $conf['data_location'].$picture['file'];
182 
183  add_film_frame($picture['path'], $thumb_source);
184  add_uploaded_file($thumb_source, $picture['file'], null, null, $_GET['image_id']);
185 
186  redirect($self_url);
187}
188
189
190// +-----------------------------------------------------------------------+
191// | Template                                                              |
192// +-----------------------------------------------------------------------+
193if (empty($gvideo['height']))
194{
195  $gvideo['size_common'] = 'true';
196}
197if (empty($gvideo['autoplay']))
198{
199  $gvideo['autoplay_common'] = 'true';
200}
201
202if (function_exists('imagecreatetruecolor'))
203{
204  $template->assign('U_ADD_FILM_FRAME', $self_url.'&amp;add_film_frame=1');
205}
206
207$template->assign(array(
208  'F_ACTION' => $self_url,
209  'GVIDEO' => $gvideo,
210  'TN_SRC' => DerivativeImage::thumb_url($picture).'?'.time(),
211  'TITLE' => render_element_name($picture),
212));
213
214$template->set_filename('gvideo_content', dirname(__FILE__).'/template/photo.tpl');
215
216?>
Note: See TracBrowser for help on using the repository browser.