2019-05-12 22:16:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-24 00:01:47 -04:00
|
|
|
# name: discourse-adplugin
|
2015-08-31 20:28:47 -04:00
|
|
|
# about: Ad Plugin for Discourse
|
2019-09-10 17:09:21 -04:00
|
|
|
# version: 1.2.4
|
2015-08-31 20:28:47 -04:00
|
|
|
# authors: Vi and Sarah (@ladydanger and @cyberkoi)
|
2017-04-26 00:43:04 -04:00
|
|
|
# url: https://github.com/discourse/discourse-adplugin
|
2015-07-24 00:01:47 -04:00
|
|
|
|
2019-02-01 13:46:11 -05:00
|
|
|
register_asset "stylesheets/adplugin.scss"
|
2019-02-04 16:14:43 -05:00
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
add_admin_route 'admin.adplugin.house_ads.title', 'houseAds'
|
|
|
|
|
|
|
|
module ::AdPlugin
|
|
|
|
def self.plugin_name
|
|
|
|
'discourse-adplugin'.freeze
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.pstore_get(key)
|
|
|
|
PluginStore.get(AdPlugin.plugin_name, key)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.pstore_set(key, value)
|
|
|
|
PluginStore.set(AdPlugin.plugin_name, key, value)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.pstore_delete(key)
|
|
|
|
PluginStore.remove(AdPlugin.plugin_name, key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-19 09:29:52 -04:00
|
|
|
# TODO: Remove this once 2.4.0.beta3 is released.
|
|
|
|
# HACK: Checking if the file exists, this means we can assume the migration happenned
|
|
|
|
above_min_version = File.exist?(
|
|
|
|
File.expand_path('../../../db/migrate/20190717133743_migrate_group_list_site_settings.rb', __FILE__)
|
|
|
|
)
|
|
|
|
|
2019-02-04 16:14:43 -05:00
|
|
|
after_initialize do
|
2019-04-18 17:52:59 -04:00
|
|
|
require_dependency File.expand_path('../app/models/house_ad', __FILE__)
|
|
|
|
require_dependency File.expand_path('../app/models/house_ad_setting', __FILE__)
|
|
|
|
require_dependency File.expand_path('../app/controllers/house_ads_controller', __FILE__)
|
|
|
|
require_dependency File.expand_path('../app/controllers/house_ad_settings_controller', __FILE__)
|
2019-02-04 16:14:43 -05:00
|
|
|
require_dependency 'application_controller'
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2019-07-19 09:29:52 -04:00
|
|
|
# TODO: remove when 2.4 becomes the new stable
|
|
|
|
add_to_serializer(:site, :group_list_use_ids) { above_min_version }
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
add_to_serializer :site, :house_creatives do
|
|
|
|
AdPlugin::HouseAdSetting.settings_and_ads
|
|
|
|
end
|
|
|
|
|
2019-06-17 17:20:38 -04:00
|
|
|
add_to_serializer :topic_view, :tags_disable_ads do
|
|
|
|
return false if !SiteSetting.tagging_enabled || !SiteSetting.no_ads_for_tags.present?
|
|
|
|
return false if object.topic.tags.empty?
|
|
|
|
!(SiteSetting.no_ads_for_tags.split('|') & object.topic.tags.map(&:name)).empty?
|
|
|
|
end
|
|
|
|
|
2019-02-04 16:14:43 -05:00
|
|
|
class ::AdstxtController < ::ApplicationController
|
|
|
|
skip_before_action :check_xhr
|
|
|
|
|
|
|
|
def index
|
2019-06-03 11:39:28 -04:00
|
|
|
raise Discourse::NotFound unless SiteSetting.ads_txt.present?
|
2019-02-04 16:14:43 -05:00
|
|
|
|
2019-06-03 11:39:28 -04:00
|
|
|
render plain: SiteSetting.ads_txt
|
2019-02-04 16:14:43 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
class AdPlugin::Engine < ::Rails::Engine
|
|
|
|
engine_name 'adplugin'
|
|
|
|
isolate_namespace AdPlugin
|
|
|
|
end
|
|
|
|
|
|
|
|
AdPlugin::Engine.routes.draw do
|
|
|
|
root to: 'house_ads#index'
|
2019-05-07 14:32:32 -04:00
|
|
|
resources :house_ads, only: [:index, :show, :create, :update, :destroy]
|
2019-04-18 17:52:59 -04:00
|
|
|
resources :house_ad_settings, only: [:update]
|
|
|
|
end
|
|
|
|
|
2019-02-04 16:14:43 -05:00
|
|
|
Discourse::Application.routes.append do
|
|
|
|
get '/ads.txt' => "adstxt#index"
|
2019-04-18 17:52:59 -04:00
|
|
|
mount ::AdPlugin::Engine, at: '/admin/plugins/adplugin', constraints: AdminConstraint.new
|
2019-02-04 16:14:43 -05:00
|
|
|
end
|
|
|
|
end
|