collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 435
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

Author Topic: Random URL Block  (Read 6867 times)

0 Members and 1 Guest are viewing this topic.

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Random URL Block
« 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).
I Post You Post - Forum Owners Helping Forum Owners

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Random URL Block
« Reply #1 on: February 03, 2009, 03:56:44 AM »
+ Gets a random member id
+ Changes it every 24 hours
+ Does not choose same member following day
+ Caches member name

Code: [Select]
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>';
And slowly, you come to realize... It's all as it should be...

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #2 on: February 03, 2009, 03:46:49 PM »
I have not built a php block yet. Would I enter the code just as you have it listed?
I Post You Post - Forum Owners Helping Forum Owners

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Random URL Block
« Reply #3 on: February 04, 2009, 02:37:55 AM »
Yeah, just a create a PHP block and use the codes I gave as the content.
And slowly, you come to realize... It's all as it should be...

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #4 on: February 04, 2009, 10:02:34 AM »
When I try it as is, I receive the following error...

Quote
Fatal error: Call to undefined function db_query() in .../Sources/SPortal2.php(1863) : eval()'d code on line 8
I Post You Post - Forum Owners Helping Forum Owners

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #5 on: February 05, 2009, 04:30:49 PM »
(I hope a 24 hour bump is OK)

BD, any thought on the error?

Thank you for your help so far BTW.
I Post You Post - Forum Owners Helping Forum Owners

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Random URL Block
« Reply #6 on: February 06, 2009, 03:13:35 AM »
The code I gave was for SMF 1.x. I wish you metioned you use SMF 2.x. Use the following codes:

Code: [Select]
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>';
And slowly, you come to realize... It's all as it should be...

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #7 on: February 06, 2009, 03:22:46 AM »
I should have mentioned that, sorry. Now the codes out there for both though... right  :-[

Again, it worked perfectly, thanks!!!
I Post You Post - Forum Owners Helping Forum Owners

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #8 on: February 06, 2009, 03:27:50 AM »
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 Post You Post - Forum Owners Helping Forum Owners

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #9 on: February 06, 2009, 03:34:15 AM »
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 by KahneFan
I Post You Post - Forum Owners Helping Forum Owners

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Random URL Block
« Reply #10 on: February 06, 2009, 03:35:29 AM »
You mean you want to show users' website in that block?
And slowly, you come to realize... It's all as it should be...

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #11 on: February 06, 2009, 03:48:20 AM »
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 by KahneFan

I Post You Post - Forum Owners Helping Forum Owners

Offline [SiNaN]

  • Mr. SimplePortal
  • Developer
  • *
  • Posts: 6782
  • SMF Version: 2.0.15
  • SP Version: 2.3.7
Re: Random URL Block
« Reply #12 on: April 03, 2009, 02:48:53 AM »
Sorry for delayed response.

Code: [Select]
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>';
And slowly, you come to realize... It's all as it should be...

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #13 on: April 03, 2009, 03:35:24 PM »
Perfect, thanks!

What length of time is that?
I Post You Post - Forum Owners Helping Forum Owners

Offline Nathaniel

  • Comrade
  • *
  • Posts: 5203
  • Gender: Male
    • Verbtest.com
  • SMF Version: 2 RC4
  • SP Version: 2.3.3
Re: Random URL Block
« Reply #14 on: April 03, 2009, 08:30:14 PM »
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. ;)
SMF Friend (Former Support Specialist) | SimplePortal DeveloperMy SMF Mods | SimplePortal"Quis custodiet ipsos custodes?" - Who will Guard the Guards?Please don't send me ANY support related PMs. I will just delete them.

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #15 on: April 04, 2009, 01:08:40 AM »
... value (in seconds)...

That's what I was wondering. Thanks :D
I Post You Post - Forum Owners Helping Forum Owners

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #16 on: April 06, 2009, 12:26:01 AM »
Is it possible to make the site open in a new window?
I Post You Post - Forum Owners Helping Forum Owners

Offline Eliana Tamerin

  • Comrade
  • *
  • Posts: 2889
  • Gender: Female
  • SMF Version: 2 RC2
  • SP Version: 2.3.2
Re: Random URL Block
« Reply #17 on: April 06, 2009, 01:04:42 AM »
Certainly, change this code:

Code: [Select]
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:
Code: [Select]
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>';
Ms. Eliana TamerinIt should be painfully obvious by now that I don't respond to support PMs. Don't send me PMs for support. They will be ignored and deleted, post on the Support Boards to get support.

Offline KahneFan

  • Jr. Member
  • **
  • Posts: 83
    • I Post You Post
  • SMF Version: 2 RC1.2
  • SP Version: 2.3.1
Re: Random URL Block
« Reply #18 on: April 06, 2009, 01:18:24 AM »
(to self) DUH!

I should have seen that one. Thanks  :D
I Post You Post - Forum Owners Helping Forum Owners