Skip to content

Commit

Permalink
bug 2931: revert r23675 & r23721, make element_set_ranks.php uses ASC…
Browse files Browse the repository at this point in the history
… keyword (+ migration task)

git-svn-id: http://piwigo.org/svn/trunk@23813 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jul 6, 2013
1 parent 754af8d commit 29e2ed6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 38 deletions.
36 changes: 14 additions & 22 deletions admin/configuration.php
Expand Up @@ -112,21 +112,21 @@
// image order management
$sort_fields = array(
'' => '',
'file' => l10n('File name, A → Z'),
'file ASC' => l10n('File name, A → Z'),
'file DESC' => l10n('File name, Z → A'),
'name' => l10n('Photo title, A → Z'),
'name ASC' => l10n('Photo title, A → Z'),
'name DESC' => l10n('Photo title, Z → A'),
'date_creation DESC' => l10n('Date created, new → old'),
'date_creation' => l10n('Date created, old → new'),
'date_creation ASC' => l10n('Date created, old → new'),
'date_available DESC' => l10n('Date posted, new → old'),
'date_available' => l10n('Date posted, old → new'),
'date_available ASC' => l10n('Date posted, old → new'),
'rating_score DESC' => l10n('Rating score, high → low'),
'rating_score' => l10n('Rating score, low → high'),
'rating_score ASC' => l10n('Rating score, low → high'),
'hit DESC' => l10n('Visits, high → low'),
'hit' => l10n('Visits, low → high'),
'id' => l10n('Numeric identifier, 1 → 9'),
'hit ASC' => l10n('Visits, low → high'),
'id ASC' => l10n('Numeric identifier, 1 → 9'),
'id DESC' => l10n('Numeric identifier, 9 → 1'),
'rank' => l10n('Manual sort order'),
'rank ASC' => l10n('Manual sort order'),
);

$comments_order = array(
Expand Down Expand Up @@ -162,19 +162,19 @@
$order_by = $order_by_inside_category = array_slice($_POST['order_by'], 0, ceil(count($sort_fields)/2));

// there is no rank outside categories
if ( ($i = array_search('rank', $order_by)) !== false)
if ( ($i = array_search('rank ASC', $order_by)) !== false)
{
unset($order_by[$i]);
}

// must define a default order_by if user want to order by rank only
if ( count($order_by) == 0 )
{
$order_by = array('id');
$order_by = array('id ASC');
}

$_POST['order_by'] = 'ORDER BY '.implode(',', $order_by);
$_POST['order_by_inside_category'] = 'ORDER BY '.implode(',', $order_by_inside_category);
$_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
$_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
}
}
else
Expand Down Expand Up @@ -334,18 +334,10 @@ function order_by_is_local()
}
else
{
$out = array();
$order_by = trim($conf['order_by_inside_category']);
$order_by = str_replace('ORDER BY ', null, $order_by);
$order_by = explode(',', $order_by);
foreach($order_by as &$order)
{
$order = trim($order);
if (substr_compare($order, ' ASC', -4)==0)
{
$order = substr($order, 0, -4);
}
}
unset($order);
$order_by = explode(', ', $order_by);
}

$template->assign(
Expand Down
18 changes: 9 additions & 9 deletions admin/element_set_ranks.php
Expand Up @@ -124,7 +124,7 @@ function save_images_order($category_id, $images)
}
elseif ($image_order_choice=='rank')
{
$image_order = 'rank';
$image_order = 'rank ASC';
}
$query = '
UPDATE '.CATEGORIES_TABLE.'
Expand Down Expand Up @@ -237,21 +237,21 @@ function save_images_order($category_id, $images)
// image order management
$sort_fields = array(
'' => '',
'file' => l10n('File name, A → Z'),
'file ASC' => l10n('File name, A → Z'),
'file DESC' => l10n('File name, Z → A'),
'name' => l10n('Photo title, A → Z'),
'name ASC' => l10n('Photo title, A → Z'),
'name DESC' => l10n('Photo title, Z → A'),
'date_creation DESC' => l10n('Date created, new → old'),
'date_creation' => l10n('Date created, old → new'),
'date_creation ASC' => l10n('Date created, old → new'),
'date_available DESC' => l10n('Date posted, new → old'),
'date_available' => l10n('Date posted, old → new'),
'date_available ASC' => l10n('Date posted, old → new'),
'rating_score DESC' => l10n('Rating score, high → low'),
'rating_score' => l10n('Rating score, low → high'),
'rating_score ASC' => l10n('Rating score, low → high'),
'hit DESC' => l10n('Visits, high → low'),
'hit' => l10n('Visits, low → high'),
'id' => l10n('Numeric identifier, 1 → 9'),
'hit ASC' => l10n('Visits, low → high'),
'id ASC' => l10n('Numeric identifier, 1 → 9'),
'id DESC' => l10n('Numeric identifier, 9 → 1'),
'rank' => l10n('Manual sort order'),
'rank ASC' => l10n('Manual sort order'),
);

$template->assign('image_order_options', $sort_fields);
Expand Down
10 changes: 5 additions & 5 deletions include/functions_category.inc.php
Expand Up @@ -221,16 +221,16 @@ function get_category_preferred_image_orders()

return trigger_event('get_category_preferred_image_orders', array(
array(l10n('Default'), '', true),
array(l10n('Photo title, A → Z'), 'name', true),
array(l10n('Photo title, A → Z'), 'name ASC', true),
array(l10n('Photo title, Z → A'), 'name DESC', true),
array(l10n('Date created, new → old'), 'date_creation DESC', true),
array(l10n('Date created, old → new'), 'date_creation', true),
array(l10n('Date created, old → new'), 'date_creation ASC', true),
array(l10n('Date posted, new → old'), 'date_available DESC', true),
array(l10n('Date posted, old → new'), 'date_available', true),
array(l10n('Date posted, old → new'), 'date_available ASC', true),
array(l10n('Rating score, high → low'), 'rating_score DESC', $conf['rate']),
array(l10n('Rating score, low → high'), 'rating_score', $conf['rate']),
array(l10n('Rating score, low → high'), 'rating_score ASC', $conf['rate']),
array(l10n('Visits, high → low'), 'hit DESC', true),
array(l10n('Visits, low → high'), 'hit', true),
array(l10n('Visits, low → high'), 'hit ASC', true),
array(l10n('Permissions'), 'level DESC', is_admin()),
));
}
Expand Down
4 changes: 2 additions & 2 deletions install/config.sql
Expand Up @@ -56,8 +56,8 @@ INSERT INTO piwigo_config (param,value,comment)
);
INSERT INTO piwigo_config (param,value,comment) VALUES ('week_starts_on','monday','Monday may not be the first day of the week');
INSERT INTO piwigo_config (param,value,comment) VALUES ('updates_ignored','a:3:{s:7:"plugins";a:0:{}s:6:"themes";a:0:{}s:9:"languages";a:0:{}}','Extensions ignored for update');
INSERT INTO piwigo_config (param,value,comment) VALUES ('order_by','ORDER BY date_available DESC,file,id','default photo order');
INSERT INTO piwigo_config (param,value,comment) VALUES ('order_by_inside_category','ORDER BY date_available DESC,file,id','default photo order inside category');
INSERT INTO piwigo_config (param,value,comment) VALUES ('order_by','ORDER BY date_available DESC, file ASC, id ASC','default photo order');
INSERT INTO piwigo_config (param,value,comment) VALUES ('order_by_inside_category','ORDER BY date_available DESC, file ASC, id ASC','default photo order inside category');
INSERT INTO piwigo_config (param,value) VALUES ('original_resize','false');
INSERT INTO piwigo_config (param,value) VALUES ('original_resize_maxwidth','2016');
INSERT INTO piwigo_config (param,value) VALUES ('original_resize_maxheight','2016');
Expand Down
62 changes: 62 additions & 0 deletions install/db/137-database.php
@@ -0,0 +1,62 @@
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org |
// | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net |
// | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick |
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation |
// | |
// | This program is distributed in the hope that it will be useful, but |
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA. |
// +-----------------------------------------------------------------------+

defined('PHPWG_ROOT_PATH') or die('Hacking attempt!');

$upgrade_description = 'add ASC keyword to categories image_order field';


$query = '
SELECT id, image_order
FROM '.CATEGORIES_TABLE.'
WHERE image_order != ""
;';
$cats = hash_from_query($query, 'id');

foreach ($cats as $id => &$data)
{
$image_order = explode(',',$data['image_order']);
foreach ($image_order as &$order)
{
if (strpos($order, ' ASC')===false && strpos($order, ' DESC')===false)
{
$order.= ' ASC';
}
}
unset($order);
$data['image_order'] = implode(',',$image_order);
}
unset($data);

mass_updates(CATEGORIES_TABLE,
array(
'primary' => array('id'),
'update' => array('image_order'),
),
$cats
);


echo "\n".$upgrade_description."\n";

?>

0 comments on commit 29e2ed6

Please sign in to comment.