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