~ubuntu-branches/ubuntu/saucy/tdiary/saucy-proposed

« back to all changes in this revision

Viewing changes to misc/plugin/makerss.rb

  • Committer: Bazaar Package Importer
  • Author(s): Daigo Moriwaki
  • Date: 2011-04-11 21:53:16 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110411215316-ih4gt4q8p29d2wf8
Tags: 3.0.1-1
* New upstream release (Closes: #542801, #594947)
* debian/control:
 - Bumped up Standards-Version to 3.9.1.
 - Updated version dependency.
* debian/tdiary-setup.rb: Followed the upstream changes, incorporating js and
  index.fcgi

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# makerss.rb: $Revision: 1.58 $
 
1
# makerss.rb
2
2
#
3
3
# generate RSS file when updating.
4
4
#
24
24
#   CAUTION: Before using, make 'index.rdf' and 'no_comments.rdf' file
25
25
#            into the directory of your diary, and permit writable to httpd.
26
26
#
27
 
# Copyright (c) 2004 TADA Tadashi <sho@spc.gr.jp>
 
27
# Copyright (c) 2009 TADA Tadashi <t@tdtds.jp>
28
28
# Distributed under the GPL
29
29
#
30
30
 
32
32
        unless @conf.description
33
33
                @conf.description = @conf['whatsnew_list.rdf.description']
34
34
        end
35
 
        eval( <<-TOPLEVEL_CLASS, TOPLEVEL_BINDING )
36
 
                module TDiary
37
 
                        class RDFSection
38
 
                                attr_reader :id, :time, :section, :diary_title
39
 
 
40
 
                                # 'id' has 'YYYYMMDDpNN' format (p or c).
41
 
                                # 'time' is Last-Modified this section as a Time object.
42
 
                                def initialize( id, time, section )
43
 
                                        @id, @time, @section, @diary_title = id, time, section, diary_title
44
 
                                end
45
 
 
46
 
                                def time_string
47
 
                                        g = @time.dup.gmtime
48
 
                                        l = Time::local( g.year, g.month, g.day, g.hour, g.min, g.sec )
49
 
                                        tz = (g.to_i - l.to_i)
50
 
                                        zone = sprintf( "%+03d:%02d", tz / 3600, tz % 3600 / 60 )
51
 
                                        @time.strftime( "%Y-%m-%dT%H:%M:%S" ) + zone
52
 
                                end
53
 
 
54
 
                                def <=>( other )
55
 
                                        other.time <=> @time
56
 
                                end
 
35
        module ::TDiary
 
36
                class RDFSection
 
37
                        attr_reader :id, :time, :section, :diary_title
 
38
 
 
39
                        # 'id' has 'YYYYMMDDpNN' format (p or c).
 
40
                        # 'time' is Last-Modified this section as a Time object.
 
41
                        def initialize( id, time, section )
 
42
                                @id, @time, @section, @diary_title = id, time, section, diary_title
 
43
                        end
 
44
 
 
45
                        def time_string
 
46
                                g = @time.dup.gmtime
 
47
                                l = Time::local( g.year, g.month, g.day, g.hour, g.min, g.sec )
 
48
                                tz = (g.to_i - l.to_i)
 
49
                                zone = sprintf( "%+03d:%02d", tz / 3600, tz % 3600 / 60 )
 
50
                                @time.strftime( "%Y-%m-%dT%H:%M:%S" ) + zone
 
51
                        end
 
52
 
 
53
                        def <=>( other )
 
54
                                other.time <=> @time
57
55
                        end
58
56
                end
59
 
        TOPLEVEL_CLASS
 
57
        end
60
58
end
61
59
 
62
60
@makerss_rsses = @makerss_rsses || []
286
284
        <channel rdf:about="#{h rdf_url}">
287
285
        <title>#{h @conf.html_title}</title>
288
286
        <link>#{h uri}</link>
289
 
        <xhtml:link rel="alternate" media="handheld" type="text/html" href="#{h uri}" />
 
287
        <xhtml:link xhtml:rel="alternate" xhtml:media="handheld" xhtml:type="text/html" xhtml:href="#{h uri}" />
290
288
        <description>#{h desc}</description>
291
289
        <dc:creator>#{h @conf.author_name}</dc:creator>
292
290
        <dc:rights>#{h copyright}</dc:rights>
326
324
        if rdfsec.section.respond_to?( :body_to_html ) then
327
325
                rdf = %Q|<item rdf:about="#{h uri}#{anchor rdfsec.id}">\n|
328
326
                rdf << %Q|<link>#{h uri}#{anchor rdfsec.id}</link>\n|
329
 
                rdf << %Q|<xhtml:link rel="alternate" media="handheld" type="text/html" href="#{h uri}#{anchor rdfsec.id}" />\n|
 
327
                rdf << %Q|<xhtml:link xhtml:rel="alternate" xhtml:media="handheld" xhtml:type="text/html" xhtml:href="#{h uri}#{anchor rdfsec.id}" />\n|
330
328
                rdf << %Q|<dc:date>#{h rdfsec.time_string}</dc:date>\n|
331
329
                a = rdfsec.id.scan( /(\d{4})(\d\d)(\d\d)/ ).flatten.map{|s| s.to_i}
332
330
                date = Time::local( *a )
341
339
                body_leave = body_leave_proc( date )
342
340
                @makerss_in_feed = false
343
341
 
344
 
                sub = apply_plugin( subtitle, true ).strip
345
 
                sub.sub!( /^(\[([^\]]+)\])+ */, '' )
 
342
                sub = (subtitle || '').sub( /^(\[([^\]]+)\])+ */, '' )
 
343
                sub = apply_plugin( sub, true ).strip
346
344
                if sub.empty?
347
345
                        sub = @conf.shorten( remove_tag( body ).strip, 20 )
348
346
                end
363
361
                        text << body
364
362
                        text << body_leave
365
363
                        unless text.empty?
 
364
                                uri = @conf.index.dup
 
365
                                uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri
 
366
                                uri.gsub!( %r|/\./|, '/' )
 
367
                                text = absolutify( text, uri )
366
368
                                text.gsub!( /\]\]>/, ']]]]><![CDATA[>' )
367
369
                                rdf << %Q|<content:encoded><![CDATA[#{text}|
368
 
            unless @conf['makerss.comment_link']
369
 
               ymd = date.strftime( "%Y%m%d" )
370
 
               uri = @conf.index.dup
371
 
               uri[0, 0] = @conf.base_url unless %r|^https?://|i =~ uri
372
 
               uri.gsub!( %r|/\./|, '/' )
373
 
               rdf << %Q|\n<p><a href="#{h uri}#{anchor "#{ymd}c"}">#{comment_new}</a></p>|
374
 
            end
375
 
            rdf << %Q|]]></content:encoded>\n|
 
370
                                unless @conf['makerss.comment_link']
 
371
                                        ymd = date.strftime( "%Y%m%d" )
 
372
                                        rdf << %Q|\n<p><a href="#{h uri}#{anchor "#{ymd}c"}">#{comment_new}</a></p>|
 
373
                                end
 
374
                                rdf << %Q|]]></content:encoded>\n|
376
375
                        end
377
376
                end
378
377
 
430
429
end
431
430
 
432
431
add_edit_proc do
433
 
        checked = @cgi.params['makerss_update'][0] == 'false' ? ' checked' : ''
 
432
        checked = if @cgi.params['makerss_update'][0] == 'false' then
 
433
                ' checked'
 
434
        elsif @date < (Time::now - 30*24*60*60) # older over a month
 
435
                ' checked'
 
436
        else
 
437
                ''
 
438
        end
434
439
        r = <<-HTML
435
440
        <div class="makerss"><label for="makerss_update">
436
441
        <input type="checkbox" id="makerss_update" name="makerss_update" value="false"#{checked} tabindex="390">
474
479
                        '&frac12;' => '&#189;',
475
480
                        '&frac34;' => '&#190;',
476
481
                        '&iquest;' => '&#191;',
477
 
                        '&agrave;' => '&#192;',
478
 
                        '&aacute;' => '&#193;',
479
 
                        '&acirc;' => '&#194;',
480
 
                        '&atilde;' => '&#195;',
481
 
                        '&auml;' => '&#196;',
482
 
                        '&aring;' => '&#197;',
483
 
                        '&aelig;' => '&#198;',
484
 
                        '&ccedil;' => '&#199;',
485
 
                        '&egrave;' => '&#200;',
486
 
                        '&eacute;' => '&#201;',
487
 
                        '&ecirc;' => '&#202;',
488
 
                        '&euml;' => '&#203;',
489
 
                        '&igrave;' => '&#204;',
490
 
                        '&iacute;' => '&#205;',
491
 
                        '&icirc;' => '&#206;',
492
 
                        '&iuml;' => '&#207;',
493
 
                        '&eth;' => '&#208;',
494
 
                        '&ntilde;' => '&#209;',
495
 
                        '&ograve;' => '&#210;',
496
 
                        '&oacute;' => '&#211;',
497
 
                        '&ocirc;' => '&#212;',
498
 
                        '&otilde;' => '&#213;',
499
 
                        '&ouml;' => '&#214;',
 
482
                        '&Agrave;' => '&#192;',
 
483
                        '&Aacute;' => '&#193;',
 
484
                        '&Acirc;' => '&#194;',
 
485
                        '&Atilde;' => '&#195;',
 
486
                        '&Auml;' => '&#196;',
 
487
                        '&Aring;' => '&#197;',
 
488
                        '&Aelig;' => '&#198;',
 
489
                        '&Ccedil;' => '&#199;',
 
490
                        '&Egrave;' => '&#200;',
 
491
                        '&Eacute;' => '&#201;',
 
492
                        '&Ecirc;' => '&#202;',
 
493
                        '&Euml;' => '&#203;',
 
494
                        '&Igrave;' => '&#204;',
 
495
                        '&Iacute;' => '&#205;',
 
496
                        '&Icirc;' => '&#206;',
 
497
                        '&Iuml;' => '&#207;',
 
498
                        '&ETH;' => '&#208;',
 
499
                        '&Ntilde;' => '&#209;',
 
500
                        '&Ograve;' => '&#210;',
 
501
                        '&Oacute;' => '&#211;',
 
502
                        '&Ocirc;' => '&#212;',
 
503
                        '&Otilde;' => '&#213;',
 
504
                        '&Ouml;' => '&#214;',
500
505
                        '&times;' => '&#215;',
501
 
                        '&oslash;' => '&#216;',
502
 
                        '&ugrave;' => '&#217;',
503
 
                        '&uacute;' => '&#218;',
504
 
                        '&ucirc;' => '&#219;',
505
 
                        '&uuml;' => '&#220;',
506
 
                        '&yacute;' => '&#221;',
507
 
                        '&thorn;' => '&#222;',
 
506
                        '&Oslash;' => '&#216;',
 
507
                        '&Ugrave;' => '&#217;',
 
508
                        '&Uacute;' => '&#218;',
 
509
                        '&Ucirc;' => '&#219;',
 
510
                        '&Uuml;' => '&#220;',
 
511
                        '&Yacute;' => '&#221;',
 
512
                        '&THORN;' => '&#222;',
508
513
                        '&szlig;' => '&#223;',
509
514
                        '&agrave;' => '&#224;',
510
515
                        '&aacute;' => '&#225;',
561
566
                        '&rdquo;' => '&#8221;',
562
567
                        '&bdquo;' => '&#8222;',
563
568
                        '&dagger;' => '&#8224;',
564
 
                        '&dagger;' => '&#8225;',
 
569
                        '&Dagger;' => '&#8225;',
565
570
                        '&permil;' => '&#8240;',
566
571
                        '&lsaquo;' => '&#8249;',
567
572
                        '&rsaquo;' => '&#8250;',
568
573
                        '&euro;' => '&#8364;',
569
574
                        '&fnof;' => '&#402;',
570
 
                        '&alpha;' => '&#913;',
571
 
                        '&beta;' => '&#914;',
572
 
                        '&gamma;' => '&#915;',
573
 
                        '&delta;' => '&#916;',
574
 
                        '&epsilon;' => '&#917;',
575
 
                        '&zeta;' => '&#918;',
576
 
                        '&eta;' => '&#919;',
577
 
                        '&theta;' => '&#920;',
578
 
                        '&iota;' => '&#921;',
579
 
                        '&kappa;' => '&#922;',
580
 
                        '&lambda;' => '&#923;',
581
 
                        '&mu;' => '&#924;',
582
 
                        '&nu;' => '&#925;',
583
 
                        '&xi;' => '&#926;',
584
 
                        '&omicron;' => '&#927;',
585
 
                        '&pi;' => '&#928;',
586
 
                        '&rho;' => '&#929;',
587
 
                        '&sigma;' => '&#931;',
588
 
                        '&tau;' => '&#932;',
589
 
                        '&upsilon;' => '&#933;',
590
 
                        '&phi;' => '&#934;',
591
 
                        '&chi;' => '&#935;',
592
 
                        '&psi;' => '&#936;',
593
 
                        '&omega;' => '&#937;',
 
575
                        '&Alpha;' => '&#913;',
 
576
                        '&Beta;' => '&#914;',
 
577
                        '&Gamma;' => '&#915;',
 
578
                        '&Delta;' => '&#916;',
 
579
                        '&Epsilon;' => '&#917;',
 
580
                        '&Zeta;' => '&#918;',
 
581
                        '&Eta;' => '&#919;',
 
582
                        '&Theta;' => '&#920;',
 
583
                        '&Iota;' => '&#921;',
 
584
                        '&Kappa;' => '&#922;',
 
585
                        '&Lambda;' => '&#923;',
 
586
                        '&Mu;' => '&#924;',
 
587
                        '&Nu;' => '&#925;',
 
588
                        '&Xi;' => '&#926;',
 
589
                        '&Omicron;' => '&#927;',
 
590
                        '&Pi;' => '&#928;',
 
591
                        '&Rho;' => '&#929;',
 
592
                        '&Sigma;' => '&#931;',
 
593
                        '&Tau;' => '&#932;',
 
594
                        '&Upsilon;' => '&#933;',
 
595
                        '&Phi;' => '&#934;',
 
596
                        '&Chi;' => '&#935;',
 
597
                        '&Psi;' => '&#936;',
 
598
                        '&Omega;' => '&#937;',
594
599
                        '&alpha;' => '&#945;',
595
600
                        '&beta;' => '&#946;',
596
601
                        '&gamma;' => '&#947;',
635
640
                        '&darr;' => '&#8595;',
636
641
                        '&harr;' => '&#8596;',
637
642
                        '&crarr;' => '&#8629;',
638
 
                        '&larr;' => '&#8656;',
639
 
                        '&uarr;' => '&#8657;',
640
 
                        '&rarr;' => '&#8658;',
641
 
                        '&darr;' => '&#8659;',
642
 
                        '&harr;' => '&#8660;',
 
643
                        '&lArr;' => '&#8656;',
 
644
                        '&uArr;' => '&#8657;',
 
645
                        '&rArr;' => '&#8658;',
 
646
                        '&dArr;' => '&#8659;',
 
647
                        '&hArr;' => '&#8660;',
643
648
                        '&forall;' => '&#8704;',
644
649
                        '&part;' => '&#8706;',
645
650
                        '&exist;' => '&#8707;',
692
697
                }
693
698
        end
694
699
        text.gsub( /&[a-z]+;/im ) do |e|
695
 
                @xml_entity_table[e.downcase] || e
696
 
        end
697
 
end
 
700
                @xml_entity_table[e] || e
 
701
        end
 
702
end
 
703
 
 
704
# Copied from below which includes some tests
 
705
# http://github.com/zunda/ruby-absolutify/tree/master
 
706
def absolutify(html, baseurl)
 
707
        @@_absolutify_attr_regexp ||= Hash.new
 
708
        baseuri = URI.parse(URI.encode(baseurl))
 
709
        r = html.gsub(%r|<\S[^>]*/?>|) do |tag|
 
710
                type = tag.scan(/\A<(\S+)/)[0][0].downcase
 
711
                if attr = {'a' => 'href', 'img' => 'src'}[type]
 
712
                        @@_absolutify_attr_regexp[attr] ||= %r|(.*#{attr}\s*=\s*)(['"]?)([^\2>]+?)(\2.*)|im
 
713
                        m = tag.match(@@_absolutify_attr_regexp[attr])
 
714
                        unless m.nil?
 
715
                                prefix = m[1] + m[2]
 
716
                                location = m[3]
 
717
                                postfix = m[4]
 
718
                                begin
 
719
                                        uri = URI.parse(location)
 
720
                                        if uri.relative?
 
721
                                                location = (baseuri + location).to_s
 
722
                                        elsif not uri.host
 
723
                                                path = uri.path
 
724
                                                path += '?' + uri.query if uri.query
 
725
                                                path += '#' + uri.fragment if uri.fragment
 
726
                                                location = (baseuri + path).to_s
 
727
                                        end
 
728
                                        tag = prefix + location + postfix
 
729
                                rescue URI::InvalidURIError
 
730
                                end
 
731
                        end
 
732
                end
 
733
                tag
 
734
        end
 
735
        return r
 
736
end
 
737
 
 
738
# Local Variables:
 
739
# mode: ruby
 
740
# indent-tabs-mode: t
 
741
# tab-width: 3
 
742
# ruby-indent-level: 3
 
743
# End: