source: extensions/url_uploader/admin.php @ 20064

Last change on this file since 20064 was 20064, checked in by mistic100, 11 years ago

remove useless plugins menu item

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