function fetchElement($name, $value, &$node, $control_name) { $access = JFactory::getACL(); // Include user in groups that have access to edit their articles, other articles, or manage content. $action = array('com_content.article.edit_own', 'com_content.article.edit_article', 'com_content.manage'); $groups = $access->getAuthorisedUsergroups($action, true); // Check the results of the access check. if (!$groups) { return false; } // Clean up and serialize. \Hubzero\Utility\Arr::toInteger($groups); $groups = implode(',', $groups); // Build the query to get the users. $db = App::get('db'); $query = $db->getQuery(true); $query->select('u.id AS value'); $query->select('u.name AS text'); $query->from('#__users AS u'); $query->join('INNER', '#__user_usergroup_map AS m ON m.user_id = u.id'); $query->where('u.block = 0'); $query->where('m.group_id IN (' . $groups . ')'); // Get the users. $db->setQuery((string) $query); $users = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 500); return false; } return Html::select('genericlist', $users, $name, 'class="inputbox" size="1"', 'value', 'text', $value); }
/** * Method to set the publishing state for a row or list of rows in the database * table. The method respects checked out rows by other users and will attempt * to checkin rows that it can after adjustments are made. * * @param mixed An optional array of primary key values to update. If not * set the instance property value is used. * @param integer The publishing state. eg. [0 = unpublished, 1 = published] * @param integer The user id of the user performing the operation. * @return boolean True on success. * @since 1.6 */ public function publish($pks = null, $state = 1, $userId = 0) { // Initialise variables. $k = $this->_tbl_key; // Sanitize input. \Hubzero\Utility\Arr::toInteger($pks); $userId = (int) $userId; $state = (int) $state; // If there are no primary keys set check to see if the instance key is set. if (empty($pks)) { if ($this->{$k}) { $pks = array($this->{$k}); } else { $this->setError(Lang::txt('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); return false; } } // Build the WHERE clause for the primary keys. $where = $k . ' IN (' . implode(',', $pks) . ')'; // Update the publishing state for rows with the given primary keys. $this->_db->setQuery('UPDATE ' . $this->_db->quoteName($this->_tbl) . ' SET ' . $this->_db->quoteName('state') . ' = ' . (int) $state . ' WHERE (' . $where . ')'); $this->_db->query(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } // If the JTable instance value is in the list of primary keys that were set, set the instance. if (in_array($this->{$k}, $pks)) { $this->state = $state; } $this->setError(''); return true; }
/** * Method to set the publishing state for a row or list of rows in the database * table. The method respects checked out rows by other users and will attempt * to check-in rows that it can after adjustments are made. * * @param mixed $pks An optional array of primary key values to update. If not set the instance property value is used. * @param integer $state The publishing state. eg. [0 = unpublished, 1 = published] * @param integer $userId The user id of the user performing the operation. * * @return boolean True on success. * * @link http://docs.joomla.org/JTable/publish * @since 2.5 */ public function publish($pks = null, $state = 1, $userId = 0) { // Initialise variables. $k = $this->_tbl_key; // Sanitize input. \Hubzero\Utility\Arr::toInteger($pks); $userId = (int) $userId; $state = (int) $state; // If there are no primary keys set check to see if the instance key is set. if (empty($pks)) { if ($this->{$k}) { $pks = array($this->{$k}); } else { $this->setError(Lang::txt('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); return false; } } $query = $this->_db->getQuery(true); $query->update($this->_db->quoteName($this->_tbl)); $query->set($this->_db->quoteName('state') . ' = ' . (int) $state); // Build the WHERE clause for the primary keys. $query->where($k . '=' . implode(' OR ' . $k . '=', $pks)); // Determine if there is checkin support for the table. if (!property_exists($this, 'checked_out') || !property_exists($this, 'checked_out_time')) { $checkin = false; } else { $query->where('(checked_out = 0 OR checked_out = ' . (int) $userId . ')'); $checkin = true; } // Update the publishing state for rows with the given primary keys. $this->_db->setQuery($query); $this->_db->query(); // Check for a database error. if ($this->_db->getErrorNum()) { $this->setError($this->_db->getErrorMsg()); return false; } // If checkin is supported and all rows were adjusted, check them in. if ($checkin && count($pks) == $this->_db->getAffectedRows()) { // Checkin the rows. foreach ($pks as $pk) { $this->checkin($pk); } } // If the JTable instance value is in the list of primary keys that were set, set the instance. if (in_array($this->{$k}, $pks)) { $this->state = $state; } $this->setError(''); return true; }
/** * Method to perform batch operations on a set of modules. * * @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 1.7 */ 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('JGLOBAL_NO_ITEM_SELECTED')); return false; } $done = false; if (!empty($commands['position_id'])) { $cmd = \Hubzero\Utility\Arr::getValue($commands, 'move_copy', 'c'); if (!empty($commands['position_id'])) { if ($cmd == 'c') { $result = $this->batchCopy($commands['position_id'], $pks, $contexts); if (is_array($result)) { $pks = $result; } else { return false; } } elseif ($cmd == 'm' && !$this->batchMove($commands['position_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 (!$done) { $this->setError(Lang::txt('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); return false; } // Clear the cache $this->cleanCache(); return true; }
/** * Save the ordering of entries * * @return void */ public function saveorderTask() { // Check for request forgeries Request::checkToken(); // Incoming $order = Request::getVar('order', array(), 'post', 'array'); Arr::toInteger($order); // Instantiate an object $jc = new JobCategory($this->database); if (count($order) > 0) { foreach ($order as $id => $num) { $jc->updateOrder($id, $num); } } // Redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_JOBS_ORDER_SAVED')); }
/** * Method to clone an existing module. * @since 1.6 */ public function duplicate() { // Check for request forgeries Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Initialise variables. $pks = Request::getVar('cid', array(), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($pks); try { if (empty($pks)) { throw new Exception(Lang::txt('COM_MODULES_ERROR_NO_MODULES_SELECTED')); } $model = $this->getModel(); $model->duplicate($pks); $this->setMessage(Lang::txts('COM_MODULES_N_MODULES_DUPLICATED', count($pks))); } catch (Exception $e) { Notify::error($e->getMessage()); } $this->setRedirect(Route::url('index.php?option=com_modules&view=modules', false)); }
/** * Update a set of extensions. * * @since 1.6 */ public function update() { // Check for request forgeries Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); $model = new Models\Update(); $uid = Request::getVar('cid', array(), '', 'array'); \Hubzero\Utility\Arr::toInteger($uid, array()); if ($model->update($uid)) { App::get('cache')->clean('mod_menu'); } $redirect_url = User::getState('com_installer.redirect_url'); if (empty($redirect_url)) { $redirect_url = Route::url('index.php?option=com_installer&view=update', false); } else { // wipe out the user state when we're going to redirect User::setState('com_installer.redirect_url', ''); User::setState('com_installer.message', ''); User::setState('com_installer.extension_message', ''); } App::redirect($redirect_url); }
/** * Removes an item */ public function delete() { // Check for request forgeries Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Get items to remove from the request. $cid = Request::getVar('cid', array(), '', 'array'); if (!is_array($cid) || count($cid) < 1) { Notify::error(Lang::txt('COM_MENUS_NO_MENUS_SELECTED')); } else { // Get the model. $model = $this->getModel(); // Make sure the item ids are integers \Hubzero\Utility\Arr::toInteger($cid); // Remove the items. if (!$model->delete($cid)) { $this->setMessage($model->getError()); } else { $this->setMessage(Lang::txts('COM_MENUS_N_MENUS_DELETED', count($cid))); } } $this->setRedirect('index.php?option=com_menus&view=menus'); }
/** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * * @since 1.6 */ protected function populateState($ordering = null, $direction = null) { // Initialise variables. $app = JFactory::getApplication('administrator'); // Adjust the context to support modal layouts. if ($layout = Request::getVar('layout', 'default')) { $this->context .= '.' . $layout; } // Load the filter state. $search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); $this->setState('filter.search', $search); $active = $this->getUserStateFromRequest($this->context . '.filter.active', 'filter_active', null); //'*'); $this->setState('filter.active', $active); $approved = $this->getUserStateFromRequest($this->context . '.filter.approved', 'filter_approved', '*'); $this->setState('filter.approved', $approved); $state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '*'); $this->setState('filter.state', $state); $groupId = $this->getUserStateFromRequest($this->context . '.filter.group', 'filter_group_id', null, 'int'); $this->setState('filter.group_id', $groupId); $range = $this->getUserStateFromRequest($this->context . '.filter.range', 'filter_range'); $this->setState('filter.range', $range); $groups = json_decode(base64_decode(Request::getVar('groups', '', 'default', 'BASE64'))); if (isset($groups)) { \Hubzero\Utility\Arr::toInteger($groups); } $this->setState('filter.groups', $groups); $excluded = json_decode(base64_decode(Request::getVar('excluded', '', 'default', 'BASE64'))); if (isset($excluded)) { \Hubzero\Utility\Arr::toInteger($excluded); } $this->setState('filter.excluded', $excluded); // Load the parameters. $params = Component::params('com_users'); $this->setState('params', $params); // List state information. parent::populateState('a.name', 'asc'); }
/** * Method to remove a record. */ public function delete() { // Check for request forgeries. Session::checkToken() or exit(Lang::txt('JInvalid_Token')); // Initialise variables. $ids = Request::getVar('cid', array(), '', 'array'); if (!User::authorise('core.admin', $this->option)) { throw new Exception(Lang::txt('JERROR_ALERTNOAUTHOR'), 403); } elseif (empty($ids)) { throw new Exception(Lang::txt('COM_USERS_NO_LEVELS_SELECTED'), 500); } else { // Get the model. $model = $this->getModel(); \Hubzero\Utility\Arr::toInteger($ids); // Remove the items. if (!$model->delete($ids)) { throw new Exception($model->getError(), 500); } else { $this->setMessage(Lang::txts('COM_USERS_N_LEVELS_DELETED', count($ids))); } } $this->setRedirect('index.php?option=com_users&view=levels'); }
/** * Mark a poll as open or closed * * @return void */ public function openTask() { // Check for request forgeries Request::checkToken(['get', 'post']); $cid = Request::getVar('cid', array(), '', 'array'); \Hubzero\Utility\Arr::toInteger($cid); $publish = Request::getVar('task') == 'open' ? 1 : 0; if (count($cid) < 1) { $action = $publish ? 'COM_POLL_OPEN' : 'COM_POLL_CLOSE'; App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_POLL_SELECT_ITEM_TO', Lang::txt($action), true), 'warning'); return; } $cids = implode(',', $cid); $db = \App::get('db'); $user = User::getRoot(); $query = 'UPDATE `#__polls`' . ' SET open = ' . (int) $publish . ' WHERE id IN (' . $cids . ')' . ' AND (checked_out = 0 OR (checked_out = ' . (int) $user->get('id') . '))'; $db->setQuery($query); if (!$db->query()) { throw new Exception($db->getErrorMsg(), 500); } if (count($cid) == 1) { $row = new Poll($db); $row->checkin($cid[0]); } App::redirect(Route::url('index.php?option=' . $this->_option, false)); }
/** * Returns an array of categories for the given extension. * * @param string $extension The extension option. * @param array $config An array of configuration options. By default, only published and unpublished categories are returned. * @return array Categories for the extension */ public static function categories($extension, $config = array('filter.published' => array(0, 1))) { $hash = md5($extension . '.' . serialize($config)); if (!isset(self::$items[$hash])) { $config = (array) $config; $db = \App::get('db'); $query = $db->getQuery(true); $query->select('a.id, a.title, a.level, a.parent_id'); $query->from('#__categories AS a'); $query->where('a.parent_id > 0'); // Filter on extension. $query->where('extension = ' . $db->quote($extension)); // Filter on the published state if (isset($config['filter.published'])) { if (is_numeric($config['filter.published'])) { $query->where('a.published = ' . (int) $config['filter.published']); } elseif (is_array($config['filter.published'])) { Arr::toInteger($config['filter.published']); $query->where('a.published IN (' . implode(',', $config['filter.published']) . ')'); } } $query->order('a.lft'); $db->setQuery($query); $items = $db->loadObjectList(); // Assemble the list options. self::$items[$hash] = array(); foreach ($items as &$item) { $repeat = $item->level - 1 >= 0 ? $item->level - 1 : 0; $item->title = str_repeat('- ', $repeat) . $item->title; self::$items[$hash][] = Select::option($item->id, $item->title); } // Special "Add to root" option: self::$items[$hash][] = Select::option('1', Lang::txt('JLIB_HTML_ADD_TO_ROOT')); } return self::$items[$hash]; }
/** * Build an SQL query to load the list data. * * @return JDatabaseQuery * @since 1.6 */ protected function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid' . ', a.state, a.access, a.created, a.created_by, a.created_by_alias, a.ordering, a.featured, a.language, a.hits' . ', a.publish_up, a.publish_down')); $query->from('#__content AS a'); // Join over the language $query->select('l.title AS language_title'); $query->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language'); // Join over the users for the checked out user. $query->select('uc.name AS editor'); $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out'); // Join over the asset groups. $query->select('ag.title AS access_level'); $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access'); // Join over the categories. $query->select('c.title AS category_title'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author. $query->select('ua.name AS author_name'); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); // Filter by access level. if ($access = $this->getState('filter.access')) { $query->where('a.access = ' . (int) $access); } // Implement View Level Access if (!User::authorise('core.admin')) { $groups = implode(',', User::getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { $query->where('a.state = ' . (int) $published); } elseif ($published === '') { $query->where('(a.state = 0 OR a.state = 1)'); } // Filter by a single or group of categories. $baselevel = 1; $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $cat_tbl = JTable::getInstance('Category', 'JTable'); $cat_tbl->load($categoryId); $rgt = $cat_tbl->rgt; $lft = $cat_tbl->lft; $baselevel = (int) $cat_tbl->level; $query->where('c.lft >= ' . (int) $lft); $query->where('c.rgt <= ' . (int) $rgt); } elseif (is_array($categoryId)) { \Hubzero\Utility\Arr::toInteger($categoryId); $categoryId = implode(',', $categoryId); $query->where('a.catid IN (' . $categoryId . ')'); } // Filter on the level. if ($level = $this->getState('filter.level')) { $query->where('c.level <= ' . ((int) $level + (int) $baselevel - 1)); } // Filter by author $authorId = $this->getState('filter.author_id'); if (is_numeric($authorId)) { $type = $this->getState('filter.author_id.include', true) ? '= ' : '<>'; $query->where('a.created_by ' . $type . (int) $authorId); } // Filter by search in title. $search = $this->getState('filter.search'); if (!empty($search)) { if (stripos($search, 'id:') === 0) { $query->where('a.id = ' . (int) substr($search, 3)); } elseif (stripos($search, 'author:') === 0) { $search = $db->Quote('%' . $db->escape(substr($search, 7), true) . '%'); $query->where('(ua.name LIKE ' . $search . ' OR ua.username LIKE ' . $search . ')'); } else { $search = $db->Quote('%' . $db->escape($search, true) . '%'); $query->where('(a.title LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')'); } } // Filter on the language. if ($language = $this->getState('filter.language')) { $query->where('a.language = ' . $db->quote($language)); } // Add the list ordering clause. $orderCol = $this->state->get('list.ordering', 'a.title'); $orderDirn = $this->state->get('list.direction', 'asc'); if ($orderCol == 'a.ordering' || $orderCol == 'category_title') { $orderCol = 'c.title ' . $orderDirn . ', a.ordering'; } //sqlsrv change if ($orderCol == 'language') { $orderCol = 'l.title'; } if ($orderCol == 'access_level') { $orderCol = 'ag.title'; } $query->order($db->escape($orderCol . ' ' . $orderDirn)); // echo nl2br(str_replace('#__','jos_',$query)); return $query; }
/** * Save the ordering for an array of plugins * * @return void */ public function saveorderTask() { // Check for request forgeries Request::checkToken(['post', 'get']); $cid = Request::getVar('id', array(0), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($cid, array(0)); $total = count($cid); $order = Request::getVar('order', array(0), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($order, array(0)); $row = \JTable::getInstance('extension'); $conditions = array(); // update ordering values for ($i = 0; $i < $total; $i++) { $row->load((int) $cid[$i]); if ($row->ordering != $order[$i]) { $row->ordering = $order[$i]; if (!$row->store()) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $this->database->getErrorMsg(), 'error'); return; } // remember to updateOrder this group $condition = 'folder = ' . $this->database->Quote($row->folder) . ' AND ordering > -10000 AND ordering < 10000 AND client_id = ' . (int) $row->client_id; $found = false; foreach ($conditions as $cond) { if ($cond[1] == $condition) { $found = true; break; } } if (!$found) { $conditions[] = array($row->id, $condition); } } } // execute updateOrder for each group foreach ($conditions as $cond) { $row->load($cond[0]); $row->reorder($cond[1]); } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_RESOURCES_ORDERING_SAVED')); }
/** * Reorder a plugin * * @param integer $access Access level to set * @return void */ public function orderTask() { // Check for request forgeries Request::checkToken(); $id = Request::getVar('id', array(0), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($id, array(0)); $uid = $id[0]; $inc = $this->_task == 'orderup' ? -1 : 1; $row = new Tables\Assetgroup($this->database); $row->load($uid); $row->move($inc, 'unit_id=' . $this->database->Quote($row->unit_id) . ' AND parent=' . $this->database->Quote($row->parent)); $row->reorder('unit_id=' . $this->database->Quote($row->unit_id) . ' AND parent=' . $this->database->Quote($row->parent)); //$unit = \Components\Courses\Models\Unit::getInstance(Request::getInt('unit', 0)); //$ags = $unit->assetgroups(null, array('parent' => $row->parent)); if ($ags = $row->find(array('w' => array('parent' => $row->parent, 'unit_id' => $row->unit_id)))) { foreach ($ags as $ag) { $a = new \Components\Courses\Models\Assetgroup($ag); $a->store(); } } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&unit=' . Request::getInt('unit', 0), false)); }
/** * Reorder a plugin * * @return void */ public function orderTask() { // Check for request forgeries Request::checkToken(); $id = Request::getVar('id', array(0), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($id, array(0)); $uid = $id[0]; $inc = $this->_task == 'orderup' ? -1 : 1; $row = new Tables\Page($this->database); $row->load($uid); $row->move($inc, 'course_id=' . $this->database->Quote($row->course_id) . ' AND offering_id=' . $this->database->Quote($row->offering_id)); $row->reorder('course_id=' . $this->database->Quote($row->course_id) . ' AND offering_id=' . $this->database->Quote($row->offering_id)); $this->cancelTask(); }
/** * Method to get a list of categories that respects access controls and can be used for * either category assignment or parent category assignment in edit screens. * Use the parent element to indicate that the field will be used for assigning parent categories. * * @return array The field option objects. * @since 1.6 */ protected function getOptions() { // Initialise variables. $options = array(); $published = $this->element['published'] ? $this->element['published'] : array(0, 1); $name = (string) $this->element['name']; // Let's get the id for the current item, either category or content item. $jinput = JFactory::getApplication()->input; // Load the category options for a given extension. // For categories the old category is the category id or 0 for new category. if ($this->element['parent'] || $jinput->get('option') == 'com_categories') { $oldCat = $jinput->get('id', 0); $oldParent = $this->form->getValue($name, 0); $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $jinput->get('extension', 'com_content'); } else { $thisItem = $jinput->get('id', 0); $oldCat = $this->form->getValue($name, 0); $extension = $this->element['extension'] ? (string) $this->element['extension'] : (string) $jinput->get('option', 'com_content'); } $db = App::get('db'); $query = $db->getQuery(true); $query->select('a.id AS value, a.title AS text, a.level, a.published'); $query->from('#__categories AS a'); $query->join('LEFT', $db->quoteName('#__categories') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt'); // Filter by the extension type if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') { $query->where('(a.extension = ' . $db->quote($extension) . ' OR a.parent_id = 0)'); } else { $query->where('(a.extension = ' . $db->quote($extension) . ')'); } // If parent isn't explicitly stated but we are in com_categories assume we want parents if ($oldCat != 0 && ($this->element['parent'] == true || $jinput->get('option') == 'com_categories')) { // Prevent parenting to children of this item. // To rearrange parents and children move the children up, not the parents down. $query->join('LEFT', $db->quoteName('#__categories') . ' AS p ON p.id = ' . (int) $oldCat); $query->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)'); $rowQuery = $db->getQuery(true); $rowQuery->select('a.id AS value, a.title AS text, a.level, a.parent_id'); $rowQuery->from('#__categories AS a'); $rowQuery->where('a.id = ' . (int) $oldCat); $db->setQuery($rowQuery); $row = $db->loadObject(); } // Filter on the published state if (is_numeric($published)) { $query->where('a.published = ' . (int) $published); } elseif (is_array($published)) { \Hubzero\Utility\Arr::toInteger($published); $query->where('a.published IN (' . implode(',', $published) . ')'); } $query->group('a.id, a.title, a.level, a.lft, a.rgt, a.extension, a.parent_id, a.published'); $query->order('a.lft ASC'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { throw new Exception($db->getErrorMsg(), 500); } // Pad the option text with spaces using depth level as a multiplier. for ($i = 0, $n = count($options); $i < $n; $i++) { // Translate ROOT if ($this->element['parent'] == true || $jinput->get('option') == 'com_categories') { if ($options[$i]->level == 0) { $options[$i]->text = Lang::txt('JGLOBAL_ROOT_PARENT'); } } if ($options[$i]->published == 1) { $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; } else { $options[$i]->text = str_repeat('- ', $options[$i]->level) . '[' . $options[$i]->text . ']'; } } // For new items we want a list of categories you are allowed to create in. if ($oldCat == 0) { foreach ($options as $i => $option) { // To take save or create in a category you need to have create rights for that category // unless the item is already in that category. // Unset the option if the user isn't authorised for it. In this field assets are always categories. if (User::authorise('core.create', $extension . '.category.' . $option->value) != true) { unset($options[$i]); } } } else { // If you are only allowed to edit in this category but not edit.state, you should not get any // option to change the category parent for a category or the category for a content item, // but you should be able to save in that category. foreach ($options as $i => $option) { if (User::authorise('core.edit.state', $extension . '.category.' . $oldCat) != true && !isset($oldParent)) { if ($option->value != $oldCat) { unset($options[$i]); } } if (User::authorise('core.edit.state', $extension . '.category.' . $oldCat) != true && isset($oldParent) && $option->value != $oldParent) { unset($options[$i]); } // However, if you can edit.state you can also move this to another category for which you have // create permission and you should also still be able to save in the current category. if (User::authorise('core.create', $extension . '.category.' . $option->value) != true && ($option->value != $oldCat && !isset($oldParent))) { unset($options[$i]); } if (User::authorise('core.create', $extension . '.category.' . $option->value) != true && isset($oldParent) && $option->value != $oldParent) { unset($options[$i]); } } } if (($this->element['parent'] == true || $jinput->get('option') == 'com_categories') && (isset($row) && !isset($options[0])) && isset($this->element['show_root'])) { if ($row->parent_id == '1') { $parent = new stdClass(); $parent->text = Lang::txt('JGLOBAL_ROOT_PARENT'); array_unshift($options, $parent); } array_unshift($options, Html::select('option', '0', Lang::txt('JGLOBAL_ROOT'))); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * 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(); \Hubzero\Utility\Arr::toInteger($user_ids); // Non-super admin cannot work with super-admin group if (!User::get('isRoot') && JAccess::checkGroup($group_id, 'core.admin') || $group_id < 1) { $this->setError(Lang::txt('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 // Remove users from a selected group case 'del': $doDelete = 'group'; break; // Add users to a selected group // 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); // Remove users from the group $query->delete($db->quoteName('#__user_usergroup_map')); $query->where($db->quoteName('user_id') . ' IN (' . implode(',', $user_ids) . ')'); // Only remove users from selected group if ($doDelete == 'group') { $query->where($db->quoteName('group_id') . ' = ' . (int) $group_id); } $db->setQuery($query); // Check for database errors. if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } // 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 values clause for the assignment query. $query->clear(); $groups = false; foreach ($user_ids as $id) { if (!in_array($id, $users)) { $query->values($id . ',' . $group_id); $groups = true; } } // If we have no users to process, throw an error to notify the user if (!$groups) { $this->setError(Lang::txt('COM_USERS_ERROR_NO_ADDITIONS')); return false; } $query->insert($db->quoteName('#__user_usergroup_map')); $query->columns(array($db->quoteName('user_id'), $db->quoteName('group_id'))); $db->setQuery($query); // Check for database errors. if (!$db->query()) { $this->setError($db->getErrorMsg()); return false; } } return true; }
/** * Get the master query for retrieving a list of articles subject to the model state. * * @return JDatabaseQuery * @since 1.6 */ function getListQuery() { // Create a new query object. $db = $this->getDbo(); $query = $db->getQuery(true); // Select the required fields from the table. $query->select($this->getState('list.select', 'a.id, a.title, a.alias, a.title_alias, a.introtext, a.language, ' . 'a.checked_out, a.checked_out_time, ' . 'a.catid, a.created, a.created_by, a.created_by_alias, ' . 'CASE WHEN a.modified = 0 THEN a.created ELSE a.modified END as modified, ' . 'a.modified_by, uam.name as modified_by_name,' . 'CASE WHEN a.publish_up = 0 THEN a.created ELSE a.publish_up END as publish_up,' . 'a.publish_down, a.images, a.urls, a.attribs, a.metadata, a.metakey, a.metadesc, a.access, ' . 'a.hits, a.xreference, a.featured,' . ' ' . $query->length('a.fulltext') . ' AS readmore')); // Process an Archived Article layout if ($this->getState('filter.published') == 2) { // If badcats is not null, this means that the article is inside an archived category // In this case, the state is set to 2 to indicate Archived (even if the article state is Published) $query->select($this->getState('list.select', 'CASE WHEN badcats.id is null THEN a.state ELSE 2 END AS state')); } else { // Process non-archived layout // If badcats is not null, this means that the article is inside an unpublished category // In this case, the state is set to 0 to indicate Unpublished (even if the article state is Published) $query->select($this->getState('list.select', 'CASE WHEN badcats.id is not null THEN 0 ELSE a.state END AS state')); } $query->from('#__content AS a'); // Join over the frontpage articles. if ($this->context != 'com_content.featured') { $query->join('LEFT', '#__content_frontpage AS fp ON fp.content_id = a.id'); } // Join over the categories. $query->select('c.title AS category_title, c.path AS category_route, c.access AS category_access, c.alias AS category_alias'); $query->join('LEFT', '#__categories AS c ON c.id = a.catid'); // Join over the users for the author and modified_by names. $query->select("CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author"); $query->select("ua.email AS author_email"); $query->join('LEFT', '#__users AS ua ON ua.id = a.created_by'); $query->join('LEFT', '#__users AS uam ON uam.id = a.modified_by'); // Get contact id $subQuery = $db->getQuery(true); $subQuery->select('MAX(contact.id) AS id'); $subQuery->from('#__contact_details AS contact'); $subQuery->where('contact.published = 1'); $subQuery->where('contact.user_id = a.created_by'); // Filter by language if ($this->getState('filter.language')) { $subQuery->where('(contact.language in (' . $db->quote(Lang::getTag()) . ',' . $db->quote('*') . ') OR contact.language IS NULL)'); } // [!] Hubzero - Removed contact_details table //$query->select('(' . $subQuery . ') as contactid'); $query->select('(0) as contactid'); // Join over the categories to get parent category titles $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias'); $query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); // Join on voting table $query->select('ROUND(v.rating_sum / v.rating_count, 0) AS rating, v.rating_count as rating_count'); $query->join('LEFT', '#__content_rating AS v ON a.id = v.content_id'); // Join to check for category published state in parent categories up the tree $query->select('c.published, CASE WHEN badcats.id is null THEN c.published ELSE 0 END AS parents_published'); $subquery = 'SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent '; $subquery .= 'ON cat.lft BETWEEN parent.lft AND parent.rgt '; $subquery .= 'WHERE parent.extension = ' . $db->quote('com_content'); if ($this->getState('filter.published') == 2) { // Find any up-path categories that are archived // If any up-path categories are archived, include all children in archived layout $subquery .= ' AND parent.published = 2 GROUP BY cat.id '; // Set effective state to archived if up-path category is archived $publishedWhere = 'CASE WHEN badcats.id is null THEN a.state ELSE 2 END'; } else { // Find any up-path categories that are not published // If all categories are published, badcats.id will be null, and we just use the article state $subquery .= ' AND parent.published != 1 GROUP BY cat.id '; // Select state to unpublished if up-path category is unpublished $publishedWhere = 'CASE WHEN badcats.id is null THEN a.state ELSE 0 END'; } $query->join('LEFT OUTER', '(' . $subquery . ') AS badcats ON badcats.id = c.id'); // Filter by access level. if ($access = $this->getState('filter.access')) { $groups = implode(',', User::getAuthorisedViewLevels()); $query->where('a.access IN (' . $groups . ')'); $query->where('c.access IN (' . $groups . ')'); } // Filter by published state $published = $this->getState('filter.published'); if (is_numeric($published)) { // Use article state if badcats.id is null, otherwise, force 0 for unpublished $query->where($publishedWhere . ' = ' . (int) $published); } elseif (is_array($published)) { \Hubzero\Utility\Arr::toInteger($published); $published = implode(',', $published); // Use article state if badcats.id is null, otherwise, force 0 for unpublished $query->where($publishedWhere . ' IN (' . $published . ')'); } // Filter by featured state $featured = $this->getState('filter.featured'); switch ($featured) { case 'hide': $query->where('a.featured = 0'); break; case 'only': $query->where('a.featured = 1'); break; case 'show': default: // Normally we do not discriminate // between featured/unfeatured items. break; } // Filter by a single or group of articles. $articleId = $this->getState('filter.article_id'); if (is_numeric($articleId)) { $type = $this->getState('filter.article_id.include', true) ? '= ' : '<> '; $query->where('a.id ' . $type . (int) $articleId); } elseif (is_array($articleId)) { \Hubzero\Utility\Arr::toInteger($articleId); $articleId = implode(',', $articleId); $type = $this->getState('filter.article_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.id ' . $type . ' (' . $articleId . ')'); } // Filter by a single or group of categories $categoryId = $this->getState('filter.category_id'); if (is_numeric($categoryId)) { $type = $this->getState('filter.category_id.include', true) ? '= ' : '<> '; // Add subcategory check $includeSubcategories = $this->getState('filter.subcategories', false); $categoryEquals = 'a.catid ' . $type . (int) $categoryId; if ($includeSubcategories) { $levels = (int) $this->getState('filter.max_category_levels', '1'); // Create a subquery for the subcategory list $subQuery = $db->getQuery(true); $subQuery->select('sub.id'); $subQuery->from('#__categories as sub'); $subQuery->join('INNER', '#__categories as this ON sub.lft > this.lft AND sub.rgt < this.rgt'); $subQuery->where('this.id = ' . (int) $categoryId); if ($levels >= 0) { $subQuery->where('sub.level <= this.level + ' . $levels); } // Add the subquery to the main query $query->where('(' . $categoryEquals . ' OR a.catid IN (' . $subQuery->__toString() . '))'); } else { $query->where($categoryEquals); } } elseif (is_array($categoryId) && count($categoryId) > 0) { \Hubzero\Utility\Arr::toInteger($categoryId); $categoryId = implode(',', $categoryId); if (!empty($categoryId)) { $type = $this->getState('filter.category_id.include', true) ? 'IN' : 'NOT IN'; $query->where('a.catid ' . $type . ' (' . $categoryId . ')'); } } // Filter by author $authorId = $this->getState('filter.author_id'); $authorWhere = ''; if (is_numeric($authorId)) { $type = $this->getState('filter.author_id.include', true) ? '= ' : '<> '; $authorWhere = 'a.created_by ' . $type . (int) $authorId; } elseif (is_array($authorId)) { \Hubzero\Utility\Arr::toInteger($authorId); $authorId = implode(',', $authorId); if ($authorId) { $type = $this->getState('filter.author_id.include', true) ? 'IN' : 'NOT IN'; $authorWhere = 'a.created_by ' . $type . ' (' . $authorId . ')'; } } // Filter by author alias $authorAlias = $this->getState('filter.author_alias'); $authorAliasWhere = ''; if (is_string($authorAlias)) { $type = $this->getState('filter.author_alias.include', true) ? '= ' : '<> '; $authorAliasWhere = 'a.created_by_alias ' . $type . $db->Quote($authorAlias); } elseif (is_array($authorAlias)) { $first = current($authorAlias); if (!empty($first)) { \Hubzero\Utility\Arr::toString($authorAlias); foreach ($authorAlias as $key => $alias) { $authorAlias[$key] = $db->Quote($alias); } $authorAlias = implode(',', $authorAlias); if ($authorAlias) { $type = $this->getState('filter.author_alias.include', true) ? 'IN' : 'NOT IN'; $authorAliasWhere = 'a.created_by_alias ' . $type . ' (' . $authorAlias . ')'; } } } if (!empty($authorWhere) && !empty($authorAliasWhere)) { $query->where('(' . $authorWhere . ' OR ' . $authorAliasWhere . ')'); } elseif (empty($authorWhere) && empty($authorAliasWhere)) { // If both are empty we don't want to add to the query } else { // One of these is empty, the other is not so we just add both $query->where($authorWhere . $authorAliasWhere); } // Define null and now dates $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(Date::toSql()); if (!User::authorise('core.edit.state', 'com_content') && !User::authorise('core.edit', 'com_content')) { // Filter by start and end dates. $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } // Filter by Date Range or Relative Date $dateFiltering = $this->getState('filter.date_filtering', 'off'); $dateField = $this->getState('filter.date_field', 'a.created'); switch ($dateFiltering) { case 'range': $startDateRange = $db->Quote($this->getState('filter.start_date_range', $nullDate)); $endDateRange = $db->Quote($this->getState('filter.end_date_range', $nullDate)); $query->where('(' . $dateField . ' >= ' . $startDateRange . ' AND ' . $dateField . ' <= ' . $endDateRange . ')'); break; case 'relative': $relativeDate = (int) $this->getState('filter.relative_date', 0); $query->where($dateField . ' >= DATE_SUB(' . $nowDate . ', INTERVAL ' . $relativeDate . ' DAY)'); break; case 'off': default: break; } // process the filter for list views with user-entered filters $params = $this->getState('params'); if (is_object($params) && $params->get('filter_field') != 'hide' && ($filter = $this->getState('list.filter'))) { // clean filter variable $filter = JString::strtolower($filter); $hitsFilter = intval($filter); $filter = $db->Quote('%' . $db->escape($filter, true) . '%', false); switch ($params->get('filter_field')) { case 'author': $query->where('LOWER( CASE WHEN a.created_by_alias > ' . $db->quote(' ') . ' THEN a.created_by_alias ELSE ua.name END ) LIKE ' . $filter . ' '); break; case 'hits': $query->where('a.hits >= ' . $hitsFilter . ' '); break; case 'title': default: // default to 'title' if parameter is not valid $query->where('LOWER( a.title ) LIKE ' . $filter); break; } } // Filter by language if ($this->getState('filter.language')) { $query->where('a.language in (' . $db->quote(Lang::getTag()) . ',' . $db->quote('*') . ')'); } // Add the list ordering clause. $query->order($this->getState('list.ordering', 'a.ordering') . ' ' . $this->getState('list.direction', 'ASC')); return $query; }
/** * Method to save the submitted ordering values for records. * * @return boolean True on success */ public function saveorderTask() { // Check for request forgeries. Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Get the input $pks = Request::getVar('cid', null, 'post', 'array'); $order = Request::getVar('order', null, 'post', 'array'); // Sanitize the input Arr::toInteger($pks); Arr::toInteger($order); // Get the model $model = new Models\Plugin(); // Save the ordering $return = $model->saveorder($pks, $order); if ($return === false) { // Reorder failed Notify::error(Lang::txt('JLIB_APPLICATION_ERROR_REORDER_FAILED', $model->getError())); } else { // Reorder succeeded. Notify::success(Lang::txt('JLIB_APPLICATION_SUCCESS_ORDERING_SAVED')); } App::redirect(Route::url('index.php?option=' . $this->_option, false)); }
/** Deletes and returns correctly. * * @return void * @since 2.5.12 */ public function delete() { Session::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); // Get items to remove from the request. $cid = Request::getVar('cid', array(), '', 'array'); $extension = Request::getVar('extension', null); if (!is_array($cid) || count($cid) < 1) { Notify::error(Lang::txt($this->text_prefix . '_NO_ITEM_SELECTED')); } else { // Get the model. $model = $this->getModel(); // Make sure the item ids are integers \Hubzero\Utility\Arr::toInteger($cid); // Remove the items. if ($model->delete($cid)) { $this->setMessage(Lang::txts($this->text_prefix . '_N_ITEMS_DELETED', count($cid))); } else { $this->setMessage($model->getError()); } } $this->setRedirect(Route::url('index.php?option=' . $this->option . '&extension=' . $extension, false)); }
/** * Install languages. * * @return void */ public function installTask() { $model = new Models\Languages(); // Get array of selected languages $lids = Request::getVar('cid', array(), '', 'array'); \Hubzero\Utility\Arr::toInteger($lids, array()); if (!$lids) { // No languages have been selected Notify::warning(Lang::txt('COM_INSTALLER_MSG_DISCOVER_NOEXTENSIONSELECTED')); } else { // Install selected languages $model->install($lids); } App::redirect(Route::url('index.php?option=com_installer&view=languages', false)); }
/** * Save order * * @return void */ public function saveorderTask() { // Check for request forgeries Request::checkToken(); if (!User::authorise('core.manage', $this->_option) && !User::authorise('core.admin', $this->_option) && !User::authorise('core.edit', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Get the id's $cid = Request::getVar('id', array(0), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($cid, array(0)); // Get total and order values $total = count($cid); $order = Request::getVar('order', array(0), 'post', 'array'); \Hubzero\Utility\Arr::toInteger($order, array(0)); // Update ordering values for ($i = 0; $i < $total; $i++) { $row = Rule::oneOrFail((int) $cid[$i]); if ($row->get('ordering') != $order[$i]) { $row->set('ordering', $order[$i]); if (!$row->save()) { App::abort(500, $row->getError()); } } } Notify::success(Lang::txt('COM_MEMBERS_PASSWORD_RULES_ORDERING_SAVED')); // Output message and redirect $this->cancelTask(); }
/** * Mark a poll as open or closed * * @return void */ public function openTask() { // Check for request forgeries Request::checkToken(['get', 'post']); if (!User::authorise('core.edit.state', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } $ids = Request::getVar('id', array()); Arr::toInteger($ids); $publish = Request::getVar('task') == 'open' ? 1 : 0; if (count($ids) < 1) { $action = $publish ? 'COM_POLL_OPEN' : 'COM_POLL_CLOSE'; Notify::warning(Lang::txt('COM_POLL_SELECT_ITEM_TO', Lang::txt($action), true)); return $this->cancelTask(); } foreach ($ids as $id) { $poll = Poll::oneOrFail(intval($id)); if ($poll->get('checked_out') && $poll->get('checked_out') != User::get('id')) { continue; } $poll->set('open', (int) $publish); if (!$poll->save()) { Notify::error($poll->getError()); } } $this->cancelTask(); }
/** * Method to apply an input filter to a value based on field data. * * @param string $element The XML element object representation of the form field. * @param mixed $value The value to filter for the field. * @return mixed The filtered value. */ protected function filterField($element, $value) { // Make sure there is a valid SimpleXMLElement. if (!$element instanceof SimpleXMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Access Control Rules. case 'RULES': $return = array(); foreach ((array) $value as $action => $ids) { // Build the rules array. $return[$action] = array(); foreach ($ids as $id => $p) { if ($p !== '') { $return[$action][$id] = $p == '1' || $p == 'true' ? true : false; } } } break; // Do nothing, thus leaving the return value as null. // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); Arr::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $return = String::clean($value, 'string'); break; // Convert a date to UTC based on the server timezone offset. // Convert a date to UTC based on the server timezone offset. case 'SERVER_UTC': if (intval($value) > 0) { // Get the server timezone setting. $offset = App::get('config')->get('offset'); // Return an SQL formatted datetime string in UTC. $return = with(new Date($value, $offset))->toSql(); } else { $return = ''; } break; // Convert a date to UTC based on the user timezone offset. // Convert a date to UTC based on the user timezone offset. case 'USER_UTC': if (intval($value) > 0) { // Get the user timezone setting defaulting to the server timezone setting. $offset = App::get('user')->getParam('timezone', App::get('config')->get('offset')); // Return a MySQL formatted datetime string in UTC. $return = with(new Date($value, $offset))->toSql(); } else { $return = ''; } break; // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See FormRuleUrl for list of these. // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See FormRuleUrl for list of these. case 'URL': if (empty($value)) { return false; } $value = String::clean($value); $value = trim($value); // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt. $value = str_replace(array('<', '>', '"'), '', $value); // Check for a protocol $protocol = parse_url($value, PHP_URL_SCHEME); // If there is no protocol and the relative option is not specified, // we assume that it is an external URL and prepend http://. if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) { $protocol = 'http'; // If it looks like an internal link, then add the root. if (substr($value, 0, 9) == 'index.php') { $value = App::get('request')->root() . $value; } else { // Put the url back together. $value = $protocol . '://' . $value; } } elseif (!$protocol && $element['relative']) { $host = App::get('request')->host(); // If it starts with the host string, just prepend the protocol. if (substr($value, 0) == $host) { $value = 'http://' . $value; } else { $value = App::get('request')->root() . $value; } } $return = $value; break; case 'TEL': $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\\d]/', '', $value); if (substr($number, 0, 1) == 1) { $number = substr($number, 1); } if (substr($number, 0, 2) == '+1') { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) { $result = $value; } else { $value = (string) preg_replace('/[^\\d]/', '', $value); if ($value != null && strlen($value) <= 15) { $length = strlen($value); // if it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { $result = ''; } } $return = $result; break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } elseif (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $return = String::clean($value, $filter); } break; } return $return; }
/** * Installs a discovered extension. * * @since 1.6 */ public function discover_install() { $installer = \JInstaller::getInstance(); $eid = Request::getVar('cid', 0); if (is_array($eid) || $eid) { if (!is_array($eid)) { $eid = array($eid); } \Hubzero\Utility\Arr::toInteger($eid); $failed = false; foreach ($eid as $id) { $result = $installer->discover_install($id); if (!$result) { $failed = true; Notify::error(Lang::txt('COM_INSTALLER_MSG_DISCOVER_INSTALLFAILED') . ': ' . $id); } } $this->setState('action', 'remove'); $this->setState('name', $installer->get('name')); User::setState('com_installer.message', $installer->message); User::setState('com_installer.extension_message', $installer->get('extension_message')); if (!$failed) { Notify::success(Lang::txt('COM_INSTALLER_MSG_DISCOVER_INSTALLSUCCESSFUL')); } } else { Notify::warning(Lang::txt('COM_INSTALLER_MSG_DISCOVER_NOEXTENSIONSELECTED')); } }
/** * Method to save the form data. * * @param array The form data. * @return boolean True on success. */ public function save($data) { // Detect disabled extension $extension = JTable::getInstance('Extension'); if ($extension->load(array('enabled' => 0, 'type' => 'template', 'element' => $data['template'], 'client_id' => $data['client_id']))) { $this->setError(Lang::txt('COM_TEMPLATES_ERROR_SAVE_DISABLED_TEMPLATE')); return false; } // Initialise variables; $table = $this->getTable(); $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState('style.id'); $isNew = true; // Load the row if saving an existing record. if ($pk > 0) { $table->load($pk); $isNew = false; } if (Request::getVar('task') == 'save2copy') { $data['title'] = $this->generateNewTitle(null, null, $data['title']); $data['home'] = 0; $data['assigned'] = ''; } // Bind the data. if (!$table->bind($data)) { $this->setError($table->getError()); return false; } // Prepare the row for saving $this->prepareTable($table); // Check the data. if (!$table->check()) { $this->setError($table->getError()); return false; } // Trigger the onExtensionBeforeSave event. $result = Event::trigger('extension.onExtensionBeforeSave', array('com_templates.style', &$table, $isNew)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } // Store the data. if (!$table->store()) { $this->setError($table->getError()); return false; } if (User::authorise('core.edit', 'com_menus') && $table->client_id == 0) { $n = 0; $db = App::get('db'); if (!empty($data['assigned']) && is_array($data['assigned'])) { \Hubzero\Utility\Arr::toInteger($data['assigned']); // Update the mapping for menu items that this style IS assigned to. $query = $db->getQuery(true); $query->update('#__menu'); $query->set('template_style_id=' . (int) $table->id); $query->where('id IN (' . implode(',', $data['assigned']) . ')'); $query->where('template_style_id!=' . (int) $table->id); $query->where('checked_out in (0,' . (int) User::get('id') . ')'); $db->setQuery($query); $db->query(); $n += $db->getAffectedRows(); } // Remove style mappings for menu items this style is NOT assigned to. // If unassigned then all existing maps will be removed. $query = $db->getQuery(true); $query->update('#__menu'); $query->set('template_style_id=0'); if (!empty($data['assigned'])) { $query->where('id NOT IN (' . implode(',', $data['assigned']) . ')'); } $query->where('template_style_id=' . (int) $table->id); $query->where('checked_out in (0,' . (int) User::get('id') . ')'); $db->setQuery($query); $db->query(); $n += $db->getAffectedRows(); if ($n > 0) { Notify::success(Lang::txts('COM_TEMPLATES_MENU_CHANGED', $n)); } } // Clean the cache. $this->cleanCache(); // Trigger the onExtensionAfterSave event. Event::trigger('extension.onExtensionAfterSave', array('com_templates.style', &$table, $isNew)); $this->setState('style.id', $table->id); return true; }
/** * Refreshes the cached metadata about an extension. * * Useful for debugging and testing purposes when the XML file might change. * * @since 1.6 */ public function refreshTask() { // Check for request forgeries Request::checkToken() or exit(Lang::txt('JINVALID_TOKEN')); $uid = Request::getVar('cid', array(), '', 'array'); $model = new Models\Manage(); \Hubzero\Utility\Arr::toInteger($uid, array()); $result = $model->refresh($uid); App::redirect(Route::url('index.php?option=com_installer&controller=manage', false)); }
/** * Method to delete groups. * * @param array An array of item ids. * @return boolean Returns true on success, false on failure. */ public function delete($itemIds) { // Sanitize the ids. $itemIds = (array) $itemIds; \Hubzero\Utility\Arr::toInteger($itemIds); // Get a group row instance. $table = $this->getTable(); // Iterate the items to delete each one. foreach ($itemIds as $itemId) { // TODO: Delete the menu associations - Menu items and Modules if (!$table->delete($itemId)) { $this->setError($table->getError()); return false; } } // Clean the cache $this->cleanCache(); return true; }
/** * 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)); }