Changeset 2224916
- Timestamp:
- 01/09/2020 03:44:16 PM (6 years ago)
- Location:
- essential-performance/trunk
- Files:
-
- 6 edited
-
plugin.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
src/application/Config/Config.php (modified) (3 diffs)
-
src/application/Controller/BackendController.php (modified) (7 diffs)
-
src/application/Controller/FrontendController.php (modified) (2 diffs)
-
src/application/Model/ApacheModel.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
essential-performance/trunk/plugin.php
r2224434 r2224916 14 14 * Plugin Name: Essential Performance 15 15 * Description: Essential Performance plugin for Wordpress. 16 * Version: 0.0. 216 * Version: 0.0.3 17 17 * Requires at least: 5.2 18 18 * Requires PHP: 7.0 -
essential-performance/trunk/readme.txt
r2224434 r2224916 24 24 25 25 * Lazy Load - is a smart technique which reduces the page load time. 26 * Leverage Browser Caching - To leverage your browser's caching generally means that you can specify how long web browsers should keep images, CSS and JS stored locally. 26 27 27 28 … … 46 47 == Changelog == 47 48 48 = 0.0.1 = 49 * Initial plugin 49 = 0.0.3 = 50 Added switch for Lazy Load. 51 Minor fixes. 50 52 51 53 = 0.0.2 = 52 54 * Added Leverage browser caching for static files 53 55 56 = 0.0.1 = 57 * Initial plugin 58 54 59 == Upgrade Notice == 55 60 .... -
essential-performance/trunk/src/application/Config/Config.php
r2224434 r2224916 22 22 class Config 23 23 { 24 public $version = '0.0. 1';24 public $version = '0.0.3'; 25 25 26 26 public $textDomain = 'essential-performance'; 27 28 public $options = [ 29 'lazy_load' => 0, 30 'browser_caching' => 0, 31 ]; 27 32 28 33 public $actions = []; … … 32 37 public function __construct() 33 38 { 39 // Load options 40 $options = get_option('essential_settings'); 41 42 if (is_array($options)) { 43 foreach ($options as $key => $value) { 44 $this->options[$key] = $value; 45 } 46 } 47 48 34 49 $this->actions[] = [ 35 50 'name' => 'wp_enqueue_scripts', … … 48 63 ]; 49 64 50 $this->filters[] = [ 51 'name' => 'the_content', 52 'callback' => [ 53 'controller' => 'LazyLoadController', 54 'action' => 'updateContentImages' 55 ], 56 'priority' => 100, 57 ]; 65 66 if ($this->options['lazy_load'] === 1) { 67 $this->filters[] = [ 68 'name' => 'the_content', 69 'callback' => [ 70 'controller' => 'LazyLoadController', 71 'action' => 'updateContentImages' 72 ], 73 'priority' => 100, 74 ]; 75 } 58 76 59 77 -
essential-performance/trunk/src/application/Controller/BackendController.php
r2224434 r2224916 41 41 { 42 42 $this->registerSettings(); 43 44 // Set class property45 $this->options = get_option('essential_settings');46 43 } 47 44 … … 69 66 public function settingsPageCallback() 70 67 { 71 var_dump($this->options);72 68 echo $this->load->view('Backend/settings_page', []); 73 69 } … … 86 82 add_settings_section( 87 83 $this->Config->textDomain . '_setting_section', 88 __(' Leverage Browser Caching for Images, CSS and JS', $this->Config->textDomain),84 __('General Settings', $this->Config->textDomain), 89 85 [$this, 'sectionInfoCallback'], 90 86 'essential_settings' 87 ); 88 89 add_settings_field( 90 'essential_settings_lazy_load', 91 __('Lazy Load', $this->Config->textDomain), 92 [$this, 'lazyLoadCallback'], 93 'essential_settings', 94 $this->Config->textDomain . '_setting_section' 91 95 ); 92 96 … … 105 109 public function sectionInfoCallback() 106 110 { 107 _e('To leverage your browser\'s caching generally means that you can specify how long web browsers should keep images, CSS and JS stored locally. ' . 108 'That way the user\'s browser will download less data while navigating through your pages, which will improve the loading speed of your website.', $this->Config->textDomain); 111 _e('Turn features On or Off', $this->Config->textDomain); 112 } 113 114 /** 115 * Print the Field html 116 */ 117 public function lazyLoadCallback() 118 { 119 $checked = $this->Config->options['lazy_load'] ? 'checked' : ''; 120 echo '<label><input id="essential_settings_lazy_load" name="essential_settings[lazy_load]" type="checkbox" value="1" ' . $checked . ' />' . __('Use Lazy Load', $this->Config->textDomain) . '</label>'; 121 echo '<p class="description">'; 122 _e('Lazy Load images when they enter the browsers viewport', $this->Config->textDomain); 123 echo '</p>'; 109 124 } 110 125 … … 114 129 public function leverageBrowserCachingCallback() 115 130 { 116 $checked = $this->options['browser_caching'] ? 'checked' : ''; 117 echo '<input id="essential_settings_browser_caching" name="essential_settings[browser_caching]" type="checkbox" value="1" ' . $checked . ' />'; 131 $checked = $this->Config->options['browser_caching'] ? 'checked' : ''; 132 echo '<label><input id="essential_settings_browser_caching" name="essential_settings[browser_caching]" type="checkbox" value="1" ' . $checked . ' />' . __('Add caching for Images, CSS and JS', $this->Config->textDomain) . '</label>'; 133 echo '<p class="description">'; 134 _e('To leverage your browser\'s caching generally means that you can specify how long web browsers should keep images, CSS and JS stored locally.<br>' . 135 'That way the user\'s browser will download less data while navigating through your pages, which will improve the loading speed of your website.', $this->Config->textDomain); 136 echo '</p>'; 118 137 } 119 138 … … 129 148 $inputSanitized = []; 130 149 131 $this->load->model('Apache ');150 $this->load->model('ApacheModel'); 132 151 $this->ApacheModel->read(); 133 152 … … 135 154 $inputSanitized['browser_caching'] = 1; 136 155 137 if (($this-> options['browser_caching'] === 0) && $this->Apache->addRule('EssentialPerformanceExpires', $this->Apache->getExpires())) {138 $this->Apache ->write();156 if (($this->Config->options['browser_caching'] === 0) && $this->ApacheModel->addRule('EssentialPerformanceExpires', $this->ApacheModel->getExpires())) { 157 $this->ApacheModel->write(); 139 158 } 140 159 } else { 141 160 $inputSanitized['browser_caching'] = 0; 142 161 143 if (($this-> options['browser_caching'] === 1) && $this->ApacheModel->deleteRule('EssentialPerformanceExpires')) {162 if (($this->Config->options['browser_caching'] === 1) && $this->ApacheModel->deleteRule('EssentialPerformanceExpires')) { 144 163 $this->ApacheModel->write(); 145 164 } 165 } 166 167 if (isset($input['lazy_load'])) { 168 $inputSanitized['lazy_load'] = 1; 169 } else { 170 $inputSanitized['lazy_load'] = 0; 146 171 } 147 172 -
essential-performance/trunk/src/application/Controller/FrontendController.php
r2205843 r2224916 20 20 21 21 22 use EssentialPerformance\Config\Config; 22 23 use EssentialPerformanceFramework\Core\Controller; 23 24 use EssentialPerformanceFramework\Core\InitInterface; 24 25 26 /** 27 * Class FrontendController 28 * @package EssentialPerformance\Controller 29 * @property Config $Config 30 */ 25 31 class FrontendController extends Controller implements InitInterface 26 32 { … … 31 37 public function addEnqueueScripts() 32 38 { 33 wp_enqueue_script('essential-lazy-load', $this->appURL . 'assets/js/lazyload/lazyload.min.js', [], '2.0.0-rc.2', true); 34 wp_enqueue_script('essential-main', $this->appURL . 'assets/js/main.js', ['jquery', 'essential-lazy-load'], $this->Config->version, true); 39 if ($this->Config->options['lazy_load'] === 1) { 40 wp_enqueue_script('essential-lazy-load', $this->appURL . 'assets/js/lazyload/lazyload.min.js', [], '2.0.0-rc.2', true); 41 wp_enqueue_script('essential-main', $this->appURL . 'assets/js/main.js', ['jquery', 'essential-lazy-load'], $this->Config->version, true); 42 } 35 43 } 36 44 -
essential-performance/trunk/src/application/Model/ApacheModel.php
r2224434 r2224916 91 91 public function getExpires() 92 92 { 93 return '# BEGIN EssentialPerformanceExpires ' . PHP_EOL.94 '<FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|js|css|webm|mp4|ogg|ico|pdf|woff|woff2|otf|ttf|eot|x-html|xml|flv|swf)(\.gz)?$">' . PHP_EOL.95 '<IfModule mod_headers.c>' . PHP_EOL.96 'Header set Expires "max-age=A31536000, public"' . PHP_EOL.97 'Header set Connection keep-alive' . PHP_EOL.98 'Header unset ETag' . PHP_EOL.99 'FileETag None' . PHP_EOL.100 '</IfModule>' . PHP_EOL.101 '<IfModule mod_expires.c>' . PHP_EOL.102 'ExpiresActive On' . PHP_EOL.103 'ExpiresDefault A0' . PHP_EOL.93 return '# BEGIN EssentialPerformanceExpires\n' . "\n" . 94 '<FilesMatch "\.(jpg|jpeg|png|gif|webp|svg|js|css|webm|mp4|ogg|ico|pdf|woff|woff2|otf|ttf|eot|x-html|xml|flv|swf)(\.gz)?$">' . "\n" . 95 '<IfModule mod_headers.c>' . "\n" . 96 'Header set Expires "max-age=A31536000, public"' . "\n" . 97 'Header set Connection keep-alive' . "\n" . 98 'Header unset ETag' . "\n" . 99 'FileETag None' . "\n" . 100 '</IfModule>' . "\n" . 101 '<IfModule mod_expires.c>' . "\n" . 102 'ExpiresActive On' . "\n" . 103 'ExpiresDefault A0' . "\n" . 104 104 105 'AddType application/font-woff2 .woff2' . PHP_EOL.106 'AddType application/x-font-opentype .otf' . PHP_EOL.105 'AddType application/font-woff2 .woff2' . "\n" . 106 'AddType application/x-font-opentype .otf' . "\n" . 107 107 108 'ExpiresByType application/javascript A31536000' . PHP_EOL.109 'ExpiresByType application/x-javascript A31536000' . PHP_EOL.108 'ExpiresByType application/javascript A31536000' . "\n" . 109 'ExpiresByType application/x-javascript A31536000' . "\n" . 110 110 111 'ExpiresByType application/font-woff2 A31536000' . PHP_EOL.112 'ExpiresByType application/x-font-opentype A31536000' . PHP_EOL.113 'ExpiresByType application/x-font-truetype A31536000' . PHP_EOL.111 'ExpiresByType application/font-woff2 A31536000' . "\n" . 112 'ExpiresByType application/x-font-opentype A31536000' . "\n" . 113 'ExpiresByType application/x-font-truetype A31536000' . "\n" . 114 114 115 'ExpiresByType image/png A31536000' . PHP_EOL.116 'ExpiresByType image/jpg A31536000' . PHP_EOL.117 'ExpiresByType image/jpeg A31536000' . PHP_EOL.118 'ExpiresByType image/gif A31536000' . PHP_EOL.119 'ExpiresByType image/webp A31536000' . PHP_EOL.120 'ExpiresByType image/ico A31536000' . PHP_EOL.121 'ExpiresByType image/svg+xml A31536000' . PHP_EOL.115 'ExpiresByType image/png A31536000' . "\n" . 116 'ExpiresByType image/jpg A31536000' . "\n" . 117 'ExpiresByType image/jpeg A31536000' . "\n" . 118 'ExpiresByType image/gif A31536000' . "\n" . 119 'ExpiresByType image/webp A31536000' . "\n" . 120 'ExpiresByType image/ico A31536000' . "\n" . 121 'ExpiresByType image/svg+xml A31536000' . "\n" . 122 122 123 'ExpiresByType text/css A31536000' . PHP_EOL.124 'ExpiresByType text/javascript A31536000' . PHP_EOL.123 'ExpiresByType text/css A31536000' . "\n" . 124 'ExpiresByType text/javascript A31536000' . "\n" . 125 125 126 'ExpiresByType video/ogg A31536000' . PHP_EOL.127 'ExpiresByType video/mp4 A31536000' . PHP_EOL.128 'ExpiresByType video/webm A31536000' . PHP_EOL.129 '</IfModule>' . PHP_EOL.130 '</FilesMatch>' . PHP_EOL.131 '# END EssentialPerformanceExpires' . PHP_EOL;126 'ExpiresByType video/ogg A31536000' . "\n" . 127 'ExpiresByType video/mp4 A31536000' . "\n" . 128 'ExpiresByType video/webm A31536000' . "\n" . 129 '</IfModule>' . "\n" . 130 '</FilesMatch>' . "\n" . 131 '# END EssentialPerformanceExpires' . "\n"; 132 132 } 133 133 … … 163 163 { 164 164 $count = 0; 165 $pattern = '/#\s?BEGIN\s?' . $marker . '.*?#\s?END\s?' . $marker . ' /s';165 $pattern = '/#\s?BEGIN\s?' . $marker . '.*?#\s?END\s?' . $marker . '\n/s'; 166 166 $this->content = preg_replace($pattern, '', $this->content, -1, $count); 167 167
Note: See TracChangeset
for help on using the changeset viewer.