source: trunk/admin/permalinks.php @ 1956

Last change on this file since 1956 was 1956, checked in by rvelices, 18 years ago

merge r1955 from branch-1_7 to trunk:
flat view small improvements (picture page on root category sorter urls and works in several cases)
correction in permalinks admin (error was assignment in if instead of comparison)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
5// +-----------------------------------------------------------------------+
6// | file          : $Id: permalinks.php 1956 2007-04-13 23:58:28Z rvelices $
7// | last update   : $Date: 2007-04-13 23:58:28 +0000 (Fri, 13 Apr 2007) $
8// | last modifier : $Author: rvelices $
9// | revision      : $Revision: 1956 $
10// +-----------------------------------------------------------------------+
11// | This program is free software; you can redistribute it and/or modify  |
12// | it under the terms of the GNU General Public License as published by  |
13// | the Free Software Foundation                                          |
14// |                                                                       |
15// | This program is distributed in the hope that it will be useful, but   |
16// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
17// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
18// | General Public License for more details.                              |
19// |                                                                       |
20// | You should have received a copy of the GNU General Public License     |
21// | along with this program; if not, write to the Free Software           |
22// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
23// | USA.                                                                  |
24// +-----------------------------------------------------------------------+
25
26function parse_sort_variables(
27    $sortable_by, $default_field,
28    $get_param, $get_rejects,
29    $template_var )
30{
31  global $template;
32 
33  $url_components = parse_url( $_SERVER['REQUEST_URI'] );
34
35  $base_url = $url_components['path'];
36 
37  parse_str($url_components['query'], $vars);
38  $is_first = true;
39  foreach ($vars as $key => $value)
40  {
41    if (!in_array($key, $get_rejects) and $key!=$get_param)
42    {
43      $base_url .= $is_first ? '?' : '&amp;';
44      $is_first = false;
45      $base_url .= $key.'='.urlencode($value);
46    }
47  }
48
49  $ret = array();
50  foreach( $sortable_by as $field)
51  {
52    $url = $base_url;
53    if ( $field !== @$_GET[$get_param] )
54    {
55      if ( !isset($default_field) or $default_field!=$field )
56      { // the first should be the default
57        $url = add_url_params($url, array($get_param=>$field) );
58      }
59      $disp = '&dArr;'; // TODO: an small image is better
60    }
61    else
62    {
63      array_push($ret, $field);
64      $disp = '<em>&dArr;</em>'; // TODO: an small image is better
65    }
66    if ( isset($template_var) )
67    {
68      $template->assign_var( $template_var.strtoupper($field),
69            '<a href="'.$url.'" title="'.l10n('Sort order').'">'.$disp.'</a>'
70         );
71    }
72  }
73  return $ret;
74}
75
76if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
77
78include_once(PHPWG_ROOT_PATH.'admin/include/functions_permalinks.php');
79
80$selected_cat = array();
81if ( isset($_POST['set_permalink']) and $_POST['cat_id']>0 )
82{
83  $permalink = $_POST['permalink'];
84  if ( empty($permalink) )
85    delete_cat_permalink($_POST['cat_id'], isset($_POST['save']) );
86  else
87    set_cat_permalink($_POST['cat_id'], $permalink, isset($_POST['save']) );
88  $selected_cat = array( $_POST['cat_id'] );
89}
90elseif ( isset($_GET['delete_permanent']) )
91{
92  $query = '
93DELETE FROM '.OLD_PERMALINKS_TABLE.'
94  WHERE permalink="'.$_GET['delete_permanent'].'"
95  LIMIT 1';
96  pwg_query($query);
97  if (mysql_affected_rows()==0)
98    array_push($page['errors'], 'Cannot delete the old permalink !');
99}
100
101
102$template->set_filename('permalinks', 'admin/permalinks.tpl' );
103
104$query = '
105SELECT
106  id,
107  CONCAT(id, " - ", name, IF(permalink IS NULL, "", " &radic;") ) AS name,
108  uppercats, global_rank
109FROM '.CATEGORIES_TABLE;
110
111display_select_cat_wrapper( $query, $selected_cat, 'categories', false );
112
113
114// --- generate display of active permalinks -----------------------------------
115$sort_by = parse_sort_variables(
116    array('id', 'name', 'permalink'), 'name',
117    'psf',
118    array('delete_permanent'),
119    'SORT_' );
120
121$query = '
122SELECT id, permalink, uppercats, global_rank
123  FROM '.CATEGORIES_TABLE.'
124  WHERE permalink IS NOT NULL
125';
126if ( count($sort_by) and
127      ($sort_by[0]=='id' or $sort_by[0]=='permalink')
128    )
129{
130  $query .= ' ORDER BY '.$sort_by[0];
131}
132$categories=array();
133$result=pwg_query($query);
134while ( $row=mysql_fetch_assoc($result) )
135{
136  $row['name'] = get_cat_display_name_cache( $row['uppercats'] );
137  $categories[] = $row;
138}
139
140if ( !count($sort_by) or $sort_by[0]=='name')
141{
142  usort($categories, 'global_rank_compare');
143}
144foreach ($categories as $cat)
145{
146  $template->assign_block_vars( 'permalink', $cat );
147}
148
149
150// --- generate display of old permalinks --------------------------------------
151
152$sort_by = parse_sort_variables(
153    array('cat_id','permalink','date_deleted','last_hit','hit'), null,
154    'dpsf',
155    array('delete_permanent'),
156    'SORT_OLD_' );
157
158$url_del_base = get_root_url().'admin.php?page=permalinks';
159$query = 'SELECT * FROM '.OLD_PERMALINKS_TABLE;
160if ( count($sort_by) )
161{
162  $query .= ' ORDER BY '.$sort_by[0];
163}
164$result = pwg_query($query);
165while ( $row=mysql_fetch_assoc($result) )
166{
167  $row['name'] = get_cat_display_name_cache($row['cat_id']);
168  $row['U_DELETE'] =
169      add_url_params(
170        $url_del_base,
171        array( 'delete_permanent'=> $row['permalink'] )
172      );
173  $template->assign_block_vars( 'deleted_permalink', $row );
174}
175
176$template->assign_var('U_HELP', get_root_url().'popuphelp.php?page=permalinks');
177
178$template->assign_var_from_handle('ADMIN_CONTENT', 'permalinks');
179?>
Note: See TracBrowser for help on using the repository browser.