source: extensions/SmartAlbums/include/init_cat_list.php @ 11376

Last change on this file since 11376 was 11376, checked in by mistic100, 9 years ago

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

File size: 3.1 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3/**
4 * Add a link into categories list to regenerate associations
5 */
6$smart_count = 0;
7
8function smart_cat_list()
9{
10  global $template, $page, $smart_count;
11
12  $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&amp;parent_id='.$_GET['parent_id'] : null);
13 
14  /* get categories with smart filters */
15  $query = '
16SELECT DISTINCT id, name
17  FROM '.CATEGORIES_TABLE.' AS c
18    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
19      ON c.id = cf.category_id';
20  if (!isset($_GET['parent_id']))
21  {
22    // $query.= '
23    // WHERE id_uppercat IS NULL';
24  }
25  else
26  {
27    $query .= '
28  WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\'';
29  }
30  $query .= '
31;';
32 
33  $result = pwg_query($query);
34  $smart_cats = array();
35  while ($cat = pwg_db_fetch_assoc($result))
36  {
37    $smart_cats[$cat['id']] = trigger_event('render_category_name', $cat['name']);
38  }
39 
40  $smart_count = count($smart_cats);
41 
42  if (isset($_GET['smart_generate']))
43  {
44    /* regenerate photo list | all (sub) categories */
45    if ($_GET['smart_generate'] == 'all')
46    {
47      foreach ($smart_cats as $cat => $name)
48      {
49        $associated_images = smart_make_associations($cat);
50        array_push(
51          $page['infos'], 
52          l10n_args(get_l10n_args(
53            '%d photos associated to album &laquo;%s&raquo;', 
54            array(count($associated_images), $name)
55            ))
56          );
57      }
58    }
59    /* regenerate photo list | one category */
60    else
61    {
62      $associated_images = smart_make_associations($_GET['smart_generate']);   
63      array_push(
64        $page['infos'], 
65        l10n_args(get_l10n_args(
66          '%d photos associated to album &laquo;%s&raquo;', 
67          array(count($associated_images), $smart_cats[$_GET['smart_generate']])
68          ))
69        );
70    }
71   
72    define('SMART_NOT_UPDATE', 1);
73    invalidate_user_cache();
74  }
75 
76  // create regenerate link
77  $tpl_cat = array();
78  foreach ($smart_cats as $cat => $name)
79  {
80    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
81  }
82  $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
83 
84  $template->assign(array(
85    'SMART_URL' => $tpl_cat,
86    'SMART_PATH' => SMART_PATH,
87  ));
88 
89  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
90}
91
92
93function smart_cat_list_prefilter($content, &$smarty)
94{
95  global $smart_count;
96 
97  $search[0] = '{if isset($category.U_SYNC) }';
98  $replacement[0] = '
99{if isset($SMART_URL[$category.ID])}
100        <li><a href="{$SMART_URL[$category.ID]}" title="{\'Regenerate photos list of this SmartAlbum\'|@translate}"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/synchronize.png" class="button" alt="{\'regenerate photos list\'|@translate}"></a></li>
101{/if}'
102.$search[0];
103
104  if ($smart_count > 0)
105  {
106    $search[1] = '</ul>
107</form>
108{/if}';
109    $replacement[1] = $search[1].'
110<form method="post" action="{$SMART_URL.all}">
111  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
112  <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p>
113</form>';
114  }
115
116  return str_replace($search, $replacement, $content);
117}
118
119?>
Note: See TracBrowser for help on using the repository browser.