Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 /**
  * 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');
 }
Exemplo n.º 3
0
 /**
  * Returns an object list
  *
  * @param	string The query
  * @param	int Offset
  * @param	int The number of records
  * @return	array
  */
 protected function _getList($query, $limitstart = 0, $limit = 0)
 {
     $ordering = $this->getState('list.ordering');
     $search = $this->getState('filter.search');
     // Replace slashes so preg_match will work
     $search = str_replace('/', ' ', $search);
     $db = $this->getDbo();
     if ($ordering == 'name' || !empty($search) && stripos($search, 'id:') !== 0) {
         $db->setQuery($query);
         $result = $db->loadObjectList();
         $lang = Lang::getRoot();
         $this->translate($result);
         if (!empty($search)) {
             foreach ($result as $i => $item) {
                 if (!preg_match("/{$search}/i", $item->name)) {
                     unset($result[$i]);
                 }
             }
         }
         \Hubzero\Utility\Arr::sortObjects($result, $this->getState('list.ordering'), $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale());
         $total = count($result);
         $this->cache[$this->getStoreId('getTotal')] = $total;
         if ($total < $limitstart) {
             $limitstart = 0;
             $this->setState('list.start', 0);
         }
         return array_slice($result, $limitstart, $limit ? $limit : null);
     } else {
         $query->order($db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
         $result = parent::_getList($query, $limitstart, $limit);
         $this->translate($result);
         return $result;
     }
 }
Exemplo n.º 4
0
 /**
  * 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');
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * @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;
 }
Exemplo n.º 7
0
 /**
  * Override preprocessForm to load the user plugin group instead of content.
  *
  * @param	object	A form object.
  * @param	mixed	The data expected for the form.
  * @throws	Exception if there is an error in the form event.
  * @since	1.6
  */
 protected function preprocessForm(JForm $form, $data, $groups = '')
 {
     $obj = is_array($data) ? \Hubzero\Utility\Arr::toObject($data, '\\Hubzero\\Base\\Object') : $data;
     if (isset($obj->parent_id) && $obj->parent_id == 0 && $obj->id > 0) {
         $form->setFieldAttribute('parent_id', 'type', 'hidden');
         $form->setFieldAttribute('parent_id', 'hidden', 'true');
     }
     parent::preprocessForm($form, $data, 'user');
 }
Exemplo n.º 8
0
 /**
  * Get a link
  *
  * @param   object  $params  Registry
  * @return  string
  */
 static function getLink(&$params)
 {
     $data = Document::getHeadData();
     foreach ($data['links'] as $link => $value) {
         $value = Arr::toString($value);
         if (strpos($value, 'application/' . $params->get('format') . '+xml')) {
             return $link;
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Overrides the getItems method to attach additional metrics to the list.
  *
  * @return  mixed  An array of data items on success, false on failure.
  *
  * @since   1.6.1
  */
 public function getItems()
 {
     // Get a storage key.
     $store = $this->getStoreId('getItems');
     // Try to load the data from internal storage.
     if (!empty($this->cache[$store])) {
         return $this->cache[$store];
     }
     // Load the list items.
     $items = parent::getItems();
     // If emtpy or an error, just return.
     if (empty($items)) {
         return array();
     }
     // Getting the following metric by joins is WAY TOO SLOW.
     // Faster to do three queries for very large menu trees.
     // Get the menu types of menus in the list.
     $db = $this->getDbo();
     $menuTypes = \Hubzero\Utility\Arr::getColumn($items, 'menutype');
     // Quote the strings.
     $menuTypes = implode(',', array_map(array($db, 'quote'), $menuTypes));
     // Get the published menu counts.
     $query = $db->getQuery(true)->select('m.menutype, COUNT(DISTINCT m.id) AS count_published')->from('#__menu AS m')->where('m.published = 1')->where('m.menutype IN (' . $menuTypes . ')')->group('m.menutype');
     $db->setQuery($query);
     $countPublished = $db->loadAssocList('menutype', 'count_published');
     if ($db->getErrorNum()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     // Get the unpublished menu counts.
     $query->clear('where')->where('m.published = 0')->where('m.menutype IN (' . $menuTypes . ')');
     $db->setQuery($query);
     $countUnpublished = $db->loadAssocList('menutype', 'count_published');
     if ($db->getErrorNum()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     // Get the trashed menu counts.
     $query->clear('where')->where('m.published = -2')->where('m.menutype IN (' . $menuTypes . ')');
     $db->setQuery($query);
     $countTrashed = $db->loadAssocList('menutype', 'count_published');
     if ($db->getErrorNum()) {
         $this->setError($db->getErrorMsg());
         return false;
     }
     // Inject the values back into the array.
     foreach ($items as $item) {
         $item->count_published = isset($countPublished[$item->menutype]) ? $countPublished[$item->menutype] : 0;
         $item->count_unpublished = isset($countUnpublished[$item->menutype]) ? $countUnpublished[$item->menutype] : 0;
         $item->count_trashed = isset($countTrashed[$item->menutype]) ? $countTrashed[$item->menutype] : 0;
     }
     // Add the items to the internal cache.
     $this->cache[$store] = $items;
     return $this->cache[$store];
 }
 /**
  * @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;
 }
Exemplo n.º 11
0
 /**
  * @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;
 }
Exemplo n.º 12
0
 /**
  * @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;
 }
Exemplo n.º 13
0
 /**
  * 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;
 }
Exemplo n.º 14
0
 /**
  * Method to get article data.
  *
  * @param	integer	The id of the article.
  *
  * @return	mixed	Content item data object on success, false on failure.
  */
 public function &getItem($pk = NULL)
 {
     // Initialise variables.
     $itemId = $pk;
     $itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('article.id');
     // Get a row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($itemId);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return false;
     }
     $properties = $table->getProperties(1);
     $value = \Hubzero\Utility\Arr::toObject($properties, '\\Hubzero\\Base\\Object');
     // Convert attrib field to Registry.
     $value->params = new \Hubzero\Config\Registry($value->attribs);
     // Compute selected asset permissions.
     $userId = User::get('id');
     $asset = 'com_content.article.' . $value->id;
     // Check general edit permission first.
     if (User::authorise('core.edit', $asset)) {
         $value->params->set('access-edit', true);
     } elseif (!empty($userId) && User::authorise('core.edit.own', $asset)) {
         // Check for a valid user and that they are the owner.
         if ($userId == $value->created_by) {
             $value->params->set('access-edit', true);
         }
     }
     // Check edit state permission.
     if ($itemId) {
         // Existing item
         $value->params->set('access-change', User::authorise('core.edit.state', $asset));
     } else {
         // New item.
         $catId = (int) $this->getState('article.catid');
         if ($catId) {
             $value->params->set('access-change', User::authorise('core.edit.state', 'com_content.category.' . $catId));
             $value->catid = $catId;
         } else {
             $value->params->set('access-change', User::authorise('core.edit.state', 'com_content'));
         }
     }
     $value->articletext = $value->introtext;
     if (!empty($value->fulltext)) {
         $value->articletext .= '<hr id="system-readmore" />' . $value->fulltext;
     }
     return $value;
 }
Exemplo n.º 15
0
 /**
  * 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;
     }
 }
Exemplo n.º 16
0
 /**
  * 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'));
 }
Exemplo n.º 17
0
 /**
  * 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));
 }
Exemplo n.º 18
0
 /**
  * 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 \\/\\>|", "#<#", "#>#", "|&#39;|", '#&quot;#', '#&nbsp;#');
     $html_entities_replace = array("\n", '&lt;', '&gt;', "'", '"', ' ');
     $text = preg_replace($html_entities_match, $html_entities_replace, $text);
     $text = str_replace('&lt;', '<', $text);
     $text = str_replace('&gt;', '>', $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;
 }
Exemplo n.º 19
0
 /**
  * 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);
 }
Exemplo n.º 20
0
 /**
  * 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);
 }
Exemplo n.º 21
0
 /**
  * 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');
 }
Exemplo n.º 22
0
 /**
  * Method to get a member item.
  *
  * @param	integer	The id of the member to get.
  *
  * @return	mixed	User data object on success, false on failure.
  * @since	1.0
  */
 public function getItem($langId = null)
 {
     // Initialise variables.
     $langId = !empty($langId) ? $langId : (int) $this->getState('language.id');
     $false = false;
     // Get a member row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($langId);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return $false;
     }
     // Set a valid accesslevel in case '0' is stored due to a bug in the installation SQL.
     if ($table->access == '0') {
         $table->access = (int) Config::get('access');
     }
     $properties = $table->getProperties(1);
     $value = \Hubzero\Utility\Arr::toObject($properties, '\\Hubzero\\Base\\Object');
     return $value;
 }
Exemplo n.º 23
0
 /**
  * Get a list of the components.
  *
  * @return  array
  */
 public static function getComponents()
 {
     // Initialise variable.
     $db = App::get('db');
     $query = $db->getQuery(true);
     $query->select('name AS text, element AS value')->from('#__extensions')->where('enabled >= 1')->where('type =' . $db->Quote('component'));
     $items = $db->setQuery($query)->loadObjectList();
     if (count($items)) {
         $lang = Lang::getRoot();
         foreach ($items as &$item) {
             // Load language
             $extension = $item->value;
             $source = PATH_CORE . '/components/' . $extension . '/admin';
             $lang->load("{$extension}.sys", PATH_APP, null, false, true) || $lang->load("{$extension}.sys", $source, null, false, true);
             // Translate component name
             $item->text = Lang::txt($item->text);
         }
         // Sort by component name
         \Hubzero\Utility\Arr::sortObjects($items, 'text', 1, true, $lang->getLocale());
     }
     return $items;
 }
Exemplo n.º 24
0
 /**
  * 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');
 }
Exemplo n.º 25
0
 /**
  * Create a new configuration repository.
  *
  * @param   string  $path
  * @return  void
  */
 public function __construct($path = null)
 {
     if (!$path) {
         $path = PATH_ROOT;
     }
     $this->file = $path . DS . 'configuration.php';
     if ($this->file) {
         $data = $this->read($this->file);
         $data = \Hubzero\Utility\Arr::fromObject($data);
         $config = array();
         foreach ($data as $key => $value) {
             foreach ($this->map as $group => $values) {
                 if (!isset($config[$group])) {
                     $config[$group] = array();
                 }
                 if (in_array($key, $values)) {
                     $config[$group][$key] = $value;
                 }
             }
         }
         parent::__construct($config);
     }
 }
Exemplo n.º 26
0
 /**
  * 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');
 }
Exemplo n.º 27
0
 /**
  * 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;
 }
Exemplo n.º 28
0
 /**
  * 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();
 }
Exemplo n.º 29
0
 /**
  * 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;
 }
Exemplo n.º 30
0
 /**
  * Get a list of the authorised, non-special components to display in the components menu.
  *
  * @param   boolean  $authCheck  An optional switch to turn off the auth check (to support custom layouts 'grey out' behaviour).
  * @return  array    A nest array of component objects and submenus
  */
 public static function getComponents($authCheck = true)
 {
     // Initialise variables.
     $lang = App::get('language');
     $user = User::getRoot();
     $db = \App::get('db');
     $query = $db->getQuery(true);
     $result = array();
     $langs = array();
     // Prepare the query.
     $query->select('m.id, m.title, m.alias, m.link, m.parent_id, m.img, e.element, e.protected');
     $query->from('#__menu AS m');
     // Filter on the enabled states.
     $query->leftJoin('#__extensions AS e ON m.component_id = e.extension_id');
     $query->where('m.client_id = 1');
     $query->where('e.enabled = 1');
     $query->where('m.id > 1');
     // Order by lft.
     $query->order('m.lft');
     $db->setQuery($query);
     // Component list
     $components = $db->loadObjectList();
     // Parse the list of extensions.
     foreach ($components as &$component) {
         // Trim the menu link.
         $component->link = trim($component->link);
         if ($component->parent_id == 1) {
             // Only add this top level if it is authorised and enabled.
             if ($authCheck == false || $authCheck && $user->authorise('core.manage', $component->element)) {
                 // Root level.
                 $result[$component->id] = $component;
                 if (!isset($result[$component->id]->submenu)) {
                     $result[$component->id]->submenu = array();
                 }
                 // If the root menu link is empty, add it in.
                 if (empty($component->link)) {
                     $component->link = 'index.php?option=' . $component->element;
                 }
                 if (!empty($component->element)) {
                     // Load the core file then
                     // Load extension-local file.
                     $lang->load($component->element . '.sys', PATH_APP . '/bootstrap/administrator', null, false, false) || $lang->load($component->element . '.sys', ($component->protected ? PATH_CORE : PATH_APP) . '/components/' . $component->element . '/admin', null, false, false) || $lang->load($component->element . '.sys', PATH_APP . '/bootstrap/administrator', $lang->getDefault(), false, false) || $lang->load($component->element . '.sys', ($component->protected ? PATH_CORE : PATH_APP) . '/components/' . $component->element . '/admin', $lang->getDefault(), false, false);
                 }
                 $component->text = $lang->hasKey($component->title) ? Lang::txt($component->title) : $component->alias;
             }
         } else {
             // Sub-menu level.
             if (isset($result[$component->parent_id])) {
                 // Add the submenu link if it is defined.
                 if (isset($result[$component->parent_id]->submenu) && !empty($component->link)) {
                     $component->text = $lang->hasKey($component->title) ? Lang::txt($component->title) : $component->alias;
                     $result[$component->parent_id]->submenu[] =& $component;
                 }
             }
         }
     }
     $result = Arr::sortObjects($result, 'text', 1, true, $lang->getLocale());
     return $result;
 }