Changeset 17657


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

consolidate upgrade process, remote filter_var function (PHP 5.2)

Location:
extensions/UserCollections
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/UserCollections/include/collections.inc.php

    r17519 r17657  
    1717   
    1818    // actions
    19     if ( isset($_GET['action']) and filter_var($_GET['col_id'], FILTER_VALIDATE_INT) !== false )
     19    if ( isset($_GET['action']) and preg_match('#^([0-9]+)$#', $_GET['col_id']) )
    2020    {
    2121      switch ($_GET['action'])
  • extensions/UserCollections/include/events.inc.php

    r17519 r17657  
    33
    44# this file contains all functions directly called by the triggers #
    5 
    6 /* unserialize conf and load language */
    7 function user_collections_init()
    8 {
    9   load_language('plugin.lang', USER_COLLEC_PATH);
    10 }
    115
    126
  • extensions/UserCollections/main.inc.php

    r17519 r17657  
    1313global $conf, $prefixeTable;
    1414
    15 define('USER_COLLEC_PATH',       PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
     15define('USER_COLLEC_PATH',       PHPWG_PLUGINS_PATH . 'UserCollections/');
    1616define('COLLECTIONS_TABLE',      $prefixeTable.'collections');
    1717define('COLLECTION_IMAGES_TABLE',$prefixeTable.'collection_images');
    18 define('USER_COLLEC_ADMIN',      get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
     18define('USER_COLLEC_ADMIN',      get_root_url() . 'admin.php?page=plugin-UserCollections');
    1919define('USER_COLLEC_PUBLIC',     get_absolute_root_url() . make_index_url(array('section' => 'collections')) . '/');
     20define('USER_COLLEC_VERSION',    '1.0.3');
     21
    2022
    2123add_event_handler('init', 'user_collections_init');
     
    3638require(USER_COLLEC_PATH . 'include/events.inc.php');
    3739
     40
     41/**
     42 * update plugin & load language
     43 */
     44function user_collections_init()
     45{
     46  global $pwg_loaded_plugins;
     47 
     48  if (
     49    $pwg_loaded_plugins['UserCollections']['version'] == 'auto' or
     50    version_compare($pwg_loaded_plugins['UserCollections']['version'], USER_COLLEC_VERSION, '<')
     51  )
     52  {
     53    include_once(USER_COLLEC_PATH . 'include/install.inc.php');
     54    user_collections_install();
     55   
     56    if ($pwg_loaded_plugins['UserCollections']['version'] != 'auto')
     57    {
     58      $query = '
     59UPDATE '. PLUGINS_TABLE .'
     60SET version = "'. USER_COLLEC_VERSION .'"
     61WHERE id = "UserCollections"';
     62      pwg_query($query);
     63     
     64      $pwg_loaded_plugins['UserCollections']['version'] = USER_COLLEC_VERSION;
     65     
     66      if (defined('IN_ADMIN'))
     67      {
     68        $_SESSION['page_infos'][] = 'UserCollections updated to version '. USER_COLLEC_VERSION;
     69      }
     70    }
     71  }
     72 
     73  load_language('plugin.lang', USER_COLLEC_PATH);
     74}
     75
    3876?>
  • extensions/UserCollections/maintain.inc.php

    r16658 r17657  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
     4include_once(PHPWG_PLUGINS_PATH . 'UserCollections/include/install.inc.php');
     5
    46function plugin_install()
    57{
    6   global $conf, $prefixeTable;
     8  user_collections_install();
    79 
    8   $query = '
    9 CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collections` (
    10   `id` mediumint(8) NOT NULL AUTO_INCREMENT,
    11   `user_id` smallint(5) DEFAULT NULL,
    12   `name` varchar(255) NOT NULL,
    13   `date_creation` datetime NOT NULL,
    14   `nb_images` mediumint(8) NOT NULL DEFAULT 0,
    15   `active` tinyint(1) DEFAULT 0,
    16   `public` tinyint(1) DEFAULT 0,
    17   `public_id` varchar(10) NULL,
    18   PRIMARY KEY (`id`)
    19 ) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1
    20 ;';
    21   pwg_query($query);
    22  
    23   $query = '
    24 CREATE TABLE IF NOT EXISTS `'.$prefixeTable.'collection_images` (
    25   `col_id` mediumint(8) NOT NULL,
    26   `image_id` mediumint(8) NOT NULL,
    27   UNIQUE KEY `UNIQUE` (`col_id`,`image_id`)
    28 ) DEFAULT CHARSET=utf8
    29 ;';
    30   pwg_query($query);
     10  define('user_collections_installed', true);
    3111}
    3212
    3313function plugin_activate()
    3414{
    35   global $prefixeTable;
    36  
    37   // new collumn in beta2
    38   $query = 'SHOW COLUMNS FROM `'.$prefixeTable.'collections`;';
    39   $columns = array_from_query($query, 'Field');
    40   if (!in_array('public_id', $columns))
     15  if (!defined('user_collections_intalled'))
    4116  {
    42     pwg_query('ALTER TABLE `'.$prefixeTable.'collections` ADD `public_id` varchar(10) NULL;');
     17    user_collections_install();
    4318  }
    4419}
     
    4823  global $prefixeTable;
    4924 
    50   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "user_collections" LIMIT 1;');
    5125  pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collections`;');
    5226  pwg_query('DROP TABLE IF EXISTS `'.$prefixeTable.'collection_images`;');
Note: See TracChangeset for help on using the changeset viewer.