diff options
Diffstat (limited to 'plugins/instances')
-rw-r--r-- | plugins/instances/init.php | 105 | ||||
-rw-r--r-- | plugins/instances/instances.js | 12 |
2 files changed, 86 insertions, 31 deletions
diff --git a/plugins/instances/init.php b/plugins/instances/init.php index 6c0f89e1c..aac28196f 100644 --- a/plugins/instances/init.php +++ b/plugins/instances/init.php @@ -1,7 +1,5 @@ <?php class Instances extends Plugin implements IHandler { - - private $link; private $host; private $status_codes = array( @@ -18,7 +16,6 @@ class Instances extends Plugin implements IHandler { } function init($host) { - $this->link = $host->get_link(); $this->host = $host; $host->add_hook($host::HOOK_PREFS_TABS, $this); @@ -30,7 +27,7 @@ class Instances extends Plugin implements IHandler { function hook_update_task($args) { _debug("Get linked feeds..."); - $this->get_linked_feeds($this->link); + $this->get_linked_feeds(); } // Status codes: @@ -40,7 +37,7 @@ class Instances extends Plugin implements IHandler { // 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 @@ -52,7 +49,7 @@ class Instances extends Plugin implements IHandler { $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)) { @@ -80,7 +77,7 @@ class Instances extends Plugin implements IHandler { // 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 { @@ -88,7 +85,7 @@ class Instances extends Plugin implements IHandler { 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) { @@ -97,7 +94,7 @@ class Instances extends Plugin implements IHandler { $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())"); @@ -122,7 +119,7 @@ class Instances extends Plugin implements IHandler { _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'"); } @@ -130,7 +127,7 @@ class Instances extends Plugin implements IHandler { function get_feeds() { - $this->get_linked_feeds($this->link, false); + $this->get_linked_feeds(false); } function get_prefs_js() { @@ -169,7 +166,7 @@ class Instances extends Plugin implements IHandler { function remove() { $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)"); } @@ -178,26 +175,26 @@ class Instances extends Plugin implements IHandler { $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($_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\">"; @@ -257,7 +254,7 @@ class Instances extends Plugin implements IHandler { $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'"); @@ -298,7 +295,7 @@ class Instances extends Plugin implements IHandler { 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 @@ -327,7 +324,7 @@ class Instances extends Plugin implements IHandler { $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>"; @@ -354,8 +351,7 @@ class Instances extends Plugin implements IHandler { print "</div>"; #pane - global $pluginhost; - $pluginhost->run_hooks($pluginhost::HOOK_PREFS_TAB, + PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "hook_prefs_tab", "prefInstances"); print "</div>"; #container @@ -367,14 +363,14 @@ class Instances extends Plugin implements IHandler { $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(); @@ -383,7 +379,7 @@ class Instances extends Plugin implements IHandler { 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)); @@ -392,6 +388,65 @@ class Instances extends Plugin implements IHandler { } } + 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)); + } + + function api_version() { + return 2; + } } ?> diff --git a/plugins/instances/instances.js b/plugins/instances/instances.js index 83213896d..f699acf72 100644 --- a/plugins/instances/instances.js +++ b/plugins/instances/instances.js @@ -1,6 +1,6 @@ function addInstance() { try { - var query = "backend.php?op=dlg&method=addInstance"; + var query = "backend.php?op=pluginhandler&plugin=instances&method=addInstance"; if (dijit.byId("instanceAddDlg")) dijit.byId("instanceAddDlg").destroyRecursive(); @@ -11,7 +11,7 @@ function addInstance() { style: "width: 600px", regenKey: function() { new Ajax.Request("backend.php", { - parameters: "?op=rpc&method=genHash", + parameters: "op=pluginhandler&plugin=instances&method=genHash", onComplete: function(transport) { var reply = JSON.parse(transport.responseText); if (reply) @@ -47,7 +47,7 @@ function addInstance() { function updateInstanceList(sort_key) { new Ajax.Request("backend.php", { - parameters: "?op=pref-instances&sort=" + param_escape(sort_key), + parameters: "op=pluginhandler&plugin=instances&sort=" + param_escape(sort_key), onComplete: function(transport) { dijit.byId('instanceConfigTab').attr('content', transport.responseText); selectTab("instanceConfig", true); @@ -62,7 +62,7 @@ function editInstance(id, event) { selectTableRows('prefInstanceList', 'none'); selectTableRowById('LIRR-'+id, 'LICHK-'+id, true); - var query = "backend.php?op=pref-instances&method=edit&id=" + + var query = "backend.php?op=pluginhandler&plugin=instances&method=edit&id=" + param_escape(id); if (dijit.byId("instanceEditDlg")) @@ -74,7 +74,7 @@ function editInstance(id, event) { style: "width: 600px", regenKey: function() { new Ajax.Request("backend.php", { - parameters: "?op=rpc&method=genHash", + parameters: "op=pluginhandler&plugin=instances&method=genHash", onComplete: function(transport) { var reply = JSON.parse(transport.responseText); if (reply) @@ -124,7 +124,7 @@ function removeSelectedInstances() { if (ok) { notify_progress("Removing selected instances..."); - var query = "?op=pref-instances&method=remove&ids="+ + var query = "op=pluginhandler&plugin=instances&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { |