Your IP : 216.73.216.248


Current Path : /home/digilove/www/41423/
Upload File :
Current File : /home/digilove/www/41423/Condition.tar

Agent.php000064400000006516152346010360006323 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use RegularLabs\Library\Condition;
use RegularLabs\Library\MobileDetect;
use RegularLabs\Library\RegEx;

/**
 * Class Agent
 * @package RegularLabs\Library\Condition
 */
abstract class Agent extends Condition
{
    var $agent     = null;
    var $device    = null;
    var $is_mobile = false;

    /**
     * isDesktop
     */
    public function isDesktop()
    {
        return $this->getDevice() == 'desktop';
    }

    /**
     * isMobile
     */
    public function isMobile()
    {
        return $this->getDevice() == 'mobile';
    }

    /**
     * isPhone
     */
    public function isPhone()
    {
        return $this->isMobile();
    }

    /**
     * isTablet
     */
    public function isTablet()
    {
        return $this->getDevice() == 'tablet';
    }

    /**
     * passBrowser
     */
    public function passBrowser($browser = '')
    {
        if ( ! $browser)
        {
            return false;
        }

        if ($browser == 'mobile')
        {
            return $this->isMobile();
        }

        // also check for _ instead of .
        $browser = RegEx::replace('\\\.([^\]])', '[\._]\1', $browser);
        $browser = str_replace('\.]', '\._]', $browser);

        return RegEx::match($browser, $this->getAgent(), $match, 'i');
    }

    /**
     * getAgent
     */
    private function getAgent()
    {
        if ( ! is_null($this->agent))
        {
            return $this->agent;
        }

        $detect = new MobileDetect;
        $agent  = $detect->getUserAgent();

        switch (true)
        {
            case (stripos($agent, 'Trident') !== false):
                // Add MSIE to IE11 and others missing it
                $agent = RegEx::replace('(Trident/[0-9\.]+;.*rv[: ]([0-9\.]+))', '\1 MSIE \2', $agent);
                break;

            case (stripos($agent, 'Chrome') !== false):
                // Remove Safari from Chrome
                $agent = RegEx::replace('(Chrome/.*)Safari/[0-9\.]*', '\1', $agent);
                // Add MSIE to IE Edge and remove Chrome from IE Edge
                $agent = RegEx::replace('Chrome/.*(Edge/[0-9])', 'MSIE \1', $agent);
                break;

            case (stripos($agent, 'Opera') !== false):
                $agent = RegEx::replace('(Opera/.*)Version/', '\1Opera/', $agent);
                break;
        }

        $this->agent = $agent;

        return $this->agent;
    }

    /**
     * setDevice
     */
    private function getDevice()
    {
        if ( ! is_null($this->device))
        {
            return $this->device;
        }

        $detect = new MobileDetect;

        $this->is_mobile = $detect->isMobile();

        switch (true)
        {
            case($detect->isTablet()):
                $this->device = 'tablet';
                break;

            case ($detect->isMobile()):
                $this->device = 'mobile';
                break;

            default:
                $this->device = 'desktop';
        }

        return $this->device;
    }
}
Redshop.php000064400000001566152346010360006671 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

/**
 * Class Redshop
 * @package RegularLabs\Library\Condition
 */
abstract class Redshop extends Condition
{
    public function initRequest(&$request)
    {
        $request->item_id     = JFactory::getApplication()->input->getInt('pid', 0);
        $request->category_id = JFactory::getApplication()->input->getInt('cid', 0);
        $request->id          = $request->item_id ?: $request->category_id;
    }
}
AgentBrowser.php000064400000001562152346010360007663 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class AgentBrowser
 * @package RegularLabs\Library\Condition
 */
class AgentBrowser extends Agent
{
    public function pass()
    {
        if (empty($this->selection))
        {
            return $this->_(false);
        }

        foreach ($this->selection as $browser)
        {
            if ( ! $this->passBrowser($browser))
            {
                continue;
            }

            return $this->_(true);
        }

        return $this->_(false);
    }
}
RedshopCategory.php000064400000004104152346010360010356 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class RedshopCategory
 * @package RegularLabs\Library\Condition
 */
class RedshopCategory extends Redshop
{
    public function pass()
    {
        if ($this->request->option != 'com_redshop')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_categories
                && ($this->request->view == 'category')
            )
            || ($this->params->inc_items && $this->request->view == 'product')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = [];
        if ($this->request->category_id)
        {
            $cats = $this->request->category_id;
        }
        else if ($this->request->item_id)
        {
            $query = $this->db->getQuery(true)
                ->select('x.category_id')
                ->from('#__redshop_product_category_xref AS x')
                ->where('x.product_id = ' . (int) $this->request->item_id);
            $this->db->setQuery($query);
            $cats = $this->db->loadColumn();
        }

        $cats = $this->makeArray($cats);

        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }
        else if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        return $this->getParentIds($id, 'redshop_category_xref', 'category_parent_id', 'category_child_id');
    }
}
AgentDevice.php000064400000001451152346010360007434 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class AgentDevice
 * @package RegularLabs\Library\Condition
 */
class AgentDevice extends Agent
{
    public function pass()
    {
        $pass = (in_array('mobile', $this->selection) && $this->isMobile())
            || (in_array('tablet', $this->selection) && $this->isTablet())
            || (in_array('desktop', $this->selection) && $this->isDesktop());

        return $this->_($pass);
    }
}
AgentOs.php000064400000001027152346010360006615 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class AgentOs
 * @package RegularLabs\Library\Condition
 */
class AgentOs extends AgentBrowser
{
    // Same as AgentBrowser
}
RedshopPagetype.php000064400000001217152346010360010361 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class RedshopPagetype
 * @package RegularLabs\Library\Condition
 */
class RedshopPagetype extends Redshop
{
    public function pass()
    {
        return $this->passByPageType('com_redshop', $this->selection, $this->include_type, true);
    }
}
Akeebasubs.php000064400000002273152346010360007326 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

/**
 * Class Akeebasubs
 * @package RegularLabs\Library\Condition
 */
abstract class Akeebasubs extends Condition
{
    var $agent  = null;
    var $device = null;

    public function initRequest(&$request)
    {
        if ($request->id || $request->view != 'level')
        {
            return;
        }

        $slug = JFactory::getApplication()->input->getString('slug', '');

        if ( ! $slug)
        {
            return;
        }

        $query = $this->db->getQuery(true)
            ->select('l.akeebasubs_level_id')
            ->from('#__akeebasubs_levels AS l')
            ->where('l.slug = ' . $this->db->quote($slug));
        $this->db->setQuery($query);
        $request->id = $this->db->loadResult();
    }
}
RedshopProduct.php000064400000001415152346010360010223 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class RedshopProduct
 * @package RegularLabs\Library\Condition
 */
class RedshopProduct extends Redshop
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_redshop' || $this->request->view != 'product')
        {
            return $this->_(false);
        }

        return $this->passSimple($this->request->id);
    }
}
AkeebasubsLevel.php000064400000001423152346010360010312 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class AkeebasubsLevel
 * @package RegularLabs\Library\Condition
 */
class AkeebasubsLevel extends Akeebasubs
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_akeebasubs' || $this->request->view != 'level')
        {
            return $this->_(false);
        }

        return $this->passSimple($this->request->id);
    }
}
AkeebasubsPagetype.php000064400000001225152346010360011021 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class AkeebasubsPagetype
 * @package RegularLabs\Library\Condition
 */
class AkeebasubsPagetype extends Akeebasubs
{
    public function pass()
    {
        return $this->passByPageType('com_akeebasubs', $this->selection, $this->include_type);
    }
}
VirtuemartCategory.php000064400000006623152346010360011124 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\RegEx;

/**
 * Class VirtuemartCategory
 * @package RegularLabs\Library\Condition
 */
class VirtuemartCategory extends Virtuemart
{
    public function pass()
    {
        if ($this->request->option != 'com_virtuemart')
        {
            return $this->_(false);
        }

        // Because VM sucks, we have to get the view again
        $this->request->view = JFactory::getApplication()->input->getString('view');

        $pass = (($this->params->inc_categories && in_array($this->request->view, ['categories', 'category']))
            || ($this->params->inc_items && $this->request->view == 'productdetails')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = [];
        if ($this->request->view == 'productdetails' && $this->request->item_id)
        {
            $query = $this->db->getQuery(true)
                ->select('x.virtuemart_category_id')
                ->from('#__virtuemart_product_categories AS x')
                ->where('x.virtuemart_product_id = ' . (int) $this->request->item_id);
            $this->db->setQuery($query);
            $cats = $this->db->loadColumn();
        }
        else if ($this->request->category_id)
        {
            $cats = $this->request->category_id;
            if ( ! is_numeric($cats))
            {
                $query = $this->db->getQuery(true)
                    ->select('config')
                    ->from('#__virtuemart_configs')
                    ->where('virtuemart_config_id = 1');
                $this->db->setQuery($query);
                $config = $this->db->loadResult();
                $lang   = substr($config, strpos($config, 'vmlang='));
                $lang   = substr($lang, 0, strpos($lang, '|'));
                if (RegEx::match('"([^"]*_[^"]*)"', $lang, $lang))
                {
                    $lang = $lang[1];
                }
                else
                {
                    $lang = 'en_gb';
                }

                $query = $this->db->getQuery(true)
                    ->select('l.virtuemart_category_id')
                    ->from('#__virtuemart_categories_' . $lang . ' AS l')
                    ->where('l.slug = ' . $this->db->quote($cats));
                $this->db->setQuery($query);
                $cats = $this->db->loadResult();
            }
        }

        $cats = $this->makeArray($cats);

        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }

        if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        return $this->getParentIds($id, 'virtuemart_category_categories', 'category_parent_id', 'category_child_id');
    }
}
Component.php000064400000001477152346010360007230 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Component
 * @package RegularLabs\Library\Condition
 */
class Component extends Condition
{
    public function pass()
    {
        $option = JFactory::getApplication()->input->get('option') == 'com_categories'
            ? 'com_categories'
            : $this->request->option;

        return $this->passSimple(strtolower($option));
    }
}
Content.php000064400000002306152346010360006670 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\MVC\Model\BaseDatabaseModel as JModel;
use RegularLabs\Library\Condition;
use RegularLabs\Library\ConditionContent;

/**
 * Class Content
 * @package RegularLabs\Library\Condition
 */
abstract class Content extends Condition
{
    use ConditionContent;

    public function getItem($fields = [])
    {
        if ($this->article)
        {
            return $this->article;
        }

        if ( ! class_exists('ContentModelArticle'))
        {
            require_once JPATH_SITE . '/components/com_content/models/article.php';
        }

        $model = JModel::getInstance('article', 'contentModel');

        if ( ! method_exists($model, 'getItem'))
        {
            return null;
        }

        $this->article = $model->getItem($this->request->id);

        return $this->article;
    }
}
VirtuemartPagetype.php000064400000001521152346010360011115 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class VirtuemartPagetype
 * @package RegularLabs\Library\Condition
 */
class VirtuemartPagetype extends Virtuemart
{
    public function pass()
    {
        // Because VM sucks, we have to get the view again
        $this->request->view = JFactory::getApplication()->input->getString('view');

        return $this->passByPageType('com_virtuemart', $this->selection, $this->include_type, true);
    }
}
ContentArticle.php000064400000003560152346010360010177 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class ContentArticle
 * @package RegularLabs\Library\Condition
 */
class ContentArticle extends Content
{
    public function pass()
    {
        if ( ! $this->request->id
            || ! (($this->request->option == 'com_content' && $this->request->view == 'article')
                || ($this->request->option == 'com_flexicontent' && $this->request->view == 'item')
            )
        )
        {
            return $this->_(false);
        }

        $pass = false;

        // Pass Article Id
        if ( ! $this->passItemByType($pass, 'ContentId'))
        {
            return $this->_(false);
        }

        // Pass Featured
        if ( ! $this->passItemByType($pass, 'Featured'))
        {
            return $this->_(false);
        }

        // Pass Content Keywords
        if ( ! $this->passItemByType($pass, 'ContentKeyword'))
        {
            return $this->_(false);
        }

        // Pass Meta Keywords
        if ( ! $this->passItemByType($pass, 'MetaKeyword'))
        {
            return $this->_(false);
        }

        // Pass Author
        if ( ! $this->passItemByType($pass, 'Author'))
        {
            return $this->_(false);
        }

        // Pass Date
        if ( ! $this->passItemByType($pass, 'Date'))
        {
            return $this->_(false);
        }

        // Pass Fields
        if ( ! $this->passItemByType($pass, 'Field'))
        {
            return $this->_(false);
        }

        return $this->_($pass);
    }
}
VirtuemartProduct.php000064400000001726152346010360010766 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class VirtuemartProduct
 * @package RegularLabs\Library\Condition
 */
class VirtuemartProduct extends Virtuemart
{
    public function pass()
    {
        // Because VM sucks, we have to get the view again
        $this->request->view = JFactory::getApplication()->input->getString('view');

        if ( ! $this->request->id || $this->request->option != 'com_virtuemart' || $this->request->view != 'productdetails')
        {
            return $this->_(false);
        }

        return $this->passSimple($this->request->id);
    }
}
ContentCategory.php000064400000011750152346010360010371 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use ContentsubmitModelArticle;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Table\Table as JTable;

/**
 * Class ContentCategory
 * @package RegularLabs\Library\Condition
 */
class ContentCategory extends Content
{
    public function pass()
    {
        // components that use the com_content secs/cats
        $components = ['com_content', 'com_flexicontent', 'com_contentsubmit'];

        if ( ! in_array($this->request->option, $components))
        {
            return $this->_(false);
        }

        if (empty($this->selection))
        {
            return $this->_(false);
        }

        $app = JFactory::getApplication();

        $is_content  = in_array($this->request->option, ['com_content', 'com_flexicontent']);
        $is_category = in_array($this->request->view, ['category']);
        $is_item     = in_array($this->request->view, ['', 'article', 'item', 'form']);

        if (
            $this->request->option != 'com_contentsubmit'
            && ! ($this->params->inc_categories && $is_content && $is_category)
            && ! ($this->params->inc_articles && $is_content && $is_item)
            && ! ($this->params->inc_others && ! ($is_content && ($is_category || $is_item)))
            && ! ($app->input->get('rl_qp') && ! empty($this->getCategoryIds()))
        )
        {
            return $this->_(false);
        }

        if ($this->request->option == 'com_contentsubmit')
        {
            // Content Submit
            $contentsubmit_params = new ContentsubmitModelArticle;
            if (in_array($contentsubmit_params->_id, $this->selection))
            {
                return $this->_(true);
            }

            return $this->_(false);
        }

        $pass = false;
        if (
            $this->params->inc_others
            && ! ($is_content && ($is_category || $is_item))
            && $this->article
        )
        {
            if ( ! isset($this->article->id) && isset($this->article->slug))
            {
                $this->article->id = (int) $this->article->slug;
            }

            if ( ! isset($this->article->catid) && isset($this->article->catslug))
            {
                $this->article->catid = (int) $this->article->catslug;
            }

            $this->request->id   = $this->article->id;
            $this->request->view = 'article';
        }

        $catids = $this->getCategoryIds($is_category);

        foreach ($catids as $catid)
        {
            if ( ! $catid)
            {
                continue;
            }

            $pass = in_array($catid, $this->selection);

            if ($pass && $this->params->inc_children == 2)
            {
                $pass = false;
                continue;
            }

            if ( ! $pass && $this->params->inc_children)
            {
                $parent_ids = $this->getCatParentIds($catid);
                $parent_ids = array_diff($parent_ids, [1]);
                foreach ($parent_ids as $id)
                {
                    if (in_array($id, $this->selection))
                    {
                        $pass = true;
                        break;
                    }
                }

                unset($parent_ids);
            }
        }

        return $this->_($pass);
    }

    private function getCatParentIds($id = 0)
    {
        return $this->getParentIds($id, 'categories');
    }

    private function getCategoryIds($is_category = false)
    {
        if ($is_category)
        {
            return (array) $this->request->id;
        }

        $app = JFactory::getApplication();

        $catid = $app->getUserState('com_content.edit.article.data.catid');

        if ( ! $catid)
        {
            if ( ! $this->article && $this->request->id)
            {
                $this->article = JTable::getInstance('content');
                $this->article->load($this->request->id);
            }

            if ($this->article && isset($this->article->catid))
            {
                return (array) $this->article->catid;
            }
        }

        if ( ! $catid)
        {
            $catid = $app->getUserState('com_content.articles.filter.category_id');
        }

        if ( ! $catid)
        {
            $catid = JFactory::getApplication()->input->getInt('catid');
        }

        $menuparams = $this->getMenuItemParams($this->request->Itemid);

        if ($this->request->view == 'featured')
        {
            $menuparams = $this->getMenuItemParams($this->request->Itemid);

            return (array) ($menuparams->featured_categories ?? $catid);
        }

        return (array) ($menuparams->catid ?? $catid);
    }
}
Zoo.php000064400000003750152346010360006031 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;
use RegularLabs\Library\ConditionContent;

/**
 * Class Zoo
 * @package RegularLabs\Library\Condition
 */
abstract class Zoo extends Condition
{
    use ConditionContent;

    public function getItem($fields = [])
    {
        $query = $this->db->getQuery(true)
            ->select($fields)
            ->from('#__zoo_item')
            ->where('id = ' . (int) $this->request->id);
        $this->db->setQuery($query);

        return $this->db->loadObject();
    }

    public function initRequest(&$request)
    {
        $request->view = $request->task ?: $request->view;

        switch ($request->view)
        {
            case 'item':
                $request->idname = 'item_id';
                break;
            case 'category':
                $request->idname = 'category_id';
                break;
        }

        if ( ! isset($request->idname))
        {
            $request->idname = '';
        }

        switch ($request->idname)
        {
            case 'item_id':
                $request->view = 'item';
                break;
            case 'category_id':
                $request->view = 'category';
                break;
        }

        $request->id = JFactory::getApplication()->input->getInt($request->idname, 0);

        if ($request->id)
        {
            return;
        }

        $menu = JFactory::getApplication()->getMenu()->getItem((int) $request->Itemid);

        if (empty($menu))
        {
            return;
        }

        $request->id = $menu->getParams()->get('item_id', 0);
    }

}
ContentPagetype.php000064400000001741152346010360010371 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class ContentPagetype
 * @package RegularLabs\Library\Condition
 */
class ContentPagetype extends Content
{
    public function pass()
    {
        $components = ['com_content', 'com_contentsubmit'];

        if ( ! in_array($this->request->option, $components))
        {
            return $this->_(false);
        }
        if ($this->request->view == 'category' && $this->request->layout == 'blog')
        {
            $view = 'categoryblog';
        }
        else
        {
            $view = $this->request->view;
        }

        return $this->passSimple($view);
    }
}
ZooCategory.php000064400000012166152346010360007530 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class ZooCategory
 * @package RegularLabs\Library\Condition
 */
class ZooCategory extends Zoo
{
    public function pass()
    {
        if ($this->request->option != 'com_zoo')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_apps && $this->request->view == 'frontpage')
            || ($this->params->inc_categories && $this->request->view == 'category')
            || ($this->params->inc_items && $this->request->view == 'item')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = $this->getCategories();

        if ($cats === false)
        {
            return $this->_(false);
        }

        $cats = $this->makeArray($cats);

        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }

        if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        $parent_ids = [];

        if ( ! $id)
        {
            return $parent_ids;
        }

        while ($id)
        {
            if (substr($id, 0, 3) == 'app')
            {
                $parent_ids[] = $id;
                break;
            }

            $query = $this->db->getQuery(true)
                ->select('c.parent')
                ->from('#__zoo_category AS c')
                ->where('c.id = ' . (int) $id);
            $this->db->setQuery($query);
            $pid = $this->db->loadResult();

            if ( ! $pid)
            {
                $query = $this->db->getQuery(true)
                    ->select('c.application_id')
                    ->from('#__zoo_category AS c')
                    ->where('c.id = ' . (int) $id);
                $this->db->setQuery($query);
                $app = $this->db->loadResult();

                if ($app)
                {
                    $parent_ids[] = 'app' . $app;
                }

                break;
            }

            $parent_ids[] = $pid;

            $id = $pid;
        }

        return $parent_ids;
    }

    private function getCategories()
    {
        if ($this->article && isset($this->article->catid))
        {
            return [$this->article->catid];
        }

        $menuparams = $this->getMenuItemParams($this->request->Itemid);

        switch ($this->request->view)
        {
            case 'frontpage':
                if ($this->request->id)
                {
                    return [$this->request->id];
                }

                if ( ! isset($menuparams->application))
                {
                    return [];
                }

                return ['app' . $menuparams->application];

            case 'category':
                $cats = [];

                if ($this->request->id)
                {
                    $cats[] = $this->request->id;
                }
                else if (isset($menuparams->category))
                {
                    $cats[] = $menuparams->category;
                }

                if (empty($cats[0]))
                {
                    return [];
                }

                $query = $this->db->getQuery(true)
                    ->select('c.application_id')
                    ->from('#__zoo_category AS c')
                    ->where('c.id = ' . (int) $cats[0]);
                $this->db->setQuery($query);
                $cats[] = 'app' . $this->db->loadResult();

                return $cats;

            case 'item':
                $id = $this->request->id;

                if ( ! $id && isset($menuparams->item_id))
                {
                    $id = $menuparams->item_id;
                }

                if ( ! $id)
                {
                    return [];
                }

                $query = $this->db->getQuery(true)
                    ->select('c.category_id')
                    ->from('#__zoo_category_item AS c')
                    ->where('c.item_id = ' . (int) $id)
                    ->where('c.category_id != 0');
                $this->db->setQuery($query);
                $cats = $this->db->loadColumn();

                $query = $this->db->getQuery(true)
                    ->select('i.application_id')
                    ->from('#__zoo_item AS i')
                    ->where('i.id = ' . (int) $id);
                $this->db->setQuery($query);
                $cats[] = 'app' . $this->db->loadResult();

                return $cats;

            default:
                return false;
        }
    }
}
Cookieconfirm.php000064400000001446152346010360010051 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use PlgSystemCookieconfirmCore;
use RegularLabs\Library\Condition;

/**
 * Class Cookieconfirm
 * @package RegularLabs\Library\Condition
 */
class Cookieconfirm extends Condition
{
    public function pass()
    {
        require_once JPATH_PLUGINS . '/system/cookieconfirm/core.php';
        $pass = PlgSystemCookieconfirmCore::getInstance()->isCookiesAllowed();

        return $this->_($pass);
    }
}
Date.php000064400000001037152346010360006133 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Date
 * @package RegularLabs\Library\Condition
 */
abstract class Date extends Condition
{
}
DateDate.php000064400000004565152346010360006742 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class DateDate
 * @package RegularLabs\Library\Condition
 */
class DateDate extends Date
{
    public function pass()
    {
        if ( ! $this->params->publish_up && ! $this->params->publish_down)
        {
            // no date range set
            return ($this->include_type == 'include');
        }

        $now  = $this->getNow();
        $up   = $this->getDate($this->params->publish_up);
        $down = $this->getDate($this->params->publish_down);

        if (isset($this->params->recurring) && $this->params->recurring)
        {
            if ( ! (int) $this->params->publish_up || ! (int) $this->params->publish_down)
            {
                // no date range set
                return ($this->include_type == 'include');
            }

            $up   = strtotime(date('Y') . $up->format('-m-d H:i:s', true));
            $down = strtotime(date('Y') . $down->format('-m-d H:i:s', true));

            // pass:
            // 1) now is between up and down
            // 2) up is later in year than down and:
            // 2a) now is after up
            // 2b) now is before down
            if (
                ($up < $now && $down > $now)
                || ($up > $down
                    && (
                        $up < $now
                        || $down > $now
                    )
                )
            )
            {
                return ($this->include_type == 'include');
            }

            // outside date range
            return $this->_(false);
        }

        if (
            (
                (int) $this->params->publish_up
                && strtotime($up->format('Y-m-d H:i:s', true)) > $now
            )
            || (
                (int) $this->params->publish_down
                && strtotime($down->format('Y-m-d H:i:s', true)) < $now
            )
        )
        {
            // outside date range
            return $this->_(false);
        }

        // pass
        return ($this->include_type == 'include');
    }
}
DateDay.php000064400000001233152346010360006567 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class DateDay
 * @package RegularLabs\Library\Condition
 */
class DateDay extends Date
{
    public function pass()
    {
        $day = $this->date->format('N', true); // 1 (for Monday) though 7 (for Sunday )

        return $this->passSimple($day);
    }
}
ZooItem.php000064400000002116152346010360006643 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class ZooItem
 * @package RegularLabs\Library\Condition
 */
class ZooItem extends Zoo
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_zoo')
        {
            return $this->_(false);
        }

        if ($this->request->view != 'item')
        {
            return $this->_(false);
        }

        $pass = false;

        // Pass Article Id
        if ( ! $this->passItemByType($pass, 'ContentId'))
        {
            return $this->_(false);
        }

        // Pass Author
        if ( ! $this->passItemByType($pass, 'Author'))
        {
            return $this->_(false);
        }

        return $this->_($pass);
    }
}
DateMonth.php000064400000001256152346010360007144 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class DateMonth
 * @package RegularLabs\Library\Condition
 */
class DateMonth extends Date
{
    public function pass()
    {
        $month = $this->date->format('m', true); // 01 (for January) through 12 (for December)

        return $this->passSimple((int) $month);
    }
}
ZooPagetype.php000064400000001171152346010360007523 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class ZooPagetype
 * @package RegularLabs\Library\Condition
 */
class ZooPagetype extends Zoo
{
    public function pass()
    {
        return $this->passByPageType('com_zoo', $this->selection, $this->include_type);
    }
}
DateSeason.php000064400000007047152346010360007313 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class DateSeason
 * @package RegularLabs\Library\Condition
 */
class DateSeason extends Date
{
    public function pass()
    {
        $season = self::getSeason($this->date, $this->params->hemisphere);

        return $this->passSimple($season);
    }

    private function getSeason(&$d, $hemisphere = 'northern')
    {
        // Set $date to today
        $date = strtotime($d->format('Y-m-d H:i:s', true));

        // Get year of date specified
        $date_year = $d->format('Y', true); // Four digit representation for the year

        // Specify the season names
        $season_names = ['winter', 'spring', 'summer', 'fall'];

        // Declare season date ranges
        switch (strtolower($hemisphere))
        {
            case 'southern':
                if (
                    $date < strtotime($date_year . '-03-21')
                    || $date >= strtotime($date_year . '-12-21')
                )
                {
                    return $season_names[2]; // Must be in Summer
                }

                if ($date >= strtotime($date_year . '-09-23'))
                {
                    return $season_names[1]; // Must be in Spring
                }

                if ($date >= strtotime($date_year . '-06-21'))
                {
                    return $season_names[0]; // Must be in Winter
                }

                if ($date >= strtotime($date_year . '-03-21'))
                {
                    return $season_names[3]; // Must be in Fall
                }
                break;
            case 'australia':
                if (
                    $date < strtotime($date_year . '-03-01')
                    || $date >= strtotime($date_year . '-12-01')
                )
                {
                    return $season_names[2]; // Must be in Summer
                }

                if ($date >= strtotime($date_year . '-09-01'))
                {
                    return $season_names[1]; // Must be in Spring
                }

                if ($date >= strtotime($date_year . '-06-01'))
                {
                    return $season_names[0]; // Must be in Winter
                }

                if ($date >= strtotime($date_year . '-03-01'))
                {
                    return $season_names[3]; // Must be in Fall
                }
                break;
            default: // northern
                if (
                    $date < strtotime($date_year . '-03-21')
                    || $date >= strtotime($date_year . '-12-21')
                )
                {
                    return $season_names[0]; // Must be in Winter
                }

                if ($date >= strtotime($date_year . '-09-23'))
                {
                    return $season_names[3]; // Must be in Fall
                }

                if ($date >= strtotime($date_year . '-06-21'))
                {
                    return $season_names[2]; // Must be in Summer
                }

                if ($date >= strtotime($date_year . '-03-21'))
                {
                    return $season_names[1]; // Must be in Spring
                }
                break;
        }

        return 0;
    }
}
DateTime.php000064400000002623152346010360006754 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class DateTime
 * @package RegularLabs\Library\Condition
 */
class DateTime extends Date
{
    public function pass()
    {
        $now  = $this->getNow();
        $up   = strtotime($this->date->format('Y-m-d ', true) . $this->params->publish_up);
        $down = strtotime($this->date->format('Y-m-d ', true) . $this->params->publish_down);

        if ($up > $down)
        {
            // publish up is after publish down (spans midnight)
            // current time should be:
            // - after publish up
            // - OR before publish down
            if ($now >= $up || $now < $down)
            {
                return $this->_(true);
            }

            return $this->_(false);
        }

        // publish down is after publish up (simple time span)
        // current time should be:
        // - after publish up
        // - AND before publish down
        if ($now >= $up && $now < $down)
        {
            return $this->_(true);
        }

        return $this->_(false);
    }
}
Easyblog.php000064400000001631152346010360007023 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;
use RegularLabs\Library\ConditionContent;

defined('_JEXEC') or die;

/**
 * Class Easyblog
 * @package RegularLabs\Library\Condition
 */
abstract class Easyblog extends Condition
{
    use ConditionContent;

    public function getItem($fields = [])
    {
        $query = $this->db->getQuery(true)
            ->select($fields)
            ->from('#__easyblog_post')
            ->where('id = ' . (int) $this->request->id);
        $this->db->setQuery($query);

        return $this->db->loadObject();
    }
}
EasyblogCategory.php000064400000004305152346010360010522 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class EasyblogCategory
 * @package RegularLabs\Library\Condition
 */
class EasyblogCategory extends Easyblog
{
    public function pass()
    {
        if ($this->request->option != 'com_easyblog')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_categories && $this->request->view == 'categories')
            || ($this->params->inc_items && $this->request->view == 'entry')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = $this->makeArray($this->getCategories());

        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }
        else if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        return $this->getParentIds($id, 'easyblog_category', 'parent_id');
    }

    private function getCategories()
    {
        switch ($this->request->view)
        {
            case 'entry' :
                return $this->getCategoryIDFromItem();
                break;

            case 'categories' :
                return $this->request->id;
                break;

            default:
                return '';
        }
    }

    private function getCategoryIDFromItem()
    {
        $query = $this->db->getQuery(true)
            ->select('i.category_id')
            ->from('#__easyblog_post AS i')
            ->where('i.id = ' . (int) $this->request->id);
        $this->db->setQuery($query);

        return $this->db->loadResult();
    }
}
EasyblogItem.php000064400000002271152346010360007643 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class EasyblogItem
 * @package RegularLabs\Library\Condition
 */
class EasyblogItem extends Easyblog
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_easyblog' || $this->request->view != 'entry')
        {
            return $this->_(false);
        }

        $pass = false;

        // Pass Article Id
        if ( ! $this->passItemByType($pass, 'ContentId'))
        {
            return $this->_(false);
        }

        // Pass Content Keywords
        if ( ! $this->passItemByType($pass, 'ContentKeyword'))
        {
            return $this->_(false);
        }

        // Pass Author
        if ( ! $this->passItemByType($pass, 'Author'))
        {
            return $this->_(false);
        }

        return $this->_($pass);
    }
}
EasyblogKeyword.php000064400000001124152346010360010365 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class EasyblogKeyword
 * @package RegularLabs\Library\Condition
 */
class EasyblogKeyword extends Easyblog
{
    public function pass()
    {
        parent::passContentKeyword();
    }
}
EasyblogPagetype.php000064400000001215152346010360010520 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class EasyblogPagetype
 * @package RegularLabs\Library\Condition
 */
class EasyblogPagetype extends Easyblog
{
    public function pass()
    {
        return $this->passByPageType('com_easyblog', $this->selection, $this->include_type);
    }
}
EasyblogTag.php000064400000003421152346010360007456 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class EasyblogTag
 * @package RegularLabs\Library\Condition
 */
class EasyblogTag extends Easyblog
{
    public function pass()
    {
        if ($this->request->option != 'com_easyblog')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_tags && $this->request->layout == 'tag')
            || ($this->params->inc_items && $this->request->view == 'entry')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        if ($this->params->inc_tags && $this->request->layout == 'tag')
        {
            $query = $this->db->getQuery(true)
                ->select('t.alias')
                ->from('#__easyblog_tag AS t')
                ->where('t.id = ' . (int) $this->request->id)
                ->where('t.published = 1');
            $this->db->setQuery($query);
            $tags = $this->db->loadColumn();

            return $this->passSimple($tags, true);
        }

        $query = $this->db->getQuery(true)
            ->select('t.alias')
            ->from('#__easyblog_post_tag AS x')
            ->join('LEFT', '#__easyblog_tag AS t ON t.id = x.tag_id')
            ->where('x.post_id = ' . (int) $this->request->id)
            ->where('t.published = 1');
        $this->db->setQuery($query);
        $tags = $this->db->loadColumn();

        return $this->passSimple($tags, true);
    }
}
Flexicontent.php000064400000001057152346010360007722 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Flexicontent
 * @package RegularLabs\Library\Condition
 */
abstract class Flexicontent extends Condition
{
}
MijoshopProduct.php000064400000001421152346010360010404 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class MijoshopProduct
 * @package RegularLabs\Library\Condition
 */
class MijoshopProduct extends Mijoshop
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_mijoshop' || $this->request->view != 'product')
        {
            return $this->_(false);
        }

        return $this->passSimple($this->request->id);
    }
}
FlexicontentPagetype.php000064400000001235152346010360011417 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class FlexicontentPagetype
 * @package RegularLabs\Library\Condition
 */
class FlexicontentPagetype extends Flexicontent
{
    public function pass()
    {
        return $this->passByPageType('com_flexicontent', $this->selection, $this->include_type);
    }
}
FlexicontentTag.php000064400000003667152346010360010367 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class FlexicontentTag
 * @package RegularLabs\Library\Condition
 */
class FlexicontentTag extends Flexicontent
{
    public function pass()
    {
        if ($this->request->option != 'com_flexicontent')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_tags && $this->request->view == 'tags')
            || ($this->params->inc_items && in_array($this->request->view, ['item', 'items']))
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        if ($this->params->inc_tags && $this->request->view == 'tags')
        {
            $query = $this->db->getQuery(true)
                ->select('t.name')
                ->from('#__flexicontent_tags AS t')
                ->where('t.id = ' . (int) trim(JFactory::getApplication()->input->getInt('id', 0)))
                ->where('t.published = 1');
            $this->db->setQuery($query);
            $tag  = $this->db->loadResult();
            $tags = [$tag];
        }
        else
        {
            $query = $this->db->getQuery(true)
                ->select('t.name')
                ->from('#__flexicontent_tags_item_relations AS x')
                ->join('LEFT', '#__flexicontent_tags AS t ON t.id = x.tid')
                ->where('x.itemid = ' . (int) $this->request->id)
                ->where('t.published = 1');
            $this->db->setQuery($query);
            $tags = $this->db->loadColumn();
        }

        return $this->passSimple($tags, true);
    }
}
FlexicontentType.php000064400000002240152346010360010557 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class FlexicontentType
 * @package RegularLabs\Library\Condition
 */
class FlexicontentType extends Flexicontent
{
    public function pass()
    {
        if ($this->request->option != 'com_flexicontent')
        {
            return $this->_(false);
        }

        $pass = in_array($this->request->view, ['item', 'items']);

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $query = $this->db->getQuery(true)
            ->select('x.type_id')
            ->from('#__flexicontent_items_ext AS x')
            ->where('x.item_id = ' . (int) $this->request->id);
        $this->db->setQuery($query);
        $type = $this->db->loadResult();

        $types = $this->makeArray($type);

        return $this->passSimple($types);
    }
}
Form2content.php000064400000001057152346010360007640 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Form2content
 * @package RegularLabs\Library\Condition
 */
abstract class Form2content extends Condition
{
}
Php.php000064400000015073152346010360006012 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use JDocument;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Filesystem\File as JFile;
use Joomla\CMS\MVC\Model\BaseDatabaseModel as JModel;
use Joomla\CMS\Version;
use RegularLabs\Library\Condition;
use RegularLabs\Library\RegEx;

/**
 * Class Php
 * @package RegularLabs\Library\Condition
 */
class Php extends Condition
{
    public static function createFunctionInMemory($string = '')
    {
        $file_name = getmypid() . '_' . md5($string);

        $tmp_path  = JFactory::getConfig()->get('tmp_path', JPATH_ROOT . '/tmp');
        $temp_file = $tmp_path . '/regularlabs/custom_php/' . $file_name;

        // Write file
        if ( ! file_exists($temp_file) || is_writable($temp_file))
        {
            JFile::write($temp_file, $string);
        }

        // Include file
        include_once $temp_file;

        // Delete file
        if ( ! JFactory::getApplication()->get('debug'))
        {
            @chmod($temp_file, 0777);
            @unlink($temp_file);
        }
    }

    public static function getApplication()
    {
        if (JFactory::getApplication()->input->get('option') != 'com_finder')
        {
            return JFactory::getApplication();
        }

        return CMSApplication::getInstance('site');
    }

    public static function getDocument()
    {
        if (JFactory::getApplication()->input->get('option') != 'com_finder')
        {
            return JFactory::getDocument();
        }

        $lang    = JFactory::getLanguage();
        $version = new Version;

        $attributes = [
            'charset'      => 'utf-8',
            'lineend'      => 'unix',
            'tab'          => "\t",
            'language'     => $lang->getTag(),
            'direction'    => $lang->isRtl() ? 'rtl' : 'ltr',
            'mediaversion' => $version->getMediaVersion(),
        ];

        return JDocument::getInstance('html', $attributes);
    }

    public static function getVarInits()
    {
        return [
            '$app = $mainframe = RegularLabs\Library\Condition\Php::getApplication();',
            '$document = $doc = RegularLabs\Library\Condition\Php::getDocument();',
            '$database = $db = JFactory::getDbo();',
            '$user = JFactory::getApplication()->getIdentity() ?: JFactory::getUser();',
            '$Itemid = $app->input->getInt(\'Itemid\');',
        ];
    }

    public function execute($string = '', $article = null, $module = null)
    {
        if ( ! $function_name = $this->getFunctionName($string))
        {
            // Something went wrong!
            return true;
        }

        return $this->runFunction($function_name, $string, $article, $module);
    }

    public function pass()
    {
        if ( ! is_array($this->selection))
        {
            $this->selection = [$this->selection];
        }

        $pass = false;
        foreach ($this->selection as $php)
        {
            // replace \n with newline and other fix stuff
            $php = str_replace('\|', '|', $php);
            $php = RegEx::replace('(?<!\\\)\\\n', "\n", $php);
            $php = trim(str_replace('[:REGEX_ENTER:]', '\n', $php));

            if ($php == '')
            {
                $pass = true;
                break;
            }

            ob_start();
            $pass = (bool) $this->execute($php, $this->article, $this->module);
            ob_end_clean();

            if ($pass)
            {
                break;
            }
        }

        return $this->_($pass);
    }

    private static function extractUseStatements(&$string)
    {
        $use_statements = [];

        $string = trim($string);

        RegEx::matchAll('^use\s+[^\s;]+\s*;', $string, $matches, 'm');

        foreach ($matches as $match)
        {
            $use_statements[] = $match[0];
            $string           = str_replace($match[0], '', $string);
        }

        $string = trim($string);

        return implode("\n", $use_statements);
    }

    private function generateFileContents($function_name = 'rl_function', $string = '')
    {
        $use_statements = self::extractUseStatements($string);

        $init_variables = self::getVarInits();

        $contents = [
            '<?php',
            'defined(\'_JEXEC\') or die;',
            $use_statements,
            'function ' . $function_name . '($article, $module){',
            implode("\n", $init_variables),
            $string,
            ';return true;',
            ';}',
        ];

        $contents = implode("\n", $contents);

        // Remove Zero Width spaces / (non-)joiners
        $contents = str_replace(
            [
                "\xE2\x80\x8B",
                "\xE2\x80\x8C",
                "\xE2\x80\x8D",
            ],
            '',
            $contents
        );

        return $contents;
    }

    private function getArticleById($id = 0)
    {
        if ( ! $id)
        {
            return null;
        }

        if ( ! class_exists('ContentModelArticle'))
        {
            require_once JPATH_SITE . '/components/com_content/models/article.php';
        }

        $model = JModel::getInstance('article', 'contentModel');

        if ( ! method_exists($model, 'getItem'))
        {
            return null;
        }

        return $model->getItem($id);
    }

    private function getFunctionName($string = '')
    {
        $function_name = 'regularlabs_php_' . md5($string);

        if (function_exists($function_name))
        {
            return $function_name;
        }

        $contents = $this->generateFileContents($function_name, $string);
        self::createFunctionInMemory($contents);

        if ( ! function_exists($function_name))
        {
            // Something went wrong!
            return false;
        }

        return $function_name;
    }

    private function runFunction($function_name = 'rl_function', $string = '', $article = null, $module = null)
    {
        if ( ! $article && strpos($string, '$article') !== false)
        {
            if ($this->request->option == 'com_content' && $this->request->view == 'article')
            {
                $article = $this->getArticleById($this->request->id);
            }
        }

        return $function_name($article, $module);
    }
}
Form2contentProject.php000064400000002054152346010360011165 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Form2contentProject
 * @package RegularLabs\Library\Condition
 */
class Form2contentProject extends Form2content
{
    public function pass()
    {
        if ($this->request->option != 'com_content' && $this->request->view == 'article')
        {
            return $this->_(false);
        }

        $query = $this->db->getQuery(true)
            ->select('c.projectid')
            ->from('#__f2c_form AS c')
            ->where('c.reference_id = ' . (int) $this->request->id);
        $this->db->setQuery($query);
        $type = $this->db->loadResult();

        $types = $this->makeArray($type);

        return $this->passSimple($types);
    }
}
Geo.php000064400000003120152346010360005763 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use GeoIp;
use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Log\Log as JLog;
use RegularLabs\Library\Condition;
use RegularLabs_GeoIp;

/**
 * Class Geo
 * @package RegularLabs\Library\Condition
 */
abstract class Geo extends Condition
{
    var $geo = null;

    public function getGeo($ip = '')
    {
        if ($this->geo !== null)
        {
            return $this->geo;
        }


        $geo = $this->getGeoObject($ip);

        if (empty($geo))
        {
            return false;
        }

        $this->geo = $geo->get();

        if (JFactory::getApplication()->get('debug'))
        {
            JLog::addLogger(['text_file' => 'regularlabs_geoip.log.php'], JLog::ALL, ['regularlabs_geoip']);
            JLog::add(json_encode($this->geo), JLog::DEBUG, 'regularlabs_geoip');
        }

        return $this->geo;
    }

    private function getGeoObject($ip)
    {
        if ( ! file_exists(JPATH_LIBRARIES . '/geoip/geoip.php'))
        {
            return false;
        }

        require_once JPATH_LIBRARIES . '/geoip/geoip.php';

        if ( ! class_exists('RegularLabs_GeoIp'))
        {
            return new GeoIp($ip);
        }

        return new RegularLabs_GeoIp($ip);
    }
}
GeoContinent.php000064400000001366152346010360007657 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class GeoContinent
 * @package RegularLabs\Library\Condition
 */
class GeoContinent extends Geo
{
    public function pass()
    {
        if ( ! $this->getGeo() || empty($this->geo->continentCode))
        {
            return $this->_(false);
        }

        return $this->passSimple([$this->geo->continent, $this->geo->continentCode]);
    }
}
GeoCountry.php000064400000001354152346010360007356 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class GeoCountry
 * @package RegularLabs\Library\Condition
 */
class GeoCountry extends Geo
{
    public function pass()
    {
        if ( ! $this->getGeo() || empty($this->geo->countryCode))
        {
            return $this->_(false);
        }

        return $this->passSimple([$this->geo->country, $this->geo->countryCode]);
    }
}
GeoPostalcode.php000064400000001517152346010360010011 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class GeoPostalcode
 * @package RegularLabs\Library\Condition
 */
class GeoPostalcode extends Geo
{
    public function pass()
    {
        if ( ! $this->getGeo() || empty($this->geo->postalCode))
        {
            return $this->_(false);
        }

        // replace dashes with dots: 730-0011 => 730.0011
        $postalcode = str_replace('-', '.', $this->geo->postalCode);

        return $this->passInRange($postalcode);
    }
}
GeoRegion.php000064400000002354152346010360007137 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class GeoRegion
 * @package RegularLabs\Library\Condition
 */
class GeoRegion extends Geo
{
    public function pass()
    {
        if ( ! $this->getGeo() || empty($this->geo->countryCode) || empty($this->geo->regionCodes))
        {
            return $this->_(false);
        }

        $country = $this->geo->countryCode;
        $regions = $this->geo->regionCodes;

        array_walk($regions, function (&$region, $key, $country) {

            $region = $this->getCountryRegionCode($region, $country);
        }, $country);

        return $this->passSimple($regions);
    }

    private function getCountryRegionCode(&$region, $country)
    {
        switch ($country . '-' . $region)
        {
            case 'MX-CMX':
                return 'MX-DIF';

            default:
                return $country . '-' . $region;
        }
    }
}
Hikashop.php000064400000002131152346010360007020 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

/**
 * Class Hikashop
 * @package RegularLabs\Library\Condition
 */
abstract class Hikashop extends Condition
{
    public function beforePass()
    {
        $input = JFactory::getApplication()->input;

        // Reset $this->request because HikaShop messes with the view after stuff is loaded!
        $this->request->option = $input->get('option', $this->request->option);
        $this->request->view   = $input->get('view', $input->get('ctrl', $this->request->view));
        $this->request->id     = $input->getInt('id', $this->request->id);
        $this->request->Itemid = $input->getInt('Itemid', $this->request->Itemid);
    }
}
HikashopCategory.php000064400000005325152346010360010526 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class HikashopCategory
 * @package RegularLabs\Library\Condition
 */
class HikashopCategory extends Hikashop
{
    public function pass()
    {
        if ($this->request->option != 'com_hikashop')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_categories
                && ($this->request->view == 'category' || $this->request->layout == 'listing')
            )
            || ($this->params->inc_items && $this->request->view == 'product')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = $this->getCategories();

        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }

        if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        return $this->getParentIds($id, 'hikashop_category', 'category_parent_id', 'category_id');
    }

    private function getCategories()
    {
        switch (true)
        {
            case (($this->request->view == 'category' || $this->request->layout == 'listing') && $this->request->id):
                return [$this->request->id];

            case ($this->request->view == 'category' || $this->request->layout == 'listing'):
                include_once JPATH_ADMINISTRATOR . '/components/com_hikashop/helpers/helper.php';
                $menuClass = hikashop_get('class.menus');
                $menuData  = $menuClass->get($this->request->Itemid);

                return $this->makeArray($menuData->hikashop_params['selectparentlisting']);

            case ($this->request->id):
                $query = $this->db->getQuery(true)
                    ->select('c.category_id')
                    ->from('#__hikashop_product_category AS c')
                    ->where('c.product_id = ' . (int) $this->request->id);
                $this->db->setQuery($query);
                $cats = $this->db->loadColumn();

                return $this->makeArray($cats);

            default:
                return [];
        }
    }
}
HikashopPagetype.php000064400000002261152346010360010523 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class HikashopPagetype
 * @package RegularLabs\Library\Condition
 */
class HikashopPagetype extends Hikashop
{
    public function pass()
    {
        if ($this->request->option != 'com_hikashop')
        {
            return $this->_(false);
        }

        $type = $this->request->view;

        if (
            ($type == 'product' && in_array($this->request->task, ['contact', 'show']))
        )
        {
            $type .= '_' . $this->request->task;
        }
        elseif (
            ($type == 'product' && in_array($this->request->layout, ['contact', 'show']))
            || ($type == 'user' && in_array($this->request->layout, ['cpanel']))
        )
        {
            $type .= '_' . $this->request->layout;
        }

        return $this->passSimple($type);
    }
}
HikashopProduct.php000064400000001421152346010360010362 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class HikashopProduct
 * @package RegularLabs\Library\Condition
 */
class HikashopProduct extends Hikashop
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_hikashop' || $this->request->view != 'product')
        {
            return $this->_(false);
        }

        return $this->passSimple($this->request->id);
    }
}
Homepage.php000064400000013417152346010360007010 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use Joomla\CMS\Language\LanguageHelper as JLanguageHelper;
use Joomla\CMS\Uri\Uri as JUri;
use RegularLabs\Library\Condition;
use RegularLabs\Library\RegEx;
use RegularLabs\Library\StringHelper;

/**
 * Class HomePage
 * @package RegularLabs\Library\Condition
 */
class HomePage extends Condition
{
    public function pass()
    {
        $home = JFactory::getApplication()->getMenu('site')->getDefault(JFactory::getLanguage()->getTag());

        // return if option or other set values do not match the homepage menu item values
        if ($this->request->option)
        {
            // check if option is different to home menu
            if ( ! $home || ! isset($home->query['option']) || $home->query['option'] != $this->request->option)
            {
                return $this->_(false);
            }

            if ( ! $this->request->option)
            {
                // set the view/task/layout in the menu item to empty if not set
                $home->query['view']   ??= '';
                $home->query['task']   ??= '';
                $home->query['layout'] ??= '';
            }

            // check set values against home menu query items
            foreach ($home->query as $k => $v)
            {
                if ((isset($this->request->{$k}) && $this->request->{$k} != $v)
                    || (
                        ( ! isset($this->request->{$k}) || in_array($v, ['virtuemart', 'mijoshop']))
                        && JFactory::getApplication()->input->get($k) != $v
                    )
                )
                {
                    return $this->_(false);
                }
            }

            // check post values against home menu params
            foreach ($home->params->toObject() as $k => $v)
            {
                if (($v && isset($_POST[$k]) && $_POST[$k] != $v)
                    || ( ! $v && isset($_POST[$k]) && $_POST[$k])
                )
                {
                    return $this->_(false);
                }
            }
        }

        $pass = $this->checkPass($home);

        if ( ! $pass)
        {
            $pass = $this->checkPass($home, true);
        }

        return $this->_($pass);
    }

    private function checkPass(&$home, $addlang = false)
    {
        $uri = JUri::getInstance();

        if ($addlang)
        {
            $sef = $uri->getVar('lang');
            if (empty($sef))
            {
                $langs = array_keys(JLanguageHelper::getLanguages('sef'));
                $path  = StringHelper::substr(
                    $uri->toString(['scheme', 'user', 'pass', 'host', 'port', 'path']),
                    StringHelper::strlen($uri->base())
                );
                $path  = RegEx::replace('^index\.php/?', '', $path);
                $parts = explode('/', $path);
                $part  = reset($parts);
                if (in_array($part, $langs))
                {
                    $sef = $part;
                }
            }

            if (empty($sef))
            {
                return false;
            }
        }

        $query = $uri->toString(['query']);
        if (strpos($query, 'option=') === false && strpos($query, 'Itemid=') === false)
        {
            $url = $uri->toString(['host', 'path']);
        }
        else
        {
            $url = $uri->toString(['host', 'path', 'query']);
        }

        // remove the www.
        $url = RegEx::replace('^www\.', '', $url);
        // replace ampersand chars
        $url = str_replace('&amp;', '&', $url);
        // remove any language vars
        $url = RegEx::replace('((\?)lang=[a-z-_]*(&|$)|&lang=[a-z-_]*)', '\2', $url);
        // remove trailing nonsense
        $url = trim(RegEx::replace('/?\??&?$', '', $url));
        // remove the index.php/
        $url = RegEx::replace('/index\.php(/|$)', '/', $url);
        // remove trailing /
        $url = trim(RegEx::replace('/$', '', $url));

        $root = JUri::root();

        // remove the http(s)
        $root = RegEx::replace('^.*?://', '', $root);
        // remove the www.
        $root = RegEx::replace('^www\.', '', $root);
        //remove the port
        $root = RegEx::replace(':[0-9]+', '', $root);
        // so also passes on urls with trailing /, ?, &, /?, etc...
        $root = RegEx::replace('(Itemid=[0-9]*).*^', '\1', $root);
        // remove trailing /
        $root = trim(RegEx::replace('/$', '', $root));

        if ($addlang)
        {
            $root .= '/' . $sef;
        }

        /* Pass urls:
         * [root]
         */
        $regex = '^' . $root . '$';

        if (RegEx::match($regex, $url))
        {
            return true;
        }

        /* Pass urls:
         * [root]?Itemid=[menu-id]
         * [root]/?Itemid=[menu-id]
         * [root]/index.php?Itemid=[menu-id]
         * [root]/[menu-alias]
         * [root]/[menu-alias]?Itemid=[menu-id]
         * [root]/index.php?[menu-alias]
         * [root]/index.php?[menu-alias]?Itemid=[menu-id]
         * [root]/[menu-link]
         * [root]/[menu-link]&Itemid=[menu-id]
         */
        $regex = '^' . $root
            . '(/('
            . 'index\.php'
            . '|'
            . '(index\.php\?)?' . RegEx::quote($home->alias)
            . '|'
            . RegEx::quote($home->link)
            . ')?)?'
            . '(/?[\?&]Itemid=' . (int) $home->id . ')?'
            . '$';

        return RegEx::match($regex, $url);
    }
}
Ip.php000064400000010207152346010360005625 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Ip
 * @package RegularLabs\Library\Condition
 */
class Ip extends Condition
{
    public function pass()
    {
        if (is_array($this->selection))
        {
            $this->selection = implode(',', $this->selection);
        }

        $this->selection = explode(',', str_replace([' ', "\r", "\n"], ['', '', ','], $this->selection));

        $pass = $this->checkIPList();

        return $this->_($pass);
    }

    private function checkIP($range)
    {
        if (empty($range))
        {
            return false;
        }

        if (strpos($range, '-') !== false)
        {
            // Selection is an IP range
            return $this->checkIPRange($range);
        }

        // Selection is a single IP (part)
        return $this->checkIPPart($range);
    }

    private function checkIPList()
    {
        foreach ($this->selection as $range)
        {
            // Check next range if this one doesn't match
            if ( ! $this->checkIP($range))
            {
                continue;
            }

            // Match found, so return true!
            return true;
        }

        // No matches found, so return false
        return false;
    }

    private function checkIPPart($range)
    {
        $ip = $this->getIP();

        // Return if no IP address can be found (shouldn't happen, but who knows)
        if (empty($ip))
        {
            return false;
        }

        $ip_parts    = explode('.', $ip);
        $range_parts = explode('.', trim($range));

        // Trim the IP to the part length of the range
        $ip = implode('.', array_slice($ip_parts, 0, count($range_parts)));

        // Return false if ip does not match the range
        if ($range != $ip)
        {
            return false;
        }

        return true;
    }

    /* Fill the max range by prefixing it with the missing parts from the min range
     * So 101.102.103.104-201.202 becomes:
     * max: 101.102.201.202
     */

    private function checkIPRange($range)
    {
        $ip = $this->getIP();

        // Return if no IP address can be found (shouldn't happen, but who knows)
        if (empty($ip))
        {
            return false;
        }

        // check if IP is between or equal to the from and to IP range
        [$min, $max] = explode('-', trim($range), 2);

        // Return false if IP is smaller than the range start
        if ($ip < trim($min))
        {
            return false;
        }

        $max = $this->fillMaxRange($max, $min);

        // Return false if IP is larger than the range end
        if ($ip > trim($max))
        {
            return false;
        }

        return true;
    }

    private function fillMaxRange($max, $min)
    {
        $max_parts = explode('.', $max);

        if (count($max_parts) == 4)
        {
            return $max;
        }

        $min_parts = explode('.', $min);

        $prefix = array_slice($min_parts, 0, count($min_parts) - count($max_parts));

        return implode('.', $prefix) . '.' . implode('.', $max_parts);
    }

    private function getIP()
    {
        if ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR']) && $this->isValidIp($_SERVER['HTTP_X_FORWARDED_FOR']))
        {
            return $_SERVER['HTTP_X_FORWARDED_FOR'];
        }

        if ( ! empty($_SERVER['HTTP_X_REAL_IP']) && $this->isValidIp($_SERVER['HTTP_X_REAL_IP']))
        {
            return $_SERVER['HTTP_X_REAL_IP'];
        }

        if ( ! empty($_SERVER['HTTP_CLIENT_IP']) && $this->isValidIp($_SERVER['HTTP_CLIENT_IP']))
        {
            return $_SERVER['HTTP_CLIENT_IP'];
        }

        return $_SERVER['REMOTE_ADDR'];
    }

    private function isValidIp($string)
    {
        return preg_match('#^([0-9]{1,3}\.){3}[0-9]{1,3}$#', $string);
    }
}
K2.php000064400000002100152346010360005522 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;
use RegularLabs\Library\ConditionContent;

defined('_JEXEC') or die;

// If controller.php exists, assume this is K2 v3
defined('RL_K2_VERSION') or define('RL_K2_VERSION', file_exists(JPATH_ADMINISTRATOR . '/components/com_k2/controller.php') ? 3 : 2);

/**
 * Class K2
 * @package RegularLabs\Library\Condition
 */
abstract class K2 extends Condition
{
    use ConditionContent;

    public function getItem($fields = [])
    {
        $query = $this->db->getQuery(true)
            ->select($fields)
            ->from('#__k2_items')
            ->where('id = ' . (int) $this->request->id);
        $this->db->setQuery($query);

        return $this->db->loadObject();
    }
}
K2Category.php000064400000005463152346010360007237 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class K2Category
 * @package RegularLabs\Library\Condition
 */
class K2Category extends K2
{
    public function pass()
    {
        if ($this->request->option != 'com_k2')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_categories
                && (($this->request->view == 'itemlist' && $this->request->task == 'category')
                    || $this->request->view == 'latest'
                )
            )
            || ($this->params->inc_items && $this->request->view == 'item')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = $this->makeArray($this->getCategories());
        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }
        else if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        $parent_field = RL_K2_VERSION == 3 ? 'parent_id' : 'parent';

        return $this->getParentIds($id, 'k2_categories', $parent_field);
    }

    private function getCategories()
    {
        switch ($this->request->view)
        {
            case 'item' :
                return $this->getCategoryIDFromItem();
                break;

            case 'itemlist' :
                return $this->getCategoryID();
                break;

            default:
                return '';
        }
    }

    private function getCategoryID()
    {
        return $this->request->id ?: JFactory::getApplication()->getUserStateFromRequest('com_k2itemsfilter_category', 'catid', 0, 'int');
    }

    private function getCategoryIDFromItem()
    {
        if ($this->article && isset($this->article->catid))
        {
            return $this->article->catid;
        }

        if ( ! $this->request->id)
        {
            return $this->getCategoryID();
        }

        $query = $this->db->getQuery(true)
            ->select('i.catid')
            ->from('#__k2_items AS i')
            ->where('i.id = ' . (int) $this->request->id);
        $this->db->setQuery($query);

        return $this->db->loadResult();
    }
}
K2Item.php000064400000002461152346010360006353 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class K2Item
 * @package RegularLabs\Library\Condition
 */
class K2Item extends K2
{
    public function pass()
    {
        if ( ! $this->request->id || $this->request->option != 'com_k2' || $this->request->view != 'item')
        {
            return $this->_(false);
        }

        $pass = false;

        // Pass Article Id
        if ( ! $this->passItemByType($pass, 'ContentId'))
        {
            return $this->_(false);
        }

        // Pass Content Keyword
        if ( ! $this->passItemByType($pass, 'ContentKeyword'))
        {
            return $this->_(false);
        }

        // Pass Meta Keyword
        if ( ! $this->passItemByType($pass, 'MetaKeyword'))
        {
            return $this->_(false);
        }

        // Pass Author
        if ( ! $this->passItemByType($pass, 'Author'))
        {
            return $this->_(false);
        }

        return $this->_($pass);
    }
}
K2Pagetype.php000064400000001507152346010360007233 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class K2Pagetype
 * @package RegularLabs\Library\Condition
 */
class K2Pagetype extends K2
{
    public function pass()
    {
        // K2 messes with the task in the request, so we have to reset the task
        $this->request->task = JFactory::getApplication()->input->get('task');

        return $this->passByPageType('com_k2', $this->selection, $this->include_type, false, true);
    }
}
K2Tag.php000064400000003110152346010360006160 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class K2Tag
 * @package RegularLabs\Library\Condition
 */
class K2Tag extends K2
{
    public function pass()
    {
        if ($this->request->option != 'com_k2')
        {
            return $this->_(false);
        }

        $tag  = trim(JFactory::getApplication()->input->getString('tag', ''));
        $pass = (
            ($this->params->inc_tags && $tag != '')
            || ($this->params->inc_items && $this->request->view == 'item')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        if ($this->params->inc_tags && $tag != '')
        {
            $tags = [trim(JFactory::getApplication()->input->getString('tag', ''))];

            return $this->passSimple($tags, true);
        }

        $query = $this->db->getQuery(true)
            ->select('t.name')
            ->from('#__k2_tags_xref AS x')
            ->join('LEFT', '#__k2_tags AS t ON t.id = x.tagID')
            ->where('x.itemID = ' . (int) $this->request->id)
            ->where('t.published = 1');
        $this->db->setQuery($query);
        $tags = $this->db->loadColumn();

        return $this->passSimple($tags, true);
    }
}
Language.php000064400000001264152346010360007003 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

/**
 * Class Language
 * @package RegularLabs\Library\Condition
 */
class Language extends Condition
{
    public function pass()
    {
        return $this->passSimple(JFactory::getLanguage()->getTag(), true);
    }
}
Menu.php000064400000005245152346010360006167 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;
use RegularLabs\Library\Document as RL_Document;

/**
 * Class Menu
 * @package RegularLabs\Library\Condition
 */
class Menu extends Condition
{
    public function pass()
    {
        // return if no Itemid or selection is set
        if ( ! $this->request->Itemid || empty($this->selection))
        {
            return $this->_($this->params->inc_noitemid);
        }

        // return true if menu is in selection
        if (in_array($this->request->Itemid, $this->selection))
        {
            return $this->_(($this->params->inc_children != 2));
        }

        $menutype = 'type.' . self::getMenuType();

        // return true if menu type is in selection
        if (in_array($menutype, $this->selection))
        {
            return $this->_(true);
        }

        if ( ! $this->params->inc_children)
        {
            return $this->_(false);
        }

        $parent_ids = $this->getMenuParentIds($this->request->Itemid);
        $parent_ids = array_diff($parent_ids, [1]);
        foreach ($parent_ids as $id)
        {
            if ( ! in_array($id, $this->selection))
            {
                continue;
            }

            return $this->_(true);
        }

        return $this->_(false);
    }

    private function getMenuParentIds($id = 0)
    {
        return $this->getParentIds($id, 'menu');
    }

    private function getMenuType()
    {
        if (isset($this->request->menutype))
        {
            return $this->request->menutype;
        }

        if (empty($this->request->Itemid))
        {
            $this->request->menutype = '';

            return $this->request->menutype;
        }

        if (RL_Document::isClient('site'))
        {
            $menu = JFactory::getApplication()->getMenu()->getItem((int) $this->request->Itemid);

            $this->request->menutype = $menu->menutype ?? '';

            return $this->request->menutype;
        }

        $query = $this->db->getQuery(true)
            ->select('m.menutype')
            ->from('#__menu AS m')
            ->where('m.id = ' . (int) $this->request->Itemid);
        $this->db->setQuery($query);
        $this->request->menutype = $this->db->loadResult();

        return $this->request->menutype;
    }
}
Mijoshop.php000064400000003101152346010360007040 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use MijoShop as MijoShopClass;
use RegularLabs\Library\Condition;

/**
 * Class Mijoshop
 * @package RegularLabs\Library\Condition
 */
abstract class Mijoshop extends Condition
{
    public function initRequest(&$request)
    {
        $input = JFactory::getApplication()->input;

        $category_id = $input->getCmd('path', 0);

        if (strpos($category_id, '_'))
        {
            $category_parts = explode('_', $category_id);
            $category_id    = end($category_parts);
        }

        $request->item_id     = $input->getInt('product_id', 0);
        $request->category_id = $category_id;
        $request->id          = $request->item_id ?: $request->category_id;

        $view = $input->getCmd('view', '');

        if (empty($view))
        {
            $mijoshop = JPATH_ROOT . '/components/com_mijoshop/mijoshop/mijoshop.php';

            if ( ! file_exists($mijoshop))
            {
                return;
            }

            require_once $mijoshop;

            $route = $input->getString('route', '');
            $view  = MijoShopClass::get('router')->getView($route);
        }

        $request->view = $view;
    }
}
MijoshopCategory.php000064400000004164152346010360010550 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class MijoshopCategory
 * @package RegularLabs\Library\Condition
 */
class MijoshopCategory extends Mijoshop
{
    public function pass()
    {
        if ($this->request->option != 'com_mijoshop')
        {
            return $this->_(false);
        }

        $pass = (
            ($this->params->inc_categories
                && ($this->request->view == 'category')
            )
            || ($this->params->inc_items && $this->request->view == 'product')
        );

        if ( ! $pass)
        {
            return $this->_(false);
        }

        $cats = $this->getCats();

        $pass = $this->passSimple($cats, false, 'include');

        if ($pass && $this->params->inc_children == 2)
        {
            return $this->_(false);
        }

        if ( ! $pass && $this->params->inc_children)
        {
            foreach ($cats as $cat)
            {
                $cats = array_merge($cats, $this->getCatParentIds($cat));
            }
        }

        return $this->passSimple($cats);
    }

    private function getCatParentIds($id = 0)
    {
        return $this->getParentIds($id, 'mijoshop_category', 'parent_id', 'category_id');
    }

    private function getCats()
    {
        if ($this->request->category_id)
        {
            return $this->makeArray($this->request->category_id);
        }

        if ( ! $this->request->item_id)
        {
            return [];
        }

        $query = $this->db->getQuery(true)
            ->select('c.category_id')
            ->from('#__mijoshop_product_to_category AS c')
            ->where('c.product_id = ' . (int) $this->request->id);
        $this->db->setQuery($query);
        $cats = $this->db->loadColumn();

        return $this->makeArray($cats);
    }
}
MijoshopPagetype.php000064400000001223152346010360010542 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class MijoshopPagetype
 * @package RegularLabs\Library\Condition
 */
class MijoshopPagetype extends Mijoshop
{
    public function pass()
    {
        return $this->passByPageType('com_mijoshop', $this->selection, $this->include_type, true);
    }
}
Tag.php000064400000007537152346010360006004 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class Tag
 * @package RegularLabs\Library\Condition
 */
class Tag extends Condition
{
    public function pass()
    {
        if ( ! $this->request->id)
        {
            return $this->_(false);
        }

        if (in_array($this->request->option, ['com_content', 'com_flexicontent']))
        {
            return $this->passTagsContent();
        }

        if ($this->request->option != 'com_tags'
            || $this->request->view != 'tag'
        )
        {
            return $this->_(false);
        }

        return $this->passTag($this->request->id);
    }

    private function getTagsParentIds($id = 0)
    {
        $parentids = $this->getParentIds($id, 'tags');
        // Remove the root tag
        $parentids = array_diff($parentids, [1]);

        return $parentids;
    }

    private function passTag($tag)
    {
        $pass = in_array($tag, $this->selection);

        if ($pass)
        {
            // If passed, return false if assigned to only children
            // Else return true
            return ($this->params->inc_children != 2);
        }

        if ( ! $this->params->inc_children)
        {
            return false;
        }

        // Return true if a parent id is present in the selection
        return array_intersect(
            $this->getTagsParentIds($tag),
            $this->selection
        );
    }

    private function passTagList($tags)
    {
        if ($this->params->match_all)
        {
            return $this->passTagListMatchAll($tags);
        }

        foreach ($tags as $tag)
        {
            if ( ! $this->passTag($tag->id) && ! $this->passTag($tag->title))
            {
                continue;
            }

            return true;
        }

        return false;
    }

    private function passTagListMatchAll($tags)
    {
        foreach ($this->selection as $id)
        {
            if ( ! $this->passTagMatchAll($id, $tags))
            {
                return false;
            }
        }

        return true;
    }

    private function passTagMatchAll($id, $tags)
    {

        foreach ($tags as $tag)
        {
            if ($tag->id == $id || $tag->title == $id)
            {
                return true;
            }
        }

        return false;
    }

    private function passTagsContent()
    {
        $is_item     = in_array($this->request->view, ['', 'article', 'item']);
        $is_category = in_array($this->request->view, ['category']);

        switch (true)
        {
            case ($is_item):
                $prefix = 'com_content.article';
                break;

            case ($is_category):
                $prefix = 'com_content.category';
                break;

            default:
                return $this->_(false);
        }

        // Load the tags.
        $query = $this->db->getQuery(true)
            ->select($this->db->quoteName('t.id'))
            ->select($this->db->quoteName('t.title'))
            ->from('#__tags AS t')
            ->join(
                'INNER', '#__contentitem_tag_map AS m'
                . ' ON m.tag_id = t.id'
                . ' AND m.type_alias = ' . $this->db->quote($prefix)
                . ' AND m.content_item_id = ' . (int) $this->request->id
            );
        $this->db->setQuery($query);
        $tags = $this->db->loadObjectList();

        if (empty($tags))
        {
            return $this->_(false);
        }

        return $this->_($this->passTagList($tags));
    }
}
Template.php000064400000004240152346010360007030 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

/**
 * Class Template
 * @package RegularLabs\Library\Condition
 */
class Template extends Condition
{
    public function getTemplate()
    {
        $template = JFactory::getApplication()->getTemplate(true);

        if (isset($template->id))
        {
            return $template;
        }

        $params = json_encode($template->params);

        // Find template style id based on params, as the template style id is not always stored in the getTemplate
        $query = $this->db->getQuery(true)
            ->select('id')
            ->from('#__template_styles AS s')
            ->where('s.client_id = 0')
            ->where('s.template = ' . $this->db->quote($template->template))
            ->where('s.params = ' . $this->db->quote($params))
            ->setLimit(1);
        $this->db->setQuery($query);
        $template->id = $this->db->loadResult('id');

        if ($template->id)
        {
            return $template;
        }

        // No template style id is found, so just grab the first result based on the template name
        $query->clear('where')
            ->where('s.client_id = 0')
            ->where('s.template = ' . $this->db->quote($template->template))
            ->setLimit(1);
        $this->db->setQuery($query);
        $template->id = $this->db->loadResult('id');

        return $template;
    }

    public function pass()
    {
        $template = $this->getTemplate();

        // Put template name and name + style id into array
        // The '::' separator was used in pre Joomla 3.3
        $template = [$template->template, $template->template . '--' . $template->id, $template->template . '::' . $template->id];

        return $this->passSimple($template, true);
    }
}
Url.php000064400000005027152346010360006023 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Uri\Uri as JUri;
use RegularLabs\Library\Condition;
use RegularLabs\Library\RegEx;
use RegularLabs\Library\StringHelper;

/**
 * Class Url
 * @package RegularLabs\Library\Condition
 */
class Url extends Condition
{
    public function pass()
    {
        $regex         = $this->params->regex ?? false;
        $casesensitive = $this->params->casesensitive ?? false;

        if ( ! is_array($this->selection))
        {
            $this->selection = explode("\n", $this->selection);
        }

        if (count($this->selection) == 1)
        {
            $this->selection = explode("\n", $this->selection[0]);
        }

        $url = JUri::getInstance();
        $url = $url->toString();

        $urls = [
            StringHelper::html_entity_decoder(urldecode($url)),
            urldecode($url),
            StringHelper::html_entity_decoder($url),
            $url,
        ];
        $urls = array_unique($urls);

        $pass = false;
        foreach ($urls as $url)
        {
            if ( ! $casesensitive)
            {
                $url = StringHelper::strtolower($url);
            }

            foreach ($this->selection as $selection)
            {
                $selection = trim($selection);
                if ($selection == '')
                {
                    continue;
                }

                if ($regex)
                {
                    $url_part = str_replace(['#', '&amp;'], ['\#', '(&amp;|&)'], $selection);
                    if (@RegEx::match($url_part, $url, $match, $casesensitive ? 's' : 'si'))
                    {
                        $pass = true;
                        break;
                    }

                    continue;
                }

                if ( ! $casesensitive)
                {
                    $selection = StringHelper::strtolower($selection);
                }

                if (strpos($url, $selection) !== false)
                {
                    $pass = true;
                    break;
                }
            }

            if ($pass)
            {
                break;
            }
        }

        return $this->_($pass);
    }
}
User.php000064400000001037152346010360006174 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

use RegularLabs\Library\Condition;

defined('_JEXEC') or die;

/**
 * Class User
 * @package RegularLabs\Library\Condition
 */
abstract class User extends Condition
{
}
UserAccesslevel.php000064400000003303152346010360010344 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\DB as RL_DB;

/**
 * Class UserAccesslevel
 * @package RegularLabs\Library\Condition
 */
class UserAccesslevel extends User
{
    public function pass()
    {
        $user = JFactory::getApplication()->getIdentity() ?: JFactory::getUser();

        $levels = $user->getAuthorisedViewLevels();

        $this->selection = $this->convertAccessLevelNamesToIds($this->selection);

        return $this->passSimple($levels);
    }

    private function convertAccessLevelNamesToIds($selection)
    {
        $names = [];

        foreach ($selection as $i => $level)
        {
            if (is_numeric($level))
            {
                continue;
            }

            unset($selection[$i]);

            $names[] = strtolower(str_replace(' ', '', $level));
        }

        if (empty($names))
        {
            return $selection;
        }

        $db = JFactory::getDbo();

        $query = $db->getQuery(true)
            ->select($db->quoteName('id'))
            ->from('#__viewlevels')
            ->where('LOWER(REPLACE(' . $db->quoteName('title') . ', " ", ""))'
                . RL_DB::in($names));
        $db->setQuery($query);

        $level_ids = $db->loadColumn();

        return array_unique(array_merge($selection, $level_ids));
    }
}
UserGrouplevel.php000064400000010161152346010360010237 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\DB as RL_DB;

/**
 * Class UserGrouplevel
 * @package RegularLabs\Library\Condition
 */
class UserGrouplevel extends User
{
    static $user_group_children;

    public function pass()
    {
        $user = JFactory::getApplication()->getIdentity() ?: JFactory::getUser();

        if ( ! empty($user->groups))
        {
            $groups = array_values($user->groups);
        }
        else
        {
            $groups = $user->getAuthorisedGroups();
        }

        if ( ! $this->params->match_all && $this->params->inc_children)
        {
            $this->setUserGroupChildrenIds();
        }

        $this->selection = $this->convertUsergroupNamesToIds($this->selection);

        if ($this->params->match_all)
        {
            return $this->passMatchAll($groups);
        }

        return $this->passSimple($groups);
    }

    private function convertUsergroupNamesToIds($selection)
    {
        $names = [];

        foreach ($selection as $i => $group)
        {
            if (is_numeric($group))
            {
                continue;
            }

            unset($selection[$i]);

            $names[] = strtolower(str_replace(' ', '', $group));
        }

        if (empty($names))
        {
            return $selection;
        }

        $db = JFactory::getDbo();

        $query = $db->getQuery(true)
            ->select($db->quoteName('id'))
            ->from('#__usergroups')
            ->where('LOWER(REPLACE(' . $db->quoteName('title') . ', " ", ""))'
                . RL_DB::in($names));
        $db->setQuery($query);

        $group_ids = $db->loadColumn();

        return array_unique(array_merge($selection, $group_ids));
    }

    private function getUserGroupChildrenIds($groups)
    {
        $children = [];

        foreach ($groups as $group)
        {
            $group_children = $this->getUserGroupChildrenIdsByGroup($group);

            if (empty($group_children))
            {
                continue;
            }

            $children = array_merge($children, $group_children);

            $group_grand_children = $this->getUserGroupChildrenIds($group_children);

            if (empty($group_grand_children))
            {
                continue;
            }

            $children = array_merge($children, $group_grand_children);
        }

        $children = array_unique($children);

        return $children;
    }

    private function getUserGroupChildrenIdsByGroup($group)
    {
        $group = (int) $group;

        if ( ! is_null(self::$user_group_children))
        {
            return self::$user_group_children[$group] ?? [];
        }

        $db = JFactory::getDbo();

        $query = $db->getQuery(true)
            ->select(['id', 'parent_id'])
            ->from($db->quoteName('#__usergroups'));
        $db->setQuery($query);

        $groups = $db->loadAssocList('id', 'parent_id');

        foreach ($groups as $id => $parent)
        {
            if ( ! isset(self::$user_group_children[$parent]))
            {
                self::$user_group_children[$parent] = [];
            }

            self::$user_group_children[$parent][] = $id;
        }

        return self::$user_group_children[$group] ?? [];
    }

    private function passMatchAll($groups)
    {
        $pass = ! array_diff($this->selection, $groups) && ! array_diff($groups, $this->selection);

        return $this->_($pass);
    }

    private function setUserGroupChildrenIds()
    {
        $children = $this->getUserGroupChildrenIds($this->selection);

        if ($this->params->inc_children == 2)
        {
            $this->selection = $children;

            return;
        }

        $this->selection = array_merge($this->selection, $children);
    }
}
UserUser.php000064400000001310152346010360007025 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;

/**
 * Class UserUser
 * @package RegularLabs\Library\Condition
 */
class UserUser extends User
{
    public function pass()
    {
        $user = JFactory::getApplication()->getIdentity() ?: JFactory::getUser();

        return $this->passSimple($user->get('id'));
    }
}
Virtuemart.php000064400000002073152346010360007421 0ustar00<?php
/**
 * @package         Regular Labs Library
 * @version         23.7.24631
 * 
 * @author          Peter van Westen <info@regularlabs.com>
 * @link            https://regularlabs.com
 * @copyright       Copyright © 2023 Regular Labs All Rights Reserved
 * @license         GNU General Public License version 2 or later
 */

namespace RegularLabs\Library\Condition;

defined('_JEXEC') or die;

use Joomla\CMS\Factory as JFactory;
use RegularLabs\Library\Condition;

/**
 * Class Virtuemart
 * @package RegularLabs\Library\Condition
 */
abstract class Virtuemart extends Condition
{
    public function initRequest(&$request)
    {
        $virtuemart_product_id  = JFactory::getApplication()->input->get('virtuemart_product_id', [], 'array');
        $virtuemart_category_id = JFactory::getApplication()->input->get('virtuemart_category_id', [], 'array');

        $request->item_id     = $virtuemart_product_id[0] ?? null;
        $request->category_id = $virtuemart_category_id[0] ?? null;
        $request->id          = $request->item_id ?: $request->category_id;
    }
}