<commit_before># Copyright (C) 2009 <NAME>.

require 'mime/types'

class PublicController < ApplicationController  # :nodoc: all
  skip_before_filter :context_translate_before
  skip_after_filter :context_translate_after
  skip_before_filter :check_ssl
  skip_after_filter :save_anonymous_tags
 
  helper :paragraph
  
  after_filter :remove_session_cookie
  
  def stylesheet 
    site_template_id = params[:path][0].to_s
    lang = params[:path][1] || session[:cms_language] || Configuration.languages[0]
    editor = params[:editor] || false
    
    headers['Content-Type'] = 'text/css'
    
    if CMS_CACHE_ACTIVE 
        @css = DataCache.get_container("SiteTemplate",":#{site_template_id}:#{lang}:#{editor ? 1:0}")
    end
    
    unless @css 
      begin
        if site_template_id[0..0] == "f"
          @css = SiteFeature.find(site_template_id[1..-1]).rendered_css
        else
          @css = SiteTemplate.render_template_css(site_template_id.to_i,lang,!editor)
        end
        if CMS_CACHE_ACTIVE
          DataCache.put_container("SiteTemplate",":#{site_template_id}:#{lang}:#{editor ? 1:0}",@css)
        end
      rescue ActiveRecord::RecordNotFound => e
        render :layout => false, :text => "Stylesheet not found", :status => 404
        return
      end
    end

    get_handlers(:stylesheet,:post_process).each do |req|
      cls = req[0].constantize.new(self)
      @css = cls.post_process_stylesheet @css
    end

    render :layout=> false, :text => @css
  end
  
  def calendar
    @calendar_language = session[:cms_language] || Configuration.languages[0] || 'en'
    render :action => 'calendar', :layout => false
  end
  
  
  def image
    if params[:domain_id].to_i != DomainModel.active_domain[:file_store].to_i
      render :inline => 'File not found', :status => 404
      return
    end
    
    return self.file_version(params) if params[:path][-3] == 'v'

    filename = params[:path][-1] # Filename is always the last argument
    size = params[:path][-2]
    prefix = params[:path][0..-2]
    prefix.pop if DomainFileSize.valid_size?(size)
    prefix = prefix.join('/')

    df = DomainFile.find_by_prefix(prefix)

    # Special case for thumbs
    if df && df.name != filename
      unless df.file_type == 'thm' && filename.gsub(/\.[^.]+$/,".#{df.extension}")
        df = nil
      end
    end

    if df
      # If it's local and the remote file exists, redirect to there
      if !df.local? && df.get_size(size)
        redirect_to df.url(sz.size_name)<commit_msg>Fix to existing file on redirect :(<commit_after># Copyright (C) 2009 <NAME>.

require 'mime/types'

class PublicController < ApplicationController  # :nodoc: all
  skip_before_filter :context_translate_before
  skip_after_filter :context_translate_after
  skip_before_filter :check_ssl
  skip_after_filter :save_anonymous_tags
 
  helper :paragraph
  
  after_filter :remove_session_cookie
  
  def stylesheet 
    site_template_id = params[:path][0].to_s
    lang = params[:path][1] || session[:cms_language] || Configuration.languages[0]
    editor = params[:editor] || false
    
    headers['Content-Type'] = 'text/css'
    
    if CMS_CACHE_ACTIVE 
        @css = DataCache.get_container("SiteTemplate",":#{site_template_id}:#{lang}:#{editor ? 1:0}")
    end
    
    unless @css 
      begin
        if site_template_id[0..0] == "f"
          @css = SiteFeature.find(site_template_id[1..-1]).rendered_css
        else
          @css = SiteTemplate.render_template_css(site_template_id.to_i,lang,!editor)
        end
        if CMS_CACHE_ACTIVE
          DataCache.put_container("SiteTemplate",":#{site_template_id}:#{lang}:#{editor ? 1:0}",@css)
        end
      rescue ActiveRecord::RecordNotFound => e
        render :layout => false, :text => "Stylesheet not found", :status => 404
        return
      end
    end

    get_handlers(:stylesheet,:post_process).each do |req|
      cls = req[0].constantize.new(self)
      @css = cls.post_process_stylesheet @css
    end

    render :layout=> false, :text => @css
  end
  
  def calendar
    @calendar_language = session[:cms_language] || Configuration.languages[0] || 'en'
    render :action => 'calendar', :layout => false
  end
  
  
  def image
    if params[:domain_id].to_i != DomainModel.active_domain[:file_store].to_i
      render :inline => 'File not found', :status => 404
      return
    end
    
    return self.file_version(params) if params[:path][-3] == 'v'

    filename = params[:path][-1] # Filename is always the last argument
    size = params[:path][-2]
    prefix = params[:path][0..-2]
    prefix.pop if DomainFileSize.valid_size?(size)
    prefix = prefix.join('/')

    df = DomainFile.find_by_prefix(prefix)

    # Special case for thumbs
    if df && df.name != filename
      unless df.file_type == 'thm' && filename.gsub(/\.[^.]+$/,".#{df.extension}")
        df = nil
      end
    end

    if df
      # If it's local and the remote file exists, redirect to there
      if !df.local? && df.get_size(size)
        redirect_to df.url(size)
{'fraction_non_alphanumeric': 0.12985725614591595, 'fraction_numerical': 0.011102299762093577, 'mean_word_length': 3.048956661316212, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7302820', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1603, 'n_words': 353}