Esempio n. 1
0
 /**
  * Unpublish version/delete draft
  *
  * @return     string
  */
 public function cancelDraft()
 {
     // Incoming
     $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0);
     $confirm = Request::getInt('confirm', 0);
     $version = Request::getVar('version', 'default');
     $ajax = Request::getInt('ajax', 0);
     // Check permission
     if (!$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     // Load publication model
     $pub = new \Components\Publications\Models\Publication($pid, $version);
     if (!$pub->exists() || !$pub->belongsToProject($this->model->get('id'))) {
         throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'), 404);
         return;
     }
     // Save version ID
     $vid = $pub->version->get('id');
     // Append breadcrumbs
     if (!$ajax) {
         Pathway::append(stripslashes($pub->version->get('title')), $pub->link('edit'));
     }
     $baseUrl = Route::url($pub->link('editbase'));
     $baseEdit = Route::url($pub->link('edit'));
     // Can only unpublish published version or delete a draft
     if ($pub->version->get('state') != 1 && $pub->version->get('state') != 3 && $pub->version->get('state') != 4) {
         $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_CANT_DELETE'));
     }
     // Unpublish/delete version
     if ($confirm) {
         if (!$this->getError()) {
             $pubtitle = \Hubzero\Utility\String::truncate($pub->version->get('title'), 100);
             if ($pub->version->get('state') == 1) {
                 // Unpublish published version
                 $pub->version->set('published_down', Date::toSql());
                 $pub->version->set('modified', Date::toSql());
                 $pub->version->set('modified_by', $this->_uid);
                 $pub->version->set('state', 0);
                 if (!$pub->version->store()) {
                     throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_UNPUBLISH_FAILED'), 403);
                     return;
                 } else {
                     $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_UNPUBLISHED');
                     // Add activity
                     $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_UNPUBLISHED');
                     $action .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version->get('version_label') . ' ' . Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" ';
                     $aid = $this->model->recordActivity($action, $pid, $pubtitle, Route::url($pub->link('editversion')), 'publication', 0);
                 }
             } elseif ($pub->version->get('state') == 3 || $pub->version->get('state') == 4) {
                 $vlabel = $pub->version->get('version_label');
                 // Delete draft version
                 if (!$pub->version->delete()) {
                     throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DELETE_DRAFT_FAILED'), 403);
                     return;
                 }
                 // Delete authors
                 $pa = new \Components\Publications\Tables\Author($this->_database);
                 $authors = $pa->deleteAssociations($vid);
                 // Delete attachments
                 $pContent = new \Components\Publications\Tables\Attachment($this->_database);
                 $pContent->deleteAttachments($vid);
                 // Delete screenshots
                 $pScreenshot = new \Components\Publications\Tables\Screenshot($this->_database);
                 $pScreenshot->deleteScreenshots($vid);
                 // Build publication path
                 $path = PATH_APP . DS . trim($this->_pubconfig->get('webpath'), DS) . DS . \Hubzero\Utility\String::pad($pid);
                 // Build version path
                 $vPath = $path . DS . \Hubzero\Utility\String::pad($vid);
                 // Delete all version files
                 if (is_dir($vPath)) {
                     Filesystem::deleteDirectory($vPath);
                 }
                 // Delete access accosiations
                 $pAccess = new \Components\Publications\Tables\Access($this->_database);
                 $pAccess->deleteGroups($vid);
                 // Delete audience
                 $pAudience = new \Components\Publications\Tables\Audience($this->_database);
                 $pAudience->deleteAudience($vid);
                 // Delete publication existence
                 if ($pub->versionCount() == 0) {
                     // Delete all files
                     if (is_dir($path)) {
                         Filesystem::delete($path);
                     }
                     $pub->publication->delete($pid);
                     $pub->publication->deleteExistence($pid);
                     // Delete related publishing activity from feed
                     $objAA = $this->model->table('Activity');
                     $objAA->deleteActivityByReference($this->model->get('id'), $pid, 'publication');
                 }
                 // Add activity
                 $action = Lang::txt('PLG_PROJECTS_PUBLICATIONS_ACTIVITY_DRAFT_DELETED');
                 $action .= ' ' . $vlabel . ' ';
                 $action .= Lang::txt('PLG_PROJECTS_PUBLICATIONS_OF_PUBLICATION') . ' "' . $pubtitle . '"';
                 $aid = $this->model->recordActivity($action, $pid, '', '', 'publication', 0);
                 $this->_msg = Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_DRAFT_DELETED');
             }
         }
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'cancel'));
         // Output HTML
         $view->option = $this->_option;
         $view->database = $this->_database;
         $view->project = $this->model;
         $view->uid = $this->_uid;
         $view->pid = $pid;
         $view->pub = $pub;
         $view->publishedCount = $pub->version->getPublishedCount($pid);
         $view->task = $this->_task;
         $view->config = $this->model->config();
         $view->pubconfig = $this->_pubconfig;
         $view->ajax = $ajax;
         $view->title = $this->_area['title'];
         // Get messages	and errors
         $view->msg = $this->_msg;
         if ($this->getError()) {
             $view->setError($this->getError());
         }
         return $view->loadTemplate();
     }
     // Pass error or success message
     if ($this->getError()) {
         \Notify::message($this->getError(), 'error', 'projects');
     } elseif (!empty($this->_msg)) {
         \Notify::message($this->_msg, 'success', 'projects');
     }
     App::redirect($baseUrl);
     return;
 }
Esempio n. 2
0
    $rt = new \Components\Publications\Helpers\Tags($database);
    $supported = $rt->checkTagUsage($this->config->get('supportedtag'), $this->publication->id);
    if ($supported) {
        $tag = new \Components\Tags\Tables\Tag($database);
        $tag->loadTag($this->config->get('supportedtag'));
        $sl = $this->config->get('supportedlink');
        if ($sl) {
            $link = $sl;
        } else {
            $link = Route::url('index.php?option=com_tags&tag=' . $tag->tag);
        }
        echo '<p class="supported"><a href="' . $link . '">' . $tag->raw_tag . '</a></p>';
    }
    // Show audience
    if ($this->params->get('show_audience')) {
        $ra = new \Components\Publications\Tables\Audience($database);
        $audience = $ra->getAudience($this->publication->id, $this->publication->version_id, $getlabels = 1, $numlevels = 4);
        $this->view('_audience', 'view')->set('audience', $audience)->set('showtips', true)->set('numlevels', 4)->set('audiencelink', $this->params->get('audiencelink'))->display();
    }
    // Archive version?
    if ($this->lastPubRelease && $this->lastPubRelease->id != $this->publication->version_id) {
        ?>
		<p>
			<?php 
        echo Lang::txt('COM_PUBLICATIONS_METADATA_ARCHIVE');
        ?>
			[<a href="<?php 
        echo Route::url('index.php?option=' . $this->option . '&id=' . $this->publication->id . '&v=' . $this->lastPubRelease->version_number);
        ?>
"><?php 
        echo $this->lastPubRelease->version_label;