Advertisement:

Random Thread Mod

Aloittaja destalk, toukokuu 09, 2007, 09:28:26 AP

« edellinen - seuraava »

destalk

Would it be possible to create a random thread mod?

What I mean is having a link in addition to "Show unread posts since last visit." and "Show new replies to your posts.".

When that link is clicked a user is taken to a random thread.

KGIII

I have asked and looked and am not skilled enough. The responses have mostly been either way over my head or have gone off on me for not considering the permissions and the overhead that a random function would include. (Of course I wanted it as a part of SSI.php but, well, the result's the same I imagine.) I figured I'd let you know that I'd asked - maybe someone can figure out a way to do this.

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

destalk

Lainaus käyttäjältä: KGIII - toukokuu 09, 2007, 02:30:56 IP
I have asked and looked and am not skilled enough. The responses have mostly been either way over my head or have gone off on me for not considering the permissions and the overhead that a random function would include...

Well if it's over your head, then I won't even have the faintest clue. :P

Thanks.

KGIII

I still think it is an excellent idea. *sighs* Now if only someone could make it. :D

My PC Support Forum
Please ask in-thread before PMing
                   SMF Help
                   Visit My Blog

How can we improve the support process?:
http://www.simplemachines.org/community/index.php?topic=163533.0

SMF vs. Godzilla? Who do you think will win?

SlammedDime

#4
Would you want to give weight to more recent threads?  All threads weighted equally?  Would you want options to where it could show a random thread from a given board?  Or depending on which board the user was in, when the link is clicked, it would show a random thread from that board (and likewise from the forum index, it would show a random thread from the entire forum)?  Do you want anything permission based?  X number of posts, or specific user group required for this function?

And not to knock the staff here in any way, shape or form, as I know everyone is only volunteers, but why should anyone bother making mods at this point?  My first mod that I submitted almost a month ago still hasn't been approved, and it wasn't a very detailed mod at that.  I love coding and trying my hand at things that others have difficulty with, but to go unnoticed due to unapproval and lack of communication, it's quite frustrating.
SlammedDime
Former Lead Customizer
BitBucket Projects
GeekStorage.com Hosting
                      My Mods
SimpleSEF
Ajax Quick Reply
Sitemap
more...
                     

Harro

Shouldn't be to difficult to create such a thing.
Most easy way to do this is to generate a random value between the lowsest thread id and the highest.
But 1 problem that I'm not sure about is how to handle deleted threads....
You could look in the database, but I think that it would slow down the forum a lot though.
And by the way, I'm still very very new to php, so it's possible that there are better ways to do it :P

ディン1031

#6
I think it's not difficult, i think i will add a solution for it, it's very simple if i think correct, but i need to look for somehting, because i don't know if smf store this number somewhere, i will tell you later more, after i go home from my office.

Hmmm for this also a check if he allowed to see must be made, but this should not be a problem (I hope so) ;).

Bye
DIN1031
Support only via MOD Thread! NO PM Support!
My Forum: ayu][kult Forum
My Mods: My Small Mod Collection
My Parser: DIN1031's ModParser
Current Info: More away the next days, because i've to much work to do :x

ディン1031

#7
Okay here the easy way to make random thread select. :D
I think this is the fastest way i found for this.

Upload the RandomTopic.php into the source dir

Than change follow think in the index.php of the boarddir
search for

'recent' => array('Recent.php', 'RecentPosts'),


add before


'randomtopic' => array('RandomTopic.php', 'RandomTopic'),


Now you can got to a thread with the boardurl ?action=randomtopic to a random topic :].

I think i will not make a mod for it, i don't know how many user will need this, i think it's more for Tips and Tricks ;) but if someone like to make a mod out of it i've no problems with this.

Bye
DIN1031
Support only via MOD Thread! NO PM Support!
My Forum: ayu][kult Forum
My Mods: My Small Mod Collection
My Parser: DIN1031's ModParser
Current Info: More away the next days, because i've to much work to do :x

ディン1031

#8
Did someone tested it if it work, like it wished? :x

Bye
DIN1031
Support only via MOD Thread! NO PM Support!
My Forum: ayu][kult Forum
My Mods: My Small Mod Collection
My Parser: DIN1031's ModParser
Current Info: More away the next days, because i've to much work to do :x

karlbenson

#9
I just had a look at the code.
Its very inefficient.  (There is a mysql RAND function ;) ) rather having to have it in a loop ;)

Hope you don't mind.  I re-wrote it like this.


<?php
if (!defined('SMF'))
die('Hacking attempt...');

/*
void function randomTopic()
- Redirect to a Random Topic
*/

function RandomTopic() {
global $context$modSettings$db_prefix$user_info;

//Load the Common_Stats
setupThemeContext();

//POINTLESS RUNNING THE SCRIPT IF HAVE 0&#160; TOPICS
if($context['common_stats']['total_topics'] == 0)
{
// IF 1 TOPIC (STILL NEED TO RUN AS WE AREN'T SURE OF THE TOPIC ID (MIGHT NOT BE TOPIC=1.0)
// OR IF MORE THAN 1 TOPIC, PICKS A RANDOM TOPIC USING THE MYSQL RAND FUNCTION
redirectexit();

} else {
// PICK A RANDOM THREAD (UNCOMMENT ANY OF THE LINES TO INCREASE THE SEARCH OPTIONS EG PICK FROM UNREAD ONLY
$request db_query("
SELECT t.ID_TOPIC AS ID_TOPIC
FROM 
{$db_prefix}topics AS t
LEFT JOIN 
{$db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
WHERE 
$user_info[query_see_board]
ORDER BY RAND()
LIMIT 1"
__FILE____LINE__);

list($ID_TOPIC) = mysql_fetch_row($request);

mysql_free_result($request);
}

// IF WE'VE HAVENT FOUND AN ID, THEN WE NEED TO REDIRECT OUT OF HERE
if(empty($ID_TOPIC)) 
redirectexit();

// WE WOUD HAVE REDIRECTED BY NOW IF HADN'T FOUND AN ID/OR HAVE 0 TOPICS
redirectexit('topic='.$ID_TOPIC.'.0');
}

?>



destalk

Thanks folks....

I'm a bit confused now though. What do we have to do to get this to work?

Tanks

This was very usefull to my community - Thanks alot !  :)

comesee


Advertisement: