source: extensions/gvideo/admin/add.php @ 19213

Last change on this file since 19213 was 19213, checked in by mistic100, 11 years ago
  • add safe mode
  • fix little error when adding video without thumbnail
File size: 4.3 KB
RevLine 
[17307]1<?php
2if (!defined('GVIDEO_PATH')) die('Hacking attempt!');
3
4include_once(GVIDEO_PATH.'include/functions.inc.php');
5include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
6
7if (isset($_POST['add_video']))
8{
9  // check inputs
10  if (empty($_POST['url']))
11  {
12    array_push($page['errors'], l10n('Please fill the video URL'));
13  }
[19213]14  if ( !empty($_POST['url']) and ($video = parse_video_url($_POST['url'], isset($_POST['safe_mode']))) === false )
[17307]15  {
[19213]16    if (isset($_POST['safe_mode']))
17    {
18      array_push($page['errors'], l10n('an error happened'));
19    }
20    else
21    {
22      array_push($page['errors'], l10n('Unable to contact host server'));
23      array_push($page['errors'], l10n('Try in safe-mode'));
24    }
25    $_POST['safe_mode'] = true;
[17307]26  }
27 
28  if (count($page['errors']) == 0)
29  {
30    // download thumbnail
[19213]31    $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']);
32    $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext;
[17383]33    $thumb_source = $conf['data_location'].$thumb_name;
[19213]34    if ( empty($video['thumbnail']) or download_remote_file($video['thumbnail'], $thumb_source) !== true )
[17307]35    {
[17383]36      $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
37      copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
[17307]38    }
[17383]39   
40    if (isset($_POST['add_film_frame']))
[17307]41    {
[17383]42      add_film_frame($thumb_source);
[17307]43    }
44   
[17383]45    // add image and update infos
46    $image_id = add_uploaded_file($thumb_source, $thumb_name, array($_POST['category']));
47   
48    $updates = array(
49      'name' => pwg_db_real_escape_string($video['title']),
50      'author' => pwg_db_real_escape_string($video['author']),
[17488]51      'is_gvideo' => 1,
[17383]52      );
[19056]53     
54    if ( $_POST['sync_description'] and !empty($video['description']) )
55    {
56      $updates['comment'] = pwg_db_real_escape_string($video['description']);
57    }
58    if ( $_POST['sync_tags'] and !empty($video['tags']) )
59    {
60      set_tags(get_tag_ids(implode(',', $video['tags'])), $image_id);
61    }
[17383]62   
63    single_update(
64      IMAGES_TABLE,
65      $updates,
66      array('id' => $image_id),
67      true
68      );
69   
70    // register video
71    if ($_POST['size_common'] == 'true')
[17307]72    {
[17383]73      $_POST['width'] = $_POST['height'] = '';
74    }
[19056]75    else if ( !preg_match('#^([0-9]+)$#', $_POST['width']) or !preg_match('#^([0-9]+)$#', $_POST['height']) )
76    {
77      array_push($page['errors'], l10n('Width and height must be integers'));
78      $_POST['width'] = $_POST['height'] = '';
79    }
[17383]80    if ($_POST['autoplay_common'] == 'true')
81    {
82      $_POST['autoplay'] = '';
83    }
84   
85    $insert = array(
86      'picture_id' => $image_id,
87      'url' => $video['url'],
88      'type' => $video['type'],
[19056]89      'video_id' => $video['video_id'],
[17383]90      'width' => $_POST['width'],
91      'height' => $_POST['height'],
92      'autoplay' => $_POST['autoplay'],
93      );
[17310]94     
[17383]95    single_insert(
96      GVIDEO_TABLE,
97      $insert
98      );
[17307]99     
[17432]100    $query = '
101SELECT id, name, permalink
102  FROM '.CATEGORIES_TABLE.'
103  WHERE id = '.$_POST['category'].'
104;';
105    $category = pwg_db_fetch_assoc(pwg_query($query));
106     
[17383]107    array_push($page['infos'], sprintf(
108      l10n('Video successfully added. <a href="%s">View</a>'), 
109      make_picture_url(array(
110        'image_id' => $image_id,
111        'category' => array(
[17432]112          'id' => $category['id'],
113          'name' => $category['name'],
114          'permalink' => $category['permalink'],
[17383]115          ),
116        ))
117      ));
118    unset($_POST);
[17307]119  }
120}
121
122// categories
123$query = '
124SELECT id,name,uppercats,global_rank
125  FROM '.CATEGORIES_TABLE.'
126;';
127display_select_cat_wrapper($query, array(), 'category_parent_options');
128
129// upload limit
130$upload_max_filesize = min(
131  get_ini_size('upload_max_filesize'),
132  get_ini_size('post_max_size')
133  );
134$upload_max_filesize_shorthand = 
135  ($upload_max_filesize == get_ini_size('upload_max_filesize')) ?
136  get_ini_size('upload_max_filesize', false) :
137  get_ini_size('post_max_filesize', false);
138 
139// template
140$template->assign(array(
141  'upload_max_filesize' => $upload_max_filesize,
142  'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
[17383]143  'gd_available' => function_exists('imagecreatetruecolor'),
[17307]144  'gvideo' => $conf['gvideo'],
145  'POST' => @$_POST,
146  ));
147
148$template->set_filename('gvideo_content', dirname(__FILE__) . '/template/add.tpl');
149
150?>
Note: See TracBrowser for help on using the repository browser.