AAAAmodule.php 0000666 00000003712 15137271446 0006563 0 ustar 00 access = (int) JFactory::getConfig()->get('access');
}
/**
* Overloaded check function.
*
* @return boolean True if the instance is sane and able to be stored in the database.
*
* @see JTable::check
* @since 11.1
*/
public function check()
{
// check for valid name
if (trim($this->title) == '')
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_MODULE'));
return false;
}
// Check the publish down date is not earlier than publish up.
if (intval($this->publish_down) > 0 && $this->publish_down < $this->publish_up)
{
$this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
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;
}
return parent::bind($array, $ignore);
}
}
menu.php 0000666 00000013314 15137271446 0006241 0 ustar 00 access = (int) JFactory::getConfig()->get('access');
}
/**
* 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 = '')
{
// Verify that the default home menu is not unset
if ($this->home == '1' && $this->language == '*' && ($array['home'] == '0'))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT_DEFAULT'));
return false;
}
//Verify that the default home menu set to "all" languages" is not unset
if ($this->home == '1' && $this->language == '*' && ($array['language'] != '*'))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_CANNOT_UNSET_DEFAULT'));
return false;
}
// Verify that the default home menu is not unpublished
if ($this->home == '1' && $this->language == '*' && $array['published'] != '1')
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNPUBLISH_DEFAULT_HOME'));
return false;
}
if (isset($array['params']) && is_array($array['params']))
{
$registry = new JRegistry;
$registry->loadArray($array['params']);
$array['params'] = (string) $registry;
}
return parent::bind($array, $ignore);
}
/**
* Overloaded check function
*
* @return boolean True on success
*
* @see JTable::check
* @since 11.1
*/
public function check()
{
// If the alias field is empty, set it to the title.
$this->alias = trim($this->alias);
if ((empty($this->alias)) && ($this->type != 'alias' && $this->type != 'url'))
{
$this->alias = $this->title;
}
// Make the alias URL safe.
$this->alias = JApplication::stringURLSafe($this->alias);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
}
// Cast the home property to an int for checking.
$this->home = (int) $this->home;
// Verify that a first level menu item alias is not 'component'.
if ($this->parent_id == 1 && $this->alias == 'component')
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_ROOT_ALIAS_COMPONENT'));
return false;
}
// Verify that a first level menu item alias is not the name of a folder.
jimport('joomla.filesystem.folders');
if ($this->parent_id == 1 && in_array($this->alias, JFolder::folders(JPATH_ROOT)))
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_MENU_ROOT_ALIAS_FOLDER', $this->alias, $this->alias));
return false;
}
// Verify that the home item a component.
if ($this->home && $this->type != 'component')
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_HOME_NOT_COMPONENT'));
return false;
}
return true;
}
/**
* Overloaded store function
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return mixed False on failure, positive integer on success.
*
* @see JTable::store
* @since 11.1
*/
public function store($updateNulls = false)
{
$db = JFactory::getDBO();
// Verify that the alias is unique
$table = JTable::getInstance('Menu', 'JTable');
if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'client_id' => $this->client_id, 'language' => $this->language))
&& ($table->id != $this->id || $this->id == 0))
{
if ($this->menutype == $table->menutype)
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS'));
}
else
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_UNIQUE_ALIAS_ROOT'));
}
return false;
}
// Verify that the home page for this language is unique
if ($this->home == '1')
{
$table = JTable::getInstance('Menu', 'JTable');
if ($table->load(array('home' => '1', 'language' => $this->language)))
{
if ($table->checked_out && $table->checked_out != $this->checked_out)
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_DEFAULT_CHECKIN_USER_MISMATCH'));
return false;
}
$table->home = 0;
$table->checked_out = 0;
$table->checked_out_time = $db->getNullDate();
$table->store();
}
// Verify that the home page for this menu is unique.
if ($table->load(array('home' => '1', 'menutype' => $this->menutype)) && ($table->id != $this->id || $this->id == 0))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_HOME_NOT_UNIQUE_IN_MENU'));
return false;
}
}
if (!parent::store($updateNulls))
{
return false;
}
// Get the new path in case the node was moved
$pathNodes = $this->getPath();
$segments = array();
foreach ($pathNodes as $node)
{
// Don't include root in path
if ($node->alias != 'root')
{
$segments[] = $node->alias;
}
}
$newPath = trim(implode('/', $segments), ' /\\');
// Use new path for partial rebuild of table
// Rebuild will return positive integer on success, false on failure
return ($this->rebuild($this->{$this->_tbl_key}, $this->lft, $this->level, $newPath) > 0);
}
}
usergroup.php 0000666 00000015145 15137271446 0007334 0 ustar 00 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
*/
public function delete($oid = null)
{
if ($oid)
{
$this->load($oid);
}
if ($this->id == 0)
{
return new JException(JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
}
if ($this->parent_id == 0)
{
return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_ROOT_CATEGORIES'));
}
if ($this->lft == 0 or $this->rgt == 0)
{
return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_CATEGORY'));
}
$db = $this->_db;
// Select the category ID and it's children
$query = $db->getQuery(true);
$query->select($db->quoteName('c') . '.' . $db->quoteName('id'));
$query->from($db->quoteName($this->_tbl) . 'AS c');
$query->where($db->quoteName('c') . '.' . $db->quoteName('lft') . ' >= ' . (int) $this->lft);
$query->where($db->quoteName('c') . '.' . $db->quoteName('rgt') . ' <= ' . (int) $this->rgt);
$db->setQuery($query);
$ids = $db->loadColumn();
if (empty($ids))
{
return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_CATEGORY'));
}
// Delete the category dependencies
// @todo Remove all related threads, posts and subscriptions
// Delete the category and its children
$query->clear();
$query->delete();
$query->from($db->quoteName($this->_tbl));
$query->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')');
$db->setQuery($query);
if (!$db->execute())
{
$this->setError($db->getErrorMsg());
return false;
}
// 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("[]") . ')';
}
$query->clear();
//sqlsrv change. Alternative for regexp
$query->select('id, rules');
$query->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 = $db->getQuery(true);
$query->set('rules=' . str_repeat('replace(', 4 * count($ids)) . 'rules' . implode('', $replace));
$query->update('#__viewlevels');
$query->where('id IN (' . implode(',', $match_ids) . ')');
$db->setQuery($query);
if (!$db->execute())
{
$this->setError($db->getErrorMsg());
return false;
}
}
// Delete the user to usergroup mappings for the group(s) from the database.
$query->clear();
$query->delete();
$query->from($db->quoteName('#__user_usergroup_map'));
$query->where($db->quoteName('group_id') . ' IN (' . implode(',', $ids) . ')');
$db->setQuery($query);
$db->execute();
// Check for a database error.
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
return true;
}
}
extension.php 0000666 00000011551 15137271446 0007312 0 ustar 00 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 JDatabase 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'));
$query->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)
{
// Initialise variables.
$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 . ')';
}
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
// Update the publishing state for rows with the given primary keys.
$query->update($this->_db->quoteName($this->_tbl));
$query->set($this->_db->quoteName('enabled') . ' = ' . (int) $state);
$query->where('(' . $where . ')' . $checkin);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
// 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;
}
}
asset.php 0000666 00000005610 15137271446 0006414 0 ustar 00 _db->getQuery(true);
// Get the asset id for the asset.
$query->select($this->_db->quoteName('id'));
$query->from($this->_db->quoteName('#__assets'));
$query->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($name));
$this->_db->setQuery($query);
$assetId = (int) $this->_db->loadResult();
if (empty($assetId))
{
return false;
}
// Check for a database error.
if ($error = $this->_db->getErrorMsg())
{
$this->setError($error);
return false;
}
return $this->load($assetId);
}
/**
* Asset 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);
$query->select('COUNT(id)');
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName('id') . ' = ' . $this->parent_id);
$this->_db->setQuery($query);
if ($this->_db->loadResult())
{
return true;
}
else
{
if ($error = $this->_db->getErrorMsg())
{
$this->setError($error);
}
else
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_INVALID_PARENT_ID'));
}
return false;
}
}
return true;
}
}
session.php 0000666 00000011026 15137271446 0006756 0 ustar 00 guest = 1;
$this->username = '';
}
/**
* Insert a session
*
* @param string $sessionId The session id
* @param integer $clientId The id of the client application
*
* @return boolean True on success
*
* @since 11.1
*/
public function insert($sessionId, $clientId)
{
$this->session_id = $sessionId;
$this->client_id = $clientId;
$this->time = time();
$ret = $this->_db->insertObject($this->_tbl, $this, 'session_id');
if (!$ret)
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->stderr()));
return false;
}
else
{
return true;
}
}
/**
* Updates the session
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function update($updateNulls = false)
{
$this->time = time();
$ret = $this->_db->updateObject($this->_tbl, $this, 'session_id', $updateNulls);
if (!$ret)
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->stderr()));
return false;
}
else
{
return true;
}
}
/**
* Destroys the pre-existing session
*
* @param integer $userId Identifier of the user for this session.
* @param array $clientIds Array of client ids for which session(s) will be destroyed
*
* @return boolean True on success.
*
* @since 11.1
*/
public function destroy($userId, $clientIds = array())
{
$clientIds = implode(',', $clientIds);
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName('userid') . ' = ' . $this->_db->quote($userId));
$query->where($this->_db->quoteName('client_id') . ' IN (' . $clientIds . ')');
$this->_db->setQuery($query);
if (!$this->_db->execute())
{
$this->setError($this->_db->stderr());
return false;
}
return true;
}
/**
* Purge old sessions
*
* @param integer $maxLifetime Session age in seconds
*
* @return mixed Resource on success, null on fail
*
* @since 11.1
*/
public function purge($maxLifetime = 1440)
{
$past = time() - $maxLifetime;
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName('time') . ' < ' . (int) $past);
$this->_db->setQuery($query);
return $this->_db->execute();
}
/**
* Find out if a user has a one or more active sessions
*
* @param integer $userid The identifier of the user
*
* @return boolean True if a session for this user exists
*
* @since 11.1
*/
public function exists($userid)
{
$query = $this->_db->getQuery(true);
$query->select('COUNT(userid)');
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName('userid') . ' = ' . $this->_db->quote($userid));
$this->_db->setQuery($query);
if (!$result = $this->_db->loadResult())
{
$this->setError($this->_db->stderr());
return false;
}
return (boolean) $result;
}
/**
* Overloaded delete method
*
* We must override it because of the non-integer primary key
*
* @param integer $oid The object id (optional).
*
* @return mixed True if successful otherwise an error message
*
* @since 11.1
*/
public function delete($oid = null)
{
//if (!$this->canDelete($msg))
//{
// return $msg;
//}
$k = $this->_tbl_key;
if ($oid)
{
$this->$k = $oid;
}
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->$k));
$this->_db->setQuery($query);
if ($this->_db->execute())
{
return true;
}
else
{
$this->setError($this->_db->getErrorMsg());
return false;
}
}
}
index.html 0000666 00000000037 15137271446 0006557 0 ustar 00
viewlevel.php 0000666 00000002723 15137271446 0007301 0 ustar 00 title)) == '')
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_VIEWLEVEL'));
return false;
}
return true;
}
}
update.php 0000666 00000004653 15137271446 0006565 0 ustar 00 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 JDatabase 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);
$query->select($this->_db->quoteName($this->_tbl_key));
$query->from($this->_db->quoteName($this->_tbl));
$query->where(implode(' AND ', $where));
$this->_db->setQuery($query);
return $this->_db->loadResult();
}
}
content.php 0000666 00000023706 15137271446 0006755 0 ustar 00 _tbl_key;
return 'com_content.article.' . (int) $this->$k;
}
/**
* Method to return the title to use for the asset table.
*
* @return string
*
* @since 11.1
*/
protected function _getAssetTitle()
{
return $this->title;
}
/**
* Method to get the parent asset id for the record
*
* @param JTable $table A JTable object (optional) for the asset parent
* @param integer $id The id (optional) of the content.
*
* @return integer
*
* @since 11.1
*/
protected function _getAssetParentId($table = null, $id = null)
{
// Initialise variables.
$assetId = null;
// This is a article under a category.
if ($this->catid)
{
// Build the query to get the asset id for the parent category.
$query = $this->_db->getQuery(true);
$query->select($this->_db->quoteName('asset_id'));
$query->from($this->_db->quoteName('#__categories'));
$query->where($this->_db->quoteName('id') . ' = ' . (int) $this->catid);
// Get the asset id from the database.
$this->_db->setQuery($query);
if ($result = $this->_db->loadResult())
{
$assetId = (int) $result;
}
}
// Return the asset id.
if ($assetId)
{
return $assetId;
}
else
{
return parent::_getAssetParentId($table, $id);
}
}
/**
* 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 string
*
* @see JTable::bind
* @since 11.1
*/
public function bind($array, $ignore = '')
{
// Search for the {readmore} tag and split the text up accordingly.
if (isset($array['articletext']))
{
$pattern = '#
#i';
$tagPos = preg_match($pattern, $array['articletext']);
if ($tagPos == 0)
{
$this->introtext = $array['articletext'];
$this->fulltext = '';
}
else
{
list ($this->introtext, $this->fulltext) = preg_split($pattern, $array['articletext'], 2);
}
}
if (isset($array['attribs']) && is_array($array['attribs']))
{
$registry = new JRegistry;
$registry->loadArray($array['attribs']);
$array['attribs'] = (string) $registry;
}
if (isset($array['metadata']) && is_array($array['metadata']))
{
$registry = new JRegistry;
$registry->loadArray($array['metadata']);
$array['metadata'] = (string) $registry;
}
// Bind the rules.
if (isset($array['rules']) && is_array($array['rules']))
{
$rules = new JAccessRules($array['rules']);
$this->setRules($rules);
}
return parent::bind($array, $ignore);
}
/**
* Overloaded check function
*
* @return boolean True on success, false on failure
*
* @see JTable::check
* @since 11.1
*/
public function check()
{
if (trim($this->title) == '')
{
$this->setError(JText::_('COM_CONTENT_WARNING_PROVIDE_VALID_NAME'));
return false;
}
if (trim($this->alias) == '')
{
$this->alias = $this->title;
}
$this->alias = JApplication::stringURLSafe($this->alias);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
}
if (trim(str_replace(' ', '', $this->fulltext)) == '')
{
$this->fulltext = '';
}
if (trim($this->introtext) == '' && trim($this->fulltext) == '')
{
$this->setError(JText::_('JGLOBAL_ARTICLE_MUST_HAVE_TEXT'));
return false;
}
// Check the publish down date is not earlier than publish up.
if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up)
{
$this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
// Clean up keywords -- eliminate extra spaces between phrases
// and cr (\r) and lf (\n) characters from string
if (!empty($this->metakey))
{
// Only process if not empty
$bad_characters = array("\n", "\r", "\"", "<", ">"); // array of characters to remove
$after_clean = JString::str_ireplace($bad_characters, "", $this->metakey); // remove bad characters
$keys = explode(',', $after_clean); // create array using commas as delimiter
$clean_keys = array();
foreach ($keys as $key)
{
if (trim($key))
{
// Ignore blank keywords
$clean_keys[] = trim($key);
}
}
$this->metakey = implode(", ", $clean_keys); // put array back together delimited by ", "
}
return true;
}
/**
* Overrides JTable::store to set modified data and user id.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
if ($this->id)
{
// Existing item
$this->modified = $date->toSql();
$this->modified_by = $user->get('id');
}
else
{
// New article. An article created and created_by field can be set by the user,
// so we don't touch either of these if they are set.
if (!intval($this->created))
{
$this->created = $date->toSql();
}
if (empty($this->created_by))
{
$this->created_by = $user->get('id');
}
}
// Verify that the alias is unique
$table = JTable::getInstance('Content', 'JTable');
if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_ARTICLE_UNIQUE_ALIAS'));
return false;
}
return parent::store($updateNulls);
}
/**
* 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)
{
// Initialise variables.
$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 . ')';
}
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
// Update the publishing state for rows with the given primary keys.
$query->update($this->_db->quoteName($this->_tbl));
$query->set($this->_db->quoteName('state') . ' = ' . (int) $state);
$query->where('(' . $where . ')' . $checkin);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
// 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->state = $state;
}
$this->setError('');
return true;
}
/**
* Converts record to XML
*
* @param boolean $mapKeysToText Map foreign keys to text values
*
* @return string Record in XML format
*
* @since 11.1
* @deprecated 12.1
* @codeCoverageIgnore
*/
public function toXML($mapKeysToText = false)
{
// Deprecation warning.
JLog::add('JTableContent::toXML() is deprecated.', JLog::WARNING, 'deprecated');
if ($mapKeysToText)
{
// Get the JDatabaseQuery object
$query = $this->_db->getQuery(true);
$query->select($this->_db->quoteName('name'));
$query->from($this->_db->quoteName('#__categories'));
$query->where($this->_db->quoteName('id') . ' = ' . (int) $this->catid);
$this->_db->setQuery($query);
$this->catid = $this->_db->loadResult();
$query->clear();
$query->select($this->_db->quoteName('name'));
$query->from($this->_db->quoteName('#__users'));
$query->where($this->_db->quoteName('id') . ' = ' . (int) $this->created_by);
$this->_db->setQuery($query);
$this->created_by = $this->_db->loadResult();
}
return parent::toXML($mapKeysToText);
}
}
category.php 0000666 00000012537 15137271446 0007120 0 ustar 00 access = (int) JFactory::getConfig()->get('access');
}
/**
* 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.
*
* @return string
*
* @since 11.1
*/
protected function _getAssetName()
{
$k = $this->_tbl_key;
return $this->extension . '.category.' . (int) $this->$k;
}
/**
* Method to return the title to use for the asset table.
*
* @return string
*
* @since 11.1
*/
protected function _getAssetTitle()
{
return $this->title;
}
/**
* Get the parent asset id for the record
*
* @param JTable $table A JTable object for the asset parent.
* @param integer $id The id for the asset
*
* @return integer The id of the asset's parent
*
* @since 11.1
*/
protected function _getAssetParentId($table = null, $id = null)
{
// Initialise variables.
$assetId = null;
// This is a category under a category.
if ($this->parent_id > 1)
{
// Build the query to get the asset id for the parent category.
$query = $this->_db->getQuery(true);
$query->select($this->_db->quoteName('asset_id'));
$query->from($this->_db->quoteName('#__categories'));
$query->where($this->_db->quoteName('id') . ' = ' . $this->parent_id);
// Get the asset id from the database.
$this->_db->setQuery($query);
if ($result = $this->_db->loadResult())
{
$assetId = (int) $result;
}
}
// This is a category that needs to parent with the extension.
elseif ($assetId === null)
{
// Build the query to get the asset id for the parent category.
$query = $this->_db->getQuery(true);
$query->select($this->_db->quoteName('id'));
$query->from($this->_db->quoteName('#__assets'));
$query->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote($this->extension));
// Get the asset id from the database.
$this->_db->setQuery($query);
if ($result = $this->_db->loadResult())
{
$assetId = (int) $result;
}
}
// Return the asset id.
if ($assetId)
{
return $assetId;
}
else
{
return parent::_getAssetParentId($table, $id);
}
}
/**
* Override check function
*
* @return boolean
*
* @see JTable::check
* @since 11.1
*/
public function check()
{
// Check for a title.
if (trim($this->title) == '')
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY'));
return false;
}
$this->alias = trim($this->alias);
if (empty($this->alias))
{
$this->alias = $this->title;
}
$this->alias = JApplication::stringURLSafe($this->alias);
if (trim(str_replace('-', '', $this->alias)) == '')
{
$this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
}
return true;
}
/**
* Overloaded bind function.
*
* @param array $array named array
* @param string $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['metadata']) && is_array($array['metadata']))
{
$registry = new JRegistry;
$registry->loadArray($array['metadata']);
$array['metadata'] = (string) $registry;
}
// Bind the rules.
if (isset($array['rules']) && is_array($array['rules']))
{
$rules = new JAccessRules($array['rules']);
$this->setRules($rules);
}
return parent::bind($array, $ignore);
}
/**
* Overridden JTable::store to set created/modified and user id.
*
* @param boolean $updateNulls True to update fields even if they are null.
*
* @return boolean True on success.
*
* @since 11.1
*/
public function store($updateNulls = false)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
if ($this->id)
{
// Existing category
$this->modified_time = $date->toSql();
$this->modified_user_id = $user->get('id');
}
else
{
// New category
$this->created_time = $date->toSql();
$this->created_user_id = $user->get('id');
}
// Verify that the alias is unique
$table = JTable::getInstance('Category', 'JTable', array('dbo' => $this->getDbo()));
if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'extension' => $this->extension))
&& ($table->id != $this->id || $this->id == 0))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_CATEGORY_UNIQUE_ALIAS'));
return false;
}
return parent::store($updateNulls);
}
}
user.php 0000666 00000031111 15137271446 0006246 0 ustar 00 group ids
*
* @var array
* @since 11.1
*/
public $groups;
/**
* Constructor
*
* @param JDatabase &$db A database connector 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);
$query->select('*');
$query->from($this->_db->quoteName('#__users'));
$query->where($this->_db->quoteName('id') . ' = ' . (int) $userId);
$this->_db->setQuery($query);
$data = (array) $this->_db->loadAssoc();
// Check for an error message.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
if (!count($data))
{
return false;
}
// Bind the data to the table.
$return = $this->bind($data);
if ($return !== false)
{
// Load the user groups.
$query->clear();
$query->select($this->_db->quoteName('g') . '.' . $this->_db->quoteName('id'));
$query->select($this->_db->quoteName('g') . '.' . $this->_db->quoteName('title'));
$query->from($this->_db->quoteName('#__usergroups') . ' AS g');
$query->join('INNER', $this->_db->quoteName('#__user_usergroup_map') . ' AS m ON m.group_id = g.id');
$query->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');
// Check for an error message.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
}
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 (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);
$query->select($this->_db->quoteName('id'));
$query->select($this->_db->quoteName('title'));
$query->from($this->_db->quoteName('#__usergroups'));
$query->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');
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
}
return $return;
}
/**
* Validation and filtering
*
* @return boolean True if satisfactory
*
* @since 11.1
*/
public function check()
{
// 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('#[<>"\'%;()&\\\\]|\\.\\./#', $this->username) || strlen(utf8_decode($this->username)) < 2
|| trim($this->username) != $this->username)
{
$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;
}
// Set the registration timestamp
if ($this->registerDate == null || $this->registerDate == $this->_db->getNullDate())
{
$this->registerDate = JFactory::getDate()->toSql();
}
// check for existing username
$query = $this->_db->getQuery(true);
$query->select($this->_db->quoteName('id'));
$query->from($this->_db->quoteName('#__users'));
$query->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($this->username));
$query->where($this->_db->quoteName('id') . ' != ' . (int) $this->id);
$this->_db->setQuery($query);
$xid = intval($this->_db->loadResult());
if ($xid && $xid != intval($this->id))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_USERNAME_INUSE'));
return false;
}
// check for existing email
$query->clear();
$query->select($this->_db->quoteName('id'));
$query->from($this->_db->quoteName('#__users'));
$query->where($this->_db->quoteName('email') . ' = ' . $this->_db->quote($this->email));
$query->where($this->_db->quoteName('id') . ' != ' . (int) $this->id);
$this->_db->setQuery($query);
$xid = intval($this->_db->loadResult());
if ($xid && $xid != intval($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();
$query->select($this->_db->quoteName('id'));
$query->from($this->_db->quoteName('#__users'));
$query->where($this->_db->quoteName('username') . ' = ' . $this->_db->quote($rootUser));
$this->_db->setQuery($query);
$xid = intval($this->_db->loadResult());
if ($rootUser == $this->username && (!$xid || $xid && $xid != intval($this->id))
|| $xid && $xid == intval($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.
$return = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
}
else
{
// Don't have a table key, insert the row.
$return = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
}
// Handle error if it exists.
if (!$return)
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->getErrorMsg()));
return false;
}
// Reset groups to the local object.
$this->groups = $groups;
unset($groups);
// Store the group data if the user data was saved.
if ($return && is_array($this->groups) && count($this->groups))
{
// Delete the old user group maps.
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_db->quoteName('#__user_usergroup_map'));
$query->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->id);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
// Set the new user group maps.
$query->clear();
$query->insert($this->_db->quoteName('#__user_usergroup_map'));
$query->columns(array($this->_db->quoteName('user_id'), $this->_db->quoteName('group_id')));
$query->values($this->id . ', ' . implode('), (' . $this->id . ', ', $this->groups));
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
}
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 = intval($userId);
}
// Delete the user.
$query = $this->_db->getQuery(true);
$query->delete();
$query->from($this->_db->quoteName($this->_tbl));
$query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . (int) $this->$k);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
// Delete the user group maps.
$query->clear();
$query->delete();
$query->from($this->_db->quoteName('#__user_usergroup_map'));
$query->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->$k);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
/*
* Clean Up Related Data.
*/
$query->clear();
$query->delete();
$query->from($this->_db->quoteName('#__messages_cfg'));
$query->where($this->_db->quoteName('user_id') . ' = ' . (int) $this->$k);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
$query->clear();
$query->delete();
$query->from($this->_db->quoteName('#__messages'));
$query->where($this->_db->quoteName('user_id_to') . ' = ' . (int) $this->$k);
$this->_db->setQuery($query);
$this->_db->execute();
// Check for a database error.
if ($this->_db->getErrorNum())
{
$this->setError($this->_db->getErrorMsg());
return false;
}
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
{
// do not translate
jexit(JText::_('JLIB_DATABASE_ERROR_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);
$query->update($db->quoteName($this->_tbl));
$query->set($db->quoteName('lastvisitDate') . '=' . $db->quote($date->toSql()));
$query->where($db->quoteName('id') . '=' . (int) $userId);
$db->setQuery($query);
$db->execute();
// Check for a database error.
if ($db->getErrorNum())
{
$this->setError($db->getErrorMsg());
return false;
}
return true;
}
}
menutype.php 0000666 00000017051 15137271446 0007145 0 ustar 00 menutype = JApplication::stringURLSafe($this->menutype);
if (empty($this->menutype))
{
$this->setError(JText::_('JLIB_DATABASE_ERROR_MENUTYPE_EMPTY'));
return false;
}
// Sanitise data.
if (trim($this->title) == '')
{
$this->title = $this->menutype;
}
// Check for unique menutype.
$query = $this->_db->getQuery(true);
$query->select('COUNT(id)');
$query->from($this->_db->quoteName('#__menu_types'));
$query->where($this->_db->quoteName('menutype') . ' = ' . $this->_db->quote($this->menutype));
$query->where($this->_db->quoteName('id') . ' <> ' . (int) $this->id);
$this->_db->setQuery($query);
if ($this->_db->loadResult())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_MENUTYPE_EXISTS', $this->menutype));
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)
{
if ($this->id)
{
// Get the user id
$userId = JFactory::getUser()->id;
// Get the old value of the table
$table = JTable::getInstance('Menutype', 'JTable');
$table->load($this->id);
// Verify that no items are checked out
$query = $this->_db->getQuery(true);
$query->select('id');
$query->from('#__menu');
$query->where('menutype=' . $this->_db->quote($table->menutype));
$query->where('checked_out !=' . (int) $userId);
$query->where('checked_out !=0');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(
JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE_CHECKOUT'))
);
return false;
}
// Verify that no module for this menu are checked out
$query = $this->_db->getQuery(true);
$query->select('id');
$query->from('#__modules');
$query->where('module=' . $this->_db->quote('mod_menu'));
$query->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$query->where('checked_out !=' . (int) $userId);
$query->where('checked_out !=0');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(
JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE_CHECKOUT'))
);
return false;
}
// Update the menu items
$query = $this->_db->getQuery(true);
$query->update('#__menu');
$query->set('menutype=' . $this->_db->quote($this->menutype));
$query->where('menutype=' . $this->_db->quote($table->menutype));
$this->_db->setQuery($query);
if (!$this->_db->execute())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg()));
return false;
}
// Update the module items
$query = $this->_db->getQuery(true);
$query->update('#__modules');
$query->set(
'params=REPLACE(params,' . $this->_db->quote('"menutype":' . json_encode($table->menutype)) . ',' .
$this->_db->quote('"menutype":' . json_encode($this->menutype)) . ')'
);
$query->where('module=' . $this->_db->quote('mod_menu'));
$query->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$this->_db->setQuery($query);
if (!$this->_db->execute())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg()));
return false;
}
}
return parent::store($updateNulls);
}
/**
* Method to delete a row from the database table by primary key value.
*
* @param mixed $pk An optional primary key value to delete. If not set the instance property value is used.
*
* @return boolean True on success.
*
* @link http://docs.joomla.org/JTable/delete
* @since 11.1
*/
public function delete($pk = null)
{
// Initialise variables.
$k = $this->_tbl_key;
$pk = (is_null($pk)) ? $this->$k : $pk;
// If no primary key is given, return false.
if ($pk !== null)
{
// Get the user id
$userId = JFactory::getUser()->id;
// Get the old value of the table
$table = JTable::getInstance('Menutype', 'JTable');
$table->load($pk);
// Verify that no items are checked out
$query = $this->_db->getQuery(true);
$query->select('id');
$query->from('#__menu');
$query->where('menutype=' . $this->_db->quote($table->menutype));
$query->where('client_id=0');
$query->where('(checked_out NOT IN (0,' . (int) $userId . ') OR home=1 AND language=' . $this->_db->quote('*') . ')');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE')));
return false;
}
// Verify that no module for this menu are checked out
$query = $this->_db->getQuery(true);
$query->select('id');
$query->from('#__modules');
$query->where('module=' . $this->_db->quote('mod_menu'));
$query->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$query->where('checked_out !=' . (int) $userId);
$query->where('checked_out !=0');
$this->_db->setQuery($query);
if ($this->_db->loadRowList())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), JText::_('JLIB_DATABASE_ERROR_MENUTYPE')));
return false;
}
// Delete the menu items
$query = $this->_db->getQuery(true);
$query->delete();
$query->from('#__menu');
$query->where('menutype=' . $this->_db->quote($table->menutype));
$query->where('client_id=0');
$this->_db->setQuery($query);
if (!$this->_db->execute())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg()));
return false;
}
// Update the module items
$query = $this->_db->getQuery(true);
$query->delete();
$query->from('#__modules');
$query->where('module=' . $this->_db->quote('mod_menu'));
$query->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$this->_db->setQuery($query);
if (!$this->_db->execute())
{
$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg()));
return false;
}
}
return parent::delete($pk);
}
}
.htaccess 0000666 00000000177 15137271446 0006365 0 ustar 00
Order allow,deny
Deny from all