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

Last change on this file since 19056 was 19056, checked in by mistic100, 11 years ago

allow to add private dailymotion videos, remove videobb support, add tags support

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