Hi,
This is slowly driving me nuts, so I hope someone understands this problem.
I'm trying to read the contents of the "newbb_topic_lastread" cookie from the Recent Topics block, but I tried everything and it always return empty, while the cookie *does* exist.
I've added this code to the "newbb_new.php" code (it's in dir newbb/blocks):
$topic_lastread = !empty($HTTP_COOKIE_VARS['newbb_topic_lastread']) ? unserialize($HTTP_COOKIE_VARS['newbb_topic_lastread']) : array();
and
$topic['cookiecontent'] = $topic_lastread[$arr['topic_id']];
so that I can use the topic last read date in the Smarty template (newbb_block_new.html). I have tested other variables in the template and these DO show.
To be sure I defined $HTTP_COOKIE_VARS as Global within the newbb_new.php
The code then looks like this (added lines are in bold typeface):
Quote:
function b_newbb_new_show($options) {
global $HTTP_COOKIE_VARS;
$topic_lastread = !empty($HTTP_COOKIE_VARS['newbb_topic_lastread']) ? unserialize($HTTP_COOKIE_VARS['newbb_topic_lastread']) : array();
$db =& Database::getInstance();
$myts =& MyTextSanitizer::getInstance();
$block = array();
switch($options[2]) {
case 'views':
$order = 't.topic_views';
break;
case 'replies':
$order = 't.topic_replies';
break;
case 'time':
default:
$order = 't.topic_time';
break;
}
$query='SELECT t.topic_id, t.topic_title, t.topic_last_post_id, t.topic_time, t.topic_views, t.topic_replies, t.forum_id, f.forum_name FROM '.$db->prefix('bb_topics').' t, '.$db->prefix('bb_forums').' f WHERE f.forum_id=t.forum_id AND f.forum_type <> 1 ORDER BY '.$order.' DESC';
if (!$result = $db->query($query,$options[0],0)) {
return false;
}
if ( $options[1] != 0 ) {
$block['full_view'] = true;
} else {
$block['full_view'] = false;
}
$block['lang_forum'] = _MB_NEWBB_FORUM;
$block['lang_topic'] = _MB_NEWBB_TOPIC;
$block['lang_replies'] = _MB_NEWBB_RPLS;
$block['lang_views'] = _MB_NEWBB_VIEWS;
$block['lang_lastpost'] = _MB_NEWBB_LPOST;
$block['lang_visitforums'] = _MB_NEWBB_VSTFRMS;
while ($arr = $db->fetchArray($result)) {
$topic['forum_id'] = $arr['forum_id'];
$topic['forum_name'] = $myts->makeTboxData4Show($arr['forum_name']);
$topic['id'] = $arr['topic_id'];
$topic['title'] = $myts->makeTboxData4Show($arr['topic_title']);
$topic['replies'] = $arr['topic_replies'];
$topic['views'] = $arr['topic_views'];
$topic['cookiecontent'] = $topic_lastread[$arr['topic_id']];
$topic['post_id'] = $arr['topic_last_post_id'];
$lastpostername = $db->query("SELECT post_id, uid FROM ".$db->prefix("bb_posts")." WHERE post_id = ".$topic['post_id']);
while ($tmpdb=$db->fetchArray($lastpostername)) {
$tmpuser = XoopsUser::getUnameFromId($tmpdb['uid']);
if ( $options[1] != 0 ) {
$topic['time'] = formatTimestamp($arr['topic_time'],'m')." $tmpuser";
}
}
$block['topics'][] =& $topic;
unset($topic);
}
return $block;
}
Next I added "<{$topic.cookiecontent}>" to the Smarty Template of the Recent Topics Block, but whatever I do, the variable always show up empty!
Now I've used this method with other (global) variables in other blocks and it always worked well, but somehow reading the cookiecontent into a var is different from normal global variables as it just doesn't seem to get read!
I've checked if the cookie is available in my browser cache and it is (with a string of numbers as content), it also works when marking topics read in the newbb "viewtopics" module.
I've tried a number of other options (reordering the lines, defining as global, not defining as global, etc etc, but it's all to no avail)
What am I doing wrong??? It's driving me nuts spending hours trying to get this to work
Now I'm very new to PHP so I sincerely hope someone with experience in PHP can point me to the problem.
Thanks for any help,
Ross