Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feature 280: Allow visitors/users to choose image ordering inside a c…
…ategory

improvement 82: Viewing pictures from remote galleries does not check anymore 
for the high pictures (existence flag added to create_listing_file and db)

correction: link element in picture is in the head instead of body (w3c spec)

correction: in profile.php the current template was not selected by default

git-svn-id: http://piwigo.org/svn/trunk@1020 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
rvelices committed Feb 1, 2006
1 parent ac5fd23 commit bb181b0
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 45 deletions.
3 changes: 2 additions & 1 deletion admin/remote_site.php
Expand Up @@ -409,6 +409,7 @@ function insert_remote_element($xml_dir, $category_id)
'keywords',
'name',
'comment',
'has_high',
'path');
foreach ($optional_atts as $att)
{
Expand All @@ -425,7 +426,7 @@ function insert_remote_element($xml_dir, $category_id)
{
$dbfields = array('file','storage_category_id','date_available','tn_ext',
'filesize','width','height','date_creation','author',
'keywords','name','comment','path');
'keywords','name','comment','has_high','path');
mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
$counts{'new_elements'}+= count($inserts);

Expand Down
32 changes: 32 additions & 0 deletions category.php
Expand Up @@ -406,6 +406,38 @@
array('COMMENTS' => $page['comment'])
);
}
if ($page['cat_nb_images']>0 and
$page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
{
// image order
$template->assign_block_vars( 'preferred_image_order', array() );

if ( isset($_GET['image_order']) )
{
$order_idx = $_GET['image_order'];
}
else
{
$order_idx = isset($_COOKIE['pwg_image_order']) ?
$_COOKIE['pwg_image_order'] : 0;
}

$orders = get_category_preferred_image_orders();
for ( $i = 0; $i < count($orders); $i++)
{
if ($orders[$i][2])
{
$url = PHPWG_ROOT_PATH.'category.php'
.get_query_string_diff(array('image_order'));
$url .= '&amp;image_order='.$i;
$template->assign_block_vars( 'preferred_image_order.order', array(
'DISPLAY' => $orders[$i][0],
'URL' => $url,
'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : '' ),
) );
}
}
}
}
//------------------------------------------------------------ log informations
pwg_log( 'category', $page['title'] );
Expand Down
9 changes: 9 additions & 0 deletions include/functions.inc.php
Expand Up @@ -533,6 +533,15 @@ function get_query_string_diff($rejects = array())
return $query_string;
}

function url_is_remote($url)
{
if (preg_match('/^https?:\/\/[~\/\.\w-]+$/', $url))
{
return true;
}
return false;
}

/**
* returns available templates/themes
*/
Expand Down
37 changes: 37 additions & 0 deletions include/functions_category.inc.php
Expand Up @@ -318,6 +318,20 @@ function get_site_url($category_id)
return $row['galleries_url'];
}

// returns an array of image orders available for users/visitors
function get_category_preferred_image_orders()
{
global $lang, $conf;
return array(
array('Default', '', true),
array($lang['best_rated_cat'], 'average_rate DESC', $conf['rate']),
array($lang['most_visited_cat'], 'hit DESC', true),
array($lang['Creation date'], 'date_creation DESC', true),
array($lang['Availability date'], 'date_available DESC', true)
);
}


// initialize_category initializes ;-) the variables in relation
// with category :
// 1. calculation of the number of pictures in the category
Expand Down Expand Up @@ -603,6 +617,29 @@ function initialize_category( $calling_page = 'category' )
create_navigation_bar( $url, $page['cat_nb_images'], $page['start'],
$user['nb_image_page'], 'back' );
}

if ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated')
{
$available_image_orders = get_category_preferred_image_orders();

$order_idx=0;
if ( isset($_GET['image_order']) )
{
$order_idx = $_GET['image_order'];
setcookie( 'pwg_image_order', $order_idx, 0 );
}
else if ( isset($_COOKIE['pwg_image_order']) )
{
$order_idx = $_COOKIE['pwg_image_order'];
}

if ( $order_idx > 0 )
{
$order = $available_image_orders[$order_idx][1];
$conf['order_by'] = str_replace('ORDER BY ', 'ORDER BY '.$order.',',
$conf['order_by'] );
}
}
}
else
{
Expand Down
50 changes: 50 additions & 0 deletions install/db/5-database.php
@@ -0,0 +1,50 @@
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery |
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | last update : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
// | last modifier : $Author: plg $
// | revision : $Revision: 870 $
// +-----------------------------------------------------------------------+
// | 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 = 'Update images table with has_high column';

// +-----------------------------------------------------------------------+
// | Upgrade content |
// +-----------------------------------------------------------------------+

// column user_id becomes data of type text
$query = "
ALTER TABLE ".PREFIX_TABLE."images ADD COLUMN has_high ENUM('true') DEFAULT NULL AFTER average_rate;
";
pwg_query($query);

echo
"\n"
.'Column has_high '.PREFIX_TABLE.'images added'
."\n"
;
?>
7 changes: 4 additions & 3 deletions install/phpwebgallery_structure.sql
@@ -1,8 +1,8 @@
-- MySQL dump 9.11
-- MySQL dump 10.9
--
-- Host: localhost Database: pwg-bsf
-- Host: localhost Database: pwg_dev_bsf
-- ------------------------------------------------------
-- Server version 4.0.24_Debian-10-log
-- Server version 4.1.15-nt

--
-- Table structure for table `phpwebgallery_caddie`
Expand Down Expand Up @@ -155,6 +155,7 @@ CREATE TABLE `phpwebgallery_images` (
`representative_ext` varchar(4) default NULL,
`date_metadata_update` date default NULL,
`average_rate` float(5,2) unsigned default NULL,
`has_high` enum('true') default NULL,
`path` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`),
KEY `images_i2` (`date_available`),
Expand Down
4 changes: 3 additions & 1 deletion language/en_UK.iso-8859-1/common.lang.php
Expand Up @@ -43,6 +43,7 @@
$lang['About'] = 'About';
$lang['At least one listed rule must be satisfied.'] = 'At least one listed rule must be satisfied.';
$lang['Author'] = 'Author';
$lang['Availability date'] = 'Availability date';
$lang['Average rate'] = 'Average rate';
$lang['Categories'] = 'Categories';
$lang['Category'] = 'Category';
Expand All @@ -53,6 +54,7 @@
$lang['Contact webmaster'] = 'Contact webmaster';
$lang['Create a new account'] = 'Create a new account';
$lang['Created on'] = 'Created on';
$lang['Creation date'] = 'Creation date';
$lang['Current password is wrong'] = 'Current password is wrong';
$lang['Dimensions'] = 'Dimensions';
$lang['Display'] = 'Display';
Expand Down Expand Up @@ -121,7 +123,7 @@
$lang['became available before %s (%s)'] = 'became available before %s (%s)';
$lang['became available between %s (%s) and %s (%s)'] = 'became available between %s (%s) and %s (%s)';
$lang['became available on %s'] = 'became available on %s';
$lang['best_rated_cat'] = 'best rated';
$lang['best_rated_cat'] = 'Best rated';
$lang['best_rated_cat_hint'] = 'displays best rated items';
$lang['caddie'] = 'caddie';
$lang['calendar'] = 'Calendar';
Expand Down
2 changes: 2 additions & 0 deletions language/fr_FR.iso-8859-1/common.lang.php
Expand Up @@ -42,6 +42,7 @@
$lang['About'] = 'À propos';
$lang['At least one listed rule must be satisfied.'] = 'Au moins un des critères doit être satisfait.';
$lang['Author'] = 'Auteur';
$lang['Availability date'] = 'Date de disponibilité';
$lang['Average rate'] = 'Note moyenne';
$lang['Categories'] = 'Catégories';
$lang['Category'] = 'Catégorie';
Expand All @@ -52,6 +53,7 @@
$lang['Contact webmaster'] = 'Contacter le webmestre';
$lang['Create a new account'] = 'Créer un nouveau compte';
$lang['Created on'] = 'Créée le';
$lang['Creation date'] = 'Date de création';
$lang['Current password is wrong'] = 'Erreur sur le mot de passe actuel';
$lang['Dimensions'] = 'Dimensions';
$lang['Display'] = 'Affichage';
Expand Down
73 changes: 39 additions & 34 deletions picture.php
Expand Up @@ -247,12 +247,22 @@
$picture[$i]['src'] = $row['path'];
// if we are working on the "current" element, we search if there is a
// high quality picture
// FIXME : with remote pictures, this "remote fopen" takes long...
if ($i == 'current')
{
if (@fopen($cat_directory.'/pwg_high/'.$row['file'], 'r'))
$url_high=$cat_directory.'/pwg_high/'.$row['file'];
if (url_is_remote($cat_directory))
{
$picture[$i]['high'] = $cat_directory.'/pwg_high/'.$row['file'];
if ($row['has_high'])
{
$picture[$i]['high'] = $url_high;
}
}
else
{
if (@fopen($url_high, 'r'))
{
$picture[$i]['high'] = $url_high;
}
}
}
}
Expand Down Expand Up @@ -526,6 +536,31 @@
}

$page['body_id'] = 'thePicturePage';
//-------------------------------------------------------- navigation management
if ($has_prev)
{
$template->assign_block_vars(
'previous',
array(
'TITLE_IMG' => $picture['prev']['name'],
'IMG' => $picture['prev']['thumbnail'],
'U_IMG' => $picture['prev']['url'],
'U_IMG_SRC' => $picture['prev']['src']
));
}

if ($has_next)
{
$template->assign_block_vars(
'next',
array(
'TITLE_IMG' => $picture['next']['name'],
'IMG' => $picture['next']['thumbnail'],
'U_IMG' => $picture['next']['url'],
'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
));
}

include(PHPWG_ROOT_PATH.'include/page_header.php');
$template->set_filenames(array('picture'=>'picture.tpl'));

Expand Down Expand Up @@ -585,15 +620,10 @@
// display a high quality link if present
if (isset($picture['current']['high']))
{
$full_size = @getimagesize($picture['current']['high']);
$full_width = $full_size[0];
$full_height = $full_size[1];
$uuid = uniqid(rand());
$template->assign_block_vars('high', array(
'U_HIGH' => $picture['current']['high'],
'UUID'=>$uuid,
'WIDTH_IMG'=>($full_width + 40),
'HEIGHT_IMG'=>($full_height + 40)
'UUID'=>$uuid
));
$template->assign_block_vars(
'download',
Expand Down Expand Up @@ -673,31 +703,6 @@
$template->assign_block_vars('admin', array());
}

//-------------------------------------------------------- navigation management
if ($has_prev)
{
$template->assign_block_vars(
'previous',
array(
'TITLE_IMG' => $picture['prev']['name'],
'IMG' => $picture['prev']['thumbnail'],
'U_IMG' => $picture['prev']['url'],
'U_IMG_SRC' => $picture['prev']['src']
));
}

if ($has_next)
{
$template->assign_block_vars(
'next',
array(
'TITLE_IMG' => $picture['next']['name'],
'IMG' => $picture['next']['thumbnail'],
'U_IMG' => $picture['next']['url'],
'U_IMG_SRC' => $picture['next']['src'] // allow navigator to preload
));
}

//--------------------------------------------------------- picture information
// legend
if (isset($picture['current']['comment'])
Expand Down
2 changes: 1 addition & 1 deletion profile.php
Expand Up @@ -211,7 +211,7 @@
{
$selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
}
else if ($userdata['template'] == $pwg_template)
else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
{
$selected = 'selected="selected"';
}
Expand Down
10 changes: 10 additions & 0 deletions template/yoga/category.tpl
Expand Up @@ -120,6 +120,16 @@
<li><a href="{search_rules.URL}" style="border:none;" onclick="popuphelp(this.href); return false;" title="{lang:Search rules}"><img src="{themeconf:icon_dir}/search_rules.png" class="button" alt="(?)"></a></li>
<!-- END search_rules -->

<!-- BEGIN preferred_image_order -->
<li>
{lang:Sort order}:
<select onchange="document.location = this.options[this.selectedIndex].value;">
<!-- BEGIN order -->
<option value="{preferred_image_order.order.URL}" {preferred_image_order.order.SELECTED_OPTION}>{preferred_image_order.order.DISPLAY}</option>
<!-- END order -->
</select>
</li>
<!-- END preferred_image_order -->
</ul>

<h2>{TITLE}</h2>
Expand Down
2 changes: 2 additions & 0 deletions template/yoga/content.css
Expand Up @@ -119,10 +119,12 @@ UL.categoryActions {

#content UL.categoryActions LI {
display: inline;

}

#content UL.categoryActions A IMG, UL.categoryActions A {
border: none;
margin-bottom: -5px;
}

/* User comments */
Expand Down
3 changes: 3 additions & 0 deletions template/yoga/header.tpl
Expand Up @@ -11,6 +11,9 @@ the "text/nonsense" prevents gecko based browsers to load it -->
<link rel="stylesheet" type="text/css" media="print" href="template/{themeconf:template}/print.css">
<link rel="stylesheet" type="text/css" href="template/{themeconf:template}/default-colors.css">
<link rel="stylesheet" type="text/css" href="template/{themeconf:template}/theme/{themeconf:theme}/theme.css">
<!-- BEGIN next -->
<link rel="prefetch" href="{next.U_IMG_SRC}">
<!-- END next -->
<!-- BEGIN refresh -->
<meta http-equiv="refresh" content="{REFRESH_TIME};url={U_REFRESH}">
<!-- END refresh -->
Expand Down

0 comments on commit bb181b0

Please sign in to comment.