1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * comments.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: comments.php 350 2004-02-05 23:18:05Z z0rglub $ |
---|
9 | * * |
---|
10 | ***************************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************************** |
---|
13 | * * |
---|
14 | * This program is free software; you can redistribute it and/or modify * |
---|
15 | * it under the terms of the GNU General Public License as published by * |
---|
16 | * the Free Software Foundation; * |
---|
17 | * * |
---|
18 | ***************************************************************************/ |
---|
19 | |
---|
20 | include_once( './include/init.inc.php' ); |
---|
21 | //------------------------------------------------------------------- functions |
---|
22 | function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids ) |
---|
23 | { |
---|
24 | global $vtp,$handle,$lang,$conf, |
---|
25 | $array_cat_directories,$array_cat_site_id,$array_cat_names; |
---|
26 | |
---|
27 | while ( $row = mysql_fetch_array( $mysql_result ) ) |
---|
28 | { |
---|
29 | $vtp->addSession( $handle, 'picture' ); |
---|
30 | // 1. find a category wich is authorized for the user to display a |
---|
31 | // category name. |
---|
32 | $query = 'SELECT category_id'; |
---|
33 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
34 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
35 | if ( count( $forbidden_cat_ids ) > 0 ) |
---|
36 | { |
---|
37 | $query.= ' AND category_id NOT IN ('; |
---|
38 | foreach ( $forbidden_cat_ids as $i => $restricted_cat ) { |
---|
39 | if ( $i > 0 ) $query.= ','; |
---|
40 | $query.= $restricted_cat; |
---|
41 | } |
---|
42 | $query.= ')'; |
---|
43 | } |
---|
44 | $query.= ' ORDER BY RAND()'; |
---|
45 | $query.= ';'; |
---|
46 | $subrow = mysql_fetch_array( mysql_query( $query ) ); |
---|
47 | $category_id = $subrow['category_id']; |
---|
48 | |
---|
49 | if ( !isset($array_cat_directories[$category_id])) |
---|
50 | { |
---|
51 | $array_cat_directories[$category_id] = |
---|
52 | get_complete_dir( $category_id ); |
---|
53 | $cat_result = get_cat_info( $category_id ); |
---|
54 | $array_cat_site_id[$category_id] = $cat_result['site_id']; |
---|
55 | $array_cat_names[$category_id] = |
---|
56 | get_cat_display_name( $cat_result['name'], ' > ', '' ); |
---|
57 | } |
---|
58 | |
---|
59 | // 2. for each picture, getting informations for displaying thumbnail and |
---|
60 | // link to the full size picture |
---|
61 | $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext'; |
---|
62 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
63 | $query.= ' WHERE id = '.$row['image_id']; |
---|
64 | $query.= ';'; |
---|
65 | $subresult = mysql_query( $query ); |
---|
66 | $subrow = mysql_fetch_array( $subresult ); |
---|
67 | |
---|
68 | if ( $array_cat_directories[$subrow['cat_id']] == '' ) |
---|
69 | { |
---|
70 | $array_cat_directories[$subrow['cat_id']] = |
---|
71 | get_complete_dir( $subrow['cat_id'] ); |
---|
72 | $cat_result = get_cat_info( $subrow['cat_id'] ); |
---|
73 | $array_cat_site_id[$subrow['cat_id']] = $cat_result['site_id']; |
---|
74 | $array_cat_names[$subrow['cat_id']] = |
---|
75 | get_cat_display_name( $cat_result['name'], ' > ', '' ); |
---|
76 | } |
---|
77 | |
---|
78 | $file = get_filename_wo_extension( $subrow['file'] ); |
---|
79 | // name of the picture |
---|
80 | $name = $array_cat_names[$category_id].' > '; |
---|
81 | if ( $subrow['name'] != '' ) $name.= $subrow['name']; |
---|
82 | else $name.= str_replace( '_', ' ', $file ); |
---|
83 | $name.= ' [ '.$subrow['file'].' ]'; |
---|
84 | $vtp->setVar( $handle, 'picture.title', $name ); |
---|
85 | // source of the thumbnail picture |
---|
86 | $src = $array_cat_directories[$subrow['cat_id']]; |
---|
87 | $src.= 'thumbnail/'.$conf['prefix_thumbnail']; |
---|
88 | $src.= $file.'.'.$subrow['tn_ext']; |
---|
89 | $vtp->setVar( $handle, 'picture.thumb_src', $src ); |
---|
90 | // link to the full size picture |
---|
91 | $url = './picture.php?cat='.$category_id; |
---|
92 | $url.= '&image_id='.$row['image_id']; |
---|
93 | $vtp->setVar( $handle, 'picture.thumb_url', add_session_id( $url ) ); |
---|
94 | // 3. for each picture, retrieving all comments |
---|
95 | $query = 'SELECT id,date,author,content'; |
---|
96 | $query.= ' FROM '.PREFIX_TABLE.'comments'; |
---|
97 | $query.= ' WHERE image_id = '.$row['image_id']; |
---|
98 | $query.= ' AND date > '.$maxtime; |
---|
99 | $query.= " AND validated = 'true'"; |
---|
100 | $query.= ' ORDER BY date DESC'; |
---|
101 | $query.= ';'; |
---|
102 | $handleresult = mysql_query( $query ); |
---|
103 | while ( $subrow = mysql_fetch_array( $handleresult ) ) |
---|
104 | { |
---|
105 | $vtp->addSession( $handle, 'comment' ); |
---|
106 | $author = $subrow['author']; |
---|
107 | if ( $subrow['author'] == '' ) $author = $lang['guest']; |
---|
108 | $vtp->setVar( $handle, 'comment.author', $author ); |
---|
109 | $displayed_date = format_date( $subrow['date'], 'unix', true ); |
---|
110 | $vtp->setVar( $handle, 'comment.date', $displayed_date ); |
---|
111 | |
---|
112 | $content = nl2br( $subrow['content'] ); |
---|
113 | |
---|
114 | // replace _word_ by an underlined word |
---|
115 | $pattern = '/_([^\s]*)_/'; |
---|
116 | $replacement = '<span style="text-decoration:underline;">\1</span>'; |
---|
117 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
118 | |
---|
119 | // replace *word* by a bolded word |
---|
120 | $pattern = '/\*([^\s]*)\*/'; |
---|
121 | $replacement = '<span style="font-weight:bold;">\1</span>'; |
---|
122 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
123 | |
---|
124 | // replace /word/ by an italic word |
---|
125 | $pattern = '/\/([^\s]*)\//'; |
---|
126 | $replacement = '<span style="font-style:italic;">\1</span>'; |
---|
127 | $content = preg_replace( $pattern, $replacement, $content ); |
---|
128 | |
---|
129 | $vtp->setVar( $handle, 'comment.content', $content ); |
---|
130 | $vtp->closeSession( $handle, 'comment' ); |
---|
131 | } |
---|
132 | $vtp->closeSession( $handle, 'picture' ); |
---|
133 | } |
---|
134 | } |
---|
135 | //----------------------------------------------------- template initialization |
---|
136 | // |
---|
137 | // Start output of page |
---|
138 | // |
---|
139 | $title= $lang['title_comments']; |
---|
140 | include('include/page_header.php'); |
---|
141 | |
---|
142 | $handle = $vtp->Open( './template/'.$user['template'].'/comments.vtp' ); |
---|
143 | initialize_template(); |
---|
144 | $tpl = array( 'title_comments','stats_last_days','search_return_main_page' ); |
---|
145 | templatize_array( $tpl, 'lang', $handle ); |
---|
146 | //--------------------------------------------------- number of days to display |
---|
147 | if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] ); |
---|
148 | else define( 'MAX_DAYS', 0 ); |
---|
149 | //----------------------------------------- non specific section initialization |
---|
150 | $array_cat_directories = array(); |
---|
151 | $array_cat_names = array(); |
---|
152 | $array_cat_site_id = array(); |
---|
153 | //------------------------------------------------------- last comments display |
---|
154 | foreach ( $conf['last_days'] as $option ) { |
---|
155 | $vtp->addSession( $handle, 'last_day_option' ); |
---|
156 | $vtp->setVar( $handle, 'last_day_option.option', $option ); |
---|
157 | $url = './comments.php'; |
---|
158 | $url.= '?last_days='.($option - 1); |
---|
159 | $vtp->setVar( $handle, 'last_day_option.link', add_session_id( $url ) ); |
---|
160 | $style = ''; |
---|
161 | if ( $option == MAX_DAYS + 1 ) $style = 'text-decoration:underline;'; |
---|
162 | $vtp->setVar( $handle, 'last_day_option.style', $style ); |
---|
163 | $vtp->closeSession( $handle, 'last_day_option' ); |
---|
164 | } |
---|
165 | $vtp->setVar( $handle, 'back_url', add_session_id( './category.php' ) ); |
---|
166 | // 1. retrieving picture ids which have comments recently added |
---|
167 | $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) ); |
---|
168 | list($year,$month,$day) = explode( '-', $date); |
---|
169 | $maxtime = mktime( 0,0,0,$month,$day,$year ); |
---|
170 | $query = 'SELECT DISTINCT(ic.image_id) as image_id'; |
---|
171 | $query.= ' FROM '.PREFIX_TABLE.'comments AS c'; |
---|
172 | $query.= ', '.PREFIX_TABLE.'image_category AS ic'; |
---|
173 | $query.= ' WHERE c.image_id = ic.image_id'; |
---|
174 | $query.= ' AND date > '.$maxtime; |
---|
175 | $query.= " AND validated = 'true'"; |
---|
176 | // we must not show pictures of a forbidden category |
---|
177 | if ( $user['forbidden_categories'] != '' ) |
---|
178 | { |
---|
179 | $query.= ' AND category_id NOT IN '; |
---|
180 | $query.= '('.$user['forbidden_categories'].')'; |
---|
181 | } |
---|
182 | $query.= ' ORDER BY ic.image_id DESC'; |
---|
183 | $query.= ';'; |
---|
184 | $result = mysql_query( $query ); |
---|
185 | display_pictures( $result, $maxtime, $user['restrictions'] ); |
---|
186 | //----------------------------------------------------------- html code display |
---|
187 | $output.= $vtp->Display( $handle, 0 ); |
---|
188 | include('include/page_tail.php'); |
---|
189 | ?> |
---|