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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.