Example #1
0
 /**
  * Manage tags on a resource
  *
  * @return  void
  */
 public function displayTask()
 {
     $id = Request::getInt('id', 0);
     // Get resource title
     $row = new Resource($this->database);
     $row->load($id);
     if (!$row->get('id')) {
         Notify::error(Lang::txt('COM_RESOURCES_NOTFOUND'));
         return $this->cancelTask();
     }
     // Get tags for this resource
     $rt = new TagCloud($id);
     $mytagarray = array();
     $myrawtagarray = array();
     foreach ($rt->tags() as $tagMen) {
         $mytagarray[] = $tagMen->get('tag');
         $myrawtagarray[] = $tagMen->get('raw_tag');
     }
     // Get all tags
     $tags = $rt->tags('list', array('scope' => null, 'scope_id' => 0), true);
     $objtags = new stdClass();
     $objtags->tagMen = implode(', ', $myrawtagarray);
     // Output the HTML
     $this->view->set('id', $id)->set('row', $row)->set('tags', $tags)->set('mytagarray', $mytagarray)->set('objtags', $objtags)->setErrors($this->getErrors())->display();
 }
Example #2
0
 /**
  * Map Child Resources
  *
  * @return void
  */
 private function _mapChildData()
 {
     // do we have an array of child resources?
     if (isset($this->raw->children) && is_array($this->raw->children)) {
         // loop through each child resource and bind as a resource object
         foreach ($this->raw->children as $child) {
             $childResource = new Tables\Resource($this->_database);
             $childResource->bind($child);
             // add this child to
             array_push($this->record->children, $childResource);
         }
     }
 }
Example #3
0
 /**
  * Display a list of authors
  *
  * @param      integer $id Resource ID
  * @return     void
  */
 public function displayTask($id = null)
 {
     $this->view->setLayout('display');
     // Incoming
     if (!$id) {
         $id = Request::getInt('id', 0);
     }
     // Ensure we have an ID to work with
     if (!$id) {
         throw new Exception(Lang::txt('CONTRIBUTE_NO_ID'), 500);
     }
     // Get all contributors of this resource
     $helper = new Helper($id, $this->database);
     $helper->getCons();
     // Get a list of all existing contributors
     include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'profile.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'tables' . DS . 'association.php';
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor' . DS . 'roletype.php';
     $resource = new Resource($this->database);
     $resource->load($id);
     $rt = new RoleType($this->database);
     // Output HTML
     $this->view->config = $this->config;
     $this->view->contributors = $helper->_contributors;
     $this->view->id = $id;
     $this->view->roles = $rt->getRolesForType($resource->type);
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }
Example #4
0
 /**
  * Gets the full name of a user from their ID #
  *
  * @return     string
  */
 public function authorTask()
 {
     $this->view->id = Request::getVar('u', '');
     $this->view->role = Request::getVar('role', '');
     $rid = Request::getInt('rid', 0);
     // Get the member's info
     $profile = new \Hubzero\User\Profile();
     $profile->load($this->view->id);
     if (!is_object($profile) || !$profile->get('uidNumber')) {
         $this->database->setQuery("SELECT id FROM `#__users` WHERE `name`=" . $this->database->Quote($this->view->id));
         if ($id = $this->database->loadResult()) {
             $profile->load($id);
         }
     }
     if (is_object($profile) && $profile->get('uidNumber')) {
         if (!$profile->get('name')) {
             $this->view->name = $profile->get('givenName') . ' ';
             $this->view->name .= $profile->get('middleName') ? $profile->get('middleName') . ' ' : '';
             $this->view->name .= $profile->get('surname');
         } else {
             $this->view->name = $profile->get('name');
         }
         $this->view->org = $profile->get('organization');
         $this->view->id = $profile->get('uidNumber');
     } else {
         $this->view->name = null;
         include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'contributor.php';
         $rcc = new Contributor($this->database);
         if (is_numeric($this->view->id)) {
             $this->database->setQuery("SELECT name, organization FROM `#__author_assoc` WHERE authorid=" . $this->database->Quote($this->view->id) . " LIMIT 1");
             $author = $this->database->loadObject();
             if (is_object($author) && $author->name) {
                 $this->view->name = $author->name;
                 $this->view->org = $author->organization;
             }
         }
         if (!$this->view->name) {
             $this->view->org = '';
             $this->view->name = str_replace('_', ' ', $this->view->id);
             $this->view->id = $rcc->getUserId($this->view->name);
         }
     }
     $row = new Resource($this->database);
     $row->load($rid);
     $rt = new Type($this->database);
     $this->view->roles = $rt->getRolesForType($row->type);
     $this->view->display();
 }
Example #5
0
 /**
  * Display an upload form and file listing
  *
  * @return     void
  */
 public function displayTask()
 {
     $this->view->setLayout('display');
     // Incoming directory (this should be a path built from a resource ID and its creation year/month)
     $this->view->resource = Request::getInt('resource', 0);
     if (!$this->view->resource) {
         echo '<p class="error">' . Lang::txt('No resource ID provided.') . '</p>';
         return;
     }
     // Incoming sub-directory
     $this->view->subdir = Request::getVar('subdir', '');
     // Build the path
     //$this->view->path = Utilities::buildUploadPath($this->view->listdir, $this->view->subdir);
     $row = new Resource($this->database);
     $row->load($this->view->resource);
     // allow for temp resource uploads
     if (!$row->created || $row->created == '0000-00-00 00:00:00') {
         $row->created = Date::format('Y-m-d 00:00:00');
     }
     $this->view->path = PATH_APP . DS . trim($this->config->get('uploadpath', '/site/resources'), DS) . Html::build_path($row->created, $this->view->resource, '') . DS . 'media';
     $folders = array();
     $docs = array();
     if (is_dir($this->view->path)) {
         // Loop through all files and separate them into arrays of images, folders, and other
         $dirIterator = new \DirectoryIterator($this->view->path);
         foreach ($dirIterator as $file) {
             if ($file->isDot()) {
                 continue;
             }
             if ($file->isDir()) {
                 $name = $file->getFilename();
                 $folders[$path . DS . $name] = $name;
                 continue;
             }
             if ($file->isFile()) {
                 $name = $file->getFilename();
                 if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) {
                     continue;
                 }
                 $docs[$this->view->path . DS . $name] = $name;
             }
         }
         ksort($folders);
         ksort($docs);
     }
     $this->view->row = $row;
     $this->view->docs = $docs;
     $this->view->folders = $folders;
     // Set any errors
     if ($this->getError()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
     }
     // Output the HTML
     $this->view->display();
 }
Example #6
0
 /**
  * Create an item entry for a resource
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('id', 0);
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'models' . DS . 'resource.php';
     $resource = null;
     if (!$id) {
         $alias = Request::getVar('alias', '');
         $resource = new Resource($this->_db);
         $resource->loadAlias($alias);
         $id = $resource->id;
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$resource) {
         $resource = new Resource($this->_db);
         $resource->load($id);
     }
     if (!$resource->id) {
         $this->setError(Lang::txt('Resource not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $resource->id)->set('created', $resource->created)->set('created_by', $resource->created_by)->set('title', $resource->title)->set('description', $resource->introtext)->set('url', Route::url('index.php?option=com_resources&id=' . $resource->id));
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Example #7
0
 /**
  * Check if a user has access to a group-owned resource
  * Uses current user session if no user object is supplied
  *
  * @param   object   $resource  Resource
  * @param   object   $user      User (optional)
  * @return  boolean  True if user has access to a group-owned resource
  */
 private function checkGroupAccess($resource, $user = null)
 {
     if (!$user) {
         $user = User::getRoot();
     }
     if (!$user->get('guest')) {
         // Check if they're a site admin
         $this->config->set('access-admin-component', $user->authorise('core.admin', null));
         $this->config->set('access-manage-component', $user->authorise('core.manage', null));
         if ($this->config->get('access-admin-component') || $this->config->get('access-manage-component')) {
             return false;
         }
         $xgroups = \Hubzero\User\Helper::getGroups($user->get('id'), 'all');
         // Get the groups the user has access to
         $usersgroups = self::getUsersGroups($xgroups);
     } else {
         $usersgroups = array();
     }
     // Get the list of groups that can access this resource
     $allowedgroups = $resource->getGroups();
     if ($resource->standalone != 1) {
         $helper = new Helper($resource->id, $this->database);
         $helper->getParents();
         $parents = $helper->parents;
         if (count($parents) == 1) {
             $p = new Resource($this->database);
             $p->load($parents[0]->id);
             $allowedgroups = $p->getGroups();
         }
     }
     $this->allowedgroups = $allowedgroups;
     // Find what groups the user has in common with the resource, if any
     $common = array_intersect($usersgroups, $allowedgroups);
     // Make sure they have the proper group access
     $restricted = false;
     if ($resource->access == 4 || $resource->access == 3) {
         // Are they logged in?
         if ($user->get('guest')) {
             // Not logged in
             $restricted = true;
         } else {
             // Logged in
             // Check if the user is apart of the group that owns the resource
             // or if they have any groups in common
             if (!in_array($resource->group_owner, $usersgroups) && count($common) < 1) {
                 $restricted = true;
             }
         }
     }
     if (!$resource->standalone) {
         if (!isset($p) && isset($parents) && count($parents) == 1) {
             $p = new Resource($this->database);
             $p->load($parents[0]->id);
         }
         if (isset($p) && ($p->access == 4 || $p->access == 3) && count($common) < 1) {
             $restricted = true;
         }
     }
     return $restricted;
 }
Example #8
0
 /**
  * Check if the review step is completed
  *
  * @param      integer $id Resource ID
  * @return     integer 1 = step completed, 0 = not completed
  */
 public function step_review_check($id)
 {
     $row = new Resource($this->database);
     $row->load($id);
     if ($row->published == 1) {
         return 1;
     } else {
         return 0;
     }
 }
Example #9
0
 /**
  * Change access on an entry
  *
  * @return  void
  */
 public function accessTask()
 {
     // Incoming parent ID
     $pid = Request::getInt('pid', 0);
     if (!$pid) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_ID'));
         $this->displayTask($pid);
         return;
     }
     // Incoming child ID
     $id = Request::getInt('id', 0);
     if (!$id) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_CHILD_ID'));
         $this->displayTask($pid);
         return;
     }
     // Load resource info
     $row = new Resource($this->database);
     $row->load($id);
     if (!$row) {
         $this->setError(Lang::txt('CONTRIBUTE_NO_CHILD_ID'));
         $this->displayTask($pid);
         return;
     }
     $access = Request::getInt('access', 0);
     if (!in_array($access, array(0, 1))) {
         $access = 0;
     }
     $row->access = $access;
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     // Push through to the attachments view
     $this->displayTask($pid);
 }
Example #10
0
 /**
  * Get a list of resources
  *
  * @apiMethod GET
  * @apiUri    /resources/list
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "start",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "type",
  * 		"description":   "Type of resource to filter results.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "sortby",
  * 		"description":   "Value to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "date",
  * 		"allowedValues": "date, title, random"
  * }
  * @apiParameter {
  * 		"name":          "search",
  * 		"description":   "A word or phrase to search for.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @return    void
  */
 public function listTask()
 {
     // Incoming
     $filters = array('type' => Request::getVar('type', ''), 'sortby' => Request::getCmd('sortby', 'date'), 'limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''));
     if (!in_array($filters['sortby'], array('date', 'date_published', 'date_created', 'date_modified', 'title', 'rating', 'ranking', 'random'))) {
         App::abort(404, Lang::txt('Invalid sort value of "%s" used.', $filters['sortby']));
     }
     require_once Component::path('com_resources') . DS . 'tables' . DS . 'resource.php';
     require_once Component::path('com_resources') . DS . 'tables' . DS . 'type.php';
     $database = App::get('db');
     // Instantiate a resource object
     $rr = new Resource($database);
     // encode results and return response
     $response = new stdClass();
     $response->records = array();
     $response->total = $rr->getCount($filters);
     if ($response->total) {
         // Get major types
         $t = new Type($database);
         $types = array();
         foreach ($t->getMajorTypes() as $type) {
             unset($type->params);
             unset($type->customFields);
             $types[$type->id] = $type;
         }
         $response->records = $rr->getRecords($filters);
         $base = rtrim(Request::base(), '/');
         foreach ($response->records as $i => $entry) {
             $entry->url = str_replace('/api', '', $base . '/' . ltrim(Route::url('index.php?option=com_resources&' . ($entry->alias ? 'alias=' . $entry->alias : 'id=' . $entry->id)), '/'));
             if (isset($types[$entry->type])) {
                 $entry->type = $types[$entry->type];
             }
             $response->records[$i] = $entry;
         }
     }
     $response->success = true;
     $this->send($response);
 }