View Single Post
  #18  
Old 06-28-2009, 07:30 PM
DragonBlade's Avatar
DragonBlade DragonBlade is offline
 
Join Date: May 2006
Posts: 189
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All right, now, Melly. I'll make this simple on ye, but I STILL want you to try to understand the inner workings behind it, m'kay? That way, if vBulletin changes things around, you might have an idea what to do.

First thing's first. We'll use ONLY plugins for this, and no template edits or file edits. That way, if something does go wrong, all you have to do it turn off the plugin, kay? Good.

We'll start by Creating a Product. Load up yer AdminCP, and scroll on down near the bottom. Expand Plugins & Products, and click on Product Manager. Scroll aaaallllllll the way to the bottom and click "Add/Import Product." For the Product ID, just enter "melmaritalthreads" or something. For the Title, put "Mel's Marital Status for Threads." For the version, we'll go with "0.01a". Description, "Some help that wonderful Sarteck using DragonBlade's account gave me!" Ignore the Product and Version Check URLs. Save it.

Yay, you have a Product! Now to make some Plugins for the Product.

Again, under Plugins & Products, click this time "Add New Plugin." For Product, select "Mel's Marital Status for Threads." (The only reason we added that Product, btw, was to organize the plugins. ) For the Hook location, select "forumdisplay_query".

TECHIE NOTE: This is the "location" in the script where the plugin will execute. If you open up your "forumdisplay.php" file, find the line:
PHP Code:
($hook vBulletinHook::fetch_hook('forumdisplay_query')) ? eval($hook) : false
That basically means that this hook will execute in that spot. This is important, because it means we can use the variables already in memory up to that point, and influence some variables that will come later. END TECHIE NOTE.

Now, for the title, enter "Marital Status Thread Query." Leave the execution order at default (5). Now for the important bit--the actual plugin code:
PHP Code:
// Query to check if/what threadowner's marital status is
$marital_status_threadids = array();
$marital_status_threads_query sprintf("SELECT thread.threadid, userfield.field17 AS maritalstatus FROM thread LEFT JOIN userfield ON(thread.postuserid=userfield.userid) WHERE thread.threadid IN (0,%s)"$ids);
$marital_status_threads_result $vbulletin->db->query_read($marital_status_threads_query);
while (
$marital_status_threads_row $vbulletin->db->fetch_array($marital_status_threads_result))
  {
$marital_statis_threadids[$marital_status_threads_row['threadid']] = $marital_status_threads_row['maritalstatus'];} 
What this does is it uses the $ids already gathered by vBulletin for the forumdisplay query, and puts the marital status of the users (assuming that's your field17) into an array with the thread ID as the key.

Leave "Plugin is Active" at no--you'll activate it in a moment. Save the plugin.



All right! Next plugin will be used to display field17 next to each user's name (I'm assuming that's where you want it, right?).

"Add New Plugin" again, select the Mel's Marital Status for Threads. Hook location is now 'threadbit_display'. (Also in the forumdisplay.php, a little further down, if you wanna glance at the PHP file.) Title this one "Marital Status Thread Display," because that's what this one will be doing--displaying the marital status. Leave the execution order at default, again (5).

The code here is relatively simple--we're just going to append the Marital Status onto the end of the postusername value for the thread. :3
PHP Code:
$thread['postusername'] .= $marital_status_threadids[$thread['threadid']]; 
TECHIE NOTE: the " .= " operator basically "concatenates" two strings, meaning it glues one onto the end of the other. END TECHIE NOTE.

Again, leave this off for now, and save it.



Almost done! Now all we need to do is go to the Plugin manager, locate the two plugins we just made, and put checkmarks in the boxes to activate them both. Now go look at your forums, and see if everything went smoothly. If there's some errors, it's liekly a typo in my code somewhere. XP Just deactivate the plugins and tell me what the error is.

If it works out, come back and tell me, too. :3

--------------- Added [DATE]1246227765[/DATE] at [TIME]1246227765[/TIME] ---------------

Quote:
Originally Posted by Mellymonster View Post
Is there a way to have post bit icons like a marital status icon, show up in the description in side the forum area?

I'm not talking about post icons.



That, I want when someone starts a thread, for that icon to appear automatically in the forum area without them having to do anything, is this possible?

Ho ho ho, also, if you didn't want it next to the name, but rather in the first column, change the variable in that second plugin to
PHP Code:
$thread['openclose_editable'
And if you wanted it to the LEFT of the username, try
PHP Code:
$thread['postusername'] = $marital_status_threadids[$thread['threadid']] . $thread['postusername']; 
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02456 seconds
  • Memory Usage 1,805KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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
  • showpost_complete