Hide Code From Usergroups

ucenik1

New Member
Description:
This hack will allow you to specify which usergroups can view "code" (PHP, HTML and CODE bbCodes).

To Install:
Read the supplied install instructions. Even though there are 6 template edits, they are done automatically. Posts you have already made that contain code in them will NOT show the changes because they are already cached. You have a few options with this:

* Delete them from the postparsed table
* Rebuild post cache from AdminCP
* Edit them so it rebuilds


How it works:
vBulletin caches posts. What this means is, instead of parsing the bbCode templates each time, it will do it once per style and store the output in the database. This completely kills any chance you have of putting usergroup conditions inside of these templates.

The first step was to prevent vBulletin from caching posts which contain these tags, so in the showthread_postbit_create hook, I created the following plugin
PHP:
if (!isset($posts_cachable))
{
    $posts_cachable = $post_cachable;
}

$post_cachable = ((
        strpos($post['pagetext'], '{php}') !== false or
        strpos($post['pagetext'], '{code}') !== false or
        strpos($post['pagetext'], '{html}') !== false
    ) ? false : $posts_cachable
);
vBulletin has the variable "$post_cachable" which basically checks for the whole thread(!) if posts are cachable. Not very helpful to us... So this plugin first makes a new variable ($posts_cachable) and sets it to whatever the $post_cachable variable is set to. Only once.

The next block uses the ternary operator (cleaner to read for me) and basically checks if those 3 bbcodes are found in the currently processing post. If any are found, it will set the $post_cachable variable to false so it will bypass the caching procedure for this post. If none of the 3 are found, it will fall back to that other variable I created (the original value of $post_cachable).

I am checking if it exists inside the post by using the strpos() function, which returns the position of the needle inside the haystack if it is found (integer) or FALSE if it isn't. We can't use a single if (!...) check because it may return 0 if its at the very beginning which evaulates to false. So we can check if not exactly equal to false by using !==

Note that I'm not using strstr() because this is much faster. This could could probably be improved using a regular expression or another function, because it's case sensitive.

The next step was to determine who can view the code. Using the global_start hook, I created the following plugin:
PHP:
if ($vbulletin->options['hidecode_groups'])
{
    $showCodeGroups= explode(' ', $vbulletin->options['hidecode_groups']);
    $show['hidecode'] =  !is_member_of($vbulletin->useinfo, $showCodeGroups);
}
else
{
    $show['hidecode'] = false;
}
Since we only want this to run when the admin has entered any usergroups, we will wrap it inside an if so this happens. Using the explode() function we can convert the space-seperated-list into an array, which is must easier to work with. Now that we have an array, we can vBulletin's is_member_of() function which returns TRUE if you are a primary or secondary member of any of the groups, and FALSE if you aren't. Since I put a ! (NOT) in front of the function, it will return the opposite. I am setting the variable $show['hidecode'] to the return value of that whole statement, which in this case is TRUE if the code should be hidden (if you aren't in the usergroups) and FALSE if you can see it.

Finally, in all of the templates (the edits were done automatically), each $code variable is replaced with
PHP:
<if condition="$show['hidecode']">You can't view code phrase<else />$code</if>
which would check the variable to see if they can see it before attempting to show them anything.
 
i uploaded the files but when i try to add install xml file i get the error below that shows in the pic below

i hv tried both file same problem..neither of them works
and the text file in the zip folder says to edit temple but not sure where sud i put coeds because it just tell me find but find what>?
thanks in advance
also anotehr questions
is it like vb hide hack?
 
installed for me, also where do i find the settings?

EDIT: carnt uninstall it i get:


Code:
Database error in vBulletin 3.8.1:

Invalid SQL:

			INSERT INTO template
				(`styleid`, `version`, `title`, `templatetype`, `product`, `template`, `template_un`)
			VALUES (0, '3.6.4', 'bbcode_code', 'template', 'vbulletin', '<div style=\\\"margin:20px; margin-top:5px\\\">\r\n	<div class=\\\"smallfont\\\" style=\\\"margin-bottom:2px\\\">$vbphrase[code]:</div>\r\n	<pre class=\\\"alt2\\\" dir=\\\"ltr\\\" style=\\\"\r\n		margin: 0px;\r\n		padding: $stylevar[cellpadding]px;\r\n		border: 1px inset;\r\n		width: $stylevar[codeblockwidth];\r\n		height: {$blockheight}px;\r\n		text-align: left;\r\n		overflow: auto\\\">$code</pre>\r\n</div>', '<div style=\"margin:20px; margin-top:5px\">\r\n	<div class=\"smallfont\" style=\"margin-bottom:2px\">$vbphrase[code]:</div>\r\n	<pre class=\"alt2\" dir=\"ltr\" style=\"\r\n		margin: 0px;\r\n		padding: $stylevar[cellpadding]px;\r\n		border: 1px inset;\r\n		width: $stylevar[codeblockwidth];\r\n		height: {$blockheight}px;\r\n		text-align: left;\r\n		overflow: auto\">$code</pre>\r\n</div>');

MySQL Error   : Duplicate entry 'bbcode_code-0-template' for key 2
Error Number  : 1062
 
Back
Top