Customizing the order things appear in within the entry

Feb 02, 2009 01:22

Okay.

I'm trying to do something pretty ambitious. I'm trying to make the ultimate customizable layout layer.

What I would like to do is essentially break up the entry and make it function like the sidebar does -- where you can choose what order various items appear in. (Like, if the end user wants the subject to appear above the date; if the end user wants the tags to appear above the entry. I want to make it an actual option for them when they're poking at it.)

Because I'm kind of designing this for Inksome, I've removed a lot of the things I can tell are only there to put ads in. (Inksome doesn't have ads for any account level, so.) Let me just reassure everyone that, if I ever put this layer on LJ itself, I'll work to put those bits of code back in. But I thought their absence might be easier on Inksome, which doesn't know what to do with the new permalinks in subjects.

Right now, the error I'm getting is:

Error compiling layer:

Compile error: line 1806, column 21: Unknown local variable $e
S2::NodeVarRef, S2/NodeVarRef.pm, 180
S2::NodeTerm, S2/NodeTerm.pm, 174
S2::NodeTerm, S2/NodeTerm.pm, 66
S2::NodeEqExpr, S2/NodeEqExpr.pm, 49
S2::NodeExpr, S2/NodeExpr.pm, 46
S2::NodeIfStmt, S2/NodeIfStmt.pm, 79
S2::NodeStmtBlock, S2/NodeStmtBlock.pm, 108
S2::NodeFunction, S2/NodeFunction.pm, 230
S2::Checker, S2/Checker.pm, 374
S2::Compiler, S2/Compiler.pm, 34

Context

1802: }
1803:
1804: function print_entry_subject() {
1805: """""";
1806: if ($e.security != "")
1807: {
1808: $e.security_icon->print();
1809: }
1810: if ($p.view != "entry") {

I think this means that I haven't defined $e, but when I put (Entry e) into print_entry_subject() (and every other one of the functions in my entry section), I get another error. Suddenly "function print_entry_subject()" is unknown.

Below are the relevant parts of my layer, without the (Entry e, Page p, [etc]):

# -----------------------------------
# LAYER INFO
# -----------------------------------
layerinfo type = "layout";
layerinfo name = "Flexible Squares Mark 2";
layerinfo lang = "en";
layerinfo author_name = "Yati Mansor";
layerinfo redist_uniq = "flexiblesquares/layout";
layerinfo previews = "flexiblesquares/layout.jpg";

# -----------------------------------
# PROPGROUPS
# -----------------------------------

### ENTRY
propgroup Entry {

property bool subject_datetime {
des = "Keep the subject with the date and time?";
}
set subject_datetime = true;

property bool tags_currents {
des = "Keep the tags with the currents?";
}

set tags_currents = true;

property string entry_order_1 {
des = "First item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
property string entry_order_2 {
des = "Second item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
property string entry_order_3 {
des = "Third item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
property string entry_order_4 {
des = "Fourth item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
property string entry_order_5 {
des = "Fifth item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
property string entry_order_6 {
des = "Sixth item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
property string entry_order_7 {
des = "Seventh item in the entry";
values = "subject|Subject|datetime|Date|userpic|Userpic|entrytext|Entry Text|tags|Tags|metadata|Meta Data|commentlinks|Comment Links";
}
set entry_order_1 = "subject";
set entry_order_2 = "datetime";
set entry_order_3 = "userpic";
set entry_order_4 = "entrytext";
set entry_order_5 = "tags";
set entry_order_6 = "metadata";
set entry_order_7 = "commentlinks";
}

# -----------------------------------
# PAGE
# -----------------------------------

# Header
function Page::lay_print_header()
"Prints header"
{
var Page page = get_page();
var string title = $this->title();

print """

""";
}

# Footer
function Page::lay_print_footer()
{
"""
 

""";
}

function Page::print_stylesheets() {
if ($*include_default_stylesheet) {
println """";
}
if ($*custom_css != "") {
println """""";
}
}

function Page::print () {
var Page page = get_page();
var string title = $this->title();

var string page_align = "";
if ($*page_alignment == "left") {
$page_align = " margin-left: 20px; margin-right: auto;";
}
elseif ($*page_alignment == "right") {
$page_align = " margin-left: auto; margin-right: 20px;";
}
elseif ($*page_alignment == "center") {
$page_align = " margin-left: auto; margin-right: auto;";
}

"""
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml">

""";
$this->print_head();
$this->print_stylesheets();
print safe """$title""";
$this->print_custom_head();
"""



""";
$this->print_control_strip();
if (viewer_sees_hbox_top()) {
"""
""";
$this->print_hbox_top();
"
";
}
"""


""";
$this->lay_print_header();

if ($*show_sidebar) {
"""

""";
} elseif (viewer_sees_vbox()) {
"""";
}
"""
""";
$this->print_body();
"

";

$this->lay_print_footer();
"
";

if (viewer_sees_hbox_bottom()) {
"""
""";
$this->print_hbox_bottom();
"
";
}
"
";
}

function Entry::print_linkbar() {
# Links (memories, edit, prev, next)
var Page p = get_page();
if ($p.view == "entry" or $p.view == "reply") {
var Link prev = $this->get_link("nav_prev");
var Link next = $this->get_link("nav_next");

var string{} link_text = {
"edit_entry" => $*text_edit,
"edit_tags" => $*text_edit_tags,
"mem_add" => $*text_memories,
"tell_friend" => $*text_tell_friend,
"flag" => $*text_flag,
"watch_comments" => $*text_track,
"unwatch_comments" => $*text_untrack,
};
print safe """

""";
}

}

function print_entry_subject() {
"""""";
if ($e.security != "")
{
$e.security_icon->print();
}
if ($p.view != "entry") {
print $e.subject;"  ";
}
else { print "$e.subject  "; }
"""
""";
}

function print_entry_datetime() {
var string time = "";
$time = $time + """ @ """;
$time = $time + $e.time->time_format("short");
var string date = "";
$date = $date + $e.time->date_format("long_day");
"""
""";
print $e.time->date_format("%%dd%% %%month%% %%yyyy%%");
"$time
";
}

function print_entry_userpic() {
var string userpic = "";
if ($*show_entry_userpic)
{
if ($p.view == "friends" or $p.view == "entry" or $p.view == "reply")
{
if (defined $e.userpic)
{
$userpic = $userpic + """$e.poster.name if ($e.poster.username != $e.journal.username)
{
$userpic = $userpic + " in $e.journal.name";
}
$userpic = $userpic + "\">";
}
}
elseif ($p.journal_type == "C" and $p.view == "recent")
{
if (defined $e.userpic)
{
$userpic = $userpic + """$e.poster.name""";
}
}
else
{
if (defined $e.userpic)
{
$userpic = $userpic + """
$e.poster.name
""";
}
}
}
if (($p.view == "recent" and $p.journal_type != "C" ) or $p.view == "day")
{
print """$userpic""";
}
else
{
if ($p.view == "recent" and $p.journal_type == "C" )
{
"""
""";
}
else
{
"""
""";
}
print """$userpic""";

if ($p.view == "friends" or $p.view == "entry" or $p.view == "reply")
{
var UserLite linkto;
$linkto = $e.poster;
#print "$e.poster.username";

"""
base_url() + "\">";

"$linkto.username
";
}
elseif ($p.journal_type == "C" and $p.view == "recent")
{
var UserLite linkto;
$linkto = $e.poster;
#print "$e.poster.username";
"""
base_url() + "\">";
"$linkto.username
";
}
if (($p.view == "friends" or $p.view == "entry" or $p.view == "reply") and $e.poster.username != $e.journal.username)
{
var UserLite linkto;
$linkto = $e.journal;
"""
[base_url() + "\">";
"$linkto.username
]";
}

if ($p.view == "recent" and $p.journal_type == "C")
{
print "
";
}
if ($p.view != "recent" and $p.view != "day")
{
print """
""";
}
}
}

function print_entry_entrytext() {
"""

""";

$e->print_text();
print "

";
}

function print_entry_tags()
{
var string currents ="";
$e->print_metadata();
}

function print_entry_metadata()
{
var string currents ="";
$e->print_metadata();
}

function print_entry_commentlinks()
{
"""
""";
if ($p.view != "entry" or $p.view != "reply")
{
$e.comments->print();
}
elseif ($e.comments.enabled)
{
$e.comments->print_postlink();
}
else
{
" ";
}
"""
""";
}

function entry_order(string order)
{
if ($*subject_datetime) {
"""
""";
if ($order == "subject")
{
print_entry_subject();
}
if ($order == "datetime")
{
print_entry_datetime();
}
"""
""";
} else {
if ($order == "subject")
{
print_entry_subject();
}
if ($order == "datetime")
{
print_entry_datetime();
}
}
if ($order == "userpic")
{
print_entry_userpic();
}
if ($order == "entrytext")
{
print_entry_entrytext();
}
if ($order == "tags")
{
print_entry_tags();
}
if ($order == "metadata")
{
print_entry_metadata();
}
if ($order == "commentlinks")
{
print_entry_commentlinks();
}
}

function print_entry(Page p, Entry e, Color bgcolor, Color fgcolor)
{
"""

""";
$e->print_linkbar();

entry_order($*entry_order_1);
entry_order($*entry_order_2);
entry_order($*entry_order_3);
entry_order($*entry_order_4);
entry_order($*entry_order_5);
entry_order($*entry_order_6);
entry_order($*entry_order_7);

"""


""";
}

function Page::print_entry(Entry e) {
print_entry($this, $e, null Color, null Color);
}

function FriendsPage::print_entry (Entry e) {
if ($*use_friends_colours) {
var Friend f = $.friends{$e.journal.username};
print_entry($this, $e, $f.bgcolor, $f.fgcolor);
} else {
print_entry($this, $e, $*entry_bgcolor, $*entry_fgcolor);
}
}

function EntryPage::print_entry(Entry e) {
print_entry($this, $e, $*entry_bgcolor, $*entry_fgcolor);
}

function ReplyPage::print_entry(Entry e) {
print_entry($this, $e, $*entry_bgcolor, $*entry_fgcolor);
}

function Entry::print_metadata() {
var string tags_sep = ", "; # text for tags separator, ", " for "tag, tag, tag"

var string show_tags_link = "none"; # set to "edit" if you want the tags label to act as an 'edit tags' link
# set to "page" if you want the tags label to link to the poster's journal's tag page
# set to "manage" to link to the Tags Management page
# set to "none" to delinkify the tags label completely

var bool show_loc_link = false; # set to false to delinkify location (no Google Maps link)
# set to true to display the Google Map link

var bool show_groups_link = false; # set to false to delinkify the group (no custom friends group link)
# set to true to display the friends group link

# here, set mood, music, location and tags into the order you want them to be displayed in
# any metadata you want to hide journalwide, delete it from this list

var string[] metaorder = ["tags", "mood", "music", "location", "groups"];

# optional:
# here, put in the URLs to the pics you want to use instead of the currents' labels
# if you leave it blank, the current's text label will be used instead

var string{} metapics = { "mood" => "",
"music" => "",
"location" => "",
"tags" => "",
"groups" => "" };

var string currents = """
"""; # here all metadata will be added to print it out in the end
var string currents_close = """
"""; # html for closing of currents container

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))) {

# step through metadata in the order the user wants
foreach var string k ($metaorder) {

var string text; # the actual value of the metadata
var string label; # the label of the metadata as set in the wizard or set-statements

# handling tags metadata
if (($k == "tags") and (size $.tags > 0) and $*tags_aware) {

# label as image or text
$label = clean_url($metapics{$k}) != "" ? """$*text_tags""" : $*text_tags;

# optional linkage around tags label
if (($show_tags_link == "edit") and ($edit_tags.url != "")) { # Edit Tags Page link
$label = """""" + $label + """""";
} elseif ($show_tags_link == "page") { # Visible Tags Page link
$label = """base_url() + """/tag/ ">""" + $label + """""";
} elseif ($show_tags_link == "manage" and viewer_is_owner()) { # Tags Management Page link
$label = """tag_manage_url() + """ ">""" + $label + """""";
}

# build tag list
var bool addsep = false;
foreach var Tag t ($.tags) {
if ($addsep) {
$text = $text + $tags_sep + """""";
}
else {
$text = $text + """""";
$addsep = true;
}
}
}

# handling all other metadata
elseif (($k != "tags") and ($.metadata{$k} != "")) {

# metadata value
$text = $.metadata{$k};
$text = ($k == "mood" and defined $.mood_icon) ? """ $.metadata{""" + $text : $text;

# label as image or text
$label = clean_url($metapics{$k}) != "" ? "\""" : lang_metadata_title($k);

# strip location link
if (not ($show_loc_link) and ($k == "location") and ($.metadata{"location"} != "")) {
$text = striphtml($text);
}

# strip groups link
if (not ($show_groups_link) and ($k == "groups") and ($.metadata{"groups"} != "")) {
$text = striphtml($text);
}
}

# skipping empty quotes (= hidden metadata)
else {
continue;
}

# assemble the individual currents
$currents = $currents + """$label $text""";

}

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

# print currents
println "$currents";
}
}

function RecentPage::lay_print_footer()
{
var string range = "most recent entries";
var string sep;
var string back;
var string forward;

if ($.nav.skip > 0)
{
$range = "$.nav.skip entries back";
}
if ($.nav.forward_url != "" or $.nav.backward_url != "")
{
if ($.nav.backward_url != "")
{
$back = """
  • """ + get_plural_phrase($.nav.backward_count, "text_skiplinks_back") + """
  • """;
    }
    if ($.nav.forward_url != "")
    {

    $forward = """
  • """ + get_plural_phrase($.nav.forward_count, "text_skiplinks_forward") + """
  • """;
    }
    }
    print safe """
     


     

    """;
    }

    function RecentPage::print_body
    {
    foreach var Entry e ($.entries)
    {

    $this->print_entry($e);
    if ($e->viewer_sees_ebox()) {

    """
    """;
    $e->print_ebox();
    """


    """;
    }
    }
    }

    function EntryPage::print_body()
    {
    $this->print_entry($.entry);

    if ($.entry->viewer_sees_ebox()) {
    """
    """;
    $.entry->print_ebox();
    """


    """;
    }

    if ($.multiform_on and $.entry.comments.enabled and $.comment_pages.total_subitems > 0)
    {
    $this->print_multiform_start();
    }
    if ($.entry.comments.enabled)
    {
    """


    """;
    $.comment_pages->print();
    """
    ( """;
    $this->print_reply_link({"target" => "topcomment", "linktext" => "Post a new comment"});
    """ )
    """;
    $this->print_reply_container({"target" => "topcomment"});
    $this->print_comments($.comments);
    """
    """;
    }

    if ($this.multiform_on and $.entry.comments.enabled and $.entry.comments.count > 0)
    {
    """
    """;
    $this->print_multiform_actionline();
    $this->print_multiform_end();
    """

    ( Post a new comment )""";
    $.comment_pages->print();
    """


    """;
    }
    """

    """;

    }

    # -----------------------------------
    # ENTRY
    # -----------------------------------

    function EntryPage::print_comments( Comment[] comments )
    {
    if ( size $comments == 0 )
    {
    return;
    }

    foreach var Comment c ( $comments )
    {
    var int indent = ($c.depth - 1) * 30;
    var string partialcomment = $c.full ? " ljcmt_full" : "partial";
    var string margin = "";
    if ($*userpic_position == "left")
    {
    $margin = "right";
    }
    else
    {
    $margin = "left";
    }

    """""";
    """
    \n""";
    if ( $c.full )
    {

    $this->print_comment( $c );
    }
    else
    {
    $this->print_comment_partial( $c );
    }
    "
    ";
    $this->print_comments( $c.replies );
    }
    }

    function EntryPage::print_comment (Comment comment) {

    var string subject = $comment.subject ? $comment.subject : $*text_nosubject;
    var string date = $comment.time->date_format();
    var string poster = isnull $comment.poster ? $*text_poster_anonymous : $comment.poster->as_string();

    #Comment Userpic
    if (defined $comment.userpic and $*show_entry_userpic)
    {
    var int w = $comment.userpic.width;
    var int h = $comment.userpic.height;
    var string alt = $comment.metadata{"picture_keyword"};
    if ($*comment_userpic_style == "small")
    {
    $w = $w / 2;
    $h = $h / 2;
    }
    if ($alt != "")
    {
    $alt = ": " + $alt;

    }

    """

    $comment.poster.name$alt""";
    print """$poster on """;
    print $comment->time_display("long", "");
    }
    else
    {
    print """
    $poster on """;
    print $comment->time_display("long", "");
    }
    if (defined $comment.subject_icon or $comment.subject != "")
    {
    print "
    $comment.subject_icon $comment.subject" + "
    ";
    }
    if ($comment.metadata{"poster_ip"})
    {
    print "
    " + $*text_comment_ipaddr + "(" + $comment.metadata{"poster_ip"} + ")" + "
    ";
    }
    "
    ";

    print """
    """; $comment->print_text(); """
    \n""";
    var string alignlinks = "";
    if ($*userpic_position == "left")
    {
    $alignlinks = "right";
    }
    else
    {
    $alignlinks = "left";
    }
    "
    ";

    if ($comment.frozen)
    {
    "($*text_comment_frozen)";
    }
    else
    {
    print "("; $comment->print_reply_link({"linktext" => $*text_comment_reply}); ") ";
    }

    if ($comment.parent_url != "")
    {
    "($*text_comment_parent) ";
    }

    if ($comment.thread_url != "")
    { "(Thread) "; }

    "($*text_permalink)";

    """
    """;
    if ($this.multiform_on)
    {
    """""";
    $comment->print_multiform_check();
    }
    $comment->print_linkbar();
    if (not $comment.frozen) {
    $comment->print_reply_container({"class" => "quickreply"});
    }

    "
    \n";
    }

    ANY HELP would be seriously appreciated, I'm just going in circles here and I don't know what's wrong. :(

    solved, misc