Source Code Documentation


s2member\includes\classes\cache.inc.php


  1. <?php
  2. /**
  3. * s2Member's caching routines.
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * Released under the terms of the GNU General Public License.
  10. * You should have received a copy of the GNU General Public License,
  11. * along with this software. In the main directory, see: /licensing/
  12. * If not, see: {@link http://www.gnu.org/licenses/}.
  13. *
  14. * @package s2Member\Cache
  15. * @since 3.5
  16. */
  17. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  18. exit("Do not access this file directly.");
  19.  
  20. if (!class_exists ("c_ws_plugin__s2member_cache"))
  21. {
  22. /**
  23. * s2Member's caching routines.
  24. *
  25. * @package s2Member\Cache
  26. * @since 3.5
  27. */
  28. class c_ws_plugin__s2member_cache
  29. {
  30. /**
  31. * Page links needed for Constants.
  32. *
  33. * Page links are cached into the s2Member options on 15 min intervals.
  34. * This allows the API Constants to provide quick access to them without being
  35. * forced to execute {@link http://codex.wordpress.org/Function_Reference/get_page_link get_page_link()}
  36. * all the time, which piles up DB queries.
  37. *
  38. * @package s2Member\Cache
  39. * @since 3.5
  40. *
  41. * @return array Array of cached Page links.
  42. */
  43. public static function cached_page_links ()
  44. {
  45. do_action ("ws_plugin__s2member_before_cached_page_links", get_defined_vars ());
  46.  
  47. $lwp = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["login_welcome_page"];
  48. $mop = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"];
  49. $fdlep = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_limit_exceeded_page"];
  50.  
  51. $lwp_cache = @$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"];
  52. $mop_cache = @$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"];
  53. $fdlep_cache = @$GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"];
  54.  
  55. $links = array ("login_welcome_page" => "", "membership_options_page" => "", "file_download_limit_exceeded_page" => "");
  56.  
  57. if (isset ($lwp_cache["page"], $lwp_cache["time"], $lwp_cache["link"]) && $lwp_cache["page"] === $lwp && $lwp_cache["time"] >= strtotime ("-15 minutes") && $lwp_cache["link"])
  58. {
  59. $links["login_welcome_page"] = $lwp_cache["link"];
  60. }
  61. else // Otherwise, query the database using ``get_page_link()`` and update the cache.
  62. {
  63. $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["page"] = $lwp;
  64. $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["time"] = time ();
  65. $links["login_welcome_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["login_welcome_page"]["link"] = get_page_link ($lwp);
  66.  
  67. $cache_needs_updating = /* Flag for cache update. */ true;
  68. }
  69. if (isset ($mop_cache["page"], $mop_cache["time"], $mop_cache["link"]) && $mop_cache["page"] === $mop && $mop_cache["time"] >= strtotime ("-15 minutes") && $mop_cache["link"])
  70. {
  71. $links["membership_options_page"] = $mop_cache["link"];
  72. }
  73. else // Otherwise, query the database using ``get_page_link()`` and update the cache.
  74. {
  75. $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["page"] = $mop;
  76. $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["time"] = time ();
  77. $links["membership_options_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["membership_options_page"]["link"] = get_page_link ($mop);
  78.  
  79. $cache_needs_updating = /* Flag for cache update. */ true;
  80. }
  81. if (isset ($fdlep_cache["page"], $fdlep_cache["time"], $fdlep_cache["link"]) && $fdlep_cache["page"] === $fdlep && $fdlep_cache["time"] >= strtotime ("-15 minutes") && $fdlep_cache["link"])
  82. {
  83. $links["file_download_limit_exceeded_page"] = $fdlep_cache["link"];
  84. }
  85. else // Otherwise, query the database using ``get_page_link()`` and update the cache.
  86. {
  87. $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["page"] = $fdlep;
  88. $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["time"] = time ();
  89. $links["file_download_limit_exceeded_page"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]["file_download_limit_exceeded_page"]["link"] = get_page_link ($fdlep);
  90.  
  91. $cache_needs_updating = /* Flag for cache update. */ true;
  92. }
  93. if /* Cache is also reset dynamically during back-end option updates. */ ($cache_needs_updating)
  94. {
  95. update_option ("ws_plugin__s2member_cache", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["cache"]);
  96. }
  97. $scheme = /* SSL mode? */ (is_ssl ()) ? "https" : "http";
  98. foreach /* Conversions for SSL and non-SSL mode. */ ($links as &$link)
  99. $link = preg_replace ("/^https?\:\/\//i", $scheme . "://", $link);
  100.  
  101. return apply_filters ("ws_plugin__s2member_cached_page_links", $links, get_defined_vars ());
  102. }
  103. }
  104. }
  105. ?>

s2member\includes\classes\cache.inc.php

Source Code Documentation