array ( 'php', 'markup', 'css', 'javascript', 'sass', 'sql', 'adddarkplain', 'addlightplain' ), 'default-lang' => 'php', 'max-height' => '480', 'add-css' => 0, 'add-css-value' => '', 'theme' => 'default', 'line-highlight' => 1, 'line-numbers' => 1, 'autolinker' => 1, 'copy-to-clipboard' => 1, 'class' => '', 'token' => '1470914799' ); private $options; private $options_phdata; private $admin_notices; public function __construct() { $this->init(); $this->admin_notices = new Aphph_Admin_Notices; $this->options = get_option( APHPH_OPTION, array() ); $this->options_phdata = get_option( APHPH_OPTION_PHDATA, array() ); register_activation_hook ( APHPH_PLUGIN_PATH . APHPH_DS . APHPH_PLUGIN_FILE_NAME, array($this, 'activate_plugin') ); add_action( 'admin_init', array( $this, 'page_init' ) ); add_action( 'admin_menu', array( $this, 'add_plugin_page' ) ); add_filter( 'plugin_action_links', array($this, 'action_link'), 10, 5); add_action( 'admin_enqueue_scripts', array($this, 'register_scripts') ); add_action( 'updated_option', array($this, 'build_files'), 10, 3); add_action( 'plugins_loaded', array($this, 'check_update') ); // AJAX add_action( 'wp_ajax_nopriv_aphph-dismiss-notice' , array( $this , 'ajax_no_priv' ) ); add_action( 'wp_ajax_aphph-dismiss-notice', array($this, 'ajax_dismiss_notice') ); } private function init() { $contents = file_get_contents(APHPH_PLUGIN_PATH . APHPH_DS . 'includes/prism/conponents_json.json'); $components = json_decode($contents, true); // Languages foreach ($components as $item => $val) { if ($item == 'languages') { foreach($val as $component_name => $item) { if ($component_name == 'meta') { continue; } $components_list['lang-list'][$component_name] = $item; } $components_list['lang-list']['adddarkplain'] = array('title' => 'Dark Plain'); $components_list['lang-list']['addlightplain'] = array('title' => 'Light Plain'); } if ($item == 'themes') { foreach($val as $theme_name => $item) { if ($theme_name == 'meta') { continue; } if (is_array($item)) { $title = $item['title']; } else { $title = $item; } $components_list['themes'][$theme_name] = $title; } } if ($item == 'plugins') { foreach($val as $theme_name => $item) { if ($theme_name == 'meta') { continue; } if (is_array($item)) { $title = $item['title']; } else { $title = $item; } $components_list['plugins'][$theme_name] = $title; } } } $this->components_list = $components_list; } public function ajax_no_priv() { // echo 'xxx'; die; } // When the close button is clicked public function ajax_dismiss_notice() { $check = wp_verify_nonce($_POST['nonce'], 'aphph-admin-all'); if ($check) { $this->admin_notices->delete_notice($_POST['msg']); } wp_send_json_success( array( 'msg' => 'success', 'check' => $check ) ); } public function page_init() { register_setting( 'aphph_option_group', // Option group APHPH_OPTION, array ($this, 'submit_validation') ); } public function activate_plugin() { if (!$this->options) { update_option(APHPH_OPTION, $this->data_options); update_option(APHPH_OPTION_VERSION, APHPH_PLUGIN_VERSION); update_option(APHPH_OPTION_PHDATA, $this->components_list); add_action('wp_head', array($this, 'build_files')); } } public function check_update() { $plugin_option_version = get_option( APHPH_OPTION_VERSION, '0' ); if (version_compare(APHPH_PLUGIN_VERSION, $plugin_option_version) > 0) { update_option(APHPH_OPTION_VERSION, APHPH_PLUGIN_VERSION); update_option(APHPH_OPTION_PHDATA, $this->components_list); if (!$plugin_option_version || $plugin_option_version < 1.2) { $msg = 'APH PRISM HIGHLIGHTER v' . APHPH_PLUGIN_VERSION . ' Language added: Dark Plain and Light Plain'; $this->admin_notices->add_notice($msg, 'success', false, true); } } } public function register_scripts($hook) { if ($hook == 'settings_page_'.APHPH_PLUGIN_DIR_NAME) { wp_enqueue_style('aphph-style', APHPH_PLUGIN_URL . '/css/aphph-admin.css?rand='.time(), '', APHPH_PLUGIN_VERSION); wp_enqueue_style('aphph-icon', APHPH_PLUGIN_URL . '/css/icomoon/style.css?rand='.time(), '', APHPH_PLUGIN_VERSION); wp_enqueue_script('aphph-taboverride', APHPH_PLUGIN_URL . '/js/taboverride/taboverride.min.js', '', APHPH_PLUGIN_VERSION); wp_enqueue_script('aphph-prism-components', APHPH_PLUGIN_URL . '/includes/prism/components.js?rand='.time(), '', APHPH_PLUGIN_VERSION); wp_enqueue_script('aphph-admin', APHPH_PLUGIN_URL . '/js/aphph-admin.js?rand='.time(), 'aphph-prism-components', APHPH_PLUGIN_VERSION); } wp_enqueue_script('aphph-admin-all', APHPH_PLUGIN_URL . '/js/aphph-admin-all.js?rand='.time(), '', APHPH_PLUGIN_VERSION); wp_localize_script ( 'aphph-admin-all', 'aphph', array( 'nonce' => wp_create_nonce('aphph-admin-all'), 'ajaxurl' => admin_url('admin-ajax.php') ) ); } /** * Add Settings ling to plugin list Settings | Deactivate | Edit */ public function action_link($links, $file) { static $plugin; if (!isset($plugin)) $plugin = APHPH_PLUGIN_DIR_NAME . '/' . APHPH_PLUGIN_FILE_NAME; if ($plugin == $file) { $setting_link = 'Settings'; array_unshift($links, $setting_link); } return $links; } /** * Add options page */ public function add_plugin_page() { $page_title = 'APH Prism Highlighter Options'; $menu_title = 'Prism Highlighter'; $url = 'aph-prism-highlighter'; add_options_page( $page_title, $menu_title, 'manage_options', $url, array( $this, 'admin_setting_page' ) ); } // FORM public function admin_setting_page() { ?>

Options

APH Prism Highlighter

Choose languages option_language_list(); ?>
Default Language option_default_language()?>
Theme option_theme_list(); ?>
Plugins option_plugin_options(); ?>
Starting Line Number

Used when "Line Numbers" plugin is checked

Max Height px

Set maximum height of code container. Recomended 480px. This is usefull in long code, users don't need to scroll page a lot when they want to continue reading the article

Additional CSS 'No', 1 => 'Yes'); echo ''; $show_add_css = !$this->options['add-css'] ? ' style="display:none"' : ''; ?>

Add css code to the compiled css file. This is useful for example if we want to add responsive style to the code.

>

The container class is aphph-container. Click here for example of responsive style

Add global class

Add class to each code block container

'; }?>
options['lang-used']; echo '
'; $load_lang['core'] = 'Core'; $lang_list = $this->components_list['lang-list']; foreach ($lang_used as $lang) { // AFallback to old plugin version if (strtolower($lang) == 'core') continue; $lang_item = $lang_list[$lang]; $lang_title = $lang_list[$lang]['title']; // Dependencies if (is_array($lang_item)) { if (key_exists('require', $lang_item)) { if (!is_array($lang_item['require'])) { $lang_item['require'] = array($lang_item['require']); } foreach ($lang_item['require'] as $lang_required) { if (!key_exists($lang_required, $load_lang)) { $load_lang[$lang_required] = $lang_list[$lang_required]['title']; $file_name[$lang_required] = 'prism-'.$lang_required.'.min.js'; } } } } $load_lang[$lang] = $lang_title; $file_name[$lang] = 'prism-'.$lang.'.min.js'; } // Create lang buttons on the Choose language options foreach ($load_lang as $lang_name => $lang_title) { $msg = ''; if (substr($lang_name, 0, 3) != 'add' && !file_exists(APHPH_PLUGIN_PATH . APHPH_DS . 'includes' . APHPH_DS . 'prism' . APHPH_DS . 'components' . APHPH_DS . $file_name[$lang_name]) ) { $msg = 'File ' . $file_name[$lang_name] . ' not exists'; } $id = $lang_name == 'core' ? 'aphph-langused-disabled' : 'aphph-langused-'.$lang_name; $class = $lang_name == 'core' ? ' aphph-langused-disabled' : ''; $link = $lang_name == 'core' ? '' : ''; if (is_array($lang_list[$lang_name])) { if (key_exists('aliasTitles', $lang_list[$lang_name])) { $lang_title .= ' / ' . join($lang_list[$lang_name]['aliasTitles'], ' / '); } } echo '
'.$lang_title. $link .'
' . $msg; } echo '
Add Language Remove All'; // CREATE LIST OF ALL AVAILABLE LANGUAGES - Built in languages echo '
'; unset($lang_list['core']); echo '
'; // Languages foreach ($lang_list as $lang_key => $item) { $msg = ''; if (substr($lang_key, 0, 3) != 'add') { $file_name = 'prism-'.$lang_key.'.min.js'; if (!file_exists(APHPH_PLUGIN_PATH . APHPH_DS . 'includes' . APHPH_DS . 'prism' . APHPH_DS . 'components' . APHPH_DS . $file_name)) { $msg = 'File ' . $file_name . ' not exists'; } } $checked = key_exists($lang_key, $load_lang) ? ' checked="checked"' : ''; $title = $item['title']; if (key_exists('aliasTitles', $item)) { $title .= ' / ' . join($item['aliasTitles'], ' / '); } echo ' ' . $msg; } echo '
'; } // Default Language public function option_default_language() { $lang_used = $this->options['lang-used']; echo '

Default language in the code editor\'s drop down menu

'; // Other list of language, hidden, displayed when the language pack changed; echo ''; } // THEMES public function option_theme_list() { $theme_list = $this->components_list['themes']; $options = ''; echo $options; } // PLUGINS public function option_plugin_options() { $options = $this->options['options']; foreach($this->components_list['plugins'] as $plugin_name => $item) { if ($plugin_name == 'meta') continue; $title = is_array($item) ? $item['title'] : $item?>

data_options; } else { foreach ($this->options as $key => $val) { if (!key_exists($key, $inputs)) { $inputs[$key] = 0; } } } return $inputs; } public function build_files() { $obj = new Aphph_Build; $obj->build_files( $this->components_list ); } } ?>