|
14 | 14 | include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php'); |
15 | 15 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
16 | 16 |
|
17 | | -$allowed_extensions = array('jpg','jpeg','png','gif'); |
18 | | -$allowed_mimes = array('image/jpeg', 'image/png', 'image/gif'); |
19 | | - |
20 | 17 | $tabsheet = new tabsheet(); |
21 | 18 | $tabsheet->set_id('photos_add'); |
22 | 19 | $tabsheet->select('url_uploader'); |
|
25 | 22 | $page['active_menu'] = get_active_menu('photo'); |
26 | 23 |
|
27 | 24 |
|
28 | | -// +-----------------------------------------------------------------------+ |
29 | | -// | process form | |
30 | | -// +-----------------------------------------------------------------------+ |
31 | | -if (isset($_GET['processed'])) |
32 | | -{ |
33 | | - $category_id = $_POST['category']; |
34 | | - $image_ids = array(); |
35 | | - $page['thumbnails'] = array(); |
36 | | - |
37 | | - // SINGLE UPLOAD |
38 | | - if ($_GET['upload_mode'] == 'single') |
39 | | - { |
40 | | - $_POST = array_map('trim', $_POST); |
41 | | - |
42 | | - // check empty url |
43 | | - if (empty($_POST['file_url'])) |
44 | | - { |
45 | | - $page['errors'][] = l10n('File URL is empty'); |
46 | | - } |
47 | | - // check remote url |
48 | | - else if (!url_is_remote($_POST['file_url'])) |
49 | | - { |
50 | | - $page['errors'][] = l10n('Invalid file URL'); |
51 | | - } |
52 | | - // check file extension |
53 | | - else if (!in_array(strtolower(get_extension($_POST['file_url'])), $allowed_extensions)) |
54 | | - { |
55 | | - $page['errors'][] = l10n('Invalid file type'); |
56 | | - } |
57 | | - // continue... |
58 | | - else |
59 | | - { |
60 | | - $temp_filename = $conf['data_location'].basename($_POST['file_url']); |
61 | | - $file = fopen($temp_filename, 'w+'); |
62 | | - $result = fetchRemote($_POST['file_url'], $file); |
63 | | - fclose($file); |
64 | | - |
65 | | - // download failed ? |
66 | | - if (!$result) |
67 | | - { |
68 | | - @unlink($temp_filename); |
69 | | - $page['errors'][] = l10n('Unable to download file'); |
70 | | - } |
71 | | - // check mime-type |
72 | | - else if (!in_array(get_mime($temp_filename, $allowed_mimes[0]), $allowed_mimes)) |
73 | | - { |
74 | | - @unlink($temp_filename); |
75 | | - $page['errors'][] = l10n('Invalid file type'); |
76 | | - } |
77 | | - // continue... |
78 | | - else |
79 | | - { |
80 | | - $image_id = add_uploaded_file( |
81 | | - $temp_filename, |
82 | | - basename($temp_filename), |
83 | | - array($category_id), |
84 | | - $_POST['level'] |
85 | | - ); |
86 | | - |
87 | | - $updates = array(); |
88 | | - if (!empty($_POST['photo_name'])) |
89 | | - { |
90 | | - $updates['name'] = $_POST['photo_name']; |
91 | | - } |
92 | | - if (isset($_POST['url_in_comment'])) |
93 | | - { |
94 | | - $url = parse_url($_POST['file_url']); |
95 | | - $url = $url['scheme'].'://'.$url['host']; |
96 | | - $updates['comment'] = '<a href="'. $url . '">'. $url .'</a>'; |
97 | | - } |
98 | | - |
99 | | - single_update( |
100 | | - IMAGES_TABLE, |
101 | | - $updates, |
102 | | - array('id' => $image_id) |
103 | | - ); |
104 | | - |
105 | | - $image_ids = array($image_id); |
106 | | - } |
107 | | - } |
108 | | - } |
109 | | - // MULTIPLE UPLOAD |
110 | | - else if ($_GET['upload_mode'] == 'multiple') |
111 | | - { |
112 | | - if (isset($_POST['onUploadError']) and is_array($_POST['onUploadError']) and count($_POST['onUploadError']) > 0) |
113 | | - { |
114 | | - $page['errors'][] = l10n('%d photos not imported', count($_POST['onUploadError'])); |
115 | | - foreach ($_POST['onUploadError'] as $error) |
116 | | - { |
117 | | - $page['errors'][] = $error; |
118 | | - } |
119 | | - } |
120 | | - |
121 | | - if (isset($_POST['imageIds']) and is_array($_POST['imageIds']) and count($_POST['imageIds']) > 0) |
122 | | - { |
123 | | - $image_ids = $_POST['imageIds']; |
124 | | - } |
125 | | - } |
126 | | - |
127 | | - // DISPLAY RESULTS |
128 | | - foreach ($image_ids as $image_id) |
129 | | - { |
130 | | - $query = ' |
131 | | -SELECT id, file, path |
132 | | - FROM '.IMAGES_TABLE.' |
133 | | - WHERE id = '.$image_id.' |
134 | | -;'; |
135 | | - $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
136 | | - |
137 | | - $thumbnail = array( |
138 | | - 'file' => $image_infos['file'], |
139 | | - 'src' => DerivativeImage::thumb_url($image_infos), |
140 | | - 'title' => get_name_from_file($image_infos['file']), |
141 | | - 'link' => get_root_url().'admin.php?page=photo-'.$image_id.'&cat_id='.$category_id, |
142 | | - ); |
143 | | - |
144 | | - $page['thumbnails'][] = $thumbnail; |
145 | | - } |
146 | | - |
147 | | - if (!empty($page['thumbnails'])) |
148 | | - { |
149 | | - // nb uploaded |
150 | | - $page['infos'][] = l10n('%d photos uploaded', count($page['thumbnails'])); |
151 | | - |
152 | | - // level |
153 | | - if (0 != $_POST['level']) |
154 | | - { |
155 | | - $page['infos'][] = l10n('Privacy level set to "%s"', l10n(sprintf('Level %d', $_POST['level']))); |
156 | | - } |
157 | | - |
158 | | - // new category count |
159 | | - $query = ' |
160 | | -SELECT COUNT(*) |
161 | | - FROM '.IMAGE_CATEGORY_TABLE.' |
162 | | - WHERE category_id = '.$category_id.' |
163 | | -;'; |
164 | | - list($count) = pwg_db_fetch_row(pwg_query($query)); |
165 | | - $category_name = get_cat_display_name_from_id($category_id, 'admin.php?page=album-'); |
166 | | - |
167 | | - $page['infos'][] = l10n('Album "%s" now contains %d photos', '<em>'.$category_name.'</em>', $count); |
168 | | - |
169 | | - $page['batch_link'] = PHOTOS_ADD_BASE_URL.'&batch='.implode(',', $image_ids); |
170 | | - } |
171 | | -} |
172 | | - |
173 | | - |
174 | 25 | // +-----------------------------------------------------------------------+ |
175 | 26 | // | prepare form | |
176 | 27 | // +-----------------------------------------------------------------------+ |
177 | 28 | include(PHPWG_ROOT_PATH.'admin/include/photos_add_direct_prepare.inc.php'); |
178 | 29 |
|
179 | | -// upload mode |
180 | | -$upload_modes = array('single', 'multiple'); |
181 | | -$upload_mode = isset($conf['url_uploader_mode']) ? $conf['url_uploader_mode'] : 'single'; |
182 | | - |
183 | | -if (isset($_GET['upload_mode']) and $_GET['upload_mode']!=$upload_mode and in_array($_GET['upload_mode'], $upload_modes)) |
184 | | -{ |
185 | | - $upload_mode = $_GET['upload_mode']; |
186 | | - conf_update_param('url_uploader_mode', $upload_mode); |
187 | | -} |
188 | | - |
189 | | -// what is the upload switch mode |
190 | | -$index_of_upload_mode = array_flip($upload_modes); |
191 | | -$upload_mode_index = $index_of_upload_mode[$upload_mode]; |
192 | | -$upload_switch = $upload_modes[ ($upload_mode_index + 1) % 2 ]; |
193 | | - |
194 | | -$template->assign(array( |
195 | | - 'upload_mode' => $upload_mode, |
196 | | - 'form_action' => URLUPLOADER_ADMIN.'&upload_mode='.$upload_mode.'&processed=1', |
197 | | - 'switch_url' => URLUPLOADER_ADMIN.'&upload_mode='.$upload_switch, |
198 | | - 'another_upload_link' => URLUPLOADER_ADMIN.'&upload_mode='.$upload_mode, |
199 | | - )); |
200 | | - |
201 | | - |
202 | 30 | $template->set_filename('urluploader_content', realpath(URLUPLOADER_PATH . 'template/photos_add.tpl')); |
203 | 31 |
|
204 | 32 | // template vars |
|
0 commit comments