PageRenderTime 27ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/fsn-site-central/mediatheque/admin.php

https://gitlab.com/team_fsn/fsn-php
PHP | 321 lines | 207 code | 49 blank | 65 comment | 19 complexity | ca75367584a51f41f8d46de9b473bd94 MD5 | raw file
  1. <?php
  2. // +-----------------------------------------------------------------------+
  3. // | Piwigo - a PHP based photo gallery |
  4. // +-----------------------------------------------------------------------+
  5. // | Copyright(C) 2008-2016 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. // | Basic constants and includes |
  25. // +-----------------------------------------------------------------------+
  26. define('PHPWG_ROOT_PATH','./');
  27. define('IN_ADMIN', true);
  28. include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
  29. include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
  30. include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php');
  31. include_once(PHPWG_ROOT_PATH.'admin/include/add_core_tabs.inc.php');
  32. trigger_notify('loc_begin_admin');
  33. // +-----------------------------------------------------------------------+
  34. // | Check Access and exit when user status is not ok |
  35. // +-----------------------------------------------------------------------+
  36. check_status(ACCESS_ADMINISTRATOR);
  37. // +-----------------------------------------------------------------------+
  38. // | Direct actions |
  39. // +-----------------------------------------------------------------------+
  40. // save plugins_new display order (AJAX action)
  41. if (isset($_GET['plugins_new_order']))
  42. {
  43. pwg_set_session_var('plugins_new_order', $_GET['plugins_new_order']);
  44. exit;
  45. }
  46. // theme changer
  47. if (isset($_GET['change_theme']))
  48. {
  49. $admin_themes = array('roma', 'clear');
  50. $new_admin_theme = array_pop(
  51. array_diff(
  52. $admin_themes,
  53. array($conf['admin_theme'])
  54. )
  55. );
  56. conf_update_param('admin_theme', $new_admin_theme);
  57. $url_params = array();
  58. foreach (array('page', 'tab', 'section') as $url_param)
  59. {
  60. if (isset($_GET[$url_param]))
  61. {
  62. $url_params[] = $url_param.'='.$_GET[$url_param];
  63. }
  64. }
  65. $redirect_url = 'admin.php';
  66. if (count($url_params) > 0)
  67. {
  68. $redirect_url.= '?'.implode('&amp;', $url_params);
  69. }
  70. redirect($redirect_url);
  71. }
  72. // +-----------------------------------------------------------------------+
  73. // | Synchronize user informations |
  74. // +-----------------------------------------------------------------------+
  75. // sync_user() is only useful when external authentication is activated
  76. if ($conf['external_authentification'])
  77. {
  78. sync_users();
  79. }
  80. // +-----------------------------------------------------------------------+
  81. // | Variables init |
  82. // +-----------------------------------------------------------------------+
  83. $change_theme_url = PHPWG_ROOT_PATH.'admin.php?';
  84. $test_get = $_GET;
  85. unset($test_get['page']);
  86. unset($test_get['section']);
  87. unset($test_get['tag']);
  88. if (count($test_get) == 0 and !empty($_SERVER['QUERY_STRING']))
  89. {
  90. $change_theme_url.= str_replace('&', '&amp;', $_SERVER['QUERY_STRING']).'&amp;';
  91. }
  92. $change_theme_url.= 'change_theme=1';
  93. // ?page=plugin-community-pendings is an clean alias of
  94. // ?page=plugin&section=community/admin.php&tab=pendings
  95. if (isset($_GET['page']) and preg_match('/^plugin-([^-]*)(?:-(.*))?$/', $_GET['page'], $matches))
  96. {
  97. $_GET['page'] = 'plugin';
  98. $_GET['section'] = $matches[1].'/admin.php';
  99. if (isset($matches[2]))
  100. {
  101. $_GET['tab'] = $matches[2];
  102. }
  103. }
  104. // ?page=album-134-properties is an clean alias of
  105. // ?page=album&cat_id=134&tab=properties
  106. if (isset($_GET['page']) and preg_match('/^album-(\d+)(?:-(.*))?$/', $_GET['page'], $matches))
  107. {
  108. $_GET['page'] = 'album';
  109. $_GET['cat_id'] = $matches[1];
  110. if (isset($matches[2]))
  111. {
  112. $_GET['tab'] = $matches[2];
  113. }
  114. }
  115. // ?page=photo-1234-properties is an clean alias of
  116. // ?page=photo&image_id=1234&tab=properties
  117. if (isset($_GET['page']) and preg_match('/^photo-(\d+)(?:-(.*))?$/', $_GET['page'], $matches))
  118. {
  119. $_GET['page'] = 'photo';
  120. $_GET['image_id'] = $matches[1];
  121. if (isset($matches[2]))
  122. {
  123. $_GET['tab'] = $matches[2];
  124. }
  125. }
  126. if (isset($_GET['page'])
  127. and preg_match('/^[a-z_]*$/', $_GET['page'])
  128. and is_file(PHPWG_ROOT_PATH.'admin/'.$_GET['page'].'.php'))
  129. {
  130. $page['page'] = $_GET['page'];
  131. }
  132. else
  133. {
  134. $page['page'] = 'intro';
  135. }
  136. $link_start = PHPWG_ROOT_PATH.'admin.php?page=';
  137. $conf_link = $link_start.'configuration&amp;section=';
  138. // +-----------------------------------------------------------------------+
  139. // | Template init |
  140. // +-----------------------------------------------------------------------+
  141. $title = l10n('Piwigo Administration'); // for include/page_header.php
  142. $page['page_banner'] = '<h1>'.l10n('Piwigo Administration').'</h1>';
  143. $page['body_id'] = 'theAdminPage';
  144. $template->set_filenames(array('admin' => 'admin.tpl'));
  145. $template->assign(
  146. array(
  147. 'USERNAME' => $user['username'],
  148. 'ENABLE_SYNCHRONIZATION' => $conf['enable_synchronization'],
  149. 'U_SITE_MANAGER'=> $link_start.'site_manager',
  150. 'U_HISTORY_STAT'=> $link_start.'stats',
  151. 'U_FAQ'=> $link_start.'help',
  152. 'U_SITES'=> $link_start.'remote_site',
  153. 'U_MAINTENANCE'=> $link_start.'maintenance',
  154. 'U_NOTIFICATION_BY_MAIL'=> $link_start.'notification_by_mail',
  155. 'U_CONFIG_GENERAL'=> $link_start.'configuration',
  156. 'U_CONFIG_DISPLAY'=> $conf_link.'default',
  157. 'U_CONFIG_EXTENTS'=> $link_start.'extend_for_templates',
  158. 'U_CONFIG_MENUBAR'=> $link_start.'menubar',
  159. 'U_CONFIG_LANGUAGES' => $link_start.'languages',
  160. 'U_CONFIG_THEMES'=> $link_start.'themes',
  161. 'U_CATEGORIES'=> $link_start.'cat_list',
  162. 'U_CAT_OPTIONS'=> $link_start.'cat_options',
  163. 'U_CAT_UPDATE'=> $link_start.'site_update&amp;site=1',
  164. 'U_RATING'=> $link_start.'rating',
  165. 'U_RECENT_SET'=> $link_start.'batch_manager&amp;filter=prefilter-last_import',
  166. 'U_BATCH'=> $link_start.'batch_manager',
  167. 'U_TAGS'=> $link_start.'tags',
  168. 'U_USERS'=> $link_start.'user_list',
  169. 'U_GROUPS'=> $link_start.'group_list',
  170. 'U_RETURN'=> get_gallery_home_url(),
  171. 'U_ADMIN'=> PHPWG_ROOT_PATH.'admin.php',
  172. 'U_LOGOUT'=> PHPWG_ROOT_PATH.'index.php?act=logout',
  173. 'U_PLUGINS'=> $link_start.'plugins',
  174. 'U_ADD_PHOTOS' => $link_start.'photos_add',
  175. 'U_CHANGE_THEME' => $change_theme_url,
  176. 'U_UPDATES' => $link_start.'updates',
  177. )
  178. );
  179. if ($conf['activate_comments'])
  180. {
  181. $template->assign('U_COMMENTS', $link_start.'comments');
  182. // pending comments
  183. $query = '
  184. SELECT COUNT(*)
  185. FROM '.COMMENTS_TABLE.'
  186. WHERE validated=\'false\'
  187. ;';
  188. list($nb_comments) = pwg_db_fetch_row(pwg_query($query));
  189. if ($nb_comments > 0)
  190. {
  191. $template->assign('NB_PENDING_COMMENTS', $nb_comments);
  192. }
  193. }
  194. // any photo in the caddie?
  195. $query = '
  196. SELECT COUNT(*)
  197. FROM '.CADDIE_TABLE.'
  198. WHERE user_id = '.$user['id'].'
  199. ;';
  200. list($nb_photos_in_caddie) = pwg_db_fetch_row(pwg_query($query));
  201. if ($nb_photos_in_caddie > 0)
  202. {
  203. $template->assign(
  204. array(
  205. 'NB_PHOTOS_IN_CADDIE' => $nb_photos_in_caddie,
  206. 'U_CADDIE' => $link_start.'batch_manager&amp;filter=prefilter-caddie',
  207. )
  208. );
  209. }
  210. // any orphan photo?
  211. $nb_orphans = count(get_orphans());
  212. if ($nb_orphans > 0)
  213. {
  214. $template->assign(
  215. array(
  216. 'NB_ORPHANS' => $nb_orphans,
  217. 'U_ORPHANS' => $link_start.'batch_manager&amp;filter=prefilter-no_album',
  218. )
  219. );
  220. }
  221. // +-----------------------------------------------------------------------+
  222. // | Plugin menu |
  223. // +-----------------------------------------------------------------------+
  224. $plugin_menu_links = trigger_change('get_admin_plugin_menu_links', array() );
  225. function UC_name_compare($a, $b)
  226. {
  227. return strcmp(strtolower($a['NAME']), strtolower($b['NAME']));
  228. }
  229. usort($plugin_menu_links, 'UC_name_compare');
  230. $template->assign('plugin_menu_items', $plugin_menu_links);
  231. // +-----------------------------------------------------------------------+
  232. // | Refresh permissions |
  233. // +-----------------------------------------------------------------------+
  234. // Only for pages witch change permissions
  235. if (
  236. in_array($page['page'],
  237. array(
  238. 'site_manager', // delete site
  239. 'site_update', // ?only POST
  240. )
  241. )
  242. or ( !empty($_POST) and in_array($page['page'],
  243. array(
  244. 'album', // public/private; lock/unlock, permissions
  245. 'cat_move',
  246. 'cat_options', // public/private; lock/unlock
  247. 'user_list', // group assoc; user level
  248. 'user_perm',
  249. )
  250. )
  251. )
  252. )
  253. {
  254. invalidate_user_cache();
  255. }
  256. // +-----------------------------------------------------------------------+
  257. // | Include specific page |
  258. // +-----------------------------------------------------------------------+
  259. trigger_notify('loc_begin_admin_page');
  260. include(PHPWG_ROOT_PATH.'admin/'.$page['page'].'.php');
  261. $template->assign('ACTIVE_MENU', get_active_menu($page['page']));
  262. // +-----------------------------------------------------------------------+
  263. // | Sending html code |
  264. // +-----------------------------------------------------------------------+
  265. // Add the Piwigo Official menu
  266. $template->assign( 'pwgmenu', pwg_URL() );
  267. include(PHPWG_ROOT_PATH.'include/page_header.php');
  268. trigger_notify('loc_end_admin');
  269. flush_page_messages();
  270. $template->pparse('admin');
  271. include(PHPWG_ROOT_PATH.'include/page_tail.php');
  272. ?>