- الإهدائات >> |
Tutorial Hide Text And Code From Usergroups
Tutorial Hide Text And Code From Usergroups
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:
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 Code:
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 Code:
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
Code:
You can't view code phrase$code
which would check the variable to see if they can see it before attempting to show them anything.
ملحوظة هامة جدا جدا جدا
التحميل من موقعنا مبااااااااااااااااشر
و لكن يتطلب منك ادخال اسم مستخدم و باسورد
هذه هي بيانات التحميل
اسم المستخدم
fokakmeny_down
كلمة المرور
123456
في حالة وجود خطأ لا تتردوا بالاتصال بنا قسم البريد
او من نموذج الاتصال بنا
Tutorial Hide Text And Code From Usergroups
Tutorial Hide Text And Code From Usergroups
Tutorial Hide Text And Code From Usergroups
شكرا مصطفى
الذين يشاهدون الموضوع الآن: 1 (0 من الأعضاء و 1 زائر)
الإجراءات : (من قرأ ؟)
لم يشاهد الموضوع أي عضو حتى الأن.
مواقع النشر (المفضلة)