?

Log in

No account? Create an account
[theme] - [flexisquares] - [metadata class] - 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] - [flexisquares] - [metadata class] [Apr. 1st, 2006|02:15 pm]
S2 Layers

s2layers

[kunzite1]
[Tags|, , , ]

the following is a really complicated mess of functions that i hacked together in hopes of making metadata printing easier. three different examples are provided.
class MyUtils {
  function metadata_text (string   key)                                                                            : string "Set text labels for Metadata";
  function metadata_val  (string   key,  string{} meta, Image icon, bool vanilla_loc, Tag[] tags, string tags_sep) : string "Prepare the value of Metadata based on type";
  function metadata_val  (string   key,  string{} meta, Image icon, Tag[] tags, string tags_sep)                   : string;
  function metadata_val  (string   key,  string{} meta, Image icon, bool vanilla_loc)                              : string;
  function metadata_val  (string   key,  string{} meta, Image icon)                                                : string;
  function metadata_pair (string   key,  string{} meta, Image icon, bool vanilla_loc, Tag[] tags, string tags_sep) : string "Build Metadata text/val pair";
  function metadata_pair (string   key,  string{} meta, Image icon, Tag[] tags, string tags_sep)                   : string;
  function metadata_pair (string   key,  string{} meta, Image icon, bool vanilla_loc)                              : string;
  function metadata_pair (string   key,  string{} meta, Image icon)                                                : string;
  function metadata_pair (string   key,  Tag[]    tags, string tags_sep)                                           : string;
  function print_metadata(string{} meta, Image icon, bool vanilla_loc, Tag[] tags, string tags_sep) "Print Loc/Mood/Music/Tags";
  function print_metadata(string{} meta, Image icon, Tag[] tags, string tags_sep);
}

function MyUtils::metadata_text(string key) : string "Set text labels for Metadata" {
  var string{} metadata_texts = { # set text labels
                                 "location" => $*text_meta_location,
                                 "mood"     => $*text_meta_mood,
                                 "music"    => $*text_meta_music,
                                 "tags"     => "Current Tags:",
                                };
  # if we have a text label, return that
  #  else, return the meta key
  return $metadata_texts{$key} != "" ? $metadata_texts{$key} : $key;
}

function MyUtils::metadata_val(string key, string{} meta, Image icon, bool vanilla_loc, Tag[] tags, string tags_sep) : string "Prepare the value of Metadata based on type" {
  var string return = $meta{$key};          # get val
  if($key == "location" and $vanilla_loc) { # if we're doing loc and we're making it plain, do so
    $return = striphtml($return);
  }

  if($key == "mood" and $icon.url != "") { # if we're doing mood and we have an icon, add it
    $return = """<img src="$icon.url" width="$icon.width" height="$icon.height" alt="$return" title="$return" /> $return""";
  }

  if($key == "tags" and (size($tags) > 0) and $*tags_aware) { # if we're doing tags and the layer code is supposed to do it, do it
    var int tcount = 0;
    foreach var Tag t ($tags) {
      $return = $return + """<a rel="tag" href="$t.url">$t.name</a>""";
      $tcount++;
      if ($tcount != size $tags) { $return = $return + $tags_sep; }
    }
  }

  # return what we put together
  return $return;
}

function MyUtils::metadata_val(string key, string{} meta, Image icon, bool vanilla_loc) : string {
  var Tag[] tags = [];

  # we're printing loc/mood/music, and we have a setting for plain loc
  # send empty tags
  return $this->metadata_val($key, $meta, $icon, $vanilla_loc, $tags, "");
}

function MyUtils::metadata_val(string key, string{} meta, Image icon) : string {
  var Tag[] tags = [];

  # we're printing loc/mood/music, but we don't ahve a setting for plain loc
  # send empty tags
  return $this->metadata_val($key, $meta, $icon, $tags, "");
}

function MyUtils::metadata_pair(string key, string{} meta, Image icon, bool vanilla_loc, Tag[] tags, string tags_sep) : string "Build Metadata text/val pair" {
  var string text   = $this->metadata_text($key);                                              # get text
  var string val    = $this->metadata_val($key, $meta, $icon, $vanilla_loc, $tags, $tags_sep); # get val
  var string return = "";                                                                      # make var for returning

  if($val != "") { # if we have a val, built the text/val pair
    $return = """<div class="current$key"><strong>$text</strong> $val</div>""";
  }

  # return what we put together
  return $return;
}

function MyUtils::metadata_pair(string key, Tag[] tags, string tags_sep) : string {
  var string{} meta = {};
  var Image    icon = new Image;

  # we're printing tags, so, send empty meta, empty icon, and general setting for plain loc
  return $this->metadata_pair($key, $meta, $icon, false, $tags, $tags_sep);
}

function MyUtils::metadata_pair(string key, string{} meta, Image icon, bool vanilla_loc) : string {
  var Tag[] tags = [];

  # we're printing loc/mood/music, so, send empty tags data
  return $this->metadata_pair($key, $meta, $icon, $vanilla_loc, $tags, "");
}

function MyUtils::print_metadata(string{} meta, Image icon, bool vanilla_loc, Tag[] tags, string tags_sep) "Print Loc/Mood/Music/Tags" {
  var string currents       = ""; # make var for printing
  var string currents_open  = """<div class="clear">&nbsp;</div><div class="clear">&nbsp;</div>
	    <div class="currents">"""; # html for opening of currents container
  var string currents_close = """</div>"""; # html for closing of currents container

  $currents = $currents + $currents_open; # add opening of currents container

  var bool loc_after_mood = true;
  if(($meta{"mood"} == "") and $loc_after_mood) {
    $loc_after_mood = false;
  }

  foreach var string key ($meta) { # step thru metadata
    # we need the key, all of the entry metadata, the mood icon, and if we're printing a plain location

    # the blue/active code can be removed to remove the location after mood functionality
    if(not ($key == "location" and $loc_after_mood)) {
    $currents = $currents + $this->metadata_pair($key, $meta, $icon, $vanilla_loc) + "\n";
    }

    if(($key == "mood") and $loc_after_mood) {
      $currents = $currents + $this->metadata_pair("location", $meta, $icon, $vanilla_loc) + "\n";
    }
  }

  # now let's print the tags
  # we need to tell my func's that we're printing tags
  # we also need to send the tags and the tags separator
  $currents = $currents + $this->metadata_pair("tags", $tags, $tags_sep) + "\n";

  $currents = $currents + $currents_close; # add closing of currents container</span>

  # print currents
  print $currents;
}

function MyUtils::print_metadata(string{} meta, Image icon, Tag[] tags, string tags_sep) {
  $this->print_metadata($meta, $icon, false, $tags, $tags_sep);
}

function Entry::print_metadata() {
  var MyUtils mu = new MyUtils;

  $mu->print_metadata($.metadata, $.mood_icon, false, $.tags, ", "); # normal  location
  $mu->print_metadata($.metadata, $.mood_icon, $.tags, ", ");        # normal  location
  $mu->print_metadata($.metadata, $.mood_icon, true, $.tags, ", ");  # vanilla location
}
linkReply