Example #1
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, 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>';
 }
Example #2
0
 /**
  * Pull a list of records that were created within the time frame ($period)
  *
  * @param      object  $period     Time period to pull results for
  * @param      mixed   $limit      Number of records to pull
  * @param      integer $limitstart Start of records to pull
  * @param      array   $areas      Active area(s)
  * @param      array   $tagids     Array of tag IDs
  * @return     array
  */
 public function onWhatsnew($period, $limit = 0, $limitstart = 0, $areas = null, $tagids = array())
 {
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas)) {
             return array();
         }
     }
     // Do we have a time period?
     if (!is_object($period)) {
         return array();
     }
     $database = App::get('db');
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php';
     // Instantiate some needed objects
     $wp = new \Components\Wiki\Tables\Page($database);
     // Build query
     $filters = array();
     $filters['startdate'] = $period->cStartDate;
     $filters['enddate'] = $period->cEndDate;
     $filters['sortby'] = 'date';
     $filters['authorized'] = false;
     if (!User::isGuest()) {
         $filters['authorized'] = true;
     }
     if (count($tagids) > 0) {
         $filters['tags'] = $tagids;
     }
     if (!$limit) {
         // Get a count
         $filters['select'] = 'count';
         $database->setQuery($wp->buildPluginQuery($filters));
         return $database->loadResult();
     } else {
         // Get results
         $filters['select'] = 'records';
         $filters['limit'] = $limit;
         $filters['limitstart'] = $limitstart;
         $database->setQuery($wp->buildPluginQuery($filters));
         $rows = $database->loadObjectList();
         if ($rows) {
             foreach ($rows as $key => $row) {
                 if ($row->area != '' && $row->category != '') {
                     $rows[$key]->href = Route::url('index.php?option=com_groups&scope=' . $row->category . '&pagename=' . $row->alias);
                 } else {
                     $rows[$key]->href = Route::url('index.php?option=com_wiki&scope=' . $row->category . '&pagename=' . $row->alias);
                 }
                 $rows[$key]->text = strip_tags($rows[$key]->itext);
                 if ($row->title == '') {
                     $rows[$key]->title = $rows[$key]->alias;
                 }
             }
         }
         return $rows;
     }
 }
Example #3
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 . '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;
 }
Example #4
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 . '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;
 }
Example #5
0
 /**
  * Return either a count or an array of the member's contributions
  *
  * @param      object  $member     Current member
  * @param      string  $option     Component name
  * @param      string  $authorized Authorization level
  * @param      integer $limit      Number of record to return
  * @param      integer $limitstart Record return start
  * @param      string  $sort       Field to sort records on
  * @param      array   $areas      Areas to return data for
  * @return     array
  */
 public function onMembersContributions($member, $option, $limit = 0, $limitstart = 0, $sort, $areas = null)
 {
     $database = App::get('db');
     if (is_array($areas) && $limit) {
         if (!isset($areas[$this->_name]) && !in_array($this->_name, $areas) && !array_intersect($areas, array_keys($this->onMembersContributionsAreas()))) {
             return array();
         }
     }
     // Do we have a member ID?
     if ($member instanceof \Hubzero\User\Profile) {
         if (!$member->get('uidNumber')) {
             return array();
         } else {
             $uidNumber = $member->get('uidNumber');
             $username = $member->get('username');
         }
     } else {
         if (!$member->uidNumber) {
             return array();
         } else {
             $uidNumber = $member->uidNumber;
             $username = $member->username;
         }
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php';
     // Instantiate some needed objects
     $wp = new \Components\Wiki\Tables\Page($database);
     // Build query
     $filters = array();
     $filters['author'] = $uidNumber;
     $filters['username'] = $username;
     $filters['sortby'] = $sort;
     //if ($authorized) {
     //	$filters['authorized'] = 'admin';
     //}
     if (!$limit) {
         $filters['select'] = 'count';
         $database->setQuery($wp->buildPluginQuery($filters));
         return $database->loadResult();
     } else {
         $filters['select'] = 'records';
         $filters['limit'] = $limit;
         $filters['limitstart'] = $limitstart;
         $database->setQuery($wp->buildPluginQuery($filters));
         $rows = $database->loadObjectList();
         if ($rows) {
             foreach ($rows as $key => $row) {
                 if ($row->area != '' && $row->category != '') {
                     $rows[$key]->href = Route::url('index.php?option=com_groups&scope=' . $row->category . '&pagename=' . $row->alias);
                 } else {
                     $rows[$key]->href = Route::url('index.php?option=com_wiki&scope=' . $row->category . '&pagename=' . $row->alias);
                 }
                 $rows[$key]->text = $rows[$key]->itext;
             }
         }
         return $rows;
     }
 }
Example #6
0
 /**
  * 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>';
     }
 }
Example #7
0
 /**
  * Erases all project information (to be used for test projects only)
  *
  * @return     void
  */
 public function eraseTask()
 {
     $id = Request::getVar('id', 0);
     $permanent = 1;
     // Initiate extended database class
     $obj = new Tables\Project($this->database);
     if (!$id or !$obj->loadProject($id)) {
         App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_NOTICE_ID_NOT_FOUND'), 'error');
         return;
     }
     // Get project group
     $group_prefix = $this->config->get('group_prefix', 'pr-');
     $prGroup = $group_prefix . $obj->alias;
     // Store project info
     $alias = $obj->alias;
     $identifier = $alias;
     // Delete project
     $obj->delete();
     // Erase all owners
     $objO = new Tables\Owner($this->database);
     $objO->removeOwners($id, '', 0, $permanent, '', $all = 1);
     // Erase owner group
     $group = new \Hubzero\User\Group();
     $group->read($prGroup);
     if ($group) {
         $group->delete();
     }
     // Erase all comments
     $objC = new Tables\Comment($this->database);
     $objC->deleteProjectComments($id, $permanent);
     // Erase all activities
     $objA = new Tables\Activity($this->database);
     $objA->deleteActivities($id, $permanent);
     // Erase all todos
     $objTD = new Tables\Todo($this->database);
     $objTD->deleteTodos($id, '', $permanent);
     // Erase all blog entries
     $objB = new Tables\Blog($this->database);
     $objB->deletePosts($id, $permanent);
     // Erase all notes
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'attachment.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'author.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'comment.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'log.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'page.php';
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'tables' . DS . 'revision.php';
     $masterscope = 'projects' . DS . $alias . DS . 'notes';
     // Get all notes
     $this->database->setQuery("SELECT DISTINCT p.id FROM #__wiki_page AS p\n\t\t\tWHERE p.group_cn=" . $this->database->quote($prGroup) . " AND p.scope LIKE '" . $masterscope . "%' ");
     $notes = $this->database->loadObjectList();
     if ($notes) {
         foreach ($notes as $note) {
             $page = new \Components\Wiki\Tables\Page($this->database);
             // Delete the page's history, tags, comments, etc.
             $page->deleteBits($note->id);
             // Finally, delete the page itself
             $page->delete($note->id);
         }
     }
     // Erase all files, remove files repository
     if ($alias) {
         // Delete base dir for .git repos
         $dir = $alias;
         $prefix = $this->config->get('offroot', 0) ? '' : PATH_CORE;
         $repodir = DS . trim($this->config->get('webpath'), DS);
         $path = $prefix . $repodir . DS . $dir;
         if (is_dir($path)) {
             Filesystem::deleteDirectory($path);
         }
         // Delete images/preview directories
         $webdir = DS . trim($this->config->get('imagepath', '/site/projects'), DS);
         $webpath = PATH_APP . $webdir . DS . $dir;
         if (is_dir($webpath)) {
             Filesystem::deleteDirectory($webpath);
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option, false), Lang::txt('COM_PROJECTS_PROJECT') . ' #' . $id . ' (' . $alias . ') ' . Lang::txt('COM_PROJECTS_PROJECT_ERASED'));
 }
Example #8
0
 * @license   http://opensource.org/licenses/MIT MIT
 */
// 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');
}
$db = App::get('db');
$tbl = new \Components\Wiki\Tables\Page($db);
$db->setQuery($tbl->buildQuery(array('search' => 'Help:WikiMacros', 'sort' => 'title', 'sort_Dir' => 'asc', 'limit' => 1, 'start' => 0)));
$macros = new \Components\Wiki\Models\Page($db->loadObject());
$macros->set('group_cn', null);
$db->setQuery($tbl->buildQuery(array('search' => 'Help:WikiFormatting', 'sort' => 'title', 'sort_Dir' => 'asc', 'limit' => 1, 'start' => 0)));
$formatting = new \Components\Wiki\Models\Page($db->loadObject());
$formatting->set('group_cn', null);
?>
<header id="<?php 
echo $this->sub ? 'sub-content-header' : 'content-header';
?>
">
	<h2><?php 
echo $this->escape($this->title);
?>
</h2>
Example #9
0
 /**
  * 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;
 }
Example #10
0
 /**
  * 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;
     }
 }