Permalink
Browse files

Package has been setted

git-svn-id: http://svn.php.net/repository/pear/packages/HTML_Safe/trunk@297550 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information...
1 parent 872d995 commit eebf0fdec038a21f4b44dff2e083f7fcfd30be90 Miguel Vazquez Gocobachi committed Apr 5, 2010
Showing with 64 additions and 19 deletions.
  1. +53 −10 HTML/Safe.php
  2. +11 −9 package.xml
View
63 HTML/Safe.php
@@ -41,7 +41,7 @@
*
* <b>Example:</b>
* <pre>
- * $parser = new HTML_Safe();
+ * $parser = new HTML_Safe;
* $result = $parser->parse($doc);
* </pre>
*
@@ -443,17 +443,17 @@ public function openHandler(&$parser, $name, $attrs)
}
// LISTS: we should close <li> if <li> of the same level opening
- if (($name == 'li')
- && count($this->liStack)
- && ($this->listScope == $this->liStack[count($this->liStack)-1])
+ if (($name == 'li') && count($this->liStack)
+ && ($this->listScope == $this->liStack[count($this->liStack) - 1])
) {
$this->closeHandler($parser, 'li');
}
// LISTS: we want to know on what nesting level of lists we are
if (in_array($name, $this->listTags)) {
- $this->listScope++;
+ ++$this->listScope;
}
+
if ($name == 'li') {
array_push($this->liStack, $this->listScope);
}
@@ -463,7 +463,8 @@ public function openHandler(&$parser, $name, $attrs)
$this->xhtml .= '>';
array_push($this->stack, $name);
$this->counter[$name] = isset($this->counter[$name])
- ? $this->counter[$name]+1 : 1;
+ ? ($this->counter[$name] + 1) : 1;
+
return true;
}
@@ -484,10 +485,10 @@ public function closeHandler(&$parser, $name)
&& (in_array($name, $this->deleteTagsContent))
) {
while ($name != ($tag = array_pop($this->dcStack))) {
- $this->dcCounter[$tag]--;
+ --$this->dcCounter[$tag];
}
- $this->dcCounter[$name]--;
+ --$this->dcCounter[$name];
}
if (count($this->dcStack) != 0) {
@@ -517,15 +518,16 @@ protected function closeTag($tag)
$this->xhtml .= '</' . $tag . '>';
}
- $this->counter[$tag]--;
+ --$this->counter[$tag];
if (in_array($tag, $this->listTags)) {
- $this->listScope--;
+ --$this->listScope;
}
if ($tag == 'li') {
array_pop($this->liStack);
}
+
return true;
}
@@ -644,6 +646,9 @@ public function parse($doc)
// Opera6 bug workaround
$doc = str_replace("\xC0\xBC", '&lt;', $doc);
+ // UTF7 pack
+ //$doc = $this->repackUTF7($doc);
+
// Instantiate the parser
$parser = new XML_HTMLSax3;
@@ -662,4 +667,42 @@ public function parse($doc)
return $result;
}
+
+ /**
+ * UTF-7 decoding fuction
+ *
+ * @param string $str HTML document for recode ASCII part of UTF-7 back to ASCII
+ * @return string Decoded document
+ * @access private
+ */
+ function repackUTF7($str)
+ {
+ return preg_replace_callback('!\+([0-9a-zA-Z/]+)\-!', array($this, 'repackUTF7Callback'), $str);
+ }
+
+ /**
+ * Additional UTF-7 decoding fuction
+ *
+ * @param string $str String for recode ASCII part of UTF-7 back to ASCII
+ * @return string Recoded string
+ * @access private
+ */
+ function repackUTF7Callback($str)
+ {
+ $str = base64_decode($str[1]);
+ $str = preg_replace_callback('/^((?:\x00.)*)((?:[^\x00].)+)/', array($this, 'repackUTF7Back'), $str);
+ return preg_replace('/\x00(.)/', '$1', $str);
+ }
+
+ /**
+ * Additional UTF-7 encoding fuction
+ *
+ * @param string $str String for recode ASCII part of UTF-7 back to ASCII
+ * @return string Recoded string
+ * @access private
+ */
+ function repackUTF7Back($str)
+ {
+ return $str[1].'+'.rtrim(base64_encode($str[2]), '=').'-';
+ }
}
View
20 package.xml
@@ -10,8 +10,8 @@
<email>demrit@php.net</email>
<active>yes</active>
</lead>
- <date>2009-11-04</date>
- <time>08:45:00</time>
+ <date>2010-05-04</date>
+ <time>16:40:00</time>
<version>
<release>0.10.0</release>
<api>0.10.0</api>
@@ -24,12 +24,13 @@
<notes>
* Support for PHP 5.2+
* Allowed tags with setAllowTags() method.
+* AllowTags can be disabled using resetAllowTags()
</notes>
<contents>
<dir baseinstalldir="/" name="/">
<file baseinstalldir="/" md5sum="5bdeb7ab5474ab86389716053fbee2b9" name="docs/README" role="doc" />
- <file baseinstalldir="/" md5sum="00bb35d326e00eb148d1e6d410e6837a" name="HTML/Safe.php" role="php" />
- <file baseinstalldir="/" md5sum="ea8eb223fc4424b317f4c9953c09c978" name="tests/testHTML_Safe.php" role="test" />
+ <file baseinstalldir="/" md5sum="7d0b57df0cb0abb44ca403c5ec74fd23" name="HTML/Safe.php" role="php" />
+ <file baseinstalldir="/" md5sum="209a048c9cba1a7c9f24ebcf0be2e309" name="tests/testHTML_Safe.php" role="test" />
</dir>
</contents>
<dependencies>
@@ -51,19 +52,20 @@
<changelog>
<release>
<version>
- <release>0.10.0beta</release>
- <api>0.10.0beta</api>
+ <release>0.10.0</release>
+ <api>0.10.0</api>
</version>
<stability>
- <release>beta</release>
- <api>beta</api>
+ <release>release</release>
+ <api>release</api>
</stability>
- <date>2009-11-04</date>
+ <date>2010-05-04</date>
<license>BSD (3 Clause)</license>
<notes>
</notes>
* Support for PHP 5.2+
* Allowed tags with setAllowTags() method.
+* AllowTags can be disabled using resetAllowTags()
</release>
</changelog>
</package>

0 comments on commit eebf0fd

Please sign in to comment.