mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-06 06:07:26 +02:00
PSR-2 reformatting PHPDoc corrections
With minor corrections. Signed-off-by: Marcus Bointon <marcus@synchromedia.co.uk> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
committed by
Edward Z. Yang
parent
19eee14899
commit
fac747bdbd
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
class HTML5 {
|
||||
class HTML5
|
||||
{
|
||||
private $data;
|
||||
private $char;
|
||||
private $EOF;
|
||||
@@ -63,7 +64,8 @@ class HTML5 {
|
||||
const CHARACTR = 4;
|
||||
const EOF = 5;
|
||||
|
||||
public function __construct($data) {
|
||||
public function __construct($data)
|
||||
{
|
||||
$data = str_replace("\r\n", "\n", $data);
|
||||
$date = str_replace("\r", null, $data);
|
||||
|
||||
@@ -80,17 +82,20 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
public function save()
|
||||
{
|
||||
return $this->tree->save();
|
||||
}
|
||||
|
||||
private function char() {
|
||||
private function char()
|
||||
{
|
||||
return ($this->char < $this->EOF)
|
||||
? $this->data[$this->char]
|
||||
: false;
|
||||
}
|
||||
|
||||
private function character($s, $l = 0) {
|
||||
private function character($s, $l = 0)
|
||||
{
|
||||
if($s + $l < $this->EOF) {
|
||||
if($l === 0) {
|
||||
return $this->data[$s];
|
||||
@@ -100,11 +105,13 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function characters($char_class, $start) {
|
||||
private function characters($char_class, $start)
|
||||
{
|
||||
return preg_replace('#^(['.$char_class.']+).*#s', '\\1', substr($this->data, $start));
|
||||
}
|
||||
|
||||
private function dataState() {
|
||||
private function dataState()
|
||||
{
|
||||
// Consume the next input character
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -204,7 +211,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function entityDataState() {
|
||||
private function entityDataState()
|
||||
{
|
||||
// Attempt to consume an entity.
|
||||
$entity = $this->entity();
|
||||
|
||||
@@ -217,7 +225,8 @@ class HTML5 {
|
||||
$this->state = 'data';
|
||||
}
|
||||
|
||||
private function tagOpenState() {
|
||||
private function tagOpenState()
|
||||
{
|
||||
switch($this->content_model) {
|
||||
case self::RCDATA:
|
||||
case self::CDATA:
|
||||
@@ -302,7 +311,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function closeTagOpenState() {
|
||||
private function closeTagOpenState()
|
||||
{
|
||||
$next_node = strtolower($this->characters('A-Za-z', $this->char + 1));
|
||||
$the_same = count($this->tree->stack) > 0 && $next_node === end($this->tree->stack)->nodeName;
|
||||
|
||||
@@ -375,7 +385,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function tagNameState() {
|
||||
private function tagNameState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -419,7 +430,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function beforeAttributeNameState() {
|
||||
private function beforeAttributeNameState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -468,7 +480,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function attributeNameState() {
|
||||
private function attributeNameState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -519,7 +532,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function afterAttributeNameState() {
|
||||
private function afterAttributeNameState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -573,7 +587,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function beforeAttributeValueState() {
|
||||
private function beforeAttributeValueState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -621,7 +636,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function attributeValueDoubleQuotedState() {
|
||||
private function attributeValueDoubleQuotedState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -656,7 +672,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function attributeValueSingleQuotedState() {
|
||||
private function attributeValueSingleQuotedState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -691,7 +708,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function attributeValueUnquotedState() {
|
||||
private function attributeValueUnquotedState()
|
||||
{
|
||||
// Consume the next input character:
|
||||
$this->char++;
|
||||
$char = $this->character($this->char);
|
||||
@@ -727,7 +745,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function entityInAttributeValueState() {
|
||||
private function entityInAttributeValueState()
|
||||
{
|
||||
// Attempt to consume an entity.
|
||||
$entity = $this->entity();
|
||||
|
||||
@@ -741,7 +760,8 @@ class HTML5 {
|
||||
$this->emitToken($char);
|
||||
}
|
||||
|
||||
private function bogusCommentState() {
|
||||
private function bogusCommentState()
|
||||
{
|
||||
/* Consume every character up to the first U+003E GREATER-THAN SIGN
|
||||
character (>) or the end of the file (EOF), whichever comes first. Emit
|
||||
a comment token whose data is the concatenation of all the characters
|
||||
@@ -767,7 +787,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function markupDeclarationOpenState() {
|
||||
private function markupDeclarationOpenState()
|
||||
{
|
||||
/* If the next two characters are both U+002D HYPHEN-MINUS (-)
|
||||
characters, consume those two characters, create a comment token whose
|
||||
data is the empty string, and switch to the comment state. */
|
||||
@@ -795,7 +816,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function commentState() {
|
||||
private function commentState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -821,7 +843,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function commentDashState() {
|
||||
private function commentDashState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -848,7 +871,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function commentEndState() {
|
||||
private function commentEndState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -871,7 +895,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function doctypeState() {
|
||||
private function doctypeState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -885,7 +910,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function beforeDoctypeNameState() {
|
||||
private function beforeDoctypeNameState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -932,7 +958,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function doctypeNameState() {
|
||||
private function doctypeNameState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -961,7 +988,8 @@ class HTML5 {
|
||||
: true;
|
||||
}
|
||||
|
||||
private function afterDoctypeNameState() {
|
||||
private function afterDoctypeNameState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -984,7 +1012,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function bogusDoctypeState() {
|
||||
private function bogusDoctypeState()
|
||||
{
|
||||
/* Consume the next input character: */
|
||||
$this->char++;
|
||||
$char = $this->char();
|
||||
@@ -1003,14 +1032,15 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function entity() {
|
||||
private function entity()
|
||||
{
|
||||
$start = $this->char;
|
||||
|
||||
// This section defines how to consume an entity. This definition is
|
||||
// used when parsing entities in text and in attributes.
|
||||
|
||||
// The behaviour depends on the identity of the next character (the
|
||||
// one immediately after the U+0026 AMPERSAND character):
|
||||
// one immediately after the U+0026 AMPERSAND character):
|
||||
|
||||
switch($this->character($this->char + 1)) {
|
||||
// U+0023 NUMBER SIGN (#)
|
||||
@@ -1088,7 +1118,8 @@ class HTML5 {
|
||||
return html_entity_decode('&'.$entity.';', ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
private function emitToken($token) {
|
||||
private function emitToken($token)
|
||||
{
|
||||
$emit = $this->tree->emitToken($token);
|
||||
|
||||
if(is_int($emit)) {
|
||||
@@ -1099,7 +1130,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
private function EOF() {
|
||||
private function EOF()
|
||||
{
|
||||
$this->state = null;
|
||||
$this->tree->emitToken(array(
|
||||
'type' => self::EOF
|
||||
@@ -1107,7 +1139,8 @@ class HTML5 {
|
||||
}
|
||||
}
|
||||
|
||||
class HTML5TreeConstructer {
|
||||
class HTML5TreeConstructer
|
||||
{
|
||||
public $stack = array();
|
||||
|
||||
private $phase;
|
||||
@@ -1159,7 +1192,8 @@ class HTML5TreeConstructer {
|
||||
|
||||
const MARKER = 0;
|
||||
|
||||
public function __construct() {
|
||||
public function __construct()
|
||||
{
|
||||
$this->phase = self::INIT_PHASE;
|
||||
$this->mode = self::BEFOR_HEAD;
|
||||
$this->dom = new DOMDocument;
|
||||
@@ -1171,7 +1205,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
|
||||
// Process tag tokens
|
||||
public function emitToken($token) {
|
||||
public function emitToken($token)
|
||||
{
|
||||
switch($this->phase) {
|
||||
case self::INIT_PHASE: return $this->initPhase($token); break;
|
||||
case self::ROOT_PHASE: return $this->rootElementPhase($token); break;
|
||||
@@ -1180,7 +1215,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function initPhase($token) {
|
||||
private function initPhase($token)
|
||||
{
|
||||
/* Initially, the tree construction stage must handle each token
|
||||
emitted from the tokenisation stage as follows: */
|
||||
|
||||
@@ -1230,7 +1266,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function rootElementPhase($token) {
|
||||
private function rootElementPhase($token)
|
||||
{
|
||||
/* After the initial phase, as each token is emitted from the tokenisation
|
||||
stage, it must be processed as described in this section. */
|
||||
|
||||
@@ -1277,7 +1314,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function mainPhase($token) {
|
||||
private function mainPhase($token)
|
||||
{
|
||||
/* Tokens in the main phase must be handled as follows: */
|
||||
|
||||
/* A DOCTYPE token */
|
||||
@@ -1327,7 +1365,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function beforeHead($token) {
|
||||
private function beforeHead($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -1381,7 +1420,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inHead($token) {
|
||||
private function inHead($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -1505,7 +1545,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function afterHead($token) {
|
||||
private function afterHead($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -1561,7 +1602,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inBody($token) {
|
||||
private function inBody($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
switch($token['type']) {
|
||||
@@ -2161,7 +2203,7 @@ class HTML5TreeConstructer {
|
||||
if($this->elementInScope($token['name'])) {
|
||||
$this->generateImpliedEndTags();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(end($this->stack)->nodeName !== $token['name']) {
|
||||
/* Now, if the current node is not an element with the
|
||||
@@ -2540,7 +2582,7 @@ class HTML5TreeConstructer {
|
||||
for($x = count($this->stack) - $n; $x >= $n; $x--) {
|
||||
array_pop($this->stack);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
$category = $this->getElementCategory($node);
|
||||
|
||||
@@ -2559,7 +2601,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inTable($token) {
|
||||
private function inTable($token)
|
||||
{
|
||||
$clear = array('html', 'table');
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -2736,7 +2779,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inCaption($token) {
|
||||
private function inCaption($token)
|
||||
{
|
||||
/* An end tag whose tag name is "caption" */
|
||||
if($token['type'] === HTML5::ENDTAG && $token['name'] === 'caption') {
|
||||
/* If the stack of open elements does not have an element in table
|
||||
@@ -2804,7 +2848,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inColumnGroup($token) {
|
||||
private function inColumnGroup($token)
|
||||
{
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
U+000A LINE FEED (LF), U+000B LINE TABULATION, U+000C FORM FEED (FF),
|
||||
or U+0020 SPACE */
|
||||
@@ -2861,7 +2906,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inTableBody($token) {
|
||||
private function inTableBody($token)
|
||||
{
|
||||
$clear = array('tbody', 'tfoot', 'thead', 'html');
|
||||
|
||||
/* A start tag whose tag name is "tr" */
|
||||
@@ -2947,7 +2993,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inRow($token) {
|
||||
private function inRow($token)
|
||||
{
|
||||
$clear = array('tr', 'html');
|
||||
|
||||
/* A start tag whose tag name is one of: "th", "td" */
|
||||
@@ -3032,7 +3079,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inCell($token) {
|
||||
private function inCell($token)
|
||||
{
|
||||
/* An end tag whose tag name is one of: "td", "th" */
|
||||
if($token['type'] === HTML5::ENDTAG &&
|
||||
($token['name'] === 'td' || $token['name'] === 'th')) {
|
||||
@@ -3139,7 +3187,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inSelect($token) {
|
||||
private function inSelect($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token */
|
||||
@@ -3288,7 +3337,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function afterBody($token) {
|
||||
private function afterBody($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -3327,7 +3377,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function inFrameset($token) {
|
||||
private function inFrameset($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -3390,7 +3441,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function afterFrameset($token) {
|
||||
private function afterFrameset($token)
|
||||
{
|
||||
/* Handle the token as follows: */
|
||||
|
||||
/* A character token that is one of one of U+0009 CHARACTER TABULATION,
|
||||
@@ -3425,7 +3477,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function trailingEndPhase($token) {
|
||||
private function trailingEndPhase($token)
|
||||
{
|
||||
/* After the main phase, as each token is emitted from the tokenisation
|
||||
stage, it must be processed as described in this section. */
|
||||
|
||||
@@ -3465,7 +3518,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function insertElement($token, $append = true) {
|
||||
private function insertElement($token, $append = true)
|
||||
{
|
||||
$el = $this->dom->createElement($token['name']);
|
||||
|
||||
foreach($token['attr'] as $attr) {
|
||||
@@ -3480,17 +3534,20 @@ class HTML5TreeConstructer {
|
||||
return $el;
|
||||
}
|
||||
|
||||
private function insertText($data) {
|
||||
private function insertText($data)
|
||||
{
|
||||
$text = $this->dom->createTextNode($data);
|
||||
$this->appendToRealParent($text);
|
||||
}
|
||||
|
||||
private function insertComment($data) {
|
||||
private function insertComment($data)
|
||||
{
|
||||
$comment = $this->dom->createComment($data);
|
||||
$this->appendToRealParent($comment);
|
||||
}
|
||||
|
||||
private function appendToRealParent($node) {
|
||||
private function appendToRealParent($node)
|
||||
{
|
||||
if($this->foster_parent === null) {
|
||||
end($this->stack)->appendChild($node);
|
||||
|
||||
@@ -3518,7 +3575,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function elementInScope($el, $table = false) {
|
||||
private function elementInScope($el, $table = false)
|
||||
{
|
||||
if(is_array($el)) {
|
||||
foreach($el as $element) {
|
||||
if($this->elementInScope($element, $table)) {
|
||||
@@ -3567,7 +3625,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function reconstructActiveFormattingElements() {
|
||||
private function reconstructActiveFormattingElements()
|
||||
{
|
||||
/* 1. If there are no entries in the list of active formatting elements,
|
||||
then there is nothing to reconstruct; stop this algorithm. */
|
||||
$formatting_elements = count($this->a_formatting);
|
||||
@@ -3638,7 +3697,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function clearTheActiveFormattingElementsUpToTheLastMarker() {
|
||||
private function clearTheActiveFormattingElementsUpToTheLastMarker()
|
||||
{
|
||||
/* When the steps below require the UA to clear the list of active
|
||||
formatting elements up to the last marker, the UA must perform the
|
||||
following steps: */
|
||||
@@ -3659,7 +3719,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function generateImpliedEndTags(array $exclude = array()) {
|
||||
private function generateImpliedEndTags(array $exclude = array())
|
||||
{
|
||||
/* When the steps below require the UA to generate implied end tags,
|
||||
then, if the current node is a dd element, a dt element, an li element,
|
||||
a p element, a td element, a th element, or a tr element, the UA must
|
||||
@@ -3673,7 +3734,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function getElementCategory($name) {
|
||||
private function getElementCategory($name)
|
||||
{
|
||||
if(in_array($name, $this->special))
|
||||
return self::SPECIAL;
|
||||
|
||||
@@ -3687,7 +3749,8 @@ class HTML5TreeConstructer {
|
||||
return self::PHRASING;
|
||||
}
|
||||
|
||||
private function clearStackToTableContext($elements) {
|
||||
private function clearStackToTableContext($elements)
|
||||
{
|
||||
/* When the steps above require the UA to clear the stack back to a
|
||||
table context, it means that the UA must, while the current node is not
|
||||
a table element or an html element, pop elements from the stack of open
|
||||
@@ -3704,7 +3767,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function resetInsertionMode() {
|
||||
private function resetInsertionMode()
|
||||
{
|
||||
/* 1. Let last be false. */
|
||||
$last = false;
|
||||
$leng = count($this->stack);
|
||||
@@ -3802,7 +3866,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
private function closeCell() {
|
||||
private function closeCell()
|
||||
{
|
||||
/* If the stack of open elements has a td or th element in table scope,
|
||||
then act as if an end tag token with that tag name had been seen. */
|
||||
foreach(array('td', 'th') as $cell) {
|
||||
@@ -3817,8 +3882,8 @@ class HTML5TreeConstructer {
|
||||
}
|
||||
}
|
||||
|
||||
public function save() {
|
||||
public function save()
|
||||
{
|
||||
return $this->dom;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
function assertCli() {
|
||||
function assertCli()
|
||||
{
|
||||
if (php_sapi_name() != 'cli' && !getenv('PHP_IS_CLI')) {
|
||||
echo 'Script cannot be called from web-browser (if you are indeed calling via cli,
|
||||
set environment variable PHP_IS_CLI to work around this).';
|
||||
@@ -8,11 +9,13 @@ set environment variable PHP_IS_CLI to work around this).';
|
||||
}
|
||||
}
|
||||
|
||||
function prefix_is($comp, $subject) {
|
||||
function prefix_is($comp, $subject)
|
||||
{
|
||||
return strncmp($comp, $subject, strlen($comp)) === 0;
|
||||
}
|
||||
|
||||
function postfix_is($comp, $subject) {
|
||||
function postfix_is($comp, $subject)
|
||||
{
|
||||
return strlen($subject) < $comp ? false : substr($subject, -strlen($comp)) === $comp;
|
||||
}
|
||||
|
||||
|
@@ -34,7 +34,8 @@ foreach ($raw_files as $file) {
|
||||
/**
|
||||
* Moves the $i cursor to the next non-whitespace token
|
||||
*/
|
||||
function consumeWhitespace($tokens, &$i) {
|
||||
function consumeWhitespace($tokens, &$i)
|
||||
{
|
||||
do {$i++;} while (is_array($tokens[$i]) && $tokens[$i][0] === T_WHITESPACE);
|
||||
}
|
||||
|
||||
@@ -45,7 +46,8 @@ function consumeWhitespace($tokens, &$i) {
|
||||
* - ($token, $expect_token, $expect_value): tests if token is $expect_token type, and
|
||||
* its string representation is $expect_value
|
||||
*/
|
||||
function testToken($token, $value_or_token, $value = null) {
|
||||
function testToken($token, $value_or_token, $value = null)
|
||||
{
|
||||
if (is_null($value)) {
|
||||
if (is_int($value_or_token)) return is_array($token) && $token[0] === $value_or_token;
|
||||
else return $token === $value_or_token;
|
||||
|
@@ -11,7 +11,8 @@ assertCli();
|
||||
* generated files are up-to-date.
|
||||
*/
|
||||
|
||||
function e($cmd) {
|
||||
function e($cmd)
|
||||
{
|
||||
echo "\$ $cmd\n";
|
||||
passthru($cmd, $status);
|
||||
echo "\n";
|
||||
|
@@ -21,10 +21,11 @@ $entity_dir = '../docs/entities/';
|
||||
$output_file = '../library/HTMLPurifier/EntityLookup/entities.ser';
|
||||
|
||||
// courtesy of a PHP manual comment
|
||||
function unichr($dec) {
|
||||
function unichr($dec)
|
||||
{
|
||||
if ($dec < 128) {
|
||||
$utf = chr($dec);
|
||||
} else if ($dec < 2048) {
|
||||
} elseif ($dec < 2048) {
|
||||
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
|
||||
$utf .= chr(128 + ($dec % 64));
|
||||
} else {
|
||||
|
@@ -61,12 +61,13 @@ echo "done!\n";
|
||||
*
|
||||
* @note This function expects that format $name extends $parent on one line
|
||||
*
|
||||
* @param $file
|
||||
* @param string $file
|
||||
* File to check dependencies of.
|
||||
* @return
|
||||
* @return array
|
||||
* Lookup array of files the file is dependent on, sorted accordingly.
|
||||
*/
|
||||
function get_dependency_lookup($file) {
|
||||
function get_dependency_lookup($file)
|
||||
{
|
||||
static $cache = array();
|
||||
if (isset($cache[$file])) return $cache[$file];
|
||||
if (!file_exists($file)) {
|
||||
@@ -108,7 +109,8 @@ function get_dependency_lookup($file) {
|
||||
* @return
|
||||
* Sorted array ($files is not modified by reference!)
|
||||
*/
|
||||
function dep_sort($files) {
|
||||
function dep_sort($files)
|
||||
{
|
||||
$ret = array();
|
||||
$cache = array();
|
||||
foreach ($files as $file) {
|
||||
|
@@ -24,14 +24,16 @@ $GLOBALS['loaded'] = array();
|
||||
*/
|
||||
class MergeLibraryFSTools extends FSTools
|
||||
{
|
||||
function copyable($entry) {
|
||||
public function copyable($entry)
|
||||
{
|
||||
// Skip hidden files
|
||||
if ($entry[0] == '.') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function copy($source, $dest) {
|
||||
public function copy($source, $dest)
|
||||
{
|
||||
copy_and_remove_includes($source, $dest);
|
||||
}
|
||||
}
|
||||
@@ -42,7 +44,8 @@ $FS = new MergeLibraryFSTools();
|
||||
* source.
|
||||
* @param string $text PHP source code to replace includes from
|
||||
*/
|
||||
function replace_includes($text) {
|
||||
function replace_includes($text)
|
||||
{
|
||||
// also remove vim modelines
|
||||
return preg_replace_callback(
|
||||
"/require(?:_once)? ['\"]([^'\"]+)['\"];/",
|
||||
@@ -57,7 +60,8 @@ function replace_includes($text) {
|
||||
* @note This is safe for files that have internal <?php
|
||||
* @param string $text Text to have leading PHP tag from
|
||||
*/
|
||||
function remove_php_tags($text) {
|
||||
function remove_php_tags($text)
|
||||
{
|
||||
$text = preg_replace('#// vim:.+#', '', $text);
|
||||
return substr($text, 5);
|
||||
}
|
||||
@@ -66,7 +70,8 @@ function remove_php_tags($text) {
|
||||
* Copies the contents of a directory to the standalone directory
|
||||
* @param string $dir Directory to copy
|
||||
*/
|
||||
function make_dir_standalone($dir) {
|
||||
function make_dir_standalone($dir)
|
||||
{
|
||||
global $FS;
|
||||
return $FS->copyr($dir, 'standalone/' . $dir);
|
||||
}
|
||||
@@ -75,7 +80,8 @@ function make_dir_standalone($dir) {
|
||||
* Copies the contents of a file to the standalone directory
|
||||
* @param string $file File to copy
|
||||
*/
|
||||
function make_file_standalone($file) {
|
||||
function make_file_standalone($file)
|
||||
{
|
||||
global $FS;
|
||||
$FS->mkdirr('standalone/' . dirname($file));
|
||||
copy_and_remove_includes($file, 'standalone/' . $file);
|
||||
@@ -88,7 +94,8 @@ function make_file_standalone($file) {
|
||||
* @param string $file Original file
|
||||
* @param string $sfile New location of file
|
||||
*/
|
||||
function copy_and_remove_includes($file, $sfile) {
|
||||
function copy_and_remove_includes($file, $sfile)
|
||||
{
|
||||
$contents = file_get_contents($file);
|
||||
if (strrchr($file, '.') === '.php') $contents = replace_includes($contents);
|
||||
return file_put_contents($sfile, $contents);
|
||||
@@ -98,7 +105,8 @@ function copy_and_remove_includes($file, $sfile) {
|
||||
* @param $matches preg_replace_callback matches array, where index 1
|
||||
* is the filename to include
|
||||
*/
|
||||
function replace_includes_callback($matches) {
|
||||
function replace_includes_callback($matches)
|
||||
{
|
||||
$file = $matches[1];
|
||||
$preserve = array(
|
||||
// PEAR (external)
|
||||
|
@@ -29,7 +29,8 @@ require_once 'HTMLPurifier/Filter/ExtractStyleBlocks.php';
|
||||
/**
|
||||
* Takes a hash and saves its contents to library/HTMLPurifier/ConfigSchema/
|
||||
*/
|
||||
function saveHash($hash) {
|
||||
function saveHash($hash)
|
||||
{
|
||||
if ($hash === false) return;
|
||||
$dir = realpath(dirname(__FILE__) . '/../library/HTMLPurifier/ConfigSchema');
|
||||
$name = $hash['ID'] . '.txt';
|
||||
|
@@ -39,7 +39,8 @@ class XmlRpc_Freshmeat
|
||||
* @param $username Username to login with
|
||||
* @param $password Password to login with
|
||||
*/
|
||||
public function __construct($username = null, $password = null) {
|
||||
public function __construct($username = null, $password = null)
|
||||
{
|
||||
if ($username && $password) {
|
||||
$this->login($username, $password);
|
||||
}
|
||||
@@ -48,7 +49,8 @@ class XmlRpc_Freshmeat
|
||||
/**
|
||||
* Performs a raw XML RPC call to self::URL
|
||||
*/
|
||||
protected function call($method, $params) {
|
||||
protected function call($method, $params)
|
||||
{
|
||||
$request = xmlrpc_encode_request($method, $params, $this->encodeOptions);
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, self::URL);
|
||||
@@ -73,7 +75,8 @@ class XmlRpc_Freshmeat
|
||||
* @param $name Name of method to call, can be methodName or method_name
|
||||
* @param $args Arguments of call, in form array('key1', 'val1', 'key2' ...)
|
||||
*/
|
||||
public function __call($name, $args) {
|
||||
public function __call($name, $args)
|
||||
{
|
||||
$method = $this->camelToUnderscore($name);
|
||||
$params = array();
|
||||
if ($this->sid) $params['SID'] = $this->sid;
|
||||
@@ -102,7 +105,8 @@ class XmlRpc_Freshmeat
|
||||
/**
|
||||
* Munge methodName to method_name
|
||||
*/
|
||||
private function camelToUnderscore($name) {
|
||||
private function camelToUnderscore($name)
|
||||
{
|
||||
$method = '';
|
||||
for ($i = 0, $c = strlen($name); $i < $c; $i++) {
|
||||
$v = $name[$i];
|
||||
@@ -115,7 +119,8 @@ class XmlRpc_Freshmeat
|
||||
/**
|
||||
* Automatically logout at end of scope
|
||||
*/
|
||||
public function __destruct() {
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->sid) $this->logout();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user