|
1 | 1 | <?php
|
2 | 2 | class Yourls extends Plugin {
|
3 | 3 | private $host;
|
4 |
| - private $curl_yourls; |
5 | 4 |
|
6 | 5 | function init($host) {
|
7 | 6 | $this->host = $host;
|
8 |
| - $this->curl_yourls = $curl_yourls; |
9 |
| - $this->curl_yourls = curl_init() ; |
10 |
| - curl_setopt($this->curl_yourls, CURLOPT_RETURNTRANSFER, true); |
11 |
| - curl_setopt($this->curl_yourls, CURLOPT_FOLLOWLOCATION, true); |
12 | 7 | $host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
|
13 | 8 | $host->add_hook($host::HOOK_PREFS_TAB, $this);
|
14 | 9 | $host->add_hook($host::HOOK_HOTKEY_MAP, $this);
|
15 | 10 | $host->add_hook($host::HOOK_HOTKEY_INFO, $this);
|
16 | 11 | }
|
17 | 12 |
|
18 | 13 | function about() {
|
19 |
| - return array("1.1.1", |
20 |
| - "Shorten article Link using Yourls", |
21 |
| - "Beun and acaranta"); |
| 14 | + return array( |
| 15 | + "2.0.0", |
| 16 | + "Shorten article Link using Yourls", |
| 17 | + "Beun and acaranta, and [email protected]"); |
22 | 18 | }
|
23 | 19 |
|
24 | 20 | function hook_hotkey_map($hotkeys) {
|
25 |
| - $hotkeys['s y'] = 'send_to_yourls'; |
| 21 | + $hotkeys['s y'] = 'send_to_yourls'; |
26 | 22 |
|
27 | 23 | return $hotkeys;
|
28 | 24 | }
|
@@ -68,24 +64,40 @@ function getInfo() {
|
68 | 64 | WHERE id = ? AND ref_id = id AND owner_uid = ?");
|
69 | 65 | $sth->execute([$id, $_SESSION['uid']]);
|
70 | 66 | if ($row = $sth->fetch()) {
|
| 67 | + |
71 | 68 | $title = truncate_string(strip_tags($row['title']), 100, '...');
|
72 | 69 | $article_link = $row['link'];
|
| 70 | + $yourls_url = $this->host->get($this, "Yourls_URL"); |
| 71 | + $yourls_url = $yourls_url . "/yourls-api.php"; |
| 72 | + $yourls_api = $this->host->get($this, "Yourls_API"); |
| 73 | + $postfields = array( |
| 74 | + 'signature' => $yourls_api, |
| 75 | + 'action' => 'shorturl', |
| 76 | + 'format' => 'simple', |
| 77 | + 'url' => $article_link, |
| 78 | + 'title' => $title, |
| 79 | + ); |
| 80 | + |
| 81 | + $curl_yourls = curl_init(); |
| 82 | + |
| 83 | + curl_setopt($curl_yourls, CURLOPT_URL, $yourls_url); |
| 84 | + curl_setopt($curl_yourls, CURLOPT_HEADER, 0); |
| 85 | + curl_setopt($curl_yourls, CURLOPT_RETURNTRANSFER, true); |
| 86 | + curl_setopt($curl_yourls, CURLOPT_TIMEOUT, 30); |
| 87 | + curl_setopt($curl_yourls, CURLOPT_POST, 1); |
| 88 | + curl_setopt($curl_yourls, CURLOPT_POSTFIELDS,$postfields); |
| 89 | + |
| 90 | + if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
| 91 | + curl_setopt($curl_yourls, CURLOPT_FOLLOWLOCATION, true); |
| 92 | + } |
| 93 | + $short_url = curl_exec($curl_yourls) ; |
| 94 | + $status = curl_getinfo($curl_yourls, CURLINFO_HTTP_CODE); |
| 95 | + curl_close($curl_yourls); |
| 96 | + |
| 97 | + print json_encode(array("status" => $status, "title" => $title, "shorturl" => $short_url)); |
| 98 | + } else { |
| 99 | + print json_encode(array( "status" => "Database fail" )); |
73 | 100 | }
|
74 |
| - |
75 |
| - $yourls_url = $this->host->get($this, "Yourls_URL"); |
76 |
| - $yourls_api = $this->host->get($this, "Yourls_API"); |
77 |
| - |
78 |
| - curl_setopt($this->curl_yourls, CURLOPT_URL, "$yourls_url/yourls-api.php?signature=$yourls_api&action=shorturl&format=simple&url=".urlencode($article_link)."&title=".urlencode($title)) ; |
79 |
| - curl_setopt($this->curl_yourls, CURLOPT_RETURNTRANSFER, true); |
80 |
| - if (!ini_get('safe_mode') && !ini_get('open_basedir')) { |
81 |
| - curl_setopt($this->curl_yourls, CURLOPT_FOLLOWLOCATION, true); |
82 |
| - } |
83 |
| - $short_url = curl_exec($this->curl_yourls) ; |
84 |
| - |
85 |
| - curl_setopt($this->curl_yourls, CURLOPT_URL, "$yourls_url/yourls-api.php?signature=$yourls_api&action=shorturl&format=simple&url=".urlencode($article_link)."&title=".urlencode($title)) ; |
86 |
| - $short_url = curl_exec($this->curl_yourls) ; |
87 |
| - |
88 |
| - print json_encode(array("title" => $title, "link" => $article_link, "id" => $id, "yourlsurl" => $yourls_url, "yourlsapi" => $yourls_api, "shorturl" => $short_url)); |
89 | 101 | }
|
90 | 102 |
|
91 | 103 | function hook_prefs_tab($args) {
|
|
0 commit comments