+ /**
+ * Purge a feed contents, marked articles excepted.
+ *
+ * @param mixed $link The database connection.
+ * @param integer $id The id of the feed to purge.
+ * @return void
+ */
+ private function clear_feed_articles($id) {
+
+ if ($id != 0) {
+ $result = db_query( "DELETE FROM ttrss_user_entries
+ WHERE feed_id = '$id' AND marked = false AND owner_uid = " . $_SESSION["uid"]);
+ } else {
+ $result = db_query( "DELETE FROM ttrss_user_entries
+ WHERE feed_id IS NULL AND marked = false AND owner_uid = " . $_SESSION["uid"]);
+ }
+
+ $result = db_query( "DELETE FROM ttrss_entries WHERE
+ (SELECT COUNT(int_id) FROM ttrss_user_entries WHERE ref_id = id) = 0");
+
+ ccache_update( $id, $_SESSION['uid']);
+ } // function clear_feed_articles
+
+ private function remove_feed_category( $id, $owner_uid) {
+
+ db_query( "DELETE FROM ttrss_feed_categories
+ WHERE id = '$id' AND owner_uid = $owner_uid");
+
+ ccache_remove( $id, $owner_uid, true);
+ }
+
+ static function remove_feed( $id, $owner_uid) {
+
+ if ($id > 0) {
+
+ /* save starred articles in Archived feed */
+
+ db_query( "BEGIN");
+
+ /* prepare feed if necessary */
+
+ $result = db_query( "SELECT feed_url FROM ttrss_feeds WHERE id = $id
+ AND owner_uid = $owner_uid");
+
+ $feed_url = db_escape_string( db_fetch_result($result, 0, "feed_url"));
+
+ $result = db_query( "SELECT id FROM ttrss_archived_feeds
+ WHERE feed_url = '$feed_url' AND owner_uid = $owner_uid");
+
+ if (db_num_rows($result) == 0) {
+ $result = db_query( "SELECT MAX(id) AS id FROM ttrss_archived_feeds");
+ $new_feed_id = (int)db_fetch_result($result, 0, "id") + 1;
+
+ db_query( "INSERT INTO ttrss_archived_feeds
+ (id, owner_uid, title, feed_url, site_url)
+ SELECT $new_feed_id, owner_uid, title, feed_url, site_url from ttrss_feeds
+ WHERE id = '$id'");
+
+ $archive_id = $new_feed_id;
+ } else {
+ $archive_id = db_fetch_result($result, 0, "id");
+ }
+
+ db_query( "UPDATE ttrss_user_entries SET feed_id = NULL,
+ orig_feed_id = '$archive_id' WHERE feed_id = '$id' AND
+ marked = true AND owner_uid = $owner_uid");
+
+ /* Remove access key for the feed */
+
+ db_query( "DELETE FROM ttrss_access_keys WHERE
+ feed_id = '$id' AND owner_uid = $owner_uid");
+
+ /* remove the feed */
+
+ db_query( "DELETE FROM ttrss_feeds
+ WHERE id = '$id' AND owner_uid = $owner_uid");
+
+ db_query( "COMMIT");
+
+ if (file_exists(ICONS_DIR . "/$id.ico")) {
+ unlink(ICONS_DIR . "/$id.ico");
+ }
+
+ ccache_remove( $id, $owner_uid);
+
+ } else {
+ label_remove( feed_to_label_id($id), $owner_uid);
+ //ccache_remove( $id, $owner_uid); don't think labels are cached
+ }
+ }
+
+ function batchSubscribe() {
+ 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=\"batchaddfeeds\">";
+
+ print "<table width='100%'><tr><td>
+ ".__("Add one valid RSS feed per line (no feed detection is done)")."
+ </td><td align='right'>";
+ if (get_pref( 'ENABLE_FEED_CATS')) {
+ print __('Place in category:') . " ";
+ print_feed_cat_select( "cat", false, 'dojoType="dijit.form.Select"');
+ }
+ print "</td></tr><tr><td colspan='2'>";
+ print "<textarea
+ style='font-size : 12px; width : 100%; height: 200px;'
+ placeHolder=\"".__("Feeds to subscribe, One per line")."\"
+ dojoType=\"dijit.form.SimpleTextarea\" required=\"1\" name=\"feeds\"></textarea>";
+
+ print "</td></tr><tr><td colspan='2'>";
+
+ print "<div id='feedDlg_loginContainer' style='display : none'>
+ " .
+ " <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>";
+
+ print "</td></tr><tr><td colspan='2'>";
+
+ print "<div style=\"clear : both\">
+ <input type=\"checkbox\" name=\"need_auth\" dojoType=\"dijit.form.CheckBox\" id=\"feedDlg_loginCheck\"
+ onclick='checkboxToggleElement(this, \"feedDlg_loginContainer\")'>
+ <label for=\"feedDlg_loginCheck\">".
+ __('Feeds require authentication.')."</div>";
+
+ print "</form>";
+
+ print "</td></tr></table>";
+
+ print "<div class=\"dlgButtons\">
+ <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').execute()\">".__('Subscribe')."</button>
+ <button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('batchSubDlg').hide()\">".__('Cancel')."</button>
+ </div>";
+ }
+
+ function batchAddFeeds() {
+ $cat_id = db_escape_string( $_REQUEST['cat']);
+ $feeds = explode("\n", $_REQUEST['feeds']);
+ $login = db_escape_string( $_REQUEST['login']);
+ $pass = trim($_REQUEST['pass']);
+
+ foreach ($feeds as $feed) {
+ $feed = db_escape_string( trim($feed));
+
+ if (validate_feed_url($feed)) {
+
+ db_query( "BEGIN");
+
+ if ($cat_id == "0" || !$cat_id) {
+ $cat_qpart = "NULL";
+ } else {
+ $cat_qpart = "'$cat_id'";
+ }
+
+ $result = db_query(
+ "SELECT id FROM ttrss_feeds
+ WHERE feed_url = '$feed' AND owner_uid = ".$_SESSION["uid"]);
+
+ if (strlen(FEED_CRYPT_KEY) > 0) {
+ require_once "crypt.php";
+ $pass = substr(encrypt_string($pass), 0, 250);
+ $auth_pass_encrypted = 'true';
+ } else {
+ $auth_pass_encrypted = 'false';
+ }
+
+ $pass = db_escape_string( $pass);
+
+ if (db_num_rows($result) == 0) {
+ $result = db_query(
+ "INSERT INTO ttrss_feeds
+ (owner_uid,feed_url,title,cat_id,auth_login,auth_pass,update_method,auth_pass_encrypted)
+ VALUES ('".$_SESSION["uid"]."', '$feed',
+ '[Unknown]', $cat_qpart, '$login', '$pass', 0, $auth_pass_encrypted)");
+ }
+
+ db_query( "COMMIT");
+ }
+ }
+ }
+
+ function regenOPMLKey() {
+ $this->update_feed_access_key( 'OPML:Publish',
+ false, $_SESSION["uid"]);
+
+ $new_link = Opml::opml_publish_url();
+
+ print json_encode(array("link" => $new_link));
+ }
+
+ function regenFeedKey() {
+ $feed_id = db_escape_string( $_REQUEST['id']);
+ $is_cat = db_escape_string( $_REQUEST['is_cat']) == "true";
+
+ $new_key = $this->update_feed_access_key( $feed_id, $is_cat);
+
+ print json_encode(array("link" => $new_key));
+ }
+
+
+ private function update_feed_access_key( $feed_id, $is_cat, $owner_uid = false) {
+ if (!$owner_uid) $owner_uid = $_SESSION["uid"];
+
+ $sql_is_cat = bool_to_sql_bool($is_cat);
+
+ $result = db_query( "SELECT access_key FROM ttrss_access_keys
+ WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
+ AND owner_uid = " . $owner_uid);
+
+ if (db_num_rows($result) == 1) {
+ $key = db_escape_string( sha1(uniqid(rand(), true)));
+
+ db_query( "UPDATE ttrss_access_keys SET access_key = '$key'
+ WHERE feed_id = '$feed_id' AND is_cat = $sql_is_cat
+ AND owner_uid = " . $owner_uid);
+
+ return $key;
+
+ } else {
+ return get_feed_access_key( $feed_id, $is_cat, $owner_uid);
+ }
+ }
+
+ // Silent
+ function clearKeys() {
+ db_query( "DELETE FROM ttrss_access_keys WHERE
+ owner_uid = " . $_SESSION["uid"]);
+ }
+
+