2018-10-22 19:49:32 +01:00
|
|
|
import PostModel from "discourse/models/post";
|
|
|
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
2015-08-04 11:25:00 +10:00
|
|
|
|
|
|
|
export default {
|
2018-10-22 19:49:32 +01:00
|
|
|
name: "initialize-ad-plugin",
|
2016-02-19 15:06:13 -05:00
|
|
|
initialize(container) {
|
2018-10-22 19:49:32 +01:00
|
|
|
const siteSettings = container.lookup("site-settings:main");
|
2016-02-19 15:06:13 -05:00
|
|
|
|
2017-09-05 09:22:23 +08:00
|
|
|
PostModel.reopen({
|
2018-06-20 09:15:15 -06:00
|
|
|
postSpecificCountDFP: function() {
|
2016-04-21 18:09:46 -04:00
|
|
|
return this.isNthPost(parseInt(siteSettings.dfp_nth_post_code));
|
2018-10-22 19:49:32 +01:00
|
|
|
}.property("post_number"),
|
2015-08-25 14:30:23 +10:00
|
|
|
|
2018-06-20 09:15:15 -06:00
|
|
|
postSpecificCountAdsense: function() {
|
2016-04-21 18:09:46 -04:00
|
|
|
return this.isNthPost(parseInt(siteSettings.adsense_nth_post_code));
|
2018-10-22 19:49:32 +01:00
|
|
|
}.property("post_number"),
|
2015-09-10 22:48:14 +10:00
|
|
|
|
2018-06-20 09:15:15 -06:00
|
|
|
postSpecificCountAmazon: function() {
|
2016-04-21 18:09:46 -04:00
|
|
|
return this.isNthPost(parseInt(siteSettings.amazon_nth_post_code));
|
2018-10-22 19:49:32 +01:00
|
|
|
}.property("post_number"),
|
2016-04-21 18:09:46 -04:00
|
|
|
|
2018-06-20 09:15:15 -06:00
|
|
|
postSpecificCountCodeFund: function() {
|
|
|
|
return this.isNthPost(parseInt(siteSettings.codefund_nth_post));
|
2018-10-22 19:49:32 +01:00
|
|
|
}.property("post_number"),
|
2018-06-07 17:17:19 -06:00
|
|
|
|
2018-06-20 09:15:15 -06:00
|
|
|
isNthPost: function(n) {
|
2016-04-21 18:09:46 -04:00
|
|
|
if (n && n > 0) {
|
2018-10-22 19:49:32 +01:00
|
|
|
return this.get("post_number") % n === 0;
|
2016-04-21 18:09:46 -04:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2017-09-05 09:22:23 +08:00
|
|
|
});
|
2016-02-22 12:11:29 -05:00
|
|
|
|
2018-10-22 19:49:32 +01:00
|
|
|
withPluginApi("0.1", api => {
|
|
|
|
api.decorateWidget("post:after", dec => {
|
2016-11-23 14:29:30 -05:00
|
|
|
if (dec.canConnectComponent) {
|
2018-06-07 17:17:19 -06:00
|
|
|
return dec.connect({
|
2018-10-22 19:49:32 +01:00
|
|
|
component: "adplugin-container",
|
|
|
|
context: "model"
|
2018-06-07 17:17:19 -06:00
|
|
|
});
|
2016-11-23 14:29:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Old way for backwards compatibility
|
2016-02-22 12:11:29 -05:00
|
|
|
return dec.connect({
|
2018-10-22 19:49:32 +01:00
|
|
|
templateName: "connectors/post-bottom/discourse-adplugin",
|
|
|
|
context: "model"
|
2016-02-22 12:11:29 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-08-04 11:25:00 +10:00
|
|
|
}
|
|
|
|
};
|