Пример #1
0
 /**
  * Display a list of blog entries
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('page_id' => Request::getState($this->_option . '.' . $this->_controller . '.page_id', 'page_id', 0, 'int'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'ASC'), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $page = Page::oneOrFail($filters['page_id']);
     $comments = Comment::all();
     if ($filters['search']) {
         $comments->whereLike('ctext', strtolower((string) $filters['search']));
     }
     if ($filters['page_id']) {
         $comments->whereEquals('page_id', $filters['page_id']);
     }
     $rows = $comments->ordered('filter_order', 'filter_order_Dir')->rows();
     $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
     $list = array();
     $children = array();
     if ($rows) {
         // First pass - collect children
         foreach ($rows as $k) {
             $pt = $k->get('parent');
             $list = @$children[$pt] ? $children[$pt] : array();
             array_push($list, $k);
             $children[$pt] = $list;
         }
         // Second pass - get an indent list of the items
         $list = $this->treeRecurse(0, '', array(), $children, max(0, $levellimit - 1));
     }
     // Output the HTML
     $this->view->set('filters', $filters)->set('page', $page)->set('total', count($list))->set('rows', array_slice($list, $filters['start'], $filters['limit']))->display();
 }
Пример #2
0
 /**
  * Generate macro output
  *
  * @return  string
  */
 public function render()
 {
     $et = $this->args;
     $live_site = rtrim(Request::base(), '/');
     // Get resource by ID
     $attach = \Components\Wiki\Models\Attachment::all()->whereEquals('page_id', $this->pageid);
     if ($et) {
         $et = strip_tags($et);
         $attach->whereLike('filename', strtolower($et) . '%');
     }
     $rows = $attach->rows();
     // Did we get a result from the database?
     if ($rows) {
         $config = Component::params('com_wiki');
         if ($this->filepath != '') {
             $config->set('filepath', $this->filepath);
         }
         $page = \Components\Wiki\Models\Page::oneOrFail($this->pageid);
         if ($page->get('namespace') == 'help') {
             $page->set('path', $page->get('path') ? rtrim($this->scope, '/') . '/' . ltrim($page->get('path'), '/') : $this->scope);
         }
         // Build and return the link
         $html = '<ul>';
         foreach ($rows as $row) {
             $page->set('pagename', $page->get('pagename') . '/' . 'File:' . $row->get('filename'));
             $link = $page->link();
             $fpath = $row->filespace() . DS . $this->pageid . DS . $row->get('filename');
             $html .= '<li><a href="' . Route::url($link) . '">' . $row->get('filename') . '</a> (' . (file_exists($fpath) ? \Hubzero\Utility\Number::formatBytes(filesize($fpath)) : '-- file not found --') . ') ';
             $huser = $row->creator();
             if ($huser->get('id')) {
                 $html .= '- added by <a href="' . Route::url('index.php?option=com_members&id=' . $huser->get('id')) . '">' . stripslashes($huser->get('name')) . '</a> ';
             }
             if ($row->get('created') && $row->get('created') != '0000-00-00 00:00:00') {
                 $html .= Date::of($row->get('created'))->relative() . '. ';
             }
             $html .= $row->get('description') ? '<span>"' . stripslashes($row->get('description')) . '"</span>' : '';
             $html .= '</li>' . "\n";
         }
         $html .= '</ul>';
         return $html;
     }
     // Return error message
     return '(No ' . $et . ' files to display)';
 }
Пример #3
0
 /**
  * Retrieves a row from the database
  *
  * @param   string  $refid     ID of the database table row
  * @param   string  $category  Element type (determines table to look in)
  * @param   string  $parent    If the element has a parent element
  * @return  array
  */
 public function getReportedItem($refid, $category, $parent)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
     $query = "SELECT rc.id, rc.page_id AS entry_id, rc.chtml as `text`, rc.created_by as author, rc.created, NULL as subject, rc.anonymous as anon, 'wiki' AS parent_category\n\t\t\t\t\tFROM `#__wiki_comments` AS rc\n\t\t\t\t\tWHERE rc.id=" . $refid;
     $database = App::get('db');
     $database->setQuery($query);
     $rows = $database->loadObjectList();
     if ($rows) {
         foreach ($rows as $key => $row) {
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $row->text, $matches)) {
                 $rows[$key]->text = preg_replace('/^(<!-- \\{FORMAT:.*\\} -->)/i', '', $row->text);
             }
             $entry = \Components\Wiki\Models\Page::oneOrFail($rows[$key]->entry_id);
             $rows[$key]->text = $rows[$key]->text;
             $rows[$key]->href = Route::url($entry->link() . '#c' . $rows[$key]->id);
         }
     }
     return $rows;
 }
Пример #4
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
     if (file_exists(PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php')) {
         include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'page.php';
         // Get all notes
         $this->database->setQuery("SELECT DISTINCT p.id FROM `#__wiki_pages` AS p\n\t\t\t\tWHERE p.scope_id=" . $this->database->quote($id) . " AND p.scope=" . $this->database->quote('project'));
         $notes = $this->database->loadObjectList();
         if ($notes) {
             foreach ($notes as $note) {
                 $page = \Components\Wiki\Models\Page::oneOrFail($note->id);
                 // Finally, delete the page itself
                 $page->destroy();
             }
         }
     }
     // 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'));
 }
Пример #5
0
 /**
  * Save a revision
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.create', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $revision = Request::getVar('revision', array(), 'post', 'none', 2);
     $revision = array_map('trim', $revision);
     // Initiate extended database class
     $version = Version::oneOrNew($revision['id']);
     // Get the "approved" state before binding incoming data
     $before = $version->get('approved');
     // Bind data
     $version->set($revision);
     // Get the parent page
     $page = Page::oneOrFail(intval($version->get('page_id')));
     // Parse text
     $parser = Parser::getInstance();
     $version->set('pagehtml', $parser->parse($version->get('pagetext'), array('option' => $this->_option, 'scope' => $page->get('scope'), 'scope_id' => $page->get('scope_id'), 'path' => $page->get('path'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => '')));
     // Store new content
     if (!$version->save()) {
         Notify::error($version->getError());
         return $this->editTask($version);
     }
     // Get the most recent revision and compare to the set "current" version
     if ($before != 1 && $version->get('approved') == 1) {
         $current = $page->versions()->whereEquals('approved', 1)->ordered()->row();
         if ($current->get('id') == $version->get('id')) {
             // The newly approved revision is now the most current
             // So, we need to update the page's version_id
             $page->set('version_id', $version->get('id'));
             $page->save();
         }
         $page->log('revision_approved');
     }
     // Set the success message
     Notify::success(Lang::txt('COM_WIKI_REVISION_SAVED'));
     // Fall through to the edit form
     if ($this->getTask() == 'apply') {
         return $this->editTask($version);
     }
     // Redirect to listing
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $version->get('page_id'), false));
 }
Пример #6
0
 /**
  * Set the state for a page
  *
  * @return  void
  */
 public function stateTask()
 {
     // Check for request forgeries
     Request::checkToken('get');
     if (!User::authorise('core.edit.state', $this->_option)) {
         App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR'));
     }
     // Incoming
     $id = Request::getInt('id', 0);
     // Make sure we have an ID to work with
     if (!$id) {
         Notify::warning(Lang::txt('COM_WIKI_ERROR_MISSING_ID'));
     } else {
         // Load and set state
         $page = Page::oneOrFail(intval($id));
         $page->set('state', Request::getInt('state', 0));
         if (!$page->save()) {
             Notify::error($page->getError());
         }
     }
     // Redirect to main listing
     $this->cancelTask();
 }
Пример #7
0
 /**
  * Generate a link to a file
  * If $file starts with (http|https|mailto|ftp|gopher|feed|news|file), then it's an external URL and returned
  *
  * @param   string  $file  Filename
  * @return  string
  */
 private function _link($file)
 {
     $urlPtrn = "[^=\"\\'](https?:|mailto:|ftp:|gopher:|feed:|news:|file:)" . "([^ |\\/\"\\']*\\/)*([^ |\\t\\n\\/\"\\']*[A-Za-z0-9\\/?=&~_])";
     if (preg_match("/^(https?:|mailto:|ftp:|gopher:|news:|file:)/", $file) || preg_match("/{$urlPtrn}/", $file) || substr($file, 0, 1) == DS) {
         return $file;
     }
     $file = trim($file, DS);
     if (Request::getVar('format') == 'pdf') {
         return $this->_path($file);
     }
     if ($this->pageid) {
         $page = \Components\Wiki\Models\Page::oneOrFail($this->pageid);
         $link = $page->link();
     } else {
         $link = '/' . substr($this->option, 4, strlen($this->option)) . '/';
         if ($this->scope) {
             $scope = trim($this->scope, '/');
             $link .= $scope . '/';
         }
         $link .= $this->pagename;
     }
     $link = rtrim($link, '/');
     $link .= '/Image:' . $file;
     return Route::url($link);
 }
Пример #8
0
 /**
  * Delete a page
  *
  * @apiMethod DELETE
  * @apiUri    /wiki/{id}
  * @apiParameter {
  * 		"name":          "id",
  * 		"description":   "Page identifier",
  * 		"type":          "integer",
  * 		"required":      true,
  * 		"default":       0
  * }
  * @return  void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $page = Page::oneOrFail(Request::getInt('id', 0));
     if (!$page->get('id')) {
         throw new Exception(Lang::txt('COM_WIKI_ERROR_PAGE_NOT_FOUND'), 404);
     }
     if (!$page->access('delete')) {
         throw new Exception(Lang::txt('COM_WIKI_ERROR_NOTAUTH'), 403);
     }
     $page->set('state', Page::STATE_DELETED);
     if (!$page->save()) {
         throw new Exception(Lang::txt('COM_WIKI_UNABLE_TO_DELETE'), 500);
     }
     $this->send(null, 202);
 }
Пример #9
0
 /**
  * Create an item entry for a wiki page
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_wiki' . DS . 'models' . DS . 'book.php';
     $page = null;
     if (!$id) {
         $scope = 'site';
         $scope_id = 0;
         if ($group = Request::getVar('cn', '')) {
             $group = Group::getInstance($group);
             $scope = 'group';
             $scope_id = $group->get('gidNumber');
         }
         $book = new Book($scope, $scope_id);
         $page = $book->page();
         $id = $page->get('id');
     }
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     if (!$page) {
         $page = Page::oneOrFail($id);
     }
     if (!$page->exists()) {
         $this->setError(Lang::txt('Wiki page not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $page->get('id'))->set('created', $page->get('created'))->set('created_by', $page->get('created_by'))->set('title', $page->title)->set('description', strip_tags($page->version->content($page)))->set('url', Route::url($page->link()));
     if (!$this->store()) {
         return false;
     }
     return true;
 }