/** * Download a file * * @param string $filename File name * @return void */ public function downloadTask($filename) { //get the course $course = Course::getInstance($this->gid); //authorize $authorized = $this->_authorize(); //get the file name if (substr(strtolower($filename), 0, 5) == 'image') { $file = urldecode(substr($filename, 6)); } elseif (substr(strtolower($filename), 0, 4) == 'file') { $file = urldecode(substr($filename, 5)); } //if were on the wiki we need to output files a specific way if ($this->active == 'wiki') { //check to make sure user has access to wiki section if (!in_array(User::get('id'), $course->get('members')) || User::isGuest()) { return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH') . ' ' . $file); } //load wiki page from db require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php'; $page = new \Components\Wiki\Tables\Page($this->database); $page->load(Request::getVar('pagename'), $course->get('cn') . DS . 'wiki'); //check specific wiki page access if ($page->get('access') == 1 && !in_array(User::get('id'), $course->get('members')) && $authorized != 'admin') { return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH') . ' ' . $file); } //get the config and build base path $wiki_config = Component::params('com_wiki'); $base_path = $wiki_config->get('filepath') . DS . $page->get('id'); } else { //check to make sure we can access it if (!in_array(User::get('id'), $course->get('members')) || User::isGuest()) { return App::abort(403, Lang::txt('COM_COURSES_NOT_AUTH') . ' ' . $file); } // Build the path $base_path = $this->config->get('uploadpath'); $base_path .= DS . $course->get('gidNumber'); } // Final path of file $file_path = $base_path . DS . $file; // Ensure the file exist if (!file_exists(PATH_APP . DS . $file_path)) { return App::abort(404, Lang::txt('COM_COURSES_FILE_NOT_FOUND') . ' ' . $file); } // Serve up the file $xserver = new \Hubzero\Content\Server(); $xserver->filename(PATH_APP . DS . $file_path); $xserver->disposition('attachment'); $xserver->acceptranges(false); // @TODO fix byte range support if (!$xserver->serve()) { return App::abort(404, Lang::txt('COM_COURSES_SERVER_ERROR')); } else { exit; } return; }
/** * Generate macro output * * @return string */ public function render() { $et = $this->args; if (!$et) { return ''; } $pages = explode(',', $et); $html = '<div class="rellink relarticle mainarticle">Main articles: '; foreach ($pages as $page) { $page = trim($page); // Is it numeric? $scope = ''; if (is_numeric($page)) { // Yes $page = intval($page); } else { $page = trim($page, DS); if (strstr($page, '/') && !strstr($page, ' ')) { $bits = explode('/', $page); $page = array_pop($bits); $scope = implode('/', $bits); } } if ($this->domain != '' && $scope == '') { $scope = $this->scope; } // No, get resource by alias $g = new \Components\Wiki\Tables\Page($this->_db); if (strstr($page, ' ')) { $g->loadByTitle($page, $scope); } else { $g->load($page, $scope); } if (!$g->id) { $g->pagename = $page; } // Build and return the link if ($g->group_cn != '' && $g->scope != '') { $link = 'index.php?option=com_groups&scope=' . $g->scope . '&pagename=' . $g->pagename; } else { $link = 'index.php?option=com_wiki&scope=' . $g->scope . '&pagename=' . $g->pagename; } if (!$g->id) { $l[] = '<a href="' . Route::url($link) . '">' . stripslashes($g->getTitle()) . '</a>'; } else { $l[] = '<a class="int-link" href="' . Route::url($link) . '">' . stripslashes($g->getTitle()) . '</a>'; } } if (count($l) > 1) { $last = array_pop($l); $html .= implode(', ', $l); $html .= ' and ' . $last; } else { $html .= $l[0]; } return $html . '</div>'; }
/** * Download a file * * @param string $filename File name * @return void */ public function downloadTask($filename = "") { //get the group $group = Group::getInstance($this->cn); // make sure we have a group if (!is_object($group)) { return; } //authorize $authorized = $this->_authorize(); //get the file name if (substr(strtolower($filename), 0, 5) == 'image') { $file = urldecode(substr($filename, 6)); } elseif (substr(strtolower($filename), 0, 4) == 'file') { $file = urldecode(substr($filename, 5)); } else { return; } // clean up file, strip double "uploads" & trim directory sep $file = str_replace('uploads', '', $file); $file = ltrim($file, DS); // get extension $extension = pathinfo($file, PATHINFO_EXTENSION); //if were on the wiki we need to output files a specific way if ($this->active == 'wiki') { //get access level for wiki $access = Group\Helper::getPluginAccess($group, 'wiki'); //check to make sure user has access to wiki section if ($access == 'members' && !in_array(User::get('id'), $group->get('members')) || $access == 'registered' && User::isGuest()) { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); } //load wiki page from db require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php'; $page = new \Components\Wiki\Tables\Page($this->database); $pagename = Request::getVar('pagename'); $scope = Request::getVar('scope', $group->get('cn') . DS . 'wiki'); if ($scope) { $parts = explode('/', $scope); if (count($parts) > 2) { $pagename = array_pop($parts); if (strtolower($filename) == strtolower($pagename)) { $pagename = array_pop($parts); } $scope = implode('/', $parts); } } $page->load($pagename, $scope); //check specific wiki page access if ($page->get('access') == 1 && !in_array(User::get('id'), $group->get('members')) && $authorized != 'admin') { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); return; } //get the config and build base path $wiki_config = \Component::params('com_wiki'); $base_path = $wiki_config->get('filepath') . DS . $page->get('id'); } elseif ($this->active == 'blog') { //get access setting of group blog $access = Group\Helper::getPluginAccess($group, 'blog'); //make sure user has access to blog if ($access == 'members' && !in_array(User::get('id'), $group->get('members')) || $access == 'registered' && User::isGuest()) { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); } //make sure we have a group id of the proper length $groupID = Group\Helper::niceidformat($group->get('gidNumber')); //buld path to blog folder $base_path = $this->config->get('uploadpath') . DS . $groupID . DS . 'blog'; if (!file_exists(PATH_APP . DS . $base_path . DS . $file)) { $base_path = $this->config->get('uploadpath') . DS . $group->get('gidNumber') . DS . 'uploads' . DS . 'blog'; } } else { //get access level for overview or other group pages $access = Group\Helper::getPluginAccess($group, 'overview'); //check to make sure we can access it if ($access == 'members' && !in_array(User::get('id'), $group->get('members')) || $access == 'registered' && User::isGuest()) { $this->_errorHandler(403, Lang::txt('COM_GROUPS_ERROR_NOT_AUTH') . ' ' . $file); } // Build the path $base_path = $this->config->get('uploadpath'); $base_path .= DS . $group->get('gidNumber') . DS . 'uploads'; } // trim base path $base_path = ltrim($base_path, DS); // only can serve files from within /site/groups/{group_id}/uploads/ $pathCheck = PATH_APP . DS . $base_path; // Final path of file $file_path = $base_path . DS . $file; $alt_file_path = null; // if super group offer alt path outside uploads if ($group->isSuperGroup()) { $alt_file_path = str_replace('/uploads', '', $base_path) . DS . $file; // if super group can serve files anywhere inside /site/groups/{group_id} $altPathCheck = PATH_APP . DS . ltrim($alt_file_path); } // Ensure the file exist if (!file_exists(PATH_APP . DS . $file_path)) { if ($alt_file_path == null || !file_exists(PATH_APP . DS . $alt_file_path)) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_FILE_NOT_FOUND') . ' ' . $file); return; } else { $file_path = $alt_file_path; $pathCheck = $altPathCheck; } } // get full path, expanding ../ if ($realPath = realpath(PATH_APP . DS . $file_path)) { // make sure requested file is within acceptable dir if (strpos($realPath, $pathCheck) === false) { $this->_errorHandler(404, Lang::txt('COM_GROUPS_ERROR_FILE_NOT_FOUND') . ' ' . $file); return; } } // new content server $contentServer = new \Hubzero\Content\Server(); $contentServer->filename(PATH_APP . DS . $file_path); $contentServer->disposition('attachment'); $contentServer->acceptranges(false); // do we need to manually set mime type if ($extension == 'css') { $contentServer->setContentType('text/css'); } // Serve up the file if (!$contentServer->serve()) { App::abort(404, Lang::txt('COM_GROUPS_SERVER_ERROR')); } else { exit; } return; }
/** * Generate macro output * * @return string */ public function render() { $et = $this->args; if (!$et) { return ''; } $p = explode(',', $et); $page = array_shift($p); $nolink = false; $p = explode(' ', end($p)); foreach ($p as $a) { $a = trim($a); if ($a == 'nolink') { $nolink = true; } } // Is it numeric? $scope = ''; if (is_numeric($page)) { // Yes $page = intval($page); } else { $page = trim($page, DS); if (strstr($page, '/')) { $bits = explode('/', $page); $page = array_pop($bits); $scope = implode('/', $bits); } } if ($this->domain != '' && $scope == '') { $scope = $this->scope; } // No, get resource by alias $g = new \Components\Wiki\Tables\Page($this->_db); $g->load($page, $scope); if (!$g->id) { return '(Page(' . $et . ') failed)'; } if ($nolink) { return stripslashes($g->title); } else { // Build and return the link if ($g->group_cn != '' && $g->scope != '') { $link = 'index.php?option=com_groups&scope=' . $g->scope . '&pagename=' . $g->pagename; } else { $link = 'index.php?option=com_wiki&scope=' . $g->scope . '&pagename=' . $g->pagename; } return '<a href="' . \Route::url($link) . '">' . stripslashes($g->title) . '</a>'; } }
/** * Remove any associated resources when group is deleted * * @param object $group Group being deleted * @return string Log of items removed */ public function onGroupDelete($group) { // Get all the IDs for pages associated with this group $ids = $this->getPageIDs($group->get('cn')); // Import needed libraries include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php'; // Instantiate a object $database = App::get('db'); // Start the log text $log = Lang::txt('PLG_GROUPS_WIKI_LOG') . ': '; if (count($ids) > 0) { // Loop through all the IDs for pages associated with this group foreach ($ids as $id) { $wp = new \Components\Wiki\Tables\Page($database); $wp->load($id->id); // Delete all items linked to this page //$wp->deleteBits($id->id); // Delete the wiki page last in case somehting goes wrong //$wp->delete($id->id); if ($wp->id) { $wp->state = 2; $wp->store(); } // Add the page ID to the log $log .= $id->id . ' ' . "\n"; } } else { $log .= Lang::txt('PLG_GROUPS_WIKI_NO_RESULTS_FOUND') . "\n"; } // Return the log return $log; }
/** * Retrieve a wiki page by alias * * @param integer $depth How far back to look for ancestors * @param string $scope The URI path to traverse * @return array */ private function _getPageByAlias($alias, $scope) { if (!class_exists('\\Components\\Wiki\\Tables\\Page') && is_file(PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php')) { include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php'; } $page = new \Components\Wiki\Tables\Page($this->_db); $page->load($alias, $scope); // Check for a result if ($page && $page->id) { return $page; } else { return null; } }