first commit
This commit is contained in:
306
plugins/system/nrframework/NRFramework/Assignments.php
Normal file
306
plugins/system/nrframework/NRFramework/Assignments.php
Normal file
@@ -0,0 +1,306 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework;
|
||||
|
||||
use NRFramework\Factory;
|
||||
use NRFramework\Conditions\ConditionsHelper;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
// @deprecated - Use \NRFramework\Condnitions\ConditionsHelper;
|
||||
class Assignments
|
||||
{
|
||||
/**
|
||||
* Assignment Type Aliases
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* @deprecated To be removed on Jan 1st 2023.
|
||||
*/
|
||||
public $typeAliases = array(
|
||||
'device|devices' => 'Device',
|
||||
'urls|url' => 'URL',
|
||||
'os' => 'OS',
|
||||
'browsers|browser' => 'Browser',
|
||||
'referrer' => 'Referrer',
|
||||
'php' => 'PHP',
|
||||
'timeonsite' => 'TimeOnSite',
|
||||
'pageviews|user_pageviews' => 'Pageviews',
|
||||
'lang|language|languages' => 'Joomla\Language',
|
||||
'usergroups|usergroup|user_groups' => 'Joomla\UserGroup',
|
||||
'user_id|userid' => 'Joomla\UserID',
|
||||
'menu' => 'Joomla\Menu',
|
||||
'components|component' => 'Joomla\Component',
|
||||
'datetime|daterange|date' => 'Date\Date',
|
||||
'weekday|days|day' => 'Date\Day',
|
||||
'months|month' => 'Date\Month',
|
||||
'timerange|time' => 'Date\Time',
|
||||
'acymailing' => 'AcyMailing',
|
||||
'akeebasubs' => 'AkeebaSubs',
|
||||
'engagebox|onotherbox' => 'EngageBox',
|
||||
'convertforms' => 'ConvertForms',
|
||||
'geo_country|country|countries' => 'Geo\Country',
|
||||
'geo_continent|continent|continents' => 'Geo\Continent',
|
||||
'geo_city|city|cities' => 'Geo\City',
|
||||
'geo_region|region|regions' => 'Geo\Region',
|
||||
'cookiename|cookie' => 'Cookie',
|
||||
'ip_addresses|iprange|ip' => 'IP',
|
||||
'k2_items|k2item' => 'Component\K2Item',
|
||||
'k2_cats|k2category' => 'Component\K2Category',
|
||||
'k2_tags|k2tag' => 'Component\K2Tag',
|
||||
'k2_pagetypes|k2pagetype' => 'Component\K2Pagetype',
|
||||
'contentcats|category' => 'Component\ContentCategory',
|
||||
'contentarticles|article' => 'Component\ContentArticle',
|
||||
'contentview' => 'Component\ContentView',
|
||||
'eventbookingsingle' => 'Component\EventBookingSingle',
|
||||
'eventbookingcategory' => 'Component\EventBookingCategory',
|
||||
'j2storesingle' => 'Component\J2StoreSingle',
|
||||
'j2storecategory' => 'Component\J2StoreCategory',
|
||||
'hikashopsingle' => 'Component\HikashopSingle',
|
||||
'hikashopcategory' => 'Component\HikashopCategory',
|
||||
'sppagebuildersingle' => 'Component\SPPageBuilderSingle',
|
||||
'sppagebuildercategory' => 'Component\SPPageBuilderCategory',
|
||||
'virtuemartcategory' => 'Component\VirtueMartCategory',
|
||||
'virtuemartsingle' => 'Component\VirtueMartSingle',
|
||||
'jshoppingsingle' => 'Component\JShoppingSingle',
|
||||
'jshoppingcategory' => 'Component\JShoppingCategory',
|
||||
'rsblogsingle' => 'Component\RSBlogSingle',
|
||||
'rsblogcategory' => 'Component\RSBlogCategory',
|
||||
'easyblogcategory' => 'Component\EasyBlogCategory',
|
||||
'easyblogsingle' => 'Component\EasyBlogSingle',
|
||||
'zoosingle' => 'Component\ZooSingle',
|
||||
'zoocategory' => 'Component\ZooCategory',
|
||||
'eshopcategory' => 'Component\EshopCategory',
|
||||
'eshopsingle' => 'Component\EshopSingle',
|
||||
'djcatalog2category' => 'Component\DJCatalog2Category',
|
||||
'djcatalog2single' => 'Component\DJCatalog2Single',
|
||||
'quixsingle' => 'Component\QuixSingle',
|
||||
'djclassifiedssingle' => 'Component\DJClassifiedsSingle',
|
||||
'djclassifiedscategory' => 'Component\DJClassifiedsCategory',
|
||||
'sobiprocategory' => 'Component\SobiProCategory',
|
||||
'sobiprosingle' => 'Component\SobiProSingle',
|
||||
'gridboxcategory' => 'Component\GridboxCategory',
|
||||
'gridboxsingle' => 'Component\GridboxSingle',
|
||||
'djeventscategory' => 'Component\DJEventsCategory',
|
||||
'djeventssingle' => 'Component\DJEventsSingle',
|
||||
'jcalprocategory' => 'Component\JCalProCategory',
|
||||
'jcalprosingle' => 'Component\JCalProSingle',
|
||||
'jbusinessdirectorybusinesscategory' => 'Component\JBusinessDirectoryBusinessCategory',
|
||||
'jbusinessdirectorybusinesssingle' => 'Component\JBusinessDirectoryBusinessSingle',
|
||||
'jbusinessdirectoryeventcategory' => 'Component\JBusinessDirectoryEventCategory',
|
||||
'jbusinessdirectoryeventsingle' => 'Component\JBusinessDirectoryEventSingle',
|
||||
'jbusinessdirectoryoffercategory' => 'Component\JBusinessDirectoryOfferCategory',
|
||||
'jbusinessdirectoryoffersingle' => 'Component\JBusinessDirectoryOfferSingle'
|
||||
);
|
||||
|
||||
/**
|
||||
* Factory object
|
||||
*
|
||||
* @var \NRFramework\Factory
|
||||
*/
|
||||
protected $factory;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*/
|
||||
public function __construct($factory = null)
|
||||
{
|
||||
$this->factory = is_null($factory) ? new Factory() : $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy method to check a set of rules.
|
||||
*
|
||||
* At the moment of writing this and the moment we're going to release a new version for EngageBox
|
||||
* which is going to introduce the new ConditionBuilder field, ACF and GSD will still be using the passAll() method.
|
||||
*
|
||||
* This forces us to keep this method for backwards compatibiliy reasons.
|
||||
* Additionally, it helps us to catch a special case where both ACF and GSD expect to pass all rules even if the array passed is null.
|
||||
*
|
||||
* @param array|object $assignments_info Array/Object containing assignment info
|
||||
* @param string $match_method The matching method (and|or) - Deprecated
|
||||
* @param bool $debug Set to true to request additional debug information about assignments
|
||||
*
|
||||
* @deprecated Use passSets() instead. To be removed on Jan 1st 2023
|
||||
*/
|
||||
public function passAll($assignments_info, $match_method = 'and')
|
||||
{
|
||||
$assignments = $this->prepareAssignments($assignments_info, $match_method);
|
||||
|
||||
$ch = new ConditionsHelper($this->factory);
|
||||
$pass = $ch->passSets($assignments);
|
||||
|
||||
// If the checks return null, consider this as Success. This is required for both ACF and GSD.
|
||||
return is_null($pass) ? true : $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the classname for a given assignment alias
|
||||
*
|
||||
* @param string $alias
|
||||
* @return string|void
|
||||
*
|
||||
* @deprecated To be removed on Jan 1st 2023
|
||||
*/
|
||||
public function aliasToClassname($alias)
|
||||
{
|
||||
$alias = strtolower($alias);
|
||||
foreach ($this->typeAliases as $aliases => $type)
|
||||
{
|
||||
if (strtolower($type) == $alias)
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
|
||||
$aliases = explode('|', strtolower($aliases));
|
||||
if (in_array($alias, $aliases))
|
||||
{
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks and prepares the given array of assignment information
|
||||
*
|
||||
* @param array $assignments_info
|
||||
* @return array
|
||||
*
|
||||
* @deprecated To be removed on Jan 1st 2023
|
||||
*/
|
||||
protected function prepareAssignments($data, $matching_method = 'all')
|
||||
{
|
||||
if (is_object($data))
|
||||
{
|
||||
return $this->prepareAssignmentsFromObject($data, $matching_method);
|
||||
}
|
||||
|
||||
if (!is_array($data) OR empty($data))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$rules = array_pop($data);
|
||||
|
||||
if (!is_array($rules) OR empty($rules))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($rules as &$rule)
|
||||
{
|
||||
if (is_array($rule))
|
||||
{
|
||||
foreach ($rule as &$_rule)
|
||||
{
|
||||
$_rule = $this->prepareAssignmentRule($_rule);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$rule = $this->prepareAssignmentRule($rule);
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
[
|
||||
'matching_method' => $matching_method == 'and' ? 'all' : 'any',
|
||||
'rules' => $rules
|
||||
]
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the assignment rule.
|
||||
*
|
||||
* @param object $rule
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
private function prepareAssignmentRule($rule)
|
||||
{
|
||||
return [
|
||||
'name' => $this->aliasToClassname($rule->alias),
|
||||
'operator' => (int) $rule->assignment_state == 1 ? 'includes' : 'not_includes',
|
||||
'value' => isset($rule->value) ? $rule->value : null,
|
||||
'params' => isset($rule->params) ? $rule->params : null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an object of assignment information to an array of groups
|
||||
* Used by existing extensions
|
||||
*
|
||||
* @param object $assignments_info
|
||||
* @param string $matching_method
|
||||
*
|
||||
* @deprecated To be removed on Jan 1st 2023
|
||||
*/
|
||||
public function prepareAssignmentsFromObject($assignments_info, $matching_method)
|
||||
{
|
||||
if (!isset($assignments_info->params))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$params = json_decode($assignments_info->params);
|
||||
|
||||
if (!is_object($params))
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$assignments_info = [];
|
||||
|
||||
foreach ($this->typeAliases as $aliases => $type)
|
||||
{
|
||||
$aliases = explode('|', $aliases);
|
||||
|
||||
foreach ($aliases as $alias)
|
||||
{
|
||||
if (!isset($params->{'assign_' . $alias}) || !$params->{'assign_' . $alias})
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Discover assignment params
|
||||
$assignment_params = new \stdClass();
|
||||
foreach ($params as $key => $value)
|
||||
{
|
||||
if (strpos($key, "assign_" . $alias . "_param") !== false)
|
||||
{
|
||||
$key = str_replace("assign_" . $alias . "_param_", "", $key);
|
||||
$assignment_params->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$assignments_info[] = [
|
||||
'name' => $this->aliasToClassname($alias),
|
||||
'operator' => (int) $params->{'assign_' . $alias} == 1 ? 'includes' : 'not_includes',
|
||||
'value' => isset($params->{'assign_' . $alias . '_list'}) ? $params->{'assign_' . $alias . '_list'} : [],
|
||||
'params' => $assignment_params
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$data = [
|
||||
[
|
||||
'matching_method' => $matching_method == 'and' ? 'all' : 'any',
|
||||
'rules' => $assignments_info
|
||||
]
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
112
plugins/system/nrframework/NRFramework/Cache.php
Normal file
112
plugins/system/nrframework/NRFramework/Cache.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file is deprecated. Use CacheManager instead of Cache.
|
||||
*/
|
||||
|
||||
namespace NRFramework;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use \NRFramework\CacheManager;
|
||||
/**
|
||||
* Caching mechanism
|
||||
*/
|
||||
class Cache
|
||||
{
|
||||
/**
|
||||
* Check if has alrady exists in memory
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
static public function has($hash)
|
||||
{
|
||||
$cache = CacheManager::getInstance(\JFactory::getCache('novarain', ''));
|
||||
return $cache->has($hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns hash value
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
*
|
||||
* @return mixed False on error, Object on success
|
||||
*/
|
||||
static public function get($hash)
|
||||
{
|
||||
$cache = CacheManager::getInstance(\JFactory::getCache('novarain', ''));
|
||||
return $cache->get($hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets on memory the hash value
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
* @param mixed $data Can be string or object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
static public function set($hash, $data)
|
||||
{
|
||||
$cache = CacheManager::getInstance(\JFactory::getCache('novarain', ''));
|
||||
return $cache->set($hash, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads hash value from memory or file
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
* @param boolean $force If true, the filesystem will be used as well on the /cache/ folder
|
||||
*
|
||||
* @return mixed The hash object valuw
|
||||
*/
|
||||
static public function read($hash, $force = false)
|
||||
{
|
||||
$cache = CacheManager::getInstance(\JFactory::getCache('novarain', ''));
|
||||
return $cache->read($hash, $force);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes hash value in cache folder
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
* @param mixed $data Can be string or object
|
||||
* @param integer $ttl Expiration duration in milliseconds
|
||||
*
|
||||
* @return mixed The hash object value
|
||||
*/
|
||||
static public function write($hash, $data, $ttl = 0)
|
||||
{
|
||||
$cache = CacheManager::getInstance(\JFactory::getCache('novarain', ''));
|
||||
return $cache->write($hash, $data, $ttl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Memoize a function to run once per runtime
|
||||
*
|
||||
* @param string $key The key to store the result of the callback
|
||||
* @param callback $callback The callable anonymous function to call
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
static public function memo($key, callable $callback)
|
||||
{
|
||||
$hash = md5($key);
|
||||
|
||||
if (Cache::has($hash))
|
||||
{
|
||||
return Cache::get($hash);
|
||||
}
|
||||
|
||||
return Cache::set($hash, $callback());
|
||||
}
|
||||
}
|
||||
142
plugins/system/nrframework/NRFramework/CacheManager.php
Normal file
142
plugins/system/nrframework/NRFramework/CacheManager.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* Cache Manager
|
||||
*
|
||||
* Singleton
|
||||
*/
|
||||
class CacheManager
|
||||
{
|
||||
/**
|
||||
* 'static' cache array
|
||||
* @var array
|
||||
*/
|
||||
protected $cache = [];
|
||||
|
||||
/**
|
||||
* Cache mechanism object
|
||||
* @var object
|
||||
*/
|
||||
protected $cache_mechanism = null;
|
||||
|
||||
/**
|
||||
* Construct
|
||||
*/
|
||||
protected function __construct($cache_mechanism)
|
||||
{
|
||||
$this->cache_mechanism = $cache_mechanism;
|
||||
}
|
||||
|
||||
static public function getInstance($cache_mechanism)
|
||||
{
|
||||
static $instance = null;
|
||||
|
||||
if ($instance === null)
|
||||
{
|
||||
$instance = new CacheManager($cache_mechanism);
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a hash already exists in memory
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($hash)
|
||||
{
|
||||
return isset($this->cache[$hash]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash's value
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
*
|
||||
* @return mixed False on error, Object on success
|
||||
*/
|
||||
public function get($hash)
|
||||
{
|
||||
if (!$this->has($hash))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return is_object($this->cache[$hash]) ? clone $this->cache[$hash] : $this->cache[$hash];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a hash value
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
* @param mixed $data Can be string or object
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function set($hash, $data)
|
||||
{
|
||||
$this->cache[$hash] = $data;
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a hash value from memory or file
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
* @param boolean $force If true, the filesystem will be used as well on the /cache/ folder
|
||||
*
|
||||
* @return mixed The hash object value
|
||||
*/
|
||||
public function read($hash, $force = false)
|
||||
{
|
||||
if ($this->has($hash))
|
||||
{
|
||||
return $this->get($hash);
|
||||
}
|
||||
|
||||
if ($force)
|
||||
{
|
||||
$this->cache_mechanism->setCaching(true);
|
||||
}
|
||||
|
||||
return $this->cache_mechanism->get($hash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes hash value in cache folder
|
||||
*
|
||||
* @param string $hash The hash string
|
||||
* @param mixed $data Can be string or object
|
||||
* @param integer $ttl Expiration duration in milliseconds
|
||||
*
|
||||
* @return mixed The hash object value
|
||||
*/
|
||||
public function write($hash, $data, $ttl = 0)
|
||||
{
|
||||
if ($ttl)
|
||||
{
|
||||
$this->cache_mechanism->setLifeTime($ttl * 60);
|
||||
}
|
||||
|
||||
$this->cache_mechanism->setCaching(true);
|
||||
$this->cache_mechanism->store($data, $hash);
|
||||
|
||||
$this->set($hash, $data);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
410
plugins/system/nrframework/NRFramework/Conditions/Condition.php
Normal file
410
plugins/system/nrframework/NRFramework/Conditions/Condition.php
Normal file
@@ -0,0 +1,410 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\String\StringHelper;
|
||||
|
||||
/**
|
||||
* Assignment Class
|
||||
*/
|
||||
class Condition
|
||||
{
|
||||
/**
|
||||
* Application Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Document Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $doc;
|
||||
|
||||
/**
|
||||
* Date Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $date;
|
||||
|
||||
/**
|
||||
* Database Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* User Object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* Assignment Selection
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $selection;
|
||||
|
||||
/**
|
||||
* Assignment Parameters
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $params;
|
||||
|
||||
/**
|
||||
* Assignment State (Include|Exclude)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $assignment;
|
||||
|
||||
/**
|
||||
* Options
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $options;
|
||||
|
||||
/**
|
||||
* Framework factory object
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
public $factory;
|
||||
|
||||
/**
|
||||
* The default operator that will be used to compare haystack with needle.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $operator;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $options The rule options. Expected properties: selection, value, params
|
||||
* @param object $factory The framework's factory class.
|
||||
*/
|
||||
public function __construct($options = null, $factory = null)
|
||||
{
|
||||
$this->factory = is_null($factory) ? new \NRFramework\Factory() : $factory;
|
||||
|
||||
// Set General Joomla Objects
|
||||
$this->db = $this->factory->getDbo();
|
||||
$this->app = $this->factory->getApplication();
|
||||
$this->doc = $this->factory->getDocument();
|
||||
$this->user = $this->factory->getUser();
|
||||
|
||||
$this->options = new Registry($options);
|
||||
|
||||
$this->setParams($this->options->get('params'));
|
||||
$this->setOperator($this->options->get('operator', 'includesSome'));
|
||||
|
||||
// For performance reasons we might move this inside the pass() method
|
||||
$this->setSelection($this->options->get('selection', ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rule's user selected value
|
||||
*
|
||||
* @param mixed $selection
|
||||
* @return object
|
||||
*/
|
||||
public function setSelection($selection)
|
||||
{
|
||||
$this->selection = $selection;
|
||||
|
||||
if (method_exists($this, 'prepareSelection'))
|
||||
{
|
||||
$this->selection = $this->prepareSelection();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getSelection()
|
||||
{
|
||||
return $this->selection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the operator that will be used for the comparison
|
||||
*
|
||||
* @param string $operator
|
||||
* @return object
|
||||
*/
|
||||
public function setOperator($operator)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rule's parameters
|
||||
*
|
||||
* @param array $params
|
||||
*/
|
||||
public function setParams($params)
|
||||
{
|
||||
$this->params = new Registry($params);
|
||||
}
|
||||
|
||||
public function getParams()
|
||||
{
|
||||
return $this->params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the validitity of two values based on the given operator.
|
||||
*
|
||||
* Consider converting this method as a Trait.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed $selection
|
||||
* @param string $operator
|
||||
* @param array $options ignoreCase: true,false
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function passByOperator($value = null, $selection = null, $operator = null, $options = null)
|
||||
{
|
||||
$value = is_null($value) ? $this->value() : $value;
|
||||
|
||||
if (!is_null($selection))
|
||||
{
|
||||
$this->setSelection($selection);
|
||||
}
|
||||
|
||||
$selection = $this->getSelection();
|
||||
|
||||
$options = new Registry($options);
|
||||
$ignoreCase = $options->get('ignoreCase', true);
|
||||
|
||||
if (is_object($value))
|
||||
{
|
||||
$value = (array) $value;
|
||||
}
|
||||
|
||||
if (is_object($selection))
|
||||
{
|
||||
$selection = (array) $selection;
|
||||
}
|
||||
|
||||
if ($ignoreCase)
|
||||
{
|
||||
if (is_string($value))
|
||||
{
|
||||
$value = strtolower($value);
|
||||
}
|
||||
|
||||
if (is_string($selection))
|
||||
{
|
||||
$selection = strtolower($selection);
|
||||
}
|
||||
|
||||
if (is_array($value))
|
||||
{
|
||||
$value = array_map('strtolower', $value);
|
||||
}
|
||||
|
||||
if (is_array($selection))
|
||||
{
|
||||
$selection = array_map('strtolower', $selection);
|
||||
}
|
||||
}
|
||||
|
||||
$operator = (is_null($operator) OR empty($operator)) ? $this->operator : $operator;
|
||||
$pass = false;
|
||||
|
||||
switch ($operator)
|
||||
{
|
||||
case 'exists':
|
||||
$pass = !is_null($value);
|
||||
break;
|
||||
|
||||
// Determines whether haystack is empty. Accepts: array, string
|
||||
case 'empty':
|
||||
if (is_array($value))
|
||||
{
|
||||
$pass = empty($value);
|
||||
}
|
||||
|
||||
if (is_string($value))
|
||||
{
|
||||
$pass = $value == '' || trim($value) == '';
|
||||
}
|
||||
break;
|
||||
|
||||
// Determine whether haystack is less than needle.
|
||||
case 'less_than':
|
||||
$pass = $value < $selection;
|
||||
break;
|
||||
|
||||
// Determine whether haystack is less than or equal to needle.
|
||||
case 'less_than_or_equal_to':
|
||||
$pass = $value <= $selection;
|
||||
break;
|
||||
|
||||
// Determine whether haystack is greater than needle.
|
||||
case 'greater_than':
|
||||
$pass = $value > $selection;
|
||||
break;
|
||||
|
||||
// Determine whether haystack is greater than or equal to needle.
|
||||
case 'greater_than_or_equal_to':
|
||||
$pass = $value >= $selection;
|
||||
break;
|
||||
|
||||
// Determine whether haystack contains all elements in needle.
|
||||
case 'includesAll':
|
||||
$pass = count(array_intersect((array) $selection, (array) $value)) == count((array) $selection);
|
||||
break;
|
||||
|
||||
// Determine whether haystack contains at least one element from needle.
|
||||
case 'includesSome':
|
||||
$pass = !empty(array_intersect((array) $value, (array) $selection));
|
||||
break;
|
||||
|
||||
// Determine whether haystack contains at least one element from needle. Accepts; string, array.
|
||||
case 'includes':
|
||||
if (is_string($value) && $value != '' && is_string($selection) && $selection != '')
|
||||
{
|
||||
if (StringHelper::strpos($value, $selection) !== false)
|
||||
{
|
||||
$pass = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value) || is_array($selection))
|
||||
{
|
||||
$pass = $this->passByOperator($value, $selection, 'includesSome', $options);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// Determine whether haystack starts with needle. Accepts: string
|
||||
case 'starts_with':
|
||||
$pass = StringHelper::substr($value, 0, StringHelper::strlen($selection)) === $selection;
|
||||
break;
|
||||
|
||||
// Determine whether haystack ends with needle. Accepts: string
|
||||
case 'ends_with':
|
||||
$pass = StringHelper::substr($value, -StringHelper::strlen($selection)) === $selection;
|
||||
break;
|
||||
|
||||
// Determine whether haystack equals to needle. Accepts any object.
|
||||
default:
|
||||
$pass = $value == $selection;
|
||||
}
|
||||
|
||||
return $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base assignment check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passByOperator();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all parent rows
|
||||
*
|
||||
* This method doesn't belong here. Move it to Functions.php.
|
||||
*
|
||||
* @param integer $id Row primary key
|
||||
* @param string $table Table name
|
||||
* @param string $parent Parent column name
|
||||
* @param string $child Child column name
|
||||
*
|
||||
* @return array Array with IDs
|
||||
*/
|
||||
public function getParentIds($id = 0, $table = 'menu', $parent = 'parent_id', $child = 'id')
|
||||
{
|
||||
if (!$id)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$cache = $this->factory->getCache();
|
||||
$hash = md5('getParentIds_' . $id . '_' . $table . '_' . $parent . '_' . $child);
|
||||
|
||||
if ($cache->has($hash))
|
||||
{
|
||||
return $cache->get($hash);
|
||||
}
|
||||
|
||||
$parent_ids = array();
|
||||
|
||||
while ($id)
|
||||
{
|
||||
$query = $this->db->getQuery(true)
|
||||
->select('t.' . $parent)
|
||||
->from('#__' . $table . ' as t')
|
||||
->where('t.' . $child . ' = ' . (int) $id);
|
||||
$this->db->setQuery($query);
|
||||
$id = $this->db->loadResult();
|
||||
|
||||
// Break if no parent is found or parent already found before for some reason
|
||||
if (!$id || in_array($id, $parent_ids))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
$parent_ids[] = $id;
|
||||
}
|
||||
|
||||
return $cache->set($hash, $parent_ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* A one-line text that describes the current value detected by the rule. Eg: The current time is %s.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueHint()
|
||||
{
|
||||
$value = $this->value();
|
||||
|
||||
// If the rule returns an array, use the 1st one.
|
||||
$value = is_array($value) ? $value[0] : $value;
|
||||
|
||||
return \JText::sprintf('NR_DISPLAY_CONDITIONS_HINT_' . strtoupper($this->getName()), ucfirst(strtolower($value)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the rule name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
$classParts = explode('\\', get_called_class());
|
||||
return array_pop($classParts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Layout\LayoutHelper;
|
||||
use NRFramework\Conditions\ConditionsHelper;
|
||||
use NRFramework\Extension;
|
||||
|
||||
class ConditionBuilder
|
||||
{
|
||||
public static function pass($rules)
|
||||
{
|
||||
$rules = self::prepareRules($rules);
|
||||
|
||||
if (empty($rules))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return ConditionsHelper::getInstance()->passSets($rules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare rules object to run checks
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function prepareRules($rules)
|
||||
{
|
||||
$rules_ = [];
|
||||
|
||||
foreach ($rules as $key => $group)
|
||||
{
|
||||
if (isset($group['enabled']) AND !(bool) $group['enabled'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// A group without rules, doesn't make sense.
|
||||
if (!isset($group['rules']) OR (isset($group['rules']) AND empty($group['rules'])))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$validRules = [];
|
||||
|
||||
foreach ($group['rules'] as $rule)
|
||||
{
|
||||
// Make sure rule has a name.
|
||||
if (!isset($rule['name']) OR (isset($rule['name']) AND empty($rule['name'])))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Rule is invalid if both value and params properties are empty
|
||||
if (!isset($rule['value']) && !isset($rule['params']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip disabled rules
|
||||
if (isset($rule['enabled']) && !(bool) $rule['enabled'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// We don't need this property.
|
||||
unset($rule['enabled']);
|
||||
|
||||
// Prepare rule value if necessary
|
||||
if (isset($rule['value']))
|
||||
{
|
||||
$rule['value'] = self::prepareTFRepeaterValue($rule['value']);
|
||||
}
|
||||
|
||||
// Verify operator
|
||||
if (!isset($rule['operator']) OR (isset($rule['operator']) && empty($rule['operator'])))
|
||||
{
|
||||
$rule['operator'] = isset($rule['params']['operator']) ? $rule['params']['operator'] : '';
|
||||
}
|
||||
|
||||
$validRules[] = $rule;
|
||||
}
|
||||
|
||||
if (count($validRules) > 0)
|
||||
{
|
||||
$group['rules'] = $validRules;
|
||||
|
||||
if (!isset($group['matching_method']) OR (isset($group['matching_method']) AND empty($group['matching_method'])))
|
||||
{
|
||||
$group['matching_method'] = 'all';
|
||||
}
|
||||
|
||||
unset($group['enabled']);
|
||||
$rules_[] = $group;
|
||||
}
|
||||
}
|
||||
|
||||
return $rules_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the value of the TF Repeater Input field.
|
||||
*
|
||||
* @param array $selection
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function prepareTFRepeaterValue($selection)
|
||||
{
|
||||
// Only proceed when we have an array of arrays selection.
|
||||
if (!is_array($selection))
|
||||
{
|
||||
return $selection;
|
||||
}
|
||||
|
||||
$first = array_values($selection)[0];
|
||||
|
||||
if (!is_array($first))
|
||||
{
|
||||
return $selection;
|
||||
}
|
||||
|
||||
if (!isset($first['value']))
|
||||
{
|
||||
return $selection;
|
||||
}
|
||||
|
||||
$new_selection = [];
|
||||
|
||||
foreach ($selection as $value)
|
||||
{
|
||||
/**
|
||||
* We expect a `value` key for TFInputRepeater fields or a key,value pair
|
||||
* for plain arrays.
|
||||
*/
|
||||
if (!isset($value['value']))
|
||||
{
|
||||
/**
|
||||
* If no value exists, it means that the passed $assignment->selection is a key,value pair array so we use the value
|
||||
* as our returned selection.
|
||||
*
|
||||
* This happens when we pass a key,value pair array as $assignment->selection when we expect a TFInputRepeater value
|
||||
* so we need to take this into consideration.
|
||||
*/
|
||||
$new_selection[] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
// value must not be empty
|
||||
if (empty(trim($value['value'])))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$new_selection[] = $value['value'];
|
||||
}
|
||||
|
||||
return $new_selection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the TGeoIP plugin modal.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getGeoModal()
|
||||
{
|
||||
// Do not proceed if the database is up-to-date
|
||||
if (!\NRFramework\Extension::geoPluginNeedsUpdate())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
\Joomla\CMS\HTML\HTMLHelper::_('bootstrap.modal');
|
||||
|
||||
$modalName = 'tf-geodbchecker-modal';
|
||||
|
||||
// The TGeoIP Plugin URL
|
||||
$url = \JURI::base(true) . '/index.php?option=com_plugins&view=plugin&tmpl=component&layout=modal&extension_id=' . \NRFramework\Functions::getExtensionID('tgeoip', 'system');
|
||||
|
||||
$options = [
|
||||
'title' => \JText::_('NR_EDIT'),
|
||||
'url' => $url,
|
||||
'height' => '400px',
|
||||
'backdrop' => 'static',
|
||||
'bodyHeight' => '70',
|
||||
'modalWidth' => '70',
|
||||
'footer' => '<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" data-dismiss="modal" aria-hidden="true">'
|
||||
. \JText::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>
|
||||
<button type="button" class="btn btn-success" aria-hidden="true"
|
||||
onclick="jQuery(\'#' . $modalName . ' iframe\').contents().find(\'#applyBtn\').click();">'
|
||||
. \JText::_('JAPPLY') . '</button>',
|
||||
];
|
||||
|
||||
return \JHtml::_('bootstrap.renderModal', $modalName, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the given rules list.
|
||||
*
|
||||
* @param array $list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function prepareXmlRulesList($list)
|
||||
{
|
||||
if (is_array($list))
|
||||
{
|
||||
$list = implode(',', array_map('trim', $list));
|
||||
}
|
||||
else if (is_string($list))
|
||||
{
|
||||
$list = str_replace(' ', '', $list);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new condition item or group.
|
||||
*
|
||||
* @param string $controlGroup The name of the input used to store the data.
|
||||
* @param string $groupKey The group index ID.
|
||||
* @param string $conditionKey The added condition item index ID.
|
||||
* @param array $condition The condition name we are adding.
|
||||
* @param string $include_rules The list of included conditions that override the available conditions.
|
||||
* @param string $exclude_rules The list of excluded conditions that override the available conditions.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function add($controlGroup, $groupKey, $conditionKey, $condition = null, $include_rules = [], $exclude_rules = [])
|
||||
{
|
||||
$controlGroup_ = $controlGroup . "[$groupKey][rules][$conditionKey]"; // @Todo - rename input namespace to 'conditions'
|
||||
$form = self::getForm('conditionbuilder/base.xml', $controlGroup_, $condition);
|
||||
$form->setFieldAttribute('name', 'include_rules', is_array($include_rules) ? implode(',', $include_rules) : $include_rules);
|
||||
$form->setFieldAttribute('name', 'exclude_rules', is_array($exclude_rules) ? implode(',', $exclude_rules) : $exclude_rules);
|
||||
|
||||
$options = [
|
||||
'name' => $controlGroup_,
|
||||
'enabled' => !isset($condition['enabled']) ? true : (string) $condition['enabled'] == '1',
|
||||
'toolbar' => $form,
|
||||
'groupKey' => $groupKey,
|
||||
'conditionKey' => $conditionKey,
|
||||
'options' => ''
|
||||
];
|
||||
|
||||
if (isset($condition['name']))
|
||||
{
|
||||
$optionsHTML = self::renderOptions($condition['name'], $controlGroup_, $condition);
|
||||
$options['condition_name'] = $condition['name'];
|
||||
$options['options'] = $optionsHTML;
|
||||
}
|
||||
|
||||
return self::getLayout('conditionbuilder_row', $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render condition item settings.
|
||||
*
|
||||
* @param string $name The name of the condition item.
|
||||
* @param string $controlGroup The name of the input used to store the data.
|
||||
* @param object $formData The data that will be bound to the form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function renderOptions($name, $controlGroup = null, $formData = null)
|
||||
{
|
||||
if (!$form = self::getForm('conditions/' . strtolower(str_replace('\\', '/', $name)) . '.xml', $controlGroup, $formData))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$form->setFieldAttribute('note', 'ruleName', $name);
|
||||
|
||||
return $form->renderFieldset('general');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles loading condition builder given a payload.
|
||||
*
|
||||
* @param array $payload
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function initLoad($payload = [])
|
||||
{
|
||||
if (!$payload)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($payload['data']) &&
|
||||
!isset($payload['name']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$data = json_decode($payload['data']))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// transform object to assosiative array
|
||||
$data = json_decode(json_encode($data), true);
|
||||
|
||||
// html of condition builder
|
||||
$html = '';
|
||||
|
||||
$include_rules = isset($payload['include_rules']) ? $payload['include_rules'] : [];
|
||||
$exclude_rules = isset($payload['exclude_rules']) ? $payload['exclude_rules'] : [];
|
||||
|
||||
foreach ($data as $groupKey => $groupConditions)
|
||||
{
|
||||
$payload = [
|
||||
'name' => $payload['name'],
|
||||
'groupKey' => $groupKey,
|
||||
'groupConditions' => $groupConditions,
|
||||
'include_rules' => $include_rules,
|
||||
'exclude_rules' => $exclude_rules
|
||||
];
|
||||
|
||||
$html .= self::getLayout('conditionbuilder_group', $payload);
|
||||
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a layout given its name and payload.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $payload
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getLayout($name, $payload)
|
||||
{
|
||||
return LayoutHelper::render($name, $payload, JPATH_PLUGINS . '/system/nrframework/layouts');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the form by binding given data.
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $controlGroup
|
||||
* @param array $data
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
private static function getForm($name, $controlGroup, $data = null)
|
||||
{
|
||||
if (!file_exists(JPATH_PLUGINS . '/system/nrframework/xml/' . $name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$form = new \JForm('cb', ['control' => $controlGroup]);
|
||||
|
||||
$form->addFieldPath(JPATH_PLUGINS . '/system/nrframework/fields');
|
||||
$form->loadFile(JPATH_PLUGINS . '/system/nrframework/xml/' . $name);
|
||||
|
||||
if (!is_null($data))
|
||||
{
|
||||
$form->bind($data);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class AcyMailing extends Condition
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return array AcyMailing lists
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getSubscribedLists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all AcyMailing lists the user is subscribed to
|
||||
*
|
||||
* @return array AcyMailing lists
|
||||
*/
|
||||
private function getSubscribedLists()
|
||||
{
|
||||
if (!$user = $this->user->id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get a db connection.
|
||||
$db = $this->db;
|
||||
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$lists = [];
|
||||
|
||||
// Read AcyMailing v5 lists
|
||||
if (\NRFramework\Extension::isInstalled('com_acymailing'))
|
||||
{
|
||||
$query
|
||||
->select(array('list.listid'))
|
||||
->from($db->quoteName('#__acymailing_listsub', 'list'))
|
||||
->join('INNER', $db->quoteName('#__acymailing_subscriber', 'sub') . ' ON (' . $db->quoteName('list.subid') . '=' . $db->quoteName('sub.subid') . ')')
|
||||
->where($db->quoteName('list.status') . ' = 1')
|
||||
->where($db->quoteName('sub.userid') . ' = ' . $user)
|
||||
->where($db->quoteName('sub.confirmed') . ' = 1')
|
||||
->where($db->quoteName('sub.enabled') . ' = 1');
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$db->setQuery($query);
|
||||
|
||||
if ($cols = $db->loadColumn())
|
||||
{
|
||||
$lists = array_merge($lists, $cols);
|
||||
}
|
||||
}
|
||||
|
||||
// Read AcyMailing > v5 lists
|
||||
if (\NRFramework\Extension::isInstalled('com_acym'))
|
||||
{
|
||||
// Create a new query object.
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query
|
||||
->select(['list.id'])
|
||||
->from($db->quoteName('#__acym_user_has_list', 'userlist'))
|
||||
->join('INNER', $db->quoteName('#__acym_list', 'list') . ' ON (' . $db->quoteName('list.id') . '=' . $db->quoteName('userlist.list_id') . ')')
|
||||
->join('INNER', $db->quoteName('#__acym_user', 'user') . ' ON (' . $db->quoteName('user.id') . '=' . $db->quoteName('userlist.user_id') . ')')
|
||||
->where($db->quoteName('user.cms_id') . ' = ' . $user)
|
||||
->where($db->quoteName('userlist.status') . ' = 1')
|
||||
->where($db->quoteName('userlist.unsubscribe_date') . ' IS NULL');
|
||||
|
||||
// Reset the query using our newly populated query object.
|
||||
$db->setQuery($query);
|
||||
|
||||
$cols = $db->loadColumn();
|
||||
|
||||
foreach ($cols as $value)
|
||||
{
|
||||
$lists[] = '6:' . $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class AkeebaSubs extends Condition
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return array Akeeba Subscriptions
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getlevels();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all user's active subscriptions
|
||||
*
|
||||
* @param int $userid User's id
|
||||
*
|
||||
* @return array Akeeba Subscriptions
|
||||
*/
|
||||
private function getLevels()
|
||||
{
|
||||
if (!$user = $this->user->id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!defined('FOF30_INCLUDED') && !@include_once(JPATH_LIBRARIES . '/fof30/include.php'))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the Akeeba Subscriptions container. Also includes the autoloader.
|
||||
$container = \FOF30\Container\Container::getInstance('com_akeebasubs');
|
||||
|
||||
$subscriptionsModel = $container->factory->model('Subscriptions')->tmpInstance();
|
||||
|
||||
$items = $subscriptionsModel
|
||||
->user_id($user)
|
||||
->enabled(1)
|
||||
->get();
|
||||
|
||||
if (!$items->count())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$levels = array();
|
||||
|
||||
foreach ($items as $subscription)
|
||||
{
|
||||
$levels[] = $subscription->akeebasubs_level_id;
|
||||
}
|
||||
|
||||
return array_unique($levels);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class Browser extends Condition
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return string Browser name
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->factory->getBrowser()['name'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use NRFramework\Conditions\Condition;
|
||||
use NRFramework\Functions;
|
||||
|
||||
/**
|
||||
* Base class used by component-based assignments. Class properties defaults to com_content.
|
||||
*/
|
||||
abstract class ComponentBase extends Condition
|
||||
{
|
||||
/**
|
||||
* The component's Category Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewCategory = 'category';
|
||||
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'article';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_content';
|
||||
|
||||
/**
|
||||
* Request information
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $request = null;
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options = null, $factory = null)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
|
||||
$request = new \stdClass;
|
||||
|
||||
$request->view = $this->app->input->get('view');
|
||||
$request->task = $this->app->input->get('task');
|
||||
$request->option = $this->app->input->get('option');
|
||||
$request->layout = $this->app->input->get('layout');
|
||||
$request->id = $this->app->input->getInt('id');
|
||||
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return array Category IDs
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getCategoryIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the current view concerns a Category view
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isCategoryPage()
|
||||
{
|
||||
return ($this->request->view == $this->viewCategory);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the current view concerncs a Single Page view
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSinglePage()
|
||||
{
|
||||
return ($this->request->view == $this->viewSingle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we are in the right context and we're manipulating the correct component
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function passContext()
|
||||
{
|
||||
return ($this->request->option == $this->component_option);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns category IDs based
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCategoryIDs()
|
||||
{
|
||||
$id = $this->request->id;
|
||||
|
||||
// Make sure we have an ID.
|
||||
if (empty($id))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// If this is a Category page, return the Category ID from the Query String
|
||||
if ($this->isCategoryPage())
|
||||
{
|
||||
return (array) $id;
|
||||
}
|
||||
|
||||
// If this is a Single Page, return all assosiated Category IDs.
|
||||
if ($this->isSinglePage())
|
||||
{
|
||||
return $this->getSinglePageCategories($id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current page is within the selected categories
|
||||
*
|
||||
* @param string $ref_table The referenced table
|
||||
* @param string $ref_parent_column The name of the parent column in the referenced table
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function passCategories($ref_table = 'categories', $ref_parent_column = 'parent_id')
|
||||
{
|
||||
if (empty($this->selection) || !$this->passContext())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Include Children switch: 0 = No, 1 = Yes, 2 = Child Only
|
||||
$inc_children = $this->params->get('inc_children');
|
||||
|
||||
// Setup supported views
|
||||
$view_single = $this->params->get('view_single', true);
|
||||
$view_category = $this->params->get('view_category', false);
|
||||
|
||||
// Check if we are in a valid context
|
||||
if (!($view_category && $this->isCategoryPage()) && !($view_single && $this->isSinglePage()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Start Checks
|
||||
$pass = false;
|
||||
|
||||
// Get current page assosiated category IDs. It can be a single ID of the current Category view or multiple IDs assosiated to active item.
|
||||
$catids = $this->getCategoryIds();
|
||||
$catids = is_array($catids) ? $catids : (array) $catids;
|
||||
|
||||
foreach ($catids as $catid)
|
||||
{
|
||||
$pass = in_array($catid, $this->selection);
|
||||
|
||||
if ($pass)
|
||||
{
|
||||
// If inc_children is either disabled or set to 'Also on Childs', there's no need for further checks.
|
||||
// The condition is already passed.
|
||||
if (in_array($this->params->get('inc_children'), [0, 1]))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
// We are here because we need childs only. Disable pass and continue checking parent IDs.
|
||||
$pass = false;
|
||||
}
|
||||
|
||||
// Pass check for child items
|
||||
if (!$pass && $this->params->get('inc_children'))
|
||||
{
|
||||
$parent_ids = $this->getParentIDs($catid, $ref_table, $ref_parent_column);
|
||||
|
||||
foreach ($parent_ids as $id)
|
||||
{
|
||||
if (in_array($id, $this->selection))
|
||||
{
|
||||
$pass = true;
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
unset($parent_ids);
|
||||
}
|
||||
}
|
||||
|
||||
return $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this page passes the validation
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function passSinglePage()
|
||||
{
|
||||
// Make sure we are in the right context
|
||||
if (empty($this->selection) || !$this->passContext() || !$this->isSinglePage())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!is_array($this->selection))
|
||||
{
|
||||
$this->selection = Functions::makeArray($this->selection);
|
||||
}
|
||||
|
||||
return parent::pass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function getSinglePageCategories($id);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ContentArticle extends ContentBase
|
||||
{
|
||||
/**
|
||||
* Pass check for Joomla! Articles
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int Article ID
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ContentBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param integer The Single Page id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
// If the article is not assigned to any menu item, the cat id should be available in the query string. Let's check it.
|
||||
if ($requestCatID = $this->app->input->getInt('catid', null))
|
||||
{
|
||||
return $requestCatID;
|
||||
}
|
||||
|
||||
// Apparently, the catid is not available in the Query String. Let's ask Article model.
|
||||
$item = $this->getItem($id);
|
||||
|
||||
if (is_object($item) && isset($item->catid))
|
||||
{
|
||||
return $item->catid;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a Joomla article data object.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getItem($id = null)
|
||||
{
|
||||
$id = is_null($id) ? $this->request->id : $id;
|
||||
$hash = md5('contentItem' . $id);
|
||||
$cache = $this->factory->getCache();
|
||||
|
||||
if ($cache->has($hash))
|
||||
{
|
||||
return $cache->get($hash);
|
||||
}
|
||||
|
||||
// Setup model
|
||||
if (defined('nrJ4'))
|
||||
{
|
||||
$model = new \Joomla\Component\Content\Site\Model\ArticleModel(['ignore_request' => true]);
|
||||
$model->setState('article.id', $id);
|
||||
$model->setState('params', $this->app->getParams());
|
||||
} else
|
||||
{
|
||||
require_once JPATH_SITE . '/components/com_content/models/article.php';
|
||||
$model = \JModelLegacy::getInstance('Article', 'ContentModel');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$item = $model->getItem($id);
|
||||
return $cache->set($hash, $item);
|
||||
}
|
||||
catch (\JException $e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ContentCategory extends ContentBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ContentView extends ContentBase
|
||||
{
|
||||
/**
|
||||
* Pass check for Joomla! Articles
|
||||
*
|
||||
* @return bool
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
// Make sure we are in the right context
|
||||
if (empty($this->selection) || !$this->passContext())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// In the Joomla Content component, the 'view' query parameter equals to 'category' in both Category List and Category Blog views.
|
||||
// In order to distinguish them we are using the 'layout' parameter as well.
|
||||
if ($this->request->view == 'category' && $this->request->layout)
|
||||
{
|
||||
$this->request->view .= '_' . $this->request->layout;
|
||||
}
|
||||
|
||||
return $this->passByOperator($this->request->view, $this->selection, 'includes');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJCatalog2Base extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'item';
|
||||
|
||||
/**
|
||||
* The component's Category Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewCategory = 'items';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_djcatalog2';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('category_id'))
|
||||
->from($db->quoteName('#__djc2_items_categories'))
|
||||
->where($db->quoteName('item_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJCatalog2Category extends DJCatalog2Base
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('djc2_categories');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJCatalog2Single extends DJCatalog2Base
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJClassifiedsBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'item';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_djclassifieds';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('cat_id')
|
||||
->from('#__djcf_items')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJClassifiedsCategory extends DJClassifiedsBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('djcf_categories', 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJClassifiedsSingle extends DJClassifiedsBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJEventsBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'event';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_djevents';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('cat_id'))
|
||||
->from('#__djev_events')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJEventsCategory extends DJEventsBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('djev_cats', 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class DJEventsSingle extends DJEventsBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EasyBlogBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'entry';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_easyblog';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__easyblog_post')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EasyBlogCategory extends EasyBlogBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('easyblog_category', 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EasyBlogSingle extends EasyBlogBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
abstract class EcommerceBase extends ComponentBase
|
||||
{
|
||||
abstract protected function getCart();
|
||||
abstract protected function getCartProducts();
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EshopBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'product';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_eshop';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__eshop_productcategories')
|
||||
->where($db->quoteName('product_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EshopCategory extends EshopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('eshop_categories', 'category_parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EshopSingle extends EshopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EventBookingBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'event';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_eventbooking';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__eb_event_categories')
|
||||
->where($db->quoteName('event_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EventBookingCategory extends EventBookingBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('eb_categories', 'parent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class EventBookingSingle extends EventBookingBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class GridboxBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'page';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_gridbox';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('page_category')
|
||||
->from('#__gridbox_pages')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class GridboxCategory extends GridboxBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('gridbox_categories', 'parent');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class GridboxSingle extends GridboxBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class HikaShopBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'product';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_hikashop';
|
||||
|
||||
/**
|
||||
* The request ID used to retrieve the ID of the product
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $request_id = 'product_id';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options, $factory)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
$this->request->id = $this->app->input->get('cid', $this->app->input->getInt('product_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__hikashop_product_category')
|
||||
->where($db->quoteName('product_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Hikashop cart data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getCart()
|
||||
{
|
||||
@include_once(implode(DIRECTORY_SEPARATOR, [JPATH_ADMINISTRATOR, 'components', 'com_hikashop', 'helpers', 'helper.php']));
|
||||
@include_once(implode(DIRECTORY_SEPARATOR, [JPATH_ADMINISTRATOR, 'components', 'com_hikashop', 'helpers', 'checkout.php']));
|
||||
|
||||
if (!class_exists('hikashopCheckoutHelper'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$checkoutHelper = \hikashopCheckoutHelper::get();
|
||||
return $checkoutHelper->getCart(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the products in the cart
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCartProducts()
|
||||
{
|
||||
if (!$cart = $this->getCart())
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return $cart->cart_products;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class HikashopCartContainsProducts extends HikashopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
// Get cart products
|
||||
if (!$cartProducts = $this->getCartProducts())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get condition products
|
||||
if (!$conditionProducts = $this->selection)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure all condition's products exist in the cart
|
||||
$foundCartProducts = array_filter(
|
||||
$cartProducts,
|
||||
function ($prod) use ($conditionProducts)
|
||||
{
|
||||
return in_array($prod->{$this->request_id}, $conditionProducts);
|
||||
}
|
||||
);
|
||||
|
||||
return count($foundCartProducts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class HikashopCartContainsXProducts extends HikashopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
// Get cart products
|
||||
if (!$cartProducts = $this->getCartProducts())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->passByOperator(count($cartProducts), $this->selection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class HikashopCartValue extends HikashopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
$exclude_shipping_cost = $this->params->get('exclude_shipping_cost', '0') === '1';
|
||||
|
||||
return $this->passByOperator($this->getCartTotal($exclude_shipping_cost), $this->selection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cart total billable cost
|
||||
*
|
||||
* @param bool $exclude_shipping_cost
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getCartTotal($exclude_shipping_cost = false)
|
||||
{
|
||||
if (!$cart = $this->getCart())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!isset($cart->total->prices[0]->price_value_with_tax))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$priceWithoutShipping = $cart->total->prices[0]->price_value_with_tax;
|
||||
|
||||
$shipping_cost = isset($cart->shipping[0]) ? $cart->shipping[0]->shipping_price_with_tax : 0;
|
||||
$total = $exclude_shipping_cost ? $priceWithoutShipping : $priceWithoutShipping + $shipping_cost;
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class HikashopCategory extends HikashopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('hikashop_category', 'category_parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all parent rows
|
||||
*
|
||||
* @param integer $id Row primary key
|
||||
* @param string $table Table name
|
||||
* @param string $parent Parent column name
|
||||
* @param string $child Child column name
|
||||
*
|
||||
* @return array Array with IDs
|
||||
*/
|
||||
public function getParentIds($id = 0, $table = 'hikashop_category', $parent = 'category_parent_id', $child = 'category_id')
|
||||
{
|
||||
return parent::getParentIds($id, $table, $parent, $child);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class HikashopSingle extends HikashopBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class J2StoreBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_j2store';
|
||||
|
||||
/**
|
||||
* Indicates whether the page is a category page
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isCategory()
|
||||
{
|
||||
return is_null($this->request->task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the page is a single page
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSinglePage()
|
||||
{
|
||||
return (in_array($this->request->view, ['products', 'producttags']) && $this->request->task == 'view');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
// Get product information
|
||||
require_once JPATH_ADMINISTRATOR . '/components/com_j2store/helpers/product.php';
|
||||
|
||||
// Make sure J2Store is loaded
|
||||
if (!class_exists('J2Product'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$item = \J2Product::getInstance()->setId($this->request->id)->getProduct();
|
||||
|
||||
if (!is_object($item) || !isset($item->source))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return $item->source->catid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class J2StoreCategory extends J2StoreBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class J2StoreSingle extends J2StoreBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'companies';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_jbusinessdirectory';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('categoryId'))
|
||||
->from('#__jbusinessdirectory_company_category')
|
||||
->where($db->quoteName('companyId') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryBusinessBase extends JBusinessDirectoryBase
|
||||
{
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options = null, $factory = null)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
|
||||
$this->request->id = (int) $this->app->input->getInt('companyId');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryBusinessCategory extends JBusinessDirectoryBusinessBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('jbusinessdirectory_categories', 'parent_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryBusinessSingle extends JBusinessDirectoryBusinessBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryEventBase extends JBusinessDirectoryBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'event';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options = null, $factory = null)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
|
||||
$this->request->id = (int) $this->app->input->getInt('eventId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('categoryId'))
|
||||
->from('#__jbusinessdirectory_company_event_category')
|
||||
->where($db->quoteName('eventId') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryEventCategory extends JBusinessDirectoryEventBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('jbusinessdirectory_categories', 'parent_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryEventSingle extends JBusinessDirectoryEventBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryOfferBase extends JBusinessDirectoryBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'offer';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options = null, $factory = null)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
|
||||
$this->request->id = (int) $this->app->input->getInt('offerId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('categoryId'))
|
||||
->from('#__jbusinessdirectory_company_offer_category')
|
||||
->where($db->quoteName('offerId') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2022 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryOfferCategory extends JBusinessDirectoryOfferBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('jbusinessdirectory_categories', 'parent_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JBusinessDirectoryOfferSingle extends JBusinessDirectoryOfferBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JCalProBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'event';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_jcalpro';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__jcalpro_event_categories')
|
||||
->where($db->quoteName('event_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JCalProCategory extends JCalProBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('categories', 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JCalProSingle extends JCalProBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JShoppingBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'product';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_jshopping';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options, $factory)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
$this->request->view = $this->app->input->get('view', $this->app->input->get('controller'));
|
||||
$this->request->id = $this->app->input->getInt('product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__jshopping_products_to_categories')
|
||||
->where($db->quoteName('product_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JShoppingCategory extends JShoppingBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('jshopping_categories', 'category_parent_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all parent rows
|
||||
*
|
||||
* @param integer $id Row primary key
|
||||
* @param string $table Table name
|
||||
* @param string $parent Parent column name
|
||||
* @param string $child Child column name
|
||||
*
|
||||
* @return array Array with IDs
|
||||
*/
|
||||
public function getParentIds($id = 0, $table = 'jshopping_categories', $parent = 'category_parent_id', $child = 'category_id')
|
||||
{
|
||||
return parent::getParentIds($id, $table, $parent, $child);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class JShoppingSingle extends JShoppingBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class K2Base extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'item';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_k2';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param integer The Single Page id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$item = $this->getK2Item();
|
||||
|
||||
return isset($item->catid) ? $item->catid : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the current view concerns a Category view
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isCategoryPage()
|
||||
{
|
||||
return ($this->request->layout == 'category' || $this->request->task == 'category' || $this->request->view == 'latest');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a K2 item
|
||||
*
|
||||
* @return object|null
|
||||
*/
|
||||
public function getK2Item()
|
||||
{
|
||||
$cache = $this->factory->getcache();
|
||||
$hash = md5('k2assitem');
|
||||
|
||||
if ($cache->has($hash))
|
||||
{
|
||||
return $cache->get($hash);
|
||||
}
|
||||
|
||||
return $cache->set($hash, \JModelLegacy::getInstance('Item', 'K2Model')->getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return tags of a K2 item
|
||||
*
|
||||
* @param int $id K2 item ID
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getK2tags($id = null)
|
||||
{
|
||||
$id = is_null($id) ? $this->request->id : $id;
|
||||
|
||||
if (!$id)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$cache = $this->factory->getcache();
|
||||
$hash = md5('k2_item_tags' . $id);
|
||||
|
||||
if ($cache->has($hash))
|
||||
{
|
||||
return $cache->get($hash);
|
||||
}
|
||||
|
||||
$q = $this->db->getQuery(true)
|
||||
->select('t.id')
|
||||
->from('#__k2_tags_xref AS tx')
|
||||
->join('LEFT', '#__k2_tags AS t ON t.id = tx.tagID')
|
||||
->where('tx.itemID = ' . $this->db->q($id))
|
||||
->where('t.published = 1');
|
||||
|
||||
$this->db->setQuery($q);
|
||||
|
||||
return $cache->set($hash, $this->db->loadColumn());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current view layout string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPageType()
|
||||
{
|
||||
$view = $this->request->view;
|
||||
$layout = $this->request->layout;
|
||||
|
||||
if (is_null($layout))
|
||||
{
|
||||
switch ($view)
|
||||
{
|
||||
case 'item':
|
||||
$layout = 'item';
|
||||
break;
|
||||
default:
|
||||
$layout = $this->request->task;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$pagetype = $view . '_' . $layout;
|
||||
|
||||
return $pagetype;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class K2Category extends K2Base
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('k2_categories', 'parent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
use NRFramework\Functions;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class K2Item extends K2Base
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
$pass = $this->passSinglePage();
|
||||
|
||||
// Keywords Checking
|
||||
$contentKeywords = $this->params->get('cont_keywords', '');
|
||||
$metaKeywords = $this->params->get('meta_keywords', '');
|
||||
|
||||
// If both are empty, do not maky any further check
|
||||
if (empty($contentKeywords) && empty($metaKeywords))
|
||||
{
|
||||
return $pass;
|
||||
}
|
||||
|
||||
// Load current K2 Item object
|
||||
if (!$item = $this->getK2Item())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// check items's text
|
||||
if (!empty($contentKeywords))
|
||||
{
|
||||
$pass = $this->passArrayInString($contentKeywords, $item->introtext . $item->fulltext);
|
||||
}
|
||||
|
||||
// check item's metakeywords
|
||||
if (!empty($metaKeywords))
|
||||
{
|
||||
$pass = $this->passArrayInString($metaKeywords, $item->metakey);
|
||||
}
|
||||
|
||||
return $pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int Article ID
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an array of values (needle) exists in a text (haystack).
|
||||
*
|
||||
* @param array $needle The searched array of values.
|
||||
* @param string $haystack The text
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function passArrayInString($needle, $haystack)
|
||||
{
|
||||
if (empty($needle) || empty($haystack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$needle = Functions::makeArray($needle);
|
||||
|
||||
return \NRFramework\Functions::strpos_arr($needle, $haystack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class K2Pagetype extends K2Base
|
||||
{
|
||||
/**
|
||||
* Pass check for K2 page types
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
if (empty($this->selection) || !$this->passContext())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::pass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return string Pagetype
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getPageType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class K2Tag extends K2Base
|
||||
{
|
||||
/**
|
||||
* Pass check for K2 Tags
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
if (empty($this->selection) || !$this->passContext())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::pass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return array K2 item tags
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getK2tags();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class QuixBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'page';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_quix';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('catid')
|
||||
->from('#__quix')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class QuixSingle extends QuixBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class RSBlogBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'post';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_rsblog';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('cat_id')
|
||||
->from('#__rsblog_posts_categories')
|
||||
->where($db->quoteName('post_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class RSBlogCategory extends RSBlogBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('rsblog_categories', 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class RSBlogSingle extends RSBlogBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class SPPageBuilderBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'page';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_sppagebuilder';
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('catid')
|
||||
->from('#__sppagebuilder')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class SPPageBuilderCategory extends SPPageBuilderBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('categories', 'parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class SPPageBuilderSingle extends SPPageBuilderBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class SobiProBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'entry';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_sobipro';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options, $factory)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
$this->request->view = 'entry';
|
||||
|
||||
// Make sure SPRequest is loaded
|
||||
if (!class_exists('SPRequest'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->request->id = (int) \SPRequest::sid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the page is a single page
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isSinglePage()
|
||||
{
|
||||
return (parent::isSinglePage() && $this->request->task == 'entry.details');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('pid')
|
||||
->from('#__sobipro_relations')
|
||||
->where($db->quoteName('id') . '=' . $db->q($id))
|
||||
->where($db->quoteName('oType') . " = 'entry'");
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class SobiProCategory extends SobiProBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('sobipro_relations', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class SobiProSingle extends SobiProBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class VirtueMartBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'productdetails';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_virtuemart';
|
||||
|
||||
/**
|
||||
* The request ID used to retrieve the ID of the product
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $request_id = 'virtuemart_product_id';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options, $factory)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
$this->request->id = $this->app->input->getInt($this->request_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('virtuemart_category_id')
|
||||
->from('#__virtuemart_product_categories')
|
||||
->where($db->quoteName($this->request_id) . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns Virtuemart cart data
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getCart()
|
||||
{
|
||||
// load the configuration wherever required as its not available everywhere
|
||||
if (!class_exists('VmConfig'))
|
||||
{
|
||||
@include_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/config.php';
|
||||
|
||||
\VmConfig::loadConfig();
|
||||
}
|
||||
|
||||
@include_once JPATH_SITE . '/components/com_virtuemart/helpers/cart.php';
|
||||
|
||||
if (!class_exists('VirtueMartCart'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$cart = \VirtueMartCart::getCart();
|
||||
$cart->prepareCartData();
|
||||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the products in the cart
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getCartProducts()
|
||||
{
|
||||
if (!$cart = $this->getCart())
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return $cart->products;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns all parent rows
|
||||
*
|
||||
* @param integer $id Row primary key
|
||||
* @param string $table Table name
|
||||
* @param string $parent Parent column name
|
||||
* @param string $child Child column name
|
||||
*
|
||||
* @return array Array with IDs
|
||||
*/
|
||||
public function getParentIds($id = 0, $table = 'virtuemart_categories', $parent = 'category_parent_id', $child = 'virtuemart_category_id')
|
||||
{
|
||||
return parent::getParentIds($id, $table, $parent, $child);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class VirtueMartCartContainsProducts extends VirtueMartBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
// Get cart products
|
||||
if (!$cartProducts = $this->getCartProducts())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get condition products
|
||||
if (!$conditionProducts = $this->selection)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Ensure all condition's products exist in the cart
|
||||
$foundCartProducts = array_filter(
|
||||
$cartProducts,
|
||||
function ($prod) use ($conditionProducts)
|
||||
{
|
||||
return in_array($prod->{$this->request_id}, $conditionProducts);
|
||||
}
|
||||
);
|
||||
|
||||
return count($foundCartProducts);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class VirtueMartCartContainsXProducts extends VirtueMartBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
// Get cart products
|
||||
if (!$cartProducts = $this->getCartProducts())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->passByOperator(count($cartProducts), $this->selection);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class VirtueMartCartValue extends VirtueMartBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
$exclude_shipping_cost = $this->params->get('exclude_shipping_cost', '0') === '1';
|
||||
|
||||
return $this->passByOperator($this->getCartTotal($exclude_shipping_cost), $this->selection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cart total billable cost
|
||||
*
|
||||
* @param bool $exclude_shipping_cost
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function getCartTotal($exclude_shipping_cost = false)
|
||||
{
|
||||
if (!$cart = $this->getCart())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!isset($cart->cartPrices['billTotal']))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@include_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/currencydisplay.php';
|
||||
|
||||
if (!class_exists('CurrencyDisplay'))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
$total = $exclude_shipping_cost ? $cart->cartPrices['salesPrice'] : $cart->cartPrices['billTotal'];
|
||||
|
||||
$currency = \CurrencyDisplay::getInstance();
|
||||
|
||||
// billTotal is stored as a float like 70.00120120312
|
||||
// We use the `roundByPriceConfig` method to round it based on Virtuemart configuration,
|
||||
// in order to get the same total as seen in the cart and compare with this value instead of the raw one.
|
||||
return $currency->roundByPriceConfig($total);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class VirtueMartCategory extends VirtueMartBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('virtuemart_categories', 'category_parent_id');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class VirtueMartSingle extends VirtueMartBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ZooBase extends ComponentBase
|
||||
{
|
||||
/**
|
||||
* The component's Single Page view name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewSingle = 'item';
|
||||
|
||||
/**
|
||||
* The component's option name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $component_option = 'com_zoo';
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options, $factory)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
|
||||
$this->request->view = $this->app->input->get('view', $this->app->input->get('task'));
|
||||
|
||||
// Normally the item's id can be read by the request parameters BUT if the item
|
||||
// is assosiated to a menu item the item_id parameter is not yet available and
|
||||
// we can only find it out through the menu's parameters.
|
||||
$this->request->id = (int) $this->app->input->getInt('item_id', $this->app->getMenu()->getActive()->getParams()->get('item_id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get single page's assosiated categories
|
||||
*
|
||||
* @param Integer The Single Page id
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getSinglePageCategories($id)
|
||||
{
|
||||
$db = $this->db;
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('category_id')
|
||||
->from('#__zoo_category_item')
|
||||
->where($db->quoteName('item_id') . '=' . $db->q($id));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
return $db->loadColumn();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ZooCategory extends ZooBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passCategories('zoo_category', 'parent');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Component;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class ZooSingle extends ZooBase
|
||||
{
|
||||
/**
|
||||
* Pass check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
return $this->passSinglePage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->request->id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class ConvertForms extends Condition
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return array List of campaign IDs
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getCampaigns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns campaigns list visitor is subscribed to
|
||||
* If the user is logged in, we try to get the campaigns by user's ID
|
||||
* Otherwise, the visitor cookie ID will be used instead
|
||||
*
|
||||
* @return array List of campaign IDs
|
||||
*/
|
||||
private function getCampaigns()
|
||||
{
|
||||
@include_once JPATH_ADMINISTRATOR . '/components/com_convertforms/helpers/convertforms.php';
|
||||
|
||||
if (!class_exists('ConvertFormsHelper'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
return \ConvertFormsHelper::getVisitorCampaigns();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class Cookie extends Condition
|
||||
{
|
||||
/**
|
||||
* When we need to compare the user's value with the cookie value, we change the $selection to the value entered by the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function prepareSelection()
|
||||
{
|
||||
if (in_array($this->operator, ['exists', 'empty']))
|
||||
{
|
||||
return $this->getSelection();
|
||||
}
|
||||
|
||||
return $this->params->get('content', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value of the cookie as stored in the user's browser
|
||||
*
|
||||
* @return string The value of the cookie
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
/**
|
||||
* $this->selection is not used here as prepareSelection() above, called in \NRFramework\Conditions\Condition->setSelection() method changes its value
|
||||
* and thus we do not always have the correct Cookie Name to search for.
|
||||
*
|
||||
* $this->options->get('selection') will always have the correct cookie name.
|
||||
*/
|
||||
return $this->factory->getCookie($this->options->get('selection'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Date;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Date extends DateBase
|
||||
{
|
||||
/**
|
||||
* Checks if current date passes the given date range.
|
||||
* Dates must be always passed in format: Y-m-d H:i:s
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
$publish_up = $this->params->get('publish_up');
|
||||
$publish_down = $this->params->get('publish_down');
|
||||
|
||||
// No valid dates
|
||||
if (!$publish_up && !$publish_up)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$up = $publish_up ? $this->getDate($publish_up) : null;
|
||||
$down = $publish_down ? $this->getDate($publish_down) : null;
|
||||
|
||||
return $this->checkRange($up, $down);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return \Date Current date
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called before the value of the condition is stored into the database.
|
||||
*
|
||||
* Dates should be always stored in the database in GMT. Thus, we remove the timezone offset from the date.
|
||||
*
|
||||
* @param array $rule The condition object.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeSave(&$rule)
|
||||
{
|
||||
\NRFramework\Functions::fixDateOffset($rule['params']['publish_up']);
|
||||
\NRFramework\Functions::fixDateOffset($rule['params']['publish_down']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Date;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use NRFramework\Conditions\Condition;
|
||||
|
||||
class DateBase extends Condition
|
||||
{
|
||||
/**
|
||||
* Server's Timezone
|
||||
*
|
||||
* @var DateTimeZone
|
||||
*/
|
||||
protected $tz;
|
||||
|
||||
/**
|
||||
* If set to True, dates will be constructed with modified offset based on the passed timezone
|
||||
*
|
||||
* @var Boolean
|
||||
*/
|
||||
protected $modify_offset = true;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object $assignment
|
||||
*/
|
||||
public function __construct($assignment = null, $factory = null)
|
||||
{
|
||||
parent::__construct($assignment, $factory);
|
||||
|
||||
// Set timezone
|
||||
if ($timezone = $this->params->get('timezone'))
|
||||
{
|
||||
$this->tz = new \DateTimeZone($timezone);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->tz = new \DateTimeZone($this->app->getCfg('offset', 'GMT'));
|
||||
}
|
||||
|
||||
// Set modify offset switch
|
||||
$this->modify_offset = $this->params->get('modify_offset', true);
|
||||
|
||||
// Set now date
|
||||
$now = $this->params->get('now', 'now');
|
||||
$this->date = $this->getDate($now);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current datetime is between the specified range
|
||||
*
|
||||
* @param JDate &$up_date
|
||||
* @param JDate &$down_date
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkRange(&$up_date, &$down_date)
|
||||
{
|
||||
if (!$up_date && !$down_date)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$now = $this->date->getTimestamp();
|
||||
|
||||
if (((bool)$up_date && $up_date->getTimestamp() > $now) ||
|
||||
((bool)$down_date && $down_date->getTimestamp() < $now))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a date object based on the given string and apply timezone.
|
||||
*
|
||||
* @param String $date
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function getDate($date = 'now')
|
||||
{
|
||||
// Fix the date string
|
||||
\NRFramework\Functions::fixDate($date);
|
||||
|
||||
if ($this->modify_offset)
|
||||
{
|
||||
// Create date, set timezone and modify offset
|
||||
$date = $this->factory->getDate($date)->setTimeZone($this->tz);
|
||||
} else
|
||||
{
|
||||
// Create date and set timezone without modifyig offset
|
||||
$date = $this->factory->getDate($date, $this->tz);
|
||||
}
|
||||
|
||||
return $date;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Date;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Day extends DateBase
|
||||
{
|
||||
/**
|
||||
* Cover special cases where the user checks whether the current day is a Weekday or Weekend.
|
||||
*
|
||||
* @param mixed $selection The current selection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function prepareSelection()
|
||||
{
|
||||
$selection = (array) $this->getSelection();
|
||||
|
||||
foreach ($selection as $str)
|
||||
{
|
||||
$str = \strtolower($str);
|
||||
|
||||
if (strpos($str, 'weekday') !== false)
|
||||
{
|
||||
$selection = array_merge($selection, range(1, 5));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strpos($str, 'weekend') !== false)
|
||||
{
|
||||
$selection = array_merge($selection, [6, 7]);
|
||||
}
|
||||
}
|
||||
|
||||
return $selection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list with all different formats of the current day.
|
||||
*
|
||||
* This returns the day in non-localized strings.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return [
|
||||
$this->date->format('l', false, false), // 'Friday'
|
||||
$this->date->format('D', false, false), // 'Fri'
|
||||
$this->date->format('N', false, false), // '1' (Monday) to '7' (Sunday)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Date;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Month extends DateBase
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* This returns the month in non-localized strings.
|
||||
*
|
||||
* @return string Name of the current month
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return [
|
||||
$this->date->format('F', false, false),
|
||||
$this->date->format('M', false, false),
|
||||
$this->date->format('n', false, false),
|
||||
$this->date->format('m', false, false),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Date;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
/**
|
||||
* DateTime Assignment Scheduling helper
|
||||
*/
|
||||
class Scheduler
|
||||
{
|
||||
/**
|
||||
* Starting date
|
||||
*
|
||||
* @var object \DateTime
|
||||
*/
|
||||
protected $start_date;
|
||||
|
||||
/**
|
||||
* Ending date
|
||||
*
|
||||
* @var object \DateTime
|
||||
*/
|
||||
protected $end_date;
|
||||
|
||||
/**
|
||||
* Date to test against
|
||||
*
|
||||
* @var object \DateTime
|
||||
*/
|
||||
protected $current_date;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $repetitionFrequency;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $repetitionStep;
|
||||
|
||||
/**
|
||||
* Used by 'weekly' repetition frequency
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $weekdays;
|
||||
|
||||
/**
|
||||
* The interval between the starting and current date
|
||||
* http://php.net/manual/en/class.dateinterval.php
|
||||
*
|
||||
* @var object \DateInterval
|
||||
*/
|
||||
protected $interval;
|
||||
|
||||
|
||||
/**
|
||||
* Scheduler constructor
|
||||
*
|
||||
* @param array $options: Scheduling options
|
||||
* start_date:
|
||||
* end_date:
|
||||
* current_date:
|
||||
* repetitionFrequency: one of 'daily', 'weekly', 'monthly', 'yearly'
|
||||
* repetitionStep: integer (1,2,3,...)
|
||||
* weekdays: Array, used with 'weekly' repetitionFrequency, any of 'Monday', 'Tuesday', etc.
|
||||
* Defaults to start_date's day name if empty
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
$this->start_date = $options['start_date'];
|
||||
$this->end_date = array_key_exists('end_date', $options) ? $options['end_date'] : null;
|
||||
$this->current_date = $options['current_date'];
|
||||
$this->repetitionFrequency = $options['repetitionFrequency'];
|
||||
$this->repetitionStep = $options['repetitionStep'];
|
||||
$this->weekdays = array_key_exists('weekdays', $options) ?
|
||||
array_map('ucfirst', $options['weekdays']) :
|
||||
null;
|
||||
|
||||
//create a DateInterval object from current and start dates
|
||||
$this->interval = $this->start_date->diff($this->current_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function repeat()
|
||||
{
|
||||
//check if we are within the start/end date range (inclusive)
|
||||
if (!$this->checkDateRange())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = false;
|
||||
|
||||
//
|
||||
switch ($this->repetitionFrequency)
|
||||
{
|
||||
case 'daily':
|
||||
$result = $this->repeatDaily();
|
||||
break;
|
||||
case 'weekly':
|
||||
$result = $this->repeatWeekly();
|
||||
break;
|
||||
case 'monthly':
|
||||
$result = $this->repeatMonthly();
|
||||
break;
|
||||
case 'yearly':
|
||||
$result = $this->repeatYearly();
|
||||
break;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Daily repetition check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function repeatDaily()
|
||||
{
|
||||
//get the number of days that have passed since start_date
|
||||
$num_days = $this->interval->days;
|
||||
|
||||
if ($num_days % $this->repetitionStep !== 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Weekly repetition check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function repeatWeekly()
|
||||
{
|
||||
//get current_date's day name
|
||||
$today_name = $this->current_date->format('l');
|
||||
|
||||
// if $this->weekdays is empty use start_date's day name
|
||||
if (empty($this->weekdays))
|
||||
{
|
||||
$start_day_name = $this->start_date->format('l');
|
||||
if ($start_day_name !== $today_name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!in_array($today_name, $this->weekdays))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//get the number of weeks that passed since start_date
|
||||
$num_weeks = floor($this->interval->days / 7);
|
||||
|
||||
if ($num_weeks % $this->repetitionStep !== 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Monthly repetition check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function repeatMonthly()
|
||||
{
|
||||
//check if we are on the same day of the month
|
||||
$start_day = $this->start_date->format('d');
|
||||
$current_day = $this->current_date->format('d');
|
||||
|
||||
if ($start_day !== $current_day)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the number of months that have passed since start_date
|
||||
$num_months = ($this->interval->y * 12) + $interval->m;
|
||||
|
||||
if ($num_months % $this->repetitionStep !== 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Yearly repetition check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function repeatYearly()
|
||||
{
|
||||
//check if we are on the same month and day
|
||||
$start_day_month = $this->start_date->format('d-m');
|
||||
$current_day_month = $this->current_date->format('d-m');
|
||||
|
||||
if ($start_day_month !== $current_day_month)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//get the number of years that have passed since start_date
|
||||
$num_years = $this->interval->y;
|
||||
|
||||
if ($num_years % $this->repetitionStep !== 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current date is between the start/end range (inclusive)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function checkDateRange()
|
||||
{
|
||||
if ($this->start_date > $this->current_date)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!empty($this->end_date) && $this->end_date < $this->current_date)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Date;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Time extends DateBase
|
||||
{
|
||||
/**
|
||||
* If set to True, dates will be constructed with modified offset based on the passed timezone
|
||||
*
|
||||
* @var Boolean
|
||||
*/
|
||||
protected $modify_offset = false;
|
||||
|
||||
/**
|
||||
* Checks if current time passes the given time range
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
$up = $this->date->format('Y-m-d', true) . ' ' . $this->params->get('publish_up');
|
||||
$down = $this->date->format('Y-m-d', true) . ' ' . $this->params->get('publish_down');
|
||||
|
||||
$up = $this->factory->getDate((string) $up, $this->tz);
|
||||
$down = $this->factory->getDate((string) $down, $this->tz);
|
||||
|
||||
return $this->checkRange($up, $down);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return \Date Current date
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
/**
|
||||
* A one-line text that describes the current value detected by the rule. Eg: The current time is %s.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueHint()
|
||||
{
|
||||
return \JText::sprintf('NR_DISPLAY_CONDITIONS_HINT_' . strtoupper($this->getName()), $this->date->format('H:i', true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class Device extends Condition
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return string Device type
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->factory->getDevice();
|
||||
}
|
||||
|
||||
/**
|
||||
* A one-line text that describes the current value detected by the rule. Eg: The current time is %s.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueHint()
|
||||
{
|
||||
return parent::getValueHint() . ' ' . \JText::_('NR_ASSIGN_DEVICES_NOTE');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos.gr <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos 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\Conditions\Condition;
|
||||
|
||||
class EngageBox extends Condition
|
||||
{
|
||||
/**
|
||||
* Checks if the user viewed any of the given boxes
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function pass()
|
||||
{
|
||||
// Skip if the visitorID is not set
|
||||
$visitorID = \NRFramework\VisitorToken::getInstance()->get();
|
||||
if (empty($visitorID))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$box_ids = $this->selection;
|
||||
if (!is_array($box_ids) || empty($box_ids))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
$box_ids = implode(',', $box_ids);
|
||||
|
||||
$db = \JFactory::getDBO();
|
||||
$query = $db->getQuery(true);
|
||||
|
||||
$query
|
||||
->select('COUNT(id)')
|
||||
->from($db->quoteName('#__rstbox_logs'))
|
||||
->where($db->quoteName('event') . ' = 1')
|
||||
->where($db->quoteName('box') . " IN ( $box_ids )")
|
||||
->where($db->quoteName('visitorid') . ' = '. $db->quote($visitorID));
|
||||
|
||||
$db->setQuery($query);
|
||||
|
||||
$pass = (int) $db->loadResult();
|
||||
|
||||
return (bool) $pass;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Geo;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class City extends GeoBase
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return string City name
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->geo->getCity();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Geo;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use NRFramework\Functions;
|
||||
|
||||
class Continent extends GeoBase
|
||||
{
|
||||
/**
|
||||
* Continent check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function prepareSelection()
|
||||
{
|
||||
$selection = Functions::makeArray($this->getSelection());
|
||||
|
||||
// Try to convert continent names to codes
|
||||
return array_map(function($c) {
|
||||
if (strlen($c) > 2)
|
||||
{
|
||||
$c = \NRFramework\Continents::getCode($c);
|
||||
}
|
||||
return $c;
|
||||
}, $selection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Continent's code and full name
|
||||
*
|
||||
* @return string Country code
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return [
|
||||
$this->geo->getContinentName('en'),
|
||||
$this->geo->getContinentCode()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Geo;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use NRFramework\Countries;
|
||||
use NRFramework\Functions;
|
||||
|
||||
class Country extends GeoBase
|
||||
{
|
||||
/**
|
||||
* Country check
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function prepareSelection()
|
||||
{
|
||||
$selection = Functions::makeArray($this->getSelection());
|
||||
|
||||
return array_map(function($c) {
|
||||
if (strlen($c) > 2)
|
||||
{
|
||||
$c = Countries::getCode($c);
|
||||
}
|
||||
return $c;
|
||||
}, $selection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return string Country code
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return [
|
||||
$this->geo->getCountryName(),
|
||||
$this->geo->getCountryCode()
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Geo;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use NRFramework\Conditions\Condition;
|
||||
use NRFramework\User;
|
||||
|
||||
/**
|
||||
* IP addresses sample
|
||||
*
|
||||
* Greece / Dodecanese: 94.67.238.3
|
||||
* Belgium / Flanders: 37.62.255.255
|
||||
* USA / New York: 72.229.28.185
|
||||
*/
|
||||
class GeoBase extends Condition
|
||||
{
|
||||
/**
|
||||
* GeoIP Class
|
||||
*
|
||||
* @var class
|
||||
*/
|
||||
protected $geo;
|
||||
|
||||
/**
|
||||
* Indicates whether we detected successfully the user's geographical location
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $success;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param object $options
|
||||
* @param object $factory
|
||||
*/
|
||||
public function __construct($options = null, $factory = null)
|
||||
{
|
||||
parent::__construct($options, $factory);
|
||||
|
||||
$ip = $this->params->get('ip', null);
|
||||
|
||||
$this->loadGeo($ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load GeoIP Classes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function loadGeo($ip)
|
||||
{
|
||||
if (!class_exists('TGeoIP'))
|
||||
{
|
||||
$path = JPATH_PLUGINS . '/system/tgeoip';
|
||||
|
||||
if (@file_exists($path . '/helper/tgeoip.php'))
|
||||
{
|
||||
if (@include_once($path . '/vendor/autoload.php'))
|
||||
{
|
||||
@include_once $path . '/helper/tgeoip.php';
|
||||
}
|
||||
}
|
||||
|
||||
// If for some reason the tgeoip plugin files do not exist, abort
|
||||
if (!class_exists('TGeoIP'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$this->geo = new \TGeoIP($ip);
|
||||
|
||||
$record = $this->geo->getRecord();
|
||||
|
||||
$this->success = ($record !== false AND !is_null($record));
|
||||
}
|
||||
|
||||
/**
|
||||
* A one-line text that describes the current value detected by the rule. Eg: The current time is %s.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getValueHint()
|
||||
{
|
||||
if (!$this->success)
|
||||
{
|
||||
return \JText::sprintf('NR_DISPLAY_CONDITIONS_HINT_GEO_ERROR', User::getIP());
|
||||
}
|
||||
|
||||
// If the rule returns an array, use the 1st one.
|
||||
$value = $this->value();
|
||||
$value = is_array($value) ? $value[0] : $value;
|
||||
|
||||
return \JText::sprintf('NR_DISPLAY_CONDITIONS_HINT_GEO', User::getIP(), $this->getName(), ucfirst(strtolower($value)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Tassos Marinos <info@tassos.gr>
|
||||
* @link http://www.tassos.gr
|
||||
* @copyright Copyright © 2021 Tassos Marinos All Rights Reserved
|
||||
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
|
||||
*/
|
||||
|
||||
namespace NRFramework\Conditions\Conditions\Geo;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
class Region extends GeoBase
|
||||
{
|
||||
/**
|
||||
* Returns the assignment's value
|
||||
*
|
||||
* @return string Region codes
|
||||
*/
|
||||
public function value()
|
||||
{
|
||||
return $this->getRegions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all ISO 3611 Country Region Codes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getRegions()
|
||||
{
|
||||
$regionCodes = [];
|
||||
$record = $this->geo->getRecord();
|
||||
|
||||
if ($record === false || is_null($record))
|
||||
{
|
||||
return $regionCodes;
|
||||
}
|
||||
|
||||
// Skip if no regions found
|
||||
if (!$regions = $record->subdivisions)
|
||||
{
|
||||
return $regionCodes;
|
||||
}
|
||||
|
||||
foreach ($regions as $key => $region)
|
||||
{
|
||||
// Get the Region's full name
|
||||
$regionCodes[] = $region->names['en'];
|
||||
|
||||
// Get the Region's code by preppending the country isocode to the region code
|
||||
$regionCodes[] = $record->country->isoCode . '-' . $region->isoCode;
|
||||
}
|
||||
|
||||
return $regionCodes;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user