util = new Util(); } public function add_default_settings() { if (false == get_option(APFW_OPTION_NAME)) { add_option(APFW_OPTION_NAME, $this->get_default_options()); } } private function get_default_options() { return array( 'plugin_ver' => APFW_PLUGIN_VERSION, 'theme' => 2, 'lang' => array(1, 2, 3), 'plugin' => array(4), 'onlyOnPost' => 0, 'noAssistant' => 0, ); } /** * Register our settings, using WP settings API */ public function register_plugin_settings() { register_setting(APFW_OPTION_NAME, APFW_OPTION_NAME, array($this, 'validate_form_post')); } public function add_to_settings_menu() { $page_hook_suffix = add_submenu_page('options-general.php', 'Prism For WP', 'Prism For WP', 'manage_options', self::PLUGIN_SLUG, array($this, 'show_options_page')); /* Add help drop down menu on option page wp v3.3+ */ add_action("load-$page_hook_suffix", array($this, 'add_help_menu_tab')); // We can load additional css/js to our option page here add_action('admin_print_scripts-' . $page_hook_suffix, array($this, 'add_settings_assets')); } public function add_plugin_actions_links($links) { if (current_user_can('manage_options')) { $url = add_query_arg('page', self::PLUGIN_SLUG, 'options-general.php'); array_unshift( $links, sprintf('%s', esc_url($url), __('Settings')) ); } return $links; } public function add_settings_assets() { wp_enqueue_style('prism-admin', plugins_url("/assets/options-page.css", APFW_BASE_FILE), array(), APFW_PLUGIN_VERSION); wp_enqueue_script('prism-admin', plugins_url("/assets/options-page.js", APFW_BASE_FILE), array('jquery'), APFW_PLUGIN_VERSION, true); } public function validate_form_post($in) { $out = array(); $out['plugin_ver'] = APFW_PLUGIN_VERSION; if (isset($in['theme'])) { $out['theme'] = intval($in['theme']); } else { $out['theme'] = 1; } if (isset($in['lang'])) { $out['lang'] = $in['lang']; } else { $out['lang'] = array(); add_settings_error(APFW_OPTION_NAME, 'apfw_lang', 'At-least one language must be selected to work.'); } if (isset($in['plugin'])) { $out['plugin'] = $in['plugin']; } else { $out['plugin'] = array(); } $out['onlyOnPost'] = (isset($in['onlyOnPost'])) ? 1 : 0; $out['noAssistant'] = (isset($in['noAssistant'])) ? 1 : 0; //delete js and css files, will be re-created on front end $this->util->delete_file('prism-css.min.css'); $this->util->delete_file('prism-js.min.js'); return $out; } public function show_options_page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $this->util->load_view('settings', array( 'db' => get_option(APFW_OPTION_NAME), 'themeList' => $this->util->get_themes_list(), 'langList' => $this->util->get_langs_list(), 'pluginList' => $this->util->get_plugins_list() )); } public function add_editor_button() { if ($this->should_add_button() == true) { add_filter("mce_external_plugins", array($this, "add_tinymce_plugin")); add_filter('mce_buttons', array($this, 'register_tinymce_button')); } } public function register_tinymce_button($buttons) { array_push($buttons, "prism_assist_button"); return $buttons; } public function add_tinymce_plugin($plugin_array) { $plugin_array['prism_assist_button'] = plugins_url('/assets/editor-plugin.js', APFW_BASE_FILE); return $plugin_array; } public function add_admin_inline_script($hook) { if ($this->should_add_button() == true) { $lang_list = $this->util->get_langs_list(); echo ""; } } public function add_admin_inline_style($hook) { if ($this->should_add_button() == true) { ?> add_help_tab( array( 'id' => 'apfw-overview', 'title' => 'Overview', 'content' => '

Thanks for using this plugin.
' . 'This plugin allows you to control and use Prism Syntax Highlighter on your website. Just configure options below and ' . 'save your settings.Then use something like this in your posts.' . '<pre><code class="language-css">p { color: red }</code></pre>' . '
You can also use in editor Prism Assistant Button.

' ) ); $currentScreen->add_help_tab( array( 'id' => 'apfw-troubleshoot', 'title' => 'Troubleshoot', 'content' => '

Things to remember' . '

' ) ); $currentScreen->add_help_tab( array( 'id' => 'apfw-more-info', 'title' => 'More', 'content' => '

Need more information ?
' . 'A brief FAQ is available here
' . 'You can also check out instructions from original developer here .
' . 'Support is only available on WordPress Forums, click here to ask anything about this plugin.
' . 'You can also report a bug at plugin's GitHub page.' . ' I will try to reply as soon as possible.

' ) ); // Help sidebar links $currentScreen->set_help_sidebar( '

Quick Links

' . '

Plugin FAQ

' . '

Plugin Home

' ); } }