Permalink
Browse files

subscriptions fixes

- utf-8 fixes
- allow for variables for new style markup
- make the dummy article an object so it works with all the new code
  that expects an object
- fix handling of a negative or invalid archive article id
- use the BSE::UI wrapper in subs.pl
  • Loading branch information...
1 parent 7797165 commit 6c8fac025b217ba0d54ddaa11590878a16e3cf2d @tonycoz committed Mar 3, 2014
View
@@ -82,6 +82,7 @@ site/cgi-bin/modules/BSE/Custom.pm
site/cgi-bin/modules/BSE/CustomBase.pm
site/cgi-bin/modules/BSE/DB.pm
site/cgi-bin/modules/BSE/DB/Mysql.pm
+site/cgi-bin/modules/BSE/DummyArticle.pm
site/cgi-bin/modules/BSE/Dynamic/Article.pm
site/cgi-bin/modules/BSE/Dynamic/Catalog.pm
site/cgi-bin/modules/BSE/Dynamic/Product.pm
View
@@ -71,7 +71,7 @@ distdir: docs dbinfo version
$(PERL) site/util/make_versions.pl $(DISTBUILD)/$(BSEMODULES)
mkdir $(DISTBUILD)/site/htdocs/shop
find $(DISTBUILD) -type f | xargs chmod u+w
- for i in `cat MANIFEST` ; do if [ -x $$i ] ; then chmod a+x $(DISTBUILD)/$$i ; fi ; done
+ for i in `cat MANIFEST | sed -e 's/\s.*//'` ; do if [ -x $$i ] ; then chmod a+x $(DISTBUILD)/$$i ; fi ; done
clean:
$(NOOP)
View
@@ -4,15 +4,7 @@
use strict;
use FindBin;
use lib "$FindBin::Bin/../modules";
-use BSE::DB;
-use BSE::Request;
-use BSE::Template;
use Carp 'confess';
-use BSE::UI::AdminNewsletter;
+use BSE::UI;
-$SIG{__DIE__} = sub { confess $@ };
-
-my $req = BSE::Request->new;
-
-my $result = BSE::UI::AdminNewsletter->dispatch($req);
-$req->output_result($result);
+BSE::UI->run("BSE::UI::AdminNewsletter", silent_exit => 1);
@@ -0,0 +1,49 @@
+package BSE::DummyArticle;
+use base 'BSE::TB::SiteCommon';
+use Articles;
+
+our $VERSION = "1.000";
+
+sub images {
+ return;
+}
+
+sub files {
+ return;
+}
+
+{
+ for my $name (Article->columns) {
+ eval "sub $name { \$_[0]{$name} }";
+ }
+}
+
+sub restricted_method {
+ return 0;
+}
+
+sub section {
+ $_[0];
+}
+
+sub is_descendant_of {
+ 0;
+}
+
+sub parent {
+ return;
+}
+
+sub is_dynamic {
+ 1;
+}
+
+sub is_step_ancestor {
+ 0;
+}
+
+sub menu_ancestors {
+ return;
+}
+
+1;
@@ -9,8 +9,9 @@ use Constants qw($GENERATE_BUTTON $SHOPID $AUTO_GENERATE);
use Carp qw(confess);
use BSE::WebUtil qw(refresh_to_admin);
use BSE::Util::HTML;
+use BSE::DummyArticle;
-our $VERSION = "1.012";
+our $VERSION = "1.013";
# returns non-zero if the Regenerate button should work
sub generate_button {
@@ -468,49 +469,7 @@ sub _write_text {
sub _dummy_article {
my ($data) = @_;
- return bless $data, "BSE::Regen::DummyArticle";
-}
-
-package BSE::Regen::DummyArticle;
-use base 'BSE::TB::SiteCommon';
-
-sub images {
- return;
-}
-
-sub files {
- return;
-}
-
-{
- use Articles;
- for my $name (Article->columns) {
- eval "sub $name { \$_[0]{$name} }";
- }
-}
-
-sub restricted_method {
- return 0;
-}
-
-sub section {
- $_[0];
-}
-
-sub is_descendant_of {
- 0;
-}
-
-sub parent {
- return;
-}
-
-sub is_dynamic {
- 1;
-}
-
-sub is_step_ancestor {
- 0;
+ return bless $data, "BSE::DummyArticle";
}
1;
@@ -5,7 +5,7 @@ use Squirrel::Row;
use vars qw/@ISA/;
@ISA = qw/Squirrel::Row/;
-our $VERSION = "1.002";
+our $VERSION = "1.003";
sub columns {
return qw/id name title description frequency keyword archive
@@ -19,23 +19,26 @@ sub _build_article {
my @cols = Article->columns;
shift @cols;
@$article{@cols} = ('') x @cols;
- my $parentId = $opts->{parentId} || $sub->{parentId} || -1;
+ my $parent_id = $opts->{parentId} || $sub->{parentId} || -1;
my $parent;
- if ($parentId > 0) {
- $parent = Articles->getByPkey($parentId);
+ if ($parent_id > 0) {
+ $parent = Articles->getByPkey($parent_id);
+ unless ($parent) {
+ $parent_id = -1;
+ }
}
use BSE::Util::SQL qw(now_datetime now_sqldate);
$article->{body} = $opts->{body} || '';
$article->{title} = defined($opts->{title}) ? $opts->{title} : $sub->{title};
- $article->{parentid} = $opts->{parentId} || $sub->{parentId};
+ $article->{parentid} = $parent_id;
$article->{displayOrder} = time;
$article->{imagePos} = 'tr';
$article->{release} = now_sqldate;
$article->{expire} = $Constants::D_99;
$article->{keyword} =
exists($opts->{keyword}) ? $opts->{keyword} : $sub->{keyword};
$article->{generator} = 'Generate::Article';
- $article->{level} = $parent ? $parent->{level} + 1 : -1;
+ $article->{level} = $parent ? $parent->{level} + 1 : 1;
$article->{listed} = 1;
$article->{lastModified} = now_datetime;
$article->{link} = '';
@@ -267,6 +270,7 @@ sub _text_format_low {
sub => sub { $sub->{$_[0]} },
);
+ require BSE::Template;
return BSE::Template->get_page($template, $cfg, \%acts);
}
@@ -275,6 +279,8 @@ sub text_format {
my %article;
$sub->_build_article(\%article, $opts);
+ require BSE::DummyArticle;
+ bless \%article, "BSE::DummyArticle";
return $sub->_text_format_low($cfg, $user, $opts, \%article);
}
@@ -283,7 +289,9 @@ sub html_format {
my %article;
$sub->_build_article(\%article, $opts);
- require 'Generate/Subscription.pm';
+ require Generate::Subscription;
+ require BSE::DummyArticle;
+ bless \%article, "BSE::DummyArticle";
my $gen = Generate::Subscription->new(cfg=>$cfg, top => \%article);
$gen->set_user($user);
$gen->set_sub($sub);
@@ -312,10 +320,12 @@ sub _send {
require 'BSE/Mail.pm';
my $mailer = BSE::Mail->new(cfg=>$cfg);
$sub->_build_article($article, $opts);
+ require BSE::DummyArticle;
+ bless $article, "BSE::DummyArticle";
my $gen;
if ($article->{template}) {
#print STDERR "Making generator\n";
- require 'Generate/Subscription.pm';
+ require Generate::Subscription;
$gen = Generate::Subscription->new(cfg=>$cfg, top=>$article);
$gen->set_sub($sub);
}
@@ -327,16 +337,27 @@ sub _send {
$callback->('error', undef, "Configuration error: No from address configured, please set from in the subscriptions section of the config file, or \$SHOP_FROM in Constants.pm");
return;
}
- my $charset = $cfg->entry('basic', 'charset') || 'iso-8859-1';
+ my $charset = $cfg->charset;
my $index = 0;
for my $user (@$recipients) {
$callback->('user', $user) if $callback;
my $text = $sub->_text_format_low($cfg, $user, $opts, $article);
+ if ($cfg->utf8) {
+ require Encode;
+ $text = Encode::encode($cfg->charset, $text);
+ }
my $html;
if ($gen && !$user->{textOnlyMail}) {
#print STDERR "Making HTML\n";
$gen->set_user($user);
- $html = $gen->generate($article, 'Articles');
+ my %acts;
+ %acts = $gen->baseActs("Articles", \%acts, $article);
+ $html = BSE::Template->get_page($article->template, $cfg, \%acts,
+ undef, undef, $gen->variables);
+ if ($cfg->utf8) {
+ require Encode;
+ $html = Encode::encode($cfg->charset, $html);
+ }
}
my @headers;
my $content;
@@ -4,7 +4,7 @@ use Squirrel::Template;
use Carp qw(confess cluck);
use Config ();
-our $VERSION = "1.010";
+our $VERSION = "1.011";
my %formats =
(
@@ -151,6 +151,24 @@ sub get_response {
return $class->make_response($content, $class->get_type($cfg, $template));
}
+sub encode_content {
+ my ($self, $content, $cfg, $charset) = @_;
+
+ $cfg ||= BSE::Cfg->single;
+ if ($cfg->utf8) {
+ $charset ||= $cfg->charset;
+
+ require Encode;
+ my $cfg = BSE::Cfg->single;
+ my $check = $cfg->entry("utf8", "check", Encode::FB_DEFAULT());
+ $check = oct($check) if $check =~ /^0/;
+
+ $content = Encode::encode($charset, $content, $check);
+ }
+
+ return $content;
+}
+
sub make_response {
my ($class, $content, $type) = @_;
@@ -351,4 +369,22 @@ sub output_resultc {
}
}
+sub print_first_part {
+ my ($class, $content, $cfg) = @_;
+
+ $cfg ||= BSE::Cfg->single;
+
+ my $type = $class->html_type($cfg);
+
+ print "Content-Type: $type\n\n";
+ $class->print_next_part($content, $cfg);
+}
+
+sub print_next_part {
+ my ($class, $content, $cfg) = @_;
+
+ $content = $class->encode_content($content, $cfg);
+ print $content;
+}
+
1;
Oops, something went wrong.

0 comments on commit 6c8fac0

Please sign in to comment.