murklinstest (murklinstest) wrote,
murklinstest
murklinstest

Flexible Squares: GMT in entries

Sometimes it's useful to know the exact time a post was made to LJ, especially on your flist. Here's a snippet of code to show the date & time in GMT that the server recorded when the post was made.

1. Make sure you have created a theme layer.

2. If you don't have a function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor) in your theme layer yet, go to the Flexible Squares source, find the function, and copy it to your theme layer.

3. Add the two segments of blue code below to your theme layer's print_entry function:
function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor)
{
    """<a name="$e.journal.username$e.itemid"></a>""";
    $e->print_linkbar();


    # Userpic

    var string userpic = "";
    if ($*show_entry_userpic)
    {
        if ($p.view == "friends" or $p.view == "entry" or $p.view == "reply")
        {
            if (defined $e.userpic)
                 {
                $userpic = $userpic + """<img src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height"  alt="$e.poster.name" title="$e.poster.name""";
                    if ($e.poster.username != $e.journal.username)
                        {
                            $userpic = $userpic + " in $e.journal.name";
                        }
                    $userpic = $userpic + "\">";
                }
        }
        elseif ($p.journal_type == "C" and $p.view == "recent")
        {
            if (defined $e.userpic)
                 {
                $userpic = $userpic + """<img src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height"  alt="$e.poster.name" title="$e.poster.name" />""";
                }
        }
    else
        {
            if (defined $e.userpic)
                {
                 $userpic = $userpic + """<div class="userpic"><img src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="$e.poster.name" title="$e.poster.name" /></div>""";
                }
    }
    }
    print """
        <div class="subcontent">
        """;
        if (($p.view == "recent" and $p.journal_type != "C" ) or $p.view == "day")
        {
            print """$userpic""";
        }
        else
        {
            if ($p.view == "recent" and $p.journal_type == "C" )
            {
                """<div class="userpicfriends" style="background-color: $*entry_bgcolor;">""";
            }
            else
            {
                """<div class="userpicfriends" style="background-color: $bgcolor;">""";
            }
            print """$userpic""";


    # Poster

            if ($p.view == "friends" or $p.view == "entry" or $p.view == "reply")
            {
                var UserLite linkto;
                $linkto = $e.poster;
                #print "$e.poster.username";
                """<br /><a href=\"""" + $linkto->base_url() + "\">";
                 "<font color=\"$fgcolor\">$linkto.username</font></a>";
            }
            elseif ($p.journal_type == "C" and $p.view == "recent")
            {
                var UserLite linkto;
                $linkto = $e.poster;
                #print "$e.poster.username";
                """<br /><a href=\"""" + $linkto->base_url() + "\">";
                 "$linkto.username</a>";
            }
            if (($p.view == "friends" or $p.view == "entry" or $p.view == "reply") and $e.poster.username != $e.journal.username)
            {
                    var UserLite linkto;
                $linkto = $e.journal;
                """<br />[<a href=\"""" + $linkto->base_url() + "\">";
                 "<font color=\"$fgcolor\">$linkto.username</font></a>]";
            }
            if ($p.view == "recent" and $p.journal_type == "C")
            {
                print "</div>";
            }
            if ($p.view != "recent" and $p.view != "day")
            {
                print """</div>""";
            }
        }



    # Date, time, subject

            # Show the system time in GMT
            var DateTime gmt = $e.system_time;
            var string gmtstr = "";
            if ($p.view == "friends") {
                $gmtstr = """ <span class="gmtdatetiem">[""" + $gmt->date_format("%%mon%%. %%dayord%%") + " " + $gmt->time_format() + " GMT]</span>";
            }

            var string time = "";
            $time = $time + """ @ """;
            $time = $time + $e.time->time_format("short");
            var string date = "";
            $date = $date + $e.time->date_format("long_day");
            """
            <div class="datesubject"><div class="date">""";
                print $e.time->date_format("%%dd%% %%month%% %%yyyy%%");
                "$time $gmtstr
               </div>";
            """
            <div class="subject">""";
                if ($e.security != "")
                {
                    $e.security_icon->print();
                }        
                if ($p.view != "entry") {
                   """<a href="$e.permalink_url">$e.subject</a> &nbsp;""";
                }
                else { print "$e.subject &nbsp;"; }
            """</div>
        </div>
        """;

         """
         <div class="entry">
              <div class="entry_text">""";

                        $e->print_text();
                        print "</div> ";

            # Currents

            var string currents ="";
            $e->print_metadata();

            # Comments

            """
            <div class="clear">&nbsp;</div>
            <div class="comments">""";
             if ($p.view != "entry" or $p.view != "reply")
            {
                 $e.comments->print();
            }
            elseif ($e.comments.enabled)
            {
                $e.comments->print_postlink();
            }
            else
            {
                "&nbsp;";
            }
            """
            </div>
        </div>
    </div>

    <div class="separator"></div>
    <div class="clear">&nbsp;</div>""";
}

4. If you only want to show the system datetime in GMT on your Friends Page entries, hit Save & Compile and you're done! If you prefer to have the system datetime show on ALL entries in your journal, go on to step 5.

5. In the first segment of blue code that you added to the print_entry function, find and delete these two highlighted lines:
            # Show the system time in GMT
            var DateTime gmt = $e.system_time;
            var string gmtstr = "";
            if ($p.view == "friends") {
                $gmtstr = """ <span class="gmtdatetime">[""" + $gmt->date_format("%%mon%%. %%dayord%%") + " " + $gmt->time_format() + " GMT]</span>";
            }
Now hit Save & Compile and you're done!
Tags: code:gmt, layout:flexiblesquares
Subscribe

  • Post a new comment

    Error

    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 21 comments