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