/** * Sets the ID of this resource map. Do not supply with alias. */ public function setPaths() { $this->componentURL = Request::base() . 'publications/'; $this->resourceURL = $this->componentURL . $this->id; $database = \App::get('db'); $pub = new \Components\Publications\Tables\Publication($database); $publication = $pub->getPublication($this->id); $this->resourceSite = \Components\Publications\Helpers\Html::buildPubPath($this->id, $publication->version_id, '', $publication->secret, 1); }
/** * Get configs * * @param object $element * @param integer $elementId * @param object $pub * @param object $blockParams * @return boolean */ public function getConfigs($element, $elementId, $pub, $blockParams) { $configs = new stdClass(); $typeParams = $element->typeParams; // Allow changes in non-draft version? $configs->freeze = 0; if (isset($blockParams->published_editing) && $blockParams->published_editing == 0 && ($pub->state == 1 || $pub->state == 5)) { $configs->freeze = 1; } // Log path $configs->logPath = \Components\Publications\Helpers\Html::buildPubPath($pub->id, $pub->version_id, '', 'logs', 0); // replace current attachments? $configs->replace = Request::getInt('replace_current', 0, 'post'); // Verify file type against allowed before attaching? $configs->check = isset($blockParams->verify_types) ? $blockParams->verify_types : 0; // Get default title $title = isset($element->title) ? str_replace('{pubtitle}', $pub->title, $element->title) : NULL; $configs->title = str_replace('{pubversion}', $pub->version_label, $title); // Fancy launcher? $configs->fancyLauncher = isset($typeParams->fancyLauncher) ? $typeParams->fancyLauncher : 0; return $configs; }
/** * Check completion status * * @return object */ public function getStatus($manifest, $pub = NULL) { $status = new \Components\Publications\Models\Status(); // Get requirements to check against $field = $manifest->params->field; $required = $manifest->params->required; $key = $manifest->params->aliasmap; $default = isset($manifest->params->default) ? $manifest->params->default : NULL; $value = isset($pub->{$key}) ? $pub->{$key} : NULL; $incomplete = 0; // Parse data in metadata field $data = array(); preg_match_all("#<nb:(.*?)>(.*?)</nb:(.*?)>#s", $pub->metadata, $matches, PREG_SET_ORDER); if (count($matches) > 0) { foreach ($matches as $match) { $data[$match[1]] = \Components\Publications\Helpers\Html::_txtUnpee($match[2]); } } // Metadata field (special treatment) if ($field == 'metadata') { $value = isset($data[$key]) ? $data[$key] : NULL; } // Default value not replaced? if ($default && $value) { if ($default == $value || preg_match('/' . $default . ' (\\(.*\\))/', $value, $matches)) { $status->setError(Lang::txt('Default value needs to be replaced')); } } // Required value not filled? if ($required && !$value) { $status->setError(Lang::txt('Missing ' . $key)); } elseif (!$required && !$value) { $incomplete = 1; } $status->status = $status->getError() ? 0 : 1; $status->status = $incomplete ? 2 : $status->status; return $status; }
/** * Serve publication-related file (via public link) * * @param int $projectid * @return void */ public function serve($type = '', $projectid = 0, $query = '') { $this->_area = $this->onProjectAreas(); if ($type != $this->_area['name']) { return false; } $data = json_decode($query); if (!isset($data->pid) || !$projectid) { return false; } $disp = isset($data->disp) ? $data->disp : 'inline'; $type = isset($data->type) ? $data->type : 'file'; $folder = isset($data->folder) ? $data->folder : 'wikicontent'; $fpath = isset($data->path) ? $data->path : 'inline'; $limited = isset($data->limited) ? $data->limited : 0; if ($type != 'file') { return false; } $database = App::get('db'); // Instantiate a project $model = new \Components\Projects\Models\Project($projectid); if (!$model->exists() || $limited == 1 && !$model->access('member')) { // Throw error throw new Exception(Lang::txt('COM_PROJECTS_ERROR_ACTION_NOT_AUTHORIZED'), 403); return; } // Get referenced path $pubconfig = Component::params('com_publications'); $base_path = $pubconfig->get('webpath'); $pubPath = \Components\Publications\Helpers\Html::buildPubPath($data->pid, $data->vid, $base_path, $folder, $root = 0); $serve = PATH_APP . $pubPath . DS . $fpath; // Ensure the file exist if (!file_exists($serve)) { // Throw error throw new Exception(Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'), 404); return; } // Initiate a new content server and serve up the file $server = new \Hubzero\Content\Server(); $server->filename($serve); $server->disposition($disp); $server->acceptranges(false); // @TODO fix byte range support $server->saveas(basename($fpath)); if (!$server->serve()) { // Should only get here on error throw new Exception(Lang::txt('COM_PUBLICATIONS_SERVER_ERROR'), 404); } else { exit; } return; }
echo implode(' <span>-</span> ', $info); ?> </span> --> <span class="item-wrap"> <?php echo $item->get('title'); ?> <br /> <span class="item-info"><?php echo implode(' <span>-</span> ', $info); ?> </span> </span> <span class="item-fullinfo"> <?php echo $description; ?> <p class="details"> <?php if ($authors) { echo Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_AUTHORS_LIST') . ': ' . \Components\Publications\Helpers\Html::showContributors($authors, false, true); } ?> </p> </span> </li> <?php } ?> </ul>
/** * On after approve/kickback * * @return void */ public function onAfterStatusChange() { if ($this->getError()) { return; } $pub = $this->_pub; $status = $this->_pub->version->state; $activity = $status == 1 ? Lang::txt('COM_PUBLICATIONS_CURATION_ACTIVITY_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_CURATION_ACTIVITY_KICKBACK'); $pubtitle = \Hubzero\Utility\String::truncate($pub->title, 100); // Log activity in curation history $pub->_curationModel->saveHistory(User::get('id'), $pub->state, $status, 1); // Add activity $activity .= ' ' . strtolower(Lang::txt('version')) . ' ' . $pub->version_label . ' ' . Lang::txt('COM_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('publication')) . ' "' . $pubtitle . '" '; // Record activity $aid = $pub->project()->recordActivity($activity, $pub->id, $pubtitle, $pub->link('version'), 'publication', 0, $admin = 1); // Start message $sef = 'publications' . DS . $pub->id . DS . $pub->version_number; $link = rtrim(Request::base(), DS) . DS . trim($pub->link('version'), DS); $manage = rtrim(Request::base(), DS) . DS . trim($pub->link('editversion'), DS); $message = $status == 1 ? Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_CURATOR_APPROVED') : Lang::txt('COM_PUBLICATIONS_CURATION_EMAIL_CURATOR_KICKED_BACK'); if ($status != 1) { $message .= "\n" . "\n"; $message .= Lang::txt('COM_PUBLICATIONS_CURATION_TAKE_ACTION') . ' ' . $manage; } else { $message .= ' ' . $link; } $pubtitle = \Hubzero\Utility\String::truncate($pub->title, 100); $subject = ucfirst(Lang::txt('COM_PUBLICATIONS_CURATION_VERSION')) . ' ' . $pub->version_label . ' ' . Lang::txt('COM_PUBLICATIONS_OF') . ' ' . strtolower(Lang::txt('COM_PUBLICATIONS_PUBLICATION')) . ' "' . $pubtitle . '" '; $subject .= $status == 1 ? Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_PUBLISHED') : Lang::txt('COM_PUBLICATIONS_MSG_ADMIN_KICKED_BACK'); // Get authors $authors = $pub->table('Author')->getAuthors($pub->version_id, 1, 1, 1); // No authors – send to publication creator if (count($authors) == 0) { $authors = array($pub->created_by); } // New version released? if ($status == 1 && $pub->get('version_number') > 1) { // Notify subsrcibers Event::trigger('publications.onWatch', array($pub)); } // Make sure there are no duplicates $authors = array_unique($authors); // Notify authors Helpers\Html::notify($pub, $authors, $subject, $message, true); return; }
* * 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; $database = \App::get('db'); // Get version authors $pa = new \Components\Publications\Tables\Author($database); ?> <ul class="mypubs"> <?php foreach ($this->results as $row) { // Get version authors $authors = $pa->getAuthors($row->version_id); $info = array(); $info[] = Date::of($row->published_up)->toLocal('d M Y'); $info[] = $row->cat_name; $info[] = Lang::txt('COM_PUBLICATIONS_CONTRIBUTORS') . ': ' . \Components\Publications\Helpers\Html::showContributors($authors, false, true); // Display List of items $this->view('_item')->set('option', 'com_publications')->set('row', $row)->set('info', $info)->display(); } ?> </ul>
/** * Publish supporting database files * * @param object $objPD * * @return boolean or error */ public function publishDataFiles($objPD, $configs) { if (!$objPD->id) { return false; } // Get data definition $dd = json_decode($objPD->data_definition, true); $files = array(); $columns = array(); foreach ($dd['cols'] as $colname => $col) { if (isset($col['linktype']) && $col['linktype'] == "repofiles") { $dir = ''; if (isset($col['linkpath']) && $col['linkpath'] != '') { $dir = $col['linkpath']; } $columns[$col['idx']] = $dir; } } // No files to publish if (empty($columns)) { return false; } $repoPath = $objPD->source_dir ? $configs->path . DS . $objPD->source_dir : $configs->path; $csv = $repoPath . DS . $objPD->source_file; if (file_exists($csv) && ($handle = fopen($csv, "r")) !== FALSE) { // Check if expert mode CSV $expert_mode = false; $col_labels = fgetcsv($handle); $col_prop = fgetcsv($handle); $data_start = fgetcsv($handle); if (isset($data_start[0]) && $data_start[0] == 'DATASTART') { $expert_mode = true; } while ($r = fgetcsv($handle)) { for ($i = 0; $i < count($col_labels); $i++) { if (isset($columns[$i])) { if (isset($r[$i]) && $r[$i] != '') { $file = $columns[$i] ? $columns[$i] . DS . trim($r[$i]) : trim($r[$i]); if (file_exists($repoPath . DS . $file)) { $files[] = $file; } } } } } } // Copy files from repo to published location if (!empty($files)) { foreach ($files as $file) { if (!file_exists($repoPath . DS . $file)) { continue; } // If parent dir does not exist, we must create it if (!file_exists(dirname($configs->dataPath . DS . $file))) { Filesystem::makeDirectory(dirname($configs->dataPath . DS . $file), 0755, true, true); } if (Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $file)) { // Generate thumbnail $thumb = \Components\Publications\Helpers\Html::createThumbName($file, '_tn', $extension = 'gif'); Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $thumb); $hi = new \Hubzero\Image\Processor($configs->dataPath . DS . $thumb); if (count($hi->getErrors()) == 0) { $hi->resize(180, false, false, false); $hi->save($configs->dataPath . DS . $thumb); } else { return false; } // Generate medium image $med = \Components\Publications\Helpers\Html::createThumbName($file, '_medium', $extension = 'gif'); Filesystem::copy($repoPath . DS . $file, $configs->dataPath . DS . $med); $hi = new \Hubzero\Image\Processor($configs->dataPath . DS . $med); if (count($hi->getErrors()) == 0) { $hi->resize(800, false, false, false); $hi->save($configs->dataPath . DS . $med); } else { return false; } } } } }
/** * Get path to archival bundle * * @return mixed */ public function bundlePath() { if (!$this->exists()) { return false; } if (!isset($this->_bundlePath)) { // Archival package $tarname = Lang::txt('Publication') . '_' . $this->get('id') . '.zip'; $this->_bundlePath = Helpers\Html::buildPubPath($this->get('id'), $this->get('version_id'), '', '', 1) . DS . $tarname; } return $this->_bundlePath; }
</div><!-- / .aside --> </section><!-- / .main section --> </div> <?php } $html = ''; // Part below if ($this->publication->access('view-all')) { $html .= '<div class="clear sep"></div>' . "\n"; $html .= '<section class="main section noborder">' . "\n"; $html .= ' <div class="subject tabbed">' . "\n"; $html .= \Components\Publications\Helpers\Html::tabs($this->option, $this->publication->id, $this->cats, $this->tab, $this->publication->alias, $this->version); $html .= \Components\Publications\Helpers\Html::sections($this->sections, $this->cats, $this->tab, 'hide', 'main'); // Add footer notice if ($this->tab == 'about') { $html .= \Components\Publications\Helpers\Html::footer($this->publication); } $html .= '</div><!-- / .subject -->' . "\n"; $html .= ' <div class="aside extracontent">' . "\n"; } // Show related content $out = Event::trigger('publications.onPublicationSub', array($this->publication, $this->option, 1)); if (count($out) > 0) { foreach ($out as $ou) { if (isset($ou['html'])) { $html .= $ou['html']; } } } // Show what's popular if ($this->tab == 'about') {
/** * Deletes assoc with pub version * * @param integer $vid * @param integer $pid * @return void */ public function deleteVersionExistence($vid, $pid) { // Delete authors $pa = new Tables\Author($this->database); $authors = $pa->deleteAssociations($vid); // Delete attachments $pContent = new Tables\Attachment($this->database); $pContent->deleteAttachments($vid); // Delete screenshots $pScreenshot = new Tables\Screenshot($this->database); $pScreenshot->deleteScreenshots($vid); // Delete access accosiations $pAccess = new Tables\Access($this->database); $pAccess->deleteGroups($vid); // Delete audience $pAudience = new Tables\Audience($this->database); $pAudience->deleteAudience($vid); // Build publication path $path = Helpers\Html::buildPubPath($pid, $vid, $this->config->get('webpath'), '', 1); // Delete all files if (is_dir($path)) { Filesystem::deleteDirectory($path); } return true; }
/** * Save block * * @return string HTML */ public function save($manifest = NULL, $blockId = 0, $pub = NULL, $actor = 0, $elementId = 0) { // Set block manifest if ($this->_manifest === NULL) { $this->_manifest = $manifest ? $manifest : self::getManifest(); } // Make sure changes are allowed if ($this->_parent->checkFreeze($this->_manifest->params, $pub)) { return false; } // Load publication version $row = new \Components\Publications\Tables\Version($this->_parent->_db); if (!$row->load($pub->version_id)) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND')); return false; } // Track changes $changed = 0; $missed = 0; $collapse = $this->_manifest->params->collapse_elements == 0 ? 0 : 1; // Incoming $nbtags = Request::getVar('nbtag', array(), 'request', 'array'); // Parse metadata $data = array(); preg_match_all("#<nb:(.*?)>(.*?)</nb:(.*?)>#s", $pub->metadata, $matches, PREG_SET_ORDER); if (count($matches) > 0) { foreach ($matches as $match) { $data[$match[1]] = \Components\Publications\Helpers\Html::_txtUnpee($match[2]); } } // Save each element foreach ($this->_manifest->elements as $id => $element) { // Are we saving just one element? if ($elementId && $id != $elementId && $collapse) { continue; } $field = $element->params->field; $aliasmap = $element->params->aliasmap; $input = $element->params->input; $required = $element->params->required; if ($field == 'metadata') { $value = isset($nbtags[$aliasmap]) ? trim(stripslashes($nbtags[$aliasmap])) : NULL; if (!$value && $required) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED')); } else { if ($value && !isset($data[$aliasmap]) || isset($data[$aliasmap]) && $data[$aliasmap] != $value) { $changed++; } // Replace data $data[$aliasmap] = $value; // Save all in one field $tagCollect = ''; foreach ($data as $tagname => $tagcontent) { $tagCollect .= "\n" . '<nb:' . $tagname . '>' . $tagcontent . '</nb:' . $tagname . '>' . "\n"; } $row->metadata = $tagCollect; } } else { $value = trim(Request::getVar($field, '', 'post', 'none', 2)); $value = $input == 'editor' ? stripslashes($value) : \Hubzero\Utility\Sanitize::clean($value); if (!$value && $required) { $missed++; } if ($row->{$field} != $value) { $lastRecord = $pub->_curationModel->getLastUpdate($id, $this->_name, $blockId); $changed++; // Record update time $data = new stdClass(); $data->updated = Date::toSql(); $data->updated_by = $actor; // Unmark as skipped if ($lastRecord && $lastRecord->review_status == 3) { $data->review_status = 0; $data->update = ''; } if ($value) { $data->update = ''; // remove dispute message if requirement satisfied } $pub->_curationModel->saveUpdate($data, $id, $this->_name, $pub, $blockId); } $row->{$field} = $value; } } // Update modified info if ($changed) { $row->modified = Date::toSql(); $row->modified_by = $actor; $this->_parent->set('_update', 1); } // Report error if ($missed && $collapse == 0) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_MISSING_REQUIRED')); } // Save if (!$row->store()) { $this->setError(Lang::txt('PLG_PROJECTS_PUBLICATIONS_ERROR_SAVE_PUBLICATION')); return false; } // Set success message $this->_parent->set('_message', $this->get('_message')); return true; }
echo $launcher; } ?> <div class="version-info"> <?php echo \Components\Publications\Helpers\Html::showVersionInfo($this->publication); echo \Components\Publications\Helpers\Html::showLicense($this->publication, 'play'); ?> </div> </div> <div class="col span2 omega"> <div class="meta"> <?php if ($this->publication->state == 1 && $this->publication->main == 1) { // Show metadata $this->view('_metadata')->set('option', $this->option)->set('publication', $this->publication)->set('config', $this->config)->set('version', $this->version)->set('sections', $this->sections)->set('cats', $this->cats)->set('params', $this->publication->params)->set('lastPubRelease', $this->lastPubRelease)->set('launcherLayout', true)->display(); } ?> </div> </div> </div> </section> <div class="launcher-notes"> <?php // Show status for authorized users if ($this->contributable) { echo \Components\Publications\Helpers\Html::showAccessMessage($this->publication); } ?> </div>
/** * Conversion for publications created in a non-curated flow * * @param object $pub * @return boolean */ public function convertToCuration($pub = NULL) { $pub = $pub ? $pub : $this->_pub; $oldFlow = false; // Load attachments $pub->attachments(); if (!isset($pub->_attachments) || empty($pub->_attachments['elements'])) { // Nothing to convert return false; } // Get supporting docs element manifest $sElements = self::getElements(2); $sElement = $sElements ? $sElements[0] : NULL; // Loop through attachments foreach ($pub->_attachments['elements'] as $elementId => $elementAttachments) { if (empty($elementAttachments)) { continue; } // Check if any attachments are missing element id foreach ($elementAttachments as $elAttach) { if ($elAttach->element_id == 0) { // Save elementid $row = new Tables\Attachment($this->_db); if ($row->load($elAttach->id)) { $markId = $elAttach->role != 1 && $sElement ? $sElement->id : $elementId; $row->element_id = $markId; $row->store(); } $oldFlow = true; // will need to make further checks } } } if (!$oldFlow) { return false; } // Get gallery element manifest $elements = self::getElements(3); $element = $elements ? $elements[0] : NULL; // Retrieve screenshots $pScreenshot = new Tables\Screenshot($this->_db); $shots = $pScreenshot->getScreenshots($pub->version_id); // Transfer gallery files to the right location if ($element && $shots) { // Get attachment type model $attModel = new Attachments($this->_db); $fileAttach = $attModel->loadAttach('file'); // Set configs $configs = $fileAttach->getConfigs($element->manifest->params, $element->id, $pub, $element->block); // Get gallery path $galleryPath = Helpers\Html::buildPubPath($pub->id, $pub->version_id, '', 'gallery', 1); if (is_dir($galleryPath)) { foreach ($shots as $shot) { $objPA = new Tables\Attachment($this->_db); if (is_file($galleryPath . DS . $shot->srcfile) && !$objPA->loadElementAttachment($pub->version_id, array('path' => $shot->filename), $element->id, 'file', $element->manifest->params->role)) { $objPA = new Tables\Attachment($this->_db); $objPA->publication_id = $pub->id; $objPA->publication_version_id = $pub->version_id; $objPA->path = $shot->filename; $objPA->type = 'file'; $objPA->created_by = User::get('id'); $objPA->created = Date::toSql(); $objPA->role = $element->manifest->params->role; $objPA->element_id = $element->id; $objPA->ordering = $shot->ordering; if (!$objPA->store()) { continue; } // Check if names is already used $suffix = $fileAttach->checkForDuplicate($configs->path . DS . $objPA->path, $objPA, $configs); // Save params if applicable if ($suffix) { $objPA->params = 'suffix=' . $suffix . "\n"; } // Copy file into the right spot $configs->copyFrom = $galleryPath . DS . $shot->srcfile; if (!$fileAttach->publishAttachment($objPA, $pub, $configs)) { $objPA->delete(); } } } } } // Check if published version has curation manifest saved $row = new Tables\Version($this->_db); if ($pub->state == 1 && !$pub->curation) { if ($row->load($pub->version_id)) { $row->curation = json_encode($this->_manifest); $row->store(); } } // Mark as curated $row->saveParam($row->id, 'curated', 1); return true; }
$cite->year = $this->publication->published_up && $this->publication->published_up != '0000-00-00 00:00:00' ? Date::of($this->publication->published_up)->toLocal('Y') : Date::of('now')->toLocal('Y'); $cite->location = ''; $cite->date = ''; $cite->doi = $this->publication->doi ? $this->publication->doi : ''; $cite->url = $cite->doi ? trim($this->config->get('doi_resolve', 'http://dx.doi.org/'), DS) . DS . $cite->doi : NULL; $cite->type = ''; $cite->pages = ''; $cite->author = $this->publication->getUnlinkedContributors(); $cite->publisher = $this->config->get('doi_publisher', ''); if ($this->publication->params->get('show_citation') == 2) { $citations = ''; } } else { $cite = null; } $citeinstruct = \Components\Publications\Helpers\Html::citation($cite, $this->publication, $citations); ?> <h4 id="citethis"><?php echo Lang::txt('COM_PUBLICATIONS_CITE_THIS'); ?> </h4> <div class="pub-content"> <?php echo $citeinstruct; ?> </div> <?php } if ($this->publication->params->get('show_submitter') && $this->publication->submitter()) { ?> <h4><?php
/** * Return data on a resource view (this will be some form of HTML) * * @param object $publication Current publication * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @param string $version Version name * @param boolean $extended Whether or not to show panel * @return array */ public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true, $authorized = true) { $arr = array('html' => '', 'metadata' => ''); // Check if our area is in the array of areas we want to return results for if (is_array($areas)) { if (!array_intersect($areas, $this->onPublicationAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationAreas($publication)))) { // do nothing return $arr; } } if (!$publication->_category->_params->get('plg_supportingdocs')) { return $arr; } // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { $database = App::get('db'); $config = Component::params($option); // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'supportingdocs', 'name' => 'browse')); // Get docs $pContent = new \Components\Publications\Tables\Attachment($database); $view->docs = $pContent->getAttachments($publication->version_id, $filters = array('role' => array(1, 0, 2), 'order' => 'a.role DESC, a.ordering ASC')); // Get projects html helper require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'helpers' . DS . 'html.php'; // Build publication path $base_path = $config->get('webpath'); $view->path = \Components\Publications\Helpers\Html::buildPubPath($publication->id, $publication->version_id, $base_path, $publication->secret, $root = 1); // Pass the view some info $view->option = $option; $view->publication = $publication; $view->config = $config; $view->version = $version; $view->live_site = Request::base(); $view->authorized = $authorized; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } return $arr; }
/** * Static method for formatting results * * @param object $row Database row * @return string HTML */ public static function out($row) { include_once Component::path('com_publications') . DS . 'tables' . DS . 'author.php'; require_once Component::path('com_publications') . DS . 'helpers' . DS . 'html.php'; $row->href = Route::url('index.php?option=com_publications&id=' . $row->id); $database = App::get('db'); // Get version authors $pa = new \Components\Publications\Tables\Author($database); $authors = $pa->getAuthors($row->ftext); // Get the component params $config = Component::params('com_publications'); $row->rating = $row->rcount; $row->category = $row->data1; $row->area = $row->data2; $row->ranking = $row->data3; // Set the display date switch ($config->get('show_date')) { case 0: $thedate = ''; break; case 1: $thedate = Date::of($row->created)->toLocal(Lang::txt('DATE_FORMAT_HZ1')); break; case 2: $thedate = Date::of($row->modified)->toLocal(Lang::txt('DATE_FORMAT_HZ1')); break; case 3: $thedate = Date::of($row->publish_up)->toLocal(Lang::txt('DATE_FORMAT_HZ1')); break; } if (strstr($row->href, 'index.php')) { $row->href = Route::url($row->href); } // Start building the HTML $html = "\t" . '<li class="'; $html .= 'publication">' . "\n"; $html .= "\t\t" . '<p class="title"><a href="' . $row->href . '/?v=' . $row->alias . '">' . stripslashes($row->title) . '</a></p>' . "\n"; $html .= "\t\t" . '<p class="details">' . $thedate . ' <span>|</span> ' . $row->area; if ($authors) { $html .= ' <span>|</span> ' . Lang::txt('PLG_TAGS_PUBLICATIONS_CONTRIBUTORS') . ' ' . stripslashes(\Components\Publications\Helpers\Html::showContributors($authors, true, false)); } $html .= '</p>' . "\n"; if ($row->itext) { $html .= "\t\t" . '<p>' . \Hubzero\Utility\String::truncate(\Hubzero\Utility\Sanitize::stripAll(stripslashes($row->itext)), 200) . '</p>' . "\n"; } $html .= "\t\t" . '<p class="href">' . Request::base() . trim($row->href . '/?v=' . $row->alias, '/') . '</p>' . "\n"; $html .= "\t" . '</li>' . "\n"; // Return output return $html; }
/** * Download a file * * @return void */ public function downloadTask() { // Incoming $pid = Request::getInt('id', 0); $vid = Request::getInt('v', 0); $source = NULL; // Need pub and version ID if (!$pid || $pid == 0 || !$vid) { return; } // Get the file name $uri = Request::getVar('REQUEST_URI', '', 'server'); if (strstr($uri, 'Image:')) { $file = str_replace('Image:', '', strstr($uri, 'Image:')); } elseif (strstr($uri, 'File:')) { $file = str_replace('File:', '', strstr($uri, 'File:')); } //decode file name $file = urldecode($file); if (strtolower($file) == 'thumb') { // Get publication thumbnail $source = Helpers\Html::getThumb($pid, $vid, $this->config); } else { // Build publication path $path = Helpers\Html::buildPubPath($pid, $vid, $this->config->get('webpath')); if (strtolower($file) == 'master') { // Get master image $source = $path . DS . 'master.png'; // Default image if (!is_file(PATH_APP . DS . $source)) { // Grab first bigger image in gallery if (is_dir(PATH_APP . DS . $path . DS . 'gallery')) { $file_list = scandir(PATH_APP . DS . $path . DS . 'gallery'); foreach ($file_list as $file) { list($width, $height, $type, $attr) = getimagesize(PATH_APP . DS . $path . DS . 'gallery' . DS . $file); if ($width > 200) { $source = $path . DS . 'gallery' . DS . $file; break; } } } if (!is_file(PATH_APP . DS . $source)) { $source = PATH_CORE . DS . trim($this->config->get('masterimage', 'components/com_publications/site/assets/img/master.png'), DS); } } } else { // Load from gallery $source = PATH_APP . DS . $path . DS . 'gallery' . DS . $file; // Default image if (!is_file($source)) { $source = PATH_CORE . DS . trim($this->config->get('gallery_thumb', 'components/com_publications/site/assets/img/gallery_thumb.gif'), DS); } } } if (is_file($source)) { $server = new \Hubzero\Content\Server(); $server->filename($source); $server->serve_inline($source); exit; } return; }
* 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; // Get creator name $creator = $this->pub->creator('name') . ' (' . $this->pub->creator('username') . ')'; // Version status $status = $this->pub->getStatusName(); $class = $this->pub->getStatusCss(); // Get block content $blockcontent = $this->pub->_curationModel->parseBlock('edit'); // Write title echo \Components\Publications\Helpers\Html::showPubTitle($this->pub, $this->title); // Draw status bar echo $this->pub->_curationModel->drawStatusBar(); ?> <div id="pub-body"> <?php echo $blockcontent; ?> </div> <p class="rightfloat"> <a href="<?php echo Route::url($this->pub->link('version')); ?> " class="public-page" rel="external" title="<?php echo Lang::txt('PLG_PROJECTS_PUBLICATIONS_VIEW_PUB_PAGE'); ?>
/** * Draw launcher * * @return string HTML */ public function drawLauncher($element, $elementId, $pub, $blockParams, $elements, $authorized) { // Get configs $configs = $this->getConfigs($element->params, $elementId, $pub, $blockParams); $attachments = $pub->_attachments; $attachments = isset($attachments['elements'][$elementId]) ? $attachments['elements'][$elementId] : NULL; // Sort out attachments for this element $attachments = $this->_parent->getElementAttachments($elementId, $attachments, $this->_name); $disabled = 0; $pop = NULL; $mconfig = Component::params('com_tools'); // Ensure we have a connection to the middleware if (!$mconfig->get('mw_on')) { $pop = Lang::txt('COM_PUBLICATIONS_STATE_SESSION_INVOKE_DISABLED_POP'); $disabled = 1; } elseif ($pub->isUnpublished() || $pub->isDown()) { $pop = Lang::txt('COM_PUBLICATIONS_STATE_UNPUBLISHED_POP'); $disabled = 1; } elseif (!$authorized) { $pop = $pub->access == 1 ? Lang::txt('COM_PUBLICATIONS_STATE_REGISTERED_POP') : Lang::txt('COM_PUBLICATIONS_STATE_RESTRICTED_POP'); $disabled = 1; } elseif (!$attachments) { $disabled = 1; $pop = Lang::txt('COM_PUBLICATIONS_ERROR_CONTENT_UNAVAILABLE'); } $pop = $pop ? '<p class="warning">' . $pop . '</p>' : ''; $html = ''; // Which role? $role = $element->params->role; $url = Route::url('index.php?option=com_publications&task=serve&id=' . $pub->id . '&v=' . $pub->version_number) . '?el=' . $elementId; // Primary button if ($role == 1) { $attach = $attachments[0]; if (count($attachments) > 1) { // TBD } // One launcher for all items $label = Lang::txt('COM_PUBLICATIONS_LAUNCH_TOOL'); $class = 'btn btn-primary active icon-next'; $class .= $disabled ? ' link_disabled' : ''; $title = $configs->title ? $configs->title : Lang::txt('COM_PUBLICATIONS_LAUNCH_TOOL'); $html = \Components\Publications\Helpers\Html::primaryButton($class, $url, $label, NULL, $title, 'rel="external"', $disabled, $pop); } elseif ($role == 2 && $attachments) { $html .= '<ul>'; $html .= self::drawList($attachments, $element, $elementId, $pub, $blockParams, $authorized); $html .= '</ul>'; } return $html; }
/** * Get path to log file * * @return void */ public function getLogPath($pid = 0, $vid = 0) { if (!isset($this->_config)) { $this->_config = Component::params('com_publications'); } if (!$pid || !$vid) { return false; } // Build log path (access logs) $logPath = Html::buildPubPath($pid, $vid, $this->_config->get('webpath'), 'logs', 1); if (!is_dir($logPath)) { return false; } return $logPath; }
} else { $sef = Route::url('index.php?option=com_topics&scope=' . $line->scope . '&pagename=' . $line->alias); } } else { $class = \Components\Publications\Helpers\Html::getRatingClass($line->rating); // Get version authors $authors = $pa->getAuthors($line->version); $authorlist = \Components\Publications\Helpers\Html::showContributors($authors, false, true); // If the user is logged in, get their rating for this publication if (!User::isGuest()) { $mr = new \Components\Publications\Tables\Review($database); $myrating = $mr->loadUserRating($line->id, User::get('id'), $line->version); } else { $myrating = 0; } $myclass = \Components\Publications\Helpers\Html::getRatingClass($myrating); // Get the SEF for the publication if ($line->alias) { $sef = Route::url('index.php?option=' . $this->option . '&alias=' . $line->alias); } else { $sef = Route::url('index.php?option=' . $this->option . '&id=' . $line->id); } } // Make sure we have an SEF, otherwise it's a querystring if (strstr($sef, 'option=')) { $d = '&'; } else { $d = '?'; } // Format the ranking $line->ranking = round($line->ranking, 1);
/** * Static method for formatting results * * @param object $row Database row * @return string HTML */ public static function out($row) { $database = App::get('db'); $thedate = Date::of($row->published_up)->toLocal('d M Y'); // Get version authors $pa = new \Components\Publications\Tables\Author($database); $authors = $pa->getAuthors($row->version_id); $html = "\t" . '<li class="resource">' . "\n"; $html .= "\t\t" . '<p class="title"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a></p>' . "\n"; $html .= "\t\t" . '<p class="details">' . $thedate . ' <span>|</span> ' . stripslashes($row->cat_name); if ($authors) { $html .= ' <span>|</span>' . Lang::txt('PLG_MEMBERS_IMPACT_CONTRIBUTORS') . ': ' . \Components\Publications\Helpers\Html::showContributors($authors, false, true) . "\n"; } if ($row->doi) { $html .= ' <span>|</span> doi:' . $row->doi . "\n"; } if (!$row->project_provisioned && (isset($row->project_private) && $row->project_private != 1 || $row->author == true)) { $url = 'index.php?option=com_projects&alias=' . $row->project_alias; $url .= $row->author == true ? '&active=publications&pid=' . $row->id : ''; $html .= ' <span>|</span> Project: '; $html .= '<a href="'; $html .= Route::url($url) . '">'; $html .= $row->project_title; $html .= '</a>'; $html .= "\n"; } $html .= '</p>' . "\n"; if ($row->text) { $html .= "\t\t<p>" . \Hubzero\Utility\String::truncate(strip_tags(stripslashes($row->text)), 300) . "</p>\n"; } $html .= "\t" . '</li>' . "\n"; return $html; }
/** * Special formatting for results * * @param object $row Database row * @param string $period Time period * @return string */ public static function out($row, $period) { $database = App::get('db'); $config = Component::params('com_publications'); // Get version authors $pa = new \Components\Publications\Tables\Author($database); $authors = $pa->getAuthors($row->version_id); // Start building HTML $html = "\t" . '<li class="publication">' . "\n"; $html .= "\t\t" . '<p><span class="pub-thumb"><img src="' . Route::url('index.php?option=com_publications&id=' . $row->id . '&v=' . $row->version_id) . '/Image:thumb' . '" alt="" /></span>'; $html .= '<span class="pub-details"><a href="' . $row->href . '">' . stripslashes($row->title) . '</a>' . "\n"; $html .= "\t\t" . '<span class="block details">' . Date::of($row->published_up)->toLocal('d M Y') . ' <span>|</span> ' . $row->cat_name; if ($authors) { $html .= ' <span>|</span> ' . Lang::txt('PLG_WHATSNEW_PUBLICATIONS_CONTRIBUTORS') . ' ' . \Components\Publications\Helpers\Html::showContributors($authors, false, true); } $html .= '</span></span></p>' . "\n"; if ($row->text) { $html .= "\t\t" . '<p>' . \Hubzero\Utility\String::truncate(\Hubzero\Utility\Sanitize::stripAll(stripslashes($row->text)), 200) . '</p>' . "\n"; } $html .= "\t\t" . '<p class="href">' . Request::base() . trim($row->href, '/') . '</p>' . "\n"; $html .= "\t" . '</li>' . "\n"; // Return output return $html; }
/** * Show disk usage * * @param object $model Project model * @param string $repoName * @param integer $by * @return string */ public function diskspace($model, $repoName = 'local', $by = '') { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'diskspace')); if (!isset($this->repo)) { $this->repo = new \Components\Projects\Models\Repo($model, $repoName); } $url = Route::url('index.php?option=' . $this->_option . '&alias=' . $model->get('alias') . '&active=files&action=diskspace'); // Report usage with all history? if ($this->params->get('disk_usage') == true || $by == 'admin') { $view->dirsize = $this->repo->call('getDiskUsage', $params = array('working' => true, 'history' => true)); $view->totalspace = $this->repo->call('getDiskUsage', $params = array('working' => false, 'history' => false)); } else { $view->totalspace = $this->repo->call('getDiskUsage', $params = array('working' => false, 'history' => true)); $view->dirsize = $view->totalspace; } // Get publication usage if (Plugin::isEnabled('projects', 'publications') && $by == 'admin') { require_once Component::path('com_publications') . DS . 'helpers' . DS . 'html.php'; $filters = array(); $filters['project'] = $model->get('id'); $filters['ignore_access'] = 1; $filters['dev'] = 1; $database = \App::get('db'); $objP = new \Components\Publications\Tables\Publication($database); $pubs = $objP->getRecords($filters); $view->pubDiskUsage = \Components\Publications\Helpers\Html::getDiskUsage($pubs); $view->pubQuota = $model->params->get('pubQuota') ? $model->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b'); } $view->total = $this->repo->count(); $view->quota = $model->params->get('quota', \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('defaultQuota', '1')), 'GB', 'b')); $view->by = $by; $view->model = $model; $view->option = $this->_option; $view->config = $model->config(); $view->title = isset($this->_area['title']) ? $this->_area['title'] : ''; $view->params = $this->params; return $view->loadTemplate(); }
/** * Transfer files from one version to another * * @return boolean */ public function transferData($elementparams, $elementId, $pub, $blockParams, $attachments, $oldVersion, $newVersion) { // Get configs $configs = $this->getConfigs($elementparams, $elementId, $pub, $blockParams); // Get configs for new version $typeParams = $elementparams->typeParams; $directory = isset($typeParams->directory) && $typeParams->directory ? $typeParams->directory : $newVersion->secret; $newConfigs = new stdClass(); // Directory path within pub folder $newConfigs->dirPath = $configs->subdir ? $directory . DS . $configs->subdir : $directory; // Build new path $newPath = \Components\Publications\Helpers\Html::buildPubPath($pub->id, $newVersion->id, '', $newConfigs->dirPath, 1); $newConfigs->pubPath = $newPath; $newConfigs->dirHierarchy = $configs->dirHierarchy; // Create new path if (!is_dir($newPath)) { Filesystem::makeDirectory($newPath, 0755, true, true); } // Loop through attachments foreach ($attachments as $att) { // Make new attachment record $pAttach = new \Components\Publications\Tables\Attachment($this->_parent->_db); if (!$pAttach->copyAttachment($att, $newVersion->id, $elementId, User::get('id'))) { continue; } // Get paths $copyFrom = $this->getFilePath($att->path, $att->id, $configs, $att->params); $copyTo = $this->getFilePath($pAttach->path, $pAttach->id, $newConfigs, $pAttach->params); if (!is_file($copyFrom)) { $pAttach->delete(); continue; } // Make sure we have subdirectories if (!is_dir(dirname($copyTo))) { Filesystem::makeDirectory(dirname($copyTo), 0755, true, true); } // Copy file if (!Filesystem::copy($copyFrom, $copyTo)) { $pAttach->delete(); } else { // Also make hash $md5hash = hash_file('sha256', $copyTo); $pAttach->content_hash = $md5hash; // Create hash file $hfile = $copyTo . '.hash'; if (!is_file($hfile)) { $handle = fopen($hfile, 'w'); fwrite($handle, $md5hash); fclose($handle); chmod($hfile, 0644); } $pAttach->store(); // Produce thumbnail (if applicable) if ($configs->handler && $configs->handler->getName() == 'imageviewer') { $configs->handler->makeThumbnail($pAttach, $pub, $newConfigs); } } } return true; }
* * 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; $this->css()->js()->css('jquery.fancybox.css', 'system')->css('curation.css')->js('curation.js'); $status = $this->pub->getStatusName(); $class = $this->pub->getStatusCss(); $typetitle = \Components\Publications\Helpers\Html::writePubCategory($this->pub->category()->alias, $this->pub->category()->name); ?> <div id="content-header"> <h2><?php echo $this->title; ?> </h2> </div><!-- / #content-header --> <div id="content-header-extra"> <ul id="useroptions"> <li><a class="btn icon-browse" href="<?php echo Route::url('index.php?option=' . $this->option . '&controller=curation'); ?> "><?php echo Lang::txt('COM_PUBLICATIONS_CURATION_LIST'); ?>
/** * Make thumb * * @return void */ public function makeThumbnail($row, $pub, $configs) { // Make sure we got config if (!$this->_config) { $this->getConfig(); } $fpath = $this->getFilePath($row->path, $row->id, $configs, $row->params); $thumbName = \Components\Publications\Helpers\Html::createThumbName(basename($fpath), $this->_config->params->thumbSuffix, $this->_config->params->thumbFormat); $thumbPath = $configs->pubPath . DS . $thumbName; // No file found if (!is_file($fpath)) { return; } // Check if image if (!getimagesize($fpath)) { return false; } $md5 = hash_file('sha256', $fpath); // Create/update thumb if doesn't exist or file changed if (!is_file($thumbPath) || $md5 != $row->content_hash) { Filesystem::copy($fpath, $thumbPath); $hi = new \Hubzero\Image\Processor($thumbPath); if (count($hi->getErrors()) == 0) { $hi->resize($this->_config->params->thumbWidth, false, true, true); $hi->save($thumbPath); } else { return false; } } return true; }