You've already forked joomla_test
first commit
This commit is contained in:
125
libraries/joomla/table/asset.php
Normal file
125
libraries/joomla/table/asset.php
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Table class supporting modified pre-order tree traversal behavior.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @link http://docs.joomla.org/JTableAsset
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableAsset extends JTableNested
|
||||
{
|
||||
/**
|
||||
* The primary key of the asset.
|
||||
*
|
||||
* @var integer
|
||||
* @since 11.1
|
||||
*/
|
||||
public $id = null;
|
||||
|
||||
/**
|
||||
* The unique name of the asset.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
public $name = null;
|
||||
|
||||
/**
|
||||
* The human readable title of the asset.
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
public $title = null;
|
||||
|
||||
/**
|
||||
* The rules for the asset stored in a JSON string
|
||||
*
|
||||
* @var string
|
||||
* @since 11.1
|
||||
*/
|
||||
public $rules = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__assets', 'id', $db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load an asset by its name.
|
||||
*
|
||||
* @param string $name The name of the asset.
|
||||
*
|
||||
* @return integer
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function loadByName($name)
|
||||
{
|
||||
$query = $this->_db->getQuery(true)
|
||||
->select($this->_db->quoteName('id'))
|
||||
->from($this->_db->quoteName('#__assets'))
|
||||
->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($name));
|
||||
$this->_db->setQuery($query);
|
||||
$assetId = (int) $this->_db->loadResult();
|
||||
if (empty($assetId))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->load($assetId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the nested set data is valid.
|
||||
*
|
||||
* @return boolean True if the instance is sane and able to be stored in the database.
|
||||
*
|
||||
* @link http://docs.joomla.org/JTable/check
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$this->parent_id = (int) $this->parent_id;
|
||||
|
||||
// JTableNested does not allow parent_id = 0, override this.
|
||||
if ($this->parent_id > 0)
|
||||
{
|
||||
// Get the JDatabaseQuery object
|
||||
$query = $this->_db->getQuery(true)
|
||||
->select('COUNT(id)')
|
||||
->from($this->_db->quoteName($this->_tbl))
|
||||
->where($this->_db->quoteName('id') . ' = ' . $this->parent_id);
|
||||
$this->_db->setQuery($query);
|
||||
if ($this->_db->loadResult())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->setError('Invalid Parent ID');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
187
libraries/joomla/table/extension.php
Normal file
187
libraries/joomla/table/extension.php
Normal file
@ -0,0 +1,187 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Extension table
|
||||
* Replaces plugins table
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableExtension extends JTable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__extensions', 'extension_id', $db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded check function
|
||||
*
|
||||
* @return boolean True if the object is ok
|
||||
*
|
||||
* @see JTable::check
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Check for valid name
|
||||
if (trim($this->name) == '' || trim($this->element) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_EXTENSION'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded bind function
|
||||
*
|
||||
* @param array $array Named array
|
||||
* @param mixed $ignore An optional array or space separated list of properties
|
||||
* to ignore while binding.
|
||||
*
|
||||
* @return mixed Null if operation was satisfactory, otherwise returns an error
|
||||
*
|
||||
* @see JTable::bind
|
||||
* @since 11.1
|
||||
*/
|
||||
public function bind($array, $ignore = '')
|
||||
{
|
||||
if (isset($array['params']) && is_array($array['params']))
|
||||
{
|
||||
$registry = new JRegistry;
|
||||
$registry->loadArray($array['params']);
|
||||
$array['params'] = (string) $registry;
|
||||
}
|
||||
|
||||
if (isset($array['control']) && is_array($array['control']))
|
||||
{
|
||||
$registry = new JRegistry;
|
||||
$registry->loadArray($array['control']);
|
||||
$array['control'] = (string) $registry;
|
||||
}
|
||||
|
||||
return parent::bind($array, $ignore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create and execute a SELECT WHERE query.
|
||||
*
|
||||
* @param array $options Array of options
|
||||
*
|
||||
* @return string The database query result
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function find($options = array())
|
||||
{
|
||||
// Get the JDatabaseQuery object
|
||||
$query = $this->_db->getQuery(true);
|
||||
|
||||
foreach ($options as $col => $val)
|
||||
{
|
||||
$query->where($col . ' = ' . $this->_db->quote($val));
|
||||
}
|
||||
|
||||
$query->select($this->_db->quoteName('extension_id'))
|
||||
->from($this->_db->quoteName('#__extensions'));
|
||||
$this->_db->setQuery($query);
|
||||
return $this->_db->loadResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the publishing state for a row or list of rows in the database
|
||||
* table. The method respects checked out rows by other users and will attempt
|
||||
* to checkin rows that it can after adjustments are made.
|
||||
*
|
||||
* @param mixed $pks An optional array of primary key values to update. If not
|
||||
* set the instance property value is used.
|
||||
* @param integer $state The publishing state. eg. [0 = unpublished, 1 = published]
|
||||
* @param integer $userId The user id of the user performing the operation.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function publish($pks = null, $state = 1, $userId = 0)
|
||||
{
|
||||
$k = $this->_tbl_key;
|
||||
|
||||
// Sanitize input.
|
||||
JArrayHelper::toInteger($pks);
|
||||
$userId = (int) $userId;
|
||||
$state = (int) $state;
|
||||
|
||||
// If there are no primary keys set check to see if the instance key is set.
|
||||
if (empty($pks))
|
||||
{
|
||||
if ($this->$k)
|
||||
{
|
||||
$pks = array($this->$k);
|
||||
}
|
||||
// Nothing to set publishing state on, return false.
|
||||
else
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Build the WHERE clause for the primary keys.
|
||||
$where = $k . '=' . implode(' OR ' . $k . '=', $pks);
|
||||
|
||||
// Determine if there is checkin support for the table.
|
||||
if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time'))
|
||||
{
|
||||
$checkin = '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$checkin = ' AND (checked_out = 0 OR checked_out = ' . (int) $userId . ')';
|
||||
}
|
||||
|
||||
// Update the publishing state for rows with the given primary keys.
|
||||
$query = $this->_db->getQuery(true)
|
||||
->update($this->_db->quoteName($this->_tbl))
|
||||
->set($this->_db->quoteName('enabled') . ' = ' . (int) $state)
|
||||
->where('(' . $where . ')' . $checkin);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
|
||||
// If checkin is supported and all rows were adjusted, check them in.
|
||||
if ($checkin && (count($pks) == $this->_db->getAffectedRows()))
|
||||
{
|
||||
// Checkin the rows.
|
||||
foreach ($pks as $pk)
|
||||
{
|
||||
$this->checkin($pk);
|
||||
}
|
||||
}
|
||||
|
||||
// If the JTable instance value is in the list of primary keys that were set, set the instance.
|
||||
if (in_array($this->$k, $pks))
|
||||
{
|
||||
$this->enabled = $state;
|
||||
}
|
||||
|
||||
$this->setError('');
|
||||
return true;
|
||||
}
|
||||
}
|
1
libraries/joomla/table/index.html
Normal file
1
libraries/joomla/table/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
85
libraries/joomla/table/language.php
Normal file
85
libraries/joomla/table/language.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Languages table.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableLanguage extends JTable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__languages', 'lang_id', $db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded check method to ensure data integrity
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
if (trim($this->title) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_NO_TITLE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides JTable::store to check unique fields.
|
||||
*
|
||||
* @param boolean $updateNulls True to update fields even if they are null.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @since 11.4
|
||||
*/
|
||||
public function store($updateNulls = false)
|
||||
{
|
||||
// Verify that the sef field is unique
|
||||
$table = JTable::getInstance('Language', 'JTable');
|
||||
if ($table->load(array('sef' => $this->sef)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_SEF'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that the image field is unique
|
||||
if ($table->load(array('image' => $this->image)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_IMAGE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Verify that the language code is unique
|
||||
if ($table->load(array('lang_code' => $this->lang_code)) && ($table->lang_id != $this->lang_id || $this->lang_id == 0))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_LANGUAGE_UNIQUE_LANG_CODE'));
|
||||
return false;
|
||||
}
|
||||
return parent::store($updateNulls);
|
||||
}
|
||||
}
|
1637
libraries/joomla/table/nested.php
Normal file
1637
libraries/joomla/table/nested.php
Normal file
File diff suppressed because it is too large
Load Diff
112
libraries/joomla/table/observer.php
Normal file
112
libraries/joomla/table/observer.php
Normal file
@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Table class supporting modified pre-order tree traversal behavior.
|
||||
*
|
||||
* @package Joomla
|
||||
* @subpackage Table
|
||||
* @link http://docs.joomla.org/JTableObserver
|
||||
* @since 3.1.2
|
||||
*/
|
||||
abstract class JTableObserver implements JObserverInterface
|
||||
{
|
||||
/**
|
||||
* The observed table
|
||||
*
|
||||
* @var JTable
|
||||
*/
|
||||
protected $table;
|
||||
|
||||
/**
|
||||
* Constructor: Associates to $table $this observer
|
||||
*
|
||||
* @param JTable $table Table to be observed
|
||||
*/
|
||||
public function __construct(JTable $table)
|
||||
{
|
||||
$table->attachObserver($this);
|
||||
$this->table = $table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-processor for $table->load($keys, $reset)
|
||||
*
|
||||
* @param mixed $keys An optional primary key value to load the row by, or an array of fields to match. If not
|
||||
* set the instance property value is used.
|
||||
* @param boolean $reset True to reset the default values before loading the new row.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeLoad($keys, $reset)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-processor for $table->load($keys, $reset)
|
||||
*
|
||||
* @param boolean &$result The result of the load
|
||||
* @param array $row The loaded (and already binded to $this->table) row of the database table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterLoad(&$result, $row)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-processor for $table->store($updateNulls)
|
||||
*
|
||||
* @param boolean $updateNulls The result of the load
|
||||
* @param string $tableKey The key of the table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeStore($updateNulls, $tableKey)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-processor for $table->store($updateNulls)
|
||||
*
|
||||
* @param boolean &$result The result of the store
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterStore(&$result)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-processor for $table->delete($pk)
|
||||
*
|
||||
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
|
||||
* @param string $tableKey The normal key of the table
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function onBeforeDelete($pk, $tableKey)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-processor for $table->delete($pk)
|
||||
*
|
||||
* @param mixed $pk The deleted primary key value.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterDelete($pk)
|
||||
{
|
||||
}
|
||||
}
|
1
libraries/joomla/table/observer/index.html
Normal file
1
libraries/joomla/table/observer/index.html
Normal file
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><title></title>
|
166
libraries/joomla/table/observer/tags.php
Normal file
166
libraries/joomla/table/observer/tags.php
Normal file
@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Table class supporting modified pre-order tree traversal behavior.
|
||||
*
|
||||
* @package Joomla
|
||||
* @subpackage Table
|
||||
* @link http://docs.joomla.org/JTableObserver
|
||||
* @since 3.1.2
|
||||
*/
|
||||
class JTableObserverTags extends JTableObserver
|
||||
{
|
||||
/**
|
||||
* Helper object for storing and deleting tag information associated with this table observer
|
||||
*
|
||||
* @var JHelperTags
|
||||
*/
|
||||
protected $tagsHelper;
|
||||
|
||||
/**
|
||||
* The pattern for this tag's TypeAlias
|
||||
* @var string
|
||||
*/
|
||||
protected $typeAliasPattern = null;
|
||||
|
||||
/**
|
||||
* Override for postStoreProcess param newTags, Set by setNewTagsToAdd, used by onAfterStore
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $newTags = array();
|
||||
|
||||
/**
|
||||
* Override for postStoreProcess param replaceTags. Set by setNewTagsToAdd, used by onAfterStore
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $replaceTags = true;
|
||||
|
||||
/**
|
||||
* Not public, so marking private and deprecated, but needed internally in parseTypeAlias for
|
||||
* PHP < 5.4.0 as it's not passing context $this to closure function.
|
||||
*
|
||||
* @var JTableObserverTags
|
||||
* @deprecated Never use this
|
||||
* @private
|
||||
*/
|
||||
public static $_myTableForPregreplaceOnly;
|
||||
|
||||
/**
|
||||
* Creates the associated observer instance and attaches it to the $observableObject
|
||||
* Creates the associated tags helper class instance
|
||||
* $typeAlias can be of the form "{variableName}.type", automatically replacing {variableName} with table-instance variables variableName
|
||||
*
|
||||
* @param JObservableInterface|JTable $observableObject The subject object to be observed
|
||||
* @param array $params ( 'typeAlias' => $typeAlias )
|
||||
*
|
||||
* @return JObserverInterface|JTableObserverTags
|
||||
*/
|
||||
public static function createObserver(JObservableInterface $observableObject, $params = array())
|
||||
{
|
||||
$typeAlias = $params['typeAlias'];
|
||||
|
||||
$observer = new self($observableObject);
|
||||
|
||||
$observer->tagsHelper = new JHelperTags;
|
||||
$observer->typeAliasPattern = $typeAlias;
|
||||
|
||||
return $observer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-processor for $table->store($updateNulls)
|
||||
*
|
||||
* @param boolean $updateNulls The result of the load
|
||||
* @param string $tableKey The key of the table
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onBeforeStore($updateNulls, $tableKey)
|
||||
{
|
||||
$this->parseTypeAlias();
|
||||
$this->tagsHelper->preStoreProcess($this->table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post-processor for $table->store($updateNulls)
|
||||
* You can change optional params newTags and replaceTags of tagsHelper with method setNewTagsToAdd
|
||||
*
|
||||
* @param boolean &$result The result of the load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterStore(&$result)
|
||||
{
|
||||
if ($result)
|
||||
{
|
||||
$result = $this->tagsHelper->postStoreProcess($this->table);
|
||||
|
||||
// Restore default values for the optional params:
|
||||
$this->newTags = array();
|
||||
$this->replaceTags = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-processor for $table->delete($pk)
|
||||
*
|
||||
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
|
||||
* @param string $tableKey The normal key of the table
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
public function onBeforeDelete($pk, $tableKey)
|
||||
{
|
||||
$this->parseTypeAlias();
|
||||
$this->tagsHelper->deleteTagData($this->table, $pk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new tags to be added/replaced to the table row
|
||||
*
|
||||
* @param array $newTags New tags to be added or replaced
|
||||
* @param boolean $replaceTags Replace tags (true) or add them (false)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function setNewTags($newTags, $replaceTags)
|
||||
{
|
||||
$this->parseTypeAlias();
|
||||
|
||||
return $this->tagsHelper->postStoreProcess($this->table, $newTags, $replaceTags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal method
|
||||
* Parses a TypeAlias of the form "{variableName}.type", replacing {variableName} with table-instance variables variableName
|
||||
* Storing result into $this->tagsHelper->typeAlias
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function parseTypeAlias()
|
||||
{
|
||||
// Needed for PHP < 5.4.0 as it's not passing context $this to closure function
|
||||
static::$_myTableForPregreplaceOnly = $this->table;
|
||||
|
||||
$this->tagsHelper->typeAlias = preg_replace_callback('/{([^}]+)}/',
|
||||
function($matches)
|
||||
{
|
||||
return JTableObserverTags::$_myTableForPregreplaceOnly->{$matches[1]};
|
||||
},
|
||||
$this->typeAliasPattern
|
||||
);
|
||||
}
|
||||
}
|
1345
libraries/joomla/table/table.php
Normal file
1345
libraries/joomla/table/table.php
Normal file
File diff suppressed because it is too large
Load Diff
107
libraries/joomla/table/update.php
Normal file
107
libraries/joomla/table/update.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Update table
|
||||
* Stores updates temporarily
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableUpdate extends JTable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__updates', 'update_id', $db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded check function
|
||||
*
|
||||
* @return boolean True if the object is ok
|
||||
*
|
||||
* @see JTable::check
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Check for valid name
|
||||
if (trim($this->name) == '' || trim($this->element) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_EXTENSION'));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloaded bind function
|
||||
*
|
||||
* @param array $array Named array
|
||||
* @param mixed $ignore An optional array or space separated list of properties
|
||||
* to ignore while binding.
|
||||
*
|
||||
* @return mixed Null if operation was satisfactory, otherwise returns an error
|
||||
*
|
||||
* @see JTable::bind
|
||||
* @since 11.1
|
||||
*/
|
||||
public function bind($array, $ignore = '')
|
||||
{
|
||||
if (isset($array['params']) && is_array($array['params']))
|
||||
{
|
||||
$registry = new JRegistry;
|
||||
$registry->loadArray($array['params']);
|
||||
$array['params'] = (string) $registry;
|
||||
}
|
||||
|
||||
if (isset($array['control']) && is_array($array['control']))
|
||||
{
|
||||
$registry = new JRegistry;
|
||||
$registry->loadArray($array['control']);
|
||||
$array['control'] = (string) $registry;
|
||||
}
|
||||
|
||||
return parent::bind($array, $ignore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create and execute a SELECT WHERE query.
|
||||
*
|
||||
* @param array $options Array of options
|
||||
*
|
||||
* @return string Results of query
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function find($options = array())
|
||||
{
|
||||
$where = array();
|
||||
foreach ($options as $col => $val)
|
||||
{
|
||||
$where[] = $col . ' = ' . $this->_db->quote($val);
|
||||
}
|
||||
$query = $this->_db->getQuery(true)
|
||||
->select($this->_db->quoteName($this->_tbl_key))
|
||||
->from($this->_db->quoteName($this->_tbl))
|
||||
->where(implode(' AND ', $where));
|
||||
$this->_db->setQuery($query);
|
||||
return $this->_db->loadResult();
|
||||
}
|
||||
}
|
424
libraries/joomla/table/user.php
Normal file
424
libraries/joomla/table/user.php
Normal file
@ -0,0 +1,424 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Users table
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableUser extends JTable
|
||||
{
|
||||
/**
|
||||
* Associative array of group ids => group ids for the user
|
||||
*
|
||||
* @var array
|
||||
* @since 11.1
|
||||
*/
|
||||
public $groups;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__users', 'id', $db);
|
||||
|
||||
// Initialise.
|
||||
$this->id = 0;
|
||||
$this->sendEmail = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to load a user, user groups, and any other necessary data
|
||||
* from the database so that it can be bound to the user object.
|
||||
*
|
||||
* @param integer $userId An optional user id.
|
||||
* @param boolean $reset False if row not found or on error
|
||||
* (internal error state set in that case).
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function load($userId = null, $reset = true)
|
||||
{
|
||||
// Get the id to load.
|
||||
if ($userId !== null)
|
||||
{
|
||||
$this->id = $userId;
|
||||
}
|
||||
else
|
||||
{
|
||||
$userId = $this->id;
|
||||
}
|
||||
|
||||
// Check for a valid id to load.
|
||||
if ($userId === null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset the table.
|
||||
$this->reset();
|
||||
|
||||
// Load the user data.
|
||||
$query = $this->_db->getQuery(true)
|
||||
->select('*')
|
||||
->from($this->_db->quoteName('#__users'))
|
||||
->where($this->_db->quoteName('id') . ' = ' . (int) $userId);
|
||||
$this->_db->setQuery($query);
|
||||
$data = (array) $this->_db->loadAssoc();
|
||||
|
||||
if (!count($data))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert e-mail from punycode
|
||||
$data['email'] = JStringPunycode::emailToUTF8($data['email']);
|
||||
|
||||
// Bind the data to the table.
|
||||
$return = $this->bind($data);
|
||||
|
||||
if ($return !== false)
|
||||
{
|
||||
// Load the user groups.
|
||||
$query->clear()
|
||||
->select($this->_db->quoteName('g.id'))
|
||||
->select($this->_db->quoteName('g.title'))
|
||||
->from($this->_db->quoteName('#__usergroups') . ' AS g')
|
||||
->join('INNER', $this->_db->quoteName('#__user_usergroup_map') . ' AS m ON m.group_id = g.id')
|
||||
->where($this->_db->quoteName('m.user_id') . ' = ' . (int) $userId);
|
||||
$this->_db->setQuery($query);
|
||||
|
||||
// Add the groups to the user data.
|
||||
$this->groups = $this->_db->loadAssocList('id', 'id');
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to bind the user, user groups, and any other necessary data.
|
||||
*
|
||||
* @param array $array The data to bind.
|
||||
* @param mixed $ignore An array or space separated list of fields to ignore.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function bind($array, $ignore = '')
|
||||
{
|
||||
if (array_key_exists('params', $array) && is_array($array['params']))
|
||||
{
|
||||
$registry = new JRegistry;
|
||||
$registry->loadArray($array['params']);
|
||||
$array['params'] = (string) $registry;
|
||||
}
|
||||
|
||||
// Attempt to bind the data.
|
||||
$return = parent::bind($array, $ignore);
|
||||
|
||||
// Load the real group data based on the bound ids.
|
||||
if ($return && !empty($this->groups))
|
||||
{
|
||||
// Set the group ids.
|
||||
JArrayHelper::toInteger($this->groups);
|
||||
|
||||
// Get the titles for the user groups.
|
||||
$query = $this->_db->getQuery(true)
|
||||
->select($this->_db->quoteName('id'))
|
||||
->select($this->_db->quoteName('title'))
|
||||
->from($this->_db->quoteName('#__usergroups'))
|
||||
->where($this->_db->quoteName('id') . ' = ' . implode(' OR ' . $this->_db->quoteName('id') . ' = ', $this->groups));
|
||||
$this->_db->setQuery($query);
|
||||
|
||||
// Set the titles for the user groups.
|
||||
$this->groups = $this->_db->loadAssocList('id', 'id');
|
||||
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation and filtering
|
||||
*
|
||||
* @return boolean True if satisfactory
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Set user id to null istead of 0, if needed
|
||||
if ($this->id === 0)
|
||||
{
|
||||
$this->id = null;
|
||||
}
|
||||
|
||||
// Validate user information
|
||||
if (trim($this->name) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_YOUR_NAME'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trim($this->username) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_PLEASE_ENTER_A_USER_NAME'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (preg_match("#[<>\"'%;()&]#i", $this->username) || strlen(utf8_decode($this->username)) < 2)
|
||||
{
|
||||
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_VALID_AZ09', 2));
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((trim($this->email) == "") || !JMailHelper::isEmailAddress($this->email))
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_VALID_MAIL'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Convert e-mail to punycode for storage
|
||||
$this->email = JStringPunycode::emailToPunycode($this->email);
|
||||
|
||||
// Set the registration timestamp
|
||||
if (empty($this->registerDate) || $this->registerDate == $this->_db->getNullDate())
|
||||
{
|
||||
$this->registerDate = JFactory::getDate()->toSql();
|
||||
}
|
||||
|
||||
// Set the lastvisitDate timestamp
|
||||
if (empty($this->lastvisitDate))
|
||||
{
|
||||
$this->lastvisitDate = $this->_db->getNullDate();
|
||||
}
|
||||
|
||||
// Check for existing username
|
||||
$query = $this->_db->getQuery(true)
|
||||
->select($this->_db->quoteName('id'))
|
||||
->from($this->_db->quoteName('#__users'))
|
||||
->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($this->username))
|
||||
->where($this->_db->quoteName('id') . ' != ' . (int) $this->id);
|
||||
$this->_db->setQuery($query);
|
||||
|
||||
$xid = (int) $this->_db->loadResult();
|
||||
if ($xid && $xid != (int) $this->id)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_USERNAME_INUSE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for existing email
|
||||
$query->clear()
|
||||
->select($this->_db->quoteName('id'))
|
||||
->from($this->_db->quoteName('#__users'))
|
||||
->where($this->_db->quoteName('email') . ' = ' . $this->_db->quote($this->email))
|
||||
->where($this->_db->quoteName('id') . ' != ' . (int) $this->id);
|
||||
$this->_db->setQuery($query);
|
||||
$xid = (int) $this->_db->loadResult();
|
||||
if ($xid && $xid != (int) $this->id)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_EMAIL_INUSE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for root_user != username
|
||||
$config = JFactory::getConfig();
|
||||
$rootUser = $config->get('root_user');
|
||||
if (!is_numeric($rootUser))
|
||||
{
|
||||
$query->clear()
|
||||
->select($this->_db->quoteName('id'))
|
||||
->from($this->_db->quoteName('#__users'))
|
||||
->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($rootUser));
|
||||
$this->_db->setQuery($query);
|
||||
$xid = (int) $this->_db->loadResult();
|
||||
if ($rootUser == $this->username && (!$xid || $xid && $xid != (int) $this->id)
|
||||
|| $xid && $xid == (int) $this->id && $rootUser != $this->username)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_USERNAME_CANNOT_CHANGE'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to store a row in the database from the JTable instance properties.
|
||||
* If a primary key value is set the row with that primary key value will be
|
||||
* updated with the instance property values. If no primary key value is set
|
||||
* a new row will be inserted into the database with the properties from the
|
||||
* JTable instance.
|
||||
*
|
||||
* @param boolean $updateNulls True to update fields even if they are null.
|
||||
*
|
||||
* @return boolean True on success.
|
||||
*
|
||||
* @link http://docs.joomla.org/JTable/store
|
||||
* @since 11.1
|
||||
*/
|
||||
public function store($updateNulls = false)
|
||||
{
|
||||
// Get the table key and key value.
|
||||
$k = $this->_tbl_key;
|
||||
$key = $this->$k;
|
||||
|
||||
// TODO: This is a dumb way to handle the groups.
|
||||
// Store groups locally so as to not update directly.
|
||||
$groups = $this->groups;
|
||||
unset($this->groups);
|
||||
|
||||
// Insert or update the object based on presence of a key value.
|
||||
if ($key)
|
||||
{
|
||||
// Already have a table key, update the row.
|
||||
$this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't have a table key, insert the row.
|
||||
$this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
|
||||
}
|
||||
|
||||
// Reset groups to the local object.
|
||||
$this->groups = $groups;
|
||||
unset($groups);
|
||||
|
||||
// Store the group data if the user data was saved.
|
||||
if (is_array($this->groups) && count($this->groups))
|
||||
{
|
||||
// Delete the old user group maps.
|
||||
$query = $this->_db->getQuery(true)
|
||||
->delete($this->_db->quoteName('#__user_usergroup_map'))
|
||||
->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->id);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
|
||||
// Set the new user group maps.
|
||||
$query->clear()
|
||||
->insert($this->_db->quoteName('#__user_usergroup_map'))
|
||||
->columns(array($this->_db->quoteName('user_id'), $this->_db->quoteName('group_id')));
|
||||
|
||||
// Have to break this up into individual queries for cross-database support.
|
||||
foreach ($this->groups as $group)
|
||||
{
|
||||
$query->clear('values')
|
||||
->values($this->id . ', ' . $group);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delete a user, user groups, and any other necessary data from the database.
|
||||
*
|
||||
* @param integer $userId An optional user id.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function delete($userId = null)
|
||||
{
|
||||
// Set the primary key to delete.
|
||||
$k = $this->_tbl_key;
|
||||
if ($userId)
|
||||
{
|
||||
$this->$k = (int) $userId;
|
||||
}
|
||||
|
||||
// Delete the user.
|
||||
$query = $this->_db->getQuery(true)
|
||||
->delete($this->_db->quoteName($this->_tbl))
|
||||
->where($this->_db->quoteName($this->_tbl_key) . ' = ' . (int) $this->$k);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
|
||||
// Delete the user group maps.
|
||||
$query->clear()
|
||||
->delete($this->_db->quoteName('#__user_usergroup_map'))
|
||||
->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->$k);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
|
||||
/*
|
||||
* Clean Up Related Data.
|
||||
*/
|
||||
|
||||
$query->clear()
|
||||
->delete($this->_db->quoteName('#__messages_cfg'))
|
||||
->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->$k);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
|
||||
$query->clear()
|
||||
->delete($this->_db->quoteName('#__messages'))
|
||||
->where($this->_db->quoteName('user_id_to') . ' = ' . (int) $this->$k);
|
||||
$this->_db->setQuery($query);
|
||||
$this->_db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates last visit time of user
|
||||
*
|
||||
* @param integer $timeStamp The timestamp, defaults to 'now'.
|
||||
* @param integer $userId The user id (optional).
|
||||
*
|
||||
* @return boolean False if an error occurs
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function setLastVisit($timeStamp = null, $userId = null)
|
||||
{
|
||||
// Check for User ID
|
||||
if (is_null($userId))
|
||||
{
|
||||
if (isset($this))
|
||||
{
|
||||
$userId = $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
jexit('No userid in setLastVisit');
|
||||
}
|
||||
}
|
||||
|
||||
// If no timestamp value is passed to function, than current time is used.
|
||||
$date = JFactory::getDate($timeStamp);
|
||||
|
||||
// Update the database row for the user.
|
||||
$db = $this->_db;
|
||||
$query = $db->getQuery(true)
|
||||
->update($db->quoteName($this->_tbl))
|
||||
->set($db->quoteName('lastvisitDate') . '=' . $db->quote($date->toSql()))
|
||||
->where($db->quoteName('id') . '=' . (int) $userId);
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
241
libraries/joomla/table/usergroup.php
Normal file
241
libraries/joomla/table/usergroup.php
Normal file
@ -0,0 +1,241 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Usergroup table class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableUsergroup extends JTable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__usergroups', 'id', $db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check the current record to save
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Validate the title.
|
||||
if ((trim($this->title)) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_USERGROUP_TITLE'));
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for a duplicate parent_id, title.
|
||||
// There is a unique index on the (parent_id, title) field in the table.
|
||||
$db = $this->_db;
|
||||
$query = $db->getQuery(true)
|
||||
->select('COUNT(title)')
|
||||
->from($this->_tbl)
|
||||
->where('title = ' . $db->quote(trim($this->title)))
|
||||
->where('parent_id = ' . (int) $this->parent_id)
|
||||
->where('id <> ' . (int) $this->id);
|
||||
$db->setQuery($query);
|
||||
|
||||
if ($db->loadResult() > 0)
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_USERGROUP_TITLE_EXISTS'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to recursively rebuild the nested set tree.
|
||||
*
|
||||
* @param integer $parent_id The root of the tree to rebuild.
|
||||
* @param integer $left The left id to start with in building the tree.
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function rebuild($parent_id = 0, $left = 0)
|
||||
{
|
||||
// Get the database object
|
||||
$db = $this->_db;
|
||||
|
||||
// Get all children of this node
|
||||
$db->setQuery('SELECT id FROM ' . $this->_tbl . ' WHERE parent_id=' . (int) $parent_id . ' ORDER BY parent_id, title');
|
||||
$children = $db->loadColumn();
|
||||
|
||||
// The right value of this node is the left value + 1
|
||||
$right = $left + 1;
|
||||
|
||||
// Execute this function recursively over all children
|
||||
for ($i = 0, $n = count($children); $i < $n; $i++)
|
||||
{
|
||||
// $right is the current right value, which is incremented on recursion return
|
||||
$right = $this->rebuild($children[$i], $right);
|
||||
|
||||
// If there is an update failure, return false to break out of the recursion
|
||||
if ($right === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// We've got the left value, and now that we've processed
|
||||
// the children of this node we also know the right value
|
||||
$db->setQuery('UPDATE ' . $this->_tbl . ' SET lft=' . (int) $left . ', rgt=' . (int) $right . ' WHERE id=' . (int) $parent_id);
|
||||
|
||||
// If there is an update failure, return false to break out of the recursion
|
||||
if (!$db->execute())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return the right value of this node + 1
|
||||
return $right + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a new row if id is zero or updates an existing row in the database table
|
||||
*
|
||||
* @param boolean $updateNulls If false, null object variables are not updated
|
||||
*
|
||||
* @return boolean True if successful, false otherwise and an internal error message is set
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function store($updateNulls = false)
|
||||
{
|
||||
if ($result = parent::store($updateNulls))
|
||||
{
|
||||
// Rebuild the nested set tree.
|
||||
$this->rebuild();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this object and its dependencies
|
||||
*
|
||||
* @param integer $oid The primary key of the user group to delete.
|
||||
*
|
||||
* @return mixed Boolean or Exception.
|
||||
*
|
||||
* @since 11.1
|
||||
* @throws RuntimeException on database error.
|
||||
* @throws UnexpectedValueException on data error.
|
||||
*/
|
||||
public function delete($oid = null)
|
||||
{
|
||||
if ($oid)
|
||||
{
|
||||
$this->load($oid);
|
||||
}
|
||||
if ($this->id == 0)
|
||||
{
|
||||
throw new UnexpectedValueException('Global Category not found');
|
||||
}
|
||||
if ($this->parent_id == 0)
|
||||
{
|
||||
throw new UnexpectedValueException('Root categories cannot be deleted.');
|
||||
}
|
||||
if ($this->lft == 0 || $this->rgt == 0)
|
||||
{
|
||||
throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete usergroup.');
|
||||
}
|
||||
|
||||
$db = $this->_db;
|
||||
|
||||
// Select the usergroup ID and its children
|
||||
$query = $db->getQuery(true)
|
||||
->select($db->quoteName('c.id'))
|
||||
->from($db->quoteName($this->_tbl) . 'AS c')
|
||||
->where($db->quoteName('c.lft') . ' >= ' . (int) $this->lft)
|
||||
->where($db->quoteName('c.rgt') . ' <= ' . (int) $this->rgt);
|
||||
$db->setQuery($query);
|
||||
$ids = $db->loadColumn();
|
||||
if (empty($ids))
|
||||
{
|
||||
throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete usergroup.');
|
||||
}
|
||||
|
||||
// Delete the category dependencies
|
||||
// @todo Remove all related threads, posts and subscriptions
|
||||
|
||||
// Delete the usergroup and its children
|
||||
$query->clear()
|
||||
->delete($db->quoteName($this->_tbl))
|
||||
->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
// Delete the usergroup in view levels
|
||||
$replace = array();
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
$replace[] = ',' . $db->quote("[$id,") . ',' . $db->quote("[") . ')';
|
||||
$replace[] = ',' . $db->quote(",$id,") . ',' . $db->quote(",") . ')';
|
||||
$replace[] = ',' . $db->quote(",$id]") . ',' . $db->quote("]") . ')';
|
||||
$replace[] = ',' . $db->quote("[$id]") . ',' . $db->quote("[]") . ')';
|
||||
}
|
||||
|
||||
// SQLSsrv change. Alternative for regexp
|
||||
$query->clear()
|
||||
->select('id, rules')
|
||||
->from('#__viewlevels');
|
||||
$db->setQuery($query);
|
||||
$rules = $db->loadObjectList();
|
||||
|
||||
$match_ids = array();
|
||||
foreach ($rules as $rule)
|
||||
{
|
||||
foreach ($ids as $id)
|
||||
{
|
||||
if (strstr($rule->rules, '[' . $id) || strstr($rule->rules, ',' . $id) || strstr($rule->rules, $id . ']'))
|
||||
{
|
||||
$match_ids[] = $rule->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($match_ids))
|
||||
{
|
||||
$query->clear()
|
||||
->set('rules=' . str_repeat('replace(', 4 * count($ids)) . 'rules' . implode('', $replace))
|
||||
->update('#__viewlevels')
|
||||
->where('id IN (' . implode(',', $match_ids) . ')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
// Delete the user to usergroup mappings for the group(s) from the database.
|
||||
$query->clear()
|
||||
->delete($db->quoteName('#__user_usergroup_map'))
|
||||
->where($db->quoteName('group_id') . ' IN (' . implode(',', $ids) . ')');
|
||||
$db->setQuery($query);
|
||||
$db->execute();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
75
libraries/joomla/table/viewlevel.php
Normal file
75
libraries/joomla/table/viewlevel.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
*
|
||||
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
|
||||
* @license GNU General Public License version 2 or later; see LICENSE
|
||||
*/
|
||||
|
||||
defined('JPATH_PLATFORM') or die;
|
||||
|
||||
/**
|
||||
* Viewlevels table class.
|
||||
*
|
||||
* @package Joomla.Platform
|
||||
* @subpackage Table
|
||||
* @since 11.1
|
||||
*/
|
||||
class JTableViewlevel extends JTable
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param JDatabaseDriver $db Database driver object.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function __construct($db)
|
||||
{
|
||||
parent::__construct('#__viewlevels', 'id', $db);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to bind the data.
|
||||
*
|
||||
* @param array $array The data to bind.
|
||||
* @param mixed $ignore An array or space separated list of fields to ignore.
|
||||
*
|
||||
* @return boolean True on success, false on failure.
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function bind($array, $ignore = '')
|
||||
{
|
||||
// Bind the rules as appropriate.
|
||||
if (isset($array['rules']))
|
||||
{
|
||||
if (is_array($array['rules']))
|
||||
{
|
||||
$array['rules'] = json_encode($array['rules']);
|
||||
}
|
||||
}
|
||||
|
||||
return parent::bind($array, $ignore);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to check the current record to save
|
||||
*
|
||||
* @return boolean True on success
|
||||
*
|
||||
* @since 11.1
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
// Validate the title.
|
||||
if ((trim($this->title)) == '')
|
||||
{
|
||||
$this->setError(JText::_('JLIB_DATABASE_ERROR_VIEWLEVEL'));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user