示例#1
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
         $row = \Components\Wiki\Models\Page::oneOrNew(intval($page));
     } else {
         $page = rtrim($page, '/');
         $row = \Components\Wiki\Models\Page::oneByPagename($page, $this->domain, $this->domain_id);
     }
     if (!$row->exists()) {
         return '(Page(' . $et . ') failed)';
     }
     if ($nolink) {
         return stripslashes($row->get('title', $row->get('pagename')));
     }
     // Build and return the link
     return '<a href="' . Route::url($row->link()) . '">' . stripslashes($row->get('title', $row->get('pagename'))) . '</a>';
 }
示例#2
0
 /**
  * Display all revisions for a page in the wiki(s)
  *
  * @return  void
  */
 public function displayTask()
 {
     $filters = array('sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'version'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', ''), 'pageid' => Request::getState($this->_option . '.' . $this->_controller . '.pageid', 'pageid', 0, 'int'));
     $page = Page::oneOrNew(intval($filters['pageid']));
     // Get records
     $records = $page->versions();
     if ($filters['search']) {
         $filters['search'] = strtolower((string) $filters['search']);
         $records->whereLike('pagetext', $filters['search']);
     }
     $rows = $records->ordered('filter_order', 'filter_order_Dir')->paginated('limitstart', 'limit')->rows();
     // Output the HTML
     $this->view->set('rows', $rows)->set('filters', $filters)->set('page', $page)->display();
 }
示例#3
0
 /**
  * Save changes to an entry
  *
  * @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
     $fields = Request::getVar('page', array(), 'post');
     $fields = array_map('trim', $fields);
     $authors = $fields['authors'];
     $tags = $fields['tags'];
     unset($fields['authors']);
     unset($fields['tags']);
     // Initiate extended database class
     $page = Page::oneOrNew($fields['id'])->set($fields);
     // Get parameters
     $params = Request::getVar('params', array(), 'post');
     if (is_array($params)) {
         $pparams = new \Hubzero\Config\Registry($page->get('params'));
         $pparams->merge($params);
         $page->set('params', $pparams->toString());
     }
     // Store new content
     if (!$page->save()) {
         Notify::error($page->getError());
         return $this->editTask($page);
     }
     if (!Author::setForPage($authors, $page->get('id'))) {
         Notify::error($page->getError());
         return $this->editTask($page);
     }
     $page->tag($tags);
     Notify::success(Lang::txt('COM_WIKI_PAGE_SAVED'));
     if ($this->getTask() == 'apply') {
         Request::setVar('id', $page->get('id'));
         return $this->editTask($page);
     }
     // Redirect to main listing
     $this->cancelTask();
 }
示例#4
0
 /**
  * Save a wiki page
  *
  * @return  void
  */
 public function saveTask()
 {
     // 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 revision
     $revision = $this->page->version;
     $revision->set('version', $revision->get('version') + 1);
     $revision->set(Request::getVar('revision', array(), 'post', 'none', 2));
     $revision->set('id', 0);
     // Incoming page
     $page = Request::getVar('page', array(), 'post', 'none', 2);
     if (!isset($page['protected']) || !$page['protected']) {
         $page['protected'] = 0;
     }
     $this->page = Page::oneOrNew(intval($revision->get('page_id')));
     $this->page->set($page);
     $this->page->set('pagename', trim(Request::getVar('pagename', '', 'post')));
     // Get parameters
     $params = new \Hubzero\Config\Registry($this->page->get('params', ''));
     $params->merge(Request::getVar('params', array(), 'post'));
     $this->page->set('params', $params->toString());
     // Get the previous version to compare against
     if (!$revision->get('page_id')) {
         // New page - save it to the database
         $this->page->set('created_by', User::get('id'));
         $old = Version::blank();
     } else {
         // Get the revision before changes
         $old = $this->page->version;
     }
     // Was the preview button pushed?
     $this->preview = trim(Request::getVar('preview', ''));
     if ($this->preview) {
         // Set the component task
         if (!$page['id']) {
             Request::setVar('task', 'new');
             $this->_task = 'new';
         } else {
             Request::setVar('task', 'edit');
             $this->_task = 'edit';
         }
         // Push on through to the edit form
         return $this->editTask($revision);
     }
     // Check content
     // First, make sure the pagetext isn't empty
     if ($revision->get('pagetext') == '') {
         $this->setError(Lang::txt('COM_WIKI_ERROR_MISSING_PAGETEXT'));
         return $this->editTask($revision);
     }
     // Store new content
     if (!$this->page->save()) {
         $this->setError($this->page->getError());
         return $this->editTask($revision);
     }
     // Get allowed authors
     if (!Author::setForPage(Request::getVar('authors', '', 'post'), $this->page->get('id'))) {
         $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_AUTHORS'));
         return $this->editTask($revision);
     }
     // Get the upload path
     $path = Attachment::blank()->filespace();
     // Rename the temporary upload directory if it exist
     $lid = Request::getInt('lid', 0, 'post');
     if ($lid != $this->page->get('id')) {
         if (is_dir($path . DS . $lid)) {
             if (!\Filesystem::move($path . DS . $lid, $path . DS . $this->page->get('id'))) {
                 $this->setError(\Filesystem::move($path . DS . $lid, $path . DS . $this->page->get('id')));
             }
         }
         foreach (Attachment::all()->whereEquals('page_id', $lid)->rows() as $attachment) {
             $attachment->set('page_id', $this->page->get('id'));
             if (!$attachment->save()) {
                 $this->setError($attachment->getError());
             }
         }
     }
     $revision->set('page_id', $this->page->get('id'));
     $revision->set('version', $revision->get('version') + 1);
     if ($this->page->param('mode', 'wiki') == 'knol') {
         // Set revisions to NOT approved
         $revision->set('approved', 0);
         // If an author or the original page creator, set to approved
         if ($this->page->get('created_by') == User::get('id') || $this->page->isAuthor(User::get('id'))) {
             $revision->set('approved', 1);
         }
     } else {
         // Wiki mode, approve revision
         $revision->set('approved', 1);
     }
     // Compare against previous revision
     // We don't want to create a whole new revision if just the tags were changed
     if (rtrim($old->get('pagetext')) != rtrim($revision->get('pagetext'))) {
         // Transform the wikitext to HTML
         $revision->set('pagehtml', '');
         $revision->set('pagehtml', $revision->content($this->page));
         if ($this->page->access('manage') || $this->page->access('edit')) {
             $revision->set('approved', 1);
         }
         // Store content
         if (!$revision->save()) {
             $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_REVISION'));
             return $this->editTask($revision);
         }
         $this->page->set('version_id', $revision->get('id'));
         $this->page->set('modified', $revision->get('created'));
     } else {
         $this->page->set('modified', Date::toSql());
     }
     if (!$this->page->save()) {
         // This really shouldn't happen.
         $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_PAGE'));
         return $this->editTask($revision);
     }
     // Process tags
     $this->page->tag(Request::getVar('tags', ''));
     // Log activity
     $recipients = array(['wiki.site', 1], ['user', $this->page->get('created_by')], ['user', $revision->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' => $page['id'] ? 'updated' : 'created', 'scope' => 'wiki.page', 'scope_id' => $this->page->get('id'), 'description' => Lang::txt('COM_WIKI_ACTIVITY_PAGE_' . ($page['id'] ? 'UPDATED' : 'CREATED'), '<a href="' . Route::url($this->page->link()) . '">' . $this->page->title . '</a>'), 'details' => array('title' => $this->page->title, 'url' => Route::url($this->page->link()), 'name' => $this->page->get('pagename'), 'revision' => $revision->get('id'))], 'recipients' => $recipients]);
     // Redirect
     App::redirect(Route::url($this->page->link()));
 }