aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-05-25 08:31:39 +0000
committerz0rglub <z0rglub@piwigo.org>2003-05-25 08:31:39 +0000
commit1de10bd66f761f8b66dcaecd28f5c2547b754ff3 (patch)
tree4588721b837ce115214e1f6a1525408fc3e46aa7
parent887c7ee4d443259498795d4760cc8d38d359ed38 (diff)
search improved
git-svn-id: http://piwigo.org/svn/trunk@17 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--admin/configuration.php8
-rw-r--r--admin/miseajour.php531
-rw-r--r--category.php69
-rw-r--r--include/config.inc.php3
-rw-r--r--include/functions.inc.php31
-rw-r--r--include/functions_category.inc.php76
-rw-r--r--language/francais.php6
-rw-r--r--picture.php12
-rw-r--r--profile.php4
-rw-r--r--search.php59
-rw-r--r--template/default/search.vtp5
11 files changed, 176 insertions, 628 deletions
diff --git a/admin/configuration.php b/admin/configuration.php
index 75be943db..300466bb8 100644
--- a/admin/configuration.php
+++ b/admin/configuration.php
@@ -242,7 +242,7 @@ if ( $_GET['valider'] == 1 )
$query.= "'".$_POST[$default_user_infos[$i]]."'";
}
}
- $query.= " where pseudo = 'visiteur';";
+ $query.= " where username = 'guest';";
mysql_query( $query );
}
//--------------------------------------------------------- data initialization
@@ -795,18 +795,18 @@ $vtp->closeSession( $sub, 'line' );
// maxwidth for thumbnail
$vtp->addSession( $sub, 'line' );
$vtp->addSession( $sub, 'param_line' );
-$vtp->setVar( $sub, 'param_line.name', $lang['conf_upload_maxwidth_thumbnail'] );
+$vtp->setVar( $sub, 'param_line.name',$lang['conf_upload_maxwidth_thumbnail']);
$vtp->addSession( $sub, 'text' );
$vtp->setVar( $sub, 'text.name', 'upload_maxwidth_thumbnail' );
$vtp->setVar( $sub, 'text.value', $upload_maxwidth_thumbnail );
$vtp->closeSession( $sub, 'text' );
-$vtp->setVar( $sub, 'param_line.def', $lang['conf_upload_maxwidth_thumbnail_info'] );
+$vtp->setVar($sub,'param_line.def',$lang['conf_upload_maxwidth_thumbnail_info']);
$vtp->closeSession( $sub, 'param_line' );
$vtp->closeSession( $sub, 'line' );
// maxheight for thumbnail
$vtp->addSession( $sub, 'line' );
$vtp->addSession( $sub, 'param_line' );
-$vtp->setVar( $sub, 'param_line.name', $lang['conf_upload_maxheight_thumbnail'] );
+$vtp->setVar( $sub,'param_line.name',$lang['conf_upload_maxheight_thumbnail']);
$vtp->addSession( $sub, 'text' );
$vtp->setVar( $sub, 'text.name', 'upload_maxheight_thumbnail' );
$vtp->setVar( $sub, 'text.value', $upload_maxheight_thumbnail );
diff --git a/admin/miseajour.php b/admin/miseajour.php
deleted file mode 100644
index 53ce3371d..000000000
--- a/admin/miseajour.php
+++ /dev/null
@@ -1,531 +0,0 @@
-<?
-/***************************************************************************
- * miseajour.php is a part of PhpWebGallery *
- * ------------------- *
- * last update : Tuesday, July 16, 2002 *
- * email : pierrick@z0rglub.com *
- * *
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * 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; *
- * *
- ***************************************************************************/
- include_once( "./include/isadmin.inc.php" );
-
- function insert_local_category( $cat_id )
- {
- global $prefixeTable,$conf,$page,$HTTP_GET_VARS;
-
- $site_id = 1;
-
- // 0. retrieving informations on the category to display
- $cat_directory = "../galleries";
-
- if ( is_numeric( $cat_id ) )
- {
- $result = get_cat_info( $cat_id );
- $cat_directory.= "/".$result['local_dir'];
- // 1. display the category name to update
- echo "
- <img src=\"".$conf['lien_puce']."\" alt=\"&gt;\" /><span style=\"font-weight:bold;\">".$result['name'][0]."</span> [ dir : ".$result['last_dir']." ]
- <div class=\"retrait\">";
-
- // 2. we search pictures of the category only if the update is for all or a cat_id is specified
- if ( isset( $page['cat'] ) || $HTTP_GET_VARS['update'] == 'all' )
- {
- insert_local_image( $cat_directory, $cat_id );
- update_cat_info( $cat_id );
- }
- }
-
- // 3. we have to remove the categories of the database not present anymore
- $query = "select id from $prefixeTable"."categories";
- $query.= " where site_id = $site_id";
- if ( !is_numeric( $cat_id ) )
- {
- $query.= " and id_uppercat is NULL;";
- }
- else
- {
- $query.= " and id_uppercat = $cat_id;";
- }
- $result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
- {
- // retrieving the directory
- $rep = "../galleries";
- $resultat = get_cat_info( $row['id'] );
- $rep.= "/".$resultat['local_dir'];
-
- // is the directory present ?
- if ( !is_dir( $rep ) )
- {
- delete_category( $row['id'] );
- }
- }
-
- // 4. retrieving the sub-directories
- $sub_rep = array();
- $i = 0;
- $dirs = "";
- if ( $opendir = opendir ( $cat_directory ) )
- {
- while ( $file = readdir ( $opendir ) )
- {
- if ( $file != "." && $file != ".." && is_dir ( $cat_directory."/".$file ) && $file != "thumbnail" )
- {
- $sub_rep[$i++] = $file;
- }
- }
- }
-
- for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
- {
- // 5. is the category already existing ? we create a subcat if not existing
- $category_id = "";
- $query = "select id from $prefixeTable"."categories";
- $query.= " where site_id = $site_id";
- $query.= " and dir = '".$sub_rep[$i]."'";
- if ( !is_numeric( $cat_id ) )
- {
- $query.= " and id_uppercat is NULL;";
- }
- else
- {
- $query.= " and id_uppercat = $cat_id;";
- }
- $result = mysql_query( $query );
- if ( mysql_num_rows( $result ) == 0 )
- {
- // we have to create the category
- $query = "insert into $prefixeTable"."categories (dir,site_id,id_uppercat) values ('".$sub_rep[$i]."','$site_id'";
- if ( !is_numeric( $cat_id ) )
- {
- $query.= ",NULL";
- }
- else
- {
- $query.= ",'$cat_id'";
- }
- $query.= ");";
- mysql_query( $query );
- $category_id = mysql_insert_id();
- }
- else
- {
- // we get the already registered id
- $row = mysql_fetch_array( $result );
- $category_id = $row['id'];
- }
- // 6. recursive call
- insert_local_category( $category_id );
- }
-
- if ( is_numeric( $cat_id ) )
- {
- echo "
- </div>";
- }
- }
-
- function insert_local_image( $rep, $category_id )
- {
- global $prefixeTable,$lang,$conf,$count_new;
-
- // we have to delete all the images from the database that :
- // - are not in the directory anymore
- // - don't have the associated thumbnail available anymore
- $query = "select id,file,tn_ext from $prefixeTable"."images";
- $query.= " where cat_id = $category_id;";
- $result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
- {
- $lien_image = $rep."/".$row['file'];
- $lien_thumbnail = $rep."/"."thumbnail/".$conf['prefixe_thumbnail'].substr( $row['file'], 0, strrpos( $row['file'], "." ) ).".".$row['tn_ext'];
-
- if ( !is_file ( $lien_image ) || !is_file ( $lien_thumbnail ) )
- {
- if ( !is_file ( $lien_image ) )
- {
- echo $row['file']." <span style=\"font-weight:bold;\">".$lang['update_disappeared']."</span><br />";
- }
- if ( !is_file ( $lien_thumbnail ) )
- {
- echo $row['file']." : <span style=\"font-weight:bold;\">".$lang['update_disappeared_tn']."</span><br />";
- }
- // suppression de la base :
- delete_image( $row['id'] );
- }
- }
-
- // searching the new images in the directory
- $pictures = array();
- $i = 0;
- $tn_ext = "";
- $root = "";
- if ( $opendir = opendir ( $rep ) )
- {
- while ( $file = readdir ( $opendir ) )
- {
- if ( is_file( $rep."/".$file ) && is_image( $rep."/".$file ) )
- {
- // is the picture waiting for validation by an administrator ?
- $query = "select id from $prefixeTable"."waiting";
- $query.= " where cat_id = $category_id";
- $query.= " and file = '$file';";
- $result = mysql_query( $query );
- if ( mysql_num_rows( $result ) == 0 )
- {
- if ( $tn_ext = TN_exist( $rep, $file ) )
- {
- // is the picture already in the database ?
- $query = "select id from $prefixeTable"."images";
- $query.= " where cat_id = $category_id";
- $query.= " and file = '$file';";
- $result = mysql_query( $query );
- if ( mysql_num_rows( $result ) == 0 )
- {
- $pictures[$i] = array();
- $pictures[$i]['file'] = $file;
- $pictures[$i]['tn_ext'] = $tn_ext;
- $pictures[$i]['date'] = date( "Y-m-d", filemtime ( $rep."/".$file ) );
- $pictures[$i]['filesize'] = floor ( filesize( $rep."/".$file ) / 1024 );
- $image_size = @getimagesize( $rep."/".$file );
- $pictures[$i]['width'] = $image_size[0];
- $pictures[$i]['height'] = $image_size[1];
- $i++;
- }
- }
- else
- {
- echo "<span style=\"color:red;\">".$lang['update_missing_tn']." : $file (<span style=\"font-weight:bold;\">".$conf['prefixe_thumbnail'].substr( $file, 0, strrpos( $file, "." ) ).".XXX</span>, XXX = gif, png or jpg)</span><br />";
- }
- }
- }
- }
- }
- // inserting the pictures found in the directory
- $root.= "\n".$indent."<root>";
- if ( sizeof( $pictures ) > 0 )
- {
- for( $i = 0; $i < sizeof( $pictures ); $i++ )
- {
- $query = "insert into $prefixeTable"."images (file,cat_id,date_available,tn_ext,filesize,width,height) values ('".$pictures[$i]['file']."','".$category_id."','".$pictures[$i]['date']."','".$pictures[$i]['tn_ext']."','".$pictures[$i]['filesize']."','".$pictures[$i]['width']."','".$pictures[$i]['height']."');";
- echo"
- ".$pictures[$i]['file']." <span style=\"font-weight:bold;\">".$lang['update_research_added']."</span> (".$lang['update_research_tn_ext']." ".$pictures[$i]['tn_ext'].")<br />";
- $count_new++;
- mysql_query( $query );
- }
- }
- }
-
- // The function "update_cat_info" updates the information about the last online image
- // and the number of images in the category
- function update_cat_info( $category_id )
- {
- global $prefixeTable;
-
- $query = "select date_available from $prefixeTable"."images";
- $query.= " where cat_id = $category_id";
- $query.= " order by date_available desc limit 0,1;";
- $result = mysql_query( $query );
- $row = mysql_fetch_array( $result );
- $date_last = $row['date_available'];
-
- $query = "select count(*) as nb_images from $prefixeTable"."images";
- $query.= " where cat_id = $category_id";
- $result = mysql_query( $query );
- $row = mysql_fetch_array( $result );
- $nb_images = $row['nb_images'];
-
- $query = "update $prefixeTable"."categories";
- $query.= " set date_dernier = '$date_last'";
- $query.= ", nb_images = $nb_images";
- $query.= " where id = $category_id;";
- mysql_query( $query );
- }
-
- function getContent( $element, $node )
- {
- $content = str_replace( "<".$node.">", "", $element );
- $content = str_replace( "</".$node.">", "", $content );
- return $content;
- }
-
- function getChild( $document, $node )
- {
- preg_match("/\<".$node.">.*\<\/".$node."\>/U", $document, $retour);
- return $retour[0];
- }
-
- function getChildren( $document, $node )
- {
- preg_match_all("/\<".$node.">.*\<\/".$node."\>/U", $document, $retour);
- return $retour[0];
- }
-
- function remote_images()
- {
- global $conf, $prefixeTable, $lang;
-
- // 1.is there a file listing.xml ?
- $filename = "listing.xml";
- $xml_content = "";
- if ( $fp = @fopen ( $filename, "r" ) )
- {
- while ( !feof ( $fp ) )
- {
- $xml_content .= fgets ( $fp, 1024 );
- }
- @fclose( $file );
- $xml_content = str_replace("\n","",$xml_content);
- $xml_content = str_replace("\t","",$xml_content);
- }
- else
- {
- return false;
- }
- $url = getContent( getChild( $xml_content, "url" ), "url" );
- echo "<span style=\"font-weight:bold;color:navy;\">$url</span><br /><br />";
-
- // 2. is the site already existing ?
- $site_id = "";
- $result = mysql_query( "select id from $prefixeTable"."sites where galleries_url = '$url';" );
- if ( mysql_num_rows($result ) == 0 )
- {
- // we have to register this site in the database
- mysql_query( "insert into $prefixeTable"."sites (galleries_url) values ('$url');" );
- $site_id = mysql_insert_id();
- }
- else
- {
- // we get the already registered id
- $row = mysql_fetch_array( $result );
- $site_id = $row['id'];
- }
-
- // 3. available dirs in the file
- insert_remote_category( $xml_content, $site_id, "NULL", 0 );
- }
-
- // insert_remote_category search the "dir" node of the xml_dir given
- // and insert the contained categories if the are not in the database yet.
- // The function also delete the categories that are in the database
- // and not in the xml_file
- function insert_remote_category( $xml_dir, $site_id, $id_uppercat, $level )
- {
- global $prefixeTable,$conf;;
-
- $categories = array();
- $list_dirs = getChildren( $xml_dir, "dir".$level );
- for ( $i = 0; $i < sizeof( $list_dirs ); $i++ )
- {
- // is the category already existing ?
- $category_id = "";
- $name = getContent( getChild( $list_dirs[$i], "name" ), "name" );
- $categories[$i] = $name;
- echo "
- <img src=\"".$conf['lien_puce']."\"><span style=\"font-weight:bold;\">$name</span>
- <div class=\"retrait\">";
- $query = "select id from $prefixeTable"."categories";
- $query.= " where site_id = '$site_id'";
- $query.= " and dir = '$name'";
- if ( $id_uppercat == "NULL" )
- {
- $query.= " and id_uppercat is NULL;";
- }
- else
- {
- $query.= " and id_uppercat = '$id_uppercat';";
- }
- //echo "<br />".$query;
- $result = mysql_query( $query );
- if ( mysql_num_rows( $result ) == 0 )
- {
- // we have to create the category
- $query = "insert into $prefixeTable"."categories (dir,site_id,id_uppercat) values ('$name','$site_id'";
- if ( $id_uppercat == "NULL" )
- {
- $query.= ",NULL";
- }
- else
- {
- $query.= ",'$id_uppercat'";
- }
- $query.= ");";
- //echo "<br />".$query;
- mysql_query( $query );
- $category_id = mysql_insert_id();
- }
- else
- {
- // we get the already registered id
- $row = mysql_fetch_array( $result );
- $category_id = $row['id'];
- }
- insert_remote_image( $list_dirs[$i], $category_id );
- update_cat_info( $category_id );
- insert_remote_category( $list_dirs[$i], $site_id, $category_id, $level + 1 );
- echo "
- </div>";
- }
- // we have to remove the categories of the database not present in the xml file
- // (ie deleted from the picture storage server)
- $query = "select dir,id from $prefixeTable"."categories";
- $query.= " where site_id = '$site_id'";
- if ( $id_uppercat == "NULL" )
- {
- $query.= " and id_uppercat is NULL;";
- }
- else
- {
- $query.= " and id_uppercat = '$id_uppercat';";
- }
- $result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
- {
- // is the category in the xml file ?
- if ( !in_array( $row['dir'], $categories ) )
- {
- delete_category( $row['id'] );
- }
- }
- }
-
- // insert_remote_image search the "root" node of the xml_dir given
- // and insert the contained pictures if the are not in the database yet
- function insert_remote_image( $xml_dir, $category_id )
- {
- global $prefixeTable,$count_new,$lang;
-
- $root = getChild( $xml_dir, "root" );
- $pictures = array();
- $xml_pictures = getChildren( $root, "picture" );
- for ( $j = 0; $j < sizeof( $xml_pictures ); $j++ )
- {
- //<picture>
- // <file>albatros.jpg</file>
- // <tn_ext>png</tn_ext>
- // <date>2002-04-14</date>
- // <filesize>35</filesize>
- // <width>640</width>
- // <height>480</height>
- //</picture>
- $file = getContent( getChild( $xml_pictures[$j], "file" ), "file" );
- $tn_ext = getContent( getChild( $xml_pictures[$j], "tn_ext" ), "tn_ext" );
- $date = getContent( getChild( $xml_pictures[$j], "date" ), "date" );
- $filesize = getContent( getChild( $xml_pictures[$j], "filesize" ), "filesize" );
- $width = getContent( getChild( $xml_pictures[$j], "width" ), "width" );
- $height = getContent( getChild( $xml_pictures[$j], "height" ), "height" );
-
- $pictures[$j] = $file;
-
- // is the picture already existing in the database ?
- $query = "select id,tn_ext from $prefixeTable"."images where cat_id = '$category_id' and file = '$file';";
- $result = mysql_query( $query );
- $query = "";
- if ( mysql_num_rows( $result ) == 0 )
- {
- $query = "insert into $prefixeTable"."images (file,cat_id,date_available,tn_ext,filesize,width,height) values ('$file','$category_id','$date','$tn_ext','$filesize','$width','$height');";
- echo"
- $file <span style=\"font-weight:bold;\">".$lang['update_research_added']."</span> (".$lang['update_research_tn_ext']." $tn_ext)<br />";
- $count_new++;
- }
- else
- {
- // is the tn_ext the same in the xml file and in the database ?
- $row = mysql_fetch_array( $result );
- if ( $row['tn_ext'] != $tn_ext )
- {
- $query = "update $prefixeTable"."images set tn_ext = '$tn_ext' where cat_id = '$category_id' and file = '$file';";
- }
- }
- // execution of the query
- if ( $query != "" )
- {
- mysql_query( $query );
- }
- }
- // we have to remove the pictures of the database not present in the xml file
- // (ie deleted from the picture storage server)
- $query = "select id,file from $prefixeTable"."images where cat_id = '$category_id';";
- $result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
- {
- // is the file in the xml file ?
- if ( !in_array( $row['file'], $pictures ) )
- {
- delete_image( $row['id'] );
- }
- }
- }
- //------------------------------------------------------------------------------
- echo "<table style=\"width:100%;\">";
- //------------------------------------------------------------------------------
- // Display choice if "update" var is not specified
- check_cat_id( $HTTP_GET_VARS['update'] );
- if ( !isset( $HTTP_GET_VARS['update'] ) && !( isset( $page['cat'] ) || $HTTP_GET_VARS['update'] == 'cats' || $HTTP_GET_VARS['update'] == 'all' ) )
- {
- echo"
- <tr><th>".$lang['update_default_title']."</th></tr>
- <tr>
- <td>
- <div class=\"retrait\">
- <img src=\"".$conf['lien_puce']."\" alt=\"&gt;\" /><a href=\"".add_session_id_to_url( "./admin.php?page=miseajour&amp;update=cats" )."\">".$lang['update_only_cat']."</a>
- <br /><img src=\"".$conf['lien_puce']."\" alt=\"&gt;\" /><a href=\"".add_session_id_to_url( "./admin.php?page=miseajour&amp;update=all" )."\">".$lang['update_all']."</a>
- </div>
- </td>
- </tr>";
- }
- //------------------------------------------------------------------------------
- // Recherche des nouvelles images dans les repertoires
- else
- {
- $count_new = 0;
- $count_deleted = 0;
- echo"
- <tr><th>".$lang['update_part_research']."</th></tr>
- <tr>
- <td>
- <div class=\"retrait\">";
- if ( isset( $page['cat'] ) )
- {
- insert_local_category( $page['cat'] );
- }
- else
- {
- insert_local_category( "NULL" );
- }
- echo "<br /><span style=\"color:blue;\">$count_new ".$lang['update_research_conclusion']."</span>";
- echo "<br /><span style=\"color:red;\">$count_deleted ".$lang['update_deletion_conclusion']."</span>";
- echo "
- </div>
- </td>
- </tr>";
- }
- //------------------------------------------------------------------------------
- // Searching new pictures in the file listing.xml from a remote storage server
- if ( @is_file( "./listing.xml" ) )
- {
- $count_new = 0;
- $count_deleted = 0;
- echo"
- <tr><th>Site distant</th></tr>
- <tr>
- <td>
- <div class=\"retrait\">";
- remote_images();
- echo "<br /><span style=\"color:blue;\">$count_new ".$lang['update_research_conclusion']."</span>";
- echo "<br /><span style=\"color:red;\">$count_deleted ".$lang['update_deletion_conclusion']."</span>";
- echo "
- </div>
- </td>
- </tr>";
- }
- //------------------------------------------------------------------------------
- echo "</table>";
-?> \ No newline at end of file
diff --git a/category.php b/category.php
index 8796ce8c4..c0b803528 100644
--- a/category.php
+++ b/category.php
@@ -170,7 +170,7 @@ if ( !$user['is_the_guest'] )
$url.= '&amp;expand='.$page['expand'];
if ( $page['cat'] == 'search' )
{
- $url.= '&amp;search='.$_GET['search'];
+ $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$vtp->setVar( $handle, 'summary.url', add_session_id( $url ) );
$vtp->setVar( $handle, 'summary.title', $lang['hint_customize'] );
@@ -243,12 +243,15 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$query.= $conf['order_by'];
$query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
$query.= ';';
+ echo $query;
$result = mysql_query( $query );
$vtp->addSession( $handle, 'thumbnails' );
$vtp->addSession( $handle, 'line' );
// iteration counter to use a new <tr> every "$nb_image_line" pictures
- $i = 1;
+ $cell_number = 1;
+ // iteration counter to be sure not to create too much lines in the table
+ $line_number = 1;
while ( $row = mysql_fetch_array( $result ) )
{
if ( !is_numeric( $page['cat'] ) )
@@ -294,11 +297,11 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$url_link.= '&amp;image_id='.$row['id'].'&amp;expand='.$page['expand'];
if ( $page['cat'] == 'search' )
{
- $url_link.= '&amp;search='.$_GET['search'];
+ $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
// date of availability for creation icon
- $date = explode( '-', $row['date_available'] );
- $date = mktime( 0, 0, 0, $date[1], $date[2], $date[0] );
+ list( $year,$month,$day ) = explode( '-', $row['date_available'] );
+ $date = mktime( 0, 0, 0, $month, $day, $year );
// sending vars to display
$vtp->addSession( $handle, 'thumbnail' );
$vtp->setVar( $handle, 'thumbnail.url', add_session_id( $url_link ) );
@@ -322,21 +325,20 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$vtp->closeSession( $handle, 'thumbnail' );
- if ( $i == $user['nb_image_line'] )
+ if ( $cell_number++ == $user['nb_image_line'] )
{
+ // creating a new line
$vtp->closeSession( $handle, 'line' );
- $vtp->addSession( $handle, 'line' );
- $i = 1;
- }
- else
- {
- $i++;
+ // the number of the next cell is 1
+ $cell_number = 1;
+ // we only create a new line if it does not exceed the maximum line
+ // per page for the logged user
+ if ( $line_number++ < $user['nb_line_page'] )
+ {
+ $vtp->addSession( $handle, 'line' );
+ }
}
}
- if ( $i < $user['nb_image_line'] )
- {
- $vtp->closeSession( $handle, 'line' );
- }
$vtp->closeSession( $handle, 'thumbnails' );
}
elseif ( isset( $page['cat'] )
@@ -347,8 +349,8 @@ elseif ( isset( $page['cat'] )
$vtp->addSession( $handle, 'line' );
$subcats = get_non_empty_sub_cat_ids( $page['cat'] );
- $i = 1;
- foreach ( $subcats as $subcat) {
+ $cell_number = 1;
+ foreach ( $subcats as $id => $subcat ) {
$result = get_cat_info( $subcat['non_empty_cat'] );
$cat_directory = $result['dir'];
@@ -373,8 +375,7 @@ elseif ( isset( $page['cat'] )
$image_result = mysql_query( $query );
$image_row = mysql_fetch_array( $image_result );
- $file = substr ( $image_row['file'], 0,
- strrpos ( $image_row['file'], '.' ) );
+ $file = get_filename_wo_extension( $image_row['file'] );
// creating links for thumbnail and associated category
$lien_image = $cat_directory;
@@ -383,15 +384,17 @@ elseif ( isset( $page['cat'] )
$lien_thumbnail.= $file.'.'.$image_row['tn_ext'];
$lien_image.= $image_row['file'];
- $thumbnail_title = '';
+ $thumbnail_title = $lang['hint_category'];
$url_link = './category.php?cat='.$subcat['id'];
if ( !in_array( $page['cat'], $page['tab_expand'] ) )
{
- $page['tab_expand'][sizeof( $page['tab_expand'] )] = $page['cat'];
+ array_push( $page['tab_expand'], $page['cat'] );
$page['expand'] = implode( ',', $page['tab_expand'] );
}
$url_link.= '&amp;expand='.$page['expand'];
+ list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
+ $date = mktime( 0, 0, 0, $month, $day, $year );
// sending vars to display
$vtp->addSession( $handle, 'thumbnail' );
@@ -400,24 +403,24 @@ elseif ( isset( $page['cat'] )
$vtp->setVar( $handle, 'thumbnail.alt', $image_row['file'] );
$vtp->setVar( $handle, 'thumbnail.title', $thumbnail_title );
$vtp->setVar( $handle, 'thumbnail.name', $name );
-
- list( $year,$month,$day ) = explode( '-', $subcat['date_dernier'] );
- $date = mktime( 0, 0, 0, $month, $day, $year );
$vtp->setVar( $handle, 'thumbnail.icon', get_icon( $date ) );
-
$vtp->closeSession( $handle, 'thumbnail' );
- if ( $i == $user['nb_image_line'] )
+ if ( $cell_number++ == $user['nb_image_line'] )
{
$vtp->closeSession( $handle, 'line' );
- $vtp->addSession( $handle, 'line' );
- $i = 1;
- }
- else
- {
- $i++;
+ $cell_number = 1;
+ // we open a new line if the subcat was not the last one
+ if ( $id < count( $subcats ) - 1 )
+ {
+ $vtp->addSession( $handle, 'line' );
+ }
}
}
+ if ( $id < count( $subcats ) - 1 )
+ {
+ $vtp->closeSession( $handle, 'line' );
+ }
$vtp->closeSession( $handle, 'thumbnails' );
}
//------------------------------------------------------- category informations
diff --git a/include/config.inc.php b/include/config.inc.php
index fec4fa170..25566bd79 100644
--- a/include/config.inc.php
+++ b/include/config.inc.php
@@ -37,9 +37,8 @@ include_once( PREFIXE_INCLUDE.'./include/vtemplate.class.php' );
// 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';
+$conf['order_by'] = ' ORDER BY date_available DESC, file ASC';
-$conf['repertoire_image'] = './images/';
$conf['nb_image_row'] = array('4','5','6','7','8');
$conf['nb_row_page'] = array('2','3','4','5','6','7','10','20','1000');
$conf['version'] = '1.3';
diff --git a/include/functions.inc.php b/include/functions.inc.php
index 5ff119f29..eb8571e86 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -169,7 +169,7 @@ function get_dirs( $rep )
{
while ( $file = readdir ( $opendir ) )
{
- if ( $file != "." and $file != ".." and is_dir ( $rep.$file ) )
+ if ( $file != '.' and $file != '..' and is_dir ( $rep.$file ) )
{
array_push( $sub_rep, $file );
}
@@ -274,14 +274,14 @@ function get_themes( $theme_dir )
return $themes;
}
-// - The replace_search function replaces a $search string by the search in
-// another color
+// - add_style replaces the
+// $search into <span style="$style">$search</span>
+// in the given $string.
// - The function does not replace characters in HTML tags
-function replace_search( $string, $search )
+function add_style( $string, $search, $style )
{
//return $string;
- $style_search = "background-color:white;color:red;";
- $return_string = "";
+ $return_string = '';
$remaining = $string;
$start = 0;
@@ -291,21 +291,32 @@ function replace_search( $string, $search )
while ( is_numeric( $start ) and is_numeric( $end ) )
{
$treatment = substr ( $remaining, 0, $start );
- $treatment = str_replace( $search, '<span style="'.$style_search.'">'.
+ $treatment = str_replace( $search, '<span style="'.$style.'">'.
$search.'</span>', $treatment );
- $return_string.= $treatment.substr ( $remaining, $start,
- $end - $start + 1 );
+ $return_string.= $treatment.substr( $remaining, $start, $end-$start+1 );
$remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
$start = strpos ( $remaining, '<' );
$end = strpos ( $remaining, '>' );
}
- $treatment = str_replace( $search, '<span style="'.$style_search.'">'.
+ $treatment = str_replace( $search, '<span style="'.$style.'">'.
$search.'</span>', $remaining );
$return_string.= $treatment;
return $return_string;
}
+// replace_search replaces a searched words array string by the search in
+// another style for the given $string.
+function replace_search( $string, $search )
+{
+ $words = explode( ',', $search );
+ $style = 'background-color:white;color:red;';
+ foreach ( $words as $word ) {
+ $string = add_style( $string, $word, $style );
+ }
+ return $string;
+}
+
function database_connection()
{
// $cfgHote,$cfgUser,$cfgPassword,$cfgBase;
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 25c54c94a..aa4e277dc 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -132,7 +132,7 @@ function display_cat( $id_uppercat, $indent, $restriction, $tab_expand )
$url = "./category.php?cat=".$page['cat']."&amp;expand=$expand";
if ( $page['cat'] == 'search' )
{
- $url.= "&amp;search=".$_GET['search'];
+ $url.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$lien_cat = add_session_id( $url );
if ( $row['name'] == "" )
@@ -381,7 +381,15 @@ function initialize_category( $calling_page = 'category' )
}
else
{
- $query = '';
+ if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
+ or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
+ {
+ // we must not show pictures of a forbidden category
+ $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
+ foreach ( $restricted_cats as $restricted_cat ) {
+ $where_append.= ' AND cat_id != '.$restricted_cat;
+ }
+ }
// search result
if ( $page['cat'] == 'search' )
{
@@ -391,16 +399,40 @@ function initialize_category( $calling_page = 'category' )
$page['title'].= ' : <span style="font-style:italic;">';
$page['title'].= $_GET['search']."</span>";
}
- $page['where'] = " WHERE ( file LIKE '%".$_GET['search']."%'";
- $page['where'].= " OR name LIKE '%".$_GET['search']."%'";
- $page['where'].= " OR comment LIKE '%".$_GET['search']."%' )";
+
+ $page['where'] = ' WHERE (';
+ $fields = array( 'file', 'name', 'comment' );
+ $words = explode( ',', $_GET['search'] );
+ $sql_search = array();
+ foreach ( $words as $i => $word ) {
+ if ( $_GET['mode'] == 'OR' )
+ {
+ if ( $i != 0 ) $page['where'].= ' OR';
+ foreach ( $fields as $j => $field ) {
+ if ( $j != 0 ) $page['where'].= ' OR';
+ $page['where'].= ' '.$field." LIKE '%".$word."%'";
+ }
+ }
+ else if ( $_GET['mode'] == 'AND' )
+ {
+ if ( $i != 0 ) $page['where'].= ' AND';
+ $page['where'].= ' (';
+ foreach ( $fields as $j => $field ) {
+ if ( $j != 0 ) $page['where'].= ' OR';
+ $page['where'].= ' '.$field." LIKE '%".$word."%'";
+ }
+ $page['where'].= ' )';
+ }
+ }
+ $page['where'].= ' )';
+ $page['where'].= $where_append;
$query = 'SELECT COUNT(*) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'images';
$query.= $page['where'];
$query.= ';';
- $url.= '&amp;search='.$_GET['search'];
+ $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
// favorites displaying
else if ( $page['cat'] == 'fav' )
@@ -425,6 +457,7 @@ function initialize_category( $calling_page = 'category' )
$date = time() - 60*60*24*$user['short_period'];
$page['where'] = " WHERE date_available > '";
$page['where'].= date( 'Y-m-d', $date )."'";
+ $page['where'].= $where_append;
$query = 'SELECT COUNT(*) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'images';
@@ -435,7 +468,7 @@ function initialize_category( $calling_page = 'category' )
else if ( $page['cat'] == 'most_visited' )
{
$page['title'] = $conf['top_number'].' '.$lang['most_visited_cat'];
- $page['where'] = ' WHERE cat_id != -1';
+ $page['where'] = ' WHERE cat_id != -1'.$where_append;
$conf['order_by'] = ' ORDER BY hit DESC, file ASC';
$page['cat_nb_images'] = $conf['top_number'];
if ( $page['start'] + $user['nb_image_page'] >= $conf['top_number'] )
@@ -450,16 +483,6 @@ function initialize_category( $calling_page = 'category' )
$row = mysql_fetch_array( $result );
$page['cat_nb_images'] = $row['nb_total_images'];
}
-
- if ( $page['cat'] == 'search' or $page['cat'] == 'most_visited'
- or $page['cat'] == 'recent' or $page['cat'] == 'best_rated' )
- {
- // we must not show pictures of a forbidden category
- $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
- foreach ( $restricted_cats as $restricted_cat ) {
- $page['where'].= ' AND cat_id != '.$restricted_cat;
- }
- }
}
if ( $calling_page == 'category' )
{
@@ -518,23 +541,16 @@ function get_non_empty_sub_cat_ids( $id_uppercat )
$result = mysql_query( $query );
while ( $row = mysql_fetch_array( $result ) )
{
- if ( $row['nb_images'] == 0 )
- {
- $non_empty_cat = get_first_non_empty_cat_id( $row['id'] );
- }
- else
- {
- $non_empty_cat = $row['id'];
- }
// only categories with findable picture in any of its subcats is
// represented.
- if ( $non_empty_cat != false )
+ if ( ( $row['nb_images'] != 0 and $non_empty_cat = $row['id'] )
+ or $non_empty_cat = get_first_non_empty_cat_id( $row['id'] ) )
{
$temp_cat = array(
- 'id' => $row['id'],
- 'name' => $row['name'],
- 'dir' => $row['dir'],
- 'date_dernier' => $row['date_dernier'],
+ 'id' => $row['id'],
+ 'name' => $row['name'],
+ 'dir' => $row['dir'],
+ 'date_dernier' => $row['date_dernier'],
'non_empty_cat' => $non_empty_cat );
array_push( $cats, $temp_cat );
}
diff --git a/language/francais.php b/language/francais.php
index 649f12996..b725f8698 100644
--- a/language/francais.php
+++ b/language/francais.php
@@ -180,7 +180,11 @@ $lang['reg_err_mail_address'] = 'l\'adresse mail doit être de la forme xxx@yyy.e
// page search
$lang['search_title'] = 'Recherche';
-$lang['invalid_search'] = 'La recherche doit porter sur 3 caractères ou plus';
+// start version 1.3
+$lang['invalid_search'] = 'Les mots recherchés doivent comporter plus de 3 caractères et ne doivent pas inclure de caractères de ponctuation';
+$lang['search_mode_or'] = 'au moins un mot';
+$lang['search_mode_and'] = 'tous les mots';
+// end version 1.3
$lang['search_field_search'] = 'Rechercher';
$lang['search_return_main_page'] = 'Retour à la page des miniatures';
diff --git a/picture.php b/picture.php
index 4c3fd749c..76a0fdaa0 100644
--- a/picture.php
+++ b/picture.php
@@ -132,7 +132,7 @@ if ( isset( $_GET['add_fav'] ) )
$redirect.= '&expand='.$_GET['expand'];
if ( $page['cat'] == 'search' )
{
- $redirect.= '&search='.$_GET['search'];
+ $redirect.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$url = add_session_id( $redirect, true );
header( 'Request-URI: '.$url );
@@ -211,7 +211,7 @@ if ( $page['num'] >= 1 )
$url_link.= '&amp;expand='.$_GET['expand'];
if ( $page['cat'] == 'search' )
{
- $url_link.= '&amp;search='.$_GET['search'];
+ $url_link.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
// sending vars for display
$vtp->addSession( $handle, 'previous' );
@@ -285,7 +285,7 @@ $url_link = './category.php?cat='.$page['cat'].'&amp;';
$url_link.= 'num='.$page['num'].'&amp;expand='.$_GET['expand'];
if ( $page['cat'] == 'search' )
{
- $url_link.= "&amp;search=".$_GET['search'];
+ $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$vtp->setGlobalVar( $handle, 'picture_link', add_session_id( $url_link ) );
$vtp->setGlobalVar( $handle, 'picture_width', $final_width );
@@ -385,7 +385,7 @@ if ( $page['cat'] != 'fav' && !$user['is_the_guest'] )
$url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=1';
if ( $page['cat'] == 'search' )
{
- $url.= '&amp;search='.$_GET['search'];
+ $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$vtp->addSession( $handle, 'favorite' );
$vtp->setVar( $handle, 'favorite.link', add_session_id( $url ) );
@@ -458,7 +458,7 @@ if ( $page['num'] < $page['cat_nb_images']-1 )
$url_link.= '&amp;expand='.$_GET['expand'];
if ( $page['cat'] == 'search' )
{
- $url_link.= "&amp;search=".$_GET['search'];
+ $url_link.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
}
// sending vars for display
$vtp->addSession( $handle, 'next' );
@@ -511,7 +511,7 @@ if ( $conf['show_comments'] )
$url.= '&amp;expand='.$_GET['expand'];
if ( $page['cat'] == 'search' )
{
- $url.= '&amp;search='.$_GET['search'];
+ $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
if( !isset( $_GET['start'] )
|| !is_numeric( $_GET['start'] )
diff --git a/profile.php b/profile.php
index c3ce554ca..30e28c256 100644
--- a/profile.php
+++ b/profile.php
@@ -132,7 +132,7 @@ if ( isset( $_POST['submit'] ) )
$url = 'category.php?cat='.$page['cat'].'&expand='.$_GET['expand'];
if ( $page['cat'] == 'search' )
{
- $url.= '&search='.$_GET['search'];
+ $url.= '&search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$url = add_session_id( $url, true );
header( 'Request-URI: '.$url );
@@ -152,7 +152,7 @@ templatize_array( $tpl, 'lang', $handle );
$url = './profile.php?cat='.$page['cat'].'&amp;expand='.$page['expand'];
if ( $page['cat'] == 'search' )
{
- $url.= '&amp;search='.$_GET['search'];
+ $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
}
$vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) );
//-------------------------------------------------------------- errors display
diff --git a/search.php b/search.php
index e751fa032..81d5d97f9 100644
--- a/search.php
+++ b/search.php
@@ -23,20 +23,32 @@ check_login_authorization();
$error = array();
if ( isset( $_POST['search'] ) )
{
- $i = 0;
- if ( strlen( $_POST['search'] ) > 2 )
+ $redirect = true;
+ $search = array();
+ $words = preg_split( '/\s+/', $_POST['search'] );
+ foreach ( $words as $i => $word ) {
+ if ( strlen( $word ) > 2 and !preg_match( '/[,;:\']/', $word ) )
+ {
+ array_push( $search, $word );
+ }
+ else
+ {
+ $redirect = false;
+ array_push( $error, $lang['invalid_search'] );
+ break;
+ }
+ }
+ $search = array_unique( $search );
+ $search = implode( ',', $search );
+ if ( $redirect )
{
- $url = add_session_id( 'category.php?cat=search&search='.
- $_POST['search'], true );
+ $url = 'category.php?cat=search&search='.$search.'&mode='.$_POST['mode'];
+ $url = add_session_id( $url, true );
header( 'Request-URI: '.$url );
header( 'Content-Location: '.$url );
header( 'Location: '.$url );
exit();
}
- else
- {
- $error[$i++] = $lang['invalid_search'];
- }
}
//----------------------------------------------------- template initialization
$vtp = new VTemplate;
@@ -67,7 +79,8 @@ if ( sizeof( $error ) != 0 )
}
$vtp->closeSession( $handle, 'errors' );
}
-//---------------------------------------------------------------- search field
+//------------------------------------------------------------------------ form
+// search field
$vtp->addSession( $handle, 'line' );
$vtp->setVar( $handle, 'line.name', $lang['search_field_search'] );
$vtp->addSession( $handle, 'text' );
@@ -76,12 +89,40 @@ $vtp->setVar( $handle, 'text.name', 'search' );
$vtp->setVar( $handle, 'text.value', $_POST['search'] );
$vtp->closeSession( $handle, 'text' );
$vtp->closeSession( $handle, 'line' );
+// mode of search : match all words or at least one of this words
+$vtp->addSession( $handle, 'line' );
+$vtp->addSession( $handle, 'group' );
+
+$vtp->addSession( $handle, 'radio' );
+$vtp->setVar( $handle, 'radio.name', 'mode' );
+$vtp->setVar( $handle, 'radio.value', 'OR' );
+$vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
+if ( $_POST['mode'] == 'OR' or $_POST['mode'] == '' )
+{
+ $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
+}
+$vtp->closeSession( $handle, 'radio' );
+
+$vtp->addSession( $handle, 'radio' );
+$vtp->setVar( $handle, 'radio.name', 'mode' );
+$vtp->setVar( $handle, 'radio.value', 'AND' );
+$vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
+if ( $_POST['mode'] == 'AND' )
+{
+ $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
+}
+$vtp->closeSession( $handle, 'radio' );
+
+$vtp->closeSession( $handle, 'group' );
+$vtp->closeSession( $handle, 'line' );
//---------------------------------------------------- return to main page link
$vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
//----------------------------------------------------------- html code display
$code = $vtp->Display( $handle, 0 );
echo $code;
//------------------------------------------------------------ log informations
+pwg_log( 'category', $page['title'] );
+mysql_close();
$query = 'insert into '.PREFIX_TABLE.'history';
$query.= '(date,login,IP,page) values';
$query.= "('".time()."', '".$user['pseudo']."','".$_SERVER['REMOTE_ADDR']."'";
diff --git a/template/default/search.vtp b/template/default/search.vtp
index 3b79b6637..8ba9039c7 100644
--- a/template/default/search.vtp
+++ b/template/default/search.vtp
@@ -47,6 +47,11 @@
<!--VTP_text-->
<input type="text" name="{#name}" size="{#size}" value="{#value}" />
<!--/VTP_text-->
+ <!--VTP_group-->
+ <!--VTP_radio-->
+ <input type="radio" name="{#name}" value="{#value}"{#checked}/>{#option}
+ <!--/VTP_radio-->
+ <!--/VTP_group-->
</td>
</tr>
<!--/VTP_line-->