Skip to content

Commit 095d6d7

Browse files
committed
multiple fixes
- update to ttrss v21.03-ddfa39015 - php8 - fix hotkey action
1 parent 1915c0f commit 095d6d7

File tree

2 files changed

+83
-46
lines changed

2 files changed

+83
-46
lines changed

yourls/init.php

+36-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
<?php
22
class Yourls extends Plugin {
33
private $host;
4-
private $curl_yourls;
54

65
function init($host) {
76
$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);
127
$host->add_hook($host::HOOK_ARTICLE_BUTTON, $this);
138
$host->add_hook($host::HOOK_PREFS_TAB, $this);
149
$host->add_hook($host::HOOK_HOTKEY_MAP, $this);
1510
$host->add_hook($host::HOOK_HOTKEY_INFO, $this);
1611
}
1712

1813
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]");
2218
}
2319

2420
function hook_hotkey_map($hotkeys) {
25-
$hotkeys['s y'] = 'send_to_yourls';
21+
$hotkeys['s y'] = 'send_to_yourls';
2622

2723
return $hotkeys;
2824
}
@@ -68,24 +64,40 @@ function getInfo() {
6864
WHERE id = ? AND ref_id = id AND owner_uid = ?");
6965
$sth->execute([$id, $_SESSION['uid']]);
7066
if ($row = $sth->fetch()) {
67+
7168
$title = truncate_string(strip_tags($row['title']), 100, '...');
7269
$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" ));
73100
}
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));
89101
}
90102

91103
function hook_prefs_tab($args) {

yourls/yourls.js

+47-22
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
function shareArticleToYourls(id) {
2-
try {
3-
var query = "?op=pluginhandler&plugin=yourls&method=getInfo&id=" + encodeURIComponent(id);
4-
var d = new Date();
5-
var ts = d.getTime();
6-
7-
new Ajax.Request("backend.php", {
8-
parameters: query,
9-
onSuccess: function(transport) {
10-
var ti = JSON.parse(transport.responseText);
11-
var share_url_query = "?signature=" + ti.yourlsapi + "&action=shorturl&format=simple&url=" + encodeURIComponent(ti.link) + "&title=" + encodeURIComponent(ti.title);
12-
dialog = new dijit.Dialog({
13-
id: "YourlsShortLinkDlg"+ts,
14-
title: __("Youlrs Shortened URL"),
15-
style: "width: 200px",
16-
content: '<p align=center>' + ti.shorturl + '<br/><a target="_blank" href="https://twitter.com/share?_=' + ts + '&text=' + encodeURIComponent(ti.title) + '&url=' + encodeURIComponent(ti.shorturl) + '"><img src="/plugins.local/yourls/tweetshare.png"/></a><br/><a target="_blank" href="https://www.facebook.com/sharer.php?u=' + encodeURIComponent(ti.shorturl) + '"><img src="/plugins.local/yourls/fbshare.png" border=0/></a></p>',
17-
});
18-
dialog.show();
19-
} });
20-
21-
} catch (e) {
22-
exception_error("yourlsArticle", e);
23-
}
2+
try {
3+
Notify.progress("Saving to YOURLS …", true);
4+
xhr.json("backend.php",
5+
{
6+
'op': 'pluginhandler',
7+
'plugin': 'yourls',
8+
'method': 'getInfo',
9+
'id': encodeURIComponent(id)
10+
},
11+
(reply) => {
12+
if (reply.status) {
13+
if (reply.status=="200") {
14+
var d = new Date();
15+
var ts = d.getTime();
16+
17+
dialog = new dijit.Dialog({
18+
id: "YourlsShortLinkDlg"+ts,
19+
title: __("Youlrs Shortened URL"),
20+
style: "width: 200px",
21+
content: '<p align=center>' + reply.shorturl + '<br/><a target="_blank" href="https://twitter.com/share?_=' + ts + '&text=' + encodeURIComponent(reply.title) + '&url=' + encodeURIComponent(reply.shorturl) + '"><img src="/plugins.local/yourls/tweetshare.png"/></a><br/><a target="_blank" href="https://www.facebook.com/sharer.php?u=' + encodeURIComponent(reply.shorturl) + '"><img src="/plugins.local/yourls/fbshare.png" border=0/></a></p>',
22+
});
23+
24+
dialog.show();
25+
Notify.info("Saved to YOURLS");
26+
} else {
27+
Notify.error("<strong>Error: "+reply.status+" encountered while saving to YOURLS!</strong>", true);
28+
}
29+
} else {
30+
Notify.error("The YOURLS plugin needs to be configured. See the README for help", true);
31+
}
32+
});
33+
} catch (e) {
34+
Notify.error("yourlsArticle", e);
35+
}
2436
}
37+
38+
require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
39+
ready(function () {
40+
PluginHost.register(PluginHost.HOOK_INIT_COMPLETE, () => {
41+
App.hotkey_actions["send_to_yourls"] = function() {
42+
if (Article.getActive()) {
43+
shareArticleToYourls(Article.getActive());
44+
return;
45+
}
46+
};
47+
});
48+
});
49+
});

0 commit comments

Comments
 (0)