array( 'abap' => 'ABAB', 'actionscript' => 'ActionScript', 'ada' => 'Ada', 'apacheconf' => 'Apache Configuration', 'apl' => 'APL', 'applescript' => 'AppleScript', 'asciidoc' => 'AsciiDoc', 'aspnet' => 'ASP.NET', 'autohotkey' => 'AutoHotkey', 'autoit' => 'AutoIt', 'bash' => 'Bash', 'basic' => 'BASIC', 'batch' => 'Batch', 'bison' => 'Bison', 'brainfuck' => 'Brainfuck', 'bro' => 'Bro', 'c' => 'C', 'clike' => 'C-Like', 'coffeescript' => 'CoffeeScript', 'core' => 'Core', 'cpp' => 'C++', 'crystal' => 'Crystal', 'csharp' => 'C#', 'css-extras' => 'CSS Extras', 'css' => 'CSS', 'd' => 'D', 'dart' => 'Dart', 'diff' => 'Diff', 'docker' => 'Docker', 'eiffel' => 'Eiffel', 'elixir' => 'Elixir', 'erlang' => 'Erlang', 'fortran' => 'Fortran', 'fsharp' => 'F#', 'gherkin' => 'Gherkin', 'git' => 'Git', 'glsl' => 'GLSL', 'go' => 'Go', 'graphql' => 'GraphQl', 'groovy' => 'Groovy', 'haml' => 'Haml', 'handlebars' => 'Handlebars', 'haskell' => 'Haskell', 'haxe' => 'Haxe', 'http' => 'HTTP', 'icon' => 'Icon', 'inform7' => 'Inform 7', 'ini' => 'Ini', 'j' => 'J', 'jade' => 'Jade', 'java' => 'Java', 'javascript' => 'JavaScript', 'json' => 'JSON', 'jsx' => 'JSX (React JSX)', 'julia' => 'Julia', 'keyman' => 'Keyman', 'kotlin' => 'Kotlin', 'latex' => 'LaTeX', 'less' => 'Less', 'livescript' => 'LiveScript', 'lolcode' => 'LOLCODE', 'lua' => 'Lua', 'makefile' => 'Makefile', 'markdown' => 'Markdown', 'markup' => 'Markup/HTML/XML', 'matlab' => 'MATLAB', 'mel' => 'MEL', 'mizar' => 'Mizar', 'monkey' => 'Monkey', 'nasm' => 'NASM', 'nginx' => 'nginx', 'nim' => 'Nim', 'nix' => 'Nix', 'nsis' => 'NSIS', 'objectivec' => 'Objective-C', 'ocaml' => 'OCaml', 'oz' => 'Oz', 'parigp' => 'PARI/GP', 'parser' => 'Parser', 'pascal' => 'Pascal', 'perl' => 'Perl', 'php-extras' => 'PHP Extras', 'php' => 'PHP', 'powershell' => 'PowerShell', 'processing' => 'Processing', 'prolog' => 'Prolog', 'properties' => 'Properties', 'protobuf' => 'Protocol Buffer', 'puppet' => 'Puppet', 'pure' => 'Pure', 'python' => 'Python', 'q' => 'Q', 'qore' => 'Qore', 'r' => 'R', 'rest' => 'ReST (reStructuredText)', 'rip' => 'Rip', 'roboconf' => 'Roboconf', 'ruby' => 'Ruby', 'rust' => 'Rust', 'sas' => 'SAS', 'sass' => 'Sass', 'scala' => 'Scala', 'scheme' => 'Scheme', 'scss' => 'Scss', 'smalltalk' => 'Smalltalk', 'smarty' => 'Smarty', 'sql' => 'SQL', 'stylus' => 'Stylus', 'swift' => 'Swift', 'tcl' => 'Tcl', 'textile' => 'Textile', 'twig' => 'Twig', 'typescript' => 'TypeScript', 'verilog' => 'Verilog', 'vhdl' => 'VHDL', 'vim' => 'Vim', 'wiki' => 'Wiki Markup', 'xojo' => 'Xojo (REAL Basic)', 'yaml' => 'YAML' ), 'themes' => array( 'default' => 'Default', 'coy' => 'Coy', 'dark' => 'Dark', 'funky' => 'Funky', 'okaidia' => 'Okaidia', 'solarizedlight' => 'Solarizedlight', 'tomorrow' => 'Tomorrow', 'twilight' => 'Twilight' ) ); private $data_options = array ( 'lang-used' => array ( 'core', 'clike', 'php', 'markup', 'css', 'javascript', 'sass', 'sql' ), 'default-lang' => 'php', 'max-height' => '480', 'add-css' => 0, 'add-css-value' => '', 'theme' => 'default', 'gutter' => 1, 'start-number' => 1, 'auto-links' => 1, 'show-lang' => 0, 'show-hidden-char' => 0, 'class' => '', 'token' => '1470914799' ); private $options; private $options_phdata; public function __construct() { $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( 'admin_notices', array( $this, 'adminNotices' ), 1 ); } 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->default_param); add_action('wp_head', array($this, 'build_files')); } } 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); } } /** * 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' ) ); } public function admin_setting_page() { ?>

Options

APH Prism Highlighter

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

Used when "Show line numbers" 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 '
'; foreach ($lang_used as $lang) { $lang_name = $this->options_phdata['lang-list'][$lang]; $file_name = 'prism-'.$lang.'.min.js'; $msg = ''; 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 = in_array($lang_key, $lang_used) ? ' checked="checked"' : ''; $id = $lang == 'core' ? 'aphph-langused-disabled' : 'aphph-langused-'.$lang; $class = $lang == 'core' ? ' aphph-langused-disabled' : ''; $link = $lang == 'core' ? '' : ''; echo '
'.$lang_name. $link .'
' . $msg; } echo '
Add Language Remove All
'; $lang_list = $this->options_phdata['lang-list']; unset($lang_list['core']); echo '
'; foreach ($lang_list as $lang_key => $lang_name) { $file_name = 'prism-'.$lang_key.'.min.js'; $msg = ''; 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 = in_array($lang_key, $lang_used) ? ' checked="checked"' : ''; echo ' ' . $msg; } echo '
'; } 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 ''; } public function option_theme_list() { $theme_list = $this->options_phdata['themes']; $options = ''; echo $options; } public function option_plugin_options() { $options = $this->options['options']; ?>

data_options; } else { foreach ($this->options as $key => $val) { if (!key_exists($key, $inputs)) { $inputs[$key] = 0; } } } return $inputs; } public function build_files() { $options = get_option(APHPH_OPTION); $token = $options['token']; // Build prism with selected lang $path = APHPH_PLUGIN_PATH . APHPH_DS . 'includes' . APHPH_DS . 'prism' . APHPH_DS; // $scripts = file_get_contents($path . 'prism.js') . ';'; $scripts = ''; foreach ($options['lang-used'] as $lang) { $scripts .= file_get_contents($path . 'components' . APHPH_DS . 'prism-'.$lang.'.min.js') . ';'; } /** * Add Plugins... */ $plugin_path = $path . 'plugins' . APHPH_DS; $plugin_used = array(); // line-numbers if (@$options['gutter']) { $scripts .= file_get_contents($plugin_path . 'line-numbers' . APHPH_DS .'prism-line-numbers.min.js') . ';'; $plugin_used[] = 'line-numbers'; } // show-invisibles if (@$options['show-hidden-char']) { $scripts .= file_get_contents($plugin_path . 'show-invisibles' . APHPH_DS .'prism-show-invisibles.min.js') . ';'; $plugin_used[] = 'show-invisibles'; } //show-language if (@$options['show-lang']) { $scripts .= file_get_contents($plugin_path . 'show-language' . APHPH_DS .'prism-show-language.min.js') . ';'; $plugin_used[] = 'show-language'; } // autolinker if (@$options['auto-links']) { $scripts .= file_get_contents($plugin_path . 'autolinker' . APHPH_DS .'prism-autolinker.min.js') . ';'; $plugin_used[] = 'autolinker'; } /* Default plugin */ // file-highlight $scripts .= file_get_contents($plugin_path . 'file-highlight' . APHPH_DS .'prism-file-highlight.min.js') . ';'; $plugin_used[] = 'file-highlight'; // line-highlight $scripts .= file_get_contents($plugin_path . 'line-highlight' . APHPH_DS .'prism-line-highlight.min.js') . ';'; $plugin_used[] = 'line-highlight'; /** Script */ /* Cleanup the directory */ $result_path = APHPH_PLUGIN_PATH . APHPH_DS . 'js' . APHPH_DS . 'prism'; $files = scandir($result_path); foreach ($files as $file) { if ($file == '.' || $file == '..') continue; unlink ($result_path . APHPH_DS . $file); } // We build with time() to make sure the client browser use our lastest build file_put_contents($result_path . APHPH_DS . 'aphph-prism-' . $token . '.js', $scripts); /** Theme */ // Cleanup theme directory $theme_path = APHPH_PLUGIN_PATH . APHPH_DS . 'css' . APHPH_DS . 'prism'; $files = scandir($theme_path); foreach ($files as $file) { if ($file == '.' || $file == '..') continue; unlink ($theme_path . APHPH_DS . $file); } // Get theme css $theme_name = $options['theme'] == 'default' ? '' : '-'.$options['theme']; $prism_css = file_get_contents($path . 'themes' . APHPH_DS . 'prism' . $theme_name. '.css'); // Get plugins css foreach ($plugin_used as $plugin) { $css_file = $path . 'plugins' . APHPH_DS . $plugin . APHPH_DS . 'prism-' . $plugin . '.css'; if (file_exists($css_file)) { $prism_css .= "\r\n" . file_get_contents($css_file); } } // ADDITIONAL CSS if ($options['max-height']){ $prism_css .= "\r\n" . 'pre.aphph-container { max-height: '.$options['max-height'] .'px; }'; } if ($options['add-css']) { $prism_css .= "\r\n" . $options['add-css-value']; } file_put_contents($theme_path . APHPH_DS . 'aphph-prism-' . $token . '.css', $prism_css); } } ?>