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() { ?>
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 ); } } ?>