# vsitemap.rb $Revision$ # # visual sitemap plugin # # Copyright (c) 2003 shinichro.h # Copyright (c) 2005 Kazuhiko def about_vsitemap <<-EOS !Description This plugin adds a menu link to display visual sitemap. You can also include visual sitemap to any page by putting the following line. {{vsitemap_str)}} !Options !!@conf.options['vsitemap.file'] Specify the PNG filename of visual sitemap. !!@conf.options['vsitemap.url'] Specify the URI of visual sitemap PNG file. !!@conf.options['vsitemap.font'] Specify the full path of truetype font for rasterizing output text. !!@conf.options['vsitemap.fontsize'] Specify the font size of output text (unit: pixel). EOS end def vsitemap_label 'サイトマップ' end def vsitemap page = Page::new( @cgi, @conf ) data = get_common_data( @db, self, @conf ) hiki_menu(data, @cmd) pg_title='' data[:title] = "#{@conf.site_name} - #{vsitemap_label}" data[:view_title] = data[:title] data[:body] = %Q|
\n#{vsitemap_str}\n
|.sanitize page.template = "#{@conf.template_path }/#{@conf.template['view']}" page.contents = data print page.page( self ) end def vsitemap_str png_file = @options['vsitemap.file'] || 'sitemap.png' png_url = @options['vsitemap.url'] || "#{@conf.base_url}sitemap.png" cache_path = "#{@conf.cache_path}/vsitemap".untaint Dir::mkdir( cache_path ) unless File::directory?( cache_path ) map_file = "#{cache_path}/sitemap.map" if File.exists?(map_file.untaint) and File.exists?(png_file.untaint) map_str = %Q(sitemap\n) + utf8_to_euc(File.read(map_file)) return map_str end font = @options['vsitemap.font'] || '/usr/share/fonts/truetype/japanese/sazanami-gothic.ttf' size = @options['vsitemap.fontsize'] || 9 nodes = [] @db.pages.each do |name| @db.get_references( name ).each do |i| nodes << %Q!\t"#{page_name(i)}" -> "#{page_name(name)}"\n! if i != name end nodes << %Q!\t"#{page_name(name)}" [href="#{@conf.cgi_name}?#{name.escape}"]\n! end dot_file = "#{cache_path}/sitemap.dot" File.open(dot_file, "w") do |ofile| ofile.print "digraph sitemap {\n" ofile.print "\tnode[fontname=\"#{font}\" fontsize=\"#{size}\" height=0 width=0 shape=\"polygon\"];\n" ofile.print "\tedge[arrowsize=0.6];\n" nodes.each do |i| ofile.print euc_to_utf8(i) end ofile.print "}\n" end system("dot -Tpng #{dot_file} -o #{png_file}".untaint) system("dot -Tcmapx #{dot_file} -o #{map_file}".untaint) map_str = %Q(sitemap\n) + utf8_to_euc(File.read(map_file)) return map_str end add_update_proc { File.unlink( "#{@conf.cache_path}/vsitemap/sitemap.map".untaint ) } add_body_enter_proc(Proc.new do add_plugin_command('vsitemap', vsitemap_label, {}) end)