Файловый менеджер - Редактировать - /home/wuectly/www/03cbe/src.tar
Назад
Extension/MediaJce.php 0000604 00000001273 15245530242 0010673 0 ustar 00 <?php /** * @package Jce.Plugin * @subpackage Fields.mediajce * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @copyright (C) 2020 - 2024 Ryan Demmer. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Fields\MediaJce\Extension; use Joomla\Component\Fields\Administrator\Plugin\FieldsPlugin; use Joomla\Plugin\Fields\MediaJce\PluginTraits\FormTrait; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Fields Media Plugin * * @since 2.9.73 */ final class MediaJce extends FieldsPlugin { use FormTrait; } PluginTraits/FormTrait.php 0000604 00000004023 15245530242 0011606 0 ustar 00 <?php /** * @package JCE * @subpackage Editors.Jce * * @copyright Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved. * @copyright Copyright (c) 2009-2024 Ryan Demmer. All rights reserved * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\System\Jce\PluginTraits; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Editor\Editor; use Joomla\CMS\Factory; use Joomla\CMS\Form\Form; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Plugin\PluginHelper; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Handles the onDisplay event for the JCE editor. * * @since 2.9.70 */ trait FormTrait { /** * Transforms the field into a DOM XML element and appends it as a child on the given parent. * * @param stdClass $field The field. * @param DOMElement $parent The field node parent. * @param Form $form The form. * * @return DOMElement * * @since 3.7.0 */ public function onCustomFieldsPrepareDom($field, \DOMElement $parent, Form $form) { if ($field->type !== 'mediajce') { return; } // media will be loaded by JCE Pro if (PluginHelper::isEnabled('system', 'jcepro')) { return; } $document = Factory::getDocument(); // load scripts and styles for core JCE Media field HTMLHelper::_('jquery.framework'); $option = Factory::getApplication()->input->getCmd('option'); $component = ComponentHelper::getComponent($option); $document->addScriptOptions('plg_system_jce', array( 'context' => (int) $component->id, ), true); $document->addScript(Uri::root(true) . '/media/com_jce/site/js/media.min.js', array('version' => 'auto')); $document->addStyleSheet(Uri::root(true) . '/media/com_jce/site/css/media.min.css', array('version' => 'auto')); } } EditorButtonPopup.php 0000604 00000004046 15245535751 0010737 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Exception; use Joomla\CMS\Language\Text as JText; use ReflectionClass; /** * Class EditorButtonPopup * @package RegularLabs\Library */ class EditorButtonPopup { var $extension = ''; var $params = null; var $require_core_auth = true; public function __construct($extension) { $this->extension = $extension; $this->params = Parameters::getInstance()->getPluginParams($extension); } public function render() { if ( ! Extension::isAuthorised($this->require_core_auth)) { throw new Exception(JText::_("ALERTNOTAUTH")); } if ( ! Extension::isEnabledInArea($this->params)) { throw new Exception(JText::_("ALERTNOTAUTH")); } $this->loadLibraryLanguages(); $this->loadLibraryScriptsStyles(); $this->loadLanguages(); Document::style('regularlabs/popup.min.css'); $this->loadScripts(); $this->loadStyles(); echo $this->renderTemplate(); } public function loadLanguages() { Language::load('plg_editors-xtd_' . $this->extension); Language::load('plg_system_' . $this->extension); } public function loadScripts() { } public function loadStyles() { } private function loadLibraryLanguages() { Language::load('plg_system_regularlabs'); } private function loadLibraryScriptsStyles() { Document::loadPopupDependencies(); } private function renderTemplate() { ob_start(); include $this->getDir() . '/popup.tmpl.php'; $html = ob_get_contents(); ob_end_clean(); return $html; } private function getDir() { // use static::class instead of get_class($this) after php 5.4 support is dropped $rc = new ReflectionClass(get_class($this)); return dirname($rc->getFileName()); } } EditorButton.php 0000604 00000001003 15245535751 0007701 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * @deprecated 2018-11-14 Use EditorButtonPlugin instead */ class EditorButton extends EditorButtonPlugin { } Api/ConditionInterface.php 0000604 00000001040 15245535751 0011540 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Api; defined('_JEXEC') or die; /** * Interface ConditionConditionInterface * @package RegularLabs\Library\Api */ interface ConditionInterface { public function pass(); } Alias.php 0000604 00000006104 15245535751 0006317 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Application\ApplicationHelper as JApplicationHelper; use Joomla\CMS\Factory as JFactory; /** * Class Alias * @package RegularLabs\Library */ class Alias { /** * Creates an alias from a string * * @param string $string * * @return string */ public static function get($string = '', $unicode = false) { if (empty($string)) { return ''; } $string = strip_tags($string); // Remove < > html entities $string = str_replace(['<', '>'], '', $string); // Remove quotes $string = str_replace(['"', "'"], '', $string); if ($unicode || JFactory::getConfig()->get('unicodeslugs') == 1) { return self::stringURLUnicodeSlug($string); } // Convert html entities $string = StringHelper::html_entity_decoder($string); return JApplicationHelper::stringURLSafe($string); } /** * Creates a unicode alias from a string * Based on stringURLUnicodeSlug method from the unicode slug plugin by infograf768 * * @param string $string * * @return string */ private static function stringURLUnicodeSlug($string = '') { if (empty($string)) { return ''; } // Remove < > html entities $string = str_replace(['<', '>'], '', $string); // Convert html entities $string = StringHelper::html_entity_decoder($string); // Convert to lowercase $string = StringHelper::strtolower($string); // remove html tags $string = RegEx::replace('</?[a-z][^>]*>', '', $string); // remove comments tags $string = RegEx::replace('<\!--.*?-->', '', $string); // Replace weird whitespace characters like (Â) with spaces //$string = str_replace(array(chr(160), chr(194)), ' ', $string); $string = str_replace("\xC2\xA0", ' ', $string); $string = str_replace("\xE2\x80\xA8", ' ', $string); // ascii only // Replace double byte whitespaces by single byte (East Asian languages) $string = str_replace("\xE3\x80\x80", ' ', $string); // Remove any '-' from the string as they will be used as concatenator. // Would be great to let the spaces in but only Firefox is friendly with this $string = str_replace('-', ' ', $string); // Replace forbidden characters by whitespaces $string = RegEx::replace('[' . RegEx::quote(',:#$*"@+=;&.%()[]{}/\'\\|') . ']', "\x20", $string); // Delete all characters that should not take up any space, like: ? $string = RegEx::replace('[' . RegEx::quote('?!¿¡') . ']', '', $string); // Trim white spaces at beginning and end of alias and make lowercase $string = trim($string); // Remove any duplicate whitespace and replace whitespaces by hyphens $string = RegEx::replace('\x20+', '-', $string); // Remove leading and trailing hyphens $string = trim($string, '-'); return $string; } } DB.php 0000604 00000010602 15245535751 0005551 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class DB * @package RegularLabs\Library */ class DB { static $tables = []; /** * Check if a table exists in the database * * @param string $table * * @return bool */ public static function tableExists($table) { if (isset(self::$tables[$table])) { return self::$tables[$table]; } $db = JFactory::getDbo(); if (strpos($table, '#__') === 0) { $table = $db->getPrefix() . substr($table, 3); } if (strpos($table, $db->getPrefix()) !== 0) { $table = $db->getPrefix() . $table; } $query = 'SHOW TABLES LIKE ' . $db->quote($table); $db->setQuery($query); $result = $db->loadResult(); self::$tables[$table] = ! empty($result); return self::$tables[$table]; } /** * Concatenate conditions using AND or OR * * @param string $glue * @param array $conditions * * @return string */ public static function combine($conditions = [], $glue = 'OR') { if (empty($conditions)) { return ''; } if ( ! is_array($conditions)) { return (string) $conditions; } if (count($conditions) < 2) { return $conditions[0]; } $glue = strtoupper($glue) == 'AND' ? 'AND' : 'OR'; return '(' . implode(' ' . $glue . ' ', $conditions) . ')'; } /** * Create an IN statement * Reverts to a simple equals statement if array just has 1 value * * @param string|array $value * * @return string */ public static function in($value, $handle_now = false) { if (empty($value) && ! is_array($value)) { return ' = 0'; } $operator = self::getOperator($value); $value = self::prepareValue($value, $handle_now); if ( ! is_array($value)) { return ' ' . $operator . ' ' . $value; } if (count($value) == 1) { return ' ' . $operator . ' ' . reset($value); } $operator = $operator == '!=' ? 'NOT IN' : 'IN'; $values = empty($value) ? "''" : implode(',', $value); return ' ' . $operator . ' (' . $values . ')'; } public static function prepareValue($value, $handle_now = false) { if (is_array($value)) { $array = $value; foreach ($array as &$array_value) { $array_value = self::prepareValue($array_value, $handle_now); } return $array; } $dates = ['now', 'now()', 'date()', 'jfactory::getdate()']; if ($handle_now && ! is_array($value) && in_array(strtolower($value), $dates)) { return 'NOW()'; } if (is_int($value) || ctype_digit($value)) { return $value; } return JFactory::getDbo()->quote($value); } public static function getOperator(&$value, $default = '=') { if (empty($value)) { return $default; } if (is_array($value)) { $value = array_values($value); $operator = self::getOperatorFromValue($value[0], $default); // remove operators from other array values foreach ($value as &$val) { $val = self::removeOperator($val); } return $operator; } $operator = self::getOperatorFromValue($value, $default); $value = self::removeOperator($value); return $operator; } public static function removeOperator($string) { $regex = '^' . RegEx::quote(self::getOperators(), 'operator'); return RegEx::replace($regex, '', $string); } public static function getOperators() { return ['!NOT!', '!=', '!', '<>', '<=', '<', '>=', '>', '=', '==']; } public static function getOperatorFromValue($value, $default = '=') { $regex = '^' . RegEx::quote(self::getOperators(), 'operator'); if ( ! RegEx::match($regex, $value, $parts)) { return $default; } $operator = $parts['operator']; switch ($operator) { case '!': case '!NOT!': $operator = '!='; break; case '==': $operator = '='; break; } return $operator; } /** * Create an LIKE statement * * @param string $value * * @return string */ public static function like($value) { $operator = self::getOperator($value); $value = str_replace('*', '%', self::prepareValue($value)); $operator = $operator == '!=' ? 'NOT LIKE' : 'LIKE'; return ' ' . $operator . ' ' . $value; } } License.php 0000604 00000003333 15245535751 0006651 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Layout\LayoutHelper; /** * Class Language * @package RegularLabs\Library */ class License { /** * Render the license message for Free versions * * @param string $name * @param bool $check_pro * * @return string */ public static function getMessage($name, $check_pro = false) { if ( ! $name) { return ''; } $alias = Extension::getAliasByName($name); $name = Extension::getNameByAlias($name); if ($check_pro && self::isPro($alias)) { return ''; } $displayData = [ 'msgList' => [ '' => [ JText::sprintf('RL_IS_FREE_VERSION', $name), JText::_('RL_FOR_MORE_GO_PRO'), '<a href="https://regularlabs.com/purchase/cart/add/' . $alias . '" target="_blank" class="btn btn-small btn-primary">' . '<span class="icon-basket"></span> ' . StringHelper::html_entity_decoder(JText::_('RL_GO_PRO')) . '</a>', ], ], ]; return LayoutHelper::render('joomla.system.message', $displayData); } /** * Check if the installed version of the extension is a Pro version * * @param string $element_name * * @return bool */ private static function isPro($element_name) { if ( ! $version = Extension::getXMLValue('version', $element_name)) { return false; } return (stripos($version, 'PRO') !== false); } } Plugin.php 0000604 00000024051 15245535751 0006525 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Application\CMSApplication as JCMSApplication; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Form\Form as JForm; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Plugin\CMSPlugin as JPlugin; use Joomla\CMS\Plugin\PluginHelper as JPluginHelper; class Plugin extends JPlugin { public $_alias = ''; public $_title = ''; public $_lang_prefix = ''; public $_is_admin = false; public $_has_tags = false; public $_enable_in_frontend = true; public $_enable_in_admin = false; public $_can_disable_by_url = true; public $_disable_on_components = false; public $_protected_formats = []; public $_page_types = []; public $_jversion = 3; private $_pass = null; /** * @var JCMSApplication */ protected $app; /** * @var \JDatabaseDriver */ protected $db; /** * @param object &$subject The object to observe * @param array $config An optional associative array of configuration settings. * Recognized key values include 'name', 'group', 'params', 'language' * (this list is not meant to be comprehensive). */ public function __construct(&$subject, $config = []) { if (isset($config['id'])) { $this->_id = $config['id']; } parent::__construct($subject, $config); $this->app = JFactory::getApplication(); $this->db = JFactory::getDbo(); $this->_is_admin = Document::isAdmin(); if (empty($this->_alias)) { $this->_alias = $this->_name; } if (empty($this->_title)) { $this->_title = strtoupper($this->_alias); } Language::load('plg_' . $this->_type . '_' . $this->_name); } /** * @return void */ public function onAfterRoute() { if ( ! $this->passChecks()) { return; } $this->handleOnAfterRoute(); } /** * @return void */ public function onAfterDispatch() { if ( ! $this->passChecks()) { return; } $this->handleOnAfterDispatch(); $buffer = Document::getBuffer(); $this->loadStylesAndScripts($buffer); if ( ! $buffer) { return; } if ( ! $this->changeDocumentBuffer($buffer)) { return; } Document::setBuffer($buffer); } /** * @return void */ public function onAfterInitialise() { if ( ! $this->passChecks()) { return; } $this->handleOnAfterInitialise(); } /** * @param string $context The context of the content being passed to the plugin. * @param mixed &$row An object with a "text" property * @param mixed &$params Additional parameters. See {@see PlgContentContent()}. * @param integer $page Optional page number. Unused. Defaults to zero. * * @return bool */ public function onContentPrepare($context, &$article, &$params, $page = 0) { if ( ! $this->passChecks()) { return true; } $area = isset($article->created_by) ? 'article' : 'other'; $context = (($params instanceof \JRegistry) && $params->get('rl_search')) ? 'com_search.' . $params->get('readmore_limit') : $context; if ( ! $this->handleOnContentPrepare($area, $context, $article, $params, $page)) { return false; } Article::process($article, $context, $this, 'processArticle', [$area, $context, $article, $page]); return true; } /** * @param JForm $form The form to be altered. * @param mixed $data The associated data for the form. * * @return bool */ public function onContentPrepareForm(JForm $form, $data) { if ( ! $this->passChecks()) { return true; } return $this->handleOnContentPrepareForm($form, $data); } /** * @return void */ public function onAfterRender() { if ( ! $this->passChecks()) { return; } $this->handleOnAfterRender(); $html = $this->app->getBody(); if ($html == '') { return; } if ( ! $this->changeFinalHtmlOutput($html)) { return; } $this->cleanFinalHtmlOutput($html); $this->app->setBody($html); } /** * @return void */ protected function handleOnAfterRoute() { } /** * @return void */ protected function handleOnAfterDispatch() { } /** * @return void */ protected function handleOnAfterInitialise() { } /** * @param string $area * @param string $context The context of the content being passed to the plugin. * @param mixed $article An object with a "text" property * @param mixed &$params Additional parameters. See {@see PlgContentContent()}. * @param int $page Optional page number. Unused. Defaults to zero. * * @return bool */ protected function handleOnContentPrepare($area, $context, &$article, &$params, $page = 0) { return true; } /** * @param JForm $form The form to be altered. * @param mixed $data The associated data for the form. * * @return bool */ protected function handleOnContentPrepareForm(JForm $form, $data) { return true; } /** * @param string $buffer * * @return void */ protected function loadStylesAndScripts(&$buffer) { } /** * @return void * * Consider using changeFinalHtmlOutput instead */ protected function handleOnAfterRender() { } /** * @param string &$string * @param string $area * @param string $context The context of the content being passed to the plugin. * @param mixed $article An object with a "text" property * @param int $page Optional page number. Unused. Defaults to zero. * * @return void */ public function processArticle(&$string, $area = 'article', $context = '', $article = null, $page = 0) { } /** * @param string $buffer * * @return bool */ protected function changeDocumentBuffer(&$buffer) { return false; } /** * @param string $html * * @return bool */ protected function changeFinalHtmlOutput(&$html) { return false; } /** * @param string $html * * @return void */ protected function cleanFinalHtmlOutput(&$html) { } /** * @return bool */ protected function passChecks() { if ( ! is_null($this->_pass)) { return $this->_pass; } $this->_pass = false; if ( ! $this->isFrameworkEnabled()) { return false; } if ( ! $this->passPageTypes()) { return false; } // allow in frontend? if ( ! $this->_enable_in_frontend && ! $this->_is_admin) { return false; } $params = Parameters::getInstance()->getPluginParams($this->_name); // allow in admin? if ( ! $this->_enable_in_admin && $this->_is_admin && ( ! isset($params->enable_admin) || ! $params->enable_admin)) { return false; } // disabled by url? if ($this->_can_disable_by_url && Protect::isDisabledByUrl($this->_alias)) { return false; } // disabled by component? if ($this->_disable_on_components && Protect::isRestrictedComponent(isset($params->disabled_components) ? $params->disabled_components : [], 'component')) { return false; } // restricted page? if (Protect::isRestrictedPage($this->_has_tags, $this->_protected_formats)) { return false; } if ( ! $this->extraChecks()) { return false; } $this->_pass = true; return true; } protected function passPageTypes() { if (empty($this->_page_types)) { return true; } if (in_array('*', $this->_page_types)) { return true; } if (empty(JFactory::$document)) { return true; } if (Document::isFeed()) { return in_array('feed', $this->_page_types); } if (Document::isPDF()) { return in_array('pdf', $this->_page_types); } $page_type = JFactory::getDocument()->getType(); if (in_array($page_type, $this->_page_types)) { return true; } return false; } protected function extraChecks() { $input = JFactory::getApplication()->input; // Disable on Gridbox edit form: option=com_gridbox&view=gridbox if ($input->get('option') == 'com_gridbox' && $input->get('view') == 'gridbox') { return false; } // Disable on SP PageBuilder edit form: option=com_sppagebuilder&view=form if ($input->get('option') == 'com_sppagebuilder' && $input->get('view') == 'form') { return false; } return true; } protected function init() { return; } /** * Check if the Regular Labs Library is enabled * * @return bool */ private function isFrameworkEnabled() { if ( ! defined('REGULAR_LABS_LIBRARY_ENABLED')) { $this->setIsFrameworkEnabled(); } if ( ! REGULAR_LABS_LIBRARY_ENABLED) { $this->throwError('REGULAR_LABS_LIBRARY_NOT_ENABLED'); } return REGULAR_LABS_LIBRARY_ENABLED; } /** * Set the define with whether the Regular Labs Library is enabled */ private function setIsFrameworkEnabled() { if ( ! JPluginHelper::isEnabled('system', 'regularlabs')) { $this->throwError('REGULAR_LABS_LIBRARY_NOT_ENABLED'); define('REGULAR_LABS_LIBRARY_ENABLED', false); return; } define('REGULAR_LABS_LIBRARY_ENABLED', true); } /** * Place an error in the message queue */ protected function throwError($error) { // Return if page is not an admin page or the admin login page if ( ! JFactory::getApplication()->isClient('administrator') || JFactory::getUser()->get('guest') ) { return; } // load the admin language file JFactory::getLanguage()->load('plg_' . $this->_type . '_' . $this->_name, JPATH_PLUGINS . '/' . $this->_type . '/' . $this->_name); $text = JText::sprintf($this->_lang_prefix . '_' . $error, JText::_($this->_title)); $text = JText::_($text) . ' ' . JText::sprintf($this->_lang_prefix . '_EXTENSION_CAN_NOT_FUNCTION', JText::_($this->_title)); // Check if message is not already in queue $messagequeue = JFactory::getApplication()->getMessageQueue(); foreach ($messagequeue as $message) { if ($message['message'] == $text) { return; } } JFactory::getApplication()->enqueueMessage($text, 'error'); } } Xml.php 0000604 00000002767 15245535751 0006041 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use SimpleXMLElement; jimport('joomla.filesystem.file'); /** * Class File * @package RegularLabs\Library */ class Xml { /** * Get an object filled with data from an xml file * * @param string $url * @param string $root * * @return object */ public static function toObject($url, $root = '') { $cache_id = 'xmlToObject_' . $url . '_' . $root; if (Cache::has($cache_id)) { return Cache::get($cache_id); } if (file_exists($url)) { $xml = @new SimpleXMLElement($url, LIBXML_NONET | LIBXML_NOCDATA, 1); } else { $xml = simplexml_load_string($url, "SimpleXMLElement", LIBXML_NONET | LIBXML_NOCDATA); } if ( ! @count($xml)) { return Cache::set( $cache_id, (object) [] ); } if ($root) { if ( ! isset($xml->{$root})) { return Cache::set( $cache_id, (object) [] ); } $xml = $xml->{$root}; } $json = json_encode($xml); $xml = json_decode($json); if (is_null($xml)) { $xml = (object) []; } if ($root && isset($xml->{$root})) { $xml = $xml->{$root}; } return Cache::set( $cache_id, $xml ); } } EditorButtonHelper.php 0000604 00000004346 15245535751 0011056 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper as JHtml; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Object\CMSObject as JObject; /** * Class EditorButtonHelper * @package RegularLabs\Library */ class EditorButtonHelper { var $_name = ''; var $params = null; public function __construct($name, &$params) { $this->_name = $name; $this->params = $params; Language::load('plg_editors-xtd_' . $name); JHtml::_('jquery.framework'); Document::script('regularlabs/script.min.js'); Document::style('regularlabs/style.min.css'); } public function getButtonText() { $text_ini = strtoupper(str_replace(' ', '_', $this->params->button_text)); $text = JText::_($text_ini); if ($text == $text_ini) { $text = JText::_($this->params->button_text); } return trim($text); } public function getIcon($icon = '') { $icon = $icon ?: $this->_name; return 'reglab icon-' . $icon; } public function renderPopupButton($editor_name, $width = 0, $height = 0) { $button = new JObject; $button->modal = true; $button->class = 'btn rl_button_' . $this->_name; $button->link = $this->getPopupLink($editor_name); $button->text = $this->getButtonText(); $button->name = $this->getIcon(); $button->options = $this->getPopupOptions($width, $height); return $button; } public function getPopupLink($editor_name) { return 'index.php?rl_qp=1' . '&folder=plugins.editors-xtd.' . $this->_name . '&file=popup.php' . '&name=' . $editor_name; } public function getPopupOptions($width = 0, $height = 0) { $width = $width ?: 1600; $height = $height ?: 1200; $width = 'Math.min(window.getSize().x-100, ' . $width . ')'; $height = 'Math.min(window.getSize().y-100, ' . $height . ')'; return '{' . 'handler: \'iframe\',' . 'size: {' . 'x:' . $width . ',' . 'y:' . $height . '}' . '}'; } } PluginTag.php 0000604 00000043744 15245535751 0007173 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * Class PluginTag * @package RegularLabs\Library */ class PluginTag { /** * @var array */ static $protected_characters = [ '=' => '[[:EQUAL:]]', '"' => '[[:QUOTE:]]', ',' => '[[:COMMA:]]', '|' => '[[:BAR:]]', ':' => '[[:COLON:]]', ]; /** * Cleans the given tag word * * @param string $string * * @return string */ public static function clean($string = '') { return RegEx::replace('[^a-z0-9-_]', '', $string); } /** * Get the attributes from plugin style string * * @param string $string * @param string $main_key * @param array $known_boolean_keys * @param array $keep_escaped_chars * * @return object */ public static function getAttributesFromString($string = '', $main_key = 'title', $known_boolean_keys = [], $keep_escaped_chars = [',']) { if (empty($string)) { return (object) []; } // Replace html entity quotes to normal quotes if (strpos($string, '"') === false) { $string = str_replace('"', '"', $string); } self::protectSpecialChars($string); // replace weird whitespace $string = str_replace(chr(194) . chr(160), ' ', $string); // Replace html entity spaces between attributes to normal spaces $string = RegEx::replace('((?:^|")\s*) (\s*(?:[a-z]|$))', '\1 \2', $string); // Only one value, so return simple key/value object if (strpos($string, '|') == false && ! RegEx::match('=\s*["\']', $string)) { self::unprotectSpecialChars($string, $keep_escaped_chars); return (object) [$main_key => $string]; } // No foo="bar" syntax found, so assume old syntax if ( ! RegEx::match('=\s*["\']', $string)) { self::unprotectSpecialChars($string, $keep_escaped_chars); $attributes = self::getAttributesFromStringOld($string, [$main_key]); self::convertOldSyntax($attributes, $known_boolean_keys); return $attributes; } // Cannot find right syntax, so return simple key/value object if ( ! RegEx::matchAll('(?:^|\s)(?<key>[a-z0-9-_\:]+)\s*(?<not>\!?)=\s*(["\'])(?<value>.*?)\3', $string, $matches)) { self::unprotectSpecialChars($string, $keep_escaped_chars); return (object) [$main_key => $string]; } $tag = (object) []; foreach ($matches as $match) { $tag->{$match['key']} = self::getAttributeValueFromMatch($match, $known_boolean_keys, $keep_escaped_chars); } return $tag; } /** * Get the value from a found attribute match * * @param array $match * @param array $known_boolean_keys * @param array $keep_escaped_chars * * @return bool|int|string */ private static function getAttributeValueFromMatch($match, $known_boolean_keys = [], $keep_escaped_chars = [',']) { $value = $match['value']; self::unprotectSpecialChars($value, $keep_escaped_chars); if (is_numeric($value) && ( in_array($match['key'], $known_boolean_keys) || in_array(strtolower($match['key']), $known_boolean_keys) ) ) { $value = $value ? 'true' : 'false'; } // Convert numeric values to ints/floats if (is_numeric($value)) { $value = $value + 0; } // Convert boolean values to actual booleans if ($value === 'true' || $value === true) { return $match['not'] ? false : true; } if ($value === 'false' || $value === false) { return $match['not'] ? true : false; } return $match['not'] ? '!NOT!' . $value : $value; } /** * Replace special characters in the string with the protected versions * * @param string $string */ public static function protectSpecialChars(&$string) { $unescaped_chars = array_keys(self::$protected_characters); array_walk($unescaped_chars, function (&$char) { $char = '\\' . $char; }); // replace escaped characters with special markup $string = str_replace( $unescaped_chars, array_values(self::$protected_characters), $string ); if ( ! RegEx::matchAll( '(<.*?>|{.*?}|\[.*?\])', $string, $tags, null, PREG_PATTERN_ORDER ) ) { return; } foreach ($tags[0] as $tag) { // replace unescaped characters with special markup $protected = str_replace( ['=', '"'], [self::$protected_characters['='], self::$protected_characters['"']], $tag ); $string = str_replace($tag, $protected, $string); } } /** * Replace protected characters in the string with the original special versions * * @param string $string * @param array $keep_escaped_chars */ public static function unprotectSpecialChars(&$string, $keep_escaped_chars = []) { $unescaped_chars = array_keys(self::$protected_characters); if ( ! empty($keep_escaped_chars)) { array_walk($unescaped_chars, function (&$char, $key, $keep_escaped_chars) { if (is_array($keep_escaped_chars) && ! in_array($char, $keep_escaped_chars)) { return; } $char = '\\' . $char; }, $keep_escaped_chars); } // replace special markup with unescaped characters $string = str_replace( array_values(self::$protected_characters), $unescaped_chars, $string ); } /** * Only used for old syntaxes * * @param string $string * @param array $keys * @param string $separator * @param string $equal * @param int $limit * * @return object */ public static function getAttributesFromStringOld($string = '', $keys = ['title'], $separator = '|', $equal = '=', $limit = 0) { $temp_separator = '[[SEPARATOR]]'; $temp_equal = '[[EQUAL]]'; $tag_start = '[[TAG]]'; $tag_end = '[[/TAG]]'; // replace separators and equal signs with special markup $string = str_replace([$separator, $equal], [$temp_separator, $temp_equal], $string); // replace protected separators and equal signs back to original $string = str_replace(['\\' . $temp_separator, '\\' . $temp_equal], [$separator, $equal], $string); // protect all html tags RegEx::matchAll('</?[a-z][^>]*>', $string, $tags); if ( ! empty($tags)) { foreach ($tags as $tag) { $string = str_replace( $tag[0], $tag_start . base64_encode(str_replace([$temp_separator, $temp_equal], [$separator, $equal], $tag[0])) . $tag_end, $string ); } } // split string into array $attribs = $limit ? explode($temp_separator, $string, (int) $limit) : explode($temp_separator, $string); $attributes = (object) [ 'params' => [], ]; // loop through splits foreach ($attribs as $i => $keyval) { // spit part into key and val by equal sign $keyval = explode($temp_equal, $keyval, 2); if (isset($keyval[1])) { $keyval[1] = str_replace([$temp_separator, $temp_equal], [$separator, $equal], $keyval[1]); } // unprotect tags in key and val foreach ($keyval as $key => $value) { RegEx::matchAll(RegEx::quote($tag_start) . '(.*?)' . RegEx::quote($tag_end), $value, $tags); if (empty($tags)) { continue; } foreach ($tags as $tag) { $value = str_replace($tag[0], base64_decode($tag[1]), $value); } $keyval[trim($key)] = $value; } if (isset($keys[$i])) { $key = trim($keys[$i]); // if value is in the keys array add as defined in keys array // ignore equal sign $value = implode($equal, $keyval); if (substr($value, 0, strlen($key) + 1) == $key . '=') { $value = substr($value, strlen($key) + 1); } $attributes->{$key} = $value; unset($keys[$i]); continue; } // else add as defined in the string if (isset($keyval[1])) { $value = $keyval[1]; $value = trim($value, '"'); if ($value === 'true' || $value === true) { $value = true; } if ($value === 'false' || $value === false) { $value = false; } $attributes->{$keyval[0]} = $value; continue; } $attributes->params[] = implode($equal, $keyval); } return $attributes; } /** * Replace keys aliases with the main key names in an object * * @param object $attributes * @param array $key_aliases * @param bool $handle_plurals */ public static function replaceKeyAliases(&$attributes, $key_aliases = [], $handle_plurals = false) { foreach ($key_aliases as $key => $aliases) { if (self::replaceKeyAlias($attributes, $key, $key, $handle_plurals)) { continue; } foreach ($aliases as $alias) { if ( ! isset($attributes->{$alias})) { continue; } if (self::replaceKeyAlias($attributes, $key, $alias, $handle_plurals)) { break; } } } } /** * Replace specific key alias with the main key name in an object * * @param object $attributes * @param string $key * @param string $alias * @param bool $handle_plurals * * @return bool */ private static function replaceKeyAlias(&$attributes, $key, $alias, $handle_plurals = false) { if ($handle_plurals) { if (self::replaceKeyAlias($attributes, $key, $alias . 's')) { return true; } if (substr($alias, -1) == 's' && self::replaceKeyAlias($attributes, $key, substr($alias, 0, -1))) { return true; } } if (isset($attributes->{$key})) { return true; } if ( ! isset($attributes->{$alias})) { return false; } $attributes->{$key} = $attributes->{$alias}; unset($attributes->{$alias}); return true; } /** * Convert an object using the old param style to the new syntax * * @param object $attributes * @param array $known_boolean_keys * @param string $extra_key */ public static function convertOldSyntax(&$attributes, $known_boolean_keys = [], $extra_key = 'class') { $extra = isset($attributes->class) ? [$attributes->class] : []; foreach ($attributes->params as $i => $param) { if ( ! $param) { continue; } if (in_array($param, $known_boolean_keys)) { $attributes->{$param} = true; continue; } if (strpos($param, '=') == false) { $extra[] = $param; continue; } list($key, $val) = explode('=', $param, 2); $attributes->{$key} = $val; } $attributes->{$extra_key} = trim(implode(' ', $extra)); unset($attributes->params); } /** * Return the Regular Expressions string to match: * Different types of spaces * * @param string $modifier * * @return string */ public static function getRegexSpaces($modifier = '+') { return '(?:\s| |&\#160;)' . $modifier; } /** * Return the Regular Expressions string to match: * Plugin type tags inside others * * @return string */ public static function getRegexInsideTag($start_character = '{', $end_character = '}') { $s = RegEx::quote($start_character); $e = RegEx::quote($end_character); return '(?:[^' . $s . $e . ']*' . $s . '[^' . $e . ']*' . $e . ')*.*?'; } /** * Return the Regular Expressions string to match: * html before plugin tag * * @param string $group_id * * @return string */ public static function getRegexLeadingHtml($group_id = '') { $group = 'leading_block_element'; $html_tag_group = 'html_tag'; if ($group_id) { $group .= '_' . $group_id; $html_tag_group .= '_' . $group_id; } $block_elements = Html::getBlockElements(['div']); $block_element = '(?<' . $group . '>' . implode('|', $block_elements) . ')'; $other_html = '[^<]*(<(?<' . $html_tag_group . '>[a-z][a-z0-9_-]*)[\s>]([^<]*</(?P=' . $html_tag_group . ')>)?[^<]*)*'; // Grab starting block element tag and any html after it (that is not the same block element starting/ending tag). return '(?:' . '<' . $block_element . '(?: [^>]*)?>' . $other_html . ')?'; } /** * Return the Regular Expressions string to match: * html after plugin tag * * @param string $group_id * * @return string */ public static function getRegexTrailingHtml($group_id = '') { $group = 'leading_block_element'; if ($group_id) { $group .= '_' . $group_id; } // If the grouped name is found, then grab all content till ending html tag is found. Otherwise grab nothing. return '(?(<' . $group . '>)' . '(?:.*?</(?P=' . $group . ')>)?' . ')'; } /** * Return the Regular Expressions string to match: * Opening html tags * * @param array $block_elements * @param array $inline_elements * @param array $excluded_block_elements * * @return string */ public static function getRegexSurroundingTagsPre($block_elements = [], $inline_elements = ['span'], $excluded_block_elements = []) { $block_elements = ! empty($block_elements) ? $block_elements : Html::getBlockElements($excluded_block_elements); $regex = '(?:<(?:' . implode('|', $block_elements) . ')(?: [^>]*)?>\s*(?:<br ?/?>\s*)*)?'; if ( ! empty($inline_elements)) { $regex .= '(?:<(?:' . implode('|', $inline_elements) . ')(?: [^>]*)?>\s*(?:<br ?/?>\s*)*){0,3}'; } return $regex; } /** * Return the Regular Expressions string to match: * Closing html tags * * @param array $block_elements * @param array $inline_elements * @param array $excluded_block_elements * * @return string */ public static function getRegexSurroundingTagsPost($block_elements = [], $inline_elements = ['span'], $excluded_block_elements = []) { $block_elements = ! empty($block_elements) ? $block_elements : Html::getBlockElements($excluded_block_elements); $regex = ''; if ( ! empty($inline_elements)) { $regex .= '(?:(?:\s*<br ?/?>)*\s*<\/(?:' . implode('|', $inline_elements) . ')>){0,3}'; } $regex .= '(?:(?:\s*<br ?/?>)*\s*<\/(?:' . implode('|', $block_elements) . ')>)?'; return $regex; } /** * Return the Regular Expressions string to match: * Leading html tag * * @param array $elements * * @return string */ public static function getRegexSurroundingTagPre($elements = []) { $elements = ! empty($elements) ? $elements : array_merge(Html::getBlockElements(), ['span']); return '(?:<(?:' . implode('|', $elements) . ')(?: [^>]*)?>\s*(?:<br ?/?>\s*)*)?'; } /** * Return the Regular Expressions string to match: * Trailing html tag * * @param array $elements * * @return string */ public static function getRegexSurroundingTagPost($elements = []) { $elements = ! empty($elements) ? $elements : array_merge(Html::getBlockElements(), ['span']); return '(?:(?:\s*<br ?/?>)*\s*<\/(?:' . implode('|', $elements) . ')>)?'; } /** * Return the Regular Expressions string to match: * Plugin style tags * * @param array $tags * @param bool $include_no_attributes * @param bool $include_ending * @param array $required_attributes * * @return string */ public static function getRegexTags($tags, $include_no_attributes = true, $include_ending = true, $required_attributes = []) { $tags = ArrayHelper::toArray($tags); $tags = count($tags) > 1 ? '(?:' . implode('|', $tags) . ')' : $tags[0]; $value = '(?:\s*=\s*(?:"[^"]*"|\'[^\']*\'|[a-z0-9-_]+))?'; $attributes = '(?:\s+[a-z0-9-_]+' . $value . ')+'; $required_attributes = ArrayHelper::toArray($required_attributes); if ( ! empty($required_attributes)) { $attributes = '(?:' . $attributes . ')?' . '(?:\s+' . implode('|', $required_attributes) . ')' . $value . '(?:' . $attributes . ')?'; } if ($include_no_attributes) { $attributes = '\s*(?:' . $attributes . ')?'; } if ( ! $include_ending) { return '<' . $tags . $attributes . '\s*/?>'; } return '<(?:\/' . $tags . '|' . $tags . $attributes . '\s*/?)\s*/?>'; } /** * Extract the plugin style div tags with the possible attributes. like: * {div width:100|float:left}...{/div} * * @param string $start_tag * @param string $end_tag * @param string $tag_start * @param string $tag_end * * @return array */ public static function getDivTags($start_tag = '', $end_tag = '', $tag_start = '{', $tag_end = '}') { $tag_start = RegEx::quote($tag_start); $tag_end = RegEx::quote($tag_end); $start_div = ['pre' => '', 'tag' => '', 'post' => '']; $end_div = ['pre' => '', 'tag' => '', 'post' => '']; if ( ! empty($start_tag) && RegEx::match( '^(?<pre>.*?)(?<tag>' . $tag_start . 'div(?: .*?)?' . $tag_end . ')(?<post>.*)$', $start_tag, $match ) ) { $start_div = $match; } if ( ! empty($end_tag) && RegEx::match( '^(?<pre>.*?)(?<tag>' . $tag_start . '/div' . $tag_end . ')(?<post>.*)$', $end_tag, $match ) ) { $end_div = $match; } if (empty($start_div['tag']) || empty($end_div['tag'])) { return [$start_div, $end_div]; } $attribs = trim(RegEx::replace($tag_start . 'div(.*)' . $tag_end, '\1', $start_div['tag'])); $start_div['tag'] = '<div>'; $end_div['tag'] = '</div>'; if (empty($attribs)) { return [$start_div, $end_div]; } $attribs = self::getDivAttributes($attribs); $style = []; if (isset($attribs->width)) { if (is_numeric($attribs->width)) { $attribs->width .= 'px'; } $style[] = 'width:' . $attribs->width; } if (isset($attribs->height)) { if (is_numeric($attribs->height)) { $attribs->height .= 'px'; } $style[] = 'height:' . $attribs->height; } if (isset($attribs->align)) { $style[] = 'float:' . $attribs->align; } if ( ! isset($attribs->align) && isset($attribs->float)) { $style[] = 'float:' . $attribs->float; } $attribs = isset($attribs->class) ? 'class="' . $attribs->class . '"' : ''; if ( ! empty($style)) { $attribs .= ' style="' . implode(';', $style) . ';"'; } $start_div['tag'] = trim('<div ' . trim($attribs)) . '>'; return [$start_div, $end_div]; } /** * Get the attributes from a plugin style div tag * * @param string $string * * @return object */ private static function getDivAttributes($string) { if (strpos($string, '="') !== false) { return self::getAttributesFromString($string); } $parts = explode('|', $string); $attributes = (object) []; foreach ($parts as $e) { if (strpos($e, ':') === false) { continue; } list($key, $val) = explode(':', $e, 2); $attributes->{$key} = $val; } return $attributes; } } ShowOn.php 0000604 00000002501 15245535751 0006500 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; use Joomla\CMS\Form\FormHelper as JFormHelper; use RegularLabs\Library\Document as RL_Document; defined('_JEXEC') or die; /** * Class ShowOn * @package RegularLabs\Library */ class ShowOn { public static function open($condition = '', $formControl = '', $group = '', $class = '') { if ( ! $condition) { return self::close(); } RL_Document::loadFormDependencies(); $json = json_encode(JFormHelper::parseShowOnConditions($condition, $formControl, $group)); $class = $class ? ' class="' . $class . '"' : ''; return '<div data-showon=\'' . $json . '\' style="display: none;"' . $class . '>'; } public static function close() { return '</div>'; } public static function show($string = '', $condition = '', $formControl = '', $group = '', $animate = true, $class = '') { if ( ! $condition || ! $string) { return $string; } return self::open($condition, $formControl, $group, $animate, $class) . $string . self::close(); } } MobileDetect.php 0000604 00000226420 15245535751 0007633 0 ustar 00 <?php /** * Mobile Detect Library * Motto: "Every business should have a mobile detection script to detect mobile readers" * * Mobile_Detect is a lightweight PHP class for detecting mobile devices (including tablets). * It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment. * * Homepage: http://mobiledetect.net * GitHub: https://github.com/serbanghita/Mobile-Detect * README: https://github.com/serbanghita/Mobile-Detect/blob/master/README.md * CONTRIBUTING: https://github.com/serbanghita/Mobile-Detect/blob/master/docs/CONTRIBUTING.md * KNOWN LIMITATIONS: https://github.com/serbanghita/Mobile-Detect/blob/master/docs/KNOWN_LIMITATIONS.md * EXAMPLES: https://github.com/serbanghita/Mobile-Detect/wiki/Code-examples * * @license https://github.com/serbanghita/Mobile-Detect/blob/master/LICENSE.txt MIT License * @author Serban Ghita <serbanghita@gmail.com> * @author Nick Ilyin <nick.ilyin@gmail.com> * Original author: Victor Stanciu <vic.stanciu@gmail.com> * * @version 2.8.37 */ namespace RegularLabs\Library; defined('_JEXEC') or die; use BadMethodCallException; class MobileDetect { /** * Mobile detection type. * * @deprecated since version 2.6.9 */ const DETECTION_TYPE_MOBILE = 'mobile'; /** * Extended detection type. * * @deprecated since version 2.6.9 */ const DETECTION_TYPE_EXTENDED = 'extended'; /** * A frequently used regular expression to extract version #s. * * @deprecated since version 2.6.9 */ const VER = '([\w._\+]+)'; /** * Top-level device. */ const MOBILE_GRADE_A = 'A'; /** * Mid-level device. */ const MOBILE_GRADE_B = 'B'; /** * Low-level device. */ const MOBILE_GRADE_C = 'C'; /** * Stores the version number of the current release. */ const VERSION = '2.8.37'; /** * A type for the version() method indicating a string return value. */ const VERSION_TYPE_STRING = 'text'; /** * A type for the version() method indicating a float return value. */ const VERSION_TYPE_FLOAT = 'float'; /** * A cache for resolved matches * @var array */ protected $cache = []; /** * The User-Agent HTTP header is stored in here. * @var string */ protected $userAgent = null; /** * HTTP headers in the PHP-flavor. So HTTP_USER_AGENT and SERVER_SOFTWARE. * @var array */ protected $httpHeaders = []; /** * CloudFront headers. E.g. CloudFront-Is-Desktop-Viewer, CloudFront-Is-Mobile-Viewer & CloudFront-Is-Tablet-Viewer. * @var array */ protected $cloudfrontHeaders = []; /** * The matching Regex. * This is good for debug. * @var string */ protected $matchingRegex = null; /** * The matches extracted from the regex expression. * This is good for debug. * * @var string */ protected $matchesArray = null; /** * The detection type, using self::DETECTION_TYPE_MOBILE or self::DETECTION_TYPE_EXTENDED. * * @deprecated since version 2.6.9 * * @var string */ protected $detectionType = self::DETECTION_TYPE_MOBILE; /** * HTTP headers that trigger the 'isMobile' detection * to be true. * * @var array */ protected static $mobileHeaders = [ 'HTTP_ACCEPT' => [ 'matches' => [ // Opera Mini; @reference: http://dev.opera.com/articles/view/opera-binary-markup-language/ 'application/x-obml2d', // BlackBerry devices. 'application/vnd.rim.html', 'text/vnd.wap.wml', 'application/vnd.wap.xhtml+xml', ], ], 'HTTP_X_WAP_PROFILE' => null, 'HTTP_X_WAP_CLIENTID' => null, 'HTTP_WAP_CONNECTION' => null, 'HTTP_PROFILE' => null, // Reported by Opera on Nokia devices (eg. C3). 'HTTP_X_OPERAMINI_PHONE_UA' => null, 'HTTP_X_NOKIA_GATEWAY_ID' => null, 'HTTP_X_ORANGE_ID' => null, 'HTTP_X_VODAFONE_3GPDPCONTEXT' => null, 'HTTP_X_HUAWEI_USERID' => null, // Reported by Windows Smartphones. 'HTTP_UA_OS' => null, // Reported by Verizon, Vodafone proxy system. 'HTTP_X_MOBILE_GATEWAY' => null, // Seen this on HTC Sensation. SensationXE_Beats_Z715e. 'HTTP_X_ATT_DEVICEID' => null, // Seen this on a HTC. 'HTTP_UA_CPU' => ['matches' => ['ARM']], ]; /** * List of mobile devices (phones). * * @var array */ protected static $phoneDevices = [ 'iPhone' => '\biPhone\b|\biPod\b', // |\biTunes 'BlackBerry' => 'BlackBerry|\bBB10\b|rim[0-9]+|\b(BBA100|BBB100|BBD100|BBE100|BBF100|STH100)\b-[0-9]+', 'Pixel' => '; \bPixel\b', 'HTC' => 'HTC|HTC.*(Sensation|Evo|Vision|Explorer|6800|8100|8900|A7272|S510e|C110e|Legend|Desire|T8282)|APX515CKT|Qtek9090|APA9292KT|HD_mini|Sensation.*Z710e|PG86100|Z715e|Desire.*(A8181|HD)|ADR6200|ADR6400L|ADR6425|001HT|Inspire 4G|Android.*\bEVO\b|T-Mobile G1|Z520m|Android [0-9.]+; Pixel', 'Nexus' => 'Nexus One|Nexus S|Galaxy.*Nexus|Android.*Nexus.*Mobile|Nexus 4|Nexus 5|Nexus 5X|Nexus 6', // @todo: Is 'Dell Streak' a tablet or a phone? ;) 'Dell' => 'Dell[;]? (Streak|Aero|Venue|Venue Pro|Flash|Smoke|Mini 3iX)|XCD28|XCD35|\b001DL\b|\b101DL\b|\bGS01\b', 'Motorola' => 'Motorola|DROIDX|DROID BIONIC|\bDroid\b.*Build|Android.*Xoom|HRI39|MOT-|A1260|A1680|A555|A853|A855|A953|A955|A956|Motorola.*ELECTRIFY|Motorola.*i1|i867|i940|MB200|MB300|MB501|MB502|MB508|MB511|MB520|MB525|MB526|MB611|MB612|MB632|MB810|MB855|MB860|MB861|MB865|MB870|ME501|ME502|ME511|ME525|ME600|ME632|ME722|ME811|ME860|ME863|ME865|MT620|MT710|MT716|MT720|MT810|MT870|MT917|Motorola.*TITANIUM|WX435|WX445|XT300|XT301|XT311|XT316|XT317|XT319|XT320|XT390|XT502|XT530|XT531|XT532|XT535|XT603|XT610|XT611|XT615|XT681|XT701|XT702|XT711|XT720|XT800|XT806|XT860|XT862|XT875|XT882|XT883|XT894|XT901|XT907|XT909|XT910|XT912|XT928|XT926|XT915|XT919|XT925|XT1021|\bMoto E\b|XT1068|XT1092|XT1052', 'Samsung' => '\bSamsung\b|SM-G950F|SM-G955F|SM-G9250|GT-19300|SGH-I337|BGT-S5230|GT-B2100|GT-B2700|GT-B2710|GT-B3210|GT-B3310|GT-B3410|GT-B3730|GT-B3740|GT-B5510|GT-B5512|GT-B5722|GT-B6520|GT-B7300|GT-B7320|GT-B7330|GT-B7350|GT-B7510|GT-B7722|GT-B7800|GT-C3010|GT-C3011|GT-C3060|GT-C3200|GT-C3212|GT-C3212I|GT-C3262|GT-C3222|GT-C3300|GT-C3300K|GT-C3303|GT-C3303K|GT-C3310|GT-C3322|GT-C3330|GT-C3350|GT-C3500|GT-C3510|GT-C3530|GT-C3630|GT-C3780|GT-C5010|GT-C5212|GT-C6620|GT-C6625|GT-C6712|GT-E1050|GT-E1070|GT-E1075|GT-E1080|GT-E1081|GT-E1085|GT-E1087|GT-E1100|GT-E1107|GT-E1110|GT-E1120|GT-E1125|GT-E1130|GT-E1160|GT-E1170|GT-E1175|GT-E1180|GT-E1182|GT-E1200|GT-E1210|GT-E1225|GT-E1230|GT-E1390|GT-E2100|GT-E2120|GT-E2121|GT-E2152|GT-E2220|GT-E2222|GT-E2230|GT-E2232|GT-E2250|GT-E2370|GT-E2550|GT-E2652|GT-E3210|GT-E3213|GT-I5500|GT-I5503|GT-I5700|GT-I5800|GT-I5801|GT-I6410|GT-I6420|GT-I7110|GT-I7410|GT-I7500|GT-I8000|GT-I8150|GT-I8160|GT-I8190|GT-I8320|GT-I8330|GT-I8350|GT-I8530|GT-I8700|GT-I8703|GT-I8910|GT-I9000|GT-I9001|GT-I9003|GT-I9010|GT-I9020|GT-I9023|GT-I9070|GT-I9082|GT-I9100|GT-I9103|GT-I9220|GT-I9250|GT-I9300|GT-I9305|GT-I9500|GT-I9505|GT-M3510|GT-M5650|GT-M7500|GT-M7600|GT-M7603|GT-M8800|GT-M8910|GT-N7000|GT-S3110|GT-S3310|GT-S3350|GT-S3353|GT-S3370|GT-S3650|GT-S3653|GT-S3770|GT-S3850|GT-S5210|GT-S5220|GT-S5229|GT-S5230|GT-S5233|GT-S5250|GT-S5253|GT-S5260|GT-S5263|GT-S5270|GT-S5300|GT-S5330|GT-S5350|GT-S5360|GT-S5363|GT-S5369|GT-S5380|GT-S5380D|GT-S5560|GT-S5570|GT-S5600|GT-S5603|GT-S5610|GT-S5620|GT-S5660|GT-S5670|GT-S5690|GT-S5750|GT-S5780|GT-S5830|GT-S5839|GT-S6102|GT-S6500|GT-S7070|GT-S7200|GT-S7220|GT-S7230|GT-S7233|GT-S7250|GT-S7500|GT-S7530|GT-S7550|GT-S7562|GT-S7710|GT-S8000|GT-S8003|GT-S8500|GT-S8530|GT-S8600|SCH-A310|SCH-A530|SCH-A570|SCH-A610|SCH-A630|SCH-A650|SCH-A790|SCH-A795|SCH-A850|SCH-A870|SCH-A890|SCH-A930|SCH-A950|SCH-A970|SCH-A990|SCH-I100|SCH-I110|SCH-I400|SCH-I405|SCH-I500|SCH-I510|SCH-I515|SCH-I600|SCH-I730|SCH-I760|SCH-I770|SCH-I830|SCH-I910|SCH-I920|SCH-I959|SCH-LC11|SCH-N150|SCH-N300|SCH-R100|SCH-R300|SCH-R351|SCH-R400|SCH-R410|SCH-T300|SCH-U310|SCH-U320|SCH-U350|SCH-U360|SCH-U365|SCH-U370|SCH-U380|SCH-U410|SCH-U430|SCH-U450|SCH-U460|SCH-U470|SCH-U490|SCH-U540|SCH-U550|SCH-U620|SCH-U640|SCH-U650|SCH-U660|SCH-U700|SCH-U740|SCH-U750|SCH-U810|SCH-U820|SCH-U900|SCH-U940|SCH-U960|SCS-26UC|SGH-A107|SGH-A117|SGH-A127|SGH-A137|SGH-A157|SGH-A167|SGH-A177|SGH-A187|SGH-A197|SGH-A227|SGH-A237|SGH-A257|SGH-A437|SGH-A517|SGH-A597|SGH-A637|SGH-A657|SGH-A667|SGH-A687|SGH-A697|SGH-A707|SGH-A717|SGH-A727|SGH-A737|SGH-A747|SGH-A767|SGH-A777|SGH-A797|SGH-A817|SGH-A827|SGH-A837|SGH-A847|SGH-A867|SGH-A877|SGH-A887|SGH-A897|SGH-A927|SGH-B100|SGH-B130|SGH-B200|SGH-B220|SGH-C100|SGH-C110|SGH-C120|SGH-C130|SGH-C140|SGH-C160|SGH-C170|SGH-C180|SGH-C200|SGH-C207|SGH-C210|SGH-C225|SGH-C230|SGH-C417|SGH-C450|SGH-D307|SGH-D347|SGH-D357|SGH-D407|SGH-D415|SGH-D780|SGH-D807|SGH-D980|SGH-E105|SGH-E200|SGH-E315|SGH-E316|SGH-E317|SGH-E335|SGH-E590|SGH-E635|SGH-E715|SGH-E890|SGH-F300|SGH-F480|SGH-I200|SGH-I300|SGH-I320|SGH-I550|SGH-I577|SGH-I600|SGH-I607|SGH-I617|SGH-I627|SGH-I637|SGH-I677|SGH-I700|SGH-I717|SGH-I727|SGH-i747M|SGH-I777|SGH-I780|SGH-I827|SGH-I847|SGH-I857|SGH-I896|SGH-I897|SGH-I900|SGH-I907|SGH-I917|SGH-I927|SGH-I937|SGH-I997|SGH-J150|SGH-J200|SGH-L170|SGH-L700|SGH-M110|SGH-M150|SGH-M200|SGH-N105|SGH-N500|SGH-N600|SGH-N620|SGH-N625|SGH-N700|SGH-N710|SGH-P107|SGH-P207|SGH-P300|SGH-P310|SGH-P520|SGH-P735|SGH-P777|SGH-Q105|SGH-R210|SGH-R220|SGH-R225|SGH-S105|SGH-S307|SGH-T109|SGH-T119|SGH-T139|SGH-T209|SGH-T219|SGH-T229|SGH-T239|SGH-T249|SGH-T259|SGH-T309|SGH-T319|SGH-T329|SGH-T339|SGH-T349|SGH-T359|SGH-T369|SGH-T379|SGH-T409|SGH-T429|SGH-T439|SGH-T459|SGH-T469|SGH-T479|SGH-T499|SGH-T509|SGH-T519|SGH-T539|SGH-T559|SGH-T589|SGH-T609|SGH-T619|SGH-T629|SGH-T639|SGH-T659|SGH-T669|SGH-T679|SGH-T709|SGH-T719|SGH-T729|SGH-T739|SGH-T746|SGH-T749|SGH-T759|SGH-T769|SGH-T809|SGH-T819|SGH-T839|SGH-T919|SGH-T929|SGH-T939|SGH-T959|SGH-T989|SGH-U100|SGH-U200|SGH-U800|SGH-V205|SGH-V206|SGH-X100|SGH-X105|SGH-X120|SGH-X140|SGH-X426|SGH-X427|SGH-X475|SGH-X495|SGH-X497|SGH-X507|SGH-X600|SGH-X610|SGH-X620|SGH-X630|SGH-X700|SGH-X820|SGH-X890|SGH-Z130|SGH-Z150|SGH-Z170|SGH-ZX10|SGH-ZX20|SHW-M110|SPH-A120|SPH-A400|SPH-A420|SPH-A460|SPH-A500|SPH-A560|SPH-A600|SPH-A620|SPH-A660|SPH-A700|SPH-A740|SPH-A760|SPH-A790|SPH-A800|SPH-A820|SPH-A840|SPH-A880|SPH-A900|SPH-A940|SPH-A960|SPH-D600|SPH-D700|SPH-D710|SPH-D720|SPH-I300|SPH-I325|SPH-I330|SPH-I350|SPH-I500|SPH-I600|SPH-I700|SPH-L700|SPH-M100|SPH-M220|SPH-M240|SPH-M300|SPH-M305|SPH-M320|SPH-M330|SPH-M350|SPH-M360|SPH-M370|SPH-M380|SPH-M510|SPH-M540|SPH-M550|SPH-M560|SPH-M570|SPH-M580|SPH-M610|SPH-M620|SPH-M630|SPH-M800|SPH-M810|SPH-M850|SPH-M900|SPH-M910|SPH-M920|SPH-M930|SPH-N100|SPH-N200|SPH-N240|SPH-N300|SPH-N400|SPH-Z400|SWC-E100|SCH-i909|GT-N7100|GT-N7105|SCH-I535|SM-N900A|SGH-I317|SGH-T999L|GT-S5360B|GT-I8262|GT-S6802|GT-S6312|GT-S6310|GT-S5312|GT-S5310|GT-I9105|GT-I8510|GT-S6790N|SM-G7105|SM-N9005|GT-S5301|GT-I9295|GT-I9195|SM-C101|GT-S7392|GT-S7560|GT-B7610|GT-I5510|GT-S7582|GT-S7530E|GT-I8750|SM-G9006V|SM-G9008V|SM-G9009D|SM-G900A|SM-G900D|SM-G900F|SM-G900H|SM-G900I|SM-G900J|SM-G900K|SM-G900L|SM-G900M|SM-G900P|SM-G900R4|SM-G900S|SM-G900T|SM-G900V|SM-G900W8|SHV-E160K|SCH-P709|SCH-P729|SM-T2558|GT-I9205|SM-G9350|SM-J120F|SM-G920F|SM-G920V|SM-G930F|SM-N910C|SM-A310F|GT-I9190|SM-J500FN|SM-G903F|SM-J330F|SM-G610F|SM-G981B|SM-G892A|SM-A530F', 'LG' => '\bLG\b;|LG[- ]?(C800|C900|E400|E610|E900|E-900|F160|F180K|F180L|F180S|730|855|L160|LS740|LS840|LS970|LU6200|MS690|MS695|MS770|MS840|MS870|MS910|P500|P700|P705|VM696|AS680|AS695|AX840|C729|E970|GS505|272|C395|E739BK|E960|L55C|L75C|LS696|LS860|P769BK|P350|P500|P509|P870|UN272|US730|VS840|VS950|LN272|LN510|LS670|LS855|LW690|MN270|MN510|P509|P769|P930|UN200|UN270|UN510|UN610|US670|US740|US760|UX265|UX840|VN271|VN530|VS660|VS700|VS740|VS750|VS910|VS920|VS930|VX9200|VX11000|AX840A|LW770|P506|P925|P999|E612|D955|D802|MS323|M257)|LM-G710', 'Sony' => 'SonyST|SonyLT|SonyEricsson|SonyEricssonLT15iv|LT18i|E10i|LT28h|LT26w|SonyEricssonMT27i|C5303|C6902|C6903|C6906|C6943|D2533|SOV34|601SO|F8332', 'Asus' => 'Asus.*Galaxy|PadFone.*Mobile', 'Xiaomi' => '^(?!.*\bx11\b).*xiaomi.*$|POCOPHONE F1|MI 8|Redmi Note 9S|Redmi Note 5A Prime|N2G47H|M2001J2G|M2001J2I|M1805E10A|M2004J11G|M1902F1G|M2002J9G|M2004J19G|M2003J6A1G', 'NokiaLumia' => 'Lumia [0-9]{3,4}', // http://www.micromaxinfo.com/mobiles/smartphones // Added because the codes might conflict with Acer Tablets. 'Micromax' => 'Micromax.*\b(A210|A92|A88|A72|A111|A110Q|A115|A116|A110|A90S|A26|A51|A35|A54|A25|A27|A89|A68|A65|A57|A90)\b', // @todo Complete the regex. 'Palm' => 'PalmSource|Palm', // avantgo|blazer|elaine|hiptop|plucker|xiino ; 'Vertu' => 'Vertu|Vertu.*Ltd|Vertu.*Ascent|Vertu.*Ayxta|Vertu.*Constellation(F|Quest)?|Vertu.*Monika|Vertu.*Signature', // Just for fun ;) // http://www.pantech.co.kr/en/prod/prodList.do?gbrand=VEGA (PANTECH) // Most of the VEGA devices are legacy. PANTECH seem to be newer devices based on Android. 'Pantech' => 'PANTECH|IM-A850S|IM-A840S|IM-A830L|IM-A830K|IM-A830S|IM-A820L|IM-A810K|IM-A810S|IM-A800S|IM-T100K|IM-A725L|IM-A780L|IM-A775C|IM-A770K|IM-A760S|IM-A750K|IM-A740S|IM-A730S|IM-A720L|IM-A710K|IM-A690L|IM-A690S|IM-A650S|IM-A630K|IM-A600S|VEGA PTL21|PT003|P8010|ADR910L|P6030|P6020|P9070|P4100|P9060|P5000|CDM8992|TXT8045|ADR8995|IS11PT|P2030|P6010|P8000|PT002|IS06|CDM8999|P9050|PT001|TXT8040|P2020|P9020|P2000|P7040|P7000|C790', // http://www.fly-phone.com/devices/smartphones/ ; Included only smartphones. 'Fly' => 'IQ230|IQ444|IQ450|IQ440|IQ442|IQ441|IQ245|IQ256|IQ236|IQ255|IQ235|IQ245|IQ275|IQ240|IQ285|IQ280|IQ270|IQ260|IQ250', // http://fr.wikomobile.com 'Wiko' => 'KITE 4G|HIGHWAY|GETAWAY|STAIRWAY|DARKSIDE|DARKFULL|DARKNIGHT|DARKMOON|SLIDE|WAX 4G|RAINBOW|BLOOM|SUNSET|GOA(?!nna)|LENNY|BARRY|IGGY|OZZY|CINK FIVE|CINK PEAX|CINK PEAX 2|CINK SLIM|CINK SLIM 2|CINK +|CINK KING|CINK PEAX|CINK SLIM|SUBLIM', 'iMobile' => 'i-mobile (IQ|i-STYLE|idea|ZAA|Hitz)', // Added simvalley mobile just for fun. They have some interesting devices. // http://www.simvalley.fr/telephonie---gps-_22_telephonie-mobile_telephones_.html 'SimValley' => '\b(SP-80|XT-930|SX-340|XT-930|SX-310|SP-360|SP60|SPT-800|SP-120|SPT-800|SP-140|SPX-5|SPX-8|SP-100|SPX-8|SPX-12)\b', // Wolfgang - a brand that is sold by Aldi supermarkets. // http://www.wolfgangmobile.com/ 'Wolfgang' => 'AT-B24D|AT-AS50HD|AT-AS40W|AT-AS55HD|AT-AS45q2|AT-B26D|AT-AS50Q', 'Alcatel' => 'Alcatel', 'Nintendo' => 'Nintendo (3DS|Switch)', // http://en.wikipedia.org/wiki/Amoi 'Amoi' => 'Amoi', // http://en.wikipedia.org/wiki/INQ 'INQ' => 'INQ', 'OnePlus' => 'ONEPLUS', // @Tapatalk is a mobile app; http://support.tapatalk.com/threads/smf-2-0-2-os-and-browser-detection-plugin-and-tapatalk.15565/#post-79039 'GenericPhone' => 'Tapatalk|PDA;|SAGEM|\bmmp\b|pocket|\bpsp\b|symbian|Smartphone|smartfon|treo|up.browser|up.link|vodafone|\bwap\b|nokia|Series40|Series60|S60|SonyEricsson|N900|MAUI.*WAP.*Browser', ]; /** * List of tablet devices. * * @var array */ protected static $tabletDevices = [ // @todo: check for mobile friendly emails topic. 'iPad' => 'iPad|iPad.*Mobile', // Removed |^.*Android.*Nexus(?!(?:Mobile).)*$ // @see #442 // @todo Merge NexusTablet into GoogleTablet. 'NexusTablet' => 'Android.*Nexus[\s]+(7|9|10)', // https://en.wikipedia.org/wiki/Pixel_C 'GoogleTablet' => 'Android.*Pixel C', 'SamsungTablet' => 'SAMSUNG.*Tablet|Galaxy.*Tab|SC-01C|GT-P1000|GT-P1003|GT-P1010|GT-P3105|GT-P6210|GT-P6800|GT-P6810|GT-P7100|GT-P7300|GT-P7310|GT-P7500|GT-P7510|SCH-I800|SCH-I815|SCH-I905|SGH-I957|SGH-I987|SGH-T849|SGH-T859|SGH-T869|SPH-P100|GT-P3100|GT-P3108|GT-P3110|GT-P5100|GT-P5110|GT-P6200|GT-P7320|GT-P7511|GT-N8000|GT-P8510|SGH-I497|SPH-P500|SGH-T779|SCH-I705|SCH-I915|GT-N8013|GT-P3113|GT-P5113|GT-P8110|GT-N8010|GT-N8005|GT-N8020|GT-P1013|GT-P6201|GT-P7501|GT-N5100|GT-N5105|GT-N5110|SHV-E140K|SHV-E140L|SHV-E140S|SHV-E150S|SHV-E230K|SHV-E230L|SHV-E230S|SHW-M180K|SHW-M180L|SHW-M180S|SHW-M180W|SHW-M300W|SHW-M305W|SHW-M380K|SHW-M380S|SHW-M380W|SHW-M430W|SHW-M480K|SHW-M480S|SHW-M480W|SHW-M485W|SHW-M486W|SHW-M500W|GT-I9228|SCH-P739|SCH-I925|GT-I9200|GT-P5200|GT-P5210|GT-P5210X|SM-T311|SM-T310|SM-T310X|SM-T210|SM-T210R|SM-T211|SM-P600|SM-P601|SM-P605|SM-P900|SM-P901|SM-T217|SM-T217A|SM-T217S|SM-P6000|SM-T3100|SGH-I467|XE500|SM-T110|GT-P5220|GT-I9200X|GT-N5110X|GT-N5120|SM-P905|SM-T111|SM-T2105|SM-T315|SM-T320|SM-T320X|SM-T321|SM-T520|SM-T525|SM-T530NU|SM-T230NU|SM-T330NU|SM-T900|XE500T1C|SM-P605V|SM-P905V|SM-T337V|SM-T537V|SM-T707V|SM-T807V|SM-P600X|SM-P900X|SM-T210X|SM-T230|SM-T230X|SM-T325|GT-P7503|SM-T531|SM-T330|SM-T530|SM-T705|SM-T705C|SM-T535|SM-T331|SM-T800|SM-T700|SM-T537|SM-T807|SM-P907A|SM-T337A|SM-T537A|SM-T707A|SM-T807A|SM-T237|SM-T807P|SM-P607T|SM-T217T|SM-T337T|SM-T807T|SM-T116NQ|SM-T116BU|SM-P550|SM-T350|SM-T550|SM-T9000|SM-P9000|SM-T705Y|SM-T805|GT-P3113|SM-T710|SM-T810|SM-T815|SM-T360|SM-T533|SM-T113|SM-T335|SM-T715|SM-T560|SM-T670|SM-T677|SM-T377|SM-T567|SM-T357T|SM-T555|SM-T561|SM-T713|SM-T719|SM-T813|SM-T819|SM-T580|SM-T355Y?|SM-T280|SM-T817A|SM-T820|SM-W700|SM-P580|SM-T587|SM-P350|SM-P555M|SM-P355M|SM-T113NU|SM-T815Y|SM-T585|SM-T285|SM-T825|SM-W708|SM-T835|SM-T830|SM-T837V|SM-T720|SM-T510|SM-T387V|SM-P610|SM-T290|SM-T515|SM-T590|SM-T595|SM-T725|SM-T817P|SM-P585N0|SM-T395|SM-T295|SM-T865|SM-P610N|SM-P615|SM-T970|SM-T380|SM-T5950|SM-T905|SM-T231|SM-T500|SM-T860', // SCH-P709|SCH-P729|SM-T2558|GT-I9205 - Samsung Mega - treat them like a regular phone. // http://docs.aws.amazon.com/silk/latest/developerguide/user-agent.html 'Kindle' => 'Kindle|Silk.*Accelerated|Android.*\b(KFOT|KFTT|KFJWI|KFJWA|KFOTE|KFSOWI|KFTHWI|KFTHWA|KFAPWI|KFAPWA|WFJWAE|KFSAWA|KFSAWI|KFASWI|KFARWI|KFFOWI|KFGIWI|KFMEWI)\b|Android.*Silk/[0-9.]+ like Chrome/[0-9.]+ (?!Mobile)', // Only the Surface tablets with Windows RT are considered mobile. // http://msdn.microsoft.com/en-us/library/ie/hh920767(v=vs.85).aspx 'SurfaceTablet' => 'Windows NT [0-9.]+; ARM;.*(Tablet|ARMBJS)', // http://shopping1.hp.com/is-bin/INTERSHOP.enfinity/WFS/WW-USSMBPublicStore-Site/en_US/-/USD/ViewStandardCatalog-Browse?CatalogCategoryID=JfIQ7EN5lqMAAAEyDcJUDwMT 'HPTablet' => 'HP Slate (7|8|10)|HP ElitePad 900|hp-tablet|EliteBook.*Touch|HP 8|Slate 21|HP SlateBook 10', // Watch out for PadFone, see #132. // http://www.asus.com/de/Tablets_Mobile/Memo_Pad_Products/ 'AsusTablet' => '^.*PadFone((?!Mobile).)*$|Transformer|TF101|TF101G|TF300T|TF300TG|TF300TL|TF700T|TF700KL|TF701T|TF810C|ME171|ME301T|ME302C|ME371MG|ME370T|ME372MG|ME172V|ME173X|ME400C|Slider SL101|\bK00F\b|\bK00C\b|\bK00E\b|\bK00L\b|TX201LA|ME176C|ME102A|\bM80TA\b|ME372CL|ME560CG|ME372CG|ME302KL| K010 | K011 | K017 | K01E |ME572C|ME103K|ME170C|ME171C|\bME70C\b|ME581C|ME581CL|ME8510C|ME181C|P01Y|PO1MA|P01Z|\bP027\b|\bP024\b|\bP00C\b', 'BlackBerryTablet' => 'PlayBook|RIM Tablet', 'HTCtablet' => 'HTC_Flyer_P512|HTC Flyer|HTC Jetstream|HTC-P715a|HTC EVO View 4G|PG41200|PG09410', 'MotorolaTablet' => 'xoom|sholest|MZ615|MZ605|MZ505|MZ601|MZ602|MZ603|MZ604|MZ606|MZ607|MZ608|MZ609|MZ615|MZ616|MZ617', 'NookTablet' => 'Android.*Nook|NookColor|nook browser|BNRV200|BNRV200A|BNTV250|BNTV250A|BNTV400|BNTV600|LogicPD Zoom2', // http://www.acer.ro/ac/ro/RO/content/drivers // http://www.packardbell.co.uk/pb/en/GB/content/download (Packard Bell is part of Acer) // http://us.acer.com/ac/en/US/content/group/tablets // http://www.acer.de/ac/de/DE/content/models/tablets/ // Can conflict with Micromax and Motorola phones codes. 'AcerTablet' => 'Android.*; \b(A100|A101|A110|A200|A210|A211|A500|A501|A510|A511|A700|A701|W500|W500P|W501|W501P|W510|W511|W700|G100|G100W|B1-A71|B1-710|B1-711|A1-810|A1-811|A1-830)\b|W3-810|\bA3-A10\b|\bA3-A11\b|\bA3-A20\b|\bA3-A30|A3-A40', // http://eu.computers.toshiba-europe.com/innovation/family/Tablets/1098744/banner_id/tablet_footerlink/ // http://us.toshiba.com/tablets/tablet-finder // http://www.toshiba.co.jp/regza/tablet/ 'ToshibaTablet' => 'Android.*(AT100|AT105|AT200|AT205|AT270|AT275|AT300|AT305|AT1S5|AT500|AT570|AT700|AT830)|TOSHIBA.*FOLIO', // http://www.nttdocomo.co.jp/english/service/developer/smart_phone/technical_info/spec/index.html // http://www.lg.com/us/tablets 'LGTablet' => '\bL-06C|LG-V909|LG-V900|LG-V700|LG-V510|LG-V500|LG-V410|LG-V400|LG-VK810\b', 'FujitsuTablet' => 'Android.*\b(F-01D|F-02F|F-05E|F-10D|M532|Q572)\b', // Prestigio Tablets http://www.prestigio.com/support 'PrestigioTablet' => 'PMP3170B|PMP3270B|PMP3470B|PMP7170B|PMP3370B|PMP3570C|PMP5870C|PMP3670B|PMP5570C|PMP5770D|PMP3970B|PMP3870C|PMP5580C|PMP5880D|PMP5780D|PMP5588C|PMP7280C|PMP7280C3G|PMP7280|PMP7880D|PMP5597D|PMP5597|PMP7100D|PER3464|PER3274|PER3574|PER3884|PER5274|PER5474|PMP5097CPRO|PMP5097|PMP7380D|PMP5297C|PMP5297C_QUAD|PMP812E|PMP812E3G|PMP812F|PMP810E|PMP880TD|PMT3017|PMT3037|PMT3047|PMT3057|PMT7008|PMT5887|PMT5001|PMT5002', // http://support.lenovo.com/en_GB/downloads/default.page?# 'LenovoTablet' => 'Lenovo TAB|Idea(Tab|Pad)( A1|A10| K1|)|ThinkPad([ ]+)?Tablet|YT3-850M|YT3-X90L|YT3-X90F|YT3-X90X|Lenovo.*(S2109|S2110|S5000|S6000|K3011|A3000|A3500|A1000|A2107|A2109|A1107|A5500|A7600|B6000|B8000|B8080)(-|)(FL|F|HV|H|)|TB-X103F|TB-X304X|TB-X304F|TB-X304L|TB-X505F|TB-X505L|TB-X505X|TB-X605F|TB-X605L|TB-8703F|TB-8703X|TB-8703N|TB-8704N|TB-8704F|TB-8704X|TB-8704V|TB-7304F|TB-7304I|TB-7304X|Tab2A7-10F|Tab2A7-20F|TB2-X30L|YT3-X50L|YT3-X50F|YT3-X50M|YT-X705F|YT-X703F|YT-X703L|YT-X705L|YT-X705X|TB2-X30F|TB2-X30L|TB2-X30M|A2107A-F|A2107A-H|TB3-730F|TB3-730M|TB3-730X|TB-7504F|TB-7504X|TB-X704F|TB-X104F|TB3-X70F|TB-X705F|TB-8504F|TB3-X70L|TB3-710F|TB-X704L', // http://www.dell.com/support/home/us/en/04/Products/tab_mob/tablets 'DellTablet' => 'Venue 11|Venue 8|Venue 7|Dell Streak 10|Dell Streak 7', // http://www.yarvik.com/en/matrix/tablets/ 'YarvikTablet' => 'Android.*\b(TAB210|TAB211|TAB224|TAB250|TAB260|TAB264|TAB310|TAB360|TAB364|TAB410|TAB411|TAB420|TAB424|TAB450|TAB460|TAB461|TAB464|TAB465|TAB467|TAB468|TAB07-100|TAB07-101|TAB07-150|TAB07-151|TAB07-152|TAB07-200|TAB07-201-3G|TAB07-210|TAB07-211|TAB07-212|TAB07-214|TAB07-220|TAB07-400|TAB07-485|TAB08-150|TAB08-200|TAB08-201-3G|TAB08-201-30|TAB09-100|TAB09-211|TAB09-410|TAB10-150|TAB10-201|TAB10-211|TAB10-400|TAB10-410|TAB13-201|TAB274EUK|TAB275EUK|TAB374EUK|TAB462EUK|TAB474EUK|TAB9-200)\b', 'MedionTablet' => 'Android.*\bOYO\b|LIFE.*(P9212|P9514|P9516|S9512)|LIFETAB', 'ArnovaTablet' => '97G4|AN10G2|AN7bG3|AN7fG3|AN8G3|AN8cG3|AN7G3|AN9G3|AN7dG3|AN7dG3ST|AN7dG3ChildPad|AN10bG3|AN10bG3DT|AN9G2', // http://www.intenso.de/kategorie_en.php?kategorie=33 // @todo: http://www.nbhkdz.com/read/b8e64202f92a2df129126bff.html - investigate 'IntensoTablet' => 'INM8002KP|INM1010FP|INM805ND|Intenso Tab|TAB1004', // IRU.ru Tablets http://www.iru.ru/catalog/soho/planetable/ 'IRUTablet' => 'M702pro', 'MegafonTablet' => 'MegaFon V9|\bZTE V9\b|Android.*\bMT7A\b', // http://www.e-boda.ro/tablete-pc.html 'EbodaTablet' => 'E-Boda (Supreme|Impresspeed|Izzycomm|Essential)', // http://www.allview.ro/produse/droseries/lista-tablete-pc/ 'AllViewTablet' => 'Allview.*(Viva|Alldro|City|Speed|All TV|Frenzy|Quasar|Shine|TX1|AX1|AX2)', // http://wiki.archosfans.com/index.php?title=Main_Page // @note Rewrite the regex format after we add more UAs. 'ArchosTablet' => '\b(101G9|80G9|A101IT)\b|Qilive 97R|Archos5|\bARCHOS (70|79|80|90|97|101|FAMILYPAD|)(b|c|)(G10| Cobalt| TITANIUM(HD|)| Xenon| Neon|XSK| 2| XS 2| PLATINUM| CARBON|GAMEPAD)\b', // http://www.ainol.com/plugin.php?identifier=ainol&module=product 'AinolTablet' => 'NOVO7|NOVO8|NOVO10|Novo7Aurora|Novo7Basic|NOVO7PALADIN|novo9-Spark', 'NokiaLumiaTablet' => 'Lumia 2520', // @todo: inspect http://esupport.sony.com/US/p/select-system.pl?DIRECTOR=DRIVER // Readers http://www.atsuhiro-me.net/ebook/sony-reader/sony-reader-web-browser // http://www.sony.jp/support/tablet/ 'SonyTablet' => 'Sony.*Tablet|Xperia Tablet|Sony Tablet S|SO-03E|SGPT12|SGPT13|SGPT114|SGPT121|SGPT122|SGPT123|SGPT111|SGPT112|SGPT113|SGPT131|SGPT132|SGPT133|SGPT211|SGPT212|SGPT213|SGP311|SGP312|SGP321|EBRD1101|EBRD1102|EBRD1201|SGP351|SGP341|SGP511|SGP512|SGP521|SGP541|SGP551|SGP621|SGP641|SGP612|SOT31|SGP771|SGP611|SGP612|SGP712', // http://www.support.philips.com/support/catalog/worldproducts.jsp?userLanguage=en&userCountry=cn&categoryid=3G_LTE_TABLET_SU_CN_CARE&title=3G%20tablets%20/%20LTE%20range&_dyncharset=UTF-8 'PhilipsTablet' => '\b(PI2010|PI3000|PI3100|PI3105|PI3110|PI3205|PI3210|PI3900|PI4010|PI7000|PI7100)\b', // db + http://www.cube-tablet.com/buy-products.html 'CubeTablet' => 'Android.*(K8GT|U9GT|U10GT|U16GT|U17GT|U18GT|U19GT|U20GT|U23GT|U30GT)|CUBE U8GT', // http://www.cobyusa.com/?p=pcat&pcat_id=3001 'CobyTablet' => 'MID1042|MID1045|MID1125|MID1126|MID7012|MID7014|MID7015|MID7034|MID7035|MID7036|MID7042|MID7048|MID7127|MID8042|MID8048|MID8127|MID9042|MID9740|MID9742|MID7022|MID7010', // http://www.match.net.cn/products.asp 'MIDTablet' => 'M9701|M9000|M9100|M806|M1052|M806|T703|MID701|MID713|MID710|MID727|MID760|MID830|MID728|MID933|MID125|MID810|MID732|MID120|MID930|MID800|MID731|MID900|MID100|MID820|MID735|MID980|MID130|MID833|MID737|MID960|MID135|MID860|MID736|MID140|MID930|MID835|MID733|MID4X10', // http://www.msi.com/support // @todo Research the Windows Tablets. 'MSITablet' => 'MSI \b(Primo 73K|Primo 73L|Primo 81L|Primo 77|Primo 93|Primo 75|Primo 76|Primo 73|Primo 81|Primo 91|Primo 90|Enjoy 71|Enjoy 7|Enjoy 10)\b', // @todo http://www.kyoceramobile.com/support/drivers/ // 'KyoceraTablet' => null, // @todo http://intexuae.com/index.php/category/mobile-devices/tablets-products/ // 'IntextTablet' => null, // http://pdadb.net/index.php?m=pdalist&list=SMiT (NoName Chinese Tablets) // http://www.imp3.net/14/show.php?itemid=20454 'SMiTTablet' => 'Android.*(\bMID\b|MID-560|MTV-T1200|MTV-PND531|MTV-P1101|MTV-PND530)', // http://www.rock-chips.com/index.php?do=prod&pid=2 'RockChipTablet' => 'Android.*(RK2818|RK2808A|RK2918|RK3066)|RK2738|RK2808A', // http://www.fly-phone.com/devices/tablets/ ; http://www.fly-phone.com/service/ 'FlyTablet' => 'IQ310|Fly Vision', // http://www.bqreaders.com/gb/tablets-prices-sale.html 'bqTablet' => 'Android.*(bq)?.*\b(Elcano|Curie|Edison|Maxwell|Kepler|Pascal|Tesla|Hypatia|Platon|Newton|Livingstone|Cervantes|Avant|Aquaris ([E|M]10|M8))\b|Maxwell.*Lite|Maxwell.*Plus', // http://www.huaweidevice.com/worldwide/productFamily.do?method=index&directoryId=5011&treeId=3290 // http://www.huaweidevice.com/worldwide/downloadCenter.do?method=index&directoryId=3372&treeId=0&tb=1&type=software (including legacy tablets) 'HuaweiTablet' => 'MediaPad|MediaPad 7 Youth|IDEOS S7|S7-201c|S7-202u|S7-101|S7-103|S7-104|S7-105|S7-106|S7-201|S7-Slim|M2-A01L|BAH-L09|BAH-W09|AGS-L09|CMR-AL19', // Nec or Medias Tab 'NecTablet' => '\bN-06D|\bN-08D', // Pantech Tablets: http://www.pantechusa.com/phones/ 'PantechTablet' => 'Pantech.*P4100', // Broncho Tablets: http://www.broncho.cn/ (hard to find) 'BronchoTablet' => 'Broncho.*(N701|N708|N802|a710)', // http://versusuk.com/support.html 'VersusTablet' => 'TOUCHPAD.*[78910]|\bTOUCHTAB\b', // http://www.zync.in/index.php/our-products/tablet-phablets 'ZyncTablet' => 'z1000|Z99 2G|z930|z990|z909|Z919|z900', // Removed "z999" because of https://github.com/serbanghita/Mobile-Detect/issues/717 // http://www.positivoinformatica.com.br/www/pessoal/tablet-ypy/ 'PositivoTablet' => 'TB07STA|TB10STA|TB07FTA|TB10FTA', // https://www.nabitablet.com/ 'NabiTablet' => 'Android.*\bNabi', 'KoboTablet' => 'Kobo Touch|\bK080\b|\bVox\b Build|\bArc\b Build', // French Danew Tablets http://www.danew.com/produits-tablette.php 'DanewTablet' => 'DSlide.*\b(700|701R|702|703R|704|802|970|971|972|973|974|1010|1012)\b', // Texet Tablets and Readers http://www.texet.ru/tablet/ 'TexetTablet' => 'NaviPad|TB-772A|TM-7045|TM-7055|TM-9750|TM-7016|TM-7024|TM-7026|TM-7041|TM-7043|TM-7047|TM-8041|TM-9741|TM-9747|TM-9748|TM-9751|TM-7022|TM-7021|TM-7020|TM-7011|TM-7010|TM-7023|TM-7025|TM-7037W|TM-7038W|TM-7027W|TM-9720|TM-9725|TM-9737W|TM-1020|TM-9738W|TM-9740|TM-9743W|TB-807A|TB-771A|TB-727A|TB-725A|TB-719A|TB-823A|TB-805A|TB-723A|TB-715A|TB-707A|TB-705A|TB-709A|TB-711A|TB-890HD|TB-880HD|TB-790HD|TB-780HD|TB-770HD|TB-721HD|TB-710HD|TB-434HD|TB-860HD|TB-840HD|TB-760HD|TB-750HD|TB-740HD|TB-730HD|TB-722HD|TB-720HD|TB-700HD|TB-500HD|TB-470HD|TB-431HD|TB-430HD|TB-506|TB-504|TB-446|TB-436|TB-416|TB-146SE|TB-126SE', // Avoid detecting 'PLAYSTATION 3' as mobile. 'PlaystationTablet' => 'Playstation.*(Portable|Vita)', // http://www.trekstor.de/surftabs.html 'TrekstorTablet' => 'ST10416-1|VT10416-1|ST70408-1|ST702xx-1|ST702xx-2|ST80208|ST97216|ST70104-2|VT10416-2|ST10216-2A|SurfTab', // http://www.pyleaudio.com/Products.aspx?%2fproducts%2fPersonal-Electronics%2fTablets 'PyleAudioTablet' => '\b(PTBL10CEU|PTBL10C|PTBL72BC|PTBL72BCEU|PTBL7CEU|PTBL7C|PTBL92BC|PTBL92BCEU|PTBL9CEU|PTBL9CUK|PTBL9C)\b', // http://www.advandigital.com/index.php?link=content-product&jns=JP001 // because of the short codenames we have to include whitespaces to reduce the possible conflicts. 'AdvanTablet' => 'Android.* \b(E3A|T3X|T5C|T5B|T3E|T3C|T3B|T1J|T1F|T2A|T1H|T1i|E1C|T1-E|T5-A|T4|E1-B|T2Ci|T1-B|T1-D|O1-A|E1-A|T1-A|T3A|T4i)\b ', // http://www.danytech.com/category/tablet-pc 'DanyTechTablet' => 'Genius Tab G3|Genius Tab S2|Genius Tab Q3|Genius Tab G4|Genius Tab Q4|Genius Tab G-II|Genius TAB GII|Genius TAB GIII|Genius Tab S1', // http://www.galapad.net/product.html ; https://github.com/serbanghita/Mobile-Detect/issues/761 'GalapadTablet' => 'Android [0-9.]+; [a-z-]+; \bG1\b', // http://www.micromaxinfo.com/tablet/funbook 'MicromaxTablet' => 'Funbook|Micromax.*\b(P250|P560|P360|P362|P600|P300|P350|P500|P275)\b', // http://www.karbonnmobiles.com/products_tablet.php 'KarbonnTablet' => 'Android.*\b(A39|A37|A34|ST8|ST10|ST7|Smart Tab3|Smart Tab2)\b', // http://www.myallfine.com/Products.asp 'AllFineTablet' => 'Fine7 Genius|Fine7 Shine|Fine7 Air|Fine8 Style|Fine9 More|Fine10 Joy|Fine11 Wide', // http://www.proscanvideo.com/products-search.asp?itemClass=TABLET&itemnmbr= 'PROSCANTablet' => '\b(PEM63|PLT1023G|PLT1041|PLT1044|PLT1044G|PLT1091|PLT4311|PLT4311PL|PLT4315|PLT7030|PLT7033|PLT7033D|PLT7035|PLT7035D|PLT7044K|PLT7045K|PLT7045KB|PLT7071KG|PLT7072|PLT7223G|PLT7225G|PLT7777G|PLT7810K|PLT7849G|PLT7851G|PLT7852G|PLT8015|PLT8031|PLT8034|PLT8036|PLT8080K|PLT8082|PLT8088|PLT8223G|PLT8234G|PLT8235G|PLT8816K|PLT9011|PLT9045K|PLT9233G|PLT9735|PLT9760G|PLT9770G)\b', // http://www.yonesnav.com/products/products.php 'YONESTablet' => 'BQ1078|BC1003|BC1077|RK9702|BC9730|BC9001|IT9001|BC7008|BC7010|BC708|BC728|BC7012|BC7030|BC7027|BC7026', // http://www.cjshowroom.com/eproducts.aspx?classcode=004001001 // China manufacturer makes tablets for different small brands (eg. http://www.zeepad.net/index.html) 'ChangJiaTablet' => 'TPC7102|TPC7103|TPC7105|TPC7106|TPC7107|TPC7201|TPC7203|TPC7205|TPC7210|TPC7708|TPC7709|TPC7712|TPC7110|TPC8101|TPC8103|TPC8105|TPC8106|TPC8203|TPC8205|TPC8503|TPC9106|TPC9701|TPC97101|TPC97103|TPC97105|TPC97106|TPC97111|TPC97113|TPC97203|TPC97603|TPC97809|TPC97205|TPC10101|TPC10103|TPC10106|TPC10111|TPC10203|TPC10205|TPC10503', // http://www.gloryunion.cn/products.asp // http://www.allwinnertech.com/en/apply/mobile.html // http://www.ptcl.com.pk/pd_content.php?pd_id=284 (EVOTAB) // @todo: Softwiner tablets? // aka. Cute or Cool tablets. Not sure yet, must research to avoid collisions. 'GUTablet' => 'TX-A1301|TX-M9002|Q702|kf026', // A12R|D75A|D77|D79|R83|A95|A106C|R15|A75|A76|D71|D72|R71|R73|R77|D82|R85|D92|A97|D92|R91|A10F|A77F|W71F|A78F|W78F|W81F|A97F|W91F|W97F|R16G|C72|C73E|K72|K73|R96G // http://www.pointofview-online.com/showroom.php?shop_mode=product_listing&category_id=118 'PointOfViewTablet' => 'TAB-P506|TAB-navi-7-3G-M|TAB-P517|TAB-P-527|TAB-P701|TAB-P703|TAB-P721|TAB-P731N|TAB-P741|TAB-P825|TAB-P905|TAB-P925|TAB-PR945|TAB-PL1015|TAB-P1025|TAB-PI1045|TAB-P1325|TAB-PROTAB[0-9]+|TAB-PROTAB25|TAB-PROTAB26|TAB-PROTAB27|TAB-PROTAB26XL|TAB-PROTAB2-IPS9|TAB-PROTAB30-IPS9|TAB-PROTAB25XXL|TAB-PROTAB26-IPS10|TAB-PROTAB30-IPS10', // http://www.overmax.pl/pl/katalog-produktow,p8/tablety,c14/ // @todo: add more tests. 'OvermaxTablet' => 'OV-(SteelCore|NewBase|Basecore|Baseone|Exellen|Quattor|EduTab|Solution|ACTION|BasicTab|TeddyTab|MagicTab|Stream|TB-08|TB-09)|Qualcore 1027', // http://hclmetablet.com/India/index.php 'HCLTablet' => 'HCL.*Tablet|Connect-3G-2.0|Connect-2G-2.0|ME Tablet U1|ME Tablet U2|ME Tablet G1|ME Tablet X1|ME Tablet Y2|ME Tablet Sync', // http://www.edigital.hu/Tablet_es_e-book_olvaso/Tablet-c18385.html 'DPSTablet' => 'DPS Dream 9|DPS Dual 7', // http://www.visture.com/index.asp 'VistureTablet' => 'V97 HD|i75 3G|Visture V4( HD)?|Visture V5( HD)?|Visture V10', // http://www.mijncresta.nl/tablet 'CrestaTablet' => 'CTP(-)?810|CTP(-)?818|CTP(-)?828|CTP(-)?838|CTP(-)?888|CTP(-)?978|CTP(-)?980|CTP(-)?987|CTP(-)?988|CTP(-)?989', // MediaTek - http://www.mediatek.com/_en/01_products/02_proSys.php?cata_sn=1&cata1_sn=1&cata2_sn=309 'MediatekTablet' => '\bMT8125|MT8389|MT8135|MT8377\b', // Concorde tab 'ConcordeTablet' => 'Concorde([ ]+)?Tab|ConCorde ReadMan', // GoClever Tablets - http://www.goclever.com/uk/products,c1/tablet,c5/ 'GoCleverTablet' => 'GOCLEVER TAB|A7GOCLEVER|M1042|M7841|M742|R1042BK|R1041|TAB A975|TAB A7842|TAB A741|TAB A741L|TAB M723G|TAB M721|TAB A1021|TAB I921|TAB R721|TAB I720|TAB T76|TAB R70|TAB R76.2|TAB R106|TAB R83.2|TAB M813G|TAB I721|GCTA722|TAB I70|TAB I71|TAB S73|TAB R73|TAB R74|TAB R93|TAB R75|TAB R76.1|TAB A73|TAB A93|TAB A93.2|TAB T72|TAB R83|TAB R974|TAB R973|TAB A101|TAB A103|TAB A104|TAB A104.2|R105BK|M713G|A972BK|TAB A971|TAB R974.2|TAB R104|TAB R83.3|TAB A1042', // Modecom Tablets - http://www.modecom.eu/tablets/portal/ 'ModecomTablet' => 'FreeTAB 9000|FreeTAB 7.4|FreeTAB 7004|FreeTAB 7800|FreeTAB 2096|FreeTAB 7.5|FreeTAB 1014|FreeTAB 1001 |FreeTAB 8001|FreeTAB 9706|FreeTAB 9702|FreeTAB 7003|FreeTAB 7002|FreeTAB 1002|FreeTAB 7801|FreeTAB 1331|FreeTAB 1004|FreeTAB 8002|FreeTAB 8014|FreeTAB 9704|FreeTAB 1003', // Vonino Tablets 'VoninoTablet' => '\b(Argus[ _]?S|Diamond[ _]?79HD|Emerald[ _]?78E|Luna[ _]?70C|Onyx[ _]?S|Onyx[ _]?Z|Orin[ _]?HD|Orin[ _]?S|Otis[ _]?S|SpeedStar[ _]?S|Magnet[ _]?M9|Primus[ _]?94[ _]?3G|Primus[ _]?94HD|Primus[ _]?QS|Android.*\bQ8\b|Sirius[ _]?EVO[ _]?QS|Sirius[ _]?QS|Spirit[ _]?S)\b', // ECS Tablets - http://www.ecs.com.tw/ECSWebSite/Product/Product_Tablet_List.aspx?CategoryID=14&MenuID=107&childid=M_107&LanID=0 'ECSTablet' => 'V07OT2|TM105A|S10OT1|TR10CS1', // Storex Tablets - http://storex.fr/espace_client/support.html // @note: no need to add all the tablet codes since they are guided by the first regex. 'StorexTablet' => 'eZee[_\']?(Tab|Go)[0-9]+|TabLC7|Looney Tunes Tab', // Generic Vodafone tablets. 'VodafoneTablet' => 'SmartTab([ ]+)?[0-9]+|SmartTabII10|SmartTabII7|VF-1497|VFD 1400', // French tablets - Essentiel B http://www.boulanger.fr/tablette_tactile_e-book/tablette_tactile_essentiel_b/cl_68908.htm?multiChoiceToDelete=brand&mc_brand=essentielb // Aka: http://www.essentielb.fr/ 'EssentielBTablet' => 'Smart[ \']?TAB[ ]+?[0-9]+|Family[ \']?TAB2', // Ross & Moor - http://ross-moor.ru/ 'RossMoorTablet' => 'RM-790|RM-997|RMD-878G|RMD-974R|RMT-705A|RMT-701|RME-601|RMT-501|RMT-711', // i-mobile http://product.i-mobilephone.com/Mobile_Device 'iMobileTablet' => 'i-mobile i-note', // http://www.tolino.de/de/vergleichen/ 'TolinoTablet' => 'tolino tab [0-9.]+|tolino shine', // AudioSonic - a Kmart brand // http://www.kmart.com.au/webapp/wcs/stores/servlet/Search?langId=-1&storeId=10701&catalogId=10001&categoryId=193001&pageSize=72¤tPage=1&searchCategory=193001%2b4294965664&sortBy=p_MaxPrice%7c1 'AudioSonicTablet' => '\bC-22Q|T7-QC|T-17B|T-17P\b', // AMPE Tablets - http://www.ampe.com.my/product-category/tablets/ // @todo: add them gradually to avoid conflicts. 'AMPETablet' => 'Android.* A78 ', // Skk Mobile - http://skkmobile.com.ph/product_tablets.php 'SkkTablet' => 'Android.* (SKYPAD|PHOENIX|CYCLOPS)', // Tecno Mobile (only tablet) - http://www.tecno-mobile.com/index.php/product?filterby=smart&list_order=all&page=1 'TecnoTablet' => 'TECNO P9|TECNO DP8D', // JXD (consoles & tablets) - http://jxd.hk/products.asp?selectclassid=009008&clsid=3 'JXDTablet' => 'Android.* \b(F3000|A3300|JXD5000|JXD3000|JXD2000|JXD300B|JXD300|S5800|S7800|S602b|S5110b|S7300|S5300|S602|S603|S5100|S5110|S601|S7100a|P3000F|P3000s|P101|P200s|P1000m|P200m|P9100|P1000s|S6600b|S908|P1000|P300|S18|S6600|S9100)\b', // i-Joy tablets - http://www.i-joy.es/en/cat/products/tablets/ 'iJoyTablet' => 'Tablet (Spirit 7|Essentia|Galatea|Fusion|Onix 7|Landa|Titan|Scooby|Deox|Stella|Themis|Argon|Unique 7|Sygnus|Hexen|Finity 7|Cream|Cream X2|Jade|Neon 7|Neron 7|Kandy|Scape|Saphyr 7|Rebel|Biox|Rebel|Rebel 8GB|Myst|Draco 7|Myst|Tab7-004|Myst|Tadeo Jones|Tablet Boing|Arrow|Draco Dual Cam|Aurix|Mint|Amity|Revolution|Finity 9|Neon 9|T9w|Amity 4GB Dual Cam|Stone 4GB|Stone 8GB|Andromeda|Silken|X2|Andromeda II|Halley|Flame|Saphyr 9,7|Touch 8|Planet|Triton|Unique 10|Hexen 10|Memphis 4GB|Memphis 8GB|Onix 10)', // http://www.intracon.eu/tablet 'FX2Tablet' => 'FX2 PAD7|FX2 PAD10', // http://www.xoro.de/produkte/ // @note: Might be the same brand with 'Simply tablets' 'XoroTablet' => 'KidsPAD 701|PAD[ ]?712|PAD[ ]?714|PAD[ ]?716|PAD[ ]?717|PAD[ ]?718|PAD[ ]?720|PAD[ ]?721|PAD[ ]?722|PAD[ ]?790|PAD[ ]?792|PAD[ ]?900|PAD[ ]?9715D|PAD[ ]?9716DR|PAD[ ]?9718DR|PAD[ ]?9719QR|PAD[ ]?9720QR|TelePAD1030|Telepad1032|TelePAD730|TelePAD731|TelePAD732|TelePAD735Q|TelePAD830|TelePAD9730|TelePAD795|MegaPAD 1331|MegaPAD 1851|MegaPAD 2151', // http://www1.viewsonic.com/products/computing/tablets/ 'ViewsonicTablet' => 'ViewPad 10pi|ViewPad 10e|ViewPad 10s|ViewPad E72|ViewPad7|ViewPad E100|ViewPad 7e|ViewSonic VB733|VB100a', // https://www.verizonwireless.com/tablets/verizon/ 'VerizonTablet' => 'QTAQZ3|QTAIR7|QTAQTZ3|QTASUN1|QTASUN2|QTAXIA1', // http://www.odys.de/web/internet-tablet_en.html 'OdysTablet' => 'LOOX|XENO10|ODYS[ -](Space|EVO|Xpress|NOON)|\bXELIO\b|Xelio10Pro|XELIO7PHONETAB|XELIO10EXTREME|XELIOPT2|NEO_QUAD10', // http://www.captiva-power.de/products.html#tablets-en 'CaptivaTablet' => 'CAPTIVA PAD', // IconBIT - http://www.iconbit.com/products/tablets/ 'IconbitTablet' => 'NetTAB|NT-3702|NT-3702S|NT-3702S|NT-3603P|NT-3603P|NT-0704S|NT-0704S|NT-3805C|NT-3805C|NT-0806C|NT-0806C|NT-0909T|NT-0909T|NT-0907S|NT-0907S|NT-0902S|NT-0902S', // http://www.teclast.com/topic.php?channelID=70&topicID=140&pid=63 'TeclastTablet' => 'T98 4G|\bP80\b|\bX90HD\b|X98 Air|X98 Air 3G|\bX89\b|P80 3G|\bX80h\b|P98 Air|\bX89HD\b|P98 3G|\bP90HD\b|P89 3G|X98 3G|\bP70h\b|P79HD 3G|G18d 3G|\bP79HD\b|\bP89s\b|\bA88\b|\bP10HD\b|\bP19HD\b|G18 3G|\bP78HD\b|\bA78\b|\bP75\b|G17s 3G|G17h 3G|\bP85t\b|\bP90\b|\bP11\b|\bP98t\b|\bP98HD\b|\bG18d\b|\bP85s\b|\bP11HD\b|\bP88s\b|\bA80HD\b|\bA80se\b|\bA10h\b|\bP89\b|\bP78s\b|\bG18\b|\bP85\b|\bA70h\b|\bA70\b|\bG17\b|\bP18\b|\bA80s\b|\bA11s\b|\bP88HD\b|\bA80h\b|\bP76s\b|\bP76h\b|\bP98\b|\bA10HD\b|\bP78\b|\bP88\b|\bA11\b|\bA10t\b|\bP76a\b|\bP76t\b|\bP76e\b|\bP85HD\b|\bP85a\b|\bP86\b|\bP75HD\b|\bP76v\b|\bA12\b|\bP75a\b|\bA15\b|\bP76Ti\b|\bP81HD\b|\bA10\b|\bT760VE\b|\bT720HD\b|\bP76\b|\bP73\b|\bP71\b|\bP72\b|\bT720SE\b|\bC520Ti\b|\bT760\b|\bT720VE\b|T720-3GE|T720-WiFi', // Onda - http://www.onda-tablet.com/buy-android-onda.html?dir=desc&limit=all&order=price 'OndaTablet' => '\b(V975i|Vi30|VX530|V701|Vi60|V701s|Vi50|V801s|V719|Vx610w|VX610W|V819i|Vi10|VX580W|Vi10|V711s|V813|V811|V820w|V820|Vi20|V711|VI30W|V712|V891w|V972|V819w|V820w|Vi60|V820w|V711|V813s|V801|V819|V975s|V801|V819|V819|V818|V811|V712|V975m|V101w|V961w|V812|V818|V971|V971s|V919|V989|V116w|V102w|V973|Vi40)\b[\s]+|V10 \b4G\b', 'JaytechTablet' => 'TPC-PA762', 'BlaupunktTablet' => 'Endeavour 800NG|Endeavour 1010', // http://www.digma.ru/support/download/ // @todo: Ebooks also (if requested) 'DigmaTablet' => '\b(iDx10|iDx9|iDx8|iDx7|iDxD7|iDxD8|iDsQ8|iDsQ7|iDsQ8|iDsD10|iDnD7|3TS804H|iDsQ11|iDj7|iDs10)\b', // http://www.evolioshop.com/ro/tablete-pc.html // http://www.evolio.ro/support/downloads_static.html?cat=2 // @todo: Research some more 'EvolioTablet' => 'ARIA_Mini_wifi|Aria[ _]Mini|Evolio X10|Evolio X7|Evolio X8|\bEvotab\b|\bNeura\b', // @todo http://www.lavamobiles.com/tablets-data-cards 'LavaTablet' => 'QPAD E704|\bIvoryS\b|E-TAB IVORY|\bE-TAB\b', // http://www.breezetablet.com/ 'AocTablet' => 'MW0811|MW0812|MW0922|MTK8382|MW1031|MW0831|MW0821|MW0931|MW0712', // http://www.mpmaneurope.com/en/products/internet-tablets-14/android-tablets-14/ 'MpmanTablet' => 'MP11 OCTA|MP10 OCTA|MPQC1114|MPQC1004|MPQC994|MPQC974|MPQC973|MPQC804|MPQC784|MPQC780|\bMPG7\b|MPDCG75|MPDCG71|MPDC1006|MP101DC|MPDC9000|MPDC905|MPDC706HD|MPDC706|MPDC705|MPDC110|MPDC100|MPDC99|MPDC97|MPDC88|MPDC8|MPDC77|MP709|MID701|MID711|MID170|MPDC703|MPQC1010', // https://www.celkonmobiles.com/?_a=categoryphones&sid=2 'CelkonTablet' => 'CT695|CT888|CT[\s]?910|CT7 Tab|CT9 Tab|CT3 Tab|CT2 Tab|CT1 Tab|C820|C720|\bCT-1\b', // http://www.wolderelectronics.com/productos/manuales-y-guias-rapidas/categoria-2-miTab 'WolderTablet' => 'miTab \b(DIAMOND|SPACE|BROOKLYN|NEO|FLY|MANHATTAN|FUNK|EVOLUTION|SKY|GOCAR|IRON|GENIUS|POP|MINT|EPSILON|BROADWAY|JUMP|HOP|LEGEND|NEW AGE|LINE|ADVANCE|FEEL|FOLLOW|LIKE|LINK|LIVE|THINK|FREEDOM|CHICAGO|CLEVELAND|BALTIMORE-GH|IOWA|BOSTON|SEATTLE|PHOENIX|DALLAS|IN 101|MasterChef)\b', 'MediacomTablet' => 'M-MPI10C3G|M-SP10EG|M-SP10EGP|M-SP10HXAH|M-SP7HXAH|M-SP10HXBH|M-SP8HXAH|M-SP8MXA', // http://www.mi.com/en 'MiTablet' => '\bMI PAD\b|\bHM NOTE 1W\b', // http://www.nbru.cn/index.html 'NibiruTablet' => 'Nibiru M1|Nibiru Jupiter One', // http://navroad.com/products/produkty/tablety/ // http://navroad.com/products/produkty/tablety/ 'NexoTablet' => 'NEXO NOVA|NEXO 10|NEXO AVIO|NEXO FREE|NEXO GO|NEXO EVO|NEXO 3G|NEXO SMART|NEXO KIDDO|NEXO MOBI', // http://leader-online.com/new_site/product-category/tablets/ // http://www.leader-online.net.au/List/Tablet 'LeaderTablet' => 'TBLT10Q|TBLT10I|TBL-10WDKB|TBL-10WDKBO2013|TBL-W230V2|TBL-W450|TBL-W500|SV572|TBLT7I|TBA-AC7-8G|TBLT79|TBL-8W16|TBL-10W32|TBL-10WKB|TBL-W100', // http://www.datawind.com/ubislate/ 'UbislateTablet' => 'UbiSlate[\s]?7C', // http://www.pocketbook-int.com/ru/support 'PocketBookTablet' => 'Pocketbook', // http://www.kocaso.com/product_tablet.html 'KocasoTablet' => '\b(TB-1207)\b', // http://global.hisense.com/product/asia/tablet/Sero7/201412/t20141215_91832.htm 'HisenseTablet' => '\b(F5281|E2371)\b', // http://www.tesco.com/direct/hudl/ 'Hudl' => 'Hudl HT7S3|Hudl 2', // http://www.telstra.com.au/home-phone/thub-2/ 'TelstraTablet' => 'T-Hub2', 'GenericTablet' => 'Android.*\b97D\b|Tablet(?!.*PC)|BNTV250A|MID-WCDMA|LogicPD Zoom2|\bA7EB\b|CatNova8|A1_07|CT704|CT1002|\bM721\b|rk30sdk|\bEVOTAB\b|M758A|ET904|ALUMIUM10|Smartfren Tab|Endeavour 1010|Tablet-PC-4|Tagi Tab|\bM6pro\b|CT1020W|arc 10HD|\bTP750\b|\bQTAQZ3\b|WVT101|TM1088|KT107', ]; /** * List of mobile Operating Systems. * * @var array */ protected static $operatingSystems = [ 'AndroidOS' => 'Android', 'BlackBerryOS' => 'blackberry|\bBB10\b|rim tablet os', 'PalmOS' => 'PalmOS|avantgo|blazer|elaine|hiptop|palm|plucker|xiino', 'SymbianOS' => 'Symbian|SymbOS|Series60|Series40|SYB-[0-9]+|\bS60\b', // @reference: http://en.wikipedia.org/wiki/Windows_Mobile 'WindowsMobileOS' => 'Windows CE.*(PPC|Smartphone|Mobile|[0-9]{3}x[0-9]{3})|Windows Mobile|Windows Phone [0-9.]+|WCE;', // @reference: http://en.wikipedia.org/wiki/Windows_Phone // http://wifeng.cn/?r=blog&a=view&id=106 // http://nicksnettravels.builttoroam.com/post/2011/01/10/Bogus-Windows-Phone-7-User-Agent-String.aspx // http://msdn.microsoft.com/library/ms537503.aspx // https://msdn.microsoft.com/en-us/library/hh869301(v=vs.85).aspx 'WindowsPhoneOS' => 'Windows Phone 10.0|Windows Phone 8.1|Windows Phone 8.0|Windows Phone OS|XBLWP7|ZuneWP7|Windows NT 6.[23]; ARM;', 'iOS' => '\biPhone.*Mobile|\biPod|\biPad|AppleCoreMedia', // https://en.wikipedia.org/wiki/IPadOS 'iPadOS' => 'CPU OS 13', // @reference https://en.m.wikipedia.org/wiki/Sailfish_OS // https://sailfishos.org/ 'SailfishOS' => 'Sailfish', // http://en.wikipedia.org/wiki/MeeGo // @todo: research MeeGo in UAs 'MeeGoOS' => 'MeeGo', // http://en.wikipedia.org/wiki/Maemo // @todo: research Maemo in UAs 'MaemoOS' => 'Maemo', 'JavaOS' => 'J2ME/|\bMIDP\b|\bCLDC\b', // '|Java/' produces bug #135 'webOS' => 'webOS|hpwOS', 'badaOS' => '\bBada\b', 'BREWOS' => 'BREW', ]; /** * List of mobile User Agents. * * IMPORTANT: This is a list of only mobile browsers. * Mobile Detect 2.x supports only mobile browsers, * it was never designed to detect all browsers. * The change will come in 2017 in the 3.x release for PHP7. * * @var array */ protected static $browsers = [ //'Vivaldi' => 'Vivaldi', // @reference: https://developers.google.com/chrome/mobile/docs/user-agent 'Chrome' => '\bCrMo\b|CriOS|Android.*Chrome/[.0-9]* (Mobile)?', 'Dolfin' => '\bDolfin\b', 'Opera' => 'Opera.*Mini|Opera.*Mobi|Android.*Opera|Mobile.*OPR/[0-9.]+$|Coast/[0-9.]+', 'Skyfire' => 'Skyfire', // Added "Edge on iOS" https://github.com/serbanghita/Mobile-Detect/issues/764 'Edge' => '\bEdgiOS\b|Mobile Safari/[.0-9]* Edge', 'IE' => 'IEMobile|MSIEMobile', // |Trident/[.0-9]+ 'Firefox' => 'fennec|firefox.*maemo|(Mobile|Tablet).*Firefox|Firefox.*Mobile|FxiOS', 'Bolt' => 'bolt', 'TeaShark' => 'teashark', 'Blazer' => 'Blazer', // @reference: http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariWebContent/OptimizingforSafarioniPhone/OptimizingforSafarioniPhone.html#//apple_ref/doc/uid/TP40006517-SW3 // Excluded "Edge on iOS" https://github.com/serbanghita/Mobile-Detect/issues/764 'Safari' => 'Version((?!\bEdgiOS\b).)*Mobile.*Safari|Safari.*Mobile|MobileSafari', // http://en.wikipedia.org/wiki/Midori_(web_browser) //'Midori' => 'midori', //'Tizen' => 'Tizen', 'WeChat' => '\bMicroMessenger\b', 'UCBrowser' => 'UC.*Browser|UCWEB', 'baiduboxapp' => 'baiduboxapp', 'baidubrowser' => 'baidubrowser', // https://github.com/serbanghita/Mobile-Detect/issues/7 'DiigoBrowser' => 'DiigoBrowser', // http://www.puffinbrowser.com/index.php // https://github.com/serbanghita/Mobile-Detect/issues/752 // 'Puffin' => 'Puffin', // http://mercury-browser.com/index.html 'Mercury' => '\bMercury\b', // http://en.wikipedia.org/wiki/Obigo_Browser 'ObigoBrowser' => 'Obigo', // http://en.wikipedia.org/wiki/NetFront 'NetFront' => 'NF-Browser', // @reference: http://en.wikipedia.org/wiki/Minimo // http://en.wikipedia.org/wiki/Vision_Mobile_Browser 'GenericBrowser' => 'NokiaBrowser|OviBrowser|OneBrowser|TwonkyBeamBrowser|SEMC.*Browser|FlyFlow|Minimo|NetFront|Novarra-Vision|MQQBrowser|MicroMessenger', // @reference: https://en.wikipedia.org/wiki/Pale_Moon_(web_browser) 'PaleMoon' => 'Android.*PaleMoon|Mobile.*PaleMoon', ]; /** * Utilities. * * @var array */ protected static $utilities = [ // Experimental. When a mobile device wants to switch to 'Desktop Mode'. // http://scottcate.com/technology/windows-phone-8-ie10-desktop-or-mobile/ // https://github.com/serbanghita/Mobile-Detect/issues/57#issuecomment-15024011 // https://developers.facebook.com/docs/sharing/webmasters/crawler/ 'Bot' => 'Googlebot|facebookexternalhit|Google-AMPHTML|s~amp-validator|AdsBot-Google|Google Keyword Suggestion|Facebot|YandexBot|YandexMobileBot|bingbot|ia_archiver|AhrefsBot|Ezooms|GSLFbot|WBSearchBot|Twitterbot|TweetmemeBot|Twikle|PaperLiBot|Wotbox|UnwindFetchor|Exabot|MJ12bot|YandexImages|TurnitinBot|Pingdom|contentkingapp|AspiegelBot', 'MobileBot' => 'Googlebot-Mobile|AdsBot-Google-Mobile|YahooSeeker/M1A1-R2D2', 'DesktopMode' => 'WPDesktop', 'TV' => 'SonyDTV|HbbTV', // experimental 'WebKit' => '(webkit)[ /]([\w.]+)', // @todo: Include JXD consoles. 'Console' => '\b(Nintendo|Nintendo WiiU|Nintendo 3DS|Nintendo Switch|PLAYSTATION|Xbox)\b', 'Watch' => 'SM-V700', ]; /** * All possible HTTP headers that represent the * User-Agent string. * * @var array */ protected static $uaHttpHeaders = [ // The default User-Agent string. 'HTTP_USER_AGENT', // Header can occur on devices using Opera Mini. 'HTTP_X_OPERAMINI_PHONE_UA', // Vodafone specific header: http://www.seoprinciple.com/mobile-web-community-still-angry-at-vodafone/24/ 'HTTP_X_DEVICE_USER_AGENT', 'HTTP_X_ORIGINAL_USER_AGENT', 'HTTP_X_SKYFIRE_PHONE', 'HTTP_X_BOLT_PHONE_UA', 'HTTP_DEVICE_STOCK_UA', 'HTTP_X_UCBROWSER_DEVICE_UA', ]; /** * The individual segments that could exist in a User-Agent string. VER refers to the regular * expression defined in the constant self::VER. * * @var array */ protected static $properties = [ // Build 'Mobile' => 'Mobile/[VER]', 'Build' => 'Build/[VER]', 'Version' => 'Version/[VER]', 'VendorID' => 'VendorID/[VER]', // Devices 'iPad' => 'iPad.*CPU[a-z ]+[VER]', 'iPhone' => 'iPhone.*CPU[a-z ]+[VER]', 'iPod' => 'iPod.*CPU[a-z ]+[VER]', //'BlackBerry' => array('BlackBerry[VER]', 'BlackBerry [VER];'), 'Kindle' => 'Kindle/[VER]', // Browser 'Chrome' => ['Chrome/[VER]', 'CriOS/[VER]', 'CrMo/[VER]'], 'Coast' => ['Coast/[VER]'], 'Dolfin' => 'Dolfin/[VER]', // @reference: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox 'Firefox' => ['Firefox/[VER]', 'FxiOS/[VER]'], 'Fennec' => 'Fennec/[VER]', // http://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx // https://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx 'Edge' => 'Edge/[VER]', 'IE' => ['IEMobile/[VER];', 'IEMobile [VER]', 'MSIE [VER];', 'Trident/[0-9.]+;.*rv:[VER]'], // http://en.wikipedia.org/wiki/NetFront 'NetFront' => 'NetFront/[VER]', 'NokiaBrowser' => 'NokiaBrowser/[VER]', 'Opera' => [' OPR/[VER]', 'Opera Mini/[VER]', 'Version/[VER]'], 'Opera Mini' => 'Opera Mini/[VER]', 'Opera Mobi' => 'Version/[VER]', 'UCBrowser' => ['UCWEB[VER]', 'UC.*Browser/[VER]'], 'MQQBrowser' => 'MQQBrowser/[VER]', 'MicroMessenger' => 'MicroMessenger/[VER]', 'baiduboxapp' => 'baiduboxapp/[VER]', 'baidubrowser' => 'baidubrowser/[VER]', 'SamsungBrowser' => 'SamsungBrowser/[VER]', 'Iron' => 'Iron/[VER]', // @note: Safari 7534.48.3 is actually Version 5.1. // @note: On BlackBerry the Version is overwriten by the OS. 'Safari' => ['Version/[VER]', 'Safari/[VER]'], 'Skyfire' => 'Skyfire/[VER]', 'Tizen' => 'Tizen/[VER]', 'Webkit' => 'webkit[ /][VER]', 'PaleMoon' => 'PaleMoon/[VER]', 'SailfishBrowser' => 'SailfishBrowser/[VER]', // Engine 'Gecko' => 'Gecko/[VER]', 'Trident' => 'Trident/[VER]', 'Presto' => 'Presto/[VER]', 'Goanna' => 'Goanna/[VER]', // OS 'iOS' => ' \bi?OS\b [VER][ ;]{1}', 'Android' => 'Android [VER]', 'Sailfish' => 'Sailfish [VER]', 'BlackBerry' => ['BlackBerry[\w]+/[VER]', 'BlackBerry.*Version/[VER]', 'Version/[VER]'], 'BREW' => 'BREW [VER]', 'Java' => 'Java/[VER]', // @reference: http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/08/29/introducing-the-ie9-on-windows-phone-mango-user-agent-string.aspx // @reference: http://en.wikipedia.org/wiki/Windows_NT#Releases 'Windows Phone OS' => ['Windows Phone OS [VER]', 'Windows Phone [VER]'], 'Windows Phone' => 'Windows Phone [VER]', 'Windows CE' => 'Windows CE/[VER]', // http://social.msdn.microsoft.com/Forums/en-US/windowsdeveloperpreviewgeneral/thread/6be392da-4d2f-41b4-8354-8dcee20c85cd 'Windows NT' => 'Windows NT [VER]', 'Symbian' => ['SymbianOS/[VER]', 'Symbian/[VER]'], 'webOS' => ['webOS/[VER]', 'hpwOS/[VER];'], ]; /** * Construct an instance of this class. * * @param array $headers Specify the headers as injection. Should be PHP _SERVER flavored. * If left empty, will use the global _SERVER['HTTP_*'] vars instead. * @param string $userAgent Inject the User-Agent header. If null, will use HTTP_USER_AGENT * from the $headers array instead. */ public function __construct( array $headers = null, $userAgent = null ) { $this->setHttpHeaders($headers); $this->setUserAgent($userAgent); } /** * Get the current script version. * This is useful for the demo.php file, * so people can check on what version they are testing * for mobile devices. * * @return string The version number in semantic version format. */ public static function getScriptVersion() { return self::VERSION; } /** * Set the HTTP Headers. Must be PHP-flavored. This method will reset existing headers. * * @param array $httpHeaders The headers to set. If null, then using PHP's _SERVER to extract * the headers. The default null is left for backwards compatibility. */ public function setHttpHeaders($httpHeaders = null) { // use global _SERVER if $httpHeaders aren't defined if ( ! is_array($httpHeaders) || ! count($httpHeaders)) { $httpHeaders = $_SERVER; } // clear existing headers $this->httpHeaders = []; // Only save HTTP headers. In PHP land, that means only _SERVER vars that // start with HTTP_. foreach ($httpHeaders as $key => $value) { if (substr($key, 0, 5) === 'HTTP_') { $this->httpHeaders[$key] = $value; } } // In case we're dealing with CloudFront, we need to know. $this->setCfHeaders($httpHeaders); } /** * Retrieves the HTTP headers. * * @return array */ public function getHttpHeaders() { return $this->httpHeaders; } /** * Retrieves a particular header. If it doesn't exist, no exception/error is caused. * Simply null is returned. * * @param string $header The name of the header to retrieve. Can be HTTP compliant such as * "User-Agent" or "X-Device-User-Agent" or can be php-esque with the * all-caps, HTTP_ prefixed, underscore seperated awesomeness. * * @return string|null The value of the header. */ public function getHttpHeader($header) { // are we using PHP-flavored headers? if (strpos($header, '_') === false) { $header = str_replace('-', '_', $header); $header = strtoupper($header); } // test the alternate, too $altHeader = 'HTTP_' . $header; //Test both the regular and the HTTP_ prefix if (isset($this->httpHeaders[$header])) { return $this->httpHeaders[$header]; } elseif (isset($this->httpHeaders[$altHeader])) { return $this->httpHeaders[$altHeader]; } return null; } public function getMobileHeaders() { return self::$mobileHeaders; } /** * Get all possible HTTP headers that * can contain the User-Agent string. * * @return array List of HTTP headers. */ public function getUaHttpHeaders() { return self::$uaHttpHeaders; } /** * Set CloudFront headers * http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-device * * @param array $cfHeaders List of HTTP headers * * @return boolean If there were CloudFront headers to be set */ public function setCfHeaders($cfHeaders = null) { // use global _SERVER if $cfHeaders aren't defined if ( ! is_array($cfHeaders) || ! count($cfHeaders)) { $cfHeaders = $_SERVER; } // clear existing headers $this->cloudfrontHeaders = []; // Only save CLOUDFRONT headers. In PHP land, that means only _SERVER vars that // start with cloudfront-. $response = false; foreach ($cfHeaders as $key => $value) { if (substr(strtolower($key), 0, 16) === 'http_cloudfront_') { $this->cloudfrontHeaders[strtoupper($key)] = $value; $response = true; } } return $response; } /** * Retrieves the cloudfront headers. * * @return array */ public function getCfHeaders() { return $this->cloudfrontHeaders; } /** * @param string $userAgent * * @return string */ private function prepareUserAgent($userAgent) { $userAgent = trim($userAgent); $userAgent = substr($userAgent, 0, 500); return $userAgent; } /** * Set the User-Agent to be used. * * @param string $userAgent The user agent string to set. * * @return string|null */ public function setUserAgent($userAgent = null) { // Invalidate cache due to #375 $this->cache = []; if (false === empty($userAgent)) { return $this->userAgent = $this->prepareUserAgent($userAgent); } else { $this->userAgent = null; foreach ($this->getUaHttpHeaders() as $altHeader) { if (false === empty($this->httpHeaders[$altHeader])) { // @todo: should use getHttpHeader(), but it would be slow. (Serban) $this->userAgent .= $this->httpHeaders[$altHeader] . " "; } } if ( ! empty($this->userAgent)) { return $this->userAgent = $this->prepareUserAgent($this->userAgent); } } if (count($this->getCfHeaders()) > 0) { return $this->userAgent = 'Amazon CloudFront'; } return $this->userAgent = null; } /** * Retrieve the User-Agent. * * @return string|null The user agent if it's set. */ public function getUserAgent() { return $this->userAgent; } /** * Set the detection type. Must be one of self::DETECTION_TYPE_MOBILE or * self::DETECTION_TYPE_EXTENDED. Otherwise, nothing is set. * * @param string $type The type. Must be a self::DETECTION_TYPE_* constant. The default * parameter is null which will default to self::DETECTION_TYPE_MOBILE. * * @deprecated since version 2.6.9 * */ public function setDetectionType($type = null) { if ($type === null) { $type = self::DETECTION_TYPE_MOBILE; } if ($type !== self::DETECTION_TYPE_MOBILE && $type !== self::DETECTION_TYPE_EXTENDED) { return; } $this->detectionType = $type; } public function getMatchingRegex() { return $this->matchingRegex; } public function getMatchesArray() { return $this->matchesArray; } /** * Retrieve the list of known phone devices. * * @return array List of phone devices. */ public static function getPhoneDevices() { return self::$phoneDevices; } /** * Retrieve the list of known tablet devices. * * @return array List of tablet devices. */ public static function getTabletDevices() { return self::$tabletDevices; } /** * Alias for getBrowsers() method. * * @return array List of user agents. */ public static function getUserAgents() { return self::getBrowsers(); } /** * Retrieve the list of known browsers. Specifically, the user agents. * * @return array List of browsers / user agents. */ public static function getBrowsers() { return self::$browsers; } /** * Retrieve the list of known utilities. * * @return array List of utilities. */ public static function getUtilities() { return self::$utilities; } /** * Method gets the mobile detection rules. This method is used for the magic methods $detect->is*(). * * @return array All the rules (but not extended). * @deprecated since version 2.6.9 * */ public static function getMobileDetectionRules() { static $rules; if ( ! $rules) { $rules = array_merge( self::$phoneDevices, self::$tabletDevices, self::$operatingSystems, self::$browsers ); } return $rules; } /** * Method gets the mobile detection rules + utilities. * The reason this is separate is because utilities rules * don't necessary imply mobile. This method is used inside * the new $detect->is('stuff') method. * * @return array All the rules + extended. * @deprecated since version 2.6.9 * */ public function getMobileDetectionRulesExtended() { static $rules; if ( ! $rules) { // Merge all rules together. $rules = array_merge( self::$phoneDevices, self::$tabletDevices, self::$operatingSystems, self::$browsers, self::$utilities ); } return $rules; } /** * Retrieve the current set of rules. * * @return array * @deprecated since version 2.6.9 * */ public function getRules() { if ($this->detectionType == self::DETECTION_TYPE_EXTENDED) { return self::getMobileDetectionRulesExtended(); } else { return self::getMobileDetectionRules(); } } /** * Retrieve the list of mobile operating systems. * * @return array The list of mobile operating systems. */ public static function getOperatingSystems() { return self::$operatingSystems; } /** * Check the HTTP headers for signs of mobile. * This is the fastest mobile check possible; it's used * inside isMobile() method. * * @return bool */ public function checkHttpHeadersForMobile() { foreach ($this->getMobileHeaders() as $mobileHeader => $matchType) { if (isset($this->httpHeaders[$mobileHeader])) { if (isset($matchType['matches']) && is_array($matchType['matches'])) { foreach ($matchType['matches'] as $_match) { if (strpos($this->httpHeaders[$mobileHeader], $_match) !== false) { return true; } } return false; } else { return true; } } } return false; } /** * Magic overloading method. * * @method boolean is[...]() * @param string $name * @param array $arguments * * @return mixed * @throws BadMethodCallException when the method doesn't exist and doesn't start with 'is' */ public function __call($name, $arguments) { // make sure the name starts with 'is', otherwise if (substr($name, 0, 2) !== 'is') { throw new BadMethodCallException("No such method exists: $name"); } $this->setDetectionType(self::DETECTION_TYPE_MOBILE); $key = substr($name, 2); return $this->matchUAAgainstKey($key); } /** * Find a detection rule that matches the current User-agent. * * @param null $userAgent deprecated * * @return boolean */ protected function matchDetectionRulesAgainstUA($userAgent = null) { // Begin general search. foreach ($this->getRules() as $_regex) { if (empty($_regex)) { continue; } if ($this->match($_regex, $userAgent)) { return true; } } return false; } /** * Search for a certain key in the rules array. * If the key is found then try to match the corresponding * regex against the User-Agent. * * @param string $key * * @return boolean */ protected function matchUAAgainstKey($key) { // Make the keys lowercase so we can match: isIphone(), isiPhone(), isiphone(), etc. $key = strtolower($key); if (false === isset($this->cache[$key])) { // change the keys to lower case $_rules = array_change_key_case($this->getRules()); if (false === empty($_rules[$key])) { $this->cache[$key] = $this->match($_rules[$key]); } if (false === isset($this->cache[$key])) { $this->cache[$key] = false; } } return $this->cache[$key]; } /** * Check if the device is mobile. * Returns true if any type of mobile device detected, including special ones * * @param null $userAgent deprecated * @param null $httpHeaders deprecated * * @return bool */ public function isMobile($userAgent = null, $httpHeaders = null) { if ($httpHeaders) { $this->setHttpHeaders($httpHeaders); } if ($userAgent) { $this->setUserAgent($userAgent); } // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront' if ($this->getUserAgent() === 'Amazon CloudFront') { $cfHeaders = $this->getCfHeaders(); if (array_key_exists('HTTP_CLOUDFRONT_IS_MOBILE_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_MOBILE_VIEWER'] === 'true') { return true; } } $this->setDetectionType(self::DETECTION_TYPE_MOBILE); if ($this->checkHttpHeadersForMobile()) { return true; } else { return $this->matchDetectionRulesAgainstUA(); } } /** * Check if the device is a tablet. * Return true if any type of tablet device is detected. * * @param string $userAgent deprecated * @param array $httpHeaders deprecated * * @return bool */ public function isTablet($userAgent = null, $httpHeaders = null) { // Check specifically for cloudfront headers if the useragent === 'Amazon CloudFront' if ($this->getUserAgent() === 'Amazon CloudFront') { $cfHeaders = $this->getCfHeaders(); if (array_key_exists('HTTP_CLOUDFRONT_IS_TABLET_VIEWER', $cfHeaders) && $cfHeaders['HTTP_CLOUDFRONT_IS_TABLET_VIEWER'] === 'true') { return true; } } $this->setDetectionType(self::DETECTION_TYPE_MOBILE); foreach (self::$tabletDevices as $_regex) { if ($this->match($_regex, $userAgent)) { return true; } } return false; } /** * This method checks for a certain property in the * userAgent. * * @param string $key * @param string $userAgent deprecated * @param string $httpHeaders deprecated * * @return bool|int|null * @todo: The httpHeaders part is not yet used. * */ public function is($key, $userAgent = null, $httpHeaders = null) { // Set the UA and HTTP headers only if needed (eg. batch mode). if ($httpHeaders) { $this->setHttpHeaders($httpHeaders); } if ($userAgent) { $this->setUserAgent($userAgent); } $this->setDetectionType(self::DETECTION_TYPE_EXTENDED); return $this->matchUAAgainstKey($key); } /** * Some detection rules are relative (not standard), * because of the diversity of devices, vendors and * their conventions in representing the User-Agent or * the HTTP headers. * * This method will be used to check custom regexes against * the User-Agent string. * * @param $regex * @param string $userAgent * * @return bool * * @todo: search in the HTTP headers too. */ public function match($regex, $userAgent = null) { $match = (bool) preg_match(sprintf('#%s#is', $regex), (false === empty($userAgent) ? $userAgent : $this->userAgent), $matches); // If positive match is found, store the results for debug. if ($match) { $this->matchingRegex = $regex; $this->matchesArray = $matches; } return $match; } /** * Get the properties array. * * @return array */ public static function getProperties() { return self::$properties; } /** * Prepare the version number. * * @param string $ver The string version, like "2.6.21.2152"; * * @return float * @todo Remove the error supression from str_replace() call. * */ public function prepareVersionNo($ver) { $ver = str_replace(['_', ' ', '/'], '.', $ver); $arrVer = explode('.', $ver, 2); if (isset($arrVer[1])) { $arrVer[1] = @str_replace('.', '', $arrVer[1]); // @todo: treat strings versions. } return (float) implode('.', $arrVer); } /** * Check the version of the given property in the User-Agent. * Will return a float number. (eg. 2_0 will return 2.0, 4.3.1 will return 4.31) * * @param string $propertyName The name of the property. See self::getProperties() array * keys for all possible properties. * @param string $type Either self::VERSION_TYPE_STRING to get a string value or * self::VERSION_TYPE_FLOAT indicating a float value. This parameter * is optional and defaults to self::VERSION_TYPE_STRING. Passing an * invalid parameter will default to the this type as well. * * @return string|float The version of the property we are trying to extract. */ public function version($propertyName, $type = self::VERSION_TYPE_STRING) { if (empty($propertyName)) { return false; } // set the $type to the default if we don't recognize the type if ($type !== self::VERSION_TYPE_STRING && $type !== self::VERSION_TYPE_FLOAT) { $type = self::VERSION_TYPE_STRING; } $properties = self::getProperties(); // Check if the property exists in the properties array. if (true === isset($properties[$propertyName])) { // Prepare the pattern to be matched. // Make sure we always deal with an array (string is converted). $properties[$propertyName] = (array) $properties[$propertyName]; foreach ($properties[$propertyName] as $propertyMatchString) { $propertyPattern = str_replace('[VER]', self::VER, $propertyMatchString); // Identify and extract the version. preg_match(sprintf('#%s#is', $propertyPattern), $this->userAgent, $match); if (false === empty($match[1])) { $version = ($type == self::VERSION_TYPE_FLOAT ? $this->prepareVersionNo($match[1]) : $match[1]); return $version; } } } return false; } /** * Retrieve the mobile grading, using self::MOBILE_GRADE_* constants. * * @return string One of the self::MOBILE_GRADE_* constants. */ public function mobileGrade() { $isMobile = $this->isMobile(); if ( // Apple iOS 4-7.0 – Tested on the original iPad (4.3 / 5.0), iPad 2 (4.3 / 5.1 / 6.1), iPad 3 (5.1 / 6.0), iPad Mini (6.1), iPad Retina (7.0), iPhone 3GS (4.3), iPhone 4 (4.3 / 5.1), iPhone 4S (5.1 / 6.0), iPhone 5 (6.0), and iPhone 5S (7.0) $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) >= 4.3 || $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) >= 4.3 || $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) >= 4.3 || // Android 2.1-2.3 - Tested on the HTC Incredible (2.2), original Droid (2.2), HTC Aria (2.1), Google Nexus S (2.3). Functional on 1.5 & 1.6 but performance may be sluggish, tested on Google G1 (1.5) // Android 3.1 (Honeycomb) - Tested on the Samsung Galaxy Tab 10.1 and Motorola XOOM // Android 4.0 (ICS) - Tested on a Galaxy Nexus. Note: transition performance can be poor on upgraded devices // Android 4.1 (Jelly Bean) - Tested on a Galaxy Nexus and Galaxy 7 ($this->version('Android', self::VERSION_TYPE_FLOAT) > 2.1 && $this->is('Webkit')) || // Windows Phone 7.5-8 - Tested on the HTC Surround (7.5), HTC Trophy (7.5), LG-E900 (7.5), Nokia 800 (7.8), HTC Mazaa (7.8), Nokia Lumia 520 (8), Nokia Lumia 920 (8), HTC 8x (8) $this->version('Windows Phone OS', self::VERSION_TYPE_FLOAT) >= 7.5 || // Tested on the Torch 9800 (6) and Style 9670 (6), BlackBerry® Torch 9810 (7), BlackBerry Z10 (10) $this->is('BlackBerry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 6.0 || // Blackberry Playbook (1.0-2.0) - Tested on PlayBook $this->match('Playbook.*Tablet') || // Palm WebOS (1.4-3.0) - Tested on the Palm Pixi (1.4), Pre (1.4), Pre 2 (2.0), HP TouchPad (3.0) ($this->version('webOS', self::VERSION_TYPE_FLOAT) >= 1.4 && $this->match('Palm|Pre|Pixi')) || // Palm WebOS 3.0 - Tested on HP TouchPad $this->match('hp.*TouchPad') || // Firefox Mobile 18 - Tested on Android 2.3 and 4.1 devices ($this->is('Firefox') && $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 18) || // Chrome for Android - Tested on Android 4.0, 4.1 device ($this->is('Chrome') && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 4.0) || // Skyfire 4.1 - Tested on Android 2.3 device ($this->is('Skyfire') && $this->version('Skyfire', self::VERSION_TYPE_FLOAT) >= 4.1 && $this->is('AndroidOS') && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3) || // Opera Mobile 11.5-12: Tested on Android 2.3 ($this->is('Opera') && $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11.5 && $this->is('AndroidOS')) || // Meego 1.2 - Tested on Nokia 950 and N9 $this->is('MeeGoOS') || // Sailfish OS $this->is('SailfishOS') || // Tizen (pre-release) - Tested on early hardware $this->is('Tizen') || // Samsung Bada 2.0 - Tested on a Samsung Wave 3, Dolphin browser // @todo: more tests here! $this->is('Dolfin') && $this->version('Bada', self::VERSION_TYPE_FLOAT) >= 2.0 || // UC Browser - Tested on Android 2.3 device (($this->is('UC Browser') || $this->is('Dolfin')) && $this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3) || // Kindle 3 and Fire - Tested on the built-in WebKit browser for each ($this->match('Kindle Fire') || $this->is('Kindle') && $this->version('Kindle', self::VERSION_TYPE_FLOAT) >= 3.0) || // Nook Color 1.4.1 - Tested on original Nook Color, not Nook Tablet $this->is('AndroidOS') && $this->is('NookTablet') || // Chrome Desktop 16-24 - Tested on OS X 10.7 and Windows 7 $this->version('Chrome', self::VERSION_TYPE_FLOAT) >= 16 && ! $isMobile || // Safari Desktop 5-6 - Tested on OS X 10.7 and Windows 7 $this->version('Safari', self::VERSION_TYPE_FLOAT) >= 5.0 && ! $isMobile || // Firefox Desktop 10-18 - Tested on OS X 10.7 and Windows 7 $this->version('Firefox', self::VERSION_TYPE_FLOAT) >= 10.0 && ! $isMobile || // Internet Explorer 7-9 - Tested on Windows XP, Vista and 7 $this->version('IE', self::VERSION_TYPE_FLOAT) >= 7.0 && ! $isMobile || // Opera Desktop 10-12 - Tested on OS X 10.7 and Windows 7 $this->version('Opera', self::VERSION_TYPE_FLOAT) >= 10 && ! $isMobile ) { return self::MOBILE_GRADE_A; } if ( $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) < 4.3 || $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) < 4.3 || $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) < 4.3 || // Blackberry 5.0: Tested on the Storm 2 9550, Bold 9770 $this->is('Blackberry') && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) >= 5 && $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) < 6 || //Opera Mini (5.0-6.5) - Tested on iOS 3.2/4.3 and Android 2.3 ($this->version('Opera Mini', self::VERSION_TYPE_FLOAT) >= 5.0 && $this->version('Opera Mini', self::VERSION_TYPE_FLOAT) <= 7.0 && ($this->version('Android', self::VERSION_TYPE_FLOAT) >= 2.3 || $this->is('iOS'))) || // Nokia Symbian^3 - Tested on Nokia N8 (Symbian^3), C7 (Symbian^3), also works on N97 (Symbian^1) $this->match('NokiaN8|NokiaC7|N97.*Series60|Symbian/3') || // @todo: report this (tested on Nokia N71) $this->version('Opera Mobi', self::VERSION_TYPE_FLOAT) >= 11 && $this->is('SymbianOS') ) { return self::MOBILE_GRADE_B; } if ( // Blackberry 4.x - Tested on the Curve 8330 $this->version('BlackBerry', self::VERSION_TYPE_FLOAT) <= 5.0 || // Windows Mobile - Tested on the HTC Leo (WinMo 5.2) $this->match('MSIEMobile|Windows CE.*Mobile') || $this->version('Windows Mobile', self::VERSION_TYPE_FLOAT) <= 5.2 || // Tested on original iPhone (3.1), iPhone 3 (3.2) $this->is('iOS') && $this->version('iPad', self::VERSION_TYPE_FLOAT) <= 3.2 || $this->is('iOS') && $this->version('iPhone', self::VERSION_TYPE_FLOAT) <= 3.2 || $this->is('iOS') && $this->version('iPod', self::VERSION_TYPE_FLOAT) <= 3.2 || // Internet Explorer 7 and older - Tested on Windows XP $this->version('IE', self::VERSION_TYPE_FLOAT) <= 7.0 && ! $isMobile ) { return self::MOBILE_GRADE_C; } // All older smartphone platforms and featurephones - Any device that doesn't support media queries // will receive the basic, C grade experience. return self::MOBILE_GRADE_C; } } Date.php 0000604 00000007507 15245535751 0006153 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use DateTimeZone; use Joomla\CMS\Factory as JFactory; class Date { /** * Convert string to a correct date format ('00-00-00 00:00:00' or '00-00-00') or null * * @param string $date * * @return null|string */ public static function fix($date) { if ( ! $date) { return null; } $date = trim($date); // Check if date has correct syntax: 00-00-00 00:00:00 // If so, the date format is correct if (RegEx::match('^[0-9]+-[0-9]+-[0-9]+( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$', $date)) { return $date; } // Check if date has syntax: 00-00-00 00:00 // If so, it is missing the seconds, so add :00 (seconds) if (RegEx::match('^[0-9]+-[0-9]+-[0-9]+ [0-9][0-9]:[0-9][0-9]$', $date)) { return $date . ':00'; } // Check if date has a prepending date syntax: 00-00-00 // If so, it is missing a correct time time, so add 00:00:00 (hours, minutes, seconds) if (RegEx::match('^([0-9]+-[0-9]+-[0-9]+)$', $date, $match)) { return $match[1] . ' 00:00:00'; } // Date format is not correct, so return null return null; } /** * Applies offset to a date * * @param string $date * @param string $timezone */ public static function applyTimezone(&$date, $timezone = '') { if ($date <= 0) { $date = 0; return; } $timezone = $timezone ?: JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset')); $date = JFactory::getDate($date, $timezone); $date->setTimezone(new DateTimeZone('UTC')); $date = $date->format('Y-m-d H:i:s', true, false); } /** * Convert string with 'date' format to 'strftime' format * * @param string $format * * @return string */ public static function strftimeToDateFormat($format) { if (strpos($format, '%') === false) { return $format; } return strtr((string) $format, self::getStrftimeToDateFormats()); } /** * Convert string with 'date' format to 'strftime' format * * @param string $format * * @return string */ public static function dateToStrftimeFormat($format) { return strtr((string) $format, self::getDateToStrftimeFormats()); } private static function getStrftimeToDateFormats() { return [ // Day '%d' => 'd', '%a' => 'D', '%#d' => 'j', '%A' => 'l', '%u' => 'N', '%w' => 'w', '%j' => 'z', // Week '%V' => 'W', // Month '%B' => 'F', '%m' => 'm', '%b' => 'M', // Year '%G' => 'o', '%Y' => 'Y', '%y' => 'y', // Time '%P' => 'a', '%p' => 'A', '%l' => 'g', '%I' => 'h', '%H' => 'H', '%M' => 'i', '%S' => 's', // Timezone '%z' => 'O', '%Z' => 'T', // Full Date / Time '%s' => 'U', ]; } private static function getDateToStrftimeFormats() { return [ // Day - no strf eq : S 'd' => '%d', 'D' => '%a', 'jS' => '%#d[TH]', 'j' => '%#d', 'l' => '%A', 'N' => '%u', 'w' => '%w', 'z' => '%j', // Week - no date eq : %U, %W 'W' => '%V', // Month - no strf eq : n, t 'F' => '%B', 'm' => '%m', 'M' => '%b', // Year - no strf eq : L; no date eq : %C, %g 'o' => '%G', 'Y' => '%Y', 'y' => '%y', // Time - no strf eq : B, G, u; no date eq : %r, %R, %T, %X 'a' => '%P', 'A' => '%p', 'g' => '%l', 'h' => '%I', 'H' => '%H', 'i' => '%M', 's' => '%S', // Timezone - no strf eq : e, I, P, Z 'O' => '%z', 'T' => '%Z', // Full Date / Time - no strf eq : c, r; no date eq : %c, %D, %F, %x 'U' => '%s', ]; } } Language.php 0000604 00000002022 15245535751 0007004 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Language * @package RegularLabs\Library */ class Language { /** * Load the language of the given extension * * @param string $extension * @param string $basePath * @param bool $reload * * @return bool */ public static function load($extension = 'plg_system_regularlabs', $basePath = '', $reload = false) { if ($basePath && JFactory::getLanguage()->load($extension, $basePath, null, $reload)) { return true; } $basePath = Extension::getPath($extension, $basePath, 'language'); return JFactory::getLanguage()->load($extension, $basePath, null, $reload); } } Log.php 0000604 00000006175 15245535751 0006017 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use ActionlogsModelActionlog; use JLoader; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\MVC\Model\BaseDatabaseModel as JModel; /** * Class Log * @package RegularLabs\Library */ class Log { public static function add($message, $languageKey, $context) { $user = JFactory::getUser(); $message['userid'] = $user->id; $message['username'] = $user->username; $message['accountlink'] = 'index.php?option=com_users&task=user.edit&id=' . $user->id; JLoader::register('ActionlogsHelper', JPATH_ADMINISTRATOR . '/components/com_actionlogs/helpers/actionlogs.php'); JLoader::register('ActionlogsModelActionlog', JPATH_ADMINISTRATOR . '/components/com_actionlogs/models/actionlog.php'); /* @var ActionlogsModelActionlog $model */ $model = JModel::getInstance('Actionlog', 'ActionlogsModel'); $model->addLog([$message], $languageKey, $context, $user->id); } public static function save($message, $context, $isNew) { $languageKey = $isNew ? 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ADDED' : 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UPDATED'; $message['action'] = $isNew ? 'add' : 'update'; self::add($message, $languageKey, $context); } public static function delete($message, $context) { $languageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_DELETED'; $message['action'] = 'deleted'; self::add($message, $languageKey, $context); } public static function changeState($message, $context, $value) { switch ($value) { case 0: $languageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_UNPUBLISHED'; $message['action'] = 'unpublish'; break; case 1: $languageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_PUBLISHED'; $message['action'] = 'publish'; break; case 2: $languageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_ARCHIVED'; $message['action'] = 'archive'; break; case -2: $languageKey = 'PLG_SYSTEM_ACTIONLOGS_CONTENT_TRASHED'; $message['action'] = 'trash'; break; default: return; } self::add($message, $languageKey, $context); } public static function install($message, $context, $type = 'component') { $languageKey = 'PLG_ACTIONLOG_JOOMLA_' . strtoupper($type) . '_INSTALLED'; if ( ! JFactory::getApplication()->getLanguage()->hasKey($languageKey)) { $languageKey = 'PLG_ACTIONLOG_JOOMLA_EXTENSION_INSTALLED'; } $message['action'] = 'install'; $message['type'] = 'PLG_ACTIONLOG_JOOMLA_TYPE_' . strtoupper($type); self::add($message, $languageKey, $context); } public static function uninstall($message, $context, $type = 'component') { $languageKey = 'PLG_ACTIONLOG_JOOMLA_EXTENSION_UNINSTALLED'; $message['action'] = 'uninstall'; $message['type'] = 'PLG_ACTIONLOG_JOOMLA_TYPE_' . strtoupper($type); self::add($message, $languageKey, $context); } } Protect.php 0000604 00000066450 15245535751 0006720 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Access\Access as JAccess; use Joomla\CMS\Factory as JFactory; jimport('joomla.filesystem.file'); /** * Class Protect * @package RegularLabs\Library */ class Protect { static $protect_start = '<!-- ___RL_PROTECTED___'; static $protect_end = '___RL_PROTECTED___ -->'; static $protect_tags_start = '<!-- ___RL_PROTECTED_TAGS___'; static $protect_tags_end = '___RL_PROTECTED_TAGS___ -->'; static $html_safe_start = '___RL_PROTECTED___'; static $html_safe_end = '___/RL_PROTECTED___'; static $html_safe_tags_start = '___RL_PROTECTED_TAGS___'; static $html_safe_tags_end = '___/RL_PROTECTED_TAGS___'; static $sourcerer_tag = null; static $sourcerer_characters = '{.}'; /** * Check if page should be protected for given extension * * @param string $extension_alias * * @return bool */ public static function isDisabledByUrl($extension_alias = '') { // return if disabled via url if (($extension_alias && JFactory::getApplication()->input->get('disable_' . $extension_alias))) { return true; } } /** * Check if page should be protected for given extension * * @param bool $hastags * @param array $restricted_formats * * @return bool */ public static function isRestrictedPage($hastags = false, $restricted_formats = []) { $cache_id = 'isRestrictedPage_' . $hastags . '_' . json_encode($restricted_formats); if (Cache::has($cache_id)) { return Cache::get($cache_id); } $input = JFactory::getApplication()->input; // return if current page is in protected formats // return if current page is an image // return if current page is an installation page // return if current page is Regular Labs QuickPage // return if current page is a JoomFish or Josetta page $is_restricted = ( in_array($input->get('format'), $restricted_formats) // || in_array($input->get('view'), ['image', 'img']) || in_array($input->get('type'), ['image', 'img']) || in_array($input->get('task'), ['install.install', 'install.ajax_upload']) || ($hastags && $input->getInt('rl_qp', 0)) || ($hastags && in_array($input->get('option'), ['com_joomfishplus', 'com_josetta'])) || (Document::isClient('administrator') && in_array($input->get('option'), ['com_jdownloads'])) ); return Cache::set( $cache_id, $is_restricted ); } /** * @deprecated Use isDisabledByUrl() and isRestrictedPage() */ public static function isProtectedPage($extension_alias = '', $hastags = false, $exclude_formats = []) { if (self::isDisabledByUrl($extension_alias)) { return true; } return self::isRestrictedPage($hastags, $exclude_formats); } /** * Check if the page is a restricted component * * @param array $restricted_components * @param string $area * * @return bool */ public static function isRestrictedComponent($restricted_components, $area = 'component') { if ($area != 'component' && ! ($area == 'article' && JFactory::getApplication()->input->get('option') == 'com_content')) { return false; } $restricted_components = ArrayHelper::toArray(str_replace('|', ',', $restricted_components)); $restricted_components = ArrayHelper::clean($restricted_components); if ( ! empty($restricted_components) && in_array(JFactory::getApplication()->input->get('option'), $restricted_components)) { return true; } if (JFactory::getApplication()->input->get('option') == 'com_acymailing' && ! in_array(JFactory::getApplication()->input->get('ctrl'), ['user', 'archive']) && ! in_array(JFactory::getApplication()->input->get('view'), ['user', 'archive']) ) { return true; } return false; } /** * Check if the component is installed * * @param string $extension_alias * * @return bool */ public static function isComponentInstalled($extension_alias) { return file_exists(JPATH_ADMINISTRATOR . '/components/com_' . $extension_alias . '/' . $extension_alias . '.php'); } /** * Check if the component is installed * * @param string $extension_alias * * @return bool */ public static function isSystemPluginInstalled($extension_alias) { return file_exists(JPATH_PLUGINS . '/system/' . $extension_alias . '/' . $extension_alias . '.php'); } /** * Return the Regular Expressions string to match: * The edit form * * @param array $form_classes * * @return string */ public static function getFormRegex($form_classes = []) { $form_classes = ArrayHelper::toArray($form_classes); return '(<form\s[^>]*(' . '(id|name)="(adminForm|postform|submissionForm|default_action_user|seblod_form|spEntryForm)"' . '|action="[^"]*option=com_myjspace&(amp;)?view=see"' . (! empty($form_classes) ? '|class="([^"]* )?(' . implode('|', $form_classes) . ')( [^"]*)?"' : '') . '))'; } /** * Protect all text based form fields * * @param string $string * @param array $search_strings */ public static function protectFields(&$string, $search_strings = []) { // No specified strings tags found in the string if ( ! self::containsStringsToProtect($string, $search_strings)) { return; } $parts = StringHelper::split($string, ['</label>', '</select>']); foreach ($parts as &$part) { if ( ! self::containsStringsToProtect($part, $search_strings)) { continue; } self::protectFieldsPart($part); } $string = implode('', $parts); } /** * Check if the string contains certain substrings to protect * * @param string $string * @param array $search_strings * * @return bool */ private static function containsStringsToProtect($string, $search_strings = []) { if ( empty($string) || ( strpos($string, '<input') === false && strpos($string, '<textarea') === false && strpos($string, '<select') === false ) ) { return false; } // No specified strings tags found in the string if ( ! empty($search_strings) && ! StringHelper::contains($string, $search_strings)) { return false; } return true; } /** * Protect the fields in the string * * @param string $string */ private static function protectFieldsPart(&$string) { self::protectFieldsTextAreas($string); self::protectFieldsInputFields($string); } /** * Protect the textarea fields in the string * * @param string $string */ private static function protectFieldsTextAreas(&$string) { if (strpos($string, '<textarea') === false) { return; } // Only replace non-empty textareas // Todo: maybe also prevent empty textareas but with a non-empty placeholder attribute // Temporarily replace empty textareas $temp_tag = '___TEMP_TEXTAREA___'; $string = RegEx::replace( '<textarea((?:\s[^>]*)?)>(\s*)</textarea>', '<' . $temp_tag . '\1>\2</' . $temp_tag . '>', $string ); self::protectByRegex( $string, '(?:' . '<textarea.*?</textarea>' . '\s*)+' ); // Replace back the temporarily replaced empty textareas $string = str_replace($temp_tag, 'textarea', $string); } /** * Protect the input fields in the string * * @param string $string */ private static function protectFieldsInputFields(&$string) { if (strpos($string, '<input') === false) { return; } $type_values = '(?:text|email|hidden)'; // must be of certain type $param_type = '\s+type\s*=\s*(?:"' . $type_values . '"|\'' . $type_values . '\'])'; // must have a non-empty value or placeholder attribute $param_value = '\s+(?:value|placeholder)\s*=\s*(?:"[^"]+"|\'[^\']+\'])'; // Regex to match any other parameter $params = '(?:\s+[a-z][a-z0-9-_]*(?:\s*=\s*(?:"[^"]*"|\'[^\']*\'|[0-9]+))?)*'; self::protectByRegex( $string, '(?:(?:' . '<input' . $params . $param_type . $params . $param_value . $params . '\s*/?>' . '|<input' . $params . $param_value . $params . $param_type . $params . '\s*/?>' . ')\s*)+' ); } /** * Protect the script tags * * @param string $string */ public static function protectScripts(&$string) { if (strpos($string, '</script>') === false) { return; } self::protectByRegex( $string, '<script[\s>].*?</script>' ); } /** * Protect all html tags with some type of attributes/content * * @param string $string */ public static function protectHtmlTags(&$string) { // protect comment tags self::protectHtmlCommentTags($string); // protect html tags self::protectByRegex($string, '<[a-z][^>]*(?:="[^"]*"|=\'[^\']*\')+[^>]*>'); } /** * Protect all html comment tags * * @param string $string */ public static function protectHtmlCommentTags(&$string) { // protect comment tags self::protectByRegex($string, '<\!--.*?-->'); } /** * Protect text by given regex * * @param string $string * @param string $regex */ public static function protectByRegex(&$string, $regex) { RegEx::matchAll($regex, $string, $matches, null, PREG_PATTERN_ORDER); if (empty($matches)) { return; } $matches = array_unique($matches[0]); $replacements = []; foreach ($matches as $match) { $replacements[] = self::protectString($match); } $string = str_replace($matches, $replacements, $string); } /** * Protect given plugin style tags * * @param string $string * @param array $tags * @param bool $include_closing_tags */ public static function protectTags(&$string, $tags = [], $include_closing_tags = true) { list($tags, $protected) = self::prepareTags($tags, $include_closing_tags); $string = str_replace($tags, $protected, $string); } /** * Replace any protected tags to original * * @param string $string * @param array $tags * @param bool $include_closing_tags */ public static function unprotectTags(&$string, $tags = [], $include_closing_tags = true) { list($tags, $protected) = self::prepareTags($tags, $include_closing_tags); $string = str_replace($protected, $tags, $string); } /** * Protect array of strings * * @param string $string * @param array $unprotected * @param array $protected */ public static function protectInString(&$string, $unprotected = [], $protected = []) { $protected = empty($protected) ? self::protectArray($unprotected) : $protected; $string = str_replace($unprotected, $protected, $string); } /** * Replace any protected tags to original * * @param string $string * @param array $unprotected * @param array $protected */ public static function unprotectInString(&$string, $unprotected = [], $protected = []) { $protected = empty($protected) ? self::protectArray($unprotected) : $protected; $string = str_replace($protected, $unprotected, $string); } /** * Return the sourcerer tag name and characters * * @return array */ public static function getSourcererTag() { if ( ! is_null(self::$sourcerer_tag)) { return [self::$sourcerer_tag, self::$sourcerer_characters]; } $parameters = Parameters::getInstance()->getPluginParams('sourcerer'); self::$sourcerer_tag = isset($parameters->syntax_word) ? $parameters->syntax_word : ''; self::$sourcerer_characters = isset($parameters->tag_characters) ? $parameters->tag_characters : '{.}'; return [self::$sourcerer_tag, self::$sourcerer_characters]; } /** * Protect all Sourcerer blocks * * @param string $string */ public static function protectSourcerer(&$string) { list($tag, $characters) = self::getSourcererTag(); if (empty($tag)) { return; } list($start, $end) = explode('.', $characters); if (strpos($string, $start . '/' . $tag . $end) === false) { return; } $regex = RegEx::quote($start . $tag) . '[\s\}].*?' . RegEx::quote($start . '/' . $tag . $end); RegEx::matchAll($regex, $string, $matches, null, PREG_PATTERN_ORDER); if (empty($matches)) { return; } $matches = array_unique($matches[0]); foreach ($matches as $match) { $string = str_replace($match, self::protectString($match), $string); } } /** * Protect complete AdminForm * * @param string $string * @param array $tags * @param bool $include_closing_tags */ public static function protectForm(&$string, $tags = [], $include_closing_tags = true, $form_classes = []) { if ( ! Document::isEditPage()) { return; } list($tags, $protected_tags) = self::prepareTags($tags, $include_closing_tags); $string = RegEx::replace(self::getFormRegex($form_classes), '<!-- TMP_START_EDITOR -->\1', $string); $string = explode('<!-- TMP_START_EDITOR -->', $string); foreach ($string as $i => &$string_part) { if (empty($string_part) || ! fmod($i, 2)) { continue; } self::protectFormPart($string_part, $tags, $protected_tags); } $string = implode('', $string); } /** * Protect part of the AdminForm * * @param string $string * @param array $tags * @param array $protected_tags */ private static function protectFormPart(&$string, $tags = [], $protected_tags = []) { if (strpos($string, '</form>') === false) { return; } // Protect entire form if (empty($tags)) { $form_parts = explode('</form>', $string, 2); $form_parts[0] = self::protectString($form_parts[0] . '</form>'); $string = implode('', $form_parts); return; } $regex_tags = RegEx::quote($tags); if ( ! RegEx::match($regex_tags, $string)) { return; } $form_parts = explode('</form>', $string, 2); // protect tags only inside form fields RegEx::matchAll( '(?:<textarea[^>]*>.*?<\/textarea>|<input[^>]*>)', $form_parts[0], $matches, null, PREG_PATTERN_ORDER ); if (empty($matches)) { return; } $matches = array_unique($matches[0]); foreach ($matches as $match) { $field = str_replace($tags, $protected_tags, $match); $form_parts[0] = str_replace($match, $field, $form_parts[0]); } $string = implode('</form>', $form_parts); } /** * Replace any protected text to original * * @param string|array $string */ public static function unprotect(&$string) { if (is_array($string)) { foreach ($string as &$part) { self::unprotect($part); } return; } self::unprotectByDelimiters( $string, [self::$protect_tags_start, self::$protect_tags_end] ); self::unprotectByDelimiters( $string, [self::$protect_start, self::$protect_end] ); if (StringHelper::contains($string, [self::$protect_tags_start, self::$protect_tags_end, self::$protect_start, self::$protect_end])) { self::unprotect($string); } } /** * @param string $string * @param array $delimiters */ private static function unprotectByDelimiters(&$string, $delimiters) { if ( ! StringHelper::contains($string, $delimiters)) { return; } $regex = RegEx::preparePattern(RegEx::quote($delimiters), 's', $string); $parts = preg_split($regex, $string); foreach ($parts as $i => &$part) { if ($i % 2 == 0) { continue; } $part = base64_decode($part); } $string = implode('', $parts); } /** * Replace any protected text to original * * @param string $string */ public static function convertProtectionToHtmlSafe(&$string) { $string = str_replace( [ self::$protect_start, self::$protect_end, self::$protect_tags_start, self::$protect_tags_end, ], [ self::$html_safe_start, self::$html_safe_end, self::$html_safe_tags_start, self::$html_safe_tags_end, ], $string ); } /** * Replace any protected text to original * * @param string $string */ public static function unprotectHtmlSafe(&$string) { $string = str_replace( [ self::$html_safe_start, self::$html_safe_end, self::$html_safe_tags_start, self::$html_safe_tags_end, ], [ self::$protect_start, self::$protect_end, self::$protect_tags_start, self::$protect_tags_end, ], $string ); self::unprotect($string); } /** * Prepare the tags and protected tags array * * @param array $tags * @param bool $include_closing_tags * * @return bool|mixed */ private static function prepareTags($tags, $include_closing_tags = true) { if ( ! is_array($tags)) { $tags = [$tags]; } $cache_id = 'prepareTags_' . json_encode($tags) . '_' . $include_closing_tags; if (Cache::has($cache_id)) { return Cache::get($cache_id); } foreach ($tags as $i => $tag) { if (StringHelper::is_alphanumeric($tag[0])) { $tag = '{' . $tag; } $tags[$i] = $tag; if ($include_closing_tags) { $tags[] = RegEx::replace('^([^a-z0-9]+)', '\1/', $tag); } } return Cache::set( $cache_id, [$tags, self::protectArray($tags, 1)] ); } /** * Encode string * * @param string $string * @param int $is_tag * * @return string */ public static function protectString($string, $is_tag = false) { if ($is_tag) { return self::$protect_tags_start . base64_encode($string) . self::$protect_tags_end; } return self::$protect_start . base64_encode($string) . self::$protect_end; } /** * Decode string * * @param string $string * @param int $is_tag * * @return string */ public static function unprotectString($string, $is_tag = false) { if ($is_tag) { return self::$protect_tags_start . base64_decode($string) . self::$protect_tags_end; } return self::$protect_start . base64_decode($string) . self::$protect_end; } /** * Encode tag string * * @param string $string * * @return string */ public static function protectTag($string) { return self::protectString($string, 1); } /** * Encode array of strings * * @param array $array * @param int $is_tag * * @return mixed */ public static function protectArray($array, $is_tag = false) { foreach ($array as &$string) { $string = self::protectString($string, $is_tag); } return $array; } /** * Decode array of strings * * @param array $array * @param int $is_tag * * @return mixed */ public static function unprotectArray($array, $is_tag = false) { foreach ($array as &$string) { $string = self::unprotectString($string, $is_tag); } return $array; } /** * Replace any protected tags to original * * @param string $string * @param array $tags */ public static function unprotectForm(&$string, $tags = []) { // Protect entire form if (empty($tags)) { self::unprotect($string); return; } self::unprotectTags($string, $tags); } /** * Wrap string in comment tags * * @param string $name * @param string $comment * * @return string */ public static function wrapInCommentTags($name, $string) { list($start, $end) = self::getCommentTags($name); return $start . $string . $end; } /** * Get the html comment tags * * @param string $name * * @return array */ public static function getCommentTags($name = '') { return [self::getCommentStartTag($name), self::getCommentEndTag($name)]; } /** * Get the html start comment tags * * @param string $name * * @return string */ public static function getCommentStartTag($name = '') { return '<!-- START: ' . $name . ' -->'; } /** * Get the html end comment tags * * @param string $name * * @return string */ public static function getCommentEndTag($name = '') { return '<!-- END: ' . $name . ' -->'; } /** * Create a html comment from given comment string * * @param string $name * @param string $comment * * @return string */ public static function getMessageCommentTag($name, $comment) { list($start, $end) = self::getMessageCommentTags($name); return $start . $comment . $end; } /** * Get the start and end parts for the html message comment tag * * @param string $name * * @return array */ public static function getMessageCommentTags($name = '') { return ['<!-- ' . $name . ' Message: ', ' -->']; } /** * Get the start and end parts for the inline comment tags for scripts/styles * * @param string $name * @param string $type * * @return array */ public static function getInlineCommentTags($name = '', $type = '', $regex = false) { if ($regex) { $type = 'TYPE_PLACEHOLDER'; } $start = '/* START: ' . $name . ' ' . $type . ' */'; $end = '/* END: ' . $name . ' ' . $type . ' */'; if ($regex) { $start = str_replace($type, '[a-z]*', RegEx::quote($start)); $end = str_replace($type, '[a-z]*', RegEx::quote($end)); } return [$start, $end]; } /** * Wraps a style or javascript declaration with comment tags * * @param string $content * @param string $name * @param string $type * @param bool $minify */ public static function wrapDeclaration($content = '', $name = '', $type = 'styles', $minify = true) { if (empty($name)) { return $content; } list($start, $end) = self::getInlineCommentTags($name, $type); $spacer = $minify ? ' ' : "\n"; return $start . $spacer . $content . $spacer . $end; } /** * Wraps a javascript declaration with comment tags * * @param string $content * @param string $name * @param bool $minify */ public static function wrapScriptDeclaration($content = '', $name = '', $minify = true) { return self::wrapDeclaration($content, $name, 'scripts', $minify); } /** * Wraps a stylesheet declaration with comment tags * * @param string $content * @param string $name * @param bool $minify */ public static function wrapStyleDeclaration($content = '', $name = '', $minify = true) { return self::wrapDeclaration($content, $name, 'styles', $minify); } /** * Remove area comments in html * * @param string $string * @param string $prefix */ public static function removeAreaTags(&$string, $prefix = '') { $string = RegEx::replace('<!-- (START|END): ' . $prefix . '_[A-Z]+ -->', '', $string, 's'); } /** * Remove comments in html * * @param string $string * @param string $name */ public static function removeCommentTags(&$string, $name = '') { list($start, $end) = self::getCommentTags($name); $string = str_replace( [ $start, $end, htmlentities($start), htmlentities($end), urlencode($start), urlencode($end), ], '', $string ); list($start, $end) = self::getMessageCommentTags($name); $string = RegEx::replace( RegEx::quote($start) . '.*?' . RegEx::quote($end), '', $string ); } /** * Remove inline comments in scrips and styles * * @param string $string * @param string $name */ public static function removeInlineComments(&$string, $name) { list($start, $end) = Protect::getInlineCommentTags($name, null, true); $string = RegEx::replace('(' . $start . '|' . $end . ')', "\n", $string); } /** * Remove left over plugin tags * * @param string $string * @param array $tags * @param string $character_start * @param string $character_end * @param bool $keep_content */ public static function removePluginTags(&$string, $tags, $character_start = '{', $character_end = '}', $keep_content = true) { $regex_character_start = RegEx::quote($character_start); $regex_character_end = RegEx::quote($character_end); foreach ($tags as $tag) { if ( ! is_array($tag)) { $tag = [$tag, $tag]; } if (count($tag) < 2) { $tag = [$tag[0], $tag[0]]; } if ( ! StringHelper::contains($string, $character_start . '/' . $tag[1] . $character_end)) { continue; } $regex = $regex_character_start . RegEx::quote($tag[0]) . '(?:\s.*?)?' . $regex_character_end . '(.*?)' . $regex_character_start . '/' . RegEx::quote($tag[1]) . $regex_character_end; $replace = $keep_content ? '\1' : ''; $string = RegEx::replace($regex, $replace, $string); } } /** * Remove tags from title tags * * @param string $string * @param array $tags * @param bool $include_closing_tags * @param array $html_tags */ public static function removeFromHtmlTagContent(&$string, $tags, $include_closing_tags = true, $html_tags = ['title']) { list($tags, $protected) = self::prepareTags($tags, $include_closing_tags); if ( ! is_array($html_tags)) { $html_tags = [$html_tags]; } RegEx::matchAll('(<(' . implode('|', $html_tags) . ')(?:\s[^>]*?)>)(.*?)(</\2>)', $string, $matches); if (empty($matches)) { return; } foreach ($matches as $match) { $content = $match[3]; foreach ($tags as $tag) { $content = RegEx::replace(RegEx::quote($tag) . '.*?\}', '', $content); } $string = str_replace($match[0], $match[1] . $content . $match[4], $string); } } /** * Remove tags from tag attributes * * @param string $string * @param array $tags * @param string $attributes * @param bool $include_closing_tags */ public static function removeFromHtmlTagAttributes(&$string, $tags, $attributes = 'ALL', $include_closing_tags = true) { list($tags, $protected) = self::prepareTags($tags, $include_closing_tags); if ($attributes == 'ALL') { $attributes = ['[a-z][a-z0-9-_]*']; } if ( ! is_array($attributes)) { $attributes = [$attributes]; } RegEx::matchAll( '\s(?:' . implode('|', $attributes) . ')\s*=\s*".*?"', $string, $matches, null, PREG_PATTERN_ORDER ); if (empty($matches) || empty($matches[0])) { return; } $matches = array_unique($matches[0]); // preg_quote all tags $tags_regex = RegEx::quote($tags) . '.*?\}'; foreach ($matches as $match) { if ( ! StringHelper::contains($match, $tags)) { continue; } $title = $match; $title = RegEx::replace($tags_regex, '', $title); $string = StringHelper::replaceOnce($match, $title, $string); } } /** * Check if article passes security levels * * @param object $article * @param array $securtiy_levels * * @return bool|int */ public static function articlePassesSecurity(&$article, $securtiy_levels = []) { if ( ! isset($article->created_by)) { return true; } if (empty($securtiy_levels)) { return true; } if (is_string($securtiy_levels)) { $securtiy_levels = [$securtiy_levels]; } if ( ! is_array($securtiy_levels) || in_array('-1', $securtiy_levels) ) { return true; } // Lookup group level of creator $user_groups = new JAccess; $user_groups = $user_groups->getGroupsByUser($article->created_by); // Return true if any of the security levels are found in the users groups return count(array_intersect($user_groups, $securtiy_levels)); } /** * Replace in protect array * * @param array $array * @param string $search * @param string $replacement */ public static function replaceInArray(&$array, $search, $replacement) { foreach ($array as $key => &$string) { // only do something if string is not empty // or on uneven count = not yet protected if (trim($string) == '' || fmod($key, 2)) { continue; } $array[$key] = str_replace($search, $replacement, $string); } } /** * Replace in protect array using Regular Expressions * * @param array $array * @param string $search * @param string $replacement */ public static function pregReplaceInArray(&$array, $search, $replacement) { foreach ($array as $key => &$string) { // only do something if string is not empty // or on uneven count = not yet protected if (trim($string) == '' || fmod($key, 2)) { continue; } $array[$key] = RegEx::replace($search, $replacement, $string); } } } Extension.php 0000604 00000033215 15245535751 0007245 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper as JComponentHelper; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Filesystem\Folder as JFolder; use Joomla\CMS\Helper\ModuleHelper as JModuleHelper; use Joomla\CMS\Installer\Installer as JInstaller; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Plugin\PluginHelper as JPluginHelper; jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); /** * Class Extension * @package RegularLabs\Library */ class Extension { /** * Get the full path to the extension folder * * @param string $extension * @param string $basePath * @param string $check_folder * * @return string */ public static function getPath($extension = 'plg_system_regularlabs', $basePath = JPATH_ADMINISTRATOR, $check_folder = '') { $basePath = $basePath ?: JPATH_SITE; if ( ! in_array($basePath, [JPATH_ADMINISTRATOR, JPATH_SITE])) { return $basePath; } $extension = str_replace('.sys', '', $extension); switch (true) { case (strpos($extension, 'mod_') === 0): $path = 'modules/' . $extension; break; case (strpos($extension, 'plg_') === 0): list($prefix, $folder, $name) = explode('_', $extension, 3); $path = 'plugins/' . $folder . '/' . $name; break; case (strpos($extension, 'com_') === 0): default: $path = 'components/' . $extension; break; } $check_folder = $check_folder ? '/' . $check_folder : ''; if (is_dir($basePath . '/' . $path . $check_folder)) { return $basePath . '/' . $path; } if (is_dir(JPATH_ADMINISTRATOR . '/' . $path . $check_folder)) { return JPATH_ADMINISTRATOR . '/' . $path; } if (is_dir(JPATH_SITE . '/' . $path . $check_folder)) { return JPATH_SITE . '/' . $path; } return $basePath; } /** * Check if all extension types of a given extension are installed * * @param string $extension * @param array $types * * @return bool */ public static function areInstalled($extension, $types = ['plugin']) { foreach ($types as $type) { $folder = 'system'; if (is_array($type)) { list($type, $folder) = $type; } if ( ! self::isInstalled($extension, $type, $folder)) { return false; } } return true; } /** * Check if the given extension is installed * * @param string $extension * @param string $type * @param string $folder * * @return bool */ public static function isInstalled($extension, $type = 'component', $folder = 'system') { $extension = strtolower($extension); switch ($type) { case 'component': if (file_exists(JPATH_ADMINISTRATOR . '/components/com_' . $extension . '/' . $extension . '.php') || file_exists(JPATH_ADMINISTRATOR . '/components/com_' . $extension . '/admin.' . $extension . '.php') || file_exists(JPATH_SITE . '/components/com_' . $extension . '/' . $extension . '.php') ) { if ($extension == 'cookieconfirm' && file_exists(JPATH_ADMINISTRATOR . '/components/com_cookieconfirm/version.php')) { // Only Cookie Confirm 2.0.0.rc1 and above is supported, because // previous versions don't have isCookiesAllowed() require_once JPATH_ADMINISTRATOR . '/components/com_cookieconfirm/version.php'; if (version_compare(COOKIECONFIRM_VERSION, '2.2.0.rc1', '<')) { return false; } } return true; } break; case 'plugin': return file_exists(JPATH_PLUGINS . '/' . $folder . '/' . $extension . '/' . $extension . '.php'); case 'module': return (file_exists(JPATH_ADMINISTRATOR . '/modules/mod_' . $extension . '/' . $extension . '.php') || file_exists(JPATH_ADMINISTRATOR . '/modules/mod_' . $extension . '/mod_' . $extension . '.php') || file_exists(JPATH_SITE . '/modules/mod_' . $extension . '/' . $extension . '.php') || file_exists(JPATH_SITE . '/modules/mod_' . $extension . '/mod_' . $extension . '.php') ); case 'library': return JFolder::exists(JPATH_LIBRARIES . '/' . $extension); } return false; } /** * Check if the Regular Labs Library is enabled * * @return bool */ public static function isEnabled($extension, $type = 'component', $folder = 'system') { $extension = strtolower($extension); if ( ! self::isInstalled($extension, $type, $folder)) { return false; } switch ($type) { case 'component': return JComponentHelper::isEnabled($extension); case 'plugin': return JPluginHelper::isEnabled($folder, $extension); case 'module': return JModuleHelper::isEnabled($extension); } return false; } /** * Check if the Regular Labs Library is enabled * * @return bool */ public static function isFrameworkEnabled() { return JPluginHelper::isEnabled('system', 'regularlabs'); } /** * Return an alias and element name based on the given extension name * * @param string $name * * @return array */ public static function getAliasAndElement(&$name) { $name = self::getNameByAlias($name); $alias = self::getAliasByName($name); $element = self::getElementByAlias($alias); return [$alias, $element]; } /** * Return the name based on the given extension alias * * @param string $alias * * @return string */ public static function getNameByAlias($alias) { // Alias is a language string if (strpos($alias, ' ') === false && strtoupper($alias) == $alias) { return JText::_($alias); } // Alias has a space and/or capitals, so is already a name if (strpos($alias, ' ') !== false || $alias !== strtolower($alias)) { return $alias; } return JText::_(self::getXMLValue('name', $alias)); } /** * Return an alias based on the given extension name * * @param string $name * * @return string */ public static function getAliasByName($name) { $alias = RegEx::replace('[^a-z0-9]', '', strtolower($name)); switch ($alias) { case 'advancedmodules': return 'advancedmodulemanager'; case 'advancedtemplates': return 'advancedtemplatemanager'; case 'nonumbermanager': return 'nonumberextensionmanager'; case 'what-nothing': return 'whatnothing'; } return $alias; } /** * Return an element name based on the given extension alias * * @param string $alias * * @return string */ public static function getElementByAlias($alias) { $alias = self::getAliasByName($alias); switch ($alias) { case 'advancedmodulemanager': return 'advancedmodules'; case 'advancedtemplatemanager': return 'advancedtemplates'; case 'nonumberextensionmanager': return 'nonumbermanager'; } return $alias; } /** * Return a value from an extensions main xml file based on the given key * * @param string $key * @param string $alias * @param string $type * @param string $folder * * @return string */ public static function getXMLValue($key, $alias, $type = '', $folder = '') { if ( ! $xml = self::getXML($alias, $type, $folder)) { return ''; } if ( ! isset($xml[$key])) { return ''; } return isset($xml[$key]) ? $xml[$key] : ''; } /** * Return an extensions main xml array * * @param string $alias * @param string $type * @param string $folder * * @return array|bool */ public static function getXML($alias, $type = '', $folder = '') { if ( ! $file = self::getXMLFile($alias, $type, $folder)) { return false; } return JInstaller::parseXMLInstallFile($file); } /** * Return an extensions main xml file name (including path) * * @param string $alias * @param string $type * @param string $folder * * @return string */ public static function getXMLFile($alias, $type = '', $folder = '') { $element = self::getElementByAlias($alias); $files = []; // Components if (empty($type) || $type == 'component') { $files[] = JPATH_ADMINISTRATOR . '/components/com_' . $element . '/' . $element . '.xml'; $files[] = JPATH_SITE . '/components/com_' . $element . '/' . $element . '.xml'; $files[] = JPATH_ADMINISTRATOR . '/components/com_' . $element . '/com_' . $element . '.xml'; $files[] = JPATH_SITE . '/components/com_' . $element . '/com_' . $element . '.xml'; } // Plugins if (empty($type) || $type == 'plugin') { if ( ! empty($folder)) { $files[] = JPATH_PLUGINS . '/' . $folder . '/' . $element . '/' . $element . '.xml'; } // System Plugins $files[] = JPATH_PLUGINS . '/system/' . $element . '/' . $element . '.xml'; // Editor Button Plugins $files[] = JPATH_PLUGINS . '/editors-xtd/' . $element . '/' . $element . '.xml'; // Field Plugins $field_name = RegEx::replace('field$', '', $element); $files[] = JPATH_PLUGINS . '/fields/' . $field_name . '/' . $field_name . '.xml'; } // Modules if (empty($type) || $type == 'module') { $files[] = JPATH_ADMINISTRATOR . '/modules/mod_' . $element . '/' . $element . '.xml'; $files[] = JPATH_SITE . '/modules/mod_' . $element . '/' . $element . '.xml'; $files[] = JPATH_ADMINISTRATOR . '/modules/mod_' . $element . '/mod_' . $element . '.xml'; $files[] = JPATH_SITE . '/modules/mod_' . $element . '/mod_' . $element . '.xml'; } foreach ($files as $file) { if ( ! file_exists($file)) { continue; } return $file; } return ''; } public static function isAuthorised($require_core_auth = true) { $user = JFactory::getUser(); if ($user->get('guest')) { return false; } if ( ! $require_core_auth) { return true; } if ( ! $user->authorise('core.edit', 'com_content') && ! $user->authorise('core.edit.own', 'com_content') && ! $user->authorise('core.create', 'com_content') ) { return false; } return true; } public static function isEnabledInArea($params) { if ( ! isset($params->enable_frontend)) { return true; } // Only allow in frontend if ($params->enable_frontend == 2 && Document::isClient('administrator')) { return false; } // Do not allow in frontend if ( ! $params->enable_frontend && Document::isClient('site')) { return false; } return true; } public static function isEnabledInComponent($params) { if ( ! isset($params->disabled_components)) { return true; } return ! Protect::isRestrictedComponent($params->disabled_components); } public static function getById($id) { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select($db->quoteName(['extension_id', 'manifest_cache'])) ->from($db->quoteName('#__extensions')) ->where($db->quoteName('extension_id') . ' = ' . (int) $id); $db->setQuery($query); return $db->loadObject(); } public static function disable($alias, $type = 'plugin', $folder = 'system') { $element = self::getElementByAlias($alias); switch ($type) { case 'module': $element = 'mod_' . $element; break; case 'component': $element = 'com_' . $element; break; } $db = JFactory::getDbo(); $query = $db->getQuery(true) ->update($db->quoteName('#__extensions')) ->set($db->quoteName('enabled') . ' = 0') ->where($db->quoteName('element') . ' = ' . $db->quote($element)) ->where($db->quoteName('type') . ' = ' . $db->quote($type)); if ($type == 'plugin') { $query->where($db->quoteName('folder') . ' = ' . $db->quote($folder)); } $db->setQuery($query); $db->execute(); } public static function orderPluginFirst($name, $folder = 'system') { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select(['e.ordering']) ->from($db->quoteName('#__extensions', 'e')) ->where('e.type = ' . $db->quote('plugin')) ->where('e.folder = ' . $db->quote($folder)) ->where('e.element = ' . $db->quote($name)); $db->setQuery($query); $current_ordering = $db->loadResult(); if ($current_ordering == '') { return; } $query = $db->getQuery(true) ->select('e.ordering') ->from($db->quoteName('#__extensions', 'e')) ->where('e.type = ' . $db->quote('plugin')) ->where('e.folder = ' . $db->quote($folder)) ->where('e.manifest_cache LIKE ' . $db->quote('%"author":"Regular Labs%')) ->where('e.element != ' . $db->quote($name)) ->order('e.ordering ASC'); $db->setQuery($query); $min_ordering = $db->loadResult(); if ($min_ordering == '') { return; } if ($current_ordering < $min_ordering) { return; } if ($min_ordering < 1 || $current_ordering == $min_ordering) { $new_ordering = max($min_ordering, 1); $query = $db->getQuery(true) ->update($db->quoteName('#__extensions')) ->set($db->quoteName('ordering') . ' = ' . $new_ordering) ->where($db->quoteName('ordering') . ' = ' . $min_ordering) ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) ->where($db->quoteName('folder') . ' = ' . $db->quote($folder)) ->where($db->quoteName('element') . ' != ' . $db->quote($name)) ->where($db->quoteName('manifest_cache') . ' LIKE ' . $db->quote('%"author":"Regular Labs%')); $db->setQuery($query); $db->execute(); $min_ordering = $new_ordering; } if ($current_ordering == $min_ordering) { return; } $new_ordering = $min_ordering - 1; $query = $db->getQuery(true) ->update($db->quoteName('#__extensions')) ->set($db->quoteName('ordering') . ' = ' . $new_ordering) ->where($db->quoteName('type') . ' = ' . $db->quote('plugin')) ->where($db->quoteName('folder') . ' = ' . $db->quote($folder)) ->where($db->quoteName('element') . ' = ' . $db->quote($name)); $db->setQuery($query); $db->execute(); } } Article.php 0000604 00000022026 15245535751 0006652 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\Registry\Registry; jimport('joomla.filesystem.file'); /** * Class Article * @package RegularLabs\Library */ class Article { static $articles = []; /** * Method to get article data. * * @param integer $id The id, alias or title of the article. * @param boolean $get_unpublished Whether to also return the article if it is not published * @param array $selects Option array of stuff to select. Note: requires correct table alias prefixes * * @return object|boolean Menu item data object on success, boolean false */ public static function get($id = null, $get_unpublished = false, $selects = []) { $id = ! empty($id) ? $id : (int) self::getId(); $cache_id = md5(json_encode([$id, $get_unpublished, $selects])); if (isset(self::$articles[$cache_id])) { return self::$articles[$cache_id]; } $db = JFactory::getDbo(); $user = JFactory::getUser(); $custom_selects = ! empty($selects); $query = $db->getQuery(true) ->select($custom_selects ? $selects : [ 'a.id', 'a.asset_id', 'a.title', 'a.alias', 'a.introtext', 'a.fulltext', 'a.state', 'a.catid', 'a.created', 'a.created_by', 'a.created_by_alias', // Use created if modified is 0 'CASE WHEN a.modified = ' . $db->quote($db->getNullDate()) . ' THEN a.created ELSE a.modified END as modified', 'a.modified_by', 'a.checked_out', 'a.checked_out_time', 'a.publish_up', 'a.publish_down', 'a.images', 'a.urls', 'a.attribs', 'a.version', 'a.ordering', 'a.metakey', 'a.metadesc', 'a.access', 'a.hits', 'a.metadata', 'a.featured', 'a.language', 'a.xreference', ] ) ->from($db->quoteName('#__content', 'a')); if ( ! is_numeric($id)) { $query->where('(' . $db->quoteName('a.title') . ' = ' . $db->quote($id) . ' OR ' . $db->quoteName('a.alias') . ' = ' . $db->quote($id) . ')'); } else { $query->where($db->quoteName('a.id') . ' = ' . (int) $id); } // Join on category table. if ( ! $custom_selects) { $query->select([ $db->quoteName('c.title', 'category_title'), $db->quoteName('c.alias', 'category_alias'), $db->quoteName('c.access', 'category_access'), $db->quoteName('c.lft', 'category_lft'), $db->quoteName('c.lft', 'category_ordering'), ]); } $query->innerJoin($db->quoteName('#__categories', 'c') . ' ON ' . $db->quoteName('c.id') . ' = ' . $db->quoteName('a.catid')) ->where($db->quoteName('c.published') . ' > 0'); // Join on user table. if ( ! $custom_selects) { $query->select($db->quoteName('u.name', 'author')); } $query->join('LEFT', $db->quoteName('#__users', 'u') . ' ON ' . $db->quoteName('u.id') . ' = ' . $db->quoteName('a.created_by')); // Join over the categories to get parent category titles if ( ! $custom_selects) { $query->select([ $db->quoteName('parent.title', 'parent_title'), $db->quoteName('parent.id', 'parent_id'), $db->quoteName('parent.path', 'parent_route'), $db->quoteName('parent.alias', 'parent_alias'), ]); } $query->join('LEFT', $db->quoteName('#__categories', 'parent') . ' ON ' . $db->quoteName('parent.id') . ' = ' . $db->quoteName('c.parent_id')); // Join on voting table if ( ! $custom_selects) { $query->select([ 'ROUND(v.rating_sum / v.rating_count, 0) AS rating', $db->quoteName('v.rating_count', 'rating_count'), ]); } $query->join('LEFT', $db->quoteName('#__content_rating', 'v') . ' ON ' . $db->quoteName('v.content_id') . ' = ' . $db->quoteName('a.id')); if ( ! $get_unpublished && ( ! $user->authorise('core.edit.state', 'com_content')) && ( ! $user->authorise('core.edit', 'com_content')) ) { // Filter by start and end dates. $nullDate = $db->quote($db->getNullDate()); $date = JFactory::getDate(); $nowDate = $db->quote($date->toSql()); $query->where($db->quoteName('a.state') . ' = 1') ->where('(' . $db->quoteName('a.publish_up') . ' = ' . $nullDate . ' OR ' . $db->quoteName('a.publish_up') . ' <= ' . $nowDate . ')') ->where('(' . $db->quoteName('a.publish_down') . ' = ' . $nullDate . ' OR ' . $db->quoteName('a.publish_down') . ' >= ' . $nowDate . ')'); } $db->setQuery($query); $data = $db->loadObject(); if (empty($data)) { return false; } if (isset($data->attribs)) { // Convert parameter field to object. $data->params = new Registry($data->attribs); } if (isset($data->metadata)) { // Convert metadata field to object. $data->metadata = new Registry($data->metadata); } self::$articles[$cache_id] = $data; return self::$articles[$cache_id]; } /** * Gets the current article id based on url data */ public static function getId() { $input = JFactory::getApplication()->input; $id = $input->getInt('id'); if ( ! $id || ! ( ($input->get('option') == 'com_content' && $input->get('view') == 'article') || ($input->get('option') == 'com_flexicontent' && $input->get('view') == 'item') ) ) { return false; } return $id; } /** * Passes the different article parts through the given plugin method * * @param object $article * @param string $context * @param object $helper * @param string $method * @param array $params * @param array $ignore */ public static function process(&$article, &$context, &$helper, $method, $params = [], $ignore = []) { self::processText('title', $article, $helper, $method, $params, $ignore); self::processText('created_by_alias', $article, $helper, $method, $params, $ignore); self::processText('description', $article, $helper, $method, $params, $ignore); // Don't replace in text fields in the category list view, as they won't get used anyway if (Document::isCategoryList($context)) { return; } // prevent fulltext from being messed with, when it is a json encoded string (Yootheme Pro templates do this for some weird f-ing reason) if ( ! empty($article->fulltext) && substr($article->fulltext, 0, 6) == '<!-- {') { self::processText('text', $article, $helper, $method, $params, $ignore); return; } $has_text = isset($article->text); $has_article_texts = isset($article->introtext) && isset($article->fulltext); $text_same_as_article_text = false; if ($has_text && $has_article_texts) { $check_text = RegEx::replace('\s', '', $article->text); $check_introtext_fulltext = RegEx::replace('\s', '', $article->introtext . ' ' . $article->fulltext); $text_same_as_article_text = $check_text == $check_introtext_fulltext; } if ($has_article_texts && ! $has_text) { self::processText('introtext', $article, $helper, $method, $params, $ignore); self::processText('fulltext', $article, $helper, $method, $params, $ignore); return; } if ($has_article_texts && $text_same_as_article_text) { $splitter = '͞'; if (strpos($article->introtext, $splitter) !== false || strpos($article->fulltext, $splitter) !== false) { $splitter = 'Ͽ'; } $article->text = $article->introtext . $splitter . $article->fulltext; self::processText('text', $article, $helper, $method, $params, $ignore); list($article->introtext, $article->fulltext) = explode($splitter, $article->text, 2); $article->text = str_replace($splitter, ' ', $article->text); return; } self::processText('text', $article, $helper, $method, $params, $ignore); self::processText('introtext', $article, $helper, $method, $params, $ignore); // Don't handle fulltext on category blog views if ($context == 'com_content.category' && JFactory::getApplication()->input->get('view') == 'category') { return; } self::processText('fulltext', $article, $helper, $method, $params, $ignore); } private static function processText($type = '', &$article, &$helper, $method, $params = [], $ignore = []) { if (empty($article->{$type})) { return; } if (in_array($type, $ignore)) { return; } call_user_func_array([$helper, $method], array_merge([&$article->{$type}], $params)); } public static function getPages($string) { if (empty($string)) { return ['']; } return preg_split('#(<hr class="system-pagebreak" .*?>)#s', $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); } public static function getPageNumber(&$all_pages, $search_string) { if (is_string($all_pages)) { $all_pages = self::getPages($all_pages); } if (count($all_pages) < 2) { return 0; } foreach ($all_pages as $i => $page_text) { if ($i % 2) { continue; } if (strpos($page_text, $search_string) === false) { continue; } $all_pages[$i] = StringHelper::replaceOnce($search_string, '---', $page_text); return $i / 2; } return 0; } } Condition/K2Item.php 0000604 00000002204 15245535751 0010304 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/MijoshopPagetype.php 0000604 00000001213 15245535751 0012477 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/RedshopProduct.php 0000604 00000001352 15245535751 0012161 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Ip.php 0000604 00000006730 15245535751 0007571 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Ip * @package RegularLabs\Library\Condition */ class Ip extends \RegularLabs\Library\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 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 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 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 list($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; } /* 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 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 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; } 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'])) { $_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); } } Condition/AkeebasubsLevel.php 0000604 00000001360 15245535751 0012250 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/UserAccesslevel.php 0000604 00000002702 15245535751 0012304 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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::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)); } } Condition/DateDate.php 0000604 00000003607 15245535751 0010674 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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'); } } Condition/Date.php 0000604 00000001027 15245535751 0010070 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Date * @package RegularLabs\Library\Condition */ abstract class Date extends \RegularLabs\Library\Condition { } Condition/UserGrouplevel.php 0000604 00000005616 15245535751 0012206 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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 { public function pass() { $user = 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 passMatchAll($groups) { $pass = ! array_diff($this->selection, $groups) && ! array_diff($groups, $this->selection); return $this->_($pass); } 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 setUserGroupChildrenIds() { $children = $this->getUserGroupChildrenIds($this->selection); if ($this->params->inc_children == 2) { $this->selection = $children; return; } $this->selection = array_merge($this->selection, $children); } private function getUserGroupChildrenIds($groups) { $children = []; $db = JFactory::getDbo(); foreach ($groups as $group) { $query = $db->getQuery(true) ->select($db->quoteName('id')) ->from($db->quoteName('#__usergroups')) ->where($db->quoteName('parent_id') . ' = ' . (int) $group); $db->setQuery($query); $group_children = $db->loadColumn(); 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; } } Condition/Url.php 0000604 00000003213 15245535751 0007754 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Uri\Uri as JUri; use RegularLabs\Library\RegEx; use RegularLabs\Library\StringHelper; /** * Class Url * @package RegularLabs\Library\Condition */ class Url extends \RegularLabs\Library\Condition { public function pass() { $regex = isset($this->params->regex) ? $this->params->regex : 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) { foreach ($this->selection as $s) { $s = trim($s); if ($s == '') { continue; } if ($regex) { $url_part = str_replace(['#', '&'], ['\#', '(&|&)'], $s); if (@RegEx::match($url_part, $url)) { $pass = true; break; } continue; } if (strpos($url, $s) !== false) { $pass = true; break; } } if ($pass) { break; } } return $this->_($pass); } } Condition/Form2contentProject.php 0000604 00000001726 15245535751 0013130 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/ZooItem.php 0000604 00000001710 15245535751 0010600 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Php.php 0000604 00000011630 15245535751 0007743 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; 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\RegEx; /** * Class Php * @package RegularLabs\Library\Condition */ class Php extends \RegularLabs\Library\Condition { 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 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); } 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); } 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); } 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; } 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' . '/' . $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); } } private function generateFileContents($function_name = 'rl_function', $string = '') { $init_variables = self::getVarInits(); $contents = [ '<?php', 'defined(\'_JEXEC\') or die;', '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; } 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::getUser();', '$Itemid = $app->input->getInt(\'Itemid\');', ]; } 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); } } Condition/Form2content.php 0000604 00000001047 15245535751 0011575 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Form2content * @package RegularLabs\Library\Condition */ abstract class Form2content extends \RegularLabs\Library\Condition { } Condition/UserUser.php 0000604 00000001173 15245535751 0010772 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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() { return $this->passSimple(JFactory::getUser()->get('id')); } } Condition/FlexicontentPagetype.php 0000604 00000001225 15245535751 0013354 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/HikashopProduct.php 0000604 00000001356 15245535751 0012327 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/GeoRegion.php 0000604 00000002143 15245535751 0011071 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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; } } } Condition/Easyblog.php 0000604 00000001503 15245535751 0010757 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Easyblog * @package RegularLabs\Library\Condition */ abstract class Easyblog extends \RegularLabs\Library\Condition { use \RegularLabs\Library\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(); } } Condition/DateSeason.php 0000604 00000005255 15245535751 0011250 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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; } } Condition/DateTime.php 0000604 00000002340 15245535751 0010706 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/MijoshopCategory.php 0000604 00000003433 15245535751 0012504 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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 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); } private function getCatParentIds($id = 0) { return $this->getParentIds($id, 'mijoshop_category', 'parent_id', 'category_id'); } } Condition/User.php 0000604 00000001027 15245535751 0010131 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class User * @package RegularLabs\Library\Condition */ abstract class User extends \RegularLabs\Library\Condition { } Condition/Component.php 0000604 00000001421 15245535751 0011153 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; use Joomla\CMS\Factory as JFactory; defined('_JEXEC') or die; /** * Class Component * @package RegularLabs\Library\Condition */ class Component extends \RegularLabs\Library\Condition { public function pass() { $option = JFactory::getApplication()->input->get('option') == 'com_categories' ? 'com_categories' : $this->request->option; return $this->passSimple(strtolower($option)); } } Condition/AgentDevice.php 0000604 00000001411 15245535751 0011366 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/EasyblogItem.php 0000604 00000002055 15245535751 0011601 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/K2Pagetype.php 0000604 00000001463 15245535751 0011172 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/K2Tag.php 0000604 00000002603 15245535751 0010124 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Content.php 0000604 00000002073 15245535751 0010627 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\MVC\Model\BaseDatabaseModel as JModel; /** * Class Content * @package RegularLabs\Library\Condition */ abstract class Content extends \RegularLabs\Library\Condition { use \RegularLabs\Library\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; } } Condition/HikashopCategory.php 0000604 00000004412 15245535751 0012460 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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 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 []; } } private function getCatParentIds($id = 0) { return $this->getParentIds($id, 'hikashop_category', 'category_parent_id', 'category_id'); } } Condition/Mijoshop.php 0000604 00000002535 15245535751 0011010 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use MijoShop as MijoShopClass; /** * Class Mijoshop * @package RegularLabs\Library\Condition */ abstract class Mijoshop extends \RegularLabs\Library\Condition { public function initRequest(&$request) { $input = JFactory::getApplication()->input; $category_id = $input->getCmd('path', 0); if (strpos($category_id, '_')) { $category_id = end(explode('_', $category_id)); } $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; } } Condition/Flexicontent.php 0000604 00000001047 15245535751 0011657 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Flexicontent * @package RegularLabs\Library\Condition */ abstract class Flexicontent extends \RegularLabs\Library\Condition { } Condition/HikashopPagetype.php 0000604 00000002052 15245535751 0012457 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/AgentBrowser.php 0000604 00000001415 15245535751 0011616 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Tag.php 0000604 00000006074 15245535751 0007735 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class Tag * @package RegularLabs\Library\Condition */ class Tag extends \RegularLabs\Library\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 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)); } 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 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 getTagsParentIds($id = 0) { $parentids = $this->getParentIds($id, 'tags'); // Remove the root tag $parentids = array_diff($parentids, [1]); return $parentids; } 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; } } Condition/EasyblogTag.php 0000604 00000003020 15245535751 0011407 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/GeoContinent.php 0000604 00000001323 15245535751 0011606 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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]); } } Condition/Akeebasubs.php 0000604 00000002074 15245535751 0011263 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Akeebasubs * @package RegularLabs\Library\Condition */ abstract class Akeebasubs extends \RegularLabs\Library\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(); } } Condition/GeoCountry.php 0000604 00000001311 15245535751 0011305 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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]); } } Condition/K2Category.php 0000604 00000004476 15245535751 0011200 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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 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(); } private function getCatParentIds($id = 0) { $parent_field = RL_K2_VERSION == 3 ? 'parent_id' : 'parent'; return $this->getParentIds($id, 'k2_categories', $parent_field); } } Condition/K2.php 0000604 00000001752 15245535751 0007474 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; 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 \RegularLabs\Library\Condition { use \RegularLabs\Library\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(); } } Condition/Agent.php 0000604 00000005354 15245535751 0010260 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use RegularLabs\Library\MobileDetect; use RegularLabs\Library\RegEx; /** * Class Agent * @package RegularLabs\Library\Condition */ abstract class Agent extends \RegularLabs\Library\Condition { var $agent = null; var $device = null; var $is_mobile = false; /** * isPhone */ public function isPhone() { return $this->isMobile(); } /** * isMobile */ public function isMobile() { return $this->getDevice() == 'mobile'; } /** * isTablet */ public function isTablet() { return $this->getDevice() == 'tablet'; } /** * isDesktop */ public function isDesktop() { return $this->getDevice() == 'desktop'; } /** * 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'); } /** * 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; } /** * 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; } } Condition/DateDay.php 0000604 00000001215 15245535751 0010525 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Hikashop.php 0000604 00000002045 15245535751 0010762 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Hikashop * @package RegularLabs\Library\Condition */ abstract class Hikashop extends \RegularLabs\Library\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); } } Condition/RedshopCategory.php 0000604 00000003353 15245535751 0012321 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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'); } } Condition/Virtuemart.php 0000604 00000002122 15245535751 0011352 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Virtuemart * @package RegularLabs\Library\Condition */ abstract class Virtuemart extends \RegularLabs\Library\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 = isset($virtuemart_product_id[0]) ? $virtuemart_product_id[0] : null; $request->category_id = isset($virtuemart_category_id[0]) ? $virtuemart_category_id[0] : null; $request->id = $request->item_id ?: $request->category_id; } } Condition/ContentArticle.php 0000604 00000003074 15245535751 0012135 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/EasyblogKeyword.php 0000604 00000001114 15245535751 0012322 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class EasyblogKeyword * @package RegularLabs\Library\Condition */ class EasyblogKeyword extends Easyblog { public function pass() { parent::passContentKeyword(); } } Condition/Zoo.php 0000604 00000003171 15245535751 0007764 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Zoo * @package RegularLabs\Library\Condition */ abstract class Zoo extends \RegularLabs\Library\Condition { use \RegularLabs\Library\ConditionContent; 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); } 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(); } } Condition/VirtuemartProduct.php 0000604 00000001647 15245535751 0012726 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/VirtuemartCategory.php 0000604 00000005421 15245535751 0013055 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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'); } } Condition/Redshop.php 0000604 00000001524 15245535751 0010621 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Redshop * @package RegularLabs\Library\Condition */ abstract class Redshop extends \RegularLabs\Library\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; } } Condition/VirtuemartPagetype.php 0000604 00000001475 15245535751 0013063 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Homepage.php 0000604 00000011415 15245535751 0010742 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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\RegEx; use RegularLabs\Library\StringHelper; /** * Class HomePage * @package RegularLabs\Library\Condition */ class HomePage extends \RegularLabs\Library\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'] = isset($home->query['view']) ? $home->query['view'] : ''; $home->query['task'] = isset($home->query['task']) ? $home->query['task'] : ''; $home->query['layout'] = isset($home->query['layout']) ? $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('&', '&', $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); } } Condition/AgentOs.php 0000604 00000001033 15245535751 0010550 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; /** * Class AgentOs * @package RegularLabs\Library\Condition */ class AgentOs extends AgentBrowser { // Same as AgentBrowser } Condition/DateMonth.php 0000604 00000001240 15245535751 0011073 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/Cookieconfirm.php 0000604 00000001404 15245535751 0012001 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use PlgSystemCookieconfirmCore; /** * Class Cookieconfirm * @package RegularLabs\Library\Condition */ class Cookieconfirm extends \RegularLabs\Library\Condition { public function pass() { require_once JPATH_PLUGINS . '/system/cookieconfirm/core.php'; $pass = PlgSystemCookieconfirmCore::getInstance()->isCookiesAllowed(); return $this->_($pass); } } Condition/RedshopPagetype.php 0000604 00000001207 15245535751 0012316 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/AkeebasubsPagetype.php 0000604 00000001215 15245535751 0012756 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/ContentCategory.php 0000604 00000010133 15245535751 0012321 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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 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 isset($menuparams->featured_categories) ? (array) $menuparams->featured_categories : (array) $catid; } return isset($menuparams->catid) ? (array) $menuparams->catid : (array) $catid; } private function getCatParentIds($id = 0) { return $this->getParentIds($id, 'categories'); } } Condition/Geo.php 0000604 00000002546 15245535751 0007734 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Log\Log as JLog; /** * Class Geo * @package RegularLabs\Library\Condition */ abstract class Geo extends \RegularLabs\Library\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); } } Condition/MijoshopProduct.php 0000604 00000001356 15245535751 0012351 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/ZooPagetype.php 0000604 00000001161 15245535751 0011460 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/FlexicontentTag.php 0000604 00000003214 15245535751 0012311 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/EasyblogCategory.php 0000604 00000003513 15245535751 0012460 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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 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(); } private function getCatParentIds($id = 0) { return $this->getParentIds($id, 'easyblog_category', 'parent_id'); } } Condition/Menu.php 0000604 00000004436 15245535751 0010126 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use RegularLabs\Library\Document as RL_Document; /** * Class Menu * @package RegularLabs\Library\Condition */ class Menu extends \RegularLabs\Library\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 = isset($menu->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; } } Condition/Template.php 0000604 00000003640 15245535751 0010771 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Template * @package RegularLabs\Library\Condition */ class Template extends \RegularLabs\Library\Condition { 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); } 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; } } Condition/Language.php 0000604 00000001236 15245535751 0010740 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library\Condition; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Language * @package RegularLabs\Library\Condition */ class Language extends \RegularLabs\Library\Condition { public function pass() { return $this->passSimple(JFactory::getLanguage()->getTag(), true); } } Condition/EasyblogPagetype.php 0000604 00000001205 15245535751 0012455 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/ZooCategory.php 0000604 00000007411 15245535751 0011463 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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, '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 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; } } 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; } } Condition/GeoPostalcode.php 0000604 00000001440 15245535751 0011742 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/ContentPagetype.php 0000604 00000001602 15245535751 0012323 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Condition/FlexicontentType.php 0000604 00000002051 15245535751 0012515 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ 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); } } Uri.php 0000604 00000011717 15245535751 0006033 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Router\Route as JRoute; use Joomla\CMS\Uri\Uri as JUri; /** * Class Uri * @package RegularLabs\Library */ class Uri { /** * Returns the full uri and optionally adds/replaces the hash * * @param string $hash * * @return string */ public static function get($hash = '') { $url = JUri::getInstance()->toString(); if ($hash == '') { return $url; } return self::appendHash($url, $hash); } /** * adds the given url parameter (key + value) to the url or replaces it already exists * * @param string $url * @param string $key * @param string $value * @param bool $replace * * @return string */ public static function addParameter($url, $key, $value = '', $replace = true) { if (empty($key)) { return $url; } $uri = parse_url($url); $query = isset($uri['query']) ? self::parse_query($uri['query']) : []; if ( ! $replace && isset($query[$key])) { return $url; } $query[$key] = $value; $uri['query'] = http_build_query($query); return self::createUrlFromArray($uri); } /** * removes the given url parameter from the url * * @param string $url * @param string $key * * @return string */ public static function removeParameter($url, $key) { if (empty($key)) { return $url; } $uri = parse_url($url); if ( ! isset($uri['query'])) { return $url; } $query = self::parse_query($uri['query']); unset($query[$key]); $uri['query'] = http_build_query($query); return self::createUrlFromArray($uri); } /** * Converts an array of url parts (like made by parse_url) to a string * * @param array $uri * * @return string */ public static function createUrlFromArray($uri) { $user = ! empty($uri['user']) ? $uri['user'] : ''; $pass = ! empty($uri['pass']) ? ':' . $uri['pass'] : ''; return (! empty($uri['scheme']) ? $uri['scheme'] . '://' : '') . (($user || $pass) ? $user . $pass . '@' : '') . (! empty($uri['host']) ? $uri['host'] : '') . (! empty($uri['port']) ? ':' . $uri['port'] : '') . (! empty($uri['path']) ? $uri['path'] : '') . (! empty($uri['query']) ? '?' . $uri['query'] : '') . (! empty($uri['fragment']) ? '#' . $uri['fragment'] : ''); } /** * Appends the given hash to the url or replaces it if there is already one * * @param string $url * @param string $hash * * @return string */ public static function appendHash($url = '', $hash = '') { if (empty($hash)) { return $url; } $uri = parse_url($url); $uri['fragment'] = $hash; return self::createUrlFromArray($uri); } public static function isExternal($url) { if (strpos($url, '://') === false) { return false; } // hostname: give preference to SERVER_NAME, because this includes subdomains $hostname = ($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']; return ! (strpos(RegEx::replace('^.*?://', '', $url), $hostname) === 0); } public static function route($url) { return JRoute::_(JUri::root(true) . '/' . $url); } public static function encode($string) { return urlencode(base64_encode(gzdeflate($string))); } public static function decode($string) { return gzinflate(base64_decode(urldecode($string))); } public static function createCompressedAttributes($string) { $parameters = []; $compressed = base64_encode(gzdeflate($string)); $chunk_length = ceil(strlen($compressed) / 10); $chunks = str_split($compressed, $chunk_length); foreach ($chunks as $i => $chunk) { $parameters[] = 'rlatt_' . $i . '=' . urlencode($chunk); } return implode('&', $parameters); } public static function getCompressedAttributes() { $input = JFactory::getApplication()->input; $compressed = ''; for ($i = 0; $i < 10; $i++) { $compressed .= $input->getString('rlatt_' . $i, ''); } return gzinflate(base64_decode($compressed)); } /** * Parse a query string into an associative array. * * @param string $string * * @return array */ private static function parse_query($string) { $result = []; if ($string === '') { return $result; } $decoder = function ($value) { return rawurldecode(str_replace('+', ' ', $value)); }; foreach (explode('&', $string) as $kvp) { $parts = explode('=', $kvp, 2); $key = $decoder($parts[0]); $value = isset($parts[1]) ? $decoder($parts[1]) : null; if ( ! isset($result[$key])) { $result[$key] = $value; continue; } if ( ! is_array($result[$key])) { $result[$key] = [$result[$key]]; } $result[$key][] = $value; } return $result; } } FieldGroup.php 0000604 00000006176 15245535751 0007337 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Language\Text as JText; use Joomla\Registry\Registry; class FieldGroup extends Field { public $type = 'Field'; public $default_group = 'Categories'; protected function getInput() { $this->params = $this->element->attributes(); return $this->getSelectList(); } public function getGroup() { $this->params = $this->element->attributes(); return $this->get('group', $this->default_group ?: $this->type); } public function getOptions($group = false) { $group = $group ?: $this->getGroup(); $id = $this->type . '_' . $group; if ( ! isset($data[$id])) { $data[$id] = $this->{'get' . $group}(); } return $data[$id]; } public function getSelectList($group = '') { if ( ! is_array($this->value)) { $this->value = explode(',', $this->value); } $size = (int) $this->get('size'); $multiple = $this->get('multiple'); $show_ignore = $this->get('show_ignore'); $group = $group ?: $this->getGroup(); $simple = $this->get('simple', ! in_array($group, ['categories'])); return $this->selectListAjax( $this->type, $this->name, $this->value, $this->id, compact('group', 'size', 'multiple', 'simple', 'show_ignore'), $simple ); } function getAjaxRaw(Registry $attributes) { $this->params = $attributes; $name = $attributes->get('name', $this->type); $id = $attributes->get('id', strtolower($name)); $value = $attributes->get('value', []); $size = $attributes->get('size'); $multiple = $attributes->get('multiple'); $simple = $attributes->get('simple'); $options = $this->getOptions( $attributes->get('group') ); return $this->selectList($options, $name, $value, $id, $size, $multiple, $simple); } public function missingFilesOrTables($tables = ['categories', 'items'], $component = '', $table_prefix = '') { $component = $component ?: $this->type; if ( ! Extension::isInstalled($component)) { return '<fieldset class="alert alert-danger">' . JText::_('ERROR') . ': ' . JText::sprintf('RL_FILES_NOT_FOUND', JText::_('RL_' . strtoupper($component))) . '</fieldset>'; } $group = $this->getGroup(); if ( ! in_array($group, $tables) && ! in_array($group, array_keys($tables))) { // no need to check database table for this group return false; } $table_list = $this->db->getTableList(); $table = isset($tables[$group]) ? $tables[$group] : $group; $table = $this->db->getPrefix() . strtolower($table_prefix ?: $component) . '_' . $table; if (in_array($table, $table_list)) { // database table exists, so no error return false; } return '<fieldset class="alert alert-danger">' . JText::_('ERROR') . ': ' . JText::sprintf('RL_TABLE_NOT_FOUND', JText::_('RL_' . strtoupper($component))) . '</fieldset>'; } } ConditionContent.php 0000604 00000023257 15245535751 0010557 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; use FieldsHelper; use JLoader; use Joomla\CMS\Date\Date as JDate; use Joomla\CMS\Factory as JFactory; use RegularLabs\Plugin\System\ArticlesAnywhere\Replace as AA_Replace; defined('_JEXEC') or die; JLoader::register('FieldsHelper', JPATH_ADMINISTRATOR . '/components/com_fields/helpers/fields.php'); /** * Class ConditionContent * @package RegularLabs\Library */ trait ConditionContent { public function passContentId() { if (empty($this->selection)) { return null; } return in_array($this->request->id, $this->selection); } public function passFeatured() { return $this->passBoolean('featured'); } public function passBoolean($field = 'featured') { if ( ! isset($this->params->{$field}) || $this->params->{$field} == '') { return null; } $item = $this->getItem($field); if ( ! isset($item->{$field})) { return false; } return $this->params->{$field} == $item->{$field}; } public function passContentKeyword($fields = ['title', 'introtext', 'fulltext'], $text = '') { if (empty($this->params->content_keywords)) { return null; } if ( ! $text) { $item = $this->getItem($fields); foreach ($fields as $field) { if ( ! isset($item->{$field})) { return false; } $text = trim($text . ' ' . $item->{$field}); } } if (empty($text)) { return false; } $this->params->content_keywords = $this->makeArray($this->params->content_keywords); foreach ($this->params->content_keywords as $keyword) { if ( ! RegEx::match('\b' . RegEx::quote($keyword) . '\b', $text)) { continue; } return true; } return false; } public function passMetaKeyword($field = 'metakey', $keywords = '') { if (empty($this->params->meta_keywords)) { return null; } if ( ! $keywords) { $item = $this->getItem($field); if ( ! isset($item->metakey) || empty($item->metakey)) { return false; } $keywords = $item->metakey; } if (empty($keywords)) { return false; } if (is_string($keywords)) { $keywords = str_replace(' ', ',', $keywords); } $keywords = $this->makeArray($keywords); $this->params->meta_keywords = $this->makeArray($this->params->meta_keywords); foreach ($this->params->meta_keywords as $keyword) { if ( ! $keyword || ! in_array(trim($keyword), $keywords)) { continue; } return true; } return false; } public function passAuthor($field = 'created_by', $author = '') { $this->params->authors = ArrayHelper::clean($this->params->authors); if (empty($this->params->authors)) { return null; } if ( ! $author) { $item = $this->getItem($field); if ( ! isset($item->{$field})) { return false; } $author = $item->{$field}; } if (empty($author)) { return false; } $this->params->authors = $this->makeArray($this->params->authors); if (in_array('current', $this->params->authors) && JFactory::getUser()->id) { $this->params->authors[] = JFactory::getUser()->id; $this->params->authors = array_diff($this->params->authors, ['current']); } return in_array($author, $this->params->authors); } public function passDate() { if (empty($this->params->date)) { return null; } $field = $this->params->date; $item = $this->getItem($field); if ( ! isset($item->{$field})) { return false; } $date = $this->getDateString($item->{$field}); switch ($this->params->date_comparison) { case 'before': if ($this->params->date_type == 'now') { return $date < $this->getNow(); } return $date < $this->getDateString($this->params->date_date); case 'after': if ($this->params->date_type == 'now') { return $date > $this->getNow(); } return $date > $this->getDateString($this->params->date_date); case 'fromto': $from = (int) $this->params->date_from ? $this->getDateString($this->params->date_from) : false; $to = (int) $this->params->date_to ? $this->getDateString($this->params->date_to) : false; return ( ! $from || $date >= $from) && ( ! $to || $date <= $to); default: return false; } } public function passField() { if (empty($this->params->fields)) { return null; } $item = $this->getItem(); if ( ! isset($item->id)) { return false; } $fields = $this->params->fields; $article_fields = FieldsHelper::getFields('com_content.article', $item, true); foreach ($fields as $i => $field) { $pass = false; foreach ($article_fields as $article_field) { if ($article_field->name != $field->field) { continue; } $comparison = ! empty($field->field_comparison) ? $field->field_comparison : 'equals'; if ( ! self::passComparison($field->field_value, $article_field->rawvalue, $comparison)) { return false; } $pass = true; break; } if ( ! $pass) { return false; } } return true; } private static function passComparison($needle, $haystack, $comparison = 'equals') { $haystack = ArrayHelper::toArray($haystack); if (empty($haystack)) { return false; } // For list values if (count($haystack) > 1) { switch ($comparison) { case 'not_equals': $needle = ArrayHelper::toArray($needle); sort($needle); sort($haystack); return $needle != $haystack; case 'contains': $needle = ArrayHelper::toArray($needle); sort($needle); $intersect = array_intersect($needle, $haystack); return $needle == $intersect; case 'contains_one': return ArrayHelper::find($needle, $haystack); case 'not_contains': return ! ArrayHelper::find($needle, $haystack); case 'equals': default: $needle = ArrayHelper::toArray($needle); sort($needle); sort($haystack); return $needle == $haystack; } } $haystack = $haystack[0]; if ($comparison == 'regex') { return RegEx::match($needle, $haystack); } // What's the use case? Not sure yet :) $needle = self::runThroughArticlesAnywhere($needle); // Convert dynamic date values i, like date('yesterday') $haystack = self::valueToDateString($haystack, true); $has_time = self::hasTime($haystack); $needle = self::valueToDateString($needle, false, $has_time); // make the needle and haystack lowercase, so comparisons are case insensitive $needle = StringHelper::strtolower($needle); $haystack = StringHelper::strtolower($haystack); switch ($comparison) { case 'not_equals': return $needle != $haystack; case 'contains': case 'contains_one': return strpos($haystack, $needle) !== false; case 'not_contains': return strpos($haystack, $needle) === false; case 'begins_with': $length = strlen($needle); return substr($haystack, 0, $length) === $needle; case 'ends_with': $length = strlen($needle); if ($length == 0) { return true; } return substr($haystack, -$length) === $needle; case 'less_than': return $haystack < $needle; case 'greater_than': return $haystack > $needle; case 'equals': default: return $needle == $haystack; } } private static function valueToDateString($value, $apply_offset = true, $add_time = false) { $value = trim($value); if (in_array($value, [ 'now()', 'JFactory::getDate()', ])) { if ( ! $apply_offset) { return date('Y-m-d H:i:s', strtotime('now')); } $date = new JDate('now', JFactory::getConfig()->get('offset', 'UTC')); return $date->format('Y-m-d H:i:s'); } if (self::isDateTimeString($value)) { $format = 'Y-m-d H:i:s'; $date = new JDate($value, JFactory::getConfig()->get('offset', 'UTC')); if ($apply_offset) { $date = JFactory::getDate($value, 'UTC'); $date->setTimezone(new \DateTimeZone(JFactory::getConfig()->get('offset'))); } return $date->format($format, true, false); } $regex = '^date\(\s*' . '(?:\'(?<datetime>.*?)\')?' . '(?:\\\\?,\s*\'(?<format>.*?)\')?' . '\s*\)$'; if ( ! RegEx::match($regex, $value, $match)) { return $value; } $datetime = ! empty($match['datetime']) ? $match['datetime'] : 'now'; $format = ! empty($match['format']) ? $match['format'] : ''; if (empty($format)) { $time = date('His', strtotime($datetime)); $format = (int) $time || $add_time ? 'Y-m-d H:i:s' : 'Y-m-d'; } $date = new JDate($datetime, JFactory::getConfig()->get('offset', 'UTC')); if ($apply_offset) { $date = JFactory::getDate($datetime, 'UTC'); $date->setTimezone(new \DateTimeZone(JFactory::getConfig()->get('offset'))); } return $date->format($format, true, false); } public static function isDateTimeString($string) { return RegEx::match('^[0-9]{4}-[0-9]{2}-[0-9]{2}', $string); } public static function hasTime($string) { if ( ! self::isDateTimeString($string)) { return false; } return RegEx::match('^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}', $string); } public static function runThroughArticlesAnywhere($string) { $articlesanywhere_params = Parameters::getInstance()->getPluginParams('articlesanywhere'); if (empty($articlesanywhere_params) || ! isset($articlesanywhere_params->article_tag) || ! isset($articlesanywhere_params->articles_tag)) { return $string; } AA_Replace::replaceTags($string); Protect::removeCommentTags($string, 'Articles Anywhere'); return $string; } abstract public function getItem($fields = []); } Condition.php 0000604 00000024345 15245535751 0007223 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use DateTimeZone; use Joomla\CMS\Factory as JFactory; /** * Class Condition * @package RegularLabs\Library */ abstract class Condition implements \RegularLabs\Library\Api\ConditionInterface { static $_request = null; public $request = null; public $date = null; public $db = null; public $selection = null; public $params = null; public $include_type = null; public $article = null; public $module = null; private $timezone = null; private $dates = []; public function __construct($condition = [], $article = null, $module = null) { $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); $this->date = JFactory::getDate()->setTimeZone($tz); $this->request = self::getRequest(); $this->db = JFactory::getDbo(); $this->selection = isset($condition->selection) ? $condition->selection : []; $this->params = isset($condition->params) ? $condition->params : []; $this->include_type = isset($condition->include_type) ? $condition->include_type : 'none'; if (is_array($this->selection)) { $this->selection = ArrayHelper::clean($this->selection); } $this->article = $article; $this->module = $module; } public function init() { } public function initRequest(&$request) { } public function beforePass() { } private function getRequest() { $return_early = ! is_null(self::$_request); $app = JFactory::getApplication(); $input = $app->input; $id = $input->get( 'a_id', $input->get('id', [0], 'array'), 'array' ); self::$_request = (object) [ 'idname' => 'id', 'option' => $input->get('option'), 'view' => $input->get('view'), 'task' => $input->get('task'), 'layout' => $input->getString('layout'), 'Itemid' => $this->getItemId(), 'id' => (int) $id[0], ]; switch (self::$_request->option) { case 'com_categories': $extension = $input->getCmd('extension'); self::$_request->option = $extension ? $extension : 'com_content'; self::$_request->view = 'category'; break; case 'com_breezingforms': if (self::$_request->view == 'article') { self::$_request->option = 'com_content'; } break; } $this->initRequest(self::$_request); if ( ! self::$_request->id) { $cid = $input->get('cid', [0], 'array'); self::$_request->id = (int) $cid[0]; } if ($return_early) { return self::$_request; } // if no id is found, check if menuitem exists to get view and id if (Document::isClient('site') && ( ! self::$_request->option || ! self::$_request->id) ) { $menuItem = empty(self::$_request->Itemid) ? $app->getMenu('site')->getActive() : $app->getMenu('site')->getItem(self::$_request->Itemid); if ($menuItem) { if ( ! self::$_request->option) { self::$_request->option = (empty($menuItem->query['option'])) ? null : $menuItem->query['option']; } self::$_request->view = (empty($menuItem->query['view'])) ? null : $menuItem->query['view']; self::$_request->task = (empty($menuItem->query['task'])) ? null : $menuItem->query['task']; if ( ! self::$_request->id) { self::$_request->id = (empty($menuItem->query[self::$_request->idname])) ? $menuItem->params->get(self::$_request->idname) : $menuItem->query[self::$_request->idname]; } } unset($menuItem); } return self::$_request; } public function _($pass = true, $include_type = null) { $include_type = $include_type ?: $this->include_type; return $pass ? ($include_type == 'include') : ($include_type == 'exclude'); } public function passSimple($values = '', $caseinsensitive = false, $include_type = null, $selection = null) { $values = $this->makeArray($values); $include_type = $include_type ?: $this->include_type; $selection = $selection ?: $this->selection; $pass = false; foreach ($values as $value) { if ($caseinsensitive) { if (in_array(strtolower($value), array_map('strtolower', $selection))) { $pass = true; break; } continue; } if (in_array($value, $selection)) { $pass = true; break; } } return $this->_($pass, $include_type); } public function passInRange($value = '', $include_type = null, $selection = null) { $include_type = $include_type ?: $this->include_type; if (empty($value)) { return $this->_(false, $include_type); } $selections = $this->makeArray($selection ?: $this->selection); $pass = false; foreach ($selections as $selection) { if (empty($selection)) { continue; } if (strpos($selection, '-') === false) { if ((int) $value == (int) $selection) { $pass = true; break; } continue; } list($min, $max) = explode('-', $selection, 2); if ((int) $value >= (int) $min && (int) $value <= (int) $max) { $pass = true; break; } } return $this->_($pass, $include_type); } public function passItemByType(&$pass, $type = '', $data = null) { $pass_type = ! empty($data) ? $this->{'pass' . $type}($data) : $this->{'pass' . $type}(); if ($pass_type === null) { return true; } $pass = $pass_type; return $pass; } public function passByPageType($option, $selection = [], $include_type = 'all', $add_view = false, $get_task = false, $get_layout = true) { if ($this->request->option != $option) { return $this->_(false, $include_type); } if ($get_task && $this->request->task && $this->request->task != $this->request->view && $this->request->task != 'default') { $pagetype = ($add_view ? $this->request->view . '_' : '') . $this->request->task; return $this->passSimple($pagetype, $selection, $include_type); } if ($get_layout && $this->request->layout && $this->request->layout != $this->request->view && $this->request->layout != 'default') { $pagetype = ($add_view ? $this->request->view . '_' : '') . $this->request->layout; return $this->passSimple($pagetype, $selection, $include_type); } return $this->passSimple($this->request->view, $selection, $include_type); } public function getMenuItemParams($id = 0) { $cache_id = 'getMenuItemParams_' . $id; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $query = $this->db->getQuery(true) ->select('m.params') ->from('#__menu AS m') ->where('m.id = ' . (int) $id); $this->db->setQuery($query); $params = $this->db->loadResult(); $parameters = Parameters::getInstance(); return Cache::set( $cache_id, $parameters->getParams($params) ); } public function getParentIds($id = 0, $table = 'menu', $parent = 'parent_id', $child = 'id') { if ( ! $id) { return []; } $cache_id = 'getParentIds_' . $id . '_' . $table . '_' . $parent . '_' . $child; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $parent_ids = []; while ($id) { $query = $this->db->getQuery(true) ->select('t.' . $parent) ->from('#__' . $table . ' as t') ->where('t.' . $child . ' = ' . (int) $id); $this->db->setQuery($query); $id = $this->db->loadResult(); // Break if no parent is found or parent already found before for some reason if ( ! $id || in_array($id, $parent_ids)) { break; } $parent_ids[] = $id; } return Cache::set( $cache_id, $parent_ids ); } public function makeArray($array = '', $delimiter = ',', $trim = false) { if (empty($array)) { return []; } $cache_id = 'makeArray_' . json_encode($array) . '_' . $delimiter . '_' . $trim; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $array = $this->mixedDataToArray($array, $delimiter); if (empty($array)) { return $array; } if ( ! $trim) { return $array; } foreach ($array as $k => $v) { if ( ! is_string($v)) { continue; } $array[$k] = trim($v); } return Cache::set( $cache_id, $array ); } private function mixedDataToArray($array = '', $onlycommas = false) { if ( ! is_array($array)) { $delimiter = ($onlycommas || strpos($array, '|') === false) ? ',' : '|'; return explode($delimiter, $array); } if (empty($array)) { return $array; } if (isset($array[0]) && is_array($array[0])) { return $array[0]; } if (count($array) === 1 && strpos($array[0], ',') !== false) { return explode(',', $array[0]); } return $array; } private function getItemId() { $app = JFactory::getApplication(); if ($id = $app->input->getInt('Itemid', 0)) { return $id; } $menu = $this->getActiveMenu(); return isset($menu->id) ? $menu->id : 0; } private function getActiveMenu() { $menu = JFactory::getApplication()->getMenu()->getActive(); if (empty($menu->id)) { return false; } return $this->getMenuById($menu->id); } private function getMenuById($id = 0) { $menu = JFactory::getApplication()->getMenu()->getItem($id); if (empty($menu->id)) { return false; } if ($menu->type == 'alias') { $params = $menu->getParams(); return $this->getMenuById($params->get('aliasoptions')); } return $menu; } public function getNow() { return strtotime($this->date->format('Y-m-d H:i:s', true)); } public function getDate($date = '') { $date = Date::fix($date); $id = 'date_' . $date; if (isset($this->dates[$id])) { return $this->dates[$id]; } $this->dates[$id] = JFactory::getDate($date); if (empty($this->params->ignore_time_zone)) { $this->dates[$id]->setTimeZone($this->getTimeZone()); } return $this->dates[$id]; } public function getDateString($date = '') { $date = $this->getDate($date); $date = strtotime($date->format('Y-m-d H:i:s', true)); return $date; } private function getTimeZone() { if ( ! is_null($this->timezone)) { return $this->timezone; } $this->timezone = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); return $this->timezone; } } Image.php 0000604 00000020503 15245535751 0006307 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Filesystem\Folder as JFolder; use Joomla\CMS\Uri\Uri as JUri; use Joomla\Image\Image as JImage; class Image { // public static function getSet($source, $width, $height, $folder = 'resized', $resize = true, $quality = 'medium', $possible_suffix = '') // { // $paths = self::getPaths($source, $width, $height, $folder, $resize, $quality, $possible_suffix); // // return (object) [ // 'original' => (object) [ // 'url' => $paths->image, // 'width' => self::getWidth($paths->original), // 'height' => self::getHeight($paths->original), // ], // 'resized' => (object) [ // 'url' => $paths->resized, // 'width' => self::getWidth($paths->resized), // 'height' => self::getHeight($paths->resized), // ], // ]; // } public static function getUrls($source, $width, $height, $folder = 'resized', $resize = true, $quality = 'medium', $possible_suffix = '') { if ($image = self::isResized($source, $folder, $possible_suffix)) { $source = $image; } $original = $source; $resized = self::getResize($source, $width, $height, $folder, $resize, $quality); return (object) compact('original', 'resized'); } public static function getResize($source, $width, $height, $folder = 'resized', $resize = true, $quality = 'medium') { $destination_folder = File::getDirName($source) . '/' . $folder; $override = File::getDirName($source) . '/' . $folder . '/' . File::getBaseName($source); if (file_exists(JPATH_SITE . '/' . $override)) { $source = $override; } if ( ! self::setNewDimensions($source, $width, $height)) { return $source; } if ( ! $width && ! $height) { return $source; } $destination = self::getNewPath( $source, $width, $height, $destination_folder ); if ( ! file_exists(JPATH_SITE . '/' . $destination) && $resize) { // Create new resized image $destination = self::resize( $source, $width, $height, $destination_folder, $quality ); } if ( ! file_exists(JPATH_SITE . '/' . $destination)) { return $source; } return $destination; } public static function isResized($file, $folder = 'resized', $possible_suffix = '') { if (File::isExternal($file)) { return false; } if ( ! file_exists($file)) { return false; } if ($main_image = self::isResizedWithFolder($file, $folder)) { return $main_image; } if ($possible_suffix && $main_image = self::isResizedWithSuffix($file, $possible_suffix)) { return $main_image; } return false; } public static function isResizedWithSuffix($file, $suffix = '_t') { // Remove the suffix from the file // image_t.jpg => image.jpg $main_file = RegEx::replace( RegEx::quote($suffix) . '(\.[^.]+)$', '\1', $file ); // Nothing removed, so not a resized image if ($main_file == $file) { return false; } if ( ! file_exists(JPATH_SITE . '/' . utf8_decode($main_file))) { return false; } return $main_file; } private static function isResizedWithFolder($file, $resize_folder = 'resized') { $folder = File::getDirName($file); $file = File::getBaseName($file); $parent_folder_name = File::getBaseName($folder); $parent_folder = File::getDirName($folder); // Image is not inside the resize folder if ($parent_folder_name != $resize_folder) { return false; } // Check if image with same name exists in parent folder if (file_exists(JPATH_SITE . '/' . $parent_folder . '/' . utf8_decode($file))) { return $parent_folder . '/' . $file; } // Remove any dimensions from the file // image_300x200.jpg => image.jpg $file = RegEx::replace( '_[0-9]+x[0-9]*(\.[^.]+)$', '\1', $file ); // Check again if image with same name (but without dimensions) exists in parent folder if (file_exists(JPATH_SITE . '/' . $parent_folder . '/' . utf8_decode($file))) { return $parent_folder . '/' . $file; } return false; } public static function resize($source, &$width, &$height, $destination_folder = '', $quality = 'medium', $overwrite = false) { if (File::isExternal($source)) { return $source; } $clean_source = self::cleanPath($source); $source_path = JPATH_SITE . '/' . $clean_source; $destination_folder = ltrim($destination_folder ?: File::getDirName($clean_source)); $destination_folder = self::cleanPath($destination_folder); if ( ! file_exists($source_path)) { return false; } if ( ! self::setNewDimensions($source, $width, $height)) { return $source; } if ( ! $width && ! $height) { return $source; } if ( ! getimagesize($source_path)) { return $source; } try { $image = new JImage($source_path); } catch (\InvalidArgumentException $e) { return $source; } $destination = self::getNewPath($source, $width, $height, $destination_folder); $destination_path = JPATH_SITE . '/' . $destination; if (file_exists($destination_path) && ! $overwrite) { return $destination; } JFolder::create(JPATH_SITE . '/' . $destination_folder); $info = JImage::getImageFileProperties($source_path); $options = ['quality' => self::getQuality($info->type, $quality)]; $image->cropResize($width, $height, false) ->toFile($destination_path, $info->type, $options); $image->destroy(); return $destination; } public static function setNewDimensions($source, &$width, &$height) { if ( ! $width && ! $height) { return false; } if (File::isExternal($source)) { return false; } $clean_source = self::cleanPath($source); $source_path = JPATH_SITE . '/' . $clean_source; if ( ! file_exists($source_path)) { return false; } if ( ! getimagesize($source_path)) { return false; } try { $image = new JImage($source_path); } catch (\InvalidArgumentException $e) { return false; } $original_width = $image->getWidth(); $original_height = $image->getHeight(); $width = $width ?: round($original_width / $original_height * $height); $height = $height ?: round($original_height / $original_width * $width); $image->destroy(); if ($width == $original_width && $height == $original_height) { return false; } return true; } public static function getNewPath($source, $width, $height, $destination_folder = '') { $clean_source = self::cleanPath($source); $source_parts = pathinfo($clean_source); $destination_folder = ltrim($destination_folder ?: File::getDirName($clean_source)); $destination_file = File::getFileName($clean_source) . '_' . $width . 'x' . $height . '.' . $source_parts['extension']; JFolder::create(JPATH_SITE . '/' . $destination_folder); return ltrim($destination_folder . '/' . $destination_file); } public static function cleanPath($source) { $source = ltrim(str_replace(JUri::root(), '', $source), '/'); $source = strtok($source, '?'); return $source; } public static function getWidth($source) { $dimensions = self::getDimensions($source); return $dimensions->width; } public static function getHeight($source) { $dimensions = self::getDimensions($source); return $dimensions->height; } public static function getDimensions($source) { $empty = (object) [ 'width' => 0, 'height' => 0, ]; if (File::isExternal($source)) { return $empty; } if ( ! getimagesize($source)) { return $empty; } try { $image = new JImage(JPATH_SITE . '/' . $source); } catch (\InvalidArgumentException $e) { return $empty; } return (object) [ 'width' => $image->getWidth(), 'height' => $image->getHeight(), ]; } public static function getQuality($type, $quality = 'medium') { switch ($type) { case IMAGETYPE_JPEG: return min(max(self::getJpgQuality($quality), 0), 100); case IMAGETYPE_PNG: return 9; default: return ''; } } public static function getJpgQuality($quality = 'medium') { switch ($quality) { case 'low': return 50; case 'high': return 90; case 'medium': default: return 70; } } } Conditions.php 0000604 00000044713 15245535751 0007407 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; jimport('joomla.filesystem.file'); /** * Class Conditions * @package RegularLabs\Library */ class Conditions { static $installed_extensions = null; static $params = null; public static function pass($conditions, $matching_method = 'all', $article = null, $module = null) { if (empty($conditions)) { return true; } $article_id = isset($article->id) ? $article->id : ''; $module_id = isset($module->id) ? $module->id : ''; $matching_method = in_array($matching_method, ['any', 'or']) ? 'any' : 'all'; $cache_id = 'pass_' . $article_id . '_' . $module_id . '_' . $matching_method . '_' . json_encode($conditions); if (Cache::has($cache_id)) { return Cache::get($cache_id); } $pass = (bool) ($matching_method == 'all'); foreach (self::getTypes() as $type) { // Break if not passed and matching method is ALL // Or if passed and matching method is ANY if ( ( ! $pass && $matching_method == 'all') || ($pass && $matching_method == 'any') ) { break; } if ( ! isset($conditions[$type])) { continue; } $pass = self::passByType($conditions[$type], $type, $article, $module); } return Cache::set( $cache_id, $pass ); } public static function hasConditions($conditions) { if (empty($conditions)) { return false; } foreach (self::getTypes() as $type) { if (isset($conditions[$type]) && isset($conditions[$type]->include_type) && $conditions[$type]->include_type) { return true; } } return false; } public static function getConditionsFromParams(&$params) { $cache_id = 'getConditionsFromParams_' . json_encode($params); if (Cache::has($cache_id)) { return Cache::get($cache_id); } self::renameParamKeys($params); $types = []; foreach (self::getTypes() as $id => $type) { if (empty($params->conditions[$id])) { continue; } $types[$type] = (object) [ 'include_type' => $params->conditions[$id], 'selection' => [], 'params' => (object) [], ]; if (isset($params->conditions[$id . '_selection'])) { $types[$type]->selection = self::getSelection($params->conditions[$id . '_selection'], $type); } self::addParams($types[$type], $type, $id, $params); } return Cache::set( $cache_id, $types ); } public static function getConditionsFromTagAttributes(&$attributes, $only_types = []) { $conditions = []; PluginTag::replaceKeyAliases($attributes, self::getTypeAliases(), true); $types = self::getTypes($only_types); if (empty($types)) { return $conditions; } $type_params = []; foreach ($attributes as $type_param => $value) { if (strpos($type_param, '_') === false) { continue; } list($type, $param) = explode('_', $type_param, 2); $condition_type = self::getType($type, $only_types); if ( ! $condition_type) { continue; } $type_params[$type_param] = $value; unset($attributes->{$type_param}); } foreach ($attributes as $type => $value) { if (empty($value)) { continue; } $condition_type = self::getType($type, $only_types); if ( ! $condition_type) { continue; } $value = html_entity_decode($value); $params = self::getDefaultParamsByType($condition_type, $type); $params->conditions = $type_params; $reverse = false; $selection = self::getSelectionFromTagAttribute($condition_type, $value, $params, $reverse); $condition = (object) [ 'include_type' => $reverse ? 2 : 1, 'selection' => $selection, 'params' => (object) [], ]; self::addParams($condition, $condition_type, $type, $params); $conditions[$condition_type] = $condition; } return $conditions; } private static function initParametersByType(&$params, $type = '') { $params->class_name = str_replace('.', '', $type); $params->include_type = self::getConditionState($params->include_type); } private static function passByType($condition, $type, $article = null, $module = null) { $article_id = isset($article->id) ? $article->id : ''; $module_id = isset($module->id) ? $module->id : ''; $cache_prefix = 'passByType_' . $type . '_' . $article_id . '_' . $module_id; $cache_id = $cache_prefix . '_' . json_encode($condition); if (Cache::has($cache_id)) { return Cache::get($cache_id); } self::initParametersByType($condition, $type); $cache_id = $cache_prefix . '_' . json_encode($condition); if (Cache::has($cache_id)) { return Cache::get($cache_id); } $pass = false; switch ($condition->include_type) { case 'all': $pass = true; break; case 'none': $pass = false; break; default: if ( ! file_exists(__DIR__ . '/Condition/' . $condition->class_name . '.php')) { break; } $className = '\\RegularLabs\\Library\\Condition\\' . $condition->class_name; $class = new $className($condition, $article, $module); $class->beforePass(); $pass = $class->pass(); break; } return Cache::set( $cache_id, $pass ); } private static function getConditionState($include_type) { switch ($include_type . '') { case 1: case 'include': return 'include'; case 2: case 'exclude': return 'exclude'; case 3: case -1: case 'none': return 'none'; default: return 'all'; } } private static function makeArray($array = '', $delimiter = ',', $trim = true) { if (empty($array)) { return []; } $cache_id = 'makeArray_' . json_encode($array) . '_' . $delimiter . '_' . $trim; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $array = self::mixedDataToArray($array, $delimiter); if (empty($array)) { return $array; } if ( ! $trim) { return $array; } foreach ($array as $k => $v) { if ( ! is_string($v)) { continue; } $array[$k] = trim($v); } return Cache::set( $cache_id, $array ); } private static function mixedDataToArray($array = '', $delimiter = ',') { if ( ! is_array($array)) { return explode($delimiter, $array); } if (empty($array)) { return $array; } if (isset($array[0]) && is_array($array[0])) { return $array[0]; } if (count($array) === 1 && strpos($array[0], $delimiter) !== false) { return explode($delimiter, $array[0]); } return $array; } private static function renameParamKeys(&$params) { $params->conditions = isset($params->conditions) ? $params->conditions : []; foreach ($params as $key => $value) { if (strpos($key, 'condition_') === false && strpos($key, 'assignto_') === false) { continue; } $new_key = substr($key, strpos($key, '_') + 1); $params->conditions[$new_key] = $value; unset($params->{$key}); } } private static function getSelection($selection, $type = '') { if (in_array($type, self::getNotArrayTextAreaTypes())) { return $selection; } $delimiter = in_array($type, self::getTextAreaTypes()) ? "\n" : ','; return self::makeArray($selection, $delimiter); } private static function getSelectionFromTagAttribute($type, $value, &$params, &$reverse) { if ($type == 'Date.Date') { $value = str_replace('from', '', $value); $dates = explode(' - ', str_replace('to', ' - ', $value)); $params->ignore_time_zone = true; if ( ! empty($dates[0])) { $params->publish_up = date('Y-m-d H:i:s', strtotime($dates[0])); } if ( ! empty($dates[1])) { $params->publish_down = date('Y-m-d H:i:s', strtotime($dates[1])); } return []; } if ($type == 'Date.Time') { $value = str_replace('from', '', $value); $dates = explode(' - ', str_replace('to', ' - ', $value)); $params->publish_up = $dates[0]; $params->publish_down = isset($dates[1]) ? $dates[1] : $dates[0]; return []; } if (in_array($type, self::getTextAreaTypes())) { $value = Html::convertWysiwygToPlainText($value); } if (strpos($value, '!NOT!') === 0) { $reverse = true; $value = substr($value, 5); } if ( ! in_array($type, self::getNotArrayTextAreaTypes())) { $value = str_replace('[[:COMMA:]]', ',', str_replace(',', '[[:SPLIT:]]', str_replace('\\,', '[[:COMMA:]]', $value))); $value = explode('[[:SPLIT:]]', $value); } return $value; } private static function getDefaultParamsByType($condition_type, $type) { switch ($condition_type) { case 'Content.Category': return (object) [ 'assignto_' . $type . '_inc' => [ 'inc_cats', 'inc_arts', ], ]; case 'Easyblog.Category': case 'K2.Category': case 'Zoo.Category': case 'Hikashop.Category': case 'Mijoshop.Category': case 'Redshop.Category': case 'Virtuemart.Category': return (object) [ 'assignto_' . $type . '_inc' => [ 'inc_cats', 'inc_items', ], ]; default: return (object) []; } } private static function addParams(&$object, $type, $id, &$params) { $extra_params = []; $array_params = []; $includes = []; switch ($type) { case 'Menu': $extra_params = ['inc_children', 'inc_noitemid']; break; case 'Date.Date': $extra_params = ['publish_up', 'publish_down', 'recurring', 'ignore_time_zone']; break; case 'Date.Season': $extra_params = ['hemisphere']; break; case 'Date.Time': $extra_params = ['publish_up', 'publish_down']; break; case 'User.Grouplevel': $extra_params = ['inc_children']; break; case 'Url': if (is_array($object->selection)) { $object->selection = implode("\n", $object->selection); } if (isset($params->conditions['urls_selection_sef'])) { $object->selection .= "\n" . $params->conditions['urls_selection_sef']; } $object->selection = trim(str_replace("\r", '', $object->selection)); $object->selection = explode("\n", $object->selection); $object->params->regex = isset($params->conditions['urls_regex']) ? $params->conditions['urls_regex'] : false; break; case 'Agent.Browser': if ( ! empty($params->conditions['mobile_selection'])) { $object->selection = array_merge(self::makeArray($object->selection), self::makeArray($params->conditions['mobile_selection'])); } if ( ! empty($params->conditions['searchbots_selection'])) { $object->selection = array_merge($object->selection, self::makeArray($params->conditions['searchbots_selection'])); } break; case 'Tag': $extra_params = ['inc_children']; break; case 'Content.Category': $extra_params = ['inc_children']; $includes = ['cats' => 'categories', 'arts' => 'articles', 'others']; break; case 'Easyblog.Category': case 'K2.Category': case 'Hikashop.Category': case 'Mijoshop.Category': case 'Redshop.Category': case 'Virtuemart.Category': $extra_params = ['inc_children']; $includes = ['cats' => 'categories', 'items']; break; case 'Zoo.Category': $extra_params = ['inc_children']; $includes = ['apps', 'cats' => 'categories', 'items']; break; case 'Easyblog.Tag': case 'Flexicontent.Tag': case 'K2.Tag': $includes = ['tags', 'items']; break; case 'Content.Article': $extra_params = [ 'featured', 'content_keywords', 'keywords' => 'meta_keywords', 'authors', 'date', 'date_comparison', 'date_type', 'date_date', 'date_from', 'date_to', 'fields', ]; break; case 'K2.Item': $extra_params = ['content_keywords', 'meta_keywords', 'authors']; break; case 'Easyblog.Item': $extra_params = ['content_keywords', 'authors']; break; case 'Zoo.Item': $extra_params = ['authors']; break; } if (in_array($type, self::getMatchAllTypes())) { $extra_params[] = 'match_all'; if (count($object->selection) == 1 && strpos($object->selection[0], '+') !== false) { $object->selection = ArrayHelper::toArray($object->selection[0], '+'); $params->match_all = true; } } if (empty($extra_params) && empty($array_params) && empty($includes)) { return; } self::addParamsByType($object, $id, $params, $extra_params, $array_params, $includes); } private static function addParamsByType(&$object, $id, $params, $extra_params = [], $array_params = [], $includes = []) { foreach ($extra_params as $key => $param) { $key = is_numeric($key) ? $param : $key; $object->params->{$param} = self::getTypeParamValue($id, $params, $key); } foreach ($array_params as $key => $param) { $key = is_numeric($key) ? $param : $key; $object->params->{$param} = self::getTypeParamValue($id, $params, $key, true); } if (empty($includes)) { return; } $incs = self::getTypeParamValue($id, $params, 'inc', true); if (empty($incs) && ! empty($params->conditions[$id]) && ! isset($params->conditions[$id . '_inc'])) { $incs = ['inc_items', 'inc_arts', 'inc_cats', 'inc_others', 'x']; } foreach ($includes as $key => $param) { $key = is_numeric($key) ? $param : $key; $object->params->{'inc_' . $param} = in_array('inc_' . $key, $incs) ? 1 : 0; } unset($object->params->inc); } private static function getTypeParamValue($id, $params, $key, $is_array = false) { if (isset($params->conditions) && isset($params->conditions[$id . '_' . $key])) { return $params->conditions[$id . '_' . $key]; } if (isset($params->{'assignto_' . $id . '_' . $key})) { return $params->{'assignto_' . $id . '_' . $key}; } if (isset($params->{$key})) { return $params->{$key}; } if ($is_array) { return []; } return ''; } private static function getTypes($only_types = []) { $types = [ 'menuitems' => 'Menu', 'homepage' => 'Homepage', 'date' => 'Date.Date', 'seasons' => 'Date.Season', 'months' => 'Date.Month', 'days' => 'Date.Day', 'time' => 'Date.Time', 'accesslevels' => 'User.Accesslevel', 'usergrouplevels' => 'User.Grouplevel', 'users' => 'User.User', 'languages' => 'Language', 'ips' => 'Ip', 'geocontinents' => 'Geo.Continent', 'geocountries' => 'Geo.Country', 'georegions' => 'Geo.Region', 'geopostalcodes' => 'Geo.Postalcode', 'templates' => 'Template', 'urls' => 'Url', 'devices' => 'Agent.Device', 'os' => 'Agent.Os', 'browsers' => 'Agent.Browser', 'components' => 'Component', 'tags' => 'Tag', 'contentpagetypes' => 'Content.Pagetype', 'cats' => 'Content.Category', 'articles' => 'Content.Article', 'easyblogpagetypes' => 'Easyblog.Pagetype', 'easyblogcats' => 'Easyblog.Category', 'easyblogtags' => 'Easyblog.Tag', 'easyblogitems' => 'Easyblog.Item', 'flexicontentpagetypes' => 'Flexicontent.Pagetype', 'flexicontenttags' => 'Flexicontent.Tag', 'flexicontenttypes' => 'Flexicontent.Type', 'form2contentprojects' => 'Form2content.Project', 'k2pagetypes' => 'K2.Pagetype', 'k2cats' => 'K2.Category', 'k2tags' => 'K2.Tag', 'k2items' => 'K2.Item', 'zoopagetypes' => 'Zoo.Pagetype', 'zoocats' => 'Zoo.Category', 'zooitems' => 'Zoo.Item', 'akeebasubspagetypes' => 'Akeebasubs.Pagetype', 'akeebasubslevels' => 'Akeebasubs.Level', 'hikashoppagetypes' => 'Hikashop.Pagetype', 'hikashopcats' => 'Hikashop.Category', 'hikashopproducts' => 'Hikashop.Product', 'mijoshoppagetypes' => 'Mijoshop.Pagetype', 'mijoshopcats' => 'Mijoshop.Category', 'mijoshopproducts' => 'Mijoshop.Product', 'redshoppagetypes' => 'Redshop.Pagetype', 'redshopcats' => 'Redshop.Category', 'redshopproducts' => 'Redshop.Product', 'virtuemartpagetypes' => 'Virtuemart.Pagetype', 'virtuemartcats' => 'Virtuemart.Category', 'virtuemartproducts' => 'Virtuemart.Product', 'cookieconfirm' => 'Cookieconfirm', 'php' => 'Php', ]; if (empty($only_types)) { return $types; } return array_intersect_key($types, array_flip($only_types)); } private static function getType(&$type, $only_types = []) { $types = self::getTypes($only_types); if (isset($types[$type])) { return $types[$type]; } // Make it plural $type = rtrim($type, 's') . 's'; if (isset($types[$type])) { return $types[$type]; } // Replace incorrect plural endings $type = str_replace('ys', 'ies', $type); if (isset($types[$type])) { return $types[$type]; } return false; } private static function getTypeAliases() { return [ 'matching_method' => ['method'], 'menuitems' => ['menu'], 'homepage' => ['home'], 'date' => ['daterange'], 'seasons' => [''], 'months' => [''], 'days' => [''], 'time' => [''], 'accesslevels' => ['access'], 'usergrouplevels' => ['usergroups', 'groups'], 'users' => [''], 'languages' => ['langs'], 'ips' => ['ipaddress', 'ipaddresses'], 'geocontinents' => ['continents'], 'geocountries' => ['countries'], 'georegions' => ['regions'], 'geopostalcodes' => ['postalcodes', 'postcodes'], 'templates' => [''], 'urls' => [''], 'devices' => [''], 'os' => [''], 'browsers' => [''], 'components' => [''], 'tags' => [''], 'contentpagetypes' => ['pagetypes'], 'cats' => ['categories', 'category'], 'articles' => [''], 'php' => [''], ]; } private static function getTextAreaTypes() { return [ 'Ip', 'Url', 'Php', ]; } private static function getNotArrayTextAreaTypes() { return [ 'Php', ]; } public static function getMatchAllTypes() { return [ 'User.Grouplevel', 'Tag', ]; } } HtmlTag.php 0000604 00000007504 15245535751 0006633 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * Class HtmlTag * @package RegularLabs\Library */ class HtmlTag { /** * Combine 2 opening html tags into one * * @param string $tag1 * @param string $tag2 * * @return string */ public static function combine($tag1, $tag2) { // Return if tags are the same if ($tag1 == $tag2) { return $tag1; } if ( ! RegEx::match('<([a-z][a-z0-9]*)', $tag1, $tag_type)) { return $tag2; } $tag_type = $tag_type[1]; if ( ! $attribs = self::combineAttributes($tag1, $tag2)) { return '<' . $tag_type . '>'; } return '<' . $tag_type . ' ' . $attribs . '>'; } /** * Extract attribute value from a html tag string by given attribute key * * @param string $key * @param string $string * * @return string */ public static function getAttributeValue($key, $string) { if (empty($key) || empty($string)) { return ''; } RegEx::match(RegEx::quote($key) . '="([^"]*)"', $string, $match); if (empty($match)) { return ''; } return $match[1]; } /** * Extract all attributes from a html tag string * * @param string $string * * @return array */ public static function getAttributes($string) { if (empty($string)) { return []; } RegEx::matchAll('([a-z0-9-_]+)="([^"]*)"', $string, $matches); if (empty($matches)) { return []; } $attribs = []; foreach ($matches as $match) { $attribs[$match[1]] = $match[2]; } return $attribs; } /** * Combine attribute values from 2 given html tag strings (or arrays of attributes) * And return as a sting of attributes * * @param string /array $string1 * @param string /array $string2 * * @return string */ public static function combineAttributes($string1, $string2, $flatten = true) { $attribsutes1 = is_array($string1) ? $string1 : self::getAttributes($string1); $attribsutes2 = is_array($string2) ? $string2 : self::getAttributes($string2); $duplicate_attributes = array_intersect_key($attribsutes1, $attribsutes2); // Fill $attributes with the unique ids $attributes = array_diff_key($attribsutes1, $attribsutes2) + array_diff_key($attribsutes2, $attribsutes1); // List of attrubute types that can only contain one value $single_value_attributes = ['id', 'href']; // Add/combine the duplicate ids foreach ($duplicate_attributes as $key => $val) { if (in_array($key, $single_value_attributes)) { $attributes[$key] = $attribsutes2[$key]; continue; } // Combine strings, but remove duplicates // "aaa bbb" + "aaa ccc" = "aaa bbb ccc" // use a ';' as a concatenated for javascript values (keys beginning with 'on') // Otherwise use a space (like for classes) $glue = substr($key, 0, 2) == 'on' ? ';' : ' '; $attributes[$key] = implode($glue, array_merge(explode($glue, $attribsutes1[$key]), explode($glue, $attribsutes2[$key]))); } return $flatten ? self::flattenAttributes($attributes) : $attributes; } /** * Convert array of attributes to a html style string * * @param array $attributes * * @return string */ public static function flattenAttributes($attributes, $prefix = '') { $output = []; foreach ($attributes as $key => $val) { if (is_null($val) || $val === '') { continue; } if ($val === false) { $val = 'false'; } if ($val === true) { $val = 'true'; } $val = str_replace('"', '"', $val); $output[] = $prefix . $key . '="' . $val . '"'; } return implode(' ', $output); } } EditorButtonPlugin.php 0000604 00000007207 15245535751 0011074 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Object\CMSObject as JObject; use Joomla\CMS\Plugin\CMSPlugin as JPlugin; use ReflectionClass; /** * Class EditorButtonPlugin * @package RegularLabs\Library */ class EditorButtonPlugin extends JPlugin { private $_init = false; private $_helper = null; var $main_type = 'plugin'; // The type of extension that holds the parameters var $check_installed = null; // The types of extensions that need to be checked (will default to main_type) var $require_core_auth = true; // Whether or not the core content create/edit permissions are required var $folder = null; // The path to the original caller file var $enable_on_acymailing = false; // Whether or not to enable the editor button on AcyMailing /** * Display the button * * @param string $editor_name * * @return JObject|null A button object */ function onDisplay($editor_name) { if ( ! $this->getHelper()) { return null; } return $this->_helper->render($editor_name, $this->_subject); } /* * Below methods are general functions used in most of the Regular Labs extensions * The reason these are not placed in the Regular Labs Library files is that they also * need to be used when the Regular Labs Library is not installed */ /** * Create the helper object * * @return object|null The plugins helper object */ private function getHelper() { // Already initialized, so return if ($this->_init) { return $this->_helper; } $this->_init = true; if ( ! Extension::isFrameworkEnabled()) { return null; } if ( ! Extension::isAuthorised($this->require_core_auth)) { return null; } if ( ! $this->isInstalled()) { return null; } if ( ! $this->enable_on_acymailing && JFactory::getApplication()->input->get('option') == 'com_acymailing') { return null; } $params = $this->getParams(); if ( ! Extension::isEnabledInComponent($params)) { return null; } if ( ! Extension::isEnabledInArea($params)) { return null; } if ( ! $this->extraChecks($params)) { return null; } require_once $this->getDir() . '/helper.php'; $class_name = 'PlgButton' . ucfirst($this->_name) . 'Helper'; $this->_helper = new $class_name($this->_name, $params); return $this->_helper; } public function extraChecks($params) { return true; } private function getDir() { // use static::class instead of get_class($this) after php 5.4 support is dropped $rc = new ReflectionClass(get_class($this)); return dirname($rc->getFileName()); } private function getParams() { switch ($this->main_type) { case 'component': if ( ! Protect::isComponentInstalled($this->_name)) { return null; } // Load component parameters return Parameters::getInstance()->getComponentParams($this->_name); case 'plugin': default: if ( ! Protect::isSystemPluginInstalled($this->_name)) { return null; } // Load plugin parameters return Parameters::getInstance()->getPluginParams($this->_name); } } private function isInstalled() { $extensions = ! is_null($this->check_installed) ? $this->check_installed : [$this->main_type]; return Extension::areInstalled($this->_name, $extensions); } } File.php 0000604 00000027333 15245535751 0006154 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Client\ClientHelper as JClientHelper; use Joomla\CMS\Client\FtpClient as JFtpClient; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Filesystem\Folder as JFolder; use Joomla\CMS\Filesystem\Path as JPath; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Log\Log as JLog; use Joomla\CMS\Uri\Uri as JUri; /** * Class File * @package RegularLabs\Library */ class File { /** * Find a matching media file in the different possible extension media folders for given type * * @param string $type (css/js/...) * @param string $file * * @return bool|string */ public static function getMediaFile($type, $file) { // If http is present in filename if (strpos($file, 'http') === 0 || strpos($file, '//') === 0) { return $file; } $files = []; // Detect debug mode if (JFactory::getConfig()->get('debug') || JFactory::getApplication()->input->get('debug')) { $files[] = str_replace(['.min.', '-min.'], '.', $file); } $files[] = $file; /* * Loop on 1 or 2 files and break on first find. * Add the content of the MD5SUM file located in the same folder to url to ensure cache browser refresh * This MD5SUM file must represent the signature of the folder content */ foreach ($files as $check_file) { $file_found = self::findMediaFileByFile($check_file, $type); if ( ! $file_found) { continue; } return $file_found; } return false; } /** * Find a matching media file in the different possible extension media folders for given type * * @param string $file * @param string $type (css/js/...) * * @return bool|string */ private static function findMediaFileByFile($file, $type) { $template = JFactory::getApplication()->getTemplate(); // If the file is in the template folder $file_found = self::getFileUrl('/templates/' . $template . '/' . $type . '/' . $file); if ($file_found) { return $file_found; } // Try to deal with system files in the media folder if (strpos($file, '/') === false) { $file_found = self::getFileUrl('/media/system/' . $type . '/' . $file); if ( ! $file_found) { return false; } return $file_found; } $paths = []; // If the file contains any /: it can be in a media extension subfolder // Divide the file extracting the extension as the first part before / list($extension, $file) = explode('/', $file, 2); $paths[] = '/media/' . $extension . '/' . $type; $paths[] = '/templates/' . $template . '/' . $type . '/system'; $paths[] = '/media/system/' . $type; foreach ($paths as $path) { $file_found = self::getFileUrl($path . '/' . $file); if ( ! $file_found) { continue; } return $file_found; } return false; } /** * Get the url for the file * * @param string $path * * @return bool|string */ private static function getFileUrl($path) { if ( ! file_exists(JPATH_ROOT . $path)) { return false; } return JUri::root(true) . $path; } /** * Delete a file or array of files * * @param mixed $file The file name or an array of file names * @param boolean $show_messages Whether or not to show error messages * @param int $min_age_in_minutes Minimum last modified age in minutes * * @return boolean True on success * * @since 11.1 */ public static function delete($file, $show_messages = false, $min_age_in_minutes = 0) { $FTPOptions = JClientHelper::getCredentials('ftp'); $pathObject = new JPath; $files = is_array($file) ? $file : [$file]; if ($FTPOptions['enabled'] == 1) { // Connect the FTP client $ftp = JFtpClient::getInstance($FTPOptions['host'], $FTPOptions['port'], [], $FTPOptions['user'], $FTPOptions['pass']); } foreach ($files as $file) { $file = $pathObject->clean($file); if ( ! is_file($file)) { continue; } if ($min_age_in_minutes && floor((time() - filemtime($file)) / 60) < $min_age_in_minutes) { continue; } // Try making the file writable first. If it's read-only, it can't be deleted // on Windows, even if the parent folder is writable @chmod($file, 0777); if ($FTPOptions['enabled'] == 1) { $file = $pathObject->clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $file), '/'); if ( ! $ftp->delete($file)) { // FTP connector throws an error return false; } } // Try the unlink twice in case something was blocking it on first try if ( ! @unlink($file) && ! @unlink($file)) { $show_messages && JLog::add(JText::sprintf('JLIB_FILESYSTEM_DELETE_FAILED', basename($file)), JLog::WARNING, 'jerror'); return false; } } return true; } /** * Delete a folder. * * @param string $path The path to the folder to delete. * @param boolean $show_messages Whether or not to show error messages * @param int $min_age_in_minutes Minimum last modified age in minutes * * @return boolean True on success. */ public static function deleteFolder($path, $show_messages = false, $min_age_in_minutes = 0) { @set_time_limit(ini_get('max_execution_time')); $pathObject = new JPath; if ( ! $path) { $show_messages && JLog::add(__METHOD__ . ': ' . JText::_('JLIB_FILESYSTEM_ERROR_DELETE_BASE_DIRECTORY'), JLog::WARNING, 'jerror'); return false; } // Check to make sure the path valid and clean $path = $pathObject->clean($path); if ( ! is_dir($path)) { $show_messages && JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path), JLog::WARNING, 'jerror'); return false; } // Remove all the files in folder if they exist; disable all filtering $files = JFolder::files($path, '.', false, true, [], []); if ( ! empty($files)) { if (self::delete($files, $show_messages, $min_age_in_minutes) !== true) { // JFile::delete throws an error return false; } } // Remove sub-folders of folder; disable all filtering $folders = JFolder::folders($path, '.', false, true, [], []); foreach ($folders as $folder) { if (is_link($folder)) { // Don't descend into linked directories, just delete the link. if (self::delete($folder, $show_messages, $min_age_in_minutes) !== true) { return false; } continue; } if ( ! self::deleteFolder($folder, $show_messages, $min_age_in_minutes)) { return false; } } // Skip if folder is not empty yet if ( ! empty(JFolder::files($path, '.', false, true, [], [])) || ! empty(JFolder::folders($path, '.', false, true, [], []))) { return true; } if (@rmdir($path)) { return true; } $FTPOptions = JClientHelper::getCredentials('ftp'); if ($FTPOptions['enabled'] == 1) { // Connect the FTP client $ftp = JFtpClient::getInstance($FTPOptions['host'], $FTPOptions['port'], [], $FTPOptions['user'], $FTPOptions['pass']); // Translate path and delete $path = $pathObject->clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $path), '/'); // FTP connector throws an error return $ftp->delete($path); } if ( ! @rmdir($path)) { $show_messages && JLog::add(JText::sprintf('JLIB_FILESYSTEM_ERROR_FOLDER_DELETE', $path), JLog::WARNING, 'jerror'); return false; } return true; } public static function trimFolder($folder) { return trim(str_replace(['\\', '//'], '/', $folder), '/'); } public static function isInternal($url) { return ! self::isExternal($url); } public static function isExternal($url) { if (strpos($url, '://') === false) { return false; } // hostname: give preference to SERVER_NAME, because this includes subdomains $hostname = ($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HTTP_HOST']; return ! (strpos(RegEx::replace('^.*?://', '', $url), $hostname) === 0); } // some/url/to/a/file.ext // > some/url/to/a public static function getDirName($url) { $url = StringHelper::normalize($url); return rtrim(dirname($url), '/'); } // some/url/to/a/file.ext // > file.ext public static function getBaseName($url, $lowercase = false) { $url = StringHelper::normalize($url); $basename = ltrim(basename($url), '/'); $parts = explode('?', $basename); $basename = $parts[0]; if ($lowercase) { $basename = strtolower($basename); } return $basename; } // some/url/to/a/file.ext // > file public static function getFileName($url, $lowercase = false) { $url = StringHelper::normalize($url); $info = pathinfo($url); $filename = isset($info['filename']) ? $info['filename'] : $url; if ($lowercase) { $filename = strtolower($filename); } return $filename; } // some/url/to/a/file.ext // > ext public static function getExtension($url) { $info = pathinfo($url); if ( ! isset($info['extension'])) { return ''; } $ext = explode('?', $info['extension']); return strtolower($ext[0]); } public static function isImage($url) { return self::isMedia($url, self::getFileTypes('images')); } public static function isVideo($url) { return self::isMedia($url, self::getFileTypes('videos')); } public static function isExternalVideo($url) { return (strpos($url, 'youtu.be') !== false || strpos($url, 'youtube.com') !== false || strpos($url, 'vimeo.com') !== false ); } public static function isDocument($url) { return self::isMedia($url, self::getFileTypes('documents')); } public static function isMedia($url, $filetypes = []) { $filetype = self::getExtension($url); if ( ! $filetype) { return false; } if ( ! is_array($filetypes)) { $filetypes = [$filetypes]; } if (count($filetypes) == 1 && strpos($filetypes[0], ',') !== false) { $filetypes = ArrayHelper::toArray($filetypes[0]); } $filetypes = ! empty($filetypes) ? $filetypes : self::getFileTypes(); return in_array($filetype, $filetypes); } public static function getFileTypes($type = 'images') { switch ($type) { case 'image': case 'images': return [ 'bmp', 'flif', 'gif', 'jpe', 'jpeg', 'jpg', 'png', 'tiff', 'eps', ]; case 'audio': return [ 'aif', 'aiff', 'mp3', 'wav', ]; case 'video': case 'videos': return [ '3g2', '3gp', 'avi', 'divx', 'f4v', 'flv', 'm4v', 'mov', 'mp4', 'mpe', 'mpeg', 'mpg', 'ogv', 'swf', 'webm', 'wmv', ]; case 'document': case 'documents': return [ 'doc', 'docm', 'docx', 'dotm', 'dotx', 'odb', 'odc', 'odf', 'odg', 'odi', 'odm', 'odp', 'ods', 'odt', 'onepkg', 'onetmp', 'onetoc', 'onetoc2', 'otg', 'oth', 'otp', 'ots', 'ott', 'oxt', 'pdf', 'potm', 'potx', 'ppam', 'pps', 'ppsm', 'ppsx', 'ppt', 'pptm', 'pptx', 'rtf', 'sldm', 'sldx', 'thmx', 'xla', 'xlam', 'xlc', 'xld', 'xll', 'xlm', 'xls', 'xlsb', 'xlsm', 'xlsx', 'xlt', 'xltm', 'xltx', 'xlw', ]; case 'other': case 'others': return [ 'css', 'csv', 'js', 'json', 'tar', 'txt', 'xml', 'zip', ]; default: case 'all': return array_merge( self::getFileTypes('images'), self::getFileTypes('audio'), self::getFileTypes('videos'), self::getFileTypes('documents'), self::getFileTypes('other') ); } } } Form.php 0000604 00000040500 15245535751 0006167 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\HTML\HTMLHelper as JHtml; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Plugin\PluginHelper as JPluginHelper; class Form { /** * Render a full select list * * @param array $options * @param string $name * @param string $value * @param string $id * @param int $size * @param bool $multiple * @param bool $simple * @param bool $readonly * @param bool $ignore_max_count * * @return string */ public static function selectList(&$options, $name, $value, $id, $size = 0, $multiple = false, $simple = false, $readonly = false, $ignore_max_count = false) { if (empty($options)) { return '<fieldset class="radio">' . JText::_('RL_NO_ITEMS_FOUND') . '</fieldset>'; } if ( ! $multiple) { $simple = true; } $parameters = Parameters::getInstance(); $params = $parameters->getPluginParams('regularlabs'); if ( ! is_array($value)) { $value = explode(',', $value); } if (count($value) === 1 && strpos($value[0], ',') !== false) { $value = explode(',', $value[0]); } $count = 0; if ($options != -1) { foreach ($options as $option) { $count++; if (isset($option->links)) { $count += count($option->links); } if ( ! $ignore_max_count && $count > $params->max_list_count) { break; } } } if ($options == -1 || ( ! $ignore_max_count && $count > $params->max_list_count)) { if (is_array($value)) { $value = implode(',', $value); } if ( ! $value) { $input = '<textarea name="' . $name . '" id="' . $id . '" cols="40" rows="5">' . $value . '</textarea>'; } else { $input = '<input type="text" name="' . $name . '" id="' . $id . '" value="' . $value . '" size="60">'; } $plugin = JPluginHelper::getPlugin('system', 'regularlabs'); $url = ! empty($plugin->id) ? 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $plugin->id : 'index.php?option=com_plugins&filter_folder=&filter_search=Regular%20Labs%20Library'; $label = JText::_('RL_ITEM_IDS'); $text = JText::_('RL_MAX_LIST_COUNT_INCREASE'); $tooltip = JText::_('RL_MAX_LIST_COUNT_INCREASE_DESC,' . $params->max_list_count . ',RL_MAX_LIST_COUNT'); $link = '<a href="' . $url . '" target="_blank" id="' . $id . '_msg"' . ' class="hasPopover" title="' . $text . '" data-content="' . htmlentities($tooltip) . '">' . '<span class="icon icon-cog"></span>' . $text . '</a>'; $script = 'jQuery("#' . $id . '_msg").popover({"html": true,"trigger": "hover focus","container": "body"})'; return '<fieldset class="radio">' . '<label for="' . $id . '">' . $label . ':</label>' . $input . '<br><small>' . $link . '</small>' . '</fieldset>' . '<script>' . $script . '</script>'; } if ($simple) { $first_level = isset($options[0]->level) ? $options[0]->level : 0; foreach ($options as &$option) { if ( ! isset($option->level)) { continue; } $repeat = ($option->level - $first_level > 0) ? $option->level - $first_level : 0; if ( ! $repeat) { continue; } //$option->text = str_repeat(' - ', $repeat) . $option->text; $option->text = '[[:padding-left: ' . (5 + ($repeat * 15)) . 'px;:]]' . $option->text; } } if ( ! $multiple) { $attr = 'class="inputbox"'; if ($readonly) { $attr .= ' readonly="readonly"'; } if (is_array(reset($options)) && isset(reset($options)['items'])) { return JHtml::_( 'select.groupedlist', $options, $name, [ 'id' => $id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $value, ] ); } $html = JHtml::_('select.genericlist', $options, $name, $attr, 'value', 'text', $value, $id); return self::handlePreparedStyles($html); } $size = (int) $size ?: 300; if ($simple) { $attr = 'style="width: ' . $size . 'px" multiple="multiple"'; if ($readonly) { $attr .= ' readonly="readonly"'; } if (substr($name, -2) !== '[]') { $name .= '[]'; } if (is_array(reset($options)) && isset(reset($options)['items'])) { return JHtml::_( 'select.groupedlist', $options, $name, [ 'id' => $id, 'group.id' => 'id', 'list.attr' => trim($attr), 'list.select' => $value, ] ); } $html = JHtml::_('select.genericlist', $options, $name, trim($attr), 'value', 'text', $value, $id); return self::handlePreparedStyles($html); } Language::load('com_modules', JPATH_ADMINISTRATOR); Document::script('regularlabs/multiselect.min.js'); Document::stylesheet('regularlabs/multiselect.min.css'); $count_total = self::getOptionsCount($options); $count_selected = count($value); $has_nested = $count_total > count($options); $html = []; $html[] = '<div class="well well-small rl_multiselect" id="' . $id . '">'; $html[] = '<div class="form-inline rl_multiselect-controls">'; $html[] = '<span class="small">' . JText::_('JSELECT') . ': <a class="rl_multiselect-checkall" href="javascript:;">' . JText::_('JALL') . '</a> <span class="ghosted">[' . $count_total . ']</span>, <a class="rl_multiselect-uncheckall" href="javascript:;">' . JText::_('JNONE') . '</a>, <a class="rl_multiselect-toggleall" href="javascript:;">' . JText::_('RL_TOGGLE') . '</a> </span>'; $html[] = '<span> | </span>'; if ($has_nested) { $html[] = '<span class="small">' . JText::_('RL_EXPAND') . ': <a class="rl_multiselect-expandall" href="javascript:;">' . JText::_('JALL') . '</a>, <a class="rl_multiselect-collapseall" href="javascript:;">' . JText::_('JNONE') . '</a> </span>'; $html[] = '<span> | </span>'; } $html[] = '<span class="small">' . JText::_('JSHOW') . ': <a class="rl_multiselect-showall" href="javascript:;">' . JText::_('JALL') . '</a> <span class="ghosted">[' . $count_total . ']</span>, <a class="rl_multiselect-showselected" href="javascript:;">' . JText::_('RL_SELECTED') . '</a> <span class="ghosted">[<span class="rl_multiselect-count-selected">' . $count_selected . '</span>]</span> </span>'; $html[] = '<span class="rl_multiselect-maxmin"> <span> | </span> <span class="small"> <a class="rl_multiselect-maximize" href="javascript:;">' . JText::_('RL_MAXIMIZE') . '</a> <a class="rl_multiselect-minimize" style="display:none;" href="javascript:;">' . JText::_('RL_MINIMIZE') . '</a> </span> </span>'; $html[] = '<input type="text" name="rl_multiselect-filter" class="rl_multiselect-filter input-medium search-query pull-right" size="16" autocomplete="off" placeholder="' . JText::_('JSEARCH_FILTER') . '" aria-invalid="false" tabindex="-1">'; $html[] = '</div>'; $html[] = '<hr class="hr-condensed">'; $o = []; foreach ($options as $option) { $option->level = isset($option->level) ? $option->level : 0; $o[] = $option; if (isset($option->links)) { foreach ($option->links as $link) { $link->level = $option->level + (isset($link->level) ? $link->level : 1); $o[] = $link; } } } $html[] = '<ul class="rl_multiselect-ul" style="max-height:300px;min-width:' . $size . 'px;overflow-x: hidden;">'; $prevlevel = 0; foreach ($o as $i => $option) { if ($prevlevel < $option->level) { // correct wrong level indentations $option->level = $prevlevel + 1; $html[] = '<ul class="rl_multiselect-sub">'; } else if ($prevlevel > $option->level) { $html[] = str_repeat('</li></ul>', $prevlevel - $option->level); } else if ($i) { $html[] = '</li>'; } $labelclass = trim('pull-left ' . (isset($option->labelclass) ? $option->labelclass : '')); $html[] = '<li>'; $item = '<div class="' . trim('rl_multiselect-item pull-left ' . (isset($option->class) ? $option->class : '')) . '">'; if (isset($option->title)) { $labelclass .= ' nav-header'; } if (isset($option->title) && ( ! isset($option->value) || ! $option->value)) { $item .= '<label class="' . $labelclass . '">' . $option->title . '</label>'; } else { $selected = in_array($option->value, $value) ? ' checked="checked"' : ''; $disabled = (isset($option->disable) && $option->disable) ? ' disabled="disabled"' : ''; if (empty($option->hide_select)) { $item .= '<input type="checkbox" class="pull-left" name="' . $name . '" id="' . $id . $option->value . '" value="' . $option->value . '"' . $selected . $disabled . '>'; } $item .= '<label for="' . $id . $option->value . '" class="' . $labelclass . '">' . $option->text . '</label>'; } $item .= '</div>'; $html[] = $item; if ( ! isset($o[$i + 1]) && $option->level > 0) { $html[] = str_repeat('</li></ul>', (int) $option->level); } $prevlevel = $option->level; } $html[] = '</ul>'; $html[] = ' <div style="display:none;" class="rl_multiselect-menu-block"> <div class="pull-left nav-hover rl_multiselect-menu"> <div class="btn-group"> <a href="#" data-toggle="dropdown" class="dropdown-toggle btn btn-micro"> <span class="caret"></span> </a> <ul class="dropdown-menu"> <li class="nav-header">' . JText::_('COM_MODULES_SUBITEMS') . '</li> <li class="divider"></li> <li class=""><a class="checkall" href="javascript:;"><span class="icon-checkbox"></span> ' . JText::_('JSELECT') . '</a> </li> <li><a class="uncheckall" href="javascript:;"><span class="icon-checkbox-unchecked"></span> ' . JText::_('COM_MODULES_DESELECT') . '</a> </li> <div class="rl_multiselect-menu-expand"> <li class="divider"></li> <li><a class="expandall" href="javascript:;"><span class="icon-plus"></span> ' . JText::_('RL_EXPAND') . '</a></li> <li><a class="collapseall" href="javascript:;"><span class="icon-minus"></span> ' . JText::_('RL_COLLAPSE') . '</a></li> </div> </ul> </div> </div> </div>'; $html[] = '</div>'; $html = implode('', $html); return self::handlePreparedStyles($html); } public static function getOptionsCount($options) { $count = 0; foreach ($options as $option) { $count++; if ( ! empty($option->links)) { $count += self::getOptionsCount($option->links); } } return $count; } /** * Render a simple select list * * @param array $options * @param $string $name * @param string $value * @param string $id * @param int $size * @param bool $multiple * @param bool $readonly * @param bool $ignore_max_count * * @return string */ public static function selectListSimple(&$options, $name, $value, $id, $size = 0, $multiple = false, $readonly = false, $ignore_max_count = false) { return self::selectlist($options, $name, $value, $id, $size, $multiple, true, $readonly, $ignore_max_count); } /** * Render a select list loaded via Ajax * * @param string $field * @param string $name * @param string $value * @param string $id * @param array $attributes * @param bool $simple * * @return string */ public static function selectListAjax($field, $name, $value, $id, $attributes = [], $simple = false) { JHtml::_('jquery.framework'); $script = self::getAddToLoadAjaxListScript($field, $name, $value, $id, $attributes, $simple); if (is_array($value)) { $value = implode(',', $value); } Document::script('regularlabs/script.min.js'); Document::stylesheet('regularlabs/style.min.css'); $input = '<textarea name="' . $name . '" id="' . $id . '" cols="40" rows="5">' . $value . '</textarea>' . '<div id="' . $id . '_spinner" class="rl_spinner"></div>'; return $input . $script; } public static function getAddToLoadAjaxListScript($field, $name, $value, $id, $attributes = [], $simple = false) { $attributes['field'] = $field; $attributes['name'] = $name; $attributes['value'] = $value; $attributes['id'] = $id; $url = 'index.php?option=com_ajax&plugin=regularlabs&format=raw' . '&' . Uri::createCompressedAttributes(json_encode($attributes)); $remove_spinner = "$('#" . $id . "_spinner').remove();"; $replace_field = "$('#" . $id . "').replaceWith(data);"; $init_chosen = 'document.getElementById("' . $id . '") && document.getElementById("' . $id . '").nodeName == "SELECT" && $("#' . $id . '").chosen();'; $success = $replace_field; if ($simple) { $success .= $init_chosen; } else { Document::script('regularlabs/multiselect.min.js'); Document::stylesheet('regularlabs/multiselect.min.css'); $success .= "if(data.indexOf('rl_multiselect') > -1)\{RegularLabsMultiSelect.init($('#" . $id . "'));\} else { " . $init_chosen . "}"; } // $success .= "console.log('#" . $id . "');"; // $success .= "console.log(data);"; $error = $remove_spinner; $success = "if(data)\{" . $success . "\}" . $remove_spinner; $script = "jQuery(document).ready(function() {" . "RegularLabsScripts.addToLoadAjaxList(" . "'" . addslashes($url) . "'," . "'" . addslashes($success) . "'," . "'" . addslashes($error) . "'" . ")" . "});"; return '<script>' . $script . '</script>'; } /** * Render a simple select list loaded via Ajax * * @param string $field * @param string $name * @param string $value * @param string $id * @param array $attributes * * @return string */ public static function selectListSimpleAjax($field, $name, $value, $id, $attributes = []) { return self::selectListAjax($field, $name, $value, $id, $attributes, true); } /** * Prepare the string for a select form field item * * @param string $string * @param int $published * @param string $type * @param int $remove_first * * @return string */ public static function prepareSelectItem($string, $published = 1, $type = '', $remove_first = 0) { if (empty($string)) { return ''; } $string = str_replace([' ', ' '], ' ', $string); $string = RegEx::replace('- ', ' ', $string); for ($i = 0; $remove_first > $i; $i++) { $string = RegEx::replace('^ ', '', $string, ''); } if (RegEx::match('^( *)(.*)$', $string, $match, '')) { list($string, $pre, $name) = $match; $pre = str_replace(' ', ' · ', $pre); $pre = RegEx::replace('(( · )*) · ', '\1 » ', $pre); $pre = str_replace(' ', ' ', $pre); $string = $pre . $name; } switch (true) { case ($type == 'separator'): $string = '[[:font-weight:normal;font-style:italic;color:grey;:]]' . $string; break; case ($published == -2): $string = '[[:font-style:italic;color:grey;:]]' . $string . ' [' . JText::_('JTRASHED') . ']'; break; case ($published == 0): $string = '[[:font-style:italic;color:grey;:]]' . $string . ' [' . JText::_('JUNPUBLISHED') . ']'; break; case ($published == 2): $string = '[[:font-style:italic;:]]' . $string . ' [' . JText::_('JARCHIVED') . ']'; break; } return $string; } /** * Replace style placeholders with actual style attributes * * @param string $string * * @return string */ private static function handlePreparedStyles($string) { // No placeholders found if (strpos($string, '[[:') === false) { return $string; } // Doing following replacement in 3 steps to prevent the Regular Expressions engine from exploding // Replace style tags right after the html tags $string = RegEx::replace( ';?:\]\]\s*\[\[:', ';', $string ); $string = RegEx::replace( '>\s*\[\[\:(.*?)\:\]\]', ' style="\1">', $string ); // No more placeholders found if (strpos($string, '[[:') === false) { return $string; } // Replace style tags prepended with a minus and any amount of whitespace: '- ' $string = RegEx::replace( '>((?:-\s*)+)\[\[\:(.*?)\:\]\]', ' style="\2">\1', $string ); // No more placeholders found if (strpos($string, '[[:') === false) { return $string; } // Replace style tags prepended with whitespace, a minus and any amount of whitespace: ' - ' $string = RegEx::replace( '>((?:\s+-\s*)+)\[\[\:(.*?)\:\]\]', ' style="\2">\1', $string ); return $string; } } StringHelper.php 0000604 00000014441 15245535751 0007677 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\String\Normalise; use Normalizer; /** * Class StringHelper * @package RegularLabs\Library */ class StringHelper extends \Joomla\String\StringHelper { /** * Decode html entities in string or array of strings * * @param string $data * @param int $quote_style * @param string $encoding * * @return array|string */ public static function html_entity_decoder($data, $quote_style = ENT_QUOTES, $encoding = 'UTF-8') { if (is_array($data)) { array_walk($data, function (&$part, $key, $quote_style, $encoding) { $part = self::html_entity_decoder($part, $quote_style, $encoding); }, $quote_style, $encoding); return $data; } if ( ! is_string($data)) { return $data; } return html_entity_decode($data, $quote_style | ENT_HTML5, $encoding); } /** * Replace the given replace string once in the main string * * @param string $search * @param string $replace * @param string $string * * @return string */ public static function replaceOnce($search, $replace, $string) { if (empty($search) || empty($string)) { return $string; } $pos = strpos($string, $search); if ($pos === false) { return $string; } return substr_replace($string, $replace, $pos, strlen($search)); } /** * Check if any of the needles are found in any of the haystacks * * @param $haystacks * @param $needles * * @return bool */ public static function contains($haystacks, $needles) { $haystacks = (array) $haystacks; $needles = (array) $needles; foreach ($haystacks as $haystack) { foreach ($needles as $needle) { if (strpos($haystack, $needle) !== false) { return true; } } } return false; } /** * Check if string is alphanumerical * * @param string $string * * @return bool */ public static function is_alphanumeric($string) { if (function_exists('ctype_alnum')) { return (bool) ctype_alnum($string); } return (bool) RegEx::match('^[a-z0-9]+$', $string); } /** * Check if string is a valid key / alias (alphanumeric with optional _ or - chars) * * @param string $string * * @return bool */ public static function is_key($string) { return RegEx::match('^[a-z][a-z0-9-_]*$', trim($string)); } /** * Split a long string into parts (array) * * @param string $string * @param array $delimiters Array of strings to split the string on * @param int $max_length Maximum length of each part * @param bool $maximize_parts If true, the different parts will be made as large as possible (combining consecutive short string elements) * * @return array */ public static function split($string, $delimiters = [], $max_length = 10000, $maximize_parts = true) { // String is too short to split if (strlen($string) < $max_length) { return [$string]; } // No delimiters given or found if (empty($delimiters) || ! self::contains($string, $delimiters)) { return [$string]; } // preg_quote all delimiters $array = preg_split('#' . RegEx::quote($delimiters) . '#s', $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if ( ! $maximize_parts) { return $array; } $new_array = []; foreach ($array as $part) { // First element, add to new array if ( ! count($new_array)) { $new_array[] = $part; continue; } $last_part = end($new_array); $last_key = key($new_array); // If last and current parts are longer than max_length, then simply add as new value if (strlen($last_part) + strlen($part) > $max_length) { $new_array[] = $part; continue; } // Concatenate part to previous part $new_array[$last_key] .= $part; } return $new_array; } /** * Check whether string is a UTF-8 encoded string * * @param string $string * * @return bool */ public static function detectUTF8($string = '') { // Try to check the string via the mb_check_encoding function if (function_exists('mb_check_encoding')) { return mb_check_encoding($string, 'UTF-8'); } // Otherwise: Try to check the string via the iconv function if (function_exists('iconv')) { $converted = iconv('UTF-8', 'UTF-8//IGNORE', $string); return (md5($converted) == md5($string)); } // As last fallback, check if the preg_match finds anything using the unicode flag return preg_match('#.#u', $string); } /** * Converts a string to a UTF-8 encoded string * * @param string $string * * @return string */ public static function convertToUtf8($string = '') { if (self::detectUTF8($string)) { // Already UTF-8, so skip return $string; } if ( ! function_exists('iconv')) { // Still need to find a stable fallback return $string; } $utf8_string = @iconv('UTF8', 'UTF-8//IGNORE', $string); if (empty($utf8_string)) { return $string; } return $utf8_string; } /** * Converts a camelcased string to a underscore separated string * eg: FooBar => foo_bar * * @param string $string * @param bool $tolowercase * * @return string */ public static function camelToUnderscore($string = '', $tolowercase = true) { $string = Normalise::toUnderscoreSeparated(Normalise::fromCamelCase($string)); if ( ! $tolowercase) { return $string; } return strtolower($string); } /** * Removes html tags from string * * @param string $string * @param bool $remove_comments * * @return string */ public static function removeHtml($string, $remove_comments = false) { return Html::removeHtmlTags($string, $remove_comments); } /** * Normalizes the input provided and returns the normalized string * * @param string $string * * @return string */ public static function normalize($string, $tolowercase = false) { // Normalizer-class missing! if (class_exists('Normalizer', $autoload = false)) { $string = Normalizer::normalize($string); } if ( ! $tolowercase) { return $string; } return strtolower($string); } } Database.php 0000604 00000000720 15245535751 0006770 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * @depecated Use DB instead */ class Database extends DB { } RegEx.php 0000604 00000012577 15245535751 0006313 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * Class RegEx * @package RegularLabs\Library */ class RegEx { /** * Perform a regular expression search and replace * * @param string $pattern * @param string $replacement * @param string $string * @param string $options * @param int $limit * @param int $count * * @return string */ public static function replace($pattern, $replacement, $string, $options = null, $limit = -1, &$count = null) { if ( ! is_string($pattern) || $pattern == '' || ! is_string($string) || $string == '') { return $string; } $pattern = self::preparePattern($pattern, $options, $string); return preg_replace($pattern, $replacement, $string, $limit, $count); } /** * Perform a regular expression search and replace once * * @param string $pattern * @param string $replacement * @param string $string * @param string $options * * @return string */ public static function replaceOnce($pattern, $replacement, $string, $options = null) { return self::replace($pattern, $replacement, $string, $options, 1); } /** * Perform a regular expression match * * @param string $pattern * @param string $string * @param null $matches * @param string $options * @param int $flags * * @return int */ public static function match($pattern, $string, &$matches = null, $options = null, $flags = 0) { if ( ! is_string($pattern) || $pattern == '' || ! is_string($string) || $string == '') { return false; } $pattern = self::preparePattern($pattern, $options, $string); return preg_match($pattern, $string, $matches, $flags); } /** * Perform a global regular expression match * * @param string $pattern * @param string $string * @param null $matches * @param string $options * @param int $flags * * @return int */ public static function matchAll($pattern, $string, &$matches = null, $options = null, $flags = PREG_SET_ORDER) { if ( ! is_string($pattern) || $pattern == '' || ! is_string($string) || $string == '') { $matches = []; return false; } $pattern = self::preparePattern($pattern, $options, $string); return preg_match_all($pattern, $string, $matches, $flags); } /** * preg_quote the given string or array of strings * * @param string|array $data * @param string $name * @param string $delimiter * * @return string */ public static function quote($data, $name = '', $delimiter = '#', $capture = true) { if (is_array($data)) { $array = self::quoteArray($data, $delimiter); $prefix = '?!'; if ($capture) { $prefix = $name ? '?<' . $name . '>' : ''; } return '(' . $prefix . implode('|', $array) . ')'; } if ( ! empty($name)) { return '(?<' . $name . '>' . preg_quote($data, $delimiter) . ')'; } return preg_quote($data, $delimiter); } /** * reverse preg_quote the given string * * @param string $string * @param string $delimiter * * @return string */ public static function unquote($string, $delimiter = '#') { return strtr($string, [ '\\' . $delimiter => $delimiter, '\\.' => '.', '\\\\' => '\\', '\\+' => '+', '\\*' => '*', '\\?' => '?', '\\[' => '[', '\\^' => '^', '\\]' => ']', '\\$' => '$', '\\(' => '(', '\\)' => ')', '\\{' => '{', '\\}' => '}', '\\=' => '=', '\\!' => '!', '\\<' => '<', '\\>' => '>', '\\|' => '|', '\\:' => ':', '\\-' => '-', ]); } /** * preg_quote the given array of strings * * @param array $array * @param string $delimiter * * @return array */ public static function quoteArray($array = [], $delimiter = '#') { array_walk($array, function (&$part, $key, $delimiter) { $part = self::quote($part, '', $delimiter); }, $delimiter); return $array; } /** * Make a string a valid regular expression pattern * * @param string $pattern * @param string $options * @param string $string * * @return string */ public static function preparePattern($pattern, $options = null, $string = '') { if (is_array($pattern)) { return self::preparePatternArray($pattern, $options, $string); } if (substr($pattern, 0, 1) != '#') { $options = ! is_null($options) ? $options : 'si'; $pattern = '#' . $pattern . '#' . $options; } if (StringHelper::detectUTF8($string)) { // use utf-8 return $pattern . 'u'; } return $pattern; } /** * Make an array of strings valid regular expression patterns * * @param array $pattern * @param string $options * @param string $string * * @return array */ private static function preparePatternArray($pattern, $options = null, $string = '') { array_walk($pattern, function (&$subpattern, $key, $data) { $subpattern = self::preparePattern($subpattern, $data[0], $data[1]); }, [$options, $string]); return $pattern; } } Version.php 0000604 00000017704 15245535751 0006723 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper as JComponentHelper; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\HTML\HTMLHelper as JHtml; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Router\Route as JRoute; use Joomla\CMS\Session\Session as JSession; use Joomla\CMS\Uri\Uri as JUri; jimport('joomla.filesystem.file'); /** * Class Version * @package RegularLabs\Library */ class Version { /** * Get the version of the given extension * * @param $alias * @param string $type * @param string $folder * * @return string */ public static function get($alias, $type = 'component', $folder = 'system') { return trim(Extension::getXmlValue('version', $alias, $type, $folder)); } /** * Get the version of the given plugin * * @param $alias * @param string $folder * * @return string */ public static function getPluginVersion($alias, $folder = 'system') { return self::get($alias, 'plugin', $folder); } /** * Get the version of the given component * * @param $alias * * @return string */ public static function getComponentVersion($alias) { return self::get($alias, 'component'); } /** * Get the version of the given module * * @param $alias * * @return string */ public static function getModuleVersion($alias) { return self::get($alias, 'module'); } /** * Get the version message * * @param $alias * * @return string */ public static function getMessage($alias) { if ( ! $alias) { return ''; } $name = Extension::getNameByAlias($alias); $alias = Extension::getAliasByName($alias); if ( ! $version = self::get($alias)) { return ''; } Document::loadMainDependencies(); $url = 'download.regularlabs.com/extensions.xml?j=3&e=' . $alias; $script = " jQuery(document).ready(function() { RegularLabsScripts.loadajax( '" . $url . "', 'RegularLabsScripts.displayVersion( data, \"" . $alias . "\", \"" . str_replace(['FREE', 'PRO'], '', $version) . "\" )', 'RegularLabsScripts.displayVersion( \"\" )', null, null, null, (60 * 60) ); }); "; JFactory::getDocument()->addScriptDeclaration($script); return '<div class="alert alert-success" style="display:none;" id="regularlabs_version_' . $alias . '">' . self::getMessageText($alias, $name, $version) . '</div>'; } /** * Get the full footer * * @param $name * @param int $copyright * * @return string */ public static function getFooter($name, $copyright = true) { Document::loadMainDependencies(); $html = []; $html[] = '<div class="rl_footer_extension">' . self::getFooterName($name) . '</div>'; if ($copyright) { $html[] = '<div class="rl_footer_review">' . self::getFooterReview($name) . '</div>'; $html[] = '<div class="rl_footer_logo">' . self::getFooterLogo() . '</div>'; $html[] = '<div class="rl_footer_copyright">' . self::getFooterCopyright() . '</div>'; } return '<div class="rl_footer">' . implode('', $html) . '</div>'; } /** * Get the version message text * * @param $alias * @param $name * @param $version * * @return array|string */ private static function getMessageText($alias, $name, $version) { list($url, $onclick) = self::getUpdateLink($alias, $version); $href = $onclick ? '' : 'href="' . $url . '" target="_blank" '; $onclick = $onclick ? 'onclick="' . $onclick . '" ' : ''; $is_pro = strpos($version, 'PRO') !== false; $version = str_replace(['FREE', 'PRO'], ['', ' <small>[PRO]</small>'], $version); $msg = '<div class="text-center">' . '<span class="ghosted">' . JText::sprintf('RL_NEW_VERSION_OF_AVAILABLE', JText::_($name)) . '</span>' . '<br>' . '<a ' . $href . $onclick . ' class="btn btn-large btn-success">' . '<span class="icon-upload"></span> ' . StringHelper::html_entity_decoder(JText::sprintf('RL_UPDATE_TO', '<span id="regularlabs_newversionnumber_' . $alias . '"></span>')) . '</a>'; if ( ! $is_pro) { $msg .= ' <a href="https://regularlabs.com/purchase/cart/add/' . $alias . '" target="_blank" class="btn btn-large btn-primary">' . '<span class="icon-basket"></span> ' . JText::_('RL_GO_PRO') . '</a>'; } $msg .= '<br>' . '<span class="ghosted">' . '[ <a href="https://regularlabs.com/' . $alias . '/changelog" target="_blank">' . JText::_('RL_CHANGELOG') . '</a> ]' . '<br>' . JText::sprintf('RL_CURRENT_VERSION', $version) . '</span>' . '</div>'; return StringHelper::html_entity_decoder($msg); } /** * Get the url and onclick function for the update link * * @param $alias * @param $version * * @return array */ private static function getUpdateLink($alias, $version) { $is_pro = strpos($version, 'PRO') !== false; if ( ! file_exists(JPATH_ADMINISTRATOR . '/components/com_regularlabsmanager/regularlabsmanager.xml') || ! JComponentHelper::isInstalled('com_regularlabsmanager') || ! JComponentHelper::isEnabled('com_regularlabsmanager') ) { $url = $is_pro ? 'https://regularlabs.com/' . $alias . '/features' : JRoute::_('index.php?option=com_installer&view=update'); return [$url, '']; } $config = JComponentHelper::getParams('com_regularlabsmanager'); $key = trim($config->get('key')); if ($is_pro && ! $key) { return ['index.php?option=com_regularlabsmanager', '']; } jimport('joomla.filesystem.file'); Document::loadMainDependencies(); JHtml::_('behavior.modal'); JFactory::getDocument()->addScriptDeclaration( " var RLEM_TIMEOUT = " . (int) $config->get('timeout', 5) . "; var RLEM_TOKEN = '" . JSession::getFormToken() . "'; " ); Document::script('regularlabsmanager/script.min.js', '21.4.10972'); $url = 'https://download.regularlabs.com?ext=' . $alias . '&j=3'; if ($is_pro) { $url .= '&k=' . strtolower(substr($key, 0, 8) . md5(substr($key, 8))); } return ['', 'RegularLabsManager.openModal(\'update\', [\'' . $alias . '\'], [\'' . $url . '\'], true);']; } /** * Get the extension name and version for the footer * * @param $name * * @return string */ private static function getFooterName($name) { $name = JText::_($name); if ( ! $version = self::get($name)) { return $name; } if (strpos($version, 'PRO') !== false) { return $name . ' v' . str_replace('PRO', '', $version) . ' <small>[PRO]</small>'; } if (strpos($version, 'FREE') !== false) { return $name . ' v' . str_replace('FREE', '', $version) . ' <small>[FREE]</small>'; } return $name . ' v' . $version; } /** * Get the review text for the footer * * @param $name * * @return string */ private static function getFooterReview($name) { $alias = Extension::getAliasByName($name); $jed_url = 'http://regl.io/jed-' . $alias . '#reviews'; return StringHelper::html_entity_decoder( JText::sprintf( 'RL_JED_REVIEW', '<a href="' . $jed_url . '" target="_blank">', '</a>' . ' <a href="' . $jed_url . '" target="_blank" class="stars">' . str_repeat('<span class="icon-star"></span>', 5) . '</a>' ) ); } /** * Get the Regular Labs logo for the footer * * @return string */ private static function getFooterLogo() { return JText::sprintf( 'RL_POWERED_BY', '<a href="https://regularlabs.com" target="_blank">' . '<img src="' . JUri::root() . 'media/regularlabs/images/logo.svg" width="112" height="24" alt="Regular Labs">' . '</a>' ); } /** * Get the copyright text for the footer * * @return string */ private static function getFooterCopyright() { return JText::_('RL_COPYRIGHT') . ' © ' . date('Y') . ' Regular Labs - ' . JText::_('RL_ALL_RIGHTS_RESERVED'); } } Cache.php 0000604 00000003754 15245535751 0006301 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; /** * Class Cache * @package RegularLabs\Library */ class Cache { static $group = 'regularlabs'; static $cache = []; // Is the cached object in the cache memory? public static function has($id) { return isset(self::$cache[md5($id)]); } // Get the cached object from the cache memory public static function get($id) { $hash = md5($id); if ( ! isset(self::$cache[$hash])) { return false; } return is_object(self::$cache[$hash]) ? clone self::$cache[$hash] : self::$cache[$hash]; } // Save the cached object to the cache memory public static function set($id, $data) { self::$cache[md5($id)] = $data; return $data; } // Get the cached object from the Joomla cache public static function read($id) { if (JFactory::getApplication()->get('debug')) { return false; } $hash = md5($id); if (isset(self::$cache[$hash])) { return self::$cache[$hash]; } $cache = JFactory::getCache(self::$group, 'output'); return $cache->get($hash); } // Save the cached object to the Joomla cache public static function write($id, $data, $time_to_life_in_minutes = 0, $force_caching = true) { if (JFactory::getApplication()->get('debug')) { return $data; } $hash = md5($id); self::$cache[$hash] = $data; $cache = JFactory::getCache(self::$group, 'output'); if ($time_to_life_in_minutes) { // convert ttl to minutes $cache->setLifeTime($time_to_life_in_minutes * 60); } if ($force_caching) { $cache->setCaching(true); } $cache->store($data, $hash); self::set($hash, $data); return $data; } } Html.php 0000604 00000050112 15245535751 0006170 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use DOMDocument; /** * Class Html * @package RegularLabs\Library */ class Html { /** * Convert content saved in a WYSIWYG editor to plain text (like removing html tags) * * @param $string * * @return string */ public static function convertWysiwygToPlainText($string) { // replace chr style enters with normal enters $string = str_replace([chr(194) . chr(160), ' ', ' '], ' ', $string); // replace linebreak tags with normal linebreaks (paragraphs, enters, etc). $enter_tags = ['p', 'br']; $regex = '</?((' . implode(')|(', $enter_tags) . '))+[^>]*?>\n?'; $string = RegEx::replace($regex, " \n", $string); // replace indent characters with spaces $string = RegEx::replace('<img [^>]*/sourcerer/images/tab\.png[^>]*>', ' ', $string); // strip all other tags $regex = '<(/?\w+((\s+\w+(\s*=\s*(?:".*?"|\'.*?\'|[^\'">\s]+))?)+\s*|\s*)/?)>'; $string = RegEx::replace($regex, '', $string); // reset htmlentities $string = StringHelper::html_entity_decoder($string); // convert protected html entities &_...; -> &...; $string = RegEx::replace('&_([a-z0-9\#]+?);', '&\1;', $string); return $string; } /** * Extract the <body>...</body> part from an entire html output string * * @param string $html * * @return array */ public static function getBody($html, $include_body_tag = true) { if (strpos($html, '<body') === false || strpos($html, '</body>') === false) { return ['', $html, '']; } // Force string to UTF-8 $html = StringHelper::convertToUtf8($html); $split = explode('<body', $html, 2); $pre = $split[0]; $split = explode('>', $split[1], 2); $body_start = '<body' . $split[0] . '>'; $body_end = '</body>'; $split = explode('</body>', $split[1]); $post = array_pop($split); $body = implode('</body>', $split); if ( ! $include_body_tag) { return [ $pre . $body_start, $body, $body_end . $post, ]; } return [ $pre, $body_start . $body . $body_end, $post, ]; } /** * Search the string for the start and end searches and split the string in a pre, body and post part * This is used to be able to do replacements on the body part, which will be lighter than doing it on the entire string * * @param string $string * @param array $start_searches * @param array $end_searches * @param int $start_offset * @param null $end_offset * * @return array */ public static function getContentContainingSearches($string, $start_searches = [], $end_searches = [], $start_offset = 1000, $end_offset = null) { // String is too short to split and search through if (strlen($string) < 2000) { return ['', $string, '']; } $end_offset = is_null($end_offset) ? $start_offset : $end_offset; $found = false; $start_split = strlen($string); foreach ($start_searches as $search) { $pos = strpos($string, $search); if ($pos === false) { continue; } $start_split = min($start_split, $pos); $found = true; } // No searches are found if ( ! $found) { return [$string, '', '']; } // String is too short to split if (strlen($string) < ($start_offset + $end_offset + 1000)) { return ['', $string, '']; } $start_split = max($start_split - $start_offset, 0); $pre = substr($string, 0, $start_split); $string = substr($string, $start_split); self::fixBrokenTagsByPreString($pre, $string); if (empty($end_searches)) { $end_searches = $start_searches; } $end_split = 0; $found = false; foreach ($end_searches as $search) { $pos = strrpos($string, $search); if ($pos === false) { continue; } $end_split = max($end_split, $pos + strlen($search)); $found = true; } // No end split is found, so don't split remainder if ( ! $found) { return [$pre, $string, '']; } $end_split = min($end_split + $end_offset, strlen($string)); $post = substr($string, $end_split); $string = substr($string, 0, $end_split); self::fixBrokenTagsByPostString($post, $string); return [$pre, $string, $post]; } /** * Check if string contains block elements * * @param string $string * * @return string */ public static function containsBlockElements($string) { return RegEx::match('</?(' . implode('|', self::getBlockElements()) . ')(?: [^>]*)?>', $string); } /** * Fix broken/invalid html syntax in a string * * @param string $string * * @return string */ public static function fix($string) { if ( ! self::containsBlockElements($string)) { return $string; } // Convert utf8 characters to html entities if (function_exists('mb_convert_encoding')) { $string = mb_convert_encoding($string, 'html-entities', 'utf-8'); } $string = self::protectSpecialCode($string); $string = self::convertDivsInsideInlineElementsToSpans($string); $string = self::removeParagraphsAroundBlockElements($string); $string = self::removeInlineElementsAroundBlockElements($string); $string = self::fixParagraphsAroundParagraphElements($string); $string = class_exists('DOMDocument') ? self::fixUsingDOMDocument($string) : self::fixUsingCustomFixer($string); $string = self::unprotectSpecialCode($string); // Convert html entities back to utf8 characters if (function_exists('mb_convert_encoding')) { // Make sure < and > don't get converted $string = str_replace(['<', '>'], ['&lt;', '&gt;'], $string); $string = mb_convert_encoding($string, 'utf-8', 'html-entities'); } $string = self::removeParagraphsAroundComments($string); return $string; } /** * Fix broken/invalid html syntax in an array of strings * * @param array $array * * @return array */ public static function fixArray($array) { $splitter = ':|:'; $string = self::fix(implode($splitter, $array)); $parts = self::removeEmptyTags(explode($splitter, $string)); // use original keys but new values return array_combine(array_keys($array), $parts); } /** * Removes empty tags which span concatenating parts in the array * * @param array $array * * @return array */ public static function removeEmptyTags($array) { $splitter = ':|:'; $comments = '(?:\s*<\!--[^>]*-->\s*)*'; $string = implode($splitter, $array); Protect::protectHtmlCommentTags($string); $string = RegEx::replace( '<([a-z][a-z0-9]*)(?: [^>]*)?>\s*(' . $comments . RegEx::quote($splitter) . $comments . ')\s*</\1>', '\2', $string ); Protect::unprotect($string); return explode($splitter, $string); } /** * Fix broken/invalid html syntax in a string using php DOMDocument functionality * * @param string $string * * @return mixed */ private static function fixUsingDOMDocument($string) { $doc = new DOMDocument; $doc->substituteEntities = false; list($pre, $body, $post) = Html::getBody($string, false); // Add temporary document structures $body = '<html><body><div>' . $body . '</div></body></html>'; @$doc->loadHTML($body); $body = $doc->saveHTML(); if (strpos($doc->documentElement->textContent, 'Ã') !== false) { // Need to do this utf8 workaround to deal with special characters // DOMDocument doesn't seem to deal with them very well // See: https://stackoverflow.com/questions/8218230/php-domdocument-loadhtml-not-encoding-utf-8-correctly/47396055#47396055 $body = utf8_decode($doc->saveHTML($doc->documentElement)); } // Remove temporary document structures and surrounding div $body = RegEx::replace('^.*?<html>.*?(?:<head>(.*)</head>.*?)?<body>\s*<div>(.*)</div>\s*</body>.*?$', '\1\2', $body); // Remove leading/trailing empty paragraph $body = RegEx::replace('(^\s*<div>\s*</div>|<div>\s*</div>\s*$)', '', $body); // Remove leading/trailing empty paragraph $body = RegEx::replace('(^\s*<div>\s*</div>|<div>\s*</div>\s*$)', '', $body); // Remove leading/trailing empty paragraph $body = RegEx::replace('(^\s*<p(?: [^>]*)?>\s*</p>|<p(?: [^>]*)?>\s*</p>\s*$)', '', $body); return $pre . $body . $post; } /** * Fix broken/invalid html syntax in a string using custom code as an alternative to php DOMDocument functionality * * @param string $string * * @return string */ private static function fixUsingCustomFixer($string) { $block_regex = '<(' . implode('|', self::getBlockElementsNoDiv()) . ')[\s>]'; $string = RegEx::replace('(' . $block_regex . ')', '[:SPLIT-BLOCK:]\1', $string); $parts = explode('[:SPLIT-BLOCK:]', $string); foreach ($parts as $i => &$part) { if ( ! RegEx::match('^' . $block_regex, $part, $type)) { continue; } $type = strtolower($type[1]); // remove endings of other block elements $part = RegEx::replace('</(?:' . implode('|', self::getBlockElementsNoDiv($type)) . ')>', '', $part); if (strpos($part, '</' . $type . '>') !== false) { continue; } // Add ending tag once $part = RegEx::replaceOnce('(\s*)$', '</' . $type . '>\1', $part); // Remove empty block tags $part = RegEx::replace('^<' . $type . '(?: [^>]*)?>\s*</' . $type . '>', '', $part); } return implode('', $parts); } /** * Removes complete html tag pairs from the concatenated parts * * @param array $parts * @param array $elements * * @return array */ public static function cleanSurroundingTags($parts, $elements = ['p', 'span']) { $breaks = '(?:(?:<br ?/?>|<\!--[^>]*-->|:\|:)\s*)*'; $keys = array_keys($parts); $string = implode(':|:', $parts); Protect::protectHtmlCommentTags($string); // Remove empty tags $regex = '<(' . implode('|', $elements) . ')(?: [^>]*)?>\s*(' . $breaks . ')<\/\1>\s*'; while (RegEx::match($regex, $string, $match)) { $string = str_replace($match[0], $match[2], $string); } // Remove paragraphs around block elements $block_elements = [ 'p', 'div', 'table', 'tr', 'td', 'thead', 'tfoot', 'h[1-6]', ]; $block_elements = '(' . implode('|', $block_elements) . ')'; $regex = '(<p(?: [^>]*)?>)(\s*' . $breaks . ')(<' . $block_elements . '(?: [^>]*)?>)'; while (RegEx::match($regex, $string, $match)) { if ($match[4] == 'p') { $match[3] = $match[1] . $match[3]; self::combinePTags($match[3]); } $string = str_replace($match[0], $match[2] . $match[3], $string); } $regex = '(</' . $block_elements . '>\s*' . $breaks . ')</p>'; while (RegEx::match($regex, $string, $match)) { $string = str_replace($match[0], $match[1], $string); } Protect::unprotect($string); $parts = explode(':|:', $string); $new_tags = []; foreach ($parts as $key => $val) { $key = isset($keys[$key]) ? $keys[$key] : $key; $new_tags[$key] = $val; } return $new_tags; } /** * Remove <p> tags around block elements * * @param string $string * * @return mixed */ private static function removeParagraphsAroundBlockElements($string) { if (strpos($string, '</p>') == false) { return $string; } Protect::protectHtmlCommentTags($string); $string = RegEx::replace( '<p(?: [^>]*)?>\s*' . '((?:<\!--[^>]*-->\s*)*</?(?:' . implode('|', self::getBlockElements()) . ')' . '(?: [^>]*)?>)', '\1', $string ); $string = RegEx::replace( '(</?(?:' . implode('|', self::getBlockElements()) . ')' . '(?: [^>]*)?>(?:\s*<\!--[^>]*-->)*)' . '(?:\s*</p>)', '\1', $string ); Protect::unprotect($string); return $string; } /** * Remove <p> tags around comments * * @param string $string * * @return mixed */ private static function removeParagraphsAroundComments($string) { if (strpos($string, '</p>') == false) { return $string; } Protect::protectHtmlCommentTags($string); $string = RegEx::replace( '(?:<p(?: [^>]*)?>\s*)' . '(<\!--[^>]*-->)' . '(?:\s*</p>)', '\1', $string ); Protect::unprotect($string); return $string; } /** * Fix <p> tags around other <p> elements * * @param string $string * * @return mixed */ private static function fixParagraphsAroundParagraphElements($string) { if (strpos($string, '</p>') == false) { return $string; } $parts = explode('</p>', $string); $ending = '</p>' . array_pop($parts); foreach ($parts as &$part) { if (strpos($part, '<p>') === false && strpos($part, '<p ') === false) { $part = '<p>' . $part; continue; } $part = RegEx::replace( '(<p(?: [^>]*)?>.*?)(<p(?: [^>]*)?>)', '\1</p>\2', $part ); } return implode('</p>', $parts) . $ending; } /* * Remove empty tags * * @param string $string * @param array $elements * * @return mixed */ public static function removeEmptyTagPairs($string, $elements = ['p', 'span']) { $breaks = '(?:(?:<br ?/?>|<\!--[^>]*-->)\s*)*'; $regex = '<(' . implode('|', $elements) . ')(?: [^>]*)?>\s*(' . $breaks . ')<\/\1>\s*'; Protect::protectHtmlCommentTags($string); while (RegEx::match($regex, $string, $match)) { $string = str_replace($match[0], $match[2], $string); } Protect::unprotect($string); return $string; } /** * Convert <div> tags inside inline elements to <span> tags * * @param string $string * * @return mixed */ private static function convertDivsInsideInlineElementsToSpans($string) { if (strpos($string, '</div>') == false) { return $string; } // Ignore block elements inside anchors $regex = '<(' . implode('|', self::getInlineElementsNoAnchor()) . ')(?: [^>]*)?>.*?</\1>'; RegEx::matchAll($regex, $string, $matches, '', PREG_PATTERN_ORDER); if (empty($matches)) { return $string; } $matches = array_unique($matches[0]); $searches = []; $replacements = []; foreach ($matches as $match) { if (strpos($match, '</div>') === false) { continue; } $searches[] = $match; $replacements[] = str_replace( ['<div>', '<div ', '</div>'], ['<span>', '<span ', '</span>'], $match ); } if (empty($searches)) { return $string; } return str_replace($searches, $replacements, $string); } /** * Combine duplicate <p> tags * input: <p class="aaa" a="1"><!-- ... --><p class="bbb" b="2"> * output: <p class="aaa bbb" a="1" b="2"><!-- ... --> * * @param $string */ public static function combinePTags(&$string) { if (empty($string)) { return; } $p_start_tag = '<p(?: [^>]*)?>'; $optional_tags = '\s*(?:<\!--[^>]*-->| |&\#160;)*\s*'; Protect::protectHtmlCommentTags($string); RegEx::matchAll('(' . $p_start_tag . ')(' . $optional_tags . ')(' . $p_start_tag . ')', $string, $tags); if (empty($tags)) { Protect::unprotect($string); return; } foreach ($tags as $tag) { $string = str_replace($tag[0], $tag[2] . HtmlTag::combine($tag[1], $tag[3]), $string); } Protect::unprotect($string); } /** * Remove inline elements around block elements * * @param string $string * * @return mixed */ public static function removeInlineElementsAroundBlockElements($string) { $string = RegEx::replace( '(?:<(?:' . implode('|', self::getInlineElementsNoAnchor()) . ')(?: [^>]*)?>\s*)' . '(</?(?:' . implode('|', self::getBlockElements()) . ')(?: [^>]*)?>)', '\1', $string ); $string = RegEx::replace( '(</?(?:' . implode('|', self::getBlockElements()) . ')(?: [^>]*)?>)' . '(?:\s*</(?:' . implode('|', self::getInlineElementsNoAnchor()) . ')>)', '\1', $string ); return $string; } /** * Return an array of block element names, optionally without any of the names given $exclude * * @param array $exclude * * @return array */ public static function getBlockElements($exclude = []) { if ( ! is_array($exclude)) { $exclude = [$exclude]; } $elements = [ 'div', 'p', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', ]; $elements = array_diff($elements, $exclude); $elements = implode(',', $elements); $elements = str_replace('h1,h2,h3,h4,h5,h6', 'h[1-6]', $elements); $elements = explode(',', $elements); return $elements; } /** * Return an array of inline element names, optionally without any of the names given $exclude * * @param array $exclude * * @return array */ public static function getInlineElements($exclude = []) { if ( ! is_array($exclude)) { $exclude = [$exclude]; } $elements = [ 'span', 'code', 'a', 'strong', 'b', 'em', 'i', 'u', 'big', 'small', 'font', 'sup', 'sub', ]; return array_diff($elements, $exclude); } /** * Return an array of block element names, without divs and any of the names given $exclude * * @param array $exclude * * @return array */ public static function getBlockElementsNoDiv($exclude = []) { return array_diff(self::getBlockElements($exclude), ['div']); } /** * Return an array of block element names, without anchors (a) and any of the names given $exclude * * @param array $exclude * * @return array */ public static function getInlineElementsNoAnchor($exclude = []) { return array_diff(self::getInlineElements($exclude), ['a']); } /** * Protect plugin style tags and php * * @param $string * * @return mixed */ private static function protectSpecialCode($string) { // Protect PHP code Protect::protectByRegex($string, '(<|<)\?php\s.*?\?(>|>)'); // Protect {...} tags Protect::protectByRegex($string, '\{[a-z0-9].*?\}'); // Protect [...] tags Protect::protectByRegex($string, '\[[a-z0-9].*?\]'); // Protect scripts Protect::protectByRegex($string, '<script[^>]*>.*?</script>'); // Protect css Protect::protectByRegex($string, '<style[^>]*>.*?</style>'); Protect::convertProtectionToHtmlSafe($string); return $string; } /** * Unprotect protected tags * * @param $string * * @return mixed */ private static function unprotectSpecialCode($string) { Protect::unprotectHtmlSafe($string); return $string; } /** * Prevents broken html tags at the end of $pre (other half at beginning of $string) * It will move the broken part to the beginning of $string to complete it * * @param $pre * @param $string */ private static function fixBrokenTagsByPreString(&$pre, &$string) { if ( ! RegEx::match('<(\![^>]*|/?[a-z][^>]*(="[^"]*)?)$', $pre, $match)) { return; } $pre = substr($pre, 0, strlen($pre) - strlen($match[0])); $string = $match[0] . $string; } /** * Prevents broken html tags at the beginning of $pre (other half at end of $string) * It will move the broken part to the end of $string to complete it * * @param $post * @param $string */ private static function fixBrokenTagsByPostString(&$post, &$string) { if ( ! RegEx::match('<(\![^>]*|/?[a-z][^>]*(="[^"]*)?)$', $string, $match)) { return; } if ( ! RegEx::match('^[^>]*>', $post, $match)) { return; } $post = substr($post, strlen($match[0])); $string .= $match[0]; } /** * Removes html tags from string * * @param string $string * @param bool $remove_comments * * @return string */ public static function removeHtmlTags($string, $remove_comments = false) { // remove pagenavcounter $string = RegEx::replace('<div class="pagenavcounter">.*?</div>', ' ', $string); // remove pagenavbar $string = RegEx::replace('<div class="pagenavbar">(<div>.*?</div>)*</div>', ' ', $string); // remove inline scripts $string = RegEx::replace('<script[^a-z0-9].*?</script>', '', $string); $string = RegEx::replace('<noscript[^a-z0-9].*?</noscript>', '', $string); // remove inline styles $string = RegEx::replace('<style[^a-z0-9].*?</style>', '', $string); // remove inline html tags $string = RegEx::replace( '</?(' . implode('|', self::getInlineElements()) . ')( [^>]*)?>', '', $string ); if ($remove_comments) { // remove html comments $string = RegEx::replace('<!--.*?-->', ' ', $string); } // replace other tags with a space $string = RegEx::replace('</?[a-z].*?>', ' ', $string); // remove double whitespace $string = trim(RegEx::replace('(\s)[ ]+', '\1', $string)); return $string; } } Http.php 0000604 00000007410 15245535751 0006206 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Http\HttpFactory as JHttpFactory; use Joomla\Registry\Registry; use RuntimeException; /** * Class Http * @package RegularLabs\Library */ class Http { /** * Get the contents of the given internal url * * @param string $url * @param int $timeout * * @return string */ public static function get($url, $timeout = 20) { if (Uri::isExternal($url)) { return ''; } return @file_get_contents($url) || self::getFromUrl($url, $timeout); } /** * Get the contents of the given url * * @param string $url * @param int $timeout * * @return string */ public static function getFromUrl($url, $timeout = 20) { $cache_id = 'getUrl_' . $url; if (Cache::has($cache_id)) { return Cache::get($cache_id); } if (JFactory::getApplication()->input->getInt('cache', 0) && $content = Cache::read($cache_id) ) { return $content; } $content = self::getContents($url, $timeout); if (empty($content)) { return ''; } if ($ttl = JFactory::getApplication()->input->getInt('cache', 0)) { return Cache::write($cache_id, $content, $ttl > 1 ? $ttl : 0); } return Cache::set($cache_id, $content); } /** * Get the contents of the given external url from the Regular Labs server * * @param string $url * @param int $timeout * * @return string */ public static function getFromServer($url, $timeout = 20) { $cache_id = 'getByUrl_' . $url; if (Cache::has($cache_id)) { return Cache::get($cache_id); } // only allow url calls from administrator if ( ! Document::isClient('administrator')) { die; } // only allow when logged in $user = JFactory::getUser(); if ( ! $user->id) { die; } if (substr($url, 0, 4) != 'http') { $url = 'http://' . $url; } // only allow url calls to regularlabs.com domain if ( ! (RegEx::match('^https?://([^/]+\.)?regularlabs\.com/', $url))) { die; } // only allow url calls to certain files if ( strpos($url, 'download.regularlabs.com/extensions.php') === false && strpos($url, 'download.regularlabs.com/extensions.json') === false && strpos($url, 'download.regularlabs.com/extensions.xml') === false ) { die; } $content = self::getContents($url, $timeout); if (empty($content)) { return ''; } $format = (strpos($url, '.json') !== false || strpos($url, 'format=json') !== false) ? 'application/json' : 'text/xml'; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-type: " . $format); if ($ttl = JFactory::getApplication()->input->getInt('cache', 0)) { return Cache::write($cache_id, $content, $ttl > 1 ? $ttl : 0); } return Cache::set($cache_id, $content); } /** * Load the contents of the given url * * @param string $url * @param int $timeout * * @return string */ private static function getContents($url, $timeout = 20) { try { // Adding a valid user agent string, otherwise some feed-servers returning an error $options = new Registry([ 'userAgent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0', ]); $content = JHttpFactory::getHttp($options)->get($url, null, $timeout)->body; } catch (RuntimeException $e) { return ''; } return $content; } } Parameters.php 0000604 00000016562 15245535751 0007402 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper as JComponentHelper; use Joomla\CMS\Filesystem\File as JFile; use Joomla\CMS\Plugin\PluginHelper as JPluginHelper; jimport('joomla.filesystem.file'); /** * Class Parameters * @package RegularLabs\Library */ class Parameters { public static $instance = null; /** * @return static instance */ public static function getInstance() { if (is_null(self::$instance)) { self::$instance = new static; } return self::$instance; } /** * Get a usable parameter object based on the Joomla Registry object * The object will have all the available parameters with their value (default value if none is set) * * @param \Registry $params * @param string $path * @param string $default * * @return object */ public function getParams($params, $path = '', $default = '', $use_cache = true) { $cache_id = 'getParams_' . json_encode($params) . '_' . $path . '_' . $default; if ($use_cache && Cache::has($cache_id)) { return Cache::get($cache_id); } $xml = $this->loadXML($path, $default); if (empty($params)) { return Cache::set( $cache_id, (object) $xml ); } if ( ! is_object($params)) { $params = json_decode($params); if (is_null($xml)) { $xml = (object) []; } } elseif (method_exists($params, 'toObject')) { $params = $params->toObject(); } if ( ! $params) { return Cache::set( $cache_id, (object) $xml ); } if (empty($xml)) { return Cache::set( $cache_id, $params ); } foreach ($xml as $key => $val) { if (isset($params->{$key}) && $params->{$key} != '') { continue; } $params->{$key} = $val; } return Cache::set( $cache_id, $params ); } /** * Get a usable parameter object for the component * * @param string $name * @param \Registry $params * * @return object */ public function getComponentParams($name, $params = null, $use_cache = true) { $name = 'com_' . RegEx::replace('^com_', '', $name); $cache_id = 'getComponentParams_' . $name . '_' . json_encode($params); if ($use_cache && Cache::has($cache_id)) { return Cache::get($cache_id); } if (empty($params) && JComponentHelper::isInstalled($name)) { $params = JComponentHelper::getParams($name); } return Cache::set( $cache_id, $this->getParams($params, JPATH_ADMINISTRATOR . '/components/' . $name . '/config.xml') ); } /** * Get a usable parameter object for the module * * @param string $name * @param int $admin * @param \Registry $params * * @return object */ public function getModuleParams($name, $admin = true, $params = '', $use_cache = true) { $name = 'mod_' . RegEx::replace('^mod_', '', $name); $cache_id = 'getModuleParams_' . $name . '_' . json_encode($params); if ($use_cache && Cache::has($cache_id)) { return Cache::get($cache_id); } if (empty($params)) { $params = null; } return Cache::set( $cache_id, $this->getParams($params, ($admin ? JPATH_ADMINISTRATOR : JPATH_SITE) . '/modules/' . $name . '/' . $name . '.xml') ); } /** * Get a usable parameter object for the plugin * * @param string $name * @param string $type * @param \Registry $params * * @return object */ public function getPluginParams($name, $type = 'system', $params = '', $use_cache = true) { $cache_id = 'getPluginParams_' . $name . '_' . $type . '_' . json_encode($params); if ($use_cache && Cache::has($cache_id)) { return Cache::get($cache_id); } if (empty($params)) { $plugin = JPluginHelper::getPlugin($type, $name); $params = (is_object($plugin) && isset($plugin->params)) ? $plugin->params : null; } return Cache::set( $cache_id, $this->getParams($params, JPATH_PLUGINS . '/' . $type . '/' . $name . '/' . $name . '.xml') ); } /** * Returns an object based on the data in a given xml array * * @param $xml * * @return bool|mixed */ public function getObjectFromXml(&$xml, $use_cache = true) { $cache_id = 'getObjectFromXml_' . json_encode($xml); if ($use_cache && Cache::has($cache_id)) { return Cache::get($cache_id); } if ( ! is_array($xml)) { $xml = [$xml]; } $object = $this->getObjectFromXmlNode($xml); return Cache::set( $cache_id, $object ); } /** * Returns an array based on the data in a given xml file * * @param string $path * @param string $default * * @return array */ private function loadXML($path, $default = '', $use_cache = true) { $cache_id = 'loadXML_' . $path . '_' . $default; if ($use_cache && Cache::has($cache_id)) { return Cache::get($cache_id); } if ( ! $path || ! file_exists($path) || ! $file = file_get_contents($path) ) { return Cache::set( $cache_id, [] ); } $xml = []; $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $file, $fields); xml_parser_free($xml_parser); $default = $default ? strtoupper($default) : 'DEFAULT'; foreach ($fields as $field) { if ($field['tag'] != 'FIELD' || ! isset($field['attributes']) || ! isset($field['attributes']['NAME']) || $field['attributes']['NAME'] == '' || $field['attributes']['NAME'][0] == '@' || ! isset($field['attributes']['TYPE']) || $field['attributes']['TYPE'] == 'spacer' ) { continue; } if (isset($field['attributes'][$default])) { $field['attributes']['DEFAULT'] = $field['attributes'][$default]; } if ( ! isset($field['attributes']['DEFAULT'])) { $field['attributes']['DEFAULT'] = ''; } if ($field['attributes']['TYPE'] == 'textarea') { $field['attributes']['DEFAULT'] = str_replace('<br>', "\n", $field['attributes']['DEFAULT']); } $xml[$field['attributes']['NAME']] = $field['attributes']['DEFAULT']; } return Cache::set( $cache_id, $xml ); } /** * Returns the main attributes key from an xml object * * @param $xml * * @return mixed */ private function getKeyFromXML($xml) { if ( ! empty($xml->_attributes) && isset($xml->_attributes['name'])) { return $xml->_attributes['name']; } return $xml->_name; } /** * Returns the value from an xml object / node * * @param $xml * * @return object */ private function getValFromXML($xml) { if ( ! empty($xml->_attributes) && isset($xml->_attributes['value'])) { return $xml->_attributes['value']; } if (empty($xml->_children)) { return $xml->_data; } return $this->getObjectFromXmlNode($xml->_children); } /** * Create an object from the given xml node * * @param $xml * * @return object */ private function getObjectFromXmlNode($xml) { $object = (object) []; foreach ($xml as $child) { $key = $this->getKeyFromXML($child); $value = $this->getValFromXML($child); if ( ! isset($object->{$key})) { $object->{$key} = $value; continue; } if ( ! is_array($object->{$key})) { $object->{$key} = [$object->{$key}]; } $object->{$key}[] = $value; } return $object; } } Field.php 0000604 00000020120 15245535751 0006303 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Form\Form as JForm; use Joomla\CMS\HTML\HTMLHelper as JHtml; use Joomla\CMS\Language\Text as JText; /** * Class Field * @package RegularLabs\Library */ class Field extends \JFormField { /** * @var string */ public $type = 'Field'; /** * @var \JDatabaseDriver|null */ public $db = null; /** * @var int */ public $max_list_count = 0; /** * @var null */ public $params = null; public $context = 'com_content.article'; /** * @param JForm $form */ public function __construct($form = null) { parent::__construct($form); $this->db = JFactory::getDbo(); $params = Parameters::getInstance()->getPluginParams('regularlabs'); $this->max_list_count = $params->max_list_count; Document::loadFormDependencies(); Document::stylesheet('regularlabs/style.min.css'); } public function setup(\SimpleXMLElement $element, $value, $group = null) { $this->params = $element->attributes(); return parent::setup($element, $value, $group); } /** * Return the field input markup * Return empty by default * * @return string */ protected function getInput() { return ''; } /** * Return the field options (array) * Overrules the Joomla core functionality * * @return array */ protected function getOptions() { // This only returns 1 option!!! if (empty($this->element->option)) { return []; } $option = $this->element->option; $fieldname = RegEx::replace('[^a-z0-9_\-]', '_', $this->fieldname); $value = (string) $option['value']; $text = trim((string) $option) ? trim((string) $option) : $value; return [ [ 'value' => $value, 'text' => '- ' . JText::alt($text, $fieldname) . ' -', ], ]; } public static function selectList(&$options, $name, $value, $id, $size = 0, $multiple = false, $simple = false) { return Form::selectlist($options, $name, $value, $id, $size, $multiple, $simple); } public static function selectListSimple(&$options, $name, $value, $id, $size = 0, $multiple = false, $ignore_max_count = false) { return Form::selectListSimple($options, $name, $value, $id, $size, $multiple, false, $ignore_max_count); } public static function selectListAjax($field, $name, $value, $id, $attributes = [], $simple = false) { return Form::selectListAjax($field, $name, $value, $id, $attributes, $simple); } public static function selectListSimpleAjax($field, $name, $value, $id, $attributes = []) { return Form::selectListSimpleAjax($field, $name, $value, $id, $attributes); } /** * Get a value from the field params * * @param string $key * @param string $default * * @return bool|string */ public function get($key, $default = '') { $value = $default; if (isset($this->params[$key]) && (string) $this->params[$key] != '') { $value = (string) $this->params[$key]; } if ($value === 'true') { return true; } if ($value === 'false') { return false; } return $value; } /** * Return a array of options using the custom prepare methods * * @param array $list * @param array $extras * @param int $levelOffset * * @return array */ function getOptionsByList($list, $extras = [], $levelOffset = 0) { $options = []; foreach ($list as $id => $item) { $options[$id] = $this->getOptionByListItem($item, $extras, $levelOffset); } return $options; } /** * Return a list option using the custom prepare methods * * @param object $item * @param array $extras * @param int $levelOffset * * @return mixed */ function getOptionByListItem($item, $extras = [], $levelOffset = 0) { $name = trim($item->name); foreach ($extras as $key => $extra) { if (empty($item->{$extra})) { continue; } if ($extra == 'language' && $item->{$extra} == '*') { continue; } if (in_array($extra, ['id', 'alias']) && $item->{$extra} == $item->name) { continue; } $name .= ' [' . $item->{$extra} . ']'; } $name = Form::prepareSelectItem($name, isset($item->published) ? $item->published : 1); $option = JHtml::_('select.option', $item->id, $name, 'value', 'text', 0); if (isset($item->level)) { $option->level = $item->level + $levelOffset; } return $option; } /** * Return a recursive options list using the custom prepare methods * * @param array $items * @param int $root * * @return array */ function getOptionsTreeByList($items = [], $root = 0) { // establish the hierarchy of the menu // TODO: use node model $children = []; if ( ! empty($items)) { // first pass - collect children foreach ($items as $v) { $pt = $v->parent_id; $list = @$children[$pt] ? $children[$pt] : []; array_push($list, $v); $children[$pt] = $list; } } // second pass - get an indent list of the items $list = JHtml::_('menu.treerecurse', $root, '', [], $children, 9999, 0, 0); // assemble items to the array $options = []; if ($this->get('show_ignore')) { if (in_array('-1', $this->value)) { $this->value = ['-1']; } $options[] = JHtml::_('select.option', '-1', '- ' . JText::_('RL_IGNORE') . ' -', 'value', 'text', 0); $options[] = JHtml::_('select.option', '-', ' ', 'value', 'text', 1); } foreach ($list as $item) { $item->treename = Form::prepareSelectItem($item->treename, isset($item->published) ? $item->published : 1, '', 1); $options[] = JHtml::_('select.option', $item->id, $item->treename, 'value', 'text', 0); } return $options; } /** * Prepare the option string, handling language strings * * @param string $string * * @return string */ public function prepareText($string = '') { $string = trim($string); if ($string == '') { return ''; } switch (true) { // Old fields using var attributes case (JText::_($this->get('var1'))): $string = $this->sprintf_old($string); break; // Normal language string default: $string = JText::_($string); } return $this->fixLanguageStringSyntax($string); } /** * Fix some syntax/encoding issues in option text strings * * @param string $string * * @return string */ private function fixLanguageStringSyntax($string = '') { $string = str_replace('[:COMMA:]', ',', $string); $string = trim(StringHelper::html_entity_decoder($string)); $string = str_replace('"', '"', $string); $string = str_replace('span style="font-family:monospace;"', 'span class="rl_code"', $string); return $string; } /** * Replace language strings in a string * * @param string $string * * @return string */ private function sprintf($string = '') { $string = trim($string); if (strpos($string, ',') === false) { return $string; } $string_parts = explode(',', $string); $first_part = array_shift($string_parts); if ($first_part === strtoupper($first_part)) { $first_part = JText::_($first_part); } $first_part = RegEx::replace('\[\[%([0-9]+):[^\]]*\]\]', '%\1$s', $first_part); array_walk($string_parts, '\RegularLabs\Library\Field::jText'); return vsprintf($first_part, $string_parts); } /** * Passes along to the JText method. * This is used for the array_walk in the sprintf method above. * * @param $string */ public function jText(&$string) { $string = JText::_($string); } /** * Replace language strings in an old syntax string * * @param string $string * * @return string */ private function sprintf_old($string = '') { // variables $var1 = JText::_($this->get('var1')); $var2 = JText::_($this->get('var2')); $var3 = JText::_($this->get('var3')); $var4 = JText::_($this->get('var4')); $var5 = JText::_($this->get('var5')); return JText::sprintf(JText::_(trim($string)), $var1, $var2, $var3, $var4, $var5); } } ActionLogPlugin.php 0000604 00000014055 15245535751 0010330 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\Language\Text as JText; use Joomla\CMS\Plugin\CMSPlugin as JPlugin; /** * Class ActionLogPlugin * @package RegularLabs\Library */ class ActionLogPlugin extends JPlugin { public $name = ''; public $alias = ''; public $option = ''; public $items = []; public $table = null; public $events = []; static $ids = []; public function __construct(&$subject, array $config = []) { parent::__construct($subject, $config); Language::load('plg_actionlog_' . $this->alias); $config = Parameters::getInstance()->getComponentParams($this->alias); $enable_actionlog = isset($config->enable_actionlog) ? $config->enable_actionlog : true; $this->events = $enable_actionlog ? ['*'] : []; if ($enable_actionlog && ! empty($config->actionlog_events)) { $this->events = ArrayHelper::toArray($config->actionlog_events); } $this->name = JText::_($this->name); $this->option = $this->option ?: 'com_' . $this->alias; } public function onContentAfterSave($context, $table, $isNew) { if (strpos($context, $this->option) === false) { return; } $event = $isNew ? 'create' : 'update'; if ( ! ArrayHelper::find(['*', $event], $this->events)) { return; } $item = $this->getItem($context); $title = isset($table->title) ? $table->title : (isset($table->name) ? $table->name : $table->id); $item_url = str_replace('{id}', $table->id, $item->url); $message = [ 'type' => $item->title, 'id' => $table->id, 'title' => $title, 'itemlink' => $item_url, ]; Log::save($message, $context, $isNew); } public function onContentAfterDelete($context, $table) { if (strpos($context, $this->option) === false) { return; } if ( ! ArrayHelper::find(['*', 'delete'], $this->events)) { return; } $item = $this->getItem($context); $title = isset($table->title) ? $table->title : (isset($table->name) ? $table->name : $table->id); $message = [ 'type' => $item->title, 'id' => $table->id, 'title' => $title, ]; Log::delete($message, $context); } public function onContentChangeState($context, $ids, $value) { if (strpos($context, $this->option) === false) { return; } if ( ! ArrayHelper::find(['*', 'change_state'], $this->events)) { return; } $item = $this->getItem($context); if ( ! $this->table) { if ( ! is_file($item->file)) { return; } require_once $item->file; $this->table = (new $item->model)->getTable(); } foreach ($ids as $id) { $this->table->load($id); $title = isset($this->table->title) ? $this->table->title : (isset($this->table->name) ? $this->table->name : $this->table->id); $itemlink = str_replace('{id}', $this->table->id, $item->url); $message = [ 'type' => $item->title, 'id' => $id, 'title' => $title, 'itemlink' => $itemlink, ]; Log::changeState($message, $context, $value); } } public function onExtensionAfterSave($context, $table, $isNew) { self::onContentAfterSave($context, $table, $isNew); } public function onExtensionAfterDelete($context, $table) { self::onContentAfterDelete($context, $table); } public function onExtensionAfterInstall($installer, $eid) { // Prevent duplicate logs if (in_array('install_' . $eid, self::$ids)) { return; } $context = JFactory::getApplication()->input->get('option'); if (strpos($context, $this->option) === false) { return; } if ( ! ArrayHelper::find(['*', 'install'], $this->events)) { return; } $extension = Extension::getById($eid); if (empty($extension->manifest_cache)) { return; } $manifest = json_decode($extension->manifest_cache); if (empty($manifest->name)) { return; } self::$ids[] = 'install_' . $eid; $message = [ 'id' => $eid, 'extension_name' => JText::_($manifest->name), ]; Log::install($message, 'com_regularlabsmanager', $manifest->type); } public function onExtensionAfterUninstall($installer, $eid, $result) { // Prevent duplicate logs if (in_array('uninstall_' . $eid, self::$ids)) { return; } $context = JFactory::getApplication()->input->get('option'); if (strpos($context, $this->option) === false) { return; } if ( ! ArrayHelper::find(['*', 'uninstall'], $this->events)) { return; } if ($result === false) { return; } $manifest = $installer->get('manifest'); if ($manifest === null) { return; } self::$ids[] = 'uninstall_' . $eid; $message = [ 'id' => $eid, 'extension_name' => JText::_($manifest->name), ]; Log::uninstall($message, 'com_regularlabsmanager', $manifest->attributes()->type); } private function getItem($context) { $item = $this->getItemData($context); $item->title = isset($item->title) ? JText::_($item->title) : $this->type . ' ' . JText::_('RL_ITEM'); if ( ! isset($item->file)) { $item->file = JPATH_ADMINISTRATOR . '/components/' . $this->option . '/models/' . $item->type . '.php'; } if ( ! isset($item->model)) { $item->model = $this->alias . 'Model' . ucfirst($item->type); } if ( ! isset($item->url)) { $item->url = 'index.php?option=' . $this->option . '&view=' . $item->type . '&layout=edit&id={id}'; } return $item; } private function getItemData($context) { $default = (object) [ 'type' => 'item', ]; $type = key($this->items) ?: 'item'; if (strpos($context, '.') !== false) { $parts = explode('.', $context); $type = $parts[1]; } if ( ! isset($this->items[$type])) { return $default; } $item = $this->items[$type]; if ( ! isset($item->type)) { $item->type = $type; } return $item; } } ObjectHelper.php 0000604 00000002537 15245535751 0007642 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * Class ObjectHelper * @package RegularLabs\Library */ class ObjectHelper { /** * Return the value by the object property key * A list of keys can be given. The first one that is not empty will get returned * * @param object $object * @param string|array $keys * * @return mixed */ public static function getValue($object, $keys, $default = null) { $keys = ArrayHelper::toArray($keys); foreach ($keys as $key) { if (empty($object->{$key})) { continue; } return $object->{$key}; } return $default; } /** * Deep clone an object * * @param object $object * * @return object */ public static function deepClone($object) { return unserialize(serialize($object)); } /** * Merge 2 objects * * @param object $object1 * @param object $object2 * * @return object */ public static function merge($object1, $object2) { return (object) array_merge((array) $object1, (array) $object2); } } Title.php 0000604 00000004670 15245535751 0006355 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * Class Title * @package RegularLabs\Library */ class Title { /** * Cleans the string to make it usable as a title * * @param string $string * @param bool $strip_tags * @param bool $strip_spaces * * @return string */ public static function clean($string = '', $strip_tags = false, $strip_spaces = true) { if (empty($string)) { return ''; } // remove comment tags $string = RegEx::replace('<\!--.*?-->', '', $string); // replace weird whitespace $string = str_replace(chr(194) . chr(160), ' ', $string); if ($strip_tags) { // remove svgs $string = RegEx::replace('<svg.*?</svg>', '', $string); // remove html tags $string = RegEx::replace('</?[a-z][^>]*>', '', $string); // remove comments tags $string = RegEx::replace('<\!--.*?-->', '', $string); } if ($strip_spaces) { // Replace html spaces $string = str_replace([' ', ' '], ' ', $string); // Remove duplicate whitespace $string = RegEx::replace('[ \n\r\t]+', ' ', $string); } return trim($string); } /** * Creates an array of different syntaxes of titles to match against a url variable * * @param array $titles * * @return array */ public static function getUrlMatches($titles = []) { $matches = []; foreach ($titles as $title) { $matches[] = $title; $matches[] = StringHelper::strtolower($title); } $matches = array_unique($matches); foreach ($matches as $title) { $matches[] = htmlspecialchars(StringHelper::html_entity_decoder($title)); } $matches = array_unique($matches); foreach ($matches as $title) { $matches[] = urlencode($title); $matches[] = utf8_decode($title); $matches[] = str_replace(' ', '', $title); $matches[] = trim(RegEx::replace('[^a-z0-9]', '', $title)); $matches[] = trim(RegEx::replace('[^a-z]', '', $title)); } $matches = array_unique($matches); foreach ($matches as $i => $title) { $matches[$i] = trim(str_replace('?', '', $title)); } $matches = array_diff(array_unique($matches), ['', '-']); return $matches; } } Document.php 0000604 00000031216 15245535751 0007046 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; use Joomla\CMS\Factory as JFactory; use Joomla\CMS\HTML\HTMLHelper as JHtml; use Joomla\CMS\Language\Text as JText; /** * Class Document * @package RegularLabs\Library */ class Document { /** * Check if the current setup matches the given main version number * * @param int $version * @param string $title * * @return bool */ public static function isJoomlaVersion($version, $title = '') { if ((int) JVERSION == $version) { return true; } if ($title) { Language::load('plg_system_regularlabs'); JFactory::getApplication()->enqueueMessage( JText::sprintf('RL_NOT_COMPATIBLE_WITH_JOOMLA_VERSION', JText::_($title), (int) JVERSION), 'error' ); } return false; } /** * Check if page is an admin page * * @param bool $exclude_login * * @return bool */ public static function isAdmin($exclude_login = false) { $cache_id = __FUNCTION__ . '_' . $exclude_login; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $input = JFactory::getApplication()->input; return Cache::set($cache_id, ( self::isClient('administrator') && ( ! $exclude_login || ! JFactory::getUser()->get('guest')) && $input->get('task') != 'preview' && ! ( $input->get('option') == 'com_finder' && $input->get('format') == 'json' ) ) ); } /** * Check if page is an edit page * * @return bool */ public static function isClient($identifier) { $identifier = $identifier == 'admin' ? 'administrator' : $identifier; $cache_id = __FUNCTION__ . '_' . $identifier; if (Cache::has($cache_id)) { return Cache::get($cache_id); } return Cache::set($cache_id, JFactory::getApplication()->isClient($identifier)); } /** * Check if page is an edit page * * @return bool */ public static function isEditPage() { $cache_id = __FUNCTION__; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $input = JFactory::getApplication()->input; $option = $input->get('option'); // always return false for these components if (in_array($option, ['com_rsevents', 'com_rseventspro'])) { return Cache::set($cache_id, false); } $task = $input->get('task'); if (strpos($task, '.') !== false) { $task = explode('.', $task); $task = array_pop($task); } $view = $input->get('view'); if (strpos($view, '.') !== false) { $view = explode('.', $view); $view = array_pop($view); } return Cache::set($cache_id, ( in_array($option, ['com_config', 'com_contentsubmit', 'com_cckjseblod']) || ($option == 'com_comprofiler' && in_array($task, ['', 'userdetails'])) || in_array($task, ['edit', 'form', 'submission']) || in_array($view, ['edit', 'form']) || in_array($input->get('do'), ['edit', 'form']) || in_array($input->get('layout'), ['edit', 'form', 'write']) || self::isAdmin() ) ); } /** * Checks if current page is a html page * * @return bool */ public static function isHtml() { $cache_id = __FUNCTION__; if (Cache::has($cache_id)) { return Cache::get($cache_id); } return Cache::set($cache_id, (JFactory::getDocument()->getType() == 'html') ); } /** * Checks if current page is a feed * * @return bool */ public static function isFeed() { $cache_id = __FUNCTION__; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $input = JFactory::getApplication()->input; return Cache::set($cache_id, ( JFactory::getDocument()->getType() == 'feed' || $input->getWord('format') == 'feed' || $input->getWord('format') == 'xml' || $input->getWord('type') == 'rss' || $input->getWord('type') == 'atom' ) ); } /** * Checks if current page is a pdf * * @return bool */ public static function isPDF() { $cache_id = __FUNCTION__; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $input = JFactory::getApplication()->input; return Cache::set($cache_id, ( JFactory::getDocument()->getType() == 'pdf' || $input->getWord('format') == 'pdf' || $input->getWord('cAction') == 'pdf' ) ); } /** * Checks if current page is a JSON format fle * * @return bool */ public static function isJSON() { return JFactory::getApplication()->input->get('format') == 'json'; } /** * Checks if current page is a https (ssl) page * * @return bool */ public static function isHttps() { $cache_id = __FUNCTION__; if (Cache::has($cache_id)) { return Cache::get($cache_id); } return Cache::set($cache_id, ( ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') || (isset($_SERVER['SSL_PROTOCOL'])) || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') ) ); } /** * Checks if context/page is a category list * * @param string $context * * @return bool */ public static function isCategoryList($context) { $cache_id = __FUNCTION__ . '_' . $context; if (Cache::has($cache_id)) { return Cache::get($cache_id); } $app = JFactory::getApplication(); $input = $app->input; // Return false if it is not a category page if ($context != 'com_content.category' || $input->get('view') != 'category') { return Cache::set($cache_id, false); } // Return false if layout is set and it is not a list layout if ($input->get('layout') && $input->get('layout') != 'list') { return Cache::set($cache_id, false); } // Return false if default layout is set to blog if ($app->getParams()->get('category_layout') == '_:blog') { return Cache::set($cache_id, false); } // Return true if it IS a list layout return Cache::set($cache_id, true); } /** * Adds a script file to the page (with optional versioning) * * @param string $file * @param string $version * @param array $options * @param array $attribs * @param bool $load_jquery */ public static function script($file, $version = '', $options = [], $attribs = [], $load_jquery = true) { if ( ! $url = File::getMediaFile('js', $file)) { return; } if ($load_jquery) { JHtml::_('jquery.framework'); } if (strpos($file, 'regularlabs/') !== false && strpos($file, 'regular.') === false ) { JHtml::_('behavior.core'); JHtml::_('script', 'jui/cms.js', ['version' => 'auto', 'relative' => true]); $version = '21.4.10972'; } if ( ! empty($version)) { $url .= '?v=' . $version; } JFactory::getDocument()->addScript($url, $options, $attribs); } /** * Adds a stylesheet file to the page(with optional versioning) * * @param string $file * @param string $version */ public static function style($file, $version = '') { if (strpos($file, 'regularlabs/') === 0) { $version = '21.4.10972'; } if ( ! $file = File::getMediaFile('css', $file)) { return; } if ( ! empty($version)) { $file .= '?v=' . $version; } JFactory::getDocument()->addStylesheet($file); } /** * Alias of \RegularLabs\Library\Document::style() * * @param string $file * @param string $version */ public static function stylesheet($file, $version = '') { self::style($file, $version); } /** * Adds extension options to the page * * @param array $options * @param string $name */ public static function scriptOptions($options = [], $name = '') { $key = 'rl_' . Extension::getAliasByName($name); JHtml::_('behavior.core'); JFactory::getDocument()->addScriptOptions($key, $options); } /** * Loads the required scripts and styles used in forms */ public static function loadMainDependencies() { JHtml::_('jquery.framework'); self::script('regularlabs/script.min.js'); self::style('regularlabs/style.min.css'); } /** * Loads the required scripts and styles used in forms */ public static function loadFormDependencies() { JHtml::_('jquery.framework'); JHtml::_('behavior.tooltip'); JHtml::_('behavior.formvalidator'); JHtml::_('behavior.combobox'); JHtml::_('behavior.keepalive'); JHtml::_('behavior.tabstate'); JHtml::_('formbehavior.chosen', '#jform_position', null, ['disable_search_threshold' => 0]); JHtml::_('formbehavior.chosen', '.multipleCategories', null, ['placeholder_text_multiple' => JText::_('JOPTION_SELECT_CATEGORY')]); JHtml::_('formbehavior.chosen', '.multipleTags', null, ['placeholder_text_multiple' => JText::_('JOPTION_SELECT_TAG')]); JHtml::_('formbehavior.chosen', 'select'); self::script('regularlabs/form.min.js'); self::style('regularlabs/form.min.css'); } /** * Loads the required scripts and styles used in forms */ public static function loadEditorButtonDependencies() { self::loadMainDependencies(); JHtml::_('bootstrap.popover'); } public static function loadPopupDependencies() { self::loadMainDependencies(); self::loadFormDependencies(); self::style('regularlabs/popup.min.css'); } /** * Adds a javascript declaration to the page * * @param string $content * @param string $name * @param bool $minify * @param string $type */ public static function scriptDeclaration($content = '', $name = '', $minify = true, $type = 'text/javascript') { if ($minify) { $content = self::minify($content); } if ( ! empty($name)) { $content = Protect::wrapScriptDeclaration($content, $name, $minify); } JFactory::getDocument()->addScriptDeclaration($content, $type); } /** * Adds a stylesheet declaration to the page * * @param string $content * @param string $name * @param bool $minify * @param string $type */ public static function styleDeclaration($content = '', $name = '', $minify = true, $type = 'text/css') { if ($minify) { $content = self::minify($content); } if ( ! empty($name)) { $content = Protect::wrapStyleDeclaration($content, $name, $minify); } JFactory::getDocument()->addStyleDeclaration($content, $type); } /** * Remove style/css blocks from html string * * @param string $string * @param string $name * @param string $alias */ public static function removeScriptsStyles(&$string, $name, $alias = '') { list($start, $end) = Protect::getInlineCommentTags($name, null, true); $alias = $alias ?: Extension::getAliasByName($name); $string = RegEx::replace('((?:;\s*)?)(;?)' . $start . '.*?' . $end . '\s*', '\1', $string); $string = RegEx::replace('\s*<link [^>]*href="[^"]*/(' . $alias . '/css|css/' . $alias . ')/[^"]*\.css[^"]*"[^>]*( /)?>', '', $string); $string = RegEx::replace('\s*<script [^>]*src="[^"]*/(' . $alias . '/js|js/' . $alias . ')/[^"]*\.js[^"]*"[^>]*></script>', '', $string); } /** * Remove joomla script options * * @param string $string * @param string $name * @param string $alias */ public static function removeScriptsOptions(&$string, $name, $alias = '') { RegEx::match( '(<script type="application/json" class="joomla-script-options new">)(.*?)(</script>)', $string, $match ); if (empty($match)) { return; } $alias = $alias ?: Extension::getAliasByName($name); $scripts = json_decode($match[2]); if ( ! isset($scripts->{'rl_' . $alias})) { return; } unset($scripts->{'rl_' . $alias}); $string = str_replace( $match[0], $match[1] . json_encode($scripts) . $match[3], $string ); } /** * Returns the document buffer * * @return null|string */ public static function getBuffer() { $buffer = JFactory::getDocument()->getBuffer('component'); if (empty($buffer) || ! is_string($buffer)) { return null; } $buffer = trim($buffer); if (empty($buffer)) { return null; } return $buffer; } /** * Set the document buffer * * @param string $buffer */ public static function setBuffer($buffer = '') { JFactory::getDocument()->setBuffer($buffer, 'component'); } /** * Minify the given string * * @param string $string * * @return string */ public static function minify($string) { // place new lines around string to make regex searching easier $string = "\n" . $string . "\n"; // Remove comment lines $string = RegEx::replace('\n\s*//.*?\n', '', $string); // Remove comment blocks $string = RegEx::replace('/\*.*?\*/', '', $string); // Remove enters $string = RegEx::replace('\n\s*', ' ', $string); // Remove surrounding whitespace $string = trim($string); return $string; } } ArrayHelper.php 0000604 00000010404 15245535751 0007502 0 ustar 00 <?php /** * @package Regular Labs Library * @version 21.4.10972 * * @author Peter van Westen <info@regularlabs.com> * @link http://www.regularlabs.com * @copyright Copyright © 2021 Regular Labs All Rights Reserved * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL */ namespace RegularLabs\Library; defined('_JEXEC') or die; /** * Class ArrayHelper * @package RegularLabs\Library */ class ArrayHelper { /** * Convert data (string or object) to an array * * @param mixed $data * @param string $separator * @param bool $unique * * @return array */ public static function toArray($data, $separator = ',', $unique = false, $trim = true) { if (is_array($data)) { return $data; } if (is_object($data)) { return (array) $data; } if ($data === '' || is_null($data)) { return []; } if ($separator === '') { return [$data]; } // explode on separator, but keep escaped separators $splitter = uniqid('RL_SPLIT'); $data = str_replace($separator, $splitter, $data); $data = str_replace('\\' . $splitter, $separator, $data); $array = explode($splitter, $data); if ($trim) { $array = self::trim($array); } if ($unique) { $array = array_unique($array); } return $array; } /** * Join array elements with a string * * @param string $glue * @param array $pieces * * @return array */ public static function implode($pieces, $glue = '') { if ( ! is_array($pieces)) { $pieces = self::toArray($pieces, $glue); } return implode($glue, $pieces); } /** * Clean array by trimming values and removing empty/false values * * @param array $array * * @return array */ public static function clean($array) { if ( ! is_array($array)) { return $array; } $array = self::trim($array); $array = self::unique($array); $array = self::removeEmpty($array); return $array; } /** * Removes empty values from the array * * @param array $array * * @return array */ public static function removeEmpty($array) { if ( ! is_array($array)) { return $array; } foreach ($array as $key => &$value) { if ($key && ! is_numeric($key)) { continue; } if ($value !== '') { continue; } unset($array[$key]); } return $array; } /** * Removes duplicate values from the array * * @param array $array * * @return array */ public static function unique($array) { if ( ! is_array($array)) { return $array; } $values = []; foreach ($array as $key => $value) { if ( ! is_numeric($key)) { continue; } if ( ! in_array($value, $values)) { $values[] = $value; continue; } unset($array[$key]); } return $array; } /** * Clean array by trimming values * * @param array $array * * @return array */ public static function trim($array) { if ( ! is_array($array)) { return $array; } foreach ($array as &$value) { if ( ! is_string($value)) { continue; } $value = trim($value); } return $array; } /** * Check if any of the given values is found in the array * * @param array $needles * @param array $haystack * * @return boolean */ public static function find($needles, $haystack) { if ( ! is_array($haystack) || empty($haystack)) { return false; } $needles = self::toArray($needles); foreach ($needles as $value) { if (in_array($value, $haystack)) { return true; } } return false; } /** * Sorts the array by keys based on the values of another array * * @param array $array * @param array $order * * @return array */ public static function sortByOtherArray($array, $order) { uksort($array, function ($key1, $key2) use ($order) { return (array_search($key1, $order) > array_search($key2, $order)); }); return $array; } /** * Flatten an array of nested arrays, keeping the order * * @param array $array * * @return array */ public static function flatten($array) { $flattened = []; foreach ($array as $nested) { if ( ! is_array($nested)) { $flattened[] = $nested; continue; } $flattened = array_merge($flattened, self::flatten($nested)); } return $flattened; } } Extension/Jce.php 0000604 00000004741 15245536005 0007741 0 ustar 00 <?php /** * @package JCE * @subpackage Installer.Jce * * @copyright Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved * @copyright Copyright (C) 2023 - 2024 Ryan Demmer. All rights reserved * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Installer\Jce\Extension; \defined('_JEXEC') or die; use Joomla\CMS\Component\ComponentHelper; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\Database\DatabaseAwareTrait; use Joomla\Plugin\Installer\Jce\PluginTraits\EventsTrait; class Jce extends CMSPlugin { use EventsTrait; use DatabaseAwareTrait; /** * Affects constructor behavior. If true, language files will be loaded automatically. * * @var boolean */ protected $autoloadLanguage = true; private function getDownloadKeyFromUpdateSites() { $db = $this->getDatabase(); $query = $db->getQuery(true) ->select('package_id') ->from('#__extensions') ->where('element = ' . $db->quote('com_jce')); $db->setQuery($query); $packageId = $db->loadResult(); if (is_null($packageId)) { return null; } $query = $db->getQuery(true) ->select($db->quoteName('update_sites.extra_query')) ->from($db->quoteName('#__update_sites', 'update_sites')) ->join( 'INNER', $db->quoteName('#__update_sites_extensions', 'update_sites_extensions') . ' ON ' . $db->quoteName('update_sites_extensions.update_site_id') . ' = ' . $db->quoteName('update_sites.update_site_id') ) ->where($db->quoteName('update_sites_extensions.extension_id') . ' = ' . (int) $packageId); $db->setQuery($query); $result = $db->loadResult(); if ($result) { // Parse the `extra_query` to extract the key value parse_str($result, $parsedQuery); if (isset($parsedQuery['key'])) { return $parsedQuery['key']; } } return null; } /** * Get the download key from the update sites table. * * @return string|null The download key or null if not found */ public function getDownloadKey() { // get the key directly from the update sites table, eg: when updating a plugin $key = $this->getDownloadKeyFromUpdateSites(); // Return the key or null if not found return $key; } } PluginTraits/EventTrait.php 0000604 00000003322 15245536005 0011770 0 ustar 00 <?php /** * @package JCE * @subpackage Editors.Jce * * @copyright Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved. * @copyright Copyright (c) 2009-2024 Ryan Demmer. All rights reserved * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\System\Jce\PluginTraits; use Joomla\CMS\Factory; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Handles the onDisplay event for the JCE editor. * * @since 2.9.70 */ trait EventTrait { private function getDummyDispatcher() { $app = Factory::getApplication(); if (method_exists($app, 'getDispatcher')) { $dispatcher = Factory::getApplication()->getDispatcher(); } else { $dispatcher = JEventDispatcher::getInstance(); } return $dispatcher; } private function bootCustomPlugin($className, $config = array()) { if (class_exists($className)) { $dispatcher = $this->getDummyDispatcher(); // Instantiate and register the event $plugin = new $className($dispatcher, $config); if ($plugin instanceof \Joomla\CMS\Extension\PluginInterface) { $plugin->registerListeners(); } } } public function onBeforeWfEditorLoad() { $path = JPATH_PLUGINS . '/system/jce'; $items = glob($path . '/templates/*.php'); foreach ($items as $item) { $name = basename($item, '.php'); $className = 'WfTemplate' . ucfirst($name); require_once $item; $this->bootCustomPlugin($className); } } } PluginTraits/EventsTrait.php 0000604 00000007555 15245557207 0012176 0 ustar 00 <?php /** * @package JCE * @subpackage Installer.Jce * * @copyright Copyright (C) 2005 - 2023 Open Source Matters, Inc. All rights reserved * @copyright Copyright (C) 2023 - 2024 Ryan Demmer. All rights reserved * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\Plugin\Installer\Jce\PluginTraits; defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Http\HttpFactory; use Joomla\CMS\Language\Text; use Joomla\CMS\Uri\Uri; /** * JCE Installer Events Trait * * @since 2.9.73 */ trait EventsTrait { private function checkIfKeyRequired($query) { // get the file name from the url without the xml extension $file = isset($query['file']) ? $query['file'] : ''; if (empty($file)) { return false; } // jce pro requires a key if (strpos($file, 'pkg_jce_pro_') !== false) { return true; } // jce core does not require a key if (strpos($file, 'pkg_jce_') !== false) { return false; } // jce plugins require a key if (strpos($file, 'plg_jce_') !== false) { return true; } // mediabox does not require a key if (strpos($file, 'plg_system_jcemediabox') !== false) { return false; } return false; } /** * Handle adding credentials to package download request. * * @param string $url url from which package is going to be downloaded * @param array $headers headers to be sent along the download request (key => value format) * * @return bool true if credentials have been added to request or not our business, false otherwise (credentials not set by user) * * @since 3.0 */ public function onInstallerBeforePackageDownload(&$url, &$headers) { $app = Factory::getApplication(); $uri = Uri::getInstance($url); $host = $uri->getHost(); if ($host !== 'www.joomlacontenteditor.net') { return true; } // check if the key has already been set via the dlid field. This will only be available in Joomla 4.x and later $key = $uri->getVar('key', ''); // get the key from the component params or Update Sites (in the case of plugin updates) if (empty($key)) { $key = $this->getDownloadKey(); } // if no key is set... if (empty($key)) { $query = $uri->getQuery(true); // if we are attempting to update JCE Pro or JCE Plugins, display a notice message if ($this->checkIfKeyRequired($query) === true) { $app->enqueueMessage(Text::_('PLG_INSTALLER_JCE_KEY_WARNING'), 'notice'); return true; } } // Append the subscription key to the download URL if it exists if (!empty($key)) { $uri->setVar('key', $key); } // create the url string $url = $uri->toString(); // check validity of the key and display a message if it is invalid / expired try { $tmpUri = clone $uri; $tmpUri->setVar('task', 'update.validate'); $tmpUrl = $tmpUri->toString(); $response = HttpFactory::getHttp()->get($tmpUrl, array()); } catch (\RuntimeException $exception) { $app->enqueueMessage($exception->getMessage(), 'notice'); return true; } // invalid key, display a notice message if (403 == $response->code || 401 == $response->code) { $app->enqueueMessage(Text::_('PLG_INSTALLER_JCE_KEY_INVALID'), 'notice'); } // update limit exceeded if (498 === $response->code) { $app->enqueueMessage(Text::_('PLG_INSTALLER_JCE_KEY_LIMIT'), 'notice'); } return true; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Генерация страницы: 0.01 |
proxy
|
phpinfo
|
Настройка