Esempio n. 1
0
 /**
  * Serve file (usually via public link)
  *
  * @param   string   $type
  * @param   integer  $projectid
  * @param   string   $query
  * @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->file) || !$projectid) {
         return false;
     }
     $file = $data->file;
     $disp = isset($data->disp) ? $data->disp : 'inline';
     $limited = isset($data->limited) ? $data->limited : 0;
     $hash = isset($data->hash) ? $data->hash : 0;
     $repoName = isset($data->repo) ? $data->repo : 'local';
     // Instantiate a project
     $model = new \Components\Projects\Models\Project($projectid);
     if (!$model->exists() || $limited == 1 && !$model->access('member')) {
         // Throw error
         App::abort(403, Lang::txt('COM_PROJECTS_ERROR_ACTION_NOT_AUTHORIZED'));
     }
     // Load repo
     $repo = new \Components\Projects\Models\Repo($model, $repoName);
     $deleteTemp = false;
     if ($hash) {
         $tempPath = sys_get_temp_dir();
         $tempName = 'temp-' . \Components\Projects\Helpers\Html::generateCode(4, 4, 0, 1, 0) . basename($file);
         $serve = $tempPath . DS . $tempName;
         // Get file content
         $repo->call('content', $params = array('fileName' => $file, 'hash' => $hash, 'target' => $serve));
         $deleteTemp = true;
     } else {
         $serve = $repo->get('path') . DS . $file;
     }
     // Ensure the file exist
     if (!file_exists($serve)) {
         // Throw error
         App::abort(404, Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'));
     }
     // Initiate a new content server and serve up the file
     $server = new \Hubzero\Content\Server();
     $server->filename($serve);
     $server->disposition($disp);
     $server->acceptranges(false);
     // @TODO fix byte range support
     $server->saveas(basename($file));
     $result = $server->serve();
     if ($deleteTemp) {
         // Delete downloaded temp file
         Filesystem::delete($serve);
     }
     if (!$result) {
         // Should only get here on error
         App::abort(404, Lang::txt('PLG_PROJECTS_FILES_SERVER_ERROR'));
     } else {
         exit;
     }
     return;
 }
Esempio n. 2
0
 /**
  * Serve publication-related file (via public link)
  *
  * @param   int  	$projectid
  * @return  void
  */
 public function serve($type = '', $projectid = 0, $query = '')
 {
     $this->_area = $this->onProjectAreas();
     if ($type != $this->_area['name']) {
         return false;
     }
     $data = json_decode($query);
     if (!isset($data->pid) || !$projectid) {
         return false;
     }
     $disp = isset($data->disp) ? $data->disp : 'inline';
     $type = isset($data->type) ? $data->type : 'file';
     $folder = isset($data->folder) ? $data->folder : 'wikicontent';
     $fpath = isset($data->path) ? $data->path : 'inline';
     $limited = isset($data->limited) ? $data->limited : 0;
     if ($type != 'file') {
         return false;
     }
     $database = App::get('db');
     // Instantiate a project
     $model = new \Components\Projects\Models\Project($projectid);
     if (!$model->exists() || $limited == 1 && !$model->access('member')) {
         // Throw error
         throw new Exception(Lang::txt('COM_PROJECTS_ERROR_ACTION_NOT_AUTHORIZED'), 403);
         return;
     }
     // Get referenced path
     $pubconfig = Component::params('com_publications');
     $base_path = $pubconfig->get('webpath');
     $pubPath = \Components\Publications\Helpers\Html::buildPubPath($data->pid, $data->vid, $base_path, $folder, $root = 0);
     $serve = PATH_APP . $pubPath . DS . $fpath;
     // Ensure the file exist
     if (!file_exists($serve)) {
         // Throw error
         throw new Exception(Lang::txt('COM_PROJECTS_FILE_NOT_FOUND'), 404);
         return;
     }
     // Initiate a new content server and serve up the file
     $server = new \Hubzero\Content\Server();
     $server->filename($serve);
     $server->disposition($disp);
     $server->acceptranges(false);
     // @TODO fix byte range support
     $server->saveas(basename($fpath));
     if (!$server->serve()) {
         // Should only get here on error
         throw new Exception(Lang::txt('COM_PUBLICATIONS_SERVER_ERROR'), 404);
     } else {
         exit;
     }
     return;
 }
Esempio n. 3
0
 /**
  * Contribute a publication
  *
  * @return  void
  */
 public function contributeTask()
 {
     // Incoming
     $pid = Request::getInt('pid', 0);
     $action = Request::getVar('action', '');
     $active = Request::getVar('active', 'publications');
     $action = $this->_task == 'start' ? 'start' : $action;
     $ajax = Request::getInt('ajax', 0);
     $doiErr = Request::getInt('doierr', 0);
     // Redirect if publishing is turned off
     if (!$this->_contributable) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     // Load language file
     Lang::load('com_projects') || Lang::load('com_projects', PATH_CORE . DS . 'components' . DS . 'com_projects' . DS . 'site');
     // Instantiate a new view
     $this->view = new \Hubzero\Component\View(array('name' => 'submit', 'layout' => 'default'));
     $this->view->option = $this->_option;
     $this->view->config = $this->config;
     // Set page title
     $this->_task_title = Lang::txt('COM_PUBLICATIONS_SUBMIT');
     $this->_buildTitle();
     // Set the pathway
     $this->_buildPathway();
     // What plugin requested?
     $allowed = array('team', 'files', 'notes', 'databases', 'publications', 'links');
     $plugin = in_array($active, $allowed) ? $active : 'publications';
     if (User::isGuest() && ($action == 'login' || $action == 'start' || $action == 'publication')) {
         $this->_msg = $this->_task == 'start' ? Lang::txt('COM_PUBLICATIONS_LOGIN_TO_START') : Lang::txt('COM_PUBLICATIONS_LOGIN_TO_VIEW_SUBMISSIONS');
         $this->_login();
         return;
     }
     // Get project model
     $project = new \Components\Projects\Models\Project();
     // Get project information
     if ($pid) {
         $project->loadProvisioned($pid);
         if (!$project->exists()) {
             App::redirect(Route::url('index.php?option=' . $this->_option . '&task=submit'));
             return;
         }
         // Block unauthorized access
         if (!$project->access('owner') && !$project->access('content')) {
             $this->_blockAccess();
             return;
         }
         // Redirect to project if not provisioned
         if (!$project->isProvisioned()) {
             App::redirect(Route::url($project->link('publications') . '&pid=' . $pid . '&action=' . $action));
             return;
         }
     }
     // Is project registration restricted?
     if ($action == 'start' && !$project->access('create')) {
         $this->_buildPathway(null);
         $this->view = new \Hubzero\Component\View(array('name' => 'error', 'layout' => 'restricted'));
         $this->view->error = Lang::txt('COM_PUBLICATIONS_ERROR_NOT_FROM_CREATOR_GROUP');
         $this->view->title = $this->title;
         $this->view->option = $this->_option;
         $this->view->display();
         return;
     }
     // No action requested ?
     if (!$action) {
         $action = $pid ? 'publication' : 'contribute';
     }
     // Plugin params
     $plugin_params = array($project, $action, $areas = array($plugin));
     $content = Event::trigger('projects.onProject', $plugin_params);
     $this->view->content = is_array($content) && isset($content[0]['html']) ? $content[0]['html'] : '';
     if (isset($content[0]['msg']) && !empty($content[0]['msg'])) {
         $this->setNotification($content[0]['msg']['message'], $content[0]['msg']['type']);
     }
     if ($ajax) {
         echo $this->view->content;
         return;
     } elseif (!$this->view->content && isset($content[0]['referer']) && $content[0]['referer'] != '') {
         App::redirect($content[0]['referer']);
         return;
     } elseif (empty($content)) {
         // plugin disabled?
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     // @FIXME: Handle errors appropriately. [QUBES][#732]
     if ($doiErr == 1) {
         $this->setError(Lang::txt('COM_PUBLICATIONS_ERROR_DOI_NO_SERVICE'));
     }
     // Output HTML
     $this->view->project = $project;
     $this->view->action = $action;
     $this->view->pid = $pid;
     $this->view->title = $this->_title;
     $this->view->msg = $this->getNotifications('success');
     $error = $this->getError() ? $this->getError() : $this->getNotifications('error');
     if ($error) {
         $this->view->setError($error);
     }
     $this->view->display();
     return;
 }
Esempio n. 4
0
 /**
  * Save item
  *
  * @return  string
  */
 protected function _save()
 {
     if (User::isGuest()) {
         $this->setError(Lang::txt('MEMBERS_LOGIN_NOTICE'));
         return;
     }
     if (User::get('id') != $this->member->get('id')) {
         $this->setError(Lang::txt('PLG_MEMBERS_TODO_NOT_AUTHORIZED'));
         return $this->_browse();
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $content = Request::getVar('content', '');
     $projectid = Request::getInt('projectid', 0);
     $due = trim(Request::getVar('due', ''));
     $model = new \Components\Projects\Models\Project($projectid);
     if (!$content) {
         $this->setError(Lang::txt('PLG_MEMBERS_TODO_ERROR_PROVIDE_CONTENT'));
         return $this->_browse();
     }
     if (!$model->exists() || !$model->access('content')) {
         $this->setError(Lang::txt('PLG_MEMBERS_TODO_ERROR_ACCESS_PROJECT'));
         return $this->_browse();
     }
     // Initiate extended database class
     $objTD = new \Components\Projects\Tables\Todo($this->database);
     $content = rtrim(stripslashes($content));
     $objTD->content = $content ? $content : $objTD->content;
     $objTD->content = \Hubzero\Utility\Sanitize::stripAll($objTD->content);
     $objTD->created_by = $this->member->get('id');
     $objTD->created = Date::toSql();
     $objTD->projectid = $model->get('id');
     if (strlen($objTD->content) > 255) {
         $objTD->details = $objTD->content;
     }
     $objTD->content = \Hubzero\Utility\String::truncate($objTD->content, 255);
     if ($due && $due != 'mm/dd/yyyy') {
         $date = explode('/', $due);
         if (count($date) == 3) {
             $month = $date[0];
             $day = $date[1];
             $year = $date[2];
             if (intval($month) && intval($day) && intval($year)) {
                 if (strlen($day) == 1) {
                     $day = '0' . $day;
                 }
                 if (strlen($month) == 1) {
                     $month = '0' . $month;
                 }
                 if (checkdate($month, $day, $year)) {
                     $objTD->duedate = Date::of(mktime(0, 0, 0, $month, $day, $year))->toSql();
                 }
             }
         }
     } else {
         $objTD->duedate = '';
     }
     // Get last order
     $lastorder = $objTD->getLastOrder($model->get('id'));
     $objTD->priority = $lastorder ? $lastorder + 1 : 1;
     // Store content
     if (!$objTD->store()) {
         $this->setError($objTD->getError());
         return $this->_browse();
     } else {
         // Record activity
         $aid = $model->recordActivity(Lang::txt('PLG_MEMBERS_TODO_ACTIVITY_TODO_ADDED'), $objTD->id, 'to do', Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&active=todo&action=view&todoid=' . $objTD->id), 'todo', 1);
         // Store activity ID
         if ($aid) {
             $objTD->activityid = $aid;
             $objTD->store();
         }
     }
     App::redirect(Route::url($this->member->link() . '&active=' . $this->_name), Lang::txt('PLG_MEMBERS_TODO_SAVED'));
 }