source: trunk/admin/permalinks.php @ 25762

Last change on this file since 25762 was 25018, checked in by mistic100, 11 years ago

remove all array_push (50% slower than []) + some changes missing for feature:2978

  • Property svn:eol-style set to LF
File size: 6.0 KB
RevLine 
[1866]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[19703]5// | Copyright(C) 2008-2013 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1866]23
[1873]24function parse_sort_variables(
25    $sortable_by, $default_field,
26    $get_param, $get_rejects,
[1975]27    $template_var,
28    $anchor = '' )
[1873]29{
30  global $template;
[2119]31
[1873]32  $url_components = parse_url( $_SERVER['REQUEST_URI'] );
33
34  $base_url = $url_components['path'];
[2119]35
[1873]36  parse_str($url_components['query'], $vars);
37  $is_first = true;
38  foreach ($vars as $key => $value)
39  {
40    if (!in_array($key, $get_rejects) and $key!=$get_param)
41    {
42      $base_url .= $is_first ? '?' : '&amp;';
43      $is_first = false;
44      $base_url .= $key.'='.urlencode($value);
45    }
46  }
47
48  $ret = array();
49  foreach( $sortable_by as $field)
50  {
51    $url = $base_url;
[13282]52    $disp = '↓'; // TODO: an small image is better
[2119]53
[1873]54    if ( $field !== @$_GET[$get_param] )
55    {
56      if ( !isset($default_field) or $default_field!=$field )
57      { // the first should be the default
58        $url = add_url_params($url, array($get_param=>$field) );
59      }
[2119]60      elseif (isset($default_field) and !isset($_GET[$get_param]) )
61      {
[25018]62        $ret[] = $field;
[2119]63        $disp = '<em>'.$disp.'</em>';
64      }
[1873]65    }
66    else
67    {
[25018]68      $ret[] = $field;
[2119]69      $disp = '<em>'.$disp.'</em>';
[1873]70    }
71    if ( isset($template_var) )
72    {
[2223]73      $template->assign( $template_var.strtoupper($field),
[1975]74            '<a href="'.$url.$anchor.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
[1873]75         );
76    }
77  }
78  return $ret;
79}
80
[1866]81if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
82
83include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php');
84
85$selected_cat = array();
[8126]86if ( isset($_POST['set_permalink']) and $_POST['cat_id']>0 )
[1866]87{
88  $permalink = $_POST['permalink'];
89  if ( empty($permalink) )
90    delete_cat_permalink($_POST['cat_id'], isset($_POST['save']) );
91  else
92    set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save']) );
93  $selected_cat = array( $_POST['cat_id'] );
94}
[8126]95elseif ( isset($_GET['delete_permanent']) )
[1866]96{
97  $query = '
98DELETE FROM '.OLD_PERMALINKS_TABLE.'
[6550]99  WHERE permalink=\''.$_GET['delete_permanent'].'\'
[1866]100  LIMIT 1';
[5192]101  $result = pwg_query($query);
102  if (pwg_db_changes($result)==0)
[25018]103  {
104    $page['errors'][] = l10n('Cannot delete the old permalink !');
105  }
[1866]106}
107
[1873]108
[2530]109$template->set_filename('permalinks', 'permalinks.tpl' );
[1866]110
[13282]111// +-----------------------------------------------------------------------+
112// | tabs                                                                  |
113// +-----------------------------------------------------------------------+
114
115$page['tab'] = 'permalinks';
116include(PHPWG_ROOT_PATH.'admin/include/albums_tab.inc.php');
117
118
[1866]119$query = '
[2119]120SELECT
[5192]121  id, permalink,
[18579]122  CONCAT(id, " - ", name, IF(permalink IS NULL, "", " &radic;") ) AS name,
[2119]123  uppercats, global_rank
[1866]124FROM '.CATEGORIES_TABLE;
125
126display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
127
[1873]128
129// --- generate display of active permalinks -----------------------------------
130$sort_by = parse_sort_variables(
131    array('id', 'name', 'permalink'), 'name',
132    'psf',
133    array('delete_permanent'),
134    'SORT_' );
135
[1866]136$query = '
[1873]137SELECT id, permalink, uppercats, global_rank
[1866]138  FROM '.CATEGORIES_TABLE.'
[1873]139  WHERE permalink IS NOT NULL
140';
[2119]141if ( $sort_by[0]=='id' or $sort_by[0]=='permalink' )
[1873]142{
143  $query .= ' ORDER BY '.$sort_by[0];
144}
145$categories=array();
[1866]146$result=pwg_query($query);
[4325]147while ( $row = pwg_db_fetch_assoc($result) )
[1866]148{
[1873]149  $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
150  $categories[] = $row;
[1866]151}
152
[2119]153if ( $sort_by[0]=='name')
[1873]154{
155  usort($categories, 'global_rank_compare');
156}
[2223]157$template->assign( 'permalinks', $categories );
[1873]158
159// --- generate display of old permalinks --------------------------------------
160
161$sort_by = parse_sort_variables(
162    array('cat_id','permalink','date_deleted','last_hit','hit'), null,
163    'dpsf',
164    array('delete_permanent'),
[1975]165    'SORT_OLD_', '#old_permalinks' );
[1873]166
[1866]167$url_del_base = get_root_url().'admin.php?page=permalinks';
168$query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE;
[1873]169if ( count($sort_by) )
170{
171  $query .= ' ORDER BY '.$sort_by[0];
172}
[1866]173$result = pwg_query($query);
[2223]174$deleted_permalinks=array();
[4325]175while ( $row = pwg_db_fetch_assoc($result) )
[1866]176{
[1873]177  $row['name'] = get_cat_display_name_cache($row['cat_id']);
[1866]178  $row['U_DELETE'] =
179      add_url_params(
180        $url_del_base,
181        array( 'delete_permanent'=> $row['permalink'] )
182      );
[2223]183  $deleted_permalinks[] = $row;
[1866]184}
[2223]185$template->assign('deleted_permalinks', $deleted_permalinks);
[5920]186$template->assign('U_HELP', get_root_url().'admin/popuphelp.php?page=permalinks');
[1866]187
188$template->assign_var_from_handle('ADMIN_CONTENT', 'permalinks');
189?>
Note: See TracBrowser for help on using the repository browser.