/** * 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))); return; } // Incoming revision $rev = Request::getVar('revision', array(), 'post', 'none', 2); //$rev['pageid'] = (isset($rev['pageid'])) ? intval($rev['pageid']) : 0; $this->revision = $this->page->revision('current'); $this->revision->set('version', $this->revision->get('version') + 1); if (!$this->revision->bind($rev)) { $this->setError($this->revision->getError()); $this->editTask(); return; } $this->revision->set('id', 0); // Incoming page $page = Request::getVar('page', array(), 'post', 'none', 2); $this->page = new Article(intval($rev['pageid'])); if (!$this->page->bind($page)) { $this->setError($this->page->getError()); $this->editTask(); return; } $this->page->set('pagename', trim(Request::getVar('pagename', '', 'post'))); $this->page->set('scope', trim(Request::getVar('scope', '', '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 (!$rev['pageid']) { // New page - save it to the database $this->page->set('created_by', User::get('id')); $old = new Revision(0); } else { // Get the revision before changes $old = $this->page->revision('current'); } // Was the preview button pushed? $this->preview = trim(Request::getVar('preview', '')); if ($this->preview) { // Set the component task if (!$rev['pageid']) { Request::setVar('task', 'new'); $this->_task = 'new'; } else { Request::setVar('task', 'edit'); $this->_task = 'edit'; } // Push on through to the edit form $this->editTask(); return; } // Check content // First, make sure the pagetext isn't empty if ($this->revision->get('pagetext') == '') { $this->setError(Lang::txt('COM_WIKI_ERROR_MISSING_PAGETEXT')); $this->editTask(); return; } // Store new content if (!$this->page->store(true)) { $this->setError($this->page->getError()); $this->editTask(); return; } // Get allowed authors if (!$this->page->updateAuthors(Request::getVar('authors', '', 'post'))) { $this->setError($this->page->getError()); $this->editTask(); return; } // Get the upload path $wpa = new Tables\Attachment($this->database); $path = $wpa->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'))); } $wpa->setPageID($lid, $this->page->get('id')); } } $this->revision->set('pageid', $this->page->get('id')); $this->revision->set('pagename', $this->page->get('pagename')); $this->revision->set('scope', $this->page->get('scope')); $this->revision->set('group_cn', $this->page->get('group_cn')); $this->revision->set('version', $this->revision->get('version') + 1); if ($this->page->param('mode', 'wiki') == 'knol') { // Set revisions to NOT approved $this->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'))) { $this->revision->set('approved', 1); } } else { // Wiki mode, approve revision $this->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($this->revision->get('pagetext'))) { // Transform the wikitext to HTML $this->revision->set('pagehtml', ''); $this->revision->set('pagehtml', $this->revision->content('parsed')); // Parse attachments /*$a = new Tables\Attachment($this->database); $a->pageid = $this->page->id; $a->path = $path; $this->revision->pagehtml = $a->parse($this->revision->pagehtml);*/ if ($this->page->access('manage') || $this->page->access('edit')) { $this->revision->set('approved', 1); } // Store content if (!$this->revision->store(true)) { $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_REVISION')); $this->editTask(); return; } $this->page->set('version_id', $this->revision->get('id')); $this->page->set('modified', $this->revision->get('created')); } else { $this->page->set('modified', Date::toSql()); } if (!$this->page->store(true)) { // This really shouldn't happen. $this->setError(Lang::txt('COM_WIKI_ERROR_SAVING_PAGE')); $this->editTask(); return; } // Process tags $this->page->tag(Request::getVar('tags', '')); // Redirect App::redirect(Route::url($this->page->link())); }
/** * Display a list of files * * @return void */ public function listTask() { // Incoming $listdir = Request::getInt('listdir', 0, 'get'); if (!$listdir) { $this->setError(Lang::txt('COM_WIKI_NO_ID')); } $attachment = new Tables\Attachment($this->database); $path = $attachment->filespace() . DS . $listdir; $folders = array(); $docs = array(); if (is_dir($path)) { // Loop through all files and separate them into arrays of images, folders, and other $dirIterator = new \DirectoryIterator($path); foreach ($dirIterator as $file) { if ($file->isDot()) { continue; } if ($file->isDir()) { $name = $file->getFilename(); $folders[$path . DS . $name] = $name; continue; } if ($file->isFile()) { $name = $file->getFilename(); if ('cvs' == strtolower($name) || '.svn' == strtolower($name)) { continue; } $docs[$path . DS . $name] = $name; } } ksort($folders); ksort($docs); } $this->view->docs = $docs; $this->view->folders = $folders; $this->view->config = $this->config; $this->view->listdir = $listdir; $this->view->name = $this->_name; $this->view->sub = $this->_sub; foreach ($this->getErrors() as $error) { $this->view->setError($error); } $this->view->setLayout('list')->display(); }