domain = 'comment-form-quicktags'; $this->plugin_name = 'comment-form-quicktags'; $this->plugin_dir = '/' . PLUGINDIR . '/' . $this->plugin_name; $this->option_name = $this->plugin_name . '-option'; $this->option_hook = 'cfq_option_page'; $this->cap = 'comment_form_quicktags'; if (defined('WP_PLUGIN_URL')) { $this->plugin_url = WP_PLUGIN_URL . '/' . $this->plugin_name; } else { $this->plugin_url = get_option('siteurl') . '/' . PLUGINDIR . '/' . $this->plugin_name; } load_textdomain($this->domain, dirname(__FILE__) . '/languages/' . get_locale() . '.mo'); $this->get_option(); $this->set_hooks(); } /** * Get plugin options. */ function get_option() { $this->options = (array)get_option($this->option_name); $this->options += array( 'tags' => array( 'strong' => array( 'display' => 'b', 'start' => '', 'end' => '', 'access' => 'b' ), 'em' => array( 'display' => 'i', 'start' => '', 'end' => '', 'access' => 'i' ), 'del' => array( 'display' => 'del', 'start' => '', 'end' => '', 'access' => 'd' ), 'link' => array( 'display' => 'link', 'start' => '', 'end' => '', 'access' => 'a' ), 'block' => array( 'display' => 'b-quote', 'start' => '
', 'end' => '
', 'access' => 'q' ), 'code' => array( 'display' => 'code', 'start' => '', 'end' => '', 'access' => 'c' ), 'close' => array( 'display' => 'Close Tags', 'start' => '', 'end' => '', 'access' => '' ) ), 'modified' => filemtime(__FILE__), 'cap_check' => false ); if ($this->options['modified'] < filemtime(__FILE__)) { $this->options['modified'] = filemtime(__FILE__); } if (array_key_exists('sort', $this->options)) { $tags = array(); foreach ($this->options['sort'] as $id) { $tags[$id] = $this->options['tags'][$id]; } $this->options['tags'] = $tags; unset($this->options['sort']); $this->update_option(); } } /** * Update plugin options. */ function update_option() { update_option($this->option_name, $this->options); } /** * Delete plugin options. */ function delete_option() { $this->options = array(); delete_option($this->option_name); } /** * Set WP hooks. */ function set_hooks() { wp_register_script('cfq', $this->plugin_url . '/quicktags.php', array(), date('Ymd', $this->options['modified'])); wp_register_style('cfq', $this->plugin_url . '/style.css', array(), date('Ymd', filemtime(dirname(__FILE__) . '/style.css'))); add_action('wp_print_scripts', array(&$this, 'add_scripts')); add_action('wp_print_styles', array(&$this, 'add_styles')); add_action('admin_menu', array(&$this, 'set_admin_hooks')); add_filter('comments_template', array(&$this, 'detect_start')); // for comments-popup.php if (isset($_GET['comments_popup'])) { wp_enqueue_script('cfq'); wp_enqueue_style('cfq'); $this->detect_start(); } } /** * Check capabilities. */ function can_quicktag() { return !$this->options['cap_check'] || ($this->options['cap_check'] && current_user_can($this->cap)); } /** * Add scripts. */ function add_scripts() { if (is_singular()) { wp_enqueue_script('cfq'); } } /** * Add styles. */ function add_styles() { if (is_singular()) { wp_enqueue_style('cfq'); } } /** * Set WP hooks for admin. */ function set_admin_hooks() { $page = add_options_page(__('Comment Form Quicktags Options', $this->domain), __('Comment Form Quicktags', $this->domain), 8, $this->option_hook, array(&$this, 'options_page')); add_filter('plugin_action_links', array(&$this, 'add_action_links'), 10, 2); add_action('admin_print_scripts-' . $page, array(&$this, 'add_admin_scripts')); add_action('admin_print_styles-' . $page, array(&$this, 'add_admin_styles')); } /** * Add scripts to admin header. */ function add_admin_scripts() { wp_enqueue_script('cfq-admin', $this->plugin_dir . '/admin.js', array('scriptaculous-dragdrop', 'scriptaculous-effects')); wp_localize_script('cfq-admin', 'cfqadminL10n', array( 'removeConfirm' => __('Are you sure?', $this->domain) )); } /** * Add styles to admin header. */ function add_admin_styles() { wp_enqueue_style('cfq'); wp_enqueue_style('cfq-admin', $this->plugin_url . '/admin.css'); } /** * Add settings link to pluguin menu. * @param array $links * @param string $file * @return array */ function add_action_links($links, $file){ if ($file == $this->plugin_name . '/' . basename(__FILE__)) { $settings_link = '' . __('Settings', $this->domain) . ''; $links = array_merge(array($settings_link), $links); } return $links; } /** * Start to detect %U', $toolbar . "\n" . '\\0' . "\n" . $activate, $content ); return $content; } /** * Print quicktag script. */ function print_tag_js() { foreach($this->options['tags'] as $id => $sets) { printf( 'edButtons[edButtons.length] = new edButton(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\');', 'ed_' . $id, $sets['display'], $sets['start'], $sets['end'], $sets['access'] ); } } /** * Admin page function. */ function options_page() { global $wp_roles; include 'json.php'; if (isset($_POST['action'])) { switch ($_POST['action']) { case 'update': parse_str($_POST['sort'], $buf); $sort = $buf['ed_toolbar']; $tags = json_decode(stripslashes($_POST['tags'])); $this->options['tags'] = array(); foreach ($sort as $id) { $this->options['tags'][$id] = (array)$tags->$id; } $this->options['modified'] = time(); $this->update_option(); echo '

' . __('Options saved.', $this->domain) . '

'; break; case 'rolelimit': $this->options['cap_check'] = isset($_POST['cap_check']); $this->update_option(); if ($this->options['cap_check']) { foreach ($wp_roles->get_names() as $role => $name) { $wp_roles->add_cap($role, $this->cap, in_array($role, $_POST['role'])); } } echo '

' . __('Options saved.', $this->domain) . '

'; break; case 'remove': $this->delete_option(); $this->get_option(); foreach ($wp_roles->get_names() as $role => $name) { $wp_roles->remove_cap($role, $this->cap); } echo '

' . __('Options removed.', $this->domain) . '

'; break; } } ?>

domain) ?>

domain) ?>

  1. domain) ?>
  2. domain) ?>
  3. domain) ?>
  4. domain) ?>
  5. domain) ?>

[Info] Allowed tags in comments: %s.', $this->domain), trim(allowed_tags())) ?>

[Note] There are special IDs: ed_link, ed_img and ed_close.', $this->domain) ?>

options['tags'] as $id => $sets): ?>
ed_

domain) ?>

domain) ?>
roles as $role => $data) { $checked = isset($data['capabilities'][$this->cap]) && $data['capabilities'][$this->cap] ? 'checked="checked"' : ''; $disabled = $this->options['cap_check'] ? '' : 'disabled="disabled"'; printf('
', $role, $checked, $disabled, translate_user_role($data['name'])); } ?>

domain) ?>

domain) ?>