[166] | 1 | <?php |
---|
[354] | 2 | // +-----------------------------------------------------------------------+ |
---|
[362] | 3 | // | comments.php | |
---|
[354] | 4 | // +-----------------------------------------------------------------------+ |
---|
| 5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
[362] | 6 | // | branch : BSF (Best So Far) | |
---|
[354] | 7 | // +-----------------------------------------------------------------------+ |
---|
| 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2004-09-19 22:26:41 +0000 (Sun, 19 Sep 2004) $ |
---|
| 10 | // | last modifier : $Author: gweltas $ |
---|
| 11 | // | revision : $Revision: 527 $ |
---|
| 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 | |
---|
[345] | 28 | //----------------------------------------------------------- include |
---|
[393] | 29 | if (!defined('IN_ADMIN')) |
---|
| 30 | { |
---|
| 31 | define('PHPWG_ROOT_PATH','./'); |
---|
| 32 | include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
| 33 | } |
---|
[345] | 34 | |
---|
[355] | 35 | //--------------------------------------------------- number of days to display |
---|
| 36 | if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] ); |
---|
| 37 | else 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(); |
---|
[393] | 42 | |
---|
| 43 | // comment deletion |
---|
| 44 | if ( 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 |
---|
| 56 | if ( 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 | } |
---|
[355] | 68 | //------------------------------------------------------- last comments display |
---|
| 69 | |
---|
| 70 | // |
---|
| 71 | // Start output of page |
---|
| 72 | // |
---|
[393] | 73 | if (!defined('IN_ADMIN')) |
---|
| 74 | { |
---|
| 75 | $title= $lang['title_comments']; |
---|
| 76 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
| 77 | } |
---|
[355] | 78 | |
---|
| 79 | $template->set_filenames( array('comments'=>'comments.tpl') ); |
---|
| 80 | $template->assign_vars(array( |
---|
[393] | 81 | 'L_COMMENT_TITLE' => $title, |
---|
| 82 | 'L_COMMENT_STATS' => $lang['stats_last_days'], |
---|
[527] | 83 | 'L_COMMENT_RETURN' => $lang['return_main_page'], |
---|
[393] | 84 | 'L_DELETE' =>$lang['delete'], |
---|
| 85 | 'L_VALIDATE'=>$lang['submit'], |
---|
[355] | 86 | |
---|
[393] | 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' ) |
---|
[355] | 90 | ) |
---|
| 91 | ); |
---|
| 92 | |
---|
| 93 | foreach ( $conf['last_days'] as $option ) { |
---|
[420] | 94 | $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1); |
---|
[393] | 95 | if (defined('IN_ADMIN')) $url.= '&page=comments'; |
---|
[420] | 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 | ); |
---|
[355] | 104 | } |
---|
| 105 | |
---|
| 106 | // 1. retrieving picture ids which have comments recently added |
---|
| 107 | $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) ); |
---|
| 108 | list($year,$month,$day) = explode( '-', $date); |
---|
| 109 | $maxtime = mktime( 0,0,0,$month,$day,$year ); |
---|
| 110 | $query = 'SELECT DISTINCT(ic.image_id) as image_id,'; |
---|
[393] | 111 | $query.= '(ic.category_id) as category_id'; |
---|
| 112 | $query.= ' FROM '.COMMENTS_TABLE.' AS c'; |
---|
| 113 | $query.= ', '.IMAGE_CATEGORY_TABLE.' AS ic'; |
---|
[355] | 114 | $query.= ' WHERE c.image_id = ic.image_id'; |
---|
[420] | 115 | $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; |
---|
[393] | 116 | if ( $user['status'] != 'admin' ) |
---|
[166] | 117 | { |
---|
[393] | 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 | } |
---|
[355] | 125 | } |
---|
| 126 | $query.= ' ORDER BY ic.image_id DESC'; |
---|
| 127 | $query.= ';'; |
---|
| 128 | $result = mysql_query( $query ); |
---|
[393] | 129 | if ( $user['status'] == 'admin' ) |
---|
| 130 | { |
---|
| 131 | $template->assign_block_vars('validation', array()); |
---|
| 132 | } |
---|
[355] | 133 | while ( $row = mysql_fetch_array( $result ) ) |
---|
[166] | 134 | { |
---|
[355] | 135 | $category_id=$row['category_id']; |
---|
[166] | 136 | |
---|
[355] | 137 | // for each picture, getting informations for displaying thumbnail and |
---|
| 138 | // link to the full size picture |
---|
[166] | 139 | $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext'; |
---|
[355] | 140 | $query.= ' FROM '.IMAGES_TABLE; |
---|
[166] | 141 | $query.= ' WHERE id = '.$row['image_id']; |
---|
| 142 | $query.= ';'; |
---|
| 143 | $subresult = mysql_query( $query ); |
---|
| 144 | $subrow = mysql_fetch_array( $subresult ); |
---|
| 145 | |
---|
[355] | 146 | if ( !isset($array_cat_directories[$subrow['cat_id']]) ) |
---|
[166] | 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'], ' > ', '' ); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | $file = get_filename_wo_extension( $subrow['file'] ); |
---|
| 157 | // name of the picture |
---|
| 158 | $name = $array_cat_names[$category_id].' > '; |
---|
[393] | 159 | if (!empty($subrow['name'])) $name.= $subrow['name']; |
---|
[166] | 160 | else $name.= str_replace( '_', ' ', $file ); |
---|
| 161 | $name.= ' [ '.$subrow['file'].' ]'; |
---|
[464] | 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 |
---|
[393] | 176 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; |
---|
[166] | 177 | $url.= '&image_id='.$row['image_id']; |
---|
[464] | 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 | |
---|
[355] | 187 | // for each picture, retrieving all comments |
---|
[393] | 188 | $query = 'SELECT * FROM '.COMMENTS_TABLE; |
---|
[166] | 189 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
[420] | 190 | $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; |
---|
[464] | 191 | if ( $user['status'] != 'admin' ) |
---|
[393] | 192 | { |
---|
| 193 | $query.= " AND validated = 'true'"; |
---|
[464] | 194 | } |
---|
[166] | 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']; |
---|
[393] | 201 | if ( empty($subrow['author'] )) $author = $lang['guest']; |
---|
[180] | 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 ); |
---|
[420] | 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 | } |
---|
[166] | 232 | } |
---|
| 233 | } |
---|
| 234 | //----------------------------------------------------------- html code display |
---|
[393] | 235 | if (defined('IN_ADMIN')) |
---|
| 236 | { |
---|
| 237 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
| 238 | } |
---|
| 239 | else |
---|
| 240 | { |
---|
| 241 | $template->assign_block_vars('title',array()); |
---|
| 242 | $template->pparse('comments'); |
---|
| 243 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 244 | } |
---|
[362] | 245 | ?> |
---|