Пример #1
0
 /**
  * Retrieve an included page
  * This is recursive and should look for inclusions in any included page.
  *
  * @param      array $matches Pattern matches from includes() method
  * @return     string
  */
 private function _getInclude($matches)
 {
     if (isset($matches[1]) && $matches[1] != '') {
         if (strtolower($matches[1]) != 'include') {
             return $matches[0];
         }
         if (!$this->get('fullparse')) {
             return "'''Includes not allowed.'''";
         }
         $scope = $this->get('domain') ? $this->get('domain') . DS . 'wiki' : $this->get('scope');
         if (strstr($matches[3], '/')) {
             $bits = explode('/', $matches[3]);
             $pagename = array_pop($bits);
             $s = trim(implode('/', $bits));
             $scope .= DS . trim($s, DS);
         } else {
             $pagename = $matches[3];
         }
         // Don't include this page (infinite loop!)
         if ($pagename == $this->get('pagename') && $scope == $this->get('scope')) {
             return '';
         }
         // Load the page
         $p = \Components\Wiki\Tables\Page::getInstance($pagename, $scope);
         if ($p->id) {
             // Parse any nested includes
             return $this->includes($p->getCurrentRevision()->pagetext);
         }
     }
     return '';
 }
Пример #2
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;
 }