Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 7 commits
  • 5 files changed
  • 0 commit comments
  • 2 contributors
View
4 README.md
@@ -1,6 +1,6 @@
# Asset Handler
-This version of Asset Handler is compatible with Movable Type 5.0 and later.
+This version of Asset Handler is compatible with Movable Type 4.0 and later, including MT5.0x and MT5.1x.
Movable Type 4.0 introduced a file manager like system dubbed "Assets" which listed files that had been uploaded through MT and allowed you to easily add them to entries or pages. But, what about files you have already uploaded? They don't show up in the asset listing screens and the only way you can have them appear is to re-upload them.
@@ -16,4 +16,4 @@ Asset Handler which provides two crucial features that should make using assets
+ http://plugins.movalog.com/asset-handler/
+ https://github.com/arvind/movabletype-asshat
-+ https://github.com/jayallen/mt-plugin-assethandler
++ https://github.com/jayallen/mt-plugin-assethandler
View
141 plugins/AssetHandler/config.yaml
@@ -35,77 +35,6 @@ applications:
label: Import Assets
mode: asset_import
condition: $AssetHandler::AssetHandler::Util::is_blog_context
- list_actions:
- asset:
- batch_editor:
- label: Batch Edit Assets
- code: $AssetHandler::AssetHandler::App::CMS::open_batch_editor
- order: 200
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_mt5
- no_prompt: 1
- unlink:
- label: Unlink
- code: $AssetHandler::AssetHandler::App::CMS::unlink_asset
- order: 200
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_mt5
- js_message: delete
- fix_path_tor:
- label: FullPath to %r
- code: $AssetHandler::AssetHandler::App::CMS::path_tor
- order: 310
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- js_message: edit
- fix_path_tofull:
- label: Flatten Path
- code: $AssetHandler::AssetHandler::App::CMS::flatten_path
- order: 320
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- js_message: edit
- fix_url:
- label: Fix wrong URL from Path
- code: $AssetHandler::AssetHandler::App::CMS::fix_url
- order: 330
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- js_message: edit
- modify_path:
- label: Modify File Path
- code: $AssetHandler::AssetHandler::App::CMS::modify_path
- order: 340
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- input: 1
- input_label: 'Specify a folder relative to the blog site path/URL to modify the selected asset(s) path to. Examples: enter a single folder ("assets/"), enter a subdirectory path ("my/asset/location/"), or modify assets to the blog root with "/".'
- no_prompt: 1
- move_assets:
- label: Move Assets
- code: $AssetHandler::AssetHandler::App::CMS::move_assets
- order: 350
- permission: upload
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- input: 1
- input_label: 'Specify a folder relative to the blog site path/URL to move the selected asset(s) to. Examples: enter a single folder ("assets/"), enter a subdirectory path ("my/asset/location/"), or move assets to the blog root with "/".'
- no_prompt: 1
- rename_assets:
- label: Rename Assets
- code: $AssetHandler::AssetHandler::App::CMS::rename_assets
- order: 360
- permission: upload
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- input: 1
- input_label: 'Specify a filename to rename the selected asset(s) to. Examples: examples.jpg or examples.'
- no_prompt: 1
- fix_datas:
- label: Fix AssetDatas
- code: $AssetHandler::AssetHandler::App::CMS::fix_datas
- order: 370
- permission: edit_assets
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- js_message: edit
methods:
asset_batch_editor: $AssetHandler::AssetHandler::App::CMS::open_batch_editor
save_assets: $AssetHandler::AssetHandler::App::CMS::save_assets
@@ -134,21 +63,77 @@ system_filters:
order: 1000
list_actions:
asset:
+ batch_editor:
+ label: Batch Edit
+ code: $AssetHandler::AssetHandler::App::CMS::open_batch_editor
+ order: 200
+ no_prompt: 1
+ button: 1
+ permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
unlink:
label: Unlink
code: $AssetHandler::AssetHandler::App::CMS::unlink_asset
- condition: $AssetHandler::AssetHandler::Util::is_blog_context
- order: 200
+ order: 300
button: 1
+ permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ js_message: delete
+ fix_path_tor:
+ label: FullPath to %r
+ code: $AssetHandler::AssetHandler::App::CMS::path_tor
+ order: 310
+ permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ js_message: edit
+ fix_path_tofull:
+ label: Flatten Path
+ code: $AssetHandler::AssetHandler::App::CMS::flatten_path
+ order: 320
+ permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ js_message: edit
+ fix_url:
+ label: Fix wrong URL from Path
+ code: $AssetHandler::AssetHandler::App::CMS::fix_url
+ order: 330
+ permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ js_message: edit
+ modify_path:
+ label: Modify File Path
+ code: $AssetHandler::AssetHandler::App::CMS::modify_path
+ order: 340
+ permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ input: 1
+ input_label: 'Specify a folder relative to the blog site path/URL to modify the selected asset(s) path to. Examples: enter a single folder ("assets/"), enter a subdirectory path ("my/asset/location/"), or modify assets to the blog root with "/".'
+ no_prompt: 1
+ move_assets:
+ label: Move Assets
+ code: $AssetHandler::AssetHandler::App::CMS::move_assets
+ order: 350
permission: upload
- batch_editor:
- label: Batch Edit
- code: $AssetHandler::AssetHandler::App::CMS::open_batch_editor
condition: $AssetHandler::AssetHandler::Util::is_blog_context
- order: 300
+ input: 1
+ input_label: 'Specify a folder relative to the blog site path/URL to move the selected asset(s) to. Examples: enter a single folder ("assets/"), enter a subdirectory path ("my/asset/location/"), or move assets to the blog root with "/".'
no_prompt: 1
- button: 1
+ rename_assets:
+ label: Rename Assets
+ code: $AssetHandler::AssetHandler::App::CMS::rename_assets
+ order: 360
+ permission: upload
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ input: 1
+ input_label: 'Specify a filename to rename the selected asset(s) to. Examples: examples.jpg or examples.'
+ no_prompt: 1
+ fix_datas:
+ label: Fix AssetDatas
+ code: $AssetHandler::AssetHandler::App::CMS::fix_datas
+ order: 370
permission: edit_assets
+ condition: $AssetHandler::AssetHandler::Util::is_blog_context
+ js_message: edit
list_properties:
asset:
label:
View
290 plugins/AssetHandler/lib/AssetHandler/App/CMS.pm
@@ -98,7 +98,12 @@ sub open_batch_editor {
format_ts( MT::App::CMS::LISTING_TIMESTAMP_FORMAT, $modified_on, $blog, $app->user ? $app->user->preferred_language : undef );
$row->{modified_on_relative} = relative_date( $modified_on, time, $blog );
}
- $row->{metadata_json} = JSON::to_json($meta);
+ if (MT->version_number >= 4.25) {
+ $row->{metadata_json} = JSON::to_json($meta);
+ }
+ else {
+ $row->{metadata_json} = JSON::objToJson($meta);
+ }
my $tags = MT::Tag->join( $tag_delim, $obj->tags );
$row->{tags} = $tags;
$row->{asset_type} = ($obj->class || '');
@@ -180,7 +185,9 @@ sub start_transporter {
$param->{path} =~ s{\\}{/}g;
($param->{url} = $blog->site_url) =~ s{/*$}{/};
$param->{with_entry} = ( $app->config->Asset2Entry || 0 );
- $param->{with_entry} = 1 if ( $blog->theme_id eq 'photogallery_blog');
+ if (MT->version_number >= 5) {
+ $param->{with_entry} = 1 if ( $blog->theme_id eq 'photogallery_blog');
+ }
return $app->build_page( $plugin->load_tmpl('transporter.tmpl'), $param );
}
@@ -516,15 +523,19 @@ sub print_transport_progress {
sub cb_asset_table {
my ($cb, $app, $tmpl) = @_;
-
- my $old = <<HERE;
+ if (MT->version_number < 5) {
+
+ }
+ else {
+ return if (MT->version_number >= 5.1);
+ my $old = <<HERE;
<th class="created-on"><__trans phrase="Created On"></th>
</tr>
</mt:setvarblock>
HERE
- $old = quotemeta($old);
+ $old = quotemeta($old);
- my $new = <<HERE;
+ my $new = <<HERE;
<th class="created-on"><__trans phrase="Created On"></th>
<th class="created-on"><__trans phrase="Appears in..."></th>
<th class="created-on"><__trans phrase="Folder"></th>
@@ -532,16 +543,16 @@ HERE
</mt:setvarblock>
HERE
- $$tmpl =~ s/$old/$new/;
+ $$tmpl =~ s/$old/$new/;
- $old = <<HERE;
+ $old = <<HERE;
</tr>
<mt:if __last__>
</tbody>
HERE
- $old = quotemeta($old);
+ $old = quotemeta($old);
- $new = <<HERE;
+ $new = <<HERE;
<td>
<mt:if name="appears_in">
<mt:loop name="appears_in">
@@ -558,7 +569,11 @@ HERE
<p><a href="<mt:var name="script_url">?__mode=list_page&amp;blog_id=<mt:var name="blog_id" escape="url">&amp;filter=asset_id&amp;filter_val=<mt:var name="id" escape="url">"><__trans phrase="Show all pages"></a></p>
</mt:if>
<mt:else>
+ <mt:if name="is_thumbnail">
+ <span class="is_tumbnail">-</span>
+ <mt:else>
<span class="hint"><__trans phrase="This asset has not been used."></span>
+ </mt:if>
</mt:if>
</td>
<td><mt:var name="folder" /></td>
@@ -567,151 +582,156 @@ HERE
</tbody>
HERE
- $$tmpl =~ s/$old/$new/;
+ $$tmpl =~ s/$old/$new/;
+ }
}
sub cb_list_asset_pre_listing {
my ($cb, $app, $terms, $args, $param, $hasher) = @_;
- my $default_thumb_width = 75;
- my $default_thumb_height = 75;
- my $default_preview_width = 75;
- my $default_preview_height = 75;
+ if (MT->version_number < 5) {
+
+ }
+ else {
+ return if (MT->version_number >= 5.1);
+ my $default_thumb_width = 75;
+ my $default_thumb_height = 75;
+ my $default_preview_width = 75;
+ my $default_preview_height = 75;
- my $site_path = $app->blog->site_path;
+ my $site_path = $app->blog->site_path;
- require File::Basename;
- require JSON;
- my %blogs;
- $$hasher = sub {
- my ( $obj, $row, %param ) = @_;
- my ($thumb_width, $thumb_height) = @param{qw( ThumbWidth ThumbHeight )};
- $row->{id} = $obj->id;
- my $blog = $blogs{ $obj->blog_id } ||= $obj->blog;
- $row->{blog_name} = $blog ? $blog->name : '-';
- $row->{url} = $obj->url; # this has to be called to calculate
- $row->{asset_type} = $obj->class_type;
- $row->{asset_class_label} = $obj->class_label;
- my $file_path = $obj->file_path; # has to be called to calculate
- my $meta = $obj->metadata;
- require MT::FileMgr;
- my $fmgr = MT::FileMgr->new('Local');
- ## TBD: Make sure $file_path is file, not directory.
- if ( $file_path && $fmgr->exists( $file_path ) ) {
- $row->{file_path} = $file_path;
- $row->{file_name} = File::Basename::basename( $file_path );
+ require File::Basename;
+ require JSON;
+ my %blogs;
+ $$hasher = sub {
+ my ( $obj, $row, %param ) = @_;
+ my ($thumb_width, $thumb_height) = @param{qw( ThumbWidth ThumbHeight )};
+ $row->{id} = $obj->id;
+ my $blog = $blogs{ $obj->blog_id } ||= $obj->blog;
+ $row->{blog_name} = $blog ? $blog->name : '-';
+ $row->{url} = $obj->url; # this has to be called to calculate
+ $row->{asset_type} = $obj->class_type;
+ $row->{asset_class_label} = $obj->class_label;
+ my $file_path = $obj->file_path; # has to be called to calculate
+ my $meta = $obj->metadata;
+ require MT::FileMgr;
+ my $fmgr = MT::FileMgr->new('Local');
+ ## TBD: Make sure $file_path is file, not directory.
+ if ( $file_path && $fmgr->exists( $file_path ) ) {
+ $row->{file_path} = $file_path;
+ $row->{file_name} = File::Basename::basename( $file_path );
- my $filename = File::Basename::basename( $file_path );
- (my $tmp = $file_path) =~ s!^(.*)[/\\]$filename$!$1!;
- $tmp =~ s!\\!/!g;
- $site_path =~ s!\\!/!g;
- $tmp =~ s!^$site_path(.*)$!$1!;
- $tmp .= '/' if ($tmp);
- $row->{folder} = $tmp;
+ my $filename = File::Basename::basename( $file_path );
+ (my $tmp = $file_path) =~ s!^(.*)[/\\]$filename$!$1!;
+ $tmp =~ s!\\!/!g;
+ $site_path =~ s!\\!/!g;
+ $tmp =~ s!^$site_path(.*)$!$1!;
+ $tmp .= '/' if ($tmp);
+ $row->{folder} = $tmp;
- my $size = $fmgr->file_size( $file_path );
- $row->{file_size} = $size;
- if ( $size < 1024 ) {
- $row->{file_size_formatted} = sprintf( "%d Bytes", $size );
- }
- elsif ( $size < 1024000 ) {
- $row->{file_size_formatted} =
- sprintf( "%.1f KB", $size / 1024 );
+ my $size = $fmgr->file_size( $file_path );
+ $row->{file_size} = $size;
+ if ( $size < 1024 ) {
+ $row->{file_size_formatted} = sprintf( "%d Bytes", $size );
+ }
+ elsif ( $size < 1024000 ) {
+ $row->{file_size_formatted} =
+ sprintf( "%.1f KB", $size / 1024 );
+ }
+ else {
+ $row->{file_size_formatted} =
+ sprintf( "%.1f MB", $size / 1024000 );
+ }
+ $meta->{'file_size'} = $row->{file_size_formatted};
}
else {
- $row->{file_size_formatted} =
- sprintf( "%.1f MB", $size / 1024000 );
+ $row->{file_is_missing} = 1 if $file_path;
}
- $meta->{'file_size'} = $row->{file_size_formatted};
- }
- else {
- $row->{file_is_missing} = 1 if $file_path;
- }
- $row->{file_label} = $row->{label} = $obj->label || $row->{file_name} || $app->translate('Untitled');
+ $row->{file_label} = $row->{label} = $obj->label || $row->{file_name} || $app->translate('Untitled');
- if ($obj->has_thumbnail) {
- $row->{has_thumbnail} = 1;
- my $height = $thumb_height || $default_thumb_height || 75;
- my $width = $thumb_width || $default_thumb_width || 75;
- my $square = $height == 75 && $width == 75;
- @$meta{qw( thumbnail_url thumbnail_width thumbnail_height )}
- = $obj->thumbnail_url( Height => $height, Width => $width , Square => $square );
+ if ($obj->has_thumbnail) {
+ $row->{has_thumbnail} = 1;
+ my $height = $thumb_height || $default_thumb_height || 75;
+ my $width = $thumb_width || $default_thumb_width || 75;
+ my $square = $height == 75 && $width == 75;
+ @$meta{qw( thumbnail_url thumbnail_width thumbnail_height )}
+ = $obj->thumbnail_url( Height => $height, Width => $width , Square => $square );
- $meta->{thumbnail_width_offset} = int(($width - $meta->{thumbnail_width}) / 2);
- $meta->{thumbnail_height_offset} = int(($height - $meta->{thumbnail_height}) / 2);
+ $meta->{thumbnail_width_offset} = int(($width - $meta->{thumbnail_width}) / 2);
+ $meta->{thumbnail_height_offset} = int(($height - $meta->{thumbnail_height}) / 2);
- if ($default_preview_width && $default_preview_height) {
- @$meta{qw( preview_url preview_width preview_height )}
- = $obj->thumbnail_url(
- Height => $default_preview_height,
- Width => $default_preview_width,
- );
- $meta->{preview_width_offset} = int(($default_preview_width - $meta->{preview_width}) / 2);
- $meta->{preview_height_offset} = int(($default_preview_height - $meta->{preview_height}) / 2);
+ if ($default_preview_width && $default_preview_height) {
+ @$meta{qw( preview_url preview_width preview_height )}
+ = $obj->thumbnail_url(
+ Height => $default_preview_height,
+ Width => $default_preview_width,
+ );
+ $meta->{preview_width_offset} = int(($default_preview_width - $meta->{preview_width}) / 2);
+ $meta->{preview_height_offset} = int(($default_preview_height - $meta->{preview_height}) / 2);
+ }
}
- }
- else {
- $row->{has_thumbnail} = 0;
- }
-
-### New >
- my @appears_in;
- my $place_class = $app->model('objectasset');
- my $place_iter = $place_class->load_iter(
- {
- blog_id => $obj->blog_id || 0,
- asset_id => $obj->parent ? $obj->parent : $obj->id
+ else {
+ $row->{has_thumbnail} = 0;
}
- );
- while (my $place = $place_iter->()) {
- my $entry_class = $app->model($place->object_ds) or next;
- next unless $entry_class->isa('MT::Entry');
- my $entry = $entry_class->load($place->object_id)
- or next;
- my %entry_data = (
- id => $place->object_id,
- class => $entry->class_type,
- entry => $entry,
- title => $entry->title,
+### New >
+ $row->{is_thumbnail} = $obj->parent ? 1 : 0;
+ my @appears_in;
+ my $place_class = $app->model('objectasset');
+ my $place_iter = $place_class->load_iter(
+ {
+ blog_id => $obj->blog_id || 0,
+ asset_id => $obj->id
+ }
);
- if (my $ts = $entry->authored_on) {
- $entry_data{authored_on_ts} = $ts;
- $entry_data{authored_on_formatted} =
- format_ts( MT::App::CMS::LISTING_DATETIME_FORMAT(), $ts, undef,
- $app->user ? $app->user->preferred_language : undef );
+ while (my $place = $place_iter->()) {
+ my $entry_class = $app->model($place->object_ds) or next;
+ next unless $entry_class->isa('MT::Entry');
+ my $entry = $entry_class->load($place->object_id)
+ or next;
+ my %entry_data = (
+ id => $place->object_id,
+ class => $entry->class_type,
+ entry => $entry,
+ title => $entry->title,
+ );
+ if (my $ts = $entry->authored_on) {
+ $entry_data{authored_on_ts} = $ts;
+ $entry_data{authored_on_formatted} =
+ format_ts( MT::App::CMS::LISTING_DATETIME_FORMAT(), $ts, undef,
+ $app->user ? $app->user->preferred_language : undef );
+ }
+ if (my $ts = $entry->created_on) {
+ $entry_data{created_on_ts} = $ts;
+ $entry_data{created_on_formatted} =
+ format_ts( MT::App::CMS::LISTING_DATETIME_FORMAT(), $ts, undef,
+ $app->user ? $app->user->preferred_language : undef );
+ }
+ push @appears_in, \%entry_data;
}
- if (my $ts = $entry->created_on) {
- $entry_data{created_on_ts} = $ts;
- $entry_data{created_on_formatted} =
- format_ts( MT::App::CMS::LISTING_DATETIME_FORMAT(), $ts, undef,
- $app->user ? $app->user->preferred_language : undef );
+ if (4 == @appears_in) {
+ pop @appears_in;
+ $row->{appears_in_more} = 1;
}
- push @appears_in, \%entry_data;
- }
- if (4 == @appears_in) {
- pop @appears_in;
- $row->{appears_in_more} = 1;
- }
- $row->{appears_in} = \@appears_in if @appears_in;
+ $row->{appears_in} = \@appears_in if @appears_in;
### New <
-
- my $ts = $obj->created_on;
- if ( my $by = $obj->created_by ) {
- my $user = MT::Author->load($by);
- $row->{created_by} = $user ? $user->name : $app->translate('(user deleted)');
- }
- if ($ts) {
- $row->{created_on_formatted} =
- format_ts( MT::App::CMS::LISTING_DATE_FORMAT(), $ts, $blog, $app->user ? $app->user->preferred_language : undef );
- $row->{created_on_time_formatted} =
- format_ts( MT::App::CMS::LISTING_TIMESTAMP_FORMAT(), $ts, $blog, $app->user ? $app->user->preferred_language : undef );
- $row->{created_on_relative} = relative_date( $ts, time, $blog );
- }
-
- @$row{keys %$meta} = values %$meta;
- $row->{metadata_json} = MT::Util::to_json($meta);
- $row;
- };
+ my $ts = $obj->created_on;
+ if ( my $by = $obj->created_by ) {
+ my $user = MT::Author->load($by);
+ $row->{created_by} = $user ? $user->name : $app->translate('(user deleted)');
+ }
+ if ($ts) {
+ $row->{created_on_formatted} =
+ format_ts( MT::App::CMS::LISTING_DATE_FORMAT(), $ts, $blog, $app->user ? $app->user->preferred_language : undef );
+ $row->{created_on_time_formatted} =
+ format_ts( MT::App::CMS::LISTING_TIMESTAMP_FORMAT(), $ts, $blog, $app->user ? $app->user->preferred_language : undef );
+ $row->{created_on_relative} = relative_date( $ts, time, $blog );
+ }
+ @$row{keys %$meta} = values %$meta;
+ $row->{metadata_json} = MT::Util::to_json($meta);
+ $row;
+ };
+ }
}
sub cb_list_param_asset {
@@ -728,6 +748,8 @@ sub cb_list_param_asset {
sub cb_header_param {
my ($cb, $app, $param, $tmpl) = @_;
+ my $version = MT->version_number;
+ return 1 if ($version < 5.1);
return 1
if ((($app->param('__mode') || '') ne 'list') || (($app->param('_type') || '') ne 'asset'));
View
2 plugins/AssetHandler/lib/AssetHandler/L10N/ja.pm
@@ -48,6 +48,8 @@ use vars qw( %Lexicon );
'Make Entry (with Category)' => 'ブログ記事を作成する(カテゴリーと共に)',
'Category Label:' => 'カテゴリー名:',
'Category Basename:' => 'カテゴリーベースネーム:',
+ 'Modified On' => '修正日',
+ 'FileSize' => 'ファイルサイズ',
);
1;
View
3 plugins/AssetHandler/lib/AssetHandler/Util.pm
@@ -22,11 +22,10 @@ sub is_mt5 {
}
sub is_illiad {
my $version = MT->version_number;
- if ($version >= 5.1) {
+ if (($version < 5.2)&&($version >= 5.1)) {
return 1;
}
}
-
sub is_image {
my $file = shift;
my $basename = File::Basename::basename( $file );

No commit comments for this range

Something went wrong with that request. Please try again.