将所有网站链接自动更改为联盟链接 [英] Change all website links to affiliate links automatically

查看:225
本文介绍了将所有网站链接自动更改为联盟链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想能够在我的 MediaWiki 安装中自动将链接更改为联盟链接。这将有助于减少管理链接的时间量,以防将来需要更改代码。

I would like to be able to automatically change links into affiliate links automatically on my MediaWiki installation. This would help to reduce the amount of time managing links in case the code needs to be changed in the future.

这是我的GOG.com联属计划的设置:我需要将此密钥附加到每个GOG.com链接的末尾:?pp = 708a77db476d737e54b8bf4663fc79b346d696d2

This is the setup of my GOG.com affiliate scheme: I need to append this key to the end of every GOG.com link: ?pp=708a77db476d737e54b8bf4663fc79b346d696d2

gog.com/en/gamecard/baldurs_gate_the_original_saga/?pp=708a77db476d737e54b8bf4663fc79b346d696d2

可以使用一段代码(如Javascript)拦截所有链接(例如 http://www.gog.com/en/gamecard/baldurs_gate_the_original_saga/ )并附加最后的会员代码,如上例所示?

Is it possible for a piece of code, like Javascript, to intercept all links (like http://www.gog.com/en/gamecard/baldurs_gate_the_original_saga/) and append the affiliate code on the end, as in the above example?

我知道这段名为,这是一个类似的事情。但是,它只适用于亚马逊的链接,它还可以定位链接,这是我不想要的功能。

I'm aware of this piece of Javascript code called Amazon Associate Link Localiser which does a similar thing. However, it only works for Amazon links, and it also localises links which is a feature I don't want.

推荐答案

方式是使用 LinkerMakeExternalLink 这样的mediawiki钩子(你可以把它放在您的LocalSettings.php:

Right way is to use LinkerMakeExternalLink mediawiki hook like that ( you can put it at bottom of your LocalSettings.php:

$wgHooks['LinkerMakeExternalLink'][] = 'ExampleExtension::exampleLinkerMakeExternalLink';

class ExampleExtension {
    public static function exampleLinkerMakeExternalLink( &$url, &$text, &$link, &$attribs, $linktype ) {
        if( strpos( $url, 'gog.com') !== false ) {
            $url .= '?pp=708a77db476d737e54b8bf4663fc79b346d696d2';
        }
        return false;
    }
}

这篇关于将所有网站链接自动更改为联盟链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆