Example #1
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $et = $this->args;
     switch (trim($et)) {
         case 'title':
             $page = \Components\Wiki\Models\Page::oneByPath($this->pagename, $this->domain, $this->domain_id);
             return stripslashes($row->title);
             break;
         case 'alias':
         default:
             return $this->pagename;
             break;
     }
 }
Example #2
0
 /**
  * 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 . 'models' . DS . 'page.php';
         $page = \Components\Wiki\Models\Page::oneByPath(Request::getVar('pagename'), 'course', $course->get('id'));
         //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'));
     }
     exit;
 }
Example #3
0
 /**
  * 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, '/');
             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
         if (strstr($page, ' ')) {
             $g = \Components\Wiki\Models\Page::oneByTitle($page, $this->domain, $this->domain_id);
         } else {
             $g = \Components\Wiki\Models\Page::oneByPath(($scope ? $scope . '/' : '') . $page, $this->domain, $this->domain_id);
         }
         if (!$g->get('id')) {
             $g->set('pagename', $page);
             $g->set('scope', $this->domain);
             $g->set('scope_id', $this->domain_id);
         }
         // Build and return the link
         if (!$g->get('id')) {
             $l[] = '<a href="' . Route::url($g->link()) . '">' . stripslashes($g->title) . '</a>';
         } else {
             $l[] = '<a class="int-link" href="' . Route::url($g->link()) . '">' . stripslashes($g->title) . '</a>';
         }
     }
     if (count($l) > 1) {
         $last = array_pop($l);
         $html .= implode(', ', $l);
         $html .= ' and ' . $last;
     } else {
         $html .= $l[0];
     }
     return $html . '</div>';
 }
Example #4
0
 /**
  * Retrieve a wiki page by alias
  *
  * @param   string  $alias
  * @param   string  $scope
  * @return  mixed
  */
 private function _getPageByAlias($alias, $scope)
 {
     $page = \Components\Wiki\Models\Page::oneByPath($scope ? $scope . '/' . $alias : '', $this->doman, $this->domain_id);
     // Check for a result
     if ($page->get('id')) {
         return $page;
     }
     return null;
 }
Example #5
0
// No direct access.
defined('_HZEXEC_') or die;
if (!$this->sub) {
    $this->css();
}
$this->js('wiki.js', 'com_wiki')->js('jquery.fileuploader.js', 'system');
$tags = $this->page->tags('string');
if ($this->page->exists()) {
    $lid = $this->page->get('id');
} else {
    $lid = Request::getInt('lid', time() . rand(0, 10000), 'post');
    $lid = '-' . substr($lid, -8);
}
$macros = \Components\Wiki\Models\Page::oneByPath('Help:WikiMacros', 'site', 0);
$macros->set('scope', $this->book->get('scope'))->set('scope_id', $this->book->get('scope_id'));
$formatting = \Components\Wiki\Models\Page::oneByPath('Help:WikiFormatting', 'site', 0);
$formatting->set('scope', $this->book->get('scope'))->set('scope_id', $this->book->get('scope_id'));
$authors = array();
foreach ($this->page->authors()->rows() as $auth) {
    $authors[] = $auth->user()->get('username');
}
$authors = implode(', ', $authors);
?>
<header id="<?php 
echo $this->sub ? 'sub-content-header' : 'content-header';
?>
">
	<h2><?php 
echo $this->escape($this->page->title);
?>
</h2>
Example #6
0
 /**
  * Download a wiki file
  *
  * @return  void
  */
 public function downloadTask()
 {
     $pagename = urldecode(Request::getVar('pagename', '', 'default', 'none', 2));
     $pagename = explode('/', $pagename);
     $filename = array_pop($pagename);
     $pagename = implode('/', $pagename);
     // Get the parent page the file is attached to
     $this->page = Page::oneByPath($pagename, $this->page->get('scope'), $this->page->get('scope_id'));
     // Load the page
     if ($this->page->exists()) {
         // Check if the page is group restricted and the user is not authorized
         if ($this->page->get('scope') != 'site' && $this->page->get('access') != 0 && !$this->page->access('view')) {
             App::abort(403, Lang::txt('COM_WIKI_WARNING_NOT_AUTH'));
         }
     } else {
         if ($this->page->getNamespace() == 'tmp') {
             $this->page->set('id', $this->page->stripNamespace());
         } else {
             App::abort(404, Lang::txt('COM_WIKI_PAGE_NOT_FOUND'));
         }
     }
     $filename = $this->page->stripNamespace($filename);
     // Instantiate an attachment object
     $attachment = $this->page->attachments()->whereEquals('filename', $filename)->row();
     // Ensure we have a path
     if (!$attachment->get('filename')) {
         App::abort(404, Lang::txt('COM_WIKI_FILE_NOT_FOUND'));
     }
     // Add root
     $filename = $attachment->filespace() . DS . $this->page->get('id') . DS . ltrim($attachment->get('filename'), DS);
     // Ensure the file exist
     if (!file_exists($filename)) {
         App::abort(404, Lang::txt('COM_WIKI_FILE_NOT_FOUND') . ' ' . $attachment->get('filename'));
     }
     // Initiate a new content server and serve up the file
     $xserver = new Server();
     $xserver->filename($filename);
     $xserver->disposition('inline');
     $xserver->acceptranges(false);
     // @TODO fix byte range support
     if (!$xserver->serve()) {
         // Should only get here on error
         App::abort(500, Lang::txt('COM_WIKI_SERVER_ERROR'));
     }
     exit;
 }
Example #7
0
 /**
  * Retrieve an included page
  * This is recursive and should look for inclusions in any included page.
  *
  * @param   array  $matches  Pattern matches from includes() method
  * @return  string
  */
 private function _getInclude($matches)
 {
     if (isset($matches[1]) && $matches[1] != '') {
         if (strtolower($matches[1]) != 'include') {
             return $matches[0];
         }
         if (!$this->get('fullparse')) {
             return "'''Includes not allowed.'''";
         }
         /*$scope = ($this->get('scope')) ? $this->get('scope') . DS . 'wiki' : $this->get('path');
         		if (strstr($matches[3], '/'))
         		{
         			$bits = explode('/', $matches[3]);
         			$pagename = array_pop($bits);
         			$s = trim(implode('/', $bits));
         			$scope .= DS . trim($s, DS);
         		}
         		else
         		{*/
         $pagename = $matches[3];
         //}
         // Don't include this page (infinite loop!)
         if ($pagename == $this->get('pagename')) {
             return '';
         }
         // Load the page
         $p = \Components\Wiki\Models\Page::oneByPath($pagename, $this->get('domain'), $this->get('domain_id'));
         if ($p->get('id')) {
             // Parse any nested includes
             return $this->includes($p->version->get('pagetext'));
         }
     }
     return '';
 }
Example #8
0
 /**
  * Set and get a specific page
  *
  * @param   mixed   $id     Integer or string of tag to look up
  * @param   string  $scope
  * @return  object
  */
 public function page($id = null, $scope = '')
 {
     $scope = $scope ? $scope : $this->_scope;
     $this->_cache['page'] = \Components\Wiki\Models\Page::oneByPath($id, 'project', $this->_project_id);
     return $this->_cache['page'];
 }
Example #9
0
 /**
  * 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 . 'models' . DS . 'page.php';
         $page = new \Components\Wiki\Models\Page();
         $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);
             }
             $scope = str_replace($group->get('cn') . '/wiki', '', $scope);
             $scope = $scope ? trim($scope, '/') . '/' : $scope;
         }
         $page = \Components\Wiki\Models\Page::oneByPath($scope . $pagename, 'group', $group->get('gidNumber'));
         //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'));
     }
     exit;
 }
Example #10
0
 /**
  * Save the new page name
  *
  * @return  void
  */
 public function saverenameTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Check if they are logged in
     if (User::isGuest()) {
         $url = Request::getVar('REQUEST_URI', '', 'server');
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode($url), false));
     }
     // Incoming
     $oldpagename = trim(Request::getVar('oldpagename', '', 'post'));
     $newpagename = trim(Request::getVar('newpagename', '', 'post'));
     // Load the page
     $this->page = Page::oneByPath($oldpagename, $this->book->get('scope'), $this->book->get('scope_id'));
     $newpagename = $this->page->normalize($newpagename);
     // Are they just changing case of characters?
     if (strtolower($this->page->get('pagename')) == strtolower($newpagename)) {
         $this->setError(Lang::txt('New name matches old name.'));
         return $this->renameTask();
     }
     // Check that no other pages are using the new title
     $p = Page::oneByPath($newpagename, $this->page->get('scope'), $this->page->get('scope_id'));
     if ($p->exists()) {
         $this->setError(Lang::txt('COM_WIKI_ERROR_PAGE_EXIST') . ' ' . Lang::txt('CHOOSE_ANOTHER_PAGENAME'));
         return $this->renameTask();
     }
     $this->page->set('pagename', $newpagename);
     if (!$this->page->save()) {
         $this->setError($this->page->getError());
         return $this->renameTask();
     }
     $pages = Page::all()->whereEquals('parent', $this->page->get('id'))->rows();
     foreach ($pages as $page) {
         $page->save();
     }
     $this->page->log('page_renamed');
     // Log activity
     $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')]);
     if ($this->page->get('scope') != 'site') {
         $recipients[] = [$this->page->get('scope'), $this->page->get('scope_id')];
         $recipients[0] = ['wiki.' . $this->page->get('scope'), $this->page->get('scope_id')];
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'updated', 'scope' => 'wiki.page', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_PAGE_RENAMED', '<a href="' . Route::url($this->page->link()) . '">' . $this->page->get('title') . '</a>'), 'details' => array('title' => $this->page->get('title'), 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'))], 'recipients' => $recipients]);
     // Redirect to the newly named page
     App::redirect(Route::url($this->page->link()));
 }