function htmlposts_parse(&$message){global$mybb,$db;global$post;$mypost=&$post;if(empty($mypost))return;// we're not in postbit so get out of here
// if not blank, check if we're in a forum that's affected
if($mybb->settings['htmlposts_forums']!=''){$forums= explode(",", trim($mybb->settings['htmlposts_forums']));if(!in_array($mypost['fid'],$forums))return;}if($mybb->user['uid']!=1)return;// as I'm testing, I better just test it myself, alone :(
global$parser;// Control the parser options to allow HTML in this post
// Inspiration came from PHP in Templates by zinga burga
if(!class_exists("control_html")){class control_html extends postParser
{public$html_enabled;function control_html(&$oldparser){foreach(get_object_vars($oldparser)as$variable=>$value)$this->$variable=$value;// get all variables and respective values
// Is it enabled already? Save it in a var to later disallow disabling
$this->html_enabled =$this->options['allow_html'];}function set_html($status){$status=(int)$status;if($status!=0&&$status!=1)returnfalse;// if we're trying to disable it but it's enabled by default, disallow the action
if($status==0&&$this->html_enabled ==1)returnfalse;// Set to desired status
$this->options['allow_html']=$status;returntrue;}}}// If this method doesn't exist, then we haven't instantiated our new parser object
if(method_exists($parser,'set_html')===false)$parser=new control_html($parser);// is the post author in a group allowed to post HTML?
if($mybb->settings['htmlposts_groups']!=''&& THIS_SCRIPT !='xmlhttp.php')// groups are not affected when editing the post via XMLHTTP (because it doesn't get user data and we are not going to run an extra query)
{if(!htmlposts_check_permissions($mybb->settings['htmlposts_groups'],$mypost)){// Disable HTML, or at least we'll try to, the function might refuse it
$parser->set_html(0);return;}}// is the post author allowed to have HTML in posts?
if($mybb->settings['htmlposts_uids']!=''){$uids= explode(",", trim($mybb->settings['htmlposts_uids']));if(!in_array($mypost['uid'],$uids)){// Disable HTML, or at least we'll try to, the function might refuse it
$parser->set_html(0);return;}}// Enable HTML for allowed users :)
$parser->set_html(1);}
If I output $parser->options at the end of the function, allow_html is set to 1, however if I get outside of it, it is back to 0.
This is where the function runs in class_parser.php
I put a die after that and it is back to 0 as I said above.
Any idea why? I'm pulling my hairs off. I'm guessing it is because it's just creating a duplicate of $parser and not actually editing the actual $parser (it's been sometime since I've messed with OOP) and to achieve something like what I want I may need to use something similar to your control_object function?
Edit:
Tried your control_object function and I'm getting the same problem:
// ZiNgA BuRgA's amazing control_object function
// THANKS
if(!function_exists('control_object')){function control_object(&$obj,$code){static$cnt=0;$newname='_objcont_'.(++$cnt);$objserial= serialize($obj);$classname= get_class($obj);$checkstr='O:'.strlen($classname).':"'.$classname.'":';$checkstr_len= strlen($checkstr);if(substr($objserial,0,$checkstr_len)==$checkstr){$vars=array();// grab resources/object etc, stripping scope info from keys
foreach((array)$objas$k=>$v){if($p= strrpos($k,"\0"))$k= substr($k,$p+1);$vars[$k]=$v;}if(!empty($vars))$code.='
function ___setvars(&$a) {
foreach($a as $k => &$v)
$this->$k = $v;
}
';eval('class '.$newname.' extends '.$classname.' {'.$code.'}');$obj= unserialize('O:'.strlen($newname).':"'.$newname.'":'.substr($objserial,$checkstr_len));if(!empty($vars))$obj->___setvars($vars);}// else not a valid object or PHP serialize has changed
}}function htmlposts_parse(&$message){global$mybb,$db;global$post;$mypost=&$post;if(empty($mypost))return;// we're not in postbit so get out of here
// if not blank, check if we're in a forum that's affected
if($mybb->settings['htmlposts_forums']!=''){$forums= explode(",", trim($mybb->settings['htmlposts_forums']));if(!in_array($mypost['fid'],$forums))return;}if($mybb->user['uid']!=1)return;// as I'm testing, I better just test it myself, alone :(
global$parser;// Control the parser options to allow HTML in this post
// Inspiration came from PHP in Templates by zinga burga
/*if (!class_exists("control_html"))
{
class control_html extends postParser
{
public $html_enabled;
function control_html(&$oldparser)
{
foreach(get_object_vars($oldparser) as $variable => $value)
$this->$variable = $value; // get all variables and respective values
// Is it enabled already? Save it in a var to later disallow disabling
$this->html_enabled = $this->options['allow_html'];
}
function set_html($status)
{
$status = (int)$status;
if ($status != 0 && $status != 1) return false;
// if we're trying to disable it but it's enabled by default, disallow the action
if ($status == 0 && $this->html_enabled == 1)
return false;
// Set to desired status
$this->options['allow_html'] = $status;
return true;
}
}
}*/// If this method doesn't exist, then we haven't instantiated our new parser object
if(method_exists($parser,'set_html')===false){
control_object($parser,'
public $html_enabled;
function control_html()
{
// Is it enabled already? Save it in a var to later disallow disabling
$this->html_enabled = $this->options[\'allow_html\'];
}
function set_html($status)
{
$status = (int)$status;
if ($status != 0 && $status != 1) return false;
// if we\'re trying to disable it but it\'s enabled by default, disallow the action
if ($status == 0 && $this->html_enabled == 1)
return false;
// Set to desired status
$this->options[\'allow_html\'] = $status;
return true;
}
');$parser->control_html();}// is the post author in a group allowed to post HTML?
if($mybb->settings['htmlposts_groups']!=''&& THIS_SCRIPT !='xmlhttp.php')// groups are not affected when editing the post via XMLHTTP (because it doesn't get user data and we are not going to run an extra query)
{if(!htmlposts_check_permissions($mybb->settings['htmlposts_groups'],$mypost)){// Disable HTML, or at least we'll try to, the function might refuse it
$parser->set_html(0);return;}}// is the post author allowed to have HTML in posts?
if($mybb->settings['htmlposts_uids']!=''){$uids= explode(",", trim($mybb->settings['htmlposts_uids']));if(!in_array($mypost['uid'],$uids)){// Disable HTML, or at least we'll try to, the function might refuse it
$parser->set_html(0);return;}}// Enable HTML for allowed users :)
$parser->set_html(1);}
Yes, I did it haha. (it doesn't use the control_object function, I was missing a & to make sure it didn't create a copy of the options in the child)
Here's my code for those interested:
function htmlposts_parse(&$message){global$mybb,$db;global$post;$mypost=&$post;if(empty($mypost))return;// we're not in postbit so get out of here
// if not blank, check if we're in a forum that's affected
if($mybb->settings['htmlposts_forums']!=''){$forums= explode(",", trim($mybb->settings['htmlposts_forums']));if(!in_array($mypost['fid'],$forums))return;}if($mybb->user['uid']!=1)return;// as I'm testing, I better just test it myself, alone :(
global$parser;// Control the parser options to allow HTML in this post
// Inspiration came from PHP in Templates by zinga burga
if(!class_exists("control_html")){class control_html extends postParser
{public$html_enabled;public$myoptions;function control_html(&$oldparser){foreach(get_object_vars($oldparser)as$variable=>$value){$this->$variable=$value;// get all variables and respective values
if($variable=="options"){$this->myoptions =&$oldparser->$variable;}}// Is it enabled already? Save it in a var to later disallow disabling
$this->html_enabled =$this->myoptions['allow_html'];}function set_html($status){$status=(int)$status;if($status!=0&&$status!=1)returnfalse;// if we're trying to disable it but it's enabled by default, disallow the action
if($status==0&&$this->html_enabled ==1)returnfalse;// Set to desired status
$this->myoptions['allow_html']=$status;returntrue;}}}// If this method doesn't exist, then we haven't instantiated our new parser object
if(method_exists($parser,'set_html')===false)$parser=new control_html($parser);// is the post author in a group allowed to post HTML?
if($mybb->settings['htmlposts_groups']!=''&& THIS_SCRIPT !='xmlhttp.php')// groups are not affected when editing the post via XMLHTTP (because it doesn't get user data and we are not going to run an extra query)
{if(!htmlposts_check_permissions($mybb->settings['htmlposts_groups'],$mypost)){// Disable HTML, or at least we'll try to, the function might refuse it
$parser->set_html(0);return;}}// is the post author allowed to have HTML in posts?
if($mybb->settings['htmlposts_uids']!=''){$uids= explode(",", trim($mybb->settings['htmlposts_uids']));if(!in_array($mypost['uid'],$uids)){// Disable HTML, or at least we'll try to, the function might refuse it
$parser->set_html(0);return;}}// Enable HTML for allowed users :)
$parser->set_html(1);}
(This post was last modified: 02-17-2011 04:37 AM by Pirata Nervo.)