From 6d1e1cfe3137de3cb22127412787c23e2b8fd4c2 Mon Sep 17 00:00:00 2001 From: Kureha Hisame Date: Tue, 17 Sep 2013 23:35:24 +0900 Subject: [PATCH] - modified PluginManager module. - modified resize image library. --- common.rb | 1 - define.rb | 7 +++++++ feedgenerator.rb | 27 +++++++++++++++------------ filemanager.rb | 35 +++++++++++++++++++++++++++++------ resize.rb | 20 -------------------- 5 files changed, 51 insertions(+), 39 deletions(-) delete mode 100644 resize.rb diff --git a/common.rb b/common.rb index 45c38a3..3220a32 100644 --- a/common.rb +++ b/common.rb @@ -62,7 +62,6 @@ class HtmlWriter end end - # = Objectクラス # # 基本クラスのオーバーライドを行います diff --git a/define.rb b/define.rb index 6d566bc..4a554c5 100644 --- a/define.rb +++ b/define.rb @@ -53,6 +53,13 @@ LOG_DIR = "./logs/" # 開発用ログを出力するか? LOG_RELEASE_MODE = false +# ファイルマネージャ用設定 +# サムネイル画像の最大幅(縦・横共通)を指定 +THUMBS_SIZE = 150 +# 必要がある場合はrubygems, rmagickのLOADPATHを指定 +$LOAD_PATH.push("/home/lunardial/local/lib") +$LOAD_PATH.push("/home/lunardial/local/lib/ruby/gem/gems/rmagick-2.13.1/lib") + # バージョン情報を示す文字列です APPVERSION = "- FeedGenerator for Ruby version 4.0.0.0 -
Copyright(c) 2009 Kureha.H (http://lunardial.sakura.ne.jp/) & Yui Naruse (http://airemix.com/)" # タイトル領域に表示される文字列です diff --git a/feedgenerator.rb b/feedgenerator.rb index 9dc4724..57252eb 100644 --- a/feedgenerator.rb +++ b/feedgenerator.rb @@ -599,22 +599,25 @@ class FileUploader end end -# = Pluginクラス +# = PluginManagerクラス # # プラグインの処理を行うクラスです -class FeedGenPluginManager - def self.exec(mode, filepath) +class PluginManager + def self.exec(mode, module_name, filepath) feed = Feed.readxml(XMLPATH + filepath) entries = Entry.readxml(XMLPATH + filepath) feed.freeze entries.freeze Dir.foreach(PLUGINDIR) do |fn| - next unless File.extname(fn) == '.rb' - require File.join(PLUGINDIR, fn) - plugin_name = "FeedGenPlugins::" - plugin_name << File.basename(fn).gsub(/\.rb\Z/, "") - plugin_ins = plugin_name.split(/::/).inject(Object) { |c,name| c.const_get(name) } - plugin_ins.new.exec(mode, feed, entries) + begin + next unless File.extname(fn) == '.rb' + require File.join(PLUGINDIR, fn) + plugin_name = "#{module_name}::" + plugin_name << File.basename(fn).gsub(/\.rb\Z/, "") + plugin_ins = plugin_name.split(/::/).inject(Object) { |c,name| c.const_get(name) } + plugin_ins.new.exec(mode, feed, entries) + rescue + end end end end @@ -657,7 +660,7 @@ class Controller params["mode"] = "error" else # 成功時はプラグイン処理を実施する - FeedGenPluginManager.exec("newentry", File.basename(session["filepath"])) + PluginManager.exec("newentry", "FeedGenPlugins", File.basename(session["filepath"])) session["info"] = "記事の新規作成が成功しました。" end # 画面を戻った際の処理 @@ -694,7 +697,7 @@ class Controller params["mode"] = "error" else # 成功時はプラグイン処理を実施する - FeedGenPluginManager.exec("editentry", File.basename(session["filepath"])) + PluginManager.exec("editentry", "FeedGenPlugins", File.basename(session["filepath"])) session["info"] = "記事の編集が完了しました。" # 一覧を更新後の内容で更新する。 @@ -729,7 +732,7 @@ class Controller params["mode"] = "error" else # 成功時はプラグイン処理を実施する - FeedGenPluginManager.exec("delentry", File.basename(session["filepath"])) + PluginManager.exec("delentry", "FeedGenPlugins", File.basename(session["filepath"])) session["info"] = "記事の削除に成功しました。" # 内容を更新する diff --git a/filemanager.rb b/filemanager.rb index 7005ef5..f224b9a 100644 --- a/filemanager.rb +++ b/filemanager.rb @@ -275,6 +275,25 @@ class WebFiler end +# = PluginManagerクラス +# +# プラグインの処理を行うクラスです +class PluginManager + def self.exec(mode, module_name, filename, filepath) + Dir.foreach(PLUGINDIR) do |fn| + begin + next unless File.extname(fn) == '.rb' + require File.join(PLUGINDIR, fn) + plugin_name = "#{module_name}::" + plugin_name << File.basename(fn).gsub(/\.rb\Z/, "") + plugin_ins = plugin_name.split(/::/).inject(Object) { |c,name| c.const_get(name) } + plugin_ins.new.exec(mode, filename, filepath) + rescue + end + end + end +end + # = Controllerクラス # # コントローラ部分に相当する処理を受け持つクラスです @@ -319,14 +338,15 @@ class Controller end filer.upload(cgi["updata"], upload_filename) - # 独自改造 開始 + + # サムネイル作成開始 if params["thumbs"] == "true" and File.extname(upload_filename) =~ /\.(jpg|JPG|png|PNG)\Z/ begin - require('./resize.rb') + require('./plugins/ResizeManager.rb') if filer.relpath_list.size == 0 - ResizeManager.create_thumbs(IMGPATH + upload_filename) + ResizeManager::ResizeManager.create_thumbs(IMGPATH + upload_filename) else - ResizeManager.create_thumbs(IMGPATH + filer.relpath_list.join("/") + "/" + upload_filename) + ResizeManager::ResizeManager.create_thumbs(IMGPATH + filer.relpath_list.join("/") + "/" + upload_filename) end rescue LoadError # With no action @@ -337,18 +357,21 @@ class Controller end end # 独自改造 終了 + rescue FileExistedException session["error"] = "既に同名のファイルが存在します!" rescue WebSecurityException session["error"] = "ファイル名に使用できない文字列が含まれています!" end + + else session["error"] = "ファイルの容量が大きすぎます!" end # ファイル一覧を更新 - Controller.update_session(session, filer); - + Controller.update_session(session, filer) + session["info"] = "正常にファイル(#{upload_filename})のアップロードが完了しました。" if session["error"] == "" # 移動時 diff --git a/resize.rb b/resize.rb deleted file mode 100644 index 932ea56..0000000 --- a/resize.rb +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/local/bin/ruby -# -*- coding: utf-8 -*- - -THUMBS_SIZE = 150 - -class ResizeManager - def self.create_thumbs(fname) - $LOAD_PATH.push("/home/lunardial/local/lib") - $LOAD_PATH.push("/home/lunardial/local/lib/ruby/gem/gems/rmagick-2.13.1/lib") - - require 'rubygems' - require 'RMagick' - - img = Magick::Image.read(fname).first - - img.resize_to_fit!(THUMBS_SIZE, THUMBS_SIZE) - thumbs_name = fname.gsub(/#{File.extname(fname)}\Z/, "") + "_thumbs" + File.extname(fname) - img.write(thumbs_name) - end -end -- 2.11.0