Log in

View Full Version : $GLOBALS['forumid']


Exa
02-07-2014, 12:12 AM
i'm trying to use $GLOBALS['forumid'] at hook attachment_start and not working .
any idea ?

ozzy47
02-07-2014, 12:20 AM
$GLOBALS[] is a "superglobal" so it should be available everywhere.

What is it you are trying to do, you did not explain to much, also the full code you are using might help.

Exa
02-07-2014, 08:27 AM
code at attachment_start to check attachments forumid before download

if(!in_array($GLOBALS['forumid'], array(1, 2, 3, 4))){

}

ozzy47
02-07-2014, 11:30 AM
That still does not show what it is you are trying to do, what is the full code?

Exa
02-07-2014, 11:36 AM
the full code

if(!in_array($GLOBALS['forumid'], array(1, 2, 3, 4))){
$out = $_SERVER['SERVER_NAME'] ;
header('Status: 301 Moved Permanently', false, 301);
header( 'Location:' . $out) ;
}

kh99
02-07-2014, 11:50 AM
The forumid global will only be available if there is a -f or -forum parameter, and there isn't for an attachment. There doesn't seem to be any way to do what you want to do in a plugin unless you do your own query to find out what forum the postid or attachmentid is related to (if you look at attachment.php and search for 'attachment_start' you can see what's going on there).

Of course if you don't mind modifying the php files you could insert your code in attachment.php somewhere after the query has been done. Then you would use $attachmentinfo['forumid'] instead of the global.

Exa
02-07-2014, 12:12 PM
maybe query is the best way

so, what query will look like ?

kh99
02-07-2014, 01:35 PM
Well, I haven't tried it but I guess it would look like the one that's in attachment.php, but you don't need to read everything since you only need the forumid. So maybe:
if (!$attachmentinfo = $db->query_first_slave("
SELECT thread.forumid FROM " . TABLE_PREFIX . "attachment AS attachment
LEFT JOIN " . TABLE_PREFIX . "post AS post ON (post.postid = attachment.postid)
LEFT JOIN " . TABLE_PREFIX . "thread AS thread ON (post.threadid = thread.threadid)
WHERE " . ($vbulletin->GPC['postid'] ? "attachment.postid = " . $vbulletin->GPC['postid'] : "attachmentid = " . $vbulletin->GPC['attachmentid']) . "
"))
{
eval(standard_error(fetch_error('invalidid', $vbphrase['attachment'], $vbulletin->options['contactuslink'])));
}
if (!in_array($attachmentinfo['forumid'], array(1, 2, 3, 4))
{
// etc.
}

Exa
02-07-2014, 07:55 PM
Let me try and feed you back

--------------- Added 1391811107 at 1391811107 ---------------

you forget to add ")" at the end of forumid array

That's work exactly, thank you !