vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Mini Mods - [AJAX] Drop Down Message Display / Selector (https://vborg.vbsupport.ru/showthread.php?t=124955)

harmor19 08-25-2006 10:00 PM

[AJAX] Drop Down Message Display / Selector
 
File Edits: 0
Template Edits: 2
Difficulty: Easy

Description
This hack adds a drop down menu underneath your navbar.
When someone selects an option it'll load a table with the contents you put in it (without reloading the page).

You can use HTML when you add a new message.

I have added a new hook for the use of replacing text.
I have hardcoded two replacements.

[username] - This will display the username of the user browsing
[userid] - This will display the userid of the user browsing.


F.A.Q.
Q: How can I add my own replacements?
A: Add a new plugin under the hook "ajax_drop_menu_start".
In the Plugin PHP code use this format: $cm['text'] = str_replace("find", "replace", $cm['text']);

Example:
PHP Code:

$cm['text'] = str_replace("[username]"$vbulletin->userinfo['username'], $cm['text']); 

Q: Can I use the hook for other things besides replacing text?
A: Yes. You can use it for almost anything. If you'd like to query the database for the lastest 5 threads and display them in the drop down menu you can.


On the demo you'll see a drop down menu with the text "Select Message".
View The Demo

harmor19 08-26-2006 04:17 AM

Examples of what you can do with the plugin are listed below.
Add the code to the hook "ajax_drop_menu_start"


Example 1
You can have the latest 5 threads from a specific forum
PHP Code:

$getthreads $db->query_read("SELECT * FROM " TABLE_PREFIX "thread WHERE forumid='5' ORDER BY threadid DESC LIMIT 5");    
while(
$lt $db->fetch_array($getthreads))
{
   
$latestthreads .= "Title: <a href='showthread.php?t=$lt[threadid]'>".$lt['title']."</a> | Posted By: <a href='member.php?u=$lt[postuserid]'>".$lt['lastposter']."</a><br />";

}

$cm['text'] = str_replace("[latestthreads]"$latestthreads$cm['text']); 

When you create a new message you can now use [latestthreads] to populate the lastest 5 threads posted in forumid 5.


Example 2
This will display the top five users with the highest post count
PHP Code:

$gettopusers $db->query_read("SELECT * FROM " TABLE_PREFIX "user ORDER BY posts DESC LIMIT 5");    
while(
$gtu $db->fetch_array($gettopusers))
{
   
$topusers.= "<a href='member.php?u=$gtu[userid]'>".$gtu['username']."</a>: $gtu[posts]<br />";

}

$cm['text'] = str_replace("[topusers]"$topusers$cm['text']); 

When you create a new message you can now use [topusers] to populate the results


Example 3
This will display the latest 5 threads in every forum the user can access
PHP Code:

$count 0;
$getposts $db->query_read(
    SELECT DISTINCT thread.title AS title, thread.threadid AS threadid, forum.forumid AS forumid
    FROM " 
TABLE_PREFIX "post AS post 
    LEFT JOIN " 
TABLE_PREFIX "thread AS thread 
    ON post.threadid = thread.threadid
    LEFT JOIN " 
TABLE_PREFIX "forum AS forum
    ON thread.forumid = forum.forumid
    ORDER BY postid DESC"
);     
    while(
$post $db->fetch_array($getposts)) 
    { 
          
        
$forumperms fetch_permissions($post['forumid']); 
        if ((
$forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR ($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads'])) 
        { 
            if(
$count <= 5
            { 
                
$latestthreads2 .= "<b>Title</b>: <a href='showthread.php?t=$post[threadid]'>".$post['title']."</a><br />"
         
            } 
             
        
$count++; 
         
        } 
    } 

$cm['text'] = str_replace("[latestthreads_2]"$latestthreads2$cm['text']); 

Use [latestthreads_2] to populate the results

therocks 08-26-2006 05:22 AM

great mod!! ... would there be a way to pull 5 or 10 of the latest threads from a specific forum into one of those boxes????

harmor19 08-26-2006 05:27 AM

Quote:

Originally Posted by therocks
great mod!! ... would there be a way to pull 5 or 10 of the latest threads from a specific forum into one of those boxes????

No. I'll try and improve upon this hack in the next release though.

therocks 08-26-2006 05:29 AM

Quote:

Originally Posted by harmor19
No. I'll try and improve upon this hack in the next release though.

thanks :)

Kirk Y 08-26-2006 05:54 AM

Interesting idea. What would be the ideal use for this?

harmor19 08-26-2006 06:02 AM

Quote:

Originally Posted by acidburn0520
Interesting idea. What would be the ideal use for this?

I guess if you had a clan site you could list the users in each clan.

harmor19 08-26-2006 07:06 AM

I've updated my hack. I hope you like it.

harmor19 08-26-2006 07:13 AM

Quote:

Originally Posted by therocks
great mod!! ... would there be a way to pull 5 or 10 of the latest threads from a specific forum into one of those boxes????

You can do this on version 1.0.1 now.

If you need help coding the query I can assist you.

harmor19 08-26-2006 07:32 AM

I am using the first post to post examples. What other examples would you like to see posted?


All times are GMT. The time now is 02:11 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02245 seconds
  • Memory Usage 1,765KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (4)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete