From 6be61200c529f7f61a89aac6158eb63026d7a44b Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph.amissah@gmail.com>
Date: Fri, 15 Jun 2007 12:05:07 +0100
Subject: cgi search script fix, related to highlighting matches, changelog
 update, rest removal of hanging whitespace

---
 lib/sisu/v0/cgi_sql_common.rb   | 23 +++++++++++++++++++----
 lib/sisu/v0/db_load_tuple.rb    |  4 ++--
 lib/sisu/v0/shared_html_lite.rb |  1 +
 lib/sisu/v0/texpdf.rb           | 12 ++++++------
 4 files changed, 28 insertions(+), 12 deletions(-)

(limited to 'lib')

diff --git a/lib/sisu/v0/cgi_sql_common.rb b/lib/sisu/v0/cgi_sql_common.rb
index 13f9c2a3..a71d5412 100644
--- a/lib/sisu/v0/cgi_sql_common.rb
+++ b/lib/sisu/v0/cgi_sql_common.rb
@@ -111,6 +111,8 @@ module SiSU_CGI_sql
       @@limit,@@offset=1000,0
       @base="#@hosturl_db/cgi-bin/#@version.cgi"
       @@canned_search_url=@base
+      @color_heading='#DDFFAA'
+      @color_match='#ffff48'
       class Form
         def initialize(base,search_field,selected_db,checked_index,checked_text,checked_tip,checked_searched,checked_url,checked_echo,checked_sql,checked_all,checked_none,checked_ignore,search_note,the_can='')
           search_note='' if checked_searched !~/\S/
@@ -658,7 +660,7 @@ module SiSU_CGI_sql
               end
             #metadata_found_body
               if c['tid'].to_i != oldtid.to_i
-                title=%{<span style="background-color: #DDFFAA"><a href="#@hosturl_files/#@stub/#{location}/toc#{lang}.html">#{c['title']}</a></span> by #{c['creator']} <a href="#@hosturl_files/#@stub/#{location}/portrait#{lang}.pdf"><img border="0" width="15" height="18" src="#@image_src/b_pdf.png" alt="pdf portrait"></a><a href="#@hosturl_files/#@stub/#{location}/landscape#{lang}.pdf"><img border="0" width="18" height="15" src="#@image_src/b_pdf.png" alt="pdf landscape"></a> <a href="#@hosturl_files/#@stub/#{location}/sisu_manifest#{lang}.html"><img border="0" width="12" height="12" src="#@image_src/bullet_red.png" alt="manifest"><font size="2">&nbsp;?</font></a><br />}  if file_suffix=~/s/ #hmm watch file_suffix
+                title=%{<span style="background-color: #@color_heading"><a href="#@hosturl_files/#@stub/#{location}/toc#{lang}.html">#{c['title']}</a></span> by #{c['creator']} <a href="#@hosturl_files/#@stub/#{location}/portrait#{lang}.pdf"><img border="0" width="15" height="18" src="#@image_src/b_pdf.png" alt="pdf portrait"></a><a href="#@hosturl_files/#@stub/#{location}/landscape#{lang}.pdf"><img border="0" width="18" height="15" src="#@image_src/b_pdf.png" alt="pdf landscape"></a> <a href="#@hosturl_files/#@stub/#{location}/sisu_manifest#{lang}.html"><img border="0" width="12" height="12" src="#@image_src/bullet_red.png" alt="manifest"><font size="2">&nbsp;?</font></a><br />}  if file_suffix=~/s/ #hmm watch file_suffix
                  if @text_search_flag; title='<br /><hr>'+title
                  else                  title='<br />'+title
                  end
@@ -689,7 +691,13 @@ module SiSU_CGI_sql
                         end
                       else nil
                       end
-                      matched_para=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) ? (c['body'].gsub(/(#@search_regx)/,'<span style="background-color: #ffff48">\1</span>')) : c['body'] #check
+                      matched_para=if (@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/)
+                        matched=if c['body'] =~/<a href="https?:\/\//mi; c['body']
+                        else (c['body'].gsub(/(#@search_regx)/,%{<span style="background-color: #@color_match">\\1</span>})) 
+                        end
+                        matched
+                      else c['body']
+                      end
                       %{<hr><p><font size="2">ocn <b><a href="#@hosturl_files/#@stub/#{location}/#{c['seg']}#{lang}.html##{c['ocn']}">#{c['ocn']}</a></b>:</font></p>#{matched_para}}
                     elsif c['suffix'] =~/1/ #doc
                       %{#{title}<hr><p><font size="2">ocn #{c['ocn']}:#{c['body']}}
@@ -738,14 +746,21 @@ module SiSU_CGI_sql
             #metadata_found_endnotes
               if @text_search_flag
                 if e['metadata_tid'].to_i != oldtid.to_i
-                  title=%{<br /><hr><span style="background-color: #DDFFAA"><a href="#@hosturl_files/#@stub/#{location}/toc#{lang}.html">#{e['title']}</a></span> by #{e['creator']} <a href="#@hosturl_files/#@stub/#{location}/portrait.pdf"><img border="0" width="15" height="18" src="#@image_src/b_pdf.png" alt="pdf portrait"></a><a href="#@hosturl_files/#@stub/#{location}/landscape.pdf"><img border="0" width="18" height="15" src="#@image_src/b_pdf.png" alt="pdf landscape"></a> <a href="#@hosturl_files/#@stub/#{location}/sisu_manifest#{lang}.html"><img border="0" width="12" height="12" src="#@image_src/bullet_red.png" alt="manifest"><font size="2">&nbsp;?</font></a><br />}  if file_suffix=~/s/
+                  title=%{<br /><hr><span style="background-color: #@color_heading"><a href="#@hosturl_files/#@stub/#{location}/toc#{lang}.html">#{e['title']}</a></span> by #{e['creator']} <a href="#@hosturl_files/#@stub/#{location}/portrait.pdf"><img border="0" width="15" height="18" src="#@image_src/b_pdf.png" alt="pdf portrait"></a><a href="#@hosturl_files/#@stub/#{location}/landscape.pdf"><img border="0" width="18" height="15" src="#@image_src/b_pdf.png" alt="pdf landscape"></a> <a href="#@hosturl_files/#@stub/#{location}/sisu_manifest#{lang}.html"><img border="0" width="12" height="12" src="#@image_src/bullet_red.png" alt="manifest"><font size="2">&nbsp;?</font></a><br />}  if file_suffix=~/s/
                   @counter_endn_doc+=1
                   oldtid=e['metadata_tid'].to_i
                 else title = ''
                 end
                 if cgi['view']=~/text/                                           #% txt endnotes
                   @counter_endn_ocn+=1
-                  matched_endnote=(@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/) ? (e['body'].to_s.gsub(/(#@search_regx)/,'<span style="background-color: #ffff48">\1</span>')) : e['body'] #check
+                  matched_endnote=if (@search_regx.to_s.class==String && @search_regx.to_s=~/\S\S+/)
+                    matched=if e['body'] =~/<a href="https?:\/\//mi; e['body']
+                    else e['body'].gsub(/(#@search_regx)/,%{<span style="background-color: #@color_match">\\1</span>})
+                      #e['body']
+                    end
+                    matched
+                  else e['body']
+                  end
                   output=%{#{title}<hr><font size="2">note <b><a href="#@hosturl_files/#@stub/#{location}/endnotes.html##{e['nr']}">#{e['nr']}</a></b> referred to from ocn <a href="#@hosturl_files/#@stub/#{location}/doc.html##{e['ocn']}">#{e['ocn']}</a>:</font> #{matched_endnote}}
                 elsif cgi['view']=~/index/                                       #% idx endnotes
                   @counter_endn_ocn+=1
diff --git a/lib/sisu/v0/db_load_tuple.rb b/lib/sisu/v0/db_load_tuple.rb
index 9d513fda..30d8389e 100644
--- a/lib/sisu/v0/db_load_tuple.rb
+++ b/lib/sisu/v0/db_load_tuple.rb
@@ -60,12 +60,12 @@ module SiSU_DB_tuple
     def tuple                                                                    #% import line
       begin
         if @col[:en_a]
-          #puts.inspect "#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:en_a]}', '#{@col[:en_z]}'"
+          #puts "#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:en_a]}', '#{@col[:en_z]}'"
           @conn.execute(%{
           INSERT INTO documents (lid, metadata_tid, lev, clean, body, ocn, ocnd, ocns, seg, lev1, lev2, lev3, lev4, lev5, lev6, en_a, en_z, digest_clean, digest_all) VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:en_a]}', '#{@col[:en_z]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');
         })
         else
-          #puts.inspect "#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}'"
+          #puts "#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}'"
           @conn.execute(%{
           INSERT INTO documents (lid, metadata_tid, lev, clean, body, ocn, ocnd, ocns, seg, lev1, lev2, lev3, lev4, lev5, lev6, digest_clean, digest_all) VALUES (#{@col[:lid]}, #{@col[:tid]}, #{@col[:lev]}, '#{@col[:plaintext]}', '#{@col[:body]}', '#{@col[:ocn]}', '#{@col[:ocnd]}', '#{@col[:ocns]}', '#{@col[:seg]}', '#{@col[:lv1]}', '#{@col[:lv2]}', '#{@col[:lv3]}', '#{@col[:lv4]}', '#{@col[:lv5]}', '#{@col[:lv6]}', '#{@col[:digest_clean]}', '#{@col[:digest_all]}');
         })
diff --git a/lib/sisu/v0/shared_html_lite.rb b/lib/sisu/v0/shared_html_lite.rb
index 3c0e9ce1..75137148 100644
--- a/lib/sisu/v0/shared_html_lite.rb
+++ b/lib/sisu/v0/shared_html_lite.rb
@@ -94,6 +94,7 @@ module SiSU_Format_Shared
             png=m.scan(/\S+/)[0].strip
             link=link.strip
             ins=%{<a href="#{u}">#{link}</a>#{d}}
+            #ins=%{#{link} <a href="#{u}">[link]</a>#{d}}
             word.gsub!(/\{.+?\}(?:https?|ftp)\S+/,ins)
           end
           word
diff --git a/lib/sisu/v0/texpdf.rb b/lib/sisu/v0/texpdf.rb
index aec45b58..a5db4c77 100644
--- a/lib/sisu/v0/texpdf.rb
+++ b/lib/sisu/v0/texpdf.rb
@@ -283,12 +283,12 @@ module SiSU_TeX
           else para
           end
           if para.class == String
-            @md.flag_tables=true if para =~/<!Th?¡\s+c/ 
+            @md.flag_tables=true if para =~/<!Th?¡\s+c/
             do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para)
             @tex_file << do_mono.special_characters
           elsif para.class == Array
             para.each do |grp|
-              @md.flag_tables=true if grp =~/<!Th?¡\s+c/ 
+              @md.flag_tables=true if grp =~/<!Th?¡\s+c/
               do_mono=SiSU_TeX_Pdf::Format_text_object.new(@md,grp)
               @tex_file << do_mono.special_characters
             end
@@ -420,8 +420,8 @@ WOK
           mono=SiSU_TeX_Pdf::Format_text_object.new(@md,para)
           if para =~/<:(code|alt|verse|group)>/ or @@flag_group==true
             if para =~/<:(code|alt|verse|group)>/
-              @lineone=case para 
-              when /<:(alt|verse|group)>/; para 
+              @lineone=case para
+              when /<:(alt|verse|group)>/; para
               when /<:code>/; "#{@tex.paraskip_small} \\begin{footnotesize} \\begin{ttfamily} " + para
               else 'error' #should never occur
               end
@@ -440,9 +440,9 @@ WOK
             elsif @@flag_group==true;    @group_collect << para #<< "\n\n"
             end
             if x =~/(?:code|alt|verse|group)-end/
-              regx=/(\\+marginpar\{\\+begin\{tiny\}\d+\\+end\{tiny\}\})/ 
+              regx=/(\\+marginpar\{\\+begin\{tiny\}\d+\\+end\{tiny\}\})/
               y=if para =~regx
-                regx.match(para)[1] 
+                regx.match(para)[1]
               else ''
               end
               para.gsub!(regx,'')
-- 
cgit v1.2.3