From f30ef1fa1bd76b497b5c0a64a92e2e0ef7116515 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 12 Dec 2011 22:46:25 +0400 Subject: subop -> method --- js/PrefFeedTree.js | 2 +- js/digest.js | 22 +++++++------- js/feedlist.js | 18 +++++------ js/functions.js | 26 ++++++++-------- js/prefs.js | 88 +++++++++++++++++++++++++++--------------------------- js/tt-rss.js | 26 ++++++++-------- js/viewfeed.js | 38 +++++++++++------------ 7 files changed, 110 insertions(+), 110 deletions(-) (limited to 'js') diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js index 4ea486609..9e2ee0662 100644 --- a/js/PrefFeedTree.js +++ b/js/PrefFeedTree.js @@ -11,7 +11,7 @@ dojo.declare("fox.PrefFeedStore", dojo.data.ItemFileWriteStore, { dojo.xhrPost({ url: "backend.php", - content: {op: "pref-feeds", subop: "savefeedorder", + content: {op: "pref-feeds", method: "savefeedorder", payload: newFileContentString}, error: saveFailedCallback, load: saveCompleteCallback}); diff --git a/js/digest.js b/js/digest.js index 7dba6d36e..c1cbf8762 100644 --- a/js/digest.js +++ b/js/digest.js @@ -26,7 +26,7 @@ function catchup_feed(feed_id, callback) { if (feed_id < 0) is_cat = "true"; // KLUDGE - var query = "?op=rpc&subop=catchupFeed&feed_id=" + + var query = "?op=rpc&method=catchupFeed&feed_id=" + feed_id + "&is_cat=" + is_cat; new Ajax.Request("backend.php", { @@ -68,7 +68,7 @@ function catchup_visible_articles(callback) { if (confirm(__("Mark %d displayed articles as read?").replace("%d", ids.length))) { - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=0&ids=" + param_escape(ids); new Ajax.Request("backend.php", { @@ -88,7 +88,7 @@ function catchup_visible_articles(callback) { function catchup_article(article_id, callback) { try { - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=0&ids=" + article_id; new Ajax.Request("backend.php", { @@ -169,7 +169,7 @@ function update(callback) { window.clearTimeout(_update_timeout); new Ajax.Request("backend.php", { - parameters: "?op=rpc&subop=digest-init", + parameters: "?op=rpc&method=digest-init", onComplete: function(transport) { fatal_error_check(transport); parse_feeds(transport); @@ -220,7 +220,7 @@ function view(article_id) { }, 500); new Ajax.Request("backend.php", { - parameters: "?op=rpc&subop=digest-get-contents&article_id=" + + parameters: "?op=rpc&method=digest-get-contents&article_id=" + article_id, onComplete: function(transport) { fatal_error_check(transport); @@ -315,7 +315,7 @@ function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback) if (!offset) $("headlines").scrollTop = 0; - var query = "backend.php?op=rpc&subop=digest-update&feed_id=" + + var query = "backend.php?op=rpc&method=digest-update&feed_id=" + param_escape(feed_id) + "&offset=" + offset + "&seq=" + _update_seq; @@ -648,7 +648,7 @@ function parse_headlines(transport, replace, no_effects) { function init_second_stage() { try { new Ajax.Request("backend.php", { - parameters: "backend.php?op=rpc&subop=digest-init", + parameters: "backend.php?op=rpc&method=digest-init", onComplete: function(transport) { parse_feeds(transport); Element.hide("overlay"); @@ -667,7 +667,7 @@ function init() { dojo.require("dijit.Dialog"); new Ajax.Request("backend.php", { - parameters: "?op=rpc&subop=sanityCheck", + parameters: "?op=rpc&method=sanityCheck", onComplete: function(transport) { backend_sanity_check_callback(transport); } }); @@ -681,7 +681,7 @@ function toggle_mark(img, id) { try { - var query = "?op=rpc&id=" + id + "&subop=mark"; + var query = "?op=rpc&id=" + id + "&method=mark"; if (!img) return; @@ -710,7 +710,7 @@ function toggle_pub(img, id, note) { try { - var query = "?op=rpc&id=" + id + "&subop=publ"; + var query = "?op=rpc&id=" + id + "&method=publ"; if (note != undefined) { query = query + "¬e=" + param_escape(note); @@ -798,7 +798,7 @@ function update_title(unread) { function tweet_article(id) { try { - var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id); + var query = "?op=rpc&method=getTweetInfo&id=" + param_escape(id); console.log(query); diff --git a/js/feedlist.js b/js/feedlist.js index eaaeaad81..ff4c948d4 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -48,14 +48,14 @@ function loadMoreHeadlines() { } -function viewfeed(feed, subop, is_cat, offset, background, infscroll_req) { +function viewfeed(feed, method, is_cat, offset, background, infscroll_req) { try { if (is_cat == undefined) is_cat = false; else is_cat = !!is_cat; - if (subop == undefined) subop = ''; + if (method == undefined) method = ''; if (offset == undefined) offset = 0; if (background == undefined) background = false; if (infscroll_req == undefined) infscroll_req = false; @@ -110,7 +110,7 @@ function viewfeed(feed, subop, is_cat, offset, background, infscroll_req) { _infscroll_disable = 0; } - if (!offset && !subop && cached_headlines && !background) { + if (!offset && !method && cached_headlines && !background) { try { render_local_headlines(feed, is_cat, JSON.parse(cached_headlines)); return; @@ -119,7 +119,7 @@ function viewfeed(feed, subop, is_cat, offset, background, infscroll_req) { } } - if (offset != 0 && !subop) { + if (offset != 0 && !method) { var date = new Date(); var timestamp = Math.round(date.getTime() / 1000); @@ -139,7 +139,7 @@ function viewfeed(feed, subop, is_cat, offset, background, infscroll_req) { var toolbar_query = Form.serialize("main_toolbar_form"); var query = "?op=viewfeed&feed=" + feed + "&" + - toolbar_query + "&subop=" + param_escape(subop); + toolbar_query + "&method=" + param_escape(method); if (!background) { if (_search_query) { @@ -148,7 +148,7 @@ function viewfeed(feed, subop, is_cat, offset, background, infscroll_req) { _search_query = false; } - if (subop == "MarkAllRead") { + if (method == "MarkAllRead") { var show_next_feed = getInitParam("on_catchup_show_next_feed") == "1"; @@ -162,7 +162,7 @@ function viewfeed(feed, subop, is_cat, offset, background, infscroll_req) { render_local_headlines(nuf, false, JSON.parse(cached_nuf)); - var catchup_query = "?op=rpc&subop=catchupFeed&feed_id=" + + var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + feed + "&is_cat=" + is_cat; console.log(catchup_query); @@ -246,7 +246,7 @@ function request_counters_real() { try { console.log("requesting counters..."); - var query = "?op=rpc&subop=getAllCounters&seq=" + next_seq(); + var query = "?op=rpc&method=getAllCounters&seq=" + next_seq(); query = query + "&omode=flc"; @@ -487,7 +487,7 @@ function catchupFeed(feed, is_cat) { return; } - var catchup_query = "?op=rpc&subop=catchupFeed&feed_id=" + + var catchup_query = "?op=rpc&method=catchupFeed&feed_id=" + feed + "&is_cat=" + is_cat; notify_progress("Loading, please wait...", true); diff --git a/js/functions.js b/js/functions.js index 02fbadf53..e62d576b6 100644 --- a/js/functions.js +++ b/js/functions.js @@ -607,7 +607,7 @@ function filterDlgCheckDate() { var reg_exp = dialog.attr('value').reg_exp; - var query = "?op=rpc&subop=checkDate&date=" + reg_exp; + var query = "?op=rpc&method=checkDate&date=" + reg_exp; new Ajax.Request("backend.php", { parameters: query, @@ -756,7 +756,7 @@ function removeFeedIcon(id) { try { if (confirm(__("Remove stored feed icon?"))) { - var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id); + var query = "backend.php?op=pref-feeds&method=removeicon&feed_id=" + param_escape(id); console.log(query); @@ -815,7 +815,7 @@ function addLabel(select, callback) { return false; } - var query = "?op=pref-labels&subop=add&caption=" + + var query = "?op=pref-labels&method=add&caption=" + param_escape(caption); if (select) @@ -893,7 +893,7 @@ function quickAddFeed() { notify_progress("Searching for feed urls...", true); new Ajax.Request("backend.php", { - parameters: 'op=rpc&subop=extractfeedurls&url=' + param_escape(feed_url), + parameters: 'op=rpc&method=extractfeedurls&url=' + param_escape(feed_url), onComplete: function(transport, dialog, feed_url) { notify(''); @@ -978,7 +978,7 @@ function quickAddFilter() { execute: function() { if (this.validate()) { - var query = "?op=rpc&subop=verifyRegexp®_exp=" + + var query = "?op=rpc&method=verifyRegexp®_exp=" + param_escape(dialog.attr('value').reg_exp); notify_progress("Verifying regular expression..."); @@ -1028,7 +1028,7 @@ function resetPubSub(feed_id, title) { if (title == undefined || confirm(msg)) { notify_progress("Loading, please wait..."); - var query = "?op=pref-feeds&quiet=1&subop=resetPubSub&ids=" + feed_id; + var query = "?op=pref-feeds&quiet=1&method=resetPubSub&ids=" + feed_id; new Ajax.Request("backend.php", { parameters: query, @@ -1049,7 +1049,7 @@ function unsubscribeFeed(feed_id, title) { if (title == undefined || confirm(msg)) { notify_progress("Removing feed..."); - var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; + var query = "?op=pref-feeds&quiet=1&method=remove&ids=" + feed_id; new Ajax.Request("backend.php", { parameters: query, @@ -1155,7 +1155,7 @@ function quickAddCat(elem) { if (cat) { - var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat); + var query = "?op=rpc&method=quickAddCat&cat=" + param_escape(cat); notify_progress("Loading, please wait...", true); @@ -1188,7 +1188,7 @@ function genUrlChangeKey(feed, is_cat) { notify_progress("Trying to change address...", true); - var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + + var query = "?op=rpc&method=regenFeedKey&id=" + param_escape(feed) + "&is_cat=" + param_escape(is_cat); new Ajax.Request("backend.php", { @@ -1368,7 +1368,7 @@ function editFeed(feed, event) { if (feed <= 0) return alert(__("You can't edit this kind of feed.")); - var query = "backend.php?op=pref-feeds&subop=editfeed&id=" + + var query = "backend.php?op=pref-feeds&method=editfeed&id=" + param_escape(feed); console.log(query); @@ -1464,7 +1464,7 @@ function feedBrowser() { // we use dojo.toJson instead of JSON.stringify because // it somehow escapes everything TWICE, at least in Chrome 9 - var query = "?op=rpc&subop=massSubscribe&payload="+ + var query = "?op=rpc&method=massSubscribe&payload="+ param_escape(dojo.toJson(selected)) + "&mode=" + param_escape(mode); console.log(query); @@ -1524,7 +1524,7 @@ function feedBrowser() { if (confirm(pr)) { Element.show('feed_browser_spinner'); - var query = "?op=rpc&subop=remarchived&ids=" + + var query = "?op=rpc&method=remarchived&ids=" + param_escape(selected.toString());; new Ajax.Request("backend.php", { @@ -1574,7 +1574,7 @@ function showFeedsWithErrors() { if (ok) { notify_progress("Removing selected feeds...", true); - var query = "?op=pref-feeds&subop=remove&ids="+ + var query = "?op=pref-feeds&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { diff --git a/js/prefs.js b/js/prefs.js index e40d6d723..760441a3d 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -124,7 +124,7 @@ function addUser() { notify_progress("Adding user..."); - var query = "?op=pref-users&subop=add&login=" + + var query = "?op=pref-users&method=add&login=" + param_escape(login); new Ajax.Request("backend.php", { @@ -148,7 +148,7 @@ function editUser(id, event) { selectTableRows('prefUserList', 'none'); selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true); - var query = "?op=pref-users&subop=edit&id=" + + var query = "?op=pref-users&method=edit&id=" + param_escape(id); new Ajax.Request("backend.php", { @@ -173,7 +173,7 @@ function editUser(id, event) { function editFilter(id) { try { - var query = "backend.php?op=pref-filters&subop=edit&id=" + param_escape(id); + var query = "backend.php?op=pref-filters&method=edit&id=" + param_escape(id); if (dijit.byId("filterEditDlg")) dijit.byId("filterEditDlg").destroyRecursive(); @@ -193,7 +193,7 @@ function editFilter(id) { var id = this.attr('value').id; - var query = "?op=pref-filters&subop=remove&ids="+ + var query = "?op=pref-filters&method=remove&ids="+ param_escape(id); new Ajax.Request("backend.php", { @@ -224,7 +224,7 @@ function editFilter(id) { execute: function() { if (this.validate()) { - var query = "?op=rpc&subop=verifyRegexp®_exp=" + + var query = "?op=rpc&method=verifyRegexp®_exp=" + param_escape(dialog.attr('value').reg_exp); notify_progress("Verifying regular expression..."); @@ -323,7 +323,7 @@ function removeSelectedLabels() { if (ok) { notify_progress("Removing selected labels..."); - var query = "?op=pref-labels&subop=remove&ids="+ + var query = "?op=pref-labels&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -353,7 +353,7 @@ function removeSelectedUsers() { if (ok) { notify_progress("Removing selected users..."); - var query = "?op=pref-users&subop=remove&ids="+ + var query = "?op=pref-users&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -388,7 +388,7 @@ function removeSelectedFilters() { if (ok) { notify_progress("Removing selected filters..."); - var query = "?op=pref-filters&subop=remove&ids="+ + var query = "?op=pref-filters&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -423,7 +423,7 @@ function removeSelectedFeeds() { notify_progress("Unsubscribing from selected feeds...", true); - var query = "?op=pref-feeds&subop=remove&ids="+ + var query = "?op=pref-feeds&method=remove&ids="+ param_escape(sel_rows.toString()); console.log(query); @@ -484,7 +484,7 @@ function purgeSelectedFeeds() { if (pr != undefined) { notify_progress("Purging selected feed..."); - var query = "?op=rpc&subop=purge&ids="+ + var query = "?op=rpc&method=purge&ids="+ param_escape(sel_rows.toString()) + "&days=" + pr; console.log(query); @@ -583,7 +583,7 @@ function resetSelectedUserPass() { var id = rows[0]; - var query = "?op=pref-users&subop=resetPass&id=" + + var query = "?op=pref-users&method=resetPass&id=" + param_escape(id); new Ajax.Request("backend.php", { @@ -619,7 +619,7 @@ function selectedUserDetails() { var id = rows[0]; - var query = "?op=pref-users&subop=user-details&id=" + id; + var query = "?op=pref-users&method=user-details&id=" + id; new Ajax.Request("backend.php", { parameters: query, @@ -682,7 +682,7 @@ function editSelectedFeeds() { notify_progress("Loading, please wait..."); - var query = "backend.php?op=pref-feeds&subop=editfeeds&ids=" + + var query = "backend.php?op=pref-feeds&method=editfeeds&ids=" + param_escape(rows.toString()); console.log(query); @@ -863,7 +863,7 @@ function updatePrefsList() { } }); } -function selectTab(id, noupdate, subop) { +function selectTab(id, noupdate, method) { try { if (!noupdate) { notify_progress("Loading, please wait..."); @@ -905,10 +905,10 @@ function init_second_stage() { if (tab) dijit.byId("pref-tabs").selectChild(tab); } - var subop = getURLParam('subop'); + var method = getURLParam('method'); - if (subop == 'editFeed') { - var param = getURLParam('subopparam'); + if (method == 'editFeed') { + var param = getURLParam('methodparam'); window.setTimeout('editFeed(' + param + ')', 100); } @@ -938,7 +938,7 @@ function init() { loading_set_progress(50); new Ajax.Request("backend.php", { - parameters: {op: "rpc", subop: "sanityCheck"}, + parameters: {op: "rpc", method: "sanityCheck"}, onComplete: function(transport) { backend_sanity_check_callback(transport); } }); @@ -955,7 +955,7 @@ function validatePrefsReset() { if (ok) { - query = "?op=pref-prefs&subop=reset-config"; + query = "?op=pref-prefs&method=reset-config"; console.log(query); new Ajax.Request("backend.php", { @@ -1160,7 +1160,7 @@ function pref_hotkey_handler(e) { function editFeedCats() { try { - var query = "backend.php?op=pref-feeds&subop=editCats"; + var query = "backend.php?op=pref-feeds&method=editCats"; if (dijit.byId("feedCatEditDlg")) dijit.byId("feedCatEditDlg").destroyRecursive(); @@ -1181,7 +1181,7 @@ function editFeedCats() { if (ok) { notify_progress("Removing selected categories...", true); - var query = "?op=pref-feeds&subop=editCats&action=remove&ids="+ + var query = "?op=pref-feeds&method=editCats&action=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1202,7 +1202,7 @@ function editFeedCats() { if (this.validate()) { notify_progress("Creating category..."); - var query = "?op=pref-feeds&subop=editCats&action=add&cat=" + + var query = "?op=pref-feeds&method=editCats&action=add&cat=" + param_escape(this.attr('value').newcat); new Ajax.Request("backend.php", { @@ -1252,7 +1252,7 @@ function showInactiveFeeds() { if (ok) { notify_progress("Removing selected feeds...", true); - var query = "?op=pref-feeds&subop=remove&ids="+ + var query = "?op=pref-feeds&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1291,7 +1291,7 @@ function opmlRegenKey() { notify_progress("Trying to change address...", true); - var query = "?op=rpc&subop=regenOPMLKey"; + var query = "?op=rpc&method=regenOPMLKey"; new Ajax.Request("backend.php", { parameters: query, @@ -1376,7 +1376,7 @@ function clearFeedArticles(feed_id) { notify_progress("Clearing feed..."); - var query = "?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id; + var query = "?op=pref-feeds&quiet=1&method=clear&id=" + feed_id; new Ajax.Request("backend.php", { parameters: query, @@ -1399,7 +1399,7 @@ function rescoreSelectedFeeds() { if (ok) { notify_progress("Rescoring selected feeds...", true); - var query = "?op=pref-feeds&subop=rescore&quiet=1&ids="+ + var query = "?op=pref-feeds&method=rescore&quiet=1&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1422,7 +1422,7 @@ function rescore_all_feeds() { if (ok) { notify_progress("Rescoring feeds...", true); - var query = "?op=pref-feeds&subop=rescoreAll&quiet=1"; + var query = "?op=pref-feeds&method=rescoreAll&quiet=1"; new Ajax.Request("backend.php", { parameters: query, @@ -1440,7 +1440,7 @@ function labelColorReset() { var ok = confirm(__("Reset selected labels to default colors?")); if (ok) { - var query = "?op=pref-labels&subop=color-reset&ids="+ + var query = "?op=pref-labels&method=color-reset&ids="+ param_escape(labels.toString()); new Ajax.Request("backend.php", { @@ -1488,7 +1488,7 @@ function editProfiles() { if (ok) { notify_progress("Removing selected profiles...", true); - var query = "?op=rpc&subop=remprofiles&ids="+ + var query = "?op=rpc&method=remprofiles&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1514,7 +1514,7 @@ function editProfiles() { if (ok) { notify_progress("Loading, please wait..."); - var query = "?op=rpc&subop=setprofile&id="+ + var query = "?op=rpc&method=setprofile&id="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1532,7 +1532,7 @@ function editProfiles() { if (this.validate()) { notify_progress("Creating profile...", true); - var query = "?op=rpc&subop=addprofile&title=" + + var query = "?op=rpc&method=addprofile&title=" + param_escape(dialog.attr('value').newprofile); new Ajax.Request("backend.php", { @@ -1567,7 +1567,7 @@ function activatePrefProfile() { if (ok) { notify_progress("Loading, please wait..."); - var query = "?op=rpc&subop=setprofile&id="+ + var query = "?op=rpc&method=setprofile&id="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { @@ -1591,7 +1591,7 @@ function clearFeedAccessKeys() { if (ok) { notify_progress("Clearing URLs..."); - var query = "?op=rpc&subop=clearKeys"; + var query = "?op=rpc&method=clearKeys"; new Ajax.Request("backend.php", { parameters: query, @@ -1610,7 +1610,7 @@ function clearArticleAccessKeys() { if (ok) { notify_progress("Clearing URLs..."); - var query = "?op=rpc&subop=clearArticleKeys"; + var query = "?op=rpc&method=clearArticleKeys"; new Ajax.Request("backend.php", { parameters: query, @@ -1626,7 +1626,7 @@ function resetFeedOrder() { notify_progress("Loading, please wait..."); new Ajax.Request("backend.php", { - parameters: "?op=pref-feeds&subop=feedsortreset", + parameters: "?op=pref-feeds&method=feedsortreset", onComplete: function(transport) { updateFeedList(); } }); @@ -1642,7 +1642,7 @@ function resetCatOrder() { notify_progress("Loading, please wait..."); new Ajax.Request("backend.php", { - parameters: "?op=pref-feeds&subop=catsortreset", + parameters: "?op=pref-feeds&method=catsortreset", onComplete: function(transport) { updateFeedList(); } }); @@ -1664,7 +1664,7 @@ function editCat(id, item, event) { new Ajax.Request("backend.php", { parameters: { op: 'pref-feeds', - subop: 'renamecat', + method: 'renamecat', id: id, title: new_name, }, @@ -1680,7 +1680,7 @@ function editCat(id, item, event) { function editLabel(id, event) { try { - var query = "backend.php?op=pref-labels&subop=edit&id=" + + var query = "backend.php?op=pref-labels&method=edit&id=" + param_escape(id); if (dijit.byId("labelEditDlg")) @@ -1705,7 +1705,7 @@ function editLabel(id, event) { color = bg; } - var query = "?op=pref-labels&subop=color-set&kind="+kind+ + var query = "?op=pref-labels&method=color-set&kind="+kind+ "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) + "&bg=" + param_escape(bg) + "&color=" + param_escape(color); @@ -1756,7 +1756,7 @@ function clearTwitterCredentials() { if (ok) { notify_progress("Clearing credentials..."); - var query = "?op=pref-feeds&subop=remtwitterinfo"; + var query = "?op=pref-feeds&method=remtwitterinfo"; new Ajax.Request("backend.php", { parameters: query, @@ -1826,7 +1826,7 @@ function addInstance() { style: "width: 600px", regenKey: function() { new Ajax.Request("backend.php", { - parameters: "?op=rpc&subop=genHash", + parameters: "?op=rpc&method=genHash", onComplete: function(transport) { var reply = JSON.parse(transport.responseText); if (reply) @@ -1865,7 +1865,7 @@ function editInstance(id, event) { selectTableRows('prefInstanceList', 'none'); selectTableRowById('LIRR-'+id, 'LICHK-'+id, true); - var query = "backend.php?op=pref-instances&subop=edit&id=" + + var query = "backend.php?op=pref-instances&method=edit&id=" + param_escape(id); if (dijit.byId("instanceEditDlg")) @@ -1877,7 +1877,7 @@ function editInstance(id, event) { style: "width: 600px", regenKey: function() { new Ajax.Request("backend.php", { - parameters: "?op=rpc&subop=genHash", + parameters: "?op=rpc&method=genHash", onComplete: function(transport) { var reply = JSON.parse(transport.responseText); if (reply) @@ -1927,7 +1927,7 @@ function removeSelectedInstances() { if (ok) { notify_progress("Removing selected instances..."); - var query = "?op=pref-instances&subop=remove&ids="+ + var query = "?op=pref-instances&method=remove&ids="+ param_escape(sel_rows.toString()); new Ajax.Request("backend.php", { diff --git a/js/tt-rss.js b/js/tt-rss.js index 589091959..96147b3d3 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -82,7 +82,7 @@ function updateFeedList() { var cat_id = id.substr(id.indexOf(":")+1); new Ajax.Request("backend.php", - { parameters: "backend.php?op=feeds&subop=collapse&cid=" + + { parameters: "backend.php?op=feeds&method=collapse&cid=" + param_escape(cat_id) + "&mode=0" } ); }, onClose: function (item, node) { @@ -90,7 +90,7 @@ function updateFeedList() { var cat_id = id.substr(id.indexOf(":")+1); new Ajax.Request("backend.php", - { parameters: "backend.php?op=feeds&subop=collapse&cid=" + + { parameters: "backend.php?op=feeds&method=collapse&cid=" + param_escape(cat_id) + "&mode=1" } ); }, @@ -148,7 +148,7 @@ function catchupAllFeeds() { if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - var query_str = "backend.php?op=feeds&subop=catchupAll"; + var query_str = "backend.php?op=feeds&method=catchupAll"; notify_progress("Marking all feeds as read..."); @@ -165,10 +165,10 @@ function catchupAllFeeds() { } } -function viewCurrentFeed(subop) { +function viewCurrentFeed(method) { if (getActiveFeedId() != undefined) { - viewfeed(getActiveFeedId(), subop, activeFeedIsCat()); + viewfeed(getActiveFeedId(), method, activeFeedIsCat()); } return false; // block unneeded form submits } @@ -186,7 +186,7 @@ function timeout() { window.clearTimeout(counter_timeout_id); - var query_str = "?op=rpc&subop=getAllCounters&seq=" + next_seq(); + var query_str = "?op=rpc&method=getAllCounters&seq=" + next_seq(); var omode; @@ -302,7 +302,7 @@ function init() { var hasAudio = !!((myAudioTag = document.createElement('audio')).canPlayType); new Ajax.Request("backend.php", { - parameters: {op: "rpc", subop: "sanityCheck", hasAudio: hasAudio}, + parameters: {op: "rpc", method: "sanityCheck", hasAudio: hasAudio}, onComplete: function(transport) { backend_sanity_check_callback(transport); } }); @@ -454,7 +454,7 @@ function toggleDispRead() { hideOrShowFeeds(hide); - var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" + + var query = "?op=rpc&method=setpref&key=HIDE_READ_FEEDS&value=" + param_escape(hide); setInitParam("hide_read_feeds", hide); @@ -555,7 +555,7 @@ function collapse_feedlist() { dijit.byId("main").resize(); - query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true"; + query = "?op=rpc&method=setpref&key=_COLLAPSED_FEEDLIST&value=true"; new Ajax.Request("backend.php", { parameters: query }); } catch (e) { @@ -577,7 +577,7 @@ function viewLimitChanged() { var pr = prompt(__("Assign score to article:"), score); if (pr != undefined) { - var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr; + var query = "?op=rpc&method=setScore&id=" + id + "&score=" + pr; new Ajax.Request("backend.php", { parameters: query, @@ -611,7 +611,7 @@ function rescoreCurrentFeed() { if (confirm(pr)) { notify_progress("Rescoring articles..."); - var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid; + var query = "?op=pref-feeds&method=rescore&quiet=1&ids=" + actid; new Ajax.Request("backend.php", { parameters: query, @@ -1024,7 +1024,7 @@ function inPreferences() { function reverseHeadlineOrder() { try { - var query_str = "?op=rpc&subop=togglepref&key=REVERSE_HEADLINES"; + var query_str = "?op=rpc&method=togglepref&key=REVERSE_HEADLINES"; new Ajax.Request("backend.php", { parameters: query_str, @@ -1049,7 +1049,7 @@ function scheduleFeedUpdate(id, is_cat) { return; } - var query = "?op=rpc&subop=scheduleFeedUpdate&id=" + + var query = "?op=rpc&method=scheduleFeedUpdate&id=" + param_escape(id) + "&is_cat=" + param_escape(is_cat); diff --git a/js/viewfeed.js b/js/viewfeed.js index 9cb902315..363121b19 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -406,7 +406,7 @@ function view(id) { function toggleMark(id, client_only) { try { - var query = "?op=rpc&id=" + id + "&subop=mark"; + var query = "?op=rpc&id=" + id + "&method=mark"; var img = $("FMPIC-" + id); @@ -440,7 +440,7 @@ function toggleMark(id, client_only) { function togglePub(id, client_only, no_effects, note) { try { - var query = "?op=rpc&id=" + id + "&subop=publ"; + var query = "?op=rpc&id=" + id + "&method=publ"; if (note != undefined) { query = query + "¬e=" + param_escape(note); @@ -601,7 +601,7 @@ function toggleUnread(id, cmode, effect) { if (cmode == undefined) cmode = 2; - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id); // notify_progress("Loading, please wait..."); @@ -629,7 +629,7 @@ function selectionRemoveLabel(id, ids) { return; } - var query = "?op=rpc&subop=removeFromLabel&ids=" + + var query = "?op=rpc&method=removeFromLabel&ids=" + param_escape(ids.toString()) + "&lid=" + param_escape(id); console.log(query); @@ -657,7 +657,7 @@ function selectionAssignLabel(id, ids) { return; } - var query = "?op=rpc&subop=assignToLabel&ids=" + + var query = "?op=rpc&method=assignToLabel&ids=" + param_escape(ids.toString()) + "&lid=" + param_escape(id); console.log(query); @@ -717,7 +717,7 @@ function selectionToggleUnread(set_state, callback, no_error) { cmode = "0"; } - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=" + cmode + "&ids=" + param_escape(rows.toString()); notify_progress("Loading, please wait..."); @@ -752,7 +752,7 @@ function selectionToggleMarked() { if (rows.length > 0) { - var query = "?op=rpc&subop=markSelected&ids=" + + var query = "?op=rpc&method=markSelected&ids=" + param_escape(rows.toString()) + "&cmode=2"; new Ajax.Request("backend.php", { @@ -784,7 +784,7 @@ function selectionTogglePublished() { if (rows.length > 0) { - var query = "?op=rpc&subop=publishSelected&ids=" + + var query = "?op=rpc&method=publishSelected&ids=" + param_escape(rows.toString()) + "&cmode=2"; new Ajax.Request("backend.php", { @@ -910,7 +910,7 @@ function deleteSelection() { return; } - query = "?op=rpc&subop=delete&ids=" + param_escape(rows); + query = "?op=rpc&method=delete&ids=" + param_escape(rows); console.log(query); @@ -956,7 +956,7 @@ function archiveSelection() { return; } - query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows); + query = "?op=rpc&method="+op+"&ids=" + param_escape(rows); console.log(query); @@ -1052,7 +1052,7 @@ function editArticleTags(id) { dojo.disconnect(tmph); new Ajax.Autocompleter('tags_str', 'tags_choices', - "backend.php?op=rpc&subop=completeTags", + "backend.php?op=rpc&method=completeTags", { tokens: ',', paramName: "search" }); }); @@ -1141,7 +1141,7 @@ function catchupBatchedArticles() { try { if (catchup_id_batch.length > 0 && !_infscroll_request_sent) { - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=0&ids=" + param_escape(catchup_id_batch.toString()); new Ajax.Request("backend.php", { @@ -1216,7 +1216,7 @@ function catchupRelativeToArticle(below, id) { e.removeClassName("Unread"); } - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString()); new Ajax.Request("backend.php", { @@ -1275,7 +1275,7 @@ function cdmExpandArticle(id) { $("CWRAP-" + id).innerHTML = "
" + __("Loading, please wait...") + "
"; - var query = "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id); + var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id); var neighbor_ids = getRelativePostIds(id); @@ -1386,7 +1386,7 @@ function zoomToArticle(event, id) { } else { - var query = "?op=rpc&subop=getArticles&ids=" + param_escape(id); + var query = "?op=rpc&method=getArticles&ids=" + param_escape(id); notify_progress("Loading, please wait...", true); @@ -1547,7 +1547,7 @@ function emailArticle(id) { dojo.disconnect(tmph); new Ajax.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices', - "backend.php?op=rpc&subop=completeEmails", + "backend.php?op=rpc&method=completeEmails", { tokens: '', paramName: "search" }); }); @@ -1558,7 +1558,7 @@ function emailArticle(id) { document.forms['article_email_form'].destination.focus(); new Ajax.Autocompleter('destination', 'destination_choices', - "backend.php?op=rpc&subop=completeEmails", + "backend.php?op=rpc&method=completeEmails", { tokens: '', paramName: "search" }); }); */ @@ -1685,7 +1685,7 @@ function cdmClicked(event, id) { active_post_id = id; - var query = "?op=rpc&subop=catchupSelected" + + var query = "?op=rpc&method=catchupSelected" + "&cmode=0&ids=" + param_escape(id); new Ajax.Request("backend.php", { @@ -1996,7 +1996,7 @@ function initHeadlinesMenu() { function tweetArticle(id) { try { - var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id); + var query = "?op=rpc&method=getTweetInfo&id=" + param_escape(id); console.log(query); -- cgit v1.2.3-54-g00ecf From d51124689d199ef3796c09f4353ef595bd3827b0 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 12 Dec 2011 23:32:29 +0400 Subject: add tiny-OOP style backend RPC --- backend.php | 26 +- classes/handler.php | 15 + classes/rpc.php | 792 +++++++++++++++++++++++++++++++++++++++++ js/digest.js | 10 +- modules/backend-rpc.php | 911 ------------------------------------------------ 5 files changed, 832 insertions(+), 922 deletions(-) create mode 100644 classes/handler.php create mode 100644 classes/rpc.php delete mode 100644 modules/backend-rpc.php (limited to 'js') diff --git a/backend.php b/backend.php index 0e485de70..c9eed0e9a 100644 --- a/backend.php +++ b/backend.php @@ -16,6 +16,13 @@ $_REQUEST = array_map('stripslashes_deep', $_REQUEST); } + function __autoload($class) { + $file = "classes/".strtolower(basename($class)).".php"; + if (file_exists($file)) { + require $file; + } + } + $op = $_REQUEST["op"]; require_once "functions.php"; @@ -43,7 +50,7 @@ init_connection($link); - $method = $_REQUEST["method"]; + $method = strtolower($_REQUEST["method"]); $mode = $_REQUEST["mode"]; if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) { @@ -136,12 +143,19 @@ return; } - switch($op) { // Select action according to $op value. - case "rpc": - require_once "modules/backend-rpc.php"; - handle_rpc_request($link); - break; // rpc + if (class_exists($op)) { + $handler = new $op($link, $_REQUEST); + + if ($handler) { + if ($handler->before()) { + if (method_exists($handler, $method)) { + return $handler->$method(); + } + } + } + } + switch($op) { // Select action according to $op value. case "feeds": $method = $_REQUEST["method"]; $root = (bool)$_REQUEST["root"]; diff --git a/classes/handler.php b/classes/handler.php new file mode 100644 index 000000000..3bd82c725 --- /dev/null +++ b/classes/handler.php @@ -0,0 +1,15 @@ +link = $link; + $this->args = $args; + } + + function before() { + return true; + } +} +?> diff --git a/classes/rpc.php b/classes/rpc.php new file mode 100644 index 000000000..8f03381f8 --- /dev/null +++ b/classes/rpc.php @@ -0,0 +1,792 @@ +link, "DELETE FROM ttrss_settings_profiles WHERE id = '$id' AND + owner_uid = " . $_SESSION["uid"]); + } + } + } + + // Silent + function addprofile() { + $title = db_escape_string(trim($_REQUEST["title"])); + if ($title) { + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles + WHERE title = '$title' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + + db_query($this->link, "INSERT INTO ttrss_settings_profiles (title, owner_uid) + VALUES ('$title', ".$_SESSION["uid"] .")"); + + $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles WHERE + title = '$title'"); + + if (db_num_rows($result) != 0) { + $profile_id = db_fetch_result($result, 0, "id"); + + if ($profile_id) { + initialize_user_prefs($this->link, $_SESSION["uid"], $profile_id); + } + } + } + + db_query($this->link, "COMMIT"); + } + } + + // Silent + function saveprofile() { + $id = db_escape_string($_REQUEST["id"]); + $title = db_escape_string(trim($_REQUEST["value"])); + + if ($id == 0) { + print __("Default profile"); + return; + } + + if ($title) { + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT id FROM ttrss_settings_profiles + WHERE title = '$title' AND owner_uid =" . $_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + db_query($this->link, "UPDATE ttrss_settings_profiles + SET title = '$title' WHERE id = '$id' AND + owner_uid = " . $_SESSION["uid"]); + print $title; + } else { + $result = db_query($this->link, "SELECT title FROM ttrss_settings_profiles + WHERE id = '$id' AND owner_uid =" . $_SESSION["uid"]); + print db_fetch_result($result, 0, "title"); + } + + db_query($this->link, "COMMIT"); + } + } + + // Silent + function remarchive() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + $result = db_query($this->link, "DELETE FROM ttrss_archived_feeds WHERE + (SELECT COUNT(*) FROM ttrss_user_entries + WHERE orig_feed_id = '$id') = 0 AND + id = '$id' AND owner_uid = ".$_SESSION["uid"]); + + $rc = db_affected_rows($this->link, $result); + } + } + + function addfeed() { + $feed = db_escape_string($_REQUEST['feed']); + $cat = db_escape_string($_REQUEST['cat']); + $login = db_escape_string($_REQUEST['login']); + $pass = db_escape_string($_REQUEST['pass']); + + $rc = subscribe_to_feed($this->link, $feed, $cat, $login, $pass); + + print json_encode(array("result" => $rc)); + } + + function extractfeedurls() { + $urls = get_feeds_from_html($_REQUEST['url']); + + print json_encode(array("urls" => $urls)); + } + + function togglepref() { + $key = db_escape_string($_REQUEST["key"]); + set_pref($this->link, $key, !get_pref($this->link, $key)); + $value = get_pref($this->link, $key); + + print json_encode(array("param" =>$key, "value" => $value)); + } + + function setpref() { + $value = str_replace("\n", "
", $_REQUEST['value']); + + $key = db_escape_string($_REQUEST["key"]); + $value = db_escape_string($value); + + set_pref($this->link, $key, $value); + + print json_encode(array("param" =>$key, "value" => $value)); + } + + function mark() { + $mark = $_REQUEST["mark"]; + $id = db_escape_string($_REQUEST["id"]); + + if ($mark == "1") { + $mark = "true"; + } else { + $mark = "false"; + } + + $result = db_query($this->link, "UPDATE ttrss_user_entries SET marked = $mark + WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function delete() { + $ids = db_escape_string($_REQUEST["ids"]); + + $result = db_query($this->link, "DELETE FROM ttrss_user_entries + WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function unarchive() { + $ids = db_escape_string($_REQUEST["ids"]); + + $result = db_query($this->link, "UPDATE ttrss_user_entries + SET feed_id = orig_feed_id, orig_feed_id = NULL + WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function archive() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + archive_article($this->link, $id, $_SESSION["uid"]); + } + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function publ() { + $pub = $_REQUEST["pub"]; + $id = db_escape_string($_REQUEST["id"]); + $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); + + if ($pub == "1") { + $pub = "true"; + } else { + $pub = "false"; + } + + $result = db_query($this->link, "UPDATE ttrss_user_entries SET + published = $pub + WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + + $pubsub_result = false; + + if (PUBSUBHUBBUB_HUB) { + $rss_link = get_self_url_prefix() . + "/public.php?op=rss&id=-2&key=" . + get_feed_access_key($this->link, -2, false); + + $p = new Publisher(PUBSUBHUBBUB_HUB); + + $pubsub_result = $p->publish_update($rss_link); + } + + print json_encode(array("message" => "UPDATE_COUNTERS", + "pubsub_result" => $pubsub_result)); + } + + function getAllCounters() { + $last_article_id = (int) $_REQUEST["last_article_id"]; + + $reply = array(); + + if ($seq) $reply['seq'] = $seq; + + if ($last_article_id != getLastArticleId($this->link)) { + $omode = $_REQUEST["omode"]; + + if ($omode != "T") + $reply['counters'] = getAllCounters($this->link, $omode); + else + $reply['counters'] = getGlobalCounters($this->link); + } + + $reply['runtime-info'] = make_runtime_info($this->link); + + print json_encode($reply); + } + + /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ + function catchupSelected() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + $cmode = sprintf("%d", $_REQUEST["cmode"]); + + catchupArticlesById($this->link, $ids, $cmode); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function markSelected() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + $cmode = sprintf("%d", $_REQUEST["cmode"]); + + markArticlesById($this->link, $ids, $cmode); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function publishSelected() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + $cmode = sprintf("%d", $_REQUEST["cmode"]); + + publishArticlesById($this->link, $ids, $cmode); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function sanityCheck() { + $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; + + $reply = array(); + + $reply['error'] = sanity_check($this->link); + + if ($reply['error']['code'] == 0) { + $reply['init-params'] = make_init_params($this->link); + $reply['runtime-info'] = make_runtime_info($this->link); + } + + print json_encode($reply); + } + + function setArticleTags() { + global $memcache; + + $id = db_escape_string($_REQUEST["id"]); + + $tags_str = db_escape_string($_REQUEST["tags_str"]); + $tags = array_unique(trim_array(explode(",", $tags_str))); + + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT int_id FROM ttrss_user_entries WHERE + ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); + + if (db_num_rows($result) == 1) { + + $tags_to_cache = array(); + + $int_id = db_fetch_result($result, 0, "int_id"); + + db_query($this->link, "DELETE FROM ttrss_tags WHERE + post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); + + foreach ($tags as $tag) { + $tag = sanitize_tag($tag); + + if (!tag_is_valid($tag)) { + continue; + } + + if (preg_match("/^[0-9]*$/", $tag)) { + continue; + } + + // print ""; + + if ($tag != '') { + db_query($this->link, "INSERT INTO ttrss_tags + (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); + } + + array_push($tags_to_cache, $tag); + } + + /* update tag cache */ + + sort($tags_to_cache); + $tags_str = join(",", $tags_to_cache); + + db_query($this->link, "UPDATE ttrss_user_entries + SET tag_cache = '$tags_str' WHERE ref_id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + } + + db_query($this->link, "COMMIT"); + + if ($memcache) { + $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); + $memcache->delete($obj_id); + } + + $tags = get_article_tags($this->link, $id); + $tags_str = format_tags_string($tags, $id); + $tags_str_full = join(", ", $tags); + + if (!$tags_str_full) $tags_str_full = __("no tags"); + + print json_encode(array("tags_str" => array("id" => $id, + "content" => $tags_str, "content_full" => $tags_str_full))); + } + + function regenOPMLKey() { + update_feed_access_key($this->link, 'OPML:Publish', + false, $_SESSION["uid"]); + + $new_link = opml_publish_url($this->link); + + print json_encode(array("link" => $new_link)); + } + + function completeTags() { + $search = db_escape_string($_REQUEST["search"]); + + $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags + WHERE owner_uid = '".$_SESSION["uid"]."' AND + tag_name LIKE '$search%' ORDER BY tag_name + LIMIT 10"); + + print ""; + } + + function purge() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + $days = sprintf("%d", $_REQUEST["days"]); + + foreach ($ids as $id) { + + $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE + id = '$id' AND owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) == 1) { + purge_feed($this->link, $id, $days); + } + } + } + + function getArticles() { + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + $articles = array(); + + foreach ($ids as $id) { + if ($id) { + array_push($articles, format_article($this->link, $id, 0, false)); + } + } + + print json_encode($articles); + } + + function checkDate() { + $date = db_escape_string($_REQUEST["date"]); + $date_parsed = strtotime($date); + + print json_encode(array("result" => (bool)$date_parsed, + "date" => date("c", $date_parsed))); + } + + function assigntolabel() { + return labelops(true); + } + + function removefromlabel() { + return labelops(false); + } + + function labelops($assign) { + $reply = array(); + + $ids = explode(",", db_escape_string($_REQUEST["ids"])); + $label_id = db_escape_string($_REQUEST["lid"]); + + $label = db_escape_string(label_find_caption($this->link, $label_id, + $_SESSION["uid"])); + + $reply["info-for-headlines"] = array(); + + if ($label) { + + foreach ($ids as $id) { + + if ($assign) + label_add_article($this->link, $id, $label, $_SESSION["uid"]); + else + label_remove_article($this->link, $id, $label, $_SESSION["uid"]); + + $labels = get_article_labels($this->link, $id, $_SESSION["uid"]); + + array_push($reply["info-for-headlines"], + array("id" => $id, "labels" => format_article_labels($labels, $id))); + + } + } + + $reply["message"] = "UPDATE_COUNTERS"; + + print json_encode($reply); + } + + function updateFeedBrowser() { + $search = db_escape_string($_REQUEST["search"]); + $limit = db_escape_string($_REQUEST["limit"]); + $mode = (int) db_escape_string($_REQUEST["mode"]); + + print json_encode(array("content" => + make_feed_browser($this->link, $search, $limit, $mode), + "mode" => $mode)); + } + + // Silent + function massSubscribe() { + + $payload = json_decode($_REQUEST["payload"], false); + $mode = $_REQUEST["mode"]; + + if (!$payload || !is_array($payload)) return; + + if ($mode == 1) { + foreach ($payload as $feed) { + + $title = db_escape_string($feed[0]); + $feed_url = db_escape_string($feed[1]); + + $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE + feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + $result = db_query($this->link, "INSERT INTO ttrss_feeds + (owner_uid,feed_url,title,cat_id,site_url) + VALUES ('".$_SESSION["uid"]."', + '$feed_url', '$title', NULL, '')"); + } + } + } else if ($mode == 2) { + // feed archive + foreach ($payload as $id) { + $result = db_query($this->link, "SELECT * FROM ttrss_archived_feeds + WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); + $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); + $title = db_escape_string(db_fetch_result($result, 0, "title")); + + $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE + feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + $result = db_query($this->link, "INSERT INTO ttrss_feeds + (owner_uid,feed_url,title,cat_id,site_url) + VALUES ('$id','".$_SESSION["uid"]."', + '$feed_url', '$title', NULL, '$site_url')"); + } + } + } + } + } + + function digestgetcontents() { + $article_id = db_escape_string($_REQUEST['article_id']); + + $result = db_query($this->link, "SELECT content,title,link,marked,published + FROM ttrss_entries, ttrss_user_entries + WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']); + + $content = sanitize_rss($this->link, db_fetch_result($result, 0, "content")); + $title = strip_tags(db_fetch_result($result, 0, "title")); + $article_url = htmlspecialchars(db_fetch_result($result, 0, "link")); + $marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked")); + $published = sql_bool_to_bool(db_fetch_result($result, 0, "published")); + + print json_encode(array("article" => + array("id" => $article_id, "url" => $article_url, + "tags" => get_article_tags($this->link, $article_id), + "marked" => $marked, "published" => $published, + "title" => $title, "content" => $content))); + } + + function digestupdate() { + $feed_id = db_escape_string($_REQUEST['feed_id']); + $offset = db_escape_string($_REQUEST['offset']); + $seq = db_escape_string($_REQUEST['seq']); + + if (!$feed_id) $feed_id = -4; + if (!$offset) $offset = 0; + + $reply = array(); + + $reply['seq'] = $seq; + + $headlines = api_get_headlines($this->link, $feed_id, 30, $offset, + '', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0); + + $reply['headlines'] = array(); + $reply['headlines']['title'] = getFeedTitle($this->link, $feed_id); + $reply['headlines']['content'] = $headlines; + + print json_encode($reply); + } + + function digestinit() { + $tmp_feeds = api_get_feeds($this->link, -4, true, false, 0); + + $feeds = array(); + + foreach ($tmp_feeds as $f) { + if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); + } + + print json_encode(array("feeds" => $feeds)); + } + + function catchupFeed() { + $feed_id = db_escape_string($_REQUEST['feed_id']); + $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; + + catchup_feed($this->link, $feed_id, $is_cat); + + print json_encode(array("message" => "UPDATE_COUNTERS")); + } + + function sendEmail() { + $secretkey = $_REQUEST['secretkey']; + + require_once 'lib/phpmailer/class.phpmailer.php'; + + $reply = array(); + + if (DIGEST_ENABLE && $_SESSION['email_secretkey'] && + $secretkey == $_SESSION['email_secretkey']) { + + $_SESSION['email_secretkey'] = ''; + + $destination = $_REQUEST['destination']; + $subject = $_REQUEST['subject']; + $content = $_REQUEST['content']; + + $replyto = strip_tags($_SESSION['email_replyto']); + $fromname = strip_tags($_SESSION['email_fromname']); + + $mail = new PHPMailer(); + + $mail->PluginDir = "lib/phpmailer/"; + $mail->SetLanguage("en", "lib/phpmailer/language/"); + + $mail->CharSet = "UTF-8"; + + $mail->From = $replyto; + $mail->FromName = $fromname; + $mail->AddAddress($destination); + + if (DIGEST_SMTP_HOST) { + $mail->Host = DIGEST_SMTP_HOST; + $mail->Mailer = "smtp"; + $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; + $mail->Username = DIGEST_SMTP_LOGIN; + $mail->Password = DIGEST_SMTP_PASSWORD; + } + + $mail->IsHTML(false); + $mail->Subject = $subject; + $mail->Body = $content; + + $rc = $mail->Send(); + + if (!$rc) { + $reply['error'] = $mail->ErrorInfo; + } else { + save_email_address($this->link, db_escape_string($destination)); + $reply['message'] = "UPDATE_COUNTERS"; + } + + } else { + $reply['error'] = "Not authorized."; + } + + print json_encode($reply); + } + + function completeEmails() { + $search = db_escape_string($_REQUEST["search"]); + + print ""; + } + + function quickAddCat() { + $cat = db_escape_string($_REQUEST["cat"]); + + add_feed_category($this->link, $cat); + + $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE + title = '$cat' AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) == 1) { + $id = db_fetch_result($result, 0, "id"); + } else { + $id = 0; + } + + print_feed_cat_select($this->link, "cat_id", $id); + } + + function regenFeedKey() { + $feed_id = db_escape_string($_REQUEST['id']); + $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; + + $new_key = update_feed_access_key($this->link, $feed_id, $is_cat); + + print json_encode(array("link" => $new_key)); + } + + // Silent + function clearKeys() { + db_query($this->link, "DELETE FROM ttrss_access_keys WHERE + owner_uid = " . $_SESSION["uid"]); + } + + // Silent + function clearArticleKeys() { + db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '' WHERE + owner_uid = " . $_SESSION["uid"]); + + return; + } + + + function verifyRegexp() { + $reg_exp = $_REQUEST["reg_exp"]; + + $status = @preg_match("/$reg_exp/i", "TEST") !== false; + + print json_encode(array("status" => $status)); + } + + // TODO: unify with digest-get-contents? + function cdmGetArticle() { + $ids = array(db_escape_string($_REQUEST["id"])); + $cids = explode(",", $_REQUEST["cids"]); + + $ids = array_merge($ids, $cids); + + $rv = array(); + + foreach ($ids as $id) { + $id = (int)$id; + + $result = db_query($this->link, "SELECT content, + ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds, + ttrss_entries + WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND + ttrss_entries.id = ref_id AND + ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $line = db_fetch_assoc($result); + + $article_content = sanitize_rss($this->link, $line["content"], + false, false, $line['site_url']); + + array_push($rv, + array("id" => $id, "content" => $article_content)); + } + } + + print json_encode($rv); + } + + function scheduleFeedUpdate() { + $feed_id = db_escape_string($_REQUEST["id"]); + $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true'; + + $message = __("Your request could not be completed."); + + if ($feed_id >= 0) { + if (!$is_cat) { + $message = __("Feed update has been scheduled."); + + db_query($this->link, "UPDATE ttrss_feeds SET + last_update_started = '1970-01-01', + last_updated = '1970-01-01' WHERE id = '$feed_id' AND + owner_uid = ".$_SESSION["uid"]); + + } else { + $message = __("Category update has been scheduled."); + + if ($feed_id) + $cat_query = "cat_id = '$feed_id'"; + else + $cat_query = "cat_id IS NULL"; + + db_query($this->link, "UPDATE ttrss_feeds SET + last_update_started = '1970-01-01', + last_updated = '1970-01-01' WHERE $cat_query AND + owner_uid = ".$_SESSION["uid"]); + } + } else { + $message = __("Can't update this kind of feed."); + } + + print json_encode(array("message" => $message)); + return; + } + + function getTweetInfo() { + $id = db_escape_string($_REQUEST['id']); + + $result = db_query($this->link, "SELECT title, link + FROM ttrss_entries, ttrss_user_entries + WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']); + + if (db_num_rows($result) != 0) { + $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), + 100, '...'); + $article_link = db_fetch_result($result, 0, 'link'); + } + + print json_encode(array("title" => $title, "link" => $article_link, + "id" => $id)); + } + + function setNote() { + $id = db_escape_string($_REQUEST["id"]); + $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); + + db_query($this->link, "UPDATE ttrss_user_entries SET note = '$note' + WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); + + $formatted_note = format_article_note($id, $note); + + print json_encode(array("note" => $formatted_note, + "raw_length" => mb_strlen($note))); + } + + function genHash() { + $hash = sha1(uniqid(rand(), true)); + + print json_encode(array("hash" => $hash)); + } +} +?> diff --git a/js/digest.js b/js/digest.js index c1cbf8762..fc0446d83 100644 --- a/js/digest.js +++ b/js/digest.js @@ -169,7 +169,7 @@ function update(callback) { window.clearTimeout(_update_timeout); new Ajax.Request("backend.php", { - parameters: "?op=rpc&method=digest-init", + parameters: "?op=rpc&method=digestinit", onComplete: function(transport) { fatal_error_check(transport); parse_feeds(transport); @@ -220,7 +220,7 @@ function view(article_id) { }, 500); new Ajax.Request("backend.php", { - parameters: "?op=rpc&method=digest-get-contents&article_id=" + + parameters: "?op=rpc&method=digestgetcontents&article_id=" + article_id, onComplete: function(transport) { fatal_error_check(transport); @@ -315,14 +315,14 @@ function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback) if (!offset) $("headlines").scrollTop = 0; - var query = "backend.php?op=rpc&method=digest-update&feed_id=" + + var query = "backend.php?op=rpc&method=digestupdate&feed_id=" + param_escape(feed_id) + "&offset=" + offset + "&seq=" + _update_seq; console.log(query); var img = false; - + if ($("F-" + feed_id)) { img = $("F-" + feed_id).getElementsByTagName("IMG")[0]; @@ -648,7 +648,7 @@ function parse_headlines(transport, replace, no_effects) { function init_second_stage() { try { new Ajax.Request("backend.php", { - parameters: "backend.php?op=rpc&method=digest-init", + parameters: "backend.php?op=rpc&method=digestinit", onComplete: function(transport) { parse_feeds(transport); Element.hide("overlay"); diff --git a/modules/backend-rpc.php b/modules/backend-rpc.php deleted file mode 100644 index 341353480..000000000 --- a/modules/backend-rpc.php +++ /dev/null @@ -1,911 +0,0 @@ - $rc)); - - return; - - } - - if ($method == "extractfeedurls") { - - $urls = get_feeds_from_html($_REQUEST['url']); - - print json_encode(array("urls" => $urls)); - return; - } - - if ($method == "togglepref") { - $key = db_escape_string($_REQUEST["key"]); - set_pref($link, $key, !get_pref($link, $key)); - $value = get_pref($link, $key); - - print json_encode(array("param" =>$key, "value" => $value)); - return; - } - - if ($method == "setpref") { - $value = str_replace("\n", "
", $_REQUEST['value']); - - $key = db_escape_string($_REQUEST["key"]); - $value = db_escape_string($value); - - set_pref($link, $key, $value); - - print json_encode(array("param" =>$key, "value" => $value)); - return; - } - - if ($method == "mark") { - $mark = $_REQUEST["mark"]; - $id = db_escape_string($_REQUEST["id"]); - - if ($mark == "1") { - $mark = "true"; - } else { - $mark = "false"; - } - - $result = db_query($link, "UPDATE ttrss_user_entries SET marked = $mark - WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "delete") { - $ids = db_escape_string($_REQUEST["ids"]); - - $result = db_query($link, "DELETE FROM ttrss_user_entries - WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "unarchive") { - $ids = db_escape_string($_REQUEST["ids"]); - - $result = db_query($link, "UPDATE ttrss_user_entries - SET feed_id = orig_feed_id, orig_feed_id = NULL - WHERE ref_id IN ($ids) AND owner_uid = " . $_SESSION["uid"]); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "archive") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - - foreach ($ids as $id) { - archive_article($link, $id, $_SESSION["uid"]); - } - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "publ") { - $pub = $_REQUEST["pub"]; - $id = db_escape_string($_REQUEST["id"]); - $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); - - if ($pub == "1") { - $pub = "true"; - } else { - $pub = "false"; - } - - $result = db_query($link, "UPDATE ttrss_user_entries SET - published = $pub - WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); - - $pubsub_result = false; - - if (PUBSUBHUBBUB_HUB) { - $rss_link = get_self_url_prefix() . - "/public.php?op=rss&id=-2&key=" . - get_feed_access_key($link, -2, false); - - $p = new Publisher(PUBSUBHUBBUB_HUB); - - $pubsub_result = $p->publish_update($rss_link); - } - - print json_encode(array("message" => "UPDATE_COUNTERS", - "pubsub_result" => $pubsub_result)); - return; - } - - // Silent - /* if ($method == "update") { - $feed_id = db_escape_string($_REQUEST["feed"]); - update_rss_feed($link, $feed_id); - return; - } */ - - if ($method == "updateAllFeeds" || $method == "getAllCounters") { - $last_article_id = (int) $_REQUEST["last_article_id"]; - - $reply = array(); - - if ($seq) $reply['seq'] = $seq; - - if ($last_article_id != getLastArticleId($link)) { - $omode = $_REQUEST["omode"]; - - if ($omode != "T") - $reply['counters'] = getAllCounters($link, $omode); - else - $reply['counters'] = getGlobalCounters($link); - } - - $reply['runtime-info'] = make_runtime_info($link); - - - print json_encode($reply); - return; - } - - /* GET["cmode"] = 0 - mark as read, 1 - as unread, 2 - toggle */ - if ($method == "catchupSelected") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $cmode = sprintf("%d", $_REQUEST["cmode"]); - - catchupArticlesById($link, $ids, $cmode); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "markSelected") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $cmode = sprintf("%d", $_REQUEST["cmode"]); - - markArticlesById($link, $ids, $cmode); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "publishSelected") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $cmode = sprintf("%d", $_REQUEST["cmode"]); - - publishArticlesById($link, $ids, $cmode); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "sanityCheck") { - $_SESSION["hasAudio"] = $_REQUEST["hasAudio"] === "true"; - - $reply = array(); - - $reply['error'] = sanity_check($link); - - if ($reply['error']['code'] == 0) { - $reply['init-params'] = make_init_params($link); - $reply['runtime-info'] = make_runtime_info($link); - } - - print json_encode($reply); - return; - } - - if ($method == "setArticleTags") { - global $memcache; - - $id = db_escape_string($_REQUEST["id"]); - - $tags_str = db_escape_string($_REQUEST["tags_str"]); - $tags = array_unique(trim_array(explode(",", $tags_str))); - - db_query($link, "BEGIN"); - - $result = db_query($link, "SELECT int_id FROM ttrss_user_entries WHERE - ref_id = '$id' AND owner_uid = '".$_SESSION["uid"]."' LIMIT 1"); - - if (db_num_rows($result) == 1) { - - $tags_to_cache = array(); - - $int_id = db_fetch_result($result, 0, "int_id"); - - db_query($link, "DELETE FROM ttrss_tags WHERE - post_int_id = $int_id AND owner_uid = '".$_SESSION["uid"]."'"); - - foreach ($tags as $tag) { - $tag = sanitize_tag($tag); - - if (!tag_is_valid($tag)) { - continue; - } - - if (preg_match("/^[0-9]*$/", $tag)) { - continue; - } - -// print ""; - - if ($tag != '') { - db_query($link, "INSERT INTO ttrss_tags - (post_int_id, owner_uid, tag_name) VALUES ('$int_id', '".$_SESSION["uid"]."', '$tag')"); - } - - array_push($tags_to_cache, $tag); - } - - /* update tag cache */ - - sort($tags_to_cache); - $tags_str = join(",", $tags_to_cache); - - db_query($link, "UPDATE ttrss_user_entries - SET tag_cache = '$tags_str' WHERE ref_id = '$id' - AND owner_uid = " . $_SESSION["uid"]); - } - - db_query($link, "COMMIT"); - - if ($memcache) { - $obj_id = md5("TAGS:".$_SESSION["uid"].":$id"); - $memcache->delete($obj_id); - } - - $tags = get_article_tags($link, $id); - $tags_str = format_tags_string($tags, $id); - $tags_str_full = join(", ", $tags); - - if (!$tags_str_full) $tags_str_full = __("no tags"); - - print json_encode(array("tags_str" => array("id" => $id, - "content" => $tags_str, "content_full" => $tags_str_full))); - - return; - } - - if ($method == "regenOPMLKey") { - update_feed_access_key($link, 'OPML:Publish', - false, $_SESSION["uid"]); - - $new_link = opml_publish_url($link); - - print json_encode(array("link" => $new_link)); - return; - } - - if ($method == "completeTags") { - $search = db_escape_string($_REQUEST["search"]); - - $result = db_query($link, "SELECT DISTINCT tag_name FROM ttrss_tags - WHERE owner_uid = '".$_SESSION["uid"]."' AND - tag_name LIKE '$search%' ORDER BY tag_name - LIMIT 10"); - - print ""; - - return; - } - - if ($method == "purge") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $days = sprintf("%d", $_REQUEST["days"]); - - foreach ($ids as $id) { - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - id = '$id' AND owner_uid = ".$_SESSION["uid"]); - - if (db_num_rows($result) == 1) { - purge_feed($link, $id, $days); - } - } - - return; - } - -/* if ($method == "setScore") { - $id = db_escape_string($_REQUEST["id"]); - $score = sprintf("%d", $_REQUEST["score"]); - - $result = db_query($link, "UPDATE ttrss_user_entries SET score = '$score' - WHERE ref_id = '$id' AND owner_uid = ".$_SESSION["uid"]); - - print "Acknowledged."; - - return; - - } */ - - if ($method == "getArticles") { - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $articles = array(); - - foreach ($ids as $id) { - if ($id) { - array_push($articles, format_article($link, $id, 0, false)); - } - } - - print json_encode($articles); - return; - } - - if ($method == "checkDate") { - $date = db_escape_string($_REQUEST["date"]); - $date_parsed = strtotime($date); - - print json_encode(array("result" => (bool)$date_parsed, - "date" => date("c", $date_parsed))); - return; - } - - if ($method == "assignToLabel" || $method == "removeFromLabel") { - $reply = array(); - - $ids = explode(",", db_escape_string($_REQUEST["ids"])); - $label_id = db_escape_string($_REQUEST["lid"]); - - $label = db_escape_string(label_find_caption($link, $label_id, - $_SESSION["uid"])); - - $reply["info-for-headlines"] = array(); - - if ($label) { - - foreach ($ids as $id) { - - if ($method == "assignToLabel") - label_add_article($link, $id, $label, $_SESSION["uid"]); - else - label_remove_article($link, $id, $label, $_SESSION["uid"]); - - $labels = get_article_labels($link, $id, $_SESSION["uid"]); - - array_push($reply["info-for-headlines"], - array("id" => $id, "labels" => format_article_labels($labels, $id))); - - } - } - - $reply["message"] = "UPDATE_COUNTERS"; - - print json_encode($reply); - - return; - } - - if ($method == "updateFeedBrowser") { - $search = db_escape_string($_REQUEST["search"]); - $limit = db_escape_string($_REQUEST["limit"]); - $mode = (int) db_escape_string($_REQUEST["mode"]); - - print json_encode(array("content" => - make_feed_browser($link, $search, $limit, $mode), - "mode" => $mode)); - return; - } - - // Silent - if ($method == "massSubscribe") { - - $payload = json_decode($_REQUEST["payload"], false); - $mode = $_REQUEST["mode"]; - - if (!$payload || !is_array($payload)) return; - - if ($mode == 1) { - foreach ($payload as $feed) { - - $title = db_escape_string($feed[0]); - $feed_url = db_escape_string($feed[1]); - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); - - if (db_num_rows($result) == 0) { - $result = db_query($link, "INSERT INTO ttrss_feeds - (owner_uid,feed_url,title,cat_id,site_url) - VALUES ('".$_SESSION["uid"]."', - '$feed_url', '$title', NULL, '')"); - } - } - } else if ($mode == 2) { - // feed archive - foreach ($payload as $id) { - $result = db_query($link, "SELECT * FROM ttrss_archived_feeds - WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); - - if (db_num_rows($result) != 0) { - $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); - $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); - $title = db_escape_string(db_fetch_result($result, 0, "title")); - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); - - if (db_num_rows($result) == 0) { - $result = db_query($link, "INSERT INTO ttrss_feeds - (owner_uid,feed_url,title,cat_id,site_url) - VALUES ('$id','".$_SESSION["uid"]."', - '$feed_url', '$title', NULL, '$site_url')"); - } - } - } - } - -/* $ids = explode(",", db_escape_string($_REQUEST["ids"])); - - $subscribed = array(); - - foreach ($ids as $id) { - - if ($mode == 1) { - $result = db_query($link, "SELECT feed_url,title FROM ttrss_feeds - WHERE id = '$id'"); - } else if ($mode == 2) { - $result = db_query($link, "SELECT * FROM ttrss_archived_feeds - WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); - $orig_id = db_escape_string(db_fetch_result($result, 0, "id")); - $site_url = db_escape_string(db_fetch_result($result, 0, "site_url")); - } - - $feed_url = db_escape_string(db_fetch_result($result, 0, "feed_url")); - $title = db_escape_string(db_fetch_result($result, 0, "title")); - - $title_orig = db_fetch_result($result, 0, "title"); - - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); - - if (db_num_rows($result) == 0) { - if ($mode == 1) { - $result = db_query($link, - "INSERT INTO ttrss_feeds (owner_uid,feed_url,title,cat_id) - VALUES ('".$_SESSION["uid"]."', '$feed_url', '$title', NULL)"); - } else if ($mode == 2) { - $result = db_query($link, - "INSERT INTO ttrss_feeds (id,owner_uid,feed_url,title,cat_id,site_url) - VALUES ('$orig_id','".$_SESSION["uid"]."', '$feed_url', '$title', NULL, '$site_url')"); - } - array_push($subscribed, $title_orig); - } - } */ - - return; - } - - if ($method == "digest-get-contents") { - $article_id = db_escape_string($_REQUEST['article_id']); - - $result = db_query($link, "SELECT content,title,link,marked,published - FROM ttrss_entries, ttrss_user_entries - WHERE id = '$article_id' AND ref_id = id AND owner_uid = ".$_SESSION['uid']); - - $content = sanitize_rss($link, db_fetch_result($result, 0, "content")); - $title = strip_tags(db_fetch_result($result, 0, "title")); - $article_url = htmlspecialchars(db_fetch_result($result, 0, "link")); - $marked = sql_bool_to_bool(db_fetch_result($result, 0, "marked")); - $published = sql_bool_to_bool(db_fetch_result($result, 0, "published")); - - - print json_encode(array("article" => - array("id" => $article_id, "url" => $article_url, - "tags" => get_article_tags($link, $article_id), - "marked" => $marked, "published" => $published, - "title" => $title, "content" => $content))); - return; - } - - if ($method == "digest-update") { - $feed_id = db_escape_string($_REQUEST['feed_id']); - $offset = db_escape_string($_REQUEST['offset']); - $seq = db_escape_string($_REQUEST['seq']); - - if (!$feed_id) $feed_id = -4; - if (!$offset) $offset = 0; - - $reply = array(); - - $reply['seq'] = $seq; - - $headlines = api_get_headlines($link, $feed_id, 30, $offset, - '', ($feed_id == -4), true, false, "unread", "updated DESC", 0, 0); - - //function api_get_headlines($link, $feed_id, $limit, $offset, - // $filter, $is_cat, $show_excerpt, $show_content, $view_mode) { - - $reply['headlines'] = array(); - $reply['headlines']['title'] = getFeedTitle($link, $feed_id); - $reply['headlines']['content'] = $headlines; - - print json_encode($reply); - return; - } - - if ($method == "digest-init") { - $tmp_feeds = api_get_feeds($link, -4, true, false, 0); - - $feeds = array(); - - foreach ($tmp_feeds as $f) { - if ($f['id'] > 0 || $f['id'] == -4) array_push($feeds, $f); - } - - print json_encode(array("feeds" => $feeds)); - - return; - } - - if ($method == "catchupFeed") { - $feed_id = db_escape_string($_REQUEST['feed_id']); - $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; - - catchup_feed($link, $feed_id, $is_cat); - - print json_encode(array("message" => "UPDATE_COUNTERS")); - return; - } - - if ($method == "sendEmail") { - $secretkey = $_REQUEST['secretkey']; - - require_once 'lib/phpmailer/class.phpmailer.php'; - - $reply = array(); - - if (DIGEST_ENABLE && $_SESSION['email_secretkey'] && - $secretkey == $_SESSION['email_secretkey']) { - - $_SESSION['email_secretkey'] = ''; - - $destination = $_REQUEST['destination']; - $subject = $_REQUEST['subject']; - $content = $_REQUEST['content']; - - $replyto = strip_tags($_SESSION['email_replyto']); - $fromname = strip_tags($_SESSION['email_fromname']); - - $mail = new PHPMailer(); - - $mail->PluginDir = "lib/phpmailer/"; - $mail->SetLanguage("en", "lib/phpmailer/language/"); - - $mail->CharSet = "UTF-8"; - - $mail->From = $replyto; - $mail->FromName = $fromname; - $mail->AddAddress($destination); - - if (DIGEST_SMTP_HOST) { - $mail->Host = DIGEST_SMTP_HOST; - $mail->Mailer = "smtp"; - $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; - $mail->Username = DIGEST_SMTP_LOGIN; - $mail->Password = DIGEST_SMTP_PASSWORD; - } - - $mail->IsHTML(false); - $mail->Subject = $subject; - $mail->Body = $content; - - $rc = $mail->Send(); - - if (!$rc) { - $reply['error'] = $mail->ErrorInfo; - } else { - save_email_address($link, db_escape_string($destination)); - $reply['message'] = "UPDATE_COUNTERS"; - } - - } else { - $reply['error'] = "Not authorized."; - } - - print json_encode($reply); - return; - } - - if ($method == "completeEmails") { - $search = db_escape_string($_REQUEST["search"]); - - print ""; - - return; - } - - if ($method == "quickAddCat") { - $cat = db_escape_string($_REQUEST["cat"]); - - add_feed_category($link, $cat); - - $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE - title = '$cat' AND owner_uid = " . $_SESSION["uid"]); - - if (db_num_rows($result) == 1) { - $id = db_fetch_result($result, 0, "id"); - } else { - $id = 0; - } - - print_feed_cat_select($link, "cat_id", $id); - - return; - } - - if ($method == "regenFeedKey") { - $feed_id = db_escape_string($_REQUEST['id']); - $is_cat = db_escape_string($_REQUEST['is_cat']) == "true"; - - $new_key = update_feed_access_key($link, $feed_id, $is_cat); - - print json_encode(array("link" => $new_key)); - return; - } - - // Silent - if ($method == "clearKeys") { - db_query($link, "DELETE FROM ttrss_access_keys WHERE - owner_uid = " . $_SESSION["uid"]); - - return; - } - - // Silent - if ($method == "clearArticleKeys") { - db_query($link, "UPDATE ttrss_user_entries SET uuid = '' WHERE - owner_uid = " . $_SESSION["uid"]); - - return; - } - - - if ($method == "verifyRegexp") { - $reg_exp = $_REQUEST["reg_exp"]; - - $status = @preg_match("/$reg_exp/i", "TEST") !== false; - - print json_encode(array("status" => $status)); - return; - } - - // TODO: unify with digest-get-contents? - if ($method == "cdmGetArticle") { - $ids = array(db_escape_string($_REQUEST["id"])); - $cids = explode(",", $_REQUEST["cids"]); - - $ids = array_merge($ids, $cids); - - $rv = array(); - - foreach ($ids as $id) { - $id = (int)$id; - - $result = db_query($link, "SELECT content, - ttrss_feeds.site_url AS site_url FROM ttrss_user_entries, ttrss_feeds, - ttrss_entries - WHERE feed_id = ttrss_feeds.id AND ref_id = '$id' AND - ttrss_entries.id = ref_id AND - ttrss_user_entries.owner_uid = ".$_SESSION["uid"]); - - if (db_num_rows($result) != 0) { - $line = db_fetch_assoc($result); - - $article_content = sanitize_rss($link, $line["content"], - false, false, $line['site_url']); - - array_push($rv, - array("id" => $id, "content" => $article_content)); - } - } - - print json_encode($rv); - - return; - } - - if ($method == "scheduleFeedUpdate") { - $feed_id = db_escape_string($_REQUEST["id"]); - $is_cat = db_escape_string($_REQUEST['is_cat']) == 'true'; - - $message = __("Your request could not be completed."); - - if ($feed_id >= 0) { - if (!$is_cat) { - $message = __("Feed update has been scheduled."); - - db_query($link, "UPDATE ttrss_feeds SET - last_update_started = '1970-01-01', - last_updated = '1970-01-01' WHERE id = '$feed_id' AND - owner_uid = ".$_SESSION["uid"]); - - } else { - $message = __("Category update has been scheduled."); - - if ($feed_id) - $cat_query = "cat_id = '$feed_id'"; - else - $cat_query = "cat_id IS NULL"; - - db_query($link, "UPDATE ttrss_feeds SET - last_update_started = '1970-01-01', - last_updated = '1970-01-01' WHERE $cat_query AND - owner_uid = ".$_SESSION["uid"]); - } - } else { - $message = __("Can't update this kind of feed."); - } - - print json_encode(array("message" => $message)); - return; - } - - if ($method == "getTweetInfo") { - $id = db_escape_string($_REQUEST['id']); - - $result = db_query($link, "SELECT title, link - FROM ttrss_entries, ttrss_user_entries - WHERE id = '$id' AND ref_id = id AND owner_uid = " .$_SESSION['uid']); - - if (db_num_rows($result) != 0) { - $title = truncate_string(strip_tags(db_fetch_result($result, 0, 'title')), - 100, '...'); - $article_link = db_fetch_result($result, 0, 'link'); - } - - print json_encode(array("title" => $title, "link" => $article_link, - "id" => $id)); - - return; - } - - if ($method == "setNote") { - $id = db_escape_string($_REQUEST["id"]); - $note = trim(strip_tags(db_escape_string($_REQUEST["note"]))); - - db_query($link, "UPDATE ttrss_user_entries SET note = '$note' - WHERE ref_id = '$id' AND owner_uid = " . $_SESSION["uid"]); - - $formatted_note = format_article_note($id, $note); - - print json_encode(array("note" => $formatted_note, - "raw_length" => mb_strlen($note))); - return; - } - - if ($method == "genHash") { - $hash = sha1(uniqid(rand(), true)); - - print json_encode(array("hash" => $hash)); - return; - } - - print json_encode(array("error" => array("code" => 7, - "message" => "Unknown method: $method"))); - } -?> -- cgit v1.2.3-54-g00ecf From 3f3630529e1e7a0adf2ce0022596006cfcba0089 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 00:20:53 +0400 Subject: implement tiny-OOP routing --- backend.php | 275 +----------- classes/article.php | 63 +++ classes/dlg.php | 1089 ++++++++++++++++++++++++++++++++++++++++++++ classes/feeds.php | 187 ++++++++ classes/handler.php | 4 + js/feedlist.js | 4 +- js/functions.js | 10 +- js/prefs.js | 8 +- js/tt-rss.js | 6 +- js/viewfeed.js | 12 +- modules/popup-dialog.php | 1122 ---------------------------------------------- public.php | 3 +- 12 files changed, 1375 insertions(+), 1408 deletions(-) create mode 100644 classes/article.php create mode 100644 classes/dlg.php create mode 100644 classes/feeds.php delete mode 100644 modules/popup-dialog.php (limited to 'js') diff --git a/backend.php b/backend.php index c9eed0e9a..9e6da8d20 100644 --- a/backend.php +++ b/backend.php @@ -53,11 +53,13 @@ $method = strtolower($_REQUEST["method"]); $mode = $_REQUEST["mode"]; - if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) { + /* if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) { header("Content-Type: application/xml; charset=utf-8"); } else { header("Content-Type: text/plain; charset=utf-8"); - } + } */ + + header("Content-Type: text/plain; charset=utf-8"); if (ENABLE_GZIP_OUTPUT) { ob_start("ob_gzhandler"); @@ -134,8 +136,6 @@ 5 => __("Power User"), 10 => __("Administrator")); - - $error = sanity_check($link); if ($error['code'] != 0 && $op != "logout") { @@ -148,268 +148,18 @@ if ($handler) { if ($handler->before()) { - if (method_exists($handler, $method)) { - return $handler->$method(); + if ($method && method_exists($handler, $method)) { + $handler->$method(); + } else if (method_exists($handler, 'index')) { + $handler->index(); } + $handler->after(); + return; } } } switch($op) { // Select action according to $op value. - case "feeds": - $method = $_REQUEST["method"]; - $root = (bool)$_REQUEST["root"]; - - switch($method) { - case "catchupAll": - db_query($link, "UPDATE ttrss_user_entries SET - last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); - ccache_zero_all($link, $_SESSION["uid"]); - - break; - - case "collapse": - $cat_id = db_escape_string($_REQUEST["cid"]); - $mode = (int) db_escape_string($_REQUEST['mode']); - toggle_collapse_cat($link, $cat_id, $mode); - return; - break; - } - - if (!$root) { - print json_encode(outputFeedList($link)); - } else { - - $feeds = outputFeedList($link, false); - - $root = array(); - $root['id'] = 'root'; - $root['name'] = __('Feeds'); - $root['items'] = $feeds['items']; - - $fl = array(); - $fl['identifier'] = 'id'; - $fl['label'] = 'name'; - $fl['items'] = array($root); - - print json_encode($fl); - } - - break; // feeds - - case "la": - $id = db_escape_string($_REQUEST['id']); - - $result = db_query($link, "SELECT link FROM ttrss_entries, ttrss_user_entries - WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' - LIMIT 1"); - - if (db_num_rows($result) == 1) { - $article_url = db_fetch_result($result, 0, 'link'); - $article_url = str_replace("\n", "", $article_url); - - header("Location: $article_url"); - return; - - } else { - print_error(__("Article not found.")); - } - break; - - case "view": - - $id = db_escape_string($_REQUEST["id"]); - $cids = explode(",", db_escape_string($_REQUEST["cids"])); - $mode = db_escape_string($_REQUEST["mode"]); - $omode = db_escape_string($_REQUEST["omode"]); - - // in prefetch mode we only output requested cids, main article - // just gets marked as read (it already exists in client cache) - - $articles = array(); - - if ($mode == "") { - array_push($articles, format_article($link, $id, false)); - } else if ($mode == "zoom") { - array_push($articles, format_article($link, $id, true, true)); - } else if ($mode == "raw") { - if ($_REQUEST['html']) { - header("Content-Type: text/html"); - print ''; - } - - $article = format_article($link, $id, false); - print $article['content']; - return; - } - - catchupArticleById($link, $id, 0); - - if (!$_SESSION["bw_limit"]) { - foreach ($cids as $cid) { - if ($cid) { - array_push($articles, format_article($link, $cid, false, false)); - } - } - } - - print json_encode($articles); - - break; // view - - case "viewfeed": - - $timing_info = getmicrotime(); - - $reply = array(); - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); - - $omode = db_escape_string($_REQUEST["omode"]); - - $feed = db_escape_string($_REQUEST["feed"]); - $method = db_escape_string($_REQUEST["method"]); - $view_mode = db_escape_string($_REQUEST["view_mode"]); - $limit = (int) get_pref($link, "DEFAULT_ARTICLE_LIMIT"); - @$cat_view = db_escape_string($_REQUEST["cat"]) == "true"; - @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); - @$offset = db_escape_string($_REQUEST["skip"]); - @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); - $order_by = db_escape_string($_REQUEST["order_by"]); - - if (is_numeric($feed)) $feed = (int) $feed; - - /* Feed -5 is a special case: it is used to display auxiliary information - * when there's nothing to load - e.g. no stuff in fresh feed */ - - if ($feed == -5) { - print json_encode(generate_dashboard_feed($link)); - return; - } - - $result = false; - - if ($feed < -10) { - $label_feed = -11-$feed; - $result = db_query($link, "SELECT id FROM ttrss_labels2 WHERE - id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); - } else if (!$cat_view && is_numeric($feed) && $feed > 0) { - $result = db_query($link, "SELECT id FROM ttrss_feeds WHERE - id = '$feed' AND owner_uid = " . $_SESSION['uid']); - } else if ($cat_view && is_numeric($feed) && $feed > 0) { - $result = db_query($link, "SELECT id FROM ttrss_feed_categories WHERE - id = '$feed' AND owner_uid = " . $_SESSION['uid']); - } - - if ($result && db_num_rows($result) == 0) { - print json_encode(generate_error_feed($link, __("Feed not found."))); - return; - } - - /* Updating a label ccache means recalculating all of the caches - * so for performance reasons we don't do that here */ - - if ($feed >= 0) { - ccache_update($link, $feed, $_SESSION["uid"], $cat_view); - } - - set_pref($link, "_DEFAULT_VIEW_MODE", $view_mode); - set_pref($link, "_DEFAULT_VIEW_LIMIT", $limit); - set_pref($link, "_DEFAULT_VIEW_ORDER_BY", $order_by); - - if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { - db_query($link, "UPDATE ttrss_feeds SET last_viewed = NOW() - WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); - } - - $reply['headlines'] = array(); - - if (!$next_unread_feed) - $reply['headlines']['id'] = $feed; - else - $reply['headlines']['id'] = $next_unread_feed; - - $reply['headlines']['is_cat'] = (bool) $cat_view; - - $override_order = false; - - if (get_pref($link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { - $date_sort_field = "updated"; - } else { - $date_sort_field = "date_entered"; - } - - switch ($order_by) { - case "date": - if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "$date_sort_field"; - } else { - $override_order = "$date_sort_field DESC"; - } - break; - - case "title": - if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "title DESC, $date_sort_field"; - } else { - $override_order = "title, $date_sort_field DESC"; - } - break; - - case "score": - if (get_pref($link, 'REVERSE_HEADLINES', $owner_uid)) { - $override_order = "score, $date_sort_field"; - } else { - $override_order = "score DESC, $date_sort_field DESC"; - } - break; - } - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); - - $ret = format_headlines_list($link, $feed, $method, - $view_mode, $limit, $cat_view, $next_unread_feed, $offset, - $vgroup_last_feed, $override_order); - - $topmost_article_ids = $ret[0]; - $headlines_count = $ret[1]; - $returned_feed = $ret[2]; - $disable_cache = $ret[3]; - $vgroup_last_feed = $ret[4]; - -// if ($_REQUEST["debug"]) print_r($ret); - - $reply['headlines']['content'] =& $ret[5]['content']; - $reply['headlines']['toolbar'] =& $ret[5]['toolbar']; - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); - - $reply['headlines-info'] = array("count" => (int) $headlines_count, - "vgroup_last_feed" => $vgroup_last_feed, - "disable_cache" => (bool) $disable_cache); - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); - - if (is_array($topmost_article_ids) && !get_pref($link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { - $articles = array(); - - foreach ($topmost_article_ids as $id) { - array_push($articles, format_article($link, $id, false)); - } - - $reply['articles'] = $articles; - } - -// if ($method) { -// $reply['counters'] = getAllCounters($link, $omode, $feed); -// } - - if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); - - $reply['runtime-info'] = make_runtime_info($link); - - print json_encode($reply); - break; // viewfeed case "pref-feeds": require_once "modules/pref-feeds.php"; @@ -441,11 +191,6 @@ module_help($link); break; // help - case "dlg": - require_once "modules/popup-dialog.php"; - module_popup_dialog($link); - break; // dlg - case "pref-instances": require_once "modules/pref-instances.php"; module_pref_instances($link); diff --git a/classes/article.php b/classes/article.php new file mode 100644 index 000000000..98141d91e --- /dev/null +++ b/classes/article.php @@ -0,0 +1,63 @@ +link, "SELECT link FROM ttrss_entries, ttrss_user_entries + WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' + LIMIT 1"); + + if (db_num_rows($result) == 1) { + $article_url = db_fetch_result($result, 0, 'link'); + $article_url = str_replace("\n", "", $article_url); + + header("Location: $article_url"); + return; + + } else { + print_error(__("Article not found.")); + } + } + + function view() { + $id = db_escape_string($_REQUEST["id"]); + $cids = explode(",", db_escape_string($_REQUEST["cids"])); + $mode = db_escape_string($_REQUEST["mode"]); + $omode = db_escape_string($_REQUEST["omode"]); + + // in prefetch mode we only output requested cids, main article + // just gets marked as read (it already exists in client cache) + + $articles = array(); + + if ($mode == "") { + array_push($articles, format_article($this->link, $id, false)); + } else if ($mode == "zoom") { + array_push($articles, format_article($this->link, $id, true, true)); + } else if ($mode == "raw") { + if ($_REQUEST['html']) { + header("Content-Type: text/html"); + print ''; + } + + $article = format_article($this->link, $id, false); + print $article['content']; + return; + } + + catchupArticleById($this->link, $id, 0); + + if (!$_SESSION["bw_limit"]) { + foreach ($cids as $cid) { + if ($cid) { + array_push($articles, format_article($this->link, $cid, false, false)); + } + } + } + + print json_encode($articles); + + } + +} \ No newline at end of file diff --git a/classes/dlg.php b/classes/dlg.php new file mode 100644 index 000000000..3a66bf129 --- /dev/null +++ b/classes/dlg.php @@ -0,0 +1,1089 @@ +param = db_escape_string($_REQUEST["param"]); + print ""; + return true; + } + return false; + } + + function after() { + print ""; + } + + function importOpml() { + header("Content-Type: text/html"); # required for iframe + + print "
"; + $owner_uid = $_SESSION["uid"]; + + db_query($this->link, "BEGIN"); + + /* create Imported feeds category just in case */ + + $result = db_query($this->link, "SELECT id FROM + ttrss_feed_categories WHERE title = 'Imported feeds' AND + owner_uid = '$owner_uid' LIMIT 1"); + + if (db_num_rows($result) == 0) { + db_query($this->link, "INSERT INTO ttrss_feed_categories + (title,owner_uid) + VALUES ('Imported feeds', '$owner_uid')"); + } + + db_query($this->link, "COMMIT"); + + /* Handle OPML import by DOMXML/DOMDocument */ + + if (function_exists('domxml_open_file')) { + print "
    "; + print "
  • ".__("Importing using DOMXML.")."
  • "; + require_once "opml_domxml.php"; + opml_import_domxml($this->link, $owner_uid); + print "
"; + } else if (PHP_VERSION >= 5) { + print "
    "; + print "
  • ".__("Importing using DOMDocument.")."
  • "; + require_once "opml_domdoc.php"; + opml_import_domdoc($this->link, $owner_uid); + print "
"; + } else { + print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); + } + + print "
"; + + print "
"; + print ""; + print "
"; + + print ""; + + //return; + } + + function editPrefProfiles() { + print "
"; + + print " +
"; + + $result = db_query($this->link, "SELECT title,id FROM ttrss_settings_profiles + WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); + + print "
"; + + print "
"; + + print ""; + + print ""; #odd + + print ""; + + if (!$_SESSION["profile"]) { + $is_active = __("(active)"); + } else { + $is_active = ""; + } + + print ""; + + print ""; + + $lnum = 1; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + + $profile_id = $line["id"]; + $this_row_id = "id=\"FCATR-$profile_id\""; + + print ""; + + $edit_title = htmlspecialchars($line["title"]); + + print ""; + + if ($_SESSION["profile"] == $line["id"]) { + $is_active = __("(active)"); + } else { + $is_active = ""; + } + + print ""; + + print ""; + + ++$lnum; + } + + print "
" . + __("Default profile") . " $is_active
" . $edit_title . + " + $is_active
"; + print "
"; + print "
"; + + print "
+
+ + +
"; + + print ""; + print "
"; + + } + + function pubOPMLUrl() { + print "".__('Public OPML URL').""; + print "link); + + print __("Your Public OPML URL is:"); + + print "
"; + print "$url_path"; + print "
"; + + print "
"; + + print " "; + + print ""; + + print "
"; + print "]]>
"; + + //return; + } + + function explainError() { + print "".__('Notice').""; + print ""; + + if ($this->param == 1) { + print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner."); + + $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); + + print "

" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp); + + } + + if ($this->param == 3) { + print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner."); + + $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); + + print "

" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp); + + } + + print ""; + + print "

"; + + print ""; + + print "
"; + print "]]>
"; + + //return; + } + + function quickAddFeed() { + print ""; + print ""; + + print "
".__("Feed")."
"; + print "
"; + + print ""; + + print "
"; + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + print __('Place in category:') . " "; + print_feed_cat_select($this->link, "cat", false, 'dojoType="dijit.form.Select"'); + } + + print "
"; + + print ''; + + print ""; + + + print "
+ +
"; + + print ""; + + print "
+ + + +
"; + + //return; + } + + function feedBrowser() { + $browser_search = db_escape_string($_REQUEST["search"]); + + print ""; + print ""; + + print "
+
+ + + +
"; + + print " "; + + print __("limit:"); + + print " "; + + print "
"; + + $owner_uid = $_SESSION["uid"]; + + print "
    "; + print make_feed_browser($this->link, $search, 25); + print "
"; + + print "
+ + +
"; + + } + + function search() { + $this->params = explode(":", db_escape_string($_REQUEST["param"]), 2); + + $active_feed_id = sprintf("%d", $this->params[0]); + $is_cat = $this->params[1] != "false"; + + print "
".__('Look for')."
"; + + print "
"; + + if (!SPHINX_ENABLED) { + + print ""; + + print " " . __('match on')." "; + + $search_fields = array( + "title" => __("Title"), + "content" => __("Content"), + "both" => __("Title or content")); + + print_select_hash("match_on", 3, $search_fields, + 'dojoType="dijit.form.Select"'); + } else { + print ""; + } + + + print "
".__('Limit search to:')." "; + + print ""; + + print "
"; + + print "
"; + + if (!SPHINX_ENABLED) { + print "
+ Search syntax +
"; + } + + print " + +
"; + } + + function quickAddFilter() { + $active_feed_id = db_escape_string($_REQUEST["param"]); + + print ""; + print ""; + print ""; + + $result = db_query($this->link, "SELECT id,description + FROM ttrss_filter_types ORDER BY description"); + + $filter_types = array(); + + while ($line = db_fetch_assoc($result)) { + //array_push($filter_types, $line["description"]); + $filter_types[$line["id"]] = __($line["description"]); + } + + print "
".__("Match")."
"; + + print "
"; + + print ""; + + $filter_params = array( + "before" => __("before"), + "after" => __("after")); + + print_select_hash("filter_date_modifier", "before", + $filter_params, 'dojoType="dijit.form.Select"'); + + print " "; + + print ""; + + print ""; + print " "; + print ""; + + print "
" . __("on field") . " "; + print_select_hash("filter_type", 1, $filter_types, + 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); + + print "
"; + + print __("in") . " "; + print_feed_select($this->link, "feed_id", $active_feed_id, + 'dojoType="dijit.form.FilteringSelect"'); + + print "
"; + + print "
".__("Perform Action")."
"; + + print "
"; + + print ""; + + print ""; + print " " . __("with parameters:") . " "; + print ""; + + print_label_select($this->link, "action_param_label", $action_param, + 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"'); + + print ""; + + print " "; // tiny layout hack + + print "
"; + + print "
".__("Options")."
"; + print "
"; + + print " +
"; + + print " + "; + + print "
"; + + print "
"; + + print " "; + + print " "; + + print ""; + + print "
"; + } + + function inactiveFeeds() { + + if (DB_TYPE == "pgsql") { + $interval_qpart = "NOW() - INTERVAL '3 months'"; + } else { + $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; + } + + $result = db_query($this->link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url, + ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article + FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE + (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE + ttrss_entries.id = ref_id AND + ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart + AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND + ttrss_user_entries.feed_id = ttrss_feeds.id AND + ttrss_entries.id = ref_id + GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url + ORDER BY last_article"); + + print __("These feeds have not been updated with new content for 3 months (oldest first):"); + + print "
"; + + print ""; + + $lnum = 1; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + $feed_id = $line["id"]; + $this_row_id = "id=\"FUPDD-$feed_id\""; + + print ""; + + $edit_title = htmlspecialchars($line["title"]); + + print ""; + print ""; + print ""; + + ++$lnum; + } + + print "
"; + + print "". + htmlspecialchars($line["title"]).""; + + print ""; + print make_local_datetime($this->link, $line['last_article'], false); + print "
"; + print "
"; + + print "
"; + print "
"; + print " "; + print "
"; + + print ""; + + print "
"; + + } + + function feedsWithErrors() { + print __("These feeds have not been updated because of errors:"); + + $result = db_query($this->link, "SELECT id,title,feed_url,last_error,site_url + FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); + + print "
"; + + print ""; + + $lnum = 1; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + $feed_id = $line["id"]; + $this_row_id = "id=\"FUPDD-$feed_id\""; + + print ""; + + $edit_title = htmlspecialchars($line["title"]); + + print ""; + print ""; + print ""; + + ++$lnum; + } + + print "
"; + + print "". + htmlspecialchars($line["title"]).": "; + + print ""; + print htmlspecialchars($line["last_error"]); + print ""; + + print "
"; + print "
"; + + print "
"; + print "
"; + print " "; + print "
"; + + print ""; + + print "
"; + } + + function editArticleTags() { + + print __("Tags for this article (separated by commas):")."
"; + + $tags = get_article_tags($this->link, $this->param); + + $tags_str = join(", ", $tags); + + print "param\">"; + print ""; + print ""; + + print "
"; + + print " +
"; + + print "
"; + + print "
"; + + print " "; + print ""; + print "
"; + + } + + function printTagCloud() { + print "".__('Tag Cloud').""; + print ""; + + printTagCloud($this->link); + + print ""; + + print "
"; + print ""; + print "
"; + + print "]]>
"; + } + + function printTagSelect() { + + print "" . __('Select item(s) by tags') . ""; + print " Any "; + print " All "; + print " tags."; + + print ""; + + print "
"; + print ""; + print " "; + print ""; + print "
"; + + print "]]>
"; + } + + function emailArticle() { + + $secretkey = sha1(uniqid(rand(), true)); + + $_SESSION['email_secretkey'] = $secretkey; + + print ""; + print ""; + print ""; + + $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE + id = " . $_SESSION["uid"]); + + $user_email = htmlspecialchars(db_fetch_result($result, 0, "email")); + $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); + + if (!$user_name) $user_name = $_SESSION['name']; + + $_SESSION['email_replyto'] = $user_email; + $_SESSION['email_fromname'] = $user_name; + + require_once "lib/MiniTemplator.class.php"; + + $tpl = new MiniTemplator; + $tpl_t = new MiniTemplator; + + $tpl->readTemplateFromFile("templates/email_article_template.txt"); + + $tpl->setVariable('USER_NAME', $_SESSION["name"]); + $tpl->setVariable('USER_EMAIL', $user_email); + $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]); + + + $result = db_query($this->link, "SELECT link, content, title + FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND + id IN ($this->param) AND owner_uid = " . $_SESSION["uid"]); + + if (db_num_rows($result) > 1) { + $subject = __("[Forwarded]") . " " . __("Multiple articles"); + } + + while ($line = db_fetch_assoc($result)) { + + if (!$subject) + $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); + + $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); + $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); + + $tpl->addBlock('article'); + } + + $tpl->addBlock('email'); + + $content = ""; + $tpl->generateOutputToString($content); + + print ""; + + print "
"; + + print __('From:'); + + print ""; + + print "\">"; + + print "
"; + + print __('To:'); + + print ""; + + print ""; + + print "
"; + + print "
"; + + print __('Subject:'); + + print ""; + + print ""; + + print "
"; + + print "
"; + + print "
"; + print " "; + print ""; + print "
"; + + //return; + } + + function generatedFeed() { + + print "".__('View as RSS').""; + print "params = explode(":", $this->param, 3); + $feed_id = db_escape_string($this->params[0]); + $is_cat = (bool) $this->params[1]; + + $key = get_feed_access_key($this->link, $feed_id, $is_cat); + + $url_path = htmlspecialchars($this->params[2]) . "&key=" . $key; + + print __("You can view this feed as RSS using the following URL:"); + + print "
"; + print "$url_path"; + print "
"; + + print "
"; + + print " "; + + print ""; + + print "
"; + print "]]>
"; + + //return; + } + + function newVersion() { + + $version_data = check_for_update($this->link); + $version = $version_data['version']; + $id = $version_data['version_id']; + + print "
"; + + print T_sprintf("New version of Tiny Tiny RSS is available (%s).", + "$version"); + + print "
"; + + $details = "http://tt-rss.org/redmine/versions/show/$id"; + $download = "http://tt-rss.org/#Download"; + + print "
"; + print ""; + print ""; + print ""; + print "
"; + + } + + function customizeCSS() { + $value = get_pref($this->link, "USER_STYLESHEET"); + + $value = str_replace("
", "\n", $value); + + print T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. This file can be used as a baseline.", "tt-rss.css"); + + print ""; + print ""; + print ""; + + print "
"; + print ""; + print "
"; + + print "
"; + print " "; + print ""; + print "
"; + + } + + function editArticleNote() { + $result = db_query($this->link, "SELECT note FROM ttrss_user_entries WHERE + ref_id = '$this->param' AND owner_uid = " . $_SESSION['uid']); + + $note = db_fetch_result($result, 0, "note"); + + print "param\">"; + print ""; + print ""; + + print "
"; + print ""; + print "
"; + + print "
"; + print " "; + print ""; + print "
"; + + } + + function about() { + print ""; + print ""; + print "
"; + print ""; + print ""; + + print "

Tiny Riny RSS

+ Version ".VERSION." +

Copyright © 2005-".date('Y')." + Andrew Dolgov + and other contributors.

+

Licensed under GNU GPL version 2.

"; + + print "

+ Official site — + + Support the project.

"; + + print "
"; + + print "
"; + print ""; + print "
"; + } + + function addInstance() { + print ""; + print ""; + + print "
".__("Instance")."
"; + + print "
"; + + /* URL */ + + print __("URL:") . " "; + + print ""; + + print "
"; + + $access_key = sha1(uniqid(rand(), true)); + + /* Access key */ + + print __("Access key:") . " "; + + print ""; + + print "

" . __("Use one access key for both linked instances."); + + print "

"; + + print "
+
+ +
+ +
"; + + return; + } + + function shareArticle() { + $result = db_query($this->link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$this->param' + AND owner_uid = " . $_SESSION['uid']); + + if (db_num_rows($result) == 0) { + print "Article not found."; + } else { + + $uuid = db_fetch_result($result, 0, "uuid"); + $ref_id = db_fetch_result($result, 0, "ref_id"); + + if (!$uuid) { + $uuid = db_escape_string(sha1(uniqid(rand(), true))); + db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$this->param' + AND owner_uid = " . $_SESSION['uid']); + } + + print __("You can share this article by the following unique URL:"); + + $url_path = get_self_url_prefix(); + $url_path .= "/public.php?op=share&key=$uuid"; + + print "
"; + print "$url_path"; + print "
"; + + /* if (!label_find_id($this->link, __('Shared'), $_SESSION["uid"])) + label_create($this->link, __('Shared'), $_SESSION["uid"]); + + label_add_article($this->link, $ref_id, __('Shared'), $_SESSION['uid']); */ + } + + print "
"; + + print ""; + + print "
"; + } + +} +?> diff --git a/classes/feeds.php b/classes/feeds.php new file mode 100644 index 000000000..a654c92ae --- /dev/null +++ b/classes/feeds.php @@ -0,0 +1,187 @@ +link, "UPDATE ttrss_user_entries SET + last_read = NOW(),unread = false WHERE owner_uid = " . $_SESSION["uid"]); + ccache_zero_all($this->link, $_SESSION["uid"]); + } + + function collapse() { + $cat_id = db_escape_string($_REQUEST["cid"]); + $mode = (int) db_escape_string($_REQUEST['mode']); + toggle_collapse_cat($this->link, $cat_id, $mode); + } + + function index() { + $root = (bool)$_REQUEST["root"]; + + if (!$root) { + print json_encode(outputFeedList($this->link)); + } else { + + $feeds = outputFeedList($this->link, false); + + $root = array(); + $root['id'] = 'root'; + $root['name'] = __('Feeds'); + $root['items'] = $feeds['items']; + + $fl = array(); + $fl['identifier'] = 'id'; + $fl['label'] = 'name'; + $fl['items'] = array($root); + + print json_encode($fl); + } + } + + function view() { + $timing_info = getmicrotime(); + + $reply = array(); + + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("0", $timing_info); + + $omode = db_escape_string($_REQUEST["omode"]); + + $feed = db_escape_string($_REQUEST["feed"]); + $method = db_escape_string($_REQUEST["m"]); + $view_mode = db_escape_string($_REQUEST["view_mode"]); + $limit = (int) get_pref($this->link, "DEFAULT_ARTICLE_LIMIT"); + @$cat_view = db_escape_string($_REQUEST["cat"]) == "true"; + @$next_unread_feed = db_escape_string($_REQUEST["nuf"]); + @$offset = db_escape_string($_REQUEST["skip"]); + @$vgroup_last_feed = db_escape_string($_REQUEST["vgrlf"]); + $order_by = db_escape_string($_REQUEST["order_by"]); + + if (is_numeric($feed)) $feed = (int) $feed; + + /* Feed -5 is a special case: it is used to display auxiliary information + * when there's nothing to load - e.g. no stuff in fresh feed */ + + if ($feed == -5) { + print json_encode(generate_dashboard_feed($this->link)); + return; + } + + $result = false; + + if ($feed < -10) { + $label_feed = -11-$feed; + $result = db_query($this->link, "SELECT id FROM ttrss_labels2 WHERE + id = '$label_feed' AND owner_uid = " . $_SESSION['uid']); + } else if (!$cat_view && is_numeric($feed) && $feed > 0) { + $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE + id = '$feed' AND owner_uid = " . $_SESSION['uid']); + } else if ($cat_view && is_numeric($feed) && $feed > 0) { + $result = db_query($this->link, "SELECT id FROM ttrss_feed_categories WHERE + id = '$feed' AND owner_uid = " . $_SESSION['uid']); + } + + if ($result && db_num_rows($result) == 0) { + print json_encode(generate_error_feed($this->link, __("Feed not found."))); + return; + } + + /* Updating a label ccache means recalculating all of the caches + * so for performance reasons we don't do that here */ + + if ($feed >= 0) { + ccache_update($this->link, $feed, $_SESSION["uid"], $cat_view); + } + + set_pref($this->link, "_DEFAULT_VIEW_MODE", $view_mode); + set_pref($this->link, "_DEFAULT_VIEW_LIMIT", $limit); + set_pref($this->link, "_DEFAULT_VIEW_ORDER_BY", $order_by); + + if (!$cat_view && preg_match("/^[0-9][0-9]*$/", $feed)) { + db_query($this->link, "UPDATE ttrss_feeds SET last_viewed = NOW() + WHERE id = '$feed' AND owner_uid = ".$_SESSION["uid"]); + } + + $reply['headlines'] = array(); + + if (!$next_unread_feed) + $reply['headlines']['id'] = $feed; + else + $reply['headlines']['id'] = $next_unread_feed; + + $reply['headlines']['is_cat'] = (bool) $cat_view; + + $override_order = false; + + if (get_pref($this->link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) { + $date_sort_field = "updated"; + } else { + $date_sort_field = "date_entered"; + } + + switch ($order_by) { + case "date": + if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { + $override_order = "$date_sort_field"; + } else { + $override_order = "$date_sort_field DESC"; + } + break; + + case "title": + if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { + $override_order = "title DESC, $date_sort_field"; + } else { + $override_order = "title, $date_sort_field DESC"; + } + break; + + case "score": + if (get_pref($this->link, 'REVERSE_HEADLINES', $owner_uid)) { + $override_order = "score, $date_sort_field"; + } else { + $override_order = "score DESC, $date_sort_field DESC"; + } + break; + } + + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("04", $timing_info); + + $ret = format_headlines_list($this->link, $feed, $method, + $view_mode, $limit, $cat_view, $next_unread_feed, $offset, + $vgroup_last_feed, $override_order); + + $topmost_article_ids = $ret[0]; + $headlines_count = $ret[1]; + $returned_feed = $ret[2]; + $disable_cache = $ret[3]; + $vgroup_last_feed = $ret[4]; + + $reply['headlines']['content'] =& $ret[5]['content']; + $reply['headlines']['toolbar'] =& $ret[5]['toolbar']; + + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("05", $timing_info); + + $reply['headlines-info'] = array("count" => (int) $headlines_count, + "vgroup_last_feed" => $vgroup_last_feed, + "disable_cache" => (bool) $disable_cache); + + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("20", $timing_info); + + if (is_array($topmost_article_ids) && !get_pref($this->link, 'COMBINED_DISPLAY_MODE') && !$_SESSION["bw_limit"]) { + $articles = array(); + + foreach ($topmost_article_ids as $id) { + array_push($articles, format_article($this->link, $id, false)); + } + + $reply['articles'] = $articles; + } + + if ($_REQUEST["debug"]) $timing_info = print_checkpoint("30", $timing_info); + + $reply['runtime-info'] = make_runtime_info($this->link); + + print json_encode($reply); + + } +} +?> \ No newline at end of file diff --git a/classes/handler.php b/classes/handler.php index 3bd82c725..53b52ea03 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -11,5 +11,9 @@ class Handler { function before() { return true; } + + function after() { + return true; + } } ?> diff --git a/js/feedlist.js b/js/feedlist.js index ff4c948d4..75e97e884 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -138,8 +138,8 @@ function viewfeed(feed, method, is_cat, offset, background, infscroll_req) { var toolbar_query = Form.serialize("main_toolbar_form"); - var query = "?op=viewfeed&feed=" + feed + "&" + - toolbar_query + "&method=" + param_escape(method); + var query = "?op=feeds&method=view&feed=" + feed + "&" + + toolbar_query + "&m=" + param_escape(method); if (!background) { if (_search_query) { diff --git a/js/functions.js b/js/functions.js index e62d576b6..37aa73bc9 100644 --- a/js/functions.js +++ b/js/functions.js @@ -411,7 +411,7 @@ function displayDlg(id, param, callback) { notify_progress("Loading, please wait...", true); - var query = "?op=dlg&id=" + + var query = "?op=dlg&method=" + param_escape(id) + "¶m=" + param_escape(param); new Ajax.Request("backend.php", { @@ -846,7 +846,7 @@ function addLabel(select, callback) { function quickAddFeed() { try { - var query = "backend.php?op=dlg&id=quickAddFeed"; + var query = "backend.php?op=dlg&method=quickAddFeed"; if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").destroyRecursive(); @@ -948,7 +948,7 @@ function quickAddFeed() { function quickAddFilter() { try { - var query = "backend.php?op=dlg&id=quickAddFilter"; + var query = "backend.php?op=dlg&method=quickAddFilter"; if (dijit.byId("filterEditDlg")) dijit.byId("filterEditDlg").destroyRecursive(); @@ -1406,7 +1406,7 @@ function editFeed(feed, event) { function feedBrowser() { try { - var query = "backend.php?op=dlg&id=feedBrowser"; + var query = "backend.php?op=dlg&method=feedBrowser"; if (dijit.byId("feedAddDlg")) dijit.byId("feedAddDlg").hide(); @@ -1551,7 +1551,7 @@ function feedBrowser() { function showFeedsWithErrors() { try { - var query = "backend.php?op=dlg&id=feedsWithErrors"; + var query = "backend.php?op=dlg&method=feedsWithErrors"; if (dijit.byId("errorFeedsDlg")) dijit.byId("errorFeedsDlg").destroyRecursive(); diff --git a/js/prefs.js b/js/prefs.js index 760441a3d..98b581ca1 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -1229,7 +1229,7 @@ function editFeedCats() { function showInactiveFeeds() { try { - var query = "backend.php?op=dlg&id=inactiveFeeds"; + var query = "backend.php?op=dlg&method=inactiveFeeds"; if (dijit.byId("inactiveFeedsDlg")) dijit.byId("inactiveFeedsDlg").destroyRecursive(); @@ -1470,7 +1470,7 @@ function editProfiles() { if (dijit.byId("profileEditDlg")) dijit.byId("profileEditDlg").destroyRecursive(); - var query = "backend.php?op=dlg&id=editPrefProfiles"; + var query = "backend.php?op=dlg&method=editPrefProfiles"; dialog = new dijit.Dialog({ id: "profileEditDlg", @@ -1773,7 +1773,7 @@ function clearTwitterCredentials() { function customizeCSS() { try { - var query = "backend.php?op=dlg&id=customizeCSS"; + var query = "backend.php?op=dlg&method=customizeCSS"; if (dijit.byId("cssEditDlg")) dijit.byId("cssEditDlg").destroyRecursive(); @@ -1815,7 +1815,7 @@ function getSelectedInstances() { function addInstance() { try { - var query = "backend.php?op=dlg&id=addInstance"; + var query = "backend.php?op=dlg&method=addInstance"; if (dijit.byId("instanceAddDlg")) dijit.byId("instanceAddDlg").destroyRecursive(); diff --git a/js/tt-rss.js b/js/tt-rss.js index 96147b3d3..38232bdfe 100644 --- a/js/tt-rss.js +++ b/js/tt-rss.js @@ -222,7 +222,7 @@ function timeout() { } function search() { - var query = "backend.php?op=dlg&id=search¶m=" + + var query = "backend.php?op=dlg&method=search¶m=" + param_escape(getActiveFeedId() + ":" + activeFeedIsCat()); if (dijit.byId("searchDlg")) @@ -436,7 +436,7 @@ function quickMenuGo(opid) { dialog = new dijit.Dialog({ title: __("About..."), style: "width: 400px", - href: "backend.php?op=dlg&id=about", + href: "backend.php?op=dlg&method=about", }); dialog.show(); @@ -1078,7 +1078,7 @@ function scheduleFeedUpdate(id, is_cat) { function newVersionDlg() { try { - var query = "backend.php?op=dlg&id=newVersion"; + var query = "backend.php?op=dlg&method=newVersion"; if (dijit.byId("newVersionDlg")) dijit.byId("newVersionDlg").destroyRecursive(); diff --git a/js/viewfeed.js b/js/viewfeed.js index 363121b19..b9b2a8e2b 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -322,7 +322,7 @@ function view(id) { hideAuxDlg(); - var query = "?op=view&id=" + param_escape(id); + var query = "?op=article&method=view&id=" + param_escape(id); var neighbor_ids = getRelativePostIds(id); @@ -1006,7 +1006,7 @@ function catchupSelection() { } function editArticleTags(id) { - var query = "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id); + var query = "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id); if (dijit.byId("editTagsDlg")) dijit.byId("editTagsDlg").destroyRecursive(); @@ -1514,7 +1514,7 @@ function emailArticle(id) { if (dijit.byId("emailArticleDlg")) dijit.byId("emailArticleDlg").destroyRecursive(); - var query = "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id); + var query = "backend.php?op=dlg&method=emailArticle¶m=" + param_escape(id); dialog = new dijit.Dialog({ id: "emailArticleDlg", @@ -1770,7 +1770,7 @@ function getLastVisibleHeadlineId() { function openArticleInNewWindow(id) { toggleUnread(id, 0, false); - window.open("backend.php?op=la&id=" + id); + window.open("backend.php?op=article&id=" + id); } function isCdmMode() { @@ -2028,7 +2028,7 @@ function tweetArticle(id) { function editArticleNote(id) { try { - var query = "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id); + var query = "backend.php?op=dlg&method=editArticleNote¶m=" + param_escape(id); if (dijit.byId("editNoteDlg")) dijit.byId("editNoteDlg").destroyRecursive(); @@ -2227,7 +2227,7 @@ function shareArticle(id) { if (dijit.byId("shareArticleDlg")) dijit.byId("shareArticleDlg").destroyRecursive(); - var query = "backend.php?op=dlg&id=shareArticle¶m=" + param_escape(id); + var query = "backend.php?op=dlg&method=shareArticle¶m=" + param_escape(id); dialog = new dijit.Dialog({ id: "shareArticleDlg", diff --git a/modules/popup-dialog.php b/modules/popup-dialog.php deleted file mode 100644 index 13abc947f..000000000 --- a/modules/popup-dialog.php +++ /dev/null @@ -1,1122 +0,0 @@ -"; - - if ($id == "importOpml") { - print "
"; - header("Content-Type: text/html"); # required for iframe - - $owner_uid = $_SESSION["uid"]; - - db_query($link, "BEGIN"); - - /* create Imported feeds category just in case */ - - $result = db_query($link, "SELECT id FROM - ttrss_feed_categories WHERE title = 'Imported feeds' AND - owner_uid = '$owner_uid' LIMIT 1"); - - if (db_num_rows($result) == 0) { - db_query($link, "INSERT INTO ttrss_feed_categories - (title,owner_uid) - VALUES ('Imported feeds', '$owner_uid')"); - } - - db_query($link, "COMMIT"); - - /* Handle OPML import by DOMXML/DOMDocument */ - - if (function_exists('domxml_open_file')) { - print "
    "; - print "
  • ".__("Importing using DOMXML.")."
  • "; - require_once "opml_domxml.php"; - opml_import_domxml($link, $owner_uid); - print "
"; - } else if (PHP_VERSION >= 5) { - print "
    "; - print "
  • ".__("Importing using DOMDocument.")."
  • "; - require_once "opml_domdoc.php"; - opml_import_domdoc($link, $owner_uid); - print "
"; - } else { - print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); - } - - print "
"; - - print "
"; - print ""; - print "
"; - - print ""; - - //return; - } - - if ($id == "editPrefProfiles") { - - print "
"; - -# TODO: depends on selectTableRows() being broken for this list -# print "
". -# "" . __('Select').""; -# print "
"; -# print "
".__('All')."
"; -# print "
".__('None')."
"; -# print "
"; - -# print "
"; - print " -
"; - -# print "
"; - - - $result = db_query($link, "SELECT title,id FROM ttrss_settings_profiles - WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); - - print "
"; - - print "
"; - - print ""; - - print ""; #odd - - print ""; - - if (!$_SESSION["profile"]) { - $is_active = __("(active)"); - } else { - $is_active = ""; - } - - print ""; - - print ""; - - $lnum = 1; - - while ($line = db_fetch_assoc($result)) { - - $class = ($lnum % 2) ? "even" : "odd"; - - $profile_id = $line["id"]; - $this_row_id = "id=\"FCATR-$profile_id\""; - - print ""; - - $edit_title = htmlspecialchars($line["title"]); - - print ""; - - if ($_SESSION["profile"] == $line["id"]) { - $is_active = __("(active)"); - } else { - $is_active = ""; - } - - print ""; - - print ""; - - ++$lnum; - } - - print "
" . - __("Default profile") . " $is_active
" . $edit_title . - " - $is_active
"; - print "
"; - print "
"; - - print "
-
- - -
"; - - print ""; - print "
"; - - } - - if ($id == "pubOPMLUrl") { - - print "".__('Public OPML URL').""; - print ""; - print "$url_path"; - print ""; - - print "
"; - - print " "; - - print ""; - - print "
"; - print "]]>
"; - - //return; - } - - if ($id == "explainError") { - - print "".__('Notice').""; - print ""; - - if ($param == 1) { - print __("Update daemon is enabled in configuration, but daemon process is not running, which prevents all feeds from updating. Please start the daemon process or contact instance owner."); - - $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); - - print "

" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp); - - } - - if ($param == 3) { - print __("Update daemon is taking too long to perform a feed update. This could indicate a problem like crash or a hang. Please check the daemon process or contact instance owner."); - - $stamp = (int) file_get_contents(LOCK_DIRECTORY . "/update_daemon.stamp"); - - print "

" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp); - - } - - print ""; - - print "

"; - - print ""; - - print "
"; - print "]]>
"; - - //return; - } - - if ($id == "quickAddFeed") { - - print ""; - print ""; - - print "
".__("Feed")."
"; - print "
"; - - print ""; - - print "
"; - - if (get_pref($link, 'ENABLE_FEED_CATS')) { - print __('Place in category:') . " "; - print_feed_cat_select($link, "cat", false, 'dojoType="dijit.form.Select"'); - } - - print "
"; - - print ''; - - print ""; - - - print "
- -
"; - - print ""; - - print "
- - - -
"; - - //return; - } - - if ($id == "feedBrowser") { - - $browser_search = db_escape_string($_REQUEST["search"]); - -# print "
"; - - print ""; - print ""; - - print "
-
- - - -
"; - - print " "; - - print __("limit:"); - - print " "; - - print "
"; - - $owner_uid = $_SESSION["uid"]; - - print "
    "; - print make_feed_browser($link, $search, 25); - print "
"; - - print "
- - -
"; - - } - - if ($id == "search") { - - $params = explode(":", db_escape_string($_REQUEST["param"]), 2); - - $active_feed_id = sprintf("%d", $params[0]); - $is_cat = $params[1] != "false"; - - print "
".__('Look for')."
"; - - print "
"; - - if (!SPHINX_ENABLED) { - - print ""; - - print " " . __('match on')." "; - - $search_fields = array( - "title" => __("Title"), - "content" => __("Content"), - "both" => __("Title or content")); - - print_select_hash("match_on", 3, $search_fields, - 'dojoType="dijit.form.Select"'); - } else { - print ""; - } - - - print "
".__('Limit search to:')." "; - - print ""; - - print "
"; - - print "
"; - - if (!SPHINX_ENABLED) { - print ""; - } - - print " - -
"; - } - - if ($id == "quickAddFilter") { - - $active_feed_id = db_escape_string($_REQUEST["param"]); - - print ""; - print ""; - print ""; - - $result = db_query($link, "SELECT id,description - FROM ttrss_filter_types ORDER BY description"); - - $filter_types = array(); - - while ($line = db_fetch_assoc($result)) { - //array_push($filter_types, $line["description"]); - $filter_types[$line["id"]] = __($line["description"]); - } - - print "
".__("Match")."
"; - - print "
"; - - print ""; - - $filter_params = array( - "before" => __("before"), - "after" => __("after")); - - print_select_hash("filter_date_modifier", "before", - $filter_params, 'dojoType="dijit.form.Select"'); - - print " "; - - print ""; - - print ""; - print " "; - print ""; - - print "
" . __("on field") . " "; - print_select_hash("filter_type", 1, $filter_types, - 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); - - print "
"; - - print __("in") . " "; - print_feed_select($link, "feed_id", $active_feed_id, - 'dojoType="dijit.form.FilteringSelect"'); - - print "
"; - - print "
".__("Perform Action")."
"; - - print "
"; - - print ""; - - print ""; - print " " . __("with parameters:") . " "; - print ""; - - print_label_select($link, "action_param_label", $action_param, - 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"'); - - print ""; - - print " "; // tiny layout hack - - print "
"; - - print "
".__("Options")."
"; - print "
"; - - print " -
"; - - print " - "; - - print "
"; - - print "
"; - - print " "; - - print " "; - - print ""; - - print "
"; - - //return; - } - - if ($id == "inactiveFeeds") { - - if (DB_TYPE == "pgsql") { - $interval_qpart = "NOW() - INTERVAL '3 months'"; - } else { - $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)"; - } - - $result = db_query($link, "SELECT ttrss_feeds.title, ttrss_feeds.site_url, - ttrss_feeds.feed_url, ttrss_feeds.id, MAX(updated) AS last_article - FROM ttrss_feeds, ttrss_entries, ttrss_user_entries WHERE - (SELECT MAX(updated) FROM ttrss_entries, ttrss_user_entries WHERE - ttrss_entries.id = ref_id AND - ttrss_user_entries.feed_id = ttrss_feeds.id) < $interval_qpart - AND ttrss_feeds.owner_uid = ".$_SESSION["uid"]." AND - ttrss_user_entries.feed_id = ttrss_feeds.id AND - ttrss_entries.id = ref_id - GROUP BY ttrss_feeds.title, ttrss_feeds.id, ttrss_feeds.site_url, ttrss_feeds.feed_url - ORDER BY last_article"); - - print __("These feeds have not been updated with new content for 3 months (oldest first):"); - - print "
"; - - print ""; - - $lnum = 1; - - while ($line = db_fetch_assoc($result)) { - - $class = ($lnum % 2) ? "even" : "odd"; - $feed_id = $line["id"]; - $this_row_id = "id=\"FUPDD-$feed_id\""; - - print ""; - - $edit_title = htmlspecialchars($line["title"]); - - print ""; - print ""; - print ""; - - ++$lnum; - } - - print "
"; - - print "". - htmlspecialchars($line["title"]).""; - - print ""; - print make_local_datetime($link, $line['last_article'], false); - print "
"; - print "
"; - - print "
"; - print "
"; - print " "; - print "
"; - - print ""; - - print "
"; - - } - - if ($id == "feedsWithErrors") { - -# print "".__('Feeds with update errors').""; -# print ""; - - print ""; - - $lnum = 1; - - while ($line = db_fetch_assoc($result)) { - - $class = ($lnum % 2) ? "even" : "odd"; - $feed_id = $line["id"]; - $this_row_id = "id=\"FUPDD-$feed_id\""; - - print ""; - - $edit_title = htmlspecialchars($line["title"]); - - print ""; - print ""; - print ""; - - ++$lnum; - } - - print "
"; - - print "". - htmlspecialchars($line["title"]).": "; - - print ""; - print htmlspecialchars($line["last_error"]); - print ""; - - print "
"; - print ""; - - print "
"; - print "
"; - print " "; - print "
"; - - print ""; - - print "
"; - } - - if ($id == "editArticleTags") { - -# print ""; - - print __("Tags for this article (separated by commas):")."
"; - - $tags = get_article_tags($link, $param); - - $tags_str = join(", ", $tags); - - print ""; - print ""; - print ""; - - print "
"; - - print " -
"; - - print "
"; - -# print ""; - - print "
"; - - print " "; - print ""; - print "
"; - - } - - if ($id == "printTagCloud") { - print "".__('Tag Cloud').""; - print "".__('more tags')."):
"; - - print "
"; - - printTagCloud($link); - - print "
"; - - print "
"; - print ""; - print "
"; - - print "]]>
"; - } - - if ($id == 'printTagSelect') { - print "" . __('Select item(s) by tags') . ""; - print " Any "; - print " All "; - print " tags."; - - print ""; - - print "
"; - print ""; - print " "; - print ""; - print "
"; - - print "]]>
"; - } - - if ($id == "emailArticle") { - - $secretkey = sha1(uniqid(rand(), true)); - - $_SESSION['email_secretkey'] = $secretkey; - - print ""; - print ""; - print ""; - - $result = db_query($link, "SELECT email, full_name FROM ttrss_users WHERE - id = " . $_SESSION["uid"]); - - $user_email = htmlspecialchars(db_fetch_result($result, 0, "email")); - $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); - - if (!$user_name) $user_name = $_SESSION['name']; - - $_SESSION['email_replyto'] = $user_email; - $_SESSION['email_fromname'] = $user_name; - - require_once "lib/MiniTemplator.class.php"; - - $tpl = new MiniTemplator; - $tpl_t = new MiniTemplator; - - $tpl->readTemplateFromFile("templates/email_article_template.txt"); - - $tpl->setVariable('USER_NAME', $_SESSION["name"]); - $tpl->setVariable('USER_EMAIL', $user_email); - $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]); - -// $tpl->addBlock('header'); - - $result = db_query($link, "SELECT link, content, title - FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND - id IN ($param) AND owner_uid = " . $_SESSION["uid"]); - - if (db_num_rows($result) > 1) { - $subject = __("[Forwarded]") . " " . __("Multiple articles"); - } - - while ($line = db_fetch_assoc($result)) { - - if (!$subject) - $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]); - - $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"])); - $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"])); - - $tpl->addBlock('article'); - } - - $tpl->addBlock('email'); - - $content = ""; - $tpl->generateOutputToString($content); - - print ""; - - print "
"; - - print __('From:'); - - print ""; - - print "\">"; - - print "
"; - - print __('To:'); - - print ""; - - print ""; - - print "
"; - - print "
"; - - print __('Subject:'); - - print ""; - - print ""; - - print "
"; - - print "
"; - - print "
"; - print " "; - print ""; - print "
"; - - //return; - } - - if ($id == "generatedFeed") { - - print "".__('View as RSS').""; - print ""; - print "$url_path"; - print ""; - - print "
"; - - print " "; - - print ""; - - print "
"; - print "]]>
"; - - //return; - } - - if ($id == "newVersion") { - $version_data = check_for_update($link); - $version = $version_data['version']; - $id = $version_data['version_id']; - - print "
"; - - print T_sprintf("New version of Tiny Tiny RSS is available (%s).", - "$version"); - - print "
"; - - $details = "http://tt-rss.org/redmine/versions/show/$id"; - $download = "http://tt-rss.org/#Download"; - - print "
"; - print ""; - print ""; - print ""; - print "
"; - - } - - if ($id == "customizeCSS") { - - $value = get_pref($link, "USER_STYLESHEET"); - - $value = str_replace("
", "\n", $value); - - print T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. This file can be used as a baseline.", "tt-rss.css"); - - print ""; - print ""; - print ""; - - print "
"; - print ""; - print "
"; - - print "
"; - print " "; - print ""; - print "
"; - - } - - if ($id == "editArticleNote") { - - $result = db_query($link, "SELECT note FROM ttrss_user_entries WHERE - ref_id = '$param' AND owner_uid = " . $_SESSION['uid']); - - $note = db_fetch_result($result, 0, "note"); - - print ""; - print ""; - print ""; - - print "
"; - print ""; - print "
"; - - print "
"; - print " "; - print ""; - print "
"; - - } - - if ($id == "about") { - print ""; - print ""; - print "
"; - print ""; - print ""; - - print "

Tiny Riny RSS

- Version ".VERSION." -

Copyright © 2005-".date('Y')." - Andrew Dolgov - and other contributors.

-

Licensed under GNU GPL version 2.

"; - - print "

- Official site — - - Support the project.

"; - - print "
"; - - print "
"; - print ""; - print "
"; - } - - if ($id == "addInstance") { - - print ""; - print ""; - - print "
".__("Instance")."
"; - - print "
"; - - /* URL */ - - print __("URL:") . " "; - - print ""; - - print "
"; - - $access_key = sha1(uniqid(rand(), true)); - - /* Access key */ - - print __("Access key:") . " "; - - print ""; - - print "

" . __("Use one access key for both linked instances."); - - print "

"; - - print "
-
- -
- -
"; - - return; - } - - if ($id == "shareArticle") { - - $result = db_query($link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param' - AND owner_uid = " . $_SESSION['uid']); - - if (db_num_rows($result) == 0) { - print "Article not found."; - } else { - - $uuid = db_fetch_result($result, 0, "uuid"); - $ref_id = db_fetch_result($result, 0, "ref_id"); - - if (!$uuid) { - $uuid = db_escape_string(sha1(uniqid(rand(), true))); - db_query($link, "UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param' - AND owner_uid = " . $_SESSION['uid']); - } - - print __("You can share this article by the following unique URL:"); - - $url_path = get_self_url_prefix(); - $url_path .= "/public.php?op=share&key=$uuid"; - - print "
"; - print "$url_path"; - print "
"; - - /* if (!label_find_id($link, __('Shared'), $_SESSION["uid"])) - label_create($link, __('Shared'), $_SESSION["uid"]); - - label_add_article($link, $ref_id, __('Shared'), $_SESSION['uid']); */ - } - - print "
"; - - print ""; - - print "
"; - - return; - } - - print ""; - - } -?> diff --git a/public.php b/public.php index 5fd9beabd..3b0d064b6 100644 --- a/public.php +++ b/public.php @@ -1,4 +1,6 @@ Date: Tue, 13 Dec 2011 10:00:42 +0400 Subject: add pref_prefs class --- backend.php | 16 +- classes/pref_prefs.php | 493 +++++++++++++++++++++++++++++++++++++++++++++++ js/prefs.js | 2 +- modules/pref-prefs.php | 512 ------------------------------------------------- 4 files changed, 496 insertions(+), 527 deletions(-) create mode 100644 classes/pref_prefs.php delete mode 100644 modules/pref-prefs.php (limited to 'js') diff --git a/backend.php b/backend.php index 1c7b3ffb0..8220337ac 100644 --- a/backend.php +++ b/backend.php @@ -50,14 +50,7 @@ init_connection($link); - $method = strtolower($_REQUEST["method"]); - $mode = $_REQUEST["mode"]; - - /* if ((!$op || $op == "rss" || $op == "dlg") && !$_REQUEST["noxml"]) { - header("Content-Type: application/xml; charset=utf-8"); - } else { - header("Content-Type: text/plain; charset=utf-8"); - } */ + $method = $_REQUEST['subop'] ? $_REQUEST['subop'] : $_REQUEST["method"]; header("Content-Type: text/plain; charset=utf-8"); @@ -78,7 +71,7 @@ return; } else if (!($_SESSION["uid"] && validate_session($link))) { - if ($op == 'pref-feeds' && $_REQUEST['method'] == 'add') { + if ($op == 'pref-feeds' && $method == 'add') { header("Content-Type: text/html"); login_sequence($link); render_login_form($link); @@ -173,11 +166,6 @@ module_pref_labels($link); break; // pref-labels - case "pref-prefs": - require_once "modules/pref-prefs.php"; - module_pref_prefs($link); - break; // pref-prefs - case "pref-users": require_once "modules/pref-users.php"; module_pref_users($link); diff --git a/classes/pref_prefs.php b/classes/pref_prefs.php new file mode 100644 index 000000000..896268275 --- /dev/null +++ b/classes/pref_prefs.php @@ -0,0 +1,493 @@ +link, "SELECT id FROM ttrss_users WHERE + id = '$active_uid' AND (pwd_hash = '$old_pw_hash1' OR + pwd_hash = '$old_pw_hash2')"); + + if (db_num_rows($result) == 1) { + db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$new_pw_hash' + WHERE id = '$active_uid'"); + + $_SESSION["pwd_hash"] = $new_pw_hash; + + print __("Password has been changed."); + } else { + print "ERROR: ".__('Old password is incorrect.'); + } + } + + return; + + } + + function saveconfig() { + + $_SESSION["prefs_cache"] = false; + + $orig_theme = get_pref($this->link, "_THEME_ID"); + + foreach (array_keys($_POST) as $pref_name) { + + $pref_name = db_escape_string($pref_name); + $value = db_escape_string($_POST[$pref_name]); + + set_pref($this->link, $pref_name, $value); + + } + + if ($orig_theme != get_pref($this->link, "_THEME_ID")) { + print "PREFS_THEME_CHANGED"; + } else { + print __("The configuration was saved."); + } + } + + function getHelp() { + + $pref_name = db_escape_string($_REQUEST["pn"]); + + $result = db_query($this->link, "SELECT help_text FROM ttrss_prefs + WHERE pref_name = '$pref_name'"); + + if (db_num_rows($result) > 0) { + $help_text = db_fetch_result($result, 0, "help_text"); + print $help_text; + } else { + printf(__("Unknown option: %s"), $pref_name); + } + } + + function changeemail() { + + $email = db_escape_string($_POST["email"]); + $full_name = db_escape_string($_POST["full_name"]); + + $active_uid = $_SESSION["uid"]; + + db_query($this->link, "UPDATE ttrss_users SET email = '$email', + full_name = '$full_name' WHERE id = '$active_uid'"); + + print __("Your personal data has been saved."); + + return; + } + + function resetconfig() { + + $_SESSION["prefs_op_result"] = "reset-to-defaults"; + + if ($_SESSION["profile"]) { + $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; + } else { + $profile_qpart = "profile IS NULL"; + } + + db_query($this->link, "DELETE FROM ttrss_user_prefs + WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]); + + initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]); + + print "PREFS_THEME_CHANGED"; + } + + function index() { + + global $access_level_names; + + $prefs_blacklist = array("HIDE_READ_FEEDS", "FEEDS_SORT_BY_UNREAD", + "STRIP_UNSAFE_TAGS"); + + $profile_blacklist = array("ALLOW_DUPLICATE_POSTS", "PURGE_OLD_DAYS", + "PURGE_UNREAD_ARTICLES", "DIGEST_ENABLE", "DIGEST_CATCHUP", + "BLACKLISTED_TAGS", "ENABLE_API_ACCESS", "UPDATE_POST_ON_CHECKSUM_CHANGE", + "DEFAULT_UPDATE_INTERVAL", "USER_TIMEZONE", "SORT_HEADLINES_BY_FEED_DATE", + "SSL_CERT_SERIAL"); + + + if (!SINGLE_USER_MODE) { + + $_SESSION["prefs_op_result"] = ""; + + print "
"; + print "
"; + + print "
"; + + print ""; + + print ""; + + $result = db_query($this->link, "SELECT email,full_name, + access_level FROM ttrss_users + WHERE id = ".$_SESSION["uid"]); + + $email = htmlspecialchars(db_fetch_result($result, 0, "email")); + $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); + + print ""; + print ""; + + print ""; + print ""; + + if (!SINGLE_USER_MODE) { + $access_level = db_fetch_result($result, 0, "access_level"); + print ""; + print ""; + } + + print "
".__('Full name')."
".__('E-mail')."
".__('Access level')."" . $access_level_names[$access_level] . "
"; + + print ""; + print ""; + + print "

"; + + print "

"; + + print "
"; # pane + print "
"; + + $result = db_query($this->link, "SELECT id FROM ttrss_users + WHERE id = ".$_SESSION["uid"]." AND pwd_hash + = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); + + if (db_num_rows($result) != 0) { + print format_warning(__("Your password is at default value, please change it."), "default_pass_warning"); + } + + print "
"; + + print ""; + + print ""; + + print ""; + print ""; + + print ""; + + print ""; + + print ""; + + print ""; + + print "
".__("Old password")."
".__("New password")."
".__("Confirm password")."
"; + + print ""; + print ""; + + print "

"; + + print "

"; + + print "
"; #pane + } + + print "
"; + + print "
"; + + print ""; + + print '
'; + + print '
'; + + if ($_SESSION["profile"]) { + print_notice("Some preferences are only available in default profile."); + } + + if ($_SESSION["profile"]) { + initialize_user_prefs($this->link, $_SESSION["uid"], $_SESSION["profile"]); + $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; + } else { + initialize_user_prefs($this->link, $_SESSION["uid"]); + $profile_qpart = "profile IS NULL"; + } + + $result = db_query($this->link, "SELECT + ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, + section_name,def_value,section_id + FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs + WHERE type_id = ttrss_prefs_types.id AND + $profile_qpart AND + section_id = ttrss_prefs_sections.id AND + ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND + short_desc != '' AND + owner_uid = ".$_SESSION["uid"]." + ORDER BY section_id,short_desc"); + + $lnum = 0; + + $active_section = ""; + + while ($line = db_fetch_assoc($result)) { + + if (in_array($line["pref_name"], $prefs_blacklist)) { + continue; + } + + if ($_SESSION["profile"] && in_array($line["pref_name"], + $profile_blacklist)) { + continue; + } + + if ($active_section != $line["section_name"]) { + + if ($active_section != "") { + print ""; + } + + print ""; + + $active_section = $line["section_name"]; + + print ""; + + if ($line["section_id"] == 2) { + print ""; + + $user_theme = get_pref($this->link, "_THEME_ID"); + $themes = get_all_themes(); + + print ""; + } + $lnum = 0; + } + + print ""; + + $type_name = $line["type_name"]; + $pref_name = $line["pref_name"]; + $value = $line["value"]; + $def_value = $line["def_value"]; + $help_text = $line["help_text"]; + + print ""; + + print ""; + + print ""; + + $lnum++; + } + + print "

".__($active_section)."

".__("Select theme")."
" . __($line["short_desc"]); + + if ($help_text) print "
".__($help_text)."
"; + + print "
"; + + if ($pref_name == "USER_TIMEZONE") { + + $timezones = explode("\n", file_get_contents("lib/timezones.txt")); + + print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); + } else if ($pref_name == "USER_STYLESHEET") { + + print ""; + + } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") { + + $limits = array(15, 30, 45, 60); + + print_select($pref_name, $value, $limits, + 'dojoType="dijit.form.Select"'); + + } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { + + global $update_intervals_nodefault; + + print_select_hash($pref_name, $value, $update_intervals_nodefault, + 'dojoType="dijit.form.Select"'); + + } else if ($type_name == "bool") { + + if ($value == "true") { + $value = __("Yes"); + } else { + $value = __("No"); + } + + if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { + $disabled = "disabled=\"1\""; + $value = __("Yes"); + } else { + $disabled = ""; + } + + print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")), + $disabled); + + } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT', + 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { + + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; + + if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { + $disabled = "disabled=\"1\""; + $value = FORCE_ARTICLE_PURGE; + } else { + $disabled = ""; + } + + print ""; + + } else if ($pref_name == "SSL_CERT_SERIAL") { + + print ""; + + $cert_serial = htmlspecialchars(get_ssl_certificate_id()); + $has_serial = ($cert_serial) ? "false" : "true"; + + print " "; + + print " "; + + } else { + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; + + print ""; + } + + print "
"; + + print '
'; # inside pane + print '
'; + + print ""; + print ""; + + print " "; + + print " "; + + print ""; + + print '
'; # inner pane + print '
'; # border container + + print "
"; + + print "
"; #pane + print "
"; #container + } +} +?> diff --git a/js/prefs.js b/js/prefs.js index 98b581ca1..d1d02afd5 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -955,7 +955,7 @@ function validatePrefsReset() { if (ok) { - query = "?op=pref-prefs&method=reset-config"; + query = "?op=pref-prefs&method=resetconfig"; console.log(query); new Ajax.Request("backend.php", { diff --git a/modules/pref-prefs.php b/modules/pref-prefs.php deleted file mode 100644 index 15fa53490..000000000 --- a/modules/pref-prefs.php +++ /dev/null @@ -1,512 +0,0 @@ - 0) { - $help_text = db_fetch_result($result, 0, "help_text"); - print $help_text; - } else { - printf(__("Unknown option: %s"), $pref_name); - } - - } else if ($method == "change-email") { - - $email = db_escape_string($_POST["email"]); - $full_name = db_escape_string($_POST["full_name"]); - - $active_uid = $_SESSION["uid"]; - - db_query($link, "UPDATE ttrss_users SET email = '$email', - full_name = '$full_name' WHERE id = '$active_uid'"); - - print __("Your personal data has been saved."); - - return; - - } else if ($method == "reset-config") { - - $_SESSION["prefs_op_result"] = "reset-to-defaults"; - - if ($_SESSION["profile"]) { - $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; - } else { - $profile_qpart = "profile IS NULL"; - } - - db_query($link, "DELETE FROM ttrss_user_prefs - WHERE $profile_qpart AND owner_uid = ".$_SESSION["uid"]); - - initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]); - - print "PREFS_THEME_CHANGED"; - -// print __("The configuration was reset to defaults."); - - return; - - } else { - - if (!SINGLE_USER_MODE) { - - $_SESSION["prefs_op_result"] = ""; - - print "
"; - print "
"; - - print "
"; - - print ""; - - print ""; - - $result = db_query($link, "SELECT email,full_name, - access_level FROM ttrss_users - WHERE id = ".$_SESSION["uid"]); - - $email = htmlspecialchars(db_fetch_result($result, 0, "email")); - $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); - - print ""; - print ""; - - print ""; - print ""; - - if (!SINGLE_USER_MODE) { - $access_level = db_fetch_result($result, 0, "access_level"); - print ""; - print ""; - } - - print "
".__('Full name')."
".__('E-mail')."
".__('Access level')."" . $access_level_names[$access_level] . "
"; - - print ""; - print ""; - - print "

"; - - print "

"; - - print "
"; # pane - print "
"; - - $result = db_query($link, "SELECT id FROM ttrss_users - WHERE id = ".$_SESSION["uid"]." AND pwd_hash - = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); - - if (db_num_rows($result) != 0) { - print format_warning(__("Your password is at default value, please change it."), "default_pass_warning"); - } - - print "
"; - - print ""; - - print ""; - - print ""; - print ""; - - print ""; - - print ""; - - print ""; - - print ""; - - print "
".__("Old password")."
".__("New password")."
".__("Confirm password")."
"; - - print ""; - print ""; - - print "

"; - - print "

"; - - print "
"; #pane - } - - print "
"; - - print "
"; - - print ""; - - - print '
'; - - print '
'; - - if ($_SESSION["profile"]) { - print_notice("Some preferences are only available in default profile."); - } - - if ($_SESSION["profile"]) { - initialize_user_prefs($link, $_SESSION["uid"], $_SESSION["profile"]); - $profile_qpart = "profile = '" . $_SESSION["profile"] . "'"; - } else { - initialize_user_prefs($link, $_SESSION["uid"]); - $profile_qpart = "profile IS NULL"; - } - - $result = db_query($link, "SELECT - ttrss_user_prefs.pref_name,short_desc,help_text,value,type_name, - section_name,def_value,section_id - FROM ttrss_prefs,ttrss_prefs_types,ttrss_prefs_sections,ttrss_user_prefs - WHERE type_id = ttrss_prefs_types.id AND - $profile_qpart AND - section_id = ttrss_prefs_sections.id AND - ttrss_user_prefs.pref_name = ttrss_prefs.pref_name AND - short_desc != '' AND - owner_uid = ".$_SESSION["uid"]." - ORDER BY section_id,short_desc"); - - $lnum = 0; - - $active_section = ""; - - while ($line = db_fetch_assoc($result)) { - - if (in_array($line["pref_name"], $prefs_blacklist)) { - continue; - } - - if ($_SESSION["profile"] && in_array($line["pref_name"], - $profile_blacklist)) { - continue; - } - - if ($active_section != $line["section_name"]) { - - if ($active_section != "") { - print ""; - } - - print ""; - - $active_section = $line["section_name"]; - - print ""; - - if ($line["section_id"] == 2) { - print ""; - - $user_theme = get_pref($link, "_THEME_ID"); - $themes = get_all_themes(); - - print ""; - } - -// print " -// "; - - $lnum = 0; - } - -// $class = ($lnum % 2) ? "even" : "odd"; - - print ""; - - $type_name = $line["type_name"]; - $pref_name = $line["pref_name"]; - $value = $line["value"]; - $def_value = $line["def_value"]; - $help_text = $line["help_text"]; - - print ""; - - print ""; - - print ""; - - $lnum++; - } - - print "

".__($active_section)."

".__("Select theme")."
OptionValue
" . __($line["short_desc"]); - - if ($help_text) print "
".__($help_text)."
"; - - print "
"; - - if ($pref_name == "USER_TIMEZONE") { - - $timezones = explode("\n", file_get_contents("lib/timezones.txt")); - - print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"'); - } else if ($pref_name == "USER_STYLESHEET") { - - print ""; - - } else if ($pref_name == "DEFAULT_ARTICLE_LIMIT") { - - $limits = array(15, 30, 45, 60); - - print_select($pref_name, $value, $limits, - 'dojoType="dijit.form.Select"'); - - } else if ($pref_name == "DEFAULT_UPDATE_INTERVAL") { - - global $update_intervals_nodefault; - - print_select_hash($pref_name, $value, $update_intervals_nodefault, - 'dojoType="dijit.form.Select"'); - - } else if ($type_name == "bool") { -// print_select($pref_name, $value, array("true", "false")); - - if ($value == "true") { - $value = __("Yes"); - } else { - $value = __("No"); - } - - if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) { - $disabled = "disabled=\"1\""; - $value = __("Yes"); - } else { - $disabled = ""; - } - - print_radio($pref_name, $value, __("Yes"), array(__("Yes"), __("No")), - $disabled); - - } else if (array_search($pref_name, array('FRESH_ARTICLE_MAX_AGE', 'DEFAULT_ARTICLE_LIMIT', - 'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT')) !== false) { - - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; - - if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) { - $disabled = "disabled=\"1\""; - $value = FORCE_ARTICLE_PURGE; - } else { - $disabled = ""; - } - - print ""; - - } else if ($pref_name == "SSL_CERT_SERIAL") { - - print ""; - - $cert_serial = htmlspecialchars(get_ssl_certificate_id()); - $has_serial = ($cert_serial) ? "false" : "true"; - - print " "; - - print " "; - - } else { - $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; - - print ""; - } - - print "
"; - - print '
'; # inside pane - print '
'; - - print ""; - print ""; - - print " "; - - print " "; - - print ""; - - print '
'; # inner pane - print '
'; # border container - - print "
"; - - print "
"; #pane - print "
"; #container - - } - } -?> -- cgit v1.2.3-54-g00ecf From 611efae712769e38e232478b484779d73af263db Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 10:58:30 +0400 Subject: add catchall backend class --- backend.php | 4 ---- classes/article.php | 32 ++++++++++++++++---------------- classes/backend.php | 10 ++++++++++ js/digest.js | 2 +- js/viewfeed.js | 4 ++-- 5 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 classes/backend.php (limited to 'js') diff --git a/backend.php b/backend.php index 8220337ac..0390ed761 100644 --- a/backend.php +++ b/backend.php @@ -181,10 +181,6 @@ module_pref_instances($link); break; // pref-instances - case "digestTest": - print_r(prepare_headlines_digest($link, $_SESSION["uid"])); - break; // digestTest - case "digestSend": send_headlines_digests($link); break; // digestSend diff --git a/classes/article.php b/classes/article.php index 98141d91e..70ecd2653 100644 --- a/classes/article.php +++ b/classes/article.php @@ -1,20 +1,20 @@ link, "SELECT link FROM ttrss_entries, ttrss_user_entries WHERE id = '$id' AND id = ref_id AND owner_uid = '".$_SESSION['uid']."' LIMIT 1"); - + if (db_num_rows($result) == 1) { $article_url = db_fetch_result($result, 0, 'link'); $article_url = str_replace("\n", "", $article_url); - + header("Location: $article_url"); return; - + } else { print_error(__("Article not found.")); } @@ -25,12 +25,12 @@ class Article extends Handler { $cids = explode(",", db_escape_string($_REQUEST["cids"])); $mode = db_escape_string($_REQUEST["mode"]); $omode = db_escape_string($_REQUEST["omode"]); - + // in prefetch mode we only output requested cids, main article // just gets marked as read (it already exists in client cache) - + $articles = array(); - + if ($mode == "") { array_push($articles, format_article($this->link, $id, false)); } else if ($mode == "zoom") { @@ -40,14 +40,14 @@ class Article extends Handler { header("Content-Type: text/html"); print ''; } - + $article = format_article($this->link, $id, false); print $article['content']; return; } - + catchupArticleById($this->link, $id, 0); - + if (!$_SESSION["bw_limit"]) { foreach ($cids as $cid) { if ($cid) { @@ -55,9 +55,9 @@ class Article extends Handler { } } } - + print json_encode($articles); - + } - -} \ No newline at end of file + +} diff --git a/classes/backend.php b/classes/backend.php new file mode 100644 index 000000000..47fc2d826 --- /dev/null +++ b/classes/backend.php @@ -0,0 +1,10 @@ +"; + } +} +?> diff --git a/js/digest.js b/js/digest.js index fc0446d83..12d45e536 100644 --- a/js/digest.js +++ b/js/digest.js @@ -805,7 +805,7 @@ function tweet_article(id) { var d = new Date(); var ts = d.getTime(); - var w = window.open('backend.php?op=loading', 'ttrss_tweet', + var w = window.open('backend.php?op=backend&method=loading', 'ttrss_tweet', "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0"); new Ajax.Request("backend.php", { diff --git a/js/viewfeed.js b/js/viewfeed.js index b9b2a8e2b..d267c7693 100644 --- a/js/viewfeed.js +++ b/js/viewfeed.js @@ -1770,7 +1770,7 @@ function getLastVisibleHeadlineId() { function openArticleInNewWindow(id) { toggleUnread(id, 0, false); - window.open("backend.php?op=article&id=" + id); + window.open("backend.php?op=article&method=redirect&id=" + id); } function isCdmMode() { @@ -2003,7 +2003,7 @@ function tweetArticle(id) { var d = new Date(); var ts = d.getTime(); - var w = window.open('backend.php?op=loading', 'ttrss_tweet', + var w = window.open('backend.php?op=backend&method=loading', 'ttrss_tweet', "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0"); new Ajax.Request("backend.php", { -- cgit v1.2.3-54-g00ecf From 4f09f594c24a2fbdacd6124ecdeb07b92814cb88 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 11:02:43 +0400 Subject: move help to backend class --- backend.php | 15 --------------- classes/backend.php | 18 ++++++++++++++++++ js/functions.js | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) (limited to 'js') diff --git a/backend.php b/backend.php index 0390ed761..8f197ee30 100644 --- a/backend.php +++ b/backend.php @@ -171,26 +171,11 @@ module_pref_users($link); break; // prefs-users - case "help": - require_once "modules/help.php"; - module_help($link); - break; // help - case "pref-instances": require_once "modules/pref-instances.php"; module_pref_instances($link); break; // pref-instances - case "digestSend": - send_headlines_digests($link); - break; // digestSend - - case "loading": - header("Content-type: text/html"); - print __("Loading, please wait...") . " " . - ""; - break; // loading - default: header("Content-Type: text/plain"); print json_encode(array("error" => array("code" => 7))); diff --git a/classes/backend.php b/classes/backend.php index 47fc2d826..f7e7b84b8 100644 --- a/classes/backend.php +++ b/classes/backend.php @@ -6,5 +6,23 @@ class Backend extends Handler { print __("Loading, please wait...") . " " . ""; } + + function digestSend() { + send_headlines_digests($this->link); + } + + function help() { + $tid = (int) $_REQUEST["tid"]; + + if (file_exists("help/$tid.php")) { + include("help/$tid.php"); + } else { + print "

".__("Help topic not found.")."

"; + } + print "
+
"; + + } } ?> diff --git a/js/functions.js b/js/functions.js index 37aa73bc9..69406f3e1 100644 --- a/js/functions.js +++ b/js/functions.js @@ -636,7 +636,7 @@ function explainError(code) { function displayHelpInfobox(topic_id) { - var url = "backend.php?op=help&tid=" + param_escape(topic_id); + var url = "backend.php?op=backend&method=help&tid=" + param_escape(topic_id); window.open(url, "ttrss_help", "status=0,toolbar=0,location=0,width=450,height=500,scrollbars=1,menubar=0"); -- cgit v1.2.3-54-g00ecf From cbe50c800d4846be184673e623063abee7101a0c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 13:34:43 +0400 Subject: add pref_labels class --- backend.php | 5 - classes/pref_labels.php | 320 +++++++++++++++++++++++++++++++++++++++++++++++ js/prefs.js | 47 ++----- modules/pref-labels.php | 321 ------------------------------------------------ 4 files changed, 331 insertions(+), 362 deletions(-) create mode 100644 classes/pref_labels.php delete mode 100644 modules/pref-labels.php (limited to 'js') diff --git a/backend.php b/backend.php index f0dc6ae11..5511668cf 100644 --- a/backend.php +++ b/backend.php @@ -161,11 +161,6 @@ module_pref_filters($link); break; // pref-filters - case "pref_labels": - require_once "modules/pref-labels.php"; - module_pref_labels($link); - break; // pref-labels - case "pref_users": require_once "modules/pref-users.php"; module_pref_users($link); diff --git a/classes/pref_labels.php b/classes/pref_labels.php new file mode 100644 index 000000000..5de4443f7 --- /dev/null +++ b/classes/pref_labels.php @@ -0,0 +1,320 @@ +link, "SELECT * FROM ttrss_labels2 WHERE + id = '$label_id' AND owner_uid = " . $_SESSION["uid"]); + + $line = db_fetch_assoc($result); + + print ""; + print ""; + print ""; + + print "
".__("Caption")."
"; + + print "
"; + + $fg_color = $line['fg_color']; + $bg_color = $line['bg_color']; + + print "α"; + + print ""; + + print "
"; + print "
" . __("Colors") . "
"; + print "
"; + + print ""; + + print ""; + + print "
".__("Foreground:")."".__("Background:"). + "
"; + + print ""; + print ""; + + print "
+ +
"; + print ""; + + print "
"; + + print "
+ +
"; + print ""; + + print "
"; + print "
"; + +# print ""; + + print "
"; + print ""; + print ""; + print "
"; + + return; + } + + function getlabeltree() { + $root = array(); + $root['id'] = 'root'; + $root['name'] = __('Labels'); + $root['items'] = array(); + + $result = db_query($this->link, "SELECT * + FROM ttrss_labels2 + WHERE owner_uid = ".$_SESSION["uid"]." + ORDER BY caption"); + + while ($line = db_fetch_assoc($result)) { + $label = array(); + $label['id'] = 'LABEL:' . $line['id']; + $label['bare_id'] = $line['id']; + $label['name'] = $line['caption']; + $label['fg_color'] = $line['fg_color']; + $label['bg_color'] = $line['bg_color']; + $label['type'] = 'label'; + $label['checkbox'] = false; + + array_push($root['items'], $label); + } + + $fl = array(); + $fl['identifier'] = 'id'; + $fl['label'] = 'name'; + $fl['items'] = array($root); + + print json_encode($fl); + return; + } + + function colorset() { + $kind = db_escape_string($_REQUEST["kind"]); + $ids = split(',', db_escape_string($_REQUEST["ids"])); + $color = db_escape_string($_REQUEST["color"]); + $fg = db_escape_string($_REQUEST["fg"]); + $bg = db_escape_string($_REQUEST["bg"]); + + foreach ($ids as $id) { + + if ($kind == "fg" || $kind == "bg") { + db_query($this->link, "UPDATE ttrss_labels2 SET + ${kind}_color = '$color' WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + } else { + db_query($this->link, "UPDATE ttrss_labels2 SET + fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + } + + $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); + + /* Remove cached data */ + + db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' + WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); + + } + + return; + } + + function colorreset() { + $ids = split(',', db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + db_query($this->link, "UPDATE ttrss_labels2 SET + fg_color = '', bg_color = '' WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + + $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"])); + + /* Remove cached data */ + + db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = '' + WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); + } + + } + + function save() { + + $id = db_escape_string($_REQUEST["id"]); + $caption = db_escape_string(trim($_REQUEST["caption"])); + + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT caption FROM ttrss_labels2 + WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + $old_caption = db_fetch_result($result, 0, "caption"); + + $result = db_query($this->link, "SELECT id FROM ttrss_labels2 + WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); + + if (db_num_rows($result) == 0) { + if ($caption) { + $result = db_query($this->link, "UPDATE ttrss_labels2 SET + caption = '$caption' WHERE id = '$id' AND + owner_uid = " . $_SESSION["uid"]); + + /* Update filters that reference label being renamed */ + + $old_caption = db_escape_string($old_caption); + + db_query($this->link, "UPDATE ttrss_filters SET + action_param = '$caption' WHERE action_param = '$old_caption' + AND action_id = 7 + AND owner_uid = " . $_SESSION["uid"]); + + print $_REQUEST["value"]; + } else { + print $old_caption; + } + } else { + print $old_caption; + } + } + + db_query($this->link, "COMMIT"); + + return; + } + + function remove() { + + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + label_remove($this->link, $id, $_SESSION["uid"]); + } + + } + + function add() { + $caption = db_escape_string($_REQUEST["caption"]); + $output = db_escape_string($_REQUEST["output"]); + + if ($caption) { + + if (label_create($this->link, $caption)) { + if (!$output) { + print T_sprintf("Created label %s", htmlspecialchars($caption)); + } + } + + if ($output == "select") { + header("Content-Type: text/xml"); + + print ""; + + print_label_select($this->link, "select_label", + $caption, ""); + + print ""; + } + } + + return; + } + + function index() { + + $sort = db_escape_string($_REQUEST["sort"]); + + if (!$sort || $sort == "undefined") { + $sort = "caption"; + } + + $label_search = db_escape_string($_REQUEST["search"]); + + if (array_key_exists("search", $_REQUEST)) { + $_SESSION["prefs_label_search"] = $label_search; + } else { + $label_search = $_SESSION["prefs_label_search"]; + } + + print "
"; + print "
"; + print "
"; + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print" "; + + print " "; + + print ""; + + + print "
"; #toolbar + print "
"; #pane + print "
"; + + print "
+ ". + __("Loading, please wait...")."
"; + + print "
+
+
+
+
+ + +
"; + + print "
"; #pane + print "
"; #container + + } +} + +?> diff --git a/js/prefs.js b/js/prefs.js index d1d02afd5..4e1dadda2 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -15,30 +15,11 @@ function instancelist_callback2(transport) { } } -function feedlist_callback2(transport) { - try { - dijit.byId('feedConfigTab').attr('content', transport.responseText); - selectTab("feedConfig", true); - notify(""); - } catch (e) { - exception_error("feedlist_callback2", e); - } -} - function filterlist_callback2(transport) { dijit.byId('filterConfigTab').attr('content', transport.responseText); notify(""); } -function labellist_callback2(transport) { - try { - dijit.byId('labelConfigTab').attr('content', transport.responseText); - notify(""); - } catch (e) { - exception_error("labellist_callback2", e); - } -} - function userlist_callback2(transport) { try { dijit.byId('userConfigTab').attr('content', transport.responseText); @@ -49,16 +30,6 @@ function userlist_callback2(transport) { } } -function prefslist_callback2(transport) { - try { - dijit.byId('genConfigTab').attr('content', transport.responseText); - - notify(""); - } catch (e) { - exception_error("prefslist_callback2", e); - } -} - function notify_callback2(transport) { notify_info(transport.responseText); } @@ -72,7 +43,9 @@ function updateFeedList(sort_key) { new Ajax.Request("backend.php", { parameters: "?op=pref-feeds&search=" + param_escape(search), onComplete: function(transport) { - feedlist_callback2(transport); + dijit.byId('feedConfigTab').attr('content', transport.responseText); + selectTab("feedConfig", true); + notify(""); } }); } @@ -329,7 +302,7 @@ function removeSelectedLabels() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - labellist_callback2(transport); + updateLabelList(); } }); } @@ -851,7 +824,8 @@ function updateLabelList() { new Ajax.Request("backend.php", { parameters: "?op=pref-labels", onComplete: function(transport) { - labellist_callback2(transport); + dijit.byId('labelConfigTab').attr('content', transport.responseText); + notify(""); } }); } @@ -859,7 +833,8 @@ function updatePrefsList() { new Ajax.Request("backend.php", { parameters: "?op=pref-prefs", onComplete: function(transport) { - prefslist_callback2(transport); + dijit.byId('genConfigTab').attr('content', transport.responseText); + notify(""); } }); } @@ -1440,13 +1415,13 @@ function labelColorReset() { var ok = confirm(__("Reset selected labels to default colors?")); if (ok) { - var query = "?op=pref-labels&method=color-reset&ids="+ + var query = "?op=pref-labels&method=colorreset&ids="+ param_escape(labels.toString()); new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - labellist_callback2(transport); + updateLabelList(); } }); } @@ -1705,7 +1680,7 @@ function editLabel(id, event) { color = bg; } - var query = "?op=pref-labels&method=color-set&kind="+kind+ + var query = "?op=pref-labels&method=colorset&kind="+kind+ "&ids=" + param_escape(id) + "&fg=" + param_escape(fg) + "&bg=" + param_escape(bg) + "&color=" + param_escape(color); diff --git a/modules/pref-labels.php b/modules/pref-labels.php deleted file mode 100644 index f9f2c19e3..000000000 --- a/modules/pref-labels.php +++ /dev/null @@ -1,321 +0,0 @@ -"; - - print ""; - print ""; - print ""; - - print "
".__("Caption")."
"; - - print "
"; - - $fg_color = $line['fg_color']; - $bg_color = $line['bg_color']; - - print "α"; - - print ""; - - print "
"; - print "
" . __("Colors") . "
"; - print "
"; - - print ""; - - print ""; - - print "
".__("Foreground:")."".__("Background:"). - "
"; - - print ""; - print ""; - - print "
- -
"; - print ""; - - print "
"; - - print "
- -
"; - print ""; - - print "
"; - print "
"; - -# print ""; - - print "
"; - print ""; - print ""; - print "
"; - - return; - } - - if ($method == "getlabeltree") { - $root = array(); - $root['id'] = 'root'; - $root['name'] = __('Labels'); - $root['items'] = array(); - - $result = db_query($link, "SELECT * - FROM ttrss_labels2 - WHERE owner_uid = ".$_SESSION["uid"]." - ORDER BY caption"); - - while ($line = db_fetch_assoc($result)) { - $label = array(); - $label['id'] = 'LABEL:' . $line['id']; - $label['bare_id'] = $line['id']; - $label['name'] = $line['caption']; - $label['fg_color'] = $line['fg_color']; - $label['bg_color'] = $line['bg_color']; - $label['type'] = 'label'; - $label['checkbox'] = false; - - array_push($root['items'], $label); - } - - $fl = array(); - $fl['identifier'] = 'id'; - $fl['label'] = 'name'; - $fl['items'] = array($root); - - print json_encode($fl); - return; - } - - if ($method == "color-set") { - $kind = db_escape_string($_REQUEST["kind"]); - $ids = split(',', db_escape_string($_REQUEST["ids"])); - $color = db_escape_string($_REQUEST["color"]); - $fg = db_escape_string($_REQUEST["fg"]); - $bg = db_escape_string($_REQUEST["bg"]); - - foreach ($ids as $id) { - - if ($kind == "fg" || $kind == "bg") { - db_query($link, "UPDATE ttrss_labels2 SET - ${kind}_color = '$color' WHERE id = '$id' - AND owner_uid = " . $_SESSION["uid"]); - } else { - db_query($link, "UPDATE ttrss_labels2 SET - fg_color = '$fg', bg_color = '$bg' WHERE id = '$id' - AND owner_uid = " . $_SESSION["uid"]); - } - - $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); - - /* Remove cached data */ - - db_query($link, "UPDATE ttrss_user_entries SET label_cache = '' - WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); - - } - - return; - } - - if ($method == "color-reset") { - $ids = split(',', db_escape_string($_REQUEST["ids"])); - - foreach ($ids as $id) { - db_query($link, "UPDATE ttrss_labels2 SET - fg_color = '', bg_color = '' WHERE id = '$id' - AND owner_uid = " . $_SESSION["uid"]); - - $caption = db_escape_string(label_find_caption($link, $id, $_SESSION["uid"])); - - /* Remove cached data */ - - db_query($link, "UPDATE ttrss_user_entries SET label_cache = '' - WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]); - } - - } - - if ($method == "save") { - - $id = db_escape_string($_REQUEST["id"]); - $caption = db_escape_string(trim($_REQUEST["caption"])); - - db_query($link, "BEGIN"); - - $result = db_query($link, "SELECT caption FROM ttrss_labels2 - WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]); - - if (db_num_rows($result) != 0) { - $old_caption = db_fetch_result($result, 0, "caption"); - - $result = db_query($link, "SELECT id FROM ttrss_labels2 - WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]); - - if (db_num_rows($result) == 0) { - if ($caption) { - $result = db_query($link, "UPDATE ttrss_labels2 SET - caption = '$caption' WHERE id = '$id' AND - owner_uid = " . $_SESSION["uid"]); - - /* Update filters that reference label being renamed */ - - $old_caption = db_escape_string($old_caption); - - db_query($link, "UPDATE ttrss_filters SET - action_param = '$caption' WHERE action_param = '$old_caption' - AND action_id = 7 - AND owner_uid = " . $_SESSION["uid"]); - - print $_REQUEST["value"]; - } else { - print $old_caption; - } - } else { - print $old_caption; - } - } - - db_query($link, "COMMIT"); - - return; - } - - if ($method == "remove") { - - $ids = split(",", db_escape_string($_REQUEST["ids"])); - - foreach ($ids as $id) { - label_remove($link, $id, $_SESSION["uid"]); - } - - } - - if ($method == "add") { - $caption = db_escape_string($_REQUEST["caption"]); - $output = db_escape_string($_REQUEST["output"]); - - if ($caption) { - - if (label_create($link, $caption)) { - if (!$output) { - print T_sprintf("Created label %s", htmlspecialchars($caption)); - } - } - - if ($output == "select") { - header("Content-Type: text/xml"); - - print ""; - - print_label_select($link, "select_label", - $caption, ""); - - print ""; - } - } - - return; - } - - $sort = db_escape_string($_REQUEST["sort"]); - - if (!$sort || $sort == "undefined") { - $sort = "caption"; - } - - $label_search = db_escape_string($_REQUEST["search"]); - - if (array_key_exists("search", $_REQUEST)) { - $_SESSION["prefs_label_search"] = $label_search; - } else { - $label_search = $_SESSION["prefs_label_search"]; - } - - print "
"; - print "
"; - print "
"; - - print "
". - "" . __('Select').""; - print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; - print "
"; - - print" "; - - print " "; - - print ""; - - - print "
"; #toolbar - print "
"; #pane - print "
"; - - print "
- ". - __("Loading, please wait...")."
"; - - print "
-
-
-
-
- - -
"; - - print "
"; #pane - print "
"; #container - } - -?> -- cgit v1.2.3-54-g00ecf From 66665fba79c97dc3b96103e60945aedd0b9be676 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 13 Dec 2011 14:00:36 +0400 Subject: add Pref_Users class --- backend.php | 5 - classes/pref_users.php | 483 +++++++++++++++++++++++++++++++++++++++++++++++ js/prefs.js | 53 ++---- modules/pref-users.php | 501 ------------------------------------------------- 4 files changed, 499 insertions(+), 543 deletions(-) create mode 100644 classes/pref_users.php delete mode 100644 modules/pref-users.php (limited to 'js') diff --git a/backend.php b/backend.php index 5511668cf..9dd4c6f55 100644 --- a/backend.php +++ b/backend.php @@ -161,11 +161,6 @@ module_pref_filters($link); break; // pref-filters - case "pref_users": - require_once "modules/pref-users.php"; - module_pref_users($link); - break; // prefs-users - case "pref_instances": require_once "modules/pref-instances.php"; module_pref_instances($link); diff --git a/classes/pref_users.php b/classes/pref_users.php new file mode 100644 index 000000000..5f762b50e --- /dev/null +++ b/classes/pref_users.php @@ -0,0 +1,483 @@ +"; + + $uid = sprintf("%d", $_REQUEST["id"]); + + print "".__('User details').""; + + print "link, "SELECT login, + ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login, + access_level, + (SELECT COUNT(int_id) FROM ttrss_user_entries + WHERE owner_uid = id) AS stored_articles, + ".SUBSTRING_FOR_DATE."(created,1,16) AS created + FROM ttrss_users + WHERE id = '$uid'"); + + if (db_num_rows($result) == 0) { + print "

".__('User not found')."

"; + return; + } + + // print "

User Details

"; + + $login = db_fetch_result($result, 0, "login"); + + print ""; + + $last_login = make_local_datetime($this->link, + db_fetch_result($result, 0, "last_login"), true); + + $created = make_local_datetime($this->link, + db_fetch_result($result, 0, "created"), true); + + $access_level = db_fetch_result($result, 0, "access_level"); + $stored_articles = db_fetch_result($result, 0, "stored_articles"); + + print ""; + print ""; + + $result = db_query($this->link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds + WHERE owner_uid = '$uid'"); + + $num_feeds = db_fetch_result($result, 0, "num_feeds"); + + print ""; + + print "
".__('Registered')."$created
".__('Last logged in')."$last_login
".__('Subscribed feeds count')."$num_feeds
"; + + print "

".__('Subscribed feeds')."

"; + + $result = db_query($this->link, "SELECT id,title,site_url FROM ttrss_feeds + WHERE owner_uid = '$uid' ORDER BY title"); + + print "
    "; + + $row_class = "odd"; + + while ($line = db_fetch_assoc($result)) { + + $icon_file = ICONS_URL."/".$line["id"].".ico"; + + if (file_exists($icon_file) && filesize($icon_file) > 0) { + $feed_icon = ""; + } else { + $feed_icon = ""; + } + + print "
  • $feed_icon ".$line["title"]."
  • "; + + $row_class = $row_class == "even" ? "odd" : "even"; + + } + + if (db_num_rows($result) < $num_feeds) { + // FIXME - add link to show ALL subscribed feeds here somewhere + print "
  •  ...
  • "; + } + + print "
"; + + print "
+
"; + + print "]]>
"; + + return; + } + + function edit() { + global $access_level_names; + + header("Content-Type: text/xml"); + + $id = db_escape_string($_REQUEST["id"]); + + print ""; + print "".__('User Editor').""; + print ""; + + print ""; + print ""; + print ""; + + $result = db_query($this->link, "SELECT * FROM ttrss_users WHERE id = '$id'"); + + $login = db_fetch_result($result, 0, "login"); + $access_level = db_fetch_result($result, 0, "access_level"); + $email = db_fetch_result($result, 0, "email"); + + $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : ""; + + print "
".__("User")."
"; + print "
"; + + if ($sel_disabled) { + print ""; + print ""; + } else { + print ""; + } + + print "
"; + + print "
".__("Authentication")."
"; + print "
"; + + print __('Access level: ') . " "; + + if (!$sel_disabled) { + print_select_hash("access_level", $access_level, $access_level_names, + $sel_disabled); + } else { + print_select_hash("", $access_level, $access_level_names, + $sel_disabled); + print ""; + } + + print "
"; + + print __('Change password to') . + " "; + + print "
"; + + print "
".__("Options")."
"; + print "
"; + + print __('E-mail: '). + " "; + + print "
"; + + print ""; + + print ""; + + print "
+ +
"; + + print "]]>
"; + + return; + } + + function editSave() { + $login = db_escape_string(trim($_REQUEST["login"])); + $uid = db_escape_string($_REQUEST["id"]); + $access_level = (int) $_REQUEST["access_level"]; + $email = db_escape_string(trim($_REQUEST["email"])); + $password = db_escape_string(trim($_REQUEST["password"])); + + if ($password) { + $pwd_hash = encrypt_password($password, $login); + $pass_query_part = "pwd_hash = '$pwd_hash', "; + } else { + $pass_query_part = ""; + } + + db_query($this->link, "UPDATE ttrss_users SET $pass_query_part login = '$login', + access_level = '$access_level', email = '$email' WHERE id = '$uid'"); + + } + + function remove() { + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + if ($id != $_SESSION["uid"] && $id != 1) { + db_query($this->link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'"); + db_query($this->link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'"); + db_query($this->link, "DELETE FROM ttrss_users WHERE id = '$id'"); + } + } + } + + function add() { + + $login = db_escape_string(trim($_REQUEST["login"])); + $tmp_user_pwd = make_password(8); + $pwd_hash = encrypt_password($tmp_user_pwd, $login); + + $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE + login = '$login'"); + + if (db_num_rows($result) == 0) { + + db_query($this->link, "INSERT INTO ttrss_users + (login,pwd_hash,access_level,last_login,created) + VALUES ('$login', '$pwd_hash', 0, null, NOW())"); + + + $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE + login = '$login' AND pwd_hash = '$pwd_hash'"); + + if (db_num_rows($result) == 1) { + + $new_uid = db_fetch_result($result, 0, "id"); + + print format_notice(T_sprintf("Added user %s with password %s", + $login, $tmp_user_pwd)); + + initialize_user($this->link, $new_uid); + + } else { + + print format_warning(T_sprintf("Could not create user %s", $login)); + + } + } else { + print format_warning(T_sprintf("User %s already exists.", $login)); + } + } + + function resetPass() { + + $uid = db_escape_string($_REQUEST["id"]); + + $result = db_query($this->link, "SELECT login,email + FROM ttrss_users WHERE id = '$uid'"); + + $login = db_fetch_result($result, 0, "login"); + $email = db_fetch_result($result, 0, "email"); + $tmp_user_pwd = make_password(8); + $pwd_hash = encrypt_password($tmp_user_pwd, $login); + + db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' + WHERE id = '$uid'"); + + print T_sprintf("Changed password of user %s + to %s", $login, $tmp_user_pwd); + + require_once 'lib/phpmailer/class.phpmailer.php'; + + if ($email) { + print " "; + print T_sprintf("Notifying %s.", $email); + + require_once "lib/MiniTemplator.class.php"; + + $tpl = new MiniTemplator; + + $tpl->readTemplateFromFile("templates/resetpass_template.txt"); + + $tpl->setVariable('LOGIN', $login); + $tpl->setVariable('NEWPASS', $tmp_user_pwd); + + $tpl->addBlock('message'); + + $message = ""; + + $tpl->generateOutputToString($message); + + $mail = new PHPMailer(); + + $mail->PluginDir = "lib/phpmailer/"; + $mail->SetLanguage("en", "lib/phpmailer/language/"); + + $mail->CharSet = "UTF-8"; + + $mail->From = DIGEST_FROM_ADDRESS; + $mail->FromName = DIGEST_FROM_NAME; + $mail->AddAddress($email, $login); + + if (DIGEST_SMTP_HOST) { + $mail->Host = DIGEST_SMTP_HOST; + $mail->Mailer = "smtp"; + $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; + $mail->Username = DIGEST_SMTP_LOGIN; + $mail->Password = DIGEST_SMTP_PASSWORD; + } + + $mail->IsHTML(false); + $mail->Subject = __("[tt-rss] Password change notification"); + $mail->Body = $message; + + $rc = $mail->Send(); + + if (!$rc) print_error($mail->ErrorInfo); + } + + print ""; + } + + function index() { + + global $access_level_names; + + print "
"; + print "
"; + + print "
"; + + $user_search = db_escape_string($_REQUEST["search"]); + + if (array_key_exists("search", $_REQUEST)) { + $_SESSION["prefs_user_search"] = $user_search; + } else { + $user_search = $_SESSION["prefs_user_search"]; + } + + print "
+ + +
"; + + $sort = db_escape_string($_REQUEST["sort"]); + + if (!$sort || $sort == "undefined") { + $sort = "login"; + } + + print "
". + "" . __('Select').""; + print "
"; + print "
".__('All')."
"; + print "
".__('None')."
"; + print "
"; + + print ""; + + print " + + + + "; + + print "
"; #toolbar + print "
"; #pane + print "
"; + + print "
"; + + if ($user_search) { + + $user_search = split(" ", $user_search); + $tokens = array(); + + foreach ($user_search as $token) { + $token = trim($token); + array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))"); + } + + $user_search_query = "(" . join($tokens, " AND ") . ") AND "; + + } else { + $user_search_query = ""; + } + + $result = db_query($this->link, "SELECT + id,login,access_level,email, + ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, + ".SUBSTRING_FOR_DATE."(created,1,16) as created + FROM + ttrss_users + WHERE + $user_search_query + id > 0 + ORDER BY $sort"); + + if (db_num_rows($result) > 0) { + + print "

"; + + print " + + + + + "; + + $lnum = 0; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + + $uid = $line["id"]; + + print ""; + + $line["login"] = htmlspecialchars($line["login"]); + + $line["created"] = make_local_datetime($this->link, $line["created"], false); + $line["last_login"] = make_local_datetime($this->link, $line["last_login"], false); + + print ""; + + $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; + + print ""; + + if (!$line["email"]) $line["email"] = " "; + + print ""; + print ""; + print ""; + + print ""; + + ++$lnum; + } + + print "
 ".__('Login')."".__('Access Level')."".__('Registered')."".__('Last login')."
" . $line["login"] . "" . $access_level_names[$line["access_level"]] . "" . $line["created"] . "" . $line["last_login"] . "
"; + + } else { + print "

"; + if (!$user_search) { + print_warning(__('No users defined.')); + } else { + print_warning(__('No matching users found.')); + } + print "

"; + + } + + print "
"; #pane + print "
"; #container + + } + + } +?> diff --git a/js/prefs.js b/js/prefs.js index 4e1dadda2..896a787c6 100644 --- a/js/prefs.js +++ b/js/prefs.js @@ -5,33 +5,8 @@ var hotkey_prefix_pressed = false; var seq = ""; -function instancelist_callback2(transport) { - try { - dijit.byId('instanceConfigTab').attr('content', transport.responseText); - selectTab("instanceConfig", true); - notify(""); - } catch (e) { - exception_error("instancelist_callback2", e); - } -} - -function filterlist_callback2(transport) { - dijit.byId('filterConfigTab').attr('content', transport.responseText); - notify(""); -} - -function userlist_callback2(transport) { - try { - dijit.byId('userConfigTab').attr('content', transport.responseText); - - notify(""); - } catch (e) { - exception_error("userlist_callback2", e); - } -} - -function notify_callback2(transport) { - notify_info(transport.responseText); +function notify_callback2(transport, sticky) { + notify_info(transport.responseText, sticky); } function updateFeedList(sort_key) { @@ -53,14 +28,14 @@ function updateInstanceList(sort_key) { new Ajax.Request("backend.php", { parameters: "?op=pref-instances&sort=" + param_escape(sort_key), onComplete: function(transport) { - instancelist_callback2(transport); + dijit.byId('instanceConfigTab').attr('content', transport.responseText); + selectTab("instanceConfig", true); + notify(""); } }); } function updateUsersList(sort_key) { - try { - var user_search = $("user_search"); var search = ""; if (user_search) { search = user_search.value; } @@ -72,7 +47,9 @@ function updateUsersList(sort_key) { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - userlist_callback2(transport); + dijit.byId('userConfigTab').attr('content', transport.responseText); + selectTab("userConfig", true) + notify(""); } }); } catch (e) { @@ -103,7 +80,8 @@ function addUser() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - userlist_callback2(transport); + notify_callback2(transport); + updateUsersList(); } }); } catch (e) { @@ -332,7 +310,7 @@ function removeSelectedUsers() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - userlist_callback2(transport); + updateUsersList(); } }); } @@ -503,7 +481,7 @@ function userEditSave() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - userlist_callback2(transport); + updateUsersList(); } }); } catch (e) { @@ -562,7 +540,7 @@ function resetSelectedUserPass() { new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - userlist_callback2(transport); + notify_info(transport.responseText); } }); } @@ -592,7 +570,7 @@ function selectedUserDetails() { var id = rows[0]; - var query = "?op=pref-users&method=user-details&id=" + id; + var query = "?op=pref-users&method=userdetails&id=" + id; new Ajax.Request("backend.php", { parameters: query, @@ -816,7 +794,8 @@ function updateFilterList() { new Ajax.Request("backend.php", { parameters: "?op=pref-filters", onComplete: function(transport) { - filterlist_callback2(transport); + dijit.byId('filterConfigTab').attr('content', transport.responseText); + notify(""); } }); } diff --git a/modules/pref-users.php b/modules/pref-users.php deleted file mode 100644 index 8f6ba10a2..000000000 --- a/modules/pref-users.php +++ /dev/null @@ -1,501 +0,0 @@ -"; - - $uid = sprintf("%d", $_REQUEST["id"]); - - print "".__('User details').""; - - print "".__('User not found').""; - return; - } - - // print "

User Details

"; - - $login = db_fetch_result($result, 0, "login"); - - print ""; - - $last_login = make_local_datetime($link, - db_fetch_result($result, 0, "last_login"), true); - - $created = make_local_datetime($link, - db_fetch_result($result, 0, "created"), true); - - $access_level = db_fetch_result($result, 0, "access_level"); - $stored_articles = db_fetch_result($result, 0, "stored_articles"); - - print ""; - print ""; - - $result = db_query($link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds - WHERE owner_uid = '$uid'"); - - $num_feeds = db_fetch_result($result, 0, "num_feeds"); - - print ""; - - print "
".__('Registered')."$created
".__('Last logged in')."$last_login
".__('Subscribed feeds count')."$num_feeds
"; - - print "

".__('Subscribed feeds')."

"; - - $result = db_query($link, "SELECT id,title,site_url FROM ttrss_feeds - WHERE owner_uid = '$uid' ORDER BY title"); - - print "
    "; - - $row_class = "odd"; - - while ($line = db_fetch_assoc($result)) { - - $icon_file = ICONS_URL."/".$line["id"].".ico"; - - if (file_exists($icon_file) && filesize($icon_file) > 0) { - $feed_icon = ""; - } else { - $feed_icon = ""; - } - - print "
  • $feed_icon ".$line["title"]."
  • "; - - $row_class = $row_class == "even" ? "odd" : "even"; - - } - - if (db_num_rows($result) < $num_feeds) { - // FIXME - add link to show ALL subscribed feeds here somewhere - print "
  •  ...
  • "; - } - - print "
"; - - print "
-
"; - - print "]]>
"; - - return; - } - - if ($method == "edit") { - - header("Content-Type: text/xml"); - - $id = db_escape_string($_REQUEST["id"]); - - print ""; - print "".__('User Editor').""; - print ""; - - print ""; - print ""; - print ""; - - $result = db_query($link, "SELECT * FROM ttrss_users WHERE id = '$id'"); - - $login = db_fetch_result($result, 0, "login"); - $access_level = db_fetch_result($result, 0, "access_level"); - $email = db_fetch_result($result, 0, "email"); - - $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : ""; - - print "
".__("User")."
"; - print "
"; - - if ($sel_disabled) { - print ""; - print ""; - } else { - print ""; - } - - print "
"; - - print "
".__("Authentication")."
"; - print "
"; - - print __('Access level: ') . " "; - - if (!$sel_disabled) { - print_select_hash("access_level", $access_level, $access_level_names, - $sel_disabled); - } else { - print_select_hash("", $access_level, $access_level_names, - $sel_disabled); - print ""; - } - - print "
"; - - print __('Change password to') . - " "; - - print "
"; - - print "
".__("Options")."
"; - print "
"; - - print __('E-mail: '). - " "; - - print "
"; - - print ""; - - print ""; - - print "
- -
"; - - print "]]>
"; - - return; - } - - if ($method == "editSave") { - - if ($_SESSION["access_level"] >= 10) { - - $login = db_escape_string(trim($_REQUEST["login"])); - $uid = db_escape_string($_REQUEST["id"]); - $access_level = (int) $_REQUEST["access_level"]; - $email = db_escape_string(trim($_REQUEST["email"])); - $password = db_escape_string(trim($_REQUEST["password"])); - - if ($password) { - $pwd_hash = encrypt_password($password, $login); - $pass_query_part = "pwd_hash = '$pwd_hash', "; - $status_msg = format_notice(T_sprintf('Changed password of user %s.', $login)); - } else { - $pass_query_part = ""; - } - - db_query($link, "UPDATE ttrss_users SET $pass_query_part login = '$login', - access_level = '$access_level', email = '$email' WHERE id = '$uid'"); - - } - } else if ($method == "remove") { - - if ($_SESSION["access_level"] >= 10) { - - $ids = split(",", db_escape_string($_REQUEST["ids"])); - - foreach ($ids as $id) { - if ($id != $_SESSION["uid"] && $id != 1) { - db_query($link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'"); - db_query($link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'"); - db_query($link, "DELETE FROM ttrss_users WHERE id = '$id'"); - } - } - } - } else if ($method == "add") { - - if ($_SESSION["access_level"] >= 10) { - - $login = db_escape_string(trim($_REQUEST["login"])); - $tmp_user_pwd = make_password(8); - $pwd_hash = encrypt_password($tmp_user_pwd, $login); - - $result = db_query($link, "SELECT id FROM ttrss_users WHERE - login = '$login'"); - - if (db_num_rows($result) == 0) { - - db_query($link, "INSERT INTO ttrss_users - (login,pwd_hash,access_level,last_login,created) - VALUES ('$login', '$pwd_hash', 0, null, NOW())"); - - - $result = db_query($link, "SELECT id FROM ttrss_users WHERE - login = '$login' AND pwd_hash = '$pwd_hash'"); - - if (db_num_rows($result) == 1) { - - $new_uid = db_fetch_result($result, 0, "id"); - - $status_msg = format_notice(T_sprintf("Added user %s with password %s", - $login, $tmp_user_pwd)); - - initialize_user($link, $new_uid); - - } else { - - $status_msg = format_warning(T_sprintf("Could not create user %s", $login)); - - } - } else { - $status_msg = format_warning(T_sprintf("User %s already exists.", $login)); - } - } - } else if ($method == "resetPass") { - - if ($_SESSION["access_level"] >= 10) { - - $uid = db_escape_string($_REQUEST["id"]); - - $result = db_query($link, "SELECT login,email - FROM ttrss_users WHERE id = '$uid'"); - - $login = db_fetch_result($result, 0, "login"); - $email = db_fetch_result($result, 0, "email"); - $tmp_user_pwd = make_password(8); - $pwd_hash = encrypt_password($tmp_user_pwd, $login); - - db_query($link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash' - WHERE id = '$uid'"); - - $status_msg = format_notice(T_sprintf("Changed password of user %s - to %s", $login, $tmp_user_pwd)); - - require_once 'lib/phpmailer/class.phpmailer.php'; - - if ($email) { - $status_msg += format_notice(T_sprintf("Notifying %s.", $email)); - - require_once "lib/MiniTemplator.class.php"; - - $tpl = new MiniTemplator; - - $tpl->readTemplateFromFile("templates/resetpass_template.txt"); - - $tpl->setVariable('LOGIN', $login); - $tpl->setVariable('NEWPASS', $tmp_user_pwd); - - $tpl->addBlock('message'); - - $message = ""; - - $tpl->generateOutputToString($message); - - $mail = new PHPMailer(); - - $mail->PluginDir = "lib/phpmailer/"; - $mail->SetLanguage("en", "lib/phpmailer/language/"); - - $mail->CharSet = "UTF-8"; - - $mail->From = DIGEST_FROM_ADDRESS; - $mail->FromName = DIGEST_FROM_NAME; - $mail->AddAddress($email, $login); - - if (DIGEST_SMTP_HOST) { - $mail->Host = DIGEST_SMTP_HOST; - $mail->Mailer = "smtp"; - $mail->SMTPAuth = DIGEST_SMTP_LOGIN != ''; - $mail->Username = DIGEST_SMTP_LOGIN; - $mail->Password = DIGEST_SMTP_PASSWORD; - } - - $mail->IsHTML(false); - $mail->Subject = __("[tt-rss] Password change notification"); - $mail->Body = $message; - - $rc = $mail->Send(); - - if (!$rc) print_error($mail->ErrorInfo); - -/* mail("$login <$email>", "Password reset notification", - "Hi, $login.\n". - "\n". - "Your password for this TT-RSS installation was reset by". - " an administrator.\n". - "\n". - "Your new password is $tmp_user_pwd, please remember". - " it for later reference.\n". - "\n". - "Sincerely, TT-RSS Mail Daemon.", "From: " . MAIL_FROM); */ - } - - print ""; - - } - } - - print "
"; - print "
"; - - print "
"; - - $user_search = db_escape_string($_REQUEST["search"]); - - if (array_key_exists("search", $_REQUEST)) { - $_SESSION["prefs_user_search"] = $user_search; - } else { - $user_search = $_SESSION["prefs_user_search"]; - } - - print "
- - -
"; - - $sort = db_escape_string($_REQUEST["sort"]); - - if (!$sort || $sort == "undefined") { - $sort = "login"; - } - - print "
". - "" . __('Select').""; - print "
"; - print "
".__('All')."
"; - print "
".__('None')."
"; - print "
"; - - print ""; - - print " - - - - "; - - print "
"; #toolbar - print "
"; #pane - print "
"; - print "

$status_msg"; - - if ($user_search) { - - $user_search = split(" ", $user_search); - $tokens = array(); - - foreach ($user_search as $token) { - $token = trim($token); - array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))"); - } - - $user_search_query = "(" . join($tokens, " AND ") . ") AND "; - - } else { - $user_search_query = ""; - } - - $result = db_query($link, "SELECT - id,login,access_level,email, - ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login, - ".SUBSTRING_FOR_DATE."(created,1,16) as created - FROM - ttrss_users - WHERE - $user_search_query - id > 0 - ORDER BY $sort"); - - if (db_num_rows($result) > 0) { - - print "

"; - - print " - - - - - "; - - $lnum = 0; - - while ($line = db_fetch_assoc($result)) { - - $class = ($lnum % 2) ? "even" : "odd"; - - $uid = $line["id"]; - $edit_uid = $_REQUEST["id"]; - - if ($method == "edit" && $uid != $edit_uid) { - $class .= " Grayed"; - $this_row_id = ""; - } else { - $this_row_id = "id=\"UMRR-$uid\""; - } - - print ""; - - $line["login"] = htmlspecialchars($line["login"]); - - $line["created"] = make_local_datetime($link, $line["created"], false); - $line["last_login"] = make_local_datetime($link, $line["last_login"], false); - - print ""; - - $onclick = "onclick='editUser($uid, event)' title='".__('Click to edit')."'"; - - print ""; - - if (!$line["email"]) $line["email"] = " "; - - print ""; - print ""; - print ""; - - print ""; - - ++$lnum; - } - - print "
 ".__('Login')."".__('Access Level')."".__('Registered')."".__('Last login')."
" . $line["login"] . "" . $access_level_names[$line["access_level"]] . "" . $line["created"] . "" . $line["last_login"] . "
"; - - } else { - print "

"; - if (!$user_search) { - print_warning(__('No users defined.')); - } else { - print_warning(__('No matching users found.')); - } - print "

"; - - } - - print "
"; #pane - print "
"; #container - - } -?> -- cgit v1.2.3-54-g00ecf