Changeset 19875


Ignore:
Timestamp:
01/06/13 01:53:17 (7 years ago)
Author:
julien1311
Message:

[file_uploader] lots of bug fixes

Location:
extensions/File_Uploader
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • extensions/File_Uploader/admin/admin_upload.php

    r19835 r19875  
    33 
    44include_once(PHPWG_ROOT_PATH . 'include/functions.inc.php'); 
     5include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php'); 
    56 
    67global $template, $conf, $user, $page; 
     
    1516                        $file_uploader_errors['file'] = $file_uploader_upload_file['errors']; 
    1617        } else { 
    17                 $file_uploader_errors['file']['no_file'] = 'Specify a file to upload'; 
     18                $file_uploader_errors['file']['no_file'] = l10n('Specify a file to upload'); 
    1819        } 
    1920         
     
    3738 
    3839function file_uploader_upload_file($file_uploader_file) { 
    39         include_once(dirname(__FILE__).'/install/config_default.inc.php'); 
     40        require(FILE_UPLOADER_PATH.'install/config_default.inc.php'); 
     41        require_once(FILE_UPLOADER_PATH.'install/functions.inc.php'); 
    4042         
    4143        global $conf; 
     
    4345         
    4446        $file_uploader_file_tmp = $file_uploader_file['tmp_name']; 
     47        $file_uploader_file_title = substr($file_uploader_file['name'], 0, strrpos($file_uploader_file['name'], '.')); 
    4548        $file_uploader_file_name = preg_replace('/[^a-zA-Z0-9s.]/', '_', $file_uploader_file['name']); 
    4649        $file_uploader_file_name_wo_extension = substr($file_uploader_file_name, 0, strrpos($file_uploader_file_name, '.')); 
     
    5861        $return = array(); 
    5962         
     63        $return['title'] = $file_uploader_file_title; 
    6064        $return['name_wo_extension'] = $file_uploader_file_name_wo_extension; 
    6165        $return['extension'] = $file_uploader_file_extension; 
     
    6468        $return['size'] = $file_uploader_file_size; 
    6569        $return['overwrite'] = false; 
     70         
     71        //Check if the folder file_uploader exists 
     72        file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir, $file_uploader_galleries_folder_name); 
    6673         
    6774        //If the directory does not exist, we create it 
     
    7481                        $category_rank = pwg_db_fetch_assoc(pwg_query('SELECT MAX(rank) FROM '.CATEGORIES_TABLE.';')); 
    7582                        $category_rank = $category_rank['MAX(rank)'] + 1; 
    76                         $file_uploader_physical_category_id = pwg_db_fetch_assoc(pwg_query('SELECT id FROM '.CATEGORIES_TABLE.' WHERE name = "'.$file_uploader_galleries_folder.'";')); 
    77                         pwg_query('INSERT INTO '.CATEGORIES_TABLE.' (id, name, dir, rank, status, visible, uppercats, global_rank, site_id) VALUES ('.$next_id.', "'.$file_uploader_file_category.'", "'.$file_uploader_file_category.'", '.$category_rank.', "private", "'.boolean_to_string($conf['newcat_default_visible']).'", "'.$file_uploader_physical_category_id.'", '.$category_rank.', 1);'); 
     83                        $file_uploader_physical_category = pwg_db_fetch_assoc(pwg_query('SELECT id FROM '.CATEGORIES_TABLE.' WHERE dir = "'.$file_uploader_galleries_folder.'";')); 
     84                        $insert = array( 
     85                                'id' => $next_id, 
     86                                'name' => $file_uploader_file_category, 
     87                                'id_uppercat' => $file_uploader_physical_category['id'], 
     88                                'comment' => 'Created by the File Uploader plugin', 
     89                                'dir' => $file_uploader_file_category, 
     90                                'rank' => $category_rank, 
     91                                'status' => 'private', 
     92                                'visible' => boolean_to_string($conf['newcat_default_visible']), 
     93                                'uppercats' => $next_id.','.$file_uploader_physical_category['id'], 
     94                                'global_rank' => $category_rank, 
     95                                'site_id' => '1', 
     96                        ); 
     97                        single_insert(CATEGORIES_TABLE, $insert); 
    7898                } 
    7999         
     
    117137 
    118138function file_uploader_upload_thumbnail($file_uploader_thumbnail, $file_uploader_file_name_wo_extension, $file_uploader_file_extension, $file_uploader_file_folder) { 
    119         include_once(dirname(__FILE__).'/install/config_default.inc.php'); 
     139        require(FILE_UPLOADER_PATH.'install/config_default.inc.php'); 
    120140         
    121141        $file_uploader_thumbnail_tmp = $file_uploader_thumbnail['tmp_name']; 
     
    179199        $insert = array( 
    180200                'file' => substr(strrchr($file_path, '/'), 1), 
    181                 'name' => pwg_db_real_escape_string($file_uploader_file_properties['title']), 
     201                'name' => ($file_uploader_file_properties['title'] != '') ? pwg_db_real_escape_string($file_uploader_file_properties['title']) : $file_uploader_file['title'], 
    182202                'comment' => pwg_db_real_escape_string($file_uploader_file_properties['description']), 
    183203                'date_available' => $dbnow, 
     
    199219        } 
    200220         
     221        if (!is_array($image_id)) 
     222                $image_id = array($image_id); 
     223         
    201224        if(isset($file_uploader_file_properties['category']) and count($file_uploader_file_properties['category']) > 0) { 
    202225                associate_images_to_categories( 
    203                         array($image_id), 
     226                        $image_id, 
    204227                        array($file_uploader_file_properties['category'], $physical_category_id['id']) 
    205228                ); 
    206229        } 
    207230         
    208         @fill_caddie(array($image_id)); 
     231        @fill_caddie($image_id); 
    209232} 
    210233 
     
    214237display_select_cat_wrapper($query, array(), 'category_parent_options'); 
    215238 
     239//Add parameters to template 
     240$upload_max_filesize = min(get_ini_size('upload_max_filesize'), get_ini_size('post_max_size')); 
     241if ($upload_max_filesize == get_ini_size('upload_max_filesize')) { 
     242        $upload_max_filesize = get_ini_size('upload_max_filesize', true); 
     243} else { 
     244        $upload_max_filesize = get_ini_size('post_max_filesize', true); 
     245} 
     246$upload_max_filesize_display = round($upload_max_filesize/1024, 0, PHP_ROUND_HALF_DOWN); 
     247 
     248$template->assign( 
     249    array( 
     250                'upload_max_filesize' => $upload_max_filesize, 
     251                'upload_max_filesize_display' => $upload_max_filesize_display, 
     252    ) 
     253); 
     254 
    216255$template->set_filenames(array('plugin_admin_content' => dirname(__FILE__) . '/admin_upload.tpl'));  
    217256$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content'); 
  • extensions/File_Uploader/admin/admin_upload.tpl

    r19775 r19875  
    1515                                <input name="file_uploader_file" type="file" value=""{if isset($file_uploader_errors.file)} class="file_uploader_error"{/if}> 
    1616                                {foreach from=$file_uploader_errors.file item=error_description}<span class="file_uploader_error_description" title="{$error_description}">!</span>{/foreach} 
     17                                <input type="hidden" name="MAX_FILE_SIZE" value="{$upload_max_filesize}"> 
     18                        </p> 
     19                        <p class="file_uploader_center"> 
     20                                {'file_uploader_upload_max_filesize'|@translate} {$upload_max_filesize_display} Kio. 
    1721                        </p> 
    1822                </fieldset> 
  • extensions/File_Uploader/install/config_default.inc.php

    r19821 r19875  
    11<?php 
    22$file_uploader_galleries_folder = 'file_uploader'; 
     3$file_uploader_galleries_folder_name = 'File Uploader'; 
    34$file_uploader_galleries_dir = PHPWG_ROOT_PATH.'galleries/'.$file_uploader_galleries_folder.'/'; 
    45 
     
    3233); 
    3334 
    34 $config_default = array( 
    35         'new_tab' => 1, 
    36         'overwrite' => 0, 
     35$file_uploader_default_config = array( 
     36        'new_tab' => '1', 
     37        'overwrite' => '0', 
    3738        'pdf2tab_extensions' => array('pdf', 'docx', 'doc', 'odt', 'xlsx', 'xls', 'ods', 'pptx', 'ppt', 'odp'), 
    3839); 
  • extensions/File_Uploader/install/functions.inc.php

    r19821 r19875  
    55} 
    66 
    7 function file_uploader_update_db() { 
     7function file_uploader_update_db($file_uploader_default_config) { 
    88        global $conf; 
    9         include(dirname(__FILE__).'/config_default.inc.php'); 
    10  
     9         
    1110        $config = array(); 
    12         if (isset($conf['file_uploader'])) 
     11         
     12        if (isset($conf['file_uploader'])) { 
    1313                $conf_file_uploader = unserialize($conf['file_uploader']); 
    14          
    15         if (isset($conf_file_uploader)) { 
    16                 foreach ($config_default as $key => $value) { 
     14                foreach ($file_uploader_default_config as $key => $value) { 
    1715                        if (isset($conf_file_uploader[$key])) 
    1816                                $config[$key] = $conf_file_uploader[$key]; 
    1917                        else 
    20                                 $config[$key] = $config_default[$key]; 
     18                                $config[$key] = $file_uploader_default_config[$key]; 
    2119                } 
    2220                file_uploader_delete_conf("file_uploader"); 
    2321                file_uploader_install($config); 
    2422        } else { 
    25                 file_uploader_install($config_default); 
     23                file_uploader_install($file_uploader_default_config); 
    2624        } 
    2725} 
     
    3230} 
    3331 
    34 function file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir) { 
     32function file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir, $file_uploader_galleries_folder_name) { 
    3533        //If the directory does not exist, we create it 
    3634        if (!file_exists($file_uploader_galleries_dir)) 
    3735                if(!mkdir($file_uploader_galleries_dir)) 
    3836                        array_push($page['errors'], l10n('Unable to create folder ').$file_uploader_galleries_dir); 
    39                 //If the physical category si not in database, we add it 
    40                 else if (pwg_db_num_rows(pwg_query('SELECT id FROM '.CATEGORIES_TABLE.' WHERE name = "'.$file_uploader_galleries_folder.'";')) == 0){ 
     37                //If the physical category is not in database, we add it 
     38                else if (pwg_db_num_rows(pwg_query('SELECT id FROM '.CATEGORIES_TABLE.' WHERE dir = "'.$file_uploader_galleries_folder.'";')) == 0){ 
    4139                        $next_id = pwg_db_nextval('id', CATEGORIES_TABLE); 
    4240                        $category_rank = pwg_db_fetch_assoc(pwg_query('SELECT MAX(rank) FROM '.CATEGORIES_TABLE.';')); 
    4341                        $category_rank = $category_rank['MAX(rank)'] + 1; 
    44                         pwg_query('INSERT INTO '.CATEGORIES_TABLE.' (id, name, dir, rank, status, visible, uppercats, global_rank, site_id) VALUES ('.$next_id.', "'.$file_uploader_galleries_folder.'", "'.$file_uploader_file_category.'", '.$category_rank.', "private", "true", "'.$next_id.'", '.$category_rank.', 1);'); 
     42                        pwg_query('INSERT INTO '.CATEGORIES_TABLE.' (id, name, comment, dir, rank, status, visible, uppercats, global_rank, site_id) VALUES ('.$next_id.', "'.$file_uploader_galleries_folder_name.'", "Created by the File Uploader plugin", "'.$file_uploader_galleries_folder.'", '.$category_rank.', "private", "true", "'.$next_id.'", '.$category_rank.', 1);'); 
    4543                } 
    4644} 
  • extensions/File_Uploader/language/da_DK/plugin.lang.php

    r19848 r19875  
    4646$lang[': Check to overwrite files during upload if a file with the same name already exists.'] = ': Sæt flueben for at overskrive filer ved upload, hvis en fil med det samme navn allerede findes.'; 
    4747$lang['Album:'] = 'Album:'; 
    48 $lang['Can\'t copy file to galleries directory'] = 'Kan ikke kopiere filen til galleri-mappen'; 
     48$lang['Can\'t upload file to galleries directory'] = 'Kan ikke kopiere filen til galleri-mappen'; 
    4949$lang['Choose a file'] = 'Vælg en fil'; 
    5050$lang['Configuration'] = 'Opsætning'; 
  • extensions/File_Uploader/language/de_DE/plugin.lang.php

    r19864 r19875  
    4545$lang[': Check to overwrite files during upload if a file with the same name already exists.'] = ': Auswählen um Dateien zu überschreiben falls sie schon mit gleichen Namen existieren.'; 
    4646$lang['Album:'] = 'Album:'; 
    47 $lang['Can\'t copy file to galleries directory'] = 'Kann Datei nicht in Galerie Ordner kopieren'; 
     47$lang['Can\'t upload file to galleries directory'] = 'Kann Datei nicht in Galerie Ordner kopieren'; 
    4848$lang['Choose a file'] = 'Wähle eine Datei'; 
    4949$lang['Choose a thumbnail'] = 'Wähle eine Vorschaubild'; 
  • extensions/File_Uploader/language/el_GR/plugin.lang.php

    r19821 r19875  
    4848$lang['Choose a thumbnail'] = 'Επιλέξτε μια μικρογραφία'; 
    4949$lang['Choose a file'] = 'Επιλέξτε ένα αρχείο'; 
    50 $lang['Can\'t copy file to galleries directory'] = 'Δεν είναι δυνατή η αντιγραφή του αρχείου σε κατάλογο γκαλερί '; 
     50$lang['Can\'t upload file to galleries directory'] = 'Δεν είναι δυνατή η αντιγραφή του αρχείου σε κατάλογο γκαλερί '; 
    5151$lang['Album:'] = 'Λεύκωμα: '; 
    5252$lang[': Check to overwrite files during upload if a file with the same name already exists.'] = ': Ελέγξτε να αντικαταστήσετε τα αρχεία κατά τη διάρκεια της αποστολής, αν ένα αρχείο με το ίδιο όνομα υπάρχει ήδη.'; 
  • extensions/File_Uploader/language/en_UK/plugin.lang.php

    r19849 r19875  
    2121$lang['file_uploader_error_already_exist'] = 'File with this name already exists. You should rename this file. If you want to overwrite the file, modify the configuration in the configuration tab.'; 
    2222$lang['Invalid file name'] = 'Invalid file name'; 
    23 $lang['Can\'t copy file to galleries directory'] = 'Can\'t copy file to galleries directory'; 
     23$lang['Can\'t upload file to galleries directory'] = 'Can\'t upload file to galleries directory'; 
    2424$lang['The thumbnail must be a picture'] = 'The thumbnail must be a picture'; 
    2525$lang['File uploaded and synchronized'] = 'File uploaded and synchronized'; 
     
    2929$lang['Choose a file'] = 'Choose a file'; 
    3030$lang['File to upload:'] = 'File to upload:'; 
     31$lang['file_uploader_upload_max_filesize'] = 'Your server impose a maximum file size of'; 
    3132$lang['Choose a thumbnail'] = 'Choose a thumbnail'; 
    3233$lang['Thumbnail to upload:'] = 'Thumbnail to upload:'; 
     
    4142$lang['Open files in a new tab'] = 'Open files in a new tab'; 
    4243$lang['Overwrite files without notice'] = 'Overwrite files without notice'; 
    43 $lang['file_uploader_pdf2tab_supported_extensions_description'] = 'Type in the extensions PDF2Tab will handle. The extensions are case insensitive.'; 
     44$lang['file_uploader_pdf2tab_supported_extensions_description'] = 'Type in the extensions the plugin will open in new tabs or download. The extensions are case insensitive.'; 
    4445$lang['file_uploader_pdf2tab_hint_text'] = 'Type in an extension'; 
    4546 
  • extensions/File_Uploader/language/es_ES/plugin.lang.php

    r19821 r19875  
    4646$lang[': Check to overwrite files during upload if a file with the same name already exists.'] = ': marca para sobrescribir los archivos durante la subida si un archivo con el mismo nombre ya existe.'; 
    4747$lang['Album:'] = 'Album'; 
    48 $lang['Can\'t copy file to galleries directory'] = 'No se pudo copiar el archivo al directorio de la galeria.'; 
     48$lang['Can\'t upload file to galleries directory'] = 'No se pudo copiar el archivo al directorio de la galeria.'; 
    4949$lang['Choose a file'] = 'Elige un archivo'; 
    5050$lang['Choose a thumbnail'] = 'Elige una miniatura'; 
  • extensions/File_Uploader/language/fr_FR/plugin.lang.php

    r19839 r19875  
    2121$lang['file_uploader_error_already_exist'] = 'Un fichier avec le même nom existe déjà. Vous devriez renommer ce fichier. Si vous voulez remplacer le fichier, modifiez la configuration dans l\'onglet configuration'; 
    2222$lang['Invalid file name'] = 'Nom de fichier non valide'; 
    23 $lang['Can\'t copy file to galleries directory'] = 'Copie ver le répertoire galleries impossible'; 
     23$lang['Can\'t upload file to galleries directory'] = 'Copie ver le répertoire galleries impossible'; 
    2424$lang['The thumbnail must be a picture'] = 'La miniature doit être une image'; 
    2525$lang['File uploaded and synchronized'] = 'Fichier transféré et synchronisé'; 
     
    2929$lang['Choose a file'] = 'Choisir un fichier'; 
    3030$lang['File to upload:'] = 'Fichier à transférer :'; 
     31$lang['file_uploader_upload_max_filesize'] = 'Votre serveur impose une taille des fichiers maximale de'; 
    3132$lang['Choose a thumbnail'] = 'Choisir une miniature'; 
    3233$lang['Thumbnail to upload:'] = 'Miniature à transférer :'; 
     
    4142$lang['Open files in a new tab'] = 'Ouvrir les fichiers dans un nouvel onglet'; 
    4243$lang['Overwrite files without notice'] = 'Remplacer les fichiers sans avertissement'; 
    43 $lang['file_uploader_pdf2tab_supported_extensions_description'] = 'Entrer les extensions que le plugin prendra en charge. Les extensions ne sont pas sensibles à la casse.'; 
     44$lang['file_uploader_pdf2tab_supported_extensions_description'] = 'Entrer les extensions que le plugin ouvrira dans un nouvel onglet ou téléchargera. Les extensions ne sont pas sensibles à la casse.'; 
    4445$lang['file_uploader_pdf2tab_hint_text'] = 'Entrer une extension'; 
    4546 
  • extensions/File_Uploader/language/hu_HU/plugin.lang.php

    r19821 r19875  
    2626$lang['Piwigo is a free software (opensource software), you can use it for free and this is not going to change. Donations are collected by the Piwigo Foundation (non profit organization) to cover project fees.'] = 'A Piwigo egy free szoftver (opensource szoftver), melyet ingyenesen használhat és ez nem fog változni. Az adományok a Piwigo Foundation (non profit szervezet) projekt költségeinek fedezetére fordítódnak.'; 
    2727$lang['Unable to create folder '] = 'Nem sikerült létrehozni a mappát'; 
    28 $lang['Can\'t copy file to galleries directory'] = 'Nem lehet a fájlt a galéria könyvtárba másolni'; 
     28$lang['Can\'t upload file to galleries directory'] = 'Nem lehet a fájlt a galéria könyvtárba másolni'; 
    2929$lang['Overwrite files without notice'] = 'Fájlok felülírása figyelmeztetés nélkül'; 
    3030$lang['Specify a file to upload'] = 'Adja meg a feltöltendő fájlt'; 
  • extensions/File_Uploader/language/tr_TR/plugin.lang.php

    r19821 r19875  
    5757$lang['Choose a thumbnail'] = 'Bir küçük resim (thumbnail) seçin'; 
    5858$lang['Choose a file'] = 'Bir dosya seçin'; 
    59 $lang['Can\'t copy file to galleries directory'] = 'Dosya galeriler dizinine kopyalanamadı'; 
     59$lang['Can\'t upload file to galleries directory'] = 'Dosya galeriler dizinine kopyalanamadı'; 
    6060$lang['Album:'] = 'Albüm:'; 
    6161$lang[': Check to overwrite files during upload if a file with the same name already exists.'] = ': Yükleme sırasında aynı isimde dosya varsa üzerine yazılması için işaretleyin.'; 
  • extensions/File_Uploader/main.inc.php

    r19821 r19875  
    1616define('FILE_UPLOADER_PATH' , PHPWG_PLUGINS_PATH.FILE_UPLOADER_DIR.'/'); 
    1717define('FILE_UPLOADER_ADMIN',   get_root_url() . 'admin.php?page=plugin-'.FILE_UPLOADER_DIR); 
     18define('FILE_UPLOADER_PDF2TAB_PATH' , FILE_UPLOADER_PATH.'/plugin_pdf2tab/'); 
    1819define('FILE_UPLOADER_PDF2TAB_ABSOLUTE_PATH' , dirname(__FILE__).'/plugin_pdf2tab/'); 
    1920 
     
    3940 * +-----------------------------------------------------------------------+ */ 
    4041$conf_file_uploader = unserialize($conf['file_uploader']); 
    41 if ($conf_file_uploader['new_tab'] == 1) { 
     42if (isset($conf_file_uploader['new_tab']) && $conf_file_uploader['new_tab'] == 1) { 
    4243        load_language('plugin.lang', FILE_UPLOADER_PATH); 
    4344        include_once(FILE_UPLOADER_PDF2TAB_ABSOLUTE_PATH.'include/thumbnails.inc.php'); 
     
    5556        global $template; 
    5657 
    57         //add a stylesheet 
    58         $template->append('head_elements', '<link rel="stylesheet" type="text/css" href="'.FILE_UPLOADER_PATH.'admin/admin.css">'); 
    59         $template->append('head_elements', '<link rel="stylesheet" type="text/css" href="'.FILE_UPLOADER_PDF2TAB_ABSOLUTE_PATH.'css/admin.css">'); 
     58        if (defined('IN_ADMIN') and IN_ADMIN) { 
     59                $template->append('head_elements', '<link rel="stylesheet" type="text/css" href="'.FILE_UPLOADER_PATH.'admin/admin.css">'); 
     60                $template->append('head_elements', '<link rel="stylesheet" type="text/css" href="'.FILE_UPLOADER_PDF2TAB_PATH.'css/admin.css">'); 
     61        } 
    6062} 
    6163?> 
  • extensions/File_Uploader/maintain.inc.php

    r19821 r19875  
    33 
    44function plugin_install() { 
    5         include_once(dirname(__FILE__).'/install/config_default.inc.php'); 
    6         include_once(dirname(__FILE__).'/install/functions.inc.php'); 
     5        require_once('install/functions.inc.php'); 
     6        require('install/config_default.inc.php'); 
    77 
    8         file_uploader_install($config_default); 
    9          
    10         file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir); 
     8        file_uploader_install($file_uploader_default_config); 
     9        file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir, $file_uploader_galleries_folder_name); 
    1110} 
    1211 
    1312function plugin_activate() { 
    14         include_once(dirname(__FILE__).'/install/config_default.inc.php'); 
    15         include_once(dirname(__FILE__).'/install/functions.inc.php'); 
     13        require_once('install/functions.inc.php'); 
     14        require('install/config_default.inc.php'); 
    1615         
    17         file_uploader_update_db(); 
    18         file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir); 
     16        file_uploader_update_db($file_uploader_default_config); 
     17        file_uploader_folder($file_uploader_galleries_folder, $file_uploader_galleries_dir, $file_uploader_galleries_folder_name); 
    1918} 
    2019 
    2120function plugin_uninstall() { 
    22         include_once(dirname(__FILE__).'/install/functions.inc.php'); 
     21        require_once('install/functions.inc.php'); 
    2322 
    2423        file_uploader_delete_conf("file_uploader"); 
Note: See TracChangeset for help on using the changeset viewer.