Control Object Help
Pirata Nervo Offline
Member
***
Posts: 235
Joined: Jan 2008
Post: #3
RE: Control Object Help
(02-17-2011 09:24 AM)ZiNgA BuRgA Wrote:  I'm not terribly sure why you're subclassing in the first case though.
You're not actually overwriting any functions here.  Perhaps if you're aiming for compatibility with MyBB 1.6.0, I could see why, but I believe the $parser->options was made public in 1.6.1 from memory, so you could just overwrite it directly without whacky control methods.

I feel bad now.
Does the method above work for a private $options ? (the last method I posted)

Edit:
Tried it myself and it didn't work, not sure why but I don't have time to find out if get_object_vars retreives non-public variables so decided to re-write it, only for 1.6, here it is:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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;
	}
	
	global $parser, $control_html;
	
	// Create a new class to control the parser options easily
	if (!class_exists("control_html"))
	{
		class control_html
		{
			public $html_enabled;
			
			function control_html()
			{
				// Is it enabled already? Save it in a var to later disallow disabling
				$this->html_enabled = $parser->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;
					
				global $parser;
					
				// Set to desired status
				$parser->options['allow_html'] = $status;
				
				return true;
			}
		}
	}
	
	// Create object if it doesn't exist
	if (!is_object($control_html))
		$control_html = new 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
			$control_html->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
			$control_html->set_html(0);
			return;
		}
	}
	
	// Enable HTML for allowed users :)
	$control_html->set_html(1);
}


Thank you for your help zinga.

(This post was last modified: 02-18-2011 12:47 AM by Pirata Nervo.)
02-18-2011 12:12 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Control Object Help - Pirata Nervo - 02-17-2011, 04:21 AM
RE: Control Object Help - ZiNgA BuRgA - 02-17-2011, 09:24 AM
RE: Control Object Help - Pirata Nervo - 02-18-2011 12:12 AM
RE: Control Object Help - ZiNgA BuRgA - 02-18-2011, 08:08 AM

 Standard Tools
Forum Jump: