Initial Commit
This commit is contained in:
453
database/php/pear/Text/Diff.php
Normal file
453
database/php/pear/Text/Diff.php
Normal file
@@ -0,0 +1,453 @@
|
||||
<?php
|
||||
/**
|
||||
* General API for generating and formatting diffs - the differences between
|
||||
* two sequences of strings.
|
||||
*
|
||||
* The original PHP version of this code was written by Geoffrey T. Dairiki
|
||||
* <dairiki@dairiki.org>, and is used/adapted with his permission.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff.php,v 1.11.2.12 2009/01/06 15:23:41 jan Exp $
|
||||
*
|
||||
* Copyright 2004 Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*/
|
||||
class Text_Diff {
|
||||
|
||||
/**
|
||||
* Array of changes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $_edits;
|
||||
|
||||
/**
|
||||
* Computes diffs between sequences of strings.
|
||||
*
|
||||
* @param string $engine Name of the diffing engine to use. 'auto'
|
||||
* will automatically select the best.
|
||||
* @param array $params Parameters to pass to the diffing engine.
|
||||
* Normally an array of two arrays, each
|
||||
* containing the lines from a file.
|
||||
*/
|
||||
function Text_Diff($engine, $params)
|
||||
{
|
||||
// Backward compatibility workaround.
|
||||
if (!is_string($engine)) {
|
||||
$params = array($engine, $params);
|
||||
$engine = 'auto';
|
||||
}
|
||||
|
||||
if ($engine == 'auto') {
|
||||
$engine = extension_loaded('xdiff') ? 'xdiff' : 'native';
|
||||
} else {
|
||||
$engine = basename($engine);
|
||||
}
|
||||
|
||||
require_once 'Text/Diff/Engine/' . $engine . '.php';
|
||||
$class = 'Text_Diff_Engine_' . $engine;
|
||||
$diff_engine = new $class();
|
||||
|
||||
$this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of differences.
|
||||
*/
|
||||
function getDiff()
|
||||
{
|
||||
return $this->_edits;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the number of new (added) lines in a given diff.
|
||||
*
|
||||
* @since Text_Diff 1.1.0
|
||||
* @since Horde 3.2
|
||||
*
|
||||
* @return integer The number of new lines
|
||||
*/
|
||||
function countAddedLines()
|
||||
{
|
||||
$count = 0;
|
||||
foreach ($this->_edits as $edit) {
|
||||
if (is_a($edit, 'Text_Diff_Op_add') ||
|
||||
is_a($edit, 'Text_Diff_Op_change')) {
|
||||
$count += $edit->nfinal();
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of deleted (removed) lines in a given diff.
|
||||
*
|
||||
* @since Text_Diff 1.1.0
|
||||
* @since Horde 3.2
|
||||
*
|
||||
* @return integer The number of deleted lines
|
||||
*/
|
||||
function countDeletedLines()
|
||||
{
|
||||
$count = 0;
|
||||
foreach ($this->_edits as $edit) {
|
||||
if (is_a($edit, 'Text_Diff_Op_delete') ||
|
||||
is_a($edit, 'Text_Diff_Op_change')) {
|
||||
$count += $edit->norig();
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a reversed diff.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $diff = new Text_Diff($lines1, $lines2);
|
||||
* $rev = $diff->reverse();
|
||||
* </code>
|
||||
*
|
||||
* @return Text_Diff A Diff object representing the inverse of the
|
||||
* original diff. Note that we purposely don't return a
|
||||
* reference here, since this essentially is a clone()
|
||||
* method.
|
||||
*/
|
||||
function reverse()
|
||||
{
|
||||
if (version_compare(zend_version(), '2', '>')) {
|
||||
$rev = clone($this);
|
||||
} else {
|
||||
$rev = $this;
|
||||
}
|
||||
$rev->_edits = array();
|
||||
foreach ($this->_edits as $edit) {
|
||||
$rev->_edits[] = $edit->reverse();
|
||||
}
|
||||
return $rev;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for an empty diff.
|
||||
*
|
||||
* @return boolean True if two sequences were identical.
|
||||
*/
|
||||
function isEmpty()
|
||||
{
|
||||
foreach ($this->_edits as $edit) {
|
||||
if (!is_a($edit, 'Text_Diff_Op_copy')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the length of the Longest Common Subsequence (LCS).
|
||||
*
|
||||
* This is mostly for diagnostic purposes.
|
||||
*
|
||||
* @return integer The length of the LCS.
|
||||
*/
|
||||
function lcs()
|
||||
{
|
||||
$lcs = 0;
|
||||
foreach ($this->_edits as $edit) {
|
||||
if (is_a($edit, 'Text_Diff_Op_copy')) {
|
||||
$lcs += count($edit->orig);
|
||||
}
|
||||
}
|
||||
return $lcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the original set of lines.
|
||||
*
|
||||
* This reconstructs the $from_lines parameter passed to the constructor.
|
||||
*
|
||||
* @return array The original sequence of strings.
|
||||
*/
|
||||
function getOriginal()
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($this->_edits as $edit) {
|
||||
if ($edit->orig) {
|
||||
array_splice($lines, count($lines), 0, $edit->orig);
|
||||
}
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the final set of lines.
|
||||
*
|
||||
* This reconstructs the $to_lines parameter passed to the constructor.
|
||||
*
|
||||
* @return array The sequence of strings.
|
||||
*/
|
||||
function getFinal()
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($this->_edits as $edit) {
|
||||
if ($edit->final) {
|
||||
array_splice($lines, count($lines), 0, $edit->final);
|
||||
}
|
||||
}
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes trailing newlines from a line of text. This is meant to be used
|
||||
* with array_walk().
|
||||
*
|
||||
* @param string $line The line to trim.
|
||||
* @param integer $key The index of the line in the array. Not used.
|
||||
*/
|
||||
function trimNewlines(&$line, $key)
|
||||
{
|
||||
$line = str_replace(array("\n", "\r"), '', $line);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the location of the system temporary directory.
|
||||
*
|
||||
* @static
|
||||
*
|
||||
* @access protected
|
||||
*
|
||||
* @return string A directory name which can be used for temp files.
|
||||
* Returns false if one could not be found.
|
||||
*/
|
||||
function _getTempDir()
|
||||
{
|
||||
$tmp_locations = array('/tmp', '/var/tmp', 'c:\WUTemp', 'c:\temp',
|
||||
'c:\windows\temp', 'c:\winnt\temp');
|
||||
|
||||
/* Try PHP's upload_tmp_dir directive. */
|
||||
$tmp = ini_get('upload_tmp_dir');
|
||||
|
||||
/* Otherwise, try to determine the TMPDIR environment variable. */
|
||||
if (!strlen($tmp)) {
|
||||
$tmp = getenv('TMPDIR');
|
||||
}
|
||||
|
||||
/* If we still cannot determine a value, then cycle through a list of
|
||||
* preset possibilities. */
|
||||
while (!strlen($tmp) && count($tmp_locations)) {
|
||||
$tmp_check = array_shift($tmp_locations);
|
||||
if (@is_dir($tmp_check)) {
|
||||
$tmp = $tmp_check;
|
||||
}
|
||||
}
|
||||
|
||||
/* If it is still empty, we have failed, so return false; otherwise
|
||||
* return the directory determined. */
|
||||
return strlen($tmp) ? $tmp : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a diff for validity.
|
||||
*
|
||||
* This is here only for debugging purposes.
|
||||
*/
|
||||
function _check($from_lines, $to_lines)
|
||||
{
|
||||
if (serialize($from_lines) != serialize($this->getOriginal())) {
|
||||
trigger_error("Reconstructed original doesn't match", E_USER_ERROR);
|
||||
}
|
||||
if (serialize($to_lines) != serialize($this->getFinal())) {
|
||||
trigger_error("Reconstructed final doesn't match", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$rev = $this->reverse();
|
||||
if (serialize($to_lines) != serialize($rev->getOriginal())) {
|
||||
trigger_error("Reversed original doesn't match", E_USER_ERROR);
|
||||
}
|
||||
if (serialize($from_lines) != serialize($rev->getFinal())) {
|
||||
trigger_error("Reversed final doesn't match", E_USER_ERROR);
|
||||
}
|
||||
|
||||
$prevtype = null;
|
||||
foreach ($this->_edits as $edit) {
|
||||
if ($prevtype == get_class($edit)) {
|
||||
trigger_error("Edit sequence is non-optimal", E_USER_ERROR);
|
||||
}
|
||||
$prevtype = get_class($edit);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*/
|
||||
class Text_MappedDiff extends Text_Diff {
|
||||
|
||||
/**
|
||||
* Computes a diff between sequences of strings.
|
||||
*
|
||||
* This can be used to compute things like case-insensitve diffs, or diffs
|
||||
* which ignore changes in white-space.
|
||||
*
|
||||
* @param array $from_lines An array of strings.
|
||||
* @param array $to_lines An array of strings.
|
||||
* @param array $mapped_from_lines This array should have the same size
|
||||
* number of elements as $from_lines. The
|
||||
* elements in $mapped_from_lines and
|
||||
* $mapped_to_lines are what is actually
|
||||
* compared when computing the diff.
|
||||
* @param array $mapped_to_lines This array should have the same number
|
||||
* of elements as $to_lines.
|
||||
*/
|
||||
function Text_MappedDiff($from_lines, $to_lines,
|
||||
$mapped_from_lines, $mapped_to_lines)
|
||||
{
|
||||
assert(count($from_lines) == count($mapped_from_lines));
|
||||
assert(count($to_lines) == count($mapped_to_lines));
|
||||
|
||||
parent::Text_Diff($mapped_from_lines, $mapped_to_lines);
|
||||
|
||||
$xi = $yi = 0;
|
||||
for ($i = 0; $i < count($this->_edits); $i++) {
|
||||
$orig = &$this->_edits[$i]->orig;
|
||||
if (is_array($orig)) {
|
||||
$orig = array_slice($from_lines, $xi, count($orig));
|
||||
$xi += count($orig);
|
||||
}
|
||||
|
||||
$final = &$this->_edits[$i]->final;
|
||||
if (is_array($final)) {
|
||||
$final = array_slice($to_lines, $yi, count($final));
|
||||
$yi += count($final);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_Op {
|
||||
|
||||
var $orig;
|
||||
var $final;
|
||||
|
||||
function &reverse()
|
||||
{
|
||||
trigger_error('Abstract method', E_USER_ERROR);
|
||||
}
|
||||
|
||||
function norig()
|
||||
{
|
||||
return $this->orig ? count($this->orig) : 0;
|
||||
}
|
||||
|
||||
function nfinal()
|
||||
{
|
||||
return $this->final ? count($this->final) : 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_Op_copy extends Text_Diff_Op {
|
||||
|
||||
function Text_Diff_Op_copy($orig, $final = false)
|
||||
{
|
||||
if (!is_array($final)) {
|
||||
$final = $orig;
|
||||
}
|
||||
$this->orig = $orig;
|
||||
$this->final = $final;
|
||||
}
|
||||
|
||||
function &reverse()
|
||||
{
|
||||
$reverse = &new Text_Diff_Op_copy($this->final, $this->orig);
|
||||
return $reverse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_Op_delete extends Text_Diff_Op {
|
||||
|
||||
function Text_Diff_Op_delete($lines)
|
||||
{
|
||||
$this->orig = $lines;
|
||||
$this->final = false;
|
||||
}
|
||||
|
||||
function &reverse()
|
||||
{
|
||||
$reverse = &new Text_Diff_Op_add($this->orig);
|
||||
return $reverse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_Op_add extends Text_Diff_Op {
|
||||
|
||||
function Text_Diff_Op_add($lines)
|
||||
{
|
||||
$this->final = $lines;
|
||||
$this->orig = false;
|
||||
}
|
||||
|
||||
function &reverse()
|
||||
{
|
||||
$reverse = &new Text_Diff_Op_delete($this->final);
|
||||
return $reverse;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_Op_change extends Text_Diff_Op {
|
||||
|
||||
function Text_Diff_Op_change($orig, $final)
|
||||
{
|
||||
$this->orig = $orig;
|
||||
$this->final = $final;
|
||||
}
|
||||
|
||||
function &reverse()
|
||||
{
|
||||
$reverse = &new Text_Diff_Op_change($this->final, $this->orig);
|
||||
return $reverse;
|
||||
}
|
||||
|
||||
}
|
||||
438
database/php/pear/Text/Diff/Engine/native.php
Normal file
438
database/php/pear/Text/Diff/Engine/native.php
Normal file
@@ -0,0 +1,438 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used internally by Text_Diff to actually compute the diffs.
|
||||
*
|
||||
* This class is implemented using native PHP code.
|
||||
*
|
||||
* The algorithm used here is mostly lifted from the perl module
|
||||
* Algorithm::Diff (version 1.06) by Ned Konz, which is available at:
|
||||
* http://www.perl.com/CPAN/authors/id/N/NE/NEDKONZ/Algorithm-Diff-1.06.zip
|
||||
*
|
||||
* More ideas are taken from: http://www.ics.uci.edu/~eppstein/161/960229.html
|
||||
*
|
||||
* Some ideas (and a bit of code) are taken from analyze.c, of GNU
|
||||
* diffutils-2.7, which can be found at:
|
||||
* ftp://gnudist.gnu.org/pub/gnu/diffutils/diffutils-2.7.tar.gz
|
||||
*
|
||||
* Some ideas (subdivision by NCHUNKS > 2, and some optimizations) are from
|
||||
* Geoffrey T. Dairiki <dairiki@dairiki.org>. The original PHP version of this
|
||||
* code was written by him, and is used/adapted with his permission.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/native.php,v 1.7.2.5 2009/01/06 15:23:41 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
* @package Text_Diff
|
||||
*/
|
||||
class Text_Diff_Engine_native {
|
||||
|
||||
function diff($from_lines, $to_lines)
|
||||
{
|
||||
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
|
||||
array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
|
||||
|
||||
$n_from = count($from_lines);
|
||||
$n_to = count($to_lines);
|
||||
|
||||
$this->xchanged = $this->ychanged = array();
|
||||
$this->xv = $this->yv = array();
|
||||
$this->xind = $this->yind = array();
|
||||
unset($this->seq);
|
||||
unset($this->in_seq);
|
||||
unset($this->lcs);
|
||||
|
||||
// Skip leading common lines.
|
||||
for ($skip = 0; $skip < $n_from && $skip < $n_to; $skip++) {
|
||||
if ($from_lines[$skip] !== $to_lines[$skip]) {
|
||||
break;
|
||||
}
|
||||
$this->xchanged[$skip] = $this->ychanged[$skip] = false;
|
||||
}
|
||||
|
||||
// Skip trailing common lines.
|
||||
$xi = $n_from; $yi = $n_to;
|
||||
for ($endskip = 0; --$xi > $skip && --$yi > $skip; $endskip++) {
|
||||
if ($from_lines[$xi] !== $to_lines[$yi]) {
|
||||
break;
|
||||
}
|
||||
$this->xchanged[$xi] = $this->ychanged[$yi] = false;
|
||||
}
|
||||
|
||||
// Ignore lines which do not exist in both files.
|
||||
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
|
||||
$xhash[$from_lines[$xi]] = 1;
|
||||
}
|
||||
for ($yi = $skip; $yi < $n_to - $endskip; $yi++) {
|
||||
$line = $to_lines[$yi];
|
||||
if (($this->ychanged[$yi] = empty($xhash[$line]))) {
|
||||
continue;
|
||||
}
|
||||
$yhash[$line] = 1;
|
||||
$this->yv[] = $line;
|
||||
$this->yind[] = $yi;
|
||||
}
|
||||
for ($xi = $skip; $xi < $n_from - $endskip; $xi++) {
|
||||
$line = $from_lines[$xi];
|
||||
if (($this->xchanged[$xi] = empty($yhash[$line]))) {
|
||||
continue;
|
||||
}
|
||||
$this->xv[] = $line;
|
||||
$this->xind[] = $xi;
|
||||
}
|
||||
|
||||
// Find the LCS.
|
||||
$this->_compareseq(0, count($this->xv), 0, count($this->yv));
|
||||
|
||||
// Merge edits when possible.
|
||||
$this->_shiftBoundaries($from_lines, $this->xchanged, $this->ychanged);
|
||||
$this->_shiftBoundaries($to_lines, $this->ychanged, $this->xchanged);
|
||||
|
||||
// Compute the edit operations.
|
||||
$edits = array();
|
||||
$xi = $yi = 0;
|
||||
while ($xi < $n_from || $yi < $n_to) {
|
||||
assert($yi < $n_to || $this->xchanged[$xi]);
|
||||
assert($xi < $n_from || $this->ychanged[$yi]);
|
||||
|
||||
// Skip matching "snake".
|
||||
$copy = array();
|
||||
while ($xi < $n_from && $yi < $n_to
|
||||
&& !$this->xchanged[$xi] && !$this->ychanged[$yi]) {
|
||||
$copy[] = $from_lines[$xi++];
|
||||
++$yi;
|
||||
}
|
||||
if ($copy) {
|
||||
$edits[] = &new Text_Diff_Op_copy($copy);
|
||||
}
|
||||
|
||||
// Find deletes & adds.
|
||||
$delete = array();
|
||||
while ($xi < $n_from && $this->xchanged[$xi]) {
|
||||
$delete[] = $from_lines[$xi++];
|
||||
}
|
||||
|
||||
$add = array();
|
||||
while ($yi < $n_to && $this->ychanged[$yi]) {
|
||||
$add[] = $to_lines[$yi++];
|
||||
}
|
||||
|
||||
if ($delete && $add) {
|
||||
$edits[] = &new Text_Diff_Op_change($delete, $add);
|
||||
} elseif ($delete) {
|
||||
$edits[] = &new Text_Diff_Op_delete($delete);
|
||||
} elseif ($add) {
|
||||
$edits[] = &new Text_Diff_Op_add($add);
|
||||
}
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Divides the Largest Common Subsequence (LCS) of the sequences (XOFF,
|
||||
* XLIM) and (YOFF, YLIM) into NCHUNKS approximately equally sized
|
||||
* segments.
|
||||
*
|
||||
* Returns (LCS, PTS). LCS is the length of the LCS. PTS is an array of
|
||||
* NCHUNKS+1 (X, Y) indexes giving the diving points between sub
|
||||
* sequences. The first sub-sequence is contained in (X0, X1), (Y0, Y1),
|
||||
* the second in (X1, X2), (Y1, Y2) and so on. Note that (X0, Y0) ==
|
||||
* (XOFF, YOFF) and (X[NCHUNKS], Y[NCHUNKS]) == (XLIM, YLIM).
|
||||
*
|
||||
* This function assumes that the first lines of the specified portions of
|
||||
* the two files do not match, and likewise that the last lines do not
|
||||
* match. The caller must trim matching lines from the beginning and end
|
||||
* of the portions it is going to specify.
|
||||
*/
|
||||
function _diag ($xoff, $xlim, $yoff, $ylim, $nchunks)
|
||||
{
|
||||
$flip = false;
|
||||
|
||||
if ($xlim - $xoff > $ylim - $yoff) {
|
||||
/* Things seems faster (I'm not sure I understand why) when the
|
||||
* shortest sequence is in X. */
|
||||
$flip = true;
|
||||
list ($xoff, $xlim, $yoff, $ylim)
|
||||
= array($yoff, $ylim, $xoff, $xlim);
|
||||
}
|
||||
|
||||
if ($flip) {
|
||||
for ($i = $ylim - 1; $i >= $yoff; $i--) {
|
||||
$ymatches[$this->xv[$i]][] = $i;
|
||||
}
|
||||
} else {
|
||||
for ($i = $ylim - 1; $i >= $yoff; $i--) {
|
||||
$ymatches[$this->yv[$i]][] = $i;
|
||||
}
|
||||
}
|
||||
|
||||
$this->lcs = 0;
|
||||
$this->seq[0]= $yoff - 1;
|
||||
$this->in_seq = array();
|
||||
$ymids[0] = array();
|
||||
|
||||
$numer = $xlim - $xoff + $nchunks - 1;
|
||||
$x = $xoff;
|
||||
for ($chunk = 0; $chunk < $nchunks; $chunk++) {
|
||||
if ($chunk > 0) {
|
||||
for ($i = 0; $i <= $this->lcs; $i++) {
|
||||
$ymids[$i][$chunk - 1] = $this->seq[$i];
|
||||
}
|
||||
}
|
||||
|
||||
$x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $chunk) / $nchunks);
|
||||
for (; $x < $x1; $x++) {
|
||||
$line = $flip ? $this->yv[$x] : $this->xv[$x];
|
||||
if (empty($ymatches[$line])) {
|
||||
continue;
|
||||
}
|
||||
$matches = $ymatches[$line];
|
||||
reset($matches);
|
||||
while (list(, $y) = each($matches)) {
|
||||
if (empty($this->in_seq[$y])) {
|
||||
$k = $this->_lcsPos($y);
|
||||
assert($k > 0);
|
||||
$ymids[$k] = $ymids[$k - 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (list(, $y) = each($matches)) {
|
||||
if ($y > $this->seq[$k - 1]) {
|
||||
assert($y <= $this->seq[$k]);
|
||||
/* Optimization: this is a common case: next match is
|
||||
* just replacing previous match. */
|
||||
$this->in_seq[$this->seq[$k]] = false;
|
||||
$this->seq[$k] = $y;
|
||||
$this->in_seq[$y] = 1;
|
||||
} elseif (empty($this->in_seq[$y])) {
|
||||
$k = $this->_lcsPos($y);
|
||||
assert($k > 0);
|
||||
$ymids[$k] = $ymids[$k - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$seps[] = $flip ? array($yoff, $xoff) : array($xoff, $yoff);
|
||||
$ymid = $ymids[$this->lcs];
|
||||
for ($n = 0; $n < $nchunks - 1; $n++) {
|
||||
$x1 = $xoff + (int)(($numer + ($xlim - $xoff) * $n) / $nchunks);
|
||||
$y1 = $ymid[$n] + 1;
|
||||
$seps[] = $flip ? array($y1, $x1) : array($x1, $y1);
|
||||
}
|
||||
$seps[] = $flip ? array($ylim, $xlim) : array($xlim, $ylim);
|
||||
|
||||
return array($this->lcs, $seps);
|
||||
}
|
||||
|
||||
function _lcsPos($ypos)
|
||||
{
|
||||
$end = $this->lcs;
|
||||
if ($end == 0 || $ypos > $this->seq[$end]) {
|
||||
$this->seq[++$this->lcs] = $ypos;
|
||||
$this->in_seq[$ypos] = 1;
|
||||
return $this->lcs;
|
||||
}
|
||||
|
||||
$beg = 1;
|
||||
while ($beg < $end) {
|
||||
$mid = (int)(($beg + $end) / 2);
|
||||
if ($ypos > $this->seq[$mid]) {
|
||||
$beg = $mid + 1;
|
||||
} else {
|
||||
$end = $mid;
|
||||
}
|
||||
}
|
||||
|
||||
assert($ypos != $this->seq[$end]);
|
||||
|
||||
$this->in_seq[$this->seq[$end]] = false;
|
||||
$this->seq[$end] = $ypos;
|
||||
$this->in_seq[$ypos] = 1;
|
||||
return $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds LCS of two sequences.
|
||||
*
|
||||
* The results are recorded in the vectors $this->{x,y}changed[], by
|
||||
* storing a 1 in the element for each line that is an insertion or
|
||||
* deletion (ie. is not in the LCS).
|
||||
*
|
||||
* The subsequence of file 0 is (XOFF, XLIM) and likewise for file 1.
|
||||
*
|
||||
* Note that XLIM, YLIM are exclusive bounds. All line numbers are
|
||||
* origin-0 and discarded lines are not counted.
|
||||
*/
|
||||
function _compareseq ($xoff, $xlim, $yoff, $ylim)
|
||||
{
|
||||
/* Slide down the bottom initial diagonal. */
|
||||
while ($xoff < $xlim && $yoff < $ylim
|
||||
&& $this->xv[$xoff] == $this->yv[$yoff]) {
|
||||
++$xoff;
|
||||
++$yoff;
|
||||
}
|
||||
|
||||
/* Slide up the top initial diagonal. */
|
||||
while ($xlim > $xoff && $ylim > $yoff
|
||||
&& $this->xv[$xlim - 1] == $this->yv[$ylim - 1]) {
|
||||
--$xlim;
|
||||
--$ylim;
|
||||
}
|
||||
|
||||
if ($xoff == $xlim || $yoff == $ylim) {
|
||||
$lcs = 0;
|
||||
} else {
|
||||
/* This is ad hoc but seems to work well. $nchunks =
|
||||
* sqrt(min($xlim - $xoff, $ylim - $yoff) / 2.5); $nchunks =
|
||||
* max(2,min(8,(int)$nchunks)); */
|
||||
$nchunks = min(7, $xlim - $xoff, $ylim - $yoff) + 1;
|
||||
list($lcs, $seps)
|
||||
= $this->_diag($xoff, $xlim, $yoff, $ylim, $nchunks);
|
||||
}
|
||||
|
||||
if ($lcs == 0) {
|
||||
/* X and Y sequences have no common subsequence: mark all
|
||||
* changed. */
|
||||
while ($yoff < $ylim) {
|
||||
$this->ychanged[$this->yind[$yoff++]] = 1;
|
||||
}
|
||||
while ($xoff < $xlim) {
|
||||
$this->xchanged[$this->xind[$xoff++]] = 1;
|
||||
}
|
||||
} else {
|
||||
/* Use the partitions to split this problem into subproblems. */
|
||||
reset($seps);
|
||||
$pt1 = $seps[0];
|
||||
while ($pt2 = next($seps)) {
|
||||
$this->_compareseq ($pt1[0], $pt2[0], $pt1[1], $pt2[1]);
|
||||
$pt1 = $pt2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts inserts/deletes of identical lines to join changes as much as
|
||||
* possible.
|
||||
*
|
||||
* We do something when a run of changed lines include a line at one end
|
||||
* and has an excluded, identical line at the other. We are free to
|
||||
* choose which identical line is included. `compareseq' usually chooses
|
||||
* the one at the beginning, but usually it is cleaner to consider the
|
||||
* following identical line to be the "change".
|
||||
*
|
||||
* This is extracted verbatim from analyze.c (GNU diffutils-2.7).
|
||||
*/
|
||||
function _shiftBoundaries($lines, &$changed, $other_changed)
|
||||
{
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
|
||||
assert('count($lines) == count($changed)');
|
||||
$len = count($lines);
|
||||
$other_len = count($other_changed);
|
||||
|
||||
while (1) {
|
||||
/* Scan forward to find the beginning of another run of
|
||||
* changes. Also keep track of the corresponding point in the
|
||||
* other file.
|
||||
*
|
||||
* Throughout this code, $i and $j are adjusted together so that
|
||||
* the first $i elements of $changed and the first $j elements of
|
||||
* $other_changed both contain the same number of zeros (unchanged
|
||||
* lines).
|
||||
*
|
||||
* Furthermore, $j is always kept so that $j == $other_len or
|
||||
* $other_changed[$j] == false. */
|
||||
while ($j < $other_len && $other_changed[$j]) {
|
||||
$j++;
|
||||
}
|
||||
|
||||
while ($i < $len && ! $changed[$i]) {
|
||||
assert('$j < $other_len && ! $other_changed[$j]');
|
||||
$i++; $j++;
|
||||
while ($j < $other_len && $other_changed[$j]) {
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($i == $len) {
|
||||
break;
|
||||
}
|
||||
|
||||
$start = $i;
|
||||
|
||||
/* Find the end of this run of changes. */
|
||||
while (++$i < $len && $changed[$i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
do {
|
||||
/* Record the length of this run of changes, so that we can
|
||||
* later determine whether the run has grown. */
|
||||
$runlength = $i - $start;
|
||||
|
||||
/* Move the changed region back, so long as the previous
|
||||
* unchanged line matches the last changed one. This merges
|
||||
* with previous changed regions. */
|
||||
while ($start > 0 && $lines[$start - 1] == $lines[$i - 1]) {
|
||||
$changed[--$start] = 1;
|
||||
$changed[--$i] = false;
|
||||
while ($start > 0 && $changed[$start - 1]) {
|
||||
$start--;
|
||||
}
|
||||
assert('$j > 0');
|
||||
while ($other_changed[--$j]) {
|
||||
continue;
|
||||
}
|
||||
assert('$j >= 0 && !$other_changed[$j]');
|
||||
}
|
||||
|
||||
/* Set CORRESPONDING to the end of the changed run, at the
|
||||
* last point where it corresponds to a changed run in the
|
||||
* other file. CORRESPONDING == LEN means no such point has
|
||||
* been found. */
|
||||
$corresponding = $j < $other_len ? $i : $len;
|
||||
|
||||
/* Move the changed region forward, so long as the first
|
||||
* changed line matches the following unchanged one. This
|
||||
* merges with following changed regions. Do this second, so
|
||||
* that if there are no merges, the changed region is moved
|
||||
* forward as far as possible. */
|
||||
while ($i < $len && $lines[$start] == $lines[$i]) {
|
||||
$changed[$start++] = false;
|
||||
$changed[$i++] = 1;
|
||||
while ($i < $len && $changed[$i]) {
|
||||
$i++;
|
||||
}
|
||||
|
||||
assert('$j < $other_len && ! $other_changed[$j]');
|
||||
$j++;
|
||||
if ($j < $other_len && $other_changed[$j]) {
|
||||
$corresponding = $i;
|
||||
while ($j < $other_len && $other_changed[$j]) {
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while ($runlength != $i - $start);
|
||||
|
||||
/* If possible, move the fully-merged run of changes back to a
|
||||
* corresponding run in the other file. */
|
||||
while ($corresponding < $i) {
|
||||
$changed[--$start] = 1;
|
||||
$changed[--$i] = 0;
|
||||
assert('$j > 0');
|
||||
while ($other_changed[--$j]) {
|
||||
continue;
|
||||
}
|
||||
assert('$j >= 0 && !$other_changed[$j]');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
164
database/php/pear/Text/Diff/Engine/shell.php
Normal file
164
database/php/pear/Text/Diff/Engine/shell.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used internally by Diff to actually compute the diffs.
|
||||
*
|
||||
* This class uses the Unix `diff` program via shell_exec to compute the
|
||||
* differences between the two input arrays.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/shell.php,v 1.6.2.4 2009/01/06 15:23:41 jan Exp $
|
||||
*
|
||||
* Copyright 2007-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @author Milian Wolff <mail@milianw.de>
|
||||
* @package Text_Diff
|
||||
* @since 0.3.0
|
||||
*/
|
||||
class Text_Diff_Engine_shell {
|
||||
|
||||
/**
|
||||
* Path to the diff executable
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $_diffCommand = 'diff';
|
||||
|
||||
/**
|
||||
* Returns the array of differences.
|
||||
*
|
||||
* @param array $from_lines lines of text from old file
|
||||
* @param array $to_lines lines of text from new file
|
||||
*
|
||||
* @return array all changes made (array with Text_Diff_Op_* objects)
|
||||
*/
|
||||
function diff($from_lines, $to_lines)
|
||||
{
|
||||
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
|
||||
array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
|
||||
|
||||
$temp_dir = Text_Diff::_getTempDir();
|
||||
|
||||
// Execute gnu diff or similar to get a standard diff file.
|
||||
$from_file = tempnam($temp_dir, 'Text_Diff');
|
||||
$to_file = tempnam($temp_dir, 'Text_Diff');
|
||||
$fp = fopen($from_file, 'w');
|
||||
fwrite($fp, implode("\n", $from_lines));
|
||||
fclose($fp);
|
||||
$fp = fopen($to_file, 'w');
|
||||
fwrite($fp, implode("\n", $to_lines));
|
||||
fclose($fp);
|
||||
$diff = shell_exec($this->_diffCommand . ' ' . $from_file . ' ' . $to_file);
|
||||
unlink($from_file);
|
||||
unlink($to_file);
|
||||
|
||||
if (is_null($diff)) {
|
||||
// No changes were made
|
||||
return array(new Text_Diff_Op_copy($from_lines));
|
||||
}
|
||||
|
||||
$from_line_no = 1;
|
||||
$to_line_no = 1;
|
||||
$edits = array();
|
||||
|
||||
// Get changed lines by parsing something like:
|
||||
// 0a1,2
|
||||
// 1,2c4,6
|
||||
// 1,5d6
|
||||
preg_match_all('#^(\d+)(?:,(\d+))?([adc])(\d+)(?:,(\d+))?$#m', $diff,
|
||||
$matches, PREG_SET_ORDER);
|
||||
|
||||
foreach ($matches as $match) {
|
||||
if (!isset($match[5])) {
|
||||
// This paren is not set every time (see regex).
|
||||
$match[5] = false;
|
||||
}
|
||||
|
||||
if ($match[3] == 'a') {
|
||||
$from_line_no--;
|
||||
}
|
||||
|
||||
if ($match[3] == 'd') {
|
||||
$to_line_no--;
|
||||
}
|
||||
|
||||
if ($from_line_no < $match[1] || $to_line_no < $match[4]) {
|
||||
// copied lines
|
||||
assert('$match[1] - $from_line_no == $match[4] - $to_line_no');
|
||||
array_push($edits,
|
||||
new Text_Diff_Op_copy(
|
||||
$this->_getLines($from_lines, $from_line_no, $match[1] - 1),
|
||||
$this->_getLines($to_lines, $to_line_no, $match[4] - 1)));
|
||||
}
|
||||
|
||||
switch ($match[3]) {
|
||||
case 'd':
|
||||
// deleted lines
|
||||
array_push($edits,
|
||||
new Text_Diff_Op_delete(
|
||||
$this->_getLines($from_lines, $from_line_no, $match[2])));
|
||||
$to_line_no++;
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
// changed lines
|
||||
array_push($edits,
|
||||
new Text_Diff_Op_change(
|
||||
$this->_getLines($from_lines, $from_line_no, $match[2]),
|
||||
$this->_getLines($to_lines, $to_line_no, $match[5])));
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
// added lines
|
||||
array_push($edits,
|
||||
new Text_Diff_Op_add(
|
||||
$this->_getLines($to_lines, $to_line_no, $match[5])));
|
||||
$from_line_no++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($from_lines)) {
|
||||
// Some lines might still be pending. Add them as copied
|
||||
array_push($edits,
|
||||
new Text_Diff_Op_copy(
|
||||
$this->_getLines($from_lines, $from_line_no,
|
||||
$from_line_no + count($from_lines) - 1),
|
||||
$this->_getLines($to_lines, $to_line_no,
|
||||
$to_line_no + count($to_lines) - 1)));
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get lines from either the old or new text
|
||||
*
|
||||
* @access private
|
||||
*
|
||||
* @param array &$text_lines Either $from_lines or $to_lines
|
||||
* @param int &$line_no Current line number
|
||||
* @param int $end Optional end line, when we want to chop more
|
||||
* than one line.
|
||||
*
|
||||
* @return array The chopped lines
|
||||
*/
|
||||
function _getLines(&$text_lines, &$line_no, $end = false)
|
||||
{
|
||||
if (!empty($end)) {
|
||||
$lines = array();
|
||||
// We can shift even more
|
||||
while ($line_no <= $end) {
|
||||
array_push($lines, array_shift($text_lines));
|
||||
$line_no++;
|
||||
}
|
||||
} else {
|
||||
$lines = array(array_shift($text_lines));
|
||||
$line_no++;
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
}
|
||||
250
database/php/pear/Text/Diff/Engine/string.php
Normal file
250
database/php/pear/Text/Diff/Engine/string.php
Normal file
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Parses unified or context diffs output from eg. the diff utility.
|
||||
*
|
||||
* Example:
|
||||
* <code>
|
||||
* $patch = file_get_contents('example.patch');
|
||||
* $diff = new Text_Diff('string', array($patch));
|
||||
* $renderer = new Text_Diff_Renderer_inline();
|
||||
* echo $renderer->render($diff);
|
||||
* </code>
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/string.php,v 1.5.2.7 2009/07/24 13:04:43 jan Exp $
|
||||
*
|
||||
* Copyright 2005 <20>rjan Persson <o@42mm.org>
|
||||
* Copyright 2005-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @author <20>rjan Persson <o@42mm.org>
|
||||
* @package Text_Diff
|
||||
* @since 0.2.0
|
||||
*/
|
||||
class Text_Diff_Engine_string {
|
||||
|
||||
/**
|
||||
* Parses a unified or context diff.
|
||||
*
|
||||
* First param contains the whole diff and the second can be used to force
|
||||
* a specific diff type. If the second parameter is 'autodetect', the
|
||||
* diff will be examined to find out which type of diff this is.
|
||||
*
|
||||
* @param string $diff The diff content.
|
||||
* @param string $mode The diff mode of the content in $diff. One of
|
||||
* 'context', 'unified', or 'autodetect'.
|
||||
*
|
||||
* @return array List of all diff operations.
|
||||
*/
|
||||
function diff($diff, $mode = 'autodetect')
|
||||
{
|
||||
// Detect line breaks.
|
||||
$lnbr = "\n";
|
||||
if (strpos($diff, "\r\n") !== false) {
|
||||
$lnbr = "\r\n";
|
||||
} elseif (strpos($diff, "\r") !== false) {
|
||||
$lnbr = "\r";
|
||||
}
|
||||
|
||||
// Make sure we have a line break at the EOF.
|
||||
if (substr($diff, -strlen($lnbr)) != $lnbr) {
|
||||
$diff .= $lnbr;
|
||||
}
|
||||
|
||||
if ($mode != 'autodetect' && $mode != 'context' && $mode != 'unified') {
|
||||
return PEAR::raiseError('Type of diff is unsupported');
|
||||
}
|
||||
|
||||
if ($mode == 'autodetect') {
|
||||
$context = strpos($diff, '***');
|
||||
$unified = strpos($diff, '---');
|
||||
if ($context === $unified) {
|
||||
return PEAR::raiseError('Type of diff could not be detected');
|
||||
} elseif ($context === false || $unified === false) {
|
||||
$mode = $context !== false ? 'context' : 'unified';
|
||||
} else {
|
||||
$mode = $context < $unified ? 'context' : 'unified';
|
||||
}
|
||||
}
|
||||
|
||||
// Split by new line and remove the diff header, if there is one.
|
||||
$diff = explode($lnbr, $diff);
|
||||
if (($mode == 'context' && strpos($diff[0], '***') === 0) ||
|
||||
($mode == 'unified' && strpos($diff[0], '---') === 0)) {
|
||||
array_shift($diff);
|
||||
array_shift($diff);
|
||||
}
|
||||
|
||||
if ($mode == 'context') {
|
||||
return $this->parseContextDiff($diff);
|
||||
} else {
|
||||
return $this->parseUnifiedDiff($diff);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an array containing the unified diff.
|
||||
*
|
||||
* @param array $diff Array of lines.
|
||||
*
|
||||
* @return array List of all diff operations.
|
||||
*/
|
||||
function parseUnifiedDiff($diff)
|
||||
{
|
||||
$edits = array();
|
||||
$end = count($diff) - 1;
|
||||
for ($i = 0; $i < $end;) {
|
||||
$diff1 = array();
|
||||
switch (substr($diff[$i], 0, 1)) {
|
||||
case ' ':
|
||||
do {
|
||||
$diff1[] = substr($diff[$i], 1);
|
||||
} while (++$i < $end && substr($diff[$i], 0, 1) == ' ');
|
||||
$edits[] = new Text_Diff_Op_copy($diff1);
|
||||
break;
|
||||
|
||||
case '+':
|
||||
// get all new lines
|
||||
do {
|
||||
$diff1[] = substr($diff[$i], 1);
|
||||
} while (++$i < $end && substr($diff[$i], 0, 1) == '+');
|
||||
$edits[] = new Text_Diff_Op_add($diff1);
|
||||
break;
|
||||
|
||||
case '-':
|
||||
// get changed or removed lines
|
||||
$diff2 = array();
|
||||
do {
|
||||
$diff1[] = substr($diff[$i], 1);
|
||||
} while (++$i < $end && substr($diff[$i], 0, 1) == '-');
|
||||
|
||||
while ($i < $end && substr($diff[$i], 0, 1) == '+') {
|
||||
$diff2[] = substr($diff[$i++], 1);
|
||||
}
|
||||
if (count($diff2) == 0) {
|
||||
$edits[] = new Text_Diff_Op_delete($diff1);
|
||||
} else {
|
||||
$edits[] = new Text_Diff_Op_change($diff1, $diff2);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an array containing the context diff.
|
||||
*
|
||||
* @param array $diff Array of lines.
|
||||
*
|
||||
* @return array List of all diff operations.
|
||||
*/
|
||||
function parseContextDiff(&$diff)
|
||||
{
|
||||
$edits = array();
|
||||
$i = $max_i = $j = $max_j = 0;
|
||||
$end = count($diff) - 1;
|
||||
while ($i < $end && $j < $end) {
|
||||
while ($i >= $max_i && $j >= $max_j) {
|
||||
// Find the boundaries of the diff output of the two files
|
||||
for ($i = $j;
|
||||
$i < $end && substr($diff[$i], 0, 3) == '***';
|
||||
$i++);
|
||||
for ($max_i = $i;
|
||||
$max_i < $end && substr($diff[$max_i], 0, 3) != '---';
|
||||
$max_i++);
|
||||
for ($j = $max_i;
|
||||
$j < $end && substr($diff[$j], 0, 3) == '---';
|
||||
$j++);
|
||||
for ($max_j = $j;
|
||||
$max_j < $end && substr($diff[$max_j], 0, 3) != '***';
|
||||
$max_j++);
|
||||
}
|
||||
|
||||
// find what hasn't been changed
|
||||
$array = array();
|
||||
while ($i < $max_i &&
|
||||
$j < $max_j &&
|
||||
strcmp($diff[$i], $diff[$j]) == 0) {
|
||||
$array[] = substr($diff[$i], 2);
|
||||
$i++;
|
||||
$j++;
|
||||
}
|
||||
|
||||
while ($i < $max_i && ($max_j-$j) <= 1) {
|
||||
if ($diff[$i] != '' && substr($diff[$i], 0, 1) != ' ') {
|
||||
break;
|
||||
}
|
||||
$array[] = substr($diff[$i++], 2);
|
||||
}
|
||||
|
||||
while ($j < $max_j && ($max_i-$i) <= 1) {
|
||||
if ($diff[$j] != '' && substr($diff[$j], 0, 1) != ' ') {
|
||||
break;
|
||||
}
|
||||
$array[] = substr($diff[$j++], 2);
|
||||
}
|
||||
if (count($array) > 0) {
|
||||
$edits[] = new Text_Diff_Op_copy($array);
|
||||
}
|
||||
|
||||
if ($i < $max_i) {
|
||||
$diff1 = array();
|
||||
switch (substr($diff[$i], 0, 1)) {
|
||||
case '!':
|
||||
$diff2 = array();
|
||||
do {
|
||||
$diff1[] = substr($diff[$i], 2);
|
||||
if ($j < $max_j && substr($diff[$j], 0, 1) == '!') {
|
||||
$diff2[] = substr($diff[$j++], 2);
|
||||
}
|
||||
} while (++$i < $max_i && substr($diff[$i], 0, 1) == '!');
|
||||
$edits[] = new Text_Diff_Op_change($diff1, $diff2);
|
||||
break;
|
||||
|
||||
case '+':
|
||||
do {
|
||||
$diff1[] = substr($diff[$i], 2);
|
||||
} while (++$i < $max_i && substr($diff[$i], 0, 1) == '+');
|
||||
$edits[] = new Text_Diff_Op_add($diff1);
|
||||
break;
|
||||
|
||||
case '-':
|
||||
do {
|
||||
$diff1[] = substr($diff[$i], 2);
|
||||
} while (++$i < $max_i && substr($diff[$i], 0, 1) == '-');
|
||||
$edits[] = new Text_Diff_Op_delete($diff1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($j < $max_j) {
|
||||
$diff2 = array();
|
||||
switch (substr($diff[$j], 0, 1)) {
|
||||
case '+':
|
||||
do {
|
||||
$diff2[] = substr($diff[$j++], 2);
|
||||
} while ($j < $max_j && substr($diff[$j], 0, 1) == '+');
|
||||
$edits[] = new Text_Diff_Op_add($diff2);
|
||||
break;
|
||||
|
||||
case '-':
|
||||
do {
|
||||
$diff2[] = substr($diff[$j++], 2);
|
||||
} while ($j < $max_j && substr($diff[$j], 0, 1) == '-');
|
||||
$edits[] = new Text_Diff_Op_delete($diff2);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
}
|
||||
66
database/php/pear/Text/Diff/Engine/xdiff.php
Normal file
66
database/php/pear/Text/Diff/Engine/xdiff.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Class used internally by Diff to actually compute the diffs.
|
||||
*
|
||||
* This class uses the xdiff PECL package (http://pecl.php.net/package/xdiff)
|
||||
* to compute the differences between the two input arrays.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Engine/xdiff.php,v 1.4.2.5 2009/07/24 13:06:24 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @author Jon Parise <jon@horde.org>
|
||||
* @package Text_Diff
|
||||
*/
|
||||
class Text_Diff_Engine_xdiff {
|
||||
|
||||
/**
|
||||
*/
|
||||
function diff($from_lines, $to_lines)
|
||||
{
|
||||
array_walk($from_lines, array('Text_Diff', 'trimNewlines'));
|
||||
array_walk($to_lines, array('Text_Diff', 'trimNewlines'));
|
||||
|
||||
/* Convert the two input arrays into strings for xdiff processing. */
|
||||
$from_string = implode("\n", $from_lines);
|
||||
$to_string = implode("\n", $to_lines);
|
||||
|
||||
/* Diff the two strings and convert the result to an array. */
|
||||
$diff = xdiff_string_diff($from_string, $to_string, count($to_lines));
|
||||
$diff = explode("\n", $diff);
|
||||
|
||||
/* Walk through the diff one line at a time. We build the $edits
|
||||
* array of diff operations by reading the first character of the
|
||||
* xdiff output (which is in the "unified diff" format).
|
||||
*
|
||||
* Note that we don't have enough information to detect "changed"
|
||||
* lines using this approach, so we can't add Text_Diff_Op_changed
|
||||
* instances to the $edits array. The result is still perfectly
|
||||
* valid, albeit a little less descriptive and efficient. */
|
||||
$edits = array();
|
||||
foreach ($diff as $line) {
|
||||
if (!strlen($line)) {
|
||||
continue;
|
||||
}
|
||||
switch ($line[0]) {
|
||||
case ' ':
|
||||
$edits[] = &new Text_Diff_Op_copy(array(substr($line, 1)));
|
||||
break;
|
||||
|
||||
case '+':
|
||||
$edits[] = &new Text_Diff_Op_add(array(substr($line, 1)));
|
||||
break;
|
||||
|
||||
case '-':
|
||||
$edits[] = &new Text_Diff_Op_delete(array(substr($line, 1)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
}
|
||||
55
database/php/pear/Text/Diff/Mapped.php
Normal file
55
database/php/pear/Text/Diff/Mapped.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* $Horde: framework/Text_Diff/Diff/Mapped.php,v 1.3.2.4 2009/01/06 15:23:41 jan Exp $
|
||||
*
|
||||
* Copyright 2007-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*/
|
||||
class Text_Diff_Mapped extends Text_Diff {
|
||||
|
||||
/**
|
||||
* Computes a diff between sequences of strings.
|
||||
*
|
||||
* This can be used to compute things like case-insensitve diffs, or diffs
|
||||
* which ignore changes in white-space.
|
||||
*
|
||||
* @param array $from_lines An array of strings.
|
||||
* @param array $to_lines An array of strings.
|
||||
* @param array $mapped_from_lines This array should have the same size
|
||||
* number of elements as $from_lines. The
|
||||
* elements in $mapped_from_lines and
|
||||
* $mapped_to_lines are what is actually
|
||||
* compared when computing the diff.
|
||||
* @param array $mapped_to_lines This array should have the same number
|
||||
* of elements as $to_lines.
|
||||
*/
|
||||
function Text_Diff_Mapped($from_lines, $to_lines,
|
||||
$mapped_from_lines, $mapped_to_lines)
|
||||
{
|
||||
assert(count($from_lines) == count($mapped_from_lines));
|
||||
assert(count($to_lines) == count($mapped_to_lines));
|
||||
|
||||
parent::Text_Diff($mapped_from_lines, $mapped_to_lines);
|
||||
|
||||
$xi = $yi = 0;
|
||||
for ($i = 0; $i < count($this->_edits); $i++) {
|
||||
$orig = &$this->_edits[$i]->orig;
|
||||
if (is_array($orig)) {
|
||||
$orig = array_slice($from_lines, $xi, count($orig));
|
||||
$xi += count($orig);
|
||||
}
|
||||
|
||||
$final = &$this->_edits[$i]->final;
|
||||
if (is_array($final)) {
|
||||
$final = array_slice($to_lines, $yi, count($final));
|
||||
$yi += count($final);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
237
database/php/pear/Text/Diff/Renderer.php
Normal file
237
database/php/pear/Text/Diff/Renderer.php
Normal file
@@ -0,0 +1,237 @@
|
||||
<?php
|
||||
/**
|
||||
* A class to render Diffs in different formats.
|
||||
*
|
||||
* This class renders the diff in classic diff format. It is intended that
|
||||
* this class be customized via inheritance, to obtain fancier outputs.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Renderer.php,v 1.5.10.12 2009/07/24 13:26:40 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @package Text_Diff
|
||||
*/
|
||||
class Text_Diff_Renderer {
|
||||
|
||||
/**
|
||||
* Number of leading context "lines" to preserve.
|
||||
*
|
||||
* This should be left at zero for this class, but subclasses may want to
|
||||
* set this to other values.
|
||||
*/
|
||||
var $_leading_context_lines = 0;
|
||||
|
||||
/**
|
||||
* Number of trailing context "lines" to preserve.
|
||||
*
|
||||
* This should be left at zero for this class, but subclasses may want to
|
||||
* set this to other values.
|
||||
*/
|
||||
var $_trailing_context_lines = 0;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function Text_Diff_Renderer($params = array())
|
||||
{
|
||||
foreach ($params as $param => $value) {
|
||||
$v = '_' . $param;
|
||||
if (isset($this->$v)) {
|
||||
$this->$v = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any renderer parameters.
|
||||
*
|
||||
* @return array All parameters of this renderer object.
|
||||
*/
|
||||
function getParams()
|
||||
{
|
||||
$params = array();
|
||||
foreach (get_object_vars($this) as $k => $v) {
|
||||
if ($k[0] == '_') {
|
||||
$params[substr($k, 1)] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a diff.
|
||||
*
|
||||
* @param Text_Diff $diff A Text_Diff object.
|
||||
*
|
||||
* @return string The formatted output.
|
||||
*/
|
||||
function render($diff)
|
||||
{
|
||||
$xi = $yi = 1;
|
||||
$block = false;
|
||||
$context = array();
|
||||
|
||||
$nlead = $this->_leading_context_lines;
|
||||
$ntrail = $this->_trailing_context_lines;
|
||||
|
||||
$output = $this->_startDiff();
|
||||
|
||||
$diffs = $diff->getDiff();
|
||||
foreach ($diffs as $i => $edit) {
|
||||
/* If these are unchanged (copied) lines, and we want to keep
|
||||
* leading or trailing context lines, extract them from the copy
|
||||
* block. */
|
||||
if (is_a($edit, 'Text_Diff_Op_copy')) {
|
||||
/* Do we have any diff blocks yet? */
|
||||
if (is_array($block)) {
|
||||
/* How many lines to keep as context from the copy
|
||||
* block. */
|
||||
$keep = $i == count($diffs) - 1 ? $ntrail : $nlead + $ntrail;
|
||||
if (count($edit->orig) <= $keep) {
|
||||
/* We have less lines in the block than we want for
|
||||
* context => keep the whole block. */
|
||||
$block[] = $edit;
|
||||
} else {
|
||||
if ($ntrail) {
|
||||
/* Create a new block with as many lines as we need
|
||||
* for the trailing context. */
|
||||
$context = array_slice($edit->orig, 0, $ntrail);
|
||||
$block[] = new Text_Diff_Op_copy($context);
|
||||
}
|
||||
/* @todo */
|
||||
$output .= $this->_block($x0, $ntrail + $xi - $x0,
|
||||
$y0, $ntrail + $yi - $y0,
|
||||
$block);
|
||||
$block = false;
|
||||
}
|
||||
}
|
||||
/* Keep the copy block as the context for the next block. */
|
||||
$context = $edit->orig;
|
||||
} else {
|
||||
/* Don't we have any diff blocks yet? */
|
||||
if (!is_array($block)) {
|
||||
/* Extract context lines from the preceding copy block. */
|
||||
$context = array_slice($context, count($context) - $nlead);
|
||||
$x0 = $xi - count($context);
|
||||
$y0 = $yi - count($context);
|
||||
$block = array();
|
||||
if ($context) {
|
||||
$block[] = new Text_Diff_Op_copy($context);
|
||||
}
|
||||
}
|
||||
$block[] = $edit;
|
||||
}
|
||||
|
||||
if ($edit->orig) {
|
||||
$xi += count($edit->orig);
|
||||
}
|
||||
if ($edit->final) {
|
||||
$yi += count($edit->final);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($block)) {
|
||||
$output .= $this->_block($x0, $xi - $x0,
|
||||
$y0, $yi - $y0,
|
||||
$block);
|
||||
}
|
||||
|
||||
return $output . $this->_endDiff();
|
||||
}
|
||||
|
||||
function _block($xbeg, $xlen, $ybeg, $ylen, &$edits)
|
||||
{
|
||||
$output = $this->_startBlock($this->_blockHeader($xbeg, $xlen, $ybeg, $ylen));
|
||||
|
||||
foreach ($edits as $edit) {
|
||||
switch (strtolower(get_class($edit))) {
|
||||
case 'text_diff_op_copy':
|
||||
$output .= $this->_context($edit->orig);
|
||||
break;
|
||||
|
||||
case 'text_diff_op_add':
|
||||
$output .= $this->_added($edit->final);
|
||||
break;
|
||||
|
||||
case 'text_diff_op_delete':
|
||||
$output .= $this->_deleted($edit->orig);
|
||||
break;
|
||||
|
||||
case 'text_diff_op_change':
|
||||
$output .= $this->_changed($edit->orig, $edit->final);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $output . $this->_endBlock();
|
||||
}
|
||||
|
||||
function _startDiff()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
function _endDiff()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
|
||||
{
|
||||
if ($xlen > 1) {
|
||||
$xbeg .= ',' . ($xbeg + $xlen - 1);
|
||||
}
|
||||
if ($ylen > 1) {
|
||||
$ybeg .= ',' . ($ybeg + $ylen - 1);
|
||||
}
|
||||
|
||||
// this matches the GNU Diff behaviour
|
||||
if ($xlen && !$ylen) {
|
||||
$ybeg--;
|
||||
} elseif (!$xlen) {
|
||||
$xbeg--;
|
||||
}
|
||||
|
||||
return $xbeg . ($xlen ? ($ylen ? 'c' : 'd') : 'a') . $ybeg;
|
||||
}
|
||||
|
||||
function _startBlock($header)
|
||||
{
|
||||
return $header . "\n";
|
||||
}
|
||||
|
||||
function _endBlock()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
function _lines($lines, $prefix = ' ')
|
||||
{
|
||||
return $prefix . implode("\n$prefix", $lines) . "\n";
|
||||
}
|
||||
|
||||
function _context($lines)
|
||||
{
|
||||
return $this->_lines($lines, ' ');
|
||||
}
|
||||
|
||||
function _added($lines)
|
||||
{
|
||||
return $this->_lines($lines, '> ');
|
||||
}
|
||||
|
||||
function _deleted($lines)
|
||||
{
|
||||
return $this->_lines($lines, '< ');
|
||||
}
|
||||
|
||||
function _changed($orig, $final)
|
||||
{
|
||||
return $this->_deleted($orig) . "---\n" . $this->_added($final);
|
||||
}
|
||||
|
||||
}
|
||||
77
database/php/pear/Text/Diff/Renderer/context.php
Normal file
77
database/php/pear/Text/Diff/Renderer/context.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
/**
|
||||
* "Context" diff renderer.
|
||||
*
|
||||
* This class renders the diff in classic "context diff" format.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Renderer/context.php,v 1.3.2.4 2009/01/06 15:23:42 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @package Text_Diff
|
||||
*/
|
||||
|
||||
/** Text_Diff_Renderer */
|
||||
require_once 'Text/Diff/Renderer.php';
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
*/
|
||||
class Text_Diff_Renderer_context extends Text_Diff_Renderer {
|
||||
|
||||
/**
|
||||
* Number of leading context "lines" to preserve.
|
||||
*/
|
||||
var $_leading_context_lines = 4;
|
||||
|
||||
/**
|
||||
* Number of trailing context "lines" to preserve.
|
||||
*/
|
||||
var $_trailing_context_lines = 4;
|
||||
|
||||
var $_second_block = '';
|
||||
|
||||
function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
|
||||
{
|
||||
if ($xlen != 1) {
|
||||
$xbeg .= ',' . $xlen;
|
||||
}
|
||||
if ($ylen != 1) {
|
||||
$ybeg .= ',' . $ylen;
|
||||
}
|
||||
$this->_second_block = "--- $ybeg ----\n";
|
||||
return "***************\n*** $xbeg ****";
|
||||
}
|
||||
|
||||
function _endBlock()
|
||||
{
|
||||
return $this->_second_block;
|
||||
}
|
||||
|
||||
function _context($lines)
|
||||
{
|
||||
$this->_second_block .= $this->_lines($lines, ' ');
|
||||
return $this->_lines($lines, ' ');
|
||||
}
|
||||
|
||||
function _added($lines)
|
||||
{
|
||||
$this->_second_block .= $this->_lines($lines, '+ ');
|
||||
return '';
|
||||
}
|
||||
|
||||
function _deleted($lines)
|
||||
{
|
||||
return $this->_lines($lines, '- ');
|
||||
}
|
||||
|
||||
function _changed($orig, $final)
|
||||
{
|
||||
$this->_second_block .= $this->_lines($final, '! ');
|
||||
return $this->_lines($orig, '! ');
|
||||
}
|
||||
|
||||
}
|
||||
172
database/php/pear/Text/Diff/Renderer/inline.php
Normal file
172
database/php/pear/Text/Diff/Renderer/inline.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
/**
|
||||
* "Inline" diff renderer.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Renderer/inline.php,v 1.4.10.16 2009/07/24 13:25:29 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @author Ciprian Popovici
|
||||
* @package Text_Diff
|
||||
*/
|
||||
|
||||
/** Text_Diff_Renderer */
|
||||
require_once 'Text/Diff/Renderer.php';
|
||||
|
||||
/**
|
||||
* "Inline" diff renderer.
|
||||
*
|
||||
* This class renders diffs in the Wiki-style "inline" format.
|
||||
*
|
||||
* @author Ciprian Popovici
|
||||
* @package Text_Diff
|
||||
*/
|
||||
class Text_Diff_Renderer_inline extends Text_Diff_Renderer {
|
||||
|
||||
/**
|
||||
* Number of leading context "lines" to preserve.
|
||||
*/
|
||||
var $_leading_context_lines = 10000;
|
||||
|
||||
/**
|
||||
* Number of trailing context "lines" to preserve.
|
||||
*/
|
||||
var $_trailing_context_lines = 10000;
|
||||
|
||||
/**
|
||||
* Prefix for inserted text.
|
||||
*/
|
||||
var $_ins_prefix = '<ins>';
|
||||
|
||||
/**
|
||||
* Suffix for inserted text.
|
||||
*/
|
||||
var $_ins_suffix = '</ins>';
|
||||
|
||||
/**
|
||||
* Prefix for deleted text.
|
||||
*/
|
||||
var $_del_prefix = '<del>';
|
||||
|
||||
/**
|
||||
* Suffix for deleted text.
|
||||
*/
|
||||
var $_del_suffix = '</del>';
|
||||
|
||||
/**
|
||||
* Header for each change block.
|
||||
*/
|
||||
var $_block_header = '';
|
||||
|
||||
/**
|
||||
* What are we currently splitting on? Used to recurse to show word-level
|
||||
* changes.
|
||||
*/
|
||||
var $_split_level = 'lines';
|
||||
|
||||
function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
|
||||
{
|
||||
return $this->_block_header;
|
||||
}
|
||||
|
||||
function _startBlock($header)
|
||||
{
|
||||
return $header;
|
||||
}
|
||||
|
||||
function _lines($lines, $prefix = ' ', $encode = true)
|
||||
{
|
||||
if ($encode) {
|
||||
array_walk($lines, array(&$this, '_encode'));
|
||||
}
|
||||
|
||||
if ($this->_split_level == 'words') {
|
||||
return implode('', $lines);
|
||||
} else {
|
||||
return implode("\n", $lines) . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
function _added($lines)
|
||||
{
|
||||
array_walk($lines, array(&$this, '_encode'));
|
||||
$lines[0] = $this->_ins_prefix . $lines[0];
|
||||
$lines[count($lines) - 1] .= $this->_ins_suffix;
|
||||
return $this->_lines($lines, ' ', false);
|
||||
}
|
||||
|
||||
function _deleted($lines, $words = false)
|
||||
{
|
||||
array_walk($lines, array(&$this, '_encode'));
|
||||
$lines[0] = $this->_del_prefix . $lines[0];
|
||||
$lines[count($lines) - 1] .= $this->_del_suffix;
|
||||
return $this->_lines($lines, ' ', false);
|
||||
}
|
||||
|
||||
function _changed($orig, $final)
|
||||
{
|
||||
/* If we've already split on words, don't try to do so again - just
|
||||
* display. */
|
||||
if ($this->_split_level == 'words') {
|
||||
$prefix = '';
|
||||
while ($orig[0] !== false && $final[0] !== false &&
|
||||
substr($orig[0], 0, 1) == ' ' &&
|
||||
substr($final[0], 0, 1) == ' ') {
|
||||
$prefix .= substr($orig[0], 0, 1);
|
||||
$orig[0] = substr($orig[0], 1);
|
||||
$final[0] = substr($final[0], 1);
|
||||
}
|
||||
return $prefix . $this->_deleted($orig) . $this->_added($final);
|
||||
}
|
||||
|
||||
$text1 = implode("\n", $orig);
|
||||
$text2 = implode("\n", $final);
|
||||
|
||||
/* Non-printing newline marker. */
|
||||
$nl = "\0";
|
||||
|
||||
/* We want to split on word boundaries, but we need to
|
||||
* preserve whitespace as well. Therefore we split on words,
|
||||
* but include all blocks of whitespace in the wordlist. */
|
||||
$diff = new Text_Diff('native',
|
||||
array($this->_splitOnWords($text1, $nl),
|
||||
$this->_splitOnWords($text2, $nl)));
|
||||
|
||||
/* Get the diff in inline format. */
|
||||
$renderer = new Text_Diff_Renderer_inline
|
||||
(array_merge($this->getParams(),
|
||||
array('split_level' => 'words')));
|
||||
|
||||
/* Run the diff and get the output. */
|
||||
return str_replace($nl, "\n", $renderer->render($diff)) . "\n";
|
||||
}
|
||||
|
||||
function _splitOnWords($string, $newlineEscape = "\n")
|
||||
{
|
||||
// Ignore \0; otherwise the while loop will never finish.
|
||||
$string = str_replace("\0", '', $string);
|
||||
|
||||
$words = array();
|
||||
$length = strlen($string);
|
||||
$pos = 0;
|
||||
|
||||
while ($pos < $length) {
|
||||
// Eat a word with any preceding whitespace.
|
||||
$spaces = strspn(substr($string, $pos), " \n");
|
||||
$nextpos = strcspn(substr($string, $pos + $spaces), " \n");
|
||||
$words[] = str_replace("\n", $newlineEscape, substr($string, $pos, $spaces + $nextpos));
|
||||
$pos += $spaces + $nextpos;
|
||||
}
|
||||
|
||||
return $words;
|
||||
}
|
||||
|
||||
function _encode(&$string)
|
||||
{
|
||||
$string = htmlspecialchars($string);
|
||||
}
|
||||
|
||||
}
|
||||
67
database/php/pear/Text/Diff/Renderer/unified.php
Normal file
67
database/php/pear/Text/Diff/Renderer/unified.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* "Unified" diff renderer.
|
||||
*
|
||||
* This class renders the diff in classic "unified diff" format.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/Renderer/unified.php,v 1.3.10.7 2009/01/06 15:23:42 jan Exp $
|
||||
*
|
||||
* Copyright 2004-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @author Ciprian Popovici
|
||||
* @package Text_Diff
|
||||
*/
|
||||
|
||||
/** Text_Diff_Renderer */
|
||||
require_once 'Text/Diff/Renderer.php';
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
*/
|
||||
class Text_Diff_Renderer_unified extends Text_Diff_Renderer {
|
||||
|
||||
/**
|
||||
* Number of leading context "lines" to preserve.
|
||||
*/
|
||||
var $_leading_context_lines = 4;
|
||||
|
||||
/**
|
||||
* Number of trailing context "lines" to preserve.
|
||||
*/
|
||||
var $_trailing_context_lines = 4;
|
||||
|
||||
function _blockHeader($xbeg, $xlen, $ybeg, $ylen)
|
||||
{
|
||||
if ($xlen != 1) {
|
||||
$xbeg .= ',' . $xlen;
|
||||
}
|
||||
if ($ylen != 1) {
|
||||
$ybeg .= ',' . $ylen;
|
||||
}
|
||||
return "@@ -$xbeg +$ybeg @@";
|
||||
}
|
||||
|
||||
function _context($lines)
|
||||
{
|
||||
return $this->_lines($lines, ' ');
|
||||
}
|
||||
|
||||
function _added($lines)
|
||||
{
|
||||
return $this->_lines($lines, '+');
|
||||
}
|
||||
|
||||
function _deleted($lines)
|
||||
{
|
||||
return $this->_lines($lines, '-');
|
||||
}
|
||||
|
||||
function _changed($orig, $final)
|
||||
{
|
||||
return $this->_deleted($orig) . $this->_added($final);
|
||||
}
|
||||
|
||||
}
|
||||
276
database/php/pear/Text/Diff/ThreeWay.php
Normal file
276
database/php/pear/Text/Diff/ThreeWay.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/**
|
||||
* A class for computing three way diffs.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff/ThreeWay.php,v 1.3.2.4 2009/01/06 15:23:41 jan Exp $
|
||||
*
|
||||
* Copyright 2007-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @package Text_Diff
|
||||
* @since 0.3.0
|
||||
*/
|
||||
|
||||
/** Text_Diff */
|
||||
require_once 'Text/Diff.php';
|
||||
|
||||
/**
|
||||
* A class for computing three way diffs.
|
||||
*
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*/
|
||||
class Text_Diff_ThreeWay extends Text_Diff {
|
||||
|
||||
/**
|
||||
* Conflict counter.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $_conflictingBlocks = 0;
|
||||
|
||||
/**
|
||||
* Computes diff between 3 sequences of strings.
|
||||
*
|
||||
* @param array $orig The original lines to use.
|
||||
* @param array $final1 The first version to compare to.
|
||||
* @param array $final2 The second version to compare to.
|
||||
*/
|
||||
function Text_Diff_ThreeWay($orig, $final1, $final2)
|
||||
{
|
||||
if (extension_loaded('xdiff')) {
|
||||
$engine = new Text_Diff_Engine_xdiff();
|
||||
} else {
|
||||
$engine = new Text_Diff_Engine_native();
|
||||
}
|
||||
|
||||
$this->_edits = $this->_diff3($engine->diff($orig, $final1),
|
||||
$engine->diff($orig, $final2));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
function mergedOutput($label1 = false, $label2 = false)
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($this->_edits as $edit) {
|
||||
if ($edit->isConflict()) {
|
||||
/* FIXME: this should probably be moved somewhere else. */
|
||||
$lines = array_merge($lines,
|
||||
array('<<<<<<<' . ($label1 ? ' ' . $label1 : '')),
|
||||
$edit->final1,
|
||||
array("======="),
|
||||
$edit->final2,
|
||||
array('>>>>>>>' . ($label2 ? ' ' . $label2 : '')));
|
||||
$this->_conflictingBlocks++;
|
||||
} else {
|
||||
$lines = array_merge($lines, $edit->merged());
|
||||
}
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
function _diff3($edits1, $edits2)
|
||||
{
|
||||
$edits = array();
|
||||
$bb = new Text_Diff_ThreeWay_BlockBuilder();
|
||||
|
||||
$e1 = current($edits1);
|
||||
$e2 = current($edits2);
|
||||
while ($e1 || $e2) {
|
||||
if ($e1 && $e2 && is_a($e1, 'Text_Diff_Op_copy') && is_a($e2, 'Text_Diff_Op_copy')) {
|
||||
/* We have copy blocks from both diffs. This is the (only)
|
||||
* time we want to emit a diff3 copy block. Flush current
|
||||
* diff3 diff block, if any. */
|
||||
if ($edit = $bb->finish()) {
|
||||
$edits[] = $edit;
|
||||
}
|
||||
|
||||
$ncopy = min($e1->norig(), $e2->norig());
|
||||
assert($ncopy > 0);
|
||||
$edits[] = new Text_Diff_ThreeWay_Op_copy(array_slice($e1->orig, 0, $ncopy));
|
||||
|
||||
if ($e1->norig() > $ncopy) {
|
||||
array_splice($e1->orig, 0, $ncopy);
|
||||
array_splice($e1->final, 0, $ncopy);
|
||||
} else {
|
||||
$e1 = next($edits1);
|
||||
}
|
||||
|
||||
if ($e2->norig() > $ncopy) {
|
||||
array_splice($e2->orig, 0, $ncopy);
|
||||
array_splice($e2->final, 0, $ncopy);
|
||||
} else {
|
||||
$e2 = next($edits2);
|
||||
}
|
||||
} else {
|
||||
if ($e1 && $e2) {
|
||||
if ($e1->orig && $e2->orig) {
|
||||
$norig = min($e1->norig(), $e2->norig());
|
||||
$orig = array_splice($e1->orig, 0, $norig);
|
||||
array_splice($e2->orig, 0, $norig);
|
||||
$bb->input($orig);
|
||||
}
|
||||
|
||||
if (is_a($e1, 'Text_Diff_Op_copy')) {
|
||||
$bb->out1(array_splice($e1->final, 0, $norig));
|
||||
}
|
||||
|
||||
if (is_a($e2, 'Text_Diff_Op_copy')) {
|
||||
$bb->out2(array_splice($e2->final, 0, $norig));
|
||||
}
|
||||
}
|
||||
|
||||
if ($e1 && ! $e1->orig) {
|
||||
$bb->out1($e1->final);
|
||||
$e1 = next($edits1);
|
||||
}
|
||||
if ($e2 && ! $e2->orig) {
|
||||
$bb->out2($e2->final);
|
||||
$e2 = next($edits2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($edit = $bb->finish()) {
|
||||
$edits[] = $edit;
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_ThreeWay_Op {
|
||||
|
||||
function Text_Diff_ThreeWay_Op($orig = false, $final1 = false, $final2 = false)
|
||||
{
|
||||
$this->orig = $orig ? $orig : array();
|
||||
$this->final1 = $final1 ? $final1 : array();
|
||||
$this->final2 = $final2 ? $final2 : array();
|
||||
}
|
||||
|
||||
function merged()
|
||||
{
|
||||
if (!isset($this->_merged)) {
|
||||
if ($this->final1 === $this->final2) {
|
||||
$this->_merged = &$this->final1;
|
||||
} elseif ($this->final1 === $this->orig) {
|
||||
$this->_merged = &$this->final2;
|
||||
} elseif ($this->final2 === $this->orig) {
|
||||
$this->_merged = &$this->final1;
|
||||
} else {
|
||||
$this->_merged = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_merged;
|
||||
}
|
||||
|
||||
function isConflict()
|
||||
{
|
||||
return $this->merged() === false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_ThreeWay_Op_copy extends Text_Diff_ThreeWay_Op {
|
||||
|
||||
function Text_Diff_ThreeWay_Op_Copy($lines = false)
|
||||
{
|
||||
$this->orig = $lines ? $lines : array();
|
||||
$this->final1 = &$this->orig;
|
||||
$this->final2 = &$this->orig;
|
||||
}
|
||||
|
||||
function merged()
|
||||
{
|
||||
return $this->orig;
|
||||
}
|
||||
|
||||
function isConflict()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff_ThreeWay_BlockBuilder {
|
||||
|
||||
function Text_Diff_ThreeWay_BlockBuilder()
|
||||
{
|
||||
$this->_init();
|
||||
}
|
||||
|
||||
function input($lines)
|
||||
{
|
||||
if ($lines) {
|
||||
$this->_append($this->orig, $lines);
|
||||
}
|
||||
}
|
||||
|
||||
function out1($lines)
|
||||
{
|
||||
if ($lines) {
|
||||
$this->_append($this->final1, $lines);
|
||||
}
|
||||
}
|
||||
|
||||
function out2($lines)
|
||||
{
|
||||
if ($lines) {
|
||||
$this->_append($this->final2, $lines);
|
||||
}
|
||||
}
|
||||
|
||||
function isEmpty()
|
||||
{
|
||||
return !$this->orig && !$this->final1 && !$this->final2;
|
||||
}
|
||||
|
||||
function finish()
|
||||
{
|
||||
if ($this->isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
$edit = new Text_Diff_ThreeWay_Op($this->orig, $this->final1, $this->final2);
|
||||
$this->_init();
|
||||
return $edit;
|
||||
}
|
||||
}
|
||||
|
||||
function _init()
|
||||
{
|
||||
$this->orig = $this->final1 = $this->final2 = array();
|
||||
}
|
||||
|
||||
function _append(&$array, $lines)
|
||||
{
|
||||
array_splice($array, sizeof($array), 0, $lines);
|
||||
}
|
||||
|
||||
}
|
||||
276
database/php/pear/Text/Diff3.php
Normal file
276
database/php/pear/Text/Diff3.php
Normal file
@@ -0,0 +1,276 @@
|
||||
<?php
|
||||
/**
|
||||
* A class for computing three way diffs.
|
||||
*
|
||||
* $Horde: framework/Text_Diff/Diff3.php,v 1.2.10.7 2009/01/06 15:23:41 jan Exp $
|
||||
*
|
||||
* Copyright 2007-2009 The Horde Project (http://www.horde.org/)
|
||||
*
|
||||
* See the enclosed file COPYING for license information (LGPL). If you did
|
||||
* not receive this file, see http://opensource.org/licenses/lgpl-license.php.
|
||||
*
|
||||
* @package Text_Diff
|
||||
* @since 0.3.0
|
||||
*/
|
||||
|
||||
/** Text_Diff */
|
||||
require_once 'Text/Diff.php';
|
||||
|
||||
/**
|
||||
* A class for computing three way diffs.
|
||||
*
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*/
|
||||
class Text_Diff3 extends Text_Diff {
|
||||
|
||||
/**
|
||||
* Conflict counter.
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
var $_conflictingBlocks = 0;
|
||||
|
||||
/**
|
||||
* Computes diff between 3 sequences of strings.
|
||||
*
|
||||
* @param array $orig The original lines to use.
|
||||
* @param array $final1 The first version to compare to.
|
||||
* @param array $final2 The second version to compare to.
|
||||
*/
|
||||
function Text_Diff3($orig, $final1, $final2)
|
||||
{
|
||||
if (extension_loaded('xdiff')) {
|
||||
$engine = new Text_Diff_Engine_xdiff();
|
||||
} else {
|
||||
$engine = new Text_Diff_Engine_native();
|
||||
}
|
||||
|
||||
$this->_edits = $this->_diff3($engine->diff($orig, $final1),
|
||||
$engine->diff($orig, $final2));
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
function mergedOutput($label1 = false, $label2 = false)
|
||||
{
|
||||
$lines = array();
|
||||
foreach ($this->_edits as $edit) {
|
||||
if ($edit->isConflict()) {
|
||||
/* FIXME: this should probably be moved somewhere else. */
|
||||
$lines = array_merge($lines,
|
||||
array('<<<<<<<' . ($label1 ? ' ' . $label1 : '')),
|
||||
$edit->final1,
|
||||
array("======="),
|
||||
$edit->final2,
|
||||
array('>>>>>>>' . ($label2 ? ' ' . $label2 : '')));
|
||||
$this->_conflictingBlocks++;
|
||||
} else {
|
||||
$lines = array_merge($lines, $edit->merged());
|
||||
}
|
||||
}
|
||||
|
||||
return $lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* @access private
|
||||
*/
|
||||
function _diff3($edits1, $edits2)
|
||||
{
|
||||
$edits = array();
|
||||
$bb = new Text_Diff3_BlockBuilder();
|
||||
|
||||
$e1 = current($edits1);
|
||||
$e2 = current($edits2);
|
||||
while ($e1 || $e2) {
|
||||
if ($e1 && $e2 && is_a($e1, 'Text_Diff_Op_copy') && is_a($e2, 'Text_Diff_Op_copy')) {
|
||||
/* We have copy blocks from both diffs. This is the (only)
|
||||
* time we want to emit a diff3 copy block. Flush current
|
||||
* diff3 diff block, if any. */
|
||||
if ($edit = $bb->finish()) {
|
||||
$edits[] = $edit;
|
||||
}
|
||||
|
||||
$ncopy = min($e1->norig(), $e2->norig());
|
||||
assert($ncopy > 0);
|
||||
$edits[] = new Text_Diff3_Op_copy(array_slice($e1->orig, 0, $ncopy));
|
||||
|
||||
if ($e1->norig() > $ncopy) {
|
||||
array_splice($e1->orig, 0, $ncopy);
|
||||
array_splice($e1->final, 0, $ncopy);
|
||||
} else {
|
||||
$e1 = next($edits1);
|
||||
}
|
||||
|
||||
if ($e2->norig() > $ncopy) {
|
||||
array_splice($e2->orig, 0, $ncopy);
|
||||
array_splice($e2->final, 0, $ncopy);
|
||||
} else {
|
||||
$e2 = next($edits2);
|
||||
}
|
||||
} else {
|
||||
if ($e1 && $e2) {
|
||||
if ($e1->orig && $e2->orig) {
|
||||
$norig = min($e1->norig(), $e2->norig());
|
||||
$orig = array_splice($e1->orig, 0, $norig);
|
||||
array_splice($e2->orig, 0, $norig);
|
||||
$bb->input($orig);
|
||||
}
|
||||
|
||||
if (is_a($e1, 'Text_Diff_Op_copy')) {
|
||||
$bb->out1(array_splice($e1->final, 0, $norig));
|
||||
}
|
||||
|
||||
if (is_a($e2, 'Text_Diff_Op_copy')) {
|
||||
$bb->out2(array_splice($e2->final, 0, $norig));
|
||||
}
|
||||
}
|
||||
|
||||
if ($e1 && ! $e1->orig) {
|
||||
$bb->out1($e1->final);
|
||||
$e1 = next($edits1);
|
||||
}
|
||||
if ($e2 && ! $e2->orig) {
|
||||
$bb->out2($e2->final);
|
||||
$e2 = next($edits2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($edit = $bb->finish()) {
|
||||
$edits[] = $edit;
|
||||
}
|
||||
|
||||
return $edits;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff3_Op {
|
||||
|
||||
function Text_Diff3_Op($orig = false, $final1 = false, $final2 = false)
|
||||
{
|
||||
$this->orig = $orig ? $orig : array();
|
||||
$this->final1 = $final1 ? $final1 : array();
|
||||
$this->final2 = $final2 ? $final2 : array();
|
||||
}
|
||||
|
||||
function merged()
|
||||
{
|
||||
if (!isset($this->_merged)) {
|
||||
if ($this->final1 === $this->final2) {
|
||||
$this->_merged = &$this->final1;
|
||||
} elseif ($this->final1 === $this->orig) {
|
||||
$this->_merged = &$this->final2;
|
||||
} elseif ($this->final2 === $this->orig) {
|
||||
$this->_merged = &$this->final1;
|
||||
} else {
|
||||
$this->_merged = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_merged;
|
||||
}
|
||||
|
||||
function isConflict()
|
||||
{
|
||||
return $this->merged() === false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff3_Op_copy extends Text_Diff3_Op {
|
||||
|
||||
function Text_Diff3_Op_Copy($lines = false)
|
||||
{
|
||||
$this->orig = $lines ? $lines : array();
|
||||
$this->final1 = &$this->orig;
|
||||
$this->final2 = &$this->orig;
|
||||
}
|
||||
|
||||
function merged()
|
||||
{
|
||||
return $this->orig;
|
||||
}
|
||||
|
||||
function isConflict()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @package Text_Diff
|
||||
* @author Geoffrey T. Dairiki <dairiki@dairiki.org>
|
||||
*
|
||||
* @access private
|
||||
*/
|
||||
class Text_Diff3_BlockBuilder {
|
||||
|
||||
function Text_Diff3_BlockBuilder()
|
||||
{
|
||||
$this->_init();
|
||||
}
|
||||
|
||||
function input($lines)
|
||||
{
|
||||
if ($lines) {
|
||||
$this->_append($this->orig, $lines);
|
||||
}
|
||||
}
|
||||
|
||||
function out1($lines)
|
||||
{
|
||||
if ($lines) {
|
||||
$this->_append($this->final1, $lines);
|
||||
}
|
||||
}
|
||||
|
||||
function out2($lines)
|
||||
{
|
||||
if ($lines) {
|
||||
$this->_append($this->final2, $lines);
|
||||
}
|
||||
}
|
||||
|
||||
function isEmpty()
|
||||
{
|
||||
return !$this->orig && !$this->final1 && !$this->final2;
|
||||
}
|
||||
|
||||
function finish()
|
||||
{
|
||||
if ($this->isEmpty()) {
|
||||
return false;
|
||||
} else {
|
||||
$edit = new Text_Diff3_Op($this->orig, $this->final1, $this->final2);
|
||||
$this->_init();
|
||||
return $edit;
|
||||
}
|
||||
}
|
||||
|
||||
function _init()
|
||||
{
|
||||
$this->orig = $this->final1 = $this->final2 = array();
|
||||
}
|
||||
|
||||
function _append(&$array, $lines)
|
||||
{
|
||||
array_splice($array, sizeof($array), 0, $lines);
|
||||
}
|
||||
|
||||
}
|
||||
164
database/php/pear/Text/Template.php
Normal file
164
database/php/pear/Text/Template.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* Text_Template
|
||||
*
|
||||
* Copyright (c) 2009-2012, Sebastian Bergmann <sb@sebastian-bergmann.de>.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* * Neither the name of Sebastian Bergmann nor the names of his
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Text
|
||||
* @package Template
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
|
||||
* @link http://github.com/sebastianbergmann/php-text-template
|
||||
* @since File available since Release 1.0.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* A simple template engine.
|
||||
*
|
||||
* @category Text
|
||||
* @package Template
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2009-2012 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
|
||||
* @version Release: 1.1.4
|
||||
* @link http://github.com/sebastianbergmann/php-text-template
|
||||
* @since Class available since Release 1.0.0
|
||||
*/
|
||||
class Text_Template
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $template = '';
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $values = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $file
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct($file = '')
|
||||
{
|
||||
$this->setFile($file);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the template file.
|
||||
*
|
||||
* @param string $file
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setFile($file)
|
||||
{
|
||||
$distFile = $file . '.dist';
|
||||
|
||||
if (file_exists($file)) {
|
||||
$this->template = file_get_contents($file);
|
||||
}
|
||||
|
||||
else if (file_exists($distFile)) {
|
||||
$this->template = file_get_contents($distFile);
|
||||
}
|
||||
|
||||
else {
|
||||
throw new InvalidArgumentException(
|
||||
'Template file could not be loaded.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets one or more template variables.
|
||||
*
|
||||
* @param array $values
|
||||
* @param boolean $merge
|
||||
*/
|
||||
public function setVar(array $values, $merge = TRUE)
|
||||
{
|
||||
if (!$merge || empty($this->values)) {
|
||||
$this->values = $values;
|
||||
} else {
|
||||
$this->values = array_merge($this->values, $values);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the template and returns the result.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
$keys = array();
|
||||
|
||||
foreach ($this->values as $key => $value) {
|
||||
$keys[] = '{' . $key . '}';
|
||||
}
|
||||
|
||||
return str_replace($keys, $this->values, $this->template);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the template and writes the result to a file.
|
||||
*
|
||||
* @param string $target
|
||||
*/
|
||||
public function renderTo($target)
|
||||
{
|
||||
$fp = @fopen($target, 'wt');
|
||||
|
||||
if ($fp) {
|
||||
fwrite($fp, $this->render());
|
||||
fclose($fp);
|
||||
} else {
|
||||
$error = error_get_last();
|
||||
|
||||
throw new RuntimeException(
|
||||
sprintf(
|
||||
'Could not write to %s: %s',
|
||||
$target,
|
||||
substr(
|
||||
$error['message'],
|
||||
strpos($error['message'], ':') + 2
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
65
database/php/pear/Text/Template/Autoload.php
Normal file
65
database/php/pear/Text/Template/Autoload.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* Text_Template
|
||||
*
|
||||
* Copyright (c) 2009-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* * Neither the name of Sebastian Bergmann nor the names of his
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @category Text
|
||||
* @package Template
|
||||
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @copyright 2009-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
|
||||
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
|
||||
* @link http://github.com/sebastianbergmann/php-text-template
|
||||
* @since File available since Release 1.1.0
|
||||
*/
|
||||
|
||||
spl_autoload_register(
|
||||
function ($class) {
|
||||
static $classes = NULL;
|
||||
static $path = NULL;
|
||||
|
||||
if ($classes === NULL) {
|
||||
$classes = array(
|
||||
'text_template' => '/Template.php'
|
||||
);
|
||||
|
||||
$path = dirname(dirname(__FILE__));
|
||||
}
|
||||
|
||||
$cn = strtolower($class);
|
||||
|
||||
if (isset($classes[$cn])) {
|
||||
require $path . $classes[$cn];
|
||||
}
|
||||
}
|
||||
);
|
||||
1550
database/php/pear/Text/Wiki.php
Normal file
1550
database/php/pear/Text/Wiki.php
Normal file
File diff suppressed because it is too large
Load Diff
27
database/php/pear/Text/Wiki/Default.php
Normal file
27
database/php/pear/Text/Wiki/Default.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Parse structured wiki text and render into arbitrary formats such as XHTML.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Justin Patrin <justinpatrin@php.net>
|
||||
* @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 <justinpatrin@php.net>
|
||||
*/
|
||||
class Text_Wiki_Default extends Text_Wiki {
|
||||
}
|
||||
264
database/php/pear/Text/Wiki/Parse.php
Normal file
264
database/php/pear/Text/Wiki/Parse.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Baseline rule class for extension into a "real" parser component.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @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 <pmjones@php.net>
|
||||
* @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;
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
87
database/php/pear/Text/Wiki/Parse/Default/Anchor.php
Normal file
87
database/php/pear/Text/Wiki/Parse/Default/Anchor.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for anchor targets.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Manuel Holtgrewe <purestorm at ggnore dot net>
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <purestorm at ggnore dot net>
|
||||
*
|
||||
* @author Paul M. Jones <pmjones at ciaweb dot net>
|
||||
*
|
||||
* @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 <code></code> 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
180
database/php/pear/Text/Wiki/Parse/Default/Blockquote.php
Normal file
180
database/php/pear/Text/Wiki/Parse/Default/Blockquote.php
Normal file
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse for block-quoted text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
79
database/php/pear/Text/Wiki/Parse/Default/Bold.php
Normal file
79
database/php/pear/Text/Wiki/Parse/Default/Bold.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for bold text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
72
database/php/pear/Text/Wiki/Parse/Default/Break.php
Normal file
72
database/php/pear/Text/Wiki/Parse/Default/Break.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for explicit line breaks.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
78
database/php/pear/Text/Wiki/Parse/Default/Center.php
Normal file
78
database/php/pear/Text/Wiki/Parse/Default/Center.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for centered lines of text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
?>
|
||||
99
database/php/pear/Text/Wiki/Parse/Default/Code.php
Normal file
99
database/php/pear/Text/Wiki/Parse/Default/Code.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for text marked as a code example block.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <code> on a line by itself,
|
||||
* followed by the inline code example, and terminated with the string
|
||||
* </code> on a line by itself. The code example is run through the
|
||||
* native PHP highlight_string() function to colorize it, then surrounded
|
||||
* with <pre>...</pre> tags when rendered as XHTML.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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 = '/^(\<code( .+)?\>)\n(.+)\n(\<\/code\>)(\s|$)/Umsi';*/
|
||||
var $regex = ';^<code(\s[^>]*)?>((?:(?R)|.*?)*)\n</code>(\s|$);msi';
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a token entry for the matched text. Token options are:
|
||||
*
|
||||
* 'text' => The full matched text, not including the <code></code> 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];
|
||||
}
|
||||
}
|
||||
?>
|
||||
89
database/php/pear/Text/Wiki/Parse/Default/Colortext.php
Normal file
89
database/php/pear/Text/Wiki/Parse/Default/Colortext.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for colorized text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
122
database/php/pear/Text/Wiki/Parse/Default/Deflist.php
Normal file
122
database/php/pear/Text/Wiki/Parse/Default/Deflist.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for definition lists.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
?>
|
||||
80
database/php/pear/Text/Wiki/Parse/Default/Delimiter.php
Normal file
80
database/php/pear/Text/Wiki/Parse/Default/Delimiter.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for Text_Wiki delimiter characters already in the source text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
106
database/php/pear/Text/Wiki/Parse/Default/Embed.php
Normal file
106
database/php/pear/Text/Wiki/Parse/Default/Embed.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Embeds the results of a PHP script at render-time.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @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 <script> or other similar tags. Be
|
||||
* careful.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Embed extends Text_Wiki_Parse {
|
||||
|
||||
var $conf = array(
|
||||
'base' => '/path/to/scripts/'
|
||||
);
|
||||
|
||||
var $file = null;
|
||||
|
||||
var $output = null;
|
||||
|
||||
var $vars = null;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The regular expression used to find source text matching this
|
||||
* rule.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
var $regex = '/(\[\[embed )(.+?)( .+?)?(\]\])/i';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a token entry for the matched text. Token options are:
|
||||
*
|
||||
* 'text' => The full matched text, not including the <code></code> 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)
|
||||
{
|
||||
// save the file location
|
||||
$this->file = $this->getConf('base', './') . $matches[2];
|
||||
|
||||
// extract attribs as variables in the local space
|
||||
$this->vars = $this->getAttrs($matches[3]);
|
||||
unset($this->vars['this']);
|
||||
extract($this->vars);
|
||||
|
||||
// run the script
|
||||
ob_start();
|
||||
include($this->file);
|
||||
$this->output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// done, place the script output directly in the source
|
||||
return $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array('text' => $this->output)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
85
database/php/pear/Text/Wiki/Parse/Default/Emphasis.php
Normal file
85
database/php/pear/Text/Wiki/Parse/Default/Emphasis.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for emphasized text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Emphasis.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for emphasized text.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked for
|
||||
* emphasis (italics) as defined by text surrounded by two single-quotes.
|
||||
* On parsing, the text itself is left in place, but the starting and ending
|
||||
* instances of two single-quotes are replaced with tokens.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_emphasis 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.
|
||||
*
|
||||
* @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')
|
||||
);
|
||||
|
||||
$end = $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'end')
|
||||
);
|
||||
|
||||
return $start . $matches[1] . $end;
|
||||
}
|
||||
}
|
||||
?>
|
||||
134
database/php/pear/Text/Wiki/Parse/Default/Freelink.php
Normal file
134
database/php/pear/Text/Wiki/Parse/Default/Freelink.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for wiki freelink text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Freelink.php 224598 2006-12-08 08:23:51Z justinpatrin $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for freelinked page links.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked as a
|
||||
* wiki freelink, and automatically create a link to that page.
|
||||
*
|
||||
* A freelink is any page name not conforming to the standard
|
||||
* StudlyCapsStyle for a wiki page name. For example, a page normally
|
||||
* named MyHomePage can be renamed and referred to as ((My Home Page)) --
|
||||
* note the spaces in the page name. You can also make a "nice-looking"
|
||||
* link without renaming the target page; e.g., ((MyHomePage|My Home
|
||||
* Page)). Finally, you can use named anchors on the target page:
|
||||
* ((MyHomePage|My Home Page#Section1)).
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Freelink extends Text_Wiki_Parse {
|
||||
|
||||
var $conf = array (
|
||||
'utf-8' => false
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor. We override the Text_Wiki_Parse constructor so we can
|
||||
* explicitly comment each part of the $regex property.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param object &$obj The calling "parent" Text_Wiki object.
|
||||
*
|
||||
*/
|
||||
|
||||
function Text_Wiki_Parse_Freelink(&$obj)
|
||||
{
|
||||
parent::Text_Wiki_Parse($obj);
|
||||
if ($this->getConf('utf-8')) {
|
||||
$any = '\p{L}';
|
||||
} else {
|
||||
$any = '';
|
||||
}
|
||||
$this->regex =
|
||||
'/' . // START regex
|
||||
"\\(\\(" . // double open-parens
|
||||
"(" . // START freelink page patter
|
||||
"[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&".$any."\xc0-\xff]+" . // 1 or more of just about any character
|
||||
")" . // END freelink page pattern
|
||||
"(" . // START display-name
|
||||
"\|" . // a pipe to start the display name
|
||||
"[-A-Za-z0-9 _+\\/.,;:!?'\"\\[\\]\\{\\}&".$any."\xc0-\xff]+" . // 1 or more of just about any character
|
||||
")?" . // END display-name pattern 0 or 1
|
||||
"(" . // START pattern for named anchors
|
||||
"\#" . // a hash mark
|
||||
"[A-Za-z]" . // 1 alpha
|
||||
"[-A-Za-z0-9_:.]*" . // 0 or more alpha, digit, underscore
|
||||
")?" . // END named anchors pattern 0 or 1
|
||||
"()\\)\\)" . // double close-parens
|
||||
'/'.($this->getConf('utf-8') ? 'u' : ''); // END regex
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text. Token options are:
|
||||
*
|
||||
* 'page' => the wiki page name (e.g., HomePage).
|
||||
*
|
||||
* 'text' => alternative text to be displayed in place of the wiki
|
||||
* page name.
|
||||
*
|
||||
* 'anchor' => a named anchor on the target wiki page
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A delimited token to be used as a placeholder in
|
||||
* the source text, plus any text priot to the match.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// use nice variable names
|
||||
$page = $matches[1];
|
||||
$text = $matches[2];
|
||||
$anchor = $matches[3];
|
||||
|
||||
// is the page given a new text appearance?
|
||||
if (trim($text) == '') {
|
||||
// no
|
||||
$text = $page;
|
||||
} else {
|
||||
// yes, strip the leading | character
|
||||
$text = substr($text, 1);
|
||||
}
|
||||
|
||||
// set the options
|
||||
$options = array(
|
||||
'page' => $page,
|
||||
'text' => $text,
|
||||
'anchor' => $anchor
|
||||
);
|
||||
|
||||
// return a token placeholder
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
141
database/php/pear/Text/Wiki/Parse/Default/Function.php
Normal file
141
database/php/pear/Text/Wiki/Parse/Default/Function.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for an API function documentation block.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Function.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for an API function documentation block.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Function extends Text_Wiki_Parse {
|
||||
|
||||
var $regex = '/^(\<function\>)\n(.+)\n(\<\/function\>)(\s|$)/Umsi';
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// default options
|
||||
$opts = array(
|
||||
'name' => null,
|
||||
'access' => null,
|
||||
'return' => null,
|
||||
'params' => array(),
|
||||
'throws' => array()
|
||||
);
|
||||
|
||||
// split apart the markup lines and loop through them
|
||||
$lines = explode("\n", $matches[2]);
|
||||
foreach ($lines as $line) {
|
||||
|
||||
// skip blank lines
|
||||
if (trim($line) == '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
// find the first ':' on the line; the left part is the
|
||||
// type, the right part is the value. skip lines without
|
||||
// a ':' on them.
|
||||
$pos = strpos($line, ':');
|
||||
if ($pos === false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// $type is the line type: name, access, return, param, throws
|
||||
// 012345678901234
|
||||
// name: something
|
||||
$type = trim(substr($line, 0, $pos));
|
||||
$val = trim(substr($line, $pos+1));
|
||||
|
||||
switch($type) {
|
||||
|
||||
case 'a':
|
||||
case 'access':
|
||||
$opts['access'] = $val;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
case 'name':
|
||||
$opts['name'] = $val;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case 'param':
|
||||
$tmp = explode(',', $val);
|
||||
$k = count($tmp);
|
||||
if ($k == 1) {
|
||||
$opts['params'][] = array(
|
||||
'type' => $tmp[0],
|
||||
'descr' => null,
|
||||
'default' => null
|
||||
);
|
||||
} elseif ($k == 2) {
|
||||
$opts['params'][] = array(
|
||||
'type' => $tmp[0],
|
||||
'descr' => $tmp[1],
|
||||
'default' => null
|
||||
);
|
||||
} else {
|
||||
$opts['params'][] = array(
|
||||
'type' => $tmp[0],
|
||||
'descr' => $tmp[1],
|
||||
'default' => $tmp[2]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
case 'return':
|
||||
case 'returns':
|
||||
$opts['return'] = $val;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
case 'throws':
|
||||
$tmp = explode(',', $val);
|
||||
$k = count($tmp);
|
||||
if ($k == 1) {
|
||||
$opts['throws'][] = array(
|
||||
'type' => $tmp[0],
|
||||
'descr' => null
|
||||
);
|
||||
} else {
|
||||
$opts['throws'][] = array(
|
||||
'type' => $tmp[0],
|
||||
'descr' => $tmp[1]
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$opts[$type] = $val;
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// add the token back in place
|
||||
return $this->wiki->addToken($this->rule, $opts) . $matches[4];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
107
database/php/pear/Text/Wiki/Parse/Default/Heading.php
Normal file
107
database/php/pear/Text/Wiki/Parse/Default/Heading.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for heading text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Heading.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for heading text.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked to
|
||||
* be a heading element, as defined by text on a line by itself prefixed
|
||||
* with a number of plus signs (+). The heading text itself is left in
|
||||
* the source, but is prefixed and suffixed with delimited tokens marking
|
||||
* the start and end of the heading.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Heading 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 = '/^(\+{1,6}) (.*)/m';
|
||||
|
||||
var $conf = array(
|
||||
'id_prefix' => 'toc'
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text. Token options are:
|
||||
*
|
||||
* 'type' => ['start'|'end'] The starting or ending point of the
|
||||
* heading text. The text itself is left in the source.
|
||||
*
|
||||
* @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 heading text.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// keep a running count for header IDs. we use this later
|
||||
// when constructing TOC entries, etc.
|
||||
static $id;
|
||||
if (! isset($id)) {
|
||||
$id = 0;
|
||||
}
|
||||
|
||||
$prefix = htmlspecialchars($this->getConf('id_prefix'));
|
||||
|
||||
$start = $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => 'start',
|
||||
'level' => strlen($matches[1]),
|
||||
'text' => $matches[2],
|
||||
'id' => $prefix . $id ++
|
||||
)
|
||||
);
|
||||
|
||||
$end = $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => 'end',
|
||||
'level' => strlen($matches[1])
|
||||
)
|
||||
);
|
||||
|
||||
return $start . $matches[2] . $end . "\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
70
database/php/pear/Text/Wiki/Parse/Default/Horiz.php
Normal file
70
database/php/pear/Text/Wiki/Parse/Default/Horiz.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for horizontal ruling lines.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Horiz.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for horizontal ruling lines.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked to
|
||||
* be a horizontal rule, as defined by four dashed on their own line.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Horiz 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 = '/^([-]{4,})$/m';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement token for the matched text.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return string A token marking the horizontal rule.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
return $this->wiki->addToken($this->rule);
|
||||
}
|
||||
}
|
||||
?>
|
||||
75
database/php/pear/Text/Wiki/Parse/Default/Html.php
Normal file
75
database/php/pear/Text/Wiki/Parse/Default/Html.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for blocks of HTML code.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Html.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for blocks of HTML code.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked as
|
||||
* HTML to be redndred as-is. The block start is marked by <html> on its
|
||||
* own line, and the block end is marked by </html> on its own line.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Html 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 = '/^\<html\>\n(.+)\n\<\/html\>(\s|$)/Umsi';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text. Token options are:
|
||||
*
|
||||
* 'text' => The text of the HTML to be rendered as-is.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A delimited token to be used as a placeholder in
|
||||
* the source text, plus any text following the HTML block.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
$options = array('text' => $matches[1]);
|
||||
return $this->wiki->addToken($this->rule, $options) . $matches[2];
|
||||
}
|
||||
}
|
||||
?>
|
||||
136
database/php/pear/Text/Wiki/Parse/Default/Image.php
Normal file
136
database/php/pear/Text/Wiki/Parse/Default/Image.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for image placement.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Image.php 195859 2005-09-12 11:34:44Z toggg $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for image placement.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Image extends Text_Wiki_Parse {
|
||||
|
||||
/**
|
||||
* URL schemes recognized by this rule.
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $conf = array(
|
||||
'schemes' => 'http|https|ftp|gopher|news',
|
||||
'host_regexp' => '(?:[^.\s/"\'<\\\#delim#\ca-\cz]+\.)*[a-z](?:[-a-z0-9]*[a-z0-9])?\.?',
|
||||
'path_regexp' => '(?:/[^\s"<\\\#delim#\ca-\cz]*)?'
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* The regular expression used to find source text matching this
|
||||
* rule.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
var $regex = '/(\[\[image\s+)(.+?)(\]\])/i';
|
||||
|
||||
|
||||
/**
|
||||
* The regular expressions used to check ecternal urls
|
||||
*
|
||||
* @access public
|
||||
* @var string
|
||||
* @see parse()
|
||||
*/
|
||||
var $url = '';
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* We override the constructor to build up the url regex from config
|
||||
*
|
||||
* @param object &$obj the base conversion handler
|
||||
* @return The parser object
|
||||
* @access public
|
||||
*/
|
||||
function Text_Wiki_Parse_Image(&$obj)
|
||||
{
|
||||
$default = $this->conf;
|
||||
parent::Text_Wiki_Parse($obj);
|
||||
|
||||
// convert the list of recognized schemes to a regex OR,
|
||||
$schemes = $this->getConf('schemes', $default['schemes']);
|
||||
$this->url = str_replace( '#delim#', $this->wiki->delim,
|
||||
'#(?:' . (is_array($schemes) ? implode('|', $schemes) : $schemes) . ')://'
|
||||
. $this->getConf('host_regexp', $default['host_regexp'])
|
||||
. $this->getConf('path_regexp', $default['path_regexp']) .'#');
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a token entry for the matched text. Token options are:
|
||||
*
|
||||
* 'src' => The image source, typically a relative path name.
|
||||
*
|
||||
* 'opts' => Any macro options following the source.
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$pos = strpos($matches[2], ' ');
|
||||
|
||||
if ($pos === false) {
|
||||
$options = array(
|
||||
'src' => $matches[2],
|
||||
'attr' => array());
|
||||
} else {
|
||||
// everything after the space is attribute arguments
|
||||
$options = array(
|
||||
'src' => substr($matches[2], 0, $pos),
|
||||
'attr' => $this->getAttrs(substr($matches[2], $pos+1))
|
||||
);
|
||||
// check the scheme case of external link
|
||||
if (array_key_exists('link', $options['attr'])) {
|
||||
// external url ?
|
||||
if (($pos = strpos($options['attr']['link'], '://')) !== false) {
|
||||
if (!preg_match($this->url, $options['attr']['link'])) {
|
||||
return $matches[0];
|
||||
}
|
||||
} elseif (in_array('Wikilink', $this->wiki->disable)) {
|
||||
return $matches[0]; // Wikilink disabled
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
100
database/php/pear/Text/Wiki/Parse/Default/Include.php
Normal file
100
database/php/pear/Text/Wiki/Parse/Default/Include.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Includes the contents of another PHP script into the source text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Include.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to include the results of a
|
||||
* script directly into the source at parse-time; thus, the output of the
|
||||
* script will be parsed by Text_Wiki. This differs from the 'embed'
|
||||
* rule, which incorporates the results at render-time, meaning that the
|
||||
* 'embed' content is not parsed by Text_Wiki.
|
||||
*
|
||||
* DANGER!
|
||||
*
|
||||
* This rule is inherently not secure; it allows cross-site scripting to
|
||||
* occur if the embedded output has <script> or other similar tags. Be
|
||||
* careful.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Include extends Text_Wiki_Parse {
|
||||
|
||||
var $conf = array(
|
||||
'base' => '/path/to/scripts/'
|
||||
);
|
||||
|
||||
var $file = null;
|
||||
|
||||
var $output = null;
|
||||
|
||||
var $vars = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* The regular expression used to find source text matching this
|
||||
* rule.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
var $regex = '/(\[\[include )(.+?)( .+?)?(\]\])/i';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Includes the results of the script directly into the source; the output
|
||||
* will subsequently be parsed by the remaining Text_Wiki rules.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return The results of the included script.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// save the file location
|
||||
$this->file = $this->getConf('base', './') . $matches[2];
|
||||
|
||||
// extract attribs as variables in the local space
|
||||
$this->vars = $this->getAttrs($matches[3]);
|
||||
unset($this->vars['this']);
|
||||
extract($this->vars);
|
||||
|
||||
// run the script
|
||||
ob_start();
|
||||
include($this->file);
|
||||
$this->output = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// done, place the script output directly in the source
|
||||
return $this->output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
138
database/php/pear/Text/Wiki/Parse/Default/Interwiki.php
Normal file
138
database/php/pear/Text/Wiki/Parse/Default/Interwiki.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for interwiki links.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Interwiki.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for interwiki links.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked as
|
||||
* an Interwiki link. See the regex for a detailed explanation of the
|
||||
* text matching procedure; e.g., "InterWikiName:PageName".
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Interwiki extends Text_Wiki_Parse {
|
||||
|
||||
// double-colons wont trip up now
|
||||
var $regex = '([A-Za-z0-9_]+):((?!:)[A-Za-z0-9_\/=&~#.:;-]+)';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Parser. We override the standard parser so we can
|
||||
* find both described interwiki links and standalone links.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
|
||||
function parse()
|
||||
{
|
||||
// described interwiki links
|
||||
$tmp_regex = '/\[' . $this->regex . ' (.+?)\]/';
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'processDescr'),
|
||||
$this->wiki->source
|
||||
);
|
||||
|
||||
// standalone interwiki links
|
||||
$tmp_regex = '/' . $this->regex . '/';
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'process'),
|
||||
$this->wiki->source
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched standalone interwiki text.
|
||||
* Token options are:
|
||||
*
|
||||
* 'site' => The key name for the Text_Wiki interwiki array map,
|
||||
* usually the name of the interwiki site.
|
||||
*
|
||||
* 'page' => The page on the target interwiki to link to.
|
||||
*
|
||||
* 'text' => The text to display as the link.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A delimited token to be used as a placeholder in
|
||||
* the source text, plus any text priot to the match.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
$options = array(
|
||||
'site' => $matches[1],
|
||||
'page' => $matches[2],
|
||||
'text' => $matches[0]
|
||||
);
|
||||
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for described interwiki links. Token
|
||||
* options are:
|
||||
*
|
||||
* 'site' => The key name for the Text_Wiki interwiki array map,
|
||||
* usually the name of the interwiki site.
|
||||
*
|
||||
* 'page' => The page on the target interwiki to link to.
|
||||
*
|
||||
* 'text' => The text to display as the link.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A delimited token to be used as a placeholder in
|
||||
* the source text, plus any text priot to the match.
|
||||
*
|
||||
*/
|
||||
|
||||
function processDescr(&$matches)
|
||||
{
|
||||
$options = array(
|
||||
'site' => $matches[1],
|
||||
'page' => $matches[2],
|
||||
'text' => $matches[3]
|
||||
);
|
||||
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
85
database/php/pear/Text/Wiki/Parse/Default/Italic.php
Normal file
85
database/php/pear/Text/Wiki/Parse/Default/Italic.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for italic text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Italic.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for italic text.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked for
|
||||
* emphasis (italics) as defined by text surrounded by two single-quotes.
|
||||
* On parsing, the text itself is left in place, but the starting and ending
|
||||
* instances of two single-quotes are replaced with tokens.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Italic 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 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')
|
||||
);
|
||||
|
||||
$end = $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'end')
|
||||
);
|
||||
|
||||
return $start . $matches[1] . $end;
|
||||
}
|
||||
}
|
||||
?>
|
||||
262
database/php/pear/Text/Wiki/Parse/Default/List.php
Normal file
262
database/php/pear/Text/Wiki/Parse/Default/List.php
Normal file
@@ -0,0 +1,262 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for bulleted and numbered lists.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: List.php 248434 2007-12-17 16:12:25Z justinpatrin $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for bulleted and numbered lists.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked as
|
||||
* a bulleted or numbered list. In short, if a line starts with '* ' then
|
||||
* it is a bullet list item; if a line starts with '# ' then it is a
|
||||
* number list item. Spaces in front of the * or # indicate an indented
|
||||
* sub-list. The list items must be on sequential lines, and may be
|
||||
* separated by blank lines to improve readability. Using a non-* non-#
|
||||
* non-whitespace character at the beginning of a line ends the list.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_List 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 = '/^((\*|#)\s.*\n)(?!\2\s|(?:\s+((?:\*|#) |\n)))/Usm';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text. Token options are:
|
||||
*
|
||||
* 'type' =>
|
||||
* 'bullet_start' : the start of a bullet list
|
||||
* 'bullet_end' : the end of a bullet list
|
||||
* 'number_start' : the start of a number list
|
||||
* 'number_end' : the end of a number list
|
||||
* 'item_start' : the start of item text (bullet or number)
|
||||
* 'item_end' : the end of item text (bullet or number)
|
||||
* 'unknown' : unknown type of list or item
|
||||
*
|
||||
* 'level' => the indent level (0 for the first level, 1 for the
|
||||
* second, etc)
|
||||
*
|
||||
* 'count' => the list item number at this level. not needed for
|
||||
* xhtml, but very useful for PDF and RTF.
|
||||
*
|
||||
* @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
|
||||
$return = '';
|
||||
|
||||
// the list of post-processing matches
|
||||
$list = array();
|
||||
|
||||
// a stack of list-start and list-end types; we keep this
|
||||
// so that we know what kind of list we're working with
|
||||
// (bullet or number) and what indent level we're at.
|
||||
$stack = array();
|
||||
|
||||
// the item count is the number of list items for any
|
||||
// given list-type on the stack
|
||||
$itemcount = array();
|
||||
|
||||
// have we processed the very first list item?
|
||||
$pastFirst = false;
|
||||
|
||||
// populate $list with this set of matches. $matches[1] is the
|
||||
// text matched as a list set by parse().
|
||||
preg_match_all(
|
||||
'=^(\s*)(\*|#)\s(.*)$=Ums',
|
||||
$matches[1],
|
||||
$list,
|
||||
PREG_SET_ORDER
|
||||
);
|
||||
|
||||
$numSpaces = 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 spaces (indent level)
|
||||
// $val[2] is the list item type (* or #)
|
||||
// $val[3] is the list item text
|
||||
|
||||
// how many levels are we indented? (1 means the "root"
|
||||
// list level, no indenting.)
|
||||
$level = strlen($val[1]) + 1;
|
||||
|
||||
// get the list item type
|
||||
if ($val[2] == '*') {
|
||||
$type = 'bullet';
|
||||
} elseif ($val[2] == '#') {
|
||||
$type = 'number';
|
||||
} else {
|
||||
$type = 'unknown';
|
||||
}
|
||||
|
||||
// get the text of the list item
|
||||
$text = $val[3];
|
||||
|
||||
// add a level to the list?
|
||||
if ($level > count($stack)) {
|
||||
|
||||
//watch for the same # of spaces and reset level
|
||||
if ($level == $numSpaces) {
|
||||
$level = count($stack);
|
||||
} else {
|
||||
|
||||
$numSpaces = $level;
|
||||
|
||||
// reset level as sometimes people use too many spaces
|
||||
$level = count($stack) + 1;
|
||||
|
||||
// the current indent level is greater than the
|
||||
// number of stack elements, so we must be starting
|
||||
// a new list. push the new list type onto the
|
||||
// stack...
|
||||
array_push($stack, $type);
|
||||
|
||||
// ...and add a list-start token to the return.
|
||||
$return .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => $type . '_list_start',
|
||||
'level' => $level - 1
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove a level from the list?
|
||||
while (count($stack) > $level) {
|
||||
|
||||
// so we don't keep counting the stack, we set up a temp
|
||||
// var for the count. -1 becuase we're going to pop the
|
||||
// stack in the next command. $tmp will then equal the
|
||||
// current level of indent.
|
||||
$tmp = count($stack) - 1;
|
||||
|
||||
// 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 .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array (
|
||||
'type' => array_pop($stack) . '_list_end',
|
||||
'level' => $tmp
|
||||
)
|
||||
);
|
||||
|
||||
// reset to the current (previous) list type so that
|
||||
// the new list item matches the proper list type.
|
||||
$type = $stack[$tmp - 1];
|
||||
|
||||
// reset the item count for the popped indent level
|
||||
unset($itemcount[$tmp + 1]);
|
||||
}
|
||||
|
||||
// add to the item count for this list (taking into account
|
||||
// which level we are at).
|
||||
if (! isset($itemcount[$level])) {
|
||||
// first count
|
||||
$itemcount[$level] = 0;
|
||||
} else {
|
||||
// increment count
|
||||
$itemcount[$level]++;
|
||||
}
|
||||
|
||||
// is this the very first item in the list?
|
||||
if (! $pastFirst) {
|
||||
$first = true;
|
||||
$pastFirst = true;
|
||||
} else {
|
||||
$first = false;
|
||||
}
|
||||
|
||||
// create a list-item starting token.
|
||||
$start = $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => $type . '_item_start',
|
||||
'level' => $level,
|
||||
'count' => $itemcount[$level],
|
||||
'first' => $first
|
||||
)
|
||||
);
|
||||
|
||||
// create a list-item ending token.
|
||||
$end = $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => $type . '_item_end',
|
||||
'level' => $level,
|
||||
'count' => $itemcount[$level]
|
||||
)
|
||||
);
|
||||
|
||||
// add the starting token, list-item text, and ending token
|
||||
// to the return.
|
||||
$return .= $start . $val[3] . $end;
|
||||
}
|
||||
|
||||
// the last list-item may have been indented. go through the
|
||||
// list-type stack and create end-list tokens until the stack
|
||||
// is empty.
|
||||
while (count($stack) > 0) {
|
||||
$return .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array (
|
||||
'type' => array_pop($stack) . '_list_end',
|
||||
'level' => count($stack)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// we're done! send back the replacement text.
|
||||
return "\n\n" . $return . "\n\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
75
database/php/pear/Text/Wiki/Parse/Default/Newline.php
Normal file
75
database/php/pear/Text/Wiki/Parse/Default/Newline.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for implied line breaks indicated by newlines.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Newline.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for implied line breaks indicated by newlines.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to mark implied line breaks in the
|
||||
* source text, usually a single carriage return in the middle of a paragraph
|
||||
* or block-quoted text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Newline 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])/m';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 $matches[1] .
|
||||
$this->wiki->addToken($this->rule) .
|
||||
$matches[2];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
116
database/php/pear/Text/Wiki/Parse/Default/Paragraph.php
Normal file
116
database/php/pear/Text/Wiki/Parse/Default/Paragraph.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for paragraph blocks.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Paragraph.php 286814 2009-08-04 17:03:17Z rodrigosprimo $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for paragraph blocks.
|
||||
*
|
||||
* This class implements a Text_Wiki rule to find sections of the source
|
||||
* text that are paragraphs. A para is any line not starting with a token
|
||||
* delimiter, followed by two newlines.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Paragraph extends Text_Wiki_Parse {
|
||||
|
||||
/**
|
||||
*
|
||||
* The regular expression used to find source text matching this
|
||||
* rule.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
var $regex = "/^.*?\n\n/m";
|
||||
|
||||
var $conf = array(
|
||||
'skip' => array(
|
||||
'blockquote', // are we sure about this one?
|
||||
'code',
|
||||
'heading',
|
||||
'horiz',
|
||||
'deflist',
|
||||
'table',
|
||||
'list',
|
||||
'toc'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a token entry for the matched text. Token options are:
|
||||
*
|
||||
* 'start' => The starting point of the paragraph.
|
||||
*
|
||||
* 'end' => The ending point of the paragraph.
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$delim = $this->wiki->delim;
|
||||
$skip = $this->getConf('skip', array());
|
||||
|
||||
// was anything there?
|
||||
if (trim($matches[0]) == '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// does the match has tokens inside?
|
||||
preg_match_all("/(?:$delim)(\d+?)(?:$delim)/", $matches[0], $delimiters, PREG_SET_ORDER);
|
||||
|
||||
// look each delimiter inside the match and see if it's skippable
|
||||
// (if we skip, it will not be marked as a paragraph)
|
||||
foreach ($delimiters as $d) {
|
||||
$token_type = strtolower($this->wiki->tokens[$d[1]][0]);
|
||||
if (in_array($token_type, $skip)) {
|
||||
return $matches[0];
|
||||
}
|
||||
}
|
||||
|
||||
// if there is no skipable token inside the match
|
||||
// add the Paragraph token and return
|
||||
$start = $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'start')
|
||||
);
|
||||
|
||||
$end = $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'end')
|
||||
);
|
||||
|
||||
return $start . trim($matches[0]) . $end;
|
||||
}
|
||||
}
|
||||
?>
|
||||
73
database/php/pear/Text/Wiki/Parse/Default/Phplookup.php
Normal file
73
database/php/pear/Text/Wiki/Parse/Default/Phplookup.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Find source text marked for lookup in the PHP online manual.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Phplookup.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Find source text marked for lookup in the PHP online manual.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Phplookup 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 = "/\[\[php (.+?)\]\]/";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text. Token options are:
|
||||
*
|
||||
* 'type' => ['start'|'end'] The starting or ending point of the
|
||||
* teletype text. The text itself is left in the source.
|
||||
*
|
||||
* @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 teletype text.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
return $this->wiki->addToken(
|
||||
$this->rule, array('text' => $matches[1])
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
84
database/php/pear/Text/Wiki/Parse/Default/Prefilter.php
Normal file
84
database/php/pear/Text/Wiki/Parse/Default/Prefilter.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* "Pre-filter" the source text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Prefilter.php 224599 2006-12-08 08:30:37Z justinpatrin $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* "Pre-filter" the source text.
|
||||
*
|
||||
* Convert DOS and Mac line endings to Unix, concat lines ending in a
|
||||
* backslash \ with the next line, convert tabs to 4-spaces, add newlines
|
||||
* to the top and end of the source text, compress 3 or more newlines to
|
||||
* 2 newlines.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Prefilter extends Text_Wiki_Parse {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Simple parsing method.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
|
||||
function parse()
|
||||
{
|
||||
// convert DOS line endings
|
||||
$this->wiki->source = str_replace("\r\n", "\n",
|
||||
$this->wiki->source);
|
||||
|
||||
// convert Macintosh line endings
|
||||
$this->wiki->source = str_replace("\r", "\n",
|
||||
$this->wiki->source);
|
||||
|
||||
// concat lines ending in a backslash
|
||||
$this->wiki->source = str_replace("\\\n", "",
|
||||
$this->wiki->source);
|
||||
|
||||
// convert tabs to four-spaces
|
||||
$this->wiki->source = str_replace("\t", " ",
|
||||
$this->wiki->source);
|
||||
|
||||
// add extra newlines at the top and end; this
|
||||
// seems to help many rules.
|
||||
$this->wiki->source = "\n" . $this->wiki->source . "\n\n";
|
||||
|
||||
$this->wiki->source = str_replace("\n----\n","\n\n----\n\n",
|
||||
$this->wiki->source);
|
||||
$this->wiki->source = preg_replace("/\n(\\+{1,6})(.*)\n/m",
|
||||
"\n\n\\1 \\2\n\n",
|
||||
$this->wiki->source);
|
||||
|
||||
// finally, compress all instances of 3 or more newlines
|
||||
// down to two newlines.
|
||||
$find = "/\n{3,}/m";
|
||||
$replace = "\n\n";
|
||||
$this->wiki->source = preg_replace($find, $replace,
|
||||
$this->wiki->source);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
73
database/php/pear/Text/Wiki/Parse/Default/Raw.php
Normal file
73
database/php/pear/Text/Wiki/Parse/Default/Raw.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for text marked as "raw" (i.e., to be rendered as-is).
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Raw.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for text marked as "raw" (i.e., to be rendered as-is).
|
||||
*
|
||||
* This class implements a Text_Wiki rule to find sections of the source
|
||||
* text that are not to be processed by Text_Wiki. These blocks of "raw"
|
||||
* text will be rendered as they were found.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Raw extends Text_Wiki_Parse {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The regular expression used to find source text matching this
|
||||
* rule.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
*/
|
||||
|
||||
var $regex = "/``(.*)``/U";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 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)
|
||||
{
|
||||
$options = array('text' => $matches[1]);
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
145
database/php/pear/Text/Wiki/Parse/Default/Revise.php
Normal file
145
database/php/pear/Text/Wiki/Parse/Default/Revise.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for text marked as revised (insert/delete).
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Revise.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for text marked as revised (insert/delete).
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Revise 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";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Config options.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
*/
|
||||
|
||||
var $conf = array(
|
||||
'delmark' => '---',
|
||||
'insmark' => '+++'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text. Token options are:
|
||||
*
|
||||
* 'type' => ['start'|'end'] The starting or ending point of the
|
||||
* inserted text. The text itself is left in the source.
|
||||
*
|
||||
* @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 teletype text.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
$output = '';
|
||||
$src = $matches[1];
|
||||
$delmark = $this->getConf('delmark'); // ---
|
||||
$insmark = $this->getConf('insmark'); // +++
|
||||
|
||||
// '---' must be before '+++' (if they both appear)
|
||||
$del = strpos($src, $delmark);
|
||||
$ins = strpos($src, $insmark);
|
||||
|
||||
// if neither is found, return right away
|
||||
if ($del === false && $ins === false) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
// handle text to be deleted
|
||||
if ($del !== false) {
|
||||
|
||||
// move forward to the end of the deletion mark
|
||||
$del += strlen($delmark);
|
||||
|
||||
if ($ins === false) {
|
||||
// there is no insertion text following
|
||||
$text = substr($src, $del);
|
||||
} else {
|
||||
// there is insertion text following,
|
||||
// mitigate the length
|
||||
$text = substr($src, $del, $ins - $del);
|
||||
}
|
||||
|
||||
$output .= $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'del_start')
|
||||
);
|
||||
|
||||
$output .= $text;
|
||||
|
||||
$output .= $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'del_end')
|
||||
);
|
||||
}
|
||||
|
||||
// handle text to be inserted
|
||||
if ($ins !== false) {
|
||||
|
||||
// move forward to the end of the insert mark
|
||||
$ins += strlen($insmark);
|
||||
$text = substr($src, $ins);
|
||||
|
||||
$output .= $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'ins_start')
|
||||
);
|
||||
|
||||
$output .= $text;
|
||||
|
||||
$output .= $this->wiki->addToken(
|
||||
$this->rule, array('type' => 'ins_end')
|
||||
);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
?>
|
||||
157
database/php/pear/Text/Wiki/Parse/Default/Smiley.php
Normal file
157
database/php/pear/Text/Wiki/Parse/Default/Smiley.php
Normal file
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Default: Parses for smileys / emoticons tags
|
||||
*
|
||||
* This class implements a Text_Wiki_Rule to find source text marked as
|
||||
* smileys defined by symbols as ':)' , ':-)' or ':smile:'
|
||||
* The symbol is replaced with a token.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Smiley.php 197527 2005-10-04 08:17:51Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smiley rule parser class for Default.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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_Parse::Text_Wiki_Parse()
|
||||
*/
|
||||
class Text_Wiki_Parse_Smiley extends Text_Wiki_Parse {
|
||||
|
||||
/**
|
||||
* Configuration keys for this rule
|
||||
* 'smileys' => array Smileys recognized by this rule, symbols key definitions:
|
||||
* 'symbol' => array ( 'name', 'description' [, 'variante', ...] ) as
|
||||
* ':)' => array('smile', 'Smile'),
|
||||
* ':D' => array('biggrin', 'Very Happy',':grin:'),
|
||||
* the eventual elements after symbol and description are variantes
|
||||
*
|
||||
* 'auto_nose' => boolean enabling the auto nose feature:
|
||||
* auto build a variante for 2 chars symbols by inserting a '-' as ':)' <=> ':-)'
|
||||
*
|
||||
* @access public
|
||||
* @var array 'config-key' => mixed config-value
|
||||
*/
|
||||
var $conf = array(
|
||||
'smileys' => array(
|
||||
':D' => array('biggrin', 'Very Happy', ':grin:'),
|
||||
':)' => array('smile', 'Smile', '(:'),
|
||||
':(' => array('sad', 'Sad', '):'),
|
||||
':o' => array('surprised', 'Surprised', ':eek:', 'o:'),
|
||||
':shock:' => array('eek', 'Shocked'),
|
||||
':?' => array('confused', 'Confused', ':???:'),
|
||||
'8)' => array('cool', 'Cool', '(8'),
|
||||
':lol:' => array('lol', 'Laughing'),
|
||||
':x' => array('mad', 'Mad'),
|
||||
':P' => array('razz', 'Razz'),
|
||||
':oops:' => array('redface', 'Embarassed'),
|
||||
':cry:' => array('cry', 'Crying or Very sad'),
|
||||
':evil:' => array('evil', 'Evil or Very Mad'),
|
||||
':twisted:' => array('twisted', 'Twisted Evil'),
|
||||
':roll:' => array('rolleyes', 'Rolling Eyes'),
|
||||
';)' => array('wink', 'Wink', '(;'),
|
||||
':!:' => array('exclaim', 'Exclamation'),
|
||||
':?:' => array('question', 'Question'),
|
||||
':idea:' => array('idea', 'Idea'),
|
||||
':arrow:' => array('arrow', 'Arrow'),
|
||||
':|' => array('neutral', 'Neutral', '|:'),
|
||||
':mrgreen:' => array('mrgreen', 'Mr. Green'),
|
||||
),
|
||||
'auto_nose' => true
|
||||
);
|
||||
|
||||
/**
|
||||
* Definition array of smileys, variantes references their model
|
||||
* 'symbol' => array ( 'name', 'description')
|
||||
*
|
||||
* @access private
|
||||
* @var array 'config-key' => mixed config-value
|
||||
*/
|
||||
var $_smileys = array();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* We override the constructor to build up the regex from config
|
||||
*
|
||||
* @param object &$obj the base conversion handler
|
||||
* @return The parser object
|
||||
* @access public
|
||||
*/
|
||||
function Text_Wiki_Parse_Smiley(&$obj)
|
||||
{
|
||||
$default = $this->conf;
|
||||
parent::Text_Wiki_Parse($obj);
|
||||
|
||||
// read the list of smileys to sort out variantes and :xxx: while building the regexp
|
||||
$this->_smileys = $this->getConf('smileys', $default['smileys']);
|
||||
$autoNose = $this->getConf('auto_nose', $default['auto_nose']);
|
||||
$reg1 = $reg2 = '';
|
||||
$sep1 = ':(?:';
|
||||
$sep2 = '';
|
||||
foreach ($this->_smileys as $smiley => $def) {
|
||||
for ($i = 1; $i < count($def); $i++) {
|
||||
if ($i > 1) {
|
||||
$cur = $def[$i];
|
||||
$this->_smileys[$cur] = &$this->_smileys[$smiley];
|
||||
} else {
|
||||
$cur = $smiley;
|
||||
}
|
||||
$len = strlen($cur);
|
||||
if (($cur{0} == ':') && ($len > 2) && ($cur{$len - 1} == ':')) {
|
||||
$reg1 .= $sep1 . preg_quote(substr($cur, 1, -1), '#');
|
||||
$sep1 = '|';
|
||||
continue;
|
||||
}
|
||||
if ($autoNose && ($len === 2)) {
|
||||
$variante = $cur{0} . '-' . $cur{1};
|
||||
$this->_smileys[$variante] = &$this->_smileys[$smiley];
|
||||
$cur = preg_quote($cur{0}, '#') . '-?' . preg_quote($cur{1}, '#');
|
||||
} else {
|
||||
$cur = preg_quote($cur, '#');
|
||||
}
|
||||
$reg2 .= $sep2 . $cur;
|
||||
$sep2 = '|';
|
||||
}
|
||||
}
|
||||
$delim = '[\n\r\s' . $this->wiki->delim . '$^]';
|
||||
$this->regex = '#(?<=' . $delim .
|
||||
')(' . ($reg1 ? $reg1 . '):' . ($reg2 ? '|' : '') : '') . $reg2 .
|
||||
')(?=' . $delim . ')#i';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a replacement token for the matched text. Token options are:
|
||||
* 'symbol' => the original marker
|
||||
* 'name' => the name of the smiley
|
||||
* 'desc' => the description of the smiley
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
* @return string Delimited token representing the smiley
|
||||
* @access public
|
||||
*/
|
||||
function process(&$matches)
|
||||
{
|
||||
// tokenize
|
||||
return $this->wiki->addToken($this->rule,
|
||||
array(
|
||||
'symbol' => $matches[1],
|
||||
'name' => $this->_smileys[$matches[1]][0],
|
||||
'desc' => $this->_smileys[$matches[1]][1]
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
86
database/php/pear/Text/Wiki/Parse/Default/Strong.php
Normal file
86
database/php/pear/Text/Wiki/Parse/Default/Strong.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for strongly-emphasized text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Strong.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for strongly-emphasized text.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse 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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Strong 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.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
79
database/php/pear/Text/Wiki/Parse/Default/Subscript.php
Normal file
79
database/php/pear/Text/Wiki/Parse/Default/Subscript.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for subscripted text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Subscript.php 180691 2005-02-24 17:24:56Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for subscripted text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Subscript 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
79
database/php/pear/Text/Wiki/Parse/Default/Superscript.php
Normal file
79
database/php/pear/Text/Wiki/Parse/Default/Superscript.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for superscripted text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Superscript.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for superscripted text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Superscript 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
226
database/php/pear/Text/Wiki/Parse/Default/Table.php
Normal file
226
database/php/pear/Text/Wiki/Parse/Default/Table.php
Normal file
@@ -0,0 +1,226 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for table markup.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Table.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for table markup.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find source text marked as a
|
||||
* set of table rows, where a line start and ends with double-pipes (||)
|
||||
* and uses double-pipes to separate table cells. The rows must be on
|
||||
* sequential lines (no blank lines between them) -- a blank line
|
||||
* indicates the beginning of a new table.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Table 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)(?!(\|\|))/Us';
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text.
|
||||
*
|
||||
* Token options are:
|
||||
*
|
||||
* 'type' =>
|
||||
* 'table_start' : the start of a bullet list
|
||||
* 'table_end' : the end of a bullet list
|
||||
* 'row_start' : the start of a number list
|
||||
* 'row_end' : the end of a number list
|
||||
* 'cell_start' : the start of item text (bullet or number)
|
||||
* 'cell_end' : the end of item text (bullet or number)
|
||||
*
|
||||
* 'cols' => the number of columns in the table (for 'table_start')
|
||||
*
|
||||
* 'rows' => the number of rows in the table (for 'table_start')
|
||||
*
|
||||
* 'span' => column span (for 'cell_start')
|
||||
*
|
||||
* 'attr' => column attribute flag (for 'cell_start')
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A series of text and delimited tokens marking the different
|
||||
* table elements and cell text.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// our eventual return value
|
||||
$return = '';
|
||||
|
||||
// the number of columns in the table
|
||||
$num_cols = 0;
|
||||
|
||||
// the number of rows in the table
|
||||
$num_rows = 0;
|
||||
|
||||
// rows are separated by newlines in the matched text
|
||||
$rows = explode("\n", $matches[1]);
|
||||
|
||||
// loop through each row
|
||||
foreach ($rows as $row) {
|
||||
|
||||
// increase the row count
|
||||
$num_rows ++;
|
||||
|
||||
// start a new row
|
||||
$return .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array('type' => 'row_start')
|
||||
);
|
||||
|
||||
// cells are separated by double-pipes
|
||||
$cell = explode("||", $row);
|
||||
|
||||
// get the number of cells (columns) in this row
|
||||
$last = count($cell) - 1;
|
||||
|
||||
// is this more than the current column count?
|
||||
// (we decrease by 1 because we never use cell zero)
|
||||
if ($last - 1 > $num_cols) {
|
||||
// increase the column count
|
||||
$num_cols = $last - 1;
|
||||
}
|
||||
|
||||
// by default, cells span only one column (their own)
|
||||
$span = 1;
|
||||
|
||||
// ignore cell zero, and ignore the "last" cell; cell zero
|
||||
// is before the first double-pipe, and the "last" cell is
|
||||
// after the last double-pipe. both are always empty.
|
||||
for ($i = 1; $i < $last; $i ++) {
|
||||
|
||||
// if there is no content at all, then it's an instance
|
||||
// of two sets of || next to each other, indicating a
|
||||
// span.
|
||||
if ($cell[$i] == '') {
|
||||
|
||||
// add to the span and loop to the next cell
|
||||
$span += 1;
|
||||
continue;
|
||||
|
||||
} else {
|
||||
|
||||
// this cell has content.
|
||||
|
||||
// find any special "attr"ibute cell markers
|
||||
if (substr($cell[$i], 0, 2) == '> ') {
|
||||
// right-align
|
||||
$attr = 'right';
|
||||
$cell[$i] = substr($cell[$i], 2);
|
||||
} elseif (substr($cell[$i], 0, 2) == '= ') {
|
||||
// center-align
|
||||
$attr = 'center';
|
||||
$cell[$i] = substr($cell[$i], 2);
|
||||
} elseif (substr($cell[$i], 0, 2) == '< ') {
|
||||
// left-align
|
||||
$attr = 'left';
|
||||
$cell[$i] = substr($cell[$i], 2);
|
||||
} elseif (substr($cell[$i], 0, 2) == '~ ') {
|
||||
$attr = 'header';
|
||||
$cell[$i] = substr($cell[$i], 2);
|
||||
} else {
|
||||
$attr = null;
|
||||
}
|
||||
|
||||
// start a new cell...
|
||||
$return .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array (
|
||||
'type' => 'cell_start',
|
||||
'attr' => $attr,
|
||||
'span' => $span
|
||||
)
|
||||
);
|
||||
|
||||
// ...add the content...
|
||||
$return .= trim($cell[$i]);
|
||||
|
||||
// ...and end the cell.
|
||||
$return .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array (
|
||||
'type' => 'cell_end',
|
||||
'attr' => $attr,
|
||||
'span' => $span
|
||||
)
|
||||
);
|
||||
|
||||
// reset the span.
|
||||
$span = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// end the row
|
||||
$return .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array('type' => 'row_end')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// wrap the return value in start and end tokens
|
||||
$return =
|
||||
$this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => 'table_start',
|
||||
'rows' => $num_rows,
|
||||
'cols' => $num_cols
|
||||
)
|
||||
)
|
||||
. $return .
|
||||
$this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => 'table_end'
|
||||
)
|
||||
);
|
||||
|
||||
// we're done!
|
||||
return "\n$return\n\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
49
database/php/pear/Text/Wiki/Parse/Default/Tighten.php
Normal file
49
database/php/pear/Text/Wiki/Parse/Default/Tighten.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* The rule removes all remaining newlines.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Tighten.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The rule removes all remaining newlines.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Tighten extends Text_Wiki_Parse {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Apply tightening directly to the source text.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
|
||||
function parse()
|
||||
{
|
||||
$this->wiki->source = str_replace("\n", '',
|
||||
$this->wiki->source);
|
||||
}
|
||||
}
|
||||
?>
|
||||
130
database/php/pear/Text/Wiki/Parse/Default/Toc.php
Normal file
130
database/php/pear/Text/Wiki/Parse/Default/Toc.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Looks through parsed text and builds a table of contents.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Toc.php 187179 2005-05-28 21:33:02Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Looks through parsed text and builds a table of contents.
|
||||
*
|
||||
* This class implements a Text_Wiki_Parse to find all heading tokens and
|
||||
* build a table of contents. The [[toc]] tag gets replaced with a list
|
||||
* of all the level-2 through level-6 headings.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
class Text_Wiki_Parse_Toc 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\[\[toc( .*)?\]\]\n/m";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text.
|
||||
*
|
||||
* Token options are:
|
||||
*
|
||||
* 'type' => ['list_start'|'list_end'|'item_start'|'item_end'|'target']
|
||||
*
|
||||
* 'level' => The heading level (1-6).
|
||||
*
|
||||
* 'count' => Which entry number this is in the list.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return string A token indicating the TOC collection point.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
if (isset($matches[1])) {
|
||||
$attr = $this->getAttrs(trim($matches[1]));
|
||||
} else {
|
||||
$attr = array();
|
||||
}
|
||||
|
||||
$output = $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => 'list_start',
|
||||
'level' => 0,
|
||||
'attr' => $attr
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($this->wiki->getTokens('Heading') as $key => $val) {
|
||||
|
||||
if ($val[1]['type'] != 'start') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$options = array(
|
||||
'type' => 'item_start',
|
||||
'id' => $val[1]['id'],
|
||||
'level' => $val[1]['level'],
|
||||
'count' => $count ++
|
||||
);
|
||||
|
||||
$output .= $this->wiki->addToken($this->rule, $options);
|
||||
|
||||
$output .= $val[1]['text'];
|
||||
|
||||
$output .= $this->wiki->addToken(
|
||||
$this->rule,
|
||||
array(
|
||||
'type' => 'item_end',
|
||||
'level' => $val[1]['level']
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$output .= $this->wiki->addToken(
|
||||
$this->rule, array(
|
||||
'type' => 'list_end',
|
||||
'level' => 0
|
||||
)
|
||||
);
|
||||
|
||||
return "\n$output\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
84
database/php/pear/Text/Wiki/Parse/Default/Tt.php
Normal file
84
database/php/pear/Text/Wiki/Parse/Default/Tt.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Find source text marked for teletype (monospace).
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Tt.php 180591 2005-02-23 17:38:29Z pmjones $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Find source text marked for teletype (monospace).
|
||||
*
|
||||
* Defined by text surrounded by two curly braces. On parsing, the text
|
||||
* itself is left in place, but the starting and ending instances of
|
||||
* curly braces are replaced with tokens.
|
||||
*
|
||||
* Token options are:
|
||||
*
|
||||
* 'type' => ['start'|'end'] The starting or ending point of the
|
||||
* teletype text. The text itself is left in the source.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Tt extends Text_Wiki_Parse {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The regular expression used to parse the source text.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var string
|
||||
*
|
||||
* @see parse()
|
||||
*
|
||||
*/
|
||||
|
||||
var $regex = "/{{({*?.*}*?)}}/U";
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generates a replacement for the matched text.
|
||||
*
|
||||
* @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 teletype text.
|
||||
*
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
79
database/php/pear/Text/Wiki/Parse/Default/Underline.php
Normal file
79
database/php/pear/Text/Wiki/Parse/Default/Underline.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parses for bold text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Underline.php 190446 2005-07-10 20:40:20Z justinpatrin $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Underline 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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
281
database/php/pear/Text/Wiki/Parse/Default/Url.php
Normal file
281
database/php/pear/Text/Wiki/Parse/Default/Url.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse for URLS in the source text.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Url.php 293784 2010-01-20 18:48:09Z justinpatrin $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse for URLS in the source text.
|
||||
*
|
||||
* Various URL markings are supported: inline (the URL by itself),
|
||||
* numbered or footnote reference (where the URL is enclosed in square
|
||||
* brackets), and named reference (where the URL is enclosed in square
|
||||
* brackets and has a name included inside the brackets). E.g.:
|
||||
*
|
||||
* inline -- http://example.com
|
||||
* numbered -- [http://example.com]
|
||||
* described -- [http://example.com Example Description]
|
||||
*
|
||||
* When rendering a URL token, this will convert URLs pointing to a .gif,
|
||||
* .jpg, or .png image into an inline <img /> tag (for the 'xhtml'
|
||||
* format).
|
||||
*
|
||||
* Token options are:
|
||||
*
|
||||
* 'type' => ['inline'|'footnote'|'descr'] the type of URL
|
||||
*
|
||||
* 'href' => the URL link href portion
|
||||
*
|
||||
* 'text' => the displayed text of the URL link
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Url extends Text_Wiki_Parse {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Keeps a running count of numbered-reference URLs.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var int
|
||||
*
|
||||
*/
|
||||
|
||||
var $footnoteCount = 0;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* URL schemes recognized by this rule.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
*/
|
||||
|
||||
var $conf = array(
|
||||
'schemes' => array(
|
||||
'http://',
|
||||
'https://',
|
||||
'ftp://',
|
||||
'gopher://',
|
||||
'news://',
|
||||
'mailto:'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor.
|
||||
*
|
||||
* We override the constructor so we can comment the regex nicely.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
|
||||
function Text_Wiki_Parse_Url(&$obj)
|
||||
{
|
||||
parent::Text_Wiki_Parse($obj);
|
||||
|
||||
// convert the list of recognized schemes to a regex-safe string,
|
||||
// where the pattern delim is a slash
|
||||
$tmp = array();
|
||||
$list = $this->getConf('schemes', array());
|
||||
foreach ($list as $val) {
|
||||
$tmp[] = preg_quote($val, '/');
|
||||
}
|
||||
$schemes = implode('|', $tmp);
|
||||
|
||||
// build the regex
|
||||
$this->regex =
|
||||
"($schemes)" . // allowed schemes
|
||||
"(" . // start pattern
|
||||
"[^ \\/\"\'{$this->wiki->delim}]*\\/" . // no spaces, backslashes, slashes, double-quotes, single quotes, or delimiters;
|
||||
")*" . // end pattern
|
||||
"[^ \\t\\n\\/\"\'{$this->wiki->delim}]*" .
|
||||
"[A-Za-z0-9\\/?=&~_#]";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Find three different kinds of URLs in the source text.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
*/
|
||||
|
||||
function parse()
|
||||
{
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Described-reference (named) URLs.
|
||||
//
|
||||
|
||||
// the regular expression for this kind of URL
|
||||
$tmp_regex = '/\[(' . $this->regex . ') ([^\]]+)\]/';
|
||||
|
||||
// use a custom callback processing method to generate
|
||||
// the replacement text for matches.
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'processDescr'),
|
||||
$this->wiki->source
|
||||
);
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Numbered-reference (footnote-style) URLs.
|
||||
//
|
||||
|
||||
// the regular expression for this kind of URL
|
||||
$tmp_regex = '/\[(' . $this->regex . ')\]/U';
|
||||
|
||||
// use a custom callback processing method to generate
|
||||
// the replacement text for matches.
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'processFootnote'),
|
||||
$this->wiki->source
|
||||
);
|
||||
|
||||
|
||||
// -------------------------------------------------------------
|
||||
//
|
||||
// Normal inline URLs.
|
||||
//
|
||||
|
||||
// the regular expression for this kind of URL
|
||||
|
||||
$tmp_regex = '/(^|[^A-Za-z])(' . $this->regex . ')(.*?)/';
|
||||
|
||||
// use the standard callback for inline URLs
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'process'),
|
||||
$this->wiki->source
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Process inline URLs.
|
||||
*
|
||||
* @param array &$matches
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// set options
|
||||
$options = array(
|
||||
'type' => 'inline',
|
||||
'href' => $matches[2],
|
||||
'text' => $matches[2]
|
||||
);
|
||||
|
||||
// tokenize
|
||||
return $matches[1] . $this->wiki->addToken($this->rule, $options) . $matches[5];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Process numbered (footnote) URLs.
|
||||
*
|
||||
* Token options are:
|
||||
* @param array &$matches
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
|
||||
function processFootnote(&$matches)
|
||||
{
|
||||
// keep a running count for footnotes
|
||||
$this->footnoteCount++;
|
||||
|
||||
// set options
|
||||
$options = array(
|
||||
'type' => 'footnote',
|
||||
'href' => $matches[1],
|
||||
'text' => $this->footnoteCount
|
||||
);
|
||||
|
||||
// tokenize
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Process described-reference (named-reference) URLs.
|
||||
*
|
||||
* Token options are:
|
||||
* 'type' => ['inline'|'footnote'|'descr'] the type of URL
|
||||
* 'href' => the URL link href portion
|
||||
* 'text' => the displayed text of the URL link
|
||||
*
|
||||
* @param array &$matches
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
*/
|
||||
|
||||
function processDescr(&$matches)
|
||||
{
|
||||
// set options
|
||||
$options = array(
|
||||
'type' => 'descr',
|
||||
'href' => $matches[1],
|
||||
'text' => $matches[4]
|
||||
);
|
||||
|
||||
// tokenize
|
||||
return $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
204
database/php/pear/Text/Wiki/Parse/Default/Wikilink.php
Normal file
204
database/php/pear/Text/Wiki/Parse/Default/Wikilink.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse for links to wiki pages.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
* @license LGPL
|
||||
*
|
||||
* @version $Id: Wikilink.php 224598 2006-12-08 08:23:51Z justinpatrin $
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* Parse for links to wiki pages.
|
||||
*
|
||||
* Wiki page names are typically in StudlyCapsStyle made of
|
||||
* WordsSmashedTogether.
|
||||
*
|
||||
* You can also create described links to pages in this style:
|
||||
* [WikiPageName nice text link to use for display]
|
||||
*
|
||||
* The token options for this rule are:
|
||||
*
|
||||
* 'page' => the wiki page name.
|
||||
*
|
||||
* 'text' => the displayed link text.
|
||||
*
|
||||
* 'anchor' => a named anchor on the target wiki page.
|
||||
*
|
||||
* @category Text
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Parse_Wikilink extends Text_Wiki_Parse {
|
||||
|
||||
var $conf = array (
|
||||
'ext_chars' => false,
|
||||
'utf-8' => false
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* Constructor.
|
||||
*
|
||||
* We override the Text_Wiki_Parse constructor so we can
|
||||
* explicitly comment each part of the $regex property.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param object &$obj The calling "parent" Text_Wiki object.
|
||||
*
|
||||
*/
|
||||
|
||||
function Text_Wiki_Parse_Wikilink(&$obj)
|
||||
{
|
||||
parent::Text_Wiki_Parse($obj);
|
||||
|
||||
if ($this->getConf('utf-8')) {
|
||||
$upper = 'A-Z\p{Lu}';
|
||||
$lower = 'a-z0-9\p{Ll}';
|
||||
$either = 'A-Za-z0-9\p{L}';
|
||||
} else if ($this->getConf('ext_chars')) {
|
||||
// use an extended character set; this should
|
||||
// allow for umlauts and so on. taken from the
|
||||
// Tavi project defaults.php file.
|
||||
$upper = 'A-Z\xc0-\xde';
|
||||
$lower = 'a-z0-9\xdf-\xfe';
|
||||
$either = 'A-Za-z0-9\xc0-\xfe';
|
||||
} else {
|
||||
// the default character set, should be fine
|
||||
// for most purposes.
|
||||
$upper = "A-Z";
|
||||
$lower = "a-z0-9";
|
||||
$either = "A-Za-z0-9";
|
||||
}
|
||||
|
||||
// build the regular expression for finding WikiPage names.
|
||||
$this->regex =
|
||||
"(!?" . // START WikiPage pattern (1)
|
||||
"[$upper]" . // 1 upper
|
||||
"[$either]*" . // 0+ alpha or digit
|
||||
"[$lower]+" . // 1+ lower or digit
|
||||
"[$upper]" . // 1 upper
|
||||
"[$either]*" . // 0+ or more alpha or digit
|
||||
")" . // END WikiPage pattern (/1)
|
||||
"((\#" . // START Anchor pattern (2)(3)
|
||||
"[$either]" . // 1 alpha
|
||||
"(" . // start sub pattern (4)
|
||||
"[-_$either:.]*" . // 0+ dash, alpha, digit, underscore, colon, dot
|
||||
"[-_$either]" . // 1 dash, alpha, digit, or underscore
|
||||
")?)?)"; // end subpatterns (/4)(/3)(/2)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* First parses for described links, then for standalone links.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
*/
|
||||
|
||||
function parse()
|
||||
{
|
||||
// described wiki links
|
||||
$tmp_regex = '/\[' . $this->regex . ' (.+?)\]/'.($this->getConf('utf-8') ? 'u' : '');
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'processDescr'),
|
||||
$this->wiki->source
|
||||
);
|
||||
|
||||
// standalone wiki links
|
||||
if ($this->getConf('utf-8')) {
|
||||
$either = 'A-Za-z0-9\p{L}';
|
||||
} else if ($this->getConf('ext_chars')) {
|
||||
$either = "A-Za-z0-9\xc0-\xfe";
|
||||
} else {
|
||||
$either = "A-Za-z0-9";
|
||||
}
|
||||
|
||||
$tmp_regex = "/(^|[^{$either}\-_]){$this->regex}/".($this->getConf('utf-8') ? 'u' : '');
|
||||
$this->wiki->source = preg_replace_callback(
|
||||
$tmp_regex,
|
||||
array(&$this, 'process'),
|
||||
$this->wiki->source
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generate a replacement for described links.
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A delimited token to be used as a placeholder in
|
||||
* the source text, plus any text priot to the match.
|
||||
*
|
||||
*/
|
||||
|
||||
function processDescr(&$matches)
|
||||
{
|
||||
// set the options
|
||||
$options = array(
|
||||
'page' => $matches[1],
|
||||
'text' => $matches[5],
|
||||
'anchor' => $matches[3]
|
||||
);
|
||||
|
||||
// create and return the replacement token and preceding text
|
||||
return $this->wiki->addToken($this->rule, $options); // . $matches[7];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Generate a replacement for standalone links.
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
*
|
||||
* @param array &$matches The array of matches from parse().
|
||||
*
|
||||
* @return A delimited token to be used as a placeholder in
|
||||
* the source text, plus any text prior to the match.
|
||||
*
|
||||
*/
|
||||
|
||||
function process(&$matches)
|
||||
{
|
||||
// when prefixed with !, it's explicitly not a wiki link.
|
||||
// return everything as it was.
|
||||
if ($matches[2]{0} == '!') {
|
||||
return $matches[1] . substr($matches[2], 1) . $matches[3];
|
||||
}
|
||||
|
||||
// set the options
|
||||
$options = array(
|
||||
'page' => $matches[2],
|
||||
'text' => $matches[2] . $matches[3],
|
||||
'anchor' => $matches[3]
|
||||
);
|
||||
|
||||
// create and return the replacement token and preceding text
|
||||
return $matches[1] . $this->wiki->addToken($this->rule, $options);
|
||||
}
|
||||
}
|
||||
?>
|
||||
218
database/php/pear/Text/Wiki/Render.php
Normal file
218
database/php/pear/Text/Wiki/Render.php
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Base rendering class for parsed and tokenized text.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Paul M. Jones <pmjones@php.net>
|
||||
* @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 <pmjones@php.net>
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
?>
|
||||
90
database/php/pear/Text/Wiki/Render/Latex.php
Normal file
90
database/php/pear/Text/Wiki/Render/Latex.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* Formats parsed Text_Wiki for LaTeX rendering.
|
||||
*
|
||||
* $Id: Latex.php 169211 2004-09-25 19:05:14Z pmjones $
|
||||
*
|
||||
* @author Jeremy Cowgar <jeremy@cowgar.com>
|
||||
*
|
||||
* @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";
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
33
database/php/pear/Text/Wiki/Render/Latex/Anchor.php
Normal file
33
database/php/pear/Text/Wiki/Render/Latex/Anchor.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
*
|
||||
* This class renders an anchor target name in LaTeX.
|
||||
*
|
||||
* $Id: Anchor.php 169211 2004-09-25 19:05:14Z pmjones $
|
||||
*
|
||||
* @author Jeremy Cowgar <jeremy@cowgar.com>
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Render_Latex_Anchor extends Text_Wiki_Render {
|
||||
|
||||
function token($options)
|
||||
{
|
||||
extract($options); // $type, $name
|
||||
|
||||
if ($type == 'start') {
|
||||
//return sprintf('<a id="%s">',$name);
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($type == 'end') {
|
||||
//return '</a>';
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
36
database/php/pear/Text/Wiki/Render/Latex/Blockquote.php
Normal file
36
database/php/pear/Text/Wiki/Render/Latex/Blockquote.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Blockquote 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)
|
||||
{
|
||||
$type = $options['type'];
|
||||
$level = $options['level'];
|
||||
|
||||
// starting
|
||||
if ($type == 'start') {
|
||||
return "\\begin{quote}\n";
|
||||
}
|
||||
|
||||
// ending
|
||||
if ($type == 'end') {
|
||||
return "\\end{quote}\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
28
database/php/pear/Text/Wiki/Render/Latex/Bold.php
Normal file
28
database/php/pear/Text/Wiki/Render/Latex/Bold.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
class Text_Wiki_Render_Latex_Bold 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\textbf{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
54
database/php/pear/Text/Wiki/Render/Latex/Box.php
Normal file
54
database/php/pear/Text/Wiki/Render/Latex/Box.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Box rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Box.php 193489 2005-08-15 09:50:57Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders a box drawn in Latex.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_Box 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\framebox[\textwidth]{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return "}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
24
database/php/pear/Text/Wiki/Render/Latex/Break.php
Normal file
24
database/php/pear/Text/Wiki/Render/Latex/Break.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Break 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 "\\newline\n";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
33
database/php/pear/Text/Wiki/Render/Latex/Center.php
Normal file
33
database/php/pear/Text/Wiki/Render/Latex/Center.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Center 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 'Center: NI';
|
||||
|
||||
if ($options['type'] == 'start') {
|
||||
//return "\n<center>\n";
|
||||
return '<div style="text-align: center;">';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
//return "</center>\n";
|
||||
return '</div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
26
database/php/pear/Text/Wiki/Render/Latex/Code.php
Normal file
26
database/php/pear/Text/Wiki/Render/Latex/Code.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Code 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 = $options['text'];
|
||||
|
||||
return "\\begin{verbatim}\n$text\n\\end{verbatim}\n\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
58
database/php/pear/Text/Wiki/Render/Latex/Colortext.php
Normal file
58
database/php/pear/Text/Wiki/Render/Latex/Colortext.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Colortext extends Text_Wiki_Render {
|
||||
|
||||
var $colors = array(
|
||||
'aqua',
|
||||
'black',
|
||||
'blue',
|
||||
'fuchsia',
|
||||
'gray',
|
||||
'green',
|
||||
'lime',
|
||||
'maroon',
|
||||
'navy',
|
||||
'olive',
|
||||
'purple',
|
||||
'red',
|
||||
'silver',
|
||||
'teal',
|
||||
'white',
|
||||
'yellow'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 'Colortext: NI';
|
||||
|
||||
$type = $options['type'];
|
||||
$color = $options['color'];
|
||||
|
||||
if (! in_array($color, $this->colors)) {
|
||||
$color = '#' . $color;
|
||||
}
|
||||
|
||||
if ($type == 'start') {
|
||||
return "<span style=\"color: $color;\">";
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '</span>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
53
database/php/pear/Text/Wiki/Render/Latex/Deflist.php
Normal file
53
database/php/pear/Text/Wiki/Render/Latex/Deflist.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Deflist extends Text_Wiki_Render {
|
||||
|
||||
var $conf = array(
|
||||
'css_dl' => null,
|
||||
'css_dt' => null,
|
||||
'css_dd' => 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)
|
||||
{
|
||||
$type = $options['type'];
|
||||
switch ($type)
|
||||
{
|
||||
case 'list_start':
|
||||
return "\\begin{description}\n";
|
||||
|
||||
case 'list_end':
|
||||
return "\\end{description}\n\n";
|
||||
|
||||
case 'term_start':
|
||||
return '\item[';
|
||||
|
||||
case 'term_end':
|
||||
return '] ';
|
||||
|
||||
case 'narr_start':
|
||||
return '{';
|
||||
|
||||
case 'narr_end':
|
||||
return "}\n";
|
||||
|
||||
default:
|
||||
return '';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
25
database/php/pear/Text/Wiki/Render/Latex/Delimiter.php
Normal file
25
database/php/pear/Text/Wiki/Render/Latex/Delimiter.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Delimiter 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)
|
||||
{
|
||||
// TODO: Is this where I can do some LaTeX escaping for items
|
||||
// such as $ { } _ ?
|
||||
return "Delimiter: ".$options['text'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
23
database/php/pear/Text/Wiki/Render/Latex/Embed.php
Normal file
23
database/php/pear/Text/Wiki/Render/Latex/Embed.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Embed 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 "Embed: ".$options['text'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
29
database/php/pear/Text/Wiki/Render/Latex/Emphasis.php
Normal file
29
database/php/pear/Text/Wiki/Render/Latex/Emphasis.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Emphasis 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\textsl{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
73
database/php/pear/Text/Wiki/Render/Latex/Font.php
Normal file
73
database/php/pear/Text/Wiki/Render/Latex/Font.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* BBCode: extra Font rules renderer to size the text
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Font.php 209123 2006-03-11 11:14:23Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* Font rule render class (used for BBCode)
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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_Latex_Font extends Text_Wiki_Render {
|
||||
|
||||
/**
|
||||
* A table to translate the sizes
|
||||
*
|
||||
* @access public
|
||||
* @var array
|
||||
*/
|
||||
var $sizes = array(
|
||||
'tiny' => 5,
|
||||
'scriptsize' => 7,
|
||||
'footnotesize' => 8,
|
||||
'small' => 9,
|
||||
'normalsize' => 11,
|
||||
'large' => 13,
|
||||
'Large' => 16,
|
||||
'LARGE' => 19,
|
||||
'huge' => 22,
|
||||
'Huge' => 9999);
|
||||
|
||||
/**
|
||||
* Renders a token into text matching the requested format.
|
||||
* process the font size option
|
||||
*
|
||||
* @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') {
|
||||
foreach ($this->sizes as $key => $lim) {
|
||||
if ($options['size'] < $lim) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return '\{' . $key . '}{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
6
database/php/pear/Text/Wiki/Render/Latex/Freelink.php
Normal file
6
database/php/pear/Text/Wiki/Render/Latex/Freelink.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Freelink extends Text_Wiki_Render_Latex_Wikilink {
|
||||
// renders identically to wikilinks, only the parsing is different :-)
|
||||
}
|
||||
?>
|
||||
23
database/php/pear/Text/Wiki/Render/Latex/Function.php
Normal file
23
database/php/pear/Text/Wiki/Render/Latex/Function.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Function 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 "Function: NI";
|
||||
}
|
||||
}
|
||||
?>
|
||||
33
database/php/pear/Text/Wiki/Render/Latex/Heading.php
Normal file
33
database/php/pear/Text/Wiki/Render/Latex/Heading.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Heading extends Text_Wiki_Render {
|
||||
|
||||
function token($options)
|
||||
{
|
||||
// get nice variable names (type, level)
|
||||
extract($options);
|
||||
|
||||
if ($type == 'start') {
|
||||
switch ($level)
|
||||
{
|
||||
case '1':
|
||||
return '\part{';
|
||||
case '2':
|
||||
return '\section{';
|
||||
case '3':
|
||||
return '\subsection{';
|
||||
case '4':
|
||||
return '\subsubsection{';
|
||||
case '5':
|
||||
return '\paragraph{';
|
||||
case '6':
|
||||
return '\subparagraph{';
|
||||
}
|
||||
}
|
||||
|
||||
if ($type == 'end') {
|
||||
return "}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
23
database/php/pear/Text/Wiki/Render/Latex/Horiz.php
Normal file
23
database/php/pear/Text/Wiki/Render/Latex/Horiz.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Horiz 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 "\n\\noindent\\rule{\\textwidth}{1pt}\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
25
database/php/pear/Text/Wiki/Render/Latex/Html.php
Normal file
25
database/php/pear/Text/Wiki/Render/Latex/Html.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_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)
|
||||
{
|
||||
print_r($this);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
?>
|
||||
70
database/php/pear/Text/Wiki/Render/Latex/Image.php
Normal file
70
database/php/pear/Text/Wiki/Render/Latex/Image.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
class Text_Wiki_Render_Latex_Image extends Text_Wiki_Render {
|
||||
|
||||
var $conf = array(
|
||||
'base' => '/'
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 'Image: NI';
|
||||
|
||||
$src = '"' .
|
||||
$this->getConf('base', '/') .
|
||||
$options['src'] . '"';
|
||||
|
||||
if (isset($options['attr']['link'])) {
|
||||
|
||||
// this image has a link
|
||||
if (strpos($options['attr']['link'], '://')) {
|
||||
// it's a URL
|
||||
$href = $options['attr']['link'];
|
||||
} else {
|
||||
$href = $this->wiki->getRenderConf('xhtml', 'wikilink', 'view_url') .
|
||||
$options['attr']['link'];
|
||||
}
|
||||
|
||||
} else {
|
||||
// image is not linked
|
||||
$href = null;
|
||||
}
|
||||
|
||||
// unset these so they don't show up as attributes
|
||||
unset($options['attr']['link']);
|
||||
|
||||
$attr = '';
|
||||
$alt = false;
|
||||
foreach ($options['attr'] as $key => $val) {
|
||||
if (strtolower($key) == 'alt') {
|
||||
$alt = true;
|
||||
}
|
||||
$attr .= " $key=\"$val\"";
|
||||
}
|
||||
|
||||
// always add an "alt" attribute per Stephane Solliec
|
||||
if (! $alt) {
|
||||
$attr .= ' alt="' . basename($options['src']) . '"';
|
||||
}
|
||||
|
||||
if ($href) {
|
||||
return "<a href=\"$href\"><img src=$src$attr/></a>";
|
||||
} else {
|
||||
return "<img src=$src$attr/>";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
8
database/php/pear/Text/Wiki/Render/Latex/Include.php
Normal file
8
database/php/pear/Text/Wiki/Render/Latex/Include.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
class Text_Wiki_Render_Latex_Include extends Text_Wiki_Render {
|
||||
function token()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
?>
|
||||
58
database/php/pear/Text/Wiki/Render/Latex/Interwiki.php
Normal file
58
database/php/pear/Text/Wiki/Render/Latex/Interwiki.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_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'
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
return $text . '\footnote{' . $href . '}';
|
||||
}
|
||||
}
|
||||
?>
|
||||
28
database/php/pear/Text/Wiki/Render/Latex/Italic.php
Normal file
28
database/php/pear/Text/Wiki/Render/Latex/Italic.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
class Text_Wiki_Render_Latex_Italic 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\textit{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
76
database/php/pear/Text/Wiki/Render/Latex/List.php
Normal file
76
database/php/pear/Text/Wiki/Render/Latex/List.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
class Text_Wiki_Render_Latex_List extends Text_Wiki_Render {
|
||||
/**
|
||||
*
|
||||
* 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);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'bullet_list_start':
|
||||
return "\\begin{itemize}\n";
|
||||
|
||||
case 'bullet_list_end':
|
||||
return "\\end{itemize}\n";
|
||||
|
||||
case 'number_list_start':
|
||||
$depth = 'enumi' . str_pad('', $level, 'i');
|
||||
$enum = '\arabic';
|
||||
if (isset($format)) {
|
||||
switch ($format) {
|
||||
case 'a':
|
||||
$enum = '\alph';
|
||||
break;
|
||||
case 'A':
|
||||
$enum = '\Alph';
|
||||
break;
|
||||
case 'i':
|
||||
$enum = '\roman';
|
||||
break;
|
||||
case 'I':
|
||||
$enum = '\Roman';
|
||||
break;
|
||||
}
|
||||
}
|
||||
return '\renewcommand{\labelenumi}{' . $enum . '{' . $depth .
|
||||
"}}\n\\begin{enumerate}\n";
|
||||
|
||||
case 'number_list_end':
|
||||
return "\\end{enumerate}\n";
|
||||
|
||||
case 'bullet_item_start':
|
||||
case 'number_item_start':
|
||||
return '\item{';
|
||||
|
||||
case 'bullet_item_end':
|
||||
case 'number_item_end':
|
||||
return "}\n";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
database/php/pear/Text/Wiki/Render/Latex/Newline.php
Normal file
12
database/php/pear/Text/Wiki/Render/Latex/Newline.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Newline extends Text_Wiki_Render {
|
||||
|
||||
|
||||
function token($options)
|
||||
{
|
||||
return "\\newline\n";
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
48
database/php/pear/Text/Wiki/Render/Latex/Page.php
Normal file
48
database/php/pear/Text/Wiki/Render/Latex/Page.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Page rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Page.php 193514 2005-08-15 15:27:19Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders page markers in Latex.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_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 "\\newpage\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
31
database/php/pear/Text/Wiki/Render/Latex/Paragraph.php
Normal file
31
database/php/pear/Text/Wiki/Render/Latex/Paragraph.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Paragraph 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)
|
||||
{
|
||||
extract($options); //type
|
||||
|
||||
if ($type == 'start') {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($type == 'end') {
|
||||
return "\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
34
database/php/pear/Text/Wiki/Render/Latex/Phplookup.php
Normal file
34
database/php/pear/Text/Wiki/Render/Latex/Phplookup.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Phplookup extends Text_Wiki_Render {
|
||||
|
||||
var $conf = array('target' => '_blank');
|
||||
|
||||
/**
|
||||
*
|
||||
* 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 'Phplookup: NI';
|
||||
|
||||
$text = trim($options['text']);
|
||||
|
||||
$target = $this->getConf('target', '');
|
||||
if ($target) {
|
||||
$target = " target=\"$target\"";
|
||||
}
|
||||
|
||||
return "<a$target href=\"http://php.net/$text\">$text</a>";
|
||||
}
|
||||
}
|
||||
?>
|
||||
49
database/php/pear/Text/Wiki/Render/Latex/Plugin.php
Normal file
49
database/php/pear/Text/Wiki/Render/Latex/Plugin.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Plugin rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Plugin.php 193730 2005-08-17 09:16:36Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders wiki plugins in Latex. (empty)
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_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 '';
|
||||
}
|
||||
}
|
||||
?>
|
||||
56
database/php/pear/Text/Wiki/Render/Latex/Prefilter.php
Normal file
56
database/php/pear/Text/Wiki/Render/Latex/Prefilter.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Jeremy Cowgar <jeremy@cowgar.com>
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Prefilter.php 248435 2007-12-17 16:19:44Z justinpatrin $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2003 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Prefilter.php 248435 2007-12-17 16:19:44Z justinpatrin $
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* This class implements a Text_Wiki_Render_Latex 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.
|
||||
*
|
||||
* @author Jeremy Cowgar <jeremy@cowgar.com>
|
||||
*
|
||||
* @package Text_Wiki
|
||||
*
|
||||
*/
|
||||
|
||||
class Text_Wiki_Render_Latex_Prefilter extends Text_Wiki_Render {
|
||||
function token()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
?>
|
||||
48
database/php/pear/Text/Wiki/Render/Latex/Preformatted.php
Normal file
48
database/php/pear/Text/Wiki/Render/Latex/Preformatted.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Preformatted rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Preformatted.php 193477 2005-08-15 06:15:41Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders preformated text in Latex.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_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)
|
||||
{
|
||||
return "\\begin{verbatim}\n" . $options['text'] . "\n\\end{verbatim}\n";
|
||||
}
|
||||
}
|
||||
?>
|
||||
23
database/php/pear/Text/Wiki/Render/Latex/Raw.php
Normal file
23
database/php/pear/Text/Wiki/Render/Latex/Raw.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_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 "Raw: ".$options['text'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
38
database/php/pear/Text/Wiki/Render/Latex/Revise.php
Normal file
38
database/php/pear/Text/Wiki/Render/Latex/Revise.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Revise 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)
|
||||
{
|
||||
if ($options['type'] == 'del_start') {
|
||||
return '\sout{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'del_end') {
|
||||
return '}';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'ins_start') {
|
||||
return '\underline{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'ins_end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
44
database/php/pear/Text/Wiki/Render/Latex/Smiley.php
Normal file
44
database/php/pear/Text/Wiki/Render/Latex/Smiley.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Smiley rule Latex renderer
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Smiley.php 192951 2005-08-10 11:42:08Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smiley rule Latex render class
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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_Latex_Smiley extends Text_Wiki_Render {
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return $options['symbol'];
|
||||
}
|
||||
}
|
||||
?>
|
||||
54
database/php/pear/Text/Wiki/Render/Latex/Specialchar.php
Normal file
54
database/php/pear/Text/Wiki/Render/Latex/Specialchar.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Specialchar rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Specialchar.php 193499 2005-08-15 11:10:38Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders special characters in Latex.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_SpecialChar extends Text_Wiki_Render {
|
||||
|
||||
var $types = array('~bs~' => '\\\\',
|
||||
'~hs~' => '\hspace{1em}',
|
||||
'~amp~' => '\&',
|
||||
'~ldq~' => '``',
|
||||
'~rdq~' => "''",
|
||||
'~lsq~' => '`',
|
||||
'~rsq~' => "'",
|
||||
'~c~' => '\copyright',
|
||||
'~--~' => '---',
|
||||
'" -- "' => '---',
|
||||
'" -- "' => '---',
|
||||
'~lt~' => '<',
|
||||
'~gt~' => '>');
|
||||
|
||||
function token($options)
|
||||
{
|
||||
if (isset($this->types[$options['char']])) {
|
||||
return $this->types[$options['char']];
|
||||
} else {
|
||||
return $options['char'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
30
database/php/pear/Text/Wiki/Render/Latex/Strong.php
Normal file
30
database/php/pear/Text/Wiki/Render/Latex/Strong.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Strong 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\textbf{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
54
database/php/pear/Text/Wiki/Render/Latex/Subscript.php
Normal file
54
database/php/pear/Text/Wiki/Render/Latex/Subscript.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Subscript rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Subscript.php 193490 2005-08-15 10:09:06Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders subscript text in Latex.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_Subscript 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '_{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
31
database/php/pear/Text/Wiki/Render/Latex/Superscript.php
Normal file
31
database/php/pear/Text/Wiki/Render/Latex/Superscript.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Superscript 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 'Superscript: NI';
|
||||
|
||||
if ($options['type'] == 'start') {
|
||||
return '<sup>';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '</sup>';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
99
database/php/pear/Text/Wiki/Render/Latex/Table.php
Normal file
99
database/php/pear/Text/Wiki/Render/Latex/Table.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Table extends Text_Wiki_Render {
|
||||
var $cell_id = 0;
|
||||
var $cell_count = 0;
|
||||
var $is_spanning = false;
|
||||
|
||||
var $conf = array(
|
||||
'css_table' => 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)
|
||||
extract($options);
|
||||
|
||||
switch ($type)
|
||||
{
|
||||
case 'table_start':
|
||||
$this->cell_count = $cols;
|
||||
|
||||
$tbl_start = '\begin{tabular}{|';
|
||||
for ($a=0; $a < $this->cell_count; $a++) {
|
||||
$tbl_start .= 'l|';
|
||||
}
|
||||
$tbl_start .= "}\n";
|
||||
|
||||
return $tbl_start;
|
||||
|
||||
case 'table_end':
|
||||
return "\\hline\n\\end{tabular}\n";
|
||||
|
||||
case 'caption_start':
|
||||
return "\\caption{";
|
||||
|
||||
case 'caption_end':
|
||||
return "}\n";
|
||||
|
||||
case 'row_start':
|
||||
$this->is_spanning = false;
|
||||
$this->cell_id = 0;
|
||||
return "\\hline\n";
|
||||
|
||||
case 'row_end':
|
||||
return "\\\\\n";
|
||||
|
||||
case 'cell_start':
|
||||
if ($span > 1) {
|
||||
$col_spec = '';
|
||||
if ($this->cell_id == 0) {
|
||||
$col_spec = '|';
|
||||
}
|
||||
$col_spec .= 'l|';
|
||||
|
||||
$this->cell_id += $span;
|
||||
$this->is_spanning = true;
|
||||
|
||||
return '\multicolumn{' . $span . '}{' . $col_spec . '}{';
|
||||
}
|
||||
|
||||
$this->cell_id += 1;
|
||||
return '';
|
||||
|
||||
case 'cell_end':
|
||||
$out = '';
|
||||
if ($this->is_spanning) {
|
||||
$this->is_spanning = false;
|
||||
$out = '}';
|
||||
}
|
||||
|
||||
if ($this->cell_id != $this->cell_count) {
|
||||
$out .= ' & ';
|
||||
}
|
||||
|
||||
return $out;
|
||||
|
||||
default:
|
||||
return '';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
9
database/php/pear/Text/Wiki/Render/Latex/Tighten.php
Normal file
9
database/php/pear/Text/Wiki/Render/Latex/Tighten.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
class Text_Wiki_Render_Latex_Tighten extends Text_Wiki_Render {
|
||||
|
||||
function token()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
?>
|
||||
54
database/php/pear/Text/Wiki/Render/Latex/Titlebar.php
Normal file
54
database/php/pear/Text/Wiki/Render/Latex/Titlebar.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4:
|
||||
/**
|
||||
* Titlebar rule end renderer for Latex
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @copyright 2005 bertrand Gugger
|
||||
* @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1
|
||||
* @version CVS: $Id: Titlebar.php 193500 2005-08-15 11:36:55Z toggg $
|
||||
* @link http://pear.php.net/package/Text_Wiki
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class renders a title bar in Latex.
|
||||
*
|
||||
* @category Text
|
||||
* @package Text_Wiki
|
||||
* @author Bertrand Gugger <bertrand@toggg.com>
|
||||
* @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
|
||||
*/
|
||||
class Text_Wiki_Render_Latex_Titlebar 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\framebox[\textwidth]{\textbf{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return "}}\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
30
database/php/pear/Text/Wiki/Render/Latex/Toc.php
Normal file
30
database/php/pear/Text/Wiki/Render/Latex/Toc.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Toc 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)
|
||||
{
|
||||
if($options['type'] == 'list_start') {
|
||||
return "\\tableofcontents\n\n";
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
30
database/php/pear/Text/Wiki/Render/Latex/Tt.php
Normal file
30
database/php/pear/Text/Wiki/Render/Latex/Tt.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_tt 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\texttt{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
30
database/php/pear/Text/Wiki/Render/Latex/Underline.php
Normal file
30
database/php/pear/Text/Wiki/Render/Latex/Underline.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class Text_Wiki_Render_Latex_Underline 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)
|
||||
{
|
||||
if ($options['type'] == 'start') {
|
||||
return '\underline{';
|
||||
}
|
||||
|
||||
if ($options['type'] == 'end') {
|
||||
return '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user