Plugin Directory

Changeset 2154691


Ignore:
Timestamp:
09/11/2019 09:50:34 AM (6 years ago)
Author:
runcloud
Message:

added dropin

Location:
runcache-purger/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • runcache-purger/trunk/assets/runcache_purger.css

    r2154386 r2154691  
    3838#runcachepurger-wrap h1,
    3939#runcachepurger-wrap h2,
    40 #runcachepurger-wrap h3 {
     40#runcachepurger-wrap h3,
     41#runcachepurger-wrap h4 {
    4142    color: currentColor;
    4243    margin: 0;
     
    494495}
    495496
     497#runcachepurger-wrap .runcachepurger-field-children {
     498    padding-left: 32px;
     499}
     500
     501#runcachepurger-wrap input[type=text],
     502#runcachepurger-wrap input[type=number] {
     503    margin-top: 8px;
     504    padding: 0 8px;
     505    width: 100%;
     506    height: 32px;
     507    color: #23282d;
     508    background: #fff;
     509    border: 2px solid #c2cad4;
     510    border-radius: 3px;
     511    font-family: monospace, monaco, Consolas, Lucida Console;
     512    font-size: 12px;
     513    font-size: .75rem;
     514    line-height: 1.33333;
     515    transition: border 200ms ease-out;
     516    -webkit-transition: border 200ms ease-out;
     517}
     518
     519#runcachepurger-wrap input[type=text]:focus,
     520#runcachepurger-wrap input[type=number]:focus {
     521    outline: none;
     522    border-color: #34373a;
     523    -moz-box-shadow: none;
     524    -webkit-box-shadow: none;
     525    box-shadow: none;
     526}
     527
     528#runcachepurger-wrap .cache-redis {
     529    padding-left: 32px;
     530}
     531
     532#runcachepurger-wrap .cache-redis > h4 {
     533    margin-bottom: 5px;
     534    font-size: 14px;
     535    font-weight: 500;
     536}
     537
     538#runcachepurger-wrap .cache-redis > label {
     539    display: inline-block;
     540    width: 120px;
     541    color: #72777c;
     542}
     543
     544#runcachepurger-wrap .cache-redis > input {
     545    display: inline-block;
     546    width: 60%;
     547}
     548
     549@media (max-width: 783px) {
     550    #runcachepurger-wrap .cache-redis > label {
     551        display: block;
     552        width: 100%;
     553    }
     554
     555    #runcachepurger-wrap .cache-redis > input {
     556        display: block;
     557        width: 100%;
     558    }
     559}
     560
    496561.update-nag {
    497562    display: none;
  • runcache-purger/trunk/languages/runcachepurger.pot

    r2154386 r2154691  
    55msgstr  "Project-Id-Version: RunCache Purger 1.0.0\n"
    66        "Report-Msgid-Bugs-To: https://runcloud.io\n"
    7         "POT-Creation-Date: 2019-09-11 01:49+0800\n"
     7        "POT-Creation-Date: 2019-09-11 17:47+0800\n"
    88        "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
    99        "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
     
    1414        "Content-Transfer-Encoding: 8bit\n"
    1515
    16 #: runcache-purger.php:270
     16#: runcache-purger.php:253
    1717#, php-format
    1818msgid   "The <strong>%1$s</strong> plugin version %2$s requires:"
    1919msgstr  ""
    2020
     21#: runcache-purger.php:264
     22#, php-format
     23msgid   "WordPress version %s or higher."
     24msgstr  ""
     25
     26#: runcache-purger.php:273
     27#, php-format
     28msgid   "PHP version %s or higher."
     29msgstr  ""
     30
    2131#: runcache-purger.php:281
    22 #, php-format
    23 msgid   "WordPress version %s or higher."
    24 msgstr  ""
    25 
    26 #: runcache-purger.php:290
    27 #, php-format
    28 msgid   "PHP version %s or higher."
    29 msgstr  ""
    30 
    31 #: runcache-purger.php:298
    3232msgid   "Apache or NGINX Web Server."
    3333msgstr  ""
    3434
    35 #: runcache-purger.php:304
     35#: runcache-purger.php:287
    3636msgid   "The plugin has now deactivated itself. Please contact your hosting "
    3737        "provider or system administrator for version upgrade."
    3838msgstr  ""
    3939
    40 #: runcache-purger.php:469 runcache-purger.php:578
     40#: runcache-purger.php:506 runcache-purger.php:625
    4141msgid   "Settings"
    4242msgstr  ""
    4343
    44 #: runcache-purger.php:593
     44#: runcache-purger.php:640
    4545msgid   "Clear Cache this Post"
    4646msgstr  ""
    4747
    48 #: runcache-purger.php:604
     48#: runcache-purger.php:651
    4949msgid   "Clear Cache this URL"
    5050msgstr  ""
    5151
    52 #: runcache-purger.php:614 views/settings.php:168
     52#: runcache-purger.php:661 views/settings.php:191
    5353msgid   "Clear All Cache"
    5454msgstr  ""
    5555
    56 #: runcache-purger.php:1033
     56#: runcache-purger.php:1086
    5757msgid   "Failed to purge cache."
    5858msgstr  ""
    5959
    60 #: runcache-purger.php:1040
     60#: runcache-purger.php:1093
    6161msgid   "Purging cache was successful."
    6262msgstr  ""
    6363
    64 #: runcache-purger.php:1042
     64#: runcache-purger.php:1095
    6565msgid   "Purging redis object cache was successful."
    6666msgstr  ""
    6767
    68 #: runcache-purger.php:1047
     68#: runcache-purger.php:1100
    6969#, php-format
    7070msgid   "Purging method not implement. Status Code %s"
    7171msgstr  ""
    7272
    73 #: runcache-purger.php:1051
     73#: runcache-purger.php:1104
    7474msgid   "Failed to purge redis object cache."
    7575msgstr  ""
    7676
    77 #: runcache-purger.php:1053
    78 msgid   "Purging method not implement. Redis WP Object Cache Plugin not "
    79         "available"
    80 msgstr  ""
    81 
    82 #: runcache-purger.php:1058
     77#: runcache-purger.php:1106
     78msgid   "Purging method not implement."
     79msgstr  ""
     80
     81#: runcache-purger.php:1111
    8382#, php-format
    8483msgid   "Failed to purge cache. Status Code %s"
     
    175174msgstr  ""
    176175
    177 #: views/settings.php:163
     176#: views/settings.php:156
     177msgid   "Enable Object Cache"
     178msgstr  ""
     179
     180#: views/settings.php:160
     181msgid   "Enable this option to allow this plugin handle redis object cache."
     182msgstr  ""
     183
     184#: views/settings.php:166
     185msgid   "Hostname"
     186msgstr  ""
     187
     188#: views/settings.php:169
     189msgid   "Port"
     190msgstr  ""
     191
     192#: views/settings.php:172
     193msgid   "Key Prefix"
     194msgstr  ""
     195
     196#: views/settings.php:186
    178197msgid   "Purge Actions"
    179198msgstr  ""
    180199
    181 #: views/settings.php:172
     200#: views/settings.php:195
    182201msgid   "Clear Homepage Cache"
    183202msgstr  ""
    184203
    185 #: views/settings.php:176
     204#: views/settings.php:199
    186205msgid   "Clear Content Cache"
    187206msgstr  ""
    188207
    189 #: views/settings.php:180
     208#: views/settings.php:203
    190209msgid   "Clear Archives Cache"
    191210msgstr  ""
    192211
    193 #: views/settings.php:184
     212#: views/settings.php:207
    194213msgid   "Clear Redis Cache"
    195214msgstr  ""
  • runcache-purger/trunk/runcache-purger.php

    r2154393 r2154691  
    55 * Plugin URI:      https://runcloud.io
    66 * Description:     This plugin will purge RunCloud.io NGINX fastcgi, Proxy Cache and Redis Object Cache.
    7  * Version:         1.0.5
     7 * Version:         1.0.6
    88 * Author:          RunCloud
    99 * Author URI:      https://profiles.wordpress.org/runcloud/
     
    6363
    6464    // version
    65     private static $version      = '1.0.5';
    66     private static $version_prev = '1.0.4';
     65    private static $version      = '1.0.6';
     66    private static $version_prev = '1.0.5';
    6767
    6868    // later
     
    7979    private static $plugin_url_logo_w = '';
    8080
    81     // view checkbox
     81    // view
    8282    private static $checked = [];
     83    private static $value = [];
    8384
    8485    // is cond
     
    174175
    175176        return false;
    176     }
    177 
    178     /**
    179      * is_redis_cache_available.
    180      */
    181     private static function is_redis_cache_available() {
    182         $plugin = 'redis-cache/redis-cache.php';
    183         $file = WP_PLUGIN_DIR.DIRECTORY_SEPARATOR.$plugin;
    184 
    185         if ( !file_exists($file) ) {
    186             return false;
    187         }
    188 
    189         if ( !self::is_plugin_active($plugin) && !self::is_plugin_active_for_network($plugin) ) {
    190             return false;
    191         }
    192 
    193         return true;
    194177    }
    195178
     
    341324            'archives_homepage_onn'        => 1,
    342325            'archives_content_onn'         => 1,
    343             'redis_purge_onn'              => 1
     326            'redis_purge_onn'              => 1,
     327            'redis_cache_onn'              => 1,
     328            'redis_prefix'                 => 'runcache-purger',
     329            'redis_host'                   => '127.0.0.1',
     330            'redis_port'                   => 6379,
    344331        ];
    345332
     
    416403
    417404    /**
    418      * is_plugin_active.
    419      */
    420     private static function is_plugin_active( $plugin ) {
    421         if ( ! function_exists( 'is_plugin_active' ) ) {
    422             require_once( ABSPATH.'wp-admin/includes/plugin.php' );
    423         }
    424         return is_plugin_active( $plugin );
     405     * install_dropin.
     406     */
     407    private static function install_dropin()
     408    {
     409        $file = RUNCACHE_PURGER_PATH.'vendor/object-cache.php';
     410        if ( !file_exists($file) ) {
     411            return false;
     412        }
     413
     414        $options = self::get_settings();
     415        if ( empty($options['redis_cache_onn']) ) {
     416            return self::uninstall_dropin();
     417        }
     418
     419        $buff = file_get_contents($file);
     420        if ( !empty($buff) ) {
     421
     422            $redis_host = $options['redis_host'];
     423            $redis_port = $options['redis_port'];
     424            $redis_prefix = $options['redis_prefix'];
     425
     426            $code = "";
     427            $code .= "!defined('RUNCACHE_PURGER_DROPIN_HOST') && define('RUNCACHE_PURGER_DROPIN_HOST', '".$redis_host."');".PHP_EOL;
     428            $code .= "!defined('RUNCACHE_PURGER_DROPIN_PORT') && define('RUNCACHE_PURGER_DROPIN_PORT', '".$redis_port."');".PHP_EOL;
     429            $code .= "!defined('RUNCACHE_PURGER_DROPIN_PREFIX') && define('RUNCACHE_PURGER_DROPIN_PREFIX', '".addslashes($redis_prefix)."');".PHP_EOL;
     430
     431            $buff = str_replace('/*@CONFIG-MARKER*/', $code, $buff);
     432
     433            $filesave = WP_CONTENT_DIR.'/object-cache.php';
     434
     435            $perm = self::get_fileperms('file');
     436            if (file_put_contents($filesave, $buff)) {
     437                @chmod($filesave, $perm);
     438                return true;
     439            }
     440        }
     441
     442        return false;
     443    }
     444
     445    /**
     446     * install_dropin.
     447     */
     448    private static function uninstall_dropin()
     449    {
     450        $filesave = WP_CONTENT_DIR.'/object-cache.php';
     451        return unlink($filesave);
     452    }
     453
     454    /**
     455     * install_dropin.
     456     */
     457    private static function try_install_dropin()
     458    {
     459        if ( !defined('RUNCACHE_PURGER_DROPIN') ) {
     460            self::install_dropin();
     461        }
    425462    }
    426463
     
    507544
    508545    /**
     546     * view_fvalue.
     547     */
     548    private static function view_fvalue($name)
     549    {
     550        echo self::$value[$name];
     551    }
     552
     553    /**
    509554     * view_index.
    510555     */
     
    518563                    $val                 = (int) $val;
    519564                    self::$checked[$key] = (1 === $val ? ' checked' : '');
     565                } else {
     566                    self::$value[$key] = $val;
    520567                }
    521568            }
     
    624671    {
    625672        if (!empty($options)) {
     673            self::install_dropin();
    626674        }
    627675    }
     
    637685            [__CLASS__, 'settings_validate']
    638686        );
     687
     688        // try install dropin
     689        self::try_install_dropin();
    639690    }
    640691
     
    664715            $options = [];
    665716        }
     717
    666718        return $options;
    667719    }
     
    723775
    724776        $options = array_merge($options, $input);
     777
    725778        return $options;
    726779    }
     
    10511104                            $msg = __('Failed to purge redis object cache.', self::$textdomain);
    10521105                        } else {
    1053                             $msg = __('Purging method not implement. Redis WP Object Cache Plugin not available', self::$textdomain);
     1106                            $msg = __('Purging method not implement.', self::$textdomain);
    10541107                        }
    10551108                    }
     
    11321185     */
    11331186    public static function flush_object($purge = false) {
    1134         $ok = false;
    1135         $is_avail = self::is_redis_cache_available();
    1136 
    1137         if ( $is_avail ) {
    1138             $ok = wp_cache_flush();
    1139         }
    1140 
     1187        $ok = wp_cache_flush();
     1188        $filesave = WP_CONTENT_DIR.'/object-cache.php';
     1189        $is_avail = ( file_exists($filesave) ? true : false );
    11411190        $return = [
    1142             'code' => 200,
     1191            'code' => ( $ok ? 200 : 404 ),
    11431192            'is_redis' => 1,
    11441193            'is_avail' => ( $is_avail ? 1 : 0 )
    11451194        ];
    1146 
     1195 
    11471196        if ( !$purge ) {
    1148             $return['code'] = ( $ok ? 200 : 404 );
    11491197            self::$req_status = $return;
    11501198        }
     
    15651613    {
    15661614        self::install_options();
     1615        self::install_dropin();
    15671616    }
    15681617
     
    15731622    {
    15741623        self::force_site_deactivate_plugin();
     1624        self::uninstall_dropin();
    15751625    }
    15761626
     
    15811631    {
    15821632        self::uninstall_options();
     1633        self::uninstall_dropin();
    15831634    }
    15841635
     
    17561807     * cli_purge_all.
    17571808     */
    1758     /*public static function cli_purge_all($types)
    1759     {
    1760         $_res = [];
    1761 
    1762         foreach ($types as $type) {
    1763             self::request_purge_all($type);
    1764 
    1765             if (!self::is_debugging()) {
    1766                 $_res[$type] = [
    1767                     'code'   => self::$req_status['code'],
    1768                     'status' => self::$req_status['status'],
    1769                 ];
    1770             } else {
    1771                 $_res[$type] = self::$req_status;
    1772             }
    1773         }
    1774 
    1775         return $_res;
    1776     }*/
    1777 
    17781809    public static function cli_purge_all($type, $host = null)
    17791810    {
  • runcache-purger/trunk/views/settings.php

    r2154386 r2154691  
    149149                                    <?php _e( 'Automatically clean redis object cache when any purge action was triggered.', self::$textdomain ); ?>
    150150                                </div>
     151                            </div>
     152
     153                            <div class="runcachepurger-field runcachepurger-field-checkbox">
     154                                <div class="runcachepurger-checkbox">
     155                                    <input type="checkbox" id="redis_cache_onn" name="<?php self::view_fname('redis_cache_onn');?>" value="1"<?php self::view_checked('redis_cache_onn');?>>
     156                                    <label for="redis_cache_onn"><?php _e( 'Enable Object Cache', self::$textdomain ); ?></label>
     157                                </div>
     158
     159                                <div class="runcachepurger-field-description">
     160                                    <?php _e( 'Enable this option to allow this plugin handle redis object cache.', self::$textdomain ); ?>
     161                                </div>
     162                            </div>
     163
     164                            <div class="runcachepurger-field cache-redis">
     165                                <h4>Redis Server</h4>
     166                                <label for="redis_host"><?php _e( 'Hostname', self::$textdomain ); ?></label>
     167                                <input type="text" id="redis_host" name="<?php self::view_fname('redis_host');?>" value="<?php self::view_fvalue('redis_host');?>">
     168                                <br>
     169                                <label for="redis_port"><?php _e( 'Port', self::$textdomain ); ?></label>
     170                                <input type="number" min=1 id="redis_port" name="<?php self::view_fname('redis_port');?>" value="<?php self::view_fvalue('redis_port');?>">
     171                                <br>
     172                                <label for="redis_prefix"><?php _e( 'Key Prefix', self::$textdomain ); ?></label>
     173                                <input type="text" id="redis_prefix" name="<?php self::view_fname('redis_prefix');?>" value="<?php self::view_fvalue('redis_prefix');?>">
    151174                            </div>
    152175
Note: See TracChangeset for help on using the changeset viewer.