source: trunk/picture.php @ 375

Last change on this file since 375 was 375, checked in by gweltas, 20 years ago

New default template - User side

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 19.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                              picture.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-02-26 18:33:45 +0000 (Thu, 26 Feb 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 375 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27//----------------------------------------------------------- include
28define('PHPWG_ROOT_PATH','./');
29include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );   
30//-------------------------------------------------- access authorization check
31check_cat_id( $_GET['cat'] );
32check_login_authorization();
33if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
34{
35  check_restrictions( $page['cat'] );
36}
37//---------------------------------------- incrementation of the number of hits
38$query = 'UPDATE '.IMAGES_TABLE.' SET hit=hit+1';
39$query.= ' WHERE id='.$_GET['image_id'];
40$query.= ';';
41@mysql_query( $query );
42//-------------------------------------------------------------- initialization
43initialize_category( 'picture' );
44
45// if this image_id doesn't correspond to this category, an error message is
46// displayed, and execution is stopped
47if ( 0 )
48{
49  echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
50  echo '<a href="'.add_session_id( './category.php' ).'">';
51  echo $lang['thumbnails'].'</a></div>';
52  exit();
53}
54
55// retrieving the number of the picture in its category (in order)
56$query = 'SELECT DISTINCT(id)';
57$query.= ' FROM '.IMAGES_TABLE;
58$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
59$query.= ' ON id = ic.image_id';
60$query.= $page['where'];
61$query.= $conf['order_by'];
62$query.= ';';
63$result = mysql_query( $query );
64$page['num'] = 0;
65$row = mysql_fetch_array( $result );
66while ( $row['id'] != $_GET['image_id'] )
67{
68  $page['num']++;
69  $row = mysql_fetch_array( $result );
70}
71
72//---------------------------------------- prev, current & next picture management
73$picture=array();
74$picture['prev']['name']='';
75$picture['next']['name']='';
76$picture['prev']['thumbnail']='';
77$picture['next']['thumbnail']='';
78$picture['prev']['url']='';
79$picture['next']['url']='';
80
81$next = $page['num'] + 1;
82$prev = $page['num'] - 1;
83
84if ( $page['num'] == $page['cat_nb_images']-1)
85{
86  $next = 0;
87}
88
89$query = 'SELECT * FROM '.IMAGES_TABLE;
90$query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic';
91$query.= ' ON id=ic.image_id';
92$query.= $page['where'];
93$query.= $conf['order_by'];
94
95if ($prev <0)
96  $query.= ' LIMIT 0,2';
97else
98  $query.= ' LIMIT '.$prev.',3';
99 
100$query.= ';';
101
102$result = mysql_query( $query );
103$nb_row = mysql_num_rows($result);
104$index = array('prev','current','next');
105for ($i=0; $i<$nb_row;$i++)
106{
107  $j=($prev<0)?$index[$i+1]:$index[$i];
108  $row = mysql_fetch_array($result);
109  $picture[$j] = $row;
110 
111  if ( !isset($array_cat_directories[$row['storage_category_id']]))
112  {
113    $array_cat_directories[$row['storage_category_id']] =
114      get_complete_dir( $row['storage_category_id'] );
115  }
116  $cat_directory = $array_cat_directories[$row['storage_category_id']];
117  $file = substr ( $row['file'], 0, strrpos ( $row['file'], ".") );
118  $picture[$j]['src'] = $cat_directory.$row['file'];
119  $picture[$j]['thumbnail'] = $cat_directory.'thumbnail/';
120  $picture[$j]['thumbnail'].= $conf['prefix_thumbnail'].$file.".".$row['tn_ext'];
121 
122  if (!empty($row['name']))
123  {
124    $picture[$j]['name'] = $row['name'];
125  }
126  else
127  {
128    $picture[$j]['name'] = str_replace( "_", " ",$file);
129  }
130
131  $picture[$j]['url'] = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id'];
132  $picture[$j]['url'].= '&amp;cat='.$page['cat'];
133  if ( isset( $_GET['expand'] ) )
134    $picture[$j]['url'].= '&amp;expand='.$_GET['expand'];
135  if ( $page['cat'] == 'search' )
136  {
137    $picture[$j]['url'].= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
138  }
139}
140
141$url_home = './category.php?cat='.$page['cat'].'&amp;';
142$url_home.= 'num='.$page['num']; 
143if (isset($_GET['expand']))
144        $url_home.='&amp;expand='.$_GET['expand'];
145if ( $page['cat'] == 'search' )
146{
147  $url_home.= "&amp;search=".$_GET['search'].'&amp;mode='.$_GET['mode'];
148}
149
150$url_admin = PHPWG_ROOT_PATH.'admin.php?page=picture_modify&amp;cat_id='.$page['cat'];
151$url_admin.= '&amp;image_id='.$_GET['image_id'];
152 
153//--------------------------------------------------------- favorite management
154if ( isset( $_GET['add_fav'] ) )
155{
156  $query = 'DELETE FROM '.FAVORITES_TABLE.' WHERE user_id = '.$user['id'];
157  $query.= ' AND image_id = '.$picture['current']['id'].';';
158  $result = mysql_query( $query );
159 
160  if ( $_GET['add_fav'] == 1 )
161  {
162    $query = 'INSERT INTO '.FAVORITES_TABLE.' (image_id,user_id) VALUES';
163    $query.= ' ('.$picture['current']['id'].','.$user['id'].');';
164        $result = mysql_query( $query );
165  }
166  if ( !$_GET['add_fav'] && $page['cat']=='fav')
167  {
168    if ( $prev < 0 && $nb_row==1 )
169    {
170      // there is no favorite picture anymore
171      // we redirect the user to the category page
172      $url = add_session_id( $url_home );
173      header( 'Request-URI: '.$url );
174      header( 'Content-Location: '.$url ); 
175      header( 'Location: '.$url );
176      exit();
177    }
178        else if ( $prev < 0 )
179        {
180          $url = add_session_id( str_replace('&amp;','&',$picture['next']['url']), true);
181        }
182        else
183        {
184          $url = add_session_id( str_replace('&amp;','&',$picture['prev']['url']), true);
185        }
186        header( 'Request-URI: '.$url );
187        header( 'Content-Location: '.$url ); 
188        header( 'Location: '.$url );
189        exit();
190  }
191}
192
193//
194// Start output of page
195//
196
197$title =  $picture['current']['name'];
198$refresh = 0;
199if ( isset( $_GET['slideshow'] ) && $next) 
200{
201        $refresh= $_GET['slideshow'];
202        $url_link = $picture['next']['url'];
203}
204
205$title_img = $picture['current']['name'];
206$title_nb = '';
207if (is_numeric( $page['cat'] )) 
208{
209  $title_img = replace_space(get_cat_display_name( $page['cat_name'], " &gt; ","font-style:italic;" ));
210  $n = $page['num'] + 1;
211  $title_nb = "Photo".' '.$n.'/';
212  $title_nb.= $page['cat_nb_images'];
213  //$title_img.= $picture['current']['name'];
214}
215else if ( $page['cat'] == 'search' )
216{
217  $title_img = replace_search( $title_img, $_GET['search'] );
218}
219
220// calculation of width and height
221if ( empty($picture['current']['width']))
222{
223  $taille_image = @getimagesize( $lien_image );
224  $original_width = $taille_image[0];
225  $original_height = $taille_image[1];
226}
227else
228{
229  $original_width = $picture['current']['width'];
230  $original_height = $picture['current']['height'];
231}
232
233$picture_size = get_picture_size( $original_width, $original_height,
234                                  $user['maxwidth'], $user['maxheight'] );
235                                 
236include(PHPWG_ROOT_PATH.'include/page_header.php');
237$template->set_filenames(array('picture'=>'picture.tpl'));
238initialize_template();
239
240$template->assign_vars(array(
241  'CATEGORY' => $title_img,
242  'PHOTO' => $title_nb,
243  'TITLE' => $picture['current']['name'],
244  'PREV_TITLE_IMG' => $picture['prev']['name'],
245  'NEXT_TITLE_IMG' => $picture['next']['name'],
246  'PREV_IMG' => $picture['prev']['thumbnail'],
247  'NEXT_IMG' => $picture['next']['thumbnail'],
248  'SRC_IMG' => $picture['current']['src'],
249  'ALT_IMG' => $picture['current']['file'],
250  'WIDTH_IMG' => $picture_size[0],
251  'HEIGHT_IMG' => $picture_size[1],
252  'COMMENT_IMG' => $picture['current']['comment'],
253
254  'L_SLIDESHOW' => $lang['slideshow'],
255  'L_TIME' => $lang['period_seconds'],
256  'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
257  'L_PREV_IMG' =>$lang['previous_image'].' : ',
258  'L_ADMIN' =>$lang['link_info_image'],
259  'L_BACK' =>$lang['back'],
260  'L_COMMENT_TITLE' =>$lang['comments_title'],
261  'L_ADD_COMMENT' =>$lang['comments_add'],
262  'L_DELETE_COMMENT' =>$lang['comments_del'],
263  'L_DELETE' =>$lang['delete'],
264  'L_SUBMIT' =>$lang['submit'],
265  'L_AUTHOR' =>$lang['author'],
266 
267  'T_DEL_IMG' =>'./template/'.$user['template'].'/theme/delete.gif',
268 
269  'U_PREV_IMG' => add_session_id($picture['prev']['url']),
270  'U_NEXT_IMG' => add_session_id($picture['next']['url']),
271  'U_HOME' => add_session_id($url_home),
272  'U_ADMIN' => add_session_id($url_admin),
273  'U_ADD_COMMENT' => add_session_id(str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] ))
274  )
275);
276
277//-------------------------------------------------------- slideshow management
278if ( isset( $_GET['slideshow'] ) )
279{
280  if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'][0];
281       
282  $template->assign_block_vars('stop_slideshow', array(
283  'U_SLIDESHOW'=>add_session_id( $picture['current']['url'] )
284  ));
285}
286else
287{
288  $template->assign_block_vars('start_slideshow', array());
289  foreach ( $conf['slideshow_period'] as $option ) 
290  {
291    $template->assign_block_vars('start_slideshow.second', array(
292          'SLIDESHOW_SPEED'=>$option,
293          'U_SLIDESHOW'=>add_session_id( $picture['current']['url'].'&amp;slideshow='.$option)
294          ));
295  }
296}
297
298if ($prev>=0) $template->assign_block_vars('previous', array());
299if ($next) $template->assign_block_vars('next', array());
300
301//--------------------------------------------------------- picture information
302// author
303if ( !empty($picture['current']['author']) )
304{
305  $template->assign_block_vars('info_line', array(
306          'INFO'=>$lang['author'],
307          'VALUE'=>$picture['current']['author']
308          ));
309}
310// creation date
311if ( !empty($picture['current']['date_creation']) )
312{
313  $template->assign_block_vars('info_line', array(
314          'INFO'=>$lang['creation_date'],
315          'VALUE'=>format_date( $picture['current']['date_creation'] ) 
316          ));
317}
318// date of availability
319$template->assign_block_vars('info_line', array(
320          'INFO'=>$lang['registration_date'],
321          'VALUE'=>format_date( $picture['current']['date_available'] ) 
322          ));
323// size in pixels
324if ( $original_width != $picture_size[0] or $original_height != $picture_size[1] )
325{
326  $content = '[ <a href="'.$picture['current']['url'].'" title="'.$lang['true_size'].'">';
327  $content.= $original_width.'*'.$original_height.'</a> ]';
328}
329else
330{
331  $content = $original_width.'*'.$original_height;
332}
333$template->assign_block_vars('info_line', array(
334          'INFO'=>$lang['size'],
335          'VALUE'=>$content 
336          ));
337// file
338$template->assign_block_vars('info_line', array(
339          'INFO'=>$lang['file'],
340          'VALUE'=>$picture['current']['file'] 
341          ));
342// filesize
343if ( empty($picture['current']['filesize']))
344{
345  $poids = floor ( filesize( $picture['current']['url'] ) / 1024 );
346}
347else
348{
349  $poids = $picture['current']['filesize'];
350}
351
352$template->assign_block_vars('info_line', array(
353          'INFO'=>$lang['filesize'],
354          'VALUE'=>$poids.' KB'
355          ));
356// keywords
357if ( !empty($picture['current']['keywords']))
358{
359  $keywords = explode( ',', $picture['current']['keywords'] );
360  $content = '';
361  $url = './category.php?cat=search';
362  if ( isset( $_GET['expand'] ) ) $url.= '&amp;expand='.$_GET['expand'];
363  $url.= '&amp;mode=OR&amp;search=';
364  foreach ( $keywords as $i => $keyword ) {
365    $local_url = add_session_id( $url.$keyword );
366    if ( $i > 0 ) $content.= ',';
367    $content.= '<a href="'.$local_url.'">'.$keyword.'</a>';
368  }
369  $template->assign_block_vars('info_line', array(
370    'INFO'=>$lang['keywords'],
371    'VALUE'=>$content
372    ));
373}
374// number of visits
375$template->assign_block_vars('info_line', array(
376    'INFO'=>$lang['visited'],
377    'VALUE'=>$picture['current']['hit'].' '.$lang['times']
378    ));
379
380//------------------------------------------------------- favorite manipulation
381if ( !$user['is_the_guest'] )
382{
383  // verify if the picture is already in the favorite of the user
384  $query = 'SELECT COUNT(*) AS nb_fav';
385  $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
386  $query.= ' AND user_id = '.$user['id'].';';
387  $result = mysql_query( $query );
388  $row = mysql_fetch_array( $result );
389  if (!$row['nb_fav'])
390  {
391    $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$_GET['image_id'];
392    if (isset($_GET['expand']))
393      $url.= '&amp;expand='.$_GET['expand'];
394    $url.='&amp;add_fav=1';
395    if ( $page['cat'] == 'search' )
396    {
397      $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
398    }
399        $template->assign_block_vars('favorite', array(
400      'FAVORITE_IMG' => './template/'.$user['template'].'/theme/favorite.gif',
401          'FAVORITE_HINT' =>$lang['add_favorites_hint'],
402          'FAVORITE_ALT' =>'[ '.$lang['add_favorites_alt'].' ]',
403      'U_FAVORITE'=> add_session_id( $url )
404    ));
405  }
406  else
407  {
408    $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$_GET['image_id'];
409    $url.= '&amp;expand='.$_GET['expand'].'&amp;add_fav=0';
410        $template->assign_block_vars('favorite', array(
411      'FAVORITE_IMG' => './template/'.$user['template'].'/theme/del_favorite.gif',
412          'FAVORITE_HINT' =>$lang['del_favorites_hint'],
413          'FAVORITE_ALT' =>'[ '.$lang['del_favorites_alt'].' ]',
414      'U_FAVORITE'=> add_session_id( $url )
415    ));
416  }
417}
418//------------------------------------ admin link for information modifications
419if ( $user['status'] == 'admin' )
420{
421  $template->assign_block_vars('modification', array());
422}
423
424//---------------------------------------------------- users's comments display
425if ( $conf['show_comments'] )
426{
427  // comment registeration
428  if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
429  {
430    $register_comment = true;
431        $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
432    // if a guest try to use the name of an already existing user, he must
433    // be rejected
434    if ( $author != $user['username'] )
435    {
436      $query = 'SELECT COUNT(*) AS user_exists';
437      $query.= ' FROM '.USERS_TABLE;
438      $query.= " WHERE username = '".$author."'";
439      $query.= ';';
440      $row = mysql_fetch_array( mysql_query( $query ) );
441      if ( $row['user_exists'] == 1 )
442      {
443            $template->assign_block_vars('information', array('INFORMATION'=>$lang['comment_user_exists']));
444        $register_comment = false;
445      }
446    }
447
448    if ( $register_comment )
449    {
450      // anti-flood system
451      $reference_date = time() - $conf['anti-flood_time'];
452      $query = 'SELECT id FROM '.COMMENTS_TABLE;
453      $query.= ' WHERE date > '.$reference_date;
454      $query.= " AND author = '".$author."'";
455      $query.= ';';
456      if ( mysql_num_rows( mysql_query( $query ) ) == 0
457           || $conf['anti-flood_time'] == 0 )
458      {
459        $query = 'INSERT INTO '.COMMENTS_TABLE;
460        $query.= ' (author,date,image_id,content,validated) VALUES (';
461                $query.= "'".$author."'";
462        $query.= ','.time().','.$_GET['image_id'];
463        $query.= ",'".htmlspecialchars( $_POST['content'], ENT_QUOTES)."'";
464        if ( !$conf['comments_validation'] || $user['status'] == 'admin' )
465          $query.= ",'true'";
466        else
467          $query.= ",'false'";
468        $query.= ');';
469        mysql_query( $query );
470        // information message
471        $message = $lang['comment_added'];
472        if ( $conf['comments_validation'] and $user['status'] != 'admin' )
473        {
474          $message.= '<br />'.$lang['comment_to_validate'];
475        }
476        $template->assign_block_vars('information', array('INFORMATION'=>$message));
477        // notification to the administrators
478        if ( $conf['mail_notification'] )
479        {
480          $cat_name = get_cat_display_name( $page['cat_name'], ' > ', '' );
481          $cat_name = strip_tags( $cat_name );
482          notify( 'comment', $cat_name.' > '.$picture['current']['name']);
483        }
484      }
485      else
486      {
487        // information message
488        $template->assign_block_vars('information', array('INFORMATION'=>$lang['comment_anti-flood']));
489      }
490    }
491  }
492  // comment deletion
493  if ( isset( $_GET['del'] )
494       && is_numeric( $_GET['del'] )
495       && $user['status'] == 'admin' )
496  {
497    $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id = '.$_GET['del'].';';
498    mysql_query( $query );
499  }
500  // number of comment for this picture
501  $query = 'SELECT COUNT(*) AS nb_comments';
502  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
503  $query.= " AND validated = 'true'";
504  $query.= ';';
505  $row = mysql_fetch_array( mysql_query( $query ) );
506 
507  // navigation bar creation
508  $url = './picture.php?cat='.$page['cat'].'&amp;image_id='.$_GET['image_id'];
509  if (isset($_GET['expand']))
510        $url.= '&amp;expand='.$_GET['expand'];
511  if ( $page['cat'] == 'search' )
512  {
513    $url.= '&amp;search='.$_GET['search'].'&amp;mode='.$_GET['mode'];
514  }
515  if( !isset( $_GET['start'] )
516      or !is_numeric( $_GET['start'] )
517      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
518  {
519    $page['start'] = 0;
520  }
521  else
522  {
523    $page['start'] = $_GET['start'];
524  }
525  $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
526                                                   $page['start'],
527                                                   $conf['nb_comment_page'],
528                                                   '' );
529  $template->assign_block_vars('comments', array(
530    'NB_COMMENT'=>$row['nb_comments'],
531    'NAV_BAR'=>$page['navigation_bar']));
532
533  $query = 'SELECT id,author,date,image_id,content';
534  $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
535  $query.= " AND validated = 'true'";
536  $query.= ' ORDER BY date ASC';
537  $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
538  $result = mysql_query( $query );
539               
540  while ( $row = mysql_fetch_array( $result ) )
541  {
542    $content = nl2br( $row['content'] );
543
544    // replace _word_ by an underlined word
545    $pattern = '/_([^\s]*)_/';
546    $replacement = '<span style="text-decoration:underline;">\1</span>';
547    $content = preg_replace( $pattern, $replacement, $content );
548
549    // replace *word* by a bolded word
550    $pattern = '/\*([^\s]*)\*/';
551    $replacement = '<span style="font-weight:bold;">\1</span>';
552    $content = preg_replace( $pattern, $replacement, $content );
553
554    // replace /word/ by an italic word
555    $pattern = '/\/([^\s]*)\//';
556    $replacement = '<span style="font-style:italic;">\1</span>';
557    $content = preg_replace( $pattern, $replacement, $content );
558       
559    $template->assign_block_vars('comments.comment', array(
560    'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
561    'COMMENT_DATE'=>format_date( $row['date'], 'unix', true ),
562        'COMMENT'=>$content
563        ));
564       
565    if ( $user['status'] == 'admin' )
566    {
567          $template->assign_block_vars('comments.comment.delete', array('U_COMMENT_DELETE'=>add_session_id( $url.'&amp;del='.$row['id'] )));
568    }
569  }
570
571  if ( !$user['is_the_guest']||( $user['is_the_guest'] and $conf['comments_forall'] ) )
572  {
573    $template->assign_block_vars('comments.add_comment', array());
574    // display author field if the user is not logged in
575    if ( !$user['is_the_guest'] )
576    {
577      $template->assign_block_vars('comments.add_comment.author_known', array('KNOWN_AUTHOR'=>$user['username']));
578        }
579    else
580    {
581      $template->assign_block_vars('comments.add_comment.author_field', array());
582    }
583  }
584}
585//------------------------------------------------------------ log informations
586pwg_log( 'picture', $title_img, $picture['current']['file'] );
587mysql_close();
588
589$template->pparse('picture');
590include(PHPWG_ROOT_PATH.'include/page_tail.php');
591?>
Note: See TracBrowser for help on using the repository browser.