-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
68 lines (58 loc) · 2.17 KB
/
plugin.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
68
<?php
/*
Plugin Name: Bol.com Affiliate
Plugin URI: https://github.com/bureaupartners/yourls-bolcom-affiliate-plugin
Description: Add bol.com affiliate links
Version: 1.0
Author: Mark Hameetman <[email protected]>
Author URI: https://bureau.partners
*/
yourls_add_action('pre_redirect', 'bureaupartners_bol_affiliate');
function bureaupartners_bol_affiliate($args)
{
$url = $args[0];
if (preg_match('/^http(s)?:\\/\\/(www\\.)?bol.com+/ui', $url) == true) {
$partner_id = yourls_get_option('bureaupartners_bol_affiliate_id');
if (strlen($partner_id) === 0) {
$partner_id = 1015523;
}
$url = 'https://partner.bol.com/click/click?p=2&t=url&s=' . $partner_id . '&f=TXL&url=' . urlencode($url) . '&name=bureau.partners';
header("HTTP/1.1 301 Moved Permanently");
header("Location: $url");
die();
}
}
// Register our plugin admin page
yourls_add_action('plugins_loaded', 'bureaupartners_bol_affiliate_admin');
function bureaupartners_bol_affiliate_admin()
{
yourls_register_plugin_page('bureaupartners_bol_affiliate', 'Bol.com affiliate', 'bureaupartners_bol_affiliate_admin_page');
}
// Display admin page
function bureaupartners_bol_affiliate_admin_page()
{
// Check if a form was submitted
if (isset($_POST['partner_id'])) {
yourls_verify_nonce('bureaupartners_bol_affiliate');
bureaupartners_bol_affiliate_admin_save();
}
// Get value from database
$partner_id = yourls_get_option('bureaupartners_bol_affiliate_id');
// Create nonce
$nonce = yourls_create_nonce('bureaupartners_bol_affiliate');
echo <<<HTML
<h2>Bol.com affiliate</h2>
<p>This plugin makes affiliate links of all bol.com links</p>
<form method="post">
<input type="hidden" name="nonce" value="$nonce" />
<p><label for="test_option">Enter your Partner ID</label> <input type="text" id="partner_id" name="partner_id" value="$partner_id" /></p>
<p><input type="submit" value="Update value" /></p>
</form>
HTML;
}
function bureaupartners_bol_affiliate_admin_save()
{
if ($_POST['partner_id']) {
yourls_update_option('bureaupartners_bol_affiliate_id', intval($_POST['partner_id']));
}
}