/** * Method to toggle the featured setting of a list of articles. * * @return void * @since 1.6 */ function featured() { // Check for request forgeries Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Initialise variables. $ids = Request::getVar('cid', array(), '', 'array'); $values = array('featured' => 1, 'unfeatured' => 0); $task = $this->getTask(); $value = \Hubzero\Utility\Arr::getValue($values, $task, 0, 'int'); // Access checks. foreach ($ids as $i => $id) { if (!$user->authorise('core.edit.state', 'com_content.article.' . (int) $id)) { // Prune items that you can't change. unset($ids[$i]); Notify::warning(Lang::txt('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED')); } } if (empty($ids)) { Notify::error(Lang::txt('JERROR_NO_ITEMS_SELECTED')); } else { // Get the model. $model = $this->getModel(); // Publish the items. if (!$model->featured($ids, $value)) { throw new Exception($model->getError(), 500); } } $this->setRedirect('index.php?option=com_content&view=articles'); }
/** * Method to set the home property for a list of items * * @since 1.6 */ function setDefault() { // Check for request forgeries Session::checkToken('request') or die(Lang::txt('JINVALID_TOKEN')); // Get items to publish from the request. $cid = Request::getVar('cid', array(), '', 'array'); $data = array('setDefault' => 1, 'unsetDefault' => 0); $task = $this->getTask(); $value = \Hubzero\Utility\Arr::getValue($data, $task, 0, 'int'); if (empty($cid)) { throw new Exception(Lang::txt($this->text_prefix . '_NO_ITEM_SELECTED'), 500); } else { // Get the model. $model = $this->getModel(); // Make sure the item ids are integers \Hubzero\Utility\Arr::toInteger($cid); // Publish the items. if (!$model->setHome($cid, $value)) { throw new Exception($model->getError(), 500); } else { if ($value == 1) { $ntext = 'COM_MENUS_ITEMS_SET_HOME'; } else { $ntext = 'COM_MENUS_ITEMS_UNSET_HOME'; } $this->setMessage(Lang::txts($ntext, count($cid))); } } $this->setRedirect(Route::url('index.php?option=' . $this->option . '&view=' . $this->view_list, false)); }
/** * Method to change the block status on a record. * * @return void * * @since 1.6 */ public function changeBlock() { // Check for request forgeries. Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Initialise variables. $ids = Request::getVar('cid', array(), '', 'array'); $values = array('block' => 1, 'unblock' => 0); $task = $this->getTask(); $value = \Hubzero\Utility\Arr::getValue($values, $task, 0, 'int'); if (empty($ids)) { throw new Exception(Lang::txt('COM_USERS_USERS_NO_ITEM_SELECTED'), 500); } else { // Get the model. $model = $this->getModel(); // Change the state of the records. if (!$model->block($ids, $value)) { throw new Exception($model->getError(), 500); } else { if ($value == 1) { $this->setMessage(Lang::txts('COM_USERS_N_USERS_BLOCKED', count($ids))); } elseif ($value == 0) { $this->setMessage(Lang::txts('COM_USERS_N_USERS_UNBLOCKED', count($ids))); } } } $this->setRedirect('index.php?option=com_users&view=users'); }
/** * @param int $value The state value * @param int $i */ public static function state($value = 0, $i) { // Array of image, task, title, action $states = array(1 => array('tick.png', 'newsfeeds.unpublish', 'JPUBLISHED', 'COM_NEWSFEEDS_UNPUBLISH_ITEM'), 0 => array('publish_x.png', 'newsfeeds.publish', 'JUNPUBLISHED', 'COM_NEWSFEEDS_PUBLISH_ITEM')); $state = \Hubzero\Utility\Arr::getValue($states, (int) $value, $states[0]); $html = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" title="' . Lang::txt($state[3]) . '">' . Html::asset('image', 'admin/' . $state[0], Lang::txt($state[2]), NULL, true) . '</a>'; return $html; }
/** * @param int $value The state value * @param int $i */ public static function state($value = 0, $i, $canChange) { // Array of image, task, title, action. $states = array(-2 => array('trash.png', 'messages.unpublish', 'JTRASHED', 'COM_MESSAGES_MARK_AS_UNREAD'), 1 => array('tick.png', 'messages.unpublish', 'COM_MESSAGES_OPTION_READ', 'COM_MESSAGES_MARK_AS_UNREAD'), 0 => array('publish_x.png', 'messages.publish', 'COM_MESSAGES_OPTION_UNREAD', 'COM_MESSAGES_MARK_AS_READ')); $state = \Hubzero\Utility\Arr::getValue($states, (int) $value, $states[0]); $html = Html::asset('image', 'admin/' . $state[0], Lang::txt($state[2]), NULL, true); if ($canChange) { $html = '<a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" title="' . Lang::txt($state[3]) . '">' . $html . '</a>'; } return $html; }
/** * @param int $value The state value * @param int $i */ static function featured($value = 0, $i, $canChange = true) { // Array of image, task, title, action $states = array(0 => array('disabled.png', 'articles.featured', 'COM_CONTENT_UNFEATURED', 'COM_CONTENT_TOGGLE_TO_FEATURE'), 1 => array('featured.png', 'articles.unfeatured', 'COM_CONTENT_FEATURED', 'COM_CONTENT_TOGGLE_TO_UNFEATURE')); $state = \Hubzero\Utility\Arr::getValue($states, (int) $value, $states[1]); $html = Html::asset('image', 'admin/' . $state[0], Lang::txt($state[2]), NULL, true); if ($canChange) { $html = '<a href="#" class="state ' . ($value ? 'yes' : 'no') . '" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" title="' . Lang::txt($state[3]) . '">' . $html . '</a>'; } return $html; }
/** * @param int $value The state value. * @param int $i * @param string An optional prefix for the task. * @param boolean An optional setting for access control on the action. */ public static function published($value = 0, $i, $canChange = true) { // Array of image, task, title, action $states = array(1 => array('on', 'unpublish', 'JENABLED', 'COM_REDIRECT_DISABLE_LINK'), 0 => array('off', 'publish', 'JDISABLED', 'COM_REDIRECT_ENABLE_LINK'), 2 => array('archived', 'unpublish', 'JARCHIVED', 'JUNARCHIVE'), -2 => array('trash', 'publish', 'JTRASHED', 'COM_REDIRECT_ENABLE_LINK')); $state = \Hubzero\Utility\Arr::getValue($states, (int) $value, $states[0]); $html = '<span>' . Lang::txt($state[3]) . '</span>'; //Html::asset('image', 'admin/'.$state[0], Lang::txt($state[2]), NULL, true); if ($canChange) { $html = '<a class="state ' . $state[0] . '" href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $state[1] . '\')" title="' . Lang::txt($state[3]) . '">' . $html . '</a>'; } return $html; }
/** * Method override to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean * * @since 1.6 */ protected function allowAdd($data = array()) { // Initialise variables. $categoryId = \Hubzero\Utility\Arr::getValue($data, 'catid', Request::getInt('filter_category_id'), 'int'); $allow = null; if ($categoryId) { // If the category has been passed in the URL check it. $allow = User::authorise('core.create', $this->option . '.category.' . $categoryId); } if ($allow === null) { // In the absence of better information, revert to the component permissions. return parent::allowAdd($data); } else { return $allow; } }
/** * Replaces the matched tags. * * @param array An array of matches (see preg_match_all) * @return string */ protected function _replace(&$matches) { jimport('joomla.utilities.utility'); require_once dirname(__FILE__) . '/geshi/geshi.php'; $args = JUtility::parseAttributes($matches[1]); $text = $matches[2]; $lang = \Hubzero\Utility\Arr::getValue($args, 'lang', 'php'); $lines = \Hubzero\Utility\Arr::getValue($args, 'lines', 'false'); $html_entities_match = array("|\\<br \\/\\>|", "#<#", "#>#", "|'|", '#"#', '# #'); $html_entities_replace = array("\n", '<', '>', "'", '"', ' '); $text = preg_replace($html_entities_match, $html_entities_replace, $text); $text = str_replace('<', '<', $text); $text = str_replace('>', '>', $text); $text = str_replace("\t", ' ', $text); $geshi = new GeSHi($text, $lang); if ($lines == 'true') { $geshi->enable_line_numbers(GESHI_NORMAL_LINE_NUMBERS); } $text = $geshi->parse_code(); return $text; }
/** * Method to get the field input markup. * * @return string The field input markup. * @since 1.6 */ protected function getInput() { // Initialise variables. $html = array(); $recordId = (int) $this->form->getValue('id'); $size = ($v = $this->element['size']) ? ' size="' . $v . '"' : ''; $class = ($v = $this->element['class']) ? ' class="' . $v . '"' : 'class="text_area"'; // Get a reverse lookup of the base link URL to Title $model = JModelLegacy::getInstance('menutypes', 'menusModel'); $rlu = $model->getReverseLookup(); switch ($this->value) { case 'url': $value = Lang::txt('COM_MENUS_TYPE_EXTERNAL_URL'); break; case 'alias': $value = Lang::txt('COM_MENUS_TYPE_ALIAS'); break; case 'separator': $value = Lang::txt('COM_MENUS_TYPE_SEPARATOR'); break; default: $link = $this->form->getValue('link'); // Clean the link back to the option, view and layout $value = Lang::txt(\Hubzero\Utility\Arr::getValue($rlu, MenusHelper::getLinkKey($link))); break; } // Load the javascript and css Html::behavior('framework'); Html::behavior('modal'); Document::addScriptDeclaration("\n\t\t\tjQuery(document).ready(function(\$){\n\t\t\t\t\$('input.modal').fancybox({\n\t\t\t\t\tarrows: false,\n\t\t\t\t\ttype: 'iframe',\n\t\t\t\t\tautoSize: false,\n\t\t\t\t\tfitToView: false,\n\t\t\t\t\twidth: 600,\n\t\t\t\t\theight: 450,\n\t\t\t\t\thref: '" . Route::url('index.php?option=com_menus&view=menutypes&tmpl=component&recordId=' . $recordId, false) . "'\n\t\t\t\t});\n\t\t\t});\n\t\t"); $html[] = '<div class="input-modal">'; $html[] = '<span class="input-cell">'; $html[] = '<input type="text" id="' . $this->id . '" readonly="readonly" disabled="disabled" value="' . $value . '"' . $size . $class . ' />'; $html[] = '</span><span class="input-cell">'; $html[] = '<input type="button" class="modal" value="' . Lang::txt('JSELECT') . '" />'; $html[] = '<input type="hidden" name="' . $this->name . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" />'; $html[] = '</span>'; $html[] = '</div>'; return implode("\n", $html); }
/** * Method to publish a list of items * * @return void */ public function publishTask() { // Check for request forgeries Request::checkToken(); // Access check. if (!User::authorise('core.edit', $this->_option)) { Notify::warning(Lang::txt('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED')); return $this->cancelTask(); } // Get items to publish from the request. $ids = Request::getVar('id', array(), '', 'array'); $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); $value = \Hubzero\Utility\Arr::getValue($data, $this->_task, 0, 'int'); if (empty($ids)) { Notify::error(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED')); } $updated = 0; // Loop through all the IDs foreach ($ids as $id) { $entry = Link::oneOrFail(intval($id)); $entry->set('published', $value); // Remove the items. if (!$entry->save()) { Notify::error($entry->getError()); continue; } $updated++; } if ($value == 1) { $ntext = 'COM_REDIRECT_N_ITEMS_PUBLISHED'; } elseif ($value == 0) { $ntext = 'COM_REDIRECT_N_ITEMS_UNPUBLISHED'; } elseif ($value == 2) { $ntext = 'COM_REDIRECT_N_ITEMS_ARCHIVED'; } else { $ntext = 'COM_REDIRECT_N_ITEMS_TRASHED'; } Notify::success(Lang::txts($ntext, $updated)); $this->cancelTask(); }
/** * Remove all user blog entries for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was succesfully stored in the database * @param string $msg Message * @return boolean */ public function onMemberAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int'); if ($userId) { try { include_once PATH_CORE . DS . 'components' . DS . 'com_collections' . DS . 'models' . DS . 'archive.php'; $db = App::get('db'); $model = new \Components\Collections\Tables\Collection($db); $entries = $model->find('list', array('created_by' => $userId)); foreach ($entries as $entry) { $entry = new \Components\Collections\Models\Collection($entry); if (!$entry->delete()) { throw new Exception($entry->getError()); } } } catch (Exception $e) { return false; } } return true; }
/** * Method to publish a list of items * * @return void */ public function publishTask() { // Check for request forgeries Session::checkToken() or die(Lang::txt('JINVALID_TOKEN')); // Get items to publish from the request. $cid = Request::getVar('cid', array(), '', 'array'); $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); $task = $this->getTask(); $value = Arr::getValue($data, $task, 0, 'int'); if (empty($cid)) { throw new Exception(Lang::txt($this->text_prefix . '_NO_ITEM_SELECTED'), 500); } else { // Get the model. $model = new Models\Plugin(); // Make sure the item ids are integers Arr::toInteger($cid); // Publish the items. if (!$model->publish($cid, $value)) { throw new Exception($model->getError(), 500); } else { if ($value == 1) { $ntext = $this->text_prefix . '_N_ITEMS_PUBLISHED'; } elseif ($value == 0) { $ntext = $this->text_prefix . '_N_ITEMS_UNPUBLISHED'; } elseif ($value == 2) { $ntext = $this->text_prefix . '_N_ITEMS_ARCHIVED'; } else { $ntext = $this->text_prefix . '_N_ITEMS_TRASHED'; } Notify::success(Lang::txts($ntext, count($cid))); } } $extension = Request::getCmd('extension'); $extensionURL = $extension ? '&extension=' . Request::getCmd('extension') : ''; App::redirect(Route::url('index.php?option=' . $this->_option . $extensionURL, false)); }
/** * Batch copy categories to a new category. * * @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 */ protected function batchCopy($value, $pks, $contexts) { // $value comes as {parent_id}.{extension} $parts = explode('.', $value); $parentId = (int) \Hubzero\Utility\Arr::getValue($parts, 0, 1); $table = $this->getTable(); $db = $this->getDbo(); $extension = Request::getWord('extension', ''); $i = 0; // Check that the parent exists if ($parentId) { if (!$table->load($parentId)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Non-fatal error $this->setError(Lang::txt('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) { // Error since user cannot create in parent category $this->setError(Lang::txt('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; } } // If the parent is 0, set it to the ID of the root item in the tree if (empty($parentId)) { if (!($parentId = $table->getRootId())) { $this->setError($db->getErrorMsg()); return false; } elseif (!User::authorise('core.create', $extension)) { $this->setError(Lang::txt('COM_CATEGORIES_BATCH_CANNOT_CREATE')); return false; } } // We need to log the parent ID $parents = array(); // Calculate the emergency stop count as a precaution against a runaway loop bug $query = $db->getQuery(true); $query->select('COUNT(id)'); $query->from($db->quoteName('#__categories')); $db->setQuery($query); $count = $db->loadResult(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } // Parent exists so we let's proceed while (!empty($pks) && $count > 0) { // 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(Lang::txt('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; } } // Copy is a bit tricky, because we also need to copy the children $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)) { array_push($pks, $childId); } } // Make a copy of the old ID and Parent ID $oldId = $table->id; $oldParentId = $table->parent_id; // Reset the id because we are making a copy. $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; // 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; // Alter the title & 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()) { $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++; // Now we log the old 'parent' to the new 'parent' $parents[$oldId] = $table->id; $count--; } // Rebuild the hierarchy. if (!$table->rebuild()) { $this->setError($table->getError()); return false; } // Rebuild the tree path. if (!$table->rebuildPath($table->id)) { $this->setError($table->getError()); return false; } return $newIds; }
/** * 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 object A JForm object on success, false on failure */ public function getForm($data = array(), $loadData = true) { // The folder and element vars are passed when saving the form. if (empty($data)) { $item = $this->getItem(); $folder = $item->folder; $element = $item->element; } else { $folder = Arr::getValue($data, 'folder', '', 'cmd'); $element = Arr::getValue($data, 'element', '', 'cmd'); } // These variables are used to add data from the plugin XML files. $this->setState('item.folder', $folder); $this->setState('item.element', $element); // Get the form. $form = $this->loadForm('com_plugins.plugin', 'plugin', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Modify the form based on access controls. if (!$this->canEditState((object) $data)) { // Disable fields for display. $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('enabled', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is a record you can edit. $form->setFieldAttribute('ordering', 'filter', 'unset'); $form->setFieldAttribute('enabled', 'filter', 'unset'); } return $form; }
/** * Display module contents * * @param object $params Registry * @return array */ public static function getList(&$params) { require_once PATH_CORE . '/components/com_content/helpers/route.php'; JModelLegacy::addIncludePath(PATH_CORE . '/components/com_content/models', 'ContentModel'); // Get the dbo $db = App::get('db'); // Get an instance of the generic articles model $model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); // Set application parameters in model $app = JFactory::getApplication(); $appParams = $app->getParams(); $model->setState('params', $appParams); // Set the filters based on the module params $model->setState('list.start', 0); $model->setState('list.limit', (int) $params->get('count', 5)); $model->setState('filter.published', 1); // Access filter $access = !Component::params('com_content')->get('show_noauth'); $authorised = JAccess::getAuthorisedViewLevels(User::get('id')); $model->setState('filter.access', $access); // Category filter $model->setState('filter.category_id', $params->get('catid', array())); // User filter $userId = User::get('id'); switch ($params->get('user_id')) { case 'by_me': $model->setState('filter.author_id', (int) $userId); break; case 'not_me': $model->setState('filter.author_id', $userId); $model->setState('filter.author_id.include', false); break; case '0': break; default: $model->setState('filter.author_id', (int) $params->get('user_id')); break; } // Filter by language $model->setState('filter.language', \App::get('language.filter')); // Featured switch switch ($params->get('show_featured')) { case '1': $model->setState('filter.featured', 'only'); break; case '0': $model->setState('filter.featured', 'hide'); break; default: $model->setState('filter.featured', 'show'); break; } // Set ordering $order_map = array('m_dsc' => 'a.modified DESC, a.created', 'mc_dsc' => 'CASE WHEN (a.modified = ' . $db->quote($db->getNullDate()) . ') THEN a.created ELSE a.modified END', 'c_dsc' => 'a.created', 'p_dsc' => 'a.publish_up'); $ordering = Arr::getValue($order_map, $params->get('ordering'), 'a.publish_up'); $dir = 'DESC'; $model->setState('list.ordering', $ordering); $model->setState('list.direction', $dir); $items = $model->getItems(); foreach ($items as &$item) { $item->slug = $item->id . ':' . $item->alias; $item->catslug = $item->catid . ':' . $item->category_alias; if ($access || in_array($item->access, $authorised)) { // We know that user has the privilege to view the article $item->link = Route::url(ContentHelperRoute::getArticleRoute($item->slug, $item->catslug, $item->language)); } else { $item->link = Route::url('index.php?option=com_users&view=login'); } } return $items; }
/** * Enable/Disable an extension (if supported). * * @since 1.6 */ public function publishTask() { // Check for request forgeries. Request::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Initialise variables. $ids = Request::getVar('cid', array(), '', 'array'); $values = array('publish' => 1, 'unpublish' => 0); $task = $this->getTask(); $value = \Hubzero\Utility\Arr::getValue($values, $task, 0, 'int'); if (empty($ids)) { App::abort(500, Lang::txt('COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED')); } else { // Get the model. $model = new Models\Manage(); // Change the state of the records. if (!$model->publish($ids, $value)) { App::abort(500, implode('<br />', $model->getErrors())); } else { if ($value == 1) { $ntext = 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED'; } elseif ($value == 0) { $ntext = 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED'; } Notify::success(Lang::txts($ntext, count($ids))); } } App::redirect(Route::url('index.php?option=com_installer&controller=manage', false)); }
/** * Remove all user blog entries for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was succesfully stored in the database * @param string $msg Message * @return boolean */ public function onMemberAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int'); if ($userId) { try { include_once PATH_CORE . DS . 'components' . DS . 'com_blog' . DS . 'models' . DS . 'archive.php'; $entries = \Components\Blog\Models\Entry::all()->whereEquals('created_by', $user['id'])->rows(); foreach ($entries as $entry) { if (!$entry->destroy()) { throw new Exception($entry->getError()); } } } catch (Exception $e) { return false; } } return true; }
/** * 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 */ public function getForm($data = array(), $loadData = true) { // The folder and element vars are passed when saving the form. if (empty($data)) { $item = $this->getItem(); $this->setState('item.link', $item->link); // The type should already be set. } else { $this->setState('item.link', \Hubzero\Utility\Arr::getValue($data, 'link')); $this->setState('item.type', \Hubzero\Utility\Arr::getValue($data, 'type')); } // Get the form. $form = $this->loadForm('com_menus.item', 'item', array('control' => 'jform', 'load_data' => $loadData), true); if (empty($form)) { return false; } // Modify the form based on access controls. if (!$this->canEditState((object) $data)) { // Disable fields for display. $form->setFieldAttribute('menuordering', 'disabled', 'true'); $form->setFieldAttribute('published', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is an article you can edit. $form->setFieldAttribute('menuordering', 'filter', 'unset'); $form->setFieldAttribute('published', 'filter', 'unset'); } return $form; }
/** * Remove all user quota information for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was succesfully stored in the database * @param string $msg Message * @return boolean */ public function onUserAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int'); if ($userId) { try { $db = App::get('db'); $db->setQuery("DELETE FROM `#__users_quotas` WHERE `user_id`=" . $userId); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } $db = App::get('db'); $db->setQuery("DELETE FROM `#__users_tool_preferences` WHERE `user_id`=" . $userId); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } } catch (Exception $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; }
/** * Remove all user profile information for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was succesfully stored in the database * @param string $msg Message * @return boolean */ public function onUserAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int'); if ($userId) { try { $db = App::get('db'); $db->setQuery('DELETE FROM `#__user_profiles` WHERE user_id = ' . $userId . " AND profile_key LIKE 'profile.%'"); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } } catch (Exception $e) { $this->_subject->setError($e->getMessage()); return false; } } return true; }
/** * 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); \Hubzero\Utility\Arr::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(Lang::txt('COM_USERS_USERS_NO_ITEM_SELECTED')); return false; } $done = false; if (!empty($commands['group_id'])) { $cmd = \Hubzero\Utility\Arr::getValue($commands, 'group_action', 'add'); if (!$this->batchUser((int) $commands['group_id'], $pks, $cmd)) { return false; } $done = true; } if (!$done) { $this->setError(Lang::txt('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); return false; } // Clear the cache $this->cleanCache(); return true; }
/** * Returns a state on a grid * * @param array $states array of value/state. Each state is an array of the form * (task, text, title,html active class, HTML inactive class) * or ('task'=>task, 'text'=>text, 'active_title'=>active title, * 'inactive_title'=>inactive title, 'tip'=>boolean, 'active_class'=>html active class, * 'inactive_class'=>html inactive class) * @param integer $value The state value. * @param integer $i The row index * @param string|array $prefix An optional task prefix or an array of options * @param boolean $enabled An optional setting for access control on the action. * @param boolean $translate An optional setting for translation. * @param string $checkbox An optional prefix for checkboxes. * @return string The Html code */ public static function state($states, $value, $i, $prefix = '', $enabled = true, $translate = true, $checkbox = 'cb') { if (is_array($prefix)) { $options = $prefix; $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled; $translate = array_key_exists('translate', $options) ? $options['translate'] : $translate; $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox; $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : ''; } $state = Arr::getValue($states, (int) $value, $states[0]); $task = array_key_exists('task', $state) ? $state['task'] : $state[0]; $text = array_key_exists('text', $state) ? $state['text'] : (array_key_exists(1, $state) ? $state[1] : ''); $active_title = array_key_exists('active_title', $state) ? $state['active_title'] : (array_key_exists(2, $state) ? $state[2] : ''); $inactive_title = array_key_exists('inactive_title', $state) ? $state['inactive_title'] : (array_key_exists(3, $state) ? $state[3] : ''); $tip = array_key_exists('tip', $state) ? $state['tip'] : (array_key_exists(4, $state) ? $state[4] : false); $active_class = array_key_exists('active_class', $state) ? $state['active_class'] : (array_key_exists(5, $state) ? $state[5] : ''); $inactive_class = array_key_exists('inactive_class', $state) ? $state['inactive_class'] : (array_key_exists(6, $state) ? $state[6] : ''); return self::action($i, $task, $prefix, $text, $active_title, $inactive_title, $tip, $active_class, $inactive_class, $enabled, $translate, $checkbox); }
/** * Method to get the record form. * * @param array $data An optional array of data for the form to interogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // The folder and element vars are passed when saving the form. if (empty($data)) { $item = $this->getItem(); $clientId = $item->client_id; $template = $item->template; } else { $clientId = \Hubzero\Utility\Arr::getValue($data, 'client_id'); $template = \Hubzero\Utility\Arr::getValue($data, 'template'); } // These variables are used to add data from the plugin XML files. $this->setState('item.client_id', $clientId); $this->setState('item.template', $template); // Get the form. $form = $this->loadForm('com_templates.style', 'style', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Modify the form based on access controls. if (!$this->canEditState((object) $data)) { // Disable fields for display. $form->setFieldAttribute('home', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is a record you can edit. $form->setFieldAttribute('home', 'filter', 'unset'); } return $form; }
/** * Method to publish a list of items * * @return void */ public function publishTask() { // Check for request forgeries Request::checkToken(); // Get items to publish from the request. $ids = Request::getVar('id', array(), '', 'array'); $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); $value = \Hubzero\Utility\Arr::getValue($data, $this->_task, 0, 'int'); if (empty($ids)) { Notify::error(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED')); } $updated = 0; // Loop through all the IDs foreach ($ids as $id) { $entry = Link::oneOrFail(intval($id)); $entry->set('published', $value); // Remove the items. if (!$entry->save()) { Notify::error($entry->getError()); continue; } $updated++; } if ($value == 1) { $ntext = 'COM_REDIRECT_N_ITEMS_PUBLISHED'; } elseif ($value == 0) { $ntext = 'COM_REDIRECT_N_ITEMS_UNPUBLISHED'; } elseif ($value == 2) { $ntext = 'COM_REDIRECT_N_ITEMS_ARCHIVED'; } else { $ntext = 'COM_REDIRECT_N_ITEMS_TRASHED'; } Notify::success(Lang::txts($ntext, $updated)); App::redirect(Route::url('index.php?option=' . $this->_option, false)); }
/** * Remove all user blog entries for the given user ID * * Method is called after user data is deleted from the database * * @param array $user Holds the user data * @param boolean $success True if user was succesfully stored in the database * @param string $msg Message * @return boolean */ public function onMemberAfterDelete($user, $success, $msg) { if (!$success) { return false; } $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int'); if ($userId) { try { $entry = \Hubzero\Bank\Account::oneByUserId($user['id']); if (!$entry->destroy()) { throw new Exception($entry->getError()); } $transactions = \Hubzero\Bank\Transaction::all()->whereEquals('uid', $user['id']); foreach ($transactions->rows() as $row) { if (!$row->destroy()) { throw new Exception($row->getError()); } } } catch (Exception $e) { return false; } } return true; }
/** * Method to publish a list of items * * @return void */ public function publishTask() { // Check for request forgeries Request::checkToken() or die(Lang::txt('JINVALID_TOKEN')); // Get items to publish from the request. $cid = Request::getVar('cid', array(), '', 'array'); $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); $value = \Hubzero\Utility\Arr::getValue($data, $this->_task, 0, 'int'); if (empty($cid)) { throw new Exception(Lang::txt('COM_REDIRECT_NO_ITEM_SELECTED'), 500); } else { // Get the model. $model = new Record(); // Make sure the item ids are integers \Hubzero\Utility\Arr::toInteger($cid); // Publish the items. if (!$model->publish($cid, $value)) { throw new Exception($model->getError(), 500); } else { if ($value == 1) { $ntext = 'COM_REDIRECT_N_ITEMS_PUBLISHED'; } elseif ($value == 0) { $ntext = 'COM_REDIRECT_N_ITEMS_UNPUBLISHED'; } elseif ($value == 2) { $ntext = 'COM_REDIRECT_N_ITEMS_ARCHIVED'; } else { $ntext = 'COM_REDIRECT_N_ITEMS_TRASHED'; } Notify::success(Lang::txts($ntext, count($cid))); } } App::redirect(Route::url('index.php?option=' . $this->_option, false)); }