PDA

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


harmor19
26 Aug 2006, 06:16
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
26 Aug 2006, 06:17
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
26 Aug 2006, 07:22
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
26 Aug 2006, 07:27
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
26 Aug 2006, 07:29
No. I'll try and improve upon this hack in the next release though.
thanks :)

Kirk Y
26 Aug 2006, 07:54
Interesting idea. What would be the ideal use for this?

harmor19
26 Aug 2006, 08:02
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
26 Aug 2006, 09:06
I've updated my hack. I hope you like it.

harmor19
26 Aug 2006, 09:13
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
26 Aug 2006, 09:32
I am using the first post to post examples. What other examples would you like to see posted?

DPSR
26 Aug 2006, 11:43
Thanks buddy for the hack, i think i can make a good use of it ;)

*installed

apdcanari
26 Aug 2006, 12:09
The last 5 threads with replys ?

CÚdric :rolleyes:

harmor19
26 Aug 2006, 12:10
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
26 Aug 2006, 14:37
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
26 Aug 2006, 16:16
Screenshot of how this would look with one of your hack examples, please?
Why? Read the block and your question will be answered

DPSR
26 Aug 2006, 16:32
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
26 Aug 2006, 17:02
from where can i add messeges ?

Kirk Y
26 Aug 2006, 17:25
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
26 Aug 2006, 17:28
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
26 Aug 2006, 17:43
Last reply, possible ?

Thanks,

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

DPSR
26 Aug 2006, 17:51
Make a new plugin in 'cache_templates' with this:
$globaltemplates[] = 'custom_messages';

Thanks buddy :)

harmor19
26 Aug 2006, 21:01
Sorry about the uncached template. It'll be fix in the next release.

therocks
27 Aug 2006, 01:21
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
27 Aug 2006, 01:58
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
27 Aug 2006, 02:50
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
27 Aug 2006, 02:56
I can barely see it.
You don't need to [you] tag. It already has [username] which does the same thing.

therocks
27 Aug 2006, 02:59
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
27 Aug 2006, 03:03
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
27 Aug 2006, 03:10
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
27 Aug 2006, 03:14
You forgot to add table prefixes Harmor. ;)

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

harmor19
27 Aug 2006, 03:15
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
27 Aug 2006, 03:18
Yay... do I win anything? :)

harmor19
27 Aug 2006, 03:30
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
27 Aug 2006, 03:34
Well, I guess that's good enough.

Barakat
27 Aug 2006, 05:16
wow , now it works thanks

gothicuser
27 Aug 2006, 05:19
Really nice mod, thanks :D

Barakat
27 Aug 2006, 05:24
u need a delete option for the messeges also !!1

harmor19
27 Aug 2006, 05:31
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
27 Aug 2006, 22:07
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
27 Aug 2006, 22:19
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
27 Aug 2006, 22:28
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
27 Aug 2006, 22:29
He forgot to add another table prefix. :p

harmor19
27 Aug 2006, 22:36
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
27 Aug 2006, 22:40
working perfectly! thanks harmor!

Snake
28 Aug 2006, 00:36
Thanks! I'm loving it! :D

harmor19
28 Aug 2006, 00:55
Thanks! I'm loving it! :D
You could click "Install".

DPSR
10 Sep 2006, 19:28
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
10 Sep 2006, 22:21
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
11 Sep 2006, 03:57
Good idea. I'll get it done and add more features to it soon
Thanks buddy, i'll be waiting ;)

DPSR
14 Sep 2006, 18:28
Any update harmor19 on this?

dilbert
14 Sep 2006, 19:12
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
14 Sep 2006, 20:03
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
14 Sep 2006, 21:25
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
15 Sep 2006, 05:15
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
17 Sep 2006, 14:42
Thank you, thank you!

harmor19
12 Oct 2006, 02:37
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
12 Oct 2006, 04:01
Good idea. I'll get it done and add more features to it soon

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

Sofia
04 Jun 2007, 21:25
For links in the custom messages, use bbcode [url].

To delete message, now, it's good.

-> hidden queries ok

JohnBee
29 Sep 2007, 16:52
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
11 Jan 2008, 02:24
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: