diff --git a/README.md b/README.md index 71dfcb3..ded095e 100644 --- a/README.md +++ b/README.md @@ -1 +1,57 @@ -# discourse-adplugin +# Discourse-Adplugin + +Ad plugin for Discourse forum. + +## Installation + +* Supported Discourse version: v1.4 + +### Non-docker installation + +* Run `bundle exec rake plugin:install repo=http://github.com/team-melbourne-rgsoc2015/discourse-adplugin` in your discourse directory +* In development mode, run `bundle exec rake assets:clean` +* In production, recompile your assets: `bundle exec rake assets:precompile` +* Restart Discourse + +### Docker installation + +As seen in a [how-to on meta.discourse.org](https://meta.discourse.org/t/advanced-troubleshooting-with-docker/15927#Example:%20Install%20a%20plugin), simply **add the plugin's repo url to your container's app.yml file**: + +```yml +hooks: + after_code: + - exec: + cd: $home/plugins + cmd: + - mkdir -p plugins + - git clone https://github.com/team-melbourne-rgsoc2015/discourse-adplugin.git +``` +* Rebuild the container + +``` +cd /var/docker +git pull +./launcher rebuild app +``` + + +## Usage + +* Go to Admin > Settings > Ad Plugin +* Add DFP link into code boxes, input width and height based on Google Ad Ad units +* If you wish to disable the ad, tick ad disabling box + +# Ad Providers Supported + +* Google DFP + +## License + +GPL v2 + +TO-DO: + +* Publisher ID support +* Add size restrictions in ad slot inventory + size input fields +* Trust levels +* More ad providers diff --git a/assets/javascripts/discourse/components/google-dfp-ad.js.es6 b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 new file mode 100644 index 0000000..2b7e723 --- /dev/null +++ b/assets/javascripts/discourse/components/google-dfp-ad.js.es6 @@ -0,0 +1,67 @@ +import loadScript from 'discourse/lib/load-script'; + +const const_width = 300; +const const_height = 250; + +var _loaded = false, + _promise = null; + + +function loadGoogle(settings) { + if (_loaded) { + return Ember.RSVP.resolve(); + } + + if (_promise) { + return _promise; + } + + // The boilerplate code + var dfpSrc = (('https:' == document.location.protocol) ? 'https:' : 'http:') + '//www.googletagservices.com/tag/js/gpt.js'; + _promise = loadScript(dfpSrc, { scriptTag: true }).then(function() { + _loaded = true; + if (window.googletag === undefined) { + console.log('googletag is undefined!'); + } + + // Define our ad units - extend for mobile view. + googletag.cmd.push(function() { + if (settings.dfp_topic_list_top_code && !settings.dfp_show_topic_list_top) { + googletag.defineSlot(settings.dfp_topic_list_top_code, [parseInt(settings.dfp_size_topic_list_top_width_code), parseInt(settings.dfp_size_topic_list_top_height_code)], 'div-gpt-ad-topic-list-top').addService(googletag.pubads()); + } + if (settings.dfp_topic_above_post_stream_code && !settings.dfp_show_topic_above_post_stream) { + googletag.defineSlot(settings.dfp_topic_above_post_stream_code, [parseInt(settings.dfp_size_topic_above_post_stream_width_code), parseInt(settings.dfp_size_topic_above_post_stream_height_code)], 'div-gpt-ad-topic-above-post-stream').addService(googletag.pubads()); + } + if (settings.dfp_topic_above_suggested_code && !settings.dfp_show_topic_above_suggested) { + googletag.defineSlot(settings.dfp_topic_above_suggested_code, [parseInt(settings.dfp_size_topic_above_suggested_width_code), parseInt(settings.dfp_size_topic_above_suggested_height_code)], 'div-gpt-ad-topic-above-suggested').addService(googletag.pubads()); + } + googletag.pubads().enableSingleRequest(); + googletag.enableServices(); + }); + }); + + return _promise; +} + + +// Ember component - the class is the adblock and css +export default Ember.Component.extend({ + const_width: const_width, + const_height: const_height, + + classNames: ['google-dfp-ad'], + loadedGoogletag: false, + + // Part of the divID of the div part of the GPT + divId: function() { + return "div-gpt-ad-" + this.get('placement'); + }.property('placement'), + + + _initGoogleDFP: function() { + var self = this; + loadGoogle(this.siteSettings).then(function() { + self.set('loadedGoogletag', true); + }); + }.on('didInsertElement') +}); diff --git a/assets/javascripts/discourse/templates/components/google-dfp-ad.hbs b/assets/javascripts/discourse/templates/components/google-dfp-ad.hbs new file mode 100644 index 0000000..b70849c --- /dev/null +++ b/assets/javascripts/discourse/templates/components/google-dfp-ad.hbs @@ -0,0 +1,11 @@ +

ADVERTISEMENT FROM GOOGLE-DFT-AD

+
+ {{#if loadedGoogletag}} + + {{/if}} +
+ + + diff --git a/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs new file mode 100644 index 0000000..cc027b1 --- /dev/null +++ b/assets/javascripts/discourse/templates/connectors/discovery-list-container-top/discourse-google-dfp.hbs @@ -0,0 +1,3 @@ +{{#if siteSettings.dfp_topic_list_top_code}} + {{google-dfp-ad placement="topic-list-top"}} +{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs new file mode 100644 index 0000000..d9a81de --- /dev/null +++ b/assets/javascripts/discourse/templates/connectors/topic-above-post-stream/discourse-google-dfp.hbs @@ -0,0 +1,3 @@ +{{#if siteSettings.dfp_topic_above_post_stream_code}} + {{google-dfp-ad placement="topic-above-post-stream"}} +{{/if}} \ No newline at end of file diff --git a/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs new file mode 100644 index 0000000..0234980 --- /dev/null +++ b/assets/javascripts/discourse/templates/connectors/topic-above-suggested/discourse-google-dfp.hbs @@ -0,0 +1,3 @@ +{{#if siteSettings.dfp_topic_above_suggested_code}} + {{google-dfp-ad placement="topic-above-suggested"}} +{{/if}} \ No newline at end of file diff --git a/auto_generated/plugin_5e03562e98e357709eaba07c3a0e9054afdd7697.css b/auto_generated/plugin_5e03562e98e357709eaba07c3a0e9054afdd7697.css new file mode 100644 index 0000000..677144a --- /dev/null +++ b/auto_generated/plugin_5e03562e98e357709eaba07c3a0e9054afdd7697.css @@ -0,0 +1,25 @@ + +.google-dfp-ad { + padding: 3px; + margin-bottom: 10px; + clear: both; +} + +.google-dfp-ad .dfp-ad-unit { + margin: 0 auto; +} + +.google-dfp-ad .google-dfp-ad-label { + width: 728px; + margin: 0 auto; +} + +.google-dfp-ad .google-dfp-ad-label h2 { + margin: 4px 0 !important; + color: #858a8c; + text-transform: uppercase; + font-size: 12px; + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + font-weight: normal; +} + diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml new file mode 100644 index 0000000..320707d --- /dev/null +++ b/config/locales/client.en.yml @@ -0,0 +1,6 @@ +en: + admin_js: + admin: + site_settings: + categories: + ad_plugin: 'Ad Plugin' \ No newline at end of file diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml new file mode 100644 index 0000000..7dbadbc --- /dev/null +++ b/config/locales/server.en.yml @@ -0,0 +1,14 @@ +en: + site_settings: + dfp_show_topic_list_top: "Disable topic_list_top ad" + dfp_topic_list_top_code: "Show leaderboard ad above topic lists." + dfp_show_topic_above_post_stream: "Disable topic_above_post_stream ad" + dfp_topic_above_post_stream_code: "Show leaderboard ad above post stream" + dfp_show_topic_above_suggested: "Disable topic_above_suggested ad" + dfp_topic_above_suggested_code: "Show leaderboard ad above suggested topics" + dfp_size_topic_list_top_width_code: "Put your ad topic list top size width!" + dfp_size_topic_list_top_height_code: "Put your ad topic above post stream size height!" + dfp_size_topic_above_post_stream_width_code: "Put your ad topic above post stream size width!" + dfp_size_topic_above_post_stream_height_code: "Put your ad topic list top size height!" + dfp_size_topic_above_suggested_width_code: "Put your ad topic above suggested size width!" + dfp_size_topic_above_suggested_height_code: "Put your ad topic above suggested size height!" \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml new file mode 100644 index 0000000..f31c8ef --- /dev/null +++ b/config/settings.yml @@ -0,0 +1,37 @@ +ad_plugin: + dfp_topic_list_top_code: + client: true + default: '' + dfp_size_topic_list_top_width_code: + client: true + default: '' + dfp_size_topic_list_top_height_code: + client: true + default: '' + dfp_show_topic_list_top: + client: true + default: false + dfp_topic_above_post_stream_code: + client: true + default: '' + dfp_size_topic_above_post_stream_width_code: + client: true + default: '' + dfp_size_topic_above_post_stream_height_code: + client: true + default: '' + dfp_show_topic_above_post_stream: + client: true + default: false + dfp_topic_above_suggested_code: + client: true + default: '' + dfp_size_topic_above_suggested_width_code: + client: true + default: '' + dfp_size_topic_above_suggested_height_code: + client: true + default: '' + dfp_show_topic_above_suggested: + client: true + default: false \ No newline at end of file diff --git a/plugin.rb b/plugin.rb new file mode 100644 index 0000000..94c8feb --- /dev/null +++ b/plugin.rb @@ -0,0 +1,32 @@ +# name: discourse-adplugin +# about: Ad Plugin for Discourse (dfp) +# version: 0.1 +# authors: Vi and Sarah (Team Melbourne) + +register_css <