diff options
Diffstat (limited to 'classes')
-rw-r--r-- | classes/article.php | 63 | ||||
-rw-r--r-- | classes/backend.php | 28 | ||||
-rw-r--r-- | classes/dlg.php | 1089 | ||||
-rw-r--r-- | classes/feeds.php | 187 | ||||
-rw-r--r-- | classes/handler.php | 19 | ||||
-rw-r--r-- | classes/pref_feeds.php | 1538 | ||||
-rw-r--r-- | classes/pref_prefs.php | 493 | ||||
-rw-r--r-- | classes/rpc.php | 792 |
8 files changed, 4209 insertions, 0 deletions
diff --git a/classes/article.php b/classes/article.php new file mode 100644 index 000000000..70ecd2653 --- /dev/null +++ b/classes/article.php @@ -0,0 +1,63 @@ +<?php
+class Article extends Handler {
+
+ function redirect() {
+ $id = db_escape_string($_REQUEST['id']);
+
+ $result = db_query($this->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 '<link rel="stylesheet" type="text/css" href="tt-rss.css"/>';
+ }
+
+ $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);
+
+ }
+
+}
diff --git a/classes/backend.php b/classes/backend.php new file mode 100644 index 000000000..f7e7b84b8 --- /dev/null +++ b/classes/backend.php @@ -0,0 +1,28 @@ +<?php +class Backend extends Handler { + + function loading() { + header("Content-type: text/html"); + print __("Loading, please wait...") . " " . + "<img src='images/indicator_tiny.gif'>"; + } + + 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 "<p>".__("Help topic not found.")."</p>"; + } + print "<div align='center'> + <button onclick=\"javascript:window.close()\">". + __('Close this window')."</button></div>"; + + } +} +?> 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 @@ +<?php +class Dlg extends Handler { + private $param; + + function before() { + if (parent::before()) { + header("Content-Type: text/xml; charset=utf-8"); + $this->param = db_escape_string($_REQUEST["param"]); + print "<dlg>"; + return true; + } + return false; + } + + function after() { + print "</dlg>"; + } + + function importOpml() { + header("Content-Type: text/html"); # required for iframe + + print "<div class=\"prefFeedOPMLHolder\">"; + $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 "<ul class='nomarks'>"; + print "<li>".__("Importing using DOMXML.")."</li>"; + require_once "opml_domxml.php"; + opml_import_domxml($this->link, $owner_uid); + print "</ul>"; + } else if (PHP_VERSION >= 5) { + print "<ul class='nomarks'>"; + print "<li>".__("Importing using DOMDocument.")."</li>"; + require_once "opml_domdoc.php"; + opml_import_domdoc($this->link, $owner_uid); + print "</ul>"; + } else { + print_error(__("DOMXML extension is not found. It is required for PHP versions below 5.")); + } + + print "</div>"; + + print "<div align='center'>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('opmlImportDlg').hide()\">". + __('Close this window')."</button>"; + print "</div>"; + + print "</div>"; + + //return; + } + + function editPrefProfiles() { + print "<div dojoType=\"dijit.Toolbar\">"; + + print "<input name=\"newprofile\" dojoType=\"dijit.form.ValidationTextBox\" + required=\"1\"> + <button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('profileEditDlg').addProfile()\">". + __('Create profile')."</button></div>"; + + $result = db_query($this->link, "SELECT title,id FROM ttrss_settings_profiles + WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title"); + + print "<div class=\"prefFeedCatHolder\">"; + + print "<form id=\"profile_edit_form\" onsubmit=\"return false\">"; + + print "<table width=\"100%\" class=\"prefFeedProfileList\" + cellspacing=\"0\" id=\"prefFeedProfileList\">"; + + print "<tr class=\"\" id=\"FCATR-0\">"; #odd + + print "<td width='5%' align='center'><input + onclick='toggleSelectRow2(this);' + dojoType=\"dijit.form.CheckBox\" + type=\"checkbox\"></td>"; + + if (!$_SESSION["profile"]) { + $is_active = __("(active)"); + } else { + $is_active = ""; + } + + print "<td><span>" . + __("Default profile") . " $is_active</span></td>"; + + print "</tr>"; + + $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 "<tr class=\"\" $this_row_id>"; + + $edit_title = htmlspecialchars($line["title"]); + + print "<td width='5%' align='center'><input + onclick='toggleSelectRow2(this);' + dojoType=\"dijit.form.CheckBox\" + type=\"checkbox\"></td>"; + + if ($_SESSION["profile"] == $line["id"]) { + $is_active = __("(active)"); + } else { + $is_active = ""; + } + + print "<td><span dojoType=\"dijit.InlineEditBox\" + width=\"300px\" autoSave=\"false\" + profile-id=\"$profile_id\">" . $edit_title . + "<script type=\"dojo/method\" event=\"onChange\" args=\"item\"> + var elem = this; + dojo.xhrPost({ + url: 'backend.php', + content: {op: 'rpc', method: 'saveprofile', + value: this.value, + id: this.srcNodeRef.getAttribute('profile-id')}, + load: function(response) { + elem.attr('value', response); + } + }); + </script> + </span> $is_active</td>"; + + print "</tr>"; + + ++$lnum; + } + + print "</table>"; + print "</form>"; + print "</div>"; + + print "<div class='dlgButtons'> + <div style='float : left'> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').removeSelected()\">". + __('Remove selected profiles')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').activateProfile()\">". + __('Activate profile')."</button> + </div>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('profileEditDlg').hide()\">". + __('Close this window')."</button>"; + print "</div>"; + + } + + function pubOPMLUrl() { + print "<title>".__('Public OPML URL')."</title>"; + print "<content><![CDATA["; + + $url_path = opml_publish_url($this->link); + + print __("Your Public OPML URL is:"); + + print "<div class=\"tagCloudContainer\">"; + print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>"; + print "</div>"; + + print "<div align='center'>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return opmlRegenKey()\">". + __('Generate new URL')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">". + __('Close this window')."</button>"; + + print "</div>"; + print "]]></content>"; + + //return; + } + + function explainError() { + print "<title>".__('Notice')."</title>"; + print "<content><![CDATA["; + + print "<div class=\"errorExplained\">"; + + 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 "<p>" . __("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 "<p>" . __("Last update:") . " " . date("Y.m.d, G:i", $stamp); + + } + + print "</div>"; + + print "<div align='center'>"; + + print "<button onclick=\"return closeInfoBox()\">". + __('Close this window')."</button>"; + + print "</div>"; + print "]]></content>"; + + //return; + } + + function quickAddFeed() { + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"addfeed\">"; + + print "<div class=\"dlgSec\">".__("Feed")."</div>"; + print "<div class=\"dlgSecCont\">"; + + print "<input style=\"font-size : 16px; width : 20em;\" + placeHolder=\"".__("Feed URL")."\" + dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"feed\" id=\"feedDlg_feedUrl\">"; + + print "<hr/>"; + + 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 "</div>"; + + print '<div id="feedDlg_feedsContainer" style="display : none"> + + <div class="dlgSec">' . __('Available feeds') . '</div> + <div class="dlgSecCont">'. + '<select id="feedDlg_feedContainerSelect" + dojoType="dijit.form.Select" size="3"> + <script type="dojo/method" event="onChange" args="value"> + dijit.byId("feedDlg_feedUrl").attr("value", value); + </script> + </select>'. + '</div></div>'; + + print "<div id='feedDlg_loginContainer' style='display : none'> + + <div class=\"dlgSec\">".__("Authentication")."</div> + <div class=\"dlgSecCont\">". + + " <input dojoType=\"dijit.form.TextBox\" name='login'\" + placeHolder=\"".__("Login")."\" + style=\"width : 10em;\"> ". + " <input + placeHolder=\"".__("Password")."\" + dojoType=\"dijit.form.TextBox\" type='password' + style=\"width : 10em;\" name='pass'\"> + </div></div>"; + + + print "<div style=\"clear : both\"> + <input type=\"checkbox\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\" + onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'> + <label for=\"feedDlg_loginCheck\">". + __('This feed requires authentication.')."</div>"; + + print "</form>"; + + print "<div class=\"dlgButtons\"> + <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').execute()\">".__('Subscribe')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"return feedBrowser()\">".__('More feeds')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedAddDlg').hide()\">".__('Cancel')."</button> + </div>"; + + //return; + } + + function feedBrowser() { + $browser_search = db_escape_string($_REQUEST["search"]); + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"updateFeedBrowser\">"; + + print "<div dojoType=\"dijit.Toolbar\"> + <div style='float : right'> + <img style='display : none' + id='feed_browser_spinner' src='". + theme_image($this->link, 'images/indicator_white.gif')."'> + <input name=\"search\" dojoType=\"dijit.form.TextBox\" size=\"20\" type=\"search\" + onchange=\"dijit.byId('feedBrowserDlg').update()\" value=\"$browser_search\"> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').update()\">".__('Search')."</button> + </div>"; + + print " <select name=\"mode\" dojoType=\"dijit.form.Select\" onchange=\"dijit.byId('feedBrowserDlg').update()\"> + <option value='1'>" . __('Popular feeds') . "</option> + <option value='2'>" . __('Feed archive') . "</option> + </select> "; + + print __("limit:"); + + print " <select dojoType=\"dijit.form.Select\" name=\"limit\" onchange=\"dijit.byId('feedBrowserDlg').update()\">"; + + foreach (array(25, 50, 100, 200) as $l) { + $issel = ($l == $limit) ? "selected=\"1\"" : ""; + print "<option $issel value=\"$l\">$l</option>"; + } + + print "</select> "; + + print "</div>"; + + $owner_uid = $_SESSION["uid"]; + + print "<ul class='browseFeedList' id='browseFeedList'>"; + print make_feed_browser($this->link, $search, 25); + print "</ul>"; + + print "<div align='center'> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').execute()\">".__('Subscribe')."</button> + <button dojoType=\"dijit.form.Button\" style='display : none' id='feed_archive_remove' onclick=\"dijit.byId('feedBrowserDlg').removeFromArchive()\">".__('Remove')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedBrowserDlg').hide()\" >".__('Cancel')."</button></div>"; + + } + + 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 "<div class=\"dlgSec\">".__('Look for')."</div>"; + + print "<div class=\"dlgSecCont\">"; + + if (!SPHINX_ENABLED) { + + print "<input dojoType=\"dijit.form.ValidationTextBox\" + style=\"font-size : 16px; width : 12em;\" + required=\"1\" name=\"query\" type=\"search\" value=''>"; + + 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 "<input dojoType=\"dijit.form.ValidationTextBox\" + style=\"font-size : 16px; width : 20em;\" + required=\"1\" name=\"query\" type=\"search\" value=''>"; + } + + + print "<hr/>".__('Limit search to:')." "; + + print "<select name=\"search_mode\" dojoType=\"dijit.form.Select\"> + <option value=\"all_feeds\">".__('All feeds')."</option>"; + + $feed_title = getFeedTitle($this->link, $active_feed_id); + + if (!$is_cat) { + $feed_cat_title = getFeedCatTitle($this->link, $active_feed_id); + } else { + $feed_cat_title = getCategoryTitle($this->link, $active_feed_id); + } + + if ($active_feed_id && !$is_cat) { + print "<option selected=\"1\" value=\"this_feed\">$feed_title</option>"; + } else { + print "<option disabled=\"1\" value=\"false\">".__('This feed')."</option>"; + } + + if ($is_cat) { + $cat_preselected = "selected=\"1\""; + } + + if (get_pref($this->link, 'ENABLE_FEED_CATS') && ($active_feed_id > 0 || $is_cat)) { + print "<option $cat_preselected value=\"this_cat\">$feed_cat_title</option>"; + } else { + //print "<option disabled>".__('This category')."</option>"; + } + + print "</select>"; + + print "</div>"; + + print "<div class=\"dlgButtons\">"; + + if (!SPHINX_ENABLED) { + print "<div style=\"float : left\"> + <a class=\"visibleLink\" target=\"_blank\" href=\"http://tt-rss.org/redmine/wiki/tt-rss/SearchSyntax\">Search syntax</a> + </div>"; + } + + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').execute()\">".__('Search')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('searchDlg').hide()\">".__('Cancel')."</button> + </div>"; + } + + function quickAddFilter() { + $active_feed_id = db_escape_string($_REQUEST["param"]); + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-filters\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"quiet\" value=\"1\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">"; + + $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 "<div class=\"dlgSec\">".__("Match")."</div>"; + + print "<div class=\"dlgSecCont\">"; + + print "<span id=\"filterDlg_dateModBox\" style=\"display : none\">"; + + $filter_params = array( + "before" => __("before"), + "after" => __("after")); + + print_select_hash("filter_date_modifier", "before", + $filter_params, 'dojoType="dijit.form.Select"'); + + print " </span>"; + + print "<input dojoType=\"dijit.form.ValidationTextBox\" + required=\"true\" id=\"filterDlg_regExp\" + style=\"font-size : 16px\" + name=\"reg_exp\" value=\"$reg_exp\"/>"; + + print "<span id=\"filterDlg_dateChkBox\" style=\"display : none\">"; + print " <button dojoType=\"dijit.form.Button\" + onclick=\"return filterDlgCheckDate()\">". + __('Check it')."</button>"; + print "</span>"; + + print "<hr/>" . __("on field") . " "; + print_select_hash("filter_type", 1, $filter_types, + 'onchange="filterDlgCheckType(this)" dojoType="dijit.form.Select"'); + + print "<hr/>"; + + print __("in") . " "; + print_feed_select($this->link, "feed_id", $active_feed_id, + 'dojoType="dijit.form.FilteringSelect"'); + + print "</div>"; + + print "<div class=\"dlgSec\">".__("Perform Action")."</div>"; + + print "<div class=\"dlgSecCont\">"; + + print "<select name=\"action_id\" dojoType=\"dijit.form.Select\" + onchange=\"filterDlgCheckAction(this)\">"; + + $result = db_query($this->link, "SELECT id,description FROM ttrss_filter_actions + ORDER BY name"); + + while ($line = db_fetch_assoc($result)) { + printf("<option value='%d'>%s</option>", $line["id"], __($line["description"])); + } + + print "</select>"; + + print "<span id=\"filterDlg_paramBox\" style=\"display : none\">"; + print " " . __("with parameters:") . " "; + print "<input dojoType=\"dijit.form.TextBox\" + id=\"filterDlg_actionParam\" + name=\"action_param\">"; + + print_label_select($this->link, "action_param_label", $action_param, + 'id="filterDlg_actionParamLabel" dojoType="dijit.form.Select"'); + + print "</span>"; + + print " "; // tiny layout hack + + print "</div>"; + + print "<div class=\"dlgSec\">".__("Options")."</div>"; + print "<div class=\"dlgSecCont\">"; + + print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"enabled\" id=\"enabled\" checked=\"1\"> + <label for=\"enabled\">".__('Enabled')."</label><hr/>"; + + print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"inverse\" id=\"inverse\"> + <label for=\"inverse\">".__('Inverse match')."</label>"; + + print "</div>"; + + print "<div class=\"dlgButtons\">"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').test()\">". + __('Test')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').execute()\">". + __('Create')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterEditDlg').hide()\">". + __('Cancel')."</button>"; + + print "</div>"; + } + + 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 "<div class=\"inactiveFeedHolder\">"; + + print "<table width=\"100%\" cellspacing=\"0\" id=\"prefInactiveFeedList\">"; + + $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 "<tr class=\"\" $this_row_id>"; + + $edit_title = htmlspecialchars($line["title"]); + + print "<td width='5%' align='center'><input + onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" + type=\"checkbox\"></td>"; + print "<td>"; + + print "<a class=\"visibleLink\" href=\"#\" ". + "title=\"".__("Click to edit feed")."\" ". + "onclick=\"editFeed(".$line["id"].")\">". + htmlspecialchars($line["title"])."</a>"; + + print "</td><td class=\"insensitive\" align='right'>"; + print make_local_datetime($this->link, $line['last_article'], false); + print "</td>"; + print "</tr>"; + + ++$lnum; + } + + print "</table>"; + print "</div>"; + + print "<div class='dlgButtons'>"; + print "<div style='float : left'>"; + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').removeSelected()\">" + .__('Unsubscribe from selected feeds')."</button> "; + print "</div>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('inactiveFeedsDlg').hide()\">". + __('Close this window')."</button>"; + + print "</div>"; + + } + + 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 "<div class=\"inactiveFeedHolder\">"; + + print "<table width=\"100%\" cellspacing=\"0\" id=\"prefErrorFeedList\">"; + + $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 "<tr class=\"\" $this_row_id>"; + + $edit_title = htmlspecialchars($line["title"]); + + print "<td width='5%' align='center'><input + onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" + type=\"checkbox\"></td>"; + print "<td>"; + + print "<a class=\"visibleLink\" href=\"#\" ". + "title=\"".__("Click to edit feed")."\" ". + "onclick=\"editFeed(".$line["id"].")\">". + htmlspecialchars($line["title"])."</a>: "; + + print "<span class=\"insensitive\">"; + print htmlspecialchars($line["last_error"]); + print "</span>"; + + print "</td>"; + print "</tr>"; + + ++$lnum; + } + + print "</table>"; + print "</div>"; + + print "<div class='dlgButtons'>"; + print "<div style='float : left'>"; + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').removeSelected()\">" + .__('Unsubscribe from selected feeds')."</button> "; + print "</div>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('errorFeedsDlg').hide()\">". + __('Close this window')."</button>"; + + print "</div>"; + } + + function editArticleTags() { + + print __("Tags for this article (separated by commas):")."<br>"; + + $tags = get_article_tags($this->link, $this->param); + + $tags_str = join(", ", $tags); + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$this->param\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setArticleTags\">"; + + print "<table width='100%'><tr><td>"; + + print "<textarea dojoType=\"dijit.form.SimpleTextarea\" rows='4' + style='font-size : 12px; width : 100%' id=\"tags_str\" + name='tags_str'>$tags_str</textarea> + <div class=\"autocomplete\" id=\"tags_choices\" + style=\"display:none\"></div>"; + + print "</td></tr></table>"; + + print "<div class='dlgButtons'>"; + + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('editTagsDlg').execute()\">".__('Save')."</button> "; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('editTagsDlg').hide()\">".__('Cancel')."</button>"; + print "</div>"; + + } + + function printTagCloud() { + print "<title>".__('Tag Cloud')."</title>"; + print "<content><![CDATA["; + + print "<div class=\"tagCloudContainer\">"; + + printTagCloud($this->link); + + print "</div>"; + + print "<div align='center'>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"return closeInfoBox()\">". + __('Close this window')."</button>"; + print "</div>"; + + print "]]></content>"; + } + + function printTagSelect() { + + print "<title>" . __('Select item(s) by tags') . "</title>"; + print "<content><![CDATA["; + + print __("Match:"). " " . + "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" checked value=\"any\" name=\"tag_mode\"> Any "; + print "<input class=\"noborder\" dojoType=\"dijit.form.RadioButton\" type=\"radio\" value=\"all\" name=\"tag_mode\"> All "; + print " tags."; + + print "<select id=\"all_tags\" name=\"all_tags\" title=\"" . __('Which Tags?') . "\" multiple=\"multiple\" size=\"10\" style=\"width : 100%\">"; + $result = db_query($this->link, "SELECT DISTINCT tag_name FROM ttrss_tags WHERE owner_uid = ".$_SESSION['uid']." + AND LENGTH(tag_name) <= 30 ORDER BY tag_name ASC"); + + while ($row = db_fetch_assoc($result)) { + $tmp = htmlspecialchars($row["tag_name"]); + print "<option value=\"" . str_replace(" ", "%20", $tmp) . "\">$tmp</option>"; + } + + print "</select>"; + + print "<div align='right'>"; + print "<button dojoType=\"dijit.form.Button\" onclick=\"viewfeed(get_all_tags($('all_tags')), + get_radio_checked($('tag_mode')));\">" . __('Display entries') . "</button>"; + print " "; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"return closeInfoBox()\">" . + __('Close this window') . "</button>"; + print "</div>"; + + print "]]></content>"; + } + + function emailArticle() { + + $secretkey = sha1(uniqid(rand(), true)); + + $_SESSION['email_secretkey'] = $secretkey; + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"secretkey\" value=\"$secretkey\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"sendEmail\">"; + + $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 "<table width='100%'><tr><td>"; + + print __('From:'); + + print "</td><td>"; + + print "<input dojoType=\"dijit.form.TextBox\" disabled=\"1\" style=\"width : 30em;\" + value=\"$user_name <$user_email>\">"; + + print "</td></tr><tr><td>"; + + print __('To:'); + + print "</td><td>"; + + print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" + style=\"width : 30em;\" + name=\"destination\" id=\"emailArticleDlg_destination\">"; + + print "<div class=\"autocomplete\" id=\"emailArticleDlg_dst_choices\" + style=\"z-index: 30; display : none\"></div>"; + + print "</td></tr><tr><td>"; + + print __('Subject:'); + + print "</td><td>"; + + print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"true\" + style=\"width : 30em;\" + name=\"subject\" value=\"$subject\" id=\"subject\">"; + + print "</td></tr>"; + + print "<tr><td colspan='2'><textarea dojoType=\"dijit.form.SimpleTextarea\" style='font-size : 12px; width : 100%' rows=\"20\" + name='content'>$content</textarea>"; + + print "</td></tr></table>"; + + print "<div class='dlgButtons'>"; + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').execute()\">".__('Send e-mail')."</button> "; + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('emailArticleDlg').hide()\">".__('Cancel')."</button>"; + print "</div>"; + + //return; + } + + function generatedFeed() { + + print "<title>".__('View as RSS')."</title>"; + print "<content><![CDATA["; + + $this->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 "<div class=\"tagCloudContainer\">"; + print "<a id='gen_feed_url' href='$url_path' target='_blank'>$url_path</a>"; + print "</div>"; + + print "<div align='center'>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return genUrlChangeKey('$feed_id', '$is_cat')\">". + __('Generate new URL')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return closeInfoBox()\">". + __('Close this window')."</button>"; + + print "</div>"; + print "]]></content>"; + + //return; + } + + function newVersion() { + + $version_data = check_for_update($this->link); + $version = $version_data['version']; + $id = $version_data['version_id']; + + print "<div class='tagCloudContainer'>"; + + print T_sprintf("New version of Tiny Tiny RSS is available (%s).", + "<b>$version</b>"); + + print "</div>"; + + $details = "http://tt-rss.org/redmine/versions/show/$id"; + $download = "http://tt-rss.org/#Download"; + + print "<div style='text-align : center'>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"return window.open('$details')\">".__("Details")."</button>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"return window.open('$download')\">".__("Download")."</button>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"return dijit.byId('newVersionDlg').hide()\">". + __('Close this window')."</button>"; + print "</div>"; + + } + + function customizeCSS() { + $value = get_pref($this->link, "USER_STYLESHEET"); + + $value = str_replace("<br/>", "\n", $value); + + print T_sprintf("You can override colors, fonts and layout of your currently selected theme with custom CSS declarations here. <a target=\"_blank\" class=\"visibleLink\" href=\"%s\">This file</a> can be used as a baseline.", "tt-rss.css"); + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setpref\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"key\" value=\"USER_STYLESHEET\">"; + + print "<table width='100%'><tr><td>"; + print "<textarea dojoType=\"dijit.form.SimpleTextarea\" + style='font-size : 12px; width : 100%; height: 200px;' + placeHolder='body#ttrssMain { font-size : 14px; };' + name='value'>$value</textarea>"; + print "</td></tr></table>"; + + print "<div class='dlgButtons'>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('cssEditDlg').execute()\">".__('Save')."</button> "; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('cssEditDlg').hide()\">".__('Cancel')."</button>"; + print "</div>"; + + } + + 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 "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$this->param\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"rpc\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"setNote\">"; + + print "<table width='100%'><tr><td>"; + print "<textarea dojoType=\"dijit.form.SimpleTextarea\" + style='font-size : 12px; width : 100%; height: 100px;' + placeHolder='body#ttrssMain { font-size : 14px; };' + name='note'>$note</textarea>"; + print "</td></tr></table>"; + + print "<div class='dlgButtons'>"; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('editNoteDlg').execute()\">".__('Save')."</button> "; + print "<button dojoType=\"dijit.form.Button\" + onclick=\"dijit.byId('editNoteDlg').hide()\">".__('Cancel')."</button>"; + print "</div>"; + + } + + function about() { + print "<table width='100%'><tr><td align='center'>"; + print "<img src=\"images/logo_big.png\">"; + print "</td>"; + print "<td width='70%'>"; + + print "<h1>Tiny Riny RSS</h1> + <strong>Version ".VERSION."</strong> + <p>Copyright © 2005-".date('Y')." + <a target=\"_blank\" class=\"visibleLink\" + href=\"http://fakecake.org/\">Andrew Dolgov</a> + and other contributors.</p> + <p class=\"insensitive\">Licensed under GNU GPL version 2.</p>"; + + print "<p class=\"insensitive\"> + <a class=\"visibleLink\" target=\"_blank\" + href=\"http://tt-rss.org/\">Official site</a> — + <a href=\"http://tt-rss.org/redmine/wiki/tt-rss/Donate\" + target=\"_blank\" class=\"visibleLink\"> + Support the project.</a></p>"; + + print "</td></tr>"; + print "</table>"; + + print "<div align='center'>"; + print "<button dojoType=\"dijit.form.Button\" + type=\"submit\">". + __('Close this window')."</button>"; + print "</div>"; + } + + function addInstance() { + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-instances\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"add\">"; + + print "<div class=\"dlgSec\">".__("Instance")."</div>"; + + print "<div class=\"dlgSecCont\">"; + + /* URL */ + + print __("URL:") . " "; + + print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" + placeHolder=\"".__("Instance URL")."\" + regExp='^(http|https)://.*' + style=\"font-size : 16px; width: 20em\" name=\"access_url\">"; + + print "<hr/>"; + + $access_key = sha1(uniqid(rand(), true)); + + /* Access key */ + + print __("Access key:") . " "; + + print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" + placeHolder=\"".__("Access key")."\" regExp='\w{40}' + style=\"width: 20em\" name=\"access_key\" id=\"instance_add_key\" + value=\"$access_key\">"; + + print "<p class='insensitive'>" . __("Use one access key for both linked instances."); + + print "</div>"; + + print "<div class=\"dlgButtons\"> + <div style='float : left'> + <button dojoType=\"dijit.form.Button\" + onclick=\"return dijit.byId('instanceAddDlg').regenKey()\">". + __('Generate new key')."</button> + </div> + <button dojoType=\"dijit.form.Button\" + onclick=\"return dijit.byId('instanceAddDlg').execute()\">". + __('Create link')."</button> + <button dojoType=\"dijit.form.Button\" + onclick=\"return dijit.byId('instanceAddDlg').hide()\"\">". + __('Cancel')."</button></div>"; + + return; + } + + function 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 "<div class=\"tagCloudContainer\">"; + print "<a id='pub_opml_url' href='$url_path' target='_blank'>$url_path</a>"; + print "</div>"; + + /* 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 "<div align='center'>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('shareArticleDlg').hide()\">". + __('Close this window')."</button>"; + + print "</div>"; + } + +} +?> 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 @@ +<?php
+class Feeds extends Handler {
+
+ function catchupAll() {
+ db_query($this->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 new file mode 100644 index 000000000..53b52ea03 --- /dev/null +++ b/classes/handler.php @@ -0,0 +1,19 @@ +<?php +class Handler { + protected $link; + protected $args; + + function __construct($link, $args) { + $this->link = $link; + $this->args = $args; + } + + function before() { + return true; + } + + function after() { + return true; + } +} +?> diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php new file mode 100644 index 000000000..bf15bf25a --- /dev/null +++ b/classes/pref_feeds.php @@ -0,0 +1,1538 @@ +<?php +class Pref_Feeds extends Handler { + function batch_edit_cbox($elem, $label = false) { + print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\" + onchange=\"dijit.byId('feedEditDlg').toggleField(this, '$elem', '$label')\">"; + } + + function renamecat() { + $title = db_escape_string($_REQUEST['title']); + $id = db_escape_string($_REQUEST['id']); + + if ($title) { + db_query($this->link, "UPDATE ttrss_feed_categories SET + title = '$title' WHERE id = '$id' AND owner_uid = " . $_SESSION["uid"]); + } + return; + } + + function remtwitterinfo() { + + db_query($this->link, "UPDATE ttrss_users SET twitter_oauth = NULL + WHERE id = " . $_SESSION['uid']); + + return; + } + + function getfeedtree() { + + $search = $_SESSION["prefs_feed_search"]; + + if ($search) $search_qpart = " AND LOWER(title) LIKE LOWER('%$search%')"; + + $root = array(); + $root['id'] = 'root'; + $root['name'] = __('Feeds'); + $root['items'] = array(); + $root['type'] = 'category'; + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + + $result = db_query($this->link, "SELECT id, title FROM ttrss_feed_categories + WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY order_id, title"); + + while ($line = db_fetch_assoc($result)) { + $cat = array(); + $cat['id'] = 'CAT:' . $line['id']; + $cat['bare_id'] = $feed_id; + $cat['name'] = $line['title']; + $cat['items'] = array(); + $cat['checkbox'] = false; + $cat['type'] = 'category'; + + $feed_result = db_query($this->link, "SELECT id, title, last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + FROM ttrss_feeds + WHERE cat_id = '".$line['id']."' AND owner_uid = ".$_SESSION["uid"]. + "$search_qpart ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + $feed['error'] = $feed_line['last_error']; + $feed['icon'] = getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime($this->link, + $feed_line['last_updated'], true); + + array_push($cat['items'], $feed); + } + + $cat['param'] = T_sprintf('(%d feeds)', count($cat['items'])); + + if (count($cat['items']) > 0) + array_push($root['items'], $cat); + + $root['param'] += count($cat['items']); + } + + /* Uncategorized is a special case */ + + $cat = array(); + $cat['id'] = 'CAT:0'; + $cat['bare_id'] = 0; + $cat['name'] = __("Uncategorized"); + $cat['items'] = array(); + $cat['type'] = 'category'; + $cat['checkbox'] = false; + + $feed_result = db_query($this->link, "SELECT id, title,last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + FROM ttrss_feeds + WHERE cat_id IS NULL AND owner_uid = ".$_SESSION["uid"]. + "$search_qpart ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + $feed['error'] = $feed_line['last_error']; + $feed['icon'] = getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime($this->link, + $feed_line['last_updated'], true); + + array_push($cat['items'], $feed); + } + + $cat['param'] = T_sprintf('(%d feeds)', count($cat['items'])); + + if (count($cat['items']) > 0) + array_push($root['items'], $cat); + + $root['param'] += count($cat['items']); + $root['param'] = T_sprintf('(%d feeds)', $root['param']); + + } else { + $feed_result = db_query($this->link, "SELECT id, title, last_error, + ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated + FROM ttrss_feeds + WHERE owner_uid = ".$_SESSION["uid"]. + "$search_qpart ORDER BY order_id, title"); + + while ($feed_line = db_fetch_assoc($feed_result)) { + $feed = array(); + $feed['id'] = 'FEED:' . $feed_line['id']; + $feed['bare_id'] = $feed_line['id']; + $feed['name'] = $feed_line['title']; + $feed['checkbox'] = false; + $feed['error'] = $feed_line['last_error']; + $feed['icon'] = getFeedIcon($feed_line['id']); + $feed['param'] = make_local_datetime($this->link, + $feed_line['last_updated'], true); + + array_push($root['items'], $feed); + } + + $root['param'] = T_sprintf('(%d feeds)', count($root['items'])); + + } + + $fl = array(); + $fl['identifier'] = 'id'; + $fl['label'] = 'name'; + $fl['items'] = array($root); + + print json_encode($fl); + return; + } + + function catsortreset() { + db_query($this->link, "UPDATE ttrss_feed_categories + SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); + return; + } + + function feedsortreset() { + db_query($this->link, "UPDATE ttrss_feeds + SET order_id = 0 WHERE owner_uid = " . $_SESSION["uid"]); + return; + } + + function savefeedorder() { + $data = json_decode($_POST['payload'], true); + + if (is_array($data) && is_array($data['items'])) { + $cat_order_id = 0; + + $data_map = array(); + + foreach ($data['items'] as $item) { + + if ($item['id'] != 'root') { + if (is_array($item['items'])) { + if (isset($item['items']['_reference'])) { + $data_map[$item['id']] = array($item['items']); + } else { + $data_map[$item['id']] =& $item['items']; + } + } + } + } + + foreach ($data['items'][0]['items'] as $item) { + $id = $item['_reference']; + $bare_id = substr($id, strpos($id, ':')+1); + + ++$cat_order_id; + + if ($bare_id > 0) { + db_query($this->link, "UPDATE ttrss_feed_categories + SET order_id = '$cat_order_id' WHERE id = '$bare_id' AND + owner_uid = " . $_SESSION["uid"]); + } + + $feed_order_id = 0; + + if (is_array($data_map[$id])) { + foreach ($data_map[$id] as $feed) { + $id = $feed['_reference']; + $feed_id = substr($id, strpos($id, ':')+1); + + if ($bare_id != 0) + $cat_query = "cat_id = '$bare_id'"; + else + $cat_query = "cat_id = NULL"; + + db_query($this->link, "UPDATE ttrss_feeds + SET order_id = '$feed_order_id', + $cat_query + WHERE id = '$feed_id' AND + owner_uid = " . $_SESSION["uid"]); + + ++$feed_order_id; + } + } + } + } + + return; + } + + function removeicon() { + $feed_id = db_escape_string($_REQUEST["feed_id"]); + + $result = db_query($this->link, "SELECT id FROM ttrss_feeds + WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + unlink(ICONS_DIR . "/$feed_id.ico"); + } + + return; + } + + function uploadicon() { + $icon_file = $_FILES['icon_file']['tmp_name']; + $feed_id = db_escape_string($_REQUEST["feed_id"]); + + if (is_file($icon_file) && $feed_id) { + if (filesize($icon_file) < 20000) { + + $result = db_query($this->link, "SELECT id FROM ttrss_feeds + WHERE id = '$feed_id' AND owner_uid = ". $_SESSION["uid"]); + + if (db_num_rows($result) != 0) { + unlink(ICONS_DIR . "/$feed_id.ico"); + move_uploaded_file($icon_file, ICONS_DIR . "/$feed_id.ico"); + $rc = 0; + } else { + $rc = 2; + } + } else { + $rc = 1; + } + } else { + $rc = 2; + } + + print "<script type=\"text/javascript\">"; + print "parent.uploadIconHandler($rc);"; + print "</script>"; + return; + } + + function editfeed() { + global $purge_intervals; + global $update_intervals; + global $update_methods; + + $feed_id = db_escape_string($_REQUEST["id"]); + + $result = db_query($this->link, + "SELECT * FROM ttrss_feeds WHERE id = '$feed_id' AND + owner_uid = " . $_SESSION["uid"]); + + $title = htmlspecialchars(db_fetch_result($result, + 0, "title")); + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"id\" value=\"$feed_id\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"editSave\">"; + + print "<div class=\"dlgSec\">".__("Feed")."</div>"; + print "<div class=\"dlgSecCont\">"; + + /* Title */ + + print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" + placeHolder=\"".__("Feed Title")."\" + style=\"font-size : 16px; width: 20em\" name=\"title\" value=\"$title\">"; + + /* Feed URL */ + + $feed_url = db_fetch_result($result, 0, "feed_url"); + $feed_url = htmlspecialchars(db_fetch_result($result, + 0, "feed_url")); + + print "<hr/>"; + + print __('URL:') . " "; + print "<input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" + placeHolder=\"".__("Feed URL")."\" + regExp='^(http|https)://.*' style=\"width : 20em\" + name=\"feed_url\" value=\"$feed_url\">"; + + $last_error = db_fetch_result($result, 0, "last_error"); + + if ($last_error) { + print " <span title=\"".htmlspecialchars($last_error)."\" + class=\"feed_error\">(error)</span>"; + + } + + /* Category */ + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + + $cat_id = db_fetch_result($result, 0, "cat_id"); + + print "<hr/>"; + + print __('Place in category:') . " "; + + print_feed_cat_select($this->link, "cat_id", $cat_id, + 'dojoType="dijit.form.Select"'); + } + + print "</div>"; + + print "<div class=\"dlgSec\">".__("Update")."</div>"; + print "<div class=\"dlgSecCont\">"; + + /* Update Interval */ + + $update_interval = db_fetch_result($result, 0, "update_interval"); + + print_select_hash("update_interval", $update_interval, $update_intervals, + 'dojoType="dijit.form.Select"'); + + /* Update method */ + + $update_method = db_fetch_result($result, 0, "update_method", + 'dojoType="dijit.form.Select"'); + + print " " . __('using') . " "; + print_select_hash("update_method", $update_method, $update_methods, + 'dojoType="dijit.form.Select"'); + + $purge_interval = db_fetch_result($result, 0, "purge_interval"); + + + /* Purge intl */ + + print "<hr/>"; + print __('Article purging:') . " "; + + print_select_hash("purge_interval", $purge_interval, $purge_intervals, + 'dojoType="dijit.form.Select" ' . + ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"')); + + print "</div>"; + print "<div class=\"dlgSec\">".__("Authentication")."</div>"; + print "<div class=\"dlgSecCont\">"; + + $auth_login = htmlspecialchars(db_fetch_result($result, 0, "auth_login")); + + print "<input dojoType=\"dijit.form.TextBox\" id=\"feedEditDlg_login\" + placeHolder=\"".__("Login")."\" + name=\"auth_login\" value=\"$auth_login\"><hr/>"; + + $auth_pass = htmlspecialchars(db_fetch_result($result, 0, "auth_pass")); + + print "<input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" + placeHolder=\"".__("Password")."\" + value=\"$auth_pass\">"; + + print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedEditDlg_login\" position=\"below\"> + ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')." + </div>"; + + print "</div>"; + print "<div class=\"dlgSec\">".__("Options")."</div>"; + print "<div class=\"dlgSecCont\">"; + + $private = sql_bool_to_bool(db_fetch_result($result, 0, "private")); + + if ($private) { + $checked = "checked=\"1\""; + } else { + $checked = ""; + } + + print "<input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" name=\"private\" id=\"private\" + $checked> <label for=\"private\">".__('Hide from Popular feeds')."</label>"; + + $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content")); + + if ($rtl_content) { + $checked = "checked=\"1\""; + } else { + $checked = ""; + } + + print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\" + $checked> <label for=\"rtl_content\">".__('Right-to-left content')."</label>"; + + $include_in_digest = sql_bool_to_bool(db_fetch_result($result, 0, "include_in_digest")); + + if ($include_in_digest) { + $checked = "checked=\"1\""; + } else { + $checked = ""; + } + + print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\" + name=\"include_in_digest\" + $checked> <label for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; + + + $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures")); + + if ($always_display_enclosures) { + $checked = "checked"; + } else { + $checked = ""; + } + + print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\" + name=\"always_display_enclosures\" + $checked> <label for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; + + + $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images")); + + if ($cache_images) { + $checked = "checked=\"1\""; + } else { + $checked = ""; + } + + if (SIMPLEPIE_CACHE_IMAGES) { + print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"cache_images\" + name=\"cache_images\" + $checked> <label for=\"cache_images\">". + __('Cache images locally (SimplePie only)')."</label>"; + } + + $mark_unread_on_update = sql_bool_to_bool(db_fetch_result($result, 0, "mark_unread_on_update")); + + if ($mark_unread_on_update) { + $checked = "checked"; + } else { + $checked = ""; + } + + print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"mark_unread_on_update\" + name=\"mark_unread_on_update\" + $checked> <label for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; + + $update_on_checksum_change = sql_bool_to_bool(db_fetch_result($result, 0, "update_on_checksum_change")); + + if ($update_on_checksum_change) { + $checked = "checked"; + } else { + $checked = ""; + } + + print "<hr/><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"update_on_checksum_change\" + name=\"update_on_checksum_change\" + $checked> <label for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>"; + + print "</div>"; + + /* Icon */ + + print "<div class=\"dlgSec\">".__("Icon")."</div>"; + print "<div class=\"dlgSecCont\">"; + + print "<iframe name=\"icon_upload_iframe\" + style=\"width: 400px; height: 100px; display: none;\"></iframe>"; + + print "<form style='display : block' target=\"icon_upload_iframe\" + enctype=\"multipart/form-data\" method=\"POST\" + action=\"backend.php\"> + <input id=\"icon_file\" size=\"10\" name=\"icon_file\" type=\"file\"> + <input type=\"hidden\" name=\"op\" value=\"pref-feeds\"> + <input type=\"hidden\" name=\"feed_id\" value=\"$feed_id\"> + <input type=\"hidden\" name=\"method\" value=\"uploadicon\"> + <button dojoType=\"dijit.form.Button\" onclick=\"return uploadFeedIcon();\" + type=\"submit\">".__('Replace')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"return removeFeedIcon($feed_id);\" + type=\"submit\">".__('Remove')."</button> + </form>"; + + print "</div>"; + + $title = htmlspecialchars($title, ENT_QUOTES); + + print "<div class='dlgButtons'> + <div style=\"float : left\"> + <button dojoType=\"dijit.form.Button\" onclick='return unsubscribeFeed($feed_id, \"$title\")'>". + __('Unsubscribe')."</button>"; + + if (PUBSUBHUBBUB_ENABLED) { + $pubsub_state = db_fetch_result($result, 0, "pubsub_state"); + $pubsub_btn_disabled = ($pubsub_state == 2) ? "" : "disabled=\"1\""; + + print "<button dojoType=\"dijit.form.Button\" id=\"pubsubReset_Btn\" $pubsub_btn_disabled + onclick='return resetPubSub($feed_id, \"$title\")'>".__('Resubscribe to push updates'). + "</button>"; + } + + print "</div>"; + + print "<div dojoType=\"dijit.Tooltip\" connectId=\"pubsubReset_Btn\" position=\"below\">". + __('Resets PubSubHubbub subscription status for push-enabled feeds.')."</div>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').execute()\">".__('Save')."</button> + <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('feedEditDlg').hide()\">".__('Cancel')."</button> + </div>"; + + return; + } + + function editfeeds() { + global $purge_intervals; + global $update_intervals; + global $update_methods; + + $feed_ids = db_escape_string($_REQUEST["ids"]); + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"ids\" value=\"$feed_ids\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-feeds\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"batchEditSave\">"; + + print "<div class=\"dlgSec\">".__("Feed")."</div>"; + print "<div class=\"dlgSecCont\">"; + + /* Title */ + + print "<input dojoType=\"dijit.form.ValidationTextBox\" + disabled=\"1\" style=\"font-size : 16px; width : 20em;\" required=\"1\" + name=\"title\" value=\"$title\">"; + + $this->batch_edit_cbox("title"); + + /* Feed URL */ + + print "<br/>"; + + print __('URL:') . " "; + print "<input dojoType=\"dijit.form.ValidationTextBox\" disabled=\"1\" + required=\"1\" regExp='^(http|https)://.*' style=\"width : 20em\" + name=\"feed_url\" value=\"$feed_url\">"; + + $this->batch_edit_cbox("feed_url"); + + /* Category */ + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + + print "<br/>"; + + print __('Place in category:') . " "; + + print_feed_cat_select($this->link, "cat_id", $cat_id, + 'disabled="1" dojoType="dijit.form.Select"'); + + $this->batch_edit_cbox("cat_id"); + + } + + print "</div>"; + + print "<div class=\"dlgSec\">".__("Update")."</div>"; + print "<div class=\"dlgSecCont\">"; + + /* Update Interval */ + + print_select_hash("update_interval", $update_interval, $update_intervals, + 'disabled="1" dojoType="dijit.form.Select"'); + + $this->batch_edit_cbox("update_interval"); + + /* Update method */ + + print " " . __('using') . " "; + print_select_hash("update_method", $update_method, $update_methods, + 'disabled="1" dojoType="dijit.form.Select"'); + $this->batch_edit_cbox("update_method"); + + /* Purge intl */ + + if (FORCE_ARTICLE_PURGE == 0) { + + print "<br/>"; + + print __('Article purging:') . " "; + + print_select_hash("purge_interval", $purge_interval, $purge_intervals, + 'disabled="1" dojoType="dijit.form.Select"'); + + $this->batch_edit_cbox("purge_interval"); + } + + print "</div>"; + print "<div class=\"dlgSec\">".__("Authentication")."</div>"; + print "<div class=\"dlgSecCont\">"; + + print "<input dojoType=\"dijit.form.TextBox\" + placeHolder=\"".__("Login")."\" disabled=\"1\" + name=\"auth_login\" value=\"$auth_login\">"; + + $this->batch_edit_cbox("auth_login"); + + print "<br/><input dojoType=\"dijit.form.TextBox\" type=\"password\" name=\"auth_pass\" + placeHolder=\"".__("Password")."\" disabled=\"1\" + value=\"$auth_pass\">"; + + $this->batch_edit_cbox("auth_pass"); + + print "</div>"; + print "<div class=\"dlgSec\">".__("Options")."</div>"; + print "<div class=\"dlgSecCont\">"; + + print "<input disabled=\"1\" type=\"checkbox\" name=\"private\" id=\"private\" + dojoType=\"dijit.form.CheckBox\"> <label id=\"private_l\" class='insensitive' for=\"private\">".__('Hide from Popular feeds')."</label>"; + + print " "; $this->batch_edit_cbox("private", "private_l"); + + print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"rtl_content\" name=\"rtl_content\" + dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"rtl_content_l\" for=\"rtl_content\">".__('Right-to-left content')."</label>"; + + print " "; $this->batch_edit_cbox("rtl_content", "rtl_content_l"); + + print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"include_in_digest\" + name=\"include_in_digest\" + dojoType=\"dijit.form.CheckBox\"> <label id=\"include_in_digest_l\" class='insensitive' for=\"include_in_digest\">".__('Include in e-mail digest')."</label>"; + + print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l"); + + print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"always_display_enclosures\" + name=\"always_display_enclosures\" + dojoType=\"dijit.form.CheckBox\"> <label id=\"always_display_enclosures_l\" class='insensitive' for=\"always_display_enclosures\">".__('Always display image attachments')."</label>"; + + print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l"); + + if (SIMPLEPIE_CACHE_IMAGES) { + print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"cache_images\" + name=\"cache_images\" + dojoType=\"dijit.form.CheckBox\"> <label class='insensitive' id=\"cache_images_l\" + for=\"cache_images\">". + __('Cache images locally')."</label>"; + + + print " "; $this->batch_edit_cbox("cache_images", "cache_images_l"); + } + + print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"mark_unread_on_update\" + name=\"mark_unread_on_update\" + dojoType=\"dijit.form.CheckBox\"> <label id=\"mark_unread_on_update_l\" class='insensitive' for=\"mark_unread_on_update\">".__('Mark updated articles as unread')."</label>"; + + print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l"); + + print "<br/><input disabled=\"1\" type=\"checkbox\" id=\"update_on_checksum_change\" + name=\"update_on_checksum_change\" + dojoType=\"dijit.form.CheckBox\"> <label id=\"update_on_checksum_change_l\" class='insensitive' for=\"update_on_checksum_change\">".__('Mark posts as updated on content change')."</label>"; + + print " "; $this->batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l"); + + print "</div>"; + + print "<div class='dlgButtons'> + <button dojoType=\"dijit.form.Button\" + onclick=\"return dijit.byId('feedEditDlg').execute()\">". + __('Save')."</button> + <button dojoType=\"dijit.form.Button\" + onclick=\"return dijit.byId('feedEditDlg').hide()\">". + __('Cancel')."</button> + </div>"; + + return; + } + + function batchEditSave() { + return editsaveops(true); + } + + function editSave() { + return editsaveops(false); + } + + function editsaveops($batch) { + + $feed_title = db_escape_string(trim($_POST["title"])); + $feed_link = db_escape_string(trim($_POST["feed_url"])); + $upd_intl = (int) db_escape_string($_POST["update_interval"]); + $purge_intl = (int) db_escape_string($_POST["purge_interval"]); + $feed_id = (int) db_escape_string($_POST["id"]); /* editSave */ + $feed_ids = db_escape_string($_POST["ids"]); /* batchEditSave */ + $cat_id = (int) db_escape_string($_POST["cat_id"]); + $auth_login = db_escape_string(trim($_POST["auth_login"])); + $auth_pass = db_escape_string(trim($_POST["auth_pass"])); + $private = checkbox_to_sql_bool(db_escape_string($_POST["private"])); + $rtl_content = checkbox_to_sql_bool(db_escape_string($_POST["rtl_content"])); + $include_in_digest = checkbox_to_sql_bool( + db_escape_string($_POST["include_in_digest"])); + $cache_images = checkbox_to_sql_bool( + db_escape_string($_POST["cache_images"])); + $update_method = (int) db_escape_string($_POST["update_method"]); + + $always_display_enclosures = checkbox_to_sql_bool( + db_escape_string($_POST["always_display_enclosures"])); + + $mark_unread_on_update = checkbox_to_sql_bool( + db_escape_string($_POST["mark_unread_on_update"])); + + $update_on_checksum_change = checkbox_to_sql_bool( + db_escape_string($_POST["update_on_checksum_change"])); + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + if ($cat_id && $cat_id != 0) { + $category_qpart = "cat_id = '$cat_id',"; + $category_qpart_nocomma = "cat_id = '$cat_id'"; + } else { + $category_qpart = 'cat_id = NULL,'; + $category_qpart_nocomma = 'cat_id = NULL'; + } + } else { + $category_qpart = ""; + $category_qpart_nocomma = ""; + } + + if (SIMPLEPIE_CACHE_IMAGES) { + $cache_images_qpart = "cache_images = $cache_images,"; + } else { + $cache_images_qpart = ""; + } + + if ($method == "editSave") { + + $result = db_query($this->link, "UPDATE ttrss_feeds SET + $category_qpart + title = '$feed_title', feed_url = '$feed_link', + update_interval = '$upd_intl', + purge_interval = '$purge_intl', + auth_login = '$auth_login', + auth_pass = '$auth_pass', + private = $private, + rtl_content = $rtl_content, + $cache_images_qpart + include_in_digest = $include_in_digest, + always_display_enclosures = $always_display_enclosures, + mark_unread_on_update = $mark_unread_on_update, + update_on_checksum_change = $update_on_checksum_change, + update_method = '$update_method' + WHERE id = '$feed_id' AND owner_uid = " . $_SESSION["uid"]); + + } else if ($batch) { + $feed_data = array(); + + foreach (array_keys($_POST) as $k) { + if ($k != "op" && $k != "method" && $k != "ids") { + $feed_data[$k] = $_POST[$k]; + } + } + + db_query($this->link, "BEGIN"); + + foreach (array_keys($feed_data) as $k) { + + $qpart = ""; + + switch ($k) { + case "title": + $qpart = "title = '$feed_title'"; + break; + + case "feed_url": + $qpart = "feed_url = '$feed_link'"; + break; + + case "update_interval": + $qpart = "update_interval = '$upd_intl'"; + break; + + case "purge_interval": + $qpart = "purge_interval = '$purge_intl'"; + break; + + case "auth_login": + $qpart = "auth_login = '$auth_login'"; + break; + + case "auth_pass": + $qpart = "auth_pass = '$auth_pass'"; + break; + + case "private": + $qpart = "private = '$private'"; + break; + + case "include_in_digest": + $qpart = "include_in_digest = '$include_in_digest'"; + break; + + case "always_display_enclosures": + $qpart = "always_display_enclosures = '$always_display_enclosures'"; + break; + + case "mark_unread_on_update": + $qpart = "mark_unread_on_update = '$mark_unread_on_update'"; + break; + + case "update_on_checksum_change": + $qpart = "update_on_checksum_change = '$update_on_checksum_change'"; + break; + + case "cache_images": + $qpart = "cache_images = '$cache_images'"; + break; + + case "rtl_content": + $qpart = "rtl_content = '$rtl_content'"; + break; + + case "update_method": + $qpart = "update_method = '$update_method'"; + break; + + case "cat_id": + $qpart = $category_qpart_nocomma; + break; + + } + + if ($qpart) { + db_query($this->link, + "UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids) + AND owner_uid = " . $_SESSION["uid"]); + print "<br/>"; + } + } + + db_query($this->link, "COMMIT"); + } + return; + } + + function resetPubSub() { + + $ids = db_escape_string($_REQUEST["ids"]); + + db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0 WHERE id IN ($ids) + AND owner_uid = " . $_SESSION["uid"]); + + return; + } + + function remove() { + + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + remove_feed($this->link, $id, $_SESSION["uid"]); + } + + return; + } + + function clear() { + $id = db_escape_string($_REQUEST["id"]); + clear_feed_articles($this->link, $id); + } + + function rescore() { + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + + $filters = load_filters($this->link, $id, $_SESSION["uid"], 6); + + $result = db_query($this->link, "SELECT + title, content, link, ref_id, author,". + SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated + FROM + ttrss_user_entries, ttrss_entries + WHERE ref_id = id AND feed_id = '$id' AND + owner_uid = " .$_SESSION['uid']." + "); + + $scores = array(); + + while ($line = db_fetch_assoc($result)) { + + $tags = get_article_tags($this->link, $line["ref_id"]); + + $article_filters = get_article_filters($filters, $line['title'], + $line['content'], $line['link'], strtotime($line['updated']), + $line['author'], $tags); + + $new_score = calculate_article_score($article_filters); + + if (!$scores[$new_score]) $scores[$new_score] = array(); + + array_push($scores[$new_score], $line['ref_id']); + } + + foreach (array_keys($scores) as $s) { + if ($s > 1000) { + db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s', + marked = true WHERE + ref_id IN (" . join(',', $scores[$s]) . ")"); + } else if ($s < -500) { + db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s', + unread = false WHERE + ref_id IN (" . join(',', $scores[$s]) . ")"); + } else { + db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s' WHERE + ref_id IN (" . join(',', $scores[$s]) . ")"); + } + } + } + + print __("All done."); + + } + + function rescoreAll() { + + $result = db_query($this->link, + "SELECT id FROM ttrss_feeds WHERE owner_uid = " . $_SESSION['uid']); + + while ($feed_line = db_fetch_assoc($result)) { + + $id = $feed_line["id"]; + + $filters = load_filters($this->link, $id, $_SESSION["uid"], 6); + + $tmp_result = db_query($this->link, "SELECT + title, content, link, ref_id, author,". + SUBSTRING_FOR_DATE."(updated, 1, 19) AS updated + FROM + ttrss_user_entries, ttrss_entries + WHERE ref_id = id AND feed_id = '$id' AND + owner_uid = " .$_SESSION['uid']." + "); + + $scores = array(); + + while ($line = db_fetch_assoc($tmp_result)) { + + $tags = get_article_tags($this->link, $line["ref_id"]); + + $article_filters = get_article_filters($filters, $line['title'], + $line['content'], $line['link'], strtotime($line['updated']), + $line['author'], $tags); + + $new_score = calculate_article_score($article_filters); + + if (!$scores[$new_score]) $scores[$new_score] = array(); + + array_push($scores[$new_score], $line['ref_id']); + } + + foreach (array_keys($scores) as $s) { + if ($s > 1000) { + db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s', + marked = true WHERE + ref_id IN (" . join(',', $scores[$s]) . ")"); + } else { + db_query($this->link, "UPDATE ttrss_user_entries SET score = '$s' WHERE + ref_id IN (" . join(',', $scores[$s]) . ")"); + } + } + } + + print __("All done."); + + } + + function add() { + $feed_url = db_escape_string(trim($_REQUEST["feed_url"])); + $cat_id = db_escape_string($_REQUEST["cat_id"]); + $p_from = db_escape_string($_REQUEST["from"]); + + /* only read authentication information from POST */ + + $auth_login = db_escape_string(trim($_POST["auth_login"])); + $auth_pass = db_escape_string(trim($_POST["auth_pass"])); + + if ($p_from != 'tt-rss') { + header("Content-Type: text/html"); + print "<html> + <head> + <title>Tiny Tiny RSS</title> + <link rel=\"stylesheet\" type=\"text/css\" href=\"utility.css\"> + </head> + <body> + <img class=\"floatingLogo\" src=\"images/ttrss_logo.png\" + alt=\"Tiny Tiny RSS\"/> + <h1>Subscribe to feed...</h1>"; + } + + $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass); + + switch ($rc) { + case 1: + print_notice(T_sprintf("Subscribed to <b>%s</b>.", $feed_url)); + break; + case 2: + print_error(T_sprintf("Could not subscribe to <b>%s</b>.", $feed_url)); + break; + case 3: + print_error(T_sprintf("No feeds found in <b>%s</b>.", $feed_url)); + break; + case 0: + print_warning(T_sprintf("Already subscribed to <b>%s</b>.", $feed_url)); + break; + case 4: + print_notice("Multiple feed URLs found."); + + $feed_urls = get_feeds_from_html($feed_url); + break; + case 5: + print_error(T_sprintf("Could not subscribe to <b>%s</b>.<br>Can't download the Feed URL.", $feed_url)); + break; + } + + if ($p_from != 'tt-rss') { + + if ($feed_urls) { + + print "<form action=\"backend.php\">"; + print "<input type=\"hidden\" name=\"op\" value=\"pref-feeds\">"; + print "<input type=\"hidden\" name=\"quiet\" value=\"1\">"; + print "<input type=\"hidden\" name=\"method\" value=\"add\">"; + + print "<select name=\"feed_url\">"; + + foreach ($feed_urls as $url => $name) { + $url = htmlspecialchars($url); + $name = htmlspecialchars($name); + + print "<option value=\"$url\">$name</option>"; + } + + print "<input type=\"submit\" value=\"".__("Subscribe to selected feed"). + "\">"; + + print "</form>"; + } + + $tp_uri = get_self_url_prefix() . "/prefs.php"; + $tt_uri = get_self_url_prefix(); + + if ($rc <= 2){ + $result = db_query($this->link, "SELECT id FROM ttrss_feeds WHERE + feed_url = '$feed_url' AND owner_uid = " . $_SESSION["uid"]); + + $feed_id = db_fetch_result($result, 0, "id"); + } else { + $feed_id = 0; + } + print "<p>"; + + if ($feed_id) { + print "<form method=\"GET\" style='display: inline' + action=\"$tp_uri\"> + <input type=\"hidden\" name=\"tab\" value=\"feedConfig\"> + <input type=\"hidden\" name=\"method\" value=\"editFeed\"> + <input type=\"hidden\" name=\"methodparam\" value=\"$feed_id\"> + <input type=\"submit\" value=\"".__("Edit subscription options")."\"> + </form>"; + } + + print "<form style='display: inline' method=\"GET\" action=\"$tt_uri\"> + <input type=\"submit\" value=\"".__("Return to Tiny Tiny RSS")."\"> + </form></p>"; + + print "</body></html>"; + return; + } + } + + function categorize() { + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + $cat_id = db_escape_string($_REQUEST["cat_id"]); + + if ($cat_id == 0) { + $cat_id_qpart = 'NULL'; + } else { + $cat_id_qpart = "'$cat_id'"; + } + + db_query($this->link, "BEGIN"); + + foreach ($ids as $id) { + + db_query($this->link, "UPDATE ttrss_feeds SET cat_id = $cat_id_qpart + WHERE id = '$id' + AND owner_uid = " . $_SESSION["uid"]); + + } + + db_query($this->link, "COMMIT"); + } + + function editCats() { + + $action = $_REQUEST["action"]; + + if ($action == "save") { + + $cat_title = db_escape_string(trim($_REQUEST["value"])); + $cat_id = db_escape_string($_REQUEST["cid"]); + + db_query($this->link, "BEGIN"); + + $result = db_query($this->link, "SELECT title FROM ttrss_feed_categories + WHERE id = '$cat_id' AND owner_uid = ".$_SESSION["uid"]); + + if (db_num_rows($result) == 1) { + + $old_title = db_fetch_result($result, 0, "title"); + + if ($cat_title != "") { + $result = db_query($this->link, "UPDATE ttrss_feed_categories SET + title = '$cat_title' WHERE id = '$cat_id' AND + owner_uid = ".$_SESSION["uid"]); + + print $cat_title; + } else { + print $old_title; + } + } else { + print $_REQUEST["value"]; + } + + db_query($this->link, "COMMIT"); + + return; + + } + + if ($action == "add") { + + $feed_cat = db_escape_string(trim($_REQUEST["cat"])); + + if (!add_feed_category($this->link, $feed_cat)) + print_warning(T_sprintf("Category <b>$%s</b> already exists in the database.", $feed_cat)); + + } + + if ($action == "remove") { + + $ids = split(",", db_escape_string($_REQUEST["ids"])); + + foreach ($ids as $id) { + remove_feed_category($this->link, $id, $_SESSION["uid"]); + } + } + + print "<div dojoType=\"dijit.Toolbar\"> + <input dojoType=\"dijit.form.ValidationTextBox\" required=\"1\" name=\"newcat\"> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').addCategory()\">". + __('Create category')."</button></div>"; + + $result = db_query($this->link, "SELECT title,id FROM ttrss_feed_categories + WHERE owner_uid = ".$_SESSION["uid"]." + ORDER BY title"); + + if (db_num_rows($result) != 0) { + + print "<div class=\"prefFeedCatHolder\">"; + + print "<table width=\"100%\" class=\"prefFeedCatList\" + cellspacing=\"0\" id=\"prefFeedCatList\">"; + + $lnum = 0; + + while ($line = db_fetch_assoc($result)) { + + $class = ($lnum % 2) ? "even" : "odd"; + + $cat_id = $line["id"]; + $this_row_id = "id=\"FCATR-$cat_id\""; + + print "<tr class=\"\" $this_row_id>"; + + $edit_title = htmlspecialchars($line["title"]); + + print "<td width='5%' align='center'><input + onclick='toggleSelectRow2(this);' dojoType=\"dijit.form.CheckBox\" + type=\"checkbox\"></td>"; + + print "<td>"; + + print "<span dojoType=\"dijit.InlineEditBox\" + width=\"300px\" autoSave=\"false\" + cat-id=\"$cat_id\">" . $edit_title . + "<script type=\"dojo/method\" event=\"onChange\" args=\"item\"> + var elem = this; + dojo.xhrPost({ + url: 'backend.php', + content: {op: 'pref-feeds', method: 'editCats', + action: 'save', + value: this.value, + cid: this.srcNodeRef.getAttribute('cat-id')}, + load: function(response) { + elem.attr('value', response); + updateFeedList(); + } + }); + </script> + </span>"; + + print "</td></tr>"; + + ++$lnum; + } + + print "</table>"; + print "</div>"; + + } else { + print "<p>".__('No feed categories defined.')."</p>"; + } + + print "<div class='dlgButtons'> + <div style='float : left'> + <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').removeSelected()\">". + __('Remove selected categories')."</button> + </div>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedCatEditDlg').hide()\">". + __('Close this window')."</button></div>"; + + return; + + } + + function index() { + + print "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; + print "<div id=\"pref-feeds-feeds\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Feeds')."\">"; + + $result = db_query($this->link, "SELECT COUNT(id) AS num_errors + FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ".$_SESSION["uid"]); + + $num_errors = db_fetch_result($result, 0, "num_errors"); + + if ($num_errors > 0) { + + $error_button = "<button dojoType=\"dijit.form.Button\" + onclick=\"showFeedsWithErrors()\" id=\"errorButton\">" . + __("Feeds with errors") . "</button>"; + } + + 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 COUNT(*) AS num_inactive FROM ttrss_feeds 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"]); + + $num_inactive = db_fetch_result($result, 0, "num_inactive"); + + if ($num_inactive > 0) { + $inactive_button = "<button dojoType=\"dijit.form.Button\" + onclick=\"showInactiveFeeds()\">" . + __("Inactive feeds") . "</button>"; + } + + $feed_search = db_escape_string($_REQUEST["search"]); + + if (array_key_exists("search", $_REQUEST)) { + $_SESSION["prefs_feed_search"] = $feed_search; + } else { + $feed_search = $_SESSION["prefs_feed_search"]; + } + + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; + + print "<div region='top' dojoType=\"dijit.Toolbar\">"; #toolbar + + print "<div style='float : right; padding-right : 4px;'> + <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\" + value=\"$feed_search\"> + <button dojoType=\"dijit.form.Button\" onclick=\"updateFeedList()\">". + __('Search')."</button> + </div>"; + + print "<div dojoType=\"dijit.form.DropDownButton\">". + "<span>" . __('Select')."</span>"; + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; + print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\" + dojoType=\"dijit.MenuItem\">".__('All')."</div>"; + print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\" + dojoType=\"dijit.MenuItem\">".__('None')."</div>"; + print "</div></div>"; + + print "<div dojoType=\"dijit.form.DropDownButton\">". + "<span>" . __('Feeds')."</span>"; + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; + print "<div onclick=\"quickAddFeed()\" + dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>"; + print "<div onclick=\"editSelectedFeed()\" + dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>"; + print "<div onclick=\"resetFeedOrder()\" + dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; + print "</div></div>"; + + if (get_pref($this->link, 'ENABLE_FEED_CATS')) { + print "<div dojoType=\"dijit.form.DropDownButton\">". + "<span>" . __('Categories')."</span>"; + print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">"; + print "<div onclick=\"editFeedCats()\" + dojoType=\"dijit.MenuItem\">".__('Edit categories')."</div>"; + print "<div onclick=\"resetCatOrder()\" + dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>"; + print "</div></div>"; + + } + + print $error_button; + print $inactive_button; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"removeSelectedFeeds()\">" + .__('Unsubscribe')."</button dojoType=\"dijit.form.Button\"> "; + + if (defined('_ENABLE_FEED_DEBUGGING')) { + + print "<select id=\"feedActionChooser\" onchange=\"feedActionChange()\"> + <option value=\"facDefault\" selected>".__('More actions...')."</option>"; + + if (FORCE_ARTICLE_PURGE == 0) { + print + "<option value=\"facPurge\">".__('Manual purge')."</option>"; + } + + print " + <option value=\"facClear\">".__('Clear feed data')."</option> + <option value=\"facRescore\">".__('Rescore articles')."</option>"; + + print "</select>"; + + } + + print "</div>"; # toolbar + + //print '</div>'; + print '<div dojoType="dijit.layout.ContentPane" region="center">'; + + print "<div id=\"feedlistLoading\"> + <img src='images/indicator_tiny.gif'>". + __("Loading, please wait...")."</div>"; + + print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\" + url=\"backend.php?op=pref-feeds&method=getfeedtree\"> + </div> + <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\" + query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\" + childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\"> + </div> + <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\" + dndController=\"dijit.tree.dndSource\" + betweenThreshold=\"5\" + model=\"feedModel\" openOnClick=\"false\"> + <script type=\"dojo/method\" event=\"onClick\" args=\"item\"> + var id = String(item.id); + var bare_id = id.substr(id.indexOf(':')+1); + + if (id.match('FEED:')) { + editFeed(bare_id); + } else if (id.match('CAT:')) { + editCat(bare_id, item); + } + </script> + <script type=\"dojo/method\" event=\"onLoad\" args=\"item\"> + Element.hide(\"feedlistLoading\"); + </script> + </div>"; + + print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\"> + ".__('<b>Hint:</b> you can drag feeds and categories around.')." + </div>"; + + print '</div>'; + print '</div>'; + + print "</div>"; # feeds pane + + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('OPML')."\">"; + + print "<p>" . __("Using OPML you can export and import your feeds and Tiny Tiny RSS settings.") . " "; + + print "<span class=\"insensitive\">" . __("Note: Only main settings profile can be migrated using OPML.") . "</span>"; + + print "</p>"; + + print "<h3>" . __("Import") . "</h3>"; + + print "<br/><iframe id=\"upload_iframe\" + name=\"upload_iframe\" onload=\"opmlImportComplete(this)\" + style=\"width: 400px; height: 100px; display: none;\"></iframe>"; + + print "<form name=\"opml_form\" style='display : block' target=\"upload_iframe\" + enctype=\"multipart/form-data\" method=\"POST\" + action=\"backend.php\"> + <input id=\"opml_file\" name=\"opml_file\" type=\"file\"> + <input type=\"hidden\" name=\"op\" value=\"dlg\"> + <input type=\"hidden\" name=\"id\" value=\"importOpml\"> + <button dojoType=\"dijit.form.Button\" onclick=\"return opmlImport();\" type=\"submit\">" . + __('Import') . "</button>"; + + print "<h3>" . __("Export") . "</h3>"; + + print "<p>" . __('Filename:') . + " <input type=\"text\" id=\"filename\" value=\"TinyTinyRSS.opml\" /> " . + __('Include settings') . "<input type=\"checkbox\" id=\"settings\" CHECKED />" . + + "<button dojoType=\"dijit.form.Button\" + onclick=\"gotoExportOpml(document.opml_form.filename.value, document.opml_form.settings.checked)\" >" . + __('Export') . "</button></p></form>"; + + print "<h3>" . __("Publish") . "</h3>"; + + print "<p>".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " "; + + print "<span class=\"insensitive\">" . __("Note: Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "</span>" . "</p>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('pubOPMLUrl')\">". + __('Display URL')."</button> "; + + + print "</div>"; # pane + + if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) { + + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Firefox integration')."\">"; + + print "<p>" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "</p>"; + + print "<p>"; + + print "<button onclick='window.navigator.registerContentHandler(" . + "\"application/vnd.mozilla.maybe.feed\", " . + "\"" . add_feed_url() . "\", " . " \"Tiny Tiny RSS\")'>" . + __('Click here to register this site as a feed reader.') . + "</button>"; + + print "</p>"; + + print "</div>"; # pane + } + + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Subscribing using bookmarklet')."\">"; + + print "<p>" . __("Drag the link below to your browser toolbar, open the feed you're interested in in your browser and click on the link to subscribe to it.") . "</p>"; + + $bm_subscribe_url = str_replace('%s', '', add_feed_url()); + + $confirm_str = __('Subscribe to %s in Tiny Tiny RSS?'); + + $bm_url = htmlspecialchars("javascript:{if(confirm('$confirm_str'.replace('%s',window.location.href)))window.location.href='$bm_subscribe_url'+window.location.href}"); + + print "<a href=\"$bm_url\" class='bookmarklet'>" . __('Subscribe in Tiny Tiny RSS'). "</a>"; + + print "</div>"; #pane + + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Published & shared articles and generated feeds')."\">"; + + print "<h3>" . __("Published articles and generated feeds") . "</h3>"; + + print "<p>".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."</p>"; + + $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() . + "/public.php?op=rss&id=-2&view-mode=all_articles");; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return displayDlg('generatedFeed', '$rss_url')\">". + __('Display URL')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearFeedAccessKeys()\">". + __('Clear all generated URLs')."</button> "; + + print "<h3>" . __("Articles shared by URL") . "</h3>"; + + print "<p>" . __("You can disable all articles shared by unique URLs here.") . "</p>"; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return clearArticleAccessKeys()\">". + __('Unshare all articles')."</button> "; + + print "</div>"; #pane + + if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') { + + print "<div id=\"pref-feeds-twitter\" dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Twitter')."\">"; + + $result = db_query($this->link, "SELECT COUNT(*) AS cid FROM ttrss_users + WHERE twitter_oauth IS NOT NULL AND twitter_oauth != '' AND + id = " . $_SESSION['uid']); + + $is_registered = db_fetch_result($result, 0, "cid") != 0; + + if (!$is_registered) { + print_notice(__('Before you can update your Twitter feeds, you must register this instance of Tiny Tiny RSS with Twitter.com.')); + } else { + print_notice(__('You have been successfully registered with Twitter.com and should be able to access your Twitter feeds.')); + } + + print "<button dojoType=\"dijit.form.Button\" onclick=\"window.location.href = 'twitter.php?op=register'\">". + __("Register with Twitter.com")."</button>"; + + print " "; + + print "<button dojoType=\"dijit.form.Button\" + onclick=\"return clearTwitterCredentials()\">". + __("Clear stored credentials")."</button>"; + + print "</div>"; # pane + + } + + print "</div>"; #container + + } +} +?> 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 @@ +<?php +class Pref_Prefs extends Handler { + + function changepassword() { + + $old_pw = $_POST["old_password"]; + $new_pw = $_POST["new_password"]; + $con_pw = $_POST["confirm_password"]; + + if ($old_pw == "") { + print "ERROR: ".__("Old password cannot be blank."); + return; + } + + if ($new_pw == "") { + print "ERROR: ".__("New password cannot be blank."); + return; + } + + if ($new_pw != $con_pw) { + print "ERROR: ".__("Entered passwords do not match."); + return; + } + + $old_pw_hash1 = encrypt_password($old_pw); + $old_pw_hash2 = encrypt_password($old_pw, $_SESSION["name"]); + $new_pw_hash = encrypt_password($new_pw, $_SESSION["name"]); + + $active_uid = $_SESSION["uid"]; + + if ($old_pw && $new_pw) { + + $login = db_escape_string($_SERVER['PHP_AUTH_USER']); + + $result = db_query($this->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 "<div dojoType=\"dijit.layout.AccordionContainer\" region=\"center\">"; + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Personal data')."\">"; + + print "<form dojoType=\"dijit.form.Form\" id=\"changeUserdataForm\">"; + + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> + evt.preventDefault(); + if (this.validate()) { + notify_progress('Saving data...', true); + + new Ajax.Request('backend.php', { + parameters: dojo.objectToQuery(this.getValues()), + onComplete: function(transport) { + notify_callback2(transport); + } }); + + } + </script>"; + + print "<table width=\"100%\" class=\"prefPrefsList\">"; + + $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 "<tr><td width=\"40%\">".__('Full name')."</td>"; + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"full_name\" required=\"1\" + value=\"$full_name\"></td></tr>"; + + print "<tr><td width=\"40%\">".__('E-mail')."</td>"; + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" name=\"email\" required=\"1\" value=\"$email\"></td></tr>"; + + if (!SINGLE_USER_MODE) { + $access_level = db_fetch_result($result, 0, "access_level"); + print "<tr><td width=\"40%\">".__('Access level')."</td>"; + print "<td>" . $access_level_names[$access_level] . "</td></tr>"; + } + + print "</table>"; + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changeemail\">"; + + print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". + __("Save data")."</button>"; + + print "</form>"; + + print "</div>"; # pane + print "<div dojoType=\"dijit.layout.AccordionPane\" title=\"".__('Authentication')."\">"; + + $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 "<form dojoType=\"dijit.form.Form\">"; + + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> + evt.preventDefault(); + if (this.validate()) { + notify_progress('Changing password...', true); + + new Ajax.Request('backend.php', { + parameters: dojo.objectToQuery(this.getValues()), + onComplete: function(transport) { + notify(''); + if (transport.responseText.indexOf('ERROR: ') == 0) { + notify_error(transport.responseText.replace('ERROR: ', '')); + } else { + notify_info(transport.responseText); + var warn = $('default_pass_warning'); + if (warn) Element.hide(warn); + } + }}); + this.reset(); + } + </script>"; + + print "<table width=\"100%\" class=\"prefPrefsList\">"; + + print "<tr><td width=\"40%\">".__("Old password")."</td>"; + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"old_password\"></td></tr>"; + + print "<tr><td width=\"40%\">".__("New password")."</td>"; + + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" + name=\"new_password\"></td></tr>"; + + print "<tr><td width=\"40%\">".__("Confirm password")."</td>"; + + print "<td class=\"prefValue\"><input dojoType=\"dijit.form.ValidationTextBox\" type=\"password\" required=\"1\" name=\"confirm_password\"></td></tr>"; + + print "</table>"; + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"changepassword\">"; + + print "<p><button dojoType=\"dijit.form.Button\" type=\"submit\">". + __("Change password")."</button>"; + + print "</form>"; + + print "</div>"; #pane + } + + print "<div dojoType=\"dijit.layout.AccordionPane\" selected=\"true\" title=\"".__('Preferences')."\">"; + + print "<form dojoType=\"dijit.form.Form\" id=\"changeSettingsForm\">"; + + print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\"> + evt.preventDefault(); + if (this.validate()) { + console.log(dojo.objectToQuery(this.getValues())); + + new Ajax.Request('backend.php', { + parameters: dojo.objectToQuery(this.getValues()), + onComplete: function(transport) { + var msg = transport.responseText; + if (msg.match('PREFS_THEME_CHANGED')) { + window.location.reload(); + } else { + notify_info(msg); + } + } }); + } + </script>"; + + print '<div dojoType="dijit.layout.BorderContainer" gutters="false">'; + + print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">'; + + 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 "</table>"; + } + + print "<table width=\"100%\" class=\"prefPrefsList\">"; + + $active_section = $line["section_name"]; + + print "<tr><td colspan=\"3\"><h3>".__($active_section)."</h3></td></tr>"; + + if ($line["section_id"] == 2) { + print "<tr><td width=\"40%\">".__("Select theme")."</td>"; + + $user_theme = get_pref($this->link, "_THEME_ID"); + $themes = get_all_themes(); + + print "<td><select name=\"_THEME_ID\" dojoType=\"dijit.form.Select\">"; + print "<option value='Default'>".__('Default')."</option>"; + print "<option value='----------------' disabled=\"1\">--------</option>"; + + foreach ($themes as $t) { + $base = $t['base']; + $name = $t['name']; + + if ($base == $user_theme) { + $selected = "selected=\"1\""; + } else { + $selected = ""; + } + + print "<option $selected value='$base'>$name</option>"; + + } + + print "</select></td></tr>"; + } + $lnum = 0; + } + + print "<tr>"; + + $type_name = $line["type_name"]; + $pref_name = $line["pref_name"]; + $value = $line["value"]; + $def_value = $line["def_value"]; + $help_text = $line["help_text"]; + + print "<td width=\"40%\" class=\"prefName\" id=\"$pref_name\">" . __($line["short_desc"]); + + if ($help_text) print "<div class=\"prefHelp\">".__($help_text)."</div>"; + + print "</td>"; + + print "<td class=\"prefValue\">"; + + 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 "<button dojoType=\"dijit.form.Button\" + onclick=\"customizeCSS()\">" . __('Customize') . "</button>"; + + } 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 "<input dojoType=\"dijit.form.ValidationTextBox\" + required=\"1\" $regexp $disabled + name=\"$pref_name\" value=\"$value\">"; + + } else if ($pref_name == "SSL_CERT_SERIAL") { + + print "<input dojoType=\"dijit.form.ValidationTextBox\" + id=\"SSL_CERT_SERIAL\" readonly=\"1\" + name=\"$pref_name\" value=\"$value\">"; + + $cert_serial = htmlspecialchars(get_ssl_certificate_id()); + $has_serial = ($cert_serial) ? "false" : "true"; + + print " <button dojoType=\"dijit.form.Button\" disabled=\"$has_serial\" + onclick=\"insertSSLserial('$cert_serial')\">" . + __('Register') . "</button>"; + + print " <button dojoType=\"dijit.form.Button\" + onclick=\"insertSSLserial('')\">" . + __('Clear') . "</button>"; + + } else { + $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : ''; + + print "<input dojoType=\"dijit.form.ValidationTextBox\" + $regexp + name=\"$pref_name\" value=\"$value\">"; + } + + print "</td>"; + + print "</tr>"; + + $lnum++; + } + + print "</table>"; + + print '</div>'; # inside pane + print '<div dojoType="dijit.layout.ContentPane" region="bottom">'; + + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"op\" value=\"pref-prefs\">"; + print "<input dojoType=\"dijit.form.TextBox\" style=\"display : none\" name=\"method\" value=\"saveconfig\">"; + + print "<button dojoType=\"dijit.form.Button\" type=\"submit\">". + __('Save configuration')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return editProfiles()\">". + __('Manage profiles')."</button> "; + + print "<button dojoType=\"dijit.form.Button\" onclick=\"return validatePrefsReset()\">". + __('Reset to defaults')."</button>"; + + print '</div>'; # inner pane + print '</div>'; # border container + + print "</form>"; + + print "</div>"; #pane + print "</div>"; #container + } +} +?> 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 @@ +<?php +class RPC extends Handler { + + function setprofile() { + $id = db_escape_string($_REQUEST["id"]); + + $_SESSION["profile"] = $id; + $_SESSION["prefs_cache"] = array(); + } + + function remprofiles() { + $ids = explode(",", db_escape_string(trim($_REQUEST["ids"]))); + + foreach ($ids as $id) { + if ($_SESSION["profile"] != $id) { + db_query($this->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", "<br/>", $_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 "<!-- $id : $int_id : $tag -->"; + + 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 "<ul>"; + while ($line = db_fetch_assoc($result)) { + print "<li>" . $line["tag_name"] . "</li>"; + } + print "</ul>"; + } + + 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 "<ul>"; + + foreach ($_SESSION['stored_emails'] as $email) { + if (strpos($email, $search) !== false) { + print "<li>$email</li>"; + } + } + + print "</ul>"; + } + + 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)); + } +} +?> |