Exemplo n.º 1
0
 /**
  * Get the content of the record.
  * Optional argument to determine how content should be handled
  *
  * parsed - performs parsing on content (i.e., converting wiki markup to HTML)
  * clean  - parses content and then strips tags
  * raw    - as is, no parsing
  *
  * @param   object  $page
  * @param   string  $option
  * @return  string
  */
 public function content($page = null, $option = null)
 {
     if (!$page) {
         $page = $this->page;
     }
     $route = $page->adapter()->routing('');
     $route['option'] = '';
     $route = implode('/', $route);
     $route = $route ? $route . '/' : $route;
     $wikiconfig = array('option' => $option ?: \Request::getCmd('option'), 'scope' => $page->get('path'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => '', 'domain' => $page->get('scope'), 'domain_id' => $page->get('scope_id'), 'url' => $page->link());
     $parser = Parser::getInstance();
     // Parse the text
     return $parser->parse($this->get('pagetext'), $wikiconfig, true, true);
 }
Exemplo n.º 2
0
 /**
  * Save a revision
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $revision = Request::getVar('revision', array(), 'post', 'none', 2);
     $revision = array_map('trim', $revision);
     // Initiate extended database class
     $row = new Revision($revision['id']);
     $before = $row->get('approved');
     if (!$row->bind($revision)) {
         $this->setMessage($row->getError(), 'error');
         $this->editTask($row);
         return;
     }
     if (!$row->exists()) {
         $row->set('created', Date::toSql());
     }
     $page = new Page(intval($row->get('pageid')));
     // Parse text
     $wikiconfig = array('option' => $this->_option, 'scope' => $page->get('scope'), 'pagename' => $page->get('pagename'), 'pageid' => $page->get('id'), 'filepath' => '', 'domain' => $this->_group);
     $p = Parser::getInstance();
     $row->set('pagehtml', $p->parse($row->get('pagetext'), $wikiconfig));
     // Store new content
     if (!$row->store()) {
         $this->setMessage($row->getError(), 'error');
         $this->editTask($row);
         return;
     }
     // Get the most recent revision and compare to the set "current" version
     if ($before != 1 && $row->get('approved') == 1) {
         $page->revisions('list', array(), true)->last();
         if ($page->revisions()->current()->get('id') == $row->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', $page->revisions()->current()->get('id'));
             $page->store(false, 'revision_approved');
         } else {
             $page->log('revision_approved');
         }
     }
     // Set the redirect
     if ($this->getTask() == 'apply') {
         return $this->editTask($row);
     }
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&pageid=' . $row->get('pageid'), false), Lang::txt('COM_WIKI_REVISION_SAVED'));
 }
Exemplo n.º 3
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));
 }
Exemplo n.º 4
0
 /**
  * Parse Wiki content
  *
  * @param    Object    $group        \Hubzero\User\Group Object
  * @param    String    $content      Content to parse
  * @param    BOOL      $fullparse    Fully parse wiki content
  * @return   String
  */
 public static function parseWiki($group, $content, $fullparse = true)
 {
     // do we have wiki content that needs parsing?
     if (self::_isWiki($content)) {
         // create path
         $path = Component::params('com_groups')->get('uploadpath');
         include_once Component::path('com_wiki') . DS . 'helpers' . DS . 'parser.php';
         // build wiki config
         $wikiConfig = array('option' => 'com_groups', 'scope' => '', 'pagename' => $group->get('cn'), 'pageid' => 0, 'filepath' => $path . DS . $group->get('gidNumber') . DS . 'uploads', 'domain' => $group->get('cn'));
         // create wiki parser
         $wikiParser = \Components\Wiki\Helpers\Parser::getInstance();
         // parse content
         $content = $wikiParser->parse("\n" . $content, $wikiConfig, $fullparse);
     }
     //return content
     return $content;
 }
Exemplo n.º 5
0
 /**
  * Get the content of the entry
  *
  * @param   string   $as       Format to return state in [text, number]
  * @param   integer  $shorten  Number of characters to shorten text to
  * @return  string
  */
 public function content($as = 'parsed', $shorten = 0)
 {
     $as = strtolower($as);
     $options = array();
     switch ($as) {
         case 'parsed':
             if ($this->get('chtml')) {
                 return $this->get('chtml');
             }
             $parser = Parser::getInstance();
             $parsed = $parser->parse(stripslashes($this->get('ctext')), array('option' => Request::getCmd('option', 'com_wiki'), 'scope' => Request::getVar('scope'), 'pagename' => Request::getVar('pagename'), 'pageid' => $this->get('page_id'), 'filepath' => '', 'domain' => Request::getVar('group', '')));
             $this->set('chtml', $parsed);
             if ($shorten) {
                 $content = String::truncate($this->get('chtml'), $shorten, array('html' => true));
                 return $content;
             }
             return $this->get('chtml');
             break;
         case 'clean':
             $content = strip_tags($this->content('parsed'));
             break;
         case 'raw':
         default:
             $content = $this->get('ctext');
             break;
     }
     if ($shorten) {
         $content = String::truncate($content, $shorten, $options);
     }
     return $content;
 }
Exemplo n.º 6
0
 /**
  * Output the contents of a wiki page as a PDF
  *
  * Based on work submitted by Steven Maus <*****@*****.**> (2014)
  *
  * @return     void
  */
 public function pdfTask()
 {
     // Does a page exist for the given pagename?
     if (!$this->page->exists() || $this->page->isDeleted()) {
         App::abort(404, Lang::txt('COM_WIKI_WARNING_NOT_FOUND'));
         // No! Ask if they want to create a new page
         /*$this->view->setLayout('doesnotexist');
         			if ($this->_group)
         			{
         				$this->page->set('group_cn', $this->_group);
         				$this->page->set('scope', $this->_group . '/wiki');
         			}
         
         			if ($this->getError())
         			{
         				foreach ($this->getErrors() as $error)
         				{
         					$this->view->setError($error);
         				}
         			}
         			$this->view->display();
         			return;*/
     }
     // Retrieve a specific version if given
     $this->view->revision = $this->page->revision(Request::getInt('version', 0));
     if (!$this->view->revision->exists()) {
         foreach ($this->getErrors() as $error) {
             $this->view->setError($error);
         }
         $this->view->set('page', $this->page)->setLayout('nosuchrevision')->display();
         return;
     }
     Request::setVar('format', 'pdf');
     $pdf = new \TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
     // set header and footer fonts
     $pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
     $pdf->setFooterFont(array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
     // set margins
     $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
     $pdf->SetHeaderMargin(10);
     $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
     // set auto page breaks
     $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
     // set image scale factor
     $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
     // Set font
     $pdf->SetFont('dejavusans', '', 11, '', true);
     $pdf->setAuthor = $this->page->creator('name');
     $pdf->setCreator = \Config::get('sitename');
     $pdf->setDocModificationTimeStamp($this->page->modified());
     $pdf->setHeaderData(NULL, 0, strtoupper($this->page->get('itle')), NULL, array(84, 94, 124), array(146, 152, 169));
     $pdf->setFooterData(array(255, 255, 255), array(255, 255, 255));
     $pdf->AddPage();
     // Set the view page content to current revision html
     $this->view->page = $this->page;
     // Load the wiki parser
     $wikiconfig = array('option' => $this->_option, 'scope' => $this->page->get('scope'), 'pagename' => $this->page->get('pagename'), 'pageid' => $this->page->get('id'), 'filepath' => '', 'domain' => $this->page->get('group_cn'));
     $p = Parser::getInstance();
     // Parse the text
     $this->view->revision->set('pagehtml', $p->parse($this->view->revision->get('pagetext'), $wikiconfig, true, true));
     $pdf->writeHTML($this->view->loadTemplate(), true, false, true, false, '');
     header("Content-type: application/octet-stream");
     // Close and output PDF document
     // Force the download of the PDF
     $pdf->Output($this->page->get('pagename') . '.pdf', 'D');
     exit;
 }
Exemplo n.º 7
0
 /**
  * Get the content of the record.
  * Optional argument to determine how content should be handled
  *
  * parsed - performs parsing on content (i.e., converting wiki markup to HTML)
  * clean  - parses content and then strips tags
  * raw    - as is, no parsing
  *
  * @param   string  $as      Format to return content in [parsed, clean, raw]
  * @param   integer $shorten Number of characters to shorten text to
  * @return  mixed   String or Integer
  */
 public function content($as = 'parsed', $shorten = 0)
 {
     $as = strtolower($as);
     switch ($as) {
         case 'parsed':
             if ($this->get('pagetext_parsed')) {
                 return $this->get('pagetext_parsed');
             }
             $p = Parser::getInstance();
             $wikiconfig = array('option' => 'com_wiki', 'scope' => $this->get('scope'), 'pagename' => $this->get('pagename'), 'pageid' => $this->get('id'), 'filepath' => $this->config('uploadpath'), 'domain' => '');
             $this->set('pagetext_parsed', $p->parse(stripslashes($this->get('pagetext')), $wikiconfig));
             if ($shorten) {
                 $content = String::truncate($this->get('pagetext_parsed'), $shorten, array('html' => true));
                 return $content;
             }
             return $this->get('pagetext_parsed');
             break;
         case 'clean':
             $content = strip_tags($this->content('parsed'));
             if ($shorten) {
                 $content = String::truncate($content, $shorten);
             }
             return $content;
             break;
         case 'raw':
         default:
             $content = $this->get('pagetext');
             if ($shorten) {
                 $content = String::truncate($content, $shorten);
             }
             return $content;
             break;
     }
 }
Exemplo n.º 8
0
 /**
  * Load a wiki with default content
  * This is largely Help pages
  *
  * @param   string $option Component name
  * @return  string
  */
 public function scribe($option)
 {
     $pages = $this->_defaultPages();
     if (count($pages) <= 0) {
         return Lang::txt('No default pages found');
     }
     $p = Parser::getInstance();
     foreach ($pages as $f => $c) {
         $f = str_replace('_', ':', $f);
         // Instantiate a new page
         $page = new Tables\Page($this->_db);
         $page->pagename = $f;
         $page->title = $page->getTitle();
         $page->access = 0;
         if ($this->_scope != '__site__') {
             $page->group_cn = $this->_scope;
             $page->scope = $this->_scope . '/wiki';
         }
         if ($this->_scope == '__site__' && $page->pagename == 'MainPage') {
             $page->params = 'mode=static' . "\n";
         } else {
             $page->params = 'mode=wiki' . "\n";
         }
         // Check content
         if (!$page->check()) {
             throw new Exception($page->getError(), 500);
         }
         // Store content
         if (!$page->store()) {
             throw new Exception($page->getError(), 500);
         }
         // Ensure we have a page ID
         if (!$page->id) {
             $page->id = $this->_db->insertid();
         }
         // Instantiate a new revision
         $revision = new Tables\Revision($this->_db);
         $revision->pageid = $page->id;
         $revision->minor_edit = 0;
         $revision->version = 1;
         $revision->pagetext = $c;
         $revision->approved = 1;
         $wikiconfig = array('option' => $option, 'scope' => $page->scope, 'pagename' => $page->pagename, 'pageid' => $page->id, 'filepath' => '', 'domain' => $page->group_cn);
         // Transform the wikitext to HTML
         if ($page->pagename != 'Help:WikiMath') {
             $revision->pagehtml = $p->parse($revision->pagetext, $wikiconfig, true, true);
         }
         // Check content
         if (!$revision->check()) {
             throw new Exception($revision->getError(), 500);
         }
         // Store content
         if (!$revision->store()) {
             throw new Exception($revision->getError(), 500);
         }
         $page->version_id = $revision->id;
         $page->modified = $revision->created;
         if (!$page->store()) {
             // This really shouldn't happen.
             throw new Exception($page->getError(), 500);
         }
     }
     return null;
 }