asgarosforum = $object; add_filter('mce_buttons', array($this, 'default_mce_buttons'), 1, 2); add_filter('mce_buttons', array($this, 'add_mce_buttons'), 9999, 2); add_filter('mce_buttons_2', array($this, 'remove_mce_buttons'), 1, 2); add_filter('mce_buttons_3', array($this, 'remove_mce_buttons'), 1, 2); add_filter('mce_buttons_4', array($this, 'remove_mce_buttons'), 1, 2); add_filter('disable_captions', array($this, 'disable_captions')); add_filter('tiny_mce_before_init', array($this, 'toggle_editor')); } // Set the default TinyMCE buttons. public function default_mce_buttons($buttons, $editor_id) { // Array of default editor buttons of WordPress which should not get added automatically to the forum. $default_buttons = array( 'aligncenter', 'alignleft', 'alignright', 'blockquote', 'bold', 'bullist', 'charmap', 'dfw', 'forecolor', 'formatselect', 'fullscreen', 'hr', 'indent', 'italic', 'link', 'numlist', 'outdent', 'pastetext', 'redo', 'removeformat', 'spellchecker', 'strikethrough', 'underline', 'undo', 'unlink', 'wp_add_media', 'wp_adv', 'wp_help', 'wp_more' ); if ($this->asgarosforum->executePlugin && $editor_id === 'message') { // Build array of available buttons. $forum_buttons = array( 'bold', 'italic', 'underline', 'strikethrough', 'forecolor', 'bullist', 'numlist', 'outdent', 'indent', 'alignleft', 'aligncenter', 'alignright', 'pastetext', 'removeformat', 'undo', 'redo', 'blockquote', 'link' ); // Find non-default editor buttons. $unique_buttons = array_diff($buttons, $default_buttons); // Merge forum and non-default editor buttons. $buttons = array_merge($forum_buttons, $unique_buttons); // Apply filters. $buttons = apply_filters('asgarosforum_filter_editor_buttons', $buttons); } return $buttons; } // Add custom TinyMCE buttons. public function add_mce_buttons($buttons, $editor_id) { if ($this->asgarosforum->executePlugin && $editor_id === 'message') { $buttons[] = 'image'; } return $buttons; } // Remove TinyMCE buttons. public function remove_mce_buttons($buttons, $editor_id) { if ($this->asgarosforum->executePlugin && $editor_id === 'message') { $buttons = array(); } return $buttons; } public function disable_captions($args) { if ($this->asgarosforum->executePlugin) { return true; } else { return $args; } } public function toggle_editor($args) { if ($this->asgarosforum->executePlugin) { // Ensure that the editor is toggled. $args['wordpress_adv_hidden'] = false; } return $args; } // Check permissions before loading the editor. private function checkPermissions($editor_view) { switch ($editor_view) { case 'addtopic': // Error when the user is not logged-in and guest-posting is disabled. if (!is_user_logged_in() && !$this->asgarosforum->options['allow_guest_postings']) { return false; break; } // Error when the user is banned. if ($this->asgarosforum->permissions->isBanned('current')) { return false; break; } // Error when the forum is closed. if (!$this->asgarosforum->forumIsOpen()) { return false; break; } break; case 'addpost': // Error when user is not logged-in and guest-posting is disabled. if (!is_user_logged_in() && !$this->asgarosforum->options['allow_guest_postings']) { return false; break; } // Error when the user is banned. if ($this->asgarosforum->permissions->isBanned('current')) { return false; break; } // Error when the topic is closed and the user is not a moderator. if ($this->asgarosforum->is_topic_closed($this->asgarosforum->current_topic) && !$this->asgarosforum->permissions->isModerator('current')) { return false; break; } break; case 'editpost': // Error when user is not logged-in. if (!is_user_logged_in()) { return false; break; } // Error when the user cannot edit a post. $user_id = $this->asgarosforum->permissions->currentUserID; if (!$this->asgarosforum->permissions->can_edit_post($user_id, $this->asgarosforum->current_post)) { return false; break; } break; } return true; } public function showEditor($editor_view, $inOtherView = false) { if (!$this->checkPermissions($editor_view) && !$inOtherView) { $this->asgarosforum->render_notice(__('You are not allowed to do this.', 'asgaros-forum')); } else { $post = false; $subject = (isset($_POST['subject'])) ? sanitize_text_field($_POST['subject']) : ''; $message = (isset($_POST['message'])) ? wp_kses_post($_POST['message']) : ''; if ($editor_view === 'addpost') { if (!isset($_POST['message']) && isset($_GET['quote'])) { // We also select against the topic to ensure that we can only quote posts from the current topic. $quoteData = $this->asgarosforum->db->get_row($this->asgarosforum->db->prepare("SELECT text, author_id, date FROM ".$this->asgarosforum->tables->posts." WHERE id = %d AND parent_id = %d;", absint($_GET['quote']), $this->asgarosforum->current_topic)); if ($quoteData) { $message = '
'.__('Quote from', 'asgaros-forum').' '.$this->asgarosforum->getUsername($quoteData->author_id).' '.sprintf(__('on %s', 'asgaros-forum'), $this->asgarosforum->format_date($quoteData->date)).''.stripslashes($quoteData->text).'