0.12_22 commit r0_12_22
authorTony Cook <tony@develop-help.com>
Thu, 27 Feb 2003 06:00:46 +0000 (06:00 +0000)
committertony <tony@45cb6cf1-00bc-42d2-bb5a-07f51df49f94>
Thu, 27 Feb 2003 06:00:46 +0000 (06:00 +0000)
30 files changed:
Makefile
README
localinst.perl
site/cgi-bin/admin/shopadmin.pl
site/cgi-bin/admin/subs.pl
site/cgi-bin/modules/Article.pm
site/cgi-bin/modules/Articles.pm
site/cgi-bin/modules/BSE/Edit/Article.pm
site/cgi-bin/modules/BSE/Edit/Product.pm
site/cgi-bin/modules/BSE/FileEditor.pm
site/cgi-bin/modules/BSE/SubscriptionType.pm
site/cgi-bin/modules/BSE/Template.pm
site/cgi-bin/modules/BSE/Util/Tags.pm
site/cgi-bin/modules/Constants.pm
site/cgi-bin/modules/Generate.pm
site/cgi-bin/modules/Generate/Article.pm
site/cgi-bin/modules/Generate/Catalog.pm
site/cgi-bin/modules/Generate/Product.pm
site/cgi-bin/modules/Squirrel/Template.pm
site/cgi-bin/modules/Util.pm
site/cgi-bin/printable.pl
site/cgi-bin/search.pl
site/cgi-bin/shop.pl
site/docs/bse.pod
site/docs/config.pod
t/BSE/Test.pm
t/t00smoke.t
t/t10edit.t
t/t20gen.t
test.cfg

index 5addda83b6c8b2df4840e0d75ce9aac3b169fb0a..5d3e03aa4b586652de41fe200d4a7f770b066fc0 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION=0.12_21
+VERSION=0.12_22
 DISTNAME=bse-$(VERSION)
 DISTBUILD=$(DISTNAME)
 DISTTAR=../$(DISTNAME).tar
diff --git a/README b/README
index 08a29b3a5c16d45e934d61d52e272679f0b586e4..e0e8d3316230321327fe576dee8aca3f5cbd5fc4 100755 (executable)
--- a/README
+++ b/README
@@ -19,7 +19,29 @@ For version information please see site/docs/bse.pod
 Installation documentation can be found in INSTALL.* and plenty of
 other documentation can be found in site/docs/
 
+LICENSE
+=======
+
 BSE is distributed under your choice of either the Artistic or GNU
 Public License, just as Perl is.
 
+HELP
+====
+
+Try the bse-users mailing list for volunteer help:
+
+  http://lists.develop-help.com/mailman/listinfo/bse-users
+
+Please keep discussion on the mailing list, private emails are likely
+to result in quotes of hourly rates.
+
+If you want to be notifed about each release of BSE, subscribe to the
+bse-announce mailing list:
+
+  http://lists.develop-help.com/mailman/listinfo/bse-announce
+
+Only announcements are sent to this list, though it's possible
+spammers will figure out how to bypass its protection, in which case
+I'll make it tougher to do so.
+
 Tony Cook <tony@develop-help.com>
index 1c88233d2b27123a7574ff09c57d8beed8ad5ec0..a6278a2935fdb2eb3abcf3ed8011a4a4e21e0a49 100644 (file)
@@ -66,6 +66,8 @@ $conf{site}{url} = BSE::Test::base_url();
 $conf{site}{secureurl} = BSE::Test::base_securl();
 my $uploads = "$instbase/uploads";
 $conf{paths}{downloads} = $uploads;
+my $templates = "$instbase/templates";
+$conf{paths}{templates} = $templates;
 open TESTCONF, "< $conffile"
   or die "Could not open config file $conffile: $!";
 while (<TESTCONF>) {
index 679634cd93cf5653921e2c216dfb0de47864e372..d01058e453ffa9ed510cdd19a5a775a2fbea554c 100755 (executable)
@@ -13,8 +13,7 @@ use Orders;
 use Order;
 use OrderItems;
 use OrderItem;
-use Constants qw($TMPLDIR);
-use Squirrel::Template;
+use BSE::Template;
 #use Squirrel::ImageEditor;
 use Constants qw(:shop $SHOPID $PRODUCTPARENT 
                  $SHOP_URI $CGI_URI $IMAGES_URI $AUTO_GENERATE);
@@ -142,6 +141,8 @@ sub embedded_catalog {
     grep $_->{generator} eq 'Generate::Catalog', 
     Articles->children($catalog->{id});
 
+  my $blank = qq!<img src="$IMAGES_URI/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
+
   my %acts;
   %acts =
     (
@@ -171,6 +172,7 @@ sub embedded_catalog {
      sub {
        $req->user_can(edit_reorder_children => $catalog)
         or return '';
+       @list > 1 or return '';
        # links to move products up/down
        my $html = '';
        my $refreshto = CGI::escape($ENV{SCRIPT_NAME}."#cat".$catalog->{id});
@@ -186,6 +188,9 @@ HTML
 HTML
         }
        }
+       else {
+        $html .= $blank;
+       }
        if ($list_index > 0) {
         if ($session->{showstepkids}) {
           $html .= <<HTML;
@@ -198,6 +203,9 @@ HTML
 HTML
         }
        }
+       else {
+        $html .= $blank;
+       }
        return $html;
      },
      script=>sub { $ENV{SCRIPT_NAME} },
@@ -211,6 +219,7 @@ HTML
      sub {
        $req->user_can(edit_reorder_children => $catalog)
         or return '';
+       @subcats > 1 or return '';
        # links to move catalogs up/down
        my $html = '';
        my $refreshto = CGI::escape($ENV{SCRIPT_NAME});
@@ -219,17 +228,22 @@ HTML
 <a href="$CGI_URI/admin/move.pl?id=$subcats[$subcat_index]{id}&d=swap&other=$subcats[$subcat_index+1]{id}&refreshto=$refreshto&all=1"><img src="$IMAGES_URI/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        if ($subcat_index > 0) {
         $html .= <<HTML;
 <a href="$CGI_URI/admin/move.pl?id=$subcats[$subcat_index]{id}&d=swap&other=$subcats[$subcat_index-1]{id}&refreshto=$refreshto&all=1"><img src="$IMAGES_URI/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        return $html;
      },
     );
 
-  my $tmplt = Squirrel::Template->new;
-  return $tmplt->show_page($TMPLDIR, 'admin/'.$template, \%acts);
+  return BSE::Template->get_page('admin/'.$template, $cfg, \%acts);
 }
 
 sub product_list {
@@ -246,6 +260,9 @@ sub product_list {
     $session->{showstepkids} = $cgi->param('showstepkids');
   }
   exists $session->{showstepkids} or $session->{showstepkids} = 1;
+
+  my $blank = qq!<img src="$IMAGES_URI/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
+
   my %acts;
   %acts =
     (
@@ -267,6 +284,7 @@ sub product_list {
      sub {
        $req->user_can(edit_reorder_children => $shopid)
         or return '';
+       @catalogs > 1 or return '';
        # links to move catalogs up/down
        my $html = '';
        my $refreshto = CGI::escape($ENV{SCRIPT_NAME});
@@ -275,11 +293,17 @@ sub product_list {
 <a href="$CGI_URI/admin/move.pl?id=$catalogs[$catalog_index]{id}&d=swap&other=$catalogs[$catalog_index+1]{id}&refreshto=$refreshto&all=1"><img src="$IMAGES_URI/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        if ($catalog_index > 0) {
         $html .= <<HTML;
 <a href="$CGI_URI/admin/move.pl?id=$catalogs[$catalog_index]{id}&d=swap&other=$catalogs[$catalog_index-1]{id}&refreshto=$refreshto&all=1"><img src="$IMAGES_URI/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        return $html;
      },
      ifShowStepKids => sub { $session->{showstepkids} },
@@ -546,12 +570,18 @@ sub product_form {
 
   my @templates;
   push(@templates, "shopitem.tmpl")
-    if -e "$TMPLDIR/shopitem.tmpl";
-  if (opendir PROD_TEMPL, "$TMPLDIR/products") {
-    push @templates, map "products/$_",
-      grep -f "$TMPLDIR/products/$_" && /\.tmpl$/i, readdir PROD_TEMPL;
-    closedir PROD_TEMPL;
+    if grep -e "$_/shopitem.tmpl", BSE::Template->template_dirs($cfg);
+  for my $dir (BSE::Template->template_dirs($cfg)) {
+    if (opendir PROD_TEMPL, "$dir/products") {
+      push @templates, map "products/$_",
+       grep -f "$dir/products/$_" && /\.tmpl$/i, readdir PROD_TEMPL;
+      closedir PROD_TEMPL;
+    }
   }
+  my %seen_templates;
+  @templates = sort { lc($a) cmp lc($b) } 
+    grep !$seen_templates{$_}++, @templates;
+
   my $stepcat_index;
   use OtherParents;
   # ugh
@@ -570,6 +600,8 @@ sub product_form {
 #      if $product->{id};
   my $image_index;
 
+  my $blank = qq!<img src="$IMAGES_URI/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
+
   my %acts;
   %acts =
     (
@@ -613,16 +645,23 @@ sub product_form {
        my $html = '';
        my $refreshto = CGI::escape($ENV{SCRIPT_NAME}
                                   ."?id=$product->{id}&$template=1#step");
+       @stepcats > 1 or return '';
        if ($stepcat_index < $#stepcats) {
         $html .= <<HTML;
 <a href="$CGI_URI/admin/move.pl?stepchild=$product->{id}&id=$stepcats[$stepcat_index]{parentId}&d=swap&other=$stepcats[$stepcat_index+1]{parentId}&refreshto=$refreshto&all=1"><img src="$IMAGES_URI/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
        }
+       else {
+         $html .= $blank;
+       }
        if ($stepcat_index > 0) {
         $html .= <<HTML;
 <a href="$CGI_URI/admin/move.pl?stepchild=$product->{id}&id=$stepcats[$stepcat_index]{parentId}&d=swap&other=$stepcats[$stepcat_index-1]{parentId}&refreshto=$refreshto&all=1"><img src="$IMAGES_URI/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
        }
+       else {
+         $html .= $blank;
+       }
        return $html;
      },
      ifStepcatPossibles => sub { @stepcat_possibles },
@@ -1037,10 +1076,7 @@ sub product_edit_refresh {
 sub page {
   my ($which, $acts, $iter) = @_;
 
-  my $templ = Squirrel::Template->new;
-
-  print "Content-Type: text/html\n\n";
-  print $templ->show_page($TMPLDIR, 'admin/' . $which . ".tmpl", $acts, $iter);
+  BSE::Template->show_page('admin/'.$which, $cfg, $acts);
 }
 
 sub shop_url {
index 7c743d0824498dcd421f2edcfac8c0822a3971b2..a0bae16cfab1f7efcf15b7982ff8d82dac995588 100755 (executable)
@@ -9,7 +9,6 @@ use BSE::SubscriptionTypes;
 use BSE::DB;
 use BSE::Util::Tags;
 use BSE::Template;
-use Constants qw($TMPLDIR);
 use Articles;
 use Util qw/refresh_to/;
 use BSE::Message;
@@ -78,15 +77,16 @@ sub _template_popup {
     $base = $cfg->entry('subscriptions', "${type}_templates")
       || $type;
   }
-  if (opendir TEMPL, "$TMPLDIR/$base") {
-    push(@templates, sort map "$base/$_",
-        grep -f "$TMPLDIR/$base/$_" && /\.tmpl$/i, readdir TEMPL);
-    closedir TEMPL;
-    @templates or push(@templates, "Could not find templates in $base");
-  }
-  else {
-    push(@templates, "Cannot open dir $TMPLDIR/$base");
+  for my $dir (BSE::Template->template_dirs($cfg)) {
+    if (opendir TEMPL, "$dir/$base") {
+      push(@templates, sort map "$base/$_",
+          grep -f "$dir/$base/$_" && /\.tmpl$/i, readdir TEMPL);
+      closedir TEMPL;
+    }
   }
+  my %seen_templates;
+  @templates = sort grep !$seen_templates{$_}, @templates;
+  @templates or push(@templates, "Could not find templates in $base");
   my $def = $old ? $q->param($name) :
     $sub ? $sub->{$name} : $templates[0];
   my %labels;
@@ -189,7 +189,7 @@ sub validate {
       if ($value =~ /\.\./) {
        push(@$errors, [ $field, "Template $value is invalid, contains .." ]);
       }
-      elsif (!-f "$TMPLDIR/$value") {
+      elsif (!BSE::Template->find_source($value, $cfg)) {
        push(@$errors, [ $field, "Template $value does not exist" ]);
       }
     }
@@ -324,7 +324,7 @@ sub send_form {
      ifError => sub { 0 },
      old => sub { CGI::escapeHTML(defined $sub->{$_[0]} ? $sub->{$_[0]} : '') },
      template => sub { return _template_popup($cfg, $q, $sub, 0, $_[0]) },
-     parent=> sub { _parent_popup($sub, {})  },
+     parent=> sub { _parent_popup($sub)  },
     );
   BSE::Template->show_page('admin/subs/send_form', $cfg, \%acts);
 }
@@ -362,31 +362,6 @@ EOS
   }
 }
 
-#  sub _text_format {
-#    my ($cfg, $article, $user, $template) = @_;
-
-#    my %acts;
-#    %acts =
-#      (
-#       article=>sub { $article->{$_[0]} },
-#       ifUser => sub { $user },
-#       user =>
-#       sub {
-#         $user or return '';
-#         defined $user->{$_[0]} or return '';
-#         $user->{$_[0]}
-#       },
-#       body =>
-#       sub {
-#         _format_body($cfg, $article->{body});
-#       },
-#      );
-#    my $base = $cfg->entry('paths', 'templates') 
-#      || $TMPLDIR;
-#    my $obj = Squirrel::Template->new(template_dir=>$base);
-#    return $obj->show_page($base, $template, \%acts);
-#  }
-
 sub _dummy_user {
   my %user;
   $user{id} = 0;
index ae59c38672f6ddecf947ac7d11dbe41536d910b6..89e7c3667e948e7ff172a71609756a52e468b32e 100644 (file)
@@ -81,18 +81,7 @@ sub allkids {
 sub all_visible_kids {
   my ($self) = @_;
 
-  require 'OtherParents.pm';
-
-  my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
-  my @normalkids = Articles->listedChildren($self->{id});
-  my %order = (
-              (map { $_->{id}, $_->{displayOrder} } @normalkids ),
-              (map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
-             );
-  my @stepkids = $self->visible_stepkids;
-  my %kids = map { $_->{id}, $_ } @stepkids, @normalkids;
-
-  return @kids{ sort { $order{$b} <=> $order{$a} } keys %kids };
+  Articles->all_visible_kids($self->{id});
 }
 
 sub images {
index 3279651d459be9abbf4ff996c5e59f4465317825..b7081874f46e0aeab8c6280e70780dc8f345c4e7 100644 (file)
@@ -56,4 +56,31 @@ sub allids {
   }
 }
 
+sub visible_stepkids {
+  my ($self, $id) = @_;
+
+  use BSE::Util::SQL qw/now_sqldate/;
+  my $today = now_sqldate();
+
+  return Articles->getSpecial('visibleStepKids', $id, $today);
+}
+
+sub all_visible_kids {
+  my ($self, $id) = @_;
+
+  require 'OtherParents.pm';
+
+  my @otherlinks = OtherParents->getBy(parentId=>$id);
+  my @normalkids = Articles->listedChildren($id);
+  my %order = (
+              (map { $_->{id}, $_->{displayOrder} } @normalkids ),
+              (map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
+             );
+  my @stepkids = $self->visible_stepkids($id);
+  my %kids = map { $_->{id}, $_ } @stepkids, @normalkids;
+
+  return @kids{ sort { $order{$b} <=> $order{$a} } keys %kids };
+}
+
+
 1;
index 2bc58c0110af9f36baa95aacb7c0b81a8f769de8..385eef64403e4938717ee8b6dd7ba9421877cbeb 100644 (file)
@@ -412,7 +412,7 @@ sub templates {
 
   my @dirs = $self->template_dirs($article);
   my @templates;
-  my $basedir = $self->{cfg}->entry('paths', 'templates', $Constants::TMPLDIR);
+  my $basedir = $self->{cfg}->entryVar('paths', 'templates');
   for my $dir (@dirs) {
     my $path = File::Spec->catdir($basedir, $dir);
     if (-d $path) {
@@ -429,7 +429,7 @@ sub templates {
 sub extra_templates {
   my ($self, $article) = @_;
 
-  my $basedir = $self->{cfg}->entry('paths', 'templates', $Constants::TMPLDIR);
+  my $basedir = $self->{cfg}->entryVar('paths', 'templates');
   my @templates;
   if (my $id = $article->{id}) {
     push @templates, 'index.tmpl'
@@ -501,6 +501,8 @@ sub tag_move_stepkid {
   $req->user_can(edit_reorder_children => $article)
     or return '';
 
+  @$allkids > 1 or return '';
+
   my $cgi_uri = $self->{cfg}->entry('uri', 'cgi', '/cgi-bin');
   my $images_uri = $self->{cfg}->entry('uri', 'images', '/images');
   my $html = '';
@@ -510,16 +512,23 @@ sub tag_move_stepkid {
   }
   $url .= "#step";
   my $refreshto = CGI::escape($url);
+  my $blank = qq!<img src="$images_uri/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
   if ($$rallkids_index < $#$allkids) {
     $html .= <<HTML;
 <a href="$cgi_uri/admin/move.pl?stepparent=$article->{id}&d=swap&id=$allkids->[$$rallkids_index]{id}&other=$allkids->[$$rallkids_index+1]{id}&refreshto=$refreshto"><img src="$images_uri/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
   }
+  else {
+    $html .= $blank;
+  }
   if ($$rallkids_index > 0) {
     $html .= <<HTML;
 <a href="$cgi_uri/admin/move.pl?stepparent=$article->{id}&d=swap&id=$allkids->[$$rallkids_index]{id}&other=$allkids->[$$rallkids_index-1]{id}&refreshto=$refreshto"><img src="$images_uri/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
   }
+  else {
+    $html .= $blank;
+  }
   return $html;
 }
 
@@ -591,6 +600,8 @@ sub tag_move_stepparent {
   $req->user_can(edit_reorder_stepparents => $article)
     or return '';
 
+  @$stepparents > 1 or return '';
+
   my $cgi_uri = $self->{cfg}->entry('uri', 'cgi', '/cgi-bin');
   my $images_uri = $self->{cfg}->entry('uri', 'images', '/images');
   my $html = '';
@@ -599,17 +610,24 @@ sub tag_move_stepparent {
     $url .= "&_t=".$cgi->param('_t');
   }
   $url .= "#stepparents";
+  my $blank = qq!<img src="$images_uri/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
   my $refreshto = CGI::escape($url);
   if ($$rindex < $#$stepparents) {
     $html .= <<HTML;
 <a href="$cgi_uri/admin/move.pl?stepchild=$article->{id}&id=$stepparents->[$$rindex]{parentId}&d=swap&other=$stepparents->[$$rindex+1]{parentId}&refreshto=$refreshto&all=1"><img src="$images_uri/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
   }
+  else {
+    $html .= $blank;
+  }
   if ($$rindex > 0) {
     $html .= <<HTML;
 <a href="$cgi_uri/admin/move.pl?stepchild=$article->{id}&id=$stepparents->[$$rindex]{parentId}&d=swap&other=$stepparents->[$$rindex-1]{parentId}&refreshto=$refreshto&all=1"><img src="$images_uri/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
   }
+  else {
+    $html .= $blank;
+  }
   return $html;
 }
 
@@ -681,6 +699,8 @@ sub tag_movechild {
   $req->user_can('edit_reorder_children', $article)
     or return '';
 
+  @$kids > 1 or return '';
+
   $$rindex >=0 && $$rindex < @$kids
     or return '** movechild can only be used in the children iterator **';
 
@@ -733,6 +753,8 @@ sub tag_imgmove {
   $req->user_can(edit_images_reorder => $article)
     or return '';
 
+  @$images > 1 or return '';
+
   $$rindex >= 0 && $$rindex < @$images 
     or return '** imgmove can only be used in image iterator **';
 
@@ -764,6 +786,8 @@ sub tag_movefiles {
   $req->user_can('edit_files_reorder', $article)
     or return '';
 
+  @$files > 1 or return '';
+
   my $html = '';
 
   $$rindex >= 0 && $$rindex < @$files
index 4ae26ee6d5b6d16885affa67913a818daec5222e..e3a7109fd1921e9088146d83bbb5d0acc419a364 100644 (file)
@@ -3,6 +3,7 @@ use strict;
 use base 'BSE::Edit::Article';
 use Products;
 use HTML::Entities;
+use BSE::Template;
 
 my %money_fields =
   (
@@ -21,8 +22,9 @@ sub extra_templates {
   my ($self, $article) = @_;
 
   my @extras = $self->SUPER::extra_templates($article);
-  my $basedir = $self->{cfg}->entry('paths', 'templates', $Constants::TMPLDIR);
-  push @extras, 'shopitem.tmpl' if -f "$basedir/shopitem.tmpl";
+  push @extras, 'shopitem.tmpl' 
+    if grep -f "$_/shopitem.tmpl", 
+      BSE::Template->template_dirs($self->{cfg});
 
   return @extras;
 }
index 038d4e2762e158147e1b0c00a55250beb2aa8828..8c8e597f39c85ff73c67b0a7e9a08548b4a89159 100644 (file)
@@ -62,6 +62,8 @@ sub filelist {
 
   my @files = $self->_getfiles($article);
 
+  my $blank = qq!<img src="$IMAGES_URI/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
+
   my $message = $self->{cgi}->param('message') || '';
   my $file_index;
   my %acts;
@@ -75,16 +77,23 @@ sub filelist {
      move =>
      sub {
        my $html = '';
+       @files > 1 or return '';
        if ($file_index > 0) {
         $html .= <<HTML;
 <a href="$ENV{SCRIPT_NAME}?fileswap=1&id=$article->{id}&file1=$files[$file_index]{id}&file2=$files[$file_index-1]{id}"><img src="$IMAGES_URI/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        if ($file_index < $#files) {
         $html .= <<HTML;
 <a href="$ENV{SCRIPT_NAME}?fileswap=1&id=$article->{id}&file1=$files[$file_index]{id}&file2=$files[$file_index+1]{id}"><img src="$IMAGES_URI/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        $html;
      },
     );
index 0bd705b411e7ba1432c678f85e137d97f1d5185a..8196e4beccd841e25ab3485935f1450dc4c247f3 100644 (file)
@@ -98,10 +98,8 @@ sub _text_format_low {
      },
      sub => sub { $sub->{$_[0]} },
     );
-  my $base = $cfg->entry('paths', 'templates') 
-    || $Constants::TMPLDIR;
-  my $obj = Squirrel::Template->new(template_dir=>$base);
-  return $obj->show_page($base, $template, \%acts);
+  
+  return BSE::Template->get_page($template, $cfg, \%acts);
 }
 
 sub text_format {
index 110eb33dd3954c2c9a2429b9fca7bbe74a3e8604..2995a08e61bcd2c10f7c71de0452a74687f2fe68 100644 (file)
@@ -1,18 +1,27 @@
 package BSE::Template;
 use strict;
-use Constants qw/$TMPLDIR/;
 use Squirrel::Template;
+use Carp 'confess';
 
 sub get_page {
   my ($class, $template, $cfg, $acts) = @_;
 
-  my $base = $cfg->entry('paths', 'templates') 
-    || $TMPLDIR;
-  my $file = $cfg->entry('templates', $template) || "$template.tmpl";
+  my @dirs = $class->template_dirs($cfg);
+  my $file = $cfg->entry('templates', $template) || $template;
+  $file =~ /\.\w+$/ or $file .= ".tmpl";
 
-  my $obj = Squirrel::Template->new(template_dir => $base);
+  my $obj = Squirrel::Template->new(template_dir => \@dirs);
 
-  $obj->show_page($base, $file, $acts);
+  $obj->show_page(undef, $file, $acts);
+}
+
+sub replace {
+  my ($class, $source, $cfg, $acts) = @_;
+
+  my @dirs = $class->template_dirs($cfg);
+  my $obj = Squirrel::Template->new(template_dir => \@dirs);
+
+  $obj->replace_template($source, $acts);
 }
 
 sub html_type {
@@ -27,10 +36,22 @@ sub html_type {
 sub show_page {
   my ($class, $template, $cfg, $acts) = @_;
 
+  $class->show_literal($class->get_page($template, $cfg, $acts), $cfg);
+}
+
+sub show_replaced {
+  my ($class, $source, $cfg, $acts) = @_;
+
+  $class->show_literal($class->replace($source, $cfg, $acts), $cfg);
+}
+
+sub show_literal {
+  my ($class, $text, $cfg) = @_;
+
   my $type = $class->html_type($cfg);
 
   print "Content-Type: $type\n\n";
-  print $class->get_page($template, $cfg, $acts);
+  print $text;
 }
 
 sub get_response {
@@ -57,4 +78,47 @@ sub get_refresh {
     };
 }
 
+sub template_dirs {
+  my ($class, $cfg) = @_;
+
+  ref($cfg) eq 'BSE::Cfg'
+    or confess "Invalid cfg supplied\n";
+
+  my $base = $cfg->entryVar('paths', 'templates');
+  my $local = $cfg->entry('paths', 'local_templates');
+  my @dirs = ( $base );
+  unshift @dirs, $local if $local;
+
+  @dirs;
+}
+
+sub find_source {
+  my ($class, $template, $cfg) = @_;
+
+  my @dirs = $class->template_dirs($cfg);
+
+  my $file = $cfg->entry('templates', $template) || $template;
+  $file =~ /\.\w+$/ or $file .= ".tmpl";
+
+  for my $dir (@dirs) {
+    return "$dir/$file" if -f "$dir/$file";
+  }
+
+  return;
+}
+
+sub get_source {
+  my ($class, $template, $cfg) = @_;
+
+  my $path = $class->find_source($template, $cfg)
+    or confess "Cannot find template $template";
+  open SOURCE, "< $path"
+    or confess "Cannot open template $path: $!";
+  binmode SOURCE;
+  my $html = do { local $/; <SOURCE> };
+  close SOURCE;
+
+  $html;
+}
+
 1;
index 91a6cd8c3c5c009e313fc310fac692f99876e330..119f4c30b0260b94550d2e1b0747d84cd2545954 100644 (file)
@@ -64,6 +64,8 @@ sub static {
        my $value = $templater->perform($acts, $func, $args);
        defined $value
         or return '';
+       $value =~ /\d/
+        or print STDERR "Result '$value' from [$func $args] not a number\n";
        sprintf("%.02f", $value/100.0);
      },
      bodytext =>
index cee6ea9a2b39f5d2a7386b5afaa7d0ec9c58f806..acf32647fc5378feed4163d0a6c983971042feef 100644 (file)
@@ -5,11 +5,11 @@ use strict;
 use vars qw(@EXPORT_OK %EXPORT_TAGS @ISA $VERSION 
 $DSN $DBOPTS $DBCLASS $UN $PW $D_00 $D_99 $D_XX
 $SESSION_CLASS $SESSION_REQUIRE
-$TMPLDIR $IMAGEDIR $SEP %LEVEL_DEFAULTS $BASEDIR
+$IMAGEDIR $SEP %LEVEL_DEFAULTS $BASEDIR
 $MAXPHRASE $CONTENTBASE $SHOPID $PRODUCTPARENT $DATADIR $LINK_TITLES 
 @SEARCH_EXCLUDE @SEARCH_INCLUDE $SEARCH_LEVEL $SEARCH_ALL
 $SEARCH_WILDCARD_MIN $SEARCH_AUTO_WILDCARD $SEARCH_TITLE $SEARCH_TITLE_IMAGE
-%TEMPLATE_OPTS @NO_DELETE
+@NO_DELETE
 $SHOP_MAIL_SUBJECT $SHOP_PASSPHRASE $SHOP_CRYPTO $SHOP_SIGNING_ID
 $SHOP_GPG $SHOP_PGP $SHOP_FROM $SHOP_TO_NAME $SHOP_TO_EMAIL
 $SHOP_PGPE $SHOP_EMAIL_ORDER %SHOP_PRODUCT_OPTS
@@ -22,13 +22,13 @@ $VERSION = 0.1;
 
 require Exporter;
 @ISA = qw/Exporter/;
-@EXPORT_OK = qw/$DSN $DBOPTS $DBCLASS $UN $PW $D_00 $D_99 $D_XX $TMPLDIR $SEP
+@EXPORT_OK = qw/$DSN $DBOPTS $DBCLASS $UN $PW $D_00 $D_99 $D_XX $SEP
 $SESSION_CLASS $SESSION_REQUIRE
 $IMAGEDIR %LEVEL_DEFAULTS $BASEDIR $MAXPHRASE 
 $CONTENTBASE $SHOPID $PRODUCTPARENT $DATADIR $LINK_TITLES 
 @SEARCH_EXCLUDE @SEARCH_INCLUDE $SEARCH_LEVEL $SEARCH_ALL
 $SEARCH_WILDCARD_MIN $SEARCH_AUTO_WILDCARD $SEARCH_TITLE $SEARCH_TITLE_IMAGE
-%TEMPLATE_OPTS @NO_DELETE
+@NO_DELETE
 $SHOP_MAIL_SUBJECT $SHOP_PASSPHRASE $SHOP_CRYPTO 
 $SHOP_SIGNING_ID $SHOP_GPG $SHOP_PGP $SHOP_FROM %SHOP_PRODUCT_OPTS 
 $SHOP_TO_NAME $SHOP_TO_EMAIL $SHOP_EMAIL_ORDER $SHOP_PGPE
@@ -43,10 +43,10 @@ $HAVE_HTML_PARSER $UNLISTED_LEVEL1_IN_CRUMBS/;
                $SHOP_SIGNING_ID $SHOP_GPG $SHOP_PGP $SHOP_FROM 
                $SHOP_TO_NAME $SHOP_TO_EMAIL $SHOP_PGPE
                $SHOP_EMAIL_ORDER $SHOP_URI %SHOP_PRODUCT_OPTS/ ],
-   edit=> [ qw/$TMPLDIR $IMAGEDIR $D_00 $D_99 @NO_DELETE 
+   edit=> [ qw/$IMAGEDIR $D_00 $D_99 @NO_DELETE 
                $ARTICLE_URI $CGI_URI $SHOP_URI $ROOT_URI
               $AUTO_GENERATE $REPARENT_UPDOWN/ ],
-   search => [ qw/$TMPLDIR @SEARCH_EXCLUDE @SEARCH_INCLUDE $SEARCH_ALL
+   search => [ qw/@SEARCH_EXCLUDE @SEARCH_INCLUDE $SEARCH_ALL
                   $SEARCH_WILDCARD_MIN $SEARCH_AUTO_WILDCARD/ ],
    session => [ qw/$SESSION_CLASS $SESSION_REQUIRE/ ],
    #email => [ qw/$SMTP_SERVER $SMTP_HELO $SHOP_SENDMAIL/ ],
@@ -72,7 +72,7 @@ $BASEDIR = '/home/httpd/bsetest';
 #$BASEDIR = 'c:/your_site';
 
 # where we keep templates
-$TMPLDIR = $BASEDIR.'/templates/';
+$TMPLDIR = $BASEDIR.'/templates/';
 
 # where the html is kept
 $CONTENTBASE = $BASEDIR.'/htdocs/';
@@ -356,7 +356,7 @@ $D_99 = '9999-12-31 23:59:59' ;
 use POSIX qw/strftime/; 
 $D_XX = sub { strftime "%Y-%m-%d %H:%M:%S" => (localtime)[0..5] };
 
-%TEMPLATE_OPTS = ( template_dir => $TMPLDIR );
+%TEMPLATE_OPTS = ( template_dir => $TMPLDIR );
 
 
 1;
index f1a0589cb1665d7a8e55e56e27276b15fd8e81d1..0b83364ebfd62c2fded2364bd264fda6bc0b37be 100644 (file)
@@ -2,7 +2,7 @@ package Generate;
 use strict;
 use Articles;
 use CGI ();
-use Constants qw($IMAGEDIR $LOCAL_FORMAT $TMPLDIR $BODY_EMBED 
+use Constants qw($IMAGEDIR $LOCAL_FORMAT $BODY_EMBED 
                  $EMBED_MAX_DEPTH $HAVE_HTML_PARSER);
 use BSE::Custom;
 use DevHelp::Tags;
@@ -254,8 +254,10 @@ sub _make_img {
     $text = qq!<img src="/images/$im->{image}" width="$im->{width}"!
       . qq! height="$im->{height}" alt="! . CGI::escapeHTML($im->{alt}).'"'
        . qq! border="0"!;
-    $text .= qq! align="$align"! if $align;
+    $text .= qq! align="$align"! if $align && $align ne 'center';
     $text .= qq! />!;
+    $text = qq!<div align="center">$text</div>!
+      if $align && $align eq 'center';
     if (!$url && $im->{url}) {
       $url = $im->{url};
     }
@@ -317,6 +319,14 @@ sub format_body {
          and next TRY;
        $part =~ s#i\[([^\]\[]+)\]#<i>$1</i>#ig
          and next TRY;
+       $part =~ s#tt\[([^\]\[]+)\]#<tt>$1</tt>#ig
+         and next TRY;
+       $part =~ s#pre\[([^\]\[]+)\]#<pre>$1</pre>#ig
+         and next TRY;
+       $part =~ s#h([1-6])\[\|([^\[\]]+)\](?:\r?\n)?#<h$1>$2</h$1>#ig
+          and next TRY;
+       $part =~ s#h([1-6])\[([^\[\]\|]+)\|([^\[\]]+)\](?:\r?\n)?#<h$1 class="$2">$3</h$1>#ig
+          and next TRY;
        $part =~ s#align\[([^|\]\[]+)\|([^\]\[]+)\]#<div align="$1">$2</div>#ig
          and next TRY;
        $part =~ s#font\[([^|\]\[]+)\|([^\]\[]+)\]#<font size="$1">$2</font>#ig
@@ -345,9 +355,12 @@ sub format_body {
          and next TRY;
        $part =~ s#image\[([^\]\[]+)\]#($auto_images = 0), _make_img($1, \$imagePos, \@images)#ige
          and next TRY;
+       $part =~ s#class\[([^\]\[\|]+)\|([^\]\[]+)\]#<span class="$1">$2</span>#ig
+         and next TRY;
+       
        last;
       }
-      $part =~ s/\n([ \r]*\n)+/<p>/g;
+      $part =~ s!\n([ \r]*\n)+!</p><p>!g;
       $part =~ s/\n/<br \/>/g;
       $out .= $part;
     }
@@ -426,10 +439,7 @@ sub embed {
       unless defined($template) && $template =~ /\S/;
   }
 
-  open SOURCE, "< $TMPLDIR$template"
-    or die "Cannot open template $template: $!";
-  my $html = do { local $/; <SOURCE> };
-  close SOURCE;
+  my $html = BSE::Template->get_source($template, $self->{cfg});
 
   # the template will hopefully contain <:embed start:> and <:embed end:>
   # tags
@@ -454,6 +464,19 @@ sub iter_kids_of {
   map Articles->listedChildren($_), @ids;
 }
 
+sub iter_all_kids_of {
+  my ($args, $acts, $name, $templater) = @_;
+
+  my @ids = split ' ', $args;
+  for my $id (@ids) {
+    unless ($id =~ /^\d+$|^-1$/) {
+      $id = $templater->perform($acts, $id, "id");
+    }
+  }
+  @ids = grep /^\d+$|^-1$/, @ids;
+  map Articles->all_visible_kids($_), @ids;
+}
+
 sub iter_inlines {
   my ($args, $acts, $name, $templater) = @_;
 
@@ -589,6 +612,8 @@ sub baseActs {
      DevHelp::Tags->make_iterator2
      ( \&iter_kids_of, 'ofchild', 'children_of' ), 
      DevHelp::Tags->make_iterator2
+     ( \&iter_all_kids_of, 'ofallkid', 'allkids_of' ), 
+     DevHelp::Tags->make_iterator2
      ( \&iter_inlines, 'inline', 'inlines' ),
     );
 }
index 691234ec830bcddc3567fb22b0fb2ab55dce4cbd..80f8c22a7b7012e873956c7c41fa8e8b8b213898 100644 (file)
@@ -1,8 +1,8 @@
 package Generate::Article;
 use strict;
-use Squirrel::Template;
-use Constants qw($TMPLDIR %TEMPLATE_OPTS %LEVEL_DEFAULTS 
-                 $CGI_URI $ADMIN_URI $IMAGES_URI $UNLISTED_LEVEL1_IN_CRUMBS);
+use BSE::Template;
+use Constants qw(%LEVEL_DEFAULTS $CGI_URI $ADMIN_URI $IMAGES_URI 
+                 $UNLISTED_LEVEL1_IN_CRUMBS);
 use Images;
 use vars qw(@ISA);
 use Generate;
@@ -55,9 +55,7 @@ sub generate_low {
   my %acts;
   %acts = $self -> baseActs($articles, \%acts, $article, $embedded);
 
-
-  return Squirrel::Template->new(%TEMPLATE_OPTS)
-    ->replace_template($template, \%acts);
+  return BSE::Template->replace($template, $self->{cfg}, \%acts);
 }
 
 sub baseActs {
@@ -92,6 +90,8 @@ sub baseActs {
   my @files = sort { $b->{displayOrder} <=> $a->{displayOrder} }
     ArticleFiles->getBy(articleId=>$article->{id});
   
+  my $blank = qq!<img src="$IMAGES_URI/trans_pixel.gif"  width="17" height="13" border="0" align="absbottom" />!;
+
   my @stepkids;
   my @allkids;
   my @stepparents;
@@ -287,28 +287,31 @@ HTML
      # for rearranging order in admin mode
      moveDown=>
      sub {
+       @children > 1 or return '';
        if ($self->{admin} && $child_index < $#children) {
          return <<HTML;
 <a href="$CGI_URI/admin/move.pl?id=$children[$child_index]{id}&d=down"><img src="$IMAGES_URI/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
        } else {
-         return '';
+         return $blank;
        }
      },
      moveUp=>
      sub {
+       @children > 1 or return '';
        if ($self->{admin} && $child_index > 0) {
          return <<HTML;
 <a href="$CGI_URI/admin/move.pl?id=$children[$child_index]{id}&d=up"><img src="$IMAGES_URI/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
        } else {
-         return '';
+         return $blank;
        }
      },
      movestepkid =>
      sub {
        my $html = '';
        return '' unless $self->{admin};
+       return '' unless @allkids > 1;
        my $refreshto = CGI::escape($ENV{SCRIPT_NAME}
                                   ."?id=$article->{id}");
        if ($allkids_index < $#allkids) {
@@ -316,11 +319,17 @@ HTML
 <a href="$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$allkids[$allkids_index]{id}&other=$allkids[$allkids_index+1]{id}&refreshto=$refreshto"><img src="$IMAGES_URI/admin/move_down.gif" width="17" height="13" border="0" alt="Move Down" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        if ($allkids_index > 0) {
         $html .= <<HTML
 <a href="$CGI_URI/admin/move.pl?stepparent=$article->{id}&d=swap&id=$allkids[$allkids_index]{id}&other=$allkids[$allkids_index-1]{id}&refreshto=$refreshto"><img src="$IMAGES_URI/admin/move_up.gif" width="17" height="13" border="0" alt="Move Up" align="absbottom"></a>
 HTML
        }
+       else {
+        $html .= $blank;
+       }
        return $html;
      },
      ifCurrentPage=>
@@ -401,11 +410,7 @@ HTML
 sub generate {
   my ($self, $article, $articles) = @_;
 
-  open SOURCE, "< $TMPLDIR$article->{template}"
-    or die "Cannot open template $article->{template}: $!";
-  my $html = do { local $/; <SOURCE> };
-  close SOURCE;
-
+  my $html = BSE::Template->get_source($article->{template}, $self->{cfg});
   $html =~ s/<:\s*embed\s+(?:start|end)\s*:>//g;
 
   return $self->generate_low($html, $article, $articles, 0);
index 34524abc93cadc915af7178a4067f3c00900b060..8ba58214fcecf3fabaa9ed09f9cec05def180c07 100644 (file)
@@ -4,9 +4,8 @@ use strict;
 use Generate;
 use Products;
 use base 'Generate::Article';
-use Squirrel::Template;
-use Constants qw($TMPLDIR %TEMPLATE_OPTS $CGI_URI $IMAGES_URI
-                 $ADMIN_URI);
+use BSE::Template;
+use Constants qw($CGI_URI $IMAGES_URI $ADMIN_URI);
 use Util qw(generate_button);
 use OtherParents;
 
@@ -38,7 +37,7 @@ sub generate_low {
   my %acts;
   %acts =
     (
-     $self->baseActs($articles, \%acts, $article, 0),
+     $self->baseActs($articles, \%acts, $article, $embedded),
      article => sub { CGI::escapeHTML($article->{$_[0]}) },
      iterate_products =>
      sub {
@@ -132,6 +131,7 @@ HTML
        return '' unless $self->{request};
        return '' 
         unless $self->{request}->user_can(edit_reorder_children => $article);
+       return '' unless @allprods > 1;
        my $html = '';
        my $can_move_up = $allprod_index > 0;
        my $can_move_down = $allprod_index < $#allprods;
@@ -182,45 +182,19 @@ HTML
       return $value;
     };
 
-  return Squirrel::Template->new(%TEMPLATE_OPTS)
-    ->replace_template($template, \%acts);
+  return BSE::Template->replace($template, $self->{cfg}, \%acts);
 }
 
 sub generate {
   my ($self, $article, $articles) = @_;
 
-  open SOURCE, "< $TMPLDIR$article->{template}"
-    or die "Cannot open template $article->{template}: $!";
-  my $html = do { local $/; <SOURCE> };
-  close SOURCE;
+  my $html = BSE::Template->get_source($article->{template}, $self->{cfg});
 
   $html =~ s/<:\s*embed\s+(?:start|end)\s*:>//g;
   
   return $self->generate_low($html, $article, $articles, 0);
 }
 
-sub embed {
-  my ($self, $article, $articles, $template) = @_;
-
-  $template = $article->{template}
-    unless defined($template) && $template =~ /\S/;
-
-  open SOURCE, "< $TMPLDIR$template"
-    or die "Cannot open template $template: $!";
-  my $html = do { local $/; <SOURCE> };
-  close SOURCE;
-
-  # the template will hopefully contain <:embed start:> and <:embed end:>
-  # tags
-  # otherwise pull out the body content
-  if ($html =~ /<:\s*embed\s*start\s*:>(.*)<:\s*embed\s*end\s*:>/s
-     || $html =~ m"<\s*body[^>]*>(.*)<\s*/\s*body>"s) {
-    $html = $1;
-  }
-
-  return $self->generate_low($html, $article, $articles);
-}
-
 1;
 
 __END__
index f1996aa67219aeaa32c9315eb0092743183928c3..b34d26713c9db940999db8eecf866eda1b9ddd96 100644 (file)
@@ -4,8 +4,7 @@ use Generate::Article;
 use Products;
 use Images;
 use base qw(Generate::Article);
-use Squirrel::Template;
-use Constants qw(:shop $TMPLDIR %TEMPLATE_OPTS $CGI_URI $ADMIN_URI);
+use Constants qw(:shop $CGI_URI $ADMIN_URI);
 use Carp qw(confess);
 
 sub edit_link {
@@ -36,7 +35,7 @@ sub baseActs {
 
   return
     (
-     $self->SUPER::baseActs($articles, $acts, $product, 0),
+     $self->SUPER::baseActs($articles, $acts, $product, $embedded),
      product=> sub { CGI::escapeHTML($product->{$_[0]}) },
      admin =>
      sub {
index 6e992e0a28d8e0ddfce59abd65b278f489a75848..dd24adddd8febd03bad1cb436986becae7eaf533 100644 (file)
@@ -2,6 +2,7 @@ package Squirrel::Template;
 use vars qw($VERSION);
 use strict;
 use Carp qw/cluck confess/;
+use constant DEBUG => 0;
 
 $VERSION="0.05";
 
@@ -138,17 +139,22 @@ sub iterate {
 sub cond {
   my ($self, $name, $args, $true, $false, $acts, $orig) = @_;
 
+  print STDERR "cond $name $args\n" if DEBUG;
+
   my $result =
     eval {
       if (exists $acts->{"if$name"}) {
+       print STDERR " found cond if$name\n" if DEBUG > 1;
        my $cond = $self->low_perform($acts, "if$name", $args, '');
        return $cond ? $true : $false;
       }
       elsif (exists $acts->{lcfirst $name}) {
+       print STDERR " found cond $name\n" if DEBUG > 1;
        my $cond = $self->low_perform($acts, lcfirst $name, $args, '');
        return $cond ? $true : $false;
       }
       else {
+       print STDERR " not found\n" if DEBUG > 1;
        return $orig;
       }
     };
@@ -164,6 +170,39 @@ sub cond {
   return $result;
 }
 
+sub find_template {
+  my ($self, $name) = @_;
+
+  return unless $self->{template_dir};
+
+  my @dirs = ref $self->{template_dir} ? @{$self->{template_dir}} : $self->{template_dir};
+  for my $dir (@dirs) {
+    if (-e "$dir/$name") {
+      return "$dir/$name";
+    }
+  }
+
+  return;
+}
+
+sub include {
+  my ($self, $name) = @_;
+
+  print STDERR "Including $name\n";
+
+  my $filename = $self->find_template($name)
+    or return "** cannot find include $name in path **";
+
+  print STDERR "Found $filename\n";
+
+  open INCLUDE, "< $filename"
+    or return "** cannot open $filename : $! **";
+  my $data = do { local $/; <INCLUDE> };
+  close INCLUDE;
+
+  return $data;
+}
+
 sub tag_param {
   my ($params, $arg) = @_;
 
@@ -183,9 +222,10 @@ sub replace_template {
   if ($self->{template_dir}) {
     my $wrap_count = 0;
     while ($template =~ /^(\s*<:\s*wrap\s+(\S+?)(?:\s+(\S.*?))?:>)/i) {
-      my $wrapper = "$self->{template_dir}/$2";
-      unless (-e $wrapper) {
-       print STDERR "WARNING: Unknown wrap name: $wrapper\n";
+      my $name = $2;
+      my $wrapper = $self->find_template($name);
+      unless ($wrapper) {
+       print STDERR "WARNING: Unknown wrap name: $name\n";
        last;
       }
       unless (++$wrap_count < 10) {
@@ -217,7 +257,23 @@ sub replace_template {
     }
   }
 
-  $acts->{param} = [ \&tag_param, \%params ];
+  $acts->{param} ||= [ \&tag_param, \%params ];
+
+  if ($self->{template_dir} && !$acts->{include}) {
+    my $loops = 0;
+    1 while $template =~
+            s!<:
+                \s*
+                include
+                \s+
+                ((?:\w+/)*\w+(?:\.\w+)?)
+                \s*
+               :>
+             ! 
+               $self->include($1) 
+             !gex
+              && ++$loops < 10;
+  }
 
   # the basic iterator
   if ($iter && 
@@ -254,7 +310,7 @@ sub replace_template {
                          <:\s*eif\s+\2\s*:>)/
                         $self->cond($2, $3, $4, $5, $acts, $1) /sgex
                          && ++$nesting < 5;
-  $template =~ s/(<:\s*if(\w+)(?:\s+(.*?))?\s*:>
+  $template =~ s/(<:\s*if([A-Z]\w*)(?:\s+(.*?))?\s*:>
                   (.*?)
                  <:\s*or\s*:>
                   (.*?)
@@ -277,7 +333,14 @@ sub show_page {
 
   $acts ||= {};
 
-  my $file = $page ? "$base/$page" : $base;
+  my $file;
+  if ($base) {
+    $file = $page ? "$base/$page" : $base;
+  }
+  else {
+    $file = $self->find_template($page)
+      or die "Cannot find template $page";
+  }
   open TMPLT, "< $file"
     or die "Cannot open template $file: $!";
   my $template = do { local $/; <TMPLT> };
@@ -318,7 +381,9 @@ message rather than being left in place.
 =item template_dir
 
 Used by the wrapper mechanism to find wrapper templates.  See
-L<WRAPPING> below.
+L<WRAPPING> below.  This can be either a scalar, or a reference to an
+array of locations to search for the wrapper.  This is also used for
+the <:include filename:> mechanism.
 
 =back
 
index f0b68993a3ebc0606ed54222466a654ee498c7a1..b38dc1e5f84934a80758ca9e7f4760ab04cf95a8 100644 (file)
@@ -5,8 +5,8 @@ require Exporter;
 @ISA = qw(Exporter);
 @EXPORT_OK = qw(generate_article generate_all generate_button 
                 refresh_to regen_and_refresh);
-use Constants qw($CONTENTBASE $TMPLDIR %TEMPLATE_OPTS
-                $GENERATE_BUTTON $SHOPID $AUTO_GENERATE);
+use Constants qw($CONTENTBASE $GENERATE_BUTTON $SHOPID $AUTO_GENERATE);
+use Carp qw(confess);
 
 my %gen_cache;
 
@@ -73,10 +73,12 @@ sub generate_article {
 
 # generates search.tmpl from search_base.tmpl
 sub generate_search {
-  my ($articles) = @_;
+  my ($articles, $cfg) = @_;
+
+  $cfg or confess "Call generate search with a config object";
 
   require 'Generate/Article.pm';
-  my $gen = Generate::Article->new;
+  my $gen = Generate::Article->new(cfg=>$cfg);
 
   # build a dummy article
   use Constants qw($SEARCH_TITLE $SEARCH_TITLE_IMAGE $CGI_URI);
@@ -86,10 +88,10 @@ sub generate_search {
 
   my %acts;
   %acts = $gen->baseActs($articles, \%acts, \%article);
-  my $templ = Squirrel::Template->new(%TEMPLATE_OPTS);
-  my $content = $templ->show_page($TMPLDIR, 'search_base.tmpl', \%acts);
-  my $outname = "$TMPLDIR/search.tmpl.work";
-  my $finalname = "$TMPLDIR/search.tmpl";
+  my $content = BSE::Template->get_page('search_base', $cfg, \%acts);
+  my $tmpldir = $cfg->entryVar('paths', 'templates');
+  my $outname = "$tmpldir/search.tmpl.work";
+  my $finalname = "$tmpldir/search.tmpl";
   open OUT, "> $outname"
     or die "Cannot open $outname for write: $!";
   print OUT $content
@@ -125,10 +127,10 @@ sub generate_shop {
         }
         return $value;
       };
-    my $templ = Squirrel::Template->new(%TEMPLATE_OPTS);
-    my $content = $templ->show_page($TMPLDIR, "${name}_base.tmpl", \%acts);
-    my $outname = "$TMPLDIR/$name.tmpl.work";
-    my $finalname = "$TMPLDIR/$name.tmpl";
+    my $content = BSE::Template->get_page("${name}_base", $cfg, \%acts);
+    my $tmpldir = $cfg->entryVar('paths', 'templates');
+    my $outname = "$tmpldir/$name.tmpl.work";
+    my $finalname = "$tmpldir/$name.tmpl";
     open OUT, "> $outname"
       or die "Cannot open $outname for write: $!";
     print OUT $content
@@ -146,7 +148,7 @@ sub generate_extras {
 
   use BSE::Cfg;
   $cfg ||= BSE::Cfg->new;
-  my $template_dir = $cfg->entry('paths', 'templates') || $TMPLDIR;
+  my $template_dir = $cfg->entryVar('paths', 'templates');
 
   open EXTRAS, "$template_dir/extras.txt"
     or return;
@@ -176,9 +178,7 @@ sub generate_extras {
        }
        return $value;
       };
-    my $templ = Squirrel::Template->new(%TEMPLATE_OPTS, 
-                                       template_dir=>$template_dir);
-    my $content = $templ->show_page($template_dir, $in, \%acts);
+    my $content = BSE::Template->get_page($in, $cfg, \%acts);
     my $outname = $CONTENTBASE . $out . ".work";
     my $finalname = $CONTENTBASE . $out;
     open OUT, "> $outname"
@@ -221,9 +221,7 @@ sub generate_extras {
          }
          return $value;
        };
-      my $templ = Squirrel::Template->new(%TEMPLATE_OPTS, 
-                                         template_dir=>$template_dir);
-      my $content = $templ->show_page($template_dir, $input, \%acts);
+      my $content = BSE::Template->get_page($input, $cfg, \%acts);
       my $outname = $template_dir .'/'.$out.'.work';
       my $finalname = $template_dir . '/'. $out;
       open OUT, "> $outname"
@@ -268,7 +266,7 @@ sub generate_all {
   %gen_cache = ();
 
   $callback->("Generating search base") if $callback;
-  generate_search($articles);
+  generate_search($articles, $cfg);
 
   $callback->("Generating shop base pages") if $callback;
   generate_shop($articles);
@@ -314,7 +312,7 @@ sub regen_and_refresh {
       if ($article) {
        if ($article eq 'extras') {
          $progress->("Generating search base") if $progress;
-         generate_search($articles);
+         generate_search($articles, $cfg);
          
          $progress->("Generating shop base pages") if $progress  ;
          generate_shop($articles);
index eb22b23417905838c5e5632d8c426cae85ce603b..8ccb659b1df80dc765b15be1b5e16cc407f3b37e 100755 (executable)
@@ -5,8 +5,6 @@ use lib "$FindBin::Bin/modules";
 use CGI qw(:standard);
 use Carp; # 'verbose'; # remove the 'verbose' in production
 use Articles;
-use Constants qw($TMPLDIR);
-use Squirrel::Template;
 use BSE::Cfg;
 use BSE::Template;
 
@@ -25,7 +23,7 @@ my $article = Articles->getByPkey($id)
 
 eval "use $article->{generator}";
 die $@ if $@;
-my $generator = $article->{generator}->new(articles=>'Articles');
+my $generator = $article->{generator}->new(articles=>'Articles', cfg => $cfg);
 
 my $template = param('template');
 
@@ -65,6 +63,7 @@ $text =~ s/<:\s*embed\s+(?:start|end)\s*:>//g;
 print "Content-Type: $type\n\n";
 print $generator->generate_low($text, $article, 'Articles');
 
+
 sub error_page {
   my ($error) = @_;
   $error ||= "Unknown error";
@@ -77,19 +76,13 @@ sub error_page {
      $gen->baseActs('Articles', \%acts),
      error => sub { CGI::escapeHTML($error) },
     );
-  print "Content-Type: text/html\n\n";
-  print Squirrel::Template->new(template_dir=>$TMPLDIR)
-    ->show_page($TMPLDIR, 'error.tmpl', \%acts);
+  
+  BSE::Template->show_page('error', $cfg, \%acts);
   exit;
 }
 
 sub file_from_template {
   my ($template) = @_;
 
-  my $file = $TMPLDIR;
-  $file .= "/" unless $file =~ m![\\/]$!;
-  $file .= "printable/";
-  $file .= $template;
-
-  return $file;
+  return BSE::Template->find_source($template, $cfg);
 }
index a4bccb1af1697542ab2fd0997a670f942a48acd3..e78619410018ddf06297c23d4efc9d9a658a8ed5 100755 (executable)
@@ -5,10 +5,10 @@ use FindBin;
 use lib "$FindBin::Bin/modules";
 use Articles;
 use BSE::DB;
-use Squirrel::Template;
 use Constants qw(:search);
 use Carp;
 use BSE::Cfg;
+use BSE::Template;
 
 my $cfg = BSE::Cfg->new;
 
@@ -151,9 +151,7 @@ my %acts;
    },
   );
 
-print "Content-Type: text/html\n\n";
-my $templ = Squirrel::Template->new();
-print $templ->show_page($TMPLDIR, "search.tmpl", \%acts);
+BSE::Template->show_page('search', $cfg, \%acts);
 
 sub getSearchResult {
   my ($words, $section, $date, $terms) = @_;
index 241b742b154db222dd922c09a6d8c6d9e57ba08e..b55b1584c5c4532f57bb9a9e4ae69add96624197 100755 (executable)
@@ -7,8 +7,8 @@ use lib "$FindBin::Bin/modules";
 use CGI ':standard';
 use Products;
 use Product;
-use Constants qw(:shop $TMPLDIR $CGI_URI);
-use Squirrel::Template;
+use Constants qw(:shop $CGI_URI);
+use BSE::Template;
 use CGI::Cookie;
 use BSE::Custom;
 use BSE::Mail;
@@ -803,15 +803,14 @@ sub send_order {
      ifOptions => sub { @options },
      options => sub { nice_options(@options) },
     );
-  my $templ = Squirrel::Template->new;
 
   my $mailer = BSE::Mail->new(cfg=>$cfg);
   # ok, send some email
-  my $confirm = $templ->show_page($TMPLDIR, 'mailconfirm.tmpl', \%acts);
+  my $confirm = BSE::Template->get_page('mailconfirm', $cfg, \%acts);
   if ($SHOP_EMAIL_ORDER) {
     $acts{cardNumber} = sub { param('cardNumber') };
     $acts{cardExpiry} = sub { param('cardExpiry') };
-    my $ordertext = $templ->show_page($TMPLDIR, 'mailorder.tmpl', \%acts);
+    my $ordertext = BSE::Template->get_page('mailorder', $cfg, \%acts);
 
     eval "use $crypto_class";
     !$@ or die $@;
@@ -850,8 +849,8 @@ sub send_order {
 
 sub page {
   my ($template, $acts) = @_;
-  print "Content-Type: text/html\n\n";
-  print Squirrel::Template->new->show_page($TMPLDIR, $template, $acts);
+
+  BSE::Template->show_page($template, $cfg, $acts);
 }
 
 # convert an epoch time to sql format
index 82160dd7dc4698f12f08e61d91f7f5b25a57abe8..ae2c61e1c43debe3d15f8bc577cbd6686860344c 100644 (file)
@@ -10,13 +10,76 @@ Maybe I'll add some other bits here.
 
 =head1 CHANGES
 
+=head2 0.12_22
+
+=over
+
+=item *
+
+added iterator allkids_of to iterate over the children and
+stepchildren of a given article.
+
+=over
+
+ <:iterator begin allkids_of I<parent_id1> ...:>
+ <:ofallkid I<field>:>
+ <:iterator end allkids_of:>
+
+=back
+
+=item *
+
+when you clicked send from the subscriptions list the archive parent
+field wasn't being set from the value set when adding/editing the
+subscription
+
+=item *
+
+generate_search() wasn't supplying a config object when creating the
+article generator.  This caused problems when some article types were
+embedded within the search page.
+
+=item *
+
+added mailing list info
+
+=item *
+
+$TMPLDIR is no longer present or used in Constants.pm.  Use templates
+in the [paths] section of the config file.
+
+=item *
+
+The path specified by the local_templates entry in [paths] is now
+searched for templates before the path specified by the templates
+entry in [paths].  This can be used to keep locally modified versions
+of templates separate from the distributed templates.
+
+=item *
+
+reordering arrows now display a filler image where there's a single
+missing arrow image (at the top and bottom of the list).  No spacer is
+displayed if there's a single item.
+
+=item *
+
+added tt[text], pre[text], h1[class|text] through h6[class|text],
+class[class|text] tags to the body text formatter.  Paragraphs are now
+closed by the body text formatter.
+
+=item *
+
+added a few more tests
+
+=back
+
 =head2 0.12_21
 
 =over
 
 =item *
 
-template change from adriam (edit_steps.tmpl):
+template change from adrian (edit_steps.tmpl):
 
 Finally fixed something that has bugged me for a while... I simply 
 moved the "if Kids" conditional to include the note about "Delete 
index 79a3ad0fe7df81e6fa765b7804daa57bcfb5d04c..bc08c0f37f0a39d19eadee575bb26fcb76d5851c 100644 (file)
@@ -34,8 +34,12 @@ directory under $TMPLDIR.
 
 =item templates
 
-Directory base for most templates.  Note: this is not completely
-implemented for now, so assume the default.  Default: $TMPLDIR.
+Directory base for most templates.
+
+=item local_templates
+
+Local Directory base for templates.  This is searched before the
+templates directory.
 
 =item images
 
index d7272f1d3f94c5a658d8ae67064055a78ba87de1..0db7fba1dba0dde15f4a6b1a5b1634058978428d 100644 (file)
@@ -70,9 +70,9 @@ sub skip {
 }
 
 sub make_ua {
-  require "WWW/Automate.pm";
+  require WWW::Mechanize;
   require "HTTP/Cookies.pm";
-  my $ua = WWW::Automate->new;
+  my $ua = WWW::Mechanize->new;
   $ua->cookie_jar(HTTP::Cookies->new);
 
   $ua;
index 74c80e1d6b68a0cd160924779c67a41f9ddb899a..ea142fd113e622c64824ee55c914bcb71d8219d4 100644 (file)
@@ -3,7 +3,7 @@ use strict;
 use BSE::Test;
 
 ++$|;
-print "1..43\n";
+print "1..45\n";
 my $baseurl = base_url;
 ok($baseurl =~ /^http:/, "basic check of base url");
 my $ua = make_ua;
@@ -45,4 +45,5 @@ fetch_ok($ua, "user list", "$baseurl/cgi-bin/admin/adminusers.pl",
         qr!Admin\sUsers!s);
 fetch_ok($ua, "group list", "$baseurl/cgi-bin/admin/adminusers.pl?a_groups=1",
         qr!Admin\sGroups!s);
-
+fetch_ok($ua, "subscriptions", "$baseurl/cgi-bin/admin/subs.pl",
+        qr/Subscriptions\s+List/);
index 6c96226012923b50911266e1059a9a1f3691685d..736f80e14cd4173f914812c4ea242cf3d8f66fd5 100644 (file)
@@ -2,7 +2,7 @@
 use strict;
 use BSE::Test qw(base_url make_ua fetch_ok skip check_form post_ok ok 
                  check_content);
-use WWW::Automate;
+#use WWW::Mechanize;
 ++$|;
 print "1..24\n";
 my $baseurl = base_url;
index 03f21bc4342dcde55f4acf72a2b1011f79f1bc87..587b2d19620bfc22752437911456600e6983eba7 100644 (file)
@@ -1,12 +1,14 @@
 #!perl -w
 use strict;
 use BSE::Test ();
-use Test::More tests=>31;
+use Test::More tests=>34;
 use File::Spec;
 use FindBin;
 my $cgidir = File::Spec->catdir(BSE::Test::base_dir, 'cgi-bin');
 ok(chdir $cgidir, "switch to CGI directory");
 push @INC, 'modules';
+require BSE::Cfg;
+my $cfg = BSE::Cfg->new;
 # create some articles to test with
 require Articles;
 require BSE::Util::SQL;
@@ -23,6 +25,10 @@ for my $name ('One', 'Two', 'Three') {
   push(@kids, $kid);
 }
 
+# make parent a step child of itself
+require BSE::Admin::StepParents;
+BSE::Admin::StepParents->add($parent, $parent);
+
 my $top = Articles->getByPkey(1);
 ok($top, "grabbing Home page");
 
@@ -37,6 +43,18 @@ One
 
 EXPECTED
 
+template_test "allkids_of", $top, <<TEMPLATE, <<EXPECTED;
+<:iterator begin allkids_of $parent->{id}:><:
+ofallkid title:>
+<:iterator end allkids_of:>
+TEMPLATE
+Parent
+Three
+Two
+One
+
+EXPECTED
+
 my @kidids = map $_->{id}, @kids;
 template_test "inlines", $top, <<TEMPLATE, <<EXPECTED;
 <:iterator begin inlines @kidids:><:
@@ -84,6 +102,7 @@ One
 
 EXPECTED
 
+BSE::Admin::StepParents->del($parent, $parent);
 for my $kid (reverse @kids) {
   my $name = $kid->{title};
   $kid->remove();
@@ -133,7 +152,7 @@ sub template_test($$$$) {
       (my $filename = $article->{generator}) =~ s!::!/!g;
       $filename .= ".pm";
       require $filename;
-      $article->{generator}->new();
+      $article->{generator}->new(cfg => $cfg);
     };
   ok($gen, "$tag: created generator $article->{generator}");
   diag $@ unless $gen;
index 1013505e5d4fe361fa1a8fda35e2644377455d12..13c7f085b2ad78fff405c7129ebbbcb525f5107c 100644 (file)
--- a/test.cfg
+++ b/test.cfg
@@ -2,7 +2,7 @@
 base_url = http://bsetest.develop-help.com
 securl = http://shop.bsetest.develop-help.com:80
 # where to install the site
-base_dir = /home/httpd/bsetest
+base_dir = /var/www/httpd/bsetest
 # the database user/password/dsn
 dbuser = bsetest
 dbpass = bsetest
@@ -10,6 +10,6 @@ dsn = dbi:mysql:bsetest
 dbclass = BSE::DB::Mysql
 sessionclass = Apache::Session::MySQL
 # the location of mysql
-mysql = /usr/local/mysql/bin/mysql
+mysql = mysql
 basic.access_control=0
 #basic.htusers = /home/httpd/bsetest/htdocs/images/.htusers