#!/usr/local/bin/ruby
#  encoding: utf-8
#  daybook_lib.rb

#  Created by midori on 2006-08-24.
#  Copyright (c) 2006. All rights reserved.
#  You can distribute/modify this program under the terms of the Ruby License.
#  Last change: 2006-09-13.

#______________________________________________________________ BaseClass

class MainBase
  def MainBase.load(path)
    mod = Module.new
    mod.module_eval File.read(path)
    new(mod)
  end
  #attr_reader :base_url, :base_dir, :entryview#, url_daybook, :url_archives_dir
  #attr_reader :private_dir, :private_daybook_dir, :public_dir, :public_daybook_dir, :
  
  def initialize(mod)
    @mod = mod
    @base_url = @mod::BASE_URL #= "http://127.0.0.1:3000/"
    @base_dir = @mod::BASE_DIR #= "/xxx/xxx/webhome"
    @entryview = @mod::ENTRY_VIEW #= "10"
    
    @url_daybook = File.join(@base_url, "daybook")#"http://127.0.0.1:3000/daybook/"
    ########### Look!
    @url_archives_dir = File.join(@base_url, "daybook", "daybook_archives")#"http://127.0.0.1:3000/daybook/daybook_archives/"
    
    @private_daybook_dir = File.join(@base_dir, "daybook")# "/xxx/xxx/webhome/daybook"
    @public_dir = File.join(@base_dir, "public_html")# "/xxx/xxx/webhome/public_html"
    @public_daybook_dir = File.join(@base_dir, "public_html", "daybook")# "/xxx/xxx/webhome/public_html/daybook"
    #---------------------------
    @path_script_dir = File.join(@public_dir, "mycgi")
    @path_trash = File.join(@private_daybook_dir, "trash") #2006-10-25
    @path_xml_dir = File.join(@private_daybook_dir, "daybook_xml")
    @path_xsl_dir = File.join(@private_daybook_dir, "daybook_xsl")
    @path_xhtml_dir = File.join(@public_daybook_dir, "daybook_archives")    
    @path_admin_dir = File.join(@public_dir, "admin")
    @path_admin_trash_dir = File.join(@path_admin_dir, "daybook_trash")
    
    @path_xsl_index_file = File.join(@path_xsl_dir, "daybook_index.xsl")
    @path_xsl_post_file = File.join(@path_xsl_dir, "daybook_entry.xsl")
    @path_xsl_archives_file = File.join(@path_xsl_dir, "daybook_archives.xsl")
    @path_xsl_admin_file = File.join(@path_xsl_dir, "daybook_admin.xsl")
    @path_xsl_search_file = File.join(@path_xsl_dir, "daybook_search.xsl")
    
    @path_index_file = File.join(@public_daybook_dir, "daybook_index.html") 
    @path_archive_file = File.join(@public_daybook_dir, "daybook_archives.html")
    @path_xmllog_file = File.join(@private_daybook_dir, "daybook_log", "xml.log")
    @path_maillog_file = File.join(@private_daybook_dir, "daybook_log", "commentmail.log")
    @path_admin_file = File.join(@path_admin_dir,"daybook_admin.html")
    
    @path_lwws_xmldir =File.join(@public_dir,"lwws", "xmldata")
    
  end
  def make_base_hash
    myhash = Hash.new
    myhash["url"] = @base_url

    
    myhash["trash"] = @path_trash  #2006-10-25
    myhash["dir_pub"] = @public_dir#for google site map
    myhash["dir_script"] = @path_script_dir
    myhash["dir_xml"] = @path_xml_dir
    myhash["dir_xhtml"] = @path_xhtml_dir
    myhash["dir_admin"] = @path_admin_dir
    myhash["dir_admintrash"] = @path_admin_trash_dir
    
    myhash["f_log_xml"] = @path_xmllog_file
    myhash["f_log_mail"] = @path_maillog_file
    
    myhash["f_xsl_index"] = @path_xsl_index_file
    myhash["f_xsl_post"] = @path_xsl_post_file
    myhash["f_xsl_archives"] = @path_xsl_archives_file
    myhash["f_xsl_admin"] = @path_xsl_admin_file
    myhash["f_xsl_search"] = @path_xsl_search_file
    
    myhash["f_indexhtml"] = @path_index_file
    myhash["f_archivehtml"] = @path_archive_file
    myhash["f_adminhtml"] = @path_admin_file
    
    myhash["url_daybook"] = @url_daybook
    myhash["url_archives_dir"] = @url_archives_dir
    myhash["url_archives_path"] = "/daybook/daybook_archives"
    
    myhash["lwws_xmldir"] = @path_lwws_xmldir
    myhash["entryview"] = @entryview.to_i - 1 #2006-10-25
    
    return myhash
  end
end

