public function post() { // Set variables to be used JMHelper::setSessionUser(); JFactory::getLanguage()->load('com_users', JPATH_ADMINISTRATOR); // Include dependencies jimport('joomla.application.component.controller'); jimport('joomla.form.form'); jimport('joomla.database.table'); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_users/models'); JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_users/models/forms'); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_users/tables'); // Get user data $data = JRequest::getVar('jform', array(), 'post', 'array'); if (!isset($data['groups'])) { $data['groups'] = array(); } // Save user $model = JModel::getInstance('User', 'UsersModel'); $model->getState('user.id'); // This is only here to trigger populateState() $success = $model->save($data); if ($model->getError()) { $response = $this->getErrorResponse(400, $model->getError()); } elseif (!$success) { $response = $this->getErrorResponse(400, JText::_('COM_JM_ERROR_OCURRED')); } else { $response = $this->getSuccessResponse(201, JText::_('COM_JM_SUCCESS')); $response->id = $model->getState('user.id'); } $this->plugin->setResponse($response); }
public function post() { // Set variables to be used JMHelper::setSessionUser(); // Include dependencies jimport('joomla.database.table'); $language = JFactory::getLanguage(); $language->load('joomla', JPATH_ADMINISTRATOR); $language->load('com_categories', JPATH_ADMINISTRATOR); require_once JPATH_ADMINISTRATOR . '/components/com_categories/models/category.php'; // Fake parameters $_POST['task'] = 'apply'; $_REQUEST['task'] = 'apply'; $_REQUEST[JUtility::getToken()] = 1; $_POST[JUtility::getToken()] = 1; $data = JRequest::getVar('jform', array(), 'post', 'array'); $context = 'category'; // Clear userstate just in case $model = JModel::getInstance('Category', 'CategoriesModel'); $success = $model->save($data); if ($model->getError()) { $response = $this->getErrorResponse(400, $model->getError()); } elseif (!$success) { $response = $this->getErrorResponse(400, JText::_('COM_JM_ERROR_OCURRED')); } else { $response = $this->getSuccessResponse(201, JText::_('COM_CATEGORIES_SAVE_SUCCESS')); // Get the ID of the category that was modified or inserted $response->id = $model->get('state')->get($context . '.id'); // Checkin category $model->checkin($response->id); } $this->plugin->setResponse($response); }
/** * This is not the best example to follow * Please see the category plugin for a better example */ public function post() { // Set variables to be used JMHelper::setSessionUser(); // Include dependencies jimport('joomla.database.table'); $language = JFactory::getLanguage(); $language->load('joomla', JPATH_ADMINISTRATOR); $language->load('com_k2', JPATH_ADMINISTRATOR); require_once JPATH_ADMINISTRATOR . '/components/com_k2/models/item.php'; JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables'); // Fake parameters $_REQUEST[JUtility::getToken()] = 1; $_POST[JUtility::getToken()] = 1; // Clear userstate just in case $row = $this->save(); if ($this->getError()) { $response = $this->getErrorResponse(400, $this->getError()); } elseif (!$row->id) { $response = $this->getErrorResponse(400, JText::_('COM_JM_ERROR_OCURRED')); } else { $response = $this->getSuccessResponse(201, JText::_('COM_JM_SUCCESS')); // Get the ID of the category that was modified or inserted $response->id = $row->id; } $this->plugin->setResponse($response); }
public function get() { JMHelper::setSessionUser(); $editors = self::getEditors(); if (JRequest::getVar('default', false)) { $editors = array_merge(array((object) array('value' => '', 'text' => JText::_('JOPTION_USE_DEFAULT'))), $editors); } $this->plugin->setResponse($editors); }
public function get() { JMHelper::setSessionUser(); $options = array(); if (JRequest::getVar('default', false)) { $options = array((object) array('value' => '', 'text' => JText::_('JOPTION_USE_DEFAULT'))); } $sites = JMHelper::getField('timezone', array('name' => JRequest::getVar('field_name', ''), 'id' => JRequest::getVar('field_id', ''), '_options' => $options)); $this->plugin->setResponse(array('html' => $sites->input)); }
public function get() { jimport('joomla.application.helper'); // Set variables to be used JMHelper::setSessionUser(); $user = JFactory::getUser(); // Response is always successfull if we gotten this far! yippy! $response = $this->getSuccessResponse(200, JText::_('COM_JM_SUCCESS')); $response->user = (object) array('id' => $user->id, 'name' => $user->name, 'username' => $user->username, 'email' => $user->email); $this->plugin->setResponse($response); }
public function get() { JMHelper::setSessionUser(); require_once JPATH_ADMINISTRATOR . '/components/com_menus/models/items.php'; require_once JPATH_PLUGINS . '/jm/menus/resources/helper.php'; $model = JModel::getInstance('JMHelperModel', 'MenuItemsModel'); $model->_setCache('getstart', $model->getState('list.start')); $menuitems = $model->getItems(); if (false === $menuitems || empty($menuitems) && $model->getError()) { $response = $this->getErrorResponse(400, $model->getError()); } else { $response = $menuitems; } $this->plugin->setResponse($response); }
public function get() { $extension = JRequest::getWord('extension'); JMHelper::setSessionUser(); require_once JPATH_ADMINISTRATOR . '/components/com_categories/models/categories.php'; require_once JPATH_PLUGINS . '/jm/categories/resources/helper.php'; $model = JModel::getInstance('JMHelperModel', 'CategoriesModel'); $model->_setCache('getstart', $model->getState('list.start')); $categories = $model->getItems(); if (false === $categories) { $response = $this->getErrorResponse(400, $model->getError()); } else { $response = $categories; } $this->plugin->setResponse($response); }
public function get() { // Set variables to be used JMHelper::setSessionUser(); JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_users/models'); $model = JModel::getInstance('User', 'UsersModel'); $grouplist = $model->getGroups(); $groups = $model->getAssignedGroups(JRequest::getInt('user_id')); if (!$grouplist) { $html = ''; } else { JHtml::addIncludePath(JPATH_ROOT . '/components/com_users/helpers/html'); $html = JHtml::_('access.usergroups', 'jform[groups]', $groups, true); } $this->plugin->setResponse(array('html' => $html)); }
public function get() { // Set the user doing the request as if they were authenticated in Joomla JMHelper::setSessionUser(); if (!defined('K2_JVERSION')) { define('K2_JVERSION', '16'); } // Get the list of items $items = $this->getData(); if (!$items && $this->getError()) { $response = $this->getErrorResponse(400, $this->getError()); } else { $response = $items; } $this->plugin->setResponse($response); }
public function authenticateRequest() { $user_id = JMHelper::getJMUserID(); if ($user_id === false) { return false; } else { $user = JFactory::getUser($user_id); if (!$user->id) { $this->setError(JText::_('COM_JM_USER_NOT_FOUND')); return false; } if ($user->block == 1) { $this->setError(JText::_('COM_JM_BLOCKED_USER')); return false; } return $user; } }
/** * HTML list ready response */ public function get() { $extension = JRequest::getWord('extension'); $categories = JHtml::_('category.options', $extension); // Verify permissions. If the action attribute is set, then we scan the options. $action = 'core.edit.own'; // Get the current user object. $user = JFactory::getUser(JMHelper::getJMUserId()); foreach ($categories as $i => $cat) { // 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.' . $cat->value) != true) { unset($categories[$i]); } } $this->plugin->setResponse($categories); }
public function get() { jimport('joomla.application.helper'); // Set variables to be used $db = JFactory::getDBO(); $return_status = 200; $user_id = $this->plugin->get('user'); JMHelper::setSessionUser($user_id); $error_code = 404; $error_response = JText::_('COM_JM_KEY_NOT_FOUND'); // Load users token $db->setQuery("SELECT * FROM #__jm_keys WHERE user_id = " . (int) $user_id); $token = $db->loadObject(); // Check to see if we are forcing a token no matter what if (JRequest::getInt('force') && (!$token || !$token->published)) { $canDo = JMHelper::getActions(); // Make sure that this user is allowed to create new keys if ($canDo->get('core.manage')) { // Create new token $data = array('id' => 0, 'domain' => '', 'user_id' => $user_id, 'published' => 1); $model = JModel::getInstance('Key', 'JMModel'); $token = $model->save($data); if (false === $token) { $error_code = 500; $error_response = $model->getError(); } else { $return_status = 201; } } else { $error_code = 401; $error_response = JText::_('COM_JM_KEY_CREATE_UNAUTORIZED'); } } if (!$token) { $response = $this->getErrorResponse($error_code, $error_response); } elseif (!$token->published) { $response = $this->getErrorResponse(404, JText::_('COM_JM_KEY_DISABLED')); } else { $response = $this->getSuccessResponse($return_status, JText::_('COM_JM_SUCCESS')); $response->token = $token->hash; } $this->plugin->setResponse($response); }
public function post() { // Set variables to be used JMHelper::setSessionUser(); $language = JFactory::getLanguage(); $language->load('joomla', JPATH_ADMINISTRATOR); $language->load('com_menus', JPATH_ADMINISTRATOR); // Include dependencies jimport('joomla.application.component.controller'); jimport('joomla.form.form'); jimport('joomla.database.table'); require_once JPATH_ADMINISTRATOR . '/components/com_menus/controllers/item.php'; require_once JPATH_ADMINISTRATOR . '/components/com_menus/models/item.php'; JForm::addFormPath(JPATH_ADMINISTRATOR . '/components/com_menus/models/forms/'); // Fake parameters $_POST['task'] = 'apply'; $_REQUEST['task'] = 'apply'; $_REQUEST[JUtility::getToken()] = 1; $_POST[JUtility::getToken()] = 1; $app = JFactory::getApplication(); $context = 'com_menus.edit.item'; // Save menuitem $controller = new MenusControllerItem(); $success = $controller->execute('apply'); if ($controller->getError()) { $response = $this->getErrorResponse(400, $controller->getError()); } elseif (false === $success) { $response = $this->getErrorResponse(400, JText::_('COM_JM_ERROR_OCURRED')); } else { $response = $this->getSuccessResponse(201, $controller->get('message')); // Kind of a weird way of doing this, there has to be a better way? $values = (array) $app->getUserState($context . '.id'); $response->id = array_pop($values); $app->setUserState($context . '.id', $values); // Checkin menuitem $controller->getModel()->checkin($response->id); } // Clear userstate for future requests $app->setUserState($context . '.id', array()); $this->plugin->setResponse($response); }
/** * This is not the best example to follow * Please see the category plugin for a better example */ public function post() { // Set variables to be used JMHelper::setSessionUser(); // Include dependencies jimport('joomla.database.table'); $language = JFactory::getLanguage(); $language->load('joomla', JPATH_ADMINISTRATOR); $language->load('com_k2', JPATH_ADMINISTRATOR); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_k2/tables'); $row =& JTable::getInstance('K2Tag', 'Table'); if (!$row->bind(JRequest::get('post')) || !$row->check() || !$row->store()) { $response = $this->getErrorResponse(400, $row->getError()); } else { $response = $this->getSuccessResponse(201, JText::_('COM_JM_SUCCESS')); $response->id = $row->id; $cache =& JFactory::getCache('com_k2'); $cache->clean(); } $this->plugin->setResponse($response); }
/** * A copy with modifications for the jm from the categoryparent.php * field on the categories component */ public function get() { $options = array(); JFactory::getLanguage()->load('joomla', JPATH_ADMINISTRATOR); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id AS value, a.title AS text, a.level'); $query->from('#__categories AS a'); $query->join('LEFT', '`#__categories` AS b ON a.lft > b.lft AND a.rgt < b.rgt'); // Filter by the type if ($extension = JRequest::getVar('extension')) { $query->where('(a.extension = ' . $db->quote($extension) . ' OR a.parent_id = 0)'); } // Prevent parenting to children of this item. if ($id = JRequest::getInt('id')) { $query->join('LEFT', '`#__categories` AS p ON p.id = ' . (int) $id); $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) $id); $db->setQuery($rowQuery); $row = $db->loadObject(); } $query->where('a.published IN (0,1)'); $query->group('a.id'); $query->order('a.lft ASC'); // Get the options. $db->setQuery($query); $options = $db->loadObjectList(); // Check for a database error. if ($db->getErrorNum()) { JError::raiseWarning(500, $db->getErrorMsg()); } // Pad the option text with spaces using depth level as a multiplier. for ($i = 0, $n = count($options); $i < $n; $i++) { // Translate ROOT if ($options[$i]->level == 0) { $options[$i]->text = JText::_('JGLOBAL_ROOT_PARENT'); } $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; } // Initialise variables. $user = JFactory::getUser(JMHelper::getJMUserId()); if (empty($id)) { // New item, only have to check core.create. foreach ($options as $i => $option) { // Unset the option if the user isn't authorised for it. if (!$user->authorise('core.create', $extension . '.category.' . $option->value)) { unset($options[$i]); } } } else { // Existing item is a bit more complex. Need to account for core.edit and core.edit.own. foreach ($options as $i => $option) { // Unset the option if the user isn't authorised for it. if (!$user->authorise('core.edit', $extension . '.category.' . $option->value)) { // As a backup, check core.edit.own if (!$user->authorise('core.edit.own', $extension . '.category.' . $option->value)) { // No core.edit nor core.edit.own - bounce this one unset($options[$i]); } else { // TODO I've got a funny feeling we need to check core.create here. // Maybe you can only get the list of categories you are allowed to create in? // Need to think about that. If so, this is the place to do the check. } } } } if (isset($row) && !isset($options[0])) { if ($row->parent_id == '1') { $parent = new stdClass(); $parent->text = JText::_('JGLOBAL_ROOT_PARENT'); array_unshift($options, $parent); } } $this->plugin->setResponse($options); }