noticesys 0.4.0 → 0.5.2
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/data/css.txt +490 -0
- data/data/microblog.txt +28 -6
- data/lib/noticesys.rb +290 -221
- data.tar.gz.sig +0 -0
- metadata +44 -23
- metadata.gz.sig +0 -0
data/lib/noticesys.rb
CHANGED
@@ -18,6 +18,7 @@ require 'recordx_sqlite'
|
|
18
18
|
# CardView - renders the HTML for a card; used within a status
|
19
19
|
# HashtagQueryView - renders the HTML for the results for a hashtag search
|
20
20
|
# SearchQueryView - renders the HTML for the results for a keyword search
|
21
|
+
# CssView - outputs the default CSS used by the microblog
|
21
22
|
|
22
23
|
module NoticeSys
|
23
24
|
|
@@ -33,29 +34,29 @@ module NoticeSys
|
|
33
34
|
|
34
35
|
# save the file attachments containing the images etc.
|
35
36
|
|
36
|
-
files = (1..3).map do |n|
|
37
|
-
|
37
|
+
files = (1..3).map do |n|
|
38
|
+
|
38
39
|
f = params['file' + n.to_s]
|
39
|
-
next unless f
|
40
|
-
|
40
|
+
next unless f
|
41
|
+
|
41
42
|
original = f[:tempfile].to_path
|
42
|
-
|
43
|
+
|
43
44
|
scale_img original
|
44
|
-
|
45
|
-
end.compact
|
46
|
-
|
45
|
+
|
46
|
+
end.compact
|
47
|
+
|
47
48
|
msg = params['msg']
|
48
49
|
|
49
50
|
urls = msg.scan(/https:\/\/[^ ]+/)
|
50
|
-
|
51
|
+
|
51
52
|
if urls.any? then
|
52
53
|
|
53
54
|
h2 = OgExtractor.new(urls.last).to_h
|
54
|
-
|
55
|
+
|
55
56
|
puts 'h2: ' + h2.inspect if @debug
|
56
|
-
|
57
|
+
|
57
58
|
if h2 then
|
58
|
-
h = {msg: msg, files: files}
|
59
|
+
h = {msg: msg, files: files}
|
59
60
|
|
60
61
|
h[:site]= h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
|
61
62
|
|
@@ -63,55 +64,55 @@ module NoticeSys
|
|
63
64
|
tmpfile = Down.download h2[:img]
|
64
65
|
files2 = scale_img tmpfile.to_path
|
65
66
|
end
|
66
|
-
|
67
|
+
|
67
68
|
h[:files] = files2 || []
|
68
|
-
h[:card] = {h2[:card] => { title: h2[:title], desc: h2[:desc],
|
69
|
+
h[:card] = {h2[:card] => { title: h2[:title], desc: h2[:desc],
|
69
70
|
url: h2[:url]}}
|
70
71
|
h[:msg] = msg.sub(urls.last,'')
|
71
72
|
|
72
73
|
return "notice/%s/json: %s" % [@user, h.to_json]
|
73
|
-
|
74
|
+
|
74
75
|
end
|
75
|
-
|
76
|
-
end
|
77
76
|
|
78
|
-
|
77
|
+
end
|
78
|
+
|
79
|
+
return "notice/%s: %s" % [@user, msg]
|
80
|
+
|
81
|
+
end
|
79
82
|
|
80
|
-
end
|
81
|
-
|
82
83
|
private
|
83
84
|
|
84
|
-
def scale_img(raworiginal)
|
85
|
+
def scale_img(raworiginal)
|
85
86
|
|
86
87
|
original = if raworiginal =~ /\.\w+$/ then
|
87
|
-
|
88
|
+
|
88
89
|
raworiginal
|
89
|
-
|
90
|
+
|
90
91
|
else
|
91
|
-
|
92
|
+
|
92
93
|
neworiginal = raworiginal + '.jpg'
|
93
94
|
FileUtils.mv raworiginal, neworiginal
|
94
95
|
neworiginal
|
95
|
-
|
96
|
+
|
96
97
|
end
|
97
|
-
|
98
|
-
res = %w(240x240 360x360 *518x389 1280x720 2048x1080)
|
98
|
+
|
99
|
+
res = %w(240x240 360x360 *518x389 1280x720 2048x1080)
|
99
100
|
a = @rmagick.resize(original, res)
|
100
101
|
a2 = (a + [nil,nil,nil]).take(res.length)
|
101
102
|
|
102
103
|
oldfile = nil
|
103
104
|
sizes = %w(240x240 360x360 small medium large)
|
104
|
-
|
105
|
+
|
105
106
|
file_sizes = a2.zip(sizes).map.with_index do |x, i|
|
106
107
|
|
107
108
|
f, label = x
|
108
109
|
|
109
|
-
if f then
|
110
|
-
|
110
|
+
if f then
|
111
|
+
|
111
112
|
f2 = f.sub(/_(n\d+x\d+)\.\w+$/) {|x| x.sub($1, label)}
|
112
113
|
|
113
114
|
FileUtils.mv f, f2
|
114
|
-
oldfile = f2
|
115
|
+
oldfile = f2
|
115
116
|
|
116
117
|
elsif oldfile
|
117
118
|
|
@@ -122,12 +123,12 @@ module NoticeSys
|
|
122
123
|
FileUtils.cp oldfile, f2
|
123
124
|
|
124
125
|
end
|
125
|
-
|
126
|
-
|
126
|
+
|
127
|
+
|
127
128
|
f2
|
128
129
|
|
129
|
-
end
|
130
|
-
|
130
|
+
end
|
131
|
+
|
131
132
|
imgfile = original.sub(/\.\w+$/,'2\0')
|
132
133
|
FileUtils.mv original, imgfile
|
133
134
|
|
@@ -135,31 +136,31 @@ module NoticeSys
|
|
135
136
|
|
136
137
|
end
|
137
138
|
|
138
|
-
end
|
139
|
-
|
140
|
-
|
139
|
+
end
|
140
|
+
|
141
|
+
|
141
142
|
class CardView
|
142
|
-
|
143
|
+
|
143
144
|
def initialize(weblet)
|
144
|
-
|
145
|
+
|
145
146
|
@w = weblet
|
146
|
-
|
147
|
+
|
147
148
|
end
|
148
|
-
|
149
|
+
|
149
150
|
def render(dx, rx, card)
|
150
|
-
|
151
|
-
card2 = case card.keys.first
|
151
|
+
|
152
|
+
card2 = case card.keys.first
|
152
153
|
when :images
|
153
|
-
|
154
|
+
|
154
155
|
card[:images].map.with_index do |img, i|
|
155
|
-
|
156
|
-
href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id,
|
156
|
+
|
157
|
+
href = [dx.link.sub(/\/$/,''), rx.topic, 'status', rx.id,
|
157
158
|
'photo', (i+1).to_s ].join('/')
|
158
159
|
url, align = img[:url], img[:align]
|
159
160
|
"<a href='%s'><div class='top-crop %s'><img class='img1' src='%s'/></div></a>" % [href, align, url]
|
160
|
-
|
161
|
+
|
161
162
|
end.join
|
162
|
-
|
163
|
+
|
163
164
|
when :summary_large_image
|
164
165
|
|
165
166
|
h2 = card[:summary_large_image]
|
@@ -170,7 +171,7 @@ module NoticeSys
|
|
170
171
|
site = h2[:url][/https?:\/\/([^\/]+)/,1].sub(/^www\./,'')
|
171
172
|
title = h2[:title]
|
172
173
|
img = h2[:img]
|
173
|
-
url = h2[:url]
|
174
|
+
url = h2[:url]
|
174
175
|
|
175
176
|
@w.render('card', binding)
|
176
177
|
|
@@ -185,45 +186,48 @@ module NoticeSys
|
|
185
186
|
title = h2[:title].length > 46 ? h2[:title][0..46] + '...' : h2[:title]
|
186
187
|
img = h2[:img]
|
187
188
|
url = h2[:url]
|
188
|
-
|
189
|
-
img_element = if img then
|
189
|
+
|
190
|
+
img_element = if img then
|
190
191
|
"<img src='#{img}'>"
|
191
192
|
else
|
192
193
|
@w.render('svg/article')
|
193
194
|
end
|
194
195
|
|
195
|
-
@w.render('card2', binding)
|
196
|
-
|
196
|
+
@w.render('card2', binding)
|
197
|
+
|
197
198
|
end
|
198
|
-
end
|
199
|
+
end
|
199
200
|
end
|
200
|
-
|
201
|
+
|
201
202
|
class StatusView
|
202
|
-
|
203
|
+
include RXFHelperModule
|
204
|
+
|
203
205
|
def initialize(basepath, xslfile, css_url, weblet)
|
204
|
-
|
206
|
+
|
205
207
|
@basepath, @xslfile, @css_url = basepath, xslfile, css_url
|
206
|
-
@w = weblet
|
208
|
+
@w = weblet
|
207
209
|
@card = CardView.new(@w)
|
208
|
-
|
210
|
+
|
209
211
|
end
|
210
|
-
|
211
|
-
def render(topic, rawid, referer)
|
212
|
+
|
213
|
+
def render(topic, rawid, referer)
|
212
214
|
|
213
215
|
id = rawid[0..9].to_i
|
214
|
-
|
216
|
+
|
215
217
|
filepath = File.join(@basepath, 'u', topic)
|
216
218
|
a = [Time.at(id).strftime("%Y/%b/%-d").downcase, rawid]
|
217
219
|
xmlfile = File.join(filepath, "%s/%s/index.xml" % a)
|
218
220
|
xslfile = File.join(@basepath, "/xsl/notices/#{topic}.xsl")
|
219
|
-
|
221
|
+
|
220
222
|
unless File.exists? xslfile then
|
221
223
|
xslfile = @xslfile
|
222
224
|
end
|
223
225
|
|
224
226
|
dx = Dynarex.new(File.join(filepath, 'feed.xml'))
|
225
|
-
|
226
|
-
|
227
|
+
s = FileX.read(xmlfile)
|
228
|
+
|
229
|
+
doc = Rexle.new(s.force_encoding("UTF-8"))
|
230
|
+
|
227
231
|
doc.root.element('summary/title').text = dx.title
|
228
232
|
e = doc.root.element('summary/image')
|
229
233
|
|
@@ -231,112 +235,148 @@ module NoticeSys
|
|
231
235
|
e = Rexle::Element.new 'image'
|
232
236
|
doc.root.element('summary').add e
|
233
237
|
end
|
234
|
-
|
238
|
+
|
235
239
|
doc.root.element('summary/image').text = dx.image
|
236
|
-
|
240
|
+
|
237
241
|
# remove the card from the description
|
238
242
|
desc = doc.root.element('body/description')
|
239
243
|
desc.xpath('img|div').each(&:delete)
|
240
244
|
|
241
245
|
doc = Nokogiri::XML(doc.root.xml)
|
242
|
-
xslt = Nokogiri::XSLT(
|
246
|
+
xslt = Nokogiri::XSLT(FileX.read(xslfile))
|
243
247
|
|
244
248
|
s = xslt.transform(doc)
|
245
249
|
doc = Rexle.new(s.to_s)
|
246
|
-
|
247
|
-
rx = Kvx.new(xmlfile)
|
250
|
+
|
251
|
+
rx = Kvx.new(xmlfile)
|
248
252
|
|
249
253
|
rawcard = rx.card
|
250
254
|
|
251
255
|
|
252
256
|
card2, meta = if rawcard and rawcard.length > 10 then
|
253
|
-
|
257
|
+
|
254
258
|
card = JSON.parse(rawcard, symbolize_names: true)
|
255
|
-
|
256
|
-
if card.is_a? Hash then
|
257
|
-
|
259
|
+
|
260
|
+
if card.is_a? Hash then
|
261
|
+
|
258
262
|
type = card.keys.first
|
259
263
|
h = card[type]
|
260
264
|
#img = h[:img].sub(/small(?=\.\w+$)/,'large')
|
261
265
|
img = h[:img]
|
262
266
|
metadata = @w.render(:meta, binding)
|
263
267
|
[@card.render(dx, rx, card), metadata]
|
264
|
-
|
268
|
+
|
265
269
|
end
|
266
270
|
else
|
267
271
|
'<span/>'
|
268
272
|
end
|
269
|
-
|
273
|
+
|
270
274
|
|
271
275
|
e = doc.root.at_css '#notice'
|
272
276
|
desc = e.at_css '#desc'
|
273
|
-
desc.add Rexle.new(card2).root
|
277
|
+
desc.add Rexle.new(card2).root
|
274
278
|
|
275
279
|
ref = referer
|
276
280
|
svg = @w.render 'svg/backarrow', binding
|
277
|
-
|
281
|
+
|
278
282
|
back = if ref then
|
279
283
|
"<div id='back'><a href='#{ref}' title='back'>#{svg}</a></div>"
|
280
284
|
else
|
281
|
-
''
|
285
|
+
"<div id='back'><a href='/' title='back'>#{svg}</a></div>"
|
282
286
|
end
|
283
|
-
|
287
|
+
|
284
288
|
@w.render :status, binding
|
285
289
|
|
286
290
|
end
|
287
|
-
|
291
|
+
|
292
|
+
end
|
293
|
+
|
294
|
+
class CssView
|
295
|
+
|
296
|
+
def initialize(weblet_file)
|
297
|
+
|
298
|
+
@weblet_file = weblet_file
|
299
|
+
|
300
|
+
end
|
301
|
+
|
302
|
+
def noticelist_css()
|
303
|
+
|
304
|
+
w = Weblet.new(@weblet_file)
|
305
|
+
|
306
|
+
lines = []
|
307
|
+
lines << w.render(:main)
|
308
|
+
lines << w.render('main/user')
|
309
|
+
lines << w.render(:notice)
|
310
|
+
lines << w.render('notice/cards')
|
311
|
+
lines << w.render('main/noticelist')
|
312
|
+
lines << w.render('main/footer')
|
313
|
+
lines.join("\n")
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
def notice_css()
|
318
|
+
|
319
|
+
w = Weblet.new(@weblet_file)
|
320
|
+
|
321
|
+
lines = []
|
322
|
+
lines << w.render(:status)
|
323
|
+
lines << w.render(:cards)
|
324
|
+
lines.join("\n")
|
325
|
+
|
326
|
+
end
|
327
|
+
|
288
328
|
end
|
289
|
-
|
329
|
+
|
290
330
|
class NoticeView
|
291
|
-
|
331
|
+
|
292
332
|
def render()
|
293
333
|
end
|
294
|
-
|
334
|
+
|
295
335
|
end
|
296
336
|
|
297
|
-
|
337
|
+
|
298
338
|
class StatusListView
|
299
|
-
|
339
|
+
|
300
340
|
def initialize(basepath, css_url, static_urlbase, weblet)
|
301
|
-
|
341
|
+
|
302
342
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
303
343
|
@w = weblet
|
304
344
|
@card = CardView.new(@w)
|
305
|
-
|
345
|
+
|
306
346
|
end
|
307
|
-
|
308
|
-
def render(username)
|
347
|
+
|
348
|
+
def render(username)
|
309
349
|
|
310
350
|
s = ''
|
311
|
-
|
351
|
+
|
312
352
|
dx = Dynarex.new(File.join(@basepath, 'u', username, 'feed.xml'))
|
313
|
-
|
353
|
+
|
314
354
|
s += @w.render 'user/ptop', binding
|
315
|
-
|
355
|
+
|
316
356
|
notices = dx.all.map do |rx|
|
317
|
-
|
357
|
+
|
318
358
|
card2 = ''
|
319
|
-
rawcard = rx.to_h[:card]
|
320
|
-
|
359
|
+
rawcard = rx.to_h[:card]
|
360
|
+
|
321
361
|
card2 = if rawcard and rawcard.length > 10 then
|
322
|
-
|
323
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
324
|
-
|
325
|
-
if card.is_a? Hash then
|
362
|
+
|
363
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
364
|
+
|
365
|
+
if card.is_a? Hash then
|
326
366
|
@card.render(dx, rx, card)
|
327
367
|
end
|
328
|
-
|
368
|
+
|
329
369
|
else
|
330
370
|
''
|
331
|
-
end
|
332
|
-
|
371
|
+
end
|
372
|
+
|
333
373
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
334
374
|
relative_time = Unichron.new(t2).elapsed
|
335
|
-
|
375
|
+
|
336
376
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
337
|
-
|
377
|
+
|
338
378
|
description = if rx.description.length > 1 then
|
339
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
379
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
340
380
|
doc.root.xpath('img|div').each(&:delete)
|
341
381
|
"<p>%s</p>" % doc.root.xml
|
342
382
|
else
|
@@ -345,39 +385,45 @@ module NoticeSys
|
|
345
385
|
|
346
386
|
utitle, uimage, ubio = dx.title, dx.image, dx.bio
|
347
387
|
@w.render :notice, binding
|
348
|
-
|
388
|
+
|
349
389
|
end
|
350
390
|
|
351
|
-
s += notices.join
|
352
|
-
s += @w.render 'user/rsslink', binding
|
391
|
+
s += notices.join
|
392
|
+
s += @w.render 'user/rsslink', binding
|
353
393
|
@w.render :user, binding
|
354
|
-
|
394
|
+
|
355
395
|
end
|
356
396
|
end
|
357
|
-
|
397
|
+
|
358
398
|
class HashtagQueryView
|
359
|
-
|
360
|
-
def initialize(basepath, css_url, weblet, static_urlbase,
|
361
|
-
|
399
|
+
|
400
|
+
def initialize(basepath, db_basepath, css_url, weblet, static_urlbase,
|
401
|
+
urlbase, debug: false)
|
402
|
+
|
362
403
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
363
|
-
@w, @urlbase = weblet, urlbase
|
404
|
+
@db_basepath, @w, @urlbase, @debug = db_basepath, weblet, urlbase, debug
|
364
405
|
@card = CardView.new(@w)
|
365
|
-
|
406
|
+
|
366
407
|
end
|
367
|
-
|
368
|
-
def render(q, referer)
|
369
|
-
#q = args.first
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
408
|
+
|
409
|
+
def render(q, referer)
|
410
|
+
#q = args.first
|
411
|
+
dbindex_path = File.join(@db_basepath, '/hashtag/index.db')
|
412
|
+
puts 'dbindex_path: ' + dbindex_path.inspect if @debug
|
413
|
+
|
414
|
+
db = RecordxSqlite.new(dbindex_path, table: 'hashtags')
|
415
|
+
|
416
|
+
|
374
417
|
a = db.find_all_by_tag q
|
375
418
|
|
376
|
-
topics = a.map(&:topic).uniq.map do |topic|
|
419
|
+
topics = a.map(&:topic).uniq.map do |topic|
|
377
420
|
|
378
421
|
topicpath = File.join(@basepath, 'u', topic)
|
379
|
-
|
380
|
-
|
422
|
+
topic_db_path = File.join(@db_basepath, 'u', topic)
|
423
|
+
|
424
|
+
db_filepath = File.join(topic_db_path, "notices.db")
|
425
|
+
puts 'db_filepath: ' + db_filepath.inspect if @debug
|
426
|
+
db = RecordxSqlite.new(db_filepath, table: 'notices')
|
381
427
|
|
382
428
|
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
383
429
|
[topic, OpenStruct.new(title: dx.title, image: dx.image, db: db)]
|
@@ -390,92 +436,93 @@ module NoticeSys
|
|
390
436
|
r = topics[x.topic]
|
391
437
|
rx = r.db.find x.noticeid
|
392
438
|
link = "%s/%s/status/%s" % [@urlbase, x.topic, x.noticeid]
|
393
|
-
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
439
|
+
OpenStruct.new(rx.to_h.merge({topic: x.topic, title: r.title,
|
394
440
|
image: r.image, bio: r.bio, link: link}))
|
395
441
|
|
396
442
|
end
|
397
|
-
|
398
|
-
|
443
|
+
|
444
|
+
|
399
445
|
s = ''
|
400
|
-
|
446
|
+
|
401
447
|
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
402
|
-
|
448
|
+
|
403
449
|
next unless rx.description
|
404
|
-
|
450
|
+
|
405
451
|
card2 = ''
|
406
|
-
rawcard = rx.to_h[:card]
|
407
|
-
|
452
|
+
rawcard = rx.to_h[:card]
|
453
|
+
|
408
454
|
card2 = if rawcard and rawcard.length > 10 then
|
409
|
-
|
410
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
411
|
-
|
412
|
-
if card.is_a? Hash then
|
455
|
+
|
456
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
457
|
+
|
458
|
+
if card.is_a? Hash then
|
413
459
|
@card.render(dx, rx, card)
|
414
460
|
end
|
415
|
-
|
461
|
+
|
416
462
|
else
|
417
463
|
''
|
418
|
-
end
|
419
|
-
|
464
|
+
end
|
465
|
+
|
420
466
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
421
467
|
relative_time = Unichron.new(t2).elapsed
|
422
|
-
|
468
|
+
|
423
469
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
424
|
-
|
470
|
+
|
425
471
|
description = if rx.description.length > 1 then
|
426
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
472
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
427
473
|
doc.root.xpath('img|div').each(&:delete)
|
428
474
|
"<p>%s</p>" % doc.root.xml
|
429
475
|
else
|
430
476
|
''
|
431
|
-
end
|
477
|
+
end
|
432
478
|
|
433
479
|
utitle, uimage, ubio = rx.title, rx.image, rx.bio
|
434
480
|
@w.render :notice, binding
|
435
|
-
|
436
|
-
end
|
437
|
-
|
481
|
+
|
482
|
+
end
|
483
|
+
|
438
484
|
s += if notices.any? then
|
439
|
-
notices.compact.join
|
485
|
+
notices.compact.join
|
440
486
|
else
|
441
487
|
"<p>No results for #{q}</p>"
|
442
488
|
end
|
443
|
-
|
489
|
+
|
444
490
|
ref = referer
|
445
|
-
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
446
|
-
|
491
|
+
ref = '../' if ref =~ /(?:status|hashtag)\/\d+/
|
492
|
+
|
447
493
|
svg = @w.render 'svg/backarrow', binding
|
448
494
|
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
449
|
-
|
495
|
+
|
450
496
|
@w.render :search_pg, binding
|
451
|
-
|
497
|
+
|
452
498
|
end
|
453
|
-
|
454
|
-
|
499
|
+
|
500
|
+
|
455
501
|
end
|
456
|
-
|
502
|
+
|
457
503
|
class SearchQueryView
|
458
|
-
|
459
|
-
def initialize(basepath, css_url, weblet, static_urlbase, urlbase)
|
460
|
-
|
504
|
+
|
505
|
+
def initialize(basepath, db_basepath, css_url, weblet, static_urlbase, urlbase)
|
506
|
+
|
461
507
|
@basepath, @css_url, @static_urlbase = basepath, css_url, static_urlbase
|
462
|
-
@w, @urlbase = weblet, urlbase
|
508
|
+
@db_basepath, @w, @urlbase = db_basepath, weblet, urlbase
|
463
509
|
@card = CardView.new(@w)
|
464
|
-
|
510
|
+
|
465
511
|
end
|
466
|
-
|
467
|
-
def render(q, referer)
|
468
|
-
|
512
|
+
|
513
|
+
def render(q, referer)
|
514
|
+
|
469
515
|
|
470
516
|
users = Dir.glob(File.join(@basepath, 'u', '*')).map do |x|
|
471
517
|
File.basename(x)
|
472
518
|
end
|
473
519
|
|
474
|
-
topics = users.map do |topic|
|
520
|
+
topics = users.map do |topic|
|
475
521
|
|
476
522
|
topicpath = File.join(@basepath, 'u', topic)
|
477
|
-
|
478
|
-
|
523
|
+
topic_db_path = File.join(@db_basepath, 'u', topic)
|
524
|
+
db_filepath = File.join(topic_db_path, "notices.db")
|
525
|
+
db = RecordxSqlite.new(db_filepath, table: 'notices')
|
479
526
|
|
480
527
|
dx = Dynarex.new(File.join(topicpath, 'feed.xml'))
|
481
528
|
[topic, OpenStruct.new(title: dx.title, image: dx.image, bio: dx.bio, db: db)]
|
@@ -485,104 +532,125 @@ module NoticeSys
|
|
485
532
|
#return topics.inspect
|
486
533
|
rows = topics.flat_map do |topic, r|
|
487
534
|
|
488
|
-
a = r.db.all.select {|x| x.description =~ /#{q}/i}
|
535
|
+
a = r.db.all.select {|x| x.description =~ /#{q.gsub('$',"\\$")}/i}
|
489
536
|
a.map do |rx|
|
490
537
|
link = "%s/%s/status/%s" % [@urlbase, topic, rx.noticeid]
|
491
538
|
OpenStruct.new(rx.to_h.merge({topic: topic, title: r.title, image: r.image, link: link}))
|
492
539
|
end
|
493
540
|
|
494
541
|
end
|
495
|
-
|
496
|
-
|
497
|
-
#return rows.inspect
|
542
|
+
|
543
|
+
|
544
|
+
#return rows.inspect
|
498
545
|
s = ''
|
499
|
-
|
546
|
+
|
500
547
|
notices = rows.sort_by {|x| -(x.id.to_i)}.take(20).map do |rx|
|
501
|
-
|
502
|
-
|
548
|
+
|
549
|
+
|
503
550
|
card2 = ''
|
504
|
-
rawcard = rx.to_h[:card]
|
505
|
-
|
551
|
+
rawcard = rx.to_h[:card]
|
552
|
+
|
506
553
|
card2 = if rawcard and rawcard.length > 10 then
|
507
|
-
|
508
|
-
card = JSON.parse(rawcard, symbolize_names: true)
|
509
|
-
|
510
|
-
if card.is_a? Hash then
|
554
|
+
|
555
|
+
card = JSON.parse(rawcard, symbolize_names: true)
|
556
|
+
|
557
|
+
if card.is_a? Hash then
|
511
558
|
@card.render(dx, rx, card)
|
512
559
|
end
|
513
|
-
|
560
|
+
|
514
561
|
else
|
515
562
|
''
|
516
|
-
end
|
517
|
-
|
563
|
+
end
|
564
|
+
|
518
565
|
#rx.description
|
519
566
|
t2 = Time.at rx.id.to_s[0..9].to_i
|
520
567
|
relative_time = Unichron.new(t2).elapsed
|
521
|
-
|
568
|
+
|
522
569
|
d = t2.strftime("%I:%M%p %b %d %Y")
|
523
|
-
|
570
|
+
|
524
571
|
#desc = rx.description.gsub(/<\/?p>/,'').gsub('<','<').gsub('>','>')
|
525
|
-
|
572
|
+
|
526
573
|
topic = rx.topic
|
527
574
|
title, image, bio = %i(title image bio).map do |x|
|
528
575
|
topics[topic].method(x).call
|
529
576
|
end
|
530
|
-
|
577
|
+
|
531
578
|
description = if rx.description.length > 1 then
|
532
|
-
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
579
|
+
doc = Rexle.new "<node>%s</node>" % rx.description.gsub(/<\/?p>/,'')
|
533
580
|
doc.root.xpath('img|div').each(&:delete)
|
534
581
|
"<p>%s</p>" % doc.root.xml
|
535
582
|
else
|
536
583
|
''
|
537
|
-
end
|
538
|
-
|
584
|
+
end
|
585
|
+
|
539
586
|
utitle, uimage, ubio = title, image, bio
|
540
587
|
@w.render :notice, binding
|
541
588
|
|
542
589
|
|
543
590
|
end
|
544
591
|
#return notices.inspect
|
545
|
-
|
592
|
+
|
546
593
|
s += if notices.any? then
|
547
|
-
notices.join
|
594
|
+
notices.join
|
548
595
|
else
|
549
596
|
"<p>No results for #{q}</p>"
|
550
597
|
end
|
551
|
-
|
598
|
+
|
552
599
|
#ref = @env["HTTP_REFERER"]
|
553
600
|
ref = referer
|
554
601
|
ref = '../' if ref =~ /(?:status\/\d+|search)/
|
555
602
|
svg = @w.render 'svg/backarrow', binding
|
556
|
-
back = ref ? "<a href='#{ref}'>#{svg}</a>" : ''
|
557
|
-
|
603
|
+
back = ref ? "<a href='#{ref}'>#{svg}</a>" : "<a href='/'>#{svg}</a>"
|
604
|
+
|
558
605
|
@w.render :search_pg, binding
|
559
|
-
|
560
|
-
|
606
|
+
|
607
|
+
|
561
608
|
end
|
562
|
-
|
563
|
-
|
564
|
-
end
|
565
|
-
|
609
|
+
|
610
|
+
|
611
|
+
end
|
612
|
+
|
566
613
|
class Main
|
567
|
-
|
568
|
-
def initialize(basepath, xslfile, statuscss_url,
|
569
|
-
weblet_file, static_urlbase,
|
570
|
-
|
571
|
-
|
614
|
+
|
615
|
+
def initialize(basepath, db_basepath, xslfile, statuscss_url,
|
616
|
+
statuslistcss_url, weblet_file, static_urlbase,
|
617
|
+
urlbase, weblet_cssfile, debug: false)
|
618
|
+
|
619
|
+
weblet_file ||= File.join(File.dirname(__FILE__), '..',
|
620
|
+
'data', 'microblog.txt')
|
621
|
+
|
622
|
+
weblet = Weblet.new(weblet_file)
|
623
|
+
|
572
624
|
@status = StatusView.new(basepath, xslfile, statuscss_url, weblet)
|
573
|
-
|
625
|
+
|
626
|
+
@statuslist = StatusListView.new(basepath, statuslistcss_url,
|
574
627
|
static_urlbase, weblet)
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
static_urlbase, urlbase)
|
579
|
-
|
628
|
+
|
629
|
+
@hashtag = HashtagQueryView.new(basepath, db_basepath,
|
630
|
+
statuslistcss_url, weblet,
|
631
|
+
static_urlbase, urlbase, debug: debug)
|
632
|
+
|
633
|
+
@search = SearchQueryView.new(basepath, db_basepath, statuslistcss_url,
|
634
|
+
weblet, static_urlbase, urlbase)
|
635
|
+
|
636
|
+
weblet_cssfile ||= File.join(File.dirname(__FILE__), '..',
|
637
|
+
'data', 'css.txt')
|
638
|
+
@css = CssView.new(weblet_cssfile)
|
639
|
+
|
580
640
|
end
|
581
|
-
|
641
|
+
|
642
|
+
def notice_css()
|
643
|
+
@css.notice_css()
|
644
|
+
end
|
645
|
+
|
646
|
+
def noticelist_css()
|
647
|
+
@css.noticelist_css()
|
648
|
+
end
|
649
|
+
|
582
650
|
def status(topic, rawid, referer)
|
583
651
|
@status.render topic, rawid, referer
|
584
652
|
end
|
585
|
-
|
653
|
+
|
586
654
|
def status_list(username)
|
587
655
|
@statuslist.render username
|
588
656
|
end
|
@@ -590,11 +658,12 @@ module NoticeSys
|
|
590
658
|
def hashtag_query(s, referer)
|
591
659
|
@hashtag.render s, referer
|
592
660
|
end
|
593
|
-
|
661
|
+
|
594
662
|
def search_query(s, referer)
|
595
663
|
@search.render s, referer
|
596
|
-
end
|
597
|
-
|
664
|
+
end
|
665
|
+
|
666
|
+
|
598
667
|
end
|
599
|
-
|
600
|
-
end
|
668
|
+
|
669
|
+
end
|