/** * Return data on a resource sub view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param integer $miniview View style * @return array */ public function onResourcesSub($resource, $option, $miniview = 0) { $arr = array('area' => $this->_name, 'html' => '', 'metadata' => ''); // Get some needed libraries include_once __DIR__ . DS . 'resources.recommendation.php'; // Set some filters for returning results $filters = array('id' => $resource->id, 'threshold' => $this->params->get('threshold', '0.21'), 'limit' => $this->params->get('display_limit', 10)); $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Instantiate a view if ($miniview) { $view->setLayout('mini'); } // Pass the view some info $view->option = $option; $view->resource = $resource; // Get recommendations $database = App::get('db'); $r = new ResourcesRecommendation($database); $view->results = $r->getResults($filters); if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); return $arr; }
/** * Return data on a resource sub view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param integer $miniview View style * @return array */ public function onResourcesSub($resource, $option, $miniview = 0) { $arr = array('area' => $this->_name, 'html' => '', 'metadata' => ''); $database = App::get('db'); // Build the query that checks topic pages $sql1 = "SELECT v.id, v.pageid, MAX(v.version) AS version, w.title, w.pagename AS alias, v.pagetext AS introtext,\n\t\t\t\t\tNULL AS type, NULL AS published, NULL AS publish_up, w.scope, w.rating, w.times_rated, w.ranking, 'Topic' AS section, w.`group_cn`\n\t\t\t\tFROM `#__wiki_page` AS w\n\t\t\t\tJOIN `#__wiki_version` AS v ON w.id=v.pageid\n\t\t\t\tJOIN `#__wiki_page_links` AS wl ON wl.page_id=w.id\n\t\t\t\tWHERE v.approved=1 AND wl.scope='resource' AND wl.scope_id=" . $database->Quote($resource->id); if (!User::isGuest()) { if (User::authorize('com_resources', 'manage') || User::authorize('com_groups', 'manage')) { $sql1 .= ''; } else { $ugs = \Hubzero\User\Helper::getGroups(User::get('id'), 'members'); $groups = array(); if ($ugs && count($ugs) > 0) { foreach ($ugs as $ug) { $groups[] = $ug->cn; } } $g = "'" . implode("','", $groups) . "'"; $sql1 .= "AND (w.access!=1 OR (w.access=1 AND (w.group_cn IN ({$g}) OR w.created_by='" . User::get('id') . "'))) "; } } else { $sql1 .= "AND w.access!=1 "; } $sql1 .= "GROUP BY pageid ORDER BY ranking DESC, title LIMIT 10"; // Build the query that checks resource parents $sql2 = "SELECT DISTINCT r.id, NULL AS pageid, NULL AS version, r.title, r.alias, r.introtext, r.type, r.published, r.publish_up, " . " NULL AS scope, r.rating, r.times_rated, r.ranking, rt.type AS section, NULL AS `group` " . " FROM #__resource_types AS rt, #__resources AS r" . " JOIN #__resource_assoc AS a ON r.id=a.parent_id" . " LEFT JOIN #__resource_types AS t ON r.logical_type=t.id" . " WHERE r.published=1 AND a.child_id=" . $resource->id . " AND r.type=rt.id AND r.type!=8 "; if (!User::isGuest()) { if (User::authorize('com_resources', 'manage') || User::authorize('com_groups', 'manage')) { $sql2 .= ''; } else { $sql2 .= "AND (r.access!=1 OR (r.access=1 AND (r.group_owner IN ({$g}) OR r.created_by='" . User::get('id') . "'))) "; } } else { $sql2 .= "AND r.access=0 "; } $sql2 .= "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); $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Instantiate a view if ($miniview) { $view->setLayout('mini'); } // Pass the view some info $view->option = $option; $view->resource = $resource; $view->related = $database->loadObjectList(); foreach ($this->getErrors() as $error) { $view->setError($error); } // Return the output $arr['html'] = $view->loadTemplate(); // Return the an array of content return $arr; }
/** * Manage connections to outside services * * @param string $service Service name (google/dropbox) * @param string $callback URL to return to after authorization * @return string */ protected function _connect($service = '', $callback = '') { // Incoming $service = $service ? $service : Request::getVar('service', ''); $reauth = Request::getInt('reauth', 0); $removeData = Request::getInt('removedata', 1); // Build pub url $url = Route::url($this->model->link('files')); // Build return URL $return = $callback ? $callback : $url . '?action=connect'; // Handle authentication request for service if ($service) { $configs = $this->_connect->getConfigs($service, false); if ($this->_task == 'disconnect') { if ($this->_connect->disconnect($service, $removeData)) { $this->_msg = Lang::txt('PLG_PROJECTS_FILES_DISCONNECT_SUCCESS') . ' ' . $configs['servicename']; } else { $this->setError($this->_connect->getError()); } // Redirect to connect screen App::redirect(Route::url($this->model->link('files') . '&action=connect')); return; } elseif (!$this->_connect->makeConnection($service, $reauth, $return)) { $this->setError($this->_connect->getError()); } else { // Successful authentication if (!$this->_connect->afterConnect($service, $this->_uid)) { $this->setError($this->_connect->getError()); } else { $this->_msg = Lang::txt('PLG_PROJECTS_FILES_CONNECT_SUCCESS'); } } // Refresh info $this->_connect->setConfigs(); } // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'connect')); $view->option = $this->_option; $view->database = $this->_database; $view->model = $this->model; $view->uid = $this->_uid; $view->url = $url; $view->title = $this->_area['title']; $view->services = $this->_connect->getServices(); $view->connect = $this->_connect; // Get refreshed params $this->model->reloadProject(); $view->params = new \Hubzero\Config\Registry($this->model->table()->params); // Get connection details for user $member = $this->model->member(true); $view->oparams = new \Hubzero\Config\Registry($member->params); // Get messages and errors $view->msg = $this->_msg; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Compiles PDF/image preview for any kind of file * * @return string */ public function compile() { // Combine file and folder data $items = $this->getCollection(); // Incoming $download = Request::getInt('download', 0); // Check that we have compile enabled // @FIXME: why are latex and compiled preview tied together? // presumedly we are also 'compiling' pdfs? if (!$this->params->get('latex')) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_COMPILE_NOTALLOWED')); return; } // Output HTML $view = new \Hubzero\Plugin\View(['folder' => 'projects', 'element' => 'files', 'name' => 'connected', 'layout' => 'compiled']); // Make sure we have an item if (count($items) == 0) { $view->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_NO_FILES_TO_COMPILE')); $view->loadTemplate(); return; } // We can only handle one file at a time $file = $items->first(); // Build path for storing temp previews $imagePath = trim($this->model->config()->get('imagepath', '/site/projects'), DS); $outputDir = DS . $imagePath . DS . strtolower($this->model->get('alias')) . DS . 'compiled'; // Make sure output dir exists if (!is_dir(PATH_APP . $outputDir)) { if (!Filesystem::makeDirectory(PATH_APP . $outputDir)) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_UNABLE_TO_CREATE_UPLOAD_PATH')); return; } } // Get LaTeX helper $compiler = new \Components\Projects\Helpers\Compiler(); // Tex compiler path $texPath = DS . trim($this->params->get('texpath'), DS); // Set view args and defaults $view->file = $file; $view->oWidth = '780'; $view->oHeight = '460'; $view->url = $this->model->link('files'); $cExt = 'pdf'; // Tex file? $tex = $compiler->isTexFile($file->getName()); // Build temp name $tempBase = $tex ? 'temp__' . \Components\Projects\Helpers\Html::takeOutExt($file->getName()) : $file->getName(); $tempBase = str_replace(' ', '_', $tempBase); $view->data = $file->isImage() ? NULL : $file->read(); // LaTeX file? if ($tex && !empty($view->data)) { // Clean up data from Windows characters - important! $view->data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $view->data); // Store file locally $tmpfile = PATH_APP . $outputDir . DS . $tempBase; file_put_contents($tmpfile, $view->data); // Compile and get path to PDF $contentFile = $compiler->compileTex($tmpfile, $view->data, $texPath, PATH_APP . $outputDir, 1, $tempBase); // Read log (to show in case of error) $logFile = $tempBase . '.log'; if (file_exists(PATH_APP . $outputDir . DS . $logFile)) { $view->log = Filesystem::read(PATH_APP . $outputDir . DS . $logFile); } if (!$contentFile) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_TEX_FAILED')); } $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile); } else { // Make sure we can handle preview of this type of file if ($file->hasExtension('pdf') || $file->isImage() || !$file->isBinary()) { $origin = $this->connection->provider->alias . '://' . $file->getPath(); $dest = 'compiled://' . $tempBase; // Do the copy Manager::adapter('local', ['path' => PATH_APP . $outputDir . DS], 'compiled'); Manager::copy($origin, $dest); $contentFile = $tempBase; } } // Parse output if (!empty($contentFile) && file_exists(PATH_APP . $outputDir . DS . $contentFile)) { // Get compiled content mimetype $cType = Filesystem::mimetype(PATH_APP . $outputDir . DS . $contentFile); // Is image? if (strpos($cType, 'image/') !== false) { // Fix up object width & height list($width, $height, $type, $attr) = getimagesize(PATH_APP . $outputDir . DS . $contentFile); $xRatio = $view->oWidth / $width; $yRatio = $view->oHeight / $height; if ($xRatio * $height < $view->oHeight) { // Resize the image based on width $view->oHeight = ceil($xRatio * $height); } else { // Resize the image based on height $view->oWidth = ceil($yRatio * $width); } } // Download compiled file? if ($download) { $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile); // Serve up file $server = new \Hubzero\Content\Server(); $server->filename(PATH_APP . $outputDir . DS . $contentFile); $server->disposition('attachment'); $server->acceptranges(false); $server->saveas($pdfName); $result = $server->serve(); if (!$result) { // Should only get here on error throw new Exception(Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'), 404); } else { exit; } } // Generate preview image for browsers that cannot embed pdf if ($cType == 'application/pdf') { // GS path $gspath = trim($this->params->get('gspath'), DS); if ($gspath && file_exists(DS . $gspath . DS . 'gs')) { $gspath = DS . $gspath . DS; $pdfName = $tex ? str_replace('temp__', '', basename($contentFile)) : basename($contentFile); $pdfPath = PATH_APP . $outputDir . DS . $contentFile; $exportPath = PATH_APP . $outputDir . DS . $tempBase . '%d.jpg'; exec($gspath . "gs -dNOPAUSE -sDEVICE=jpeg -r300 -dFirstPage=1 -dLastPage=1 -sOutputFile={$exportPath} {$pdfPath} 2>&1", $out); if (is_file(PATH_APP . $outputDir . DS . $tempBase . '1.jpg')) { $hi = new \Hubzero\Image\Processor(PATH_APP . $outputDir . DS . $tempBase . '1.jpg'); if (count($hi->getErrors()) == 0) { $hi->resize($view->oWidth, false, false, true); $hi->save(PATH_APP . $outputDir . DS . $tempBase . '1.jpg'); } else { return false; } } if (is_file(PATH_APP . $outputDir . DS . $tempBase . '1.jpg')) { $image = $tempBase . '1.jpg'; } } } } elseif (!$this->getError()) { $this->setError(Lang::txt('PLG_PROJECTS_FILES_ERROR_COMPILE_PREVIEW_FAILED')); } $view->file = $file; $view->outputDir = $outputDir; $view->embed = $contentFile; $view->cType = $cType; $view->subdir = $this->subdir; $view->option = $this->_option; $view->image = !empty($image) ? $image : NULL; $view->model = $this->model; $view->repo = $this->repo; $view->connection = $this->connection; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Draw attachment * * @return HTML string */ public function drawAttachment($data, $params) { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'attachments', 'layout' => $this->_name)); $view->data = $data; $view->params = $params; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Handles view events for latex files * * @param \Hubzero\Filesystem\Collection $collection The file collection to view * @return void **/ public function onHandleView(\Hubzero\Filesystem\Collection $collection) { if (!$this->canHandle($collection)) { return false; } $file = $collection->findFirstWithExtension('tex'); // Create view $view = new \Hubzero\Plugin\View(['folder' => 'handlers', 'element' => 'latex', 'name' => 'latex', 'layout' => 'view']); // Build path for storing temp previews $outputDir = PATH_APP . DS . trim($this->params->get('compile_dir', 'site/latex/compiled'), DS); $adapter = Manager::adapter('local', ['path' => $outputDir]); $uniqid = md5(uniqid()); $temp = File::fromPath($uniqid . '.tex', $adapter); // Clean up data from Windows characters - important! $data = preg_replace('/[^(\\x20-\\x7F)\\x0A]*/', '', $file->read()); // Store file locally $temp->write($data); // Build the command $command = DS . trim($this->params->get('texpath', '/usr/bin/pdflatex'), DS); $command .= ' -output-directory=' . $outputDir . ' -interaction=batchmode ' . escapeshellarg($temp->getAbsolutePath()); // Exec and capture output exec($command, $out); $compiled = File::fromPath($uniqid . '.pdf', $adapter); $log = File::fromPath($uniqid . '.log', $adapter); if (!$compiled->size()) { $view->setError(Lang::txt('PLG_HANDLERS_LATEX_ERROR_COMPILE_TEX_FAILED')); } // Read log (to show in case of error) if ($log->size()) { $view->log = $log->read(); } $view->compiled = $compiled; return $view; }
/** * Build panel content * * @return string HTML */ public function buildContent($pub = NULL, $viewname = 'edit') { $name = $viewname == 'freeze' || $viewname == 'curator' ? 'freeze' : 'draft'; // Get selector styles \Hubzero\Document\Assets::addPluginStylesheet('projects', 'publications', 'selector'); // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => $name, 'layout' => 'license')); $view->pub = $pub; $view->manifest = $this->_manifest; $view->step = $this->_blockId; $objL = new \Components\Publications\Tables\License($this->_parent->_db); // Get selected license $view->license = $objL->getPubLicense($pub->version_id); $view->selections = $objL->getBlockLicenses($this->_manifest, $view->license); // Pre-select single available license if (!$view->license && count($view->selections) == 1) { $view->license = new \Components\Publications\Tables\License($this->_parent->_db); $view->license->load($view->selections[0]->id); } if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Build panel content * * @return string HTML */ public function buildContent($pub = NULL, $viewname = 'edit') { $name = $viewname == 'freeze' || $viewname == 'curator' ? 'freeze' : 'draft'; // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => $name, 'layout' => 'citations')); // Get selector styles \Hubzero\Document\Assets::addPluginStylesheet('projects', 'links'); \Hubzero\Document\Assets::addPluginStylesheet('projects', 'files', 'selector'); \Hubzero\Document\Assets::addPluginStylesheet('projects', 'publications', 'selector'); if (!isset($pub->_citations)) { // Get citations for this publication $c = new \Components\Citations\Tables\Citation($this->_parent->_db); $pub->_citations = $c->getCitations('publication', $pub->id); } $view->pub = $pub; $view->manifest = $this->_manifest; $view->step = $this->_blockId; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * 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; }
/** * Browser for within publications * * @return string */ public function browser() { // Incoming $ajax = Request::getInt('ajax', 0); $primary = Request::getInt('primary', 1); $versionid = Request::getInt('versionid', 0); if (!$ajax) { return false; } // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'links', 'name' => 'browser')); // Get current attachments $pContent = new \Components\Publications\Tables\Attachment($this->_database); $role = $primary ? '1' : '0'; $other = $primary ? '0' : '1'; $view->attachments = $pContent->getAttachments($versionid, $filters = array('role' => $role, 'type' => 'link')); // Output HTML $view->option = $this->_option; $view->database = $this->_database; $view->model = $this->model; $view->uid = $this->_uid; $view->config = $this->_config; $view->primary = $primary; $view->versionid = $versionid; // Get messages and errors if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * 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) { $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)))) { $rtrn = 'metadata'; } } if (!$publication->_category->_params->get('plg_citations')) { return $arr; } $database = App::get('db'); // Get a needed library include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'citation.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'association.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; // Get citations for this publication $c = new \Components\Citations\Tables\Citation($database); $citations = $c->getCitations('publication', $publication->id); $arr['count'] = $citations ? count($citations) : 0; $arr['name'] = 'citations'; // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { $config = Component::params($option); // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'citations', 'name' => 'browse')); // Pass the view some info $view->option = $option; $view->publication = $publication; $view->citations = $citations; $view->format = $config->get('citation_format', 'apa'); if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } // Are we returning metadata? if ($rtrn == 'all' || $rtrn == 'metadata') { $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'metadata')); $view->url = Route::url('index.php?option=' . $option . '&' . ($publication->alias ? 'alias=' . $publication->alias : 'id=' . $publication->id) . '&active=citations&v=' . $publication->version_number); $view->citations = $citations; $arr['metadata'] = $view->loadTemplate(); } // Return results return $arr; }
/** * Display a form for adding a question * * @param object $row * @return string */ private function _new($row = null) { // Login required if (User::isGuest()) { App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($_SERVER['REQUEST_URI'])), Lang::txt('PLG_PUBLICATIONS_QUESTIONS_LOGIN_TO_ASK_QUESTION'), 'warning'); return; } Lang::load('com_answers'); $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => $this->_name, 'name' => 'question', 'layout' => 'new')); $view->option = $this->option; $view->publication = $this->publication; if (is_object($row)) { $view->row = $row; } else { $view->row = new \Components\Answers\Models\Question(0); } $view->tag = $this->filters['tag']; // Are we banking? $upconfig = Component::params('com_members'); $view->banking = $upconfig->get('bankAccounts'); $view->funds = 0; if ($view->banking) { $BTL = new \Hubzero\Bank\Teller($this->database, User::get('id')); $funds = $BTL->summary() - $BTL->credit_summary(); $view->funds = $funds > 0 ? $funds : 0; } if ($this->getError()) { foreach ($this->getErrors() as $error) { $view->setError($error); } } return $view->loadTemplate(); }
/** * Return data on a publication 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 * @param string $authorized * @return array */ public function onPublication($publication, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true, $authorized = false) { $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)))) { $rtrn = 'metadata'; } } $database = App::get('db'); // Get pub configs $config = Component::params($option); if ($rtrn == 'all' || $rtrn == 'html') { $objV = new \Components\Publications\Tables\Version($database); $versions = $objV->getVersions($publication->id, $filters = array('public' => 1)); // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'versions', 'name' => 'browse')); // Are we allowing contributions $view->contributable = Plugin::isEnabled('projects', 'publications') ? 1 : 0; // Pass the view some info $view->option = $option; $view->publication = $publication; $view->versions = $versions; $view->config = $config; $view->authorized = $authorized; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } return $arr; }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @return array */ public function onResources($model, $option, $areas, $rtrn = 'all') { $arr = array('area' => $this->_name, '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->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->type->params->get('plg_reviews')) { return $arr; } $ar = $this->onResourcesAreas($model); if (empty($ar)) { $rtrn = ''; } include_once __DIR__ . DS . 'models' . DS . 'review.php'; // Instantiate a helper object and perform any needed actions $h = new PlgResourcesReviewsHelper(); $h->resource = $model->resource; $h->option = $option; $h->_option = $option; $h->execute(); // Get reviews for this resource $database = App::get('db'); $r = new \Components\Resources\Tables\Review($database); $reviews = $r->getRatings($model->resource->id); if (!$reviews) { $reviews = array(); } // Are we returning any HTML? if ($rtrn == 'all' || $rtrn == 'html') { // Did they perform an action? // If so, they need to be logged in first. if (!$h->loggedin) { // Instantiate a view $rtrn = Request::getVar('REQUEST_URI', Route::url('index.php?option=' . $option . '&id=' . $model->resource->id . '&active=' . $this->_name, false, true), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn))); return; } // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Thumbs voting CSS & JS $view->voting = $this->params->get('voting', 1); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->reviews = $reviews; //$view->voting = $voting; $view->h = $h; $view->banking = $this->banking; $view->infolink = $this->infolink; $view->config = $this->params; if ($h->getError()) { foreach ($h->getErrors() as $error) { $view->setError($error); } } // Return the output $arr['html'] = $view->loadTemplate(); } // Build the HTML meant for the "about" tab's metadata overview if ($rtrn == 'all' || $rtrn == 'metadata') { $view = $this->view('default', 'metadata'); $url = 'index.php?option=' . $option . '&' . ($model->resource->alias ? 'alias=' . $model->resource->alias : 'id=' . $model->resource->id) . '&active=' . $this->_name; $view->reviews = $reviews; $view->url = Route::url($url); $view->url2 = Route::url($url . '&action=addreview#reviewform'); $arr['metadata'] = $view->loadTemplate(); } return $arr; }
/** * Build panel content * * @return string HTML */ public function buildContent($pub = NULL, $viewname = 'edit') { $name = $viewname == 'freeze' || $viewname == 'curator' ? 'freeze' : 'draft'; // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => $name, 'layout' => 'review')); \Hubzero\Document\Assets::addComponentStylesheet('com_projects', 'css/calendar'); $view->pub = $pub; $view->manifest = $this->_manifest; $view->step = $this->_blockId; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Create database * * @return array */ public function act_create() { // Check permission if (!$this->model->access('content')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); return; } // Incoming $db_id = Request::getInt('db_id', false); // Get project path $path = \Components\Projects\Helpers\Html::getProjectRepoPath($this->model->get('alias')); $list = array(); $error = false; if (file_exists($path) && is_dir($path)) { chdir($path); exec($this->gitpath . ' ls-files --exclude-standard |grep ".csv"', $list); sort($list); } else { $error = Lang::txt('PLG_PROJECTS_DATABASES_MISSING_REPO'); } // Get project database object $objPD = new \Components\Projects\Tables\Database($this->_database); // Get database list $used_files = $objPD->getUsedItems($this->model->get('id')); $files = array(); foreach ($list as $l) { $info = array(); chdir($path); exec($this->gitpath . ' log --date=local --pretty=format:%f"|#|"%H"|#|"%ad%n "' . $l . '"|head -1', $info); $info = explode('|#|', $info[0]); $file = pathinfo($l); if (!in_array($l, $used_files)) { $files[$file['dirname']][] = array('name' => $file['basename'], 'hash' => $info[1], 'date' => $info[2]); } } // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'databases', 'name' => 'create')); $view->model = $this->model; $view->option = $this->_option; $view->files = $files; $view->msg = NULL; if ($error) { $view->setError($error); } // Get project database object $objPD = new \Components\Projects\Tables\Database($this->_database); if ($objPD->loadRecord($db_id)) { $view->db_id = $db_id; $view->dir = trim($objPD->source_dir, '/'); $view->file = trim($objPD->source_file, '/'); $view->title = $objPD->title; $view->desc = $objPD->description; } return array('html' => $view->loadTemplate()); }
/** * 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) { $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)))) { $rtrn = 'metadata'; } } if (!$publication->_category->_params->get('plg_wishlist') || !$extended) { return $arr; } $database = App::get('db'); // Load component language file Lang::load('com_wishlist') || Lang::load('com_wishlist', PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'site'); $option = 'com_wishlist'; $cat = 'publication'; $refid = $publication->id; $items = 0; $admin = 0; $html = ''; // Include some classes & scripts require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'models' . DS . 'wishlist.php'; require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'site' . DS . 'controllers' . DS . 'wishlists.php'; // Configure controller $controller = new \Components\Wishlist\Site\Controllers\Wishlists(); // Get filters $filters = $controller->getFilters(0); $filters['limit'] = $this->params->get('limit'); // Load some objects $obj = new \Components\Wishlist\Tables\Wishlist($database); $objWish = new \Components\Wishlist\Tables\Wish($database); $objOwner = new \Components\Wishlist\Tables\Owner($database); // Get wishlist id $id = $obj->get_wishlistID($refid, $cat); // Create a new list if necessary if (!$id) { if ($publication->title && $publication->state == 1) { $rtitle = isset($publication->alias) && $publication->alias ? Lang::txt('COM_WISHLIST_NAME_RESOURCE') . ' ' . $publication->alias : Lang::txt('COM_WISHLIST_NAME_PUB_ID') . ' ' . $publication->id; $id = $obj->createlist($cat, $refid, 1, $rtitle, $publication->title); } } // get wishlist data $wishlist = $obj->get_wishlist($id, $refid, $cat); if (!$wishlist) { $html = '<p class="error">' . Lang::txt('COM_WISHLIST_ERROR_LIST_NOT_FOUND') . '</p>'; } else { // Get the component parameters $this->config = Component::params('com_wishlist'); // Get list owners $owners = $objOwner->get_owners($id, $this->config->get('group'), $wishlist); // Authorize admins & list owners if (!User::isGuest()) { if (User::authorize($option, 'manage')) { $admin = 1; } if (in_array(User::get('id'), $owners['individuals'])) { $admin = 2; } elseif (in_array(User::get('id'), $owners['advisory'])) { $admin = 3; } } elseif (!$wishlist->public && $rtrn != 'metadata') { // not authorized throw new Exception(Lang::txt('COM_WISHLIST_ERROR_ALERTNOTAUTH'), 403); return; } $items = $objWish->get_count($id, $filters, $admin); if ($rtrn != 'metadata') { // Get wishes $wishlist->items = $objWish->get_wishes($wishlist->id, $filters, $admin, User::getRoot()); $title = $admin ? Lang::txt('COM_WISHLIST_TITLE_PRIORITIZED') : Lang::txt('COM_WISHLIST_TITLE_RECENT_WISHES'); if (count($wishlist->items) > 0 && $items > $filters['limit']) { $title .= ' (<a href="' . Route::url('index.php?option=' . $option . '&task=wishlist&category=' . $wishlist->category . '&rid=' . $wishlist->referenceid) . '">' . Lang::txt('view all') . ' ' . $items . '</a>)'; } else { $title .= ' (' . $items . ')'; } // HTML output // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'wishlist', 'name' => 'browse')); // Pass the view some info $view->option = $option; $view->publication = $publication; $view->title = $title; $view->wishlist = $wishlist; $view->filters = $filters; $view->admin = $admin; $view->config = $this->config; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $html = $view->loadTemplate(); } } // Build the HTML meant for the "about" tab's metadata overview $metadata = ''; if ($rtrn == 'all' || $rtrn == 'metadata') { $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'wishlist', 'name' => 'metadata')); $view->publication = $publication; $view->items = $items; $view->wishlistid = $id; $metadata = $view->loadTemplate(); } $arr = array('html' => $html, 'metadata' => $metadata); if ($publication->state == 1) { $arr['count'] = $items; $arr['name'] = 'wishlist'; } return $arr; }
/** * Change member role * * @return void, redirect */ protected function _changeRole() { // Incoming $checked = Request::getVar('owner', array()); $groups = Request::getVar('group', array()); $owner = Request::getVar('owner', ''); $role = Request::getInt('role', 0); if ($owner) { $checked = array($owner); } // Are we setting up project? $s = $this->model->inSetup() ? 1 : 0; // Instantiate project owner $objO = $this->model->table('Owner'); if (!empty($checked)) { // Get owners info from owner id(s) $selected = $objO->getInfo($this->model->get('id'), $checked, $groups); } else { $selected = array(); $this->setError(Lang::txt('PLG_PROJECTS_TEAM_ERROR_NOONE_TO_REASSIGN_ROLE')); } if ($this->_task == 'changerole') { // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'team', 'name' => 'role')); $view->selected = $selected; $view->checked = $checked; $view->option = $this->_option; $view->model = $this->model; $view->uid = $this->_uid; $view->aid = $objO->getOwnerID($this->model->get('id'), $this->_uid); $view->msg = isset($this->_msg) ? $this->_msg : ''; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); } else { // Changing role(s) to collaborator $left = $checked; if ($role == 0) { // Get all managers $all = $objO->getIds($this->model->get('id'), 1); $remaining = array_diff($all, $checked); if (!$remaining && count($all) > 0) { $left = array_diff($checked, array($all[0])); // leave one manager $this->setError(Lang::txt('PLG_PROJECTS_TEAM_OWNERS_REASSIGN_NOMANAGERS')); } } if ($objO->reassignRole($this->model->get('id'), $left, 1, $role)) { $this->_msg = Lang::txt('PLG_PROJECTS_TEAM_OWNERS_ROLE_CHANGED'); // Sync with system group $objO->sysGroup($this->model->get('alias'), $this->_config->get('group_prefix', 'pr-')); } $this->_task = $s ? 'setup' : 'edit'; return $this->display($edit = 1); } }
/** * 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) { $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)))) { $rtrn = 'metadata'; } } if (!$publication->_category->_params->get('plg_usage') || !$extended) { return $arr; } // Temporarily display only metadata $rtrn = 'metadata'; // Check if we have a needed database table $database = App::get('db'); $tables = $database->getTableList(); $table = $database->getPrefix() . 'publication_stats'; if ($publication->alias) { $url = Route::url('index.php?option=' . $option . '&alias=' . $publication->alias . '&active=usage'); } else { $url = Route::url('index.php?option=' . $option . '&id=' . $publication->id . '&active=usage'); } if (!in_array($table, $tables)) { $arr['html'] = '<p class="error">' . Lang::txt('PLG_PUBLICATION_USAGE_MISSING_TABLE') . '</p>'; $arr['metadata'] = '<p class="usage"><a href="' . $url . '">' . Lang::txt('PLG_PUBLICATION_USAGE_DETAILED') . '</a></p>'; return $arr; } // Get/set some variables $dthis = Request::getVar('dthis', date('Y') . '-' . date('m')); $period = Request::getInt('period', $this->params->get('period', 14)); include_once PATH_CORE . DS . 'components' . DS . $option . DS . 'tables' . DS . 'stats.php'; require_once PATH_CORE . DS . 'components' . DS . $option . DS . 'helpers' . DS . 'usage.php'; $stats = new \Components\Publications\Tables\Stats($database); $stats->loadStats($publication->id, $period, $dthis); // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { \Hubzero\Document\Assets::addComponentStylesheet('com_usage'); // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'usage', 'name' => 'browse')); // Get usage helper $view->helper = new \Components\Publications\Helpers\Usage($database, $publication->id, $publication->base); // Pass the view some info $view->option = $option; $view->publication = $publication; $view->stats = $stats; $view->chart_path = $this->params->get('chart_path', ''); $view->map_path = $this->params->get('map_path', ''); $view->dthis = $dthis; $view->period = $period; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } if ($rtrn == 'metadata') { $stats->loadStats($publication->id, $period); if ($stats->users) { $action = $publication->base == 'files' ? '%s download(s)' : '%s view(s)'; $arr['metadata'] = '<p class="usage">' . Lang::txt('%s user(s)', $stats->users); $arr['metadata'] .= $stats->downloads ? ' | ' . Lang::txt($action, $stats->downloads) : ''; $arr['metadata'] .= '</p>'; } } if ($stats->users) { $arr['name'] = 'usage'; $arr['count'] = $stats->users; } return $arr; }
/** * Compiles PDF/image preview for any kind of file * * @return string */ public function compile() { $view = new \Hubzero\Plugin\View(['folder' => 'projects', 'element' => 'files', 'name' => 'connected', 'layout' => 'compiled']); // Combine file and folder data $items = $this->getCollection(); $output = Event::trigger('handlers.onHandleView', [$items]); // Check return type and for multiple responses if ($output && count($output) > 0) { foreach ($output as $o) { if ($o instanceof \Hubzero\Plugin\View) { $handler = $o; } } } else { $view->setError(Lang::txt('No handlers are currently available to view file(s).')); } if (!isset($handler)) { $view->setError(Lang::txt('Failed to compile a view for this combination of file(s).')); } else { $view->handler = $handler; } $view->items = $items; $view->subdir = $this->subdir; $view->option = $this->_option; $view->connection = $this->connection; return $view->loadTemplate(); }
/** * 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' => '', 'name' => 'recommendations'); // Check if our area is in the array of areas we want to return results for $areas = array('recommendations'); if (!array_intersect($areas, $this->onPublicationSubAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationSubAreas($publication)))) { return false; } // Get some needed libraries include_once PATH_CORE . DS . 'plugins' . DS . 'publications' . DS . 'recommendations' . DS . 'publication.recommendation.php'; // Set some filters for returning results $filters = array('id' => $publication->get('id'), 'threshold' => $this->params->get('threshold', '0.21'), 'limit' => $this->params->get('display_limit', 10)); // Get recommendations $database = App::get('db'); $r = new PublicationRecommendation($database); $results = $r->getResults($filters); $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Instantiate a view if ($miniview) { $view->setLayout('mini'); } // Pass the view some info $view->option = $option; $view->publication = $publication; $view->results = $results; if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); return $arr; }
/** * Draw attachment * * @return HTML string */ public function drawAttachment($data, $params, $handler = NULL) { // Check if we have an alternative view of attachments for the handler $html = is_object($handler) ? $handler->drawAttachment($data, $params) : NULL; if ($html) { return $html; } // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'attachments', 'layout' => $this->_name)); $view->data = $data; $view->params = $params; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * 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($model, $option, $areas, $rtrn = 'all', $version = 'default', $extended = true) { $arr = array('area' => $this->_name, '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($model)) && !array_intersect($areas, array_keys($this->onPublicationAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->category()->_params->get('plg_reviews') || !$extended) { return $arr; } include_once __DIR__ . DS . 'models' . DS . 'review.php'; // Instantiate a helper object and perform any needed actions $h = new PlgPublicationsReviewsHelper(); $h->publication = $model; $h->option = $option; $h->_option = $option; $h->execute(); // Get reviews for this publication $database = App::get('db'); $r = new \Components\Publications\Tables\Review($database); $reviews = $r->getRatings($model->get('id')); if (!$reviews) { $reviews = array(); } $arr['count'] = count($reviews); $arr['name'] = 'reviews'; // Are we returning any HTML? if ($rtrn == 'all' || $rtrn == 'html') { // Did they perform an action? // If so, they need to be logged in first. if (!$h->loggedin) { $rtrn = Request::getVar('REQUEST_URI', Route::url($model->link($this->_name)), 'server'); App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($rtrn)), Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE'), 'warning'); return; } else { // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'browse')); } // Pass the view some info $view->option = $option; $view->publication = $model; $view->reviews = $reviews; $view->voting = $this->params->get('voting', 1); $view->h = $h; $view->banking = $this->banking; $view->infolink = $this->infolink; $view->config = $this->params; if ($h->getError()) { $view->setError($h->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } // Build the HTML meant for the "about" tab's metadata overview if ($rtrn == 'all' || $rtrn == 'metadata') { $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'metadata')); $view->url = Route::url($model->link($this->_name)); $view->url2 = Route::url($model->link($this->_name) . '&action=addreview#reviewform'); $view->reviews = $reviews; $arr['metadata'] = $view->loadTemplate(); } return $arr; }
/** * Show publication versions * * @return string (html) */ public function versions() { // Incoming $pid = $this->_pid ? $this->_pid : Request::getInt('pid', 0); // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'versions')); // Load publication model $view->pub = new \Components\Publications\Models\Publication($pid, 'default'); if (!$view->pub->exists() || !$view->pub->belongsToProject($this->model->get('id'))) { throw new Exception(Lang::txt('PLG_PROJECTS_PUBLICATIONS_PUBLICATION_VERSION_NOT_FOUND'), 404); return; } // Append breadcrumbs Pathway::append(stripslashes($view->pub->title), $view->pub->link('edit')); // Get versions $view->versions = $view->pub->version->getVersions($pid, $filters = array('withdev' => 1)); // Output HTML $view->option = $this->_option; $view->database = $this->_database; $view->project = $this->model; $view->uid = $this->_uid; $view->pid = $pid; $view->task = $this->_task; $view->config = $this->model->config(); $view->pubconfig = $this->_pubconfig; $view->title = $this->_area['title']; // Get messages and errors $view->msg = $this->_msg; if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Serve wiki page (usually 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->pageid) || !$projectid) { return false; } $this->loadLanguage(); $database = App::get('db'); $this->_option = 'com_projects'; // Instantiate a project $this->model = new \Components\Projects\Models\Project($projectid); if (!$this->model->exists()) { return false; } $groupname = $this->model->config()->get('group_prefix', 'pr-') . $this->model->get('alias'); $scope = 'projects' . DS . $this->model->get('alias') . DS . 'notes'; // Include note model include_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'models' . DS . 'note.php'; // Get our model $this->note = new \Components\Projects\Models\Note($scope, $groupname, $projectid); // Fix pathway (com_wiki screws it up) $this->fixupPathway(); // Load requested page $page = $this->note->page($data->pageid); if (!$page->get('id')) { return false; } // Write title & build pathway Document::setTitle(Lang::txt(strtoupper($this->_option)) . ': ' . stripslashes($this->model->get('title')) . ' - ' . stripslashes($page->get('title'))); // Instantiate a new view $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'notes', 'name' => 'pubview')); $view->option = $this->_option; $view->model = $this->model; $view->page = $page; $view->revision = $page->revision('current'); $view->masterscope = 'projects' . DS . $this->model->get('alias') . DS . 'notes'; // Output HTML if ($this->getError()) { $view->setError($this->getError()); } $view->display(); return true; }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @return array */ public function onResources($model, $option, $areas, $rtrn = 'all') { $arr = array('area' => $this->_name, '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->onResourcesAreas($model)) && !array_intersect($areas, array_keys($this->onResourcesAreas($model)))) { $rtrn = 'metadata'; } } if (!$model->type->params->get('plg_citations')) { return $arr; } $database = App::get('db'); // Get a needed library include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'citation.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'association.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'author.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_citations' . DS . 'tables' . DS . 'secondary.php'; // Get reviews for this resource $c = new \Components\Citations\Tables\Citation($database); $citations = $c->getCitations('resource', $model->resource->id); // Are we returning HTML? if ($rtrn == 'all' || $rtrn == 'html') { // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'browse')); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->citations = $citations; $view->citationFormat = $this->params->get('format', 'APA'); if ($this->getError()) { $view->setError($this->getError()); } // Return the output $arr['html'] = $view->loadTemplate(); } // Are we returning metadata? if ($rtrn == 'all' || $rtrn == 'metadata') { $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'metadata')); $view->url = Route::url('index.php?option=' . $option . '&' . ($model->resource->alias ? 'alias=' . $model->resource->alias : 'id=' . $model->resource->id) . '&active=citations'); $view->citations = $citations; $arr['metadata'] = $view->loadTemplate(); } // Return results return $arr; }
/** * Build panel content * * @return string HTML */ public function buildContent($pub = NULL, $viewname = 'edit') { $name = $viewname == 'freeze' || $viewname == 'curator' ? 'freeze' : 'draft'; // Get selector styles \Hubzero\Document\Assets::addPluginStylesheet('projects', 'team', 'selector'); // Output HTML $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => $name, 'layout' => 'authors')); // Get authors if (!isset($pub->_authors)) { $pAuthors = new \Components\Publications\Tables\Author($this->_parent->_db); $pub->_authors = $pAuthors->getAuthors($pub->version_id); $pub->_submitter = $pAuthors->getSubmitter($pub->version_id, $pub->created_by); } // Get creator groups $view->groups = \Hubzero\User\Helper::getGroups($pub->_project->get('owned_by_user'), 'members', 1); $view->pub = $pub; $view->manifest = $this->_manifest; $view->step = $this->_blockId; // Get team members $objO = new \Components\Projects\Tables\Owner($this->_parent->_db); $view->teamids = $objO->getIds($pub->_project->get('id'), 'all', 0, 0); if ($this->getError()) { $view->setError($this->getError()); } return $view->loadTemplate(); }
/** * Set local password * * @return void - redirect to members account page */ private function setlocalpass() { // Logged in? if ($this->user->get('guest')) { App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->option . '&task=myaccount&active=account&action=setlocalpass'))), Lang::txt('You must be a logged in to access this area.'), 'warning'); return; } // Get the token from the user state variable $token = User::getState($this->option . 'token'); // First check to make sure they're not trying to jump to this page without first verifying their token if (is_null($token)) { // Tsk tsk, no sneaky business App::redirect(Route::url('index.php?option=' . $this->option . '&id=' . $this->user->get('id') . '&active=account&task=sendtoken'), Lang::txt('You must first verify your email address by inputting the token.'), 'error'); return; } // Get the password input $password1 = Request::getVar('password1', null, 'post', 'string', JREQUEST_ALLOWRAW); $password2 = Request::getVar('password2', null, 'post', 'string', JREQUEST_ALLOWRAW); $change = Request::getVar('change', '', 'post'); // Create the view $view = new \Hubzero\Plugin\View(array('folder' => 'members', 'element' => 'account', 'name' => 'setlocalpassword', 'layout' => 'setlocalpass')); // Add a few more variables to the view $view->option = $this->option; $view->id = $this->user->get('id'); // Get the password rules $password_rules = \Hubzero\Password\Rule::getRules(); // Get the password rule descriptions $view->password_rules = array(); foreach ($password_rules as $rule) { if (!empty($rule['description'])) { $view->password_rules[] = $rule['description']; } } // Blank form request (no data submitted) if (empty($change)) { $view->notifications = $this->getPluginMessage() ? $this->getPluginMessage() : array(); return $view->loadTemplate(); } // Check for request forgeries Request::checkToken(); // Load some needed libraries jimport('joomla.user.helper'); // Initiate profile classs $profile = new \Hubzero\User\Profile(); $profile->load($this->user->get('id')); // Fire the onBeforeStoreUser trigger Event::trigger('user.onBeforeStoreUser', array($this->user->getProperties(), false)); // Validate the password against password rules if (!empty($password1)) { $msg = \Hubzero\Password\Rule::validate($password1, $password_rules, $profile->get('username')); } else { $msg = array(); } // Verify password $passrules = false; if (!$password1 || !$password2) { $this->setError(Lang::txt('MEMBERS_PASS_MUST_BE_ENTERED_TWICE')); } elseif ($password1 != $password2) { $this->setError(Lang::txt('MEMBERS_PASS_NEW_CONFIRMATION_MISMATCH')); } elseif (!empty($msg)) { $this->setError(Lang::txt('Password does not meet site password requirements. Please choose a password meeting all the requirements listed.')); $passrules = true; } // Were there any errors? if ($this->getError()) { $change = array(); $change['_missing']['password'] = $this->getError(); if (!empty($msg) && $passrules) { //$change = $msg; } if (Request::getInt('no_html', 0)) { echo json_encode($change); exit; } else { $view->setError($this->getError()); return $view->loadTemplate(); } } // No errors, so let's move on - encrypt the password and update the profile $result = \Hubzero\User\Password::changePassword($profile->get('uidNumber'), $password1); // Save the changes if (!$result) { $view->setError(Lang::txt('MEMBERS_PASS_CHANGE_FAILED')); return $view->loadTemplate(); } // Fire the onAfterStoreUser trigger Event::trigger('user.onAfterStoreUser', array($this->user->getProperties(), false, null, $this->getError())); // Flush the variables from the session User::setState($this->option . 'token', null); // Redirect if (Request::getInt('no_html', 0)) { echo json_encode(array("success" => true, "redirect" => Route::url($this->member->getLink() . '&active=account'))); exit; } else { // Redirect user to confirm view page App::redirect(Route::url($this->member->getLink() . '&active=account'), Lang::txt('Password reset successful'), 'passed'); } return; }
/** * 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; }
/** * Return data on a resource view (this will be some form of HTML) * * @param object $resource Current resource * @param string $option Name of the component * @param array $areas Active area(s) * @param string $rtrn Data to be returned * @return array */ public function onResources($model, $option, $areas, $rtrn = 'all') { if (!$model->type->params->get('plg_share')) { return; } $arr = array('area' => $this->_name, 'html' => '', 'metadata' => ''); $sef = Route::url('index.php?option=' . $option . '&id=' . $model->resource->id); $url = Request::base() . ltrim($sef, '/'); // Incoming action $sharewith = Request::getVar('sharewith', ''); if ($sharewith && $sharewith != 'email') { $this->share($sharewith, $url, $model->resource); return; } // Email form if ($sharewith == 'email') { // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'options', 'layout' => 'email')); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->_params = $this->params; $view->url = $url; foreach ($this->getErrors() as $error) { $view->setError($error); } // Return the output $view->display(); exit; } // Build the HTML meant for the "about" tab's metadata overview if ($rtrn == 'all' || $rtrn == 'metadata') { // Instantiate a view $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'options')); // Pass the view some info $view->option = $option; $view->resource = $model->resource; $view->_params = $this->params; $view->url = $url; foreach ($this->getErrors() as $error) { $view->setError($error); } // Return the output $arr['metadata'] = $view->loadTemplate(); } return $arr; }