more work on the new asset system
This commit is contained in:
parent
fa86e1521a
commit
bb4b4d5c4e
5 changed files with 808 additions and 39 deletions
|
|
@ -49,7 +49,97 @@ $sth->finish;
|
|||
WebGUI::SQL->write("delete from settings where name in ('siteicon','favicon')");
|
||||
|
||||
|
||||
#print "\tConverting Pages, Wobjects, and Forums to Assets\n" unless ($quiet);
|
||||
#walkTree('0','theroot','000001','0');
|
||||
|
||||
WebGUI::Session::close();
|
||||
|
||||
|
||||
sub walkTree {
|
||||
my $oldParentId = shift;
|
||||
my $newParentId = shift;
|
||||
my $parentLineage = shift;
|
||||
my $myRank = shift;
|
||||
WebGUI::SQL->write("alter table wobject add column assetId varchar(22) not null");
|
||||
my $sth = WebGUI::SQL->read("select distinct(namespace) from wobject");
|
||||
while (my ($namespace) = $sth->array) {
|
||||
WebGUI::SQL->write("alter table ".$namespace." add column assetId varchar(22) not null");
|
||||
}
|
||||
$sth->finish;
|
||||
my $a = WebGUI::SQL->read("select * from page where subroutinePackage='WebGUI::Page' and parentId=".quote($oldParentId));
|
||||
while (my $page = $a->hashRef) {
|
||||
my $pageId = WebGUI::Id::generate();
|
||||
my $pageLineage = $parentLineage.sprintf("%06d",$myRank);
|
||||
my $pageUrl = $page->{urlizedTitle};
|
||||
my $className = 'WebGUI::Asset::Layout';
|
||||
if ($page->{redirectURL} ne "") {
|
||||
$className = 'WebGUI::Asset::Redirect';
|
||||
}
|
||||
WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, className, state, title, menuTitle, url, startDate,
|
||||
endDate, synopsis, newWindow, isHidden, ownerUserId, groupIdView, groupIdEdit) values (".quote($pageId).",
|
||||
".quote($newParentId).", ".quote($pageLineage).", ".quote($className).",'published',".quote($page->{title}).",
|
||||
".quote($page->{menuTitle}).", ".quote($pageUrl).", ".quote($page->startDate).", ".quote($page->{endDate}).",
|
||||
".quote($page->{synopsis}).", ".quote($page->{newWindow}).", ".quote($page->{hideFromNavigation}).", ".quote($page->{ownerId}).",
|
||||
".quote($page->{groupIdView}).", ".quote($page->{groupIdEdit}).")");
|
||||
if ($page->{redirectURL} ne "") {
|
||||
WebGUI::SQL->write("insert into redirect (assetId, redirectUrl) values (".quote($pageId).",".quote($page->{redirectURL}).")");
|
||||
} else {
|
||||
WebGUI::SQL->write("insert into layout (assetId, styleTemplateId, layoutTemplateId, printableStyleTemplateId) values (
|
||||
".quote($pageId).", ".quote($page->{styleId}).", ".quote($page->{templateId}).",
|
||||
".quote($page->{printableStyleTemplateId}).")");
|
||||
}
|
||||
my $rank = 0;
|
||||
my $b = WebGUI::SQL->read("select * from wobject where pageId=".quote($page->{pageId}));
|
||||
while (my $wobject = $b->hashRef) {
|
||||
$rank++;
|
||||
my $wobjectId = WebGUI::Id::generate();
|
||||
my $wobjectLineage = $pageLineage.sprintf("%06d",$rank);
|
||||
my $wobjectUrl = $pageUrl."/".$wobject->{title};
|
||||
my $groupIdView = $page->{groupIdView};
|
||||
my $groupIdEdit = $page->{groupIdEdit};
|
||||
my $ownerId = $page->{ownerId};
|
||||
if ($page->{wobjectPrivileges}) {
|
||||
$groupIdView = $wobject->{groupIdView};
|
||||
$groupIdEdit = $wobject->{groupIdEdit};
|
||||
$ownerId = $wobject->{ownerId};
|
||||
}
|
||||
$className = 'WebGUI::Asset::Wobject::'.$wobject->{namespace};
|
||||
WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, className, state, title, menuTitle, url, startDate,
|
||||
endDate, synopsis, isHidden, ownerUserId, groupIdView, groupIdEdit) values (".quote($wobjectId).",
|
||||
".quote($pageId).", ".quote($wobjectLineage).", ".quote($className).",'published',".quote($page->{title}).",
|
||||
".quote($page->{title}).", ".quote($wobjectUrl).", ".quote($wobject->startDate).", ".quote($wobject->{endDate}).",
|
||||
".quote($page->{synopsis}).", 1, ".quote($ownerId).", ".quote($groupIdView).", ".quote($groupIdEdit).")");
|
||||
WebGUI::SQL->write("update wobject set assetId=".quote($wobjectId));
|
||||
my $c = WebGUI::SQL->read("select * from ".$wobject->{namespace}." where wobjectId=".quote($wobject->{wobjectId}));
|
||||
while (my $namespace = $c->hashRef) {
|
||||
}
|
||||
$c->finish;
|
||||
}
|
||||
$b->finish;
|
||||
walkTree($page->{pageId},$pageId,$pageLineage,$rank+1);
|
||||
}
|
||||
$a->finish;
|
||||
my $sth = WebGUI::SQL->read("select distinct(namespace) from wobject");
|
||||
while (my ($namespace) = $sth->array) {
|
||||
if (isIn($namespace, qw(Article DataForm EventsCalendar HttpProxy IndexedSearch MessageBoard Poll Product SQLReport Survey SyndicatedContent USS WobjectProxy WSClient))) {
|
||||
WebGUI::SQL->write("alter table ".$namespace." drop column wobjectId");
|
||||
} else {
|
||||
WebGUI::SQL->write("alter table ".$namespace." drop primary key");
|
||||
}
|
||||
WebGUI::SQL->write("alter table ".$namespace." add primary key (assetId)");
|
||||
}
|
||||
$sth->finish;
|
||||
WebGUI::SQL->write("alter table wobject drop column wobjectId");
|
||||
WebGUI::SQL->write("alter table wobject add primary key (assetId)");
|
||||
WebGUI::SQL->write("alter table wobject drop column namespace");
|
||||
WebGUI::SQL->write("alter table wobject drop column title");
|
||||
WebGUI::SQL->write("alter table wobject drop column ownerId");
|
||||
WebGUI::SQL->write("alter table wobject drop column groupIdEdit");
|
||||
WebGUI::SQL->write("alter table wobject drop column groupIdView");
|
||||
WebGUI::SQL->write("drop table page");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -48,14 +48,18 @@ create table asset (
|
|||
parentId varchar(22) not null,
|
||||
lineage varchar(255) not null,
|
||||
state varchar(35) not null,
|
||||
namespace varchar(255) not null,
|
||||
className varchar(255) not null,
|
||||
boundToId varchar(22),
|
||||
title varchar(255),
|
||||
menuTitle varchar(255),
|
||||
url varchar(255) not null,
|
||||
startDate bigint not null,
|
||||
endDate bigint not null,
|
||||
ownerUserId varchar(22) not null,
|
||||
groupIdView varchar(22) not null,
|
||||
groupIdEdit varchar(22) not null,
|
||||
synopsis text,
|
||||
newWindow int not null default 0,
|
||||
isHidden int not null default 0,
|
||||
isSystem int not null default 0,
|
||||
unique index (lineage asc),
|
||||
|
|
@ -63,5 +67,5 @@ create table asset (
|
|||
index (parentId)
|
||||
);
|
||||
|
||||
insert into asset (assetId, parentId, lineage, state, namespace, title, menuTitle, url, startDate, endDate, isSystem) values ('theroot', 'infinity', '000001','published','Asset','Root','Root','root',997995720,9223372036854775807,1);
|
||||
insert into asset (assetId, parentId, lineage, state, className, title, menuTitle, url, startDate, endDate, isSystem, ownerUserId, groupIdView, groupIdEdit) values ('theroot', 'infinity', '000001','published','WebGUI::Asset','Root','Root','root',997995720,9223372036854775807,1,'3','3','3');
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,19 @@ sub addChild {
|
|||
my $properties = shift;
|
||||
my $id = WebGUI::Id::generate();
|
||||
my $lineage = $self->get("lineage").$self->getNextChildRank;
|
||||
WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, state, namespace, url, startDate, endDate)
|
||||
WebGUI::SQL->beginTransaction;
|
||||
WebGUI::SQL->write("insert into asset (assetId, parentId, lineage, state, className, url, startDate, endDate)
|
||||
values (".quote($id).",".quote($self->getId).", ".quote($lineage).",
|
||||
'published', ".quote($properties->{namespace}).", ".quote($id).",
|
||||
'published', ".quote($properties->{className}).", ".quote($id).",
|
||||
997995720, 9223372036854775807)");
|
||||
my $newAsset = WebGUI::Asset->new($id);
|
||||
foreach my $definition (@{$self->{definition}}) {
|
||||
unless ($definition->{tableName} eq "asset") {
|
||||
WebGUI::SQL->write("insert into ".$definition->{tableName}." (assetId) values (".quote($id).")");
|
||||
}
|
||||
}
|
||||
WebGUI::SQL->commit;
|
||||
my $className = $properties->{className};
|
||||
my $newAsset = $className->new($id);
|
||||
$newAsset->set($properties);
|
||||
return $newAsset;
|
||||
}
|
||||
|
|
@ -29,7 +37,7 @@ sub addChild {
|
|||
sub canEdit {
|
||||
my $self = shift;
|
||||
my $userId = shift || $session{user}{userId};
|
||||
if ($userId eq $self->get("ownerId")) {
|
||||
if ($userId eq $self->get("ownerUserId")) {
|
||||
return 1;
|
||||
}
|
||||
return WebGUI::Grouping::isInGroup($self->get("groupIdEdit"),$userId);
|
||||
|
|
@ -38,7 +46,7 @@ sub canEdit {
|
|||
sub canView {
|
||||
my $self = shift;
|
||||
my $userId = shift || $session{user}{userId};
|
||||
if ($userId eq $self->get("ownerId")) {
|
||||
if ($userId eq $self->get("ownerUserId")) {
|
||||
return 1;
|
||||
} elsif ($self->get("startDate") < time() &&
|
||||
$self->get("endDate") > time() &&
|
||||
|
|
@ -65,6 +73,55 @@ sub cut {
|
|||
$self->{_properties}{state} = "clipboard";
|
||||
}
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
push(@{$definition}, {
|
||||
tableName=>'asset',
|
||||
className=>'WebGUI::Asset',
|
||||
properties=>{
|
||||
title=>{
|
||||
fieldType=>'text',
|
||||
defaultValue=>$definition->[0]->{className}
|
||||
},
|
||||
menuTitle=>{
|
||||
fieldType=>'text',
|
||||
defaultValue=>undef
|
||||
},
|
||||
synopsis=>{
|
||||
fieldType=>'textarea',
|
||||
defaultValue=>undef
|
||||
},
|
||||
url=>{
|
||||
fieldType=>'text',
|
||||
defaultValue=>undef,
|
||||
filter=>'fixUrl',
|
||||
},
|
||||
groupIdEdit=>{
|
||||
fieldType=>'group',
|
||||
defaultValue=>'4'
|
||||
},
|
||||
groupIdView=>{
|
||||
fieldType=>'group',
|
||||
defaultValue=>'7'
|
||||
},
|
||||
ownerUserId=>{
|
||||
fieldType=>'selectList',
|
||||
defaultValue=>'3'
|
||||
},
|
||||
startDate=>{
|
||||
fieldType=>'dateTime',
|
||||
defaultValue=>undef
|
||||
},
|
||||
endDate=>{
|
||||
fieldType=>'dateTime',
|
||||
defaultValue=>undef
|
||||
},
|
||||
}
|
||||
});
|
||||
return $definition;
|
||||
}
|
||||
|
||||
sub delete {
|
||||
my $self = shift;
|
||||
WebGUI::SQL->beginTransaction;
|
||||
|
|
@ -124,10 +181,23 @@ sub get {
|
|||
return $self->{_properties};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getAdminConsole ()
|
||||
|
||||
Returns a reference to a WebGUI::AdminConsole object.
|
||||
|
||||
=cut
|
||||
|
||||
sub getAdminConsole {
|
||||
my $self = shift;
|
||||
my $ac = WebGUI::AdminConsole->set("assets");
|
||||
return $ac;
|
||||
unless (exists $self->{_adminConsole}) {
|
||||
$self->{_adminConsole} = WebGUI::AdminConsole->new("assets");
|
||||
}
|
||||
return $self->{_adminConsole};
|
||||
}
|
||||
|
||||
sub getEditForm {
|
||||
|
|
@ -214,14 +284,14 @@ sub getEditForm {
|
|||
push (@$contentManagers, $session{user}{userId});
|
||||
$clause = "userId in (".quoteAndJoin($contentManagers).")";
|
||||
} else {
|
||||
$clause = "userId=".quote($self->get("ownerId"));
|
||||
$clause = "userId=".quote($self->get("ownerUserId"));
|
||||
}
|
||||
my $users = WebGUI::SQL->buildHashRef("select userId,username from users where $clause order by username");
|
||||
$tabform->getTab("privileges")->select(
|
||||
-name=>"ownerId",
|
||||
-name=>"ownerUserId",
|
||||
-options=>$users,
|
||||
-label=>WebGUI::International::get(108),
|
||||
-value=>[$self->get("ownerId")],
|
||||
-value=>[$self->get("ownerUserId")],
|
||||
-subtext=>$subtext,
|
||||
-uiLevel=>6
|
||||
);
|
||||
|
|
@ -307,16 +377,14 @@ sub getLineage {
|
|||
my $lineageLength = length($lineage);
|
||||
$whereDescendants .= "lineage like ".quote($lineage.'%')." and length(lineage)> ".$lineageLength;
|
||||
}
|
||||
my $select = "*";
|
||||
$select = "assetId" if ($rules->{returnIds});
|
||||
my $sql = "select $select from asset where $whereSiblings $whereExact $whereDescendants order by lineage";
|
||||
my $sql = "select assetId from asset where $whereSiblings $whereExact $whereDescendants order by lineage";
|
||||
my @lineage;
|
||||
my $sth = WebGUI::SQL->read($sql);
|
||||
while (my $asset = $sth->hashRef) {
|
||||
if ($rules->{returnIds}) {
|
||||
push(@lineage,$asset->{assetId});
|
||||
while (my ($assetId) = $sth->array) {
|
||||
if ($rules->{returnOjbects}) {
|
||||
push(@lineage,WebGUI::Asset->new($assetId);
|
||||
} else {
|
||||
push(@lineage,WebGUI::Asset->new($asset->{assetId},$asset));
|
||||
push(@lineage,$assetId);
|
||||
}
|
||||
}
|
||||
$sth->finish;
|
||||
|
|
@ -352,7 +420,14 @@ sub getValue {
|
|||
my $self = shift;
|
||||
my $key = shift;
|
||||
if (defined $key) {
|
||||
return $session{form}{$key} || $self->get($key);
|
||||
unless (exists $self->{_propertyDefinitions}) { # check to see if the defintions have been merged and cached
|
||||
my %properties;
|
||||
foreach my $definition (@{$self->definition}) {
|
||||
%properties = (%properties, %{$definition->{properties}});
|
||||
}
|
||||
$self->{_propertyDefinitions} = \%properties;
|
||||
}
|
||||
return $session{form}{$key} || $self->get($key) || $self->{_propertiyDefinitions}{$key}{defaultValue};
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
|
@ -360,17 +435,33 @@ sub getValue {
|
|||
sub new {
|
||||
my $class = shift;
|
||||
my $assetId = shift;
|
||||
my $properties = shift;
|
||||
my $overrideProperties = shift;
|
||||
my $properties;
|
||||
if ($assetId eq "new") {
|
||||
$properties = $overrideProperties;
|
||||
$properties->{assetId} = "new";
|
||||
$properties->{className} = $class;
|
||||
} else {
|
||||
my $definitions = $class->definition;
|
||||
my @definitionsReversed = reverse(@{$definitions});
|
||||
shift(@definitionsReversed);
|
||||
my $sql = "select * from asset";
|
||||
foreach my $definition (@definitionsReversed) {
|
||||
$sql .= " left join ".$definition->{tableName}." on asset.assetId=".$definition->{tableName}.".assetId";
|
||||
}
|
||||
$sql .= " where asset.assetId=".quote($assetId);
|
||||
$properties = WebGUI::SQL->quickHashRef($sql);
|
||||
return undef unless (exists $properties->{assetId});
|
||||
foreach my $property (keys %{$overrideProperties}) {
|
||||
unless (isIn($property, qw(assetId className parentId lineage state))) {
|
||||
$properties->{$property} = $overrideProperties->{$property};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (defined $properties) {
|
||||
return bless { _properties=>$properties }, $class;
|
||||
} else {
|
||||
$properties = WebGUI::SQL->quickHashRef("select * from asset where assetId=".quote($assetId));
|
||||
if (exists $properties->{assetId}) {
|
||||
return bless { _properties=>$properties}, $class;
|
||||
} else {
|
||||
return undef;
|
||||
}
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub paste {
|
||||
|
|
@ -396,21 +487,38 @@ sub promote {
|
|||
return 0;
|
||||
}
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
# NOTE to self, still need to delete all children too
|
||||
WebGUI::SQL->beginTransaction;
|
||||
foreach my $definition (@{$self->definition}) {
|
||||
WebGUI::SQL->write("delete from ".$definition->{tableName}." where assetId=".quote($self->getId));
|
||||
}
|
||||
WebGUI::SQL->commit;
|
||||
$self = undef;
|
||||
}
|
||||
|
||||
sub set {
|
||||
my $self = shift;
|
||||
my $properties = shift;
|
||||
my %props = %{$properties}; # make a copy so we don't disturb the original as we make changes
|
||||
my @setPairs;
|
||||
foreach my $property (keys %props) {
|
||||
if (isIn($property, qw(groupIdEdit groupIdView ownerId startDate endDate url title menuTitle synopsis))) {
|
||||
if ($property eq "url") {
|
||||
$props{url} = $self->fixUrl($props{url});
|
||||
WebGUI::SQL->beginTransaction;
|
||||
foreach my $definition (@{$self->definition}) {
|
||||
my @setPairs;
|
||||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
my $value = $properties->{$property} || $definition->{properties}{$property}{defaultValue};
|
||||
if (defined $value) {
|
||||
if (exists $definition->{properties}{$property}{filter}) {
|
||||
$value = $self->$definition->{properties}{$property}{filter}($value);
|
||||
}
|
||||
$self->{_properties}{$property} = $value;
|
||||
push(@setPairs, $property."=".quote($value));
|
||||
}
|
||||
$self->{_properties}{$property} = $props{$property};
|
||||
push(@setPairs ,$property."=".quote($props{$property}));
|
||||
}
|
||||
if (scalar(@setPairs) > 0) {
|
||||
WebGUI::SQL->write("update ".$definition->{tableName}." set ".join(",",@setPairs)." where assetId=".quote($self->getId));
|
||||
}
|
||||
}
|
||||
WebGUI::SQL->write("update asset set ".join(",",@setPairs)." where assetId=".quote($self->getId));
|
||||
WebGUI::SQL->commit;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -439,7 +547,7 @@ sub setRank {
|
|||
my $currentRank = $self->getRank;
|
||||
return 1 if ($newRank == $currentRank); # do nothing if we're moving to ourself
|
||||
my $parentLineage = $self->getParentLineage;
|
||||
my $siblings = $self->getLineage(["siblings"]);
|
||||
my $siblings = $self->getLineage(["siblings"],{returnObjects=>1});
|
||||
my $temp = substr(WebGUI::Id::generate(),0,6);
|
||||
if ($newRank < $currentRank) { # have to do the ordering in reverse when the new rank is above the old rank
|
||||
@{$siblings} = reverse @{$siblings};
|
||||
|
|
@ -478,42 +586,64 @@ sub www_copy {
|
|||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
my $newAsset = $self->duplicate;
|
||||
$newAsset->cut;
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_cut {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->cut;
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_delete {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->delete;
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_demote {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->demote;
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
return "No editor has been defined for this asset.";
|
||||
return $self->getAdminConsole->render($self->getEditForm);
|
||||
}
|
||||
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
my %data;
|
||||
foreach my $definition (@{$self->definition}) {
|
||||
foreach my $property (keys %{$definition->{properties}}) {
|
||||
my $data{$property} = WebGUI::FormProcessor::process(
|
||||
$property,
|
||||
$definition->{properties}{fieldType},
|
||||
$definition->{properties}{defaultValue}
|
||||
);
|
||||
}
|
||||
}
|
||||
$self->set(\%data);
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_paste {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->paste($session{form}{newParentId});
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_promote {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->promote;
|
||||
return "";
|
||||
}
|
||||
|
||||
sub www_view {
|
||||
|
|
|
|||
350
lib/WebGUI/Asset/Wobject.pm
Normal file
350
lib/WebGUI/Asset/Wobject.pm
Normal file
|
|
@ -0,0 +1,350 @@
|
|||
package WebGUI::Asset::Wobject;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
||||
-------------------------------------------------------------------
|
||||
Please read the legal notices (docs/legal.txt) and the license
|
||||
(docs/license.txt) that came with this distribution before using
|
||||
this software.
|
||||
-------------------------------------------------------------------
|
||||
http://www.plainblack.com info@plainblack.com
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=cut
|
||||
|
||||
use CGI::Util qw(rearrange);
|
||||
use DBI;
|
||||
use strict qw(subs vars);
|
||||
use Tie::IxHash;
|
||||
use WebGUI::AdminConsole;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::FormProcessor;
|
||||
use WebGUI::Grouping;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::Id;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Node;
|
||||
use WebGUI::Page;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::SQL;
|
||||
use WebGUI::TabForm;
|
||||
use WebGUI::Template;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Utility;
|
||||
use WebGUI::MetaData;
|
||||
use WebGUI::Wobject::WobjectProxy;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::Wobject
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
An abstract class for all other wobjects to extend.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
use WebGUI::Wobject;
|
||||
our @ISA = qw(WebGUI::Wobject);
|
||||
|
||||
See the subclasses in lib/WebGUI/Wobjects for details.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
push(@{$definition}, {
|
||||
tableName=>'wobject',
|
||||
className=>'WebGUI::Asset::Wobject',
|
||||
properties=>{
|
||||
description=>{
|
||||
fieldType=>'HTMLArea',
|
||||
defaultValue=>undef
|
||||
},
|
||||
displayTitle=>{
|
||||
fieldType=>'yesNo',
|
||||
defaultValue=>1
|
||||
},
|
||||
cacheTimeout=>{
|
||||
fieldType=>'interval',
|
||||
defaultValue=>60
|
||||
},
|
||||
cacheTimeoutVisitor=>{
|
||||
fieldType=>'interval',
|
||||
defaultValue=>600
|
||||
}
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 confirm ( message, yesURL, [ , noURL, vitalComparison ] )
|
||||
|
||||
=head3 message
|
||||
|
||||
A string containing the message to prompt the user for this action.
|
||||
|
||||
=head3 yesURL
|
||||
|
||||
A URL to the web method to execute if the user confirms the action.
|
||||
|
||||
=head3 noURL
|
||||
|
||||
A URL to the web method to execute if the user denies the action. Defaults back to the current page.
|
||||
|
||||
=head3 vitalComparison
|
||||
|
||||
A comparison expression to be used when checking whether the action should be allowed to continue. Typically this is used when the action is a delete of some sort.
|
||||
|
||||
=cut
|
||||
|
||||
sub confirm {
|
||||
return WebGUI::Privilege::vitalComponent() if ($_[4]);
|
||||
my $noURL = $_[3] || WebGUI::URL::page();
|
||||
my $output = '<h1>'.WebGUI::International::get(42).'</h1>';
|
||||
$output .= $_[1].'<p>';
|
||||
$output .= '<div align="center"><a href="'.$_[2].'">'.WebGUI::International::get(44).'</a>';
|
||||
$output .= ' <a href="'.$noURL.'">'.WebGUI::International::get(45).'</a></div>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 duplicate ( [ pageId ] )
|
||||
|
||||
Duplicates this wobject with a new wobject Id. Returns the new wobject Id.
|
||||
|
||||
B<NOTE:> This method is meant to be extended by all sub-classes.
|
||||
|
||||
=head3 pageId
|
||||
|
||||
If specified the wobject will be duplicated to this pageId, otherwise it will be duplicated to the clipboard.
|
||||
|
||||
=cut
|
||||
|
||||
sub duplicate {
|
||||
my $self = shift;
|
||||
my $newAsset = $self->SUPER::duplicate();
|
||||
WebGUI::MetaData::MetaDataDuplicate($self->getId, $newAsset->getId);
|
||||
return $newAsset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getEditForm ()
|
||||
|
||||
Returns the TabForm object that will be used in generating the edit page for this wobject.
|
||||
|
||||
=cut
|
||||
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
$tabform->addTab("layout",WebGUI::International::get(105),5);
|
||||
$tabform->getTab("layout")->yesNo(
|
||||
-name=>"displayTitle",
|
||||
-label=>WebGUI::International::get(174),
|
||||
-value=>$self->getValue("displayTitle"),
|
||||
-uiLevel=>5
|
||||
);
|
||||
$tabform->getTab("layout")->template(
|
||||
-value=>$self->getValue("templateId"),
|
||||
-namespace=>$self->get("namespace"),
|
||||
-afterEdit=>'func=edit&wid='.$self->get("wobjectId")."&namespace=".$self->get("namespace")
|
||||
);
|
||||
$tabform->getTab("properties")->HTMLArea(
|
||||
-name=>"description",
|
||||
-label=>WebGUI::International::get(85),
|
||||
-value=>$self->getValue("description")
|
||||
);
|
||||
$tabform->getTab("properties")->interval(
|
||||
-name=>"cacheTimeout",
|
||||
-label=>WebGUI::International::get(895),
|
||||
-value=>$self->getValue("cacheTimeout"),
|
||||
-uiLevel=>8
|
||||
);
|
||||
$tabform->getTab("properties")->interval(
|
||||
-name=>"cacheTimeoutVisitor",
|
||||
-label=>WebGUI::International::get(896),
|
||||
-value=>$self->getValue("cacheTimeoutVisitor"),
|
||||
-uiLevel=>8
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 logView ( )
|
||||
|
||||
Logs the view of the wobject to the passive profiling mechanism.
|
||||
=cut
|
||||
|
||||
sub logView {
|
||||
my $self = shift;
|
||||
WebGUI::PassiveProfiling::add($self->get("assetId"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 name ( )
|
||||
|
||||
This method should be overridden by all wobjects and should return an internationalized human friendly name for the wobject. This method only exists in the super class for reverse compatibility and will try to look up the name based on the old name definition.
|
||||
|
||||
=cut
|
||||
|
||||
sub name {
|
||||
my $self = shift;
|
||||
return $self->get("className");
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 processMacros ( output )
|
||||
|
||||
Decides whether or not macros should be processed and returns the
|
||||
appropriate output.
|
||||
|
||||
=head3 output
|
||||
|
||||
An HTML blob to be processed for macros.
|
||||
|
||||
=cut
|
||||
|
||||
sub processMacros {
|
||||
return WebGUI::Macro::process($_[1]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 processTemplate ( templateId, vars [ , namespace ] )
|
||||
|
||||
Returns the content generated from this template.
|
||||
|
||||
B<NOTE:> Only for use in wobjects that support templates.
|
||||
|
||||
=head3 templateId
|
||||
|
||||
An id referring to a particular template in the templates table.
|
||||
|
||||
=head3 hashRef
|
||||
|
||||
A hash reference containing variables and loops to pass to the template engine.
|
||||
|
||||
=head3 namespace
|
||||
|
||||
A namespace to use for the template. Defaults to the wobject's namespace.
|
||||
|
||||
=cut
|
||||
|
||||
sub processTemplate {
|
||||
my $self = shift;
|
||||
my $templateId = shift;
|
||||
my $var = shift;
|
||||
my $namespace = shift || $self->get("namespace");
|
||||
if ($self->{_useMetaData}) {
|
||||
my $meta = WebGUI::MetaData::getMetaDataFields($self->get("wobjectId"));
|
||||
foreach my $field (keys %$meta) {
|
||||
$var->{$meta->{$field}{fieldName}} = $meta->{$field}{value};
|
||||
}
|
||||
}
|
||||
my %vars = (
|
||||
%{$self->{_property}},
|
||||
%{$var}
|
||||
);
|
||||
if (defined $self->get("_WobjectProxy")) {
|
||||
$vars{isShortcut} = 1;
|
||||
my ($originalPageURL) = WebGUI::SQL->quickArray("select urlizedTitle from page where pageId=".quote($self->get("pageId")),WebGUI::SQL->getSlave);
|
||||
$vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$self->get("wobjectId"));
|
||||
}
|
||||
return WebGUI::Template::process($templateId,$namespace, \%vars);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 purge ( )
|
||||
|
||||
Removes this wobject and it's descendants from the database.
|
||||
|
||||
=cut
|
||||
|
||||
sub purge {
|
||||
my $self = shift;
|
||||
$self->SUPER::purge();
|
||||
WebGUI::MetaData::metaDataDelete($self->get("wobjectId"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_createShortcut ( )
|
||||
|
||||
Creates a shortcut (using the wobject proxy) of this wobject on the clipboard.
|
||||
|
||||
B<NOTE:> Should never need to be overridden or extended.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_createShortcut {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless ($self->canEdit);
|
||||
my $w = WebGUI::Wobject::WobjectProxy->new({wobjectId=>"new",namespace=>"WobjectProxy"});
|
||||
$w->set({
|
||||
pageId=>'2',
|
||||
templatePosition=>1,
|
||||
title=>$self->getValue("title"),
|
||||
proxiedNamespace=>$self->get("namespace"),
|
||||
proxiedWobjectId=>$self->get("wobjectId"),
|
||||
bufferUserId=>$session{user}{userId},
|
||||
bufferDate=>WebGUI::DateTime::time(),
|
||||
bufferPrevId=>$session{page}{pageId}
|
||||
});
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_editSave ( )
|
||||
|
||||
Saves the default properties of any/all wobjects.
|
||||
|
||||
B<NOTE:> This method should only need to be extended if you need to do some special validation that you can't achieve via filters.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_editSave {
|
||||
my $self = shift;
|
||||
$self->SUPER::www_editSave();
|
||||
WebGUI::MetaData::metaDataSave($self->getId);
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
||||
195
lib/WebGUI/Asset/Wobject/Article.pm
Normal file
195
lib/WebGUI/Asset/Wobject/Article.pm
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
package WebGUI::Asset::Wobject::Article;
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2004 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use Tie::CPHash;
|
||||
use WebGUI::DateTime;
|
||||
use WebGUI::Forum;
|
||||
use WebGUI::Forum::UI;
|
||||
use WebGUI::HTML;
|
||||
use WebGUI::HTMLForm;
|
||||
use WebGUI::Icon;
|
||||
use WebGUI::International;
|
||||
use WebGUI::Paginator;
|
||||
use WebGUI::Privilege;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::URL;
|
||||
use WebGUI::Wobject;
|
||||
|
||||
our @ISA = qw(WebGUI::Asset::Wobject);
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub definition {
|
||||
my $class = shift;
|
||||
my $definition = shift;
|
||||
push(@{$definition}, {
|
||||
tableName=>'Article',
|
||||
className=>'WebGUI::Asset::Wobject::Article',
|
||||
properties=>{
|
||||
linkURL=>{
|
||||
fieldType=>'url',
|
||||
defaultValue=>undef
|
||||
},
|
||||
linkTitle=>{
|
||||
fieldType=>'text',
|
||||
defaultValue=>undef
|
||||
},
|
||||
convertCarriageReturns=>{
|
||||
fieldType=>'yesNo',
|
||||
defaultValue=>0
|
||||
}
|
||||
}
|
||||
});
|
||||
return $class->SUPER::definition($definition);
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub name {
|
||||
return WebGUI::International::get(1,"Article");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub getEditForm {
|
||||
my $self = shift;
|
||||
my $tabform = $self->SUPER::getEditForm();
|
||||
$tabform->getTab("properties")->text(
|
||||
-name=>"linkTitle",
|
||||
-label=>WebGUI::International::get(7,$self->get("namespace")),
|
||||
-value=>$self->getValue("linkTitle"),
|
||||
-uiLevel=>3
|
||||
);
|
||||
$tabform->getTab("properties")->url(
|
||||
-name=>"linkURL",
|
||||
-label=>WebGUI::International::get(8,$self->get("namespace")),
|
||||
-value=>$self->getValue("linkURL"),
|
||||
-uiLevel=>3
|
||||
);
|
||||
$tabform->getTab("layout")->yesNo(
|
||||
-name=>"convertCarriageReturns",
|
||||
-label=>WebGUI::International::get(10,$_[0]->get("namespace")),
|
||||
-value=>$_[0]->getValue("convertCarriageReturns"),
|
||||
-subtext=>' <span style="font-size: 8pt;">'.WebGUI::International::get(11,$_[0]->get("namespace")).'</span>',
|
||||
-uiLevel=>5,
|
||||
-defaultValue=>0
|
||||
);
|
||||
return $tabform;
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_edit {
|
||||
my $self = shift;
|
||||
return WebGUI::Privilege::insufficient() unless $self->canEdit;
|
||||
$self->getAdminConsole->setHelp("article add/edit");
|
||||
return $self->getAdminConsole->render($self->getEditForm,WebGUI::International::get("12","Article"));
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_editSave {
|
||||
my ($image, $attachment, %property);
|
||||
$_[0]->SUPER::www_editSave() if ($_[0]->get("wobjectId") eq "new");
|
||||
$image = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
|
||||
$image->save("image");
|
||||
$attachment = WebGUI::Attachment->new("",$_[0]->get("wobjectId"));
|
||||
$attachment->save("attachment");
|
||||
$property{image} = $image->getFilename if ($image->getFilename ne "");
|
||||
$property{attachment} = $attachment->getFilename if ($attachment->getFilename ne "");
|
||||
return $_[0]->SUPER::www_editSave(\%property);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
sub www_view {
|
||||
my $self = shift;
|
||||
$self->logView() if ($session{setting}{passiveProfilingEnabled});
|
||||
my ($file, %var);
|
||||
if ($self->get("image") ne "") {
|
||||
$file = WebGUI::Attachment->new($self->get("image"),$self->get("wobjectId"));
|
||||
$var{"image.url"} = $file->getURL;
|
||||
$var{"image.thumbnail"} = $file->getThumbnail;
|
||||
}
|
||||
$var{description} = $self->get("description");
|
||||
if ($self->get("convertCarriageReturns")) {
|
||||
$var{description} =~ s/\n/\<br\>\n/g;
|
||||
}
|
||||
$var{"new.template"} = WebGUI::URL::page("wid=".$self->get("wobjectId")."&func=view")."&overrideTemplateId=";
|
||||
$var{"description.full"} = $var{description};
|
||||
$var{"description.full"} =~ s/\^\-\;//g;
|
||||
$var{"description.first.100words"} = $var{"description.full"};
|
||||
$var{"description.first.100words"} =~ s/(((\S+)\s+){100}).*/$1/s;
|
||||
$var{"description.first.75words"} = $var{"description.first.100words"};
|
||||
$var{"description.first.75words"} =~ s/(((\S+)\s+){75}).*/$1/s;
|
||||
$var{"description.first.50words"} = $var{"description.first.75words"};
|
||||
$var{"description.first.50words"} =~ s/(((\S+)\s+){50}).*/$1/s;
|
||||
$var{"description.first.25words"} = $var{"description.first.50words"};
|
||||
$var{"description.first.25words"} =~ s/(((\S+)\s+){25}).*/$1/s;
|
||||
$var{"description.first.10words"} = $var{"description.first.25words"};
|
||||
$var{"description.first.10words"} =~ s/(((\S+)\s+){10}).*/$1/s;
|
||||
$var{"description.first.2paragraphs"} = $var{"description.full"};
|
||||
$var{"description.first.2paragraphs"} =~ s/^((.*?\n){2}).*/$1/s;
|
||||
$var{"description.first.paragraph"} = $var{"description.first.2paragraphs"};
|
||||
$var{"description.first.paragraph"} =~ s/^(.*?\n).*/$1/s;
|
||||
$var{"description.first.4sentences"} = $var{"description.full"};
|
||||
$var{"description.first.4sentences"} =~ s/^((.*?\.){4}).*/$1/s;
|
||||
$var{"description.first.3sentences"} = $var{"description.first.4sentences"};
|
||||
$var{"description.first.3sentences"} =~ s/^((.*?\.){3}).*/$1/s;
|
||||
$var{"description.first.2sentences"} = $var{"description.first.3sentences"};
|
||||
$var{"description.first.2sentences"} =~ s/^((.*?\.){2}).*/$1/s;
|
||||
$var{"description.first.sentence"} = $var{"description.first.2sentences"};
|
||||
$var{"description.first.sentence"} =~ s/^(.*?\.).*/$1/s;
|
||||
my $p = WebGUI::Paginator->new(WebGUI::URL::page("wid=".$self->get("wobjectId")."&func=view"),1);
|
||||
if ($session{form}{makePrintable} || $var{description} eq "") {
|
||||
$var{description} =~ s/\^\-\;//g;
|
||||
$p->setDataByArrayRef([$var{description}]);
|
||||
} else {
|
||||
my @pages = split(/\^\-\;/,$var{description});
|
||||
$p->setDataByArrayRef(\@pages);
|
||||
$var{description} = $p->getPage;
|
||||
}
|
||||
$p->appendTemplateVars(\%var);
|
||||
if ($self->get("attachment") ne "") {
|
||||
$file = WebGUI::Attachment->new($self->get("attachment"),$self->get("wobjectId"));
|
||||
$var{"attachment.box"} = $file->box;
|
||||
$var{"attachment.icon"} = $file->getIcon;
|
||||
$var{"attachment.url"} = $file->getURL;
|
||||
$var{"attachment.name"} = $file->getFilename;
|
||||
}
|
||||
my $callback = WebGUI::URL::page("func=view&wid=".$self->get("wobjectId"));
|
||||
if ($self->get("allowDiscussion")) {
|
||||
my $forum = WebGUI::Forum->new($self->get("forumId"));
|
||||
$var{"replies.count"} = ($forum->get("replies") + $forum->get("threads"));
|
||||
$var{"replies.URL"} = WebGUI::Forum::UI::formatForumURL($callback,$forum->get("forumId"));
|
||||
$var{"replies.label"} = WebGUI::International::get(28,$self->get("namespace"));
|
||||
$var{"post.URL"} = WebGUI::Forum::UI::formatNewThreadURL($callback,$forum->get("forumId"));
|
||||
$var{"post.label"} = WebGUI::International::get(24,$self->get("namespace"));
|
||||
}
|
||||
my $templateId = $self->get("templateId");
|
||||
if ($session{form}{overrideTemplateId} ne "") {
|
||||
$templateId = $session{form}{overrideTemplateId};
|
||||
}
|
||||
if ($session{form}{forumOp}) {
|
||||
return WebGUI::Forum::UI::forumOp({
|
||||
callback=>$callback,
|
||||
title=>$self->get("title"),
|
||||
description=>$self->get("description"),
|
||||
forumId=>$self->get("forumId")
|
||||
});
|
||||
} else {
|
||||
return $self->processTemplate($templateId,\%var);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue