=begin filemanager.rb Copyright (C) 2008 Leon Li You may redistribute it and/or modify it under the same license terms as Ruby. =end require 'action_controller/routing' require 'fileutils' fm_config = File.join(RAILS_ROOT, 'config', 'filemanager.yml') if $FM_OVERWRITE || ! File.exist?(fm_config) fm_rails_path = File.dirname(File.dirname(__FILE__)) + "/rails/" Dir.foreach(fm_rails_path) {|f| FileUtils.cp_r(fm_rails_path + f, RAILS_ROOT)} end ActionController::Routing::RouteSet.class_eval do def fm_load_routes! fm_old_load_routes! map = ActionController::Routing::RouteSet::Mapper.new(self) map.namespace :fm do |f| f.resources :filemanager end end alias_method :fm_old_load_routes!, :load_routes! alias_method :load_routes!, :fm_load_routes! end require "erb" require "yaml" $FM_PROPERTIES = YAML::load(ERB.new(IO.read(fm_config)).result) FM_IMAGE_TYPES = $FM_PROPERTIES['image.type'].split(' ') FM_FLASH_TYPES = $FM_PROPERTIES['flash.type'].split(' ') FM_MOVIE_TYPES = $FM_PROPERTIES['movie.type'].split(' ') FM_RM_TYPES = $FM_PROPERTIES['rm.type'].split(' ') FM_OFFICE_TYPES = $FM_PROPERTIES['office.type'].split(' ') FM_EXCEL_TYPES = $FM_PROPERTIES['excel.type'].split(' ') FM_WORD_TYPES = $FM_PROPERTIES['word.type'].split(' ') FM_PPT_TYPES = $FM_PROPERTIES['ppt.type'].split(' ') FM_HELP_TYPES = $FM_PROPERTIES['help.type'].split(' ') FM_PLAIN_TYPES = $FM_PROPERTIES['plain.type'].split(' ') FM_NONE_TYPES = $FM_PROPERTIES['none.type'].split(' ') FM_SUPPORT_TYPES = FM_IMAGE_TYPES + FM_FLASH_TYPES + FM_MOVIE_TYPES + FM_RM_TYPES + FM_OFFICE_TYPES + FM_HELP_TYPES + FM_PLAIN_TYPES FM_UNKNOWN_TYPE = 'unknown' FM_RESOURCES_PATH= $FM_PROPERTIES['resources.path'] FM_LOCK_PATH = $FM_PROPERTIES['resources.url'] FM_ENCODING_TO = $FM_PROPERTIES['encoding.to'] FM_ENCODING_FROM = $FM_PROPERTIES['encoding.from'].nil? ? '' : $FM_PROPERTIES['encoding.from'] FM_TEMP_DIR = $FM_PROPERTIES['temp.dir'].nil? ? File.join(RAILS_ROOT, '/fm_temp') : $FM_PROPERTIES['temp.dir'] FileUtils.rm_rf(Dir.glob("#{FM_TEMP_DIR}/*"))