Ignore:
Timestamp:
Dec 17, 2012, 3:55:58 PM (11 years ago)
Author:
plg
Message:

Ability to filter the PayPal form on a list of albums

Implements the "automatic update" mechanism from Skeleton plugin.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/PayPalShoppingCart/main.inc.php

    r9876 r19464  
    22/*
    33Plugin Name: PayPal Shopping Cart
    4 Version: 1.0.7
     4Version: auto
    55Description: Append PayPal Shopping Cart on Piwigo to sell photos
    66Plugin URI: http://piwigo.org/ext/extension_view.php?eid=499
     
    5656*/
    5757if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
     58
     59global $prefixeTable;
     60
     61// +-----------------------------------------------------------------------+
     62// | Define plugin constants                                               |
     63// +-----------------------------------------------------------------------+
     64
     65defined('PPPPP_ID') or define('PPPPP_ID', basename(dirname(__FILE__)));
    5866define('PPPPP_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
    59 include_once (PPPPP_PATH.'/constants.php');
     67define('PPPPP_SIZE_TABLE', $prefixeTable.'ppppp_size');
     68define('PPPPP_CONFIG_TABLE', $prefixeTable.'ppppp_config');
     69define('PPPPP_VERSION', 'auto');
     70
    6071
    6172function ppppp_append_form($tpl_source, &$smarty){
     
    112123
    113124function ppppp_picture_handler(){
    114  global $template;
     125  global $template, $conf, $page;
     126
     127  if ($conf['PayPalShoppingCart']['apply_to_albums'] == 'list')
     128  {
     129    if (!isset($page['category']))
     130    {
     131      return;
     132    }
     133
     134    $query = '
     135SELECT
     136    paypal_active
     137  FROM '.CATEGORIES_TABLE.'
     138  WHERE id = '.$page['category']['id'].'
     139;';
     140    list($paypal_active) = pwg_db_fetch_row(pwg_query($query));
     141
     142    if ('false' == $paypal_active)
     143    {
     144      return;
     145    }
     146  }   
     147 
    115148 $template->set_prefilter('picture', 'ppppp_append_form');
    116149 load_language('plugin.lang', PPPPP_PATH);
     
    130163 
    131164 $template->assign('ppppp_e_mail',get_webmaster_mail_address());
    132  $template->append('footer_elements',' - PayPal plugin by <a href=http://www.queguineur.fr>queguineur.fr</a>');
    133165 }
    134166
     
    169201
    170202add_event_handler('get_admin_plugin_menu_links', 'ppppp_admin_menu');
     203
     204add_event_handler('init', 'ppppp_init');
     205/**
     206 * plugin initialization
     207 *   - check for upgrades
     208 *   - unserialize configuration
     209 *   - load language
     210 */
     211function ppppp_init()
     212{
     213  global $conf, $pwg_loaded_plugins;
     214 
     215  // apply upgrade if needed
     216  if (
     217    PPPPP_VERSION == 'auto' or
     218    $pwg_loaded_plugins[PPPPP_ID]['version'] == 'auto' or
     219    version_compare($pwg_loaded_plugins[PPPPP_ID]['version'], PPPPP_VERSION, '<')
     220  )
     221  {
     222    // call install function
     223    include_once(PPPPP_PATH.'include/install.inc.php');
     224    ppppp_install();
     225   
     226    // update plugin version in database
     227    if ( $pwg_loaded_plugins[PPPPP_ID]['version'] != 'auto' and PPPPP_VERSION != 'auto' )
     228    {
     229      $query = '
     230UPDATE '. PLUGINS_TABLE .'
     231SET version = "'. PPPPP_VERSION .'"
     232WHERE id = "'. PPPPP_ID .'"';
     233      pwg_query($query);
     234     
     235      $pwg_loaded_plugins[PPPPP_ID]['version'] = PPPPP_VERSION;
     236     
     237      if (defined('IN_ADMIN'))
     238      {
     239        $_SESSION['page_infos'][] = 'PayPalShoppingCart plugin updated to version '. PPPPP_VERSION;
     240      }
     241    }
     242  }
     243 
     244  // load plugin language file
     245  load_language('plugin.lang', PPPPP_PATH);
     246 
     247  // prepare plugin configuration
     248  $conf['PayPalShoppingCart'] = unserialize($conf['PayPalShoppingCart']);
     249}
    171250?>
Note: See TracChangeset for help on using the changeset viewer.