The S2 HowTo Journal

Tips, Tricks, and Tutorials for Basic S2 Customization

Previous Entry Share Next Entry
[paid accounts only] [Cuteness Attack] Adding Usericons to the Recent View
howto_user wrote in s2howto
Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

Usericons are disabled by default on the Recent Entries view of Cuteness Attack, so this tutorial covers how to enable them. It will override the print_entry function. This requires the creation of a theme layer. If you already have a theme layer, you will need to edit it and add the code below. If you do not have a theme layer, you will need to create one by following the instructions in the Theme Layer tutorial.

Copy and paste the following code into your theme layer if you do not already have the print_entry code in your theme layer. If you already have this in your theme layer (for example, if you have already customised an aspect of how journal entries are printed using this function) then ignore this step.

# -------------------------------
# display an entry (all views )
# -------------------------------
function print_entry ( Page p, Entry e )
{
        # get date/time
        var string datetime;
        $datetime = $e.time->date_format($*date_format) + " | " + $e.time->time_format($*time_format);

        # get metadata
        var string metadata;
        if ( $e.metadata ) {
                foreach var string k ( $e.metadata ) {
                        var string text = $k;
                        var string val = $e.metadata{$k};
                        if ( $k == "mood" ) {
                                $text = $*text_meta_mood;
                        } elseif ( $k == "music" ) {
                                $text = $*text_meta_music;
                        } elseif ( $k == "location" ) {
                                $text = $*text_meta_location;
                        }
                        if ( $k == "mood" and defined $e.mood_icon ) {
                                var Image i = $e.mood_icon;
                                $val = "<img src=\"$i.url\" width=\"$i.width\" height=\"$i.height\" align=\"absmiddle\" alt=\"$val\" /> $val";
                        }
                        $metadata = "$metadata\n<b>$text:</b> $val<br />";
                }
        }

        # get any extra user info (if posting to community, etc)
        var string poster = "";
        var string userpic = "";
        if ( $p.view == "friends" or $p.journal_type == "C" or $e.poster.username != $e.journal.username ) {
                if ( $e.poster.username != $e.journal.username ) {
                        $poster = "<a class=\"user\" href=\"" + $e.poster->base_url() + "\" title=\"$e.poster.username\">$e.poster.username</a> in <a class=\"comm\" href=\"" + $e.journal->base_url() + "\" title=\"$e.journal.username\" >$e.journal.username</a>";
                } else {
                        $poster =  "<a class=\"user\" href=\"" + $e.poster->base_url() + "\" title=\"$e.poster.username\">$e.poster.username</a>";
                }
                $poster = "<b>posted by:</b> $poster";
                if ( defined $e.userpic ) {
                        $userpic = "<h3 class=\"userpic\"><img border=\"0\" src=\"$e.userpic.url\" width=\"$e.userpic.width\" height=\"$e.userpic.height\" alt=\"$e.journal.username\" /></h3>";
                }
        }
        # print the entry now:
        print "<div id=\"entry_$e.itemid\" class=\"ind-entry\">";

                # print icon (if needed)
                if ( $userpic != "" ) {
                        print "$userpic";       
                }

                print "<h2>";
                if ( $e.security != "" ) {
                        $e.security_icon->print();
                        print " ";
                }
                if ( $e.subject == "" ) {
                        print "<i>$*text_nosubject</i>";
                } else {
                        print "$e.subject";
                }
                print "</h2>";

                print "<h4>";
                if ( $p.view == "entry" and $*show_entrynav_icons ) {
                        var string item_link = "";
                        foreach var string key (["nav_prev","nav_next"]) {
                                var Link link = $e->get_link($key);
                                if ( $link ) { 
                                        if ( $key == "nav_prev" ) {
                                                $item_link = $item_link + "<a href=\"$link.url\" title=\"" + $link.caption->lower() + "\">« " + $link.caption->lower() + "</a> | ";
                                        } elseif ( $key == "nav_next" ) {
                                                $item_link = $item_link + "<a href=\"$link.url\" title=\"" + $link.caption->lower() + "\">" + $link.caption->lower() + " »</a>";
                                        }
                                }
                        }
                        print $item_link;
                        print "<br />";
                }
                print "<b>$datetime</b><br />";
                print "$metadata";
                if ( $poster != "" ) {
                        print "$poster";        
                }
                print "</h4>";

                print "<div class=\"entry-item\">";
                $e->print_text();
                print "</div>\n";

                print "<h4>";
                print safe get_permalink($e.permalink_url);
                if ( $p.view != "entry" and $p.view != "reply" ) {
                        print " | ";
                        $e.comments->print();
                } elseif ( $e.comments.enabled ) {
                        print " | ";
                        $e.comments->print_postlink();
                }
                var Link tmp;
                if ( viewer_is_owner() and $p.view != "friends" ) {
                        $tmp = $e->get_link("edit_entry");
                        print " | <a href=\"$tmp.url\" title=\"$tmp.caption\">$tmp.caption</a>";
                }
                $tmp = $e->get_link("mem_add");
                print " | <a href=\"$tmp.url\" title=\"$tmp.caption\">$tmp.caption</a>";
                print "</h4>";
        print "</div>";
        print "<hr />";
}

Now, locate the } highlighted in orange, and cut and paste it at the end of the line in blue. That line will now read as follows:

                $poster = "<b>posted by:</b> $poster"; } 

Ordinarily, this style checks to see if a journal is not on the Recent view, and if this is true, it prints a userpic and "posted by: exampleusername". This amendment means that the style still checks that it is not the Recent view in order to display "posted by: exampleusername", but displays the userpic regardless of the view.

Compile your layer, and it's ready to use. You will need to apply your theme layer via the Customize interface in order for your changes to take effect.

Additional References:
  • What are the different S2 layer types?
  • Contributed by dandelion.


    Comments Disabled:

    Comments have been disabled for this post.

    ?

    Log in

    No account? Create an account