From aca06a08aa8d2148ba6198811907fbb61a4e8f57 Mon Sep 17 00:00:00 2001 From: rvelices Date: Wed, 26 Jul 2006 00:51:08 +0000 Subject: feature 169: each category can have its own image order git-svn-id: http://piwigo.org/svn/trunk@1500 68402e56-0260-453c-a942-63ccdbb3a9ee --- admin/cat_modify.php | 100 +++++++++++++++++++++++++++++++ include/functions_category.inc.php | 3 +- include/section_init.inc.php | 5 ++ install/db/29-database.php | 46 ++++++++++++++ install/phpwebgallery_structure.sql | 1 + language/en_UK.iso-8859-1/admin.lang.php | 2 + language/fr_FR.iso-8859-1/admin.lang.php | 2 + template/yoga/admin/cat_modify.tpl | 32 ++++++++-- 8 files changed, 185 insertions(+), 6 deletions(-) create mode 100644 install/db/29-database.php diff --git a/admin/cat_modify.php b/admin/cat_modify.php index 3d7ed8cb7..a543d0d77 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -80,6 +80,39 @@ if (isset($_POST['submit'])) ); } + $image_order = ''; + if ( !isset($_POST['image_order_default']) ) + { + for ($i=1; $i<=3; $i++) + { + if ( !empty($_POST['order_field_'.$i]) ) + { + if (! empty($image_order) ) + { + $image_order .= ','; + } + $image_order .= $_POST['order_field_'.$i]; + if ($_POST['order_direction_'.$i]=='DESC') + { + $image_order .= ' DESC'; + } + } + } + } + $image_order = empty($image_order) ? 'null' : "'$image_order'"; + $query = ' +UPDATE '.CATEGORIES_TABLE.' SET image_order='.$image_order.' +WHERE '; + if (isset($_POST['image_order_subcats'])) + { + $query .= 'uppercats REGEXP \'(^|,)'.$_GET['cat_id'].'(,|$)\''; + } + else + { + $query .= 'id='.$_GET['cat_id'].';'; + } + pwg_query($query); + array_push($page['infos'], $lang['editcat_confirm']); } else if (isset($_POST['set_random_representant'])) @@ -226,6 +259,9 @@ $template->assign_vars( $commentable => 'checked="checked"', $uploadable => 'checked="checked"', + 'IMG_ORDER_DEFAULT' => empty($category['image_order']) ? + 'checked="checked"' : '', + 'L_EDIT_NAME' => $lang['name'], 'L_STORAGE' => $lang['storage'], 'L_REMOTE_SITE' => $lang['remote_site'], @@ -277,6 +313,70 @@ if ($category['nb_images'] > 0) ); } +// image order management +$matches = array(); +if ( !empty( $category['image_order'] ) ) +{ + preg_match_all('/([a-z_]+) *(?:(asc|desc)(?:ending)?)? *(?:, *|$)/i', + $category['image_order'], $matches); +} + +$sort_fields = array( + '' => '', + 'date_creation' => l10n('Creation date'), + 'date_available' => l10n('Post date'), + 'average_rate' => l10n('Average rate'), + 'hit' => l10n('most_visited_cat'), + 'file' => l10n('File name'), + 'id' => 'Id', + ); + +for ($i=0; $i<3; $i++) // 3 fields +{ + $template->assign_block_vars('image_order', array('NUMBER'=>$i+1) ); + foreach ($sort_fields as $sort_field => $name) + { + $selected=''; + if ( isset($matches[1][$i]) and $matches[1][$i]==$sort_field ) + { + $selected='selected="selected"'; + } + elseif ( empty($sort_field) ) + { + $selected='selected="selected"'; + } + + $template->assign_block_vars('image_order.field', + array( + 'SELECTED' => $selected, + 'VALUE' => $sort_field, + 'OPTION' => $name + ) + ); + } + + $template->assign_block_vars('image_order.order', + array( + 'SELECTED' => + ( empty($matches[2][$i]) or strcasecmp($matches[2][$i],'ASC')==0 ) + ? 'selected="selected"' : '', + 'VALUE' => 'ASC', + 'OPTION' => 'Ascending' + ) + ); + + $template->assign_block_vars('image_order.order', + array( + 'SELECTED' => + ( isset($matches[2][$i]) and strcasecmp($matches[2][$i],'DESC')==0 ) + ? 'selected="selected"' : '', + 'VALUE' => 'DESC', + 'OPTION' => 'Descending' + ) + ); +} + + // representant management if ($category['nb_images'] > 0 or !empty($category['representative_picture_id'])) diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 2aff86975..939a72e77 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -110,7 +110,8 @@ function get_cat_info( $id ) { $infos = array('nb_images','id_uppercat','comment','site_id' ,'dir','date_last','uploadable','status','visible' - ,'representative_picture_id','uppercats','commentable'); + ,'representative_picture_id','uppercats','commentable' + ,'image_order'); $query = ' SELECT '.implode(',', $infos).' diff --git a/include/section_init.inc.php b/include/section_init.inc.php index b2bb4c90e..1aa58516c 100644 --- a/include/section_init.inc.php +++ b/include/section_init.inc.php @@ -342,6 +342,11 @@ if ('categories' == $page['section']) if (!isset($page['chronology_field'])) { + if ( !empty($result['image_order']) and !isset($page['super_order_by']) ) + { + $conf[ 'order_by' ] = ' ORDER BY '.$result['image_order']; + } + $query = ' SELECT image_id FROM '.IMAGE_CATEGORY_TABLE.' diff --git a/install/db/29-database.php b/install/db/29-database.php new file mode 100644 index 000000000..efa95d2d1 --- /dev/null +++ b/install/db/29-database.php @@ -0,0 +1,46 @@ + diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql index b9434ff09..cf7c55b39 100644 --- a/install/phpwebgallery_structure.sql +++ b/install/phpwebgallery_structure.sql @@ -37,6 +37,7 @@ CREATE TABLE `phpwebgallery_categories` ( `uppercats` varchar(255) NOT NULL default '', `commentable` enum('true','false') NOT NULL default 'true', `global_rank` varchar(255) default NULL, + `image_order` varchar(128) default NULL, PRIMARY KEY (`id`), KEY `categories_i2` (`id_uppercat`) ) TYPE=MyISAM; diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index ce2a743c0..8d0b21173 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -45,6 +45,7 @@ $lang['Add a user'] = 'Add a user'; $lang['Add group'] = 'Add group'; $lang['Add selected elements to caddie'] = 'Add selected elements to caddie'; $lang['Add'] = 'Add'; +$lang['Apply to subcategories'] = 'Apply to subcategories'; $lang['Are you sure?'] = 'Are you sure?'; $lang['Associated'] = 'Associated'; $lang['Association to categories'] = 'Association to categories'; @@ -165,6 +166,7 @@ $lang['Tag selection'] = 'Tag selection'; $lang['Take selected elements out of caddie'] = 'Take selected elements out of caddie'; $lang['The %d following tags were deleted : %s'] = 'The %d following tags were deleted : %s'; $lang['Unable to check for upgrade since allow_url_fopen is disabled.'] = 'Unable to check for upgrade since allow_url_fopen is disabled.'; +$lang['Use default sort order']='Use the default image sort order (defined in the configuration file)'; $lang['User comments validation'] = 'User comments validation'; $lang['Users'] = 'Users'; $lang['Validate All'] = 'Validate All'; diff --git a/language/fr_FR.iso-8859-1/admin.lang.php b/language/fr_FR.iso-8859-1/admin.lang.php index 1e0516bca..961159348 100644 --- a/language/fr_FR.iso-8859-1/admin.lang.php +++ b/language/fr_FR.iso-8859-1/admin.lang.php @@ -45,6 +45,7 @@ $lang['Add a user'] = 'Ajouter un utilisateur'; $lang['Add group'] = 'Ajouter un groupe'; $lang['Add selected elements to caddie'] = 'Ajouter les éléments sélectionnés au panier'; $lang['Add'] = 'Ajouter'; +$lang['Apply to subcategories'] = 'Appliquer au sous-catégories'; $lang['Are you sure?'] = 'Etes-vous sur?'; $lang['Associated'] = 'Associée à'; $lang['Association to categories'] = 'Association aux catégories'; @@ -165,6 +166,7 @@ $lang['Tag selection'] = 'S $lang['Take selected elements out of caddie'] = 'Sortir les éléments sélectionnés du panier'; $lang['The %d following tags were deleted : %s'] = 'Les %d tags suivants ont été supprimés : %s'; $lang['Unable to check for upgrade since allow_url_fopen is disabled.'] = 'Impossible de connaître la dernière version cat la fonction allow_url_fopen est désactivée.'; +$lang['Use default sort order']='Utiliser l\'ordre de tri des images par défaut (défini dans le fichier de configuration)'; $lang['User comments validation'] = 'Validation des commentaires utilisateur'; $lang['Users'] = 'Utilisateurs'; $lang['Validate All'] = 'Tout valider'; diff --git a/template/yoga/admin/cat_modify.tpl b/template/yoga/admin/cat_modify.tpl index 62e97077f..ef7b64b78 100644 --- a/template/yoga/admin/cat_modify.tpl +++ b/template/yoga/admin/cat_modify.tpl @@ -62,7 +62,7 @@ - + @@ -102,6 +102,28 @@ +
+ {lang:Sort order} + + +
+ + +
+ + +
+ +
+

@@ -122,7 +144,7 @@ - +

@@ -138,7 +160,7 @@