PluginProbe
wpForo Forum / 1.0.2
wpForo Forum v1.0.2
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 1.4.13 All 138 releases
wpforo / wpf-includes / class-posts.php

class-posts.php in wpForo Forum 1.0.2, at wpf-includes/class-posts.php

563 lines 20.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if( !defined( 'ABSPATH' ) ) exit;
4
5 class wpForoPost{
6
7 private $wpforo;
8
9 function __construct( $wpForo ){
10 if(!isset($this->wpforo)) $this->wpforo = $wpForo;
11 }
12
13 public function add( $args = array() ){
14 if( empty($args) && empty($_REQUEST['post']) ){ $this->wpforo->notice->add('Reply request error', 'error'); return FALSE; }
15 if( empty($args) && !empty($_REQUEST['post']) ){ $args = $_REQUEST['post']; $args['body'] = $_REQUEST['postbody']; }
16
17 extract($args, EXTR_OVERWRITE);
18
19 if( !isset($topicid) || !$topicid ){ $this->wpforo->notice->add('Error: No topic selected', 'error'); return FALSE; }
20 if( !$topic = $this->wpforo->topic->get_topic(intval($topicid)) ){ $this->wpforo->notice->add('Error: Topic is not found', 'error'); return FALSE; }
21 if( !$forum = $this->wpforo->forum->get_forum(intval($topic['forumid'])) ){ $this->wpforo->notice->add('Error: Forum is not found', 'error'); return FALSE; }
22
23 if( $topic['closed'] ){
24 $this->wpforo->notice->add('Can\'t write a post: This topic is closed', 'error');
25 return FALSE;
26 }
27
28 if( !$this->wpforo->perm->forum_can(intval($topic['forumid']), 'cr') ){
29 $this->wpforo->notice->add('You haven\'t permission to create post into this forum', 'error');
30 return FALSE;
31 }
32
33 $post = $args;
34 $post['parentid'] = $parentid = (isset($parentid) ? intval($parentid) : 0);
35 $post['title'] = $title = (isset($title) ? wpforo_text( trim($title), 250, false ) : '');
36 $post['body'] = $body = ( isset($body) ? preg_replace('#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", $body) : '' );
37 $post['created'] = $created = ( isset($created) ? $created : current_time( 'mysql', 1 ) );
38 $post['userid'] = $userid = ( isset($userid) ? intval($userid) : $this->wpforo->current_userid );
39
40 $post = apply_filters('wpforo_add_post_data_filter', $post);
41 if(empty($post)) return FALSE;
42
43 extract($post, EXTR_OVERWRITE);
44
45 if(isset($forumid)) $forumid = intval($forumid);
46 if(isset($topicid)) $topicid = intval($topicid);
47 if(isset($parentid)) $parentid = intval($parentid);
48 if(isset($title)) $title = sanitize_text_field(trim($title));
49 if(isset($created)) $created = sanitize_text_field($created);
50 if(isset($userid)) $userid = intval($userid);
51 if(isset($body)) $body = wpforo_kses(trim($body), 'post');
52
53 do_action( 'wpforo_before_add_post', $post );
54
55 if(
56 $this->wpforo->db->insert(
57 $this->wpforo->db->prefix . 'wpforo_posts',
58 array(
59 'forumid' => (isset($topic['forumid']) ? intval($topic['forumid']) : 0),
60 'topicid' => $topicid,
61 'parentid' => $parentid,
62 'userid' => $userid,
63 'title' => stripslashes($title),
64 'body' => stripslashes($body),
65 'created' => $created,
66 'modified' => $created
67 ),
68 array('%d','%d','%d','%d','%s','%s','%s','%s')
69 )
70 ){
71 $postid = $this->wpforo->db->insert_id;
72
73 $answ_incr = '';
74 $comm_incr = '';
75 if( isset($forum['cat_layout']) && $forum['cat_layout'] == 3 ){
76 if($parentid){
77 $comm_incr = ', `comments` = `comments` + 1 ';
78 }else{
79 $answ_incr = ', `answers` = `answers` + 1 ';
80 }
81 }
82
83 $this->wpforo->db->query( "UPDATE `" . $this->wpforo->db->prefix . "wpforo_forums` SET `last_topicid` = ". intval($topicid) .", `last_postid` = ". intval($postid) .", `last_post_date` = '".esc_sql($created)."', `last_userid` = " . intval($userid) . ", `posts` = `posts` + 1 WHERE `forumid` = " . intval($topic['forumid']) );
84 $this->wpforo->db->query( "UPDATE `" . $this->wpforo->db->prefix . "wpforo_topics` SET `modified` = '" . esc_sql($created) . "', `last_post` = ". intval($postid) .", `posts` = `posts` + 1 $answ_incr WHERE `topicid` = " . intval($topicid) );
85 $this->wpforo->db->query( "UPDATE `" . $this->wpforo->db->prefix . "wpforo_profiles` SET `posts` = `posts` + 1 $answ_incr $comm_incr WHERE `userid` = " . intval($userid) );
86
87 $post['postid'] = $postid;
88 $post['posturl'] = $this->get_post_url($postid);
89
90 do_action( 'wpforo_after_add_post', $post );
91
92 $this->wpforo->member->reset($userid);
93 $this->wpforo->notice->add('You successfully replied', 'success');
94 return $postid;
95 }
96
97 $this->wpforo->notice->add('Reply request error', 'error');
98 return FALSE;
99 }
100
101 public function edit( $args = array() ){
102 if( empty($args) && (!isset($_REQUEST['post']) || empty($_REQUEST['post'])) ) return FALSE;
103 if( empty($args) && !empty($_REQUEST['post']) ){ $args = $_REQUEST['post']; $args['body'] = $_REQUEST['postbody']; }
104
105 $args = apply_filters('wpforo_edit_post_data_filter', $args);
106 if(empty($args)) return FALSE;
107
108 extract($args, EXTR_OVERWRITE);
109
110 if( !isset($postid) || !$postid || !is_numeric($postid) ){
111 $this->wpforo->notice->add('Cannot update post data', 'error');
112 return FALSE;
113 }
114
115 $postid = intval($postid);
116
117 if( !$post = $this->get_post($postid) ){ $this->wpforo->notice->add('No Posts found for update', 'error'); return FALSE; }
118
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;
123 }
124
125 $title = (isset($title) ? wpforo_text( trim($title), 250, false ) : '');
126 $body = ( isset($body) ? preg_replace('#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", $body) : '' );
127
128 if(isset($forumid)) $forumid = intval($forumid);
129 if(isset($topicid)) $topicid = intval($topicid);
130 if(isset($parentid)) $parentid = intval($parentid);
131 if(isset($title)) $title = sanitize_text_field(trim($title));
132 if(isset($slug)) $slug = sanitize_title($slug);
133 if(isset($created)) $created = sanitize_text_field($created);
134 if(isset($userid)) $userid = intval($userid);
135 if(isset($body)) $body = wpforo_kses(trim($body), 'post');
136
137 if( FALSE !== $this->wpforo->db->update(
138 $this->wpforo->db->prefix."wpforo_posts",
139 array(
140 'title' => stripslashes($title),
141 'body' => stripslashes($body),
142 'modified' => current_time( 'mysql', 1 )
143 ),
144 array('postid' => $postid),
145 array('%s','%s','%s'),
146 array('%d')
147 )
148 ){
149 $this->wpforo->notice->add('This post successfully edited', 'success');
150 return $postid;
151 }
152
153 $this->wpforo->notice->add('Reply request error', 'error');
154 return FALSE;
155 }
156
157 #################################################################################
158 /**
159 * Delete topic from DB
160 *
161 * Returns true if successfully deleted or false.
162 *
163 * @since 1.0.0
164 *
165 * @return bool
166 */
167
168 function delete($postid){
169
170 $postid = intval($postid);
171
172 $post = $this->get_post($postid);
173 $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']);
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'])) ){
175 $this->wpforo->notice->add('You haven\'t permission to delete post from this forum', 'error');
176 return FALSE;
177 }
178
179 if( $this->wpforo->db->delete($this->wpforo->db->prefix . 'wpforo_posts', array( 'postid' => intval($postid) ), array( '%d' )) ){
180 $last_post = $this->get_posts( array('topicid' => intval($post['topicid']), 'order' => 'DESC', 'row_count' => 1) );
181 if(is_array($last_post) && !empty($last_post)){
182 $last_post = $last_post[0];
183 }else{
184 $last_post = array( 'created' => '0000-00-00 00:00:00', 'userid' => 0, 'postid' => 0 );
185 }
186
187 $answ_incr = '';
188 $comm_incr = '';
189 $forum = $this->wpforo->forum->get_forum($post['forumid']);
190 if( isset($forum['cat_layout']) && $forum['cat_layout'] == 3 ){
191 if($post['parentid']){
192 $comm_incr = ', `comments` = IF( (`comments` - 1) < 0, 0, `comments` - 1 ) ';
193 }else{
194 $answ_incr = ', `answers` = IF( (`answers` - 1) < 0, 0, `answers` - 1 ) ';
195 }
196 }
197
198 if($this->wpforo->db->query( "UPDATE IGNORE " . $this->wpforo->db->prefix . "wpforo_topics SET `last_post` = " . intval($last_post['postid']) . ", `posts` = IF( (`posts` - 1) < 0, 0, `posts` - 1 ) $answ_incr WHERE `topicid` = " . intval( $post['topicid'] ))){
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'] ))){
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']) ) ){
201 $this->wpforo->member->reset($post['userid']);
202 $this->wpforo->notice->add('This post successfully deleted', 'success');
203 return TRUE;
204 }
205 }
206 }
207 }
208
209 $this->wpforo->notice->add('Post delete error', 'error');
210 return FALSE;
211 }
212
213 #################################################################################
214 /**
215 * array get_post(id(num))
216 *
217 * Returns array from defined and default arguments.
218 *
219 * @since 1.0.0
220 *
221 * @param mixed defined arguments array for returning
222 *
223 * @return array
224 */
225 function get_post($postid){
226
227 $post = array();
228 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `postid` = ".intval($postid);
229 $post = $this->wpforo->db->get_row($sql, ARRAY_A);
230 if(!empty($post)){
231 $post['userid'] = intval($post['userid']);
232 $post['body'] = wpforo_content_filter($post['body']);
233 }
234 return $post;
235 }
236 /**
237 * array get_topic(array or id(num))
238 * Returns merged arguments array from defined and default arguments.
239 *
240 * @since 1.0.0
241 *
242 * @param array defined arguments array for returning
243 *
244 * @return associative array where count is topic count and other numeric arrays with topic
245 */
246 function get_posts($args = array(), &$items_count = 0){
247
248 $default = array(
249 'include' => array(), // array( 2, 10, 25 )
250 'exclude' => array(), // array( 2, 10, 25 )
251
252 'topicid' => NULL, // topic id in DB
253 'parentid' => -1, // parent post id
254 'userid' => NULL, // user id in DB
255 'orderby' => 'postid', // forumid, order, parentid
256 'order' => 'ASC', // ASC DESC
257 'offset' => NULL, // this use when you give row_count
258 'row_count' => NULL // 4 or 1 ...
259 );
260
261 $args = wpforo_parse_args( $args, $default );
262
263 if(is_array($args) && !empty($args)){
264 extract($args, EXTR_OVERWRITE);
265
266 if( $row_count === 0 ) return array();
267
268 $include = wpforo_parse_args( $include );
269 $exclude = wpforo_parse_args( $exclude );
270
271 $wheres = array();
272
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)) . ")";
275
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);
283 }
284
285 $sql .= " ORDER BY `$orderby` " . $order;
286
287 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
288 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
289
290 if($row_count != NULL){
291 if($offset != NULL){
292 $sql .= esc_sql(" LIMIT $offset,$row_count");
293 }else{
294 $sql .= esc_sql(" LIMIT $row_count");
295 }
296 }
297
298 $posts = $this->wpforo->db->get_results($sql, ARRAY_A);
299 foreach($posts as $key => $post){
300 $posts[$key]['body'] = wpforo_content_filter($post['body']);
301 }
302 return $posts;
303
304 }
305 }
306
307
308 function search( $args = array(), &$items_count = 0 ){
309 if(!is_array($args)) $args = array('needle' => $args);
310
311 $default = array(
312 'needle' => '', // search needle
313 'forumids' => array(), // array( 2, 10, 25 )
314 'date_period' => 0, // topic id in DB
315 'type' => 'entire-posts', // search type ( entire-posts | titles-only | user-posts | user-topics )
316 'orderby' => 'relevancy', // Sort Search Results by ( relevancy | date | user | forum )
317 'order' => 'DESC', // Sort Search Results ( ASC | DESC )
318 'offset' => NULL, // this use when you give row_count
319 'row_count' => NULL // 4 or 1 ...
320 );
321
322 $args = wpforo_parse_args( $args, $default );
323
324 if( !empty($args) ){
325 extract($args, EXTR_OVERWRITE);
326
327 $date_period = intval($date_period);
328
329 $selects = array('p.`postid`', 't.`topicid`', 't.`forumid`', 'p.`userid`', 't.`title`', 'p.`created`', 'p.`body`' );
330 $innerjoins = array('INNER JOIN `'.$this->wpforo->db->prefix.'wpforo_topics` t ON t.`topicid` = p.`topicid`');
331 $wheres = array();
332 $orders = array();
333
334 if(!empty($forumids)) $wheres[] = "t.`forumid` IN(" . implode(', ', array_map('intval', $forumids)) . ")";
335 if( $date_period != 0 ){
336 $date = date( 'Y-m-d H:i:s', current_time( 'timestamp', 1 ) - ($date_period * 24 * 60 * 60) );
337 if($date) $wheres[] = "p.`created` > '".esc_sql($date)."'";
338 }
339
340 if($needle){
341
342 $needle = trim( trim( str_replace(' ', '* ', $needle) ), '*' ) . "*";
343 $needle = esc_sql(substr(sanitize_text_field($needle), 0, 60));
344
345 if($type == 'entire-posts'){
346 $selects[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`body`) AGAINST('$needle' IN BOOLEAN MODE) AS matches";
347 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`, p.`body`) AGAINST('$needle' IN BOOLEAN MODE) )";
348 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle') + MATCH(p.`body`) AGAINST('$needle')";
349 $orders[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`body`) AGAINST('$needle' IN BOOLEAN MODE)";
350 }elseif($type == 'titles-only'){
351 $selects[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) AS matches";
352 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) )";
353 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle')";
354 $orders[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE)";
355 }elseif($type == 'user-posts' || $type == 'user-topics'){
356 $innerjoins[] = "INNER JOIN `".$this->wpforo->db->prefix."users` u ON u.`ID` = p.`userid`";
357 $wheres[] = "( u.`user_login` LIKE '$needle' OR u.`user_email` LIKE '$needle' OR u.`display_name` LIKE '$needle' )";
358 if($type == 'user-topics') $wheres[] = "`is_first_post` = 1";
359 }
360 }
361
362 if($orderby == 'date'){
363 $orders = array('p.`created`');
364 }elseif($orderby == 'user'){
365 $orders = array('p.`userid`');
366 }elseif($orderby == 'forum'){
367 $orders = array('t.`forumid`');
368 }
369
370 $sql = "SELECT COUNT(p.`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts` p ".implode(' ', $innerjoins);
371 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
372 $items_count = $this->wpforo->db->get_var($sql);
373
374 $sql = "SELECT ".implode(', ', $selects)." FROM `".$this->wpforo->db->prefix."wpforo_posts` p ".implode(' ', $innerjoins);
375 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
376 if(!empty($orders)) $sql .= " ORDER BY ".implode(' '.strtoupper($order).', ', $orders)." ".strtoupper($order);
377
378 if($row_count != NULL){
379 if($offset != NULL){
380 $sql .= esc_sql(" LIMIT $offset,$row_count");
381 }else{
382 $sql .= esc_sql(" LIMIT $row_count");
383 }
384 }
385
386 return $this->wpforo->db->get_results($sql, ARRAY_A);
387 }else{
388 return array();
389 }
390 }
391
392 /**
393 * return likes count by post id
394 *
395 * Return likes count
396 *
397 * @since 1.0.0
398 *
399 * @param int
400 *
401 * @return int
402 */
403 function get_post_likes_count($postid){
404 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) );
405 }
406
407 /**
408 * return usernames who likes this post
409 *
410 * Return array with username
411 *
412 * @since 1.0.0
413 *
414 * @param int
415 *
416 * @return array
417 */
418 function get_likers_usernames($postid){
419 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);
420 }
421
422 /**
423 * return like ID or null
424 *
425 * @since 1.0.0
426 *
427 * @param int int
428 *
429 * @return null or like id
430 */
431 function is_liked($postid, $userid){
432 $returned_value = $this->wpforo->db->get_var("SELECT likeid FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `postid` = ".intval($postid)." AND `userid` = ".intval($userid) );
433 if(is_null($returned_value)){
434 return FALSE;
435 }else{
436 return $returned_value;
437 }
438 }
439
440 /**
441 * return votes sum by post id
442 *
443 * Return votes count
444 *
445 * @since 1.0.0
446 *
447 * @param int
448 *
449 * @return int
450 */
451 function get_post_votes_sum($postid){
452 $sum = $this->wpforo->db->get_var("SELECT sum(`reaction`) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `postid` = ".intval($postid) );
453 if($sum == null){
454 $sum = 0;
455 }
456 return $sum;
457 }
458
459
460 /**
461 * return forum slug
462 *
463 * string (slug)
464 *
465 * @since 1.0.0
466 *
467 * @param int
468 *
469 * @return string or false
470 */
471
472 function get_forumslug_byid($postid){
473 $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)."))");
474 if($slug){
475 return $slug;
476 }else{
477 return FALSE;
478 }
479 }
480
481
482 /**
483 * return topic slug
484 *
485 * string (slug)
486 *
487 * @since 1.0.0
488 *
489 * @param int
490 *
491 * @return string or false
492 */
493
494 function get_topicslug_byid($postid){
495 $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).")");
496 if($slug){
497 return $slug;
498 }else{
499 return FALSE;
500 }
501 }
502
503 /**
504 * return post full url by id
505 *
506 * @since 1.0.0
507 *
508 * @param int $postid
509 *
510 * @return string $url
511 */
512 function get_post_url( $arg ){
513
514 if( isset($arg) && !is_array($arg) ){
515 $postid = intval($arg);
516 $post = $this->get_post($postid);
517 }
518 else{
519 $post = $arg;
520 $postid = $post['postid'];
521 }
522
523 if( is_array($post) && !empty($post) ){
524 $url = WPFORO_BASE_URL . $this->get_forumslug_byid($postid) . '/' . $this->get_topicslug_byid($postid);
525 if( $post['topicid'] ){
526 $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`");
527 if( $position <= $this->wpforo->post_options['posts_per_page'] ) return $url . "/#post-" . intval($postid);
528 $paged = ceil( $position/$this->wpforo->post_options['posts_per_page'] );
529 return $url . "/paged/".$paged."/#post-" . intval($postid);
530 }
531 else{
532 return WPFORO_BASE_URL;
533 }
534 }else{
535 return WPFORO_BASE_URL;
536 }
537
538 }
539
540
541 /**
542 * return 0 or 1
543 *
544 * @since 1.0.0
545 *
546 * @param int $postid
547 */
548 function is_answered( $postid ){
549 $is_answered = $this->wpforo->db->get_var( $this->wpforo->db->prepare(
550 " SELECT is_answer
551 FROM `".$this->wpforo->db->prefix."wpforo_posts`
552 WHERE postid = %d
553 ",
554 intval($postid)
555 ) );
556 return $is_answered;
557 }
558
559 function get_count(){
560 return $this->wpforo->db->get_var( "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`" );
561 }
562 }
563 ?>