FEATURE: use groups to control who sees ads" and all later
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
|
||||
export default Ember.Component.extend({
|
||||
@computed()
|
||||
showToGroups: function() {
|
||||
const currentUser = Discourse.User.current();
|
||||
|
||||
if (
|
||||
!currentUser ||
|
||||
!currentUser.get("groups") ||
|
||||
!this.siteSettings.no_ads_for_groups ||
|
||||
this.siteSettings.no_ads_for_groups.length === 0
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const noAdsGroupNames = this.siteSettings.no_ads_for_groups.split("|");
|
||||
|
||||
return !currentUser
|
||||
.get("groups")
|
||||
.any(group => noAdsGroupNames.includes(group.name));
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,9 @@
|
||||
var currentUser = Discourse.User.current();
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component";
|
||||
import computed from "ember-addons/ember-computed-decorators";
|
||||
|
||||
var data = {
|
||||
const currentUser = Discourse.User.current();
|
||||
|
||||
const data = {
|
||||
"topic-list-top": {},
|
||||
"topic-above-post-stream": {},
|
||||
"topic-above-suggested": {},
|
||||
@@ -119,10 +122,12 @@ if (
|
||||
);
|
||||
}
|
||||
|
||||
export default Ember.Component.extend({
|
||||
export default AdComponent.extend({
|
||||
classNames: ["amazon-product-links"],
|
||||
|
||||
init: function() {
|
||||
showAd: Ember.computed.and("showToTrustLevel", "showToGroups"),
|
||||
|
||||
init() {
|
||||
let placement = this.get("placement");
|
||||
this.set("user_input", data[placement]["user_input"]);
|
||||
this.set("amazon_width", data[placement]["amazon_width"]);
|
||||
@@ -133,35 +138,37 @@ export default Ember.Component.extend({
|
||||
this._super();
|
||||
},
|
||||
|
||||
adWrapperStyle: function() {
|
||||
return `width: ${this.get("amazon_width")}px; height: ${this.get(
|
||||
"amazon_height"
|
||||
)}px;`.htmlSafe();
|
||||
}.property("amazon_width", "amazon_height"),
|
||||
@computed("amazon_width", "amazon_height")
|
||||
adWrapperStyle(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
adWrapperStyleMobile: function() {
|
||||
return `width: ${this.get("mobile_amazon_width")}px; height: ${this.get(
|
||||
"mobile_amazon_height"
|
||||
)}px;`.htmlSafe();
|
||||
}.property("mobile_amazon_width", "mobile_amazon_height"),
|
||||
@computed("mobile_amazon_width", "mobile_amazon_height")
|
||||
adWrapperStyleMobile(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
adTitleStyleMobile: function() {
|
||||
return `width: ${this.get("mobile_amazon_width")}px;`.htmlSafe();
|
||||
}.property("mobile_amazon_width"),
|
||||
@computed("mobile_amazon_width")
|
||||
adTitleStyleMobile(w) {
|
||||
return `width: ${w}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
userInput: function() {
|
||||
return `${this.get("user_input")}`.htmlSafe();
|
||||
}.property("user_input"),
|
||||
@computed("user_input")
|
||||
userInput(userInput) {
|
||||
return `${userInput}`.htmlSafe();
|
||||
},
|
||||
|
||||
userInputMobile: function() {
|
||||
return `${this.get("user_input_mobile")}`.htmlSafe();
|
||||
}.property("user_input_mobile"),
|
||||
@computed("user_input_mobile")
|
||||
userInputMobile(userInput) {
|
||||
return `${userInput}`.htmlSafe();
|
||||
},
|
||||
|
||||
checkTrustLevels: function() {
|
||||
@computed()
|
||||
showToTrustLevel() {
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
Discourse.SiteSettings.amazon_through_trust_level
|
||||
);
|
||||
}.property("trust_level")
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
@@ -7,21 +8,20 @@ const currentUser = Discourse.User.current(),
|
||||
serve_id = Discourse.SiteSettings.carbonads_serve_id,
|
||||
placement = Discourse.SiteSettings.carbonads_placement;
|
||||
|
||||
export default Ember.Component.extend({
|
||||
init: function() {
|
||||
export default AdComponent.extend({
|
||||
init() {
|
||||
this.set("serve_id", serve_id);
|
||||
this.set("placement", placement);
|
||||
this._super();
|
||||
},
|
||||
|
||||
@computed("serve_id", "placement")
|
||||
url: function() {
|
||||
return (`//cdn.carbonads.com/carbon.js?serve=${this.get("serve_id")}&placement=${this.get("placement")}`).htmlSafe();
|
||||
url(serveId, placement) {
|
||||
return `//cdn.carbonads.com/carbon.js?serve=${serveId}&placement=${placement}`.htmlSafe();
|
||||
},
|
||||
|
||||
|
||||
@computed("trust_level")
|
||||
checkTrustLevels: function() {
|
||||
@computed()
|
||||
showToTrustLevel() {
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
@@ -29,8 +29,8 @@ export default Ember.Component.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("checkTrustLevels")
|
||||
showAd: function(checkTrustLevels) {
|
||||
return placement && serve_id && checkTrustLevels;
|
||||
@computed("showToTrustLevel", "showToGroups")
|
||||
showAd(showToTrustLevel, showToGroups) {
|
||||
return placement && serve_id && showToTrustLevel && showToGroups;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
|
||||
var _loaded = false,
|
||||
_promise = null,
|
||||
currentUser = Discourse.User.current(),
|
||||
let _loaded = false,
|
||||
_promise = null;
|
||||
|
||||
const currentUser = Discourse.User.current(),
|
||||
propertyId = Discourse.SiteSettings.codefund_property_id;
|
||||
|
||||
function loadCodeFund() {
|
||||
@@ -48,12 +50,23 @@ function loadCodeFund() {
|
||||
return _promise;
|
||||
}
|
||||
|
||||
export default Ember.Component.extend({
|
||||
export default AdComponent.extend({
|
||||
classNameBindings: [":codefund-ad"],
|
||||
propertyId: propertyId,
|
||||
adRequested: false,
|
||||
adDetails: {},
|
||||
|
||||
displayPostBottom: Ember.computed.equal("placement", "post-bottom"),
|
||||
displayTopicAbovePostStream: Ember.computed.equal(
|
||||
"placement",
|
||||
"topic-above-post-stream"
|
||||
),
|
||||
displayTopicAboveSuggested: Ember.computed.equal(
|
||||
"placement",
|
||||
"topic-above-suggested"
|
||||
),
|
||||
displayTopicListTop: Ember.computed.equal("placement", "topic-list-top"),
|
||||
|
||||
_triggerAds() {
|
||||
if (!propertyId) return;
|
||||
|
||||
@@ -83,7 +96,7 @@ export default Ember.Component.extend({
|
||||
},
|
||||
|
||||
@observes("listLoading")
|
||||
waitForLoad: function() {
|
||||
waitForLoad() {
|
||||
if (this.get("adRequested")) {
|
||||
return;
|
||||
} // already requested that this ad unit be populated
|
||||
@@ -93,7 +106,7 @@ export default Ember.Component.extend({
|
||||
},
|
||||
|
||||
@computed()
|
||||
checkTrustLevels: function() {
|
||||
showToTrustLevel() {
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
@@ -101,28 +114,12 @@ export default Ember.Component.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("checkTrustLevels")
|
||||
showAd: function(checkTrustLevels) {
|
||||
return Discourse.SiteSettings.codefund_property_id && checkTrustLevels;
|
||||
},
|
||||
|
||||
@computed("placement")
|
||||
displayPostBottom: function(placement) {
|
||||
return placement === "post-bottom";
|
||||
},
|
||||
|
||||
@computed("placement")
|
||||
displayTopicAbovePostStream: function() {
|
||||
return this.get("placement") === "topic-above-post-stream";
|
||||
},
|
||||
|
||||
@computed("placement")
|
||||
displayTopicAboveSuggested: function() {
|
||||
return this.get("placement") === "topic-above-suggested";
|
||||
},
|
||||
|
||||
@computed("placement")
|
||||
displayTopicListTop: function() {
|
||||
return this.get("placement") === "topic-list-top";
|
||||
@computed("showToTrustLevel", "showToGroups")
|
||||
showAd(showToTrustLevel, showToGroups) {
|
||||
return (
|
||||
Discourse.SiteSettings.codefund_property_id &&
|
||||
showToTrustLevel &&
|
||||
showToGroups
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component";
|
||||
import {
|
||||
default as computed,
|
||||
observes
|
||||
@@ -146,7 +147,7 @@ if (Discourse.SiteSettings.adsense_publisher_code) {
|
||||
}
|
||||
}
|
||||
|
||||
export default Ember.Component.extend({
|
||||
export default AdComponent.extend({
|
||||
classNameBindings: [
|
||||
":google-adsense",
|
||||
"classForSlot",
|
||||
@@ -193,7 +194,7 @@ export default Ember.Component.extend({
|
||||
},
|
||||
|
||||
@observes("listLoading")
|
||||
waitForLoad: function() {
|
||||
waitForLoad() {
|
||||
if (this.get("adRequested")) {
|
||||
return;
|
||||
} // already requested that this ad unit be populated
|
||||
@@ -203,34 +204,34 @@ export default Ember.Component.extend({
|
||||
},
|
||||
|
||||
@computed("ad_width")
|
||||
isResponsive: function(adWidth) {
|
||||
isResponsive(adWidth) {
|
||||
return adWidth === "auto";
|
||||
},
|
||||
|
||||
@computed("placement", "checkTrustLevels")
|
||||
classForSlot: function(placement, shown) {
|
||||
return shown ? `adsense-${placement}`.htmlSafe() : "";
|
||||
@computed("placement", "showAd")
|
||||
classForSlot(placement, showAd) {
|
||||
return showAd ? `adsense-${placement}`.htmlSafe() : "";
|
||||
},
|
||||
|
||||
@computed("isResponsive")
|
||||
autoAdFormat: function(isResponsive) {
|
||||
autoAdFormat(isResponsive) {
|
||||
return isResponsive ? "auto".htmlSafe() : false;
|
||||
},
|
||||
|
||||
@computed("ad_width", "ad_height", "isResponsive")
|
||||
adWrapperStyle: function(w, h, isResponsive) {
|
||||
adWrapperStyle(w, h, isResponsive) {
|
||||
return (isResponsive ? "" : `width: ${w}; height: ${h};`).htmlSafe();
|
||||
},
|
||||
|
||||
@computed("adWrapperStyle", "isResponsive")
|
||||
adInsStyle: function(adWrapperStyle, isResponsive) {
|
||||
adInsStyle(adWrapperStyle, isResponsive) {
|
||||
return `display: ${
|
||||
isResponsive ? "block" : "inline-block"
|
||||
}; ${adWrapperStyle}`.htmlSafe();
|
||||
},
|
||||
|
||||
@computed()
|
||||
checkTrustLevels: function() {
|
||||
showToTrustLevel() {
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
@@ -238,8 +239,12 @@ export default Ember.Component.extend({
|
||||
);
|
||||
},
|
||||
|
||||
@computed("checkTrustLevels")
|
||||
showAd: function(shown) {
|
||||
return shown && Discourse.SiteSettings.adsense_publisher_code;
|
||||
@computed("showToTrustLevel", "showToGroups")
|
||||
showAd(showToTrustLevel, showToGroups) {
|
||||
return (
|
||||
showToTrustLevel &&
|
||||
showToGroups &&
|
||||
Discourse.SiteSettings.adsense_publisher_code
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad_component";
|
||||
import {
|
||||
default as computed,
|
||||
observes,
|
||||
on
|
||||
} from "ember-addons/ember-computed-decorators";
|
||||
import loadScript from "discourse/lib/load-script";
|
||||
|
||||
var currentUser = Discourse.User.current(),
|
||||
@@ -198,51 +204,56 @@ function loadGoogle() {
|
||||
return _promise;
|
||||
}
|
||||
|
||||
export default Ember.Component.extend({
|
||||
export default AdComponent.extend({
|
||||
classNameBindings: ["adUnitClass"],
|
||||
classNames: ["google-dfp-ad"],
|
||||
loadedGoogletag: false,
|
||||
refreshOnChange: null,
|
||||
|
||||
divId: function() {
|
||||
if (this.get("postNumber")) {
|
||||
return (
|
||||
"div-gpt-ad-" + this.get("placement") + "-" + this.get("postNumber")
|
||||
);
|
||||
@computed("placement", "postNumber")
|
||||
divId(placement, postNumber) {
|
||||
if (postNumber) {
|
||||
return `div-gpt-ad-${placement}-${postNumber}`;
|
||||
} else {
|
||||
return "div-gpt-ad-" + this.get("placement");
|
||||
return `div-gpt-ad-${placement}`;
|
||||
}
|
||||
}.property("placement", "postNumber"),
|
||||
},
|
||||
|
||||
adUnitClass: function() {
|
||||
return "dfp-ad-" + this.get("placement");
|
||||
}.property("placement"),
|
||||
@computed("placement", "showAd")
|
||||
adUnitClass(placement, showAd) {
|
||||
return showAd ? `dfp-ad-${placement}` : "";
|
||||
},
|
||||
|
||||
adWrapperStyle: function() {
|
||||
return `width: ${this.get("width")}px; height: ${this.get(
|
||||
"height"
|
||||
)}px;`.htmlSafe();
|
||||
}.property("width", "height"),
|
||||
@computed("width", "height")
|
||||
adWrapperStyle(w, h) {
|
||||
return `width: ${w}px; height: ${h}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
adTitleStyleMobile: function() {
|
||||
return `width: ${this.get("width")}px;`.htmlSafe();
|
||||
}.property("width"),
|
||||
@computed("width")
|
||||
adTitleStyleMobile(w) {
|
||||
return `width: ${w}px;`.htmlSafe();
|
||||
},
|
||||
|
||||
showAd: function() {
|
||||
@computed("showToTrustLevel", "showToGroups")
|
||||
showAd(showToTrustLevel, showToGroups) {
|
||||
return (
|
||||
Discourse.SiteSettings.dfp_publisher_id && this.get("checkTrustLevels")
|
||||
Discourse.SiteSettings.dfp_publisher_id &&
|
||||
showToTrustLevel &&
|
||||
showToGroups
|
||||
);
|
||||
}.property("checkTrustLevels"),
|
||||
},
|
||||
|
||||
checkTrustLevels: function() {
|
||||
@computed()
|
||||
showToTrustLevel() {
|
||||
return !(
|
||||
currentUser &&
|
||||
currentUser.get("trust_level") >
|
||||
Discourse.SiteSettings.dfp_through_trust_level
|
||||
);
|
||||
}.property("trust_level"),
|
||||
},
|
||||
|
||||
refreshAd: function() {
|
||||
@observes("refreshOnChange")
|
||||
refreshAd() {
|
||||
var slot = ads[this.get("divId")];
|
||||
if (!(slot && slot.ad)) {
|
||||
return;
|
||||
@@ -260,9 +271,10 @@ export default Ember.Component.extend({
|
||||
window.googletag.pubads().refresh([ad]);
|
||||
});
|
||||
}
|
||||
}.observes("refreshOnChange"),
|
||||
},
|
||||
|
||||
_initGoogleDFP: function() {
|
||||
@on("didInsertElement")
|
||||
_initGoogleDFP() {
|
||||
if (!this.get("showAd")) {
|
||||
return;
|
||||
}
|
||||
@@ -287,7 +299,7 @@ export default Ember.Component.extend({
|
||||
}
|
||||
});
|
||||
});
|
||||
}.on("didInsertElement"),
|
||||
},
|
||||
|
||||
willRender() {
|
||||
this._super(...arguments);
|
||||
@@ -300,7 +312,8 @@ export default Ember.Component.extend({
|
||||
this.set("height", size.height);
|
||||
},
|
||||
|
||||
cleanup: function() {
|
||||
@on("willDestroyElement")
|
||||
cleanup() {
|
||||
destroySlot(this.get("divId"));
|
||||
}.on("willDestroyElement")
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{{#if checkTrustLevels}}
|
||||
{{#if showAd}}
|
||||
{{#if site.mobileView}}
|
||||
<div class="amazon-product-links-label" style={{adTitleStyleMobile}}><h2>{{i18n 'adplugin.advertisement_label'}}</h2></div>
|
||||
<iframe style={{adWrapperStyleMobile}} marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src={{userInputMobile}}>
|
||||
|
||||
Reference in New Issue
Block a user