Server : LiteSpeed System : Linux server 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64 User : alsaif ( 1057) PHP Version : 7.4.33 Disable Function : show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/alsaif/public_html/plugins/system/nrframework/NRFramework/Conditions/Conditions/ |
<?php
/**
* @author Tassos.gr <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions;
defined('_JEXEC') or die;
use NRFramework\Functions;
use NRFramework\Conditions\Condition;
class URLBase extends Condition
{
public function prepareSelection()
{
return Functions::makeArray($this->getSelection());
}
/**
* Pass URL.
*
* @return bool Returns true if the current URL contains any of the selection URLs
*/
public function pass()
{
return $this->passURL();
}
/**
* Pass URL
*
* @param mixed $url If null, the current URL will be used. Otherwise we need a valid absolute URL.
*
* @return bool Returns true if the URL contains any of the selection URLs
*/
public function passURL($url = null)
{
// Get the current URL if none is passed
$url = is_null($url) ? $this->factory->getURL() : $url;
// Create an array with all possible values of the URL
$urls = array(
html_entity_decode(urldecode($url), ENT_COMPAT, 'UTF-8'),
urldecode($url),
html_entity_decode($url, ENT_COMPAT, 'UTF-8'),
$url
);
// Remove duplicates and invalid URLs
$urls = array_filter(array_unique($urls));
$regex = $this->params->get('regex', false);
$pass = false;
foreach ($urls as $url)
{
foreach ($this->getSelection() as $s)
{
// Skip empty selection URLs
$s = trim($s);
if (empty($s))
{
continue;
}
// Regular expression check
if ($regex)
{
$url_part = str_replace(array('#', '&'), array('\#', '(&|&)'), $s);
$s = '#' . $url_part . '#si';
if (@preg_match($s . 'u', $url) || @preg_match($s, $url))
{
$pass = true;
break;
}
continue;
}
// String check
if (strpos($url, $s) !== false)
{
$pass = true;
break;
}
}
if ($pass)
{
break;
}
}
return $pass;
}
}