Plugin Directory

Changeset 2224916


Ignore:
Timestamp:
01/09/2020 03:44:16 PM (6 years ago)
Author:
vozubko
Message:

Added switch for Lazy Load. Minor fixes.

Location:
essential-performance/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • essential-performance/trunk/plugin.php

    r2224434 r2224916  
    1414 * Plugin Name:       Essential Performance
    1515 * Description:       Essential Performance plugin for Wordpress.
    16  * Version:           0.0.2
     16 * Version:           0.0.3
    1717 * Requires at least: 5.2
    1818 * Requires PHP:      7.0
  • essential-performance/trunk/readme.txt

    r2224434 r2224916  
    2424
    2525*   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.
    2627
    2728
     
    4647== Changelog ==
    4748
    48 = 0.0.1 =
    49 * Initial plugin
     49= 0.0.3 =
     50Added switch for Lazy Load.
     51Minor fixes.
    5052
    5153= 0.0.2 =
    5254* Added Leverage browser caching for static files
    5355
     56= 0.0.1 =
     57* Initial plugin
     58
    5459== Upgrade Notice ==
    5560....
  • essential-performance/trunk/src/application/Config/Config.php

    r2224434 r2224916  
    2222class Config
    2323{
    24     public $version = '0.0.1';
     24    public $version = '0.0.3';
    2525
    2626    public $textDomain = 'essential-performance';
     27
     28    public $options = [
     29        'lazy_load'       => 0,
     30        'browser_caching' => 0,
     31    ];
    2732
    2833    public $actions = [];
     
    3237    public function __construct()
    3338    {
     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
    3449        $this->actions[] = [
    3550            'name'     => 'wp_enqueue_scripts',
     
    4863        ];
    4964
    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        }
    5876
    5977
  • essential-performance/trunk/src/application/Controller/BackendController.php

    r2224434 r2224916  
    4141    {
    4242        $this->registerSettings();
    43 
    44         // Set class property
    45         $this->options = get_option('essential_settings');
    4643    }
    4744
     
    6966    public function settingsPageCallback()
    7067    {
    71         var_dump($this->options);
    7268        echo $this->load->view('Backend/settings_page', []);
    7369    }
     
    8682        add_settings_section(
    8783            $this->Config->textDomain . '_setting_section',
    88             __('Leverage Browser Caching for Images, CSS and JS', $this->Config->textDomain),
     84            __('General Settings', $this->Config->textDomain),
    8985            [$this, 'sectionInfoCallback'],
    9086            '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'
    9195        );
    9296
     
    105109    public function sectionInfoCallback()
    106110    {
    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>';
    109124    }
    110125
     
    114129    public function leverageBrowserCachingCallback()
    115130    {
    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>';
    118137    }
    119138
     
    129148        $inputSanitized = [];
    130149
    131         $this->load->model('Apache');
     150        $this->load->model('ApacheModel');
    132151        $this->ApacheModel->read();
    133152
     
    135154            $inputSanitized['browser_caching'] = 1;
    136155
    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();
    139158            }
    140159        } else {
    141160            $inputSanitized['browser_caching'] = 0;
    142161
    143             if (($this->options['browser_caching'] === 1) && $this->ApacheModel->deleteRule('EssentialPerformanceExpires')) {
     162            if (($this->Config->options['browser_caching'] === 1) && $this->ApacheModel->deleteRule('EssentialPerformanceExpires')) {
    144163                $this->ApacheModel->write();
    145164            }
     165        }
     166
     167        if (isset($input['lazy_load'])) {
     168            $inputSanitized['lazy_load'] = 1;
     169        } else {
     170            $inputSanitized['lazy_load'] = 0;
    146171        }
    147172
  • essential-performance/trunk/src/application/Controller/FrontendController.php

    r2205843 r2224916  
    2020
    2121
     22use EssentialPerformance\Config\Config;
    2223use EssentialPerformanceFramework\Core\Controller;
    2324use EssentialPerformanceFramework\Core\InitInterface;
    2425
     26/**
     27 * Class FrontendController
     28 * @package EssentialPerformance\Controller
     29 * @property Config $Config
     30 */
    2531class FrontendController extends Controller implements InitInterface
    2632{
     
    3137    public function addEnqueueScripts()
    3238    {
    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        }
    3543    }
    3644
  • essential-performance/trunk/src/application/Model/ApacheModel.php

    r2224434 r2224916  
    9191    public function getExpires()
    9292    {
    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" .
    104104
    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" .
    107107
    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" .
    110110
    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" .
    114114
    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" .
    122122
    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" .
    125125
    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";
    132132    }
    133133
     
    163163    {
    164164        $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';
    166166        $this->content = preg_replace($pattern, '', $this->content, -1, $count);
    167167
Note: See TracChangeset for help on using the changeset viewer.