# $Id: 00default.rb,v 1.55 2006/06/01 10:54:50 fdiary Exp $ # Copyright (C) 2002-2003 TAKEUCHI Hitoshi #============================== # tDiary plugins for Hiki #============================== def anchor( s ) s.sub!(/^\d+$/, '') p = @page.escape.escapeHTML p.gsub!(/%/, '%%') %Q[#{@conf.cgi_name}?#{p}#{s}] end def my( a, str ) %Q[#{str.escapeHTML}] end #============================== # Hiki default plugins #============================== #===== hiki_url def hiki_url(page) "#{@conf.cgi_name}?#{page.escape}" end #===== hiki_anchor def hiki_anchor( page, display_text ) if page == 'FrontPage' then make_anchor(@conf.cgi_name, display_text) else make_anchor("#{@conf.cgi_name}?#{page}", display_text) end end #===== make_anchor def make_anchor(url, display_text, a_class = nil) if a_class %Q!#{display_text}! else %Q!#{display_text}! end end #===== page_name def page_name( page ) pg_title = @db.get_attribute(page, :title) ((pg_title && pg_title.size > 0) ? pg_title : page).escapeHTML end #===== toc def toc @toc_f = :top '' end def toc_here( page = nil ) if page tokens = @db.load_cache( page ) unless tokens parser = @conf.parser::new( @conf ) tokens = parser.parse( @db.load( page ) ) @db.save_cache( page, tokens ) end formatter = @conf.formatter::new( tokens, @db, Plugin.new( @conf.options, @conf), @conf ) formatter.to_s formatter.toc.gsub( / 0 ? n : 0 l = @db.page_info.sort do |a, b| b[b.keys[0]][:last_modified] <=> a[a.keys[0]][:last_modified] end s = '' c = 0 ddd = nil l.each do |a| break if (c += 1) > n name = a.keys[0] p = a[name] tm = p[:last_modified ] cur_date = tm.strftime( @conf.msg_date_format ) if ddd != cur_date s << "\n" if ddd s << "
#{cur_date}
\n\n" s end #===== br def br( n = 1 ) '
' * n.to_i end #===== update_proc add_update_proc { updating_mail if @conf.mail_on_update if @user @conf.repos.commit(@page, CGI::escape(@user)) else @conf.repos.commit(@page) end } #----- send a mail on updating def updating_mail begin latest_text = @db.load(@page) || '' type = (!@db.text or @db.text.size == 0) ? 'create' : 'update' text = '' text = "#{@db.text}\n#{'-' * 25}\n" if type == 'update' text << "#{latest_text}\n" send_updating_mail(@page, type, text) rescue end end #===== delete_proc add_delete_proc { @conf.repos.delete(@page) } #===== hiki_header add_header_proc { hiki_header } def hiki_header return "#{title}\n" if @conf.mobile_agent? s = < #{title} EOS s << < EOS s end #===== hiki_footer add_footer_proc { hiki_footer } def hiki_footer <Hiki
#{HIKI_VERSION} (#{HIKI_RELEASE_DATE}).
Powered by Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE})#{if /ruby/i =~ ENV['GATEWAY_INTERFACE'] then ' with mod_ruby' end}.
Founded by #{@conf.author_name.escapeHTML}.
EOS end #===== edit_proc add_edit_proc { hiki_anchor(@page.escape, "[#{page_name(@page)}]") } #===== menu def create_menu(data, command) menu = [] if @conf.bot? menu << %Q!#{@conf.msg_index}! else menu << %Q!Logged in as Admin. Don't edit any pages.
! if admin? menu << %Q!#{@conf.msg_create}! if creatable? menu << %Q!#{@conf.msg_edit}! if @page && editable? menu << %Q!#{@conf.msg_diff}! if @page && editable? menu << %Q!#{hiki_anchor( 'FrontPage', page_name('FrontPage') )}! menu << %Q!#{@conf.msg_index}! menu << %Q!#{@conf.msg_search}! menu << %Q!#{@conf.msg_recent_changes}! @plugin_menu.each do |c| next if c[:option].has_key?('p') && !(@page && editable?) cmd = %Q!#{c[:display_text]}! menu << cmd end menu_proc.each {|i| menu << i} menu << %Q!#{@conf.msg_login}! unless @user || @conf.password.empty? menu << %Q!#{@conf.msg_admin}! if admin? menu << %Q!#{@conf.msg_logout}! if @user && !@conf.password.empty? end menu end def hiki_menu(data, command) menu = create_menu(data, command) if @conf.mobile_agent? data[:tools] = menu.join('|') else data[:tools] = menu.collect! {|i| %Q!#{i}! }.join(" \n") end end # conf: default def saveconf_default if @mode == 'saveconf' then @conf.site_name = @cgi.params['site_name'][0] @conf.author_name = @cgi.params['author_name'][0] mails = [] @cgi.params['mail'][0].each_line do |addr| mails << addr.gsub(/\r?\n/, '').strip end mails.delete_if{|e| e.empty?} @conf.mail = mails @conf.mail_on_update = @cgi.params['mail_on_update'][0] == "true" end end # conf: password def saveconf_password if @mode == 'saveconf' then old_password = @cgi.params['old_password'][0] password1 = @cgi.params['password1'][0] password2 = @cgi.params['password2'][0] if password1 and password1.size > 0 if (@conf.password.size > 0 && old_password.crypt( @conf.password ) != @conf.password) || (password1 != password2) return :password_change_failure end salt = [rand(64),rand(64)].pack("C*").tr("\x00-\x3f","A-Za-z0-9./") @conf.password = password1.crypt( salt ) return :password_change_success end end return nil end # conf: display def saveconf_theme # dummy end if @cgi.params['conf'][0] == 'theme' && @mode == 'saveconf' @conf.theme = @cgi.params['theme'][0] || '' @conf.use_sidebar = @cgi.params['sidebar'][0] == "true" @conf.main_class = @cgi.params['main_class'][0] @conf.main_class = 'main' if @conf.main_class == '' @conf.sidebar_class = @cgi.params['sidebar_class'][0] @conf.sidebar_class = 'sidebar' if @conf.sidebar_class == '' @conf.auto_link = @cgi.params['auto_link'][0] == "true" @conf.use_wikiname = @cgi.params['use_wikiname'][0] == "true" @conf.theme_url = @cgi.params['theme_url'][0] @conf.theme_path = @cgi.params['theme_path'][0] end if @cgi.params['conf'][0] == 'theme' @conf_theme_list = [] Dir::glob( "#{@conf.theme_path}/*".untaint ).sort.each do |dir| theme = File::basename( dir ) next unless FileTest::file?( "#{dir}/#{theme}.css".untaint ) name = theme.split( /_/ ).collect{|s| s.capitalize}.join( ' ' ) @conf_theme_list << [theme,name] end end # conf: XML-RPC def saveconf_xmlrpc if @mode == 'saveconf' @conf.xmlrpc_enabled = @cgi.params['xmlrpc_enabled'][0] == 'true' end end def auth? true end def editable?( page = @page ) if page auth? && ((!@db.is_frozen?( page ) && !@conf.options['freeze']) || admin?) else creatable? end end def creatable? auth? && (!@conf.options['freeze'] || admin?) end export_plugin_methods(:toc, :toc_here, :recent, :br)