Skip to content
This repository has been archived by the owner on Sep 24, 2022. It is now read-only.

Use codesniffer to autoformat PHP files #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 60 additions & 72 deletions Text/Wiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Text_Wiki
*/
class Text_Wiki {
class Text_Wiki
{

/**
*
Expand All @@ -41,7 +42,7 @@ class Text_Wiki {
*/

public $rules = array(
'Include',
'Include',
'Prefilter',
'Delimiter',
// 'Moduledelimiter',
Expand All @@ -53,11 +54,11 @@ class Text_Wiki {
'Module',
'Module654',

'Iftags',
'Iftags',

'Comment',
'Iframe',
'Date',
'Date',
'Math',

'Concatlines',
Expand Down Expand Up @@ -335,17 +336,17 @@ class Text_Wiki {
'render' => array()
);

/**
* Storage for temporary variables.
*/
public $store = array();
/**
* Storage for temporary variables.
*/
public $store = array();

public $vars = array();
public $vars = array();

/**
* Stores format while processing the source.
*/
public $currentFormat;
/**
* Stores format while processing the source.
*/
public $currentFormat;

/**
*
Expand Down Expand Up @@ -384,7 +385,6 @@ function Text_Wiki($rules = null)
'render',
$this->fixPath(dirname(__FILE__)) . 'Wiki/Render/'
);

}

/**
Expand Down Expand Up @@ -545,7 +545,6 @@ function getRenderConf($format, $rule, $key = null)
// no
return null;
}

}

/**
Expand Down Expand Up @@ -685,7 +684,6 @@ function insertRule($name, $tgt = null)
}

return true;

}

/**
Expand Down Expand Up @@ -806,7 +804,7 @@ function disableRule($name)

function transform($text, $format = 'Xhtml')
{
$this->currentFormat = $format;
$this->currentFormat = $format;
$this->parse($text);
$out = $this->render($format);
$this->currentFormat = null;
Expand Down Expand Up @@ -840,7 +838,6 @@ function parse($text)
foreach ($this->rules as $name) {
// do not parse the rules listed in $disable
if (! in_array($name, $this->disable)) {

// load the parsing object
$this->loadParseObj($name);

Expand All @@ -850,7 +847,6 @@ function parse($text)
$this->parseObj[$name]->parse();
}
}

}
}

Expand Down Expand Up @@ -886,7 +882,7 @@ function render($format = 'Xhtml')
// load the format object, or crap out if we can't find it
$result = $this->loadFormatObj($format);
if ($this->isError($result)) {
return $result;
return $result;
}

// pre-rendering activity
Expand All @@ -902,33 +898,25 @@ function render($format = 'Xhtml')
// pass through the parsed source text character by character
$k = strlen($this->source);
for ($i = 0; $i < $k; $i++) {

// the current character
$char = $this->source[$i];

// are alredy in a delimited section?
if ($in_delim) {

// yes; are we ending the section?
if ($char == $this->delim) {

// yes, get the replacement text for the delimited
// token number and unset the flag.
$key = (int)$key;
$rule = $this->tokens[$key][0];
$opts = $this->tokens[$key][1];
$output .= $this->renderObj[$rule]->token($opts);
$in_delim = false;

} else {

// no, add to the dlimited token key number
$key .= $char;

}

} else {

// not currently in a delimited section.
// are we starting into a delimited section?
if ($char == $this->delim) {
Expand All @@ -948,18 +936,19 @@ function render($format = 'Xhtml')
$output .= $this->formatObj[$format]->post();
}

// this is a nasty hack... should be put somewhere else, e.g. Postfilter?
// this is a nasty hack... should be put somewhere else, e.g. Postfilter?

// fix TOC tags within entries
$d = utf8_encode("\xFC");
$output = preg_replace_callback("/$d$d(.*?)$d$d/s", array($this, 'strip'), $output);
// fix TOC tags within entries
$d = utf8_encode("\xFC");
$output = preg_replace_callback("/$d$d(.*?)$d$d/s", array($this, 'strip'), $output);

// return the rendered source text.
return $output;
}

public function strip($matches){
return strip_tags($matches[1]);
public function strip($matches)
{
return strip_tags($matches[1]);
}

/**
Expand Down Expand Up @@ -1107,20 +1096,19 @@ function loadParseObj($rule)

$loc = $this->findFile('parse', $file);

if ($loc) {
// found the class
include_once $loc;
} else {
// can't find the class
$this->parseObj[$rule] = null;
// can't find the class
return $this->error(
"Parse rule '$rule' not found"
);
}
if ($loc) {
// found the class
include_once $loc;
} else {
// can't find the class
$this->parseObj[$rule] = null;
// can't find the class
return $this->error(
"Parse rule '$rule' not found"
);
}

$this->parseObj[$rule] = new $class($this);

}

/**
Expand All @@ -1142,15 +1130,15 @@ function loadRenderObj($format, $rule)

// load the class
$loc = $this->findFile('render', $file);
if ($loc) {
// found the class
include_once $loc;
} else {
// can't find the class
return $this->error(
"Render rule '$rule' in format '$format' not found"
);
}
if ($loc) {
// found the class
include_once $loc;
} else {
// can't find the class
return $this->error(
"Render rule '$rule' in format '$format' not found"
);
}

$this->renderObj[$rule] = new $class($this);
}
Expand All @@ -1172,15 +1160,15 @@ function loadFormatObj($format)
$class = "Text_Wiki_Render_$format";

$loc = $this->findFile('render', $file);
if ($loc) {
// found the class
include_once $loc;
} else {
// can't find the class
return $this->error(
"Rendering format class '$class' not found"
);
}
if ($loc) {
// found the class
include_once $loc;
} else {
// can't find the class
return $this->error(
"Rendering format class '$class' not found"
);
}

$this->formatObj[$format] = new $class($this);
}
Expand Down Expand Up @@ -1281,7 +1269,7 @@ function fixPath($path)
$len = strlen($this->_dirSep);

if (! empty($path) &&
substr($path, -1 * $len, $len) != $this->_dirSep) {
substr($path, -1 * $len, $len) != $this->_dirSep) {
return $path . $this->_dirSep;
} else {
return $path;
Expand All @@ -1302,12 +1290,12 @@ function fixPath($path)

function &error($message)
{
throw new ProcessException($message);
// FIX?
if (! class_exists('PEAR_Error')) {
include_once 'PEAR.php';
}
return PEAR::throwError($message);
throw new ProcessException($message);
// FIX?
if (! class_exists('PEAR_Error')) {
include_once 'PEAR.php';
}
return PEAR::throwError($message);
}

/**
Expand All @@ -1324,6 +1312,6 @@ function &error($message)

function isError(&$obj)
{
return is_a($obj, 'PEAR_Error');
return is_a($obj, 'PEAR_Error');
}
}
10 changes: 3 additions & 7 deletions Text/Wiki/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Text_Wiki
*/
class Text_Wiki_Parse {
class Text_Wiki_Parse
{

/**
*
Expand Down Expand Up @@ -117,12 +118,10 @@ function Text_Wiki_Parse(&$obj)
// 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]
);

}
}

Expand All @@ -142,7 +141,7 @@ function Text_Wiki_Parse(&$obj)

function parse()
{
if($this->regex){
if ($this->regex) {
$this->wiki->source = preg_replace_callback(
$this->regex,
array(&$this, 'process'),
Expand Down Expand Up @@ -232,7 +231,6 @@ function getAttrs($text)

// loop through the sections
foreach ($tmp as $i => $val) {

// first element is always the first key
if ($i == 0) {
$key = trim($val);
Expand All @@ -245,10 +243,8 @@ function getAttrs($text)
$pos = strrpos($val, '"');
$attrs[$key] = stripslashes(substr($val, 0, $pos));
$key = trim(substr($val, $pos+1));

}

return $attrs;

}
}
16 changes: 10 additions & 6 deletions Text/Wiki/Parse/Default/Anchor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
*
*/

class Text_Wiki_Parse_Anchor extends Text_Wiki_Parse {
class Text_Wiki_Parse_Anchor extends Text_Wiki_Parse
{

/**
*
Expand All @@ -45,7 +46,7 @@ class Text_Wiki_Parse_Anchor extends Text_Wiki_Parse {
* @var string
*
*/
public $regex = '/' .
public $regex = '/' .
'(\[\[\#\s)' . # Two brackets, then hash
'([-_A-Za-z0-9.%]+?)' . # Contents of anchor
'(\]\])' . # Closing brackets
Expand All @@ -65,13 +66,16 @@ class Text_Wiki_Parse_Anchor extends Text_Wiki_Parse {
* the source text.
*
*/
function process(&$matches) {
function process(&$matches)
{

$name = $matches[2];

$start = $this->wiki->addToken($this->rule,
array(
'name' => $name));
$start = $this->wiki->addToken(
$this->rule,
array(
'name' => $name)
);

// done, place the script output directly in the source
return $start;
Expand Down
Loading