PDA

View Full Version : Add "S" icon next to Subscribed Threads w/link to view all subscriptions


mvigod
03-01-2002, 10:00 PM
This is my first "released" hack so I can give something back for all the cool hacks I found here.

This one is fairly simple. What it does is put a small icon next to the title in any thread that the user has subscribed to.
The small icon is a clickable link which will take the user to a page where they can view all of their subscriptions.

This requires modifying forumdisplay.php and one template file "forumdisplaybit".
Also you must upload the image icon file to your images directory.

First let's modify the forumdisplay.php file:

Find:

eval("\$forumdisplaybits .= \"".gettemplate('forumdisplaybit')."\";");


And above it put:


//Subscribed thread with S icon hack begin
$show_subscribed=''; // empty variable out for each pass in while loop
$s_iconhack_userid=$bbuserinfo['userid'];
$check_user_subscribed=$DB_site->query_first("SELECT subscribethreadid FROM subscribethread WHERE threadid=$thread[threadid] AND userid='$s_iconhack_userid' LIMIT 1");
$subscribed_id=$check_user_subscribed[subscribethreadid];
if ($subscribed_id>0)
{
$show_subscribed=" <a href=\"member2.php?s=$session[sessionhash]&action=viewsubscription&daysprune=1000\"><img src=\"images/subscribed-icon.gif\" align=\"middle\" width=15 height=15 border=0 alt=\"You are subscribed to this thread. Click to view all subscriptions\"></A> ";
}
//Subscribed Icon Hack End



Now go into the admin cp and change the template forumdisplaybit as follows:

Find:


<td bgcolor="#13486D" align="left" width="70%"><normalfont>$thread[gotonew] $paperclip$thread[movedprefix]$thread[typeprefix]<a href="showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]">$thread[title]</a></normalfont> <smallfont>$thread[pagenav]</smallfont></td>


Change this to:


<td bgcolor="#13486D" align="left" width="70%"><normalfont>$thread[gotonew] $paperclip$thread[movedprefix]$thread[typeprefix]<a href="showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]">$thread[title]</a></normalfont>$show_subscribed <smallfont>$thread[pagenav]</smallfont></td>


Then upload the icon below to your image directory and that's it!

I'll try to upload a demo page in a minute or so.

mvigod
03-02-2002, 07:50 PM
Here is a Screenshot:

Floris
03-02-2002, 08:24 PM
Hey
that idea is really good!!
Thank you for working it out to a full hack :) very nice!
I am not sure if I am going to implement it to my forum, but sure will give it a try on my beta version :)

AndyTSJ
03-02-2002, 10:09 PM
Didn't seem to work for me. Followed the instructions and installed ok, no technical problems or errors showing, just the small icon and link don't show next to the thread.

mvigod
03-02-2002, 10:43 PM
AndyTSJ - Are the threads you are looking at ones you are sure you have yourself subscribed to? It will only show on those threads so if a page has threads but none are subscribed it will not show.

AndyTSJ
03-02-2002, 10:50 PM
Yea, and I deliberately suscribed to a thread to test it and no luck :( The code is all in as you posted it in your instructions so I can't figure out why it won't work.

mvigod
03-02-2002, 11:09 PM
Did you put the code above the line?

eval("\$forumdisplaybits .= \"".gettemplate('forumdisplaybit')."\";");

If it's after it then it won't work.

Also is the variable in the "forumdisplaybit" template and the icon in your image directory?

I tested this on 2.2.1 but it should work in 2.2.2 and even earlier versions without problems.

AndyTSJ
03-02-2002, 11:15 PM
$bgclass = "alt1";
}
//Subscribed thread with S icon hack begin
$show_subscribed=''; // empty variable out for each pass in while loop
$s_iconhack_userid=$bbuserinfo['userid'];
$check_user_subscribed=$DB_site->query_first("SELECT subscribethreadid FROM subscribethread WHERE threadid=$thread[threadid] AND userid='$s_iconhack_userid' LIMIT 1");
$subscribed_id=$check_user_subscribed[subscribethreadid];
if (subscribed_id>0)
{
$show_subscribed=" <a href=\"member2.php?s=$session[sessionhash]&action=viewsubscription&daysprune=1000\"><img src=\"images/subscribed-icon.gif\" align=\"middle\" width=15 height=15 border=0 alt=\"You are subscribed to this thread. Click to view all subscriptions\"></A> ";
}
//Subscribed Icon Hack End
eval("\$forumdisplaybits .= \"".gettemplate('forumdisplaybit')."\";");

}
$DB_site->free_result($threads);

$pagenav = getpagenav($totalthreads,"forumdisplay.php?s=$session

yup, inserted code above the line. Also posted the $show_subscribed in the forumdisplaybit template.

Maybe there is a conflict with another hack already installed.

mvigod
03-03-2002, 12:56 AM
when you pull up the source code for the html on one of the pages which has a thread you susbscribed to does any of the code appear after the thread title on the one you subscribed to?

Your code above looks ok. Try this just to troubleshoot. Change the if statement from

if (subscribed_id>0)

to:

if (0==0)

This will guarantee a true condition. All threads should show up with an S then. Do this quickly to test it if it's on a live board and then undo it fast so all your members don't wonder what all those S's are!

If they show up then we've narrowed the problem down or if something is in the html source next to your thread. Let me know as it should be working.

Gamingforce
03-03-2002, 04:20 AM
I am having the same problem as well. I subscribed to some threads but the S icon does not display. I did a quick test with the if 0==0 statement and all threads displayed the S icon.

AndyTSJ
03-03-2002, 07:46 AM
Same here... worked with "if 0==0", each post had an "S" .... just wished I knew a bit of php cuz this is probably a real easy thing to fix. Love the idea though, definitely not gonna give up on this one....

mvigod
03-03-2002, 12:06 PM
OK...I found the problem...in the if statement I missed the dollar sign ($) when changing over the variable names to make them easier to read

it should be:
if ($subscribed_id>0)



Note the dollar sign before "subscribed_id" now...before it didn't have it on the original post so it never satisfied the condition.

I'll fix the original post so it's updated too.

LMK if it works now...must have been a long day when I missed that one :)

AndyTSJ
03-03-2002, 12:28 PM
http://dynamic3.gamespy.com/~madden/vbulletin/images/it-works.jpg

Works :) Thanks man ! Cool hack.

mvigod
03-03-2002, 12:45 PM
AndyTSJ - Looks like you have a border around the icon there....in the image tag make sure you have "border=0" so it shows up as a round circle unless you wanted it that way with the border for some reason. The original code above does in fact already have the "border=0" reference within the image tag.

AndyTSJ
03-03-2002, 12:58 PM
Yea, just the way I did my graphic as opposed to being a border around the image.

Tim Wheatley
03-03-2002, 01:00 PM
I modified it to show text instead of an icon, but it works like a dream -- thanks! :D

mvigod
03-03-2002, 01:13 PM
I had text originally for this hack too actually but liked the icon look for my site...images convey meaning to the brain faster than reading which is why I changed over to the icon.

If any user wants to substitute text for the icon just replace the <img> tag code with the text they want to see instead.

So if you prefer to use text instead of small "S" icon just replace the piece below from the original code with whatever text you want (i.e. subscribed):

<img src=\"images/subscribed-icon.gif\" align=\"middle\" width=15 height=15 border=0 alt=\"You are subscribed to this thread. Click to view all subscriptions\">

Warez
03-10-2002, 05:15 AM
Hmmm. even with the $ in front, nothing shows up :(.

mvigod
03-10-2002, 02:04 PM
make sure you are looking at a forum which has a thread that you are definitely subscribed to or you won't see the "S". Also be sure you uploaded the small S image to your images folder. Let me know if this works.

GK_ng
03-12-2002, 11:56 AM
as this Hack added a bunch of Queries, I did a redesign of this genious hack:

find:
SELECT $dotuserid $votequery ".iif($foruminfo[allowicons],'icon.title as icontitle,icon.iconpath,','')."
thread.threadid,thread.title,lastpost, forumid,pollid,open,replycount,postusername,postus erid,
lastposter,thread.dateline,views,thread.iconid,not es,thread.visible,sticky,votetotal,attach
FROM thread
".iif($foruminfo[allowicons],'LEFT JOIN icon ON (icon.iconid = thread.iconid)','')."
$dotjoin
WHERE $threadids
ORDER BY sticky DESC, $sortfield $sqlsortorder
");
replace it with
SELECT $dotuserid $votequery ".iif($foruminfo[allowicons],'icon.title as icontitle,icon.iconpath,','')."
thread.threadid,thread.title,lastpost, forumid,pollid,open,replycount,postusername,postus erid,
lastposter,thread.dateline,views,thread.iconid,not es,thread.visible,sticky,votetotal,attach,subscrib ethread.subscribethreadid AS subscribed
FROM thread
LEFT JOIN subscribethread
ON (subscribethread.threadid=thread.threadid AND subscribethread.userid='".$bbuserinfo['userid']."')
".iif($foruminfo[allowicons],'LEFT JOIN icon ON (icon.iconid = thread.iconid)','')."
$dotjoin
WHERE $threadids
ORDER BY sticky DESC, $sortfield $sqlsortorder
");

and then find:
eval("\$forumdisplaybits .= \"".gettemplate('forumdisplaybit')."\";");
and place ABOVE ist:
//Subscribed thread with S icon hack begin
if ($thread[subscribed]) {
$thread[title]="<i>".$thread[title]."</i>";
}
//Subscribed Icon Hack End


Instead of $thread[title]="<i>".$thread[title]."</i>"; you can place whatever you want to do, like $show_subscribed=" <a href=\"member2.php?s=$session[sessionhash]&action=viewsubscription&daysprune=1000\"><img src=\"images/subscribed-icon.gif\" align=\"middle\" width=15 height=15 border=0 alt=\"You are subscribed to this thread. Click to view all subscriptions\"></A> ";
etc pp..


Full Credits to mvigod for the idea and the first release of this hack ...

mvigod
03-12-2002, 12:22 PM
GK-ng,

Good update. I'll test it out and then update to my original if ok w/you. I had tried the single database query similar to how you had it but missed a parameter I think on my "ON" clause which resulted in single threads showing up multiple times in a row on a page as my database query was not correct. Because of this I went the other route of a seperate query.

If your board is not heavily loaded you are just as well off with either version but if your board is more heavily loaded it's wise to save the query as you point out. I fall into the heavy traffic board so I'll be testing out the query and see if I can remember exactly why I couldn't get it just right back then. Thanks for helping out :)

GK_ng
03-12-2002, 01:07 PM
Originally posted by mvigod
Good update. I'll update my original if ok w/you.Thanks ;)

And surely not a problem from my side.

Jawelin
04-19-2002, 01:58 PM
Originally posted by mvigod
GK-ng,

Good update. I'll test it out and then update to my original if ok w/you. I had tried the single database query similar to how you had it but missed a parameter I think on my "ON" clause which resulted in single threads showing up multiple times in a row on a page as my database query was not correct. Because of this I went the other route of a seperate query.
[...]

Hi. Great hack even the variation.
Do you plan to update the original instructions, so long ?
Thanks

Jawelin
04-19-2002, 02:13 PM
Originally posted by GK_ng
as this Hack added a bunch of Queries, I did a redesign of this genious hack:

replace it with
SELECT $dotuserid $votequery ".iif($foruminfo[allowicons],'icon.title as icontitle,icon.iconpath,','')."
thread.threadid,thread.title,lastpost, forumid,pollid,open,replycount,postusername,postus erid,
lastposter,thread.dateline,views,thread.iconid,not es,thread.visible,sticky,votetotal,attach,subscrib ethread.subscribethreadid AS subscribed
FROM thread
LEFT JOIN subscribethread
ON (subscribethread.threadid=thread.threadid AND subscribethread.userid='".$bbuserinfo['userid']."')
".iif($foruminfo[allowicons],'LEFT JOIN icon ON (icon.iconid = thread.iconid)','')."
$dotjoin
WHERE $threadids
ORDER BY sticky DESC, $sortfield $sqlsortorder
");

Full Credits to mvigod for the idea and the first release of this hack ...

Excuse me, GK_ng...
Just something.
Are you sure if inserting such a LEFT JOIN between
thread and subscribethread tables,
the later LEFT JOIN with the icon table
would be run correctly ?

I'm just thinking... what about you ?

Thanks

mvigod
04-19-2002, 03:57 PM
Actually I think I tried the changes Gk-ng made and got an error so I had to change the query...I'll go back and see what I finally ended up with and repost the variation...my original is easiest for a lower volume board and if you really need to optimize by saving a query then the other version I'll post will work...have to go run through the changes I made now...

Jawelin
04-19-2002, 04:13 PM
Thanks.
Hwr. I made it worked simply by moving the
LEFT JOIN subscribethread ON .... just before the WHERE clause.
This way, the entire table BEFORE is left joint with the subscribethread....

Now it works fine... without adding any query to the page (verified by the Nakkid's Hack...)

Thanks again

mvigod
04-19-2002, 04:48 PM
This is the alternate form of this hack which will save the query which can be used. Either one will work fine but for those concerned about queries you may certainly wish to use this variation.

In forumdisplay.php

ADD THIS:

//Subscribed hack begin
unset($show_subscribed); // empty variable out
if ($thread[subscribed])
{
$show_subscribed=" <a href=\"member2.php?s=$session[sessionhash]&action=viewsubscription&daysprune=1000\"><img
src=\"http://www.yourdomain.com/images/subscribed-icon.gif\" align=\"middle\" width=15 height=15 border=0 a
lt=\"You are subscribed to this thread. Click to view all subscriptions\"></A> ";
}
//Subscribed Hack End


BEFORE THIS:

eval("\$forumdisplaybits .= \"".gettemplate('forumdisplaybit')."\";");


Next again in forumdisplay.php


Find:

$threads=$DB_site->query("
SELECT $dotuserid $votequery ".iif($foruminfo[allowicons],'icon.title as icontitle,icon.iconpath,','')."
thread.threadid,thread.title,lastpost, forumid,pollid,open,replycount,postusername,postus erid,
lastposter,thread.dateline,views,thread.iconid,not es,thread.visible,sticky,votetotal,attach
FROM thread
".iif($foruminfo[allowicons],'LEFT JOIN icon ON (icon.iconid = thread.iconid)','')."
$dotjoin
WHERE $threadids
ORDER BY sticky DESC, $sortfield $sqlsortorder
");



Change to:

$threads=$DB_site->query("
SELECT $dotuserid $votequery ".iif($foruminfo[allowicons],'icon.title as icontitle,icon.iconpath,','')."
thread.threadid,thread.title,lastpost, forumid,pollid,open,replycount,postusername,postus erid,
lastposter,thread.dateline,views,thread.iconid,not es,thread.visible,sticky,votetotal,attach,subscrib ethread.subscribethreadid AS subscribed
FROM thread
LEFT JOIN subscribethread ON (subscribethread.threadid=thread.threadid AND subscribethread.userid='".$bbuserinfo['userid']."')
".iif($foruminfo[allowicons],'LEFT JOIN icon ON (icon.iconid = thread.iconid)','')."
$dotjoin
WHERE $threadids
ORDER BY sticky DESC, $sortfield $sqlsortorder
");


Now change the template forumdisplaybit as follows:

Find:

<td bgcolor="#13486D" align="left" width="70%"><normalfont>$thread[gotonew] $paperclip$thread[movedprefix]$thread[typeprefix]<a href="showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]">$thread[title]</a></normalfont> <smallfont>$thread[pagenav]</smallfont></td>

and change to:

<td bgcolor="#13486D" align="left" width="70%"><normalfont>$thread[gotonew] $paperclip$thread[movedprefix]$thread[typeprefix]<a href="showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]">$thread[title]</a></normalfont>$show_subscribed <smallfont>$thread[pagenav]</smallfont></td>


That's all...the users can click the "S" icon (download icon from first post) and view all their subscribed threads as well.

mashby
05-05-2002, 11:37 PM
Installed the original version and it works like a champ. Thank you!

Any chance of getting this to work on Subscribed Forums as well?

mvigod
05-06-2002, 02:45 PM
Mashby,

I'll check into it for you once I get a little time to code it and test..should not be hard to add though.