# emoddy plugin for Movable Type # 2007/6/7 Version 1.0 # Copyright (c) 2007, emoddy # Author: Atsushi IMAKI & Takashi Hirasawa & Masato Mannen package MT::Plugin::emoddy; use base 'MT::Plugin'; use strict; use MT; use MT::Template::Context; use MT::Plugin; my $plugin = MT::Plugin::emoddy->new({ name => 'emoddy', version => '1.0', doc_link => 'http://css-happylife.com/log/movabletype-plugin/000158.shtml', author_name => 'emoddy', author_link => 'http://css-happylife.com/log/movabletype-plugin/000158.shtml', description => 'Displays the EMOJI to your blog.', settings => new MT::PluginSettings([ ['dir_emoji'], ['url_emoji'], ['tag_emoji'] ]), config_template => \&config_template }); MT->add_plugin($plugin); MT::Template::Context->add_global_filter(emoddy => \&emoddy); MT->add_callback('bigpapi::template::edit_entry', 9, $plugin, \&list_icon); if (MT->version_number >= 3.3) { MT->add_callback('MT::App::CMS::AppTemplateSource.edit_entry', 9, $plugin, \&list_icon); } sub config_template { my $plugin = shift; my ($param, $scope) = @_; my $val_tag_system = $plugin->get_config_value('tag_emoji', 'system'); if ($scope eq 'system') { return <

ICON SITE URL

ex: http://www.example.com/emoddy_icons/

ICON SITE PATH

ex: /home/melody/public_html/emoddy_icons

checked="checked" /> Use emoddy tag

HERE } else { my $code_tag; if (!$val_tag_system) { $code_tag = 'checked="checked" /> '; } return <

ICON PATH

ex: img/emoddy_icons/

${code_tag}Use emoddy tag

HERE } } # list_icon sub list_icon { my ($cb, $app, $template) = @_; my $blog_id = $app->param('blog_id'); my $dir_emoddy = $plugin->get_config_value('dir_emoji', 'blog:' . $blog_id); my ($dir_icon,$url_icon); if (!$dir_emoddy) { $dir_icon = $plugin->get_config_value('dir_emoji', 'system'); $url_icon = $plugin->get_config_value('url_emoji', 'system'); if (!$dir_icon) { return; } if (!$url_icon) { return; } $dir_icon .= '/'; } else { my $blog = MT::Blog->load($blog_id); my $dir_blog = $blog->site_path; $dir_icon = $dir_blog.'/'.$dir_emoddy; my $url_blog = $blog->site_url; $url_icon = $url_blog.$dir_emoddy; } unless(-e $dir_icon.'bn_emoddy.gif') { return; } opendir(DIR, $dir_icon); my @files_icon = readdir(DIR); closedir(DIR); @files_icon = sort @files_icon; my $pict_emoddy = $url_icon.'bn_emoddy.gif'; my $list_icon; my $list_icon_more; foreach (@files_icon) { if (($_ ne 'bn_emoddy.gif') && ($_ =~ /(.+)(.gif)/)) { $_ =~ s/(.+)(\.\w+)/$1$2/; $list_icon .= ''; $list_icon_more .= ''; } } if (!$list_icon) { return; } my $val_tag_system = $plugin->get_config_value('tag_emoji', 'system'); my $js_input_tag; if ($val_tag_system == 1) { $js_input_tag = "''"; } else { my $val_tag_blog = $plugin->get_config_value('tag_emoji', 'blog:' . $blog_id); if ($val_tag_blog) { $js_input_tag = "''"; } else { $js_input_tag = '\'icon:\' + v + \'\''; } } my $old = <
HTMLNEW $$template =~ s/$old/$new/; $old = <
HTMLNEW $$template =~ s/$old/$new/; $old = < HTMLOLD $new = < HTMLNEW $$template =~ s/$old/$new/; $old = < HTMLOLD $new = < HTMLNEW $$template =~ s/$old/$new/; } # Emoddy icon show sub emoddy { my ($text, $arg, $ctx) = @_; if ($arg != 1) { return $text; } my $blog = $ctx->stash('blog'); my $dir_emoddy = $plugin->get_config_value('dir_emoji', 'blog:' . $blog->id); my $url_icon; if (!$dir_emoddy) { $url_icon = $plugin->get_config_value('url_emoji', 'system'); if (!$url_icon) { return $text; } } else { my $url_blog = $blog->site_url; $url_icon = $url_blog.$dir_emoddy; } $text =~ s//icon:$1/gs; $text; } 1;