PageRenderTime 382ms CodeModel.GetById 111ms app.highlight 117ms RepoModel.GetById 54ms app.codeStats 2ms

/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php

https://bitbucket.org/openfarmtech/weblog-content
PHP | 5050 lines | 3283 code | 821 blank | 946 comment | 733 complexity | d8b0c6e9afec0c08f466a53d99353015 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2
   3/**
   4 * W3 Total Cache plugin
   5 */
   6require_once W3TC_LIB_W3_DIR . '/Plugin.php';
   7
   8/**
   9 * Class W3_Plugin_TotalCache
  10 */
  11class W3_Plugin_TotalCache extends W3_Plugin
  12{
  13    /**
  14     * Current page
  15     * @var string
  16     */
  17    var $_page = 'w3tc_general';
  18    
  19    /**
  20     * Notes
  21     * @var array
  22     */
  23    var $_notes = array();
  24    
  25    /**
  26     * Errors
  27     * @var array
  28     */
  29    var $_errors = array();
  30    
  31    /**
  32     * Show support reminder flag
  33     * @var boolean
  34     */
  35    var $_support_reminder = false;
  36    
  37    /**
  38     * Used in PHPMailer init function
  39     * @var string
  40     */
  41    var $_phpmailer_sender = '';
  42    
  43    /**
  44     * Array of request types
  45     * @var array
  46     */
  47    var $_request_types = array(
  48        'bug_report' => 'Submit a Bug Report', 
  49        'new_feature' => 'Suggest a New Feature', 
  50        'email_support' => '<15 Minute Email Support Response (M-F 9AM - 5PM EDT): $75 USD', 
  51        'phone_support' => '<15 Minute Phone Support Response (M-F 9AM - 5PM EDT): $150 USD', 
  52        'plugin_config' => 'Professional Plugin Configuration: Starting @ $100 USD', 
  53        'theme_config' => 'Theme Performance Optimization & Plugin Configuration: Starting @ $150 USD', 
  54        'linux_config' => 'Linux Server Optimization & Plugin Configuration: Starting @ $200 USD'
  55    );
  56    
  57    /**
  58     * Array of request groups
  59     * @var array
  60     */
  61    var $_request_groups = array(
  62        'General Support' => array(
  63            'bug_report', 
  64            'new_feature'
  65        ), 
  66        'Professional Services (per site pricing)' => array(
  67            'email_support', 
  68            'phone_support', 
  69            'plugin_config', 
  70            'theme_config', 
  71            'linux_config'
  72        )
  73    );
  74    
  75    /**
  76     * Request price list
  77     * @var array
  78     */
  79    var $_request_prices = array(
  80        'email_support' => 75, 
  81        'phone_support' => 150, 
  82        'plugin_config' => 100, 
  83        'theme_config' => 150, 
  84        'linux_config' => 200
  85    );
  86    
  87    /**
  88     * Runs plugin
  89     */
  90    function run()
  91    {
  92        register_activation_hook(W3TC_FILE, array(
  93            &$this, 
  94            'activate'
  95        ));
  96        
  97        register_deactivation_hook(W3TC_FILE, array(
  98            &$this, 
  99            'deactivate'
 100        ));
 101        
 102        add_action('admin_init', array(
 103            &$this, 
 104            'admin_init'
 105        ));
 106        
 107        add_action('admin_menu', array(
 108            &$this, 
 109            'admin_menu'
 110        ));
 111        
 112        add_filter('contextual_help_list', array(
 113            &$this, 
 114            'contextual_help_list'
 115        ));
 116        
 117        add_filter('plugin_action_links_' . W3TC_FILE, array(
 118            &$this, 
 119            'plugin_action_links'
 120        ));
 121        
 122        add_filter('favorite_actions', array(
 123            &$this, 
 124            'favorite_actions'
 125        ));
 126        
 127        add_action('init', array(
 128            &$this, 
 129            'init'
 130        ));
 131        
 132        add_action('in_plugin_update_message-' . W3TC_FILE, array(
 133            &$this, 
 134            'in_plugin_update_message'
 135        ));
 136        
 137        if ($this->_config->get_boolean('widget.latest.enabled')) {
 138            add_action('wp_dashboard_setup', array(
 139                &$this, 
 140                'wp_dashboard_setup'
 141            ));
 142        }
 143        
 144        if ($this->_config->get_boolean('pgcache.enabled') || $this->_config->get_boolean('minify.enabled')) {
 145            add_filter('pre_update_option_active_plugins', array(
 146                &$this, 
 147                'pre_update_option_active_plugins'
 148            ));
 149        }
 150        
 151        if ($this->_config->get_boolean('cdn.enabled') && $this->_config->get_string('cdn.engine') != 'mirror') {
 152            add_filter('media_row_actions', array(
 153                &$this, 
 154                'media_row_actions'
 155            ), null, 2);
 156        }
 157        
 158        if ($this->_config->get_boolean('pgcache.enabled')) {
 159            add_filter('post_row_actions', array(
 160                &$this, 
 161                'post_row_actions'
 162            ), null, 2);
 163        }
 164        
 165        if (isset($_REQUEST['w3tc_theme']) && isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT'] == W3TC_POWERED_BY) {
 166            add_filter('template', array(
 167                &$this, 
 168                'template_preview'
 169            ));
 170            
 171            add_filter('stylesheet', array(
 172                &$this, 
 173                'stylesheet_preview'
 174            ));
 175        } elseif ($this->_config->get_boolean('mobile.enabled')) {
 176            add_filter('template', array(
 177                &$this, 
 178                'template'
 179            ));
 180            
 181            add_filter('stylesheet', array(
 182                &$this, 
 183                'stylesheet'
 184            ));
 185        }
 186        
 187        if ($this->_config->get_string('common.support') == 'footer') {
 188            add_action('wp_footer', array(
 189                &$this, 
 190                'footer'
 191            ));
 192        }
 193        
 194        ob_start(array(
 195            &$this, 
 196            'ob_callback'
 197        ));
 198        
 199        /**
 200         * Run DbCache plugin
 201         */
 202        require_once W3TC_DIR . '/lib/W3/Plugin/DbCache.php';
 203        $w3_plugin_dbcache = & W3_Plugin_DbCache::instance();
 204        $w3_plugin_dbcache->run();
 205        
 206        /**
 207         * Run ObjectCache plugin
 208         */
 209        require_once W3TC_DIR . '/lib/W3/Plugin/ObjectCache.php';
 210        $w3_plugin_objectcache = & W3_Plugin_ObjectCache::instance();
 211        $w3_plugin_objectcache->run();
 212        
 213        /**
 214         * Run PgCache plugin
 215         */
 216        require_once W3TC_DIR . '/lib/W3/Plugin/PgCache.php';
 217        $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
 218        $w3_plugin_pgcache->run();
 219        
 220        /**
 221         * Run CDN plugin
 222         */
 223        require_once W3TC_DIR . '/lib/W3/Plugin/Cdn.php';
 224        $w3_plugin_cdn = & W3_Plugin_Cdn::instance();
 225        $w3_plugin_cdn->run();
 226        
 227        /**
 228         * Run Minify plugin
 229         */
 230        if (W3TC_PHP5) {
 231            require_once W3TC_DIR . '/lib/W3/Plugin/Minify.php';
 232            $w3_plugin_minify = & W3_Plugin_Minify::instance();
 233            $w3_plugin_minify->run();
 234        }
 235        
 236        /**
 237         * Run BrowserCache plugin
 238         */
 239        require_once W3TC_DIR . '/lib/W3/Plugin/BrowserCache.php';
 240        $w3_plugin_browsercache = & W3_Plugin_BrowserCache::instance();
 241        $w3_plugin_browsercache->run();
 242    }
 243    
 244    /**
 245     * Returns plugin instance
 246     *
 247     * @return W3_Plugin_TotalCache
 248     */
 249    function &instance()
 250    {
 251        static $instances = array();
 252        
 253        if (!isset($instances[0])) {
 254            $class = __CLASS__;
 255            $instances[0] = & new $class();
 256        }
 257        
 258        return $instances[0];
 259    }
 260    
 261    /**
 262     * Activate plugin action
 263     */
 264    function activate()
 265    {
 266        $files = array(
 267            W3TC_INSTALL_DIR . '/db.php', 
 268            W3TC_INSTALL_DIR . '/advanced-cache.php', 
 269            W3TC_INSTALL_DIR . '/object-cache.php'
 270        );
 271        
 272        $nonexistent_files = array();
 273        
 274        foreach ($files as $file) {
 275            if (!file_exists($file)) {
 276                $nonexistent_files[] = $file;
 277            }
 278        }
 279        
 280        if (count($nonexistent_files)) {
 281            $error = sprintf('Unfortunately core file(s): (<strong>%s</strong>) are missing, so activation will fail. Please re-start the installation process from the beginning.', implode(', ', $nonexistent_files));
 282            
 283            w3_activate_error($error);
 284        }
 285        
 286        if (!@is_dir(W3TC_CONTENT_DIR)) {
 287            if (@mkdir(W3TC_CONTENT_DIR, 0755)) {
 288                @chmod(W3TC_CONTENT_DIR, 0755);
 289            } else {
 290                w3_writable_error(W3TC_CONTENT_DIR);
 291            }
 292        }
 293        
 294        if (!@is_dir(W3TC_CACHE_FILE_DBCACHE_DIR)) {
 295            if (@mkdir(W3TC_CACHE_FILE_DBCACHE_DIR, 0755)) {
 296                @chmod(W3TC_CACHE_FILE_DBCACHE_DIR, 0755);
 297            } else {
 298                w3_writable_error(W3TC_CACHE_FILE_DBCACHE_DIR);
 299            }
 300        }
 301        
 302        if (!@is_dir(W3TC_CACHE_FILE_OBJECTCACHE_DIR)) {
 303            if (@mkdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR, 0755)) {
 304                @chmod(W3TC_CACHE_FILE_OBJECTCACHE_DIR, 0755);
 305            } else {
 306                w3_writable_error(W3TC_CACHE_FILE_OBJECTCACHE_DIR);
 307            }
 308        }
 309        
 310        if (!@is_dir(W3TC_CACHE_FILE_PGCACHE_DIR)) {
 311            if (@mkdir(W3TC_CACHE_FILE_PGCACHE_DIR, 0755)) {
 312                @chmod(W3TC_CACHE_FILE_PGCACHE_DIR, 0755);
 313            } else {
 314                w3_writable_error(W3TC_CACHE_FILE_PGCACHE_DIR);
 315            }
 316        }
 317        
 318        if (!@is_dir(W3TC_CACHE_FILE_MINIFY_DIR)) {
 319            if (@mkdir(W3TC_CACHE_FILE_MINIFY_DIR, 0755)) {
 320                @chmod(W3TC_CACHE_FILE_MINIFY_DIR, 0755);
 321            } else {
 322                w3_writable_error(W3TC_CACHE_FILE_MINIFY_DIR);
 323            }
 324        }
 325        
 326        if (!@is_dir(W3TC_LOG_DIR)) {
 327            if (@mkdir(W3TC_LOG_DIR, 0755)) {
 328                @chmod(W3TC_LOG_DIR, 0755);
 329            } else {
 330                w3_writable_error(W3TC_LOG_DIR);
 331            }
 332        }
 333        
 334        if (!@is_dir(W3TC_TMP_DIR)) {
 335            if (@mkdir(W3TC_TMP_DIR, 0755)) {
 336                @chmod(W3TC_TMP_DIR, 0755);
 337            } else {
 338                w3_writable_error(W3TC_TMP_DIR);
 339            }
 340        }
 341        
 342        if (w3_is_multisite() && file_exists(W3TC_CONFIG_MASTER_PATH)) {
 343            /**
 344             * For multisite load master config
 345             */
 346            $this->_config->load_master();
 347            
 348            if (!$this->_config->save(false)) {
 349                w3_writable_error(W3TC_CONFIG_PATH);
 350            }
 351        } elseif (!file_exists(W3TC_CONFIG_PATH)) {
 352            /**
 353             * Set default settings
 354             */
 355            $this->_config->set_defaults();
 356            
 357            /**
 358             * If config doesn't exist enable preview mode
 359             */
 360            if (!$this->_config->save(true)) {
 361                w3_writable_error(W3TC_CONFIG_PREVIEW_PATH);
 362            }
 363        }
 364        
 365        /**
 366         * Save blognames into file
 367         */
 368        if (w3_is_multisite() && !w3_is_vhost()) {
 369            if (!w3_save_blognames()) {
 370                w3_writable_error(W3TC_BLOGNAMES_PATH);
 371            }
 372        }
 373        
 374        delete_option('w3tc_request_data');
 375        add_option('w3tc_request_data', '', null, 'no');
 376        
 377        $this->link_update();
 378    }
 379    
 380    /**
 381     * Deactivate plugin action
 382     */
 383    function deactivate()
 384    {
 385        $this->link_delete();
 386        
 387        delete_option('w3tc_request_data');
 388        
 389        // keep for other blogs
 390        if (!$this->locked()) {
 391            @unlink(W3TC_BLOGNAMES_PATH);
 392        }
 393        
 394        @unlink(W3TC_CONFIG_PREVIEW_PATH);
 395        
 396        w3_rmdir(W3TC_TMP_DIR);
 397        w3_rmdir(W3TC_LOG_DIR);
 398        w3_rmdir(W3TC_CACHE_FILE_MINIFY_DIR);
 399        w3_rmdir(W3TC_CACHE_FILE_PGCACHE_DIR);
 400        w3_rmdir(W3TC_CACHE_FILE_DBCACHE_DIR);
 401        w3_rmdir(W3TC_CACHE_FILE_OBJECTCACHE_DIR);
 402        w3_rmdir(W3TC_CONTENT_DIR);
 403    }
 404    
 405    /**
 406     * Init action
 407     */
 408    function init()
 409    {
 410        $this->check_request();
 411    }
 412    
 413    /**
 414     * Load action
 415     */
 416    function load()
 417    {
 418        require_once W3TC_LIB_W3_DIR . '/Request.php';
 419        
 420        $this->_page = W3_Request::get_string('page');
 421        
 422        switch (true) {
 423            case ($this->_page == 'w3tc_general'):
 424            case ($this->_page == 'w3tc_pgcache'):
 425            case ($this->_page == 'w3tc_minify' && W3TC_PHP5):
 426            case ($this->_page == 'w3tc_dbcache'):
 427            case ($this->_page == 'w3tc_objectcache'):
 428            case ($this->_page == 'w3tc_browsercache'):
 429            case ($this->_page == 'w3tc_mobile'):
 430            case ($this->_page == 'w3tc_cdn'):
 431            case ($this->_page == 'w3tc_install'):
 432            case ($this->_page == 'w3tc_faq'):
 433            case ($this->_page == 'w3tc_about'):
 434            case ($this->_page == 'w3tc_support'):
 435                break;
 436            
 437            default:
 438                $this->_page = 'w3tc_general';
 439        }
 440        
 441        /**
 442         * Flush all caches
 443         */
 444        if (isset($_REQUEST['flush_all'])) {
 445            $this->flush_all();
 446            
 447            $this->redirect(array(
 448                'w3tc_note' => 'flush_all'
 449            ), true);
 450        }
 451        
 452        /**
 453         * Flush memcached cache
 454         */
 455        if (isset($_REQUEST['flush_memcached'])) {
 456            $this->flush_memcached();
 457            
 458            $this->redirect(array(
 459                'w3tc_note' => 'flush_memcached'
 460            ), true);
 461        }
 462        
 463        /**
 464         * Flush APC cache
 465         */
 466        if (isset($_REQUEST['flush_opcode'])) {
 467            $this->flush_opcode();
 468            
 469            $this->redirect(array(
 470                'w3tc_note' => 'flush_opcode'
 471            ), true);
 472        }
 473        
 474        /**
 475         * Flush disk cache
 476         */
 477        if (isset($_REQUEST['flush_file'])) {
 478            $this->flush_file();
 479            
 480            $this->redirect(array(
 481                'w3tc_note' => 'flush_file'
 482            ), true);
 483        }
 484        
 485        /**
 486         * Flush page cache
 487         */
 488        if (isset($_REQUEST['flush_pgcache'])) {
 489            $this->flush_pgcache();
 490            
 491            $this->_config->set('notes.need_empty_pgcache', false);
 492            $this->_config->set('notes.plugins_updated', false);
 493            
 494            if (!$this->_config->save()) {
 495                $this->redirect(array(
 496                    'w3tc_error' => 'config_save'
 497                ), true);
 498            }
 499            
 500            $this->redirect(array(
 501                'w3tc_note' => 'flush_pgcache'
 502            ), true);
 503        }
 504        
 505        /**
 506         * Flush db cache
 507         */
 508        if (isset($_REQUEST['flush_dbcache'])) {
 509            $this->flush_dbcache();
 510            
 511            $this->redirect(array(
 512                'w3tc_note' => 'flush_dbcache'
 513            ), true);
 514        }
 515        
 516        /**
 517         * Flush object cache
 518         */
 519        if (isset($_REQUEST['flush_objectcache'])) {
 520            $this->flush_objectcache();
 521            
 522            $this->redirect(array(
 523                'w3tc_note' => 'flush_objectcache'
 524            ), true);
 525        }
 526        
 527        /**
 528         * Flush minify cache
 529         */
 530        if (isset($_REQUEST['flush_minify'])) {
 531            $this->flush_minify();
 532            
 533            $this->_config->set('notes.need_empty_minify', false);
 534            
 535            if (!$this->_config->save()) {
 536                $this->redirect(array(
 537                    'w3tc_error' => 'config_save'
 538                ), true);
 539            }
 540            
 541            $this->redirect(array(
 542                'w3tc_note' => 'flush_minify'
 543            ), true);
 544        }
 545        
 546        /**
 547         * Hide notes
 548         */
 549        if (isset($_REQUEST['hide_note'])) {
 550            $setting = sprintf('notes.%s', W3_Request::get_string('hide_note'));
 551            
 552            $this->_config->set($setting, false);
 553            
 554            if (!$this->_config->save()) {
 555                $this->redirect(array(
 556                    'w3tc_error' => 'config_save'
 557                ), true);
 558            }
 559            
 560            $this->redirect(array(), true);
 561        }
 562        
 563        /**
 564         * Save config
 565         */
 566        if (isset($_REQUEST['save_config'])) {
 567            if ($this->_config->save()) {
 568                $this->redirect(array(
 569                    'w3tc_note' => 'config_save'
 570                ), true);
 571            } else {
 572                $this->redirect(array(
 573                    'w3tc_error' => 'config_save'
 574                ), true);
 575            }
 576        }
 577        
 578        /**
 579         * Write page cache rules
 580         */
 581        if (isset($_REQUEST['pgcache_write_rules_core'])) {
 582            require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
 583            $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
 584            
 585            if ($w3_plugin_pgcache->write_rules_core()) {
 586                $this->redirect(array(
 587                    'w3tc_note' => 'pgcache_write_rules_core'
 588                ));
 589            } else {
 590                $this->redirect(array(
 591                    'w3tc_error' => 'pgcache_write_rules_core'
 592                ));
 593            }
 594        }
 595        
 596        if (isset($_REQUEST['pgcache_write_rules_cache'])) {
 597            require_once W3TC_LIB_W3_DIR . '/Plugin/PgCache.php';
 598            $w3_plugin_pgcache = & W3_Plugin_PgCache::instance();
 599            
 600            if ($w3_plugin_pgcache->write_rules_cache()) {
 601                $this->redirect(array(
 602                    'w3tc_note' => 'pgcache_write_rules_cache'
 603                ));
 604            } else {
 605                $this->redirect(array(
 606                    'w3tc_error' => 'pgcache_write_rules_cache'
 607                ));
 608            }
 609        }
 610        
 611        /**
 612         * Write browser cache rules
 613         */
 614        if (isset($_REQUEST['browsercache_write_rules_cache'])) {
 615            require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
 616            $w3_plugin_browsercache = & W3_Plugin_BrowserCache::instance();
 617            
 618            if ($w3_plugin_browsercache->write_rules_cache()) {
 619                $this->redirect(array(
 620                    'w3tc_note' => 'browsercache_write_rules_cache'
 621                ));
 622            } else {
 623                $this->redirect(array(
 624                    'w3tc_error' => 'browsercache_write_rules_cache'
 625                ));
 626            }
 627        }
 628        
 629        if (isset($_REQUEST['browsercache_write_rules_no404wp'])) {
 630            require_once W3TC_LIB_W3_DIR . '/Plugin/BrowserCache.php';
 631            $w3_plugin_browsercache = & W3_Plugin_BrowserCache::instance();
 632            
 633            if ($w3_plugin_browsercache->write_rules_no404wp()) {
 634                $this->redirect(array(
 635                    'w3tc_note' => 'browsercache_write_rules_no404wp'
 636                ));
 637            } else {
 638                $this->redirect(array(
 639                    'w3tc_error' => 'browsercache_write_rules_no404wp'
 640                ));
 641            }
 642        }
 643        
 644        /**
 645         * Write minify rules
 646         */
 647        if (W3TC_PHP5 && isset($_REQUEST['minify_write_rules'])) {
 648            require_once W3TC_LIB_W3_DIR . '/Plugin/Minify.php';
 649            $w3_plugin_minify = & W3_Plugin_Minify::instance();
 650            
 651            if ($w3_plugin_minify->write_rules()) {
 652                $this->redirect(array(
 653                    'w3tc_note' => 'minify_write_rules'
 654                ));
 655            } else {
 656                $this->redirect(array(
 657                    'w3tc_error' => 'minify_write_rules'
 658                ));
 659            }
 660        }
 661        
 662        /**
 663         * Save support us options
 664         */
 665        if (isset($_REQUEST['save_support_us'])) {
 666            $support = W3_Request::get_string('support');
 667            
 668            $this->_config->set('common.support', $support);
 669            
 670            if (!$this->_config->save()) {
 671                $this->redirect(array(
 672                    'w3tc_error' => 'config_save'
 673                ));
 674            }
 675            
 676            $this->link_update();
 677            
 678            $this->redirect(array(
 679                'w3tc_note' => 'config_save'
 680            ));
 681        }
 682        
 683        /**
 684         * Import config action
 685         */
 686        if (isset($_REQUEST['config_import'])) {
 687            $this->config_import();
 688        }
 689        
 690        /**
 691         * Export config action
 692         */
 693        if (isset($_REQUEST['config_export'])) {
 694            $this->config_export();
 695        }
 696        
 697        /**
 698         * Reset config action
 699         */
 700        if (isset($_REQUEST['config_reset'])) {
 701            $this->config_reset();
 702        }
 703        
 704        /**
 705         * Support select action
 706         */
 707        if (isset($_REQUEST['support_select'])) {
 708            $this->support_select();
 709        }
 710        
 711        /**
 712         * Deploy preview settings
 713         */
 714        if (isset($_REQUEST['preview_deploy'])) {
 715            $this->preview_deploy();
 716        }
 717        
 718        /**
 719         * Run plugin action
 720         */
 721        if (isset($_REQUEST['w3tc_action'])) {
 722            $action = trim($_REQUEST['w3tc_action']);
 723            
 724            if (method_exists($this, $action)) {
 725                call_user_func(array(
 726                    &$this, 
 727                    $action
 728                ));
 729                exit();
 730            }
 731        }
 732        
 733        /**
 734         * Save options
 735         */
 736        if (isset($_REQUEST['options_save'])) {
 737            $this->options_save();
 738        }
 739        
 740        /**
 741         * Save preview mode
 742         */
 743        if (isset($_REQUEST['preview_save'])) {
 744            $this->preview_save();
 745        }
 746        
 747        /**
 748         * Support request
 749         */
 750        if (isset($_REQUEST['support_request'])) {
 751            $this->support_request();
 752        }
 753        
 754        /**
 755         * CDN Purge
 756         */
 757        if (isset($_REQUEST['cdn_purge_attachment'])) {
 758            $this->cdn_purge_attachment();
 759        }
 760        
 761        /**
 762         * PgCache purge
 763         */
 764        if (isset($_REQUEST['pgcache_purge_post'])) {
 765            $this->pgcache_purge_post();
 766        }
 767        
 768        $this->_support_reminder = ($this->_config->get_boolean('notes.support_us') && $this->_config->get_integer('common.install') < (time() - W3TC_SUPPORT_US_TIMEOUT) && !$this->is_supported());
 769    }
 770    
 771    /**
 772     * Dashboard setup action
 773     */
 774    function wp_dashboard_setup()
 775    {
 776        wp_add_dashboard_widget('w3tc_latest', 'The Latest from W3 EDGE', array(
 777            &$this, 
 778            'widget_latest'
 779        ), array(
 780            &$this, 
 781            'widget_latest_control'
 782        ));
 783    }
 784    
 785    /**
 786     * Prints latest widget contents
 787     */
 788    function widget_latest()
 789    {
 790        global $wp_version;
 791        
 792        $items = array();
 793        $items_count = $this->_config->get_integer('widget.latest.items');
 794        
 795        if ($wp_version >= 2.8) {
 796            include_once (ABSPATH . WPINC . '/feed.php');
 797            $feed = fetch_feed(W3TC_FEED_URL);
 798            
 799            if (!is_wp_error($feed)) {
 800                $feed_items = $feed->get_items(0, $items_count);
 801                
 802                foreach ($feed_items as $feed_item) {
 803                    $items[] = array(
 804                        'link' => $feed_item->get_link(), 
 805                        'title' => $feed_item->get_title(), 
 806                        'description' => $feed_item->get_description()
 807                    );
 808                }
 809            }
 810        } else {
 811            include_once (ABSPATH . WPINC . '/rss.php');
 812            $rss = fetch_rss(W3TC_FEED_URL);
 813            
 814            if (is_object($rss)) {
 815                $items = array_slice($rss->items, 0, $items_count);
 816            }
 817        }
 818        
 819        include W3TC_DIR . '/inc/widget/latest.phtml';
 820    }
 821    
 822    /**
 823     * Latest widget control
 824     */
 825    function widget_latest_control($widget_id, $form_inputs = array())
 826    {
 827        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
 828            require_once W3TC_LIB_W3_DIR . '/Request.php';
 829            
 830            $this->_config->set('widget.latest.items', W3_Request::get_integer('w3tc_latest_items', 3));
 831            $this->_config->save();
 832        } else {
 833            include W3TC_DIR . '/inc/widget/latest_control.phtml';
 834        }
 835    }
 836    
 837    /**
 838     * Admin init
 839     */
 840    function admin_init()
 841    {
 842        wp_register_style('w3tc-options', WP_PLUGIN_URL . '/w3-total-cache/inc/css/options.css');
 843        wp_register_style('w3tc-lightbox', WP_PLUGIN_URL . '/w3-total-cache/inc/css/lightbox.css');
 844        
 845        wp_register_script('w3tc-options', WP_PLUGIN_URL . '/w3-total-cache/inc/js/options.js');
 846        wp_register_script('w3tc-lightbox', WP_PLUGIN_URL . '/w3-total-cache/inc/js/lightbox.js');
 847    }
 848    
 849    /**
 850     * Admin menu
 851     */
 852    function admin_menu()
 853    {
 854        $pages = array(
 855            'w3tc_general' => array(
 856                'General Settings', 
 857                'General Settings'
 858            ), 
 859            'w3tc_pgcache' => array(
 860                'Page Cache', 
 861                'Page Cache'
 862            ), 
 863            'w3tc_minify' => array(
 864                'Minify', 
 865                'Minify'
 866            ), 
 867            'w3tc_dbcache' => array(
 868                'Database Cache', 
 869                'Database Cache'
 870            ), 
 871            'w3tc_objectcache' => array(
 872                'Object Cache', 
 873                'Object Cache'
 874            ), 
 875            'w3tc_browsercache' => array(
 876                'Browser Cache', 
 877                'Browser Cache'
 878            ), 
 879            'w3tc_mobile' => array(
 880                'User Agent Groups', 
 881                'User Agent Groups'
 882            ), 
 883            'w3tc_cdn' => array(
 884                'Content Delivery Network', 
 885                '<acronym title="Content Delivery Network">CDN</acronym>'
 886            ), 
 887            'w3tc_faq' => array(
 888                'FAQ', 
 889                'FAQ'
 890            ), 
 891            'w3tc_support' => array(
 892                'Support', 
 893                '<span style="color: red;">Support</span>'
 894            ), 
 895            'w3tc_install' => array(
 896                'Install', 
 897                'Install'
 898            ), 
 899            'w3tc_about' => array(
 900                'About', 
 901                'About'
 902            )
 903        );
 904        
 905        if (!W3TC_PHP5) {
 906            unset($pages['minify']);
 907        }
 908        
 909        add_menu_page('Performance', 'Performance', 'manage_options', 'w3tc_general', '', plugins_url('w3-total-cache/inc/images/logo_small.png'));
 910        
 911        $submenu_pages = array();
 912        
 913        foreach ($pages as $slug => $titles) {
 914            $submenu_pages[] = add_submenu_page('w3tc_general', $titles[0] . ' | W3 Total Cache', $titles[1], 'manage_options', $slug, array(
 915                &$this, 
 916                'options'
 917            ));
 918        }
 919        
 920        if (current_user_can('manage_options')) {
 921            
 922            /**
 923             * Only admin can modify W3TC settings
 924             */
 925            foreach ($submenu_pages as $submenu_page) {
 926                add_action('load-' . $submenu_page, array(
 927                    &$this, 
 928                    'load'
 929                ));
 930                
 931                add_action('admin_print_styles-' . $submenu_page, array(
 932                    &$this, 
 933                    'admin_print_styles'
 934                ));
 935                
 936                add_action('admin_print_scripts-' . $submenu_page, array(
 937                    &$this, 
 938                    'admin_print_scripts'
 939                ));
 940            }
 941            
 942            /**
 943             * Only admin can see W3TC notices and errors
 944             */
 945            add_action('admin_notices', array(
 946                &$this, 
 947                'admin_notices'
 948            ));
 949        }
 950    }
 951    
 952    /**
 953     * Print styles
 954     */
 955    function admin_print_styles()
 956    {
 957        wp_enqueue_style('w3tc-options');
 958        wp_enqueue_style('w3tc-lightbox');
 959    }
 960    
 961    /**
 962     * Print scripts
 963     */
 964    function admin_print_scripts()
 965    {
 966        wp_enqueue_script('w3tc-options');
 967        wp_enqueue_script('w3tc-lightbox');
 968        
 969        switch ($this->_page) {
 970            case 'w3tc_minify':
 971            case 'w3tc_mobile':
 972            case 'w3tc_cdn':
 973                wp_enqueue_script('jquery-ui-sortable');
 974                break;
 975        }
 976    }
 977    
 978    /**
 979     * Contextual help list filter
 980     * 
 981     * @param string $list
 982     * @return string
 983     */
 984    function contextual_help_list($list)
 985    {
 986        $faq = $this->parse_faq();
 987        
 988        if (isset($faq['Usage'])) {
 989            $columns = array_chunk($faq['Usage'], ceil(count($faq['Usage']) / 3));
 990            
 991            ob_start();
 992            include W3TC_DIR . '/inc/options/common/help.phtml';
 993            $help = ob_get_contents();
 994            ob_end_clean();
 995            
 996            $hook = get_plugin_page_hookname($this->_page, 'w3tc_general');
 997            
 998            $list[$hook] = $help;
 999        }
1000        
1001        return $list;
1002    }
1003    
1004    /**
1005     * Plugin action links filter
1006     *
1007     * @return array
1008     */
1009    function plugin_action_links($links)
1010    {
1011        array_unshift($links, '<a class="edit" href="admin.php?page=w3tc_general">Settings</a>');
1012        
1013        return $links;
1014    }
1015    
1016    /**
1017     * favorite_actions filter
1018     */
1019    function favorite_actions($actions)
1020    {
1021        $actions['admin.php?page=w3tc_general&amp;flush_all'] = array(
1022            'Empty Caches', 
1023            'manage_options'
1024        );
1025        
1026        return $actions;
1027    }
1028    
1029    /**
1030     * Check request and handle w3tc_request_data requests
1031     */
1032    function check_request()
1033    {
1034        $pos = strpos($_SERVER['REQUEST_URI'], '/w3tc_request_data/');
1035        
1036        if ($pos !== false) {
1037            $hash = substr($_SERVER['REQUEST_URI'], $pos + 19, 32);
1038            
1039            if (strlen($hash) == 32) {
1040                $request_data = (array) get_option('w3tc_request_data');
1041                
1042                if (isset($request_data[$hash])) {
1043                    echo '<pre>';
1044                    foreach ($request_data[$hash] as $key => $value) {
1045                        printf("%s: %s\n", $key, $value);
1046                    }
1047                    echo '</pre>';
1048                    
1049                    unset($request_data[$hash]);
1050                    update_option('w3tc_request_data', $request_data);
1051                } else {
1052                    echo 'Requested hash expired or invalid';
1053                }
1054                
1055                exit();
1056            }
1057        }
1058    }
1059    
1060    /**
1061     * Admin notices action
1062     */
1063    function admin_notices()
1064    {
1065        $home_root = w3_get_home_root();
1066        $document_root = w3_get_document_root();
1067        $config_path = (w3_is_preview_config() ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PATH);
1068        
1069        $pgcache_rules_core_path = $home_root . '/.htaccess';
1070        $pgcache_rules_cache_path = W3TC_CACHE_FILE_PGCACHE_DIR . '/.htaccess';
1071        $browsercache_rules_cache_path = $document_root . '/.htaccess';
1072        $browsercache_rules_no404wp_path = $home_root . '/.htaccess';
1073        $minify_rules_path = W3TC_CACHE_FILE_MINIFY_DIR . '/.htaccess';
1074        
1075        $error_messages = array(
1076            'config_save' => sprintf('The settings could not be saved because the config file is not write-able. Please run <strong>chmod 777 %s</strong> to resolve this issue.', (file_exists($config_path) ? $config_path : dirname($config_path))), 
1077            'fancy_permalinks_disabled_pgcache' => sprintf('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the enhanced disk mode.', $this->button_link('enable', 'options-permalink.php')), 
1078            'fancy_permalinks_disabled_browsercache' => sprintf('Fancy permalinks are disabled. Please %s it first, then re-attempt to enabling the \'Do not process 404 errors for static objects with WordPress\'.', $this->button_link('enable', 'options-permalink.php')), 
1079            'pgcache_write_rules_core' => sprintf('Either your .htaccess file does not exist or cannot be modified (%s). Please run <strong>chmod 777 %s</strong> to resolve this issue.', $pgcache_rules_core_path, (file_exists($pgcache_rules_core_path) ? $pgcache_rules_core_path : dirname($pgcache_rules_core_path))), 
1080            'pgcache_write_rules_cache' => sprintf('The page cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $pgcache_rules_cache_path, (file_exists($pgcache_rules_cache_path) ? $pgcache_rules_cache_path : dirname($pgcache_rules_cache_path))), 
1081            'browsercache_write_rules_cache' => sprintf('The browser cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $browsercache_rules_cache_path, (file_exists($browsercache_rules_cache_path) ? $browsercache_rules_cache_path : dirname($browsercache_rules_cache_path))), 
1082            'browsercache_write_rules_no404wp' => sprintf('The browser cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $browsercache_rules_no404wp_path, (file_exists($browsercache_rules_no404wp_path) ? $browsercache_rules_no404wp_path : dirname($browsercache_rules_no404wp_path))), 
1083            'browsercache_write_rules_cdn' => sprintf('The browser cache rules for CDN could not be modified. Please check CDN settings.'), 
1084            'minify_write_rules' => sprintf('The minify cache rules (%s) could not be modified. Please run <strong>chmod 777 %s</strong> to resolve this issue.', $minify_rules_path, (file_exists($minify_rules_path) ? $minify_rules_path : dirname($minify_rules_path))), 
1085            'support_request_type' => 'Please select request type.', 
1086            'support_request_url' => 'Please enter the address of your site in the site <acronym title="Uniform Resource Locator">URL</acronym> field.', 
1087            'support_request_name' => 'Please enter your name in the Name field', 
1088            'support_request_email' => 'Please enter valid email address in the E-Mail field.', 
1089            'support_request_phone' => 'Please enter your phone in the phone field.', 
1090            'support_request_subject' => 'Please enter subject in the subject field.', 
1091            'support_request_description' => 'Please describe the issue in the issue description field.', 
1092            'support_request_wp_login' => 'Please enter an administrator login. Remember you can create a temporary one just for this support case.', 
1093            'support_request_wp_password' => 'Please enter WP Admin password, be sure it\'s spelled correctly.', 
1094            'support_request_ftp_host' => 'Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> host for your site.', 
1095            'support_request_ftp_login' => 'Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> login for your server. Remember you can create a temporary one just for this support case.', 
1096            'support_request_ftp_password' => 'Please enter <acronym title="Secure Shell">SSH</acronym> or <acronym title="File Transfer Protocol">FTP</acronym> password for your <acronym title="File Transfer Protocol">FTP</acronym> account.', 
1097            'support_request' => 'Unable to send your support request.', 
1098            'config_import_no_file' => 'Please select config file.', 
1099            'config_import_upload' => 'Unable to upload config file.', 
1100            'config_import_import' => sprintf('Configuration file could not be imported. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists($config_path) ? $config_path : dirname($config_path))), 
1101            'config_reset' => sprintf('Default settings could not be restored. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists(W3TC_CONFIG_PREVIEW_PATH) ? W3TC_CONFIG_PREVIEW_PATH : W3TC_CONFIG_PREVIEW_PATH)), 
1102            'preview_enable' => sprintf('Preview mode could not be enabled. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists(W3TC_CONFIG_PREVIEW_PATH) ? W3TC_CONFIG_PREVIEW_PATH : dirname(W3TC_CONFIG_PREVIEW_PATH))), 
1103            'preview_disable' => sprintf('Preview mode could not be disabled. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists($config_path) ? $config_path : dirname($config_path))), 
1104            'preview_deploy' => sprintf('Preview settings could not be deployed. Please run <strong>chmod 777 %s</strong> to make the configuration file write-able, then try again.', (file_exists(W3TC_CONFIG_PATH) ? W3TC_CONFIG_PATH : dirname(W3TC_CONFIG_PATH))), 
1105            'cdn_purge_attachment' => 'Unable to purge attachment.', 
1106            'pgcache_purge_post' => 'Unable to purge post.'
1107        );
1108        
1109        $note_messages = array(
1110            'config_save' => 'Plugin configuration successfully updated.', 
1111            'flush_all' => 'All caches successfully emptied.', 
1112            'flush_memcached' => 'Memcached cache(s) successfully emptied.', 
1113            'flush_opcode' => 'Opcode cache(s) successfully emptied.', 
1114            'flush_file' => 'Disk cache successfully emptied.', 
1115            'flush_pgcache' => 'Page cache successfully emptied.', 
1116            'flush_dbcache' => 'Database cache successfully emptied.', 
1117            'flush_objectcache' => 'Object cache successfully emptied.', 
1118            'flush_minify' => 'Minify cache successfully emptied.', 
1119            'pgcache_write_rules_core' => 'Page cache rewrite rules have been successfully written.', 
1120            'pgcache_write_rules_cache' => 'Page cache rewrite rules have been successfully written.', 
1121            'browsercache_write_rules_cache' => 'Browser cache directives have been successfully written.', 
1122            'browsercache_write_rules_no404wp' => 'Browser cache directives have been successfully written.', 
1123            'minify_write_rules' => 'Minify rewrite rules have been successfully written.', 
1124            'support_request' => 'Your support request has been successfully sent.', 
1125            'config_import' => 'Settings successfully imported.', 
1126            'config_reset' => 'Settings successfully restored.', 
1127            'preview_enable' => 'Preview mode was successfully enabled', 
1128            'preview_disable' => 'Preview mode was successfully disabled', 
1129            'preview_deploy' => 'Preview settings successfully deployed.', 
1130            'cdn_purge_attachment' => 'Attachment successfully purged.', 
1131            'pgcache_purge_post' => 'Post successfully purged.'
1132        );
1133        
1134        $errors = array();
1135        $notes = array();
1136        
1137        require_once W3TC_LIB_W3_DIR . '/Request.php';
1138        
1139        $error = W3_Request::get_string('w3tc_error');
1140        $note = W3_Request::get_string('w3tc_note');
1141        
1142        /**
1143         * Handle messages from reqeust
1144         */
1145        if (isset($error_messages[$error])) {
1146            $errors[] = $error_messages[$error];
1147        }
1148        
1149        if (isset($note_messages[$note])) {
1150            $notes[] = $note_messages[$note];
1151        }
1152        
1153        /**
1154         * Check config file
1155         */
1156        if (!w3_is_preview_config() && !file_exists(W3TC_CONFIG_PATH)) {
1157            $errors[] = sprintf('<strong>W3 Total Cache Error:</strong> Default settings are in use. The configuration file could not be read or doesn\'t exist. Please %s to create the file.', $this->button_link('save your settings', sprintf('admin.php?page=%s&save_config', $this->_page)));
1158        }
1159        
1160        /**
1161         * CDN notifications
1162         */
1163        if ($this->_config->get_boolean('cdn.enabled') && !in_array($this->_config->get_string('cdn.engine'), array(
1164            'mirror', 
1165            'netdna'
1166        ))) {
1167            /**
1168             * Show notification after theme change
1169             */
1170            if ($this->_config->get_boolean('notes.theme_changed')) {
1171                $notes[] = sprintf('Your active theme has changed, please %s now to ensure proper operation. %s', $this->button_popup('upload active theme files', 'cdn_export', 'cdn_export_type=theme'), $this->button_hide_note('Hide this message', 'theme_changed'));
1172            }
1173            
1174            /**
1175             * Show notification after WP upgrade
1176             */
1177            if ($this->_config->get_boolean('notes.wp_upgraded')) {
1178                $notes[] = sprintf('Have you upgraded WordPress? Please %s files now to ensure proper operation. %s', $this->button_popup('upload wp-includes', 'cdn_export', 'cdn_export_type=includes'), $this->button_hide_note('Hide this message', 'wp_upgraded'));
1179            }
1180            
1181            /**
1182             * Show notification after CDN enable
1183             */
1184            if ($this->_config->get_boolean('notes.cdn_upload')) {
1185                $cdn_upload_buttons = array();
1186                
1187                if ($this->_config->get_boolean('cdn.includes.enable')) {
1188                    $cdn_upload_buttons[] = $this->button_popup('wp-includes', 'cdn_export', 'cdn_export_type=includes');
1189                }
1190                
1191                if ($this->_config->get_boolean('cdn.theme.enable')) {
1192                    $cdn_upload_buttons[] = $this->button_popup('theme files', 'cdn_export', 'cdn_export_type=theme');
1193                }
1194                
1195                if ($this->_config->get_boolean('minify.enabled') && $this->_config->get_boolean('cdn.minify.enable')) {
1196                    $cdn_upload_buttons[] = $this->button_popup('minify files', 'cdn_export', 'cdn_export_type=minify');
1197                }
1198                
1199                if ($this->_config->get_boolean('cdn.custom.enable')) {
1200                    $cdn_upload_buttons[] = $this->button_popup('custom files', 'cdn_export', 'cdn_export_type=custom');
1201                }
1202                
1203                $notes[] = sprintf('Make sure to %s and upload your %s, files to the CDN to ensure proper operation. %s', $this->button_popup('export your media library', 'cdn_export_library'), implode(', ', $cdn_upload_buttons), $this->button_hide_note('Hide this message', 'cdn_upload'));
1204            }
1205        }
1206        
1207        /**
1208         * Show notification after plugin activate/deactivate
1209         */
1210        if ($this->_config->get_boolean('notes.plugins_updated')) {
1211            $texts = array();
1212            
1213            if ($this->_config->get_boolean('pgcache.enabled')) {
1214                $texts[] = $this->button_link('empty the page cache', sprintf('admin.php?page=%s&flush_pgcache', $this->_page));
1215            }
1216            
1217            if ($this->_config->get_boolean('minify.enabled')) {
1218                $texts[] = sprintf('check your %s to maintain the desired user experience', $this->button_hide_note('minify settings', 'plugins_updated', 'admin.php?page=w3tc_minify'));
1219            }
1220            
1221            if (count($texts)) {
1222                $notes[] = sprintf('One or more plugins have been activated or deactivated, please %s. %s', implode(' and ', $texts), $this->button_hide_note('Hide this message', 'plugins_updated'));
1223            }
1224        }
1225        
1226        /**
1227         * Show notification when page cache needs to be emptied
1228         */
1229        if ($this->_config->get_boolean('pgcache.enabled') && $this->_config->get('notes.need_empty_pgcache') && !w3_is_preview_config()) {
1230            $notes[] = sprintf('The setting change(s) made either invalidate your cached data or modify the behavior of your site. %s now to provide a consistent user experience.', $this->button_link('Empty the page cache', sprintf('admin.php?page=%s&flush_pgcache', $this->_page)));
1231        }
1232        
1233        /**
1234         * Minify notifications
1235         */
1236        if ($this->_config->get_boolean('minify.enabled')) {
1237            /**
1238             * Minify error occured
1239             */
1240            if ($this->_config->get('notes.minify_error')) {
1241                $errors[] = sprintf('Recently an error occurred while creating the CSS / JS minify cache: Some files were unavailable, please check your settings to ensure your site is working as intended. %s', $this->button_hide_note('Hide this message', 'minify_error'));
1242            }
1243            
1244            /**
1245             * Show notification when minify needs to be emptied
1246             */
1247            if ($this->_config->get('notes.need_empty_minify') && !w3_is_preview_config()) {
1248                $notes[] = sprintf('The setting change(s) made either invalidate your cached data or modify the behavior of your site. %s now to provide a consistent user experience.', $this->button_link('Empty the minify cache', sprintf('admin.php?page=%s&flush_minify', $this->_page)));
1249            }
1250        }
1251        
1252        /**
1253         * Show messages
1254         */
1255        foreach ($errors as $error) {
1256            echo sprintf('<div class="error"><p>%s</p></div>', $error);
1257        }
1258        
1259        foreach ($notes as $note) {
1260            echo sprintf('<div class="updated fade"><p>%s</p></div>', $note);
1261        }
1262    }
1263    
1264    /**
1265     * Active plugins pre update option filter
1266     */
1267    function pre_update_option_active_plugins($new_value)
1268    {
1269        $old_value = (array) get_option('active_plugins');
1270        
1271        if ($new_value !== $old_value && in_array(W3TC_FILE, (array) $new_value) && in_array(W3TC_FILE, (array) $old_value)) {
1272            $this->_config->set('notes.plugins_updated', true);
1273            $this->_config->save();
1274        }
1275        
1276        return $new_value;
1277    }
1278    
1279    /**
1280     * Show plugin changes
1281     */
1282    function in_plugin_update_message()
1283    {
1284        $data = w3_http_get(W3TC_README_URL);
1285        
1286        if ($data) {
1287            $matches = null;
1288            if (preg_match('~==\s*Changelog\s*==\s*=\s*[0-9.]+\s*=(.*)(=\s*[0-9.]+\s*=|$)~Uis', $data, $matches)) {
1289                $changelog = (array) preg_split('~[\r\n]+~', trim($matches[1]));
1290                
1291                echo '<div style="color: #f00;">Take a minute to update, here\'s why:</div><div style="font-weight: normal;">';
1292                $ul = false;
1293                
1294                foreach ($changelog as $index => $line) {
1295                    if (preg_match('~^\s*\*\s*~', $line)) {
1296                        if (!$ul) {
1297                            echo '<ul style="list-style: disc; margin-left: 20px;">';
1298                            $ul = true;
1299                        }
1300                        $line = preg_replace('~^\s*\*\s*~', '', htmlspecialchars($line));
1301                        echo '<li style="width: 50%; margin: 0; float: left; ' . ($index % 2 == 0 ? 'clear: left;' : '') . '">' . $line . '</li>';
1302                    } else {
1303                        if ($ul) {
1304                            echo '</ul><div style="clear: left;"></div>';
1305                            $ul = false;
1306                        }
1307                        echo '<p style="margin: 5px 0;">' . htmlspecialchars($line) . '</p>';
1308                    }
1309                }
1310                
1311                if ($ul) {
1312                    echo '</ul><div style="clear: left;"></div>';
1313                }
1314                
1315                echo '</div>';
1316            }
1317        }
1318    }
1319    
1320    /**
1321     * media_row_actions filter
1322     */
1323    function media_row_actions($actions, $post)
1324    {
1325        $actions = array_merge($actions, array(
1326            'cdn_purge' => sprintf('<a href="admin.php?page=w3tc_general&cdn_purge_attachment&attachment_id=%d">Purge from CDN</a>', $post->ID)
1327        ));
1328        
1329        return $actions;
1330    }
1331    
1332    /**
1333     * post_row_actions filter
1334     */
1335    function post_row_actions($actions, $post)
1336    {
1337        $actions = array_merge($actions, array(
1338            'pgcache_purge' => sprintf('<a href="admin.php?page=w3tc_general&pgcache_purge_post&post_id=%d">Purge from Page Cache</a>', $post->ID)
1339        ));
1340        
1341        return $actions;
1342    }
1343    
1344    /**
1345     * Template filter
1346     * 
1347     * @param $template
1348     * @return string
1349     */
1350    function template($template)
1351    {
1352        require_once W3TC_LIB_W3_DIR . '/Mobile.php';
1353        $w3_mobile = & W3_Mobile::instance();
1354        
1355        $mobile_template = $w3_mobile->get_template();
1356        
1357        if ($mobile_template) {
1358            return $mobile_template;
1359        }
1360        
1361        return $template;
1362    }
1363    
1364    /**
1365     * Stylesheet filter
1366     * 
1367     * @param $stylesheet
1368     * @return string
1369     */
1370    function stylesheet($stylesheet)
1371    {
1372        require_once W3TC_LIB_W3_DIR . '/Mobile.php';
1373        $w3_mobile = & W3_Mobile::instance();
1374        
1375        $mobile_stylesheet = $w3_mobile->get_stylesheet();
1376        
1377        if ($mobile_styleshee…

Large files files are truncated, but you can click here to view the full file