tdiary-contrib 3.2.2.20130518
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +35 -0
- data/README.en.md +12 -0
- data/README.md +13 -0
- data/Rakefile +41 -0
- data/doc/en/filter/spambayes.txt +3 -0
- data/doc/en/plugin.txt +1 -0
- data/doc/en/style/hatena.txt +10 -0
- data/doc/en/style/markdown.txt +16 -0
- data/doc/en/util.txt +1 -0
- data/doc/ja/filter/antirefspam.history.txt +59 -0
- data/doc/ja/filter/antirefspam.txt +86 -0
- data/doc/ja/filter/comment_key.ja.html +182 -0
- data/doc/ja/filter/spambayes.txt +3 -0
- data/doc/ja/plugin/add_bookmark.txt +50 -0
- data/doc/ja/plugin/category_to_tag.txt +21 -0
- data/doc/ja/plugin/cocoment.txt +31 -0
- data/doc/ja/plugin/google_adsense.txt +25 -0
- data/doc/ja/plugin/google_analytics.txt +7 -0
- data/doc/ja/plugin/image_detail.txt +69 -0
- data/doc/ja/plugin/image_gps.txt +36 -0
- data/doc/ja/plugin/image_gps2.txt +41 -0
- data/doc/ja/plugin/livedoor_weather.txt +105 -0
- data/doc/ja/plugin/opensearch_ad.txt +16 -0
- data/doc/ja/plugin/section_footer.txt +84 -0
- data/doc/ja/plugin/select_theme.txt +1 -0
- data/doc/ja/plugin.txt +13 -0
- data/doc/ja/style/hatena.txt +10 -0
- data/doc/ja/style/markdown.txt +13 -0
- data/doc/ja/util.txt +12 -0
- data/filter/antirefspam.rb +263 -0
- data/filter/commentkey.rb +29 -0
- data/filter/commentsize.rb +18 -0
- data/filter/hidecomment.rb +13 -0
- data/filter/iplookup.rb +55 -0
- data/filter/plugin/antirefspam.rb +59 -0
- data/filter/plugin/commentkey.rb +58 -0
- data/filter/plugin/commentsize.rb +12 -0
- data/filter/plugin/en/iplookup.rb +9 -0
- data/filter/plugin/en/spambayes.rb +123 -0
- data/filter/plugin/iplookup.rb +39 -0
- data/filter/plugin/ja/antirefspam.rb +91 -0
- data/filter/plugin/ja/commentkey.rb +17 -0
- data/filter/plugin/ja/commentsize.rb +6 -0
- data/filter/plugin/ja/iplookup.rb +9 -0
- data/filter/plugin/ja/spambayes.rb +124 -0
- data/filter/plugin/spambayes.rb +501 -0
- data/filter/plugin/zh/iplookup.rb +9 -0
- data/filter/rblcheck.rb +36 -0
- data/filter/spambayes.rb +535 -0
- data/filter/spamlookup.rb +37 -0
- data/io/dbi_io/ChangeLog +19 -0
- data/io/dbi_io/README.ja +39 -0
- data/io/dbi_io/dbi_io.rb +181 -0
- data/io/dbi_io/plugin/refererDbiIO.rb +76 -0
- data/io/dbi_io/tdiary_table.sql +42 -0
- data/js/appstore.js +109 -0
- data/js/datepicker.js +69 -0
- data/js/editor.js +82 -0
- data/js/flickr.js +157 -0
- data/js/image_ex.js +79 -0
- data/js/jquery.socialbutton.js +842 -0
- data/js/nicovideo.js +17 -0
- data/js/picasa.js +322 -0
- data/js/plugin_checker.js +71 -0
- data/js/prettify/lang-apollo.js +2 -0
- data/js/prettify/lang-clj.js +18 -0
- data/js/prettify/lang-css.js +2 -0
- data/js/prettify/lang-go.js +1 -0
- data/js/prettify/lang-hs.js +2 -0
- data/js/prettify/lang-lisp.js +3 -0
- data/js/prettify/lang-lua.js +2 -0
- data/js/prettify/lang-ml.js +2 -0
- data/js/prettify/lang-n.js +4 -0
- data/js/prettify/lang-proto.js +1 -0
- data/js/prettify/lang-scala.js +2 -0
- data/js/prettify/lang-sql.js +2 -0
- data/js/prettify/lang-tex.js +1 -0
- data/js/prettify/lang-vb.js +2 -0
- data/js/prettify/lang-vhdl.js +3 -0
- data/js/prettify/lang-wiki.js +2 -0
- data/js/prettify/lang-xq.js +3 -0
- data/js/prettify/lang-yaml.js +2 -0
- data/js/prettify/prettify.css +1 -0
- data/js/prettify/prettify.js +28 -0
- data/js/referer.js +17 -0
- data/js/show_and_hide.js +39 -0
- data/js/socialbutton.js +126 -0
- data/js/twitter_anywhere.js +28 -0
- data/js/yahoo_kousei.js +21 -0
- data/lib/bayes/convert.rb +34 -0
- data/lib/bayes.rb +232 -0
- data/lib/exifparser/BUGS +1 -0
- data/lib/exifparser/ChangeLog +169 -0
- data/lib/exifparser/README +15 -0
- data/lib/exifparser/install.rb +1015 -0
- data/lib/exifparser/lib/exifparser/makernote/canon.rb +502 -0
- data/lib/exifparser/lib/exifparser/makernote/fujifilm.rb +415 -0
- data/lib/exifparser/lib/exifparser/makernote/minolta.rb +84 -0
- data/lib/exifparser/lib/exifparser/makernote/mk_nikonflensname.rb +39 -0
- data/lib/exifparser/lib/exifparser/makernote/nikon.rb +267 -0
- data/lib/exifparser/lib/exifparser/makernote/nikon2.rb +581 -0
- data/lib/exifparser/lib/exifparser/makernote/nikonflensname.rb +438 -0
- data/lib/exifparser/lib/exifparser/makernote/olympus.rb +225 -0
- data/lib/exifparser/lib/exifparser/makernote/prove.rb +84 -0
- data/lib/exifparser/lib/exifparser/makernote/sigma.rb +237 -0
- data/lib/exifparser/lib/exifparser/pre-setup.rb +1 -0
- data/lib/exifparser/lib/exifparser/scan.rb +278 -0
- data/lib/exifparser/lib/exifparser/tag.rb +2298 -0
- data/lib/exifparser/lib/exifparser/thumbnail.rb +76 -0
- data/lib/exifparser/lib/exifparser/utils.rb +88 -0
- data/lib/exifparser/lib/exifparser.rb +265 -0
- data/lib/exifparser/sample/exifview.rb +279 -0
- data/lib/tdiary-contrib.rb +19 -0
- data/lib/wgs2tky.rb +93 -0
- data/misc/section_footer2/buzzurl.yaml +6 -0
- data/misc/section_footer2/fc2.yaml +6 -0
- data/misc/section_footer2/ldc.yaml +6 -0
- data/misc/section_footer2/retweet.yaml +7 -0
- data/misc/section_footer2/twitter.yaml +7 -0
- data/misc/section_footer2/yahoo.yaml +6 -0
- data/misc/tdiarygraph/tdiarygraph120x90e.swf +0 -0
- data/misc/tdiarygraph/tdiarygraph125x125e.swf +0 -0
- data/misc/tdiarygraph/tdiarygraph240x180e.swf +0 -0
- data/misc/tdiarygraph/tdiarygraph468x60e.swf +0 -0
- data/misc/tdiarygraph/tdiarygraph728x90e.swf +0 -0
- data/misc/tdiarytimes/tdiarytimes125x125r.swf +0 -0
- data/misc/tdiarytimes/tdiarytimes125x125r7.swf +0 -0
- data/misc/tdiarytimes/tdiarytimes125x125s.swf +0 -0
- data/misc/tdiarytimes/tdiarytimes125x30.swf +0 -0
- data/misc/tdiarytimes/tdiarytimes234x30.swf +0 -0
- data/misc/tdiarytimes/tdiarytimes468x30.swf +0 -0
- data/plugin/add_bookmark.rb +89 -0
- data/plugin/apple_webclip.rb +26 -0
- data/plugin/appstore.rb +47 -0
- data/plugin/bigpresen.rb +86 -0
- data/plugin/bitly.rb +39 -0
- data/plugin/bootstrap-navi.rb +54 -0
- data/plugin/canonical.rb +9 -0
- data/plugin/category_similar.rb +73 -0
- data/plugin/category_to_tag.rb +60 -0
- data/plugin/category_to_tagcloud.rb +172 -0
- data/plugin/cocomment.rb +37 -0
- data/plugin/code-prettify.rb +23 -0
- data/plugin/coderwall.rb +34 -0
- data/plugin/datepicker.rb +28 -0
- data/plugin/day2section.rb +20 -0
- data/plugin/del_footer.rb +111 -0
- data/plugin/description_from_body.rb +23 -0
- data/plugin/development.rb +16 -0
- data/plugin/editor.rb +11 -0
- data/plugin/en/add_bookmark.rb +20 -0
- data/plugin/en/del_footer.rb +10 -0
- data/plugin/en/git-register.rb +3 -0
- data/plugin/en/livedoor_weather.rb +25 -0
- data/plugin/en/microsummary.rb +18 -0
- data/plugin/en/nicovideo.rb +38 -0
- data/plugin/en/openid.rb +8 -0
- data/plugin/en/section_footer.rb +6 -0
- data/plugin/en/section_footer2.rb +3 -0
- data/plugin/en/socialbutton.rb +5 -0
- data/plugin/everytrail.rb +39 -0
- data/plugin/facebook_comments.rb +59 -0
- data/plugin/flickr.rb +209 -0
- data/plugin/gist.rb +16 -0
- data/plugin/git-register.rb +240 -0
- data/plugin/github_badge.rb +27 -0
- data/plugin/github_link.rb +9 -0
- data/plugin/goo_gl.rb +42 -0
- data/plugin/google_adsense.rb +132 -0
- data/plugin/google_analytics.rb +39 -0
- data/plugin/google_map.rb +168 -0
- data/plugin/google_sitemaps.rb +60 -0
- data/plugin/google_webmaster.rb +22 -0
- data/plugin/hatena_bookmark_nocomment.rb +9 -0
- data/plugin/hatena_star.rb +66 -0
- data/plugin/hb_footer.rb +255 -0
- data/plugin/hb_footer4sec.rb +244 -0
- data/plugin/hb_footer4sec_js.rb +30 -0
- data/plugin/hide_comment_form.rb +4 -0
- data/plugin/hide_sidebar_iphone.rb +21 -0
- data/plugin/iddy.rb +81 -0
- data/plugin/image_detail.rb +143 -0
- data/plugin/image_ex.rb +462 -0
- data/plugin/image_gps.rb +128 -0
- data/plugin/inline_wiki.rb +6 -0
- data/plugin/instagr.rb +64 -0
- data/plugin/ja/add_bookmark.rb +20 -0
- data/plugin/ja/del_footer.rb +10 -0
- data/plugin/ja/flickr.rb +62 -0
- data/plugin/ja/git-register.rb +3 -0
- data/plugin/ja/google_sitemaps.rb +35 -0
- data/plugin/ja/livedoor_weather.rb +25 -0
- data/plugin/ja/microsummary.rb +18 -0
- data/plugin/ja/nicovideo.rb +41 -0
- data/plugin/ja/openid.rb +7 -0
- data/plugin/ja/section_footer.rb +6 -0
- data/plugin/ja/section_footer2.rb +4 -0
- data/plugin/ja/socialbutton.rb +6 -0
- data/plugin/jdate.rb +20 -0
- data/plugin/jholiday.rb +16 -0
- data/plugin/jmonth.rb +20 -0
- data/plugin/jquery_ui_theme.rb +55 -0
- data/plugin/jroku.rb +28 -0
- data/plugin/jyear.rb +37 -0
- data/plugin/latlonglab_route.rb +25 -0
- data/plugin/lazy_referer.rb +38 -0
- data/plugin/livedoor_weather.rb +180 -0
- data/plugin/make_link.rb +44 -0
- data/plugin/makerss_category.rb +43 -0
- data/plugin/makerss_comment.rb +35 -0
- data/plugin/microsummary.rb +62 -0
- data/plugin/mm_footer.rb +215 -0
- data/plugin/monthly_autopagerize.rb +67 -0
- data/plugin/my_hotentry.rb +132 -0
- data/plugin/navi_day.rb +118 -0
- data/plugin/navi_this_month.rb +15 -0
- data/plugin/nicovideo.rb +115 -0
- data/plugin/notify_miniblog.rb +134 -0
- data/plugin/ogp.rb +55 -0
- data/plugin/ohmsha_estore.rb +71 -0
- data/plugin/openid.rb +90 -0
- data/plugin/opensearch_ad.rb +33 -0
- data/plugin/picasa.rb +56 -0
- data/plugin/plugin_checker.rb +41 -0
- data/plugin/popit.rb +22 -0
- data/plugin/prettify.rb +19 -0
- data/plugin/prezi.rb +10 -0
- data/plugin/profile.rb +222 -0
- data/plugin/puboo.rb +93 -0
- data/plugin/pygments_css.rb +76 -0
- data/plugin/rating.rb +419 -0
- data/plugin/recent_estraier.rb +50 -0
- data/plugin/recent_tweet.rb +71 -0
- data/plugin/retweet.rb +86 -0
- data/plugin/rubykaigi.rb +99 -0
- data/plugin/search-bing.rb +87 -0
- data/plugin/search-default.rb +264 -0
- data/plugin/search-google-custom.rb +60 -0
- data/plugin/search-yahoo-websearch.rb +121 -0
- data/plugin/search-yahoo.rb +109 -0
- data/plugin/section_footer.rb +195 -0
- data/plugin/section_footer2.rb +278 -0
- data/plugin/section_permalink.rb +73 -0
- data/plugin/section_permalink_anchor.rb +39 -0
- data/plugin/select_style.rb +42 -0
- data/plugin/select_theme.rb +90 -0
- data/plugin/show_and_hide.rb +77 -0
- data/plugin/slideshare.rb +10 -0
- data/plugin/socialbutton.rb +60 -0
- data/plugin/tatsu_zine.rb +93 -0
- data/plugin/tdiarygraph_flashstyle.rb +296 -0
- data/plugin/tdiarytimes.rb +166 -0
- data/plugin/tdiarytimes2.rb +406 -0
- data/plugin/tdiarytimes_flashstyle.rb +263 -0
- data/plugin/tdiarytimes_textstyle.rb +290 -0
- data/plugin/title_anchor.rb +16 -0
- data/plugin/tweet_quote.rb +106 -0
- data/plugin/twitpic.rb +10 -0
- data/plugin/twitter.rb +46 -0
- data/plugin/twitter_anywhere.rb +209 -0
- data/plugin/twitter_badge.rb +42 -0
- data/plugin/twitter_js.rb +59 -0
- data/plugin/ustream.rb +19 -0
- data/plugin/vimeo.rb +14 -0
- data/plugin/volatile.rb +89 -0
- data/plugin/vote.rb +100 -0
- data/plugin/wikiloc.rb +27 -0
- data/plugin/windex.rb +512 -0
- data/plugin/yahoo_kousei.rb +79 -0
- data/plugin/yahoo_map.rb +97 -0
- data/plugin/youtube.rb +33 -0
- data/plugin/yshop.rb +189 -0
- data/plugin/zenback.rb +46 -0
- data/spec/apple_webclip_spec.rb +46 -0
- data/spec/fixtures/friendfeed.xml +2 -0
- data/spec/fixtures/github.json +1 -0
- data/spec/fixtures/twitter.xml +73 -0
- data/spec/gist_spec.rb +16 -0
- data/spec/github_link_spec.rb +39 -0
- data/spec/google_analytics_spec.rb +60 -0
- data/spec/jdate_spec.rb +23 -0
- data/spec/jmonth_spec.rb +28 -0
- data/spec/jyear_spec.rb +21 -0
- data/spec/my_hotentry_spec.rb +78 -0
- data/spec/openid_spec.rb +246 -0
- data/spec/opensearch_ad_spec.rb +50 -0
- data/spec/profile_spec.rb +88 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec_helper.rb +223 -0
- data/spec/title_anchor_spec.rb +39 -0
- data/spec/twitter_js_spec.rb +116 -0
- data/spec/youtube_spec.rb +20 -0
- data/style/hatena_style.rb +1011 -0
- data/style/markdown_style.rb +239 -0
- data/style/wikiext_style.rb +21 -0
- data/tdiary-contrib.gemspec +25 -0
- data/util/clean-spam/README.ja +1 -0
- data/util/clean-spam/tdiary-comment-clean +46 -0
- data/util/clean-spam/tdiary-comment-clean2 +81 -0
- data/util/clean-spam/tdiary-referer-clean +46 -0
- data/util/convert_pstore.rb +82 -0
- data/util/estraier-search/ChangeLog +36 -0
- data/util/estraier-search/README.ja +114 -0
- data/util/estraier-search/en/estraier-register.rb +3 -0
- data/util/estraier-search/estraier-register.rb +298 -0
- data/util/estraier-search/estraier-search.rb +273 -0
- data/util/estraier-search/estraier.rhtml +73 -0
- data/util/estraier-search/estraier.rxml +23 -0
- data/util/estraier-search/i.estraier.rhtml +31 -0
- data/util/estraier-search/ja/estraier-register.rb +3 -0
- data/util/image-gallery/README.ja +27 -0
- data/util/image-gallery/image-gallery.rb +523 -0
- data/util/image-gallery/image-gallery.rb.euc-jp +523 -0
- data/util/image-gallery/js/SmoothGallery/Changelog +52 -0
- data/util/image-gallery/js/SmoothGallery/css/ReMooz.css +186 -0
- data/util/image-gallery/js/SmoothGallery/css/img/carrow1.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/carrow2.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/closebox.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/closebox.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/fleche1.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/fleche1.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/fleche2.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/fleche2.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/loading-bar-black.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/open.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/open.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_e.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_n.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_ne.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_nw.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_s.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_se.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_sw.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/remo_bg_w.png +0 -0
- data/util/image-gallery/js/SmoothGallery/css/img/spinner.gif +0 -0
- data/util/image-gallery/js/SmoothGallery/css/jd.gallery.css +371 -0
- data/util/image-gallery/js/SmoothGallery/css/layout.css +91 -0
- data/util/image-gallery/js/SmoothGallery/license.txt +621 -0
- data/util/image-gallery/js/SmoothGallery/resizer.php +113 -0
- data/util/image-gallery/js/SmoothGallery/scripts/Changelog +52 -0
- data/util/image-gallery/js/SmoothGallery/scripts/History.Routing.js +126 -0
- data/util/image-gallery/js/SmoothGallery/scripts/History.js +109 -0
- data/util/image-gallery/js/SmoothGallery/scripts/ReMooz.js +364 -0
- data/util/image-gallery/js/SmoothGallery/scripts/jd.gallery.js +843 -0
- data/util/image-gallery/js/SmoothGallery/scripts/jd.gallery.set.js +183 -0
- data/util/image-gallery/js/SmoothGallery/scripts/jd.gallery.transitions.js +90 -0
- data/util/image-gallery/js/SmoothGallery/scripts/jdgalleryresize.js +828 -0
- data/util/image-gallery/js/SmoothGallery/scripts/license.txt +621 -0
- data/util/image-gallery/js/SmoothGallery/scripts/mootools-1.2-more.js +103 -0
- data/util/image-gallery/js/SmoothGallery/scripts/mootools-1.2.1-core-yc.js +349 -0
- data/util/image-gallery/js/SmoothGallery/scripts/resizer.php +113 -0
- data/util/image-gallery/misc/plugin/recent_image.rb +406 -0
- data/util/image-gallery/skel/gallery.rhtml +154 -0
- data/util/image-gallery/skel/gallery.rhtml.euc-jp +154 -0
- data/util/image-gallery/tdiary.conf.igsample +8 -0
- data/util/image-gallery/theme/image-gallery.css +85 -0
- data/util/image2flickr.rb +282 -0
- data/util/posttdiary/README.ja +12 -0
- data/util/posttdiary/posttdiary-ex.rb +1155 -0
- data/util/posttdiary/posttdiary.rb +245 -0
- data/util/rast-search/ChangeLog +55 -0
- data/util/rast-search/README.ja +99 -0
- data/util/rast-search/en/rast-register.rb +3 -0
- data/util/rast-search/i.rast.rhtml +33 -0
- data/util/rast-search/ja/rast-register.rb +3 -0
- data/util/rast-search/rast-register.rb +326 -0
- data/util/rast-search/rast-search.rb +249 -0
- data/util/rast-search/rast.rhtml +66 -0
- data/util/rast-search/rast.rxml +21 -0
- data/util/section_link/README +11 -0
- data/util/section_link/misc/plugin/section_link.rb +68 -0
- data/util/section_link/misc/plugin/section_link_anchor.rb +38 -0
- data/util/section_link/tdiary/tdiary_day_ext.rb +21 -0
- data/util/section_link/tdiary/tdiaryext_style.rb +36 -0
- data/util/section_link/tdiary/wikiext_style.rb +36 -0
- data/util/tdiary-for-ruby1.9/compatible.rb +97 -0
- data/util/tdiary-for-ruby1.9/tdiary-2.2.0.patch +98 -0
- data/util/tdiary-for-ruby1.9/tdiary-2.3.1.patch +212 -0
- data/util/tdiary-grep/README +4 -0
- data/util/tdiary-grep/grep.rb +445 -0
- data/util/tdiary-mode/http.el +130 -0
- data/util/tdiary-mode/tdiary-mode.el +613 -0
- data/util/tdiary-vim/ChangeLog +25 -0
- data/util/tdiary-vim/README +60 -0
- data/util/tdiary-vim/tdiary.vim +350 -0
- data/util/tdiarysearch/README.en +53 -0
- data/util/tdiarysearch/README.ja +99 -0
- data/util/tdiarysearch/search.rb +504 -0
- metadata +497 -0
@@ -0,0 +1,1155 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# posttdiary-ex: update tDiary via e-mail. $Revision: 1.2 $
|
4
|
+
#
|
5
|
+
# Copyright (C) 2002, All right reserved by TADA Tadashi <sho@spc.gr.jp>
|
6
|
+
# You can redistribute it and/or modify it under GPL2.
|
7
|
+
#
|
8
|
+
# 2010.10.19: v.1.71: Modified by K.Sakurai (http://ks.nwr.jp)
|
9
|
+
# Acknowledgements:
|
10
|
+
# * Based on posttdiary.rb & tdiary.rb by TADA.
|
11
|
+
# * Some codes partially imported from Enikki Plugin Ex. :
|
12
|
+
# http://shimoi.s26.xrea.com/hiki/hiki.cgi?TdiaryEnikkiEx
|
13
|
+
# * Thanks to taketori for image size detection method.
|
14
|
+
# * Thanks to NOB for debugging.
|
15
|
+
# * Thanks to tamo (http://tamo.tdiary.net) for image-POSTing codes & testing.
|
16
|
+
#
|
17
|
+
|
18
|
+
# language setup for tdiary.conf (for both @data_path & @tdiary_dirname)
|
19
|
+
@tdencoding = 'UTF-8'
|
20
|
+
# @tdencoding = 'US-ASCII'
|
21
|
+
# @tdencoding = 'EUC-JP'
|
22
|
+
# @tdencoding = 'Big5'
|
23
|
+
|
24
|
+
#----------------------------------------------
|
25
|
+
|
26
|
+
def usage( detailed_help )
|
27
|
+
# (if "!" is at the head of the line, it is to be shown only when detailed_help == true (-h option) )
|
28
|
+
text = <<-TEXT
|
29
|
+
#{File::basename __FILE__}: update tDiary via e-mail (v1.64).
|
30
|
+
usage: ruby posttdiary-ex.rb [options (without -d)] <url> <user> <passwd>
|
31
|
+
ruby posttdiary-ex.rb [options (with -d)]
|
32
|
+
arguments:
|
33
|
+
url: update.rb's URL of your diary
|
34
|
+
user: username for your tDiary system
|
35
|
+
passwd: password for your tDiary system
|
36
|
+
! If the To: field is formatted as "user-passwd@example.com",
|
37
|
+
! you can omit user and passwd arguments.
|
38
|
+
options:
|
39
|
+
! ============ for automatic configuration ==========
|
40
|
+
--read-conffile, -a dirname: read settings from (dirname)/tdiary.conf
|
41
|
+
! Reads configuration parameters of image_ex plugin as well.
|
42
|
+
! (The default values of -i, -u, -t, -z, -o, -y, -C can be imported.)
|
43
|
+
! Specify the localtion (or fullpathname) of tDiary conf file.
|
44
|
+
! ex. -a /home/hoge/htdocs/diary/tdiary.conf
|
45
|
+
!
|
46
|
+
! ============ basic options ==============
|
47
|
+
--image-path, -i dirname: directory to store the image(s) in.
|
48
|
+
--image-url, -u URL: URL of the image directory.
|
49
|
+
! You must specify both -i and -u options
|
50
|
+
! (unless they are available from tdiary.conf + image_ex plugin)
|
51
|
+
! When using --remote-mode or --use-image-ex, -u is not required.
|
52
|
+
--use-subject, -s: use mail subject as subtitle
|
53
|
+
! Also inserts attached image(s) between subtitle and body.
|
54
|
+
--make-thumbnail, -t size: Create thumbnail with a link to the original image
|
55
|
+
! Works only when the original image is larger than the specified size
|
56
|
+
! (see --threshold-size also)
|
57
|
+
! ex. -t 80x80
|
58
|
+
--image-geometry, -g size: resize image(s).
|
59
|
+
! The original image would be overwritten.
|
60
|
+
! Does not change the image size when the original image is smaller.
|
61
|
+
! ex. -g 800x800 (change the image size to "fit in" to 800x800 pixels)
|
62
|
+
--use-image-ex, -e: Recognize & auto-generate tags for image.rb (Enikki)
|
63
|
+
or image_ex.rb (Enikki ex.) plugin
|
64
|
+
! Tag format: <%=image (serialno),"(alt text)"%>
|
65
|
+
! Serialno starts from 0. Will be automatically increased to match
|
66
|
+
! the real filename.
|
67
|
+
! Overrides -f option.
|
68
|
+
--wiki-style, -w: output image tags in Wiki style
|
69
|
+
! Suppress adding a whitespace before each tag
|
70
|
+
! Adds "!" to subject when -s option is given
|
71
|
+
! Recognize Wiki style tags and rewrite
|
72
|
+
! Must be used with image.rb or image_ex.rb plugin.
|
73
|
+
--blog-style, -B: do not specify date to append unless specified
|
74
|
+
! Suitable for use with blogkit
|
75
|
+
--read-exif, -c: read "User Comment" tag from EXIF and use as ALT text
|
76
|
+
! If not specified, filename would be used as ALT text.
|
77
|
+
! Requires libexif and "exif" command.
|
78
|
+
--hour-offset, -o offset: hour_offset of tDiary
|
79
|
+
! (ex. -o +4 (do not change date until 28:00))
|
80
|
+
--yearly-dir, -y: put images in yearly separated directories
|
81
|
+
! ( 2004/ , 2005/ , ...)
|
82
|
+
--help, -h: show detailed help & advanced options
|
83
|
+
!
|
84
|
+
! ============ advanced options ==============
|
85
|
+
! --convert-path, -C fullpath_of_convert: location of "convert" command
|
86
|
+
! Use this option when ImageMagick's commands are not path-reachable.
|
87
|
+
! Assumes the same location for "identify" command as well.
|
88
|
+
! --exif-path, -E fullpath_of_exif: location of "exif" command
|
89
|
+
! Enables --read-exif command as well.
|
90
|
+
! Use this option when "exif" command is not path-reachable.
|
91
|
+
! --remote-mode, -R: upload images via update.rb using HTTP POST.
|
92
|
+
! Allows user to separate the mailserver and the webserver.
|
93
|
+
! Note: Thumbnails would not be posted.
|
94
|
+
! --remote-image-path,-D remote_dirname:
|
95
|
+
! Specify the image directory of the remote webserver.
|
96
|
+
! Required when using image_ex.rb with --remote-mode option.
|
97
|
+
! --remote-yearly-dir,-Y switch:
|
98
|
+
! Specify whether to put images in yearly separated directories
|
99
|
+
! at the remote webserver.
|
100
|
+
! Required when image_ex.rb with --remote-mode option.
|
101
|
+
! 0: do not separate, 1: separate
|
102
|
+
! --preserve-local-images, -P:
|
103
|
+
! Do not delete local image files.
|
104
|
+
! Effective only when --remote-mode is enabled.
|
105
|
+
! --upload-only, -U:
|
106
|
+
! Upload the attached images to server, but do not update the diary.
|
107
|
+
! Also possible by adding "_UPLONLY#" to mail body.
|
108
|
+
! --group-id, -G: specify the group name (or GID) of the image file.
|
109
|
+
! Also makes the file group writable (chmod 664).
|
110
|
+
! ex1. -G www
|
111
|
+
! ex2. -G 67
|
112
|
+
! --class-name, -n class_name:
|
113
|
+
! Class name for each photo (default: photo)
|
114
|
+
! Invalid when --use-image-ex or --wiki-style option is enabled.
|
115
|
+
! --add-div, -v number_of_images:
|
116
|
+
! Encapsule all attached images with <div class="photos">...</div>
|
117
|
+
! When specified number of (or more) images are attached.
|
118
|
+
! Set to 2 when not given. Specify 0 to disable.
|
119
|
+
! Automatically set to 0 when --wiki-style is enabled.
|
120
|
+
! ex. -v 3 (works only when 3 or more images are attached)
|
121
|
+
! --threshold-size, -z threshold_image_size:
|
122
|
+
! Make thumbnail if image size is larger.
|
123
|
+
! ex1. -z 120x140
|
124
|
+
! ex2. -z 140 (same to 140x140)
|
125
|
+
! --image-format, -f format string:
|
126
|
+
! Specify the format string of the image tag
|
127
|
+
! These variables can be used in the format string:
|
128
|
+
! $0 : image serial number
|
129
|
+
! $1 : image url
|
130
|
+
! $2 : thumbnail image url (when -t is specified)
|
131
|
+
! $3 : class name
|
132
|
+
! $4 : ALT text (filename, or EXIF comment when -c is specified)
|
133
|
+
! ex. -f \\\"{{image \\\$0}}\\\"
|
134
|
+
! --use-original-name, -r:
|
135
|
+
! use original filename as ALT text when not specified
|
136
|
+
! --pass-filename, -p:
|
137
|
+
! Pass real filename (instead of serialno) to image_ex plugin
|
138
|
+
! (EXPERIMENTAL: Has no meanings so far)
|
139
|
+
! Effective only with -e option.
|
140
|
+
! --filter-mode, -d: print to stdout (does not call update.rb)
|
141
|
+
! --write-to-file, -b filename: writeout to file (does not call update.rb)
|
142
|
+
! --date-margin, -j date_margin: avoid writing diaries for future dates
|
143
|
+
! ex. -j 30 (default=7, 0=disabled)
|
144
|
+
! --rotate, -T LEFT or RIGHT: rotate images
|
145
|
+
! ex. -T RIGHT (rotate 90degrees clockwise)
|
146
|
+
! Also possible by adding "_ROT_LEFT#" or "_ROT_RIGHT#"to mail body.
|
147
|
+
!
|
148
|
+
! Output format:
|
149
|
+
! without -e/f, without -t: <img src="$1" class="photo" alt="$4" title="$4">
|
150
|
+
! without -e/f, with -t: <A HREF="$1"><img src="$2" class="photo" alt="$4" title="$4"></a>
|
151
|
+
! with -e: <%=image $0,'$4'%>
|
152
|
+
! with -w: {{image $0,'$4'}} (overrides -e)
|
153
|
+
! with -f: (specified format) (overrides -e, -w)
|
154
|
+
!
|
155
|
+
! Date specification format in mail body text:
|
156
|
+
! ex. when you want to append this mail to "2005 Feb 15" 's diary,
|
157
|
+
! add this line to mail body:
|
158
|
+
!
|
159
|
+
! _Date#2005-2-15
|
160
|
+
!
|
161
|
+
Examples:
|
162
|
+
posttdiary-ex.rb -a /home/hoge/htdocs/diary/tdiary.conf http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd)
|
163
|
+
posttdiary-ex.rb -w -i /home/hoge/htdocs/diary-images/ -y -t 120x120 -s -g 800x800 http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd)
|
164
|
+
! posttdiary-ex.rb -i /home/hoge/htdocs/diary-images/ -u http://yoursite.jp/~hoge/diary-images/ -t 120x120 -s -g 800x800 http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd)
|
165
|
+
! posttdiary-ex.rb -R -i /home/hoge/tmp -D /home/hoge/htdocs/diary-images -Y 1 -s -g 800x800 http://yoursite.jp/~hoge/diary/update.rb (tDiary username) (passwd)
|
166
|
+
|
167
|
+
TEXT
|
168
|
+
if( detailed_help )
|
169
|
+
text.gsub!( /\!/, '' )
|
170
|
+
else
|
171
|
+
text.gsub!( /\![^\r\n]*[\r\n]+/, '' )
|
172
|
+
end
|
173
|
+
text.delete("\t")
|
174
|
+
end
|
175
|
+
|
176
|
+
#--- override functions in the original tdiary.rb
|
177
|
+
def base_url
|
178
|
+
return ''
|
179
|
+
end
|
180
|
+
|
181
|
+
def TDiaryError( msg )
|
182
|
+
print msg + "\n"
|
183
|
+
exit 0
|
184
|
+
end
|
185
|
+
|
186
|
+
def load_cgi_conf
|
187
|
+
raise TDiaryError, 'posttdiary-ex: No @data_path variable.' unless @data_path
|
188
|
+
@data_path = add_delimiter( @data_path )
|
189
|
+
raise TDiaryError, 'posttdiary-ex: Do not set @data_path as same as tDiary system directory.' if @data_path == @tdiary_dirname
|
190
|
+
def_vars1 = ''
|
191
|
+
def_vars2 = ''
|
192
|
+
variables = [:author_name, :author_mail, :index_page, :hour_offset]
|
193
|
+
variables.each do |var|
|
194
|
+
def_vars1 << "#{var} = nil\n"
|
195
|
+
def_vars2 << "@#{var} = #{var} unless #{var} == nil\n"
|
196
|
+
end
|
197
|
+
|
198
|
+
begin
|
199
|
+
cgi_conf = File::open( "#{@data_path}tdiary.conf" ){|f| f.read }
|
200
|
+
cgi_conf.untaint unless @secure
|
201
|
+
cgi_conf.force_encoding( @tdencoding )
|
202
|
+
b = binding.taint
|
203
|
+
eval( cgi_conf, b, "(cgi_conf)", 1 )
|
204
|
+
eval( def_vars2, b )
|
205
|
+
rescue IOError, Errno::ENOENT
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
#--- read tdiary.conf
|
210
|
+
def read_tdiary_conf( dfname )
|
211
|
+
if test( ?d , dfname ) then
|
212
|
+
@tdiary_dirname = dfname
|
213
|
+
@tdiary_conf_file = 'tdiary.conf'
|
214
|
+
elsif test( ?f , dfname ) then
|
215
|
+
dfname =~ /(.*)[\/\\]([^\/\\]+)/
|
216
|
+
@tdiary_dirname = $1
|
217
|
+
@tdiary_conf_file = $2
|
218
|
+
end
|
219
|
+
@tdiary_dirname = add_delimiter( @tdiary_dirname )
|
220
|
+
orgdir = Dir.pwd
|
221
|
+
Dir.chdir( @tdiary_dirname )
|
222
|
+
|
223
|
+
@secure = false
|
224
|
+
@options = {}
|
225
|
+
# evaluate tdiary.conf (load_cgi_conf() would be called as well, via tdiary.conf)
|
226
|
+
|
227
|
+
f = File::open( @tdiary_dirname + @tdiary_conf_file ){|f| f.read }.untaint.force_encoding(@tdencoding)
|
228
|
+
eval( f, binding, "(tdiary.conf)", 1 )
|
229
|
+
|
230
|
+
Dir.chdir( orgdir )
|
231
|
+
true;
|
232
|
+
|
233
|
+
rescue IOError, Errno::ENOENT
|
234
|
+
raise 'posttdiary-ex: failed to read tdiary configuration file'
|
235
|
+
end
|
236
|
+
|
237
|
+
def check_local_images( date, path )
|
238
|
+
available_list = []
|
239
|
+
exist_list = []
|
240
|
+
maxnum = -1
|
241
|
+
Dir.foreach( path ) do |file|
|
242
|
+
if file =~ /(\d{8,})_(\d+)\.([^\.]*)/ then
|
243
|
+
if $1 == date then
|
244
|
+
serial = $2.to_i
|
245
|
+
maxnum = serial if serial > maxnum
|
246
|
+
exist_list[serial]=true
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
num = 0
|
252
|
+
for i in 0 .. 200
|
253
|
+
if !exist_list[i] then
|
254
|
+
available_list[num] = i
|
255
|
+
num += 1
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
maxnum += 1
|
260
|
+
[maxnum, available_list]
|
261
|
+
end
|
262
|
+
|
263
|
+
def bmp_to_png( bmp )
|
264
|
+
png = bmp.sub( /\.bmp$/, '.png' )
|
265
|
+
stat = system( "#{@convertpath} #{bmp} #{png}" )
|
266
|
+
raise "posttdiary-ex: could not run convert command (#{@convertpath})" if !stat
|
267
|
+
if FileTest::exist?( png )
|
268
|
+
File::delete( bmp )
|
269
|
+
png
|
270
|
+
else
|
271
|
+
bmp
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def check_command( cmdname )
|
276
|
+
raise 'posttdiary-ex: program bug found in check_command() (call the programmer!)' unless cmdname
|
277
|
+
|
278
|
+
if @pt_exist_cmd then
|
279
|
+
for priv in @pt_exist_cmd
|
280
|
+
if priv == cmdname then
|
281
|
+
return true
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
stat = false
|
287
|
+
if ( test( ?x , cmdname ) ) then
|
288
|
+
stat = true
|
289
|
+
else
|
290
|
+
require 'shell'
|
291
|
+
sh = Shell.new
|
292
|
+
searchdir = sh.system_path
|
293
|
+
for dir in searchdir
|
294
|
+
fullpath = add_delimiter( dir ) + cmdname
|
295
|
+
if sh.executable?(fullpath) then
|
296
|
+
stat = true
|
297
|
+
break
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
if stat then
|
302
|
+
@pt_exist_cmd = [] unless @pt_exist_cmd
|
303
|
+
@pt_exist_cmd << cmdname
|
304
|
+
else
|
305
|
+
raise "posttdiary-ex: execution failed: #{cmdname} not found"
|
306
|
+
end
|
307
|
+
stat
|
308
|
+
end
|
309
|
+
|
310
|
+
def check_image_size( name, geo )
|
311
|
+
cmdstr = @magickpath + "identify"
|
312
|
+
check_command( cmdstr )
|
313
|
+
return false if !FileTest::exist?( name )
|
314
|
+
begin
|
315
|
+
imgsize = %x[#{cmdstr} '#{name}'].sub(/#{name}/, '').split[1][/\d+x\d+/]
|
316
|
+
i = imgsize.split(/x/)
|
317
|
+
j = geo.split(/x/)
|
318
|
+
return false if !i[1] or !j[1]
|
319
|
+
return false if i[0].to_i < j[0].to_i and i[1].to_i < j[1].to_i
|
320
|
+
|
321
|
+
rescue
|
322
|
+
return false
|
323
|
+
end
|
324
|
+
true
|
325
|
+
end
|
326
|
+
|
327
|
+
def change_image_size( org, geo )
|
328
|
+
check_command( @convertpath )
|
329
|
+
system( "#{@convertpath} -size #{geo}\\\> #{org} -geometry #{geo}\\\> #{org}" )
|
330
|
+
if FileTest::exist?( org )
|
331
|
+
org
|
332
|
+
else
|
333
|
+
""
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def read_exif_comment( fullpath_imgname )
|
338
|
+
require 'nkf'
|
339
|
+
v = ""
|
340
|
+
check_command( @exifpath )
|
341
|
+
return "" if !FileTest::exist?( fullpath_imgname )
|
342
|
+
open( "| #{@exifpath} -t \"User Comment\" #{fullpath_imgname}", "r" ) do |f|
|
343
|
+
s = f.readlines
|
344
|
+
s.each do |t|
|
345
|
+
t.gsub!( /.*Value:/, '' )
|
346
|
+
v = NKF::nkf( '-m0 -Xwd', t ).gsub!( /^\s+/, '' ).chomp! if $&
|
347
|
+
end
|
348
|
+
end
|
349
|
+
v = '' if v =~ /^\(null\)$/i
|
350
|
+
v
|
351
|
+
end
|
352
|
+
|
353
|
+
def read_exif_orientation( fullpath_imgname )
|
354
|
+
# returns orientaion value
|
355
|
+
# top-left : 1
|
356
|
+
# right-top : 6
|
357
|
+
# left-bottom : 8
|
358
|
+
# bottom-right : 3
|
359
|
+
val = 1
|
360
|
+
v = ''
|
361
|
+
check_command( @exifpath )
|
362
|
+
return 1 if !FileTest::exist?( fullpath_imgname )
|
363
|
+
open( "| #{@exifpath} -t \"Orientation\" #{fullpath_imgname}", "r" ) do |f|
|
364
|
+
s = f.readlines
|
365
|
+
s.each do |t|
|
366
|
+
t.gsub!( /.*Value:/, '' )
|
367
|
+
if $& then
|
368
|
+
v = t
|
369
|
+
break
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
val = 6 if v =~ /right.+top/i
|
374
|
+
val = 8 if v =~ /left.+bottom/i
|
375
|
+
val = 3 if v =~ /bottom.+right/i
|
376
|
+
val
|
377
|
+
end
|
378
|
+
|
379
|
+
def rotation_degree( ori )
|
380
|
+
deg = 0
|
381
|
+
deg = 90 if ori == 6
|
382
|
+
deg = -90 if ori == 8
|
383
|
+
deg = 180 if ori == 3
|
384
|
+
deg
|
385
|
+
end
|
386
|
+
|
387
|
+
def rotate_image( org, deg )
|
388
|
+
if FileTest::exist?( org ) then
|
389
|
+
check_command( @convertpath )
|
390
|
+
system( "#{@convertpath} -rotate #{deg} #{org} #{org}" )
|
391
|
+
end
|
392
|
+
if FileTest::exist?( org )
|
393
|
+
org
|
394
|
+
else
|
395
|
+
""
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
def make_thumbnail( idir, iname , newsize , gid )
|
400
|
+
org_full = idir + iname
|
401
|
+
tb_name = "s" + iname
|
402
|
+
tb_full = idir + tb_name
|
403
|
+
begin
|
404
|
+
check_command( @convertpath )
|
405
|
+
# only for imagemagick 6 and later!!
|
406
|
+
system( "#{@convertpath} -thumbnail #{newsize}\\\> #{org_full} #{tb_full}" )
|
407
|
+
end
|
408
|
+
if FileTest::exist?( tb_full )
|
409
|
+
if gid then
|
410
|
+
require 'shell'
|
411
|
+
sh = Shell.new
|
412
|
+
sh.chown( nil , gid , tb_full )
|
413
|
+
sh.chmod( 00664 , tb_full )
|
414
|
+
end
|
415
|
+
tb_name
|
416
|
+
else
|
417
|
+
iname
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
def add_body_text( prev, sub_head , sub_body )
|
422
|
+
addtext = prev
|
423
|
+
if prev.size > 0 and !(prev =~ /\n$/) then
|
424
|
+
addtext += "\n"
|
425
|
+
end
|
426
|
+
if sub_head =~ %r[^Content-Transfer-Encoding:\s*base64]i then
|
427
|
+
addtext += NKF::nkf( '-wXd -mB', sub_body )
|
428
|
+
elsif
|
429
|
+
addtext += sub_body
|
430
|
+
end
|
431
|
+
addtext
|
432
|
+
end
|
433
|
+
|
434
|
+
def add_delimiter( orgpath )
|
435
|
+
if !orgpath or orgpath.size < 1 then
|
436
|
+
newpath = ""
|
437
|
+
else
|
438
|
+
if !(orgpath =~ /[\/\\]$/) then
|
439
|
+
if !(orgpath =~ /\//) and orgpath =~ /\\/ then
|
440
|
+
newpath = orgpath + "\\"
|
441
|
+
else
|
442
|
+
newpath = orgpath + "/"
|
443
|
+
end
|
444
|
+
else
|
445
|
+
newpath = orgpath.dup
|
446
|
+
end
|
447
|
+
end
|
448
|
+
newpath
|
449
|
+
end
|
450
|
+
|
451
|
+
def make_image_body( imgdata , imgname , remotedir , now , image_boundary, protection_key )
|
452
|
+
fname = ""
|
453
|
+
extension = ""
|
454
|
+
image_body = ""
|
455
|
+
if imgname =~ /^(.*)(\.jpg|\.jpeg|\.gif|\.png)\z/i
|
456
|
+
extension = $2.downcase
|
457
|
+
fname = $1 + extension
|
458
|
+
else
|
459
|
+
return nil
|
460
|
+
end
|
461
|
+
typestr = "image/jpeg" if extension =~ /jpe??g/i
|
462
|
+
typestr = "image/bmp" if extension =~ /bmp/i
|
463
|
+
typestr = "image/gif" if extension =~ /gif/i
|
464
|
+
typestr = "image/png" if extension =~ /png/i
|
465
|
+
|
466
|
+
if remotedir and remotedir.length > 0 then
|
467
|
+
image_body.concat <<END
|
468
|
+
--#{image_boundary}\r
|
469
|
+
content-disposition: form-data; name="plugin_image_dir"\r
|
470
|
+
\r
|
471
|
+
#{add_delimiter(remotedir)}\r
|
472
|
+
END
|
473
|
+
end
|
474
|
+
if protection_key and protection_key.length > 0 then
|
475
|
+
image_body.concat <<END
|
476
|
+
--#{image_boundary}\r
|
477
|
+
content-disposition: form-data; name="csrf_protection_key"\r
|
478
|
+
\r
|
479
|
+
#{protection_key}\r
|
480
|
+
END
|
481
|
+
end
|
482
|
+
|
483
|
+
image_body.concat <<END
|
484
|
+
--#{image_boundary}\r
|
485
|
+
content-disposition: form-data; name="plugin_image_add"\r
|
486
|
+
\r
|
487
|
+
true\r
|
488
|
+
--#{image_boundary}\r
|
489
|
+
content-disposition: form-data; name="plugin_image_addimage"\r
|
490
|
+
\r
|
491
|
+
true\r
|
492
|
+
--#{image_boundary}\r
|
493
|
+
content-disposition: form-data; name="date"\r
|
494
|
+
\r
|
495
|
+
#{now.strftime( "%Y%m%d" )}\r
|
496
|
+
END
|
497
|
+
|
498
|
+
image_body.concat <<END
|
499
|
+
--#{image_boundary}\r
|
500
|
+
content-disposition: form-data; name="plugin_image_file"; filename="#{fname}"\r
|
501
|
+
Content-Type: #{typestr}\r
|
502
|
+
\r
|
503
|
+
#{imgdata}\r
|
504
|
+
END
|
505
|
+
|
506
|
+
image_body.concat <<END
|
507
|
+
--#{image_boundary}\r
|
508
|
+
content-disposition: form-data; name="plugin"\r
|
509
|
+
\r
|
510
|
+
image\r
|
511
|
+
--#{image_boundary}--\r
|
512
|
+
END
|
513
|
+
image_body
|
514
|
+
end
|
515
|
+
|
516
|
+
def check_remote_images( http, cgi, user, pass, now )
|
517
|
+
available_list = []
|
518
|
+
maxnum = -1
|
519
|
+
|
520
|
+
str = cgi + '?edit=true;year=' + now.strftime( "%Y" ) + ';month=' + now.strftime( "%m").gsub(/^0/, "") + ';day=' + now.strftime( "%d").gsub(/^0/, "")
|
521
|
+
req = Net::HTTP::Get.new( str )
|
522
|
+
req.basic_auth user, pass
|
523
|
+
response, = http.request(req)
|
524
|
+
body = response.body
|
525
|
+
date = now.strftime( "%Y%m%d" )
|
526
|
+
imglist = []
|
527
|
+
num = 0
|
528
|
+
for i in 0 .. 200
|
529
|
+
if body =~ /\<img [^\<\>]*src=\"[^\"]*(#{date}_#{i}\.[^\"]*)\"/ then
|
530
|
+
maxnum = i
|
531
|
+
else
|
532
|
+
available_list[num] = i
|
533
|
+
num += 1
|
534
|
+
end
|
535
|
+
end
|
536
|
+
|
537
|
+
maxnum += 1
|
538
|
+
[maxnum, available_list]
|
539
|
+
end
|
540
|
+
|
541
|
+
def post_image( http, cgi, user, pass, image_dir , imgname, remote_image_dir, now, protection_key, refurl )
|
542
|
+
auth = ["#{user}:#{pass}"].pack( 'm' ).strip
|
543
|
+
image_boundary = "PosttdiaryMainBoundary"
|
544
|
+
image_data = ( File.open( image_dir + imgname ) { |f| f.read } )
|
545
|
+
image_body = make_image_body(image_data, imgname, remote_image_dir, now , image_boundary, protection_key ) if image_data
|
546
|
+
if image_body then
|
547
|
+
image_header = {
|
548
|
+
'Authorization' => "Basic #{auth}",
|
549
|
+
'Content-Length' => image_body.length.to_s,
|
550
|
+
'Content-Type' => "multipart/form-data; boundary=#{image_boundary}",
|
551
|
+
'Referer' => refurl,
|
552
|
+
}
|
553
|
+
response, = http.post( cgi, image_body, image_header )
|
554
|
+
raise "posttdiary-ex: failed to upload image (#{imgname}) to remote server" if response.code.to_i < 200 or response.code.to_i > 202
|
555
|
+
end
|
556
|
+
|
557
|
+
(image_body ? true : false)
|
558
|
+
end
|
559
|
+
|
560
|
+
def get_date_to_append( http, cgi, user, pass, now )
|
561
|
+
# call update.rb via HTTP and get the date to append
|
562
|
+
str = cgi
|
563
|
+
req = Net::HTTP::Get.new( str )
|
564
|
+
req.basic_auth user, pass
|
565
|
+
response, = http.request(req)
|
566
|
+
body = response.body
|
567
|
+
|
568
|
+
year = now.strftime( "%Y" )
|
569
|
+
month = now.strftime( "%m" )
|
570
|
+
day = now.strftime( "%d" )
|
571
|
+
bodytmp = body.split(/$/);
|
572
|
+
bodytmp.each do |oneline|
|
573
|
+
if oneline =~ /\<input\s.*\sname=\"year\"([^\>]*)\>/ then
|
574
|
+
if $1 =~ /value=\"(\d\d\d\d)"/ then
|
575
|
+
year = $1
|
576
|
+
end
|
577
|
+
end
|
578
|
+
if oneline =~ /\<input\s.*\sname=\"month\"([^\>]*)\>/ then
|
579
|
+
if $1 =~ /value=\"(\d+)\"/ then
|
580
|
+
month = $1
|
581
|
+
end
|
582
|
+
end
|
583
|
+
if oneline =~ /\<input\s.*\sname=\"day\"([^\>]*)\>/ then
|
584
|
+
if $1 =~ /value=\"(\d+)\"/ then
|
585
|
+
day = $1
|
586
|
+
end
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
Time::local( year, month, day )
|
591
|
+
end
|
592
|
+
|
593
|
+
def parse_mail( head, body , image_dir )
|
594
|
+
imglist = []
|
595
|
+
orglist = []
|
596
|
+
textbody = ""
|
597
|
+
imgnum = -1
|
598
|
+
imgdir = add_delimiter( image_dir )
|
599
|
+
|
600
|
+
if head =~ /Content-Type:\s*Multipart\/Mixed.*boundary=\"*([^\"\r\n]*)\"*/im or head =~ /Content-Type:\s*Multipart\/Related.*boundary=\"*([^\"\r\n]*)\"*/im then
|
601
|
+
bound = "--" + $1
|
602
|
+
body_sub = body.split( Regexp.compile( Regexp.escape( bound ) ) )
|
603
|
+
body_sub.each do |b|
|
604
|
+
sub_head, sub_body = b.split( /(?:\r\n){2}|\r\r|\n\n/, 2 )
|
605
|
+
sub_body = "" unless sub_body
|
606
|
+
|
607
|
+
next unless sub_head =~ /Content-Type/i
|
608
|
+
|
609
|
+
if sub_head =~ %r[^Content-Type:\s*text/plain]i then
|
610
|
+
textbody = add_body_text( textbody , sub_head, sub_body )
|
611
|
+
elsif sub_head =~ %r[^Content-Type:\s*(image\/|application\/octet-stream).*name=\"*(.*)(\.[^\"\r\n]*)\"*]im
|
612
|
+
imgnum += 1
|
613
|
+
orgname = $2
|
614
|
+
orgname = "" if !orgname
|
615
|
+
image_ext = $3.downcase
|
616
|
+
image_name = "_tmp" + Process.pid.to_s + "_" + imgnum.to_s + image_ext
|
617
|
+
File::umask( 022 )
|
618
|
+
open( imgdir + image_name, "wb" ) do |s|
|
619
|
+
begin
|
620
|
+
s.print Base64::decode64( sub_body.strip )
|
621
|
+
rescue NameError
|
622
|
+
s.print decode64( sub_body.strip )
|
623
|
+
end
|
624
|
+
end
|
625
|
+
if /\.bmp$/i =~ image_name then
|
626
|
+
bmp_to_png( imgdir + image_name )
|
627
|
+
image_name.sub!( /\.bmp$/, '.png' )
|
628
|
+
end
|
629
|
+
imglist[imgnum] = imgdir + image_name
|
630
|
+
orglist[imgnum] = orgname
|
631
|
+
end
|
632
|
+
end
|
633
|
+
elsif head =~ /^Content-Type:\s*text\/plain/i
|
634
|
+
textbody = add_body_text( textbody , head, body )
|
635
|
+
else
|
636
|
+
raise "posttdiary-ex: can not read this mail (illegal format)"
|
637
|
+
end
|
638
|
+
|
639
|
+
addr = nil
|
640
|
+
if /^To:(.*)$/ =~ head then
|
641
|
+
to = $1.strip
|
642
|
+
if /.*?\s*<(.*)>/ =~ to then
|
643
|
+
addr = $1
|
644
|
+
elsif /(.*?)\s*\(.*\)/ =~ to
|
645
|
+
addr = $1
|
646
|
+
else
|
647
|
+
addr = to
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
subject = ''
|
652
|
+
nextline = false
|
653
|
+
headlines = head.split( /[\r\n]+/ )
|
654
|
+
for n in 0 .. headlines.size-1
|
655
|
+
if nextline then
|
656
|
+
if /^[ \t]/ =~ headlines[n] then
|
657
|
+
s = headlines[n].sub( /^[ \t]/, '' )
|
658
|
+
subject += NKF::nkf( '-wXd', s )
|
659
|
+
else
|
660
|
+
break
|
661
|
+
end
|
662
|
+
end
|
663
|
+
if /^Subject:(.*)$/ =~ headlines[n] then
|
664
|
+
s = $1.sub( /^\s+/, '' )
|
665
|
+
subject = NKF::nkf( '-wXd', s )
|
666
|
+
nextline = true
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
[addr, subject, imglist, orglist, textbody]
|
671
|
+
end
|
672
|
+
|
673
|
+
begin
|
674
|
+
raise usage(false) if ARGV.length < 1
|
675
|
+
|
676
|
+
require 'getoptlong'
|
677
|
+
parser = GetoptLong::new
|
678
|
+
|
679
|
+
conf_df_name = nil
|
680
|
+
image_dir = nil
|
681
|
+
image_url = nil
|
682
|
+
use_subject = false
|
683
|
+
thumbnail_size = nil
|
684
|
+
image_geometry = nil
|
685
|
+
use_image_ex = false
|
686
|
+
hour_offset = nil
|
687
|
+
@hour_offset = nil
|
688
|
+
yearly_dir = false
|
689
|
+
thumbnail_name = Hash.new("")
|
690
|
+
exif_comment = Hash.new("")
|
691
|
+
exif_orientation = Hash.new(1)
|
692
|
+
image_orgname = Hash.new("")
|
693
|
+
|
694
|
+
remote_mode = false
|
695
|
+
remote_image_dir = nil
|
696
|
+
remote_yearly_dir = false
|
697
|
+
preserve_local_images = false
|
698
|
+
upload_only = false
|
699
|
+
class_name = 'photo'
|
700
|
+
group_id = nil
|
701
|
+
add_div_imgnum = 2
|
702
|
+
add_div_imgnum_specified = nil
|
703
|
+
threshold_size = nil
|
704
|
+
pass_filename = false
|
705
|
+
filter_mode = false
|
706
|
+
writeout_filename = nil
|
707
|
+
read_exif = false
|
708
|
+
image_format = ' <img class="$3" src="$1" alt="$4" title="$4">'
|
709
|
+
image_format_with_thumbnail = ' <A HREF="$1"><img class="$3" src="$2" alt="$4" title="$4"></a>'
|
710
|
+
image_format_specified = nil
|
711
|
+
wiki_style = false
|
712
|
+
blog_style = false
|
713
|
+
use_original_name = false
|
714
|
+
date_margin = 7
|
715
|
+
convertpath_specified = nil
|
716
|
+
@convertpath = "convert"
|
717
|
+
@magickpath = ""
|
718
|
+
exifpath_specified = nil
|
719
|
+
@exifpath = "exif"
|
720
|
+
rotation_degree_specified = nil
|
721
|
+
|
722
|
+
parser.set_options(
|
723
|
+
['--read-conffile', '-a', GetoptLong::REQUIRED_ARGUMENT],
|
724
|
+
['--image-path', '-i', GetoptLong::REQUIRED_ARGUMENT],
|
725
|
+
['--image-url', '-u', GetoptLong::REQUIRED_ARGUMENT],
|
726
|
+
['--use-subject', '-s', GetoptLong::NO_ARGUMENT],
|
727
|
+
['--make-thumbnail', '-t', GetoptLong::REQUIRED_ARGUMENT],
|
728
|
+
['--image-geometry', '-g', GetoptLong::REQUIRED_ARGUMENT],
|
729
|
+
['--use-image-ex', '-e', GetoptLong::NO_ARGUMENT],
|
730
|
+
['--hour-offset', '-o', GetoptLong::REQUIRED_ARGUMENT],
|
731
|
+
['--yearly-dir', '-y', GetoptLong::NO_ARGUMENT],
|
732
|
+
['--help', '-h', GetoptLong::NO_ARGUMENT],
|
733
|
+
['--convert-path', '-C', GetoptLong::REQUIRED_ARGUMENT],
|
734
|
+
['--exif-path', '-E', GetoptLong::REQUIRED_ARGUMENT],
|
735
|
+
['--remote-mode', '-R', GetoptLong::NO_ARGUMENT],
|
736
|
+
['--remote-image-path', '-D', GetoptLong::REQUIRED_ARGUMENT],
|
737
|
+
['--remote-yearly-dir', '-Y', GetoptLong::REQUIRED_ARGUMENT],
|
738
|
+
['--preserve-local-images', '-P', GetoptLong::NO_ARGUMENT],
|
739
|
+
['--upload-only', '-U', GetoptLong::NO_ARGUMENT],
|
740
|
+
['--group-id', '-G', GetoptLong::REQUIRED_ARGUMENT],
|
741
|
+
['--class-name', '-n', GetoptLong::REQUIRED_ARGUMENT],
|
742
|
+
['--add-div', '-v', GetoptLong::REQUIRED_ARGUMENT],
|
743
|
+
['--threshold-size', '-z', GetoptLong::REQUIRED_ARGUMENT],
|
744
|
+
['--image-format', '-f', GetoptLong::REQUIRED_ARGUMENT],
|
745
|
+
['--use-original-name', '-r', GetoptLong::NO_ARGUMENT],
|
746
|
+
['--wiki-style', '-w', GetoptLong::NO_ARGUMENT],
|
747
|
+
['--blog-style', '-B', GetoptLong::NO_ARGUMENT],
|
748
|
+
['--read-exif', '-c', GetoptLong::NO_ARGUMENT],
|
749
|
+
['--margin-time', '-m', GetoptLong::REQUIRED_ARGUMENT],
|
750
|
+
['--pass-filename', '-p', GetoptLong::NO_ARGUMENT],
|
751
|
+
['--filter-mode', '-d', GetoptLong::NO_ARGUMENT],
|
752
|
+
['--write-to-file', '-b', GetoptLong::REQUIRED_ARGUMENT],
|
753
|
+
['--date-margin', '-j', GetoptLong::REQUIRED_ARGUMENT],
|
754
|
+
['--rotate', '-T', GetoptLong::REQUIRED_ARGUMENT]
|
755
|
+
)
|
756
|
+
begin
|
757
|
+
parser.each do |opt, arg|
|
758
|
+
case opt
|
759
|
+
when '--read-conffile'
|
760
|
+
conf_df_name = arg.dup
|
761
|
+
when '--image-path'
|
762
|
+
image_dir = arg.dup
|
763
|
+
when '--image-url'
|
764
|
+
image_url = arg.dup
|
765
|
+
when '--use-subject'
|
766
|
+
use_subject = true
|
767
|
+
when '--make-thumbnail'
|
768
|
+
thumbnail_size = arg.dup
|
769
|
+
when '--image-geometry'
|
770
|
+
image_geometry = arg.dup
|
771
|
+
when '--use-image-ex'
|
772
|
+
use_image_ex = true
|
773
|
+
when '--hour-offset'
|
774
|
+
hour_offset = arg.to_i
|
775
|
+
when '--yearly-dir'
|
776
|
+
yearly_dir = true
|
777
|
+
when '--help'
|
778
|
+
print usage(true)
|
779
|
+
exit 0
|
780
|
+
|
781
|
+
when '--convert-path'
|
782
|
+
convertpath_specified = arg.dup
|
783
|
+
when '--exif-path'
|
784
|
+
exifpath_specified = arg.dup
|
785
|
+
read_exif = true
|
786
|
+
when '--remote-mode'
|
787
|
+
remote_mode = true
|
788
|
+
when '--remote-image-path'
|
789
|
+
remote_image_dir = add_delimiter(arg.dup)
|
790
|
+
when '--remote-yearly-dir'
|
791
|
+
remote_yearly_dir = (arg.dup =~ /[1yt]/i)
|
792
|
+
when '--preserve-local-images'
|
793
|
+
preserve_local_images = true
|
794
|
+
when '--upload-only'
|
795
|
+
upload_only = true
|
796
|
+
filter_mode = true
|
797
|
+
when '--group-id'
|
798
|
+
if arg =~ /\D/ then
|
799
|
+
require 'etc'
|
800
|
+
group_id = Etc.getgrnam( arg.dup )['gid']
|
801
|
+
else
|
802
|
+
group_id = arg.to_i
|
803
|
+
end
|
804
|
+
group_id = nil if group_id <= 0 or group_id > 65535
|
805
|
+
when '--add-div'
|
806
|
+
add_div_imgnum_specified = arg.to_i
|
807
|
+
when '--threshold-size'
|
808
|
+
threshold_size = arg.dup
|
809
|
+
when '--image-format'
|
810
|
+
image_format_specified = arg.dup
|
811
|
+
when '--use-original-name'
|
812
|
+
use_original_name = true
|
813
|
+
when '--wiki-style'
|
814
|
+
wiki_style = true
|
815
|
+
use_image_ex = true
|
816
|
+
when '--blog-style'
|
817
|
+
blog_style = true
|
818
|
+
when '--read-exif'
|
819
|
+
read_exif = true
|
820
|
+
when '--pass-filename'
|
821
|
+
pass_filename = true
|
822
|
+
when '--filter-mode'
|
823
|
+
filter_mode = true
|
824
|
+
when '--write-to-file'
|
825
|
+
filter_mode = true
|
826
|
+
writeout_filename = arg.dup
|
827
|
+
when '--date-margin'
|
828
|
+
date_margin = arg.to_i
|
829
|
+
when '--rotate'
|
830
|
+
rotation_degree_specified = 0
|
831
|
+
rotation_degree_specified = 90 if arg =~ /right/i
|
832
|
+
rotation_degree_specified = -90 if arg =~ /left/i
|
833
|
+
end
|
834
|
+
end
|
835
|
+
rescue
|
836
|
+
raise usage(false)
|
837
|
+
end
|
838
|
+
if conf_df_name then
|
839
|
+
if read_tdiary_conf( conf_df_name ) then
|
840
|
+
image_dir = @options['image.dir'] if @options['image.dir'] and !image_dir
|
841
|
+
image_url = @options['image.url'] if @options['image.url'] and !image_url
|
842
|
+
yearly_dir = true if @options['image_ex.yearlydir'] and @options['image_ex.yearlydir'] == 1
|
843
|
+
thumbnail_size = @options['image_ex.convertedwidth'].to_s + "x" + @options['image_ex.convertedheight'].to_s if @options['image_ex.convertedwidth'] and @options['image_ex.convertedheight'] and thumbnail_size == nil
|
844
|
+
threshold_size = @options['image_ex.thresholdsize'].to_s if @options['image_ex.thresholdsize'] and !threshold_size
|
845
|
+
@convertpath= @options['image_ex.convertpath'] if @options['image_ex.convertpath'] and !convertpath_specified
|
846
|
+
@exifpath = @options['image_ex.exifpath'] if @options['image_ex.exifpath'] and !exifpath_specified
|
847
|
+
else
|
848
|
+
conf_df_name = ''
|
849
|
+
end
|
850
|
+
end
|
851
|
+
image_url = "" if use_image_ex and !image_url
|
852
|
+
raise 'posttdiary-ex: image-path (-i) or image-url (-u) missing...' if (!image_url and image_dir) or (!image_dir and image_url)
|
853
|
+
if image_dir then
|
854
|
+
image_dir = add_delimiter( image_dir )
|
855
|
+
end
|
856
|
+
if image_url then
|
857
|
+
image_url += '/' unless %r[/$] =~ image_url
|
858
|
+
end
|
859
|
+
if thumbnail_size then
|
860
|
+
thumbnail_size.gsub!(/[\>\\\s]/, '')
|
861
|
+
thumbnail_size = thumbnail_size + 'x' + thumbnail_size if !(thumbnail_size =~ /x/ )
|
862
|
+
raise usage if !(thumbnail_size =~ /^\d+x\d+/)
|
863
|
+
end
|
864
|
+
threshold_size = thumbnail_size if !threshold_size
|
865
|
+
if threshold_size and threshold_size.size > 0 then
|
866
|
+
threshold_size.gsub!(/[\>\\\s]/, '')
|
867
|
+
threshold_size = threshold_size + 'x' + threshold_size if !(threshold_size =~ /x/ )
|
868
|
+
raise usage if !(threshold_size =~ /^\d+x\d+/)
|
869
|
+
end
|
870
|
+
if image_geometry then
|
871
|
+
image_geometry.gsub!(/[\>\\\s]/, '')
|
872
|
+
image_geometry = image_geometry + 'x' + image_geometry if !(image_geometry =~ /x/ )
|
873
|
+
raise usage if !(image_geometry =~ /^\d+x\d+/)
|
874
|
+
end
|
875
|
+
hour_offset = @hour_offset if !hour_offset
|
876
|
+
hour_offset = 0 if !hour_offset
|
877
|
+
if image_format_specified then
|
878
|
+
image_format = image_format_specified
|
879
|
+
image_format_with_thumbnail = image_format
|
880
|
+
else
|
881
|
+
if use_image_ex then
|
882
|
+
image_format = '<%=image $0,\'$4\'%>'
|
883
|
+
image_format_with_thumbnail = image_format
|
884
|
+
end
|
885
|
+
if wiki_style then
|
886
|
+
image_format = '{{image $0,\'$4\'}}'
|
887
|
+
image_format_with_thumbnail = image_format
|
888
|
+
end
|
889
|
+
end
|
890
|
+
if wiki_style then
|
891
|
+
add_div_imgnum = 0
|
892
|
+
else
|
893
|
+
add_div_imgnum = add_div_imgnum_specified if add_div_imgnum_specified
|
894
|
+
end
|
895
|
+
@convertpath = convertpath_specified if convertpath_specified
|
896
|
+
@convertpath = add_delimiter( @convertpath ) + "convert" if test( ?d , @convertpath )
|
897
|
+
@magickpath = $1 if @convertpath =~ /(.*[\/\\])[^\/\\]+$/
|
898
|
+
@exifpath = exifpath_specified if exifpath_specified
|
899
|
+
@exifpath = add_delimiter( @exifpath ) + "exif" if test( ?d , @exifpath )
|
900
|
+
|
901
|
+
if filter_mode == false then
|
902
|
+
url = ARGV.shift.dup
|
903
|
+
if %r|http://([^:/]*):?(\d*)(/.*)| =~ url then
|
904
|
+
host = $1
|
905
|
+
port = $2.to_i
|
906
|
+
cgi = $3
|
907
|
+
raise 'posttdiary-ex: invalid url for update.rb.' if not host or not cgi
|
908
|
+
port = 80 if port == 0
|
909
|
+
else
|
910
|
+
raise 'posttdiary-ex: invalid url for update.rb.'
|
911
|
+
end
|
912
|
+
user = ARGV.shift.dup
|
913
|
+
pass = ARGV.shift.dup
|
914
|
+
end
|
915
|
+
|
916
|
+
require 'base64'
|
917
|
+
require 'nkf'
|
918
|
+
require 'net/http'
|
919
|
+
require 'shell'
|
920
|
+
Net::HTTP.version_1_2
|
921
|
+
|
922
|
+
mail = NKF::nkf( '-m0 -Xwd', ARGF.read )
|
923
|
+
raise "posttdiary-ex: no mail text." if not mail or mail.length == 0
|
924
|
+
|
925
|
+
head, body = mail.split( /(?:\r\n){2}|\r\r|\n\n/, 2 )
|
926
|
+
body = "" unless body
|
927
|
+
addr, subject, tmpimglist, orglist, @body = parse_mail( head, body, image_dir )
|
928
|
+
|
929
|
+
if /([^-]+)-(.*)@/ =~ addr then
|
930
|
+
user = $1 unless user
|
931
|
+
pass = $2 unless pass
|
932
|
+
end
|
933
|
+
raise "posttdiary-ex: please specify the username for your tdiary system." unless user or filter_mode
|
934
|
+
if tmpimglist.length > 0 and ( !image_dir or !image_url ) then
|
935
|
+
raise "posttdiary-ex: please specify image-path (-i) and/or image-url (-u)"
|
936
|
+
end
|
937
|
+
|
938
|
+
now = Time::now + hour_offset * 3600
|
939
|
+
tmp = Time::now + hour_offset * 3600
|
940
|
+
if @body.gsub!( /^\_date\#([\d\-\/\.]+)[^\r\n]*[\r\n]+/i , '' ) then
|
941
|
+
t = $1
|
942
|
+
if /(\d\d\d\d)[^\d]*(\d\d)[^\d]*(\d\d)/ =~ t then
|
943
|
+
tmp = Time::local( $1.to_i, $2.to_i, $3.to_i );
|
944
|
+
end
|
945
|
+
if /(\d\d\d\d)[^\d]+(\d+)[^\d]+(\d+)/ =~ t then
|
946
|
+
tmp = Time::local( $1.to_i, $2.to_i, $3.to_i );
|
947
|
+
end
|
948
|
+
else
|
949
|
+
if blog_style and !filter_mode then
|
950
|
+
Net::HTTP.start( host, port ) do |http|
|
951
|
+
tmp = get_date_to_append( http, cgi, user, pass, now )
|
952
|
+
end
|
953
|
+
end
|
954
|
+
end
|
955
|
+
if @body.gsub!( /^\_up[ld]+only\#[ \t]*[\r\n]+/i , '' ) then
|
956
|
+
upload_only = true
|
957
|
+
end
|
958
|
+
if @body.gsub!( /^\_rot[ate]*\_right\#[ \t]*[\r\n]+/i , '' ) then
|
959
|
+
rotation_degree_specified = 90
|
960
|
+
end
|
961
|
+
if @body.gsub!( /^\_rot[ate]*\_left\#[ \t]*[\r\n]+/i , '' ) then
|
962
|
+
rotation_degree_specified = -90
|
963
|
+
end
|
964
|
+
if @body.gsub!( /^\_rot[ate]*\_none\#[ \t]*[\r\n]+/i , '' ) then
|
965
|
+
rotation_degree_specified = 0
|
966
|
+
end
|
967
|
+
|
968
|
+
if date_margin != 0 and (tmp - now).abs >= date_margin * 24 * 3600 then
|
969
|
+
# raise "posttdiary-ex: specified date is too far from today"
|
970
|
+
# # use current date (now) instead of specified date(tmp)..
|
971
|
+
else
|
972
|
+
now = tmp
|
973
|
+
end
|
974
|
+
|
975
|
+
topic_year = now.strftime( "%Y" )
|
976
|
+
topic_month = now.strftime( "%m" )
|
977
|
+
topic_date = now.strftime( "%d" )
|
978
|
+
|
979
|
+
if image_dir then
|
980
|
+
image_dir = add_delimiter( image_dir + now.strftime( "%Y" ) ) if yearly_dir
|
981
|
+
Dir.mkdir( image_dir ) if !test( ?d , image_dir )
|
982
|
+
if remote_mode then
|
983
|
+
image_url += topic_year + "/" if remote_yearly_dir
|
984
|
+
else
|
985
|
+
image_url += topic_year + "/" if yearly_dir
|
986
|
+
end
|
987
|
+
end
|
988
|
+
nextnum = -1
|
989
|
+
av_list = []
|
990
|
+
if remote_mode then
|
991
|
+
if !remote_image_dir or remote_image_dir.length < 1 then
|
992
|
+
# needed when using image_ex.rb, but not when using image.rb...
|
993
|
+
# raise 'posttdiary-ex: please specify --remote-image-path'
|
994
|
+
remote_image_dir = ""
|
995
|
+
else
|
996
|
+
if remote_yearly_dir then
|
997
|
+
remote_image_dir = add_delimiter( remote_image_dir + topic_year )
|
998
|
+
end
|
999
|
+
end
|
1000
|
+
Net::HTTP.start( host, port ) do |http|
|
1001
|
+
nextnum,av_list = check_remote_images( http, cgi, user, pass, now)
|
1002
|
+
end
|
1003
|
+
else
|
1004
|
+
nextnum,av_list = check_local_images( now.strftime( "%Y%m%d" ), image_dir )
|
1005
|
+
end
|
1006
|
+
@image_name = nil
|
1007
|
+
sh = Shell.new
|
1008
|
+
for i in 0 .. (tmpimglist.length-1)
|
1009
|
+
tmpimgname = tmpimglist[i]
|
1010
|
+
raise "posttdiary-ex: program bug found: no extension in tmpimgname" if !(tmpimgname =~ /(\.[^\.]*?)$/)
|
1011
|
+
image_ext = $1.downcase
|
1012
|
+
image_name = now.strftime( "%Y%m%d" ) + "_" + nextnum.to_s + image_ext
|
1013
|
+
nextnum += 1
|
1014
|
+
sh.rename( tmpimgname , image_dir + image_name )
|
1015
|
+
exif_comment[image_name] = (read_exif ? read_exif_comment(image_dir + image_name) : "" )
|
1016
|
+
exif_orientation[image_name] = (read_exif ? read_exif_orientation(image_dir + image_name) : "" )
|
1017
|
+
image_orgname[image_name] = orglist[i]
|
1018
|
+
change_image_size( image_dir + image_name , image_geometry ) if image_geometry
|
1019
|
+
if rotation_degree_specified then
|
1020
|
+
if rotation_degree_specified != 0 then
|
1021
|
+
rotate_image( image_dir + image_name , rotation_degree_specified )
|
1022
|
+
end
|
1023
|
+
elsif read_exif and exif_orientation[image_name] != 1 then
|
1024
|
+
rotate_image( image_dir + image_name , rotation_degree( exif_orientation[image_name] ) )
|
1025
|
+
end
|
1026
|
+
if group_id then
|
1027
|
+
sh.chown( nil , group_id , image_dir + image_name )
|
1028
|
+
sh.chmod( 00664 , image_dir + image_name )
|
1029
|
+
end
|
1030
|
+
thumbnail_name[image_name] = ""
|
1031
|
+
thumbnail_name[image_name] = make_thumbnail( image_dir, image_name , thumbnail_size , group_id ) if thumbnail_size and check_image_size( image_dir + image_name, threshold_size)
|
1032
|
+
@image_name = [] unless @image_name
|
1033
|
+
@image_name << image_name
|
1034
|
+
end
|
1035
|
+
|
1036
|
+
if @image_name then
|
1037
|
+
img_src = ""
|
1038
|
+
marker = "_posttdiary_ex_temporary_marker_"
|
1039
|
+
img_in_div = 0
|
1040
|
+
for j in 0 .. @image_name.size-1
|
1041
|
+
i = @image_name[j]
|
1042
|
+
serial = i.sub( /^\d+_(\d+)\.[^\.]*?$/, '\1' )
|
1043
|
+
serial = i if use_image_ex and pass_filename
|
1044
|
+
cm = ""
|
1045
|
+
cm = exif_comment[i] if read_exif and exif_comment[i] and exif_comment[i].size > 0
|
1046
|
+
cm = image_orgname[i] if use_original_name and (!cm or cm.size == 0)
|
1047
|
+
cm = i.gsub(/\.[^\.]*?$/, '') if !cm or cm.size == 0
|
1048
|
+
if use_image_ex then
|
1049
|
+
# modify <%=image (num),'comment'%> or <%=image (num)%> tags
|
1050
|
+
if @body =~ /\<\%\=image[^\s]*\s+#{j}\s*\,\s*[\"\'](.*)[\"\']\s*\%*\>/i then
|
1051
|
+
alttext = $1;
|
1052
|
+
alttext = cm if alttext.length < 1
|
1053
|
+
@body.gsub!( /\<\%\=(image[^\s]*)\s+#{j}\s*\,\s*[\"\'].*[\"\']\s*\%*\>/i, '<%=\1 '+marker+serial.to_s+',\''+alttext+'\'%>' )
|
1054
|
+
next
|
1055
|
+
elsif @body =~ /\<\%\=image[^\s]*\s+#{j}\s*\%*\>/i then
|
1056
|
+
alttext = cm
|
1057
|
+
@body.gsub!( /\<\%\=(image[^\s]*)\s+#{j}\s*\%*\>/i, '<%=\1 '+marker+serial.to_s+',\''+alttext+'\'%>' )
|
1058
|
+
next
|
1059
|
+
end
|
1060
|
+
end
|
1061
|
+
if wiki_style then
|
1062
|
+
# modify {{image (num),"comment"}} or {{image (num)}} tags (also recognizes image_left, image_right)
|
1063
|
+
if @body =~ /\{\{image[^\s]*\s+#{j}\s*\,\s*[\"\'](.*)[\"\']\s*\}\}/i then
|
1064
|
+
alttext = $1;
|
1065
|
+
alttext = cm if alttext.length < 1
|
1066
|
+
@body.gsub!( /\{\{(image[^\s]*)\s+#{j}\s*\,\s*[\"\'].*[\"\']\s*\}\}/i, '{{\1 '+marker+serial.to_s+',\''+alttext+'\'}}' )
|
1067
|
+
next
|
1068
|
+
elsif @body =~ /\{\{image[^\s]*\s+#{j}\s*\}\}/i then
|
1069
|
+
alttext = cm
|
1070
|
+
@body.gsub!( /\{\{(image[^\s]*)\s+#{j}\s*\}\}/i, '{{\1 '+marker+serial.to_s+',\''+alttext+'\'}}' )
|
1071
|
+
next
|
1072
|
+
end
|
1073
|
+
end
|
1074
|
+
img_in_div+=1
|
1075
|
+
if thumbnail_size and thumbnail_name[i].size > 0 then
|
1076
|
+
t = thumbnail_name[i]
|
1077
|
+
img_src += image_format_with_thumbnail.gsub( /\$0/, serial ).gsub( /\$1/, image_url + i ).gsub( /\$2/, image_url + t ).gsub( /\$3/, class_name ).gsub( /\$4/, cm )
|
1078
|
+
else
|
1079
|
+
img_src += image_format.gsub( /\$0/, serial ).gsub( /\$1/, image_url + i ).gsub( /\$3/, class_name ).gsub( /\$4/, cm )
|
1080
|
+
end
|
1081
|
+
end
|
1082
|
+
@body.gsub!( /#{marker}/ , '' )
|
1083
|
+
if img_src =~ /^\s+$/ then
|
1084
|
+
img_src = ''
|
1085
|
+
else
|
1086
|
+
if add_div_imgnum <= img_in_div and add_div_imgnum > 0 then
|
1087
|
+
img_src = "<div class=\"photos\">" + img_src + "</div>"
|
1088
|
+
end
|
1089
|
+
end
|
1090
|
+
img_src.sub!( /^/ , ' ' ) if ! wiki_style
|
1091
|
+
if use_subject then
|
1092
|
+
img_src = img_src + "\n" if !(img_src =~ /^\s*$/)
|
1093
|
+
@body = "#{img_src}#{@body.sub( /\n+\z/, '' )}"
|
1094
|
+
else
|
1095
|
+
@body = "#{@body.sub( /\n+\z/, '' )}\n#{img_src}"
|
1096
|
+
end
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
if use_subject then
|
1100
|
+
title = ''
|
1101
|
+
@body = "#{subject}\n#{@body}"
|
1102
|
+
@body = "!" + @body if wiki_style
|
1103
|
+
else
|
1104
|
+
title = subject
|
1105
|
+
end
|
1106
|
+
|
1107
|
+
if upload_only then
|
1108
|
+
exit 0
|
1109
|
+
end
|
1110
|
+
require 'cgi'
|
1111
|
+
require 'nkf'
|
1112
|
+
if filter_mode then
|
1113
|
+
data = title + "\n";
|
1114
|
+
data << @body + "\n";
|
1115
|
+
if writeout_filename then
|
1116
|
+
open( writeout_filename, "wb" ) do |s|
|
1117
|
+
s.print data
|
1118
|
+
end
|
1119
|
+
else
|
1120
|
+
print data
|
1121
|
+
end
|
1122
|
+
else
|
1123
|
+
data = "title=#{CGI::escape title}"
|
1124
|
+
data << "&body=#{CGI::escape @body}"
|
1125
|
+
data << "&append=true"
|
1126
|
+
data << "&year=#{topic_year}"
|
1127
|
+
data << "&month=#{topic_month}"
|
1128
|
+
data << "&day=#{topic_date}"
|
1129
|
+
auth = ["#{user}:#{pass}"].pack( 'm' ).strip
|
1130
|
+
Net::HTTP.start( host, port ) do |http|
|
1131
|
+
protection_key = nil
|
1132
|
+
res = http.get( cgi,
|
1133
|
+
'Authorization' => "Basic #{auth}",
|
1134
|
+
'Referer' => url )
|
1135
|
+
if %r|<input type="hidden" name="csrf_protection_key" value="([^"]+)">| =~ res.body then
|
1136
|
+
protection_key = $1
|
1137
|
+
data << "&csrf_protection_key=#{CGI::escape( CGI::unescapeHTML( protection_key ) )}"
|
1138
|
+
end
|
1139
|
+
if remote_mode and @image_name then
|
1140
|
+
for i in 0 .. (@image_name.length - 1)
|
1141
|
+
imagename = @image_name[i]
|
1142
|
+
thumbnailname = thumbnail_name[imagename]
|
1143
|
+
post_image( http, cgi, user, pass, image_dir, imagename, remote_image_dir, now, protection_key, url )
|
1144
|
+
File.delete( image_dir + imagename ) if !preserve_local_images
|
1145
|
+
File.delete( image_dir + thumbnailname ) if !preserve_local_images and test( ?f , image_dir + thumbnailname )
|
1146
|
+
end
|
1147
|
+
end
|
1148
|
+
response = http.post( cgi, data, 'Authorization' => "Basic #{auth}", 'Referer' => url )
|
1149
|
+
end
|
1150
|
+
end
|
1151
|
+
|
1152
|
+
rescue
|
1153
|
+
$stderr.puts $!
|
1154
|
+
exit 1
|
1155
|
+
end
|