aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/0.52/html_promo.rb
blob: b41b1ffaf99dde4bf19b633bdea4df2bba38f2f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
=begin
 * Name: SiSU information Structuring Universe - Structured information, Serialized Units
 * Author: Ralph Amissah
   * http://www.jus.uio.no/sisu
   * http://www.jus.uio.no/sisu/SiSU/download.html

 * Description: html advertising component, build here, mockup

 * Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Ralph Amissah

 * License: GPL 2 or later

  Summary of GPL 2

  This program is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published by the Free
  Software Foundation; either version 2 of the License, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

  If you have Internet connection, the latest version of the GPL should be
  available at these locations:
    http://www.fsf.org/licenses/gpl.html
    http://www.gnu.org/copyleft/gpl.html
    http://www.jus.uio.no/sisu/gpl2.fsf

  SiSU was first released to the public on January 4th 2005

  SiSU uses:
  
  *  Standard SiSU markup syntax,
  *  Standard SiSU meta-markup syntax, and the
  *  Standard SiSU object citation numbering and system
  
  © Ralph Amissah 1997, current 2007.
  All Rights Reserved.

 * Ralph Amissah: ralph@amissah.com
                  ralph.amissah@gmail.com
=end
module SiSU_HTML_promo
  require SiSU_lib + '/sysenv'
  include SiSU_Env
  class Ad
    def initialize(md)
      @md=md
      @env=SiSU_Env::Info_env.new(@md.fns,@md)
      @rc=SiSU_Env::Get_init.instance.yamlrc
      @ad=SiSU_Env::Get_init.instance.ads
      @vz=SiSU_Env::Get_init.instance.skin
      @flag=@env.widget.promo?
    end
    def div
      def major
        @flag[:ad] ? '<div id="pane_major">' : ''
      end
      def minor
        @flag[:ad] ? '<div id="pane_minor">' : ''
      end
      def close
        @flag[:ad] ? '</div>' : ''
      end
      self
    end
    def display #(type=nil,id=nil)
      ads_array,promo_array=[],[]
      if @flag[:ad]
        ads=if @md.promo && @md.promo.length > 0           #promo set in document
          promo_array=@md.promo
        elsif @flag[:sk]                                   #promo set in associated skin
          promo_array=@vz.widget_promo
        elsif @flag[:rc]                                   #promo set in rc file
          promo_array=if @rc['promo'].class == String
            @rc['promo'].split(/[,;]\s*/)
          else @rc['promo']
          end
        else advert_extract_all
        end
        ads=if promo_array.length > 0
          promo_array.each do |x|
            ads_array << advert_extract_subject(x)
          end
          ads_array
        end
        adverts(ads)
      #else no_adverts
      end
    end
    def cell(prod,id)
      @prod,@id=prod,id
      def title
        @prod['title'] ? %{<b>#{@prod['title']}</b>} : ''
      end
      def subtitle
        @prod['subtitle'] ? %{ - #{@prod['subtitle']}} : ''
      end
      def author
        @prod['author'] ? %{<p class="pane">#{@prod['author']}</p>} : ''
      end
      def editor
        @prod['editor'] ? %{<p class="pane">#{@prod['editor']}</p>} : ''
      end
      def year
        @prod['year'] ? %{<p class="pane">#{@prod['year']}</p>} : ''
      end
      def date
        @prod['date'] ? %{<p class="pane">On: #{@prod['date']}</p>} : ''
      end
      def location
        @prod['at'] ? %{<p class="pane">At: #{@prod['at']}</p>} : ''
      end
      def pages
        @prod['pages'] ? %{<p class="pane">Pages: #{@prod['pages']} pages</p>} : ''
      end
      def form
        @prod['form'] ? %{<p class="pane">#{@prod['form']}</p>} : ''
      end
      def nick
        @prod['nick'] ? %{(#{@prod['nick']})<br />} : ''
      end
      def update
        @prod['update'] ? %{<p class="pane">Updated: #{@prod['update']}</p>} : ''
      end
      def issn
        @prod['issn'] ? %{<p class="pane">issn: #{@prod['issn']}</p>} : ''
      end
      def blurb
        @prod['blurb'] ? %{<p class="pane_blurb">#{@prod['blurb']}</p>} : ''
      end
      def search_form
        db=if @prod['db']=~/\S+/
          @prod['db']=~/^SiSU_\S+/ ? @prod['db'] : "SiSU_#{@prod['db']}"
        elsif defined? @rc['search']['db'] and @rc['search']['db'] =~/\S+/
          @rc['search']['db']=~/^SiSU_\S+/ ? @prod['search']['db'] : "SiSU_#{@prod['db']}"
        else nil
        end
        #target=@prod['target']=~/^\S+/ ? @prod['target'] : '_top'
        action=if @prod['action']=~/^http:\/\// 
          @prod['action']
        elsif defined? @rc['search']['action'] and @rc['search']['action'] =~/^http:\/\//
          @rc['search']['action']
        else nil
        end
        form=if action and db
          '<br />' + @env.widget.search_form(action,db)
        else ''
        end
      end
      def links
        if @prod['links'] #and @prod['links'] == Array
          links_a=[]
          @prod['links'].each do |x|
            if x and x['url'] and x['title']
              subtitle=x['subtitle'] ? %{ - #{x['subtitle']}} : ''
              url_=x['url'] =~/http:/ ? x['url'] : "../#{x['url']}"
              #url_=x['url'] =~/http:/ ? x['url'] : "#{@env.url.root}/#{x['url']}"
              links_a << %{<p class="pane_link"><a href="#{url_}">#{x['title']}#{subtitle}</a></p>\n}
            end
          end
          links_a.to_s
        else ''
        end
      end
      def image
        @prod['image'] ? %{<img border="0" src="../_sisu/image_local/#{@prod['image']}" /><br />} : ''
      end
      def url_link
        @url_=if @prod['url'] =~/http:/
          "#{@prod['url']}"
        else "../#{@prod['url']}" # "#{@env.url.root}/#{@prod['url']}"
        end
        def show
          @prod['url'] ? %{<p class="pane_link"><a href="#@url_">#@url_</a></p>} : ''
        end
        def url
          @prod['url'] ? %{<a href="#@url_">} : ''
        end
        def url_relative
          @prod['url'] ? %{<a href="../#{@prod['url']}/toc.html">} : ''
        end
        self
      end
      def flyer
        if @prod['flyer']
          %{<p class="pane"><a href="../man/pdf/#@id.pdf"><img border="0" height="18" width="15" src="../_sisu/image/b_pdf.png">&nbsp;PDF&nbsp;flyer</a></p>}
        else ''
        end
      end
      def price
        def gbp
          if defined? @prod['price']['gbp'] and @prod['price']['gbp']
            " &nbsp;&pound;&nbsp;#{@prod['price']['gbp']}&nbsp;(GBP)&nbsp;"
          else ''
          end
        end
        def euro
          if defined? @prod['price']['euro'] and @prod['price']['euro']
            " &nbsp;&euro;&nbsp;#{@prod['price']['euro']}&nbsp;(Euro)&nbsp;"
          else ''
          end
        end
        def usd
          if defined? @prod['price']['usd'] and @prod['price']['usd']
            " &nbsp;$&nbsp;#{@prod['price']['usd']}&nbsp;(USD)&nbsp;"
          else ''
          end
        end
        %{<p class="pane">Price:#{gbp}#{euro}#{usd}</p>}
      end
      def site_link #Work area
        if url_link.url
           <<WOK
<p class="pane">
#{url_link.url}
#{image}
#{title}
#{subtitle}
</a>#{nick}</p>
WOK
        else
         <<WOK
<p class="pane">
#{image}
#{title}
#{subtitle}
</p>
WOK
        end
      end
      self
    end
    def output_form_sponsor(type,id)
      cell=cell(@ad[:promo][type][id],prod_id)
      prod_type=id=~/id_(?:[0-9x]){10,13}/i ? 'isbn' : 'id'
      id_detail = %{<p class="pane">#{prod_type}: #{prod_id}</p>}
       <<WOK
<br />
#{cell.site_link}
#{cell.blurb}
#{cell.links}
WOK
    end
    def output_form_link(type,id)
      prod_id=id.gsub(/id_/,'')
      cell=cell(@ad[:promo][type][id],prod_id)
       <<WOK
<br />
#{cell.site_link}
#{cell.author}
#{cell.year}
#{cell.blurb}
#{cell.links}
WOK
    end
    def output_form_search(type,id)
      prod_id=id.gsub(/id_/,'')
      cell=cell(@ad[:promo][type][id],prod_id)
      cell.search_form
    end
    def output_form_book(type,id)
      prod_id=id.gsub(/id_/,'')
      cell=cell(@ad[:promo][type][id],prod_id)
      prod_type=id=~/id_(?:[0-9x]){10,13}/i ? 'isbn' : 'id'
      id_detail = %{<p class="pane">#{prod_type}: #{prod_id}</p>}
       <<WOK
<br />
#{cell.site_link}
#{cell.author}
#{cell.year}
#{id_detail}
#{cell.pages}#{cell.form}
#{cell.price}
#{cell.flyer}
#{cell.blurb}
#{cell.links}
WOK
    end
    def output_form_journal(type,id)
      prod_id=id.gsub(/id_/,'')
      cell=cell(@ad[:promo][type][id],prod_id)
       <<WOK
<br />
#{cell.site_link}
#{cell.editor}
#{cell.issn}
#{cell.update}
#{cell.form}
#{cell.price.gsub(/Price:/,'Subscription:')}
#{cell.flyer}
#{cell.blurb}
#{cell.links}
WOK
    end
    def output_form_conference(type,id)
      prod_id=id.gsub(/id_/,'')
      cell=cell(@ad[:promo][type][id],prod_id)
#translate date (dd month yyyy) from 2007-03-04 and ruby conversion
       <<WOK
<br />
#{cell.site_link}
#{cell.date}
#{cell.location}
#{cell.price}
#{cell.flyer}
#{cell.blurb}
#{cell.links}
WOK
    end
    def output_form_select(type,id)
      case type
      when /site/
        output_form_link(type,id)
      when /sponsor/
        output_form_sponsor(type,id)
      when /search/
        output_form_search(type,id)
      when /book/
        output_form_book(type,id)
      when /journal/
        output_form_journal(type,id)
      when /conference/
        output_form_conference(type,id)
      end
    end
    def advert_extract_single(type,id) #extracts single item of type with id
      #type === book,journal,conference,sponsor
      id=id.to_s.gsub(/^(\d)/,'id_\1')
      if defined? @ad[:promo][type][id] and @ad[:promo][type][id]
        output_form_select(type,id)
      end
    end
    def advert_extract_subject(category) #extracts products from category/subject list
      adverts=[]
      if defined? @ad[:promo_list][category] and @ad[:promo_list][category]
        @ad[:promo_list][category].keys.each do |type|
          @ad[:promo_list][category][type].each do |i|
            if i
              id=i.to_s =~/^\d/ ? "id_#{i.to_s.strip}" : i.to_s.strip
              gbp=usd=euro=nil
              if defined? @ad[:promo][type][id] and not @ad[:promo][type][id].nil?
                adverts << output_form_select(type,id)
              end
            end
          end
        end
      else
        tell=SiSU_Screen::Ansi.new(@md.cmd,"category not found: #{category}")
        tell.warn unless @md.cmd =~/q/
      end
      adverts.to_s
    end
    def advert_extract_all #extracts all products from list (which is broken down into categories)
      adverts=[]
      @ad[:promo_list].keys.each do |category|
        adverts << advert_extract_subject(category)
      end
      adverts.flatten
    end
    def adverts(ads)
      <<WOK
#{div.minor}
#{ads}
#{div.close}
WOK
    end
    def no_adverts
      <<WOK
#{div.minor}
#{div.close}
WOK
    end
  end
end
__END__