Ejemplo n.º 1
0
 /**
  * Return data on a publication sub view (this will be some form of HTML)
  *
  * @param      object  $publication 	Current publication
  * @param      string  $option    		Name of the component
  * @param      integer $miniview  		View style
  * @return     array
  */
 public function onPublicationSub($publication, $option, $miniview = 0)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     $areas = array('related');
     if (!array_intersect($areas, $this->onPublicationSubAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationSubAreas($publication)))) {
         return false;
     }
     $database = App::get('db');
     // Build the query that checks topic pages
     $sql1 = "SELECT v.id, v.page_id AS pageid, MAX(v.version) AS version, w.title, w.pagename AS alias, v.pagetext AS abstract,\n\t\t\t\t\tNULL AS category, NULL AS published, NULL AS publish_up, w.scope, w.rating, w.times_rated, w.ranking, 'wiki' AS class, 'Topic' AS section\n\t\t\t\tFROM `#__wiki_pages` AS w\n\t\t\t\tJOIN `#__wiki_versions` AS v ON w.id=v.page_id\n\t\t\t\tJOIN `#__wiki_links` AS wl ON wl.page_id=w.id\n\t\t\t\tWHERE v.approved=1 AND wl.scope='publication' AND wl.scope_id=" . $database->quote($publication->id);
     if (!User::isGuest()) {
         if (User::authorise('com_resources', 'manage') || User::authorise('com_groups', 'manage')) {
             $sql1 .= '';
         } else {
             $ugs = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
             $groups = array();
             $cns = array();
             if ($ugs && count($ugs) > 0) {
                 foreach ($ugs as $ug) {
                     $cns[] = $database->quote($ug->cn);
                     $groups[] = $database->quote($ug->gidNumber);
                 }
             }
             $g = implode(",", $groups);
             $c = implode(",", $cns);
             $sql1 .= "AND (w.access!=1 OR (w.access=1 AND ((w.scope=" . $database->quote('group') . " AND w.scope_id IN ({$g})) OR w.created_by=" . $database->quote(User::get('id')) . "))) ";
         }
     } else {
         $sql1 .= "AND w.access!=1 ";
     }
     $sql1 .= "GROUP BY pageid ORDER BY ranking DESC, title LIMIT 10";
     // Initiate a helper class
     $model = new \Components\Publications\Models\Publication($publication);
     $tags = $model->getTags();
     // Get version authors
     $authors = isset($publication->_authors) ? $publication->_authors : array();
     // Build the query that get publications related by tag
     $sql2 = "SELECT DISTINCT r.publication_id as id, NULL AS pageid, r.id AS version,\n\t\t\t\tr.title, C.alias, r.abstract, C.category, r.state as published,\n\t\t\t\tr.published_up, NULL AS scope, C.rating, C.times_rated, C.ranking,\n\t\t\t\trt.alias AS class, rt.name AS section" . "\n FROM #__publications as C, #__publication_categories AS rt, #__publication_versions AS r " . "\n JOIN #__tags_object AS a ON r.publication_id=a.objectid AND a.tbl='publications'" . "\n JOIN #__publication_authors AS PA ON PA.publication_version_id=r.id " . "\n WHERE C.id=r.publication_id ";
     if ($tags) {
         $tquery = array(0);
         foreach ($tags as $tagg) {
             $tquery[] = $database->quote($tagg->get('id'));
         }
         $sql2 .= " AND ( a.tagid IN (" . implode(',', $tquery) . ")";
         $sql2 .= count($authors) > 0 ? " OR " : "";
     }
     if (count($authors) > 0) {
         $aquery = '';
         foreach ($authors as $author) {
             $aquery .= "'" . $author->user_id . "',";
         }
         $aquery = substr($aquery, 0, strlen($aquery) - 1);
         $sql2 .= $tags ? "" : " AND ( ";
         $sql2 .= " PA.user_id IN (" . $aquery . ")";
     }
     $sql2 .= $tags || count($authors) > 0 ? ")" : "";
     $sql2 .= " AND r.publication_id !=" . $publication->id;
     $sql2 .= " AND C.category = rt.id AND C.category!=8 ";
     $sql2 .= "AND r.access=0 ";
     $sql2 .= "AND r.state=1 ";
     $sql2 .= "GROUP BY r.publication_id ORDER BY r.ranking LIMIT 10";
     // Build the final query
     $query = "SELECT k.* FROM (({$sql1}) UNION ({$sql2})) AS k ORDER BY ranking DESC LIMIT 10";
     // Execute the query
     $database->setQuery($query);
     $related = $database->loadObjectList();
     // Instantiate a view
     if ($miniview) {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'related', 'name' => 'browse', 'layout' => 'mini'));
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'related', 'name' => 'browse'));
     }
     // Pass the view some info
     $view->option = $option;
     $view->publication = $publication;
     $view->related = $related;
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     // Return the output
     $arr['html'] = $view->loadTemplate();
     // Return the an array of content
     return $arr;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
0
 /**
  * Get a list of project files
  *
  * @apiMethod GET
  * @apiUri    /projects/{id}/files
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Project identifier (numeric ID or alias)",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "limitstart",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "sortby",
  * 		"description":   "Field to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       "title",
  * 		"allowedValues": "title, date, id, category, status"
  * }
  * @apiParameter {
  * 		"name":          "sortdir",
  * 		"description":   "Direction to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "asc",
  * 		"allowedValues": "asc, desc"
  * }
  * @apiParameter {
  * 		"name":          "published",
  * 		"description":   "Get only published datasets (1) or all including drafts (0)",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "0",
  * 		"allowedValues": "0, 1"
  * }
  * @return  void
  */
 public function listTask()
 {
     $response = new stdClass();
     // Instantiate a publication object
     $pub = new \Components\Publications\Models\Publication();
     // Filters for returning results
     $filters = array('project' => $this->model->get('id'), 'limit' => Request::getInt('limit', 25), 'limitstart' => Request::getInt('limitstart', 0), 'sortby' => Request::getWord('sortby', 'title', 'post'), 'sortdir' => strtoupper(Request::getWord('sortdir', 'ASC')), 'ignore_access' => 1);
     $published = Request::getInt('published', '0', 'post');
     if (!$published) {
         $filters['dev'] = 1;
     }
     $response->publications = array();
     $response->total = $pub->entries('count', $filters);
     $response->project = $this->model->get('alias');
     $publications = $pub->entries('list', $filters);
     if (!empty($publications)) {
         $base = rtrim(Request::base(), '/');
         foreach ($publications as $i => $entry) {
             $obj = new stdClass();
             $obj->id = $entry->get('id');
             $obj->alias = $entry->get('alias');
             $obj->title = $entry->get('title');
             $obj->abstract = $entry->get('abstract');
             $obj->creator = $entry->creator('name');
             $obj->created = $entry->get('created');
             $obj->published = $entry->published('date');
             $obj->masterType = $entry->masterType()->type;
             $obj->category = $entry->category()->name;
             $obj->version = $entry->get('version_number');
             $obj->versionLabel = $entry->get('version_label');
             $obj->status = $entry->get('state');
             $obj->statusName = $entry->getStatusName();
             $obj->thumbUrl = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link('thumb')), '/'));
             $obj->uri = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link('version')), '/'));
             $response->publications[] = $obj;
         }
     }
     $this->send($response);
 }
Ejemplo n.º 4
0
 /**
  * Issue master DOI for publications if does not exist
  *
  * @param   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function issueMasterDoi(\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 publications without master DOI
     $sql = "SELECT V.* FROM #__publication_versions as V, #__publications as C";
     $sql .= " WHERE C.id=V.publication_id AND (C.master_doi IS NULL OR master_doi=0)";
     $sql .= " AND V.state=1 GROUP BY C.id ORDER BY V.version_number ASC";
     $database->setQuery($sql);
     if (!($rows = $database->loadObjectList())) {
         // No applicable results
         return true;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'models' . DS . 'publication.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) {
         // Load publication model
         $model = new \Components\Publications\Models\Publication($row->publication_id, $row->id);
         // Check to make sure we got result
         if (!$model->exists()) {
             continue;
         }
         // Map publication
         $doiService->mapPublication($model);
         // Build url
         $pointer = $model->publication->alias ? $model->publication->alias : $model->publication->id;
         $url = $doiService->_configs->livesite . DS . 'publications' . DS . $pointer . DS . 'main';
         // Master DOI should link to /main
         $doiService->set('url', $url);
         // Register DOI
         $masterDoi = $doiService->register();
         // Save with publication record
         if ($masterDoi) {
             $model->publication->master_doi = strtoupper($masterDoi);
             $model->publication->store();
         }
     }
     return true;
 }
Ejemplo n.º 5
0
}
?>
			<h5 class="element-title"><?php 
echo $this->manifest->label;
?>
</h5>
			    <?php 
if ($this->name == 'curator') {
    $this->pub->_curationModel->drawCurationNotice($curatorStatus, $props, 'curator', $elName);
}
?>
			<?php 
if ($value) {
    // Parse editor text
    if ($editor) {
        $model = new \Components\Publications\Models\Publication($this->pub);
        $value = $model->parse($aliasmap, $field, 'parsed');
    }
    ?>
				<div class="element-value"><?php 
    echo $value;
    ?>
</div>
			<?php 
} else {
    ?>
				<p class="noresults">No user input</p>
				<?php 
    if (!$this->pub->isPublished() && ($this->status->getError() || $required && !$complete)) {
        ?>
					<p class="witherror"><?php 
Ejemplo n.º 6
0
echo $elementUrl;
?>
" class="edit-element" id="<?php 
echo $elName;
?>
-edit"><?php 
echo Lang::txt('[edit]');
?>
</a></span>
			</h5>
			<?php 
if (!$coming && $value) {
    // Parse editor text
    $val = $value;
    if ($editor) {
        $model = new \Components\Publications\Models\Publication($this->pub);
        $val = $model->parse($aliasmap, $this->manifest->params->field, 'parsed');
    }
    ?>
				<div class="element-value"><?php 
    echo $val;
    ?>
</div>
			<?php 
}
?>
		</div>
	</div>
	<!-- Active editing -->
	<div class="element_editing<?php 
if (!$active) {
Ejemplo n.º 7
0
 /**
  * Draw list
  *
  * @param   array    $attachments
  * @param   object   $element
  * @param   integer  $elementId
  * @param   object   $pub
  * @param   object   $blockParams
  * @param   boolean  $authorized
  * @return  string   HTML
  */
 public function drawList($attachments, $element, $elementId, $pub, $blockParams, $authorized)
 {
     // Get configs
     $configs = $this->getConfigs($element->params, $elementId, $pub, $blockParams);
     $html = '';
     if ($attachments) {
         // Serve individually
         foreach ($attachments as $attach) {
             $itemUrl = Route::url('index.php?option=com_publications&id=' . $attach->object_id);
             $publication = new \Components\Publications\Models\Publication($attach->object_id, 'default');
             $title = $publication->title ? $publication->title : $configs->title;
             $title = $title ? $title : $attach->path;
             $description = '';
             if ($publication->get('abstract')) {
                 $description = \Hubzero\Utility\String::truncate(stripslashes($publication->get('abstract')), 300) . "\n";
             } else {
                 if ($publication->get('description')) {
                     $description = \Hubzero\Utility\String::truncate(stripslashes($publication->get('description')), 300) . "\n";
                 }
             }
             $pop = Lang::txt('View link') . ' ' . $title;
             $html .= '<li>';
             $html .= $authorized === 'administrator' ? '[' . $this->_name . '] ' : '';
             $html .= '<p><a href="' . $itemUrl . '" title="' . $pop . '" target="_blank" class="link-type">' . $title . '</a></p>';
             $html .= '<p>' . $description . '</p>';
             $html .= '</li>';
         }
     }
     return $html;
 }
Ejemplo n.º 8
0
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */
// No direct access
defined('_HZEXEC_') or die;
$pubParams = $this->publication->params;
$filters = array('category' => Request::getVar('category', ''), 'sortby' => Request::getCmd('sortby', 'date'), 'limit' => Request::getInt('limit', 10000), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'tag' => trim(Request::getVar('tag', '', 'request', 'none', 2)), 'tag_ignored' => array());
// Instantiate a publication object
$model = new \Components\Publications\Models\Publication();
// Execute count query
$total = $model->entries('count', $filters);
// Run query with limit
$results = $model->entries('list', $filters);
// Initiate paging
$pageNav = new \Hubzero\Pagination\Paginator($total, $filters['start'], $filters['limit']);
$database = \App::get('db');
$pa = new \Components\Publications\Tables\Author($database);
?>
<label for="pub-search"><?php 
echo Lang::txt('Search');
?>
</label>
<input id="pub-search" name="search" placeholder="Start typing here" type="text" data-list=".pub-selector" autocomplete="off" />
<ul class="pub-selector" id="pub-selector">