source: trunk/comments.php @ 369

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

Template migration

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.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-02-22 02:43:13 +0000 (Sun, 22 Feb 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 369 $
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
29define('PHPWG_ROOT_PATH','./');
30include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
31
32//--------------------------------------------------- number of days to display
33if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
34else                               define( 'MAX_DAYS', 0 );
35//----------------------------------------- non specific section initialization
36$array_cat_directories = array();
37$array_cat_names       = array();
38$array_cat_site_id     = array();
39//------------------------------------------------------- last comments display
40
41//
42// Start output of page
43//
44$title= $lang['title_comments'];
45include(PHPWG_ROOT_PATH.'include/page_header.php');
46
47$template->set_filenames( array('comments'=>'comments.tpl') );
48initialize_template();
49
50$template->assign_vars(array(
51  'L_TITLE' => $lang['title_comments'],
52  'L_STATS' => $lang['stats_last_days'],
53  'L_RETURN' => $lang['search_return_main_page'],
54 
55  'U_HOME' => add_session_id( 'category.php' )
56  )
57);
58
59foreach ( $conf['last_days'] as $option ) {
60  $url = './comments.php?last_days='.($option - 1);
61  $template->assign_block_vars('last_day_option', array (
62    'OPTION'=>$option,
63        'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''),
64        'U_OPTION'=>add_session_id( $url )
65        ));
66}
67
68// 1. retrieving picture ids which have comments recently added
69$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
70list($year,$month,$day) = explode( '-', $date);
71$maxtime = mktime( 0,0,0,$month,$day,$year );
72$query = 'SELECT DISTINCT(ic.image_id) as image_id,';
73$query .= '(ic.category_id) as category_id';
74$query.= ' FROM '.PREFIX_TABLE.'comments AS c';
75$query.=     ', '.PREFIX_TABLE.'image_category AS ic';
76$query.= ' WHERE c.image_id = ic.image_id';
77$query.= ' AND date > '.$maxtime;
78$query.= " AND validated = 'true'";
79// we must not show pictures of a forbidden category
80if ( $user['forbidden_categories'] != '' )
81{
82  $query.= ' AND category_id NOT IN ';
83  $query.= '('.$user['forbidden_categories'].')';
84}
85$query.= ' ORDER BY ic.image_id DESC';
86$query.= ';';
87$result = mysql_query( $query );
88
89while ( $row = mysql_fetch_array( $result ) )
90  {
91    $category_id=$row['category_id'];
92
93    // for each picture, getting informations for displaying thumbnail and
94    // link to the full size picture
95    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
96    $query.= ' FROM '.IMAGES_TABLE;
97    $query.= ' WHERE id = '.$row['image_id'];
98    $query.= ';';
99    $subresult = mysql_query( $query );
100    $subrow = mysql_fetch_array( $subresult );
101
102    if ( !isset($array_cat_directories[$subrow['cat_id']]) )
103    {
104      $array_cat_directories[$subrow['cat_id']] =
105        get_complete_dir( $subrow['cat_id'] );
106      $cat_result = get_cat_info( $subrow['cat_id'] );
107      $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
108      $array_cat_names[$subrow['cat_id']] =
109        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
110    }
111
112    $file = get_filename_wo_extension( $subrow['file'] );
113    // name of the picture
114    $name = $array_cat_names[$category_id].' &gt; ';
115    if ( $subrow['name'] != '' ) $name.= $subrow['name'];
116    else                         $name.= str_replace( '_', ' ', $file );
117    $name.= ' [ '.$subrow['file'].' ]';
118        // source of the thumbnail picture
119    $src = $array_cat_directories[$subrow['cat_id']];
120    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
121    $src.= $file.'.'.$subrow['tn_ext'];
122        // link to the full size picture
123    $url = './picture.php?cat='.$category_id;
124    $url.= '&amp;image_id='.$row['image_id'];
125       
126        $template->assign_block_vars('picture',array(
127          'TITLE_IMG'=>$name,
128          'I_THUMB'=>$src,
129          'U_THUMB'=>add_session_id( $url )
130          ));
131
132    // for each picture, retrieving all comments
133    $query = 'SELECT id,date,author,content';
134    $query.= ' FROM '.COMMENTS_TABLE;
135    $query.= ' WHERE image_id = '.$row['image_id'];
136    $query.= ' AND date > '.$maxtime;
137    $query.= " AND validated = 'true'";
138    $query.= ' ORDER BY date DESC';
139    $query.= ';';
140    $handleresult = mysql_query( $query );
141    while ( $subrow = mysql_fetch_array( $handleresult ) )
142    {
143      $author = $subrow['author'];
144      if ( $subrow['author'] == '' ) $author = $lang['guest'];
145      $content = nl2br( $subrow['content'] );
146     
147      // replace _word_ by an underlined word
148      $pattern = '/_([^\s]*)_/';
149      $replacement = '<span style="text-decoration:underline;">\1</span>';
150      $content = preg_replace( $pattern, $replacement, $content );
151     
152      // replace *word* by a bolded word
153      $pattern = '/\*([^\s]*)\*/';
154      $replacement = '<span style="font-weight:bold;">\1</span>';
155      $content = preg_replace( $pattern, $replacement, $content );
156
157      // replace /word/ by an italic word
158      $pattern = '/\/([^\s]*)\//';
159      $replacement = '<span style="font-style:italic;">\1</span>';
160      $content = preg_replace( $pattern, $replacement, $content );
161      $template->assign_block_vars('picture.comment',array(
162            'AUTHOR'=>$author,
163                'DATE'=>format_date( $subrow['date'], 'unix', true ),
164                'CONTENT'=>$content,
165                ));
166    }
167  }
168//----------------------------------------------------------- html code display
169$template->pparse('comments');
170include(PHPWG_ROOT_PATH.'include/page_tail.php');
171?>
Note: See TracBrowser for help on using the repository browser.