PDA

View Full Version : Mini Mods - [AJAX] Drop Down Message Display / Selector


harmor19
08-25-2006, 10:00 PM
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:
$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 (http://xenweb.net/forums/index.php)

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
$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
$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

$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
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
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
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
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
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
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
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:
(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
Thanks harmor19 beautiful hack, i am using fo rthe purpose i want ;)

But can you please resolve this issue:
(1 queries for uncached templates)
Uncached templates: custom_messages (1)

Microstats plugin is showing this :(

Make a new plugin in 'cache_templates' with this:
$globaltemplates[] = 'custom_messages';

apdcanari
08-26-2006, 03:28 PM
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
Last reply, possible ?

Thanks,

C?dric ;)
Ok. Once I get back I'll get started.

DPSR
08-26-2006, 03:51 PM
Make a new plugin in 'cache_templates' with this:
$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
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
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
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
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:
$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
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
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:

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
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
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 (http://xenweb.net/forums/index.php)
you'll see a drop down menu with the text "Select Message".

therocks
08-27-2006, 08:28 PM
therocks,
Download the hack and overwrite "custom_messages.php".
Import the product and select "Allow Overwrite".

acidburn,
You get a reply from me.
harmor.. replaced custom_messages.php and reinstalled the product with overwrite allowed... now getting this..

Database error in vBulletin 3.6.0:

Invalid SQL:
SELECT * FROM thread WHERE forumid='23' ORDER BY threadid DESC LIMIT 5;

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

thanks for all the help btw :)

Kirk Y
08-27-2006, 08:29 PM
He forgot to add another table prefix. :p

harmor19
08-27-2006, 08:36 PM
harmor.. replaced custom_messages.php and reinstalled the product with overwrite allowed... now getting this..

Database error in vBulletin 3.6.0:

Invalid SQL:
SELECT * FROM thread WHERE forumid='23' ORDER BY threadid DESC LIMIT 5;

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

thanks for all the help btw :)
Use this code
$getthreads = $db->query_read("SELECT * FROM " . TABLE_PREFIX . "thread WHERE forumid='23' 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']);

therocks
08-27-2006, 08:40 PM
working perfectly! thanks harmor!

Snake
08-27-2006, 10:36 PM
Thanks! I'm loving it! :D

harmor19
08-27-2006, 10:55 PM
Thanks! I'm loving it! :D
You could click "Install".

DPSR
09-10-2006, 05:28 PM
Hack is working fine but i wan't to request a small addon-

Can you please guide me how to add a close link to the open window..like when someone open the message from dropdown menu and then he/she click the 'close' of 'collapse' button in the bottom of the window to close it .... intsead of choosing 'Please choose a message' from dropmenu to close the current picture

anyway to do it?

harmor19
09-10-2006, 08:21 PM
Hack is working fine but i wan't to request a small addon-

Can you please guide me how to add a close link to the open window..like when someone open the message from dropdown menu and then he/she click the 'close' of 'collapse' button in the bottom of the window to close it .... intsead of choosing 'Please choose a message' from dropmenu to close the current picture

anyway to do it?
Good idea. I'll get it done and add more features to it soon

DPSR
09-11-2006, 01:57 AM
Good idea. I'll get it done and add more features to it soon
Thanks buddy, i'll be waiting ;)

DPSR
09-14-2006, 04:28 PM
Any update harmor19 on this?

dilbert
09-14-2006, 05:12 PM
Terrific! Thank you.

You mentioned new requests for queries were being accepted.

I have a few addition on my site I'd like to query that last 10 of.

Links
Photos
Reviews
Classifieds
Downloads

What do you kneed to know about these? I can post the table structure for each, but will wait until you ask so as not to make this a huge post.

Many thanks, Cliff

harmor19
09-14-2006, 06:03 PM
Terrific! Thank you.

You mentioned new requests for queries were being accepted.

I have a few addition on my site I'd like to query that last 10 of.

Links
Photos
Reviews
Classifieds
Downloads

What do you kneed to know about these? I can post the table structure for each, but will wait until you ask so as not to make this a huge post.

Many thanks, Cliff
I'll need to know the table structure for all of those.

dilbert
09-14-2006, 07:25 PM
I'll need to know the table structure for all of those. See attached.
I'm sure many others people who use this mod will find these queries useful too.

PhotoPost Products
Classifieds
Reviews
Photos

vBadvanced Product
Links

dilbert
09-15-2006, 03:15 AM
Hmm, many errors on non standard pages.
For instance, I have Photoposts Classified, Reviews, and Photos. On all of those pages I get page can not be found error. The dropdown shows, but no results. Then if I go to the new posts page http://www.bloodbanktalk.com/forum/search.php?do=getnew the drop down is there, but there are no selections.

Uninstalled for now. Hopefully a new version soon?

Snake
09-17-2006, 12:42 PM
Thank you, thank you!

harmor19
10-12-2006, 12:37 AM
If you use this hack I'm interested in what queries you use. I would like to update this and add the most commonly used queries so you won't need to use a plugin.

For those who don't know what I'm talking about read the first post.

DPSR
10-12-2006, 02:01 AM
Good idea. I'll get it done and add more features to it soon

Anyupdat on this buddy ????? :surprised: :surprised:

Sofia
06-04-2007, 07:25 PM
For links in the custom messages, use bbcode [url].

To delete message, now, it's good.

-> hidden queries ok

JohnBee
09-29-2007, 02:52 PM
Nice hack, to bad it doesn't work.

Database error in vBulletin 3.6.8:

Invalid SQL:
SELECT * FROM custom_messages ORDER BY display_order ASC;

MySQL Error : Table 'pdiscdev.custom_messages' doesn't exist
Error Number : 1146
Date : Saturday, September 29th 2007 @ 03:51:08 PM
Script : http://www.mysite.com/forums/index.php
Referrer : http://www.mysite.com/forums/admincp/index.php?do=head
IP Address : 62.123.145.252
Username : JohnBee
Classname : vB_Database

ShadowOne
01-11-2008, 12:24 AM
Sorry if this sounds dumb, but ive read all 3 1/2 pages and still dont understand what this MOD does, or what its used for. Ive looked at the screenies and i dont see what you said is there...:confused: