aboutsummaryrefslogtreecommitdiffstats
path: root/comments.php
blob: 4ac6e1cad9bb9684c7e04bd58e9edf2043cdad1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<?php
// +-----------------------------------------------------------------------+
// |                             comments.php                              |
// +-----------------------------------------------------------------------+
// | application   : PhpWebGallery <http://phpwebgallery.net>              |
// | branch        : BSF (Best So Far)                                     |
// +-----------------------------------------------------------------------+
// | file          : $RCSfile$
// | last update   : $Date$
// | last modifier : $Author$
// | revision      : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

//----------------------------------------------------------- include
$phpwg_root_path = './';
include_once( $phpwg_root_path.'include/common.inc.php' );

//--------------------------------------------------- number of days to display
if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
else                               define( 'MAX_DAYS', 0 );
//----------------------------------------- non specific section initialization
$array_cat_directories = array();
$array_cat_names       = array();
$array_cat_site_id     = array();
//------------------------------------------------------- last comments display

//
// Start output of page
//
$title= $lang['title_comments'];
include('include/page_header.php');

$template->set_filenames( array('comments'=>'comments.tpl') );
initialize_template();

$template->assign_vars(array(
  'L_TITLE' => $lang['title_comments'],
  'L_STATS' => $lang['stats_last_days'],
  'L_RETURN' => $lang['search_return_main_page'],
  
  'U_HOME' => add_session_id( 'category.php' )
  )
);

foreach ( $conf['last_days'] as $option ) {
  $url = './comments.php?last_days='.($option - 1);
  $template->assign_block_vars('last_day_option', array (
    'OPTION'=>$option,
	'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''),
	'U_OPTION'=>add_session_id( $url )
	));
}

// 1. retrieving picture ids which have comments recently added
$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
list($year,$month,$day) = explode( '-', $date);
$maxtime = mktime( 0,0,0,$month,$day,$year );
$query = 'SELECT DISTINCT(ic.image_id) as image_id,';
$query .= '(ic.category_id) as category_id';
$query.= ' FROM '.PREFIX_TABLE.'comments AS c';
$query.=     ', '.PREFIX_TABLE.'image_category AS ic';
$query.= ' WHERE c.image_id = ic.image_id';
$query.= ' AND date > '.$maxtime;
$query.= " AND validated = 'true'";
// we must not show pictures of a forbidden category
if ( $user['forbidden_categories'] != '' )
{
  $query.= ' AND category_id NOT IN ';
  $query.= '('.$user['forbidden_categories'].')';
}
$query.= ' ORDER BY ic.image_id DESC';
$query.= ';';
$result = mysql_query( $query );

while ( $row = mysql_fetch_array( $result ) )
  {
    $category_id=$row['category_id'];

    // for each picture, getting informations for displaying thumbnail and
    // link to the full size picture
    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
    $query.= ' FROM '.IMAGES_TABLE;
    $query.= ' WHERE id = '.$row['image_id'];
    $query.= ';';
    $subresult = mysql_query( $query );
    $subrow = mysql_fetch_array( $subresult );

    if ( !isset($array_cat_directories[$subrow['cat_id']]) )
    {
      $array_cat_directories[$subrow['cat_id']] =
        get_complete_dir( $subrow['cat_id'] );
      $cat_result = get_cat_info( $subrow['cat_id'] );
      $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id'];
      $array_cat_names[$subrow['cat_id']] =
        get_cat_display_name( $cat_result['name'], ' &gt; ', '' );
    }

    $file = get_filename_wo_extension( $subrow['file'] );
    // name of the picture
    $name = $array_cat_names[$category_id].' &gt; ';
    if ( $subrow['name'] != '' ) $name.= $subrow['name'];
    else                         $name.= str_replace( '_', ' ', $file );
    $name.= ' [ '.$subrow['file'].' ]';
	// source of the thumbnail picture
    $src = $array_cat_directories[$subrow['cat_id']];
    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
    $src.= $file.'.'.$subrow['tn_ext'];
	// link to the full size picture
    $url = './picture.php?cat='.$category_id;
    $url.= '&amp;image_id='.$row['image_id'];
	
	$template->assign_block_vars('picture',array(
	  'TITLE_IMG'=>$name,
	  'I_THUMB'=>$src,
	  'U_THUMB'=>add_session_id( $url )
	  ));

    // for each picture, retrieving all comments
    $query = 'SELECT id,date,author,content';
    $query.= ' FROM '.COMMENTS_TABLE;
    $query.= ' WHERE image_id = '.$row['image_id'];
    $query.= ' AND date > '.$maxtime;
    $query.= " AND validated = 'true'";
    $query.= ' ORDER BY date DESC';
    $query.= ';';
    $handleresult = mysql_query( $query );
    while ( $subrow = mysql_fetch_array( $handleresult ) )
    {
      $author = $subrow['author'];
      if ( $subrow['author'] == '' ) $author = $lang['guest'];
      $content = nl2br( $subrow['content'] );
      
      // replace _word_ by an underlined word
      $pattern = '/_([^\s]*)_/';
      $replacement = '<span style="text-decoration:underline;">\1</span>';
      $content = preg_replace( $pattern, $replacement, $content );
      
      // replace *word* by a bolded word
      $pattern = '/\*([^\s]*)\*/';
      $replacement = '<span style="font-weight:bold;">\1</span>';
      $content = preg_replace( $pattern, $replacement, $content );

      // replace /word/ by an italic word
      $pattern = '/\/([^\s]*)\//';
      $replacement = '<span style="font-style:italic;">\1</span>';
      $content = preg_replace( $pattern, $replacement, $content );
      $template->assign_block_vars('picture.comment',array(
	    'AUTHOR'=>$author,
		'DATE'=>format_date( $subrow['date'], 'unix', true ),
		'CONTENT'=>$content,
		));
    }
  }
//----------------------------------------------------------- html code display
$template->pparse('comments');
include('include/page_tail.php');
?>