diff --git a/assets/javascripts/discourse/components/codefund-ad.js.es6 b/assets/javascripts/discourse/components/codefund-ad.js.es6
new file mode 100644
index 0000000..3a4307b
--- /dev/null
+++ b/assets/javascripts/discourse/components/codefund-ad.js.es6
@@ -0,0 +1,98 @@
+var _loaded = false,
+ _promise = null,
+ currentUser = Discourse.User.current(),
+ propertyId = Discourse.SiteSettings.codefund_property_code;
+
+function loadCodeFund() {
+ if (_loaded) {
+ return Ember.RSVP.resolve();
+ }
+
+ if (_promise) {
+ return _promise;
+ }
+
+ const url = 'https://codefund.io/t/s/' + propertyId + '/details.json';
+
+ _promise = new Promise(function(resolve, reject){
+ let xhr = new XMLHttpRequest();
+
+ xhr.open('GET', url);
+ xhr.onreadystatechange = handler;
+ xhr.responseType = 'json';
+ xhr.setRequestHeader('Accept', 'application/json');
+ xhr.send();
+
+ function handler() {
+ if (this.readyState === this.DONE) {
+ _loaded = true;
+ if (this.status === 200) {
+ resolve(this.response);
+ } else {
+ reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
+ }
+ }
+ };
+ });
+
+ return _promise;
+}
+
+
+export default Ember.Component.extend({
+ classNameBindings: [':codefund-ad', 'classForSlot', 'isResponsive:codefund-responsive'],
+ propertyId: propertyId,
+ adRequested: false,
+ adDetails: {},
+
+ _triggerAds() {
+ this.set('adRequested', true);
+ loadCodeFund().then((data) => {
+ this.set('adDetails', data);
+ this.set('adRequested', false);
+ console.log('Loaded ad');
+ }).catch(error => console.log(error));
+ },
+
+ didInsertElement() {
+ this._super();
+
+ if (!this.get('showAd')) { return; }
+
+ if (this.get('listLoading')) { return; }
+
+ Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
+ },
+
+ waitForLoad: function() {
+ if (this.get('adRequested')) { return; } // already requested that this ad unit be populated
+ if (!this.get('listLoading')) {
+ Ember.run.scheduleOnce('afterRender', this, this._triggerAds);
+ }
+ }.observes('listLoading'),
+
+ checkTrustLevels: function() {
+ return !((currentUser) && (currentUser.get('trust_level') > Discourse.SiteSettings.codefund_through_trust_level));
+ }.property('trust_level'),
+
+ showAd: function() {
+ return Discourse.SiteSettings.codefund_property_code && this.get('checkTrustLevels');
+ }.property('checkTrustLevels'),
+
+ displayPostBottom: function() {
+ return this.get('placement') === 'post-bottom';
+ }.property('placement'),
+
+ displayTopicAbovePostStream: function() {
+ return this.get('placement') === 'topic-above-post-stream';
+ }.property('placement'),
+
+ displayTopicAboveSuggested: function() {
+ return this.get('placement') === 'topic-above-suggested';
+ }.property('placement'),
+
+ displayTopicListTop: function() {
+ return this.get('placement') === 'topic-list-top';
+ }.property('placement')
+
+});
diff --git a/assets/javascripts/discourse/templates/components/adplugin-container.hbs b/assets/javascripts/discourse/templates/components/adplugin-container.hbs
index 65e1b28..bcffef5 100644
--- a/assets/javascripts/discourse/templates/components/adplugin-container.hbs
+++ b/assets/javascripts/discourse/templates/components/adplugin-container.hbs
@@ -14,6 +14,11 @@
{{amazon-product-links placement="post-bottom" postNumber=model.post_number}}
{{/if}}
{{/if}}
+ {{#if model.postSpecificCountCodeFund}}
+ {{#if siteSettings.codefund_below_post_enabled}}
+ {{codefund-ad placement="post-bottom" postNumber=model.post_number}}
+ {{/if}}
+ {{/if}}
{{else}}
{{#if model.postSpecificCountAdsense}}
{{#if siteSettings.adsense_post_bottom_code}}
@@ -30,4 +35,9 @@
{{amazon-product-links placement="post-bottom" postNumber=model.post_number}}
{{/if}}
{{/if}}
+ {{#if model.postSpecificCountCodeFund}}
+ {{#if siteSettings.codefund_below_post_enabled}}
+ {{codefund-ad placement="post-bottom" postNumber=model.post_number}}
+ {{/if}}
+ {{/if}}
{{/if}}
diff --git a/assets/javascripts/discourse/templates/components/codefund-ad.hbs b/assets/javascripts/discourse/templates/components/codefund-ad.hbs
new file mode 100644
index 0000000..e89aac2
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/codefund-ad.hbs
@@ -0,0 +1,29 @@
+{{#if showAd}}
+ {{#if site.mobileView}}
+ {{#if displayPostBottom}}
+ {{partial "components/codefund/post-bottom"}}
+ {{/if}}
+ {{#if displayTopicAbovePostStream}}
+ {{partial "components/codefund/topic-above-post-stream"}}
+ {{/if}}
+ {{#if displayTopicAboveSuggested}}
+ {{partial "components/codefund/topic-above-suggested"}}
+ {{/if}}
+ {{#if displayTopicListTop}}
+ {{partial "components/codefund/topic-list-top"}}
+ {{/if}}
+ {{else}}
+ {{#if displayPostBottom}}
+ {{partial "components/codefund/post-bottom"}}
+ {{/if}}
+ {{#if displayTopicAbovePostStream}}
+ {{partial "components/codefund/topic-above-post-stream"}}
+ {{/if}}
+ {{#if displayTopicAboveSuggested}}
+ {{partial "components/codefund/topic-above-suggested"}}
+ {{/if}}
+ {{#if displayTopicListTop}}
+ {{partial "components/codefund/topic-list-top"}}
+ {{/if}}
+ {{/if}}
+{{/if}}
diff --git a/assets/javascripts/discourse/templates/components/codefund/post-bottom.hbs b/assets/javascripts/discourse/templates/components/codefund/post-bottom.hbs
new file mode 100644
index 0000000..70461da
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/codefund/post-bottom.hbs
@@ -0,0 +1,8 @@
+
+
+ {{#if siteSettings.codefund_display_advertiser_labels}}
+ {{siteSettings.codefund_advertiser_short_label}}
+ {{/if}}
+ {{adDetails.headline}} {{adDetails.description}}
+
+
diff --git a/assets/javascripts/discourse/templates/components/codefund/topic-above-post-stream.hbs b/assets/javascripts/discourse/templates/components/codefund/topic-above-post-stream.hbs
new file mode 100644
index 0000000..cd6ea94
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/codefund/topic-above-post-stream.hbs
@@ -0,0 +1,11 @@
+
+
+ {{#if siteSettings.codefund_display_advertiser_labels}}
+ {{siteSettings.codefund_advertiser_label}}
+ {{/if}}
+ {{adDetails.headline}} {{adDetails.description}}
+
+
+ ads via codefund.io
+
+
diff --git a/assets/javascripts/discourse/templates/components/codefund/topic-above-suggested.hbs b/assets/javascripts/discourse/templates/components/codefund/topic-above-suggested.hbs
new file mode 100644
index 0000000..7d0a19c
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/codefund/topic-above-suggested.hbs
@@ -0,0 +1,11 @@
+
+
+ {{#if siteSettings.codefund_display_advertiser_labels}}
+ {{siteSettings.codefund_advertiser_label}}
+ {{/if}}
+ {{adDetails.headline}} {{adDetails.description}}
+
+
+ ads via codefund.io
+
+
diff --git a/assets/javascripts/discourse/templates/components/codefund/topic-list-top.hbs b/assets/javascripts/discourse/templates/components/codefund/topic-list-top.hbs
new file mode 100644
index 0000000..7ac35a7
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/codefund/topic-list-top.hbs
@@ -0,0 +1,11 @@
+
+
+ {{#if siteSettings.codefund_display_advertiser_labels}}
+ {{siteSettings.codefund_advertiser_label}}
+ {{/if}}
+ {{adDetails.headline}} {{adDetails.description}}
+
+
+ ads via codefund.io
+
+
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 af418d9..f0e9a5d 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
@@ -8,6 +8,9 @@
{{#if siteSettings.amazon_mobile_topic_list_top_src_code}}
{{amazon-product-links placement="topic-list-top" listLoading=listLoading}}
{{/if}}
+ {{#if siteSettings.codefund_top_of_topic_list_enabled}}
+ {{codefund-ad placement="topic-list-top" listLoading=listLoading refreshOnChange=listLoading}}
+ {{/if}}
{{else}}
{{#if siteSettings.adsense_topic_list_top_code}}
{{google-adsense placement="topic-list-top" listLoading=listLoading}}
@@ -18,4 +21,7 @@
{{#if siteSettings.amazon_topic_list_top_src_code}}
{{amazon-product-links placement="topic-list-top" listLoading=listLoading}}
{{/if}}
+ {{#if siteSettings.codefund_top_of_topic_list_enabled}}
+ {{codefund-ad placement="topic-list-top" listLoading=listLoading refreshOnChange=listLoading}}
+ {{/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 ed36964..e57429a 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
@@ -8,6 +8,9 @@
{{#if siteSettings.amazon_mobile_topic_above_post_stream_src_code}}
{{amazon-product-links placement="topic-above-post-stream"}}
{{/if}}
+ {{#if siteSettings.codefund_above_post_stream_enabled}}
+ {{codefund-ad placement="topic-above-post-stream"}}
+ {{/if}}
{{else}}
{{#if siteSettings.adsense_topic_above_post_stream_code}}
{{google-adsense placement="topic-above-post-stream"}}
@@ -18,4 +21,7 @@
{{#if siteSettings.amazon_topic_above_post_stream_src_code}}
{{amazon-product-links placement="topic-above-post-stream"}}
{{/if}}
+ {{#if siteSettings.codefund_above_post_stream_enabled}}
+ {{codefund-ad placement="topic-above-post-stream"}}
+ {{/if}}
{{/if}}
\ No newline at end of file
diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs
index 8e3f62c..8f45084 100644
--- a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs
+++ b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-adplugin.hbs
@@ -8,6 +8,9 @@
{{#if siteSettings.amazon_mobile_topic_above_suggested_src_code}}
{{amazon-product-links placement="topic-above-suggested"}}
{{/if}}
+ {{#if siteSettings.codefund_above_suggested_enabled}}
+ {{codefund-ad placement="topic-above-suggested"}}
+ {{/if}}
{{else}}
{{#if siteSettings.adsense_topic_above_suggested_code}}
{{google-adsense placement="topic-above-suggested"}}
@@ -18,4 +21,7 @@
{{#if siteSettings.amazon_topic_above_suggested_src_code}}
{{amazon-product-links placement="topic-above-suggested"}}
{{/if}}
+ {{#if siteSettings.codefund_above_suggested_enabled}}
+ {{codefund-ad placement="topic-above-suggested"}}
+ {{/if}}
{{/if}}
\ No newline at end of file
diff --git a/assets/javascripts/initializers/initialize-ad-plugin.js.es6 b/assets/javascripts/initializers/initialize-ad-plugin.js.es6
index 74aac40..9e216fc 100644
--- a/assets/javascripts/initializers/initialize-ad-plugin.js.es6
+++ b/assets/javascripts/initializers/initialize-ad-plugin.js.es6
@@ -1,5 +1,7 @@
import PostModel from 'discourse/models/post';
-import { withPluginApi } from 'discourse/lib/plugin-api';
+import {
+ withPluginApi
+} from 'discourse/lib/plugin-api';
export default {
name: 'initialize-ad-plugin',
@@ -7,19 +9,23 @@ export default {
const siteSettings = container.lookup('site-settings:main');
PostModel.reopen({
- postSpecificCountDFP: function() {
+ postSpecificCountDFP: function () {
return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code));
}.property('post_number'),
- postSpecificCountAdsense: function() {
+ postSpecificCountAdsense: function () {
return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code));
}.property('post_number'),
- postSpecificCountAmazon: function() {
+ postSpecificCountAmazon: function () {
return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code));
}.property('post_number'),
- isNthPost: function(n) {
+ postSpecificCountCodeFund: function () {
+ return this.isNthPost(parseInt(siteSettings.codefund_nth_post_code));
+ }.property('post_number'),
+
+ isNthPost: function (n) {
if (n && n > 0) {
return (this.get('post_number') % n) === 0;
} else {
@@ -32,7 +38,10 @@ export default {
api.decorateWidget('post:after', dec => {
if (dec.canConnectComponent) {
- return dec.connect({ component: 'adplugin-container', context: 'model' });
+ return dec.connect({
+ component: 'adplugin-container',
+ context: 'model'
+ });
}
// Old way for backwards compatibility
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index bb8ba7d..876dfc1 100755
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -8,4 +8,5 @@ en:
categories:
dfp_plugin: 'DFP'
adsense_plugin: 'Adsense'
- amazon_plugin: 'Amazon'
\ No newline at end of file
+ amazon_plugin: 'Amazon'
+ codefund_plugin: 'CodeFund'
\ No newline at end of file
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index b3f15f4..0e659ea 100755
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -78,3 +78,14 @@ en:
amazon_mobile_post_bottom_ad_width_code: "Input your ad width (mobile)"
amazon_mobile_post_bottom_ad_height_code: "Input your ad height (mobile)"
amazon_nth_post_code: "Show an ad after every N posts, where N is this value."
+
+ codefund_property_code: "Your CodeFund property ID"
+ codefund_advertiser_label: "Label that appears before the advertisement (e.g. Advertiser or Supporter)"
+ codefund_advertiser_short_label: "Abbreviated label that appears before the advertisement (e.g. Ad)"
+ codefund_display_advertiser_labels: "Show the advertiser label (e.g. 'Advertiser') on the ads"
+ codefund_through_trust_level: "Show your ads to users based on trust levels. Users with trust level higher than this value will not see ads"
+ codefund_nth_post_code: "Show an ad after every N posts, where N is this value"
+ codefund_below_post_enabled: "Show an ad below each blog post"
+ 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"
diff --git a/config/settings.yml b/config/settings.yml
index 1d119d8..10cade2 100755
--- a/config/settings.yml
+++ b/config/settings.yml
@@ -340,4 +340,39 @@ amazon_plugin:
default: ''
amazon_mobile_post_bottom_ad_height_code:
client: true
- default: ''
\ No newline at end of file
+ default: ''
+
+codefund_plugin:
+ codefund_property_code:
+ client: true
+ default: ''
+ regex: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
+ codefund_advertiser_label:
+ client: true
+ default: 'Advertiser'
+ codefund_advertiser_short_label:
+ client: true
+ default: 'Ad'
+ codefund_through_trust_level:
+ client: true
+ default: 2
+ enum: 'TrustLevelSetting'
+ codefund_nth_post_code:
+ client: true
+ default: 4
+ min: 1
+ codefund_display_advertiser_labels:
+ default: true
+ client: true
+ codefund_below_post_enabled:
+ default: true
+ client: true
+ codefund_above_post_stream_enabled:
+ default: true
+ client: true
+ codefund_above_suggested_enabled:
+ default: true
+ client: true
+ codefund_top_of_topic_list_enabled:
+ default: true
+ client: true
diff --git a/plugin.rb b/plugin.rb
index d560dac..cff4605 100755
--- a/plugin.rb
+++ b/plugin.rb
@@ -6,6 +6,9 @@
register_css <