Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

initial addition of files, having fixed bug that prevented plugin fro…

…m working with MT 4.2
  • Loading branch information...
commit 491585c67a3a48187fe3ad768a28e62b398c1e36 1 parent 66b490c
@byrnereese authored
View
8 .gitignore
@@ -0,0 +1,8 @@
+#*
+*.bak
+*.zip
+Makefile
+Makefile.old
+MANIFEST
+MANIFEST.bak
+*~
View
17 MANIFEST.SKIP
@@ -0,0 +1,17 @@
+# version control
+\bCVS
+(^|/)\.
+
+# CPAN chain files
+^MANIFEST
+^Makefile
+^META.yml$
+^blib/
+\#$
+~$
+.bak$
+
+# packages
+\.zip$
+\.tar\.gz$
+
View
7 Makefile.PL
@@ -0,0 +1,7 @@
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Asset Gallery',
+ VERSION => '1.0.1',
+ DISTNAME => 'AssetGallery',
+);
View
24 README.md
@@ -0,0 +1,24 @@
+This plugin provides a custom field type called "Asset Gallery." This field
+type allows users to upload multiple files at once and associate them with not
+just a single blog post, but also a single field within that post.
+
+This plugin makes it easy for designers to create photo galleries embedded
+inside of a blog post.
+
+*This plugin was originally developed by Six Apart, but has since fallen into
+disrepair. Endevver has taken on responsibility for maintaining this plugin.*
+
+# Installation
+
+To install this plugin follow the instructions found here:
+
+http://tinyurl.com/easy-plugin-install
+
+# License
+
+This plugin is licensed under the GPLv2.
+
+# Copyright
+
+(c) 2008 Six Apart, Ltd.
+(c) 2009 Endevver, LLC.
View
77 plugins/AssetGallery/AssetGallery.pl
@@ -1,77 +0,0 @@
-# Asset Gallery - A plugin for Movable Type
-# Copyright (c) 2008, Six Apart
-
-package MT::Plugin::AssetGallery;
-
-use strict;
-use MT 4.0;
-use base qw( MT::Plugin );
-
-# Define $DISPLAY_NAME only if different from package ending (i.e. TestPlugin)
-our $DISPLAY_NAME = 'Asset Gallery';
-our $VERSION = '1.0';
-
-our ($plugin, $PLUGIN_MODULE, $PLUGIN_KEY);
-MT->add_plugin($plugin = __PACKAGE__->new({
- id => plugin_module(),
- key => plugin_key(),
- name => plugin_name(),
- description => "Introduces a new custom field that allows you to create a gallery of assets",
- version => $VERSION,
- author_name => "Six Apart",
- author_link => "http://sixapart.com/",
- # plugin_link => "http://plugins.movalog.com/asset-gallery/",
-}));
-
-sub init_registry {
- my $plugin = shift;
- $plugin->registry({
- customfield_types => '$AssetGallery::AssetGallery::load_customfield_type',
- callbacks => {
- 'api_post_save.entry' => { # For MTCS
- handler => '$AssetGallery::AssetGallery::CMSPostSave',
- priority => 2
- },
- 'cms_post_save.entry' => {
- handler => '$AssetGallery::AssetGallery::CMSPostSave',
- priority => 2
- },
- 'MT::App::CMS::template_source.edit_entry' => sub {
- my ($cb, $app, $tmpl) = @_;
-
- $$tmpl =~ s/(name="entry_form")/$1 enctype=\"multipart\/form-data\"/g;
- },
- 'cms_post_save.page' => {
- handler => '$AssetGallery::AssetGallery::CMSPostSave',
- priority => 2
- },
- 'cms_post_save.category' => {
- handler => '$AssetGallery::AssetGallery::CMSPostSave',
- priority => 2
- },
- 'cms_post_save.folder' => {
- handler => '$AssetGallery::AssetGallery::CMSPostSave',
- priority => 2
- },
- 'cms_post_save.author' => {
- handler => '$AssetGallery::AssetGallery::CMSPostSave',
- priority => 2
- }
- },
- tags => '$AssetGallery::AssetGallery::load_tags'
- });
-}
-
-sub plugin_name { return ($DISPLAY_NAME || plugin_module()) }
-sub plugin_module {
- $PLUGIN_MODULE or ($PLUGIN_MODULE = __PACKAGE__) =~ s/^MT::Plugin:://;
- return $PLUGIN_MODULE;
-}
-sub plugin_key {
- $PLUGIN_KEY or ($PLUGIN_KEY = lc(plugin_module())) =~ s/\s+//g;
- return $PLUGIN_KEY
-}
-
-sub instance { return $plugin; }
-
-1;
View
31 plugins/AssetGallery/config.yaml
@@ -0,0 +1,31 @@
+id: AssetGallery
+name: Asset Gallery
+version: 1.0
+description: "Introduces a new custom field that allows you to create a gallery of assets"
+author_name: "Six Apart, Byrne Reese"
+author_link: "http://www.sixapart.com/"
+
+customfield_types: $AssetGallery::AssetGallery::load_customfield_type
+tags: $AssetGallery::AssetGallery::load_tags
+
+callbacks:
+ MT::App::CMS::template_source.edit_entry: $AssetGallery::AssetGallery::xfrm_entry
+ api_post_save.entry:
+ handler: $AssetGallery::AssetGallery::CMSPostSave
+ priority: 2
+ cms_post_save.entry:
+ handler: $AssetGallery::AssetGallery::CMSPostSave
+ priority: 2
+ cms_post_save.page:
+ handler: $AssetGallery::AssetGallery::CMSPostSave
+ priority: 2
+ cms_post_save.category:
+ handler: $AssetGallery::AssetGallery::CMSPostSave
+ priority: 2
+ cms_post_save.folder:
+ handler: $AssetGallery::AssetGallery::CMSPostSave
+ priority: 2
+ cms_post_save.author:
+ handler: $AssetGallery::AssetGallery::CMSPostSave
+ priority: 2
+
View
98 plugins/AssetGallery/lib/AssetGallery.pm
@@ -8,7 +8,7 @@ sub load_customfield_type {
'asset_gallery' => {
label => 'Asset Gallery',
field_html => sub{
- my $plugin = MT::Plugin::AssetGallery->instance;
+ my $plugin = MT->component('AssetGallery');
return $plugin->load_tmpl('asset-gallery.tmpl');
},
field_html_params => sub {
@@ -16,11 +16,10 @@ sub load_customfield_type {
my $max_height = 0;
# my $max_width = 580;
- require MT::Asset;
my @asset_loop;
my @asset_ids = split ',', $param->{value};
foreach my $id (@asset_ids) {
- my $asset = MT::Asset->load($id) or next;
+ my $asset = MT->model('asset')->load($id) or next;
my $row = $asset->column_values;
$row->{url} = $asset->url; # this has to be called to calculate
@@ -74,30 +73,34 @@ sub load_tags {
return $tags;
}
+sub xfrm_entry {
+ my ($cb, $app, $tmpl) = @_;
+ $$tmpl =~ s/(name="entry_form")/$1 enctype=\"multipart\/form-data\"/g;
+}
+
sub CMSPostSave {
my ($cb, $app, $obj) = @_;
-
return unless $app->isa('MT::App');
-
my $q = $app->param;
-
- foreach ($app->param) {
- if(m/^(.*?)_multifile_(.*?)$/) {
- my $field_name = "$1_multifile_$2";
- my $customfield_value = $q->param($1);
-
- next if !$q->param($field_name);
-
- my ($asset, $bytes) = _upload_file($app, $obj, $field_name, $1);
-
+ foreach my $field ($app->param) {
+ if(my ($parent,$i) = ($field =~ m/^customfield_(.*?)_multifile_(.*?)$/)) {
+ my @assets = split(",",$app->param('customfield_'.$parent));
+ unless ($q->param($field)) {
+ $app->{'query'}->delete($field); # remove so others don't process it
+ next;
+ }
+ my ($asset, $bytes) = _upload_file($app, $obj, $field, $parent);
+# use Data::Dumper; MT->log({ message => "Uploaded asset (".Dumper($asset)."), bytes: $bytes" });
+ $app->{'query'}->delete($field); # remove so others don't process it
next if !defined $asset;
-
- $app->param($1, join ',', $customfield_value, $asset->id);
+ push @assets, $asset->id;
+ $app->param('customfield_'.$parent,join(',', @assets));
+ MT->log({ message => "app->param(customfield_".$parent.") = " . $app->param('customfield_'.$parent) });
}
- }
-
- return 1;
+ }
+ return 1;
}
+
## Mostly copied from MT::App::CMS::Asset::_upload_file
## we have to make it more re-usable!!
sub _upload_file {
@@ -105,19 +108,16 @@ sub _upload_file {
my $q = $app->param;
- require MT::Blog;
- my $blog_id = $app->param('blog_id');
- my $blog = MT::Blog->load($blog_id);
+ my $blog = $app->blog;
+ my $blog_id = $blog->id;
my $fmgr = $blog->file_mgr;
my $root_path = $blog->site_path;
my $obj_type = $obj->class_type || $obj->datasource;
my ($fh, $info) = $app->upload_info($field_name);
-
+
my $mimetype;
- if ($info) {
- $mimetype = $info->{'Content-Type'};
- }
+ $mimetype = $info->{'Content-Type'} if ($info);
# eval { $fh = $q->upload($field_name) };
# if ($@ && $@ =~ /^Undefined subroutine/) {
@@ -129,34 +129,44 @@ sub _upload_file {
$basename =~ s!^.*/!!; ## Get rid of full directory paths
my $relative_path;
- my $file_tmpl = $app->param("${field_id}_options");
- my ($ctx);
+
+ require CustomFields::Field;
+ my $field = CustomFields::Field->load(
+ {
+ $blog_id ? ( blog_id => [ $blog_id, 0 ] ) : ( blog_id => $blog_id ),
+ basename => $field_id,
+ }
+ );
+ my $file_tmpl = $field->options;
+
if ( $file_tmpl =~ m/\%[_-]?[A-Za-z]/ ) {
if ( $file_tmpl =~ m/<\$?MT/i ) {
$file_tmpl =~
-s!(<\$?MT[^>]+?>)|(%[_-]?[A-Za-z])!$1 ? $1 : '<MTFileTemplate format="'. $2 . '">'!gie;
+ s!(<\$?MT[^>]+?>)|(%[_-]?[A-Za-z])!$1 ? $1 : '<mt:FileTemplate format="'. $2 . '">'!gie;
}
else {
- $file_tmpl = qq{<MTFileTemplate format="$file_tmpl">};
+ $file_tmpl = qq{<mt:FileTemplate format="$file_tmpl">};
}
}
- if ($file_tmpl) {
- require MT::Template::Context;
- $ctx = MT::Template::Context->new;
- $ctx->stash( 'blog', $blog );
- }
+
+ require MT::Template::Context;
+ my $ctx = MT::Template::Context->new;
+ $ctx->{current_timestamp} = $obj->created_on;
local $ctx->{__stash}{$obj_type} = $obj;
+ local $ctx->{__stash}{blog} = $blog;
local $ctx->{__stash}{archive_category} = $obj if $obj_type eq 'category';
local $ctx->{__stash}{author} = $obj_type eq 'entry' ? $obj->author : $app->user;
+
require MT::Builder;
my $build = MT::Builder->new;
my $tokens = $build->compile( $ctx, $file_tmpl )
or return $blog->error( $build->errstr() );
- defined( $relative_path = $build->build( $ctx, $tokens ) )
- or return $blog->error( $build->errstr() );
+ unless ( $relative_path = $build->build( $ctx, $tokens ) ) {
+ MT->log({ message => "error building $file_tmpl: " . $build->errstr() });
+ return $blog->error( $build->errstr() );
+ }
my $path = File::Spec->catdir( $root_path, $relative_path );
-
unless ( $fmgr->exists($path) ) {
$fmgr->mkpath($path)
or return $app->error($app->translate(
@@ -224,8 +234,7 @@ s!(<\$?MT[^>]+?>)|(%[_-]?[A-Za-z])!$1 ? $1 : '<MTFileTemplate format="'. $2 . '"
my $ext =
( File::Basename::fileparse( $local_file, qr/[A-Za-z0-9]+$/ ) )[2];
- require MT::Asset;
- my $asset_pkg = MT::Asset->handler_for_file($local_basename);
+ my $asset_pkg = MT->model('asset')->handler_for_file($local_basename);
my $is_image = defined($w)
&& defined($h)
&& $asset_pkg->isa('MT::Asset::Image');
@@ -331,15 +340,14 @@ sub _hdlr_assets {
return '' unless $value;
- require MT::Asset;
- my @asset_ids = split /,/, $value;
+ my @asset_ids = split(/,/, $value);
my $count = 0;
my $asset_count = 0;
my $vars = $ctx->{__stash}{vars} ||= {};
foreach my $id (@asset_ids) {
$count++;
- my $asset = MT::Asset->load($id);
+ my $asset = MT->model('asset')->load($id);
next unless $asset;
$asset_count++;
@@ -358,4 +366,4 @@ sub _hdlr_assets {
$res;
}
-1;
+1;
View
2  plugins/AssetGallery/tmpl/asset-gallery.tmpl
@@ -64,7 +64,7 @@
</mt:unless>
<mt:setvar name="asset_gallery_js" value="1">
<input type="hidden" name="<mt:var name="field_id">" value="<mt:var name="field_value">" id="<mt:var name="field_id">" />
-<input type="hidden" name="<mt:var name="field_id">_options" value="<mt:var name="options">" id="<mt:var name="field_id">_options" />
+<!--<input type="hidden" name="<mt:var name="field_id">_options" value="<mt:var name="options">" id="<mt:var name="field_id">_options" />-->
<mt:unless name="field_value">
<!-- If there's' nothing in the gallery, just show file upload -->
Please sign in to comment.
Something went wrong with that request. Please try again.