feat: add affiliate links

This commit is contained in:
grandeljay 2023-09-07 10:33:41 +02:00
parent 15bf22ba80
commit a4f70b3e05
6 changed files with 38 additions and 11 deletions

View file

@ -142,10 +142,10 @@ switch ($_SERVER['REQUEST_METHOD']) {
}
/** Update */
$wish_title = empty($wish_title) ? null : substr($wish_title, 0, 128);
$wish_title = empty($wish_title) ? null : substr($wish_title, 0, 128) ;
$wish_description = empty($wish_description) ? null : $wish_description ;
$wish_image = empty($wish_image) || Wish::NO_IMAGE === $wish_image ? null : $wish_image ;
$wish_url = empty($wish_url) ? null : $wish_url ;
$wish_url = empty($wish_url) ? null : Wish::getAffiliateLink($wish_url);
$wish_priority = empty($wish_priority) ? null : $wish_priority ;
$database
@ -229,10 +229,10 @@ switch ($_SERVER['REQUEST_METHOD']) {
}
/** Update */
$wish_title = empty($wish_title) ? null : substr($wish_title, 0, 128);
$wish_title = empty($wish_title) ? null : substr($wish_title, 0, 128) ;
$wish_description = empty($wish_description) ? null : $wish_description ;
$wish_image = empty($wish_image) || Wish::NO_IMAGE === $wish_image ? null : $wish_image ;
$wish_url = empty($wish_url) ? null : $wish_url ;
$wish_url = empty($wish_url) ? null : Wish::getAffiliateLink($wish_url);
$database
->query(

View file

@ -39,6 +39,7 @@
--gap: 0.5rem;
gap: var(--gap);
margin-bottom: 1em;
}
.flex.why-wishthis > ul {
flex: 0 0 calc(50% - var(--gap) / 2);

View file

@ -68,6 +68,25 @@ class Wish
return $wish;
}
public static function getAffiliateLink(string $url): string
{
$urlParts = parse_url($url);
if (isset($urlParts['query'])) {
\parse_str($urlParts['query'], $urlParameters);
} else {
$urlParameters = array();
}
if (\str_contains($urlParts['host'], 'amazon')) {
$urlParameters['tag'] = 'grandel-21';
$urlParts['query'] = \http_build_query($urlParameters);
$url = $urlParts['scheme'] . '://' . $urlParts['host'] . $urlParts['path'] . '?' . $urlParts['query'];
}
return $url;
}
/**
* Non-Static
*/

View file

@ -124,6 +124,12 @@ $page->navigation();
echo __('After creating an account your language is automatically set to your browser\'s (if it is available), instead of defaulting to en_GB.');
?>
</li>
<li>
<?php
/** TRANSLATORS: Changelog: Added */
echo __('Amazon links are now automatically converted to affiliate links to help support wishthis financially.');
?>
</li>
</ul>
<h3 class="ui header"><?= __('Fixed') ?></h3>

View file

@ -105,7 +105,7 @@ $user = User::getCurrent();
'</a>'
) ?></p>
<p><?= __('As a non-commercial project it remains') ?></p>
<p><?= __('As an open source project it remains') ?></p>
<div class="flex why-wishthis">
<ul class="ui list">
<li class="item" data-content="<?= __('unless you want them') ?>">
@ -137,6 +137,7 @@ $user = User::getCurrent();
</li>
</ul>
</div>
<p><?= __('Plese note that wishthis automatically converts amazon links to affiliate links to help support the project financially.') ?></p>
</div>
<div class="ui segment">

View file

@ -301,7 +301,7 @@ $page->navigation();
<h2 class="ui header"><?= __('About your email address') ?></h2>
<p><?= __('Currently the email address is used as a unique identifier and does not have to be verified. You may enter a fake address.') ?></p>
<p><?= __('wishthis is not a commercial project and is not interested in sending you marketing emails or selling your information to third parties. Although possible to do otherwise, it is strongly recommend to enter your real email address in case you need to recover your password or receive important notifications. These do not exist yet, but some future features and options might require sending you an email (e. g. when a wish has been fulfilled).') ?></p>
<p><?= __('wishthis is not interested in sending you marketing emails or selling your information to third parties. Although possible to do otherwise, it is strongly recommend to enter your real email address in case you need to recover your password or receive important notifications. These do not exist yet, but some future features and options might require sending you an email (e. g. when a wish has been fulfilled).') ?></p>
<p>
<?=
sprintf(