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'], isset($_POST['safe_mode']))) === false ) |
---|
15 | { |
---|
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; |
---|
26 | } |
---|
27 | |
---|
28 | if (count($page['errors']) == 0) |
---|
29 | { |
---|
30 | // download thumbnail |
---|
31 | $thumb_ext = empty($video['thumbnail']) ? 'jpg' : get_extension($video['thumbnail']); |
---|
32 | $thumb_name = $video['type'].'-'.$video['video_id'].'-'.uniqid().'.'.$thumb_ext; |
---|
33 | $thumb_source = $conf['data_location'].$thumb_name; |
---|
34 | if ( empty($video['thumbnail']) or download_remote_file($video['thumbnail'], $thumb_source) !== true ) |
---|
35 | { |
---|
36 | $thumb_source = $conf['data_location'].get_filename_wo_extension($thumb_name).'.jpg'; |
---|
37 | copy(GVIDEO_PATH.'mimetypes/'.$video['type'].'.jpg', $thumb_source); |
---|
38 | } |
---|
39 | |
---|
40 | if (isset($_POST['add_film_frame'])) |
---|
41 | { |
---|
42 | add_film_frame($thumb_source); |
---|
43 | } |
---|
44 | |
---|
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']), |
---|
51 | 'is_gvideo' => 1, |
---|
52 | ); |
---|
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 | } |
---|
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') |
---|
72 | { |
---|
73 | $_POST['width'] = $_POST['height'] = ''; |
---|
74 | } |
---|
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 | } |
---|
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'], |
---|
89 | 'video_id' => $video['video_id'], |
---|
90 | 'width' => $_POST['width'], |
---|
91 | 'height' => $_POST['height'], |
---|
92 | 'autoplay' => $_POST['autoplay'], |
---|
93 | ); |
---|
94 | |
---|
95 | single_insert( |
---|
96 | GVIDEO_TABLE, |
---|
97 | $insert |
---|
98 | ); |
---|
99 | |
---|
100 | $query = ' |
---|
101 | SELECT id, name, permalink |
---|
102 | FROM '.CATEGORIES_TABLE.' |
---|
103 | WHERE id = '.$_POST['category'].' |
---|
104 | ;'; |
---|
105 | $category = pwg_db_fetch_assoc(pwg_query($query)); |
---|
106 | |
---|
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( |
---|
112 | 'id' => $category['id'], |
---|
113 | 'name' => $category['name'], |
---|
114 | 'permalink' => $category['permalink'], |
---|
115 | ), |
---|
116 | )) |
---|
117 | )); |
---|
118 | unset($_POST); |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | // categories |
---|
123 | $query = ' |
---|
124 | SELECT id,name,uppercats,global_rank |
---|
125 | FROM '.CATEGORIES_TABLE.' |
---|
126 | ;'; |
---|
127 | display_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, |
---|
143 | 'gd_available' => function_exists('imagecreatetruecolor'), |
---|
144 | 'gvideo' => $conf['gvideo'], |
---|
145 | 'POST' => @$_POST, |
---|
146 | )); |
---|
147 | |
---|
148 | $template->set_filename('gvideo_content', dirname(__FILE__) . '/template/add.tpl'); |
---|
149 | |
---|
150 | ?> |
---|