source: trunk/admin/comments.php @ 362

Last change on this file since 362 was 362, checked in by z0rglub, 20 years ago

header global refactoring

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.2 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                             comments.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 362 $
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// +-----------------------------------------------------------------------+
27include_once( './admin/include/isadmin.inc.php' );
28$page['plain_structure'] = get_plain_structure();
29//------------------------------------------------------------------- functions
30function display_pictures( $mysql_result, $maxtime, $validation_box = false )
31{
32  global $vtp,$sub,$lang,$conf,
33    $array_cat_directories,$array_cat_site_id,$array_cat_names;
34
35  while ( $row = mysql_fetch_array( $mysql_result ) )
36  {
37    $vtp->addSession( $sub, 'picture' );
38    // 2. for each picture, getting informations for displaying thumbnail and
39    //    link to the full size picture
40    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
41    $query.= ' FROM '.PREFIX_TABLE.'images';
42    $query.= ' WHERE id = '.$row['image_id'];
43    $query.= ';';
44    $subresult = mysql_query( $query );
45    $subrow = mysql_fetch_array( $subresult );
46
47    if ( !isset( $array_cat_directories[$subrow['cat_id']] ) )
48    {
49      $array_cat_directories[$subrow['cat_id']] =
50        get_complete_dir( $subrow['cat_id'] );
51      $cat_result = get_cat_info( $subrow['cat_id'] );
52      $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
53      $array_cat_names[$subrow['cat_id']] =
54        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
55    }
56
57    $file = get_filename_wo_extension( $subrow['file'] );
58    // name of the picture
59    $name = $array_cat_names[$subrow['cat_id']].' &gt; ';
60    if ( isset( $subrow['name'] ) and $subrow['name'] != '' )
61    {
62      $name.= $subrow['name'];
63    }
64    else
65    {
66      $name.= str_replace( '_', ' ', $file );
67    }
68    $name.= ' [ '.$subrow['file'].' ]';
69    $vtp->setVar( $sub, 'picture.title', $name );
70    // source of the thumbnail picture
71    $src = $array_cat_directories[$subrow['cat_id']];
72    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
73    $src.= $file.'.'.$subrow['tn_ext'];
74    $vtp->setVar( $sub, 'picture.thumb_src', $src );
75    // link to the full size picture
76    $url = './picture.php?cat='.$subrow['cat_id'];
77    $url.= '&amp;image_id='.$row['image_id'];
78    $vtp->setVar( $sub, 'picture.thumb_url', add_session_id( $url ) );
79    // 3. for each picture, retrieving all comments
80    $query = 'SELECT id,date,author,content';
81    $query.= ' FROM '.PREFIX_TABLE.'comments';
82    $query.= ' WHERE image_id = '.$row['image_id'];
83    $query.= ' AND date > '.$maxtime;
84    if ( $validation_box ) $query.= " AND validated = 'false'";
85    $query.= ' ORDER BY date DESC';
86    $query.= ';';
87    $subresult = mysql_query( $query );
88    while ( $subrow = mysql_fetch_array( $subresult ) )
89    {
90      $vtp->addSession( $sub, 'comment' );
91      $author = $subrow['author'];
92      if ( $subrow['author'] == '' ) $author = $lang['guest'];
93      $vtp->setVar( $sub, 'comment.author', $author );
94      $displayed_date = format_date( $subrow['date'], 'unix', true );
95      $vtp->setVar( $sub, 'comment.date', $displayed_date );
96
97      $content = nl2br( $subrow['content'] );
98     
99      // replace _word_ by an underlined word
100      $pattern = '/_([^\s]*)_/';
101      $replacement = '<span style="text-decoration:underline;">\1</span>';
102      $content = preg_replace( $pattern, $replacement, $content );
103     
104      // replace *word* by a bolded word
105      $pattern = '/\*([^\s]*)\*/';
106      $replacement = '<span style="font-weight:bold;">\1</span>';
107      $content = preg_replace( $pattern, $replacement, $content );
108
109      // replace /word/ by an italic word
110      $pattern = '/\/([^\s]*)\//';
111      $replacement = '<span style="font-style:italic;">\1</span>';
112      $content = preg_replace( $pattern, $replacement, $content );
113
114      $vtp->setVar( $sub, 'comment.content', $content );
115
116      $vtp->addSession( $sub, 'delete' );
117      $url = './admin.php?page=comments';
118      if ( isset( $_GET['last_days'] ) ) $url.= '&amp;last_days='.MAX_DAYS;
119      if ( isset( $_GET['show_unvalidated'] ) )
120        $url.= '&amp;show_unvalidated=true';
121      $url.= '&amp;del='.$subrow['id'];
122      $vtp->setVar( $sub, 'delete.link', add_session_id( $url ) );
123      $vtp->closeSession( $sub, 'delete' );
124      // if the comment has to be validated, we display a checkbox
125      if ( $validation_box )
126      {
127        $vtp->addSession( $sub, 'validation' );
128        $vtp->setVar( $sub, 'validation.id', $subrow['id'] );
129        $vtp->closeSession( $sub, 'validation' );
130      }
131      $vtp->closeSession( $sub, 'comment' );
132    }
133    $vtp->closeSession( $sub, 'picture' );
134  }
135}
136//------------------------------------------------------------ comment deletion
137if ( isset( $_GET['del'] ) and is_numeric( $_GET['del'] ) )
138{
139  $query = 'DELETE FROM '.PREFIX_TABLE.'comments';
140  $query.= ' WHERE id = '.$_GET['del'];
141  $query.= ';';
142  mysql_query( $query );
143}
144//--------------------------------------------------------- comments validation
145if ( isset( $_POST['submit'] ) )
146{
147  $query = 'SELECT id';
148  $query.= ' FROM '.PREFIX_TABLE.'comments';
149  $query.= " WHERE validated = 'false'";
150  $query.= ';';
151  $result = mysql_query( $query );
152  while ( $row = mysql_fetch_array( $result ) )
153  {
154    if ( $_POST['validate-'.$row['id']] == 'true' )
155    {
156      $query = 'UPDATE '.PREFIX_TABLE.'comments';
157      $query.= " SET validated = 'true'";
158      $query.= ' WHERE id = '.$row['id'];
159      $query.= ';';
160      mysql_query( $query );
161    }
162  }
163}
164//----------------------------------------------------- template initialization
165$sub = $vtp->Open( './template/'.$user['template'].'/admin/comments.vtp' );
166$tpl = array( 'stats_last_days','delete','close','submit','open' );
167templatize_array( $tpl, 'lang', $sub );
168$vtp->setGlobalVar( $sub, 'user_template', $user['template'] );
169//--------------------------------------------------- number of days to display
170if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
171else                               define( 'MAX_DAYS', 0 );
172//----------------------------------------- non specific section initialization
173$array_cat_directories = array();
174$array_cat_names       = array();
175$array_cat_site_id     = array();
176//------------------------------------------------------- last comments display
177$vtp->addSession( $sub, 'section' );
178$vtp->setVar( $sub, 'section.title', $lang['comments_last_title'] );
179$vtp->addSession( $sub, 'last_days' );
180foreach ( $conf['last_days'] as $option ) {
181  $vtp->addSession( $sub, 'last_day_option' );
182  $vtp->setVar( $sub, 'last_day_option.option', $option );
183  $url = './admin.php?page=comments';
184  $url.= '&amp;last_days='.($option - 1);
185  $vtp->setVar( $sub, 'last_day_option.link', add_session_id( $url ) );
186  if ( $option == MAX_DAYS + 1 )
187  {
188    $vtp->setVar( $sub, 'last_day_option.style', 'font-weight:bold;');
189  }
190  $vtp->closeSession( $sub, 'last_day_option' );
191}
192$vtp->closeSession( $sub, 'last_days' );
193if ( isset( $_GET['last_days'] ) )
194{
195  $vtp->addSession( $sub, 'close' );
196  $url = './admin.php?page=comments';
197  if ( isset( $_GET['show_unvalidated'] ) )
198  {
199    $url.= '&amp;show_unvalidated='.$_GET['show_unvalidated'];
200  }
201  $vtp->setVar( $sub, 'close.url', add_session_id( $url ) );
202  $vtp->closeSession( $sub, 'close' );
203  // 1. retrieving picture ids which have comments recently added
204  $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
205  list($year,$month,$day) = explode( '-', $date);
206  $maxtime = mktime( 0,0,0,$month,$day,$year );
207  $query = 'SELECT DISTINCT(image_id) as image_id';
208  $query.= ' FROM '.PREFIX_TABLE.'comments';
209  $query.=     ', '.PREFIX_TABLE.'images as images';
210  $query.= ' WHERE image_id = images.id';
211  $query.= ' AND date > '.$maxtime;
212  $query.= ' ORDER BY date_available DESC';
213  $query.= ';';
214  $result = mysql_query( $query );
215  display_pictures( $result, $maxtime );
216}
217$vtp->closeSession( $sub, 'section' );
218//---------------------------------------------- non validated comments display
219$vtp->addSession( $sub, 'section' );
220$vtp->setVar( $sub, 'section.title', $lang['comments_non_validated_title'] );
221if ( isset( $_GET['show_unvalidated'] ) )
222{
223  // form starts
224  $vtp->addSession( $sub, 'start_form' );
225  $action = './admin.php?page=comments';
226  if ( isset( $_GET['last_days'] ) )
227  {
228    $action.= '&amp;last_days='.$_GET['last_days'];
229  }
230  $action.= '&amp;show_unvalidated=true';
231  $vtp->setVar( $sub, 'start_form.action', add_session_id( $action ) );
232  $vtp->closeSession( $sub, 'start_form' );
233  // close this section ?
234  $vtp->addSession( $sub, 'close' );
235  $url = './admin.php?page=comments';
236  if ( isset( $_GET['last_days'] ) )
237  {
238    $url.= '&amp;last_days='.$_GET['last_days'];
239  }
240  $vtp->setVar( $sub, 'close.url', add_session_id( $url ) );
241  $vtp->closeSession( $sub, 'close' );
242  // retrieving all picture ids which have unvalidated comments
243  $query = 'SELECT DISTINCT(image_id) as image_id';
244  $query.= ' FROM '.PREFIX_TABLE.'comments as comments';
245  $query.=     ', '.PREFIX_TABLE.'images as images';
246  $query.= ' WHERE image_id = images.id';
247  $query.= " AND comments.validated = 'false'";
248  $query.= ' ORDER BY date_available DESC';
249  $query.= ';';
250  $result = mysql_query( $query );
251  display_pictures( $result, 0, true );
252  $vtp->addSession( $sub, 'submit' );
253  $vtp->closeSession( $sub, 'submit' );
254  // form ends
255  $vtp->addSession( $sub, 'end_form' );
256  $vtp->closeSession( $sub, 'end_form' );
257}
258else
259{
260  $vtp->addSession( $sub, 'open' );
261  $url = './admin.php?page=comments';
262  if ( isset( $_GET['last_days'] ) )
263  {
264    $url.= '&amp;last_days='.$_GET['last_days'];
265  }
266  $url.= '&amp;show_unvalidated=true';
267  $vtp->setVar( $sub, 'open.url', add_session_id( $url ) );
268  $vtp->closeSession( $sub, 'open' );
269}
270$vtp->closeSession( $sub, 'section' );
271//----------------------------------------------------------- sending html code
272$vtp->Parse( $handle, 'sub', $sub );
273?>
Note: See TracBrowser for help on using the repository browser.