?

Log in

No account? Create an account
[theme] - [tranqii] - [print_entry with stuff] - 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] - [tranqii] - [print_entry with stuff] [Aug. 30th, 2005|04:27 pm]
S2 Layers

s2layers

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

in response to jdark's s2tranquility2 post.
fix linkbar.
add tags to date line.
add options for userpic showingness.
changes poster info to actual [info]username pairs.
# tell the system to not auto-magically add tags to entry text
set tags_aware      = true;

# add colons to mood/music
set text_meta_location = "location:";
set text_meta_mood     = "mood:";
set text_meta_music    = "music:";

function Entry::print_metadata() {
  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

  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

  if (size $.metadata > 0){
    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

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

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

    # print currents
    println "$currents";
  }
}

function Entry::print_linkbar() {
  var string   link_seperator = " | "; # seperator for links

  # initialize array/hashes
  var string[] link_keyseq    = [""];
  var string{} link_url       = {"" => ""};
  var string{} link_caption   = {"" => ""};
  var string{} link_image     = {"" => ""};

  var string print           = "";                                         # var for printing
  var Page   p               = get_page();                                 # page handle to determine interentry
  var bool   show_interentry = ($p.view == "entry" or $p.view == "reply"); # if entry/reply view, show interentry
  var int    keyseq_index    = 0;                                          # set index point for new link_keyseq array

  if($show_interentry) {
    # if show interentry, put previous entry link first
#    $link_keyseq[$keyseq_index++] = "nav_prev";

    # get previous entry link information
    var Link prev             = $this->get_link("nav_prev");
    $link_url{"nav_prev"}     = $prev.url;
    $link_caption{"nav_prev"} = $prev.caption;
    $link_image{"nav_prev"}   = $prev.icon.url;

    # get next entry link information
    var Link next             = $this->get_link("nav_next");
    $link_url{"nav_next"}     = $next.url;
    $link_caption{"nav_next"} = $next.caption;
    $link_image{"nav_next"}   = $next.icon.url;
  }

  # gather current linkbar
  foreach var string link_key ($.link_keyseq) {
    var Link  link            = $this->get_link($link_key);
    $link_url{$link_key}      = $link.url;
    $link_caption{$link_key}  = $link.caption;
    $link_image{$link_key}    = $link.icon.url;
    $link_keyseq[$keyseq_index++] = $link_key; # add this to new link_keyseq array
  }
  if($show_interentry) {
    # if show interentry, put next entry link last
#    $link_keyseq[$keyseq_index++] = "nav_next";
  }

  #################################################################################################################
  # by now, the above hashes should look something like:                                                          #
  #                                                                                                               #
  # If interentry:                                                                                                #
  #   Previous Entry:                                                                                             # 
  #    $link_url{"nav_prev"}     = http://www.livejournal.com/go.bml?journal=exampleusername&itemid=256&dir=prev  #
  #    $link_caption{"nav_prev"} = Previous Entry                                                                 #
  #    $link_image{"nav_prev"}   = http://stat.livejournal.com/img/btn_prev.gif                                   #
  #                                                                                                               #
  # Edit Entry:                                                                                                   # 
  #  $link_url{"edit_entry"}     = http://www.livejournal.com/editjournal.bml?journal=exampleusername&itemid=256  #
  #  $link_caption{"edit_entry"} = Edit Entry                                                                     #
  #  $link_image{"edit_entry"}   = http://stat.livejournal.com/img/btn_edit.gif                                   #
  #                                                                                                               #
  # Edit Tags:                                                                                                    # 
  #  $link_url{"edit_tags"}      = http://www.livejournal.com/edittags.bml?journal=exampleusername&itemid=256     #
  #  $link_caption{"edit_tags"}  = Edit Tags                                                                      #
  #  $link_image{"edit_tags"}    = http://stat.livejournal.com/img/btn_edittags.gif                               #
  #                                                                                                               #
  # Add to Memories:                                                                                              # 
  #  $link_url{"mem_add"}        = http://www.livejournal.com/tools/memadd.bml?journal=exampleusername&itemid=256 #
  #  $link_caption{"mem_add"}    = Add to Memories                                                                #
  #  $link_image{"mem_add"}      = http://stat.livejournal.com/img/btn_memories.gif                               #
  #                                                                                                               #
  # If interentry:                                                                                                #
  #   Next Entry:                                                                                                 #
  #    $link_url{"nav_next"}     = http://www.livejournal.com/go.bml?journal=exampleusername&itemid=256&dir=next  #
  #    $link_caption{"nav_next"} = Next Entry                                                                     #
  #    $link_image{"nav_next"}   = http://stat.livejournal.com/img/btn_next.gif                                   #
  #################################################################################################################

  # disable pictures
  $link_image{"edit_entry"}       = "";
  $link_image{"edit_tags"}        = "";
  $link_image{"mem_add"}          = "";
  $link_image{"nav_prev"}         = "";
  $link_image{"nav_next"}         = "";
  $link_image{"watch_comments"}   = "";
  $link_image{"unwatch_comments"} = "";

  # loop thru linkbar and add links to print var
  foreach var string link_key ($link_keyseq) {
    # if we can do performed action, url will be present
    if($link_url{$link_key} != "") {
      $print = $print + """<a href="$link_url{$link_key}">""";
      # if image url available, use it
      if($link_image{$link_key} != "") {
        $print = $print + """<img src="$link_image{$link_key}" alt="$link_caption{$link_key}" title="$link_caption{$link_key}" border="0" />""";
      } else {
        # else, just use text
        $print = $print + "$link_caption{$link_key}";
      }
      # add a seperator
      $print = $print + "</a>$link_seperator";
    }
  }

  # hack off last seperator
  $print = $print->substr(0, $print->length() - $link_seperator->length());

  # we're done! let's print it!
  print $print;
}

# -------------------------------
# display an entry (all views )
# -------------------------------
function print_entry ( Page p, Entry e ) {
  # ideally, this would be the same as the seperator in Entry::print_linkbar()
  var string link_sep = " | ";

  var string interentry = "";

  # get tags
  var string tags = "";
  if(((size $e.tags) > 0) and ($*tags_aware == true)) {
    foreach var Tag t ($e.tags) {
      $tags = $tags + """ | <a href="$t.url">$t.name</a>""";
    }
  }


  # get date/time

  var string datetime;
  $datetime = $e.time->date_format($*date_format) + " | " + $e.time->time_format($*time_format);

  # get subject
  var string subject = $e.subject != "" ? $e.subject : """<i class="nosubject">$*text_nosubject</i>""";

  # get any extra user info (if posting to community, etc)
  var string poster = "";
  var string userpic = "";
  var bool   show_recent_userpic  = true;
  var bool   show_friends_userpic = true;
  var bool   show_day_userpic     = true;
  var bool   show_entry_userpic   = true;
  var bool   show_reply_userpic   = true;
  var bool   show_userpic         = (
                                     (defined $e.userpic) and
                                     (
                                      (($p.view == "recent")  and ($show_recent_userpic))  or
                                      (($p.view == "friends") and ($show_friends_userpic)) or
                                      (($p.view == "day")     and ($show_day_userpic))     or
                                      (($p.view == "entry")   and ($show_entry_userpic))   or
                                      (($p.view == "reply")   and ($show_reply_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 = "$e.poster in $e.journal";
    } else {
      $poster =  $e.poster->as_string();
    }
    $poster = "<b>posted by:</b> $poster";
  }
  if ($show_userpic) {
    $userpic = """<h3 class="userpic"><a href="$*SITEROOT/allpics.bml?user=$e.poster.username" target="_blank"><img border="0" src="$e.userpic.url" width="$e.userpic.width" height="$e.userpic.height" alt="$e.poster.username's user pictures" title="$e.poster.username's user pictures" /></a></h3>""";
  }

  # print the entry now:
  """
  <div id="entry_$e.itemid" class="ind-entry">""";

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

  """
    <h2>""";

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

  var bool show_interentry = ($p.view == "entry" or $p.view == "reply");

  if($show_interentry) {
    var Link   nav_prev = $e->get_link("nav_prev");
    var Link   nav_next = $e->get_link("nav_next");
    var string text     = "";
    if($nav_prev.url != "") {
      $text = "&laquo; previous entry";
      $interentry = $interentry + """<a href="$nav_prev.url">$text</a>""";
    }
    if($nav_next.url != "") {
      $text = "next entry &raquo;";
      if($interentry != "") {
        $interentry = $interentry + $link_sep;
      }
      $interentry = $interentry + """<a href="$nav_next.url">$text</a>""";
    }
    if($interentry != "") {
      $interentry = $interentry + "<br />";
    }
  }

  """
    <h4>$interentry
      <b>$datetime$tags</b><br />""";

  $e->print_metadata();

  if ( $poster != "" ) {
    """
      $poster""";
  }

  """
    </h4>""";

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

  """
    <h4>""";

  """<a href="$e.permalink_url">$*text_permalink</a>""";

  print $link_sep;

  $e.comments->print();

  if($e.comments.enabled) {
    print $link_sep;
  }

  $e->print_linkbar();

  """
    </h4>
  </div>
  <hr />""";
}
linkReply

Comments:
From: jdark
2005-08-31 03:15 pm (UTC)
Thanks, I tried it but it didn't seem to change anything, i.e. still no 'Edit Tags' link.
(Reply) (Thread)
[User Picture]From: kunzite1
2005-08-31 03:20 pm (UTC)

hmm. it should work.

could you friend component_help so i can see if i can access the edit tags link on your friends page? it's been coded in such a way that it should be enabled that way.

also, do you have any other custom code going on in your layers?

since you have no public entries to view, it's kinda hard to debug the situation.
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: kunzite1
2005-08-31 05:25 pm (UTC)

posting code like that doesn't work very well because it loses it's formatting and is much easier to read with the indentation.
is much easier to view what is on lj's servers.

if you could put the following into the top of the layer and give me the layerid number, thatd be great:
layerinfo "source_viewable" = 1;
(Reply) (Parent) (Thread)
(Deleted comment)
[User Picture]From: kunzite1
2005-08-31 06:04 pm (UTC)

ok. i edited the entry to put the tags up next to the date.
is jdark the account that you are using to attempt to edit the tags in the journal with? if not, that could be causing problems.

the edit tags link will only appear if the remote viewer is allowed to use it.
(Reply) (Parent) (Thread)
[User Picture]From: emmavescence
2006-02-09 10:00 pm (UTC)
Thank you for this! I'd tried some other code and not got it to work, but this is happy and functioning. One thing done, several things to go...
(Reply) (Thread)
[User Picture]From: blue_ant
2006-03-29 12:31 am (UTC)
Thanks for this! I, too, tried to get different code to work and this was the only one that did. I do have a question, though. Is there anyway to get rid of the link (not the one that says "Edit Tags") to edit tags where tags are displayed (under the music, etc)?
(Reply) (Thread)
[User Picture]From: kunzite1
2006-03-29 05:38 pm (UTC)

In order to help you, we need to have a look at your layer. Please make it viewable and give us its ID. If you have multiple layers that you are working with, we will need all of them to be viewable and all of their IDs. This entry will tell you how to do that.
(Reply) (Parent) (Thread)
[User Picture]From: blue_ant
2006-03-30 03:49 am (UTC)
Ok.

Layer number: 5663305
Style number: 9006371 (though I don't know if you need it)
(Reply) (Parent) (Thread)
[User Picture]From: kunzite1
2006-03-31 08:02 am (UTC)

see # if remote user can edit tags, let's give them a link? might be there. ;)
(Reply) (Parent) (Thread)
[User Picture]From: hermintage
2006-11-08 09:54 pm (UTC)
I'm using this user layer (I haven't changed anything from it) but I'm having trouble getting the image for "track comments" to turn off. It's been too long since I've fiddled with s2 at all. Wow, I've forgotten so much of this. Do you have a minute to help?
(Reply) (Thread)
[User Picture]From: kunzite1
2006-11-09 03:30 am (UTC)
updated post to reflect silliness they've added to s2. :)
(Reply) (Parent) (Thread)
[User Picture]From: hermintage
2006-11-09 04:33 am (UTC)
exxxxxxxxcellent. thanks much!
(Reply) (Parent) (Thread)