Changeset 579 for trunk/comments.php
- Timestamp:
- Oct 23, 2004, 7:56:46 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/comments.php
r527 r579 26 26 // +-----------------------------------------------------------------------+ 27 27 28 //----------------------------------------------------------- include 28 // +-----------------------------------------------------------------------+ 29 // | initialization | 30 // +-----------------------------------------------------------------------+ 29 31 if (!defined('IN_ADMIN')) 30 32 { 31 33 define('PHPWG_ROOT_PATH','./'); 32 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); 33 } 34 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(); 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 } 68 //------------------------------------------------------- last comments display 69 70 // 71 // Start output of page 72 // 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 mysql_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 mysql_query($query); 67 } 68 // +-----------------------------------------------------------------------+ 69 // | page header and options | 70 // +-----------------------------------------------------------------------+ 73 71 if (!defined('IN_ADMIN')) 74 72 { … … 77 75 } 78 76 79 $template->set_filenames( array('comments'=>'comments.tpl'));80 $template->assign_vars( array(81 'L_COMMENT_TITLE' => $title,82 'L_COMMENT_STATS' => $lang['stats_last_days'],83 'L_COMMENT_RETURN' => $lang['return_main_page'],84 'L_DELETE' =>$lang['delete'],85 'L_VALIDATE'=>$lang['submit'],86 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')90 ) 91 ); 92 93 foreach ( $conf['last_days'] as $option ){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['return_main_page'], 83 'L_DELETE' =>$lang['delete'], 84 'L_VALIDATE'=>$lang['submit'], 85 86 'U_HOME' => add_session_id(PHPWG_ROOT_PATH.'category.php') 87 ) 88 ); 89 90 foreach ($conf['last_days'] as $option) 91 { 94 92 $url = $_SERVER['PHP_SELF'].'?last_days='.($option - 1); 95 if (defined('IN_ADMIN')) $url.= '&page=comments'; 93 if (defined('IN_ADMIN')) 94 { 95 $url.= '&page=comments'; 96 } 96 97 $template->assign_block_vars( 97 98 'last_day_option', 98 99 array( 99 100 'OPTION'=>$option, 100 'T_STYLE'=>(( $option == MAX_DAYS + 1)?'text-decoration:underline;':''),101 'U_OPTION'=>add_session_id( $url)101 'T_STYLE'=>(($option == MAX_DAYS + 1)?'text-decoration:underline;':''), 102 'U_OPTION'=>add_session_id($url) 102 103 ) 103 104 ); 104 105 } 105 106 // +-----------------------------------------------------------------------+ 107 // | last comments display | 108 // +-----------------------------------------------------------------------+ 106 109 // 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,'; 111 $query.= '(ic.category_id) as category_id'; 112 $query.= ' FROM '.COMMENTS_TABLE.' AS c'; 113 $query.= ', '.IMAGE_CATEGORY_TABLE.' AS ic'; 114 $query.= ' WHERE c.image_id = ic.image_id'; 115 $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; 116 if ( $user['status'] != 'admin' ) 117 { 118 $query.= " AND validated = 'true'"; 110 $maxdate = date('Y-m-d', strtotime('-'.MAX_DAYS.' day')); 111 112 $query = ' 113 SELECT DISTINCT(ic.image_id) AS image_id,(ic.category_id) AS category_id 114 FROM '.COMMENTS_TABLE.' AS c, '.IMAGE_CATEGORY_TABLE.' AS ic 115 WHERE c.image_id = ic.image_id 116 AND date >= \''.$maxdate.'\''; 117 if ($user['status'] != 'admin') 118 { 119 $query.= " 120 AND validated = 'true'"; 119 121 // 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 } 125 } 126 $query.= ' ORDER BY ic.image_id DESC'; 127 $query.= ';'; 128 $result = mysql_query( $query ); 129 if ( $user['status'] == 'admin' ) 122 if ($user['forbidden_categories'] != '') 123 { 124 $query.= ' 125 AND category_id NOT IN ('.$user['forbidden_categories'].')'; 126 } 127 } 128 $query.= ' 129 ORDER BY ic.image_id DESC 130 ;'; 131 $result = mysql_query($query); 132 if ($user['status'] == 'admin') 130 133 { 131 134 $template->assign_block_vars('validation', array()); 132 135 } 133 while ( $row = mysql_fetch_array( $result ) ) 134 { 135 $category_id=$row['category_id']; 136 137 // for each picture, getting informations for displaying thumbnail and 138 // link to the full size picture 139 $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext'; 140 $query.= ' FROM '.IMAGES_TABLE; 141 $query.= ' WHERE id = '.$row['image_id']; 142 $query.= ';'; 143 $subresult = mysql_query( $query ); 144 $subrow = mysql_fetch_array( $subresult ); 145 146 if ( !isset($array_cat_directories[$subrow['cat_id']]) ) 136 while ($row = mysql_fetch_array($result)) 137 { 138 $category_id = $row['category_id']; 139 140 // for each picture, getting informations for displaying thumbnail and 141 // link to the full size picture 142 $query = ' 143 SELECT name,file,storage_category_id as cat_id,tn_ext 144 FROM '.IMAGES_TABLE.' 145 WHERE id = '.$row['image_id'].' 146 ;'; 147 $subresult = mysql_query($query); 148 $subrow = mysql_fetch_array($subresult); 149 150 if (!isset($array_cat_names[$subrow['cat_id']])) 151 { 152 $cat_result = get_cat_info($subrow['cat_id']); 153 $array_cat_names[$subrow['cat_id']] = 154 get_cat_display_name($cat_result['name'], ' > ', ''); 155 } 156 157 // name of the picture 158 $name = $array_cat_names[$category_id].' > '; 159 if (!empty($subrow['name'])) 160 { 161 $name.= $subrow['name']; 162 } 163 else 164 { 165 $name.= str_replace('_',' ',get_filename_wo_extension($subrow['file'])); 166 } 167 $name.= ' [ '.$subrow['file'].' ]'; 168 // source of the thumbnail picture 169 $thumbnail_src = get_thumbnail_src($subrow['file'], 170 $subrow['cat_id'], 171 @$subrow['tn_ext']); 172 // link to the full size picture 173 $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; 174 $url.= '&image_id='.$row['image_id']; 175 176 $template->assign_block_vars( 177 'picture', 178 array( 179 'TITLE_IMG'=>$name, 180 'I_THUMB'=>$thumbnail_src, 181 'U_THUMB'=>add_session_id($url) 182 )); 183 184 // for each picture, retrieving all comments 185 $query = ' 186 SELECT * 187 FROM '.COMMENTS_TABLE.' 188 WHERE image_id = '.$row['image_id'].' 189 AND date >= \''.$maxdate.'\''; 190 if ($user['status'] != 'admin') 191 { 192 $query.= ' 193 AND validated = \'true\''; 194 } 195 $query.= ' 196 ORDER BY date DESC 197 ;'; 198 $handleresult = mysql_query($query); 199 while ($subrow = mysql_fetch_array($handleresult)) 200 { 201 $author = $subrow['author']; 202 if (empty($subrow['author'])) 147 203 { 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'], ' > ', '' ); 204 $author = $lang['guest']; 154 205 } 155 206 156 $file = get_filename_wo_extension( $subrow['file'] ); 157 // name of the picture 158 $name = $array_cat_names[$category_id].' > '; 159 if (!empty($subrow['name'])) $name.= $subrow['name']; 160 else $name.= str_replace( '_', ' ', $file ); 161 $name.= ' [ '.$subrow['file'].' ]'; 162 // source of the thumbnail picture 163 if (isset($subrow['tn_ext']) and $subrow['tn_ext'] != '') 207 $template->assign_block_vars( 208 'picture.comment', 209 array( 210 'COMMENT_AUTHOR'=>$author, 211 'COMMENT_DATE'=>format_date($subrow['date'],'mysql_datetime',true), 212 'COMMENT'=>parse_comment_content($subrow['content']), 213 )); 214 215 if ($user['status'] == 'admin') 164 216 { 165 $src = $array_cat_directories[$subrow['cat_id']]; 166 $src.= 'thumbnail/'.$conf['prefix_thumbnail']; 167 $src.= $file.'.'.$subrow['tn_ext']; 217 $template->assign_block_vars( 218 'picture.comment.validation', 219 array( 220 'ID'=> $subrow['id'], 221 'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': '' 222 )); 168 223 } 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 176 $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; 177 $url.= '&image_id='.$row['image_id']; 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 187 // for each picture, retrieving all comments 188 $query = 'SELECT * FROM '.COMMENTS_TABLE; 189 $query.= ' WHERE image_id = '.$row['image_id']; 190 $query.= ' AND date > FROM_UNIXTIME('.$maxtime.')'; 191 if ( $user['status'] != 'admin' ) 192 { 193 $query.= " AND validated = 'true'"; 194 } 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']; 201 if ( empty($subrow['author'] )) $author = $lang['guest']; 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 ); 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 } 232 } 233 } 234 //----------------------------------------------------------- html code display 224 } 225 } 226 // +-----------------------------------------------------------------------+ 227 // | html code display | 228 // +-----------------------------------------------------------------------+ 235 229 if (defined('IN_ADMIN')) 236 230 {
Note: See TracChangeset
for help on using the changeset viewer.