Comment out: JTableObserverContenthistory::createObserver(, array('typeAlias' => 'com_demo.look'));

This commit is contained in:
Oh 2021-10-16 09:40:36 +02:00
parent 92e1dfb005
commit f0339880c3
Signed by untrusted user: Oh
GPG Key ID: F91C6D0A21225F8A

View File

@ -1,322 +1,322 @@
<?php <?php
/*----------------------------------------------------------------------------------| www.vdm.io |----/ /*----------------------------------------------------------------------------------| www.vdm.io |----/
Vast Development Method Vast Development Method
/-------------------------------------------------------------------------------------------------------/ /-------------------------------------------------------------------------------------------------------/
@version 2.0.3 @version 2.0.3
@build 8th February, 2021 @build 8th February, 2021
@created 18th October, 2016 @created 18th October, 2016
@package Demo @package Demo
@subpackage look.php @subpackage look.php
@author Llewellyn van der Merwe <https://www.vdm.io/> @author Llewellyn van der Merwe <https://www.vdm.io/>
@copyright Copyright (C) 2015. All Rights Reserved @copyright Copyright (C) 2015. All Rights Reserved
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html @license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____ ____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _) (_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )( .-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__) \____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
/------------------------------------------------------------------------------------------------------*/ /------------------------------------------------------------------------------------------------------*/
// No direct access to this file // No direct access to this file
defined('_JEXEC') or die('Restricted access'); defined('_JEXEC') or die('Restricted access');
use Joomla\Registry\Registry; use Joomla\Registry\Registry;
use Joomla\String\StringHelper; use Joomla\String\StringHelper;
use Joomla\Utilities\ArrayHelper; use Joomla\Utilities\ArrayHelper;
/** /**
* Looks Table class * Looks Table class
*/ */
class DemoTableLook extends JTable class DemoTableLook extends JTable
{ {
/** /**
* Ensure the params and metadata in json encoded in the bind method * Ensure the params and metadata in json encoded in the bind method
* *
* @var array * @var array
* @since 3.3 * @since 3.3
*/ */
protected $_jsonEncode = array('params', 'metadata'); protected $_jsonEncode = array('params', 'metadata');
/** /**
* Constructor * Constructor
* *
* @param object Database connector object * @param object Database connector object
*/ */
function __construct(&$db) function __construct(&$db)
{ {
parent::__construct('#__demo_look', 'id', $db); parent::__construct('#__demo_look', 'id', $db);
// Adding History Options // Adding History Options
JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_demo.look')); // JTableObserverContenthistory::createObserver($this, array('typeAlias' => 'com_demo.look'));
} }
public function bind($array, $ignore = '') public function bind($array, $ignore = '')
{ {
if (isset($array['params']) && is_array($array['params'])) if (isset($array['params']) && is_array($array['params']))
{ {
$registry = new JRegistry; $registry = new JRegistry;
$registry->loadArray($array['params']); $registry->loadArray($array['params']);
$array['params'] = (string) $registry; $array['params'] = (string) $registry;
} }
if (isset($array['metadata']) && is_array($array['metadata'])) if (isset($array['metadata']) && is_array($array['metadata']))
{ {
$registry = new JRegistry; $registry = new JRegistry;
$registry->loadArray($array['metadata']); $registry->loadArray($array['metadata']);
$array['metadata'] = (string) $registry; $array['metadata'] = (string) $registry;
} }
// Bind the rules. // Bind the rules.
if (isset($array['rules']) && is_array($array['rules'])) if (isset($array['rules']) && is_array($array['rules']))
{ {
$rules = new JAccessRules($array['rules']); $rules = new JAccessRules($array['rules']);
$this->setRules($rules); $this->setRules($rules);
} }
return parent::bind($array, $ignore); return parent::bind($array, $ignore);
} }
/** /**
* Overload the store method for the Look table. * Overload the store method for the Look table.
* *
* @param boolean Toggle whether null values should be updated. * @param boolean Toggle whether null values should be updated.
* @return boolean True on success, false on failure. * @return boolean True on success, false on failure.
* @since 1.6 * @since 1.6
*/ */
public function store($updateNulls = false) public function store($updateNulls = false)
{ {
$date = JFactory::getDate(); $date = JFactory::getDate();
$user = JFactory::getUser(); $user = JFactory::getUser();
if ($this->id) if ($this->id)
{ {
// Existing item // Existing item
$this->modified = $date->toSql(); $this->modified = $date->toSql();
$this->modified_by = $user->get('id'); $this->modified_by = $user->get('id');
} }
else else
{ {
// New look. A look created and created_by field can be set by the user, // New look. A look created and created_by field can be set by the user,
// so we don't touch either of these if they are set. // so we don't touch either of these if they are set.
if (!(int) $this->created) if (!(int) $this->created)
{ {
$this->created = $date->toSql(); $this->created = $date->toSql();
} }
if (empty($this->created_by)) if (empty($this->created_by))
{ {
$this->created_by = $user->get('id'); $this->created_by = $user->get('id');
} }
} }
if (isset($this->alias)) if (isset($this->alias))
{ {
// Verify that the alias is unique // Verify that the alias is unique
$table = JTable::getInstance('look', 'DemoTable'); $table = JTable::getInstance('look', 'DemoTable');
if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0))
{ {
$this->setError(JText::_('COM_DEMO_LOOK_ERROR_UNIQUE_ALIAS')); $this->setError(JText::_('COM_DEMO_LOOK_ERROR_UNIQUE_ALIAS'));
return false; return false;
} }
} }
if (isset($this->url)) if (isset($this->url))
{ {
// Convert IDN urls to punycode // Convert IDN urls to punycode
$this->url = JStringPunycode::urlToPunycode($this->url); $this->url = JStringPunycode::urlToPunycode($this->url);
} }
if (isset($this->website)) if (isset($this->website))
{ {
// Convert IDN urls to punycode // Convert IDN urls to punycode
$this->website = JStringPunycode::urlToPunycode($this->website); $this->website = JStringPunycode::urlToPunycode($this->website);
} }
return parent::store($updateNulls); return parent::store($updateNulls);
} }
/** /**
* Overloaded check method to ensure data integrity. * Overloaded check method to ensure data integrity.
* *
* @return boolean True on success. * @return boolean True on success.
*/ */
public function check() public function check()
{ {
if (isset($this->alias)) if (isset($this->alias))
{ {
// Generate a valid alias // Generate a valid alias
$this->generateAlias(); $this->generateAlias();
$table = JTable::getInstance('look', 'demoTable'); $table = JTable::getInstance('look', 'demoTable');
while ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) while ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0))
{ {
$this->alias = StringHelper::increment($this->alias, 'dash'); $this->alias = StringHelper::increment($this->alias, 'dash');
} }
} }
/* /*
* Clean up keywords -- eliminate extra spaces between phrases * Clean up keywords -- eliminate extra spaces between phrases
* and cr (\r) and lf (\n) characters from string. * and cr (\r) and lf (\n) characters from string.
* Only process if not empty. * Only process if not empty.
*/ */
if (!empty($this->metakey)) if (!empty($this->metakey))
{ {
// Array of characters to remove. // Array of characters to remove.
$bad_characters = array("\n", "\r", "\"", "<", ">"); $bad_characters = array("\n", "\r", "\"", "<", ">");
// Remove bad characters. // Remove bad characters.
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey); $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
// Create array using commas as delimiter. // Create array using commas as delimiter.
$keys = explode(',', $after_clean); $keys = explode(',', $after_clean);
$clean_keys = array(); $clean_keys = array();
foreach ($keys as $key) foreach ($keys as $key)
{ {
// Ignore blank keywords. // Ignore blank keywords.
if (trim($key)) if (trim($key))
{ {
$clean_keys[] = trim($key); $clean_keys[] = trim($key);
} }
} }
// Put array back together delimited by ", " // Put array back together delimited by ", "
$this->metakey = implode(", ", $clean_keys); $this->metakey = implode(", ", $clean_keys);
} }
// Clean up description -- eliminate quotes and <> brackets // Clean up description -- eliminate quotes and <> brackets
if (!empty($this->metadesc)) if (!empty($this->metadesc))
{ {
// Only process if not empty // Only process if not empty
$bad_characters = array("\"", "<", ">"); $bad_characters = array("\"", "<", ">");
$this->metadesc = StringHelper::str_ireplace($bad_characters, "", $this->metadesc); $this->metadesc = StringHelper::str_ireplace($bad_characters, "", $this->metadesc);
} }
// If we don't have any access rules set at this point just use an empty JAccessRules class // If we don't have any access rules set at this point just use an empty JAccessRules class
if (!$this->getRules()) if (!$this->getRules())
{ {
$rules = $this->getDefaultAssetValues('com_demo.look.'.$this->id); $rules = $this->getDefaultAssetValues('com_demo.look.'.$this->id);
$this->setRules($rules); $this->setRules($rules);
} }
// Set ordering // Set ordering
if ($this->published < 0) if ($this->published < 0)
{ {
// Set ordering to 0 if state is archived or trashed // Set ordering to 0 if state is archived or trashed
$this->ordering = 0; $this->ordering = 0;
} }
return true; return true;
} }
/** /**
* Gets the default asset values for a component. * Gets the default asset values for a component.
* *
* @param $string $component The component asset name to search for * @param $string $component The component asset name to search for
* *
* @return JAccessRules The JAccessRules object for the asset * @return JAccessRules The JAccessRules object for the asset
*/ */
protected function getDefaultAssetValues($component, $try = true) protected function getDefaultAssetValues($component, $try = true)
{ {
// Need to find the asset id by the name of the component. // Need to find the asset id by the name of the component.
$db = JFactory::getDbo(); $db = JFactory::getDbo();
$query = $db->getQuery(true) $query = $db->getQuery(true)
->select($db->quoteName('id')) ->select($db->quoteName('id'))
->from($db->quoteName('#__assets')) ->from($db->quoteName('#__assets'))
->where($db->quoteName('name') . ' = ' . $db->quote($component)); ->where($db->quoteName('name') . ' = ' . $db->quote($component));
$db->setQuery($query); $db->setQuery($query);
$db->execute(); $db->execute();
if ($db->loadRowList()) if ($db->loadRowList())
{ {
// asset already set so use saved rules // asset already set so use saved rules
$assetId = (int) $db->loadResult(); $assetId = (int) $db->loadResult();
return JAccess::getAssetRules($assetId); // (TODO) instead of keeping inherited Allowed it becomes Allowed. return JAccess::getAssetRules($assetId); // (TODO) instead of keeping inherited Allowed it becomes Allowed.
} }
// try again // try again
elseif ($try) elseif ($try)
{ {
$try = explode('.',$component); $try = explode('.',$component);
$result = $this->getDefaultAssetValues($try[0], false); $result = $this->getDefaultAssetValues($try[0], false);
if ($result instanceof JAccessRules) if ($result instanceof JAccessRules)
{ {
if (isset($try[1])) if (isset($try[1]))
{ {
$_result = (string) $result; $_result = (string) $result;
$_result = json_decode($_result); $_result = json_decode($_result);
foreach ($_result as $name => &$rule) foreach ($_result as $name => &$rule)
{ {
$v = explode('.', $name); $v = explode('.', $name);
if ($try[1] !== $v[0]) if ($try[1] !== $v[0])
{ {
// remove since it is not part of this view // remove since it is not part of this view
unset($_result->$name); unset($_result->$name);
} }
else else
{ {
// clear the value since we inherit // clear the value since we inherit
$rule = array(); $rule = array();
} }
} }
// check if there are any view values remaining // check if there are any view values remaining
if (count( (array) $_result)) if (count( (array) $_result))
{ {
$_result = json_encode($_result); $_result = json_encode($_result);
$_result = array($_result); $_result = array($_result);
// Instantiate and return the JAccessRules object for the asset rules. // Instantiate and return the JAccessRules object for the asset rules.
$rules = new JAccessRules; $rules = new JAccessRules;
$rules->mergeCollection($_result); $rules->mergeCollection($_result);
return $rules; return $rules;
} }
} }
return $result; return $result;
} }
} }
return JAccess::getAssetRules(0); return JAccess::getAssetRules(0);
} }
/** /**
* Method to compute the default name of the asset. * Method to compute the default name of the asset.
* The default name is in the form 'table_name.id' * The default name is in the form 'table_name.id'
* where id is the value of the primary key of the table. * where id is the value of the primary key of the table.
* *
* @return string * @return string
* @since 2.5 * @since 2.5
*/ */
protected function _getAssetName() protected function _getAssetName()
{ {
$k = $this->_tbl_key; $k = $this->_tbl_key;
return 'com_demo.look.'.(int) $this->$k; return 'com_demo.look.'.(int) $this->$k;
} }
/** /**
* Method to return the title to use for the asset table. * Method to return the title to use for the asset table.
* *
* @return string * @return string
* @since 2.5 * @since 2.5
*/ */
protected function _getAssetTitle() protected function _getAssetTitle()
{ {
if (isset($this->title)) if (isset($this->title))
{ {
return $this->title; return $this->title;
} }
return ''; return '';
} }
/** /**
* Get the parent asset id for the record * Get the parent asset id for the record
* *
* @return int * @return int
* @since 2.5 * @since 2.5
*/ */
protected function _getAssetParentId(JTable $table = NULL, $id = NULL) protected function _getAssetParentId(JTable $table = NULL, $id = NULL)
{ {
$asset = JTable::getInstance('Asset'); $asset = JTable::getInstance('Asset');
$asset->loadByName('com_demo'); $asset->loadByName('com_demo');
return $asset->id; return $asset->id;
} }
/** /**
@ -340,6 +340,6 @@ class DemoTableLook extends JTable
} }
return $this->alias; return $this->alias;
} }
} }