The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Problem with If-Else If-Else Conditional in Plugin
I am having some issues with an If-Else If-Else that I have in a plugin for the postbit. The real kicker is it works on my own personal site, but it doesn't work on at least 3 other sites, running practically the exact same setup as me. From what I can tell, the conditional goes directly to the ELSE, but I am almost positive that the value being evaluated in the statement is being passed correctly. Here is the plugin code:
Code:
if(THIS_SCRIPT == 'showpost' OR THIS_SCRIPT == 'showthread') { switch ($vbulletin->options['postbittype']) { case 1: $pbq = "ORDER BY `main_vehicle` DESC LIMIT 1"; break; case 2: $pbq = "ORDER BY `main_vehicle` DESC LIMIT 1"; break; case 3: $pbq = "ORDER BY `vehicle_id` DESC LIMIT 10"; break; } $sql = $this->registry->db->query("select *, " . TABLE_PREFIX . "garage_user_vehicle.user_id AS PostUser from " . TABLE_PREFIX . "garage_user_vehicle LEFT JOIN " .TABLE_PREFIX . "garage_makes on (" .TABLE_PREFIX . "garage_user_vehicle.make_id=" .TABLE_PREFIX . "garage_makes.id) LEFT JOIN " .TABLE_PREFIX . "garage_models on (" .TABLE_PREFIX . "garage_user_vehicle.model_id=" .TABLE_PREFIX . "garage_models.id) WHERE " . TABLE_PREFIX . "garage_user_vehicle.user_id='" . $post['userid'] ."' " . $pbq); if($this->registry->db->num_rows($sql) > 0) { if($vbulletin->options['postbittype'] == 3) { while ($entry = $this->registry->db->fetch_array($sql)) { $newyr = substr($entry[made_year], -2); $template_hook['postbit_userinfo_right_after_posts'] .= "<div><a href=garage_vehicle.php?do=view_vehicle&id=$entry[vehicle_id]>'$newyr $entry[make] $entry[model]</a></div>"; } } else if($vbulletin->options['postbittype'] == 2) { $entry = $this->registry->db->fetch_array($sql); $newyr = substr($entry[made_year], -2); $template_hook['postbit_userinfo_right_after_posts'] .= "<div><img src='images/garage/car.png'><a href=garage.php?do=user_garage_view&id=$entry[PostUser]> $post[username]'s Garage</a></div>"; } else { $entry = $this->registry->db->fetch_array($sql); $newyr = substr($entry[made_year], -2); $template_hook['postbit_userinfo_right_after_posts'] .= "<div><a href=garage.php?do=user_garage_view&id=$entry[PostUser]>'$newyr $entry[make] $entry[model]</a></div>"; } } } |
#2
|
||||
|
||||
Turn on debug mode and use DEVDEBUG() to find which condition you go to.
(If I'm reading right, you're potentially running an SQL query on every post being displayed - that is not good.) |
#3
|
|||
|
|||
I have tried to join the showthread query, but have never figured out how to get it to work. If you could give me some hints on that as well, that would be great.
I'll try the debugging idea, although I know which condition it does to when it doesn't work. Will the debugging also tell me what value is being passed by the "vbulletin->options[postbittype]" variable? Thanks for help! |
#4
|
|||
|
|||
I have narrowed it down to the fact that in some cases the vboption is being passed to the plugin, and in some cases it is not. Now I just need to figure out why it isn't being passed in these cases.
|
#5
|
|||
|
|||
Whoa.... You're hammering your db pretty hard with that. As Dismounted already stated, that's not a good thing.
|
#6
|
|||
|
|||
All these great comments and no solutions. If I could find a decent thread on how to use the showthread_query hook, perhaps I could write it a different way. From what I can from the limited threads I found on that hook, there isn't a way to hook the WHERE and ORDER statements of the query.
Or, if someone could offer a better idea, I am more than willing to recode the hack. But so far, people can only tell me the code sucks and not offer any assistance. |
#7
|
||||
|
||||
You can hook into the WHERE and ORDER by adding to the $postids and $postorder variables using that hook.
|
#8
|
|||
|
|||
Thanks Lynne. I will look into that and see what I can come up with. Like I said, there are only a limited number of threads (that I can find in numerous searches) that discuss the showthread_query hook, and it is usually just a single post that doesn't go into very good discussion on how exactly the hook works. I have tried numerous times to use the hook, and have never been successful with it.
|
#9
|
||||
|
||||
Well, this is an example from a showthread_query plugin I have on my site. I don't add to the two variables I mentioned though.
PHP Code:
|
#10
|
||||
|
||||
Lynne, you may want to use concatenation there - to prevent overwrites.
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|