add Wobject metadata, passive profiling, generateContent script

This commit is contained in:
Len Kranendonk 2004-07-17 20:20:10 +00:00
parent 3482822e40
commit 50cc94ba43
7 changed files with 648 additions and 0 deletions

View file

@ -0,0 +1,36 @@
package WebGUI::Macro::AOIHits;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC.
#-------------------------------------------------------------------
# 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::Macro;
use WebGUI::Session;
use WebGUI::SQL;
#-------------------------------------------------------------------
sub process {
my (@param, $temp);
@param = WebGUI::Macro::getParams($_[0]);
my $key = $param[0];
my $value = $param[1];
my $sql = "select count from passiveProfileAOI a, metaData_fields f
where a.fieldId=f.fieldId
and userId=".quote($session{user}{userId})."
and fieldName=".quote($key)."
and value=".quote($value);
my ($count) = WebGUI::SQL->buildArray($sql);
return $count;
}
1;

View file

@ -0,0 +1,36 @@
package WebGUI::Macro::AOIRank;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC.
#-------------------------------------------------------------------
# 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::Macro;
use WebGUI::Session;
use WebGUI::SQL;
#-------------------------------------------------------------------
sub process {
my (@param, $temp);
@param = WebGUI::Macro::getParams($_[0]);
my $key = $param[0];
my $rank = $param[1] || 1; # 1 is highest rank
$rank--; # Rank is zero based
my $sql = "select value from passiveProfileAOI a, metaData_fields f
where a.fieldId=f.fieldId
and userId=".quote($session{user}{userId})."
and fieldName=".quote($key)." order by a.count desc";
my @values = WebGUI::SQL->buildArray($sql);
return $values[$rank];
}
1;

View file

@ -0,0 +1,195 @@
package WebGUI::Operation::MetaData;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC.
#-------------------------------------------------------------------
# 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 Exporter;
use strict;
use Tie::IxHash;
use WebGUI::International;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::URL;
use WebGUI::Utility;
use WebGUI::Operation::Shared;
use WebGUI::Icon;
use WebGUI::Privilege;
use WebGUI::SQL;
use WebGUI::MetaData;
our @ISA = qw(Exporter);
our @EXPORT = qw(&www_editMetaDataField &www_manageMetaData &www_editMetaDataFieldSave &www_deleteMetaDataField
&www_deleteMetaDataFieldConfirm &www_saveSettings);
#-------------------------------------------------------------------
sub _submenu {
my (%menu);
tie %menu, 'Tie::IxHash';
$menu{WebGUI::URL::page('op=manageSettings')} = WebGUI::International::get(4);
if($session{form}{op} ne "manageMetaData") {
$menu{WebGUI::URL::page('op=manageMetaData')} = WebGUI::International::get('Manage Metadata','MetaData');
}
$menu{WebGUI::URL::page('op=editMetaDataField')} = WebGUI::International::get('Add new field','MetaData');
return menuWrapper($_[0],\%menu);
}
#-------------------------------------------------------------------
sub www_saveSettings {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
WebGUI::SQL->write("update settings set value=".quote($session{form}{metaDataEnabled})." where name='metaDataEnabled'");
WebGUI::SQL->write("update settings set value=".quote($session{form}{passiveProfilingEnabled})." where name='passiveProfilingEnabled'");
$session{setting}{metaDataEnabled} = $session{form}{metaDataEnabled};
$session{setting}{passiveProfilingEnabled} = $session{form}{passiveProfilingEnabled};
return www_manageMetaData();
}
#-------------------------------------------------------------------
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);
# TODO: add help / internationlize
$output = helpIcon(22);
$output .= '<h1>'.WebGUI::International::get('Edit Metadata','MetaData').'</h1>';
if($session{form}{fid} && $session{form}{fid} ne "new") {
$fieldInfo = WebGUI::MetaData::getField($session{form}{fid});
}
my $fid = $session{form}{fid} || "new";
#TODO: internatioa
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->text("defaultValue", "Default value", $defaultValue);
$f->submit();
$output .= $f->print;
return _submenu($output);
}
#-------------------------------------------------------------------
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_fields 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}{fid} eq 'new') {
$session{form}{fid} = getNextId("metaData_fieldId");
WebGUI::SQL->write("insert into metaData_fields (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_fields 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_deleteMetaDataField {
return WebGUI::Privilege::adminOnly() unless (WebGUI::Grouping::isInGroup(3));
return WebGUI::Privilege::vitalComponent() if ($session{form}{fid} < 1000 && $session{form}{fid} > 0);
#TODO HELP
my $output = helpIcon("theme delete");
$output .= '<h1>'.WebGUI::International::get('Delete Metadata field','MetaData').'</h1>';
$output .= WebGUI::International::get('deleteConfirm','MetaData').'<p>';
$output .= '<div align="center"><a href="'.
WebGUI::URL::page('op=deleteMetaDataFieldConfirm&fid='.$session{form}{fid})
.'">'.WebGUI::International::get(44).'</a>';
$output .= '&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.WebGUI::URL::page('op=manageMetaData').
'">'.WebGUI::International::get(45).'</a></div>';
return _submenu($output);
}
#-------------------------------------------------------------------
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;
# TODO: add help
$output = helpIcon(22);
$output .= '<h1>'.WebGUI::International::get('Manage Metadata','MetaData').'</h1>';
my $f = new WebGUI::HTMLForm;
$f->hidden("op","saveSettings");
$f->yesNo(
-name=>"metaDataEnabled",
-label=>WebGUI::International::get("Enable Metadata ?", 'MetaData'),
-value=>$session{setting}{metaDataEnabled},
);
$f->yesNo(
-name=>"passiveProfilingEnabled",
-label=>WebGUI::International::get("Enable passive profiling ?", 'MetaData'),
-value=>$session{setting}{passiveProfilingEnabled},
);
$f->submit();
$output .= $f->print;
$output .= "<h1>".WebGUI::International::get('Manage Metadata fields','MetaData')."</h1>";
my $fields = WebGUI::MetaData::getMetaDataFields();
foreach my $fieldId (keys %{$fields}) {
$output .= deleteIcon("op=deleteMetaDataField&fid=".$fieldId);
$output .= editIcon("op=editMetaDataField&fid=".$fieldId);
$output .= "<b>".$fields->{$fieldId}{fieldName}."</b><br>";
}
$output .= '<p><a href="'.WebGUI::URL::page("op=editMetaDataField&fid=new").'">'.
WebGUI::International::get('Add new field','MetaData').
'</a></p>';
return _submenu($output);
}
1;

View file

@ -0,0 +1,151 @@
package WebGUI::PassiveProfiling;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2004 Plain Black LLC.
-------------------------------------------------------------------
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::DateTime;
use Tie::IxHash;
=head1 NAME
Package WebGUI::PassiveProfiling
=head1 DESCRIPTION
This package provides an interface to the passive profiling system.
=head1 SYNOPSIS
use WebGUI::PassiveProfiling;
WebGUI::PassiveProfiling::add( $wobjectId );
=head1 METHODS
These functions/methods are available from this package:
=cut
#-------------------------------------------------------------------
=head2 add ( wobjectId )
Adds a wobjectId to the passive profile log.
=over
=item wobjectId
The wobjectId to add.
=back
=cut
sub add {
return unless ($session{setting}{passiveProfilingEnabled});
my $wobjectId = shift;
my $sql = "insert into passiveProfileLog (passiveProfileLogId, userId, sessionId, wobjectId, dateOfEntry)
values (".quote(getNextId("passiveProfileLogId")).",".
quote($session{user}{userId}).",".
quote($session{var}{sessionId}).",".
quote($wobjectId).",".
quote(WebGUI::DateTime::time()).")";
WebGUI::SQL->write($sql);
return;
}
#-------------------------------------------------------------------
=head2 addPage ( [ pageId ] )
Adds all wobjects on current page to the passive profile log.
Optionally you can specify an alternate pageId.
=over
=item pageId
The pageId of the page you want to log.
=back
=cut
sub addPage {
return unless ($session{setting}{passiveProfilingEnabled});
my $pageId = shift || $session{page}{pageId};
my @wids = WebGUI::SQL->buildArray("select * from wobject where pageId=".quote($pageId));
foreach my $wid (@wids) {
add($wid);
}
return;
}
#-------------------------------------------------------------------
=head2 summarizeAOI ( hashRef )
Summarizes passive profile log data using the metadata attributes. An entry
is logged in the passiveProfileAOI table.
=item hashRef
A hashRef with userId and wobjectId.
=back
=cut
sub summarizeAOI {
my $data = shift;
my $sql = "
select f.fieldName,
f.fieldType,
d.fieldId,
d.wobjectId,
d.value
from metaData_data d , metaData_fields f
where f.fieldId = d.fieldId
and d.wobjectId = ".$data->{wobjectId};
my $sth = WebGUI::SQL->read($sql);
while (my $field = $sth->hashRef) {
my $aoi = WebGUI::SQL->quickHashRef("select * from passiveProfileAOI
where userId=".quote($data->{userId})."
and fieldId=".quote($field->{fieldId})." and
value=".quote($field->{value}));
if(not exists $aoi->{userId}) {
# Add record to DB
WebGUI::SQL->write("insert into passiveProfileAOI (userId, fieldId, value)
values (".quote($data->{userId}).",".
quote($field->{fieldId}).",".
quote($field->{value}).")");
}
my $count = $aoi->{count};
$count++;
WebGUI::SQL->write("update passiveProfileAOI set count=".quote($count)."
where userId=".quote($data->{userId})."
and fieldId=".quote($field->{fieldId})." and
value=".quote($field->{value}));
}
$sth->finish;
}
1;

View file

@ -0,0 +1,57 @@
package WebGUI::i18n::English::MetaData;
our $I18N = {
'Metadata' => {
message => q|Metadata|,
lastUpdated => 1089039511,
context => 'Label for tab'
},
'duplicateField' => {
message => q|<p><b>Error: Fieldname "%field%" is already in use.</b></p>|,
lastUpdated => 1089039511,
},
'Delete Metadata field' => {
message => q|Delete Metadata field|,
lastUpdated => 1089039511,
},
'deleteConfirm' => {
message => q|Are you certain you want to delete this Metadata field ?|,
lastUpdated => 1089039511,
},
'Manage Metadata' => {
message => q|Manage Metadata|,
lastUpdated => 1089039511,
},
'Enable Metadata ?' => {
message => q|Enable Metadata ?|,
lastUpdated => 1089039511,
},
'Add new field' => {
message => q|Add new field|,
lastUpdated => 1089039511,
},
'Manage Metadata fields' => {
message => q|Manage Metadata fields|,
lastUpdated => 1089039511,
},
'Edit Metadata' => {
message => q|Edit Metadata|,
lastUpdated => 1089039511,
},
'Field Id' => {
message =>q|Field Id|,
lastUpdated=> 1089039511,
},
'Field name' => {
message => q|Field name|,
lastUpdated=> 1089039511,
},
'Enable passive profiling ?' => {
message => q|Enable passive profiling ?|,
lastUpdated=> 1089039511,
},
};
1;

View file

@ -0,0 +1,50 @@
package Hourly::SummarizePassiveProfileLog;
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC.
#-------------------------------------------------------------------
# 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::DateTime;
use WebGUI::Session;
use WebGUI::SQL;
use WebGUI::PassiveProfiling;
use WebGUI::DateTime;
#-----------------------------------------
sub process {
my $verbose = shift;
unless ($session{setting}{passiveProfilingEnabled}) {
print "Passive profiling is disabled...\n";
return;
}
my ($firstDate) = WebGUI::SQL->quickArray("select min(dateOfEntry) from passiveProfileLog");
my $interval = $session{config}{passiveProfileInterval} || 86400;
if (WebGUI::DateTime::time()-$firstDate < $interval) {
print " - Recently runned: Skipping...\n" if ($verbose);
return "";
}
my $sessionExpired = WebGUI::DateTime::time() - $session{setting}{sessionTimeout};
# We process entries for registered users and expired visitor sessions
my $sql = "select * from passiveProfileLog";
$sql .= " where userId <> 1 or (userId = 1 and dateOfEntry < ".quote($sessionExpired).")";
my $sth = WebGUI::SQL->read($sql);
while (my $data = $sth->hashRef) {
WebGUI::PassiveProfiling::summarizeAOI($data);
WebGUI::SQL->write("delete from passiveProfileLog where passiveProfileLogId = ".
quote($data->{passiveProfileLogId}));
}
$sth->finish;
}
1;

123
sbin/generateContent.pl Normal file
View file

@ -0,0 +1,123 @@
#!/usr/bin/perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2004 Plain Black LLC.
#-------------------------------------------------------------------
# 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;
BEGIN {
$webguiRoot = "..";
unshift (@INC, $webguiRoot."/lib");
}
use DBI;
use Getopt::Long;
use strict qw(subs vars);
use WebGUI;
use WebGUI::Session;
use WebGUI::HTML;
use WebGUI::Utility;
$|=1;
my ($configFile, $pageId, $userId, $styleId, $toFile, $stripHTML, $help);
$userId = 1;
GetOptions(
'configFile:s'=>\$configFile,
'pageId:i'=>\$pageId,
'userId:i'=>\$userId,
'styleId:i'=>\$styleId,
'toFile:s'=>\$toFile,
'stripHTML'=>\$stripHTML,
'help'=>\$help
);
#if ($help || $configFile eq '' || $pageId eq '' ) {
if ($help || $configFile eq '' ) {
print <<STOP;
Usage: perl $0 --configfile=<webguiConfig> --pageId=<pageNumber>
--configFile WebGUI config file (with no path info).
--pageId Set the page to be generated.
Options:
--help Displays this message.
--userId Set the user that should view the page.
Defaults to "1" (Visitor).
--styleId Set an alternate style for the page.
Defaults to page's default style.
--toFile Set the path and filename to write the
content to instead of standard out.
--stripHTML A flag indicating that WebGUI should
strip all the HTML from the document and
output only text. NOTE: The resulting
text may have formatting problems as a
result.
STOP
exit;
}
# Open output file if necessary
if ($toFile) {
open (TOFILE, ">$toFile") or die "Can't open file $toFile for writing. $!";
}
# Open WebGUI session
WebGUI::Session::open($webguiRoot,$configFile);
WebGUI::Session::refreshUserInfo($userId,$session{dbh});
WebGUI::Session::refreshPageInfo($pageId);
# No HTTP header as we're browserless
$session{page}{noHttpHeader} = 1;
# Alternate style
if (defined $styleId) {
$session{form}{makePrintable}++; # prevent caching
$session{page}{styleId} = $styleId;
}
# Retrieve content
my $content = WebGUI::page(undef, undef, 1);
# stripHTML
if ($stripHTML) {
$content = WebGUI::HTML::html2text($content);
} else {
# Make links absolute
$content = WebGUI::HTML::makeAbsolute($content);
}
# Print result
if ($toFile) {
print TOFILE $content;
} else {
print $content;
}
# Clean-up WebGUI Session
WebGUI::Session::end($session{var}{sessionId});
WebGUI::Session::close();
# Close output file if necessary
close(TOFILE) if ($toFile);
exit;