Skip to content

Commit

Permalink
feature:2317 move order config to Admin->Config->Options
Browse files Browse the repository at this point in the history
change regex test, now compatible with strings like "file COLLATE 'utf8_general_ci' ASC"

git-svn-id: http://piwigo.org/svn/trunk@11433 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jun 19, 2011
1 parent b213308 commit 0f3c1ea
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions admin/configuration.php
Expand Up @@ -103,8 +103,10 @@
);

$order_options = array(
' ORDER BY date_available DESC, file ASC, id ASC' => 'date_available DESC, file ASC, id ASC',
' ORDER BY file DESC, date_available DESC' => 'file DESC, date_available DESC',
' ORDER BY date_available DESC, file ASC, id ASC' => 'Post date DESC, File name ASC',
' ORDER BY date_available ASC, file ASC, id ASC' => 'Post date ASC, File name ASC',
' ORDER BY file DESC, date_available DESC, id ASC' => 'File name DESC, Post date DESC',
' ORDER BY file ASC, date_available DESC, id ASC' => 'File name ASC, Post date DESC',
'custom' => l10n('Custom'),
);

Expand All @@ -117,19 +119,20 @@
{
case 'main' :
{
$order_regex = '#^(( *)(id|file|name|date_available|date_creation|hit|average_rate|comment|author|filesize|width|height|high_filesize|high_width|high_height) (ASC|DESC),{1}){1,}$#';
$order_regex = '#^(([ \w\']{2,}) (ASC|DESC),{1}){1,}$#';
// process 'order_by_perso' string
if ($_POST['order_by'] == 'custom' AND !empty($_POST['order_by_perso']))
{
$_POST['order_by_perso'] = stripslashes(trim($_POST['order_by_perso']));
$_POST['order_by'] = str_ireplace(
array('order by ', 'asc', 'desc'),
array(null, 'ASC', 'DESC'),
trim($_POST['order_by_perso'])
array('order by ', 'asc', 'desc', '"'),
array(null, 'ASC', 'DESC', '\''),
$_POST['order_by_perso']
);

if (preg_match($order_regex, $_POST['order_by'].','))
{
$_POST['order_by'] = ' ORDER BY '.$_POST['order_by'];
$_POST['order_by'] = ' ORDER BY '.addslashes($_POST['order_by']);
}
else
{
Expand All @@ -147,15 +150,16 @@
}
else if ($_POST['order_by_inside_category'] == 'custom' AND !empty($_POST['order_by_inside_category_perso']))
{
$_POST['order_by_inside_category_perso'] = stripslashes(trim($_POST['order_by_inside_category_perso']));
$_POST['order_by_inside_category'] = str_ireplace(
array('order by ', 'asc', 'desc'),
array(null, 'ASC', 'DESC'),
trim($_POST['order_by_inside_category_perso'])
array('order by ', 'asc', 'desc', '"'),
array(null, 'ASC', 'DESC', '\''),
$_POST['order_by_inside_category_perso']
);

if (preg_match($order_regex, $_POST['order_by_inside_category'].','))
{
$_POST['order_by_inside_category'] = ' ORDER BY '.$_POST['order_by_inside_category'];
$_POST['order_by_inside_category'] = ' ORDER BY '.addslashes($_POST['order_by_inside_category']);
}
else
{
Expand Down

0 comments on commit 0f3c1ea

Please sign in to comment.