View Full Version : Problem with setting a cookie variable with a hook!
Citizen
11-22-2006, 09:39 PM
I setup a sidebar for navigation on my forums. I want the sidebar to be removable if my users click a link at the bottom of the side bar. The sidebar works great, but if you click the "remove" link, nothing happens.
http://www.gunzfactor.com/forums
Hook Name: "Sidebar Cookie"
Hook Location: global_start
Hook Code:
$show['sidebar'] = true;
if ($_REQUEST['do'] == 'hidesidebar')
{
vbsetcookie('hidesidebar', 1, true);
}
$vbulletin->input->clean_gpc('c', 'hidesidebar', 'TYPE_INT');
if ($vbulletin->GPC['hidesidebar'] == 1)
{
$show['sidebar'] = false;
}
The template conditional:
<if condition="$show['sidebar']"> </if>
The "remove" link points to:
{$vbulletin->options['bburl']}/index.php?$session[sessionurl]do=hidesidebar
Any idea where the problem is?
Guest190829
11-22-2006, 09:57 PM
The following should work:
$show['sidebar'] = true;
if ($_REQUEST['do'] == 'hidesidebar')
{
vbsetcookie('hidesidebar', 1, true);
}
$cookiename = COOKIE_PREFIX . 'hidesidebar';
$vbulletin->input->clean_gpc('c', $cookiename, 'TYPE_INT');
if ($vbulletin->GPC["$cookiename"] == 1)
{
$show['sidebar'] = false;
}
Seranza
12-26-2006, 09:20 PM
Ok, I'm having problems, can anyone figure out how to get this to work with my "hide the sidebar" code....
I have this in my main template
<table align="center" class="page" cellspacing="0" cellpadding="0"width="100%">
<tr valign="top">
<if condition="$show['left_column']">
<td width="175" id="collapseobj_gtpcloseleftcol" style="$vbcollapse[collapseobj_gtpcloseleftcol]">
And this is my navbar link before adding the plugin(works but doesn't keep settings between pages hence the need for a cookie...)
<a href="#top"
onclick="toggle_collapse('gtpcloseleftcol')">SideBar</a>
This is the code I have in my plugin just as suggested in the previous post
$show['left_column'] = true;
if ($_REQUEST['do'] == 'hidesidebar')
{
vbsetcookie('hidesidebar', 1, true);
}
if ($_REQUEST['do'] == 'showsidebar')
{
vbsetcookie('hidesidebar', 0, true);
}
$cookiename = COOKIE_PREFIX . 'hidesidebar';
$vbulletin->input->clean_gpc('c', $cookiename, 'TYPE_INT');
$sidebar = $vbulletin->GPC["$cookiename"];
if ($sidebar == 1)
{
$show['left_column'] = false;
}
This is the nav bar link after the plugin code has been added
<if condition="$sidebar == 0"><a href="./index.php?do=hidesidebar">Hide</if><if condition="$sidebar == 1"><a href="./index.php?do=showsidebar">Show</if></a>
Now... the page takes 2 clicks of either link before it will swap to the other link and the sidebar does not go away... I'm stumped... can anyone help me figure this out? Also, is there another way to do the link so it doesn't force them back to the index page but will leave them on the page they are on like the old (cookieless) code does?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.