Log in

No account? Create an account
S2 Layers [entries|archive|friends|userinfo]
S2 Layers

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

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

[theme] - [component] - [mood icon to left of metadata] [Dec. 14th, 2005|02:05 pm]
S2 Layers


[Tags|, , ]

in response to xtomxfallsx' comment on my s2layers post.
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     = """<strong>""";   # 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

    if(defined $.mood_icon) {
      var Image i = $.mood_icon;
      $currents = $currents + """<table border="0"><tr><td><img src="$i.url" width="$i.width" height="$i.height" alt="$.metadata{"mood"}" title="$.metadata{"mood"}" /></td><td>""";

    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;
      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

        # 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);

          # 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"

      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>""";

        # 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;

    if(defined $.mood_icon) {
      $currents = $currents + """</td></tr></table>""";

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

    # print currents
    println "$currents";

[User Picture]From: kunzite1
2006-04-03 02:31 pm (UTC)

you're welcome.

it'd be helpful to me if you could confirm that it all works correctly.
(Reply) (Parent) (Thread)
From: leighblack
2006-04-03 02:43 pm (UTC)
It does work correctly. It's all located in the right places and I was able to remove that stupid link to the location. So I'd say it's a success. ;)
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-04-03 02:43 pm (UTC)

kick ass! :D
(Reply) (Parent) (Thread)
From: leighblack
2006-04-03 02:45 pm (UTC)
Thanks again! I was giving myself a headache trying to figure it out on my own.
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-04-03 02:46 pm (UTC)


i tried to make the options easy as the logic down below got all confusing.

i made an even more confusing post here.
(Reply) (Parent) (Thread)
From: leighblack
2006-04-03 02:54 pm (UTC)
I can copy & paste like a rockstar, so this was no problem at all. ;) Plus, it was super easy to understand. On a Monday morning with 2 hours of sleep, I definitely need super easy.
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-04-03 02:56 pm (UTC)

heh. yay for copy/paste skillz like a rockstar. i think that's going to keep my day brightened. even though it's cold and cloudy outside.

thanks. :)

however, i must off to class. k1 actually has a little bit more of a life now! :O
(Reply) (Parent) (Thread)