PDA

View Full Version : Where this hook edit should go...


Logikos
01-25-2006, 09:52 PM
Hey guys, Maybe you can help me out. I'm creating a new condition to be able to use in the postbit template. The condition will be something like this:



<if condition="$check">
<!-- $check holds information -->
<else />
<!-- $check doesn't hold information -->
</if>


The '$check' variable will be determined like this:


$checkdata = $db->query_read("
SELECT dateline
FROM " . TABLE_PREFIX . "custom
WHERE userid = " . $vbulletin->userinfo['userid'] . "
AND threadid = " . intval($threadid)
);

if ($db->num_rows($checkdata))
{
$check = true;
}
else
{
$check = false;
}


Now I want to beable to use that in my postbit_legacy template. Any ideas where in showthread.php to add the PHP code? I've tried ALL avalible hooks and none worked. Thanks

Xenon
01-25-2006, 09:59 PM
place it in postbit_display_start and make sure via a static variable, that the query just runs once!

Logikos
01-25-2006, 10:36 PM
Thanks Xenon, though that doesn't seem to work as expected. It seemed to add one addional query for each post per page. The condition didn't seem to work also.

Basicly I need a query to check that database to see if the user who is viewing the threadid is in the database table. If he is show X if he isn't show Y. Normaly I would just add this to the showthread.php and it works fine. Though I have to add this to the postbit template. So theres no reason to run 10 extra queries when they will always equal the same thing.

The problem is getting the condition to work in the postbit template. :)

Xenon
01-26-2006, 10:56 AM
that's why i said you need a static variable to run it just once ;)


static $alreadychecked, $check;

if (!$alreadychecked)
{
$checkdata = $db->query_read("
SELECT dateline
FROM " . TABLE_PREFIX . "custom
WHERE userid = " . $vbulletin->userinfo['userid'] . "
AND threadid = " . intval($threadid)
);

if ($db->num_rows($checkdata))
{
$check = true;
}
else
{
$check = false;
}
$alreadychecked = true;
}

Logikos
01-26-2006, 01:52 PM
that's why i said you need a static variable to run it just once ;)

Yea I know and I tried using a static variable. Heres the code I used in ": postbit_display_start".


global $db, $vbulletin;
static $alreadychecked, $check;

if (!$alreadychecked)
{
$checkdata = $db->query_read("
SELECT dateline
FROM " . TABLE_PREFIX . "custom
WHERE userid = " . $vbulletin->userinfo['userid'] . "
AND threadid = " . intval($thread['threadid']) . "
");

if ($db->num_rows($checkdata))
{
$check = true;
}
else
{
$check = false;
}

$alreadychecked = true;

}


The conditions worked for each postbit, but its still running the query for each postbit. =\ I had to add:

global $db, $vbulletin;
Or it would give me a "Fatal error: Call to a member function on a non-object in /home/vbhacker/public_html/jelsoft/includes/class_postbit.php(251) : eval()'d code on line 6"

amykhar
01-26-2006, 02:00 PM
Would it work to put the query in showthread and assign the results to a variable? Then in postbit, you could declare the variable global and check the value. Might be worth a shot.

Xenon
01-26-2006, 02:43 PM
hmm, that should be possible as well amy.

as for the other thing, that seems to be a glitch in the plugin system, or better said in the eval() function of php... not the first one i noticed... ^^

Logikos
01-26-2006, 02:52 PM
Should I ask vBulletin about this and see if its a glitch in the plugin system?

Also Amy: Are you saying add the query to showthread_start and use $GLOBALS[]?

Xenon
01-26-2006, 02:58 PM
nope, its a provlem in the eval function, which is used by vbulletin.

and to answer question two.
that would be possible, but it should be enough to use global variablename in the postbit plugin ;)

amykhar
01-26-2006, 03:04 PM
What stefan said.

harmor19
01-26-2006, 03:12 PM
I am doing something similiar and I received that error as well.

The first thing when I get off work is checking if "global $db, $vbulletin;" work.

Princeton
01-26-2006, 03:44 PM
I'm not sure what you are trying to do but why not use a JOIN in showthread.php
$hook_query_fields, $hook_query_joins in 'showthread_query' hook

then add
$check = false;
if custom_userid and custom_threadid exist
{
$check = true;
}in 'showthread_postbit_create' hook

Logikos
01-26-2006, 03:54 PM
Well I decided to add this condition around the query:


if ($thread['firstpostid'] == $post['postid'])
{

}


That seemed to do the trick. Now I have 13 queries running instead of 23. :)