|
| 1 | +<?php |
| 2 | +/*********************************************** |
| 3 | +* File : admin_config.php |
| 4 | +* Project : piwigo-openstreetmap |
| 5 | +* Descr : Install / Uninstall method |
| 6 | +* |
| 7 | +* Created : 28.05.2013 |
| 8 | +* |
| 9 | +* Copyright 2013-2014 <xbgmsharp@gmail.com> |
| 10 | +* |
| 11 | +* This program is free software: you can redistribute it and/or modify |
| 12 | +* it under the terms of the GNU General Public License as published by |
| 13 | +* the Free Software Foundation, either version 3 of the License, or |
| 14 | +* (at your option) any later version. |
| 15 | +* |
| 16 | +* This program is distributed in the hope that it will be useful, |
| 17 | +* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | +* GNU General Public License for more details. |
| 20 | +* |
| 21 | +* You should have received a copy of the GNU General Public License |
| 22 | +* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 | +* |
| 24 | +************************************************/ |
| 25 | + |
| 26 | +// Check whether we are indeed included by Piwigo. |
| 27 | +if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
| 28 | + |
| 29 | +// Check access and exit when user status is not ok |
| 30 | +check_status(ACCESS_ADMINISTRATOR); |
| 31 | + |
| 32 | +// Setup plugin Language |
| 33 | +load_language('plugin.lang', OSM_PATH); |
| 34 | + |
| 35 | + |
| 36 | +if (isset($_POST['submit'])) { |
| 37 | + $uploaded_errors = array(); |
| 38 | + $upload_file = array(); |
| 39 | + |
| 40 | + if($_FILES['file_uploaded']['size'] != 0) { |
| 41 | + $upload_file = gps_upload_file(pwg_db_real_escape_string($_FILES['file_uploaded'])); |
| 42 | + if(count($upload_file['errors']) != 0) |
| 43 | + $uploaded_errors['file'] = $upload_file['errors']; |
| 44 | + } else { |
| 45 | + $uploaded_errors['file']['no_file'] = l10n('Specify a file to upload'); |
| 46 | + } |
| 47 | + |
| 48 | + if (count($uploaded_errors) == 0) { |
| 49 | + $file_path = pwg_db_real_escape_string($upload_file['destination']); |
| 50 | + $category = pwg_db_real_escape_string($_POST['category']); |
| 51 | + $query="INSERT INTO ".$prefixeTable."gps ( `category_id`, `path` ) VALUES ('$category', '$file_path');"; |
| 52 | + pwg_query($query); |
| 53 | + array_push($page['infos'], l10n('File uploaded and synchronized')); |
| 54 | + } else { |
| 55 | + array_push($page['errors'], l10n('There have been errors. See below')); |
| 56 | + $template->assign('uploaded_errors', $uploaded_errors); |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +function gps_upload_file($uploaded_file) { |
| 61 | + $uploaded_galleries_dir = PHPWG_ROOT_PATH.'galleries/gps/'; |
| 62 | + $uploaded_file_tmp = $uploaded_file['tmp_name']; |
| 63 | + $uploaded_file_name = preg_replace('/[^a-zA-Z0-9s.]/', '_', $uploaded_file['name']); |
| 64 | + $uploaded_file_destination = $uploaded_galleries_dir . '/' . $uploaded_file_name; |
| 65 | + $ext = pathinfo($uploaded_file_name)['extension'] |
| 66 | + $uploaded_errors = array(); |
| 67 | + if(!in_array($ext, array('csv', 'gpx', 'kml', 'wkt', 'topojson', 'geojson'))) { |
| 68 | + $uploaded_errors['upload_error'] = l10n('Extension not supported'); |
| 69 | + } else if ($uploaded_file['error'] !== UPLOAD_ERR_OK) { |
| 70 | + switch ($_FILES['file_uploaded']['error']) { |
| 71 | + case UPLOAD_ERR_INI_SIZE: |
| 72 | + $uploaded_errors['upload_error'] = l10n('File exceeds the upload_max_filesize directive in php.ini'); |
| 73 | + break; |
| 74 | + case UPLOAD_ERR_PARTIAL: |
| 75 | + $uploaded_errors['upload_error'] = l10n('File was only partially uploaded'); |
| 76 | + break; |
| 77 | + case UPLOAD_ERR_NO_FILE: |
| 78 | + $uploaded_errors['upload_error'] = l10n('No file to upload'); |
| 79 | + break; |
| 80 | + case UPLOAD_ERR_NO_TMP_DIR: |
| 81 | + $uploaded_errors['upload_error'] = l10n('Missing a temporary folder'); |
| 82 | + break; |
| 83 | + case UPLOAD_ERR_CANT_WRITE: |
| 84 | + $uploaded_errors['upload_error'] = l10n('Failed to write file to disk'); |
| 85 | + break; |
| 86 | + case UPLOAD_ERR_EXTENSION: |
| 87 | + $uploaded_errors['upload_error'] = l10n('File upload stopped by extension'); |
| 88 | + break; |
| 89 | + default: |
| 90 | + $uploaded_errors['upload_error'] = l10n('Upload error'); |
| 91 | + } |
| 92 | + } else if (file_exists($uploaded_file_destination)) { |
| 93 | + $uploaded_errors['already_exist'] = l10n('file_uploader_error_already_exist'); |
| 94 | + } else if (!move_uploaded_file($uploaded_file_tmp, $uploaded_file_destination)) { |
| 95 | + $uploaded_errors['move_uploaded_file'] = l10n('Can\'t upload file to galleries directory'); |
| 96 | + } |
| 97 | + $return['errors'] = $uploaded_errors; |
| 98 | + $return['destination'] = $uploaded_file_destination; |
| 99 | + return $return; |
| 100 | +} |
| 101 | + |
| 102 | +//Categories |
| 103 | +$query = 'SELECT id,name,uppercats,global_rank FROM '.CATEGORIES_TABLE.';'; |
| 104 | +display_select_cat_wrapper($query, array(), 'category_gps'); |
| 105 | + |
0 commit comments