-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extend.php
67 lines (54 loc) · 2.67 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
* This file is part of fof/amazon-affiliation.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FoF\AmazonAffiliation;
use Flarum\Extend;
use Flarum\Settings\Event\Saving as SettingsSaving;
use Flarum\Settings\SettingsRepositoryInterface;
use s9e\TextFormatter\Configurator;
return [
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js'),
new Extend\Locales(__DIR__.'/resources/locale'),
(new Extend\Formatter())
->render(Formatter\AlterAmazonLinks::class),
(new Extend\ServiceProvider())
->register(Providers\LinkManipulatorProvider::class),
(new Extend\Event())
->listen(SettingsSaving::class, function (SettingsSaving $event) {
foreach ($event->settings as $key => $setting) {
if (strpos($key, 'fof-amazon-affiliation.affiliate-tag.') === 0) {
resolve('flarum.formatter')->flush();
return;
}
}
}),
(new Extend\Formatter())
->configure(function (Configurator $configurator): void {
/** @var SettingsRepositoryInterface */
$settings = resolve(SettingsRepositoryInterface::class);
$prefix = 'fof-amazon-affiliation.affiliate-tag.';
$params = $configurator->rendering->parameters;
$params['AMAZON_ASSOCIATE_TAG'] = $settings->get($prefix.'com', '');
$params['AMAZON_ASSOCIATE_TAG_UK'] = $settings->get($prefix.'co.uk', '');
$params['AMAZON_ASSOCIATE_TAG_DE'] = $settings->get($prefix.'de', '');
$params['AMAZON_ASSOCIATE_TAG_FR'] = $settings->get($prefix.'fr', '');
$params['AMAZON_ASSOCIATE_TAG_JP'] = $settings->get($prefix.'co.jp', '');
$params['AMAZON_ASSOCIATE_TAG_CA'] = $settings->get($prefix.'ca', '');
$params['AMAZON_ASSOCIATE_TAG_IT'] = $settings->get($prefix.'it', '');
$params['AMAZON_ASSOCIATE_TAG_ES'] = $settings->get($prefix.'es', '');
$params['AMAZON_ASSOCIATE_TAG_IN'] = $settings->get($prefix.'in', '');
// Not currently supported by MediaEmbed. Will look to PR these into s9e/textformatter soon
// $params['AMAZON_ASSOCIATE_TAG_CN'] = $settings->get($prefix.'cn', '');
// $params['AMAZON_ASSOCIATE_TAG_BR'] = $settings->get($prefix.'com.br', '');
// $params['AMAZON_ASSOCIATE_TAG_MX'] = $settings->get($prefix.'com.mx', '');
// $params['AMAZON_ASSOCIATE_TAG_AU'] = $settings->get($prefix.'com.au', '');
//extract($configurator->finalize());
}),
];