Skip to content
Snippets Groups Projects
Commit 6b7b33dc authored by hfuecks's avatar hfuecks
Browse files

xhtmlsummary_patch

darcs-hash:20051107000554-e96b6-1a7ae7a9d5e820d3c52629570ff33f8e75bc4a46.gz
parent 9b9cbe54
No related branches found
No related tags found
No related merge requests found
<?php
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
require_once DOKU_INC . 'inc/parser/xhtml.php';
/**
* The summary XHTML form selects either up to the first two paragraphs
* it find in a page or the first section (whichever comes first)
* It strips out the table of contents if one exists
* Section divs are not used - everything should be nested in a single
* div with CSS class "page"
* Headings have their a name link removed and section editing links
* removed
* It also attempts to capture the first heading in a page for
* use as the title of the page.
*/
class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
// Namespace these variables to
// avoid clashes with parent classes
var $sum_paragraphs = 0;
var $sum_capture = TRUE;
var $sum_inSection = FALSE;
var $sum_summary = '';
var $sum_pageTitle = FALSE;
function document_start() {
$this->doc .= DOKU_LF.'<div>'.DOKU_LF;
}
function document_end() {
$this->doc = $this->sum_summary;
$this->doc .= DOKU_LF.'</div>'.DOKU_LF;
}
function toc_open() {
$this->sum_summary .= $this->doc;
}
function toc_close() {
$this->doc = '';
}
function header($text, $level, $pos) {
if ( !$this->sum_pageTitle ) {
$this->info['sum_pagetitle'] = $text;
$this->sum_pageTitle = TRUE;
}
$this->doc .= DOKU_LF.'<h'.$level.'>';
$this->doc .= $this->_xmlEntities($text);
$this->doc .= "</h$level>".DOKU_LF;
}
function section_open($level) {
if ( $this->sum_capture ) {
$this->sum_inSection = TRUE;
}
}
function section_close() {
if ( $this->sum_capture && $this->sum_inSection ) {
$this->sum_summary .= $this->doc;
$this->sum_capture = FALSE;
}
}
function p_open() {
if ( $this->sum_capture && $this->sum_paragraphs < 2 ) {
$this->sum_paragraphs++;
}
parent :: p_open();
}
function p_close() {
parent :: p_close();
if ( $this->sum_capture && $this->sum_paragraphs >= 2 ) {
$this->sum_summary .= $this->doc;
$this->sum_capture = FALSE;
}
}
}
//Setup VIM: ex: et ts=2 enc=utf-8 :
......@@ -50,6 +50,62 @@ function p_wiki_xhtml($id, $rev='', $excuse=true){
return $ret;
}
/**
* Returns starting summary for a page (e.g. the first few
* paragraphs), marked up in XHTML.
*
* If $excuse is true an explanation is returned if the file
* wasn't found
*
* @param string wiki page id
* @param reference populated with page title from heading or page id
* @author Andreas Gohr <hfuecks@gmail.com>
*/
function p_wiki_xhtml_summary($id, &$title, $rev='', $excuse=true){
$file = wikiFN($id,$rev);
$ret = '';
//ensure $id is in global $ID (needed for parsing)
global $ID;
$keep = $ID;
$ID = $id;
if($rev){
if(@file_exists($file)){
//no caching on old revisions
$ins = p_get_instructions(io_readfile($file));
}elseif($excuse){
$ret = p_locale_xhtml('norev');
//restore ID (just in case)
$ID = $keep;
return $ret;
}
}else{
if(@file_exists($file)){
// The XHTML for a summary is not cached so use the instruction cache
$ins = p_cached_instructions($file);
}elseif($excuse){
$ret = p_locale_xhtml('newpage');
//restore ID (just in case)
$ID = $keep;
return $ret;
}
}
$ret = p_render('xhtmlsummary',$ins,$info);
if ( $info['sum_pagetitle'] ) {
$title = $info['sum_pagetitle'];
} else {
$title = $id;
}
$ID = $keep;
return $ret;
}
/**
* Returns the specified local text in parsed format
*
......@@ -294,6 +350,9 @@ function p_render($mode,$instructions,& $info){
require_once DOKU_INC."inc/parser/$mode.php";
$rclass = "Doku_Renderer_$mode";
if ( !class_exists($rclass) ) {
trigger_error("Unable to resolve render class $rclass",E_USER_ERROR);
}
$Renderer = & new $rclass(); #FIXME any way to check for class existance?
$Renderer->smileys = getSmileys();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment