• R/O
  • HTTP
  • SSH
  • HTTPS

feedgenerator: Commit

rubyで構築された、Atom Feedの管理ツールです


Commit MetaInfo

Revision5875352444851255d99d99001fbd05b4ec7ccce7 (tree)
Time2011-07-07 16:38:08
Authorelixirel <elixirel@sour...>
Commiterelixirel

Log Message

- Plugin function added.
- Multi login added.

Change Summary

Incremental Difference

--- a/erbtemp/login.html.erb
+++ b/erbtemp/login.html.erb
@@ -31,10 +31,7 @@
3131 </td>
3232 </tr>
3333 </tbody>
34- </table><% if (cgi["loginid"] != LOGINID || cgi["password"] != PASSWORD) && (cgi["loginid"] != "" || cgi["password"] != "") %>
35- <br>
36- <span style="color: #ff0000">ID/PASSWORDが違います!</span>
37- <% end %>
34+ </table>
3835 <br>
3936 <input type="submit" value="submit">
4037 <br>
--- a/erbtemp/stylesheet.css
+++ b/erbtemp/stylesheet.css
@@ -11,6 +11,7 @@ body {
1111 text-align: center;
1212 margin-left: auto;
1313 margin-right: auto;
14+ -webkit-text-size-adjust: none;
1415 }
1516
1617 table {
--- a/feedgenerator.rb
+++ b/feedgenerator.rb
@@ -17,10 +17,10 @@ require 'time'
1717 require "date"
1818 require "fileutils"
1919
20-# ログインID
21-LOGINID = "login"
22-# ログインパスワード
23-PASSWORD = "password"
20+# ログイン情報配列
21+LOGININFO = [
22+{:id => "login", :password => "password", :name => "テストユーザ"}
23+]
2424 # インターフェースのテーブルの幅
2525 TABLEWIDTH = 1000
2626 # XMLファイル格納先までの相対パス
@@ -45,11 +45,8 @@ REPLACEBRTAG = false
4545 REPLACEENTRYIDANDURL = false
4646 # プラグインディレクトリ
4747 PLUGINDIR = "./plugins/"
48-
49-# EXPERIMENTAL AREA START
50-TO_HTML_ENTRYTEMPLATE = 'htmltemp/diary.html.erb'
51-TO_HTML_MAINTEMPLATE = 'htmltemp/main.html.erb'
52-# EXPERIMENTAL AREA END
48+# 記事用初期ファイル名
49+INITIALXML = "diary.xml"
5350
5451 # バージョン情報を示す文字列です
5552 APPVERSION = "- FeedGenerator for Ruby version 2.0.0.0 -<br>Copyright(c) 2009 Kureha.H (<a href=\"http://lunardial.sakura.ne.jp/\" target=\"_blank\">http://lunardial.sakura.ne.jp/</a>) & Yui Naruse (<a href=\"http://airemix.com/\" target=\"_blank\">http://airemix.com/</a>)"
@@ -71,10 +68,10 @@ class Object
7168 mode = arg[1]
7269 rdonly_p = true
7370 case mode
74- when String
71+ when String
7572 arg[1] = mode[/[^:]+/] if RUBY_VERSION < "1.8.7" && mode.include?(':')
7673 rdonly_p = /\A[^:]*[wa+]/ !~ mode
77- when Numeric
74+ when Numeric
7875 rdonly_p = !(mode & (IO::WRONY | IO::RDWR))
7976 end
8077 open(*arg) do |f|
@@ -229,20 +226,20 @@ class Feed < AbstractEntry
229226 elm.elements.each { |child|
230227 begin
231228 case child.name
232- when "id"
229+ when "id"
233230 xml[:feedid] = child.text
234- when "title", "subtitle", "updated", "rights"
231+ when "title", "subtitle", "updated", "rights"
235232 xml[child.name.to_sym] = child.text
236- when "author"
233+ when "author"
237234 child.elements.each do |gchild|
238235 case gchild.name
239- when "name"
236+ when "name"
240237 xml[:aname] = gchild.text
241- when "email"
238+ when "email"
242239 xml[:amail] = gchild.text
243240 end
244241 end
245- when "link"
242+ when "link"
246243 child.attributes.each do |k, v|
247244 if k == "rel"
248245 if v == "self"
@@ -252,7 +249,7 @@ class Feed < AbstractEntry
252249 end
253250 end
254251 end
255- when "entry"
252+ when "entry"
256253 # Entry要素は無視します
257254 else
258255 # 上記判定以外の全要素は配列に格納します
@@ -398,11 +395,11 @@ class Entry < AbstractEntry
398395 elm.elements.each do |child|
399396 begin
400397 case child.name
401- when "id"
398+ when "id"
402399 xml[:entryid] = child.text
403- when "link"
400+ when "link"
404401 xml[:url] = child.attributes["href"]
405- when "title", "summary", "summary", "published", "updated", "content"
402+ when "title", "summary", "summary", "published", "updated", "content"
406403 xml[child.name.to_sym] = child.text
407404 else
408405 # 上記判定以外の全要素は配列に格納します
@@ -625,9 +622,9 @@ class LogList
625622 doc.elements.each("list/file") { |elm|
626623 elm.elements.each {|child|
627624 case child.name
628- when "display"
625+ when "display"
629626 @display.push(child.text)
630- when "path"
627+ when "path"
631628 @path.push(child.text)
632629 else
633630 # With no action
@@ -697,16 +694,18 @@ end
697694 #
698695 # プラグインの処理を行うクラスです
699696 class FeedGenPluginManager
700- def self.exec(mode, feed, entry)
701- l_feed = feed.dup.freeze
702- l_entry = entry.dup.freeze
697+ def self.exec(mode, filepath)
698+ feed = Feed.readxml(XMLPATH + filepath)
699+ entries = Entry.readxml(XMLPATH + filepath)
700+ feed.freeze
701+ entries.freeze
703702 Dir.foreach(PLUGINDIR) do |fn|
704703 next unless File.extname(fn) == '.rb'
705704 require File.join(PLUGINDIR, fn)
706705 plugin_name = "FeedGenPlugins::"
707706 plugin_name << File.basename(fn).gsub(/\.rb\Z/, "")
708707 plugin_ins = plugin_name.split(/::/).inject(Object) { |c,name| c.const_get(name) }
709- plugin_ins.new.exec(mode, l_feed, l_entry)
708+ plugin_ins.new.exec(mode, feed, entries)
710709 end
711710 end
712711 end
@@ -724,7 +723,7 @@ class Controller
724723 # + ... and more
725724 case params["mode"]
726725 # ログ選択画面
727- when "logselect"
726+ when "logselect"
728727 session["filepath"] = params["logpath"]
729728 db["loglist"] = LogList.readxml(LISTXMLPATH)
730729 # 初期状態で選択されるログは「loglist.xml」の最上に位置するログになります
@@ -733,15 +732,15 @@ class Controller
733732 db["entry"] = Entry.readxml(XMLPATH + File.basename(session["filepath"]))
734733
735734 # 新規記事追加部分
736- when "newentry"
735+ when "newentry"
737736 case params["action"]
738737 # 確認画面
739- when "confirm"
738+ when "confirm"
740739 session["target_filepath"] = params["target_filepath"]
741740 db["newentry"] = Entry.new(params)
742741 db["newentry"].content = db["newentry"].content_for_blog
743742 # 記事の追記を実際にファイルに反映
744- when "exec"
743+ when "exec"
745744 session["target_filepath"] = params["target_filepath"]
746745 successed = Entry.insert(XMLPATH + File.basename(params["target_filepath"]), Entry.new(params))
747746 unless successed
@@ -749,10 +748,10 @@ class Controller
749748 params["mode"] = "error"
750749 else
751750 # 成功時はプラグイン処理を実施する
752- FeedGenPluginManager.exec("newentry", db["feed"], Entry.new(params))
751+ FeedGenPluginManager.exec("newentry", File.basename(session["filepath"]))
753752 end
754753 # 画面を戻った際の処理
755- when "back"
754+ when "back"
756755 session["target_filepath"] = params["target_filepath"]
757756 db["newentry"] = Entry.new(params)
758757 else
@@ -763,21 +762,21 @@ class Controller
763762 end
764763
765764 # 記事編集部分
766- when "editentry"
765+ when "editentry"
767766 case params["action"]
768767 # 編集画面
769- when "edit"
768+ when "edit"
770769 session["target_filepath"] = params["target_filepath"]
771770 session["editid"] = cgi["editid"].to_s
772771 db["editentry"] = Entry.select(XMLPATH + File.basename(session["target_filepath"]), session["editid"])
773772 # 確認画面
774- when "confirm"
773+ when "confirm"
775774 session["target_filepath"] = params["target_filepath"]
776775 session["editid"] = cgi["editid"].to_s
777776 db["editentry"] = Entry.new(params)
778777 db["editentry"].content = db["editentry"].content_for_blog
779778 # 記事の変更を実際にファイルに反映
780- when "exec"
779+ when "exec"
781780 session["target_filepath"] = params["target_filepath"]
782781 successed = Entry.update(XMLPATH + File.basename(params["target_filepath"]), Entry.new(params))
783782 unless successed
@@ -785,9 +784,9 @@ class Controller
785784 params["mode"] = "error"
786785 else
787786 # 成功時はプラグイン処理を実施する
788- FeedGenPluginManager.exec("editentry", db["feed"], Entry.new(params))
787+ FeedGenPluginManager.exec("editentry", File.basename(session["filepath"]))
789788 end
790- when "back"
789+ when "back"
791790 session["target_filepath"] = params["target_filepath"]
792791 db["editentry"] = Entry.new(params)
793792 else
@@ -798,22 +797,25 @@ class Controller
798797 end
799798
800799 # 記事削除部分
801- when "delentry"
800+ when "delentry"
802801 case params["action"]
803802 # 確認画面
804- when "confirm"
803+ when "confirm"
805804 session["target_filepath"] = params["target_filepath"]
806805 session["delid"] = cgi["delid"].to_s
807806 db["delentry"] = Entry.select(XMLPATH + File.basename(session["target_filepath"]), session["delid"])
808807 # 記事の削除を実際にファイルに反映
809- when "exec"
808+ when "exec"
810809 session["target_filepath"] = params["target_filepath"]
811810 successed = Entry.delete(XMLPATH + File.basename(params["target_filepath"]), cgi["delid"].to_s)
812811 unless successed
813812 db["error"] = "日記の編集処理に失敗しました。<br>該当の日記が既に存在しない可能性があります。"
814813 params["mode"] = "error"
814+ else
815+ # 成功時はプラグイン処理を実施する
816+ FeedGenPluginManager.exec("delentry", File.basename(session["filepath"]))
815817 end
816- when "back"
818+ when "back"
817819 session["target_filepath"] = params["target_filepath"]
818820 db["feed"] = Feed.readxml(XMLPATH + File.basename(session["target_filepath"]))
819821 db["entry"] = Entry.readxml(XMLPATH + File.basename(session["target_filepath"]))
@@ -825,17 +827,17 @@ class Controller
825827 end
826828
827829 # Feed情報変更部分
828- when "editfeed"
830+ when "editfeed"
829831 case params["action"]
830832 # 確認画面
831- when "confirm"
833+ when "confirm"
832834 session["target_filepath"] = params["target_filepath"]
833835 db["feed"] = Feed.new(params)
834836 # 実際にFeed情報の変更をファイルに反映
835- when "back"
837+ when "back"
836838 session["target_filepath"] = params["target_filepath"]
837839 db["feed"] = Feed.new(params)
838- when "exec"
840+ when "exec"
839841 session["target_filepath"] = params["target_filepath"]
840842 Feed.update(XMLPATH + File.basename(params["target_filepath"]), Feed.new(params))
841843 else
@@ -844,12 +846,12 @@ class Controller
844846 end
845847
846848 # ログ編集モード
847- when "log"
849+ when "log"
848850 # 必ず内部データをリフレッシュする
849851 db["loglist"] = LogList.readxml(LISTXMLPATH)
850852 case params["action"]
851853 # ログファイルの編集を実際にファイルに反映
852- when "addexec"
854+ when "addexec"
853855 # エラーチェック。この段階のエラーは強度のエラーを発する。
854856 db["loglist"].path.each do |val|
855857 if val == cgi["logpath"]
@@ -873,7 +875,7 @@ class Controller
873875 # 新たなdiary.xmlを生成。この際保持する情報は同一のFeedオブジェクトnew()
874876 Feed.to_xml(XMLPATH + File.basename(db["loglist"].path[0]), db["feed"], [])
875877 # 確認画面
876- when "addconfirm"
878+ when "addconfirm"
877879 # 入力されたログが既に存在するかを確認
878880 db["loglist"].path.each do |val|
879881 if val == cgi["logpath"]
@@ -890,10 +892,10 @@ class Controller
890892 if db["logpath"].blank? || db["logdisplay"].blank?
891893 params["action"] = ""
892894 end
893- when "back"
895+ when "back"
894896
895897 # 削除確認画面
896- when "delconfirm"
898+ when "delconfirm"
897899 db["logdelindex"] = params["logdelindex"].to_i
898900
899901 if db["logdelindex"] < 1
@@ -901,7 +903,7 @@ class Controller
901903 params["action"] = ""
902904 end
903905 # 削除処理
904- when "delexec"
906+ when "delexec"
905907 if cgi["logdelindex"].to_i < 1
906908 params["action"] = ""
907909 params["mode"] = "error"
@@ -920,7 +922,7 @@ class Controller
920922 end
921923
922924 # 編集画面
923- when "edit"
925+ when "edit"
924926 db["logeditindex"] = params["logdelindex"].to_i
925927
926928 db["logpath"] = db["loglist"].path[db["logeditindex"]]
@@ -931,7 +933,7 @@ class Controller
931933 params["action"] = ""
932934 end
933935 # 編集確認画面
934- when "editconfirm"
936+ when "editconfirm"
935937 checkflag = true
936938 db["loglist"].path.each_with_index do |val, i|
937939 if db["logeditindex"] != i
@@ -951,7 +953,7 @@ class Controller
951953 db["logdisplay"] = params["logdisplay"].to_s
952954 end
953955 # 編集実行
954- when "editexec"
956+ when "editexec"
955957 checkflag = true
956958 db["loglist"].path.each_with_index do |val, i|
957959 if db["logeditindex"] != i
@@ -998,14 +1000,14 @@ class Controller
9981000 end
9991001
10001002 # インポートモードの場合の処理
1001- when "import"
1003+ when "import"
10021004 db["loglist"] = LogList.readxml(LISTXMLPATH)
10031005
10041006 # リセットモードの場合の処理
1005- when "reset"
1007+ when "reset"
10061008 case params["action"]
10071009 # リセット実行時の処理
1008- when "exec"
1010+ when "exec"
10091011 file = FileUploader.new
10101012 file.filelist().each { |fname|
10111013 file.delete(fname) if File.ftype(XMLPATH + fname) == "file"
@@ -1013,7 +1015,7 @@ class Controller
10131015
10141016 # 全ファイルの初期化を実行する
10151017 # loglist.xmlの初期化
1016- loglist = LogList.new(["最新の記事"], ["#{FEEDXMLDIR}diary.xml"], LISTXMLPATH)
1018+ loglist = LogList.new(["最新の記事"], ["#{FEEDXMLDIR}#{INITIALXML}"], LISTXMLPATH)
10171019 loglist.to_xml
10181020
10191021 db["loglist"] = LogList.readxml(LISTXMLPATH)
@@ -1044,7 +1046,7 @@ class Controller
10441046 # loglist.xmlが存在するかチェック
10451047 if File.exist?(LISTXMLPATH) == false
10461048 # なかった場合はloglist.xmlを自動生成
1047- loglist = LogList.new(["最新の記事"], ["#{FEEDXMLDIR}diary.xml"], LISTXMLPATH)
1049+ loglist = LogList.new(["最新の記事"], ["#{FEEDXMLDIR}#{INITIALXML}"], LISTXMLPATH)
10481050 loglist.to_xml
10491051 Feed.to_xml(XMLPATH + File.basename(loglist.path[0]), Feed.new({}), [])
10501052 end
@@ -1072,9 +1074,9 @@ class Controller
10721074 db["loglist"] = LogList.readxml(LISTXMLPATH)
10731075 case params["mode"]
10741076 # 特定位置に挿入する場合の処理
1075- when "insert"
1077+ when "insert"
10761078 case params["action"]
1077- when "exec"
1079+ when "exec"
10781080 # この段階のエラーに対しては強度のエラーを発する
10791081 checkflag = true
10801082 db["logpath"] = Controller.get_mpart_value(cgi["logpath"])
@@ -1122,7 +1124,7 @@ class Controller
11221124 db["feed"] = Feed.readxml(XMLPATH + File.basename(session["filepath"]))
11231125 db["entry"] = Entry.readxml(XMLPATH + File.basename(session["filepath"]))
11241126
1125- when "confirm"
1127+ when "confirm"
11261128 # 入力されたログファイルパスが既に存在するかを確認
11271129 checkflag = true
11281130 db["logpath"] = Controller.get_mpart_value(cgi["logpath"])
@@ -1172,9 +1174,9 @@ class Controller
11721174 end
11731175
11741176 # diary.xmlを入れ替える処理
1175- when "replace"
1177+ when "replace"
11761178 case params["action"]
1177- when "exec"
1179+ when "exec"
11781180 # この段階のエラーに対しては強度のエラーを発する
11791181 checkflag = true
11801182 db["logpath"] = Controller.get_mpart_value(cgi["logpath"])
@@ -1198,10 +1200,10 @@ class Controller
11981200 end
11991201
12001202 # diary.xmlを移動します
1201- FileUtils.move(XMLPATH + "diary.xml", XMLPATH + File.basename(db["logpath"]))
1203+ FileUtils.move(XMLPATH + INITIALXML, XMLPATH + File.basename(db["logpath"]))
12021204 # ファイルをアップロードします
12031205 file = FileUploader.new
1204- file.upload("diary.xml", db["importxml"])
1206+ file.upload(INITIALXML, db["importxml"])
12051207
12061208 # loglist.xmlを更新します
12071209 db["loglist"].path[1, 0] = db["logpath"]
@@ -1214,7 +1216,7 @@ class Controller
12141216 db["feed"] = Feed.readxml(XMLPATH + File.basename(session["filepath"]))
12151217 db["entry"] = Entry.readxml(XMLPATH + File.basename(session["filepath"]))
12161218
1217- when "confirm"
1219+ when "confirm"
12181220 # 入力されたログファイルパスが既に存在するかを確認
12191221 checkflag = true
12201222 db["logpath"] = Controller.get_mpart_value(cgi["logpath"])
@@ -1288,9 +1290,17 @@ def main
12881290 # コントローラー部分
12891291 # セッション管理
12901292 if session["login"] != "true"
1291- if (cgi["loginid"] == LOGINID && cgi["password"] == PASSWORD)
1292- session["login"] = "true"
1293-
1293+
1294+ # ログイン情報を確認
1295+ LOGININFO.each {|h|
1296+ if (cgi["loginid"] == h[:id] && cgi["password"] == h[:password])
1297+ session["login"] = "true"
1298+ session["name"] = h[:name]
1299+ break
1300+ end
1301+ }
1302+
1303+ if (session["login"] == "true")
12941304 # ワークフォルダの中をクリーンアップします
12951305 filelist = Dir::entries("./work")
12961306 # 削除条件 : 最終変更日時から1日(60*60*24sec)かつ、ファイルタイプがファイルの場合
@@ -1363,27 +1373,27 @@ def main
13631373 htmlwriter = HtmlWriter.new("./erbtemp/login.html.erb", binding)
13641374 else
13651375 case params["mode"]
1366- when "selectlog"
1376+ when "selectlog"
13671377 htmlwriter = HtmlWriter.new("./erbtemp/select.html.erb", binding)
1368- when "newentry"
1378+ when "newentry"
13691379 htmlwriter = HtmlWriter.new("./erbtemp/newentry.html.erb", binding)
1370- when "editentry"
1380+ when "editentry"
13711381 htmlwriter = HtmlWriter.new("./erbtemp/editentry.html.erb", binding)
1372- when "delentry"
1382+ when "delentry"
13731383 htmlwriter = HtmlWriter.new("./erbtemp/delentry.html.erb", binding)
1374- when "editfeed"
1384+ when "editfeed"
13751385 htmlwriter = HtmlWriter.new("./erbtemp/editfeed.html.erb", binding)
1376- when "log"
1386+ when "log"
13771387 htmlwriter = HtmlWriter.new("./erbtemp/log.html.erb", binding)
1378- when "insert"
1388+ when "insert"
13791389 htmlwriter = HtmlWriter.new("./erbtemp/insertfeed.html.erb", binding)
1380- when "replace"
1390+ when "replace"
13811391 htmlwriter = HtmlWriter.new("./erbtemp/replacefeed.html.erb", binding)
1382- when "import"
1392+ when "import"
13831393 htmlwriter = HtmlWriter.new("./erbtemp/indeximport.html.erb", binding)
1384- when "reset"
1394+ when "reset"
13851395 htmlwriter = HtmlWriter.new("./erbtemp/reset.html.erb", binding)
1386- when "error"
1396+ when "error"
13871397 htmlwriter = HtmlWriter.new("./erbtemp/error.html.erb", binding)
13881398 else
13891399 htmlwriter = HtmlWriter.new("./erbtemp/index.html.erb", binding)
@@ -1409,7 +1419,7 @@ begin
14091419 rescue => evar
14101420 # エラーが発生した場合、それを画面に表示します
14111421 detail = ("%s: %s (%s)\n" %
1412- [evar.backtrace[0], evar.message, evar.send('class')]) +
1413- evar.backtrace[1..-1].join("\n")
1422+ [evar.backtrace[0], evar.message, evar.send('class')]) +
1423+ evar.backtrace[1..-1].join("\n")
14141424 puts "content-type: text/html\n\n<plaintext>\n" + detail
14151425 end
--- a/htmltemp/diary.html.erb
+++ /dev/null
@@ -1,6 +0,0 @@
1-<tr>
2-<td><%= title %> / <%= date %></td>
3-</tr>
4-<tr>
5-<td><%= content %></td>
6-</tr>
\ No newline at end of file
--- a/htmltemp/main.html.erb
+++ /dev/null
@@ -1,10 +0,0 @@
1-<html>
2- <head>
3- <title>TESTING</title>
4- </head>
5- <body>
6- <table>
7- <%= body %>
8- </table>
9- </body>
10-</html>
\ No newline at end of file
Show on old repository browser