Beispiel #1
0
 /**
  * Remove any associated resources when group is deleted
  *
  * @param      object $group Group being deleted
  * @return     string Log of items removed
  */
 public function onGroupDelete($group)
 {
     // Get all the IDs for resources associated with this group
     $ids = $this->getResourceIDs($group->get('cn'));
     // Start the log text
     $log = Lang::txt('PLG_GROUPS_RESOURCES_LOG') . ': ';
     if (count($ids) > 0) {
         $database = App::get('db');
         // Loop through all the IDs for resources associated with this group
         foreach ($ids as $id) {
             // Disassociate the resource from the group and unpublish it
             $rr = new \Components\Resources\Tables\Resource($database);
             $rr->load($id->id);
             $rr->group_owner = '';
             $rr->published = 0;
             $rr->store();
             // Add the page ID to the log
             $log .= $id->id . ' ' . "\n";
         }
     } else {
         $log .= Lang::txt('PLG_GROUPS_RESOURCES_NONE') . "\n";
     }
     // Return the log
     return $log;
 }
Beispiel #2
0
 /**
  * Issue master DOI for tool resources if does not exist
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function issueResourceMasterDoi(\Components\Cron\Models\Job $job)
 {
     $database = App::get('db');
     $config = Component::params('com_publications');
     // Is config to issue master DOI turned ON?
     if (!$config->get('master_doi')) {
         return true;
     }
     // Get all tool resources without master DOI
     $sql = "SELECT r.id, r.created_by, v.id as tool_version_id,\n\t\t\t\tv.toolid, v.toolname, v.title, v.description,\n\t\t\t\tv.instance, v.revision, v.released\n\t\t\t\tFROM #__resources AS r, #__tool_version AS v\n\t\t\t\tWHERE r.published=1\n\t\t\t\tAND r.type=7\n\t\t\t\tAND r.standalone=1\n\t\t\t\tAND r.alias=v.toolname\n\t\t\t\tAND v.state=1\n\t\t\t\tAND (r.master_doi IS NULL OR r.master_doi=0)\n\t\t\t\tGROUP BY r.id\n\t\t\t\tORDER BY v.title, v.toolname, v.revision DESC";
     $database->setQuery($sql);
     if (!($rows = $database->loadObjectList())) {
         // No applicable results
         return true;
     }
     // Includes
     require_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'models' . DS . 'doi.php';
     // Get DOI service
     $doiService = new \Components\Publications\Models\Doi();
     // Is service enabled?
     if (!$doiService->on() || !$doiService->_configs->livesite) {
         return true;
     }
     // Go through records
     foreach ($rows as $row) {
         // Reset metadata
         $doiService->reset();
         // Map data
         $pubYear = $row->released && $row->released != '0000-00-00 00:00:00' ? gmdate('Y', strtotime($row->released)) : gmdate('Y');
         $doiService->set('pubYear', $pubYear);
         $doiService->mapUser($row->created_by, array(), 'creator');
         $doiService->set('resourceType', 'Software');
         $doiService->set('title', htmlspecialchars(stripslashes($row->title)));
         $doiService->set('url', $doiService->_configs->livesite . DS . 'resources' . DS . $row->toolname . DS . 'main');
         // Register DOI
         $masterDoi = $doiService->register();
         // Save with publication record
         $resource = new \Components\Resources\Tables\Resource($database);
         if ($masterDoi && $resource->load($row->id)) {
             $resource->master_doi = strtoupper($masterDoi);
             $resource->store();
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Generate a resource page from tool data
  *
  * @param      integer $toolid Tool ID
  * @param      array   $tool   Tool info to generate resource from
  * @return     mixed False if error, integer if success
  */
 public function createPage($toolid, $tool)
 {
     $tool['title'] = preg_replace('/\\s+/', ' ', $tool['title']);
     $params = array();
     $params[] = 'pageclass_sfx=';
     $params[] = 'show_title=1';
     $params[] = 'show_authors=1';
     $params[] = 'show_assocs=1';
     $params[] = 'show_type=1';
     $params[] = 'show_logicaltype=1';
     $params[] = 'show_rating=1';
     $params[] = 'show_date=1';
     $params[] = 'show_parents=1';
     $params[] = 'series_banner=';
     $params[] = 'show_banner=1';
     $params[] = 'show_footer=3';
     $params[] = 'show_stats=0';
     $params[] = 'st_appname=' . strtolower($tool['toolname']);
     $params[] = 'st_appcaption=' . $tool['title'] . $tool['version'];
     $params[] = 'st_method=com_narwhal';
     // Initiate extended database class
     $row = new \Components\Resources\Tables\Resource($this->database);
     $row->created_by = User::get('id');
     $row->created = Date::toSql();
     $row->published = 2;
     // draft state
     $row->params = implode("\n", $params);
     $row->attribs = 'marknew=0';
     $row->standalone = 1;
     $row->type = 7;
     $row->title = $tool['title'];
     $row->introtext = $tool['description'];
     $row->alias = $tool['toolname'];
     $row->access = 0;
     if (!$row->store()) {
         $this->setError($row->getError());
         return false;
     }
     return $row->id;
 }
Beispiel #4
0
 /**
  * Save an attachment
  *
  * @return     void
  */
 public function saveTask()
 {
     // Incoming
     $pid = Request::getInt('pid', 0);
     if (!$pid) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_ID'));
         $this->displayTask($pid);
         return;
     }
     // get tool object
     $obj = new \Components\Tools\Tables\Tool($this->database);
     $this->_toolid = $obj->getToolIdFromResource($pid);
     // make sure user is authorized to go further
     if (!$this->_checkAccess($this->_toolid)) {
         App::abort(403, Lang::txt('COM_TOOLS_ALERTNOTAUTH'));
         return;
     }
     // Incoming file
     $file = Request::getVar('upload', '', 'files', 'array');
     if (!$file['name']) {
         $this->setError(Lang::txt('COM_TOOLS_CONTRIBUTE_NO_FILE'));
         $this->displayTask($pid);
         return;
     }
     // Make the filename safe
     $file['name'] = Filesystem::clean($file['name']);
     // Ensure file names fit.
     $ext = Filesystem::extension($file['name']);
     $file['name'] = str_replace(' ', '_', $file['name']);
     if (strlen($file['name']) > 230) {
         $file['name'] = substr($file['name'], 0, 230);
         $file['name'] .= '.' . $ext;
     }
     // Instantiate a new resource object
     $row = new \Components\Resources\Tables\Resource($this->database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     $row->title = $row->title ? $row->title : $file['name'];
     $row->introtext = $row->title;
     $row->created = Date::toSql();
     $row->created_by = User::get('id');
     $row->published = 1;
     $row->publish_up = Date::toSql();
     $row->publish_down = '0000-00-00 00:00:00';
     $row->standalone = 0;
     $row->access = 0;
     $row->path = '';
     // make sure no path is specified just yet
     // Check content
     if (!$row->check()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     if (!$row->id) {
         $row->id = $row->insertid();
     }
     // Build the path
     include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'helpers' . DS . 'html.php';
     $listdir = \Components\Resources\Tables\Html::build_path($row->created, $row->id, '');
     $path = $this->_buildUploadPath($listdir, '');
     // Make sure the upload path exist
     if (!is_dir($path)) {
         if (!Filesystem::makeDirectory($path)) {
             $this->setError(Lang::txt('COM_TOOLS_UNABLE_TO_CREATE_UPLOAD_PATH'));
             $this->displayTask($pid);
             return;
         }
     }
     // Perform the upload
     if (!Filesystem::upload($file['tmp_name'], $path . DS . $file['name'])) {
         $this->setError(Lang::txt('COM_TOOLS_ERROR_UPLOADING'));
     } else {
         // File was uploaded
         // Check the file type
         $row->type = $this->_getChildType($file['name']);
     }
     if (!$row->path) {
         $row->path = $listdir . DS . $file['name'];
     }
     if (substr($row->path, 0, 1) == DS) {
         $row->path = substr($row->path, 1, strlen($row->path));
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         $this->displayTask($pid);
         return;
     }
     // Instantiate a Resources Assoc object
     $assoc = new \Components\Resources\Tables\Assoc($this->database);
     // Get the last child in the ordering
     $order = $assoc->getLastOrder($pid);
     $order = $order ? $order : 0;
     // Increase the ordering - new items are always last
     $order = $order + 1;
     // Create new parent/child association
     $assoc->parent_id = $pid;
     $assoc->child_id = $row->id;
     $assoc->ordering = $order;
     $assoc->grouping = 0;
     if (!$assoc->check()) {
         $this->setError($assoc->getError());
     }
     if (!$assoc->store(true)) {
         $this->setError($assoc->getError());
     }
     $this->_rid = $pid;
     // Push through to the attachments view
     $this->displayTask($pid);
 }
Beispiel #5
0
 /**
  * Removes an item reported as abusive
  *
  * @param      integer $referenceid ID of the database table row
  * @param      integer $parentid    If the element has a parent element
  * @param      string  $category    Element type (determines table to look in)
  * @param      string  $message     Message to user to append to
  * @return     string
  */
 public function deleteReportedItem($referenceid, $parentid, $category, $message)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     $this->loadLanguage();
     $database = App::get('db');
     switch ($category) {
         case 'review':
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'review.php';
             // Delete the review
             $review = new \Components\Resources\Tables\Review($database);
             $review->load($referenceid);
             $review->state = 2;
             $review->store();
             // Recalculate the average rating for the parent resource
             $resource = new \Components\Resources\Tables\Resource($database);
             $resource->load($parentid);
             $resource->calculateRating();
             if (!$resource->store()) {
                 $this->setError($resource->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
         case 'reviewcomment':
             $comment = \Hubzero\Item\Comment::oneOrFail($referenceid);
             $comment->set('state', $comment::STATE_DELETED);
             if (!$comment->save()) {
                 $this->setError($comment->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
     }
     return $message;
 }