Changeset 11376


Ignore:
Timestamp:
Jun 14, 2011, 6:41:10 PM (13 years ago)
Author:
mistic100
Message:

Add event_handler on 'login_success' and 'invalidate_user_cache' to regenerate SmartAlbums content

Location:
extensions/SmartAlbums
Files:
2 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • extensions/SmartAlbums/include/functions.inc.php

    r11334 r11376  
    3030  }
    3131 
     32  if (!function_exists('set_rendom_representant'))
     33  {
     34    include(PHPWG_ROOT_PATH.'admin/include/functions.php');
     35  }
    3236  set_random_representant(array($cat_id));
    3337 
    3438  return $images;
     39}
     40
     41
     42/*
     43 * Make associations for all SmartAlbums
     44 * Called with invalidate_user_cache and/or on admin login
     45 * @param string login (not mandatory)
     46 */
     47function smart_make_all_associations($login = false)
     48{
     49  global $conf;
     50   
     51  if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
     52 
     53  if ( !$login AND !defined('SMART_NOT_UPDATE') AND $conf['SmartAlbums']['update_on_upload'] != 'false' )
     54    continue;
     55  else if ( is_string($login) AND is_admin() AND $conf['SmartAlbums']['update_on_login'] != 'false' )
     56    continue;
     57  else
     58    return;
     59 
     60  /* get categories with smart filters */
     61  $query = '
     62SELECT DISTINCT id
     63  FROM '.CATEGORIES_TABLE.' AS c
     64    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
     65    ON c.id = cf.category_id
     66;';
     67 
     68  /* regenerate photo list */
     69  $smart_cats = array_from_query($query, 'id');
     70  array_map('smart_make_associations', $smart_cats);
     71 
     72  if (is_string($login))
     73  {
     74    define('SMART_NOT_UPDATE', 1);
     75    invalidate_user_cache();
     76  }
    3577}
    3678
  • extensions/SmartAlbums/include/init_cat_list.php

    r11334 r11376  
    99{
    1010  global $template, $page, $smart_count;
    11   include_once(SMART_PATH.'include/functions.inc.php');
     11
    1212  $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&parent_id='.$_GET['parent_id'] : null);
    1313 
     
    7070    }
    7171   
    72     invalidate_user_cache(true);
     72    define('SMART_NOT_UPDATE', 1);
     73    invalidate_user_cache();
    7374  }
    7475 
  • extensions/SmartAlbums/include/init_cat_modify.php

    r11334 r11376  
    88{
    99  global $template, $page;
    10   include_once(SMART_PATH.'include/functions.inc.php');
    1110 
    1211  $cat_id = $_GET['cat_id'];
     
    6261     
    6362      $associated_images = smart_make_associations($cat_id);
    64       invalidate_user_cache(true);
    6563      $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
     64     
     65      define('SMART_NOT_UPDATE', 1);
     66      invalidate_user_cache();
    6667    }
    6768  }
  • extensions/SmartAlbums/language/en_UK/plugin.lang.php

    r11334 r11376  
    2323$lang['Regenerate photos list of this SmartAlbum'] = 'Regenerate photos list of this SmartAlbum';
    2424$lang['Regenerate photos list of all SmartAlbums'] = 'Regenerate photos list of all SmartAlbums';
     25$lang['Update albums on file upload'] = 'Update albums on file upload';
     26$lang['Update albums when an admin logins'] = 'Update albums when an admin logins';
    2527
    2628?>
  • extensions/SmartAlbums/language/fr_FR/plugin.lang.php

    r11334 r11376  
    2323$lang['Regenerate photos list of this SmartAlbum'] = 'Régénérer les photos de ce SmartAlbum';
    2424$lang['Regenerate photos list of all SmartAlbums'] = 'Régénérer les photos de tous les SmartAlbums';
     25$lang['Update albums on file upload'] = 'Mettre à jour les albums après la mise en ligne d\'un fichier';
     26$lang['Update albums when an admin logins'] = 'Mettre à jour les albums quand un admin se connecte';
    2527
    2628?>
  • extensions/SmartAlbums/main.inc.php

    r11334 r11376  
    1616define('CATEGORY_FILTERS_TABLE', $prefixeTable.'category_filters');
    1717
     18add_event_handler('invalidate_user_cache', 'smart_make_all_associations');
     19add_event_handler('login_success', 'smart_make_all_associations');
     20include_once(SMART_PATH.'include/functions.inc.php');
     21
    1822if (script_basename() == 'index')
    1923{
     
    3034  add_event_handler('loc_begin_cat_list', 'smart_cat_list');
    3135  include_once(SMART_PATH.'include/init_cat_list.php');
     36 
     37  add_event_handler('get_admin_plugin_menu_links', 'smart_admin_menu');
     38        function smart_admin_menu($menu)
     39        {
     40                array_push($menu, array(
     41                        'NAME' => 'SmartAlbums',
     42                        'URL' => get_root_url().'admin.php?page=plugin-' . SMART_DIR));
     43                return $menu;
     44        }
    3245}
    3346
  • extensions/SmartAlbums/maintain.inc.php

    r11333 r11376  
    22if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
    33
    4 function plugin_install() {
     4function plugin_install()
     5{
    56        global $prefixeTable;
    67
     
    1617 
    1718  /* add a collumn to image_category_table */
    18   pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM("true", "false") NOT NULL DEFAULT "false";');
     19  pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
    1920     
    2021  /* config parameter */
    21   // pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
    22     // VALUES ('SmartAlbums', '', 'Configuration for SmartAlbums plugin');");
     22  pwg_query('
     23INSERT INTO `' . CONFIG_TABLE . '`
     24  VALUES (
     25    \'SmartAlbums\',
     26    \''.serialize(array(
     27        'update_on_upload' => false,
     28        'update_on_login' => false,
     29        )
     30      ).'\',
     31    \'Configuration for SmartAlbums plugin\'
     32  )
     33;');
     34
    2335}
    2436
    25 function plugin_uninstall() {
     37function plugin_activate()
     38{
     39  global $conf;
     40 
     41  if (!isset($conf['SmartAlbums']))
     42  {
     43    pwg_query('
     44INSERT INTO `' . CONFIG_TABLE . '`
     45  VALUES (
     46    \'SmartAlbums\',
     47    \''.serialize(array(
     48        'update_on_upload' => false,
     49        'update_on_login' => false,
     50        )
     51      ).'\',
     52    \'Configuration for SmartAlbums plugin\'
     53  )
     54;');
     55  }
     56 
     57}
     58
     59function plugin_uninstall()
     60{
    2661        global $prefixeTable;
    2762 
    2863  pwg_query('DROP TABLE `' . $prefixeTable . 'category_filters`;');
    2964  pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
    30   pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "SmartAlbums";');
     65  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = \'SmartAlbums\';');
    3166}
    3267?>
Note: See TracChangeset for help on using the changeset viewer.