source: trunk/comments.php @ 464

Last change on this file since 464 was 464, checked in by z0rglub, 20 years ago
  • non picture files management
  • refactoring
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.9 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-08-05 17:27:09 +0000 (Thu, 05 Aug 2004) $
10// | last modifier : $Author: z0rglub $
11// | revision      : $Revision: 464 $
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
29if (!defined('IN_ADMIN'))
30{
31  define('PHPWG_ROOT_PATH','./');
32  include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
33}
34
35//--------------------------------------------------- number of days to display
36if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
37else                               define( 'MAX_DAYS', 0 );
38//----------------------------------------- non specific section initialization
39$array_cat_directories = array();
40$array_cat_names       = array();
41$array_cat_site_id     = array();
42
43// comment deletion
44if ( isset( $_POST['delete'] ) )
45{
46  $mod_sql='';
47  while( list($id, $row_id) = @each($_POST['comment_id']) )
48  {
49        $mod_sql .= ( ( $mod_sql != '' ) ? ', ' : '' ) . $row_id;
50  }
51  $query = 'DELETE FROM '.COMMENTS_TABLE.' WHERE id IN ('.$mod_sql.');';
52  mysql_query( $query );
53}
54
55//--------------------------------------------------------- comments validation
56if ( isset( $_POST['validate'] ) )
57{
58  $mod_sql='';
59  while( list($id, $row_id) = @each($_POST['comment_id']) )
60  {
61        $mod_sql .= ( ( $mod_sql != '' ) ? ', ' : '' ) . $row_id;
62  }
63  $query = 'UPDATE '.COMMENTS_TABLE;
64  $query.= " SET validated = 'true'";
65  $query.=' WHERE id IN ('.$mod_sql.');';
66  mysql_query( $query );
67}
68//------------------------------------------------------- last comments display
69
70//
71// Start output of page
72//
73if (!defined('IN_ADMIN'))
74{
75  $title= $lang['title_comments'];
76  include(PHPWG_ROOT_PATH.'include/page_header.php');
77}
78
79$template->set_filenames( array('comments'=>'comments.tpl') );
80$template->assign_vars(array(
81  'L_COMMENT_TITLE' => $title,
82  'L_COMMENT_STATS' => $lang['stats_last_days'],
83  'L_COMMENT_RETURN' => $lang['search_return_main_page'],
84  'L_DELETE' =>$lang['delete'],
85  'L_VALIDATE'=>$lang['submit'],
86 
87  'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif',
88 
89  'U_HOME' => add_session_id( PHPWG_ROOT_PATH.'category.php' )
90  )
91);
92
93foreach ( $conf['last_days'] as $option ) {
94  $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1);
95  if (defined('IN_ADMIN')) $url.= '&amp;page=comments';
96  $template->assign_block_vars(
97    'last_day_option',
98    array(
99      'OPTION'=>$option,
100      'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''),
101      'U_OPTION'=>add_session_id( $url )
102      )
103    );
104}
105
106// 1. retrieving picture ids which have comments recently added
107$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
108list($year,$month,$day) = explode( '-', $date);
109$maxtime = mktime( 0,0,0,$month,$day,$year );
110$query = 'SELECT DISTINCT(ic.image_id) as image_id,';
111$query.= '(ic.category_id) as category_id';
112$query.= ' FROM '.COMMENTS_TABLE.' AS c';
113$query.= ', '.IMAGE_CATEGORY_TABLE.' AS ic';
114$query.= ' WHERE c.image_id = ic.image_id';
115$query.= ' AND date > FROM_UNIXTIME('.$maxtime.')';
116if ( $user['status'] != 'admin' )
117{
118  $query.= " AND validated = 'true'";
119  // we must not show pictures of a forbidden category
120  if ( $user['forbidden_categories'] != '' )
121  {
122    $query.= ' AND category_id NOT IN ';
123    $query.= '('.$user['forbidden_categories'].')';
124  }
125}
126$query.= ' ORDER BY ic.image_id DESC';
127$query.= ';';
128$result = mysql_query( $query );
129if ( $user['status'] == 'admin' )
130{
131  $template->assign_block_vars('validation', array());
132}
133while ( $row = mysql_fetch_array( $result ) )
134  {
135    $category_id=$row['category_id'];
136
137    // for each picture, getting informations for displaying thumbnail and
138    // link to the full size picture
139    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
140    $query.= ' FROM '.IMAGES_TABLE;
141    $query.= ' WHERE id = '.$row['image_id'];
142    $query.= ';';
143    $subresult = mysql_query( $query );
144    $subrow = mysql_fetch_array( $subresult );
145
146    if ( !isset($array_cat_directories[$subrow['cat_id']]) )
147    {
148      $array_cat_directories[$subrow['cat_id']] =
149        get_complete_dir( $subrow['cat_id'] );
150      $cat_result = get_cat_info( $subrow['cat_id'] );
151      $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
152      $array_cat_names[$subrow['cat_id']] =
153        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
154    }
155
156    $file = get_filename_wo_extension( $subrow['file'] );
157    // name of the picture
158    $name = $array_cat_names[$category_id].' &gt; ';
159    if (!empty($subrow['name'])) $name.= $subrow['name'];
160    else                         $name.= str_replace( '_', ' ', $file );
161    $name.= ' [ '.$subrow['file'].' ]';
162    // source of the thumbnail picture
163    if (isset($subrow['tn_ext']) and $subrow['tn_ext'] != '')
164    {
165      $src = $array_cat_directories[$subrow['cat_id']];
166      $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
167      $src.= $file.'.'.$subrow['tn_ext'];
168    }
169    else
170    {
171      $src = './template/'.$user['template'].'/mimetypes/';
172      $src.= strtolower(get_extension($subrow['file'])).'.png';
173    }
174   
175    // link to the full size picture
176    $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
177    $url.= '&amp;image_id='.$row['image_id'];
178   
179    $template->assign_block_vars(
180      'picture',
181      array(
182        'TITLE_IMG'=>$name,
183        'I_THUMB'=>$src,
184        'U_THUMB'=>add_session_id( $url )
185        ));
186   
187    // for each picture, retrieving all comments
188    $query = 'SELECT * FROM '.COMMENTS_TABLE;
189    $query.= ' WHERE image_id = '.$row['image_id'];
190    $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')';
191    if ( $user['status'] != 'admin' )
192    {
193      $query.= " AND validated = 'true'";
194    }
195    $query.= ' ORDER BY date DESC';
196    $query.= ';';
197    $handleresult = mysql_query( $query );
198    while ( $subrow = mysql_fetch_array( $handleresult ) )
199    {
200      $author = $subrow['author'];
201      if ( empty($subrow['author'] )) $author = $lang['guest'];
202      $content = nl2br( $subrow['content'] );
203     
204      // replace _word_ by an underlined word
205      $pattern = '/_([^\s]*)_/';
206      $replacement = '<span style="text-decoration:underline;">\1</span>';
207      $content = preg_replace( $pattern, $replacement, $content );
208     
209      // replace *word* by a bolded word
210      $pattern = '/\*([^\s]*)\*/';
211      $replacement = '<span style="font-weight:bold;">\1</span>';
212      $content = preg_replace( $pattern, $replacement, $content );
213
214      // replace /word/ by an italic word
215      $pattern = '/\/([^\s]*)\//';
216      $replacement = '<span style="font-style:italic;">\1</span>';
217      $content = preg_replace( $pattern, $replacement, $content );
218      $template->assign_block_vars(
219        'picture.comment',array(
220          'COMMENT_AUTHOR'=>$author,
221          'COMMENT_DATE'=>format_date( $subrow['date'],'mysql_datetime',true ),
222          'COMMENT'=>$content,
223          ));
224      if ( $user['status'] == 'admin' )
225      {
226        $template->assign_block_vars(
227          'picture.comment.validation', array(
228            'ID'=> $subrow['id'],
229            'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
230            ));
231      }
232    }
233  }
234//----------------------------------------------------------- html code display
235if (defined('IN_ADMIN'))
236{
237  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
238}
239else
240{
241  $template->assign_block_vars('title',array());
242  $template->pparse('comments');
243  include(PHPWG_ROOT_PATH.'include/page_tail.php');
244}
245?>
Note: See TracBrowser for help on using the repository browser.