Ejemplo n.º 1
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');
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * Method to get a single record.
  *
  * @param	integer	The id of the primary key.
  *
  * @return	mixed	Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('style.id');
     if (!isset($this->_cache[$pk])) {
         $false = false;
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return $false;
         }
         // Convert to the Object before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = \Hubzero\Utility\Arr::toObject($properties, '\\Hubzero\\Base\\Object');
         // Convert the params field to an array.
         $registry = new \Hubzero\Config\Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Get the template XML.
         //$client = \Hubzero\Base\ClientManager::client($table->client_id);
         $patha = Filesystem::cleanPath(PATH_APP . '/templates/' . $table->template . '/templateDetails.xml');
         $pathc = Filesystem::cleanPath(PATH_CORE . '/templates/' . $table->template . '/templateDetails.xml');
         if (file_exists($patha)) {
             $this->_cache[$pk]->xml = simplexml_load_file($patha);
         } elseif (file_exists($pathc)) {
             $this->_cache[$pk]->xml = simplexml_load_file($pathc);
         } else {
             $this->_cache[$pk]->xml = null;
         }
     }
     return $this->_cache[$pk];
 }
Ejemplo n.º 5
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed  Object on success, false on failure.
  *
  * @since   1.6
  */
 public function getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? (int) $pk : (int) $this->getState('module.id');
     $db = $this->getDbo();
     if (!isset($this->_cache[$pk])) {
         $false = false;
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && ($error = $table->getError())) {
             $this->setError($error);
             return $false;
         }
         // Check if we are creating a new extension.
         if (empty($pk)) {
             if ($extensionId = (int) $this->getState('extension.id')) {
                 $query = $db->getQuery(true);
                 $query->select('element, client_id');
                 $query->from('#__extensions');
                 $query->where('extension_id = ' . $extensionId);
                 $query->where('type = ' . $db->quote('module'));
                 $db->setQuery($query);
                 $extension = $db->loadObject();
                 if (empty($extension)) {
                     if ($error = $db->getErrorMsg()) {
                         $this->setError($error);
                     } else {
                         $this->setError('COM_MODULES_ERROR_CANNOT_FIND_MODULE');
                     }
                     return false;
                 }
                 // Extension found, prime some module values.
                 $table->module = $extension->element;
                 $table->client_id = $extension->client_id;
             } else {
                 App::redirect(Route::url('index.php?option=com_modules&view=modules', false));
                 return false;
             }
         }
         // Convert to the Object before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = \Hubzero\Utility\Arr::toObject($properties, '\\Hubzero\\Base\\Object');
         // Convert the params field to an array.
         $registry = new \Hubzero\Config\Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Determine the page assignment mode.
         $db->setQuery('SELECT menuid' . ' FROM #__modules_menu' . ' WHERE moduleid = ' . $pk);
         $assigned = $db->loadColumn();
         if (empty($pk)) {
             // If this is a new module, assign to all pages.
             $assignment = 0;
         } elseif (empty($assigned)) {
             // For an existing module it is assigned to none.
             $assignment = '-';
         } else {
             if ($assigned[0] > 0) {
                 $assignment = +1;
             } elseif ($assigned[0] < 0) {
                 $assignment = -1;
             } else {
                 $assignment = 0;
             }
         }
         $this->_cache[$pk]->assigned = $assigned;
         $this->_cache[$pk]->assignment = $assignment;
         // Get the module XML.
         //$client = \Hubzero\Base\ClientManager::client($table->client_id);
         //$path   = JPath::clean($client->path.'/modules/'.$table->module.'/'.$table->module.'.xml');
         $patha = JPath::clean(PATH_APP . '/modules/' . $table->module . '/' . $table->module . '.xml');
         $pathc = JPath::clean(PATH_CORE . '/modules/' . $table->module . '/' . $table->module . '.xml');
         if (file_exists($patha)) {
             $this->_cache[$pk]->xml = simplexml_load_file($patha);
         } elseif (file_exists($pathc)) {
             $this->_cache[$pk]->xml = simplexml_load_file($pathc);
         } else {
             $this->_cache[$pk]->xml = null;
         }
     }
     return $this->_cache[$pk];
 }
Ejemplo n.º 6
0
 /**
  * Method to get a menu item.
  *
  * @param	integer	The id of the menu item to get.
  *
  * @return	mixed	Menu item data object on success, false on failure.
  */
 public function &getItem($itemId = null)
 {
     // Initialise variables.
     $itemId = !empty($itemId) ? $itemId : (int) $this->getState('menu.id');
     $false = false;
     // Get a menu item 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');
     return $value;
 }
Ejemplo n.º 7
0
 /**
  * Method to get a menu item.
  *
  * @param	integer	$pk	An optional id of the object to get, otherwise the id from the model state is used.
  *
  * @return	mixed	Menu item data object on success, false on failure.
  * @since	1.6
  */
 public function getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('item.id');
     // Get a level row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $table->load($pk);
     // Check for a table object error.
     if ($error = $table->getError()) {
         $this->setError($error);
         $false = false;
         return $false;
     }
     // Prime required properties.
     if ($type = $this->getState('item.type')) {
         $table->type = $type;
     }
     if (empty($table->id)) {
         $table->parent_id = $this->getState('item.parent_id');
         $table->menutype = $this->getState('item.menutype');
         $table->params = '{}';
     }
     // If the link has been set in the state, possibly changing link type.
     if ($link = $this->getState('item.link')) {
         // Check if we are changing away from the actual link type.
         if (MenusHelper::getLinkKey($table->link) != MenusHelper::getLinkKey($link)) {
             $table->link = $link;
         }
     }
     switch ($table->type) {
         case 'alias':
             $table->component_id = 0;
             $args = array();
             parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
             break;
         case 'separator':
             $table->link = '';
             $table->component_id = 0;
             break;
         case 'url':
             $table->component_id = 0;
             parse_str(parse_url($table->link, PHP_URL_QUERY));
             break;
         case 'component':
         default:
             // Enforce a valid type.
             $table->type = 'component';
             // Ensure the integrity of the component_id field is maintained, particularly when changing the menu item type.
             $args = array();
             parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
             if (isset($args['option'])) {
                 // Load the language file for the component.
                 $lang = Lang::getRoot();
                 $lang->load($args['option'], PATH_APP, null, false, true) || $lang->load($args['option'], PATH_APP . '/components/' . $args['option'] . '/admin', null, false, true) || $lang->load($args['option'], PATH_CORE . '/components/' . $args['option'] . '/admin', null, false, true);
                 // Determine the component id.
                 $component = Component::load($args['option']);
                 if (isset($component->id)) {
                     $table->component_id = $component->id;
                 }
             }
             break;
     }
     // We have a valid type, inject it into the state for forms to use.
     $this->setState('item.type', $table->type);
     // Convert to the Object before adding the params.
     $properties = $table->getProperties(1);
     $result = \Hubzero\Utility\Arr::toObject($properties, '\\Hubzero\\Base\\Object');
     // Convert the params field to an array.
     $registry = new \Hubzero\Config\Registry($table->params);
     $result->params = $registry->toArray();
     // Merge the request arguments in to the params for a component.
     if ($table->type == 'component') {
         // Note that all request arguments become reserved parameter names.
         $result->request = $args;
         $result->params = array_merge($result->params, $args);
     }
     if ($table->type == 'alias') {
         // Note that all request arguments become reserved parameter names.
         $args = array();
         parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
         $result->params = array_merge($result->params, $args);
     }
     if ($table->type == 'url') {
         // Note that all request arguments become reserved parameter names.
         $args = array();
         parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
         $result->params = array_merge($result->params, $args);
     }
     // Load associated menu items
     if (JFactory::getApplication()->get('menu_associations', 0)) {
         if ($pk != null) {
             $result->associations = MenusHelper::getAssociations($pk);
         } else {
             $result->associations = array();
         }
     }
     $result->menuordering = $pk;
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  * @return  mixed    Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     // Initialise variables.
     $pk = !empty($pk) ? $pk : (int) $this->getState('plugin.id');
     if (!isset($this->_cache[$pk])) {
         $false = false;
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return $false;
         }
         // Convert to the Object before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = Arr::toObject($properties, '\\Hubzero\\Base\\Object');
         // Convert the params field to an array.
         $registry = new Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Get the plugin XML.
         $path = array('app' => Filesystem::cleanPath(PATH_APP . DS . 'plugins' . DS . $table->folder . DS . $table->element . DS . $table->element . '.xml'), 'core' => Filesystem::cleanPath(PATH_CORE . DS . 'plugins' . DS . $table->folder . DS . $table->element . DS . $table->element . '.xml'));
         if (file_exists($path['app'])) {
             $this->_cache[$pk]->xml = \JFactory::getXML($path['app']);
         } else {
             if (file_exists($path['core'])) {
                 $this->_cache[$pk]->xml = \JFactory::getXML($path['core']);
             } else {
                 $this->_cache[$pk]->xml = null;
             }
         }
     }
     return $this->_cache[$pk];
 }