Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
<?php
2
// +-----------------------------------------------------------------------+
3
// | PhpWebGallery - a PHP based picture gallery                           |
4
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5
// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6
// +-----------------------------------------------------------------------+
7
// | branch        : BSF (Best So Far)
8
// | file          : $RCSfile: comments.php,v $
9
// | last update   : $Date: 2005/01/23 15:27:20 $
10
// | last modifier : $Author: plg $
11
// | revision      : $Revision: 1.23 $
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
// +-----------------------------------------------------------------------+
29
// |                           initialization                              |
30
// +-----------------------------------------------------------------------+
31
if (!defined('IN_ADMIN'))
32
{
33
  define('PHPWG_ROOT_PATH','./');
34
  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
35
}
36
 
37
if (isset($_GET['last_days']))
38
{
39
  define('MAX_DAYS', $_GET['last_days']);
40
}
41
else
42
{
43
  define('MAX_DAYS', 0);
44
}
45
$array_cat_names = array();
46
// +-----------------------------------------------------------------------+
47
// |                         comments management                           |
48
// +-----------------------------------------------------------------------+
49
// comments deletion
50
if (isset($_POST['delete']) and count($_POST['comment_id']) > 0)
51
{
52
  $query = '
53
DELETE FROM '.COMMENTS_TABLE.'
54
  WHERE id IN ('.implode(',', $_POST['comment_id']).')
55
;';
56
  pwg_query($query);
57
}
58
// comments validation
59
if (isset($_POST['validate']) and count($_POST['comment_id']) > 0)
60
{
61
  $query = '
62
UPDATE '.COMMENTS_TABLE.'
63
  SET validated = \'true\'
64
  WHERE id IN ('.implode(',', $_POST['comment_id']).')
65
;';
66
  pwg_query($query);
67
}
68
// +-----------------------------------------------------------------------+
69
// |                       page header and options                         |
70
// +-----------------------------------------------------------------------+
71
if (!defined('IN_ADMIN'))
72
{
73
  $title= $lang['title_comments'];
74
  include(PHPWG_ROOT_PATH.'include/page_header.php');
75
}
76
 
77
$template->set_filenames(array('comments'=>'comments.tpl'));
78
$template->assign_vars(
79
  array(
80
    'L_COMMENT_TITLE' => $title,
81
    'L_COMMENT_STATS' => $lang['stats_last_days'],
82
    'L_COMMENT_RETURN' => $lang['home'],
83
	'L_COMMENT_RETURN_HINT' => $lang['home_hint'],
84
    'L_DELETE' =>$lang['delete'],
85
    'L_VALIDATE'=>$lang['submit'],
86
 
87
    'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php')
88
    )
89
  );
90
 
91
foreach ($conf['last_days'] as $option)
92
{
93
  $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1);
94
  if (defined('IN_ADMIN'))
95
  {
96
    $url.= '&amp;page=comments';
97
  }
98
  $template->assign_block_vars(
99
    'last_day_option',
100
    array(
101
      'OPTION'=>$option,
102
      'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''),
103
      'U_OPTION'=>add_session_id($url)
104
      )
105
    );
106
}
107
// +-----------------------------------------------------------------------+
108
// |                        last comments display                          |
109
// +-----------------------------------------------------------------------+
110
// 1. retrieving picture ids which have comments recently added
111
$maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day'));
112
 
113
$query = '
114
SELECT DISTINCT(ic.image_id) AS image_id,ic.category_id, uppercats
115
  FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic
116
    , '.CATEGORIES_TABLE.' AS cat
117
  WHERE c.image_id = ic.image_id
118
    AND ic.category_id = cat.id
119
    AND date >= \''.$maxdate.'\'';
120
if ($user['status'] != 'admin')
121
{
122
  $query.= "
123
    AND validated = 'true'";
124
  // we must not show pictures of a forbidden category
125
  if ($user['forbidden_categories'] != '')
126
  {
127
    $query.= '
128
    AND category_id NOT IN ('.$user['forbidden_categories'].')';
129
  }
130
}
131
$query.= '
132
  GROUP BY ic.image_id
133
  ORDER BY ic.image_id DESC
134
;';
135
$result = pwg_query($query);
136
if ($user['status'] == 'admin')
137
{
138
  $template->assign_block_vars('validation', array());
139
}
140
while ($row = mysql_fetch_array($result))
141
{
142
  $category_id = $row['category_id'];
143
 
144
  // for each picture, getting informations for displaying thumbnail and
145
  // link to the full size picture
146
  $query = '
147
SELECT name,file,storage_category_id as cat_id,tn_ext,path
148
  FROM '.IMAGES_TABLE.'
149
  WHERE id = '.$row['image_id'].'
150
;';
151
  $subresult = pwg_query($query);
152
  $subrow = mysql_fetch_array($subresult);
153
 
154
  // name of the picture
155
  $name = get_cat_display_name_cache($row['uppercats'], '', false);
156
  $name.= $conf['level_separator'];
157
  if (!empty($subrow['name']))
158
  {
159
    $name.= $subrow['name'];
160
  }
161
  else
162
  {
163
    $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file']));
164
  }
165
 
166
  // source of the thumbnail picture
167
  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
168
  // link to the full size picture
169
  $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
170
  $url.= '&amp;image_id='.$row['image_id'];
171
 
172
  $template->assign_block_vars(
173
    'picture',
174
    array(
175
      'TITLE_IMG'=>$name,
176
      'I_THUMB'=>$thumbnail_src,
177
      'U_THUMB'=>add_session_id($url)
178
      ));
179
 
180
  // for each picture, retrieving all comments
181
  $query = '
182
SELECT *
183
  FROM '.COMMENTS_TABLE.'
184
  WHERE image_id = '.$row['image_id'].'
185
    AND date >= \''.$maxdate.'\'';
186
  if ($user['status'] != 'admin')
187
  {
188
    $query.= '
189
    AND validated = \'true\'';
190
  }
191
  $query.= '
192
  ORDER BY date DESC
193
;';
194
  $handleresult = pwg_query($query);
195
  while ($subrow = mysql_fetch_array($handleresult))
196
  {
197
    $author = $subrow['author'];
198
    if (empty($subrow['author']))
199
    {
200
      $author = $lang['guest'];
201
    }
202
 
203
    $template->assign_block_vars(
204
      'picture.comment',
205
      array(
206
        'COMMENT_AUTHOR'=>$author,
207
        'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true),
208
        'COMMENT'=>parse_comment_content($subrow['content']),
209
        ));
210
 
211
    if ($user['status'] == 'admin')
212
    {
213
      $template->assign_block_vars(
214
        'picture.comment.validation',
215
        array(
216
          'ID'=> $subrow['id'],
217
          'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': ''
218
          ));
219
    }
220
  }
221
}
222
// +-----------------------------------------------------------------------+
223
// |                           html code display                           |
224
// +-----------------------------------------------------------------------+
225
if (defined('IN_ADMIN'))
226
{
227
  $template->assign_var_from_handle('ADMIN_CONTENT', 'comments');
228
}
229
else
230
{
231
  $template->assign_block_vars('title',array());
232
  $template->parse('comments');
233
  include(PHPWG_ROOT_PATH.'include/page_tail.php');
234
}
235
?>