Change friendly time format

How would I change the "posted 1234 Days ago", to "posted on Dec 20, 2011" on Elgg 1.8? Thanks

  • I get "Parse error: syntax error, unexpected T_IF in /home6/xxx/public_html/mod/friendlytime/start.php on line 11"

  • whenever you get an unexpected T_* always look at the line right before it.  You're usually missing a semi-colon or something.

    Is your code exactly what I posted, if not post it here if you can't find what's wrong.

  • I get a white page now

    <?php

    elgg_register_event_handler('init', 'system', 'friendlytime_init');

    function friendlytime_init() {

    elgg_register_plugin_hook_handler('format', 'friendly:time', 'friendlytime_hook_handler');

    }

    function friendlytime_hook_handler($hook, $type, $return, $params) {
      if($params['time'] > (time() - 60*60*48)){
        // this time is within the last 48 hours, so return the default value
        return $return;
      }
    // everything below this happened longer than 2 days ago, so return a date & time

    $old_time = $params['time'];

    $mdy = date("M j, Y", $old_time);
    $hm = date("g:ia", $old_time);

    $new_time_readable = elgg_echo('friendly_time', array($mdy, $hm));

    return $new_time_readable;

    }

  • this is wrong --
    $new_time_readable = elgg_echo('friendly_time', array($mdy, $hm));
    read here -- http://php.net/manual/en/language.types.array.php to learn how to correct it.

  • Hi, I also have the same problem implementing different time format. Help will be much appreciated.image

  • Hi Keiooz,

    I'm going to upload the plugin this weekend, as of now it only changes the friendlytime to "Dec 27, 2011 at 8:01pm. Haven't correctly implemented the "just now", "earlier today", etc.

  • @Dhrup - What's wrong with array($mdy, $hm)? It should be equivalent to array(0 => $mdy, 1 => $hm)

    Anyway, Chris - white page means php error - what do your logs say now?

  • @Matt -- nuffink wrong ;-oO I was reading that line + friendlyTime() call at the same time ! lolz ;-O sorry ;)

  • The error I am getting is [28-Dec-2011 09:18:32] PHP Parse error: syntax error, unexpected T_IF in /home6/xxx/public_html/mod/friendlytime/start.php on line 12

    My start.php is posted above. Not sure what the problem could be, thanks

  • ran the code from above thru my php syntax checker...

    1st run with start.php as-is ==>

    Src_File = (C:/xampp/htdocs/FriendlyTime2.php)
    Call PHP Syntax Checker::
    ::ShellExec::C:/xampp/php/php.exe -l C:/xampp/htdocs/FriendlyTime2.php > php_syntax_check_1.php.log]::
    ::EOF::
    No syntax errors detected in C:/xampp/htdocs/FriendlyTime2.php

    2nd run with start.php deliberately changed to introduce 1 error ==>

    Src_File = (C:/xampp/htdocs/FriendlyTime2.php)
    Call PHP Syntax Checker::
    ::ShellExec::C:/xampp/php/php.exe -l C:/xampp/htdocs/FriendlyTime2.php > php_syntax_check_1.php.log]::
    ::EOF::
    Errors parsing C:/xampp/htdocs/FriendlyTime2.php

     

Feedback and Planning

Feedback and Planning

Discussions about the past, present, and future of Elgg and this community site.