/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 are truncated click here to view the full file

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