From c5272db7f3f1bccea4151e0cb05065744735bfc8 Mon Sep 17 00:00:00 2001 From: Diego Barreiro Date: Sun, 7 Apr 2019 03:14:27 +0200 Subject: [PATCH] UX: Init Carbon Ads --- .../discourse/components/carbonads-ad.js.es6 | 33 +++++++++++++++++++ .../templates/components/carbonads-ad.hbs | 4 +++ .../discourse-adplugin.hbs | 6 ++++ .../discourse-adplugin.hbs | 6 ++++ config/locales/client.en.yml | 1 + config/locales/server.en.yml | 6 ++++ config/settings.yml | 18 ++++++++++ 7 files changed, 74 insertions(+) create mode 100644 assets/javascripts/discourse/components/carbonads-ad.js.es6 create mode 100644 assets/javascripts/discourse/templates/components/carbonads-ad.hbs diff --git a/assets/javascripts/discourse/components/carbonads-ad.js.es6 b/assets/javascripts/discourse/components/carbonads-ad.js.es6 new file mode 100644 index 0000000..9bf98e5 --- /dev/null +++ b/assets/javascripts/discourse/components/carbonads-ad.js.es6 @@ -0,0 +1,33 @@ +import { + default as computed, + observes +} from "ember-addons/ember-computed-decorators"; + +var currentUser = Discourse.User.current(), + serve_id = Discourse.SiteSettings.carbonads_serve_id, + placement = Discourse.SiteSettings.carbonads_placement; + +export default Ember.Component.extend({ + init: function() { + this.set("serve_id", serve_id); + this.set("placement", placement); + this._super(); + }, + + url: function() { + return (`//cdn.carbonads.com/carbon.js?serve=${this.get("serve_id")}&placement=${this.get("placement")}`).htmlSafe(); + }.property("serve_id", "placement"), + + checkTrustLevels: function() { + return !( + currentUser && + currentUser.get("trust_level") > + Discourse.SiteSettings.carbonads_through_trust_level + ); + }.property("trust_level"), + + @computed("checkTrustLevels") + showAd: function(checkTrustLevels) { + return placement && serve_id && checkTrustLevels; + } +}); diff --git a/assets/javascripts/discourse/templates/components/carbonads-ad.hbs b/assets/javascripts/discourse/templates/components/carbonads-ad.hbs new file mode 100644 index 0000000..1818308 --- /dev/null +++ b/assets/javascripts/discourse/templates/components/carbonads-ad.hbs @@ -0,0 +1,4 @@ +{{#if showAd}} + +{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs index f0e9a5d..3a50085 100644 --- a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-adplugin.hbs @@ -11,6 +11,9 @@ {{#if siteSettings.codefund_top_of_topic_list_enabled}} {{codefund-ad placement="topic-list-top" listLoading=listLoading refreshOnChange=listLoading}} {{/if}} + {{#if siteSettings.carbonads_topic_list_top_enabled}} + {{carbonads-ad}} + {{/if}} {{else}} {{#if siteSettings.adsense_topic_list_top_code}} {{google-adsense placement="topic-list-top" listLoading=listLoading}} @@ -24,4 +27,7 @@ {{#if siteSettings.codefund_top_of_topic_list_enabled}} {{codefund-ad placement="topic-list-top" listLoading=listLoading refreshOnChange=listLoading}} {{/if}} + {{#if siteSettings.carbonads_topic_list_top_enabled}} + {{carbonads-ad}} + {{/if}} {{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs index e57429a..e5d3d74 100644 --- a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs +++ b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-adplugin.hbs @@ -11,6 +11,9 @@ {{#if siteSettings.codefund_above_post_stream_enabled}} {{codefund-ad placement="topic-above-post-stream"}} {{/if}} + {{#if siteSettings.carbonads_above_post_stream_enabled}} + {{carbonads-ad}} + {{/if}} {{else}} {{#if siteSettings.adsense_topic_above_post_stream_code}} {{google-adsense placement="topic-above-post-stream"}} @@ -24,4 +27,7 @@ {{#if siteSettings.codefund_above_post_stream_enabled}} {{codefund-ad placement="topic-above-post-stream"}} {{/if}} + {{#if siteSettings.carbonads_above_post_stream_enabled}} + {{carbonads-ad}} + {{/if}} {{/if}} \ No newline at end of file diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0159791..6cdb0a9 100755 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -10,3 +10,4 @@ en: adsense_plugin: 'AdSense' amazon_plugin: 'Amazon' codefund_plugin: 'CodeFund' + carbonads_plugin: 'Carbon Ads' diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index aa95a26..934bed9 100755 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -90,3 +90,9 @@ en: codefund_above_post_stream_enabled: "Show an ad above the post stream" codefund_above_suggested_enabled: "Show an ad above the suggested topic list" codefund_top_of_topic_list_enabled: "Show an ad above the topic list" + + carbonads_serve_id: "Your Carbon Ads Serve ID" + carbonads_placement: "Your Carbon Ads Placement" + carbonads_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads." + carbonads_topic_list_top_enabled: "Show an ad above the topic list" + carbonads_above_post_stream_enabled: "Show an ad above the post stream" diff --git a/config/settings.yml b/config/settings.yml index 8e7ee93..927e277 100755 --- a/config/settings.yml +++ b/config/settings.yml @@ -379,3 +379,21 @@ codefund_plugin: codefund_top_of_topic_list_enabled: default: true client: true + +carbonads_plugin: + carbonads_serve_id: + client: true + default: "" + carbonads_placement: + client: true + default: "" + carbonads_through_trust_level: + client: true + default: 2 + enum: "TrustLevelSetting" + carbonads_topic_list_top_enabled: + client: true + default: false + carbonads_above_post_stream_enabled: + client: true + default: false