2022-03-06 13:52:19 -05:00
|
|
|
import { and } from "@ember/object/computed";
|
2022-06-01 12:37:01 -04:00
|
|
|
import { htmlSafe } from "@ember/template";
|
2024-11-29 05:11:21 -05:00
|
|
|
import { classNames } from "@ember-decorators/component";
|
2023-11-07 12:07:33 -05:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
|
|
import AdComponent from "discourse/plugins/discourse-adplugin/discourse/components/ad-component";
|
2015-09-10 08:48:14 -04:00
|
|
|
|
2024-11-29 05:11:21 -05:00
|
|
|
@classNames("amazon-product-links")
|
|
|
|
export default class AmazonProductLinks extends AdComponent {
|
|
|
|
@and("showAmazonAds", "showToGroups", "showAfterPost", "showOnCurrentPage")
|
|
|
|
showAd;
|
2019-04-18 14:10:56 -04:00
|
|
|
|
|
|
|
init() {
|
2021-09-21 14:27:10 -04:00
|
|
|
const data = {
|
|
|
|
"topic-list-top": {},
|
|
|
|
"topic-above-post-stream": {},
|
|
|
|
"topic-above-suggested": {},
|
|
|
|
"post-bottom": {},
|
|
|
|
};
|
|
|
|
const mobileView = this.site.get("mobileView");
|
|
|
|
const placement = this.get("placement");
|
|
|
|
|
|
|
|
if (!mobileView && this.siteSettings.amazon_topic_list_top_src_code) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["topic-list-top"]["user_input"] =
|
|
|
|
this.siteSettings.amazon_topic_list_top_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["topic-list-top"]["amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_topic_list_top_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["topic-list-top"]["amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_topic_list_top_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mobileView && this.siteSettings.amazon_mobile_topic_list_top_src_code) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["topic-list-top"]["user_input_mobile"] =
|
|
|
|
this.siteSettings.amazon_mobile_topic_list_top_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["topic-list-top"]["mobile_amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_topic_list_top_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["topic-list-top"]["mobile_amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_topic_list_top_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!mobileView &&
|
|
|
|
this.siteSettings.amazon_topic_above_post_stream_src_code
|
|
|
|
) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["topic-above-post-stream"]["user_input"] =
|
|
|
|
this.siteSettings.amazon_topic_above_post_stream_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["topic-above-post-stream"]["amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_topic_above_post_stream_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["topic-above-post-stream"]["amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_topic_above_post_stream_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
mobileView &&
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_post_stream_src_code
|
|
|
|
) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["topic-above-post-stream"]["user_input_mobile"] =
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_post_stream_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["topic-above-post-stream"]["mobile_amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_post_stream_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["topic-above-post-stream"]["mobile_amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_post_stream_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
!mobileView &&
|
|
|
|
this.siteSettings.amazon_topic_above_suggested_src_code
|
|
|
|
) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["topic-above-suggested"]["user_input"] =
|
|
|
|
this.siteSettings.amazon_topic_above_suggested_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["topic-above-suggested"]["amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_topic_above_suggested_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["topic-above-suggested"]["amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_topic_above_suggested_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
mobileView &&
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_suggested_src_code
|
|
|
|
) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["topic-above-suggested"]["user_input_mobile"] =
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_suggested_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["topic-above-suggested"]["mobile_amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_suggested_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["topic-above-suggested"]["mobile_amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_topic_above_suggested_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mobileView && this.siteSettings.amazon_post_bottom_src_code) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["post-bottom"]["user_input"] =
|
|
|
|
this.siteSettings.amazon_post_bottom_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["post-bottom"]["amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_post_bottom_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["post-bottom"]["amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_post_bottom_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mobileView && this.siteSettings.amazon_mobile_post_bottom_src_code) {
|
2023-01-04 07:34:08 -05:00
|
|
|
data["post-bottom"]["user_input_mobile"] =
|
|
|
|
this.siteSettings.amazon_mobile_post_bottom_src_code;
|
2021-09-21 14:27:10 -04:00
|
|
|
data["post-bottom"]["mobile_amazon_width"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_post_bottom_ad_width_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
data["post-bottom"]["mobile_amazon_height"] = parseInt(
|
|
|
|
this.siteSettings.amazon_mobile_post_bottom_ad_height_code,
|
|
|
|
10
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-22 14:49:32 -04:00
|
|
|
this.set("user_input", data[placement]["user_input"]);
|
|
|
|
this.set("amazon_width", data[placement]["amazon_width"]);
|
|
|
|
this.set("amazon_height", data[placement]["amazon_height"]);
|
|
|
|
this.set("user_input_mobile", data[placement]["user_input_mobile"]);
|
|
|
|
this.set("mobile_amazon_height", data[placement]["mobile_amazon_height"]);
|
|
|
|
this.set("mobile_amazon_width", data[placement]["mobile_amazon_width"]);
|
2024-11-29 05:11:21 -05:00
|
|
|
super.init();
|
|
|
|
}
|
2015-09-15 21:44:31 -04:00
|
|
|
|
2020-03-23 04:40:29 -04:00
|
|
|
@discourseComputed("amazon_width", "amazon_height")
|
2019-04-18 14:10:56 -04:00
|
|
|
adWrapperStyle(w, h) {
|
2022-06-01 12:37:01 -04:00
|
|
|
return htmlSafe(`width: ${w}px; height: ${h}px;`);
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
2015-09-10 08:48:14 -04:00
|
|
|
|
2020-03-23 04:40:29 -04:00
|
|
|
@discourseComputed("mobile_amazon_width", "mobile_amazon_height")
|
2019-04-18 14:10:56 -04:00
|
|
|
adWrapperStyleMobile(w, h) {
|
2022-06-01 12:37:01 -04:00
|
|
|
return htmlSafe(`width: ${w}px; height: ${h}px;`);
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
2015-09-10 08:48:14 -04:00
|
|
|
|
2020-03-23 04:40:29 -04:00
|
|
|
@discourseComputed("mobile_amazon_width")
|
2019-04-18 14:10:56 -04:00
|
|
|
adTitleStyleMobile(w) {
|
2022-06-01 12:37:01 -04:00
|
|
|
return htmlSafe(`width: ${w}px;`);
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
2015-10-28 19:51:53 -04:00
|
|
|
|
2020-03-23 04:40:29 -04:00
|
|
|
@discourseComputed("user_input")
|
2019-04-18 14:10:56 -04:00
|
|
|
userInput(userInput) {
|
2022-06-01 12:37:01 -04:00
|
|
|
return htmlSafe(`${userInput}`);
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
2015-09-10 08:48:14 -04:00
|
|
|
|
2020-03-23 04:40:29 -04:00
|
|
|
@discourseComputed("user_input_mobile")
|
2019-04-18 14:10:56 -04:00
|
|
|
userInputMobile(userInput) {
|
2022-06-01 12:37:01 -04:00
|
|
|
return htmlSafe(`${userInput}`);
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
2015-09-15 21:44:31 -04:00
|
|
|
|
2024-01-31 13:04:24 -05:00
|
|
|
@discourseComputed
|
2024-02-08 21:42:40 -05:00
|
|
|
showAmazonAds() {
|
2024-01-31 13:04:24 -05:00
|
|
|
if (!this.currentUser) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.currentUser.show_amazon_ads;
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
2019-04-18 17:52:59 -04:00
|
|
|
|
2020-03-23 04:40:29 -04:00
|
|
|
@discourseComputed("postNumber")
|
2019-04-18 17:52:59 -04:00
|
|
|
showAfterPost(postNumber) {
|
|
|
|
if (!postNumber) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-18 10:07:55 -05:00
|
|
|
return this.isNthPost(parseInt(this.siteSettings.amazon_nth_post_code, 10));
|
2024-11-29 05:11:21 -05:00
|
|
|
}
|
|
|
|
}
|