View Full Version : "Random Post Icon" possible?
Dorign
03-07-2008, 02:54 AM
When posting a new topic and/or replying to a topic, you have the option of selecting an icon. By default, "No Icon" is selected.
I was wondering if there was a simple way to have the "No Icon" renamed to "Random Icon" and have the thread automatically select a random post icon from the posticon folder.
My reasoning is almost none of my users will pick an icon, and if I remove the "No Icon" button, then all the post icons will look the same. It looks ugly on the forum.
Here's an example.
http://www.ev0lnetwork.net/sigs/temp/ewexample.jpg
The only one using post icons is me, so there's only one selected in the image.
Is this possible? How would I go about doing this?
Dorign
03-11-2008, 04:06 AM
Bump
Dismounted
03-11-2008, 05:29 AM
Possible. You'll have to override the setting in newreply and choose an id at random.
GameWizard
03-11-2008, 05:41 AM
Wouldn't it make more sense to just apply a default icon? As if you have a random one selected, it would turn into a mish mash of random colors and shit all over which will look worse than no icons.
Dorign
03-11-2008, 11:43 PM
Wouldn't it make more sense to just apply a default icon? As if you have a random one selected, it would turn into a mish mash of random colors and shit all over which will look worse than no icons.
I disagree. Being as the entire site is monochrome green in the first place, a tiny mesh of 16x16 colorful icons in one column would add enough to capture the eye. I know a lot about colors and how they're used to capture the eye because I majored in Art. Sadly, I didn't major in coding and I have no idea how to get done what I want. :o
GameWizard
03-12-2008, 08:31 AM
Well then it looks like were in the same preticament. Although I am slightly more proficient in coding, but also have a good eye for design. In your case, you'll need a pretty unique script as I have never seen such a thing anywhere else, best of luck. Maybe consider requesting it in the Paid section if you're willing to dish out some cash for it.
sunilvarma
03-13-2008, 03:49 AM
Here's a way to do this. As this involves editing newthread.php, not everyone may like this solution.
Anyways, here's what to do:
(UPDATED) In newthread.php, FIND:
$newpost['iconid'] =& $vbulletin->GPC['iconid'];
REPLACE WITH:
if($vbulletin->GPC['iconid'] != 0){
$newpost['iconid'] =& $vbulletin->GPC['iconid'];
}
else{
$icons_list = array();
$iconids = $db->query_read("SELECT iconid FROM icon");
while($row=mysql_fetch_assoc($iconids)){
array_push($icons_list, $row);
}
$newpost['iconid'] = array_rand($icons_list) + 1;
}
That should do it.
If you want to change the "No icon" text to "Random Icon" just edit the posticons template:
FIND:
$vbphrase[no_icon]
REPLACE WITH:
Random Icon
If anyone can implement this with a plugin, please show me how. And also let me know if the code is efficient.
Dismounted
03-13-2008, 05:32 AM
You can hook a plugin further down the code to overwrite the variable. You also don't really need a query, just do a random number between 1-10 or something.
sunilvarma
03-13-2008, 05:56 AM
if a posticon is deleted its ID is no longer valid right? so i used a query to get all the IDs in the table instead of generating a random number directly.
could you explain a little about hooking a plugin?
Dismounted
03-13-2008, 06:06 AM
Well, you could always make a setting that lets the admin list ids that they want for the random icon. As for the plugin, find a plugin before the post is submitted, but after the varuable has been initialised.
Dorign
03-13-2008, 08:28 PM
Hmm, maybe I did something wrong, but..
Database error in vBulletin 3.6.8:
Invalid SQL:
SELECT iconid FROM icon;
MySQL Error : Table doesn't exist
Error Number : 1146
EDIT: Oh, I got that because I'm a n00b and didn't even read the code. :P Fixed it, and it's working great! Thanks a ton, sunilvarma!
What would be the benefits of waiting for a code that doesn't use a query? A better load time of .002 seconds, or better than that? I don't really notice any slow down, but my server is kinda slow anyway.
--------------- Added 1205449134 at 1205449134 ---------------
Ah, crap, found a bug.
ALL the icons are random. Even if I pick one, it still is a random icon.
sunilvarma
03-14-2008, 04:34 AM
Sorry Dorign, was in a hurry and couldn't really test it.
Now I fixed it and it should work. Just use the updated code in my first post.
Let me know if you have any issues.
Dorign
03-14-2008, 11:02 PM
Worked like a charm. I don't know how many people would use this, but I'd click "Install" if you made it a release. :D
Thank you a million times over!
sunilvarma
03-15-2008, 03:22 AM
I am looking at how to turn this into a plugin and if it materializes I would definitely release it! :)
Dismounted
03-15-2008, 06:08 AM
Just hook into a newthread hook and change the values dynamically.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.