2019-05-12 22:16:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-07-24 00:01:47 -04:00
|
|
|
# name: discourse-adplugin
|
2023-11-08 14:16:53 -05:00
|
|
|
# about: Allows admins to configure advertisements, and integrates with external ad platforms.
|
|
|
|
# meta_topic_id: 33734
|
2019-09-16 15:03:47 -04:00
|
|
|
# version: 1.2.5
|
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
|
|
|
|
2022-12-29 07:29:26 -05:00
|
|
|
add_admin_route "admin.adplugin.house_ads.title", "houseAds"
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-08-01 11:31:28 -04:00
|
|
|
enabled_site_setting :discourse_adplugin_enabled
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
module ::AdPlugin
|
|
|
|
def self.plugin_name
|
2022-12-29 07:29:26 -05:00
|
|
|
"discourse-adplugin".freeze
|
2019-04-18 17:52:59 -04:00
|
|
|
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-02-04 16:14:43 -05:00
|
|
|
after_initialize do
|
2024-03-05 10:39:27 -05:00
|
|
|
require_relative "app/models/house_ad"
|
|
|
|
require_relative "app/models/house_ad_setting"
|
|
|
|
require_relative "app/controllers/house_ads_controller"
|
|
|
|
require_relative "app/controllers/house_ad_settings_controller"
|
|
|
|
require_relative "app/controllers/adstxt_controller"
|
|
|
|
require_relative "lib/adplugin/guardian_extensions"
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2024-01-31 13:04:24 -05:00
|
|
|
reloadable_patch { Guardian.prepend ::AdPlugin::GuardianExtensions }
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
add_to_serializer :site, :house_creatives do
|
2024-04-09 13:54:11 -04:00
|
|
|
AdPlugin::HouseAdSetting.settings_and_ads(for_anons: scope.anonymous?, scope: scope)
|
2019-04-18 17:52:59 -04:00
|
|
|
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?
|
2022-12-29 07:29:26 -05:00
|
|
|
!(SiteSetting.no_ads_for_tags.split("|") & object.topic.tags.map(&:name)).empty?
|
2019-06-17 17:20:38 -04:00
|
|
|
end
|
|
|
|
|
2024-01-31 13:04:24 -05:00
|
|
|
add_to_serializer :current_user, :show_dfp_ads do
|
|
|
|
scope.show_dfp_ads?
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer :current_user, :show_adsense_ads do
|
|
|
|
scope.show_adsense_ads?
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer :current_user, :show_carbon_ads do
|
|
|
|
scope.show_carbon_ads?
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer :current_user, :show_amazon_ads do
|
|
|
|
scope.show_amazon_ads?
|
|
|
|
end
|
|
|
|
|
|
|
|
add_to_serializer :current_user, :show_adbutler_ads do
|
|
|
|
scope.show_adbutler_ads?
|
|
|
|
end
|
|
|
|
|
2024-02-15 16:52:15 -05:00
|
|
|
add_to_serializer :current_user, :show_to_groups do
|
|
|
|
scope.show_to_groups?
|
|
|
|
end
|
|
|
|
|
2019-04-18 17:52:59 -04:00
|
|
|
class AdPlugin::Engine < ::Rails::Engine
|
2022-12-29 07:29:26 -05:00
|
|
|
engine_name "adplugin"
|
2019-04-18 17:52:59 -04:00
|
|
|
isolate_namespace AdPlugin
|
|
|
|
end
|
|
|
|
|
|
|
|
AdPlugin::Engine.routes.draw do
|
2022-12-29 07:29:26 -05:00
|
|
|
root to: "house_ads#index"
|
|
|
|
resources :house_creatives, only: %i[index show create update destroy], controller: "house_ads"
|
|
|
|
resources :house_settings, only: [:update], controller: "house_ad_settings"
|
2019-04-18 17:52:59 -04:00
|
|
|
end
|
|
|
|
|
2019-02-04 16:14:43 -05:00
|
|
|
Discourse::Application.routes.append do
|
2022-12-29 07:29:26 -05:00
|
|
|
get "/ads.txt" => "adstxt#index"
|
|
|
|
mount ::AdPlugin::Engine, at: "/admin/plugins/pluginad", constraints: AdminConstraint.new
|
2019-02-04 16:14:43 -05:00
|
|
|
end
|
|
|
|
end
|