2023-07-26 09:09:42 +00:00
|
|
|
<?php
|
|
|
|
/*----------------------------------------------------------------------------------| io.vdm.dev |----/
|
|
|
|
Vast Development Method
|
|
|
|
/-------------------------------------------------------------------------------------------------------/
|
|
|
|
|
|
|
|
@package getBible.net
|
|
|
|
|
|
|
|
@created 3rd December, 2015
|
|
|
|
@author Llewellyn van der Merwe <https://getbible.net>
|
|
|
|
@git Get Bible <https://git.vdm.dev/getBible>
|
|
|
|
@github Get Bible <https://github.com/getBible>
|
|
|
|
@support Get Bible <https://git.vdm.dev/getBible/support>
|
|
|
|
@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');
|
|
|
|
|
2024-01-22 08:48:28 +00:00
|
|
|
use Joomla\CMS\Factory;
|
2023-07-26 09:09:42 +00:00
|
|
|
use Joomla\CMS\Table\Table;
|
2024-01-22 08:48:28 +00:00
|
|
|
use Joomla\CMS\Access\Access as AccessRules;
|
|
|
|
use Joomla\CMS\Access\Rules;
|
2023-07-26 09:09:42 +00:00
|
|
|
use Joomla\Registry\Registry;
|
|
|
|
use Joomla\String\StringHelper;
|
|
|
|
use Joomla\Utilities\ArrayHelper;
|
2024-01-22 08:48:28 +00:00
|
|
|
use Joomla\CMS\String\PunycodeHelper;
|
|
|
|
use Joomla\CMS\Table\Observer\Tags as TableObserverTags;
|
|
|
|
use Joomla\CMS\Table\Observer\ContentHistory as TableObserverContenthistory;
|
|
|
|
use Joomla\CMS\Application\ApplicationHelper;
|
2023-07-26 09:09:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Passwords Table class
|
|
|
|
*/
|
|
|
|
class GetbibleTablePassword extends Table
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Ensure the params and metadata in json encoded in the bind method
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 3.3
|
|
|
|
*/
|
|
|
|
protected $_jsonEncode = array('params', 'metadata');
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param object Database connector object
|
|
|
|
*/
|
2024-01-22 08:48:28 +00:00
|
|
|
function __construct(&$db)
|
2023-07-26 09:09:42 +00:00
|
|
|
{
|
|
|
|
parent::__construct('#__getbible_password', 'id', $db);
|
2024-01-22 08:48:28 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
public function bind($array, $ignore = '')
|
|
|
|
{
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
if (isset($array['params']) && is_array($array['params']))
|
|
|
|
{
|
2024-01-22 08:48:28 +00:00
|
|
|
$registry = new Registry;
|
2023-07-26 09:09:42 +00:00
|
|
|
$registry->loadArray($array['params']);
|
|
|
|
$array['params'] = (string) $registry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($array['metadata']) && is_array($array['metadata']))
|
|
|
|
{
|
2024-01-22 08:48:28 +00:00
|
|
|
$registry = new Registry;
|
2023-07-26 09:09:42 +00:00
|
|
|
$registry->loadArray($array['metadata']);
|
|
|
|
$array['metadata'] = (string) $registry;
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
|
|
|
// Bind the rules.
|
2023-07-26 09:09:42 +00:00
|
|
|
if (isset($array['rules']) && is_array($array['rules']))
|
2024-01-22 08:48:28 +00:00
|
|
|
{
|
|
|
|
$rules = new AccessRules($array['rules']);
|
|
|
|
$this->setRules($rules);
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
return parent::bind($array, $ignore);
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
/**
|
|
|
|
* Overload the store method for the Password table.
|
|
|
|
*
|
2024-01-22 08:48:28 +00:00
|
|
|
* @param boolean Toggle whether null values should be updated.
|
2023-07-26 09:09:42 +00:00
|
|
|
* @return boolean True on success, false on failure.
|
|
|
|
* @since 1.6
|
|
|
|
*/
|
|
|
|
public function store($updateNulls = false)
|
|
|
|
{
|
2024-01-22 08:48:28 +00:00
|
|
|
$date = Factory::getDate();
|
|
|
|
$user = Factory::getUser();
|
2023-07-26 09:09:42 +00:00
|
|
|
|
|
|
|
if ($this->id)
|
|
|
|
{
|
|
|
|
// Existing item
|
2024-01-22 08:48:28 +00:00
|
|
|
$this->modified = $date->toSql();
|
|
|
|
$this->modified_by = $user->get('id');
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// New password. A password created and created_by field can be set by the user,
|
|
|
|
// so we don't touch either of these if they are set.
|
|
|
|
if (!(int) $this->created)
|
|
|
|
{
|
|
|
|
$this->created = $date->toSql();
|
|
|
|
}
|
|
|
|
if (empty($this->created_by))
|
|
|
|
{
|
|
|
|
$this->created_by = $user->get('id');
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
if (isset($this->alias))
|
|
|
|
{
|
|
|
|
// Verify that the alias is unique
|
2024-01-22 08:48:28 +00:00
|
|
|
$table = Table::getInstance('password', 'GetbibleTable');
|
2023-07-26 09:09:42 +00:00
|
|
|
|
|
|
|
if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0))
|
|
|
|
{
|
2024-01-22 08:48:28 +00:00
|
|
|
$this->setError(Text::_('COM_GETBIBLE_PASSWORD_ERROR_UNIQUE_ALIAS'));
|
|
|
|
|
|
|
|
if ($table->published === -2)
|
|
|
|
{
|
|
|
|
$this->setError(Text::_('COM_GETBIBLE_PASSWORD_ERROR_UNIQUE_ALIAS_TRASHED'));
|
|
|
|
}
|
2023-07-26 09:09:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
if (isset($this->url))
|
|
|
|
{
|
|
|
|
// Convert IDN urls to punycode
|
2024-01-22 08:48:28 +00:00
|
|
|
$this->url = PunycodeHelper::urlToPunycode($this->url);
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
if (isset($this->website))
|
|
|
|
{
|
|
|
|
// Convert IDN urls to punycode
|
2024-01-22 08:48:28 +00:00
|
|
|
$this->website = PunycodeHelper::urlToPunycode($this->website);
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return parent::store($updateNulls);
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
/**
|
|
|
|
* Overloaded check method to ensure data integrity.
|
|
|
|
*
|
|
|
|
* @return boolean True on success.
|
|
|
|
*/
|
|
|
|
public function check()
|
|
|
|
{
|
|
|
|
if (isset($this->alias))
|
|
|
|
{
|
|
|
|
// Generate a valid alias
|
|
|
|
$this->generateAlias();
|
2024-01-22 08:48:28 +00:00
|
|
|
|
|
|
|
$table = Table::getInstance('password', 'getbibleTable');
|
2023-07-26 09:09:42 +00:00
|
|
|
|
|
|
|
while ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0))
|
|
|
|
{
|
|
|
|
$this->alias = StringHelper::increment($this->alias, 'dash');
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
/*
|
|
|
|
* Clean up keywords -- eliminate extra spaces between phrases
|
|
|
|
* and cr (\r) and lf (\n) characters from string.
|
|
|
|
* Only process if not empty.
|
2024-01-22 08:48:28 +00:00
|
|
|
*/
|
2023-07-26 09:09:42 +00:00
|
|
|
if (!empty($this->metakey))
|
|
|
|
{
|
|
|
|
// Array of characters to remove.
|
|
|
|
$bad_characters = array("\n", "\r", "\"", "<", ">");
|
|
|
|
|
|
|
|
// Remove bad characters.
|
|
|
|
$after_clean = StringHelper::str_ireplace($bad_characters, "", $this->metakey);
|
|
|
|
|
|
|
|
// Create array using commas as delimiter.
|
|
|
|
$keys = explode(',', $after_clean);
|
2024-01-22 08:48:28 +00:00
|
|
|
$clean_keys = [];
|
2023-07-26 09:09:42 +00:00
|
|
|
|
|
|
|
foreach ($keys as $key)
|
|
|
|
{
|
|
|
|
// Ignore blank keywords.
|
|
|
|
if (trim($key))
|
|
|
|
{
|
|
|
|
$clean_keys[] = trim($key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put array back together delimited by ", "
|
|
|
|
$this->metakey = implode(", ", $clean_keys);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up description -- eliminate quotes and <> brackets
|
|
|
|
if (!empty($this->metadesc))
|
|
|
|
{
|
|
|
|
// Only process if not empty
|
|
|
|
$bad_characters = array("\"", "<", ">");
|
|
|
|
$this->metadesc = StringHelper::str_ireplace($bad_characters, "", $this->metadesc);
|
|
|
|
}
|
|
|
|
|
2024-01-22 08:48:28 +00:00
|
|
|
// If we don't have any access rules set at this point just use an empty AccessRules class
|
2023-07-26 09:09:42 +00:00
|
|
|
if (!$this->getRules())
|
|
|
|
{
|
|
|
|
$rules = $this->getDefaultAssetValues('com_getbible.password.'.$this->id);
|
|
|
|
$this->setRules($rules);
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
|
2023-07-26 09:09:42 +00:00
|
|
|
// Set ordering
|
|
|
|
if ($this->published < 0)
|
|
|
|
{
|
|
|
|
// Set ordering to 0 if state is archived or trashed
|
|
|
|
$this->ordering = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the default asset values for a component.
|
|
|
|
*
|
|
|
|
* @param $string $component The component asset name to search for
|
|
|
|
*
|
2024-01-22 08:48:28 +00:00
|
|
|
* @return AccessRules The AccessRules object for the asset
|
2023-07-26 09:09:42 +00:00
|
|
|
*/
|
|
|
|
protected function getDefaultAssetValues($component, $try = true)
|
|
|
|
{
|
|
|
|
// Need to find the asset id by the name of the component.
|
2024-01-22 08:48:28 +00:00
|
|
|
$db = Factory::getDbo();
|
2023-07-26 09:09:42 +00:00
|
|
|
$query = $db->getQuery(true)
|
|
|
|
->select($db->quoteName('id'))
|
|
|
|
->from($db->quoteName('#__assets'))
|
|
|
|
->where($db->quoteName('name') . ' = ' . $db->quote($component));
|
|
|
|
$db->setQuery($query);
|
|
|
|
$db->execute();
|
|
|
|
if ($db->loadRowList())
|
|
|
|
{
|
|
|
|
// asset already set so use saved rules
|
|
|
|
$assetId = (int) $db->loadResult();
|
2024-01-22 08:48:28 +00:00
|
|
|
return AccessRules::getAssetRules($assetId); // (TODO) instead of keeping inherited Allowed it becomes Allowed.
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
// try again
|
|
|
|
elseif ($try)
|
|
|
|
{
|
|
|
|
$try = explode('.',$component);
|
|
|
|
$result = $this->getDefaultAssetValues($try[0], false);
|
2024-01-22 08:48:28 +00:00
|
|
|
if ($result instanceof AccessRules)
|
2023-07-26 09:09:42 +00:00
|
|
|
{
|
|
|
|
if (isset($try[1]))
|
|
|
|
{
|
|
|
|
$_result = (string) $result;
|
|
|
|
$_result = json_decode($_result);
|
|
|
|
foreach ($_result as $name => &$rule)
|
|
|
|
{
|
|
|
|
$v = explode('.', $name);
|
|
|
|
if ($try[1] !== $v[0])
|
|
|
|
{
|
|
|
|
// remove since it is not part of this view
|
|
|
|
unset($_result->$name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// clear the value since we inherit
|
2024-01-22 08:48:28 +00:00
|
|
|
$rule = [];
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// check if there are any view values remaining
|
|
|
|
if (count( (array) $_result))
|
|
|
|
{
|
|
|
|
$_result = json_encode($_result);
|
|
|
|
$_result = array($_result);
|
2024-01-22 08:48:28 +00:00
|
|
|
// Instantiate and return the AccessRules object for the asset rules.
|
|
|
|
$rules = new AccessRules;
|
2023-07-26 09:09:42 +00:00
|
|
|
$rules->mergeCollection($_result);
|
|
|
|
|
|
|
|
return $rules;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
2024-01-22 08:48:28 +00:00
|
|
|
return AccessRules::getAssetRules(0);
|
2023-07-26 09:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to compute the default name of the asset.
|
|
|
|
* The default name is in the form 'table_name.id'
|
|
|
|
* where id is the value of the primary key of the table.
|
|
|
|
*
|
2024-01-22 08:48:28 +00:00
|
|
|
* @return string
|
|
|
|
* @since 2.5
|
2023-07-26 09:09:42 +00:00
|
|
|
*/
|
|
|
|
protected function _getAssetName()
|
|
|
|
{
|
|
|
|
$k = $this->_tbl_key;
|
|
|
|
return 'com_getbible.password.'.(int) $this->$k;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to return the title to use for the asset table.
|
|
|
|
*
|
2024-01-22 08:48:28 +00:00
|
|
|
* @return string
|
|
|
|
* @since 2.5
|
2023-07-26 09:09:42 +00:00
|
|
|
*/
|
|
|
|
protected function _getAssetTitle()
|
|
|
|
{
|
|
|
|
if (isset($this->title))
|
|
|
|
{
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the parent asset id for the record
|
|
|
|
*
|
2024-01-22 08:48:28 +00:00
|
|
|
* @return int
|
|
|
|
* @since 2.5
|
2023-07-26 09:09:42 +00:00
|
|
|
*/
|
2024-01-22 08:48:28 +00:00
|
|
|
protected function _getAssetParentId(?Table $table = null, $id = null)
|
2023-07-26 09:09:42 +00:00
|
|
|
{
|
2024-01-22 08:48:28 +00:00
|
|
|
$asset = Table::getInstance('Asset');
|
2023-07-26 09:09:42 +00:00
|
|
|
$asset->loadByName('com_getbible');
|
|
|
|
|
|
|
|
return $asset->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This view does not actually have an alias
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function generateAlias()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|