<commit_before># coding: utf-8
require 'uservoice_sso'
class ApplicationController < ActionController::Base
  layout :use_catarse_boostrap
  protect_from_forgery

  before_filter :redirect_user_back_after_login, unless: :devise_controller?
  before_filter :configure_permitted_parameters, if: :devise_controller?

  rescue_from ActionController::RoutingError, with: :render_404
  rescue_from ActionController::UnknownController, with: :render_404
  rescue_from ActiveRecord::RecordNotFound, with: :render_404

  rescue_from CanCan::Unauthorized do |exception|
    session[:return_to] = request.env['REQUEST_URI']
    message = exception.message

    if current_user.nil?
      redirect_to new_user_registration_path, alert: I18n.t('devise.failure.unauthenticated')
    elsif request.env["HTTP_REFERER"]
      redirect_to :back, alert: message
    else
      redirect_to root_path, alert: message
    end
  end

  helper_method :channel, :namespace, :fb_admins, :render_facebook_sdk, :render_facebook_like, :render_twitter, :display_uservoice_sso

  before_filter :set_locale
  before_filter :force_http

  before_action :referal_it!

  # TODO: Change this way to get the opendata
  before_filter do
    @fb_admins = [100000428222603, 547955110]
  end

  @@menu_items = {}
  cattr_accessor :menu_items

  def self.add_to_menu i18n_name, path
    menu I18n.t(i18n_name) => path
  end

  def self.menu menu
    self.menu_items.merge! menu
  end

  def menu
    ApplicationController.menu_items.inject({}) do |memo, el|
      memo.merge!(el.first => Rails.application.routes.url_helpers.send(el.last)) if can? :access, el.last
      memo
    end
  end

  def channel
    Channel.find_by_permalink(request.subdomain.to_s)
  end

  # We use this method only to make stubing easier
  # and remove FB templates from acceptance tests
  def render_facebook_sdk
    render_to_string(partial: 'layouts/facebook_sdk').html_safe
  end

  def render_twitter options={}
    render_to_string(partial: 'layouts/twitter', locals: options).html_safe
  end

  def render_facebook_like options={}<commit_msg>use find_by_permalink with !(bang) to raise 404 when channel not found<commit_after># coding: utf-8
require 'uservoice_sso'
class ApplicationController < ActionController::Base
  layout :use_catarse_boostrap
  protect_from_forgery

  before_filter :redirect_user_back_after_login, unless: :devise_controller?
  before_filter :configure_permitted_parameters, if: :devise_controller?

  rescue_from ActionController::RoutingError, with: :render_404
  rescue_from ActionController::UnknownController, with: :render_404
  rescue_from ActiveRecord::RecordNotFound, with: :render_404

  rescue_from CanCan::Unauthorized do |exception|
    session[:return_to] = request.env['REQUEST_URI']
    message = exception.message

    if current_user.nil?
      redirect_to new_user_registration_path, alert: I18n.t('devise.failure.unauthenticated')
    elsif request.env["HTTP_REFERER"]
      redirect_to :back, alert: message
    else
      redirect_to root_path, alert: message
    end
  end

  helper_method :channel, :namespace, :fb_admins, :render_facebook_sdk, :render_facebook_like, :render_twitter, :display_uservoice_sso

  before_filter :set_locale
  before_filter :force_http

  before_action :referal_it!

  # TODO: Change this way to get the opendata
  before_filter do
    @fb_admins = [100000428222603, 547955110]
  end

  @@menu_items = {}
  cattr_accessor :menu_items

  def self.add_to_menu i18n_name, path
    menu I18n.t(i18n_name) => path
  end

  def self.menu menu
    self.menu_items.merge! menu
  end

  def menu
    ApplicationController.menu_items.inject({}) do |memo, el|
      memo.merge!(el.first => Rails.application.routes.url_helpers.send(el.last)) if can? :access, el.last
      memo
    end
  end

  def channel
    Channel.find_by_permalink!(request.subdomain.to_s)
  end

  # We use this method only to make stubing easier
  # and remove FB templates from acceptance tests
  def render_facebook_sdk
    render_to_string(partial: 'layouts/facebook_sdk').html_safe
  end

  def render_twitter options={}
    render_to_string(partial: 'layouts/twitter', locals: options).html_safe
  end

  def render_facebook_like options={}
{'fraction_non_alphanumeric': 0.08132387706855793, 'fraction_numerical': 0.02056737588652482, 'mean_word_length': 4.756462585034013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '2753404', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1363, 'n_words': 317}