first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,229 @@
<?php
/**
* @package Joomla.Legacy
* @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;
/**
* Category table
*
* @package Joomla.Legacy
* @subpackage Table
* @since 11.1
*/
class JTableCategory extends JTableNested
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct($db)
{
parent::__construct('#__categories', 'id', $db);
$this->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)
{
$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)
->select($this->_db->quoteName('asset_id'))
->from($this->_db->quoteName('#__categories'))
->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)
->select($this->_db->quoteName('id'))
->from($this->_db->quoteName('#__assets'))
->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);
}
}

View File

@ -0,0 +1,378 @@
<?php
/**
* @package Joomla.Legacy
* @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;
/**
* Content table
*
* @package Joomla.Legacy
* @subpackage Table
* @since 11.1
* @deprecated Class will be removed upon completion of transition to UCM
*/
class JTableContent extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver $db A database connector object
*
* @since 11.1
*/
public function __construct($db)
{
parent::__construct('#__content', 'id', $db);
/*
* This is left here for reference:
*
* This would set up the tags observer in $this from here (so not entirely decoupled):
* JTableObserverTags::createObserver($this, array('typeAlias' => 'com_content.article'));
*
* But this makes the relation between content and tags completely external to Content as JTable is observable:
* So we are doing this only once in libraries/cms.php:
* JObserverFactory::addObserverClassToClass('JTableObserverTags', 'JTableContent', array('typeAlias' => 'com_content.article'));
*/
}
/**
* 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 '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)
{
$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)
->select($this->_db->quoteName('asset_id'))
->from($this->_db->quoteName('#__categories'))
->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 = '#<hr\s+id=("|\')system-readmore("|\')\s*\/*>#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('&nbsp;', '', $this->fulltext)) == '')
{
$this->fulltext = '';
}
// Check the publish down date is not earlier than publish up.
if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up)
{
// Swap the dates.
$temp = $this->publish_up;
$this->publish_up = $this->publish_down;
$this->publish_down = $temp;
}
// 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
// Array of characters to remove
$bad_characters = array("\n", "\r", "\"", "<", ">");
// Remove bad characters
$after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
// Create array using commas as delimiter
$keys = explode(',', $after_clean);
$clean_keys = array();
foreach ($keys as $key)
{
if (trim($key))
{
// Ignore blank keywords
$clean_keys[] = trim($key);
}
}
// Put array back together delimited by ", "
$this->metakey = implode(", ", $clean_keys);
}
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 (!(int) $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)
{
$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('state') . ' = ' . (int) $state)
->where('(' . $where . ')' . $checkin);
$this->_db->setQuery($query);
try
{
$this->_db->execute();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
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;
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,204 @@
<?php
/**
* @package Joomla.Legacy
* @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;
/**
* Menu table
*
* @package Joomla.Legacy
* @subpackage Table
* @since 11.1
*/
class JTableMenu extends JTableNested
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct($db)
{
parent::__construct('#__menu', 'id', $db);
// Set the default access level.
$this->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.folder');
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', array('dbo' => $this->getDbo()));
if ($table->load(array('alias' => $this->alias, 'parent_id' => $this->parent_id, 'client_id' => (int) $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', array('dbo' => $this->getDbo()));
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);
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,226 @@
<?php
/**
* @package Joomla.Legacy
* @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;
/**
* Menu Types table
*
* @package Joomla.Legacy
* @subpackage Table
* @since 11.1
*/
class JTableMenuType extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct($db)
{
parent::__construct('#__menu_types', 'id', $db);
}
/**
* Overloaded check function
*
* @return boolean True on success, false on failure
*
* @see JTable::check
* @since 11.1
*/
public function check()
{
$this->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)
->select('COUNT(id)')
->from($this->_db->quoteName('#__menu_types'))
->where($this->_db->quoteName('menutype') . ' = ' . $this->_db->quote($this->menutype))
->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)
->select('id')
->from('#__menu')
->where('menutype=' . $this->_db->quote($table->menutype))
->where('checked_out !=' . (int) $userId)
->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->clear()
->select('id')
->from('#__modules')
->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'))
->where('checked_out !=' . (int) $userId)
->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->clear()
->update('#__menu')
->set('menutype=' . $this->_db->quote($this->menutype))
->where('menutype=' . $this->_db->quote($table->menutype));
$this->_db->setQuery($query);
$this->_db->execute();
// Update the module items
$query->clear()
->update('#__modules')
->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'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$this->_db->setQuery($query);
$this->_db->execute();
}
return parent::store($updateNulls);
}
/**
* Override parent delete method to delete tags information.
*
* @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)
{
$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)
->select('id')
->from('#__menu')
->where('menutype=' . $this->_db->quote($table->menutype))
->where('client_id=0')
->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->clear()
->select('id')
->from('#__modules')
->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'))
->where('checked_out !=' . (int) $userId)
->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->clear()
->delete('#__menu')
->where('menutype=' . $this->_db->quote($table->menutype))
->where('client_id=0');
$this->_db->setQuery($query);
$this->_db->execute();
// Update the module items
$query->clear()
->delete('#__modules')
->where('module=' . $this->_db->quote('mod_menu'))
->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%'));
$this->_db->setQuery($query);
$this->_db->execute();
}
return parent::delete($pk);
}
}

View File

@ -0,0 +1,86 @@
<?php
/**
* @package Joomla.Legacy
* @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;
/**
* Module table
*
* @package Joomla.Legacy
* @subpackage Table
* @since 11.1
*/
class JTableModule extends JTable
{
/**
* Constructor.
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct($db)
{
parent::__construct('#__modules', 'id', $db);
$this->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 ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up)
{
// Swap the dates.
$temp = $this->publish_up;
$this->publish_up = $this->publish_down;
$this->publish_down = $temp;
}
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);
}
}

View File

@ -0,0 +1,192 @@
<?php
/**
* @package Joomla.Legacy
* @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;
/**
* Session table
*
* @package Joomla.Legacy
* @subpackage Table
* @since 11.1
*/
class JTableSession extends JTable
{
/**
* Constructor
*
* @param JDatabaseDriver $db Database driver object.
*
* @since 11.1
*/
public function __construct($db)
{
parent::__construct('#__session', 'session_id', $db);
$this->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)
->delete($this->_db->quoteName($this->_tbl))
->where($this->_db->quoteName('userid') . ' = ' . $this->_db->quote($userId))
->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)
->delete($this->_db->quoteName($this->_tbl))
->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)
->select('COUNT(userid)')
->from($this->_db->quoteName($this->_tbl))
->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)
{
$k = $this->_tbl_key;
if ($oid)
{
$this->$k = $oid;
}
$query = $this->_db->getQuery(true)
->delete($this->_db->quoteName($this->_tbl))
->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->$k));
$this->_db->setQuery($query);
$this->_db->execute();
return true;
}
}