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/include
Files:
3 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  }
Note: See TracChangeset for help on using the changeset viewer.