package.xml0000644000175000017500000007276011461243356014000 0ustar clockwerxclockwerx Text_Wiki pear.php.net Transforms Wiki and BBCode markup into XHTML, LaTeX or plain text markup. This is the base engine for all of the Text_Wiki sub-classes. The text transformation is done in 2 steps. The chosen parser uses markup rules to tokenize the tags and content. Renderers output the tokens and text into the requested format. The tokenized form replaces the tags by a protected byte value associated to an index in an options table. This form shares up to 50 rules by all parsers and renderers. The package is intented for versatile transformers as well as converters. Text_Wiki is delivered with its own parser, which is used by Yawiki or Horde's Wicked and three basic renderers: XHTML , LaTeX and plain text. Strong sanitizing of XHTML is default. Parsers (* and Renderers) exist for BBCode, Cowiki (*), Dokuwiki (*), Mediawiki and Tikiwiki (*). It is highly configurable and can be easily extended. Paul Jones pmjones pmjones@ciaweb.net yes Justin Patrin justinpatrin papercrane@reversefold.com yes Del Elson delatbabel del@babel.com.au yes 2010-10-25 1.2.1 1.2.0 stable stable LGPL QA Release Bug #12490 wiki's do not display since php5-5.2.5 upgrade but are editable. justinpatrin Bug #12580 incorrect/incomplete license in package.xml justinpatrin Bug #12619 Tab character before # causes invalid Xhtml justinpatrin Bug #12665 External site documentation link invalid justinpatrin Doc Bug #14049 Missing documentation justinpatrin Bug #14869 skip tests when config is not available, not fail justinpatrin Bug #15758 URLs with # at the end not considered a url justinpatrin Bug #16222 External documentation is down justinpatrin 4.0.0 1.4.4 1.2.0 1.2.0RC2 beta beta 2007-03-11 LGPL New Features: # Added an Address Xhtml renderer # Balanced token checking has been added (this means that output such as <b><i>italic</b></i> is caught) # A new stack-based callback system for renderers has been added to allow for more flexible output handling (see BlockQuote) # The Url Xhtml renderer now allows a name to be passed in # The Url Xhtml, Plain, Latex renderers now allow start/end tokens Changes: # Experimental preg rendering method deprecated as it had problems # Package.xml 2.0 is now used exclusively Bugs fixed: # Bug #7320 fix UTF-8 rendering in WikiLink and Freelink # Various UTF-8 fixes # Bug #6292 remove paragraph tags from around headings and hrs in Xhtml renderer # Preformatted Xhtml renderer now correctly escapes output 1.2.0RC1 1.2.0RC1 beta beta LGPL New Features: # Experimental new rendering method introduced that uses preg instead of char-by-char parsing ## Please test for both speed and memory usage Changes: # Internal Text_Wiki error handling used in factory and singleton # Needed files are now required # bertrand Gugger has left development of Text_Wiki Bugs fixed: # Raw output is now encoded in Xhtml renderer to avoid XSS attacks # Bug 8313 fix anchor output in Xhtml/Wikilink when used in conjuction with sprintf (thanks to bjs5075 at rit dot edu) # Fixed various encoding issues with Xhtml/Wikilink URLs # Bug #7091 fixed variable substitution in Latex renderer (thanks randlem at bgsu dot edu) 1.1.0 1.1.0 stable stable 2006-03-02 LGPL This is a major release as we reduce global resource usage # instantiate renderers only as needed # factory() method introduced for instantiating Text_Wiki objects # singleton() static method to get a single object instanciated pro parser (merci davidc for advices) The constructor is now deprecated in favor of the new singleton() or factory() methods Default also have its own class now, wich means Text_Wiki is a pure abstract class Renderers now have their own methods for: # text: textEncode() defaulted to php htmlspecialchars() for Xhtml render to the text encoding choosed in conf (#5953, thanks jocke at selincite dot com) # url: urlEncode() defaulted to the php rawurlencode() Wiki general: # Correct the key used in changeRule(), ensure no double new rule. # Page names and anchors Urlencode() as render required (e.g. may contain spaces) # Interwiki: parser may now give the full url instead of site+page (Mediawiki need) # Improved test. Latex render: # Only variables should be assigned by reference (#6010, thanks twells at smarterliving dot com) Plain render: # Interwiki: Complete the rendering with indication of (url) or (site:page) Xhtml render: # Rendering Fix for Tables (Missing Whitespace) (thanks ritzmo) # Added support for two-token URLs ## This allows formatting within URL text and proper rendering into other Wiki dialects (assuming that your parser supports the new feature. The Default parser does not yet support this.) Maintainers: # Del , one of the funders of the original code fully as pear developer # JustinP is now lead 1.0.3 1.0.3 stable stable 2005-11-08 LGPL This is a bug fix release, the Bug #5863: mixed <ul> <ol> when using * and # fix introduced a potential BBC: Bug #5879 Nested lists to do not parse properly in Text_Wiki 1.0.2 1.0.2 stable stable 2005-11-06 LGPL This is a bug fix release, also with a few enhancements Default parser: * Bug #5660: The # is to be kept in the anchor option, (jeremy Lecour) * Bug #5863: Don't mix bullet and numbered lists when following each other, (stefan dot kilp at gmx dot net) * Bug #5397: variable used inside single quotes bugs WikiLinks (kristof dot coomans at sckcen dot be) Xhtml renderer: * Bug #5447: Preset $collapse to null (martin at mein-horde dot de) * Bug #5847: onclick in lowercase for Xhtml compliance (meisteg at msoe dot edu) * Unitiliazed row and column 's spans when coming from not mediawiki parser Xhtml and Latex renderers: * Render enumeration type a, A, i, or I in lists 1.0.1 1.0.1 stable stable 2005-09-12 LGPL This is a bug fix and security release, also preparing the introduction of new parsers/renderers * Fixed bug 3881 and 4442, UTF-8 encoding problems. There are new config options for Render_Xhtml, 'charset' and 'quotes', that allow you to specify the charset for translation. * Fixed bug 3959, "XHTML lists not rendered according W3C Standards" (where a line of text before a list leaves an open paragraph tag and closes it after the list) * In Parse_Xhtml_Toc, returns an extra newline before the parsed replacement text to comply with the matching regex. * In Render_Xhtml_Toc, added a 'collapse' config key to collapse the div horizontally within a table; this is for aesthetics, nothing else. The 'collapse' option is true by default. * Added general rules Smiley, Subscript ",,text,," and Underline "__text__" * Added rendering rules Box, Font, Page, Plugin, Preformatted, Specialchar and Titelbar for the optional extra parsers (BBCode, Cowiki, Doku, Mediawiki and Tiki) * Fixed bug 4175 "Wrong transform method" by generating PEAR_Error objects when a parse, format, or render rule cannot be found. * applied feature request 4436 "Add option to getTokens to get original token indices" -- now the return array from getTokens() is keyed to the original token index number. * Fixed Bug #4473 Undefined variables in error() * Fixed bug 4474 to silence calls to htmlentities and htmlspecialchars so that errors about charsets don't pop up, per counsel from Jan at Horde. * Fixed Code potential nesting * Fixed bug #4719, "In Latex, newline rule does not produce a new line" * Request #4520 Additional space confuses image tag, adapted regexp * Request #4634 Code block title/filename, uses conf css_filename * Code Xhtml: add php tags only if not there * Heading: collapsing in headers * Colortext Xhtml: don't add # if allready present * Anchor Xhtml htlmentify the link * Cleaned Xhtml renderers documentation headers * Added an example in doc * Rowspan and space before free format in Table renderer * Secured url linked on images Text_Wiki-1.2.1/doc/test_Text_Wiki.php0000600000175000017500000001277311461243356020441 0ustar clockwerxclockwerx$plist[0], 'render'=>$rlist[0], 'exchoice'=>($elist ? $elist[0] : ''), 'source'=>'') as $fld=>$def) { if(!isset($_REQUEST[$fld])) { $_REQUEST[$fld] = $def; } $$fld = $_REQUEST[$fld]; } if (!isset($_REQUEST['translate'])) { echo bldHtml('', $plist, $rlist, $elist); die(); } } // instantiate a Text_Wiki object from the given class $wiki = & Text_Wiki::singleton($parser); // If you want to include rules, use //$wiki = & Text_Wiki::singleton($parser, $rules); // If you want to get a new copy of the class use factory //$wiki =& Text_Wiki::factory($parser); //print "
\n";
//print_r($wiki);
//print "
\n"; // when rendering XHTML, make sure wiki links point to a // specific base URL //$wiki->setRenderConf('xhtml', 'wikilink', 'view_url', // 'http://example.com/view.php?page='); // set an array of pages that exist in the wiki // and tell the XHTML renderer about them //$pages = array('HomePage', 'AnotherPage', 'SomeOtherPage'); $wiki->setRenderConf('xhtml', 'code', 'css_filename', 'codefilename'); // transform the wiki text into given rendering $result = $wiki->transform($source, $render); // display the transformed text if ($html) { echo bldHtml($result, $plist, $rlist, $elist); } else { if (PEAR::isError($result)) { var_dump($result); } else { echo $result; } } function bldOpt($name, $list) { $ret = ''; foreach($list as $opt) { $ret .= "\n"; } return $ret; } function bldHtml($result, $plist, $rlist, $elist) { $optparser = bldOpt('parser', $plist); $optrender = bldOpt('render', $rlist); $optexample = bldOpt('exchoice', $elist); if (PEAR::isError($result)) { $hresult = '' . nl2br(htmlentities($result->toString ())) . ''; $result = ''; } else { $hresult = nl2br(htmlentities($result)); } if ($_REQUEST['render'] != 'Xhtml') { $result = ''; } $_REQUEST['source'] = htmlspecialchars($_REQUEST['source']); return << PEAR::Text_Wiki Demo

PEAR::Text_Wiki Demo

Translate from to

Or choose and

{$hresult}
{$result}
EOT; } function findExamples($dir=null) { $ret = array(); $dh=opendir($dir? $dir : '.'); while ($subfil = readdir($dh)) { if (!is_dir($subfil) && is_readable($subfil) && (substr($subfil, -4) == '.txt')) { $ret[] = $subfil; } } closedir($dh); return $ret; } ?> Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Anchor.php0000600000175000017500000000335611461243356022422 0ustar clockwerxclockwerx * * @author Paul M. Jones * * @license LGPL * * @version $Id: Anchor.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * This class implements a Text_Wiki_Parse to add an anchor target name * in the wiki page. * * @author Manuel Holtgrewe * * @author Paul M. Jones * * @category Text * * @package Text_Wiki * */ class Text_Wiki_Parse_Anchor extends Text_Wiki_Parse { /** * * The regular expression used to find source text matching this * rule. Looks like a macro: [[# anchor_name]] * * @access public * * @var string * */ var $regex = '/(\[\[# )([-_A-Za-z0-9.]+?)( .+)?(\]\])/i'; /** * * Generates a token entry for the matched text. Token options are: * * 'text' => The full matched text, not including the tags. * * @access public * * @param array &$matches The array of matches from parse(). * * @return A delimited token number to be used as a placeholder in * the source text. * */ function process(&$matches) { $name = $matches[2]; $text = $matches[3]; $start = $this->wiki->addToken( $this->rule, array('type' => 'start', 'name' => $name) ); $end = $this->wiki->addToken( $this->rule, array('type' => 'end', 'name' => $name) ); // done, place the script output directly in the source return $start . trim($text) . $end; } } ?> Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Blockquote.php0000600000175000017500000001131511461243356023312 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Blockquote.php 222150 2006-10-21 05:56:28Z justinpatrin $ * */ /** * * Parse for block-quoted text. * * Find source text marked as a blockquote, identified by any number of * greater-than signs '>' at the start of the line, followed by a space, * and then the quote text; each '>' indicates an additional level of * quoting. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Blockquote extends Text_Wiki_Parse { /** * * Regex for parsing the source text. * * @access public * * @var string * * @see parse() * */ var $regex = '/\n((\>).*\n)(?!(\>))/Us'; /** * * Generates a replacement for the matched text. * * Token options are: * * 'type' => * 'start' : the start of a blockquote * 'end' : the end of a blockquote * * 'level' => the indent level (0 for the first level, 1 for the * second, etc) * * @access public * * @param array &$matches The array of matches from parse(). * * @return A series of text and delimited tokens marking the different * list text and list elements. * */ function process(&$matches) { // the replacement text we will return to parse() $return = "\n"; // the list of post-processing matches $list = array(); // $matches[1] is the text matched as a list set by parse(); // create an array called $list that contains a new set of // matches for the various list-item elements. preg_match_all( '=^(\>+) (.*\n)=Ums', $matches[1], $list, PREG_SET_ORDER ); $curLevel = 0; // loop through each list-item element. foreach ($list as $key => $val) { // $val[0] is the full matched list-item line // $val[1] is the number of initial '>' chars (indent level) // $val[2] is the quote text // we number levels starting at 1, not zero $level = strlen($val[1]); // add a level to the list? while ($level > $curLevel) { // the current indent level is greater than the number // of stack elements, so we must be starting a new // level. push the new level onto the stack with a // dummy value (boolean true)... ++$curLevel; //$return .= "\n"; // ...and add a start token to the return. $return .= $this->wiki->addToken( $this->rule, array( 'type' => 'start', 'level' => $curLevel ) ); //$return .= "\n\n"; } // remove a level? while ($curLevel > $level) { // as long as the stack count is greater than the // current indent level, we need to end list types. // continue adding end-list tokens until the stack count // and the indent level are the same. //$return .= "\n\n"; $return .= $this->wiki->addToken( $this->rule, array ( 'type' => 'end', 'level' => $curLevel ) ); //$return .= "\n"; --$curLevel; } // add the line text. $return .= $val[2]; } // the last char of the matched pattern must be \n but we don't // want this to be inside the tokens $return = substr($return, 0, -1); // the last line may have been indented. go through the stack // and create end-tokens until the stack is empty. //$return .= "\n"; while ($curLevel > 0) { $return .= $this->wiki->addToken( $this->rule, array ( 'type' => 'end', 'level' => $curLevel ) ); --$curLevel; } // put back the trailing \n $return .= "\n"; // we're done! send back the replacement text. return $return; } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Bold.php0000600000175000017500000000330011461243356022055 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Bold.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Parses for bold text. * * This class implements a Text_Wiki_Rule to find source text marked for * strong emphasis (bold) as defined by text surrounded by three * single-quotes. On parsing, the text itself is left in place, but the * starting and ending instances of three single-quotes are replaced with * tokens. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Bold extends Text_Wiki_Parse { /** * * The regular expression used to parse the source text and find * matches conforming to this rule. Used by the parse() method. * * @access public * * @var string * * @see parse() * */ var $regex = "/'''(()|[^'].*)'''/U"; /** * * Generates a replacement for the matched text. Token options are: * * 'type' => ['start'|'end'] The starting or ending point of the * emphasized text. The text itself is left in the source. * * @access public * * @param array &$matches The array of matches from parse(). * * @return A pair of delimited tokens to be used as a placeholder in * the source text surrounding the text to be emphasized. * */ function process(&$matches) { $start = $this->wiki->addToken($this->rule, array('type' => 'start')); $end = $this->wiki->addToken($this->rule, array('type' => 'end')); return $start . $matches[1] . $end; } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Break.php0000600000175000017500000000226411461243356022231 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Break.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Parses for explicit line breaks. * * This class implements a Text_Wiki_Parse to mark forced line breaks in the * source text. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Break extends Text_Wiki_Parse { /** * * The regular expression used to parse the source text and find * matches conforming to this rule. Used by the parse() method. * * @access public * * @var string * * @see parse() * */ var $regex = '/ _\n/'; /** * * Generates a replacement token for the matched text. * * @access public * * @param array &$matches The array of matches from parse(). * * @return string A delimited token to be used as a placeholder in * the source text. * */ function process(&$matches) { return $this->wiki->addToken($this->rule); } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Center.php0000600000175000017500000000262511461243356022426 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Center.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Parses for centered lines of text. * * This class implements a Text_Wiki_Parse to find lines marked for centering. * The line must start with "= " (i.e., an equal-sign followed by a space). * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Center extends Text_Wiki_Parse { /** * * The regular expression used to find source text matching this * rule. * * @access public * * @var string * */ var $regex = '/\n\= (.*?)\n/'; /** * * Generates a token entry for the matched text. * * @access public * * @param array &$matches The array of matches from parse(). * * @return A delimited token number to be used as a placeholder in * the source text. * */ function process(&$matches) { $start = $this->wiki->addToken( $this->rule, array('type' => 'start') ); $end = $this->wiki->addToken( $this->rule, array('type' => 'end') ); return "\n" . $start . $matches[1] . $end . "\n"; } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Code.php0000600000175000017500000000447511461243356022065 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Code.php 237313 2007-06-09 23:11:25Z justinpatrin $ * */ /** * * Parses for text marked as a code example block. * * This class implements a Text_Wiki_Parse to find sections marked as code * examples. Blocks are marked as the string on a line by itself, * followed by the inline code example, and terminated with the string * on a line by itself. The code example is run through the * native PHP highlight_string() function to colorize it, then surrounded * with
...
tags when rendered as XHTML. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Code extends Text_Wiki_Parse { /** * * The regular expression used to find source text matching this * rule. * * @access public * * @var string * */ /* var $regex = '/^(\)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';*/ var $regex = ';^]*)?>((?:(?R)|.*?)*)\n(\s|$);msi'; /** * * Generates a token entry for the matched text. Token options are: * * 'text' => The full matched text, not including the tags. * * @access public * * @param array &$matches The array of matches from parse(). * * @return A delimited token number to be used as a placeholder in * the source text. * */ function process(&$matches) { // are there additional attribute arguments? $args = trim($matches[1]); if ($args == '') { $options = array( 'text' => $matches[2], 'attr' => array('type' => '') ); } else { // get the attributes... $attr = $this->getAttrs($args); // ... and make sure we have a 'type' if (! isset($attr['type'])) { $attr['type'] = ''; } // retain the options $options = array( 'text' => $matches[2], 'attr' => $attr ); } return $this->wiki->addToken($this->rule, $options) . $matches[3]; } } ?> Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Colortext.php0000600000175000017500000000331111461243356023162 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Colortext.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Parses for colorized text. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Colortext extends Text_Wiki_Parse { /** * * The regular expression used to parse the source text and find * matches conforming to this rule. Used by the parse() method. * * @access public * * @var string * * @see parse() * */ var $regex = "/\#\#(.+?)\|(.+?)\#\#/"; /** * * Generates a replacement for the matched text. Token options are: * * 'type' => ['start'|'end'] The starting or ending point of the * emphasized text. The text itself is left in the source. * * 'color' => the color indicator * * @access public * * @param array &$matches The array of matches from parse(). * * @return string A pair of delimited tokens to be used as a * placeholder in the source text surrounding the text to be * emphasized. * */ function process(&$matches) { $start = $this->wiki->addToken( $this->rule, array( 'type' => 'start', 'color' => $matches[1] ) ); $end = $this->wiki->addToken( $this->rule, array( 'type' => 'end', 'color' => $matches[1] ) ); return $start . $matches[2] . $end; } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Deflist.php0000600000175000017500000000647411461243356022606 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Deflist.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Parses for definition lists. * * This class implements a Text_Wiki_Parse to find source text marked as a * definition list. In short, if a line starts with ':' then it is a * definition list item; another ':' on the same line indicates the end * of the definition term and the beginning of the definition narrative. * The list items must be on sequential lines (no blank lines between * them) -- a blank line indicates the beginning of a new list. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Deflist extends Text_Wiki_Parse { /** * * The regular expression used to parse the source text and find * matches conforming to this rule. Used by the parse() method. * * @access public * * @var string * * @see parse() * */ var $regex = '/\n((: ).*\n)(?!(: |\n))/Us'; /** * * Generates a replacement for the matched text. Token options are: * * 'type' => * 'list_start' : the start of a definition list * 'list_end' : the end of a definition list * 'term_start' : the start of a definition term * 'term_end' : the end of a definition term * 'narr_start' : the start of definition narrative * 'narr_end' : the end of definition narrative * 'unknown' : unknown type of definition portion * * @access public * * @param array &$matches The array of matches from parse(). * * @return A series of text and delimited tokens marking the different * list text and list elements. * */ function process(&$matches) { // the replacement text we will return to parse() $return = ''; // the list of post-processing matches $list = array(); // start the deflist $options = array('type' => 'list_start'); $return .= $this->wiki->addToken($this->rule, $options); // $matches[1] is the text matched as a list set by parse(); // create an array called $list that contains a new set of // matches for the various definition-list elements. preg_match_all( '/^(: )(.*)?( : )(.*)?$/Ums', $matches[1], $list, PREG_SET_ORDER ); // add each term and narrative foreach ($list as $key => $val) { $return .= ( $this->wiki->addToken($this->rule, array('type' => 'term_start')) . trim($val[2]) . $this->wiki->addToken($this->rule, array('type' => 'term_end')) . $this->wiki->addToken($this->rule, array('type' => 'narr_start')) . trim($val[4]) . $this->wiki->addToken($this->rule, array('type' => 'narr_end')) ); } // end the deflist $options = array('type' => 'list_end'); $return .= $this->wiki->addToken($this->rule, $options); // done! return "\n" . $return . "\n\n"; } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Delimiter.php0000600000175000017500000000342511461243356023123 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Delimiter.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Parses for Text_Wiki delimiter characters already in the source text. * * This class implements a Text_Wiki_Parse to find instances of the delimiter * character already embedded in the source text; it extracts them and replaces * them with a delimited token, then renders them as the delimiter itself * when the target format is XHTML. * * @category Text * * @package Text_Wiki * * @author Paul M. Jones * */ class Text_Wiki_Parse_Delimiter extends Text_Wiki_Parse { /** * * Constructor. Overrides the Text_Wiki_Parse constructor so that we * can set the $regex property dynamically (we need to include the * Text_Wiki $delim character. * * @param object &$obj The calling "parent" Text_Wiki object. * * @param string $name The token name to use for this rule. * */ function Text_Wiki_Parse_delimiter(&$obj) { parent::Text_Wiki_Parse($obj); $this->regex = '/' . $this->wiki->delim . '/'; } /** * * Generates a token entry for the matched text. Token options are: * * 'text' => The full matched text. * * @access public * * @param array &$matches The array of matches from parse(). * * @return A delimited token number to be used as a placeholder in * the source text. * */ function process(&$matches) { return $this->wiki->addToken( $this->rule, array('text' => $this->wiki->delim) ); } } ?>Text_Wiki-1.2.1/Text/Wiki/Parse/Default/Embed.php0000600000175000017500000000450411461243356022220 0ustar clockwerxclockwerx * * @license LGPL * * @version $Id: Embed.php 180591 2005-02-23 17:38:29Z pmjones $ * */ /** * * Embeds the results of a PHP script at render-time. * * This class implements a Text_Wiki_Parse to embed the contents of a URL * inside the page at render-time. Typically used to get script output. * This differs from the 'include' rule, which incorporates results at * parse-time; 'embed' output does not get parsed by Text_Wiki, while * 'include' ouput does. * * This rule is inherently not secure; it allows cross-site scripting to * occur if the embedded output has '; } } else { $js = ''; } return $js.'
'; case 'endContent': return '
'; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Horiz.php0000600000175000017500000000240111461243356022146 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Horiz.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders an horizontal bar in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Horiz extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $css = $this->formatConf(' class="%s"', 'css'); return "\n"; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Html.php0000600000175000017500000000222311461243356021761 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Html.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders preformated html in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Html extends Text_Wiki_Render { /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { return $options['text']; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Image.php0000600000175000017500000001365411461243356022111 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Image.php 231923 2007-03-15 15:04:50Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class inserts an image in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Image extends Text_Wiki_Render { var $conf = array( 'base' => '/', 'url_base' => null, 'css' => null, 'css_link' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // note the image source $src = $options['src']; // is the source a local file or URL? if (strpos($src, '://') === false) { // the source refers to a local file. // add the URL base to it. $src = $this->getConf('base', '/') . $src; } // stephane@metacites.net // is the image clickable? if (isset($options['attr']['link'])) { // yes, the image is clickable. // are we linked to a URL or a wiki page? if (strpos($options['attr']['link'], '://')) { // it's a URL, prefix the URL base $href = $this->getConf('url_base') . $options['attr']['link']; } else { // it's a WikiPage; assume it exists. /** @todo This needs to honor sprintf wikilinks (pmjones) */ /** @todo This needs to honor interwiki (pmjones) */ /** @todo This needs to honor freelinks (pmjones) */ $href = $this->wiki->getRenderConf('xhtml', 'wikilink', 'view_url') . $options['attr']['link']; } } else { // image is not clickable. $href = null; } // unset so it won't show up as an attribute unset($options['attr']['link']); // stephane@metacites.net -- 25/07/2004 // use CSS for all alignment if (isset($options['attr']['align'])) { // make sure we have a style attribute if (!isset($options['attr']['style'])) { // no style, set up a blank one $options['attr']['style'] = ''; } else { // style exists, add a space $options['attr']['style'] .= ' '; } if ($options['attr']['align'] == 'center') { // add a "center" style to the existing style. $options['attr']['style'] .= 'display: block; margin-left: auto; margin-right: auto;'; } else { // add a float style to the existing style $options['attr']['style'] .= 'float: '.$options['attr']['align']; } // unset so it won't show up as an attribute unset($options['attr']['align']); } // stephane@metacites.net -- 25/07/2004 // try to guess width and height if (! isset($options['attr']['width']) && ! isset($options['attr']['height'])) { // does the source refer to a local file or a URL? if (strpos($src,'://')) { // is a URL link $imageFile = $src; } elseif ($src[0] == '.') { // reg at dav-muz dot net -- 2005-03-07 // is a local file on relative path. $imageFile = $src; # ...don't do anything because it's perfect! } else { // is a local file on absolute path. $imageFile = $_SERVER['DOCUMENT_ROOT'] . $src; } // attempt to get the image size $imageSize = @getimagesize($imageFile); if (is_array($imageSize)) { $options['attr']['width'] = $imageSize[0]; $options['attr']['height'] = $imageSize[1]; } } // start the HTML output $output = 'formatConf(' class="%s"', 'css'); // add the attributes to the output, and be sure to // track whether or not we find an "alt" attribute $alt = false; foreach ($options['attr'] as $key => $val) { // track the 'alt' attribute if (strtolower($key) == 'alt') { $alt = true; } // the 'class' attribute overrides the CSS class conf if (strtolower($key) == 'class') { $css = null; } $key = $this->textEncode($key); $val = $this->textEncode($val); $output .= " $key=\"$val\""; } // always add an "alt" attribute per Stephane Solliec if (! $alt) { $alt = $this->textEncode(basename($options['src'])); $output .= " alt=\"$alt\""; } // end the image tag with the automatic CSS class (if any) $output .= "$css />"; // was the image clickable? if ($href) { // yes, add the href and return $href = $this->textEncode($href); $css = $this->formatConf(' class="%s"', 'css_link'); $output = "$output"; } return $output; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Include.php0000600000175000017500000000156311461243356022446 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Include.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders included maekup in XHTML. (empty) * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Include extends Text_Wiki_Render { function token() { return ''; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Interwiki.php0000600000175000017500000000606211461243356023027 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Interwiki.php 231896 2007-03-15 00:08:47Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders inter wikis links in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Interwiki extends Text_Wiki_Render { var $conf = array( 'sites' => array( 'MeatBall' => 'http://www.usemod.com/cgi-bin/mb.pl?%s', 'Advogato' => 'http://advogato.org/%s', 'Wiki' => 'http://c2.com/cgi/wiki?%s' ), 'target' => '_blank', 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $text = $options['text']; if (isset($options['url'])) { // calculated by the parser (e.g. Mediawiki) $href = $options['url']; } else { $site = $options['site']; // toggg 2006/02/05 page name must be url encoded (e.g. may contain spaces) $page = $this->urlEncode($options['page']); if (isset($this->conf['sites'][$site])) { $href = $this->conf['sites'][$site]; } else { return $text; } // old form where page is at end, // or new form with %s placeholder for sprintf()? if (strpos($href, '%s') === false) { // use the old form $href = $href . $page; } else { // use the new form $href = sprintf($href, $page); } } // allow for alternative targets $target = $this->getConf('target'); // build base link $css = $this->formatConf(' class="%s"', 'css'); $text = $this->textEncode($text); $output = "textEncode($target); $output .= " onclick=\"window.open(this.href, '$target');"; $output .= " return false;\""; } $output .= ">$text"; return $output; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Italic.php0000600000175000017500000000260511461243356022266 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Italic.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders italic text in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Italic extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/List.php0000600000175000017500000001117211461243356021773 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: List.php 200073 2005-11-06 10:38:25Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders bullet and ordered lists in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_List extends Text_Wiki_Render { var $conf = array( 'css_ol' => null, 'css_ol_li' => null, 'css_ul' => null, 'css_ul_li' => null ); /** * * Renders a token into text matching the requested format. * * This rendering method is syntactically and semantically compliant * with XHTML 1.1 in that sub-lists are part of the previous list item. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // make nice variables (type, level, count) extract($options); // set up indenting so that the results look nice; we do this // in two steps to avoid str_pad mathematics. ;-) $pad = str_pad('', $level, "\t"); $pad = str_replace("\t", ' ', $pad); switch ($type) { case 'bullet_list_start': // build the base HTML $css = $this->formatConf(' class="%s"', 'css_ul'); $html = ""; /* // if this is the opening block for the list, // put an extra newline in front of it so the // output looks nice. if ($level == 0) { $html = "\n$html"; } */ // done! return $html; break; case 'bullet_list_end': // build the base HTML $html = "\n$pad"; // if this is the closing block for the list, // put extra newlines after it so the output // looks nice. if ($level == 0) { $html .= "\n\n"; } // done! return $html; break; case 'number_list_start': if (isset($format)) { $format = ' type="' . $format . '"'; } else { $format = ''; } // build the base HTML $css = $this->formatConf(' class="%s"', 'css_ol'); $html = ""; /* // if this is the opening block for the list, // put an extra newline in front of it so the // output looks nice. if ($level == 0) { $html = "\n$html"; } */ // done! return $html; break; case 'number_list_end': // build the base HTML $html = "\n$pad"; // if this is the closing block for the list, // put extra newlines after it so the output // looks nice. if ($level == 0) { $html .= "\n\n"; } // done! return $html; break; case 'bullet_item_start': case 'number_item_start': // pick the proper CSS class if ($type == 'bullet_item_start') { $css = $this->formatConf(' class="%s"', 'css_ul_li'); } else { $css = $this->formatConf(' class="%s"', 'css_ol_li'); } // build the base HTML $html = "\n$pad"; // for the very first item in the list, do nothing. // but for additional items, be sure to close the // previous item. if ($count > 0) { $html = "$html"; } // done! return $html; break; case 'bullet_item_end': case 'number_item_end': default: // ignore item endings and all other types. // item endings are taken care of by the other types // depending on their place in the list. return ''; break; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Newline.php0000600000175000017500000000157011461243356022462 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Newline.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders new lines in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Newline extends Text_Wiki_Render { function token($options) { return "
\n"; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Page.php0000600000175000017500000000225011461243356021731 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Page.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders page markers in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Page extends Text_Wiki_Render { /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { return 'PAGE MARKER HERE*&^%$#^$%*PAGEMARKERHERE'; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Paragraph.php0000600000175000017500000000263611461243356022772 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Paragraph.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders paragraphs in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Paragraph extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { extract($options); //type if ($type == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($type == 'end') { return "

\n\n"; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Phplookup.php0000600000175000017500000000443311461243356023043 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Phplookup.php 231896 2007-03-15 00:08:47Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders a link to php functions description in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Phplookup extends Text_Wiki_Render { var $conf = array( 'target' => '_blank', 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $text = trim($options['text']); $css = $this->formatConf(' class="%s"', 'css'); // start the html $output = "getConf('target', ''); if ($target && $target != '_self') { // use a "popup" window. this is XHTML compliant, suggested by // Aaron Kalin. uses the $target as the new window name. $target = $this->textEncode($target); $output .= " onclick=\"window.open(this.href, '$target');"; $output .= " return false;\""; } // take off the final parens for functions if (substr($text, -2) == '()') { $q = substr($text, 0, -2); } else { $q = $text; } // toggg 2006/02/05 page name must be url encoded (e.g. may contain spaces) $q = $this->urlEncode($q); $text = $this->textEncode($text); // finish and return $output .= " href=\"http://php.net/$q\">$text"; return $output; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Plugin.php0000600000175000017500000000234011461243356022313 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Plugin.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders wiki plugins in XHTML. (empty) * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Plugin extends Text_Wiki_Render { /** * * Renders a token into text matching the requested format. * Plugins produce wiki markup so are processed by parsing, no tokens produced * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { return ''; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Prefilter.php0000600000175000017500000000204411461243356023012 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Prefilter.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class implements a Text_Wiki_Render_Xhtml to "pre-filter" source text so * that line endings are consistently \n, lines ending in a backslash \ * are concatenated with the next line, and tabs are converted to spaces. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Prefilter extends Text_Wiki_Render { function token() { return ''; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Preformatted.php0000600000175000017500000000234311461243356023514 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Preformatted.php 229275 2007-02-07 13:40:44Z mic $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders preformated text in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Preformatted extends Text_Wiki_Render { /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { $text = $this->textEncode($options['text']); return '
'.$text.'
'; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Raw.php0000600000175000017500000000225511461243356021613 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Raw.php 214538 2006-06-09 21:32:24Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders not processed blocks in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Raw extends Text_Wiki_Render { /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { return $this->textEncode($options['text']); } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Revise.php0000600000175000017500000000324711461243356022321 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Revise.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders revision marks in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Revise extends Text_Wiki_Render { var $conf = array( 'css_ins' => null, 'css_del' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'del_start') { $css = $this->formatConf(' class="%s"', 'css_del'); return ""; } if ($options['type'] == 'del_end') { return ""; } if ($options['type'] == 'ins_start') { $css = $this->formatConf(' class="%s"', 'css_ins'); return ""; } if ($options['type'] == 'ins_end') { return ""; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Smiley.php0000600000175000017500000000507011461243356022322 0ustar clockwerxclockwerx * @copyright 2005 bertrand Gugger * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Smiley.php 206940 2006-02-10 23:07:03Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * Smiley rule Xhtml render class * * @category Text * @package Text_Wiki * @author Bertrand Gugger * @copyright 2005 bertrand Gugger * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki * @see Text_Wiki::Text_Wiki_Render() */ class Text_Wiki_Render_Xhtml_Smiley extends Text_Wiki_Render { /** * Configuration keys for this rule * 'prefix' => the path to smileys images inclusive file name prefix, * starts with '/' ==> abolute reference * if no file names prefix but some folder, terminates with '/' * 'extension' => the file extension (inclusive '.'), e.g. : * if prefix 'smileys/icon_' and extension '.gif' * ':)' whose name is 'smile' will give relative file 'smileys/icon_smile.gif' * if prefix '/image/smileys/' and extension '.png': absolute '/image/smileys/smile.gif' * 'css' => optional style applied to smileys * * @access public * @var array 'config-key' => mixed config-value */ var $conf = array( 'prefix' => 'images/smiles/icon_', 'extension' => '.gif', 'css' => null ); /** * Renders a token into text matching the requested format. * process the Smileys * * @access public * @param array $options The "options" portion of the token (second element). * @return string The text rendered from the token options. */ function token($options) { $imageFile = $this->getConf('prefix') . $options['name'] . $this->getConf('extension'); // attempt to get the image size $imageSize = @getimagesize($imageFile); // return the HTML output return '' . $options['desc'] . 'formatConf(' class="%s"', 'css') . ' />'; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Specialchar.php0000600000175000017500000000316511461243356023301 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Specialchar.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders special characters in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_SpecialChar extends Text_Wiki_Render { var $types = array('~bs~' => '\', '~hs~' => ' ', '~amp~' => '&', '~ldq~' => '“', '~rdq~' => '”', '~lsq~' => '‘', '~rsq~' => '’', '~c~' => '©', '~--~' => '—', '" -- "' => '—', '" -- "' => '—', '~lt~' => '<', '~gt~' => '>'); function token($options) { if (isset($this->types[$options['char']])) { return $this->types[$options['char']]; } else { return '&#'.substr($options['char'], 1, -1).';'; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Strong.php0000600000175000017500000000263211461243356022335 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Strong.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders text marked as strong in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Strong extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Subscript.php0000600000175000017500000000262511461243356023041 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Subscript.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders subscript text in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Subscript extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Superscript.php0000600000175000017500000000263511461243356023407 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Superscript.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders superscript text in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Superscript extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Table.php0000600000175000017500000000664111461243356022114 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Table.php 202250 2005-12-06 15:29:29Z ritzmo $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders tables in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Table extends Text_Wiki_Render { var $conf = array( 'css_table' => null, 'css_caption' => null, 'css_tr' => null, 'css_th' => null, 'css_td' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // make nice variable names (type, attr, span) $span = $rowspan = 1; extract($options); // free format $format = isset($format) ? ' '. $format : ''; $pad = ' '; switch ($type) { case 'table_start': $css = $this->formatConf(' class="%s"', 'css_table'); return "\n\n\n"; break; case 'table_end': return "\n\n"; break; case 'caption_start': $css = $this->formatConf(' class="%s"', 'css_caption'); return "\n"; break; case 'caption_end': return "\n"; break; case 'row_start': $css = $this->formatConf(' class="%s"', 'css_tr'); return "$pad\n"; break; case 'row_end': return "$pad\n"; break; case 'cell_start': // base html $html = $pad . $pad; // is this a TH or TD cell? if ($attr == 'header') { // start a header cell $css = $this->formatConf(' class="%s"', 'css_th'); $html .= "formatConf(' class="%s"', 'css_td'); $html .= " 1) { $html .= " colspan=\"$span\""; } // add the row span if ($rowspan > 1) { $html .= " rowspan=\"$rowspan\""; } // add alignment if ($attr != 'header' && $attr != '') { $html .= " style=\"text-align: $attr;\""; } // done! $html .= "$format>"; return $html; break; case 'cell_end': if ($attr == 'header') { return "\n"; } else { return "\n"; } break; default: return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Tighten.php0000600000175000017500000000156211461243356022464 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Tighten.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class makes the tightening in XHTML. (empty) * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Tighten extends Text_Wiki_Render { function token() { return ''; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Titlebar.php0000600000175000017500000000262511461243356022631 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Titlebar.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders a title bar in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Titlebar extends Text_Wiki_Render { var $conf = array( 'css' => 'titlebar' ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Toc.php0000600000175000017500000000552111461243356021606 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Toc.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class inserts a table of content in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Toc extends Text_Wiki_Render { var $conf = array( 'css_list' => null, 'css_item' => null, 'title' => 'Table of Contents', 'div_id' => 'toc', 'collapse' => true ); var $min = 2; /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // type, id, level, count, attr extract($options); switch ($type) { case 'list_start': $css = $this->getConf('css_list'); $html = ''; // collapse div within a table? if ($this->getConf('collapse')) { $html .= ''; $html .= "
\n"; } // add the div, class, and id $html .= 'getConf('div_id'); if ($div_id) { $html .= " id=\"$div_id\""; } // add the title, and done $html .= '>'; $html .= $this->getConf('title'); return $html; break; case 'list_end': if ($this->getConf('collapse')) { return "\n\n
\n\n"; } else { return "\n\n\n"; } break; case 'item_start': $html = "\n\tgetConf('css_item'); if ($css) { $html .= " class=\"$css\""; } $pad = ($level - $this->min); $html .= " style=\"margin-left: {$pad}em;\">"; $html .= ""; return $html; break; case 'item_end': return ""; break; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Tt.php0000600000175000017500000000260011461243356021443 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Tt.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders monospaced text in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Tt extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Underline.php0000600000175000017500000000262211461243356023005 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Underline.php 191862 2005-07-30 08:03:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders underlined text in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Underline extends Text_Wiki_Render { var $conf = array( 'css' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { if ($options['type'] == 'start') { $css = $this->formatConf(' class="%s"', 'css'); return ""; } if ($options['type'] == 'end') { return ''; } } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Url.php0000600000175000017500000000774011461243356021630 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Url.php 236400 2007-05-26 17:15:41Z mic $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders URL links in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Url extends Text_Wiki_Render { var $conf = array( 'target' => '_blank', 'images' => true, 'img_ext' => array('jpg', 'jpeg', 'gif', 'png'), 'css_inline' => null, 'css_footnote' => null, 'css_descr' => null, 'css_img' => null ); /** * * Renders a token into text matching the requested format. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // create local variables from the options array (text, // href, type) extract($options); // find the rightmost dot and determine the filename // extension. $pos = strrpos($href, '.'); $ext = strtolower(substr($href, $pos + 1)); $href = $this->textEncode($href); // does the filename extension indicate an image file? if ($this->getConf('images') && in_array($ext, $this->getConf('img_ext', array()))) { // create alt text for the image if (! isset($text) || $text == '') { $text = basename($href); $text = $this->textEncode($text); } // generate an image tag $css = $this->formatConf(' class="%s"', 'css_img'); $start = ""; } else { // should we build a target clause? if ($href{0} == '#' || strtolower(substr($href, 0, 7)) == 'mailto:') { // targets not allowed for on-page anchors // and mailto: links. $target = ''; } else { // allow targets on non-anchor non-mailto links $target = $this->getConf('target'); } // generate a regular link (not an image) $text = $this->textEncode($text); $css = $this->formatConf(' class="%s"', "css_$type"); $start = "textEncode($target); $start .= " onclick=\"window.open(this.href, '$target');"; $start .= " return false;\""; } if (isset($name)) { $start .= " id=\"$name\""; } // finish up output $start .= ">"; $end = ""; // make numbered references look like footnotes when no // CSS class specified, make them superscript by default if ($type == 'footnote' && ! $css) { $start = '' . $start; $end = $end . ''; } } if ($options['type'] == 'start') { $output = $start; } else if ($options['type'] == 'end') { $output = $end; } else { $output = $start . $text . $end; } return $output; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Xhtml/Wikilink.php0000600000175000017500000001351211461243356022641 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Wikilink.php 224670 2006-12-08 21:25:24Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * This class renders wiki links in XHTML. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml_Wikilink extends Text_Wiki_Render { var $conf = array( 'pages' => array(), // set to null or false to turn off page checks 'view_url' => 'http://example.com/index.php?page=%s', 'new_url' => 'http://example.com/new.php?page=%s', 'new_text' => '?', 'new_text_pos' => 'after', // 'before', 'after', or null/false 'css' => null, 'css_new' => null, 'exists_callback' => null // call_user_func() callback ); /** * * Renders a token into XHTML. * * @access public * * @param array $options The "options" portion of the token (second * element). * * @return string The text rendered from the token options. * */ function token($options) { // make nice variable names (page, anchor, text) extract($options); // is there a "page existence" callback? // we need to access it directly instead of through // getConf() because we'll need a reference (for // object instance method callbacks). if (isset($this->conf['exists_callback'])) { $callback =& $this->conf['exists_callback']; } else { $callback = false; } if ($callback) { // use the callback function $exists = call_user_func($callback, $page); } else { // no callback, go to the naive page array. $list = $this->getConf('pages'); if (is_array($list)) { // yes, check against the page list $exists = in_array($page, $list); } else { // no, assume it exists $exists = true; } } $anchor = '#'.$this->urlEncode(substr($anchor, 1)); // does the page exist? if ($exists) { // PAGE EXISTS. // link to the page view, but we have to build // the HREF. we support both the old form where // the page always comes at the end, and the new // form that uses %s for sprintf() $href = $this->getConf('view_url'); if (strpos($href, '%s') === false) { // use the old form (page-at-end) $href = $href . $this->urlEncode($page) . $anchor; } else { // use the new form (sprintf format string) $href = sprintf($href, $this->urlEncode($page)) . $anchor; } // get the CSS class and generate output $css = ' class="'.$this->textEncode($this->getConf('css')).'"'; $start = ''; $end = ''; } else { // PAGE DOES NOT EXIST. // link to a create-page url, but only if new_url is set $href = $this->getConf('new_url', null); // set the proper HREF if (! $href || trim($href) == '') { // no useful href, return the text as it is //TODO: This is no longer used, need to look closer into this branch $output = $text; } else { // yes, link to the new-page href, but we have to build // it. we support both the old form where // the page always comes at the end, and the new // form that uses sprintf() if (strpos($href, '%s') === false) { // use the old form $href = $href . $this->urlEncode($page); } else { // use the new form $href = sprintf($href, $this->urlEncode($page)); } } // get the appropriate CSS class and new-link text $css = ' class="'.$this->textEncode($this->getConf('css_new')).'"'; $new = $this->getConf('new_text'); // what kind of linking are we doing? $pos = $this->getConf('new_text_pos'); if (! $pos || ! $new) { // no position (or no new_text), use css only on the page name $start = ''; $end = ''; } elseif ($pos == 'before') { // use the new_text BEFORE the page name $start = ''.$this->textEncode($new).''; $end = ''; } else { // default, use the new_text link AFTER the page name $start = ''; $end = ''.$this->textEncode($new).''; } } if (!strlen($text)) { $start .= $this->textEncode($page); } if (isset($type)) { switch ($type) { case 'start': $output = $start; break; case 'end': $output = $end; break; } } else { $output = $start.$this->textEncode($text).$end; } return $output; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render/Latex.php0000600000175000017500000000457611461243356021053 0ustar clockwerxclockwerx * * @package Text_Wiki * * @todo [http://google.com] becomes 1 with a LaTeX footnote in subscript. * This should be a normal LaTeX footnote associated with the * previous word? * * @todo parse "..." to be ``...'' * * @todo parse '...' to be `...' * * @todo move escape_latex to a static function, move escaping to the * individual .php files they are associated with * * @todo allow the user to add conf items to do things like * + A custom document header * + Custom page headings * + Include packages * + Set Title, Author, Date * + Include a title page * + Not output Document Head/Foot (maybe combinding many pages?) * */ class Text_Wiki_Render_Latex extends Text_Wiki_Render { function escape_latex ($txt) { $txt = str_replace("\\", "\\\\", $txt); $txt = str_replace('#', '\#', $txt); $txt = str_replace('$', '\$', $txt); $txt = str_replace('%', '\%', $txt); $txt = str_replace('^', '\^', $txt); $txt = str_replace('&', '\&', $txt); $txt = str_replace('_', '\_', $txt); $txt = str_replace('{', '\{', $txt); $txt = str_replace('}', '\}', $txt); // Typeset things a bit prettier than normas $txt = str_replace('~', '$\sim$', $txt); $txt = str_replace('...', '\ldots', $txt); return $txt; } function escape($tok, $ele) { if (isset($tok[$ele])) { $tok[$ele] = $this->escape_latex($tok[$ele]); } return $tok; } function pre() { foreach ($this->wiki->tokens as $k => $tok) { if ($tok[0] == 'Code') { continue; } $tok[1] = $this->escape($tok[1], 'text'); $tok[1] = $this->escape($tok[1], 'page'); $tok[1] = $this->escape($tok[1], 'href'); $this->wiki->tokens[$k] = $tok; } $this->wiki->source = $this->escape_latex($this->wiki->source); return "\\documentclass{article}\n". "\\usepackage{ulem}\n". "\\pagestyle{headings}\n". "\\begin{document}\n"; } function post() { return "\\end{document}\n"; } } ?>Text_Wiki-1.2.1/Text/Wiki/Render/Plain.php0000600000175000017500000000026111461243356021024 0ustar clockwerxclockwerxText_Wiki-1.2.1/Text/Wiki/Render/Xhtml.php0000600000175000017500000000535611461243356021067 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Xhtml.php 206939 2006-02-10 22:31:50Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * Format class for the Xhtml rendering * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render_Xhtml extends Text_Wiki_Render { var $conf = array( 'translate' => HTML_ENTITIES, 'quotes' => ENT_COMPAT, 'charset' => 'ISO-8859-1' ); function pre() { $this->wiki->source = $this->textEncode($this->wiki->source); } function post() { return; } /** * Method to render text * * @access public * @param string $text the text to render * @return rendered text * */ function textEncode($text) { // attempt to translate HTML entities in the source. // get the config options. $type = $this->getConf('translate', HTML_ENTITIES); $quotes = $this->getConf('quotes', ENT_COMPAT); $charset = $this->getConf('charset', 'ISO-8859-1'); // have to check null and false because HTML_ENTITIES is a zero if ($type === HTML_ENTITIES) { // keep a copy of the translated version of the delimiter // so we can convert it back. $new_delim = htmlentities($this->wiki->delim, $quotes, $charset); // convert the entities. we silence the call here so that // errors about charsets don't pop up, per counsel from // Jan at Horde. (http://pear.php.net/bugs/bug.php?id=4474) $text = @htmlentities( $text, $quotes, $charset ); // re-convert the delimiter $text = str_replace( $new_delim, $this->wiki->delim, $text ); } elseif ($type === HTML_SPECIALCHARS) { // keep a copy of the translated version of the delimiter // so we can convert it back. $new_delim = htmlspecialchars($this->wiki->delim, $quotes, $charset); // convert the entities. we silence the call here so that // errors about charsets don't pop up, per counsel from // Jan at Horde. (http://pear.php.net/bugs/bug.php?id=4474) $text = @htmlspecialchars( $text, $quotes, $charset ); // re-convert the delimiter $text = str_replace( $new_delim, $this->wiki->delim, $text ); } return $text; } } ?> Text_Wiki-1.2.1/Text/Wiki/Default.php0000600000175000017500000000144211461243356020130 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Default.php 208363 2006-03-01 16:58:17Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ require_once('Text/Wiki.php'); /** * This is the parser for the Default ruleset. For now, this simply extends Text_Wiki. * * @category Text * @package Text_Wiki * @version Release: @package_version@ * @author Justin Patrin */ class Text_Wiki_Default extends Text_Wiki { } Text_Wiki-1.2.1/Text/Wiki/Parse.php0000600000175000017500000001470711461243356017626 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Parse.php 191781 2005-07-29 08:57:29Z toggg $ * @link http://pear.php.net/package/Text_Wiki */ /** * Baseline rule class for extension into a "real" parser component. * * Text_Wiki_Rule classes do not stand on their own; they are called by a * Text_Wiki object, typcially in the transform() method. Each rule class * performs three main activities: parse, process, and render. * * The parse() method takes a regex and applies it to the whole block of * source text at one time. Each match is sent as $matches to the * process() method. * * The process() method acts on the matched text from the source, and * then processes the source text is some way. This may mean the * creation of a delimited token using addToken(). In every case, the * process() method returns the text that should replace the matched text * from parse(). * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Parse { /** * * Configuration options for this parser rule. * * @access public * * @var string * */ var $conf = array(); /** * * Regular expression to find matching text for this rule. * * @access public * * @var string * * @see parse() * */ var $regex = null; /** * * The name of this rule for new token array elements. * * @access public * * @var string * */ var $rule = null; /** * * A reference to the calling Text_Wiki object. * * This is needed so that each rule has access to the same source * text, token set, URLs, interwiki maps, page names, etc. * * @access public * * @var object */ var $wiki = null; /** * * Constructor for this parser rule. * * @access public * * @param object &$obj The calling "parent" Text_Wiki object. * */ function Text_Wiki_Parse(&$obj) { // set the reference to the calling Text_Wiki object; // this allows us access to the shared source text, token // array, etc. $this->wiki =& $obj; // set the name of this rule; generally used when adding // to the tokens array. strip off the Text_Wiki_Parse_ portion. // text_wiki_parse_ // 0123456789012345 $tmp = substr(get_class($this), 16); $this->rule = ucwords(strtolower($tmp)); // override config options for the rule if specified if (isset($this->wiki->parseConf[$this->rule]) && is_array($this->wiki->parseConf[$this->rule])) { $this->conf = array_merge( $this->conf, $this->wiki->parseConf[$this->rule] ); } } /** * * Abstrct method to parse source text for matches. * * Applies the rule's regular expression to the source text, passes * every match to the process() method, and replaces the matched text * with the results of the processing. * * @access public * * @see Text_Wiki_Parse::process() * */ function parse() { $this->wiki->source = preg_replace_callback( $this->regex, array(&$this, 'process'), $this->wiki->source ); } /** * * Abstract method to generate replacements for matched text. * * @access public * * @param array $matches An array of matches from the parse() method * as generated by preg_replace_callback. $matches[0] is the full * matched string, $matches[1] is the first matched pattern, * $matches[2] is the second matched pattern, and so on. * * @return string The processed text replacement; defaults to the * full matched string (i.e., no changes to the text). * * @see Text_Wiki_Parse::parse() * */ function process(&$matches) { return $matches[0]; } /** * * Simple method to safely get configuration key values. * * @access public * * @param string $key The configuration key. * * @param mixed $default If the key does not exist, return this value * instead. * * @return mixed The configuration key value (if it exists) or the * default value (if not). * */ function getConf($key, $default = null) { if (isset($this->conf[$key])) { return $this->conf[$key]; } else { return $default; } } /** * * Extract 'attribute="value"' portions of wiki markup. * * This kind of markup is typically used only in macros, but is useful * anywhere. * * The syntax is pretty strict; there can be no spaces between the * option name, the equals, and the first double-quote; the value * must be surrounded by double-quotes. You can escape characters in * the value with a backslash, and the backslash will be stripped for * you. * * @access public * * @param string $text The "attributes" portion of markup. * * @return array An associative array of key-value pairs where the * key is the option name and the value is the option value. * */ function getAttrs($text) { // find the =" sections; $tmp = explode('="', trim($text)); // basic setup $k = count($tmp) - 1; $attrs = array(); $key = null; // loop through the sections foreach ($tmp as $i => $val) { // first element is always the first key if ($i == 0) { $key = trim($val); continue; } // find the last double-quote in the value. // the part to the left is the value for the last key, // the part to the right is the next key name $pos = strrpos($val, '"'); $attrs[$key] = stripslashes(substr($val, 0, $pos)); $key = trim(substr($val, $pos+1)); } return $attrs; } } ?> Text_Wiki-1.2.1/Text/Wiki/Render.php0000600000175000017500000001164011461243356017764 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Render.php 209118 2006-03-11 07:12:13Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * Base rendering class for parsed and tokenized text. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: @package_version@ * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki_Render { /** * * Configuration options for this render rule. * * @access public * * @var string * */ var $conf = array(); /** * * The name of this rule's format. * * @access public * * @var string * */ var $format = null; /** * * The name of this rule's token array elements. * * @access public * * @var string * */ var $rule = null; /** * * A reference to the calling Text_Wiki object. * * This is needed so that each rule has access to the same source * text, token set, URLs, interwiki maps, page names, etc. * * @access public * * @var object */ var $wiki = null; /** * * Constructor for this render format or rule. * * @access public * * @param object &$obj The calling "parent" Text_Wiki object. * */ function Text_Wiki_Render(&$obj) { // keep a reference to the calling Text_Wiki object $this->wiki =& $obj; // get the config-key-name for this object, // strip the Text_Wiki_Render_ part // 01234567890123456 $tmp = get_class($this); $tmp = substr($tmp, 17); // split into pieces at the _ mark. // first part is format, second part is rule. $part = explode('_', $tmp); $this->format = isset($part[0]) ? ucwords(strtolower($part[0])) : null; $this->rule = isset($part[1]) ? ucwords(strtolower($part[1])) : null; // is there a format but no rule? // then this is the "main" render object, with // pre() and post() methods. if ($this->format && ! $this->rule && isset($this->wiki->formatConf[$this->format]) && is_array($this->wiki->formatConf[$this->format])) { // this is a format render object $this->conf = array_merge( $this->conf, $this->wiki->formatConf[$this->format] ); } // is there a format and a rule? if ($this->format && $this->rule && isset($this->wiki->renderConf[$this->format][$this->rule]) && is_array($this->wiki->renderConf[$this->format][$this->rule])) { // this is a rule render object $this->conf = array_merge( $this->conf, $this->wiki->renderConf[$this->format][$this->rule] ); } } /** * * Simple method to safely get configuration key values. * * @access public * * @param string $key The configuration key. * * @param mixed $default If the key does not exist, return this value * instead. * * @return mixed The configuration key value (if it exists) or the * default value (if not). * */ function getConf($key, $default = null) { if (isset($this->conf[$key])) { return $this->conf[$key]; } else { return $default; } } /** * * Simple method to wrap a configuration in an sprintf() format. * * @access public * * @param string $key The configuration key. * * @param string $format The sprintf() format string. * * @return mixed The formatted configuration key value (if it exists) * or null (if it does not). * */ function formatConf($format, $key) { if (isset($this->conf[$key])) { //$this->conf[$key] needs a textEncode....at least for Xhtml output... return sprintf($format, $this->conf[$key]); } else { return null; } } /** * Default method to render url * * @access public * @param string $urlChunk a part of an url to render * @return rendered url * */ function urlEncode($urlChunk) { return rawurlencode($urlChunk); } /** * Default method to render text (htmlspecialchars) * * @access public * @param string $text the text to render * @return rendered text * */ function textEncode($text) { return htmlspecialchars($text); } } ?> Text_Wiki-1.2.1/Text/Wiki.php0000600000175000017500000011676211461243356016560 0ustar clockwerxclockwerx * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: Wiki.php 248433 2007-12-17 16:03:48Z justinpatrin $ * @link http://pear.php.net/package/Text_Wiki */ /** * The baseline abstract parser class. */ require_once 'Text/Wiki/Parse.php'; /** * The baseline abstract render class. */ require_once 'Text/Wiki/Render.php'; /** * Parse structured wiki text and render into arbitrary formats such as XHTML. * * This is the "master" class for handling the management and convenience * functions to transform Wiki-formatted text. * * @category Text * @package Text_Wiki * @author Paul M. Jones * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version Release: 1.2.1 * @link http://pear.php.net/package/Text_Wiki */ class Text_Wiki { /** * * The default list of rules, in order, to apply to the source text. * * @access public * * @var array * */ var $rules = array( 'Prefilter', 'Delimiter', 'Code', 'Function', 'Html', 'Raw', 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', 'Break', 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup', 'Center', 'Newline', 'Paragraph', 'Url', 'Freelink', 'Interwiki', 'Wikilink', 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic', 'Underline', 'Tt', 'Superscript', 'Subscript', 'Revise', 'Tighten' ); /** * * The list of rules to not-apply to the source text. * * @access public * * @var array * */ var $disable = array( 'Html', 'Include', 'Embed' ); /** * * Custom configuration for rules at the parsing stage. * * In this array, the key is the parsing rule name, and the value is * an array of key-value configuration pairs corresponding to the $conf * property in the target parsing rule. * * For example: * * * $parseConf = array( * 'Include' => array( * 'base' => '/path/to/scripts/' * ) * ); * * * Note that most default rules do not need any parsing configuration. * * @access public * * @var array * */ var $parseConf = array(); /** * * Custom configuration for rules at the rendering stage. * * Because rendering may be different for each target format, the * first-level element in this array is always a format name (e.g., * 'Xhtml'). * * Within that first level element, the subsequent elements match the * $parseConf format. That is, the sub-key is the rendering rule name, * and the sub-value is an array of key-value configuration pairs * corresponding to the $conf property in the target rendering rule. * * @access public * * @var array * */ var $renderConf = array( 'Docbook' => array(), 'Latex' => array(), 'Pdf' => array(), 'Plain' => array(), 'Rtf' => array(), 'Xhtml' => array() ); /** * * Custom configuration for the output format itself. * * Even though Text_Wiki will render the tokens from parsed text, * the format itself may require some configuration. For example, * RTF needs to know font names and sizes, PDF requires page layout * information, and DocBook needs a section hierarchy. This array * matches the $conf property of the the format-level renderer * (e.g., Text_Wiki_Render_Xhtml). * * In this array, the key is the rendering format name, and the value is * an array of key-value configuration pairs corresponding to the $conf * property in the rendering format rule. * * @access public * * @var array * */ var $formatConf = array( 'Docbook' => array(), 'Latex' => array(), 'Pdf' => array(), 'Plain' => array(), 'Rtf' => array(), 'Xhtml' => array() ); /** * * The delimiter for token numbers of parsed elements in source text. * * @access public * * @var string * */ var $delim = "\31"; /** * * The tokens generated by rules as the source text is parsed. * * As Text_Wiki applies rule classes to the source text, it will * replace portions of the text with a delimited token number. This * is the array of those tokens, representing the replaced text and * any options set by the parser for that replaced text. * * The tokens array is sequential; each element is itself a sequential * array where element 0 is the name of the rule that generated the * token, and element 1 is an associative array where the key is an * option name and the value is an option value. * * @access private * * @var array * */ var $tokens = array(); /** * How many tokens generated pro rules. * * Intended to load only necessary render objects * * @access private * @var array */ var $_countRulesTokens = array(); /** * * The source text to which rules will be applied. * * This text will be transformed in-place, which means that it will * change as the rules are applied. * * @access private * * @var string * */ var $source = ''; /** * The output text * * @var string */ var $output = ''; /** * * Array of rule parsers. * * Text_Wiki creates one instance of every rule that is applied to * the source text; this array holds those instances. The array key * is the rule name, and the array value is an instance of the rule * class. * * @access private * * @var array * */ var $parseObj = array(); /** * * Array of rule renderers. * * Text_Wiki creates one instance of every rule that is applied to * the source text; this array holds those instances. The array key * is the rule name, and the array value is an instance of the rule * class. * * @access private * * @var array * */ var $renderObj = array(); /** * * Array of format renderers. * * @access private * * @var array * */ var $formatObj = array(); /** * * Array of paths to search, in order, for parsing and rendering rules. * * @access private * * @var array * */ var $path = array( 'parse' => array(), 'render' => array() ); /** * * The directory separator character. * * @access private * * @var string * */ var $_dirSep = DIRECTORY_SEPARATOR; /** * Temporary configuration variable * * @var string */ var $renderingType = 'normal'; /** * Stack of rendering callbacks * * @var Array */ var $_renderCallbacks = array(); /** * Current output block * * @var string */ var $_block; /** * A stack of blocks * * @param Array */ var $_blocks; /** * * Constructor. * * **DEPRECATED** * Please use the singleton() or factory() methods. * * @access public * * @param array $rules The set of rules to load for this object. Defaults * to null, which will load the default ruleset for this parser. */ function Text_Wiki($rules = null) { if (is_array($rules)) { $this->rules = array(); foreach ($rules as $rule) { $this->rules[] = ucfirst($rule); } } $this->addPath( 'parse', $this->fixPath(dirname(__FILE__)) . 'Wiki/Parse/Default/' ); $this->addPath( 'render', $this->fixPath(dirname(__FILE__)) . 'Wiki/Render/' ); } /** * Singleton. * * This avoids instantiating multiple Text_Wiki instances where a number * of objects are required in one call, e.g. to save memory in a * CMS invironment where several parsers are required in a single page. * * $single = & singleton(); * * or * * $single = & singleton('Parser', array('Prefilter', 'Delimiter', 'Code', 'Function', * 'Html', 'Raw', 'Include', 'Embed', 'Anchor', 'Heading', 'Toc', 'Horiz', * 'Break', 'Blockquote', 'List', 'Deflist', 'Table', 'Image', 'Phplookup', * 'Center', 'Newline', 'Paragraph', 'Url', 'Freelink', 'Interwiki', 'Wikilink', * 'Colortext', 'Strong', 'Bold', 'Emphasis', 'Italic', 'Underline', 'Tt', * 'Superscript', 'Subscript', 'Revise', 'Tighten')); * * Call using a subset of this list. The order of passing rulesets in the * $rules array is important! * * After calling this, call $single->setParseConf(), setRenderConf() or setFormatConf() * as usual for a constructed object of this class. * * The internal static array of singleton objects has no index on the parser * rules, the only index is on the parser name. So if you call this multiple * times with different rules but the same parser name, you will get the same * static parser object each time. * * @access public * @static * @since Method available since Release 1.1.0 * @param string $parser The parser to be used (defaults to 'Default'). * @param array $rules The set of rules to instantiate the object. This * will only be used when the first call to singleton is made, if included * in further calls it will be effectively ignored. * @return &object a reference to the Text_Wiki unique instantiation. */ function &singleton($parser = 'Default', $rules = null) { static $only = array(); if (!isset($only[$parser])) { $ret = & Text_Wiki::factory($parser, $rules); if (Text_Wiki::isError($ret)) { return $ret; } $only[$parser] =& $ret; } return $only[$parser]; } /** * Returns a Text_Wiki Parser class for the specified parser. * * @access public * @static * @param string $parser The name of the parse to instantiate * you need to have Text_Wiki_XXX installed to use $parser = 'XXX', it's E_FATAL * @param array $rules The rules to pass into the constructor * {@see Text_Wiki::singleton} for a list of rules * @return Text_Wiki a Parser object extended from Text_Wiki */ function &factory($parser = 'Default', $rules = null) { $class = 'Text_Wiki_' . $parser; $file = str_replace('_', '/', $class).'.php'; if (!class_exists($class)) { require_once $file; if (!class_exists($class)) { return Text_Wiki::error( 'Class ' . $class . ' does not exist after requiring '. $file . ', install package ' . $class . "\n"); } } $obj =& new $class($rules); return $obj; } /** * * Set parser configuration for a specific rule and key. * * @access public * * @param string $rule The parse rule to set config for. * * @param array|string $arg1 The full config array to use for the * parse rule, or a conf key in that array. * * @param string $arg2 The config value for the key. * * @return void * */ function setParseConf($rule, $arg1, $arg2 = null) { $rule = ucwords(strtolower($rule)); if (! isset($this->parseConf[$rule])) { $this->parseConf[$rule] = array(); } // if first arg is an array, use it as the entire // conf array for the rule. otherwise, treat arg1 // as a key and arg2 as a value for the rule conf. if (is_array($arg1)) { $this->parseConf[$rule] = $arg1; } else { $this->parseConf[$rule][$arg1] = $arg2; } } /** * * Get parser configuration for a specific rule and key. * * @access public * * @param string $rule The parse rule to get config for. * * @param string $key A key in the conf array; if null, * returns the entire conf array. * * @return mixed The whole conf array if no key is specified, * or the specific conf key value. * */ function getParseConf($rule, $key = null) { $rule = ucwords(strtolower($rule)); // the rule does not exist if (! isset($this->parseConf[$rule])) { return null; } // no key requested, return the whole array if (is_null($key)) { return $this->parseConf[$rule]; } // does the requested key exist? if (isset($this->parseConf[$rule][$key])) { // yes, return that value return $this->parseConf[$rule][$key]; } else { // no return null; } } /** * * Set renderer configuration for a specific format, rule, and key. * * @access public * * @param string $format The render format to set config for. * * @param string $rule The render rule to set config for in the format. * * @param array|string $arg1 The config array, or the config key * within the render rule. * * @param string $arg2 The config value for the key. * * @return void * */ function setRenderConf($format, $rule, $arg1, $arg2 = null) { $format = ucwords(strtolower($format)); $rule = ucwords(strtolower($rule)); if (! isset($this->renderConf[$format])) { $this->renderConf[$format] = array(); } if (! isset($this->renderConf[$format][$rule])) { $this->renderConf[$format][$rule] = array(); } // if first arg is an array, use it as the entire // conf array for the render rule. otherwise, treat arg1 // as a key and arg2 as a value for the render rule conf. if (is_array($arg1)) { $this->renderConf[$format][$rule] = $arg1; } else { $this->renderConf[$format][$rule][$arg1] = $arg2; } } /** * * Get renderer configuration for a specific format, rule, and key. * * @access public * * @param string $format The render format to get config for. * * @param string $rule The render format rule to get config for. * * @param string $key A key in the conf array; if null, * returns the entire conf array. * * @return mixed The whole conf array if no key is specified, * or the specific conf key value. * */ function getRenderConf($format, $rule, $key = null) { $format = ucwords(strtolower($format)); $rule = ucwords(strtolower($rule)); if (! isset($this->renderConf[$format]) || ! isset($this->renderConf[$format][$rule])) { return null; } // no key requested, return the whole array if (is_null($key)) { return $this->renderConf[$format][$rule]; } // does the requested key exist? if (isset($this->renderConf[$format][$rule][$key])) { // yes, return that value return $this->renderConf[$format][$rule][$key]; } else { // no return null; } } /** * * Set format configuration for a specific rule and key. * * @access public * * @param string $format The format to set config for. * * @param string $key The config key within the format. * * @param string $val The config value for the key. * * @return void * */ function setFormatConf($format, $arg1, $arg2 = null) { if (! is_array($this->formatConf[$format])) { $this->formatConf[$format] = array(); } // if first arg is an array, use it as the entire // conf array for the format. otherwise, treat arg1 // as a key and arg2 as a value for the format conf. if (is_array($arg1)) { $this->formatConf[$format] = $arg1; } else { $this->formatConf[$format][$arg1] = $arg2; } } /** * * Get configuration for a specific format and key. * * @access public * * @param string $format The format to get config for. * * @param mixed $key A key in the conf array; if null, * returns the entire conf array. * * @return mixed The whole conf array if no key is specified, * or the specific conf key value. * */ function getFormatConf($format, $key = null) { // the format does not exist if (! isset($this->formatConf[$format])) { return null; } // no key requested, return the whole array if (is_null($key)) { return $this->formatConf[$format]; } // does the requested key exist? if (isset($this->formatConf[$format][$key])) { // yes, return that value return $this->formatConf[$format][$key]; } else { // no return null; } } /** * * Inserts a rule into to the rule set. * * @access public * * @param string $name The name of the rule. Should be different from * all other keys in the rule set. * * @param string $tgt The rule after which to insert this new rule. By * default (null) the rule is inserted at the end; if set to '', inserts * at the beginning. * * @return void * */ function insertRule($name, $tgt = null) { $name = ucwords(strtolower($name)); if (! is_null($tgt)) { $tgt = ucwords(strtolower($tgt)); } // does the rule name to be inserted already exist? if (in_array($name, $this->rules)) { // yes, return return null; } // the target name is not null, and not '', but does not exist // in the list of rules. this means we're trying to insert after // a target key, but the target key isn't there. if (! is_null($tgt) && $tgt != '' && ! in_array($tgt, $this->rules)) { return false; } // if $tgt is null, insert at the end. We know this is at the // end (instead of resetting an existing rule) becuase we exited // at the top of this method if the rule was already in place. if (is_null($tgt)) { $this->rules[] = $name; return true; } // save a copy of the current rules, then reset the rule set // so we can insert in the proper place later. // where to insert the rule? if ($tgt == '') { // insert at the beginning array_unshift($this->rules, $name); return true; } // insert after the named rule $tmp = $this->rules; $this->rules = array(); foreach ($tmp as $val) { $this->rules[] = $val; if ($val == $tgt) { $this->rules[] = $name; } } return true; } /** * * Delete (remove or unset) a rule from the $rules property. * * @access public * * @param string $rule The name of the rule to remove. * * @return void * */ function deleteRule($name) { $name = ucwords(strtolower($name)); $key = array_search($name, $this->rules); if ($key !== false) { unset($this->rules[$key]); } } /** * * Change from one rule to another in-place. * * @access public * * @param string $old The name of the rule to change from. * * @param string $new The name of the rule to change to. * * @return void * */ function changeRule($old, $new) { $old = ucwords(strtolower($old)); $new = ucwords(strtolower($new)); $key = array_search($old, $this->rules); if ($key !== false) { // delete the new name , case it was already there $this->deleteRule($new); $this->rules[$key] = $new; } } /** * * Enables a rule so that it is applied when parsing. * * @access public * * @param string $rule The name of the rule to enable. * * @return void * */ function enableRule($name) { $name = ucwords(strtolower($name)); $key = array_search($name, $this->disable); if ($key !== false) { unset($this->disable[$key]); } } /** * * Disables a rule so that it is not applied when parsing. * * @access public * * @param string $rule The name of the rule to disable. * * @return void * */ function disableRule($name) { $name = ucwords(strtolower($name)); $key = array_search($name, $this->disable); if ($key === false) { $this->disable[] = $name; } } /** * * Parses and renders the text passed to it, and returns the results. * * First, the method parses the source text, applying rules to the * text as it goes. These rules will modify the source text * in-place, replacing some text with delimited tokens (and * populating the $this->tokens array as it goes). * * Next, the method renders the in-place tokens into the requested * output format. * * Finally, the method returns the transformed text. Note that the * source text is transformed in place; once it is transformed, it is * no longer the same as the original source text. * * @access public * * @param string $text The source text to which wiki rules should be * applied, both for parsing and for rendering. * * @param string $format The target output format, typically 'xhtml'. * If a rule does not support a given format, the output from that * rule is rule-specific. * * @return string The transformed wiki text. * */ function transform($text, $format = 'Xhtml') { $this->parse($text); return $this->render($format); } /** * * Sets the $_source text property, then parses it in place and * retains tokens in the $_tokens array property. * * @access public * * @param string $text The source text to which wiki rules should be * applied, both for parsing and for rendering. * * @return void * */ function parse($text) { // set the object property for the source text $this->source = $text; // reset the tokens. $this->tokens = array(); $this->_countRulesTokens = array(); // apply the parse() method of each requested rule to the source // text. foreach ($this->rules as $name) { // do not parse the rules listed in $disable if (! in_array($name, $this->disable)) { // load the parsing object $this->loadParseObj($name); // load may have failed; only parse if // an object is in the array now if (is_object($this->parseObj[$name])) { $this->parseObj[$name]->parse(); } } } } /** * * Renders tokens back into the source text, based on the requested format. * * @access public * * @param string $format The target output format, typically 'xhtml'. * If a rule does not support a given format, the output from that * rule is rule-specific. * * @return string The transformed wiki text. * */ function render($format = 'Xhtml') { // the rendering method we're going to use from each rule $format = ucwords(strtolower($format)); // the eventual output text $this->output = ''; // when passing through the parsed source text, keep track of when // we are in a delimited section $in_delim = false; // when in a delimited section, capture the token key number $key = ''; // load the format object, or crap out if we can't find it $result = $this->loadFormatObj($format); if ($this->isError($result)) { return $result; } // pre-rendering activity if (is_object($this->formatObj[$format])) { $this->output .= $this->formatObj[$format]->pre(); } // load the render objects foreach (array_keys($this->_countRulesTokens) as $rule) { $this->loadRenderObj($format, $rule); } if ($this->renderingType == 'preg') { $this->output = preg_replace_callback('/'.$this->delim.'(\d+)'.$this->delim.'/', array(&$this, '_renderToken'), $this->source); /* //Damn strtok()! Why does it "skip" empty parts of the string. It's useless now! } elseif ($this->renderingType == 'strtok') { echo '
'.htmlentities($this->source).'
'; $t = strtok($this->source, $this->delim); $inToken = true; $i = 0; while ($t !== false) { echo 'Token: '.$i.'
"'.htmlentities($t).'"


'; if ($inToken) { //$this->output .= $this->renderObj[$this->tokens[$t][0]]->token($this->tokens[$t][1]); } else { $this->output .= $t; } $inToken = !$inToken; $t = strtok($this->delim); ++$i; } */ } else { // pass through the parsed source text character by character $this->_block = ''; $tokenStack = array(); $k = strlen($this->source); for ($i = 0; $i < $k; $i++) { // the current character $char = $this->source{$i}; // are alredy in a delimited section? if ($in_delim) { // yes; are we ending the section? if ($char == $this->delim) { if (count($this->_renderCallbacks) == 0) { $this->output .= $this->_block; $this->_block = ''; } if (isset($opts['type'])) { if ($opts['type'] == 'start') { array_push($tokenStack, $rule); } elseif ($opts['type'] == 'end') { if ($tokenStack[count($tokenStack) - 1] != $rule) { return Text_Wiki::error('Unbalanced tokens, check your syntax'); } else { array_pop($tokenStack); } } } // yes, get the replacement text for the delimited // token number and unset the flag. $key = (int)$key; $rule = $this->tokens[$key][0]; $opts = $this->tokens[$key][1]; $this->_block .= $this->renderObj[$rule]->token($opts); $in_delim = false; } else { // no, add to the delimited token key number $key .= $char; } } else { // not currently in a delimited section. // are we starting into a delimited section? if ($char == $this->delim) { // yes, reset the previous key and // set the flag. $key = ''; $in_delim = true; } else { // no, add to the output as-is $this->_block .= $char; } } } } if (count($this->_renderCallbacks)) { return $this->error('Render callbacks left over after processing finished'); } /* while (count($this->_renderCallbacks)) { $this->popRenderCallback(); } */ if (strlen($this->_block)) { $this->output .= $this->_block; $this->_block = ''; } // post-rendering activity if (is_object($this->formatObj[$format])) { $this->output .= $this->formatObj[$format]->post(); } // return the rendered source text. return $this->output; } /** * Renders a token, for use only as an internal callback * * @param array Matches from preg_rpelace_callback, [1] is the token number * @return string The rendered text for the token * @access private */ function _renderToken($matches) { return $this->renderObj[$this->tokens[$matches[1]][0]]->token($this->tokens[$matches[1]][1]); } function registerRenderCallback($callback) { $this->_blocks[] = $this->_block; $this->_block = ''; $this->_renderCallbacks[] = $callback; } function popRenderCallback() { if (count($this->_renderCallbacks) == 0) { return Text_Wiki::error('Render callback popped when no render callbacks in stack'); } else { $callback = array_pop($this->_renderCallbacks); $this->_block = call_user_func($callback, $this->_block); if (count($this->_blocks)) { $parentBlock = array_pop($this->_blocks); $this->_block = $parentBlock.$this->_block; } if (count($this->_renderCallbacks) == 0) { $this->output .= $this->_block; $this->_block = ''; } } } /** * * Returns the parsed source text with delimited token placeholders. * * @access public * * @return string The parsed source text. * */ function getSource() { return $this->source; } /** * * Returns tokens that have been parsed out of the source text. * * @access public * * @param array $rules If an array of rule names is passed, only return * tokens matching these rule names. If no array is passed, return all * tokens. * * @return array An array of tokens. * */ function getTokens($rules = null) { if (is_null($rules)) { return $this->tokens; } else { settype($rules, 'array'); $result = array(); foreach ($this->tokens as $key => $val) { if (in_array($val[0], $rules)) { $result[$key] = $val; } } return $result; } } /** * * Add a token to the Text_Wiki tokens array, and return a delimited * token number. * * @access public * * @param array $options An associative array of options for the new * token array element. The keys and values are specific to the * rule, and may or may not be common to other rule options. Typical * options keys are 'text' and 'type' but may include others. * * @param boolean $id_only If true, return only the token number, not * a delimited token string. * * @return string|int By default, return the number of the * newly-created token array element with a delimiter prefix and * suffix; however, if $id_only is set to true, return only the token * number (no delimiters). * */ function addToken($rule, $options = array(), $id_only = false) { // increment the token ID number. note that if you parse // multiple times with the same Text_Wiki object, the ID number // will not reset to zero. static $id; if (! isset($id)) { $id = 0; } else { $id ++; } // force the options to be an array settype($options, 'array'); // add the token $this->tokens[$id] = array( 0 => $rule, 1 => $options ); if (!isset($this->_countRulesTokens[$rule])) { $this->_countRulesTokens[$rule] = 1; } else { ++$this->_countRulesTokens[$rule]; } // return a value if ($id_only) { // return the last token number return $id; } else { // return the token number with delimiters return $this->delim . $id . $this->delim; } } /** * * Set or re-set a token with specific information, overwriting any * previous rule name and rule options. * * @access public * * @param int $id The token number to reset. * * @param int $rule The rule name to use. * * @param array $options An associative array of options for the * token array element. The keys and values are specific to the * rule, and may or may not be common to other rule options. Typical * options keys are 'text' and 'type' but may include others. * * @return void * */ function setToken($id, $rule, $options = array()) { $oldRule = $this->tokens[$id][0]; // reset the token $this->tokens[$id] = array( 0 => $rule, 1 => $options ); if ($rule != $oldRule) { if (!($this->_countRulesTokens[$oldRule]--)) { unset($this->_countRulesTokens[$oldRule]); } if (!isset($this->_countRulesTokens[$rule])) { $this->_countRulesTokens[$rule] = 1; } else { ++$this->_countRulesTokens[$rule]; } } } /** * * Load a rule parser class file. * * @access public * * @return bool True if loaded, false if not. * */ function loadParseObj($rule) { $rule = ucwords(strtolower($rule)); $file = $rule . '.php'; $class = "Text_Wiki_Parse_$rule"; if (! class_exists($class)) { $loc = $this->findFile('parse', $file); if ($loc) { // found the class include_once $loc; } else { // can't find the class $this->parseObj[$rule] = null; // can't find the class return $this->error( "Parse rule '$rule' not found" ); } } $this->parseObj[$rule] =& new $class($this); } /** * * Load a rule-render class file. * * @access public * * @return bool True if loaded, false if not. * */ function loadRenderObj($format, $rule) { $format = ucwords(strtolower($format)); $rule = ucwords(strtolower($rule)); $file = "$format/$rule.php"; $class = "Text_Wiki_Render_$format" . "_$rule"; if (! class_exists($class)) { // load the class $loc = $this->findFile('render', $file); if ($loc) { // found the class include_once $loc; } else { // can't find the class return $this->error( "Render rule '$rule' in format '$format' not found" ); } } $this->renderObj[$rule] =& new $class($this); } /** * * Load a format-render class file. * * @access public * * @return bool True if loaded, false if not. * */ function loadFormatObj($format) { $format = ucwords(strtolower($format)); $file = $format . '.php'; $class = "Text_Wiki_Render_$format"; if (! class_exists($class)) { $loc = $this->findFile('render', $file); if ($loc) { // found the class include_once $loc; } else { // can't find the class return $this->error( "Rendering format class '$class' not found" ); } } $this->formatObj[$format] =& new $class($this); } /** * * Add a path to a path array. * * @access public * * @param string $type The path-type to add (parse or render). * * @param string $dir The directory to add to the path-type. * * @return void * */ function addPath($type, $dir) { $dir = $this->fixPath($dir); if (! isset($this->path[$type])) { $this->path[$type] = array($dir); } else { array_unshift($this->path[$type], $dir); } } /** * * Get the current path array for a path-type. * * @access public * * @param string $type The path-type to look up (plugin, filter, or * template). If not set, returns all path types. * * @return array The array of paths for the requested type. * */ function getPath($type = null) { if (is_null($type)) { return $this->path; } elseif (! isset($this->path[$type])) { return array(); } else { return $this->path[$type]; } } /** * * Searches a series of paths for a given file. * * @param array $type The type of paths to search (template, plugin, * or filter). * * @param string $file The file name to look for. * * @return string|bool The full path and file name for the target file, * or boolean false if the file is not found in any of the paths. * */ function findFile($type, $file) { // get the set of paths $set = $this->getPath($type); // start looping through them foreach ($set as $path) { $fullname = $path . $file; if (file_exists($fullname) && is_readable($fullname)) { return $fullname; } } // could not find the file in the set of paths return false; } /** * * Append a trailing '/' to paths, unless the path is empty. * * @access private * * @param string $path The file path to fix * * @return string The fixed file path * */ function fixPath($path) { $len = strlen($this->_dirSep); if (! empty($path) && substr($path, -1 * $len, $len) != $this->_dirSep) { return $path . $this->_dirSep; } else { return $path; } } /** * * Simple error-object generator. * * @access public * * @param string $message The error message. * * @return object PEAR_Error * */ function &error($message) { if (! class_exists('PEAR_Error')) { include_once 'PEAR.php'; } return PEAR::throwError($message); } /** * * Simple error checker. * * @access public * * @param mixed $obj Check if this is a PEAR_Error object or not. * * @return bool True if a PEAR_Error, false if not. * */ function isError(&$obj) { return is_a($obj, 'PEAR_Error'); } } ?>