Decode post_time

Discussion forum for MOD Writers regarding MOD Development.
Locked
mannyotr
Registered User
Posts: 54
Joined: Wed Dec 07, 2005 2:21 pm

Decode post_time

Post by mannyotr »

Please help!!

I have searched and searched but can't find the equivalent of this in phpbb3. This is from the phpbb2 mod writers forum...
drathbun wrote:The function in phpBB is called create_date(), and looks like this:

Code: Select all

$topic_post_time = create_date($board_config['default_dateformat'], $topic_data[$i]['post_time'], $board_config['board_timezone']);
That includes the timezone offset. The function is located in ./includes/functions.php.
I am looking to do the same exact thing in phpbb3 RC2. Also taking into account the user's timezone offset.

User avatar
Creomire
Registered User
Posts: 174
Joined: Thu May 31, 2007 4:27 pm
Location: Bonnie Scotland
Contact:

Re: Decode post_time

Post by Creomire »

mannyotr wrote:Please help!!

I have searched and searched but can't find the equivalent of this in phpbb3. This is from the phpbb2 mod writers forum...
drathbun wrote:The function in phpBB is called create_date(), and looks like this:

Code: Select all

$topic_post_time = create_date($board_config['default_dateformat'], $topic_data[$i]['post_time'], $board_config['board_timezone']);
That includes the timezone offset. The function is located in ./includes/functions.php.
I am looking to do the same exact thing in phpbb3 RC2. Also taking into account the user's timezone offset.

Code: Select all

$topic_post_time = $user->format_date($topic_data[$i]['post_time']);

mannyotr
Registered User
Posts: 54
Joined: Wed Dec 07, 2005 2:21 pm

Re: Decode post_time

Post by mannyotr »

Creomire wrote:

Code: Select all

$topic_post_time = $user->format_date($topic_data[$i]['post_time']);[code]
[/code]
I tried that but it didn't work. Got this error...

[phpBB Debug] PHP Notice: in file /includes/session.php on line 1666: strtr() [function.strtr]: The second argument is not an array.

I should clarify that I am doing on a standalone webpage. See the code below.

I have modified this to include only the pertinent code...

Code: Select all

  <?php

    define('IN_PHPBB', true);
    $phpbb_root_path = 'phpBB/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.'.$phpEx);

    $sql = "select pp.post_time
              from phpbb3_posts pp
             limit 0, 5";

    $recentposts = $db->sql_query($sql);

    while ($posts = $db->sql_fetchrow($recentposts)) {

       $topic_post_time = $user->format_date($posts['post_time']);

       print "$topic_post_time<br />";

    }  // end while

  ?>
So am I maybe missing an include of some file that needs to be included?

User avatar
poyntesm
Registered User
Posts: 1671
Joined: Tue Jan 18, 2005 11:19 am
Location: Dublin, Ireland
Contact:

Re: Decode post_time

Post by poyntesm »

You are not setting up the page correctly. Add this after you include common.php. You need to setup the session and user data.

Code: Select all

$user->session_begin();
$auth->acl($user->data);
$user->setup();

User avatar
Creomire
Registered User
Posts: 174
Joined: Thu May 31, 2007 4:27 pm
Location: Bonnie Scotland
Contact:

Re: Decode post_time

Post by Creomire »

mannyotr wrote:
Creomire wrote:

Code: Select all

$topic_post_time = $user->format_date($topic_data[$i]['post_time']);[code]
[/code]
I tried that but it didn't work. Got this error...

[phpBB Debug] PHP Notice: in file /includes/session.php on line 1666: strtr() [function.strtr]: The second argument is not an array.

I should clarify that I am doing on a standalone webpage. See the code below.

I have modified this to include only the pertinent code...

Code: Select all

  <?php

    define('IN_PHPBB', true);
    $phpbb_root_path = 'phpBB/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.'.$phpEx);

    $sql = "select pp.post_time
              from phpbb3_posts pp
             limit 0, 5";

    $recentposts = $db->sql_query($sql);

    while ($posts = $db->sql_fetchrow($recentposts)) {

       $topic_post_time = $user->format_date($posts['post_time']);

       print "$topic_post_time<br />";

    }  // end while

  ?>
So am I maybe missing an include of some file that needs to be included?
You are looking to allow for the user's timezone, but to do this you must start a new session and set up the user's preferences.

AFTER

Code: Select all

include($phpbb_root_path . 'common.'.$phpEx);
ADD

Code: Select all

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

mannyotr
Registered User
Posts: 54
Joined: Wed Dec 07, 2005 2:21 pm

Re: Decode post_time

Post by mannyotr »

Creomire wrote:AFTER

Code: Select all

include($phpbb_root_path . 'common.'.$phpEx);
ADD

Code: Select all

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
Excellent! It works perfectly now! Thanks!

mannyotr
Registered User
Posts: 54
Joined: Wed Dec 07, 2005 2:21 pm

Re: Decode post_time

Post by mannyotr »

So it turns out that this did not work as well as I expected.

I am using the code above in a page (call it a main page) where users first come to my website. From there they click on over to the forum. The code is used to display a simple list of the last 5 posts made, and the time they were posted.

if you are coming to the website or for the first time, the code displays an error. But if you navigate over to the forum and then back to the main page, the error is gone. Almost like simply displaying the forums populates some variable needed for the code to work on the main page.

Any ideas?

User avatar
Creomire
Registered User
Posts: 174
Joined: Thu May 31, 2007 4:27 pm
Location: Bonnie Scotland
Contact:

Re: Decode post_time

Post by Creomire »

mannyotr wrote:So it turns out that this did not work as well as I expected.

I am using the code above in a page (call it a main page) where users first come to my website. From there they click on over to the forum. The code is used to display a simple list of the last 5 posts made, and the time they were posted.

if you are coming to the website or for the first time, the code displays an error. But if you navigate over to the forum and then back to the main page, the error is gone. Almost like simply displaying the forums populates some variable needed for the code to work on the main page.

Any ideas?
Could you post the error?

Locked

Return to “[3.0.x] MOD Writers Discussion”