-
Notifications
You must be signed in to change notification settings - Fork 7
/
plugin.php
38 lines (32 loc) · 1.09 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
<?php
/*
Plugin Name: Bulk URL shortener
Plugin URI: https://github.com/tdakanalis/bulk_api_bulkshortener
Description: Shorten URLs in bulk (a single request with many URLs to shorten).
Version: 1.0
Author: Stelios Mavromichalis
Author URI: http://www.cytech.gr
*/
yourls_add_action('api', 'bulk_api_bulkshortener');
function bulk_api_bulkshortener($action) {
if ($action[0] != 'bulkshortener') {
return;
}
if (!isset($_REQUEST['urls'])) {
$return = array(
'errorCode' => 400,
'message' => 'bulkshortener: missing URLS parameter',
'simple' => 'bulkshortener: missing URLS parameter',
);
echo $return['errorCode'] . ": " . $return['simple'];
die();
}
$keyword = (isset($_REQUEST['keyword']) ? $_REQUEST['keyword'] : '');
$title = (isset($_REQUEST['title']) ? $_REQUEST['title'] : '');
$urls = (isset($_REQUEST['urls']) ? $_REQUEST['urls'] : array());
foreach ($urls as $url) {
$return = yourls_add_new_link($url, $keyword, $title);
echo $return['shorturl'] . "\n";
}
die();
}