site/cgi-bin/interest.pl
site/cgi-bin/modules/Apache/Session/DBIreal.pm
site/cgi-bin/modules/Apache/Session/Store/DBIreal.pm
-site/cgi-bin/modules/Article.pm
-site/cgi-bin/modules/Articles.pm
+site/cgi-bin/modules/BSE/TB/Article.pm
+site/cgi-bin/modules/BSE/TB/Articles.pm
site/cgi-bin/modules/BSE/Admin/StepParents.pm
site/cgi-bin/modules/BSE/AdminLogon.pm
site/cgi-bin/modules/BSE/AdminMenu.pm
use strict;
use FindBin;
use lib "$FindBin::Bin/../modules";
-use Articles;
+use BSE::TB::Articles;
use CGI qw(:standard);
use Constants;
use BSE::Regen qw(generate_button generate_all generate_article generate_base generate_one_extra pregenerate_list);
exit;
}
-my $articles = "Articles";
+my $articles = "BSE::TB::Articles";
my $id = $cgi->param('id');
my $fromid = $cgi->param('fromid') || $id;
my $baseurl;
if (defined $fromid
- and my $fromart = Articles->getByPkey($fromid)) {
+ and my $fromart = BSE::TB::Articles->getByPkey($fromid)) {
$baseurl = $fromart->{admin};
}
else {
or die { error_code => "ACCESS", message => "Access denied - you need regen_extras access" };
}
else {
- $article = Articles->getByPkey($id)
+ $article = BSE::TB::Articles->getByPkey($id)
or die { error_code => "NOTFOUND", message => "No such article $id found" };
$req->user_can('regen_article', $article)
or die { error_code => "ACCESS", message => "Access denied - you don't have regen_article access on article $id" };
use strict;
use FindBin;
use lib "$FindBin::Bin/../modules";
-use Articles;
+use BSE::TB::Articles;
use CGI ':standard';
use Carp 'verbose';
use CGI::Carp 'fatalsToBrowser';
my $id = $cgi->param('id');
my $direction = $cgi->param('d');
-my $articles = 'Articles';
+my $articles = 'BSE::TB::Articles';
my $article;
if (defined $cgi->param('stepchild')) {
if ($req->user_can(edit_reorder_stepparents=>$stepchild)) {
# we always need a swap for this one
- my $article = Articles->getByPkey($stepchild)
+ my $article = BSE::TB::Articles->getByPkey($stepchild)
or die "Cannot find child $stepchild";
my $other = $cgi->param('other');
($two->{childDisplayOrder}, $one->{childDisplayOrder});
$one->save;
$two->save;
- generate_article('Articles', $article);
+ generate_article('BSE::TB::Articles', $article);
}
}
elsif (defined $cgi->param('stepparent')) {
my $one = OtherParents->getBy(parentId=>$stepparent, childId=>$id);
unless ($one) {
$onename = 'displayOrder';
- $one = Articles->getByPkey($id)
+ $one = BSE::TB::Articles->getByPkey($id)
or die "Could not find article $id";
}
my $twoname = 'parentDisplayOrder';
my $two = OtherParents->getBy(parentId=>$stepparent, childId=>$other);
unless ($two) {
$twoname = 'displayOrder';
- $two = Articles->getByPkey($other)
+ $two = BSE::TB::Articles->getByPkey($other)
or die "Could not find article $other";
}
($one->{$onename}, $two->{$twoname}) = ($two->{$twoname}, $one->{$onename});
$one->save;
$two->save;
- generate_article('Articles', $article);
+ generate_article('BSE::TB::Articles', $article);
}
}
else {
}
$article->save();
- generate_article('Articles', $article);
+ generate_article('BSE::TB::Articles', $article);
}
}
+++ /dev/null
-package Article;
-use strict;
-# represents an article from the database
-use Squirrel::Row;
-use BSE::TB::SiteCommon;
-use BSE::TB::TagOwner;
-use vars qw/@ISA/;
-@ISA = qw/Squirrel::Row BSE::TB::SiteCommon BSE::TB::TagOwner/;
-use Carp 'confess';
-
-our $VERSION = "1.023";
-
-=head1 NAME
-
-Article - article objects for BSE.
-
-=head1 SYNOPSIS
-
- use BSE::API qw(bse_make_article);
-
- my $article = bse_make_article(...)
-
- my $article = Articles->getByPkey($id);
-
-=head1 DESCRIPTION
-
-Implements the base article object for BSE.
-
-=head1 USEFUL METHODS
-
-=over
-
-=cut
-
-sub columns {
- return qw/id parentid displayOrder title titleImage body
- thumbImage thumbWidth thumbHeight imagePos
- release expire keyword template link admin threshold
- summaryLength generator level listed lastModified flags
- customDate1 customDate2 customStr1 customStr2
- customInt1 customInt2 customInt3 customInt4
- lastModifiedBy created createdBy author pageTitle
- force_dynamic cached_dynamic inherit_siteuser_rights
- metaDescription metaKeywords summary menu titleAlias linkAlias
- category/;
-}
-
-sub db_columns {
- my ($self) = @_;
-
- return map { $_ eq "summary" ? "summaryx" : $_ } $self->columns;
-}
-
-=item id
-
-=item parentid
-
-=item displayOrder
-
-=item title
-
-=item titleImage
-
-=item body
-
-=item thumbImage
-
-=item thumbWidth
-
-=item thumbHeight
-
-=item imagePos
-
-=item release
-
-=item expire
-
-=item keyword
-
-=item template
-
-=item threshold
-
-=item summaryLength
-
-=item generator
-
-=item level
-
-=item listed
-
-=item lastModified
-
-=item flags
-
-=item customDate1
-
-=item customDate2
-
-=item customStr1
-
-=item customStr2
-
-=item customInt1
-
-=item customInt2
-
-=item customInt3
-
-=item customInt4
-
-=item lastModifiedBy
-
-=item created
-
-=item createdBy
-
-=item author
-
-=item pageTitle
-
-=item force_dynamic
-
-=item cached_dynamic
-
-=item inherit_siteuser_rights
-
-=item metaDescription
-
-=item metaKeywords
-
-=item summary
-
-=item menu
-
-=item titleAlias
-
-=item linkAlias
-
-=item category
-
-Simple column accessors.
-
-=cut
-
-sub table {
- 'article';
-}
-
-sub numeric {
- qw(id listed parentid threshold summaryLength level
- customInt1 customInt2 customInt3 customInt4 menu);
-}
-
-=item section
-
-Return the article's section.
-
-=cut
-
-sub section {
- my ($self) = @_;
-
- my $section = $self;
- while ($section->{parentid} > 0
- and my $parent = $section->parent) {
- $section = $parent;
- }
-
- return $section;
-}
-
-=item parent
-
-Return the article's parent.
-
-=cut
-
-sub parent {
- my ($self) = @_;
-
- my $parentid = $self->parentid;
-
- $parentid == -1
- and return;
- $self->{_parent} && $self->{_parent}->id == $parentid
- and return $self->{_parent};
- return ($self->{_parent} = Articles->getByPkey($self->{parentid}));
-}
-
-sub update_dynamic {
- my ($self, $cfg) = @_;
-
- $cfg && $cfg->can('entry')
- or confess 'update_dynamic called without $cfg';
-
- # conditional in case something strange is in the config file
- my $dynamic = $cfg->entry('basic', 'all_dynamic', 0) ? 1 : 0;
-
- if (!$dynamic && $self->generator =~ /\bCatalog\b/) {
- require Products;
- my @tiers = Products->pricing_tiers;
- @tiers and $dynamic = 1;
- }
-
- $dynamic or $dynamic = $self->{force_dynamic};
-
- $dynamic or $dynamic = $self->is_access_controlled;
-
- $dynamic or $dynamic = $self->force_dynamic_inherited;
-
- $self->{cached_dynamic} = $dynamic;
-}
-
-=item is_dynamic
-
-Return true if the article is rendered dynamically.
-
-=cut
-
-sub is_dynamic {
- $_[0]{cached_dynamic};
-}
-
-=item is_accessible_to($group)
-
-Return true if the article is accessible to the supplied siteuser
-group or group id.
-
-=cut
-
-sub is_accessible_to {
- my ($self, $group) = @_;
-
- my $groupid = ref $group ? $group->{id} : $group;
-
- my @rows = BSE::DB->query(articleAccessibleToGroup => $self->{id}, $groupid);
-
- scalar @rows;
-}
-
-sub group_ids {
- my ($self) = @_;
-
- map $_->{id}, BSE::DB->query(siteuserGroupsForArticle => $self->{id});
-}
-
-sub add_group_id {
- my ($self, $id) = @_;
-
- eval {
- BSE::DB->single->run(articleAddSiteUserGroup => $self->{id}, $id);
- };
-}
-
-sub remove_group_id {
- my ($self, $id) = @_;
-
- BSE::DB->single->run(articleDeleteSiteUserGroup => $self->{id}, $id);
-}
-
-=item is_access_controlled
-
-Return true if the article is access controlled.
-
-=cut
-
-sub is_access_controlled {
- my ($self) = @_;
-
- my @group_ids = $self->group_ids;
- return 1 if @group_ids;
-
- return 0
- unless $self->{inherit_siteuser_rights};
-
- my $parent = $self->parent
- or return 0;
-
- return $parent->is_access_controlled;
-}
-
-sub force_dynamic_inherited {
- my ($self) = @_;
-
- my $parent = $self->parent
- or return 0;
-
- $parent->{force_dynamic} && $parent->{flags} =~ /F/
- and return 1;
-
- return $parent->force_dynamic_inherited;
-}
-
-sub link_to_filename {
- my ($self, $cfg, $link) = @_;
-
- $cfg ||= BSE::Cfg->single;
-
- defined $link or $link = $self->{link};
-
- length $link or return;
-
- my $filename = $link;
-
- # remove any appended title,
- $filename =~ s!(.)/\w+$!$1!;
- $filename =~ s{^\w+://[\w.-]+(?::\d+)?}{};
- $filename = $cfg->content_base_path() . $filename;
- if ($filename =~ m(/$)) {
- $filename .= $cfg->entry("basic", "index_file", "index.html");
- }
- $filename =~ s!//+!/!;
-
- return $filename;
-}
-
-sub cached_filename {
- my ($self, $cfg) = @_;
-
- $cfg ||= BSE::Cfg->single;
-
- my $dynamic_path = $cfg->entryVar('paths', 'dynamic_cache');
- return $dynamic_path . "/" . $self->{id} . ".html";
-}
-
-sub html_filename {
- my ($self, $cfg) = @_;
-
- $cfg ||= BSE::Cfg->single;
-
- return $self->is_dynamic
- ? $self->cached_filename($cfg)
- : $self->link_to_filename($cfg);
-}
-
-sub remove_html {
- my ($self, $cfg) = @_;
-
- my $filename = $self->html_filename($cfg)
- or return 1;
-
- unlink $filename
- or return;
-
- return 1;
-}
-
-sub remove {
- my ($self, $cfg) = @_;
-
- $cfg or confess "No \$cfg supplied to ", ref $self, "->remove";
-
- $self->remove_tags;
-
- $self->remove_images($cfg);
-
- $self->remove_files($cfg);
-
- # remove any step(child|parent) links
- require OtherParents;
- my @steprels = OtherParents->anylinks($self->{id});
- for my $link (@steprels) {
- $link->remove();
- }
-
- # remove any site user access controls
- BSE::DB->single->run(bseRemoveArticleSiteUserGroups => $self->id);
-
- # remove any admin user/group access controls
- BSE::DB->single->run(bseRemoveArticleAdminAccess => $self->id);
-
- # remove the static page
- $self->remove_html($cfg);
-
- $self->SUPER::remove();
-}
-
-=item all_parents
-
-Return a list of all parents.
-
-=cut
-
-sub all_parents {
- my ($self) = @_;
-
- my @result = $self->step_parents;
- if ($self->{parentid} > 0 && !grep $_->{id} eq $self->{parentid}, @result) {
- push @result, $self->parent;
- }
-
- return @result;
-}
-
-sub is_step_ancestor {
- my ($self, $other, $max) = @_;
-
- my $other_id = ref $other ? $other->{id} : $other;
- my %seen;
-
- $max ||= 10;
-
- # early exit if possible
- return 1 if $self->{parentid} == $other_id;
-
- my @all_parents = $self->all_parents;
- return 1 if grep $_->{id} == $other_id, @all_parents;
- my @work = map [ 0, $_], grep !$seen{$_}++, @all_parents;
- while (@work) {
- my $entry = shift @work;
- my ($level, $workart) = @$entry;
-
- $level++;
- if ($level < $max) {
- @all_parents = $workart->all_parents;
- return 1 if grep $_->{id} == $other_id, @all_parents;
- push @work, map [ $level, $_ ], grep !$seen{$_}++, @all_parents;
- }
- }
-
- return 0;
-}
-
-sub possible_stepparents {
- my $self = shift;
-
- return BSE::DB->query(articlePossibleStepparents => $self->{id}, $self->{id});
-}
-
-sub possible_stepchildren {
- my $self = shift;
-
- return BSE::DB->query(articlePossibleStepchildren => $self->{id}, $self->{id});
-}
-
-sub link {
- my ($self, $cfg) = @_;
-
- if ($self->flags =~ /P/) {
- my $parent = $self->parent;
- $parent and return $parent->link($cfg);
- }
-
- $self->is_linked
- or return "";
-
- $cfg ||= BSE::Cfg->single;
-
- unless ($self->{linkAlias} && $cfg->entry('basic', 'use_alias', 1)) {
- return $self->{link};
- }
-
- my $prefix = $cfg->entry('basic', 'alias_prefix', '');
- my $link;
- if ($cfg->entry('basic', 'alias_recursive')) {
- my @steps = $self->{linkAlias};
- my $article = $self;
- while ($article = $article->parent) {
- if ($article->{linkAlias}) {
- unshift @steps, $article->{linkAlias};
- }
- }
- $link = join('/', $prefix, @steps);
- }
- else {
- $link = $prefix . '/' . $self->{linkAlias};
- }
- if ($cfg->entry('basic', 'alias_suffix', 1)) {
- my $title = $self->{title};
- $title =~ tr/a-zA-Z0-9/-/cs;
- $link .= '/' . $title;
- }
- return $link;
-}
-
-=item admin
-
-Return the admin link for the article.
-
-=cut
-
-sub admin {
- my ($self) = @_;
-
- return BSE::Cfg->single->admin_url("admin", { id => $self->id });
-}
-
-=item is_linked
-
-Return true if the article can be linked to.
-
-=cut
-
-sub is_linked {
- my ($self) = @_;
-
- return $self->flags !~ /D/;
-}
-
-sub tag_owner_type {
- return "BA";
-}
-
-# the time used for expiry/release comparisons
-sub _expire_release_datetime {
- my ($year, $month, $day) = (localtime)[5,4,3];
- my $today = sprintf("%04d-%02d-%02d 00:00:00ZZZ", $year+1900, $month+1, $day);
-}
-
-=item is_expired
-
-Returns true if the article expiry date has passed.
-
-=cut
-
-sub is_expired {
- my $self = shift;
-
- return $self->expire lt _expire_release_datetime();
-}
-
-=item is_released
-
-Returns true if the article release date has passed (ie. the article
-has been released.)
-
-=cut
-
-sub is_released {
- my $self = shift;
-
- return $self->release le _expire_release_datetime();
-}
-
-=item listed_in_menu
-
-Return true if the article should be listed in menus.
-
-=cut
-
-sub listed_in_menu {
- my $self = shift;
-
- return $self->listed == 1;
-}
-
-=item ancestors
-
-Returns a list of ancestors of self.
-
-=cut
-
-sub ancestors {
- my ($self) = @_;
-
- unless ($self->{_ancestors}) {
- my @ancestors;
- my $work = $self;
- while ($work->parentid != -1) {
- $work = $work->parent;
- push @ancestors, $work;
- }
-
- $self->{_ancestors} = \@ancestors;
- }
-
- return @{$self->{_ancestors}};
-}
-
-=item is_descendant_of($ancestor)
-
-Return true if self is a decsendant of the supplied article or article
-id.
-
-=cut
-
-sub is_descendant_of {
- my ($self, $ancestor) = @_;
-
- my $ancestor_id = ref $ancestor ? $ancestor->id : $ancestor;
-
- for my $anc ($self->ancestors) {
- return 1 if $anc->id == $ancestor_id;
- }
-
- return 0;
-}
-
-=item visible_ancestors
-
-Returns all visible ancestors.
-
-Lists the top-level ancestor C<last>.
-
-This list does not include the article itself.
-
-=cut
-
-sub visible_ancestors {
- my ($self) = @_;
-
- return grep $_->listed, $self->ancestors;
-}
-
-=item menu_ancestors
-
-Returns visible ancestprs that are visible for menus (ie. listed = 1).
-
-Lists the top-level ancestor C<last>.
-
-This list does not include the article itself.
-
-=cut
-
-sub menu_ancestors {
- my ($self) = @_;
-
- return grep $_->listed, $self->ancestors;
-}
-
-=item should_generate
-
-Return true if this article should have pages generated, either for
-static content or for dynamic.
-
-=cut
-
-sub should_generate {
- my ($self) = @_;
-
- return $self->is_linked && $self->listed && $self->is_released && !$self->is_expired;
-}
-
-=item should_index
-
-Returns true if the article should be indexed.
-
-=cut
-
-sub should_index {
- my ($self) = @_;
-
- return ($self->listed || $self->is_index_even_if_hidden)
- && $self->is_linked
- && !$self->is_dont_index
- && !$self->is_dont_index_or_kids
-}
-
-=item is_index_even_if_hidden
-
-Return true if the article's index even if hidden flag is set.
-
-=cut
-
-sub is_index_even_if_hidden {
- my ($self) = @_;
-
- return $self->flags =~ /I/;
-}
-
-=item is_dont_index
-
-Return true if the "don't index" flag (C<N>) is set.
-
-=cut
-
-sub is_dont_index {
- return $_[0]->flags =~ /N/;
-}
-
-=item is_dont_index_or_kids
-
-Return true if the article or any of it's parents have the "don't
-index me or my children" flag (C<C>) set.
-
-=cut
-
-sub is_dont_index_or_kids {
- my ($self) = @_;
-
- $self->flags =~ /C/ and return 1;
-
- my $parent = $self->parent
- or return 0;
-
- return $parent->is_dont_index_or_kids;
-}
-
-sub restricted_method {
- my ($self, $name) = @_;
-
- return $self->SUPER::restricted_method($name)
- || $name =~ /^(?:update_|remove_|add_|mark_modified)/;
-}
-
-sub tableClass {
- return "Articles";
-}
-
-=item mark_modified
-
-Call by admin code to do the things we do when an article is modified.
-
-Parameters:
-
-=over
-
-=item *
-
-actor - an audit log compatible actor.
-
-=back
-
-=cut
-
-sub mark_modified {
- my ($self, %opts) = @_;
-
- require BSE::Util::SQL;
- $self->set_lastModified(BSE::Util::SQL::now_sqldatetime());
- $self->set_lastModifiedBy(ref $opts{actor} ? $opts{actor}->logon : "");
-}
-
-=item uncache
-
-Free any cached data.
-
-=cut
-
-sub uncache {
- my ($self) = @_;
-
- delete @{$self}{qw/_parent/};
-
- $self->SUPER::uncache();
-}
-
-1;
-
-__END__
-
-=back
-
-=head1 BASE CLASSES
-
-L<BSE::TB::SiteCommon>
-
-L<BSE::TB::TagOwner>
-
-L<Squirrel::Row>
-
-=head1 AUTHOR
-
-Tony Cook <tony@develop-help.com>
-
-=cut
+++ /dev/null
-package Articles;
-use strict;
-use Squirrel::Table;
-use vars qw(@ISA $VERSION);
-require BSE::TB::TagOwners;
-@ISA = qw(Squirrel::Table BSE::TB::TagOwners);
-use Article;
-
-our $VERSION = "1.005";
-
-=head1 NAME
-
-Articles - BSE's article collection
-
-=head1 SYNOPSIS
-
- use Articles;
-
- my $article = Articles->make(...);
- my $article = Articles->getByPkey($id)
- # etc
-
-=head1 DESCRIPTION
-
-The collective class for BSE articles.
-
-=head1 USEFUL METHODS
-
-=over
-
-=cut
-
-sub rowClass {
- return 'Article';
-}
-
-=item sections
-
-Returns a list of articles which are sections
-
-=cut
-
-sub sections {
- my ($self) = @_;
-
- return $self->getBy('level', 1);
-}
-
-=item subsections
-
-Returns a list of articles which are sub sections
-
-=cut
-
-sub subsections {
- my ($self) = @_;
-
- return $self->getBy('level', 2);
-}
-
-=item children($id)
-
-Child articles of the given article id
-
-=cut
-
-sub children {
- my ($self, $id) = @_;
-
- return $self->getBy('parentid', $id);
-}
-
-=item listedChildren($id)
-
-Children of the given article id that are listed and in the display
-order
-
-=cut
-
-sub listedChildren {
- my ($self, $id) = @_;
- my ($year, $month, $day) = (localtime)[5,4,3];
- my $today = sprintf("%04d-%02d-%02d 00:00:00ZZZ", $year+1900, $month+1, $day);
- my @work = $self->children($id);
- return sort { $b->{displayOrder} <=> $a->{displayOrder} }
- grep { $_->{listed} && $today ge $_->{release}
- && $today le $_->{expire}} @work;
-}
-
-=item summary
-
-Return a list of hashes with article id and title for every article.
-
-=cut
-
-sub summary {
- BSE::DB->query('articlesList');
-}
-
-=item allids
-
-Return a list of all article ids.
-
-=cut
-
-sub allids {
- my ($self) = @_;
-
- if (ref $self) {
- return map $_->{id}, $self->all;
- }
- else {
- return map $_->{id}, BSE::DB->query('Articles.ids');
- }
-}
-
-=item visible_stepkids($id)
-
-Return a list of visible stepkids of the given article id.
-
-=cut
-
-sub visible_stepkids {
- my ($self, $id) = @_;
-
- use BSE::Util::SQL qw/now_sqldate/;
- my $today = now_sqldate();
-
- return Articles->getSpecial('visibleStepKids', $id, $today);
-}
-
-=item all_visible_kids($id)
-
-Return a list of all visible children of the given article id.
-
-=cut
-
-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 };
-}
-
-=item all_visible_kid_tags($id)
-
-Return a hash with two keys, C<tags> being all tags for all visible
-children of C<$id>, and C<members> being all tag member objects for
-all visible children of C<$id>.
-
-=cut
-
-sub all_visible_kid_tags {
- my ($self, $id) = @_;
-
- require BSE::TB::Tags;
- require BSE::TB::TagMembers;
- return
- {
- tags => [ BSE::TB::Tags->getSpecial(allkids => $id, $id) ],
- members => [ BSE::TB::TagMembers->getSpecial(allkids => $id, $id) ],
- };
-}
-
-=item global_files
-
-Return a list of global files.
-
-=cut
-
-sub global_files {
- my ($self) = @_;
-
- require BSE::TB::ArticleFiles;
- return BSE::TB::ArticleFiles->getBy(articleId => -1);
-}
-
-=item allkid_summary($parent_id)
-
-Return a list of hash per child, each with id, displayOrder sorted for
-display.
-
-Entries with step_id are for step children of $parent_id.
-
-=cut
-
-sub allkid_summary {
- my ($class, $parent_id) = @_;
-
- my @child_order = BSE::DB->query(bseChildOrder => $parent_id);
- my @stepchild_order = BSE::DB->query(bseStepchildOrder => $parent_id);
-
- return sort { $b->{displayOrder} <=> $a->{displayOrder} }
- ( @child_order, @stepchild_order );
-}
-
-=item reorder_child($parent_id, $child_id, $after_id)
-
-Move article C<$child_id> after C<$after_id> in the all children list
-of article C<$after_id>.
-
-Returns a true value on success.
-
-=cut
-
-sub reorder_child {
- my ($class, $parent_id, $child_id, $after_id) = @_;
-
- my @child_order = $class->allkid_summary($parent_id);
-
- my ($child_index) = grep $child_order[$_]{id} == $child_id, 0..$#child_order
- or return; # nothing to do, it's not a child
- my @order = map $_->{displayOrder}, @child_order;
-
- if ($child_index > 0 && $child_order[$child_index-1]{id} == $after_id
- || $child_index == 0 && $after_id == 0) {
- # trivial success
- return 1;
- }
-
- # remove the child from the order
- my ($child) = splice(@child_order, $child_index, 1);
-
- my $start_index;
- if ($after_id == 0) {
- unshift @child_order, $child;
- $start_index = 0;
- }
- else {
- my ($after_index) = grep $child_order[$_]{id} == $after_id, 0..$#child_order
- or return; # after not found, nothing to do
-
- splice(@child_order, $after_index+1, 0, $child);
- $start_index = $after_index + 1;
- }
-
- for my $index (0 .. $#order) {
- my $child = $child_order[$index];
- if ($child->{step_id}) {
- BSE::DB->run(bseSetStepOrder => $order[$index], $child->{step_id});
- }
- else {
- BSE::DB->run(bseSetArticleOrder => $order[$index], $child->{id});
- }
- }
-
- return 1;
-}
-
-=item categories
-
-Return a list of all configured article categories.
-
-Each entry is a hash containing C<id> and C<name>.
-
-=cut
-
-sub categories {
- my $cfg = BSE::Cfg->single;
-
- my @cat_ids = split /,/, $cfg->entry("article categories", "ids", "");
- grep $_ eq "", @cat_ids
- or unshift @cat_ids, "";
-
- my @cats;
- for my $id (@cat_ids) {
- my $section = length $id ? "article category $id" : "article category empty";
- my $def_name = length $id ? ucfirst $id : "(None)";
- my $name = $cfg->entry($section, "name",
- $cfg->entry("article categories", $id, $def_name));
- push @cats, +{ id => $id, name => $name };
- }
-
- return @cats;
-}
-
-1;
-
-=back
-
-=head1 AUTHOR
-
-Tony Cook <tony@develop-help.com>
-
-=cut
-
use Fcntl qw(:seek);
use Cwd;
-our $VERSION = "1.008";
+our $VERSION = "1.009";
=head1 NAME
$article->{level} = 1;
}
else {
- require Articles;
- my $parent = Articles->getByPkey($article->{parentid})
+ require BSE::TB::Articles;
+ my $parent = BSE::TB::Articles->getByPkey($article->{parentid})
or confess "Invalid parent $article->{parentid}\n";
$article->{level} = $parent->{level} + 1;
}
my $cfg = delete $opts{cfg}
or confess "cfg option missing";
- require Articles;
+ require BSE::TB::Articles;
defined $opts{title} && length $opts{title}
or confess "Missing title option\n";
_set_dynamic($cfg, \%opts);
- my @cols = Article->columns;
+ my @cols = BSE::TB::Article->columns;
shift @cols;
- my $catalog = Articles->add(@opts{@cols});
+ my $catalog = BSE::TB::Articles->add(@opts{@cols});
require BSE::Edit::Catalog;
_finalize_article($cfg, $catalog, 'BSE::Edit::Catalog');
my $cfg = delete $opts{cfg}
or confess "cfg option missing";
- require Articles;
+ require BSE::TB::Articles;
defined $opts{title} && length $opts{title}
or confess "Missing title option\n";
_set_dynamic($cfg, \%opts);
- my @cols = Article->columns;
+ my @cols = BSE::TB::Article->columns;
shift @cols;
- my $article = Articles->add(@opts{@cols});
+ my $article = BSE::TB::Articles->add(@opts{@cols});
require BSE::Edit::Article;
_finalize_article($cfg, $article, 'BSE::Edit::Article');
my ($article, $cfg) = @_;
require BSE::Edit::Base;
- return BSE::Edit::Base->article_class($article, 'Articles', $cfg);
+ return BSE::Edit::Base->article_class($article, 'BSE::TB::Articles', $cfg);
}
# File::Copy doesn't like CGI.pm's fake fhs
package BSE::Admin::StepParents;
use strict;
-use Articles;
+use BSE::TB::Articles;
use OtherParents;
use BSE::Util::SQL qw/date_to_sql/;
-our $VERSION = "1.000";
+our $VERSION = "1.001";
sub add {
my ($class, $parent, $child, $release, $expire) = @_;
use BSE::TB::AdminGroups;
use BSE::Util::Iterate;
-our $VERSION = "1.008";
+our $VERSION = "1.009";
my %actions =
(
sub iter_get_kids {
my ($article) = @_;
- require Articles;
+ require BSE::TB::Articles;
return sort { $b->{displayOrder} <=> $a->{displayOrder} }
- Articles->children($article->{id});
+ BSE::TB::Articles->children($article->{id});
}
sub iter_get_aperms {
};
}
else {
- require Articles;
- return Articles->getByPkey($id);
+ require BSE::TB::Articles;
+ return BSE::TB::Articles->getByPkey($id);
}
}
package BSE::DummyArticle;
use strict;
use base 'BSE::TB::SiteCommon';
-use Articles;
+use BSE::TB::Articles;
-our $VERSION = "1.002";
+our $VERSION = "1.003";
sub images {
return;
}
{
- for my $name (Article->columns) {
+ for my $name (BSE::TB::Article->columns) {
eval "sub $name { \$_[0]{$name} }";
}
}
use BSE::Util::HTML;
use base qw(BSE::Util::DynamicTags);
-our $VERSION = "1.006";
+our $VERSION = "1.007";
sub new {
my ($class, $req, %opts) = @_;
$result
and return $result;
- $result = $self->access_filter(Articles->listedChildren($article->{id}));
+ $result = $self->access_filter(BSE::TB::Articles->listedChildren($article->{id}));
$self->set_cached(dynchildren => $result);
return $result;
use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
-our $VERSION = "1.047";
+our $VERSION = "1.048";
=head1 NAME
my @children;
$article->{id} or return;
- if (UNIVERSAL::isa($article, 'Article')) {
+ if (UNIVERSAL::isa($article, 'BSE::TB::Article')) {
@children = $article->children;
}
elsif ($article->{id}) {
}
my %article;
- my @cols = Article->columns;
+ my @cols = BSE::TB::Article->columns;
@article{@cols} = ('') x @cols;
$article{id} = '';
$article{parentid} = $parentid;
my ($after_id) = $cgi->param("_after");
if (defined $after_id) {
- Articles->reorder_child($article->{parentid}, $article->{id}, $after_id);
+ BSE::TB::Articles->reorder_child($article->{parentid}, $article->{id}, $after_id);
# reload, the displayOrder probably changed
$article = $articles->getByPkey($article->{id});
}
$data->{body} =~ s/\x0D\x0A/\n/g;
$data->{body} =~ tr/\r/\n/;
}
- for my $col (Article->columns) {
+ for my $col (BSE::TB::Article->columns) {
next if $col =~ /^custom/;
$article->{$col} = $data->{$col}
if exists $data->{$col} && $col ne 'id' && $col ne 'parentid';
my ($after_id) = $cgi->param("_after");
if (defined $after_id) {
- Articles->reorder_child($article->{parentid}, $article->{id}, $after_id);
+ BSE::TB::Articles->reorder_child($article->{parentid}, $article->{id}, $after_id);
# reload, the displayOrder probably changed
$article = $articles->getByPkey($article->{id});
}
my $after_id = $cgi->param("_after");
if (defined $after_id) {
- Articles->reorder_child($article->id, $child->id, $after_id);
+ BSE::TB::Articles->reorder_child($article->id, $child->id, $after_id);
}
generate_article($articles, $article) if $Constants::AUTO_GENERATE;
if ($newparentid) {
$newparentid =~ /^\d+$/
or return $self->_service_error($req, $article, $articles, "Bad new parent id", {}, "BADNEWPARENT");
- my $new_parent = Articles->getByPkey($newparentid)
+ my $new_parent = BSE::TB::Articles->getByPkey($newparentid)
or return $self->_service_error($req, $article, $articles, "Unknown new parent id", {}, "UNKNOWNNEWPARENT");
my $existing =
OtherParents->getBy(parentId=>$newparentid, childId=>$article->id)
my $after_id = $cgi->param("_after");
if (defined $after_id) {
- Articles->reorder_child($step->{parentId}, $article->id, $after_id);
+ BSE::TB::Articles->reorder_child($step->{parentId}, $article->id, $after_id);
}
if ($req->is_ajax) {
$article = $self->_dummy_article($req, $articles, \$mymsg);
$article ||=
{
- map $_ => '', Article->columns
+ map $_ => '', BSE::TB::Article->columns
};
}
if ($col eq 'threshold') {
my $parent = defined $article->{parentid} && $article->{parentid} != -1
- && Articles->getByPkey($article->{parentid});
+ && BSE::TB::Articles->getByPkey($article->{parentid});
$parent and return $parent->{threshold};
if ($col eq 'summaryLength') {
my $parent = defined $article->{parentid} && $article->{parentid} != -1
- && Articles->getByPkey($article->{parentid});
+ && BSE::TB::Articles->getByPkey($article->{parentid});
$parent and return $parent->{summaryLength};
my $msg = $req->csrf_error;
$errors{_csrfp} = $msg;
my $mymsg;
- $article ||= $self->_dummy_article($req, 'Articles', \$mymsg);
+ $article ||= $self->_dummy_article($req, 'BSE::TB::Articles', \$mymsg);
unless ($article) {
require BSE::Edit::Site;
my $site = BSE::Edit::Site->new(cfg=>$req->cfg, db=> BSE::DB->single);
- return $site->edit_sections($req, 'Articles', $mymsg);
+ return $site->edit_sections($req, 'BSE::TB::Articles', $mymsg);
}
- return $self->_service_error($req, $article, 'Articles', $msg, \%errors);
+ return $self->_service_error($req, $article, 'BSE::TB::Articles', $msg, \%errors);
}
=item a_csrp
"Only usable from Ajax", undef, "NOTAJAX");
$ENV{REQUEST_METHOD} eq 'POST'
- or return $self->_service_error($req, $article, "Articles",
+ or return $self->_service_error($req, $article, "BSE::TB::Articles",
"POST required for this action", {}, "NOTPOST");
my %errors;
if (--$depth > 0) {
for my $kid (@kids) {
$kid->{children} = [ _article_kid_summary($kid->{id}, $depth) ];
- $kid->{allkids} = [ Articles->allkid_summary($kid->{id}) ];
+ $kid->{allkids} = [ BSE::TB::Articles->allkid_summary($kid->{id}) ];
}
}
],
allkids =>
[
- Articles->allkid_summary($article->id)
+ BSE::TB::Articles->allkid_summary($article->id)
],
);
}
=cut
-our $VERSION = "1.012";
+our $VERSION = "1.013";
use base 'BSE::Edit::Article';
use BSE::TB::Site;
sub get_files {
my ($self, $article) = @_;
- Articles->global_files;
+ BSE::TB::Articles->global_files;
}
sub req_tagshow {
push @opts, [ like => "cat", "$cat%" ];
}
}
- my @tags = Articles->all_tags(@opts);
+ my @tags = BSE::TB::Articles->all_tags(@opts);
if ($req->is_ajax) {
my @json = map $_->json_data, @tags;
for my $i (0 .. $#tags) {
my $tag = $tags[$i];
my $json = $json[$i];
- $json->{articles} = [ Articles->getIdsByTag($tag) ];
+ $json->{articles} = [ BSE::TB::Articles->getIdsByTag($tag) ];
}
}
plural => "systagarts",
code => sub {
return sort { lc $a->title cmp lc $b->title }
- Articles->getByTag($tag);
+ BSE::TB::Articles->getByTag($tag);
},
nocache => 1,
),
}
if ($tag && !$errors{name}) {
- my $other = Articles->getTagByName($name);
+ my $other = BSE::TB::Articles->getTagByName($name);
if ($other) {
if ($other->id != $tag->id) {
$errors{name} = "msg:bse/admin/edit/tags/duplicate:$name";
sub req_tagcats {
my ($self, $req, $article, $articles) = @_;
- my @cats = Articles->all_tag_categories;
+ my @cats = BSE::TB::Articles->all_tag_categories;
my $filter = $req->cgi->param("cat");
if (defined $filter and $filter =~ /\S/) {
@cats = grep /\A\Q$filter/i, @cats;
return $self->req_tagcats($req, $article, $articles, undef, \%errors);
}
- my $cat = Articles->tag_category($workcat)
+ my $cat = BSE::TB::Articles->tag_category($workcat)
or return $self->req_tagcats($req, $article, $articles,
"Cannot find or create tag category '$workcat'");
return $self->req_tagcats($req, $article, $articles, undef, \%errors);
}
- my $cat = Articles->tag_category($workcat)
+ my $cat = BSE::TB::Articles->tag_category($workcat)
or return $self->req_tagcats($req, $article, $articles,
"Cannot find or create tag category '$workcat'");
use BSE::Util::HTML;
use Carp 'confess';
-our $VERSION = "1.007";
+our $VERSION = "1.008";
use base 'DevHelp::Formatter';
my ($self, $fileid, $text, $type) = @_;
unless ($self->{gfiles}) {
- $self->{gfiles} = [ Articles->global_files ];
+ $self->{gfiles} = [ BSE::TB::Articles->global_files ];
}
my ($file) = grep $_->{name} eq $fileid, @{$self->{gfiles}}
or return "** unknown file $fileid **";
my ($self, $fileid, $text, $type) = @_;
unless ($self->{gfiles}) {
- $self->{gfiles} = [ Articles->global_files ];
+ $self->{gfiles} = [ BSE::TB::Articles->global_files ];
}
my ($file) = grep $_->{name} eq $fileid, @{$self->{gfiles}}
or return "** unknown file $fileid **";
package BSE::Generate;
use strict;
-use Articles;
+use BSE::TB::Articles;
use Constants qw($LOCAL_FORMAT $BODY_EMBED
$EMBED_MAX_DEPTH $HAVE_HTML_PARSER);
use DevHelp::Tags;
=cut
-our $VERSION = "1.023";
+our $VERSION = "1.024";
my $excerptSize = 300;
};
$opts{varstack} = [];
my $self = bless \%opts, $class;
- $self->set_variable_class(articles => "Articles");
+ $self->set_variable_class(articles => "BSE::TB::Articles");
$opts{vars}{generator} = $self;
Scalar::Util::weaken($opts{vars}{generator});
$limit ||= $article->summaryLength;
- return $self->summarize("Articles", $article->body, $self->{acts}, $limit);
+ return $self->summarize("BSE::TB::Articles", $article->body, $self->{acts}, $limit);
}
# attempts to move the given position forward if it's within a HTML tag,
sub vembed {
my ($self, $article, $template) = @_;
- return $self->embed($article, "Articles", $template);
+ return $self->embed($article, "BSE::TB::Articles", $template);
}
sub iter_kids_of {
if (@ids == 1) {
$state->{parentid} = $ids[0];
}
- $self->_do_filter($filter, map Articles->listedChildren($_), @ids);
+ $self->_do_filter($filter, map BSE::TB::Articles->listedChildren($_), @ids);
}
my $cols_re; # cache for below
my $expr = $1;
my $orig_expr = $expr;
unless ($cols_re) {
- my $cols_expr = '(' . join('|', Article->columns) . ')';
+ my $cols_expr = '(' . join('|', BSE::TB::Article->columns) . ')';
$cols_re = qr/\[$cols_expr\]/;
}
$expr =~ s/$cols_re/\$article->{$1}/g;
@ids = grep /^\d+$|^-1$/, @ids;
@ids == 1 and $state->{parentid} = $ids[0];
- $self->_do_filter($filter, map Articles->all_visible_kids($_), @ids);
+ $self->_do_filter($filter, map BSE::TB::Articles->all_visible_kids($_), @ids);
}
sub iter_inlines {
@ids = grep /^\d+$/, @ids;
@ids == 1 and $state->{parentid} = $ids[0];
- $self->_do_filter($filter, map Articles->getByPkey($_), @ids);
+ $self->_do_filter($filter, map BSE::TB::Articles->getByPkey($_), @ids);
}
sub iter_gimages {
my ($self, $args) = @_;
unless ($self->{gfiles}) {
- my @gfiles = Articles->global_files;
+ my @gfiles = BSE::TB::Articles->global_files;
my %gfiles = map { $_->{name} => $_ } @gfiles;
$self->{gfiles} = \%gfiles;
}
my $article;
if ($article_id =~ /^\d+$/) {
- require Articles;
- $article = Articles->getByPkey($article_id);
+ require BSE::TB::Articles;
+ $article = BSE::TB::Articles->getByPkey($article_id);
unless ($article) {
$$msg = "* no article $article_id found *";
return;
}
elsif ($acts->{$article_id}) {
my $id = $templater->perform($acts, $article_id, "id");
- $article = Articles->getByPkey($id);
+ $article = BSE::TB::Articles->getByPkey($id);
unless ($article) {
$$msg = "* article $article_id/$id not found *";
return;
}
}
else {
- ($article) = Articles->getBy(linkAlias => $article_id);
+ ($article) = BSE::TB::Articles->getBy(linkAlias => $article_id);
unless ($article) {
$$msg = "* no article $article_id found *";
return;
my ($self, $article_id, $article, $acts, $name, $templater) = @_;
if ($article_id =~ /^\d+$/) {
- my $result = Articles->getByPkey($article_id);
+ my $result = BSE::TB::Articles->getByPkey($article_id);
$result or print STDERR "** Unknown article id $article_id **\n";
return $result ? $result : ();
}
elsif ($article_id =~ /^alias\((\w+)\)$/) {
- my $result = Articles->getBy(linkAlias => $1);
+ my $result = BSE::TB::Articles->getBy(linkAlias => $1);
$result or print STDERR "** Unknown article alias $article_id **\n";
return $result ? $result : ();
}
elsif ($article_id =~ /^childrenof\((.*)\)$/) {
my $id = $1;
if ($id eq '-1') {
- return Articles->all_visible_kids(-1);
+ return BSE::TB::Articles->all_visible_kids(-1);
}
else {
my @parents = $self->_find_articles($id, $article, $acts, $name, $templater)
elsif ($acts->{$article_id}) {
my $id = $templater->perform($acts, $article_id, 'id');
if ($id && $id =~ /^\d+$/) {
- return Articles->getByPkey($id);
+ return BSE::TB::Articles->getByPkey($id);
}
}
print STDERR "** Unknown article identifier $article_id **\n";
# we remove any formatting tags here, otherwise we get wierd table
# rubbish or other formatting in the excerpt.
my @files = $article->files;
- $self->remove_block('Articles', [], \$body, \@files);
+ $self->remove_block('BSE::TB::Articles', [], \$body, \@files);
1 while $body =~ s/[bi]\[([^\]\[]+)\]/$1/g;
}
my ($self, $name) = @_;
unless ($self->{gfiles}) {
- my @gfiles = Articles->global_files;
+ my @gfiles = BSE::TB::Articles->global_files;
my %gfiles = map { $_->{name} => $_ } @gfiles;
$self->{gfiles} = \%gfiles;
}
use BSE::Util::Iterate;
use BSE::CfgInfo qw(cfg_dist_image_uri cfg_image_uri);
-our $VERSION = "1.014";
+our $VERSION = "1.015";
=head1 NAME
# used to generate a navigation list for the article
# generate a list of ancester articles/sections
# Jason calls these breadcrumbs
- my @ancestors = UNIVERSAL::isa($article, 'Article') ?
+ my @ancestors = UNIVERSAL::isa($article, 'BSE::TB::Article') ?
reverse($article->ancestors) : ();
my @crumbs = grep $_->{listed} == 1 || $_->{level} == 1, @ancestors;
my $current_crumb;
my $section = @crumbs ? $crumbs[0] : $article;
my @images;
- if (UNIVERSAL::isa($article, 'Article')) {
+ if (UNIVERSAL::isa($article, 'BSE::TB::Article')) {
@images = $article->images;
}
my @unnamed_images = grep $_->{name} eq '', @images;
my $abs_urls = $self->abs_urls($article);
my $dynamic = $self->{force_dynamic}
- || (UNIVERSAL::isa($top, 'Article') ? $top->is_dynamic : 0);
+ || (UNIVERSAL::isa($top, 'BSE::TB::Article') ? $top->is_dynamic : 0);
$self->set_variable(dynamic => $dynamic);
my @stepkids;
my @allkids;
my @stepparents;
- if (UNIVERSAL::isa($article, 'Article')) {
+ if (UNIVERSAL::isa($article, 'BSE::TB::Article')) {
@stepkids = $article->visible_stepkids;
@allkids = $article->all_visible_kids;
@stepparents = $article->visible_step_parents;
# this is to support pregenerated pages being handled as dynamic pages
$self->{force_dynamic} and return 1;
- UNIVERSAL::isa($top, 'Article') ? $top->is_dynamic : 0;
+ UNIVERSAL::isa($top, 'BSE::TB::Article') ? $top->is_dynamic : 0;
}
sub tag_ifAccessControlled {
if ($arg) {
if ($acts->{$arg}) {
my $id = $templater->perform($acts, $arg, 'id');
- $article = Articles->getByPkey($id);
+ $article = BSE::TB::Articles->getByPkey($id);
unless ($article) {
print STDERR "** Unknown article $id from $arg in ifAccessControlled\n";
return 0;
}
}
- return UNIVERSAL::isa($article, 'Article') ?
+ return UNIVERSAL::isa($article, 'BSE::TB::Article') ?
$article->is_access_controlled : 0;
}
package BSE::ImageClean;
use strict;
use BSE::TB::Images;
-use Articles;
+use BSE::TB::Articles;
use BSE::TB::Files;
use BSE::CfgInfo qw(cfg_image_dir);
use File::Spec::Functions qw(catfile);
-our $VERSION = "1.000";
+our $VERSION = "1.001";
sub scan {
my ($class, $callback) = @_;
unless (exists $articleIds{$image->{articleId}}) {
$articleIds{$image->{articleId}} =
- defined(Articles->getByPkey($image->{articleId}));
+ defined(BSE::TB::Articles->getByPkey($image->{articleId}));
}
unless ($articleIds{$image->{articleId}}) {
$orphan_files{$image->image} = 1;
}
);
$callback->({type => "substage", stage => "index", substage => "thumbnails"});
- Articles->iterateBy
+ BSE::TB::Articles->iterateBy
(
sub {
my ($article) = @_;
use strict;
use base 'BSE::Importer::Target::Base';
use BSE::API qw(bse_make_article bse_add_image bse_add_step_parent);
-use Articles;
+use BSE::TB::Articles;
use Products;
use OtherParents;
-our $VERSION = "1.008";
+our $VERSION = "1.009";
=head1 NAME
or next;
my $step;
if ($step_id =~ /^\d+$/) {
- $step = Articles->getByPkey($step_id);
+ $step = BSE::TB::Articles->getByPkey($step_id);
}
else {
- $step = Articles->getBy(linkAlias => $step_id);
+ $step = BSE::TB::Articles->getBy(linkAlias => $step_id);
}
$step
or die "Cannot find stepparent with id $step_id\n";
sub children_of {
my ($self, $parent) = @_;
- Articles->children($parent);
+ BSE::TB::Articles->children($parent);
}
=item make_parent()
$leaf_id =~ s/\A\s+//;
$leaf_id =~ s/\s+\z//;
- my ($leaf) = Articles->getBy($self->{code_field}, $leaf_id)
+ my ($leaf) = BSE::TB::Articles->getBy($self->{code_field}, $leaf_id)
or return;
$importer->event(find_leaf => { id => $leaf_id, leaf => $leaf });
my ($self, $importer, $entry) = @_;
if (defined $entry->{linkAlias} && $entry->{linkAlias} ne '') {
- my $other = Articles->getBy(linkAlias => $entry->{linkAlias});
+ my $other = BSE::TB::Articles->getBy(linkAlias => $entry->{linkAlias});
$other
and die "Duplicate linkAlias value with article ", $other->id, "\n";
}
use strict;
use base 'BSE::Importer::Target::Article';
use BSE::API qw(bse_make_product bse_make_catalog bse_add_image);
-use Articles;
+use BSE::TB::Articles;
use Products;
use BSE::TB::ProductOptions;
use BSE::TB::ProductOptionValues;
use BSE::TB::PriceTiers;
-our $VERSION = "1.006";
+our $VERSION = "1.007";
=head1 NAME
my ($self, $parent) = @_;
return grep $_->{generator} eq 'BSE::Generate::Catalog',
- Articles->children($parent);
+ BSE::TB::Articles->children($parent);
}
=item make_parent()
use strict;
use Time::HiRes qw(time);
use Constants qw(@SEARCH_EXCLUDE @SEARCH_INCLUDE);
-use Articles;
+use BSE::TB::Articles;
-our $VERSION = "1.004";
+our $VERSION = "1.005";
my %default_scores =
(
@dont_search{@SEARCH_EXCLUDE} = @SEARCH_EXCLUDE;
@do_search{@SEARCH_INCLUDE} = @SEARCH_INCLUDE;
$self->vnote("s::Loading article ids");
- my @ids = Articles->allids;
+ my @ids = BSE::TB::Articles->allids;
my $count = @ids;
$self->vnote("c:$count:$count articles to index");
my $cfg = BSE::Cfg->single;
my @files;
my $got_files;
# find the section
- my $article = Articles->getByPkey($id);
+ my $article = BSE::TB::Articles->getByPkey($id);
next unless $article;
next unless $article->should_index;
my $section = $article->section;
}
#next if $text =~ m!^\<html\>!i; # I don't know how to do this (yet)
if ($field eq 'body') {
- $gen->remove_block("Articles", [], \$text);
+ $gen->remove_block("BSE::TB::Articles", [], \$text);
$text =~ s/[abi]\[([^\]]+)\]/$1/g;
}
"&{}" => sub { my $self = $_[0]; return sub { $self->_old_msg(@_) } },
"bool" => sub { 1 };
-our $VERSION = "1.007";
+our $VERSION = "1.008";
my $single;
my $gen = Generate->new(cfg => BSE::Cfg->single);
my $templater = BSE::Template->templater(BSE::Cfg->single);
return $gen->format_body(acts => {},
- articles => "Articles",
+ articles => "BSE::TB::Articles",
text => $msg->{message},
templater => $templater);
}
package BSE::Permissions;
use strict;
-our $VERSION = "1.002";
+our $VERSION = "1.003";
# these are the permissions that are checked beyond just whether the permissions DB allows them
my @checks =
return $self->{sitearticle};
}
else {
- require Articles;
- $self->{artcache}{$id} = Articles->getByPkey($id);
+ require BSE::TB::Articles;
+ $self->{artcache}{$id} = BSE::TB::Articles->getByPkey($id);
}
}
my ($self, $user, $article, $action, $rmsg) = @_;
# can't delete an article that has children
- if (Articles->children($article->{id})) {
+ if (BSE::TB::Articles->children($article->{id})) {
$$rmsg = "This article has children. You must delete the children first (or change their parents)";
return;
}
use strict;
use Spreadsheet::ParseExcel;
use BSE::API qw(bse_make_product bse_make_catalog bse_add_image);
-use Articles;
+use BSE::TB::Articles;
use Products;
use Config;
-our $VERSION = "1.001";
+our $VERSION = "1.002";
sub new {
my ($class, $cfg, $profile, %opts) = @_;
or return $parent;
unless ($cache->{$parent}) {
my @kids = grep $_->{generator} eq 'BSE::Generate::Catalog',
- Articles->children($parent);
+ BSE::TB::Articles->children($parent);
$cache->{$parent} = \@kids;
}
use BSE::Util::HTML;
use BSE::DummyArticle;
-our $VERSION = "1.014";
+our $VERSION = "1.015";
# returns non-zero if the Regenerate button should work
sub generate_button {
my $section = "$type settings";
- require Articles;
- for my $field (Article->columns) {
+ require BSE::TB::Articles;
+ for my $field (BSE::TB::Article->columns) {
if ($cfg->entry($section, $field)) {
$article->{$field} = $cfg->entryVar($section, $field);
}
# build a dummy article
use Constants qw($SEARCH_TITLE $SEARCH_TITLE_IMAGE $CGI_URI);
- require Articles;
- my %article = map { $_, '' } Article->columns;
+ require BSE::TB::Articles;
+ my %article = map { $_, '' } BSE::TB::Article->columns;
@article{qw(id parentid title titleImage displayOrder link level listed force_dynamic)} =
(-4, -1, $SEARCH_TITLE, $SEARCH_TITLE_IMAGE, 0, $CGI_URI."/search.pl", 0, 1, 1);
sub _shop_presets {
my ($cfg) = @_;
- require Articles;
- my $shop_base = Articles->getByPkey($SHOPID);
+ require BSE::TB::Articles;
+ my $shop_base = BSE::TB::Articles->getByPkey($SHOPID);
my $shop = { map { $_ => $shop_base->{$_} } $shop_base->columns };
$shop->{link} =~ /^\w+:/
or $shop->{link} = $cfg->entryErr('site', 'url') . $shop->{link};
sub _extras_presets {
my ($cfg, $presets) = @_;
- require Articles;
- my %article = map { $_, '' } Article->columns;
+ require BSE::TB::Articles;
+ my %article = map { $_, '' } BSE::TB::Article->columns;
$article{displayOrder} = 1;
$article{id} = -5;
$article{parentid} = -1;
my $cfg = delete $opts{cfg} || BSE::Cfg->single;
- my $articles = delete $opts{articles} || "Articles";
+ my $articles = delete $opts{articles} || "BSE::TB::Articles";
my $extras = delete $opts{extras} || [ pregenerate_list($cfg) ];
my $progress = delete $opts{progress} || sub {};
use BSE::Util::HTML;
use Carp qw(cluck confess);
-our $VERSION = "1.028";
+our $VERSION = "1.029";
=head1 NAME
$self->{perms} ||= BSE::Permissions->new($self->cfg);
if ($self->cfg->entry('basic', 'access_control', 0)) {
unless (ref $object) {
- require Articles;
- my $art = $object == -1 ? $site_article : Articles->getByPkey($object);
+ require BSE::TB::Articles;
+ my $art = $object == -1 ? $site_article : BSE::TB::Articles->getByPkey($object);
if ($art) {
$object = $art;
}
use vars qw/@ISA/;
@ISA = qw/Squirrel::Row/;
-our $VERSION = "1.006";
+our $VERSION = "1.007";
sub columns {
return qw/id name title description frequency keyword archive
sub _build_article {
my ($sub, $article, $opts) = @_;
- my @cols = Article->columns;
+ my @cols = BSE::TB::Article->columns;
shift @cols;
@$article{@cols} = ('') x @cols;
my $parent_id = $opts->{parentId} || $sub->{parentId} || -1;
my $parent;
if ($parent_id > 0) {
- $parent = Articles->getByPkey($parent_id);
+ $parent = BSE::TB::Articles->getByPkey($parent_id);
unless ($parent) {
$parent_id = -1;
}
$dispid = "$id ($work)";
$id = $work;
}
- require Articles;
- my $art = Articles->getByPkey($id);
+ require BSE::TB::Articles;
+ my $art = BSE::TB::Articles->getByPkey($id);
unless ($art) {
return ">> Cannot find article id $dispid <<";
}
while ($body =~ s#(?:pop)?(doclink|link)\[([^\]\[]+)\]#_any_link($cfg, \@urls, $1, $2, \$url_index)#ie) {
}
- $gen->remove_block('Articles', [], \$body);
+ $gen->remove_block('BSE::TB::Articles', [], \$body);
while (1) {
$body =~ s/[bi]\[([^\[\]]+)\]/$1/g
and next;
$gen->set_user($user);
$gen->set_sub($sub);
- return $gen->generate(\%article, 'Articles');
+ return $gen->generate(\%article, 'BSE::TB::Articles');
}
sub recipients {
#print STDERR "Making HTML\n";
$gen->set_user($user);
my %acts;
- %acts = $gen->baseActs("Articles", \%acts, $article);
+ %acts = $gen->baseActs("BSE::TB::Articles", \%acts, $article);
$html = BSE::Template->get_page($article->template, $cfg, \%acts,
undef, undef, $gen->variables);
if ($cfg->utf8) {
if (exists $opts->{archive} ? $opts->{archive} : $sub->{archive}) {
$callback->('general', undef, "Archiving article");
- require 'Articles.pm';
+ require BSE::TB::Articles;
$article{template} = $opts->{article_template} || $sub->{article_template};
$article{generator} = 'BSE::Generate::Article';
$article{parentid} = $opts->{parentId} || $sub->{parentId};
- my @cols = Article->columns;
+ my @cols = BSE::TB::Article->columns;
shift @cols;
- my $article = Articles->add(@article{@cols});
+ my $article = BSE::TB::Articles->add(@article{@cols});
use Constants qw(:edit $CGI_URI $ARTICLE_URI $LINK_TITLES);
my $link = "$ARTICLE_URI/$article->{id}.html";
if ($LINK_TITLES) {
require BSE::Regen;
$callback->('general', undef, "Generating article");
- BSE::Regen::generate_article('Articles', $article, $cfg);
+ BSE::Regen::generate_article('BSE::TB::Articles', $article, $cfg);
}
use BSE::Util::SQL qw/now_datetime/;
--- /dev/null
+package BSE::TB::Article;
+use strict;
+# represents an article from the database
+use Squirrel::Row;
+use BSE::TB::SiteCommon;
+use BSE::TB::TagOwner;
+use vars qw/@ISA/;
+@ISA = qw/Squirrel::Row BSE::TB::SiteCommon BSE::TB::TagOwner/;
+use Carp 'confess';
+
+our $VERSION = "1.024";
+
+=head1 NAME
+
+Article - article objects for BSE.
+
+=head1 SYNOPSIS
+
+ use BSE::API qw(bse_make_article);
+
+ my $article = bse_make_article(...)
+
+ my $article = BSE::TB::Articles->getByPkey($id);
+
+=head1 DESCRIPTION
+
+Implements the base article object for BSE.
+
+=head1 USEFUL METHODS
+
+=over
+
+=cut
+
+sub columns {
+ return qw/id parentid displayOrder title titleImage body
+ thumbImage thumbWidth thumbHeight imagePos
+ release expire keyword template link admin threshold
+ summaryLength generator level listed lastModified flags
+ customDate1 customDate2 customStr1 customStr2
+ customInt1 customInt2 customInt3 customInt4
+ lastModifiedBy created createdBy author pageTitle
+ force_dynamic cached_dynamic inherit_siteuser_rights
+ metaDescription metaKeywords summary menu titleAlias linkAlias
+ category/;
+}
+
+sub db_columns {
+ my ($self) = @_;
+
+ return map { $_ eq "summary" ? "summaryx" : $_ } $self->columns;
+}
+
+=item id
+
+=item parentid
+
+=item displayOrder
+
+=item title
+
+=item titleImage
+
+=item body
+
+=item thumbImage
+
+=item thumbWidth
+
+=item thumbHeight
+
+=item imagePos
+
+=item release
+
+=item expire
+
+=item keyword
+
+=item template
+
+=item threshold
+
+=item summaryLength
+
+=item generator
+
+=item level
+
+=item listed
+
+=item lastModified
+
+=item flags
+
+=item customDate1
+
+=item customDate2
+
+=item customStr1
+
+=item customStr2
+
+=item customInt1
+
+=item customInt2
+
+=item customInt3
+
+=item customInt4
+
+=item lastModifiedBy
+
+=item created
+
+=item createdBy
+
+=item author
+
+=item pageTitle
+
+=item force_dynamic
+
+=item cached_dynamic
+
+=item inherit_siteuser_rights
+
+=item metaDescription
+
+=item metaKeywords
+
+=item summary
+
+=item menu
+
+=item titleAlias
+
+=item linkAlias
+
+=item category
+
+Simple column accessors.
+
+=cut
+
+sub table {
+ 'article';
+}
+
+sub numeric {
+ qw(id listed parentid threshold summaryLength level
+ customInt1 customInt2 customInt3 customInt4 menu);
+}
+
+=item section
+
+Return the article's section.
+
+=cut
+
+sub section {
+ my ($self) = @_;
+
+ my $section = $self;
+ while ($section->{parentid} > 0
+ and my $parent = $section->parent) {
+ $section = $parent;
+ }
+
+ return $section;
+}
+
+=item parent
+
+Return the article's parent.
+
+=cut
+
+sub parent {
+ my ($self) = @_;
+
+ my $parentid = $self->parentid;
+
+ $parentid == -1
+ and return;
+ $self->{_parent} && $self->{_parent}->id == $parentid
+ and return $self->{_parent};
+ return ($self->{_parent} = BSE::TB::Articles->getByPkey($self->{parentid}));
+}
+
+sub update_dynamic {
+ my ($self, $cfg) = @_;
+
+ $cfg && $cfg->can('entry')
+ or confess 'update_dynamic called without $cfg';
+
+ # conditional in case something strange is in the config file
+ my $dynamic = $cfg->entry('basic', 'all_dynamic', 0) ? 1 : 0;
+
+ if (!$dynamic && $self->generator =~ /\bCatalog\b/) {
+ require Products;
+ my @tiers = Products->pricing_tiers;
+ @tiers and $dynamic = 1;
+ }
+
+ $dynamic or $dynamic = $self->{force_dynamic};
+
+ $dynamic or $dynamic = $self->is_access_controlled;
+
+ $dynamic or $dynamic = $self->force_dynamic_inherited;
+
+ $self->{cached_dynamic} = $dynamic;
+}
+
+=item is_dynamic
+
+Return true if the article is rendered dynamically.
+
+=cut
+
+sub is_dynamic {
+ $_[0]{cached_dynamic};
+}
+
+=item is_accessible_to($group)
+
+Return true if the article is accessible to the supplied siteuser
+group or group id.
+
+=cut
+
+sub is_accessible_to {
+ my ($self, $group) = @_;
+
+ my $groupid = ref $group ? $group->{id} : $group;
+
+ my @rows = BSE::DB->query(articleAccessibleToGroup => $self->{id}, $groupid);
+
+ scalar @rows;
+}
+
+sub group_ids {
+ my ($self) = @_;
+
+ map $_->{id}, BSE::DB->query(siteuserGroupsForArticle => $self->{id});
+}
+
+sub add_group_id {
+ my ($self, $id) = @_;
+
+ eval {
+ BSE::DB->single->run(articleAddSiteUserGroup => $self->{id}, $id);
+ };
+}
+
+sub remove_group_id {
+ my ($self, $id) = @_;
+
+ BSE::DB->single->run(articleDeleteSiteUserGroup => $self->{id}, $id);
+}
+
+=item is_access_controlled
+
+Return true if the article is access controlled.
+
+=cut
+
+sub is_access_controlled {
+ my ($self) = @_;
+
+ my @group_ids = $self->group_ids;
+ return 1 if @group_ids;
+
+ return 0
+ unless $self->{inherit_siteuser_rights};
+
+ my $parent = $self->parent
+ or return 0;
+
+ return $parent->is_access_controlled;
+}
+
+sub force_dynamic_inherited {
+ my ($self) = @_;
+
+ my $parent = $self->parent
+ or return 0;
+
+ $parent->{force_dynamic} && $parent->{flags} =~ /F/
+ and return 1;
+
+ return $parent->force_dynamic_inherited;
+}
+
+sub link_to_filename {
+ my ($self, $cfg, $link) = @_;
+
+ $cfg ||= BSE::Cfg->single;
+
+ defined $link or $link = $self->{link};
+
+ length $link or return;
+
+ my $filename = $link;
+
+ # remove any appended title,
+ $filename =~ s!(.)/\w+$!$1!;
+ $filename =~ s{^\w+://[\w.-]+(?::\d+)?}{};
+ $filename = $cfg->content_base_path() . $filename;
+ if ($filename =~ m(/$)) {
+ $filename .= $cfg->entry("basic", "index_file", "index.html");
+ }
+ $filename =~ s!//+!/!;
+
+ return $filename;
+}
+
+sub cached_filename {
+ my ($self, $cfg) = @_;
+
+ $cfg ||= BSE::Cfg->single;
+
+ my $dynamic_path = $cfg->entryVar('paths', 'dynamic_cache');
+ return $dynamic_path . "/" . $self->{id} . ".html";
+}
+
+sub html_filename {
+ my ($self, $cfg) = @_;
+
+ $cfg ||= BSE::Cfg->single;
+
+ return $self->is_dynamic
+ ? $self->cached_filename($cfg)
+ : $self->link_to_filename($cfg);
+}
+
+sub remove_html {
+ my ($self, $cfg) = @_;
+
+ my $filename = $self->html_filename($cfg)
+ or return 1;
+
+ unlink $filename
+ or return;
+
+ return 1;
+}
+
+sub remove {
+ my ($self, $cfg) = @_;
+
+ $cfg or confess "No \$cfg supplied to ", ref $self, "->remove";
+
+ $self->remove_tags;
+
+ $self->remove_images($cfg);
+
+ $self->remove_files($cfg);
+
+ # remove any step(child|parent) links
+ require OtherParents;
+ my @steprels = OtherParents->anylinks($self->{id});
+ for my $link (@steprels) {
+ $link->remove();
+ }
+
+ # remove any site user access controls
+ BSE::DB->single->run(bseRemoveArticleSiteUserGroups => $self->id);
+
+ # remove any admin user/group access controls
+ BSE::DB->single->run(bseRemoveArticleAdminAccess => $self->id);
+
+ # remove the static page
+ $self->remove_html($cfg);
+
+ $self->SUPER::remove();
+}
+
+=item all_parents
+
+Return a list of all parents.
+
+=cut
+
+sub all_parents {
+ my ($self) = @_;
+
+ my @result = $self->step_parents;
+ if ($self->{parentid} > 0 && !grep $_->{id} eq $self->{parentid}, @result) {
+ push @result, $self->parent;
+ }
+
+ return @result;
+}
+
+sub is_step_ancestor {
+ my ($self, $other, $max) = @_;
+
+ my $other_id = ref $other ? $other->{id} : $other;
+ my %seen;
+
+ $max ||= 10;
+
+ # early exit if possible
+ return 1 if $self->{parentid} == $other_id;
+
+ my @all_parents = $self->all_parents;
+ return 1 if grep $_->{id} == $other_id, @all_parents;
+ my @work = map [ 0, $_], grep !$seen{$_}++, @all_parents;
+ while (@work) {
+ my $entry = shift @work;
+ my ($level, $workart) = @$entry;
+
+ $level++;
+ if ($level < $max) {
+ @all_parents = $workart->all_parents;
+ return 1 if grep $_->{id} == $other_id, @all_parents;
+ push @work, map [ $level, $_ ], grep !$seen{$_}++, @all_parents;
+ }
+ }
+
+ return 0;
+}
+
+sub possible_stepparents {
+ my $self = shift;
+
+ return BSE::DB->query(articlePossibleStepparents => $self->{id}, $self->{id});
+}
+
+sub possible_stepchildren {
+ my $self = shift;
+
+ return BSE::DB->query(articlePossibleStepchildren => $self->{id}, $self->{id});
+}
+
+sub link {
+ my ($self, $cfg) = @_;
+
+ if ($self->flags =~ /P/) {
+ my $parent = $self->parent;
+ $parent and return $parent->link($cfg);
+ }
+
+ $self->is_linked
+ or return "";
+
+ $cfg ||= BSE::Cfg->single;
+
+ unless ($self->{linkAlias} && $cfg->entry('basic', 'use_alias', 1)) {
+ return $self->{link};
+ }
+
+ my $prefix = $cfg->entry('basic', 'alias_prefix', '');
+ my $link;
+ if ($cfg->entry('basic', 'alias_recursive')) {
+ my @steps = $self->{linkAlias};
+ my $article = $self;
+ while ($article = $article->parent) {
+ if ($article->{linkAlias}) {
+ unshift @steps, $article->{linkAlias};
+ }
+ }
+ $link = join('/', $prefix, @steps);
+ }
+ else {
+ $link = $prefix . '/' . $self->{linkAlias};
+ }
+ if ($cfg->entry('basic', 'alias_suffix', 1)) {
+ my $title = $self->{title};
+ $title =~ tr/a-zA-Z0-9/-/cs;
+ $link .= '/' . $title;
+ }
+ return $link;
+}
+
+=item admin
+
+Return the admin link for the article.
+
+=cut
+
+sub admin {
+ my ($self) = @_;
+
+ return BSE::Cfg->single->admin_url("admin", { id => $self->id });
+}
+
+=item is_linked
+
+Return true if the article can be linked to.
+
+=cut
+
+sub is_linked {
+ my ($self) = @_;
+
+ return $self->flags !~ /D/;
+}
+
+sub tag_owner_type {
+ return "BA";
+}
+
+# the time used for expiry/release comparisons
+sub _expire_release_datetime {
+ my ($year, $month, $day) = (localtime)[5,4,3];
+ my $today = sprintf("%04d-%02d-%02d 00:00:00ZZZ", $year+1900, $month+1, $day);
+}
+
+=item is_expired
+
+Returns true if the article expiry date has passed.
+
+=cut
+
+sub is_expired {
+ my $self = shift;
+
+ return $self->expire lt _expire_release_datetime();
+}
+
+=item is_released
+
+Returns true if the article release date has passed (ie. the article
+has been released.)
+
+=cut
+
+sub is_released {
+ my $self = shift;
+
+ return $self->release le _expire_release_datetime();
+}
+
+=item listed_in_menu
+
+Return true if the article should be listed in menus.
+
+=cut
+
+sub listed_in_menu {
+ my $self = shift;
+
+ return $self->listed == 1;
+}
+
+=item ancestors
+
+Returns a list of ancestors of self.
+
+=cut
+
+sub ancestors {
+ my ($self) = @_;
+
+ unless ($self->{_ancestors}) {
+ my @ancestors;
+ my $work = $self;
+ while ($work->parentid != -1) {
+ $work = $work->parent;
+ push @ancestors, $work;
+ }
+
+ $self->{_ancestors} = \@ancestors;
+ }
+
+ return @{$self->{_ancestors}};
+}
+
+=item is_descendant_of($ancestor)
+
+Return true if self is a decsendant of the supplied article or article
+id.
+
+=cut
+
+sub is_descendant_of {
+ my ($self, $ancestor) = @_;
+
+ my $ancestor_id = ref $ancestor ? $ancestor->id : $ancestor;
+
+ for my $anc ($self->ancestors) {
+ return 1 if $anc->id == $ancestor_id;
+ }
+
+ return 0;
+}
+
+=item visible_ancestors
+
+Returns all visible ancestors.
+
+Lists the top-level ancestor C<last>.
+
+This list does not include the article itself.
+
+=cut
+
+sub visible_ancestors {
+ my ($self) = @_;
+
+ return grep $_->listed, $self->ancestors;
+}
+
+=item menu_ancestors
+
+Returns visible ancestprs that are visible for menus (ie. listed = 1).
+
+Lists the top-level ancestor C<last>.
+
+This list does not include the article itself.
+
+=cut
+
+sub menu_ancestors {
+ my ($self) = @_;
+
+ return grep $_->listed, $self->ancestors;
+}
+
+=item should_generate
+
+Return true if this article should have pages generated, either for
+static content or for dynamic.
+
+=cut
+
+sub should_generate {
+ my ($self) = @_;
+
+ return $self->is_linked && $self->listed && $self->is_released && !$self->is_expired;
+}
+
+=item should_index
+
+Returns true if the article should be indexed.
+
+=cut
+
+sub should_index {
+ my ($self) = @_;
+
+ return ($self->listed || $self->is_index_even_if_hidden)
+ && $self->is_linked
+ && !$self->is_dont_index
+ && !$self->is_dont_index_or_kids
+}
+
+=item is_index_even_if_hidden
+
+Return true if the article's index even if hidden flag is set.
+
+=cut
+
+sub is_index_even_if_hidden {
+ my ($self) = @_;
+
+ return $self->flags =~ /I/;
+}
+
+=item is_dont_index
+
+Return true if the "don't index" flag (C<N>) is set.
+
+=cut
+
+sub is_dont_index {
+ return $_[0]->flags =~ /N/;
+}
+
+=item is_dont_index_or_kids
+
+Return true if the article or any of it's parents have the "don't
+index me or my children" flag (C<C>) set.
+
+=cut
+
+sub is_dont_index_or_kids {
+ my ($self) = @_;
+
+ $self->flags =~ /C/ and return 1;
+
+ my $parent = $self->parent
+ or return 0;
+
+ return $parent->is_dont_index_or_kids;
+}
+
+sub restricted_method {
+ my ($self, $name) = @_;
+
+ return $self->SUPER::restricted_method($name)
+ || $name =~ /^(?:update_|remove_|add_|mark_modified)/;
+}
+
+sub tableClass {
+ return "BSE::TB::Articles";
+}
+
+=item mark_modified
+
+Call by admin code to do the things we do when an article is modified.
+
+Parameters:
+
+=over
+
+=item *
+
+actor - an audit log compatible actor.
+
+=back
+
+=cut
+
+sub mark_modified {
+ my ($self, %opts) = @_;
+
+ require BSE::Util::SQL;
+ $self->set_lastModified(BSE::Util::SQL::now_sqldatetime());
+ $self->set_lastModifiedBy(ref $opts{actor} ? $opts{actor}->logon : "");
+}
+
+=item uncache
+
+Free any cached data.
+
+=cut
+
+sub uncache {
+ my ($self) = @_;
+
+ delete @{$self}{qw/_parent/};
+
+ $self->SUPER::uncache();
+}
+
+1;
+
+__END__
+
+=back
+
+=head1 BASE CLASSES
+
+L<BSE::TB::SiteCommon>
+
+L<BSE::TB::TagOwner>
+
+L<Squirrel::Row>
+
+=head1 AUTHOR
+
+Tony Cook <tony@develop-help.com>
+
+=cut
@ISA = qw/Squirrel::Row/;
use Carp 'confess';
-our $VERSION = "1.010";
+our $VERSION = "1.011";
sub columns {
return qw/id articleId displayName filename sizeInBytes description
sub article {
my $self = shift;
- require Articles;
+ require BSE::TB::Articles;
- return Articles->getByPkey($self->{articleId});
+ return BSE::TB::Articles->getByPkey($self->{articleId});
}
sub url {
--- /dev/null
+package BSE::TB::Articles;
+use strict;
+use Squirrel::Table;
+use vars qw(@ISA $VERSION);
+require BSE::TB::TagOwners;
+@ISA = qw(Squirrel::Table BSE::TB::TagOwners);
+use BSE::TB::Article;
+
+our $VERSION = "1.006";
+
+=head1 NAME
+
+Articles - BSE's article collection
+
+=head1 SYNOPSIS
+
+ use BSE::TB::Articles;
+
+ my $article = BSE::TB::Articles->make(...);
+ my $article = BSE::TB::Articles->getByPkey($id)
+ # etc
+
+=head1 DESCRIPTION
+
+The collective class for BSE articles.
+
+=head1 USEFUL METHODS
+
+=over
+
+=cut
+
+sub rowClass {
+ return 'BSE::TB::Article';
+}
+
+=item sections
+
+Returns a list of articles which are sections
+
+=cut
+
+sub sections {
+ my ($self) = @_;
+
+ return $self->getBy('level', 1);
+}
+
+=item subsections
+
+Returns a list of articles which are sub sections
+
+=cut
+
+sub subsections {
+ my ($self) = @_;
+
+ return $self->getBy('level', 2);
+}
+
+=item children($id)
+
+Child articles of the given article id
+
+=cut
+
+sub children {
+ my ($self, $id) = @_;
+
+ return $self->getBy('parentid', $id);
+}
+
+=item listedChildren($id)
+
+Children of the given article id that are listed and in the display
+order
+
+=cut
+
+sub listedChildren {
+ my ($self, $id) = @_;
+ my ($year, $month, $day) = (localtime)[5,4,3];
+ my $today = sprintf("%04d-%02d-%02d 00:00:00ZZZ", $year+1900, $month+1, $day);
+ my @work = $self->children($id);
+ return sort { $b->{displayOrder} <=> $a->{displayOrder} }
+ grep { $_->{listed} && $today ge $_->{release}
+ && $today le $_->{expire}} @work;
+}
+
+=item summary
+
+Return a list of hashes with article id and title for every article.
+
+=cut
+
+sub summary {
+ BSE::DB->query('articlesList');
+}
+
+=item allids
+
+Return a list of all article ids.
+
+=cut
+
+sub allids {
+ my ($self) = @_;
+
+ if (ref $self) {
+ return map $_->{id}, $self->all;
+ }
+ else {
+ return map $_->{id}, BSE::DB->query('Articles.ids');
+ }
+}
+
+=item visible_stepkids($id)
+
+Return a list of visible stepkids of the given article id.
+
+=cut
+
+sub visible_stepkids {
+ my ($self, $id) = @_;
+
+ use BSE::Util::SQL qw/now_sqldate/;
+ my $today = now_sqldate();
+
+ return BSE::TB::Articles->getSpecial('visibleStepKids', $id, $today);
+}
+
+=item all_visible_kids($id)
+
+Return a list of all visible children of the given article id.
+
+=cut
+
+sub all_visible_kids {
+ my ($self, $id) = @_;
+
+ require 'OtherParents.pm';
+
+ my @otherlinks = OtherParents->getBy(parentId=>$id);
+ my @normalkids = BSE::TB::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 };
+}
+
+=item all_visible_kid_tags($id)
+
+Return a hash with two keys, C<tags> being all tags for all visible
+children of C<$id>, and C<members> being all tag member objects for
+all visible children of C<$id>.
+
+=cut
+
+sub all_visible_kid_tags {
+ my ($self, $id) = @_;
+
+ require BSE::TB::Tags;
+ require BSE::TB::TagMembers;
+ return
+ {
+ tags => [ BSE::TB::Tags->getSpecial(allkids => $id, $id) ],
+ members => [ BSE::TB::TagMembers->getSpecial(allkids => $id, $id) ],
+ };
+}
+
+=item global_files
+
+Return a list of global files.
+
+=cut
+
+sub global_files {
+ my ($self) = @_;
+
+ require BSE::TB::ArticleFiles;
+ return BSE::TB::ArticleFiles->getBy(articleId => -1);
+}
+
+=item allkid_summary($parent_id)
+
+Return a list of hash per child, each with id, displayOrder sorted for
+display.
+
+Entries with step_id are for step children of $parent_id.
+
+=cut
+
+sub allkid_summary {
+ my ($class, $parent_id) = @_;
+
+ my @child_order = BSE::DB->query(bseChildOrder => $parent_id);
+ my @stepchild_order = BSE::DB->query(bseStepchildOrder => $parent_id);
+
+ return sort { $b->{displayOrder} <=> $a->{displayOrder} }
+ ( @child_order, @stepchild_order );
+}
+
+=item reorder_child($parent_id, $child_id, $after_id)
+
+Move article C<$child_id> after C<$after_id> in the all children list
+of article C<$after_id>.
+
+Returns a true value on success.
+
+=cut
+
+sub reorder_child {
+ my ($class, $parent_id, $child_id, $after_id) = @_;
+
+ my @child_order = $class->allkid_summary($parent_id);
+
+ my ($child_index) = grep $child_order[$_]{id} == $child_id, 0..$#child_order
+ or return; # nothing to do, it's not a child
+ my @order = map $_->{displayOrder}, @child_order;
+
+ if ($child_index > 0 && $child_order[$child_index-1]{id} == $after_id
+ || $child_index == 0 && $after_id == 0) {
+ # trivial success
+ return 1;
+ }
+
+ # remove the child from the order
+ my ($child) = splice(@child_order, $child_index, 1);
+
+ my $start_index;
+ if ($after_id == 0) {
+ unshift @child_order, $child;
+ $start_index = 0;
+ }
+ else {
+ my ($after_index) = grep $child_order[$_]{id} == $after_id, 0..$#child_order
+ or return; # after not found, nothing to do
+
+ splice(@child_order, $after_index+1, 0, $child);
+ $start_index = $after_index + 1;
+ }
+
+ for my $index (0 .. $#order) {
+ my $child = $child_order[$index];
+ if ($child->{step_id}) {
+ BSE::DB->run(bseSetStepOrder => $order[$index], $child->{step_id});
+ }
+ else {
+ BSE::DB->run(bseSetArticleOrder => $order[$index], $child->{id});
+ }
+ }
+
+ return 1;
+}
+
+=item categories
+
+Return a list of all configured article categories.
+
+Each entry is a hash containing C<id> and C<name>.
+
+=cut
+
+sub categories {
+ my $cfg = BSE::Cfg->single;
+
+ my @cat_ids = split /,/, $cfg->entry("article categories", "ids", "");
+ grep $_ eq "", @cat_ids
+ or unshift @cat_ids, "";
+
+ my @cats;
+ for my $id (@cat_ids) {
+ my $section = length $id ? "article category $id" : "article category empty";
+ my $def_name = length $id ? ucfirst $id : "(None)";
+ my $name = $cfg->entry($section, "name",
+ $cfg->entry("article categories", $id, $def_name));
+ push @cats, +{ id => $id, name => $name };
+ }
+
+ return @cats;
+}
+
+1;
+
+=back
+
+=head1 AUTHOR
+
+Tony Cook <tony@develop-help.com>
+
+=cut
+
@ISA = qw/Squirrel::Row BSE::ThumbCommon BSE::TB::TagOwner/;
use Carp qw(confess);
-our $VERSION = "1.009";
+our $VERSION = "1.010";
=head1 NAME
return BSE::TB::Site->new;
}
else {
- require Articles;
- return Articles->getByPkey($self->articleId);
+ require BSE::TB::Articles;
+ return BSE::TB::Articles->getByPkey($self->articleId);
}
}
use strict;
use Carp qw(confess);
-our $VERSION = "1.019";
+our $VERSION = "1.020";
=head1 NAME
sub step_parents {
my ($self) = @_;
- Articles->getSpecial('stepParents', $self->{id});
+ BSE::TB::Articles->getSpecial('stepParents', $self->{id});
}
sub visible_step_parents {
my ($self) = @_;
my $now = now_sqldate();
- Articles->getSpecial('visibleStepParents', $self->{id}, $now);
+ BSE::TB::Articles->getSpecial('visibleStepParents', $self->{id}, $now);
}
sub stepkids {
my ($self) = @_;
- return Articles->getSpecial('stepKids', $self->{id});
+ return BSE::TB::Articles->getSpecial('stepKids', $self->{id});
}
sub allstepkids {
my ($self) = @_;
- return Articles->getSpecial('stepKids', $self->{id});
+ return BSE::TB::Articles->getSpecial('stepKids', $self->{id});
}
sub visible_stepkids {
return Products->getSpecial('visibleStep', $self->{id}, $today);
}
else {
- return Articles->getSpecial('visibleStepKids', $self->{id}, $today);
+ return BSE::TB::Articles->getSpecial('visibleStepKids', $self->{id}, $today);
}
return ();
require 'OtherParents.pm';
my @otherlinks = OtherParents->getBy(parentId=>$self->{id});
- my @normalkids = Articles->children($self->{id});
+ my @normalkids = BSE::TB::Articles->children($self->{id});
my %order = (
(map { $_->{id}, $_->{displayOrder} } @normalkids ),
(map { $_->{childId}, $_->{parentDisplayOrder} } @otherlinks),
sub all_visible_kids {
my ($self) = @_;
- Articles->all_visible_kids($self->{id});
+ BSE::TB::Articles->all_visible_kids($self->{id});
}
sub all_visible_kid_tags {
my ($self) = @_;
- Articles->all_visible_kid_tags($self->{id});
+ BSE::TB::Articles->all_visible_kid_tags($self->{id});
}
sub all_visible_products {
sub visible_kids {
my ($self) = @_;
- return Articles->listedChildren($self->{id});
+ return BSE::TB::Articles->listedChildren($self->{id});
}
=item menu_kids
my ($self) = @_;
return sort { $b->{displayOrder} <=> $a->{displayOrder} }
- Articles->children($self->{id});
+ BSE::TB::Articles->children($self->{id});
}
=item files
sub reorder_child {
my ($self, $child_id, $after_id) = @_;
- Articles->reorder_child($self->{id}, $child_id, $after_id);
+ BSE::TB::Articles->reorder_child($self->{id}, $child_id, $after_id);
}
sub set_image_order {
=head1 SYNOPSIS
- my $cat = Article->tag_category($name);
+ my $cat = BSE::TB::Article->tag_category($name);
my @deps = $cat->deps;
=cut
-our $VERSION = "1.000";
+our $VERSION = "1.001";
sub columns {
qw(id cat owner_type);
use strict;
use base 'BSE::UI::AdminDispatch';
use BSE::Edit::Base;
-use Articles;
+use BSE::TB::Articles;
-our $VERSION = "1.000";
+our $VERSION = "1.001";
sub dispatch {
my ($self, $req) = @_;
my $cgi = $req->cgi;
my $cfg = $req->cfg;
my $id = $cgi->param('id');
- my $articles = 'Articles'; # for a later switch to proper objects, I hope
+ my $articles = 'BSE::TB::Articles'; # for a later switch to proper objects, I hope
my $result;
if (defined $id && $id =~ /\d/ && $id == -1) {
my $obj = get_class('BSE::Edit::Site', $cfg)
use strict;
use BSE::SubscriptionTypes;
use BSE::Util::Tags qw(tag_hash);
-use Articles;
+use BSE::TB::Articles;
use BSE::Message;
use BSE::Util::HTML qw(:default popup_menu);
use BSE::Util::Iterate;
use base 'BSE::UI::AdminDispatch';
-our $VERSION = "1.004";
+our $VERSION = "1.005";
=head1 NAME
my %valid_types = map { $_ => 1 } _valid_archive_types($req);
my $shopid = $req->cfg->entryErr('articles', 'shop');
- my @all = Articles->query([qw/id title generator/],
+ my @all = BSE::TB::Articles->query([qw/id title generator/],
[ [ '<>', 'id', $shopid ] ]);
if ($req->cfg->entry('basic', 'access_filter_parents', 0)) {
@all = grep($req->user_can('edit_add_child', $_->{id})
if ($q->param('archive')) {
my $id = $q->param('parentId');
if ($id) {
- my $article = Articles->getByPkey($id);
+ my $article = BSE::TB::Articles->getByPkey($id);
if ($article) {
unless ($req->user_can('edit_add_child', $article)
|| ($sub && $sub->{parentId} == $id)) {
package BSE::UI::AdminPage;
use strict;
-use Articles;
+use BSE::TB::Articles;
use BSE::Util::HTML qw(escape_uri);
use BSE::UI::AdminDispatch;
-use Articles;
+use BSE::TB::Articles;
our @ISA = qw(BSE::UI::AdminDispatch);
-our $VERSION = "1.000";
+our $VERSION = "1.001";
my %actions =
(
$admin_links = $cgi->param('admin_links')
if defined $cgi->param('admin_links');
- #my $articles = Articles->new;
- my $articles = 'Articles';
+ #my $articles = BSE::TB::Articles->new;
+ my $articles = 'BSE::TB::Articles';
my $article;
$article = $articles->getByPkey($id) if $id =~ /^\d+$/;
use BSE::Util::Tags qw(tag_hash);
use BSE::Regen qw(pregenerate_list content_one_extra response_one_extra);
-our $VERSION = "1.002";
+our $VERSION = "1.003";
my %actions =
(
or return $self->req_list($req, { template => "Unknown pregen template $id" });
if ($entry->{dynamic}) {
- my ($content, $article) = content_one_extra("Articles", $entry);
+ my ($content, $article) = content_one_extra("BSE::TB::Articles", $entry);
require BSE::Dynamic::Article;
my $dyngen = BSE::Dynamic::Article->new($req);
return $dyngen->generate($article, $content);
}
else {
- return response_one_extra("Articles", $entry);
+ return response_one_extra("BSE::TB::Articles", $entry);
}
}
package BSE::UI::AdminReorder;
use strict;
use base 'BSE::UI::AdminDispatch';
-use Articles;
+use BSE::TB::Articles;
use OtherParents;
use List::Util ();
-our $VERSION = "1.001";
+our $VERSION = "1.002";
=head1 NAME
(
$req,
[
- map [ $_, $_, 'displayOrder' ], Articles->getBy(parentid => $parentid)
+ map [ $_, $_, 'displayOrder' ], BSE::TB::Articles->getBy(parentid => $parentid)
]
);
$req->user_can(bse_edit_reorder_children => $stepparent)
or return $self->access_error($req, $msg);
- my $parent = Articles->getByPkey($stepparent)
+ my $parent = BSE::TB::Articles->getByPkey($stepparent)
or return $self->error($req, "Unknown article $stepparent");
my @otherlinks = OtherParents->getBy(parentId => $stepparent);
- my @normalkids = Articles->children($stepparent);
+ my @normalkids = BSE::TB::Articles->children($stepparent);
my @stepkids = $parent->stepkids;
my %stepkids = map { $_->{id}, $_ } @stepkids;
my @kids =
$req->user_can(bse_edit_reorder_children => $stepchild)
or return $self->access_error($req, $msg);
- my $child = Articles->getByPkey($stepchild)
+ my $child = BSE::TB::Articles->getByPkey($stepchild)
or return $self->error($req, "Unknown child $stepchild");
my @otherlinks = OtherParents->getBy(childId=>$stepchild);
- my @stepparents = map Articles->getByPkey($_->{parentId}), @otherlinks;
+ my @stepparents = map BSE::TB::Articles->getByPkey($_->{parentId}), @otherlinks;
my %stepparents = map { $_->{id}, $_ } @stepparents;
@reverse{@fields} = @reverse;
@fields = grep exists($kids->[0][0]{$_}), @fields;
my @num =
- my %num = map { $_ => 1 } Article->numeric;
+ my %num = map { $_ => 1 } BSE::TB::Article->numeric;
$code =
sub {
use SiteUsers;
use BSE::Util::Tags qw(tag_hash_plain);
-our $VERSION = "1.000";
+our $VERSION = "1.001";
my %actions =
(
my $article;
if ($args =~ /^\d+$/) {
- require Articles;
- $article = Articles->getByPkey($args);
+ require BSE::TB::Articles;
+ $article = BSE::TB::Articles->getByPkey($args);
}
else {
$article = $req->get_article($args);
use Constants qw(:shop $SHOPID $PRODUCTPARENT
$SHOP_URI $CGI_URI $AUTO_GENERATE);
use BSE::TB::Images;
-use Articles;
+use BSE::TB::Articles;
use BSE::Sort;
use BSE::Util::Tags qw(tag_hash tag_error_img tag_object_plain tag_object tag_article);
use BSE::Util::Iterate;
use BSE::Util::SQL qw/now_sqldate sql_to_date date_to_sql sql_date sql_datetime/;
use BSE::Util::Valid qw/valid_date/;
-our $VERSION = "1.025";
+our $VERSION = "1.026";
my %actions =
(
my $subcat_index = -1;
my @subcats = sort { $b->{displayOrder} <=> $a->{displayOrder} }
grep $_->{generator} eq 'BSE::Generate::Catalog',
- Articles->children($catalog->{id});
+ BSE::TB::Articles->children($catalog->{id});
my $image_uri = cfg_dist_image_uri();
my $blank = qq!<img src="$image_uri/trans_pixel.gif" width="17" height="13" border="0" align="absbottom" />!;
my $cgi = $req->cgi;
my $session = $req->session;
my $shopid = $req->cfg->entryErr('articles', 'shop');
- my $shop = Articles->getByPkey($shopid);
+ my $shop = BSE::TB::Articles->getByPkey($shopid);
my @catalogs = sort { $b->{displayOrder} <=> $a->{displayOrder} }
- grep $_->{generator} eq 'BSE::Generate::Catalog', Articles->children($shopid);
+ grep $_->{generator} eq 'BSE::Generate::Catalog', BSE::TB::Articles->children($shopid);
my $catalog_index = -1;
$message = $req->message($message);
if (defined $cgi->param('showstepkids')) {
push(@catalogs, { id=>$parent, display=>$title }) if $title;
my @kids = sort { $b->{displayOrder} <=> $a->{displayOrder} }
grep $_->{generator} eq 'BSE::Generate::Catalog',
- Articles->children($parent);
+ BSE::TB::Articles->children($parent);
$title .= ' / ' if $title;
unshift(@work, map [ $_->{id}, $title.$_->{title} ], @kids);
}
package BSE::UI::Image;
use strict;
-use Articles;
+use BSE::TB::Articles;
use BSE::TB::Images;
use BSE::Util::Tags qw(tag_hash);
use BSE::Util::HTML qw(escape_uri);
-our $VERSION = "1.000";
+our $VERSION = "1.001";
# we don't do anything fancy on dispatch yet, so don't use the
# dispatch classes
my $id = $cgi->param('id');
$id && $id =~ /^\d+$/
or return $class->error($req, "required id parameter not present or invalid");
- my $article = Articles->getByPkey($id)
+ my $article = BSE::TB::Articles->getByPkey($id)
or return $class->error($req, "unknown article id $id");
my $image;
package BSE::UI::Page;
use strict;
-use Articles;
+use BSE::TB::Articles;
use BSE::Util::HTML qw(escape_uri);
use BSE::UI::Dispatch;
use BSE::Template;
our @ISA = qw(BSE::UI::Dispatch);
-our $VERSION = "1.007";
+our $VERSION = "1.008";
# we don't do anything fancy on dispatch yet, so don't use the
# dispatch classes
if ($page) {
$dump .= "Page lookup: '$page'\n";
if ($page =~ /^[0-9]+$/) {
- $article = Articles->getByPkey($page);
+ $article = BSE::TB::Articles->getByPkey($page);
$dump .= "Search by id\n";
$search_by_id = 1;
}
$dump .= "Removed recursive prefix\n";
}
$dump .= "Looking for alias: $alias\n";
- ($article) = Articles->getBy(linkAlias => $alias);
+ ($article) = BSE::TB::Articles->getBy(linkAlias => $alias);
}
}
sub _generate_pregen {
my ($self, $req, $article, $srcname) = @_;
- my $articles = 'Articles';
+ my $articles = 'BSE::TB::Articles';
my $genname = $article->{generator};
eval "use $genname";
$@ && die $@;
package BSE::UI::Search;
use strict;
use base 'BSE::UI::Dispatch';
-use Articles;
+use BSE::TB::Articles;
use BSE::DB;
use Constants qw(:search);
use Carp;
use BSE::Util::Tags qw(tag_article);
use BSE::Request;
-our $VERSION = "1.003";
+our $VERSION = "1.004";
my %actions =
(
if ($cfg->entry('search', 'keep_inaccessible')) {
for my $entry (@results[$articles_start..$articles_end]) {
- my $article = Articles->getByPkey($entry->[0])
+ my $article = BSE::TB::Articles->getByPkey($entry->[0])
or die "Cannot retrieve article $entry->[0]\n";
push(@articles, $article);
}
my $seen = 0;
while ($index < @results && $seen <= $articles_end) {
my $id = $results[$index][0];
- my $article = Articles->getByPkey($id)
+ my $article = BSE::TB::Articles->getByPkey($id)
or die "Cannot retrieve article $id\n";
if ($req->siteuser_has_access($article)) {
if ($seen >= $articles_start) {
sort { $b->{displayOrder} <=> $a->{displayOrder} }
grep { ($_->{listed} || $included{$_->{id}})
&& !$excluded{$_->{id}} }
- Articles->getBy('level', 1);
+ BSE::TB::Articles->getBy('level', 1);
unshift(@sections, { ""=>$SEARCH_ALL });
my %sections = map { %$_ } @sections;
# now a list of values ( in the correct order
use BSE::Util::Secure qw/make_secret/;
use BSE::Util::Tags qw(tag_hash tag_error_img tag_hash_plain tag_article tag_article_plain);
use BSE::ComposeMail;
-use Articles;
+use BSE::TB::Articles;
-our $VERSION = "1.000";
+our $VERSION = "1.001";
my %actions =
(
return;
}
- my $article = Articles->getByPkey($id);
+ my $article = BSE::TB::Articles->getByPkey($id);
unless ($article) {
$$error = "article $id not found";
return;
use base 'BSE::UI::UserCommon';
use Carp qw(confess);
-our $VERSION = "1.031";
+our $VERSION = "1.032";
use constant MAX_UNACKED_CONF_MSGS => 3;
use constant MIN_UNACKED_CONF_GAP => 2 * 24 * 60 * 60;
# check the user has access to this file (RT#531)
my $article;
if ($file->{articleId} != -1) {
- require Articles;
- $article ||= Articles->getByPkey($file->{articleId})
+ require BSE::TB::Articles;
+ $article ||= BSE::TB::Articles->getByPkey($file->{articleId})
or return $self->req_show_logon($req,
$msgs->('downloadarticle',
"Could not load article for file"));
use BSE::CfgInfo qw(custom_class);
use BSE::Cart;
-our $VERSION = "1.026";
+our $VERSION = "1.027";
=head1 NAME
my $article;
if ($args =~ /^\d+$/) {
- require Articles;
- $article = Articles->getByPkey($args);
+ require BSE::TB::Articles;
+ $article = BSE::TB::Articles->getByPkey($args);
}
else {
$article = $req->get_article($args);
$result
and return $result;
- require Articles;
- $result = $self->access_filter(Articles->listedChildren(-1));
+ require BSE::TB::Articles;
+ $result = $self->access_filter(BSE::TB::Articles->listedChildren(-1));
$self->set_cached(dynlevel1 => $result);
return $result;
$cached && $cached->[0] == $parent->{id}
and return $cached->[1];
- require Articles;
- my $result = $self->access_filter(Articles->listedChildren($parent->{id}));
+ require BSE::TB::Articles;
+ my $result = $self->access_filter(BSE::TB::Articles->listedChildren($parent->{id}));
$self->set_cached(dynlevel2 => [ $parent->{id}, $result ]);
return $result;
$cached && $cached->[0] == $parent->{id}
and return $cached->[1];
- require Articles;
- my $result = $self->access_filter( Articles->listedChildren($parent->{id}));
+ require BSE::TB::Articles;
+ my $result = $self->access_filter( BSE::TB::Articles->listedChildren($parent->{id}));
$self->set_cached(dynlevel3 => [ $parent->{id}, $result ]);
return $result;
@ids == 1 and $state->{parentid} = $ids[0];
- require Articles;
- return $self->access_filter(map Articles->all_visible_kids($_), @ids);
+ require BSE::TB::Articles;
+ return $self->access_filter(map BSE::TB::Articles->all_visible_kids($_), @ids);
}
sub tags_for_dynallkids_of {
@ids
or return { tags => [], members => [] };
- require Articles;
+ require BSE::TB::Articles;
if (@ids == 1) {
- return Articles->all_visible_kid_tags($ids[0]);
+ return BSE::TB::Articles->all_visible_kid_tags($ids[0]);
}
else {
my %tags;
my @members;
for my $id (@ids) {
- my $more_tags = Articles->all_visible_kid_tags($id);
+ my $more_tags = BSE::TB::Articles->all_visible_kid_tags($id);
for my $tag (@{$more_tags->{tags}}) {
$tags{$tag->id} = $tag;
}
}
@ids = grep defined && /^\d+$|^-1$/, @ids;
- require Articles;
- return $self->access_filter( map Articles->listedChildren($_), @ids);
+ require BSE::TB::Articles;
+ return $self->access_filter( map BSE::TB::Articles->listedChildren($_), @ids);
}
=item iterator dyncart
my ($self, $article_id) = @_;
if ($article_id =~ /^\d+$/) {
- my $result = Articles->getByPkey($article_id);
+ my $result = BSE::TB::Articles->getByPkey($article_id);
$result or print STDERR "** Unknown article id $article_id **\n";
return $result ? $result : ();
}
elsif ($article_id =~ /^alias\((\w+)\)$/) {
- my $result = Articles->getBy(linkAlias => $1);
+ my $result = BSE::TB::Articles->getBy(linkAlias => $1);
$result or print STDERR "** Unknown article alias $article_id **\n";
return $result ? $result : ();
}
elsif ($article_id =~ /^childrenof\((.*)\)$/) {
my $id = $1;
if ($id eq '-1') {
- return Articles->all_visible_kids(-1);
+ return BSE::TB::Articles->all_visible_kids(-1);
}
else {
my @parents = $self->_find_articles($id)
$tags = $self->{tags}{$iter};
}
- require Articles;
+ require BSE::TB::Articles;
- return Articles->categorize_tags
+ return BSE::TB::Articles->categorize_tags
(
[ keys %$tags ],
$selected_tags,
my $article;
if ($article_id =~ /^\d+$/) {
- require Articles;
- $article = Articles->getByPkey($args);
+ require BSE::TB::Articles;
+ $article = BSE::TB::Articles->getByPkey($args);
}
else {
$article = $self->{req}->get_article($article_id);
my $expr = $1;
my $orig_expr = $expr;
unless ($cols_re) {
- require Articles;
- my $cols_expr = '(' . join('|', Article->columns) . ')';
+ require BSE::TB::Articles;
+ my $cols_expr = '(' . join('|', BSE::TB::Article->columns) . ')';
$cols_re = qr/\[$cols_expr\]/;
}
$expr =~ s/$cols_re/\$article->{$1}/g;
my $all_found = 1;
TAGS:
for my $tag_name (@$tags) {
- my $tag = Articles->getTagByName($tag_name);
+ my $tag = BSE::TB::Articles->getTagByName($tag_name);
unless ($tag) {
# can't find a tag that doesn't exist
$all_found = 0;
@ISA = qw(Exporter);
require Exporter;
-our $VERSION = "1.026";
+our $VERSION = "1.027";
sub _get_parms {
my ($acts, $args) = @_;
require BSE::Generate;
my $gen = BSE::Generate->new(cfg=>$cfg);
return $gen->format_body(acts => $acts,
- articles => 'Articles',
+ articles => 'BSE::TB::Articles',
text => $value,
templater => $templater);
},
require BSE::Generate;
my $gen = BSE::Generate->new(cfg=>$cfg);
- $gen->remove_block('Articles', $acts, \$value);
+ $gen->remove_block('BSE::TB::Articles', $acts, \$value);
return escape_html($value);
}
use BSE::TB::Site;
use BSE::Util::HTML;
-our $VERSION = "1.019";
+our $VERSION = "1.020";
sub _base_variables {
my ($self, %opts) = @_;
sub _categorize_tags {
my ($tags, $selected_tags, $opts) = @_;
- require Articles;
+ require BSE::TB::Articles;
if ($opts && $opts->{members} && !$opts->{counts}) {
my %counts;
$opts->{counts} = \%counts;
}
- return Articles->categorize_tags($tags, $selected_tags, $opts);
+ return BSE::TB::Articles->categorize_tags($tags, $selected_tags, $opts);
}
sub _paged {
my $articles;
sub _articles {
unless ($articles) {
- require Articles;
- $articles = _variable_class("Articles");
+ require BSE::TB::Articles;
+ $articles = _variable_class("BSE::TB::Articles");
}
return $articles;
package Product;
use strict;
# represents a product from the database
-use Articles;
+use BSE::TB::Articles;
use vars qw/@ISA/;
-@ISA = qw/Article/;
+@ISA = qw/BSE::TB::Article/;
-our $VERSION = "1.003";
+our $VERSION = "1.004";
# subscription_usage values
use constant SUBUSAGE_START_ONLY => 1;
}
sub bases {
- return { articleId=>{ class=>'Article'} };
+ return { articleId=>{ class=>'BSE::TB::Article'} };
}
sub subscription_required {
use lib "$FindBin::Bin/modules";
use CGI qw(:standard);
use Carp; # 'verbose'; # remove the 'verbose' in production
-use Articles;
+use BSE::TB::Articles;
use BSE::Cfg;
use BSE::DB;
use BSE::Template;
# loads all of the articles into memory
# hopefully a print template won't include too many references to
# other articles anyway
-#my $articles = Articles->new;
+#my $articles = BSE::TB::Articles->new;
-my $article = Articles->getByPkey($id)
+my $article = BSE::TB::Articles->getByPkey($id)
or error_page("No article with id $id found");
eval "use $article->{generator}";
die $@ if $@;
-my $generator = $article->{generator}->new(articles=>'Articles', cfg => $cfg,
+my $generator = $article->{generator}->new(articles=>'BSE::TB::Articles', cfg => $cfg,
top => $article);
my $template = param('template');
$text =~ s/<:\s*embed\s+(?:start|end)\s*:>//g;
print "Content-Type: $type\n\n";
-print $generator->generate_low($text, $article, 'Articles');
+print $generator->generate_low($text, $article, 'BSE::TB::Articles');
sub error_page {
$error ||= "Unknown error";
my %article;
- my @cols = Article->columns;
+ my @cols = BSE::TB::Article->columns;
@article{@cols} = ('') x @cols;
$article{id} = -10;
$article{title} = "Error";
my %acts;
%acts =
(
- $gen->baseActs('Articles', \%acts, \%article),
+ $gen->baseActs('BSE::TB::Articles', \%acts, \%article),
error => sub { CGI::escapeHTML($error) },
);
-/Article.html
+/BSE::TB::Article.html
/BSE::TB::SiteCommon.html
/BSE::TB::TagOwner.html
/BSE::UI::Affiliate.html
my @targets =
(
'access.html',
- 'Article.html',
+ 'BSE::TB::Article.html',
'bse.html',
'BSE::TB::SiteCommon.html',
'BSE::TB::TagOwner.html',
use lib "$FindBin::Bin/../cgi-bin/modules";
use BSE::Index;
use BSE::API qw(bse_init bse_cfg);
-use Articles;
+use BSE::TB::Articles;
use Encode;
bse_init("../cgi-bin");
use lib "$FindBin::Bin/../cgi-bin/modules";
use BSE::Regen qw/generate_all generate_article generate_base pregenerate_list generate_one_extra/;
use BSE::API qw(bse_init bse_cfg);
-use Articles;
+use BSE::TB::Articles;
bse_init("../cgi-bin");
my $cfg = bse_cfg();
-my $articles = 'Articles';
+my $articles = 'BSE::TB::Articles';
$| = 1;
use strict;
use lib '../cgi-bin/modules';
use DBI;
-use Article;
+use BSE::TB::Article;
use Constants qw($DSN $UN $PW $CGI_URI $SHOP_URI $ROOT_URI);
use BSE::API qw(bse_init bse_cfg);
use BSE::Util::SQL qw(now_sqldate now_sqldatetime);
my $dbh = BSE::DB->single->dbh
or die "Cannot connect to database: ",DBI->errstr;
-my @columns = Article->columns;
+my @columns = BSE::TB::Article->columns;
$dbh->do('delete from article')
or die "Cannot delete articles: ",$dbh->errstr;
$dbh->do('delete from product')
my $error;
ok($art->set_tags([ "colour: red", "size: large" ], \$error),
"set some tags should succeed");
- my $cat = Articles->tag_category("colour");
+ my $cat = BSE::TB::Articles->tag_category("colour");
ok($cat, "get the 'colour' tag cat");
my @orig_deps = $cat->deps;
use File::Spec;
use BSE::Cfg;
-use_ok("Article");
+use_ok("BSE::TB::Article");
{
my $cfg = BSE::Cfg->new_from_text(text => <<'EOS');
public_html=$(base)/htdocs
EOS
- is(Article->link_to_filename($cfg, "/"), "/test/htdocs/index.html",
+ is(BSE::TB::Article->link_to_filename($cfg, "/"), "/test/htdocs/index.html",
"check default link to /");
- is(Article->link_to_filename($cfg, "/foo.html/test"), "/test/htdocs/foo.html",
+ is(BSE::TB::Article->link_to_filename($cfg, "/foo.html/test"), "/test/htdocs/foo.html",
"check default link to filename - trailing title");
- is(Article->link_to_filename($cfg, "/test.html"), "/test/htdocs/test.html",
+ is(BSE::TB::Article->link_to_filename($cfg, "/test.html"), "/test/htdocs/test.html",
"check default link to filename - trailing filename");
- is(Article->link_to_filename($cfg, "//test.html"), "/test/htdocs/test.html",
+ is(BSE::TB::Article->link_to_filename($cfg, "//test.html"), "/test/htdocs/test.html",
"check default link to filename - doubled /");
}
index_file=default.htm
EOS
- is(Article->link_to_filename($cfg, "/"), "/test/htdocs/default.htm",
+ is(BSE::TB::Article->link_to_filename($cfg, "/"), "/test/htdocs/default.htm",
"check cfg link to filename");
}
}
#ok(chdir $cgidir, "switch to CGI directory");
# create some articles to test with
-use Articles;
+use BSE::TB::Articles;
use Products;
use BSE::API qw/bse_cfg bse_init bse_make_catalog bse_make_product bse_add_step_child/;
require BSE::Cfg;
my $cfg = BSE::Cfg->new;
# create some articles to test with
-require Articles;
+require BSE::TB::Articles;
require Products;
require BSE::TB::ProductOptions;
require BSE::TB::ProductOptionValues;
sub _generate_dyn_template {
my ($article, $template) = @_;
- my $articles = 'Articles';
+ my $articles = 'BSE::TB::Articles';
my $genname = $article->{generator};
eval "use $genname";
$@ && die $@;
sleep(2); # make sure they get a new displayOrder
BSE::Admin::StepParents->add($parent, $stepprod);
-my $top = Articles->getByPkey(1);
+my $top = BSE::TB::Articles->getByPkey(1);
ok($top, "grabbing Home page");
template_test "children_of", $top, <<TEMPLATE, <<EXPECTED;