?

Log in

[theme] - [linkbar/metadata handling] - 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] - [linkbar/metadata handling] [Dec. 5th, 2006|12:25 pm]
S2 Layers

s2layers

[kunzite1]
[Tags|, , , ]

to make sure that these work, make sure that the function that prints entries calls Entry::print_linkbar() and Entry::print_metadata(). also make sure that Entry::print_comment(Comment c) calls Comment::print_linkbar().
function Comment::print_linkbar() {
  var bool     add_links     = false;
  var bool     first_sep     = false;
  var bool     last_sep      = false;
  var string   img_id        = "";
  var string   link_key      = "";
  var string   link_link     = "";
  var string   link_sep      = "";
  var string   print         = "";
  var string[] link_keyseq   = [];
  var string{} link_captions = {};
  var string{} link_images   = {};
  var string{} link_urls     = {};
  var Link     link          = new Link;

  # add a sep before the links?
  $first_sep = true;

  # add a sep after the links?
  $last_sep  = false;

  # define the sep
  $link_sep  = """ <span class="separator">|</span> """;

  # define the link order
  #   comment_reply    : reply to comment
  #   comment_parent   : parent of comment
  #   comment_thread   : comment thread
  #   delete_comment   : delete comment
  #   freeze_thread    : freeze thread
  #   permalink        : permalink of comment
  #   screen_comment   : screen comment
  #   unfreeze_thread  : unfreeze thread
  #   unscreen_comment : unscreen comment
  #   unwatch_thread   : untrack/unwatch thread
  #   watch_thread     : track/watch thread
  #   watching_parent  : tracking/watching parent of comment
  $link_keyseq = [ # comment_reply, comment_parent, comment_thread, permalink, delete_comment, freeze_thread, screen_comment, unscreen_comment, unfreeze_thread, unwatch_thread, watch_thread, watching_parent
                  "comment_reply",
                  "comment_parent",
                  "comment_thread",
                  "permalink",
                  "delete_comment",
                  "freeze_thread",
                  "screen_comment",
                  "unscreen_comment",
                  "unfreeze_thread",
                  "unwatch_thread",
                  "watch_thread",
                  "watching_parent",
                 ];

  # define the link images
  $link_images = {
                  "permalink"        => "http://mike.mm1swebcreations.com/lj/silk/link.png",

                  "nav_prev"         => "http://mike.mm1swebcreations.com/lj/silk/arrow_left.png",
                  "edit_entry"       => "http://mike.mm1swebcreations.com/lj/silk/pencil.png",
                  "edit_tags"        => "http://mike.mm1swebcreations.com/lj/silk/tag_blue_edit.png",
                  "mem_add"          => "http://mike.mm1swebcreations.com/lj/silk/disk.png",
                  "tell_friend"      => "http://mike.mm1swebcreations.com/lj/silk/email_go.png",
                  "watch_comments"   => "http://mike.mm1swebcreations.com/lj/silk/map_add.png",
                  "unwatch_comments" => "http://mike.mm1swebcreations.com/lj/silk/map_delete.png",
                  "nav_next"         => "http://mike.mm1swebcreations.com/lj/silk/arrow_right.png",

                  "comment_frozen"   => "http://mike.mm1swebcreations.com/lj/silk/comment_frozen.png",
                  "comment_parent"   => "http://mike.mm1swebcreations.com/lj/silk/arrow_up.png",
                  "comment_reply"    => "http://mike.mm1swebcreations.com/lj/silk/comment_add.png",
                  "comment_thread"   => "http://mike.mm1swebcreations.com/lj/silk/comment.png",
                  "delete_comment"   => "http://mike.mm1swebcreations.com/lj/silk/cancel.png",
                  "freeze_thread"    => "http://mike.mm1swebcreations.com/lj/silk/lightbulb_off.png",
                  "screen_comment"   => "http://mike.mm1swebcreations.com/lj/silk/eye_cross.png",
                  "unscreen_comment" => "http://mike.mm1swebcreations.com/lj/silk/eye.png",
                  "unfreeze_thread"  => "http://mike.mm1swebcreations.com/lj/silk/lightbulb.png",
                  "unwatch_thread"   => "http://mike.mm1swebcreations.com/lj/silk/map_delete.png",
                  "watch_thread"     => "http://mike.mm1swebcreations.com/lj/silk/map_add.png",
                  "watching_parent"  => "http://mike.mm1swebcreations.com/lj/silk/map_magnify.png",
                 };

  # define permalink data
  $link_key                  = "permalink";
  $link_captions{$link_key}  = $*text_permalink;
  $link_urls{$link_key}      = $.permalink_url;

  # define reply link data
  $link_key                  = "comment_reply";
  $link_captions{$link_key}  = $.frozen ? $*text_comment_frozen : $*text_comment_reply;
  $link_images{$link_key}    = $.frozen ? $link_images{"comment_frozen"} : $link_images{"comment_reply"};
  $link_urls{$link_key}      = $.frozen ? "" : $.reply_url;

  # define parent link data
  $link_key                  = "comment_parent";
  $link_captions{$link_key}  = $*text_comment_parent;
  $link_urls{$link_key}      = $.parent_url;

  # define thread link data
  $link_key                  = "comment_thread";
  $link_captions{$link_key}  = $*text_comment_thread;
  $link_urls{$link_key}      = $.thread_url;

  # if there aren't any links defined in the array, let's add 'em
  $add_links = (size($link_keyseq) < 1);

  # cycle thru links and gather data
  foreach $link_key ($.link_keyseq) {
    $link                            = $this->get_link($link_key);
    $link_captions{$link_key}        = $link_captions{$link_key} != "" ? $link_captions{$link_key} : $link.caption;
    $link_images{$link_key}          = $link_images{$link_key}   != "" ? $link_images{$link_key}   : $link.icon.url;
    $link_urls{$link_key}            = $link_urls{$link_key}     != "" ? $link_urls{$link_key}     : $link.url;

    # if we're adding links
    if($add_links) {
      # add it to the array
      $link_keyseq[size($link_keyseq)] = $link_key;
    }
  }

  # give linkbar a css class
  $print = $print + """<span class="comment-linkbar">""";

  # if we've got links to process
  if(size($link_keyseq) > 0) {
    # if we're adding a first sep
    if($first_sep) {
      # add it
      $print = $print + $link_sep;
    }

    # cycle thru links
    foreach $link_key ($link_keyseq) {
      var bool have_img = $link_images{$link_key} != ""; # do we have an image?
      var bool have_url = $link_urls{$link_key}   != ""; # do we have a url?
      var bool is_reply = $link_key == "comment_reply";  # is this the reply link?

      if($have_url or $is_reply) {                       # if we have a url or it's the reply link
        if($have_url or ($is_reply and not $have_url)) { #   if we have a url, or it's the reply link without a url
          $link_link = $link_captions{$link_key};        #     set the link text
          if($have_img) {                                #     if we have an image
            if($link_key->contains("freeze")) {          #       if it's the [un]freeze link
              $img_id = "fuf";                           #         set img id prefix of "fuf"
            } elseif ($link_key->contains("screen")) {   #       if it's the [un]screen link
              $img_id = "sus";                           #         set img id prefix of "sus"
            } elseif ($link_key->contains("watch")) {    #       if it's the [un]track/watch link
              $img_id = "tut";                           #         set img id prefix of "tut"
            } else {                                     #       else, we're not doing a special image
              $img_id = "";                              #         set img id prefix of nothing
            }

            if($img_id != "") {                          #       if we have an img id prefix
              $img_id = " id=\"${img_id}_${.talkid}\"";  #         set it up
            }

            # add the image
            $link_link = """<img$img_id src="$link_images{$link_key}" alt="$link_link" title="$link_link" border="0" />""";
          }

          # if we have a url, apply it
          if($have_url) {
            $link_link = """<a href="$link_urls{$link_key}">$link_link</a>""";
          }

          # add a link sep
          $print     = $print + $link_link + $link_sep;

        } else {

          # else, we're doing the reply link with a url

          print $print; # print what we've got
          $print = "";  # set print var to nothing

          # create array for QR reply link
          var string{} opts = {};

          # if we have an image
          if($have_img) {
            $opts{"img_url"} = $link_images{$link_key};   # set image url
            $opts{"alt"}     = $link_captions{$link_key}; # set image alt
            $opts{"title"}   = $link_captions{$link_key}; # set image title
          } else {
            # else, we don't have an image
            $opts{"linktext"} = $link_captions{$link_key}; # set linktext
          }

          # set url
          $opts{"reply_url"} = $link_urls{$link_key};

          # print QR reply link
          $this->print_reply_link($opts);

          # add a link sep
          $print = $print + $link_sep;
        }
      }
    }

    # if we don't have a sep on the end
    if(not $last_sep) {
      # hack it off
      $print = $print->substr(0, $print->length() - $link_sep->length());
    }
  }

  # close span
  $print = $print + "</span>";

  # print linkbar
  print $print;

  # print reply container
  $this->print_reply_container();
}

function CommentInfo::print() {
  # define a link sep
  var string link_sep = """ <span class="separator">|</span> """;

  var bool show_readlink = $.show_readlink;                   # are we showing the  link to read   comments?
  var bool show_postlink = $.show_postlink;                   # are we showing the  link to post a comment?
  var bool show_sep      = $show_readlink and $show_postlink; # are we showing both and therefore need a sep?

  # give comment links a css class
  """<span class="entry-commentlinks">""";

  # if we're showing the readlink
  if($show_readlink) {
    # print it
    $this->print_readlink();
  }

  # if we're showing both links
  if($show_sep) {
    # print a sep
    print $link_sep;
  }

  # if we're showing the postlink
  if($show_postlink) {
    # print it
    $this->print_postlink();
  }

  "</span>";
}

function CommentInfo::print_postlink() {
  # get page handle
  var Page   p         = get_page();

  # define image url for postlink
  var string image_url = "http://mike.mm1swebcreations.com/lj/silk/comments_add.png";

  # get postlink url
  var string url       = $.post_url;

  # get postlink text
  var string text      = get_plural_phrase(0, "text_post_comment" + ($p.view == "friends" ? "_friends" : ""));

  # if we've reached max comments
  if($.maxcomments) {
    $url  = "";                  # clear url
    $text = $*text_max_comments; # set max comments text
  }

  # if we have a url
  if($url != "") {
    # open it
    """<a href="$url">""";
  }

  # if we have an image
  if($image_url != "") {
    # print it
    """<img src="$image_url" alt="$text" title="$text" border="0" />""";
  } else {
    # else, print text
    print $text;
  }

  # if we have a url
  if($url != "") {
    # close it
    """</a>""";
  }

}

function CommentInfo::print_readlink() {
  # get page handle
  var Page   p         = get_page();

  # define image url for readlink
  var string image_url = "http://mike.mm1swebcreations.com/lj/silk/comments.png";

  # get readlink url
  var string url       = $.read_url;

  # get readlink text
  var string text      = get_plural_phrase($.count, "text_read_comments" + ($p.view == "friends" ? "_friends" : ""));

  # if we have a url
  if($url != "") {
    # open it
    """<a href="$url">""";
  }

  # if we have an image
  if($image_url != "") {
    # print it
    """<img src="$image_url" alt="$text" title="$text" border="0" />""";
  } else {
    # else, print text
    print $text;
  }

  # if we have a url
  if($url != "") {
    # close it
    """</a>""";
  }

}

function Entry::print_linkbar() {
  var Page     p             = get_page();

  var bool     add_links     = false;
  var bool     first_sep     = false;
  var bool     interentry    = ($p.view == "entry") or ($p.view == "reply");
  var bool     last_sep      = false;
  var string   link_key      = "";
  var string   link_link     = "";
  var string   link_sep      = "";
  var string   print         = "";
  var string[] link_keyseq   = [];
  var string{} link_captions = {};
  var string{} link_images   = {};
  var string{} link_urls     = {};
  var Link     link          = new Link;

  # add a sep before the links?
  $first_sep = true;

  # add a sep after the links?
  $last_sep  = false;

  # define the sep
  $link_sep  = """ <span class="separator">|</span> """;

  # define the link order
  #   edit_entry       : edit entry
  #   edit_tags        : edit tags
  #   mem_add          : add to memories
  #   nav_next         : next entry
  #   nav_prev         : previous entry
  #   permalink        : permalink of entry
  #   tell_friend      : tell a friend
  #   unwatch_comments : untrack/unwatch comments
  #   watch_comments   : track/watch comments
  $link_keyseq = [ # permalink, nav_prev, edit_entry, edit_tags, mem_add, tell_friend, watch_comments, unwatch_comments, nav_next
                  "permalink",
                  "nav_prev",
                  "edit_entry",
                  "edit_tags",
                  "mem_add",
                  "tell_friend",
                  "watch_comments",
                  "unwatch_comments",
                  "nav_next",
                 ];

  # define the link images
  $link_images = {
                  "permalink"        => "http://mike.mm1swebcreations.com/lj/silk/link.png",

                  "nav_prev"         => "http://mike.mm1swebcreations.com/lj/silk/arrow_left.png",
                  "edit_entry"       => "http://mike.mm1swebcreations.com/lj/silk/pencil.png",
                  "edit_tags"        => "http://mike.mm1swebcreations.com/lj/silk/tag_blue_edit.png",
                  "mem_add"          => "http://mike.mm1swebcreations.com/lj/silk/disk.png",
                  "tell_friend"      => "http://mike.mm1swebcreations.com/lj/silk/email_go.png",
                  "watch_comments"   => "http://mike.mm1swebcreations.com/lj/silk/map_add.png",
                  "unwatch_comments" => "http://mike.mm1swebcreations.com/lj/silk/map_delete.png",
                  "nav_next"         => "http://mike.mm1swebcreations.com/lj/silk/arrow_right.png",

                  "comment_parent"   => "http://mike.mm1swebcreations.com/lj/silk/arrow_up.png",
                  "comment_reply"    => "http://mike.mm1swebcreations.com/lj/silk/comment_add.png",
                  "comment_thread"   => "http://mike.mm1swebcreations.com/lj/silk/comment.png",
                  "delete_comment"   => "http://mike.mm1swebcreations.com/lj/silk/cancel.png",
                  "freeze_thread"    => "http://mike.mm1swebcreations.com/lj/silk/lightbulb_off.png",
                  "screen_comment"   => "http://mike.mm1swebcreations.com/lj/silk/eye_cross.png",
                  "unscreen_comment" => "http://mike.mm1swebcreations.com/lj/silk/eye.png",
                  "unfreeze_thread"  => "http://mike.mm1swebcreations.com/lj/silk/lightbulb.png",
                  "unwatch_thread"   => "http://mike.mm1swebcreations.com/lj/silk/map_delete.png",
                  "watch_thread"     => "http://mike.mm1swebcreations.com/lj/silk/map_add.png",
                  "watching_parent"  => "http://mike.mm1swebcreations.com/lj/silk/map_magnify.png",
                 };

  # if there aren't any links defined in the array, let's add 'em
  $add_links = (size($link_keyseq) < 1);

  # define permalink data
  $link_key                  = "permalink";
  $link_captions{$link_key}  = $*text_permalink;
  $link_urls{$link_key}      = $.permalink_url;

  # if we're viewing an entry
  if($interentry) {
    # get previous entry link data
    $link_key                        = "nav_prev";
    $link                            = $this->get_link($link_key);
    $link_captions{$link_key}        = $link_captions{$link_key} != "" ? $link_captions{$link_key} : $link.caption;
    $link_images{$link_key}          = $link_images{$link_key}   != "" ? $link_images{$link_key}   : $link.icon.url;
    $link_urls{$link_key}            = $link_urls{$link_key}     != "" ? $link_urls{$link_key}     : $link.url;

    # if we're adding links
    if($add_links) {
      # add it to the array
      $link_keyseq[size($link_keyseq)] = $link_key;
    }
  }

  # cycle thru links and gather data
  foreach $link_key ($.link_keyseq) {
    $link                            = $this->get_link($link_key);
    $link_captions{$link_key}        = $link_captions{$link_key} != "" ? $link_captions{$link_key} : $link.caption;
    $link_images{$link_key}          = $link_images{$link_key}   != "" ? $link_images{$link_key}   : $link.icon.url;
    $link_urls{$link_key}            = $link_urls{$link_key}     != "" ? $link_urls{$link_key}     : $link.url;

    # if we're adding links
    if($add_links) {
      # add it to the array
      $link_keyseq[size($link_keyseq)] = $link_key;
    }
  }

  # if we're viewing an entry
  if($interentry) {
    # get next entry link data
    $link_key                        = "nav_next";
    $link                            = $this->get_link($link_key);
    $link_captions{$link_key}        = $link_captions{$link_key} != "" ? $link_captions{$link_key} : $link.caption;
    $link_images{$link_key}          = $link_images{$link_key}   != "" ? $link_images{$link_key}   : $link.icon.url;
    $link_urls{$link_key}            = $link_urls{$link_key}     != "" ? $link_urls{$link_key}     : $link.url;

    # if we're adding links
    if($add_links) {
      # add it to the array
      $link_keyseq[size($link_keyseq)] = $link_key;
    }
  }

  # give linkbar a css class
  $print = $print + """<span class="entry-linkbar">""";

  # if we've got links to process
  if(size($link_keyseq) > 0) {
    # if we're adding a first sep
    if($first_sep) {
      # add it
      $print = $print + $link_sep;
    }

    # cycle thru links
    foreach $link_key ($link_keyseq) {
      var bool have_img = $link_images{$link_key} != ""; # do we have an image?
      var bool have_url = $link_urls{$link_key}   != ""; # do we have a url?

      # if we have a url
      if($have_url) {
        # set the link text
        $link_link = $link_captions{$link_key};

        # if we have an image
        if($have_img) {
          # add the image
          $link_link = """<img src="$link_images{$link_key}" alt="$link_link" title="$link_link" border="0" />""";
        }
        
        # if we have a url, apply it
        $link_link = """<a href="$link_urls{$link_key}">$link_link</a>""";

        # add a link sep
        $print     = $print + $link_link + $link_sep;
      }
    }

    # if we don't have a sep on the end
    if(not $last_sep) {
      # hack it off
      $print = $print->substr(0, $print->length() - $link_sep->length());
    }
  }

  # close span
  $print = $print + "</span>";

  # print linkbar
  print $print;
}

function Entry::print_metadata() {
  var string[] metadata    = [];
  var string{} meta_images = {};
  var string{} meta_labels = {};

  # define the meta order
  #   location : current location
  #   mood     : current mood
  #   music    : current music
  #   tags     : current tags
  $metadata    = [ # location, mood, music, tags
                  "location",
                  "mood",
                  "music",
                  "tags"
                 ];

  # define the meta labels
  $meta_labels = {
                  "location"        => lang_metadata_title("location"),
                  "mood"            => lang_metadata_title("mood"),
                  "music"           => lang_metadata_title("music"),
                  "picture_keyword" => "Picture Keyword:",
                  "tags"            => "Current Tags:",
                 };

  # define the meta images
  $meta_images = {
                  "location"        => "http://mike.mm1swebcreations.com/lj/silk/map_magnify.png",
                  "mood"            => "http://mike.mm1swebcreations.com/lj/silk/user.png",
                  "music"           => "http://mike.mm1swebcreations.com/lj/silk/music.png",
                  "picture_keyword" => "",
                  "tags"            => "http://mike.mm1swebcreations.com/lj/silk/tag_blue.png",
                 };

  var string   currents_open    = """<div class="entry-metadata">"""; # html to open  metadata container
  var string   meta_label_open  = """<div><b>""";                     # html to open  metadata label
  var string   meta_label_close = """</b>""";                         # html to close metadata label
  var string   meta_val_open    = " ";                                # html to open  metadata value
  var string   meta_val_close   = """</div>""";                       # html to close metadata value
  var string   currents_close   = """</div>""";                       # html to close metadata container
  var bool     vanilla_loc      = false;                              # strip current location value?

  var bool     have_meta        = (size($.metadata) > 0);                # do we have meta?
  var bool     have_tags        = ((size($.tags) > 0) and $*tags_aware); # do we have tags?
  var int      tcount           = 0;
  var string   currents         = "";
  var string   image            = "";
  var string   k                = "";
  var string   label            = "";
  var string   meta             = "";
  var string   tag              = "";
  var string   val              = "";
  var Tag      t                = new Tag;

  # if we have meta or we have tags
  if($have_meta or $have_tags) {
    # add opening of metadata container
    $currents = $currents + $currents_open;


    # cycle thru meta
    foreach $k ($metadata) {
      $label = $meta_labels{$k} != "" ? $meta_labels{$k} : lang_metadata_title($k); # get label
      $image = $meta_images{$k} != "" ? $meta_images{$k} : "";                      # get image
      $val   = $.metadata{$k};                                                      # get value

      # if we have an image
      if($image != "") {
        # add it
        $label = """<img src="$image" alt="$label" title="$label" />""";
      }

      # if we're doing the location and we're stripping t
      if(($k == "location") and $vanilla_loc) {
        # do it
        $val = striphtml($val);
      }

      # this piece of meta has a specific class
      $meta_label_open = """<div class="current$k"><b>""";

      # if we're doing tags
      if($k == "tags") {
        # clear val
        $val = "";

        # if we have tags
        if($have_tags) {
          # cycle thru tags
          foreach $t ($.tags) {
            $tag = """<a href="$t.url">$t.name</a>"""; # build tag
            $val = $val + $tag;                        # add tag to val
            $tcount++;                                 # increment tag counter

            # if current count is less than the size of the tags
            if($tcount < size($.tags)) {
              # add a sep
              $val = $val + ", ";
            }
          }
        }
      }

      # if we have a val
      if($val != "") {
        # build meta row
        $meta   = $meta_label_open + $label + $meta_label_close + $meta_val_open + $val + $meta_val_close;
      }

      # add meta
      $currents = $currents + $meta;
    }

    # add closing of metadata container
    $currents = $currents + $currents_close;
  }

  # print metadata
  print $currents;
}
linkReply

Comments:
(Deleted comment)
[User Picture]From: kunzite1
2006-12-05 11:28 pm (UTC)
it works great in bloggish because that's what i used to create it. ;)

and thanks!
(Reply) (Parent) (Thread)
[User Picture]From: av8rmike
2007-01-17 02:02 pm (UTC)
In re-working the print_metadata() function for Expressive, I think I found a bug. Maybe it's different in Bloggish, I don't know. Anyway, if not all of the $.metadata fields are filled, the last known value repeats until the foreach loop is finished. In my version, I fixed it with:
if($val != "") {
    # build meta row
    $meta = """$meta_label_open$label$meta_label_close$meta_val_open$val$meta_val_close""";
} else {
    # don't add row if there's missing meta
    $meta = "";
}
I guess you could fix it some other way, like adding the long string directly to $currents and not using the $meta variable at all.
(Reply) (Thread)
(Deleted comment)
[User Picture]From: kunzite1
2007-02-14 02:40 am (UTC)
i think that was a redundant check from stale code.
removed the check.
(Reply) (Parent) (Thread)
From: ex_uniquewo
2007-02-13 05:40 pm (UTC)
Unless I'm mistaken, tags are not printed when they're the only metadata present in the entry.
(Reply) (Thread)
From: ex_uniquewo
2007-02-13 05:52 pm (UTC)
I think it's because of:
if ($have_meta) { }

Since size($.metadata) = 0 when you've got tags only and since tags are not printed if $have_meta == "", you're fucked.
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2007-02-13 09:42 pm (UTC)
you are correct. o.0

i'll have to fix that! XD
(Reply) (Parent) (Thread)
[User Picture]From: scotchsour
2007-08-18 10:30 pm (UTC)
I think this is great but I am driving myself mad trying to figure out where is my mood icon? I had it on the left with carriep63's version but I can't figure it out in yours...
(Reply) (Thread)
[User Picture]From: kunzite1
2007-08-19 11:41 am (UTC)
you know what? that's a good question.

i almost never use or pay attention to mood icons. this code in fact does not account for such an object...

oops. will have to fix later. in a couple days, if i remember, i'll get that done.
(Reply) (Parent) (Thread)
[User Picture]From: scotchsour
2007-08-19 08:53 pm (UTC)
Thank you, I'm glad I said something then. :)

Another question about the link bar section. When you go leave a comment (i guess the comment page) I can't figure out which part of the code to remove to get rid of the text links if I have the picture version all ready there.
(Reply) (Parent) (Thread)
[User Picture]From: scotchsour
2007-08-25 04:59 pm (UTC)
When you have time could you tell me how to add the number back to the comments so I don't just see a picture or need to pass over to see if somebody answered.
(Reply) (Parent) (Thread)