Esempio n. 1
0
 /**
  * Initial render view
  *
  * @return  string
  */
 public static function render()
 {
     // Load language
     Lang::load('plg_time_weeklybar', __DIR__);
     // Create view
     $view = new \Hubzero\Plugin\View(array('folder' => 'time', 'element' => 'weeklybar', 'name' => 'overview'));
     return $view->loadTemplate();
 }
Esempio n. 2
0
 /**
  * Initial render view
  *
  * @return (string) view contents
  */
 public static function render()
 {
     // Load language
     Lang::load('plg_time_csv', __DIR__);
     $view = new \Hubzero\Plugin\View(array('folder' => 'time', 'element' => 'csv', 'name' => 'overview'));
     $view->hub_id = Request::getInt('hub_id', null);
     $view->start = Request::getCmd('start_date', Date::of(strtotime('today - 1 month'))->format('Y-m-d'));
     $view->end = Request::getCmd('end_date', Date::format('Y-m-d'));
     $records = Record::all()->where('date', '>=', $view->start)->where('date', '<=', Date::of(strtotime($view->end . ' + 1 day'))->format('Y-m-d'))->order('date', 'asc');
     if (isset($view->hub_id) && $view->hub_id > 0) {
         // @FIXME: is there a better way to do this?
         $records->whereIn('task_id', Task::select('id')->whereEquals('hub_id', $view->hub_id)->rows()->fieldsByKey('id'));
     }
     // Pass permissions to view
     $view->permissions = new Permissions('com_time');
     $view->records = $records->including('task.hub', 'user')->rows();
     return $view->loadTemplate();
 }
Esempio n. 3
0
 /**
  * Return data on a publication sub view (this will be some form of HTML)
  *
  * @param      object  $publication 	Current publication
  * @param      string  $option    		Name of the component
  * @param      integer $miniview  		View style
  * @return     array
  */
 public function onPublicationSub($publication, $option, $miniview = 0)
 {
     $arr = array('html' => '', 'metadata' => '');
     // Check if our area is in the array of areas we want to return results for
     $areas = array('related');
     if (!array_intersect($areas, $this->onPublicationSubAreas($publication)) && !array_intersect($areas, array_keys($this->onPublicationSubAreas($publication)))) {
         return false;
     }
     $database = App::get('db');
     // Build the query that checks topic pages
     $sql1 = "SELECT v.id, v.page_id AS pageid, MAX(v.version) AS version, w.title, w.pagename AS alias, v.pagetext AS abstract,\n\t\t\t\t\tNULL AS category, NULL AS published, NULL AS publish_up, w.scope, w.rating, w.times_rated, w.ranking, 'wiki' AS class, 'Topic' AS section\n\t\t\t\tFROM `#__wiki_pages` AS w\n\t\t\t\tJOIN `#__wiki_versions` AS v ON w.id=v.page_id\n\t\t\t\tJOIN `#__wiki_links` AS wl ON wl.page_id=w.id\n\t\t\t\tWHERE v.approved=1 AND wl.scope='publication' AND wl.scope_id=" . $database->quote($publication->id);
     if (!User::isGuest()) {
         if (User::authorise('com_resources', 'manage') || User::authorise('com_groups', 'manage')) {
             $sql1 .= '';
         } else {
             $ugs = \Hubzero\User\Helper::getGroups(User::get('id'), 'members');
             $groups = array();
             $cns = array();
             if ($ugs && count($ugs) > 0) {
                 foreach ($ugs as $ug) {
                     $cns[] = $database->quote($ug->cn);
                     $groups[] = $database->quote($ug->gidNumber);
                 }
             }
             $g = implode(",", $groups);
             $c = implode(",", $cns);
             $sql1 .= "AND (w.access!=1 OR (w.access=1 AND ((w.scope=" . $database->quote('group') . " AND w.scope_id IN ({$g})) OR w.created_by=" . $database->quote(User::get('id')) . "))) ";
         }
     } else {
         $sql1 .= "AND w.access!=1 ";
     }
     $sql1 .= "GROUP BY pageid ORDER BY ranking DESC, title LIMIT 10";
     // Initiate a helper class
     $model = new \Components\Publications\Models\Publication($publication);
     $tags = $model->getTags();
     // Get version authors
     $authors = isset($publication->_authors) ? $publication->_authors : array();
     // Build the query that get publications related by tag
     $sql2 = "SELECT DISTINCT r.publication_id as id, NULL AS pageid, r.id AS version,\n\t\t\t\tr.title, C.alias, r.abstract, C.category, r.state as published,\n\t\t\t\tr.published_up, NULL AS scope, C.rating, C.times_rated, C.ranking,\n\t\t\t\trt.alias AS class, rt.name AS section" . "\n FROM #__publications as C, #__publication_categories AS rt, #__publication_versions AS r " . "\n JOIN #__tags_object AS a ON r.publication_id=a.objectid AND a.tbl='publications'" . "\n JOIN #__publication_authors AS PA ON PA.publication_version_id=r.id " . "\n WHERE C.id=r.publication_id ";
     if ($tags) {
         $tquery = array(0);
         foreach ($tags as $tagg) {
             $tquery[] = $database->quote($tagg->get('id'));
         }
         $sql2 .= " AND ( a.tagid IN (" . implode(',', $tquery) . ")";
         $sql2 .= count($authors) > 0 ? " OR " : "";
     }
     if (count($authors) > 0) {
         $aquery = '';
         foreach ($authors as $author) {
             $aquery .= "'" . $author->user_id . "',";
         }
         $aquery = substr($aquery, 0, strlen($aquery) - 1);
         $sql2 .= $tags ? "" : " AND ( ";
         $sql2 .= " PA.user_id IN (" . $aquery . ")";
     }
     $sql2 .= $tags || count($authors) > 0 ? ")" : "";
     $sql2 .= " AND r.publication_id !=" . $publication->id;
     $sql2 .= " AND C.category = rt.id AND C.category!=8 ";
     $sql2 .= "AND r.access=0 ";
     $sql2 .= "AND r.state=1 ";
     $sql2 .= "GROUP BY r.publication_id ORDER BY r.ranking LIMIT 10";
     // Build the final query
     $query = "SELECT k.* FROM (({$sql1}) UNION ({$sql2})) AS k ORDER BY ranking DESC LIMIT 10";
     // Execute the query
     $database->setQuery($query);
     $related = $database->loadObjectList();
     // Instantiate a view
     if ($miniview) {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'related', 'name' => 'browse', 'layout' => 'mini'));
     } else {
         $view = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'related', 'name' => 'browse'));
     }
     // Pass the view some info
     $view->option = $option;
     $view->publication = $publication;
     $view->related = $related;
     if ($this->getError()) {
         $view->setError($this->getError());
     }
     // Return the output
     $arr['html'] = $view->loadTemplate();
     // Return the an array of content
     return $arr;
 }
Esempio n. 4
0
 /**
  * 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();
 }
Esempio n. 5
0
 /**
  * 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();
 }
Esempio n. 6
0
 /**
  * Event call to get content for public project page
  *
  * @return
  */
 public function onProjectPublicList($model)
 {
     if (!$model->exists() || !$model->access('content') || !$model->isPublic()) {
         return false;
     }
     if (!$model->params->get('notes_public', 0)) {
         return false;
     }
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'notes', 'name' => 'publist'));
     require_once PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'tables' . DS . 'publicstamp.php';
     $database = App::get('db');
     $objSt = new \Components\Projects\Tables\Stamp($database);
     $view->items = $objSt->getPubList($model->get('id'), 'notes');
     $view->page = new \Components\Wiki\Tables\Page($database);
     $view->model = $model;
     return $view->loadTemplate();
 }
Esempio n. 7
0
 /**
  * Initial render view
  *
  * @return (string) view contents
  */
 public static function render()
 {
     // Load language
     Lang::load('plg_time_summary', __DIR__);
     // Create view
     $view = new \Hubzero\Plugin\View(array('folder' => 'time', 'element' => 'summary', 'name' => 'overview'));
     // Get vars from request
     $permissions = new Permissions('com_time');
     $view->hub_id = Request::getInt('hub_id', null);
     $view->task_id = Request::getInt('task_id', null);
     $view->start = Request::getCmd('start_date', Date::of(strtotime('today - 1 month'))->format('Y-m-d'));
     $view->end = Request::getCmd('end_date', Date::format('Y-m-d'));
     $view->hubs = array();
     $records = Record::where('date', '>=', Date::of($view->start . ' 00:00:00', Config::get('offset'))->toSql())->where('date', '<=', Date::of($view->end . ' 23:59:59', Config::get('offset'))->toSql());
     if (isset($view->task_id) && $view->task_id > 0) {
         $records->whereEquals('task_id', $view->task_id);
     } else {
         if (isset($view->hub_id) && $view->hub_id > 0) {
             $hub_id = $view->hub_id;
             $records->whereRelatedHas('task', function ($task) use($hub_id) {
                 $task->whereEquals('hub_id', $hub_id);
             });
         }
     }
     foreach ($records->including('task.hub', 'user') as $record) {
         if (isset($view->hubs[$record->task->hub_id])) {
             $view->hubs[$record->task->hub_id]['total'] += $record->time;
             if (isset($view->hubs[$record->task->hub_id]['tasks'][$record->task_id])) {
                 $view->hubs[$record->task->hub_id]['tasks'][$record->task_id]['total'] += $record->time;
                 $view->hubs[$record->task->hub_id]['tasks'][$record->task_id]['records'][] = $record;
             } else {
                 $view->hubs[$record->task->hub_id]['tasks'][$record->task_id] = ['name' => $record->task->name, 'total' => $record->time, 'records' => array($record)];
             }
         } else {
             if ($permissions->can('view.report', 'hub', $record->task->hub_id)) {
                 $view->hubs[$record->task->hub_id] = ['name' => $record->task->hub->name, 'tasks' => array($record->task_id => ['name' => $record->task->name, 'total' => $record->time, 'records' => [$record]]), 'total' => $record->time];
             }
         }
     }
     // Pass permissions to view
     $view->permissions = $permissions;
     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;
 }
Esempio n. 9
0
 /**
  * Get disk space
  *
  * @param      object  	$model
  *
  * @return     string
  */
 public function pubDiskSpace($model)
 {
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'publications', 'name' => 'diskspace'));
     // Include styling and js
     \Hubzero\Document\Assets::addPluginStylesheet('projects', 'files', 'diskspace');
     \Hubzero\Document\Assets::addPluginScript('projects', 'files', 'diskspace');
     $database = App::get('db');
     // Build query
     $filters = array();
     $filters['limit'] = Request::getInt('limit', 25);
     $filters['start'] = Request::getInt('limitstart', 0);
     $filters['sortby'] = Request::getVar('t_sortby', 'title');
     $filters['sortdir'] = Request::getVar('t_sortdir', 'ASC');
     $filters['project'] = $model->get('id');
     $filters['ignore_access'] = 1;
     $filters['dev'] = 1;
     // get dev versions
     // Instantiate project publication
     $objP = new \Components\Publications\Tables\Publication($database);
     // Get all publications
     $view->rows = $objP->getRecords($filters);
     // Get used space
     $view->dirsize = \Components\Publications\Helpers\Html::getDiskUsage($view->rows);
     $view->params = $model->params;
     $view->quota = $view->params->get('pubQuota') ? $view->params->get('pubQuota') : \Components\Projects\Helpers\Html::convertSize(floatval($model->config()->get('pubQuota', '1')), 'GB', 'b');
     // Get total count
     $view->total = $objP->getCount($filters);
     $view->project = $model;
     $view->option = $this->_option;
     $view->title = isset($this->_area['title']) ? $this->_area['title'] : '';
     return $view->loadTemplate();
 }
Esempio n. 10
0
 /**
  * Displays a form field and image
  *
  * @return string
  */
 private function _getCapthcaHtml()
 {
     if (!isset($GLOBALS['totalCaptchas'])) {
         $GLOBALS['totalCaptchas'] = -1;
     }
     $GLOBALS['totalCaptchas']++;
     $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'display'));
     $view->task = Request::getVar('task', '');
     $view->option = Request::getVar('option', '');
     $view->total = $GLOBALS['totalCaptchas'];
     return $view->loadTemplate();
 }
Esempio n. 11
0
 /**
  * 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();
 }
Esempio n. 12
0
 /**
  * Static method for formatting results
  *
  * @param      object $row Database row
  * @return     string HTML
  */
 public static function out($row)
 {
     include_once Component::path('com_forum') . DS . 'models' . DS . 'post.php';
     $row->scope = $row->rcount;
     $row->scope_id = $row->data3;
     $row->section = $row->data2;
     $row->category = $row->data1;
     $p = explode(':', $row->params);
     $row->thread = $p[0];
     $row->parent = $p[1];
     $row->comment = $row->ftext;
     $view = new \Hubzero\Plugin\View(array('folder' => 'tags', 'element' => 'forum', 'name' => 'result'));
     $view->post = \Components\Forum\Models\Post::blank()->set(array('id' => $row->id, 'title' => $row->title, 'alias' => $row->alias, 'comment' => $row->comment, 'state' => $row->state, 'created' => $row->created, 'created_by' => $row->created_by, 'scope' => $row->rcount, 'scope_id' => $row->data3, 'thread' => $row->thread, 'parent' => $row->parent, 'section' => $row->data2, 'category' => $row->data1));
     return $view->loadTemplate();
 }
Esempio n. 13
0
 /**
  * Display updates
  *
  * @return  string
  */
 protected function _updates()
 {
     // Build the final HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'groups', 'element' => 'projects', 'name' => 'updates'));
     $view->filters = array('limit' => Request::getVar('limit', 25, 'request'));
     // Get shared updates feed from blog plugin
     $results = Event::trigger('projects.onShared', array('feed', $this->model, $this->_projects, User::get('id'), $view->filters));
     $view->content = !empty($results) && isset($results[0]) ? $results[0] : NULL;
     $view->newcount = $this->model->table()->getUpdateCount($this->_projects, User::get('id'));
     $view->projectcount = count($this->_projects);
     $view->uid = User::get('id');
     $view->config = $this->_config;
     $view->group = $this->group;
     $view->setErrors($this->getErrors());
     return $view->loadTemplate();
 }
Esempio n. 14
0
 /**
  * Send emails to authors with the monthly stats
  *
  * @param   object   $job  \Components\Cron\Models\Job
  * @return  boolean
  */
 public function sendAuthorStats(\Components\Cron\Models\Job $job)
 {
     $database = App::get('db');
     $pconfig = Component::params('com_publications');
     // Get some params
     $limit = $pconfig->get('limitStats', 5);
     $image = $pconfig->get('email_image', '');
     Lang::load('com_publications', PATH_CORE) || Lang::load('com_publications', PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'site');
     // Is logging enabled?
     if (is_file(PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'logs.php')) {
         require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'logs.php';
     } else {
         $this->setError('Publication logs not present on this hub, cannot email stats to authors');
         return false;
     }
     // Helpers
     require_once PATH_CORE . DS . 'components' . DS . 'com_members' . DS . 'helpers' . DS . 'imghandler.php';
     require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'helpers' . DS . 'html.php';
     // Get all registered authors who subscribed to email
     $query = "SELECT A.user_id, P.picture ";
     $query .= " FROM #__publication_authors as A ";
     $query .= " JOIN #__xprofiles as P ON A.user_id = P.uidNumber ";
     $query .= " WHERE P.mailPreferenceOption != 0 ";
     // either 1 (set to YES) or -1 (never set)
     $query .= " AND A.user_id > 0 AND A.status=1 ";
     // If we need to restrict to selected authors
     $params = $job->get('params');
     if (is_object($params) && $params->get('userids')) {
         $apu = explode(',', $params->get('userids'));
         $apu = array_map('trim', $apu);
         $query .= " AND A.user_id IN (";
         $tquery = '';
         foreach ($apu as $a) {
             $tquery .= "'" . $a . "',";
         }
         $tquery = substr($tquery, 0, strlen($tquery) - 1);
         $query .= $tquery . ") ";
     }
     $query .= " GROUP BY A.user_id ";
     $database->setQuery($query);
     if (!($authors = $database->loadObjectList())) {
         return true;
     }
     // Set email config
     $from = array('name' => Config::get('fromname') . ' ' . Lang::txt('Publications'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
     $subject = Lang::txt('Monthly Publication Usage Report');
     $i = 0;
     foreach ($authors as $author) {
         // Get the user's account
         $user = User::getInstance($author->user_id);
         if (!$user->get('id')) {
             // Skip if not registered
             continue;
         }
         // Get pub stats for each author
         $pubLog = new \Components\Publications\Tables\Log($database);
         $pubstats = $pubLog->getAuthorStats($author->user_id);
         if (!$pubstats || !count($pubstats)) {
             // Nothing to send
             continue;
         }
         // Plain text
         $eview = new \Hubzero\Plugin\View(array('folder' => 'cron', 'element' => 'publications', 'name' => 'emails', 'layout' => 'stats_plain'));
         $eview->option = 'com_publications';
         $eview->controller = 'publications';
         $eview->user = $user;
         $eview->pubstats = $pubstats;
         $eview->limit = $limit;
         $eview->image = $image;
         $eview->config = $pconfig;
         $eview->totals = $pubLog->getTotals($author->user_id, 'author');
         $plain = $eview->loadTemplate();
         $plain = str_replace("\n", "\r\n", $plain);
         // HTML
         $eview->setLayout('stats_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         // Build message
         $message = new \Hubzero\Mail\Message();
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_publications')->addHeader('X-Component-Object', 'publications');
         $message->addPart($plain, 'text/plain');
         $message->addPart($html, 'text/html');
         // Send mail
         if (!$message->send()) {
             $this->setError(Lang::txt('PLG_CRON_PUBLICATIONS_ERROR_FAILED_TO_MAIL', $user->get('email')));
         }
         $mailed[] = $user->get('email');
     }
     return true;
 }
Esempio n. 15
0
 /**
  * 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();
 }
Esempio n. 16
0
 /**
  * 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;
 }
Esempio n. 17
0
 /**
  * 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();
 }
Esempio n. 18
0
 /**
  * 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;
 }
Esempio n. 19
0
 /**
  * Process Registration
  *
  * @return     string
  */
 private function doRegister()
 {
     //get request vars
     $register = Request::getVar('register', NULL, 'post');
     $arrival = Request::getVar('arrival', NULL, 'post');
     $departure = Request::getVar('departure', NULL, 'post');
     $dietary = Request::getVar('dietary', NULL, 'post');
     $dinner = Request::getVar('dinner', NULL, 'post');
     $disability = Request::getVar('disability', NULL, 'post');
     $race = Request::getVar('race', NULL, 'post');
     $event_id = Request::getInt('event_id', NULL, 'post');
     //load event data
     $event = new \Components\Events\Models\Event($event_id);
     // get event params
     $params = new \Hubzero\Config\Registry($event->get('params'));
     //array to hold any errors
     $errors = array();
     //check for first name
     if (!isset($register['first_name']) || $register['first_name'] == '') {
         $errors[] = Lang::txt('Missing first name.');
     }
     //check for last name
     if (!isset($register['last_name']) || $register['last_name'] == '') {
         $errors[] = Lang::txt('Missing last name.');
     }
     //check for affiliation
     if (isset($register['affiliation']) && $register['affiliation'] == '') {
         $errors[] = Lang::txt('Missing affiliation.');
     }
     //check for email if email is supposed to be on
     if ($params->get('show_email', 1) == 1) {
         if (!isset($register['email']) || $register['email'] == '' || !filter_var($register['email'], FILTER_VALIDATE_EMAIL)) {
             $errors[] = Lang::txt('Missing email address or email is not valid.');
         }
         // check to make sure this is the only time registering
         if (\Components\Events\Tables\Respondent::checkUniqueEmailForEvent($register['email'], $event_id) > 0) {
             $errors[] = Lang::txt('You have previously registered for this event.');
         }
     }
     //if we have any errors we must return
     if (count($errors) > 0) {
         $this->register = $register;
         $this->arrival = $arrival;
         $this->departure = $departure;
         $this->dietary = $dietary;
         $this->dinner = $dinner;
         $this->disability = $disability;
         $this->race = $race;
         $this->setError(implode('<br />', $errors));
         return $this->register();
     }
     //set data for saving
     $eventsRespondent = new \Components\Events\Tables\Respondent(array());
     $eventsRespondent->event_id = $event_id;
     $eventsRespondent->registered = Date::toSql();
     $eventsRespondent->arrival = $arrival['day'] . ' ' . $arrival['time'];
     $eventsRespondent->departure = $departure['day'] . ' ' . $departure['time'];
     $eventsRespondent->position_description = '';
     if (isset($register['position_other']) && $register['position_other'] != '') {
         $eventsRespondent->position_description = $register['position_other'];
     } else {
         if (isset($register['position'])) {
             $eventsRespondent->position_description = $register['position'];
         }
     }
     $eventsRespondent->highest_degree = isset($register['degree']) ? $register['degree'] : '';
     $eventsRespondent->gender = isset($register['sex']) ? $register['sex'] : '';
     $eventsRespondent->disability_needs = isset($disability) && strtolower($disability) == 'yes' ? 1 : null;
     $eventsRespondent->dietary_needs = isset($dietary['needs']) && strtolower($dietary['needs']) == 'yes' ? $dietary['specific'] : null;
     $eventsRespondent->attending_dinner = isset($dinner) && $dinner == 'yes' ? 1 : 0;
     $eventsRespondent->bind($register);
     //did we save properly
     if (!$eventsRespondent->save($eventsRespondent)) {
         $this->setError($eventsRespondent->getError());
         return $this->register();
     }
     $r = $race;
     unset($r['nativetribe']);
     $r = empty($r) ? array() : $r;
     $sql = "INSERT INTO `#__events_respondent_race_rel` (respondent_id, race, tribal_affiliation)\n\t\t        VALUES (" . $this->database->quote($eventsRespondent->id) . ", " . $this->database->quote(implode(',', $r)) . ", " . $this->database->quote($race['nativetribe']) . ")";
     $this->database->setQuery($sql);
     $this->database->query();
     //load event we are registering for
     $eventsEvent = new \Components\Events\Tables\Event($this->database);
     $eventsEvent->load($event_id);
     // send a copy to event admin
     if ($eventsEvent->email != '') {
         //build message to send to event admin
         $email = new \Hubzero\Plugin\View(array('folder' => 'groups', 'element' => 'calendar', 'name' => 'calendar', 'layout' => 'register_email_admin'));
         $email->option = $this->option;
         $email->group = $this->group;
         $email->params = $params;
         $email->event = $eventsEvent;
         $email->sitename = Config::get('sitename');
         $email->register = $register;
         $email->race = $race;
         $email->dietary = $dietary;
         $email->disability = $disability;
         $email->arrival = $arrival;
         $email->departure = $departure;
         $email->dinner = $dinner;
         $message = str_replace("\n", "\r\n", $email->loadTemplate());
         //declare subject
         $subject = Lang::txt("[" . $email->sitename . "] Group \"{$this->group->get('description')}\" Event Registration: " . $eventsEvent->title);
         //make from array
         $from = array('email' => 'group-event-registration@' . $_SERVER['HTTP_HOST'], 'name' => $register['first_name'] . ' ' . $register['last_name']);
         // email from person
         if ($params->get('show_email', 1) == 1) {
             $from['email'] = $register['email'];
         }
         //send email
         $this->_sendEmail($eventsEvent->email, $from, $subject, $message);
     }
     // build message to send to event registerer
     // only send if show email is on
     if ($params->get('show_email', 1) == 1) {
         $email = $this->view('register_email_user', 'calendar');
         $email->option = $this->option;
         $email->group = $this->group;
         $email->params = $params;
         $email->event = $eventsEvent;
         $email->sitename = Config::get('sitename');
         $email->siteurl = Config::get('live_site');
         $email->register = $register;
         $email->race = $race;
         $email->dietary = $dietary;
         $email->disability = $disability;
         $email->arrival = $arrival;
         $email->departure = $departure;
         $email->dinner = $dinner;
         $message = str_replace("\n", "\r\n", $email->loadTemplate());
         // build to, from, & subject
         $to = User::get('email');
         $from = array('email' => 'groups@' . $_SERVER['HTTP_HOST'], 'name' => $email->sitename . ' Group Calendar: ' . $this->group->get('description'));
         $subject = Lang::txt('Thank you for Registering for the "%s" event', $eventsEvent->title);
         // send mail to user registering
         $this->_sendEmail($to, $from, $subject, $message);
     }
     // redirect back to the event
     App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=calendar&action=details&event_id=' . $event_id), Lang::txt('You have successfully registered for the event.'), 'passed');
 }
Esempio n. 20
0
 /**
  * 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;
 }
Esempio n. 21
0
 /**
  * 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();
 }
Esempio n. 22
0
 /**
  * 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());
 }
Esempio n. 23
0
		<input type="hidden" name="move" value="continue" />
	</fieldset>
	<p class="requirement"><?php 
echo Lang::txt('PLG_PROJECTS_TEAM_SELECTOR_SELECT_FROM_TEAM');
?>
</p>
	<div id="content-selector" class="content-selector">
		<?php 
// Show files
$view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'team', 'name' => 'selector', 'layout' => 'selector'));
$view->option = $this->option;
$view->model = $this->model;
$view->selected = $selected;
$view->publication = $this->publication;
$view->team = $this->team;
echo $view->loadTemplate();
?>
	</div>
	</form>
	<p class="newauthor-question"><span><?php 
echo Lang::txt('PLG_PROJECTS_TEAM_SELECTOR_AUTHOR_NOT_PART_OF_TEAM');
?>
 <a href="<?php 
echo $newauthorUrl;
?>
" class="add" id="newauthor-question"><?php 
echo Lang::txt('PLG_PROJECTS_TEAM_SELECTOR_ADD_AUTHOR');
?>
</a></span></p>
</div>
</div>
Esempio n. 24
0
 /**
  * View of item
  *
  * @return	   string
  */
 public function item()
 {
     // Incoming
     $todoid = $this->_todoid ? $this->_todoid : Request::getInt('todoid', 0);
     $layout = $this->_task == 'edit' || $this->_task == 'new' ? 'edit' : 'default';
     // Check permission
     if ($this->_task == 'edit' && !$this->model->access('content')) {
         throw new Exception(Lang::txt('ALERTNOTAUTH'), 403);
         return;
     }
     $view = new \Hubzero\Plugin\View(array('folder' => $this->_type, 'element' => $this->_name, 'name' => 'item', 'layout' => $layout));
     $view->option = $this->option;
     $view->todo = $this->todo;
     $view->params = $this->model->params;
     $view->model = $this->model;
     // Get team members (to assign items to)
     $objO = $this->model->table('Owner');
     $view->team = $objO->getOwners($this->model->get('id'), $tfilters = array('status' => 1));
     if (isset($this->entry) && is_object($this->entry)) {
         $view->row = $this->entry;
     } else {
         $view->row = $this->todo->entry($todoid);
     }
     if (!$view->row->exists() && $this->_task != 'new') {
         return $this->page();
     }
     // Append breadcrumbs
     Pathway::append(stripslashes(\Hubzero\Utility\String::truncate($view->row->get('content'), 40)), Route::url($this->model->link('todo') . '&action=view&todoid=' . $todoid));
     $view->uid = $this->_uid;
     $view->title = $this->_area['title'];
     $view->list = Request::getVar('list', '');
     $view->ajax = Request::getVar('ajax', 0);
     return $view->loadTemplate();
 }
Esempio n. 25
0
 /**
  * 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();
 }
Esempio n. 26
0
 /**
  * Get File Previews
  *
  * @param   string  $ref  Reference to files
  * @return  mixed
  */
 protected function _getFilesPreview($ref = '')
 {
     if (!$ref) {
         return false;
     }
     if (!$this->_path) {
         // Get project file path
         $this->_path = \Components\Projects\Helpers\Html::getProjectRepoPath($this->model->get('alias'));
     }
     // We do need project file path
     if (!$this->_path || !is_dir($this->_path)) {
         return false;
     }
     $files = explode(',', $ref);
     $selected = array();
     $maxHeight = 0;
     $minHeight = 0;
     $minWidth = 0;
     $maxWidth = 0;
     $imagepath = trim($this->_config->get('imagepath', '/site/projects'), DS);
     $to_path = DS . $imagepath . DS . strtolower($this->model->get('alias')) . DS . 'preview';
     foreach ($files as $item) {
         $parts = explode(':', $item);
         $file = count($parts) > 1 ? $parts[1] : $parts[0];
         $hash = count($parts) > 1 ? $parts[0] : NULL;
         if ($hash) {
             // Only preview mid-size images from now on
             $hashed = md5(basename($file) . '-' . $hash) . '.png';
             if (is_file(PATH_APP . $to_path . DS . $hashed)) {
                 $preview['image'] = $hashed;
                 $preview['url'] = NULL;
                 $preview['title'] = basename($file);
                 // Get image properties
                 list($width, $height, $type, $attr) = getimagesize(PATH_APP . $to_path . DS . $hashed);
                 $preview['width'] = $width;
                 $preview['height'] = $height;
                 $preview['orientation'] = $width > $height ? 'horizontal' : 'vertical';
                 // Record min and max width and height to build image grid
                 if ($height >= $maxHeight) {
                     $maxHeight = $height;
                 }
                 if ($height && $height <= $minHeight) {
                     $minHeight = $height;
                 } else {
                     $minHeight = $height;
                 }
                 if ($width > $maxWidth) {
                     $maxWidth = $width;
                 }
                 $selected[] = $preview;
             }
         }
     }
     // No files for preview
     if (empty($selected)) {
         return false;
     }
     // Output HTML
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => $this->_name, 'name' => 'preview', 'layout' => 'files'));
     $view->maxHeight = $maxHeight;
     $view->maxWidth = $maxWidth;
     $view->minHeight = $minHeight > 400 ? 400 : $minHeight;
     $view->selected = $selected;
     $view->option = $this->_option;
     $view->model = $this->model;
     return $view->loadTemplate();
 }
Esempio n. 27
0
 /**
  * Static method for formatting results
  *
  * @param      object $row Database row
  * @return     string HTML
  */
 public static function out($row)
 {
     include_once Component::path('com_forum') . DS . 'models' . DS . 'thread.php';
     $row->scope = $row->rcount;
     $row->scope_id = $row->data3;
     $row->section = $row->data2;
     $row->category = $row->data1;
     $p = explode(':', $row->params);
     $row->thread = $p[0];
     $row->parent = $p[1];
     $row->comment = $row->ftext;
     $view = new \Hubzero\Plugin\View(array('folder' => 'tags', 'element' => 'forum', 'name' => 'result'));
     $view->post = new \Components\Forum\Models\Post($row);
     return $view->loadTemplate();
 }
Esempio n. 28
0
 /**
  * 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;
 }
Esempio n. 29
0
 /**
  * Save a review
  *
  * @return  void
  */
 public function savereview()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_LOGIN_NOTICE'));
         return;
     }
     $publication =& $this->publication;
     // Do we have a publication ID?
     if (!$publication->exists()) {
         // No ID - fail! Can't do anything else without an ID
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID'));
         return;
     }
     $database = App::get('db');
     // Bind the form data to our object
     $row = new \Components\Publications\Tables\Review($database);
     if (!$row->bind($_POST)) {
         $this->setError($row->getError());
         return;
     }
     // Perform some text cleaning, etc.
     $row->id = Request::getInt('reviewid', 0);
     $row->state = 1;
     $row->comment = \Hubzero\Utility\Sanitize::stripAll($row->comment);
     $row->anonymous = $row->anonymous == 1 || $row->anonymous == '1' ? $row->anonymous : 0;
     $row->created = $row->created ? $row->created : Date::toSql();
     $row->created_by = User::get('id');
     $message = $row->id ? Lang::txt('PLG_PUBLICATIONS_REVIEWS_EDITS_SAVED') : Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_POSTED');
     // Check for missing (required) fields
     if (!$row->check()) {
         $this->setError($row->getError());
         return;
     }
     // Save the data
     if (!$row->store()) {
         $this->setError($row->getError());
         return;
     }
     // Calculate the new average rating for the parent publication
     $publication->table()->calculateRating();
     $publication->table()->updateRating();
     // Process tags
     $tags = trim(Request::getVar('review_tags', ''));
     if ($tags) {
         $rt = new \Components\Publications\Helpers\Tags($database);
         $rt->tag_object($row->created_by, $publication->get('id'), $tags, 1, 0);
     }
     // Get version authors
     $users = $publication->table('Author')->getAuthors($publication->get('version_id'), 1, 1, true);
     // Build the subject
     $subject = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS');
     // Message
     $eview = new \Hubzero\Plugin\View(array('folder' => 'publications', 'element' => 'reviews', 'name' => 'emails'));
     $eview->option = $this->_option;
     $eview->juser = User::getInstance();
     $eview->publication = $publication;
     $message = $eview->loadTemplate();
     $message = str_replace("\n", "\r\n", $message);
     // Build the "from" data for the e-mail
     $from = array();
     $from['name'] = Config::get('sitename') . ' ' . Lang::txt('PLG_PUBLICATIONS_REVIEWS_CONTRIBUTIONS');
     $from['email'] = Config::get('mailfrom');
     // Send message
     if (!Event::trigger('xmessage.onSendMessage', array('publications_new_comment', $subject, $message, $from, $users, $this->_option))) {
         $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_FAILED_TO_MESSAGE'));
     }
     App::redirect(Route::url($publication->link('reviews')), $message);
     return;
 }
Esempio n. 30
0
 /**
  * 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();
 }