summaryrefslogtreecommitdiff
path: root/classes/pref/feeds.php
diff options
context:
space:
mode:
Diffstat (limited to 'classes/pref/feeds.php')
-rwxr-xr-xclasses/pref/feeds.php253
1 files changed, 107 insertions, 146 deletions
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index 3b4afab26..788104d38 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -1,5 +1,10 @@
<?php
class Pref_Feeds extends Handler_Protected {
+ const E_ICON_FILE_TOO_LARGE = 'E_ICON_FILE_TOO_LARGE';
+ const E_ICON_RENAME_FAILED = 'E_ICON_RENAME_FAILED';
+ const E_ICON_UPLOAD_FAILED = 'E_ICON_UPLOAD_FAILED';
+ const E_ICON_UPLOAD_SUCCESS = 'E_ICON_UPLOAD_SUCCESS';
+
function csrf_ignore($method) {
$csrf_ignored = array("index", "getfeedtree", "savefeedorder");
@@ -22,14 +27,16 @@ class Pref_Feeds extends Handler_Protected {
return $rv;
}
- function renamecat() {
+ function renameCat() {
+ $cat = ORM::for_table("ttrss_feed_categories")
+ ->where("owner_uid", $_SESSION["uid"])
+ ->find_one($_REQUEST['id']);
+
$title = clean($_REQUEST['title']);
- $id = clean($_REQUEST['id']);
- if ($title) {
- $sth = $this->pdo->prepare("UPDATE ttrss_feed_categories SET
- title = ? WHERE id = ? AND owner_uid = ?");
- $sth->execute([$title, $id, $_SESSION['uid']]);
+ if ($cat && $title) {
+ $cat->title = $title;
+ $cat->save();
}
}
@@ -433,78 +440,67 @@ class Pref_Feeds extends Handler_Protected {
}
}
- function removeicon() {
- $feed_id = clean($_REQUEST["feed_id"]);
-
- $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
- WHERE id = ? AND owner_uid = ?");
- $sth->execute([$feed_id, $_SESSION['uid']]);
+ function removeIcon() {
+ $feed_id = (int) $_REQUEST["feed_id"];
+ $icon_file = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
- if ($row = $sth->fetch()) {
- @unlink(Config::get(Config::ICONS_DIR) . "/$feed_id.ico");
+ $feed = ORM::for_table('ttrss_feeds')
+ ->where('owner_uid', $_SESSION['uid'])
+ ->find_one($feed_id);
- $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL, favicon_last_checked = '1970-01-01'
- where id = ?");
- $sth->execute([$feed_id]);
+ if ($feed && file_exists($icon_file)) {
+ if (unlink($icon_file)) {
+ $feed->set([
+ 'favicon_avg_color' => null,
+ 'favicon_last_checked' => '1970-01-01',
+ 'favicon_is_custom' => false,
+ ]);
+ $feed->save();
+ }
}
}
- function uploadicon() {
- header("Content-type: text/html");
+ function uploadIcon() {
+ $feed_id = (int) $_REQUEST['feed_id'];
+ $tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon');
- if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
- $tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon');
+ // default value
+ $rc = self::E_ICON_UPLOAD_FAILED;
- if (!$tmp_file)
- return;
+ $feed = ORM::for_table('ttrss_feeds')
+ ->where('owner_uid', $_SESSION['uid'])
+ ->find_one($feed_id);
- $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file);
+ if ($feed && $tmp_file && move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file)) {
+ if (filesize($tmp_file) < Config::get(Config::MAX_FAVICON_FILE_SIZE)) {
- if (!$result) {
- return;
- }
- } else {
- return;
- }
+ $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
- $icon_file = $tmp_file;
- $feed_id = clean($_REQUEST["feed_id"]);
- $rc = 2; // failed
+ if (file_exists($new_filename)) unlink($new_filename);
+ if (rename($tmp_file, $new_filename)) {
+ chmod($new_filename, 0644);
- if ($icon_file && is_file($icon_file) && $feed_id) {
- if (filesize($icon_file) < 65535) {
+ $feed->set([
+ 'favicon_avg_color' => null,
+ 'favicon_is_custom' => true,
+ ]);
- $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
- WHERE id = ? AND owner_uid = ?");
- $sth->execute([$feed_id, $_SESSION['uid']]);
-
- if ($row = $sth->fetch()) {
- $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
-
- if (file_exists($new_filename)) unlink($new_filename);
-
- if (rename($icon_file, $new_filename)) {
- chmod($new_filename, 644);
-
- $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET
- favicon_avg_color = ''
- WHERE id = ?");
- $sth->execute([$feed_id]);
+ if ($feed->save()) {
+ $rc = self::E_ICON_UPLOAD_SUCCESS;
+ }
- $rc = Feeds::_get_icon($feed_id);
+ } else {
+ $rc = self::E_ICON_RENAME_FAILED;
}
- }
} else {
- $rc = 1;
+ $rc = self::E_ICON_FILE_TOO_LARGE;
}
}
- if ($icon_file && is_file($icon_file)) {
- unlink($icon_file);
- }
+ if (file_exists($tmp_file))
+ unlink($tmp_file);
- print $rc;
- return;
+ print json_encode(['rc' => $rc, 'icon_url' => Feeds::_get_icon($feed_id)]);
}
function editfeed() {
@@ -513,11 +509,11 @@ class Pref_Feeds extends Handler_Protected {
$feed_id = (int)clean($_REQUEST["id"]);
- $sth = $this->pdo->prepare("SELECT * FROM ttrss_feeds WHERE id = ? AND
- owner_uid = ?");
- $sth->execute([$feed_id, $_SESSION['uid']]);
+ $row = ORM::for_table('ttrss_feeds')
+ ->where("owner_uid", $_SESSION["uid"])
+ ->find_one($feed_id)->as_array();
- if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
+ if ($row) {
ob_start();
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, $feed_id);
@@ -694,7 +690,7 @@ class Pref_Feeds extends Handler_Protected {
$purge_intl = (int) clean($_POST["purge_interval"] ?? 0);
$feed_id = (int) clean($_POST["id"] ?? 0); /* editSave */
$feed_ids = explode(",", clean($_POST["ids"] ?? "")); /* batchEditSave */
- $cat_id = (int) clean($_POST["cat_id"]);
+ $cat_id = (int) clean($_POST["cat_id"] ?? 0);
$auth_login = clean($_POST["auth_login"]);
$auth_pass = clean($_POST["auth_pass"]);
$private = checkbox_to_sql_bool(clean($_POST["private"] ?? ""));
@@ -710,7 +706,7 @@ class Pref_Feeds extends Handler_Protected {
$mark_unread_on_update = checkbox_to_sql_bool(
clean($_POST["mark_unread_on_update"] ?? ""));
- $feed_language = clean($_POST["feed_language"]);
+ $feed_language = clean($_POST["feed_language"] ?? "");
if (!$batch) {
@@ -720,48 +716,32 @@ class Pref_Feeds extends Handler_Protected {
$reset_basic_info = $orig_feed_url != $feed_url; */
- $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET
- cat_id = :cat_id,
- title = :title,
- feed_url = :feed_url,
- site_url = :site_url,
- update_interval = :upd_intl,
- purge_interval = :purge_intl,
- auth_login = :auth_login,
- auth_pass = :auth_pass,
- auth_pass_encrypted = false,
- private = :private,
- cache_images = :cache_images,
- hide_images = :hide_images,
- include_in_digest = :include_in_digest,
- always_display_enclosures = :always_display_enclosures,
- mark_unread_on_update = :mark_unread_on_update,
- feed_language = :feed_language
- WHERE id = :id AND owner_uid = :uid");
-
- $sth->execute([":title" => $feed_title,
- ":cat_id" => $cat_id ? $cat_id : null,
- ":feed_url" => $feed_url,
- ":site_url" => $site_url,
- ":upd_intl" => $upd_intl,
- ":purge_intl" => $purge_intl,
- ":auth_login" => $auth_login,
- ":auth_pass" => $auth_pass,
- ":private" => (int)$private,
- ":cache_images" => (int)$cache_images,
- ":hide_images" => (int)$hide_images,
- ":include_in_digest" => (int)$include_in_digest,
- ":always_display_enclosures" => (int)$always_display_enclosures,
- ":mark_unread_on_update" => (int)$mark_unread_on_update,
- ":feed_language" => $feed_language,
- ":id" => $feed_id,
- ":uid" => $_SESSION['uid']]);
-
-/* if ($reset_basic_info) {
- RSSUtils::set_basic_feed_info($feed_id);
- } */
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, $feed_id);
+ $feed = ORM::for_table('ttrss_feeds')
+ ->where('owner_uid', $_SESSION['uid'])
+ ->find_one($feed_id);
+
+ if ($feed) {
+
+ $feed->title = $feed_title;
+ $feed->cat_id = $cat_id ? $cat_id : null;
+ $feed->feed_url = $feed_url;
+ $feed->site_url = $site_url;
+ $feed->update_interval = $upd_intl;
+ $feed->purge_interval = $purge_intl;
+ $feed->auth_login = $auth_login;
+ $feed->auth_pass = $auth_pass;
+ $feed->private = (int)$private;
+ $feed->cache_images = (int)$cache_images;
+ $feed->hide_images = (int)$hide_images;
+ $feed->feed_language = $feed_language;
+ $feed->include_in_digest = (int)$include_in_digest;
+ $feed->always_display_enclosures = (int)$always_display_enclosures;
+ $feed->mark_unread_on_update = (int)$mark_unread_on_update;
+
+ $feed->save();
+
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_SAVE_FEED, $feed_id);
+ }
} else {
$feed_data = array();
@@ -874,14 +854,14 @@ class Pref_Feeds extends Handler_Protected {
function removeCat() {
$ids = explode(",", clean($_REQUEST["ids"]));
foreach ($ids as $id) {
- $this->remove_feed_category($id, $_SESSION["uid"]);
+ Feeds::_remove_cat((int)$id, $_SESSION["uid"]);
}
}
function addCat() {
$feed_cat = clean($_REQUEST["cat"]);
- Feeds::_add_cat($feed_cat);
+ Feeds::_add_cat($feed_cat, $_SESSION['uid']);
}
function importOpml() {
@@ -1003,10 +983,6 @@ class Pref_Feeds extends Handler_Protected {
private function index_opml() {
?>
- <h3><?= __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") ?></h3>
-
- <?php print_notice("Only main settings profile can be migrated using OPML.") ?>
-
<form id='opml_import_form' method='post' enctype='multipart/form-data'>
<label class='dijitButton'><?= __("Choose file...") ?>
<input style='display : none' id='opml_file' name='opml_file' type='file'>
@@ -1015,20 +991,24 @@ class Pref_Feeds extends Handler_Protected {
<input type='hidden' name='csrf_token' value="<?= $_SESSION['csrf_token'] ?>">
<input type='hidden' name='method' value='importOpml'>
<button dojoType='dijit.form.Button' class='alt-primary' onclick="return Helpers.OPML.import()" type="submit">
+ <?= \Controls\icon("file_upload") ?>
<?= __('Import OPML') ?>
</button>
</form>
<hr/>
+ <?php print_notice("Only main settings profile can be migrated using OPML.") ?>
+
<form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>
<button dojoType='dijit.form.Button' onclick='Helpers.OPML.export()'>
+ <?= \Controls\icon("file_download") ?>
<?= __('Export OPML') ?>
</button>
<label class='checkbox'>
<?= \Controls\checkbox_tag("include_settings", true, "1") ?>
- <?= __("Include settings") ?>
+ <?= __("Include tt-rss settings") ?>
</label>
</form>
@@ -1036,12 +1016,10 @@ class Pref_Feeds extends Handler_Protected {
<h2><?= __("Published OPML") ?></h2>
- <p>
- <?= __('Your OPML can be published publicly and can be subscribed by anyone who knows the URL below.') ?>
- <?= __("Published OPML does not include your Tiny Tiny RSS settings, feeds that require authentication or feeds hidden from Popular feeds.") ?>
- </p>
+ <?= format_notice("Your OPML can be published and then subscribed by anyone who knows the URL below. This won't include your settings nor authenticated feeds.") ?>
<button dojoType='dijit.form.Button' class='alt-primary' onclick="return Helpers.OPML.publish()">
+ <?= \Controls\icon("share") ?>
<?= __('Display published OPML URL') ?>
</button>
@@ -1052,14 +1030,16 @@ class Pref_Feeds extends Handler_Protected {
private function index_shared() {
?>
- <h3><?= __('Published articles can be subscribed by anyone who knows the following URL:') ?></h3>
+ <?= format_notice('Published articles can be subscribed by anyone who knows the following URL:') ?></h3>
<button dojoType='dijit.form.Button' class='alt-primary'
onclick="CommonDialogs.generatedFeed(-2, false)">
+ <?= \Controls\icon('share') ?>
<?= __('Display URL') ?>
</button>
<button class='alt-danger' dojoType='dijit.form.Button' onclick='return Helpers.Feeds.clearFeedAccessKeys()'>
+ <?= \Controls\icon('delete') ?>
<?= __('Clear all generated URLs') ?>
</button>
@@ -1188,12 +1168,6 @@ class Pref_Feeds extends Handler_Protected {
print json_encode($rv);
}
- private function remove_feed_category($id, $owner_uid) {
- $sth = $this->pdo->prepare("DELETE FROM ttrss_feed_categories
- WHERE id = ? AND owner_uid = ?");
- $sth->execute([$id, $owner_uid]);
- }
-
static function remove_feed($id, $owner_uid) {
if (PluginHost::getInstance()->run_hooks_until(PluginHost::HOOK_UNSUBSCRIBE_FEED, true, $id, $owner_uid))
@@ -1273,12 +1247,16 @@ class Pref_Feeds extends Handler_Protected {
}
}
+ function clearKeys() {
+ return Feeds::_clear_access_keys($_SESSION['uid']);
+ }
+
function getOPMLKey() {
print json_encode(["link" => OPML::get_publish_url()]);
}
function regenOPMLKey() {
- $this->update_feed_access_key('OPML:Publish',
+ Feeds::_update_access_key('OPML:Publish',
false, $_SESSION["uid"]);
print json_encode(["link" => OPML::get_publish_url()]);
@@ -1288,17 +1266,17 @@ class Pref_Feeds extends Handler_Protected {
$feed_id = clean($_REQUEST['id']);
$is_cat = clean($_REQUEST['is_cat']);
- $new_key = $this->update_feed_access_key($feed_id, $is_cat, $_SESSION["uid"]);
+ $new_key = Feeds::_update_access_key($feed_id, $is_cat, $_SESSION["uid"]);
print json_encode(["link" => $new_key]);
}
- function getsharedurl() {
+ function getSharedURL() {
$feed_id = clean($_REQUEST['id']);
$is_cat = clean($_REQUEST['is_cat']) == "true";
$search = clean($_REQUEST['search']);
- $link = get_self_url_prefix() . "/public.php?" . http_build_query([
+ $link = Config::get_self_url() . "/public.php?" . http_build_query([
'op' => 'rss',
'id' => $feed_id,
'is_cat' => (int)$is_cat,
@@ -1312,23 +1290,6 @@ class Pref_Feeds extends Handler_Protected {
]);
}
- private function update_feed_access_key($feed_id, $is_cat, $owner_uid) {
-
- // clear old value and generate new one
- $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys
- WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?");
- $sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]);
-
- return Feeds::_get_access_key($feed_id, $is_cat, $owner_uid);
- }
-
- // Silent
- function clearKeys() {
- $sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE
- owner_uid = ?");
- $sth->execute([$_SESSION['uid']]);
- }
-
private function calculate_children_count($cat) {
$c = 0;