From a12afdd2a44775c52654cfebb3d47a308e3e1c5e Mon Sep 17 00:00:00 2001 From: Taku Amano Date: Sat, 19 Sep 2009 10:44:20 +0900 Subject: [PATCH 1/1] Initial version. --- Build.PL | 126 ++++++++++++++++++ LICENSE | 22 +++ MANIFEST | 15 +++ MANIFEST.SKIP | 48 +++++++ config.yaml | 150 +++++++++++++++++++++ l10n/en_us.yaml | 7 + l10n/ja.yaml | 9 ++ lib/Manifest/App.pm | 244 ++++++++++++++++++++++++++++++++++ lib/Manifest/L10N.pm | 26 ++++ lib/Manifest/L10N/en_us.pm | 30 +++++ lib/Manifest/L10N/ja.pm | 39 ++++++ php/block.mtifmanifesthadmodified.php | 34 +++++ php/block.mtmanifest.php | 50 +++++++ php/block.mtmanifests.php | 27 ++++ php/function.mtmanifestparty.php | 27 ++++ php/init.manifest.php | 63 +++++++++ php/load_object.pl | 62 +++++++++ tmpl/config.tmpl | 6 + 18 files changed, 985 insertions(+) create mode 100644 Build.PL create mode 100644 LICENSE create mode 100644 MANIFEST create mode 100644 MANIFEST.SKIP create mode 100644 config.yaml create mode 100644 l10n/en_us.yaml create mode 100644 l10n/ja.yaml create mode 100644 lib/Manifest/App.pm create mode 100644 lib/Manifest/L10N.pm create mode 100644 lib/Manifest/L10N/en_us.pm create mode 100644 lib/Manifest/L10N/ja.pm create mode 100644 php/block.mtifmanifesthadmodified.php create mode 100644 php/block.mtmanifest.php create mode 100644 php/block.mtmanifests.php create mode 100644 php/function.mtmanifestparty.php create mode 100644 php/init.manifest.php create mode 100644 php/load_object.pl create mode 100644 tmpl/config.tmpl diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..c98ff53 --- /dev/null +++ b/Build.PL @@ -0,0 +1,126 @@ +use strict; +use warnings; +use Module::Build; +use File::Spec; +use File::Basename; +use YAML qw/ Load /; + +my $class = Module::Build->subclass( + class => 'MTToiplanPluginDirectoryBuilder', + code => q{ + # Don't make blib + # sub ACTION_code {}; + # Don't make blib + sub ACTION_docs {}; + # Don't make META.yml + sub ACTION_distmeta { + # no warning on ACTION_distdir + $_[0]->{metafile} = 'MANIFEST'; + }; + # Don't add MEATA.yml to MANIFEST + sub ACTION_manifest { + $_[0]->{metafile} = 'MANIFEST', + $_[0]->SUPER::ACTION_manifest(@_); + }; + sub ACTION_test { + my $p = $_[0]->{properties}; + unshift( + @INC, + File::Spec->catdir($p->{base_dir}, 'extlib'), + File::Spec->catdir($p->{base_dir}, '../../lib'), + File::Spec->catdir($p->{base_dir}, '../../extlib'), + ); + + $_[0]->SUPER::ACTION_test(@_); + }; + sub ACTION_upload_google { + my ($self) = @_; + my $prj = 'toiplan-mtplugin-directory'; + my $ver = $self->dist_version; + my $dist_dir = $self->dist_dir; + my $name = $self->dist_name; + + $self->depends_on('dist'); + #$self->_call_action('distdir'); + $self->ACTION_distdir; + $self->depends_on('zipdist'); + system( + "googlecode_upload.py -s 'Release $ver (TGZ)' -p $prj -l $name $dist_dir.tar.gz" + ); + system( + "googlecode_upload.py -s 'Release $ver (ZIP)' -p $prj -l $name $dist_dir.zip" + ); + unlink("$dist_dir.tar.gz"); + unlink("$dist_dir.zip"); + }; + + sub ACTION_zipdist { + my ($self) = @_; + my $dist_dir = $self->dist_dir; + $self->depends_on('distdir'); + print "Creating $dist_dir.zip\n"; + system("zip -r $dist_dir.zip $dist_dir") == 0 or die $?; + $self->delete_filetree($dist_dir); + } + + sub ACTION_distdir { + my ($self) = @_; + + $_[0]->SUPER::ACTION_distdir(@_); + + my $dist_dir = $self->dist_dir; + rename($dist_dir, $self->{properties}{dist_name}); + use File::Path; + use File::Spec; + use File::Basename; + my $plugins = File::Spec->catfile($dist_dir, 'plugins'); + mkpath($plugins, 1, 0755); + + my $new_dist_dir = File::Spec->catfile( + $plugins, $self->{properties}{dist_name} + ); + rename($self->{properties}{dist_name}, $new_dist_dir); + + foreach my $f (glob(File::Spec->catfile($new_dist_dir, 'LIC*'))) { + rename($f, File::Spec->catfile($dist_dir, basename($f))); + } + + if (my @statics = glob(File::Spec->catfile($new_dist_dir, 'static/*'))) { + my $static = File::Spec->catfile( + $dist_dir, 'mt-static/plugins' + ); + mkpath($static, 1, 0755); + + my $d = File::Spec->catfile( + $static, $self->{properties}{dist_name} + ); + mkpath($d, 1, 0755); + + foreach my $f (@statics) { + rename($f, File::Spec->catfile($d, basename($f))); + } + + rmdir(File::Spec->catfile($new_dist_dir, 'static')); + } + } + } +); + +my $yaml_string = do { + open(my $fh, File::Spec->catfile(dirname(__FILE__), 'config.yaml')); + local $/; + <$fh> +}; +$yaml_string =~ s/^(\s*)\*/$1App::\*/gm; +my $yaml = Load($yaml_string); + +my $builder = $class->new( + dist_name => $yaml->{name}, + dist_author => 'Movable Type ACME Plugin Project', + dist_version => $yaml->{version}, + module_name => $yaml->{name} . '::App', + license => 'MIT License', + add_to_cleanup => [ $yaml->{name} . '-*' ], +); + +$builder->create_build_script(); diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c459ee --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +Manifest - Managing manifest. +Inspired by Acme::Bleach + +Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..5f2a7c6 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,15 @@ +config.yaml +l10n/en_us.yaml +l10n/ja.yaml +lib/Manifest/App.pm +lib/Manifest/L10N.pm +lib/Manifest/L10N/en_us.pm +lib/Manifest/L10N/ja.pm +LICENSE +php/block.mtifmanifesthadmodified.php +php/block.mtmanifest.php +php/block.mtmanifests.php +php/function.mtmanifestparty.php +php/init.manifest.php +php/load_object.pl +tmpl/config.tmpl diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..0d160a2 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,48 @@ +^MANIFEST +\bBuild.PL$ +#^Makefile +#^META.yml$ +#^blib/ +#~$ + + +# Avoid version control files. +\bRCS\b +\bCVS\b +,v$ +\B\.svn\b +\B\.cvsignore$ +\B\.git + +# Avoid Makemaker generated and utility files. +\bMakefile$ +\bblib +\bMakeMaker-\d +\bpm_to_blib$ +\bblibdirs$ +^MANIFEST\.SKIP$ + +# Avoid Module::Build generated and utility files. +\bBuild$ +\bBuild.bat$ +\b_build + +# Avoid Devel::Cover generated files +\bcover_db + +# Avoid temp and backup files. +~$ +\.tmp$ +\.old$ +\.bak$ +\#$ +\.# +\.rej$ + +# Avoid OS-specific files/dirs +# Mac OSX metadata +\B\.DS_Store +# Mac OSX SMB mount metadata files +\B\._ +# Avoid archives of this distribution +\bArchiveUploader-[\d\.\_]+ diff --git a/config.yaml b/config.yaml new file mode 100644 index 0000000..74f479c --- /dev/null +++ b/config.yaml @@ -0,0 +1,150 @@ +# Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +# plugin name +id: Manifest +name: Manifest +version: 0.0.1 +schema_version: 0.2 + +# about this plugin +description: <__trans phrase="Managing manifest"> +author_name: <__trans phrase="Movable Type ACME Plugin Project"> +author_link: http://mt-acme.sourceforge.jp/ +plugin_link: http://mt-acme.sourceforge.jp/manifest/ +doc_link: http://mt-acme.sourceforge.jp/manifest/ + +# localization +l10n_class: Manifest::L10N + +# object types +object_types: + entry: + first_revision: + type: integer + not_null: 1 + default: 0 + label: First published revisions + party: + type: string + size: 255 + not_null: 1 + label: Political party + required: 1 + revisioned: 1 + +# settings +config_template: config.tmpl +settings: + enabled: + Default: 0 + +# tag +tags: + help_url: http://mt-acme.sourceforge.jp/manifest/tags#%t + block: + Manifests: $Manifest::Manifest::App::_hdlr_manifests + Manifest: $Manifest::Manifest::App::_hdlr_manifest + IfManifestHadModified?: $Manifest::Manifest::App::_hdlr_if_modified + + ManifestAdditionalCategories: $Manifest::Manifest::App::_hdlr_proxy + ManifestAssets: $Manifest::Manifest::App::_hdlr_proxy + ManifestAtomID: $Manifest::Manifest::App::_hdlr_proxy + ManifestAudio: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthor: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorDisplayName: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorEmail: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorID: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorLink: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorNickname: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorURL: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorUsername: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorUserpic: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorUserpicAsset: $Manifest::Manifest::App::_hdlr_proxy + ManifestAuthorUserpicURL: $Manifest::Manifest::App::_hdlr_proxy + ManifestBasename: $Manifest::Manifest::App::_hdlr_proxy + ManifestBlogDescription: $Manifest::Manifest::App::_hdlr_proxy + ManifestBlogID: $Manifest::Manifest::App::_hdlr_proxy + ManifestBlogName: $Manifest::Manifest::App::_hdlr_proxy + ManifestBlogURL: $Manifest::Manifest::App::_hdlr_proxy + ManifestBody: $Manifest::Manifest::App::_hdlr_proxy + ManifestCategories: $Manifest::Manifest::App::_hdlr_proxy + ManifestCategory: $Manifest::Manifest::App::_hdlr_proxy + ManifestClass: $Manifest::Manifest::App::_hdlr_proxy + ManifestClassLabel: $Manifest::Manifest::App::_hdlr_proxy + ManifestCommentCount: $Manifest::Manifest::App::_hdlr_proxy + ManifestCreatedDate: $Manifest::Manifest::App::_hdlr_proxy + ManifestCustomFieldDescription: $Manifest::Manifest::App::_hdlr_proxy + ManifestCustomFieldName: $Manifest::Manifest::App::_hdlr_proxy + ManifestCustomFieldValue: $Manifest::Manifest::App::_hdlr_proxy + ManifestCustomFields: $Manifest::Manifest::App::_hdlr_proxy + ManifestDate: $Manifest::Manifest::App::_hdlr_proxy + ManifestEditLink: $Manifest::Manifest::App::_hdlr_proxy + ManifestEmbedCode: $Manifest::Manifest::App::_hdlr_proxy + ManifestExcerpt: $Manifest::Manifest::App::_hdlr_proxy + ManifestFlag: $Manifest::Manifest::App::_hdlr_proxy + ManifestID: $Manifest::Manifest::App::_hdlr_proxy + ManifestIfAllowComments: $Manifest::Manifest::App::_hdlr_proxy + ManifestIfAllowPings: $Manifest::Manifest::App::_hdlr_proxy + ManifestIfCategory: $Manifest::Manifest::App::_hdlr_proxy + ManifestIfCommentsOpen: $Manifest::Manifest::App::_hdlr_proxy + ManifestIfExtended: $Manifest::Manifest::App::_hdlr_proxy + ManifestIfTagged: $Manifest::Manifest::App::_hdlr_proxy + ManifestKeywords: $Manifest::Manifest::App::_hdlr_proxy + ManifestLink: $Manifest::Manifest::App::_hdlr_proxy + ManifestLinkURL: $Manifest::Manifest::App::_hdlr_proxy + ManifestModifiedDate: $Manifest::Manifest::App::_hdlr_proxy + ManifestMore: $Manifest::Manifest::App::_hdlr_proxy + ManifestNext: $Manifest::Manifest::App::_hdlr_proxy + ManifestPermalink: $Manifest::Manifest::App::_hdlr_proxy + ManifestPhoto: $Manifest::Manifest::App::_hdlr_proxy + ManifestPostType: $Manifest::Manifest::App::_hdlr_proxy + ManifestPrevious: $Manifest::Manifest::App::_hdlr_proxy + ManifestRank: $Manifest::Manifest::App::_hdlr_proxy + ManifestRawPostType: $Manifest::Manifest::App::_hdlr_proxy + ManifestRecommendVoteLink: $Manifest::Manifest::App::_hdlr_proxy + ManifestRecommendedTotal: $Manifest::Manifest::App::_hdlr_proxy + ManifestScore: $Manifest::Manifest::App::_hdlr_proxy + ManifestScoreAvg: $Manifest::Manifest::App::_hdlr_proxy + ManifestScoreCount: $Manifest::Manifest::App::_hdlr_proxy + ManifestScoreHigh: $Manifest::Manifest::App::_hdlr_proxy + ManifestScoreLow: $Manifest::Manifest::App::_hdlr_proxy + ManifestStatus: $Manifest::Manifest::App::_hdlr_proxy + ManifestTags: $Manifest::Manifest::App::_hdlr_proxy + ManifestTitle: $Manifest::Manifest::App::_hdlr_proxy + ManifestTrackbackCount: $Manifest::Manifest::App::_hdlr_proxy + ManifestTrackbackData: $Manifest::Manifest::App::_hdlr_proxy + ManifestTrackbackID: $Manifest::Manifest::App::_hdlr_proxy + ManifestTrackbackLink: $Manifest::Manifest::App::_hdlr_proxy + + function: + ManifestParty: $Manifest::Manifest::App::_hdlr_party + +# callback +callbacks: + MT::App::CMS::template_param.edit_entry: $Manifest::Manifest::App::param_edit_entry + MT::App::CMS::template_param.list_entry: $Manifest::Manifest::App::param_list_entry + MT::App::CMS::pre_run: $Manifest::Manifest::App::pre_run + MT::Entry::pre_save: $Manifest::Manifest::App::pre_save + MT::Page::pre_save: $Manifest::Manifest::App::pre_save + + api_save_filter.entry: $Manifest::Manifest::App::save_filter + cms_save_filter.entry: $Manifest::Manifest::App::save_filter + cms_delete_permission_filter.entry: $Manifest::Manifest::App::remove_filter diff --git a/l10n/en_us.yaml b/l10n/en_us.yaml new file mode 100644 index 0000000..8c8b127 --- /dev/null +++ b/l10n/en_us.yaml @@ -0,0 +1,7 @@ +entry: Manifest +Entry: Manifest +Entries: Manifests +Manage Entries: Manage Manifests +A saved version of this entry was auto-saved [_2]. Recover auto-saved content: A saved version of this manifest was auto-saved [_2]. Recover auto-saved content +This entry has been saved.: This manifest has been saved. +Create Entry: Create Manifest diff --git a/l10n/ja.yaml b/l10n/ja.yaml new file mode 100644 index 0000000..7d7b894 --- /dev/null +++ b/l10n/ja.yaml @@ -0,0 +1,9 @@ +entry: マニフェスト +Entry: マニフェスト +Entries: マニフェスト +Manage Entries: マニフェストの管理 +A saved version of this entry was auto-saved [_2]. Recover auto-saved content: マニフェストは自動保存され ています([_2])。自動保存された内容を元に戻す' +This entry has been saved.: マニフェストを保 存しました。 +Create Entry: 新しいマニフェストを作成 +View Entry: マニフェストを見る +Edit Entry: マニフェストを編集 diff --git a/lib/Manifest/App.pm b/lib/Manifest/App.pm new file mode 100644 index 0000000..970e866 --- /dev/null +++ b/lib/Manifest/App.pm @@ -0,0 +1,244 @@ +# Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +package Manifest::App; +use strict; +use warnings; + +use utf8; +use Encode; + +sub _hdlr_manifests { + my ($ctx, $args, $cond) = @_; + $ctx->tag('Entries', $args, $cond); +} + +sub _hdlr_proxy { + my ($ctx, $args, $cond) = @_; + my $tag = lc($ctx->stash('tag')); + $tag =~ s/manifest/entry/; + $ctx->tag($tag, $args, $cond); +} + +sub _hdlr_manifest { + my ($ctx, $args, $cond) = @_; + my $current = $ctx->{__stash}{entry}; + + if ($args->{revision} eq 'original') { + my $rev = $current->load_revision( + { rev_number => $current->first_revision } + ); + if ( $rev && @$rev ) { + $ctx->{__stash}{entry} = $rev->[0]; + } + } + + my $result = $ctx->slurp($args, $cond); + + $ctx->{__stash}{entry} = $current; + + $result; +} + +sub _hdlr_if_modified { + my ($ctx, $args, $cond) = @_; + + my $entry = $ctx->stash('entry') + or return $ctx->_no_entry_error(); + $entry->revision != $entry->first_revision; +} + +sub _hdlr_party { + my ($ctx, $args) = @_; + + my $entry = $ctx->stash('entry') + or return $ctx->_no_entry_error(); + $entry->party; +} + +sub enabled { + my $blog_id = shift; + if (! $blog_id) { + my $blog = MT->instance->blog + or return 0; + $blog_id = $blog->id; + } + my $plugin = MT->component('Manifest'); + $plugin->get_config_value('enabled', 'blog:' . $blog_id); +} + +sub pre_save { + my ($cb, $obj, $original) = @_; + + if (! $obj->first_revision) { + require MT::Entry; + if ($obj->status == MT::Entry::RELEASE()) { + my $revision = $obj->revision || 0; + $obj->first_revision($revision + 1); + } + else { + $obj->first_revision(0); + } + } + + if (! $obj->party) { + $obj->party(''); + } + + if ($obj->id && &enabled($obj->blog_id)) { + delete($obj->{changed_cols}->{'title'}); + delete($obj->{changed_cols}->{'party'}); + } + + 1; +} + +sub save_filter { + return 1 unless &enabled(); + + my ($cb, $app) = @_; + my $plugin = MT->component('Manifest'); + + my $party = $app->param('party') || ''; + $party =~ s/ |\s//g; + + if (! $party) { + return $cb->error($plugin->translate('Party is required.')); + } + + 1; +} + +sub remove_filter { + my ($cb, $app, $obj) = @_; + my $plugin = MT->component('Manifest'); + + if ($obj->id && &enabled($obj->blog_id)) { + return $cb->error($plugin->translate('The manifest is not editable.')); + } + + 1; +} + +sub pre_run { + return 1 unless &enabled(); + + my $plugin = MT->component('Manifest'); + my $lh = MT->language_handle; + + my $file = File::Spec->catfile( + $plugin->{full_path}, 'l10n', $lh->language_tag . '.yaml' + ); + if (! -f $file) { + $file = File::Spec->catfile( + $plugin->{full_path}, 'l10n', 'en_us.yaml' + ); + } + + require YAML::Tiny; + my $yaml = YAML::Tiny->read($file); + my $map = $yaml->[0]; + my $package = ref $lh; + + eval(<<__EOE__); +package $package; +\$Lexicon{\$_} = \$map->{\$_} foreach (keys(%\$map)); +__EOE__ +} + +sub param_edit_entry { + return 1 unless &enabled(); + + my ($cb, $app, $param, $tmpl) = @_; + + return 1 unless $app->param('_type') eq 'entry'; + + my $plugin = MT->component('Manifest'); + + push(@{ $param->{'field_loop'} }, { + 'field_id' => 'party', + 'lock_field' => '0', + 'field_name' => 'party', + 'show_field' => 1, + 'field_label' => $plugin->translate('Party'), + 'label_class' => 'top-label', + 'required' => '1', + 'field_html' => <<__EOF__, +" mt:watch-change="1" autocomplete="off" /> +__EOF__ + }); + + require MT::Entry; + return if (! $param->{id}) || ($param->{status} != MT::Entry::RELEASE()); + + my $confirm = $plugin->translate( + 'A manifest change is not recommended. \nMay I change really?' + ); + my $cant_mod_title = $plugin->translate( + 'The title is not editable.' + ); + my $cant_mod_party = $plugin->translate( + 'The party is not editable.' + ); + $param->{'js_include'} ||= ''; + $param->{'js_include'} .= <<__EOS__; + +__EOS__ +} + +sub param_list_entry { + return 1 unless &enabled(); + + my ($cb, $app, $param, $tmpl) = @_; + + return 1 unless $app->mode eq 'list_entry'; + + $param->{'js_include'} ||= ''; + $param->{'js_include'} .= <<__EOS__; + +__EOS__ +} + +1; diff --git a/lib/Manifest/L10N.pm b/lib/Manifest/L10N.pm new file mode 100644 index 0000000..6c33979 --- /dev/null +++ b/lib/Manifest/L10N.pm @@ -0,0 +1,26 @@ +# Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +package Manifest::L10N; +use strict; +use warnings; +use base 'MT::Plugin::L10N'; + +1; diff --git a/lib/Manifest/L10N/en_us.pm b/lib/Manifest/L10N/en_us.pm new file mode 100644 index 0000000..f5d2443 --- /dev/null +++ b/lib/Manifest/L10N/en_us.pm @@ -0,0 +1,30 @@ +# Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +package Manifest::L10N::en_us; + +use strict; +use warnings; + +use base 'Manifest::L10N'; +use vars qw( %Lexicon ); +%Lexicon = (); + +1; diff --git a/lib/Manifest/L10N/ja.pm b/lib/Manifest/L10N/ja.pm new file mode 100644 index 0000000..8c3aade --- /dev/null +++ b/lib/Manifest/L10N/ja.pm @@ -0,0 +1,39 @@ +# Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +package Manifest::L10N::ja; + +use strict; +use warnings; +use base 'Manifest::L10N::en_us'; +use vars qw( %Lexicon ); + +%Lexicon = ( + 'Managing manifest' => 'マニフェストを管理します', + 'Enabled in this blog' => 'このブログでマニフェストを管理する', + 'Party' => '政党', + 'A manifest change is not recommended. \nMay I change really?' => 'マニフェストの変更は推奨されません。\n本当に変更してもよろしいですか?', + 'Party is required.' => '政党欄は必ず記入してください', + 'The title is not editable.' => 'タイトルは編集できません。', + 'The party is not editable.' => '政党は変更できません。', + 'The manifest is not editable.' => 'マニフェストは変更できません。', +); + +1; diff --git a/php/block.mtifmanifesthadmodified.php b/php/block.mtifmanifesthadmodified.php new file mode 100644 index 0000000..d624626 --- /dev/null +++ b/php/block.mtifmanifesthadmodified.php @@ -0,0 +1,34 @@ +stash('entry'); + $meta = $entry->load_meta($entry); + $result = $entry->first_revision != $meta->revision; + return $ctx->_hdlr_if($args, $content, $ctx, $repeat, $result); + } + else { + return $ctx->_hdlr_if($args, $content, $ctx, $repeat); + } +} + +?> diff --git a/php/block.mtmanifest.php b/php/block.mtmanifest.php new file mode 100644 index 0000000..2ad5126 --- /dev/null +++ b/php/block.mtmanifest.php @@ -0,0 +1,50 @@ +localize($localvars); + $current = $ctx->stash('entry'); + $id = $current->id; + $rev = $current->first_revision; + + $entry = new Entry; + if ($entry->Load($id)) { + $file = dirname(__FILE__) . '/load_object.pl'; + $data = `/usr/bin/perl $file entry $id $rev`; + eval('$array = ' . $data); + foreach ($array as $k => $v) { + $entry->$k = $v; + } + $ctx->stash('entry', $entry); + } + } + else { + $ctx->restore($localvars); + } + } + + return $content; +} + +?> diff --git a/php/block.mtmanifests.php b/php/block.mtmanifests.php new file mode 100644 index 0000000..5990e7e --- /dev/null +++ b/php/block.mtmanifests.php @@ -0,0 +1,27 @@ + diff --git a/php/function.mtmanifestparty.php b/php/function.mtmanifestparty.php new file mode 100644 index 0000000..0dd594d --- /dev/null +++ b/php/function.mtmanifestparty.php @@ -0,0 +1,27 @@ +stash('entry'); + return $entry->party; +} + +?> diff --git a/php/init.manifest.php b/php/init.manifest.php new file mode 100644 index 0000000..cd39933 --- /dev/null +++ b/php/init.manifest.php @@ -0,0 +1,63 @@ +context(); +$tags = array( + 'manifestadditionalcategories', 'manifestassets', 'manifestatomid', + 'manifestaudio', 'manifestauthor', 'manifestauthordisplayname', + 'manifestauthoremail', 'manifestauthorid', 'manifestauthorlink', + 'manifestauthornickname', 'manifestauthorurl', 'manifestauthorusername', + 'manifestauthoruserpic', 'manifestauthoruserpicasset', 'manifestauthoruserpicurl', + 'manifestbasename', 'manifestblogdescription', 'manifestblogid', + 'manifestblogname', 'manifestblogurl', 'manifestbody', + 'manifestcategories', 'manifestcategory', 'manifestclass', + 'manifestclasslabel', 'manifestcommentcount', 'manifestcreateddate', + 'manifestcustomfielddescription', 'manifestcustomfieldname', 'manifestcustomfieldvalue', + 'manifestcustomfields', 'manifestdate', 'manifesteditlink', + 'manifestembedcode', 'manifestexcerpt', 'manifestflag', + 'manifestid', 'manifestifallowcomments', 'manifestifallowpings', + 'manifestifcategory', 'manifestifcommentsopen', 'manifestifextended', + 'manifestiftagged', 'manifestkeywords', 'manifestlink', + 'manifestlinkurl', 'manifestmodifieddate', 'manifestmore', + 'manifestnext', 'manifestpermalink', 'manifestphoto', + 'manifestposttype', 'manifestprevious', 'manifestrank', + 'manifestrawposttype', 'manifestrecommendvotelink', 'manifestrecommendedtotal', + 'manifestscore', 'manifestscoreavg', 'manifestscorecount', + 'manifestscorehigh', 'manifestscorelow', 'manifeststatus', + 'manifesttags', 'manifesttitle', 'manifesttrackbackcount', + 'manifesttrackbackdata', 'manifesttrackbackid', 'manifesttrackbacklink', +); +foreach ($tags as $t) { + $p = new ManifestProxy($t); + $ctx->add_tag($t, array($p, 'tag')); +} + +class ManifestProxy { + var $tag; + function ManifestProxy($tag) { + $this->tag = str_replace('manifest', 'entry', strtolower($tag)); + } + + function tag($args, &$ctx) { + return $ctx->tag($this->tag, $args); + } +} diff --git a/php/load_object.pl b/php/load_object.pl new file mode 100644 index 0000000..903e4d2 --- /dev/null +++ b/php/load_object.pl @@ -0,0 +1,62 @@ +# Copyright (c) 2009 Movable Type ACME Plugin Project, All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +use strict; +use warnings; + +BEGIN { + use File::Basename; + chdir dirname(dirname(dirname(dirname(__FILE__)))); +} +use lib 'lib', 'extlib'; + +require MT::Bootstrap; +require MT; +use MT::Util qw( encode_php ); + +my $mt = MT->new() or die MT->errstr; + +$mt->{vtbl} = { }; +$mt->{is_admin} = 0; +$mt->{template_dir} = 'cms'; +$mt->{user_class} = 'MT::Author'; +$mt->{plugin_template_path} = 'tmpl'; +$mt->run_callbacks('init_app', $mt); + + +my ($model, $id, $revision) = @ARGV; +my $class = $mt->model($model); +my $obj = $class->load($id); + +my $rev = $obj->load_revision( + { rev_number => $revision } +); + +if ( $rev && @$rev ) { + $obj = $rev->[0]; +} + +print( + 'array(' . + join(",\n", + map("'$_' => '@{[ $obj->$_ ]}'", @{ &encode_php($obj->column_names) }) + ) . + ");\n" +); diff --git a/tmpl/config.tmpl b/tmpl/config.tmpl new file mode 100644 index 0000000..e9664c4 --- /dev/null +++ b/tmpl/config.tmpl @@ -0,0 +1,6 @@ +" +> +checked="checked" /> + -- 2.11.0