moved metadata system into asset superclass, and added a fileImport script

This commit is contained in:
JT Smith 2005-01-08 16:53:29 +00:00
parent 1914386984
commit 2110af418a
16 changed files with 623 additions and 1056 deletions

View file

@ -76,6 +76,7 @@ WebGUI::SQL->write("alter table wobject add styleTemplateId varchar(22) not null
WebGUI::SQL->write("alter table wobject add printableStyleTemplateId varchar(22) not null");
WebGUI::SQL->write("alter table wobject add cacheTimeout int not null default 60");
WebGUI::SQL->write("alter table wobject add cacheTimeoutVisitor int not null default 3600");
WebGUI::SQL->write("alter table metaData_values add assetId varchar(22) not null");
WebGUI::SQL->write("alter table wobject drop primary key");
WebGUI::SQL->write("alter table Poll_answer add column assetId varchar(22)");
WebGUI::SQL->write("alter table DataForm_entry add column assetId varchar(22)");
@ -139,6 +140,7 @@ WebGUI::SQL->write("alter table wobject drop column dateAdded");
WebGUI::SQL->write("alter table wobject drop column editedBy");
WebGUI::SQL->write("alter table wobject drop column lastEdited");
WebGUI::SQL->write("alter table wobject drop column allowDiscussion");
WebGUI::SQL->write("alter table metaData_values drop column wobjectId");
WebGUI::SQL->write("drop table page");
WebGUI::SQL->write("drop table FileManager");
WebGUI::SQL->write("drop table FileManager_file");
@ -581,6 +583,13 @@ $sth->finish;
print "\tDeleting files which are no longer used.\n" unless ($quiet);
#unlink("../../lib/WebGUI/MetaData.pm");
#unlink("../../lib/WebGUI/Operation/MetaData.pm");
#unlink("../../lib/WebGUI/i18n/English/MetaData.pm");
#unlink("../../lib/WebGUI/Help/MetaData.pm");
#unlink("../../sbin/fileManagerImport.pl");
#unlink("../../sbin/collateralImport.pl");
#unlink("../../lib/WebGUI/Page.pm");
#unlink("../../lib/WebGUI/Page.pm");
#unlink("../../lib/WebGUI/Operation/Page.pm");
#unlink("../../lib/WebGUI/Operation/Package.pm");
@ -819,6 +828,7 @@ sub walkTree {
.", cacheTimeoutVisitor=".quote($page->{cacheTimeoutVisitor})." where wobjectId=".quote($wobject->{wobjectId}));
WebGUI::SQL->write("update ".$wobject->{namespace}." set assetId=".quote($wobjectId)." where wobjectId="
.quote($wobject->{wobjectId}));
WebGUI::SQL->write("update metaData_values set assetId=".quote($wobjectId)." where wobjectId=".quote($wobject->{wobjectId}));
if ($wobject->{namespace} eq "Article") {
print "\t\t\tMigrating attachments for Article ".$wobject->{wobjectId}."\n" unless ($quiet);
if ($namespace->{attachment}) {

View file

@ -239,10 +239,10 @@ sub getAdminFunction {
"contentProfiling"=>{
title=>{
id=>"content profiling",
namespace=>"MetaData"
namespace=>"Asset"
},
icon=>"contentProfiling.gif",
op=>"manageMetaData",
func=>"manageMetaData",
group=>"4"
},
"contentFilters"=>{

View file

@ -16,6 +16,7 @@ package WebGUI::Asset;
use strict;
use Tie::IxHash;
use WebGUI::Asset::Template;
use WebGUI::AdminConsole;
use WebGUI::DateTime;
use WebGUI::ErrorHandler;
@ -29,6 +30,7 @@ use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::TabForm;
use WebGUI::URL;
use WebGUI::Utility;
=head1 NAME
@ -333,6 +335,28 @@ sub definition {
return \@newDef;
}
#-------------------------------------------------------------------
=head2 deleteMetaDataField ( fieldId )
Deletes a field from the metadata system.
=head3 fieldId
The fieldId to be deleted.
=cut
sub deleteMetaDataField {
my $fieldId = shift;
return unless ($fieldId =~ /^\d+$/ || length($fieldId) == 22);
WebGUI::SQL->beginTransaction;
WebGUI::SQL->write("delete from metaData_properties where fieldId = ".quote($fieldId));
WebGUI::SQL->write("delete from metaData_values where fieldId = ".quote($fieldId));
WebGUI::SQL->commit;
}
#-------------------------------------------------------------------
=head2 demote ( )
@ -388,6 +412,12 @@ sub duplicate {
my $self = shift;
my $assetToDuplicate = shift || $self;
my $newAsset = $self->addChild($assetToDuplicate->get);
my $sth = WebGUI::SQL->read("select * from metaData_values where assetId = ".quote($self->getId));
while( my $h = $sth->hashRef) {
WebGUI::SQL->write("insert into metaData_values (fieldId, assetId, value) values (".
quote($h->{fieldId}).",".quote($newAsset->getId).",".quote($h->{value}).")");
}
$sth->finish;
return $newAsset;
}
@ -1044,6 +1074,44 @@ sub getLineageLength {
#-------------------------------------------------------------------
=head2 getMetaDataFields ( [fieldId] )
Returns a hash reference containing all metadata field properties. You can limit the output to a certain field by specifying a fieldId.
=head3 fieldId
If specified, the hashRef will contain only this field.
=cut
sub getMetaDataFields {
my $self = shift;
my $fieldId = shift;
tie my %hash, 'Tie::IxHash';
my $sql = "select
f.fieldId,
f.fieldName,
f.description,
f.defaultValue,
f.fieldType,
f.possibleValues,
d.value
from metaData_properties f
left join metaData_values d on f.fieldId=d.fieldId and d.assetId=".quote($self->getId);
$sql .= " where f.fieldId = ".quote($fieldId) if ($fieldId);
$sql .= " order by f.fieldName";
my $sth = WebGUI::SQL->read($sql);
while( my $h = $sth->hashRef) {
foreach(keys %$h) {
$hash{$h->{fieldId}}{$_} = $h->{$_};
}
}
$sth->finish;
return \%hash;
}
#-------------------------------------------------------------------
=head2 getName ( )
Returns the internationalization of the word "Asset".
@ -1500,6 +1568,65 @@ sub processPropertiesFromFormPost {
$data{menuTitle} = $data{title} unless ($data{menuTitle});
$data{url} = $self->getParent->get("url").'/'.$data{menuTitle} unless ($data{url});
$self->update(\%data);
foreach my $form (keys %{$session{form}}) {
if ($form =~ /^metadata_(\d+)$/) {
my $fieldId = $1;
my ($exists) = WebGUI::SQL->quickArray("select count(*) from metaData_values
where assetId = ".quote($self->getId)."
and fieldId = ".quote($fieldId));
if(! $exists && $session{form}{$form} ne "") {
WebGUI::SQL->write("insert into metaData_values (fieldId, assetId)
values (".quote($fieldId).",".quote($self->getId).")");
}
if($session{form}{$form} eq "") {
# Keep it clean
WebGUI::SQL->write("delete from metaData_values where assetId = ".
quote($self->getId)." and fieldId = ".quote($fieldId));
} else {
WebGUI::SQL->write("update metaData_values set value = ".quote($session{form}{$form})."
where assetId = ".quote($self->getId)." and fieldId = ".
quote($fieldId));
}
}
}
}
#-------------------------------------------------------------------
=head2 processTemplate ( vars, templateId )
Returns the content generated from this template.
=head3 hashRef
A hash reference containing variables and loops to pass to the template engine.
=head3 templateId
An id referring to a particular template in the templates table.
=cut
sub processTemplate {
my $self = shift;
my $var = shift;
my $templateId = shift;
my $meta = $self->getMetaDataFields();
foreach my $field (keys %$meta) {
$var->{$meta->{$field}{fieldName}} = $meta->{$field}{value};
}
$var->{'controls'} = $self->getToolbar;
my %vars = (
%{$self->{_properties}},
%{$var}
);
if (defined $self->get("_WobjectProxy")) {
$vars{isShortcut} = 1;
my ($originalPageURL) = WebGUI::SQL->quickArray("select url from asset where assetId=".quote($self->getId),WebGUI::SQL->getSlave);
$vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$self->getId);
}
return WebGUI::Asset::Template->new($templateId)->process(\%vars);
}
#-------------------------------------------------------------------
@ -1538,6 +1665,7 @@ sub purge {
foreach my $definition (@{$self->definition}) {
WebGUI::SQL->write("delete from ".$definition->{tableName}." where assetId=".quote($self->getId));
}
WebGUI::SQL->write("delete from metaData_values where assetId = ".quote($self->getId));
WebGUI::SQL->commit;
# eliminate anything bound to this asset
my $sth = WebGUI::SQL->read("select assetId,className from asset where boundToId=".quote($self->getId));
@ -1920,6 +2048,15 @@ sub www_deleteList {
return $self->www_manageAssets();
}
#-------------------------------------------------------------------
sub www_deleteMetaDataField {
my $self = shift;
my $ac = WebGUI::AdminConsole->new("content profiling");
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
$self->deleteMetaDataField($session{form}{fid});
return $self->www_manageMetaData;
}
#-------------------------------------------------------------------
=head2 www_demote ( )
@ -1999,6 +2136,81 @@ sub www_editSave {
return $object->www_view;
}
#-------------------------------------------------------------------
sub www_editMetaDataField {
my $self = shift;
my $ac = WebGUI::AdminConsole->new("content profiling");
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
my $fieldInfo;
if($session{form}{fid} && $session{form}{fid} ne "new") {
$fieldInfo = WebGUI::MetaData::getField($session{form}{fid});
}
my $fid = $session{form}{fid} || "new";
my $f = WebGUI::HTMLForm->new(-action=>$self->getUrl);
$f->hidden("func", "editMetaDataFieldSave");
$f->hidden("fid", $fid);
$f->readOnly(
-value=>$fid,
-label=>WebGUI::International::get('Field Id','Asset'),
);
$f->text("fieldName", WebGUI::International::get('Field name','Asset'), $fieldInfo->{fieldName});
$f->textarea("description", WebGUI::International::get(85), $fieldInfo->{description});
$f->fieldType(
-name=>"fieldType",
-label=>WebGUI::International::get(486),
-value=>[$fieldInfo->{fieldType} || "text"],
-types=> [ qw /text integer yesNo selectList radioList/ ]
);
$f->textarea("possibleValues",WebGUI::International::get(487),$fieldInfo->{possibleValues});
$f->submit();
$ac->setHelp("metadata edit property","Asset");
return $ac->render($f->print, WebGUI::International::get('Edit Metadata',"Asset"));
}
#-------------------------------------------------------------------
sub www_editMetaDataFieldSave {
my $self = shift;
my $ac = WebGUI::AdminConsole->new("content profiling");
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
$ac->setHelp("metadata edit property","Asset");
# Check for duplicate field names
my $sql = "select count(*) from metaData_properties where fieldName = ".
quote($session{form}{fieldName});
if ($session{form}{fid} ne "new") {
$sql .= " and fieldId <> ".quote($session{form}{fid});
}
my ($isDuplicate) = WebGUI::SQL->buildArray($sql);
if($isDuplicate) {
my $error = WebGUI::International::get("duplicateField", "Asset");
$error =~ s/\%field\%/$session{form}{fieldName}/;
return $ac->render($error,WebGUI::International::get('Edit Metadata',"Asset"));
}
if($session{form}{fieldName} eq "") {
return $ac->render(WebGUI::International::get("errorEmptyField", "Asset"),WebGUI::International::get('Edit Metadata',"Asset"));
}
if($session{form}{fid} eq 'new') {
$session{form}{fid} = WebGUI::Id::generate();
WebGUI::SQL->write("insert into metaData_properties (fieldId, fieldName, defaultValue, description, fieldType, possibleValues) values (".
quote($session{form}{fid}).",".
quote($session{form}{fieldName}).",".
quote($session{form}{defaultValue}).",".
quote($session{form}{description}).",".
quote($session{form}{fieldType}).",".
quote($session{form}{possibleValues}).")");
} else {
WebGUI::SQL->write("update metaData_properties set fieldName = ".quote($session{form}{fieldName}).", ".
"defaultValue = ".quote($session{form}{defaultValue}).", ".
"description = ".quote($session{form}{description}).", ".
"fieldType = ".quote($session{form}{fieldType}).", ".
"possibleValues = ".quote($session{form}{possibleValues}).
" where fieldId = ".quote($session{form}{fid}));
}
return $self->www_manageMetaData;
}
#-------------------------------------------------------------------
=head2 www_editTree ( )
@ -2313,7 +2525,7 @@ sub www_manageAssets {
sub www_manageClipboard {
my $self = shift;
my $ac = WebGUI::AdminConsole->new("clipboard");
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(12));
my @assets;
my ($header,$limit);
$ac->setHelp("clipboard manage");
@ -2334,6 +2546,22 @@ sub www_manageClipboard {
return $ac->render($self->getAssetManagerControl(\@assets), $header);
}
#-------------------------------------------------------------------
sub www_manageMetaData {
my $self = shift;
my $ac = WebGUI::AdminConsole->new("content profiling");
return $ac->render(WebGUI::Privilege::insufficient()) unless (WebGUI::Grouping::isInGroup(4));
my $output;
my $fields = $self->getMetaDataFields();
foreach my $fieldId (keys %{$fields}) {
$output .= deleteIcon("func=deleteMetaDataField&fid=".$fieldId,$self->getUrl,WebGUI::International::get('deleteConfirm','Asset'));
$output .= editIcon("func=editMetaDataField&fid=".$fieldId,$self->getUrl);
$output .= "<b>".$fields->{$fieldId}{fieldName}."</b><br>";
}
$ac->setHelp("metadata manage");
return $ac->render($output);
}
#-------------------------------------------------------------------
=head2 www_manageTrash ( )

View file

@ -165,7 +165,6 @@ sub editSave {
my %data;
my $class = 'WebGUI::Asset::File';
$class = "WebGUI::Asset::File::Image" if (isIn($storage->getFileExtension($filename),qw(jpg jpeg gif png)));
my $newAsset = $parent->addChild({className=>$class});
foreach my $definition (@{$self->definition}) {
foreach my $property (keys %{$definition->{properties}}) {
$data{$property} = WebGUI::FormProcessor::process(
@ -175,11 +174,11 @@ sub editSave {
);
}
}
$data{filename} = $filename;
$data->{className} = $class;
$data{storageId} = $storage->getId;
$data{title} = $data{menuTitle} = $filename;
$data{filename} = $data{title} = $data{menuTitle} = $filename;
$data{url} = $parent->getUrl.'/'.$filename;
$newAsset->update(\%data);
my $newAsset = $parent->addChild(\%data);
$newAsset->setSize($storage->getFileSize($filename));
$newAsset->generateThumbnail if ($class eq "WebGUI::Asset::File::Image");
}

View file

@ -19,12 +19,7 @@ use DBI;
use strict qw(subs vars);
use Tie::IxHash;
use WebGUI::Asset;
use WebGUI::AdminConsole;
use WebGUI::DateTime;
use WebGUI::FormProcessor;
use WebGUI::Grouping;
use WebGUI::HTML;
use WebGUI::HTMLForm;
use WebGUI::Id;
use WebGUI::International;
use WebGUI::Macro;
@ -32,11 +27,7 @@ use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::Style;
use WebGUI::SQL;
use WebGUI::TabForm;
use WebGUI::Asset::Template;
use WebGUI::URL;
use WebGUI::Utility;
use WebGUI::MetaData;
#use WebGUI::Asset::Wobject::WobjectProxy;
our @ISA = qw(WebGUI::Asset);
@ -163,22 +154,6 @@ sub confirm {
}
#-------------------------------------------------------------------
=head2 duplicate ( asset )
Extends the Asset duplicate method to also duplicate meta data.
=cut
sub duplicate {
my $self = shift;
my $newAsset = $self->SUPER::duplicate(shift);
WebGUI::MetaData::MetaDataDuplicate($self->getId, $newAsset->getId);
return $newAsset;
}
#-------------------------------------------------------------------
@ -417,12 +392,6 @@ sub processMacros {
return WebGUI::Macro::process($_[1]);
}
#-------------------------------------------------------------------
sub processPropertiesFromFormPost {
my $self = shift;
my $output = $self->SUPER::processPropertiesFromFormPost;
WebGUI::MetaData::metaDataSave($self->getId);
}
@ -435,58 +404,6 @@ sub processStyle {
}
#-------------------------------------------------------------------
=head2 processTemplate ( vars, templateId )
Returns the content generated from this template.
=head3 hashRef
A hash reference containing variables and loops to pass to the template engine.
=head3 templateId
An id referring to a particular template in the templates table.
=cut
sub processTemplate {
my $self = shift;
my $var = shift;
my $templateId = shift;
my $meta = WebGUI::MetaData::getMetaDataFields($self->get("wobjectId"));
foreach my $field (keys %$meta) {
$var->{$meta->{$field}{fieldName}} = $meta->{$field}{value};
}
$var->{'controls'} = $self->getToolbar;
my %vars = (
%{$self->{_properties}},
%{$var}
);
if (defined $self->get("_WobjectProxy")) {
$vars{isShortcut} = 1;
my ($originalPageURL) = WebGUI::SQL->quickArray("select url from asset where assetId=".quote($self->getId),WebGUI::SQL->getSlave);
$vars{originalURL} = WebGUI::URL::gateway($originalPageURL."#".$self->getId);
}
return WebGUI::Asset::Template->new($templateId)->process(\%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->getId);
}
#-------------------------------------------------------------------
=head2 reorderCollateral ( tableName, keyName [ , setName, setValue ] )

View file

@ -41,6 +41,42 @@ our $HELP = {
]
},
'metadata manage'=> {
title => 'content profiling',
body => 'metadata manage body',
related => [
{
tag => 'metadata edit property',
namespace => 'Asset'
},
{
tag => 'user macros',
namespace => 'WebGUI'
},
{
tag => 'wobject add/edit',
namespace => 'WebGUI',
},
],
},
'metadata edit property' => {
title => 'Metadata, Edit property',
body => 'metadata edit property body',
related => [
{
tag => 'metadata manage',
namespace => 'Asset'
},
{
tag => 'user macros',
namespace => 'WebGUI'
},
{
tag => 'wobject add/edit',
namespace => 'WebGUI',
},
],
},
};
1;

View file

@ -1,42 +0,0 @@
package WebGUI::Help::MetaData;
our $HELP = {
'metadata manage'=> {
title => 'content profiling',
body => 'metadata manage body',
related => [
{
tag => 'metadata edit property',
namespace => 'MetaData'
},
{
tag => 'user macros',
namespace => 'WebGUI'
},
{
tag => 'wobject add/edit',
namespace => 'WebGUI',
},
],
},
'metadata edit property' => {
title => 'Metadata, Edit property',
body => 'metadata edit property body',
related => [
{
tag => 'metadata manage',
namespace => 'MetaData'
},
{
tag => 'user macros',
namespace => 'WebGUI'
},
{
tag => 'wobject add/edit',
namespace => 'WebGUI',
},
],
},
};
1;

View file

@ -1,366 +0,0 @@
package WebGUI::MetaData;
=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 strict;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Macro;
use Tie::IxHash;
use WebGUI::ErrorHandler;
=head1 NAME
Package WebGUI::MetaData
=head1 DESCRIPTION
This package provides an interface to the MetaData system.
=head1 SYNOPSIS
use WebGUI::MetaData;
$wid = getWobjectByCriteria($hashRef);
$hashRef = WebGUI::MetaData::getField( $fieldId );
$hashRef = WebGUI::MetaData::getMetaDataFields();
$wid = getWobjectByCriteria($hashRef);
$arrayRef = WebGUI::MetaData::getFieldTypes;
WebGUI::MetaData::metaDataSave( $wobjectId )
WebGUI::MetaData::metaDataDelete( $wobjectId )
WebGUI::MetaData::MetaDataDuplicate( $fromWobjectId , $toWobjectId )
WebGUI::MetaData::deleteField( $fieldId );
=head1 METHODS
These functions/methods are available from this package:
=cut
#-------------------------------------------------------------------
=head2 getFieldTypes ()
Returns an array ref with supported metadata field types.
=cut
sub getFieldTypes {
return [ qw /text integer yesNo selectList radioList/ ];
}
#-------------------------------------------------------------------
=head2 deleteField ( fieldId )
Deletes a field from the metadata system.
=head3 fieldId
The fieldId to be deleted.
=cut
sub deleteField {
my $fieldId = shift;
return unless ($fieldId =~ /^\d+$/ || length($fieldId) == 22);
WebGUI::SQL->write("delete from metaData_properties where fieldId = ".quote($fieldId));
WebGUI::SQL->write("delete from metaData_values where fieldId = ".quote($fieldId));
}
#-------------------------------------------------------------------
=head2 getField ( fieldId , [ wobjectId ] )
Returns a hash reference containing metadata field properties
for a single field.
=head3 fieldId
The fieldId for which you want to retrieve field properties.
=head3 wobjectId
If specified, the method will not only get the field properties,
but the value for this wobjectId as well.
=cut
sub getField {
my $hashRef = {};
my $fieldId = shift;
my $wobjectId = shift;
my $field = getMetaDataFields($wobjectId, $fieldId);
foreach (keys %{$field->{$fieldId}}) {
$hashRef->{$_} = $field->{$fieldId}{$_};
}
return $hashRef;
}
#-------------------------------------------------------------------
=head2 getMetaDataFields ( [ wobjectId , fieldId] )
Returns a hash reference containing all metadata field properties.
If a wobjectId is specified, the metadata values for that wobject
are included as well. You can limit the output to a certain
field by specifying a fieldId.
=head3 wobjectId
If specified, the hashRef will contain the metadata values for
this wobject.
=head3 fieldId
If specified, the hashRef will contain only this field.
=cut
sub getMetaDataFields {
my $wobjectId = shift;
my $fieldId = shift;
tie my %hash, 'Tie::IxHash';
my $sql = "select
f.fieldId,
f.fieldName,
f.description,
f.defaultValue,
f.fieldType,
f.possibleValues,
d.value
from metaData_properties f
left join metaData_values d on f.fieldId=d.fieldId and d.wobjectId=".quote($wobjectId);
$sql .= " where f.fieldId = ".quote($fieldId) if ($fieldId);
$sql .= " order by f.fieldName";
my $sth = WebGUI::SQL->read($sql);
while( my $h = $sth->hashRef) {
foreach(keys %$h) {
$hash{$h->{fieldId}}{$_} = $h->{$_};
}
}
$sth->finish;
return \%hash;
}
#-------------------------------------------------------------------
=head2 metaDataSave ( wobjectId )
Saves posted metadata for requested wobjectId
=head3 wobjectId
The Id from the wobject you want to save metadata for.
=cut
sub metaDataSave {
my $wobjectId = shift;
foreach my $form (keys %{$session{form}}) {
if ($form =~ /^metadata_(\d+)$/) {
my $fieldId = $1;
my ($exists) = WebGUI::SQL->quickArray("select count(*) from metaData_values
where wobjectId = ".quote($wobjectId)."
and fieldId = ".quote($fieldId));
if(! $exists && $session{form}{$form} ne "") {
WebGUI::SQL->write("insert into metaData_values (fieldId, wobjectId)
values (".quote($fieldId).",".quote($wobjectId).")");
}
if($session{form}{$form} eq "") {
# Keep it clean
WebGUI::SQL->write("delete from metaData_values where wobjectId = ".
quote($wobjectId)." and fieldId = ".quote($fieldId));
} else {
WebGUI::SQL->write("update metaData_values set value = ".quote($session{form}{$form})."
where wobjectId = ".quote($wobjectId)." and fieldId = ".
quote($fieldId));
}
}
}
}
#-------------------------------------------------------------------
=head2 metaDataDelete ( wobjectId )
Deletes the metadata for requested wobjectId
=head3 wobjectId
The Id from the wobject you want to delete metadata for.
=cut
sub metaDataDelete {
my $wobjectId = shift;
return WebGUI::SQL->write("delete from metaData_values where wobjectId = ".quote($wobjectId));
}
#-------------------------------------------------------------------
=head2 MetaDataDuplicate ( fromWobjectId , toWobjectId )
Duplicates Metadata
=head3 fromWobjectId
The original wobject Id
=head3 toWobjectId
The new wobject Id
=cut
sub MetaDataDuplicate {
my $fromWobjectId = shift;
my $toWobjectId = shift;
my $sth = WebGUI::SQL->read("select * from metaData_values where wobjectId = ".quote($fromWobjectId));
while( my $h = $sth->hashRef) {
WebGUI::SQL->write("insert into metaData_values (fieldId, wobjectId, value) values (".
quote($h->{fieldId}).",".quote($toWobjectId).",".quote($h->{value}).")");
}
$sth->finish;
}
#-------------------------------------------------------------------
=head2 getWobjectByCriteria ( hashRef )
This function will search for a wobject that match a metadata criteria set.
If no wobject is found, undef will be returned.
=head3 hashRef
A typical hashRef for this function will look like:
{
proxiedNamespace => "Article",
resolveMultiples => "random",
proxyCriteria => "State = Wisconsin AND Country != Sauk"
}
Most of the time this will be a:
WebGUI::SQL->quickHashRef("select * from WobjectProxy where wobjectId=".quote($proxiedId));
=cut
sub getWobjectByCriteria {
my $wobjectProxy = shift;
my $criteria = $wobjectProxy->{proxyCriteria};
my $order = $wobjectProxy->{resolveMultiples};
my $namespace = $wobjectProxy->{proxiedNamespace};
my $wobjectId = $wobjectProxy->{wobjectId};
# Parse macro's in criteria
$criteria = WebGUI::Macro::process($criteria);
# Once a wobject is found, we will stick to that wobject,
# to prevent the proxying of multiple- depth wobjects like Surveys and USS.
my $scratchId;
if ($wobjectId) {
$scratchId = "WobjectProxy_" . $wobjectId;
if($session{scratch}{$scratchId}) {
return $session{scratch}{$scratchId} unless ($session{var}{adminOn});
}
}
# $criteria = "State = Wisconsin AND Country != Sauk";
#
# State = Wisconsin AND Country != Sauk
# | | |
# |- $field |_ $operator |- $value
# |_ $attribute |_ $attribute
my $operator = qr/<>|!=|=|>=|<=|>|<|like/i;
my $attribute = qr/['"][^()|=><!]+['"]|[^()|=><!\s]+/i;
my $constraint = $criteria;
# Get each expression from $criteria
foreach my $expression ($criteria =~ /($attribute\s*$operator\s*$attribute)/gi) {
# $expression will match "State = Wisconsin"
my $replacement = $expression; # We don't want to modify $expression.
# We need it later.
# Get the field (State) and the value (Wisconsin) from the $expression.
$expression =~ /($attribute)\s*$operator\s*($attribute)/gi;
my $field = $1;
my $value = $2;
# quote the field / value variables.
my $quotedField = $field;
my $quotedValue = $value;
unless ($field =~ /^\s*['"].*['"]\s*/) {
$quotedField = quote($field);
}
unless ($value =~ /^\s*['"].*['"]\s*/) {
$quotedValue = quote($value);
}
# transform replacement from "State = Wisconsin" to
# "(fieldname=State and value = Wisconsin)"
$replacement =~ s/\Q$field/(fieldname=$quotedField and value /;
$replacement =~ s/\Q$value/$quotedValue )/i;
# replace $expression with the new $replacement in $constraint.
$constraint =~ s/\Q$expression/$replacement/;
}
my $sql = " select w.wobjectId
from metaData_values d, metaData_properties f, wobject w
where f.fieldId = d.fieldId
and w.wobjectId = d.wobjectId
and w.namespace = ".quote($namespace);
# Add constraint only if it has been modified.
$sql .= " and ".$constraint if (($constraint ne $criteria) && $constraint ne "");
$sql .= " order by w.lastEdited desc";
# Execute the query with an unconditional read
my @wids;
my $sth = WebGUI::SQL->unconditionalRead($sql);
while (my ($data) = $sth->array) {
push (@wids, $data);
}
$sth->finish;
# No matching wobjects found.
if (scalar(@wids) == 0) {
return undef; # fall back to the originally mirrored wobject.
}
my $wid;
# Grab a wid from the results
if ($order eq 'random') {
$wid = $wids[ rand @wids ];
} else {
#default order is mostRecent
$wid = $wids[0]; # 1st element in list is most recent.
}
# Store the matching wobjectId in user scratch.
WebGUI::Session::setScratch($scratchId,$wid) if ($scratchId);
return $wid;
}
1;

View file

@ -117,12 +117,6 @@ sub getOperations {
'viewHelpIndex' => 'WebGUI::Operation::Help',
'viewMessageLog' => 'WebGUI::Operation::MessageLog',
'viewMessageLogMessage' => 'WebGUI::Operation::MessageLog',
'editMetaDataField' => 'WebGUI::Operation::MetaData',
'manageMetaData' => 'WebGUI::Operation::MetaData',
'editMetaDataFieldSave' => 'WebGUI::Operation::MetaData',
'deleteMetaDataField' => 'WebGUI::Operation::MetaData',
'deleteMetaDataFieldConfirm' => 'WebGUI::Operation::MetaData',
'saveMetaDataSettings' => 'WebGUI::Operation::MetaData',
'editProfile' => 'WebGUI::Operation::Profile',
'editProfileSave' => 'WebGUI::Operation::Profile',
'viewProfile' => 'WebGUI::Operation::Profile',

View file

@ -1,144 +0,0 @@
package WebGUI::Operation::MetaData;
#-------------------------------------------------------------------
# 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 WebGUI::AdminConsole;
use WebGUI::Icon;
use WebGUI::Id;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::MetaData;
use WebGUI::Privilege;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::URL;
use WebGUI::Utility;
#-------------------------------------------------------------------
sub _submenu {
my $workarea = shift;
my $title = shift;
$title = WebGUI::International::get($title,"MetaData") if ($title);
my $help = shift;
my $ac = WebGUI::AdminConsole->new("contentProfiling");
if ($help) {
$ac->setHelp($help,"MetaData");
}
if($session{form}{op} ne "manageMetaData") {
$ac->addSubmenuItem(WebGUI::URL::page('op=manageMetaData'), WebGUI::International::get('content profiling','MetaData'));
}
$ac->addSubmenuItem(WebGUI::URL::page('op=editMetaDataField'), WebGUI::International::get('Add new field','MetaData'));
return $ac->render($workarea, $title);
}
#-------------------------------------------------------------------
sub www_editMetaDataField {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
return WebGUI::Privilege::vitalComponent() if ($session{form}{fid} < 1000 && $session{form}{fid} > 0);
my ($output, $fieldName, $defaultValue, $description, $fieldInfo);
if($session{form}{fid} && $session{form}{fid} ne "new") {
$fieldInfo = WebGUI::MetaData::getField($session{form}{fid});
}
my $fid = $session{form}{fid} || "new";
my $f = WebGUI::HTMLForm->new;
$f->hidden("op", "editMetaDataFieldSave");
$f->hidden("fid", $fid);
$f->readOnly(
-value=>$fid,
-label=>WebGUI::International::get('Field Id','MetaData'),
);
$f->text("fieldName", WebGUI::International::get('Field name','MetaData'), $fieldInfo->{fieldName});
$f->textarea("description", WebGUI::International::get(85), $fieldInfo->{description});
$f->fieldType(
-name=>"fieldType",
-label=>WebGUI::International::get(486),
-value=>[$fieldInfo->{fieldType} || "text"],
-types=>WebGUI::MetaData::getFieldTypes()
);
$f->textarea("possibleValues",WebGUI::International::get(487),$fieldInfo->{possibleValues});
$f->submit();
$output .= $f->print;
return _submenu($output,'Edit Metadata',"metadata edit property");
}
#-------------------------------------------------------------------
sub www_editMetaDataFieldSave {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
return WebGUI::Privilege::vitalComponent() if ($session{form}{fid} < 1000 && $session{form}{fid} > 0);
# Check for duplicate field names
my $sql = "select count(*) from metaData_properties where fieldName = ".
quote($session{form}{fieldName});
if ($session{form}{fid} ne "new") {
$sql .= " and fieldId <> ".quote($session{form}{fid});
}
my ($isDuplicate) = WebGUI::SQL->buildArray($sql);
if($isDuplicate) {
my $error = WebGUI::International::get("duplicateField", "MetaData");
$error =~ s/\%field\%/$session{form}{fieldName}/;
return $error . www_editMetaDataField();
}
if($session{form}{fieldName} eq "") {
return WebGUI::International::get("errorEmptyField", "MetaData")
. www_editMetaDataField();
}
if($session{form}{fid} eq 'new') {
$session{form}{fid} = WebGUI::Id::generate();
WebGUI::SQL->write("insert into metaData_properties (fieldId, fieldName, defaultValue, description, fieldType, possibleValues) values (".
quote($session{form}{fid}).",".
quote($session{form}{fieldName}).",".
quote($session{form}{defaultValue}).",".
quote($session{form}{description}).",".
quote($session{form}{fieldType}).",".
quote($session{form}{possibleValues}).")");
} else {
WebGUI::SQL->write("update metaData_properties set fieldName = ".quote($session{form}{fieldName}).", ".
"defaultValue = ".quote($session{form}{defaultValue}).", ".
"description = ".quote($session{form}{description}).", ".
"fieldType = ".quote($session{form}{fieldType}).", ".
"possibleValues = ".quote($session{form}{possibleValues}).
" where fieldId = ".quote($session{form}{fid}));
}
return www_manageMetaData();
}
#-------------------------------------------------------------------
sub www_deleteMetaDataFieldConfirm {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
return WebGUI::Privilege::vitalComponent() if ($session{form}{fid} < 1000 && $session{form}{fid} > 0);
WebGUI::MetaData::deleteField($session{form}{fid});
return www_manageMetaData();
}
#-------------------------------------------------------------------
sub www_manageMetaData {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
my $output;
my $fields = WebGUI::MetaData::getMetaDataFields();
foreach my $fieldId (keys %{$fields}) {
$output .= deleteIcon("op=deleteMetaDataFieldConfirm&fid=".$fieldId,'',WebGUI::International::get('deleteConfirm','MetaData'));
$output .= editIcon("op=editMetaDataField&fid=".$fieldId);
$output .= "<b>".$fields->{$fieldId}{fieldName}."</b><br>";
}
return _submenu($output,undef,"metadata manage");
}
1;

View file

@ -308,3 +308,127 @@ sub www_view {
1;
#-------------------------------------------------------------------
=head2 getAssetByCriteria ( hashRef )
This function will search for a asset that match a metadata criteria set.
If no asset is found, undef will be returned.
=head3 hashRef
A typical hashRef for this function will look like:
{
proxiedNamespace => "Article",
resolveMultiples => "random",
proxyCriteria => "State = Wisconsin AND Country != Sauk"
}
Most of the time this will be a:
WebGUI::SQL->quickHashRef("select * from AssetProxy where assetId=".quote($proxiedId));
=cut
sub getAssetByCriteria {
my $assetProxy = shift;
my $criteria = $assetProxy->{proxyCriteria};
my $order = $assetProxy->{resolveMultiples};
my $namespace = $assetProxy->{proxiedNamespace};
my $assetId = $assetProxy->{assetId};
# Parse macro's in criteria
$criteria = WebGUI::Macro::process($criteria);
# Once a asset is found, we will stick to that asset,
# to prevent the proxying of multiple- depth assets like Surveys and USS.
my $scratchId;
if ($assetId) {
$scratchId = "AssetProxy_" . $assetId;
if($session{scratch}{$scratchId}) {
return $session{scratch}{$scratchId} unless ($session{var}{adminOn});
}
}
# $criteria = "State = Wisconsin AND Country != Sauk";
#
# State = Wisconsin AND Country != Sauk
# | | |
# |- $field |_ $operator |- $value
# |_ $attribute |_ $attribute
my $operator = qr/<>|!=|=|>=|<=|>|<|like/i;
my $attribute = qr/['"][^()|=><!]+['"]|[^()|=><!\s]+/i;
my $constraint = $criteria;
# Get each expression from $criteria
foreach my $expression ($criteria =~ /($attribute\s*$operator\s*$attribute)/gi) {
# $expression will match "State = Wisconsin"
my $replacement = $expression; # We don't want to modify $expression.
# We need it later.
# Get the field (State) and the value (Wisconsin) from the $expression.
$expression =~ /($attribute)\s*$operator\s*($attribute)/gi;
my $field = $1;
my $value = $2;
# quote the field / value variables.
my $quotedField = $field;
my $quotedValue = $value;
unless ($field =~ /^\s*['"].*['"]\s*/) {
$quotedField = quote($field);
}
unless ($value =~ /^\s*['"].*['"]\s*/) {
$quotedValue = quote($value);
}
# transform replacement from "State = Wisconsin" to
# "(fieldname=State and value = Wisconsin)"
$replacement =~ s/\Q$field/(fieldname=$quotedField and value /;
$replacement =~ s/\Q$value/$quotedValue )/i;
# replace $expression with the new $replacement in $constraint.
$constraint =~ s/\Q$expression/$replacement/;
}
my $sql = " select w.assetId
from metaData_values d, metaData_properties f, asset w
where f.fieldId = d.fieldId
and w.assetId = d.assetId
and w.namespace = ".quote($namespace);
# Add constraint only if it has been modified.
$sql .= " and ".$constraint if (($constraint ne $criteria) && $constraint ne "");
$sql .= " order by w.lastEdited desc";
# Execute the query with an unconditional read
my @wids;
my $sth = WebGUI::SQL->unconditionalRead($sql);
while (my ($data) = $sth->array) {
push (@wids, $data);
}
$sth->finish;
# No matching assets found.
if (scalar(@wids) == 0) {
return undef; # fall back to the originally mirrored asset.
}
my $wid;
# Grab a wid from the results
if ($order eq 'random') {
$wid = $wids[ rand @wids ];
} else {
#default order is mostRecent
$wid = $wids[0]; # 1st element in list is most recent.
}
# Store the matching assetId in user scratch.
WebGUI::Session::setScratch($scratchId,$wid) if ($scratchId);
return $wid;
}

View file

@ -186,6 +186,146 @@ The URL where the user will be redirected.
context => 'Help text for redirects'
},
'errorEmptyField' => {
message => q|<p><b>Error: Field name may not be empty.</b></p>|,
lastUpdated => 1089039511
},
'Select...' => {
message => q|Select...|,
lastUpdated => 1089039511
},
'duplicateField' => {
message => q|<p><b>Error: Fieldname "%field%" is already in use.</b></p>|,
lastUpdated => 1089039511
},
'Metadata' => {
message => q|Metadata|,
lastUpdated => 1089039511
},
'Field name' => {
message => q|Field name|,
lastUpdated => 1089039511
},
'Enable Metadata ?' => {
message => q|Enable Metadata ?|,
lastUpdated => 1089039511
},
'Edit Metadata' => {
message => q|Edit Metadata property|,
lastUpdated => 1089039511
},
'Add new field' => {
message => q|Add new metadata property|,
lastUpdated => 1089039511
},
'Enable passive profiling ?' => {
message => q|Enable passive profiling ?|,
lastUpdated => 1089039511
},
'deleteConfirm' => {
message => q|Are you certain you want to delete this Metadata property ?|,
lastUpdated => 1089039511
},
'Field Id' => {
message => q|Field Id|,
lastUpdated => 1089039511
},
'Delete Metadata field' => {
message => q|Delete Metadata property|,
lastUpdated => 1089039511
},
'Illegal Warning' => {
message => q|Enabling this feature is illegal in some countries, like Australia. In addition, some countries require you to add a warning to your site if you use this feature. Consult your local authorities for local laws. Plain Black Corporation is not responsible for your illegal activities, regardless of ignorance or malice.|,
lastUpdated => 1089039511
},
'content profiling' => {
message => q|Content Profiling|,
lastUpdated => 1089039511,
context => q|The title of the content profiling manager for the admin console.|
},
'metadata edit property body' => {
message => q|
You may add as many Metadata properties to a Wobject as you like.<br>
<br>
<b>Field Name</b><br>
The name of this metadata property.It must be unique. <br>
It is advisable to use only letters (a-z), numbers (0-9) or underscores (_) for
the field names.
<p><b>Description<br>
</b>An optional description for this metadata property. This text is displayed
as mouseover text in the wobject properties tab.</p>
<p><b>Data Type<br>
</b>Choose the type of form element for this field.<b><br>
<br>
Possible Values<br>
</b>This field is used only for the Radio List and Select List data types. Enter
the values you wish to appear, one per line.</p>
|,
lastUpdated => 1100232327
},
'metadata manage body' => {
message => q|
<p>The content profiling system in WebGUI (also known as the metadata system) allows you to identify content. Metadata is
information about the content, and is defined in terms of property-value pairs.</p>
<p>Examples of metadata:</p>
<ul>
<li>contenttype: sport</li>
<li>adult content: no</li>
<li>source: newspaper</li>
</ul>
<p>In the example <b>source: newspaper</b>, this metadata has a <i>property</i> named
<i>source</i> with a <i>value</i> of <i>newspaper</i>.</p>
<p>Metadata properties are defined globally, while Metadata values are set for
each wobject under the tab &quot;Metadata&quot; in the wobject properties.</p>
<p>Before you can use metadata in WebGUI, you'll have to switch the &quot;Enable Metadata
?&quot; setting to Yes in the Manage Settings menu.</p>
<p>Usage of metadata:</p>
<ul>
<li><p><b>Passive Profiling</b><br>
When passive profiling is switched on, every wobject viewed by a user will
be logged. The WebGUI scheduler summarizes the profiling information on a regular
basis.
This is basically content
ranking based upon the user's Areas of Interest (AOI).<br>
By default the summarizer runs once a day. However you can change that by
setting: <b>passiveProfileInterval = &lt;number of seconds&gt;</b> in the
WebGUI config file.</p>
</li>
<li><p><b>Areas of Interest Ranking</b><br>
Metadata in combination with passive profiling produces AOI (Areas of
Interest) information. You can retrieve the value of a metadata property
with the &#94;AOIRank(); and &#AOIHits(); macros.</p>
<li><p><b>Show content based upon criteria<br>
</b>The Wobject Proxy allows you to select content based upon criteria like:<blockquote>
contenttype = sport AND source != newspaper</blockquote>
You can use the AOI macro's described above in the criteria, so you can
present content based upon the users Areas of Interest. Example:<br>
type = &#94;AOIRank(contenttype);</p></li>
</ul>|,
context => q|Metadata help|,
lastUpdated => 1099530955
},
'Metadata, Edit property' => {
message => q|Metadata, Edit|,
lastUpdated => 1089039511
},
};
1;

View file

@ -1,146 +0,0 @@
package WebGUI::i18n::English::MetaData;
our $I18N = {
'errorEmptyField' => {
message => q|<p><b>Error: Field name may not be empty.</b></p>|,
lastUpdated => 1089039511
},
'Select...' => {
message => q|Select...|,
lastUpdated => 1089039511
},
'duplicateField' => {
message => q|<p><b>Error: Fieldname "%field%" is already in use.</b></p>|,
lastUpdated => 1089039511
},
'Metadata' => {
message => q|Metadata|,
lastUpdated => 1089039511
},
'Field name' => {
message => q|Field name|,
lastUpdated => 1089039511
},
'Enable Metadata ?' => {
message => q|Enable Metadata ?|,
lastUpdated => 1089039511
},
'Edit Metadata' => {
message => q|Edit Metadata property|,
lastUpdated => 1089039511
},
'Add new field' => {
message => q|Add new metadata property|,
lastUpdated => 1089039511
},
'Enable passive profiling ?' => {
message => q|Enable passive profiling ?|,
lastUpdated => 1089039511
},
'deleteConfirm' => {
message => q|Are you certain you want to delete this Metadata property ?|,
lastUpdated => 1089039511
},
'Field Id' => {
message => q|Field Id|,
lastUpdated => 1089039511
},
'Delete Metadata field' => {
message => q|Delete Metadata property|,
lastUpdated => 1089039511
},
'Illegal Warning' => {
message => q|Enabling this feature is illegal in some countries, like Australia. In addition, some countries require you to add a warning to your site if you use this feature. Consult your local authorities for local laws. Plain Black Corporation is not responsible for your illegal activities, regardless of ignorance or malice.|,
lastUpdated => 1089039511
},
'content profiling' => {
message => q|Content Profiling|,
lastUpdated => 1089039511,
context => q|The title of the content profiling manager for the admin console.|
},
'metadata edit property body' => {
message => q|
You may add as many Metadata properties to a Wobject as you like.<br>
<br>
<b>Field Name</b><br>
The name of this metadata property.It must be unique. <br>
It is advisable to use only letters (a-z), numbers (0-9) or underscores (_) for
the field names.
<p><b>Description<br>
</b>An optional description for this metadata property. This text is displayed
as mouseover text in the wobject properties tab.</p>
<p><b>Data Type<br>
</b>Choose the type of form element for this field.<b><br>
<br>
Possible Values<br>
</b>This field is used only for the Radio List and Select List data types. Enter
the values you wish to appear, one per line.</p>
|,
lastUpdated => 1100232327
},
'metadata manage body' => {
message => q|
<p>The content profiling system in WebGUI (also known as the metadata system) allows you to identify content. Metadata is
information about the content, and is defined in terms of property-value pairs.</p>
<p>Examples of metadata:</p>
<ul>
<li>contenttype: sport</li>
<li>adult content: no</li>
<li>source: newspaper</li>
</ul>
<p>In the example <b>source: newspaper</b>, this metadata has a <i>property</i> named
<i>source</i> with a <i>value</i> of <i>newspaper</i>.</p>
<p>Metadata properties are defined globally, while Metadata values are set for
each wobject under the tab &quot;Metadata&quot; in the wobject properties.</p>
<p>Before you can use metadata in WebGUI, you'll have to switch the &quot;Enable Metadata
?&quot; setting to Yes in the Manage Settings menu.</p>
<p>Usage of metadata:</p>
<ul>
<li><p><b>Passive Profiling</b><br>
When passive profiling is switched on, every wobject viewed by a user will
be logged. The WebGUI scheduler summarizes the profiling information on a regular
basis.
This is basically content
ranking based upon the user's Areas of Interest (AOI).<br>
By default the summarizer runs once a day. However you can change that by
setting: <b>passiveProfileInterval = &lt;number of seconds&gt;</b> in the
WebGUI config file.</p>
</li>
<li><p><b>Areas of Interest Ranking</b><br>
Metadata in combination with passive profiling produces AOI (Areas of
Interest) information. You can retrieve the value of a metadata property
with the &#94;AOIRank(); and &#AOIHits(); macros.</p>
<li><p><b>Show content based upon criteria<br>
</b>The Wobject Proxy allows you to select content based upon criteria like:<blockquote>
contenttype = sport AND source != newspaper</blockquote>
You can use the AOI macro's described above in the criteria, so you can
present content based upon the users Areas of Interest. Example:<br>
type = &#94;AOIRank(contenttype);</p></li>
</ul>|,
context => q|Metadata help|,
lastUpdated => 1099530955
},
'Metadata, Edit property' => {
message => q|Metadata, Edit|,
lastUpdated => 1089039511
},
};
1;

View file

@ -1,194 +0,0 @@
#!/usr/bin/perl
#-------------------------------------------------------------------
# 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
#-------------------------------------------------------------------
our ($webguiRoot, $webUser, @nailable);
BEGIN {
$webguiRoot = "..";
@nailable = qw(jpg jpeg png gif);
unshift (@INC, $webguiRoot."/lib");
}
$| = 1;
use Getopt::Long;
use strict;
use WebGUI::Collateral;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Utility;
my $configFile;
my $folderId = '0';
my $help;
my $override;
my $pathToFiles;
my $quiet;
my $thumbnailSize;
my $webUser = 'apache';
GetOptions(
'configFile=s'=>\$configFile,
'folderId=s'=>\$folderId,
'help'=>\$help,
'override'=>\$override,
'pathToFiles=s'=>\$pathToFiles,
'quiet'=>\$quiet,
'thumbnailSize=i'=>\$thumbnailSize,
'webUser=s'=>\$webUser
);
if ($help || $configFile eq "" || $pathToFiles eq ""){
print <<STOP;
Usage: perl $0 --pathToFiles=<pathToImportFiles> --configfile=<webguiConfig>
--configFile WebGUI config file.
--pathToFiles Folder containing files to import.
Options:
--folderId The unique identifier for the collateral
folder that the imported files should
be organized under. Defaults to '0' (Root).
--help Display this help message and exit.
--override This utility is designed to be run as
a privileged user on Linux style systems.
If you wish to run this utility without
being the super user, then use this flag,
but note that it may not work as
intended.
--quiet Disable output unless there's an error.
--thumbnailSize The size (in pixels) of the thumbnails
that will be generated if you import
images. Defaults to the Thumbnail Size
setting in the site's content settings.
--webUser The user that your web server runs as.
Defaults to 'apache'.
STOP
exit;
}
if (!($^O =~ /^Win/i) && $> != 0 && !$override) {
print "You must be the super user to use this utility.\n";
exit;
}
print "Starting..." unless ($quiet);
WebGUI::Session::open($webguiRoot,$configFile);
WebGUI::Session::refreshUserInfo(3);
print "OK\n" unless ($quiet);
addFiles(buildFileList($pathToFiles), ($thumbnailSize||$session{setting}{thumbnailSize}));
setPrivileges();
print "Cleaning up..." unless ($quiet);
WebGUI::Session::end($session{var}{sessionId});
WebGUI::Session::close();
print "OK\n" unless ($quiet);
#-----------------------------------------
# addFiles(dbHandler, filelistHashRef, webguiSettingsHashRef, pathToCopyFrom)
#-----------------------------------------
sub addFiles {
my ($type, $parameters);
my ($filelist, $thumbnailSize) = @_;
print "Adding files...\n" unless ($quiet);
foreach my $filename (keys %{$filelist}) {
print "Processing $filename.\n" unless ($quiet);
foreach my $ext (keys %{${$filelist}{$filename}}) {
my $collateral = WebGUI::Collateral->new("new");
print "\tCopying ".${$filelist}{$filename}{$ext}.".\n" unless ($quiet);
$collateral->saveFromFilesystem($pathToFiles.$session{os}{slash}.${$filelist}{$filename}{$ext},$thumbnailSize);
print "\tAdding $filename to the database.\n" unless ($quiet);
if (isIn(lc($ext), @nailable)) {
$type = "image";
$parameters = 'border="0"';
} else {
$type = "file";
$parameters = '';
}
$collateral->set({
collateralType=>$type,
name=>$filelist->{$filename}{$ext},
username=>"Imported",
thumbnailSize=>$thumbnailSize,
collateralFolderId=>$folderId,
parameters=>$parameters
});
}
}
print "Finished adding.\n";
}
#-----------------------------------------
# setPrivileges()
#-----------------------------------------
sub setPrivileges {
print "Setting filesystem privileges.\n" unless ($quiet);
if ($session{os}{type} eq "Linuxish") {
unless (system("chown -R ".$webUser." ".$session{config}{uploadsPath})) {
print "Privileges set.\n" unless ($quiet);
} else {
print "Could not set privileges.\n";
}
} else {
print "Cannot set privileges on this platform.\n" unless ($quiet)
}
}
#-----------------------------------------
# buildFileList(pathToImportFiles)
#-----------------------------------------
sub buildFileList {
print "Building file list.\n" unless ($quiet);
my (%filelist, @files, $file, $filename, $ext);
if (opendir(FILES,$_[0])) {
@files = readdir(FILES);
foreach $file (@files) {
unless ($file eq "." || $file eq "..") {
$file =~ /(.*?)\.(.*?)$/;
$filename = $1;
$ext = $2;
$filelist{$filename}{$ext} = $file;
print "Found file $file.\n" unless ($quiet);
}
}
closedir(FILES);
print "File list complete.\n" unless ($quiet);
return \%filelist;
} else {
print "Error: Could not open folder.\n";
exit;
}
}

View file

@ -14,7 +14,7 @@ our ($webguiRoot, @nailable);
BEGIN {
$webguiRoot = "..";
@nailable = qw(jpg jpeg png gif tif tiff bmp);
@nailable = qw(jpg jpeg png gif);
unshift (@INC, $webguiRoot."/lib");
}
@ -25,60 +25,72 @@ use File::Path;
use File::stat;
use FileHandle;
use Getopt::Long;
use Image::Magick;
use POSIX;
use strict;
use WebGUI::Attachment;
use WebGUI::Asset::File;
use WebGUI::Asset::File::Image;
use WebGUI::DateTime;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::Storage;
use WebGUI::Utility;
use WebGUI::Wobject::FileManager;
my $configFile;
my $groupToView = 2;
my $owner = 3;
my $groupToView = 7;
my $groupToEdit = 4;
my $help;
my $pathToFiles;
my $override;
my $quiet;
my $webUser = 'apache';
my $wobjectId;
my $assetId;
GetOptions(
'configFile=s'=>\$configFile,
'owner=s'=>\$owner,
'groupToView=s'=>\$groupToView,
'groupToEdit=s'=>\$groupToEdit,
'help'=>\$help,
'override'=>$override,
'pathToFiles=s'=>\$pathToFiles,
'quiet'=>\$quiet,
'webUser=s'=>\$webUser,
'wobjectId=s'=>\$wobjectId
'parentAssetId=s'=>\$parrentAssetId
);
if ($help || $configFile eq "" || $pathToFiles eq "" || $wobjectId eq ""){
if ($help || $configFile eq "" || $pathToFiles eq "" || $parentAssetId eq ""){
print <<STOP;
Usage: perl $0 --pathToFiles=<pathToImportFiles> --configfile=<webguiConfig> --wobjectId=<fileManagerWobjectId>
Usage: perl $0 --pathToFiles=<pathToImportFiles> --configfile=<webguiConfig> --parentAssetId=<assetId>
--configFile WebGUI config file.
--pathToFiles Folder containing files to import.
--wobjectId The wobject ID of the file manager you
wish to import these files to.
--parentAssetId The asset ID of the asset you wish
to attach these files to.
Options:
--groupToEdit The group ID of the group that should
have the privileges to edit these
files. Defaults to '4' (Content Managers).
--groupToView The group ID of the group that should
have the privileges to view these
files. Defaults to '2'.
files. Defaults to '7' (Everybody).
--help Display this help message and exit.
--owner The user ID of the user that should
have the privileges to modify these
files. Defaults to '3' (Admin).
--override This utility is designed to be run as
a privileged user on Linux style systems.
If you wish to run this utility without
@ -119,39 +131,33 @@ print "OK\n" unless ($quiet);
# addFiles(dbHandler, filelistHashRef, webguiSettingsHashRef, pathToCopyFrom)
#-----------------------------------------
sub addFiles {
my ($exists, @files, $filename, $ext, $id, $i, $file1, $file2, $file3, $seq);
my $filelist = shift;
print "Adding files...\n" unless ($quiet);
($exists) = WebGUI::SQL->quickArray("select count(*) from FileManager where wobjectId='$wobjectId'");
if ($exists) {
my $w = WebGUI::Wobject::FileManager->new({wobjectId=>$wobjectId,namespace=>"FileManager"});
foreach $filename (keys %{$_[0]}) {
print "Processing $filename.\n" unless ($quiet);
$i = 0;
@files = [];
print "\tAdding $filename to the database.\n" unless ($quiet);
my $fileId = $w->setCollateral("FileManager_file","FileManager_fileId",{
FileManager_fileId=>"new",
groupToView=>$groupToView,
dateUploaded=>time(),
fileTitle=>$filename
});
my $attachment = WebGUI::Attachment->new("new",$w->get("wobjectId"),$fileId);
foreach $ext (keys %{${$_[0]}{$filename}}) {
print "\tCopying ".${$_[0]}{$filename}{$ext}.".\n" unless ($quiet);
$attachment->saveFromFilesystem($pathToFiles.$session{os}{slash}.${$_[0]}{$filename}{$ext});
$files[$i] = ${$_[0]}{$filename}{$ext};
$i++;
}
my @files = sort {isIn(getType($b),@nailable) cmp isIn(getType($a),@nailable)} @files;
$w->setCollateral("FileManager_file","FileManager_fileId",{
FileManager_fileId=>$fileId,
downloadFile=>$files[0],
alternateVersion1=>$files[1],
alternateVersion2=>$files[2]
my $parent = WebGUI::Asset::File->newByDynamicClass($parentAssetId);
if (defined $parent) {
foreach my $file (@{$filelist}) {
print "\tAdding ".$file->{filename}." to the database.\n" unless ($quiet);
my $class = 'WebGUI::Asset::File';
$class = 'WebGUI::Asset::File::Image' if (isIn($file->{ext},@nailable));
my $url = $parent->getUrl.'/'.$file->{filename};
my $storage = WebGUI::Storage->create;
my $filename = $storage->addFileFromFilesystem($pathToFiles.$session{os}{slash}.$file->{filename});
my $newAsset = $parent->addChild({
className=>$class,
title=>$filename,
menuTitle=>$filename,
filename=>$filename,
storageId=>$storage->getId,
url=>$url,
groupIdView=>$groupToView,
groupIdEdit=>$groupToEdit,
ownerUserId=>$owner
});
$newAsset->generateThumbnail if ($class eq 'WebGUI::Asset::File::Image');
$newAsset->setSize($storage->getFileSize($filename));
}
} else {
print "Warning: File Manager '".$wobjectId."' does not exist. Cannot import files.\n";
print "Warning: Parent asset '".$parentAssetId."' does not exist. Cannot import files.\n";
}
print "Finished adding.\n" unless ($quiet);
}
@ -177,7 +183,7 @@ sub setPrivileges {
#-----------------------------------------
sub buildFileList {
print "Building file list.\n" unless ($quiet);
my (%filelist, @files, $file, $filename, $ext);
my (@filelist, @files, $file, $filename, $ext);
if (opendir(FILES,$_[0])) {
@files = readdir(FILES);
foreach $file (@files) {
@ -185,13 +191,14 @@ sub buildFileList {
$file =~ /(.*?)\.(.*?)$/;
$filename = $1;
$ext = $2;
push(@filelist,{ext=>$ext, filename=>$file});
$filelist{$filename}{$ext} = $file;
print "Found file $file.\n" unless ($quiet);
}
}
closedir(FILES);
print "File list complete.\n" unless ($quiet);
return \%filelist;
return \@filelist;
} else {
print "Error: Could not open folder.\n";
exit;

View file

@ -69,7 +69,6 @@ use XML::Simple ();
use WebGUI ();
use WebGUI::Affiliate ();
use WebGUI::Asset ();
use WebGUI::Asset::Wobject ();
use WebGUI::Auth ();
use WebGUI::Cache ();
use WebGUI::Config ();
@ -78,10 +77,6 @@ use WebGUI::DateTime ();
use WebGUI::ErrorHandler ();
use WebGUI::Form ();
use WebGUI::FormProcessor ();
use WebGUI::Forum ();
use WebGUI::Forum::Post ();
use WebGUI::Forum::Thread ();
use WebGUI::Forum::UI ();
use WebGUI::Group ();
use WebGUI::Grouping ();
use WebGUI::HTMLForm ();
@ -106,25 +101,25 @@ use WebGUI::User ();
use WebGUI::Utility ();
# help
use WebGUI::Help::Article ();
use WebGUI::Help::Asset ();
use WebGUI::Help::AuthLDAP ();
use WebGUI::Help::AuthSMB ();
use WebGUI::Help::AuthWebGUI ();
use WebGUI::Help::DataForm ();
use WebGUI::Help::EventsCalendar ();
use WebGUI::Help::HttpProxy ();
use WebGUI::Help::IndexedSearch ();
use WebGUI::Help::MessageBoard ();
use WebGUI::Help::Poll ();
use WebGUI::Help::Product ();
use WebGUI::Help::SQLReport ();
use WebGUI::Help::Survey ();
use WebGUI::Help::SyndicatedContent ();
use WebGUI::Help::USS ();
use WebGUI::Help::WebGUI ();
use WebGUI::Help::WobjectProxy ();
use WebGUI::Help::WSClient ();
#use WebGUI::Help::Article ();
#use WebGUI::Help::Asset ();
#use WebGUI::Help::AuthLDAP ();
#use WebGUI::Help::AuthSMB ();
#use WebGUI::Help::AuthWebGUI ();
#use WebGUI::Help::DataForm ();
#use WebGUI::Help::EventsCalendar ();
#use WebGUI::Help::HttpProxy ();
#use WebGUI::Help::IndexedSearch ();
#use WebGUI::Help::MessageBoard ();
#use WebGUI::Help::Poll ();
#use WebGUI::Help::Product ();
#use WebGUI::Help::SQLReport ();
#use WebGUI::Help::Survey ();
#use WebGUI::Help::SyndicatedContent ();
#use WebGUI::Help::USS ();
#use WebGUI::Help::WebGUI ();
#use WebGUI::Help::WobjectProxy ();
#use WebGUI::Help::WSClient ();
# i18n
use WebGUI::i18n::English ();
@ -156,6 +151,8 @@ use WebGUI::i18n::English::WSClient ();
use WebGUI::Asset::File ();
use WebGUI::Asset::File::Image ();
use WebGUI::Asset::Snippet ();
use WebGUI::Asset::Template ();
use WebGUI::Asset::Wobject ();
use WebGUI::Asset::Wobject::Article ();
use WebGUI::Asset::Wobject::Layout ();
use WebGUI::Asset::Wobject::Navigation ();
@ -173,6 +170,13 @@ use WebGUI::Auth::LDAP ();
# macros
use WebGUI::Macro::AdminBar ();
use WebGUI::Macro::AssetProxy ();
use WebGUI::Macro::Extras ();
use WebGUI::Macro::FileUrl ();
use WebGUI::Macro::JavaScript ();
use WebGUI::Macro::PageUrl ();
use WebGUI::Macro::Slash_gatewayUrl ();
use WebGUI::Macro::Spacer ();
use WebGUI::Macro::StyleSheet ();