Permalink
Browse files

Drop using getStaticProperty in favour of just configuring via the co…

…nstructor
  • Loading branch information...
1 parent 79d4e32 commit 74ae1dc3da34f67e2c932d3ab586a792293932d7 @CloCkWeRX CloCkWeRX committed Nov 3, 2012
@@ -34,23 +34,20 @@
*
*
* Usage:
-* $parser = new HTML_BBCodeParser2();
+* $parser = new HTML_BBCodeParser2($options = array(...));
* $parser->setText('normal [b]bold[/b] and normal again');
* $parser->parse();
* echo $parser->getParsed();
* or:
-* $parser = new HTML_BBCodeParser2();
+* $parser = new HTML_BBCodeParser2($options = array(...));
* echo $parser->qparse('normal [b]bold[/b] and normal again');
* or:
* echo HTML_BBCodeParser2::staticQparse('normal [b]bold[/b] and normal again');
*
*
* Setting the options from the ini file:
* $config = parse_ini_file('BBCodeParser.ini', true);
-* $options = &PEAR::getStaticProperty('HTML_BBCodeParser2', '_options');
* $options = $config['HTML_BBCodeParser2'];
-* unset($options);
-*
*
* The _definedTags variables should be in this format:
* array('tag' // the actual tag used
@@ -78,8 +75,6 @@
* => (...)
* )
*/
-require_once 'PEAR.php';
-
class HTML_BBCodeParser2
{
/**
@@ -148,13 +143,9 @@ class HTML_BBCodeParser2
/**
* Constructor, initialises the options and filters
*
- * Sets the private variable _options with base options defined with
- * &PEAR::getStaticProperty(), overwriting them with (if present)
- * the argument to this method.
- * Then it sets the extra options to properly escape the tag
- * characters in preg_replace() etc. The set options are
- * then stored back with &PEAR::getStaticProperty(), so that the filter
- * classes can use them.
+ * Sets options to properly escape the tag
+ * characters in preg_replace() etc.
+ *
* All the filters in the options are initialised and their defined tags
* are copied into the private variable _definedTags.
*
@@ -165,15 +156,6 @@ class HTML_BBCodeParser2
*/
function __construct($options = array())
{
- $pear=new PEAR();
- // set the already set options
- $baseoptions = $pear->getStaticProperty('HTML_BBCodeParser2', '_options');
- if (is_array($baseoptions)) {
- foreach ($baseoptions as $k => $v) {
- $this->_options[$k] = $v;
- }
- }
-
// set the options passed as an argument
foreach ($options as $k => $v ) {
$this->_options[$k] = $v;
@@ -230,7 +212,7 @@ function addFilter($filter)
$class = 'HTML_BBCodeParser2_Filter_'.$filter;
@include_once 'HTML/BBCodeParser2/Filter/'.$filter.'.php';
if (!class_exists($class)) {
- PEAR::raiseError("Failed to load filter $filter", null, PEAR_ERROR_DIE);
+ throw new InvalidArgumentException("Failed to load filter $filter");
}
$this->_filters[$filter] = new $class;
$this->_definedTags = array_merge(
@@ -66,8 +66,7 @@ class HTML_BBCodeParser2_Filter_Email extends HTML_BBCodeParser2_Filter
*/
function _preparse()
{
- $pear = new PEAR();
- $options = $pear->getStaticProperty('HTML_BBCodeParser2','_options');
+ $options = $this->_options;
$o = $options['open'];
$c = $options['close'];
$oe = $options['open_esc'];
@@ -66,7 +66,7 @@ class HTML_BBCodeParser2_Filter_Images extends HTML_BBCodeParser2_Filter
*/
function _preparse()
{
- $options = PEAR::getStaticProperty('HTML_BBCodeParser2','_options');
+ $options = $this->_options;
$o = $options['open'];
$c = $options['close'];
$oe = $options['open_esc'];
@@ -82,7 +82,7 @@ class HTML_BBCodeParser2_Filter_Links extends HTML_BBCodeParser2_Filter
*/
function _preparse()
{
- $options = PEAR::getStaticProperty('HTML_BBCodeParser2', '_options');
+ $options = $this->_options;
$o = $options['open'];
$c = $options['close'];
$oe = $options['open_esc'];
@@ -110,8 +110,7 @@ function _preparse()
*/
function smarterPPLinkExpand($matches)
{
- //echo '<hr><pre>';var_dump($matches);echo '</pre><hr>';
- $options = PEAR::getStaticProperty('HTML_BBCodeParser2','_options');
+ $options = $this->_options;
$o = $options['open'];
$c = $options['close'];
$oe = $options['open_esc'];
@@ -169,7 +168,7 @@ function smarterPPLinkExpand($matches)
*/
function smarterPPLink($matches)
{
- $options = PEAR::getStaticProperty('HTML_BBCodeParser2','_options');
+ $options = $this->_options;
$o = $options['open'];
$c = $options['close'];
@@ -78,7 +78,7 @@ class HTML_BBCodeParser2_Filter_Lists extends HTML_BBCodeParser2_Filter
*/
function _preparse()
{
- $options = PEAR::getStaticProperty('HTML_BBCodeParser2','_options');
+ $options = $this->_options;
$o = $options['open'];
$c = $options['close'];
$oe = $options['open_esc'];
@@ -102,4 +102,4 @@ function _preparse()
$this->_preparsed = preg_replace($pattern, $replace, $this->_text);
}
-}
+}
View
@@ -12,12 +12,10 @@
/* get options from the ini file */
$config = parse_ini_file('BBCodeParser2.ini', true);
-$options = PEAR::getStaticProperty('HTML_BBCodeParser2', '_options');
$options = $config['HTML_BBCodeParser2'];
-unset($options);
/* do yer stuff! */
-$parser = new HTML_BBCodeParser2();
+$parser = new HTML_BBCodeParser2($options);
$parser->setText(@$_GET['string']);
$parser->parse();
$parsed = $parser->getParsed();

0 comments on commit 74ae1dc

Please sign in to comment.