public function getPreview($length = 200) { if (is_array($this->prefetched)) { if (in_array('page_compiled', $this->prefetched)) { if (in_array('page_compiled', $this->prefetchedObjects)) { $compiled = $this->prefetchedObjects['page_compiled']; } else { $obj = new DB_PageCompiled($this->sourceRow); $obj->setNew(false); $this->prefetchedObjects['page_compiled'] = $obj; $compiled = $obj; } } } if ($compiled == null) { $c = new Criteria(); $c->add("page_id", $this->getPageId()); $compiled = DB_PageCompiledPeer::instance()->selectOne($c); } $text = $compiled->getText(); $text = preg_replace(';<table style=".*?id="toc".*?</table>;s', '', $text, 1); $stripped = strip_tags($text); $d = utf8_encode("þ"); $stripped = preg_replace("/" . $d . "module \"([a-zA-Z0-9\\/_]+?)\"(.+?)?" . $d . "/", '', $stripped); $stripped = str_replace($d, '', $stripped); // get last position of " " if (strlen8($stripped) > $length) { $substr = substr($stripped, 0, $length); $length = strrpos($substr, " "); $substr = trim(substr($substr, 0, $length)); $substr .= '...'; } else { $substr = $stripped; } return $substr; }
/** * This is the place where pages are compiled! * * @param Db_Page $page */ private function recompilePage($page) { // compiled content not up to date. recompile! $source = $page->getSource(); $c = new Criteria(); $c->add("page_id", $page->getPageId()); $compiled = DB_PageCompiledPeer::instance()->selectOne($c); /* Find out if the category is using any templates. */ if (!preg_match(';(:|^)_;', $page->getUnixName())) { $category = $page->getCategory(); $categoryName = $category->getName(); $templatePage = DB_PagePeer::instance()->selectByName($page->getSiteId(), ($categoryName == '_default' ? '' : $categoryName . ':') . '_template'); if ($templatePage) { $source = $this->assemblySource($source, $templatePage->getSource(), $page); } } $wt = new WikiTransformation(); $wt->setPage($page); $result = $wt->processSource($source); $compiled->setText($result); $compiled->setDateCompiled(new ODate()); $compiled->save(); $linksExist = $wt->wiki->vars['internalLinksExist']; $linksNotExist = $wt->wiki->vars['internalLinksNotExist']; $inclusions = $wt->wiki->vars['inclusions']; $inclusionsNotExist = $wt->wiki->vars['inclusionsNotExist']; $externalLinks = $wt->wiki->vars['externalLinks']; $this->vars['linksExist'] = $linksExist; $this->vars['linksNotExist'] = $linksNotExist; $this->vars['inclusions'] = $inclusions; $this->vars['inclusionsNotExist'] = $inclusionsNotExist; $this->vars['externalLinks'] = $externalLinks; }