asgarosforum = $object; add_filter('teeny_mce_buttons', array($this, 'custom_mce_buttons'), 9999, 2); add_filter('mce_buttons', array($this, 'custom_mce_buttons'), 9999, 2); add_filter('disable_captions', array($this, 'disable_captions')); add_filter('tiny_mce_before_init', array($this, 'toggle_editor')); } public function custom_mce_buttons($buttons, $editor_id) { if ($this->asgarosforum->executePlugin && $editor_id === 'message') { // Add image button. $buttons[] = 'image'; // Remove the read-more button. $searchKey = array_search('wp_more', $buttons); if ($searchKey !== false) { unset($buttons[$searchKey]); } // Remove the toggle-button when we dont use the minimalistic editor. if ($this->asgarosforum->options['minimalistic_editor'] === false) { $searchKey = array_search('wp_adv', $buttons); if ($searchKey !== false) { unset($buttons[$searchKey]); } } $buttons = apply_filters('asgarosforum_filter_editor_buttons', $buttons); } 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) { // Toggle editor when we dont use the minimalistic editor. if ($this->asgarosforum->options['minimalistic_editor'] === false) { $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'])) ? trim($_POST['subject']) : ''; $message = (isset($_POST['message'])) ? trim($_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).'