Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Improved user_box for Scoop (See related posts)

If you've ever built a site with Scoop, you know that all that messy hard-coded table-based HTML can be a pain. In the course of building several Scoop sites I've been reworking some of the common boxes to use cleaner, easily-styled, semantic markup, and this seems as good a place as any to post the code.

Here's a reworked user_box which outputs the tools menu as an unordered list:

my $content;
if ($S->{UID} > 0) {
  if ($S->have_perm('moderate')) {
    my ($nstories, $tstories) = $S->_count_new_sub();
    my $color = '';
    my $c_end = '';
    if ($nstories) {
       $color = '<strong style="color: #f00;">';
       $c_end = '</strong>';
    }
    $content = qq\|<ul>
    <li><a href="|rootdir|/modsub">Vote on Submissions</a> ($tstories/$color$nstories$c_end new)</li>\|;
  }

  if ($S->{TRUSTLEV} == 2 \|\| $S->have_perm('super_mojo')) {
    $content .= qq{<li><a href="|rootdir|/search?type=comment;hidden_comments=show">Review Hidden Comments</a></li>};
  }
  
  my $urlnick = $S->urlify($S->{NICK});
  my $diary_link = $S->{UI}->{VARS}->{use_diaries} ? 
                qq{
      <li><a href="|rootdir|/user/$urlnick/diary">Your Diary</a></li>
      <li><a href="|rootdir|/submitstory/Diary">New Diary Entry</a></li> 
                } : '';
        my $upload_link = ($S->{UI}->{VARS}->{allow_uploads} && ($S->have_perm('upload_user') \|\| $S->have_perm('upload_admin'))) ?
                qq{<li><a href="|rootdir|/user/$urlnick/files">Your Files</a></li>} : '';

        my $ad_link = $S->{UI}->{VARS}->{use_ads} ?
                qq{
      <li><a class="light" href="|rootdir|/user/$urlnick/ads">Your Advertisements</a></li>
          <li><a href="|rootdir|/submitad">Submit Ad</a></li>
                } : '';

  $content .= qq\|
      <li><a href="|rootdir|/user/$urlnick">User Info</a></li>
      <li><a href="|rootdir|/user/$urlnick/comments">Your Comments</a></li>
      <li><a href="|rootdir|/user/$urlnick/stories">Your Stories</a></li>
      $diary_link
          $ad_link
      $upload_link
      <li><a href="|rootdir|/user/$urlnick/prefs">User Preferences</a></li>
      <li><a href="|rootdir|/my/prefs/Interface">Display Preferences</a></li>
      <li><a href="|rootdir|/my/prefs/Comments">Comment Preferences</a></li>
      <li><a href="|rootdir|/logout">Logout $S->{NICK}</a></li></ul>\|;

    $title = $S->{NICK};
} else {
    $content = $S->{UI}->{BLOCKS}->{login_box};
    $content =~ s/|LOGIN_ERROR|/$S->{LOGIN_ERROR}/;
}
return {content => $content, title => $title };

You need to create an account or log in to post comments to this site.


Related Posts