SimplePortal
Customization => Custom Coding => Topic started by: KahneFan on February 03, 2009, 02:50:40 AM
-
It would be nice if we could highlite a random member's URL each day by adding a block to our homepage with a random URL pulled from a random member's profile within a set period of time (24 hours).
-
+ Gets a random member id
+ Changes it every 24 hours
+ Does not choose same member following day
+ Caches member name
global $db_prefix, $scripturl, $modSettings;
if (!empty($modSettings['sp_random_member']))
$member = explode(',', $modSettings['sp_random_member']);
if (empty($member) || $member[2] + 86400 < time())
{
$request = db_query("
SELECT ID_MEMBER, realName
FROM {$db_prefix}members" . (!empty($member[0]) ? "
WHERE ID_MEMBER != $member[0]" : "") . "
ORDER BY RAND()
LIMIT 1", __FILE__, __LINE__);
list ($id, $username) = mysql_fetch_row($request);
mysql_free_result($request);
if (empty($id))
return 'No members.';
updateSettings(array(
'sp_random_member' => $id . ',' . $username . ',' . time()
));
}
if (!empty($id) && !empty($username))
$member = array($id, $username);
echo '
<a href="', $scripturl, '?action=profile;u=', $member[0], '" title="', $member[1], '">', $member[1], '</a>';
-
I have not built a php block yet. Would I enter the code just as you have it listed?
-
Yeah, just a create a PHP block and use the codes I gave as the content.
-
When I try it as is, I receive the following error...
Fatal error: Call to undefined function db_query() in .../Sources/SPortal2.php(1863) : eval()'d code on line 8
-
(I hope a 24 hour bump is OK)
BD, any thought on the error?
Thank you for your help so far BTW.
-
The code I gave was for SMF 1.x. I wish you metioned you use SMF 2.x. Use the following codes:
global $smcFunc, $scripturl, $modSettings;
if (!empty($modSettings['sp_random_member']))
$member = explode(',', $modSettings['sp_random_member']);
if (empty($member) || $member[2] + 86400 < time())
{
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name
FROM {db_prefix}members' . (!empty($member[0]) ? '
WHERE id_member != {int:current_member}' : '') . '
ORDER BY RAND()
LIMIT 1',
array(
'current_member' => !empty($member[0]) ? $member[0] : 0,
)
);
list ($id, $username) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if (empty($id))
return 'No members.';
updateSettings(array(
'sp_random_member' => $id . ',' . $username . ',' . time()
));
}
if (!empty($id) && !empty($username))
$member = array($id, $username);
echo '
<a href="', $scripturl, '?action=profile;u=', $member[0], '" title="', $member[1], '">', $member[1], '</a>';
-
I should have mentioned that, sorry. Now the codes out there for both though... right :-[
Again, it worked perfectly, thanks!!!
-
BD, sorry for bugging again. I just realized, that gives a user of the day, it linked to a user profile instead of to a site. I was hoping to have something like...
{linkable-URLtitle} by {deadtext-username}
(the "by {username}" isn't a must, but it would be nice)
If you take a peek at the top left block on my site, you'll see it currently links to a member's profile.
-
I think I see the issue, it's the way I phrased the request. I did say member's URL, but I meant the URL from a member's profile. For instance, if it highlighted me for a day it would say...
I Post You Post (http://ipostyoupost.com) by KahneFan
-
You mean you want to show users' website in that block?
-
Just the link to their site. Since I Post You Post is about helping to promote forums, it would be a way to spotlite a forum of the day. So, no graphics or anything (screenshot), just the link they have listed in their profile.
You know, I just looked at the profile listings here and I don't see the "website" field like I used to see on 1.1.x. In our profiles there is a "Website Title" and "Website URL" field which USED to come together to give a profile line of:
"Website: {linked titled}"
I no longer see that in 2.x, but that was the effect I was looking for was to be able to place that linked title in a box so I could highlight a user's forum each day.
Again, to use me as an example; in my profile I have listed:
Website Title: I Post You Post
Website URL: http://ipostyoupost.com
and I as hoping the block would be able to display
I Post You Post (http://ipostyoupost.com) by KahneFan
-
Sorry for delayed response.
global $smcFunc, $scripturl, $modSettings;
if (!empty($modSettings['sp_random_site']))
$member = explode('~', $modSettings['sp_random_site']);
if (empty($member) || $member[4] + 86400 < time())
{
$request = $smcFunc['db_query']('', '
SELECT id_member, real_name, website_title, website_url
FROM {db_prefix}members
WHERE website_url != {string:empty_string}' . (!empty($member[0]) ? '
AND id_member != {int:current_member}' : '') . '
ORDER BY RAND()
LIMIT 1',
array(
'current_member' => !empty($member[0]) ? $member[0] : 0,
'empty_string' => '',
)
);
list ($id, $username, $title, $url) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
if (empty($id))
{
echo 'No members.';
return;
}
updateSettings(array(
'sp_random_site' => implode('~', array($id, $username, $title, $url, time())),
));
}
if (!empty($id) && !empty($username))
$member = array($id, $username, $title, $url);
echo '
<a href="', $member[3], '">', !empty($member[2]) ? $member[2] : $member[3], '</a> by <a href="', $scripturl, '?action=profile;u=', $member[0], '" title="', $member[1], '">', $member[1], '</a>';
-
Perfect, thanks!
What length of time is that?
-
That code should change the website once a day. Is that what you were refering to?
You can change the '86400' value (in seconds) if you want to change the length of time that a website is shown for. ;)
-
... value (in seconds)...
That's what I was wondering. Thanks :D
-
Is it possible to make the site open in a new window?
-
Certainly, change this code:
echo '
<a href="', $member[3], '">', !empty($member[2]) ? $member[2] : $member[3], '</a> by <a href="', $scripturl, '?action=profile;u=', $member[0], '" title="', $member[1], '">', $member[1], '</a>';
To this:
echo '
<a href="', $member[3], '" target="_blank">', !empty($member[2]) ? $member[2] : $member[3], '</a> by <a href="', $scripturl, '?action=profile;u=', $member[0], '" title="', $member[1], '">', $member[1], '</a>';
-
(to self) DUH!
I should have seen that one. Thanks :D