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

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

make url compatible with $confcategory_url_style='id-name';

File size: 3.4 KB
Line 
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  }
14  if ( !empty($_POST['url']) and ($video = parse_video_url($_POST['url'])) === false )
15  {
16    array_push($page['errors'], l10n('Unable to contact host server'));
17  }
18 
19  if (count($page['errors']) == 0)
20  {
21    // download thumbnail
22    $thumb_name = $video['type'].'-'.$video['id'].'-'.uniqid().'.'.get_extension($video['thumbnail']);
23    $thumb_source = $conf['data_location'].$thumb_name;
24    if (download_remote_file($video['thumbnail'], $thumb_source) !== true)
25    {
26      $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg';
27      copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source);
28    }
29   
30    if (isset($_POST['add_film_frame']))
31    {
32      add_film_frame($thumb_source);
33    }
34   
35    // add image and update infos
36    $image_id = add_uploaded_file($thumb_source, $thumb_name, array($_POST['category']));
37   
38    $updates = array(
39      'name' => pwg_db_real_escape_string($video['title']),
40      'comment' => pwg_db_real_escape_string($video['description']),
41      'author' => pwg_db_real_escape_string($video['author']),
42      );
43   
44    single_update(
45      IMAGES_TABLE,
46      $updates,
47      array('id' => $image_id),
48      true
49      );
50   
51    // register video
52    if ($_POST['size_common'] == 'true')
53    {
54      $_POST['width'] = $_POST['height'] = '';
55    }
56    if ($_POST['autoplay_common'] == 'true')
57    {
58      $_POST['autoplay'] = '';
59    }
60   
61    $insert = array(
62      'picture_id' => $image_id,
63      'url' => $video['url'],
64      'type' => $video['type'],
65      'video_id' => $video['id'],
66      'width' => $_POST['width'],
67      'height' => $_POST['height'],
68      'autoplay' => $_POST['autoplay'],
69      );
70     
71    single_insert(
72      GVIDEO_TABLE,
73      $insert
74      );
75     
76    $query = '
77SELECT id, name, permalink
78  FROM '.CATEGORIES_TABLE.'
79  WHERE id = '.$_POST['category'].'
80;';
81    $category = pwg_db_fetch_assoc(pwg_query($query));
82     
83    array_push($page['infos'], sprintf(
84      l10n('Video successfully added. <a href="%s">View</a>'), 
85      make_picture_url(array(
86        'image_id' => $image_id,
87        'category' => array(
88          'id' => $category['id'],
89          'name' => $category['name'],
90          'permalink' => $category['permalink'],
91          ),
92        ))
93      ));
94    unset($_POST);
95  }
96}
97
98// categories
99$query = '
100SELECT id,name,uppercats,global_rank
101  FROM '.CATEGORIES_TABLE.'
102;';
103display_select_cat_wrapper($query, array(), 'category_parent_options');
104
105// upload limit
106$upload_max_filesize = min(
107  get_ini_size('upload_max_filesize'),
108  get_ini_size('post_max_size')
109  );
110$upload_max_filesize_shorthand = 
111  ($upload_max_filesize == get_ini_size('upload_max_filesize')) ?
112  get_ini_size('upload_max_filesize', false) :
113  get_ini_size('post_max_filesize', false);
114 
115// template
116$template->assign(array(
117  'upload_max_filesize' => $upload_max_filesize,
118  'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
119  'gd_available' => function_exists('imagecreatetruecolor'),
120  'gvideo' => $conf['gvideo'],
121  'POST' => @$_POST,
122  ));
123
124$template->set_filename('gvideo_content', dirname(__FILE__) . '/template/add.tpl');
125
126?>
Note: See TracBrowser for help on using the repository browser.