source: extensions/SmartAlbums/admin/cat_list.php @ 19446

Last change on this file since 19446 was 19446, checked in by mistic100, 11 years ago
  • add regex for phot name, author
  • add dimensions filter
  • rewrite javascript algorithms
  • add auto update on timeout (default 3 days)
  • display photos count on plugin albums list
File size: 5.1 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4if (isset($_GET['hide_messages']))
5{
6  $conf['SmartAlbums']['show_list_messages'] = false;
7  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
8}
9
10// +-----------------------------------------------------------------------+
11// |                            initialization                             |
12// +-----------------------------------------------------------------------+
13$base_url = get_root_url() . 'admin.php?page=';
14$self_url = SMART_ADMIN . '-cat_list';
15
16$categories = array();
17$query = '
18SELECT
19    id,
20    name,
21    permalink,
22    dir,
23    smart_update
24  FROM '.CATEGORIES_TABLE.' AS cat
25  INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
26    ON cf.category_id = cat.id
27  ORDER BY rank ASC
28;';
29$categories = hash_from_query($query, 'id');
30
31// +-----------------------------------------------------------------------+
32// |                    virtual categories management                      |
33// +-----------------------------------------------------------------------+
34// request to delete a album
35if (isset($_GET['delete']) and is_numeric($_GET['delete']))
36{
37  delete_categories(array($_GET['delete']));
38  $_SESSION['page_infos'] = array(l10n('SmartAlbum deleted'));
39  update_global_rank();
40  redirect($self_url);
41}
42// request to add a album
43else if (isset($_POST['submitAdd']))
44{
45  $output_create = create_virtual_category(
46    $_POST['virtual_name'],
47    @$_POST['parent_id']
48    );
49
50  if (isset($output_create['error']))
51  {
52    array_push($page['errors'], $output_create['error']);
53  }
54  else
55  {
56    $_SESSION['page_infos'] = array(l10n('SmartAlbum added'));
57    $redirect_url = SMART_ADMIN . '-album&amp;cat_id='.$output_create['id'].'&amp;new_smart';
58    redirect($redirect_url);
59  }
60}
61// request to regeneration
62else if (isset($_GET['smart_generate']))
63{
64  /* regenerate photo list | all categories */
65  if ($_GET['smart_generate'] == 'all')
66  {
67    foreach ($categories as $category)
68    {
69      $associated_images = smart_make_associations($category['id']);
70      array_push($page['infos'], 
71        sprintf(l10n('%d photos associated to album %s'), 
72          count($associated_images), 
73          '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
74          )
75        );
76    }
77  }
78  /* regenerate photo list | one category */
79  else
80  {
81    $associated_images = smart_make_associations($_GET['smart_generate']);   
82    array_push($page['infos'], 
83      sprintf(l10n('%d photos associated to album %s'), 
84        count($associated_images), 
85        '&laquo;'.trigger_event('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
86        )
87      );
88  }
89 
90  define('SMART_NOT_UPDATE', 1);
91  invalidate_user_cache();
92}
93
94// +-----------------------------------------------------------------------+
95// |                       template initialization                         |
96// +-----------------------------------------------------------------------+
97$template->assign(array(
98  'F_ACTION' => $self_url,
99  'PWG_TOKEN' => get_pwg_token(),
100 ));
101 
102// retrieve all existing categories for album creation
103$query = '
104SELECT id,name,uppercats,global_rank
105  FROM '.CATEGORIES_TABLE.'
106;';
107
108display_select_cat_wrapper(
109  $query,
110  null,
111  'category_options'
112  );
113 
114if ($conf['SmartAlbums']['show_list_messages'])
115{
116  array_push($page['warnings'], l10n('Only SmartAlbums are displayed on this page'));
117  array_push($page['warnings'], sprintf(l10n('To order albums please go the main albums <a href="%s">management page</a>'), $base_url.'cat_list'));
118  array_push($page['warnings'], '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>');
119}
120
121// +-----------------------------------------------------------------------+
122// |                          Categories display                           |
123// +-----------------------------------------------------------------------+
124
125$categories_count_images = array();
126if ( count($categories) )
127{
128  $query = '
129SELECT
130    category_id,
131    COUNT(image_id) AS total_images
132  FROM '.IMAGE_CATEGORY_TABLE.'
133  WHERE category_id IN ('.implode(',', array_keys($categories)).')
134  GROUP BY category_id
135;';
136  $categories_count_images = simple_hash_from_query($query, 'category_id', 'total_images');
137}
138
139$template->assign('categories', array());
140
141foreach ($categories as $category)
142{
143  $tpl_cat =
144    array(
145      'NAME'        => get_cat_display_name_from_id($category['id'], $base_url.'album-'),
146      'ID'          => $category['id'],
147      'IMG_COUNT'   => !empty($categories_count_images[ $category['id'] ]) ? $categories_count_images[ $category['id'] ] : 0,
148      'LAST_UPDATE' => format_date($category['smart_update'], true),
149
150      'U_JUMPTO'    => make_index_url(array('category' => $category)),
151      'U_EDIT'      => SMART_ADMIN.'-album&amp;cat_id='.$category['id'],
152      'U_DELETE'    => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
153      'U_SMART'     => $self_url.'&amp;smart_generate='.$category['id'],
154    );
155 
156  $template->append('categories', $tpl_cat);
157}
158
159$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/cat_list.tpl');
160
161?>
Note: See TracBrowser for help on using the repository browser.