source: trunk/comments.php @ 345

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

Merge of the 1.3.1 release
Creation of an unique include file (common.php)
Creation of an unique define file (include/constants.php)
Modification of the installation procedure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.2 KB
Line 
1<?php
2/***************************************************************************
3 *                               comments.php                              *
4 *                            -------------------                          *
5 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
6 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
7 *                                                                         *
8 *   $Id: comments.php 345 2004-02-02 00:55:18Z gweltas $
9 *                                                                         *
10 ***************************************************************************/
11
12/***************************************************************************
13 *                                                                         *
14 *   This program is free software; you can redistribute it and/or modify  *
15 *   it under the terms of the GNU General Public License as published by  *
16 *   the Free Software Foundation;                                         *
17 *                                                                         *
18 ***************************************************************************/
19
20//----------------------------------------------------------- include
21$phpwg_root_path = './';
22include_once( $phpwg_root_path.'common.php' );
23
24//------------------------------------------------------------------- functions
25function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
26{
27  global $vtp,$handle,$lang,$conf,
28    $array_cat_directories,$array_cat_site_id,$array_cat_names;
29
30  while ( $row = mysql_fetch_array( $mysql_result ) )
31  {
32    $vtp->addSession( $handle, 'picture' );
33    // 1. find a category wich is authorized for the user to display a
34    //    category name.
35    $query = 'SELECT category_id';
36    $query.= ' FROM '.PREFIX_TABLE.'image_category';
37    $query.= ' WHERE image_id = '.$row['image_id'];
38    if ( count( $forbidden_cat_ids ) > 0 )
39    {
40      $query.= ' AND category_id NOT IN (';
41      foreach ( $forbidden_cat_ids as $i => $restricted_cat ) {
42        if ( $i > 0 ) $query.= ',';
43        $query.= $restricted_cat;
44      }
45      $query.= ')';
46    }
47    $query.= ' ORDER BY RAND()';
48    $query.= ';';
49    $subrow = mysql_fetch_array( mysql_query( $query ) );
50    $category_id = $subrow['category_id'];
51
52    if ( !isset($array_cat_directories[$category_id]))
53    {
54      $array_cat_directories[$category_id] =
55        get_complete_dir( $category_id );
56      $cat_result = get_cat_info( $category_id );
57      $array_cat_site_id[$category_id] = $cat_result['site_id'];
58      $array_cat_names[$category_id] =
59        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
60    }
61   
62    // 2. for each picture, getting informations for displaying thumbnail and
63    //    link to the full size picture
64    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
65    $query.= ' FROM '.PREFIX_TABLE.'images';
66    $query.= ' WHERE id = '.$row['image_id'];
67    $query.= ';';
68    $subresult = mysql_query( $query );
69    $subrow = mysql_fetch_array( $subresult );
70
71    if ( $array_cat_directories[$subrow['cat_id']] == '' )
72    {
73      $array_cat_directories[$subrow['cat_id']] =
74        get_complete_dir( $subrow['cat_id'] );
75      $cat_result = get_cat_info( $subrow['cat_id'] );
76      $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
77      $array_cat_names[$subrow['cat_id']] =
78        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
79    }
80
81    $file = get_filename_wo_extension( $subrow['file'] );
82    // name of the picture
83    $name = $array_cat_names[$category_id].' &gt; ';
84    if ( $subrow['name'] != '' ) $name.= $subrow['name'];
85    else                         $name.= str_replace( '_', ' ', $file );
86    $name.= ' [ '.$subrow['file'].' ]';
87    $vtp->setVar( $handle, 'picture.title', $name );
88    // source of the thumbnail picture
89    $src = $array_cat_directories[$subrow['cat_id']];
90    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
91    $src.= $file.'.'.$subrow['tn_ext'];
92    $vtp->setVar( $handle, 'picture.thumb_src', $src );
93    // link to the full size picture
94    $url = './picture.php?cat='.$category_id;
95    $url.= '&amp;image_id='.$row['image_id'];
96    $vtp->setVar( $handle, 'picture.thumb_url', add_session_id( $url ) );
97    // 3. for each picture, retrieving all comments
98    $query = 'SELECT id,date,author,content';
99    $query.= ' FROM '.PREFIX_TABLE.'comments';
100    $query.= ' WHERE image_id = '.$row['image_id'];
101    $query.= ' AND date > '.$maxtime;
102    $query.= " AND validated = 'true'";
103    $query.= ' ORDER BY date DESC';
104    $query.= ';';
105    $handleresult = mysql_query( $query );
106    while ( $subrow = mysql_fetch_array( $handleresult ) )
107    {
108      $vtp->addSession( $handle, 'comment' );
109      $author = $subrow['author'];
110      if ( $subrow['author'] == '' ) $author = $lang['guest'];
111      $vtp->setVar( $handle, 'comment.author', $author );
112      $displayed_date = format_date( $subrow['date'], 'unix', true );
113      $vtp->setVar( $handle, 'comment.date', $displayed_date );
114
115      $content = nl2br( $subrow['content'] );
116     
117      // replace _word_ by an underlined word
118      $pattern = '/_([^\s]*)_/';
119      $replacement = '<span style="text-decoration:underline;">\1</span>';
120      $content = preg_replace( $pattern, $replacement, $content );
121     
122      // replace *word* by a bolded word
123      $pattern = '/\*([^\s]*)\*/';
124      $replacement = '<span style="font-weight:bold;">\1</span>';
125      $content = preg_replace( $pattern, $replacement, $content );
126
127      // replace /word/ by an italic word
128      $pattern = '/\/([^\s]*)\//';
129      $replacement = '<span style="font-style:italic;">\1</span>';
130      $content = preg_replace( $pattern, $replacement, $content );
131     
132      $vtp->setVar( $handle, 'comment.content', $content );
133      $vtp->closeSession( $handle, 'comment' );
134    }
135    $vtp->closeSession( $handle, 'picture' );
136  }
137}
138//----------------------------------------------------- template initialization
139//
140// Start output of page
141//
142$title= $lang['title_comments'];
143include('include/page_header.php');
144
145$handle = $vtp->Open( './template/'.$user['template'].'/comments.vtp' );
146initialize_template();
147$tpl = array( 'title_comments','stats_last_days','search_return_main_page' );
148templatize_array( $tpl, 'lang', $handle );
149//--------------------------------------------------- number of days to display
150if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
151else                               define( 'MAX_DAYS', 0 );
152//----------------------------------------- non specific section initialization
153$array_cat_directories = array();
154$array_cat_names       = array();
155$array_cat_site_id     = array();
156//------------------------------------------------------- last comments display
157foreach ( $conf['last_days'] as $option ) {
158  $vtp->addSession( $handle, 'last_day_option' );
159  $vtp->setVar( $handle, 'last_day_option.option', $option );
160  $url = './comments.php';
161  $url.= '?last_days='.($option - 1);
162  $vtp->setVar( $handle, 'last_day_option.link', add_session_id( $url ) );
163  $style = '';
164  if ( $option == MAX_DAYS + 1 ) $style = 'text-decoration:underline;';
165  $vtp->setVar( $handle, 'last_day_option.style', $style );
166  $vtp->closeSession( $handle, 'last_day_option' );
167}
168$vtp->setVar( $handle, 'back_url', add_session_id( './category.php' ) );
169// 1. retrieving picture ids which have comments recently added
170$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
171list($year,$month,$day) = explode( '-', $date);
172$maxtime = mktime( 0,0,0,$month,$day,$year );
173$query = 'SELECT DISTINCT(ic.image_id) as image_id';
174$query.= ' FROM '.PREFIX_TABLE.'comments AS c';
175$query.=     ', '.PREFIX_TABLE.'image_category AS ic';
176$query.= ' WHERE c.image_id = ic.image_id';
177$query.= ' AND date > '.$maxtime;
178$query.= " AND validated = 'true'";
179// we must not show pictures of a forbidden category
180if ( $user['forbidden_categories'] != '' )
181{
182  $query.= ' AND category_id NOT IN ';
183  $query.= '('.$user['forbidden_categories'].')';
184}
185$query.= ' ORDER BY ic.image_id DESC';
186$query.= ';';
187$result = mysql_query( $query );
188display_pictures( $result, $maxtime, $user['restrictions'] );
189//----------------------------------------------------------- html code display
190$code = $vtp->Display( $handle, 0 );
191echo $code;
192include('include/page_tail.php');
193?>
Note: See TracBrowser for help on using the repository browser.