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
first try, may has issues with very specials params

git-svn-id: http://piwigo.org/svn/trunk@11279 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
mistic100 committed Jun 9, 2011
1 parent 193d1e4 commit f56fc4f
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 11 deletions.
94 changes: 94 additions & 0 deletions admin/configuration.php
Expand Up @@ -100,6 +100,12 @@
'average_rate',
'privacy_level',
);

$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',
'custom' => l10n('Custom'),
);

//------------------------------ verification and registration of modifications
if (isset($_POST['submit']))
Expand All @@ -110,6 +116,56 @@
{
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,}$#';
// process 'order_by_perso' string
if ($_POST['order_by'] == 'custom' AND !empty($_POST['order_by_perso']))
{
$_POST['order_by'] = str_ireplace(
array('order by ', 'asc', 'desc'),
array(null, 'ASC', 'DESC'),
trim($_POST['order_by_perso'])
);

if (preg_match($order_regex, $_POST['order_by'].','))
{
$_POST['order_by'] = ' ORDER BY '.$_POST['order_by'];
}
else
{
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'] = str_ireplace(
array('order by ', 'asc', 'desc'),
array(null, 'ASC', 'DESC'),
trim($_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'];
}
else
{
array_push($page['errors'], l10n('Invalid order string').' « '.$_POST['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'])
{
$tpl_var = & $template->get_template_vars('header_msgs');
Expand Down Expand Up @@ -234,6 +290,34 @@
{
case 'main' :
{
// process 'order_by' string
if (array_key_exists($conf['order_by'], $order_options))
{
$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']);
}
// process 'order_by_inside_category' string
if ($conf['order_by_inside_category'] == $conf['order_by'])
{
$order_by_inside_category_selected = 'as_order_by';
$order_by_inside_category_perso = null;
}
else if (array_key_exists($conf['order_by_inside_category'], $order_options))
{
$order_by_inside_category_selected = $conf['order_by_inside_category'];
$order_by_inside_category_perso = null;
}
else
{
$order_by_inside_category_selected = 'custom';
$order_by_inside_category_perso = str_replace(' ORDER BY ', null, $conf['order_by_inside_category']);
}

$template->assign(
'main',
array(
Expand All @@ -245,6 +329,16 @@
'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,
));

foreach ($main_checkboxes as $checkbox)
Expand Down
49 changes: 43 additions & 6 deletions admin/themes/default/template/configuration.tpl
Expand Up @@ -89,13 +89,50 @@
</li>

<li>
<label>
<span class="property">
{'Week starts on'|@translate}
{html_options name="week_starts_on" options=$main.week_starts_on_options selected=$main.week_starts_on_options_selected}
</span>
</label>
&nbsp;
<span class="property">
{'Week starts on'|@translate}
{html_options name="week_starts_on" options=$main.week_starts_on_options selected=$main.week_starts_on_options_selected}
</span>
</li>

<li>
&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}>
</span>
</li>

{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();
}
});
$('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();
}
});
});
{/literal}{/footer_script}
</ul>
</fieldset>
{/if}
Expand Down
2 changes: 2 additions & 0 deletions install/config.sql
Expand Up @@ -51,6 +51,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) 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
48 changes: 48 additions & 0 deletions install/db/106-database.php
@@ -0,0 +1,48 @@
<?php
// +-----------------------------------------------------------------------+
// | Piwigo - a PHP based photo gallery |
// +-----------------------------------------------------------------------+
// | Copyright(C) 2008-2011 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. |
// +-----------------------------------------------------------------------+

if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}

$upgrade_description = 'add order parameters to bdd';

$query = '
INSERT INTO '.PREFIX_TABLE.'config(param,value,comment)
VALUES (\'order_by\', \''.$conf['order_by'].'\', \'default photos order\')
;';
pwg_query($query);

$query = '
INSERT INTO '.PREFIX_TABLE.'config(param,value,comment)
VALUES (\'order_by_inside_category\', \''.$conf['order_by_inside_category'].'\', \'default photos order inside category\')
;';
pwg_query($query);

echo
"\n"
. $upgrade_description
."\n"
;
?>
5 changes: 5 additions & 0 deletions language/en_UK/admin.lang.php
Expand Up @@ -150,6 +150,7 @@
$lang['Are you sure to install this upgrade? You must verify if this version does not need uninstallation.'] = "Are you sure you want to install this upgrade? You must verify if this version does not need prior uninstallation.";
$lang['Are you sure you want to delete this plugin?'] = "Are you sure you want to delete this plugin?";
$lang['Are you sure you want to install this plugin?'] = "Are you sure you want to install this plugin?";
$lang['As default order'] = "As default order";
$lang['Associate to album'] = "Associate to album";
$lang['associate to group'] = "associate to group";
$lang['Associated'] = "Associated";
Expand Down Expand Up @@ -202,13 +203,16 @@
$lang['Create this site'] = "Create this site";
$lang['created'] = "created";
$lang['Current name'] = "Current name";
$lang['Custom'] = "Custom";
$lang['Database synchronization with files'] = "Database synchronization with files";
$lang['Database'] = "Database";
$lang['Date'] = "Date";
$lang['Day'] = "Day";
$lang['Deactivate'] = "Deactivate";
$lang['Deactivate all'] = "Deactivate all";
$lang['Default display'] = "Default display";
$lang['Default photos order'] = "Default photos order";
$lang['Default photos order inside album'] = "Default photos order inside album";
$lang['Default user cannot be deleted'] = "Default user cannot be deleted";
$lang['Default user does not exist'] = "The default user does not exist";
$lang['default values'] = "default values";
Expand Down Expand Up @@ -358,6 +362,7 @@
$lang['Installed Languages'] = 'Installed Languages';
$lang['Installed Themes'] = "Installed Themes";
$lang['Instructions to use Piwigo'] = "Instructions to use Piwigo";
$lang['Invalid order string'] = 'Invalid order string';
$lang['Invert'] = 'Invert';
$lang['IP'] = "IP";
$lang['JPEG files or ZIP archives with JPEG files inside please.'] = 'JPEG files or ZIP archives with JPEG files inside please.';
Expand Down
14 changes: 14 additions & 0 deletions language/en_UK/help/configuration.html
Expand Up @@ -33,6 +33,20 @@ <h3>Main</h3>
<li><strong>Mail address is mandatory for all users</strong>: mail address will be checked on registration or profile update, except if the action is done by an administrator.</li>

<li><strong>Email admins when a new user registers</strong>: administrators will be notified by mail for each registration.</li>

<li><strong>Default photos order</strong>: You can define a personalized order by selecting &laquo;Personalized&raquo; in the drop-down menu. This field must respect the SQL syntax, example: <i>date_available DESC, file ASC, id ASC</i><br>
Available fields:
<ul style="font-size:0.85em;">
<li><b>date_available</b>: date of the adding to the gallery</li>
<li><b>file</b>: name of the file</li>
<li><b>id</b>: identifier</li>
<li><b>date_creation</b>: date of element creation</li>
<li><b>name</b>: name of the picture</li>
<li><b>hit</b>: number of visits</li>
<li><b>average_rate</b>: average rate on the picture</li>
</ul>
Don't forgot to specify the order for each field with these keywords : <i>ASC</i> and <i>DESC</i>
</li>

</ul>

Expand Down
15 changes: 10 additions & 5 deletions language/fr_FR/admin.lang.php
Expand Up @@ -842,9 +842,14 @@
$lang['Follow Orientation'] = "Respecter l'orientation";
$lang['If you want to regenerate thumbnails, please go to the <a href="%s">Batch Manager</a>.'] = 'Si vous voulez régénérer des miniatures, merci de vous rendre dans la <a href="%s">Gestion par lot</a>.';
$lang['Graphics Library'] = 'Bibliothèque graphique';
$lang['Show menubar'] = "Afficher le menu";
$lang['No results'] = "Pas de résultat";
$lang['Type in a search term'] = "Entrez un terme de recherche";
$lang['Searching...'] = "Recherche...";
$lang['new'] = "nouveau";
$lang['Show menubar'] = 'Afficher le menu';
$lang['No results'] = 'Pas de résultat';
$lang['Type in a search term'] = 'Entrez un terme de recherche';
$lang['Searching...'] = 'Recherche...';
$lang['new'] = 'nouveau';
$lang['Default photos order'] = "Ordre par défaut des photos";
$lang['Default photos order inside album'] = "Ordre par défaut des photos dans un album";
$lang['Invalid order string'] = 'Chaîne SQL incorrecte';
$lang['As default order'] = "Comme l'ordre par défaut";
$lang['Custom'] = "Personnalisé";
?>
14 changes: 14 additions & 0 deletions language/fr_FR/help/configuration.html
Expand Up @@ -33,6 +33,20 @@ <h3>Principale</h3>
<li><strong>L'adresse mail est obligatoire pour tous les utilisateurs</strong>: L'adresse mail sera vérifié lors des inscriptions ou de la mise à jour des profils sauf si l'action est effectuée dans la partie administration.</li>

<li><strong>Notifier les administrateurs lors de l'inscription d'un utilisateur</strong>: Les administrateurs recevront un courriel à chaque inscription.</li>

<li><strong>Ordre par défaut des photos</strong>: Vous pouvez définir un ordre personnalisé et selectionant &laquo;Personnalisé&raquo; dans la liste déroulante. Ce champ doit respecter la syntaxe SQL, exemple: <i>date_available DESC, file ASC, id ASC</i><br>
Liste des champs utilisables :
<ul style="font-size:0.85em;">
<li><b>date_available</b>: date d'ajout à la galerie</li>
<li><b>file</b>: nom du fichier</li>
<li><b>id</b>: identifiant</li>
<li><b>date_creation</b>: date de création</li>
<li><b>name</b>: nom de l'image</li>
<li><b>hit</b>: nombre de visites</li>
<li><b>average_rate</b>: note globale</li>
</ul>
N'oubliez pas pour chaque champ de spécifier l'ordre avec les mots clefs <i>ASC</i> et <i>DESC</i>
</li>

</ul>

Expand Down

0 comments on commit f56fc4f

Please sign in to comment.