diff --git a/administrator/components/com_banners/controllers/banner.php b/administrator/components/com_banners/controllers/banner.php index 88c3e1f2db603..8279164223551 100644 --- a/administrator/components/com_banners/controllers/banner.php +++ b/administrator/components/com_banners/controllers/banner.php @@ -1,8 +1,10 @@ authorise('core.create', $this->option.'.category.'.$categoryId); + $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } - if ($allow === null) { - // In the absense of better information, revert to the component permissions. + if ($allow === null) + { + // In the absence of better information, revert to the component permissions. return parent::allowAdd($data); - } else { + } + else + { return $allow; } } @@ -56,11 +63,12 @@ protected function allowAdd($data = array()) /** * Method override to check if you can edit an existing record. * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key. + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. * - * @return boolean - * @since 1.6 + * @return boolean + * + * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { @@ -69,16 +77,43 @@ protected function allowEdit($data = array(), $key = 'id') $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $categoryId = 0; - if ($recordId) { + if ($recordId) + { $categoryId = (int) $this->getModel()->getItem($recordId)->catid; } - if ($categoryId) { + if ($categoryId) + { // The category has been set. Check the category permissions. - return $user->authorise('core.edit', $this->option.'.category.'.$categoryId); - } else { + return $user->authorise('core.edit', $this->option . '.category.' . $categoryId); + } + else + { // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } } + + /** + * Method to run batch operations. + * + * @param string $model The model + * + * @return boolean True on success. + * + * @since 2.5 + */ + public function batch($model = null) + { + JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('Banner', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_banners&view=banners' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } + } diff --git a/administrator/components/com_banners/helpers/html/banner.php b/administrator/components/com_banners/helpers/html/banner.php new file mode 100644 index 0000000000000..7d6498d67def4 --- /dev/null +++ b/administrator/components/com_banners/helpers/html/banner.php @@ -0,0 +1,72 @@ +', + JText::_('COM_BANNERS_BATCH_CLIENT_LABEL'), + '', + '' + ); + + return implode("\n", $lines); + } + + /** + * Method to get the field options. + * + * @return array The field option objects. + * @since 1.6 + */ + public static function clientlist() + { + $db = JFactory::getDbo(); + $query = $db->getQuery(true); + + $query->select('id As value, name As text'); + $query->from('#__banner_clients AS a'); + $query->order('a.name'); + + // Get the options. + $db->setQuery($query); + + $options = $db->loadObjectList(); + + // Check for a database error. + if ($db->getErrorNum()) { + JError::raiseWarning(500, $db->getErrorMsg()); + } + + return $options; + } +} diff --git a/administrator/components/com_banners/helpers/html/index.html b/administrator/components/com_banners/helpers/html/index.html new file mode 100644 index 0000000000000..2efb97f319a35 --- /dev/null +++ b/administrator/components/com_banners/helpers/html/index.html @@ -0,0 +1 @@ + diff --git a/administrator/components/com_banners/models/banner.php b/administrator/components/com_banners/models/banner.php index 2d8b525a67a9e..6e133b37db767 100644 --- a/administrator/components/com_banners/models/banner.php +++ b/administrator/components/com_banners/models/banner.php @@ -1,8 +1,10 @@ setError(JText::_('JGLOBAL_NO_ITEM_SELECTED')); + return false; + } + + $done = false; + + if (!empty($commands['category_id'])) + { + $cmd = JArrayHelper::getValue($commands, 'move_copy', 'c'); + + if ($cmd == 'c') + { + $result = $this->batchCopy($commands['category_id'], $pks, $contexts); + if (is_array($result)) + { + $pks = $result; + } + else + { + return false; + } + } + elseif ($cmd == 'm' && !$this->batchMove($commands['category_id'], $pks, $contexts)) + { + return false; + } + $done = true; + } + + if (strlen($commands['client_id']) > 0) + { + if (!$this->batchClient($commands['client_id'], $pks, $contexts)) + { + return false; + } + + $done = true; + } + + if (!empty($commands['language_id'])) + { + if (!$this->batchLanguage($commands['language_id'], $pks, $contexts)) + { + return false; + } + + $done = true; + } + + if (!$done) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); + return false; + } + + // Clear the cache + $this->cleanCache(); + + return true; + } + + /** + * Batch client changes for a group of banners. + * + * @param string $value The new value matching a client. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 2.5 + */ + protected function batchClient($value, $pks, $contexts) + { + // Set the variables + $user = JFactory::getUser(); + $table = $this->getTable(); + + foreach ($pks as $pk) + { + if ($user->authorise('core.edit', $contexts[$pk])) + { + $table->reset(); + $table->load($pk); + $table->cid = (int) $value; + + if (!$table->store()) + { + $this->setError($table->getError()); + return false; + } + } + else + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + return false; + } + } + + // Clean the cache + $this->cleanCache(); + + return true; + } + + /** + * Batch copy items to a new category or current. + * + * @param integer $value The new category. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 2.5 + */ + protected function batchCopy($value, $pks, $contexts) + { + $categoryId = (int) $value; + + $table = $this->getTable(); + $i = 0; + + // Check that the category exists + if ($categoryId) + { + $categoryTable = JTable::getInstance('Category'); + if (!$categoryTable->load($categoryId)) + { + if ($error = $categoryTable->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + } + } + + if (empty($categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + + // Check that the user has create permission for the component + $user = JFactory::getUser(); + if (!$user->authorise('core.create', 'com_banners.category.' . $categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); + return false; + } + + // Parent exists so we let's proceed + while (!empty($pks)) + { + // Pop the first ID off the stack + $pk = array_shift($pks); + + $table->reset(); + + // Check that the row actually exists + if (!$table->load($pk)) + { + if ($error = $table->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + // Alter the title & alias + $data = $this->generateNewTitle($categoryId, $table->alias, $table->name); + $table->name = $data['0']; + $table->alias = $data['1']; + + // Reset the ID because we are making a copy + $table->id = 0; + + // New category ID + $table->catid = $categoryId; + + // TODO: Deal with ordering? + //$table->ordering = 1; + + // Check the row. + if (!$table->check()) + { + $this->setError($table->getError()); + return false; + } + + // Store the row. + if (!$table->store()) + { + $this->setError($table->getError()); + return false; + } + + // Get the new item ID + $newId = $table->get('id'); + + // Add the new ID to the array + $newIds[$i] = $newId; + $i++; + } + + // Clean the cache + $this->cleanCache(); + + return $newIds; + } + /** * Method to test whether a record can be deleted. * - * @param object A record object. - * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. - * @since 1.6 + * @param object $record A record object. + * + * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. + * + * @since 1.6 */ protected function canDelete($record) { - if (!empty($record->id)) { - if ($record->state != -2) { - return ; + if (!empty($record->id)) + { + if ($record->state != -2) + { + return; } $user = JFactory::getUser(); - if (!empty($record->catid)) { - return $user->authorise('core.delete', 'com_banners.category.'.(int) $record->catid); + if (!empty($record->catid)) + { + return $user->authorise('core.delete', 'com_banners.category.' . (int) $record->catid); } - else { + else + { return parent::canDelete($record); } } @@ -52,32 +309,38 @@ protected function canDelete($record) /** * Method to test whether a record can have its state changed. * - * @param object A record object. - * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. - * @since 1.6 + * @param object $record A record object. + * + * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. + * + * @since 1.6 */ protected function canEditState($record) { $user = JFactory::getUser(); // Check against the category. - if (!empty($record->catid)) { - return $user->authorise('core.edit.state', 'com_banners.category.'.(int) $record->catid); + if (!empty($record->catid)) + { + return $user->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid); } // Default to component settings if category not known. - else { + else + { return parent::canEditState($record); } } /** - * Returns a reference to the a Table object, always creating it. + * Returns a JTable object, always creating it. + * + * @param string $type The table type to instantiate. [optional] + * @param string $prefix A prefix for the table class name. [optional] + * @param array $config Configuration array for model. [optional] * - * @param type The table type to instantiate - * @param string A prefix for the table class name. Optional. - * @param array Configuration array for model. Optional. - * @return JTable A database object - * @since 1.6 + * @return JTable A database object + * + * @since 1.6 */ public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = array()) { @@ -87,30 +350,37 @@ public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = a /** * Method to get the record form. * - * @param array $data Data for the form. - * @param boolean $loadData True if the form is to load its own data (default case), false if not. - * @return mixed A JForm object on success, false on failure - * @since 1.6 + * @param array $data Data for the form. [optional] + * @param boolean $loadData True if the form is to load its own data (default case), false if not. [optional] + * + * @return mixed A JForm object on success, false on failure + * + * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_banners.banner', 'banner', array('control' => 'jform', 'load_data' => $loadData)); - if (empty($form)) { + if (empty($form)) + { return false; } // Determine correct permissions to check. - if ($this->getState('banner.id')) { + if ($this->getState('banner.id')) + { // Existing record. Can only edit in selected categories. $form->setFieldAttribute('catid', 'action', 'core.edit'); - } else { + } + else + { // New record. Can only create in selected categories. $form->setFieldAttribute('catid', 'action', 'core.create'); } // Modify the form based on access controls. - if (!$this->canEditState((object) $data)) { + if (!$this->canEditState((object) $data)) + { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('publish_up', 'disabled', 'true'); @@ -133,19 +403,22 @@ public function getForm($data = array(), $loadData = true) /** * Method to get the data that should be injected in the form. * - * @return mixed The data for the form. - * @since 1.6 + * @return mixed The data for the form. + * + * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_banners.edit.banner.data', array()); - if (empty($data)) { + if (empty($data)) + { $data = $this->getItem(); // Prime some default values. - if ($this->getState('banner.id') == 0) { + if ($this->getState('banner.id') == 0) + { $app = JFactory::getApplication(); $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_banners.banners.filter.category_id'))); } @@ -157,22 +430,27 @@ protected function loadFormData() /** * Method to stick records. * - * @param array The ids of the items to publish. - * @param int The value of the published state + * @param array &$pks The ids of the items to publish. + * @param integer $value The value of the published state + * + * @return boolean True on success. * - * @return boolean True on success. + * @since 1.6 */ function stick(&$pks, $value = 1) { // Initialise variables. - $user = JFactory::getUser(); - $table = $this->getTable(); - $pks = (array) $pks; + $user = JFactory::getUser(); + $table = $this->getTable(); + $pks = (array) $pks; // Access checks. - foreach ($pks as $i => $pk) { - if ($table->load($pk)) { - if (!$this->canEditState($table)) { + foreach ($pks as $i => $pk) + { + if ($table->load($pk)) + { + if (!$this->canEditState($table)) + { // Prune items that you can't change. unset($pks[$i]); JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); @@ -181,7 +459,8 @@ function stick(&$pks, $value = 1) } // Attempt to change the state of the records. - if (!$table->stick($pks, $value, $user->get('id'))) { + if (!$table->stick($pks, $value, $user->get('id'))) + { $this->setError($table->getError()); return false; } @@ -192,9 +471,11 @@ function stick(&$pks, $value = 1) /** * A protected method to get a set of ordering conditions. * - * @param object A record object. - * @return array An array of conditions to add to add to ordering queries. - * @since 1.6 + * @param JTable $table A record object. + * + * @return array An array of conditions to add to add to ordering queries. + * + * @since 1.6 */ protected function getReorderConditions($table) { diff --git a/administrator/components/com_banners/views/banners/tmpl/default.php b/administrator/components/com_banners/views/banners/tmpl/default.php index 8a8a2e594fb3b..bcc2dd91893e2 100644 --- a/administrator/components/com_banners/views/banners/tmpl/default.php +++ b/administrator/components/com_banners/views/banners/tmpl/default.php @@ -1,10 +1,10 @@ + + loadTemplate('batch'); ?> +
diff --git a/administrator/components/com_banners/views/banners/tmpl/default_batch.php b/administrator/components/com_banners/views/banners/tmpl/default_batch.php new file mode 100644 index 0000000000000..b16936564883b --- /dev/null +++ b/administrator/components/com_banners/views/banners/tmpl/default_batch.php @@ -0,0 +1,31 @@ +state->get('filter.published'); +?> +
+ +

+ + + + = 0) : ?> + + + + + +
diff --git a/administrator/components/com_banners/views/banners/view.html.php b/administrator/components/com_banners/views/banners/view.html.php index c7b5e90f1ed09..a183d4b84e934 100644 --- a/administrator/components/com_banners/views/banners/view.html.php +++ b/administrator/components/com_banners/views/banners/view.html.php @@ -1,8 +1,10 @@ state = $this->get('State'); // Check for errors. - if (count($errors = $this->get('Errors'))) { + if (count($errors = $this->get('Errors'))) + { JError::raiseError(500, implode("\n", $errors)); return false; } $this->addToolbar(); - require_once JPATH_COMPONENT .'/models/fields/bannerclient.php'; + require_once JPATH_COMPONENT . '/models/fields/bannerclient.php'; + // Include the component HTML helpers. + JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + parent::display($tpl); } /** * Add the page title and toolbar. * - * @since 1.6 + * @return void + * + * @since 1.6 */ protected function addToolbar() { - require_once JPATH_COMPONENT.'/helpers/banners.php'; + require_once JPATH_COMPONENT . '/helpers/banners.php'; - $canDo = BannersHelper::getActions($this->state->get('filter.category_id')); - $user = JFactory::getUser(); + $canDo = BannersHelper::getActions($this->state->get('filter.category_id')); + $user = JFactory::getUser(); JToolBarHelper::title(JText::_('COM_BANNERS_MANAGER_BANNERS'), 'banners.png'); - if (count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0) { + if (count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0) + { JToolBarHelper::addNew('banner.add'); } - if (($canDo->get('core.edit'))) { + if (($canDo->get('core.edit'))) + { JToolBarHelper::editList('banner.edit'); } - if ($canDo->get('core.edit.state')) { - if ($this->state->get('filter.state') != 2){ + if ($canDo->get('core.edit.state')) + { + if ($this->state->get('filter.state') != 2) + { JToolBarHelper::divider(); JToolBarHelper::publish('banners.publish', 'JTOOLBAR_PUBLISH', true); JToolBarHelper::unpublish('banners.unpublish', 'JTOOLBAR_UNPUBLISH', true); } - if ($this->state->get('filter.state') != -1 ) { + if ($this->state->get('filter.state') != -1) + { JToolBarHelper::divider(); - if ($this->state->get('filter.state') != 2) { + if ($this->state->get('filter.state') != 2) + { JToolBarHelper::archiveList('banners.archive'); } - elseif ($this->state->get('filter.state') == 2) { + elseif ($this->state->get('filter.state') == 2) + { JToolBarHelper::unarchiveList('banners.publish'); } } } - if ($canDo->get('core.edit.state')) { + if ($canDo->get('core.edit.state')) + { JToolBarHelper::checkin('banners.checkin'); } - - if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) { + if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) + { JToolBarHelper::deleteList('', 'banners.delete', 'JTOOLBAR_EMPTY_TRASH'); JToolBarHelper::divider(); - } elseif ($canDo->get('core.edit.state')) { + } + elseif ($canDo->get('core.edit.state')) + { JToolBarHelper::trash('banners.trash'); JToolBarHelper::divider(); } - if ($canDo->get('core.admin')) { + if ($canDo->get('core.admin')) + { JToolBarHelper::preferences('com_banners'); JToolBarHelper::divider(); } diff --git a/administrator/components/com_categories/controllers/category.php b/administrator/components/com_categories/controllers/category.php index 8c02b62c03e41..c570d2e8b38ab 100644 --- a/administrator/components/com_categories/controllers/category.php +++ b/administrator/components/com_categories/controllers/category.php @@ -1,8 +1,10 @@ extension)) { + if (empty($this->extension)) + { $this->extension = JRequest::getCmd('extension', 'com_content'); } } @@ -44,12 +50,11 @@ public function __construct($config = array()) /** * Method to check if you can add a new record. * - * Extended classes can override this if necessary. + * @param array $data An array of input data. * - * @param array An array of input data. + * @return boolean * - * @return boolean - * @since 1.6 + * @since 1.6 */ protected function allowAdd($data = array()) { @@ -59,41 +64,45 @@ protected function allowAdd($data = array()) /** * Method to check if you can edit a record. * - * Extended classes can override this if necessary. + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. * - * @param array An array of input data. - * @param string The name of the key for the primary key. + * @return boolean * - * @return boolean - * @since 1.6 + * @since 1.6 */ protected function allowEdit($data = array(), $key = 'parent_id') { // Initialise variables. - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; - $user = JFactory::getUser(); - $userId = $user->get('id'); + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $user = JFactory::getUser(); + $userId = $user->get('id'); // Check general edit permission first. - if ($user->authorise('core.edit', $this->extension)) { + if ($user->authorise('core.edit', $this->extension)) + { return true; } // Check specific edit permission. - if ($user->authorise('core.edit', $this->extension.'.category.'.$recordId)) { + if ($user->authorise('core.edit', $this->extension . '.category.' . $recordId)) + { return true; } // Fallback on edit.own. // First test if the permission is available. - if ($user->authorise('core.edit.own', $this->extension.'.category.'.$recordId) || $user->authorise('core.edit.own', $this->extension)) { + if ($user->authorise('core.edit.own', $this->extension . '.category.' . $recordId) || $user->authorise('core.edit.own', $this->extension)) + { // Now test the owner is the user. - $ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0; - if (empty($ownerId) && $recordId) { + $ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0; + if (empty($ownerId) && $recordId) + { // Need to do a lookup from the model. - $record = $this->getModel()->getItem($recordId); + $record = $this->getModel()->getItem($recordId); - if (empty($record)) { + if (empty($record)) + { return false; } @@ -101,32 +110,32 @@ protected function allowEdit($data = array(), $key = 'parent_id') } // If the owner matches 'me' then do the test. - if ($ownerId == $userId) { + if ($ownerId == $userId) + { return true; } } return false; - } + } /** - * Method to run batch opterations. + * Method to run batch operations. + * + * @param object $model The model. * - * @return void + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 1.6 */ - public function batch($model) + public function batch($model = null) { JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model - $model = $this->getModel('Category'); - - $extension = JRequest::getCmd('extension', ''); - if ($extension) { - $extension = '&extension='.$extension; - } + $model = $this->getModel('Category'); // Preset the redirect - $this->setRedirect('index.php?option=com_categories&view=categories'.$extension); + $this->setRedirect('index.php?option=com_categories&view=categories&extension=' . $this->extension); return parent::batch($model); } @@ -134,15 +143,17 @@ public function batch($model) /** * Gets the URL arguments to append to an item redirect. * - * @param int $recordId The primary key id for the item. + * @param integer $recordId The primary key id for the item. + * @param string $urlVar The name of the URL variable for the id. * - * @return string The arguments to append to the redirect URL. - * @since 1.6 + * @return string The arguments to append to the redirect URL. + * + * @since 1.6 */ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') { $append = parent::getRedirectToItemAppend($recordId); - $append .= '&extension='.$this->extension; + $append .= '&extension=' . $this->extension; return $append; } @@ -150,13 +161,14 @@ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') /** * Gets the URL arguments to append to a list redirect. * - * @return string The arguments to append to the redirect URL. - * @since 1.6 + * @return string The arguments to append to the redirect URL. + * + * @since 1.6 */ protected function getRedirectToListAppend() { $append = parent::getRedirectToListAppend(); - $append .= '&extension='.$this->extension; + $append .= '&extension=' . $this->extension; return $append; } diff --git a/administrator/components/com_categories/models/category.php b/administrator/components/com_categories/models/category.php index f6e87cfd542ca..1afcdbc700a42 100644 --- a/administrator/components/com_categories/models/category.php +++ b/administrator/components/com_categories/models/category.php @@ -1,8 +1,10 @@ id)) { - if ($record->published != -2) { - return ; + if (!empty($record->id)) + { + if ($record->published != -2) + { + return; } $user = JFactory::getUser(); - return $user->authorise('core.delete', $record->extension.'.category.'.(int) $record->id); - + return $user->authorise('core.delete', $record->extension . '.category.' . (int) $record->id); } } /** - * Method to test whether a record can be deleted. + * Method to test whether a record can have its state changed. * - * @param object A record object. - * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. - * @since 1.6 + * @param object $record A record object. + * + * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. + * + * @since 1.6 */ protected function canEditState($record) { $user = JFactory::getUser(); // Check for existing category. - if (!empty($record->id)) { - return $user->authorise('core.edit.state', $record->extension.'.category.'.(int) $record->id); + if (!empty($record->id)) + { + return $user->authorise('core.edit.state', $record->extension . '.category.' . (int) $record->id); } // New category, so check against the parent. - elseif (!empty($record->parent_id)) { - return $user->authorise('core.edit.state', $record->extension.'.category.'.(int) $record->parent_id); + elseif (!empty($record->parent_id)) + { + return $user->authorise('core.edit.state', $record->extension . '.category.' . (int) $record->parent_id); } // Default to component settings if neither category nor parent known. - else { + else + { return $user->authorise('core.edit.state', $record->extension); } } /** - * Returns a Table object, always creating it + * Method to get a table object, load it if necessary. * - * @param type The table type to instantiate - * @param string A prefix for the table class name. Optional. - * @param array Configuration array for model. Optional. - * @return JTable A database object - * @since 1.6 + * @param string $type The table name. Optional. + * @param string $prefix The class prefix. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return JTable A JTable object + * + * @since 1.6 */ public function getTable($type = 'Category', $prefix = 'CategoriesTable', $config = array()) { @@ -89,7 +101,9 @@ public function getTable($type = 'Category', $prefix = 'CategoriesTable', $confi * * Note. Calling getState in this method will result in recursion. * - * @since 1.6 + * @return void + * + * @since 1.6 */ protected function populateState() { @@ -100,38 +114,42 @@ protected function populateState() // Load the User state. $pk = (int) JRequest::getInt('id'); - $this->setState($this->getName().'.id', $pk); + $this->setState($this->getName() . '.id', $pk); $extension = JRequest::getCmd('extension', 'com_content'); $this->setState('category.extension', $extension); - $parts = explode('.',$extension); + $parts = explode('.', $extension); // Extract the component name $this->setState('category.component', $parts[0]); // Extract the optional section name - $this->setState('category.section', (count($parts)>1)?$parts[1]:null); + $this->setState('category.section', (count($parts) > 1) ? $parts[1] : null); // Load the parameters. - $params = JComponentHelper::getParams('com_categories'); + $params = JComponentHelper::getParams('com_categories'); $this->setState('params', $params); } /** * Method to get a category. * - * @param integer An optional id of the object to get, otherwise the id from the model state is used. - * @return mixed Category data object on success, false on failure. - * @since 1.6 + * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used. + * + * @return mixed Category data object on success, false on failure. + * + * @since 1.6 */ public function getItem($pk = null) { - if ($result = parent::getItem($pk)) { + if ($result = parent::getItem($pk)) + { // Prime required properties. - if (empty($result->id)) { - $result->parent_id = $this->getState('category.parent_id'); - $result->extension = $this->getState('category.extension'); + if (empty($result->id)) + { + $result->parent_id = $this->getState('category.parent_id'); + $result->extension = $this->getState('category.extension'); } // Convert the metadata field to an array. @@ -141,23 +159,27 @@ public function getItem($pk = null) // Convert the created and modified dates to local user time for display in the form. jimport('joomla.utilities.date'); - $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); + $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset')); - if (intval($result->created_time)) { + if (intval($result->created_time)) + { $date = new JDate($result->created_time); $date->setTimezone($tz); $result->created_time = $date->toSql(true); } - else { + else + { $result->created_time = null; } - if (intval($result->modified_time)) { + if (intval($result->modified_time)) + { $date = new JDate($result->modified_time); $date->setTimezone($tz); $result->modified_time = $date->toSql(true); } - else { + else + { $result->modified_time = null; } } @@ -168,39 +190,44 @@ public function getItem($pk = null) /** * Method to get the row form. * - * @param array $data Data for the form. - * @param boolean $loadData True if the form is to load its own data (default case), false if not. - * @return mixed A JForm object on success, false on failure - * @since 1.6 + * @param array $data Data for the form. + * @param boolean $loadData True if the form is to load its own data (default case), false if not. + * + * @return mixed A JForm object on success, false on failure + * + * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Initialise variables. - $extension = $this->getState('category.extension'); + $extension = $this->getState('category.extension'); // A workaround to get the extension into the model for save requests. - if (empty($extension) && isset($data['extension'])) { - $extension = $data['extension']; - $parts = explode('.',$extension); + if (empty($extension) && isset($data['extension'])) + { + $extension = $data['extension']; + $parts = explode('.', $extension); - $this->setState('category.extension', $extension); - $this->setState('category.component', $parts[0]); - $this->setState('category.section', @$parts[1]); + $this->setState('category.extension', $extension); + $this->setState('category.component', $parts[0]); + $this->setState('category.section', @$parts[1]); } // Get the form. - $form = $this->loadForm('com_categories.category'.$extension, 'category', array('control' => 'jform', 'load_data' => $loadData)); - if (empty($form)) { + $form = $this->loadForm('com_categories.category' . $extension, 'category', array('control' => 'jform', 'load_data' => $loadData)); + if (empty($form)) + { return false; } // Modify the form based on Edit State access controls. - if (empty($data['extension'])) { + if (empty($data['extension'])) + { $data['extension'] = $extension; } - - if (!$this->canEditState((object) $data)) { + if (!$this->canEditState((object) $data)) + { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('published', 'disabled', 'true'); @@ -218,10 +245,11 @@ public function getForm($data = array(), $loadData = true) * A protected method to get the where clause for the reorder * This ensures that the row will be moved relative to a row with the same extension * - * @param JCategoryTable current table instance + * @param JCategoryTable $table Current table instance * - * @return array An array of conditions to add to add to ordering queries. - * @since 1.6 + * @return array An array of conditions to add to add to ordering queries. + * + * @since 1.6 */ protected function getReorderConditions($table) { @@ -231,15 +259,17 @@ protected function getReorderConditions($table) /** * Method to get the data that should be injected in the form. * - * @return mixed The data for the form. - * @since 1.6 + * @return mixed The data for the form. + * + * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. - $data = JFactory::getApplication()->getUserState('com_categories.edit.'.$this->getName().'.data', array()); + $data = JFactory::getApplication()->getUserState('com_categories.edit.' . $this->getName() . '.data', array()); - if (empty($data)) { + if (empty($data)) + { $data = $this->getItem(); } @@ -247,59 +277,69 @@ protected function loadFormData() } /** - * @param object A form object. - * @param mixed The data expected for the form. - * @throws Exception if there is an error loading the form. - * @since 1.6 + * Method to preprocess the form. + * + * @param JForm $form A JForm object. + * @param mixed $data The data expected for the form. + * @param string $groups The name of the plugin group to import. + * + * @return void + * + * @see JFormField + * @since 1.6 + * @throws Exception if there is an error in the form event. */ protected function preprocessForm(JForm $form, $data, $groups = '') { jimport('joomla.filesystem.path'); // Initialise variables. - $lang = JFactory::getLanguage(); - $extension = $this->getState('category.extension'); - $component = $this->getState('category.component'); - $section = $this->getState('category.section'); + $lang = JFactory::getLanguage(); + $extension = $this->getState('category.extension'); + $component = $this->getState('category.component'); + $section = $this->getState('category.section'); // Get the component form if it exists jimport('joomla.filesystem.path'); - $name = 'category'.($section ? ('.'.$section):''); + $name = 'category' . ($section ? ('.' . $section) : ''); // Looking first in the component models/forms folder - $path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/models/forms/$name.xml"); + $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/models/forms/$name.xml"); // Old way: looking in the component folder - if (!file_exists($path)) { - $path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/$name.xml"); + if (!file_exists($path)) + { + $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/$name.xml"); } - if (file_exists($path)) { + if (file_exists($path)) + { $lang->load($component, JPATH_BASE, null, false, false); $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false); - if (!$form->loadFile($path, false)) { + if (!$form->loadFile($path, false)) + { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } } // Try to find the component helper. - $eName = str_replace('com_', '', $component); - $path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/helpers/category.php"); + $eName = str_replace('com_', '', $component); + $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/helpers/category.php"); - if (file_exists($path)) { + if (file_exists($path)) + { require_once $path; - $cName = ucfirst($eName).ucfirst($section).'HelperCategory'; + $cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory'; - if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) { - $lang->load($component, JPATH_BASE, null, false, false) - || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) - || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) - || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false); + if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) + { + $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false); call_user_func_array(array($cName, 'onPrepareForm'), array(&$form)); // Check for an error. - if ($form instanceof Exception) { + if ($form instanceof Exception) + { $this->setError($form->getMessage()); return false; } @@ -307,8 +347,8 @@ protected function preprocessForm(JForm $form, $data, $groups = '') } // Set the access control rules field component value. - $form->setFieldAttribute('rules', 'component', $component); - $form->setFieldAttribute('rules', 'section', $name); + $form->setFieldAttribute('rules', 'component', $component); + $form->setFieldAttribute('rules', 'section', $name); // Trigger the default form events. parent::preprocessForm($form, $data); @@ -317,86 +357,98 @@ protected function preprocessForm(JForm $form, $data, $groups = '') /** * Method to save the form data. * - * @param array The form data. - * @return boolean True on success. - * @since 1.6 + * @param array $data The form data. + * + * @return boolean True on success. + * + * @since 1.6 */ public function save($data) { // Initialise variables; $dispatcher = JDispatcher::getInstance(); - $table = $this->getTable(); - $pk = (!empty($data['id'])) ? $data['id'] : (int)$this->getState($this->getName().'.id'); - $isNew = true; + $table = $this->getTable(); + $pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState($this->getName() . '.id'); + $isNew = true; // Include the content plugins for the on save events. JPluginHelper::importPlugin('content'); // Load the row if saving an existing category. - if ($pk > 0) { + if ($pk > 0) + { $table->load($pk); $isNew = false; } // Set the new parent id if parent id not matched OR while New/Save as Copy . - if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) { + if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) + { $table->setLocation($data['parent_id'], 'last-child'); } // Alter the title for save as copy - if (JRequest::getVar('task') == 'save2copy') { - list($title,$alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']); - $data['title'] = $title; - $data['alias'] = $alias; + if (JRequest::getVar('task') == 'save2copy') + { + list($title, $alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']); + $data['title'] = $title; + $data['alias'] = $alias; } // Bind the data. - if (!$table->bind($data)) { + if (!$table->bind($data)) + { $this->setError($table->getError()); return false; } // Bind the rules. - if (isset($data['rules'])) { + if (isset($data['rules'])) + { $rules = new JAccessRules($data['rules']); $table->setRules($rules); } // Check the data. - if (!$table->check()) { + if (!$table->check()) + { $this->setError($table->getError()); return false; } // Trigger the onContentBeforeSave event. - $result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, &$table, $isNew)); - if (in_array(false, $result, true)) { + $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew)); + if (in_array(false, $result, true)) + { $this->setError($table->getError()); return false; } // Store the data. - if (!$table->store()) { + if (!$table->store()) + { $this->setError($table->getError()); return false; } // Trigger the onContentAfterSave event. - $dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, &$table, $isNew)); + $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew)); // Rebuild the path for the category: - if (!$table->rebuildPath($table->id)) { + if (!$table->rebuildPath($table->id)) + { $this->setError($table->getError()); return false; } // Rebuild the paths of the category's children: - if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) { + if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) + { $this->setError($table->getError()); return false; } - $this->setState($this->getName().'.id', $table->id); + $this->setState($this->getName() . '.id', $table->id); // Clear the cache $this->cleanCache(); @@ -434,15 +486,17 @@ function publish(&$pks, $value = 1) /** * Method rebuild the entire nested set tree. * - * @return boolean False on failure or error, true otherwise. - * @since 1.6 + * @return boolean False on failure or error, true otherwise. + * + * @since 1.6 */ public function rebuild() { - // Get an instance of the table obejct. + // Get an instance of the table object. $table = $this->getTable(); - if (!$table->rebuild()) { + if (!$table->rebuild()) + { $this->setError($table->getError()); return false; } @@ -458,15 +512,20 @@ public function rebuild() * First we save the new order values in the lft values of the changed ids. * Then we invoke the table rebuild to implement the new ordering. * - * @return boolean false on failuer or error, true otherwise - * @since 1.6 + * @param array $idArray An array of primary key ids. + * @param integer $lft_array The lft value + * + * @return boolean False on failure or error, True otherwise + * + * @since 1.6 */ public function saveorder($idArray = null, $lft_array = null) { // Get an instance of the table object. $table = $this->getTable(); - if (!$table->saveorder($idArray, $lft_array)) { + if (!$table->saveorder($idArray, $lft_array)) + { $this->setError($table->getError()); return false; } @@ -474,84 +533,54 @@ public function saveorder($idArray = null, $lft_array = null) // Clear the cache $this->cleanCache(); - return true; - - } - - /** - * Batch access level changes for a group of rows. - * - * @param int The new value matching an Asset Group ID. - * @param array An array of row IDs. - * @return booelan True if successful, false otherwise and internal error is set. - * @since 1.6 - */ - protected function batchAccess($value, $pks) - { - // Check that user has edit permission for every category being changed - // Note that the entire batch operation fails if any category lacks edit permission - $user = JFactory::getUser(); - $extension = JRequest::getWord('extension'); - foreach ($pks as $pk) { - if (!$user->authorise('core.edit', $extension.'.category.'.$pk)) { - // Error since user cannot edit this category - $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_EDIT')); - return false; - } - } - $table = $this->getTable(); - foreach ($pks as $pk) { - $table->reset(); - $table->load($pk); - $table->access = (int) $value; - if (!$table->store()) { - $this->setError($table->getError()); - return false; - } - } - return true; } /** * Batch copy categories to a new category. * - * @param int $value The new category or sub-item. - * @param array $pks An array of row IDs. + * @param integer $value The new category. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. * - * @return mixed An array of new IDs on success, boolean false on failure. - * @since 1.6 + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 1.6 */ - protected function batchCopy($value, $pks) + protected function batchCopy($value, $pks, $contexts) { // $value comes as {parent_id}.{extension} - $parts = explode('.', $value); - $parentId = (int) JArrayHelper::getValue($parts, 0, 1); + $parts = explode('.', $value); + $parentId = (int) JArrayHelper::getValue($parts, 0, 1); - $table = $this->getTable(); - $db = $this->getDbo(); - $user = JFactory::getUser(); - $extension = JRequest::getWord('extension'); - $i = 0; + $table = $this->getTable(); + $db = $this->getDbo(); + $user = JFactory::getUser(); + $extension = JFactory::getApplication()->input->get('extension', '', 'word'); + $i = 0; // Check that the parent exists - if ($parentId) { - if (!$table->load($parentId)) { - if ($error = $table->getError()) { + if ($parentId) + { + if (!$table->load($parentId)) + { + if ($error = $table->getError()) + { // Fatal error $this->setError($error); return false; } - else { + else + { // Non-fatal error $this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND')); $parentId = 0; } } // Check that user has create permission for parent category - $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : - $user->authorise('core.create', $extension.'.category.'.$parentId); - if (!$canCreate) { + $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : $user->authorise('core.create', $extension . '.category.' . $parentId); + if (!$canCreate) + { // Error since user cannot create in parent category $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; @@ -559,13 +588,16 @@ protected function batchCopy($value, $pks) } // If the parent is 0, set it to the ID of the root item in the tree - if (empty($parentId)) { - if (!$parentId = $table->getRootId()) { + if (empty($parentId)) + { + if (!$parentId = $table->getRootId()) + { $this->setError($db->getErrorMsg()); return false; } // Make sure we can create in root - elseif (!$user->authorise('core.create', $extension)) { + elseif (!$user->authorise('core.create', $extension)) + { $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; } @@ -575,13 +607,14 @@ protected function batchCopy($value, $pks) $parents = array(); // Calculate the emergency stop count as a precaution against a runaway loop bug - $db->setQuery( - 'SELECT COUNT(id)' . - ' FROM #__categories' - ); + $query = $db->getQuery(true); + $query->select('COUNT(id)'); + $query->from($db->quoteName('#__categories')); + $db->setQuery($query); $count = $db->loadResult(); - if ($error = $db->getErrorMsg()) { + if ($error = $db->getErrorMsg()) + { $this->setError($error); return false; } @@ -595,13 +628,16 @@ protected function batchCopy($value, $pks) $table->reset(); // Check that the row actually exists - if (!$table->load($pk)) { - if ($error = $table->getError()) { + if (!$table->load($pk)) + { + if ($error = $table->getError()) + { // Fatal error $this->setError($error); return false; } - else { + else + { // Not fatal error $this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; @@ -609,49 +645,52 @@ protected function batchCopy($value, $pks) } // Copy is a bit tricky, because we also need to copy the children - $db->setQuery( - 'SELECT id' . - ' FROM #__categories' . - ' WHERE lft > '.(int) $table->lft.' AND rgt < '.(int) $table->rgt - ); - $childIds = $db->loadResultArray(); + $query->clear(); + $query->select('id'); + $query->from($db->quoteName('#__categories')); + $query->where('lft > ' . (int) $table->lft); + $query->where('rgt < ' . (int) $table->rgt); + $db->setQuery($query); + $childIds = $db->loadColumn(); // Add child ID's to the array only if they aren't already there. foreach ($childIds as $childId) { - if (!in_array($childId, $pks)) { + if (!in_array($childId, $pks)) + { array_push($pks, $childId); } } // Make a copy of the old ID and Parent ID - $oldId = $table->id; - $oldParentId = $table->parent_id; + $oldId = $table->id; + $oldParentId = $table->parent_id; // Reset the id because we are making a copy. - $table->id = 0; + $table->id = 0; // If we a copying children, the Old ID will turn up in the parents list // otherwise it's a new top level item - $table->parent_id = isset($parents[$oldParentId]) ? $parents[$oldParentId] : $parentId; + $table->parent_id = isset($parents[$oldParentId]) ? $parents[$oldParentId] : $parentId; // Set the new location in the tree for the node. $table->setLocation($table->parent_id, 'last-child'); // TODO: Deal with ordering? //$table->ordering = 1; - $table->level = null; - $table->asset_id = null; - $table->lft = null; - $table->rgt = null; + $table->level = null; + $table->asset_id = null; + $table->lft = null; + $table->rgt = null; // Alter the title & alias - list($title,$alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title); - $table->title = $title; - $table->alias = $alias; + list($title, $alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title); + $table->title = $title; + $table->alias = $alias; // Store the row. - if (!$table->store()) { + if (!$table->store()) + { $this->setError($table->getError()); return false; } @@ -660,7 +699,7 @@ protected function batchCopy($value, $pks) $newId = $table->get('id'); // Add the new ID to the array - $newIds[$i] = $newId; + $newIds[$i] = $newId; $i++; // Now we log the old 'parent' to the new 'parent' @@ -669,13 +708,15 @@ protected function batchCopy($value, $pks) } // Rebuild the hierarchy. - if (!$table->rebuild()) { + if (!$table->rebuild()) + { $this->setError($table->getError()); return false; } // Rebuild the tree path. - if (!$table->rebuildPath($table->id)) { + if (!$table->rebuildPath($table->id)) + { $this->setError($table->getError()); return false; } @@ -686,40 +727,47 @@ protected function batchCopy($value, $pks) /** * Batch move categories to a new category. * - * @param int $value The new category or sub-item. - * @param array $pks An array of row IDs. + * @param integer $value The new category ID. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. * - * @return booelan True if successful, false otherwise and internal error is set. - * @since 1.6 + * @return boolean True on success. + * + * @since 1.6 */ - protected function batchMove($value, $pks) + protected function batchMove($value, $pks, $contexts) { - $parentId = (int) $value; + $parentId = (int) $value; - $table = $this->getTable(); - $db = $this->getDbo(); - $user = JFactory::getUser(); - $extension = JRequest::getWord('extension'); + $table = $this->getTable(); + $db = $this->getDbo(); + $query = $db->getQuery(true); + $user = JFactory::getUser(); + $extension = JFactory::getApplication()->input->get('extension', '', 'word'); // Check that the parent exists. - if ($parentId) { - if (!$table->load($parentId)) { - if ($error = $table->getError()) { + if ($parentId) + { + if (!$table->load($parentId)) + { + if ($error = $table->getError()) + { // Fatal error $this->setError($error); return false; } - else { + else + { // Non-fatal error $this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND')); $parentId = 0; } } // Check that user has create permission for parent category - $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : - $user->authorise('core.create', $extension.'.category.'.$parentId); - if (!$canCreate) { + $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : $user->authorise('core.create', $extension . '.category.' . $parentId); + if (!$canCreate) + { // Error since user cannot create in parent category $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; @@ -727,8 +775,10 @@ protected function batchMove($value, $pks) // Check that user has edit permission for every category being moved // Note that the entire batch operation fails if any category lacks edit permission - foreach ($pks as $pk) { - if (!$user->authorise('core.edit', $extension.'.category.'.$pk)) { + foreach ($pks as $pk) + { + if (!$user->authorise('core.edit', $extension . '.category.' . $pk)) + { // Error since user cannot edit this category $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_EDIT')); return false; @@ -736,7 +786,6 @@ protected function batchMove($value, $pks) } } - // We are going to store all the children and just move the category $children = array(); @@ -744,13 +793,16 @@ protected function batchMove($value, $pks) foreach ($pks as $pk) { // Check that the row actually exists - if (!$table->load($pk)) { - if ($error = $table->getError()) { + if (!$table->load($pk)) + { + if ($error = $table->getError()) + { // Fatal error $this->setError($error); return false; } - else { + else + { // Not fatal error $this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; @@ -761,36 +813,42 @@ protected function batchMove($value, $pks) $table->setLocation($parentId, 'last-child'); // Check if we are moving to a different parent - if ($parentId != $table->parent_id) { + if ($parentId != $table->parent_id) + { // Add the child node ids to the children array. - $db->setQuery( - 'SELECT '.$db->quoteName(id).' . - FROM '.$db->quoteName("#__categories").' WHERE $db->quoteName(lft) BETWEEN '.(int) $table->lft.' AND '.(int) $table->rgt - ); - $children = array_merge($children, (array) $db->loadResultArray()); + $query->clear(); + $query->select('id'); + $query->from($db->quoteName('#__categories')); + $query->where($db->quoteName('lft' ) .' BETWEEN ' . (int) $table->lft . ' AND ' . (int) $table->rgt); + $db->setQuery($query); + $children = array_merge($children, (array) $db->loadColumn()); } // Store the row. - if (!$table->store()) { + if (!$table->store()) + { $this->setError($table->getError()); return false; } // Rebuild the tree path. - if (!$table->rebuildPath()) { + if (!$table->rebuildPath()) + { $this->setError($table->getError()); return false; } } // Process the child rows - if (!empty($children)) { + if (!empty($children)) + { // Remove any duplicates and sanitize ids. $children = array_unique($children); JArrayHelper::toInteger($children); // Check for a database error. - if ($db->getErrorNum()) { + if ($db->getErrorNum()) + { $this->setError($db->getErrorMsg()); return false; } @@ -827,11 +885,12 @@ protected function cleanCache($group = null, $client_id = 0) /** * Method to change the title & alias. * - * @param int The value of the parent category ID. - * @param string The value of the category alias. - * @param string The value of the category title. + * @param integer $parent_id The id of the parent. + * @param string $alias The alias. + * @param string $title The title. + * + * @return array Contains the modified title and alias. * - * @return array Contains title and alias. * @since 1.7 */ protected function generateNewTitle($parent_id, $alias, $title) diff --git a/administrator/components/com_contact/controllers/contact.php b/administrator/components/com_contact/controllers/contact.php index 1686881c58891..30c8eab0503af 100644 --- a/administrator/components/com_contact/controllers/contact.php +++ b/administrator/components/com_contact/controllers/contact.php @@ -1,10 +1,10 @@ authorise('core.create', $this->option.'.category.'.$categoryId); + $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } - if ($allow === null) { + if ($allow === null) + { // In the absense of better information, revert to the component permissions. return parent::allowAdd($data); } - else { + else + { return $allow; } } @@ -51,35 +55,40 @@ protected function allowAdd($data = array()) /** * Method override to check if you can edit an existing record. * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key. + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean * - * @return boolean - * @since 1.6 + * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; - $user = JFactory::getUser(); - $userId = $user->get('id'); - $categoryId = (int) isset($data['catid']) ? $data['catid'] : 0; + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $user = JFactory::getUser(); + $userId = $user->get('id'); + $categoryId = (int) isset($data['catid']) ? $data['catid'] : 0; // Check general edit permission first. - if ($user->authorise('core.edit', $this->option.'.category.'.$categoryId)) { + if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId)) + { return true; } // Fallback on edit.own. // First test if the permission is available. - if ($user->authorise('core.edit.own', $this->option.'.category.'.$categoryId)) { + if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId)) + { // Now test the owner is the user. - $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; - if (empty($ownerId) && $recordId) { + $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; + if (empty($ownerId) && $recordId) + { // Need to do a lookup from the model. - $record = $this->getModel()->getItem($recordId); + $record = $this->getModel()->getItem($recordId); - if (empty($record)) { + if (empty($record)) + { return false; } @@ -87,7 +96,8 @@ protected function allowEdit($data = array(), $key = 'id') } // If the owner matches 'me' then do the test. - if ($ownerId == $userId) { + if ($ownerId == $userId) + { return true; } } @@ -95,4 +105,26 @@ protected function allowEdit($data = array(), $key = 'id') // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } + + /** + * Method to run batch operations. + * + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 2.5 + */ + public function batch($model = null) + { + JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('Contact', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_contact&view=contacts' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } } diff --git a/administrator/components/com_contact/models/contact.php b/administrator/components/com_contact/models/contact.php index 5233a2371ac3e..a22b9c50800e3 100644 --- a/administrator/components/com_contact/models/contact.php +++ b/administrator/components/com_contact/models/contact.php @@ -21,6 +21,265 @@ */ class ContactModelContact extends JModelAdmin { + /** + * Method to perform batch operations on an item or a set of items. + * + * @param array $commands An array of commands to perform. + * @param array $pks An array of item ids. + * @param array $contexts An array of item contexts. + * + * @return boolean Returns true on success, false on failure. + * + * @since 2.5 + */ + public function batch($commands, $pks, $contexts) + { + // Sanitize user ids. + $pks = array_unique($pks); + JArrayHelper::toInteger($pks); + + // Remove any values of zero. + if (array_search(0, $pks, true)) + { + unset($pks[array_search(0, $pks, true)]); + } + + if (empty($pks)) + { + $this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED')); + return false; + } + + $done = false; + + if (!empty($commands['category_id'])) + { + $cmd = JArrayHelper::getValue($commands, 'move_copy', 'c'); + + if ($cmd == 'c') + { + $result = $this->batchCopy($commands['category_id'], $pks, $contexts); + if (is_array($result)) + { + $pks = $result; + } + else + { + return false; + } + } + elseif ($cmd == 'm' && !$this->batchMove($commands['category_id'], $pks, $contexts)) + { + return false; + } + $done = true; + } + + if (!empty($commands['assetgroup_id'])) + { + if (!$this->batchAccess($commands['assetgroup_id'], $pks, $contexts)) + { + return false; + } + + $done = true; + } + + if (!empty($commands['language_id'])) + { + if (!$this->batchLanguage($commands['language_id'], $pks, $contexts)) + { + return false; + } + + $done = true; + } + + if (strlen($commands['user_id']) > 0) + { + if (!$this->batchUser($commands['user_id'], $pks, $contexts)) + { + return false; + } + + $done = true; + } + + if (!$done) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); + return false; + } + + // Clear the cache + $this->cleanCache(); + + return true; + } + + /** + * Batch copy items to a new category or current. + * + * @param integer $value The new category. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 11.1 + */ + protected function batchCopy($value, $pks, $contexts) + { + $categoryId = (int) $value; + + $table = $this->getTable(); + $i = 0; + + // Check that the category exists + if ($categoryId) + { + $categoryTable = JTable::getInstance('Category'); + if (!$categoryTable->load($categoryId)) + { + if ($error = $categoryTable->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + } + } + + if (empty($categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + + // Check that the user has create permission for the component + $user = JFactory::getUser(); + if (!$user->authorise('core.create', 'com_contact.category.' . $categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); + return false; + } + + // Parent exists so we let's proceed + while (!empty($pks)) + { + // Pop the first ID off the stack + $pk = array_shift($pks); + + $table->reset(); + + // Check that the row actually exists + if (!$table->load($pk)) + { + if ($error = $table->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + // Alter the title & alias + $data = $this->generateNewTitle($categoryId, $table->alias, $table->name); + $table->name = $data['0']; + $table->alias = $data['1']; + + // Reset the ID because we are making a copy + $table->id = 0; + + // New category ID + $table->catid = $categoryId; + + // TODO: Deal with ordering? + //$table->ordering = 1; + + // Check the row. + if (!$table->check()) + { + $this->setError($table->getError()); + return false; + } + + // Store the row. + if (!$table->store()) + { + $this->setError($table->getError()); + return false; + } + + // Get the new item ID + $newId = $table->get('id'); + + // Add the new ID to the array + $newIds[$i] = $newId; + $i++; + } + + // Clean the cache + $this->cleanCache(); + + return $newIds; + } + + /** + * Batch change a linked user. + * + * @param integer $value The new value matching a User ID. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 2.5 + */ + protected function batchUser($value, $pks, $contexts) + { + // Set the variables + $user = JFactory::getUser(); + $table = $this->getTable(); + + foreach ($pks as $pk) + { + if ($user->authorise('core.edit', $contexts[$pk])) + { + $table->reset(); + $table->load($pk); + $table->user_id = (int) $value; + + if (!$table->store()) + { + $this->setError($table->getError()); + return false; + } + } + else + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); + return false; + } + } + + // Clean the cache + $this->cleanCache(); + + return true; + } + /** * Method to test whether a record can be deleted. * diff --git a/administrator/components/com_contact/views/contacts/tmpl/default.php b/administrator/components/com_contact/views/contacts/tmpl/default.php index cdeef23816c07..53953a8d6630a 100644 --- a/administrator/components/com_contact/views/contacts/tmpl/default.php +++ b/administrator/components/com_contact/views/contacts/tmpl/default.php @@ -1,10 +1,10 @@ + + loadTemplate('batch'); ?> +
diff --git a/administrator/components/com_contact/views/contacts/tmpl/default_batch.php b/administrator/components/com_contact/views/contacts/tmpl/default_batch.php new file mode 100644 index 0000000000000..6dbda45847c01 --- /dev/null +++ b/administrator/components/com_contact/views/contacts/tmpl/default_batch.php @@ -0,0 +1,32 @@ +state->get('filter.published'); +?> +
+ +

+ + + + + = 0) : ?> + + + + + +
diff --git a/administrator/components/com_content/controllers/article.php b/administrator/components/com_content/controllers/article.php index 2ee454a112aab..6a8ae1a3e82f2 100644 --- a/administrator/components/com_content/controllers/article.php +++ b/administrator/components/com_content/controllers/article.php @@ -1,10 +1,10 @@ view_list = 'featured'; $this->view_item = 'article&return=featured'; } @@ -42,28 +42,32 @@ function __construct($config = array()) /** * Method override to check if you can add a new record. * - * @param array An array of input data. + * @param array $data An array of input data. * - * @return boolean - * @since 1.6 + * @return boolean + * + * @since 1.6 */ protected function allowAdd($data = array()) { // Initialise variables. - $user = JFactory::getUser(); - $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int'); - $allow = null; + $user = JFactory::getUser(); + $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int'); + $allow = null; - if ($categoryId) { + if ($categoryId) + { // If the category has been passed in the data or URL check it. - $allow = $user->authorise('core.create', 'com_content.category.'.$categoryId); + $allow = $user->authorise('core.create', 'com_content.category.' . $categoryId); } - if ($allow === null) { + if ($allow === null) + { // In the absense of better information, revert to the component permissions. return parent::allowAdd(); } - else { + else + { return $allow; } } @@ -71,34 +75,39 @@ protected function allowAdd($data = array()) /** * Method override to check if you can edit an existing record. * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key. + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. * - * @return boolean - * @since 1.6 + * @return boolean + * + * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; - $user = JFactory::getUser(); - $userId = $user->get('id'); + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $user = JFactory::getUser(); + $userId = $user->get('id'); // Check general edit permission first. - if ($user->authorise('core.edit', 'com_content.article.'.$recordId)) { + if ($user->authorise('core.edit', 'com_content.article.' . $recordId)) + { return true; } // Fallback on edit.own. // First test if the permission is available. - if ($user->authorise('core.edit.own', 'com_content.article.'.$recordId)) { + if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId)) + { // Now test the owner is the user. - $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; - if (empty($ownerId) && $recordId) { + $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0; + if (empty($ownerId) && $recordId) + { // Need to do a lookup from the model. - $record = $this->getModel()->getItem($recordId); + $record = $this->getModel()->getItem($recordId); - if (empty($record)) { + if (empty($record)) + { return false; } @@ -106,7 +115,8 @@ protected function allowEdit($data = array(), $key = 'id') } // If the owner matches 'me' then do the test. - if ($ownerId == $userId) { + if ($ownerId == $userId) + { return true; } } @@ -118,18 +128,21 @@ protected function allowEdit($data = array(), $key = 'id') /** * Method to run batch operations. * - * @return void - * @since 1.6 + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 1.6 */ - public function batch($model) + public function batch($model = null) { JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model - $model = $this->getModel('Article', '', array()); + $model = $this->getModel('Article', '', array()); // Preset the redirect - $this->setRedirect(JRoute::_('index.php?option=com_content&view=articles'.$this->getRedirectToListAppend(), false)); + $this->setRedirect(JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false)); return parent::batch($model); } diff --git a/administrator/components/com_content/models/article.php b/administrator/components/com_content/models/article.php index e36b8b0ea7560..4c307950e141e 100644 --- a/administrator/components/com_content/models/article.php +++ b/administrator/components/com_content/models/article.php @@ -29,6 +29,140 @@ class ContentModelArticle extends JModelAdmin */ protected $text_prefix = 'COM_CONTENT'; + /** + * Batch copy items to a new category or current. + * + * @param integer $value The new category. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 11.1 + */ + protected function batchCopy($value, $pks, $contexts) + { + $categoryId = (int) $value; + + $table = $this->getTable(); + $i = 0; + + // Check that the category exists + if ($categoryId) + { + $categoryTable = JTable::getInstance('Category'); + if (!$categoryTable->load($categoryId)) + { + if ($error = $categoryTable->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + } + } + + if (empty($categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + + // Check that the user has create permission for the component + $extension = JFactory::getApplication()->input->get('option', ''); + $user = JFactory::getUser(); + if (!$user->authorise('core.create', $extension . '.category.' . $categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); + return false; + } + + // Parent exists so we let's proceed + while (!empty($pks)) + { + // Pop the first ID off the stack + $pk = array_shift($pks); + + $table->reset(); + + // Check that the row actually exists + if (!$table->load($pk)) + { + if ($error = $table->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + // Alter the title & alias + $data = $this->generateNewTitle($categoryId, $table->alias, $table->title); + $table->title = $data['0']; + $table->alias = $data['1']; + + // Reset the ID because we are making a copy + $table->id = 0; + + // New category ID + $table->catid = $categoryId; + + // TODO: Deal with ordering? + //$table->ordering = 1; + + // Get the featured state + $featured = $table->featured; + + // Check the row. + if (!$table->check()) + { + $this->setError($table->getError()); + return false; + } + + // Store the row. + if (!$table->store()) + { + $this->setError($table->getError()); + return false; + } + + // Get the new item ID + $newId = $table->get('id'); + + // Add the new ID to the array + $newIds[$i] = $newId; + $i++; + + // Check if the article was featured and update the #__content_frontpage table + if ($featured == 1) + { + $db = $this->getDbo(); + $query = $db->getQuery(true); + $query->insert($db->quoteName('#__content_frontpage')); + $query->values($newId . ', 0'); + $db->setQuery($query); + $db->query(); + } + } + + // Clean the cache + $this->cleanCache(); + + return $newIds; + } + /** * Method to test whether a record can be deleted. * diff --git a/administrator/components/com_content/views/articles/tmpl/default_batch.php b/administrator/components/com_content/views/articles/tmpl/default_batch.php index deb23652334e0..ec0d4f5bc33a3 100644 --- a/administrator/components/com_content/views/articles/tmpl/default_batch.php +++ b/administrator/components/com_content/views/articles/tmpl/default_batch.php @@ -1,10 +1,10 @@ = 0) : ?> - + + + diff --git a/administrator/components/com_modules/views/modules/view.html.php b/administrator/components/com_modules/views/modules/view.html.php index 412c231eaff6a..b94b35c4818c4 100644 --- a/administrator/components/com_modules/views/modules/view.html.php +++ b/administrator/components/com_modules/views/modules/view.html.php @@ -47,6 +47,8 @@ public function display($tpl = null) } $this->addToolbar(); + // Include the component HTML helpers. + JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); parent::display($tpl); } diff --git a/administrator/components/com_newsfeeds/controllers/newsfeed.php b/administrator/components/com_newsfeeds/controllers/newsfeed.php index 03168d6cf763b..b6060c4f5df93 100644 --- a/administrator/components/com_newsfeeds/controllers/newsfeed.php +++ b/administrator/components/com_newsfeeds/controllers/newsfeed.php @@ -1,10 +1,13 @@ authorise('core.create', $this->option.'.category.'.$categoryId); + $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } - if ($allow === null) { - // In the absense of better information, revert to the component permissions. + if ($allow === null) + { + // In the absence of better information, revert to the component permissions. return parent::allowAdd($data); - } else { + } + else + { return $allow; } } @@ -50,29 +58,56 @@ protected function allowAdd($data = array()) /** * Method to check if you can edit a record. * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key. + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. + * + * @return boolean * - * @return boolean - * @since 1.6 + * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. - $user = JFactory::getUser(); - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $user = JFactory::getUser(); + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $categoryId = 0; - if ($recordId) { + if ($recordId) + { $categoryId = (int) $this->getModel()->getItem($recordId)->catid; } - if ($categoryId) { + if ($categoryId) + { // The category has been set. Check the category permissions. - return $user->authorise('core.edit', $this->option.'.category.'.$categoryId); - } else { + return $user->authorise('core.edit', $this->option . '.category.' . $categoryId); + } + else + { // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } } + + /** + * Method to run batch operations. + * + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 2.5 + */ + public function batch($model = null) + { + JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('Newsfeed', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_newsfeeds&view=newsfeeds' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } } diff --git a/administrator/components/com_newsfeeds/models/newsfeed.php b/administrator/components/com_newsfeeds/models/newsfeed.php index a9167b88972e2..f1f9571994363 100644 --- a/administrator/components/com_newsfeeds/models/newsfeed.php +++ b/administrator/components/com_newsfeeds/models/newsfeed.php @@ -25,6 +25,125 @@ class NewsfeedsModelNewsfeed extends JModelAdmin */ protected $text_prefix = 'COM_NEWSFEEDS'; + /** + * Batch copy items to a new category or current. + * + * @param integer $value The new category. + * @param array $pks An array of row IDs. + * @param array $contexts An array of item contexts. + * + * @return mixed An array of new IDs on success, boolean false on failure. + * + * @since 11.1 + */ + protected function batchCopy($value, $pks, $contexts) + { + $categoryId = (int) $value; + + $table = $this->getTable(); + $i = 0; + + // Check that the category exists + if ($categoryId) + { + $categoryTable = JTable::getInstance('Category'); + if (!$categoryTable->load($categoryId)) + { + if ($error = $categoryTable->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + } + } + + if (empty($categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); + return false; + } + + // Check that the user has create permission for the component + $user = JFactory::getUser(); + if (!$user->authorise('core.create', 'com_newsfeeds.category.' . $categoryId)) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); + return false; + } + + // Parent exists so we let's proceed + while (!empty($pks)) + { + // Pop the first ID off the stack + $pk = array_shift($pks); + + $table->reset(); + + // Check that the row actually exists + if (!$table->load($pk)) + { + if ($error = $table->getError()) + { + // Fatal error + $this->setError($error); + return false; + } + else + { + // Not fatal error + $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); + continue; + } + } + + // Alter the title & alias + $data = $this->generateNewTitle($categoryId, $table->alias, $table->name); + $table->name = $data['0']; + $table->alias = $data['1']; + + // Reset the ID because we are making a copy + $table->id = 0; + + // New category ID + $table->catid = $categoryId; + + // TODO: Deal with ordering? + //$table->ordering = 1; + + // Check the row. + if (!$table->check()) + { + $this->setError($table->getError()); + return false; + } + + // Store the row. + if (!$table->store()) + { + $this->setError($table->getError()); + return false; + } + + // Get the new item ID + $newId = $table->get('id'); + + // Add the new ID to the array + $newIds[$i] = $newId; + $i++; + } + + // Clean the cache + $this->cleanCache(); + + return $newIds; + } + /** * Method to test whether a record can be deleted. * diff --git a/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default.php b/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default.php index e4ae5e1cd5c8f..45026305549fc 100644 --- a/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default.php +++ b/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default.php @@ -173,6 +173,9 @@ + + loadTemplate('batch'); ?> +
diff --git a/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default_batch.php b/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default_batch.php new file mode 100644 index 0000000000000..a3463784e4397 --- /dev/null +++ b/administrator/components/com_newsfeeds/views/newsfeeds/tmpl/default_batch.php @@ -0,0 +1,31 @@ +state->get('filter.published'); +?> +
+ +

+ + + + = 0) : ?> + + + + + +
diff --git a/administrator/components/com_users/controllers/user.php b/administrator/components/com_users/controllers/user.php index 5accd301ab02d..3e810cd60448f 100644 --- a/administrator/components/com_users/controllers/user.php +++ b/administrator/components/com_users/controllers/user.php @@ -1,10 +1,10 @@ authorise('core.admin')) { + if (!JFactory::getUser()->authorise('core.admin')) + { return false; } } @@ -51,20 +54,48 @@ protected function allowEdit($data = array(), $key = 'id') return parent::allowEdit($data, $key); } + /** + * Method to run batch operations. + * + * @param object $model The model. + * + * @return boolean True on success, false on failure + * + * @since 2.5 + */ + public function batch($model = null) + { + JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + // Set the model + $model = $this->getModel('User', '', array()); + + // Preset the redirect + $this->setRedirect(JRoute::_('index.php?option=com_users&view=users' . $this->getRedirectToListAppend(), false)); + + return parent::batch($model); + } + /** * Overrides parent save method to check the submitted passwords match. * - * @return mixed Boolean or JError. - * @since 1.6 + * @param string $key The name of the primary key of the URL variable. + * @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions). + * + * @return boolean True if successful, false otherwise. + * + * @since 1.6 */ public function save($key = null, $urlVar = null) { $data = JRequest::getVar('jform', array(), 'post', 'array'); // TODO: JForm should really have a validation handler for this. - if (isset($data['password']) && isset($data['password2'])) { + if (isset($data['password']) && isset($data['password2'])) + { // Check the passwords match. - if ($data['password'] != $data['password2']) { + if ($data['password'] != $data['password2']) + { $this->setMessage(JText::_('JLIB_USER_ERROR_PASSWORD_NOT_MATCH'), 'warning'); $this->setRedirect(JRoute::_('index.php?option=com_users&view=user&layout=edit', false)); } diff --git a/administrator/components/com_users/controllers/users.php b/administrator/components/com_users/controllers/users.php index 430a25aabf389..f0532f6c6a551 100644 --- a/administrator/components/com_users/controllers/users.php +++ b/administrator/components/com_users/controllers/users.php @@ -1,8 +1,10 @@ registerTask('block', 'changeBlock'); $this->registerTask('unblock', 'changeBlock'); } + /** * Proxy for getModel. * + * @param string $name The model name. Optional. + * @param string $prefix The class prefix. Optional. + * @param array $config Configuration array for model. Optional. + * + * @return object The model. + * * @since 1.6 */ public function getModel($name = 'User', $prefix = 'UsersModel', $config = array('ignore_request' => true)) @@ -50,9 +62,11 @@ public function getModel($name = 'User', $prefix = 'UsersModel', $config = array } /** - * Method to remove a record. + * Method to change the block status on a record. * - * @since 1.6 + * @return void + * + * @since 1.6 */ public function changeBlock() { @@ -65,19 +79,28 @@ public function changeBlock() $task = $this->getTask(); $value = JArrayHelper::getValue($values, $task, 0, 'int'); - if (empty($ids)) { + if (empty($ids)) + { JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED')); - } else { + } + else + { // Get the model. $model = $this->getModel(); // Change the state of the records. - if (!$model->block($ids, $value)) { + if (!$model->block($ids, $value)) + { JError::raiseWarning(500, $model->getError()); - } else { - if ($value == 1){ + } + else + { + if ($value == 1) + { $this->setMessage(JText::plural('COM_USERS_N_USERS_BLOCKED', count($ids))); - } elseif ($value == 0){ + } + elseif ($value == 0) + { $this->setMessage(JText::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids))); } } @@ -87,9 +110,11 @@ public function changeBlock() } /** - * Method to remove a record. + * Method to activate a record. * - * @since 1.6 + * @return void + * + * @since 1.6 */ public function activate() { @@ -99,59 +124,26 @@ public function activate() // Initialise variables. $ids = JRequest::getVar('cid', array(), '', 'array'); - if (empty($ids)) { + if (empty($ids)) + { JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED')); - } else { + } + else + { // Get the model. $model = $this->getModel(); // Change the state of the records. - if (!$model->activate($ids)) { + if (!$model->activate($ids)) + { JError::raiseWarning(500, $model->getError()); - } else { + } + else + { $this->setMessage(JText::plural('COM_USERS_N_USERS_ACTIVATED', count($ids))); } } $this->setRedirect('index.php?option=com_users&view=users'); } - - /** - * Method to run batch opterations. - * - * @return void - * @since 1.6 - */ - function batch() - { - // Check for request forgeries. - JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); - - // Initialise variables. - $app = JFactory::getApplication(); - $model = $this->getModel('User'); - $vars = JRequest::getVar('batch', array(), 'post', 'array'); - $cid = JRequest::getVar('cid', array(), 'post', 'array'); - - // Sanitize user ids. - $cid = array_unique($cid); - JArrayHelper::toInteger($cid); - - // Remove any values of zero. - if (array_search(0, $cid, true)) { - unset($cid[array_search(0, $cid, true)]); - } - - // Attempt to run the batch operation. - if (!$model->batch($vars, $cid)) { - // Batch operation failed, go back to the users list and display a notice. - $message = JText::sprintf('COM_USERS_USER_BATCH_FAILED', $model->getError()); - $this->setRedirect('index.php?option=com_users&view=users', $message, 'error'); - return false; - } - - $message = JText::_('COM_USERS_USER_BATCH_SUCCESS'); - $this->setRedirect('index.php?option=com_users&view=users', $message); - return true; - } } diff --git a/administrator/components/com_users/models/user.php b/administrator/components/com_users/models/user.php index 6a213a8ad734f..c84fb37ca9340 100644 --- a/administrator/components/com_users/models/user.php +++ b/administrator/components/com_users/models/user.php @@ -1,8 +1,10 @@ loadForm('com_users.user', 'user', array('control' => 'jform', 'load_data' => $loadData)); - if (empty($form)) { + if (empty($form)) + { return false; } @@ -83,15 +90,17 @@ public function getForm($data = array(), $loadData = true) /** * Method to get the data that should be injected in the form. * - * @return mixed The data for the form. - * @since 1.6 + * @return mixed The data for the form. + * + * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_users.edit.user.data', array()); - if (empty($data)) { + if (empty($data)) + { $data = $this->getItem(); } @@ -104,7 +113,8 @@ protected function loadFormData() $results = $dispatcher->trigger('onContentPrepareData', array('com_users.profile', $data)); // Check for errors encountered while preparing the data. - if (count($results) && in_array(false, $results, true)) { + if (count($results) && in_array(false, $results, true)) + { $this->setError($dispatcher->getError()); } @@ -114,12 +124,14 @@ protected function loadFormData() /** * Override JModelAdmin::preprocessForm to ensure the correct plugin group is loaded. * - * @param object $form A form object. - * @param mixed $data The data expected for the form. - * @param string $group The name of the plugin group to import (defaults to "content"). + * @param JForm $form A JForm object. + * @param mixed $data The data expected for the form. + * @param string $group The name of the plugin group to import (defaults to "content"). * - * @throws Exception if there is an error in the form event. - * @since 1.6 + * @return void + * + * @since 1.6 + * @throws Exception if there is an error in the form event. */ protected function preprocessForm(JForm $form, $data, $group = 'user') { @@ -129,10 +141,11 @@ protected function preprocessForm(JForm $form, $data, $group = 'user') /** * Method to save the form data. * - * @param array $data The form data. + * @param array $data The form data. * - * @return boolean True on success. - * @since 1.6 + * @return boolean True on success. + * + * @since 1.6 */ public function save($data) { @@ -142,34 +155,40 @@ public function save($data) $my = JFactory::getUser(); - if ($data['block'] && $pk == $my->id && !$my->block) { + if ($data['block'] && $pk == $my->id && !$my->block) + { $this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF')); return false; } // Make sure that we are not removing ourself from Super Admin group $iAmSuperAdmin = $my->authorise('core.admin'); - if ($iAmSuperAdmin && $my->get('id') == $pk) { + if ($iAmSuperAdmin && $my->get('id') == $pk) + { // Check that at least one of our new groups is Super Admin $stillSuperAdmin = false; $myNewGroups = $data['groups']; - foreach ($myNewGroups as $group) { + foreach ($myNewGroups as $group) + { $stillSuperAdmin = ($stillSuperAdmin) ? ($stillSuperAdmin) : JAccess::checkGroup($group, 'core.admin'); } - if (!$stillSuperAdmin) { + if (!$stillSuperAdmin) + { $this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_DEMOTE_SELF')); return false; } } // Bind the data. - if (!$user->bind($data)) { + if (!$user->bind($data)) + { $this->setError($user->getError()); return false; } // Store the data. - if (!$user->save()) { + if (!$user->save()) + { $this->setError($user->getError()); return false; } @@ -182,10 +201,11 @@ public function save($data) /** * Method to delete rows. * - * @param array $pks An array of item ids. + * @param array &$pks An array of item ids. * - * @return boolean Returns true on success, false on failure. - * @since 1.6 + * @return boolean Returns true on success, false on failure. + * + * @since 1.6 */ public function delete(&$pks) { @@ -194,14 +214,15 @@ public function delete(&$pks) $table = $this->getTable(); $pks = (array) $pks; - // Check if I am a Super Admin + // Check if I am a Super Admin $iAmSuperAdmin = $user->authorise('core.admin'); // Trigger the onUserBeforeSave event. JPluginHelper::importPlugin('user'); $dispatcher = JDispatcher::getInstance(); - if (in_array($user->id, $pks)) { + if (in_array($user->id, $pks)) + { $this->setError(JText::_('COM_USERS_USERS_ERROR_CANNOT_DELETE_SELF')); return false; } @@ -209,34 +230,41 @@ public function delete(&$pks) // Iterate the items to delete each one. foreach ($pks as $i => $pk) { - if ($table->load($pk)) { + if ($table->load($pk)) + { // Access checks. $allow = $user->authorise('core.delete', 'com_users'); // Don't allow non-super-admin to delete a super admin $allow = (!$iAmSuperAdmin && JAccess::check($pk, 'core.admin')) ? false : $allow; - if ($allow) { + if ($allow) + { // Get users data for the users to delete. $user_to_delete = JFactory::getUser($pk); // Fire the onUserBeforeDelete event. $dispatcher->trigger('onUserBeforeDelete', array($table->getProperties())); - if (!$table->delete($pk)) { + if (!$table->delete($pk)) + { $this->setError($table->getError()); return false; - } else { + } + else + { // Trigger the onUserAfterDelete event. $dispatcher->trigger('onUserAfterDelete', array($user_to_delete->getProperties(), true, $this->getError())); } } - else { + else + { // Prune items that you can't change. unset($pks[$i]); JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED')); } } - else { + else + { $this->setError($table->getError()); return false; } @@ -248,11 +276,12 @@ public function delete(&$pks) /** * Method to block user records. * - * @param array $pks The ids of the items to publish. - * @param int $value The value of the published state + * @param array &$pks The ids of the items to publish. + * @param integer $value The value of the published state * - * @return boolean True on success. - * @since 1.6 + * @return boolean True on success. + * + * @since 1.6 */ function block(&$pks, $value = 1) { @@ -260,7 +289,7 @@ function block(&$pks, $value = 1) $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $user = JFactory::getUser(); - // Check if I am a Super Admin + // Check if I am a Super Admin $iAmSuperAdmin = $user->authorise('core.admin'); $table = $this->getTable(); $pks = (array) $pks; @@ -270,13 +299,15 @@ function block(&$pks, $value = 1) // Access checks. foreach ($pks as $i => $pk) { - if ($value == 1 && $pk == $user->get('id')) { + if ($value == 1 && $pk == $user->get('id')) + { // Cannot block yourself. unset($pks[$i]); JError::raiseWarning(403, JText::_('COM_USERS_USERS_ERROR_CANNOT_BLOCK_SELF')); } - elseif ($table->load($pk)) { + elseif ($table->load($pk)) + { $old = $table->getProperties(); $allow = $user->authorise('core.edit.state', 'com_users'); // Don't allow non-super-admin to delete a super admin @@ -287,9 +318,11 @@ function block(&$pks, $value = 1) 'clientid' => array(0, 1) ); - if ($allow) { + if ($allow) + { // Skip changing of same state - if ($table->block == $value) { + if ($table->block == $value) + { unset($pks[$i]); continue; } @@ -299,20 +332,23 @@ function block(&$pks, $value = 1) // Allow an exception to be thrown. try { - if (!$table->check()) { + if (!$table->check()) + { $this->setError($table->getError()); return false; } // Trigger the onUserBeforeSave event. $result = $dispatcher->trigger('onUserBeforeSave', array($old, false, $table->getProperties())); - if (in_array(false, $result, true)) { + if (in_array(false, $result, true)) + { // Plugin will have to raise it's own error or throw an exception. return false; } // Store the table. - if (!$table->store()) { + if (!$table->store()) + { $this->setError($table->getError()); return false; } @@ -328,11 +364,13 @@ function block(&$pks, $value = 1) } // Log the user out. - if ($value) { + if ($value) + { $app->logout($table->id, $options); } } - else { + else + { // Prune items that you can't change. unset($pks[$i]); JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); @@ -346,17 +384,18 @@ function block(&$pks, $value = 1) /** * Method to activate user records. * - * @param array $pks The ids of the items to activate. + * @param array &$pks The ids of the items to activate. * - * @return boolean True on success. - * @since 1.6 + * @return boolean True on success. + * + * @since 1.6 */ function activate(&$pks) { // Initialise variables. $dispatcher = JDispatcher::getInstance(); $user = JFactory::getUser(); - // Check if I am a Super Admin + // Check if I am a Super Admin $iAmSuperAdmin = $user->authorise('core.admin'); $table = $this->getTable(); $pks = (array) $pks; @@ -366,37 +405,43 @@ function activate(&$pks) // Access checks. foreach ($pks as $i => $pk) { - if ($table->load($pk)) { + if ($table->load($pk)) + { $old = $table->getProperties(); $allow = $user->authorise('core.edit.state', 'com_users'); // Don't allow non-super-admin to delete a super admin $allow = (!$iAmSuperAdmin && JAccess::check($pk, 'core.admin')) ? false : $allow; - if (empty($table->activation)) { + if (empty($table->activation)) + { // Ignore activated accounts. unset($pks[$i]); } - elseif ($allow) { + elseif ($allow) + { $table->block = 0; $table->activation = ''; // Allow an exception to be thrown. try { - if (!$table->check()) { + if (!$table->check()) + { $this->setError($table->getError()); return false; } // Trigger the onUserBeforeSave event. $result = $dispatcher->trigger('onUserBeforeSave', array($old, false, $table->getProperties())); - if (in_array(false, $result, true)) { + if (in_array(false, $result, true)) + { // Plugin will have to raise it's own error or throw an exception. return false; } // Store the table. - if (!$table->store()) { + if (!$table->store()) + { $this->setError($table->getError()); return false; } @@ -411,7 +456,8 @@ function activate(&$pks) return false; } } - else { + else + { // Prune items that you can't change. unset($pks[$i]); JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); @@ -423,106 +469,169 @@ function activate(&$pks) } /** - * Perform batch operations + * Method to perform batch operations on an item or a set of items. * - * @param array $config An array of variable for the batch operation - * @param array $user_ids An array of IDs on which to operate - * @since 1.6 + * @param array $commands An array of commands to perform. + * @param array $pks An array of item ids. + * @param array $contexts An array of item contexts. + * + * @return boolean Returns true on success, false on failure. + * + * @since 2.5 */ - public function batch($config, $user_ids) + public function batch($commands, $pks, $contexts) { - // Ensure there are selected users to operate on. - if (empty($user_ids)) { - $this->setError(JText::_('COM_USERS_USERS_NO_ITEM_SELECTED')); + // Sanitize user ids. + $pks = array_unique($pks); + JArrayHelper::toInteger($pks); + + // Remove any values of zero. + if (array_search(0, $pks, true)) + { + unset($pks[array_search(0, $pks, true)]); + } + if (empty($pks)) + { + $this->setError(JText::_('COM_USERS_USERS_NO_ITEM_SELECTED')); return false; } - elseif (!empty($config)) { - // Only run operations if a config array is present. - // Ensure there is a valid group. - $group_id = JArrayHelper::getValue($config, 'group_id', 0, 'int'); - JArrayHelper::toInteger($user_ids); - if ($group_id < 1) { - $this->setError(JText::_('COM_USERS_ERROR_INVALID_GROUP')); + $done = false; + + if (!empty($commands['group_id'])) + { + $cmd = JArrayHelper::getValue($commands, 'group_action', 'add'); + if (!$this->batchUser((int) $commands['group_id'], $pks, $cmd)) + { return false; } + $done = true; + } + + if (!$done) + { + $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); + return false; + } + + // Clear the cache + $this->cleanCache(); + + return true; + } + + /** + * Perform batch operations + * + * @param integer $group_id The group ID which assignments are being edited + * @param array $user_ids An array of user IDs on which to operate + * @param string $action The action to perform + * + * @return boolean True on success, false on failure + * + * @since 1.6 + */ + public function batchUser($group_id, $user_ids, $action) + { + // Get the DB object + $db = $this->getDbo(); + + JArrayHelper::toInteger($user_ids); + + if ($group_id < 1) + { + $this->setError(JText::_('COM_USERS_ERROR_INVALID_GROUP')); + return false; + } + + switch ($action) + { + // Sets users to a selected group + case 'set': + $doDelete = 'all'; + $doAssign = true; + break; + + // Remove users from a selected group + case 'del': + $doDelete = 'group'; + break; + + // Add users to a selected group + case 'add': + default: + $doAssign = true; + break; + } + + // Remove the users from the group if requested. + if (isset($doDelete)) + { + $query = $db->getQuery(true); - // Get the system ACL object and set the mode to database driven. - $acl = JFactory::getACL(); - $oldAclMode = $acl->setCheckMode(1); + // Remove users from the group + $query->delete($db->quoteName('#__user_usergroup_map')); + $query->where($db->quoteName('user_id') . ' IN (' . implode(',', $user_ids) . ')'); - $groupLogic = JArrayHelper::getValue($config, 'group_logic'); - switch ($groupLogic) + // Only remove users from selected group + if ($doDelete == 'group') { - case 'set': - $doDelete = 2; - $doAssign = true; - break; - - case 'del': - $doDelete = true; - $doAssign = false; - break; - - case 'add': - default: - $doDelete = false; - $doAssign = true; - break; + $query->where($db->quoteName('group_id') . ' = ' . (int) $group_id); } - // Remove the users from the group(s) if requested. - if ($doDelete) { - // Purge operation, remove the users from all groups. - if ($doDelete === 2) { - $this->_db->setQuery( - 'DELETE FROM '.$this->_db->quoteName('#__user_usergroup_map') . - ' WHERE '.$this->_db->quoteName('user_id').' IN ('.implode(',', $user_ids).')' - ); - } - else { - // Remove the users from the group. - $this->_db->setQuery( - 'DELETE FROM '.$this->_db->quoteName('#__user_usergroup_map') . - ' WHERE '.$this->_db->quoteName('user_id').' IN ('.implode(',', $user_ids).')' . - ' AND '.$this->_db->quoteName('group_id').' = '.$group_id - ); - } - - // Check for database errors. - if (!$this->_db->query()) { - $this->setError($this->_db->getErrorMsg()); + $db->setQuery($query); - return false; - } + // Check for database errors. + if (!$db->query()) + { + $this->setError($db->getErrorMsg()); + return false; } + } - // Assign the users to the group if requested. - if ($doAssign) { - // Build the tuples array for the assignment query. - $tuples = array(); - foreach ($user_ids as $id) + // Assign the users to the group if requested. + if (isset($doAssign)) + { + $query = $db->getQuery(true); + + // First, we need to check if the user is already assigned to a group + $query->select($db->quoteName('user_id')); + $query->from($db->quoteName('#__user_usergroup_map')); + $query->where($db->quoteName('group_id') . ' = ' . (int) $group_id); + $db->setQuery($query); + $users = $db->loadColumn(); + + // Build the groups array for the assignment query. + $groups = array(); + foreach ($user_ids as $id) + { + if (!in_array($id, $users)) { - $tuples[] = '('.$id.','.$group_id.')'; + $groups[] = $id . ',' . $group_id; } + } - $this->_db->setQuery( - 'INSERT INTO '.$this->_db->quoteName('#__user_usergroup_map').' ('. - $this->_db->quoteName('user_id').', '.$this->_db->quoteName('group_id').')' . - ' VALUES '.implode(',', $tuples) - ); - - // Check for database errors. - if (!$this->_db->query()) { - $this->setError($this->_db->getErrorMsg()); - return false; - } + // If we have no users to process, throw an error to notify the user + if (empty($groups)) + { + $this->setError(JText::_('COM_USERS_ERROR_NO_ADDITIONS')); + return false; } - // Set the ACL mode back to it's previous state. - $acl->setCheckMode($oldAclMode); + $query->clear(); + $query->insert($db->quoteName('#__user_usergroup_map')); + $query->columns(array($db->quoteName('user_id'), $db->quoteName('group_id'))); + $query->values(implode(',', $groups)); + $db->setQuery($query); + + // Check for database errors. + if (!$db->query()) + { + $this->setError($db->getErrorMsg()); + return false; + } } return true; @@ -531,8 +640,9 @@ public function batch($config, $user_ids) /** * Gets the available groups. * - * @return array - * @since 1.6 + * @return array An array of groups + * + * @since 1.6 */ public function getGroups() { @@ -551,22 +661,29 @@ public function getGroups() /** * Gets the groups this object is assigned to * - * @return array - * @since 1.6 + * @param integer $userId The user ID to retrieve the groups for + * + * @return array An array of assigned groups + * + * @since 1.6 */ public function getAssignedGroups($userId = null) { // Initialise variables. $userId = (!empty($userId)) ? $userId : (int)$this->getState('user.id'); - if (empty($userId)) { + if (empty($userId)) + { $result = array(); $config = JComponentHelper::getParams('com_users'); - if ($groupId = $config->get('new_usertype')) { + if ($groupId = $config->get('new_usertype')) + { $result[] = $groupId; } } - else { + else + { + jimport('joomla.user.helper'); $result = JUserHelper::getUserGroups($userId); } diff --git a/administrator/components/com_users/views/users/tmpl/default.php b/administrator/components/com_users/views/users/tmpl/default.php index 0266bfd7ff3fd..6417b7f7f9223 100755 --- a/administrator/components/com_users/views/users/tmpl/default.php +++ b/administrator/components/com_users/views/users/tmpl/default.php @@ -10,9 +10,6 @@ // No direct access. defined('_JEXEC') or die; -// Include the component HTML helpers. -JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html'); - // Load the tooltip behavior. JHtml::_('behavior.tooltip'); JHtml::_('behavior.multiselect'); @@ -180,6 +177,9 @@ + + loadTemplate('batch'); ?> +
diff --git a/administrator/components/com_users/views/users/tmpl/default_batch.php b/administrator/components/com_users/views/users/tmpl/default_batch.php new file mode 100644 index 0000000000000..1fe4b95d32099 --- /dev/null +++ b/administrator/components/com_users/views/users/tmpl/default_batch.php @@ -0,0 +1,38 @@ + +
+ + +
+ + +
+ + + +
diff --git a/administrator/components/com_users/views/users/view.html.php b/administrator/components/com_users/views/users/view.html.php index 18d0d99400d11..da565b0e4155d 100644 --- a/administrator/components/com_users/views/users/view.html.php +++ b/administrator/components/com_users/views/users/view.html.php @@ -38,6 +38,9 @@ public function display($tpl = null) return false; } + // Include the component HTML helpers. + JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html'); + $this->addToolbar(); parent::display($tpl); } diff --git a/administrator/components/com_weblinks/controllers/weblink.php b/administrator/components/com_weblinks/controllers/weblink.php index a121078e61d62..4c12bb5ebd4f4 100644 --- a/administrator/components/com_weblinks/controllers/weblink.php +++ b/administrator/components/com_weblinks/controllers/weblink.php @@ -1,8 +1,10 @@ authorise('core.create', $this->option.'.category.'.$categoryId); + $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } - if ($allow === null) { + if ($allow === null) + { // In the absense of better information, revert to the component permissions. return parent::allowAdd($data); - } else { + } + else + { return $allow; } } @@ -49,26 +57,30 @@ protected function allowAdd($data = array()) /** * Method to check if you can add a new record. * - * @param array $data An array of input data. - * @param string $key The name of the key for the primary key. + * @param array $data An array of input data. + * @param string $key The name of the key for the primary key. * - * @return boolean - * @since 1.6 + * @return boolean + * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. - $recordId = (int) isset($data[$key]) ? $data[$key] : 0; + $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $categoryId = 0; - if ($recordId) { + if ($recordId) + { $categoryId = (int) $this->getModel()->getItem($recordId)->catid; } - if ($categoryId) { + if ($categoryId) + { // The category has been set. Check the category permissions. - return JFactory::getUser()->authorise('core.edit', $this->option.'.category.'.$categoryId); - } else { + return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId); + } + else + { // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } @@ -77,18 +89,21 @@ protected function allowEdit($data = array(), $key = 'id') /** * Method to run batch operations. * - * @return void - * @since 1.7 + * @param object $model The model. + * + * @return boolean True if successful, false otherwise and internal error is set. + * + * @since 1.7 */ - public function batch($model) + public function batch($model = null) { JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model - $model = $this->getModel('Weblink', '', array()); + $model = $this->getModel('Weblink', '', array()); // Preset the redirect - $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks'.$this->getRedirectToListAppend(), false)); + $this->setRedirect(JRoute::_('index.php?option=com_weblinks&view=weblinks' . $this->getRedirectToListAppend(), false)); return parent::batch($model); } diff --git a/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch.php b/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch.php index f5aac451aa89d..f98dcfec80319 100644 --- a/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch.php +++ b/administrator/components/com_weblinks/views/weblinks/tmpl/default_batch.php @@ -19,7 +19,7 @@ = 0) : ?> - +