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