This commit is contained in:
2024-12-31 11:07:09 +01:00
parent df7915205d
commit e089172b15
1916 changed files with 165422 additions and 271 deletions

View File

@ -0,0 +1,455 @@
<?php
/**
* @author Tassos Marinos <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions;
defined('_JEXEC') or die;
use Joomla\Registry\Registry;
use Joomla\String\StringHelper;
use Joomla\CMS\Language\Text;
/**
* 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(function($str)
{
return is_null($str) ? '' : strtolower($str);
}, $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) == '';
}
if (is_bool($value))
{
$pass = !$value;
}
break;
case 'equals':
if (is_array($selection) || is_array($value))
{
$pass = $this->passByOperator($value, $selection, 'includesSome', $options);
}
else
{
$pass = $value == $selection;
}
break;
case 'contains':
if (is_string($value) && is_string($selection))
{
$pass = strlen($selection) > 0 && strpos($value, $selection) !== false;
}
break;
// Determine whether haystack is less than needle.
case 'less_than':
case 'lowerthan':
case 'lt':
$pass = $value < $selection;
break;
// Determine whether haystack is less than or equal to needle.
case 'less_than_or_equal_to':
case 'lowerthanequal':
case 'lte':
$pass = $value <= $selection;
break;
// Determine whether haystack is greater than needle.
case 'greater_than':
case 'greaterthan':
case 'gt':
$pass = $value > $selection;
break;
// Determine whether haystack is greater than or equal to needle.
case 'greater_than_or_equal_to':
case 'greterthanequal':
case 'gte':
$pass = $value >= $selection;
break;
// Determine whether haystack contains all elements in needle.
case 'includesAll':
case 'containsall':
$pass = count(array_intersect((array) $selection, (array) $value)) == count((array) $selection);
break;
// Determine whether haystack contains at least one element from needle.
case 'includesSome':
case 'containsany':
$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 value is in given range
case 'range':
$value1 = isset($selection['value1']) ? (float) $selection['value1'] : false;
$value2 = isset($selection['value2']) ? (float) $selection['value2'] : false;
$pass = $value1 && $value2 ? (($value >= $value1) && ($value <= $value2)) : false;
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 Text::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);
}
}

View File

@ -0,0 +1,393 @@
<?php
/**
* @author Tassos.gr <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions;
defined('_JEXEC') or die;
use Joomla\CMS\Layout\LayoutHelper;
use NRFramework\Conditions\ConditionsHelper;
use NRFramework\Extension;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Form\Form;
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 = [])
{
if (!is_array($rules))
{
return [];
}
$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
*/
public 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 (is_scalar($value['value']) && empty(trim($value['value'])))
{
continue;
}
$new_selection[] = count($value) === 1 ? $value['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;
}
HTMLHelper::_('bootstrap.modal');
$modalName = 'tf-geodbchecker-modal';
// The TGeoIP Plugin URL
$url = Uri::base(true) . '/index.php?option=com_plugins&view=plugin&tmpl=component&layout=modal&extension_id=' . \NRFramework\Functions::getExtensionID('tgeoip', 'system');
$options = [
'title' => Text::_('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">'
. Text::_('JLIB_HTML_BEHAVIOR_CLOSE') . '</button>
<button type="button" class="btn btn-success" aria-hidden="true"
onclick="jQuery(\'#' . $modalName . ' iframe\').contents().find(\'#applyBtn\').click();">'
. Text::_('JAPPLY') . '</button>',
];
return HTMLHelper::_('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.
* @param bool $exclude_rules_pro Whether the excluded rules should appear as Pro missing features.
*
* @return string
*/
public static function add($controlGroup, $groupKey, $conditionKey, $condition = null, $include_rules = [], $exclude_rules = [], $exclude_rules_pro = false)
{
$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);
$form->setFieldAttribute('name', 'exclude_rules_pro', $exclude_rules_pro);
$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'] : [];
$exclude_rules_pro = isset($payload['exclude_rules_pro']) ? $payload['exclude_rules_pro'] : false;
foreach ($data as $groupKey => $groupConditions)
{
$payload = [
'name' => $payload['name'],
'groupKey' => $groupKey,
'groupConditions' => $groupConditions,
'include_rules' => $include_rules,
'exclude_rules' => $exclude_rules,
'exclude_rules_pro' => $exclude_rules_pro
];
$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 Form('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;
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* @author Tassos.gr <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions;
defined('_JEXEC') or die;
use NRFramework\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;
}
}

View File

@ -0,0 +1,71 @@
<?php
/**
* @author Tassos.gr <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions;
defined('_JEXEC') or die;
use NRFramework\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);
}
}

View File

@ -0,0 +1,27 @@
<?php
/**
* @author Tassos.gr <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions;
defined('_JEXEC') or die;
use NRFramework\Conditions\Condition;
class Browser extends Condition
{
/**
* Returns the assignment's value
*
* @return string Browser name
*/
public function value()
{
return $this->factory->getBrowser()['name'];
}
}

View File

@ -0,0 +1,249 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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');
// Check if request is forwarded
if ($context = $this->app->input->get('forward_context'))
{
if (isset($context['request']))
{
$request = (object) $context['request'];
}
}
$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);
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class ContentArticle extends ContentBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['article'];
/**
* 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;
}
}

View File

@ -0,0 +1,120 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
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;
// Sanity check
if (is_null($id))
{
return;
}
$hash = md5('contentItem' . $id);
$cache = $this->factory->getCache();
if ($cache->has($hash))
{
return $cache->get($hash);
}
// Prevent "Article not found" error on J3.
if (!defined('nrJ4'))
{
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__content'))
->where($db->quoteName('id') . ' = ' . $db->q((int) $id));
$db->setQuery($query);
if (!$db->loadResult())
{
return $cache->set($hash, null);
}
}
// Use try catch to prevent fatal errors in case the article is not found
try
{
$model = $this->getArticleModel();
$item = $model->getItem($id);
if ($item)
{
$item->images = is_string($item->images) ? json_decode($item->images) : $item->images;
$item->urls = is_string($item->urls) ? json_decode($item->urls) : $item->urls;
$item->attribs = is_string($item->attribs) ? json_decode($item->attribs) : $item->attribs;
}
return $cache->set($hash, $item);
} catch (\Throwable $th)
{
return null;
}
}
/**
* Return the Article's model.
*
* @return object
*/
private function getArticleModel()
{
if (defined('nrJ4'))
{
$mvcFactory = Factory::getApplication()->bootComponent('com_content')->getMVCFactory();
return $mvcFactory->createModel('Article', 'Administrator');
}
// Joomla 3
BaseDatabaseModel::addIncludePath(JPATH_SITE . '/components/com_content/models');
return BaseDatabaseModel::getInstance('Article', 'ContentModel');
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class ContentCategory extends ContentBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories();
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class ContentView extends ContentBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['contentview'];
/**
* 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');
}
}

View File

@ -0,0 +1,57 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DJCatalog2Category extends DJCatalog2Base
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['djcatalog2.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('djc2_categories');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DJCatalog2Single extends DJCatalog2Base
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['djcatalog2.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DJClassifiedsCategory extends DJClassifiedsBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['djclassifieds.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('djcf_categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DJClassifiedsSingle extends DJClassifiedsBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['djclassifieds.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DJEventsCategory extends DJEventsBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['djevents.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('djev_cats', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DJEventsSingle extends DJEventsBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['djevents.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DPCalendarBase 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_dpcalendar';
/**
* 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('catid'))
->from('#__dpcalendar_events')
->where($db->quoteName('id') . '=' . $db->q($id));
$db->setQuery($query);
return $db->loadColumn();
}
}

View File

@ -0,0 +1,26 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DPCalendarCategory extends DPCalendarBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('categories', 'parent_id');
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class DPCalendarSingle extends DPCalendarBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class EasyBlogCategory extends EasyBlogBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['easyblog.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('easyblog_category', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class EasyBlogSingle extends EasyBlogBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['easyblog.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,400 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
class EcommerceBase extends ComponentBase
{
/**
* Pass method for "Amount In Cart" condition.
*
* @return bool
*/
public function passAmountInCart()
{
// Whether we exclude shipping cost
$exclude_shipping_cost = $this->params->get('exclude_shipping_cost', '0') === '1';
$shipping_total = 0;
$amount = 0;
switch ($this->params->get('total', 'total'))
{
case 'total':
$amount = $this->getCartTotal();
if ($exclude_shipping_cost)
{
$shipping_total = -$this->getShippingTotal();
}
break;
case 'subtotal':
$amount = $this->getCartSubtotal();
if (!$exclude_shipping_cost)
{
$shipping_total = $this->getShippingTotal();
}
break;
}
// Calculate final amount
$amount = $amount + $shipping_total;
$operator = $this->options->get('operator', 'equal');
$selection = (float) $this->selection;
// Range selection
if ($operator === 'range')
{
$selection = [
'value1' => $selection,
'value2' => (float) $this->options->get('params.value2', false)
];
}
return $this->passByOperator($amount, $selection, $operator);
}
/**
* Pass method for "Products In Cart" condition.
*
* @param string $cart_product_item_id_key
*
* @return bool
*/
protected function passProductsInCart($cart_product_item_id_key = ['id'], $product_prop_key = 'quantity')
{
// Get cart products
if (!$cartProducts = $this->getCartProducts())
{
return false;
}
// Get condition products
if (!$conditionProducts = $this->selection)
{
return false;
}
if (!is_array($conditionProducts))
{
return false;
}
// Ensure all condition's products exist in the cart
$foundCartProducts = array_filter(
$cartProducts,
function ($prod) use ($conditionProducts, $cart_product_item_id_key, $product_prop_key)
{
$prod = (array) $prod;
// Check the ID first
foreach ($cart_product_item_id_key as $id_key)
{
$valid = array_filter($conditionProducts, function($item) use ($prod, $id_key) {
return isset($item['value']) && (int) $item['value'] === (int) $prod[$id_key];
});
if ($valid)
{
break;
}
}
// If not valid, abort
if (!$valid)
{
return;
}
// Get valid product
$valid_product = reset($valid);
// Ensure product has property
$product_property_value = isset($prod[$product_prop_key]) ? (int) $prod[$product_prop_key] : false;
if (!$product_property_value)
{
return $valid;
}
// We need an operator other than "any"
if (!isset($valid_product['operator']) || $valid_product['operator'] === 'any')
{
return $valid;
}
// Ensure value 1 is valid
$product_value1 = isset($valid_product['value1']) ? (int) $valid_product['value1'] : false;
if (!$product_value1)
{
return $valid;
}
$product_value2 = isset($valid_product['value2']) ? (int) $valid_product['value2'] : false;
// Default selection
$selection = $product_value1;
// Range selection
if ($valid_product['operator'] === 'range')
{
$selection = [
'value1' => $product_value1,
'value2' => $product_value2
];
}
return $this->passByOperator($product_property_value, $selection, $valid_product['operator']);
}
);
return count($foundCartProducts);
}
/**
* Pass method for "Last Purchase Date" condition.
*
* @return bool
*/
protected function passLastPurchaseDate()
{
if (!$user = Factory::getUser())
{
return;
}
if (!$user->id)
{
return;
}
if (!$purchase_date = $this->getLastPurchaseDate($user->id))
{
return;
}
$purchaseDate = new \DateTime('@' . $purchase_date);
$purchaseDate->setTimezone(new \DateTimeZone('UTC'));
$purchaseDate->setTime(0,0);
$currentDate = new \DateTime('now', new \DateTimeZone('UTC'));
$pass = false;
$operator = $this->options->get('params.operator', 'within_hours');
switch ($operator)
{
case 'within_hours':
case 'within_days':
case 'within_weeks':
case 'within_months':
if (!$within_value = intval($this->options->get('params.within_value')))
{
return;
}
$period = str_replace('within_', '', $operator);
$timeframe = strtoupper($period[0]);
// Hours requires a "T"
if ($timeframe === 'H')
{
$within_value = 'T' . $within_value;
}
$interval = new \DateInterval("P{$within_value}{$timeframe}");
$purchaseDateXDaysAgo = (clone $purchaseDate)->add($interval);
$interval->invert = 1; // Set invert to 1 to indicate past time
$pass = $purchaseDateXDaysAgo >= $currentDate;
break;
case 'equal':
if (!$this->selection)
{
return;
}
$selectionDate = new \DateTime($this->selection, new \DateTimeZone('UTC'));
$pass = $purchaseDate->format('Y-m-d') === $selectionDate->format('Y-m-d');
break;
case 'before':
if (!$this->selection)
{
return;
}
$selectionDate = new \DateTime($this->selection, new \DateTimeZone('UTC'));
$pass = $purchaseDate < $selectionDate;
break;
case 'after':
if (!$this->selection)
{
return;
}
$selectionDate = new \DateTime($this->selection, new \DateTimeZone('UTC'));
$pass = $purchaseDate > $selectionDate;
break;
case 'range':
if (!$secondDate = $this->options->get('params.value2'))
{
return;
}
if (!$this->selection)
{
return;
}
$startDate = new \DateTime($this->selection, new \DateTimeZone('UTC'));
$endDate = new \DateTime($secondDate, new \DateTimeZone('UTC'));
$pass = $purchaseDate >= $startDate && $purchaseDate <= $endDate;
break;
}
return $pass;
}
/**
* Pass method for "Current Product Price" condition.
*
* @return bool
*/
public function passCurrentProductPrice()
{
// Ensure we are viewing a product page
if (!$this->isSinglePage())
{
return;
}
if (!$this->selection)
{
return;
}
// Get current product data
if (!$product_data = $this->getCurrentProductData())
{
return;
}
// Get value 1
$selection = (float) $this->options->get('selection');
// Range selection
if ($this->operator === 'range')
{
$value2 = (float) $this->options->get('params.value2');
$selection = [
'value1' => $selection,
'value2' => $value2
];
}
return $this->passByOperator($product_data['price'], $selection, $this->operator);
}
/**
* Pass method for "Current Product Stock" condition.
*
* @return bool
*/
public function passCurrentProductStock()
{
// Ensure we are viewing a product page
if (!$this->isSinglePage())
{
return;
}
if (!$this->selection)
{
return;
}
$current_product_id = $this->request->id;
if (!$product_stock = $this->getProductStock($current_product_id))
{
return;
}
// Get value 1
$selection = (int) $this->options->get('selection');
// Range selection
if ($this->operator === 'range')
{
$value2 = (int) $this->options->get('params.value2');
$selection = [
'value1' => $selection,
'value2' => $value2
];
}
return $this->passByOperator($product_stock, $selection, $this->operator);
}
protected function getPreparedSelection()
{
$selection = $this->getSelection();
if (!is_array($selection))
{
return $selection;
}
foreach ($selection as &$value)
{
if (!is_array($value))
{
continue;
}
$params = isset($value['params']) ? $value['params'] : [];
if ($params)
{
if (isset($params['value']))
{
$params['value1'] = $params['value'];
}
unset($params['value']);
unset($value['params']);
}
$value = array_merge($value, $params);
}
return $selection;
}
/**
* Get single page's assosiated categories
*
* @param Integer The Single Page id
*
* @return array
*/
protected function getSinglePageCategories($id) {}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class EshopCategory extends EshopBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['eshop.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('eshop_categories', 'category_parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class EshopSingle extends EshopBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['eshop.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class EventBookingCategory extends EventBookingBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['eventbookingcategory'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('eb_categories', 'parent');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class EventBookingSingle extends EventBookingBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['eventbookingsingle'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class GridboxCategory extends GridboxBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['gridbox.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('gridbox_categories', 'parent');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class GridboxSingle extends GridboxBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['gridbox.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,208 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikaShopBase extends EcommerceBase
{
/**
* 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;
}
/**
* Returns the current user's last purchase date in format: d/m/Y H:i:s and in UTC.
*
* @param int $user_id
*
* @return string
*/
protected function getLastPurchaseDate($user_id = null)
{
if (!$user_id)
{
return;
}
$db = $this->db;
$query = $this->db->getQuery(true)
->clear()
->select('o.order_created')
->from('#__hikashop_order_product AS op')
->leftJoin('#__hikashop_order AS o ON o.order_id = op.order_id')
->leftJoin('#__hikashop_user AS u ON u.user_id = o.order_user_id')
->where('o.order_status IN ("confirmed", "shipped")')
->where('u.user_cms_id = ' . (int) $user_id)
->order('o.order_created DESC')
->setLimit(1);
$db->setQuery($query);
return $db->loadResult();
}
/**
* Returns the current product.
*
* @return object
*/
protected function getCurrentProduct()
{
if (!$this->request->id)
{
return;
}
if (!function_exists('hikashop_get'))
{
return;
}
$productClass = hikashop_get('class.product');
return $productClass->get($this->request->id);
}
/**
* Returns the current product data.
*
* @return object
*/
protected function getCurrentProductData()
{
if (!$product = $this->getCurrentProduct())
{
return;
}
return [
'id' => $product->product_id,
'price' => (float) $product->product_msrp
];
}
/**
* Returns the product stock.
*
* @param int $id
*
* @return int
*/
public function getProductStock($id = null)
{
if (!$id)
{
return;
}
if (!function_exists('hikashop_get'))
{
return;
}
$productClass = hikashop_get('class.product');
if (!$product = $productClass->get($id))
{
return;
}
// Means infinite
if ($product->product_quantity === -1)
{
return PHP_INT_MAX;
}
return (int) $product->product_quantity;
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCartContainsProducts extends HikashopBase
{
public function prepareSelection()
{
return $this->getPreparedSelection();
}
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['hikashop.cart_contains_products'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passProductsInCart(['product_id', 'cart_product_parent_id'], 'cart_product_quantity');
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCartContainsXProducts extends HikashopBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['hikashop.cart_contains_x_products'];
public function prepareSelection()
{
if ($this->operator === 'range')
{
return [
'value1' => (float) $this->options->get('selection'),
'value2' => (float) $this->options->get('params.value2', false)
];
}
return (float) $this->selection;
}
public function value()
{
if (!$cartProducts = $this->getCartProducts())
{
return false;
}
return count($cartProducts);
}
}

View File

@ -0,0 +1,124 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCartValue extends HikashopBase
{
public function prepareSelection()
{
if ($this->operator === 'range')
{
return [
'value1' => (float) $this->options->get('selection'),
'value2' => (float) $this->options->get('params.value2', false)
];
}
return (float) $this->options->get('selection');
}
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['hikashopcartvalue'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passAmountInCart();
}
/**
* Returns the cart total.
*
* @return float
*/
public function getCartTotal()
{
if (!$cart = $this->getCart())
{
return 0;
}
if (!isset($cart->full_total->prices[0]->price_value_with_tax))
{
return 0;
}
return $cart->full_total->prices[0]->price_value_with_tax;
}
/**
* Returns the cart subtotal.
*
* @return float
*/
public function getCartSubtotal()
{
if (!$cart = $this->getCart())
{
return 0;
}
if (isset($cart->full_total->prices[0]->price_value_without_shipping))
{
return $cart->full_total->prices[0]->price_value_without_shipping;
}
if (isset($cart->full_total->prices[0]->price_value_without_payment))
{
return $cart->full_total->prices[0]->price_value_without_payment;
}
return 0;
}
/**
* Returns the shipping total.
*
* @return float
*/
protected function getShippingTotal()
{
if (!$cart = $this->getCart())
{
return 0;
}
if (!isset($cart->shipping))
{
return 0;
}
if (!is_array($cart->shipping))
{
return 0;
}
if (!count($cart->shipping))
{
return 0;
}
$total_fees = 0;
foreach ($cart->shipping as $item)
{
$total_fees += (float) $item->shipping_price;
}
return $total_fees;
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCategory extends HikashopBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['hikashopcategory'];
/**
* 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);
}
}

View File

@ -0,0 +1,48 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCategoryView extends HikashopBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
if (!$this->isCategoryPage())
{
return false;
}
$this->params->set('view_category', true);
$this->params->set('view_single', false);
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);
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCurrentProductPrice extends HikashopBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCurrentProductPrice();
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopCurrentProductStock extends HikashopBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCurrentProductStock();
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopLastPurchasedDate extends HikashopBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passLastPurchaseDate();
}
}

View File

@ -0,0 +1,69 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopPurchasedProduct extends HikashopBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
if (!is_array($this->selection) || empty($this->selection))
{
return;
}
return $this->hasPurchased($this->selection);
}
/**
* Returns which given products has the current logged-in user purchased.
*
* @param array $product_ids
*
* @return array
*/
private function hasPurchased($product_ids = [])
{
if (!$product_ids)
{
return;
}
if (!$user = $this->factory->getUser())
{
return;
}
if (!$user->id)
{
return;
}
$query = $this->db->getQuery(true)
->clear()
->select('DISTINCT op.order_id')
->from('#__hikashop_order_product AS op')
->leftJoin('#__hikashop_order AS o ON o.order_id = op.order_id')
->leftJoin('#__hikashop_user AS u ON u.user_id = o.order_user_id')
->where('op.product_id IN (' . implode(',', $product_ids) . ')')
->where('o.order_status IN ("confirmed", "shipped")')
->where('u.user_cms_id = ' . (int) $user->id);
$this->db->setQuery($query);
return $this->db->loadColumn();
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopSingle extends HikashopBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['hikashopsingle'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,60 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class HikashopTotalSpend extends HikashopBase
{
public function prepareSelection()
{
if ($this->operator === 'range')
{
return [
'value1' => (float) $this->options->get('selection'),
'value2' => (float) $this->options->get('params.value2', false)
];
}
return (float) $this->options->get('selection');
}
/**
* Returns the condtion value.
*
* @return float
*/
public function value()
{
if (!$user = $this->factory->getUser())
{
return;
}
if (!$user->id)
{
return;
}
$db = $this->db;
$query = $db->getQuery(true)
->clear()
->select('SUM(o.order_full_price) AS total')
->from('#__hikashop_order AS o')
->leftJoin('#__hikashop_user AS u ON u.user_id = o.order_user_id')
->where('o.order_status IN (\'shipped\', \'confirmed\')')
->where('u.user_cms_id = ' . (int) $user->id);
$db->setQuery($query);
return (float) $db->loadResult();
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class ICagendaBase 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_icagenda';
/**
* 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('catid'))
->from('#__icagenda_events')
->where($db->quoteName('id') . '=' . $db->q($id));
$db->setQuery($query);
return $db->loadColumn();
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class ICagendaCategory extends ICagendaBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['icagenda.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('icagenda_category', '');
}
/*
* 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 = 'icagenda_category', $parent = '', $child = '')
{
return [];
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class ICagendaSingle extends ICagendaBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['icagenda.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,70 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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;
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class J2StoreCategory extends J2StoreBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['j2storecategory'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories();
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class J2StoreSingle extends J2StoreBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['j2storesingle'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,28 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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');
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JBusinessDirectoryBusinessCategory extends JBusinessDirectoryBusinessBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbusinessdirectory.business_category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('jbusinessdirectory_categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JBusinessDirectoryBusinessSingle extends JBusinessDirectoryBusinessBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbuisnessdirectory.business_single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JBusinessDirectoryEventCategory extends JBusinessDirectoryEventBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbuisnessdirectory.event_category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('jbusinessdirectory_categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JBusinessDirectoryEventSingle extends JBusinessDirectoryEventBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbuisnessdirectory.event_single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JBusinessDirectoryOfferCategory extends JBusinessDirectoryOfferBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbuisnessdirectory.offer_category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('jbusinessdirectory_categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JBusinessDirectoryOfferSingle extends JBusinessDirectoryOfferBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbuisnessdirectory.offer_single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JCalProCategory extends JCalProBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jcalpro.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JCalProSingle extends JCalProBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jbuisnessdirectory.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,73 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JEventsBase extends ComponentBase
{
/**
* The component's Single Page view name
*
* @var string
*/
protected $viewSingle = 'icalrepeat';
/**
* The component's option name
*
* @var string
*/
protected $component_option = 'com_jevents';
/**
* Indicates whether the page is a single page
*
* @return boolean
*/
public function isSinglePage()
{
return ($this->request->task == 'icalrepeat.detail' || $this->request->task == 'icalrepeat');
}
/**
* Class Constructor
*
* @param object $options
* @param object $factory
*/
public function __construct($options, $factory)
{
parent::__construct($options, $factory);
$this->request->id = $this->app->input->get('evid');
$this->request->task = $this->app->input->get('jevtask');
}
/**
* 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('#__jevents_vevent')
->where($db->quoteName('ev_id') . '=' . $id);
$db->setQuery($query);
return $db->loadColumn();
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JEventsCategory extends JEventsBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jevents.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories();
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JEventsSingle extends JEventsBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jevents.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JReviewsBase extends ComponentBase
{
protected $viewSingle = 'article';
/**
* The component's option name
*
* @var string
*/
protected $component_option = 'com_content';
/**
* 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()
{
if (!class_exists('\ClassRegistry'))
{
return;
}
if (!$listingModel = \ClassRegistry::getClass('EverywhereComContentModel'))
{
return;
}
if (!$listing = $listingModel->getListingById($this->request->id))
{
return;
}
return $this->request->view === 'article' && $this->request->option === 'com_content' && $listing;
}
/**
* Get single page's assosiated categories
*
* @param Integer The Single Page id
*
* @return array
*/
protected function getSinglePageCategories($id)
{
if (!class_exists('\ClassRegistry'))
{
return;
}
if (!$listingModel = \ClassRegistry::getClass('EverywhereComContentModel'))
{
return;
}
if (!$listing = $listingModel->getListingById($id))
{
return;
}
return isset($listing['Category']['cat_id']) ? $listing['Category']['cat_id'] : null;
}
}

View File

@ -0,0 +1,25 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JReviewsCategory extends JReviewsBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories();
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JReviewsSingle extends JReviewsBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,63 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JShoppingCategory extends JShoppingBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jshopping.catagory'];
/**
* 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);
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class JShoppingSingle extends JShoppingBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['jshopping.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,142 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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);
}
// K2 doesn't have a Joomla 4+ version, bail early
if (!class_exists('JModelLegacy'))
{
return;
}
// Ignore JModelLegacy here because K2 doesn't have a J4+ version, so we don't care.
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;
}
}

View File

@ -0,0 +1,30 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class K2Category extends K2Base
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['k2_cats', 'k2category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('k2_categories', 'parent');
}
}

View File

@ -0,0 +1,92 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
use NRFramework\Functions;
defined('_JEXEC') or die;
class K2Item extends K2Base
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['k2_items', 'k2item'];
/**
* 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);
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class K2Pagetype extends K2Base
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['k2_pagetypes', 'k2pagetype'];
/**
* 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();
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class K2Tag extends K2Base
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['k2_tags', 'k2tag'];
/**
* 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();
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class QuixSingle extends QuixBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['quix.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class RSBlogCategory extends RSBlogBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['rsblog.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('rsblog_categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class RSBlogSingle extends RSBlogBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['rsblog.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class RSEventsProBase extends ComponentBase
{
/**
* The component's Single Page view name
*
* @var string
*/
protected $viewSingle = 'rseventspro';
/**
* The component's option name
*
* @var string
*/
protected $component_option = 'com_rseventspro';
/**
* Get single events's assosiated categories
*
* @param Integer The Single Event id
*
* @return array
*/
protected function getSinglePageCategories($id)
{
$db = $this->db;
$query = $db->getQuery(true)
->select('id')
->from('#__rseventspro_taxonomy')
->where($db->quoteName('ide') . '=' . $db->q($id))
->where($db->quoteName('type') . '=' . $db->q('category'));
$db->setQuery($query);
return $db->loadColumn();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class RSEventsProCategory extends RSEventsProBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['rseventspro.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class RSEventsProSingle extends RSEventsProBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['rseventspro.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,50 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class SPPageBuilderCategory extends SPPageBuilderBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['sppagebuilder.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('categories', 'parent_id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class SPPageBuilderSingle extends SPPageBuilderBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['sppagebuilder.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\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();
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class SobiProCategory extends SobiProBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['sobipro.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('sobipro_relations', 'id');
}
}

View File

@ -0,0 +1,40 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class SobiProSingle extends SobiProBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['sobipro.single'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passSinglePage();
}
/**
* Returns the assignment's value
*
* @return int
*/
public function value()
{
return $this->request->id;
}
}

View File

@ -0,0 +1,236 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class VirtueMartBase extends EcommerceBase
{
/**
* 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';
/**
* The request ID used to retrieve the ID of the product category.
*
* @var string
*/
protected $category_request_id = 'virtuemart_category_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, $this->app->input->getInt($this->category_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 the current user's last purchase date in format: d/m/Y H:i:s and in UTC.
*
* @param int $user_id
*
* @return string
*/
protected function getLastPurchaseDate($user_id = null)
{
if (!$user_id)
{
return;
}
$db = $this->db;
$query = $this->db->getQuery(true)
->clear()
->select('created_on')
->from('#__virtuemart_orders')
->where('order_status IN ("C", "S", "F")')
->where('virtuemart_user_id = ' . (int) $user_id)
->order('created_on DESC')
->setLimit(1);
$db->setQuery($query);
return strtotime($db->loadResult());
}
/**
* Returns the current product.
*
* @return object
*/
protected function getCurrentProduct()
{
if (!$this->request->id)
{
return;
}
return $this->getProductById($this->request->id);
}
protected function getProductById($id = null)
{
if (!$id)
{
return;
}
if (!class_exists('VmModel'))
{
return;
}
return \VmModel::getModel('Product')->getProduct($id);
}
/**
* Returns the current product data.
*
* @return object
*/
protected function getCurrentProductData()
{
if (!$product = $this->getCurrentProduct())
{
return;
}
return [
'id' => $product->virtuemart_product_id,
'price' => isset($product->prices['salesPrice']) ? (float) $product->prices['salesPrice'] : 0
];
}
/**
* Returns the product stock.
*
* @param int $id
*
* @return int
*/
public function getProductStock($id = null)
{
if (!$id)
{
return;
}
if (!$product = $this->getProductById($id))
{
return;
}
return $product->product_in_stock;
}
/*
* 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);
}
}

View File

@ -0,0 +1,35 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class VirtueMartCartContainsProducts extends VirtueMartBase
{
public function prepareSelection()
{
return $this->getPreparedSelection();
}
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['virtumart.cart_contains_products'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passProductsInCart(['virtuemart_product_id', 'product_parent_id']);
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class VirtueMartCartContainsXProducts extends VirtueMartBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['virtuemart.contains_x_products'];
public function prepareSelection()
{
if ($this->operator === 'range')
{
return [
'value1' => (float) $this->options->get('selection'),
'value2' => (float) $this->options->get('params.value2', false)
];
}
return (float) $this->options->get('selection');
}
public function value()
{
if (!$cartProducts = $this->getCartProducts())
{
return false;
}
return count($cartProducts);
}
}

View File

@ -0,0 +1,121 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class VirtueMartCartValue extends VirtueMartBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['virtuemart.cart_value'];
public function prepareSelection()
{
if ($this->operator === 'range')
{
return [
'value1' => (float) $this->options->get('selection'),
'value2' => (float) $this->options->get('params.value2', false)
];
}
return (float) $this->options->get('selection');
}
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passAmountInCart();
}
/**
* Returns the cart total billable cost
*
* @return float
*/
protected function getCartTotal()
{
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;
}
$currency = \CurrencyDisplay::getInstance();
return $currency->roundByPriceConfig($cart->cartPrices['billTotal']);
}
/**
* Returns the cart subtotal.
*
* @return float
*/
public function getCartSubtotal()
{
if (!$cart = $this->getCart())
{
return 0;
}
if (!isset($cart->cartPrices['basePrice']))
{
return 0;
}
@include_once JPATH_ADMINISTRATOR . '/components/com_virtuemart/helpers/currencydisplay.php';
if (!class_exists('CurrencyDisplay'))
{
return 0;
}
$currency = \CurrencyDisplay::getInstance();
return $currency->roundByPriceConfig($cart->cartPrices['basePrice']);
}
/**
* Returns the shipping total.
*
* @return float
*/
protected function getShippingTotal()
{
if (!$cart = $this->getCart())
{
return 0;
}
if (!isset($cart->cartPrices['shipmentValue']) || !isset($cart->cartPrices['shipmentTax']))
{
return 0;
}
return $cart->cartPrices['shipmentValue'] + $cart->cartPrices['shipmentTax'];
}
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class VirtueMartCategory extends VirtueMartBase
{
/**
* Shortcode aliases for this Condition
*/
public static $shortcode_aliases = ['virtuemart.category'];
/**
* Pass check
*
* @return bool
*/
public function pass()
{
return $this->passCategories('virtuemart_categories', 'category_parent_id');
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* @author Tassos.gr
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
namespace NRFramework\Conditions\Conditions\Component;
defined('_JEXEC') or die;
class VirtueMartCategoryView extends VirtueMartBase
{
/**
* Pass check
*
* @return bool
*/
public function pass()
{
if (!$this->isCategoryPage())
{
return false;
}
$this->params->set('view_category', true);
$this->params->set('view_single', false);
return $this->passCategories('virtuemart_categories', 'category_parent_id');
}
}

Some files were not shown because too many files have changed in this diff Show More