Optional parameter bug fixed. Deprecated curly braces syntax fixed. Thanks for reporting both, Matthias :)

This commit is contained in:
azett 2020-09-06 11:12:22 +02:00
parent e65bb9c549
commit 04900d4154
2 changed files with 580 additions and 491 deletions

View File

@ -383,7 +383,10 @@ function theme_def_feed_comments_link($str, $feed, $id) {
return BLOG_BASEURL . "?x=entry:$id;comments:1;feed:{$feed}";
}
function theme_comments_feed_link($feed = 'rss2', $id) {
function theme_comments_feed_link($feed, $id) {
if (empty($feed)) {
$feed = 'rss2';
}
return apply_filters('post_comments_feed_link', '', $feed, $id);
}

View File

@ -37,21 +37,25 @@
/**
* String parser mode: Search for the next character
*
* @see StringParser::_parserMode
*/
define('STRINGPARSER_MODE_SEARCH', 1);
/**
* String parser mode: Look at each character of the string
*
* @see StringParser::_parserMode
*/
define('STRINGPARSER_MODE_LOOP', 2);
/**
* Filter type: Prefilter
*
* @see StringParser::addFilter, StringParser::_prefilters
*/
define('STRINGPARSER_FILTER_PRE', 1);
/**
* Filter type: Postfilter
*
* @see StringParser::addFilter, StringParser::_postfilters
*/
define('STRINGPARSER_FILTER_POST', 2);
@ -64,6 +68,7 @@ define ('STRINGPARSER_FILTER_POST', 2);
* @package stringparser
*/
class StringParser {
/**
* String parser mode
*
@ -87,6 +92,7 @@ class StringParser {
/**
* Raw text
*
* @access protected
* @var string
*/
@ -94,6 +100,7 @@ class StringParser {
/**
* Parse stack
*
* @access protected
* @var array
*/
@ -101,6 +108,7 @@ class StringParser {
/**
* Current position in raw text
*
* @access protected
* @var integer
*/
@ -108,6 +116,7 @@ class StringParser {
/**
* Root node
*
* @access protected
* @var mixed
*/
@ -115,6 +124,7 @@ class StringParser {
/**
* Length of the text
*
* @access protected
* @var integer
*/
@ -143,6 +153,7 @@ class StringParser {
/**
* Characters or strings to look for
*
* @access protected
* @var array
*/
@ -168,6 +179,7 @@ class StringParser {
/**
* Current parser status
*
* @access protected
* @var int
*/
@ -175,6 +187,7 @@ class StringParser {
/**
* Prefilters
*
* @access protected
* @var array
*/
@ -182,6 +195,7 @@ class StringParser {
/**
* Postfilters
*
* @access protected
* @var array
*/
@ -189,6 +203,7 @@ class StringParser {
/**
* Recently reparsed?
*
* @access protected
* @var bool
*/
@ -209,8 +224,10 @@ class StringParser {
* Add a filter
*
* @access public
* @param int $type The type of the filter
* @param mixed $callback The callback to call
* @param int $type
* The type of the filter
* @param mixed $callback
* The callback to call
* @return bool
* @see STRINGPARSER_FILTER_PRE, STRINGPARSER_FILTER_POST
*/
@ -238,7 +255,8 @@ class StringParser {
* Remove all filters
*
* @access public
* @param int $type The type of the filter or 0 for all
* @param int $type
* The type of the filter or 0 for all
* @return bool
* @see STRINGPARSER_FILTER_PRE, STRINGPARSER_FILTER_POST
*/
@ -264,7 +282,8 @@ class StringParser {
* This function parses the text
*
* @access public
* @param string $text The text to parse
* @param string $text
* The text to parse
* @return mixed Either the root object of the tree if no output method
* is defined, the tree reoutput to e.g. a string or false
* if an internal error occured, such as a parse error if
@ -410,6 +429,7 @@ class StringParser {
/**
* Abstract method: Manipulate the tree
*
* @access protected
* @return bool
*/
@ -419,6 +439,7 @@ class StringParser {
/**
* Abstract method: Output tree
*
* @access protected
* @return bool
*/
@ -462,7 +483,7 @@ class StringParser {
// if yes, how should this be achieved? Another member of
// StringParser_Node?
$this->_setStatus(0);
$res = $this->_appendText ($this->_text{$topelem->occurredAt});
$res = $this->_appendText($this->_text [$topelem->occurredAt]);
if (!$res) {
return false;
}
@ -475,6 +496,7 @@ class StringParser {
/**
* Abstract method: Close remaining blocks
*
* @access protected
*/
function _closeRemainingBlocks() {
@ -497,6 +519,7 @@ class StringParser {
/**
* Abstract method: Initialize the parser
*
* @access protected
*/
function _parserInit() {
@ -505,6 +528,7 @@ class StringParser {
/**
* Abstract method: Set a specific status
*
* @access protected
*/
function _setStatus($status) {
@ -519,9 +543,12 @@ class StringParser {
/**
* Abstract method: Handle status
*
* @access protected
* @param int $status The current status
* @param string $needle The needle that was found
* @param int $status
* The current status
* @param string $needle
* The needle that was found
* @return bool
*/
function _handleStatus($status, $needle) {
@ -532,6 +559,7 @@ class StringParser {
/**
* Search mode loop
*
* @access protected
* @return bool
*/
@ -571,7 +599,7 @@ class StringParser {
return false;
}
if (!$res) {
$res = $this->_appendText ($this->_text{$this->_cpos});
$res = $this->_appendText($this->_text [$this->_cpos]);
if (!$res) {
return false;
}
@ -606,63 +634,64 @@ class StringParser {
function _loop() {
// HACK: This method ist not yet implemented correctly, the code below
// DOES NOT WORK! Do not use!
return false;
/*
while ($this->_cpos < $this->_length) {
$needle = $this->_strDetect ($this->_charactersSearch, $this->_cpos);
if ($needle === false) {
// not found => see if character is allowed
if (!in_array ($this->_text{$this->_cpos}, $this->_charactersAllowed)) {
if ($strict) {
return false;
}
// ignore
continue;
}
// lot's of FIXMES
$res = $this->_appendText ($this->_text{$this->_cpos});
if (!$res) {
return false;
}
}
// get subtext
$subtext = substr ($this->_text, $offset, $offset - $this->_cpos);
$res = $this->_appendText ($subtext);
if (!$res) {
return false;
}
$this->_cpos = $subtext;
$res = $this->_handleStatus ($this->_status, $needle);
if (!$res && $strict) {
return false;
}
}
// original status 0 => no problem
if (!$this->_status) {
return true;
}
// not in original status? strict mode?
if ($this->strict) {
return false;
}
// break up parsing operation of current node
$res = $this->_reparseAfterCurrentBlock ();
if (!$res) {
return false;
}
// this will not cause an infinite loop because
// _reparseAfterCurrentBlock will increase _cpos by one!
return $this->_loop ();
* while ($this->_cpos < $this->_length) {
* $needle = $this->_strDetect ($this->_charactersSearch, $this->_cpos);
*
* if ($needle === false) {
* // not found => see if character is allowed
* if (!in_array ($this->_text{$this->_cpos}, $this->_charactersAllowed)) {
* if ($strict) {
* return false;
* }
* // ignore
* continue;
* }
* // lot's of FIXMES
* $res = $this->_appendText ($this->_text{$this->_cpos});
* if (!$res) {
* return false;
* }
* }
*
* // get subtext
* $subtext = substr ($this->_text, $offset, $offset - $this->_cpos);
* $res = $this->_appendText ($subtext);
* if (!$res) {
* return false;
* }
* $this->_cpos = $subtext;
* $res = $this->_handleStatus ($this->_status, $needle);
* if (!$res && $strict) {
* return false;
* }
* }
* // original status 0 => no problem
* if (!$this->_status) {
* return true;
* }
* // not in original status? strict mode?
* if ($this->strict) {
* return false;
* }
* // break up parsing operation of current node
* $res = $this->_reparseAfterCurrentBlock ();
* if (!$res) {
* return false;
* }
* // this will not cause an infinite loop because
* // _reparseAfterCurrentBlock will increase _cpos by one!
* return $this->_loop ();
*/
}
/**
* Abstract method Append text depending on current status
*
* @access protected
* @param string $text The text to append
* @param string $text
* The text to append
* @return bool On success, the function returns true, else false
*/
function _appendText($text) {
@ -675,8 +704,10 @@ class StringParser {
/**
* Append text to last text child of current top parser stack node
*
* @access protected
* @param string $text The text to append
* @param string $text
* The text to append
* @return bool On success, the function returns true, else false
*/
function _appendToLastTextChild($text) {
@ -689,7 +720,8 @@ class StringParser {
/**
* Searches {@link StringParser::_text _text} for every needle that is
* specified by using the {@link PHP_MANUAL#strpos strpos} function. It
* specified by using the {@link PHP_MANUAL#strpos strpos} function.
* It
* returns an associative array with the key <code>'needle'</code>
* pointing at the string that was found first and the key
* <code>'offset'</code> pointing at the offset at which the string was
@ -717,15 +749,22 @@ class StringParser {
}
}
return array ($cur_needle, $cur_offset, 'needle' => $cur_needle, 'offset' => $cur_offset);
return array(
$cur_needle,
$cur_offset,
'needle' => $cur_needle,
'offset' => $cur_offset
);
}
/**
* Detects a string at the current position
*
* @access protected
* @param array $needles The strings that are to be detected
* @param int $offset The current offset
* @param array $needles
* The strings that are to be detected
* @param int $offset
* The current offset
* @return mixed The string that was detected or the needle
*/
function _strDetect($needles, $offset) {
@ -738,12 +777,12 @@ class StringParser {
return false;
}
/**
* Adds a node to the current parse stack
*
* @access protected
* @param object $node The node that is to be added
* @param object $node
* The node that is to be added
* @return bool True on success, else false.
* @see StringParser_Node, StringParser::_stack
*/
@ -783,7 +822,10 @@ class StringParser {
}
$method = array_shift($args);
$stack_count = count($this->_stack);
$method = array (&$this->_stack[$stack_count-1], $method);
$method = array(
&$this->_stack [$stack_count - 1],
$method
);
if (!is_callable($method)) {
return; // oops?
}
@ -800,29 +842,35 @@ class StringParser {
$stack_count = count($this->_stack);
return $this->_stack [$stack_count - 1]->$var;
}
}
/**
* Node type: Unknown node
*
* @see StringParser_Node::_type
*/
define('STRINGPARSER_NODE_UNKNOWN', 0);
/**
* Node type: Root node
*
* @see StringParser_Node::_type
*/
define('STRINGPARSER_NODE_ROOT', 1);
/**
* Node type: Text node
*
* @see StringParser_Node::_type
*/
define('STRINGPARSER_NODE_TEXT', 2);
/**
* Global value that is a counter of string parser node ids. Compare it to a
* Global value that is a counter of string parser node ids.
* Compare it to a
* sequence in databases.
*
* @var int
*/
$GLOBALS ['__STRINGPARSER_NODE_ID'] = 0;
@ -839,6 +887,7 @@ $GLOBALS['__STRINGPARSER_NODE_ID'] = 0;
* @package stringparser
*/
class StringParser_Node {
/**
* The type of this node.
*
@ -909,7 +958,8 @@ class StringParser_Node {
* assigns it.
*
* @access public
* @param int $occurredAt The position in the text where this node
* @param int $occurredAt
* The position in the text where this node
* occurred at. If not determinable, it is -1.
* @global __STRINGPARSER_NODE_ID
*/
@ -934,7 +984,8 @@ class StringParser_Node {
* Prepend a node
*
* @access public
* @param object $node The node to be prepended.
* @param object $node
* The node to be prepended.
* @return bool On success, the function returns true, else false.
*/
function prependChild(&$node) {
@ -975,8 +1026,10 @@ class StringParser_Node {
/**
* Append text to last text child
*
* @access public
* @param string $text The text to append
* @param string $text
* The text to append
* @return bool On success, the function returns true, else false
*/
function appendToLastTextChild($text) {
@ -998,7 +1051,8 @@ class StringParser_Node {
* property of the node that is to be appended.
*
* @access public
* @param object $node The node that is to be appended.
* @param object $node
* The node that is to be appended.
* @return bool On success, the function returns true, else false.
*/
function appendChild(&$node) {
@ -1032,8 +1086,10 @@ class StringParser_Node {
* Insert a node before another node
*
* @access public
* @param object $node The node to be inserted.
* @param object $reference The reference node where the new node is
* @param object $node
* The node to be inserted.
* @param object $reference
* The reference node where the new node is
* to be inserted before.
* @return bool On success, the function returns true, else false.
*/
@ -1084,8 +1140,10 @@ class StringParser_Node {
* Insert a node after another node
*
* @access public
* @param object $node The node to be inserted.
* @param object $reference The reference node where the new node is
* @param object $node
* The node to be inserted.
* @param object $reference
* The reference node where the new node is
* to be inserted after.
* @return bool On success, the function returns true, else false.
*/
@ -1141,10 +1199,12 @@ class StringParser_Node {
* return false.
*
* @access public
* @param mixed $child The child to destroy; either an integer
* @param mixed $child
* The child to destroy; either an integer
* specifying the index of the child or a reference
* to the child itself.
* @param bool $destroy Destroy the child afterwards.
* @param bool $destroy
* Destroy the child afterwards.
* @return bool On success, the function returns true, else false.
*/
function removeChild(&$child, $destroy = false) {
@ -1178,8 +1238,7 @@ class StringParser_Node {
}
// inkonsistency
if ($this->_children[$child]->_parent === null ||
$this->_children[$child]->_parent->_id != $this->_id) {
if ($this->_children [$child]->_parent === null || $this->_children [$child]->_parent->_id != $this->_id) {
return false;
}
@ -1187,7 +1246,8 @@ class StringParser_Node {
// as $object->_parent is a reference to $this!
// because of this, we have to unset the variable to remove
// the reference and then redeclare the variable
unset ($object->_parent); $object->_parent = null;
unset($object->_parent);
$object->_parent = null;
// we have to unset it because else it will be overridden in
// in the loop
@ -1248,7 +1308,8 @@ class StringParser_Node {
*
* @access public
* @static
* @param object $node The node to destroy
* @param object $node
* The node to destroy
* @return bool True on success, else false.
*/
static function destroyNode(&$node) {
@ -1304,7 +1365,8 @@ class StringParser_Node {
* node.
*
* @access protected
* @param mixed $child The node to look for.
* @param mixed $child
* The node to look for.
* @return mixed The index of the child node on success, else false.
*/
function _findChild(&$child) {
@ -1326,7 +1388,8 @@ class StringParser_Node {
* Checks equality of this node and another node
*
* @access public
* @param mixed $node The node to be compared with
* @param mixed $node
* The node to be compared with
* @return bool True if the other node equals to this node, else false.
*/
function equals(&$node) {
@ -1337,8 +1400,10 @@ class StringParser_Node {
* Determines whether a criterium matches this node
*
* @access public
* @param string $criterium The criterium that is to be checked
* @param mixed $value The value that is to be compared
* @param string $criterium
* The criterium that is to be checked
* @param mixed $value
* The value that is to be compared
* @return bool True if this node matches that criterium
*/
function matchesCriterium($criterium, $value) {
@ -1351,8 +1416,10 @@ class StringParser_Node {
* This may be used to implement getElementsByTagName etc.
*
* @access public
* @param string $criterium The criterium that is to be checked
* @param mixed $value The value that is to be compared
* @param string $criterium
* The criterium that is to be checked
* @param mixed $value
* The value that is to be compared
* @return array All subnodes that match this criterium
*/
function &getNodesByCriterium($criterium, $value) {
@ -1381,8 +1448,10 @@ class StringParser_Node {
* Similar to getNodesByCriterium
*
* @access public
* @param string $criterium The criterium that is to be checked
* @param mixed $value The value that is to be compared
* @param string $criterium
* The criterium that is to be checked
* @param mixed $value
* The value that is to be compared
* @return int The number of subnodes that match this criterium
*/
function getNodeCountByCriterium($criterium, $value) {
@ -1403,9 +1472,12 @@ class StringParser_Node {
* This dumps a tree of nodes
*
* @access public
* @param string $prefix The prefix that is to be used for indentation
* @param string $linesep The line separator
* @param int $level The initial level of indentation
* @param string $prefix
* The prefix that is to be used for indentation
* @param string $linesep
* The line separator
* @param int $level
* The initial level of indentation
* @return string
*/
function dump($prefix = " ", $linesep = "\n", $level = 0) {
@ -1428,6 +1500,7 @@ class StringParser_Node {
}
return (string) $this->_type;
}
}
/**
@ -1436,6 +1509,7 @@ class StringParser_Node {
* @package stringparser
*/
class StringParser_Node_Root extends StringParser_Node {
/**
* The type of this node.
*
@ -1446,6 +1520,7 @@ class StringParser_Node_Root extends StringParser_Node {
* @see STRINGPARSER_NODE_ROOT
*/
var $_type = STRINGPARSER_NODE_ROOT;
}
/**
@ -1454,6 +1529,7 @@ class StringParser_Node_Root extends StringParser_Node {
* @package stringparser
*/
class StringParser_Node_Text extends StringParser_Node {
/**
* The type of this node.
*
@ -1475,6 +1551,7 @@ class StringParser_Node_Text extends StringParser_Node {
/**
* The content of this node
*
* @access public
* @var string
*/
@ -1484,8 +1561,10 @@ class StringParser_Node_Text extends StringParser_Node {
* Constructor
*
* @access public
* @param string $content The initial content of this element
* @param int $occurredAt The position in the text where this node
* @param string $content
* The initial content of this element
* @param int $occurredAt
* The position in the text where this node
* occurred at. If not determinable, it is -1.
* @see StringParser_Node_Text::content
*/
@ -1498,7 +1577,8 @@ class StringParser_Node_Text extends StringParser_Node {
* Append text to content
*
* @access public
* @param string $text The text to append
* @param string $text
* The text to append
* @see StringParser_Node_Text::content
*/
function appendText($text) {
@ -1509,8 +1589,10 @@ class StringParser_Node_Text extends StringParser_Node {
* Set a flag
*
* @access public
* @param string $name The name of the flag
* @param mixed $value The value of the flag
* @param string $name
* The name of the flag
* @param mixed $value
* The value of the flag
*/
function setFlag($name, $value) {
$this->_flags [$name] = $value;
@ -1521,9 +1603,12 @@ class StringParser_Node_Text extends StringParser_Node {
* Get Flag
*
* @access public
* @param string $flag The requested flag
* @param string $type The requested type of the return value
* @param mixed $default The default return value
* @param string $flag
* The requested flag
* @param string $type
* The requested type of the return value
* @param mixed $default
* The default return value
*/
function getFlag($flag, $type = 'mixed', $default = null) {
if (!isset($this->_flags [$flag])) {
@ -1542,6 +1627,7 @@ class StringParser_Node_Text extends StringParser_Node {
function _dumpToString() {
return "text \"" . substr(preg_replace('/\s+/', ' ', $this->content), 0, 40) . "\" [f:" . preg_replace('/\s+/', ' ', join(':', array_keys($this->_flags))) . "]";
}
}
?>