From: Andrew Dolgov
Date: Fri, 17 Aug 2012 10:20:55 +0000 (+0400)
Subject: rework class system to use subdirectories
X-Git-Tag: 1.6.0~132
X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=369dbc19d6ae35c97a2306ae4821c7812e2f24b2;p=tt-rss.git
rework class system to use subdirectories
add placeholder plugin/hook system
---
diff --git a/backend.php b/backend.php
index 13568d16..b0ef5e0f 100644
--- a/backend.php
+++ b/backend.php
@@ -77,6 +77,8 @@
return;
}
+ $plugins = new Plugins($link);
+
$purge_intervals = array(
0 => __("Use default"),
-1 => __("Never purge"),
diff --git a/classes/article.php b/classes/article.php
index 30f0c7d1..16619c9a 100644
--- a/classes/article.php
+++ b/classes/article.php
@@ -1,5 +1,5 @@
link = $link;
+ }
+
+ function authenticate($login, $password) {
+ return false;
+ }
+
+ // Auto-creates specified user if allowed by system configuration
+ // Can be used instead of find_user_by_login() by external auth modules
+ function auto_create_user($login) {
+ if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
+ $user_id = $this->find_user_by_login($login);
+
+ if (!$user_id) {
+ $login = db_escape_string($login);
+ $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $pwd_hash = encrypt_password($password, $salt, true);
+
+ $query = "INSERT INTO ttrss_users
+ (login,access_level,last_login,created,pwd_hash,salt)
+ VALUES ('$login', 0, null, NOW(), '$pwd_hash','$salt')";
+
+ db_query($this->link, $query);
+
+ return $this->find_user_by_login($login);
+
+ } else {
+ return $user_id;
+ }
+ }
+
+ return $this->find_user_by_login($login);
+ }
+
+ function find_user_by_login($login) {
+ $login = db_escape_string($login);
+
+ $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
+ login = '$login'");
+
+ if (db_num_rows($result) > 0) {
+ return db_fetch_result($result, 0, "id");
+ } else {
+ return false;
+ }
+
+ }
+}
+
+?>
diff --git a/classes/auth/internal.php b/classes/auth/internal.php
new file mode 100644
index 00000000..8890d445
--- /dev/null
+++ b/classes/auth/internal.php
@@ -0,0 +1,118 @@
+link) > 87) {
+
+ $result = db_query($this->link, "SELECT salt FROM ttrss_users WHERE
+ login = '$login'");
+
+ if (db_num_rows($result) != 1) {
+ return false;
+ }
+
+ $salt = db_fetch_result($result, 0, "salt");
+
+ if ($salt == "") {
+
+ $query = "SELECT id
+ FROM ttrss_users WHERE
+ login = '$login' AND (pwd_hash = '$pwd_hash1' OR
+ pwd_hash = '$pwd_hash2')";
+
+ // verify and upgrade password to new salt base
+
+ $result = db_query($this->link, $query);
+
+ if (db_num_rows($result) == 1) {
+ // upgrade password to MODE2
+
+ $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $pwd_hash = encrypt_password($password, $salt, true);
+
+ db_query($this->link, "UPDATE ttrss_users SET
+ pwd_hash = '$pwd_hash', salt = '$salt' WHERE login = '$login'");
+
+ $query = "SELECT id
+ FROM ttrss_users WHERE
+ login = '$login' AND pwd_hash = '$pwd_hash'";
+
+ } else {
+ return false;
+ }
+
+ } else {
+
+ $pwd_hash = encrypt_password($password, $salt, true);
+
+ $query = "SELECT id
+ FROM ttrss_users WHERE
+ login = '$login' AND pwd_hash = '$pwd_hash'";
+
+ }
+
+ } else {
+ $query = "SELECT id
+ FROM ttrss_users WHERE
+ login = '$login' AND (pwd_hash = '$pwd_hash1' OR
+ pwd_hash = '$pwd_hash2')";
+ }
+
+ $result = db_query($this->link, $query);
+
+ if (db_num_rows($result) == 1) {
+ return db_fetch_result($result, 0, "id");
+ }
+
+ return false;
+ }
+
+ function change_password($owner_uid, $old_password, $new_password) {
+ $owner_uid = db_escape_string($owner_uid);
+
+ $result = db_query($this->link, "SELECT salt,login FROM ttrss_users WHERE
+ id = '$owner_uid'");
+
+ $salt = db_fetch_result($result, 0, "salt");
+ $login = db_fetch_result($result, 0, "login");
+
+ if (!$salt) {
+ $old_password_hash1 = encrypt_password($old_password);
+ $old_password_hash2 = encrypt_password($old_password, $login);
+
+ $query = "SELECT id FROM ttrss_users WHERE
+ id = '$owner_uid' AND (pwd_hash = '$old_password_hash1' OR
+ pwd_hash = '$old_password_hash2')";
+
+ } else {
+ $old_password_hash = encrypt_password($old_password, $salt, true);
+
+ $query = "SELECT id FROM ttrss_users WHERE
+ id = '$owner_uid' AND pwd_hash = '$old_password_hash'";
+ }
+
+ $result = db_query($this->link, $query);
+
+ if (db_num_rows($result) == 1) {
+
+ $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $new_password_hash = encrypt_password($new_password, $new_salt, true);
+
+ db_query($this->link, "UPDATE ttrss_users SET
+ pwd_hash = '$new_password_hash', salt = '$new_salt'
+ WHERE id = '$owner_uid'");
+
+ $_SESSION["pwd_hash"] = $new_password_hash;
+
+ return __("Password has been changed.");
+ } else {
+ return "ERROR: ".__('Old password is incorrect.');
+ }
+ }
+}
+?>
diff --git a/classes/auth/remote.php b/classes/auth/remote.php
new file mode 100644
index 00000000..6892a352
--- /dev/null
+++ b/classes/auth/remote.php
@@ -0,0 +1,61 @@
+link, "SELECT login FROM ttrss_user_prefs, ttrss_users
+ WHERE pref_name = 'SSL_CERT_SERIAL' AND value = '$cert_serial' AND
+ owner_uid = ttrss_users.id");
+
+ if (db_num_rows($result) != 0) {
+ return db_escape_string(db_fetch_result($result, 0, "login"));
+ }
+ }
+
+ return "";
+ }
+
+
+ function authenticate($login, $password) {
+ $try_login = db_escape_string($_SERVER["REMOTE_USER"]);
+
+ if (!$try_login) $try_login = $this->get_login_by_ssl_certificate();
+# if (!$try_login) $try_login = "test_qqq";
+
+ if ($try_login) {
+ $user_id = $this->auto_create_user($try_login);
+
+ if ($user_id) {
+ $_SESSION["fake_login"] = $try_login;
+ $_SESSION["fake_password"] = "******";
+ $_SESSION["hide_hello"] = true;
+ $_SESSION["hide_logout"] = true;
+
+ // LemonLDAP can send user informations via HTTP HEADER
+ if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){
+ // update user name
+ $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN'];
+ if ($fullname){
+ $fullname = db_escape_string($fullname);
+ db_query($this->link, "UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " .
+ $user_id);
+ }
+ // update user mail
+ $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL'];
+ if ($email){
+ $email = db_escape_string($email);
+ db_query($this->link, "UPDATE ttrss_users SET email = '$email' WHERE id = " .
+ $user_id);
+ }
+ }
+
+ return $user_id;
+ }
+ }
+
+ return false;
+ }
+}
+
+?>
diff --git a/classes/auth_base.php b/classes/auth_base.php
deleted file mode 100644
index 7c37967a..00000000
--- a/classes/auth_base.php
+++ /dev/null
@@ -1,55 +0,0 @@
-link = $link;
- }
-
- function authenticate($login, $password) {
- return false;
- }
-
- // Auto-creates specified user if allowed by system configuration
- // Can be used instead of find_user_by_login() by external auth modules
- function auto_create_user($login) {
- if ($login && defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE) {
- $user_id = $this->find_user_by_login($login);
-
- if (!$user_id) {
- $login = db_escape_string($login);
- $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $pwd_hash = encrypt_password($password, $salt, true);
-
- $query = "INSERT INTO ttrss_users
- (login,access_level,last_login,created,pwd_hash,salt)
- VALUES ('$login', 0, null, NOW(), '$pwd_hash','$salt')";
-
- db_query($this->link, $query);
-
- return $this->find_user_by_login($login);
-
- } else {
- return $user_id;
- }
- }
-
- return $this->find_user_by_login($login);
- }
-
- function find_user_by_login($login) {
- $login = db_escape_string($login);
-
- $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
- login = '$login'");
-
- if (db_num_rows($result) > 0) {
- return db_fetch_result($result, 0, "id");
- } else {
- return false;
- }
-
- }
-}
-
-?>
diff --git a/classes/auth_internal.php b/classes/auth_internal.php
deleted file mode 100644
index 8890d445..00000000
--- a/classes/auth_internal.php
+++ /dev/null
@@ -1,118 +0,0 @@
-link) > 87) {
-
- $result = db_query($this->link, "SELECT salt FROM ttrss_users WHERE
- login = '$login'");
-
- if (db_num_rows($result) != 1) {
- return false;
- }
-
- $salt = db_fetch_result($result, 0, "salt");
-
- if ($salt == "") {
-
- $query = "SELECT id
- FROM ttrss_users WHERE
- login = '$login' AND (pwd_hash = '$pwd_hash1' OR
- pwd_hash = '$pwd_hash2')";
-
- // verify and upgrade password to new salt base
-
- $result = db_query($this->link, $query);
-
- if (db_num_rows($result) == 1) {
- // upgrade password to MODE2
-
- $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $pwd_hash = encrypt_password($password, $salt, true);
-
- db_query($this->link, "UPDATE ttrss_users SET
- pwd_hash = '$pwd_hash', salt = '$salt' WHERE login = '$login'");
-
- $query = "SELECT id
- FROM ttrss_users WHERE
- login = '$login' AND pwd_hash = '$pwd_hash'";
-
- } else {
- return false;
- }
-
- } else {
-
- $pwd_hash = encrypt_password($password, $salt, true);
-
- $query = "SELECT id
- FROM ttrss_users WHERE
- login = '$login' AND pwd_hash = '$pwd_hash'";
-
- }
-
- } else {
- $query = "SELECT id
- FROM ttrss_users WHERE
- login = '$login' AND (pwd_hash = '$pwd_hash1' OR
- pwd_hash = '$pwd_hash2')";
- }
-
- $result = db_query($this->link, $query);
-
- if (db_num_rows($result) == 1) {
- return db_fetch_result($result, 0, "id");
- }
-
- return false;
- }
-
- function change_password($owner_uid, $old_password, $new_password) {
- $owner_uid = db_escape_string($owner_uid);
-
- $result = db_query($this->link, "SELECT salt,login FROM ttrss_users WHERE
- id = '$owner_uid'");
-
- $salt = db_fetch_result($result, 0, "salt");
- $login = db_fetch_result($result, 0, "login");
-
- if (!$salt) {
- $old_password_hash1 = encrypt_password($old_password);
- $old_password_hash2 = encrypt_password($old_password, $login);
-
- $query = "SELECT id FROM ttrss_users WHERE
- id = '$owner_uid' AND (pwd_hash = '$old_password_hash1' OR
- pwd_hash = '$old_password_hash2')";
-
- } else {
- $old_password_hash = encrypt_password($old_password, $salt, true);
-
- $query = "SELECT id FROM ttrss_users WHERE
- id = '$owner_uid' AND pwd_hash = '$old_password_hash'";
- }
-
- $result = db_query($this->link, $query);
-
- if (db_num_rows($result) == 1) {
-
- $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $new_password_hash = encrypt_password($new_password, $new_salt, true);
-
- db_query($this->link, "UPDATE ttrss_users SET
- pwd_hash = '$new_password_hash', salt = '$new_salt'
- WHERE id = '$owner_uid'");
-
- $_SESSION["pwd_hash"] = $new_password_hash;
-
- return __("Password has been changed.");
- } else {
- return "ERROR: ".__('Old password is incorrect.');
- }
- }
-}
-?>
diff --git a/classes/auth_remote.php b/classes/auth_remote.php
deleted file mode 100644
index 6892a352..00000000
--- a/classes/auth_remote.php
+++ /dev/null
@@ -1,61 +0,0 @@
-link, "SELECT login FROM ttrss_user_prefs, ttrss_users
- WHERE pref_name = 'SSL_CERT_SERIAL' AND value = '$cert_serial' AND
- owner_uid = ttrss_users.id");
-
- if (db_num_rows($result) != 0) {
- return db_escape_string(db_fetch_result($result, 0, "login"));
- }
- }
-
- return "";
- }
-
-
- function authenticate($login, $password) {
- $try_login = db_escape_string($_SERVER["REMOTE_USER"]);
-
- if (!$try_login) $try_login = $this->get_login_by_ssl_certificate();
-# if (!$try_login) $try_login = "test_qqq";
-
- if ($try_login) {
- $user_id = $this->auto_create_user($try_login);
-
- if ($user_id) {
- $_SESSION["fake_login"] = $try_login;
- $_SESSION["fake_password"] = "******";
- $_SESSION["hide_hello"] = true;
- $_SESSION["hide_logout"] = true;
-
- // LemonLDAP can send user informations via HTTP HEADER
- if (defined('AUTH_AUTO_CREATE') && AUTH_AUTO_CREATE){
- // update user name
- $fullname = $_SERVER['HTTP_USER_NAME'] ? $_SERVER['HTTP_USER_NAME'] : $_SERVER['AUTHENTICATE_CN'];
- if ($fullname){
- $fullname = db_escape_string($fullname);
- db_query($this->link, "UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " .
- $user_id);
- }
- // update user mail
- $email = $_SERVER['HTTP_USER_MAIL'] ? $_SERVER['HTTP_USER_MAIL'] : $_SERVER['AUTHENTICATE_MAIL'];
- if ($email){
- $email = db_escape_string($email);
- db_query($this->link, "UPDATE ttrss_users SET email = '$email' WHERE id = " .
- $user_id);
- }
- }
-
- return $user_id;
- }
- }
-
- return false;
- }
-}
-
-?>
diff --git a/classes/button.php b/classes/button.php
new file mode 100644
index 00000000..24d576da
--- /dev/null
+++ b/classes/button.php
@@ -0,0 +1,11 @@
+link = $link;
+ }
+
+}
+?>
diff --git a/classes/button/mail.php b/classes/button/mail.php
new file mode 100644
index 00000000..309493bb
--- /dev/null
+++ b/classes/button/mail.php
@@ -0,0 +1,192 @@
+";
+ }
+
+ function emailArticle() {
+
+ $param = db_escape_string($_REQUEST['param']);
+
+ $secretkey = sha1(uniqid(rand(), true));
+
+ $_SESSION['email_secretkey'] = $secretkey;
+
+ print " ";
+ print " ";
+ print " ";
+ print " ";
+ print " ";
+
+ $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE
+ id = " . $_SESSION["uid"]);
+
+ $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
+ $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
+
+ if (!$user_name) $user_name = $_SESSION['name'];
+
+ $_SESSION['email_replyto'] = $user_email;
+ $_SESSION['email_fromname'] = $user_name;
+
+ require_once "lib/MiniTemplator.class.php";
+
+ $tpl = new MiniTemplator;
+ $tpl_t = new MiniTemplator;
+
+ $tpl->readTemplateFromFile("templates/email_article_template.txt");
+
+ $tpl->setVariable('USER_NAME', $_SESSION["name"]);
+ $tpl->setVariable('USER_EMAIL', $user_email);
+ $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]);
+
+
+ $result = db_query($this->link, "SELECT link, content, title
+ FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
+ id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
+
+ if (db_num_rows($result) > 1) {
+ $subject = __("[Forwarded]") . " " . __("Multiple articles");
+ }
+
+ while ($line = db_fetch_assoc($result)) {
+
+ if (!$subject)
+ $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
+
+ $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
+ $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
+
+ $tpl->addBlock('article');
+ }
+
+ $tpl->addBlock('email');
+
+ $content = "";
+ $tpl->generateOutputToString($content);
+
+ print "";
+
+ print "";
+ print "".__('Send e-mail')." ";
+ print "".__('Cancel')." ";
+ print "
";
+
+ //return;
+ }
+
+ function sendEmail() {
+ $secretkey = $_REQUEST['secretkey'];
+
+ require_once 'lib/phpmailer/class.phpmailer.php';
+
+ $reply = array();
+
+ if ($_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 (SMTP_HOST) {
+ $mail->Host = SMTP_HOST;
+ $mail->Mailer = "smtp";
+ $mail->SMTPAuth = SMTP_LOGIN != '';
+ $mail->Username = SMTP_LOGIN;
+ $mail->Password = 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 "";
+
+ foreach ($_SESSION['stored_emails'] as $email) {
+ if (strpos($email, $search) !== false) {
+ print "$email ";
+ }
+ }
+
+ print " ";
+ }
+
+
+}
+?>
diff --git a/classes/button/note.php b/classes/button/note.php
new file mode 100644
index 00000000..d5b6e380
--- /dev/null
+++ b/classes/button/note.php
@@ -0,0 +1,55 @@
+link, "images/art-pub-note.png")."\"
+ style=\"cursor : pointer\" style=\"cursor : pointer\"
+ onclick=\"editArticleNote($article_id)\"
+ class='tagsPic' title='".__('Edit article note')."'>";
+ }
+
+ function edit() {
+ $param = db_escape_string($_REQUEST['param']);
+
+ $result = db_query($this->link, "SELECT note FROM ttrss_user_entries WHERE
+ ref_id = '$param' AND owner_uid = " . $_SESSION['uid']);
+
+ $note = db_fetch_result($result, 0, "note");
+
+ print " ";
+ print " ";
+ print " ";
+ print " ";
+ print " ";
+
+ print "";
+
+ print "";
+ print "".__('Save')." ";
+ print "".__('Cancel')." ";
+ print "
";
+
+ }
+
+ 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)));
+ }
+
+
+}
+?>
diff --git a/classes/button/share.php b/classes/button/share.php
new file mode 100644
index 00000000..74d7128d
--- /dev/null
+++ b/classes/button/share.php
@@ -0,0 +1,54 @@
+link, 'images/art-share.png')."\"
+ class='tagsPic' style=\"cursor : pointer\"
+ onclick=\"shareArticle(".$line['int_id'].")\"
+ title='".__('Share by URL')."'>";
+ }
+
+ function shareArticle() {
+ $param = db_escape_string($_REQUEST['param']);
+
+ $result = db_query($this->link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param'
+ AND owner_uid = " . $_SESSION['uid']);
+
+ if (db_num_rows($result) == 0) {
+ print "Article not found.";
+ } else {
+
+ $uuid = db_fetch_result($result, 0, "uuid");
+ $ref_id = db_fetch_result($result, 0, "ref_id");
+
+ if (!$uuid) {
+ $uuid = db_escape_string(sha1(uniqid(rand(), true)));
+ db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
+ AND owner_uid = " . $_SESSION['uid']);
+ }
+
+ print __("You can share this article by the following unique URL:");
+
+ $url_path = get_self_url_prefix();
+ $url_path .= "/public.php?op=share&key=$uuid";
+
+ print "";
+
+ /* if (!label_find_id($this->link, __('Shared'), $_SESSION["uid"]))
+ label_create($this->link, __('Shared'), $_SESSION["uid"]);
+
+ label_add_article($this->link, $ref_id, __('Shared'), $_SESSION['uid']); */
+ }
+
+ print "";
+
+ print "".
+ __('Close this window')." ";
+
+ print "
";
+ }
+
+
+}
+?>
diff --git a/classes/button/tweet.php b/classes/button/tweet.php
new file mode 100644
index 00000000..3157fb77
--- /dev/null
+++ b/classes/button/tweet.php
@@ -0,0 +1,31 @@
+link, 'images/art-tweet.png')."\"
+ class='tagsPic' style=\"cursor : pointer\"
+ onclick=\"tweetArticle($article_id)\"
+ title='".__('Share on Twitter')."'>";
+
+ return $rv;
+ }
+
+ 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));
+ }
+
+
+}
+?>
diff --git a/classes/feeds.php b/classes/feeds.php
index a3062565..7598b0af 100644
--- a/classes/feeds.php
+++ b/classes/feeds.php
@@ -1,5 +1,5 @@
hook('headlines_before', $reply);
+
if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
$button_plugins = array();
foreach (explode(",", ARTICLE_BUTTON_PLUGINS) as $p) {
- $pclass = trim("${p}_button");
+ $pclass = trim("button_${p}");
if (class_exists($pclass)) {
$plugin = new $pclass($link);
@@ -245,6 +249,12 @@ class Feeds extends Protected_Handler {
while ($line = db_fetch_assoc($result)) {
+ if (get_pref($this->link, 'COMBINED_DISPLAY_MODE')) {
+ $plugins->hook('cdm_article_before', $line);
+ } else {
+ $plugins->hook('headlines_row', $line);
+ }
+
$class = ($lnum % 2) ? "even" : "odd";
$id = $line["id"];
@@ -673,11 +683,15 @@ class Feeds extends Protected_Handler {
$reply['content'] .= "";
+ $plugins->hook('cdm_article_after', $reply['content']);
+
}
++$lnum;
}
+ $plugins->hook('headlines_after', $reply);
+
if ($_REQUEST["debug"]) $timing_info = print_checkpoint("PE", $timing_info);
} else {
diff --git a/classes/handler/protected.php b/classes/handler/protected.php
new file mode 100644
index 00000000..4ce86534
--- /dev/null
+++ b/classes/handler/protected.php
@@ -0,0 +1,8 @@
+
diff --git a/classes/handler/public.php b/classes/handler/public.php
new file mode 100644
index 00000000..983f0aaa
--- /dev/null
+++ b/classes/handler/public.php
@@ -0,0 +1,310 @@
+link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
+ $date_sort_field = "updated";
+ } else {
+ $date_sort_field = "date_entered";
+ }
+
+ $qfh_ret = queryFeedHeadlines($this->link, $feed,
+ $limit, $view_mode, $is_cat, $search, $search_mode,
+ $match_on, "$date_sort_field DESC", 0, $owner_uid);
+
+ $result = $qfh_ret[0];
+ $feed_title = htmlspecialchars($qfh_ret[1]);
+ $feed_site_url = $qfh_ret[2];
+ $last_error = $qfh_ret[3];
+
+ $feed_self_url = get_self_url_prefix() .
+ "/public.php?op=rss&id=-2&key=" .
+ get_feed_access_key($this->link, -2, false, $owner_uid);
+
+ if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
+
+ $tpl = new MiniTemplator;
+
+ $tpl->readTemplateFromFile("templates/generated_feed.txt");
+
+ $tpl->setVariable('FEED_TITLE', $feed_title, true);
+ $tpl->setVariable('VERSION', VERSION, true);
+ $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
+
+ if (PUBSUBHUBBUB_HUB && $feed == -2) {
+ $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
+ $tpl->addBlock('feed_hub');
+ }
+
+ $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
+
+ while ($line = db_fetch_assoc($result)) {
+ $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
+ $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
+ $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
+ $tpl->setVariable('ARTICLE_EXCERPT',
+ truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
+
+ $content = sanitize($this->link, $line["content_preview"], false, $owner_uid);
+
+ if ($line['note']) {
+ $content = "Article note: " . $line['note'] . "
" .
+ $content;
+ }
+
+ $tpl->setVariable('ARTICLE_CONTENT', $content, true);
+
+ $tpl->setVariable('ARTICLE_UPDATED_ATOM',
+ date('c', strtotime($line["updated"])), true);
+ $tpl->setVariable('ARTICLE_UPDATED_RFC822',
+ date(DATE_RFC822, strtotime($line["updated"])), true);
+
+ $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
+
+ $tags = get_article_tags($this->link, $line["id"], $owner_uid);
+
+ foreach ($tags as $tag) {
+ $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
+ $tpl->addBlock('category');
+ }
+
+ $enclosures = get_article_enclosures($this->link, $line["id"]);
+
+ foreach ($enclosures as $e) {
+ $type = htmlspecialchars($e['content_type']);
+ $url = htmlspecialchars($e['content_url']);
+ $length = $e['duration'];
+
+ $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
+ $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
+
+ $tpl->addBlock('enclosure');
+ }
+
+ $tpl->addBlock('entry');
+ }
+
+ $tmp = "";
+
+ $tpl->addBlock('feed');
+ $tpl->generateOutputToString($tmp);
+
+ print $tmp;
+ }
+
+ function getUnread() {
+ $login = db_escape_string($_REQUEST["login"]);
+ $fresh = $_REQUEST["fresh"] == "1";
+
+ $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE login = '$login'");
+
+ if (db_num_rows($result) == 1) {
+ $uid = db_fetch_result($result, 0, "id");
+
+ print getGlobalUnread($this->link, $uid);
+
+ if ($fresh) {
+ print ";";
+ print getFeedArticles($this->link, -3, false, true, $uid);
+ }
+
+ } else {
+ print "-1;User not found";
+ }
+
+ }
+
+ function getProfiles() {
+ $login = db_escape_string($_REQUEST["login"]);
+ $password = db_escape_string($_REQUEST["password"]);
+
+ if (authenticate_user($this->link, $login, $password)) {
+ $result = db_query($this->link, "SELECT * FROM ttrss_settings_profiles
+ WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
+
+ print "";
+
+ print "" . __("Default profile") . " ";
+
+ while ($line = db_fetch_assoc($result)) {
+ $id = $line["id"];
+ $title = $line["title"];
+
+ print "$title ";
+ }
+
+ print " ";
+
+ $_SESSION = array();
+ }
+ }
+
+ function pubsub() {
+ $mode = db_escape_string($_REQUEST['hub_mode']);
+ $feed_id = (int) db_escape_string($_REQUEST['id']);
+ $feed_url = db_escape_string($_REQUEST['hub_topic']);
+
+ if (!PUBSUBHUBBUB_ENABLED) {
+ header('HTTP/1.0 404 Not Found');
+ echo "404 Not found";
+ return;
+ }
+
+ // TODO: implement hub_verifytoken checking
+
+ $result = db_query($this->link, "SELECT feed_url FROM ttrss_feeds
+ WHERE id = '$feed_id'");
+
+ if (db_num_rows($result) != 0) {
+
+ $check_feed_url = db_fetch_result($result, 0, "feed_url");
+
+ if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
+ if ($mode == "subscribe") {
+
+ db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 2
+ WHERE id = '$feed_id'");
+
+ print $_REQUEST['hub_challenge'];
+ return;
+
+ } else if ($mode == "unsubscribe") {
+
+ db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0
+ WHERE id = '$feed_id'");
+
+ print $_REQUEST['hub_challenge'];
+ return;
+
+ } else if (!$mode) {
+
+ // Received update ping, schedule feed update.
+ //update_rss_feed($this->link, $feed_id, true, true);
+
+ db_query($this->link, "UPDATE ttrss_feeds SET
+ last_update_started = '1970-01-01',
+ last_updated = '1970-01-01' WHERE id = '$feed_id'");
+
+ }
+ } else {
+ header('HTTP/1.0 404 Not Found');
+ echo "404 Not found";
+ }
+ } else {
+ header('HTTP/1.0 404 Not Found');
+ echo "404 Not found";
+ }
+
+ }
+
+ function logout() {
+ logout_user();
+ header("Location: index.php");
+ }
+
+ function fbexport() {
+
+ $access_key = db_escape_string($_POST["key"]);
+
+ // TODO: rate limit checking using last_connected
+ $result = db_query($this->link, "SELECT id FROM ttrss_linked_instances
+ WHERE access_key = '$access_key'");
+
+ if (db_num_rows($result) == 1) {
+
+ $instance_id = db_fetch_result($result, 0, "id");
+
+ $result = db_query($this->link, "SELECT feed_url, site_url, title, subscribers
+ FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
+
+ $feeds = array();
+
+ while ($line = db_fetch_assoc($result)) {
+ array_push($feeds, $line);
+ }
+
+ db_query($this->link, "UPDATE ttrss_linked_instances SET
+ last_status_in = 1 WHERE id = '$instance_id'");
+
+ print json_encode(array("feeds" => $feeds));
+ } else {
+ print json_encode(array("error" => array("code" => 6)));
+ }
+ }
+
+ function share() {
+ $uuid = db_escape_string($_REQUEST["key"]);
+
+ $result = db_query($this->link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
+ uuid = '$uuid'");
+
+ if (db_num_rows($result) != 0) {
+ header("Content-Type: text/html");
+
+ $id = db_fetch_result($result, 0, "ref_id");
+ $owner_uid = db_fetch_result($result, 0, "owner_uid");
+
+ $article = format_article($this->link, $id, false, true, $owner_uid);
+
+ print_r($article['content']);
+
+ } else {
+ print "Article not found.";
+ }
+
+ }
+
+ function rss() {
+ header("Content-Type: text/xml; charset=utf-8");
+
+ $feed = db_escape_string($_REQUEST["id"]);
+ $key = db_escape_string($_REQUEST["key"]);
+ $is_cat = $_REQUEST["is_cat"] != false;
+ $limit = (int)db_escape_string($_REQUEST["limit"]);
+
+ $search = db_escape_string($_REQUEST["q"]);
+ $match_on = db_escape_string($_REQUEST["m"]);
+ $search_mode = db_escape_string($_REQUEST["smode"]);
+ $view_mode = db_escape_string($_REQUEST["view-mode"]);
+
+ if (SINGLE_USER_MODE) {
+ authenticate_user($this->link, "admin", null);
+ }
+
+ $owner_id = false;
+
+ if ($key) {
+ $result = db_query($this->link, "SELECT owner_uid FROM
+ ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
+
+ if (db_num_rows($result) == 1)
+ $owner_id = db_fetch_result($result, 0, "owner_uid");
+ }
+
+ if ($owner_id) {
+ $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
+ $search, $search_mode, $match_on, $view_mode);
+ } else {
+ header('HTTP/1.1 403 Forbidden');
+ }
+ }
+
+ function globalUpdateFeeds() {
+ include "rssfuncs.php";
+ // Update all feeds needing a update.
+ update_daemon_common($this->link, 0, true, false);
+ }
+}
+?>
diff --git a/classes/mail_button.php b/classes/mail_button.php
deleted file mode 100644
index b299ccef..00000000
--- a/classes/mail_button.php
+++ /dev/null
@@ -1,192 +0,0 @@
-";
- }
-
- function emailArticle() {
-
- $param = db_escape_string($_REQUEST['param']);
-
- $secretkey = sha1(uniqid(rand(), true));
-
- $_SESSION['email_secretkey'] = $secretkey;
-
- print " ";
- print " ";
- print " ";
- print " ";
- print " ";
-
- $result = db_query($this->link, "SELECT email, full_name FROM ttrss_users WHERE
- id = " . $_SESSION["uid"]);
-
- $user_email = htmlspecialchars(db_fetch_result($result, 0, "email"));
- $user_name = htmlspecialchars(db_fetch_result($result, 0, "full_name"));
-
- if (!$user_name) $user_name = $_SESSION['name'];
-
- $_SESSION['email_replyto'] = $user_email;
- $_SESSION['email_fromname'] = $user_name;
-
- require_once "lib/MiniTemplator.class.php";
-
- $tpl = new MiniTemplator;
- $tpl_t = new MiniTemplator;
-
- $tpl->readTemplateFromFile("templates/email_article_template.txt");
-
- $tpl->setVariable('USER_NAME', $_SESSION["name"]);
- $tpl->setVariable('USER_EMAIL', $user_email);
- $tpl->setVariable('TTRSS_HOST', $_SERVER["HTTP_HOST"]);
-
-
- $result = db_query($this->link, "SELECT link, content, title
- FROM ttrss_user_entries, ttrss_entries WHERE id = ref_id AND
- id IN ($param) AND owner_uid = " . $_SESSION["uid"]);
-
- if (db_num_rows($result) > 1) {
- $subject = __("[Forwarded]") . " " . __("Multiple articles");
- }
-
- while ($line = db_fetch_assoc($result)) {
-
- if (!$subject)
- $subject = __("[Forwarded]") . " " . htmlspecialchars($line["title"]);
-
- $tpl->setVariable('ARTICLE_TITLE', strip_tags($line["title"]));
- $tpl->setVariable('ARTICLE_URL', strip_tags($line["link"]));
-
- $tpl->addBlock('article');
- }
-
- $tpl->addBlock('email');
-
- $content = "";
- $tpl->generateOutputToString($content);
-
- print "";
-
- print "";
- print "".__('Send e-mail')." ";
- print "".__('Cancel')." ";
- print "
";
-
- //return;
- }
-
- function sendEmail() {
- $secretkey = $_REQUEST['secretkey'];
-
- require_once 'lib/phpmailer/class.phpmailer.php';
-
- $reply = array();
-
- if ($_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 (SMTP_HOST) {
- $mail->Host = SMTP_HOST;
- $mail->Mailer = "smtp";
- $mail->SMTPAuth = SMTP_LOGIN != '';
- $mail->Username = SMTP_LOGIN;
- $mail->Password = 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 "";
-
- foreach ($_SESSION['stored_emails'] as $email) {
- if (strpos($email, $search) !== false) {
- print "$email ";
- }
- }
-
- print " ";
- }
-
-
-}
-?>
diff --git a/classes/note_button.php b/classes/note_button.php
deleted file mode 100644
index 794f1773..00000000
--- a/classes/note_button.php
+++ /dev/null
@@ -1,55 +0,0 @@
-link, "images/art-pub-note.png")."\"
- style=\"cursor : pointer\" style=\"cursor : pointer\"
- onclick=\"editArticleNote($article_id)\"
- class='tagsPic' title='".__('Edit article note')."'>";
- }
-
- function edit() {
- $param = db_escape_string($_REQUEST['param']);
-
- $result = db_query($this->link, "SELECT note FROM ttrss_user_entries WHERE
- ref_id = '$param' AND owner_uid = " . $_SESSION['uid']);
-
- $note = db_fetch_result($result, 0, "note");
-
- print " ";
- print " ";
- print " ";
- print " ";
- print " ";
-
- print "";
-
- print "";
- print "".__('Save')." ";
- print "".__('Cancel')." ";
- print "
";
-
- }
-
- 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)));
- }
-
-
-}
-?>
diff --git a/classes/opml.php b/classes/opml.php
index af597caf..8683fb73 100644
--- a/classes/opml.php
+++ b/classes/opml.php
@@ -1,5 +1,5 @@
link = $link;
+ $this->handler = $handler;
+ $this->initialize();
+ }
+
+ function initialize() {
+
+
+ }
+
+ function add_listener($hook) {
+ $this->handler->add_listener($hook, $this);
+ }
+}
+?>
diff --git a/classes/plugin/example.php b/classes/plugin/example.php
new file mode 100644
index 00000000..e10781aa
--- /dev/null
+++ b/classes/plugin/example.php
@@ -0,0 +1,11 @@
+
+ class Plugin_Example extends Plugin {
+ function initialize() {
+ $this->add_listener('article_before');
+ }
+
+ function article_before(&$line) {
+ $line["title"] = "EXAMPLE/REPLACED:" . $line["title"];
+ }
+ }
+?>
diff --git a/classes/plugin_button.php b/classes/plugin_button.php
deleted file mode 100644
index 6cb8ec1b..00000000
--- a/classes/plugin_button.php
+++ /dev/null
@@ -1,11 +0,0 @@
-link = $link;
- }
-
-}
-?>
diff --git a/classes/plugins.php b/classes/plugins.php
new file mode 100644
index 00000000..6f3720ca
--- /dev/null
+++ b/classes/plugins.php
@@ -0,0 +1,44 @@
+link = $link;
+ $this->listeners = array();
+ $this->load_plugins();
+ }
+
+ function load_plugins() {
+ if (defined('_ENABLE_PLUGINS')) {
+ $plugins = explode(",", _ENABLE_PLUGINS);
+
+ foreach ($plugins as $p) {
+ $plugin_class = "plugin_$p";
+ if (class_exists($plugin_class)) {
+ $plugin = new $plugin_class($this->link, $this);
+ }
+ }
+ }
+ }
+
+ function add_listener($hook_name, $plugin) {
+ if (!is_array($this->listeners[$hook_name]))
+ $this->listeners[$hook_name] = array();
+
+ array_push($this->listeners[$hook_name], $plugin);
+ }
+
+ function hook($hook_name, &$params) {
+ if (is_array($this->listeners[$hook_name])) {
+ foreach ($this->listeners[$hook_name] as $p) {
+ if (method_exists($p, $hook_name)) {
+ $p->$hook_name($params);
+ }
+ }
+ }
+ }
+
+}
+?>
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
new file mode 100644
index 00000000..5899115b
--- /dev/null
+++ b/classes/pref/feeds.php
@@ -0,0 +1,1681 @@
+";
+ }
+
+ 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;
+ }
+
+ private function get_category_items($cat_id) {
+ $show_empty_cats = $_REQUEST['mode'] != 2 &&
+ get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+
+ $items = array();
+
+ $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
+ WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title");
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $cat = array();
+ $cat['id'] = 'CAT:' . $line['id'];
+ $cat['bare_id'] = (int)$line['id'];
+ $cat['name'] = $line['title'];
+ $cat['items'] = array();
+ $cat['checkbox'] = false;
+ $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
+ $cat['type'] = 'category';
+ $cat['unread'] = 0;
+ $cat['child_unread'] = 0;
+
+ $cat['items'] = $this->get_category_items($line['id']);
+
+ $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+
+ if (count($cat['items']) > 0 || $show_empty_cats)
+ array_push($items, $cat);
+
+ }
+
+ $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 = '$cat_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'] = (int)$feed_line['id'];
+ $feed['name'] = $feed_line['title'];
+ $feed['checkbox'] = false;
+ $feed['unread'] = 0;
+ $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($items, $feed);
+ }
+
+ return $items;
+ }
+
+ 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';
+
+ $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
+
+ if ($_REQUEST['mode'] == 2) {
+
+ if ($enable_cats) {
+ $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
+ $cat = $this->feedlist_init_cat(-1, $cat_hidden);
+ } else {
+ $cat['items'] = array();
+ }
+
+ foreach (array(-4, -3, -1, -2, 0) as $i) {
+ array_push($cat['items'], $this->feedlist_init_feed($i));
+ }
+
+ if ($enable_cats) {
+ array_push($root['items'], $cat);
+ } else {
+ $root['items'] = array_merge($root['items'], $cat['items']);
+ }
+
+ $result = db_query($this->link, "SELECT * FROM
+ ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption");
+
+ if (db_num_rows($result) > 0) {
+
+ if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+ $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
+ $cat = $this->feedlist_init_cat(-2, $cat_hidden);
+ } else {
+ $cat['items'] = array();
+ }
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $label_id = -$line['id'] - 11;
+ $count = getFeedUnread($this->link, $label_id);
+
+ $feed = $this->feedlist_init_feed($label_id, false, $count);
+
+ $feed['fg_color'] = $line['fg_color'];
+ $feed['bg_color'] = $line['bg_color'];
+
+ array_push($cat['items'], $feed);
+ }
+
+ if ($enable_cats) {
+ array_push($root['items'], $cat);
+ } else {
+ $root['items'] = array_merge($root['items'], $cat['items']);
+ }
+ }
+ }
+
+ if ($enable_cats) {
+ $show_empty_cats = $_REQUEST['mode'] != 2 &&
+ get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
+
+ $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
+ WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
+
+ while ($line = db_fetch_assoc($result)) {
+ $cat = array();
+ $cat['id'] = 'CAT:' . $line['id'];
+ $cat['bare_id'] = (int)$line['id'];
+ $cat['name'] = $line['title'];
+ $cat['items'] = array();
+ $cat['checkbox'] = false;
+ $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
+ $cat['type'] = 'category';
+ $cat['unread'] = 0;
+ $cat['child_unread'] = 0;
+
+ $cat['items'] = $this->get_category_items($line['id']);
+
+ $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+
+ if (count($cat['items']) > 0 || $show_empty_cats)
+ 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['hidden'] = get_pref($this->link, "_COLLAPSED_UNCAT");
+ $cat['type'] = 'category';
+ $cat['checkbox'] = false;
+ $cat['unread'] = 0;
+ $cat['child_unread'] = 0;
+
+ $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'] = (int)$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);
+ $feed['unread'] = 0;
+ $feed['type'] = 'feed';
+
+ array_push($cat['items'], $feed);
+ }
+
+ $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
+
+ if (count($cat['items']) > 0 || $show_empty_cats)
+ 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'] = (int)$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);
+ $feed['unread'] = 0;
+ $feed['type'] = 'feed';
+
+ array_push($root['items'], $feed);
+ }
+
+ $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
+ }
+
+ $fl = array();
+ $fl['identifier'] = 'id';
+ $fl['label'] = 'name';
+
+ if ($_REQUEST['mode'] != 2) {
+ $fl['items'] = array($root);
+ } else {
+ $fl['items'] =& $root['items'];
+ }
+
+ 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 togglehiddenfeedcats() {
+ set_pref($this->link, '_PREFS_SHOW_EMPTY_CATS',
+ (get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
+ }
+
+ private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
+ $debug = isset($_REQUEST["debug"]);
+
+ $prefix = "";
+ for ($i = 0; $i < $nest_level; $i++)
+ $prefix .= " ";
+
+ if ($debug) _debug("$prefix C: $item_id P: $parent_id");
+
+ $bare_item_id = substr($item_id, strpos($item_id, ':')+1);
+
+ if ($item_id != 'root') {
+ if ($parent_id && $parent_id != 'root') {
+ $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1);
+ $parent_qpart = db_escape_string($parent_bare_id);
+ } else {
+ $parent_qpart = 'NULL';
+ }
+
+ db_query($this->link, "UPDATE ttrss_feed_categories
+ SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND
+ owner_uid = " . $_SESSION["uid"]);
+ }
+
+ $order_id = 0;
+
+ $cat = $data_map[$item_id];
+
+ if ($cat && is_array($cat)) {
+ foreach ($cat as $item) {
+ $id = $item['_reference'];
+ $bare_id = substr($id, strpos($id, ':')+1);
+
+ if ($debug) _debug("$prefix [$order_id] $id/$bare_id");
+
+ if ($item['_reference']) {
+
+ if (strpos($id, "FEED") === 0) {
+
+ $cat_id = ($item_id != "root") ?
+ db_escape_string($bare_item_id) : "NULL";
+
+ db_query($this->link, "UPDATE ttrss_feeds
+ SET order_id = $order_id, cat_id = '$cat_id'
+ WHERE id = '$bare_id' AND
+ owner_uid = " . $_SESSION["uid"]);
+
+ } else if (strpos($id, "CAT:") === 0) {
+ $this->process_category_order($data_map, $item['_reference'], $item_id,
+ $nest_level+1);
+
+ if ($item_id != 'root') {
+ $parent_qpart = db_escape_string($bare_id);
+ } else {
+ $parent_qpart = 'NULL';
+ }
+
+ db_query($this->link, "UPDATE ttrss_feed_categories
+ SET order_id = '$order_id' WHERE id = '$bare_id' AND
+ owner_uid = " . $_SESSION["uid"]);
+ }
+ }
+
+ ++$order_id;
+ }
+ }
+ }
+
+ function savefeedorder() {
+ $data = json_decode($_POST['payload'], true);
+
+ #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
+ #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
+
+ if (!is_array($data['items']))
+ $data['items'] = json_decode($data['items'], true);
+
+# print_r($data['items']);
+
+ if (is_array($data) && is_array($data['items'])) {
+ $cat_order_id = 0;
+
+ $data_map = array();
+ $root_item = false;
+
+ 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'];
+ }
+ }
+ if ($item['id'] == 'root') {
+ $root_item = $item['id'];
+ }
+ }
+
+ $this->process_category_order($data_map, $root_item);
+
+ /* 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 "";
+ 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 " ";
+ print " ";
+ print " ";
+
+ print "".__("Feed")."
";
+ print "";
+
+ /* Title */
+
+ print " ";
+
+ /* Feed URL */
+
+ $feed_url = db_fetch_result($result, 0, "feed_url");
+ $feed_url = htmlspecialchars(db_fetch_result($result,
+ 0, "feed_url"));
+
+ print "
";
+
+ print __('URL:') . " ";
+ print " ";
+
+ $last_error = db_fetch_result($result, 0, "last_error");
+
+ if ($last_error) {
+ print " (error) ";
+
+ }
+
+ /* Category */
+
+ if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+
+ $cat_id = db_fetch_result($result, 0, "cat_id");
+
+ print " ";
+
+ print __('Place in category:') . " ";
+
+ print_feed_cat_select($this->link, "cat_id", $cat_id,
+ 'dojoType="dijit.form.Select"');
+ }
+
+ print "
";
+
+ print "".__("Update")."
";
+ print "";
+
+ /* 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 "
";
+ print __('Article purging:') . " ";
+
+ print_select_hash("purge_interval", $purge_interval, $purge_intervals,
+ 'dojoType="dijit.form.Select" ' .
+ ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
+
+ print "";
+ print "".__("Authentication")."
";
+ print "";
+ print "".__("Options")."
";
+ print "";
+
+ $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
+
+ if ($private) {
+ $checked = "checked=\"1\"";
+ } else {
+ $checked = "";
+ }
+
+ print " ".__('Hide from Popular feeds')." ";
+
+ $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
+
+ if ($rtl_content) {
+ $checked = "checked=\"1\"";
+ } else {
+ $checked = "";
+ }
+
+ print "
".__('Right-to-left content')." ";
+
+ $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 " ".__('Include in e-mail digest')." ";
+
+
+ $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
+
+ if ($always_display_enclosures) {
+ $checked = "checked";
+ } else {
+ $checked = "";
+ }
+
+ print " ".__('Always display image attachments')." ";
+
+
+ $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
+
+ if ($cache_images) {
+ $checked = "checked=\"1\"";
+ } else {
+ $checked = "";
+ }
+
+ print " ".
+ __('Cache images locally')." ";
+
+ $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 " ".__('Mark updated articles as unread')." ";
+
+ $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 " ".__('Mark posts as updated on content change')." ";
+
+ print "";
+
+ /* Icon */
+
+ print "".__("Icon")."
";
+ print "";
+
+ print "";
+
+ print "";
+
+ print "
";
+
+ $title = htmlspecialchars($title, ENT_QUOTES);
+
+ print "";
+
+ return;
+ }
+
+ function editfeeds() {
+ global $purge_intervals;
+ global $update_intervals;
+ global $update_methods;
+
+ $feed_ids = db_escape_string($_REQUEST["ids"]);
+
+ print "" . __("Enable the options you wish to apply using checkboxes on the right:") . "
";
+
+ print " ";
+ print " ";
+ print " ";
+
+ print "".__("Feed")."
";
+ print "";
+
+ /* Title */
+
+ print " ";
+
+ $this->batch_edit_cbox("title");
+
+ /* Feed URL */
+
+ print " ";
+
+ print __('URL:') . " ";
+ print " ";
+
+ $this->batch_edit_cbox("feed_url");
+
+ /* Category */
+
+ if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+
+ print " ";
+
+ 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 "
";
+
+ print "".__("Update")."
";
+ print "";
+
+ /* 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 " ";
+
+ 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 "
";
+ print "".__("Authentication")."
";
+ print "";
+
+ print " ";
+
+ $this->batch_edit_cbox("auth_login");
+
+ print " ";
+
+ $this->batch_edit_cbox("auth_pass");
+
+ print "
";
+ print "".__("Options")."
";
+ print "";
+
+ print " ".__('Hide from Popular feeds')." ";
+
+ print " "; $this->batch_edit_cbox("private", "private_l");
+
+ print " ".__('Right-to-left content')." ";
+
+ print " "; $this->batch_edit_cbox("rtl_content", "rtl_content_l");
+
+ print " ".__('Include in e-mail digest')." ";
+
+ print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
+
+ print " ".__('Always display image attachments')." ";
+
+ print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
+
+ print " ".
+ __('Cache images locally')." ";
+
+ print " "; $this->batch_edit_cbox("cache_images", "cache_images_l");
+
+ print " ".__('Mark updated articles as unread')." ";
+
+ print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
+
+ print " ".__('Mark posts as updated on content change')." ";
+
+ print " "; $this->batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l");
+
+ print "
";
+
+ print "
+ ".
+ __('Save')."
+ ".
+ __('Cancel')."
+
";
+
+ return;
+ }
+
+ function batchEditSave() {
+ return $this->editsaveops(true);
+ }
+
+ function editSave() {
+ return $this->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 = "";
+ }
+
+ $cache_images_qpart = "cache_images = $cache_images,";
+
+ if (!$batch) {
+
+ $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 {
+ $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 " ";
+ }
+ }
+
+ 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; charset=utf-8');
+ print "
+
+ Tiny Tiny RSS
+
+
+
+
+
+ Subscribe to feed... ";
+ }
+
+ $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
+
+ switch ($rc) {
+ case 1:
+ print_notice(T_sprintf("Subscribed to %s .", $feed_url));
+ break;
+ case 2:
+ print_error(T_sprintf("Could not subscribe to %s .", $feed_url));
+ break;
+ case 3:
+ print_error(T_sprintf("No feeds found in %s .", $feed_url));
+ break;
+ case 0:
+ print_warning(T_sprintf("Already subscribed to %s .", $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 %s . Can't download the Feed URL.", $feed_url));
+ break;
+ }
+
+ if ($p_from != 'tt-rss') {
+
+ if ($feed_urls) {
+
+ print "";
+ }
+
+ $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 "";
+
+ if ($feed_id) {
+ print "
";
+ }
+
+ print "";
+
+ print "";
+ 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 removeCat() {
+ $ids = split(",", db_escape_string($_REQUEST["ids"]));
+ foreach ($ids as $id) {
+ remove_feed_category($this->link, $id, $_SESSION["uid"]);
+ }
+ }
+
+ function addCat() {
+ $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
+
+ add_feed_category($this->link, $feed_cat);
+ }
+
+ function index() {
+
+ print "";
+ print "
";
+
+ $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 = "
" .
+ __("Feeds with errors") . " ";
+ }
+
+ 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 = "
" .
+ __("Inactive feeds") . " ";
+ }
+
+ $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 '
';
+
+ print "
"; #toolbar
+
+ print "
+
+ ".
+ __('Search')."
+
";
+
+ print "
".
+ "
" . __('Select')." ";
+ print "
";
+ print "
".__('All')."
";
+ print "
".__('None')."
";
+ print "
";
+
+ print "
".
+ "
" . __('Feeds')." ";
+ print "
";
+ print "
".__('Subscribe to feed')."
";
+ print "
".__('Edit selected feeds')."
";
+ print "
".__('Reset sort order')."
";
+ print "
".__('Batch subscribe')."
";
+ print "
";
+
+ if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
+ print "
".
+ "
" . __('Categories')." ";
+ print "
";
+ print "
".__('Add category')."
";
+ print "
".__('(Un)hide empty categories')."
";
+ print "
".__('Reset sort order')."
";
+ print "
";
+
+ }
+
+ print $error_button;
+ print $inactive_button;
+
+ print "
"
+ .__('Unsubscribe')." ";
+
+ if (defined('_ENABLE_FEED_DEBUGGING')) {
+
+ print "
+ ".__('More actions...')." ";
+
+ if (FORCE_ARTICLE_PURGE == 0) {
+ print
+ "".__('Manual purge')." ";
+ }
+
+ print "
+ ".__('Clear feed data')."
+ ".__('Rescore articles')." ";
+
+ print " ";
+
+ }
+
+ print "
"; # toolbar
+
+ //print '
';
+ print '
';
+
+ print "
+
".
+ __("Loading, please wait...")."
";
+
+ print "
+
+
+
+
+
+
+
";
+
+# print "
+# ".__('Hint: you can drag feeds and categories around.')."
+#
";
+
+ print '
';
+ print '
';
+
+ print "
"; # feeds pane
+
+ print "";
+
+ print "
" . __("OPML") . " ";
+
+ print "
" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
+
+ print __("Only main settings profile can be migrated using OPML.") . "
";
+
+ print "
";
+
+ print "
";
+
+ print "
";
+
+ print "
".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
+
+ print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "
";
+
+ print "
".
+ __('Display published OPML URL')." ";
+
+
+ print "
" . __("Article archive") . " ";
+
+ print "
" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "
";
+
+ print "
".
+ __('Export my data')." ";
+
+ print "
";
+
+ print "
";
+
+ print "
"; # pane
+
+ if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
+
+ print "";
+
+ print "
" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "
";
+
+ print "
";
+
+ print "" .
+ __('Click here to register this site as a feed reader.') .
+ " ";
+
+ print "
";
+
+ print "
"; # pane
+ }
+
+ print "";
+
+ print "
" . __("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.") . "
";
+
+ $bm_subscribe_url = str_replace('%s', '', add_feed_url());
+
+ $confirm_str = str_replace("'", "\'", __('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 "
" . __('Subscribe in Tiny Tiny RSS'). " ";
+
+ print "
"; #pane
+
+ print "";
+
+ print "
" . __("Published articles and generated feeds") . " ";
+
+ print "
".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."
";
+
+ $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
+ "/public.php?op=rss&id=-2&view-mode=all_articles");;
+
+ print "
".
+ __('Display URL')." ";
+
+ print "
".
+ __('Clear all generated URLs')." ";
+
+ print "
" . __("Articles shared by URL") . " ";
+
+ print "
" . __("You can disable all articles shared by unique URLs here.") . "
";
+
+ print "
".
+ __('Unshare all articles')." ";
+
+ print "
"; #pane
+
+ if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
+
+ print ""; # pane
+
+ }
+
+ print ""; #container
+
+ }
+
+ private function feedlist_init_cat($cat_id, $hidden = false) {
+ $obj = array();
+ $cat_id = (int) $cat_id;
+
+ if ($cat_id > 0) {
+ $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
+ } else if ($cat_id == 0 || $cat_id == -2) {
+ $cat_unread = getCategoryUnread($this->link, $cat_id);
+ }
+
+ $obj['id'] = 'CAT:' . $cat_id;
+ $obj['items'] = array();
+ $obj['name'] = getCategoryTitle($this->link, $cat_id);
+ $obj['type'] = 'category';
+ $obj['unread'] = (int) $cat_unread;
+ $obj['hidden'] = $hidden;
+ $obj['bare_id'] = $cat_id;
+
+ return $obj;
+ }
+
+ private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
+ $obj = array();
+ $feed_id = (int) $feed_id;
+
+ if (!$title)
+ $title = getFeedTitle($this->link, $feed_id, false);
+
+ if ($unread === false)
+ $unread = getFeedUnread($this->link, $feed_id, false);
+
+ $obj['id'] = 'FEED:' . $feed_id;
+ $obj['name'] = $title;
+ $obj['unread'] = (int) $unread;
+ $obj['type'] = 'feed';
+ $obj['error'] = $error;
+ $obj['updated'] = $updated;
+ $obj['icon'] = getFeedIcon($feed_id);
+ $obj['bare_id'] = $feed_id;
+
+ return $obj;
+ }
+
+}
+?>
diff --git a/classes/pref/filters.php b/classes/pref/filters.php
new file mode 100644
index 00000000..9cd59e96
--- /dev/null
+++ b/classes/pref/filters.php
@@ -0,0 +1,657 @@
+link, "SELECT name FROM ttrss_filter_types WHERE
+ id = " . $filter_type);
+ $type_name = db_fetch_result($result, 0, "name");
+
+ $result = db_query($this->link, "SELECT name FROM ttrss_filter_actions WHERE
+ id = " . $action_id);
+ $action_name = db_fetch_result($result, 0, "name");
+
+ $filter["reg_exp"] = $reg_exp;
+ $filter["action"] = $action_name;
+ $filter["type"] = $type_name;
+ $filter["action_param"] = $action_param;
+ $filter["filter_param"] = $filter_param;
+ $filter["inverse"] = $inverse;
+
+ $filters[$type_name] = array($filter);
+
+ if ($feed_id)
+ $feed = $feed_id;
+ else
+ $feed = -4;
+
+ $regexp_valid = preg_match('/' . $filter['reg_exp'] . '/',
+ $filter['reg_exp']) !== FALSE;
+
+ print __("Articles matching this filter:");
+
+ print "";
+ print "
";
+
+ if ($regexp_valid) {
+
+ $feed_title = getFeedTitle($this->link, $feed);
+
+ $qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed,
+ 30, "", $cat_filter, false, false,
+ false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
+
+ $result = $qfh_ret[0];
+
+ $articles = array();
+ $found = 0;
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $entry_timestamp = strtotime($line["updated"]);
+ $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]);
+
+ $content_preview = truncate_string(
+ strip_tags($line["content_preview"]), 100, '...');
+
+ if ($line["feed_title"])
+ $feed_title = $line["feed_title"];
+
+ print "";
+
+ print " ";
+ print "";
+
+ print $line["title"];
+ print " (";
+ print "" . $feed_title . " ";
+ print "): ";
+ print "" . $content_preview . " ";
+ print " " . mb_substr($line["date_entered"], 0, 16);
+
+ print " ";
+
+ $found++;
+ }
+
+ if ($found == 0) {
+ print "" .
+ __("No articles matching this filter has been found.") . " ";
+ }
+ } else {
+ print "" .
+ __("Invalid regular expression.") . " ";
+
+ }
+
+ print "
";
+ print "
";
+
+ }
+
+ function getfiltertree() {
+ $root = array();
+ $root['id'] = 'root';
+ $root['name'] = __('Filters');
+ $root['items'] = array();
+
+ $search = $_SESSION["prefs_filter_search"];
+
+ if ($search) $search_qpart = " (LOWER(reg_exp) LIKE LOWER('%$search%')
+ OR LOWER(ttrss_feeds.title) LIKE LOWER('%$search%')
+ OR LOWER(COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."'))
+ LIKE LOWER('%$search%') AND cat_filter = true) AND ";
+
+ $result = db_query($this->link, "SELECT
+ ttrss_filters.id AS id,reg_exp,
+ ttrss_filter_types.name AS filter_type_name,
+ ttrss_filter_types.description AS filter_type_descr,
+ enabled,
+ inverse,
+ cat_filter,
+ feed_id,
+ ttrss_filters.cat_id,
+ action_id,
+ filter_param,
+ filter_type,
+ ttrss_filter_actions.description AS action_description,
+ ttrss_feeds.title AS feed_title,
+ COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS cat_title,
+ ttrss_filter_actions.name AS action_name,
+ ttrss_filters.action_param AS action_param
+ FROM
+ ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
+ ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) LEFT JOIN
+ ttrss_feed_categories ON (ttrss_filters.cat_id = ttrss_feed_categories.id)
+ WHERE
+ filter_type = ttrss_filter_types.id AND
+ ttrss_filter_actions.id = action_id AND
+ $search_qpart
+ ttrss_filters.owner_uid = ".$_SESSION["uid"]."
+ ORDER by action_description, reg_exp");
+
+ $cat = false;
+ $cur_action_description = "";
+
+ if (db_num_rows($result) > 0) {
+
+ while ($line = db_fetch_assoc($result)) {
+ if ($cur_action_description != $line['action_description']) {
+
+ if ($cat)
+ array_push($root['items'], $cat);
+
+ $cat = array();
+ $cat['id'] = 'ACTION:' . $line['action_id'];
+ $cat['name'] = $line['action_description'];
+ $cat['items'] = array();
+
+ $cur_action_description = $line['action_description'];
+ }
+
+ if (array_search($line["action_name"],
+ array("score", "tag", "label")) === false) {
+
+ $line["action_param"] = '';
+ } else {
+ if ($line['action_name'] == 'label') {
+
+ $tmp_result = db_query($this->link, "SELECT fg_color, bg_color
+ FROM ttrss_labels2 WHERE caption = '".
+ db_escape_string($line["action_param"])."' AND
+ owner_uid = " . $_SESSION["uid"]);
+
+ if (db_num_rows($tmp_result) != 0) {
+ $fg_color = db_fetch_result($tmp_result, 0, "fg_color");
+ $bg_color = db_fetch_result($tmp_result, 0, "bg_color");
+
+ $tmp = "α " . $line['action_param'];
+
+ $line['action_param'] = $tmp;
+ }
+ }
+ }
+
+ $filter = array();
+ $filter['id'] = 'FILTER:' . $line['id'];
+ $filter['bare_id'] = $line['id'];
+ $filter['name'] = $line['reg_exp'];
+ $filter['type'] = $line['filter_type'];
+ $filter['enabled'] = sql_bool_to_bool($line['enabled']);
+ $filter['param'] = $line['action_param'];
+ $filter['inverse'] = sql_bool_to_bool($line['inverse']);
+ $filter['checkbox'] = false;
+
+ if (sql_bool_to_bool($line['cat_filter']))
+ if ($line['cat_id'] != 0) {
+ $filter['feed'] = $line['cat_title'];
+ } else {
+ $filter['feed'] = __('Uncategorized');
+ }
+ else if ($line['feed_id'])
+ $filter['feed'] = $line['feed_title'];
+
+ array_push($cat['items'], $filter);
+ }
+
+ array_push($root['items'], $cat);
+ }
+
+ $fl = array();
+ $fl['identifier'] = 'id';
+ $fl['label'] = 'name';
+ $fl['items'] = array($root);
+
+ print json_encode($fl);
+ return;
+ }
+
+ function edit() {
+
+ $filter_id = db_escape_string($_REQUEST["id"]);
+
+ $result = db_query($this->link,
+ "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
+
+ $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
+ $filter_type = db_fetch_result($result, 0, "filter_type");
+ $feed_id = db_fetch_result($result, 0, "feed_id");
+ $cat_id = db_fetch_result($result, 0, "cat_id");
+ $action_id = db_fetch_result($result, 0, "action_id");
+ $action_param = db_fetch_result($result, 0, "action_param");
+ $filter_param = db_fetch_result($result, 0, "filter_param");
+
+ $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
+ $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
+ $cat_filter = sql_bool_to_bool(db_fetch_result($result, 0, "cat_filter"));
+
+ print "";
+
+ print "";
+ print "".
+ __('Save')." ";
+ print "".
+ __('Cancel')." ";
+ print "
";
+
+ return;
+ }
+
+ function getlabeltree() {
+ $root = array();
+ $root['id'] = 'root';
+ $root['name'] = __('Labels');
+ $root['items'] = array();
+
+ $result = db_query($this->link, "SELECT *
+ FROM ttrss_labels2
+ WHERE owner_uid = ".$_SESSION["uid"]."
+ ORDER BY caption");
+
+ while ($line = db_fetch_assoc($result)) {
+ $label = array();
+ $label['id'] = 'LABEL:' . $line['id'];
+ $label['bare_id'] = $line['id'];
+ $label['name'] = $line['caption'];
+ $label['fg_color'] = $line['fg_color'];
+ $label['bg_color'] = $line['bg_color'];
+ $label['type'] = 'label';
+ $label['checkbox'] = false;
+
+ array_push($root['items'], $label);
+ }
+
+ $fl = array();
+ $fl['identifier'] = 'id';
+ $fl['label'] = 'name';
+ $fl['items'] = array($root);
+
+ print json_encode($fl);
+ return;
+ }
+
+ function colorset() {
+ $kind = db_escape_string($_REQUEST["kind"]);
+ $ids = split(',', db_escape_string($_REQUEST["ids"]));
+ $color = db_escape_string($_REQUEST["color"]);
+ $fg = db_escape_string($_REQUEST["fg"]);
+ $bg = db_escape_string($_REQUEST["bg"]);
+
+ foreach ($ids as $id) {
+
+ if ($kind == "fg" || $kind == "bg") {
+ db_query($this->link, "UPDATE ttrss_labels2 SET
+ ${kind}_color = '$color' WHERE id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
+ } else {
+ db_query($this->link, "UPDATE ttrss_labels2 SET
+ fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
+ }
+
+ $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"]));
+
+ /* Remove cached data */
+
+ db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = ''
+ WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
+
+ }
+
+ return;
+ }
+
+ function colorreset() {
+ $ids = split(',', db_escape_string($_REQUEST["ids"]));
+
+ foreach ($ids as $id) {
+ db_query($this->link, "UPDATE ttrss_labels2 SET
+ fg_color = '', bg_color = '' WHERE id = '$id'
+ AND owner_uid = " . $_SESSION["uid"]);
+
+ $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"]));
+
+ /* Remove cached data */
+
+ db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = ''
+ WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
+ }
+
+ }
+
+ function save() {
+
+ $id = db_escape_string($_REQUEST["id"]);
+ $caption = db_escape_string(trim($_REQUEST["caption"]));
+
+ db_query($this->link, "BEGIN");
+
+ $result = db_query($this->link, "SELECT caption FROM ttrss_labels2
+ WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
+
+ if (db_num_rows($result) != 0) {
+ $old_caption = db_fetch_result($result, 0, "caption");
+
+ $result = db_query($this->link, "SELECT id FROM ttrss_labels2
+ WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
+
+ if (db_num_rows($result) == 0) {
+ if ($caption) {
+ $result = db_query($this->link, "UPDATE ttrss_labels2 SET
+ caption = '$caption' WHERE id = '$id' AND
+ owner_uid = " . $_SESSION["uid"]);
+
+ /* Update filters that reference label being renamed */
+
+ $old_caption = db_escape_string($old_caption);
+
+ db_query($this->link, "UPDATE ttrss_filters SET
+ action_param = '$caption' WHERE action_param = '$old_caption'
+ AND action_id = 7
+ AND owner_uid = " . $_SESSION["uid"]);
+
+ print $_REQUEST["value"];
+ } else {
+ print $old_caption;
+ }
+ } else {
+ print $old_caption;
+ }
+ }
+
+ db_query($this->link, "COMMIT");
+
+ return;
+ }
+
+ function remove() {
+
+ $ids = split(",", db_escape_string($_REQUEST["ids"]));
+
+ foreach ($ids as $id) {
+ label_remove($this->link, $id, $_SESSION["uid"]);
+ }
+
+ }
+
+ function add() {
+ $caption = db_escape_string($_REQUEST["caption"]);
+ $output = db_escape_string($_REQUEST["output"]);
+
+ if ($caption) {
+
+ if (label_create($this->link, $caption)) {
+ if (!$output) {
+ print T_sprintf("Created label %s ", htmlspecialchars($caption));
+ }
+ }
+
+ if ($output == "select") {
+ header("Content-Type: text/xml");
+
+ print "";
+
+ print_label_select($this->link, "select_label",
+ $caption, "");
+
+ print " ";
+ }
+ }
+
+ return;
+ }
+
+ function index() {
+
+ $sort = db_escape_string($_REQUEST["sort"]);
+
+ if (!$sort || $sort == "undefined") {
+ $sort = "caption";
+ }
+
+ $label_search = db_escape_string($_REQUEST["search"]);
+
+ if (array_key_exists("search", $_REQUEST)) {
+ $_SESSION["prefs_label_search"] = $label_search;
+ } else {
+ $label_search = $_SESSION["prefs_label_search"];
+ }
+
+ print "";
+ print ""; #pane
+ print "
";
+
+ print "
+
".
+ __("Loading, please wait...")."
";
+
+ print "
+
+
+
+
+
+
+
";
+
+ print "
"; #pane
+ print "
"; #container
+
+ }
+}
+
+?>
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
new file mode 100644
index 00000000..ff8a17cd
--- /dev/null
+++ b/classes/pref/prefs.php
@@ -0,0 +1,499 @@
+link);
+
+ if (method_exists($authenticator, "change_password")) {
+ print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
+ } else {
+ print "ERROR: ".__("Function not supported by authentication module.");
+ }
+ }
+
+ 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]);
+
+ if ($pref_name == 'DIGEST_PREFERRED_TIME') {
+ if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) {
+
+ db_query($this->link, "UPDATE ttrss_users SET
+ last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
+
+ }
+ }
+
+ 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", "DIGEST_PREFERRED_TIME");
+
+
+ $_SESSION["prefs_op_result"] = "";
+
+ print "";
+ print "
";
+
+ print "
";
+
+ if ($_SESSION["auth_module"]) {
+ $module_class = "auth_" . $_SESSION["auth_module"];
+ $authenticator = new $module_class($this->link);
+ } else {
+ $authenticator = false;
+ }
+
+ if ($authenticator && method_exists($authenticator, "change_password")) {
+
+ $result = db_query($this->link, "SELECT id FROM ttrss_users
+ WHERE id = ".$_SESSION["uid"]." AND pwd_hash
+ = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
+
+ if (db_num_rows($result) != 0) {
+ print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
+ }
+
+ print "
";
+
+ }
+
+ print "
"; #pane
+
+ print "
";
+
+ print "
";
+
+ print "
"; #pane
+ print "
"; #container
+ }
+}
+?>
diff --git a/classes/pref/users.php b/classes/pref/users.php
new file mode 100644
index 00000000..e54f899d
--- /dev/null
+++ b/classes/pref/users.php
@@ -0,0 +1,494 @@
+";
+
+ $uid = sprintf("%d", $_REQUEST["id"]);
+
+ print "".__('User details')." ";
+
+ print "link, "SELECT login,
+ ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login,
+ access_level,
+ (SELECT COUNT(int_id) FROM ttrss_user_entries
+ WHERE owner_uid = id) AS stored_articles,
+ ".SUBSTRING_FOR_DATE."(created,1,16) AS created
+ FROM ttrss_users
+ WHERE id = '$uid'");
+
+ if (db_num_rows($result) == 0) {
+ print "".__('User not found')." ";
+ return;
+ }
+
+ // print "User Details ";
+
+ $login = db_fetch_result($result, 0, "login");
+
+ print "";
+
+ $last_login = make_local_datetime($this->link,
+ db_fetch_result($result, 0, "last_login"), true);
+
+ $created = make_local_datetime($this->link,
+ db_fetch_result($result, 0, "created"), true);
+
+ $access_level = db_fetch_result($result, 0, "access_level");
+ $stored_articles = db_fetch_result($result, 0, "stored_articles");
+
+ print "".__('Registered')." $created ";
+ print "".__('Last logged in')." $last_login ";
+
+ $result = db_query($this->link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
+ WHERE owner_uid = '$uid'");
+
+ $num_feeds = db_fetch_result($result, 0, "num_feeds");
+
+ print "".__('Subscribed feeds count')." $num_feeds ";
+
+ print "
";
+
+ print "".__('Subscribed feeds')." ";
+
+ $result = db_query($this->link, "SELECT id,title,site_url FROM ttrss_feeds
+ WHERE owner_uid = '$uid' ORDER BY title");
+
+ print "";
+
+ $row_class = "odd";
+
+ while ($line = db_fetch_assoc($result)) {
+
+ $icon_file = ICONS_URL."/".$line["id"].".ico";
+
+ if (file_exists($icon_file) && filesize($icon_file) > 0) {
+ $feed_icon = " ";
+ } else {
+ $feed_icon = " ";
+ }
+
+ print "$feed_icon ".$line["title"]." ";
+
+ $row_class = $row_class == "even" ? "odd" : "even";
+
+ }
+
+ if (db_num_rows($result) < $num_feeds) {
+ // FIXME - add link to show ALL subscribed feeds here somewhere
+ print " ... ";
+ }
+
+ print " ";
+
+ print "
+ ".__("Close this window").
+ "
";
+
+ print "]]> ";
+
+ return;
+ }
+
+ function edit() {
+ global $access_level_names;
+
+ header("Content-Type: text/xml");
+
+ $id = db_escape_string($_REQUEST["id"]);
+
+ print "";
+ print "".__('User Editor')." ";
+ print "";
+
+ print " ";
+ print " ";
+ print " ";
+
+ $result = db_query($this->link, "SELECT * FROM ttrss_users WHERE id = '$id'");
+
+ $login = db_fetch_result($result, 0, "login");
+ $access_level = db_fetch_result($result, 0, "access_level");
+ $email = db_fetch_result($result, 0, "email");
+
+ $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
+
+ print "".__("User")."
";
+ print "";
+
+ if ($sel_disabled) {
+ print " ";
+ print " ";
+ } else {
+ print " ";
+ }
+
+ print "
";
+
+ print "".__("Authentication")."
";
+ print "";
+
+ print __('Access level: ') . " ";
+
+ if (!$sel_disabled) {
+ print_select_hash("access_level", $access_level, $access_level_names,
+ $sel_disabled);
+ } else {
+ print_select_hash("", $access_level, $access_level_names,
+ $sel_disabled);
+ print " ";
+ }
+
+ print " ";
+
+ print __('Change password to') .
+ " ";
+
+ print "
";
+
+ print "".__("Options")."
";
+ print "";
+
+ print __('E-mail: ').
+ " ";
+
+ print "
";
+
+ print "";
+
+ print "";
+
+ print "
+ ".
+ __('Save')."
+ ".
+ __('Cancel')."
";
+
+ print "]]> ";
+
+ return;
+ }
+
+ function editSave() {
+ $login = db_escape_string(trim($_REQUEST["login"]));
+ $uid = db_escape_string($_REQUEST["id"]);
+ $access_level = (int) $_REQUEST["access_level"];
+ $email = db_escape_string(trim($_REQUEST["email"]));
+ $password = db_escape_string(trim($_REQUEST["password"]));
+
+ if ($password) {
+ $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $pwd_hash = encrypt_password($password, $salt, true);
+ $pass_query_part = "pwd_hash = '$pwd_hash', salt = '$salt',";
+ } else {
+ $pass_query_part = "";
+ }
+
+ db_query($this->link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
+ access_level = '$access_level', email = '$email' WHERE id = '$uid'");
+
+ }
+
+ function remove() {
+ $ids = split(",", db_escape_string($_REQUEST["ids"]));
+
+ foreach ($ids as $id) {
+ if ($id != $_SESSION["uid"] && $id != 1) {
+ db_query($this->link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'");
+ db_query($this->link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'");
+ db_query($this->link, "DELETE FROM ttrss_users WHERE id = '$id'");
+ }
+ }
+ }
+
+ function add() {
+
+ $login = db_escape_string(trim($_REQUEST["login"]));
+ $tmp_user_pwd = make_password(8);
+ $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $pwd_hash = encrypt_password($tmp_user_pwd, $salt, true);
+
+ $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
+ login = '$login'");
+
+ if (db_num_rows($result) == 0) {
+
+ db_query($this->link, "INSERT INTO ttrss_users
+ (login,pwd_hash,access_level,last_login,created, salt)
+ VALUES ('$login', '$pwd_hash', 0, null, NOW(), '$salt')");
+
+
+ $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
+ login = '$login' AND pwd_hash = '$pwd_hash'");
+
+ if (db_num_rows($result) == 1) {
+
+ $new_uid = db_fetch_result($result, 0, "id");
+
+ print format_notice(T_sprintf("Added user %s with password %s ",
+ $login, $tmp_user_pwd));
+
+ initialize_user($this->link, $new_uid);
+
+ } else {
+
+ print format_warning(T_sprintf("Could not create user %s ", $login));
+
+ }
+ } else {
+ print format_warning(T_sprintf("User %s already exists.", $login));
+ }
+ }
+
+ function resetPass() {
+
+ $uid = db_escape_string($_REQUEST["id"]);
+
+ $result = db_query($this->link, "SELECT login,email
+ FROM ttrss_users WHERE id = '$uid'");
+
+ $login = db_fetch_result($result, 0, "login");
+ $email = db_fetch_result($result, 0, "email");
+ $salt = db_fetch_result($result, 0, "salt");
+
+ $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
+ $tmp_user_pwd = make_password(8);
+
+ $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
+
+ db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash', salt = '$new_salt'
+ WHERE id = '$uid'");
+
+ print T_sprintf("Changed password of user %s
+ to %s ", $login, $tmp_user_pwd);
+
+ require_once 'lib/phpmailer/class.phpmailer.php';
+
+ if ($email) {
+ print " ";
+ print T_sprintf("Notifying %s .", $email);
+
+ require_once "lib/MiniTemplator.class.php";
+
+ $tpl = new MiniTemplator;
+
+ $tpl->readTemplateFromFile("templates/resetpass_template.txt");
+
+ $tpl->setVariable('LOGIN', $login);
+ $tpl->setVariable('NEWPASS', $tmp_user_pwd);
+
+ $tpl->addBlock('message');
+
+ $message = "";
+
+ $tpl->generateOutputToString($message);
+
+ $mail = new PHPMailer();
+
+ $mail->PluginDir = "lib/phpmailer/";
+ $mail->SetLanguage("en", "lib/phpmailer/language/");
+
+ $mail->CharSet = "UTF-8";
+
+ $mail->From = SMTP_FROM_ADDRESS;
+ $mail->FromName = SMTP_FROM_NAME;
+ $mail->AddAddress($email, $login);
+
+ if (SMTP_HOST) {
+ $mail->Host = SMTP_HOST;
+ $mail->Mailer = "smtp";
+ $mail->SMTPAuth = SMTP_LOGIN != '';
+ $mail->Username = SMTP_LOGIN;
+ $mail->Password = SMTP_PASSWORD;
+ }
+
+ $mail->IsHTML(false);
+ $mail->Subject = __("[tt-rss] Password change notification");
+ $mail->Body = $message;
+
+ $rc = $mail->Send();
+
+ if (!$rc) print_error($mail->ErrorInfo);
+ }
+
+ print "";
+ }
+
+ function index() {
+
+ global $access_level_names;
+
+ print "";
+ print ""; #pane
+ print "
";
+
+ print "
";
+
+ if ($user_search) {
+
+ $user_search = split(" ", $user_search);
+ $tokens = array();
+
+ foreach ($user_search as $token) {
+ $token = trim($token);
+ array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))");
+ }
+
+ $user_search_query = "(" . join($tokens, " AND ") . ") AND ";
+
+ } else {
+ $user_search_query = "";
+ }
+
+ $result = db_query($this->link, "SELECT
+ id,login,access_level,email,
+ ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login,
+ ".SUBSTRING_FOR_DATE."(created,1,16) as created
+ FROM
+ ttrss_users
+ WHERE
+ $user_search_query
+ id > 0
+ ORDER BY $sort");
+
+ if (db_num_rows($result) > 0) {
+
+ print "
";
+
+ } else {
+ print "
";
+ if (!$user_search) {
+ print_warning(__('No users defined.'));
+ } else {
+ print_warning(__('No matching users found.'));
+ }
+ print "
";
+
+ }
+
+ print "
"; #pane
+ print "
"; #container
+
+ }
+
+ }
+?>
diff --git a/classes/pref_feeds.php b/classes/pref_feeds.php
deleted file mode 100644
index b1056119..00000000
--- a/classes/pref_feeds.php
+++ /dev/null
@@ -1,1681 +0,0 @@
-";
- }
-
- 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;
- }
-
- private function get_category_items($cat_id) {
- $show_empty_cats = $_REQUEST['mode'] != 2 &&
- get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
-
- $items = array();
-
- $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
- WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat = '$cat_id' ORDER BY order_id, title");
-
- while ($line = db_fetch_assoc($result)) {
-
- $cat = array();
- $cat['id'] = 'CAT:' . $line['id'];
- $cat['bare_id'] = (int)$line['id'];
- $cat['name'] = $line['title'];
- $cat['items'] = array();
- $cat['checkbox'] = false;
- $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
- $cat['type'] = 'category';
- $cat['unread'] = 0;
- $cat['child_unread'] = 0;
-
- $cat['items'] = $this->get_category_items($line['id']);
-
- $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
-
- if (count($cat['items']) > 0 || $show_empty_cats)
- array_push($items, $cat);
-
- }
-
- $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 = '$cat_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'] = (int)$feed_line['id'];
- $feed['name'] = $feed_line['title'];
- $feed['checkbox'] = false;
- $feed['unread'] = 0;
- $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($items, $feed);
- }
-
- return $items;
- }
-
- 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';
-
- $enable_cats = get_pref($this->link, 'ENABLE_FEED_CATS');
-
- if ($_REQUEST['mode'] == 2) {
-
- if ($enable_cats) {
- $cat_hidden = get_pref($this->link, "_COLLAPSED_SPECIAL");
- $cat = $this->feedlist_init_cat(-1, $cat_hidden);
- } else {
- $cat['items'] = array();
- }
-
- foreach (array(-4, -3, -1, -2, 0) as $i) {
- array_push($cat['items'], $this->feedlist_init_feed($i));
- }
-
- if ($enable_cats) {
- array_push($root['items'], $cat);
- } else {
- $root['items'] = array_merge($root['items'], $cat['items']);
- }
-
- $result = db_query($this->link, "SELECT * FROM
- ttrss_labels2 WHERE owner_uid = ".$_SESSION['uid']." ORDER by caption");
-
- if (db_num_rows($result) > 0) {
-
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
- $cat_hidden = get_pref($this->link, "_COLLAPSED_LABELS");
- $cat = $this->feedlist_init_cat(-2, $cat_hidden);
- } else {
- $cat['items'] = array();
- }
-
- while ($line = db_fetch_assoc($result)) {
-
- $label_id = -$line['id'] - 11;
- $count = getFeedUnread($this->link, $label_id);
-
- $feed = $this->feedlist_init_feed($label_id, false, $count);
-
- $feed['fg_color'] = $line['fg_color'];
- $feed['bg_color'] = $line['bg_color'];
-
- array_push($cat['items'], $feed);
- }
-
- if ($enable_cats) {
- array_push($root['items'], $cat);
- } else {
- $root['items'] = array_merge($root['items'], $cat['items']);
- }
- }
- }
-
- if ($enable_cats) {
- $show_empty_cats = $_REQUEST['mode'] != 2 &&
- get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS');
-
- $result = db_query($this->link, "SELECT id, title, collapsed FROM ttrss_feed_categories
- WHERE owner_uid = " . $_SESSION["uid"] . " AND parent_cat IS NULL ORDER BY order_id, title");
-
- while ($line = db_fetch_assoc($result)) {
- $cat = array();
- $cat['id'] = 'CAT:' . $line['id'];
- $cat['bare_id'] = (int)$line['id'];
- $cat['name'] = $line['title'];
- $cat['items'] = array();
- $cat['checkbox'] = false;
- $cat['hidden'] = sql_bool_to_bool($line['collapsed']);
- $cat['type'] = 'category';
- $cat['unread'] = 0;
- $cat['child_unread'] = 0;
-
- $cat['items'] = $this->get_category_items($line['id']);
-
- $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
-
- if (count($cat['items']) > 0 || $show_empty_cats)
- 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['hidden'] = get_pref($this->link, "_COLLAPSED_UNCAT");
- $cat['type'] = 'category';
- $cat['checkbox'] = false;
- $cat['unread'] = 0;
- $cat['child_unread'] = 0;
-
- $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'] = (int)$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);
- $feed['unread'] = 0;
- $feed['type'] = 'feed';
-
- array_push($cat['items'], $feed);
- }
-
- $cat['param'] = T_sprintf('(%d feeds)', count($cat['items']));
-
- if (count($cat['items']) > 0 || $show_empty_cats)
- 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'] = (int)$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);
- $feed['unread'] = 0;
- $feed['type'] = 'feed';
-
- array_push($root['items'], $feed);
- }
-
- $root['param'] = T_sprintf('(%d feeds)', count($root['items']));
- }
-
- $fl = array();
- $fl['identifier'] = 'id';
- $fl['label'] = 'name';
-
- if ($_REQUEST['mode'] != 2) {
- $fl['items'] = array($root);
- } else {
- $fl['items'] =& $root['items'];
- }
-
- 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 togglehiddenfeedcats() {
- set_pref($this->link, '_PREFS_SHOW_EMPTY_CATS',
- (get_pref($this->link, '_PREFS_SHOW_EMPTY_CATS') ? 'false' : 'true'));
- }
-
- private function process_category_order(&$data_map, $item_id, $parent_id = false, $nest_level = 0) {
- $debug = isset($_REQUEST["debug"]);
-
- $prefix = "";
- for ($i = 0; $i < $nest_level; $i++)
- $prefix .= " ";
-
- if ($debug) _debug("$prefix C: $item_id P: $parent_id");
-
- $bare_item_id = substr($item_id, strpos($item_id, ':')+1);
-
- if ($item_id != 'root') {
- if ($parent_id && $parent_id != 'root') {
- $parent_bare_id = substr($parent_id, strpos($parent_id, ':')+1);
- $parent_qpart = db_escape_string($parent_bare_id);
- } else {
- $parent_qpart = 'NULL';
- }
-
- db_query($this->link, "UPDATE ttrss_feed_categories
- SET parent_cat = $parent_qpart WHERE id = '$bare_item_id' AND
- owner_uid = " . $_SESSION["uid"]);
- }
-
- $order_id = 0;
-
- $cat = $data_map[$item_id];
-
- if ($cat && is_array($cat)) {
- foreach ($cat as $item) {
- $id = $item['_reference'];
- $bare_id = substr($id, strpos($id, ':')+1);
-
- if ($debug) _debug("$prefix [$order_id] $id/$bare_id");
-
- if ($item['_reference']) {
-
- if (strpos($id, "FEED") === 0) {
-
- $cat_id = ($item_id != "root") ?
- db_escape_string($bare_item_id) : "NULL";
-
- db_query($this->link, "UPDATE ttrss_feeds
- SET order_id = $order_id, cat_id = '$cat_id'
- WHERE id = '$bare_id' AND
- owner_uid = " . $_SESSION["uid"]);
-
- } else if (strpos($id, "CAT:") === 0) {
- $this->process_category_order($data_map, $item['_reference'], $item_id,
- $nest_level+1);
-
- if ($item_id != 'root') {
- $parent_qpart = db_escape_string($bare_id);
- } else {
- $parent_qpart = 'NULL';
- }
-
- db_query($this->link, "UPDATE ttrss_feed_categories
- SET order_id = '$order_id' WHERE id = '$bare_id' AND
- owner_uid = " . $_SESSION["uid"]);
- }
- }
-
- ++$order_id;
- }
- }
- }
-
- function savefeedorder() {
- $data = json_decode($_POST['payload'], true);
-
- #file_put_contents("/tmp/saveorder.json", $_POST['payload']);
- #$data = json_decode(file_get_contents("/tmp/saveorder.json"), true);
-
- if (!is_array($data['items']))
- $data['items'] = json_decode($data['items'], true);
-
-# print_r($data['items']);
-
- if (is_array($data) && is_array($data['items'])) {
- $cat_order_id = 0;
-
- $data_map = array();
- $root_item = false;
-
- 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'];
- }
- }
- if ($item['id'] == 'root') {
- $root_item = $item['id'];
- }
- }
-
- $this->process_category_order($data_map, $root_item);
-
- /* 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 "";
- 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 " ";
- print " ";
- print " ";
-
- print "".__("Feed")."
";
- print "";
-
- /* Title */
-
- print " ";
-
- /* Feed URL */
-
- $feed_url = db_fetch_result($result, 0, "feed_url");
- $feed_url = htmlspecialchars(db_fetch_result($result,
- 0, "feed_url"));
-
- print "
";
-
- print __('URL:') . " ";
- print " ";
-
- $last_error = db_fetch_result($result, 0, "last_error");
-
- if ($last_error) {
- print " (error) ";
-
- }
-
- /* Category */
-
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
-
- $cat_id = db_fetch_result($result, 0, "cat_id");
-
- print " ";
-
- print __('Place in category:') . " ";
-
- print_feed_cat_select($this->link, "cat_id", $cat_id,
- 'dojoType="dijit.form.Select"');
- }
-
- print "";
-
- print "".__("Update")."
";
- print "";
-
- /* 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 "
";
- print __('Article purging:') . " ";
-
- print_select_hash("purge_interval", $purge_interval, $purge_intervals,
- 'dojoType="dijit.form.Select" ' .
- ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
-
- print "";
- print "".__("Authentication")."
";
- print "";
- print "".__("Options")."
";
- print "";
-
- $private = sql_bool_to_bool(db_fetch_result($result, 0, "private"));
-
- if ($private) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print " ".__('Hide from Popular feeds')." ";
-
- $rtl_content = sql_bool_to_bool(db_fetch_result($result, 0, "rtl_content"));
-
- if ($rtl_content) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print "
".__('Right-to-left content')." ";
-
- $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 " ".__('Include in e-mail digest')." ";
-
-
- $always_display_enclosures = sql_bool_to_bool(db_fetch_result($result, 0, "always_display_enclosures"));
-
- if ($always_display_enclosures) {
- $checked = "checked";
- } else {
- $checked = "";
- }
-
- print " ".__('Always display image attachments')." ";
-
-
- $cache_images = sql_bool_to_bool(db_fetch_result($result, 0, "cache_images"));
-
- if ($cache_images) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print " ".
- __('Cache images locally')." ";
-
- $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 " ".__('Mark updated articles as unread')." ";
-
- $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 " ".__('Mark posts as updated on content change')." ";
-
- print "";
-
- /* Icon */
-
- print "".__("Icon")."
";
- print "";
-
- print "";
-
- print "";
-
- print "
";
-
- $title = htmlspecialchars($title, ENT_QUOTES);
-
- print "";
-
- return;
- }
-
- function editfeeds() {
- global $purge_intervals;
- global $update_intervals;
- global $update_methods;
-
- $feed_ids = db_escape_string($_REQUEST["ids"]);
-
- print "" . __("Enable the options you wish to apply using checkboxes on the right:") . "
";
-
- print " ";
- print " ";
- print " ";
-
- print "".__("Feed")."
";
- print "";
-
- /* Title */
-
- print " ";
-
- $this->batch_edit_cbox("title");
-
- /* Feed URL */
-
- print " ";
-
- print __('URL:') . " ";
- print " ";
-
- $this->batch_edit_cbox("feed_url");
-
- /* Category */
-
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
-
- print " ";
-
- 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 "
";
-
- print "".__("Update")."
";
- print "";
-
- /* 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 " ";
-
- 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 "
";
- print "".__("Authentication")."
";
- print "";
-
- print " ";
-
- $this->batch_edit_cbox("auth_login");
-
- print " ";
-
- $this->batch_edit_cbox("auth_pass");
-
- print "
";
- print "".__("Options")."
";
- print "";
-
- print " ".__('Hide from Popular feeds')." ";
-
- print " "; $this->batch_edit_cbox("private", "private_l");
-
- print " ".__('Right-to-left content')." ";
-
- print " "; $this->batch_edit_cbox("rtl_content", "rtl_content_l");
-
- print " ".__('Include in e-mail digest')." ";
-
- print " "; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
-
- print " ".__('Always display image attachments')." ";
-
- print " "; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
-
- print " ".
- __('Cache images locally')." ";
-
- print " "; $this->batch_edit_cbox("cache_images", "cache_images_l");
-
- print " ".__('Mark updated articles as unread')." ";
-
- print " "; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
-
- print " ".__('Mark posts as updated on content change')." ";
-
- print " "; $this->batch_edit_cbox("update_on_checksum_change", "update_on_checksum_change_l");
-
- print "
";
-
- print "
- ".
- __('Save')."
- ".
- __('Cancel')."
-
";
-
- return;
- }
-
- function batchEditSave() {
- return $this->editsaveops(true);
- }
-
- function editSave() {
- return $this->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 = "";
- }
-
- $cache_images_qpart = "cache_images = $cache_images,";
-
- if (!$batch) {
-
- $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 {
- $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 " ";
- }
- }
-
- 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; charset=utf-8');
- print "
-
- Tiny Tiny RSS
-
-
-
-
-
- Subscribe to feed... ";
- }
-
- $rc = subscribe_to_feed($this->link, $feed_url, $cat_id, $auth_login, $auth_pass);
-
- switch ($rc) {
- case 1:
- print_notice(T_sprintf("Subscribed to %s .", $feed_url));
- break;
- case 2:
- print_error(T_sprintf("Could not subscribe to %s .", $feed_url));
- break;
- case 3:
- print_error(T_sprintf("No feeds found in %s .", $feed_url));
- break;
- case 0:
- print_warning(T_sprintf("Already subscribed to %s .", $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 %s . Can't download the Feed URL.", $feed_url));
- break;
- }
-
- if ($p_from != 'tt-rss') {
-
- if ($feed_urls) {
-
- print "";
- }
-
- $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 "";
-
- if ($feed_id) {
- print "
";
- }
-
- print "";
-
- print "";
- 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 removeCat() {
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
- foreach ($ids as $id) {
- remove_feed_category($this->link, $id, $_SESSION["uid"]);
- }
- }
-
- function addCat() {
- $feed_cat = db_escape_string(trim($_REQUEST["cat"]));
-
- add_feed_category($this->link, $feed_cat);
- }
-
- function index() {
-
- print "";
- print "
";
-
- $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 = "
" .
- __("Feeds with errors") . " ";
- }
-
- 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 = "
" .
- __("Inactive feeds") . " ";
- }
-
- $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 '
';
-
- print "
"; #toolbar
-
- print "
-
- ".
- __('Search')."
-
";
-
- print "
".
- "
" . __('Select')." ";
- print "
";
- print "
".__('All')."
";
- print "
".__('None')."
";
- print "
";
-
- print "
".
- "
" . __('Feeds')." ";
- print "
";
- print "
".__('Subscribe to feed')."
";
- print "
".__('Edit selected feeds')."
";
- print "
".__('Reset sort order')."
";
- print "
".__('Batch subscribe')."
";
- print "
";
-
- if (get_pref($this->link, 'ENABLE_FEED_CATS')) {
- print "
".
- "
" . __('Categories')." ";
- print "
";
- print "
".__('Add category')."
";
- print "
".__('(Un)hide empty categories')."
";
- print "
".__('Reset sort order')."
";
- print "
";
-
- }
-
- print $error_button;
- print $inactive_button;
-
- print "
"
- .__('Unsubscribe')." ";
-
- if (defined('_ENABLE_FEED_DEBUGGING')) {
-
- print "
- ".__('More actions...')." ";
-
- if (FORCE_ARTICLE_PURGE == 0) {
- print
- "".__('Manual purge')." ";
- }
-
- print "
- ".__('Clear feed data')."
- ".__('Rescore articles')." ";
-
- print " ";
-
- }
-
- print "
"; # toolbar
-
- //print '
';
- print '
';
-
- print "
-
".
- __("Loading, please wait...")."
";
-
- print "
-
-
-
-
-
-
-
";
-
-# print "
-# ".__('Hint: you can drag feeds and categories around.')."
-#
";
-
- print '
';
- print '
';
-
- print "
"; # feeds pane
-
- print "";
-
- print "
" . __("OPML") . " ";
-
- print "
" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . " ";
-
- print __("Only main settings profile can be migrated using OPML.") . "
";
-
- print "
";
-
- print "
";
-
- print "
";
-
- print "
".__('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') . " ";
-
- print __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") . "
";
-
- print "
".
- __('Display published OPML URL')." ";
-
-
- print "
" . __("Article archive") . " ";
-
- print "
" . __("You can export and import your Starred and Archived articles for safekeeping or when migrating between tt-rss instances.") . "
";
-
- print "
".
- __('Export my data')." ";
-
- print "
";
-
- print "
";
-
- print "
"; # pane
-
- if (strpos($_SERVER['HTTP_USER_AGENT'], "Firefox") !== false) {
-
- print "";
-
- print "
" . __('This Tiny Tiny RSS site can be used as a Firefox Feed Reader by clicking the link below.') . "
";
-
- print "
";
-
- print "" .
- __('Click here to register this site as a feed reader.') .
- " ";
-
- print "
";
-
- print "
"; # pane
- }
-
- print "";
-
- print "
" . __("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.") . "
";
-
- $bm_subscribe_url = str_replace('%s', '', add_feed_url());
-
- $confirm_str = str_replace("'", "\'", __('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 "
" . __('Subscribe in Tiny Tiny RSS'). " ";
-
- print "
"; #pane
-
- print "";
-
- print "
" . __("Published articles and generated feeds") . " ";
-
- print "
".__('Published articles are exported as a public RSS feed and can be subscribed by anyone who knows the URL specified below.')."
";
-
- $rss_url = '-2::' . htmlspecialchars(get_self_url_prefix() .
- "/public.php?op=rss&id=-2&view-mode=all_articles");;
-
- print "
".
- __('Display URL')." ";
-
- print "
".
- __('Clear all generated URLs')." ";
-
- print "
" . __("Articles shared by URL") . " ";
-
- print "
" . __("You can disable all articles shared by unique URLs here.") . "
";
-
- print "
".
- __('Unshare all articles')." ";
-
- print "
"; #pane
-
- if (defined('CONSUMER_KEY') && CONSUMER_KEY != '') {
-
- print ""; # pane
-
- }
-
- print ""; #container
-
- }
-
- private function feedlist_init_cat($cat_id, $hidden = false) {
- $obj = array();
- $cat_id = (int) $cat_id;
-
- if ($cat_id > 0) {
- $cat_unread = ccache_find($this->link, $cat_id, $_SESSION["uid"], true);
- } else if ($cat_id == 0 || $cat_id == -2) {
- $cat_unread = getCategoryUnread($this->link, $cat_id);
- }
-
- $obj['id'] = 'CAT:' . $cat_id;
- $obj['items'] = array();
- $obj['name'] = getCategoryTitle($this->link, $cat_id);
- $obj['type'] = 'category';
- $obj['unread'] = (int) $cat_unread;
- $obj['hidden'] = $hidden;
- $obj['bare_id'] = $cat_id;
-
- return $obj;
- }
-
- private function feedlist_init_feed($feed_id, $title = false, $unread = false, $error = '', $updated = '') {
- $obj = array();
- $feed_id = (int) $feed_id;
-
- if (!$title)
- $title = getFeedTitle($this->link, $feed_id, false);
-
- if ($unread === false)
- $unread = getFeedUnread($this->link, $feed_id, false);
-
- $obj['id'] = 'FEED:' . $feed_id;
- $obj['name'] = $title;
- $obj['unread'] = (int) $unread;
- $obj['type'] = 'feed';
- $obj['error'] = $error;
- $obj['updated'] = $updated;
- $obj['icon'] = getFeedIcon($feed_id);
- $obj['bare_id'] = $feed_id;
-
- return $obj;
- }
-
-}
-?>
diff --git a/classes/pref_filters.php b/classes/pref_filters.php
deleted file mode 100644
index ea99d56e..00000000
--- a/classes/pref_filters.php
+++ /dev/null
@@ -1,657 +0,0 @@
-link, "SELECT name FROM ttrss_filter_types WHERE
- id = " . $filter_type);
- $type_name = db_fetch_result($result, 0, "name");
-
- $result = db_query($this->link, "SELECT name FROM ttrss_filter_actions WHERE
- id = " . $action_id);
- $action_name = db_fetch_result($result, 0, "name");
-
- $filter["reg_exp"] = $reg_exp;
- $filter["action"] = $action_name;
- $filter["type"] = $type_name;
- $filter["action_param"] = $action_param;
- $filter["filter_param"] = $filter_param;
- $filter["inverse"] = $inverse;
-
- $filters[$type_name] = array($filter);
-
- if ($feed_id)
- $feed = $feed_id;
- else
- $feed = -4;
-
- $regexp_valid = preg_match('/' . $filter['reg_exp'] . '/',
- $filter['reg_exp']) !== FALSE;
-
- print __("Articles matching this filter:");
-
- print "";
- print "
";
-
- if ($regexp_valid) {
-
- $feed_title = getFeedTitle($this->link, $feed);
-
- $qfh_ret = queryFeedHeadlines($this->link, $cat_filter ? $cat_id : $feed,
- 30, "", $cat_filter, false, false,
- false, "date_entered DESC", 0, $_SESSION["uid"], $filter);
-
- $result = $qfh_ret[0];
-
- $articles = array();
- $found = 0;
-
- while ($line = db_fetch_assoc($result)) {
-
- $entry_timestamp = strtotime($line["updated"]);
- $entry_tags = get_article_tags($this->link, $line["id"], $_SESSION["uid"]);
-
- $content_preview = truncate_string(
- strip_tags($line["content_preview"]), 100, '...');
-
- if ($line["feed_title"])
- $feed_title = $line["feed_title"];
-
- print "";
-
- print " ";
- print "";
-
- print $line["title"];
- print " (";
- print "" . $feed_title . " ";
- print "): ";
- print "" . $content_preview . " ";
- print " " . mb_substr($line["date_entered"], 0, 16);
-
- print " ";
-
- $found++;
- }
-
- if ($found == 0) {
- print "" .
- __("No articles matching this filter has been found.") . " ";
- }
- } else {
- print "" .
- __("Invalid regular expression.") . " ";
-
- }
-
- print "
";
- print "
";
-
- }
-
- function getfiltertree() {
- $root = array();
- $root['id'] = 'root';
- $root['name'] = __('Filters');
- $root['items'] = array();
-
- $search = $_SESSION["prefs_filter_search"];
-
- if ($search) $search_qpart = " (LOWER(reg_exp) LIKE LOWER('%$search%')
- OR LOWER(ttrss_feeds.title) LIKE LOWER('%$search%')
- OR LOWER(COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."'))
- LIKE LOWER('%$search%') AND cat_filter = true) AND ";
-
- $result = db_query($this->link, "SELECT
- ttrss_filters.id AS id,reg_exp,
- ttrss_filter_types.name AS filter_type_name,
- ttrss_filter_types.description AS filter_type_descr,
- enabled,
- inverse,
- cat_filter,
- feed_id,
- ttrss_filters.cat_id,
- action_id,
- filter_param,
- filter_type,
- ttrss_filter_actions.description AS action_description,
- ttrss_feeds.title AS feed_title,
- COALESCE(ttrss_feed_categories.title, '".__('Uncategorized')."') AS cat_title,
- ttrss_filter_actions.name AS action_name,
- ttrss_filters.action_param AS action_param
- FROM
- ttrss_filter_types,ttrss_filter_actions,ttrss_filters LEFT JOIN
- ttrss_feeds ON (ttrss_filters.feed_id = ttrss_feeds.id) LEFT JOIN
- ttrss_feed_categories ON (ttrss_filters.cat_id = ttrss_feed_categories.id)
- WHERE
- filter_type = ttrss_filter_types.id AND
- ttrss_filter_actions.id = action_id AND
- $search_qpart
- ttrss_filters.owner_uid = ".$_SESSION["uid"]."
- ORDER by action_description, reg_exp");
-
- $cat = false;
- $cur_action_description = "";
-
- if (db_num_rows($result) > 0) {
-
- while ($line = db_fetch_assoc($result)) {
- if ($cur_action_description != $line['action_description']) {
-
- if ($cat)
- array_push($root['items'], $cat);
-
- $cat = array();
- $cat['id'] = 'ACTION:' . $line['action_id'];
- $cat['name'] = $line['action_description'];
- $cat['items'] = array();
-
- $cur_action_description = $line['action_description'];
- }
-
- if (array_search($line["action_name"],
- array("score", "tag", "label")) === false) {
-
- $line["action_param"] = '';
- } else {
- if ($line['action_name'] == 'label') {
-
- $tmp_result = db_query($this->link, "SELECT fg_color, bg_color
- FROM ttrss_labels2 WHERE caption = '".
- db_escape_string($line["action_param"])."' AND
- owner_uid = " . $_SESSION["uid"]);
-
- if (db_num_rows($tmp_result) != 0) {
- $fg_color = db_fetch_result($tmp_result, 0, "fg_color");
- $bg_color = db_fetch_result($tmp_result, 0, "bg_color");
-
- $tmp = "α " . $line['action_param'];
-
- $line['action_param'] = $tmp;
- }
- }
- }
-
- $filter = array();
- $filter['id'] = 'FILTER:' . $line['id'];
- $filter['bare_id'] = $line['id'];
- $filter['name'] = $line['reg_exp'];
- $filter['type'] = $line['filter_type'];
- $filter['enabled'] = sql_bool_to_bool($line['enabled']);
- $filter['param'] = $line['action_param'];
- $filter['inverse'] = sql_bool_to_bool($line['inverse']);
- $filter['checkbox'] = false;
-
- if (sql_bool_to_bool($line['cat_filter']))
- if ($line['cat_id'] != 0) {
- $filter['feed'] = $line['cat_title'];
- } else {
- $filter['feed'] = __('Uncategorized');
- }
- else if ($line['feed_id'])
- $filter['feed'] = $line['feed_title'];
-
- array_push($cat['items'], $filter);
- }
-
- array_push($root['items'], $cat);
- }
-
- $fl = array();
- $fl['identifier'] = 'id';
- $fl['label'] = 'name';
- $fl['items'] = array($root);
-
- print json_encode($fl);
- return;
- }
-
- function edit() {
-
- $filter_id = db_escape_string($_REQUEST["id"]);
-
- $result = db_query($this->link,
- "SELECT * FROM ttrss_filters WHERE id = '$filter_id' AND owner_uid = " . $_SESSION["uid"]);
-
- $reg_exp = htmlspecialchars(db_fetch_result($result, 0, "reg_exp"));
- $filter_type = db_fetch_result($result, 0, "filter_type");
- $feed_id = db_fetch_result($result, 0, "feed_id");
- $cat_id = db_fetch_result($result, 0, "cat_id");
- $action_id = db_fetch_result($result, 0, "action_id");
- $action_param = db_fetch_result($result, 0, "action_param");
- $filter_param = db_fetch_result($result, 0, "filter_param");
-
- $enabled = sql_bool_to_bool(db_fetch_result($result, 0, "enabled"));
- $inverse = sql_bool_to_bool(db_fetch_result($result, 0, "inverse"));
- $cat_filter = sql_bool_to_bool(db_fetch_result($result, 0, "cat_filter"));
-
- print "";
-
- print "";
- print "".
- __('Save')." ";
- print "".
- __('Cancel')." ";
- print "
";
-
- return;
- }
-
- function getlabeltree() {
- $root = array();
- $root['id'] = 'root';
- $root['name'] = __('Labels');
- $root['items'] = array();
-
- $result = db_query($this->link, "SELECT *
- FROM ttrss_labels2
- WHERE owner_uid = ".$_SESSION["uid"]."
- ORDER BY caption");
-
- while ($line = db_fetch_assoc($result)) {
- $label = array();
- $label['id'] = 'LABEL:' . $line['id'];
- $label['bare_id'] = $line['id'];
- $label['name'] = $line['caption'];
- $label['fg_color'] = $line['fg_color'];
- $label['bg_color'] = $line['bg_color'];
- $label['type'] = 'label';
- $label['checkbox'] = false;
-
- array_push($root['items'], $label);
- }
-
- $fl = array();
- $fl['identifier'] = 'id';
- $fl['label'] = 'name';
- $fl['items'] = array($root);
-
- print json_encode($fl);
- return;
- }
-
- function colorset() {
- $kind = db_escape_string($_REQUEST["kind"]);
- $ids = split(',', db_escape_string($_REQUEST["ids"]));
- $color = db_escape_string($_REQUEST["color"]);
- $fg = db_escape_string($_REQUEST["fg"]);
- $bg = db_escape_string($_REQUEST["bg"]);
-
- foreach ($ids as $id) {
-
- if ($kind == "fg" || $kind == "bg") {
- db_query($this->link, "UPDATE ttrss_labels2 SET
- ${kind}_color = '$color' WHERE id = '$id'
- AND owner_uid = " . $_SESSION["uid"]);
- } else {
- db_query($this->link, "UPDATE ttrss_labels2 SET
- fg_color = '$fg', bg_color = '$bg' WHERE id = '$id'
- AND owner_uid = " . $_SESSION["uid"]);
- }
-
- $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"]));
-
- /* Remove cached data */
-
- db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = ''
- WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
-
- }
-
- return;
- }
-
- function colorreset() {
- $ids = split(',', db_escape_string($_REQUEST["ids"]));
-
- foreach ($ids as $id) {
- db_query($this->link, "UPDATE ttrss_labels2 SET
- fg_color = '', bg_color = '' WHERE id = '$id'
- AND owner_uid = " . $_SESSION["uid"]);
-
- $caption = db_escape_string(label_find_caption($this->link, $id, $_SESSION["uid"]));
-
- /* Remove cached data */
-
- db_query($this->link, "UPDATE ttrss_user_entries SET label_cache = ''
- WHERE label_cache LIKE '%$caption%' AND owner_uid = " . $_SESSION["uid"]);
- }
-
- }
-
- function save() {
-
- $id = db_escape_string($_REQUEST["id"]);
- $caption = db_escape_string(trim($_REQUEST["caption"]));
-
- db_query($this->link, "BEGIN");
-
- $result = db_query($this->link, "SELECT caption FROM ttrss_labels2
- WHERE id = '$id' AND owner_uid = ". $_SESSION["uid"]);
-
- if (db_num_rows($result) != 0) {
- $old_caption = db_fetch_result($result, 0, "caption");
-
- $result = db_query($this->link, "SELECT id FROM ttrss_labels2
- WHERE caption = '$caption' AND owner_uid = ". $_SESSION["uid"]);
-
- if (db_num_rows($result) == 0) {
- if ($caption) {
- $result = db_query($this->link, "UPDATE ttrss_labels2 SET
- caption = '$caption' WHERE id = '$id' AND
- owner_uid = " . $_SESSION["uid"]);
-
- /* Update filters that reference label being renamed */
-
- $old_caption = db_escape_string($old_caption);
-
- db_query($this->link, "UPDATE ttrss_filters SET
- action_param = '$caption' WHERE action_param = '$old_caption'
- AND action_id = 7
- AND owner_uid = " . $_SESSION["uid"]);
-
- print $_REQUEST["value"];
- } else {
- print $old_caption;
- }
- } else {
- print $old_caption;
- }
- }
-
- db_query($this->link, "COMMIT");
-
- return;
- }
-
- function remove() {
-
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
-
- foreach ($ids as $id) {
- label_remove($this->link, $id, $_SESSION["uid"]);
- }
-
- }
-
- function add() {
- $caption = db_escape_string($_REQUEST["caption"]);
- $output = db_escape_string($_REQUEST["output"]);
-
- if ($caption) {
-
- if (label_create($this->link, $caption)) {
- if (!$output) {
- print T_sprintf("Created label %s ", htmlspecialchars($caption));
- }
- }
-
- if ($output == "select") {
- header("Content-Type: text/xml");
-
- print "";
-
- print_label_select($this->link, "select_label",
- $caption, "");
-
- print " ";
- }
- }
-
- return;
- }
-
- function index() {
-
- $sort = db_escape_string($_REQUEST["sort"]);
-
- if (!$sort || $sort == "undefined") {
- $sort = "caption";
- }
-
- $label_search = db_escape_string($_REQUEST["search"]);
-
- if (array_key_exists("search", $_REQUEST)) {
- $_SESSION["prefs_label_search"] = $label_search;
- } else {
- $label_search = $_SESSION["prefs_label_search"];
- }
-
- print "";
- print ""; #pane
- print "
";
-
- print "
-
".
- __("Loading, please wait...")."
";
-
- print "
-
-
-
-
-
-
-
";
-
- print "
"; #pane
- print "
"; #container
-
- }
-}
-
-?>
diff --git a/classes/pref_prefs.php b/classes/pref_prefs.php
deleted file mode 100644
index 60d24110..00000000
--- a/classes/pref_prefs.php
+++ /dev/null
@@ -1,499 +0,0 @@
-link);
-
- if (method_exists($authenticator, "change_password")) {
- print $authenticator->change_password($_SESSION["uid"], $old_pw, $new_pw);
- } else {
- print "ERROR: ".__("Function not supported by authentication module.");
- }
- }
-
- 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]);
-
- if ($pref_name == 'DIGEST_PREFERRED_TIME') {
- if (get_pref($this->link, 'DIGEST_PREFERRED_TIME') != $value) {
-
- db_query($this->link, "UPDATE ttrss_users SET
- last_digest_sent = NULL WHERE id = " . $_SESSION['uid']);
-
- }
- }
-
- 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", "DIGEST_PREFERRED_TIME");
-
-
- $_SESSION["prefs_op_result"] = "";
-
- print "";
- print "
";
-
- print "
";
-
- if ($_SESSION["auth_module"]) {
- $module_class = "auth_" . $_SESSION["auth_module"];
- $authenticator = new $module_class($this->link);
- } else {
- $authenticator = false;
- }
-
- if ($authenticator && method_exists($authenticator, "change_password")) {
-
- $result = db_query($this->link, "SELECT id FROM ttrss_users
- WHERE id = ".$_SESSION["uid"]." AND pwd_hash
- = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'");
-
- if (db_num_rows($result) != 0) {
- print format_warning(__("Your password is at default value, please change it."), "default_pass_warning");
- }
-
- print "
";
-
- }
-
- print "
"; #pane
-
- print "
";
-
- print "
";
-
- print "
"; #pane
- print "
"; #container
- }
-}
-?>
diff --git a/classes/pref_users.php b/classes/pref_users.php
deleted file mode 100644
index 8f8f819f..00000000
--- a/classes/pref_users.php
+++ /dev/null
@@ -1,494 +0,0 @@
-";
-
- $uid = sprintf("%d", $_REQUEST["id"]);
-
- print "".__('User details')." ";
-
- print "link, "SELECT login,
- ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login,
- access_level,
- (SELECT COUNT(int_id) FROM ttrss_user_entries
- WHERE owner_uid = id) AS stored_articles,
- ".SUBSTRING_FOR_DATE."(created,1,16) AS created
- FROM ttrss_users
- WHERE id = '$uid'");
-
- if (db_num_rows($result) == 0) {
- print "".__('User not found')." ";
- return;
- }
-
- // print "User Details ";
-
- $login = db_fetch_result($result, 0, "login");
-
- print "";
-
- $last_login = make_local_datetime($this->link,
- db_fetch_result($result, 0, "last_login"), true);
-
- $created = make_local_datetime($this->link,
- db_fetch_result($result, 0, "created"), true);
-
- $access_level = db_fetch_result($result, 0, "access_level");
- $stored_articles = db_fetch_result($result, 0, "stored_articles");
-
- print "".__('Registered')." $created ";
- print "".__('Last logged in')." $last_login ";
-
- $result = db_query($this->link, "SELECT COUNT(id) as num_feeds FROM ttrss_feeds
- WHERE owner_uid = '$uid'");
-
- $num_feeds = db_fetch_result($result, 0, "num_feeds");
-
- print "".__('Subscribed feeds count')." $num_feeds ";
-
- print "
";
-
- print "".__('Subscribed feeds')." ";
-
- $result = db_query($this->link, "SELECT id,title,site_url FROM ttrss_feeds
- WHERE owner_uid = '$uid' ORDER BY title");
-
- print "";
-
- $row_class = "odd";
-
- while ($line = db_fetch_assoc($result)) {
-
- $icon_file = ICONS_URL."/".$line["id"].".ico";
-
- if (file_exists($icon_file) && filesize($icon_file) > 0) {
- $feed_icon = " ";
- } else {
- $feed_icon = " ";
- }
-
- print "$feed_icon ".$line["title"]." ";
-
- $row_class = $row_class == "even" ? "odd" : "even";
-
- }
-
- if (db_num_rows($result) < $num_feeds) {
- // FIXME - add link to show ALL subscribed feeds here somewhere
- print " ... ";
- }
-
- print " ";
-
- print "
- ".__("Close this window").
- "
";
-
- print "]]> ";
-
- return;
- }
-
- function edit() {
- global $access_level_names;
-
- header("Content-Type: text/xml");
-
- $id = db_escape_string($_REQUEST["id"]);
-
- print "";
- print "".__('User Editor')." ";
- print "";
-
- print " ";
- print " ";
- print " ";
-
- $result = db_query($this->link, "SELECT * FROM ttrss_users WHERE id = '$id'");
-
- $login = db_fetch_result($result, 0, "login");
- $access_level = db_fetch_result($result, 0, "access_level");
- $email = db_fetch_result($result, 0, "email");
-
- $sel_disabled = ($id == $_SESSION["uid"]) ? "disabled" : "";
-
- print "".__("User")."
";
- print "";
-
- if ($sel_disabled) {
- print " ";
- print " ";
- } else {
- print " ";
- }
-
- print "
";
-
- print "".__("Authentication")."
";
- print "";
-
- print __('Access level: ') . " ";
-
- if (!$sel_disabled) {
- print_select_hash("access_level", $access_level, $access_level_names,
- $sel_disabled);
- } else {
- print_select_hash("", $access_level, $access_level_names,
- $sel_disabled);
- print " ";
- }
-
- print " ";
-
- print __('Change password to') .
- " ";
-
- print "
";
-
- print "".__("Options")."
";
- print "";
-
- print __('E-mail: ').
- " ";
-
- print "
";
-
- print "";
-
- print "";
-
- print "
- ".
- __('Save')."
- ".
- __('Cancel')."
";
-
- print "]]> ";
-
- return;
- }
-
- function editSave() {
- $login = db_escape_string(trim($_REQUEST["login"]));
- $uid = db_escape_string($_REQUEST["id"]);
- $access_level = (int) $_REQUEST["access_level"];
- $email = db_escape_string(trim($_REQUEST["email"]));
- $password = db_escape_string(trim($_REQUEST["password"]));
-
- if ($password) {
- $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $pwd_hash = encrypt_password($password, $salt, true);
- $pass_query_part = "pwd_hash = '$pwd_hash', salt = '$salt',";
- } else {
- $pass_query_part = "";
- }
-
- db_query($this->link, "UPDATE ttrss_users SET $pass_query_part login = '$login',
- access_level = '$access_level', email = '$email' WHERE id = '$uid'");
-
- }
-
- function remove() {
- $ids = split(",", db_escape_string($_REQUEST["ids"]));
-
- foreach ($ids as $id) {
- if ($id != $_SESSION["uid"] && $id != 1) {
- db_query($this->link, "DELETE FROM ttrss_tags WHERE owner_uid = '$id'");
- db_query($this->link, "DELETE FROM ttrss_feeds WHERE owner_uid = '$id'");
- db_query($this->link, "DELETE FROM ttrss_users WHERE id = '$id'");
- }
- }
- }
-
- function add() {
-
- $login = db_escape_string(trim($_REQUEST["login"]));
- $tmp_user_pwd = make_password(8);
- $salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $pwd_hash = encrypt_password($tmp_user_pwd, $salt, true);
-
- $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
- login = '$login'");
-
- if (db_num_rows($result) == 0) {
-
- db_query($this->link, "INSERT INTO ttrss_users
- (login,pwd_hash,access_level,last_login,created, salt)
- VALUES ('$login', '$pwd_hash', 0, null, NOW(), '$salt')");
-
-
- $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE
- login = '$login' AND pwd_hash = '$pwd_hash'");
-
- if (db_num_rows($result) == 1) {
-
- $new_uid = db_fetch_result($result, 0, "id");
-
- print format_notice(T_sprintf("Added user %s with password %s ",
- $login, $tmp_user_pwd));
-
- initialize_user($this->link, $new_uid);
-
- } else {
-
- print format_warning(T_sprintf("Could not create user %s ", $login));
-
- }
- } else {
- print format_warning(T_sprintf("User %s already exists.", $login));
- }
- }
-
- function resetPass() {
-
- $uid = db_escape_string($_REQUEST["id"]);
-
- $result = db_query($this->link, "SELECT login,email
- FROM ttrss_users WHERE id = '$uid'");
-
- $login = db_fetch_result($result, 0, "login");
- $email = db_fetch_result($result, 0, "email");
- $salt = db_fetch_result($result, 0, "salt");
-
- $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $tmp_user_pwd = make_password(8);
-
- $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
-
- db_query($this->link, "UPDATE ttrss_users SET pwd_hash = '$pwd_hash', salt = '$new_salt'
- WHERE id = '$uid'");
-
- print T_sprintf("Changed password of user %s
- to %s ", $login, $tmp_user_pwd);
-
- require_once 'lib/phpmailer/class.phpmailer.php';
-
- if ($email) {
- print " ";
- print T_sprintf("Notifying %s .", $email);
-
- require_once "lib/MiniTemplator.class.php";
-
- $tpl = new MiniTemplator;
-
- $tpl->readTemplateFromFile("templates/resetpass_template.txt");
-
- $tpl->setVariable('LOGIN', $login);
- $tpl->setVariable('NEWPASS', $tmp_user_pwd);
-
- $tpl->addBlock('message');
-
- $message = "";
-
- $tpl->generateOutputToString($message);
-
- $mail = new PHPMailer();
-
- $mail->PluginDir = "lib/phpmailer/";
- $mail->SetLanguage("en", "lib/phpmailer/language/");
-
- $mail->CharSet = "UTF-8";
-
- $mail->From = SMTP_FROM_ADDRESS;
- $mail->FromName = SMTP_FROM_NAME;
- $mail->AddAddress($email, $login);
-
- if (SMTP_HOST) {
- $mail->Host = SMTP_HOST;
- $mail->Mailer = "smtp";
- $mail->SMTPAuth = SMTP_LOGIN != '';
- $mail->Username = SMTP_LOGIN;
- $mail->Password = SMTP_PASSWORD;
- }
-
- $mail->IsHTML(false);
- $mail->Subject = __("[tt-rss] Password change notification");
- $mail->Body = $message;
-
- $rc = $mail->Send();
-
- if (!$rc) print_error($mail->ErrorInfo);
- }
-
- print "";
- }
-
- function index() {
-
- global $access_level_names;
-
- print "";
- print ""; #pane
- print "
";
-
- print "
";
-
- if ($user_search) {
-
- $user_search = split(" ", $user_search);
- $tokens = array();
-
- foreach ($user_search as $token) {
- $token = trim($token);
- array_push($tokens, "(UPPER(login) LIKE UPPER('%$token%'))");
- }
-
- $user_search_query = "(" . join($tokens, " AND ") . ") AND ";
-
- } else {
- $user_search_query = "";
- }
-
- $result = db_query($this->link, "SELECT
- id,login,access_level,email,
- ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login,
- ".SUBSTRING_FOR_DATE."(created,1,16) as created
- FROM
- ttrss_users
- WHERE
- $user_search_query
- id > 0
- ORDER BY $sort");
-
- if (db_num_rows($result) > 0) {
-
- print "
";
-
- } else {
- print "
";
- if (!$user_search) {
- print_warning(__('No users defined.'));
- } else {
- print_warning(__('No matching users found.'));
- }
- print "
";
-
- }
-
- print "
"; #pane
- print "
"; #container
-
- }
-
- }
-?>
diff --git a/classes/protected_handler.php b/classes/protected_handler.php
deleted file mode 100644
index 5d8d690c..00000000
--- a/classes/protected_handler.php
+++ /dev/null
@@ -1,8 +0,0 @@
-
diff --git a/classes/public_handler.php b/classes/public_handler.php
deleted file mode 100644
index 5b7b523b..00000000
--- a/classes/public_handler.php
+++ /dev/null
@@ -1,310 +0,0 @@
-link, "SORT_HEADLINES_BY_FEED_DATE", $owner_uid)) {
- $date_sort_field = "updated";
- } else {
- $date_sort_field = "date_entered";
- }
-
- $qfh_ret = queryFeedHeadlines($this->link, $feed,
- $limit, $view_mode, $is_cat, $search, $search_mode,
- $match_on, "$date_sort_field DESC", 0, $owner_uid);
-
- $result = $qfh_ret[0];
- $feed_title = htmlspecialchars($qfh_ret[1]);
- $feed_site_url = $qfh_ret[2];
- $last_error = $qfh_ret[3];
-
- $feed_self_url = get_self_url_prefix() .
- "/public.php?op=rss&id=-2&key=" .
- get_feed_access_key($this->link, -2, false, $owner_uid);
-
- if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
-
- $tpl = new MiniTemplator;
-
- $tpl->readTemplateFromFile("templates/generated_feed.txt");
-
- $tpl->setVariable('FEED_TITLE', $feed_title, true);
- $tpl->setVariable('VERSION', VERSION, true);
- $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
-
- if (PUBSUBHUBBUB_HUB && $feed == -2) {
- $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB), true);
- $tpl->addBlock('feed_hub');
- }
-
- $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()), true);
-
- while ($line = db_fetch_assoc($result)) {
- $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']), true);
- $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']), true);
- $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']), true);
- $tpl->setVariable('ARTICLE_EXCERPT',
- truncate_string(strip_tags($line["content_preview"]), 100, '...'), true);
-
- $content = sanitize($this->link, $line["content_preview"], false, $owner_uid);
-
- if ($line['note']) {
- $content = "Article note: " . $line['note'] . "
" .
- $content;
- }
-
- $tpl->setVariable('ARTICLE_CONTENT', $content, true);
-
- $tpl->setVariable('ARTICLE_UPDATED_ATOM',
- date('c', strtotime($line["updated"])), true);
- $tpl->setVariable('ARTICLE_UPDATED_RFC822',
- date(DATE_RFC822, strtotime($line["updated"])), true);
-
- $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']), true);
-
- $tags = get_article_tags($this->link, $line["id"], $owner_uid);
-
- foreach ($tags as $tag) {
- $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag), true);
- $tpl->addBlock('category');
- }
-
- $enclosures = get_article_enclosures($this->link, $line["id"]);
-
- foreach ($enclosures as $e) {
- $type = htmlspecialchars($e['content_type']);
- $url = htmlspecialchars($e['content_url']);
- $length = $e['duration'];
-
- $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
- $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
- $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length, true);
-
- $tpl->addBlock('enclosure');
- }
-
- $tpl->addBlock('entry');
- }
-
- $tmp = "";
-
- $tpl->addBlock('feed');
- $tpl->generateOutputToString($tmp);
-
- print $tmp;
- }
-
- function getUnread() {
- $login = db_escape_string($_REQUEST["login"]);
- $fresh = $_REQUEST["fresh"] == "1";
-
- $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE login = '$login'");
-
- if (db_num_rows($result) == 1) {
- $uid = db_fetch_result($result, 0, "id");
-
- print getGlobalUnread($this->link, $uid);
-
- if ($fresh) {
- print ";";
- print getFeedArticles($this->link, -3, false, true, $uid);
- }
-
- } else {
- print "-1;User not found";
- }
-
- }
-
- function getProfiles() {
- $login = db_escape_string($_REQUEST["login"]);
- $password = db_escape_string($_REQUEST["password"]);
-
- if (authenticate_user($this->link, $login, $password)) {
- $result = db_query($this->link, "SELECT * FROM ttrss_settings_profiles
- WHERE owner_uid = " . $_SESSION["uid"] . " ORDER BY title");
-
- print "";
-
- print "" . __("Default profile") . " ";
-
- while ($line = db_fetch_assoc($result)) {
- $id = $line["id"];
- $title = $line["title"];
-
- print "$title ";
- }
-
- print " ";
-
- $_SESSION = array();
- }
- }
-
- function pubsub() {
- $mode = db_escape_string($_REQUEST['hub_mode']);
- $feed_id = (int) db_escape_string($_REQUEST['id']);
- $feed_url = db_escape_string($_REQUEST['hub_topic']);
-
- if (!PUBSUBHUBBUB_ENABLED) {
- header('HTTP/1.0 404 Not Found');
- echo "404 Not found";
- return;
- }
-
- // TODO: implement hub_verifytoken checking
-
- $result = db_query($this->link, "SELECT feed_url FROM ttrss_feeds
- WHERE id = '$feed_id'");
-
- if (db_num_rows($result) != 0) {
-
- $check_feed_url = db_fetch_result($result, 0, "feed_url");
-
- if ($check_feed_url && ($check_feed_url == $feed_url || !$feed_url)) {
- if ($mode == "subscribe") {
-
- db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 2
- WHERE id = '$feed_id'");
-
- print $_REQUEST['hub_challenge'];
- return;
-
- } else if ($mode == "unsubscribe") {
-
- db_query($this->link, "UPDATE ttrss_feeds SET pubsub_state = 0
- WHERE id = '$feed_id'");
-
- print $_REQUEST['hub_challenge'];
- return;
-
- } else if (!$mode) {
-
- // Received update ping, schedule feed update.
- //update_rss_feed($this->link, $feed_id, true, true);
-
- db_query($this->link, "UPDATE ttrss_feeds SET
- last_update_started = '1970-01-01',
- last_updated = '1970-01-01' WHERE id = '$feed_id'");
-
- }
- } else {
- header('HTTP/1.0 404 Not Found');
- echo "404 Not found";
- }
- } else {
- header('HTTP/1.0 404 Not Found');
- echo "404 Not found";
- }
-
- }
-
- function logout() {
- logout_user();
- header("Location: index.php");
- }
-
- function fbexport() {
-
- $access_key = db_escape_string($_POST["key"]);
-
- // TODO: rate limit checking using last_connected
- $result = db_query($this->link, "SELECT id FROM ttrss_linked_instances
- WHERE access_key = '$access_key'");
-
- if (db_num_rows($result) == 1) {
-
- $instance_id = db_fetch_result($result, 0, "id");
-
- $result = db_query($this->link, "SELECT feed_url, site_url, title, subscribers
- FROM ttrss_feedbrowser_cache ORDER BY subscribers DESC LIMIT 100");
-
- $feeds = array();
-
- while ($line = db_fetch_assoc($result)) {
- array_push($feeds, $line);
- }
-
- db_query($this->link, "UPDATE ttrss_linked_instances SET
- last_status_in = 1 WHERE id = '$instance_id'");
-
- print json_encode(array("feeds" => $feeds));
- } else {
- print json_encode(array("error" => array("code" => 6)));
- }
- }
-
- function share() {
- $uuid = db_escape_string($_REQUEST["key"]);
-
- $result = db_query($this->link, "SELECT ref_id, owner_uid FROM ttrss_user_entries WHERE
- uuid = '$uuid'");
-
- if (db_num_rows($result) != 0) {
- header("Content-Type: text/html");
-
- $id = db_fetch_result($result, 0, "ref_id");
- $owner_uid = db_fetch_result($result, 0, "owner_uid");
-
- $article = format_article($this->link, $id, false, true, $owner_uid);
-
- print_r($article['content']);
-
- } else {
- print "Article not found.";
- }
-
- }
-
- function rss() {
- header("Content-Type: text/xml; charset=utf-8");
-
- $feed = db_escape_string($_REQUEST["id"]);
- $key = db_escape_string($_REQUEST["key"]);
- $is_cat = $_REQUEST["is_cat"] != false;
- $limit = (int)db_escape_string($_REQUEST["limit"]);
-
- $search = db_escape_string($_REQUEST["q"]);
- $match_on = db_escape_string($_REQUEST["m"]);
- $search_mode = db_escape_string($_REQUEST["smode"]);
- $view_mode = db_escape_string($_REQUEST["view-mode"]);
-
- if (SINGLE_USER_MODE) {
- authenticate_user($this->link, "admin", null);
- }
-
- $owner_id = false;
-
- if ($key) {
- $result = db_query($this->link, "SELECT owner_uid FROM
- ttrss_access_keys WHERE access_key = '$key' AND feed_id = '$feed'");
-
- if (db_num_rows($result) == 1)
- $owner_id = db_fetch_result($result, 0, "owner_uid");
- }
-
- if ($owner_id) {
- $this->generate_syndicated_feed($owner_id, $feed, $is_cat, $limit,
- $search, $search_mode, $match_on, $view_mode);
- } else {
- header('HTTP/1.1 403 Forbidden');
- }
- }
-
- function globalUpdateFeeds() {
- include "rssfuncs.php";
- // Update all feeds needing a update.
- update_daemon_common($this->link, 0, true, false);
- }
-}
-?>
diff --git a/classes/rpc.php b/classes/rpc.php
index bf693d2a..d9caae4d 100644
--- a/classes/rpc.php
+++ b/classes/rpc.php
@@ -1,5 +1,5 @@
link, 'images/art-share.png')."\"
- class='tagsPic' style=\"cursor : pointer\"
- onclick=\"shareArticle(".$line['int_id'].")\"
- title='".__('Share by URL')."'>";
- }
-
- function shareArticle() {
- $param = db_escape_string($_REQUEST['param']);
-
- $result = db_query($this->link, "SELECT uuid, ref_id FROM ttrss_user_entries WHERE int_id = '$param'
- AND owner_uid = " . $_SESSION['uid']);
-
- if (db_num_rows($result) == 0) {
- print "Article not found.";
- } else {
-
- $uuid = db_fetch_result($result, 0, "uuid");
- $ref_id = db_fetch_result($result, 0, "ref_id");
-
- if (!$uuid) {
- $uuid = db_escape_string(sha1(uniqid(rand(), true)));
- db_query($this->link, "UPDATE ttrss_user_entries SET uuid = '$uuid' WHERE int_id = '$param'
- AND owner_uid = " . $_SESSION['uid']);
- }
-
- print __("You can share this article by the following unique URL:");
-
- $url_path = get_self_url_prefix();
- $url_path .= "/public.php?op=share&key=$uuid";
-
- print "";
-
- /* if (!label_find_id($this->link, __('Shared'), $_SESSION["uid"]))
- label_create($this->link, __('Shared'), $_SESSION["uid"]);
-
- label_add_article($this->link, $ref_id, __('Shared'), $_SESSION['uid']); */
- }
-
- print "";
-
- print "".
- __('Close this window')." ";
-
- print "
";
- }
-
-
-}
-?>
diff --git a/classes/tweet_button.php b/classes/tweet_button.php
deleted file mode 100644
index 470bc63a..00000000
--- a/classes/tweet_button.php
+++ /dev/null
@@ -1,31 +0,0 @@
-link, 'images/art-tweet.png')."\"
- class='tagsPic' style=\"cursor : pointer\"
- onclick=\"tweetArticle($article_id)\"
- title='".__('Share on Twitter')."'>";
-
- return $rv;
- }
-
- 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));
- }
-
-
-}
-?>
diff --git a/include/functions.php b/include/functions.php
index 702843c1..ac07974e 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -3,7 +3,10 @@
define('SCHEMA_VERSION', 94);
function __autoload($class) {
- $file = dirname(__FILE__)."/../classes/".strtolower(basename($class)).".php";
+ $class_file = str_replace("_", "/", strtolower(basename($class)));
+
+ $file = dirname(__FILE__)."/../classes/$class_file.php";
+
if (file_exists($file)) {
require $file;
}
@@ -3194,6 +3197,7 @@
}
function format_article($link, $id, $mark_as_read = true, $zoom_mode = false, $owner_uid = false) {
+ global $plugins;
if (!$owner_uid) $owner_uid = $_SESSION["uid"];
@@ -3256,6 +3260,8 @@
$line = db_fetch_assoc($result);
+ $plugins->hook('article_before', $line);
+
if ($line["icon_url"]) {
$feed_icon = " ";
} else {
@@ -3359,7 +3365,7 @@
$button_plugins = explode(",", ARTICLE_BUTTON_PLUGINS);
foreach ($button_plugins as $p) {
- $pclass = trim("${p}_button");
+ $pclass = trim("button_${p}");
if (class_exists($pclass)) {
$plugin = new $pclass($link);
@@ -3468,6 +3474,8 @@
$rv['content'] .= "