?

Log in

No account? Create an account
[theme] - [digimultiplex] - [smoothsailing-esque summary] - S2 Layers [entries|archive|friends|userinfo]
S2 Layers

[ website | advanced customization ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Links
[Links:| how to post tags page ]
[affiliated communities| fblayers ]

[theme] - [digimultiplex] - [smoothsailing-esque summary] [Jan. 15th, 2006|04:39 pm]
S2 Layers

s2layers

[kunzite1]
[Tags|, , , , , , , , ]

in response to ravenshrinkery's s2styles post.
# add colons to labels because it's silly to hard-code it in the function
set text_meta_location = "Current Location:";
set text_meta_mood     = "Current Mood:";
set text_meta_music    = "Current Music:";

class MyUtils {
  function entrylite_make_comment_count(EntryLite el)       : string;
  function entrylite_make_icon         (EntryLite el)       : string;
  function entrylite_make_id           (EntryLite el)       : string;
  function lang_user_wrote_summary     (EntryLite e )       : string;
  function num_comments_in_thread      (Comment[] comments) : int;
}

# make icon string for comments/entries
function MyUtils::entrylite_make_icon(EntryLite el) : string {

  # if this is a Comment
  if($el isa Comment) {
    # return subject icon string, if it exists
    var Comment c = $el as Comment;
    return (defined $c.subject_icon) ? $c.subject_icon->as_string() : "";
  }

  # if this is an Entry
  if($el isa Entry) {
    # return security icon string, if it exits
    var Entry e = $el as Entry;
    return (defined $e.security_icon) ? $e.security_icon->as_string() : "";
  }
  return "";
}

# make id string for comments/entries
function MyUtils::entrylite_make_id(EntryLite el) : string {

  # if this is a Comment
  if($el isa Comment) {
    # "t" [talkid]
    var Comment c = $el as Comment;
    return "t" + $c.talkid;
  }

  # if this is an Entry
  if($el isa Entry) {
    # [journal username][itemid number]
    var Entry e = $el as Entry;
    return "$e.journal.username$e.itemid";
  }
  return "";
}

# make comment count string for comments/entries
function MyUtils::entrylite_make_comment_count(EntryLite el) : string {
  var string return = "";

  # if this is a Comment
  if($el isa Comment) {
    var Comment c = $el as Comment;

    # if the comment has replies, get the number of comments in this thread
    if(size $c.replies) {
      $return = "[+" + $this->num_comments_in_thread($c.replies) + "]";
    }
  }

  # if this is an Entry
  if($el isa Entry) {
    var Entry e = $el as Entry;

    # if there are comments present or screened comments, get number of comments on entry
    if(($e.comments.count > 0) or $e.comments.screened) {
      $return = "[+$e.comments.count]";
    }
  }
  return $return;
}

function MyUtils::num_comments_in_thread (Comment[] comments)  : int {
  var int total = 0;
  foreach var Comment c ($comments) {
    $total = $total + 1;
    if (size $c.replies > 0) {
      $total = $total + $this->num_comments_in_thread($c.replies);
    }
  }
  return $total;
}

# Returns text describing that the user wrote something, for use in summary navbar box. i18nc layers should override this.
function MyUtils::lang_user_wrote_summary(EntryLite e) : string "Returns text describing that the user wrote something, for use in summary navbar box. i18nc layers should override this." {
  # get poster, journal, icon, subject, id, comment count
  var UserLite poster      = $e.poster;
  var UserLite journal     = $e.journal;
  var string   icon        = $this->entrylite_make_icon($e);
  var string   subject     = $e.subject != "" ? $e->get_plain_subject() : """<i class="nosubject">$*text_nosubject</i>""";
  var string   id          = $this->entrylite_make_id($e);
  var string   comments    = $this->entrylite_make_comment_count($e);

  # get page handle
  var Page     p           = get_page();

  var bool     showjournal = (not $e.poster->equals($e.journal)  and (not $e isa Comment));
  var bool     showposter  = (not $p.journal->equals($e.journal) and ($p.view != "day"));

  var string   return      = "";

  # add icon
  $return = $return + $icon;

  # if we're showing the journal name, add journal name and " - "
  if($showjournal) {
    $return = $return + $journal->as_string() + " - ";
  }

  # if we're showing the poster name or this is a Comment
  if ($showposter or ($e isa Comment)) {

    # if we have a poster, add the poster's name
    # else, add """<i class="noposter">$*text_poster_anonymous</i>"""
    if (defined $poster) {
      $return = $return + $poster->as_string();
    } else {
      $return = $return + """<i class="noposter">$*text_poster_anonymous</i>""";
    }
    $return = $return + " - ";
  }

  if($p.view == "day") {
    $return = $return + $e.time->time_format() + " - ";
  }

  # put it all together
  $return = $return + """<a href="#$id">$subject</a> <a href="$e.permalink_url">$comments</a>""";

  return $return;
}

function Entry::print_metadata() {
  var string tags_header         = "Current Tags"; # text for tags header,    "Current Tags"
  var string tags_joiner         = ":";            # text for tags joiner,    ":"
  var string tags_sep            = ", ";           # text for tags separator, ", "
  var bool   show_edit_tags_link = false;          # set to true if you want edit tags link as tags header

  var string currents_open       = ""; # html for opening of currents container
  var string currents_close      = ""; # html for closing of currents container

  var bool   loc_after_mood      = false;               # set to true to print location after mood
  var bool   vanilla_loc         = false;               # set to true to delinkify location

  # if you need data specific to the meta to be in these strings you'll have to set those individually down further
  # one example is provided with meta_label_open
  var string meta_label_open     = "";               # html for opening of metadata label
  var string meta_label_close    = """</strong> """; # html for closing of metadata label
  var string meta_val_open       = "";               # html for opening of metadata value
  var string meta_val_close      = """<br />""";     # html for closing of metadata value

  var Link   edit_tags           = $this->get_link("edit_tags"); # helper var to see if remote user can edit tags

  if ((size $.metadata > 0) or ((size $.tags > 0) and ($*tags_aware))){
    if($.metadata{"mood"} == "" and $loc_after_mood) {
      # if we're printing loc after mood but we have no mood, set loc_after_mood to false
      $loc_after_mood = false;
    }
    var string currents = "";             # make var for printing
    $currents           = $currents_open; # add opening of currents container

    foreach var string k ($.metadata){  # step thru metadata
      var string text = $k;             # set text to key
      var string val  = $.metadata{$k}; # get val
      if ($k == "mood"){                # if mood, set text to mood property
        $text = $*text_meta_mood;
        if (defined $.mood_icon){       # if we have a mood icon, add it
          var Image i = $.mood_icon;
          $val        = """<img src="$i.url" width="$i.width" height="$i.height" align="middle" alt="$val" title="$val" /> $val""";
        }
      } 
      elseif ($k == "music") {          # if music, set text to music property
        $text = $*text_meta_music;
      } elseif ($k == "location") {     # if location, set text to loc variable
        $text = $*text_meta_location;
        if($vanilla_loc) {              # if vanilla loc, striphtml() it
          $val = striphtml($val);
        }
      }
      if(not ($k == "location" and $loc_after_mood)) {
        # if we're doing loc right now and printing loc after mood, skip it
        # if we're doing loc right now and we're not printing loc after mood, print it now
        # if we're not doing loc right now, print this piece of meta

        # in this layout, each piece of meta gets its own class
        $meta_label_open  = """<div class="current$k"><strong>""";

        # add the meta
        $currents = $currents + """$meta_label_open$text$meta_label_close$meta_val_open$val$meta_val_close""";
      }

      if($k == "mood" and $loc_after_mood) {
        # if we just now did the mood and we're printing loc after mood, print the loc
        $k    = "location";           # set meta key to "location"
        $text = $*text_meta_location; # set text to loc variable
        $val  = $.metadata{$k};       # get val

        # if we have a loc, do stuff
        if($val != "") {

          # if vanilla loc, striphtml() it
          if($vanilla_loc) {
            $val = striphtml($val);
          }

          # in this layout, each piece of meta gets its own class
          $meta_label_open  = """<div class="current$k"><strong>""";

          # add the meta
          $currents         = $currents + """$meta_label_open$text$meta_label_close$meta_val_open$val$meta_val_close""";
        }
      }
    }
    if ((size $.tags > 0) and $*tags_aware) {
      var string k      = "tags"; # set key to "tags"

      # in this layout, each piece of meta gets its own class
      $meta_label_open  = """<div class="current$k"><strong>""";

      var int tcount = 0; # set counter for tags
      if($edit_tags.url != "" and $show_edit_tags_link) { # if remote user can edit tags, let's give them a link
        $tags_header = """<a href="$edit_tags.url">$tags_header</a>""";
      }

      # add text, open val container
      $currents = $currents + """$meta_label_open$tags_header$tags_joiner$meta_label_close$meta_val_open""";

      # build tag list
      foreach var Tag t ($.tags) {
        $currents = $currents + """<a rel="tag" href="$t.url">$t.name</a>""";
        $tcount++;

        # if we haven't hit the last tag, add a separator
        if ($tcount != size $.tags) { $currents = $currents + $tags_sep; }
      }

      # close val container
      $currents = $currents + $meta_val_close;
    }

    # close currents container
    $currents = $currents + $currents_close;

    # print currents
    println "$currents";
  }
}

function print_entry_short (Page p, Entry e, Color bgcolor, Color fgcolor) {
  var string subject  = $e.subject ? $e.subject : """<i class="nosubject">$*text_nosubject</i>""";
  var string datetime = $e.time->date_format("med") + " @ " + $e.time->time_format();
  """
  <a name="$e.journal.username$e.itemid"></a>
  <table class="short_entry" width="100%">
    <tr>
      <th align="left">
        <a href="$e.permalink_url">&raquo; $subject</a>
      </th>
    </tr>
    <tr>
      <td width="100%" align="left">
        """;
  $e->print_text();
  """<br />
        <span class="short_entry_meta">$datetime""";
  $e.comments->print();
  """
        </span>
      </td>
    </tr>
  </table>""";
}
function print_entry_full (Page p, Entry e, Color bgcolor, Color fgcolor, bool hide_text) {
  """
    <br />
    <a name="$e.journal.username$e.itemid"></a>""";

  var string time = $p.view != "day" ? $e.time->date_format("med") + " @ " : "";
  $time = $time + $e.time->time_format();
  var string subject = $e.subject ? $e.subject : """<i class="nosubject">$*text_nosubject</i>""";
    if ($e.security) {
      $subject = "$e.security_icon $subject";
    }
    if ($subject) {
      $subject = """<span class="subject">$subject</span>""";
    }
    var Link prev; var Link next;
    if ($p.view == "entry") {
      $prev = $e->get_link("nav_prev");
      $next = $e->get_link("nav_next");
    }
    print_heading_bar("$prev $subject", "$time $next");

    """
    <table cellspacing="0" cellpadding="0" class="full_entry">
      <tr>""";

    var bool showjournal = (not $e.poster->equals($e.journal)) or  ($p.view == "friends");
    var bool showposter  = (not $e.poster->equals($e.journal)) and ($p.view == "friends");
    var bool showuserpic = ($*show_entry_userpic and defined $e.userpic);

    if (($showjournal or $showuserpic) and $p.view != "entry") {
      """
        <td valign="top">
          <table cellspacing="0" cellpadding="0" class="full_entry_userpic">
            <tr>
              <td align="center">
                """;
      if ($p.view == "friends") {
        if ($showposter) {
          print $e.poster->as_string() + ", posting in ";
        }
        print $e.journal->as_string() + "<br />";
        if ($showuserpic) {
          """<img src="$e.userpic.url" width="$e.userpic.width" style="color: $fgcolor; background: $bgcolor; border: 2px solid $bgcolor;" height="$e.userpic.height" alt="" align="right" />""";
        }
      } elseif ($showposter) {
        print $e.poster->as_string() + "<br />";
        if (defined $e.userpic) {
          """<img src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="" align="right" />""";
        }
      } elseif (defined $e.userpic and $p.view != "entry") {
        """<img src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="" align="right" />""";
      }
      """
              </td>
            </tr>
          </table>
        </td>""";
    }
    """
        <td valign="top" style="text-align: left; padding: 10px" align="left" width="100%">
          """;
    if (not $hide_text) {
      $e->print_text();
      $e->print_metadata();
    }
   $e.comments->print();
   """
        </td>
      </tr>
    </table>""";
}

function Page::lay_sidebar_view_summary() : string {
  var MyUtils  mu     = new MyUtils;
  var Page     p      = $this;
  var string[] links  = [];
  var string   return = "";

  # If  the Page is a RecentPage
  # Get the Page as a RecentPage
  # Cycle through the entries while tossing them into an array
  if ($p isa RecentPage) {
    var RecentPage rp = $p as RecentPage;
    foreach var Entry e ($rp.entries) {
      $links[size $links] = $mu->lang_user_wrote_summary($e);
    }
  }

  # If  the Page is a YearPage
  # Get the Page as a YearPage
  # Cycle through the entries while tossing them into an array
  if ($p isa YearPage) {
    var YearPage yp = $p as YearPage;
    if($*page_year_sortorder == "reverse") { $yp.months = reverse $yp.months; }
    foreach var YearMonth ym ($yp.months) {
      if($ym.has_entries) {
        $links[size $links] = """<a href="#$ym.year$ym.month">""" + $ym->month_format("long") + """</a>""";
      }
    }
  }

  # If  the Page is a MonthPage
  # Get the Page as a MonthPage
  # Cycle through the entries while tossing them into an array
  if ($p isa MonthPage) {
    var MonthPage mp = $p as MonthPage;
    foreach var MonthDay md ($mp.days) {
      if($md.has_entries) {
        $links[size $links] = """<a href="#$md.day">""" + $md.date->date_format("long") + """</a>""";
      }
    }
  }

  # If  the Page is a DayPage
  # Get the Page as a DayPage
  # Cycle through the entries while tossing them into an array
  if ($p isa DayPage) {
    var DayPage dp = $p as DayPage;
    if($*page_day_sortorder == "reverse") { $dp.entries = reverse $dp.entries; }
    foreach var Entry e ($dp.entries) {
      $links[size $links] = $mu->lang_user_wrote_summary($e);
    }
  }

  # If  the Page is a EntryPage
  # Get the Page as a EntryPage
  # Cycle through the entries while tossing them into an array
  if ($p isa EntryPage) {
    var EntryPage ep = $p as EntryPage;
    foreach var Comment c ($ep.comments) {
      $links[size $links] = $mu->lang_user_wrote_summary($c);
    }
  }

  if (size($links) > 0) {
    foreach var string link ($links) {
      $return = $return + "<tr><td>" + $link + "</td></tr>";
    }
  }

  return $return;
}

function MonthPage::print_body {
  "<form method='post' action='$.redir.url'><center>";
  $.redir->print_hiddens();

  var string selector;
  if (size $.months > 1) {
    $selector = "<select name='redir_key'>\n";
    foreach var MonthEntryInfo mei ($.months) {
      var string sel;
      if ($mei.date.year == $.date.year and $mei.date.month == $.date.month) {
        $sel = " selected='selected'";
      }
      $selector = "$selector<option value='$mei.redir_key'$sel>" + $mei.date->date_format($*lang_fmt_month_long) + "</option>";
    }
    $selector = "$selector</select>\n<input type='submit' value='View' />";
    print_heading_bar("Switch to: $selector");
  }

  "</center></form>\n<dl>";
  foreach var MonthDay d ($.days) {
    if ($d.has_entries) {
      var string id = $d.day + "";
      $id = " id=\"$id\" name=\"$id\"";
      "<dt><a href=\"$d.url\"$id><b>";
      print lang_ordinal($d.day);
      "</b></a></dt>\n<dd>";
      $d->print_subjectlist();
      "</dd>\n";
    }
  }
  "</dl>\n";
}
linkReply

Comments:
[User Picture]From: ravenshrinkery
2006-01-16 04:54 am (UTC)
There is a stray lowercase n in one of the fields that creates an unwanted character in the page summary block. It is located here:

# put it all together
$return = $return + """$subject $comments
n""";

$return = $return + "</td></tr>";
return $return;

Other that that, excellent work and most appreciated! :)
(Reply) (Thread)
[User Picture]From: kunzite1
2006-01-16 07:25 am (UTC)

fixed the 'n.'
it's in MyUtils::lang_user_wrote_summary(EntryLite e).
also removed the <tr><td> and </td></tr> from the same function.

added the the <tr><td> and </td></tr> to Page::lay_sidebar_view_summary().

still need to work on hooking everything together.
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-01-16 11:47 pm (UTC)

added Entry::print_metadata(), print_entry_short(), print_entry_full(), MonthPage::print_body() and edited the references in Page::lay_sidebar_view_summary().
(Reply) (Parent) (Thread)
[User Picture]From: ravenshrinkery
2006-01-17 12:25 am (UTC)
Unless you know of anything missing (I tested it under the main, calendar, and friends views), I didn't spot any bugs as of this point testing it through compiling and using it :).
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-01-17 12:27 am (UTC)

looking good to me.
(Reply) (Parent) (Thread)