source: trunk/admin.php @ 26010

Last change on this file since 26010 was 25975, checked in by rvelices, 7 years ago

invalidate_user_cache fix in web service method + do not invalidate user cache on every page hit on album list, photo etc ...

  • Property svn:eol-style set to LF
File size: 10.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24// +-----------------------------------------------------------------------+
25// | Basic constants and includes                                          |
26// +-----------------------------------------------------------------------+
27
28define('PHPWG_ROOT_PATH','./');
29define('IN_ADMIN', true);
30
31include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php');
34include_once(PHPWG_ROOT_PATH.'admin/include/add_core_tabs.inc.php');
35
36trigger_action('loc_begin_admin');
37
38// +-----------------------------------------------------------------------+
39// | Check Access and exit when user status is not ok                      |
40// +-----------------------------------------------------------------------+
41
42check_status(ACCESS_ADMINISTRATOR);
43
44// +-----------------------------------------------------------------------+
45// | Direct actions                                                        |
46// +-----------------------------------------------------------------------+
47
48// save plugins_new display order (AJAX action)
49if (isset($_GET['plugins_new_order']))
50{
51  pwg_set_session_var('plugins_new_order', $_GET['plugins_new_order']);
52  exit;
53}
54
55// theme changer
56if (isset($_GET['change_theme']))
57{
58  $admin_themes = array('roma', 'clear');
59
60  $new_admin_theme = array_pop(
61    array_diff(
62      $admin_themes,
63      array($conf['admin_theme'])
64      )
65    );
66
67  conf_update_param('admin_theme', $new_admin_theme);
68
69  $url_params = array();
70  foreach (array('page', 'tab', 'section') as $url_param)
71  {
72    if (isset($_GET[$url_param]))
73    {
74      $url_params[] = $url_param.'='.$_GET[$url_param];
75    }
76  }
77 
78  $redirect_url = 'admin.php';
79  if (count($url_params) > 0)
80  {
81    $redirect_url.= '?'.implode('&amp;', $url_params);
82  }
83
84  redirect($redirect_url);
85}
86
87// +-----------------------------------------------------------------------+
88// | Synchronize user informations                                         |
89// +-----------------------------------------------------------------------+
90
91// sync_user() is only useful when external authentication is activated
92if ($conf['external_authentification'])
93{
94  sync_users();
95}
96
97// +-----------------------------------------------------------------------+
98// | Variables init                                                        |
99// +-----------------------------------------------------------------------+
100
101$change_theme_url = PHPWG_ROOT_PATH.'admin.php?';
102$test_get = $_GET;
103unset($test_get['page']);
104unset($test_get['section']);
105unset($test_get['tag']);
106if (count($test_get) == 0 and !empty($_SERVER['QUERY_STRING']))
107{
108  $change_theme_url.= str_replace('&', '&amp;', $_SERVER['QUERY_STRING']).'&amp;';
109}
110$change_theme_url.= 'change_theme=1';
111
112// ?page=plugin-community-pendings is an clean alias of
113// ?page=plugin&section=community/admin.php&tab=pendings
114if (isset($_GET['page']) and preg_match('/^plugin-([^-]*)(?:-(.*))?$/', $_GET['page'], $matches))
115{
116  $_GET['page'] = 'plugin';
117  $_GET['section'] = $matches[1].'/admin.php';
118  if (isset($matches[2]))
119  {
120    $_GET['tab'] = $matches[2];
121  }
122}
123
124// ?page=album-134-properties is an clean alias of
125// ?page=album&cat_id=134&tab=properties
126if (isset($_GET['page']) and preg_match('/^album-(\d+)(?:-(.*))?$/', $_GET['page'], $matches))
127{
128  $_GET['page'] = 'album';
129  $_GET['cat_id'] = $matches[1];
130  if (isset($matches[2]))
131  {
132    $_GET['tab'] = $matches[2];
133  }
134}
135
136// ?page=photo-1234-properties is an clean alias of
137// ?page=photo&image_id=1234&tab=properties
138if (isset($_GET['page']) and preg_match('/^photo-(\d+)(?:-(.*))?$/', $_GET['page'], $matches))
139{
140  $_GET['page'] = 'photo';
141  $_GET['image_id'] = $matches[1];
142  if (isset($matches[2]))
143  {
144    $_GET['tab'] = $matches[2];
145  }
146}
147
148if (isset($_GET['page'])
149    and preg_match('/^[a-z_]*$/', $_GET['page'])
150    and is_file(PHPWG_ROOT_PATH.'admin/'.$_GET['page'].'.php'))
151{
152  $page['page'] = $_GET['page'];
153}
154else
155{
156  $page['page'] = 'intro';
157}
158
159$link_start = PHPWG_ROOT_PATH.'admin.php?page=';
160$conf_link = $link_start.'configuration&amp;section=';
161
162// +-----------------------------------------------------------------------+
163// | Template init                                                         |
164// +-----------------------------------------------------------------------+
165
166$title = l10n('Piwigo Administration'); // for include/page_header.php
167$page['page_banner'] = '<h1>'.l10n('Piwigo Administration').'</h1>';
168$page['body_id'] = 'theAdminPage';
169
170$template->set_filenames(array('admin' => 'admin.tpl'));
171
172$template->assign(
173  array(
174    'USERNAME' => $user['username'],
175    'ENABLE_SYNCHRONIZATION' => $conf['enable_synchronization'],
176    'U_SITE_MANAGER'=> $link_start.'site_manager',
177    'U_HISTORY_STAT'=> $link_start.'stats',
178    'U_FAQ'=> $link_start.'help',
179    'U_SITES'=> $link_start.'remote_site',
180    'U_MAINTENANCE'=> $link_start.'maintenance',
181    'U_NOTIFICATION_BY_MAIL'=> $link_start.'notification_by_mail',
182    'U_CONFIG_GENERAL'=> $link_start.'configuration',
183    'U_CONFIG_DISPLAY'=> $conf_link.'default',
184    'U_CONFIG_EXTENTS'=> $link_start.'extend_for_templates',
185    'U_CONFIG_MENUBAR'=> $link_start.'menubar',
186    'U_CONFIG_LANGUAGES' => $link_start.'languages',
187    'U_CONFIG_THEMES'=> $link_start.'themes',
188    'U_CATEGORIES'=> $link_start.'cat_list',
189    'U_CAT_OPTIONS'=> $link_start.'cat_options',
190    'U_CAT_UPDATE'=> $link_start.'site_update&amp;site=1',
191    'U_RATING'=> $link_start.'rating',
192    'U_RECENT_SET'=> $link_start.'batch_manager&amp;filter=prefilter-last_import',
193    'U_BATCH'=> $link_start.'batch_manager',
194    'U_TAGS'=> $link_start.'tags',
195    'U_USERS'=> $link_start.'user_list',
196    'U_GROUPS'=> $link_start.'group_list',
197    'U_RETURN'=> get_gallery_home_url(),
198    'U_ADMIN'=> PHPWG_ROOT_PATH.'admin.php',
199    'U_LOGOUT'=> PHPWG_ROOT_PATH.'index.php?act=logout',
200    'U_PLUGINS'=> $link_start.'plugins',
201    'U_ADD_PHOTOS' => $link_start.'photos_add',
202    'U_CHANGE_THEME' => $change_theme_url,
203    'U_UPDATES' => $link_start.'updates',
204    )
205  );
206 
207if ($conf['activate_comments'])
208{
209  $template->assign('U_COMMENTS', $link_start.'comments');
210 
211  // pending comments
212  $query = '
213SELECT COUNT(*)
214  FROM '.COMMENTS_TABLE.'
215  WHERE validated=\'false\'
216;';
217  list($nb_comments) = pwg_db_fetch_row(pwg_query($query));
218
219  if ($nb_comments > 0)
220  {
221    $template->assign('NB_PENDING_COMMENTS', $nb_comments);
222  }
223}
224
225// any photo in the caddie?
226$query = '
227SELECT COUNT(*)
228  FROM '.CADDIE_TABLE.'
229  WHERE user_id = '.$user['id'].'
230;';
231list($nb_photos_in_caddie) = pwg_db_fetch_row(pwg_query($query));
232
233if ($nb_photos_in_caddie > 0)
234{
235  $template->assign(
236    array(
237      'NB_PHOTOS_IN_CADDIE' => $nb_photos_in_caddie,
238      'U_CADDIE' => $link_start.'batch_manager&amp;filter=prefilter-caddie',
239      )
240    );
241}
242
243// +-----------------------------------------------------------------------+
244// | Plugin menu                                                           |
245// +-----------------------------------------------------------------------+
246
247$plugin_menu_links = trigger_event('get_admin_plugin_menu_links', array() );
248
249function UC_name_compare($a, $b)
250{
251  return strcmp(strtolower($a['NAME']), strtolower($b['NAME']));
252}
253usort($plugin_menu_links, 'UC_name_compare');
254$template->assign('plugin_menu_items', $plugin_menu_links);
255
256// +-----------------------------------------------------------------------+
257// | Refresh permissions                                                   |
258// +-----------------------------------------------------------------------+
259
260// Only for pages witch change permissions
261if (
262    in_array($page['page'],
263      array(
264        'site_manager', // delete site
265        'site_update',  // ?only POST
266      )
267    )
268    or ( !empty($_POST) and in_array($page['page'],
269        array(
270          'album',        // public/private; lock/unlock, permissions
271          'cat_move',
272          'cat_options',  // public/private; lock/unlock
273          'batch_manager',  // associate/dissociate; delete; set level
274          'user_list',    // group assoc; user level
275          'user_perm',
276        )
277      )
278    )
279  )
280{
281  invalidate_user_cache();
282}
283
284// +-----------------------------------------------------------------------+
285// | Include specific page                                                 |
286// +-----------------------------------------------------------------------+
287
288trigger_action('loc_begin_admin_page');
289include(PHPWG_ROOT_PATH.'admin/'.$page['page'].'.php');
290
291$template->assign('ACTIVE_MENU', get_active_menu($page['page']));
292
293// +-----------------------------------------------------------------------+
294// | Sending html code                                                     |
295// +-----------------------------------------------------------------------+
296
297// Add the Piwigo Official menu
298$template->assign( 'pwgmenu', pwg_URL() );
299
300include(PHPWG_ROOT_PATH.'include/page_header.php');
301
302trigger_action('loc_end_admin');
303
304flush_page_messages();
305
306$template->pparse('admin');
307
308include(PHPWG_ROOT_PATH.'include/page_tail.php');
309?>
Note: See TracBrowser for help on using the repository browser.