]> git.imager.perl.org - bse.git/commitdiff
metadata for articles
authorTony Cook <tony@develop-help.com>
Fri, 22 Aug 2014 07:14:29 +0000 (17:14 +1000)
committerTony Cook <tony@develop-help.com>
Sat, 9 May 2015 04:08:51 +0000 (14:08 +1000)
MANIFEST
site/cgi-bin/modules/BSE/ArticleMetaMeta.pm [new file with mode: 0644]
site/cgi-bin/modules/BSE/Edit/Article.pm
site/cgi-bin/modules/BSE/MetaMeta.pm
site/cgi-bin/modules/BSE/MetaOwnerBase.pm
site/cgi-bin/modules/BSE/TB/Article.pm
site/templates/admin/edit_1.tmpl
site/templates/admin/file_edit.tmpl

index 8adb55e05279c26f3407437a81069c93e91d8e7f..91193934575ba6e71cb248f47656d9ea96842a4f 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -65,6 +65,7 @@ site/cgi-bin/modules/BSE/AdminSiteUsers.pm
 site/cgi-bin/modules/BSE/AdminUsers.pm
 site/cgi-bin/modules/BSE/API.pm
 site/cgi-bin/modules/BSE/Arrows.pm
+site/cgi-bin/modules/BSE/ArticleMetaMeta.pm
 site/cgi-bin/modules/BSE/Cache.pm
 site/cgi-bin/modules/BSE/Cache/Cache.pm
 site/cgi-bin/modules/BSE/Cache/CHI.pm
diff --git a/site/cgi-bin/modules/BSE/ArticleMetaMeta.pm b/site/cgi-bin/modules/BSE/ArticleMetaMeta.pm
new file mode 100644 (file)
index 0000000..fc9b482
--- /dev/null
@@ -0,0 +1,21 @@
+package BSE::ArticleMetaMeta;
+use strict;
+use base 'BSE::MetaMeta';
+
+our $VERSION = "1.000";
+
+sub validation_section {
+  "article metadata validation";
+}
+
+sub fields_section {
+  "global article metadata";
+}
+
+sub name_section {
+  my ($self, $name) = @_;
+
+  return "article metadata $name";
+}
+
+1;
index 70a51cddf8dc784c8d9cbd607d456ba163aad343..ad0545c1d3a9ee63a2a8b9160b7f1fffdcc77bd9 100644 (file)
@@ -16,7 +16,7 @@ use List::Util qw(first);
 use constant MAX_FILE_DISPLAYNAME_LENGTH => 255;
 use constant ARTICLE_CUSTOM_FIELDS_CFG => "article custom fields";
 
-our $VERSION = "1.051";
+our $VERSION = "1.052";
 
 =head1 NAME
 
@@ -2134,6 +2134,12 @@ sub save {
     $errors{template} = "Please only select templates from the list provided";
   }
 
+  my $meta;
+  if ($cgi->param("_save_meta")) {
+    require BSE::ArticleMetaMeta;
+    $meta = BSE::ArticleMetaMeta->retrieve($req, $article, \%errors);
+  }
+
   my $save_tags = $cgi->param("_save_tags");
   my @tags;
   if ($save_tags) {
@@ -2243,6 +2249,12 @@ sub save {
     $article->set_tags([ grep /\S/, @tags ], \$error);
   }
 
+use Data::Dumper;
+print STDERR Dumper($meta);
+  if ($meta) {
+    BSE::ArticleMetaMeta->save($article, $meta);
+  }
+
   # fix the kids too
   my @extra_regen;
   @extra_regen = $self->update_child_dynamic($article, $articles, $req);
index 9a5ebfb01dc09f0d8dd2e36b4df5d4c54fe15560..deaadfefff8f9b93f30da4c85b7a198f75faf129 100644 (file)
@@ -4,7 +4,7 @@ use Carp qw(confess);
 use Image::Size;
 use Fcntl ':seek';
 
-our $VERSION = "1.004";
+our $VERSION = "1.005";
 
 =head1 NAME
 
@@ -232,9 +232,9 @@ sub field {
   return $fields{$self->name};
 }
 
-=item name
+=item validate
 
-The field name of the metadata.
+Validate a meta data item.
 
 =cut
 
@@ -290,9 +290,9 @@ sub validate {
   return 1;
 }
 
-=item name
+=item metanames
 
-The field name of the metadata.
+List of form fields that are read for the meta item.
 
 =cut
 
@@ -347,6 +347,8 @@ sub display_name {
   $_[0]{display_name}
 }
 
+=back
+
 =head1 CLASS METHODS
 
 =over
index 19b211aa0d1df7717b1388c0e9b1ff1c3d0919ae..b562dccf8d729cefdab3e49888eadd1a6499e680 100644 (file)
@@ -2,7 +2,7 @@ package BSE::MetaOwnerBase;
 use strict;
 use Carp 'confess';
 
-our $VERSION = "1.002";
+our $VERSION = "1.003";
 
 =head1 NAME
 
@@ -47,7 +47,7 @@ sub metadata {
     );
 }
 
-=item metadata
+=item text_metadata
 
 Return all metadata for the object with a content type of
 C<text/plain>.
@@ -171,6 +171,8 @@ sub meta_config {
 
 These are not accessible from templates.
 
+=over
+
 =item clear_metadata
 
 Remove all metadata for this object.  Should be called when the object
index a010fe36ec6374aca2d5d8e5ece2176573959d72..656858a3ed43ded7315ccce2e7d9864699899f02 100644 (file)
@@ -5,11 +5,13 @@ use Squirrel::Row;
 use BSE::TB::SiteCommon;
 use BSE::TB::TagOwner;
 use BSE::FormatterBase;
+use BSE::MetaOwnerBase;
 use vars qw/@ISA/;
-@ISA = qw/Squirrel::Row BSE::TB::SiteCommon BSE::TB::TagOwner BSE::FormatterBase/;
+@ISA = qw/Squirrel::Row BSE::TB::SiteCommon BSE::TB::TagOwner BSE::FormatterBase BSE::MetaOwnerBase/;
+
 use Carp 'confess';
 
-our $VERSION = "1.028";
+our $VERSION = "1.029";
 
 =head1 NAME
 
@@ -753,6 +755,32 @@ sub others_indexed_as_myself {
   return grep $_->should_index, @kids, map($_->others_indexed_as_myself, @kids);
 }
 
+sub meta_owner_type {
+  'bse_article';
+}
+
+sub meta_meta_cfg_section {
+  "global article metadata";
+}
+
+sub meta_meta_cfg_prefix {
+  "article metadata";
+}
+
+sub metafields {
+  my ($self, $cfg) = @_;
+
+  $cfg ||= BSE::Cfg->single;
+
+  my %metanames = map { $_ => 1 } $self->metanames;
+
+  require BSE::ArticleMetaMeta;
+  my @fields = grep $metanames{$_->name} || $_->cond($self), BSE::ArticleMetaMeta->all_metametadata($cfg);
+
+  return ( @fields );
+}
+
+
 sub restricted_method {
   my ($self, $name) = @_;
 
index 26ed67641c5188888c5173e13a4d9b75d27a6c1a..fa81838eaf214206bc348ede8ae8d69c4d4047c5 100644 (file)
           </tr>
           <:or Article:><:eif Article:> 
         </table>
+<:.if !ifnew -:>
+<:.set metas = [ article.metafields ] -:>
+<:  .if metas.size -:>
+<fieldset>
+  <legend>Article Metadata</legend>
+<input type="hidden" name="_save_meta" value="1">
+<:  .for m in metas -:>
+<:#= bse.dumper(m) |raw :>
+<:    .set name = "meta_" _ m.name -:>
+<:    .set mdata = article.meta_by_name(m.name) -:>
+<:    .if m.type eq 'image' -:>
+<:      .set def = article.meta_by_name(m.display_name) -:>
+<:      .set def = def ? def.value_text : "" -:>
+<:    .else -:>
+<:      .set def = mdata ? mdata.value_text : "" -:>
+<:    .end if -:>
+<:    .if m.ro -:>
+<:      .call "inlinefieldro", name: name, field: m.field,
+               options: { default: def } -:>
+<:    .else -:>
+<:      .call "inlinefield", name: name, field: m.field, 
+                options: { delete: 1, default: def } -:>
+<:    .end if :>
+<:  .end for -:>
+</fieldset>
+<:  .end if -:>
+<:.end if -:>
 
   <p><: ifNew :>
     <input type="submit" name="save" value="Add New <: articleType:>" />
index 78276e8416ca00e7ef1bd89233f465bc9775ab94..5bee01faa5994a55de9c0153c47cd0431dd568bb 100644 (file)
@@ -42,7 +42,6 @@
   <legend>File metadata</legend>
 
 <:  .for m in metas -:>
-<:= bse.dumper(m.field) |raw :>
 <:#= bse.dumper(m) |raw :>
 <:    .set name = "meta_" _ m.name -:>
 <:    .set mdata = file.meta_by_name(m.name) -:>