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

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

-restore option to add film frame effect (improved)
-update mimetypes to avoid double frames

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