moved metadata system into asset superclass, and added a fileImport script
This commit is contained in:
parent
1914386984
commit
2110af418a
16 changed files with 623 additions and 1056 deletions
|
|
@ -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"=>{
|
||||
|
|
|
|||
|
|
@ -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 ( )
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 ] )
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
||||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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 "Metadata" in the wobject properties.</p>
|
||||
<p>Before you can use metadata in WebGUI, you'll have to switch the "Enable Metadata
|
||||
?" 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 = <number of seconds></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 ^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 = ^AOIRank(contenttype);</p></li>
|
||||
</ul>|,
|
||||
context => q|Metadata help|,
|
||||
lastUpdated => 1099530955
|
||||
},
|
||||
|
||||
'Metadata, Edit property' => {
|
||||
message => q|Metadata, Edit|,
|
||||
lastUpdated => 1089039511
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -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 "Metadata" in the wobject properties.</p>
|
||||
<p>Before you can use metadata in WebGUI, you'll have to switch the "Enable Metadata
|
||||
?" 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 = <number of seconds></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 ^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 = ^AOIRank(contenttype);</p></li>
|
||||
</ul>|,
|
||||
context => q|Metadata help|,
|
||||
lastUpdated => 1099530955
|
||||
},
|
||||
|
||||
'Metadata, Edit property' => {
|
||||
message => q|Metadata, Edit|,
|
||||
lastUpdated => 1089039511
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue