[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-05-20 21:22:44 +0000 (Thu, 20 May 2004) $ |
---|
| 10 | // | last modifier : $Author: z0rglub $ |
---|
| 11 | // | revision : $Revision: 420 $ |
---|
| 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'], |
---|
| 83 | 'L_COMMENT_RETURN' => $lang['search_return_main_page'], |
---|
| 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'].' ]'; |
---|
[355] | 162 | // source of the thumbnail picture |
---|
[166] | 163 | $src = $array_cat_directories[$subrow['cat_id']]; |
---|
| 164 | $src.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
| 165 | $src.= $file.'.'.$subrow['tn_ext']; |
---|
[355] | 166 | // link to the full size picture |
---|
[393] | 167 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; |
---|
[166] | 168 | $url.= '&image_id='.$row['image_id']; |
---|
[355] | 169 | |
---|
| 170 | $template->assign_block_vars('picture',array( |
---|
| 171 | 'TITLE_IMG'=>$name, |
---|
| 172 | 'I_THUMB'=>$src, |
---|
| 173 | 'U_THUMB'=>add_session_id( $url ) |
---|
| 174 | )); |
---|
| 175 | |
---|
| 176 | // for each picture, retrieving all comments |
---|
[393] | 177 | $query = 'SELECT * FROM '.COMMENTS_TABLE; |
---|
[166] | 178 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
[420] | 179 | $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; |
---|
[393] | 180 | if ( $user['status'] != 'admin' ) |
---|
| 181 | { |
---|
| 182 | $query.= " AND validated = 'true'"; |
---|
| 183 | } |
---|
[166] | 184 | $query.= ' ORDER BY date DESC'; |
---|
| 185 | $query.= ';'; |
---|
| 186 | $handleresult = mysql_query( $query ); |
---|
| 187 | while ( $subrow = mysql_fetch_array( $handleresult ) ) |
---|
| 188 | { |
---|
| 189 | $author = $subrow['author']; |
---|
[393] | 190 | if ( empty($subrow['author'] )) $author = $lang['guest']; |
---|
[180] | 191 | $content = nl2br( $subrow['content'] ); |
---|
| 192 | |
---|
| 193 | // replace _word_ by an underlined word |
---|
| 194 | $pattern = '/_([^\s]*)_/'; |
---|
| 195 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
| 196 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
| 197 | |
---|
| 198 | // replace *word* by a bolded word |
---|
| 199 | $pattern = '/\*([^\s]*)\*/'; |
---|
| 200 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
| 201 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
| 202 | |
---|
| 203 | // replace /word/ by an italic word |
---|
| 204 | $pattern = '/\/([^\s]*)\//'; |
---|
| 205 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
| 206 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
[420] | 207 | $template->assign_block_vars( |
---|
| 208 | 'picture.comment',array( |
---|
| 209 | 'COMMENT_AUTHOR'=>$author, |
---|
| 210 | 'COMMENT_DATE'=>format_date( $subrow['date'],'mysql_datetime',true ), |
---|
| 211 | 'COMMENT'=>$content, |
---|
| 212 | )); |
---|
| 213 | if ( $user['status'] == 'admin' ) |
---|
| 214 | { |
---|
| 215 | $template->assign_block_vars( |
---|
| 216 | 'picture.comment.validation', array( |
---|
| 217 | 'ID'=> $subrow['id'], |
---|
| 218 | 'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': '' |
---|
| 219 | )); |
---|
| 220 | } |
---|
[166] | 221 | } |
---|
| 222 | } |
---|
| 223 | //----------------------------------------------------------- html code display |
---|
[393] | 224 | if (defined('IN_ADMIN')) |
---|
| 225 | { |
---|
| 226 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
| 227 | } |
---|
| 228 | else |
---|
| 229 | { |
---|
| 230 | $template->assign_block_vars('title',array()); |
---|
| 231 | $template->pparse('comments'); |
---|
| 232 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
| 233 | } |
---|
[362] | 234 | ?> |
---|