| 1 | package Labyrinth::Metadata; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 12 | ▶ | use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 12 | $VERSION = '5.32'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | Labyrinth::Metadata - Metadata Management for Labyrinth. | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =cut | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # ------------------------------------- | ||||||||||||||||||||||||||||
| 16 | # Export Details | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 12 | require Exporter; | |||||||||||||||||||||||||||
| 19 | 12 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 12 | %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 22 | 'all' => [ qw( MetaSearch MetaSave MetaGet MetaCloud MetaTags ) ] | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 12 | @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 26 | 12 | @EXPORT = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 29 | # Libraries | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 12 | ▶ | use Labyrinth::Audit; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 12 | ▶ | use Labyrinth::Globals; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 12 | ▶ | use Labyrinth::DBUtils; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 12 | ▶ | use Labyrinth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 12 | ▶ | use HTML::TagCloud; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 39 | # Variables | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # type: 0 = optional, 1 = mandatory | ||||||||||||||||||||||||||||
| 42 | # html: 0 = none, 1 = text, 2 = textarea | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 12 | my %fields = ( | |||||||||||||||||||||||||||
| 45 | title => { type => 1, html => 1 }, | ||||||||||||||||||||||||||||
| 46 | tagline => { type => 0, html => 1 }, | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | #---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 50 | # Public Interface Functions | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =over 4 | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =item MetaSearch(%hash) | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | Provides the IDs for the given metadata search. The sqlkeys are one or more | ||||||||||||||||||||||||||||
| 59 | keys into the phrasebook. Requires a hash of parameters: | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | keys => \@sqlkeys | ||||||||||||||||||||||||||||
| 62 | meta => \@metadata | ||||||||||||||||||||||||||||
| 63 | full => 1 | ||||||||||||||||||||||||||||
| 64 | limit => $limit | ||||||||||||||||||||||||||||
| 65 | order => $order | ||||||||||||||||||||||||||||
| 66 | sort => $sort_order | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 'key' and 'meta' are mandatory, all other key/value pairs are optional. If | ||||||||||||||||||||||||||||
| 69 | 'full' is provided with a non-zero value, a full text search is performed. If | ||||||||||||||||||||||||||||
| 70 | a limit is given then only that number of records will be returned if more are | ||||||||||||||||||||||||||||
| 71 | available. In order to suitably sort the records you can porovide the ORDER BY | ||||||||||||||||||||||||||||
| 72 | string via the 'order' hash key. | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =item MetaSave | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | Records the metadata with the given sqlkey for the name record id. | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =item MetaGet | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | Gets the metadata for the given id. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =item MetaCloud | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Returns the XHTML snippet to display a Metadata Tag Cloud. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =item MetaTags | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Returns the list of tags attributed to a entry type and section ids. | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | =back | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub MetaSearch { | ||||||||||||||||||||||||||
|
Subroutine
MetaSearch: not called CC=17 SCAR=57.2
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my %hash = @_; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | my $keys = $hash{'keys'} || return (); | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'keys'} || (return ())
MC/DC0%0/1
$hash{'keys'} || (return ())
$hash{'keys'}
Truth table0%0/2
A
A= $hash{'keys'}
| |||||||||||||||||||||||||||||
| 98 | 0 | my $meta = lc join(",", map {"'$_'"} @{$hash{meta}}); | |||||||||||||||||||||||||||
| 99 | 0 | my $data = lc join("|", @{$hash{meta}}); | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $full = $hash{'full'} || 0; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'full'} || 0
MC/DC0%0/1
$hash{'full'} || 0
$hash{'full'}
Truth table0%0/2
A
A= $hash{'full'}
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | LogDebug("MetaSearch: keys=[@$keys], meta=[$meta], full=$full"); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return () unless(@$keys && $meta); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@$keys and $meta
MC/DC0%0/2
@$keys and $meta
@$keys
$meta
Truth table0%0/3
A and B
A= @$keysB= $meta
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my $where = $hash{'where'} ? "AND $hash{'where'}" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $limit = $hash{'limit'} ? "LIMIT $hash{'limit'}" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $order = $hash{'order'} ? "ORDER BY $hash{'order'}" : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | my %res; | |||||||||||||||||||||||||||
| 111 | 0 | for my $key (@$keys) { | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if($full) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | # full text searching | ||||||||||||||||||||||||||||
| 114 | 0 | my @rs = $dbi->GetQuery('hash',"MetaDetail$key",{meta=>$meta, data => $data, where => $where, limit => $limit, order => $order}); | |||||||||||||||||||||||||||
| 115 | 0 | for(@rs) {$res{$_->{id}} = $_}; | |||||||||||||||||||||||||||
| 116 | } else { | ||||||||||||||||||||||||||||
| 117 | 0 | my @rs = $dbi->GetQuery('hash',"MetaSearch$key",{meta=>$meta, data => $data, where => $where, limit => $limit, order => $order}); | |||||||||||||||||||||||||||
| 118 | 0 | for(@rs) {$res{$_->{id}} = $_}; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 0 | my @res; | |||||||||||||||||||||||||||
| 123 | 0 | ▶ | if($hash{'order'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if($hash{'order'} eq 'createdate') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | @res = map {$res{$_}} sort {int($res{$a}->{createdate}) <=> int($res{$b}->{createdate})} keys %res; | |||||||||||||||||||||||||||
| 126 | } else { | ||||||||||||||||||||||||||||
| 127 | 0 | @res = map {$res{$_}} sort {$res{$a}->{$hash{'order'}} cmp $res{$b}->{$hash{'order'}}} keys %res; | |||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||
| 130 | 0 | @res = map {$res{$_}} keys %res; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if($hash{'sort'} && $hash{'sort'} =~ /^desc/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$hash{"sort"} and $hash{"sort"} =~ /^desc/
MC/DC0%0/2
$hash{"sort"} and $hash{"sort"} =~ /^desc/
$hash{"sort"}
$hash{"sort"} =~ /^desc/
Truth table0%0/3
A and B
A= $hash{"sort"}B= $hash{"sort"} =~ /^desc/
| |||||||||||||||||||||||||||||
| 134 | 0 | @res = reverse @res; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if($hash{'limit'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | splice(@res,$hash{'limit'}); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | return @res; | |||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub MetaSave { | ||||||||||||||||||||||||||
|
Subroutine
MetaSave: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 145 | 0 | ▶ | my $id = shift || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my $keys = shift || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 147 | 0 | my @meta = @_; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | LogDebug("MetaSave: $id,[@meta]"); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 152 | 0 | for my $key (@$keys) { | |||||||||||||||||||||||||||
| 153 | 0 | $dbi->DoQuery("MetaDelete$key",$id); | |||||||||||||||||||||||||||
| 154 | 0 | $dbi->DoQuery("MetaUpdate$key",$id,lc($_)) for(@meta); | |||||||||||||||||||||||||||
| 155 | 0 | $count += scalar(@meta); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | return $count; | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | sub MetaGet { | ||||||||||||||||||||||||||
|
Subroutine
MetaGet: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 162 | 0 | my ($id,$key) = @_; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if($id && $key) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$id and $key
MC/DC0%0/2
$id and $key
$id
$key
Truth table0%0/3
A and B
A= $idB= $key
| |||||||||||||||||||||||||||||
| 165 | 0 | my @meta; | |||||||||||||||||||||||||||
| 166 | 0 | my @rows = $dbi->GetQuery('array',"MetaGet$key",$id); | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | if(@rows) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | push @meta, $_->[1] for(@rows); | |||||||||||||||||||||||||||
| 169 | 0 | ▶ | return @meta if(wantarray); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | return join(" ",sort @meta); | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return () if(wantarray); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | return; | |||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | sub MetaCloud { | ||||||||||||||||||||||||||
|
Subroutine
MetaCloud: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 179 | 0 | my %hash = @_; | |||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $key = $hash{'key'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'key'} || (return)
MC/DC0%0/1
$hash{'key'} || (return)
$hash{'key'}
Truth table0%0/2
A
A= $hash{'key'}
| |||||||||||||||||||||||||||||
| 182 | 0 | ▶ | my $sectionid = $hash{'sectionid'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'sectionid'} || (return)
MC/DC0%0/1
$hash{'sectionid'} || (return)
$hash{'sectionid'}
Truth table0%0/2
A
A= $hash{'sectionid'}
| |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my $actcode = $hash{'actcode'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'actcode'} || (return)
MC/DC0%0/1
$hash{'actcode'} || (return)
$hash{'actcode'}
Truth table0%0/2
A
A= $hash{'actcode'}
| |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $path = $settings{'urlmap-'.$actcode} || "$tvars{cgipath}/pages.cgi?act=$actcode&data="; | ||||||||||||||||||||||||||
|
Condition0%0/2
$Labyrinth::Metadata::settings{'urlmap-' . $actcode} || "$Labyrinth::Metadata::tvars{'cgipath'}/pages.cgi?act=$actcode&data="
MC/DC0%0/1
$Labyrinth::Metadata::settings{'urlmap-' . $actcode} || "$Labyrinth::Metadata::tvars{'cgipath'}/pages.cgi?act=$actcode&data="
$Labyrinth::Metadata::settings{'urlmap-' . $actcode}
Truth table0%0/2
A
A= $Labyrinth::Metadata::settings{'urlmap-' . $actcode}
| |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | my $cloud = HTML::TagCloud->new(levels=>10); | |||||||||||||||||||||||||||
| 188 | 0 | my @rsa = $dbi->GetQuery('hash',"MetaCloud$key",{ids => $sectionid}); | |||||||||||||||||||||||||||
| 189 | 0 | for(@rsa) { | |||||||||||||||||||||||||||
| 190 | 0 | $cloud->add($_->{metadata}, $path . $_->{metadata}, $_->{count}); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | my $html = $cloud->html(); | |||||||||||||||||||||||||||
| 194 | 0 | ▶ | while($html =~ m!((<a href="$path)([^"]+)">)!) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 195 | 0 | my ($href,$link1,$link2) = ($1,$2,$3); | |||||||||||||||||||||||||||
| 196 | 0 | $html =~ s!$href!$link1$link2" title="Meta search for '$link2'">!sgi; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | return $html; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub MetaTags { | ||||||||||||||||||||||||||
|
Subroutine
MetaTags: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 0 | my %hash = @_; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | ▶ | my $key = $hash{'key'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'key'} || (return)
MC/DC0%0/1
$hash{'key'} || (return)
$hash{'key'}
Truth table0%0/2
A
A= $hash{'key'}
| |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $sectionid = $hash{'sectionid'} || return; | ||||||||||||||||||||||||||
|
Condition0%0/2
$hash{'sectionid'} || (return)
MC/DC0%0/1
$hash{'sectionid'} || (return)
$hash{'sectionid'}
Truth table0%0/2
A
A= $hash{'sectionid'}
| |||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | my @rows = $dbi->GetQuery('hash',"MetaCloud$key",{ids => $sectionid}); | |||||||||||||||||||||||||||
| 209 | 0 | my @tags = map {$_->{metadata}} @rows; | |||||||||||||||||||||||||||
| 210 | 0 | return @tags; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 12 | 1; | |||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | __END__ | ||||||||||||||||||||||||||||