1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | comments.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-03-20 00:52:37 +0000 (Sat, 20 Mar 2004) $ |
---|
10 | // | last modifier : $Author: gweltas $ |
---|
11 | // | revision : $Revision: 393 $ |
---|
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 | //----------------------------------------------------------- include |
---|
29 | if (!defined('IN_ADMIN')) |
---|
30 | { |
---|
31 | 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 | // |
---|
73 | if (!defined('IN_ADMIN')) |
---|
74 | { |
---|
75 | $title= $lang['title_comments']; |
---|
76 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
77 | } |
---|
78 | |
---|
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['search_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 ) { |
---|
94 | $url = $PHP_SELF.'?last_days='.($option - 1); |
---|
95 | if (defined('IN_ADMIN')) $url.= '&page=comments'; |
---|
96 | $template->assign_block_vars('last_day_option', array ( |
---|
97 | 'OPTION'=>$option, |
---|
98 | 'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''), |
---|
99 | 'U_OPTION'=>add_session_id( $url ) |
---|
100 | )); |
---|
101 | } |
---|
102 | |
---|
103 | // 1. retrieving picture ids which have comments recently added |
---|
104 | $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) ); |
---|
105 | list($year,$month,$day) = explode( '-', $date); |
---|
106 | $maxtime = mktime( 0,0,0,$month,$day,$year ); |
---|
107 | $query = 'SELECT DISTINCT(ic.image_id) as image_id,'; |
---|
108 | $query.= '(ic.category_id) as category_id'; |
---|
109 | $query.= ' FROM '.COMMENTS_TABLE.' AS c'; |
---|
110 | $query.= ', '.IMAGE_CATEGORY_TABLE.' AS ic'; |
---|
111 | $query.= ' WHERE c.image_id = ic.image_id'; |
---|
112 | $query.= ' AND date > '.$maxtime; |
---|
113 | if ( $user['status'] != 'admin' ) |
---|
114 | { |
---|
115 | $query.= " AND validated = 'true'"; |
---|
116 | // we must not show pictures of a forbidden category |
---|
117 | if ( $user['forbidden_categories'] != '' ) |
---|
118 | { |
---|
119 | $query.= ' AND category_id NOT IN '; |
---|
120 | $query.= '('.$user['forbidden_categories'].')'; |
---|
121 | } |
---|
122 | } |
---|
123 | $query.= ' ORDER BY ic.image_id DESC'; |
---|
124 | $query.= ';'; |
---|
125 | $result = mysql_query( $query ); |
---|
126 | if ( $user['status'] == 'admin' ) |
---|
127 | { |
---|
128 | $template->assign_block_vars('validation', array()); |
---|
129 | } |
---|
130 | while ( $row = mysql_fetch_array( $result ) ) |
---|
131 | { |
---|
132 | $category_id=$row['category_id']; |
---|
133 | |
---|
134 | // for each picture, getting informations for displaying thumbnail and |
---|
135 | // link to the full size picture |
---|
136 | $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext'; |
---|
137 | $query.= ' FROM '.IMAGES_TABLE; |
---|
138 | $query.= ' WHERE id = '.$row['image_id']; |
---|
139 | $query.= ';'; |
---|
140 | $subresult = mysql_query( $query ); |
---|
141 | $subrow = mysql_fetch_array( $subresult ); |
---|
142 | |
---|
143 | if ( !isset($array_cat_directories[$subrow['cat_id']]) ) |
---|
144 | { |
---|
145 | $array_cat_directories[$subrow['cat_id']] = |
---|
146 | get_complete_dir( $subrow['cat_id'] ); |
---|
147 | $cat_result = get_cat_info( $subrow['cat_id'] ); |
---|
148 | $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id']; |
---|
149 | $array_cat_names[$subrow['cat_id']] = |
---|
150 | get_cat_display_name( $cat_result['name'], ' > ', '' ); |
---|
151 | } |
---|
152 | |
---|
153 | $file = get_filename_wo_extension( $subrow['file'] ); |
---|
154 | // name of the picture |
---|
155 | $name = $array_cat_names[$category_id].' > '; |
---|
156 | if (!empty($subrow['name'])) $name.= $subrow['name']; |
---|
157 | else $name.= str_replace( '_', ' ', $file ); |
---|
158 | $name.= ' [ '.$subrow['file'].' ]'; |
---|
159 | // source of the thumbnail picture |
---|
160 | $src = $array_cat_directories[$subrow['cat_id']]; |
---|
161 | $src.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
162 | $src.= $file.'.'.$subrow['tn_ext']; |
---|
163 | // link to the full size picture |
---|
164 | $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id; |
---|
165 | $url.= '&image_id='.$row['image_id']; |
---|
166 | |
---|
167 | $template->assign_block_vars('picture',array( |
---|
168 | 'TITLE_IMG'=>$name, |
---|
169 | 'I_THUMB'=>$src, |
---|
170 | 'U_THUMB'=>add_session_id( $url ) |
---|
171 | )); |
---|
172 | |
---|
173 | // for each picture, retrieving all comments |
---|
174 | $query = 'SELECT * FROM '.COMMENTS_TABLE; |
---|
175 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
176 | $query.= ' AND date > '.$maxtime; |
---|
177 | if ( $user['status'] != 'admin' ) |
---|
178 | { |
---|
179 | $query.= " AND validated = 'true'"; |
---|
180 | } |
---|
181 | $query.= ' ORDER BY date DESC'; |
---|
182 | $query.= ';'; |
---|
183 | $handleresult = mysql_query( $query ); |
---|
184 | while ( $subrow = mysql_fetch_array( $handleresult ) ) |
---|
185 | { |
---|
186 | $author = $subrow['author']; |
---|
187 | if ( empty($subrow['author'] )) $author = $lang['guest']; |
---|
188 | $content = nl2br( $subrow['content'] ); |
---|
189 | |
---|
190 | // replace _word_ by an underlined word |
---|
191 | $pattern = '/_([^\s]*)_/'; |
---|
192 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
193 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
194 | |
---|
195 | // replace *word* by a bolded word |
---|
196 | $pattern = '/\*([^\s]*)\*/'; |
---|
197 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
198 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
199 | |
---|
200 | // replace /word/ by an italic word |
---|
201 | $pattern = '/\/([^\s]*)\//'; |
---|
202 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
203 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
204 | $template->assign_block_vars('picture.comment',array( |
---|
205 | 'COMMENT_AUTHOR'=>$author, |
---|
206 | 'COMMENT_DATE'=>format_date( $subrow['date'], 'unix', true ), |
---|
207 | 'COMMENT'=>$content, |
---|
208 | )); |
---|
209 | if ( $user['status'] == 'admin' ) |
---|
210 | { |
---|
211 | $template->assign_block_vars('picture.comment.validation', array( |
---|
212 | 'ID'=> $subrow['id'], |
---|
213 | 'CHECKED'=>($subrow['validated']=='false')?'checked="checked"': '' |
---|
214 | )); |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|
218 | //----------------------------------------------------------- html code display |
---|
219 | if (defined('IN_ADMIN')) |
---|
220 | { |
---|
221 | $template->assign_var_from_handle('ADMIN_CONTENT', 'comments'); |
---|
222 | } |
---|
223 | else |
---|
224 | { |
---|
225 | $template->assign_block_vars('title',array()); |
---|
226 | $template->pparse('comments'); |
---|
227 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
228 | } |
---|
229 | ?> |
---|