Initial commit
This commit is contained in:
71
content/inc/parser/code.php
Normal file
71
content/inc/parser/code.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* A simple renderer that allows downloading of code and file snippets
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
class Doku_Renderer_code extends Doku_Renderer {
|
||||
protected $_codeblock = 0;
|
||||
|
||||
/**
|
||||
* Send the wanted code block to the browser
|
||||
*
|
||||
* When the correct block was found it exits the script.
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $language
|
||||
* @param string $filename
|
||||
*/
|
||||
public function code($text, $language = null, $filename = '') {
|
||||
global $INPUT;
|
||||
if(!$language) $language = 'txt';
|
||||
$language = preg_replace(PREG_PATTERN_VALID_LANGUAGE, '', $language);
|
||||
if(!$filename) $filename = 'snippet.'.$language;
|
||||
$filename = \dokuwiki\Utf8\PhpString::basename($filename);
|
||||
$filename = \dokuwiki\Utf8\Clean::stripspecials($filename, '_');
|
||||
|
||||
// send CRLF to Windows clients
|
||||
if(strpos($INPUT->server->str('HTTP_USER_AGENT'), 'Windows') !== false) {
|
||||
$text = str_replace("\n", "\r\n", $text);
|
||||
}
|
||||
|
||||
if($this->_codeblock == $INPUT->str('codeblock')) {
|
||||
header("Content-Type: text/plain; charset=utf-8");
|
||||
header("Content-Disposition: attachment; filename=$filename");
|
||||
header("X-Robots-Tag: noindex");
|
||||
echo trim($text, "\r\n");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->_codeblock++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps around code()
|
||||
*
|
||||
* @param string $text
|
||||
* @param string $language
|
||||
* @param string $filename
|
||||
*/
|
||||
public function file($text, $language = null, $filename = '') {
|
||||
$this->code($text, $language, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* This should never be reached, if it is send a 404
|
||||
*/
|
||||
public function document_end() {
|
||||
http_status(404);
|
||||
echo '404 - Not found';
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the format of the renderer
|
||||
*
|
||||
* @returns string 'code'
|
||||
*/
|
||||
public function getFormat() {
|
||||
return 'code';
|
||||
}
|
||||
}
|
1157
content/inc/parser/handler.php
Normal file
1157
content/inc/parser/handler.php
Normal file
File diff suppressed because it is too large
Load Diff
751
content/inc/parser/metadata.php
Normal file
751
content/inc/parser/metadata.php
Normal file
@@ -0,0 +1,751 @@
|
||||
<?php
|
||||
/**
|
||||
* The MetaData Renderer
|
||||
*
|
||||
* Metadata is additional information about a DokuWiki page that gets extracted mainly from the page's content
|
||||
* but also it's own filesystem data (like the creation time). All metadata is stored in the fields $meta and
|
||||
* $persistent.
|
||||
*
|
||||
* Some simplified rendering to $doc is done to gather the page's (text-only) abstract.
|
||||
*
|
||||
* @author Esther Brunner <wikidesign@gmail.com>
|
||||
*/
|
||||
class Doku_Renderer_metadata extends Doku_Renderer
|
||||
{
|
||||
/** the approximate byte lenght to capture for the abstract */
|
||||
const ABSTRACT_LEN = 250;
|
||||
|
||||
/** the maximum UTF8 character length for the abstract */
|
||||
const ABSTRACT_MAX = 500;
|
||||
|
||||
/** @var array transient meta data, will be reset on each rendering */
|
||||
public $meta = array();
|
||||
|
||||
/** @var array persistent meta data, will be kept until explicitly deleted */
|
||||
public $persistent = array();
|
||||
|
||||
/** @var array the list of headers used to create unique link ids */
|
||||
protected $headers = array();
|
||||
|
||||
/** @var string temporary $doc store */
|
||||
protected $store = '';
|
||||
|
||||
/** @var string keeps the first image reference */
|
||||
protected $firstimage = '';
|
||||
|
||||
/** @var bool whether or not data is being captured for the abstract, public to be accessible by plugins */
|
||||
public $capturing = true;
|
||||
|
||||
/** @var bool determines if enough data for the abstract was collected, yet */
|
||||
public $capture = true;
|
||||
|
||||
/** @var int number of bytes captured for abstract */
|
||||
protected $captured = 0;
|
||||
|
||||
/**
|
||||
* Returns the format produced by this renderer.
|
||||
*
|
||||
* @return string always 'metadata'
|
||||
*/
|
||||
public function getFormat()
|
||||
{
|
||||
return 'metadata';
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the document
|
||||
*
|
||||
* Sets up some of the persistent info about the page if it doesn't exist, yet.
|
||||
*/
|
||||
public function document_start()
|
||||
{
|
||||
global $ID;
|
||||
|
||||
$this->headers = array();
|
||||
|
||||
// external pages are missing create date
|
||||
if (!isset($this->persistent['date']['created']) || !$this->persistent['date']['created']) {
|
||||
$this->persistent['date']['created'] = filectime(wikiFN($ID));
|
||||
}
|
||||
if (!isset($this->persistent['user'])) {
|
||||
$this->persistent['user'] = '';
|
||||
}
|
||||
if (!isset($this->persistent['creator'])) {
|
||||
$this->persistent['creator'] = '';
|
||||
}
|
||||
// reset metadata to persistent values
|
||||
$this->meta = $this->persistent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the document
|
||||
*
|
||||
* Stores collected data in the metadata
|
||||
*/
|
||||
public function document_end()
|
||||
{
|
||||
global $ID;
|
||||
|
||||
// store internal info in metadata (notoc,nocache)
|
||||
$this->meta['internal'] = $this->info;
|
||||
|
||||
if (!isset($this->meta['description']['abstract'])) {
|
||||
// cut off too long abstracts
|
||||
$this->doc = trim($this->doc);
|
||||
if (strlen($this->doc) > self::ABSTRACT_MAX) {
|
||||
$this->doc = \dokuwiki\Utf8\PhpString::substr($this->doc, 0, self::ABSTRACT_MAX).'…';
|
||||
}
|
||||
$this->meta['description']['abstract'] = $this->doc;
|
||||
}
|
||||
|
||||
$this->meta['relation']['firstimage'] = $this->firstimage;
|
||||
|
||||
if (!isset($this->meta['date']['modified'])) {
|
||||
$this->meta['date']['modified'] = filemtime(wikiFN($ID));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render plain text data
|
||||
*
|
||||
* This function takes care of the amount captured data and will stop capturing when
|
||||
* enough abstract data is available
|
||||
*
|
||||
* @param $text
|
||||
*/
|
||||
public function cdata($text)
|
||||
{
|
||||
if (!$this->capture || !$this->capturing) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->doc .= $text;
|
||||
|
||||
$this->captured += strlen($text);
|
||||
if ($this->captured > self::ABSTRACT_LEN) {
|
||||
$this->capture = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the TOC
|
||||
*
|
||||
* @param string $id the hash link
|
||||
* @param string $text the text to display
|
||||
* @param int $level the nesting level
|
||||
*/
|
||||
public function toc_additem($id, $text, $level)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
//only add items within configured levels
|
||||
if ($level >= $conf['toptoclevel'] && $level <= $conf['maxtoclevel']) {
|
||||
// the TOC is one of our standard ul list arrays ;-)
|
||||
$this->meta['description']['tableofcontents'][] = array(
|
||||
'hid' => $id,
|
||||
'title' => $text,
|
||||
'type' => 'ul',
|
||||
'level' => $level - $conf['toptoclevel'] + 1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a heading
|
||||
*
|
||||
* @param string $text the text to display
|
||||
* @param int $level header level
|
||||
* @param int $pos byte position in the original source
|
||||
*/
|
||||
public function header($text, $level, $pos)
|
||||
{
|
||||
if (!isset($this->meta['title'])) {
|
||||
$this->meta['title'] = $text;
|
||||
}
|
||||
|
||||
// add the header to the TOC
|
||||
$hid = $this->_headerToLink($text, true);
|
||||
$this->toc_additem($hid, $text, $level);
|
||||
|
||||
// add to summary
|
||||
$this->cdata(DOKU_LF.$text.DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a paragraph
|
||||
*/
|
||||
public function p_open()
|
||||
{
|
||||
$this->cdata(DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a paragraph
|
||||
*/
|
||||
public function p_close()
|
||||
{
|
||||
$this->cdata(DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a line break
|
||||
*/
|
||||
public function linebreak()
|
||||
{
|
||||
$this->cdata(DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a horizontal line
|
||||
*/
|
||||
public function hr()
|
||||
{
|
||||
$this->cdata(DOKU_LF.'----------'.DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for footnote start syntax
|
||||
*
|
||||
* All following content will go to the footnote instead of
|
||||
* the document. To achieve this the previous rendered content
|
||||
* is moved to $store and $doc is cleared
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
public function footnote_open()
|
||||
{
|
||||
if ($this->capture) {
|
||||
// move current content to store
|
||||
// this is required to ensure safe behaviour of plugins accessed within footnotes
|
||||
$this->store = $this->doc;
|
||||
$this->doc = '';
|
||||
|
||||
// disable capturing
|
||||
$this->capturing = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for footnote end syntax
|
||||
*
|
||||
* All content rendered whilst within footnote syntax mode is discarded,
|
||||
* the previously rendered content is restored and capturing is re-enabled.
|
||||
*
|
||||
* @author Andreas Gohr
|
||||
*/
|
||||
public function footnote_close()
|
||||
{
|
||||
if ($this->capture) {
|
||||
// re-enable capturing
|
||||
$this->capturing = true;
|
||||
// restore previously rendered content
|
||||
$this->doc = $this->store;
|
||||
$this->store = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an unordered list
|
||||
*/
|
||||
public function listu_open()
|
||||
{
|
||||
$this->cdata(DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an ordered list
|
||||
*/
|
||||
public function listo_open()
|
||||
{
|
||||
$this->cdata(DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a list item
|
||||
*
|
||||
* @param int $level the nesting level
|
||||
* @param bool $node true when a node; false when a leaf
|
||||
*/
|
||||
public function listitem_open($level, $node=false)
|
||||
{
|
||||
$this->cdata(str_repeat(DOKU_TAB, $level).'* ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a list item
|
||||
*/
|
||||
public function listitem_close()
|
||||
{
|
||||
$this->cdata(DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output preformatted text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function preformatted($text)
|
||||
{
|
||||
$this->cdata($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a block quote
|
||||
*/
|
||||
public function quote_open()
|
||||
{
|
||||
$this->cdata(DOKU_LF.DOKU_TAB.'"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a block quote
|
||||
*/
|
||||
public function quote_close()
|
||||
{
|
||||
$this->cdata('"'.DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display text as file content, optionally syntax highlighted
|
||||
*
|
||||
* @param string $text text to show
|
||||
* @param string $lang programming language to use for syntax highlighting
|
||||
* @param string $file file path label
|
||||
*/
|
||||
public function file($text, $lang = null, $file = null)
|
||||
{
|
||||
$this->cdata(DOKU_LF.$text.DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display text as code content, optionally syntax highlighted
|
||||
*
|
||||
* @param string $text text to show
|
||||
* @param string $language programming language to use for syntax highlighting
|
||||
* @param string $file file path label
|
||||
*/
|
||||
public function code($text, $language = null, $file = null)
|
||||
{
|
||||
$this->cdata(DOKU_LF.$text.DOKU_LF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an acronym
|
||||
*
|
||||
* Uses $this->acronyms
|
||||
*
|
||||
* @param string $acronym
|
||||
*/
|
||||
public function acronym($acronym)
|
||||
{
|
||||
$this->cdata($acronym);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a smiley
|
||||
*
|
||||
* Uses $this->smiley
|
||||
*
|
||||
* @param string $smiley
|
||||
*/
|
||||
public function smiley($smiley)
|
||||
{
|
||||
$this->cdata($smiley);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an entity
|
||||
*
|
||||
* Entities are basically small text replacements
|
||||
*
|
||||
* Uses $this->entities
|
||||
*
|
||||
* @param string $entity
|
||||
*/
|
||||
public function entity($entity)
|
||||
{
|
||||
$this->cdata($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Typographically format a multiply sign
|
||||
*
|
||||
* Example: ($x=640, $y=480) should result in "640×480"
|
||||
*
|
||||
* @param string|int $x first value
|
||||
* @param string|int $y second value
|
||||
*/
|
||||
public function multiplyentity($x, $y)
|
||||
{
|
||||
$this->cdata($x.'×'.$y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an opening single quote char (language specific)
|
||||
*/
|
||||
public function singlequoteopening()
|
||||
{
|
||||
global $lang;
|
||||
$this->cdata($lang['singlequoteopening']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a closing single quote char (language specific)
|
||||
*/
|
||||
public function singlequoteclosing()
|
||||
{
|
||||
global $lang;
|
||||
$this->cdata($lang['singlequoteclosing']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an apostrophe char (language specific)
|
||||
*/
|
||||
public function apostrophe()
|
||||
{
|
||||
global $lang;
|
||||
$this->cdata($lang['apostrophe']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an opening double quote char (language specific)
|
||||
*/
|
||||
public function doublequoteopening()
|
||||
{
|
||||
global $lang;
|
||||
$this->cdata($lang['doublequoteopening']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an closinging double quote char (language specific)
|
||||
*/
|
||||
public function doublequoteclosing()
|
||||
{
|
||||
global $lang;
|
||||
$this->cdata($lang['doublequoteclosing']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a CamelCase link
|
||||
*
|
||||
* @param string $link The link name
|
||||
* @see http://en.wikipedia.org/wiki/CamelCase
|
||||
*/
|
||||
public function camelcaselink($link)
|
||||
{
|
||||
$this->internallink($link, $link);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a page local link
|
||||
*
|
||||
* @param string $hash hash link identifier
|
||||
* @param string $name name for the link
|
||||
*/
|
||||
public function locallink($hash, $name = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->_firstimage($name['src']);
|
||||
if ($name['type'] == 'internalmedia') {
|
||||
$this->_recordMediaUsage($name['src']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* keep track of internal links in $this->meta['relation']['references']
|
||||
*
|
||||
* @param string $id page ID to link to. eg. 'wiki:syntax'
|
||||
* @param string|array|null $name name for the link, array for media file
|
||||
*/
|
||||
public function internallink($id, $name = null)
|
||||
{
|
||||
global $ID;
|
||||
|
||||
if (is_array($name)) {
|
||||
$this->_firstimage($name['src']);
|
||||
if ($name['type'] == 'internalmedia') {
|
||||
$this->_recordMediaUsage($name['src']);
|
||||
}
|
||||
}
|
||||
|
||||
$parts = explode('?', $id, 2);
|
||||
if (count($parts) === 2) {
|
||||
$id = $parts[0];
|
||||
}
|
||||
|
||||
$default = $this->_simpleTitle($id);
|
||||
|
||||
// first resolve and clean up the $id
|
||||
resolve_pageid(getNS($ID), $id, $exists);
|
||||
@list($page) = explode('#', $id, 2);
|
||||
|
||||
// set metadata
|
||||
$this->meta['relation']['references'][$page] = $exists;
|
||||
// $data = array('relation' => array('isreferencedby' => array($ID => true)));
|
||||
// p_set_metadata($id, $data);
|
||||
|
||||
// add link title to summary
|
||||
if ($this->capture) {
|
||||
$name = $this->_getLinkTitle($name, $default, $id);
|
||||
$this->doc .= $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an external link
|
||||
*
|
||||
* @param string $url full URL with scheme
|
||||
* @param string|array|null $name name for the link, array for media file
|
||||
*/
|
||||
public function externallink($url, $name = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->_firstimage($name['src']);
|
||||
if ($name['type'] == 'internalmedia') {
|
||||
$this->_recordMediaUsage($name['src']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->capture) {
|
||||
$this->doc .= $this->_getLinkTitle($name, '<'.$url.'>');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an interwiki link
|
||||
*
|
||||
* You may want to use $this->_resolveInterWiki() here
|
||||
*
|
||||
* @param string $match original link - probably not much use
|
||||
* @param string|array $name name for the link, array for media file
|
||||
* @param string $wikiName indentifier (shortcut) for the remote wiki
|
||||
* @param string $wikiUri the fragment parsed from the original link
|
||||
*/
|
||||
public function interwikilink($match, $name, $wikiName, $wikiUri)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->_firstimage($name['src']);
|
||||
if ($name['type'] == 'internalmedia') {
|
||||
$this->_recordMediaUsage($name['src']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->capture) {
|
||||
list($wikiUri) = explode('#', $wikiUri, 2);
|
||||
$name = $this->_getLinkTitle($name, $wikiUri);
|
||||
$this->doc .= $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to windows share
|
||||
*
|
||||
* @param string $url the link
|
||||
* @param string|array $name name for the link, array for media file
|
||||
*/
|
||||
public function windowssharelink($url, $name = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->_firstimage($name['src']);
|
||||
if ($name['type'] == 'internalmedia') {
|
||||
$this->_recordMediaUsage($name['src']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->capture) {
|
||||
if ($name) {
|
||||
$this->doc .= $name;
|
||||
} else {
|
||||
$this->doc .= '<'.$url.'>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a linked E-Mail Address
|
||||
*
|
||||
* Should honor $conf['mailguard'] setting
|
||||
*
|
||||
* @param string $address Email-Address
|
||||
* @param string|array $name name for the link, array for media file
|
||||
*/
|
||||
public function emaillink($address, $name = null)
|
||||
{
|
||||
if (is_array($name)) {
|
||||
$this->_firstimage($name['src']);
|
||||
if ($name['type'] == 'internalmedia') {
|
||||
$this->_recordMediaUsage($name['src']);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->capture) {
|
||||
if ($name) {
|
||||
$this->doc .= $name;
|
||||
} else {
|
||||
$this->doc .= '<'.$address.'>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an internal media file
|
||||
*
|
||||
* @param string $src media ID
|
||||
* @param string $title descriptive text
|
||||
* @param string $align left|center|right
|
||||
* @param int $width width of media in pixel
|
||||
* @param int $height height of media in pixel
|
||||
* @param string $cache cache|recache|nocache
|
||||
* @param string $linking linkonly|detail|nolink
|
||||
*/
|
||||
public function internalmedia($src, $title = null, $align = null, $width = null,
|
||||
$height = null, $cache = null, $linking = null)
|
||||
{
|
||||
if ($this->capture && $title) {
|
||||
$this->doc .= '['.$title.']';
|
||||
}
|
||||
$this->_firstimage($src);
|
||||
$this->_recordMediaUsage($src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an external media file
|
||||
*
|
||||
* @param string $src full media URL
|
||||
* @param string $title descriptive text
|
||||
* @param string $align left|center|right
|
||||
* @param int $width width of media in pixel
|
||||
* @param int $height height of media in pixel
|
||||
* @param string $cache cache|recache|nocache
|
||||
* @param string $linking linkonly|detail|nolink
|
||||
*/
|
||||
public function externalmedia($src, $title = null, $align = null, $width = null,
|
||||
$height = null, $cache = null, $linking = null)
|
||||
{
|
||||
if ($this->capture && $title) {
|
||||
$this->doc .= '['.$title.']';
|
||||
}
|
||||
$this->_firstimage($src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the output of an RSS feed
|
||||
*
|
||||
* @param string $url URL of the feed
|
||||
* @param array $params Finetuning of the output
|
||||
*/
|
||||
public function rss($url, $params)
|
||||
{
|
||||
$this->meta['relation']['haspart'][$url] = true;
|
||||
|
||||
$this->meta['date']['valid']['age'] =
|
||||
isset($this->meta['date']['valid']['age']) ?
|
||||
min($this->meta['date']['valid']['age'], $params['refresh']) :
|
||||
$params['refresh'];
|
||||
}
|
||||
|
||||
#region Utils
|
||||
|
||||
/**
|
||||
* Removes any Namespace from the given name but keeps
|
||||
* casing and special chars
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return mixed|string
|
||||
*/
|
||||
public function _simpleTitle($name)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (is_array($name)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($conf['useslash']) {
|
||||
$nssep = '[:;/]';
|
||||
} else {
|
||||
$nssep = '[:;]';
|
||||
}
|
||||
$name = preg_replace('!.*'.$nssep.'!', '', $name);
|
||||
//if there is a hash we use the anchor name only
|
||||
$name = preg_replace('!.*#!', '', $name);
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a title and handle images in titles
|
||||
*
|
||||
* @author Harry Fuecks <hfuecks@gmail.com>
|
||||
* @param string|array|null $title either string title or media array
|
||||
* @param string $default default title if nothing else is found
|
||||
* @param null|string $id linked page id (used to extract title from first heading)
|
||||
* @return string title text
|
||||
*/
|
||||
public function _getLinkTitle($title, $default, $id = null)
|
||||
{
|
||||
if (is_array($title)) {
|
||||
if ($title['title']) {
|
||||
return '['.$title['title'].']';
|
||||
} else {
|
||||
return $default;
|
||||
}
|
||||
} elseif (is_null($title) || trim($title) == '') {
|
||||
if (useHeading('content') && $id) {
|
||||
$heading = p_get_first_heading($id, METADATA_DONT_RENDER);
|
||||
if ($heading) {
|
||||
return $heading;
|
||||
}
|
||||
}
|
||||
return $default;
|
||||
} else {
|
||||
return $title;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remember first image
|
||||
*
|
||||
* @param string $src image URL or ID
|
||||
*/
|
||||
protected function _firstimage($src)
|
||||
{
|
||||
global $ID;
|
||||
|
||||
if ($this->firstimage) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($src) = explode('#', $src, 2);
|
||||
if (!media_isexternal($src)) {
|
||||
resolve_mediaid(getNS($ID), $src, $exists);
|
||||
}
|
||||
if (preg_match('/.(jpe?g|gif|png)$/i', $src)) {
|
||||
$this->firstimage = $src;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store list of used media files in metadata
|
||||
*
|
||||
* @param string $src media ID
|
||||
*/
|
||||
protected function _recordMediaUsage($src)
|
||||
{
|
||||
global $ID;
|
||||
|
||||
list ($src) = explode('#', $src, 2);
|
||||
if (media_isexternal($src)) {
|
||||
return;
|
||||
}
|
||||
resolve_mediaid(getNS($ID), $src, $exists);
|
||||
$this->meta['relation']['media'][$src] = $exists;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
99
content/inc/parser/parser.php
Normal file
99
content/inc/parser/parser.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
use dokuwiki\Debug\PropertyDeprecationHelper;
|
||||
|
||||
/**
|
||||
* Define various types of modes used by the parser - they are used to
|
||||
* populate the list of modes another mode accepts
|
||||
*/
|
||||
global $PARSER_MODES;
|
||||
$PARSER_MODES = array(
|
||||
// containers are complex modes that can contain many other modes
|
||||
// hr breaks the principle but they shouldn't be used in tables / lists
|
||||
// so they are put here
|
||||
'container' => array('listblock', 'table', 'quote', 'hr'),
|
||||
|
||||
// some mode are allowed inside the base mode only
|
||||
'baseonly' => array('header'),
|
||||
|
||||
// modes for styling text -- footnote behaves similar to styling
|
||||
'formatting' => array(
|
||||
'strong', 'emphasis', 'underline', 'monospace',
|
||||
'subscript', 'superscript', 'deleted', 'footnote'
|
||||
),
|
||||
|
||||
// modes where the token is simply replaced - they can not contain any
|
||||
// other modes
|
||||
'substition' => array(
|
||||
'acronym', 'smiley', 'wordblock', 'entity',
|
||||
'camelcaselink', 'internallink', 'media',
|
||||
'externallink', 'linebreak', 'emaillink',
|
||||
'windowssharelink', 'filelink', 'notoc',
|
||||
'nocache', 'multiplyentity', 'quotes', 'rss'
|
||||
),
|
||||
|
||||
// modes which have a start and end token but inside which
|
||||
// no other modes should be applied
|
||||
'protected' => array('preformatted', 'code', 'file', 'php', 'html', 'htmlblock', 'phpblock'),
|
||||
|
||||
// inside this mode no wiki markup should be applied but lineendings
|
||||
// and whitespace isn't preserved
|
||||
'disabled' => array('unformatted'),
|
||||
|
||||
// used to mark paragraph boundaries
|
||||
'paragraphs' => array('eol')
|
||||
);
|
||||
|
||||
/**
|
||||
* Class Doku_Parser
|
||||
*
|
||||
* @deprecated 2018-05-04
|
||||
*/
|
||||
class Doku_Parser extends \dokuwiki\Parsing\Parser {
|
||||
use PropertyDeprecationHelper {
|
||||
__set as protected deprecationHelperMagicSet;
|
||||
__get as protected deprecationHelperMagicGet;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function __construct(Doku_Handler $handler = null) {
|
||||
dbg_deprecated(\dokuwiki\Parsing\Parser::class);
|
||||
$this->deprecatePublicProperty('modes', __CLASS__);
|
||||
$this->deprecatePublicProperty('connected', __CLASS__);
|
||||
|
||||
if ($handler === null) {
|
||||
$handler = new Doku_Handler();
|
||||
}
|
||||
|
||||
parent::__construct($handler);
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
{
|
||||
|
||||
if ($name === 'Handler') {
|
||||
$this->handler = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($name === 'Lexer') {
|
||||
$this->lexer = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->deprecationHelperMagicSet($name, $value);
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
if ($name === 'Handler') {
|
||||
return $this->handler;
|
||||
}
|
||||
|
||||
if ($name === 'Lexer') {
|
||||
return $this->lexer;
|
||||
}
|
||||
|
||||
return $this->deprecationHelperMagicGet($name);
|
||||
}
|
||||
}
|
910
content/inc/parser/renderer.php
Normal file
910
content/inc/parser/renderer.php
Normal file
@@ -0,0 +1,910 @@
|
||||
<?php
|
||||
/**
|
||||
* Renderer output base class
|
||||
*
|
||||
* @author Harry Fuecks <hfuecks@gmail.com>
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*/
|
||||
|
||||
use dokuwiki\Extension\Plugin;
|
||||
use dokuwiki\Extension\SyntaxPlugin;
|
||||
|
||||
/**
|
||||
* Allowed chars in $language for code highlighting
|
||||
* @see GeSHi::set_language()
|
||||
*/
|
||||
define('PREG_PATTERN_VALID_LANGUAGE', '#[^a-zA-Z0-9\-_]#');
|
||||
|
||||
/**
|
||||
* An empty renderer, produces no output
|
||||
*
|
||||
* Inherits from dokuwiki\Plugin\DokuWiki_Plugin for giving additional functions to render plugins
|
||||
*
|
||||
* The renderer transforms the syntax instructions created by the parser and handler into the
|
||||
* desired output format. For each instruction a corresponding method defined in this class will
|
||||
* be called. That method needs to produce the desired output for the instruction and add it to the
|
||||
* $doc field. When all instructions are processed, the $doc field contents will be cached by
|
||||
* DokuWiki and sent to the user.
|
||||
*/
|
||||
abstract class Doku_Renderer extends Plugin {
|
||||
/** @var array Settings, control the behavior of the renderer */
|
||||
public $info = array(
|
||||
'cache' => true, // may the rendered result cached?
|
||||
'toc' => true, // render the TOC?
|
||||
);
|
||||
|
||||
/** @var array contains the smiley configuration, set in p_render() */
|
||||
public $smileys = array();
|
||||
/** @var array contains the entity configuration, set in p_render() */
|
||||
public $entities = array();
|
||||
/** @var array contains the acronym configuration, set in p_render() */
|
||||
public $acronyms = array();
|
||||
/** @var array contains the interwiki configuration, set in p_render() */
|
||||
public $interwiki = array();
|
||||
|
||||
/** @var array the list of headers used to create unique link ids */
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* @var string the rendered document, this will be cached after the renderer ran through
|
||||
*/
|
||||
public $doc = '';
|
||||
|
||||
/**
|
||||
* clean out any per-use values
|
||||
*
|
||||
* This is called before each use of the renderer object and should be used to
|
||||
* completely reset the state of the renderer to be reused for a new document
|
||||
*/
|
||||
public function reset(){
|
||||
$this->headers = array();
|
||||
$this->doc = '';
|
||||
$this->info['cache'] = true;
|
||||
$this->info['toc'] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the plugin to prevent DokuWiki from reusing an instance
|
||||
*
|
||||
* Since most renderer plugins fail to implement Doku_Renderer::reset() we default
|
||||
* to reinstantiating the renderer here
|
||||
*
|
||||
* @return bool false if the plugin has to be instantiated
|
||||
*/
|
||||
public function isSingleton() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the format produced by this renderer.
|
||||
*
|
||||
* Has to be overidden by sub classes
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getFormat();
|
||||
|
||||
/**
|
||||
* Disable caching of this renderer's output
|
||||
*/
|
||||
public function nocache() {
|
||||
$this->info['cache'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable TOC generation for this renderer's output
|
||||
*
|
||||
* This might not be used for certain sub renderer
|
||||
*/
|
||||
public function notoc() {
|
||||
$this->info['toc'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle plugin rendering
|
||||
*
|
||||
* Most likely this needs NOT to be overwritten by sub classes
|
||||
*
|
||||
* @param string $name Plugin name
|
||||
* @param mixed $data custom data set by handler
|
||||
* @param string $state matched state if any
|
||||
* @param string $match raw matched syntax
|
||||
*/
|
||||
public function plugin($name, $data, $state = '', $match = '') {
|
||||
/** @var SyntaxPlugin $plugin */
|
||||
$plugin = plugin_load('syntax', $name);
|
||||
if($plugin != null) {
|
||||
$plugin->render($this->getFormat(), $this, $data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* handle nested render instructions
|
||||
* this method (and nest_close method) should not be overloaded in actual renderer output classes
|
||||
*
|
||||
* @param array $instructions
|
||||
*/
|
||||
public function nest($instructions) {
|
||||
foreach($instructions as $instruction) {
|
||||
// execute the callback against ourself
|
||||
if(method_exists($this, $instruction[0])) {
|
||||
call_user_func_array(array($this, $instruction[0]), $instruction[1] ? $instruction[1] : array());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* dummy closing instruction issued by Doku_Handler_Nest
|
||||
*
|
||||
* normally the syntax mode should override this instruction when instantiating Doku_Handler_Nest -
|
||||
* however plugins will not be able to - as their instructions require data.
|
||||
*/
|
||||
public function nest_close() {
|
||||
}
|
||||
|
||||
#region Syntax modes - sub classes will need to implement them to fill $doc
|
||||
|
||||
/**
|
||||
* Initialize the document
|
||||
*/
|
||||
public function document_start() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize the document
|
||||
*/
|
||||
public function document_end() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the Table of Contents
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render_TOC() {
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an item to the TOC
|
||||
*
|
||||
* @param string $id the hash link
|
||||
* @param string $text the text to display
|
||||
* @param int $level the nesting level
|
||||
*/
|
||||
public function toc_additem($id, $text, $level) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a heading
|
||||
*
|
||||
* @param string $text the text to display
|
||||
* @param int $level header level
|
||||
* @param int $pos byte position in the original source
|
||||
*/
|
||||
public function header($text, $level, $pos) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a new section
|
||||
*
|
||||
* @param int $level section level (as determined by the previous header)
|
||||
*/
|
||||
public function section_open($level) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the current section
|
||||
*/
|
||||
public function section_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render plain text data
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function cdata($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a paragraph
|
||||
*/
|
||||
public function p_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a paragraph
|
||||
*/
|
||||
public function p_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a line break
|
||||
*/
|
||||
public function linebreak() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a horizontal line
|
||||
*/
|
||||
public function hr() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start strong (bold) formatting
|
||||
*/
|
||||
public function strong_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop strong (bold) formatting
|
||||
*/
|
||||
public function strong_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start emphasis (italics) formatting
|
||||
*/
|
||||
public function emphasis_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop emphasis (italics) formatting
|
||||
*/
|
||||
public function emphasis_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start underline formatting
|
||||
*/
|
||||
public function underline_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop underline formatting
|
||||
*/
|
||||
public function underline_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start monospace formatting
|
||||
*/
|
||||
public function monospace_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop monospace formatting
|
||||
*/
|
||||
public function monospace_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a subscript
|
||||
*/
|
||||
public function subscript_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a subscript
|
||||
*/
|
||||
public function subscript_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a superscript
|
||||
*/
|
||||
public function superscript_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a superscript
|
||||
*/
|
||||
public function superscript_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start deleted (strike-through) formatting
|
||||
*/
|
||||
public function deleted_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop deleted (strike-through) formatting
|
||||
*/
|
||||
public function deleted_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a footnote
|
||||
*/
|
||||
public function footnote_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a footnote
|
||||
*/
|
||||
public function footnote_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an unordered list
|
||||
*/
|
||||
public function listu_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an unordered list
|
||||
*/
|
||||
public function listu_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open an ordered list
|
||||
*/
|
||||
public function listo_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an ordered list
|
||||
*/
|
||||
public function listo_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a list item
|
||||
*
|
||||
* @param int $level the nesting level
|
||||
* @param bool $node true when a node; false when a leaf
|
||||
*/
|
||||
public function listitem_open($level,$node=false) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a list item
|
||||
*/
|
||||
public function listitem_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the content of a list item
|
||||
*/
|
||||
public function listcontent_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the content of a list item
|
||||
*/
|
||||
public function listcontent_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Output unformatted $text
|
||||
*
|
||||
* Defaults to $this->cdata()
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function unformatted($text) {
|
||||
$this->cdata($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output inline PHP code
|
||||
*
|
||||
* If $conf['phpok'] is true this should evaluate the given code and append the result
|
||||
* to $doc
|
||||
*
|
||||
* @param string $text The PHP code
|
||||
*/
|
||||
public function php($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Output block level PHP code
|
||||
*
|
||||
* If $conf['phpok'] is true this should evaluate the given code and append the result
|
||||
* to $doc
|
||||
*
|
||||
* @param string $text The PHP code
|
||||
*/
|
||||
public function phpblock($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Output raw inline HTML
|
||||
*
|
||||
* If $conf['htmlok'] is true this should add the code as is to $doc
|
||||
*
|
||||
* @param string $text The HTML
|
||||
*/
|
||||
public function html($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Output raw block-level HTML
|
||||
*
|
||||
* If $conf['htmlok'] is true this should add the code as is to $doc
|
||||
*
|
||||
* @param string $text The HTML
|
||||
*/
|
||||
public function htmlblock($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Output preformatted text
|
||||
*
|
||||
* @param string $text
|
||||
*/
|
||||
public function preformatted($text) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a block quote
|
||||
*/
|
||||
public function quote_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop a block quote
|
||||
*/
|
||||
public function quote_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display text as file content, optionally syntax highlighted
|
||||
*
|
||||
* @param string $text text to show
|
||||
* @param string $lang programming language to use for syntax highlighting
|
||||
* @param string $file file path label
|
||||
*/
|
||||
public function file($text, $lang = null, $file = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Display text as code content, optionally syntax highlighted
|
||||
*
|
||||
* @param string $text text to show
|
||||
* @param string $lang programming language to use for syntax highlighting
|
||||
* @param string $file file path label
|
||||
*/
|
||||
public function code($text, $lang = null, $file = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an acronym
|
||||
*
|
||||
* Uses $this->acronyms
|
||||
*
|
||||
* @param string $acronym
|
||||
*/
|
||||
public function acronym($acronym) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a smiley
|
||||
*
|
||||
* Uses $this->smiley
|
||||
*
|
||||
* @param string $smiley
|
||||
*/
|
||||
public function smiley($smiley) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an entity
|
||||
*
|
||||
* Entities are basically small text replacements
|
||||
*
|
||||
* Uses $this->entities
|
||||
*
|
||||
* @param string $entity
|
||||
*/
|
||||
public function entity($entity) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Typographically format a multiply sign
|
||||
*
|
||||
* Example: ($x=640, $y=480) should result in "640×480"
|
||||
*
|
||||
* @param string|int $x first value
|
||||
* @param string|int $y second value
|
||||
*/
|
||||
public function multiplyentity($x, $y) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an opening single quote char (language specific)
|
||||
*/
|
||||
public function singlequoteopening() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a closing single quote char (language specific)
|
||||
*/
|
||||
public function singlequoteclosing() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an apostrophe char (language specific)
|
||||
*/
|
||||
public function apostrophe() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an opening double quote char (language specific)
|
||||
*/
|
||||
public function doublequoteopening() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an closinging double quote char (language specific)
|
||||
*/
|
||||
public function doublequoteclosing() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a CamelCase link
|
||||
*
|
||||
* @param string $link The link name
|
||||
* @see http://en.wikipedia.org/wiki/CamelCase
|
||||
*/
|
||||
public function camelcaselink($link) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a page local link
|
||||
*
|
||||
* @param string $hash hash link identifier
|
||||
* @param string $name name for the link
|
||||
*/
|
||||
public function locallink($hash, $name = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a wiki internal link
|
||||
*
|
||||
* @param string $link page ID to link to. eg. 'wiki:syntax'
|
||||
* @param string|array $title name for the link, array for media file
|
||||
*/
|
||||
public function internallink($link, $title = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an external link
|
||||
*
|
||||
* @param string $link full URL with scheme
|
||||
* @param string|array $title name for the link, array for media file
|
||||
*/
|
||||
public function externallink($link, $title = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the output of an RSS feed
|
||||
*
|
||||
* @param string $url URL of the feed
|
||||
* @param array $params Finetuning of the output
|
||||
*/
|
||||
public function rss($url, $params) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an interwiki link
|
||||
*
|
||||
* You may want to use $this->_resolveInterWiki() here
|
||||
*
|
||||
* @param string $link original link - probably not much use
|
||||
* @param string|array $title name for the link, array for media file
|
||||
* @param string $wikiName indentifier (shortcut) for the remote wiki
|
||||
* @param string $wikiUri the fragment parsed from the original link
|
||||
*/
|
||||
public function interwikilink($link, $title, $wikiName, $wikiUri) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to file on users OS
|
||||
*
|
||||
* @param string $link the link
|
||||
* @param string|array $title name for the link, array for media file
|
||||
*/
|
||||
public function filelink($link, $title = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to windows share
|
||||
*
|
||||
* @param string $link the link
|
||||
* @param string|array $title name for the link, array for media file
|
||||
*/
|
||||
public function windowssharelink($link, $title = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a linked E-Mail Address
|
||||
*
|
||||
* Should honor $conf['mailguard'] setting
|
||||
*
|
||||
* @param string $address Email-Address
|
||||
* @param string|array $name name for the link, array for media file
|
||||
*/
|
||||
public function emaillink($address, $name = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an internal media file
|
||||
*
|
||||
* @param string $src media ID
|
||||
* @param string $title descriptive text
|
||||
* @param string $align left|center|right
|
||||
* @param int $width width of media in pixel
|
||||
* @param int $height height of media in pixel
|
||||
* @param string $cache cache|recache|nocache
|
||||
* @param string $linking linkonly|detail|nolink
|
||||
*/
|
||||
public function internalmedia($src, $title = null, $align = null, $width = null,
|
||||
$height = null, $cache = null, $linking = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render an external media file
|
||||
*
|
||||
* @param string $src full media URL
|
||||
* @param string $title descriptive text
|
||||
* @param string $align left|center|right
|
||||
* @param int $width width of media in pixel
|
||||
* @param int $height height of media in pixel
|
||||
* @param string $cache cache|recache|nocache
|
||||
* @param string $linking linkonly|detail|nolink
|
||||
*/
|
||||
public function externalmedia($src, $title = null, $align = null, $width = null,
|
||||
$height = null, $cache = null, $linking = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a link to an internal media file
|
||||
*
|
||||
* @param string $src media ID
|
||||
* @param string $title descriptive text
|
||||
* @param string $align left|center|right
|
||||
* @param int $width width of media in pixel
|
||||
* @param int $height height of media in pixel
|
||||
* @param string $cache cache|recache|nocache
|
||||
*/
|
||||
public function internalmedialink($src, $title = null, $align = null,
|
||||
$width = null, $height = null, $cache = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a link to an external media file
|
||||
*
|
||||
* @param string $src media ID
|
||||
* @param string $title descriptive text
|
||||
* @param string $align left|center|right
|
||||
* @param int $width width of media in pixel
|
||||
* @param int $height height of media in pixel
|
||||
* @param string $cache cache|recache|nocache
|
||||
*/
|
||||
public function externalmedialink($src, $title = null, $align = null,
|
||||
$width = null, $height = null, $cache = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Start a table
|
||||
*
|
||||
* @param int $maxcols maximum number of columns
|
||||
* @param int $numrows NOT IMPLEMENTED
|
||||
* @param int $pos byte position in the original source
|
||||
*/
|
||||
public function table_open($maxcols = null, $numrows = null, $pos = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table
|
||||
*
|
||||
* @param int $pos byte position in the original source
|
||||
*/
|
||||
public function table_close($pos = null) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a table header
|
||||
*/
|
||||
public function tablethead_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table header
|
||||
*/
|
||||
public function tablethead_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a table body
|
||||
*/
|
||||
public function tabletbody_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table body
|
||||
*/
|
||||
public function tabletbody_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a table footer
|
||||
*/
|
||||
public function tabletfoot_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table footer
|
||||
*/
|
||||
public function tabletfoot_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a table row
|
||||
*/
|
||||
public function tablerow_open() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table row
|
||||
*/
|
||||
public function tablerow_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a table header cell
|
||||
*
|
||||
* @param int $colspan
|
||||
* @param string $align left|center|right
|
||||
* @param int $rowspan
|
||||
*/
|
||||
public function tableheader_open($colspan = 1, $align = null, $rowspan = 1) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table header cell
|
||||
*/
|
||||
public function tableheader_close() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a table cell
|
||||
*
|
||||
* @param int $colspan
|
||||
* @param string $align left|center|right
|
||||
* @param int $rowspan
|
||||
*/
|
||||
public function tablecell_open($colspan = 1, $align = null, $rowspan = 1) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a table cell
|
||||
*/
|
||||
public function tablecell_close() {
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region util functions, you probably won't need to reimplement them
|
||||
|
||||
/**
|
||||
* Creates a linkid from a headline
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
* @param string $title The headline title
|
||||
* @param boolean $create Create a new unique ID?
|
||||
* @return string
|
||||
*/
|
||||
public function _headerToLink($title, $create = false) {
|
||||
if($create) {
|
||||
return sectionID($title, $this->headers);
|
||||
} else {
|
||||
$check = false;
|
||||
return sectionID($title, $check);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes any Namespace from the given name but keeps
|
||||
* casing and special chars
|
||||
*
|
||||
* @author Andreas Gohr <andi@splitbrain.org>
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
public function _simpleTitle($name) {
|
||||
global $conf;
|
||||
|
||||
//if there is a hash we use the ancor name only
|
||||
@list($name, $hash) = explode('#', $name, 2);
|
||||
if($hash) return $hash;
|
||||
|
||||
if($conf['useslash']) {
|
||||
$name = strtr($name, ';/', ';:');
|
||||
} else {
|
||||
$name = strtr($name, ';', ':');
|
||||
}
|
||||
|
||||
return noNSorNS($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve an interwikilink
|
||||
*
|
||||
* @param string $shortcut identifier for the interwiki link
|
||||
* @param string $reference fragment that refers the content
|
||||
* @param null|bool $exists reference which returns if an internal page exists
|
||||
* @return string interwikilink
|
||||
*/
|
||||
public function _resolveInterWiki(&$shortcut, $reference, &$exists = null) {
|
||||
//get interwiki URL
|
||||
if(isset($this->interwiki[$shortcut])) {
|
||||
$url = $this->interwiki[$shortcut];
|
||||
}elseif(isset($this->interwiki['default'])) {
|
||||
$shortcut = 'default';
|
||||
$url = $this->interwiki[$shortcut];
|
||||
}else{
|
||||
// not parsable interwiki outputs '' to make sure string manipluation works
|
||||
$shortcut = '';
|
||||
$url = '';
|
||||
}
|
||||
|
||||
//split into hash and url part
|
||||
$hash = strrchr($reference, '#');
|
||||
if($hash) {
|
||||
$reference = substr($reference, 0, -strlen($hash));
|
||||
$hash = substr($hash, 1);
|
||||
}
|
||||
|
||||
//replace placeholder
|
||||
if(preg_match('#\{(URL|NAME|SCHEME|HOST|PORT|PATH|QUERY)\}#', $url)) {
|
||||
//use placeholders
|
||||
$url = str_replace('{URL}', rawurlencode($reference), $url);
|
||||
//wiki names will be cleaned next, otherwise urlencode unsafe chars
|
||||
$url = str_replace('{NAME}', ($url[0] === ':') ? $reference :
|
||||
preg_replace_callback('/[[\\\\\]^`{|}#%]/', function($match) {
|
||||
return rawurlencode($match[0]);
|
||||
}, $reference), $url);
|
||||
$parsed = parse_url($reference);
|
||||
if (empty($parsed['scheme'])) $parsed['scheme'] = '';
|
||||
if (empty($parsed['host'])) $parsed['host'] = '';
|
||||
if (empty($parsed['port'])) $parsed['port'] = 80;
|
||||
if (empty($parsed['path'])) $parsed['path'] = '';
|
||||
if (empty($parsed['query'])) $parsed['query'] = '';
|
||||
$url = strtr($url,[
|
||||
'{SCHEME}' => $parsed['scheme'],
|
||||
'{HOST}' => $parsed['host'],
|
||||
'{PORT}' => $parsed['port'],
|
||||
'{PATH}' => $parsed['path'],
|
||||
'{QUERY}' => $parsed['query'] ,
|
||||
]);
|
||||
} else if($url != '') {
|
||||
// make sure when no url is defined, we keep it null
|
||||
// default
|
||||
$url = $url.rawurlencode($reference);
|
||||
}
|
||||
//handle as wiki links
|
||||
if($url[0] === ':') {
|
||||
$urlparam = null;
|
||||
$id = $url;
|
||||
if (strpos($url, '?') !== false) {
|
||||
list($id, $urlparam) = explode('?', $url, 2);
|
||||
}
|
||||
$url = wl(cleanID($id), $urlparam);
|
||||
$exists = page_exists($id);
|
||||
}
|
||||
if($hash) $url .= '#'.rawurlencode($hash);
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
//Setup VIM: ex: et ts=4 :
|
1999
content/inc/parser/xhtml.php
Normal file
1999
content/inc/parser/xhtml.php
Normal file
File diff suppressed because it is too large
Load Diff
84
content/inc/parser/xhtmlsummary.php
Normal file
84
content/inc/parser/xhtmlsummary.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?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.
|
||||
*
|
||||
*
|
||||
* @author Harry Fuecks <hfuecks@gmail.com>
|
||||
* @todo Is this currently used anywhere? Should it?
|
||||
*/
|
||||
class Doku_Renderer_xhtmlsummary extends Doku_Renderer_xhtml {
|
||||
|
||||
// Namespace these variables to
|
||||
// avoid clashes with parent classes
|
||||
protected $sum_paragraphs = 0;
|
||||
protected $sum_capture = true;
|
||||
protected $sum_inSection = false;
|
||||
protected $sum_summary = '';
|
||||
protected $sum_pageTitle = false;
|
||||
|
||||
/** @inheritdoc */
|
||||
public function document_start() {
|
||||
$this->doc .= DOKU_LF.'<div>'.DOKU_LF;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function document_end() {
|
||||
$this->doc = $this->sum_summary;
|
||||
$this->doc .= DOKU_LF.'</div>'.DOKU_LF;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public 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;
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function section_open($level) {
|
||||
if ( $this->sum_capture ) {
|
||||
$this->sum_inSection = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function section_close() {
|
||||
if ( $this->sum_capture && $this->sum_inSection ) {
|
||||
$this->sum_summary .= $this->doc;
|
||||
$this->sum_capture = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public function p_open() {
|
||||
if ( $this->sum_capture && $this->sum_paragraphs < 2 ) {
|
||||
$this->sum_paragraphs++;
|
||||
}
|
||||
parent :: p_open();
|
||||
}
|
||||
|
||||
/** @inheritdoc */
|
||||
public 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 :
|
Reference in New Issue
Block a user