kommuni |
01-03-2006 07:11 AM |
Hi together,
as there doesn't seem to be anymore support for this hack, i helped myself and found a solution for that previously named problem.
I'll post it here and you may use it at your own risk!
With this modification, you're able to setup rules for every page. With such a global rule everyone first has to agree to this rule before beeing able to read any of your forums (or even gallery, arcade, any hack that uses vb-templateparser).
the only thing you need to modify is the template_parser plugin from the rules & agreementhack. Just xchange the complete code with this:
PHP Code:
$hackagree = array();
$vbulletin->input->clean_array_gpc('p', array('hackagree' => TYPE_ARRAY_INT, 'forumid' => TYPE_INT, 'oldurl' => TYPE_STR, 'do' => TYPE_STR));
$ruleids = implode(",", $vbulletin->GPC['hackagree']);
$scripturl1 = iif ($_SERVER['SCRIPT_URI'], $_SERVER['SCRIPT_URI'], "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME']);
$urluri = $scripturl1 . iif($_SERVER['QUERY_STRING'], "?" . $_SERVER['QUERY_STRING']);
if ($ruleids)
{
//Lets see if this user has agreed or not (Update agreed ruleid)
update_rules($ruleids, $vbulletin->GPC['forumid']);
}
else
{
if ($vbulletin->GPC['hackagree']<>1)
{
// Check for all list of RULE to be apply for this page...
$ruletext = check_newrules($vbulletin->GPC['forumid']);
if ($ruletext)
{
$navbits = array();
$parentlist = array_reverse(explode(',', substr($foruminfo['parentlist'], 0, -3)));
foreach ($parentlist AS $forumID)
{
$forumTitle = $forumcache["$forumID"]['title'];
$navbits["forumdisplay.php?$session[sessionurl]f=$forumID"] = $forumTitle;
}
// parse headinclude, header & footer
$admincpdir =& $vbulletin->config['Misc']['admincpdir'];
$modcpdir =& $vbulletin->config['Misc']['modcpdir'];
$navbits[''] = $vbphrase['ruleshack_rules_and_agreement'];
$navbits = construct_navbits($navbits);
if (empty($navbar))
eval('$navbar = "' . fetch_template('navbar') . '";');
if (empty($headinclude))
eval('$headinclude = "' . fetch_template('headinclude') . '";');
if (empty($header))
eval('$header = "' . fetch_template('header') . '";');
if (defined('VBA_PORTAL'))
{
require_once(DIR . '/includes/vba_cmps_include_bottom.php');
}
if (empty($footer))
eval('$footer = "' . fetch_template('footer') . '";');
if ($_REQUEST['do'] == 'postreply')
{
$rule = array();
$rule['postreply'] = 1;
$rule['wysiwyg'] = $_REQUEST['wysiwyg'];
$rule['quickreply'] = $_REQUEST['quickreply'];
$rule['message'] = addslashes($_REQUEST['message']);
$rule['fromquickreply'] = $_REQUEST['fromquickreply'];
$rule['t'] = $_REQUEST['t'];
$rule['p'] = $_REQUEST['p'];
$rule['parseurl'] = $_REQUEST['parseurl'];
}
eval('print_output("' . fetch_template('ruleshack_rules') . '");');
exit;
}
}
}
// function "check_rulesneed" to find any rules exist for this page....
function check_rulesneeded()
{
global $vbulletin, $urluri, $scripturl1;
$ruleneed = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX . "ruleshack
WHERE (fileurl LIKE '" . $urluri . "' AND exactmatch = 1 )
OR (fileurl LIKE '" . $scripturl1 . "%' AND exactmatch = 0 )
OR (fileurl LIKE 'all' AND exactmatch = 0) AND active = 1 ORDER BY ruleid");
if (!$ruleneed)
return false;
else
return true;
}
// function "check_newrules" to find all the rules to be agreed by this user
function check_newrules($fid = 0)
{
global $vbulletin, $foruminfo, $vbphrase, $stylevar, $urluri, $scripturl1;
if ((!$fid) and (!check_rulesneeded()))
return false;
//Lets check what rule(s) this user should get
$vbulletin->userinfo['agreedrule'] = iif($vbulletin->userinfo['agreedrule'], $vbulletin->userinfo['agreedrule'], '0');
$parents = iif($vbulletin->forumcache[$vbulletin->GPC['forumid']]['parentlist'], $vbulletin->forumcache[$vbulletin->GPC['forumid']]['parentlist'], '0');
$parentids = array();
$parentids = iif($parents, explode(',', str_replace(' ', '', $parents)), 0);
if (($_COOKIE[COOKIE_PREFIX . 'rules']) and ($vbulletin->userinfo['userid']==0))
foreach($_COOKIE[COOKIE_PREFIX . 'rules'] AS $key => $value)
{
$allrules .= " :: " . $key;
$vbulletin->userinfo['agreedrule'] .= iif($vbulletin->userinfo['agreedrule']!='',",","") . $value;
}
$sql = "SELECT * from " . TABLE_PREFIX . "ruleshack
WHERE
(
(forumid = $fid)
OR
(fileurl LIKE '" . $urluri . "' AND exactmatch = 1 )
OR
(fileurl LIKE '" . $scripturl1 . "%' AND exactmatch = 0 )
OR
(fileurl LIKE 'all' AND exactmatch = 0 )
OR
(forumid IN ($parents))
)
AND
(ruleid not in (" . $vbulletin->userinfo['agreedrule'] . "))
AND
active = 1
ORDER BY ruleid";
$rule = $vbulletin->db->query($sql);
$i = 1;
while ($rules = $vbulletin->db->fetch_array($rule))
{
$flag = 0;
$condflag = 0;
$groupflag = 0;
$memberflag = 0;
// Lets start our rules
// Rule #1 : USER is from Selected Usergroup(s)
if ($rules['groupids'])
{
$gids = array();
$gids = explode(',', str_replace(' ', '', $rules['groupids']));
if (in_array($vbulletin->userinfo['usergroupid'], $gids))
{
$flag = 1;
$groupflag = 1;
}
}
// Rule #2 : USRE is from Selected Membergroup(s)
if ($rules['memberids'])
{
$mids = array();
$mgids = explode(',', str_replace(' ', '', $vbulletin->userinfo['membergroupids']));
$mids = explode(',', str_replace(' ', '', $rules['memberids']));
foreach ($mgids as $ids)
{
if (in_array($ids, $mids))
{
$flag = 1;
$memberflag = 1;
}
}
}
if ( ($groupflag==1) or ($memberflag==1) )
$condflag = 1;
else
$condflag = 0;
// Rule #4 : USER is from Selected Userid(s)
if ($rules['userids'])
{
$uids = array();
$uids = explode(',', str_replace(' ', '', $rules['userids']));
if (in_array($vbulletin->userinfo['userid'], $uids))
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #5 : USER is from Selected Username(s)
if ($rules['usernames'])
{
$unames = array();
$unames = explode(',', str_replace(' ', '', $rules['usernames']));
if (in_array($vbulletin->userinfo['username'], $unames))
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// All the Condition from Rule #6 - Rule #13 for VB Users....
if ($vbulletin->userinfo['userid'] > 0 )
{
// Rule #6 : User has More than X post(s)
if ($rules['postmore'])
{
if ($vbulletin->userinfo['posts'] > $rules['postmore'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #7 : User has Less than X post(s)
if ($rules['postless'])
{
if ($vbulletin->userinfo['posts'] < $rules['postless'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #8 : Join date is After xxx Date
if ($rules['joindateafter'])
{
if ($vbulletin->userinfo['joindate'] > $rules['joindateafter'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #9 : Join date is Before xxx Date
if ($rules['joindatebefore'])
{
if ($vbulletin->userinfo['joindate'] < $rules['joindatebefore'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #10 : Last visit is After xxx Date
if ($rules['lastactiveafter'])
{
if ($vbulletin->userinfo['lastvisit'] > $rules['lastactiveafter'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #11 : Last visit is Before xxx Date
if ($rules['lastactivebefore'])
{
if ($vbulletin->userinfo['lastvisit'] < $rules['lastactivebefore'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #12 : Last post is After xxx Date
if ($rules['lastpostafter'])
{
if ($vbulletin->userinfo['lastpost'] > $rules['lastpostafter'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #13 : Last post is Before xxx Date
if ($rules['lastpostbefore'])
{
if ($vbulletin->userinfo['lastpost'] < $rules['lastpostbefore'])
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
}
// All the Condition from Rule #6 - Rule #13 for VB Users....
// Rule #14 : Rule apply for Child forum....
if (($parentids) and ($fid != $rules['forumid']))
{
if ((in_array($rules['forumid'], $parentids)==1) and ($rules['childforum']==1))
{
$flag = 1;
$condflag = 1;
}
else {
$condflag = 0;
}
}
// Rules from URL
$flag = 0;
if ($condflag == 1)
{
if ($rules['fileurl'])
{
$urlpos = strrpos($urluri, $rules['fileurl']);
// Rule #14 : Show Rules on URL match.....
if (($rules['fileurl'] == $urluri) and ($rules['exactmatch']==1))
{
$flag = 1;
$condflag = 1;
} else {
$condflag = 0;
}
// Rule #15 : Show Rules on URL match.....
if (($urlpos) and ($rules['exactmatch']==0))
{
$flag = 1;
$condflag = 1;
} else {
$condflag = 0;
}
// Rule #14 + 15 : Show Rules regardless to URL.....
if(($rules['fileurl']=='all') and ($rules['exactmatch']==0))
{
$flag = 1;
$condflag = 1;
} else {
$condflag = 0;
}
}
// Rule #16 : First Thread ever in this Forum by this User
if (($rules['firstnewthread']) and ($fid!=0) and ($_REQUEST['do'] == 'newthread'))
{
$result = $vbulletin->db->query_first("SELECT * from " . TABLE_PREFIX . "thread
WHERE forumid = $fid and postuserid = " . $vbulletin->userinfo['userid'] . " ");
if (!$result)
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
// Rule #17 : Show Rules on New Thread....
if ($rules['newthread'])
{
if ($_REQUEST['do'] == 'newthread')
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
} else {
$condflag = 0;
}
// Rule #18 : Show Rules on New Post....
if ($rules['newreply'])
{
if ($_REQUEST['do'] == 'newreply' or $_REQUEST['do'] == 'postreply')
{
$flag = 1;
$condflag = 1;
}else
$condflag = 0;
} else {
$condflag = 0;
}
// Rule #19 : Show Rules on View Forum....
if ($rules['viewforum'])
{
if (($fid) and ($_REQUEST['do'] != 'newreply' and $_REQUEST['do'] != 'newthread' and $_REQUEST['do'] != 'postreply'))
{
$flag = 1;
$condflag = 1;
}else {
$condflag = 0;
}
}
} else {
$condflag = 0;
}
// Rules End ... Thank you
if ($rules['conditions'])
if ($condflag == 0)
$flag = 0;
if ($flag == 1)
{
$ruletitle = $rules['ruletitle'];
$ruleid = $rules['ruleid'];
if ($rules['allowbbcode'])
{
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$ruletextbit = $bbcode_parser->parse($rules['ruletext']);
}
else
{
$ruletextbit = $rules['ruletext'];
}
eval('$ruletext .= "' . fetch_template('ruleshack_rulesbit') . '";');
$i++;
}
}
return $ruletext;
}
function update_rules($rid = '', $f = 0)
{
global $vbulletin ;
// You gotta agree on this
if ($rid)
{
$vbulletin->db->query("UPDATE " . TABLE_PREFIX . "user SET agreedrule = '" .
iif($vbulletin->userinfo['agreedrule'], $vbulletin->userinfo['agreedrule'] . ",", "") . $rid . "'
WHERE userid = " . $vbulletin->userinfo['userid']);
vbsetcookie("rules[". $rid ."]",$rid);
if ($_REQUEST['do'] != 'postreply')
exec_header_redirect($vbulletin->GPC['oldurl']);
}
return 1;
}
function fetch_user_agreed_rules()
{
global $vbulletin, $threadinfo, $userinfo;
if ($_REQUEST['find'] == 'lastposter' AND $userinfo)
{
$uid = $userinfo['userid'];
}
$uid = iif($_REQUEST['u'], $_REQUEST['u'], $uid);
if ($uid > 0)
{
$Ruser = fetch_userinfo($uid);
$ruleids = iif($Ruser['agreedrule'], $Ruser['agreedrule'], 0);
$result = $vbulletin->db->query("SELECT * from " . TABLE_PREFIX . "ruleshack
WHERE ruleid in ($ruleids) AND ruleurl <> ''");
while ($ruleinfo = $vbulletin->db->fetch_array($result))
{
$agreedrules .= "<tr><td><a href='" . $ruleinfo['ruleurl'] . "'>" . $ruleinfo['ruletitle'] . "</a></td></tr>";
}
}
return $agreedrules;
}
Then setup a rule with URL "all" (just type in these three letters in the url field) and set exact match to no.
That's all.
It's kind of a 'dirty' solution but it's working and should not have any negative consequences. I've setup some new forumrules for my 15k+ board and it's working very well.
Best,
Frank
|