Transfer files from Discourse plugin to here

This commit is contained in:
vi 2015-07-24 14:01:47 +10:00
parent 2679384ba1
commit 21362c7632
11 changed files with 258 additions and 1 deletions

View File

@ -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

View File

@ -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')
});

View File

@ -0,0 +1,11 @@
<div class="google-dfp-ad-label"><h2>ADVERTISEMENT FROM GOOGLE-DFT-AD</h2></div>
<div id={{divId}} style='width: {{const_width}}px; height: {{const_height}}px' class="dfp-ad-unit" align=center>
{{#if loadedGoogletag}}
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('{{divId}}'); });
</script>
{{/if}}
</div>

View File

@ -0,0 +1,3 @@
{{#if siteSettings.dfp_topic_list_top_code}}
{{google-dfp-ad placement="topic-list-top"}}
{{/if}}

View File

@ -0,0 +1,3 @@
{{#if siteSettings.dfp_topic_above_post_stream_code}}
{{google-dfp-ad placement="topic-above-post-stream"}}
{{/if}}

View File

@ -0,0 +1,3 @@
{{#if siteSettings.dfp_topic_above_suggested_code}}
{{google-dfp-ad placement="topic-above-suggested"}}
{{/if}}

View File

@ -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;
}

View File

@ -0,0 +1,6 @@
en:
admin_js:
admin:
site_settings:
categories:
ad_plugin: 'Ad Plugin'

View File

@ -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!"

37
config/settings.yml Normal file
View File

@ -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

32
plugin.rb Normal file
View File

@ -0,0 +1,32 @@
# name: discourse-adplugin
# about: Ad Plugin for Discourse (dfp)
# version: 0.1
# authors: Vi and Sarah (Team Melbourne)
register_css <<CSS
.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;
}
CSS