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

Last change on this file since 11392 was 11392, checked in by mistic100, 13 years ago

add a list of all SmartAlbums

File size: 3.3 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  $smart_cats = hash_from_query($query, 'id'); 
34  $smart_count = count($smart_cats);
35 
36  if (isset($_GET['smart_generate']))
37  {
38    /* regenerate photo list | all (sub) categories */
39    if ($_GET['smart_generate'] == 'all')
40    {
41      foreach ($smart_cats as $category)
42      {
43        $associated_images = smart_make_associations($category['id']);
44        array_push(
45          $page['infos'], 
46          l10n_args(get_l10n_args(
47            '%d photos associated to album &laquo;%s&raquo;', 
48            array(
49              count($associated_images), 
50              trigger_event(
51                'render_category_name',
52                $category['name'],
53                'admin_cat_list'
54                )
55              )
56            ))
57          );
58      }
59    }
60    /* regenerate photo list | one category */
61    else
62    {
63      $associated_images = smart_make_associations($_GET['smart_generate']);   
64      array_push(
65        $page['infos'], 
66        l10n_args(get_l10n_args(
67          '%d photos associated to album &laquo;%s&raquo;', 
68          array(
69            count($associated_images), 
70            trigger_event(
71              'render_category_name',
72              $smart_cats[$_GET['smart_generate']]['name'],
73              'admin_cat_list'
74              )
75            )
76          ))
77        );
78    }
79   
80    define('SMART_NOT_UPDATE', 1);
81    invalidate_user_cache();
82  }
83 
84  // create regenerate link
85  $tpl_cat = array();
86  foreach ($smart_cats as $cat => $name)
87  {
88    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
89  }
90  $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
91 
92  $template->assign(array(
93    'SMART_URL' => $tpl_cat,
94    'SMART_PATH' => SMART_PATH,
95  ));
96 
97  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
98}
99
100
101function smart_cat_list_prefilter($content, &$smarty)
102{
103  global $smart_count;
104 
105  $search[0] = '{if isset($category.U_SYNC) }';
106  $replacement[0] = '
107{if isset($SMART_URL[$category.ID])}
108        <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 of this SmartAlbum\'|@translate}"></a></li>
109{/if}'
110.$search[0];
111
112  if ($smart_count > 0)
113  {
114    $search[1] = '</ul>
115</form>
116{/if}';
117    $replacement[1] = $search[1].'
118<form method="post" action="{$SMART_URL.all}">
119  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
120  <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p>
121</form>';
122  }
123
124  return str_replace($search, $replacement, $content);
125}
126
127?>
Note: See TracBrowser for help on using the repository browser.