<?php
class Instances extends Plugin implements IHandler {
-
- private $link;
private $host;
private $status_codes = array(
}
function init($host) {
- $this->link = $host->get_link();
$this->host = $host;
$host->add_hook($host::HOOK_PREFS_TABS, $this);
function hook_update_task($args) {
_debug("Get linked feeds...");
- $this->get_linked_feeds($this->link);
+ $this->get_linked_feeds();
}
// Status codes:
// 2 - did not receive valid data
// >10 - server error, code + 10 (e.g. 16 means server error 6)
- function get_linked_feeds($link, $instance_id = false) {
+ function get_linked_feeds( $instance_id = false) {
if ($instance_id)
$instance_qpart = "id = '$instance_id' AND ";
else
$date_qpart = "last_connected < DATE_SUB(NOW(), INTERVAL 6 HOUR)";
}
- $result = db_query($link, "SELECT id, access_key, access_url FROM ttrss_linked_instances
+ $result = db_query( "SELECT id, access_key, access_url FROM ttrss_linked_instances
WHERE $instance_qpart $date_qpart ORDER BY last_connected");
while ($line = db_fetch_assoc($result)) {
// access denied
if ($status == 16) {
- db_query($link, "DELETE FROM ttrss_linked_feeds
+ db_query( "DELETE FROM ttrss_linked_feeds
WHERE instance_id = '$id'");
}
} else {
if (count($feeds['feeds']) > 0) {
- db_query($link, "DELETE FROM ttrss_linked_feeds
+ db_query( "DELETE FROM ttrss_linked_feeds
WHERE instance_id = '$id'");
foreach ($feeds['feeds'] as $feed) {
- $feed_url = db_escape_string($this->link, $feed['feed_url']);
- $title = db_escape_string($this->link, $feed['title']);
- $subscribers = db_escape_string($this->link, $feed['subscribers']);
- $site_url = db_escape_string($this->link, $feed['site_url']);
+ $feed_url = db_escape_string( $feed['feed_url']);
+ $title = db_escape_string( $feed['title']);
+ $subscribers = db_escape_string( $feed['subscribers']);
+ $site_url = db_escape_string( $feed['site_url']);
- db_query($link, "INSERT INTO ttrss_linked_feeds
+ db_query( "INSERT INTO ttrss_linked_feeds
(feed_url, site_url, title, subscribers, instance_id, created, updated)
VALUES
('$feed_url', '$site_url', '$title', '$subscribers', '$id', NOW(), NOW())");
_debug("Status: $status");
- db_query($link, "UPDATE ttrss_linked_instances SET
+ db_query( "UPDATE ttrss_linked_instances SET
last_status_out = '$status', last_connected = NOW() WHERE id = '$id'");
}
function get_feeds() {
- $this->get_linked_feeds($this->link, false);
+ $this->get_linked_feeds( false);
}
function get_prefs_js() {
}
function remove() {
- $ids = db_escape_string($this->link, $_REQUEST['ids']);
+ $ids = db_escape_string( $_REQUEST['ids']);
- db_query($this->link, "DELETE FROM ttrss_linked_instances WHERE
+ db_query( "DELETE FROM ttrss_linked_instances WHERE
id IN ($ids)");
}
function add() {
- $id = db_escape_string($this->link, $_REQUEST["id"]);
- $access_url = db_escape_string($this->link, $_REQUEST["access_url"]);
- $access_key = db_escape_string($this->link, $_REQUEST["access_key"]);
+ $id = db_escape_string( $_REQUEST["id"]);
+ $access_url = db_escape_string( $_REQUEST["access_url"]);
+ $access_key = db_escape_string( $_REQUEST["access_key"]);
- db_query($this->link, "BEGIN");
+ db_query( "BEGIN");
- $result = db_query($this->link, "SELECT id FROM ttrss_linked_instances
+ $result = db_query( "SELECT id FROM ttrss_linked_instances
WHERE access_url = '$access_url'");
if (db_num_rows($result) == 0) {
- db_query($this->link, "INSERT INTO ttrss_linked_instances
+ db_query( "INSERT INTO ttrss_linked_instances
(access_url, access_key, last_connected, last_status_in, last_status_out)
VALUES
('$access_url', '$access_key', '1970-01-01', -1, -1)");
}
- db_query($this->link, "COMMIT");
+ db_query( "COMMIT");
}
function edit() {
- $id = db_escape_string($this->link, $_REQUEST["id"]);
+ $id = db_escape_string( $_REQUEST["id"]);
- $result = db_query($this->link, "SELECT * FROM ttrss_linked_instances WHERE
+ $result = db_query( "SELECT * FROM ttrss_linked_instances WHERE
id = '$id'");
print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$id\">";
}
function editSave() {
- $id = db_escape_string($this->link, $_REQUEST["id"]);
- $access_url = db_escape_string($this->link, $_REQUEST["access_url"]);
- $access_key = db_escape_string($this->link, $_REQUEST["access_key"]);
+ $id = db_escape_string( $_REQUEST["id"]);
+ $access_url = db_escape_string( $_REQUEST["access_url"]);
+ $access_key = db_escape_string( $_REQUEST["access_key"]);
- db_query($this->link, "UPDATE ttrss_linked_instances SET
+ db_query( "UPDATE ttrss_linked_instances SET
access_key = '$access_key', access_url = '$access_url',
last_connected = '1970-01-01'
WHERE id = '$id'");
print "<div id=\"pref-instance-toolbar\" dojoType=\"dijit.Toolbar\">";
- $sort = db_escape_string($this->link, $_REQUEST["sort"]);
+ $sort = db_escape_string( $_REQUEST["sort"]);
if (!$sort || $sort == "undefined") {
$sort = "access_url";
print "</div>"; #toolbar
- $result = db_query($this->link, "SELECT *,
+ $result = db_query( "SELECT *,
(SELECT COUNT(*) FROM ttrss_linked_feeds
WHERE instance_id = ttrss_linked_instances.id) AS num_feeds
FROM ttrss_linked_instances
$id = $line['id'];
$this_row_id = "id=\"LIRR-$id\"";
- $line["last_connected"] = make_local_datetime($this->link, $line["last_connected"], false);
+ $line["last_connected"] = make_local_datetime( $line["last_connected"], false);
print "<tr class=\"$class\" $this_row_id>";
function fbexport() {
- $access_key = db_escape_string($this->link, $_POST["key"]);
+ $access_key = db_escape_string( $_POST["key"]);
// TODO: rate limit checking using last_connected
- $result = db_query($this->link, "SELECT id FROM ttrss_linked_instances
+ $result = db_query( "SELECT id FROM ttrss_linked_instances
WHERE access_key = '$access_key'");
if (db_num_rows($result) == 1) {
$instance_id = db_fetch_result($result, 0, "id");
- $result = db_query($this->link, "SELECT feed_url, site_url, title, subscribers
+ $result = db_query( "SELECT feed_url, site_url, title, subscribers
FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
$feeds = array();
array_push($feeds, $line);
}
- db_query($this->link, "UPDATE ttrss_linked_instances SET
+ db_query( "UPDATE ttrss_linked_instances SET
last_status_in = 1 WHERE id = '$instance_id'");
print json_encode(array("feeds" => $feeds));
}
}
+ function addInstance() {
+ print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-instances\">";
+ print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">";
+
+ print "<div class=\"dlgSec\">".__("Instance")."</div>";
+
+ print "<div class=\"dlgSecCont\">";
+
+ /* URL */
+
+ print __("URL:") . " ";
+
+ print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
+ placeHolder=\"".__("Instance URL")."\"
+ regExp='^(http|https)://.*'
+ style=\"font-size : 16px; width: 20em\" name=\"access_url\">";
+
+ print "<hr/>";
+
+ $access_key = sha1(uniqid(rand(), true));
+
+ /* Access key */
+
+ print __("Access key:") . " ";
+
+ print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\"
+ placeHolder=\"".__("Access key")."\" regExp='\w{40}'
+ style=\"width: 20em\" name=\"access_key\" id=\"instance_add_key\"
+ value=\"$access_key\">";
+
+ print "<p class='insensitive'>" . __("Use one access key for both linked instances.");
+
+ print "</div>";
+
+ print "<div class=\"dlgButtons\">
+ <div style='float : left'>
+ <button dojoType=\"dijit.form.Button\"
+ onclick=\"return dijit.byId('instanceAddDlg').regenKey()\">".
+ __('Generate new key')."</button>
+ </div>
+ <button dojoType=\"dijit.form.Button\"
+ onclick=\"return dijit.byId('instanceAddDlg').execute()\">".
+ __('Create link')."</button>
+ <button dojoType=\"dijit.form.Button\"
+ onclick=\"return dijit.byId('instanceAddDlg').hide()\"\">".
+ __('Cancel')."</button></div>";
+
+ return;
+ }
+
+ function genHash() {
+ $hash = sha1(uniqid(rand(), true));
+
+ print json_encode(array("hash" => $hash));
+ }
+
}
?>