Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2009, 12:42 AM
wottech wottech is offline
 
Join Date: May 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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>";
       }
    }
}
Any help would be appreciated. It wouldn't be so bad if it didn't work properly on my own site...
Reply With Quote
  #2  
Old 05-01-2009, 05:34 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.)
Reply With Quote
  #3  
Old 05-01-2009, 08:38 AM
wottech wottech is offline
 
Join Date: May 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #4  
Old 05-05-2009, 04:03 PM
wottech wottech is offline
 
Join Date: May 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #5  
Old 05-05-2009, 04:09 PM
Biker_GA Biker_GA is offline
 
Join Date: Oct 2004
Location: Where my hat is
Posts: 829
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Whoa.... You're hammering your db pretty hard with that. As Dismounted already stated, that's not a good thing.
Reply With Quote
  #6  
Old 05-05-2009, 04:43 PM
wottech wottech is offline
 
Join Date: May 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 05-05-2009, 04:49 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You can hook into the WHERE and ORDER by adding to the $postids and $postorder variables using that hook.
Reply With Quote
  #8  
Old 05-05-2009, 04:53 PM
wottech wottech is offline
 
Join Date: May 2006
Posts: 122
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #9  
Old 05-05-2009, 05:54 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$hook_query_fields ",users.downloaded as downloaded, users.uploaded as uploaded";
$hook_query_joins "LEFT JOIN " TABLE_PREFIX "users as users ON(user.userid = users.id)"
In this plugin, I added two new fields to be grabbed in the select statement and then added a join to another table in my database where those fields are from.
Reply With Quote
  #10  
Old 05-06-2009, 06:58 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lynne, you may want to use concatenation there - to prevent overwrites.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:40 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04714 seconds
  • Memory Usage 2,259KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete