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.

Location:
extensions/PayPalShoppingCart
Files:
2 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • extensions/PayPalShoppingCart/admin.php

    r9239 r19464  
    2323load_language('plugin.lang', PPPPP_PATH);
    2424$my_base_url = get_admin_plugin_menu_link(__FILE__);
    25 include_once (PPPPP_PATH.'/constants.php');
    2625
    2726// onglets
     
    3534               l10n('Currency'),
    3635               $my_base_url.'&tab=currency');
     36$tabsheet->add('albums', l10n('Albums'), $my_base_url.'&tab=albums');
    3737$tabsheet->add('size',
    3838               l10n('Size'),
     
    8585  $template->assign('ppppp_array_currency',$array_currency);
    8686  break;
     87
     88 case 'albums' :
     89
     90   if (isset($_POST['apply_to_albums']) and in_array($_POST['apply_to_albums'], array('all', 'list')))
     91   {
     92     $conf['PayPalShoppingCart']['apply_to_albums'] = $_POST['apply_to_albums'];
     93     conf_update_param('PayPalShoppingCart', serialize($conf['PayPalShoppingCart']));
     94
     95     if ($_POST['apply_to_albums'] == 'list')
     96     {
     97       check_input_parameter('albums', $_POST, true, PATTERN_ID);
     98
     99       if (empty($_POST['albums']))
     100       {
     101         $_POST['albums'][] = -1;
     102       }
     103       
     104       $query = '
     105UPDATE '.CATEGORIES_TABLE.'
     106  SET paypal_active = \'false\'
     107  WHERE id NOT IN ('.implode(',', $_POST['albums']).')
     108;';
     109       pwg_query($query);
     110
     111       $query = '
     112UPDATE '.CATEGORIES_TABLE.'
     113  SET paypal_active = \'true\'
     114  WHERE id IN ('.implode(',', $_POST['albums']).')
     115;';
     116       pwg_query($query);
     117     }
     118   }
     119   
     120   // associate to albums
     121   $query = '
     122SELECT id
     123  FROM '.CATEGORIES_TABLE.'
     124  WHERE paypal_active = \'true\'
     125;';
     126   $paypal_albums = array_from_query($query, 'id');
     127
     128   $query = '
     129SELECT id,name,uppercats,global_rank
     130  FROM '.CATEGORIES_TABLE.'
     131;';
     132   display_select_cat_wrapper($query, $paypal_albums, 'album_options');
     133
     134   $template->assign('apply_to_albums', $conf['PayPalShoppingCart']['apply_to_albums']);
     135
     136   break;
     137 
    87138 
    88139 case 'size':
  • extensions/PayPalShoppingCart/admin.tpl

    r9239 r19464  
     1{combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'}
     2{combine_css path="themes/default/js/plugins/chosen.css"}
     3
     4{footer_script}{literal}
     5jQuery(document).ready(function() {
     6  jQuery(".chzn-select").chosen();
     7
     8  function checkStatusOptions() {
     9    if (jQuery("input[name=apply_to_albums]:checked").val() == "list") {
     10      jQuery("#albumList").show();
     11    }
     12    else {
     13      jQuery("#albumList").hide();
     14    }
     15  }
     16
     17  checkStatusOptions();
     18
     19  jQuery("input[name=apply_to_albums]").change(function() {
     20    checkStatusOptions();
     21  });
     22});
     23{/literal}{/footer_script}
     24
    125<div class="titrePage">
    226<h2>{'PayPal Shopping Cart'|@translate}</h2>
     
    1741<br>
    1842<!--input type=submit value="{'Update data'|@translate}"-->
     43</fieldset>
     44</form>
     45
     46{elseif $tabsheet_selected=='albums'}
     47<h3>{'Albums'|@translate}</h3>
     48<form method=post>
     49<fieldset>
     50  <legend>{'Apply to albums'|@translate}</legend>
     51  <p>
     52    <label><input type="radio" name="apply_to_albums" value="all"{if $apply_to_albums eq 'all'} checked="checked"{/if}> <strong>{'all albums'|@translate}</strong></label>
     53    <label><input type="radio" name="apply_to_albums" value="list"{if $apply_to_albums eq 'list'} checked="checked"{/if}> <strong>{'a list of albums'|@translate}</strong></label>
     54  </p>
     55  <p id="albumList">
     56    <select data-placeholder="Select albums..." class="chzn-select" multiple style="width:700px;" name="albums[]">
     57      {html_options options=$album_options selected=$album_options_selected}
     58    </select>
     59  </p>
     60  <p class="formButtons">
     61                <input type="submit" name="submit" value="{'Save Settings'|@translate}">
     62        </p>
    1963</fieldset>
    2064</form>
  • extensions/PayPalShoppingCart/language/en_UK/plugin.lang.php

    r9239 r19464  
    3636$lang['View Shopping Cart'] = 'View Shopping Cart';
    3737$lang['View my PayPal Shopping Cart'] = 'View my PayPal Shopping Cart';
     38$lang['Apply to albums'] = 'Apply to albums';
     39$lang['all albums'] = 'all albums';
     40$lang['a list of albums'] = 'a list of albums';
    3841?>
  • extensions/PayPalShoppingCart/language/fr_FR/plugin.lang.php

    r9239 r19464  
    3636$lang['View Shopping Cart'] = 'Voir mon panier';
    3737$lang['View my PayPal Shopping Cart'] = 'Voir mon panier PayPal';
     38$lang['Apply to albums'] = 'Appliquer aux albums';
     39$lang['all albums'] = 'tous les albums';
     40$lang['a list of albums'] = 'une liste d\'albums';
    3841?>
  • 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?>
  • extensions/PayPalShoppingCart/maintain.inc.php

    r9239 r19464  
    2121if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    2222
    23 if (!defined("PPPPP_PATH")){
    24   define('PPPPP_PATH', PHPWG_PLUGINS_PATH.basename(dirname(__FILE__)));
     23defined('PPPPP_ID') or define('PPPPP_ID', basename(dirname(__FILE__)));
     24include_once(PHPWG_PLUGINS_PATH.PPPPP_ID.'/include/install.inc.php');
     25
     26/**
     27 * plugin installation
     28 *
     29 * perform here all needed step for the plugin installation
     30 * such as create default config, add database tables,
     31 * add fields to existing tables, create local folders...
     32 */
     33function plugin_install()
     34{
     35  ppppp_install();
     36  define('ppppp_installed', true);
    2537}
    26 include_once (PPPPP_PATH.'/constants.php');
    2738
    28 function plugin_install(){
    29  global $prefixeTable;
    30  $query = "CREATE TABLE IF NOT EXISTS ".PPPPP_SIZE_TABLE." (
    31   id tinyint(4) NOT NULL AUTO_INCREMENT,
    32   size varchar(40) NOT NULL,
    33   price float NOT NULL,
    34   PRIMARY KEY (id),
    35   UNIQUE KEY size (size)
    36   );";
    37  pwg_query($query);
    38  $query = "INSERT INTO ".PPPPP_SIZE_TABLE." (size,price) VALUES ('Classique', '40');";
    39  pwg_query($query);
     39/**
     40 * plugin activation
     41 *
     42 * this function is triggered adter installation, by manual activation
     43 * or after a plugin update
     44 * for this last case you must manage updates tasks of your plugin in this function
     45 */
     46function plugin_activate()
     47{
     48  if (!defined('ppppp_installed')) // a plugin is activated just after its installation
     49  {
     50    ppppp_install();
     51  }
     52}
     53
     54/**
     55 * plugin unactivation
     56 *
     57 * triggered before uninstallation or by manual unactivation
     58 */
     59function plugin_unactivate()
     60{
     61}
     62
     63function plugin_uninstall()
     64{
     65  global $prefixeTable;
    4066 
    41  $query = "CREATE TABLE IF NOT EXISTS ".PPPPP_CONFIG_TABLE." (
    42   param varchar(40) NOT NULL,
    43   value text NOT NULL,
    44   PRIMARY KEY (param)
    45   );";
    46  pwg_query($query);
    47  $query = "INSERT INTO ".PPPPP_CONFIG_TABLE." VALUES ('fixed_shipping', '0');";
    48  pwg_query($query);
    49  $query = "INSERT INTO ".PPPPP_CONFIG_TABLE." VALUES ('currency', 'EUR');";
    50  pwg_query($query);
    51  }
     67  $query = "DROP TABLE ".$prefixeTable."ppppp_size;";
     68  pwg_query($query);
     69 
     70  $query = "DROP TABLE ".$prefixeTable."ppppp_config;";
     71  pwg_query($query);
    5272
    53 function plugin_uninstall(){
    54  global $prefixeTable;
    55  $query = "DROP TABLE ".PPPPP_SIZE_TABLE.";";
    56  pwg_query($query);
    57  $query = "DROP TABLE ".PPPPP_CONFIG_TABLE.";";
    58  pwg_query($query);
     73  // delete configuration
     74  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "PayPalShoppingCart";');
     75 
     76  // delete field
     77  pwg_query('ALTER TABLE `'. CATEGORIES_TABLE .'` DROP COLUMN paypal_active;');
    5978}
    6079?>
Note: See TracChangeset for help on using the changeset viewer.