aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-07-23 19:49:15 +0000
committerz0rglub <z0rglub@piwigo.org>2003-07-23 19:49:15 +0000
commit0a5b436654df4c849749435eacec380e092351a8 (patch)
treedca43d37f1f60d6ef12d5cbef32b5275c5176024
parent53479d08c3e10bbb8eb14c0659c3a8141318617a (diff)
Support of keywords for pictures. They are used in the search
git-svn-id: http://piwigo.org/svn/trunk@33 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--admin/infos_images.php111
-rw-r--r--include/functions_category.inc.php2
-rw-r--r--language/francais.php1
-rw-r--r--template/default/admin/infos_image.vtp20
4 files changed, 98 insertions, 36 deletions
diff --git a/admin/infos_images.php b/admin/infos_images.php
index 29957b478..62c09863f 100644
--- a/admin/infos_images.php
+++ b/admin/infos_images.php
@@ -21,17 +21,16 @@ include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' );
function check_date_format( $date )
{
// date arrives at this format : DD/MM/YYYY
- // checkdate ( int month, int day, int year)
- $tab_date = explode( '/', $date );
- return checkdate ( $tab_date[1], $tab_date[0], $tab_date[2]);
+ list($day,$month,$year) = explode( '/', $date );
+ return checkdate ( $month, $day, $year );
}
function date_convert( $date )
{
// date arrives at this format : DD/MM/YYYY
// It must be transformed in YYYY-MM-DD
- $tab_date = explode( '/', $date );
- return $tab_date[2].'-'.$tab_date[1].'-'.$tab_date[0];
+ list($day,$month,$year) = explode( '/', $date );
+ return $year.'-'.$month.'-'.$day;
}
function date_convert_back( $date )
@@ -40,14 +39,33 @@ function date_convert_back( $date )
// It must be transformed in DD/MM/YYYY
if ( $date != '' )
{
- $tab_date = explode( '-', $date );
- return $tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0];
+ list($year,$month,$day) = explode( '-', $date );
+ return $day.'/'.$month.'/'.$year;
}
else
{
return '';
}
}
+
+// get_keywords returns an array with relevant keywords found in the string
+// given in argument. Keywords must be separated by comma in this string.
+// keywords must :
+// - be longer or equal to 3 characters
+// - not contain ', " or blank characters
+// - unique in the string ("test,test" -> "test")
+function get_keywords( $keywords_string )
+{
+ $keywords = array();
+
+ $candidates = explode( ',', $keywords_string );
+ foreach ( $candidates as $candidate ) {
+ if ( strlen($candidate) >= 3 and !preg_match( '/(\'|"|\s)/', $candidate ) )
+ array_push( $keywords, $candidate );
+ }
+
+ return array_unique( $keywords );
+}
//-------------------------------------------------------------- initialization
check_cat_id( $_GET['cat_id'] );
@@ -66,42 +84,49 @@ if ( isset( $page['cat'] ) )
$author = 'author-'.$row['id'];
$comment = 'comment-'.$row['id'];
$date_creation = 'date_creation-'.$row['id'];
+ $keywords = 'keywords-'.$row['id'];
if ( isset( $_POST[$name] ) )
{
$query = 'UPDATE '.PREFIX_TABLE.'images';
+
+ $query.= ' SET name = ';
if ( $_POST[$name] == '' )
- {
- $query.= ' SET name = NULL';
- }
+ $query.= 'NULL';
else
- {
- $query.= " SET name = '".htmlentities( $_POST[$name], ENT_QUOTES )."'";
- }
+ $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
+
+ $query.= ', author = ';
if ( $_POST[$author] == '' )
- {
- $query.= ', author = NULL';
- }
+ $query.= 'NULL';
else
- {
- $query.= ", author = '".htmlentities($_POST[$author],ENT_QUOTES)."'";
- }
+ $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
+
+ $query.= ', comment = ';
if ( $_POST[$comment] == '' )
- {
- $query.= ', comment = NULL';
- }
+ $query.= 'NULL';
else
- {
- $query.= ", comment = '".htmlentities($_POST[$comment],ENT_QUOTES)."'";
- }
+ $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
+
+ $query.= ', date_creation = ';
if ( check_date_format( $_POST[$date_creation] ) )
- {
- $date = date_convert( $_POST[$date_creation] );
- $query.= ", date_creation = '".$date."'";
- }
+ $query.= "'".date_convert( $_POST[$date_creation] )."'";
else if ( $_POST[$date_creation] == '' )
+ $query.= 'NULL';
+
+ $query.= ', keywords = ';
+ $keywords_array = get_keywords( $_POST[$keywords] );
+ if ( count( $keywords_array ) == 0 )
+ $query.= 'NULL';
+ else
{
- $query.= ', date_creation = NULL';
+ $query.= '"';
+ foreach ( $keywords_array as $i => $keyword ) {
+ if ( $i > 0 ) $query.= ',';
+ $query.= $keyword;
+ }
+ $query.= '"';
}
+
$query.= ' WHERE id = '.$row['id'];
$query.= ';';
mysql_query( $query );
@@ -147,6 +172,27 @@ if ( isset( $page['cat'] ) )
echo $lang['err_date'];
}
}
+ if ( $_POST['use_common_keywords'] == 1 )
+ {
+ $keywords = get_keywords( $_POST['keywords_cat'] );
+ $query = 'UPDATE '.PREFIX_TABLE.'images';
+ if ( count( $keywords ) == 0 )
+ {
+ $query.= ' SET keywords = NULL';
+ }
+ else
+ {
+ $query.= ' SET keywords = "';
+ foreach ( $keywords as $i => $keyword ) {
+ if ( $i > 0 ) $query.= ',';
+ $query.= $keyword;
+ }
+ $query.= '"';
+ }
+ $query.= ' WHERE cat_id = '.$page['cat'];
+ $query.= ';';
+ mysql_query( $query );
+ }
//--------------------------------------------------------- form initialization
$page['nb_image_page'] = 5;
@@ -178,7 +224,7 @@ if ( isset( $page['cat'] ) )
$tpl = array( 'infoimage_general','author','infoimage_useforall','submit',
'infoimage_creation_date','infoimage_detailed','thumbnail',
'infoimage_title','infoimage_comment',
- 'infoimage_creation_date' );
+ 'infoimage_creation_date','infoimage_keywords' );
templatize_array( $tpl, 'lang', $sub );
//------------------------------------------------------------------------ form
$url = './admin.php?page=infos_images&amp;cat_id='.$page['cat'];
@@ -190,7 +236,7 @@ if ( isset( $page['cat'] ) )
$cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;');
$vtp->setVar( $sub, 'cat_name', $cat_name );
- $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation';
+ $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords';
$query.= ' FROM '.PREFIX_TABLE.'images';
$query.= ' WHERE cat_id = '.$page['cat'];
$query.= $conf['order_by'];
@@ -205,6 +251,7 @@ if ( isset( $page['cat'] ) )
$vtp->setVar( $sub, 'picture.name', $row['name'] );
$vtp->setVar( $sub, 'picture.author', $row['author'] );
$vtp->setVar( $sub, 'picture.comment', $row['comment'] );
+ $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] );
$vtp->setVar( $sub, 'picture.date_creation',
date_convert_back( $row['date_creation'] ) );
$file = get_filename_wo_extension( $row['file'] );
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 989349466..f0b825381 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -421,7 +421,7 @@ function initialize_category( $calling_page = 'category' )
}
$page['where'] = ' WHERE (';
- $fields = array( 'file', 'name', 'comment' );
+ $fields = array( 'file', 'name', 'comment', 'keywords' );
$words = explode( ',', $_GET['search'] );
$sql_search = array();
foreach ( $words as $i => $word ) {
diff --git a/language/francais.php b/language/francais.php
index cba6596c4..b6f29a012 100644
--- a/language/francais.php
+++ b/language/francais.php
@@ -492,6 +492,7 @@ if ( $isadmin )
// page info images
// start version 1.3
// $lang['infoimage_err_date'] = 'date erronée';
+ $lang['infoimage_keywords'] = 'mots-clefs';
// end version 1.3
$lang['infoimage_general'] = 'Options générale pour la catégorie';
$lang['infoimage_useforall'] = 'utiliser pour toutes les images ?';
diff --git a/template/default/admin/infos_image.vtp b/template/default/admin/infos_image.vtp
index b5174628e..bd6aeea46 100644
--- a/template/default/admin/infos_image.vtp
+++ b/template/default/admin/infos_image.vtp
@@ -25,13 +25,25 @@
{#infoimage_useforall}
</td>
</tr>
+ <tr>
+ <td>
+ <div style="margin-left:50px;">{#infoimage_keywords}</div>
+ </td>
+ <td style="text-align:center;">
+ <input type="text" name="keywords_cat" value="" size="12" maxlength="255" />
+ </td>
+ <td style="text-align:left;">
+ <input type="checkbox" name="use_common_keywords" value="1" />
+ {#infoimage_useforall}
+ </td>
+ </tr>
</table>
<table width="100%">
<tr>
- <th colspan="5">{#infoimage_detailed}</th>
+ <th colspan="6">{#infoimage_detailed}</th>
</tr>
<tr>
- <td colspan="5" align="center">{#navigation_bar}</td>
+ <td colspan="6" align="center">{#navigation_bar}</td>
</tr>
<tr>
<td class="row2" style="text-align:center;">{#thumbnail}</td>
@@ -39,6 +51,7 @@
<td class="row2" style="text-align:center;">{#author}</td>
<td class="row2" style="text-align:center;">{#infoimage_comment}</td>
<td class="row2" style="text-align:center;">{#infoimage_creation_date}</td>
+ <td class="row2" style="text-align:center;">{#infoimage_keywords}</td>
</tr>
<!--VTP_picture-->
<tr>
@@ -47,10 +60,11 @@
<td style="text-align:center;"><input type="text" name="author-{#id}" value="{#author}" maxlength="255"/></td>
<td style="text-align:center;"><textarea name="comment-{#id}" rows="3" cols="40" style="overflow:auto">{#comment}</textarea></td>
<td style="text-align:center;"><input type="text" name="date_creation-{#id}" value="{#date_creation}" maxlength="10" size="12" /></td>
+ <td style="text-align:center;"><input type="text" name="keywords-{#id}" value="{#keywords}" maxlength="255" /></td>
</tr>
<!--/VTP_picture-->
<tr>
- <td colspan="5" style="text-align:center;">
+ <td colspan="6" style="text-align:center;">
<input type="submit" value="{#submit}" name="submit" />
</td>
</tr>