PluginProbe
wpForo Forum / 1.1.1
wpForo Forum v1.1.1
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 1.1.1, at wpf-includes/class-posts.php

567 lines 20.9 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('cr', $topic['forumid']) ){
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('er', $post['forumid']) || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can('eor', $post['forumid']) && $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('dr', $post['forumid']) || ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can('dor', $post['forumid']) && $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 $this->wpforo->db->delete(
188 $this->wpforo->db->prefix.'wpforo_likes', array( 'postid' => $postid ), array( '%d' )
189 );
190 $this->wpforo->db->delete(
191 $this->wpforo->db->prefix.'wpforo_votes', array( 'postid' => $postid ), array( '%d' )
192 );
193
194 $answ_incr = '';
195 $comm_incr = '';
196 $forum = $this->wpforo->forum->get_forum($post['forumid']);
197 if( isset($forum['cat_layout']) && $forum['cat_layout'] == 3 ){
198 if($post['parentid']){
199 $comm_incr = ', `comments` = IF( (`comments` - 1) < 0, 0, `comments` - 1 ) ';
200 }else{
201 $answ_incr = ', `answers` = IF( (`answers` - 1) < 0, 0, `answers` - 1 ) ';
202 }
203 }
204
205 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'] ))){
206 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'] ))){
207 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']) ) ){
208 $this->wpforo->member->reset($post['userid']);
209 $this->wpforo->notice->add('This post successfully deleted', 'success');
210 return TRUE;
211 }
212 }
213 }
214 }
215
216 $this->wpforo->notice->add('Post delete error', 'error');
217 return FALSE;
218 }
219
220 #################################################################################
221 /**
222 * array get_post(id(num))
223 *
224 * Returns array from defined and default arguments.
225 *
226 * @since 1.0.0
227 *
228 * @param mixed defined arguments array for returning
229 *
230 * @return array
231 */
232 function get_post($postid){
233
234 $post = array();
235 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `postid` = ".intval($postid);
236 $post = $this->wpforo->db->get_row($sql, ARRAY_A);
237 if(!empty($post)) $post['userid'] = intval($post['userid']);
238 $post = apply_filters('wpforo_get_post', $post);
239 return $post;
240 }
241 /**
242 * array get_topic(array or id(num))
243 * Returns merged arguments array from defined and default arguments.
244 *
245 * @since 1.0.0
246 *
247 * @param array defined arguments array for returning
248 *
249 * @return associative array where count is topic count and other numeric arrays with topic
250 */
251 function get_posts($args = array(), &$items_count = 0){
252
253 $default = array(
254 'include' => array(), // array( 2, 10, 25 )
255 'exclude' => array(), // array( 2, 10, 25 )
256
257 'topicid' => NULL, // topic id in DB
258 'parentid' => -1, // parent post id
259 'userid' => NULL, // user id in DB
260 'orderby' => 'postid', // forumid, order, parentid
261 'order' => 'ASC', // ASC DESC
262 'offset' => NULL, // this use when you give row_count
263 'row_count' => NULL // 4 or 1 ...
264 );
265
266 $args = wpforo_parse_args( $args, $default );
267
268 if(is_array($args) && !empty($args)){
269 extract($args, EXTR_OVERWRITE);
270
271 if( $row_count === 0 ) return array();
272
273 $include = wpforo_parse_args( $include );
274 $exclude = wpforo_parse_args( $exclude );
275
276 $wheres = array();
277
278 if(!empty($include)) $wheres[] = "`postid` IN(" . implode(', ', array_map('intval', $include)) . ")";
279 if(!empty($exclude)) $wheres[] = "`postid` NOT IN(" . implode(', ', array_map('intval', $exclude)) . ")";
280
281 if($topicid != NULL) $wheres[] = "`topicid` = " . intval($topicid);
282 if($parentid != -1) $wheres[] = "`parentid` = " . intval($parentid);
283 if($userid != NULL) $wheres[] = "`userid` = " . intval($userid);
284
285 $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts`";
286 if(!empty($wheres)){
287 $sql .= " WHERE " . implode(" AND ", $wheres);
288 }
289
290 $sql .= " ORDER BY `$orderby` " . $order;
291
292 $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql);
293 if( $item_count_sql ) $items_count = $this->wpforo->db->get_var($item_count_sql);
294
295 if($row_count != NULL){
296 if($offset != NULL){
297 $sql .= esc_sql(" LIMIT $offset,$row_count");
298 }else{
299 $sql .= esc_sql(" LIMIT $row_count");
300 }
301 }
302
303 $posts = $this->wpforo->db->get_results($sql, ARRAY_A);
304
305 $posts = apply_filters('wpforo_get_posts', $posts);
306 return $posts;
307
308 }
309 }
310
311
312 function search( $args = array(), &$items_count = 0 ){
313 if(!is_array($args)) $args = array('needle' => $args);
314
315 $default = array(
316 'needle' => '', // search needle
317 'forumids' => array(), // array( 2, 10, 25 )
318 'date_period' => 0, // topic id in DB
319 'type' => 'entire-posts', // search type ( entire-posts | titles-only | user-posts | user-topics )
320 'orderby' => 'relevancy', // Sort Search Results by ( relevancy | date | user | forum )
321 'order' => 'DESC', // Sort Search Results ( ASC | DESC )
322 'offset' => NULL, // this use when you give row_count
323 'row_count' => NULL // 4 or 1 ...
324 );
325
326 $args = wpforo_parse_args( $args, $default );
327
328 if( !empty($args) ){
329 extract($args, EXTR_OVERWRITE);
330
331 $date_period = intval($date_period);
332
333 $selects = array('p.`postid`', 't.`topicid`', 't.`forumid`', 'p.`userid`', 't.`title`', 'p.`created`', 'p.`body`' );
334 $innerjoins = array('INNER JOIN `'.$this->wpforo->db->prefix.'wpforo_topics` t ON t.`topicid` = p.`topicid`');
335 $wheres = array();
336 $orders = array();
337
338 if(!empty($forumids)) $wheres[] = "t.`forumid` IN(" . implode(', ', array_map('intval', $forumids)) . ")";
339 if( $date_period != 0 ){
340 $date = date( 'Y-m-d H:i:s', current_time( 'timestamp', 1 ) - ($date_period * 24 * 60 * 60) );
341 if($date) $wheres[] = "p.`created` > '".esc_sql($date)."'";
342 }
343
344 if($needle){
345
346 $needle = trim( trim( str_replace(' ', '* ', $needle) ), '*' ) . "*";
347 $needle = esc_sql(substr(sanitize_text_field($needle), 0, 60));
348
349 if($type == 'entire-posts'){
350 $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";
351 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`, p.`body`) AGAINST('$needle' IN BOOLEAN MODE) )";
352 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle') + MATCH(p.`body`) AGAINST('$needle')";
353 $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)";
354 }elseif($type == 'titles-only'){
355 $selects[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) AS matches";
356 $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) )";
357 $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle')";
358 $orders[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE)";
359 }elseif($type == 'user-posts' || $type == 'user-topics'){
360 $innerjoins[] = "INNER JOIN `".$this->wpforo->db->base_prefix."users` u ON u.`ID` = p.`userid`";
361 $wheres[] = "( u.`user_login` LIKE '$needle' OR u.`user_email` LIKE '$needle' OR u.`display_name` LIKE '$needle' )";
362 if($type == 'user-topics') $wheres[] = "`is_first_post` = 1";
363 }
364 }
365
366 if($orderby == 'date'){
367 $orders = array('p.`created`');
368 }elseif($orderby == 'user'){
369 $orders = array('p.`userid`');
370 }elseif($orderby == 'forum'){
371 $orders = array('t.`forumid`');
372 }
373
374 $sql = "SELECT COUNT(p.`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts` p ".implode(' ', $innerjoins);
375 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
376 $items_count = $this->wpforo->db->get_var($sql);
377
378 $sql = "SELECT ".implode(', ', $selects)." FROM `".$this->wpforo->db->prefix."wpforo_posts` p ".implode(' ', $innerjoins);
379 if(!empty($wheres)) $sql .= " WHERE " . implode( " AND ", $wheres );
380 if(!empty($orders)) $sql .= " ORDER BY ".implode(' '.strtoupper($order).', ', $orders)." ".strtoupper($order);
381
382 if($row_count != NULL){
383 if($offset != NULL){
384 $sql .= esc_sql(" LIMIT $offset,$row_count");
385 }else{
386 $sql .= esc_sql(" LIMIT $row_count");
387 }
388 }
389
390 return $this->wpforo->db->get_results($sql, ARRAY_A);
391 }else{
392 return array();
393 }
394 }
395
396 /**
397 * return likes count by post id
398 *
399 * Return likes count
400 *
401 * @since 1.0.0
402 *
403 * @param int
404 *
405 * @return int
406 */
407 function get_post_likes_count($postid){
408 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) );
409 }
410
411 /**
412 * return usernames who likes this post
413 *
414 * Return array with username
415 *
416 * @since 1.0.0
417 *
418 * @param int
419 *
420 * @return array
421 */
422 function get_likers_usernames($postid){
423 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);
424 }
425
426 /**
427 * return like ID or null
428 *
429 * @since 1.0.0
430 *
431 * @param int int
432 *
433 * @return null or like id
434 */
435 function is_liked($postid, $userid){
436 $returned_value = $this->wpforo->db->get_var("SELECT likeid FROM `".$this->wpforo->db->prefix."wpforo_likes` WHERE `postid` = ".intval($postid)." AND `userid` = ".intval($userid) );
437 if(is_null($returned_value)){
438 return FALSE;
439 }else{
440 return $returned_value;
441 }
442 }
443
444 /**
445 * return votes sum by post id
446 *
447 * Return votes count
448 *
449 * @since 1.0.0
450 *
451 * @param int
452 *
453 * @return int
454 */
455 function get_post_votes_sum($postid){
456 $sum = $this->wpforo->db->get_var("SELECT sum(`reaction`) FROM `".$this->wpforo->db->prefix."wpforo_votes` WHERE `postid` = ".intval($postid) );
457 if($sum == null){
458 $sum = 0;
459 }
460 return $sum;
461 }
462
463
464 /**
465 * return forum slug
466 *
467 * string (slug)
468 *
469 * @since 1.0.0
470 *
471 * @param int
472 *
473 * @return string or false
474 */
475
476 function get_forumslug_byid($postid){
477 $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)."))");
478 if($slug){
479 return $slug;
480 }else{
481 return FALSE;
482 }
483 }
484
485
486 /**
487 * return topic slug
488 *
489 * string (slug)
490 *
491 * @since 1.0.0
492 *
493 * @param int
494 *
495 * @return string or false
496 */
497
498 function get_topicslug_byid($postid){
499 $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).")");
500 if($slug){
501 return $slug;
502 }else{
503 return FALSE;
504 }
505 }
506
507 /**
508 * return post full url by id
509 *
510 * @since 1.0.0
511 *
512 * @param int $postid
513 *
514 * @return string $url
515 */
516 function get_post_url( $arg ){
517
518 if( isset($arg) && !is_array($arg) ){
519 $postid = intval($arg);
520 $post = $this->get_post($postid);
521 }
522 else{
523 $post = $arg;
524 $postid = $post['postid'];
525 }
526
527 if( is_array($post) && !empty($post) ){
528 $url = WPFORO_BASE_URL . $this->get_forumslug_byid($postid) . '/' . $this->get_topicslug_byid($postid);
529 if( $post['topicid'] ){
530 $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`");
531 if( $position <= $this->wpforo->post_options['posts_per_page'] ) return $url . "/#post-" . intval($postid);
532 $paged = ceil( $position/$this->wpforo->post_options['posts_per_page'] );
533 return $url . "/paged/".$paged."/#post-" . intval($postid);
534 }
535 else{
536 return WPFORO_BASE_URL;
537 }
538 }else{
539 return WPFORO_BASE_URL;
540 }
541
542 }
543
544
545 /**
546 * return 0 or 1
547 *
548 * @since 1.0.0
549 *
550 * @param int $postid
551 */
552 function is_answered( $postid ){
553 $is_answered = $this->wpforo->db->get_var( $this->wpforo->db->prepare(
554 " SELECT is_answer
555 FROM `".$this->wpforo->db->prefix."wpforo_posts`
556 WHERE postid = %d
557 ",
558 intval($postid)
559 ) );
560 return $is_answered;
561 }
562
563 function get_count(){
564 return $this->wpforo->db->get_var( "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`" );
565 }
566 }
567 ?>