Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/sitepres.../lib/twig/src/Loader
File: FilesystemLoader.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of Twig.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
namespace WPML\Core\Twig\Loader;
[10] Fix | Delete
[11] Fix | Delete
use WPML\Core\Twig\Error\LoaderError;
[12] Fix | Delete
use WPML\Core\Twig\Source;
[13] Fix | Delete
/**
[14] Fix | Delete
* Loads template from the filesystem.
[15] Fix | Delete
*
[16] Fix | Delete
* @author Fabien Potencier <fabien@symfony.com>
[17] Fix | Delete
*/
[18] Fix | Delete
class FilesystemLoader implements \WPML\Core\Twig\Loader\LoaderInterface, \WPML\Core\Twig\Loader\ExistsLoaderInterface, \WPML\Core\Twig\Loader\SourceContextLoaderInterface
[19] Fix | Delete
{
[20] Fix | Delete
/** Identifier of the main namespace. */
[21] Fix | Delete
const MAIN_NAMESPACE = '__main__';
[22] Fix | Delete
protected $paths = [];
[23] Fix | Delete
protected $cache = [];
[24] Fix | Delete
protected $errorCache = [];
[25] Fix | Delete
private $rootPath;
[26] Fix | Delete
/**
[27] Fix | Delete
* @param string|array $paths A path or an array of paths where to look for templates
[28] Fix | Delete
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
[29] Fix | Delete
*/
[30] Fix | Delete
public function __construct($paths = [], $rootPath = null)
[31] Fix | Delete
{
[32] Fix | Delete
$this->rootPath = (null === $rootPath ? \getcwd() : $rootPath) . \DIRECTORY_SEPARATOR;
[33] Fix | Delete
if (\false !== ($realPath = \realpath($rootPath))) {
[34] Fix | Delete
$this->rootPath = $realPath . \DIRECTORY_SEPARATOR;
[35] Fix | Delete
}
[36] Fix | Delete
if ($paths) {
[37] Fix | Delete
$this->setPaths($paths);
[38] Fix | Delete
}
[39] Fix | Delete
}
[40] Fix | Delete
/**
[41] Fix | Delete
* Returns the paths to the templates.
[42] Fix | Delete
*
[43] Fix | Delete
* @param string $namespace A path namespace
[44] Fix | Delete
*
[45] Fix | Delete
* @return array The array of paths where to look for templates
[46] Fix | Delete
*/
[47] Fix | Delete
public function getPaths($namespace = self::MAIN_NAMESPACE)
[48] Fix | Delete
{
[49] Fix | Delete
return isset($this->paths[$namespace]) ? $this->paths[$namespace] : [];
[50] Fix | Delete
}
[51] Fix | Delete
/**
[52] Fix | Delete
* Returns the path namespaces.
[53] Fix | Delete
*
[54] Fix | Delete
* The main namespace is always defined.
[55] Fix | Delete
*
[56] Fix | Delete
* @return array The array of defined namespaces
[57] Fix | Delete
*/
[58] Fix | Delete
public function getNamespaces()
[59] Fix | Delete
{
[60] Fix | Delete
return \array_keys($this->paths);
[61] Fix | Delete
}
[62] Fix | Delete
/**
[63] Fix | Delete
* Sets the paths where templates are stored.
[64] Fix | Delete
*
[65] Fix | Delete
* @param string|array $paths A path or an array of paths where to look for templates
[66] Fix | Delete
* @param string $namespace A path namespace
[67] Fix | Delete
*/
[68] Fix | Delete
public function setPaths($paths, $namespace = self::MAIN_NAMESPACE)
[69] Fix | Delete
{
[70] Fix | Delete
if (!\is_array($paths)) {
[71] Fix | Delete
$paths = [$paths];
[72] Fix | Delete
}
[73] Fix | Delete
$this->paths[$namespace] = [];
[74] Fix | Delete
foreach ($paths as $path) {
[75] Fix | Delete
$this->addPath($path, $namespace);
[76] Fix | Delete
}
[77] Fix | Delete
}
[78] Fix | Delete
/**
[79] Fix | Delete
* Adds a path where templates are stored.
[80] Fix | Delete
*
[81] Fix | Delete
* @param string $path A path where to look for templates
[82] Fix | Delete
* @param string $namespace A path namespace
[83] Fix | Delete
*
[84] Fix | Delete
* @throws LoaderError
[85] Fix | Delete
*/
[86] Fix | Delete
public function addPath($path, $namespace = self::MAIN_NAMESPACE)
[87] Fix | Delete
{
[88] Fix | Delete
// invalidate the cache
[89] Fix | Delete
$this->cache = $this->errorCache = [];
[90] Fix | Delete
$checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath . $path;
[91] Fix | Delete
if (!\is_dir($checkPath)) {
[92] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError(\sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
[93] Fix | Delete
}
[94] Fix | Delete
$this->paths[$namespace][] = \rtrim($path, '/\\');
[95] Fix | Delete
}
[96] Fix | Delete
/**
[97] Fix | Delete
* Prepends a path where templates are stored.
[98] Fix | Delete
*
[99] Fix | Delete
* @param string $path A path where to look for templates
[100] Fix | Delete
* @param string $namespace A path namespace
[101] Fix | Delete
*
[102] Fix | Delete
* @throws LoaderError
[103] Fix | Delete
*/
[104] Fix | Delete
public function prependPath($path, $namespace = self::MAIN_NAMESPACE)
[105] Fix | Delete
{
[106] Fix | Delete
// invalidate the cache
[107] Fix | Delete
$this->cache = $this->errorCache = [];
[108] Fix | Delete
$checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath . $path;
[109] Fix | Delete
if (!\is_dir($checkPath)) {
[110] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError(\sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath));
[111] Fix | Delete
}
[112] Fix | Delete
$path = \rtrim($path, '/\\');
[113] Fix | Delete
if (!isset($this->paths[$namespace])) {
[114] Fix | Delete
$this->paths[$namespace][] = $path;
[115] Fix | Delete
} else {
[116] Fix | Delete
\array_unshift($this->paths[$namespace], $path);
[117] Fix | Delete
}
[118] Fix | Delete
}
[119] Fix | Delete
public function getSource($name)
[120] Fix | Delete
{
[121] Fix | Delete
@\trigger_error(\sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), \E_USER_DEPRECATED);
[122] Fix | Delete
if (null === ($path = $this->findTemplate($name)) || \false === $path) {
[123] Fix | Delete
return '';
[124] Fix | Delete
}
[125] Fix | Delete
return \file_get_contents($path);
[126] Fix | Delete
}
[127] Fix | Delete
public function getSourceContext($name)
[128] Fix | Delete
{
[129] Fix | Delete
if (null === ($path = $this->findTemplate($name)) || \false === $path) {
[130] Fix | Delete
return new \WPML\Core\Twig\Source('', $name, '');
[131] Fix | Delete
}
[132] Fix | Delete
return new \WPML\Core\Twig\Source(\file_get_contents($path), $name, $path);
[133] Fix | Delete
}
[134] Fix | Delete
public function getCacheKey($name)
[135] Fix | Delete
{
[136] Fix | Delete
if (null === ($path = $this->findTemplate($name)) || \false === $path) {
[137] Fix | Delete
return '';
[138] Fix | Delete
}
[139] Fix | Delete
$len = \strlen($this->rootPath);
[140] Fix | Delete
if (0 === \strncmp($this->rootPath, $path, $len)) {
[141] Fix | Delete
return \substr($path, $len);
[142] Fix | Delete
}
[143] Fix | Delete
return $path;
[144] Fix | Delete
}
[145] Fix | Delete
public function exists($name)
[146] Fix | Delete
{
[147] Fix | Delete
$name = $this->normalizeName($name);
[148] Fix | Delete
if (isset($this->cache[$name])) {
[149] Fix | Delete
return \true;
[150] Fix | Delete
}
[151] Fix | Delete
try {
[152] Fix | Delete
return null !== ($path = $this->findTemplate($name, \false)) && \false !== $path;
[153] Fix | Delete
} catch (\WPML\Core\Twig\Error\LoaderError $e) {
[154] Fix | Delete
@\trigger_error(\sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), \E_USER_DEPRECATED);
[155] Fix | Delete
return \false;
[156] Fix | Delete
}
[157] Fix | Delete
}
[158] Fix | Delete
public function isFresh($name, $time)
[159] Fix | Delete
{
[160] Fix | Delete
// false support to be removed in 3.0
[161] Fix | Delete
if (null === ($path = $this->findTemplate($name)) || \false === $path) {
[162] Fix | Delete
return \false;
[163] Fix | Delete
}
[164] Fix | Delete
return \filemtime($path) < $time;
[165] Fix | Delete
}
[166] Fix | Delete
/**
[167] Fix | Delete
* Checks if the template can be found.
[168] Fix | Delete
*
[169] Fix | Delete
* @param string $name The template name
[170] Fix | Delete
*
[171] Fix | Delete
* @return string|false|null The template name or false/null
[172] Fix | Delete
*/
[173] Fix | Delete
protected function findTemplate($name)
[174] Fix | Delete
{
[175] Fix | Delete
$throw = \func_num_args() > 1 ? \func_get_arg(1) : \true;
[176] Fix | Delete
$name = $this->normalizeName($name);
[177] Fix | Delete
if (isset($this->cache[$name])) {
[178] Fix | Delete
return $this->cache[$name];
[179] Fix | Delete
}
[180] Fix | Delete
if (isset($this->errorCache[$name])) {
[181] Fix | Delete
if (!$throw) {
[182] Fix | Delete
return \false;
[183] Fix | Delete
}
[184] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError($this->errorCache[$name]);
[185] Fix | Delete
}
[186] Fix | Delete
try {
[187] Fix | Delete
$this->validateName($name);
[188] Fix | Delete
list($namespace, $shortname) = $this->parseName($name);
[189] Fix | Delete
} catch (\WPML\Core\Twig\Error\LoaderError $e) {
[190] Fix | Delete
if (!$throw) {
[191] Fix | Delete
return \false;
[192] Fix | Delete
}
[193] Fix | Delete
throw $e;
[194] Fix | Delete
}
[195] Fix | Delete
if (!isset($this->paths[$namespace])) {
[196] Fix | Delete
$this->errorCache[$name] = \sprintf('There are no registered paths for namespace "%s".', $namespace);
[197] Fix | Delete
if (!$throw) {
[198] Fix | Delete
return \false;
[199] Fix | Delete
}
[200] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError($this->errorCache[$name]);
[201] Fix | Delete
}
[202] Fix | Delete
foreach ($this->paths[$namespace] as $path) {
[203] Fix | Delete
if (!$this->isAbsolutePath($path)) {
[204] Fix | Delete
$path = $this->rootPath . $path;
[205] Fix | Delete
}
[206] Fix | Delete
if (\is_file($path . '/' . $shortname)) {
[207] Fix | Delete
if (\false !== ($realpath = \realpath($path . '/' . $shortname))) {
[208] Fix | Delete
return $this->cache[$name] = $realpath;
[209] Fix | Delete
}
[210] Fix | Delete
return $this->cache[$name] = $path . '/' . $shortname;
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
$this->errorCache[$name] = \sprintf('Unable to find template "%s" (looked into: %s).', $name, \implode(', ', $this->paths[$namespace]));
[214] Fix | Delete
if (!$throw) {
[215] Fix | Delete
return \false;
[216] Fix | Delete
}
[217] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError($this->errorCache[$name]);
[218] Fix | Delete
}
[219] Fix | Delete
protected function parseName($name, $default = self::MAIN_NAMESPACE)
[220] Fix | Delete
{
[221] Fix | Delete
if (isset($name[0]) && '@' == $name[0]) {
[222] Fix | Delete
if (\false === ($pos = \strpos($name, '/'))) {
[223] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError(\sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name));
[224] Fix | Delete
}
[225] Fix | Delete
$namespace = \substr($name, 1, $pos - 1);
[226] Fix | Delete
$shortname = \substr($name, $pos + 1);
[227] Fix | Delete
return [$namespace, $shortname];
[228] Fix | Delete
}
[229] Fix | Delete
return [$default, $name];
[230] Fix | Delete
}
[231] Fix | Delete
protected function normalizeName($name)
[232] Fix | Delete
{
[233] Fix | Delete
return \preg_replace('#/{2,}#', '/', \str_replace('\\', '/', (string) $name));
[234] Fix | Delete
}
[235] Fix | Delete
protected function validateName($name)
[236] Fix | Delete
{
[237] Fix | Delete
if (\false !== \strpos($name, "\0")) {
[238] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError('A template name cannot contain NUL bytes.');
[239] Fix | Delete
}
[240] Fix | Delete
$name = \ltrim($name, '/');
[241] Fix | Delete
$parts = \explode('/', $name);
[242] Fix | Delete
$level = 0;
[243] Fix | Delete
foreach ($parts as $part) {
[244] Fix | Delete
if ('..' === $part) {
[245] Fix | Delete
--$level;
[246] Fix | Delete
} elseif ('.' !== $part) {
[247] Fix | Delete
++$level;
[248] Fix | Delete
}
[249] Fix | Delete
if ($level < 0) {
[250] Fix | Delete
throw new \WPML\Core\Twig\Error\LoaderError(\sprintf('Looks like you try to load a template outside configured directories (%s).', $name));
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
}
[254] Fix | Delete
private function isAbsolutePath($file)
[255] Fix | Delete
{
[256] Fix | Delete
return \strspn($file, '/\\', 0, 1) || \strlen($file) > 3 && \ctype_alpha($file[0]) && ':' === \substr($file, 1, 1) && \strspn($file, '/\\', 2, 1) || null !== \parse_url($file, \PHP_URL_SCHEME);
[257] Fix | Delete
}
[258] Fix | Delete
}
[259] Fix | Delete
\class_alias('WPML\\Core\\Twig\\Loader\\FilesystemLoader', 'WPML\\Core\\Twig_Loader_Filesystem');
[260] Fix | Delete
[261] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function