| Server IP : 121.121.20.254 / Your IP : 216.73.216.66 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/KnowledgeBase/wp-content/plugins/aioseo-redirects/app/Utils/ |
Upload File : |
<?php
namespace AIOSEO\Plugin\Addon\Redirects\Utils;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use AIOSEO\Plugin\Addon\Redirects\Models;
/**
* Main class for redirects cache.
*
* @since 1.1.4
*/
class Cache extends \AIOSEO\Plugin\Common\Utils\Cache {
/**
* The redirect addon cache prefix.
*
* @since 1.1.4
*
* @var string
*/
protected $prefix = 'aioseo_redirects_';
/**
* The redirect URL cache prefix.
*
* @since 1.1.4
*
* @var string
*/
private $redirectUrlPrefix = 'url_';
/**
* Gets redirects from cache for a URL path.
*
* @since 1.1.4
*
* @param string $path The path.
* @return array An array of redirect results.
*/
public function getRedirects( $path ) {
$redirects = $this->get( $this->getUrlCacheName( $path ) );
if ( ! empty( $redirects ) ) {
foreach ( $redirects as &$redirect ) {
$redirect = new Models\Redirect( $redirect );
}
}
return $redirects;
}
/**
* Adds redirects to a URL path's cache.
*
* @since 1.1.4
*
* @param string $path The path.
* @param string $redirects Redirects to cache.
* @return void
*/
public function setRedirects( $path, $redirects ) {
foreach ( $redirects as &$redirect ) {
if ( is_a( $redirect, 'AIOSEO\Plugin\Addon\Redirects\Models\Redirect' ) ) {
if ( isset( $redirect->regexMatches ) ) {
$redirect = array_merge( $redirect->jsonSerialize(), [ 'regexMatches' => $redirect->regexMatches ] );
} else {
$redirect = $redirect->jsonSerialize();
}
}
}
$this->update( $this->getUrlCacheName( $path ), $redirects, WEEK_IN_SECONDS );
}
/**
* Deletes all redirects from cache.
*
* @since 1.1.4
*
* @return void
*/
public function clearRedirects() {
$this->clearPrefix( $this->redirectUrlPrefix );
}
/**
* Adds redirects to a URL path's cache.
*
* @since 1.1.4
*
* @param string $path The path.
* @return string The cache name.
*/
public function getUrlCacheName( $path ) {
return $this->redirectUrlPrefix . Request::getUrlHash( $path );
}
}