Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Linkvertise #10

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
28c6496
8Mi_Yile's change
8MiYile Apr 21, 2023
22ffef3
add git ignore list
8MiYile Apr 21, 2023
66421cd
revert plugin.php's author info
8MiYile Apr 21, 2023
350e607
Support for Linkvertise is tested locally
8MiYile Apr 21, 2023
b0cdf02
Update Acknowledgement
8MiYile Apr 22, 2023
f60330c
Update the steps about the website
8MiYile Apr 22, 2023
50499ac
Really hate tabs instead of spaces!
8MiYile Apr 22, 2023
9b0abd5
remove user-config.php and fix some bug
8MiYile May 5, 2023
6af6226
add-settings-page yes
8MiYile May 5, 2023
bdffeae
remove user-config.php from git ignore list
8MiYile May 5, 2023
f971c60
remove user-config.php from git ignore list
8MiYile May 5, 2023
44deedb
more than better
8MiYile May 6, 2023
5c05fac
Merge branch 'master' into add-setting-page
8MiYile Nov 27, 2023
2248df1
Merge pull request #4 from 8Mi-Tech/add-setting-page
8MiYile Nov 27, 2023
9992703
README move to Github Wiki
8MiYile Nov 27, 2023
3c8af5b
add: random adurl string=`r/`
8MiYile Nov 27, 2023
866607f
add: settings.php example
8MiYile Nov 27, 2023
4949d7b
add: Support i18n
8MiYile Nov 27, 2023
aa327eb
add: Langage zh_CN
8MiYile Nov 27, 2023
9d93dc4
add: langage tag `Enable`
8MiYile Nov 27, 2023
206fbb2
add: Better WebUI and Save button
8MiYile Nov 28, 2023
ea5d4df
fix:plugin version
8MiYile Nov 29, 2023
3d9d38e
fix: plugin version
8MiYile Nov 29, 2023
daf1cb1
add: auto-mo.sh
8MiYile Nov 29, 2023
702dca9
add: Language zh_TW
8MiYile Nov 29, 2023
b847cb5
add: Language zh_HK
8MiYile Nov 29, 2023
538f2b7
fix: better randm
8MiYile Nov 30, 2023
d8f6258
fix: better random (again)
8MiYile Nov 30, 2023
3140875
fix: The procedure is not a step-by-step approach
8MiYile Dec 1, 2023
3825069
fix: Tutorial URL
8MiYile Dec 1, 2023
755c155
fix: nothing fix, it's just look
8MiYile Dec 2, 2023
e4f859b
Bump 1.4
8MiYile Dec 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
user-config.php
43 changes: 3 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
# Conditional URL Advertisements

Plugin for [YOURLS](http://yourls.org).

## Description
This plugin allows you to redirect all shortlinks through a link monetizer.

Currently, the following shorteners are supported:
* [AdFly](https://adf.ly/?id=2777408), trigger: `a/`
* [AdFoc.us](https://adfoc.us/?refid=287608), trigger `f/`
* [ouo.io](https://ouo.io/ref/0IqYvHOo), trigger `o/`

Going to a shorturl with a trigger before it will automatically forward the url through the selected service (ex *sho.rt/a/test*). If it recognizes a trigger but there is no associated service it will not monetize the link.

If you have another sevice you want supported, make a ticket for it!

## Installation
1. Clone this repo to the `/user/plugins` plugins directory
2. Edit the plugin's settings (inside *plugin.php*) to suit your needs
3. Go to the Plugins administration page and activate the plugin
4. Test your shortlinks with each activated service
5. If everything works, celebrate!

## Getting your IDs
To properly setup this plugin, you need to manually change the IDs from the defaults to your's. These instructions should show you how to do this for each service:

### AdFly
1. Ensure you have a valid account and are logged in
2. Navigate to [this url](https://adf.ly/publisher/tools#tools-api)
3. Your ID is the number after 'Your User ID:' *not API key*

### AdFocus
1. Ensure you have a valid account and are logged in
2. Navigate to [this url](http://adfoc.us/tools/site-links)
3. Your ID is the number after '?id='

### ouo.io
1. Ensure you have a valid account and are logged in
2. Navigate to [this url](https://ouo.io/manage/tools/full-page-script)
3. Your ID is the bit inside the quotes for `ouo_token`
# Conditional URLAds [![Listed in Awesome YOURLS!](https://img.shields.io/badge/Awesome-YOURLS-C5A3BE)](https://github.com/YOURLS/awesome-yourls/)

- Requires [YOURLS](https://yourls.org) `1.91` and above.
- Select language [:cn:](./README/zh_CN.md) / [:us:](./README/en_US.md) to view README.md
71 changes: 71 additions & 0 deletions README/en_US.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Conditional URLAds [![Listed in Awesome YOURLS!](https://img.shields.io/badge/Awesome-YOURLS-C5A3BE)](https://github.com/YOURLS/awesome-yourls/)
- Requires [YOURLS](https://yourls.org) `1.91` and above.
- Select language: [:cn:](./zh_CN.md) / [:us:](./en_US.md)
- This Page's Language is::us: [English(US)](./en_US.md)

---
## Description
This plugin allows you to redirect all shortlinks through a link monetizer.

Currently, the following shorteners are supported:
- [AdFly](https://adf.ly/?id=2777408), trigger: `a/`
- [AdFoc.us](https://adfoc.us/?refid=287608), trigger `f/`
- [ouo.io](https://ouo.io/ref/0IqYvHOo), trigger `o/`

Going to a shorturl with a trigger before it will automatically forward the url through the selected service (ex *sho.rt/a/test*). If it recognizes a trigger but there is no associated service it will not monetize the link.

If you have another sevice you want supported, make a ticket for it!

---
## Installation
1. Clone this repo to the `/user/plugins` plugins directory
2. Copy `user-config.php.example` and rename it to `user-config.php`
3. Edit the plugin's user config (inside `user-config.php`) to suit your needs
4. Go to the Plugins administration page and activate the plugin
5. Test your shortlinks with each activated service
6. If everything works, celebrate!

---
## Getting your IDs
To properly setup this plugin, you need to manually change the IDs from the defaults to your's. These instructions should show you how to do this for each service:

### AdFly
~To Be Deprecated~
1. Ensure you have a valid account and are logged in
2. Navigate to [this url](https://adf.ly/publisher/tools#tools-api)
3. Your ID is the number after 'Your User ID:' *not API key*
4. copy the ID into the `ADFLY_ID` option of `user-config.php` (replacing `input_your_id_here`)

### AdFocus
1. Ensure you have a valid account and are logged in
2. Navigate to [this url](http://adfoc.us/tools/site-links)
3. Your ID is the number after '?id='
4. copy the ID into the `ADFOCUS_ID` option of `user-config.php` (replacing `input_your_id_here`)

### ouo.io
1. Ensure you have a valid account and are logged in
2. Navigate to [this url](https://ouo.io/manage/tools/full-page-script)
3. Your ID is the bit inside the quotes for `ouo_token`
4. copy the ID into the `OUO_ID` option of `user-config.php` (replacing `input_your_id_here`)

### Linkvertise
1. Ensure you have a valid account and are [logged in](https://publisher.linkvertise.com/)
2. On the left side of the site click on `Full Script API`, and select on the right`Activate Full Script API`
3. Click the button on the left again `Full Script API`, You should see the following text, and the required text is the string I marked with an asterisk
4. copy the ID into the `LINKVERTISE_ID` option of `user-config.php` (replacing `input_your_id_here`)
```html
<script src="https://publisher.linkvertise.com/cdn/linkvertise.js"></script><script>linkvertise(******, {whitelist: [], blacklist: [""]});</script>
```

---
## To Do List
Status Tags: :x: 未解决 :o: 解决 :question: 未知状态
| Status | Question | Solved? |
|-|-|-|
| :o: | Detects and is compatible with the [Ban User-Agent](https://github.com/8Mi-Tech/yourls-ban-useragent) plugin | No need to detect, he was executed before me
| :x: | Config `user-config.php` move to `/admin/plugins.php?page=conditional-urlads` |
---
## Acknowledgements
- Original : [@HeroCC](https://github.com/HeroCC)
- Patch Updater : [@JackBailey](https://github.com/JackBailey)
- Linkverse Support: [@8Mi_Yile](https://github.com/8MiYile) (Powered By [FutureStunt/linkvertise](https://github.com/FutureStunt/linkvertise))
80 changes: 80 additions & 0 deletions README/zh_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Conditional URLAds [![Listed in Awesome YOURLS!](https://img.shields.io/badge/Awesome-YOURLS-C5A3BE)](https://github.com/YOURLS/awesome-yourls/)
- 需要安装 [YOURLS](https://yourls.org) 大于或等于`1.91`版本
- 选择语言切换页面: [:cn:](./zh_CN.md) / [:us:](./en_US.md)
- 当前页面语言为: :cn: [中文(简体)](./zh_CN.md)
---
## 插件描述
为你的短域名套一层其他带广告的短链接系统

支持如下的广告平台(以下是注册链接):
- [AdFly](https://8mi.ink/a/ref-adfly), 触发标识: `a/`
- [AdFoc.us](https://8mi.ink/f/ref-adfoc), 触发标识 `f/`
- [ouo.io](https://8mi.ink/o/ref-ouoio), 触发标识 `o/`
- [Linkvertise](https://8mi.ink/l/ref-linkvertise), 触发标识 `l/`

到一个有触发器的短地址服务之前,会自动通过选定的服务转发该url(例如*sho.rt/a/test*)。如果它识别了一个触发器,但没有相关的服务,它将不会使链接广告化。

如果你有其他想要支持的服务,请为其发起issue

---
## 如何安装
1. 克隆到 `/user/plugins` 这个插件文件夹下
2. 在原地复制 `user-config.php.example` 并更名为 `user-config.php`
3. 编辑插件配置 (`user-config.php`)
4. 在管理员操作中心的插件管理启用该插件
5. 测试短连接地址转换是否成功( sho.rt/a/test -> adfly -> sho.rt/test)
6. 有问题记得反馈即可

### Linux用户可以看看这边 (假设你已经cd到自己的yourls站点文件夹)
```bash
cd user/plugins
git clone https://github.com/HeroCC/yourls-conditional-urlads
cd yourls-conditional-urlads
cp user-config.php.example user-config.php
vim user-config.php
```
---
## 获取ID
以下方法 不同平台获取ID的方式

### AdFly
~即将被废弃~
1. 先[进去](https://login.adf.ly/login)登录,完事后回来继续看教程
2. [点我访问](https://adf.ly/publisher/tools#tools-api)以获得UserID
3. 你的ID显示在`Your User ID:`或者是`你的用户ID:` *不是API key阿喂!!!*
4. 并将ID复制进`user-config.php`的`ADFLY_ID`选项 (替换掉`input_your_id_here`)

### AdFocus
1. 先[进去](http://adfoc.us/)登录,完事后回来继续看教程
2. [点我访问](http://adfoc.us/tools/site-links)以获得ID
3. 你的ID在网页里面显示的模板链接 在`?id=`右边
4. 并将ID复制进`user-config.php`的`ADFOCUS_ID`选项 (替换掉`input_your_id_here`)

### ouo.io
1. 先[进去](https://ouo.io/auth/signin)登录,完事后回来继续看教程(提示capecha的 关掉Adblock这类插件)
2. [点我访问](https://ouo.io/manage/tools/full-page-script)以获得token
3. 你的ID应该在`ouo_token`这个选项
4. 并将ID复制进`user-config.php`的`OUO_ID`选项 (替换掉`input_your_id_here`)

### Linkvertise
1. 先[登录](https://publisher.linkvertise.com/)
2. 在网站左侧点击`Full Script API`, 并在右侧选择`Activate Full Script API`
3. 再点击左侧的按钮`Full Script API`, 你应该会看到如下文本,并所需的文本是我马赛克的那串文本
4. 并将ID复制进`user-config.php`的`LINKVERTISE_ID`选项 (替换掉`input_your_id_here`)
```html
<script src="https://publisher.linkvertise.com/cdn/linkvertise.js"></script><script>linkvertise(******, {whitelist: [], blacklist: [""]});</script>
```

---
## 目标清单
状态标志 :x: 未解决 :o: 解决 :question: 未知状态
| 状态 | 问题 | 解决方案 |
|-|-|-|
| :o: | 检测并兼容 [Ban User-Agent](https://github.com/8Mi-Tech/yourls-ban-useragent) 插件 | 不用检测了,他直接抢在我前面执行,草了
| :x: | 配置文件从 `user-config.php` 迁移到 `/admin/plugins.php?page=conditional-urlads` |

---
## 致谢
- 原作者:[@HeroCC](https://github.com/HeroCC)
- 后续更新 : [@JackBailey](https://github.com/JackBailey)
- Linkverse支持: [@8Mi_Yile](https://github.com/8MiYile) (创意来源于[FutureStunt/linkvertise](https://github.com/FutureStunt/linkvertise))
54 changes: 34 additions & 20 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,16 @@
Plugin Name: Conditional URL Advertisements
Plugin URI: https://github.com/HeroCC/yourls-conditional-urlads
Description: Conditionally send shortlinks through various link monetizing services
Version: 1.1
Version: 1.2.1
Author: HeroCC
Author URI: https://herocc.com/
*/

if( !defined( 'YOURLS_ABSPATH' ) ) die();

define( 'TRIGGERS', array('a/', 'f/', 'o/') ); // Add any possible trigger to use here
define( 'TRIGGERS', array('a/', 'f/', 'o/', 'l/') ); // Add any possible trigger to use here

define( 'ADFLY_ID', '2777408' ); // Replace this with your Adfly ID
define( 'ADFOCUS_ID', '287608' ); // Replace this with your Adfoc.us ID
define( 'OUO_ID', '0IqYvHOo' ); // You get the drill

define( 'ADFLY_DOMAIN', 'https://adf.ly' ); // If you have a custom Adfly domain, replace this with it
define( 'ADFOCUS_DOMAIN', 'https://adfoc.us' ); // Same for this
define( 'OUO_DOMAIN', 'https://ouo.io' );
include 'user-config.php';

yourls_add_action( 'loader_failed', 'check_for_redirect' ); // On url fail, check here
function check_for_redirect( $args ) {
Expand All @@ -35,21 +29,41 @@ function check_for_redirect( $args ) {

function redirect_to_advert( $url, $code ) {
if ( doAdvert ) {
$redirectUrl = getRedirect();
if ( redirectService == 'f' ) { // Use adfocus
return ADFOCUS_DOMAIN . '/serve/sitelinks/?id=' . ADFOCUS_ID . '&url=' . $redirectUrl;
} else if ( redirectService == 'a' ) { // Adfly
return ADFLY_DOMAIN . '/' . ADFLY_ID . '/' . $redirectUrl;
} else if ( redirectService == 'o' ) { // OUO.io
return OUO_DOMAIN . '/qs/' . OUO_ID . '?s=' . $redirectUrl;
$redirectUrl = getRedirect();
switch ( redirectService ) {
case 'f': // Use adfocus
return ADFOCUS_DOMAIN . '/serve/sitelinks/?id=' . ADFOCUS_ID . '&url=' . $redirectUrl;
case 'a': // Adfly
return ADFLY_DOMAIN . '/' . ADFLY_ID . '/' . $redirectUrl;
case 'o': // OUO.io
return OUO_DOMAIN . '/qs/' . OUO_ID . '?s=' . $redirectUrl;
case 'l': // linkvertise.com
return getLinkvertise(LINKVERTISE_ID,$redirectUrl);
}
}
return $url; // If none of those redirect services, forward to the normal URL
}

function getRedirect(){
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // get the current url
$pieces = explode('/', $actual_link); // split the url into an arrray seperated by /
$last_word = array_pop($pieces); // get the keyword - this may not work if you use a plugin to allow slashes in your shortened url
return '//' . $_SERVER['SERVER_NAME'] . '/' . $last_word; // replace the '/' after $_SERVER['SERVER_NAME' if your yourls is not in your base domain, such as '/shorten/'
$protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") ;
$actual_link = $protocol . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; // get the current url
$pieces = explode('/', $actual_link); // split the url into an arrray seperated by /
$last_word = array_pop($pieces); // get the keyword - this may not work if you use a plugin to allow slashes in your shortened url
return $protocol . '://' . $_SERVER['SERVER_NAME'] . '/' . $last_word; // replace the '/' after $_SERVER['SERVER_NAME' if your yourls is not in your base domain, such as '/shorten/'
}
// About Linkvertise
function btoa($str) {
$buffer = null;
if ($str instanceof \Buffer) {
$buffer = $str;
} else {
$buffer = \pack("H*", \bin2hex($str));
}
return base64_encode($buffer);
}

function getLinkvertise($userid, $link) {
$base_url = "https://link-to.net/" . $userid . "/" . strval(rand()*1000) . "/dynamic";
$href = $base_url . "?r=" . btoa(utf8_encode($link));
return $href;
}
11 changes: 11 additions & 0 deletions user-config.php.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
define( 'ADFLY_ID', 'input_your_id_here' ); // Replace this with your Adfly ID
define( 'ADFOCUS_ID', 'input_your_id_here' ); // Replace this with your Adfoc.us ID
define( 'OUO_ID', 'input_your_id_here' ); // You get the drill
define( 'LINKVERTISE_ID', 'input_your_id_here' ); // You get the drill


define( 'ADFLY_DOMAIN', 'https://adf.ly' ); // If you have a custom Adfly domain, replace this with it
define( 'ADFOCUS_DOMAIN', 'https://adfoc.us' ); // Same for this
define( 'OUO_DOMAIN', 'https://ouo.io' );
?>