示例#1
0
 /**
  * Get items
  *
  * @param      integer $projectid
  * @param      array   $filters
  * @param      integer $id
  * @return     object
  */
 public function getEntries($projectid = NULL, $filters = array(), $id = 0)
 {
     if ($projectid === NULL) {
         return false;
     }
     $pc = new \Components\Projects\Tables\Comment($this->_db);
     $query = "SELECT m.*, (SELECT COUNT(*) FROM " . $pc->getTableName() . " AS c\n\t\t\tWHERE c.itemid=m.id AND c.tbl='blog')\n\t\t\tAS comments, u.name " . $this->_buildQuery($projectid, $filters, $id);
     $this->_db->setQuery($query);
     return $this->_db->loadObjectList();
 }
示例#2
0
 /**
  * Get a list or count of comments
  *
  * @param   string  $rtrn    Data format to return
  * @param   array   $filters Filters to apply to data fetch
  * @param   boolean $clear   Clear cached data?
  * @return  mixed
  */
 public function comments($rtrn = 'list', $filters = array(), $clear = false)
 {
     $tbl = new \Components\Projects\Tables\Comment($this->_db);
     switch (strtolower($rtrn)) {
         case 'count':
             if (!isset($this->_comments_count) || !is_numeric($this->_comments_count) || $clear) {
                 $this->_comments_count = 0;
                 if (!$this->_comments) {
                     $c = $this->comments('list', $filters);
                 }
                 foreach ($this->_comments as $com) {
                     $this->_comments_count++;
                 }
             }
             return $this->_comments_count;
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_comments instanceof \Hubzero\Base\ItemList || $clear) {
                 if ($results = $tbl->getComments($this->get('id'), 'todo')) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Comment($result);
                         $results[$key]->set('option', 'com_projects');
                         $results[$key]->set('scope', '');
                         $results[$key]->set('alias', '');
                         $results[$key]->set('path', '');
                     }
                 } else {
                     $results = array();
                 }
                 $this->_comments = new \Hubzero\Base\ItemList($results);
             }
             return $this->_comments;
             break;
     }
 }
示例#3
0
 /**
  * Delete comment
  *
  * @return  void
  */
 protected function _deleteComment()
 {
     // Check permission
     if (!$this->model->access('content')) {
         App::abort(403, Lang::txt('ALERTNOTAUTH'));
     }
     // Incoming
     $cid = Request::getInt('cid', 0);
     // Instantiate comment
     $objC = new \Components\Projects\Tables\Comment($this->_database);
     if ($objC->load($cid)) {
         $activityid = $objC->activityid;
         // delete comment
         if ($objC->deleteComment()) {
             $this->_msg = Lang::txt('PLG_PROJECTS_BLOG_COMMENT_DELETED');
         }
         // delete associated activity
         $objAA = $this->model->table('Activity');
         if ($activityid && $objAA->load($activityid)) {
             $objAA->deleteActivity();
         }
     }
     // Pass error or success message
     if ($this->getError()) {
         Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         Notify::message($this->_msg, 'success', 'projects');
     }
     // Redirect
     App::redirect(Route::url($this->model->link()));
 }
示例#4
0
 /**
  * Save comment
  *
  * @return	   void, redirect
  */
 protected function _saveComment()
 {
     // Check for request forgeries
     Request::checkToken();
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Incoming
     $itemid = Request::getInt('itemid', 0, 'post');
     $comment = trim(Request::getVar('comment', '', 'post'));
     $parent_activity = Request::getInt('parent_activity', 0, 'post');
     // Clean-up
     $comment = \Hubzero\Utility\Sanitize::stripScripts($comment);
     $comment = \Hubzero\Utility\Sanitize::stripImages($comment);
     $comment = \Hubzero\Utility\String::truncate($comment, 800);
     // Instantiate comment
     $objC = new \Components\Projects\Tables\Comment($this->_database);
     if ($comment) {
         $objC->itemid = $itemid;
         $objC->tbl = 'todo';
         $objC->parent_activity = $parent_activity;
         $objC->comment = $comment;
         $objC->created = Date::toSql();
         $objC->created_by = $this->_uid;
         if (!$objC->store()) {
             $this->setError($objC->getError());
         } else {
             $this->_msg = Lang::txt('PLG_PROJECTS_TODO_COMMENT_POSTED');
         }
         // Get new entry ID
         if (!$objC->id) {
             $objC->checkin();
         }
         // Record activity
         if ($objC->id) {
             $what = Lang::txt('COM_PROJECTS_TODO_ITEM');
             $url = Route::url($this->model->link('todo') . '&action=view&todoid=' . $itemid);
             $aid = $this->model->recordActivity(Lang::txt('COM_PROJECTS_COMMENTED') . ' ' . Lang::txt('COM_PROJECTS_ON') . ' ' . $what, $objC->id, $what, $url, 'quote', 0);
         }
         // Store activity ID
         if ($aid) {
             $objC->activityid = $aid;
             $objC->store();
         }
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     // Redirect
     App::redirect(Route::url($this->model->link('todo') . '&action=view&todoid=' . $itemid));
     return;
 }
示例#5
0
 /**
  * Saves a publication
  * Redirects to main listing
  *
  * @param   boolean  $redirect
  * @return  void
  */
 public function saveTask($redirect = false)
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $id = Request::getInt('id', 0);
     $action = Request::getVar('admin_action', '');
     $published_up = Request::getVar('published_up', '');
     $version = Request::getVar('version', 'default');
     // Is this a new publication? Cannot create via back-end
     $isnew = $id ? 0 : 1;
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_PUBLICATIONS_ERROR_LOAD_PUBLICATION'), 'error');
         return;
     }
     // Load publication model
     $this->model = new Models\Publication($id, $version);
     if (!$this->model->exists()) {
         throw new Exception(Lang::txt('COM_PUBLICATIONS_NOT_FOUND'), 404);
     }
     // Checkin resource
     $this->model->publication->checkin();
     // Set redirect URL
     $url = Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit' . '&id[]=' . $id . '&version=' . $version, false);
     $authors = $this->model->authors();
     $project = $this->model->project();
     $this->model->setCuration();
     $requireDoi = isset($this->model->_curationModel->_manifest->params->require_doi) ? $this->model->_curationModel->_manifest->params->require_doi : 0;
     // Incoming updates
     $title = trim(Request::getVar('title', '', 'post'));
     $title = htmlspecialchars($title);
     $abstract = trim(Request::getVar('abstract', '', 'post'));
     $abstract = htmlspecialchars(\Hubzero\Utility\Sanitize::clean($abstract));
     $description = trim(Request::getVar('description', '', 'post', 'none', 2));
     $release_notes = stripslashes(trim(Request::getVar('release_notes', '', 'post', 'none', 2)));
     $group_owner = Request::getInt('group_owner', 0, 'post');
     $published_up = trim(Request::getVar('published_up', '', 'post'));
     $published_down = trim(Request::getVar('published_down', '', 'post'));
     $state = Request::getInt('state', 0);
     $metadata = '';
     $activity = '';
     // Save publication record
     $this->model->publication->alias = trim(Request::getVar('alias', '', 'post'));
     $this->model->publication->category = trim(Request::getInt('category', 0, 'post'));
     $this->model->publication->access = Request::getInt('access', 0, 'post');
     if (!$project->get('owned_by_group')) {
         $this->model->publication->group_owner = $group_owner;
     }
     $this->model->publication->store();
     // Get metadata
     if (isset($_POST['nbtag'])) {
         $category = $this->model->category();
         $fields = array();
         if (trim($category->customFields) != '') {
             $fs = explode("\n", trim($category->customFields));
             foreach ($fs as $f) {
                 $fields[] = explode('=', $f);
             }
         }
         $nbtag = Request::getVar('nbtag', array(), 'request', 'array');
         foreach ($nbtag as $tagname => $tagcontent) {
             $tagcontent = trim(stripslashes($tagcontent));
             if ($tagcontent != '') {
                 $metadata .= "\n" . '<nb:' . $tagname . '>' . $tagcontent . '</nb:' . $tagname . '>' . "\n";
             } else {
                 foreach ($fields as $f) {
                     if ($f[0] == $tagname && end($f) == 1) {
                         echo Helpers\Html::alert(Lang::txt('COM_PUBLICATIONS_REQUIRED_FIELD_CHECK', $f[1]));
                         exit;
                     }
                 }
             }
         }
     }
     // Save incoming
     $this->model->version->title = $title;
     $this->model->version->abstract = \Hubzero\Utility\String::truncate($abstract, 250);
     $this->model->version->description = $description;
     $this->model->version->metadata = $metadata;
     $this->model->version->release_notes = $release_notes;
     $this->model->version->license_text = trim(Request::getVar('license_text', '', 'post'));
     $this->model->version->license_type = Request::getInt('license_type', 0, 'post');
     $this->model->version->access = Request::getInt('access', 0, 'post');
     // Get DOI service
     $doiService = new Models\Doi($this->model);
     // DOI manually entered?
     $doi = trim(Request::getVar('doi', '', 'post'));
     if ($doi && (!$this->model->version->doi || !preg_match("/" . $doiService->_configs->shoulder . "/", $this->model->version->doi))) {
         $this->model->version->doi = $doi;
     }
     $this->model->version->published_up = $published_up ? Date::of($published_up, Config::get('offset'))->toSql() : '0000-00-00 00:00:00';
     $this->model->version->published_down = $published_down && trim($published_down) != 'Never' ? Date::of($published_down, Config::get('offset'))->toSql() : '0000-00-00 00:00:00';
     // Determine action (if status is flipped)
     if ($this->model->version->state != $state) {
         switch ($state) {
             case 1:
                 $action = $this->model->version->state == 0 ? 'republish' : 'publish';
                 break;
             case 0:
                 $action = 'unpublish';
                 break;
             case 3:
             case 4:
                 $action = 'revert';
                 break;
             case 7:
                 $action = 'wip';
                 break;
         }
         $this->model->version->state = $state;
     }
     // Update DOI with latest information
     if ($this->model->version->doi && !$action) {
         // Update DOI if locally issued
         if (preg_match("/" . $doiService->_configs->shoulder . "/", $this->model->version->doi)) {
             $doiService->update($this->model->version->doi, true);
         }
     }
     // Incoming tags
     $tags = Request::getVar('tags', '', 'post');
     // Save the tags
     $rt = new Helpers\Tags($this->database);
     $rt->tag_object(User::get('id'), $id, $tags, 1, true);
     // Email config
     $pubtitle = \Hubzero\Utility\String::truncate($this->model->version->title, 100);
     $subject = Lang::txt('Version') . ' ' . $this->model->version->version_label . ' ' . Lang::txt('COM_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('COM_PUBLICATIONS_PUBLICATION')) . ' "' . $pubtitle . '" ';
     $sendmail = 0;
     $message = rtrim(\Hubzero\Utility\Sanitize::clean(Request::getVar('message', '')));
     $output = Lang::txt('COM_PUBLICATIONS_SUCCESS_SAVED_ITEM');
     // Admin actions
     if ($action) {
         $output = '';
         switch ($action) {
             case 'publish':
             case 'republish':
                 // Unset the published_down timestamp if publishing
                 $this->model->version->published_down = '0000-00-00 00:00:00';
                 $activity = $action == 'publish' ? Lang::txt('COM_PUBLICATIONS_ACTIVITY_ADMIN_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_ACTIVITY_ADMIN_REPUBLISHED');
                 $subject .= $action == 'publish' ? Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_REPUBLISHED');
                 $this->model->version->state = 1;
                 // Is service enabled? - Issue/update a DOI
                 if ($doiService->on()) {
                     if ($this->model->version->doi && preg_match("/" . $doiService->_configs->shoulder . "/", $this->model->version->doi)) {
                         // Update
                         $doiService->update($this->model->version->doi, true);
                         if ($doiService->getError()) {
                             $this->setError($doiService->getError());
                         }
                     } elseif ($requireDoi) {
                         // Register
                         $doi = $doiService->register(true);
                         if (!$doi) {
                             App::redirect($url, Lang::txt('COM_PUBLICATIONS_ERROR_DOI') . ' ' . $doiService->getError(), 'error');
                             return;
                         } else {
                             $this->model->version->doi = $doi;
                         }
                     }
                 }
                 // Save date accepted
                 if ($action == 'publish') {
                     $this->model->version->accepted = Date::toSql();
                     $this->model->version->published_up = $published_up ? Date::of($published_up, Config::get('offset'))->toSql() : Date::toSql();
                     // Get and save manifest and its version
                     $versionNumber = $this->model->_curationModel->checkCurationVersion();
                     $this->model->version->set('curation', json_encode($this->model->_curationModel->_manifest));
                     $this->model->version->set('curation_version_id', $versionNumber);
                     // Check if publication is within grace period (published status)
                     $gracePeriod = $this->config->get('graceperiod', 0);
                     $allowArchive = $gracePeriod ? false : true;
                     if ($allowArchive && $this->model->version->accepted && $this->model->version->accepted != '0000-00-00 00:00:00') {
                         $monthFrom = Date::of($this->model->version->accepted . '+1 month')->toSql();
                         if (strtotime($monthFrom) < Date::toUnix()) {
                             $allowArchive = true;
                         }
                     }
                     // Run mkAIP if no grace period set or passed
                     if (!$this->getError() && $this->model->version->doi && $allowArchive == true && (!$this->model->version->archived || $this->model->version->archived == '0000-00-00 00:00:00') && Helpers\Utilities::mkAip($this->model->version)) {
                         $this->model->version->archived = Date::toSql();
                     }
                 }
                 if (!$this->getError()) {
                     $output .= ' ' . Lang::txt('COM_PUBLICATIONS_ITEM') . ' ';
                     $output .= $action == 'publish' ? Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_REPUBLISHED');
                 }
                 break;
             case 'revert':
                 // What is this? This sets it to the state it's alreayd in.
                 //$this->model->version->state = $state ? $state : 4;
                 $this->model->version->state = 3;
                 $activity = Lang::txt('COM_PUBLICATIONS_ACTIVITY_ADMIN_REVERTED');
                 $subject .= Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_REVERTED');
                 $output .= ' ' . Lang::txt('COM_PUBLICATIONS_ITEM') . ' ';
                 $output .= Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_REVERTED');
                 break;
             case 'unpublish':
                 $this->model->version->state = 0;
                 $this->model->version->published_down = Date::toSql();
                 $activity = Lang::txt('COM_PUBLICATIONS_ACTIVITY_ADMIN_UNPUBLISHED');
                 $subject .= Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_UNPUBLISHED');
                 $output .= ' ' . Lang::txt('COM_PUBLICATIONS_ITEM') . ' ';
                 $output .= Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_UNPUBLISHED');
                 break;
             case 'wip':
                 $activity = Lang::txt('COM_PUBLICATIONS_ACTIVITY_ADMIN_REQUESTED_CHANGES');
                 $subject .= Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_REQUESTED_CHANGES');
                 $output .= ' ' . Lang::txt('COM_PUBLICATIONS_ITEM') . ' ';
                 $output .= Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_REQUESTED_CHANGES');
                 break;
         }
     }
     // Updating entry if anything changed
     if (!$this->getError()) {
         $this->model->version->modified = Date::toSql();
         $this->model->version->modified_by = User::get('id');
         // Store content
         if (!$this->model->version->store()) {
             App::redirect($url, $this->model->version->getError(), 'error');
             return;
         } elseif ($action) {
             // Add activity
             $activity .= ' ' . strtolower(Lang::txt('version')) . ' ' . $this->model->version->version_label . ' ' . Lang::txt('COM_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" ';
             // Build return url
             $link = '/projects/' . $project->get('alias') . '/publications/' . $id . '/?version=' . $this->model->version->version_number;
             if ($action != 'message' && !$this->getError()) {
                 $aid = $project->recordActivity($activity, $id, $pubtitle, $link, 'publication', 0, $admin = 1);
                 $sendmail = $this->config->get('email') ? 1 : 0;
                 // Append comment to activity
                 if ($message && $aid) {
                     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'comment.php';
                     $objC = new \Components\Projects\Tables\Comment($this->database);
                     $comment = \Hubzero\Utility\String::truncate($message, 250);
                     $comment = \Hubzero\Utility\Sanitize::stripAll($comment);
                     $objC->itemid = $aid;
                     $objC->tbl = 'activity';
                     $objC->parent_activity = $aid;
                     $objC->comment = $comment;
                     $objC->admin = 1;
                     $objC->created = Date::toSql();
                     $objC->created_by = User::get('id');
                     $objC->store();
                     // Get new entry ID
                     if (!$objC->id) {
                         $objC->checkin();
                     }
                     if ($objC->id) {
                         $what = Lang::txt('COM_PROJECTS_AN_ACTIVITY');
                         $curl = Route::url($project->link('feed')) . '#tr_' . $aid;
                         // same-page link
                         $caid = $project->recordActivity(Lang::txt('COM_PROJECTS_COMMENTED') . ' ' . Lang::txt('COM_PROJECTS_ON') . ' ' . $what, $objC->id, $what, $curl, 'quote', 0, 1);
                         // Store activity ID
                         if ($caid) {
                             $objC->activityid = $aid;
                             $objC->store();
                         }
                     }
                 }
             }
         }
     }
     // Save parameters
     $params = Request::getVar('params', '', 'post');
     if (is_array($params)) {
         foreach ($params as $k => $v) {
             $this->model->version->saveParam($this->model->version->id, $k, $v);
         }
     }
     // Do we have a message to send?
     if ($message) {
         $subject .= ' - ' . Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_NEW_MESSAGE');
         $sendmail = 1;
         $output .= ' ' . Lang::txt('COM_PUBLICATIONS_MESSAGE_SENT');
     }
     // Send email
     if ($sendmail && !$this->getError()) {
         // Get ids of publication authors with accounts
         $notify = $this->model->table('Author')->getAuthors($this->model->version->id, 1, 1, 1, true);
         $notify[] = $this->model->version->created_by;
         $notify = array_unique($notify);
         $this->_emailContributors($subject, $message, $notify, $action);
     }
     // Append any errors
     if ($this->getError()) {
         $output .= ' ' . $this->getError();
     }
     // Redirect to edit view?
     if ($redirect) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=edit' . '&id[]=' . $id . '&version=' . $this->model->get('version_number'), false), $output);
     } else {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $output);
     }
     return;
 }