source: trunk/admin/infos_images.php @ 34

Last change on this file since 34 was 33, checked in by z0rglub, 21 years ago

Support of keywords for pictures. They are used in the search

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1<?php
2/***************************************************************************
3 *                             infos_images.php                            *
4 *                            ------------------                           *
5 *   application          : PhpWebGallery 1.3                              *
6 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
7 *                                                                         *
8 ***************************************************************************/
9
10/***************************************************************************
11 *                                                                         *
12 *   This program is free software; you can redistribute it and/or modify  *
13 *   it under the terms of the GNU General Public License as published by  *
14 *   the Free Software Foundation;                                         *
15 *                                                                         *
16 ***************************************************************************/
17
18include_once( './include/isadmin.inc.php' );
19include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' );
20//------------------------------------------------------------------- functions
21function check_date_format( $date )
22{
23  // date arrives at this format : DD/MM/YYYY
24  list($day,$month,$year) = explode( '/', $date );
25  return checkdate ( $month, $day, $year );
26}
27
28function date_convert( $date )
29{
30  // date arrives at this format : DD/MM/YYYY
31  // It must be transformed in YYYY-MM-DD
32  list($day,$month,$year) = explode( '/', $date );
33  return $year.'-'.$month.'-'.$day;
34}
35
36function date_convert_back( $date )
37{
38  // date arrives at this format : YYYY-MM-DD
39  // It must be transformed in DD/MM/YYYY
40  if ( $date != '' )
41  {
42    list($year,$month,$day) = explode( '-', $date );
43    return $day.'/'.$month.'/'.$year;
44  }
45  else
46  {
47    return '';
48  }
49}
50
51// get_keywords returns an array with relevant keywords found in the string
52// given in argument. Keywords must be separated by comma in this string.
53// keywords must :
54//   - be longer or equal to 3 characters
55//   - not contain ', " or blank characters
56//   - unique in the string ("test,test" -> "test")
57function get_keywords( $keywords_string )
58{
59  $keywords = array();
60
61  $candidates = explode( ',', $keywords_string );
62  foreach ( $candidates as $candidate ) {
63    if ( strlen($candidate) >= 3 and !preg_match( '/(\'|"|\s)/', $candidate ) )
64      array_push( $keywords, $candidate );
65  }
66
67  return array_unique( $keywords );
68}
69//-------------------------------------------------------------- initialization
70check_cat_id( $_GET['cat_id'] );
71
72if ( isset( $page['cat'] ) )
73{
74//--------------------------------------------------- update individual options
75  $query = 'SELECT id,file';
76  $query.= ' FROM '.PREFIX_TABLE.'images';
77  $query.= ' WHERE cat_id = '.$page['cat'];
78  $query.= ';';
79  $result = mysql_query( $query );
80  $i = 1;
81  while ( $row = mysql_fetch_array( $result ) )
82  {
83    $name          = 'name-'.$row['id'];
84    $author        = 'author-'.$row['id'];
85    $comment       = 'comment-'.$row['id'];
86    $date_creation = 'date_creation-'.$row['id'];
87    $keywords      = 'keywords-'.$row['id'];
88    if ( isset( $_POST[$name] ) )
89    {
90      $query = 'UPDATE '.PREFIX_TABLE.'images';
91
92      $query.= ' SET name = ';
93      if ( $_POST[$name] == '' )
94        $query.= 'NULL';
95      else
96        $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
97
98      $query.= ', author = ';
99      if ( $_POST[$author] == '' )
100        $query.= 'NULL';
101      else
102        $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
103
104      $query.= ', comment = ';
105      if ( $_POST[$comment] == '' )
106        $query.= 'NULL';
107      else
108        $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
109
110      $query.= ', date_creation = ';
111      if ( check_date_format( $_POST[$date_creation] ) )
112        $query.= "'".date_convert( $_POST[$date_creation] )."'";
113      else if ( $_POST[$date_creation] == '' )
114        $query.= 'NULL';
115
116      $query.= ', keywords = ';
117      $keywords_array = get_keywords( $_POST[$keywords] );
118      if ( count( $keywords_array ) == 0 )
119        $query.= 'NULL';
120      else
121      {
122        $query.= '"';
123        foreach ( $keywords_array as $i => $keyword ) {
124          if ( $i > 0 ) $query.= ',';
125          $query.= $keyword;
126        }
127        $query.= '"';
128      }
129
130      $query.= ' WHERE id = '.$row['id'];
131      $query.= ';';
132      mysql_query( $query );
133    }
134  }
135//------------------------------------------------------ update general options
136  if ( $_POST['use_common_author'] == 1 )
137  {
138    $query = 'UPDATE '.PREFIX_TABLE.'images';
139    if ( $_POST['author_cat'] == '' )
140    {
141      $query.= ' SET author = NULL';
142    }
143    else
144    {
145      $query.= ' SET author = ';
146      $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'";
147    }
148    $query.= ' WHERE cat_id = '.$page['cat'];
149    $query.= ';';
150    mysql_query( $query );
151  }
152  if ( $_POST['use_common_date_creation'] == 1 )
153  {
154    if ( check_date_format( $_POST['date_creation_cat'] ) )
155    {
156      $date = date_convert( $_POST['date_creation_cat'] );
157      $query = 'UPDATE '.PREFIX_TABLE.'images';
158      if ( $_POST['date_creation_cat'] == '' )
159      {
160        $query.= ' SET date_creation = NULL';
161      }
162      else
163      {
164        $query.= " SET date_creation = '".$date."'";
165      }
166      $query.= ' WHERE cat_id = '.$page['cat'];
167      $query.= ';';
168      mysql_query( $query );
169    }
170    else
171    {
172      echo $lang['err_date'];
173    }
174  }
175  if ( $_POST['use_common_keywords'] == 1 )
176  {
177    $keywords = get_keywords( $_POST['keywords_cat'] );
178    $query = 'UPDATE '.PREFIX_TABLE.'images';
179    if ( count( $keywords ) == 0 )
180    {
181      $query.= ' SET keywords = NULL';
182    }
183    else
184    {
185      $query.= ' SET keywords = "';
186      foreach ( $keywords as $i => $keyword ) {
187        if ( $i > 0 ) $query.= ',';
188        $query.= $keyword;
189      }
190      $query.= '"';
191    }
192    $query.= ' WHERE cat_id = '.$page['cat'];
193    $query.= ';';
194    mysql_query( $query );
195  }
196//--------------------------------------------------------- form initialization
197  $page['nb_image_page'] = 5;
198
199  if( !isset( $_GET['start'] )
200      or !is_numeric( $_GET['start'] )
201      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
202  {
203    $page['start'] = 0;
204  }
205  else
206  {
207    $page['start'] = $_GET['start'];
208  }
209
210  if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 )
211  {
212    $page['start'] =
213      floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page'];
214  }
215  // retrieving category information
216  $result = get_cat_info( $page['cat'] );
217  $cat['local_dir'] = $result['local_dir'];
218  $cat['dir'] = $result['dir'];
219  $cat['name'] = $result['name'];
220  $cat['site_id'] = $result['site_id'];
221  $cat['nb_images'] = $result['nb_images'];
222//----------------------------------------------------- template initialization
223  $sub = $vtp->Open('../template/'.$user['template'].'/admin/infos_image.vtp');
224  $tpl = array( 'infoimage_general','author','infoimage_useforall','submit',
225                'infoimage_creation_date','infoimage_detailed','thumbnail',
226                'infoimage_title','infoimage_comment',
227                'infoimage_creation_date','infoimage_keywords' );
228  templatize_array( $tpl, 'lang', $sub );
229//------------------------------------------------------------------------ form
230  $url = './admin.php?page=infos_images&amp;cat_id='.$page['cat'];
231  $url.= '&amp;start='.$page['start'];
232  $vtp->setVar( $sub, 'form_action', add_session_id( $url ) ); 
233  $page['navigation_bar'] = create_navigation_bar(
234    $url, $cat['nb_images'],$page['start'], $page['nb_image_page'], '' );
235  $vtp->setVar( $sub, 'navigation_bar', $page['navigation_bar'] );
236  $cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;');
237  $vtp->setVar( $sub, 'cat_name', $cat_name );
238
239  $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords';
240  $query.= ' FROM '.PREFIX_TABLE.'images';
241  $query.= ' WHERE cat_id = '.$page['cat'];
242  $query.= $conf['order_by'];
243  $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
244  $query.= ';';
245  $result = mysql_query( $query );
246  while ( $row = mysql_fetch_array( $result ) )
247  {
248    $vtp->addSession( $sub, 'picture' );
249    $vtp->setVar( $sub, 'picture.id', $row['id'] );
250    $vtp->setVar( $sub, 'picture.filename', $row['file'] );
251    $vtp->setVar( $sub, 'picture.name', $row['name'] );
252    $vtp->setVar( $sub, 'picture.author', $row['author'] );
253    $vtp->setVar( $sub, 'picture.comment', $row['comment'] );
254    $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] );
255    $vtp->setVar( $sub, 'picture.date_creation',
256                  date_convert_back( $row['date_creation'] ) );
257    $file = get_filename_wo_extension( $row['file'] );
258    $vtp->setVar( $sub, 'picture.default_name', $file );
259    // creating url to thumbnail
260    if ( $cat['site_id'] == 1 )
261    { 
262      $thumbnail_url = '../galleries/'.$cat['local_dir'].'/';
263    }
264    else
265    {
266      $thumbnail_url = $cat['dir'];
267    }
268    $thumbnail_url.= 'thumbnail/';
269    $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
270    $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url );
271    $url = '../picture.php?cat='.$_GET['cat_id'].'&amp;image_id='.$row['id'];
272    $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) );
273    $vtp->closeSession( $sub, 'picture' );
274  }
275}
276//----------------------------------------------------------- sending html code
277$vtp->Parse( $handle , 'sub', $sub );
278?>
Note: See TracBrowser for help on using the repository browser.