ddd
Showing
52 changed files
with
1161 additions
and
0 deletions
This diff is collapsed.
Click to expand it.
| 1 | /* FVM 3 */ | ||
| 2 | #fastvelocity-min{margin-top:10px} | ||
| 3 | #fastvelocity-min .clear{clear:both} | ||
| 4 | .fvm-settings label{font-size:15px;color:#222;padding-top:1px} | ||
| 5 | .fvm-settings span.note-info{font-size:15px;margin-left:8px;color:#666;font-style:italic} | ||
| 6 | .fvm-settings p.description{font-size:15px;color:#666;font-style:italic} | ||
| 7 | #tab-info h4{font-size:15px;margin-bottom:-10px} | ||
| 8 | .fvm-hide{max-height:1px;overflow:none;position:absolute;top:-9999px;left:-9999px;visibility:hidden} | ||
| 9 | .fvm-warning{font-weight:500;color:#A00} | ||
| 10 | h3.fvm-bold-green{font-weight:500;font-size:15px;color:#1196A3} | ||
| 11 | .fvm-bold-green{font-weight:500;color:#1196A3} | ||
| 12 | .fvm-label-special{line-height:38px} | ||
| 13 | .fvm-label-pad{line-height:21px} | ||
| 14 | .fvm-rowintro{padding-bottom:10px;font-size:15px} | ||
| 15 | table.fvm-settings td,table.fvm-settings td p,table.fvm-settings th{font-size:15px} | ||
| 16 | .fvm-wrapper{font-size:16px;padding:18px} | ||
| 17 | .fvm-wrapper h4{font-size:16px;margin:0;color:#1196A3} | ||
| 18 | .fvm-wrapper .accordion p,.fvm-wrapper .accordion code{font-size:16px;line-height:1.3} | ||
| 19 | .fvm-wrapper .accordion a, .fvm-wrapper .accordion a:hover { color: #0073aa; } | ||
| 20 | .fvm-code-full{width:100%;padding:8px;background:#F3F3F3;box-sizing:border-box;font-family:Consolas,Monaco,monospace;font-size:13px;line-height:1.5;margin-bottom:15px} | ||
| 21 | #status .fvm-cache-stats{margin:10px 0 0} | ||
| 22 | #status textarea.row-log{display:block;margin:0;padding:6px;border:none;background:#23282d;color:#ccc;height:300px;max-width:100%;overflow:auto;line-height:1.5;font-size:.8125rem;white-space:pre;font-family:monospace} | ||
| 23 | #status textarea.row-log::-webkit-scrollbar{width:8px;height:8px;background-color:#222} | ||
| 24 | #status textarea.row-log::-webkit-scrollbar-thumb{background-color:#000} | ||
| 25 | #status textarea.row-log::-webkit-scrollbar-track{background-color:#999} | ||
| 26 | |||
| 27 | /* jQuery UI */ | ||
| 28 | .ui-helper-reset{margin:0;padding:0;border:0;outline:0;line-height:1.3;text-decoration:none;font-size:100%;list-style:none} | ||
| 29 | .ui-icon{display:inline-block;vertical-align:middle;margin-top:-.25em;position:relative;text-indent:-99999px;overflow:hidden;background-repeat:no-repeat} | ||
| 30 | .ui-accordion .ui-accordion-header{display:block;cursor:pointer;position:relative;margin:2px 0 0;padding:.5em .5em .5em .7em;font-size:100%} | ||
| 31 | .ui-accordion .ui-accordion-content{padding:1em 2.2em;border-top:0;overflow:auto} | ||
| 32 | .ui-widget{font-size:1em} | ||
| 33 | .ui-widget-content{border:1px solid #ddd;background:#fff;color:#333} | ||
| 34 | .ui-widget-content a{color:#333} | ||
| 35 | .ui-state-default,.ui-widget-content .ui-state-default,.ui-widget-header .ui-state-default,.ui-button,html .ui-button.ui-state-disabled:hover,html .ui-button.ui-state-disabled:active{border:1px solid #c5c5c5;background:#f6f6f6;font-weight:400;color:#454545} | ||
| 36 | .ui-state-hover,.ui-widget-content .ui-state-hover,.ui-widget-header .ui-state-hover,.ui-state-focus,.ui-widget-content .ui-state-focus,.ui-widget-header .ui-state-focus,.ui-button:hover,.ui-button:focus{border:1px solid #ccc;background:#ededed;font-weight:400;color:#2b2b2b} | ||
| 37 | .ui-state-active,.ui-widget-content .ui-state-active,.ui-widget-header .ui-state-active,a.ui-button:active,.ui-button:active,.ui-button.ui-state-active:hover{border:1px solid #bbb;background:#0073aa;font-weight:400;color:#fff} | ||
| 38 | .ui-icon{width:16px;height:16px} | ||
| 39 | .ui-icon,.ui-widget-content .ui-icon{background-image:url(images/ui-icons_444444_256x240.png)} | ||
| 40 | .ui-state-hover .ui-icon,.ui-state-focus .ui-icon,.ui-button:hover .ui-icon,.ui-button:focus .ui-icon{background-image:url(images/ui-icons_555555_256x240.png)} | ||
| 41 | .ui-state-active .ui-icon,.ui-button:active .ui-icon{background-image:url(images/ui-icons_ffffff_256x240.png)} | ||
| 42 | .ui-icon-triangle-1-e{background-position:-32px -16px} | ||
| 43 | .ui-icon-triangle-1-s{background-position:-65px -16px} | ||
| 44 | .ui-corner-all,.ui-corner-top,.ui-corner-left,.ui-corner-tl{border-top-left-radius:3px} | ||
| 45 | .ui-corner-all,.ui-corner-top,.ui-corner-right,.ui-corner-tr{border-top-right-radius:3px} | ||
| 46 | .ui-corner-all,.ui-corner-bottom,.ui-corner-left,.ui-corner-bl{border-bottom-left-radius:3px} | ||
| 47 | .ui-corner-all,.ui-corner-bottom,.ui-corner-right,.ui-corner-br{border-bottom-right-radius:3px} | ||
| 48 | .ui-state-focus:focus{outline:none} | ||
| 49 | |||
| 50 | /* Mobile */ | ||
| 51 | @media screen and (max-width:520px) { | ||
| 52 | .fvm-label-special { line-height: inherit; } | ||
| 53 | } |
| 1 | // get logs via ajax | ||
| 2 | function fvm_get_logs() { | ||
| 3 | |||
| 4 | // ajax request | ||
| 5 | jQuery( document ).ready(function() { | ||
| 6 | var data = { 'action': 'fvm_get_logs' }; | ||
| 7 | jQuery.post(ajaxurl, data, function(resp) { | ||
| 8 | if(resp.success == 'OK') { | ||
| 9 | |||
| 10 | // logs | ||
| 11 | jQuery('.log-stats textarea').val(resp.log); | ||
| 12 | jQuery('.log-stats textarea').scrollTop(jQuery('.log-stats textarea')[0].scrollHeight); | ||
| 13 | |||
| 14 | } else { | ||
| 15 | // error log | ||
| 16 | console.error(resp.success); | ||
| 17 | } | ||
| 18 | }); | ||
| 19 | }); | ||
| 20 | } | ||
| 21 | |||
| 22 | |||
| 23 | jQuery( document ).ready(function() { | ||
| 24 | |||
| 25 | // help section | ||
| 26 | jQuery( ".accordion" ).accordion({ active: false, collapsible: true, heightStyle: "content" }); | ||
| 27 | |||
| 28 | }); | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
6.84 KB
6.84 KB
6.17 KB
| 1 | <?php | ||
| 2 | /* | ||
| 3 | Plugin Name: Fast Velocity Minify | ||
| 4 | Plugin URI: http://fastvelocity.com | ||
| 5 | Description: Improve your speed score on GTmetrix, Pingdom Tools and Google PageSpeed Insights by merging and minifying CSS and JavaScript files into groups, compressing HTML and other speed optimizations. | ||
| 6 | Author: Raul Peixoto | ||
| 7 | Author URI: http://fastvelocity.com | ||
| 8 | Text Domain: fast-velocity-minify | ||
| 9 | Version: 3.2.2 | ||
| 10 | License: GPL2 | ||
| 11 | |||
| 12 | ------------------------------------------------------------------------ | ||
| 13 | This program is free software; you can redistribute it and/or modify | ||
| 14 | it under the terms of the GNU General Public License as published by | ||
| 15 | the Free Software Foundation; either version 2 of the License, or | ||
| 16 | (at your option) any later version. | ||
| 17 | |||
| 18 | This program is distributed in the hope that it will be useful, | ||
| 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 21 | GNU General Public License for more details. | ||
| 22 | |||
| 23 | You should have received a copy of the GNU General Public License | ||
| 24 | along with this program; if not, write to the Free Software | ||
| 25 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 26 | */ | ||
| 27 | |||
| 28 | # Exit if accessed directly | ||
| 29 | if (!defined('ABSPATH')){ exit(); } | ||
| 30 | |||
| 31 | # Invalidate OPCache for current file on WP 5.5+ | ||
| 32 | if(function_exists('wp_opcache_invalidate') && stripos(__FILE__, '/fvm.php') !== false) { | ||
| 33 | wp_opcache_invalidate(__FILE__, true); | ||
| 34 | } | ||
| 35 | |||
| 36 | # info, variables, paths | ||
| 37 | $fvm_var_file = __FILE__; # /home/path/plugins/pluginname/wpr.php | ||
| 38 | $fvm_var_basename = plugin_basename($fvm_var_file); # pluginname/wpr.php | ||
| 39 | $fvm_var_dir_path = plugin_dir_path($fvm_var_file); # /home/path/plugins/pluginname/ | ||
| 40 | $fvm_var_url_path = plugins_url(dirname($fvm_var_basename)) . '/'; # https://example.com/wp-content/plugins/pluginname/ | ||
| 41 | $fvm_var_plugin_version = get_file_data($fvm_var_file, array('Version' => 'Version'), false)['Version']; | ||
| 42 | $fvm_var_inc_dir = $fvm_var_dir_path . 'inc' . DIRECTORY_SEPARATOR; # /home/path/plugins/pluginname/inc/ | ||
| 43 | $fvm_var_inc_lib = $fvm_var_dir_path . 'libs' . DIRECTORY_SEPARATOR; # /home/path/plugins/pluginname/libs/ | ||
| 44 | |||
| 45 | # global functions for backend, frontend, ajax, etc | ||
| 46 | require_once($fvm_var_inc_dir . 'common.php'); | ||
| 47 | require_once($fvm_var_inc_dir . 'updates.php'); | ||
| 48 | |||
| 49 | # wp-cli support | ||
| 50 | if (defined('WP_CLI') && WP_CLI) { | ||
| 51 | require_once($fvm_var_inc_dir . 'wp-cli.php'); | ||
| 52 | } | ||
| 53 | |||
| 54 | # get all options from database | ||
| 55 | $fvm_settings = fvm_get_settings(); | ||
| 56 | |||
| 57 | # site url, domain name | ||
| 58 | $fvm_urls = array('wp_site_url'=>trailingslashit(site_url()), 'wp_domain'=>fvm_get_domain()); | ||
| 59 | |||
| 60 | |||
| 61 | # only on backend | ||
| 62 | if(is_admin()) { | ||
| 63 | |||
| 64 | # admin functionality | ||
| 65 | require_once($fvm_var_inc_dir . 'admin.php'); | ||
| 66 | require_once($fvm_var_inc_dir . 'serverinfo.php'); | ||
| 67 | |||
| 68 | # both backend and frontend, as long as user can manage options | ||
| 69 | add_action('admin_bar_menu', 'fvm_admintoolbar', 100); | ||
| 70 | add_action('init', 'fvm_process_cache_purge_request'); | ||
| 71 | |||
| 72 | # do admin stuff, as long as user can manage options | ||
| 73 | add_action('admin_init', 'fvm_save_settings'); | ||
| 74 | add_action('admin_init', 'fvm_check_minimum_requirements'); | ||
| 75 | add_action('admin_init', 'fvm_check_misconfiguration'); | ||
| 76 | add_action('admin_init', 'fvm_update_changes'); | ||
| 77 | add_action('admin_enqueue_scripts', 'fvm_add_admin_jscss'); | ||
| 78 | add_action('admin_menu', 'fvm_add_admin_menu'); | ||
| 79 | add_action('admin_notices', 'fvm_show_admin_notice_from_transient'); | ||
| 80 | add_action('wp_ajax_fvm_get_logs', 'fvm_get_logs_callback'); | ||
| 81 | |||
| 82 | # purge everything | ||
| 83 | add_action('switch_theme', 'fvm_purge_all'); | ||
| 84 | add_action('customize_save', 'fvm_purge_all'); | ||
| 85 | add_action('avada_clear_dynamic_css_cache', 'fvm_purge_all'); | ||
| 86 | add_action('upgrader_process_complete', 'fvm_purge_all'); | ||
| 87 | add_action('update_option_theme_mods_' . get_option('stylesheet'), 'fvm_purge_all'); | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | |||
| 92 | |||
| 93 | # frontend only, any user permissions | ||
| 94 | if(!is_admin()) { | ||
| 95 | |||
| 96 | # frontend functionality | ||
| 97 | require_once($fvm_var_inc_dir . 'frontend.php'); | ||
| 98 | |||
| 99 | # both back and front, as long as the option is enabled | ||
| 100 | add_action('init', 'fvm_disable_emojis'); | ||
| 101 | add_action('wp_loaded', 'fvm_ajax_optimizer'); | ||
| 102 | |||
| 103 | # both backend and frontend, as long as user can manage options | ||
| 104 | add_action('admin_bar_menu', 'fvm_admintoolbar', 100); | ||
| 105 | add_action('init', 'fvm_process_cache_purge_request'); | ||
| 106 | |||
| 107 | # actions for frontend only | ||
| 108 | add_action('template_redirect', 'fvm_start_buffer', -PHP_INT_MAX); | ||
| 109 | |||
| 110 | } | ||
| 111 |
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
| 1 | <?php | ||
| 2 | |||
| 3 | # Exit if accessed directly | ||
| 4 | if (!defined('ABSPATH')){ exit(); } | ||
| 5 | |||
| 6 | # update routines for new fields and replacements | ||
| 7 | function fvm_update_changes() { | ||
| 8 | |||
| 9 | # current version | ||
| 10 | global $fvm_var_plugin_version; | ||
| 11 | |||
| 12 | # Version 3.0 routines start | ||
| 13 | |||
| 14 | # delete old FVM files | ||
| 15 | global $fvm_var_dir_path, $fvm_var_inc_lib, $fvm_var_inc_dir; | ||
| 16 | |||
| 17 | # prevent deleting if the paths are empty | ||
| 18 | # can happen when a user runs wp-cli on a child directory | ||
| 19 | if(isset($fvm_var_dir_path) && isset($fvm_var_inc_lib) && isset($fvm_var_inc_dir) && !empty($fvm_var_dir_path) && !empty($fvm_var_inc_lib) && !empty($fvm_var_inc_dir)) { | ||
| 20 | |||
| 21 | # must be inside a fast-velocity-minify directory | ||
| 22 | if (stripos($fvm_var_dir_path, 'fast-velocity-minify') !== false) { | ||
| 23 | |||
| 24 | # delete | ||
| 25 | if(file_exists($fvm_var_inc_dir.'functions-cache.php')) { @unlink($fvm_var_inc_dir.'functions-cache.php'); } | ||
| 26 | if(file_exists($fvm_var_inc_dir.'functions-cli.php')) { @unlink($fvm_var_inc_dir.'functions-cli.php'); } | ||
| 27 | if(file_exists($fvm_var_inc_dir.'functions-serverinfo.php')) { @unlink($fvm_var_inc_dir.'functions-serverinfo.php'); } | ||
| 28 | if(file_exists($fvm_var_inc_dir.'functions-upgrade.php')) { @unlink($fvm_var_inc_dir.'functions-upgrade.php'); } | ||
| 29 | if(file_exists($fvm_var_inc_dir.'functions.php')) { @unlink($fvm_var_inc_dir.'functions.php'); } | ||
| 30 | if(file_exists($fvm_var_dir_path.'fvm.css')) { @unlink($fvm_var_dir_path.'fvm.css'); } | ||
| 31 | if(file_exists($fvm_var_dir_path.'fvm.js')) { @unlink($fvm_var_dir_path.'fvm.js'); } | ||
| 32 | if(file_exists($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'HTML.php')) { | ||
| 33 | @unlink($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'HTML.php'); | ||
| 34 | @unlink($fvm_var_inc_lib.'mrclay' . DIRECTORY_SEPARATOR . 'index.html'); | ||
| 35 | @rmdir($fvm_var_inc_lib.'mrclay'); | ||
| 36 | } | ||
| 37 | |||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | # Version 3.2 routines start | ||
| 42 | if (get_option("fastvelocity_plugin_version") !== false) { | ||
| 43 | if (version_compare($fvm_var_plugin_version, '3.2.0', '>=') && get_option("fastvelocity_min_ignore") !== false) { | ||
| 44 | |||
| 45 | # cleanup | ||
| 46 | delete_option('fastvelocity_min_change_cache_path'); | ||
| 47 | delete_option('fastvelocity_min_change_cache_base_url'); | ||
| 48 | delete_option('fastvelocity_min_fvm_cdn_url'); | ||
| 49 | delete_option('fastvelocity_plugin_version'); | ||
| 50 | delete_option('fvm-last-cache-update'); | ||
| 51 | delete_option('fastvelocity_min_ignore'); | ||
| 52 | delete_option('fastvelocity_min_blacklist'); | ||
| 53 | delete_option('fastvelocity_min_ignorelist'); | ||
| 54 | delete_option('fastvelocity_min_excludecsslist'); | ||
| 55 | delete_option('fastvelocity_min_excludejslist'); | ||
| 56 | delete_option('fastvelocity_min_enable_purgemenu'); | ||
| 57 | delete_option('fastvelocity_min_default_protocol'); | ||
| 58 | delete_option('fastvelocity_min_disable_js_merge'); | ||
| 59 | delete_option('fastvelocity_min_disable_css_merge'); | ||
| 60 | delete_option('fastvelocity_min_disable_js_minification'); | ||
| 61 | delete_option('fastvelocity_min_disable_css_minification'); | ||
| 62 | delete_option('fastvelocity_min_remove_print_mediatypes'); | ||
| 63 | delete_option('fastvelocity_min_skip_html_minification'); | ||
| 64 | delete_option('fastvelocity_min_strip_htmlcomments'); | ||
| 65 | delete_option('fastvelocity_min_skip_cssorder'); | ||
| 66 | delete_option('fastvelocity_min_skip_google_fonts'); | ||
| 67 | delete_option('fastvelocity_min_skip_emoji_removal'); | ||
| 68 | delete_option('fastvelocity_fvm_clean_header_one'); | ||
| 69 | delete_option('fastvelocity_min_enable_defer_js'); | ||
| 70 | delete_option('fastvelocity_min_exclude_defer_jquery'); | ||
| 71 | delete_option('fastvelocity_min_force_inline_css'); | ||
| 72 | delete_option('fastvelocity_min_force_inline_css_footer'); | ||
| 73 | delete_option('fastvelocity_min_remove_googlefonts'); | ||
| 74 | delete_option('fastvelocity_min_defer_for_pagespeed'); | ||
| 75 | delete_option('fastvelocity_min_defer_for_pagespeed_optimize'); | ||
| 76 | delete_option('fastvelocity_min_exclude_defer_login'); | ||
| 77 | delete_option('fastvelocity_min_skip_defer_lists'); | ||
| 78 | delete_option('fastvelocity_min_fvm_fix_editor'); | ||
| 79 | delete_option('fastvelocity_min_loadcss'); | ||
| 80 | delete_option('fastvelocity_min_fvm_removecss'); | ||
| 81 | delete_option('fastvelocity_enabled_css_preload'); | ||
| 82 | delete_option('fastvelocity_enabled_js_preload'); | ||
| 83 | delete_option('fastvelocity_fontawesome_method'); | ||
| 84 | delete_option('fastvelocity_gfonts_method'); | ||
| 85 | |||
| 86 | } | ||
| 87 | } | ||
| 88 | # Version 3.2 routines end | ||
| 89 | |||
| 90 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | # Exit if accessed directly | ||
| 4 | if (!defined('ABSPATH')){ exit(); } | ||
| 5 | |||
| 6 | ################################################### | ||
| 7 | # extend wp-cli to purge cache, usage: wp fvm purge | ||
| 8 | ################################################### | ||
| 9 | |||
| 10 | # only for wp-cli | ||
| 11 | if ( defined( 'WP_CLI' ) && WP_CLI ) { | ||
| 12 | |||
| 13 | class fastvelocity_WPCLI { | ||
| 14 | |||
| 15 | # purge files + cache | ||
| 16 | public function purge() { | ||
| 17 | WP_CLI::success( __( 'FVM and other caches were purged.', 'fast-velocity-minify' ) ); | ||
| 18 | fvm_purge_static_files(); | ||
| 19 | fvm_purge_others(); | ||
| 20 | |||
| 21 | # purge everything | ||
| 22 | $cache = fvm_purge_static_files(); | ||
| 23 | $others = fvm_purge_others(); | ||
| 24 | |||
| 25 | # notices | ||
| 26 | WP_CLI::success( __( 'FVM: All Caches are now cleared.', 'fast-velocity-minify' ) .' ('.date("D, d M Y @ H:i:s e").')'); | ||
| 27 | if(is_string($cache)) { WP_CLI::warning($cache); } | ||
| 28 | if(is_string($others)) { WP_CLI::success($others); } | ||
| 29 | |||
| 30 | } | ||
| 31 | |||
| 32 | # get cache size | ||
| 33 | public function stats() { | ||
| 34 | WP_CLI::error( __( 'This feature is currently under development.', 'fast-velocity-minify' ) ); | ||
| 35 | } | ||
| 36 | |||
| 37 | } | ||
| 38 | |||
| 39 | # add commands | ||
| 40 | WP_CLI::add_command( 'fvm', 'fastvelocity_WPCLI' ); | ||
| 41 | |||
| 42 | } | ||
| 43 |
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
| 1 | <?php | ||
| 2 | |||
| 3 | # server info | ||
| 4 | if( $active_tab == 'status' ) { | ||
| 5 | ?> | ||
| 6 | <div class="fvm-wrapper"> | ||
| 7 | |||
| 8 | <div id="status"> | ||
| 9 | |||
| 10 | <div style="height: 40px;"></div> | ||
| 11 | <h2 class="title"><?php _e( 'Latest Logs', 'fast-velocity-minify' ); ?></h2> | ||
| 12 | <h3 class="fvm-bold-green"><?php _e( 'In this section, you can check the latest logs for CSS and JS files', 'fast-velocity-minify' ); ?></h3> | ||
| 13 | <div class="row-log log-stats wpraiser-textarea"><textarea rows="10" cols="50" class="large-text code row-log log-css" disabled></textarea></div> | ||
| 14 | |||
| 15 | <div style="height: 40px;"></div> | ||
| 16 | <h2 class="title"><?php _e( 'Server Info', 'fast-velocity-minify' ); ?></h2> | ||
| 17 | <h3 class="fvm-bold-green"><?php _e( 'In this section, you can check some server stats and information', 'fast-velocity-minify' ); ?></h3> | ||
| 18 | <textarea rows="10" cols="50" class="large-text code row-log" disabled><?php fvm_get_generalinfo(); ?></textarea> | ||
| 19 | |||
| 20 | |||
| 21 | <script>fvm_get_logs();</script> | ||
| 22 | </div> | ||
| 23 | |||
| 24 | </div> | ||
| 25 | <?php | ||
| 26 | |||
| 27 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | <div class="wrap"> | ||
| 2 | <h1>Fast Velocity Minify</h1> | ||
| 3 | <div style="height: 20px;"></div> | ||
| 4 | |||
| 5 | <?php | ||
| 6 | # get active tab, set default | ||
| 7 | $active_tab = isset($_GET['tab']) ? $_GET['tab'] : 'settings'; | ||
| 8 | ?> | ||
| 9 | |||
| 10 | <h2 class="nav-tab-wrapper wp-clearfix"> | ||
| 11 | <a href="?page=fvm" class="nav-tab <?php echo $active_tab == 'settings' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Settings', 'fast-velocity-minify' ); ?></a> | ||
| 12 | <a href="?page=fvm&tab=status" class="nav-tab <?php echo $active_tab == 'status' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Status', 'fast-velocity-minify' ); ?></a> | ||
| 13 | <?php /*<a href="?page=fvm&tab=upgrade" class="nav-tab <?php echo $active_tab == 'upgrade' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Upgrade', 'fast-velocity-minify' ); ?></a>*/ ?> | ||
| 14 | <a href="?page=fvm&tab=help" class="nav-tab <?php echo $active_tab == 'help' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Help', 'fast-velocity-minify' ); ?></a> | ||
| 15 | </h2> | ||
| 16 | |||
| 17 | <div id="fvm"> | ||
| 18 | |||
| 19 | <?php | ||
| 20 | # settings | ||
| 21 | include_once($fvm_var_dir_path . 'layout' . DIRECTORY_SEPARATOR . 'admin-layout-settings.php'); | ||
| 22 | |||
| 23 | # include other tabs | ||
| 24 | include_once($fvm_var_dir_path . 'layout' . DIRECTORY_SEPARATOR . 'admin-layout-status.php'); | ||
| 25 | #include_once($fvm_var_dir_path . 'layout' . DIRECTORY_SEPARATOR . 'admin-layout-upgrade.php'); | ||
| 26 | include_once($fvm_var_dir_path . 'layout' . DIRECTORY_SEPARATOR . 'admin-layout-help.php'); | ||
| 27 | ?> | ||
| 28 | |||
| 29 | </div> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
File mode changed
File mode changed
File mode changed
| 1 | #!/usr/bin/env php | ||
| 2 | <?php | ||
| 3 | use MatthiasMullie\Minify; | ||
| 4 | |||
| 5 | // command line utility to minify CSS | ||
| 6 | if (file_exists(__DIR__ . '/../../../autoload.php')) { | ||
| 7 | // if composer install | ||
| 8 | require_once __DIR__ . '/../../../autoload.php'; | ||
| 9 | } else { | ||
| 10 | require_once __DIR__ . '/../src/Minify.php'; | ||
| 11 | require_once __DIR__ . '/../src/CSS.php'; | ||
| 12 | require_once __DIR__ . '/../src/Exception.php'; | ||
| 13 | } | ||
| 14 | |||
| 15 | error_reporting(E_ALL); | ||
| 16 | // check PHP setup for cli arguments | ||
| 17 | if (!isset($_SERVER['argv']) && !isset($argv)) { | ||
| 18 | fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini' . PHP_EOL); | ||
| 19 | exit(1); | ||
| 20 | } elseif (!isset($argv)) { | ||
| 21 | $argv = $_SERVER['argv']; | ||
| 22 | } | ||
| 23 | // check if path to file given | ||
| 24 | if (!isset($argv[1])) { | ||
| 25 | fwrite(STDERR, 'Argument expected: path to file' . PHP_EOL); | ||
| 26 | exit(1); | ||
| 27 | } | ||
| 28 | // check if script run in cli environment | ||
| 29 | if ('cli' !== php_sapi_name()) { | ||
| 30 | fwrite(STDERR, $argv[1] . ' must be run in the command line' . PHP_EOL); | ||
| 31 | exit(1); | ||
| 32 | } | ||
| 33 | // check if source file exists | ||
| 34 | if (!file_exists($argv[1])) { | ||
| 35 | fwrite(STDERR, 'Source file "' . $argv[1] . '" not found' . PHP_EOL); | ||
| 36 | exit(1); | ||
| 37 | } | ||
| 38 | |||
| 39 | try { | ||
| 40 | $minifier = new Minify\CSS($argv[1]); | ||
| 41 | echo $minifier->minify(); | ||
| 42 | } catch (Exception $e) { | ||
| 43 | fwrite(STDERR, $e->getMessage(), PHP_EOL); | ||
| 44 | exit(1); | ||
| 45 | } |
| 1 | #!/usr/bin/env php | ||
| 2 | <?php | ||
| 3 | use MatthiasMullie\Minify; | ||
| 4 | |||
| 5 | // command line utility to minify JS | ||
| 6 | if (file_exists(__DIR__ . '/../../../autoload.php')) { | ||
| 7 | // if composer install | ||
| 8 | require_once __DIR__ . '/../../../autoload.php'; | ||
| 9 | } else { | ||
| 10 | require_once __DIR__ . '/../src/Minify.php'; | ||
| 11 | require_once __DIR__ . '/../src/JS.php'; | ||
| 12 | require_once __DIR__ . '/../src/Exception.php'; | ||
| 13 | } | ||
| 14 | |||
| 15 | error_reporting(E_ALL); | ||
| 16 | // check PHP setup for cli arguments | ||
| 17 | if (!isset($_SERVER['argv']) && !isset($argv)) { | ||
| 18 | fwrite(STDERR, 'Please enable the "register_argc_argv" directive in your php.ini' . PHP_EOL); | ||
| 19 | exit(1); | ||
| 20 | } elseif (!isset($argv)) { | ||
| 21 | $argv = $_SERVER['argv']; | ||
| 22 | } | ||
| 23 | // check if path to file given | ||
| 24 | if (!isset($argv[1])) { | ||
| 25 | fwrite(STDERR, 'Argument expected: path to file' . PHP_EOL); | ||
| 26 | exit(1); | ||
| 27 | } | ||
| 28 | // check if script run in cli environment | ||
| 29 | if ('cli' !== php_sapi_name()) { | ||
| 30 | fwrite(STDERR, $argv[1] . ' must be run in the command line' . PHP_EOL); | ||
| 31 | exit(1); | ||
| 32 | } | ||
| 33 | // check if source file exists | ||
| 34 | if (!file_exists($argv[1])) { | ||
| 35 | fwrite(STDERR, 'Source file "' . $argv[1] . '" not found' . PHP_EOL); | ||
| 36 | exit(1); | ||
| 37 | } | ||
| 38 | |||
| 39 | try { | ||
| 40 | $minifier = new Minify\JS($argv[1]); | ||
| 41 | echo $minifier->minify(); | ||
| 42 | } catch (Exception $e) { | ||
| 43 | fwrite(STDERR, $e->getMessage(), PHP_EOL); | ||
| 44 | exit(1); | ||
| 45 | } |
File mode changed
File mode changed
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/minify/data/js/keywords_reserved.txt
0 → 100644
| 1 | do | ||
| 2 | if | ||
| 3 | in | ||
| 4 | for | ||
| 5 | let | ||
| 6 | new | ||
| 7 | try | ||
| 8 | var | ||
| 9 | case | ||
| 10 | else | ||
| 11 | enum | ||
| 12 | eval | ||
| 13 | null | ||
| 14 | this | ||
| 15 | true | ||
| 16 | void | ||
| 17 | with | ||
| 18 | break | ||
| 19 | catch | ||
| 20 | class | ||
| 21 | const | ||
| 22 | false | ||
| 23 | super | ||
| 24 | throw | ||
| 25 | while | ||
| 26 | yield | ||
| 27 | delete | ||
| 28 | export | ||
| 29 | import | ||
| 30 | public | ||
| 31 | return | ||
| 32 | static | ||
| 33 | switch | ||
| 34 | typeof | ||
| 35 | default | ||
| 36 | extends | ||
| 37 | finally | ||
| 38 | package | ||
| 39 | private | ||
| 40 | continue | ||
| 41 | debugger | ||
| 42 | function | ||
| 43 | arguments | ||
| 44 | interface | ||
| 45 | protected | ||
| 46 | implements | ||
| 47 | instanceof | ||
| 48 | abstract | ||
| 49 | boolean | ||
| 50 | byte | ||
| 51 | char | ||
| 52 | double | ||
| 53 | final | ||
| 54 | float | ||
| 55 | goto | ||
| 56 | int | ||
| 57 | long | ||
| 58 | native | ||
| 59 | short | ||
| 60 | synchronized | ||
| 61 | throws | ||
| 62 | transient | ||
| 63 | volatile | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 1 | + | ||
| 2 | - | ||
| 3 | * | ||
| 4 | / | ||
| 5 | % | ||
| 6 | = | ||
| 7 | += | ||
| 8 | -= | ||
| 9 | *= | ||
| 10 | /= | ||
| 11 | %= | ||
| 12 | <<= | ||
| 13 | >>= | ||
| 14 | >>>= | ||
| 15 | &= | ||
| 16 | ^= | ||
| 17 | |= | ||
| 18 | & | ||
| 19 | | | ||
| 20 | ^ | ||
| 21 | ~ | ||
| 22 | << | ||
| 23 | >> | ||
| 24 | >>> | ||
| 25 | == | ||
| 26 | === | ||
| 27 | != | ||
| 28 | !== | ||
| 29 | > | ||
| 30 | < | ||
| 31 | >= | ||
| 32 | <= | ||
| 33 | && | ||
| 34 | || | ||
| 35 | ! | ||
| 36 | . | ||
| 37 | [ | ||
| 38 | ] | ||
| 39 | ? | ||
| 40 | : | ||
| 41 | , | ||
| 42 | ; | ||
| 43 | ( | ||
| 44 | ) | ||
| 45 | { | ||
| 46 | } | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
File mode changed
This diff is collapsed.
Click to expand it.
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Base Exception | ||
| 4 | * | ||
| 5 | * @deprecated Use Exceptions\BasicException instead | ||
| 6 | * | ||
| 7 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 8 | */ | ||
| 9 | namespace FVM\MatthiasMullie\Minify; | ||
| 10 | |||
| 11 | /** | ||
| 12 | * Base Exception Class | ||
| 13 | * @deprecated Use Exceptions\BasicException instead | ||
| 14 | * | ||
| 15 | * @package Minify | ||
| 16 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 17 | */ | ||
| 18 | abstract class Exception extends \Exception | ||
| 19 | { | ||
| 20 | } |
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/minify/src/Exceptions/BasicException.php
0 → 100644
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * Basic exception | ||
| 4 | * | ||
| 5 | * Please report bugs on https://github.com/matthiasmullie/minify/issues | ||
| 6 | * | ||
| 7 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 8 | * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved | ||
| 9 | * @license MIT License | ||
| 10 | */ | ||
| 11 | namespace FVM\MatthiasMullie\Minify\Exceptions; | ||
| 12 | |||
| 13 | use FVM\MatthiasMullie\Minify\Exception; | ||
| 14 | |||
| 15 | /** | ||
| 16 | * Basic Exception Class | ||
| 17 | * | ||
| 18 | * @package Minify\Exception | ||
| 19 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 20 | */ | ||
| 21 | abstract class BasicException extends Exception | ||
| 22 | { | ||
| 23 | } |
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * File Import Exception | ||
| 4 | * | ||
| 5 | * Please report bugs on https://github.com/matthiasmullie/minify/issues | ||
| 6 | * | ||
| 7 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 8 | * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved | ||
| 9 | * @license MIT License | ||
| 10 | */ | ||
| 11 | namespace FVM\MatthiasMullie\Minify\Exceptions; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * File Import Exception Class | ||
| 15 | * | ||
| 16 | * @package Minify\Exception | ||
| 17 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 18 | */ | ||
| 19 | class FileImportException extends BasicException | ||
| 20 | { | ||
| 21 | } |
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/minify/src/Exceptions/IOException.php
0 → 100644
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * IO Exception | ||
| 4 | * | ||
| 5 | * Please report bugs on https://github.com/matthiasmullie/minify/issues | ||
| 6 | * | ||
| 7 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 8 | * @copyright Copyright (c) 2012, Matthias Mullie. All rights reserved | ||
| 9 | * @license MIT License | ||
| 10 | */ | ||
| 11 | namespace FVM\MatthiasMullie\Minify\Exceptions; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * IO Exception Class | ||
| 15 | * | ||
| 16 | * @package Minify\Exception | ||
| 17 | * @author Matthias Mullie <minify@mullie.eu> | ||
| 18 | */ | ||
| 19 | class IOException extends BasicException | ||
| 20 | { | ||
| 21 | } |
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/minify/src/Exceptions/index.html
0 → 100644
File mode changed
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
File mode changed
File mode changed
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/path-converter/src/Converter.php
0 → 100644
| 1 | <?php | ||
| 2 | |||
| 3 | namespace FVM\MatthiasMullie\PathConverter; | ||
| 4 | |||
| 5 | /** | ||
| 6 | * Convert paths relative from 1 file to another. | ||
| 7 | * | ||
| 8 | * E.g. | ||
| 9 | * ../../images/icon.jpg relative to /css/imports/icons.css | ||
| 10 | * becomes | ||
| 11 | * ../images/icon.jpg relative to /css/minified.css | ||
| 12 | * | ||
| 13 | * Please report bugs on https://github.com/matthiasmullie/path-converter/issues | ||
| 14 | * | ||
| 15 | * @author Matthias Mullie <pathconverter@mullie.eu> | ||
| 16 | * @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved | ||
| 17 | * @license MIT License | ||
| 18 | */ | ||
| 19 | class Converter implements ConverterInterface | ||
| 20 | { | ||
| 21 | /** | ||
| 22 | * @var string | ||
| 23 | */ | ||
| 24 | protected $from; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * @var string | ||
| 28 | */ | ||
| 29 | protected $to; | ||
| 30 | |||
| 31 | /** | ||
| 32 | * @param string $from The original base path (directory, not file!) | ||
| 33 | * @param string $to The new base path (directory, not file!) | ||
| 34 | * @param string $root Root directory (defaults to `getcwd`) | ||
| 35 | */ | ||
| 36 | public function __construct($from, $to, $root = '') | ||
| 37 | { | ||
| 38 | $shared = $this->shared($from, $to); | ||
| 39 | if ($shared === '') { | ||
| 40 | // when both paths have nothing in common, one of them is probably | ||
| 41 | // absolute while the other is relative | ||
| 42 | $root = $root ?: getcwd(); | ||
| 43 | $from = strpos($from, $root) === 0 ? $from : preg_replace('/\/+/', '/', $root.'/'.$from); | ||
| 44 | $to = strpos($to, $root) === 0 ? $to : preg_replace('/\/+/', '/', $root.'/'.$to); | ||
| 45 | |||
| 46 | // or traveling the tree via `..` | ||
| 47 | // attempt to resolve path, or assume it's fine if it doesn't exist | ||
| 48 | $from = @realpath($from) ?: $from; | ||
| 49 | $to = @realpath($to) ?: $to; | ||
| 50 | } | ||
| 51 | |||
| 52 | $from = $this->dirname($from); | ||
| 53 | $to = $this->dirname($to); | ||
| 54 | |||
| 55 | $from = $this->normalize($from); | ||
| 56 | $to = $this->normalize($to); | ||
| 57 | |||
| 58 | $this->from = $from; | ||
| 59 | $this->to = $to; | ||
| 60 | } | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Normalize path. | ||
| 64 | * | ||
| 65 | * @param string $path | ||
| 66 | * | ||
| 67 | * @return string | ||
| 68 | */ | ||
| 69 | protected function normalize($path) | ||
| 70 | { | ||
| 71 | // deal with different operating systems' directory structure | ||
| 72 | $path = rtrim(str_replace(DIRECTORY_SEPARATOR, '/', $path), '/'); | ||
| 73 | |||
| 74 | /* | ||
| 75 | * Example: | ||
| 76 | * /home/forkcms/frontend/cache/compiled_templates/../../core/layout/css/../images/img.gif | ||
| 77 | * to | ||
| 78 | * /home/forkcms/frontend/core/layout/images/img.gif | ||
| 79 | */ | ||
| 80 | do { | ||
| 81 | $path = preg_replace('/[^\/]+(?<!\.\.)\/\.\.\//', '', $path, -1, $count); | ||
| 82 | } while ($count); | ||
| 83 | |||
| 84 | return $path; | ||
| 85 | } | ||
| 86 | |||
| 87 | /** | ||
| 88 | * Figure out the shared path of 2 locations. | ||
| 89 | * | ||
| 90 | * Example: | ||
| 91 | * /home/forkcms/frontend/core/layout/images/img.gif | ||
| 92 | * and | ||
| 93 | * /home/forkcms/frontend/cache/minified_css | ||
| 94 | * share | ||
| 95 | * /home/forkcms/frontend | ||
| 96 | * | ||
| 97 | * @param string $path1 | ||
| 98 | * @param string $path2 | ||
| 99 | * | ||
| 100 | * @return string | ||
| 101 | */ | ||
| 102 | protected function shared($path1, $path2) | ||
| 103 | { | ||
| 104 | // $path could theoretically be empty (e.g. no path is given), in which | ||
| 105 | // case it shouldn't expand to array(''), which would compare to one's | ||
| 106 | // root / | ||
| 107 | $path1 = $path1 ? explode('/', $path1) : array(); | ||
| 108 | $path2 = $path2 ? explode('/', $path2) : array(); | ||
| 109 | |||
| 110 | $shared = array(); | ||
| 111 | |||
| 112 | // compare paths & strip identical ancestors | ||
| 113 | foreach ($path1 as $i => $chunk) { | ||
| 114 | if (isset($path2[$i]) && $path1[$i] == $path2[$i]) { | ||
| 115 | $shared[] = $chunk; | ||
| 116 | } else { | ||
| 117 | break; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | return implode('/', $shared); | ||
| 122 | } | ||
| 123 | |||
| 124 | /** | ||
| 125 | * Convert paths relative from 1 file to another. | ||
| 126 | * | ||
| 127 | * E.g. | ||
| 128 | * ../images/img.gif relative to /home/forkcms/frontend/core/layout/css | ||
| 129 | * should become: | ||
| 130 | * ../../core/layout/images/img.gif relative to | ||
| 131 | * /home/forkcms/frontend/cache/minified_css | ||
| 132 | * | ||
| 133 | * @param string $path The relative path that needs to be converted | ||
| 134 | * | ||
| 135 | * @return string The new relative path | ||
| 136 | */ | ||
| 137 | public function convert($path) | ||
| 138 | { | ||
| 139 | // quit early if conversion makes no sense | ||
| 140 | if ($this->from === $this->to) { | ||
| 141 | return $path; | ||
| 142 | } | ||
| 143 | |||
| 144 | $path = $this->normalize($path); | ||
| 145 | // if we're not dealing with a relative path, just return absolute | ||
| 146 | if (strpos($path, '/') === 0) { | ||
| 147 | return $path; | ||
| 148 | } | ||
| 149 | |||
| 150 | // normalize paths | ||
| 151 | $path = $this->normalize($this->from.'/'.$path); | ||
| 152 | |||
| 153 | // strip shared ancestor paths | ||
| 154 | $shared = $this->shared($path, $this->to); | ||
| 155 | $path = mb_substr($path, mb_strlen($shared)); | ||
| 156 | $to = mb_substr($this->to, mb_strlen($shared)); | ||
| 157 | |||
| 158 | // add .. for every directory that needs to be traversed to new path | ||
| 159 | $to = str_repeat('../', count(array_filter(explode('/', $to)))); | ||
| 160 | |||
| 161 | return $to.ltrim($path, '/'); | ||
| 162 | } | ||
| 163 | |||
| 164 | /** | ||
| 165 | * Attempt to get the directory name from a path. | ||
| 166 | * | ||
| 167 | * @param string $path | ||
| 168 | * | ||
| 169 | * @return string | ||
| 170 | */ | ||
| 171 | protected function dirname($path) | ||
| 172 | { | ||
| 173 | if (@is_file($path)) { | ||
| 174 | return dirname($path); | ||
| 175 | } | ||
| 176 | |||
| 177 | if (@is_dir($path)) { | ||
| 178 | return rtrim($path, '/'); | ||
| 179 | } | ||
| 180 | |||
| 181 | // no known file/dir, start making assumptions | ||
| 182 | |||
| 183 | // ends in / = dir | ||
| 184 | if (mb_substr($path, -1) === '/') { | ||
| 185 | return rtrim($path, '/'); | ||
| 186 | } | ||
| 187 | |||
| 188 | // has a dot in the name, likely a file | ||
| 189 | if (preg_match('/.*\..*$/', basename($path)) !== 0) { | ||
| 190 | return dirname($path); | ||
| 191 | } | ||
| 192 | |||
| 193 | // you're on your own here! | ||
| 194 | return $path; | ||
| 195 | } | ||
| 196 | } |
| 1 | <?php | ||
| 2 | |||
| 3 | namespace FVM\MatthiasMullie\PathConverter; | ||
| 4 | |||
| 5 | /** | ||
| 6 | * Convert file paths. | ||
| 7 | * | ||
| 8 | * Please report bugs on https://github.com/matthiasmullie/path-converter/issues | ||
| 9 | * | ||
| 10 | * @author Matthias Mullie <pathconverter@mullie.eu> | ||
| 11 | * @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved | ||
| 12 | * @license MIT License | ||
| 13 | */ | ||
| 14 | interface ConverterInterface | ||
| 15 | { | ||
| 16 | /** | ||
| 17 | * Convert file paths. | ||
| 18 | * | ||
| 19 | * @param string $path The path to be converted | ||
| 20 | * | ||
| 21 | * @return string The new path | ||
| 22 | */ | ||
| 23 | public function convert($path); | ||
| 24 | } |
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/path-converter/src/NoConverter.php
0 → 100644
| 1 | <?php | ||
| 2 | |||
| 3 | namespace FVM\MatthiasMullie\PathConverter; | ||
| 4 | |||
| 5 | /** | ||
| 6 | * Don't convert paths. | ||
| 7 | * | ||
| 8 | * Please report bugs on https://github.com/matthiasmullie/path-converter/issues | ||
| 9 | * | ||
| 10 | * @author Matthias Mullie <pathconverter@mullie.eu> | ||
| 11 | * @copyright Copyright (c) 2015, Matthias Mullie. All rights reserved | ||
| 12 | * @license MIT License | ||
| 13 | */ | ||
| 14 | class NoConverter implements ConverterInterface | ||
| 15 | { | ||
| 16 | /** | ||
| 17 | * {@inheritdoc} | ||
| 18 | */ | ||
| 19 | public function convert($path) | ||
| 20 | { | ||
| 21 | return $path; | ||
| 22 | } | ||
| 23 | } |
wp-content/plugins/fast-velocity-minify/libs/matthiasmullie/path-converter/src/index.html
0 → 100644
File mode changed
File mode changed
| 1 | <?php | ||
| 2 | /** | ||
| 3 | * | ||
| 4 | * Website: https://wpraiser.com/ | ||
| 5 | * Author: Raul Peixoto (https://www.upwork.com/fl/raulpeixoto) | ||
| 6 | * Licensed under GPLv2 (or later) | ||
| 7 | * Version 1.0 | ||
| 8 | * | ||
| 9 | * Usage: fvm_raisermin_js($js); | ||
| 10 | * | ||
| 11 | */ | ||
| 12 | |||
| 13 | # Exit if accessed directly | ||
| 14 | if (!defined('ABSPATH')){ exit(); } | ||
| 15 | |||
| 16 | # minify js, whitespace only | ||
| 17 | function fvm_raisermin_js($code){ | ||
| 18 | |||
| 19 | # remove // comments | ||
| 20 | $code = preg_replace('/(^|\s)\/\/(.*)\n/m', '', $code); | ||
| 21 | $code = preg_replace('/(\{|\}|\[|\]|\(|\)|\;)\/\/(.*)\n/m', '$1', $code); | ||
| 22 | |||
| 23 | # remove /* ... */ comments | ||
| 24 | $code = preg_replace('/(^|\s)\/\*(.*)\*\//Us', '', $code); | ||
| 25 | $code = preg_replace('/(\;|\{)\/\*(.*)\*\//Us', '$1', $code); | ||
| 26 | |||
| 27 | # remove sourceMappingURL | ||
| 28 | $code = preg_replace('/(\/\/\s*[#]\s*sourceMappingURL\s*[=]\s*)([a-zA-Z0-9-_\.\/]+)(\.map)/ui', '', $code); | ||
| 29 | |||
| 30 | # uniform line endings, make them all line feed | ||
| 31 | $code = str_replace(array("\r\n", "\r"), "\n", $code); | ||
| 32 | |||
| 33 | # collapse all non-line feed whitespace into a single space | ||
| 34 | $code = preg_replace('/[^\S\n]+/', ' ', $code); | ||
| 35 | |||
| 36 | # strip leading & trailing whitespace | ||
| 37 | $code = str_replace(array(" \n", "\n "), "\n", $code); | ||
| 38 | |||
| 39 | # collapse consecutive line feeds into just 1 | ||
| 40 | $code = preg_replace('/\n+/', "\n", $code); | ||
| 41 | |||
| 42 | # process horizontal space | ||
| 43 | $code = preg_replace('/([\[\]\(\)\{\}\;\<\>])(\h+)([\[\]\(\)\{\}\;\<\>])/ui', '$1 $3', $code); | ||
| 44 | $code = preg_replace('/([\)])(\h?)(\.)/ui', '$1$3', $code); | ||
| 45 | $code = preg_replace('/([\)\?])(\h?)(\.)/ui', '$1$3', $code); | ||
| 46 | $code = preg_replace('/(\,)(\h+)/ui', '$1 ', $code); | ||
| 47 | $code = preg_replace('/(\h+)(\,)/ui', ' $2', $code); | ||
| 48 | $code = preg_replace('/([if])(\h+)(\()/ui', '$1$3', $code); | ||
| 49 | |||
| 50 | # trim whitespace on beginning/end | ||
| 51 | return trim($code); | ||
| 52 | } | ||
| 53 | |||
| 54 | |||
| 55 | # remove UTF8 BOM | ||
| 56 | function fvm_min_remove_utf8_bom($text) { | ||
| 57 | $bom = pack('H*','EFBBBF'); | ||
| 58 | while (preg_match("/^$bom/", $text)) { | ||
| 59 | $text = preg_replace("/^$bom/ui", '', $text); | ||
| 60 | } | ||
| 61 | return $text; | ||
| 62 | } | ||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | |||
| 67 | # minify html, don't touch certain tags | ||
| 68 | function fvm_raisermin_html($html) { | ||
| 69 | |||
| 70 | # clone | ||
| 71 | $content = $html; | ||
| 72 | |||
| 73 | # get all scripts | ||
| 74 | $skp = array(); | ||
| 75 | preg_match_all('/(\<script(.*?)\<(\s*)\/script(\s*)\>|\<noscript(.*?)\<(\s*)\/noscript(\s*)\>|\<code(.*?)\<(\s*)\/code(\s*)\>|\<pre(.*?)\<(\s*)\/pre(\s*)\>)/uis', $html, $skp); | ||
| 76 | |||
| 77 | # replace all skippable patterns with comment | ||
| 78 | if(is_array($skp) && isset($skp[0]) && count($skp[0]) > 0) { | ||
| 79 | foreach ($skp[0] as $k=>$v) { | ||
| 80 | $content = str_replace($v, '<!-- SKIP '.$k.' -->', $content); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | # remove line breaks, and colapse two or more white spaces into one | ||
| 85 | $content = preg_replace('/\s+/u', " ", $content); | ||
| 86 | |||
| 87 | # add linebreaks after html and head tags, for readability | ||
| 88 | $content = str_replace('<head>', PHP_EOL . '<head>' . PHP_EOL, $content); | ||
| 89 | $content = str_replace('</head>', PHP_EOL . '</head>' . PHP_EOL, $content); | ||
| 90 | $content = str_replace('<html', PHP_EOL . '<html', $content); | ||
| 91 | $content = str_replace('</html>', PHP_EOL . '</html>', $content); | ||
| 92 | |||
| 93 | # final readability adjustments | ||
| 94 | $content = str_replace('<meta ', PHP_EOL . '<meta ', $content); | ||
| 95 | $content = str_replace('<link ', PHP_EOL . '<link ', $content); | ||
| 96 | $content = str_replace('<style', PHP_EOL . '<style', $content); | ||
| 97 | $content = str_replace('<noscript', PHP_EOL . '<noscript>', $content); | ||
| 98 | |||
| 99 | # replace markers for scripts last | ||
| 100 | if(is_array($skp) && isset($skp[0]) && count($skp[0]) > 0) { | ||
| 101 | foreach ($skp[0] as $k=>$v) { | ||
| 102 | $content = str_replace('<!-- SKIP '.$k.' -->', PHP_EOL . $v . PHP_EOL, $content); | ||
| 103 | } | ||
| 104 | } | ||
| 105 | |||
| 106 | # no empty lines | ||
| 107 | $lines = explode(PHP_EOL, $content); | ||
| 108 | foreach($lines as $k=>$ln) { $ln = ltrim($ln); if(empty($ln)) { unset($lines[$k]); } else { $lines[$k] = $ln; } } | ||
| 109 | $content = implode(PHP_EOL, $lines); | ||
| 110 | |||
| 111 | # save as html, if not empty | ||
| 112 | if(!empty($content)) { | ||
| 113 | $html = $content; | ||
| 114 | } | ||
| 115 | |||
| 116 | # return | ||
| 117 | return $html; | ||
| 118 | } |
File mode changed
This diff is collapsed.
Click to expand it.
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment