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
new GUI interface for simple paterns
in GUI, order_by and order_by_inside_category are merged (not un DB)
users can define special paterns with $conf['order_by_custom'] and $conf['order_by_inside_category_custom']

git-svn-id: http://piwigo.org/svn/trunk@11587 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jul 1, 2011
1 parent c97377e commit 9c0cfb0
Show file tree
Hide file tree
Showing 19 changed files with 281 additions and 184 deletions.
162 changes: 77 additions & 85 deletions admin/configuration.php
Expand Up @@ -102,12 +102,21 @@
'privacy_level',
);

$order_options = array(
' 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'),
// image order management
$sort_fields = array(
'' => '',
'rank' => l10n('Rank'),
'file' => l10n('File name'),
'date_creation' => l10n('Creation date'),
'date_available' => l10n('Post date'),
'average_rate' => l10n('Average rate'),
'hit' => l10n('Most visited'),
'id' => 'Id',
);

$sort_directions = array(
'ASC' => l10n('ascending'),
'DESC' => l10n('descending'),
);

//------------------------------ verification and registration of modifications
Expand All @@ -118,58 +127,32 @@
switch ($page['section'])
{
case 'main' :
{
$order_regex = '#^(([ \w\']{2,}) (ASC|DESC),{1}){1,}$#';
// process 'order_by_perso' string
if ($_POST['order_by'] == 'custom' AND !empty($_POST['order_by_perso']))
{
if ( !isset($conf['order_by_custom']) and !isset($conf['order_by_inside_category_custom']) )
{
$_POST['order_by_perso'] = stripslashes(trim($_POST['order_by_perso']));
$_POST['order_by'] = str_ireplace(
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 '.addslashes($_POST['order_by']);
}
else
if ( !empty($_POST['order_by_field']) )
{
array_push($page['errors'], l10n('Invalid order string').' « '.$_POST['order_by'].' »');
}
}
else if ($_POST['order_by'] == 'custom')
{
array_push($page['errors'], l10n('Invalid order string'));
}
// process 'order_by_inside_category_perso' string
if ($_POST['order_by_inside_category'] == 'as_order_by')
{
$_POST['order_by_inside_category'] = $_POST['order_by'];
}
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', '\''),
$_POST['order_by_inside_category_perso']
);

if (preg_match($order_regex, $_POST['order_by_inside_category'].','))
{
$_POST['order_by_inside_category'] = ' ORDER BY '.addslashes($_POST['order_by_inside_category']);
}
else
{
array_push($page['errors'], l10n('Invalid order string').' « '.$_POST['order_by_inside_category'].' »');
$order_by = array();
$order_by_inside_category = array();
for ($i=0; $i<count($_POST['order_by_field']); $i++)
{
if ($_POST['order_by_field'][$i] == '')
{
array_push($page['errors'], l10n('No field selected'));
}
else
{
if ($_POST['order_by_field'][$i] != 'rank')
{
$order_by[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
}
$order_by_inside_category[] = $_POST['order_by_field'][$i].' '.$_POST['order_by_direction'][$i];
}
}
$_POST['order_by'] = 'ORDER BY '.implode(', ', $order_by);
$_POST['order_by_inside_category'] = 'ORDER BY '.implode(', ', $order_by_inside_category);
}
}
else if ($_POST['order_by_inside_category'] == 'custom')
{
array_push($page['errors'], l10n('Invalid order string'));
}

if (empty($_POST['gallery_locked']) and $conf['gallery_locked'])
{
Expand Down Expand Up @@ -294,35 +277,50 @@
switch ($page['section'])
{
case 'main' :
{
// process 'order_by' string
if (array_key_exists($conf['order_by'], $order_options))
{

function order_by_is_local()
{
$order_by_selected = $conf['order_by'];
$order_by_perso = null;
}
else
{
$order_by_selected = 'custom';
$order_by_perso = str_replace(' ORDER BY ', null, $conf['order_by']);
@include(PHPWG_ROOT_PATH. 'local/config/config.inc.php');
if (isset($conf['local_dir_site']))
{
@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
}

return isset($conf['order_by']) or isset($conf['order_by_inside_category']);
}
// process 'order_by_inside_category' string
if ($conf['order_by_inside_category'] == $conf['order_by'])

if (order_by_is_local())
{
$order_by_inside_category_selected = 'as_order_by';
$order_by_inside_category_perso = null;
array_push($page['warnings'], l10n('You have specified <i>$conf[\'order_by\']</i> in your local configuration file, this parameter in deprecated, please remove it or rename it into <i>$conf[\'order_by_custom\']</i> !'));
}
else if (array_key_exists($conf['order_by_inside_category'], $order_options))

if ( isset($conf['order_by_custom']) or isset($conf['order_by_inside_category_custom']) )
{
$order_by_inside_category_selected = $conf['order_by_inside_category'];
$order_by_inside_category_perso = null;
$order_by = array(array(
'FIELD' => '',
'DIRECTION' => 'ASC',
));

$template->assign('ORDER_BY_IS_CUSTOM', true);
}
else
{
$order_by_inside_category_selected = 'custom';
$order_by_inside_category_perso = str_replace(' ORDER BY ', null, $conf['order_by_inside_category']);
$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 $field)
{
$field= explode(' ', $field);
$out[] = array(
'FIELD' => $field[0],
'DIRECTION' => $field[1],
);
}
$order_by = $out;
}

$template->assign(
'main',
array(
Expand All @@ -334,17 +332,11 @@
'monday' => $lang['day'][1],
),
'week_starts_on_options_selected' => $conf['week_starts_on'],
'order_by_options' => $order_options,
'order_by_selected' => $order_by_selected,
'order_by_perso' => $order_by_perso,
'order_by_inside_category_options' =>
array_merge(
array('as_order_by'=>l10n('As default order')),
$order_options
),
'order_by_inside_category_selected' => $order_by_inside_category_selected,
'order_by_inside_category_perso' => $order_by_inside_category_perso,
));
'order_by' => $order_by,
'order_field_options' => $sort_fields,
'order_direction_options' => $sort_directions,
)
);

foreach ($main_checkboxes as $checkbox)
{
Expand Down
56 changes: 32 additions & 24 deletions admin/themes/default/template/configuration.tpl
Expand Up @@ -100,39 +100,47 @@
&nbsp;
<span class="property">
{'Default photos order'|@translate}
{html_options name="order_by" options=$main.order_by_options selected=$main.order_by_selected}
<input type="text" name="order_by_perso" size="40" value="{$main.order_by_perso}"
{if $main.order_by_selected != 'custom'}style="display:none;"{/if}/>
</span>
</li>
<li>
&nbsp;
<span class="property">
{'Default photos order inside album'|@translate}
{html_options name="order_by_inside_category" options=$main.order_by_inside_category_options selected=$main.order_by_inside_category_selected}
<input type="text" name="order_by_inside_category_perso" size="40" value="{$main.order_by_inside_category_perso}"
{if $main.order_by_inside_category_selected != 'custom'}style="display:none;"{/if}>

{foreach from=$main.order_by item=order}
<span class="filter {if $ORDER_BY_IS_CUSTOM}transparent{/if}">
<a class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
<select name="order_by_field[]" {if $ORDER_BY_IS_CUSTOM}disabled{/if}>
{html_options options=$main.order_field_options selected=$order.FIELD }
</select>
<select name="order_by_direction[]" {if $ORDER_BY_IS_CUSTOM}disabled{/if}>
{html_options options=$main.order_direction_options selected=$order.DIRECTION }
</select>
</span>
{/foreach}

{if !$ORDER_BY_IS_CUSTOM}
<a class="addFilter" title="{'Add a filter'|@translate}"><span>[+]</span></a>
{else}
<span class="order_by_is_custom">{'You can\'t define a default photo order because you have a custom setting in your local configuration.'|@translate}</span>
{/if}
</span>
</li>

{if !$ORDER_BY_IS_CUSTOM}
{footer_script require='jquery'}{literal}
jQuery(document).ready(function () {
$('select[name="order_by"]').change(function () {
if ($(this).val() == 'custom') {
$('input[name="order_by_perso"]').show();
} else {
$('input[name="order_by_perso"]').hide();
}
$('.addFilter').click(function() {
rel = $(this).attr('rel');
$(this).prev('span.filter').clone().insertBefore($(this));
$(this).prev('span.filter').children('select[name="order_by_field[]"]').val('');
$(this).prev('span.filter').children('select[name="order_by_direction[]"]').val('ASC');
$(".removeFilter").click(function () {
$(this).parent('span.filter').remove();
});
});
$('select[name="order_by_inside_category"]').change(function () {
if ($(this).val() == 'custom') {
$('input[name="order_by_inside_category_perso"]').show();
} else {
$('input[name="order_by_inside_category_perso"]').hide();
}

$(".removeFilter").click(function () {
$(this).parent('span.filter').remove();
});
});
{/literal}{/footer_script}
{/if}
</ul>
</fieldset>
{/if}
Expand Down
13 changes: 12 additions & 1 deletion admin/themes/default/theme.css
Expand Up @@ -1047,4 +1047,15 @@ div.token-input-dropdown ul li {background-color: #fff;padding: 3px;margin: 0;li
div.token-input-dropdown ul li.token-input-dropdown-item {background-color: #fff;}
div.token-input-dropdown ul li.token-input-dropdown-item2 {background-color: #fff;}
div.token-input-dropdown ul li em {font-weight: bold;font-style: normal;}
div.token-input-dropdown ul li.token-input-selected-dropdown-item {background-color: #3b5998;color: #fff;}
div.token-input-dropdown ul li.token-input-selected-dropdown-item {background-color: #3b5998;color: #fff;}

#mainConfCheck a.addFilter {background: url(icon/plus.gif) no-repeat 0 4px;width:19px;height:19px;display:inline-block;}
#mainConfCheck a.addFilter:hover {background-position:0 5px;border:none;}
#mainConfCheck a.addFilter span {display:none;}
#mainConfCheck a.removeFilter {background: url(icon/remove_filter.png) no-repeat top left;width:7px;height:7px;display:inline-block;}
#mainConfCheck a.removeFilter:hover {background: url(icon/remove_filter_hover.png);border:none;}
#mainConfCheck a.removeFilter span {display:none;}
#mainConfCheck span.property span.filter:first-child a.removeFilter {display:none;} /* can't delete the first field */
#mainConfCheck span.filter {margin-right:10px;}
#mainConfCheck .transparent {opacity:0.5;filter:alpha(opacity=50);}
#mainConfCheck .order_by_is_custom {display:block;font-weight:normal;font-style:italic;}
21 changes: 21 additions & 0 deletions include/common.inc.php
Expand Up @@ -106,6 +106,17 @@ function sanitize_mysql_kv(&$v, $k)
{
@include(PHPWG_ROOT_PATH.PWG_LOCAL_DIR. 'config/config.inc.php');
}

// that's for migration from 2.2, will be deprecated in 2.4
if (isset($conf['order_by']))
{
$conf['order_by_custom'] = $conf['order_by'];
}
if (isset($conf['order_by_inside_category']))
{
$conf['order_by_inside_category_custom'] = $conf['order_by_inside_category'];
}

include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$conf['dblayer'].'.inc.php');

if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
Expand Down Expand Up @@ -143,6 +154,16 @@ function sanitize_mysql_kv(&$v, $k)

load_plugins();

// users can have defined a custom order pattern, incompatible with GUI form
if (isset($conf['order_by_custom']))
{
$conf['order_by'] = $conf['order_by_custom'];
}
if (isset($conf['order_by_inside_category_custom']))
{
$conf['order_by_inside_category'] = $conf['order_by_inside_category_custom'];
}

include(PHPWG_ROOT_PATH.'include/user.inc.php');

if (in_array( substr($user['language'],0,2), array('fr','it','de','es','pl','hu','ru','nl') ) )
Expand Down
28 changes: 4 additions & 24 deletions include/config_default.inc.php
Expand Up @@ -43,35 +43,15 @@
// | misc |
// +-----------------------------------------------------------------------+

// order_by : how to change the order of display for images in a category ?
// order_by_custom and order_by_inside_category_custom : for non common pattern
// you can define special ORDER configuration
//
// There are several fields that can order the display :
//
// - date_available : the date of the adding to the gallery
// - file : the name of the file
// - id : element identifier
// - date_creation : date of element creation
//
// Once you've chosen which field(s) to use for ordering, you must chose the
// ascending or descending order for each field. examples :
//
// 1. $conf['order_by'] = " order by date_available desc, file asc";
// will order pictures by date_available descending & by filename ascending
//
// 2. $conf['order_by'] = " order by file asc";
// will only order pictures by file ascending without taking into account
// the date_available
$conf['order_by'] = ' ORDER BY date_available DESC, file ASC, id ASC';
// $conf['order_by_custom'] = ' ORDER BY date_available DESC, file ASC, id ASC';

// order_by_inside_category : inside a category, images can also be ordered
// by rank. A manually defined rank on each image for the category.
//
// In addition to fields of #images table, you can use the
// #image_category.rank column
//
// $conf['order_by_inside_category'] = ' ORDER BY rank';
// will sort images by the manually defined rank of images in this album.
$conf['order_by_inside_category'] = $conf['order_by'];
// $conf['order_by_inside_category_custom'] = $conf['order_by_custom'];

// file_ext : file extensions (case sensitive) authorized
$conf['file_ext'] = array('jpg','JPG','jpeg','JPEG',
Expand Down
4 changes: 2 additions & 2 deletions install/config.sql
Expand Up @@ -52,8 +52,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 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,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 ('upload_form_websize_resize','true');
INSERT INTO piwigo_config (param,value) VALUES ('upload_form_websize_maxwidth','800');
INSERT INTO piwigo_config (param,value) VALUES ('upload_form_websize_maxheight','600');
Expand Down

0 comments on commit 9c0cfb0

Please sign in to comment.