source: trunk/comments.php @ 354

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

Migration of common.php in the include directory to fit the new coding rules

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