1 | <?php |
---|
2 | if (!defined('GVIDEO_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | include_once(GVIDEO_PATH.'include/functions.inc.php'); |
---|
5 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); |
---|
6 | |
---|
7 | if (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['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 | 'author' => pwg_db_real_escape_string($video['author']), |
---|
41 | 'is_gvideo' => 1, |
---|
42 | ); |
---|
43 | |
---|
44 | if ( $_POST['sync_description'] and !empty($video['description']) ) |
---|
45 | { |
---|
46 | $updates['comment'] = pwg_db_real_escape_string($video['description']); |
---|
47 | } |
---|
48 | if ( $_POST['sync_tags'] and !empty($video['tags']) ) |
---|
49 | { |
---|
50 | set_tags(get_tag_ids(implode(',', $video['tags'])), $image_id); |
---|
51 | } |
---|
52 | |
---|
53 | single_update( |
---|
54 | IMAGES_TABLE, |
---|
55 | $updates, |
---|
56 | array('id' => $image_id), |
---|
57 | true |
---|
58 | ); |
---|
59 | |
---|
60 | // register video |
---|
61 | if ($_POST['size_common'] == 'true') |
---|
62 | { |
---|
63 | $_POST['width'] = $_POST['height'] = ''; |
---|
64 | } |
---|
65 | else if ( !preg_match('#^([0-9]+)$#', $_POST['width']) or !preg_match('#^([0-9]+)$#', $_POST['height']) ) |
---|
66 | { |
---|
67 | array_push($page['errors'], l10n('Width and height must be integers')); |
---|
68 | $_POST['width'] = $_POST['height'] = ''; |
---|
69 | } |
---|
70 | if ($_POST['autoplay_common'] == 'true') |
---|
71 | { |
---|
72 | $_POST['autoplay'] = ''; |
---|
73 | } |
---|
74 | |
---|
75 | $insert = array( |
---|
76 | 'picture_id' => $image_id, |
---|
77 | 'url' => $video['url'], |
---|
78 | 'type' => $video['type'], |
---|
79 | 'video_id' => $video['video_id'], |
---|
80 | 'width' => $_POST['width'], |
---|
81 | 'height' => $_POST['height'], |
---|
82 | 'autoplay' => $_POST['autoplay'], |
---|
83 | ); |
---|
84 | |
---|
85 | single_insert( |
---|
86 | GVIDEO_TABLE, |
---|
87 | $insert |
---|
88 | ); |
---|
89 | |
---|
90 | $query = ' |
---|
91 | SELECT id, name, permalink |
---|
92 | FROM '.CATEGORIES_TABLE.' |
---|
93 | WHERE id = '.$_POST['category'].' |
---|
94 | ;'; |
---|
95 | $category = pwg_db_fetch_assoc(pwg_query($query)); |
---|
96 | |
---|
97 | array_push($page['infos'], sprintf( |
---|
98 | l10n('Video successfully added. <a href="%s">View</a>'), |
---|
99 | make_picture_url(array( |
---|
100 | 'image_id' => $image_id, |
---|
101 | 'category' => array( |
---|
102 | 'id' => $category['id'], |
---|
103 | 'name' => $category['name'], |
---|
104 | 'permalink' => $category['permalink'], |
---|
105 | ), |
---|
106 | )) |
---|
107 | )); |
---|
108 | unset($_POST); |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | // categories |
---|
113 | $query = ' |
---|
114 | SELECT id,name,uppercats,global_rank |
---|
115 | FROM '.CATEGORIES_TABLE.' |
---|
116 | ;'; |
---|
117 | display_select_cat_wrapper($query, array(), 'category_parent_options'); |
---|
118 | |
---|
119 | // upload limit |
---|
120 | $upload_max_filesize = min( |
---|
121 | get_ini_size('upload_max_filesize'), |
---|
122 | get_ini_size('post_max_size') |
---|
123 | ); |
---|
124 | $upload_max_filesize_shorthand = |
---|
125 | ($upload_max_filesize == get_ini_size('upload_max_filesize')) ? |
---|
126 | get_ini_size('upload_max_filesize', false) : |
---|
127 | get_ini_size('post_max_filesize', false); |
---|
128 | |
---|
129 | // template |
---|
130 | $template->assign(array( |
---|
131 | 'upload_max_filesize' => $upload_max_filesize, |
---|
132 | 'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand, |
---|
133 | 'gd_available' => function_exists('imagecreatetruecolor'), |
---|
134 | 'gvideo' => $conf['gvideo'], |
---|
135 | 'POST' => @$_POST, |
---|
136 | )); |
---|
137 | |
---|
138 | $template->set_filename('gvideo_content', dirname(__FILE__) . '/template/add.tpl'); |
---|
139 | |
---|
140 | ?> |
---|