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

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

private items are not displayed in SmartAlbums (according to user permissions)

File size: 3.2 KB
RevLine 
[10980]1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3/**
4 * Add a link into categories list to regenerate associations
5 */
[11290]6$smart_count = 0;
7
[10980]8function smart_cat_list()
9{
[11290]10  global $template, $page, $smart_count;
[10980]11  include_once(SMART_PATH.'include/functions.inc.php');
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 */
[11333]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';
[10980]20  if (!isset($_GET['parent_id']))
21  {
22    // $query.= '
23    // WHERE id_uppercat IS NULL';
24  }
25  else
26  {
[11333]27    $query .= '
28  WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\'';
[10980]29  }
[11333]30  $query .= '
31;';
[10980]32 
33  $result = pwg_query($query);
[11290]34  $smart_cats = array();
[10980]35  while ($cat = pwg_db_fetch_assoc($result))
36  {
[11290]37    $smart_cats[$cat['id']] = trigger_event('render_category_name', $cat['name']);
[10980]38  }
39 
[11290]40  $smart_count = count($smart_cats);
41 
[10980]42  if (isset($_GET['smart_generate']))
43  {
44    /* regenerate photo list | all (sub) categories */
45    if ($_GET['smart_generate'] == 'all')
46    {
[11290]47      foreach ($smart_cats as $cat => $name)
[10980]48      {
49        $associated_images = smart_make_associations($cat);
[11333]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          );
[10980]57      }
58    }
59    /* regenerate photo list | one category */
60    else
61    {
62      $associated_images = smart_make_associations($_GET['smart_generate']);   
[11333]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        );
[10980]70    }
71   
72    invalidate_user_cache(true);
73  }
74 
75  // create regenerate link
76  $tpl_cat = array();
[11290]77  foreach ($smart_cats as $cat => $name)
[10980]78  {
79    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
80  }
81  $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
82 
83  $template->assign(array(
84    'SMART_URL' => $tpl_cat,
85    'SMART_PATH' => SMART_PATH,
86  ));
87 
88  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
89}
90
91
92function smart_cat_list_prefilter($content, &$smarty)
93{
[11290]94  global $smart_count;
95 
[11334]96  $search[0] = '{if isset($category.U_SYNC) }';
97  $replacement[0] = '
[10980]98{if isset($SMART_URL[$category.ID])}
[11334]99        <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>
100{/if}'
101.$search[0];
[10980]102
[11290]103  if ($smart_count > 0)
104  {
105    $search[1] = '</ul>
[10980]106</form>
107{/if}';
[11290]108    $replacement[1] = $search[1].'
[10980]109<form method="post" action="{$SMART_URL.all}">
110  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
[11334]111  <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p>
[10980]112</form>';
[11290]113  }
[10980]114
115  return str_replace($search, $replacement, $content);
116}
117
118?>
Note: See TracBrowser for help on using the repository browser.