Changeset 2719681
- Timestamp:
- 05/06/2022 10:31:51 PM (4 years ago)
- Location:
- igsyntax-hiliter/trunk
- Files:
-
- 1 deleted
- 16 edited
-
README.md (modified) (6 diffs)
-
classes/admin.php (modified) (6 diffs)
-
classes/ajax-response.php (modified) (4 diffs)
-
classes/base.php (modified) (7 diffs)
-
classes/cache.php (modified) (11 diffs)
-
classes/frontend.php (modified) (22 diffs)
-
classes/geshi.php (modified) (3 diffs)
-
classes/helper.php (modified) (9 diffs)
-
classes/ig-syntax-hiliter-gatekeeper.php (modified) (8 diffs)
-
classes/migrate.php (modified) (11 diffs)
-
classes/option.php (modified) (4 diffs)
-
classes/singleton.php (deleted)
-
classes/validate.php (modified) (7 diffs)
-
ig-syntax-hiliter.php (modified) (3 diffs)
-
readme.txt (modified) (5 diffs)
-
templates/frontend-code-box.php (modified) (2 diffs)
-
templates/plugin-options-page.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
igsyntax-hiliter/trunk/README.md
r1213537 r2719681 1 ## **iG:Syntax Hiliter v5. 0**1 ## **iG:Syntax Hiliter v5.1** 2 2 --------------------------------- 3 3 … … 5 5 6 6 ##### **Minimum Requirements** 7 - WordPress 4.1or above8 - PHP 5.3or above7 - WordPress 5.4 or above 8 - PHP 7.4.0 or above 9 9 10 10 **WordPress.org:** [https://wordpress.org/plugins/igsyntax-hiliter/](https://wordpress.org/plugins/igsyntax-hiliter/) 11 11 12 **iG:Syntax Hiliter** allows you to post source code to your site with syntax highlighting and formatting (as seen in code editors, IDEs). You can paste the code as is from your code editor or IDE and this plugin will take care of all the code colouring and preserve your formatting. It uses the [GeSHi library](http://qbnz.com/highlighter/) to colouri ze your code and supports over a 100 programming languages. Most common languages are included with the plugin and it includes drop in support for more languages used by GeSHi.12 **iG:Syntax Hiliter** allows you to post source code to your site with syntax highlighting and formatting (as seen in code editors, IDEs). You can paste the code as is from your code editor or IDE and this plugin will take care of all the code colouring and preserve your formatting. It uses the [GeSHi library](http://qbnz.com/highlighter/) to colourise your code and supports over a 100 programming languages. Most common languages are included with the plugin and it includes drop in support for more languages used by GeSHi. 13 13 14 **NOTE :** For fast results and less load on your server, you should have a cache plugin installed. That way the plugin won't have to parse the code blocks on a post every time it s loaded in browser.14 **NOTE :** For fast results and less load on your server, you should have a cache plugin installed. That way the plugin won't have to parse the code blocks on a post every time it is loaded in browser. 15 15 16 ### **[Changelog](CHANGELOG.md)** 16 17 17 18 ### **Installation** 18 19 19 20 #### **Upgrading from v4.0 or later** 20 Just click `update now` link below the plugin listing on the plugins page in your `wp-admin`. Th at's quiteeasy!!21 Just click `update now` link below the plugin listing on the plugins page in your `wp-admin`. The plugin will handle any settings migration if needed. Easy peasy!! 21 22 22 23 #### **Upgrading from v3.x** 23 Just deactivate plugin in WordPress admin, delete the `syntax_hilite.php` file & `ig_syntax_hilite` directory from plugins folder and follow the installation process below. That's quite easy!! 24 Deactivate plugin in WordPress admin, delete the `syntax_hilite.php` file & `ig_syntax_hilite` directory from plugins folder and follow the installation process below. 24 25 25 26 #### **Upgrading from v2.1 or lower** 26 Just deactivate plugin in WordPress admin, delete the `syntax_hilite.php` and `geshi.php` files & `geshi` directory from plugins folder and follow the installation process below. That's quite easy!! 27 Deactivate plugin in WordPress admin, delete the `syntax_hilite.php` and `geshi.php` files & `geshi` directory from plugins folder and follow the installation process below. 27 28 28 29 #### **Installing The Plugin** 29 30 1. Login to your WordPress `wp-admin` area. 30 31 2. Click `Add New` in the `Plugins` menu on left. 31 3. Enter `iG:Syntax Hiliter` in the search bar on the right o nthe page that opens and press Enter key.32 3. Enter `iG:Syntax Hiliter` in the search bar on the right of the page that opens and press Enter key. 32 33 4. WordPress would show the **iG:Syntax Hiliter** plugin with install button, click that to install the plugin. 33 34 5. Click on `Activate Plugin` link on the page that opens after the plugin has been installed successfully. 34 35 35 **See Also:** [" Installing Plugins" article on the WP Codex](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins)36 **See Also:** ["Finding and Installing Plugins" article on the WordPress Support](https://wordpress.org/support/article/managing-plugins/#finding-and-installing-plugins) 36 37 37 38 … … 66 67 HTML entities need not be escaped, you can post your code as is and the plugin takes care of it all. 67 68 68 **Important :** Do not forget to close the tags, as your code will not be hi lited if you don't close your tags. Also, *don't nest tags*. Nesting of tags don't work, so don't try it, it'll ruin your output.69 **Important :** Do not forget to close the tags, as your code will not be highlighted if you don't close your tags. Also, *don't nest tags*. Nesting of tags don't work, so don't try it, it'll ruin your output. 69 70 70 Also a WYSIWYG editor (like the one bundled with WordPress) will probably mess up your code when you paste it in the editor. So if you are having that issue, then please don't report it as a bug. WYSIWYG editors are just not supported at present. 71 **Important :** A WYSIWYG editor (like the one bundled with WordPress) will likely mess up your code when you paste it in the editor. If you are having that issue, then please don't report it as a bug. WYSIWYG editors are just not supported at present. 72 73 ***Similarly, Gutenberg Editor is not supported at present either.*** 71 74 72 75 #### **(Optional) Plugin Attributes** … … 107 110 Configuring **iG:Syntax Hiliter** is a piece of cake. Login to your WordPress admin section & under the `Settings` menu you'll see `iG:Syntax Hiliter` in the sub-menu. 108 111 109 When you click the `iG:Syntax Hiliter` configuration page, you are offered 10configuration settings which you can set to your liking. Lets go through each of them.112 When you click the `iG:Syntax Hiliter` configuration page, you are offered some configuration settings which you can set to your liking. Lets go through each of them. 110 113 111 **Use plugin CSS for styling? :** This option allows you to tell the plugin whether it should use its own CSS for styling the code box (not the hi lited code, just code box) or not. If you want to use your own styling for the code box, tool-bar etc then you can set it to `NO`. By default its set to `YES`.114 **Use plugin CSS for styling? :** This option allows you to tell the plugin whether it should use its own CSS for styling the code box (not the highlighted code, just code box) or not. If you want to use your own styling for the code box, tool-bar etc then you can set it to `NO`. By default its set to `YES`. 112 115 113 **GeSHi Strict Mode? :** This option allows you to tell the plugin the [strict mode](http://qbnz.com/highlighter/geshi-doc.html#using-strict-mode) setting to use with GeSHi. Strict mode can be set to be always on or off or you can set it to `MAYBE` to have GeSHi decide on its own using the language file of the language whose code you're hi liting. *If you don't have any clue about this then leave it at default setting.* By default its set to `MAYBE`. This option can be overridden for any code block using `strict_mode` attribute in the tag.116 **GeSHi Strict Mode? :** This option allows you to tell the plugin the [strict mode](http://qbnz.com/highlighter/geshi-doc.html#using-strict-mode) setting to use with GeSHi. Strict mode can be set to be always on or off or you can set it to `MAYBE` to have GeSHi decide on its own using the language file of the language whose code you're highlighting. *If you don't have any clue about this then leave it at default setting.* By default its set to `MAYBE`. This option can be overridden for any code block using `strict_mode` attribute in the tag. 114 117 115 118 **Languages where GeSHi strict mode is disabled :** This option lets you specify a comma separated list of languages where the GeSHi strict mode should always be disabled. Strict mode is disabled for PHP by default. … … 121 124 **Show line numbers in code? :** This option allows you to tell the plugin whether to show the line numbers along with code in the code boxes or not. Line numbers along with code look great, are a great help when referring to some code from a code box. This option can be overridden for any code block using `gutter` attribute in the tag. 122 125 123 **Hilite code in comments? :** This option allows you to tell the plugin whether to hi lite code posted in comments or not. If this is enabled, code posted in the comments will be hilited as it is in the posts.126 **Hilite code in comments? :** This option allows you to tell the plugin whether to highlight code posted in comments or not. If this is enabled, code posted in the comments will be highlighted as it is in the posts. 124 127 125 128 **Link keywords/function names to Manual? :** This option allows you to tell the plugin whether to link keywords, function names etc to that language's online manual or not. This works only if this feature is enabled for that particular language in GeSHi language file. … … 143 146 144 147 **A:** Please feel free to suggest a new feature. Its inclusion might be speedier if you can provide the code to make it work. 145 146 147 ### **Changelog**148 149 ##### **v5.0**150 151 * Minimum required PHP version bumped to 5.3.0. The plugin simply won't load its code on lower versions.152 * Major re-write of plugin for cleaner, modular & better performing code.153 * Assets are enqueued only if needed.154 * NEW: You can now disable plugin stylesheet which styles code boxes. People who have their own styling don't need it anyway.155 * NEW: 2 new options allow more control on GeSHi behaviour.156 * BUGFIX: Language name cache was not re-building automatically.157 158 ##### **v4.3**159 160 * BUGFIX: some language file names got snipped when building language name cache161 162 ##### **v4.2**163 164 * BUGFIX: Shorthand tags for all languages supported now - props to Karol Kuczmarski for spotting it165 * NEW: Added C++ language file166 167 ##### **v4.1**168 169 * BUGFIX: Github Gist URL XSS security hole170 * BUGFIX: `__dir__` doesn't work below PHP 5.3 - props to Karol Kuczmarski for spotting it171 * NEW: Added "lang" as shorthand for "language" attribute172 * NEW: Additional GeSHi language files can be put in "geshi" directory in theme, which will prevent their deletion on plugin upgrade173 * IMPROVED: If a code block is repeated with same attributes then its parsed only once and output is reused174 175 ##### **v4.0**176 177 * NEW: Ability to embed Github Gist in post and comments (configurable)178 * NEW: Ability to highlight one or multiple lines in a code block to show them as different179 * NEW: New code box layout180 * NEW: Ability to escape plugin tags to prevent their processing181 * NEW: New GeSHi core (v 1.0.8.11)182 * IMPROVED: Removed quirks from plain text view & its now much more smoother183 * IMPROVED: Handling of how code is prevented from beautification. The rest of the post/comment text is not affected as wptexturize is not removed anymore.184 * IMPROVED: Simpler and faster options page in wp-admin185 186 ##### **v3.5**187 188 * BUGFIX: BB Tags except the ones of iG:Syntax Hiliter are allowed. The language file's existence is checked before parsing the code. If the language file does not exist then the code is not parsed.189 * BUGFIX: 'C' code hiliting is now fixed.190 * BUGFIX: 'Plain Text' has been improved to strip the extra blank lines and spaces in Opera and FireFox.191 * The latest stable GeSHi core(v1.0.7.6).192 * NEW: Code Hiliting for Comments has been implemented. This feature can be Enabled/Disabled from the admin interface for iG:Syntax Hiliter. The tags are same for hiliting the code.193 * NEW: A cross-browser Colour Picker(tested in IE6, FireFox1.5 and Opera8.5) is now available to easily set the line colours displayed in the code box.194 * NEW: A new type of view implemented for seeing "Plain Text" code. Besides opening the plain text code in a new window, you can have it displayed in the code box itself with an option to display the hilited HTML code back again. The "Plain Text" view type can be set in the admin interface.195 * The language file for Ruby that I created a while back is now bundled with the plugin and its also a part of the default GeSHi package.196 197 ##### **v3.1**198 199 * BUGFIX: Critical bug, which broke the plugin when the square brackets([ & ]) were used in the posts in places other than tags, has been fixed.200 * BUGFIX: Another bug, which allowed any attribute in the tags besides the 'num' and also allowed any attribute value for it, affecting the processing. Now only the 'num' attribute is accepted and if you specify the 'num' attribute then its value must be a positive number otherwise your code won't be hilited. The 'num' attribute is optional and you can leave it out without any problems.201 * BUGFIX: Fixed the unclosed <select> tags in the Plugin GUI code.202 * GeSHi BUGFIX: Fixed a bug in GeSHi where the first line colour was not used when using FANCY LINE NUMBERS thus resulting in just one colour being used for the alternate lines.203 * There's a problem in WordPress due to which the starting delimiters of ASP, PHP were not displayed correctly, as whitespace was inserted between the '<' and the rest of the delimiter. This has been patched so that its displayed correctly, but its not saved in the database, so the database still contains the delimiters as formatted by WordPress.204 205 ##### **v3.0**206 207 * Complete re-write of the plugin resulting in reduction of code from 750+ lines to about 400 Lines.208 * New GeSHi Core(v1.0.7) which has some bug-fixes, please see GeSHi Website for its changelog.209 * New languages added are C#, Delphi, Smarty & VB.NET.210 * ASP language file structure updated & more keywords added.211 * Drag-n-Drop usage of new languages. The plugin now supports all languages that GeSHi(v1.0.7) supports. You just need to drop the language file in the "geshi" directory & use the filename as the tag for the language(like if file is "pascal.php", then the filename is "pascal" & the tags will be [pascal] & [/pascal]).212 * Language name which is displayed in the Code-Box can now be turned ON or OFF easily.213 * No more need to set the physical-path to the "geshi" directory if you are doing a default installation.214 * Plain-Text View of the code hilited in the code-box is now possible. This feature can be enabled/disabled easily in the Configuration Interface in WordPress Administration.215 * NO NEED TO EDIT THE PLUGIN FILE ANYMORE. You can now configure the plugin settings from a GUI located under the OPTIONS menu in your WordPress Administration(WordPress 1.5 & above only).216 217 ##### **v2.01**218 219 * BUGFIX: Fixed a bug by removing a <br /> tag from the function pFix() which lead to closing of an unnecessary <p> tag making the code not xHTML valid(as per my desires).220 221 ##### **v2.0 Final**222 223 * Implemented the new version of GeSHi core, v1.0.2 which has some bug fixes & which uses OL(Ordered Lists) for Line Numbering and supports starting of a Line Number from any given number.224 * The ASP(Active Server Pages) language file has been updated to the new Language File structure of GeSHi as well as more keywords added & hiliting is more effective now.225 * iG:Syntax Hiliter now also supports ActionScript, C, C++, JavaScript, Perl, Python, Visual Basic & XML.226 * The whole plugin has been re-written & all the hiliting code is now in a class. You can just use the class anywhere else too for hiliting the code. But to also use the Code Tags to wrap your code & then hilite them, you will need to use all other functions. You can remove the WordPress Filter calls at the end of the plugin & use the rest of the code as you want somewhere else.227 * BUGFIX: The issue of multi-line comments not being hilited properly in v2.0 Preview has been sorted out.228 229 ##### **v2.0 Preview**230 231 * Implemented the new version of GeSHi core, v1.0.1 which has some bug fixes including the extra quote(") bug that broke the xHTML validation of the code.232 * I've created a new language file for ASP(Active Server Pages) which has been added to this release & will also be a part of the next GeSHi release.233 * Line numbering is now done through Ordered Lists(<OL>) & the code is xHTML compliant.234 * Auto-Formatting disabled for posts that contain the iG:Syntax Hiliter code tags so that your code is good for copy-paste operations.235 236 ##### **v1.1**237 238 * Implemented the line numbering of code.239 * The code box is now of fixed dimensions without word-wrap & with scrollbars(if required).240 241 ##### **v1.0**242 243 * Hilites code between the special tags, all of them differently.244 * Uses GeSHi for syntax hiliting.245 * Supports HTML, CSS, PHP, JAVA & SQL codes. -
igsyntax-hiliter/trunk/classes/admin.php
r1213540 r2719681 12 12 13 13 /** 14 * protected constructor, singleton pattern implemented14 * Class constructor 15 15 */ 16 16 protected function __construct() { 17 17 18 parent::__construct(); 18 19 19 20 $this->_setup_hooks(); 20 } 21 22 protected function _setup_hooks() { 23 //call function to add options menu item 24 add_action( 'admin_menu', array( $this, 'add_menu' ) ); 25 26 //setup our style/script enqueuing for wp-admin 27 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_stuff' ) ); 28 29 //setup callback for AJAX on admin page 30 add_action( 'wp_ajax_ig-sh-save-options', array( $this, 'save_plugin_options' ) ); 31 32 //callback to show any migration messages 33 add_action( 'admin_notices', array( $this, 'show_migration_message' ) ); 21 22 } 23 24 /** 25 * Method to set up listeners to WP hooks 26 * 27 * @return void 28 */ 29 protected function _setup_hooks() : void { 30 31 /* 32 * Actions 33 */ 34 add_action( 'admin_menu', [ $this, 'add_menu' ] ); 35 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_stuff' ] ); 36 add_action( 'wp_ajax_ig-sh-save-options', [ $this, 'save_plugin_options' ] ); 37 add_action( 'admin_notices', [ $this, 'maybe_show_migration_message' ] ); 38 39 /* 40 * Filters 41 */ 42 add_filter( 'plugin_action_links', [ $this, 'get_action_links' ], 10, 2 ); 43 34 44 } 35 45 … … 39 49 * admin page and then deletes the older version number from DB. 40 50 */ 41 public function show_migration_message() { 51 public function maybe_show_migration_message() : void { 52 42 53 if ( get_current_screen()->id !== sprintf( 'settings_page_%s-page', parent::PLUGIN_ID ) ) { 43 54 //not our admin page, bail out 44 return false;55 return; 45 56 } 46 57 47 58 $old_version = round( floatval( get_option( parent::PLUGIN_ID . '-migrated-from', 0 ) ), 1 ); 48 59 49 if ( $old_version > 0 ) { 50 51 if ( $old_version < floatval( IG_SYNTAX_HILITER_VERSION ) ) { 52 53 printf( '<div class="updated fade"><p>Options migrated successfully from v%f</p></div>', $old_version ); 54 60 if ( 0 < $old_version ) { 61 62 if ( floatval( IG_SYNTAX_HILITER_VERSION ) > $old_version ) { 63 printf( 64 '<div class="updated fade"><p>Options migrated successfully from v%f</p></div>', 65 $old_version 66 ); 55 67 } 56 68 … … 60 72 } 61 73 62 unset( $old_version ); 63 } 64 65 /** 66 * This function adds plugin's admin page in the Settings menu 67 */ 68 public function add_menu() { 69 add_options_page( parent::PLUGIN_NAME . ' Options', parent::PLUGIN_NAME, 'manage_options', parent::PLUGIN_ID . '-page', array( $this, 'admin_page' ) ); 70 } 71 72 /** 73 * This function constructs the UI for the plugin admin page 74 */ 75 public function admin_page() { 76 77 echo Helper::render_template( IG_SYNTAX_HILITER_ROOT . '/templates/plugin-options-page.php', array( 78 'plugin_name' => parent::PLUGIN_NAME, 79 'options' => $this->_option->get_all(), 80 'strict_mode_opts' => Validate::$strict_mode_values, 81 'human_time_diff' => Helper::human_time_diff( time(), ( $this->_get_language_cache_build_time() + parent::LANGUAGES_CACHE_LIFE ) ), 82 ) ); 83 84 } 85 86 /** 87 * This function is called by WP to handle our AJAX requests 88 */ 89 public function save_plugin_options() { 74 } 75 76 /** 77 * Method to add plugin settings page in the Settings menu 78 * 79 * @return void 80 */ 81 public function add_menu() : void { 82 add_options_page( 83 sprintf( '%s Options', parent::PLUGIN_NAME ), 84 parent::PLUGIN_NAME, 85 'manage_options', 86 sprintf( '%s-page', parent::PLUGIN_ID ), 87 [ $this, 'admin_page' ] 88 ); 89 } 90 91 /** 92 * Method to construct the UI for the plugin settings page 93 * 94 * @return void 95 */ 96 public function admin_page() : void { 97 98 Helper::render_template( 99 sprintf( '%s/templates/plugin-options-page.php', untrailingslashit( IG_SYNTAX_HILITER_ROOT ) ), 100 [ 101 'plugin_name' => parent::PLUGIN_NAME, 102 'options' => $this->_option->get_all(), 103 'strict_mode_opts' => Validate::$strict_mode_values, 104 'human_time_diff' => Helper::human_time_diff( time(), ( $this->_get_language_cache_build_time() + parent::LANGUAGES_CACHE_LIFE ) ), 105 ], 106 true 107 ); 108 109 } 110 111 /** 112 * Method to handle our AJAX requests 113 * 114 * @return void 115 */ 116 public function save_plugin_options() : void { 90 117 91 118 if ( ! is_admin() || ! current_user_can( 'manage_options' ) ) { 92 return false;119 return; 93 120 } 94 121 95 122 $response = new Ajax_Response(); 96 123 97 $response->add_nonce( parent::PLUGIN_ID . '-nonce');124 $response->add_nonce( sprintf( '%s-nonce', parent::PLUGIN_ID ) ); 98 125 99 126 //check & see if we have the values 127 $option_name = Helper::filter_input( INPUT_POST, 'option_name', FILTER_SANITIZE_STRING ); 128 $option_value = Helper::filter_input( INPUT_POST, 'option_value', FILTER_SANITIZE_STRING ); 129 100 130 if ( 101 131 ! check_ajax_referer( parent::PLUGIN_ID . '-nonce', '_ig_sh_nonce', false ) 102 || ! isset( $_POST['option_name'] ) || ! isset( $_POST['option_value'])132 || empty( $option_name ) || empty( $option_value ) 103 133 ) { 104 134 $response->add_error( 'Invalid request sent, please refresh the page and try again' ); … … 106 136 } 107 137 108 $input = array( 109 'option_name' => sanitize_text_field( strtolower( trim( $_POST['option_name'] ) ) ), 110 'option_value' => sanitize_text_field( strtolower( trim( $_POST['option_value'] ) ) ), 111 ); 112 113 if ( $input['option_name'] == 'igsh_refresh_languages' && $input['option_value'] == 'rebuild' ) { 138 $option_name = sanitize_text_field( strtolower( trim( $option_name ) ) ); 139 $option_value = sanitize_text_field( strtolower( trim( $option_value ) ) ); 140 141 if ( 'igsh_refresh_languages' === $option_name && 'rebuild' === $option_value ) { 114 142 115 143 //rebuild language file list … … 119 147 $response->add( 'time', Helper::human_time_diff( time(), ( $this->_get_language_cache_build_time() + parent::LANGUAGES_CACHE_LIFE ) ) ); 120 148 121 } elseif ( $this->_option->get( $input['option_name'] ) !== false ) { 122 123 $response->add_success( 'Option Saved successfully' ); //assume option saved successfully 124 125 switch ( $input['option_name'] ) { 149 } elseif ( $this->_option->get( $option_name ) !== false ) { 150 151 $response->add_success( 'Option Saved successfully' ); //assume option saved successfully 152 153 switch ( $option_name ) { 154 126 155 case 'strict_mode': 127 $this->_option->save( $input['option_name'], $this->_validate->sanitize_strict_mode_values( $input['option_value'] ) ); 156 $this->_option->save( 157 $option_name, 158 $this->_validate->sanitize_strict_mode_values( $option_value ) 159 ); 128 160 break; 161 129 162 case 'non_strict_mode': 130 $sanitized_language_names = $this->_validate->languages( explode( ',', $input['option_value'] ), array_values( $this->get_languages() ) ); 131 $this->_option->save( $input['option_name'], $sanitized_language_names ); 163 $sanitized_language_names = $this->_validate->languages( 164 explode( ',', $option_value ), 165 array_values( $this->get_languages() ) 166 ); 167 168 $this->_option->save( $option_name, $sanitized_language_names ); 132 169 133 170 unset( $sanitized_language_names ); 134 171 break; 172 135 173 default: 136 if ( ! $this->_validate->is_yesno( $ input['option_value']) ) {174 if ( ! $this->_validate->is_yesno( $option_value ) ) { 137 175 $response->add_error( 'Invalid request sent, please refresh the page and try again' ); 138 176 $response->send(); 139 177 } else { 140 $this->_option->save( $ input['option_name'], $input['option_value']);178 $this->_option->save( $option_name, $option_value ); 141 179 } 180 142 181 break; 182 143 183 } 144 184 … … 147 187 $response->send(); 148 188 149 } //end save_plugin_options() 150 151 /** 152 * function to enqueue stuff in wp-admin head 153 */ 154 public function enqueue_stuff( $hook ) { 189 } //end save_plugin_options() 190 191 /** 192 * Method to load assets on settings page in wp-admin 193 * 194 * @return void 195 */ 196 public function enqueue_stuff( $hook ) : void { 155 197 156 198 if ( ! is_admin() || $hook !== sprintf( 'settings_page_%s-page', parent::PLUGIN_ID ) ) { 157 199 //page is not in wp-admin or not our settings page, so bail out 158 return false;200 return; 159 201 } 160 202 161 203 //load stylesheet 162 wp_enqueue_style( parent::PLUGIN_ID . '-admin', plugins_url( 'assets/css/admin.css', __DIR__ ), false, IG_SYNTAX_HILITER_VERSION ); 204 wp_enqueue_style( 205 sprintf( '%s-admin', parent::PLUGIN_ID ), 206 plugins_url( '/assets/css/admin.css', __DIR__ ), 207 false, 208 IG_SYNTAX_HILITER_VERSION 209 ); 210 163 211 //load jQuery::msg stylesheet 164 wp_enqueue_style( parent::PLUGIN_ID . '-jquery-msg', plugins_url( 'assets/css/jquery.msg.css', __DIR__ ), false, IG_SYNTAX_HILITER_VERSION ); 212 wp_enqueue_style( 213 sprintf( '%s-jquery-msg', parent::PLUGIN_ID ), 214 plugins_url( '/assets/css/jquery.msg.css', __DIR__ ), 215 false, 216 IG_SYNTAX_HILITER_VERSION 217 ); 165 218 166 219 //load jQuery::center script 167 wp_enqueue_script( parent::PLUGIN_ID . '-jquery-center', plugins_url( 'assets/js/jquery.center.min.js', __DIR__ ), array( 'jquery' ), IG_SYNTAX_HILITER_VERSION ); 220 wp_enqueue_script( 221 sprintf( '%s-jquery-center', parent::PLUGIN_ID ), 222 plugins_url( '/assets/js/jquery.center.min.js', __DIR__ ), 223 [ 'jquery' ], 224 IG_SYNTAX_HILITER_VERSION 225 ); 226 168 227 //load jQuery::msg script 169 wp_enqueue_script( parent::PLUGIN_ID . '-jquery-msg', plugins_url( 'assets/js/jquery.msg.min.js', __DIR__ ), array( parent::PLUGIN_ID . '-jquery-center' ), IG_SYNTAX_HILITER_VERSION ); 228 wp_enqueue_script( 229 sprintf( '%s-jquery-msg', parent::PLUGIN_ID ), 230 plugins_url( '/assets/js/jquery.msg.min.js', __DIR__ ), 231 [ sprintf( '%s-jquery-center', parent::PLUGIN_ID ) ], 232 IG_SYNTAX_HILITER_VERSION 233 ); 234 170 235 //load our script 171 wp_enqueue_script( parent::PLUGIN_ID . '-admin', plugins_url( 'assets/js/admin.js', __DIR__ ), array( parent::PLUGIN_ID . '-jquery-msg' ), IG_SYNTAX_HILITER_VERSION ); 236 wp_enqueue_script( 237 sprintf( '%s-admin', parent::PLUGIN_ID ), 238 plugins_url( '/assets/js/admin.js', __DIR__ ), 239 [ sprintf( '%s-jquery-msg', parent::PLUGIN_ID ) ], 240 IG_SYNTAX_HILITER_VERSION 241 ); 172 242 173 243 //some vars in JS that we'll need 174 wp_localize_script( parent::PLUGIN_ID . '-admin', 'ig_sh', array( 175 'plugins_url' => untrailingslashit( plugins_url( '', __DIR__ ) ) . '/', 176 'nonce' => wp_create_nonce( parent::PLUGIN_ID . '-nonce' ), 177 ) ); 178 179 } 180 181 } //end of class 182 244 wp_localize_script( 245 sprintf( '%s-admin', parent::PLUGIN_ID ), 246 'ig_sh', 247 [ 248 'plugins_url' => plugins_url( '/', __DIR__ ), 249 'nonce' => wp_create_nonce( sprintf( '%s-nonce', parent::PLUGIN_ID ) ), 250 ] 251 ); 252 253 } 254 255 /** 256 * Method to add link to plugin settings page in the plugin listing once plugin has been activated. 257 * 258 * @param array $links 259 * @param string $file 260 * 261 * @return array 262 */ 263 public function get_action_links( array $links, string $file ) : array { 264 265 if ( IG_SYNTAX_HILITER_BASENAME !== $file ) { 266 return $links; 267 } 268 269 $settings_page_slug = sprintf( 270 'options-general.php?page=%s-page', 271 parent::PLUGIN_ID 272 ); 273 274 $settings_link = sprintf( 275 '<a href="%s" aria-label="Configure %s">Settings</a>', 276 esc_url( admin_url( $settings_page_slug ) ), 277 esc_attr( parent::PLUGIN_NAME ) 278 ); 279 280 array_unshift( $links, $settings_link ); 281 282 return $links; 283 284 } 285 286 } //end of class 183 287 184 288 //EOF -
igsyntax-hiliter/trunk/classes/ajax-response.php
r1213527 r2719681 3 3 * Class for creating and sending an AJAX response 4 4 * 5 * @author Amit Gupta <http ://amitgupta.in/>5 * @author Amit Gupta <https://amitgupta.in/> 6 6 * 7 7 * @since 2015-07-22 … … 20 20 * @var array Array of data to be sent to browser 21 21 */ 22 protected $_response = array(22 protected $_response = [ 23 23 'nonce' => '', 24 'error' => 1, //lets assume there's error24 'error' => 1, //lets assume there's error 25 25 'msg' => '', 26 );26 ]; 27 27 28 28 /** 29 * constructor29 * Class constructor 30 30 */ 31 31 public function __construct() {} 32 32 33 33 /** 34 * Functionto add data to be sent to browser34 * Method to add data to be sent to browser 35 35 * 36 * @param string $key Key name to identify data 37 * @param string $value Data value 36 * @param string $key Key name to identify data 37 * @param mixed $value Data value 38 * 38 39 * @return void 39 40 */ 40 public function add( $key, $value ){41 public function add( string $key, $value ) : void { 41 42 $this->_response[ sanitize_key( $key ) ] = $value; 42 43 } 43 44 44 45 /** 45 * Function tononce to be sent to browser46 * Method to generate nonce to be sent to browser 46 47 * 47 48 * @param string $key Key to generate nonce 49 * 48 50 * @return void 49 51 */ 50 public function add_nonce( $key ) { 51 if ( empty( $key ) || ! is_string( $key ) ) { 52 public function add_nonce( string $key ) : void { 53 54 if ( empty( $key ) ) { 52 55 return; 53 56 } 54 57 55 58 $this->add( 'nonce', wp_create_nonce( $key ) ); 59 56 60 } 57 61 58 62 /** 59 * Functionto add a message to be sent to browser63 * Method to add a message to be sent to browser 60 64 * 61 65 * @param string $message 62 * @param string $type Type of message, either SUCCESS or ERROR 63 * @return boolean Returns TRUE if message added successfully else FALSE 66 * @param string $type Type of message, either SUCCESS or ERROR 67 * 68 * @return bool Returns TRUE if message added successfully else FALSE 64 69 */ 65 public function add_message( $message, $type = 'success' ) { 66 if ( empty( $message ) || ! is_string( $message ) ) { 70 public function add_message( string $message, string $type = 'success' ) : bool { 71 72 if ( empty( $message ) ) { 67 73 return false; 68 74 } 69 75 70 $type = ( strtolower( trim( $type ) ) === 'success' ) ? 'success' : 'error'; //type can only be either one76 $type = ( strtolower( trim( $type ) ) === 'success' ) ? 'success' : 'error'; //type can only be either one 71 77 72 $this->add( 'msg', sprintf( self::MESSAGE_TEMPLATE, esc_attr( $type ), esc_html( $message ) ) ); 78 $this->add( 79 'msg', 80 sprintf( 81 self::MESSAGE_TEMPLATE, 82 esc_attr( $type ), 83 esc_html( $message ) ) 84 ); 73 85 74 86 return true; 87 75 88 } 76 89 77 90 /** 78 * Functionto add error message to be sent to browser91 * Method to add error message to be sent to browser 79 92 * 80 93 * @param string $message 94 * 81 95 * @return void 82 96 */ 83 public function add_error( $message ){97 public function add_error( string $message ) : void { 84 98 if ( $this->add_message( $message, 'error' ) ) { 85 99 $this->add( 'error', 1 ); … … 88 102 89 103 /** 90 * Functionto add success message to be sent to browser104 * Method to add success message to be sent to browser 91 105 * 92 106 * @param string $message 107 * 93 108 * @return void 94 109 */ 95 public function add_success( $message ){110 public function add_success( string $message ) : void { 96 111 if ( $this->add_message( $message, 'success' ) ) { 97 112 $this->add( 'error', 0 ); … … 100 115 101 116 /** 102 * Functionto send data to browser117 * Method to send data to browser 103 118 * 104 119 * @return void 105 120 */ 106 public function send() { 121 public function send() : void { 122 107 123 header( "Content-Type: application/json" ); 108 124 109 echo json_encode( $this->_response );//we want json125 echo wp_json_encode( $this->_response ); //we want json 110 126 111 wp_die( '', '', 200 ); //send 200 HTTP Status back 127 wp_die( '', '', 200 ); //send 200 HTTP Status back 128 112 129 } 113 130 114 } //end of class 115 131 } //end of class 116 132 117 133 //EOF -
igsyntax-hiliter/trunk/classes/base.php
r1213527 r2719681 5 5 * inherited, on its own it doesn't do anything 6 6 * 7 * @author Amit Gupta <http ://amitgupta.in/>7 * @author Amit Gupta <https://amitgupta.in/> 8 8 */ 9 9 10 10 namespace iG\Syntax_Hiliter; 11 11 12 abstract class Base extends Singleton { 12 use \iG\Syntax_Hiliter\Traits\Singleton; 13 14 abstract class Base { 15 16 use Singleton; 13 17 14 18 /** 15 19 * @var const Class constant containing unique plugin ID 16 20 */ 17 const PLUGIN_ID = "ig-syntax-hiliter"; 21 const PLUGIN_ID = 'ig-syntax-hiliter'; 22 18 23 /** 19 24 * @var const Class constant containing plugin name for display 20 25 */ 21 const PLUGIN_NAME = "iG:Syntax Hiliter"; 26 const PLUGIN_NAME = 'iG:Syntax Hiliter'; 27 22 28 /** 23 29 * @var const Class constant containing life of language name cache in seconds 24 30 */ 25 const LANGUAGES_CACHE_LIFE = WEEK_IN_SECONDS; //1 week 26 /** 27 * @var String Static var containing path to GeSHi language file folder 28 */ 29 protected static $__dirs; 30 31 /** 32 * @var iG\Syntax_Hiliter\Option 31 const LANGUAGES_CACHE_LIFE = WEEK_IN_SECONDS; // 1 week 32 33 /** 34 * @var array Array containing paths to GeSHi language file folders 35 */ 36 protected $__dirs; 37 38 /** 39 * @var \iG\Syntax_Hiliter\Option 33 40 */ 34 41 protected $_option; 35 /** 36 * @var iG\Syntax_Hiliter\Validate 42 43 /** 44 * @var \iG\Syntax_Hiliter\Validate 37 45 */ 38 46 protected $_validate; … … 42 50 */ 43 51 protected function __construct() { 52 44 53 $this->_setup_dir_paths(); 45 54 … … 60 69 */ 61 70 $this->get_languages(); 62 } 63 64 /** 65 * This function scans the validated language file directories, retrieves the 66 * names of all files with .php extension and returns an array with unique 67 * file names 68 */ 69 public function build_language_list() { 70 if ( empty( self::$__dirs ) ) { 71 return false; 72 } 73 74 $tags = array(); 75 76 foreach ( self::$__dirs as $dir ) { 77 $tags = array_merge( $tags, glob( $dir . "/*.php" ) ); 78 } 79 80 $tags = array_unique( array_filter( array_map( array( $this, '_file_to_tag_name' ), $tags ) ) ); 71 72 } 73 74 /** 75 * This method scans the validated language file directories, retrieves the 76 * names of all language files and returns an array with unique file names. 77 * 78 * @return array 79 */ 80 public function get_uncached_languages() : array { 81 82 $tags = []; 83 84 if ( empty( $this->__dirs ) ) { 85 return $tags; 86 } 87 88 foreach ( $this->__dirs as $dir ) { 89 $pattern = sprintf( 90 '%s/*.php', 91 untrailingslashit( $dir ) 92 ); 93 94 $tags = array_merge( $tags, glob( $pattern ) ); 95 } 96 97 $tags = array_unique( 98 array_filter( 99 array_map( [ $this, '_file_to_tag_name' ], $tags ) 100 ) 101 ); 81 102 82 103 sort( $tags ); 83 104 84 $this->_set_language_cache_build_time(); //set language list built time105 $this->_set_language_cache_build_time(); //set language list built time 85 106 86 107 return $tags; 87 } 88 89 /** 90 * This function uses WP TLC class to fetch the language file names from supported directories 91 * and schedules a refresh of the transient cache. It also allows a force rebuild of 92 * transient cache via the optional $force_rebuild parameter. 93 */ 94 public function get_languages( $force_rebuild = 'no' ) { 108 109 } 110 111 /** 112 * Method to get cached array of language file names from supported directories. 113 * 114 * @param string $force_rebuild Optional parameter to force rebuild the cache 115 * 116 * @return array 117 * 118 * @throws \ErrorException 119 */ 120 public function get_languages( string $force_rebuild = 'no' ) : array { 121 95 122 $force_rebuild = ( ! $this->_validate->is_yesno( $force_rebuild ) ) ? 'no' : strtolower( $force_rebuild ); 96 123 97 $cache = new Cache( self::PLUGIN_ID . '-languages' );98 99 if ( $force_rebuild == 'yes') {100 $cache->delete(); //delete existing cache so we'll get fresh one below101 } 102 103 $languages = $cache->updates_with( array( $this, 'build_language_list' ))124 $cache = Cache::create( self::PLUGIN_ID . '-languages' ); 125 126 if ( 'yes' === $force_rebuild ) { 127 $cache->delete(); //delete existing cache so we'll get fresh one below 128 } 129 130 $languages = $cache->updates_with( [ $this, 'get_uncached_languages' ] ) 104 131 ->expires_in( self::LANGUAGES_CACHE_LIFE ) 105 132 ->get(); 106 133 107 134 if ( empty( $languages ) ) { 108 return ;135 return []; 109 136 } 110 137 111 138 return array_combine( $languages, $languages ); 139 112 140 } 113 141 … … 115 143 * Returns the timestamp when language file name cache was last built. If no timestamp 116 144 * found then it sets current timestamp and returns that. 117 */ 118 protected function _get_language_cache_build_time() { 145 * 146 * @return int 147 */ 148 protected function _get_language_cache_build_time() : int { 149 119 150 $time = get_option( self::PLUGIN_ID . '-lang-time' ); 120 151 121 if ( $time === false ) {152 if ( false === $time ) { 122 153 return $this->_set_language_cache_build_time(); 123 154 } 124 155 125 156 return $time; 157 126 158 } 127 159 128 160 /** 129 161 * Sets the timestamp to mark when language file name cache was built 130 */ 131 protected function _set_language_cache_build_time() { 162 * 163 * @return int 164 */ 165 protected function _set_language_cache_build_time() : int { 166 132 167 $time = time(); 133 168 … … 135 170 136 171 return $time; 172 137 173 } 138 174 139 175 /** 140 176 * Returns the file name of a php file from the physical file path 141 * /142 protected function _file_to_tag_name( $file_path ) {143 144 $file_path = str_replace( '\\', '/', $file_path );145 146 if ( empty( $file_path ) || strpos( $file_path, '.php' ) === false ) {147 148 $file_path = '';149 177 * 178 * @return string 179 */ 180 protected function _file_to_tag_name( string $path ) : string { 181 182 $path = str_replace( '\\', '/', $path ); 183 184 if ( empty( $path ) || substr( $path, -4 ) !== '.php' ) { 185 $path = ''; 150 186 } else { 151 187 152 $ file_path = explode( '/', $file_path );153 $ file_path = explode( '.', array_pop( $file_path ) );154 155 array_pop( $ file_path );156 157 $ file_path = implode( '.', $file_path );158 159 } 160 161 return $ file_path;188 $path = explode( '/', $path ); 189 $path = explode( '.', array_pop( $path ) ); 190 191 array_pop( $path ); 192 193 $path = implode( '.', $path ); 194 195 } 196 197 return $path; 162 198 163 199 } … … 169 205 * @return void 170 206 */ 171 protected function _maybe_migrate_older_settings() {207 protected function _maybe_migrate_older_settings() : void { 172 208 Migrate::get_instance()->settings( $this ); 173 209 } … … 178 214 * and child theme directories, and whichever exists is stored. 179 215 */ 180 protected function _setup_dir_paths() { 181 182 self::$__dirs['geshi'] = dirname( __DIR__ ) . "/geshi"; //setup geshi dir path 183 self::$__dirs['theme'] = get_template_directory() . "/geshi"; //setup geshi dir path in current theme folder 184 self::$__dirs['child_theme'] = get_stylesheet_directory() . "/geshi"; //setup geshi dir path in child theme folder 185 186 if ( ! is_dir( self::$__dirs['child_theme'] ) || self::$__dirs['theme'] == self::$__dirs['child_theme'] ) { 187 188 unset( self::$__dirs['child_theme'] ); //no geshi dir in child theme 189 190 } 191 192 if ( ! is_dir( self::$__dirs['theme'] ) ) { 193 194 unset( self::$__dirs['theme'] ); //no geshi dir in current theme 195 196 } 197 198 } 199 200 } //end of class 201 216 protected function _setup_dir_paths() : void { 217 218 //setup geshi dir path 219 $this->__dirs['geshi'] = sprintf( 220 '%s/geshi', 221 untrailingslashit( IG_SYNTAX_HILITER_ROOT ) 222 ); 223 224 $theme_path = sprintf( 225 '%s/geshi', 226 untrailingslashit( get_template_directory() ) 227 ); 228 229 $child_theme_path =sprintf( 230 '%s/geshi', 231 untrailingslashit( get_stylesheet_directory() ) 232 ); 233 234 //setup geshi dir path in current theme folder 235 if ( is_dir( $theme_path ) ) { 236 $this->__dirs['theme'] = $theme_path; 237 } 238 239 //setup geshi dir path in child theme folder 240 if ( $theme_path !== $child_theme_path && is_dir( $child_theme_path ) ) { 241 $this->__dirs['child_theme'] = $child_theme_path; 242 } 243 244 unset( $child_theme_path, $theme_path ); 245 246 } 247 248 } //end of class 202 249 203 250 //EOF -
igsyntax-hiliter/trunk/classes/cache.php
r1213527 r2719681 8 8 namespace iG\Syntax_Hiliter; 9 9 10 use \Exception; 10 11 use \ErrorException; 11 12 … … 14 15 const KEY_PREFIX = 'igsh-cache-'; 15 16 17 const MIN_EXPIRY = 120; // 2 minutes 18 16 19 protected $_key; 17 protected $_expiry = 1800; //30 minutes, default expiry 20 21 protected $_expiry = 1800; // 30 minutes, default expiry 22 18 23 protected $_callback; 19 protected $_params = array(); 24 25 protected $_params = []; 20 26 21 27 protected $_cache; 22 28 23 protected $_default_storage_format = array( 24 'expiry' => 0, 25 'callback' => '', 26 'params' => array(), 27 'data' => '', 28 ); 29 30 /** 31 * @param String $cache_key A mixed character string for use as unique identifier for current dataset stored in cache 32 */ 33 public function __construct( $cache_key ) { 34 35 if ( empty( $cache_key ) || ! is_string( $cache_key ) ) { 36 37 throw new ErrorException( 'Cache key is required to create ' . __CLASS__ . ' object' ); 29 protected $_default_storage_format = [ 30 'expiry' => 0, 31 'data' => '', 32 ]; 33 34 /** 35 * Class constructor 36 * 37 * @param string $cache_key A string for use as unique identifier for current dataset stored in cache 38 * 39 * @throws \ErrorException 40 */ 41 public function __construct( string $cache_key ) { 42 43 if ( empty( $cache_key ) ) { 44 45 throw new ErrorException( 46 sprintf( 47 'Cache key is required to create %s object', 48 __CLASS__ 49 ) 50 ); 38 51 39 52 } … … 46 59 * Factory method to facilitate single call data fetch using method chaining 47 60 * 48 * @param String $cache_key A mixed character string for use as unique identifier for current dataset stored in cache 49 * @return iG\Syntax_Hiliter\Cache 50 */ 51 public static function create( $cache_key ) { 52 $class = __CLASS__; 53 54 return new $class( $cache_key ); 61 * @param string $cache_key A string for use as unique identifier for current dataset stored in cache 62 * 63 * @return \iG\Syntax_Hiliter\Cache 64 * 65 * @throws \ErrorException 66 */ 67 public static function create( string $cache_key ) : self { 68 return new self( $cache_key ); 55 69 } 56 70 … … 58 72 * This function is for deleting the cache 59 73 * 60 * @return iG\Syntax_Hiliter\Cache61 */ 62 public function delete() {74 * @return \iG\Syntax_Hiliter\Cache 75 */ 76 public function delete() : self { 63 77 delete_option( $this->_key ); 64 78 … … 69 83 * This function accepts the cache expiry 70 84 * 71 * @return iG\Syntax_Hiliter\Cache 72 */ 73 public function expires_in( $expiry ) { 74 $expiry = intval( $expiry ); 75 76 if ( $expiry > 0 ) { 77 $this->_expiry = $expiry; 78 } 79 80 unset( $expiry ); 85 * @return \iG\Syntax_Hiliter\Cache 86 */ 87 public function expires_in( int $expiry ) : self { 88 89 if ( 0 < $expiry ) { 90 $this->_expiry = max( $expiry, self::MIN_EXPIRY ); 91 } 81 92 82 93 return $this; 94 83 95 } 84 96 … … 86 98 * This function accepts the callback from which data is to be received 87 99 * 88 * @return iG\Syntax_Hiliter\Cache 89 */ 90 public function updates_with( $callback, array $params = array() ) { 91 92 if ( empty( $callback ) || ! is_callable( $callback ) ) { 93 100 * @param callable $callback 101 * @param array $params 102 * 103 * @return \iG\Syntax_Hiliter\Cache 104 * 105 * @throws \ErrorException 106 */ 107 public function updates_with( callable $callback, array $params = [] ) : self { 108 109 if ( empty( $callback ) ) { 94 110 throw new ErrorException( 'Callback passed is not callable' ); 95 96 111 } 97 112 98 113 $this->_callback = $callback; 99 $this->_params = $params;114 $this->_params = $params; 100 115 101 116 return $this; … … 125 140 } 126 141 127 protected function _get_cache() { 128 129 if ( is_bool( $this->_cache ) || ( is_array( $this->_cache ) && ! empty( $this->_cache ) ) ) { 142 /** 143 * Method to grab the cache array from storage 144 * 145 * @return array 146 */ 147 protected function _get_cache() : array { 148 149 if ( is_array( $this->_cache ) && ! empty( $this->_cache ) ) { 130 150 return $this->_cache; 131 151 } … … 137 157 } 138 158 139 return false; 140 141 } 142 143 protected function _set_cache() { 159 return []; 160 161 } 162 163 /** 164 * Method to save cache array in storage 165 * 166 * @return void 167 */ 168 protected function _set_cache() : void { 169 170 if ( ! is_array( $this->_cache ) || empty( $this->_cache ) ) { 171 return; 172 } 173 144 174 //delete existing cache 145 175 $this->delete(); … … 148 178 //we want it autoloaded hence the use of update_option() 149 179 update_option( $this->_key, $this->_cache ); 150 } 151 152 protected function _has_expired() { 180 181 } 182 183 /** 184 * Method to check if cache has expired or not 185 * 186 * @return bool 187 */ 188 protected function _has_expired() : bool { 189 153 190 $cache = $this->_get_cache(); 154 191 155 if ( is_array( $cache ) && ! empty( $cache ) ) { 156 157 if ( ! empty( $cache['expiry'] ) && time() < intval( $cache['expiry'] ) ) { 158 //cache has not expired, yet 159 return false; 160 } 161 192 if ( isset( $cache['expiry'] ) && time() < intval( $cache['expiry'] ) ) { 193 //cache has not expired, yet 194 return false; 162 195 } 163 196 164 197 //cache has expired 165 198 return true; 166 } 167 168 protected function _refresh_cache() { 169 $cache = array( 170 'expiry' => ( time() + $this->_expiry ), 171 'callback' => $this->_callback, 172 'params' => $this->_params, 173 'data' => '', 174 ); 199 200 } 201 202 /** 203 * Method which refreshes cached data 204 * 205 * @return void 206 * 207 * @throws \ErrorException 208 */ 209 protected function _refresh_cache() : void { 210 211 $cache = [ 212 'expiry' => ( time() + $this->_expiry ), 213 'data' => '', 214 ]; 175 215 176 216 /* … … 185 225 try { 186 226 $cache['data'] = call_user_func_array( $this->_callback, $this->_params ); 187 } catch( \Exception $e ) {188 $cache['data'] = false;227 } catch( Exception $e ) { 228 $cache['data'] = ''; 189 229 } 190 230 … … 193 233 $this->_set_cache(); 194 234 195 unset( $cache ); 196 } 197 198 } //end of class 199 235 } 236 237 } //end of class 200 238 201 239 //EOF -
igsyntax-hiliter/trunk/classes/frontend.php
r1213527 r2719681 4 4 * for the plugin, hilite code etc. 5 5 * 6 * @author Amit Gupta <http ://amitgupta.in/>6 * @author Amit Gupta <https://amitgupta.in/> 7 7 */ 8 8 … … 14 14 15 15 /** 16 * @var Constant Class constant contains the template for generating tokens for hilited code16 * @var const Class constant contains the template for generating tokens for hilited code 17 17 */ 18 18 const TOKEN = '<pre class="igsh-token" id="%s"></pre>'; 19 /** 20 * @var Constant Class constant contains the max length allowed for a file's path 19 20 /** 21 * @var const Class constant contains the max length allowed for a file's path 21 22 */ 22 23 const FILE_PATH_LENGTH = 30; … … 25 26 * @var array Contains hilited code blocks associated to unique tokens 26 27 */ 27 protected $__hilited_code = array();28 protected $__hilited_code = []; 28 29 29 30 /** 30 31 * @var array Contains IDs/labels etc for use in code boxes 31 32 */ 32 protected $__code_box = array(33 protected $__code_box = [ 33 34 'counter' => 0, 34 35 'id_prefix' => 'ig-sh-', 35 36 'plain' => 'plain text', 36 37 'html' => 'hilited code', 37 ); 38 39 /** 40 * @var Array Contains filters on which code hiliting is not allowed & code blocks are to be stripped 41 */ 42 protected $__no_code_hilite_filters = array( 43 'excerpt_save_pre', 'get_the_excerpt', 'the_excerpt', 'the_excerpt_rss' 44 ); 45 46 /** 47 * @var Array Contains filters on which code hiliting is allowed 48 */ 49 protected $__code_hilite_filters = array( 50 'the_content' 51 ); 52 53 /** 54 * @var Array Contains filters on which Github Gist is not allowed & code blocks are to be stripped 55 */ 56 protected $__no_github_gist_filters = array( 57 'excerpt_save_pre', 'get_the_excerpt', 'the_excerpt', 'the_excerpt_rss' 58 ); 59 60 /** 61 * @var Array Contains filters on which Github Gist is allowed 62 */ 63 protected $__github_gist_filters = array( 64 'the_content' 65 ); 66 67 /** 68 * @var Array Contains file names for GeSHi language files associated with expected tag names 69 */ 70 protected $__geshi_language = array( 38 ]; 39 40 /** 41 * @var array Contains filters on which code hiliting is not allowed & code blocks are to be stripped 42 */ 43 protected $__no_code_hilite_filters = [ 44 'excerpt_save_pre', 45 'get_the_excerpt', 46 'the_excerpt', 47 'the_excerpt_rss', 48 ]; 49 50 /** 51 * @var array Contains filters on which code hiliting is allowed 52 */ 53 protected $__code_hilite_filters = [ 54 'the_content', 55 ]; 56 57 /** 58 * @var array Contains filters on which Github Gist is not allowed & code blocks are to be stripped 59 */ 60 protected $__no_github_gist_filters = [ 61 'excerpt_save_pre', 62 'get_the_excerpt', 63 'the_excerpt', 64 'the_excerpt_rss', 65 ]; 66 67 /** 68 * @var array Contains filters on which Github Gist is allowed 69 */ 70 protected $__github_gist_filters = [ 71 'the_content', 72 ]; 73 74 /** 75 * @var array Contains file names for GeSHi language files associated with expected tag names 76 */ 77 protected $__languages = [ 71 78 'as' => 'actionscript', 72 79 'html' => 'html4strict', 73 80 'js' => 'javascript', 74 );75 76 /** 77 * @var Array Contains display names for some languages, like C# for csharp, VB.NET for vbnet78 */ 79 protected $__ geshi_language_display = array(81 ]; 82 83 /** 84 * @var array Contains display names for some languages, like C# for csharp, VB.NET for vbnet 85 */ 86 protected $__language_display_names = [ 80 87 'cpp' => 'C++', 81 88 'cfm' => 'Cold Fusion', … … 86 93 'html' => 'HTML', 87 94 'html4strict' => 'HTML4', 88 );89 90 /** 91 * @var bool eanFlag to determine whether CSS & JS assets are to be enqueued or not95 ]; 96 97 /** 98 * @var bool Flag to determine whether CSS & JS assets are to be enqueued or not 92 99 */ 93 100 protected $__enqueue_assets = false; 94 101 95 102 /** 96 * @var bool eanFlag to determine whether JS assets are to be enqueued or not103 * @var bool Flag to determine whether JS assets are to be enqueued or not 97 104 */ 98 105 protected $__enqueue_js_assets = false; 99 106 100 107 /** 101 * protected constructor, singleton pattern implemented108 * Class constructor 102 109 */ 103 110 protected function __construct() { 111 104 112 parent::__construct(); 105 113 106 114 $this->_build_tags_array(); 115 $this->_determine_filters(); 116 107 117 $this->_setup_hooks(); 118 108 119 } 109 120 110 protected function _setup_hooks() { 111 112 //setup our style/script enqueuing for front-end 113 add_action( 'wp_footer', array( $this, 'enqueue_stuff' ), 1 ); 121 /** 122 * Method to separate out filters on which hiliting of code is to be set up or not 123 * 124 * @return void 125 */ 126 protected function _determine_filters() : void { 114 127 115 128 //setup code hilite handling for comments 116 if ( $this->_option->get( 'hilite_comments' ) == 'yes' ) {129 if ( $this->_option->get( 'hilite_comments' ) === 'yes' ) { 117 130 //gotta hilite 118 131 $this->__code_hilite_filters[] = 'comment_text'; … … 123 136 124 137 //setup Github Gist embed in comments 125 if ( $this->_option->get( 'gist_in_comments' ) == 'yes' ) {138 if ( $this->_option->get( 'gist_in_comments' ) === 'yes' ) { 126 139 //gotta embed 127 140 $this->__github_gist_filters[] = 'comment_text'; … … 131 144 } 132 145 146 } 147 148 /** 149 * Method to set up listeners to WP hooks 150 * 151 * @return void 152 */ 153 protected function _setup_hooks() : void { 154 155 // set on 'wp_footer' hook because we won't know whether to enqueue assets 156 // or not before post content is parsed 157 add_action( 'wp_footer', [ $this, 'enqueue_stuff' ], 1 ); 158 133 159 //queue up calls for code hiliting 134 160 foreach ( $this->__code_hilite_filters as $filter ) { 161 135 162 //to grab code blocks to be hilited & replace them with tokens 136 add_filter( $filter, array( $this, 'parse_shortcodes' ), 2 ); 163 add_filter( $filter, [ $this, 'parse_shortcodes' ], 3 ); 164 137 165 //replace code block tokens with hilited code 138 add_filter( $filter, array( $this, 'add_hilited_code_blocks' ), 100 ); 166 add_filter( $filter, [ $this, 'replace_tokens_with_code_blocks' ], 99 ); 167 139 168 } 140 169 141 170 //queue up calls for stripping out code blocks 142 171 foreach ( $this->__no_code_hilite_filters as $filter ) { 143 add_filter( $filter, array( $this, 'parse_shortcodes' ), 2 );172 add_filter( $filter, [ $this, 'parse_shortcodes' ], 2 ); 144 173 } 145 174 146 175 //queue up calls for Github Gist embed 147 176 foreach ( $this->__github_gist_filters as $filter ) { 148 add_filter( $filter, array( $this, 'parse_github_gist_tags' ), 9);177 add_filter( $filter, [ $this, 'parse_github_shortcodes' ], 10 ); 149 178 } 150 179 151 180 //queue up calls for stripping out Github Gist code blocks 152 181 foreach ( $this->__no_github_gist_filters as $filter ) { 153 add_filter( $filter, array( $this, 'parse_github_gist_tags' ), 9 ); 154 } 155 156 } //end _setup_hooks() 157 158 /** 159 * function to enqueue stuff in front-end head 160 */ 161 public function enqueue_stuff() { 182 add_filter( $filter, [ $this, 'parse_github_shortcodes' ], 9 ); 183 } 184 185 } //end _setup_hooks() 186 187 /** 188 * Method to enqueue assets on front-end 189 * 190 * @return void 191 */ 192 public function enqueue_stuff() : void { 162 193 163 194 if ( is_admin() || ! $this->__enqueue_assets ) { 164 //page is in wp-admin, so bail out 165 return false; 166 } 167 168 if ( $this->_option->get( 'fe-styles' ) == 'yes' ) { 195 // page is in wp-admin or it has no code blocks to hilite 196 // bail out 197 return; 198 } 199 200 if ( $this->_option->get( 'fe-styles' ) === 'yes' ) { 169 201 //load stylesheet 170 wp_enqueue_style( parent::PLUGIN_ID, plugins_url( 'assets/css/front-end.css', __DIR__ ), false, IG_SYNTAX_HILITER_VERSION ); 171 } 172 173 if ( $this->__enqueue_js_assets === true ) { 202 wp_enqueue_style( 203 parent::PLUGIN_ID, 204 Helper::get_asset_url( '/css/front-end.css' ), 205 false, 206 IG_SYNTAX_HILITER_VERSION 207 ); 208 } 209 210 if ( true === $this->__enqueue_js_assets ) { 174 211 175 212 //load utility lib 176 wp_enqueue_script( 'igeek-utils', plugins_url( 'assets/js/igeek-utils.js', __DIR__ ), array(), IG_SYNTAX_HILITER_VERSION ); 213 wp_enqueue_script( 214 'igeek-utils', 215 Helper::get_asset_url( '/js/igeek-utils.js' ), 216 [], 217 IG_SYNTAX_HILITER_VERSION 218 ); 219 177 220 //load script 178 wp_enqueue_script( parent::PLUGIN_ID, plugins_url( 'assets/js/front-end.js', __DIR__ ), array( 'igeek-utils', 'jquery' ), IG_SYNTAX_HILITER_VERSION ); 221 wp_enqueue_script( 222 parent::PLUGIN_ID, 223 Helper::get_asset_url( '/js/front-end.js' ), 224 [ 'igeek-utils', 'jquery' ], 225 IG_SYNTAX_HILITER_VERSION 226 ); 179 227 180 228 //vars for front-end js 181 wp_localize_script( parent::PLUGIN_ID, 'ig_syntax_hiliter', array( 182 'label' => array( 183 'plain' => $this->__code_box['plain'], 184 'html' => $this->__code_box['html'] 185 ) 186 ) ); 229 wp_localize_script( 230 parent::PLUGIN_ID, 231 'ig_syntax_hiliter', 232 [ 233 'label' => [ 234 'plain' => $this->__code_box['plain'], 235 'html' => $this->__code_box['html'], 236 ], 237 ] 238 ); 187 239 188 240 } … … 191 243 192 244 /** 193 * This function buildsthe array for shorthand tags for all language files245 * Method to build the array for shorthand tags for all language files 194 246 * available in supported directories 195 */ 196 protected function _build_tags_array() { 247 * 248 * @return void 249 * 250 * @throws \ErrorException 251 */ 252 protected function _build_tags_array() : void { 253 197 254 $languages = $this->get_languages(); 198 255 … … 201 258 } 202 259 203 $keys = array_unique( array_merge( array_keys( $this->__geshi_language ), array_keys( $languages ) ) ); 204 205 $tags = array(); 260 $keys = array_unique( 261 array_merge( 262 array_keys( $this->__languages ), 263 array_keys( $languages ) 264 ) 265 ); 266 267 $tags = []; 206 268 207 269 foreach( $keys as $key ) { 208 if ( array_key_exists( $key, $this->__geshi_language ) ) { 209 $tags[$key] = $this->__geshi_language[$key]; 270 271 if ( array_key_exists( $key, $this->__languages ) ) { 272 $tags[ $key ] = $this->__languages[ $key ]; 210 273 continue; 211 274 } 212 275 213 276 if ( array_key_exists( $key, $languages ) ) { 214 $tags[ $key] = $languages[$key];277 $tags[ $key ] = $languages[ $key ]; 215 278 continue; 216 279 } 280 217 281 } 218 282 219 283 ksort( $tags ); 220 284 221 $this->__geshi_language = $tags; 222 223 unset( $tags, $keys, $languages ); 285 $this->__languages = $tags; 286 224 287 } 225 288 226 289 /** 227 * This function is used to truncate file path to required length 228 * 229 * @param string $path Path to file 230 * @param int $length Length in number of characters 290 * Method to truncate file path to required length 291 * 292 * @param string $path Path to file 293 * @param int $length Length in number of characters 294 * 231 295 * @return string Truncated file path 232 296 */ 233 protected function _snip_file_path( $path, $length ){234 235 $length = intval( $length );236 $length = ( $length < 0 || $length > self::FILE_PATH_LENGTH ) ? self::FILE_PATH_LENGTH : $length;297 protected function _snip_file_path( string $path, int $length ) : string { 298 299 $length = abs( $length ); 300 $length = min( self::FILE_PATH_LENGTH, $length ); 237 301 238 302 if ( strlen( $path ) <= $length ) { … … 240 304 } 241 305 242 $path = "…" . substr( $path, intval( 2 - $length ) ); 306 $path = sprintf( 307 '…%s', 308 substr( $path, ( 2 - $length ) ) 309 ); 243 310 244 311 return $path; … … 247 314 248 315 /** 249 * This function is used to put hilited code in a presentable box 250 */ 251 protected function _get_code_in_box( $code, $attrs ) { 316 * Method to put hilited code in a presentable box 317 * 318 * @param string $code 319 * @param array $attrs 320 * 321 * @return string 322 * 323 * @throws \ErrorException 324 */ 325 protected function _get_code_in_box( string $code, array $attrs = [] ) : string { 326 252 327 if ( empty( $code ) ) { 253 return; 254 } 255 256 $code_box = ''; 328 return ''; 329 } 330 331 $attrs['file'] = ( empty( $attrs['file'] ) ) ? '' : $attrs['file']; 332 257 333 $this->__code_box['counter']++; 258 334 259 return Helper::render_template( IG_SYNTAX_HILITER_ROOT . '/templates/frontend-code-box.php', array( 260 'id_prefix' => $this->__code_box['id_prefix'], 261 'counter' => $this->__code_box['counter'], 262 'plain_text' => $this->__code_box['plain'], 263 'file_path' => $this->_snip_file_path( $attrs['file'], self::FILE_PATH_LENGTH ), 264 'attrs' => $attrs, 265 'code' => $code, 266 ) ); 335 return Helper::render_template( 336 sprintf( '%s/templates/frontend-code-box.php', untrailingslashit( IG_SYNTAX_HILITER_ROOT ) ), 337 [ 338 'id_prefix' => $this->__code_box['id_prefix'], 339 'counter' => $this->__code_box['counter'], 340 'plain_text' => $this->__code_box['plain'], 341 'file_path' => $this->_snip_file_path( $attrs['file'], self::FILE_PATH_LENGTH ), 342 'attrs' => $attrs, 343 'code' => $code, 344 ] 345 ); 346 267 347 } 268 348 269 349 /** 270 * This function is used to hilite code using Geshi 271 */ 272 protected function _get_hilited_code( $attrs = array(), $code = '' ) { 273 274 if ( ( empty( $code ) || ! is_string( $code ) ) ) { 275 return; 276 } 277 278 extract( shortcode_atts( array( 279 'strict_mode' => '', 280 'language' => '', 281 'firstline' => 1, 282 'highlight' => 0, 283 'file' => '', 284 'gutter' => '', 285 'plaintext' => '', 286 'toolbar' => '', 287 'lang' => 'code', 288 'num' => 1, 289 ), $attrs ) ); 290 291 $num = intval( $num ); 292 $firstline = ( intval( $firstline ) < 1 ) ? 1 : intval( $firstline ); 293 $firstline = ( $num > $firstline ) ? $num : $firstline; 294 295 $language = ( empty( $language ) ) ? $lang : $language; 350 * Method to hilite code using Geshi and get the HTML 351 * 352 * @param array $attrs 353 * @param string $code 354 * 355 * @return string 356 * 357 * @throws \ErrorException 358 */ 359 protected function _get_hilited_code( array $attrs = [], string $code = '' ) : string { 360 361 if ( empty( $code ) ) { 362 return ''; 363 } 364 365 extract( 366 shortcode_atts( 367 [ 368 'strict_mode' => '', 369 'language' => 'code', 370 'firstline' => 1, 371 'highlight' => 0, 372 'file' => '', 373 'gutter' => '', 374 'plaintext' => '', 375 'toolbar' => '', 376 'lang' => 'code', 377 'num' => 1, 378 ], 379 $attrs 380 ) 381 ); 382 383 $num = absint( $num ); 384 $firstline = absint( $firstline ); 385 $firstline = max( 1, $num, $firstline ); 386 $language = ( empty( $language ) && ! empty( $lang ) ) ? $lang : $language; 387 296 388 unset( $lang ); 297 389 298 $language = sanitize_title( $language );299 $language_display = ( array_key_exists( $language, $this->__geshi_language_display ) ) ? $this->__geshi_language_display[ $language ] :$language;300 $language = ( array_key_exists( $language, $this->__geshi_language ) ) ? $this->__geshi_language[ $language ] :$language;390 $language = sanitize_title( $language ); 391 $language_display = $this->__language_display_names[ $language ] ?? $language; 392 $language = $this->__languages[ $language ] ?? $language; 301 393 302 394 $non_strict_mode_languages = $this->_option->get( 'non_strict_mode' ); … … 304 396 if ( ! empty( $strict_mode ) ) { 305 397 $strict_mode = strtolower( trim( $strict_mode ) ); 306 } elseif ( in_array( $language, $non_strict_mode_languages ) ) {398 } elseif ( in_array( $language, $non_strict_mode_languages, true ) ) { 307 399 $strict_mode = 'never'; 308 400 } else { … … 325 417 unset( $strict_mode ); 326 418 327 $file = strip_tags( $file ); 328 $gutter = ( ! $this->_validate->is_yesno( $gutter ) ) ? '' : strtolower( trim( $gutter ) ); 329 419 $file = sanitize_text_field( wp_strip_all_tags( $file ) ); 420 $gutter = ( ! $this->_validate->is_yesno( $gutter ) ) ? '' : strtolower( trim( $gutter ) ); 330 421 $plaintext = ( ! $this->_validate->is_yesno( $plaintext ) ) ? '' : strtolower( trim( $plaintext ) ); 331 $toolbar = ( ! $this->_validate->is_yesno( $toolbar ) ) ? '' : strtolower( trim( $toolbar ) );422 $toolbar = ( ! $this->_validate->is_yesno( $toolbar ) ) ? '' : strtolower( trim( $toolbar ) ); 332 423 333 424 $code = trim( $code ); … … 335 426 if ( strpos( $highlight, ',' ) === false && strpos( $highlight, '-' ) === false ) { 336 427 337 $highlight = ( intval( $highlight ) < 0 ) ? 0 : array( intval( $highlight ) );428 $highlight = [ absint( $highlight ) ]; 338 429 339 430 } else { 340 431 341 432 $highlight = explode( ',', $highlight ); 342 343 $ranges = array(); 433 $ranges = []; 344 434 345 435 foreach ( $highlight as $num ) { 346 436 347 437 if ( strpos( $num, '-' ) === false ) { 348 $ranges[] = $num;438 $ranges[] = absint( $num ); 349 439 continue; 350 440 } 351 441 352 $range = explode( '-', $num );353 $range_start = intval( $range[0] );354 $range_end = intval( $range[1] );355 356 if ( $range_end == $range_start ) {442 $range = explode( '-', $num ); 443 $range_start = absint( $range[0] ); 444 $range_end = absint( $range[1] ); 445 446 if ( $range_end === $range_start ) { 357 447 $ranges[] = $range_start; 358 448 continue; 359 449 } elseif ( $range_end < $range_start ) { 360 $range_start = intval( $range[1] );361 $range_end = intval( $range[0] );450 $range_start = absint( $range[1] ); 451 $range_end = absint( $range[0] ); 362 452 } 363 453 364 $range = range( $range_start, $range_end );454 $range = range( $range_start, $range_end ); 365 455 $ranges = array_merge( $ranges, $range ); 366 456 … … 375 465 unset( $ranges ); 376 466 377 $highlight = array_unique( array_map( 'intval', $highlight ) ); //make 'em all int & vaporize duplicates 467 //make 'em all int & vaporize duplicates 468 $highlight = array_unique( array_map( 'intval', $highlight ) ); 469 378 470 sort( $highlight, SORT_NUMERIC ); 379 471 380 472 } 381 473 382 $is_language = true; //assume we have a valid language383 $dir_path = parent::$__dirs['geshi'];//set default path to our geshi dir384 385 if ( function_exists( 'file_exists' )) {386 387 foreach ( parent::$__dirs as $key => $dir ) {388 389 if ( file_exists( $dir . '/' . $language . '.php' ) ) {390 $is_language = true; //language file exists391 $dir_path = $dir; //set language file dir392 break; 393 }394 395 $ is_language = false; //language file doesn't exist396 474 $is_language = true; //assume we have a valid language 475 $dir_path = $this->__dirs['geshi']; //set default path to our geshi dir 476 477 foreach ( $this->__dirs as $key => $dir ) { 478 479 $language_file_path = sprintf( 480 '%s/%s.php', 481 untrailingslashit( $dir ), 482 $language 483 ); 484 485 if ( Helper::is_file_path_valid( $language_file_path ) ) { 486 $is_language = true; //language file exists 487 $dir_path = $dir; //set language file dir 488 break; 397 489 } 398 490 399 } 400 401 if ( $is_language !== true ) { 491 $is_language = false; //language file doesn't exist 492 493 } 494 495 if ( true !== $is_language ) { 402 496 //we don't have a valid language specified in the tag by user 403 497 //set the code block to be hilited using the 'code' lang file 404 $language = 'code';498 $language = 'code'; 405 499 $language_display = $language; 406 500 } 407 501 408 $options = array(502 $options = [ 409 503 'show_line_numbers' => Helper::yesno_to_bool( $this->_option->get( 'show_line_numbers' ) ), 410 504 'show_plain_text' => Helper::yesno_to_bool( $this->_option->get( 'plain_text' ) ), 411 505 'show_toolbar' => Helper::yesno_to_bool( $this->_option->get( 'toolbar' ) ), 412 );506 ]; 413 507 414 508 /* … … 440 534 441 535 if ( ! empty( $geshi_error ) ) { 442 return; //there's GeSHi error, bail from this function 443 } 444 445 $geshi->set_header_type( GESHI_HEADER_NONE ); //don't need any wrapper around hilited code, we've our own 446 $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS ); //show line numbers 447 448 if ( $options['show_line_numbers'] === false ) { 449 $geshi->set_line_style( 'list-style: none;' ); //hide line numbers 450 } 451 452 $geshi->start_line_numbers_at( $firstline ); //where to start line numbering from 453 $geshi->set_case_keywords( GESHI_CAPS_NO_CHANGE ); //don't mess with our code 454 $geshi->set_tab_width( 4 ); //if you don't know this then go stuff your head in sand, coding is not for you! 455 456 $geshi->enable_keyword_links( Helper::yesno_to_bool( $this->_option->get( 'link_to_manual' ) ) ); 457 458 if ( is_array( $highlight ) ) { 459 $geshi->highlight_lines_extra( $highlight ); //show these lines as special 460 $geshi->set_highlight_lines_extra_style( 'background-color:#FFFFBC;' ); //set bg color for special lines 461 } 536 return ''; //there's GeSHi error, bail out 537 } 538 539 $geshi->set_header_type( GESHI_HEADER_NONE ); //don't need any wrapper around hilited code, we have our own 540 $geshi->enable_line_numbers( GESHI_NORMAL_LINE_NUMBERS ); //show line numbers 541 542 if ( false === $options['show_line_numbers'] ) { 543 544 // hide line numbers 545 // doing it this way so that line hiliting still works, otherwise it would not 546 $geshi->set_line_style( 'list-style: none;' ); 547 548 } 549 550 $geshi->start_line_numbers_at( $firstline ); //where to start line numbering from 551 $geshi->set_case_keywords( GESHI_CAPS_NO_CHANGE ); //don't mess with our code 552 $geshi->set_tab_width( 4 ); //if you don't know this then go stuff your head in sand, coding is not for you! 553 554 $geshi->enable_keyword_links( 555 Helper::yesno_to_bool( 556 $this->_option->get( 'link_to_manual' ) 557 ) 558 ); 559 560 $geshi->highlight_lines_extra( $highlight ); //show these lines as special 561 $geshi->set_highlight_lines_extra_style( 'background-color:#FFFFBC;' ); //set bg color for special lines 462 562 463 563 $geshi->enable_strict_mode( $geshi_mode ); 464 564 465 $hilited_code = $geshi->parse_code(); //get it all565 $hilited_code = $geshi->parse_code(); //get it all 466 566 467 567 if ( empty( $hilited_code ) ) { 468 return ;//geshi banged up somewhere, we have nothing to show for all the hardwork above :(568 return ''; //geshi banged up somewhere, we have nothing to show for all the hardwork above :( 469 569 } 470 570 … … 475 575 * to set it to FALSE again. 476 576 */ 477 if ( $options['show_plain_text'] === true) {577 if ( true === $options['show_plain_text'] ) { 478 578 $this->__enqueue_js_assets = $options['show_plain_text']; 479 579 } 480 580 481 return $this->_get_code_in_box( $hilited_code, array( 482 'plain_text' => $options['show_plain_text'], 483 'toolbar' => $options['show_toolbar'], 484 'file' => $file, 485 'language' => $language_display, 486 ) ); 487 488 } //end _get_hilited_code() 489 490 /* 491 * This function is called for parsing a code hiliting tag setup in 492 * $this->parse_shortcodes(). 493 * It hiltes the code, generates a unique token for the code, stores hilited 494 * code in $this->__hilited_code with token as key and returns the token 581 return $this->_get_code_in_box( 582 $hilited_code, 583 [ 584 'plain_text' => $options['show_plain_text'], 585 'toolbar' => $options['show_toolbar'], 586 'file' => $file, 587 'language' => $language_display, 588 ] 589 ); 590 591 } //end _get_hilited_code() 592 593 /** 594 * Method to parse code hiliting tag set up in self::parse_shortcodes(). 595 * It hiltes the code, generates a unique token for the hilited code, stores 596 * hilited code in a class var with token as key and returns the token 495 597 * to replace the tag in content which can later be replaced with 496 598 * the hilited code. 497 */ 498 public function tokenize_code_block( $atts, $code = '', $tag = false ) { 599 * 600 * @param array $atts 601 * @param string $code 602 * @param string $tag 603 * 604 * @return string 605 * 606 * @throws \ErrorException 607 */ 608 public function replace_code_blocks_with_tokens( array $atts, string $code = '', string $tag = '' ) : string { 499 609 500 610 if ( empty( $tag ) || empty( $code ) ) { 501 return $code; //nothing to do, bail out611 return $code; //nothing to do, bail out 502 612 } 503 613 504 614 //check if we've to strip code block 505 if ( in_array( current_filter(), $this->__no_code_hilite_filters ) ) { 506 return ''; //code hiliting not allowed for this filter, so remove code block 507 } 508 509 if ( array_key_exists( $tag, $this->__geshi_language ) ) { 510 $atts['language'] = $tag; //shorthand tag used, so tag name is language 511 } 512 513 ksort( $atts ); //sort attribute array on keys 514 515 $shortcode_md5 = md5( serialize( array( 516 'text' => $code, 517 'atts' => $atts 518 ) ) ); //create unique token key for this code block with these attributes 519 520 if ( ! array_key_exists( $shortcode_md5, $this->__hilited_code ) ) { 521 522 $this->__hilited_code[ $shortcode_md5 ] = $this->_get_hilited_code( $atts, $code ); //save hilited code in array 615 if ( in_array( current_filter(), $this->__no_code_hilite_filters, true ) ) { 616 return ''; //code hiliting not allowed for this filter, so remove code block 617 } 618 619 if ( ! empty( $this->__languages[ $tag ] ) ) { 620 $atts['language'] = $tag; //shorthand tag used, so tag name is language 621 } 622 623 ksort( $atts ); //sort attribute array on keys 624 625 $shortcode_md5 = md5( //create unique token key for this code block with these attributes 626 wp_json_encode( 627 [ 628 'text' => $code, 629 'atts' => $atts, 630 ] 631 ) 632 ); 633 634 if ( empty( $this->__hilited_code[ $shortcode_md5 ] ) ) { 635 636 // save hilited code in array 637 $this->__hilited_code[ $shortcode_md5 ] = $this->_get_hilited_code( $atts, $code ); 523 638 524 639 if ( empty( $this->__hilited_code[ $shortcode_md5 ] ) ) { 525 //banged up somewhere, we didn't get anything, unset key in array & return empty 640 641 // messed up somewhere, we didn't get anything 642 // unset key in array and return empty 526 643 unset( $this->__hilited_code[ $shortcode_md5 ] ); 527 return; 644 645 return ''; 646 528 647 } 529 648 530 649 } 531 650 532 $shortcode_token = sprintf( self::TOKEN, $shortcode_md5 ); //generate token651 $shortcode_token = sprintf( self::TOKEN, $shortcode_md5 ); //generate token HTML 533 652 534 653 unset( $shortcode_md5 ); 535 654 536 $this->__enqueue_assets = true; //yes we should enqueue CSS/JS assets, we have hilited code on page 537 538 return $shortcode_token; //return unique token, we'll replace it with hilited code later 539 } //end tokenize_code_block() 540 541 /** 542 * This function is called back by a filter early on and sets up shortcode 655 $this->__enqueue_assets = true; //yes we should enqueue CSS/JS assets, we have hilited code on page 656 657 // return unique token, we'll replace it with hilited code later 658 return $shortcode_token; 659 660 } //end replace_code_blocks_with_tokens() 661 662 /** 663 * Method called back by a filter early on and sets up shortcode 543 664 * processing for code hiliting tags 544 */ 545 public function parse_shortcodes( $content ) { 665 * 666 * @param string $content 667 * 668 * @return string 669 */ 670 public function parse_shortcodes( string $content= '' ) : string { 546 671 547 672 if ( is_admin() ) { … … 551 676 global $shortcode_tags; 552 677 553 // keep a copy of the registered shortcodes as we'dneed to restore them later678 // keep a copy of the registered shortcodes as we need to restore them later 554 679 $original_shortcode_tags = $shortcode_tags; 555 680 556 remove_all_shortcodes(); //clean the slate, we want only our shortcodes to be processed right now557 558 $tags = array_merge( array_keys( $this->__ geshi_language ), array( 'sourcecode' ));681 remove_all_shortcodes(); //clean the slate, we want only our shortcodes to be processed right now 682 683 $tags = array_merge( array_keys( $this->__languages ), [ 'sourcecode' ] ); 559 684 560 685 foreach ( $tags as $tag ) { 561 add_shortcode( $tag, array( $this, 'tokenize_code_block' ));562 } 563 564 $content = do_shortcode( $content ); //parse our shortcodes565 566 $shortcode_tags = $original_shortcode_tags; //restore original shortcodes686 add_shortcode( $tag, [ $this, 'replace_code_blocks_with_tokens' ] ); 687 } 688 689 $content = do_shortcode( $content ); //parse our shortcodes 690 691 $shortcode_tags = $original_shortcode_tags; //restore original shortcodes 567 692 568 693 unset( $tags, $original_shortcode_tags ); … … 573 698 574 699 /** 575 * This function is called back by a filter in the last and replaces the unique 576 * tokens with corresponding blocks of hilited code stored in $this->__hilited_code 577 */ 578 public function add_hilited_code_blocks( $content ) { 700 * Method, called back by a filter towards the end, to replace code hilite 701 * tokens with corresponding blocks of hilited code 702 * 703 * @param string $content 704 * 705 * @return string 706 */ 707 public function replace_tokens_with_code_blocks( string $content ) : string { 708 579 709 if ( is_admin() || empty( $this->__hilited_code ) ) { 580 710 return $content; … … 582 712 583 713 /* 584 * Run a loop on $this->__hilited_code and replace all tokens in $content585 * with appropriate blocks of hilited code .714 * Loop over our tokens array and replace all tokens 715 * with appropriate blocks of hilited code 586 716 */ 587 717 foreach ( $this->__hilited_code as $key => $code_block ) { 588 718 589 $token = sprintf( self::TOKEN, $key );719 $token = sprintf( self::TOKEN, $key ); 590 720 $content = str_replace( $token, $code_block, $content ); 591 721 … … 593 723 594 724 return $content; 725 595 726 } 596 727 597 728 /** 598 * This function is called on a filter and it sets up [github] shortcode parsing 599 */ 600 public function parse_github_gist_tags( $content ) { 729 * Method, called on a filter, to set up [github] shortcode parsing 730 * 731 * @param string $content 732 * 733 * @return string 734 */ 735 public function parse_github_shortcodes( string $content ) : string { 736 601 737 if ( is_admin() ) { 602 738 return $content; … … 605 741 global $shortcode_tags; 606 742 607 // keep a copy of the registered shortcodes as we'dneed to restore them later743 // keep a copy of the registered shortcodes as we need to restore them later 608 744 $original_shortcode_tags = $shortcode_tags; 609 745 610 remove_all_shortcodes(); //clean the slate, we want only our shortcodes to be processed right now 611 612 //setup shortcode for github gist 613 add_shortcode( 'github', array( $this, 'parse_github_gist_tag' ) ); 614 615 $content = do_shortcode( $content ); //parse our shortcodes 616 617 $shortcode_tags = $original_shortcode_tags; //restore original shortcodes 746 remove_all_shortcodes(); //clean the slate, we want only our shortcodes to be processed right now 747 748 // setup shortcode for github gist 749 add_shortcode( 'github', [ $this, 'get_github_gist_embed' ] ); 750 751 $content = do_shortcode( $content ); //parse our shortcodes 752 $shortcode_tags = $original_shortcode_tags; //restore original shortcodes 618 753 619 754 unset( $original_shortcode_tags ); 620 755 621 756 return $content; 757 622 758 } 623 759 624 760 /** 625 * This function handles the [github] tag 626 */ 627 public function parse_github_gist_tag( $attrs, $content = '' ) { 628 629 extract( shortcode_atts( array( 630 'id' => 0, 631 'gist' => '', 632 ), $attrs ) ); 633 634 $gist = parse_url( esc_url( untrailingslashit( $gist ) ), PHP_URL_PATH ); 761 * Method to return Github Gist embed 762 * 763 * @param array $attrs 764 * @param string $content 765 * 766 * @return string 767 */ 768 public function get_github_gist_embed( array $attrs, string $content = '' ) : string { 769 770 extract( 771 shortcode_atts( 772 [ 773 'id' => 0, 774 'gist' => '', 775 ], 776 $attrs 777 ) 778 ); 779 780 $gist = wp_parse_url( untrailingslashit( $gist ), PHP_URL_PATH ); 635 781 636 782 if ( ! empty( $gist ) ) { … … 650 796 651 797 if ( empty( $id ) ) { 652 return; 653 } 654 655 $gist = sprintf( 'https://gist.github.com/%s', esc_url( sanitize_user( $id, true ) ) ); 798 return ''; 799 } 800 801 $gist = sprintf( 802 'https://gist.github.com/%s', 803 sanitize_user( $id, true ) 804 ); 656 805 657 806 $returnable = sprintf( '<script src="%s.js"></script>', esc_url( $gist ) ); 658 807 659 if ( in_array( current_filter(), $this->__no_github_gist_filters ) ) { 660 $returnable = sprintf( 'Github Gist: <a href="%s" rel="nofollow">%s</a>', esc_url( $gist ), esc_html( $gist ) ); 808 if ( in_array( current_filter(), $this->__no_github_gist_filters, true ) ) { 809 810 $returnable = sprintf( 811 '<div class="igsh-gist"><span class="igsh-gist__label">Github Gist:</span> <a href="%s" rel="nofollow">%s</a></div>', 812 esc_url( $gist ), 813 esc_html( $gist ) 814 ); 815 661 816 } 662 817 663 818 return $returnable; 664 819 665 } //end parse_github_gist_tag() 666 667 } //end of class 668 820 } //end get_github_gist_embed() 821 822 } //end of class 669 823 670 824 //EOF -
igsyntax-hiliter/trunk/classes/geshi.php
r1213527 r2719681 595 595 * @since 1.0.0 596 596 */ 597 function GeSHi($source = '', $language = '', $path = '') {597 function __construct($source = '', $language = '', $path = '') { 598 598 if (!empty($source)) { 599 599 $this->set_source($source); … … 4734 4734 static $callback_2; 4735 4735 if (!isset($callback_2)) { 4736 $callback_2 = create_function('$matches', 'return "[" . str_replace("|", "", $matches[1]) . "]";'); 4736 $callback_2 = function( $matches ) { 4737 return '[' . str_replace('|', '', $matches[1]) . ']'; 4738 }; 4737 4739 } 4738 4740 $list = preg_replace_callback('#\(\?\:((?:.\|)+.)\)#', $callback_2, $list); … … 4773 4775 } 4774 4776 4775 ?> 4777 //EOF -
igsyntax-hiliter/trunk/classes/helper.php
r1213527 r2719681 3 3 * Class containing collection of helper methods. 4 4 * 5 * @author Amit Gupta <http ://amitgupta.in/>5 * @author Amit Gupta <https://amitgupta.in/> 6 6 */ 7 7 … … 16 16 * 17 17 * @param array $array_to_check Array which is to be checked 18 * @return boolean Returns TRUE if the array is associative else FALSE. Even a single numeric key would make this function return FALSE. 19 */ 20 public static function is_associative_array( array $array_to_check ) { 18 * 19 * @return bool Returns TRUE if the array is associative else FALSE. Even a single numeric key would make this function return FALSE. 20 */ 21 public static function is_associative_array( array $array_to_check ) : bool { 21 22 return ! (bool) count( array_filter( array_keys( $array_to_check ), 'is_numeric' ) ); 22 23 } 23 24 24 25 /** 26 * Method to check for existence of a file 27 * 28 * @param string $path Physical path of the file which is to be checked 29 * 30 * @return bool Returns TRUE if file path is valid else FALSE 31 */ 32 public static function is_file_path_valid( string $path ) : bool { 33 return ( ! empty( $path ) && file_exists( $path ) && validate_file( $path ) === 0 ); 34 } 35 36 /** 25 37 * Method to render a template and return the markup 26 38 * 27 39 * @param string $template File path to the template file 28 * @param array $vars Associative array of values which are to be injected into the template. The array keys become var names and key values respective var values. 29 * @return string Template markup ready for output 30 */ 31 public static function render_template( $template, array $vars = array() ) { 40 * @param array $vars Associative array of values which are to be injected into the template. The array keys become var names and key values respective var values. 41 * @param bool $output Optional - Set to TRUE to print out parsed template content, FALSE to return it as string 42 * 43 * @return string|void 44 * 45 * @throws \ErrorException 46 */ 47 public static function render_template( string $template, array $vars = [], bool $output = false ) { 32 48 33 49 if ( empty( $template ) ) { … … 35 51 } 36 52 37 if ( ! file_exists( $template ) ) { 38 throw new ErrorException( 'Template ' . basename( $template ) . ' does not exist' ); 53 if ( ! static::is_file_path_valid( $template ) ) { 54 throw new ErrorException( 55 sprintf( 56 'Template %s does not exist', 57 basename( $template ) 58 ) 59 ); 39 60 } 40 61 … … 47 68 ob_start(); 48 69 require $template; 49 return ob_get_clean(); 50 51 } 52 53 /** 54 * This method returns the URL of an asset if relative path to asset is passed else 55 * the URL to assets folder. 56 * 57 * @param string $asset_path Optional asset path relative from assets folder 70 $html = ob_get_clean(); 71 72 if ( true === $output ) { 73 echo $html; // phpcs:ignore This is ignored because any escaping to be done should be done in the template itself. 74 return; 75 } 76 77 return $html; 78 79 } 80 81 /** 82 * Method to remove forward slash from the beginning of a string 83 * 84 * @param string $path String from which forward slash is to be removed from beginning 85 * 86 * @return string String with forward slash removed from beginning 87 */ 88 public static function unleadingslashit( string $path ) : string { 89 return ltrim( $path, '/' ); 90 } 91 92 /** 93 * Method to add one forward slash at the beginning of a string 94 * 95 * @param string $path String to which forward slash is to be added at beginning 96 * 97 * @return string String with forward slash added at beginning 98 */ 99 public static function leadingslashit( string $path ) : string { 100 return sprintf( '/%s', static::unleadingslashit( $path ) ); 101 } 102 103 /** 104 * Method to get the URL of an asset if relative path to asset is passed else the URL to assets folder. 105 * 106 * @param string $path Optional asset path relative from assets folder 107 * 58 108 * @return string URL to asset or asset folder 59 109 */ 60 public static function get_asset_url( $asset_path = '' ) { 61 return plugins_url( sprintf( '/assets/%s', ltrim( $asset_path, '/' ) ), dirname( __DIR__ ) ); 62 } 63 64 public static function human_time_diff( $from = 0, $to = 0 ) { 65 66 $from = intval( $from ); 67 $to = ( intval( $to ) < 1 ) ? time() : intval( $to ); 68 69 $divs = array( 110 public static function get_asset_url( string $path = '' ) : string { 111 return plugins_url( 112 sprintf( '/assets/%s', static::unleadingslashit( $path ) ), 113 __DIR__ 114 ); 115 } 116 117 /** 118 * Method to get difference between two timestamps in a humanly readable format 119 * 120 * @param int $from 121 * @param int $to 122 * 123 * @return string 124 */ 125 public static function human_time_diff( int $from = 0, int $to = 0 ) : string { 126 127 $to = ( 1 > $to ) ? time() : $to; 128 129 $divs = [ 70 130 'second' => 60, 71 131 'minute' => 60, … … 74 134 'week' => ( 30 / 7 ), 75 135 'month' => 12, 76 );136 ]; 77 137 78 138 $in_future = ( $to > $from ); 79 80 $diff = abs( intval( $from - $to ) ); 81 139 $diff = abs( intval( $from - $to ) ); 82 140 $diff_unit = 'year'; 83 141 … … 110 168 * 111 169 * @param array $default Array containing default values which are to be overridden 112 * @param array $new Array containing new values 170 * @param array $new Array containing new values 171 * 113 172 * @return array An array containing new values from $new which override existing values in $default 114 173 */ 115 public static function array_merge( array $default = array(), array $new = array() ){174 public static function array_merge( array $default = [], array $new = [] ) : array { 116 175 117 176 if ( empty( $default ) ) { 118 return false;177 return []; 119 178 } 120 179 … … 143 202 * 144 203 * @param bool $value 204 * 145 205 * @return string 146 206 */ 147 207 public static function bool_to_yesno( $value ) { 208 148 209 if ( ! is_bool( $value ) ) { 149 210 return $value; 150 211 } 151 212 152 $value = ( $value === true ) ? 'yes' : 'no';213 $value = ( true === $value ) ? 'yes' : 'no'; 153 214 154 215 return $value; 216 155 217 } 156 218 … … 160 222 * 161 223 * @param string $value 224 * 162 225 * @return bool 163 226 */ 164 227 public static function yesno_to_bool( $value ) { 228 165 229 if ( ! is_string( $value ) ) { 166 230 return $value; … … 170 234 171 235 return $value; 172 } 173 174 } //end of class 175 176 236 237 } 238 239 /** 240 * Improved version of PHP's inbuilt filter_input() which works well on PHP CLI 241 * as well which PHP default method does not. 242 * 243 * @param int $type One of INPUT_GET, INPUT_POST, INPUT_COOKIE, INPUT_SERVER, or INPUT_ENV 244 * @param string $variable_name Name of a variable to get 245 * @param int $filter The ID of the filter to apply 246 * @param null $options Filter to apply 247 * 248 * @return mixed|bool|null Value of the requested variable on success, FALSE if the filter fails, or NULL if the variable_name variable is not set. 249 * 250 * @since 2017-10-05 Amit Gupta 251 */ 252 public static function filter_input( int $type, string $variable_name, int $filter = FILTER_DEFAULT, $options = null ) { 253 254 if ( 'cli' !== php_sapi_name() ) { 255 256 /* 257 * Code is not running on PHP CLI and we are in clear. 258 * Use the PHP method and bail out. 259 */ 260 switch ( $filter ) { 261 262 case FILTER_SANITIZE_STRING: 263 $sanitized_variable = sanitize_text_field( filter_input( $type, $variable_name, $filter ) ); 264 break; 265 266 default: 267 $sanitized_variable = filter_input( $type, $variable_name, $filter, $options ); 268 break; 269 270 } 271 272 return $sanitized_variable; 273 274 } 275 276 /* 277 * Code is running on PHP CLI and INPUT_SERVER returns NULL 278 * even for set vars when run on CLI 279 * @see https://bugs.php.net/bug.php?id=49184 280 * 281 * This is a workaround for that bug till its resolved in PHP binary 282 * which doesn't look to be anytime soon. This is a friggin' 10 year old bug. 283 */ 284 285 $input = ''; 286 $allowed_html_tags = wp_kses_allowed_html( 'post' ); 287 288 /* 289 * Marking the switch() block below to be ignored by PHPCS 290 * because PHPCS squawks on using superglobals like $_POST or $_GET 291 * directly but it can't be helped in this case as this code 292 * is running on CLI. 293 */ 294 295 // phpcs:disable 296 297 switch( $type ) { 298 299 case INPUT_GET: 300 if ( ! isset( $_GET[ $variable_name ] ) ) { 301 return null; 302 } 303 304 $input = wp_kses( $_GET[ $variable_name ], $allowed_html_tags ); 305 break; 306 307 case INPUT_POST: 308 if ( ! isset( $_POST[ $variable_name ] ) ) { 309 return null; 310 } 311 312 $input = wp_kses( $_POST[ $variable_name ], $allowed_html_tags ); 313 break; 314 315 case INPUT_COOKIE: 316 if ( ! isset( $_COOKIE[ $variable_name ] ) ) { 317 return null; 318 } 319 320 $input = wp_kses( $_COOKIE[ $variable_name ], $allowed_html_tags ); 321 break; 322 323 case INPUT_SERVER: 324 if ( ! isset( $_SERVER[ $variable_name ] ) ) { 325 return null; 326 } 327 328 $input = wp_kses( $_SERVER[ $variable_name ], $allowed_html_tags ); 329 break; 330 331 case INPUT_ENV: 332 if ( ! isset( $_ENV[ $variable_name ] ) ) { 333 return null; 334 } 335 336 $input = wp_kses( $_ENV[ $variable_name ], $allowed_html_tags ); 337 break; 338 339 default: 340 return null; 341 break; 342 343 } // end switch() 344 345 // phpcs:enable 346 347 return filter_var( $input, $filter ); 348 349 } //end filter_input() 350 351 } //end of class 177 352 178 353 //EOF -
igsyntax-hiliter/trunk/classes/ig-syntax-hiliter-gatekeeper.php
r1213527 r2719681 3 3 * Gatekeeper class for the plugin which loads plugin only if minimum requirements are satisfied. 4 4 * 5 * @author Amit Gupta <http ://amitgupta.in/>5 * @author Amit Gupta <https://amitgupta.in/> 6 6 * 7 7 * @since 2015-07-26 … … 11 11 final class iG_Syntax_Hiliter_Gatekeeper { 12 12 13 const MIN_PHP_VERSION_REQUIRED = ' 5.3.0';13 const MIN_PHP_VERSION_REQUIRED = '7.4.0'; 14 14 15 15 /** … … 29 29 30 30 /** 31 * Factory method to initialize the class 32 * 33 * @return \iG_Syntax_Hiliter_Gatekeeper 34 */ 35 public static function activate() { 36 37 $class = get_called_class(); 38 39 return ( new $class() ); 40 41 } 42 43 /** 31 44 * Check if plugin's minimum requirements are satisfied or not. If they are then 32 45 * Gatekeeper can grant a pass else deny passage. … … 35 48 */ 36 49 private function _has_pass() { 50 37 51 if ( version_compare( phpversion(), self::MIN_PHP_VERSION_REQUIRED ) == -1 ) { 38 52 //min requirements not met … … 41 55 42 56 return true; 57 43 58 } 44 59 … … 49 64 */ 50 65 private function _load_plugin() { 66 51 67 //load up autoloader 52 68 require_once( IG_SYNTAX_HILITER_ROOT . '/autoloader.php' ); … … 66 82 67 83 } 84 68 85 } 69 86 … … 77 94 */ 78 95 public function show_admin_notice() { 79 printf( '<div class="error"><p>PHP version %s or greater is needed for <strong>iG:Syntax Hiliter</strong> plugin. You must upgrade your PHP to make it work.</p></div>', esc_html( self::MIN_PHP_VERSION_REQUIRED ) ); 96 97 printf( 98 '<div class="error"><p>PHP version %s or greater is needed for <strong>iG:Syntax Hiliter</strong> plugin. You must upgrade your PHP to make it work.</p></div>', 99 esc_html( self::MIN_PHP_VERSION_REQUIRED ) 100 ); 101 80 102 } 81 103 82 } //end of class 83 104 } //end of class 84 105 85 106 //EOF -
igsyntax-hiliter/trunk/classes/migrate.php
r1213527 r2719681 3 3 * Class for migrating old plugin values to new 4 4 * 5 * @author Amit Gupta <http ://amitgupta.in/>5 * @author Amit Gupta <https://amitgupta.in/> 6 6 * 7 7 * @since 2015-07-20 … … 10 10 namespace iG\Syntax_Hiliter; 11 11 12 class Migrate extends Singleton { 12 use \iG\Syntax_Hiliter\Traits\Singleton; 13 14 class Migrate { 15 16 use Singleton; 13 17 14 18 const V35_OPTION_NAME = 'igsh_options'; 15 19 16 20 /** 17 * @var iG\Syntax_Hiliter\Option21 * @var \iG\Syntax_Hiliter\Option 18 22 */ 19 23 protected $_option; … … 24 28 protected $_db_version; 25 29 30 /** 31 * Class constructor 32 */ 26 33 protected function __construct() { 27 34 //init options … … 29 36 } 30 37 31 public function settings( Base $obj ) {38 public function settings( Base $obj ) : void { 32 39 33 40 $this->_db_version = $this->_get_last_version(); 34 41 35 if ( $this->_db_version == round( floatval( IG_SYNTAX_HILITER_VERSION ), 1 )) {36 return; //current version, nothing to migrate, bail out42 if ( round( floatval( IG_SYNTAX_HILITER_VERSION ), 1 ) === $this->_db_version ) { 43 return; //current version, nothing to migrate, bail out 37 44 } 38 45 … … 64 71 * @return float Last version of plugin installed. Returns 0 if its a fresh install. 65 72 */ 66 protected function _get_last_version() { 73 protected function _get_last_version() : float { 74 67 75 $db_version = floatval( get_option( Base::PLUGIN_ID . '-version', 0 ) ); 68 76 … … 72 80 73 81 return round( floatval( $db_version ), 1 ); 82 74 83 } 75 84 … … 80 89 * @return void 81 90 */ 82 protected function _add_migrated_from_version() {91 protected function _add_migrated_from_version() : void { 83 92 update_option( Base::PLUGIN_ID . '-migrated-from', $this->_db_version ); 84 93 } … … 88 97 * or not. 89 98 * 90 * @return bool eanReturns TRUE if plugin's last version in use was v3.5.x else FALSE99 * @return bool Returns TRUE if plugin's last version in use was v3.5.x else FALSE 91 100 */ 92 protected function _is_updating_from_35() {101 protected function _is_updating_from_35() : bool { 93 102 $old_options = get_option( self::V35_OPTION_NAME, false ); 94 103 95 if ( $old_options === false|| ! is_array( $old_options ) ) {104 if ( false === $old_options || ! is_array( $old_options ) ) { 96 105 return false; 97 106 } … … 105 114 * @return void 106 115 */ 107 protected function _settings_from_35() { 108 $old_options = get_option( self::V35_OPTION_NAME, array() ); 116 protected function _settings_from_35() : void { 117 118 $old_options = get_option( self::V35_OPTION_NAME, [] ); 109 119 110 120 if ( isset( $old_options['PLAIN_TEXT'] ) ) { … … 120 130 } 121 131 122 delete_option( self::V35_OPTION_NAME ); //delete old options from DB132 delete_option( self::V35_OPTION_NAME ); //delete old options from DB 123 133 124 134 $this->_add_migrated_from_version(); 125 135 126 136 unset( $old_options ); 137 127 138 } 128 139 … … 132 143 * @return void 133 144 */ 134 protected function _initialize_on_fresh_install( Base $obj ) { 135 $obj->get_languages( 'yes' ); //rebuild language file list 145 protected function _initialize_on_fresh_install( Base $obj ) : void { 146 147 $obj->get_languages( 'yes' ); //rebuild language file list 148 136 149 $this->_option->commit(); 150 137 151 } 138 152 139 } //end of class 140 153 } //end of class 141 154 142 155 //EOF -
igsyntax-hiliter/trunk/classes/option.php
r1213527 r2719681 3 3 * Class for fetching and saving plugin options 4 4 * 5 * @author Amit Gupta <http ://amitgupta.in/>5 * @author Amit Gupta <https://amitgupta.in/> 6 6 */ 7 7 8 8 namespace iG\Syntax_Hiliter; 9 9 10 class Option extends Singleton { 10 use \iG\Syntax_Hiliter\Traits\Singleton; 11 12 class Option { 13 14 use Singleton; 11 15 12 16 /** 13 * @var Array An array which contains plugin options17 * @var array An array which contains plugin options 14 18 */ 15 19 protected $_options; 16 20 17 21 /** 18 * @var Array An array which contains default plugin options22 * @var array An array which contains default plugin options 19 23 */ 20 protected $_default_options = array(21 'fe-styles' => 'yes', //use plugin CSS to style hilited code box by default22 'strict_mode' => 'maybe', //don't use GeSHi strict mode always23 'non_strict_mode' => array( 'php' ),//langauges where strict mode is disabled24 'toolbar' => 'yes', //show toolbar above hilited code by default25 'plain_text' => 'yes', //show option to view code in plain text by default26 'show_line_numbers' => 'yes', //show line numbers in code by default27 'hilite_comments' => 'yes', //hilite code posted in comments by default28 'link_to_manual' => 'no', //don't link keywords to manual by default29 'gist_in_comments' => 'no', //don't embed Github Gist in comments by default30 );24 protected $_default_options = [ 25 'fe-styles' => 'yes', //use plugin CSS to style hilited code box by default 26 'strict_mode' => 'maybe', //don't use GeSHi strict mode always 27 'non_strict_mode' => [ 'php' ], //langauges where strict mode is disabled 28 'toolbar' => 'yes', //show toolbar above hilited code by default 29 'plain_text' => 'yes', //show option to view code in plain text by default 30 'show_line_numbers' => 'yes', //show line numbers in code by default 31 'hilite_comments' => 'yes', //hilite code posted in comments by default 32 'link_to_manual' => 'no', //don't link keywords to manual by default 33 'gist_in_comments' => 'no', //don't embed Github Gist in comments by default 34 ]; 31 35 36 /** 37 * Class constructor 38 */ 32 39 protected function __construct() { 33 40 $this->_load_all_options(); … … 37 44 * @return void 38 45 */ 39 protected function _load_all_options() { 46 protected function _load_all_options() : void { 47 40 48 //fetch options array from wp_options & then do a safe merge with default options 41 49 $db_options = get_option( Base::PLUGIN_ID . '-options', false ); 42 50 43 51 if ( empty( $db_options ) || ! is_array( $db_options ) ) { 44 $db_options = array();52 $db_options = []; 45 53 } 46 54 47 55 $this->_options = Helper::array_merge( $this->_default_options, $db_options ); 56 48 57 } 49 58 50 59 /** 51 * This function is just a wrapper to fetch an option from $_options class var, 52 * since direct access to the $_options var is not allowed 60 * Getter method to fetch a single option by name 61 * 62 * @param string $name 63 * 64 * @return mixed 53 65 */ 54 public function get( $option_name ) { 55 if ( empty( $option_name ) || ! is_string( $option_name ) ) { 56 return false; 57 } 66 public function get( string $name ) { 58 67 59 if ( isset( $this->_options[ $option_name ] ) ) { 60 return $this->_options[ $option_name ]; 61 } 62 63 return false; 64 } 65 66 public function get_all() { 67 return $this->_options; 68 } 69 70 /** 71 * This function is for setting a value in the $_options class var as direct 72 * access to it isn't allowed. It takes care of sanitizing the value before 73 * putting it in $_options & saves only if the option name exists already. 74 */ 75 public function save( $option_name, $option_value ) { 76 77 if ( empty( $option_name ) || ! is_string( $option_name ) || ! isset( $this->_options[ $option_name ] ) ) { 78 return false; 79 } 80 81 $can_be_empty = false; 82 83 if ( is_array( $option_value ) ) { 84 $option_value = array_map( 'strtolower', array_map( 'trim', array_map( 'sanitize_title', $option_value ) ) ); 85 $can_be_empty = true; 86 } else { 87 $option_value = strtolower( trim( sanitize_title( $option_value ) ) ); 88 } 89 90 if ( ! empty( $option_value ) || $can_be_empty === true ) { 91 $this->_options[ $option_name ] = $option_value; 92 $this->commit(); //lets save in DB as well 93 94 return true; 68 if ( ! empty( $name ) && isset( $this->_options[ $name ] ) ) { 69 return $this->_options[ $name ]; 95 70 } 96 71 … … 100 75 101 76 /** 102 * This function is for saving the $_options class var in the DB, can be called anytime 103 * or in the class destructor 77 * Method to get all options 78 * 79 * @return array 80 */ 81 public function get_all() : array { 82 return $this->_options; 83 } 84 85 /** 86 * Method to save an option. It takes care of sanitizing the value before 87 * saving it and saves an option only if the option name already exists. 88 * 89 * @param string $name 90 * @param mixed $value 91 * 92 * @return bool Returns TRUE if option is successfully saved else FALSE 93 */ 94 public function save( string $name, $value ) : bool { 95 96 if ( empty( $name ) || ! isset( $this->_options[ $name ] ) ) { 97 return false; 98 } 99 100 $can_be_empty = false; 101 102 if ( is_array( $value ) ) { 103 104 $value = array_map( 'sanitize_title', $value ); 105 $value = array_map( 'trim', $value ); 106 $value = array_map( 'strtolower', $value ); 107 108 $can_be_empty = true; 109 110 } else { 111 $value = strtolower( trim( sanitize_title( $value ) ) ); 112 } 113 114 if ( ! empty( $value ) || true === $can_be_empty ) { 115 116 $this->_options[ $name ] = $value; 117 118 $this->commit(); //lets save in DB as well 119 120 return true; 121 122 } 123 124 return false; 125 126 } 127 128 /** 129 * Method to save options in DB. This can be called anytime and even in the class destructor. 104 130 * 105 131 * @return bool 106 132 */ 107 public function commit() { 133 public function commit() : bool { 134 108 135 if ( empty( $this->_options ) ) { 109 136 return false; … … 113 140 114 141 return true; 142 115 143 } 116 144 117 } //end of class 118 145 } //end of class 119 146 120 147 //EOF -
igsyntax-hiliter/trunk/classes/validate.php
r1213527 r2719681 3 3 * Class for validating plugin values 4 4 * 5 * @author Amit Gupta <http ://amitgupta.in/>5 * @author Amit Gupta <https://amitgupta.in/> 6 6 * 7 7 * @since 2015-07-22 … … 10 10 namespace iG\Syntax_Hiliter; 11 11 12 class Validate extends Singleton { 12 use \iG\Syntax_Hiliter\Traits\Singleton; 13 14 class Validate { 15 16 use Singleton; 13 17 14 18 /** 15 19 * @var array Allowed values for strict mode option 16 20 */ 17 public static $strict_mode_values = array( 'always', 'maybe', 'never' );21 public static $strict_mode_values = [ 'always', 'maybe', 'never' ]; 18 22 19 23 /** 20 * Protected constructor, Singleton implemented24 * Class constructor 21 25 */ 22 26 protected function __construct() {} … … 26 30 * it returns TRUE else FALSE. The parameter accepts only string. 27 31 * 28 * @return bool ean32 * @return bool 29 33 */ 30 public function is_yesno( $value ) { 34 public function is_yesno( $value ) : bool { 35 31 36 if ( ! is_string( $value ) ) { 32 37 return false; … … 35 40 $value = strtolower( trim( $value ) ); 36 41 37 if ( $value === "yes" || $value === "no" ) { 38 return true; 39 } 42 return ( in_array( $value, [ 'yes', 'no' ], true ) ); 40 43 41 return false;42 44 } 43 45 … … 47 49 * 48 50 * @param string $value Value for strict mode option 51 * 49 52 * @return string 50 53 */ 51 public function sanitize_strict_mode_values( $value ) { 54 public function sanitize_strict_mode_values( string $value ) : string { 55 52 56 $value = sanitize_title( strtolower( trim( $value ) ) ); 53 57 54 if ( empty( $value ) || ! i s_string( $value ) || ! in_array( $value, static::$strict_mode_values) ) {58 if ( empty( $value ) || ! in_array( $value, static::$strict_mode_values, true ) ) { 55 59 $value = static::$strict_mode_values[0]; 56 60 } 57 61 58 62 return $value; 63 59 64 } 60 65 … … 66 71 * @return array A sanitized $values array, non-existing and duplicate language names removed 67 72 */ 68 public function languages( array $values = array(), array $languages = array() ){73 public function languages( array $values = [], array $languages = [] ) : array { 69 74 70 75 if ( empty( $values ) || empty( $languages ) ) { 71 return array();76 return []; 72 77 } 73 78 74 $values = array_filter( array_unique( array_map( 'sanitize_file_name', array_map( 'trim', $values ) ) ) ); 79 $values = array_filter( 80 array_unique( 81 array_map( 82 'sanitize_file_name', 83 array_map( 'trim', $values ) 84 ) 85 ) 86 ); 75 87 76 88 $values_count = count( $values ); 77 $clean_values = array();89 $clean_values = []; 78 90 79 91 for ( $i = 0; $i < $values_count; $i++ ) { 80 92 81 if ( in_array( $values[ $i ], $languages ) ) {93 if ( in_array( $values[ $i ], $languages, true ) ) { 82 94 $clean_values[] = $values[ $i ]; 83 95 } … … 91 103 } 92 104 93 } //end of class 94 105 } //end of class 95 106 96 107 //EOF -
igsyntax-hiliter/trunk/ig-syntax-hiliter.php
r1213527 r2719681 2 2 /* 3 3 Plugin Name: iG:Syntax Hiliter 4 Plugin URI: http ://blog.igeek.info/wp-plugins/igsyntax-hiliter/5 Description: Syntax Highlighter plugin to colouri ze source code for various supported programming languages. See the MANUALfor more instructions.6 Version: 5. 04 Plugin URI: https://igeek.info/category/wp-plugins/igsyntax-hiliter/ 5 Description: Syntax Highlighter plugin to colourise source code for various supported programming languages. See the <a href="https://github.com/coolamit/ig-syntax-hiliter/blob/master/README.md">documentation</a> for more instructions. 6 Version: 5.1 7 7 Author: Amit Gupta 8 Author URI: http ://blog.igeek.info/8 Author URI: https://igeek.info/ 9 9 License: GPL v2 10 10 */ 11 11 12 define( 'IG_SYNTAX_HILITER_VERSION', 5.1 ); 12 13 define( 'IG_SYNTAX_HILITER_ROOT', __DIR__ ); 13 14 if ( ! defined( 'IG_SYNTAX_HILITER_VERSION' ) ) { 15 define( 'IG_SYNTAX_HILITER_VERSION', 5.0 ); 16 } 14 define( 'IG_SYNTAX_HILITER_URL', plugins_url( '/' ) ); 15 define( 'IG_SYNTAX_HILITER_BASENAME', plugin_basename( __FILE__ ) ); 17 16 18 17 //set loader to execute on WP init … … 20 19 21 20 function ig_syntax_hiliter_loader() { 21 22 22 /* 23 23 * Load the Gatekeeper … … 28 28 * Activate the Gatekeeper 29 29 */ 30 new iG_Syntax_Hiliter_Gatekeeper(); 30 iG_Syntax_Hiliter_Gatekeeper::activate(); 31 31 32 } 32 33 -
igsyntax-hiliter/trunk/readme.txt
r1213537 r2719681 3 3 Tags: syntax highlighter, code highlighter, code, source code, php, mysql, html, css, javascript 4 4 Requires at least: 4.1 5 Tested up to: 4.3 6 Stable tag: trunk 7 License: GPLv2 5 Tested up to: 5.9 6 Requires PHP: 7.4.0 7 Stable tag: 5.1 8 License: GPLv2 or later 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 8 10 9 11 A plugin to easily present source code on your site with syntax highlighting and formatting (as seen in code editors, IDEs). … … 18 20 19 21 * WordPress 4.1 or above 20 * PHP 5.3or above22 * PHP 7.4.0 or above 21 23 22 24 23 25 Pull requests are welcome on Github. 24 26 25 Github: https://github.com/coolamit/ig-syntax-hiliter27 Github: [https://github.com/coolamit/ig-syntax-hiliter/](https://github.com/coolamit/ig-syntax-hiliter/) 26 28 27 29 == Installation == … … 51 53 == Other Notes == 52 54 53 ###Plugin Usage### 54 55 Using this syntax highlighter is fairly easy. There is one tag and 8 optional attributes. Here's how code is posted for it to be highlighted. 56 57 `[sourcecode language="language_name"] 58 //some code here 59 [/sourcecode]` 60 61 So if you are posting some PHP code then it would be 62 63 `[sourcecode language="php"] 64 //some code here 65 [/sourcecode]` 66 67 or you can use shorthand tags like 68 69 `[php] 70 //some code here 71 [/php]` 72 73 74 Its advised to use the full format of the tag for semantics, however its a personal choice and the plugin supports both full format and shorthand. 75 76 HTML entities need not be escaped, you can post your code as is and the plugin takes care of it all. 77 78 **Important :** Do not forget to close the tags, as your code will not be hilited if you don't close your tags. Also, *don't nest tags*. Nesting of tags don't work, so don't try it, it'll ruin your output. 79 80 Also a WYSIWYG editor (like the one bundled with WordPress) will probably mess up your code when you paste it in the editor. So if you are having that issue, then please don't report it as a bug. WYSIWYG editors are just not supported at present. 81 82 ###(Optional) Plugin Attributes### 83 84 **language :** Use this to specify the programming language whose code you are posting. This language has to be present in `geshi` directory inside plugin directory. If `language` attribute is not specified or if a non-existent language is specified in it then a generic code box is rendered. `lang` is the shorthand for `language` attribute. 85 86 **firstline :** Use this to start line numbering from a number greater than 1. 87 88 **highlight :** Use this to tell plugin which lines are to be marked as different for emphasis. Line numbers are actual line numbers of code and have no relation to the ones starting as per `firstline` attribute. It accepts a comma separated list of line numbers and line number ranges like 5-8 which is equal to 5,6,7,8 89 90 `[sourcecode language="php" highlight="2,4-6,9"] 91 //line 1 of PHP code 92 //line 2 of PHP code 93 //line 3 of PHP code 94 //line 4 of PHP code 95 //line 5 of PHP code 96 //line 6 of PHP code 97 //line 7 of PHP code 98 //line 8 of PHP code 99 //line 9 of PHP code 100 [/sourcecode]` 101 102 **file :** Use this to show a file name/path. This is displayed in the tool-bar shown above code box. 103 104 **gutter :** Use this to tell plugin whether to show line numbers in the code box or not. It accepts either `yes` or `no`. This, if specified, will override the global option to show line numbers for that particular code box. 105 106 **plaintext :** Use this to tell plugin whether to show plain text option for the code box or not. It accepts either `yes` or `no`. This, if specified, will override the global option to show plain text option for that particular code box. 107 108 **toolbar :** Use this to tell plugin whether to show tool-bar for the code box or not. It accepts either `yes` or `no`. This, if specified, will override the global option to show toolbar for that particular code box. 109 110 **strict_mode :** Use this to tell the plugin to use GeSHi Strict Mode for a particular code box or not. This attribute accepts `always` or `never` or `maybe` as value. If you don't know what this means then its better to ignore this attribute and let it remain default. 111 112 ###Configuration### 113 114 Configuring **iG:Syntax Hiliter** is a piece of cake. Login to your WordPress admin section & under the `Settings` menu you'll see `iG:Syntax Hiliter` in the sub-menu. 115 116 When you click the `iG:Syntax Hiliter` configuration page, you are offered 10 configuration settings which you can set to your liking. Lets go through each of them. 117 118 **Use plugin CSS for styling? :** This option allows you to tell the plugin whether it should use its own CSS for styling the code box (not the hilited code, just code box) or not. If you want to use your own styling for the code box, tool-bar etc then you can set it to `NO`. By default its set to `YES`. 119 120 **GeSHi Strict Mode? :** This option allows you to tell the plugin the [strict mode](http://qbnz.com/highlighter/geshi-doc.html#using-strict-mode) setting to use with GeSHi. Strict mode can be set to be always on or off or you can set it to `MAYBE` to have GeSHi decide on its own using the language file of the language whose code you're hiliting. *If you don't have any clue about this then leave it at default setting.* By default its set to `MAYBE`. This option can be overridden for any code block using `strict_mode` attribute in the tag. 121 122 **Languages where GeSHi strict mode is disabled :** This option lets you specify a comma separated list of languages where the GeSHi strict mode should always be disabled. Strict mode is disabled for PHP by default. 123 124 **Show Toolbar? :** This option allows you to tell the plugin whether to show the tool-bar (which shows plain text option, file name, language name) above the code boxes or not. This option can be overridden for any code block using `toolbar` attribute in the tag. 125 126 **Show Plain Text Option? :** This option allows you to tell the plugin whether to show the *Plain Text* view option on the code boxes or not. This option can be overridden for any code block using `plaintext` attribute in the tag. 127 128 **Show line numbers in code? :** This option allows you to tell the plugin whether to show the line numbers along with code in the code boxes or not. Line numbers along with code look great, are a great help when referring to some code from a code box. This option can be overridden for any code block using `gutter` attribute in the tag. 129 130 **Hilite code in comments? :** This option allows you to tell the plugin whether to hilite code posted in comments or not. If this is enabled, code posted in the comments will be hilited as it is in the posts. 131 132 **Link keywords/function names to Manual? :** This option allows you to tell the plugin whether to link keywords, function names etc to that language's online manual or not. This works only if this feature is enabled for that particular language in GeSHi language file. 133 134 **Enable GitHub Gist embed in comments? :** This option allows you to tell the plugin whether to embed Github Gist in comments or not. If disabled then a Gist posted in comments would just have a link to its page on Github. 135 136 **Rebuild Shorthand Tags :** Language files in the plugin's directory and current theme (parent & child) directory are scanned and their names are cached to allow shorthand tag usage for all languages. This cache is rebuilt automatically every week. But if you wish to rebuild it manually you can do so by clicking this button. 137 55 [Documentation on plugin usage and configuration](https://github.com/coolamit/ig-syntax-hiliter/blob/master/README.md) 138 56 139 57 == Frequently Asked Questions == … … 158 76 159 77 == ChangeLog == 78 79 = v5.1 = 80 81 * Minimum required PHP version bumped to 7.4.0. The plugin simply won't load its code on lower versions. 82 * Refactored plugin code for PHP 7.4.x for better performing code. 83 * **This is the last release using the GeSHi library.** GeSHi library has not been updated in several years and it looks unlikely that it will continue. Next release of the plugin will use a different syntax highlighting library. All existing shortcodes will continue to work and so the update and transition would be seamless for the most part, except a feature or two that will phase out and a few changes in plugin configuration options. 160 84 161 85 = v5.0 = … … 260 184 == Upgrade Notice == 261 185 262 = 5. 0=263 Major re -write of plugin for cleaner, modular & better performing code. Fixes automatic tag cache rebuilds, new options allow more control over plugin and GeSHi.186 = 5.1 = 187 Major refactor of plugin code for compatibility with PHP 7.4.0 and above. 264 188 265 189 -
igsyntax-hiliter/trunk/templates/frontend-code-box.php
r1213527 r2719681 1 1 <?php 2 /* 3 * Template for showing code box 2 /** 3 * Template for showing hilited code in a box 4 * 5 * @package igsyntax-hiliter 4 6 */ 7 8 if ( empty( $attrs ) || empty( $id_prefix ) || empty( $code ) ) { 9 return ''; 10 } 5 11 ?> 6 12 <div id="<?php echo esc_attr( $id_prefix . $counter ); ?>" class="syntax_hilite"> 7 13 8 <?php if ( $attrs['toolbar'] === true) { ?>14 <?php if ( true === $attrs['toolbar'] ) { ?> 9 15 <div class="toolbar"> 10 16 11 17 <div class="view-different-container"> 12 <?php if ( $attrs['plain_text'] === true) { ?>18 <?php if ( true === $attrs['plain_text'] ) { ?> 13 19 <a href="#" class="view-different">< View <span><?php echo esc_html( $plain_text ); ?></span> ></a> 14 20 <?php } ?> … … 17 23 <div class="language-name"><?php echo esc_html( $attrs['language'] ); ?></div> 18 24 19 <?php if ( ! empty( $attrs['file'] ) ) { ?>25 <?php if ( ! empty( $attrs['file'] ) && ! empty( $file_path ) ) { ?> 20 26 <div class="filename" title="<?php echo esc_attr( $attrs['file'] ); ?>"><?php echo esc_html( $file_path ); ?></div> 21 27 <?php } ?> -
igsyntax-hiliter/trunk/templates/plugin-options-page.php
r1213527 r2719681 1 1 <?php 2 /* 2 /** 3 3 * Template for the plugin options page 4 * 5 * @package igsyntax-hiliter 4 6 */ 5 7 ?>
Note: See TracChangeset
for help on using the changeset viewer.