2015-08-24 20:22:07 +00:00
|
|
|
<?php
|
|
|
|
/*----------------------------------------------------------------------------------| www.vdm.io |----/
|
|
|
|
Vast Development Method
|
|
|
|
/-------------------------------------------------------------------------------------------------------/
|
|
|
|
|
2021-01-06 13:52:28 +00:00
|
|
|
@version 2.0.3
|
|
|
|
@build 6th January, 2021
|
2017-04-08 18:35:55 +00:00
|
|
|
@created 18th October, 2016
|
2015-08-24 20:22:07 +00:00
|
|
|
@package Demo
|
|
|
|
@subpackage demo.php
|
|
|
|
@author Llewellyn van der Merwe <https://www.vdm.io/>
|
|
|
|
@copyright Copyright (C) 2015. All Rights Reserved
|
|
|
|
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
|
|
|
|
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
|
|
|
|
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
|
|
|
|
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
|
|
|
|
|
|
|
|
/------------------------------------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
// No direct access to this file
|
|
|
|
defined('_JEXEC') or die('Restricted access');
|
|
|
|
|
2021-01-06 13:52:28 +00:00
|
|
|
use Joomla\CMS\Language\Language;
|
|
|
|
use Joomla\Registry\Registry;
|
|
|
|
use Joomla\String\StringHelper;
|
2020-05-30 23:59:04 +00:00
|
|
|
use Joomla\Utilities\ArrayHelper;
|
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
/**
|
|
|
|
* Demo component helper
|
|
|
|
*/
|
|
|
|
abstract class DemoHelper
|
2020-05-30 23:59:04 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Composer Switch
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected static $composer = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Main Active Language
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $langTag;
|
2017-04-08 18:35:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Change to nice fancy date
|
|
|
|
*/
|
|
|
|
public static function fancyDate($date)
|
|
|
|
{
|
|
|
|
if (!self::isValidTimeStamp($date))
|
|
|
|
{
|
|
|
|
$date = strtotime($date);
|
|
|
|
}
|
|
|
|
return date('jS \o\f F Y',$date);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change to nice fancy time and date
|
|
|
|
*/
|
|
|
|
public static function fancyDateTime($time)
|
|
|
|
{
|
|
|
|
if (!self::isValidTimeStamp($time))
|
|
|
|
{
|
|
|
|
$time = strtotime($time);
|
|
|
|
}
|
|
|
|
return date('(G:i) jS \o\f F Y',$time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change to nice hour:minutes time
|
|
|
|
*/
|
|
|
|
public static function fancyTime($time)
|
|
|
|
{
|
|
|
|
if (!self::isValidTimeStamp($time))
|
|
|
|
{
|
|
|
|
$time = strtotime($time);
|
|
|
|
}
|
|
|
|
return date('G:i',$time);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if string is a valid time stamp
|
|
|
|
*/
|
|
|
|
public static function isValidTimeStamp($timestamp)
|
|
|
|
{
|
|
|
|
return ((int) $timestamp === $timestamp)
|
|
|
|
&& ($timestamp <= PHP_INT_MAX)
|
|
|
|
&& ($timestamp >= ~PHP_INT_MAX);
|
|
|
|
}
|
2020-05-30 23:59:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
// <<<=== Privacy integration with Joomla Privacy suite ===>>>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs validation to determine if the data associated with a remove information request can be processed
|
|
|
|
*
|
|
|
|
* @param PrivacyPlugin $plugin The plugin being processed
|
|
|
|
* @param PrivacyRemovalStatus $status The status being set
|
|
|
|
* @param PrivacyTableRequest $request The request record being processed
|
|
|
|
* @param JUser $user The user account associated with this request if available
|
|
|
|
*
|
|
|
|
* @return PrivacyRemovalStatus
|
|
|
|
*/
|
|
|
|
public static function onPrivacyCanRemoveData(&$plugin, &$status, &$request, &$user)
|
|
|
|
{
|
|
|
|
// Bucket to get all reasons why removal not allowed
|
|
|
|
$reasons = array();
|
|
|
|
// Check if user has permission to delete Looks
|
|
|
|
if (!$user->authorise('look.delete', 'com_demo') && !$user->authorise('look.privacy.delete', 'com_demo'))
|
|
|
|
{
|
|
|
|
$reasons[] = JText::_('COM_DEMO_PRIVACY_CANT_REMOVE_LOOKS');
|
|
|
|
}
|
|
|
|
// Check if any reasons were found not to allow removal
|
|
|
|
if (self::checkArray($reasons))
|
|
|
|
{
|
|
|
|
$status->canRemove = false;
|
|
|
|
$status->reason = implode(' ' . PHP_EOL, $reasons) . ' ' . PHP_EOL . JText::_('COM_DEMO_PRIVACY_CANT_REMOVE_CONTACT_SUPPORT');
|
|
|
|
}
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes an export request for Joomla core user data
|
|
|
|
*
|
|
|
|
* @param PrivacyPlugin $plugin The plugin being processed
|
|
|
|
* @param DomainArray $domains The array of domains
|
|
|
|
* @param PrivacyTableRequest $request The request record being processed
|
|
|
|
* @param JUser $user The user account associated with this request if available
|
|
|
|
*
|
|
|
|
* @return PrivacyExportDomain[]
|
|
|
|
*/
|
|
|
|
public static function onPrivacyExportRequest(&$plugin, &$domains, &$request, &$user)
|
|
|
|
{
|
|
|
|
// Check if user has permission to access Looks
|
|
|
|
if ($user->authorise('look.access', 'com_demo') || $user->authorise('look.privacy.access', 'com_demo'))
|
|
|
|
{
|
|
|
|
// Get Look domain
|
|
|
|
$domains[] = self::createLooksDomain($plugin, $user);
|
|
|
|
}
|
|
|
|
return $domains;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the domain for the Look
|
|
|
|
*
|
|
|
|
* @param JTableUser $user The JTableUser object to process
|
|
|
|
*
|
|
|
|
* @return PrivacyExportDomain
|
|
|
|
*/
|
|
|
|
protected static function createLooksDomain(&$plugin, &$user)
|
|
|
|
{
|
|
|
|
// create Looks domain
|
|
|
|
$domain = self::createDomain('look', 'demo_look_data');
|
|
|
|
// get database object
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
// get all item ids of Looks that belong to this user
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
->select('id')
|
|
|
|
->from($db->quoteName('#__demo_look'));
|
|
|
|
$query->where($db->quoteName('created_by') . ' = ' . $db->quote($user->id));
|
|
|
|
// get all items for the Looks domain
|
|
|
|
$pks = $db->setQuery($query)->loadColumn();
|
|
|
|
// get the Looks model
|
|
|
|
$model = self::getModel('looks', JPATH_ADMINISTRATOR . '/components/com_demo');
|
|
|
|
// Get all item details of Looks that belong to this user
|
|
|
|
$items = $model->getPrivacyExport($pks, $user);
|
|
|
|
// check if we have items since permissions could block the request
|
|
|
|
if (self::checkArray($items))
|
|
|
|
{
|
|
|
|
// Remove Look default columns
|
|
|
|
foreach (array('params', 'asset_id', 'checked_out', 'checked_out_time', 'created', 'created_by', 'modified', 'modified_by', 'published', 'ordering', 'access', 'version', 'hits') as $column)
|
|
|
|
{
|
|
|
|
$items = ArrayHelper::dropColumn($items, $column);
|
|
|
|
}
|
|
|
|
// load the items into the domain object
|
|
|
|
foreach ($items as $item)
|
|
|
|
{
|
|
|
|
$domain->addItem(self::createItemFromArray($item, $item['id']));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new domain object
|
|
|
|
*
|
|
|
|
* @param string $name The domain's name
|
|
|
|
* @param string $description The domain's description
|
|
|
|
*
|
|
|
|
* @return PrivacyExportDomain
|
|
|
|
*
|
|
|
|
* @since 3.9.0
|
|
|
|
*/
|
|
|
|
protected static function createDomain($name, $description = '')
|
|
|
|
{
|
|
|
|
$domain = new PrivacyExportDomain;
|
|
|
|
$domain->name = $name;
|
|
|
|
$domain->description = $description;
|
|
|
|
|
|
|
|
return $domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an item object for an array
|
|
|
|
*
|
|
|
|
* @param array $data The array data to convert
|
|
|
|
* @param integer|null $itemId The ID of this item
|
|
|
|
*
|
|
|
|
* @return PrivacyExportItem
|
|
|
|
*
|
|
|
|
* @since 3.9.0
|
|
|
|
*/
|
|
|
|
protected static function createItemFromArray(array $data, $itemId = null)
|
|
|
|
{
|
|
|
|
$item = new PrivacyExportItem;
|
|
|
|
$item->id = $itemId;
|
|
|
|
|
|
|
|
foreach ($data as $key => $value)
|
|
|
|
{
|
|
|
|
if (is_object($value))
|
|
|
|
{
|
|
|
|
$value = (array) $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
$value = print_r($value, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$field = new PrivacyExportField;
|
|
|
|
$field->name = $key;
|
|
|
|
$field->value = $value;
|
|
|
|
|
|
|
|
$item->addField($field);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes the data associated with a remove information request
|
|
|
|
*
|
|
|
|
* @param PrivacyTableRequest $request The request record being processed
|
|
|
|
* @param JUser $user The user account associated with this request if available
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function onPrivacyRemoveData(&$plugin, &$request, &$user)
|
|
|
|
{
|
|
|
|
// Check if user has permission to delet Looks
|
|
|
|
if ($user->authorise('look.delete', 'com_demo') || $user->authorise('look.privacy.delete', 'com_demo'))
|
|
|
|
{
|
|
|
|
// Remove Look data
|
|
|
|
self::removeLooksData($plugin, $user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the Look data
|
|
|
|
*
|
|
|
|
* @param JTableUser $user The JTableUser object to process
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected static function removeLooksData(&$plugin, &$user)
|
|
|
|
{
|
|
|
|
// get database object
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
// get all item ids of Looks that belong to this user
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
->select('id')
|
|
|
|
->from($db->quoteName('#__demo_look'));
|
|
|
|
$query->where($db->quoteName('created_by') . ' = ' . $db->quote($user->id));
|
|
|
|
// get all items for the Looks table that belong to this user
|
|
|
|
$pks = $db->setQuery($query)->loadColumn();
|
|
|
|
|
|
|
|
if (self::checkArray($pks))
|
|
|
|
{
|
|
|
|
// get the look model
|
|
|
|
$model = self::getModel('look', JPATH_ADMINISTRATOR . '/components/com_demo');
|
|
|
|
// get the Looks table
|
|
|
|
$table = $model->getTable();
|
|
|
|
// Iterate the items to delete each one.
|
|
|
|
foreach ($pks as $i => $pk)
|
|
|
|
{
|
|
|
|
if ($table->load($pk))
|
|
|
|
{
|
|
|
|
$table->delete($pk);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Clear the component's cache
|
|
|
|
$model->cleanCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 02:21:17 +00:00
|
|
|
|
2020-05-30 23:59:04 +00:00
|
|
|
/**
|
|
|
|
* Load the Composer Vendors
|
|
|
|
*/
|
|
|
|
public static function composerAutoload($target)
|
|
|
|
{
|
|
|
|
// insure we load the composer vendor only once
|
|
|
|
if (!isset(self::$composer[$target]))
|
|
|
|
{
|
|
|
|
// get the function name
|
|
|
|
$functionName = self::safeString('compose' . $target);
|
|
|
|
// check if method exist
|
|
|
|
if (method_exists(__CLASS__, $functionName))
|
|
|
|
{
|
|
|
|
return self::{$functionName}();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return self::$composer[$target];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert it into a string
|
|
|
|
*/
|
2018-05-05 13:32:19 +00:00
|
|
|
public static function jsonToString($value, $sperator = ", ", $table = null, $id = 'id', $name = 'name')
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2018-05-05 13:32:19 +00:00
|
|
|
// do some table foot work
|
|
|
|
$external = false;
|
|
|
|
if (strpos($table, '#__') !== false)
|
|
|
|
{
|
|
|
|
$external = true;
|
|
|
|
$table = str_replace('#__', '', $table);
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
// check if string is JSON
|
|
|
|
$result = json_decode($value, true);
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE)
|
2016-06-02 07:45:56 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
// is JSON
|
2016-06-02 07:45:56 +00:00
|
|
|
if (self::checkArray($result))
|
|
|
|
{
|
|
|
|
if (self::checkString($table))
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2016-06-02 07:45:56 +00:00
|
|
|
$names = array();
|
|
|
|
foreach ($result as $val)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2018-05-05 13:32:19 +00:00
|
|
|
if ($external)
|
|
|
|
{
|
2018-09-13 02:21:17 +00:00
|
|
|
if ($_name = self::getVar(null, $val, $id, $name, '=', $table))
|
2018-05-05 13:32:19 +00:00
|
|
|
{
|
2018-09-13 02:21:17 +00:00
|
|
|
$names[] = $_name;
|
2018-05-05 13:32:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2018-09-13 02:21:17 +00:00
|
|
|
if ($_name = self::getVar($table, $val, $id, $name))
|
2018-05-05 13:32:19 +00:00
|
|
|
{
|
2018-09-13 02:21:17 +00:00
|
|
|
$names[] = $_name;
|
2018-05-05 13:32:19 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2016-06-02 07:45:56 +00:00
|
|
|
if (self::checkArray($names))
|
|
|
|
{
|
|
|
|
return (string) implode($sperator,$names);
|
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2016-06-02 07:45:56 +00:00
|
|
|
return (string) implode($sperator,$result);
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
return (string) json_decode($value);
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Load the Component xml manifest.
|
|
|
|
*/
|
2018-05-05 01:16:22 +00:00
|
|
|
public static function manifest()
|
|
|
|
{
|
|
|
|
$manifestUrl = JPATH_ADMINISTRATOR."/components/com_demo/demo.xml";
|
|
|
|
return simplexml_load_file($manifestUrl);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Joomla version object
|
|
|
|
*/
|
2018-05-05 01:16:22 +00:00
|
|
|
protected static $JVersion;
|
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* set/get Joomla version
|
|
|
|
*/
|
2018-05-05 01:16:22 +00:00
|
|
|
public static function jVersion()
|
|
|
|
{
|
|
|
|
// check if set
|
|
|
|
if (!self::checkObject(self::$JVersion))
|
|
|
|
{
|
|
|
|
self::$JVersion = new JVersion();
|
|
|
|
}
|
|
|
|
return self::$JVersion;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Load the Contributors details.
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function getContributors()
|
|
|
|
{
|
|
|
|
// get params
|
|
|
|
$params = JComponentHelper::getParams('com_demo');
|
|
|
|
// start contributors array
|
|
|
|
$contributors = array();
|
|
|
|
// get all Contributors (max 20)
|
|
|
|
$searchArray = range('0','20');
|
|
|
|
foreach($searchArray as $nr)
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
if ((NULL !== $params->get("showContributor".$nr)) && ($params->get("showContributor".$nr) == 2 || $params->get("showContributor".$nr) == 3))
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
// set link based of selected option
|
|
|
|
if($params->get("useContributor".$nr) == 1)
|
|
|
|
{
|
|
|
|
$link_front = '<a href="mailto:'.$params->get("emailContributor".$nr).'" target="_blank">';
|
|
|
|
$link_back = '</a>';
|
|
|
|
}
|
|
|
|
elseif($params->get("useContributor".$nr) == 2)
|
|
|
|
{
|
|
|
|
$link_front = '<a href="'.$params->get("linkContributor".$nr).'" target="_blank">';
|
|
|
|
$link_back = '</a>';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$link_front = '';
|
|
|
|
$link_back = '';
|
|
|
|
}
|
|
|
|
$contributors[$nr]['title'] = self::htmlEscape($params->get("titleContributor".$nr));
|
|
|
|
$contributors[$nr]['name'] = $link_front.self::htmlEscape($params->get("nameContributor".$nr)).$link_back;
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
return $contributors;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-13 02:21:17 +00:00
|
|
|
* Can be used to build help urls.
|
|
|
|
**/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function getHelpUrl($view)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Get any component's model
|
|
|
|
*/
|
|
|
|
public static function getModel($name, $path = JPATH_COMPONENT_SITE, $Component = 'Demo', $config = array())
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2018-05-05 01:16:22 +00:00
|
|
|
// fix the name
|
|
|
|
$name = self::safeString($name);
|
2020-05-30 23:59:04 +00:00
|
|
|
// full path to models
|
|
|
|
$fullPathModels = $path . '/models';
|
2015-08-24 20:22:07 +00:00
|
|
|
// load the model file
|
2020-05-30 23:59:04 +00:00
|
|
|
JModelLegacy::addIncludePath($fullPathModels, $Component . 'Model');
|
|
|
|
// make sure the table path is loaded
|
|
|
|
if (!isset($config['table_path']) || !self::checkString($config['table_path']))
|
|
|
|
{
|
|
|
|
// This is the JCB default path to tables in Joomla 3.x
|
|
|
|
$config['table_path'] = JPATH_ADMINISTRATOR . '/components/com_' . strtolower($Component) . '/tables';
|
|
|
|
}
|
2017-08-21 12:17:01 +00:00
|
|
|
// get instance
|
2020-05-30 23:59:04 +00:00
|
|
|
$model = JModelLegacy::getInstance($name, $Component . 'Model', $config);
|
2018-05-05 01:16:22 +00:00
|
|
|
// if model not found (strange)
|
2017-08-21 12:17:01 +00:00
|
|
|
if ($model == false)
|
|
|
|
{
|
2018-05-05 01:16:22 +00:00
|
|
|
jimport('joomla.filesystem.file');
|
|
|
|
// get file path
|
2020-05-30 23:59:04 +00:00
|
|
|
$filePath = $path . '/' . $name . '.php';
|
|
|
|
$fullPathModel = $fullPathModels . '/' . $name . '.php';
|
2018-05-05 01:16:22 +00:00
|
|
|
// check if it exists
|
|
|
|
if (JFile::exists($filePath))
|
|
|
|
{
|
|
|
|
// get the file
|
|
|
|
require_once $filePath;
|
|
|
|
}
|
2020-05-30 23:59:04 +00:00
|
|
|
elseif (JFile::exists($fullPathModel))
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
|
|
|
// get the file
|
2020-05-30 23:59:04 +00:00
|
|
|
require_once $fullPathModel;
|
2018-05-05 01:16:22 +00:00
|
|
|
}
|
|
|
|
// build class names
|
2020-05-30 23:59:04 +00:00
|
|
|
$modelClass = $Component . 'Model' . $name;
|
2018-05-05 01:16:22 +00:00
|
|
|
if (class_exists($modelClass))
|
|
|
|
{
|
|
|
|
// initialize the model
|
|
|
|
return new $modelClass($config);
|
|
|
|
}
|
2017-08-21 12:17:01 +00:00
|
|
|
}
|
|
|
|
return $model;
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Add to asset Table
|
|
|
|
*/
|
2019-04-23 20:37:57 +00:00
|
|
|
public static function setAsset($id, $table, $inherit = true)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
|
|
|
$parent = JTable::getInstance('Asset');
|
|
|
|
$parent->loadByName('com_demo');
|
|
|
|
|
|
|
|
$parentId = $parent->id;
|
|
|
|
$name = 'com_demo.'.$table.'.'.$id;
|
|
|
|
$title = '';
|
|
|
|
|
|
|
|
$asset = JTable::getInstance('Asset');
|
|
|
|
$asset->loadByName($name);
|
|
|
|
|
|
|
|
// Check for an error.
|
|
|
|
$error = $asset->getError();
|
|
|
|
|
|
|
|
if ($error)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Specify how a new or moved node asset is inserted into the tree.
|
|
|
|
if ($asset->parent_id != $parentId)
|
|
|
|
{
|
|
|
|
$asset->setLocation($parentId, 'last-child');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare the asset to be stored.
|
|
|
|
$asset->parent_id = $parentId;
|
|
|
|
$asset->name = $name;
|
|
|
|
$asset->title = $title;
|
|
|
|
// get the default asset rules
|
2019-04-23 20:37:57 +00:00
|
|
|
$rules = self::getDefaultAssetRules('com_demo', $table, $inherit);
|
2015-12-03 02:17:44 +00:00
|
|
|
if ($rules instanceof JAccessRules)
|
|
|
|
{
|
|
|
|
$asset->rules = (string) $rules;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$asset->check() || !$asset->store())
|
|
|
|
{
|
2016-07-13 13:21:49 +00:00
|
|
|
JFactory::getApplication()->enqueueMessage($asset->getError(), 'warning');
|
2015-12-03 02:17:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Create an asset_id or heal one that is corrupted.
|
|
|
|
$object = new stdClass();
|
|
|
|
|
|
|
|
// Must be a valid primary key value.
|
|
|
|
$object->id = $id;
|
|
|
|
$object->asset_id = (int) $asset->id;
|
|
|
|
|
|
|
|
// Update their asset_id to link to the asset table.
|
|
|
|
return JFactory::getDbo()->updateObject('#__demo_'.$table, $object, 'id');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
/**
|
2019-04-23 20:37:57 +00:00
|
|
|
* Gets the default asset Rules for a component/view.
|
2015-12-03 02:17:44 +00:00
|
|
|
*/
|
2019-04-23 20:37:57 +00:00
|
|
|
protected static function getDefaultAssetRules($component, $view, $inherit = true)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// if new or inherited
|
|
|
|
$assetId = 0;
|
|
|
|
// Only get the actual item rules if not inheriting
|
|
|
|
if (!$inherit)
|
|
|
|
{
|
|
|
|
// Need to find the asset id by the name of the component.
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
$query = $db->getQuery(true)
|
|
|
|
->select($db->quoteName('id'))
|
|
|
|
->from($db->quoteName('#__assets'))
|
|
|
|
->where($db->quoteName('name') . ' = ' . $db->quote($component));
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
// check that there is a value
|
|
|
|
if ($db->getNumRows())
|
|
|
|
{
|
|
|
|
// asset already set so use saved rules
|
|
|
|
$assetId = (int) $db->loadResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// get asset rules
|
|
|
|
$result = JAccess::getAssetRules($assetId);
|
|
|
|
if ($result instanceof JAccessRules)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
$_result = (string) $result;
|
|
|
|
$_result = json_decode($_result);
|
|
|
|
foreach ($_result as $name => &$rule)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
$v = explode('.', $name);
|
|
|
|
if ($view !== $v[0])
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// remove since it is not part of this view
|
|
|
|
unset($_result->$name);
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
elseif ($inherit)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// clear the value since we inherit
|
|
|
|
$rule = array();
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
}
|
|
|
|
// check if there are any view values remaining
|
2020-05-30 23:59:04 +00:00
|
|
|
if (count((array) $_result))
|
2019-04-23 20:37:57 +00:00
|
|
|
{
|
|
|
|
$_result = json_encode($_result);
|
|
|
|
$_result = array($_result);
|
|
|
|
// Instantiate and return the JAccessRules object for the asset rules.
|
|
|
|
$rules = new JAccessRules($_result);
|
|
|
|
// return filtered rules
|
|
|
|
return $rules;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
return $result;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
|
|
|
* xmlAppend
|
|
|
|
*
|
|
|
|
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
|
|
|
|
* @param mixed $node A SimpleXMLElement node to append to the XML element reference, or a stdClass object containing a comment attribute to be injected before the XML node and a fieldXML attribute containing a SimpleXMLElement
|
|
|
|
*
|
|
|
|
* @return null
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function xmlAppend(&$xml, $node)
|
|
|
|
{
|
|
|
|
if (!$node)
|
|
|
|
{
|
|
|
|
// element was not returned
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (get_class($node))
|
|
|
|
{
|
|
|
|
case 'stdClass':
|
|
|
|
if (property_exists($node, 'comment'))
|
|
|
|
{
|
|
|
|
self::xmlComment($xml, $node->comment);
|
|
|
|
}
|
|
|
|
if (property_exists($node, 'fieldXML'))
|
|
|
|
{
|
|
|
|
self::xmlAppend($xml, $node->fieldXML);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'SimpleXMLElement':
|
|
|
|
$domXML = dom_import_simplexml($xml);
|
|
|
|
$domNode = dom_import_simplexml($node);
|
|
|
|
$domXML->appendChild($domXML->ownerDocument->importNode($domNode, true));
|
|
|
|
$xml = simplexml_import_dom($domXML);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlComment
|
|
|
|
*
|
|
|
|
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
|
|
|
|
* @param string $comment The comment to inject
|
|
|
|
*
|
|
|
|
* @return null
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function xmlComment(&$xml, $comment)
|
|
|
|
{
|
|
|
|
$domXML = dom_import_simplexml($xml);
|
|
|
|
$domComment = new DOMComment($comment);
|
|
|
|
$nodeTarget = $domXML->ownerDocument->importNode($domComment, true);
|
|
|
|
$domXML->appendChild($nodeTarget);
|
|
|
|
$xml = simplexml_import_dom($domXML);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlAddAttributes
|
|
|
|
*
|
|
|
|
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
|
|
|
|
* @param array $attributes The attributes to apply to the XML element
|
|
|
|
*
|
|
|
|
* @return null
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function xmlAddAttributes(&$xml, $attributes = array())
|
|
|
|
{
|
|
|
|
foreach ($attributes as $key => $value)
|
|
|
|
{
|
|
|
|
$xml->addAttribute($key, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* xmlAddOptions
|
|
|
|
*
|
|
|
|
* @param SimpleXMLElement $xml The XML element reference in which to inject a comment
|
|
|
|
* @param array $options The options to apply to the XML element
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function xmlAddOptions(&$xml, $options = array())
|
|
|
|
{
|
|
|
|
foreach ($options as $key => $value)
|
|
|
|
{
|
|
|
|
$addOption = $xml->addChild('option');
|
|
|
|
$addOption->addAttribute('value', $key);
|
|
|
|
$addOption[] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 02:21:17 +00:00
|
|
|
/**
|
|
|
|
* get the field object
|
|
|
|
*
|
|
|
|
* @param array $attributes The array of attributes
|
|
|
|
* @param string $default The default of the field
|
|
|
|
* @param array $options The options to apply to the XML element
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
*
|
|
|
|
*/
|
2020-05-30 23:59:04 +00:00
|
|
|
public static function getFieldObject(&$attributes, $default = '', $options = null)
|
2018-09-13 02:21:17 +00:00
|
|
|
{
|
|
|
|
// make sure we have attributes and a type value
|
|
|
|
if (self::checkArray($attributes) && isset($attributes['type']))
|
|
|
|
{
|
|
|
|
// make sure the form helper class is loaded
|
|
|
|
if (!method_exists('JFormHelper', 'loadFieldType'))
|
|
|
|
{
|
|
|
|
jimport('joomla.form.form');
|
|
|
|
}
|
|
|
|
// get field type
|
2020-05-30 23:59:04 +00:00
|
|
|
$field = JFormHelper::loadFieldType($attributes['type'], true);
|
|
|
|
// get field xml
|
|
|
|
$XML = self::getFieldXML($attributes, $options);
|
|
|
|
// setup the field
|
|
|
|
$field->setup($XML, $default);
|
|
|
|
// return the field object
|
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the field xml
|
|
|
|
*
|
|
|
|
* @param array $attributes The array of attributes
|
|
|
|
* @param array $options The options to apply to the XML element
|
|
|
|
*
|
|
|
|
* @return object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getFieldXML(&$attributes, $options = null)
|
|
|
|
{
|
|
|
|
// make sure we have attributes and a type value
|
|
|
|
if (self::checkArray($attributes))
|
|
|
|
{
|
2018-09-13 02:21:17 +00:00
|
|
|
// start field xml
|
|
|
|
$XML = new SimpleXMLElement('<field/>');
|
|
|
|
// load the attributes
|
|
|
|
self::xmlAddAttributes($XML, $attributes);
|
|
|
|
// check if we have options
|
|
|
|
if (self::checkArray($options))
|
|
|
|
{
|
|
|
|
// load the options
|
|
|
|
self::xmlAddOptions($XML, $options);
|
|
|
|
}
|
2020-05-30 23:59:04 +00:00
|
|
|
// return the field xml
|
|
|
|
return $XML;
|
2018-09-13 02:21:17 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
|
|
|
* Render Bool Button
|
|
|
|
*
|
2018-09-13 02:21:17 +00:00
|
|
|
* @param array $args All the args for the button
|
2018-05-05 01:16:22 +00:00
|
|
|
* 0) name
|
|
|
|
* 1) additional (options class) // not used at this time
|
|
|
|
* 2) default
|
|
|
|
* 3) yes (name)
|
|
|
|
* 4) no (name)
|
|
|
|
*
|
|
|
|
* @return string The input html of the button
|
|
|
|
*
|
|
|
|
*/
|
2015-08-24 20:22:07 +00:00
|
|
|
public static function renderBoolButton()
|
|
|
|
{
|
|
|
|
$args = func_get_args();
|
2018-05-05 01:16:22 +00:00
|
|
|
// check if there is additional button class
|
|
|
|
$additional = isset($args[1]) ? (string) $args[1] : ''; // not used at this time
|
|
|
|
// button attributes
|
|
|
|
$buttonAttributes = array(
|
|
|
|
'type' => 'radio',
|
|
|
|
'name' => isset($args[0]) ? self::htmlEscape($args[0]) : 'bool_button',
|
|
|
|
'label' => isset($args[0]) ? self::safeString(self::htmlEscape($args[0]), 'Ww') : 'Bool Button', // not seen anyway
|
|
|
|
'class' => 'btn-group',
|
|
|
|
'filter' => 'INT',
|
|
|
|
'default' => isset($args[2]) ? (int) $args[2] : 0);
|
|
|
|
// set the button options
|
|
|
|
$buttonOptions = array(
|
|
|
|
'1' => isset($args[3]) ? self::htmlEscape($args[3]) : 'JYES',
|
|
|
|
'0' => isset($args[4]) ? self::htmlEscape($args[4]) : 'JNO');
|
2018-09-13 02:21:17 +00:00
|
|
|
// return the input
|
|
|
|
return self::getFieldObject($buttonAttributes, $buttonAttributes['default'], $buttonOptions)->input;
|
2017-04-08 18:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-09-13 02:21:17 +00:00
|
|
|
* UIKIT Component Classes
|
|
|
|
**/
|
2017-04-08 18:35:55 +00:00
|
|
|
public static $uk_components = array(
|
|
|
|
'data-uk-grid' => array(
|
|
|
|
'grid' ),
|
|
|
|
'uk-accordion' => array(
|
|
|
|
'accordion' ),
|
|
|
|
'uk-autocomplete' => array(
|
|
|
|
'autocomplete' ),
|
|
|
|
'data-uk-datepicker' => array(
|
|
|
|
'datepicker' ),
|
|
|
|
'uk-form-password' => array(
|
|
|
|
'form-password' ),
|
|
|
|
'uk-form-select' => array(
|
|
|
|
'form-select' ),
|
|
|
|
'data-uk-htmleditor' => array(
|
|
|
|
'htmleditor' ),
|
|
|
|
'data-uk-lightbox' => array(
|
|
|
|
'lightbox' ),
|
|
|
|
'uk-nestable' => array(
|
|
|
|
'nestable' ),
|
|
|
|
'UIkit.notify' => array(
|
|
|
|
'notify' ),
|
|
|
|
'data-uk-parallax' => array(
|
|
|
|
'parallax' ),
|
|
|
|
'uk-search' => array(
|
|
|
|
'search' ),
|
|
|
|
'uk-slider' => array(
|
|
|
|
'slider' ),
|
|
|
|
'uk-slideset' => array(
|
|
|
|
'slideset' ),
|
|
|
|
'uk-slideshow' => array(
|
|
|
|
'slideshow',
|
|
|
|
'slideshow-fx' ),
|
|
|
|
'uk-sortable' => array(
|
|
|
|
'sortable' ),
|
|
|
|
'data-uk-sticky' => array(
|
|
|
|
'sticky' ),
|
|
|
|
'data-uk-timepicker' => array(
|
|
|
|
'timepicker' ),
|
|
|
|
'data-uk-tooltip' => array(
|
|
|
|
'tooltip' ),
|
|
|
|
'uk-placeholder' => array(
|
|
|
|
'placeholder' ),
|
|
|
|
'uk-dotnav' => array(
|
|
|
|
'dotnav' ),
|
|
|
|
'uk-slidenav' => array(
|
|
|
|
'slidenav' ),
|
|
|
|
'uk-form' => array(
|
|
|
|
'form-advanced' ),
|
|
|
|
'uk-progress' => array(
|
|
|
|
'progress' ),
|
|
|
|
'upload-drop' => array(
|
|
|
|
'upload', 'form-file' )
|
|
|
|
);
|
2018-09-13 02:21:17 +00:00
|
|
|
|
2017-04-08 18:35:55 +00:00
|
|
|
/**
|
2018-09-13 02:21:17 +00:00
|
|
|
* Add UIKIT Components
|
|
|
|
**/
|
2017-04-08 18:35:55 +00:00
|
|
|
public static $uikit = false;
|
|
|
|
|
|
|
|
/**
|
2018-09-13 02:21:17 +00:00
|
|
|
* Get UIKIT Components
|
|
|
|
**/
|
2017-04-08 18:35:55 +00:00
|
|
|
public static function getUikitComp($content,$classes = array())
|
|
|
|
{
|
|
|
|
if (strpos($content,'class="uk-') !== false)
|
|
|
|
{
|
|
|
|
// reset
|
|
|
|
$temp = array();
|
|
|
|
foreach (self::$uk_components as $looking => $add)
|
|
|
|
{
|
|
|
|
if (strpos($content,$looking) !== false)
|
|
|
|
{
|
|
|
|
$temp[] = $looking;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// make sure uikit is loaded to config
|
|
|
|
if (strpos($content,'class="uk-') !== false)
|
|
|
|
{
|
|
|
|
self::$uikit = true;
|
|
|
|
}
|
|
|
|
// sorter
|
|
|
|
if (self::checkArray($temp))
|
|
|
|
{
|
|
|
|
// merger
|
|
|
|
if (self::checkArray($classes))
|
|
|
|
{
|
|
|
|
$newTemp = array_merge($temp,$classes);
|
|
|
|
$temp = array_unique($newTemp);
|
|
|
|
}
|
|
|
|
return $temp;
|
|
|
|
}
|
2018-09-13 02:21:17 +00:00
|
|
|
}
|
2017-04-08 18:35:55 +00:00
|
|
|
if (self::checkArray($classes))
|
|
|
|
{
|
|
|
|
return $classes;
|
|
|
|
}
|
|
|
|
return false;
|
2018-09-13 02:21:17 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
|
|
|
* Get a variable
|
|
|
|
*
|
|
|
|
* @param string $table The table from which to get the variable
|
|
|
|
* @param string $where The value where
|
|
|
|
* @param string $whereString The target/field string where/name
|
|
|
|
* @param string $what The return field
|
|
|
|
* @param string $operator The operator between $whereString/field and $where/value
|
|
|
|
* @param string $main The component in which the table is found
|
|
|
|
*
|
|
|
|
* @return mix string/int/float
|
|
|
|
*
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function getVar($table, $where = null, $whereString = 'user', $what = 'id', $operator = '=', $main = 'demo')
|
|
|
|
{
|
|
|
|
if(!$where)
|
|
|
|
{
|
|
|
|
$where = JFactory::getUser()->id;
|
|
|
|
}
|
|
|
|
// Get a db connection.
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
|
|
$query = $db->getQuery(true);
|
2016-06-24 14:32:36 +00:00
|
|
|
$query->select($db->quoteName(array($what)));
|
|
|
|
if (empty($table))
|
|
|
|
{
|
|
|
|
$query->from($db->quoteName('#__'.$main));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query->from($db->quoteName('#__'.$main.'_'.$table));
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
if (is_numeric($where))
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName($whereString) . ' '.$operator.' '.(int) $where);
|
|
|
|
}
|
|
|
|
elseif (is_string($where))
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName($whereString) . ' '.$operator.' '. $db->quote((string)$where));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
if ($db->getNumRows())
|
|
|
|
{
|
|
|
|
return $db->loadResult();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
|
|
|
* Get array of variables
|
|
|
|
*
|
|
|
|
* @param string $table The table from which to get the variables
|
|
|
|
* @param string $where The value where
|
|
|
|
* @param string $whereString The target/field string where/name
|
|
|
|
* @param string $what The return field
|
|
|
|
* @param string $operator The operator between $whereString/field and $where/value
|
|
|
|
* @param string $main The component in which the table is found
|
|
|
|
* @param bool $unique The switch to return a unique array
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function getVars($table, $where = null, $whereString = 'user', $what = 'id', $operator = 'IN', $main = 'demo', $unique = true)
|
|
|
|
{
|
|
|
|
if(!$where)
|
|
|
|
{
|
|
|
|
$where = JFactory::getUser()->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self::checkArray($where) && $where > 0)
|
|
|
|
{
|
|
|
|
$where = array($where);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self::checkArray($where))
|
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// prep main <-- why? well if $main='' is empty then $table can be categories or users
|
|
|
|
if (self::checkString($main))
|
|
|
|
{
|
|
|
|
$main = '_'.ltrim($main, '_');
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
// Get a db connection.
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
// Create a new query object.
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
$query->select($db->quoteName(array($what)));
|
2017-08-21 12:17:01 +00:00
|
|
|
if (empty($table))
|
|
|
|
{
|
|
|
|
$query->from($db->quoteName('#__'.$main));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query->from($db->quoteName('#_'.$main.'_'.$table));
|
|
|
|
}
|
2020-05-30 23:59:04 +00:00
|
|
|
// add strings to array search
|
|
|
|
if ('IN_STRINGS' === $operator || 'NOT IN_STRINGS' === $operator)
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName($whereString) . ' ' . str_replace('_STRINGS', '', $operator) . ' ("' . implode('","',$where) . '")');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$query->where($db->quoteName($whereString) . ' ' . $operator . ' (' . implode(',',$where) . ')');
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
if ($db->getNumRows())
|
|
|
|
{
|
|
|
|
if ($unique)
|
|
|
|
{
|
|
|
|
return array_unique($db->loadColumn());
|
|
|
|
}
|
|
|
|
return $db->loadColumn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2016-05-02 15:38:37 +00:00
|
|
|
|
|
|
|
public static function isPublished($id,$type)
|
|
|
|
{
|
|
|
|
if ($type == 'raw')
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
2016-05-02 15:38:37 +00:00
|
|
|
$type = 'item';
|
|
|
|
}
|
|
|
|
$db = JFactory::getDbo();
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
$query->select(array('a.published'));
|
|
|
|
$query->from('#__demo_'.$type.' AS a');
|
|
|
|
$query->where('a.id = '. (int) $id);
|
|
|
|
$query->where('a.published = 1');
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
$found = $db->getNumRows();
|
|
|
|
if($found)
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
2016-05-02 15:38:37 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getGroupName($id)
|
|
|
|
{
|
|
|
|
$db = JFactory::getDBO();
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
$query->select(array('a.title'));
|
|
|
|
$query->from('#__usergroups AS a');
|
|
|
|
$query->where('a.id = '. (int) $id);
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
$found = $db->getNumRows();
|
|
|
|
if($found)
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
2016-05-02 15:38:37 +00:00
|
|
|
return $db->loadResult();
|
|
|
|
}
|
|
|
|
return $id;
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Get the action permissions
|
|
|
|
*
|
|
|
|
* @param string $view The related view name
|
|
|
|
* @param int $record The item to act upon
|
|
|
|
* @param string $views The related list view name
|
|
|
|
* @param mixed $target Only get this permission (like edit, create, delete)
|
|
|
|
* @param string $component The target component
|
|
|
|
* @param object $user The user whose permissions we are loading
|
|
|
|
*
|
|
|
|
* @return object The JObject of permission/authorised actions
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public static function getActions($view, &$record = null, $views = null, $target = null, $component = 'demo', $user = 'null')
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2020-05-30 23:59:04 +00:00
|
|
|
// load the user if not given
|
|
|
|
if (!self::checkObject($user))
|
|
|
|
{
|
|
|
|
// get the user object
|
|
|
|
$user = JFactory::getUser();
|
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
// load the JObject
|
|
|
|
$result = new JObject;
|
|
|
|
// make view name safe (just incase)
|
|
|
|
$view = self::safeString($view);
|
2018-05-05 01:16:22 +00:00
|
|
|
if (self::checkString($views))
|
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
$views = self::safeString($views);
|
2019-04-23 20:37:57 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
// get all actions from component
|
2019-04-23 20:37:57 +00:00
|
|
|
$actions = JAccess::getActionsFromFile(
|
|
|
|
JPATH_ADMINISTRATOR . '/components/com_' . $component . '/access.xml',
|
|
|
|
"/access/section[@name='component']/"
|
|
|
|
);
|
|
|
|
// if non found then return empty JObject
|
|
|
|
if (empty($actions))
|
|
|
|
{
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
// get created by if not found
|
|
|
|
if (self::checkObject($record) && !isset($record->created_by) && isset($record->id))
|
|
|
|
{
|
|
|
|
$record->created_by = self::getVar($view, $record->id, 'id', 'created_by', '=', $component);
|
|
|
|
}
|
|
|
|
// set actions only set in component settings
|
|
|
|
$componentActions = array('core.admin', 'core.manage', 'core.options', 'core.export');
|
|
|
|
// check if we have a target
|
|
|
|
$checkTarget = false;
|
|
|
|
if ($target)
|
|
|
|
{
|
|
|
|
// convert to an array
|
|
|
|
if (self::checkString($target))
|
|
|
|
{
|
|
|
|
$target = array($target);
|
|
|
|
}
|
|
|
|
// check if we are good to go
|
|
|
|
if (self::checkArray($target))
|
|
|
|
{
|
|
|
|
$checkTarget = true;
|
|
|
|
}
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
// loop the actions and set the permissions
|
|
|
|
foreach ($actions as $action)
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// check target action filter
|
|
|
|
if ($checkTarget && self::filterActions($view, $action->name, $target))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
// set to use component default
|
2016-02-20 20:19:24 +00:00
|
|
|
$fallback = true;
|
2019-04-23 20:37:57 +00:00
|
|
|
// reset permission per/action
|
|
|
|
$permission = false;
|
|
|
|
$catpermission = false;
|
|
|
|
// set area
|
|
|
|
$area = 'comp';
|
|
|
|
// check if the record has an ID and the action is item related (not a component action)
|
|
|
|
if (self::checkObject($record) && isset($record->id) && $record->id > 0 && !in_array($action->name, $componentActions) &&
|
|
|
|
(strpos($action->name, 'core.') !== false || strpos($action->name, $view . '.') !== false))
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// we are in item
|
|
|
|
$area = 'item';
|
2015-12-03 02:17:44 +00:00
|
|
|
// The record has been set. Check the record permissions.
|
2019-04-23 20:37:57 +00:00
|
|
|
$permission = $user->authorise($action->name, 'com_' . $component . '.' . $view . '.' . (int) $record->id);
|
|
|
|
// if no permission found, check edit own
|
|
|
|
if (!$permission)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// With edit, if the created_by matches current user then dig deeper.
|
|
|
|
if (($action->name === 'core.edit' || $action->name === $view . '.edit') && $record->created_by > 0 && ($record->created_by == $user->id))
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// the correct target
|
|
|
|
$coreCheck = (array) explode('.', $action->name);
|
|
|
|
// check that we have both local and global access
|
|
|
|
if ($user->authorise($coreCheck[0] . '.edit.own', 'com_' . $component . '.' . $view . '.' . (int) $record->id) &&
|
|
|
|
$user->authorise($coreCheck[0] . '.edit.own', 'com_' . $component))
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// allow edit
|
|
|
|
$result->set($action->name, true);
|
|
|
|
// set not to use global default
|
|
|
|
// because we already validated it
|
|
|
|
$fallback = false;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
else
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// do not allow edit
|
|
|
|
$result->set($action->name, false);
|
|
|
|
$fallback = false;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif (self::checkString($views) && isset($record->catid) && $record->catid > 0)
|
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// we are in item
|
|
|
|
$area = 'category';
|
|
|
|
// set the core check
|
|
|
|
$coreCheck = explode('.', $action->name);
|
|
|
|
$core = $coreCheck[0];
|
2018-05-05 01:16:22 +00:00
|
|
|
// make sure we use the core. action check for the categories
|
2019-04-23 20:37:57 +00:00
|
|
|
if (strpos($action->name, $view) !== false && strpos($action->name, 'core.') === false )
|
|
|
|
{
|
|
|
|
$coreCheck[0] = 'core';
|
|
|
|
$categoryCheck = implode('.', $coreCheck);
|
2018-05-05 01:16:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$categoryCheck = $action->name;
|
|
|
|
}
|
|
|
|
// The record has a category. Check the category permissions.
|
2019-04-23 20:37:57 +00:00
|
|
|
$catpermission = $user->authorise($categoryCheck, 'com_' . $component . '.' . $views . '.category.' . (int) $record->catid);
|
2015-12-03 02:17:44 +00:00
|
|
|
if (!$catpermission && !is_null($catpermission))
|
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// With edit, if the created_by matches current user then dig deeper.
|
|
|
|
if (($action->name === 'core.edit' || $action->name === $view . '.edit') && $record->created_by > 0 && ($record->created_by == $user->id))
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// check that we have both local and global access
|
|
|
|
if ($user->authorise('core.edit.own', 'com_' . $component . '.' . $views . '.category.' . (int) $record->catid) &&
|
|
|
|
$user->authorise($core . '.edit.own', 'com_' . $component))
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// allow edit
|
|
|
|
$result->set($action->name, true);
|
|
|
|
// set not to use global default
|
|
|
|
// because we already validated it
|
|
|
|
$fallback = false;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
else
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// do not allow edit
|
|
|
|
$result->set($action->name, false);
|
|
|
|
$fallback = false;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-20 20:19:24 +00:00
|
|
|
// if allowed then fallback on component global settings
|
|
|
|
if ($fallback)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
// if item/category blocks access then don't fall back on global
|
|
|
|
if ((($area === 'item') && !$permission) || (($area === 'category') && !$catpermission))
|
|
|
|
{
|
|
|
|
// do not allow
|
|
|
|
$result->set($action->name, false);
|
|
|
|
}
|
|
|
|
// Finally remember the global settings have the final say. (even if item allow)
|
|
|
|
// The local item permissions can block, but it can't open and override of global permissions.
|
|
|
|
// Since items are created by users and global permissions is set by system admin.
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$result->set($action->name, $user->authorise($action->name, 'com_' . $component));
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Filter the action permissions
|
|
|
|
*
|
|
|
|
* @param string $action The action to check
|
|
|
|
* @param array $targets The array of target actions
|
|
|
|
*
|
|
|
|
* @return boolean true if action should be filtered out
|
|
|
|
*
|
|
|
|
*/
|
2019-04-23 20:37:57 +00:00
|
|
|
protected static function filterActions(&$view, &$action, &$targets)
|
|
|
|
{
|
|
|
|
foreach ($targets as $target)
|
|
|
|
{
|
|
|
|
if (strpos($action, $view . '.' . $target) !== false ||
|
|
|
|
strpos($action, 'core.' . $target) !== false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Check if have an json string
|
|
|
|
*
|
|
|
|
* @input string The json string to check
|
|
|
|
*
|
|
|
|
* @returns bool true on success
|
|
|
|
*/
|
2016-03-10 21:23:44 +00:00
|
|
|
public static function checkJson($string)
|
|
|
|
{
|
|
|
|
if (self::checkString($string))
|
|
|
|
{
|
|
|
|
json_decode($string);
|
|
|
|
return (json_last_error() === JSON_ERROR_NONE);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Check if have an object with a length
|
|
|
|
*
|
|
|
|
* @input object The object to check
|
|
|
|
*
|
|
|
|
* @returns bool true on success
|
|
|
|
*/
|
2015-08-24 20:22:07 +00:00
|
|
|
public static function checkObject($object)
|
|
|
|
{
|
2018-05-05 01:16:22 +00:00
|
|
|
if (isset($object) && is_object($object))
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2018-05-05 01:16:22 +00:00
|
|
|
return count((array)$object) > 0;
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Check if have an array with a length
|
|
|
|
*
|
|
|
|
* @input array The array to check
|
|
|
|
*
|
|
|
|
* @returns bool/int number of items in array on success
|
|
|
|
*/
|
2017-04-08 18:35:55 +00:00
|
|
|
public static function checkArray($array, $removeEmptyString = false)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2019-04-23 20:37:57 +00:00
|
|
|
if (isset($array) && is_array($array) && ($nr = count((array)$array)) > 0)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// also make sure the empty strings are removed
|
|
|
|
if ($removeEmptyString)
|
|
|
|
{
|
|
|
|
foreach ($array as $key => $string)
|
|
|
|
{
|
|
|
|
if (empty($string))
|
|
|
|
{
|
|
|
|
unset($array[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self::checkArray($array, false);
|
|
|
|
}
|
2019-04-23 20:37:57 +00:00
|
|
|
return $nr;
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Check if have a string with a length
|
|
|
|
*
|
|
|
|
* @input string The string to check
|
|
|
|
*
|
|
|
|
* @returns bool true on success
|
|
|
|
*/
|
2015-08-24 20:22:07 +00:00
|
|
|
public static function checkString($string)
|
|
|
|
{
|
|
|
|
if (isset($string) && is_string($string) && strlen($string) > 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Check if we are connected
|
|
|
|
* Thanks https://stackoverflow.com/a/4860432/1429677
|
|
|
|
*
|
|
|
|
* @returns bool true on success
|
|
|
|
*/
|
2018-05-05 01:16:22 +00:00
|
|
|
public static function isConnected()
|
|
|
|
{
|
|
|
|
// If example.com is down, then probably the whole internet is down, since IANA maintains the domain. Right?
|
|
|
|
$connected = @fsockopen("www.example.com", 80);
|
|
|
|
// website, port (try 80 or 443)
|
|
|
|
if ($connected)
|
|
|
|
{
|
|
|
|
//action when connected
|
|
|
|
$is_conn = true;
|
|
|
|
fclose($connected);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//action in connection failure
|
|
|
|
$is_conn = false;
|
|
|
|
}
|
|
|
|
return $is_conn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Merge an array of array's
|
|
|
|
*
|
|
|
|
* @input array The arrays you would like to merge
|
|
|
|
*
|
|
|
|
* @returns array on success
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function mergeArrays($arrays)
|
|
|
|
{
|
|
|
|
if(self::checkArray($arrays))
|
|
|
|
{
|
|
|
|
$arrayBuket = array();
|
|
|
|
foreach ($arrays as $array)
|
|
|
|
{
|
|
|
|
if (self::checkArray($array))
|
|
|
|
{
|
|
|
|
$arrayBuket = array_merge($arrayBuket, $array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $arrayBuket;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:17:01 +00:00
|
|
|
// typo sorry!
|
2015-08-24 20:22:07 +00:00
|
|
|
public static function sorten($string, $length = 40, $addTip = true)
|
2017-08-21 12:17:01 +00:00
|
|
|
{
|
|
|
|
return self::shorten($string, $length, $addTip);
|
|
|
|
}
|
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Shorten a string
|
|
|
|
*
|
|
|
|
* @input string The you would like to shorten
|
|
|
|
*
|
|
|
|
* @returns string on success
|
|
|
|
*/
|
2017-08-21 12:17:01 +00:00
|
|
|
public static function shorten($string, $length = 40, $addTip = true)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
|
|
|
if (self::checkString($string))
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2015-08-24 20:22:07 +00:00
|
|
|
$initial = strlen($string);
|
|
|
|
$words = preg_split('/([\s\n\r]+)/', $string, null, PREG_SPLIT_DELIM_CAPTURE);
|
2018-09-13 02:21:17 +00:00
|
|
|
$words_count = count((array)$words);
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
$word_length = 0;
|
|
|
|
$last_word = 0;
|
|
|
|
for (; $last_word < $words_count; ++$last_word)
|
|
|
|
{
|
|
|
|
$word_length += strlen($words[$last_word]);
|
|
|
|
if ($word_length > $length)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2015-08-24 20:22:07 +00:00
|
|
|
$newString = implode(array_slice($words, 0, $last_word));
|
|
|
|
$final = strlen($newString);
|
|
|
|
if ($initial != $final && $addTip)
|
|
|
|
{
|
2017-08-21 12:17:01 +00:00
|
|
|
$title = self::shorten($string, 400 , false);
|
2015-08-24 20:22:07 +00:00
|
|
|
return '<span class="hasTip" title="'.$title.'" style="cursor:help">'.trim($newString).'...</span>';
|
|
|
|
}
|
|
|
|
elseif ($initial != $final && !$addTip)
|
|
|
|
{
|
|
|
|
return trim($newString).'...';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $string;
|
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2018-05-05 01:16:22 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Making strings safe (various ways)
|
|
|
|
*
|
|
|
|
* @input string The you would like to make safe
|
|
|
|
*
|
|
|
|
* @returns string on success
|
|
|
|
*/
|
2018-09-13 02:21:17 +00:00
|
|
|
public static function safeString($string, $type = 'L', $spacer = '_', $replaceNumbers = true, $keepOnlyCharacters = true)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
if ($replaceNumbers === true)
|
2015-12-03 02:17:44 +00:00
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// remove all numbers and replace with english text version (works well only up to millions)
|
|
|
|
$string = self::replaceNumbers($string);
|
|
|
|
}
|
|
|
|
// 0nly continue if we have a string
|
2018-05-05 01:16:22 +00:00
|
|
|
if (self::checkString($string))
|
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// create file name without the extention that is safe
|
|
|
|
if ($type === 'filename')
|
|
|
|
{
|
|
|
|
// make sure VDM is not in the string
|
|
|
|
$string = str_replace('VDM', 'vDm', $string);
|
|
|
|
// Remove anything which isn't a word, whitespace, number
|
|
|
|
// or any of the following caracters -_()
|
|
|
|
// If you don't need to handle multi-byte characters
|
|
|
|
// you can use preg_replace rather than mb_ereg_replace
|
|
|
|
// Thanks @Łukasz Rysiak!
|
2017-08-21 12:17:01 +00:00
|
|
|
// $string = mb_ereg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
|
|
|
$string = preg_replace("([^\w\s\d\-_\(\)])", '', $string);
|
2017-04-08 18:35:55 +00:00
|
|
|
// http://stackoverflow.com/a/2021729/1429677
|
|
|
|
return preg_replace('/\s+/', ' ', $string);
|
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
// remove all other characters
|
|
|
|
$string = trim($string);
|
|
|
|
$string = preg_replace('/'.$spacer.'+/', ' ', $string);
|
|
|
|
$string = preg_replace('/\s+/', ' ', $string);
|
2020-05-30 23:59:04 +00:00
|
|
|
// Transliterate string
|
|
|
|
$string = self::transliterate($string);
|
2018-09-13 02:21:17 +00:00
|
|
|
// remove all and keep only characters
|
|
|
|
if ($keepOnlyCharacters)
|
|
|
|
{
|
|
|
|
$string = preg_replace("/[^A-Za-z ]/", '', $string);
|
|
|
|
}
|
|
|
|
// keep both numbers and characters
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$string = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
|
|
|
|
}
|
2017-04-08 18:35:55 +00:00
|
|
|
// select final adaptations
|
|
|
|
if ($type === 'L' || $type === 'strtolower')
|
2018-05-05 01:16:22 +00:00
|
|
|
{
|
|
|
|
// replace white space with underscore
|
|
|
|
$string = preg_replace('/\s+/', $spacer, $string);
|
|
|
|
// default is to return lower
|
|
|
|
return strtolower($string);
|
|
|
|
}
|
2017-04-08 18:35:55 +00:00
|
|
|
elseif ($type === 'W')
|
|
|
|
{
|
|
|
|
// return a string with all first letter of each word uppercase(no undersocre)
|
|
|
|
return ucwords(strtolower($string));
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2017-04-08 18:35:55 +00:00
|
|
|
elseif ($type === 'w' || $type === 'word')
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// return a string with all lowercase(no undersocre)
|
|
|
|
return strtolower($string);
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2017-04-08 18:35:55 +00:00
|
|
|
elseif ($type === 'Ww' || $type === 'Word')
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// return a string with first letter of the first word uppercase and all the rest lowercase(no undersocre)
|
2015-12-03 02:17:44 +00:00
|
|
|
return ucfirst(strtolower($string));
|
|
|
|
}
|
2017-04-08 18:35:55 +00:00
|
|
|
elseif ($type === 'WW' || $type === 'WORD')
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2017-04-08 18:35:55 +00:00
|
|
|
// return a string with all the uppercase(no undersocre)
|
|
|
|
return strtoupper($string);
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
elseif ($type === 'U' || $type === 'strtoupper')
|
|
|
|
{
|
|
|
|
// replace white space with underscore
|
|
|
|
$string = preg_replace('/\s+/', $spacer, $string);
|
|
|
|
// return all upper
|
|
|
|
return strtoupper($string);
|
|
|
|
}
|
|
|
|
elseif ($type === 'F' || $type === 'ucfirst')
|
|
|
|
{
|
|
|
|
// replace white space with underscore
|
|
|
|
$string = preg_replace('/\s+/', $spacer, $string);
|
|
|
|
// return with first caracter to upper
|
|
|
|
return ucfirst(strtolower($string));
|
|
|
|
}
|
|
|
|
elseif ($type === 'cA' || $type === 'cAmel' || $type === 'camelcase')
|
2017-04-08 18:35:55 +00:00
|
|
|
{
|
|
|
|
// convert all words to first letter uppercase
|
|
|
|
$string = ucwords(strtolower($string));
|
|
|
|
// remove white space
|
|
|
|
$string = preg_replace('/\s+/', '', $string);
|
|
|
|
// now return first letter lowercase
|
|
|
|
return lcfirst($string);
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
// return string
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
// not a string
|
|
|
|
return '';
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
2020-05-30 23:59:04 +00:00
|
|
|
public static function transliterate($string)
|
|
|
|
{
|
|
|
|
// set tag only once
|
|
|
|
if (!self::checkString(self::$langTag))
|
|
|
|
{
|
|
|
|
// get global value
|
|
|
|
self::$langTag = JComponentHelper::getParams('com_demo')->get('language', 'en-GB');
|
|
|
|
}
|
|
|
|
// Transliterate on the language requested
|
|
|
|
$lang = Language::getInstance(self::$langTag);
|
|
|
|
return $lang->transliterate($string);
|
|
|
|
}
|
|
|
|
|
2017-08-21 12:17:01 +00:00
|
|
|
public static function htmlEscape($var, $charset = 'UTF-8', $shorten = false, $length = 40)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
|
|
|
if (self::checkString($var))
|
|
|
|
{
|
|
|
|
$filter = new JFilterInput();
|
|
|
|
$string = $filter->clean(html_entity_decode(htmlentities($var, ENT_COMPAT, $charset)), 'HTML');
|
2017-08-21 12:17:01 +00:00
|
|
|
if ($shorten)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2017-08-21 12:17:01 +00:00
|
|
|
return self::shorten($string,$length);
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
return $string;
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return '';
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
|
|
|
|
public static function replaceNumbers($string)
|
2015-08-24 20:22:07 +00:00
|
|
|
{
|
2015-12-03 02:17:44 +00:00
|
|
|
// set numbers array
|
|
|
|
$numbers = array();
|
|
|
|
// first get all numbers
|
|
|
|
preg_match_all('!\d+!', $string, $numbers);
|
|
|
|
// check if we have any numbers
|
|
|
|
if (isset($numbers[0]) && self::checkArray($numbers[0]))
|
|
|
|
{
|
|
|
|
foreach ($numbers[0] as $number)
|
|
|
|
{
|
|
|
|
$searchReplace[$number] = self::numberToString((int)$number);
|
|
|
|
}
|
|
|
|
// now replace numbers in string
|
|
|
|
$string = str_replace(array_keys($searchReplace), array_values($searchReplace),$string);
|
|
|
|
// check if we missed any, strange if we did.
|
|
|
|
return self::replaceNumbers($string);
|
|
|
|
}
|
|
|
|
// return the string with no numbers remaining.
|
|
|
|
return $string;
|
|
|
|
}
|
2018-05-05 01:16:22 +00:00
|
|
|
|
2015-12-03 02:17:44 +00:00
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Convert an integer into an English word string
|
|
|
|
* Thanks to Tom Nicholson <http://php.net/manual/en/function.strval.php#41988>
|
|
|
|
*
|
|
|
|
* @input an int
|
|
|
|
* @returns a string
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function numberToString($x)
|
|
|
|
{
|
|
|
|
$nwords = array( "zero", "one", "two", "three", "four", "five", "six", "seven",
|
|
|
|
"eight", "nine", "ten", "eleven", "twelve", "thirteen",
|
|
|
|
"fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
|
|
|
|
"nineteen", "twenty", 30 => "thirty", 40 => "forty",
|
|
|
|
50 => "fifty", 60 => "sixty", 70 => "seventy", 80 => "eighty",
|
|
|
|
90 => "ninety" );
|
|
|
|
|
|
|
|
if(!is_numeric($x))
|
|
|
|
{
|
|
|
|
$w = $x;
|
|
|
|
}
|
|
|
|
elseif(fmod($x, 1) != 0)
|
|
|
|
{
|
|
|
|
$w = $x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if($x < 0)
|
|
|
|
{
|
|
|
|
$w = 'minus ';
|
|
|
|
$x = -$x;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$w = '';
|
|
|
|
// ... now $x is a non-negative integer.
|
|
|
|
}
|
|
|
|
|
|
|
|
if($x < 21) // 0 to 20
|
|
|
|
{
|
|
|
|
$w .= $nwords[$x];
|
|
|
|
}
|
|
|
|
elseif($x < 100) // 21 to 99
|
|
|
|
{
|
|
|
|
$w .= $nwords[10 * floor($x/10)];
|
|
|
|
$r = fmod($x, 10);
|
|
|
|
if($r > 0)
|
|
|
|
{
|
|
|
|
$w .= ' '. $nwords[$r];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif($x < 1000) // 100 to 999
|
|
|
|
{
|
|
|
|
$w .= $nwords[floor($x/100)] .' hundred';
|
|
|
|
$r = fmod($x, 100);
|
|
|
|
if($r > 0)
|
|
|
|
{
|
|
|
|
$w .= ' and '. self::numberToString($r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif($x < 1000000) // 1000 to 999999
|
|
|
|
{
|
|
|
|
$w .= self::numberToString(floor($x/1000)) .' thousand';
|
|
|
|
$r = fmod($x, 1000);
|
|
|
|
if($r > 0)
|
|
|
|
{
|
|
|
|
$w .= ' ';
|
|
|
|
if($r < 100)
|
|
|
|
{
|
|
|
|
$w .= 'and ';
|
|
|
|
}
|
|
|
|
$w .= self::numberToString($r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // millions
|
|
|
|
{
|
|
|
|
$w .= self::numberToString(floor($x/1000000)) .' million';
|
|
|
|
$r = fmod($x, 1000000);
|
|
|
|
if($r > 0)
|
|
|
|
{
|
|
|
|
$w .= ' ';
|
|
|
|
if($r < 100)
|
|
|
|
{
|
2016-05-02 15:38:37 +00:00
|
|
|
$w .= 'and ';
|
2015-12-03 02:17:44 +00:00
|
|
|
}
|
|
|
|
$w .= self::numberToString($r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $w;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-30 23:59:04 +00:00
|
|
|
* Random Key
|
|
|
|
*
|
|
|
|
* @returns a string
|
|
|
|
*/
|
2015-12-03 02:17:44 +00:00
|
|
|
public static function randomkey($size)
|
|
|
|
{
|
|
|
|
$bag = "abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
|
|
|
|
$key = array();
|
|
|
|
$bagsize = strlen($bag) - 1;
|
|
|
|
for ($i = 0; $i < $size; $i++)
|
|
|
|
{
|
|
|
|
$get = rand(0, $bagsize);
|
|
|
|
$key[] = $bag[$get];
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
2015-12-03 02:17:44 +00:00
|
|
|
return implode($key);
|
2015-08-24 20:22:07 +00:00
|
|
|
}
|
|
|
|
}
|