acf
This commit is contained in:
		| @ -0,0 +1,108 @@ | ||||
| <?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\AI\TextGeneration; | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| use Joomla\CMS\Http\HttpFactory; | ||||
|  | ||||
| class ImageToText | ||||
| { | ||||
|     /** | ||||
|      * Generate a caption for an image | ||||
|      *  | ||||
|      * @param   string  $imageUrl | ||||
|      *  | ||||
|      * @return  array | ||||
|      */ | ||||
|     public function generate($imageUrl = '') | ||||
|     { | ||||
|         if (!$imageUrl) | ||||
|         { | ||||
|             return [ | ||||
|                 'error' => true, | ||||
|                 'message' => 'Image URL is required', | ||||
|             ]; | ||||
|         } | ||||
|  | ||||
| 		$apiKey = \NRFramework\Helpers\Settings::getValue('openai_api_key'); | ||||
| 		$apiEndpoint = 'https://api.openai.com/v1/chat/completions'; | ||||
|  | ||||
| 		// Disable SSL verification for local files | ||||
| 		$context = stream_context_create([ | ||||
| 			'ssl' => [ | ||||
| 				'verify_peer' => false, | ||||
| 				'verify_peer_name' => false, | ||||
| 			], | ||||
| 		]); | ||||
| 		 | ||||
| 		$imageData = base64_encode(file_get_contents($imageUrl, false, $context)); | ||||
| 		$url = "data:image/jpeg;base64,{$imageData}"; | ||||
|  | ||||
| 		$data = [ | ||||
| 			'model' => 'gpt-4o-mini', | ||||
| 			'messages' => [ | ||||
| 				[ | ||||
| 					'role' => 'user', | ||||
| 					'content' => [ | ||||
| 						[ | ||||
| 							'type' => 'text', | ||||
| 							'text' => 'Describe this image with maximum 120 characters, spaces included.' | ||||
| 						], | ||||
| 						[ | ||||
| 							'type' => 'image_url', | ||||
| 							'image_url' => [ | ||||
| 								'url' => $url, | ||||
| 							], | ||||
| 						], | ||||
| 					], | ||||
| 				], | ||||
| 			], | ||||
| 			'max_tokens' => 50, | ||||
| 		]; | ||||
|  | ||||
| 		$headers = [ | ||||
| 			'Content-Type' => 'application/json', | ||||
| 			'Authorization' => 'Bearer ' . $apiKey, | ||||
| 		]; | ||||
|  | ||||
| 		$error = false; | ||||
| 		$message = ''; | ||||
|  | ||||
| 		try { | ||||
| 			$http = HttpFactory::getHttp(); | ||||
| 			$response = $http->post($apiEndpoint, json_encode($data), $headers); | ||||
|  | ||||
| 			if ($response->code == 200) | ||||
| 			{ | ||||
| 				$result = json_decode($response->body); | ||||
| 				$message = $result->choices[0]->message->content; | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				$error = true; | ||||
|  | ||||
| 				$decodedResponse = json_decode($response->body, true); | ||||
|  | ||||
| 				$message = isset($decodedResponse['error']['message']) ? $decodedResponse['error']['message'] : 'An error occurred while generating the caption.'; | ||||
| 			} | ||||
| 		} | ||||
| 		catch (\Exception $e) | ||||
| 		{ | ||||
| 			$error = true; | ||||
| 			$message = "Error: " . $e->getMessage(); | ||||
| 		} | ||||
|  | ||||
| 		return [ | ||||
| 			'error' => $error, | ||||
| 			'message' => $message | ||||
| 		]; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										316
									
								
								plugins/system/nrframework/NRFramework/Assignments.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										316
									
								
								plugins/system/nrframework/NRFramework/Assignments.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,316 @@ | ||||
| <?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; | ||||
|  | ||||
| use NRFramework\Factory; | ||||
| use NRFramework\Conditions\ConditionsHelper; | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| // @deprecated  - Use \NRFramework\Condnitions\ConditionsHelper; | ||||
| class Assignments | ||||
| { | ||||
|     /** | ||||
| 	 *  Assignment Type Aliases | ||||
| 	 * | ||||
| 	 *  @var  array | ||||
|      *  | ||||
|      *  @deprecated To be removed on Jan 1st 2023. | ||||
| 	 */ | ||||
| 	public $typeAliases = array( | ||||
| 		'device|devices'                     => 'Device', | ||||
| 		'urls|url'                           => 'URL', | ||||
| 		'os'			                     => 'OS', | ||||
| 		'browsers|browser'		             => 'Browser', | ||||
| 		'referrer'                           => 'Referrer', | ||||
| 		'php'                                => 'PHP', | ||||
| 		'timeonsite'                         => 'TimeOnSite', | ||||
| 		'pageviews|user_pageviews'           => 'Pageviews', | ||||
| 		'lang|language|languages'            => 'Joomla\Language', | ||||
| 		'usergroups|usergroup|user_groups'   => 'Joomla\UserGroup', | ||||
| 		'user_id|userid'		             => 'Joomla\UserID', | ||||
| 		'menu'                               => 'Joomla\Menu', | ||||
|         'components|component'	             => 'Joomla\Component', | ||||
|         'datetime|daterange|date'            => 'Date\Date', | ||||
|         'weekday|days|day'                   => 'Date\Day', | ||||
|         'months|month'                       => 'Date\Month', | ||||
| 		'timerange|time'                     => 'Date\Time', | ||||
|         'acymailing'                         => 'AcyMailing', | ||||
|         'akeebasubs'                         => 'AkeebaSubs', | ||||
|         'engagebox|onotherbox'               => 'EngageBox', | ||||
|         'convertforms'	                     => 'ConvertForms', | ||||
|         'geo_country|country|countries'	     => 'Geo\Country', | ||||
|         'geo_continent|continent|continents' => 'Geo\Continent', | ||||
|         'geo_city|city|cities'               => 'Geo\City', | ||||
|         'geo_region|region|regions'          => 'Geo\Region', | ||||
|         'cookiename|cookie'                  => 'Cookie', | ||||
|         'ip_addresses|iprange|ip'            => 'IP', | ||||
|         'k2_items|k2item'                    => 'Component\K2Item', | ||||
|         'k2_cats|k2category'                 => 'Component\K2Category', | ||||
|         'k2_tags|k2tag'                      => 'Component\K2Tag', | ||||
|         'k2_pagetypes|k2pagetype'            => 'Component\K2Pagetype', | ||||
|         'contentcats|category'               => 'Component\ContentCategory', | ||||
|         'contentarticles|article'            => 'Component\ContentArticle', | ||||
|         'contentview'                        => 'Component\ContentView', | ||||
|         'eventbookingsingle'                 => 'Component\EventBookingSingle', | ||||
|         'eventbookingcategory'               => 'Component\EventBookingCategory', | ||||
|         'j2storesingle'                      => 'Component\J2StoreSingle', | ||||
|         'j2storecategory'                    => 'Component\J2StoreCategory', | ||||
|         'hikashopsingle'                     => 'Component\HikashopSingle', | ||||
|         'hikashopcategory'                   => 'Component\HikashopCategory', | ||||
|         'sppagebuildersingle'                => 'Component\SPPageBuilderSingle', | ||||
|         'sppagebuildercategory'              => 'Component\SPPageBuilderCategory', | ||||
|         'virtuemartcategory'                 => 'Component\VirtueMartCategory', | ||||
|         'virtuemartsingle'                   => 'Component\VirtueMartSingle', | ||||
|         'jshoppingsingle'                    => 'Component\JShoppingSingle', | ||||
|         'jshoppingcategory'                  => 'Component\JShoppingCategory', | ||||
|         'rsblogsingle'                       => 'Component\RSBlogSingle', | ||||
|         'rsblogcategory'                     => 'Component\RSBlogCategory', | ||||
|         'rseventsprosingle'                  => 'Component\RSEventsProSingle', | ||||
|         'rseventsprocategory'                => 'Component\RSEventsProCategory', | ||||
|         'easyblogcategory'                   => 'Component\EasyBlogCategory', | ||||
|         'easyblogsingle'                     => 'Component\EasyBlogSingle', | ||||
|         'zoosingle'                          => 'Component\ZooSingle', | ||||
|         'zoocategory'                        => 'Component\ZooCategory', | ||||
|         'eshopcategory'                      => 'Component\EshopCategory', | ||||
|         'eshopsingle'                        => 'Component\EshopSingle', | ||||
|         'jeventssingle'                      => 'Component\JEventsSingle', | ||||
|         'jeventscategory'                    => 'Component\JEventsCategory', | ||||
|         'djcatalog2category'                 => 'Component\DJCatalog2Category', | ||||
|         'djcatalog2single'                   => 'Component\DJCatalog2Single', | ||||
|         'quixsingle'                         => 'Component\QuixSingle', | ||||
|         'djclassifiedssingle'                => 'Component\DJClassifiedsSingle', | ||||
|         'djclassifiedscategory'              => 'Component\DJClassifiedsCategory', | ||||
|         'sobiprocategory'                    => 'Component\SobiProCategory', | ||||
|         'sobiprosingle'                      => 'Component\SobiProSingle', | ||||
|         'gridboxcategory'                    => 'Component\GridboxCategory', | ||||
|         'gridboxsingle'                      => 'Component\GridboxSingle', | ||||
|         'djeventscategory'                   => 'Component\DJEventsCategory', | ||||
|         'djeventssingle'                     => 'Component\DJEventsSingle', | ||||
|         'jcalprocategory'                    => 'Component\JCalProCategory', | ||||
|         'jcalprosingle'                      => 'Component\JCalProSingle', | ||||
|         'dpcalendarcategory'                 => 'Component\DPCalendarCategory', | ||||
|         'dpcalendarsingle'                   => 'Component\DPCalendarSingle', | ||||
|         'icagendacategory'                   => 'Component\ICagendaCategory', | ||||
|         'icagendasingle'                     => 'Component\ICagendaSingle', | ||||
|         'jbusinessdirectorybusinesscategory' => 'Component\JBusinessDirectoryBusinessCategory', | ||||
|         'jbusinessdirectorybusinesssingle'   => 'Component\JBusinessDirectoryBusinessSingle', | ||||
|         'jbusinessdirectoryeventcategory'    => 'Component\JBusinessDirectoryEventCategory', | ||||
|         'jbusinessdirectoryeventsingle'      => 'Component\JBusinessDirectoryEventSingle', | ||||
|         'jbusinessdirectoryoffercategory'    => 'Component\JBusinessDirectoryOfferCategory', | ||||
|         'jbusinessdirectoryoffersingle'      => 'Component\JBusinessDirectoryOfferSingle', | ||||
|         'jreviewscategory'                   => 'Component\JReviewsCategory', | ||||
|         'jreviewssingle'                     => 'Component\JReviewsSingle' | ||||
|     ); | ||||
|  | ||||
|     /** | ||||
|      *  Factory object  | ||||
|      *  | ||||
|      *  @var \NRFramework\Factory | ||||
|      */ | ||||
|     protected $factory; | ||||
|  | ||||
|     /** | ||||
|      *  Class constructor | ||||
|      */ | ||||
|     public function __construct($factory = null) | ||||
|     { | ||||
|         $this->factory = is_null($factory) ? new Factory() : $factory; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
| 	 *  Legacy method to check a set of rules.  | ||||
|      *  | ||||
|      *  At the moment of writing this and the moment we're going to release a new version for EngageBox  | ||||
|      *  which is going to introduce the new ConditionBuilder field, ACF and GSD will still be using the passAll() method.  | ||||
|      *  | ||||
|      *  This forces us to keep this method for backwards compatibiliy reasons. | ||||
|      *  Additionally, it helps us to catch a special case where both ACF and GSD expect to pass all rules even if the array passed is null. | ||||
| 	 * | ||||
| 	 *  @param   array|object   $assignments_info   Array/Object containing assignment info | ||||
| 	 *  @param   string         $match_method       The matching method (and|or) - Deprecated | ||||
| 	 *  @param   bool           $debug              Set to true to request additional debug information about assignments | ||||
|      * | ||||
|      *  @deprecated Use passSets() instead. To be removed on Jan 1st 2023 | ||||
| 	 */ | ||||
| 	public function passAll($assignments_info, $match_method = 'and') | ||||
| 	{ | ||||
|         $assignments = $this->prepareAssignments($assignments_info, $match_method); | ||||
|  | ||||
|         $ch = new ConditionsHelper($this->factory); | ||||
|         $pass = $ch->passSets($assignments); | ||||
|  | ||||
|         // If the checks return null, consider this as Success. This is required for both ACF and GSD. | ||||
|         return is_null($pass) ? true : $pass; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      *  Returns the classname for a given assignment alias | ||||
|      * | ||||
|      *  @param  string       $alias | ||||
|      *  @return string|void | ||||
|      *  | ||||
|      *  @deprecated To be removed on Jan 1st 2023 | ||||
|      */ | ||||
|     public function aliasToClassname($alias) | ||||
|     { | ||||
|         $alias = strtolower($alias); | ||||
|         foreach ($this->typeAliases as $aliases => $type) | ||||
|         { | ||||
|             if (strtolower($type) == $alias) | ||||
|             { | ||||
|                 return $type; | ||||
|             } | ||||
|  | ||||
|             $aliases = explode('|', strtolower($aliases)); | ||||
|             if (in_array($alias, $aliases)) | ||||
|             { | ||||
|                 return $type;                 | ||||
|             }    | ||||
|         } | ||||
|  | ||||
|         return null; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      *  Checks and prepares the given array of assignment information | ||||
|      *  | ||||
|      *  @param   array $assignments_info | ||||
|      *  @return  array | ||||
|      *  | ||||
|      *  @deprecated To be removed on Jan 1st 2023 | ||||
|      */ | ||||
|     protected function prepareAssignments($data, $matching_method = 'all') | ||||
|     { | ||||
|         if (is_object($data)) | ||||
|         { | ||||
|             return $this->prepareAssignmentsFromObject($data, $matching_method); | ||||
|         } | ||||
|  | ||||
|         if (!is_array($data) OR empty($data))  | ||||
|         { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         $rules = array_pop($data); | ||||
|  | ||||
|         if (!is_array($rules) OR empty($rules))  | ||||
|         { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         foreach ($rules as &$rule) | ||||
|         { | ||||
|             if (is_array($rule)) | ||||
|             { | ||||
|                 foreach ($rule as &$_rule) | ||||
|                 { | ||||
|                     $_rule = $this->prepareAssignmentRule($_rule); | ||||
|                 } | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 $rule = $this->prepareAssignmentRule($rule); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $data = [ | ||||
|             [ | ||||
|                 'matching_method' => $matching_method == 'and' ? 'all' : 'any', | ||||
|                 'rules' => $rules | ||||
|             ] | ||||
|         ]; | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Prepares the assignment rule. | ||||
|      *  | ||||
|      * @param   object  $rule | ||||
|      *  | ||||
|      * @return  object | ||||
|      */ | ||||
|     private function prepareAssignmentRule($rule) | ||||
|     { | ||||
|         return [ | ||||
|             'name'     => $this->aliasToClassname($rule->alias), | ||||
|             'operator' => (int) $rule->assignment_state == 1 ? 'includes' : 'not_includes', | ||||
|             'value'    => isset($rule->value) ? $rule->value : null, | ||||
|             'params'   => isset($rule->params) ? $rule->params : null, | ||||
|         ]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      *  Converts an object of assignment information to an array of groups | ||||
|      *  Used by existing extensions | ||||
|      *  | ||||
|      *  @param  object $assignments_info | ||||
|      *  @param  string $matching_method | ||||
|      *  | ||||
|      *  @deprecated To be removed on Jan 1st 2023 | ||||
|      */ | ||||
|     public function prepareAssignmentsFromObject($assignments_info, $matching_method) | ||||
|     { | ||||
|         if (!isset($assignments_info->params)) | ||||
|         { | ||||
|             return []; | ||||
|         } | ||||
|  | ||||
|         $params = json_decode($assignments_info->params); | ||||
|  | ||||
|         if (!is_object($params)) | ||||
|         { | ||||
|             return []; | ||||
|         } | ||||
|  | ||||
|         $assignments_info = []; | ||||
|          | ||||
|         foreach ($this->typeAliases as $aliases => $type) | ||||
|         { | ||||
|             $aliases = explode('|', $aliases); | ||||
|  | ||||
|             foreach ($aliases as $alias) | ||||
|             { | ||||
|                 if (!isset($params->{'assign_' . $alias}) || !$params->{'assign_' . $alias}) | ||||
|                 { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 // Discover assignment params | ||||
|                 $assignment_params = new \stdClass(); | ||||
|                 foreach ($params as $key => $value) | ||||
|                 { | ||||
|                     if (strpos($key, "assign_" . $alias . "_param") !== false) | ||||
|                     { | ||||
|                         $key = str_replace("assign_" . $alias . "_param_", "", $key); | ||||
|                         $assignment_params->$key = $value; | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 $assignments_info[] = [ | ||||
|                     'name'      => $this->aliasToClassname($alias), | ||||
|                     'operator'  => (int) $params->{'assign_' . $alias} == 1 ? 'includes' : 'not_includes', | ||||
|                     'value'     => isset($params->{'assign_' . $alias . '_list'}) ? $params->{'assign_' . $alias . '_list'} : [], | ||||
|                     'params'    => $assignment_params | ||||
|                 ]; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         $data = [ | ||||
|             [ | ||||
|                 'matching_method' => $matching_method == 'and' ? 'all' : 'any', | ||||
|                 'rules' => $assignments_info | ||||
|             ] | ||||
|         ]; | ||||
|  | ||||
|         return $data; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										115
									
								
								plugins/system/nrframework/NRFramework/Cache.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										115
									
								
								plugins/system/nrframework/NRFramework/Cache.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,115 @@ | ||||
| <?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 | ||||
| */ | ||||
|  | ||||
| /** | ||||
|  *  This file is deprecated. Use CacheManager instead of Cache. | ||||
|  */ | ||||
|  | ||||
| namespace NRFramework; | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| use \NRFramework\CacheManager; | ||||
| use \Joomla\CMS\Factory; | ||||
|  | ||||
| /** | ||||
|  *  Caching mechanism | ||||
|  */ | ||||
| class Cache | ||||
| { | ||||
| 	/** | ||||
| 	 *  Check if has alrady exists in memory | ||||
| 	 * | ||||
| 	 *  @param   string   $hash  The hash string | ||||
| 	 * | ||||
| 	 *  @return  boolean          | ||||
| 	 */ | ||||
| 	static public function has($hash) | ||||
| 	{ | ||||
| 		$cache = CacheManager::getInstance(Factory::getCache('tassos', '')); | ||||
| 		return $cache->has($hash); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Returns hash value | ||||
| 	 * | ||||
| 	 *  @param   string  $hash  The hash string | ||||
| 	 *  @param   string  $clone Why the hell we clone objects here? | ||||
| 	 * | ||||
| 	 *  @return  mixed          False on error, Object on success | ||||
| 	 */ | ||||
| 	static public function get($hash, $clone = true) | ||||
| 	{ | ||||
| 		$cache = CacheManager::getInstance(Factory::getCache('tassos', '')); | ||||
| 		return $cache->get($hash, $clone); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Sets on memory the hash value | ||||
| 	 * | ||||
| 	 *  @param  string  $hash  The hash string | ||||
| 	 *  @param  mixed   $data  Can be string or object | ||||
| 	 * | ||||
| 	 *  @return mixed | ||||
| 	 */ | ||||
| 	static public function set($hash, $data) | ||||
| 	{ | ||||
| 		$cache = CacheManager::getInstance(Factory::getCache('tassos', '')); | ||||
| 		return $cache->set($hash, $data); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Reads hash value from memory or file | ||||
| 	 * | ||||
| 	 *  @param   string   $hash   The hash string | ||||
| 	 *  @param   boolean  $force  If true, the filesystem will be used as well on the /cache/ folder | ||||
| 	 * | ||||
| 	 *  @return  mixed            The hash object valuw | ||||
| 	 */ | ||||
| 	static public function read($hash, $force = false) | ||||
| 	{ | ||||
| 		$cache = CacheManager::getInstance(Factory::getCache('tassos', '')); | ||||
| 		return $cache->read($hash, $force); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Writes hash value in cache folder | ||||
| 	 * | ||||
| 	 *  @param   string   $hash  The hash string | ||||
| 	 *  @param   mixed    $data  Can be string or object | ||||
| 	 *  @param   integer  $ttl   Expiration duration in milliseconds | ||||
| 	 * | ||||
| 	 *  @return  mixed           The hash object value | ||||
| 	 */ | ||||
| 	static public function write($hash, $data, $ttl = 0) | ||||
| 	{ | ||||
| 		$cache = CacheManager::getInstance(Factory::getCache('tassos', '')); | ||||
| 		return $cache->write($hash, $data, $ttl); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Memoize a function to run once per runtime | ||||
| 	 * | ||||
| 	 * @param  string	$key		The key to store the result of the callback | ||||
| 	 * @param  callback $callback	The callable anonymous function to call | ||||
| 	 *  | ||||
| 	 * @return mixed | ||||
| 	 */ | ||||
| 	static public function memo($key, callable $callback) | ||||
| 	{ | ||||
| 		$hash = md5($key); | ||||
|  | ||||
| 		if (Cache::has($hash)) | ||||
| 		{ | ||||
| 			return Cache::get($hash); | ||||
| 		} | ||||
|  | ||||
| 		return Cache::set($hash, $callback()); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										143
									
								
								plugins/system/nrframework/NRFramework/CacheManager.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										143
									
								
								plugins/system/nrframework/NRFramework/CacheManager.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,143 @@ | ||||
| <?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; | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  *  Cache Manager | ||||
|  *  | ||||
|  *  Singleton | ||||
|  */ | ||||
| class CacheManager | ||||
| { | ||||
| 	/** | ||||
| 	 *  'static' cache array | ||||
| 	 *   @var  array | ||||
| 	 */ | ||||
|     protected $cache = []; | ||||
|  | ||||
|     /** | ||||
|      *  Cache mechanism object | ||||
|      *  @var object | ||||
|      */ | ||||
|     protected $cache_mechanism = null; | ||||
|      | ||||
|     /** | ||||
|      *  Construct | ||||
|      */ | ||||
|     protected function __construct($cache_mechanism) | ||||
|     { | ||||
|         $this->cache_mechanism = $cache_mechanism; | ||||
|     } | ||||
|  | ||||
|     static public function getInstance($cache_mechanism) | ||||
|     { | ||||
|         static $instance = null; | ||||
|  | ||||
| 		if ($instance === null) | ||||
| 		{ | ||||
|             $instance = new CacheManager($cache_mechanism); | ||||
| 		} | ||||
| 		 | ||||
|         return $instance; | ||||
|     } | ||||
|  | ||||
| 	/** | ||||
| 	 *  Check if a hash already exists in memory | ||||
| 	 * | ||||
| 	 *  @param   string   $hash  The hash string | ||||
| 	 * | ||||
| 	 *  @return  boolean          | ||||
| 	 */ | ||||
| 	public function has($hash) | ||||
| 	{ | ||||
| 		return isset($this->cache[$hash]); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Returns a hash's value | ||||
| 	 * | ||||
| 	 *  @param   string  $hash  The hash string | ||||
| 	 *  @param   string  $clone Why the hell we clone objects here? | ||||
| 	 * | ||||
| 	 *  @return  mixed          False on error, Object on success | ||||
| 	 */ | ||||
| 	public function get($hash, $clone = true) | ||||
| 	{ | ||||
| 		if (!$this->has($hash)) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		return is_object($this->cache[$hash]) && $clone ? clone $this->cache[$hash] : $this->cache[$hash]; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Sets a hash value | ||||
| 	 * | ||||
| 	 *  @param  string  $hash  The hash string | ||||
| 	 *  @param  mixed   $data  Can be string or object | ||||
| 	 * | ||||
| 	 *  @return mixed | ||||
| 	 */ | ||||
| 	public function set($hash, $data) | ||||
| 	{ | ||||
| 		$this->cache[$hash] = $data; | ||||
| 		return $data; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Reads a hash value from memory or file | ||||
| 	 * | ||||
| 	 *  @param   string   $hash   The hash string | ||||
| 	 *  @param   boolean  $force  If true, the filesystem will be used as well on the /cache/ folder | ||||
| 	 * | ||||
| 	 *  @return  mixed            The hash object value | ||||
| 	 */ | ||||
| 	public function read($hash, $force = false) | ||||
| 	{ | ||||
| 		if ($this->has($hash)) | ||||
| 		{ | ||||
| 			return $this->get($hash); | ||||
| 		} | ||||
|  | ||||
| 		if ($force) | ||||
| 		{ | ||||
| 			$this->cache_mechanism->setCaching(true); | ||||
| 		} | ||||
|  | ||||
| 		return $this->cache_mechanism->get($hash); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 *  Writes hash value in cache folder | ||||
| 	 * | ||||
| 	 *  @param   string   $hash  The hash string | ||||
| 	 *  @param   mixed    $data  Can be string or object | ||||
| 	 *  @param   integer  $ttl   Expiration duration in minutes. Default 1440 minutes = 1 day.  | ||||
| 	 * | ||||
| 	 *  @return  mixed           The hash object value | ||||
| 	 */ | ||||
| 	public function write($hash, $data, $ttl = 1440) | ||||
| 	{ | ||||
| 		if ($ttl > 0) | ||||
| 		{ | ||||
| 			$this->cache_mechanism->setLifeTime($ttl); | ||||
| 		} | ||||
|  | ||||
| 		$this->cache_mechanism->setCaching(true); | ||||
| 		$this->cache_mechanism->store($data, $hash); | ||||
|  | ||||
| 		$this->set($hash, $data); | ||||
|  | ||||
| 		return $data; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										455
									
								
								plugins/system/nrframework/NRFramework/Conditions/Condition.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										455
									
								
								plugins/system/nrframework/NRFramework/Conditions/Condition.php
									
									
									
									
									
										Normal 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); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
| 	} | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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']; | ||||
|     } | ||||
| } | ||||
| @ -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); | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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'); | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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) {} | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
|     } | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
| 	} | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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(); | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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 []; | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
|     } | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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(); | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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(); | ||||
| 	} | ||||
| } | ||||
| @ -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'); | ||||
| 	} | ||||
|  | ||||
| } | ||||
| @ -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; | ||||
|     } | ||||
| } | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
| @ -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']); | ||||
|     } | ||||
| } | ||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user