tdiary-contrib 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/js/preview.js +50 -0
  3. data/lib/tdiary/contrib/version.rb +1 -1
  4. data/plugin/category-lite.rb +235 -0
  5. data/plugin/code-prettify.rb +1 -8
  6. data/plugin/en/category-lite.rb +46 -0
  7. data/plugin/flickr.rb +1 -6
  8. data/plugin/google_analytics.rb +8 -9
  9. data/plugin/image_gps.rb +15 -5
  10. data/plugin/instagr.rb +8 -39
  11. data/plugin/instagram.rb +59 -2
  12. data/plugin/ja/category-lite.rb +48 -0
  13. data/plugin/ohmsha_estore.rb +9 -22
  14. data/plugin/playstore.rb +16 -24
  15. data/plugin/preview.rb +10 -0
  16. data/plugin/profile.rb +7 -19
  17. data/plugin/rubykaigi.rb +7 -1
  18. data/plugin/socialbutton.rb +1 -1
  19. data/spec/fixtures/github.json +1 -1
  20. data/spec/flicker_spec.rb +1 -1
  21. data/spec/google_analytics_spec.rb +8 -9
  22. data/spec/profile_spec.rb +2 -18
  23. metadata +78 -41
  24. data/.gitignore +0 -2
  25. data/.travis.yml +0 -18
  26. data/Gemfile +0 -13
  27. data/Gemfile.lock +0 -66
  28. data/js/prettify/lang-apollo.js +0 -2
  29. data/js/prettify/lang-clj.js +0 -18
  30. data/js/prettify/lang-css.js +0 -2
  31. data/js/prettify/lang-go.js +0 -1
  32. data/js/prettify/lang-hs.js +0 -2
  33. data/js/prettify/lang-lisp.js +0 -3
  34. data/js/prettify/lang-lua.js +0 -2
  35. data/js/prettify/lang-ml.js +0 -2
  36. data/js/prettify/lang-n.js +0 -4
  37. data/js/prettify/lang-proto.js +0 -1
  38. data/js/prettify/lang-scala.js +0 -2
  39. data/js/prettify/lang-sql.js +0 -2
  40. data/js/prettify/lang-tex.js +0 -1
  41. data/js/prettify/lang-vb.js +0 -2
  42. data/js/prettify/lang-vhdl.js +0 -3
  43. data/js/prettify/lang-wiki.js +0 -2
  44. data/js/prettify/lang-xq.js +0 -3
  45. data/js/prettify/lang-yaml.js +0 -2
  46. data/js/prettify/prettify.css +0 -1
  47. data/js/prettify/prettify.js +0 -28
  48. data/misc/tdiarygraph/tdiarygraph120x90e.swf +0 -0
  49. data/misc/tdiarygraph/tdiarygraph125x125e.swf +0 -0
  50. data/misc/tdiarygraph/tdiarygraph240x180e.swf +0 -0
  51. data/misc/tdiarygraph/tdiarygraph468x60e.swf +0 -0
  52. data/misc/tdiarygraph/tdiarygraph728x90e.swf +0 -0
  53. data/misc/tdiarytimes/tdiarytimes125x125r.swf +0 -0
  54. data/misc/tdiarytimes/tdiarytimes125x125r7.swf +0 -0
  55. data/misc/tdiarytimes/tdiarytimes125x125s.swf +0 -0
  56. data/misc/tdiarytimes/tdiarytimes125x30.swf +0 -0
  57. data/misc/tdiarytimes/tdiarytimes234x30.swf +0 -0
  58. data/misc/tdiarytimes/tdiarytimes468x30.swf +0 -0
  59. data/plugin/tdiarygraph_flashstyle.rb +0 -292
  60. data/plugin/tdiarytimes.rb +0 -166
  61. data/tdiary-contrib.gemspec +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0261647cb0391bb468ccc2df77df87cf5b6cf65
4
- data.tar.gz: 6b51bbbe6917310a9027da41d4a04dbd122bf15a
3
+ metadata.gz: 2b963a36e85ed48eeaf351c67e1daaaa10b798d4
4
+ data.tar.gz: 2f4633b77caadcaa50960a8e1350680818ba2087
5
5
  SHA512:
6
- metadata.gz: da4972ac0fadf204dc2f4f1da359a16ae57ae32762acf35e46eba06a3495f7c3d376b341d43d52a46a6d066811e10aeea6bc8c3e4f86441d0ff8ac7215468892
7
- data.tar.gz: 9b5e50c6d5ca78ad1d19948f0b17af6f981e774c11b70e7e5fc7ed5dbcc85d4163a3bd826efb75ab58cdf798d755b800617e5bf36a2dc9ca5456271f215ea670
6
+ metadata.gz: 1755119971bbadaab70bcb37536111a1c89617aae4ef2b6dde6731f5821a8288051c9e1fce2b50671df31381387512c577c969e3f2fa08fc4af5171566435084
7
+ data.tar.gz: eddddefe6eba29289006b8e19dc5b48fd548d7e4493b03be73048151f01b67dc31071ebd91132b81e097d38df527f75e90e8725f84bd4ccb97b347e9540f82c2
data/js/preview.js ADDED
@@ -0,0 +1,50 @@
1
+ /*
2
+ * preview.js: view preview automatically
3
+ *
4
+ * Copyright (c) MATSUOKA Kohei <http://www.machu.jp/>
5
+ * Distributed under the GPL2 or any later version.
6
+ */
7
+ $(function() {
8
+
9
+ var previewButton = $('input[name="appendpreview"]');
10
+
11
+ $tDiary.plugin.preview = function() {
12
+ previewButton.prop("disabled", true);
13
+ $.post(
14
+ 'update.rb',
15
+ $('form.update').serialize() + "&appendpreview=1",
16
+ function(data) {
17
+ var beforeOffset = $('div.update').offset();
18
+ $('div.autopagerize_page_element').replaceWith(
19
+ $(data).find('div.autopagerize_page_element')
20
+ )
21
+ var afterOffset = $('div.update').offset();
22
+ // 自動更新時にスクロール位置を自動調整してみたがカクカクする
23
+ // window.scrollTo($(window).scrollLeft(),
24
+ // $(window).scrollTop() + afterOffset.top - beforeOffset.top);
25
+ setTimeout($tDiary.plugin.preview, 10000);
26
+ },
27
+ 'html'
28
+ )
29
+ .always(function() {
30
+ previewButton.prop("disabled", false);
31
+ });
32
+ }
33
+
34
+ if ($('div.autopagerize_page_element').length == 0) {
35
+ $('div.update').before(
36
+ $('<div class="autopagerize_page_element"></div>')
37
+ );
38
+ }
39
+
40
+ // プレビューボタンを押した時もajaxで更新するよう設定
41
+ previewButton.click(
42
+ function(event) {
43
+ event.preventDefault();
44
+ $tDiary.plugin.preview();
45
+ }
46
+ );
47
+
48
+ setTimeout($tDiary.plugin.preview, 10000);
49
+
50
+ });
@@ -1,5 +1,5 @@
1
1
  module TDiary
2
2
  class Contrib
3
- VERSION = "4.2.0"
3
+ VERSION = "4.2.1"
4
4
  end
5
5
  end
@@ -0,0 +1,235 @@
1
+ #
2
+ # category-lite.rb : tDiary plugin for show category pages (light edition)
3
+ #
4
+ # Copyright (C) 2015 TADA Tadashi
5
+ # Distributed under the GPL2 or any later version.
6
+ #
7
+
8
+
9
+ # read cache here so that you can use category with secure mode.
10
+ @conf['category.header1'] = ''
11
+ @conf['category.header2'] = '<%= category_dropdown_list %>'
12
+ @category_icon = {}
13
+ @categories = transaction('category'){|db|db.keys}.sort_by{|c|c.downcase}
14
+
15
+ module Category
16
+ class Info
17
+ def initialize(cgi, _, conf)
18
+ @cgi, @conf = cgi, conf
19
+ end
20
+
21
+ def category
22
+ @name || (@name = @conf.to_native(@cgi.params['category'][0], @conf.encoding_old))
23
+ end
24
+ end
25
+ end
26
+
27
+ def category_title
28
+ info = Category::Info.new(@cgi, nil, @conf)
29
+ "[#{info.category}]"
30
+ end
31
+
32
+ def category_anchor(category)
33
+ %Q|[<a href="#{h @index}?category=#{u category}" title="#{h category}">#{h category}</a>]|
34
+ end
35
+
36
+ def category_dropdown_list(label = nil, _ = nil)
37
+ label ||= 'show category list'
38
+
39
+ info = Category::Info.new(@cgi, _, @conf)
40
+ category = info.category
41
+ category = [] if category.empty?
42
+
43
+ options = ''
44
+ @categories.each do |c|
45
+ options << %Q|<option value="#{h c}"#{" selected" if category.include?(c)}>#{h c}</option>\n|
46
+ end
47
+
48
+ <<-HTML
49
+ <form method="get" action="#{h @index}"><div>
50
+ <select name="category">
51
+ #{options}
52
+ </select>
53
+ <input type="submit" value="#{label}">
54
+ </div></form>
55
+ HTML
56
+ end
57
+
58
+ def category_transaction(categories)
59
+ transaction('category') do |db|
60
+ (categories || db.keys).each do |category|
61
+ Hash[*JSON.load(db.get(category) || '{}').sort_by{|d,_|d}.flatten(1)].each do |ymd, diaries|
62
+ yield db, category, ymd, diaries
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ def category_list_sections
69
+ info = Category::Info.new(@cgi, nil, @conf)
70
+
71
+ r = ''
72
+ r << <<-HTML
73
+ <div class="category day">
74
+ <h2>
75
+ <span class="title">
76
+ <a href="#{h @conf.index}?category=#{u info.category}">#{h info.category}</a>
77
+ </span>
78
+ </h2>
79
+ <div class="body">
80
+ <ul class="category">
81
+ HTML
82
+ category_transaction([info.category]) do |db, category, ymd, diaries|
83
+ date = Time.local(*ymd.scan(/(.{4})(..)(..)/)[0]).strftime(@conf.date_format)
84
+ diaries.sort_by{|i|i[0]}.each do |idx, title, excerpt|
85
+ r << <<-HTML
86
+ <li>
87
+ <a href="#{h @index}#{anchor "#{ymd}#p#{'%02d' % idx}"}" title="#{h excerpt}">
88
+ #{date}#p#{'%02d' % idx}
89
+ </a>
90
+ #{apply_plugin(title)}
91
+ </li>
92
+ HTML
93
+ end
94
+ end
95
+ r << <<-HTML
96
+ </ul>
97
+ </div>
98
+ </div>
99
+ HTML
100
+ return r
101
+ end
102
+
103
+ def category_serialize(diary)
104
+ data = {}
105
+ ymd = diary.date.strftime('%Y%m%d')
106
+
107
+ idx = 1
108
+ diary.each_section do |s|
109
+ s.categories.each do |c|
110
+ data[c] ||= {}
111
+ data[c][ymd] ||= []
112
+ body = <<-EVAL.gsub(/^\t+/, '')
113
+ text = apply_plugin(<<'BODY', true)
114
+ #{s.body_to_html}
115
+ BODY
116
+ EVAL
117
+ shorten = begin
118
+ @conf.shorten(eval(body.untaint))
119
+ rescue NameError
120
+ ""
121
+ end
122
+ data[c][ymd] << [idx, s.stripped_subtitle_to_html, shorten]
123
+ end
124
+ idx +=1
125
+ end
126
+ data
127
+ end
128
+
129
+ def category_rebuild(years)
130
+ transaction('category') do |db|
131
+ cache = Hash.new{{}}
132
+ @years.each do |y, ms|
133
+ ms.each do |m|
134
+ m = DiaryContainer::find_by_month(@conf, "#{y}#{m}")
135
+ m.diaries.each do |ymd, diary|
136
+ next if !diary.visible? or !diary.categorizable?
137
+ serialize = category_serialize(diary)
138
+ serialize.keys.each do |category|
139
+ cache[category] = cache[category].merge!(serialize[category])
140
+ end
141
+ end
142
+ end
143
+ end
144
+ db.keys.each {|key| db.delete(key)}
145
+ cache.each do |category, diaries|
146
+ db.set(category, diaries.to_json)
147
+ end
148
+ end
149
+ end
150
+
151
+ add_update_proc do
152
+ if /^(append|replace)$/ =~ @mode
153
+ ymd = @date.strftime('%Y%m%d')
154
+ diary = @diaries[ymd]
155
+ serialize = category_serialize(diary)
156
+
157
+ transaction('category') do |db|
158
+ (db.keys + serialize.keys).uniq.each do |category|
159
+ data = JSON.load(db.get(category) || '{}')
160
+ if diary.visible? and serialize[category]
161
+ data.update(serialize[category])
162
+ db.set(category, data.to_json)
163
+ else
164
+ data.delete(ymd)
165
+ if data.empty?
166
+ db.delete(category)
167
+ else
168
+ db.set(category, data.to_json)
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
175
+
176
+ #
177
+ # edit support: insert category to editing diary using JavaScript
178
+ #
179
+ def category_edit_support_flatlist(categories)
180
+ ret = ''
181
+ ret << '<div class="field title">'
182
+ ret << "#{@category_conf_label}:\n"
183
+ categories.each do |c|
184
+ ret << %Q!| <span class="category-item">#{h c}</span>\n!
185
+ end
186
+ ret << "|\n</div>\n<br>\n"
187
+ ret
188
+ end
189
+
190
+ def category_edit_support_dropdown(categories)
191
+ ret = ''
192
+ ret << '<div class="field title">'
193
+ ret << %Q|#{@category_conf_label}: <select id="category-candidate" name="category-candidate">\n|
194
+ categories.each do |c|
195
+ ret << %Q!<option>#{h c}</option>\n!
196
+ end
197
+ ret << "|\n</select>\n</div>\n<br>\n"
198
+ ret
199
+ end
200
+
201
+ if @mode =~ /^(form|edit)$/ and @conf['category.edit_support'] != 0
202
+ enable_js( 'category.js' )
203
+ add_edit_proc do |date|
204
+ ret = ''
205
+ transaction('category') do |db|
206
+ categories = db.keys
207
+ unless categories.size == 0 then
208
+ if @conf['category.edit_support'] == 2 then
209
+ ret << category_edit_support_dropdown(categories)
210
+ else
211
+ ret << category_edit_support_flatlist(categories)
212
+ end
213
+ end
214
+ end
215
+ ret
216
+ end
217
+ end
218
+
219
+ if @mode == 'conf' || @mode == 'saveconf'
220
+ add_conf_proc('category', @category_conf_label, 'basic') do
221
+ if @mode == 'saveconf'
222
+ category_rebuild(@years) if @cgi.valid?('category_initialize')
223
+ @conf['category.edit_support'] = (@cgi.params['category.edit_support'][0] || '1').to_i
224
+ end
225
+ category_conf_html
226
+ end
227
+ end
228
+
229
+ # Local Variables:
230
+ # mode: ruby
231
+ # indent-tabs-mode: t
232
+ # tab-width: 3
233
+ # ruby-indent-level: 3
234
+ # End:
235
+ # vim: ts=3
@@ -4,14 +4,7 @@
4
4
 
5
5
  add_header_proc do
6
6
  <<-EOS
7
- <link href="js/prettify/prettify.css" type="text/css" rel="stylesheet" />
8
- <script type="text/javascript" src="js/prettify/prettify.js"></script>
9
- <script type="text/javascript"><!--
10
- jQuery.event.add(window, "load", function(){
11
- prettyPrint();
12
- });
13
- //-->
14
- </script>
7
+ <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>
15
8
  EOS
16
9
  end
17
10
 
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # en/category-lite.rb : tDiary plugin for show category pages (light edition)
4
+ #
5
+ # Copyright (C) 2015 TADA Tadashi
6
+ # Distributed under the GPL2 or any later version.
7
+ #
8
+
9
+ @category_conf_label = 'Category'
10
+
11
+ def category_conf_html
12
+ r = <<-HTML
13
+ <h3 class="subtitle">Build category index</h3>
14
+ <p>
15
+ To use the category feature, you should build category index.
16
+ Check the box below and press OK to build category index.
17
+ </p>
18
+ <p><label for="category_initialize">
19
+ <input type="checkbox" id="category_initialize" name="category_initialize" value="1">Build category index
20
+ </label></p>
21
+ <p>
22
+ It takes several or several tens of second to create it. But your diaries are many or the server has low spec, it will be timeout. Rebuild index on off-line again.
23
+ </p>
24
+
25
+ <h3 class="subtitle">Edit Support</h3>
26
+ <p>
27
+ Category names can be shown under the 'Article' form.
28
+ </p>
29
+ <p>
30
+ <select name="category.edit_support">
31
+ <option value="1"#{" selected" if @conf['category.edit_support'] == 1}>Flat List</option>
32
+ <option value="2"#{" selected" if @conf['category.edit_support'] == 2}>Dropdown List/option>
33
+ <option value="0"#{" selected" if @conf['category.edit_support'] == 0}>Hide</option>
34
+ </select>
35
+ </p>
36
+ HTML
37
+ r
38
+ end
39
+
40
+ # Local Variables:
41
+ # mode: ruby
42
+ # indent-tabs-mode: t
43
+ # tab-width: 3
44
+ # ruby-indent-level: 3
45
+ # End:
46
+ # vim: ts=3
data/plugin/flickr.rb CHANGED
@@ -43,12 +43,7 @@ def flickr(photo_id, size = nil, place = 'flickr')
43
43
  return '[ERROR] flickr.rb: failed to get photo.'
44
44
  end
45
45
 
46
- body = %Q|<a href="#{photo[:page]}" class="flickr"><img title="#{photo[:title]}" alt="#{photo[:title]}" src="#{photo[:src]}" class="#{place}"|
47
- body << %Q| width="#{photo[:width]}"| if photo[:width]
48
- body << %Q| height="#{photo[:height]}"| if photo[:height]
49
- body << %Q|></a>|
50
-
51
- body
46
+ %Q|<a href="#{photo[:page]}" class="flickr"><img title="#{photo[:title]}" alt="#{photo[:title]}" src="#{photo[:src]}" class="#{place} photo"></a>|
52
47
  end
53
48
 
54
49
  def flickr_left(photo_id, size = nil)
@@ -13,15 +13,14 @@ end
13
13
  def google_analytics_insert_code
14
14
  return '' unless @conf['google_analytics.profile']
15
15
  <<-HTML
16
- <script type="text/javascript"><!--
17
- var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
18
- document.write(unescape('%3Cscript src="' + gaJsHost + 'google-analytics.com/ga.js" type="text/javascript"%3E%3C/script%3E'));
19
- // --></script>
20
- <script type="text/javascript"><!--
21
- try {
22
- var pageTracker = _gat._getTracker("UA-#{h @conf['google_analytics.profile']}");
23
- pageTracker._trackPageview();
24
- } catch (err) {}
16
+ <script>
17
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
18
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
19
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
20
+ })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
21
+
22
+ ga('create', 'UA-#{@conf['google_analytics.profile']}', 'auto');
23
+ ga('send', 'pageview');
25
24
  // --></script>
26
25
  HTML
27
26
  end
data/plugin/image_gps.rb CHANGED
@@ -43,14 +43,24 @@ def image( id, alt = 'image', thumbnail = nil, size = nil, place = 'photo' )
43
43
  image = image_list( @image_date )[id.to_i]
44
44
  image_t = image_list( @image_date )[thumbnail.to_i] if thumbnail
45
45
  end
46
- if size then
46
+
47
+ if size
47
48
  if size.kind_of?(Array)
48
- size = %Q[ width="#{size[0]}" height="#{size[1]}"]
49
+ if size.length > 1
50
+ size = %Q| width="#{h size[0]}" height="#{h size[1]}"|
51
+ elsif size.length > 0
52
+ size = %Q| width="#{h size[0]}"|
53
+ end
49
54
  else
50
- size = %Q[ width="#{size.to_i}"]
55
+ size = %Q| width="#{size.to_i}"|
56
+ end
57
+ elsif @image_maxwidth and not @conf.secure then
58
+ _, w, _ = image_info( "#{@image_dir}/#{image}".untaint )
59
+ if w > @image_maxwidth then
60
+ size = %Q[ width="#{h @image_maxwidth}"]
61
+ else
62
+ size = ""
51
63
  end
52
- else
53
- size = ""
54
64
  end
55
65
 
56
66
  show_exif_info = @conf['image_gps.show_exif_info']
data/plugin/instagr.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  #
3
3
  # instagr.rb - plugin to insert images on instagr.am
4
+ # !! integrated into the instagram.rb.
5
+ # !! Please use the instagram.rb
4
6
  #
5
- # Copyright (C) 2011, tamoot <tamoot+tdiary@gmail.com>
7
+ # Copyright (C) 2011-2015, tamoot <tamoot+tdiary@gmail.com>
6
8
  # You can redistribute it and/or modify it under GPL2.
7
9
  #
8
10
  # usage:
@@ -14,46 +16,13 @@
14
16
  # :medium => 306x306 pixel (default)
15
17
  # :large => 612x612 pixel
16
18
 
17
- require 'cgi'
18
- require 'json'
19
- require 'net/http'
20
-
21
19
  def instagr( short_url, size = :medium)
22
- return %Q|<p>Argument is empty.. #{short_url}</p>| if !short_url or short_url.empty?
23
- option = option.nil? ? {} : option
24
-
25
- # img size
26
- size = size.to_sym if size != :medium
27
- maxwidth_data = {:medium => 320, :large => 612}
28
- maxwidth = maxwidth_data[ size ] ? maxwidth_data[ size ] : maxwidth_data[:medium]
29
-
30
- # proxy
31
- px_host, px_port = (@conf['proxy'] || '').split( /:/ )
32
- px_port = 80 if px_host and !px_port
33
-
34
- # query
35
- query = "?url=#{CGI::escape(short_url)}&maxwidth=#{maxwidth}"
36
-
37
- begin
38
- Net::HTTP.version_1_2
39
- res = Net::HTTP::Proxy(px_host, px_port).get('instagram.com', "/api/v1/oembed/#{query}")
40
- json_data = JSON::parse( res, &:read )
41
- width = option[:width] ? option[:width] : json_data["width"]
42
- height = option[:height] ? option[:height] : json_data["height"]
43
-
44
- return <<-INSTAGR_DOM
45
- <div class="instagr">
46
- <a class="instagr" href="#{h short_url}" title="#{h @conf.to_native(json_data["title"])}">
47
- <img src="#{h json_data["thumbnail_url"]}" width="#{h width}" height="#{h height}" alt="#{h @conf.to_native(json_data["title"])}">
48
- </a>
49
- <p>#{h json_data["author_name"]}'s photo.</p>
50
- </div>
51
- INSTAGR_DOM
52
- rescue
53
- return %Q|<p>Failed Open URL.. #{short_url}<br>#{h $!}</p>|
54
- end
20
+ if respond_to?(:instagram)
21
+ instagram( short_url, size )
22
+ else
23
+ return %Q|instagr.rb was integrated into instagram.rb. Please use the instagram.rb|
24
+ end
55
25
  end
56
- alias :instagram :instagr
57
26
 
58
27
 
59
28
  # Local Variables:
data/plugin/instagram.rb CHANGED
@@ -1,10 +1,67 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
1
3
  # instagram.rb - embed your photo/videos in instagram to a diary
2
4
  #
3
5
  # Author: Tatsuya Sato
4
6
  # License: GPL
7
+ require 'cgi'
8
+ require 'json'
9
+ require 'uri'
10
+ require 'net/http'
11
+ require 'open-uri'
12
+
13
+
14
+ def instagram(*args)
15
+ uri = URI::parse(args[0])
16
+ return instagram_iframe(*args) if uri.scheme.nil?
17
+ return instagram_serverside(*args)
18
+ end
5
19
 
6
- def instagram(code, width=612, height=700)
7
- <<-BODY
20
+ def instagram_iframe(code, width=612, height=700)
21
+ return <<-BODY
8
22
  <iframe src="//instagram.com/p/#{code}/embed/" width="#{width}" height="#{height}" frameborder="0" scrolling="no" allowtransparency="true"></iframe>
9
23
  BODY
10
24
  end
25
+
26
+ def instagram_serverside( short_url, size = :medium)
27
+ return %Q|<p>Argument is empty.. #{short_url}</p>| if !short_url or short_url.empty?
28
+ option = option.nil? ? {} : option
29
+
30
+ # img size
31
+ size = size.to_sym if size != :medium
32
+ maxwidth_data = {:medium => 320, :large => 612}
33
+ maxwidth = maxwidth_data[ size ] ? maxwidth_data[ size ] : maxwidth_data[:medium]
34
+
35
+ # proxy
36
+ px_host, px_port = (@conf['proxy'] || '').split( /:/ )
37
+ px_port = 80 if px_host and !px_port
38
+
39
+ # query
40
+ query = "?url=#{CGI::escape(short_url)}&maxwidth=#{maxwidth}"
41
+
42
+ begin
43
+ Net::HTTP.version_1_2
44
+ res = Net::HTTP::Proxy(px_host, px_port).get('instagram.com', "/api/v1/oembed/#{query}")
45
+ json_data = JSON::parse( res, &:read )
46
+ width = option[:width] ? option[:width] : json_data["width"]
47
+ height = option[:height] ? option[:height] : json_data["height"]
48
+ return <<-INSTAGR_DOM
49
+ <div class="instagr">
50
+ <a class="instagr" href="#{h short_url}" title="#{h @conf.to_native(json_data["title"])}">
51
+ <img src="#{h json_data["thumbnail_url"]}" width="#{h width}" height="#{h height}" alt="#{h @conf.to_native(json_data["title"])}">
52
+ </a>
53
+ <p>#{h json_data["author_name"]}'s photo.</p>
54
+ </div>
55
+ INSTAGR_DOM
56
+ rescue
57
+ return %Q|<p>Failed Open URL.. #{short_url}<br>#{h $!}</p>|
58
+ end
59
+ end
60
+
61
+ # Local Variables:
62
+ # mode: ruby
63
+ # indent-tabs-mode: t
64
+ # tab-width: 3
65
+ # ruby-indent-level: 3
66
+ # End:
67
+ # vim: ts=3
@@ -0,0 +1,48 @@
1
+ # -*- coding: utf-8 -*-
2
+ #
3
+ # ja/category-lite.rb : tDiary plugin for show category pages (light edition)
4
+ #
5
+ # Copyright (C) 2015 TADA Tadashi
6
+ # Distributed under the GPL2 or any later version.
7
+ #
8
+
9
+ @category_conf_label = 'カテゴリ'
10
+
11
+ def category_conf_html
12
+ r = <<-HTML
13
+ <h3 class="subtitle">カテゴリインデックスの作成</h3>
14
+ <p>
15
+ カテゴリの機能を利用するにはカテゴリインデックスをあらかじめ作成しておく必要があります。
16
+ カテゴリインデックスを作成するには
17
+ 以下のチェックを入れてからOKボタンを押してください。
18
+ </p>
19
+ <p><label for="category_initialize">
20
+ <input type="checkbox" id="category_initialize" name="category_initialize" value="1">カテゴリインデックスの作成
21
+ </label></p>
22
+ <p>
23
+ 数秒から数十秒でインデックスの作成は終了しますが、日記の量が多い場合やサーバの性能が低い場合はタイムアウトしてしまう場合があります。この場合はオフラインで作成して下さい。
24
+ </p>
25
+
26
+ <h3 class="subtitle">日記編集サポート</h3>
27
+ <p>
28
+ 日記編集画面の「本文」の下にカテゴリ名を一覧表示することができます。
29
+ カテゴリ名をクリックすると「本文」にそのカテゴリ名が挿入されます(要JavaScript)。
30
+ </p>
31
+ <p>
32
+ <select name="category.edit_support">
33
+ <option value="1"#{" selected" if @conf['category.edit_support'] == 1}>一覧表示</option>
34
+ <option value="2"#{" selected" if @conf['category.edit_support'] == 2}>ドロップダウンリスト</option>
35
+ <option value="0"#{" selected" if @conf['category.edit_support'] == 0}>表示しない</option>
36
+ </select>
37
+ </p>
38
+ HTML
39
+ r
40
+ end
41
+
42
+ # Local Variables:
43
+ # mode: ruby
44
+ # indent-tabs-mode: t
45
+ # tab-width: 3
46
+ # ruby-indent-level: 3
47
+ # End:
48
+ # vim: ts=3
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # You can redistribute it and/or modify it under the same license as tDiary.
3
3
  #
4
- # display book info in http://estore.ohmsha.co.jp/ like amazon.rb
4
+ # display book info in https://estore.ohmsha.co.jp/ like amazon.rb
5
5
  # USAGE: {{ohmsha_estore '978427406694P'}}
6
6
 
7
7
  def ohmsha_estore_cache_dir
@@ -25,37 +25,24 @@ rescue
25
25
  end
26
26
 
27
27
  require 'open-uri'
28
- autoload :REXML, 'rexml/document'
29
- autoload :StringIO, 'stringio'
28
+ require 'json'
30
29
  def ohmsha_estore( id, doc = nil )
31
30
  if !@conf.secure and !(result = ohmsha_estore_cache_get(id)).nil?
32
31
  return result
33
32
  end
34
33
 
35
- domain = "http://estore.ohmsha.co.jp"
36
- image = "#{domain}/images/covers/#{id}.gif"
37
- link = "#{domain}/titles/#{id}"
38
- doc ||= StringIO.new(open(link, &:read).gsub(%r|</?fb:.*?>|, ''))
39
- xml = REXML::Document.new( doc )
40
- biblio = "//html/body/div/div[2]/div/div/div/div[2]"
41
- title = REXML::XPath.match( xml,
42
- "#{biblio}/h2").first.text
43
- author = REXML::XPath.match( xml,
44
- "#{biblio}/div" ).first.text
45
-
46
- description =
47
- REXML::XPath.match( xml, '//html/body/div/div[2]/div/div/div[2]' ).
48
- first.text
34
+ html = open("https://estore.ohmsha.co.jp#{domain}/titles/#{id}", &:read)
35
+ info = JSON.parse(html.scan(%r|<script type='application/ld\+json'>(.*?)</script>|m).flatten[0])
49
36
 
50
37
  result = <<-EOS
51
38
  <a class="amazon-detail" href="#{h link}"><span class="amazon-detail">
52
- <img class="amazon-detail left" src="#{h image}"
39
+ <img class="amazon-detail left" src="#{h info['image']}"
53
40
  height="150" width="100"
54
- alt="#{h title}">
41
+ alt="#{h info['name']}">
55
42
  <span class="amazon-detail-desc">
56
- <span class="amazon-title">#{h title}</span><br>
57
- <span class="amazon-author">#{h author}</span><br>
58
- <span class="amazon-label">#{h description}</span><br>
43
+ <span class="amazon-title">#{h info['name']}</span><br>
44
+ <span class="amazon-label">#{h info['description'].split.first}</span><br>
45
+ <span class="amazon-price">#{h info['offers']['price'].to_f.to_i}円</span>
59
46
  </span><br style="clear: left">
60
47
  </span></a>
61
48
  EOS