Ejemplo n.º 1
0
 /**
  * Constructor, init on defined hooks of WP and include second class
  * @access  public
  * @since   0.0.2
  * @uses    register_activation_hook, register_uninstall_hook, add_action
  * @return  \Add_Quicktag_Settings
  */
 private function __construct()
 {
     if (!is_admin()) {
         return;
     }
     // textdomain from parent class
     self::$textdomain = parent::get_textdomain();
     self::$option_string = parent::get_option_string();
     self::$plugin = parent::get_plugin_string();
     self::$post_types_for_js = parent::get_post_types_for_js();
     self::$nonce_string = 'addquicktag_nonce';
     register_uninstall_hook(__FILE__, array('Add_Quicktag_Settings', 'unregister_settings'));
     // settings for an active multisite
     if (is_multisite() && is_plugin_active_for_network(self::$plugin)) {
         add_action('network_admin_menu', array($this, 'add_settings_page'));
         // add settings link
         add_filter('network_admin_plugin_action_links', array($this, 'network_admin_plugin_action_links'), 10, 2);
         // save settings on network
         add_action('network_admin_edit_' . self::$option_string, array($this, 'save_network_settings_page'));
         // return message for update settings
         add_action('network_admin_notices', array($this, 'get_network_admin_notices'));
         // add script on settings page
     } else {
         add_action('admin_menu', array($this, 'add_settings_page'));
         // add settings link
         add_filter('plugin_action_links', array($this, 'plugin_action_links'), 10, 2);
         // use settings API
         add_action('admin_init', array($this, 'register_settings'));
     }
     // include js
     add_action('admin_print_scripts-settings_page_' . str_replace('.php', '', plugin_basename(__FILE__)), array($this, 'print_scripts'));
     // add meta boxes on settings pages
     add_action('addquicktag_settings_page_sidebar', array($this, 'get_plugin_infos'));
     add_action('addquicktag_settings_page_sidebar', array($this, 'get_about_plugin'));
     // include class for remove core quicktags
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class-remove-quicktags.php';
     // include class for add enhanced code quicktags
     // @TODO Solution for special code tags in quicktags
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class-code-quicktags.php';
     // include class for im/export
     require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class-imexport.php';
 }
Ejemplo n.º 2
0
 /**
  * Import XML and update settings
  * 
  * @access  public
  * @since   2.0.0
  * @param   string $filename
  * @uses    current_user_can, wp_die, is_plugin_active_for_network, update_site_option, update_option
  * @return  void
  */
 public function import_file($filename = FALSE)
 {
     if (!current_user_can('manage_options')) {
         wp_die(__('Options not update - you don‘t have the privilidges to do this!', parent::get_textdomain()));
     }
     // use tmp file
     if (!$filename) {
         $filename = $_FILES['xml']['tmp_name'];
     }
     $filename = preg_replace("/\\<\\!\\[CDATA\\[(.*?)\\]\\]\\>/ies", "'[CDATA]' . base64_encode('\$1') . '[/CDATA]'", $filename);
     $filename = utf8_encode($filename);
     $matches = simplexml_load_file($filename);
     // create array from xml
     $button = array();
     foreach ($matches->quicktag as $key) {
         foreach ($key as $value) {
             $buttons[$value->getName()] = $value;
         }
         $button[] = $buttons;
     }
     $options['buttons'] = $button;
     // validate the values from xml
     $options = parent::validate_settings($options);
     // update settings in database
     if (is_multisite() && is_plugin_active_for_network(parent::get_plugin_string())) {
         update_site_option(parent::get_option_string(), $options);
     } else {
         update_option(parent::get_option_string(), $options);
     }
 }
Ejemplo n.º 3
0
 /**
  * Import json and update settings
  *
  * @access   public
  * @since    2.0.0
  *
  * @internal param bool|string $filename
  *
  * @uses     current_user_can, wp_die, is_plugin_active_for_network, update_site_option, update_option
  * @return  void
  */
 public function import_file()
 {
     if (!current_user_can('manage_options')) {
         wp_die(esc_html__('Options not update - you don&lsquo;t have the privileges to do this!', parent::get_textdomain()));
     }
     check_admin_referer(parent::$nonce_string);
     $extension = explode('.', $_FILES['import_file']['name']);
     $extension = end($extension);
     if ($extension !== 'json') {
         wp_die(esc_html__('Please upload a valid .json file', parent::get_textdomain()));
     }
     $import_file = $_FILES['import_file']['tmp_name'];
     if (empty($import_file)) {
         wp_die(esc_html__('Please upload a file to import.', parent::get_textdomain()));
     }
     // Retrieve the settings from the file and convert the json object to an array.
     $options = (array) json_decode(file_get_contents($import_file), TRUE);
     if (is_multisite() && is_plugin_active_for_network(self::$plugin)) {
         update_site_option(self::$option_string, $options);
     } else {
         update_option(self::$option_string, $options);
     }
     // redirect to settings page in network
     if (is_multisite() && is_plugin_active_for_network(self::$plugin)) {
         wp_redirect(add_query_arg(array('page' => self::$plugin, 'updated' => 'true'), network_admin_url('settings.php')));
     } else {
         $page = str_replace(basename(__FILE__), 'class-settings.php', plugin_basename(__FILE__));
         wp_redirect(add_query_arg(array('page' => $page, 'updated' => 'true'), admin_url('options-general.php')));
     }
     exit;
 }
Ejemplo n.º 4
0
    /**
     * Add settings area
     *
     * @param $options
     */
    public function get_code_quicktag_area($options)
    {
        if (!isset($options['code_buttons'])) {
            $options['code_buttons'] = array();
        }
        ?>
		<h3><?php 
        esc_html_e('Enhanced Code Quicktag buttons', self::$textdomain);
        ?>
</h3>
		<p><?php 
        esc_html_e('Select the checkbox below to add enhanced code buttons.', $this->get_textdomain());
        ?>
</p>
		<h4><?php 
        esc_html_e('pre: Enhanced Code buttons', self::$textdomain);
        ?>
</h4>
		<p><?php 
        esc_html_e('Enhanced the default Code buttons. Add a pull down menu for different languages before the default code button and include this as class inside the code tag. Also add a pre button for preformatted text.', self::$textdomain);
        ?>
</p>
		<h4><?php 
        esc_html_e('htmlentities: HTML Entities, HTML Decode', self::$textdomain);
        ?>
</h4>
		<p><?php 
        esc_html_e('Add buttons to do the inconvient HTML encoding/decoding, like &lt; to &amp;lt; and back.', self::$textdomain);
        ?>
</p>

		<?php 
        // loop about the post types, create html an values for title in table
        $pt_title = '';
        $pt_colgroup = '';
        foreach ($this->get_post_types_for_js() as $post_type) {
            $pt_title .= '<th class="row-title rotate" title="Post Type"><span><code>' . $post_type . '</code></span></th>' . "\n";
            $pt_colgroup .= '<colgroup></colgroup>' . "\n";
        }
        ?>

		<table class="widefat form-table rmnlCodeQuicktagSettings">
			<colgroup></colgroup>
			<?php 
        echo $pt_colgroup;
        ?>
			<colgroup></colgroup>

			<tr>
				<th class="row-title"><?php 
        esc_html_e('Button', self::$textdomain);
        ?>
</th>
				<?php 
        echo $pt_title;
        ?>
				<th class="row-title num" style="width:3%;">&#x2714;</th>
			</tr>

			<?php 
        // Convert string to array
        //$code_buttons = explode( ',', self::$code_quicktags );
        // Loop over items to remove and unset them from the buttons
        $i = 9999;
        foreach (self::$code_quicktags as $key => $value) {
            echo '<tr id="rmqtb' . $i . '">' . "\n";
            echo '<td><input type="button" class="ed_button" title="" value="' . $value . '"></td>';
            // loop about the post types, create html an values
            $pt_checkboxes = '';
            foreach ($this->get_post_types_for_js() as $post_type) {
                $pt_checked = '';
                if (isset($options['code_buttons'][$value][$post_type]) && 1 == $options['code_buttons'][$value][$post_type]) {
                    $pt_checked = ' checked="checked"';
                }
                $pt_checkboxes .= '<td class="num"><input type="checkbox" name="' . parent::get_option_string() . '[code_buttons][' . $value . '][' . $post_type . ']" value="1"' . $pt_checked . '/></td>' . "\n";
            }
            echo $pt_checkboxes;
            echo '<td class="num"><input type="checkbox" class="toggle" id="select_all_' . $i . '" value="' . $i . '" /></td>' . "\n";
            echo '</tr>' . "\n";
            $i++;
        }
        // Convert new buttons array back into a comma-separated string
        //$code_qt = implode( ',', $code_buttons );
        ?>

		</table>
	<?php 
    }
Ejemplo n.º 5
0
    /**
     * Add settings area
     *
     * @param $options
     */
    public function get_remove_quicktag_area($options)
    {
        if (!isset($options['core_buttons'])) {
            $options['core_buttons'] = array();
        }
        ?>
		<h3><?php 
        esc_html_e('Remove Core Quicktag buttons', parent::get_textdomain());
        ?>
</h3>
		<p><?php 
        esc_html_e('Select the checkbox below to remove a core quicktags in the editors of the respective post type.', $this->get_textdomain());
        ?>
</p>

		<?php 
        // loop about the post types, create html an values for title in table
        $pt_title = '';
        $pt_colgroup = '';
        foreach ($this->get_post_types_for_js() as $post_type) {
            $pt_title .= '<th class="row-title rotate" title="Post Type"><span><code>' . $post_type . '</code></span></th>' . "\n";
            $pt_colgroup .= '<colgroup></colgroup>' . "\n";
        }
        ?>

		<table class="widefat form-table rmnlCoreQuicktagSettings">
			<colgroup></colgroup>
			<?php 
        echo $pt_colgroup;
        ?>
			<colgroup></colgroup>

			<tr>
				<th class="row-title"><?php 
        esc_html_e('Button', parent::get_textdomain());
        ?>
</th>
				<?php 
        echo $pt_title;
        ?>
				<th class="row-title num" style="width:3%;">&#x2714;</th>
			</tr>

			<?php 
        // Convert string to array
        $core_buttons = explode(',', self::$core_quicktags);
        // Loop over items to remove and unset them from the buttons
        $i = 999;
        foreach ($core_buttons as $key => $value) {
            // same style as in editor
            if ('strong' === $value) {
                $text = 'b';
                $style = ' style="font-weight: bold;"';
            } else {
                if ('em' === $value) {
                    $text = 'i';
                    $style = ' style="font-style: italic;"';
                } else {
                    if ('link' === $value) {
                        $text = $value;
                        $style = ' style="text-decoration: underline;"';
                    } else {
                        if ('del' === $value) {
                            $text = $value;
                            $style = ' style="text-decoration: line-through;"';
                        } else {
                            if ('block' === $value) {
                                $text = 'b-quote';
                                $style = '';
                            } else {
                                $text = $value;
                                $style = '';
                            }
                        }
                    }
                }
            }
            echo '<tr id="rmqtb' . $i . '">' . "\n";
            echo '<td><input type="button" class="ed_button" title="" value="' . $text . '"' . $style . '> <code>' . $value . '</code></td>';
            // loop about the post types, create html an values
            $pt_checkboxes = '';
            foreach ($this->get_post_types_for_js() as $post_type) {
                $pt_checked = '';
                if (isset($options['core_buttons'][$value][$post_type]) && 1 == $options['core_buttons'][$value][$post_type]) {
                    $pt_checked = ' checked="checked"';
                }
                $pt_checkboxes .= '<td class="num"><input type="checkbox" name="' . parent::get_option_string() . '[core_buttons][' . $value . '][' . $post_type . ']" value="1"' . $pt_checked . '/></td>' . "\n";
            }
            echo $pt_checkboxes;
            echo '<td class="num"><input type="checkbox" class="toggle" id="select_all_' . $i . '" value="' . $i . '" /></td>' . "\n";
            echo '</tr>' . "\n";
            $i++;
        }
        // Convert new buttons array back into a comma-separated string
        $core_qt = implode(',', $core_buttons);
        ?>
		</table>
	<?php 
    }