PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
3.1.7 3.1.6 3.1.5 3.1.4 3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 All 139 releases
← All changes | wpf-includes/class-posts.php +72 -327 1.3.1beta-4 View file →
@@ -4,29 +4,16 @@
4 4
5 5 class wpForoPost{
6 6
7 7 private $wpforo;
8 - public static $cache = array( 'posts' => array(), 'post' => array(), 'item' => array(), 'topic_slug' => array(), 'forum_slug' => array(), 'post_url' => array() );
9 8
10 9 function __construct( $wpForo ){
11 10 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
12 11 }
13 12
14 - public function get_cache( $var ){
15 - if( isset(self::$cache[$var]) ) return self::$cache[$var];
16 - }
17 -
18 13 public function add( $args = array() ){
19 -
20 - //This variable will be based on according CAN of guest usergroup once Guest Posing is ready
21 - $guestposting = false;
22 -
23 14 if( empty($args) && empty($_REQUEST['post']) ){ $this->wpforo->notice->add('Reply request error', 'error'); return FALSE; }
24 15 if( empty($args) && !empty($_REQUEST['post']) ){ $args = $_REQUEST['post']; $args['body'] = $_REQUEST['postbody']; }
25 - if( !isset($args['body']) || !$args['body'] ){ $this->wpforo->notice->add('Post is empty', 'error'); return FALSE; }
26 - $args['name'] = (isset($args['name']) ? $args['name'] : '' );
27 - $args['email'] = (isset($args['email']) ? $args['email'] : '' );
28 - if( isset($args['userid']) && $args['userid'] == 0 && $args['name'] && $args['email'] ) $guestposting = true;
29 16
30 17 extract($args, EXTR_OVERWRITE);
31 18
32 19 if( !isset($topicid) || !$topicid ){ $this->wpforo->notice->add('Error: No topic selected', 'error'); return FALSE; }
@@ -37,17 +24,14 @@
37 24 $this->wpforo->notice->add('Can\'t write a post: This topic is closed', 'error');
38 25 return FALSE;
39 26 }
40 27
41 - if( !$guestposting && !$this->wpforo->perm->forum_can('cr', $topic['forumid']) ){
28 + if( !$this->wpforo->perm->forum_can(intval($topic['forumid']), 'cr') ){
42 29 $this->wpforo->notice->add('You haven\'t permission to create post into this forum', 'error');
43 30 return FALSE;
44 31 }
45 32
46 - do_action( 'wpforo_start_add_post', $args );
47 -
48 33 $post = $args;
49 - $post['forumid'] = $forumid = (isset($topic['forumid']) ? intval($topic['forumid']) : 0);
50 34 $post['parentid'] = $parentid = (isset($parentid) ? intval($parentid) : 0);
51 35 $post['title'] = $title = (isset($title) ? wpforo_text( trim($title), 250, false ) : '');
52 36 $post['body'] = $body = ( isset($body) ? preg_replace('#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", $body) : '' );
53 37 $post['created'] = $created = ( isset($created) ? $created : current_time( 'mysql', 1 ) );
@@ -53,9 +37,8 @@
53 37 $post['created'] = $created = ( isset($created) ? $created : current_time( 'mysql', 1 ) );
54 38 $post['userid'] = $userid = ( isset($userid) ? intval($userid) : $this->wpforo->current_userid );
55 39
56 40 $post = apply_filters('wpforo_add_post_data_filter', $post);
57 -
58 41 if(empty($post)) return FALSE;
59 42
60 43 extract($post, EXTR_OVERWRITE);
61 44
@@ -65,11 +48,8 @@
65 48 if(isset($title)) $title = sanitize_text_field(trim($title));
66 49 if(isset($created)) $created = sanitize_text_field($created);
67 50 if(isset($userid)) $userid = intval($userid);
68 51 if(isset($body)) $body = wpforo_kses(trim($body), 'post');
69 - if(isset($status)) $status = intval($status);
70 - if(isset($name)) $name = strip_tags(trim($name));
71 - if(isset($email)) $email = strip_tags(trim($email));
72 52
73 53 do_action( 'wpforo_before_add_post', $post );
74 54
75 55 if(
@@ -75,9 +55,9 @@
75 55 if(
76 56 $this->wpforo->db->insert(
77 57 $this->wpforo->db->prefix . 'wpforo_posts',
78 58 array(
79 - 'forumid' => $forumid,
59 + 'forumid' => (isset($topic['forumid']) ? intval($topic['forumid']) : 0),
80 60 'topicid' => $topicid,
81 61 'parentid' => $parentid,
82 62 'userid' => $userid,
83 63 'title' => stripslashes($title),
@@ -82,14 +62,11 @@
82 62 'userid' => $userid,
83 63 'title' => stripslashes($title),
84 64 'body' => stripslashes($body),
85 65 'created' => $created,
86 - 'modified' => $created,
87 - 'status' => (isset($status) ? $status : 0),
88 - 'name' => $name,
89 - 'email' => $email
66 + 'modified' => $created
90 67 ),
91 - array('%d','%d','%d','%d','%s','%s','%s','%s','%d','%s','%s')
68 + array('%d','%d','%d','%d','%s','%s','%s','%s')
92 69 )
93 70 ){
94 71 $postid = $this->wpforo->db->insert_id;
95 72
@@ -109,11 +86,10 @@
109 86
110 87 $post['postid'] = $postid;
111 88 $post['posturl'] = $this->get_post_url($postid);
112 89
113 - do_action( 'wpforo_after_add_post', $post, $topic );
90 + do_action( 'wpforo_after_add_post', $post );
114 91
115 - wpforo_clean_cache($postid, 'post');
116 92 $this->wpforo->member->reset($userid);
117 93 $this->wpforo->notice->add('You successfully replied', 'success');
118 94 return $postid;
119 95 }
@@ -122,42 +98,29 @@
122 98 return FALSE;
123 99 }
124 100
125 101 public function edit( $args = array() ){
126 -
127 - //This variable will be based on according CAN of guest usergroup once Guest Posing is ready
128 - $guestposting = false;
129 -
130 102 if( empty($args) && (!isset($_REQUEST['post']) || empty($_REQUEST['post'])) ) return FALSE;
131 103 if( empty($args) && !empty($_REQUEST['post']) ){ $args = $_REQUEST['post']; $args['body'] = $_REQUEST['postbody']; }
132 104
133 - do_action( 'wpforo_start_edit_post', $args );
105 + $args = apply_filters('wpforo_edit_post_data_filter', $args);
106 + if(empty($args)) return FALSE;
134 107
135 - if( !isset($args['postid']) || !$args['postid'] || !is_numeric($args['postid']) ){
108 + extract($args, EXTR_OVERWRITE);
109 +
110 + if( !isset($postid) || !$postid || !is_numeric($postid) ){
136 111 $this->wpforo->notice->add('Cannot update post data', 'error');
137 112 return FALSE;
138 113 }
139 - $args['postid'] = intval($args['postid']);
140 - if( !$post = $this->get_post($args['postid']) ){ $this->wpforo->notice->add('No Posts found for update', 'error'); return FALSE; }
141 114
142 - $args['userid'] = $post['userid'];
143 - $args['status'] = $post['status'];
144 -
145 - if( isset($args['userid']) && $args['userid'] == 0 && isset($args['name']) && isset($args['email']) ) $guestposting = true;
115 + $postid = intval($postid);
146 116
147 - $args = apply_filters('wpforo_edit_post_data_filter', $args);
148 - if(empty($args)) return FALSE;
117 + if( !$post = $this->get_post($postid) ){ $this->wpforo->notice->add('No Posts found for update', 'error'); return FALSE; }
149 118
150 - extract($args, EXTR_OVERWRITE);
151 -
152 - if( !$guestposting ){
153 - $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
154 - if( !($this->wpforo->perm->forum_can('er', $post['forumid']) ||
155 - ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can('eor', $post['forumid']) &&
156 - $diff < $this->wpforo->post_options['eor_durr'])) ){
157 - $this->wpforo->notice->add('You haven\'t permission to edit post from this forum', 'error');
158 - return FALSE;
159 - }
119 + $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
120 + if( !($this->wpforo->perm->forum_can($post['forumid'], 'er') || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can($post['forumid'], 'eor') && $diff < $this->wpforo->post_options['eor_durr'])) ){
121 + $this->wpforo->notice->add('You haven\'t permission to edit post from this forum', 'error');
122 + return FALSE;
160 123 }
161 124
162 125 $title = (isset($title) ? wpforo_text( trim($title), 250, false ) : '');
163 126 $body = ( isset($body) ? preg_replace('#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", $body) : '' );
@@ -169,36 +132,21 @@
169 132 if(isset($slug)) $slug = sanitize_title($slug);
170 133 if(isset($created)) $created = sanitize_text_field($created);
171 134 if(isset($userid)) $userid = intval($userid);
172 135 if(isset($body)) $body = wpforo_kses(trim($body), 'post');
173 - if(isset($status)) $status = intval($status);
174 - if(isset($name)) $name = strip_tags(trim($name));
175 - if(isset($email)) $email = strip_tags(trim($email));
176 136
177 - $title = ( isset($title) ? stripslashes($title) : stripslashes($post['title']) );
178 - $body = ( (isset($body) && $body) ? stripslashes($body) : stripslashes($post['body']) );
179 - $status = ( isset($status) ? $status : intval($post['status']) );
180 - $name = ( isset($name) ? stripslashes($name) : stripslashes($post['name']) );
181 - $email = ( isset($email) ? stripslashes($email) : stripslashes($post['email']) );
182 -
183 137 if( FALSE !== $this->wpforo->db->update(
184 138 $this->wpforo->db->prefix."wpforo_posts",
185 139 array(
186 - 'title' => $title,
187 - 'body' => $body,
188 - 'modified' => current_time( 'mysql', 1 ),
189 - 'status' => $status,
190 - 'name' => $name,
191 - 'email' => $email,
140 + 'title' => stripslashes($title),
141 + 'body' => stripslashes($body),
142 + 'modified' => current_time( 'mysql', 1 )
192 143 ),
193 144 array('postid' => $postid),
194 - array('%s','%s','%s','%d','%s','%s'),
145 + array('%s','%s','%s'),
195 146 array('%d')
196 147 )
197 148 ){
198 - do_action( 'wpforo_after_edit_post', array( 'postid' => $postid, 'topicid' => $topicid, 'title' => $title, 'body' => $body, 'status' => $status, 'name' => $name, 'email' => $email) );
199 -
200 - wpforo_clean_cache($postid, 'post');
201 149 $this->wpforo->notice->add('This post successfully edited', 'success');
202 150 return $postid;
203 151 }
204 152
@@ -207,9 +155,9 @@
207 155 }
208 156
209 157 #################################################################################
210 158 /**
211 - * Delete post from DB
159 + * Delete topic from DB
212 160 *
213 161 * Returns true if successfully deleted or false.
214 162 *
215 163 * @since 1.0.0
@@ -216,25 +164,19 @@
216 164 *
217 165 * @return bool
218 166 */
219 167
220 - function delete($postid, $delete_cache = true){
168 + function delete($postid){
169 +
221 170 $postid = intval($postid);
222 171
223 - if( !$post = $this->get_post($postid) ) return true;
224 -
225 - do_action('wpforo_before_delete_post', $post);
226 -
172 + $post = $this->get_post($postid);
227 173 $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
228 - if( !($this->wpforo->perm->forum_can('dr', $post['forumid']) || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can('dor', $post['forumid']) && $diff < $this->wpforo->post_options['dor_durr'])) ){
174 + if( !($this->wpforo->perm->forum_can($post['forumid'], 'dr') || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can($post['forumid'], 'dor') && $diff < $this->wpforo->post_options['dor_durr'])) ){
229 175 $this->wpforo->notice->add('You haven\'t permission to delete post from this forum', 'error');
230 176 return FALSE;
231 177 }
232 178
233 - //Find and delete default atatchments before deleting post
234 - $this->delete_attachments( $postid );
235 -
236 - //Delete post
237 179 if( $this->wpforo->db->delete($this->wpforo->db->prefix . 'wpforo_posts', array( 'postid' => intval($postid) ), array( '%d' )) ){
238 180 $last_post = $this->get_posts( array('topicid' => intval($post['topicid']), 'order' => 'DESC', 'row_count' => 1) );
239 181 if(is_array($last_post) && !empty($last_post)){
240 182 $last_post = $last_post[0];
@@ -241,15 +183,8 @@
241 183 }else{
242 184 $last_post = array( 'created' => '0000-00-00 00:00:00', 'userid' => 0, 'postid' => 0 );
243 185 }
244 186
245 - $this->wpforo->db->delete(
246 - $this->wpforo->db->prefix.'wpforo_likes', array( 'postid' => $postid ), array( '%d' )
247 - );
248 - $this->wpforo->db->delete(
249 - $this->wpforo->db->prefix.'wpforo_votes', array( 'postid' => $postid ), array( '%d' )
250 - );
251 -
252 187 $answ_incr = '';
253 188 $comm_incr = '';
254 189 $forum = $this->wpforo->forum->get_forum($post['forumid']);
255 190 if( isset($forum['cat_layout']) && $forum['cat_layout'] == 3 ){
@@ -264,17 +199,12 @@
264 199 if( $this->wpforo->db->query( "UPDATE IGNORE `" . $this->wpforo->db->prefix . "wpforo_forums` SET `last_post_date` = '" . esc_sql($last_post['created']) . "', `last_userid` = " . intval($last_post['userid']) . ", `last_postid` = " . intval($last_post['postid']) . ", `posts` = IF( (`posts` - 1) < 0, 0, `posts` - 1 ) WHERE `forumid` = " . intval( $post['forumid'] ))){
265 200 if( $this->wpforo->db->query( "UPDATE IGNORE `" . $this->wpforo->db->prefix . "wpforo_profiles` SET `posts` = IF( (`posts` - 1) < 0, 0, `posts` - 1 ) $answ_incr $comm_incr WHERE `userid` = " . intval($post['userid']) ) ){
266 201 $this->wpforo->member->reset($post['userid']);
267 202 $this->wpforo->notice->add('This post successfully deleted', 'success');
203 + return TRUE;
268 204 }
269 205 }
270 206 }
271 -
272 - do_action('wpforo_after_delete_post', $post);
273 -
274 - if( $post['is_first_post'] ) return $this->wpforo->topic->delete($post['topicid']);
275 - if( $delete_cache ) wpforo_clean_cache(0, 'post');
276 - return TRUE;
277 207 }
278 208
279 209 $this->wpforo->notice->add('Post delete error', 'error');
280 210 return FALSE;
@@ -287,76 +217,51 @@
287 217 * Returns array from defined and default arguments.
288 218 *
289 219 * @since 1.0.0
290 220 *
221 + * @param mixed defined arguments array for returning
222 + *
291 223 * @return array
292 224 */
293 225 function get_post($postid){
294 226
295 227 $post = array();
296 - $cache = $this->wpforo->cache->on('memory_cashe');
297 -
298 - if( $cache && isset(self::$cache['post'][$postid]) ){
299 - return self::$cache['post'][$postid];
300 - }
301 -
302 - $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `postid` = " . intval($postid);
228 + $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `postid` = ".intval($postid);
303 229 $post = $this->wpforo->db->get_row($sql, ARRAY_A);
304 - if(!empty($post)) $post['userid'] = intval($post['userid']);
305 -
306 - if( isset($post['forumid']) && $post['forumid'] && !$this->wpforo->perm->forum_can('vf', $post['forumid']) ){
307 - return array();
230 + if(!empty($post)){
231 + $post['userid'] = intval($post['userid']);
232 + $post['body'] = wpforo_content_filter($post['body']);
308 233 }
309 -
310 - if( isset($post['status']) && $post['status'] && !wpforo_is_owner($post['userid'])){
311 - if( isset($post['forumid']) && $post['forumid'] && !$this->wpforo->perm->forum_can('au', $post['forumid']) ){
312 - return array();
313 - }
314 - }
315 -
316 - if($cache && isset($postid)){
317 - self::$cache['post'][$postid] = $post;
318 - }
319 -
320 - $post = apply_filters('wpforo_get_post', $post);
321 234 return $post;
322 235 }
323 -
324 236 /**
237 + * array get_topic(array or id(num))
325 238 * Returns merged arguments array from defined and default arguments.
326 239 *
327 240 * @since 1.0.0
328 241 *
329 - * @param array
242 + * @param array defined arguments array for returning
330 243 *
331 - * @return array
244 + * @return associative array where count is topic count and other numeric arrays with topic
332 245 */
333 246 function get_posts($args = array(), &$items_count = 0){
334 247
335 - $cache = $this->wpforo->cache->on('object_cashe');
336 -
337 248 $default = array(
338 249 'include' => array(), // array( 2, 10, 25 )
339 250 'exclude' => array(), // array( 2, 10, 25 )
340 251
341 252 'topicid' => NULL, // topic id in DB
342 - 'forumid' => NULL, // forum id in DB
343 253 'parentid' => -1, // parent post id
344 254 'userid' => NULL, // user id in DB
345 255 'orderby' => 'postid', // forumid, order, parentid
346 256 'order' => 'ASC', // ASC DESC
347 257 'offset' => NULL, // this use when you give row_count
348 - 'row_count' => NULL, // 4 or 1 ...
349 - 'status' => NULL, // 0 or 1 ...
350 - 'email' => NULL, // [email protected] ...
351 -
352 - 'check_private' => FALSE
258 + 'row_count' => NULL // 4 or 1 ...
353 259 );
354 260
355 261 $args = wpforo_parse_args( $args, $default );
356 262
357 263 if(is_array($args) && !empty($args)){
358 -
359 264 extract($args, EXTR_OVERWRITE);
360 265
361 266 if( $row_count === 0 ) return array();
362 267
@@ -363,52 +268,24 @@
363 268 $include = wpforo_parse_args( $include );
364 269 $exclude = wpforo_parse_args( $exclude );
365 270
366 271 $wheres = array();
367 - $table_as_prefix = '`'.$this->wpforo->db->prefix.'wpforo_posts`.';
368 272
369 - if(!empty($include)) $wheres[] = $table_as_prefix . "`postid` IN(" . implode(', ', array_map('intval', $include)) . ")";
370 - if(!empty($exclude)) $wheres[] = $table_as_prefix . "`postid` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
273 + if(!empty($include)) $wheres[] = "`postid` IN(" . implode(', ', array_map('intval', $include)) . ")";
274 + if(!empty($exclude)) $wheres[] = "`postid` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
371 275
372 - if(!is_null($topicid)) $wheres[] = $table_as_prefix . "`topicid` = " . intval($topicid);
373 - if($parentid != -1) $wheres[] = $table_as_prefix . "`parentid` = " . intval($parentid);
374 - if(!is_null($userid)) $wheres[] = $table_as_prefix . "`userid` = " . intval($userid);
375 - if(!is_null($status)) $wheres[] = $table_as_prefix . "`status` = " . intval($status);
376 - if(!is_null($email)) $wheres[] = $table_as_prefix . "`email` = '" . esc_sql($email) . "' ";
377 -
378 - if( isset($forumid) && $forumid ){
379 - if( $this->wpforo->perm->forum_can('au', $forumid) ){
380 - if(!is_null($status)) $wheres[] = $table_as_prefix . " `status` = " . intval($status);
381 - }
382 - elseif( isset($this->wpforo->current_userid) && $this->wpforo->current_userid ){
383 - $wheres[] = " ( " . $table_as_prefix . "`status` = 0 OR (" . $table_as_prefix . "`status` = 1 AND " . $table_as_prefix . "`userid` = " .intval($this->wpforo->current_userid). ") )";
384 - }
385 - else{
386 - $wheres[] = " " . $table_as_prefix . "`status` = 0";
387 - }
276 + if($topicid != NULL) $wheres[] = "`topicid` = " . intval($topicid);
277 + if($parentid != -1) $wheres[] = "`parentid` = " . intval($parentid);
278 + if($userid != NULL) $wheres[] = "`userid` = " . intval($userid);
279 +
280 + $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts`";
281 + if(!empty($wheres)){
282 + $sql .= " WHERE " . implode(" AND ", $wheres);
388 283 }
389 284
390 - if( $check_private ){
391 - $sql = "SELECT DISTINCT `".$this->wpforo->db->prefix."wpforo_posts`.*, `".$this->wpforo->db->prefix."wpforo_topics`.`private` FROM `".$this->wpforo->db->prefix."wpforo_posts`, `".$this->wpforo->db->prefix."wpforo_topics`";
392 - if(!empty($wheres)){
393 - $sql .= " WHERE `".$this->wpforo->db->prefix."wpforo_posts`.`topicid` = `".$this->wpforo->db->prefix."wpforo_topics`.`topicid` " . ((!empty($wheres)) ? 'AND' : '') . " " . implode(" AND ", $wheres);
394 - }
395 - else{
396 - $sql .= " WHERE `".$this->wpforo->db->prefix."wpforo_posts`.`topicid` = `".$this->wpforo->db->prefix."wpforo_topics`.`topicid` ";
397 - }
398 - $sql .= " ORDER BY " .$table_as_prefix . "`$orderby` " . $order;
399 - $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
400 - }
401 - else{
402 - $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts`";
403 - if(!empty($wheres)){
404 - $sql .= " WHERE " . implode(" AND ", $wheres);
405 - }
406 - $sql .= " ORDER BY `$orderby` " . $order;
407 - $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
408 - }
285 + $sql .= " ORDER BY `$orderby` " . $order;
409 286
410 - if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
287 + $items_count = $this->wpforo->db->get_var(preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql));
411 288
412 289 if($row_count != NULL){
413 290 if($offset != NULL){
414 291 $sql .= esc_sql(" LIMIT $offset,$row_count");
@@ -416,63 +293,18 @@
416 293 $sql .= esc_sql(" LIMIT $row_count");
417 294 }
418 295 }
419 296
420 - if( $cache ){ $object_key = md5( $sql . $this->wpforo->current_user_groupid ); $object_cache = $this->wpforo->cache->get($object_key); if(!empty($object_cache)){ $items_count = $object_cache['items_count']; return $object_cache['items']; }}
421 -
422 297 $posts = $this->wpforo->db->get_results($sql, ARRAY_A);
423 - $posts = apply_filters('wpforo_get_posts', $posts);
424 -
425 - if( $check_private ){
426 - foreach($posts as $key => $post){
427 - if( isset($post['forumid']) && !$this->wpforo->perm->forum_can('vf', $post['forumid']) ){
428 - unset($posts[$key]);
429 - }
430 - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['private']) && $post['private'] && !wpforo_is_owner($post['userid']) ){
431 - if( !$this->wpforo->perm->forum_can('vp', $post['forumid']) ){
432 - unset($posts[$key]);
433 - }
434 - }
435 - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['status']) && $post['status'] && !wpforo_is_owner($post['userid']) ){
436 - if( !$this->wpforo->perm->forum_can('au', $post['forumid']) ){
437 - unset($posts[$key]);
438 - }
439 - }
440 - }
298 + foreach($posts as $key => $post){
299 + $posts[$key]['body'] = wpforo_content_filter($post['body']);
441 300 }
301 + return $posts;
442 302
443 - if($cache && isset($object_key) && !empty($posts)){
444 - self::$cache['posts'][$object_key]['items'] = $posts;
445 - self::$cache['posts'][$object_key]['items_count'] = $items_count;
446 - }
447 - return $posts;
448 303 }
449 304 }
450 305
451 - function get_posts_filtered( $args = array() ){
452 - $posts = array();
453 - $posts = $this->get_posts( $args );
454 - if( !empty($posts) ){
455 - foreach($posts as $key => $post){
456 - if( isset($post['forumid']) && !$this->wpforo->perm->forum_can('vf', $post['forumid']) ){
457 - unset($posts[$key]);
458 - }
459 - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['private']) && $post['private'] && !wpforo_is_owner($post['userid']) ){
460 - if( !$this->wpforo->perm->forum_can('vp', $post['forumid']) ){
461 - unset($posts[$key]);
462 - }
463 - }
464 - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['status']) && $post['status'] && !wpforo_is_owner($post['userid']) ){
465 - if( !$this->wpforo->perm->forum_can('au', $post['forumid']) ){
466 - unset($posts[$key]);
467 - }
468 - }
469 - }
470 - }
471 - return $posts;
472 - }
473 306
474 -
475 307 function search( $args = array(), &$items_count = 0 ){
476 308 if(!is_array($args)) $args = array('needle' => $args);
477 309
478 310 $default = array(
@@ -492,9 +324,9 @@
492 324 extract($args, EXTR_OVERWRITE);
493 325
494 326 $date_period = intval($date_period);
495 327
496 - $selects = array('p.`postid`', 't.`topicid`', 't.`private`', 't.`status`', 't.`forumid`', 'p.`userid`', 't.`title`', 'p.`created`', 'p.`body`' );
328 + $selects = array('p.`postid`', 't.`topicid`', 't.`forumid`', 'p.`userid`', 't.`title`', 'p.`created`', 'p.`body`' );
497 329 $innerjoins = array('INNER JOIN `'.$this->wpforo->db->prefix.'wpforo_topics` t ON t.`topicid` = p.`topicid`');
498 330 $wheres = array();
499 331 $orders = array();
500 332
@@ -519,9 +351,9 @@
519 351 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) )";
520 352 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle')";
521 353 $orders[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE)";
522 354 }elseif($type == 'user-posts' || $type == 'user-topics'){
523 - $innerjoins[] = "INNER JOIN `".$this->wpforo->db->base_prefix."users` u ON u.`ID` = p.`userid`";
355 + $innerjoins[] = "INNER JOIN `".$this->wpforo->db->prefix."users` u ON u.`ID` = p.`userid`";
524 356 $wheres[] = "( u.`user_login` LIKE '$needle' OR u.`user_email` LIKE '$needle' OR u.`display_name` LIKE '$needle' )";
525 357 if($type == 'user-topics') $wheres[] = "`is_first_post` = 1";
526 358 }
527 359 }
@@ -548,16 +380,10 @@
548 380 }else{
549 381 $sql .= esc_sql(" LIMIT $row_count");
550 382 }
551 383 }
552 -
553 - $posts = $this->wpforo->db->get_results($sql, ARRAY_A);
554 - foreach($posts as $key => $post){
555 - if( !$this->wpforo->perm->forum_can( 'vf', $post['forumid'] ) ) unset($posts[$key]);
556 - if( $post['private'] && !$this->wpforo->perm->forum_can( 'vp', $post['forumid'] ) ) unset($posts[$key]);
557 - if( $post['status'] && !$this->wpforo->perm->forum_can( 'au', $post['forumid'] ) ) unset($posts[$key]);
558 - }
559 - return $posts;
384 +
385 + return $this->wpforo->db->get_results($sql, ARRAY_A);
560 386 }else{
561 387 return array();
562 388 }
563 389 }
@@ -573,9 +399,9 @@
573 399 *
574 400 * @return int
575 401 */
576 402 function get_post_likes_count($postid){
577 - return $this->wpforo->db->get_var("SELECT COUNT(l.`likeid`) FROM `".$this->wpforo->db->prefix."wpforo_likes` l, `".$this->wpforo->db->base_prefix."users` u WHERE `l`.`userid` = `u`.ID AND `l`.`postid` = ".intval($postid) );
403 + return $this->wpforo->db->get_var("SELECT COUNT(l.`likeid`) FROM `".$this->wpforo->db->prefix."wpforo_likes` l, `".$this->wpforo->db->prefix."users` u WHERE `l`.`userid` = `u`.ID AND `l`.`postid` = ".intval($postid) );
578 404 }
579 405
580 406 /**
581 407 * return usernames who likes this post
@@ -588,9 +414,9 @@
588 414 *
589 415 * @return array
590 416 */
591 417 function get_likers_usernames($postid){
592 - return $this->wpforo->db->get_results("SELECT u.ID, u.display_name FROM `".$this->wpforo->db->prefix."wpforo_likes` l, `".$this->wpforo->db->base_prefix."users` u WHERE `l`.`userid` = `u`.ID AND `l`.`postid` = ".intval($postid)." ORDER BY l.`userid` = " . intval($this->wpforo->current_userid) . " DESC, l.`likeid` DESC LIMIT 3", ARRAY_A);
418 + return $this->wpforo->db->get_results("SELECT u.ID, u.display_name FROM `".$this->wpforo->db->prefix."wpforo_likes` l, `".$this->wpforo->db->prefix."users` u WHERE `l`.`userid` = `u`.ID AND `l`.`postid` = ".intval($postid)." ORDER BY l.`userid` = " . intval($this->wpforo->current_userid) . " DESC, l.`likeid` DESC LIMIT 3", ARRAY_A);
593 419 }
594 420
595 421 /**
596 422 * return like ID or null
@@ -642,21 +468,9 @@
642 468 * @return string or false
643 469 */
644 470
645 471 function get_forumslug_byid($postid){
646 -
647 - $cache = $this->wpforo->cache->on('memory_cashe');
648 -
649 - if( $cache && isset(self::$cache['forum_slug'][$postid]) ){
650 - return self::$cache['forum_slug'][$postid];
651 - }
652 -
653 472 $slug = $this->wpforo->db->get_var("SELECT `slug` FROM ".$this->wpforo->db->prefix."wpforo_forums WHERE `forumid` =(SELECT forumid FROM `".$this->wpforo->db->prefix."wpforo_topics` WHERE `topicid` =(SELECT `topicid` FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE postid = ".intval($postid)."))");
654 -
655 - if($cache && isset($postid)){
656 - self::$cache['forum_slug'][$postid] = $slug;
657 - }
658 -
659 473 if($slug){
660 474 return $slug;
661 475 }else{
662 476 return FALSE;
@@ -675,22 +489,10 @@
675 489 *
676 490 * @return string or false
677 491 */
678 492
679 - function get_topicslug_byid( $postid ){
680 -
681 - $cache = $this->wpforo->cache->on('memory_cashe');
682 -
683 - if( $cache && isset(self::$cache['topic_slug'][$postid]) ){
684 - return self::$cache['topic_slug'][$postid];
685 - }
686 -
493 + function get_topicslug_byid($postid){
687 494 $slug = $this->wpforo->db->get_var("SELECT `slug` FROM ".$this->wpforo->db->prefix."wpforo_topics WHERE `topicid` =(SELECT `topicid` FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE postid = ".intval($postid).")");
688 -
689 - if($cache && isset($postid)){
690 - self::$cache['topic_slug'][$postid] = $slug;
691 - }
692 -
693 495 if($slug){
694 496 return $slug;
695 497 }else{
696 498 return FALSE;
@@ -705,32 +507,34 @@
705 507 * @param int $postid
706 508 *
707 509 * @return string $url
708 510 */
709 - function get_post_url( $arg, $absolute = true ){
511 + function get_post_url( $arg ){
710 512
711 - $position = array();
712 -
713 - if( isset($arg) && !is_array($arg) ){
513 + if(empty($arg['postid'])){
714 514 $postid = intval($arg);
715 515 $post = $this->get_post($postid);
716 516 }
717 - elseif( !empty($arg) && isset($arg['postid']) ){
517 + else{
718 518 $post = $arg;
719 519 $postid = $post['postid'];
720 520 }
721 521
722 - if( is_array($post) && !empty($post) && $postid ){
723 - $url = $this->get_forumslug_byid($postid) . '/' . $this->get_topicslug_byid($postid);
522 + if( is_array($post) && !empty($post) ){
523 + $url = WPFORO_BASE_URL . $this->get_forumslug_byid($postid) . '/' . $this->get_topicslug_byid($postid);
724 524 if( $post['topicid'] ){
725 - if( !$position ) $position = $this->wpforo->db->get_var("SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `topicid` = ".intval($post['topicid'])." AND `postid` <= " . ($post['parentid'] ? intval($post['parentid']) : intval($postid) ) . " ORDER BY `postid`");
726 - if( $position <= $this->wpforo->post_options['posts_per_page'] ) return wpforo_home_url($url, false, $absolute ) . "#post-" . intval($postid);
525 + $position = $this->wpforo->db->get_var("SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `topicid` = ".intval($post['topicid'])." AND `postid` <= " . ($post['parentid'] ? intval($post['parentid']) : intval($postid) ) . " ORDER BY `postid`");
526 + if( $position <= $this->wpforo->post_options['posts_per_page'] ) return $url . "/#post-" . intval($postid);
727 527 $paged = ceil( $position/$this->wpforo->post_options['posts_per_page'] );
728 - return wpforo_home_url( $url . "/paged/" . $paged, false, $absolute ) ."#post-" . intval($postid);
528 + return $url . "/paged/".$paged."/#post-" . intval($postid);
729 529 }
530 + else{
531 + return WPFORO_BASE_URL;
532 + }
533 + }else{
534 + return WPFORO_BASE_URL;
730 535 }
731 536
732 - return wpforo_home_url();
733 537 }
734 538
735 539
736 540 /**
@@ -750,68 +554,9 @@
750 554 ) );
751 555 return $is_answered;
752 556 }
753 557
754 - function get_count( $args = array() ){
755 - $sql = "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`";
756 - if( !empty($args) ){
757 - $wheres = array();
758 - foreach ($args as $key => $value) $wheres[] = "`$key` = " . intval($value);
759 - if($wheres) $sql .= " WHERE " . implode(' AND ', $wheres);
760 - }
761 - return $this->wpforo->db->get_var($sql);
558 + function get_count(){
559 + return $this->wpforo->db->get_var( "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`" );
762 560 }
763 -
764 - function unapproved_count(){
765 - return $this->wpforo->db->get_var( "SELECT COUNT(*) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `status` = 1" );
766 - }
767 -
768 - function get_attachment_id( $filename ){
769 - $attach_id = $this->wpforo->db->get_var( "SELECT `post_id` FROM `".$this->wpforo->db->prefix."postmeta` WHERE `meta_key` = '_wp_attached_file' AND `meta_value` LIKE '%" . esc_sql($filename) . "' LIMIT 1");
770 - return $attach_id;
771 - }
772 -
773 - function delete_attachments( $postid ){
774 - $post = $this->get_post($postid);
775 - if( isset($post['body']) && $post['body'] ){
776 - if( preg_match_all('|\/wpforo\/default_attachments\/([^\s\"\]]+)|is', $post['body'], $attachments, PREG_SET_ORDER) ){
777 - $upload_dir = wp_upload_dir();
778 - $default_attachments_dir = $upload_dir['basedir'] . '/wpforo/default_attachments/';
779 - foreach( $attachments as $attachment ){
780 - $filename = trim($attachment[1]);
781 - $file = $default_attachments_dir . $filename;
782 - if( file_exists($file) ){
783 - $posts = $this->wpforo->db->get_var( "SELECT COUNT(*) as posts FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `body` LIKE '%" . esc_sql( $attachment[0] ) . "%'" );
784 - if( is_numeric($posts) && $posts == 1 ){
785 - $attachmentid = $this->get_attachment_id( '/' . $filename );
786 - if ( !wp_delete_attachment( $attachmentid ) ){
787 - @unlink($file);
788 - }
789 - }
790 - }
791 - }
792 - }
793 - }
794 - }
795 -
796 - public function status( $postid, $status ){
797 - if( !$postid = wpforo_bigintval($postid) ) return false;
798 - if( !$post = $this->get_post($postid) ) return false;
799 -
800 - if( $post['is_first_post'] ) return $this->wpforo->topic->status($post['topicid'], $status);
801 -
802 - if( false !== $this->wpforo->db->update(
803 - $this->wpforo->db->prefix."wpforo_posts",
804 - array( 'status' => intval($status) ),
805 - array( 'postid' => $postid ),
806 - array( '%d' ),
807 - array( '%d' )
808 - )){
809 - $this->wpforo->notice->add('Done!', 'success');
810 - return true;
811 - }
812 -
813 - $this->wpforo->notice->add('error: Change Status action', 'error');
814 - return false;
815 - }
816 561 }
817 562 ?>