| @@ -2,61 +2,18 @@ | ||
| 2 | 2 | // Exit if accessed directly |
| 3 | 3 | if( !defined( 'ABSPATH' ) ) exit; |
| 4 | 4 | |
| 5 | 5 | class wpForoPost{ |
| 6 | + | |
| 6 | 7 | private $wpforo; |
| 7 | - public $default; | |
| 8 | - public $options; | |
| 9 | - | |
| 10 | - public static $cache = array( 'posts' => array(), 'post' => array(), 'item' => array(), 'topic_slug' => array(), 'forum_slug' => array(), 'post_url' => array() ); | |
| 11 | 8 | |
| 12 | 9 | function __construct( $wpForo ){ |
| 13 | 10 | if(!isset($this->wpforo)) $this->wpforo = $wpForo; |
| 14 | - | |
| 15 | - $this->init_defaults(); | |
| 16 | - $this->init_options(); | |
| 17 | 11 | } |
| 18 | - | |
| 19 | - private function init_defaults(){ | |
| 20 | - $this->default = new stdClass; | |
| 21 | - | |
| 22 | - $upload_max_filesize = @ini_get('upload_max_filesize'); | |
| 23 | - $upload_max_filesize = wpforo_human_size_to_bytes($upload_max_filesize); | |
| 24 | - if( !$upload_max_filesize || $upload_max_filesize > 10485760 ) $upload_max_filesize = 10485760; | |
| 25 | - | |
| 26 | - $this->default->options = array( | |
| 27 | - 'layout_extended_intro_posts_toggle' => 1, | |
| 28 | - 'layout_extended_intro_posts_count' => 4, | |
| 29 | - 'topics_per_page' => 10, | |
| 30 | - 'eot_durr' => 300, | |
| 31 | - 'dot_durr' => 300, | |
| 32 | - 'posts_per_page' => 15, | |
| 33 | - 'eor_durr' => 300, | |
| 34 | - 'dor_durr' => 300, | |
| 35 | - 'max_upload_size' => $upload_max_filesize, | |
| 36 | - 'attach_cant_view_msg' => __("You are not permitted to view this attachment", 'wpforo') | |
| 37 | - ); | |
| 38 | - } | |
| 39 | - | |
| 40 | - private function init_options(){ | |
| 41 | - $this->options = get_wpf_option('wpforo_post_options', $this->default->options); | |
| 42 | - } | |
| 43 | 12 | |
| 44 | - public function get_cache( $var ){ | |
| 45 | - if( isset(self::$cache[$var]) ) return self::$cache[$var]; | |
| 46 | - } | |
| 47 | - | |
| 48 | 13 | public function add( $args = array() ){ |
| 49 | - | |
| 50 | - //This variable will be based on according CAN of guest usergroup once Guest Posing is ready | |
| 51 | - $guestposting = false; | |
| 52 | - | |
| 53 | 14 | if( empty($args) && empty($_REQUEST['post']) ){ $this->wpforo->notice->add('Reply request error', 'error'); return FALSE; } |
| 54 | 15 | if( empty($args) && !empty($_REQUEST['post']) ){ $args = $_REQUEST['post']; $args['body'] = $_REQUEST['postbody']; } |
| 55 | - if( !isset($args['body']) || !$args['body'] ){ $this->wpforo->notice->add('Post is empty', 'error'); return FALSE; } | |
| 56 | - $args['name'] = (isset($args['name']) ? $args['name'] : '' ); | |
| 57 | - $args['email'] = (isset($args['email']) ? $args['email'] : '' ); | |
| 58 | - if( isset($args['userid']) && $args['userid'] == 0 && $args['name'] && $args['email'] ) $guestposting = true; | |
| 59 | 16 | |
| 60 | 17 | extract($args, EXTR_OVERWRITE); |
| 61 | 18 | |
| 62 | 19 | if( !isset($topicid) || !$topicid ){ $this->wpforo->notice->add('Error: No topic selected', 'error'); return FALSE; } |
| @@ -67,17 +24,14 @@ | ||
| 67 | 24 | $this->wpforo->notice->add('Can\'t write a post: This topic is closed', 'error'); |
| 68 | 25 | return FALSE; |
| 69 | 26 | } |
| 70 | 27 | |
| 71 | - if( !$guestposting && !$this->wpforo->perm->forum_can('cr', $topic['forumid']) ){ | |
| 28 | + if( !$this->wpforo->perm->forum_can(intval($topic['forumid']), 'cr') ){ | |
| 72 | 29 | $this->wpforo->notice->add('You haven\'t permission to create post into this forum', 'error'); |
| 73 | 30 | return FALSE; |
| 74 | 31 | } |
| 75 | 32 | |
| 76 | - do_action( 'wpforo_start_add_post', $args ); | |
| 77 | - | |
| 78 | 33 | $post = $args; |
| 79 | - $post['forumid'] = $forumid = (isset($topic['forumid']) ? intval($topic['forumid']) : 0); | |
| 80 | 34 | $post['parentid'] = $parentid = (isset($parentid) ? intval($parentid) : 0); |
| 81 | 35 | $post['title'] = $title = (isset($title) ? wpforo_text( trim($title), 250, false ) : ''); |
| 82 | 36 | $post['body'] = $body = ( isset($body) ? preg_replace('#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", $body) : '' ); |
| 83 | 37 | $post['created'] = $created = ( isset($created) ? $created : current_time( 'mysql', 1 ) ); |
| @@ -83,9 +37,8 @@ | ||
| 83 | 37 | $post['created'] = $created = ( isset($created) ? $created : current_time( 'mysql', 1 ) ); |
| 84 | 38 | $post['userid'] = $userid = ( isset($userid) ? intval($userid) : $this->wpforo->current_userid ); |
| 85 | 39 | |
| 86 | 40 | $post = apply_filters('wpforo_add_post_data_filter', $post); |
| 87 | - | |
| 88 | 41 | if(empty($post)) return FALSE; |
| 89 | 42 | |
| 90 | 43 | extract($post, EXTR_OVERWRITE); |
| 91 | 44 | |
| @@ -95,11 +48,8 @@ | ||
| 95 | 48 | if(isset($title)) $title = sanitize_text_field(trim($title)); |
| 96 | 49 | if(isset($created)) $created = sanitize_text_field($created); |
| 97 | 50 | if(isset($userid)) $userid = intval($userid); |
| 98 | 51 | if(isset($body)) $body = wpforo_kses(trim($body), 'post'); |
| 99 | - if(isset($status)) $status = intval($status); | |
| 100 | - if(isset($name)) $name = strip_tags(trim($name)); | |
| 101 | - if(isset($email)) $email = strip_tags(trim($email)); | |
| 102 | 52 | |
| 103 | 53 | do_action( 'wpforo_before_add_post', $post ); |
| 104 | 54 | |
| 105 | 55 | if( |
| @@ -105,9 +55,9 @@ | ||
| 105 | 55 | if( |
| 106 | 56 | $this->wpforo->db->insert( |
| 107 | 57 | $this->wpforo->db->prefix . 'wpforo_posts', |
| 108 | 58 | array( |
| 109 | - 'forumid' => $forumid, | |
| 59 | + 'forumid' => (isset($topic['forumid']) ? intval($topic['forumid']) : 0), | |
| 110 | 60 | 'topicid' => $topicid, |
| 111 | 61 | 'parentid' => $parentid, |
| 112 | 62 | 'userid' => $userid, |
| 113 | 63 | 'title' => stripslashes($title), |
| @@ -112,14 +62,11 @@ | ||
| 112 | 62 | 'userid' => $userid, |
| 113 | 63 | 'title' => stripslashes($title), |
| 114 | 64 | 'body' => stripslashes($body), |
| 115 | 65 | 'created' => $created, |
| 116 | - 'modified' => $created, | |
| 117 | - 'status' => (isset($status) ? $status : 0), | |
| 118 | - 'name' => $name, | |
| 119 | - 'email' => $email | |
| 66 | + 'modified' => $created | |
| 120 | 67 | ), |
| 121 | - array('%d','%d','%d','%d','%s','%s','%s','%s','%d','%s','%s') | |
| 68 | + array('%d','%d','%d','%d','%s','%s','%s','%s') | |
| 122 | 69 | ) |
| 123 | 70 | ){ |
| 124 | 71 | $postid = $this->wpforo->db->insert_id; |
| 125 | 72 | |
| @@ -139,11 +86,10 @@ | ||
| 139 | 86 | |
| 140 | 87 | $post['postid'] = $postid; |
| 141 | 88 | $post['posturl'] = $this->get_post_url($postid); |
| 142 | 89 | |
| 143 | - do_action( 'wpforo_after_add_post', $post, $topic ); | |
| 90 | + do_action( 'wpforo_after_add_post', $post ); | |
| 144 | 91 | |
| 145 | - wpforo_clean_cache($postid, 'post', $post); | |
| 146 | 92 | $this->wpforo->member->reset($userid); |
| 147 | 93 | $this->wpforo->notice->add('You successfully replied', 'success'); |
| 148 | 94 | return $postid; |
| 149 | 95 | } |
| @@ -152,42 +98,29 @@ | ||
| 152 | 98 | return FALSE; |
| 153 | 99 | } |
| 154 | 100 | |
| 155 | 101 | public function edit( $args = array() ){ |
| 156 | - | |
| 157 | - //This variable will be based on according CAN of guest usergroup once Guest Posing is ready | |
| 158 | - $guestposting = false; | |
| 159 | - | |
| 160 | 102 | if( empty($args) && (!isset($_REQUEST['post']) || empty($_REQUEST['post'])) ) return FALSE; |
| 161 | 103 | if( empty($args) && !empty($_REQUEST['post']) ){ $args = $_REQUEST['post']; $args['body'] = $_REQUEST['postbody']; } |
| 162 | 104 | |
| 163 | - do_action( 'wpforo_start_edit_post', $args ); | |
| 105 | + $args = apply_filters('wpforo_edit_post_data_filter', $args); | |
| 106 | + if(empty($args)) return FALSE; | |
| 164 | 107 | |
| 165 | - if( !isset($args['postid']) || !$args['postid'] || !is_numeric($args['postid']) ){ | |
| 108 | + extract($args, EXTR_OVERWRITE); | |
| 109 | + | |
| 110 | + if( !isset($postid) || !$postid || !is_numeric($postid) ){ | |
| 166 | 111 | $this->wpforo->notice->add('Cannot update post data', 'error'); |
| 167 | 112 | return FALSE; |
| 168 | 113 | } |
| 169 | - $args['postid'] = intval($args['postid']); | |
| 170 | - if( !$post = $this->get_post($args['postid']) ){ $this->wpforo->notice->add('No Posts found for update', 'error'); return FALSE; } | |
| 171 | 114 | |
| 172 | - $args['userid'] = $post['userid']; | |
| 173 | - $args['status'] = $post['status']; | |
| 174 | - | |
| 175 | - if( isset($args['userid']) && $args['userid'] == 0 && isset($args['name']) && isset($args['email']) ) $guestposting = true; | |
| 115 | + $postid = intval($postid); | |
| 176 | 116 | |
| 177 | - $args = apply_filters('wpforo_edit_post_data_filter', $args); | |
| 178 | - if(empty($args)) return FALSE; | |
| 117 | + if( !$post = $this->get_post($postid) ){ $this->wpforo->notice->add('No Posts found for update', 'error'); return FALSE; } | |
| 179 | 118 | |
| 180 | - extract($args, EXTR_OVERWRITE); | |
| 181 | - | |
| 182 | - if( !$guestposting ){ | |
| 183 | - $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']); | |
| 184 | - if( !($this->wpforo->perm->forum_can('er', $post['forumid']) || | |
| 185 | - ($this->wpforo->current_userid == $post['userid'] && $this->wpforo->perm->forum_can('eor', $post['forumid']) && | |
| 186 | - $diff < $this->wpforo->post->options['eor_durr'])) ){ | |
| 187 | - $this->wpforo->notice->add('You haven\'t permission to edit post from this forum', 'error'); | |
| 188 | - return FALSE; | |
| 189 | - } | |
| 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; | |
| 190 | 123 | } |
| 191 | 124 | |
| 192 | 125 | $title = (isset($title) ? wpforo_text( trim($title), 250, false ) : ''); |
| 193 | 126 | $body = ( isset($body) ? preg_replace('#</pre>[\r\n\t\s\0]*<pre>#isu', "\r\n", $body) : '' ); |
| @@ -199,36 +132,21 @@ | ||
| 199 | 132 | if(isset($slug)) $slug = sanitize_title($slug); |
| 200 | 133 | if(isset($created)) $created = sanitize_text_field($created); |
| 201 | 134 | if(isset($userid)) $userid = intval($userid); |
| 202 | 135 | if(isset($body)) $body = wpforo_kses(trim($body), 'post'); |
| 203 | - if(isset($status)) $status = intval($status); | |
| 204 | - if(isset($name)) $name = strip_tags(trim($name)); | |
| 205 | - if(isset($email)) $email = strip_tags(trim($email)); | |
| 206 | 136 | |
| 207 | - $title = ( isset($title) ? stripslashes($title) : stripslashes($post['title']) ); | |
| 208 | - $body = ( (isset($body) && $body) ? stripslashes($body) : stripslashes($post['body']) ); | |
| 209 | - $status = ( isset($status) ? $status : intval($post['status']) ); | |
| 210 | - $name = ( isset($name) ? stripslashes($name) : stripslashes($post['name']) ); | |
| 211 | - $email = ( isset($email) ? stripslashes($email) : stripslashes($post['email']) ); | |
| 212 | - | |
| 213 | 137 | if( FALSE !== $this->wpforo->db->update( |
| 214 | 138 | $this->wpforo->db->prefix."wpforo_posts", |
| 215 | 139 | array( |
| 216 | - 'title' => $title, | |
| 217 | - 'body' => $body, | |
| 218 | - 'modified' => current_time( 'mysql', 1 ), | |
| 219 | - 'status' => $status, | |
| 220 | - 'name' => $name, | |
| 221 | - 'email' => $email, | |
| 140 | + 'title' => stripslashes($title), | |
| 141 | + 'body' => stripslashes($body), | |
| 142 | + 'modified' => current_time( 'mysql', 1 ) | |
| 222 | 143 | ), |
| 223 | 144 | array('postid' => $postid), |
| 224 | - array('%s','%s','%s','%d','%s','%s'), | |
| 145 | + array('%s','%s','%s'), | |
| 225 | 146 | array('%d') |
| 226 | 147 | ) |
| 227 | 148 | ){ |
| 228 | - do_action( 'wpforo_after_edit_post', array( 'postid' => $postid, 'topicid' => $topicid, 'title' => $title, 'body' => $body, 'status' => $status, 'name' => $name, 'email' => $email) ); | |
| 229 | - | |
| 230 | - wpforo_clean_cache($postid, 'post', $post); | |
| 231 | 149 | $this->wpforo->notice->add('This post successfully edited', 'success'); |
| 232 | 150 | return $postid; |
| 233 | 151 | } |
| 234 | 152 | |
| @@ -237,9 +155,9 @@ | ||
| 237 | 155 | } |
| 238 | 156 | |
| 239 | 157 | ################################################################################# |
| 240 | 158 | /** |
| 241 | - * Delete post from DB | |
| 159 | + * Delete topic from DB | |
| 242 | 160 | * |
| 243 | 161 | * Returns true if successfully deleted or false. |
| 244 | 162 | * |
| 245 | 163 | * @since 1.0.0 |
| @@ -246,25 +164,19 @@ | ||
| 246 | 164 | * |
| 247 | 165 | * @return bool |
| 248 | 166 | */ |
| 249 | 167 | |
| 250 | - function delete($postid, $delete_cache = true){ | |
| 168 | + function delete($postid){ | |
| 169 | + | |
| 251 | 170 | $postid = intval($postid); |
| 252 | 171 | |
| 253 | - if( !$post = $this->get_post($postid) ) return true; | |
| 254 | - | |
| 255 | - do_action('wpforo_before_delete_post', $post); | |
| 256 | - | |
| 172 | + $post = $this->get_post($postid); | |
| 257 | 173 | $diff = current_time( 'timestamp', 1 ) - strtotime($post['created']); |
| 258 | - 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'])) ){ | |
| 259 | 175 | $this->wpforo->notice->add('You haven\'t permission to delete post from this forum', 'error'); |
| 260 | 176 | return FALSE; |
| 261 | 177 | } |
| 262 | 178 | |
| 263 | - //Find and delete default atatchments before deleting post | |
| 264 | - $this->delete_attachments( $postid ); | |
| 265 | - | |
| 266 | - //Delete post | |
| 267 | 179 | if( $this->wpforo->db->delete($this->wpforo->db->prefix . 'wpforo_posts', array( 'postid' => intval($postid) ), array( '%d' )) ){ |
| 268 | 180 | $last_post = $this->get_posts( array('topicid' => intval($post['topicid']), 'order' => 'DESC', 'row_count' => 1) ); |
| 269 | 181 | if(is_array($last_post) && !empty($last_post)){ |
| 270 | 182 | $last_post = $last_post[0]; |
| @@ -271,15 +183,8 @@ | ||
| 271 | 183 | }else{ |
| 272 | 184 | $last_post = array( 'created' => '0000-00-00 00:00:00', 'userid' => 0, 'postid' => 0 ); |
| 273 | 185 | } |
| 274 | 186 | |
| 275 | - $this->wpforo->db->delete( | |
| 276 | - $this->wpforo->db->prefix.'wpforo_likes', array( 'postid' => $postid ), array( '%d' ) | |
| 277 | - ); | |
| 278 | - $this->wpforo->db->delete( | |
| 279 | - $this->wpforo->db->prefix.'wpforo_votes', array( 'postid' => $postid ), array( '%d' ) | |
| 280 | - ); | |
| 281 | - | |
| 282 | 187 | $answ_incr = ''; |
| 283 | 188 | $comm_incr = ''; |
| 284 | 189 | $forum = $this->wpforo->forum->get_forum($post['forumid']); |
| 285 | 190 | if( isset($forum['cat_layout']) && $forum['cat_layout'] == 3 ){ |
| @@ -294,17 +199,12 @@ | ||
| 294 | 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'] ))){ |
| 295 | 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']) ) ){ |
| 296 | 201 | $this->wpforo->member->reset($post['userid']); |
| 297 | 202 | $this->wpforo->notice->add('This post successfully deleted', 'success'); |
| 203 | + return TRUE; | |
| 298 | 204 | } |
| 299 | 205 | } |
| 300 | 206 | } |
| 301 | - | |
| 302 | - do_action('wpforo_after_delete_post', $post); | |
| 303 | - | |
| 304 | - if( $post['is_first_post'] ) return $this->wpforo->topic->delete($post['topicid']); | |
| 305 | - if( $delete_cache ) wpforo_clean_cache($postid, 'post', $post); | |
| 306 | - return TRUE; | |
| 307 | 207 | } |
| 308 | 208 | |
| 309 | 209 | $this->wpforo->notice->add('Post delete error', 'error'); |
| 310 | 210 | return FALSE; |
| @@ -317,76 +217,51 @@ | ||
| 317 | 217 | * Returns array from defined and default arguments. |
| 318 | 218 | * |
| 319 | 219 | * @since 1.0.0 |
| 320 | 220 | * |
| 221 | + * @param mixed defined arguments array for returning | |
| 222 | + * | |
| 321 | 223 | * @return array |
| 322 | 224 | */ |
| 323 | 225 | function get_post($postid){ |
| 324 | 226 | |
| 325 | 227 | $post = array(); |
| 326 | - $cache = $this->wpforo->cache->on('memory_cashe'); | |
| 327 | - | |
| 328 | - if( $cache && isset(self::$cache['post'][$postid]) ){ | |
| 329 | - return self::$cache['post'][$postid]; | |
| 330 | - } | |
| 331 | - | |
| 332 | - $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); | |
| 333 | 229 | $post = $this->wpforo->db->get_row($sql, ARRAY_A); |
| 334 | - if(!empty($post)) $post['userid'] = intval($post['userid']); | |
| 335 | - | |
| 336 | - if( isset($post['forumid']) && $post['forumid'] && !$this->wpforo->perm->forum_can('vf', $post['forumid']) ){ | |
| 337 | - return array(); | |
| 230 | + if(!empty($post)){ | |
| 231 | + $post['userid'] = intval($post['userid']); | |
| 232 | + $post['body'] = wpforo_content_filter($post['body']); | |
| 338 | 233 | } |
| 339 | - | |
| 340 | - if( isset($post['status']) && $post['status'] && !wpforo_is_owner($post['userid'])){ | |
| 341 | - if( isset($post['forumid']) && $post['forumid'] && !$this->wpforo->perm->forum_can('au', $post['forumid']) ){ | |
| 342 | - return array(); | |
| 343 | - } | |
| 344 | - } | |
| 345 | - | |
| 346 | - if($cache && isset($postid)){ | |
| 347 | - self::$cache['post'][$postid] = $post; | |
| 348 | - } | |
| 349 | - | |
| 350 | - $post = apply_filters('wpforo_get_post', $post); | |
| 351 | 234 | return $post; |
| 352 | 235 | } |
| 353 | - | |
| 354 | 236 | /** |
| 237 | + * array get_topic(array or id(num)) | |
| 355 | 238 | * Returns merged arguments array from defined and default arguments. |
| 356 | 239 | * |
| 357 | 240 | * @since 1.0.0 |
| 358 | 241 | * |
| 359 | - * @param array | |
| 242 | + * @param array defined arguments array for returning | |
| 360 | 243 | * |
| 361 | - * @return array | |
| 244 | + * @return associative array where count is topic count and other numeric arrays with topic | |
| 362 | 245 | */ |
| 363 | 246 | function get_posts($args = array(), &$items_count = 0){ |
| 364 | 247 | |
| 365 | - $cache = $this->wpforo->cache->on('object_cashe'); | |
| 366 | - | |
| 367 | 248 | $default = array( |
| 368 | 249 | 'include' => array(), // array( 2, 10, 25 ) |
| 369 | 250 | 'exclude' => array(), // array( 2, 10, 25 ) |
| 370 | 251 | |
| 371 | 252 | 'topicid' => NULL, // topic id in DB |
| 372 | - 'forumid' => NULL, // forum id in DB | |
| 373 | 253 | 'parentid' => -1, // parent post id |
| 374 | 254 | 'userid' => NULL, // user id in DB |
| 375 | 255 | 'orderby' => 'postid', // forumid, order, parentid |
| 376 | 256 | 'order' => 'ASC', // ASC DESC |
| 377 | 257 | 'offset' => NULL, // this use when you give row_count |
| 378 | - 'row_count' => NULL, // 4 or 1 ... | |
| 379 | - 'status' => NULL, // 0 or 1 ... | |
| 380 | - 'email' => NULL, // example@example.com ... | |
| 381 | - | |
| 382 | - 'check_private' => FALSE | |
| 258 | + 'row_count' => NULL // 4 or 1 ... | |
| 383 | 259 | ); |
| 384 | 260 | |
| 385 | 261 | $args = wpforo_parse_args( $args, $default ); |
| 386 | 262 | |
| 387 | 263 | if(is_array($args) && !empty($args)){ |
| 388 | - | |
| 389 | 264 | extract($args, EXTR_OVERWRITE); |
| 390 | 265 | |
| 391 | 266 | if( $row_count === 0 ) return array(); |
| 392 | 267 | |
| @@ -393,52 +268,24 @@ | ||
| 393 | 268 | $include = wpforo_parse_args( $include ); |
| 394 | 269 | $exclude = wpforo_parse_args( $exclude ); |
| 395 | 270 | |
| 396 | 271 | $wheres = array(); |
| 397 | - $table_as_prefix = '`'.$this->wpforo->db->prefix.'wpforo_posts`.'; | |
| 398 | 272 | |
| 399 | - if(!empty($include)) $wheres[] = $table_as_prefix . "`postid` IN(" . implode(', ', array_map('intval', $include)) . ")"; | |
| 400 | - 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)) . ")"; | |
| 401 | 275 | |
| 402 | - if(!is_null($topicid)) $wheres[] = $table_as_prefix . "`topicid` = " . intval($topicid); | |
| 403 | - if($parentid != -1) $wheres[] = $table_as_prefix . "`parentid` = " . intval($parentid); | |
| 404 | - if(!is_null($userid)) $wheres[] = $table_as_prefix . "`userid` = " . intval($userid); | |
| 405 | - if(!is_null($status)) $wheres[] = $table_as_prefix . "`status` = " . intval($status); | |
| 406 | - if(!is_null($email)) $wheres[] = $table_as_prefix . "`email` = '" . esc_sql($email) . "' "; | |
| 407 | - | |
| 408 | - if( isset($forumid) && $forumid ){ | |
| 409 | - if( $this->wpforo->perm->forum_can('au', $forumid) ){ | |
| 410 | - if(!is_null($status)) $wheres[] = $table_as_prefix . " `status` = " . intval($status); | |
| 411 | - } | |
| 412 | - elseif( isset($this->wpforo->current_userid) && $this->wpforo->current_userid ){ | |
| 413 | - $wheres[] = " ( " . $table_as_prefix . "`status` = 0 OR (" . $table_as_prefix . "`status` = 1 AND " . $table_as_prefix . "`userid` = " .intval($this->wpforo->current_userid). ") )"; | |
| 414 | - } | |
| 415 | - else{ | |
| 416 | - $wheres[] = " " . $table_as_prefix . "`status` = 0"; | |
| 417 | - } | |
| 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); | |
| 418 | 283 | } |
| 419 | 284 | |
| 420 | - if( $check_private ){ | |
| 421 | - $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`"; | |
| 422 | - if(!empty($wheres)){ | |
| 423 | - $sql .= " WHERE `".$this->wpforo->db->prefix."wpforo_posts`.`topicid` = `".$this->wpforo->db->prefix."wpforo_topics`.`topicid` " . ((!empty($wheres)) ? 'AND' : '') . " " . implode(" AND ", $wheres); | |
| 424 | - } | |
| 425 | - else{ | |
| 426 | - $sql .= " WHERE `".$this->wpforo->db->prefix."wpforo_posts`.`topicid` = `".$this->wpforo->db->prefix."wpforo_topics`.`topicid` "; | |
| 427 | - } | |
| 428 | - $sql .= " ORDER BY " .$table_as_prefix . "`$orderby` " . $order; | |
| 429 | - $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql); | |
| 430 | - } | |
| 431 | - else{ | |
| 432 | - $sql = "SELECT * FROM `".$this->wpforo->db->prefix."wpforo_posts`"; | |
| 433 | - if(!empty($wheres)){ | |
| 434 | - $sql .= " WHERE " . implode(" AND ", $wheres); | |
| 435 | - } | |
| 436 | - $sql .= " ORDER BY `$orderby` " . $order; | |
| 437 | - $item_count_sql = preg_replace('#SELECT.+?FROM#isu', 'SELECT count(*) FROM', $sql); | |
| 438 | - } | |
| 285 | + $sql .= " ORDER BY `$orderby` " . $order; | |
| 439 | 286 | |
| 440 | - 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)); | |
| 441 | 288 | |
| 442 | 289 | if($row_count != NULL){ |
| 443 | 290 | if($offset != NULL){ |
| 444 | 291 | $sql .= esc_sql(" LIMIT $offset,$row_count"); |
| @@ -446,63 +293,18 @@ | ||
| 446 | 293 | $sql .= esc_sql(" LIMIT $row_count"); |
| 447 | 294 | } |
| 448 | 295 | } |
| 449 | 296 | |
| 450 | - 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']; }} | |
| 451 | - | |
| 452 | 297 | $posts = $this->wpforo->db->get_results($sql, ARRAY_A); |
| 453 | - $posts = apply_filters('wpforo_get_posts', $posts); | |
| 454 | - | |
| 455 | - if( $check_private ){ | |
| 456 | - foreach($posts as $key => $post){ | |
| 457 | - if( isset($post['forumid']) && !$this->wpforo->perm->forum_can('vf', $post['forumid']) ){ | |
| 458 | - unset($posts[$key]); | |
| 459 | - } | |
| 460 | - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['private']) && $post['private'] && !wpforo_is_owner($post['userid']) ){ | |
| 461 | - if( !$this->wpforo->perm->forum_can('vp', $post['forumid']) ){ | |
| 462 | - unset($posts[$key]); | |
| 463 | - } | |
| 464 | - } | |
| 465 | - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['status']) && $post['status'] && !wpforo_is_owner($post['userid']) ){ | |
| 466 | - if( !$this->wpforo->perm->forum_can('au', $post['forumid']) ){ | |
| 467 | - unset($posts[$key]); | |
| 468 | - } | |
| 469 | - } | |
| 470 | - } | |
| 298 | + foreach($posts as $key => $post){ | |
| 299 | + $posts[$key]['body'] = wpforo_content_filter($post['body']); | |
| 471 | 300 | } |
| 301 | + return $posts; | |
| 472 | 302 | |
| 473 | - if($cache && isset($object_key) && !empty($posts)){ | |
| 474 | - self::$cache['posts'][$object_key]['items'] = $posts; | |
| 475 | - self::$cache['posts'][$object_key]['items_count'] = $items_count; | |
| 476 | - } | |
| 477 | - return $posts; | |
| 478 | 303 | } |
| 479 | 304 | } |
| 480 | 305 | |
| 481 | - function get_posts_filtered( $args = array() ){ | |
| 482 | - $posts = array(); | |
| 483 | - $posts = $this->get_posts( $args ); | |
| 484 | - if( !empty($posts) ){ | |
| 485 | - foreach($posts as $key => $post){ | |
| 486 | - if( isset($post['forumid']) && !$this->wpforo->perm->forum_can('vf', $post['forumid']) ){ | |
| 487 | - unset($posts[$key]); | |
| 488 | - } | |
| 489 | - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['private']) && $post['private'] && !wpforo_is_owner($post['userid']) ){ | |
| 490 | - if( !$this->wpforo->perm->forum_can('vp', $post['forumid']) ){ | |
| 491 | - unset($posts[$key]); | |
| 492 | - } | |
| 493 | - } | |
| 494 | - if( isset($posts[$key]) && isset($post['forumid']) && isset($post['status']) && $post['status'] && !wpforo_is_owner($post['userid']) ){ | |
| 495 | - if( !$this->wpforo->perm->forum_can('au', $post['forumid']) ){ | |
| 496 | - unset($posts[$key]); | |
| 497 | - } | |
| 498 | - } | |
| 499 | - } | |
| 500 | - } | |
| 501 | - return $posts; | |
| 502 | - } | |
| 503 | 306 | |
| 504 | - | |
| 505 | 307 | function search( $args = array(), &$items_count = 0 ){ |
| 506 | 308 | if(!is_array($args)) $args = array('needle' => $args); |
| 507 | 309 | |
| 508 | 310 | $default = array( |
| @@ -522,9 +324,9 @@ | ||
| 522 | 324 | extract($args, EXTR_OVERWRITE); |
| 523 | 325 | |
| 524 | 326 | $date_period = intval($date_period); |
| 525 | 327 | |
| 526 | - $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`' ); | |
| 527 | 329 | $innerjoins = array('INNER JOIN `'.$this->wpforo->db->prefix.'wpforo_topics` t ON t.`topicid` = p.`topicid`'); |
| 528 | 330 | $wheres = array(); |
| 529 | 331 | $orders = array(); |
| 530 | 332 | |
| @@ -549,9 +351,9 @@ | ||
| 549 | 351 | $wheres[] = "( MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) OR MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE) )"; |
| 550 | 352 | $orders[] = "MATCH(t.`title`) AGAINST('$needle') + MATCH(p.`title`) AGAINST('$needle')"; |
| 551 | 353 | $orders[] = "MATCH(t.`title`) AGAINST('$needle' IN BOOLEAN MODE) + MATCH(p.`title`) AGAINST('$needle' IN BOOLEAN MODE)"; |
| 552 | 354 | }elseif($type == 'user-posts' || $type == 'user-topics'){ |
| 553 | - $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`"; | |
| 554 | 356 | $wheres[] = "( u.`user_login` LIKE '$needle' OR u.`user_email` LIKE '$needle' OR u.`display_name` LIKE '$needle' )"; |
| 555 | 357 | if($type == 'user-topics') $wheres[] = "`is_first_post` = 1"; |
| 556 | 358 | } |
| 557 | 359 | } |
| @@ -578,16 +380,10 @@ | ||
| 578 | 380 | }else{ |
| 579 | 381 | $sql .= esc_sql(" LIMIT $row_count"); |
| 580 | 382 | } |
| 581 | 383 | } |
| 582 | - | |
| 583 | - $posts = $this->wpforo->db->get_results($sql, ARRAY_A); | |
| 584 | - foreach($posts as $key => $post){ | |
| 585 | - if( !$this->wpforo->perm->forum_can( 'vf', $post['forumid'] ) ) unset($posts[$key]); | |
| 586 | - if( $post['private'] && !$this->wpforo->perm->forum_can( 'vp', $post['forumid'] ) ) unset($posts[$key]); | |
| 587 | - if( $post['status'] && !$this->wpforo->perm->forum_can( 'au', $post['forumid'] ) ) unset($posts[$key]); | |
| 588 | - } | |
| 589 | - return $posts; | |
| 384 | + | |
| 385 | + return $this->wpforo->db->get_results($sql, ARRAY_A); | |
| 590 | 386 | }else{ |
| 591 | 387 | return array(); |
| 592 | 388 | } |
| 593 | 389 | } |
| @@ -603,9 +399,9 @@ | ||
| 603 | 399 | * |
| 604 | 400 | * @return int |
| 605 | 401 | */ |
| 606 | 402 | function get_post_likes_count($postid){ |
| 607 | - 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) ); | |
| 608 | 404 | } |
| 609 | 405 | |
| 610 | 406 | /** |
| 611 | 407 | * return usernames who likes this post |
| @@ -618,9 +414,9 @@ | ||
| 618 | 414 | * |
| 619 | 415 | * @return array |
| 620 | 416 | */ |
| 621 | 417 | function get_likers_usernames($postid){ |
| 622 | - 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); | |
| 623 | 419 | } |
| 624 | 420 | |
| 625 | 421 | /** |
| 626 | 422 | * return like ID or null |
| @@ -672,21 +468,9 @@ | ||
| 672 | 468 | * @return string or false |
| 673 | 469 | */ |
| 674 | 470 | |
| 675 | 471 | function get_forumslug_byid($postid){ |
| 676 | - | |
| 677 | - $cache = $this->wpforo->cache->on('memory_cashe'); | |
| 678 | - | |
| 679 | - if( $cache && isset(self::$cache['forum_slug'][$postid]) ){ | |
| 680 | - return self::$cache['forum_slug'][$postid]; | |
| 681 | - } | |
| 682 | - | |
| 683 | 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)."))"); |
| 684 | - | |
| 685 | - if($cache && isset($postid)){ | |
| 686 | - self::$cache['forum_slug'][$postid] = $slug; | |
| 687 | - } | |
| 688 | - | |
| 689 | 473 | if($slug){ |
| 690 | 474 | return $slug; |
| 691 | 475 | }else{ |
| 692 | 476 | return FALSE; |
| @@ -705,22 +489,10 @@ | ||
| 705 | 489 | * |
| 706 | 490 | * @return string or false |
| 707 | 491 | */ |
| 708 | 492 | |
| 709 | - function get_topicslug_byid( $postid ){ | |
| 710 | - | |
| 711 | - $cache = $this->wpforo->cache->on('memory_cashe'); | |
| 712 | - | |
| 713 | - if( $cache && isset(self::$cache['topic_slug'][$postid]) ){ | |
| 714 | - return self::$cache['topic_slug'][$postid]; | |
| 715 | - } | |
| 716 | - | |
| 493 | + function get_topicslug_byid($postid){ | |
| 717 | 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).")"); |
| 718 | - | |
| 719 | - if($cache && isset($postid)){ | |
| 720 | - self::$cache['topic_slug'][$postid] = $slug; | |
| 721 | - } | |
| 722 | - | |
| 723 | 495 | if($slug){ |
| 724 | 496 | return $slug; |
| 725 | 497 | }else{ |
| 726 | 498 | return FALSE; |
| @@ -735,37 +507,34 @@ | ||
| 735 | 507 | * @param int $postid |
| 736 | 508 | * |
| 737 | 509 | * @return string $url |
| 738 | 510 | */ |
| 739 | - function get_post_url( $arg, $absolute = true ){ | |
| 511 | + function get_post_url( $arg ){ | |
| 740 | 512 | |
| 741 | - $position = array(); | |
| 742 | - | |
| 743 | - if( isset($arg) && !is_array($arg) ){ | |
| 513 | + if(empty($arg['postid'])){ | |
| 744 | 514 | $postid = intval($arg); |
| 745 | 515 | $post = $this->get_post($postid); |
| 746 | 516 | } |
| 747 | - elseif( !empty($arg) && isset($arg['postid']) ){ | |
| 517 | + else{ | |
| 748 | 518 | $post = $arg; |
| 749 | 519 | $postid = $post['postid']; |
| 750 | 520 | } |
| 751 | 521 | |
| 752 | - if( is_array($post) && !empty($post) && $postid ){ | |
| 753 | - $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); | |
| 754 | 524 | if( $post['topicid'] ){ |
| 755 | - 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) ) ); | |
| 756 | - if( $position <= $this->wpforo->post->options['posts_per_page'] ) return wpforo_home_url($url, false, $absolute ) . "#post-" . intval($postid); | |
| 757 | - if( $position && $this->wpforo->post->options['posts_per_page'] ) { | |
| 758 | - $paged = ceil($position / $this->wpforo->post->options['posts_per_page']); | |
| 759 | - } | |
| 760 | - else{ | |
| 761 | - $paged = 1; | |
| 762 | - } | |
| 763 | - return wpforo_home_url( $url . "/paged/" . $paged, 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); | |
| 527 | + $paged = ceil( $position/$this->wpforo->post_options['posts_per_page'] ); | |
| 528 | + return $url . "/paged/".$paged."/#post-" . intval($postid); | |
| 764 | 529 | } |
| 530 | + else{ | |
| 531 | + return WPFORO_BASE_URL; | |
| 532 | + } | |
| 533 | + }else{ | |
| 534 | + return WPFORO_BASE_URL; | |
| 765 | 535 | } |
| 766 | 536 | |
| 767 | - return wpforo_home_url(); | |
| 768 | 537 | } |
| 769 | 538 | |
| 770 | 539 | |
| 771 | 540 | /** |
| @@ -784,74 +553,10 @@ | ||
| 784 | 553 | intval($postid) |
| 785 | 554 | ) ); |
| 786 | 555 | return $is_answered; |
| 787 | 556 | } |
| 788 | - | |
| 789 | - function is_approved( $postid ){ | |
| 790 | - $post = $this->wpforo->db->get_var( "SELECT `status` FROM " . $this->wpforo->db->prefix."wpforo_posts WHERE `postid` = " . intval($postid) ); | |
| 791 | - if( $post ) return FALSE; | |
| 792 | - return TRUE; | |
| 793 | - } | |
| 794 | - | |
| 795 | - function get_count( $args = array() ){ | |
| 796 | - $sql = "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`"; | |
| 797 | - if( !empty($args) ){ | |
| 798 | - $wheres = array(); | |
| 799 | - foreach ($args as $key => $value) $wheres[] = "`$key` = " . intval($value); | |
| 800 | - if($wheres) $sql .= " WHERE " . implode(' AND ', $wheres); | |
| 801 | - } | |
| 802 | - return $this->wpforo->db->get_var($sql); | |
| 803 | - } | |
| 804 | 557 | |
| 805 | - function unapproved_count(){ | |
| 806 | - return $this->wpforo->db->get_var( "SELECT COUNT(*) FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `status` = 1" ); | |
| 558 | + function get_count(){ | |
| 559 | + return $this->wpforo->db->get_var( "SELECT COUNT(`postid`) FROM `".$this->wpforo->db->prefix."wpforo_posts`" ); | |
| 807 | 560 | } |
| 808 | - | |
| 809 | - function get_attachment_id( $filename ){ | |
| 810 | - $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"); | |
| 811 | - return $attach_id; | |
| 812 | - } | |
| 813 | - | |
| 814 | - function delete_attachments( $postid ){ | |
| 815 | - $post = $this->get_post($postid); | |
| 816 | - if( isset($post['body']) && $post['body'] ){ | |
| 817 | - if( preg_match_all('|\/wpforo\/default_attachments\/([^\s\"\]]+)|is', $post['body'], $attachments, PREG_SET_ORDER) ){ | |
| 818 | - $upload_dir = wp_upload_dir(); | |
| 819 | - $default_attachments_dir = $upload_dir['basedir'] . '/wpforo/default_attachments/'; | |
| 820 | - foreach( $attachments as $attachment ){ | |
| 821 | - $filename = trim($attachment[1]); | |
| 822 | - $file = $default_attachments_dir . $filename; | |
| 823 | - if( file_exists($file) ){ | |
| 824 | - $posts = $this->wpforo->db->get_var( "SELECT COUNT(*) as posts FROM `".$this->wpforo->db->prefix."wpforo_posts` WHERE `body` LIKE '%" . esc_sql( $attachment[0] ) . "%'" ); | |
| 825 | - if( is_numeric($posts) && $posts == 1 ){ | |
| 826 | - $attachmentid = $this->get_attachment_id( '/' . $filename ); | |
| 827 | - if ( !wp_delete_attachment( $attachmentid ) ){ | |
| 828 | - @unlink($file); | |
| 829 | - } | |
| 830 | - } | |
| 831 | - } | |
| 832 | - } | |
| 833 | - } | |
| 834 | - } | |
| 835 | - } | |
| 836 | - | |
| 837 | - public function status( $postid, $status ){ | |
| 838 | - if( !$postid = wpforo_bigintval($postid) ) return false; | |
| 839 | - if( !$post = $this->get_post($postid) ) return false; | |
| 840 | - | |
| 841 | - if( $post['is_first_post'] ) return $this->wpforo->topic->status($post['topicid'], $status); | |
| 842 | - | |
| 843 | - if( false !== $this->wpforo->db->update( | |
| 844 | - $this->wpforo->db->prefix."wpforo_posts", | |
| 845 | - array( 'status' => intval($status) ), | |
| 846 | - array( 'postid' => $postid ), | |
| 847 | - array( '%d' ), | |
| 848 | - array( '%d' ) | |
| 849 | - )){ | |
| 850 | - $this->wpforo->notice->add('Done!', 'success'); | |
| 851 | - return true; | |
| 852 | - } | |
| 853 | - | |
| 854 | - $this->wpforo->notice->add('error: Change Status action', 'error'); | |
| 855 | - return false; | |
| 856 | - } | |
| 857 | -} | |
| 561 | +} | |
| 562 | +?> | |