PluginProbe
wpForo Forum / beta-4
wpForo Forum vbeta-4
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 1.4.2 All 137 releases
wpforo / wpf-includes / class-posts.php

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

562 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 $items_count = $this->wpforo->db->get_var(preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql));
288
289 if($row_count != NULL){
290 if($offset != NULL){
291 $sql .= esc_sql(" LIMIT $offset,$row_count");
292 }else{
293 $sql .= esc_sql(" LIMIT $row_count");
294 }
295 }
296
297 $posts = $this->wpforo->db->get_results($sql, ARRAY_A);
298 foreach($posts as $key => $post){
299 $posts[$key]['body'] = wpforo_content_filter($post['body']);
300 }
301 return $posts;
302
303 }
304 }
305
306
307 function search( $args = array(), &$items_count = 0 ){
308 if(!is_array($args)) $args = array('needle' => $args);
309
310 $default = array(
311 'needle' => '', // search needle
312 'forumids' => array(), // array( 2, 10, 25 )
313 'date_period' => 0, // topic id in DB
314 'type' => 'entire-posts', // search type ( entire-posts | titles-only | user-posts | user-topics )
315 'orderby' => 'relevancy', // Sort Search Results by ( relevancy | date | user | forum )
316 'order' => 'DESC', // Sort Search Results ( ASC | DESC )
317 'offset' => NULL, // this use when you give row_count
318 'row_count' => NULL // 4 or 1 ...
319 );
320
321 $args = wpforo_parse_args( $args, $default );
322
323 if( !empty($args) ){
324 extract($args, EXTR_OVERWRITE);
325
326 $date_period = intval($date_period);
327
328 $selects = array('p.`postid`', 't.`topicid`', 't.`forumid`', 'p.`userid`', 't.`title`', 'p.`created`', 'p.`body`' );
329 $innerjoins = array('INNER JOIN `'.$this->wpforo->db->prefix.'wpforo_topics` t ON t.`topicid` = p.`topicid`');
330 $wheres = array();
331 $orders = array();
332
333 if(!empty($forumids)) $wheres[] = "t.`forumid` IN(" . implode(', ', array_map('intval', $forumids)) . ")";
334 if( $date_period != 0 ){
335 $date = date( 'Y-m-d H:i:s', current_time( 'timestamp', 1 ) - ($date_period * 24 * 60 * 60) );
336 if($date) $wheres[] = "p.`created` > '".esc_sql($date)."'";
337 }
338
339 if($needle){
340
341 $needle = trim( trim( str_replace(' ', '* ', $needle) ), '*' ) . "*";
342 $needle = esc_sql(substr(sanitize_text_field($needle), 0, 60));
343
344 if($type == 'entire-posts'){
345 $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";
346 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`, p.`body`) AGAINST('$needle' IN BOOLEAN MODE) )";
347 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle') + MATCH(p.`body`) AGAINST('$needle')";
348 $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)";
349 }elseif($type == 'titles-only'){
350 $selects[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) AS matches";
351 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) )";
352 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle')";
353 $orders[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE)";
354 }elseif($type == 'user-posts' || $type == 'user-topics'){
355 $innerjoins[] = "INNER JOIN `".$this->wpforo->db->prefix."users` u ON u.`ID` = p.`userid`";
356 $wheres[] = "( u.`user_login` LIKE '$needle' OR u.`user_email` LIKE '$needle' OR u.`display_name` LIKE '$needle' )";
357 if($type == 'user-topics') $wheres[] = "`is_first_post` = 1";
358 }
359 }
360
361 if($orderby == 'date'){
362 $orders = array('p.`created`');
363 }elseif($orderby == 'user'){
364 $orders = array('p.`userid`');
365 }elseif($orderby == 'forum'){
366 $orders = array('t.`forumid`');
367 }
368
369 $sql = "SELECT COUNT(p.`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts` p ".implode(' ', $innerjoins);
370 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
371 $items_count = $this->wpforo->db->get_var($sql);
372
373 $sql = "SELECT ".implode(', ', $selects)." FROM `".$this->wpforo->db->prefix."wpforo_posts` p ".implode(' ', $innerjoins);
374 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
375 if(!empty($orders)) $sql .= " ORDER BY ".implode(' '.strtoupper($order).', ', $orders)." ".strtoupper($order);
376
377 if($row_count != NULL){
378 if($offset != NULL){
379 $sql .= esc_sql(" LIMIT $offset,$row_count");
380 }else{
381 $sql .= esc_sql(" LIMIT $row_count");
382 }
383 }
384
385 return $this->wpforo->db->get_results($sql, ARRAY_A);
386 }else{
387 return array();
388 }
389 }
390
391 /**
392 * return likes count by post id
393 *
394 * Return likes count
395 *
396 * @since 1.0.0
397 *
398 * @param int
399 *
400 * @return int
401 */
402 function get_post_likes_count($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) );
404 }
405
406 /**
407 * return usernames who likes this post
408 *
409 * Return array with username
410 *
411 * @since 1.0.0
412 *
413 * @param int
414 *
415 * @return array
416 */
417 function get_likers_usernames($postid){
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);
419 }
420
421 /**
422 * return like ID or null
423 *
424 * @since 1.0.0
425 *
426 * @param int int
427 *
428 * @return null or like id
429 */
430 function is_liked($postid, $userid){
431 $returned_value = $this->wpforo->db->get_var("SELECT likeid FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `postid` = ".intval($postid)." AND `userid` = ".intval($userid) );
432 if(is_null($returned_value)){
433 return FALSE;
434 }else{
435 return $returned_value;
436 }
437 }
438
439 /**
440 * return votes sum by post id
441 *
442 * Return votes count
443 *
444 * @since 1.0.0
445 *
446 * @param int
447 *
448 * @return int
449 */
450 function get_post_votes_sum($postid){
451 $sum = $this->wpforo->db->get_var("SELECT sum(`reaction`) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `postid` = ".intval($postid) );
452 if($sum == null){
453 $sum = 0;
454 }
455 return $sum;
456 }
457
458
459 /**
460 * return forum slug
461 *
462 * string (slug)
463 *
464 * @since 1.0.0
465 *
466 * @param int
467 *
468 * @return string or false
469 */
470
471 function get_forumslug_byid($postid){
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)."))");
473 if($slug){
474 return $slug;
475 }else{
476 return FALSE;
477 }
478 }
479
480
481 /**
482 * return topic slug
483 *
484 * string (slug)
485 *
486 * @since 1.0.0
487 *
488 * @param int
489 *
490 * @return string or false
491 */
492
493 function get_topicslug_byid($postid){
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).")");
495 if($slug){
496 return $slug;
497 }else{
498 return FALSE;
499 }
500 }
501
502 /**
503 * return post full url by id
504 *
505 * @since 1.0.0
506 *
507 * @param int $postid
508 *
509 * @return string $url
510 */
511 function get_post_url( $arg ){
512
513 if(empty($arg['postid'])){
514 $postid = intval($arg);
515 $post = $this->get_post($postid);
516 }
517 else{
518 $post = $arg;
519 $postid = $post['postid'];
520 }
521
522 if( is_array($post) && !empty($post) ){
523 $url = WPFORO_BASE_URL . $this->get_forumslug_byid($postid) . '/' . $this->get_topicslug_byid($postid);
524 if( $post['topicid'] ){
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);
527 $paged = ceil( $position/$this->wpforo->post_options['posts_per_page'] );
528 return $url . "/paged/".$paged."/#post-" . intval($postid);
529 }
530 else{
531 return WPFORO_BASE_URL;
532 }
533 }else{
534 return WPFORO_BASE_URL;
535 }
536
537 }
538
539
540 /**
541 * return 0 or 1
542 *
543 * @since 1.0.0
544 *
545 * @param int $postid
546 */
547 function is_answered( $postid ){
548 $is_answered = $this->wpforo->db->get_var( $this->wpforo->db->prepare(
549 " SELECT is_answer
550 FROM `".$this->wpforo->db->prefix."wpforo_posts`
551 WHERE postid = %d
552 ",
553 intval($postid)
554 ) );
555 return $is_answered;
556 }
557
558 function get_count(){
559 return $this->wpforo->db->get_var( "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`" );
560 }
561 }
562 ?>