Changeset 17656


Ignore:
Timestamp:
Aug 29, 2012, 5:11:53 PM (8 years ago)
Author:
mistic100
Message:

consolidate upgrade process, always use original filenames

Location:
extensions/BatchDownloader
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/BatchDownloader/include/BatchDownloader.class.php

    r17517 r17656  
    325325      foreach ($images_to_add as $row)
    326326      {       
    327         $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.str2url($row['name']).'.'.get_extension($row['file']));
     327        $zip->addFile(PHPWG_ROOT_PATH . $row['path'], $row['id'].'_'.get_filename_wo_extension($row['file']).'.'.get_extension($row['path']));
    328328       
    329329        array_push($images_added, $row['id']);
  • extensions/BatchDownloader/include/events.inc.php

    r17517 r17656  
    33
    44# this file contains all functions directly called by the triggers #
    5 
    6 /* unserialize conf and load language */
    7 function batch_download_init()
    8 {
    9   global $conf;
    10  
    11   $conf['batch_download'] = unserialize($conf['batch_download']);
    12   load_language('plugin.lang', BATCH_DOWNLOAD_PATH);
    13 }
    14 
    155
    166/* define page section from url */
  • extensions/BatchDownloader/main.inc.php

    r17517 r17656  
    1313global $conf, $prefixeTable;
    1414
    15 define('BATCH_DOWNLOAD_PATH',    PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
     15define('BATCH_DOWNLOAD_PATH',    PHPWG_PLUGINS_PATH . 'BatchDownloader/');
    1616define('BATCH_DOWNLOAD_TSETS',   $prefixeTable . 'download_sets');
    1717define('BATCH_DOWNLOAD_TIMAGES', $prefixeTable . 'download_sets_images');
    1818define('BATCH_DOWNLOAD_LOCAL',   PHPWG_ROOT_PATH . $conf['data_location'] . 'download_archives/');
    19 define('BATCH_DOWNLOAD_ADMIN',   get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
     19define('BATCH_DOWNLOAD_ADMIN',   get_root_url() . 'admin.php?page=plugin-BatchDownloader');
    2020define('BATCH_DOWNLOAD_PUBLIC',  get_absolute_root_url() . make_index_url(array('section' => 'download')) . '/');
     21define('BATCH_DOWNLOAD_VERSION', '1.0.3');
    2122
     23
     24add_event_handler('init', 'batch_download_init');
    2225
    2326if (class_exists('ZipArchive'))
    2427{
    25   add_event_handler('init', 'batch_download_init');
    26 
    2728  add_event_handler('loc_end_section_init', 'batch_download_section_init');
    2829  add_event_handler('loc_end_index', 'batch_download_page');
     
    3536  add_event_handler('blockmanager_apply', 'batch_download_applymenu');
    3637 
    37   require(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
    38   require(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
    39   require(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
     38  include_once(BATCH_DOWNLOAD_PATH . 'include/BatchDownloader.class.php');
     39  include_once(BATCH_DOWNLOAD_PATH . 'include/functions.inc.php');
     40  include_once(BATCH_DOWNLOAD_PATH . 'include/events.inc.php');
     41}
     42
     43if (defined('IN_ADMIN'))
     44{
     45  add_event_handler('get_admin_plugin_menu_links', 'batch_download_admin_menu');
    4046}
    4147
    4248
    43 add_event_handler('get_admin_plugin_menu_links', 'batch_download_admin_menu');
    4449
    45 /* admin plugins menu */
     50/**
     51 * unserialize conf and load language
     52 */
     53function batch_download_init()
     54{
     55  global $conf, $pwg_loaded_plugins;
     56 
     57  if (
     58    $pwg_loaded_plugins['BatchDownloader']['version'] == 'auto' or
     59    version_compare($pwg_loaded_plugins['BatchDownloader']['version'], BATCH_DOWNLOAD_VERSION, '<')
     60  )
     61  {
     62    include_once(BATCH_DOWNLOAD_PATH . 'include/install.inc.php');
     63    batch_download_install();
     64   
     65    if ($pwg_loaded_plugins['BatchDownloader']['version'] != 'auto')
     66    {
     67      $query = '
     68UPDATE '. PLUGINS_TABLE .'
     69SET version = "'. BATCH_DOWNLOAD_VERSION .'"
     70WHERE id = "BatchDownloader"';
     71      pwg_query($query);
     72     
     73      $pwg_loaded_plugins['BatchDownloader']['version'] = BATCH_DOWNLOAD_VERSION;
     74     
     75      if (defined('IN_ADMIN'))
     76      {
     77        $_SESSION['page_infos'][] = 'BatchDownloader updated to version '. BATCH_DOWNLOAD_VERSION;
     78      }
     79    }
     80  }
     81 
     82  $conf['batch_download'] = unserialize($conf['batch_download']);
     83  load_language('plugin.lang', BATCH_DOWNLOAD_PATH);
     84}
     85
     86/**
     87 * admin plugins menu
     88 */
    4689function batch_download_admin_menu($menu)
    4790{
  • extensions/BatchDownloader/maintain.inc.php

    r16689 r17656  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 define(
    5   'batch_download_default_config',
    6   serialize(array(
    7     'groups'          => array(),
    8     'level'           => 0,
    9     'photo_size'      => 'original',
    10     'archive_prefix'  => 'piwigo',
    11     'archive_timeout' => 48, /* hours */
    12     'max_elements'    => 500,
    13     'max_size'        => 100, /* MB */
    14     'last_clean'      => time(),
    15     ))
    16   );
     4include_once(PHPWG_PLUGINS_PATH . 'BatchDownloader/include/install.inc.php');
    175
    186function plugin_install()
    197{
    20   global $conf, $prefixeTable;
     8  batch_download_install();
    219 
    22   $query = '
    23 CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets` (
    24   `id` mediumint(8) NOT NULL AUTO_INCREMENT,
    25   `user_id` smallint(5) NOT NULL,
    26   `date_creation` datetime NOT NULL,
    27   `type` varchar(16) CHARACTER SET utf8 NOT NULL,
    28   `type_id` varchar(64) CHARACTER SET utf8 NOT NULL,
    29   `nb_zip` smallint(3) NOT NULL DEFAULT 0,
    30   `last_zip` smallint(3) NOT NULL DEFAULT 0,
    31   `nb_images` mediumint(8) NOT NULL DEFAULT 0,
    32   `total_size` int(10) NOT NULL DEFAULT 0,
    33   `status` enum("new","download","done") CHARACTER SET utf8 NOT NULL DEFAULT "new",
    34   PRIMARY KEY (`id`)
    35 ) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
    36 ;';
    37   pwg_query($query);
    38  
    39   $query = '
    40 CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'download_sets_images` (
    41   `set_id` mediumint(8) NOT NULL,
    42   `image_id` mediumint(8) NOT NULL,
    43   `zip` smallint(5) NOT NULL DEFAULT 0,
    44   UNIQUE KEY `UNIQUE` (`set_id`,`image_id`)
    45 ) DEFAULT CHARSET=utf8
    46 ;';
    47   pwg_query($query);
    48 
    49   conf_update_param('batch_download', batch_download_default_config);
    50   conf_update_param('batch_download_comment', null);
    51  
    52   mkdir($conf['data_location'] . 'download_archives/', 0755);
     10  define('batch_download_installed', true);
    5311}
    5412
    5513function plugin_activate()
    5614{
    57   global $conf;
    58 
    59   if (empty($conf['batch_download_comment']))
     15  if (!defined('batch_download_installed'))
    6016  {
    61     $new_conf = unserialize($conf['batch_download']);
    62     unset($new_conf['archive_comment']);
    63     conf_update_param('batch_download', serialize($new_conf));
    64     conf_update_param('batch_download_comment', null);
    65   }
    66  
    67   if (!file_exists($conf['data_location'] . 'download_archives/'))
    68   {
    69     mkdir($conf['data_location'] . 'download_archives/', 0755);
     17    batch_download_install();
    7018  }
    7119}
     
    8230}
    8331
    84 function rrmdir($dir)
     32
     33if (!function_exists('rrmdir'))
    8534{
    86   if (!is_dir($dir))
     35  function rrmdir($dir)
    8736  {
    88     return false;
    89   }
    90   $dir = rtrim($dir, '/');
    91   $objects = scandir($dir);
    92   $return = true;
    93  
    94   foreach ($objects as $object)
    95   {
    96     if ($object !== '.' && $object !== '..')
     37    if (!is_dir($dir))
    9738    {
    98       $path = $dir.'/'.$object;
    99       if (filetype($path) == 'dir')
     39      return false;
     40    }
     41    $dir = rtrim($dir, '/');
     42    $objects = scandir($dir);
     43    $return = true;
     44   
     45    foreach ($objects as $object)
     46    {
     47      if ($object !== '.' && $object !== '..')
    10048      {
    101         $return = $return && rrmdir($path);
    102       }
    103       else
    104       {
    105         $return = $return && @unlink($path);
     49        $path = $dir.'/'.$object;
     50        if (filetype($path) == 'dir')
     51        {
     52          $return = $return && rrmdir($path);
     53        }
     54        else
     55        {
     56          $return = $return && @unlink($path);
     57        }
    10658      }
    10759    }
     60   
     61    return $return && @rmdir($dir);
    10862  }
    109  
    110   return $return && @rmdir($dir);
    111 }
     63}
    11264
    11365?>
Note: See TracChangeset for help on using the changeset viewer.