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?

DPSR 08-26-2006 09:43 AM

Thanks buddy for the hack, i think i can make a good use of it ;)

*installed

apdcanari 08-26-2006 10:09 AM

The last 5 threads with replys ?

C?dric :rolleyes:

harmor19 08-26-2006 10:10 AM

Quote:

Originally Posted by apdcanari
The last 5 threads with replys ?

C?dric :rolleyes:

Do you want all the replies or the just the first post from each new thread?
I hope it's the latter.

SnickersTK 08-26-2006 12:37 PM

Quote:

This hack adds a drop down menu underneath your navbar.
When someone selects a value it'll load a table with the contents you put in it (without reloading the page).
Screenshot of how this would look with one of your hack examples, please?

harmor19 08-26-2006 02:16 PM

Quote:

Originally Posted by SnickersTK
Screenshot of how this would look with one of your hack examples, please?

Why? Read the block and your question will be answered

DPSR 08-26-2006 02:32 PM

Thanks harmor19 beautiful hack, i am using fo rthe purpose i want ;)

But can you please resolve this issue:
Code:

(1 queries for uncached templates)
 Uncached templates: custom_messages (1)

Microstats plugin is showing this :(

Barakat 08-26-2006 03:02 PM

from where can i add messeges ?

Kirk Y 08-26-2006 03:25 PM

Quote:

Originally Posted by DPSR
Thanks harmor19 beautiful hack, i am using fo rthe purpose i want ;)

But can you please resolve this issue:
Code:

(1 queries for uncached templates)
 Uncached templates: custom_messages (1)

Microstats plugin is showing this :(

Make a new plugin in 'cache_templates' with this:
PHP Code:

$globaltemplates[]  = 'custom_messages'


apdcanari 08-26-2006 03:28 PM

Quote:

Originally Posted by harmor19
Do you want all the replies or the just the first post from each new thread?
I hope it's the latter.

Last reply, possible ?

Thanks,

C?dric ;)

harmor19 08-26-2006 03:43 PM

Quote:

Originally Posted by apdcanari
Last reply, possible ?

Thanks,

C?dric ;)

Ok. Once I get back I'll get started.

DPSR 08-26-2006 03:51 PM

Quote:

Originally Posted by acidburn0520
Make a new plugin in 'cache_templates' with this:
PHP Code:

$globaltemplates[]  = 'custom_messages'


Thanks buddy :)

harmor19 08-26-2006 07:01 PM

Sorry about the uncached template. It'll be fix in the next release.

therocks 08-26-2006 11:21 PM

Quote:

Originally Posted by Barakat
from where can i add messeges ?

i was wondering this too... i created the new hook (ajax_drop_menu_start) but it's not showing up in the dropdown...

harmor19 08-26-2006 11:58 PM

Quote:

Originally Posted by therocks
i was wondering this too... i created the new hook (ajax_drop_menu_start) but it's not showing up in the dropdown...

Can you explain what you've done?

therocks 08-27-2006 12:50 AM

Quote:

Originally Posted by harmor19
Can you explain what you've done?

i went into my plugin manager and added a plugin under ajax_drop_menu_start. i used the code from one of your examples to show the last 5 threads from a specific forum as the plugin PHP code and made sure that the plugin is set to active.. for the execution order i put 1, it was at 5 by default..

is that all you need to do to add something into the dropdown menu or am i missing something??

heres a screenshot..
http://img84.imageshack.us/img84/3808/1si7.png

harmor19 08-27-2006 12:56 AM

I can barely see it.
You don't need to [you] tag. It already has [username] which does the same thing.

therocks 08-27-2006 12:59 AM

Quote:

Originally Posted by harmor19
I can barely see it.
You don't need to [you] tag. It already has [username] which does the same thing.

Not sure what you're talking about... I just copied and pasted the code from your example.. changing only the forumid to pull the new threads from... nothing's showing up in the dropdown menu... just the "Select Message".. so is this the only step you need to take to make a new drop down menu selection or am I missing something?

this is the code from the screenshot:
PHP Code:

$getthreads $db->query_read("SELECT * FROM thread WHERE forumid='23' ORDER BY threadid DESC LIMIT 10");    
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']); 


harmor19 08-27-2006 01:03 AM

Quote:

Originally Posted by therocks
Not sure what you're talking about... I just copied and pasted the code from your example.. changing only the forumid to pull the new threads from... nothing's showing up in the dropdown menu... just the "Select Message".. so is this the only step you need to take to make a new drop down menu selection or am I missing something?

You posted up a screen shot where it looks like you were trying to use the the [you] tag.

Go to Admin CP --> Custom Messages --> [Add] or [Modify]
In the text area use [latestthreads]

therocks 08-27-2006 01:10 AM

Quote:

Originally Posted by harmor19
You posted up a screen shot where it looks like you were trying to use the the [you] tag.

Go to Admin CP --> Custom Messages --> [Add] or [Modify]
In the text area use [latestthreads]

ok i did that... it's now showing in the drop down menu.. however, when i select it i get this:

Code:

Database error in vBulletin 3.6.0:

Invalid SQL:
SELECT * FROM custom_messages WHERE display_order='1';

MySQL Error  : Table '*****.custom_messages' doesn't exist
Error Number : 1146
Date        : Saturday, August 26th 2006 @ 07:09:37 PM
Script      : http://******.com/boards/custom_messages.php?display_order=1
Referrer    :
IP Address  : *******
Username    : therocks
Classname    : vb_database


Kirk Y 08-27-2006 01:14 AM

You forgot to add table prefixes Harmor. ;)

I do that all the time too, lol. :p

harmor19 08-27-2006 01:15 AM

I see what I did wrong. I forgot to add " . TABLE_PREFIX . " to the query.
I'll reupload the hack in a minute.

Edit: acidburn beat me to it.

Kirk Y 08-27-2006 01:18 AM

Yay... do I win anything? :)

harmor19 08-27-2006 01:30 AM

therocks,
Download the hack and overwrite "custom_messages.php".
Import the product and select "Allow Overwrite".

acidburn,
You get a reply from me.

Kirk Y 08-27-2006 01:34 AM

Well, I guess that's good enough.

Barakat 08-27-2006 03:16 AM

wow , now it works thanks

gothicuser 08-27-2006 03:19 AM

Really nice mod, thanks :D

Barakat 08-27-2006 03:24 AM

u need a delete option for the messeges also !!1

harmor19 08-27-2006 03:31 AM

Quote:

Originally Posted by Barakat
u need a delete option for the messeges also !!1

I know. I tried making one (it's commented out on the admin file) but I need to come up with some algorithm.
If you create three messages then go into the database and delete the second one the drop down menu doesn't work properly.
In the database change the last entry's display_order from "3" to "2" and it works fine.

SnickersTK 08-27-2006 08:07 PM

Quote:

Originally Posted by harmor19
Why? Read the block and your question will be answered

I want to see how the table would look like under the bar, please.
Sorry, I am very confused and need visual guidance to understand this thing fully. :confused:

harmor19 08-27-2006 08:19 PM

I cannot show you in a screen shot. You can view it in action here
you'll see a drop down menu with the text "Select Message".


All times are GMT. The time now is 08:04 PM.

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.01465 seconds
  • Memory Usage 1,861KB
  • 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
  • (3)bbcode_code_printable
  • (7)bbcode_php_printable
  • (19)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)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