root/platform/tdiary/plugin/add_bookmark.rb

Revision 37332, 3.3 kB (checked in by drry, 4 years ago)
  • fixed regexes.
  • fixed HTML.
  • et cetera.
Line 
1# add_bookmark.rb $Revision 1.3 $
2#
3# Copyright (c) 2005 SHIBATA Hiroshi <h-sbt@nifty.com>
4# You can redistribute it and/or modify it under GPL2.
5
6require 'uri'
7
8def bookmark_init
9        @conf['add.bookmark.delicious'] ||= ''
10        @conf['add.bookmark.hatena'] ||= ''
11        @conf['add.bookmark.livedoor'] ||= ''
12        @conf['add.bookmark.buzzurl'] ||= ''
13end
14
15add_subtitle_proc do |date, index, subtitle|
16        bookmark_init
17
18        if @conf.mobile_agent? then
19                caption = %Q|#{subtitle}|
20        else
21                caption = %Q|#{subtitle} |
22
23                section_url = @conf.base_url + anchor(date.strftime('%Y%m%d')) + '#p' + ('%02d' % index)
24
25                if @conf['add.bookmark.delicious'] == 't' then
26                        escaped_url = URI.escape(section_url, /[^-.!~*'()\w]/n)
27                        caption += %Q|<a href="http://delicious.com/save?url=#{escaped_url}" onclick="window.open('http://delicious.com/save?v=5;noui;jump=close;url=#{escaped_url};title='+encodeURIComponent(document.title), 'delicious', 'toolbar=no,width=550,height=550'); return false">|
28                        caption += %Q|<img src="http://static.delicious.com/img/delicious.small.gif" width="10" height="10" style="border: 0 none;vertical-align: middle;" alt="#{@caption_delicious}">|
29                        caption += %Q|</a> |
30                end
31
32                if @conf['add.bookmark.hatena'] == 't' then
33                        caption += %Q|<a href="http://b.hatena.ne.jp/append?#{h(section_url)}">|
34                        caption += %Q|<img src="http://b.hatena.ne.jp/images/append.gif" width="16" height="12" style="border: 0 none;vertical-align: middle;" alt="#{@caption_hatena}" title="#{@caption_hatena}">|
35                        caption += %Q|</a> |
36                end
37
38                if @conf['add.bookmark.livedoor'] == 't' then
39                        caption += %Q|<a href="http://clip.livedoor.com/redirect?link=#{h(section_url)}" class="ldclip-redirect">|
40                        caption += %Q|<img src="http://parts.blog.livedoor.jp/img/cmn/clip_16_16_w.gif" width="16" height="16" style="border: 0 none;vertical-align: middle;" alt="#{@caption_livedoor}" title="#{@caption_livedoor}">|
41                        caption += %Q|</a> |
42                end
43
44                if @conf['add.bookmark.buzzurl'] == 't' then
45                        caption += %Q|<a href="http://buzzurl.jp/entry/#{h(section_url)}">|
46                        caption += %Q|<img src="http://buzzurl.jp/static/image/api/icon/add_icon_mini_10.gif" width="16" height="12" style="border: 0 none;vertical-align: middle;" title="#{@caption_buzzurl}" alt="#{@caption_buzzurl}" class="icon">|
47                        caption += %Q|</a> |
48                end
49        end
50
51        <<-HTML
52        #{caption}
53        HTML
54end
55
56add_conf_proc( 'add_bookmark', @add_bookmark_label ) do
57        add_bookmark_conf_proc
58end
59
60def add_bookmark_conf_proc
61        bookmark_init
62        saveconf_add_bookmark
63
64        bookmark_categories = [
65        'add.bookmark.delicious',
66        'add.bookmark.hatena',
67        'add.bookmark.livedoor',
68        'add.bookmark.buzzurl'
69        ]
70
71        r = ''
72        r << %Q|<h3 class="subtitle">#{@add_bookmark_label}</h3><p>#{@add_bookmark_desc}</p><ul>|
73
74        bookmark_categories.each_with_index do |idx,view|
75                checked = 't' == @conf[idx] ? ' checked' : ''
76                label = @bookmark_label[view]
77                r << %Q|<li><label for="#{idx}"><input id=#{idx} name=#{idx} type="checkbox" value="t"#{checked}>#{label}</label></li>|
78        end
79        r << %Q|</ul>|
80end
81
82if @mode == 'saveconf'
83        def saveconf_add_bookmark
84                @conf['add.bookmark.delicious'] = @cgi.params['add.bookmark.delicious'][0]
85                @conf['add.bookmark.hatena'] = @cgi.params['add.bookmark.hatena'][0]
86                @conf['add.bookmark.livedoor'] = @cgi.params['add.bookmark.livedoor'][0]
87                @conf['add.bookmark.buzzurl'] = @cgi.params['add.bookmark.buzzurl'][0]
88        end
89end
Note: See TracBrowser for help on using the browser.