summaryrefslogtreecommitdiff
path: root/classes/pref
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-24 21:56:52 +0300
committerAndrew Dolgov <[email protected]>2021-02-24 21:56:52 +0300
commit93940d2a9f80d9e1dac49b5eb7db23230d31c5f6 (patch)
tree71016661f6017918d0934eb462bd9552018d557a /classes/pref
parent8b022c2bfb356d7dddaf334bc931d6dec77086fb (diff)
parent1adacd057230aea4ede29dab510385bf01cf99a3 (diff)
Merge branch 'master' of git.fakecake.org:fox/tt-rss into weblate-integration
Diffstat (limited to 'classes/pref')
-rwxr-xr-xclasses/pref/feeds.php1182
-rwxr-xr-xclasses/pref/filters.php642
-rw-r--r--classes/pref/labels.php190
-rw-r--r--classes/pref/prefs.php1140
-rw-r--r--classes/pref/system.php248
-rw-r--r--classes/pref/users.php446
6 files changed, 1504 insertions, 2344 deletions
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index 47e5689ec..086c52697 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -1,7 +1,7 @@
<?php
class Pref_Feeds extends Handler_Protected {
function csrf_ignore($method) {
- $csrf_ignored = array("index", "getfeedtree", "savefeedorder", "uploadicon");
+ $csrf_ignored = array("index", "getfeedtree", "savefeedorder");
return array_search($method, $csrf_ignored) !== false;
}
@@ -9,7 +9,7 @@ class Pref_Feeds extends Handler_Protected {
public static function get_ts_languages() {
$rv = [];
- if (DB_TYPE == "pgsql") {
+ if (Config::get(Config::DB_TYPE) == "pgsql") {
$dbh = Db::pdo();
$res = $dbh->query("SELECT cfgname FROM pg_ts_config");
@@ -22,11 +22,6 @@ class Pref_Feeds extends Handler_Protected {
return $rv;
}
- function batch_edit_cbox($elem, $label = false) {
- print "<input type=\"checkbox\" title=\"".__("Check to enable field")."\"
- onchange=\"App.dialogOf(this).toggleField(this, '$elem', '$label')\">";
- }
-
function renamecat() {
$title = clean($_REQUEST['title']);
$id = clean($_REQUEST['id']);
@@ -98,7 +93,7 @@ class Pref_Feeds extends Handler_Protected {
$feed['checkbox'] = false;
$feed['unread'] = -1;
$feed['error'] = $feed_line['last_error'];
- $feed['icon'] = Feeds::getFeedIcon($feed_line['id']);
+ $feed['icon'] = Feeds::_get_icon($feed_line['id']);
$feed['param'] = TimeHelper::make_local_datetime(
$feed_line['last_updated'], true);
$feed['updates_disabled'] = (int)($feed_line['update_interval'] < 0);
@@ -110,10 +105,10 @@ class Pref_Feeds extends Handler_Protected {
}
function getfeedtree() {
- print json_encode($this->makefeedtree());
+ print json_encode($this->_makefeedtree());
}
- function makefeedtree() {
+ function _makefeedtree() {
if (clean($_REQUEST['mode'] ?? 0) != 2)
$search = $_SESSION["prefs_feed_search"] ?? "";
@@ -266,7 +261,7 @@ class Pref_Feeds extends Handler_Protected {
$feed['name'] = $feed_line['title'];
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
- $feed['icon'] = Feeds::getFeedIcon($feed_line['id']);
+ $feed['icon'] = Feeds::_get_icon($feed_line['id']);
$feed['param'] = TimeHelper::make_local_datetime(
$feed_line['last_updated'], true);
$feed['unread'] = -1;
@@ -301,7 +296,7 @@ class Pref_Feeds extends Handler_Protected {
$feed['name'] = $feed_line['title'];
$feed['checkbox'] = false;
$feed['error'] = $feed_line['last_error'];
- $feed['icon'] = Feeds::getFeedIcon($feed_line['id']);
+ $feed['icon'] = Feeds::_get_icon($feed_line['id']);
$feed['param'] = TimeHelper::make_local_datetime(
$feed_line['last_updated'], true);
$feed['unread'] = -1;
@@ -446,7 +441,7 @@ class Pref_Feeds extends Handler_Protected {
$sth->execute([$feed_id, $_SESSION['uid']]);
if ($row = $sth->fetch()) {
- @unlink(ICONS_DIR . "/$feed_id.ico");
+ @unlink(Config::get(Config::ICONS_DIR) . "/$feed_id.ico");
$sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL, favicon_last_checked = '1970-01-01'
where id = ?");
@@ -458,10 +453,12 @@ class Pref_Feeds extends Handler_Protected {
header("Content-type: text/html");
if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
- $tmp_file = tempnam(CACHE_DIR . '/upload', 'icon');
+ $tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon');
- $result = move_uploaded_file($_FILES['icon_file']['tmp_name'],
- $tmp_file);
+ if (!$tmp_file)
+ return;
+
+ $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file);
if (!$result) {
return;
@@ -474,7 +471,7 @@ class Pref_Feeds extends Handler_Protected {
$feed_id = clean($_REQUEST["feed_id"]);
$rc = 2; // failed
- if (is_file($icon_file) && $feed_id) {
+ if ($icon_file && is_file($icon_file) && $feed_id) {
if (filesize($icon_file) < 65535) {
$sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
@@ -482,15 +479,19 @@ class Pref_Feeds extends Handler_Protected {
$sth->execute([$feed_id, $_SESSION['uid']]);
if ($row = $sth->fetch()) {
- @unlink(ICONS_DIR . "/$feed_id.ico");
- if (rename($icon_file, ICONS_DIR . "/$feed_id.ico")) {
+ $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]);
- $rc = 0;
+ $rc = Feeds::_get_icon($feed_id);
}
}
} else {
@@ -498,7 +499,9 @@ class Pref_Feeds extends Handler_Protected {
}
}
- if (is_file($icon_file)) @unlink($icon_file);
+ if ($icon_file && is_file($icon_file)) {
+ unlink($icon_file);
+ }
print $rc;
return;
@@ -508,131 +511,25 @@ class Pref_Feeds extends Handler_Protected {
global $purge_intervals;
global $update_intervals;
- $feed_id = clean($_REQUEST["id"]);
+ $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']]);
- if ($row = $sth->fetch()) {
- print '<div dojoType="dijit.layout.TabContainer" style="height : 450px">
- <div dojoType="dijit.layout.ContentPane" title="'.__('General').'">';
-
- $title = htmlspecialchars($row["title"]);
-
- print_hidden("id", "$feed_id");
- print_hidden("op", "pref-feeds");
- print_hidden("method", "editSave");
-
- print "<header>".__("Feed")."</header>";
- print "<section>";
-
- /* Title */
-
- print "<fieldset>";
-
- print "<input dojoType='dijit.form.ValidationTextBox' required='1'
- placeHolder=\"".__("Feed Title")."\"
- style='font-size : 16px; width: 500px' name='title' value=\"$title\">";
-
- print "</fieldset>";
-
- /* Feed URL */
-
- $feed_url = htmlspecialchars($row["feed_url"]);
-
- print "<fieldset>";
-
- print "<label>" . __('URL:') . "</label> ";
- print "<input dojoType='dijit.form.ValidationTextBox' required='1'
- placeHolder=\"".__("Feed URL")."\"
- regExp='^(http|https)://.*' style='width : 300px'
- name='feed_url' value=\"$feed_url\">";
-
- if (!empty($row["last_error"])) {
- print "&nbsp;<i class=\"material-icons\"
- title=\"".htmlspecialchars($row["last_error"])."\">error</i>";
- }
-
- print "</fieldset>";
-
- /* Category */
-
- if (get_pref('ENABLE_FEED_CATS')) {
-
- $cat_id = $row["cat_id"];
-
- print "<fieldset>";
-
- print "<label>" . __('Place in category:') . "</label> ";
-
- print_feed_cat_select("cat_id", $cat_id,
- 'dojoType="fox.form.Select"');
-
- print "</fieldset>";
- }
-
- /* Site URL */
-
- $site_url = htmlspecialchars($row["site_url"]);
-
- print "<fieldset>";
-
- print "<label>" . __('Site URL:') . "</label> ";
- print "<input dojoType='dijit.form.ValidationTextBox' required='1'
- placeHolder=\"".__("Site URL")."\"
- regExp='^(http|https)://.*' style='width : 300px'
- name='site_url' value=\"$site_url\">";
+ if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
- print "</fieldset>";
-
- /* FTS Stemming Language */
-
- if (DB_TYPE == "pgsql") {
- $feed_language = $row["feed_language"];
-
- if (!$feed_language)
- $feed_language = get_pref('DEFAULT_SEARCH_LANGUAGE');
-
- print "<fieldset>";
-
- print "<label>" . __('Language:') . "</label> ";
- print_select("feed_language", $feed_language, $this::get_ts_languages(),
- 'dojoType="fox.form.Select"');
-
- print "</fieldset>";
- }
-
- print "</section>";
-
- print "<header>".__("Update")."</header>";
- print "<section>";
-
- /* Update Interval */
-
- $update_interval = $row["update_interval"];
-
- print "<fieldset>";
+ ob_start();
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, $feed_id);
+ $plugin_data = trim((string)ob_get_contents());
+ ob_end_clean();
- print "<label>".__("Interval:")."</label> ";
+ $row["icon"] = Feeds::_get_icon($feed_id);
$local_update_intervals = $update_intervals;
$local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]);
- print_select_hash("update_interval", $update_interval, $local_update_intervals,
- 'dojoType="fox.form.Select"');
-
- print "</fieldset>";
-
- /* Purge intl */
-
- $purge_interval = $row["purge_interval"];
-
- print "<fieldset>";
-
- print "<label>" . __('Article purging:') . "</label> ";
-
- if (FORCE_ARTICLE_PURGE == 0) {
+ if (Config::get(Config::FORCE_ARTICLE_PURGE) == 0) {
$local_purge_intervals = $purge_intervals;
$default_purge_interval = get_pref("PURGE_OLD_DAYS");
@@ -642,343 +539,142 @@ class Pref_Feeds extends Handler_Protected {
$local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
} else {
- $purge_interval = FORCE_ARTICLE_PURGE;
+ $purge_interval = Config::get(Config::FORCE_ARTICLE_PURGE);
$local_purge_intervals = [ T_nsprintf('%d day', '%d days', $purge_interval, $purge_interval) ];
}
- print_select_hash("purge_interval", $purge_interval, $local_purge_intervals,
- 'dojoType="fox.form.Select" ' .
- ((FORCE_ARTICLE_PURGE == 0) ? "" : 'disabled="1"'));
-
- print "</fieldset>";
-
- print "</section>";
-
- $auth_login = htmlspecialchars($row["auth_login"]);
- $auth_pass = htmlspecialchars($row["auth_pass"]);
-
- $auth_enabled = $auth_login !== '' || $auth_pass !== '';
-
- $auth_style = $auth_enabled ? '' : 'display: none';
- print "<div id='feedEditDlg_loginContainer' style='$auth_style'>";
- print "<header>".__("Authentication")."</header>";
- print "<section>";
-
- print "<fieldset>";
-
- print "<input dojoType='dijit.form.TextBox' id='feedEditDlg_login'
- placeHolder='".__("Login")."'
- autocomplete='new-password'
- name='auth_login' value=\"$auth_login\">";
-
- print "</fieldset><fieldset>";
-
- print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass'
- autocomplete='new-password'
- placeHolder='".__("Password")."'
- value=\"$auth_pass\">";
-
- print "<div dojoType='dijit.Tooltip' connectId='feedEditDlg_login' position='below'>
- ".__('<b>Hint:</b> you need to fill in your login information if your feed requires authentication, except for Twitter feeds.')."
- </div>";
-
- print "</fieldset>";
-
- print "</section></div>";
-
- $auth_checked = $auth_enabled ? 'checked' : '';
- print "<label class='checkbox'>
- <input type='checkbox' $auth_checked name='need_auth' dojoType='dijit.form.CheckBox' id='feedEditDlg_loginCheck'
- onclick='App.displayIfChecked(this, \"feedEditDlg_loginContainer\")'>
- ".__('This feed requires authentication.')."</label>";
-
- print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Options').'">';
-
- print "<section class='narrow'>";
-
- $include_in_digest = $row["include_in_digest"];
-
- if ($include_in_digest) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print "<fieldset class='narrow'>";
-
- print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"include_in_digest\"
- name=\"include_in_digest\"
- $checked> ".__('Include in e-mail digest')."</label>";
-
- print "</fieldset>";
-
- $always_display_enclosures = $row["always_display_enclosures"];
-
- if ($always_display_enclosures) {
- $checked = "checked";
- } else {
- $checked = "";
- }
-
- print "<fieldset class='narrow'>";
-
- print "<label class='checkbox'><input dojoType=\"dijit.form.CheckBox\" type=\"checkbox\" id=\"always_display_enclosures\"
- name=\"always_display_enclosures\"
- $checked> ".__('Always display image attachments')."</label>";
-
- print "</fieldset>";
-
- $hide_images = $row["hide_images"];
-
- if ($hide_images) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print "<fieldset class='narrow'>";
-
- print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='hide_images'
- name='hide_images' $checked> ".__('Do not embed media')."</label>";
-
- print "</fieldset>";
-
- $cache_images = $row["cache_images"];
-
- if ($cache_images) {
- $checked = "checked=\"1\"";
- } else {
- $checked = "";
- }
-
- print "<fieldset class='narrow'>";
-
- print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='cache_images'
- name='cache_images' $checked> ". __('Cache media')."</label>";
-
- print "</fieldset>";
-
- $mark_unread_on_update = $row["mark_unread_on_update"];
-
- if ($mark_unread_on_update) {
- $checked = "checked";
- } else {
- $checked = "";
- }
-
- print "<fieldset class='narrow'>";
-
- print "<label class='checkbox'><input dojoType='dijit.form.CheckBox' type='checkbox' id='mark_unread_on_update'
- name='mark_unread_on_update' $checked> ".__('Mark updated articles as unread')."</label>";
-
- print "</fieldset>";
-
- print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Icon').'">';
-
- /* Icon */
-
- print "<img class='feedIcon feed-editor-icon' src=\"".Feeds::getFeedIcon($feed_id)."\">";
-
- print "<form onsubmit='return false;' id='feed_icon_upload_form'
- enctype='multipart/form-data' method='POST'>
- <label class='dijitButton'>".__("Choose file...")."
- <input style='display: none' id='icon_file' size='10' name='icon_file' type='file'>
- </label>
- <input type='hidden' name='op' value='pref-feeds'>
- <input type='hidden' name='csrf_token' value='".$_SESSION['csrf_token']."'>
- <input type='hidden' name='feed_id' value='$feed_id'>
- <input type='hidden' name='method' value='uploadicon'>
- <button dojoType='dijit.form.Button' onclick=\"return CommonDialogs.uploadFeedIcon();\"
- type='submit'>".__('Replace')."</button>
- <button class='alt-danger' dojoType='dijit.form.Button' onclick=\"return CommonDialogs.removeFeedIcon($feed_id);\"
- type='submit'>".__('Remove')."</button>
- </form>";
-
- print "</section>";
-
- print '</div><div dojoType="dijit.layout.ContentPane" title="'.__('Plugins').'">';
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_EDIT_FEED, $feed_id);
-
- print "</div></div>";
-
- $title = htmlspecialchars($title, ENT_QUOTES);
-
- print "<footer>
- <button style='float : left' class='alt-danger' dojoType='dijit.form.Button'
- onclick='App.dialogOf(this).unsubscribeFeed($feed_id, \"$title\")'>".
- __('Unsubscribe')."</button>
- <button dojoType='dijit.form.Button' class='alt-primary' type='submit'>".__('Save')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".__('Cancel')."</button>
- </footer>";
+ print json_encode([
+ "feed" => $row,
+ "cats" => [
+ "enabled" => get_pref('ENABLE_FEED_CATS'),
+ "select" => \Controls\select_feeds_cats("cat_id", $row["cat_id"]),
+ ],
+ "plugin_data" => $plugin_data,
+ "force_purge" => (int)Config::get(Config::FORCE_ARTICLE_PURGE),
+ "intervals" => [
+ "update" => $local_update_intervals,
+ "purge" => $local_purge_intervals,
+ ],
+ "lang" => [
+ "enabled" => Config::get(Config::DB_TYPE) == "pgsql",
+ "default" => get_pref('DEFAULT_SEARCH_LANGUAGE'),
+ "all" => $this::get_ts_languages(),
+ ]
+ ]);
}
}
+ private function _batch_toggle_checkbox($name) {
+ return \Controls\checkbox_tag("", false, "",
+ ["data-control-for" => $name, "title" => __("Check to enable field"), "onchange" => "App.dialogOf(this).toggleField(this)"]);
+ }
+
function editfeeds() {
global $purge_intervals;
global $update_intervals;
$feed_ids = clean($_REQUEST["ids"]);
- print_notice("Enable the options you wish to apply using checkboxes on the right:");
-
- print "<p>";
-
- print_hidden("ids", "$feed_ids");
- print_hidden("op", "pref-feeds");
- print_hidden("method", "batchEditSave");
-
- print "<header>".__("Feed")."</header>";
- print "<section>";
-
- /* Category */
-
- if (get_pref('ENABLE_FEED_CATS')) {
-
- print "<fieldset>";
-
- print "<label>" . __('Place in category:') . "</label> ";
-
- print_feed_cat_select("cat_id", false,
- 'disabled="1" dojoType="fox.form.Select"');
-
- $this->batch_edit_cbox("cat_id");
-
- print "</fieldset>";
- }
-
- /* FTS Stemming Language */
-
- if (DB_TYPE == "pgsql") {
- print "<fieldset>";
-
- print "<label>" . __('Language:') . "</label> ";
- print_select("feed_language", "", $this::get_ts_languages(),
- 'disabled="1" dojoType="fox.form.Select"');
-
- $this->batch_edit_cbox("feed_language");
-
- print "</fieldset>";
- }
-
- print "</section>";
-
- print "<header>".__("Update")."</header>";
- print "<section>";
-
- /* Update Interval */
-
- print "<fieldset>";
-
- print "<label>".__("Interval:")."</label> ";
-
$local_update_intervals = $update_intervals;
$local_update_intervals[0] .= sprintf(" (%s)", $update_intervals[get_pref("DEFAULT_UPDATE_INTERVAL")]);
- print_select_hash("update_interval", "", $local_update_intervals,
- 'disabled="1" dojoType="fox.form.Select"');
-
- $this->batch_edit_cbox("update_interval");
-
- print "</fieldset>";
-
- /* Purge intl */
-
- if (FORCE_ARTICLE_PURGE == 0) {
-
- print "<fieldset>";
-
- print "<label>" . __('Article purging:') . "</label> ";
-
- $local_purge_intervals = $purge_intervals;
- $default_purge_interval = get_pref("PURGE_OLD_DAYS");
-
- if ($default_purge_interval > 0)
- $local_purge_intervals[0] .= " " . T_sprintf("(%d days)", $default_purge_interval);
- else
- $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
-
- print_select_hash("purge_interval", "", $local_purge_intervals,
- 'disabled="1" dojoType="fox.form.Select"');
-
- $this->batch_edit_cbox("purge_interval");
-
- print "</fieldset>";
- }
-
- print "</section>";
- print "<header>".__("Authentication")."</header>";
- print "<section>";
-
- print "<fieldset>";
-
- print "<input dojoType='dijit.form.TextBox'
- placeHolder=\"".__("Login")."\" disabled='1'
- autocomplete='new-password'
- name='auth_login' value=''>";
-
- $this->batch_edit_cbox("auth_login");
-
- print "<input dojoType='dijit.form.TextBox' type='password' name='auth_pass'
- autocomplete='new-password'
- placeHolder=\"".__("Password")."\" disabled='1'
- value=''>";
-
- $this->batch_edit_cbox("auth_pass");
-
- print "</fieldset>";
-
- print "</section>";
- print "<header>".__("Options")."</header>";
- print "<section>";
-
- print "<fieldset class='narrow'>";
- print "<label class='checkbox'><input disabled='1' type='checkbox' id='include_in_digest'
- name='include_in_digest' dojoType='dijit.form.CheckBox'>&nbsp;".__('Include in e-mail digest')."</label>";
-
- print "&nbsp;"; $this->batch_edit_cbox("include_in_digest", "include_in_digest_l");
-
- print "</fieldset><fieldset class='narrow'>";
-
- print "<label class='checkbox'><input disabled='1' type='checkbox' id='always_display_enclosures'
- name='always_display_enclosures' dojoType='dijit.form.CheckBox'>&nbsp;".__('Always display image attachments')."</label>";
-
- print "&nbsp;"; $this->batch_edit_cbox("always_display_enclosures", "always_display_enclosures_l");
-
- print "</fieldset><fieldset class='narrow'>";
-
- print "<label class='checkbox'><input disabled='1' type='checkbox' id='hide_images'
- name='hide_images' dojoType='dijit.form.CheckBox'>&nbsp;". __('Do not embed media')."</label>";
-
- print "&nbsp;"; $this->batch_edit_cbox("hide_images", "hide_images_l");
-
- print "</fieldset><fieldset class='narrow'>";
+ $local_purge_intervals = $purge_intervals;
+ $default_purge_interval = get_pref("PURGE_OLD_DAYS");
- print "<label class='checkbox'><input disabled='1' type='checkbox' id='cache_images'
- name='cache_images' dojoType='dijit.form.CheckBox'>&nbsp;".__('Cache media')."</label>";
-
- print "&nbsp;"; $this->batch_edit_cbox("cache_images", "cache_images_l");
-
- print "</fieldset><fieldset class='narrow'>";
-
- print "<label class='checkbox'><input disabled='1' type='checkbox' id='mark_unread_on_update'
- name='mark_unread_on_update' dojoType='dijit.form.CheckBox'>&nbsp;".__('Mark updated articles as unread')."</label>";
-
- print "&nbsp;"; $this->batch_edit_cbox("mark_unread_on_update", "mark_unread_on_update_l");
-
- print "</fieldset>";
-
- print "</section>";
-
- print "<footer>
- <button dojoType='dijit.form.Button' type='submit' class='alt-primary' type='submit'>".
- __('Save')."</button>
- <button dojoType='dijit.form.Button'
- onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>
- </footer>";
+ if ($default_purge_interval > 0)
+ $local_purge_intervals[0] .= " " . T_sprintf("(%d days)", $default_purge_interval);
+ else
+ $local_purge_intervals[0] .= " " . sprintf("(%s)", __("Disabled"));
+
+ $options = [
+ "include_in_digest" => __('Include in e-mail digest'),
+ "always_display_enclosures" => __('Always display image attachments'),
+ "hide_images" => __('Do not embed media'),
+ "cache_images" => __('Cache media'),
+ "mark_unread_on_update" => __('Mark updated articles as unread')
+ ];
+
+ print_notice("Enable the options you wish to apply using checkboxes on the right.");
+ ?>
+
+ <?= \Controls\hidden_tag("ids", $feed_ids) ?>
+ <?= \Controls\hidden_tag("op", "pref-feeds") ?>
+ <?= \Controls\hidden_tag("method", "batchEditSave") ?>
+
+ <div dojoType="dijit.layout.TabContainer" style="height : 450px">
+ <div dojoType="dijit.layout.ContentPane" title="<?= __('General') ?>">
+ <section>
+ <?php if (get_pref('ENABLE_FEED_CATS')) { ?>
+ <fieldset>
+ <label><?= __('Place in category:') ?></label>
+ <?= \Controls\select_feeds_cats("cat_id", null, ['disabled' => '1']) ?>
+ <?= $this->_batch_toggle_checkbox("cat_id") ?>
+ </fieldset>
+ <?php } ?>
+
+ <?php if (Config::get(Config::DB_TYPE) == "pgsql") { ?>
+ <fieldset>
+ <label><?= __('Language:') ?></label>
+ <?= \Controls\select_tag("feed_language", "", $this::get_ts_languages(), ["disabled"=> 1]) ?>
+ <?= $this->_batch_toggle_checkbox("feed_language") ?>
+ </fieldset>
+ <?php } ?>
+ </section>
+
+ <hr/>
+
+ <section>
+ <fieldset>
+ <label><?= __("Update interval:") ?></label>
+ <?= \Controls\select_hash("update_interval", "", $local_update_intervals, ["disabled" => 1]) ?>
+ <?= $this->_batch_toggle_checkbox("update_interval") ?>
+ </fieldset>
+
+ <?php if (Config::get(Config::FORCE_ARTICLE_PURGE) == 0) { ?>
+ <fieldset>
+ <label><?= __('Article purging:') ?></label>
+ <?= \Controls\select_hash("purge_interval", "", $local_purge_intervals, ["disabled" => 1]) ?>
+ <?= $this->_batch_toggle_checkbox("purge_interval") ?>
+ </fieldset>
+ <?php } ?>
+ </section>
+ </div>
+ <div dojoType="dijit.layout.ContentPane" title="<?= __('Authentication') ?>">
+ <section>
+ <fieldset>
+ <label><?= __("Login:") ?></label>
+ <input dojoType='dijit.form.TextBox'
+ disabled='1' autocomplete='new-password' name='auth_login' value=''>
+ <?= $this->_batch_toggle_checkbox("auth_login") ?>
+ </fieldset>
+ <fieldset>
+ <label><?= __("Password:") ?></label>
+ <input dojoType='dijit.form.TextBox' type='password' name='auth_pass'
+ autocomplete='new-password' disabled='1' value=''>
+ <?= $this->_batch_toggle_checkbox("auth_pass") ?>
+ </fieldset>
+ </section>
+ </div>
+ <div dojoType="dijit.layout.ContentPane" title="<?= __('Options') ?>">
+ <?php
+ foreach ($options as $name => $caption) {
+ ?>
+ <fieldset class='narrow'>
+ <label class="checkbox text-muted">
+ <?= \Controls\checkbox_tag($name, false, "", ["disabled" => "1"]) ?>
+ <?= $caption ?>
+ <?= $this->_batch_toggle_checkbox($name) ?>
+ </label>
+ </fieldset>
+ <?php } ?>
+ </div>
+ </div>
- return;
+ <footer>
+ <?= \Controls\submit_tag(__("Save")) ?>
+ <?= \Controls\cancel_dialog_tag(__("Cancel")) ?>
+ </footer>
+ <?php
}
function batchEditSave() {
@@ -989,7 +685,7 @@ class Pref_Feeds extends Handler_Protected {
return $this->editsaveops(false);
}
- function editsaveops($batch) {
+ private function editsaveops($batch) {
$feed_title = clean($_POST["title"]);
$feed_url = clean($_POST["feed_url"]);
@@ -1017,10 +713,6 @@ class Pref_Feeds extends Handler_Protected {
$feed_language = clean($_POST["feed_language"]);
if (!$batch) {
- if (clean($_POST["need_auth"] ?? "") !== 'on') {
- $auth_login = '';
- $auth_pass = '';
- }
/* $sth = $this->pdo->prepare("SELECT feed_url FROM ttrss_feeds WHERE id = ?");
$sth->execute([$feed_id]);
@@ -1189,7 +881,7 @@ class Pref_Feeds extends Handler_Protected {
function addCat() {
$feed_cat = clean($_REQUEST["cat"]);
- Feeds::add_feed_category($feed_cat);
+ Feeds::_add_cat($feed_cat);
}
function importOpml() {
@@ -1197,33 +889,15 @@ class Pref_Feeds extends Handler_Protected {
$opml->opml_import($_SESSION["uid"]);
}
- function index() {
-
- print "<div dojoType='dijit.layout.AccordionContainer' region='center'>";
- print "<div style='padding : 0px' dojoType='dijit.layout.AccordionPane'
- title=\"<i class='material-icons'>rss_feed</i> ".__('Feeds')."\">";
-
- $sth = $this->pdo->prepare("SELECT COUNT(id) AS num_errors
- FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
- $sth->execute([$_SESSION['uid']]);
-
- if ($row = $sth->fetch()) {
- $num_errors = $row["num_errors"];
- } else {
- $num_errors = 0;
- }
+ private function index_feeds() {
+ $error_button = "<button dojoType='dijit.form.Button'
+ id='pref_feeds_errors_btn' style='display : none'
+ onclick='CommonDialogs.showFeedsWithErrors()'>".
+ __("Feeds with errors")."</button>";
- if ($num_errors > 0) {
- $error_button = "<button dojoType=\"dijit.form.Button\"
- onclick=\"CommonDialogs.showFeedsWithErrors()\" id=\"errorButton\">" .
- __("Feeds with errors") . "</button>";
- } else {
- $error_button = "";
- }
-
- $inactive_button = "<button dojoType=\"dijit.form.Button\"
- id=\"pref_feeds_inactive_btn\"
- style=\"display : none\"
+ $inactive_button = "<button dojoType='dijit.form.Button'
+ id='pref_feeds_inactive_btn'
+ style='display : none'
onclick=\"dijit.byId('feedTree').showInactiveFeeds()\">" .
__("Inactive feeds") . "</button>";
@@ -1235,175 +909,201 @@ class Pref_Feeds extends Handler_Protected {
$feed_search = $_SESSION["prefs_feed_search"] ?? "";
}
- print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
-
- print "<div region='top' dojoType=\"fox.Toolbar\">"; #toolbar
-
- print "<div style='float : right; padding-right : 4px;'>
- <input dojoType=\"dijit.form.TextBox\" id=\"feed_search\" size=\"20\" type=\"search\"
- value=\"$feed_search\">
- <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('feedTree').reload()\">".
- __('Search')."</button>
- </div>";
-
- print "<div dojoType=\"fox.form.DropDownButton\">".
- "<span>" . __('Select')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(true)\"
- dojoType=\"dijit.MenuItem\">".__('All')."</div>";
- print "<div onclick=\"dijit.byId('feedTree').model.setAllChecked(false)\"
- dojoType=\"dijit.MenuItem\">".__('None')."</div>";
- print "</div></div>";
-
- print "<div dojoType=\"fox.form.DropDownButton\">".
- "<span>" . __('Feeds')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"CommonDialogs.quickAddFeed()\"
- dojoType=\"dijit.MenuItem\">".__('Subscribe to feed')."</div>";
- print "<div onclick=\"dijit.byId('feedTree').editSelectedFeed()\"
- dojoType=\"dijit.MenuItem\">".__('Edit selected feeds')."</div>";
- print "<div onclick=\"dijit.byId('feedTree').resetFeedOrder()\"
- dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
- print "<div onclick=\"dijit.byId('feedTree').batchSubscribe()\"
- dojoType=\"dijit.MenuItem\">".__('Batch subscribe')."</div>";
- print "<div dojoType=\"dijit.MenuItem\" onclick=\"dijit.byId('feedTree').removeSelectedFeeds()\">"
- .__('Unsubscribe')."</div> ";
- print "</div></div>";
-
- if (get_pref('ENABLE_FEED_CATS')) {
- print "<div dojoType=\"fox.form.DropDownButton\">".
- "<span>" . __('Categories')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"dijit.byId('feedTree').createCategory()\"
- dojoType=\"dijit.MenuItem\">".__('Add category')."</div>";
- print "<div onclick=\"dijit.byId('feedTree').resetCatOrder()\"
- dojoType=\"dijit.MenuItem\">".__('Reset sort order')."</div>";
- print "<div onclick=\"dijit.byId('feedTree').removeSelectedCategories()\"
- dojoType=\"dijit.MenuItem\">".__('Remove selected')."</div>";
- print "</div></div>";
-
- }
-
- print $error_button;
- print $inactive_button;
-
- print "</div>"; # toolbar
-
- //print '</div>';
- print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">';
-
- print "<div id=\"feedlistLoading\">
- <img src='images/indicator_tiny.gif'>".
- __("Loading, please wait...")."</div>";
-
- $auto_expand = $feed_search != "" ? "true" : "false";
-
- print "<div dojoType=\"fox.PrefFeedStore\" jsId=\"feedStore\"
- url=\"backend.php?op=pref-feeds&method=getfeedtree\">
- </div>
- <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"feedModel\" store=\"feedStore\"
- query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Feeds\"
- childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
+ ?>
+
+ <div dojoType="dijit.layout.BorderContainer" gutters="false">
+ <div region='top' dojoType="fox.Toolbar">
+ <div style='float : right'>
+ <input dojoType="dijit.form.TextBox" id="feed_search" size="20" type="search"
+ value="<?= htmlspecialchars($feed_search) ?>">
+ <button dojoType="dijit.form.Button" onclick="dijit.byId('feedTree').reload()">
+ <?= __('Search') ?></button>
+ </div>
+
+ <div dojoType="fox.form.DropDownButton">
+ <span><?= __('Select') ?></span>
+ <div dojoType="dijit.Menu" style="display: none;">
+ <div onclick="dijit.byId('feedTree').model.setAllChecked(true)"
+ dojoType="dijit.MenuItem"><?= __('All') ?></div>
+ <div onclick="dijit.byId('feedTree').model.setAllChecked(false)"
+ dojoType="dijit.MenuItem"><?= __('None') ?></div>
+ </div>
+ </div>
+
+ <div dojoType="fox.form.DropDownButton">
+ <span><?= __('Feeds') ?></span>
+ <div dojoType="dijit.Menu" style="display: none">
+ <div onclick="CommonDialogs.subscribeToFeed()"
+ dojoType="dijit.MenuItem"><?= __('Subscribe to feed') ?></div>
+ <div onclick="dijit.byId('feedTree').editSelectedFeed()"
+ dojoType="dijit.MenuItem"><?= __('Edit selected feeds') ?></div>
+ <div onclick="dijit.byId('feedTree').resetFeedOrder()"
+ dojoType="dijit.MenuItem"><?= __('Reset sort order') ?></div>
+ <div onclick="dijit.byId('feedTree').batchSubscribe()"
+ dojoType="dijit.MenuItem"><?= __('Batch subscribe') ?></div>
+ <div dojoType="dijit.MenuItem" onclick="dijit.byId('feedTree').removeSelectedFeeds()">
+ <?= __('Unsubscribe') ?></div>
+ </div>
+ </div>
+
+ <?php if (get_pref('ENABLE_FEED_CATS')) { ?>
+ <div dojoType="fox.form.DropDownButton">
+ <span><?= __('Categories') ?></span>
+ <div dojoType="dijit.Menu" style="display: none">
+ <div onclick="dijit.byId('feedTree').createCategory()"
+ dojoType="dijit.MenuItem"><?= __('Add category') ?></div>
+ <div onclick="dijit.byId('feedTree').resetCatOrder()"
+ dojoType="dijit.MenuItem"><?= __('Reset sort order') ?></div>
+ <div onclick="dijit.byId('feedTree').removeSelectedCategories()"
+ dojoType="dijit.MenuItem"><?= __('Remove selected') ?></div>
+ </div>
+ </div>
+ <?php } ?>
+ <?= $error_button ?>
+ <?= $inactive_button ?>
+ </div>
+ <div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">
+ <div dojoType="fox.PrefFeedStore" jsId="feedStore"
+ url="backend.php?op=pref-feeds&method=getfeedtree">
+ </div>
+
+ <div dojoType="lib.CheckBoxStoreModel" jsId="feedModel" store="feedStore"
+ query="{id:'root'}" rootId="root" rootLabel="Feeds" childrenAttrs="items"
+ checkboxStrict="false" checkboxAll="false">
+ </div>
+
+ <div dojoType="fox.PrefFeedTree" id="feedTree"
+ dndController="dijit.tree.dndSource"
+ betweenThreshold="5"
+ autoExpand="<?= (!empty($feed_search) ? "true" : "false") ?>"
+ persist="true"
+ model="feedModel"
+ openOnClick="false">
+ <script type="dojo/method" event="onClick" args="item">
+ var id = String(item.id);
+ var bare_id = id.substr(id.indexOf(':')+1);
+
+ if (id.match('FEED:')) {
+ CommonDialogs.editFeed(bare_id);
+ } else if (id.match('CAT:')) {
+ dijit.byId('feedTree').editCategory(bare_id, item);
+ }
+ </script>
+ <script type="dojo/method" event="onLoad" args="item">
+ dijit.byId('feedTree').checkInactiveFeeds();
+ dijit.byId('feedTree').checkErrorFeeds();
+ </script>
+ </div>
+ </div>
</div>
- <div dojoType=\"fox.PrefFeedTree\" id=\"feedTree\"
- dndController=\"dijit.tree.dndSource\"
- betweenThreshold=\"5\"
- autoExpand='$auto_expand'
- model=\"feedModel\" openOnClick=\"false\">
- <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
- var id = String(item.id);
- var bare_id = id.substr(id.indexOf(':')+1);
-
- if (id.match('FEED:')) {
- CommonDialogs.editFeed(bare_id);
- } else if (id.match('CAT:')) {
- dijit.byId('feedTree').editCategory(bare_id, item);
- }
- </script>
- <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
- Element.hide(\"feedlistLoading\");
+ <?php
- dijit.byId('feedTree').checkInactiveFeeds();
- </script>
- </div>";
-
-# print "<div dojoType=\"dijit.Tooltip\" connectId=\"feedTree\" position=\"below\">
-# ".__('<b>Hint:</b> you can drag feeds and categories around.')."
-# </div>";
-
- print '</div>';
- print '</div>';
-
- print "</div>"; # feeds pane
+ }
- print "<div dojoType='dijit.layout.AccordionPane'
- title='<i class=\"material-icons\">import_export</i> ".__('OPML')."'>";
+ private function index_opml() {
+ ?>
- print "<h3>" . __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") . "</h3>";
+ <h3><?= __("Using OPML you can export and import your feeds, filters, labels and Tiny Tiny RSS settings.") ?></h3>
- print_notice("Only main settings profile can be migrated using OPML.");
+ <?php print_notice("Only main settings profile can be migrated using OPML.") ?>
- print "<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'>&nbsp;
+ <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'>
</label>
<input type='hidden' name='op' value='pref-feeds'>
- <input type='hidden' name='csrf_token' value='".$_SESSION['csrf_token']."'>
+ <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\">" .
- __('Import OPML') . "</button>";
-
- print "</form>";
+ <button dojoType='dijit.form.Button' class='alt-primary' onclick="return Helpers.OPML.import()" type="submit">
+ <?= __('Import OPML') ?>
+ </button>
+ </form>
- print "<form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>";
+ <hr/>
- print "<button dojoType='dijit.form.Button'
- onclick='Helpers.OPML.export()' >" .
- __('Export OPML') . "</button>";
+ <form dojoType='dijit.form.Form' id='opmlExportForm' style='display : inline-block'>
+ <button dojoType='dijit.form.Button' onclick='Helpers.OPML.export()'>
+ <?= __('Export OPML') ?>
+ </button>
- print " <label class='checkbox'>";
- print_checkbox("include_settings", true, "1", "");
- print " " . __("Include settings");
- print "</label>";
-
- print "</form>";
+ <label class='checkbox'>
+ <?= \Controls\checkbox_tag("include_settings", true, "1") ?>
+ <?= __("Include settings") ?>
+ </label>
+ </form>
- print "<p/>";
+ <hr/>
- print "<h2>" . __("Published OPML") . "</h2>";
+ <h2><?= __("Published OPML") ?></h2>
- print "<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>";
+ <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>
- print "<button dojoType='dijit.form.Button' class='alt-primary' onclick=\"return CommonDialogs.publishedOPML()\">".
- __('Display published OPML URL')."</button> ";
+ <button dojoType='dijit.form.Button' class='alt-primary' onclick="return Helpers.OPML.publish()">
+ <?= __('Display published OPML URL') ?>
+ </button>
+ <?php
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefFeedsOPML");
+ }
- print "</div>"; # pane
-
- print "<div dojoType=\"dijit.layout.AccordionPane\"
- title=\"<i class='material-icons'>share</i> ".__('Published & shared articles / Generated feeds')."\">";
+ private function index_shared() {
+ ?>
- print "<h3>" . __('Published articles can be subscribed by anyone who knows the following URL:') . "</h3>";
+ <h3><?= __('Published articles can be subscribed by anyone who knows the following URL:') ?></h3>
- $rss_url = htmlspecialchars(get_self_url_prefix() .
- "/public.php?op=rss&id=-2&view-mode=all_articles");;
+ <button dojoType='dijit.form.Button' class='alt-primary'
+ onclick="CommonDialogs.generatedFeed(-2, false)">
+ <?= __('Display URL') ?>
+ </button>
- print "<button dojoType='dijit.form.Button' class='alt-primary'
- onclick='CommonDialogs.generatedFeed(-2, false, \"$rss_url\", \"".__("Published articles")."\")'>".
- __('Display URL')."</button>
- <button class='alt-danger' dojoType='dijit.form.Button' onclick='return Helpers.clearFeedAccessKeys()'>".
- __('Clear all generated URLs')."</button> ";
+ <button class='alt-danger' dojoType='dijit.form.Button' onclick='return Helpers.Feeds.clearFeedAccessKeys()'>
+ <?= __('Clear all generated URLs') ?>
+ </button>
+ <?php
PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefFeedsPublishedGenerated");
+ }
- print "</div>"; #pane
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefFeeds");
-
- print "</div>"; #container
+ function index() {
+ ?>
+
+ <div dojoType='dijit.layout.TabContainer' tabPosition='left-h'>
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane'
+ title="<i class='material-icons'>rss_feed</i> <?= __('My feeds') ?>">
+ <?php $this->index_feeds() ?>
+ </div>
+
+ <div dojoType='dijit.layout.ContentPane'
+ title="<i class='material-icons'>import_export</i> <?= __('OPML') ?>">
+ <?php $this->index_opml() ?>
+ </div>
+
+ <div dojoType="dijit.layout.ContentPane"
+ title="<i class='material-icons'>share</i> <?= __('Sharing') ?>">
+ <?php $this->index_shared() ?>
+ </div>
+
+ <?php
+ ob_start();
+ PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefFeeds");
+ $plugin_data = trim((string)ob_get_contents());
+ ob_end_clean();
+ ?>
+
+ <?php if ($plugin_data) { ?>
+ <div dojoType='dijit.layout.ContentPane'
+ title="<i class='material-icons'>extension</i> <?= __('Plugins') ?>">
+
+ <div dojoType='dijit.layout.AccordionContainer' region='center'>
+ <?= $plugin_data ?>
+ </div>
+ </div>
+ <?php } ?>
+ </div>
+ <?php
}
private function feedlist_init_cat($cat_id) {
@@ -1412,9 +1112,9 @@ class Pref_Feeds extends Handler_Protected {
$obj['id'] = 'CAT:' . $cat_id;
$obj['items'] = array();
- $obj['name'] = Feeds::getCategoryTitle($cat_id);
+ $obj['name'] = Feeds::_get_cat_title($cat_id);
$obj['type'] = 'category';
- $obj['unread'] = -1; //(int) Feeds::getCategoryUnread($cat_id);
+ $obj['unread'] = -1; //(int) Feeds::_get_cat_unread($cat_id);
$obj['bare_id'] = $cat_id;
return $obj;
@@ -1425,7 +1125,7 @@ class Pref_Feeds extends Handler_Protected {
$feed_id = (int) $feed_id;
if (!$title)
- $title = Feeds::getFeedTitle($feed_id, false);
+ $title = Feeds::_get_title($feed_id, false);
if ($unread === false)
$unread = getFeedUnread($feed_id, false);
@@ -1436,7 +1136,7 @@ class Pref_Feeds extends Handler_Protected {
$obj['type'] = 'feed';
$obj['error'] = $error;
$obj['updated'] = $updated;
- $obj['icon'] = Feeds::getFeedIcon($feed_id);
+ $obj['icon'] = Feeds::_get_icon($feed_id);
$obj['bare_id'] = $feed_id;
$obj['auxcounter'] = 0;
@@ -1445,7 +1145,7 @@ class Pref_Feeds extends Handler_Protected {
function inactiveFeeds() {
- if (DB_TYPE == "pgsql") {
+ if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_qpart = "NOW() - INTERVAL '3 months'";
} else {
$interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
@@ -1464,56 +1164,14 @@ class Pref_Feeds extends Handler_Protected {
ORDER BY last_article");
$sth->execute([$_SESSION['uid']]);
- print "<div dojoType='fox.Toolbar'>";
- print "<div dojoType='fox.form.DropDownButton'>".
- "<span>" . __('Select')."</span>";
- print "<div dojoType='dijit.Menu' style='display: none'>";
- print "<div onclick=\"Tables.select('inactive-feeds-list', true)\"
- dojoType='dijit.MenuItem'>".__('All')."</div>";
- print "<div onclick=\"Tables.select('inactive-feeds-list', false)\"
- dojoType='dijit.MenuItem'>".__('None')."</div>";
- print "</div></div>";
- print "</div>"; #toolbar
-
- print "<div class='panel panel-scrollable'>";
- print "<table width='100%' id='inactive-feeds-list'>";
-
- $lnum = 1;
-
- while ($line = $sth->fetch()) {
-
- $feed_id = $line["id"];
-
- print "<tr data-row-id='$feed_id'>";
-
- print "<td width='5%' align='center'><input
- onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox'
- type='checkbox'></td>";
- print "<td>";
-
- print "<a href='#' ".
- "title=\"".__("Click to edit feed")."\" ".
- "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">".
- htmlspecialchars($line["title"])."</a>";
-
- print "</td><td class='text-muted' align='right'>";
- print TimeHelper::make_local_datetime($line['last_article'], false);
- print "</td>";
- print "</tr>";
+ $rv = [];
- ++$lnum;
+ while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
+ $row['last_article'] = TimeHelper::make_local_datetime($row['last_article'], false);
+ array_push($rv, $row);
}
- print "</table>";
- print "</div>";
-
- print "<footer>
- <button style='float : left' class='alt-danger' dojoType='dijit.form.Button' onclick='App.dialogOf(this).removeSelected()'>"
- .__('Unsubscribe from selected feeds')."</button>
- <button dojoType='dijit.form.Button' class='alt-primary' type='submit'>"
- .__('Close this window')."</button>
- </footer>";
-
+ print json_encode($rv);
}
function feedsWithErrors() {
@@ -1521,58 +1179,13 @@ class Pref_Feeds extends Handler_Protected {
FROM ttrss_feeds WHERE last_error != '' AND owner_uid = ?");
$sth->execute([$_SESSION['uid']]);
- print "<div dojoType=\"fox.Toolbar\">";
- print "<div dojoType=\"fox.form.DropDownButton\">".
- "<span>" . __('Select')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"Tables.select('error-feeds-list', true)\"
- dojoType=\"dijit.MenuItem\">".__('All')."</div>";
- print "<div onclick=\"Tables.select('error-feeds-list', false)\"
- dojoType=\"dijit.MenuItem\">".__('None')."</div>";
- print "</div></div>";
- print "</div>"; #toolbar
-
- print "<div class='panel panel-scrollable'>";
- print "<table width='100%' id='error-feeds-list'>";
-
- $lnum = 1;
-
- while ($line = $sth->fetch()) {
-
- $feed_id = $line["id"];
-
- print "<tr data-row-id='$feed_id'>";
-
- print "<td width='5%' align='center'><input
- onclick='Tables.onRowChecked(this);' dojoType=\"dijit.form.CheckBox\"
- type=\"checkbox\"></td>";
- print "<td>";
-
- print "<a class=\"visibleLink\" href=\"#\" ".
- "title=\"".__("Click to edit feed")."\" ".
- "onclick=\"CommonDialogs.editFeed(".$line["id"].")\">".
- htmlspecialchars($line["title"])."</a>: ";
-
- print "<span class=\"text-muted\">";
- print htmlspecialchars($line["last_error"]);
- print "</span>";
-
- print "</td>";
- print "</tr>";
+ $rv = [];
- ++$lnum;
+ while ($row = $sth->fetch()) {
+ array_push($rv, $row);
}
- print "</table>";
- print "</div>";
-
- print "<footer>";
- print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button' onclick='App.dialogOf(this).removeSelected()'>"
- .__('Unsubscribe from selected feeds')."</button> ";
- print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>".
- __('Close this window')."</button>";
-
- print "</footer>";
+ print json_encode($rv);
}
private function remove_feed_category($id, $owner_uid) {
@@ -1613,8 +1226,8 @@ class Pref_Feeds extends Handler_Protected {
$pdo->commit();
- if (file_exists(ICONS_DIR . "/$id.ico")) {
- unlink(ICONS_DIR . "/$id.ico");
+ if (file_exists(Config::get(Config::ICONS_DIR) . "/$id.ico")) {
+ unlink(Config::get(Config::ICONS_DIR) . "/$id.ico");
}
} else {
@@ -1623,52 +1236,10 @@ class Pref_Feeds extends Handler_Protected {
}
function batchSubscribe() {
- print "<form onsubmit='return false'>";
-
- print_hidden("op", "pref-feeds");
- print_hidden("method", "batchaddfeeds");
-
- print "<header class='horizontal'>".__("One valid feed per line (no detection is done)")."</header>";
- print "<section>";
-
- print "<textarea
- style='font-size : 12px; width : 98%; height: 200px;'
- dojoType='fox.form.ValidationTextArea' required='1' name='feeds'></textarea>";
-
- if (get_pref('ENABLE_FEED_CATS')) {
- print "<fieldset>";
- print "<label>" . __('Place in category:') . "</label> ";
- print_feed_cat_select("cat", false, 'dojoType="fox.form.Select"');
- print "</fieldset>";
- }
-
- print "</section>";
-
- print "<div id='feedDlg_loginContainer' style='display : none'>";
-
- print "<header>" . __("Authentication") . "</header>";
- print "<section>";
-
- print "<input dojoType='dijit.form.TextBox' name='login' placeHolder=\"".__("Login")."\">
- <input placeHolder=\"".__("Password")."\" dojoType=\"dijit.form.TextBox\" type='password'
- autocomplete='new-password' name='pass''></div>";
-
- print "</section>";
- print "</div>";
-
- print "<fieldset class='narrow'>
- <label class='checkbox'><input type='checkbox' name='need_auth' dojoType='dijit.form.CheckBox'
- onclick='App.displayIfChecked(this, \"feedDlg_loginContainer\")'> ".
- __('Feeds require authentication.')."</label></div>";
- print "</fieldset>";
-
- print "<footer>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).execute()' type='submit' class='alt-primary'>".
- __('Subscribe')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".__('Cancel')."</button>
- </footer>";
-
- print "</form>";
+ print json_encode([
+ "enable_cats" => (int)get_pref('ENABLE_FEED_CATS'),
+ "cat_select" => \Controls\select_feeds_cats("cat")
+ ]);
}
function batchAddFeeds() {
@@ -1703,14 +1274,14 @@ class Pref_Feeds extends Handler_Protected {
}
function getOPMLKey() {
- print json_encode(["link" => OPML::opml_publish_url()]);
+ print json_encode(["link" => OPML::get_publish_url()]);
}
function regenOPMLKey() {
$this->update_feed_access_key('OPML:Publish',
false, $_SESSION["uid"]);
- print json_encode(["link" => OPML::opml_publish_url()]);
+ print json_encode(["link" => OPML::get_publish_url()]);
}
function regenFeedKey() {
@@ -1722,11 +1293,23 @@ class Pref_Feeds extends Handler_Protected {
print json_encode(["link" => $new_key]);
}
- function getFeedKey() {
+ function getsharedurl() {
$feed_id = clean($_REQUEST['id']);
- $is_cat = clean($_REQUEST['is_cat']);
-
- print json_encode(["link" => Feeds::get_feed_access_key($feed_id, $is_cat, $_SESSION["uid"])]);
+ $is_cat = clean($_REQUEST['is_cat']) == "true";
+ $search = clean($_REQUEST['search']);
+
+ $link = get_self_url_prefix() . "/public.php?" . http_build_query([
+ 'op' => 'rss',
+ 'id' => $feed_id,
+ 'is_cat' => (int)$is_cat,
+ 'q' => $search,
+ 'key' => Feeds::_get_access_key($feed_id, $is_cat, $_SESSION["uid"])
+ ]);
+
+ print json_encode([
+ "title" => Feeds::_get_title($feed_id, $is_cat),
+ "link" => $link
+ ]);
}
private function update_feed_access_key($feed_id, $is_cat, $owner_uid) {
@@ -1736,7 +1319,7 @@ class Pref_Feeds extends Handler_Protected {
WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?");
$sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]);
- return Feeds::get_feed_access_key($feed_id, $is_cat, $owner_uid);
+ return Feeds::_get_access_key($feed_id, $is_cat, $owner_uid);
}
// Silent
@@ -1760,29 +1343,4 @@ class Pref_Feeds extends Handler_Protected {
return $c;
}
- function getinactivefeeds() {
- if (DB_TYPE == "pgsql") {
- $interval_qpart = "NOW() - INTERVAL '3 months'";
- } else {
- $interval_qpart = "DATE_SUB(NOW(), INTERVAL 3 MONTH)";
- }
-
- $sth = $this->pdo->prepare("SELECT COUNT(id) 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 = ?");
- $sth->execute([$_SESSION['uid']]);
-
- if ($row = $sth->fetch()) {
- print (int)$row["num_inactive"];
- }
- }
-
- static function subscribe_to_feed_url() {
- $url_path = get_self_url_prefix() .
- "/public.php?op=subscribe&feed_url=%s";
- return $url_path;
- }
-
}
diff --git a/classes/pref/filters.php b/classes/pref/filters.php
index a24a05b05..fda4a6513 100755
--- a/classes/pref/filters.php
+++ b/classes/pref/filters.php
@@ -162,7 +162,7 @@ class Pref_Filters extends Handler_Protected {
print json_encode($rv);
}
- private function getfilterrules_list($filter_id) {
+ private function _get_rules_list($filter_id) {
$sth = $this->pdo->prepare("SELECT reg_exp,
inverse,
match_on,
@@ -189,10 +189,10 @@ class Pref_Filters extends Handler_Protected {
if (strpos($feed_id, "CAT:") === 0) {
$feed_id = (int)substr($feed_id, 4);
- array_push($feeds_fmt, Feeds::getCategoryTitle($feed_id));
+ array_push($feeds_fmt, Feeds::_get_cat_title($feed_id));
} else {
if ($feed_id)
- array_push($feeds_fmt, Feeds::getFeedTitle((int)$feed_id));
+ array_push($feeds_fmt, Feeds::_get_title((int)$feed_id));
else
array_push($feeds_fmt, __("All feeds"));
}
@@ -203,9 +203,9 @@ class Pref_Filters extends Handler_Protected {
} else {
$where = $line["cat_filter"] ?
- Feeds::getCategoryTitle($line["cat_id"]) :
+ Feeds::_get_cat_title($line["cat_id"]) :
($line["feed_id"] ?
- Feeds::getFeedTitle($line["feed_id"]) : __("All feeds"));
+ Feeds::_get_title($line["feed_id"]) : __("All feeds"));
}
# $where = $line["cat_id"] . "/" . $line["feed_id"];
@@ -250,7 +250,7 @@ class Pref_Filters extends Handler_Protected {
while ($line = $sth->fetch()) {
- $name = $this->getFilterName($line["id"]);
+ $name = $this->_get_name($line["id"]);
$match_ok = false;
if ($filter_search) {
@@ -292,7 +292,7 @@ class Pref_Filters extends Handler_Protected {
$filter['checkbox'] = false;
$filter['last_triggered'] = $line["last_triggered"] ? TimeHelper::make_local_datetime($line["last_triggered"], false) : null;
$filter['enabled'] = sql_bool_to_bool($line["enabled"]);
- $filter['rules'] = $this->getfilterrules_list($line['id']);
+ $filter['rules'] = $this->_get_rules_list($line['id']);
if (!$filter_search || $match_ok) {
array_push($folder['items'], $filter);
@@ -319,170 +319,94 @@ class Pref_Filters extends Handler_Protected {
$sth->execute([$filter_id, $_SESSION['uid']]);
if (empty($filter_id) || $row = $sth->fetch()) {
+ $rv = [
+ "id" => $filter_id,
+ "enabled" => $row["enabled"] ?? true,
+ "match_any_rule" => $row["match_any_rule"] ?? false,
+ "inverse" => $row["inverse"] ?? false,
+ "title" => $row["title"] ?? "",
+ "rules" => [],
+ "actions" => [],
+ "filter_types" => [],
+ "action_types" => [],
+ "plugin_actions" => [],
+ "labels" => Labels::get_all($_SESSION["uid"])
+ ];
+
+ $res = $this->pdo->query("SELECT id,description
+ FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
+
+ while ($line = $res->fetch()) {
+ $rv["filter_types"][$line["id"]] = __($line["description"]);
+ }
- $enabled = $row["enabled"] ?? true;
- $match_any_rule = $row["match_any_rule"] ?? false;
- $inverse = $row["inverse"] ?? false;
- $title = htmlspecialchars($row["title"] ?? "");
-
- print "<form onsubmit='return false'>";
-
- print_hidden("op", "pref-filters");
+ $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions
+ ORDER BY name");
- if ($filter_id) {
- print_hidden("id", "$filter_id");
- print_hidden("method", "editSave");
- } else {
- print_hidden("method", "add");
+ while ($line = $res->fetch()) {
+ $rv["action_types"][$line["id"]] = __($line["description"]);
}
- print_hidden("csrf_token", $_SESSION['csrf_token']);
-
- print "<header>".__("Caption")."</header>
- <section>
- <input required='true' dojoType='dijit.form.ValidationTextBox' style='width : 20em;' name=\"title\" value=\"$title\">
- </section>
- <header class='horizontal'>".__("Match")."</header>
- <section>
- <div dojoType='fox.Toolbar'>
- <div dojoType='fox.form.DropDownButton'>
- <span>" . __('Select')."</span>
- <div dojoType='dijit.Menu' style='display: none;'>
- <!-- can't use App.dialogOf() here because DropDownButton is not a child of the Dialog -->
- <div onclick='dijit.byId(\"filterEditDlg\").selectRules(true)'
- dojoType='dijit.MenuItem'>".__('All')."</div>
- <div onclick='dijit.byId(\"filterEditDlg\").selectRules(false)'
- dojoType='dijit.MenuItem'>".__('None')."</div>
- </div>
- </div>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).addRule()'>".
- __('Add')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).deleteRule()'>".
- __('Delete')."</button>
- </div>";
+ $filter_actions = PluginHost::getInstance()->get_filter_actions();
- print "<ul id='filterDlg_Matches'>";
+ foreach ($filter_actions as $fclass => $factions) {
+ foreach ($factions as $faction) {
+
+ $rv["plugin_actions"][$fclass . ":" . $faction["action"]] =
+ $fclass . ": " . $faction["description"];
+ }
+ }
if ($filter_id) {
$rules_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_rules
WHERE filter_id = ? ORDER BY reg_exp, id");
- $rules_sth->execute([$filter_id]);
+ $rules_sth->execute([$filter_id]);
- while ($line = $rules_sth->fetch()) {
- if ($line["match_on"]) {
- $line["feed_id"] = json_decode($line["match_on"], true);
+ while ($rrow = $rules_sth->fetch(PDO::FETCH_ASSOC)) {
+ if ($rrow["match_on"]) {
+ $rrow["feed_id"] = json_decode($rrow["match_on"], true);
} else {
- if ($line["cat_filter"]) {
- $feed_id = "CAT:" . (int)$line["cat_id"];
+ if ($rrow["cat_filter"]) {
+ $feed_id = "CAT:" . (int)$rrow["cat_id"];
} else {
- $feed_id = (int)$line["feed_id"];
+ $feed_id = (int)$rrow["feed_id"];
}
- $line["feed_id"] = ["" . $feed_id]; // set item type to string for in_array()
+ $rrow["feed_id"] = ["" . $feed_id]; // set item type to string for in_array()
}
- unset($line["cat_filter"]);
- unset($line["cat_id"]);
- unset($line["filter_id"]);
- unset($line["id"]);
- if (!$line["inverse"]) unset($line["inverse"]);
- unset($line["match_on"]);
+ unset($rrow["cat_filter"]);
+ unset($rrow["cat_id"]);
+ unset($rrow["filter_id"]);
+ unset($rrow["id"]);
+ if (!$rrow["inverse"]) unset($rrow["inverse"]);
+ unset($rrow["match_on"]);
- $data = htmlspecialchars((string)json_encode($line));
+ $rrow["name"] = $this->_get_rule_name($rrow);
- print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
- <span onclick='App.dialogOf(this).editRule(this)'>".$this->getRuleName($line)."</span>".
- format_hidden("rule[]", $data)."</li>";
+ array_push($rv["rules"], $rrow);
}
- }
- print "</ul>
- </section>";
-
- print "<header class='horizontal'>".__("Apply actions")."</header>
- <section>
- <div dojoType='fox.Toolbar'>
- <div dojoType='fox.form.DropDownButton'>
- <span>".__('Select')."</span>
- <div dojoType='dijit.Menu' style='display: none'>
- <div onclick='dijit.byId(\"filterEditDlg\").selectActions(true)'
- dojoType='dijit.MenuItem'>".__('All')."</div>
- <div onclick='dijit.byId(\"filterEditDlg\").selectActions(false)'
- dojoType='dijit.MenuItem'>".__('None')."</div>
- </div>
- </div>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).addAction()'>".
- __('Add')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).deleteAction()'>".
- __('Delete')."</button>
- </div>";
-
- print "<ul id='filterDlg_Actions'>";
-
- if ($filter_id) {
$actions_sth = $this->pdo->prepare("SELECT * FROM ttrss_filters2_actions
WHERE filter_id = ? ORDER BY id");
$actions_sth->execute([$filter_id]);
- while ($line = $actions_sth->fetch()) {
- $line["action_param_label"] = $line["action_param"];
+ while ($arow = $actions_sth->fetch(PDO::FETCH_ASSOC)) {
+ $arow["action_param_label"] = $arow["action_param"];
- unset($line["filter_id"]);
- unset($line["id"]);
+ unset($arow["filter_id"]);
+ unset($arow["id"]);
- $data = htmlspecialchars((string)json_encode($line));
+ $arow["name"] = $this->_get_action_name($arow);
- print "<li><input dojoType='dijit.form.CheckBox' type='checkbox' onclick='Lists.onRowChecked(this)'>
- <span onclick='App.dialogOf(this).editAction(this)'>".$this->getActionName($line)."</span>".
- format_hidden("action[]", $data)."</li>";
+ array_push($rv["actions"], $arow);
}
}
-
- print "</ul>";
-
- print "</section>";
-
- print "<header>".__("Options")."</header>
- <section>";
-
- print "<fieldset class='narrow'>
- <label class='checkbox'>".format_checkbox('enabled', $enabled)." ".__('Enabled')."</label></fieldset>";
-
- print "<fieldset class='narrow'>
- <label class='checkbox'>".format_checkbox('match_any_rule', $match_any_rule)." ".__('Match any rule')."</label>
- </fieldset>";
-
- print "<fieldset class='narrow'><label class='checkbox'>".format_checkbox('inverse', $inverse)." ".__('Inverse matching')."</label>
- </fieldset>";
-
- print "</section>
- <footer>";
-
- if ($filter_id) {
- print "<div style='float : left'>
- <button dojoType='dijit.form.Button' class='alt-danger' onclick='App.dialogOf(this).removeFilter()'>".
- __('Remove')."</button>
- </div>
- <button dojoType='dijit.form.Button' class='alt-info' onclick='App.dialogOf(this).test()'>".
- __('Test')."</button>
- <button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>".
- __('Save')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>";
- } else {
- print "<button dojoType='dijit.form.Button' class='alt-info' onclick='App.dialogOf(this).test()'>".
- __('Test')."</button>
- <button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>".
- __('Create')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>";
- }
-
- print "</footer></form>";
+ print json_encode($rv);
}
}
- private function getRuleName($rule) {
+ private function _get_rule_name($rule) {
if (!$rule) $rule = json_decode(clean($_REQUEST["rule"]), true);
$feeds = $rule["feed_id"];
@@ -494,10 +418,10 @@ class Pref_Filters extends Handler_Protected {
if (strpos($feed_id, "CAT:") === 0) {
$feed_id = (int)substr($feed_id, 4);
- array_push($feeds_fmt, Feeds::getCategoryTitle($feed_id));
+ array_push($feeds_fmt, Feeds::_get_cat_title($feed_id));
} else {
if ($feed_id)
- array_push($feeds_fmt, Feeds::getFeedTitle((int)$feed_id));
+ array_push($feeds_fmt, Feeds::_get_title((int)$feed_id));
else
array_push($feeds_fmt, __("All feeds"));
}
@@ -523,10 +447,10 @@ class Pref_Filters extends Handler_Protected {
}
function printRuleName() {
- print $this->getRuleName(json_decode(clean($_REQUEST["rule"]), true));
+ print $this->_get_rule_name(json_decode(clean($_REQUEST["rule"]), true));
}
- private function getActionName($action) {
+ private function _get_action_name($action) {
$sth = $this->pdo->prepare("SELECT description FROM
ttrss_filter_actions WHERE id = ?");
$sth->execute([(int)$action["action_id"]]);
@@ -561,13 +485,13 @@ class Pref_Filters extends Handler_Protected {
}
function printActionName() {
- print $this->getActionName(json_decode(clean($_REQUEST["action"]), true));
+ print $this->_get_action_name(json_decode(clean($_REQUEST["action"]), true));
}
function editSave() {
$filter_id = clean($_REQUEST["id"]);
$enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"] ?? false));
- $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"]));
+ $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"] ?? false));
$inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"] ?? false));
$title = clean($_REQUEST["title"]);
@@ -581,7 +505,7 @@ class Pref_Filters extends Handler_Protected {
$sth->execute([$enabled, $match_any_rule, $inverse, $title, $filter_id, $_SESSION['uid']]);
- $this->saveRulesAndActions($filter_id);
+ $this->_save_rules_and_actions($filter_id);
$this->pdo->commit();
}
@@ -596,8 +520,7 @@ class Pref_Filters extends Handler_Protected {
$sth->execute(array_merge($ids, [$_SESSION['uid']]));
}
- private function saveRulesAndActions($filter_id)
- {
+ private function _save_rules_and_actions($filter_id) {
$sth = $this->pdo->prepare("DELETE FROM ttrss_filters2_rules WHERE filter_id = ?");
$sth->execute([$filter_id]);
@@ -674,11 +597,11 @@ class Pref_Filters extends Handler_Protected {
}
}
- function add() {
- $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"]));
- $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"]));
+ function add () {
+ $enabled = checkbox_to_sql_bool(clean($_REQUEST["enabled"] ?? false));
+ $match_any_rule = checkbox_to_sql_bool(clean($_REQUEST["match_any_rule"] ?? false));
$title = clean($_REQUEST["title"]);
- $inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"]));
+ $inverse = checkbox_to_sql_bool(clean($_REQUEST["inverse"] ?? false));
$this->pdo->beginTransaction();
@@ -696,7 +619,7 @@ class Pref_Filters extends Handler_Protected {
if ($row = $sth->fetch()) {
$filter_id = $row['id'];
- $this->saveRulesAndActions($filter_id);
+ $this->_save_rules_and_actions($filter_id);
}
$this->pdo->commit();
@@ -710,257 +633,73 @@ class Pref_Filters extends Handler_Protected {
$filter_search = ($_SESSION["prefs_filter_search"] ?? "");
}
- print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
- print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>";
- print "<div dojoType='fox.Toolbar'>";
-
- print "<div style='float : right; padding-right : 4px;'>
- <input dojoType=\"dijit.form.TextBox\" id=\"filter_search\" size=\"20\" type=\"search\"
- value=\"$filter_search\">
- <button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('filterTree').reload()\">".
- __('Search')."</button>
- </div>";
-
- print "<div dojoType=\"fox.form.DropDownButton\">".
- "<span>" . __('Select')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(true)\"
- dojoType=\"dijit.MenuItem\">".__('All')."</div>";
- print "<div onclick=\"dijit.byId('filterTree').model.setAllChecked(false)\"
- dojoType=\"dijit.MenuItem\">".__('None')."</div>";
- print "</div></div>";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return Filters.edit()\">".
- __('Create filter')."</button> ";
+ ?>
+ <div dojoType='dijit.layout.BorderContainer' gutters='false'>
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>
+ <div dojoType='fox.Toolbar'>
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').joinSelectedFilters()\">".
- __('Combine')."</button> ";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').editSelectedFilter()\">".
- __('Edit')."</button> ";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').resetFilterOrder()\">".
- __('Reset sort order')."</button> ";
-
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return dijit.byId('filterTree').removeSelectedFilters()\">".
- __('Remove')."</button> ";
-
- print "</div>"; # toolbar
- print "</div>"; # toolbar-frame
- print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>";
+ <div style='float : right; padding-right : 4px;'>
+ <input dojoType="dijit.form.TextBox" id="filter_search" size="20" type="search"
+ value="<?= htmlspecialchars($filter_search) ?>">
+ <button dojoType="dijit.form.Button" onclick="dijit.byId('filterTree').reload()">
+ <?= __('Search') ?></button>
+ </div>
- print "<div id='filterlistLoading'>
- <img src='images/indicator_tiny.gif'>".
- __("Loading, please wait...")."</div>";
+ <div dojoType="fox.form.DropDownButton">
+ <span><?= __('Select') ?></span>
+ <div dojoType="dijit.Menu" style="display: none;">
+ <div onclick="dijit.byId('filterTree').model.setAllChecked(true)"
+ dojoType="dijit.MenuItem"><?= __('All') ?></div>
+ <div onclick="dijit.byId('filterTree').model.setAllChecked(false)"
+ dojoType="dijit.MenuItem"><?= __('None') ?></div>
+ </div>
+ </div>
- print "<div dojoType=\"fox.PrefFilterStore\" jsId=\"filterStore\"
- url=\"backend.php?op=pref-filters&method=getfiltertree\">
- </div>
- <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"filterModel\" store=\"filterStore\"
- query=\"{id:'root'}\" rootId=\"root\" rootLabel=\"Filters\"
- childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
+ <button dojoType="dijit.form.Button" onclick="return Filters.edit()">
+ <?= __('Create filter') ?></button>
+ <button dojoType="dijit.form.Button" onclick="return dijit.byId('filterTree').joinSelectedFilters()">
+ <?= __('Combine') ?></button>
+ <button dojoType="dijit.form.Button" onclick="return dijit.byId('filterTree').resetFilterOrder()">
+ <?= __('Reset sort order') ?></button>
+ <button dojoType="dijit.form.Button" onclick="return dijit.byId('filterTree').removeSelectedFilters()">
+ <?= __('Remove') ?></button>
+
+ </div>
+ </div>
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>
+ <div dojoType="fox.PrefFilterStore" jsId="filterStore"
+ url="backend.php?op=pref-filters&method=getfiltertree">
+ </div>
+ <div dojoType="lib.CheckBoxStoreModel" jsId="filterModel" store="filterStore"
+ query="{id:'root'}" rootId="root" rootLabel="Filters"
+ childrenAttrs="items" checkboxStrict="false" checkboxAll="false">
+ </div>
+ <div dojoType="fox.PrefFilterTree" id="filterTree" dndController="dijit.tree.dndSource"
+ betweenThreshold="5" model="filterModel" openOnClick="true">
+ <script type="dojo/method" event="onClick" args="item">
+ var id = String(item.id);
+ var bare_id = id.substr(id.indexOf(':')+1);
+
+ if (id.match('FILTER:')) {
+ Filters.edit(bare_id);
+ }
+ </script>
+ </div>
+ </div>
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefFilters") ?>
</div>
- <div dojoType=\"fox.PrefFilterTree\" id=\"filterTree\"
- dndController=\"dijit.tree.dndSource\"
- betweenThreshold=\"5\"
- model=\"filterModel\" openOnClick=\"true\">
- <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
- Element.hide(\"filterlistLoading\");
- </script>
- <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
- var id = String(item.id);
- var bare_id = id.substr(id.indexOf(':')+1);
-
- if (id.match('FILTER:')) {
- Filters.edit(bare_id);
- }
- </script>
-
- </div>";
-
- print "</div>"; #pane
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefFilters");
-
- print "</div>"; #container
-
+ <?php
}
- function newrule() {
- $rule = json_decode(clean($_REQUEST["rule"]), true);
-
- if ($rule) {
- $reg_exp = htmlspecialchars($rule["reg_exp"]);
- $filter_type = $rule["filter_type"];
- $feed_id = $rule["feed_id"];
- $inverse_checked = isset($rule["inverse"]) ? "checked" : "";
- } else {
- $reg_exp = "";
- $filter_type = 1;
- $feed_id = ["0"];
- $inverse_checked = "";
- }
-
- print "<form name='filter_new_rule_form' id='filter_new_rule_form' onsubmit='return false;'>";
-
- $res = $this->pdo->query("SELECT id,description
- FROM ttrss_filter_types WHERE id != 5 ORDER BY description");
-
- $filter_types = array();
-
- while ($line = $res->fetch()) {
- $filter_types[$line["id"]] = __($line["description"]);
- }
-
- print "<header>".__("Match")."</header>";
-
- print "<section>";
-
- print "<textarea dojoType='fox.form.ValidationTextArea'
- required='true' id='filterDlg_regExp'
- ValidRegExp='true'
- rows='4'
- style='font-size : 14px; width : 490px; word-break: break-all'
- name='reg_exp'>$reg_exp</textarea>";
+ function editrule() {
+ $feed_ids = explode(",", clean($_REQUEST["ids"]));
- print "<div dojoType='dijit.Tooltip' id='filterDlg_regExp_tip' connectId='filterDlg_regExp' position='below'></div>";
-
- print "<fieldset>";
- print "<label class='checkbox'><input id='filterDlg_inverse' dojoType='dijit.form.CheckBox'
- name='inverse' $inverse_checked/> ".
- __("Inverse regular expression matching")."</label>";
- print "</fieldset>";
-
- print "<fieldset>";
- print "<label style='display : inline'>". __("on field") . "</label> ";
- print_select_hash("filter_type", $filter_type, $filter_types,
- 'dojoType="fox.form.Select"');
- print "<label style='padding-left : 10px; display : inline'>" . __("in") . "</label> ";
-
- print "</fieldset>";
-
- print "<fieldset>";
- print "<span id='filterDlg_feeds'>";
- print_feed_multi_select("feed_id",
- $feed_id,
- 'style="width : 500px; height : 300px" dojoType="dijit.form.MultiSelect"');
- print "</span>";
-
- print "</fieldset>";
-
- print "</section>";
-
- print "<footer>";
-
- print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/ContentFilters\")'>
- <i class='material-icons'>help</i> ".__("More info...")."</button>";
-
- print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick='App.dialogOf(this).execute()'>".
- ($rule ? __("Save rule") : __('Add rule'))."</button> ";
-
- print "<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>";
-
- print "</footer>";
-
- print "</form>";
+ print json_encode([
+ "multiselect" => $this->_feed_multi_select("feed_id", $feed_ids, 'required="1" style="width : 100%; height : 300px" dojoType="fox.form.ValidationMultiSelect"')
+ ]);
}
- function newaction() {
- $action = json_decode(clean($_REQUEST["action"]), true);
-
- if ($action) {
- $action_param = $action["action_param"];
- $action_id = (int)$action["action_id"];
- } else {
- $action_param = "";
- $action_id = 0;
- }
-
- print "<form name='filter_new_action_form' id='filter_new_action_form' onsubmit='return false;'>";
-
- print "<header>".__("Perform Action")."</header>";
-
- print "<section>";
-
- print "<select name='action_id' dojoType='fox.form.Select'
- onchange='Filters.filterDlgCheckAction(this)'>";
-
- $res = $this->pdo->query("SELECT id,description FROM ttrss_filter_actions
- ORDER BY name");
-
- while ($line = $res->fetch()) {
- $is_selected = ($line["id"] == $action_id) ? "selected='1'" : "";
- printf("<option $is_selected value='%d'>%s</option>", $line["id"], __($line["description"]));
- }
-
- print "</select>";
-
- $param_box_hidden = ($action_id == 7 || $action_id == 4 || $action_id == 6 || $action_id == 9) ?
- "" : "display : none";
-
- $param_hidden = ($action_id == 4 || $action_id == 6) ?
- "" : "display : none";
-
- $label_param_hidden = ($action_id == 7) ? "" : "display : none";
- $plugin_param_hidden = ($action_id == 9) ? "" : "display : none";
-
- print "<span id='filterDlg_paramBox' style=\"$param_box_hidden\">";
- print " ";
- //print " " . __("with parameters:") . " ";
- print "<input dojoType='dijit.form.TextBox'
- id='filterDlg_actionParam' style=\"$param_hidden\"
- name='action_param' value=\"$action_param\">";
-
- print_label_select("action_param_label", $action_param,
- "id='filterDlg_actionParamLabel' style=\"$label_param_hidden\"
- dojoType='fox.form.Select'");
-
- $filter_actions = PluginHost::getInstance()->get_filter_actions();
- $filter_action_hash = array();
-
- foreach ($filter_actions as $fclass => $factions) {
- foreach ($factions as $faction) {
-
- $filter_action_hash[$fclass . ":" . $faction["action"]] =
- $fclass . ": " . $faction["description"];
- }
- }
-
- if (count($filter_action_hash) == 0) {
- $filter_plugin_disabled = "disabled";
-
- $filter_action_hash["no-data"] = __("No actions available");
-
- } else {
- $filter_plugin_disabled = "";
- }
-
- print_select_hash("filterDlg_actionParamPlugin", $action_param, $filter_action_hash,
- "style=\"$plugin_param_hidden\" dojoType='fox.form.Select' $filter_plugin_disabled",
- "action_param_plugin");
-
- print "</span>";
-
- print "&nbsp;"; // tiny layout hack
-
- print "</section>";
-
- print "<footer>";
-
- print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick='App.dialogOf(this).execute()'>".
- ($action ? __("Save action") : __('Add action'))."</button> ";
-
- print "<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>";
-
- print "</footer>";
-
- print "</form>";
- }
-
- private function getFilterName($id) {
+ private function _get_name($id) {
$sth = $this->pdo->prepare(
"SELECT title,match_any_rule,f.inverse AS inverse,COUNT(DISTINCT r.id) AS num_rules,COUNT(DISTINCT a.id) AS num_actions
@@ -989,7 +728,7 @@ class Pref_Filters extends Handler_Protected {
$actions = "";
if ($line = $sth->fetch()) {
- $actions = $this->getActionName($line);
+ $actions = $this->_get_action_name($line);
$num_actions -= 1;
}
@@ -1031,12 +770,12 @@ class Pref_Filters extends Handler_Protected {
$this->pdo->commit();
- $this->optimizeFilter($base_id);
+ $this->_optimize($base_id);
}
}
- private function optimizeFilter($id) {
+ private function _optimize($id) {
$this->pdo->beginTransaction();
@@ -1090,4 +829,111 @@ class Pref_Filters extends Handler_Protected {
$this->pdo->commit();
}
+
+ private function _feed_multi_select($id, $default_ids = [],
+ $attributes = "", $include_all_feeds = true,
+ $root_id = null, $nest_level = 0) {
+
+ $pdo = Db::pdo();
+
+ $rv = "";
+
+ // print_r(in_array("CAT:6",$default_ids));
+
+ if (!$root_id) {
+ $rv .= "<select multiple=\true\" id=\"$id\" name=\"$id\" $attributes>";
+ if ($include_all_feeds) {
+ $is_selected = (in_array("0", $default_ids)) ? "selected=\"1\"" : "";
+ $rv .= "<option $is_selected value=\"0\">".__('All feeds')."</option>";
+ }
+ }
+
+ if (get_pref('ENABLE_FEED_CATS')) {
+
+ if (!$root_id) $root_id = null;
+
+ $sth = $pdo->prepare("SELECT id,title,
+ (SELECT COUNT(id) FROM ttrss_feed_categories AS c2 WHERE
+ c2.parent_cat = ttrss_feed_categories.id) AS num_children
+ FROM ttrss_feed_categories
+ WHERE owner_uid = :uid AND
+ (parent_cat = :root_id OR (:root_id IS NULL AND parent_cat IS NULL)) ORDER BY title");
+
+ $sth->execute([":uid" => $_SESSION['uid'], ":root_id" => $root_id]);
+
+ while ($line = $sth->fetch()) {
+
+ for ($i = 0; $i < $nest_level; $i++)
+ $line["title"] = " " . $line["title"];
+
+ $is_selected = in_array("CAT:".$line["id"], $default_ids) ? "selected=\"1\"" : "";
+
+ $rv .= sprintf("<option $is_selected value='CAT:%d'>%s</option>",
+ $line["id"], htmlspecialchars($line["title"]));
+
+ if ($line["num_children"] > 0)
+ $rv .= $this->_feed_multi_select($id, $default_ids, $attributes,
+ $include_all_feeds, $line["id"], $nest_level+1);
+
+ $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
+ WHERE cat_id = ? AND owner_uid = ? ORDER BY title");
+
+ $f_sth->execute([$line['id'], $_SESSION['uid']]);
+
+ while ($fline = $f_sth->fetch()) {
+ $is_selected = (in_array($fline["id"], $default_ids)) ? "selected=\"1\"" : "";
+
+ $fline["title"] = " " . $fline["title"];
+
+ for ($i = 0; $i < $nest_level; $i++)
+ $fline["title"] = " " . $fline["title"];
+
+ $rv .= sprintf("<option $is_selected value='%d'>%s</option>",
+ $fline["id"], htmlspecialchars($fline["title"]));
+ }
+ }
+
+ if (!$root_id) {
+ $is_selected = in_array("CAT:0", $default_ids) ? "selected=\"1\"" : "";
+
+ $rv .= sprintf("<option $is_selected value='CAT:0'>%s</option>",
+ __("Uncategorized"));
+
+ $f_sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
+ WHERE cat_id IS NULL AND owner_uid = ? ORDER BY title");
+ $f_sth->execute([$_SESSION['uid']]);
+
+ while ($fline = $f_sth->fetch()) {
+ $is_selected = in_array($fline["id"], $default_ids) ? "selected=\"1\"" : "";
+
+ $fline["title"] = " " . $fline["title"];
+
+ for ($i = 0; $i < $nest_level; $i++)
+ $fline["title"] = " " . $fline["title"];
+
+ $rv .= sprintf("<option $is_selected value='%d'>%s</option>",
+ $fline["id"], htmlspecialchars($fline["title"]));
+ }
+ }
+
+ } else {
+ $sth = $pdo->prepare("SELECT id,title FROM ttrss_feeds
+ WHERE owner_uid = ? ORDER BY title");
+ $sth->execute([$_SESSION['uid']]);
+
+ while ($line = $sth->fetch()) {
+
+ $is_selected = (in_array($line["id"], $default_ids)) ? "selected=\"1\"" : "";
+
+ $rv .= sprintf("<option $is_selected value='%d'>%s</option>",
+ $line["id"], htmlspecialchars($line["title"]));
+ }
+ }
+
+ if (!$root_id) {
+ $rv .= "</select>";
+ }
+
+ return $rv;
+ }
}
diff --git a/classes/pref/labels.php b/classes/pref/labels.php
index a787ce388..5bc094d55 100644
--- a/classes/pref/labels.php
+++ b/classes/pref/labels.php
@@ -10,72 +10,12 @@ class Pref_Labels extends Handler_Protected {
function edit() {
$label_id = clean($_REQUEST['id']);
- $sth = $this->pdo->prepare("SELECT * FROM ttrss_labels2 WHERE
+ $sth = $this->pdo->prepare("SELECT id, caption, fg_color, bg_color FROM ttrss_labels2 WHERE
id = ? AND owner_uid = ?");
$sth->execute([$label_id, $_SESSION['uid']]);
- if ($line = $sth->fetch()) {
-
- print_hidden("id", "$label_id");
- print_hidden("op", "pref-labels");
- print_hidden("method", "save");
-
- print "<form onsubmit='return false;'>";
-
- print "<header>".__("Caption")."</header>";
-
- print "<section>";
-
- $fg_color = $line['fg_color'];
- $bg_color = $line['bg_color'] ? $line['bg_color'] : '#fff7d5';
-
- print "<input style='font-size : 16px; color : $fg_color; background : $bg_color; transition : background 0.1s linear'
- id='labelEdit_caption' name='caption' dojoType='dijit.form.ValidationTextBox'
- required='true' value=\"".htmlspecialchars($line['caption'])."\">";
-
- print "</section>";
-
- print "<header>" . __("Colors") . "</header>";
- print "<section>";
-
- print "<table>";
- print "<tr><th style='text-align : left'>".__("Foreground:")."</th><th style='text-align : left'>".__("Background:")."</th></tr>";
- print "<tr><td style='padding-right : 10px'>";
-
- print "<input dojoType='dijit.form.TextBox'
- style='display : none' id='labelEdit_fgColor'
- name='fg_color' value='$fg_color'>";
- print "<input dojoType='dijit.form.TextBox'
- style='display : none' id='labelEdit_bgColor'
- name='bg_color' value='$bg_color'>";
-
- print "<div dojoType='dijit.ColorPalette'>
- <script type='dojo/method' event='onChange' args='fg_color'>
- dijit.byId('labelEdit_fgColor').attr('value', fg_color);
- dijit.byId('labelEdit_caption').domNode.setStyle({color: fg_color});
- </script>
- </div>";
-
- print "</td><td>";
-
- print "<div dojoType='dijit.ColorPalette'>
- <script type='dojo/method' event='onChange' args='bg_color'>
- dijit.byId('labelEdit_bgColor').attr('value', bg_color);
- dijit.byId('labelEdit_caption').domNode.setStyle({backgroundColor: bg_color});
- </script>
- </div>";
-
- print "</td></tr></table>";
- print "</section>";
-
- print "<footer>";
- print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary' onclick='App.dialogOf(this).execute()'>".
- __('Save')."</button>";
- print "<button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>";
- print "</footer>";
-
- print "</form>";
+ if ($line = $sth->fetch(PDO::FETCH_ASSOC)) {
+ print json_encode($line);
}
}
@@ -197,7 +137,7 @@ class Pref_Labels extends Handler_Protected {
$sth->execute([$caption, $old_caption, $_SESSION['uid']]);
- print clean($_REQUEST["value"]);
+ print clean($_REQUEST["caption"]);
} else {
print $old_caption;
}
@@ -225,88 +165,64 @@ class Pref_Labels extends Handler_Protected {
$output = clean($_REQUEST["output"]);
if ($caption) {
-
if (Labels::create($caption)) {
if (!$output) {
print T_sprintf("Created label <b>%s</b>", htmlspecialchars($caption));
}
}
-
- if ($output == "select") {
- header("Content-Type: text/xml");
-
- print "<rpc-reply><payload>";
-
- print_label_select("select_label",
- $caption, "");
-
- print "</payload></rpc-reply>";
- }
}
-
- return;
}
function index() {
-
- print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
- print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>";
- print "<div dojoType='fox.Toolbar'>";
-
- print "<div dojoType='fox.form.DropDownButton'>".
- "<span>" . __('Select')."</span>";
- print "<div dojoType=\"dijit.Menu\" style=\"display: none;\">";
- print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(true)\"
- dojoType=\"dijit.MenuItem\">".__('All')."</div>";
- print "<div onclick=\"dijit.byId('labelTree').model.setAllChecked(false)\"
- dojoType=\"dijit.MenuItem\">".__('None')."</div>";
- print "</div></div>";
-
- print"<button dojoType=\"dijit.form.Button\" onclick=\"CommonDialogs.addLabel()\">".
- __('Create label')."</button dojoType=\"dijit.form.Button\"> ";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').removeSelected()\">".
- __('Remove')."</button dojoType=\"dijit.form.Button\"> ";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"dijit.byId('labelTree').resetColors()\">".
- __('Clear colors')."</button dojoType=\"dijit.form.Button\">";
-
-
- print "</div>"; #toolbar
- print "</div>"; #pane
- print "<div style='padding : 0px' dojoType=\"dijit.layout.ContentPane\" region=\"center\">";
-
- print "<div id=\"labellistLoading\">
- <img src='images/indicator_tiny.gif'>".
- __("Loading, please wait...")."</div>";
-
- print "<div dojoType=\"dojo.data.ItemFileWriteStore\" jsId=\"labelStore\"
- url=\"backend.php?op=pref-labels&method=getlabeltree\">
+ ?>
+ <div dojoType='dijit.layout.BorderContainer' gutters='false'>
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>
+ <div dojoType='fox.Toolbar'>
+ <div dojoType='fox.form.DropDownButton'>
+ <span><?= __('Select') ?></span>
+ <div dojoType='dijit.Menu' style='display: none'>
+ <div onclick="dijit.byId('labelTree').model.setAllChecked(true)"
+ dojoType='dijit.MenuItem'><?=('All') ?></div>
+ <div onclick="dijit.byId('labelTree').model.setAllChecked(false)"
+ dojoType='dijit.MenuItem'><?=('None') ?></div>
+ </div>
+ </div>
+
+ <button dojoType='dijit.form.Button' onclick='CommonDialogs.addLabel()'>
+ <?=('Create label') ?></button dojoType='dijit.form.Button'>
+
+ <button dojoType='dijit.form.Button' onclick="dijit.byId('labelTree').removeSelected()">
+ <?=('Remove') ?></button dojoType='dijit.form.Button'>
+
+ <button dojoType='dijit.form.Button' onclick="dijit.byId('labelTree').resetColors()">
+ <?=('Clear colors') ?></button dojoType='dijit.form.Button'>
+
+ </div>
+ </div>
+
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>
+ <div dojoType='dojo.data.ItemFileWriteStore' jsId='labelStore'
+ url='backend.php?op=pref-labels&method=getlabeltree'>
+ </div>
+
+ <div dojoType='lib.CheckBoxStoreModel' jsId='labelModel' store='labelStore'
+ query="{id:'root'}" rootId='root'
+ childrenAttrs='items' checkboxStrict='false' checkboxAll='false'>
+ </div>
+
+ <div dojoType='fox.PrefLabelTree' id='labelTree' model='labelModel' openOnClick='true'>
+ <script type='dojo/method' event='onClick' args='item'>
+ var id = String(item.id);
+ var bare_id = id.substr(id.indexOf(':')+1);
+
+ if (id.match('LABEL:')) {
+ dijit.byId('labelTree').editLabel(bare_id);
+ }
+ </script>
+ </div>
+ </div>
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefLabels") ?>
</div>
- <div dojoType=\"lib.CheckBoxStoreModel\" jsId=\"labelModel\" store=\"labelStore\"
- query=\"{id:'root'}\" rootId=\"root\"
- childrenAttrs=\"items\" checkboxStrict=\"false\" checkboxAll=\"false\">
- </div>
- <div dojoType=\"fox.PrefLabelTree\" id=\"labelTree\"
- model=\"labelModel\" openOnClick=\"true\">
- <script type=\"dojo/method\" event=\"onLoad\" args=\"item\">
- Element.hide(\"labellistLoading\");
- </script>
- <script type=\"dojo/method\" event=\"onClick\" args=\"item\">
- var id = String(item.id);
- var bare_id = id.substr(id.indexOf(':')+1);
-
- if (id.match('LABEL:')) {
- dijit.byId('labelTree').editLabel(bare_id);
- }
- </script>
- </div>";
-
- print "</div>"; #pane
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefLabels");
-
- print "</div>"; #container
-
+ <?php
}
}
diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php
index d40dc87c0..0d0dcadbc 100644
--- a/classes/pref/prefs.php
+++ b/classes/pref/prefs.php
@@ -4,6 +4,7 @@ class Pref_Prefs extends Handler_Protected {
private $pref_help = [];
private $pref_item_map = [];
+ private $pref_help_bottom = [];
private $pref_blacklist = [];
private $profile_blacklist = [];
@@ -122,8 +123,8 @@ class Pref_Prefs extends Handler_Protected {
function changepassword() {
- if (defined('_TTRSS_DEMO_INSTANCE')) {
- print "ERROR: ".format_error("Disabled in demo version.");
+ if (Config::get(Config::FORBID_PASSWORD_CHANGES)) {
+ print "ERROR: ".format_error("Access forbidden.");
return;
}
@@ -235,7 +236,7 @@ class Pref_Prefs extends Handler_Protected {
$tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('NEWMAIL', $email);
- $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
+ $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl->addBlock('message');
@@ -267,39 +268,12 @@ class Pref_Prefs extends Handler_Protected {
AND owner_uid = :uid");
$sth->execute([":profile" => $_SESSION['profile'], ":uid" => $_SESSION['uid']]);
- $this->initialize_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
+ $this->_init_user_prefs($_SESSION["uid"], $_SESSION["profile"]);
echo __("Your preferences are now set to default values.");
}
- function index() {
-
- global $access_level_names;
-
- $_SESSION["prefs_op_result"] = "";
-
- print "<div dojoType='dijit.layout.AccordionContainer' region='center'>";
- print "<div dojoType='dijit.layout.AccordionPane'
- title=\"<i class='material-icons'>person</i> ".__('Personal data / Authentication')."\">";
-
- print "<div dojoType='dijit.layout.TabContainer'>";
- print "<div dojoType='dijit.layout.ContentPane' title=\"".__('Personal data')."\">";
-
- print "<form dojoType='dijit.form.Form' id='changeUserdataForm'>";
-
- print "<script type='dojo/method' event='onSubmit' args='evt'>
- evt.preventDefault();
- if (this.validate()) {
- Notify.progress('Saving data...', true);
-
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- notify_callback2(transport);
- } });
-
- }
- </script>";
+ private function index_auth_personal() {
$sth = $this->pdo->prepare("SELECT email,full_name,otp_enabled,
access_level FROM ttrss_users
@@ -311,179 +285,196 @@ class Pref_Prefs extends Handler_Protected {
$full_name = htmlspecialchars($row["full_name"]);
$otp_enabled = sql_bool_to_bool($row["otp_enabled"]);
- print "<fieldset>";
- print "<label>".__('Full name:')."</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value='$full_name'>";
- print "</fieldset>";
+ ?>
+ <form dojoType='dijit.form.Form'>
- print "<fieldset>";
- print "<label>".__('E-mail:')."</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value='$email'>";
- print "</fieldset>";
-
- if (!SINGLE_USER_MODE && !empty($_SESSION["hide_hello"])) {
-
- $access_level = $row["access_level"];
- print "<fieldset>";
- print "<label>".__('Access level:')."</label>";
- print $access_level_names[$access_level];
- print "</fieldset>";
- }
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "changeemail") ?>
- print_hidden("op", "pref-prefs");
- print_hidden("method", "changeemail");
+ <script type="dojo/method" event="onSubmit" args="evt">
+ evt.preventDefault();
+ if (this.validate()) {
+ Notify.progress('Saving data...', true);
+ xhr.post("backend.php", this.getValues(), (reply) => {
+ Notify.info(reply);
+ })
+ }
+ </script>
- print "<hr/>";
+ <fieldset>
+ <label><?= __('Full name:') ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' name='full_name' required='1' value="<?= $full_name ?>">
+ </fieldset>
- print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".
- __("Save data")."</button>";
+ <fieldset>
+ <label><?= __('E-mail:') ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' name='email' required='1' value="<?= $email ?>">
+ </fieldset>
- print "</form>";
+ <hr/>
- print "</div>"; # content pane
+ <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>
+ <?= __("Save data") ?>
+ </button>
+ </form>
+ <?php
+ }
+ private function index_auth_password() {
if ($_SESSION["auth_module"]) {
$authenticator = PluginHost::getInstance()->get_plugin($_SESSION["auth_module"]);
} else {
$authenticator = false;
}
- print "<div dojoType='dijit.layout.ContentPane' title=\"" . __('Password') . "\">";
+ $otp_enabled = $this->is_otp_enabled();
if ($authenticator && method_exists($authenticator, "change_password")) {
+ ?>
- print "<div style='display : none' id='pwd_change_infobox'></div>";
-
- print "<form dojoType='dijit.form.Form'>";
-
- print "<script type='dojo/method' event='onSubmit' args='evt'>
- evt.preventDefault();
- if (this.validate()) {
- Notify.progress('Changing password...', true);
+ <div style='display : none' id='pwd_change_infobox'></div>
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- Notify.close();
- if (transport.responseText.indexOf('ERROR: ') == 0) {
+ <form dojoType='dijit.form.Form'>
- $('pwd_change_infobox').innerHTML =
- transport.responseText.replace('ERROR: ', '');
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "changepassword") ?>
- } else {
- $('pwd_change_infobox').innerHTML =
- transport.responseText.replace('ERROR: ', '');
+ <!-- TODO: return JSON the backend call -->
+ <script type="dojo/method" event="onSubmit" args="evt">
+ evt.preventDefault();
+ if (this.validate()) {
+ Notify.progress('Saving data...', true);
+ xhr.post("backend.php", this.getValues(), (reply) => {
+ Notify.close();
+ if (reply.indexOf('ERROR: ') == 0) {
- var warn = $('default_pass_warning');
- if (warn) Element.hide(warn);
- }
+ App.byId('pwd_change_infobox').innerHTML =
+ reply.replace('ERROR: ', '');
- new Effect.Appear('pwd_change_infobox');
+ } else {
+ App.byId('pwd_change_infobox').innerHTML =
+ reply.replace('ERROR: ', '');
- }});
- this.reset();
- }
- </script>";
+ const warn = App.byId('default_pass_warning');
+ if (warn) Element.hide(warn);
+ }
- if ($otp_enabled) {
- print_notice(__("Changing your current password will disable OTP."));
- }
+ Element.show('pwd_change_infobox');
+ })
+ }
+ </script>
- print "<fieldset>";
- print "<label>" . __("Old password:") . "</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>";
- print "</fieldset>";
+ <?php if ($otp_enabled) {
+ print_notice(__("Changing your current password will disable OTP."));
+ } ?>
- print "<fieldset>";
- print "<label>" . __("New password:") . "</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' type='password' regexp='^[^<>]+' required='1' name='new_password'>";
- print "</fieldset>";
+ <fieldset>
+ <label><?= __("Old password:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='old_password'>
+ </fieldset>
- print "<fieldset>";
- print "<label>" . __("Confirm password:") . "</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' type='password' regexp='^[^<>]+' required='1' name='confirm_password'>";
- print "</fieldset>";
+ <fieldset>
+ <label><?= __("New password:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' type='password' regexp='^[^<>]+' required='1' name='new_password'>
+ </fieldset>
- print_hidden("op", "pref-prefs");
- print_hidden("method", "changepassword");
+ <fieldset>
+ <label><?= __("Confirm password:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' type='password' regexp='^[^<>]+' required='1' name='confirm_password'>
+ </fieldset>
- print "<hr/>";
+ <hr/>
- print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>" .
- __("Change password") . "</button>";
+ <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>
+ <?= __("Change password") ?>
+ </button>
+ </form>
- print "</form>";
+ <?php
} else {
print_notice(T_sprintf("Authentication module used for this session (<b>%s</b>) does not provide an ability to set passwords.",
$_SESSION["auth_module"]));
}
+ }
- print "</div>"; # content pane
+ private function index_auth_app_passwords() {
+ print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP.");
+ ?>
- print "<div dojoType='dijit.layout.ContentPane' title=\"" . __('App passwords') . "\">";
+ <div id='app_passwords_holder'>
+ <?php $this->appPasswordList() ?>
+ </div>
- print_notice("You can create separate passwords for API clients. Using one is required if you enable OTP.");
+ <hr>
- print "<div id='app_passwords_holder'>";
- $this->appPasswordList();
- print "</div>";
+ <button style='float : left' class='alt-primary' dojoType='dijit.form.Button' onclick="Helpers.AppPasswords.generate()">
+ <?= __('Generate new password') ?>
+ </button>
- print "<hr>";
+ <button style='float : left' class='alt-danger' dojoType='dijit.form.Button'
+ onclick="Helpers.AppPasswords.removeSelected()">
+ <?= __('Remove selected passwords') ?>
+ </button>
- print "<button style='float : left' class='alt-primary' dojoType='dijit.form.Button'
- onclick=\"Helpers.AppPasswords.generate()\">" .
- __('Generate new password') . "</button> ";
+ <?php
+ }
- print "<button style='float : left' class='alt-danger' dojoType='dijit.form.Button'
- onclick=\"Helpers.AppPasswords.removeSelected()\">" .
- __('Remove selected passwords') . "</button>";
+ private function is_otp_enabled() {
+ $sth = $this->pdo->prepare("SELECT otp_enabled FROM ttrss_users
+ WHERE id = ?");
+ $sth->execute([$_SESSION["uid"]]);
- print "</div>"; # content pane
+ if ($row = $sth->fetch()) {
+ return sql_bool_to_bool($row["otp_enabled"]);
+ }
- print "<div dojoType='dijit.layout.ContentPane' title=\"".__('One time passwords / Authenticator')."\">";
+ return false;
+ }
- if ($_SESSION["auth_module"] == "auth_internal") {
+ private function index_auth_2fa() {
+ $otp_enabled = $this->is_otp_enabled();
+ if ($_SESSION["auth_module"] == "auth_internal") {
if ($otp_enabled) {
-
print_warning("One time passwords are currently enabled. Enter your current password below to disable.");
+ ?>
+
+ <form dojoType='dijit.form.Form'>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "otpdisable") ?>
+
+ <!-- TODO: return JSON from the backend call -->
+ <script type="dojo/method" event="onSubmit" args="evt">
+ evt.preventDefault();
+ if (this.validate()) {
+ Notify.progress('Saving data...', true);
+ xhr.post("backend.php", this.getValues(), (reply) => {
+ Notify.close();
+
+ if (reply.indexOf('ERROR: ') == 0) {
+ Notify.error(reply.replace('ERROR: ', ''));
+ } else {
+ window.location.reload();
+ }
+ })
+ }
+ </script>
- print "<form dojoType='dijit.form.Form'>";
-
- print "<script type='dojo/method' event='onSubmit' args='evt'>
- evt.preventDefault();
- if (this.validate()) {
- Notify.progress('Disabling OTP', true);
-
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- Notify.close();
- if (transport.responseText.indexOf('ERROR: ') == 0) {
- Notify.error(transport.responseText.replace('ERROR: ', ''));
- } else {
- window.location.reload();
- }
- }});
- this.reset();
- }
- </script>";
-
- print "<fieldset>";
- print "<label>".__("Your password:")."</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>";
- print "</fieldset>";
+ <fieldset>
+ <label><?= __("Your password:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>
+ </fieldset>
- print_hidden("op", "pref-prefs");
- print_hidden("method", "otpdisable");
+ <hr/>
- print "<hr/>";
+ <button dojoType='dijit.form.Button' type='submit' class='alt-danger'>
+ <?= __("Disable OTP") ?>
+ </button>
- print "<button dojoType='dijit.form.Button' type='submit'>".
- __("Disable OTP")."</button>";
+ </form>
- print "</form>";
+ <?php
} else {
@@ -492,7 +483,6 @@ class Pref_Prefs extends Handler_Protected {
if (function_exists("imagecreatefromstring")) {
print "<h3>" . __("Scan the following code by the Authenticator application or copy the key manually") . "</h3>";
-
$csrf_token_hash = sha1($_SESSION["csrf_token"]);
print "<img alt='otp qr-code' src='backend.php?op=pref-prefs&method=otpqrcode&csrf_token_hash=$csrf_token_hash'>";
} else {
@@ -500,108 +490,87 @@ class Pref_Prefs extends Handler_Protected {
print "<h3>" . __("Use the following OTP key with a compatible Authenticator application") . "</h3>";
}
- print "<form dojoType='dijit.form.Form' id='changeOtpForm'>";
-
$otp_secret = $this->otpsecret();
+ ?>
+
+ <form dojoType='dijit.form.Form'>
+
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "otpenable") ?>
+
+ <fieldset>
+ <label><?= __("OTP Key:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value="<?= $otp_secret ?>" size='32'>
+ </fieldset>
+
+ <!-- TODO: return JSON from the backend call -->
+ <script type="dojo/method" event="onSubmit" args="evt">
+ evt.preventDefault();
+ if (this.validate()) {
+ Notify.progress('Saving data...', true);
+ xhr.post("backend.php", this.getValues(), (reply) => {
+ Notify.close();
+
+ if (reply.indexOf('ERROR:') == 0) {
+ Notify.error(reply.replace('ERROR:', ''));
+ } else {
+ window.location.reload();
+ }
+ })
+ }
+ </script>
- print "<fieldset>";
- print "<label>".__("OTP Key:")."</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' disabled='disabled' value='$otp_secret' size='32'>";
- print "</fieldset>";
-
- print_hidden("op", "pref-prefs");
- print_hidden("method", "otpenable");
-
- print "<script type='dojo/method' event='onSubmit' args='evt'>
- evt.preventDefault();
- if (this.validate()) {
- Notify.progress('Saving data...', true);
-
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- Notify.close();
- if (transport.responseText.indexOf('ERROR:') == 0) {
- Notify.error(transport.responseText.replace('ERROR:', ''));
- } else {
- window.location.reload();
- }
- } });
-
- }
- </script>";
-
- print "<fieldset>";
- print "<label>".__("Your password:")."</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' type='password' required='1'
- name='password'>";
- print "</fieldset>";
+ <fieldset>
+ <label><?= __("Your password:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' type='password' required='1' name='password'>
+ </fieldset>
- print "<fieldset>";
- print "<label>".__("One time password:")."</label>";
- print "<input dojoType='dijit.form.ValidationTextBox' autocomplete='off'
- required='1' name='otp'>";
- print "</fieldset>";
+ <fieldset>
+ <label><?= __("One time password:") ?></label>
+ <input dojoType='dijit.form.ValidationTextBox' autocomplete='off' required='1' name='otp'>
+ </fieldset>
- print "<hr/>";
- print "<button dojoType='dijit.form.Button' type='submit' class='alt-primary'>".
- __("Enable OTP")."</button>";
+ <hr/>
- print "</form>";
+ <button dojoType='dijit.form.Button' type='submit' class='alt-primary'>
+ <?= __("Enable OTP") ?>
+ </button>
+ </form>
+ <?php
}
-
} else {
print_notice("OTP is only available when using <b>auth_internal</b> authentication module.");
}
+ }
- print "</div>"; # content pane
-
- print "</div>"; # tab container
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsAuth");
-
- print "</div>"; #pane
-
- print "<div dojoType='dijit.layout.AccordionPane' selected='true'
- title=\"<i class='material-icons'>settings</i> ".__('Preferences')."\">";
-
- print "<form dojoType='dijit.form.Form' id='changeSettingsForm'>";
-
- print "<script type='dojo/method' event='onSubmit' args='evt, quit'>
- if (evt) evt.preventDefault();
- if (this.validate()) {
- console.log(dojo.objectToQuery(this.getValues()));
-
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- var msg = transport.responseText;
- if (quit) {
- document.location.href = 'index.php';
- } else {
- if (msg == 'PREFS_NEED_RELOAD') {
- window.location.reload();
- } else {
- Notify.info(msg);
- }
- }
- } });
- }
- </script>";
-
- print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
-
- print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
+ function index_auth() {
+ ?>
+ <div dojoType='dijit.layout.TabContainer'>
+ <div dojoType='dijit.layout.ContentPane' title="<?= __('Personal data') ?>">
+ <?php $this->index_auth_personal() ?>
+ </div>
+ <div dojoType='dijit.layout.ContentPane' title="<?= __('Password') ?>">
+ <?php $this->index_auth_password() ?>
+ </div>
+ <div dojoType='dijit.layout.ContentPane' title="<?= __('App passwords') ?>">
+ <?php $this->index_auth_app_passwords() ?>
+ </div>
+ <div dojoType='dijit.layout.ContentPane' title="<?= __('Authenticator (OTP)') ?>">
+ <?php $this->index_auth_2fa() ?>
+ </div>
+ </div>
+ <?php
+ }
+ private function index_prefs_list() {
$profile = $_SESSION["profile"] ?? null;
if ($profile) {
print_notice(__("Some preferences are only available in default profile."));
-
- $this->initialize_user_prefs($_SESSION["uid"], $profile);
+ $this->_init_user_prefs($_SESSION["uid"], $profile);
} else {
- $this->initialize_user_prefs($_SESSION["uid"]);
+ $this->_init_user_prefs($_SESSION["uid"]);
}
$prefs_available = [];
@@ -632,7 +601,7 @@ class Pref_Prefs extends Handler_Protected {
}
$pref_name = $line["pref_name"];
- $short_desc = $this->getShortDesc($pref_name);
+ $short_desc = $this->_get_short_desc($pref_name);
if (!$short_desc)
continue;
@@ -640,7 +609,7 @@ class Pref_Prefs extends Handler_Protected {
$prefs_available[$pref_name] = [
'type_name' => $line["type_name"],
'value' => $line['value'],
- 'help_text' => $this->getHelpText($pref_name),
+ 'help_text' => $this->_get_help_text($pref_name),
'short_desc' => $short_desc
];
}
@@ -656,11 +625,13 @@ class Pref_Prefs extends Handler_Protected {
continue;
}
- if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && DB_TYPE != "pgsql") {
+ if ($pref_name == "DEFAULT_SEARCH_LANGUAGE" && Config::get(Config::DB_TYPE) != "pgsql") {
continue;
}
- if (isset($prefs_available[$pref_name]) &&$item = $prefs_available[$pref_name]) {
+ if (isset($prefs_available[$pref_name])) {
+
+ $item = $prefs_available[$pref_name];
print "<fieldset class='prefs'>";
@@ -672,14 +643,14 @@ class Pref_Prefs extends Handler_Protected {
$type_name = $item['type_name'];
if ($pref_name == "USER_LANGUAGE") {
- print_select_hash($pref_name, $value, get_translations(),
- "style='width : 220px; margin : 0px' dojoType='fox.form.Select'");
+ print \Controls\select_hash($pref_name, $value, get_translations(),
+ ["style" => 'width : 220px; margin : 0px']);
} else if ($pref_name == "USER_TIMEZONE") {
$timezones = explode("\n", file_get_contents("lib/timezones.txt"));
- print_select($pref_name, $value, $timezones, 'dojoType="dijit.form.FilteringSelect"');
+ print \Controls\select_tag($pref_name, $value, $timezones, ["dojoType" => "dijit.form.FilteringSelect"]);
} else if ($pref_name == "BLACKLISTED_TAGS") { # TODO: other possible <textarea> prefs go here
@@ -715,7 +686,7 @@ class Pref_Prefs extends Handler_Protected {
print "</select>";
print " <button dojoType=\"dijit.form.Button\" class='alt-info'
- onclick=\"Helpers.customizeCSS()\">" . __('Customize') . "</button>";
+ onclick=\"Helpers.Prefs.customizeCSS()\">" . __('Customize') . "</button>";
print " <button dojoType='dijit.form.Button' onclick='window.open(\"https://tt-rss.org/wiki/Themes\")'>
<i class='material-icons'>open_in_new</i> ".__("More themes...")."</button>";
@@ -724,70 +695,60 @@ class Pref_Prefs extends Handler_Protected {
global $update_intervals_nodefault;
- print_select_hash($pref_name, $value, $update_intervals_nodefault,
- 'dojoType="fox.form.Select"');
+ print \Controls\select_hash($pref_name, $value, $update_intervals_nodefault);
+
} else if ($pref_name == "DEFAULT_SEARCH_LANGUAGE") {
- print_select($pref_name, $value, Pref_Feeds::get_ts_languages(),
- 'dojoType="fox.form.Select"');
+ print \Controls\select_tag($pref_name, $value, Pref_Feeds::get_ts_languages());
} else if ($type_name == "bool") {
array_push($listed_boolean_prefs, $pref_name);
- $checked = ($value == "true") ? "checked=\"checked\"" : "";
-
- if ($pref_name == "PURGE_UNREAD_ARTICLES" && FORCE_ARTICLE_PURGE != 0) {
- $disabled = "disabled=\"1\"";
- $checked = "checked=\"checked\"";
+ if ($pref_name == "PURGE_UNREAD_ARTICLES" && Config::get(Config::FORCE_ARTICLE_PURGE) != 0) {
+ $is_disabled = true;
+ $is_checked = true;
} else {
- $disabled = "";
+ $is_disabled = false;
+ $is_checked = ($value == "true");
}
- print "<input type='checkbox' name='$pref_name' $checked $disabled
- dojoType='dijit.form.CheckBox' id='CB_$pref_name' value='1'>";
+ print \Controls\checkbox_tag($pref_name, $is_checked, "true",
+ ["disabled" => $is_disabled], "CB_$pref_name");
} else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE',
'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT'])) {
- $regexp = ($type_name == 'integer') ? 'regexp="^\d*$"' : '';
-
- if ($pref_name == "PURGE_OLD_DAYS" && FORCE_ARTICLE_PURGE != 0) {
- $disabled = "disabled='1'";
- $value = FORCE_ARTICLE_PURGE;
+ if ($pref_name == "PURGE_OLD_DAYS" && Config::get(Config::FORCE_ARTICLE_PURGE) != 0) {
+ $attributes = ["disabled" => true, "required" => true];
+ $value = Config::get(Config::FORCE_ARTICLE_PURGE);
} else {
- $disabled = "";
+ $attributes = ["required" => true];
}
if ($type_name == 'integer')
- print "<input dojoType=\"dijit.form.NumberSpinner\"
- required='1' $disabled
- name=\"$pref_name\" value=\"$value\">";
+ print \Controls\number_spinner_tag($pref_name, $value, $attributes);
else
- print "<input dojoType=\"dijit.form.TextBox\"
- required='1' $regexp $disabled
- name=\"$pref_name\" value=\"$value\">";
+ print \Controls\input_tag($pref_name, $value, "text", $attributes);
} else if ($pref_name == "SSL_CERT_SERIAL") {
- print "<input dojoType='dijit.form.ValidationTextBox'
- id='SSL_CERT_SERIAL' readonly='1'
- name=\"$pref_name\" value=\"$value\">";
+ print \Controls\input_tag($pref_name, $value, "text", ["readonly" => true], "SSL_CERT_SERIAL");
$cert_serial = htmlspecialchars(get_ssl_certificate_id());
- $has_serial = ($cert_serial) ? "false" : "true";
+ $has_serial = ($cert_serial) ? true : false;
- print "<button dojoType='dijit.form.Button' disabled='$has_serial'
- onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')\">" .
- __('Register') . "</button>";
+ print \Controls\button_tag(__('Register'), "", [
+ "disabled" => !$has_serial,
+ "onclick" => "dijit.byId('SSL_CERT_SERIAL').attr('value', '$cert_serial')"]);
- print "<button dojoType='dijit.form.Button' class='alt-danger'
- onclick=\"dijit.byId('SSL_CERT_SERIAL').attr('value', '')\">" .
- __('Clear') . "</button>";
+ print \Controls\button_tag(__('Clear'), "", [
+ "class" => "alt-danger",
+ "onclick" => "dijit.byId('SSL_CERT_SERIAL').attr('value', '')"]);
- print "<button dojoType='dijit.form.Button' class='alt-info'
- onclick='window.open(\"https://tt-rss.org/wiki/SSL%20Certificate%20Authentication\")'>
- <i class='material-icons'>help</i> ".__("More info...")."</button>";
+ print \Controls\button_tag(\Controls\icon("help") . " " . __("More info..."), "", [
+ "class" => "alt-info",
+ "onclick" => "window.open('https://tt-rss.org/wiki/SSL%20Certificate%20Authentication')"]);
} else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
print "<input dojoType=\"dijit.form.ValidationTextBox\"
@@ -808,204 +769,252 @@ class Pref_Prefs extends Handler_Protected {
}
}
}
+ print \Controls\hidden_tag("boolean_prefs", htmlspecialchars(join(",", $listed_boolean_prefs)));
+ }
- $listed_boolean_prefs = htmlspecialchars(join(",", $listed_boolean_prefs));
-
- print_hidden("boolean_prefs", "$listed_boolean_prefs");
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsInside");
-
- print '</div>'; # inside pane
- print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
-
- print_hidden("op", "pref-prefs");
- print_hidden("method", "saveconfig");
+ private function index_prefs() {
+ ?>
+ <form dojoType='dijit.form.Form' id='changeSettingsForm'>
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "saveconfig") ?>
- print "<div dojoType=\"fox.form.ComboButton\" type=\"submit\" class=\"alt-primary\">
- <span>".__('Save configuration')."</span>
- <div dojoType=\"dijit.DropDownMenu\">
- <div dojoType=\"dijit.MenuItem\"
- onclick=\"dijit.byId('changeSettingsForm').onSubmit(null, true)\">".
- __("Save and exit preferences")."</div>
+ <script type="dojo/method" event="onSubmit" args="evt, quit">
+ if (evt) evt.preventDefault();
+ if (this.validate()) {
+ xhr.post("backend.php", this.getValues(), (reply) => {
+ if (quit) {
+ document.location.href = 'index.php';
+ } else {
+ if (reply == 'PREFS_NEED_RELOAD') {
+ window.location.reload();
+ } else {
+ Notify.info(reply);
+ }
+ }
+ })
+ }
+ </script>
+
+ <div dojoType="dijit.layout.BorderContainer" gutters="false">
+ <div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">
+ <?php $this->index_prefs_list() ?>
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsInside") ?>
+ </div>
+ <div dojoType="dijit.layout.ContentPane" region="bottom">
+
+ <div dojoType="fox.form.ComboButton" type="submit" class="alt-primary">
+ <span><?= __('Save configuration') ?></span>
+ <div dojoType="dijit.DropDownMenu">
+ <div dojoType="dijit.MenuItem" onclick="dijit.byId('changeSettingsForm').onSubmit(null, true)">
+ <?= __("Save and exit preferences") ?>
+ </div>
+ </div>
+ </div>
+
+ <button dojoType="dijit.form.Button" onclick="return Helpers.Profiles.edit()">
+ <?= __('Manage profiles') ?>
+ </button>
+
+ <button dojoType="dijit.form.Button" class="alt-danger" onclick="return Helpers.Prefs.confirmReset()">
+ <?= __('Reset to defaults') ?>
+ </button>
+
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsOutside") ?>
+ </div>
</div>
- </div>";
-
- print "<button dojoType=\"dijit.form.Button\" onclick=\"return Helpers.editProfiles()\">".
- __('Manage profiles')."</button> ";
-
- print "<button dojoType=\"dijit.form.Button\" class=\"alt-danger\" onclick=\"return Helpers.confirmReset()\">".
- __('Reset to defaults')."</button>";
-
- print "&nbsp;";
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefPrefsPrefsOutside");
-
- print "</form>";
- print '</div>'; # inner pane
- print '</div>'; # border container
-
- print "</div>"; #pane
-
- print "<div dojoType=\"dijit.layout.AccordionPane\"
- title=\"<i class='material-icons'>extension</i> ".__('Plugins')."\">";
-
- print "<form dojoType=\"dijit.form.Form\" id=\"changePluginsForm\">";
-
- print "<script type=\"dojo/method\" event=\"onSubmit\" args=\"evt\">
- evt.preventDefault();
- if (this.validate()) {
- Notify.progress('Saving data...', true);
-
- new Ajax.Request('backend.php', {
- parameters: dojo.objectToQuery(this.getValues()),
- onComplete: function(transport) {
- Notify.close();
- if (confirm(__('Selected plugins have been enabled. Reload?'))) {
- window.location.reload();
- }
- } });
-
- }
- </script>";
-
- print_hidden("op", "pref-prefs");
- print_hidden("method", "setplugins");
-
- print '<div dojoType="dijit.layout.BorderContainer" gutters="false">';
- print '<div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">';
-
- if (ini_get("open_basedir") && function_exists("curl_init") && !defined("NO_CURL")) {
- print_warning("Your PHP configuration has open_basedir restrictions enabled. Some plugins relying on CURL for functionality may not work correctly.");
- }
-
- if ($_SESSION["safe_mode"]) {
- print_error("You have logged in using safe mode, no user plugins will be actually enabled until you login again.");
- }
-
- $feed_handler_whitelist = [ "Af_Comics" ];
-
- $feed_handlers = array_merge(
- PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED),
- PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED),
- PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED));
-
- $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) {
- return in_array(get_class($plugin), $feed_handler_whitelist) === false; });
-
- if (count($feed_handlers) > 0) {
- print_error(
- T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" ,
- implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers))
- ) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)"
- );
- }
+ </form>
+ <?php
+ }
- print "<h2>".__("System plugins")."</h2>";
+ private function index_plugins_system() {
print_notice("System plugins are enabled in <strong>config.php</strong> for all users.");
- $system_enabled = array_map("trim", explode(",", PLUGINS));
- $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
+ $system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS)));
$tmppluginhost = new PluginHost();
$tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
- //$tmppluginhost->load_data(true);
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
if ($about[3] ?? false) {
- if (in_array($name, $system_enabled)) {
- $checked = "checked='1'";
- } else {
- $checked = "";
- }
-
- print "<fieldset class='prefs plugin'>
- <label>$name:</label>
- <label class='checkbox description text-muted' id='PLABEL-$name'>
- <input disabled='1'
- dojoType='dijit.form.CheckBox' $checked type='checkbox'>
- ".htmlspecialchars($about[1]). "</label>";
-
- if ($about[4] ?? false) {
- print "<button dojoType='dijit.form.Button' class='alt-info'
- onclick='window.open(\"".htmlspecialchars($about[4])."\")'>
- <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>";
- }
-
- print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>".
- htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])).
- "</div>";
-
- print "</fieldset>";
-
+ $is_checked = in_array($name, $system_enabled) ? "checked" : "";
+ ?>
+ <fieldset class='prefs plugin'>
+ <label><?= $name ?>:</label>
+ <label class='checkbox description text-muted' id="PLABEL-<?= htmlspecialchars($name) ?>">
+ <input disabled='1' dojoType='dijit.form.CheckBox' <?= $is_checked ?> type='checkbox'><?= htmlspecialchars($about[1]) ?>
+ </label>
+
+ <?php if ($about[4] ?? false) { ?>
+ <button dojoType='dijit.form.Button' class='alt-info'
+ onclick='window.open("<?= htmlspecialchars($about[4]) ?>")'>
+ <i class='material-icons'>open_in_new</i> <?= __("More info...") ?></button>
+ <?php } ?>
+
+ <div dojoType='dijit.Tooltip' connectId='PLABEL-<?= htmlspecialchars($name) ?>' position='after'>
+ <?= htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])) ?>
+ </div>
+ </fieldset>
+ <?php
}
}
+ }
- print "<h2>".__("User plugins")."</h2>";
+ private function index_plugins_user() {
+ $system_enabled = array_map("trim", explode(",", (string)Config::get(Config::PLUGINS)));
+ $user_enabled = array_map("trim", explode(",", get_pref("_ENABLED_PLUGINS")));
+
+ $tmppluginhost = new PluginHost();
+ $tmppluginhost->load_all($tmppluginhost::KIND_ALL, $_SESSION["uid"], true);
foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
$about = $plugin->about();
if (empty($about[3]) || $about[3] == false) {
- $checked = "";
- $disabled = "";
+ $is_checked = "";
+ $is_disabled = "";
if (in_array($name, $system_enabled)) {
- $checked = "checked='1'";
- $disabled = "disabled='1'";
+ $is_checked = "checked='1'";
+ $is_disabled = "disabled='1'";
} else if (in_array($name, $user_enabled)) {
- $checked = "checked='1'";
+ $is_checked = "checked='1'";
}
- print "<fieldset class='prefs plugin'>
- <label>$name:</label>
- <label class='checkbox description text-muted' id='PLABEL-$name'>
- <input name='plugins[]' value='$name' dojoType='dijit.form.CheckBox' $checked $disabled type='checkbox'>
- ".htmlspecialchars($about[1])."</label>";
-
- if (count($tmppluginhost->get_all($plugin)) > 0) {
- if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) {
- print " <button dojoType='dijit.form.Button'
- onclick=\"Helpers.clearPluginData('$name')\">
- <i class='material-icons'>clear</i> ".__("Clear data")."</button>";
+ ?>
+
+ <fieldset class='prefs plugin'>
+ <label><?= $name ?>:</label>
+ <label class='checkbox description text-muted' id="PLABEL-<?= htmlspecialchars($name) ?>">
+ <input name='plugins[]' value="<?= htmlspecialchars($name) ?>"
+ dojoType='dijit.form.CheckBox' <?= $is_checked ?> <?= $is_disabled ?> type='checkbox'>
+ <?= htmlspecialchars($about[1]) ?>
+ </input>
+ </label>
+
+ <?php if (count($tmppluginhost->get_all($plugin)) > 0) {
+ if (in_array($name, $system_enabled) || in_array($name, $user_enabled)) { ?>
+ <button dojoType='dijit.form.Button'
+ onclick='Helpers.Prefs.clearPluginData("<?= htmlspecialchars($name) ?>")'>
+ <i class='material-icons'>clear</i> <?= __("Clear data") ?></button>
+ <?php }
+ } ?>
+
+ <?php if ($about[4] ?? false) { ?>
+ <button dojoType='dijit.form.Button' class='alt-info'
+ onclick='window.open("<?= htmlspecialchars($about[4]) ?>")'>
+ <i class='material-icons'>open_in_new</i> <?= __("More info...") ?></button>
+ <?php } ?>
+
+ <div dojoType='dijit.Tooltip' connectId="PLABEL-<?= htmlspecialchars($name) ?>" position='after'>
+ <?= htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])) ?>
+ </div>
+
+ </fieldset>
+ <?php
+ }
+ }
+ }
+
+ function index_plugins() {
+ ?>
+ <form dojoType="dijit.form.Form" id="changePluginsForm">
+ <script type="dojo/method" event="onSubmit" args="evt">
+ evt.preventDefault();
+ if (this.validate()) {
+ xhr.post("backend.php", this.getValues(), () => {
+ Notify.close();
+ if (confirm(__('Selected plugins have been enabled. Reload?'))) {
+ window.location.reload();
+ }
+ })
}
- }
+ </script>
- if ($about[4] ?? false) {
- print " <button dojoType='dijit.form.Button' class='alt-info'
- onclick='window.open(\"".htmlspecialchars($about[4])."\")'>
- <i class='material-icons'>open_in_new</i> ".__("More info...")."</button>";
- }
+ <?= \Controls\hidden_tag("op", "pref-prefs") ?>
+ <?= \Controls\hidden_tag("method", "setplugins") ?>
- print "<div dojoType='dijit.Tooltip' connectId='PLABEL-$name' position='after'>".
- htmlspecialchars(T_sprintf("v%.2f, by %s", $about[0], $about[2])).
- "</div>";
+ <div dojoType="dijit.layout.BorderContainer" gutters="false">
+ <div dojoType="dijit.layout.ContentPane" region="center" style="overflow-y : auto">
+ <?php
+ if (!empty($_SESSION["safe_mode"])) {
+ print_error("You have logged in using safe mode, no user plugins will be actually enabled until you login again.");
+ }
- print "</fieldset>";
- }
- }
+ $feed_handler_whitelist = [ "Af_Comics" ];
- print "</div>"; #content-pane
- print '<div dojoType="dijit.layout.ContentPane" region="bottom">';
+ $feed_handlers = array_merge(
+ PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED),
+ PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED),
+ PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED));
- print "<button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open(\"https://tt-rss.org/wiki/Plugins\")'>
- <i class='material-icons'>help</i> ".__("More info...")."</button>";
+ $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) {
+ return in_array(get_class($plugin), $feed_handler_whitelist) === false; });
- print "<button dojoType='dijit.form.Button' class='alt-primary' type='submit'>".
- __("Enable selected plugins")."</button>";
- print "</div>"; #pane
+ if (count($feed_handlers) > 0) {
+ print_error(
+ T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" ,
+ implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers))
+ ) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)"
+ );
+ }
+ ?>
- print "</div>"; #pane
- print "</div>"; #border-container
+ <h2><?= __("System plugins") ?></h2>
- print "</form>";
+ <?php $this->index_plugins_system() ?>
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefPrefs");
+ <h2><?= __("User plugins") ?></h2>
- print "</div>"; #container
+ <?php $this->index_plugins_user() ?>
+ </div>
+ <div dojoType="dijit.layout.ContentPane" region="bottom">
+ <button dojoType='dijit.form.Button' style='float : left' class='alt-info' onclick='window.open("https://tt-rss.org/wiki/Plugins")'>
+ <i class='material-icons'>help</i> <?= __("More info...") ?>
+ </button>
+ <button dojoType='dijit.form.Button' class='alt-primary' type='submit'>
+ <?= __("Enable selected plugins") ?>
+ </button>
+ </div>
+ </div>
+ </form>
+ <?php
+ }
+
+ function index() {
+ ?>
+ <div dojoType='dijit.layout.AccordionContainer' region='center'>
+ <div dojoType='dijit.layout.AccordionPane' title="<i class='material-icons'>person</i> <?= __('Personal data / Authentication')?>">
+ <script type='dojo/method' event='onSelected' args='evt'>
+ if (this.domNode.querySelector('.loading'))
+ window.setTimeout(() => {
+ xhr.post("backend.php", {op: 'pref-prefs', method: 'index_auth'}, (reply) => {
+ this.attr('content', reply);
+ });
+ }, 100);
+ </script>
+ <span class='loading'><?= __("Loading, please wait...") ?></span>
+ </div>
+ <div dojoType='dijit.layout.AccordionPane' selected='true' title="<i class='material-icons'>settings</i> <?= __('Preferences') ?>">
+ <?php $this->index_prefs() ?>
+ </div>
+ <div dojoType='dijit.layout.AccordionPane' title="<i class='material-icons'>extension</i> <?= __('Plugins') ?>">
+ <script type='dojo/method' event='onSelected' args='evt'>
+ if (this.domNode.querySelector('.loading'))
+ window.setTimeout(() => {
+ xhr.post("backend.php", {op: 'pref-prefs', method: 'index_plugins'}, (reply) => {
+ this.attr('content', reply);
+ });
+ }, 200);
+ </script>
+ <span class='loading'><?= __("Loading, please wait...") ?></span>
+ </div>
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefPrefs") ?>
+ </div>
+ <?php
}
function toggleAdvanced() {
@@ -1054,7 +1063,7 @@ class Pref_Prefs extends Handler_Protected {
}
} else {
header("Content-Type: text/json");
- print error_json(6);
+ print Errors::to_json(Errors::E_UNAUTHORIZED);
}
}
@@ -1126,7 +1135,7 @@ class Pref_Prefs extends Handler_Protected {
$tpl->readTemplateFromFile("otp_disabled_template.txt");
$tpl->setVariable('LOGIN', $row["login"]);
- $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);
+ $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl->addBlock('message');
@@ -1171,112 +1180,107 @@ class Pref_Prefs extends Handler_Protected {
print json_encode(["value" => $value]);
}
- function editPrefProfiles() {
- print "<div dojoType='fox.Toolbar'>";
-
- print "<div dojoType='fox.form.DropDownButton'>".
- "<span>" . __('Select')."</span>";
- print "<div dojoType='dijit.Menu' style='display: none'>";
- print "<div onclick=\"Tables.select('pref-profiles-list', true)\"
- dojoType='dijit.MenuItem'>".__('All')."</div>";
- print "<div onclick=\"Tables.select('pref-profiles-list', false)\"
- dojoType='dijit.MenuItem'>".__('None')."</div>";
- print "</div></div>";
-
- print "<div style='float : right'>";
-
- print "<input name='newprofile' dojoType='dijit.form.ValidationTextBox'
- required='1'>
- <button dojoType='dijit.form.Button'
- onclick=\"dijit.byId('profileEditDlg').addProfile()\">".
- __('Create profile')."</button></div>";
-
- print "</div>";
+ function activateprofile() {
+ $_SESSION["profile"] = (int) clean($_REQUEST["id"]);
- $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles
- WHERE owner_uid = ? ORDER BY title");
- $sth->execute([$_SESSION['uid']]);
+ // default value
+ if (!$_SESSION["profile"]) $_SESSION["profile"] = null;
+ }
- print "<form onsubmit='return false'>";
+ function remprofiles() {
+ $ids = explode(",", clean($_REQUEST["ids"]));
- print "<div class='panel panel-scrollable'>";
+ foreach ($ids as $id) {
+ if ($_SESSION["profile"] != $id) {
+ $sth = $this->pdo->prepare("DELETE FROM ttrss_settings_profiles WHERE id = ? AND
+ owner_uid = ?");
+ $sth->execute([$id, $_SESSION['uid']]);
+ }
+ }
+ }
- print "<table width='100%' id='pref-profiles-list'>";
+ function addprofile() {
+ $title = clean($_REQUEST["title"]);
- print "<tr>"; # data-row-id='0' <-- no point, shouldn't be removed
+ if ($title) {
+ $this->pdo->beginTransaction();
- print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>";
+ $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles
+ WHERE title = ? AND owner_uid = ?");
+ $sth->execute([$title, $_SESSION['uid']]);
- if (!isset($_SESSION["profile"])) {
- $is_active = __("(active)");
- } else {
- $is_active = "";
- }
+ if (!$sth->fetch()) {
- print "<td width='100%'><span>" . __("Default profile") . " $is_active</span></td>";
+ $sth = $this->pdo->prepare("INSERT INTO ttrss_settings_profiles (title, owner_uid)
+ VALUES (?, ?)");
- print "</tr>";
+ $sth->execute([$title, $_SESSION['uid']]);
- while ($line = $sth->fetch()) {
+ $sth = $this->pdo->prepare("SELECT id FROM ttrss_settings_profiles WHERE
+ title = ? AND owner_uid = ?");
+ $sth->execute([$title, $_SESSION['uid']]);
- $profile_id = $line["id"];
+ if ($row = $sth->fetch()) {
+ $profile_id = $row['id'];
- print "<tr data-row-id='$profile_id'>";
+ if ($profile_id) {
+ Pref_Prefs::_init_user_prefs($_SESSION["uid"], $profile_id);
+ }
+ }
+ }
- $edit_title = htmlspecialchars($line["title"]);
+ $this->pdo->commit();
+ }
+ }
- print "<td><input onclick='Tables.onRowChecked(this);' dojoType='dijit.form.CheckBox' type='checkbox'></td>";
+ function saveprofile() {
+ $id = clean($_REQUEST["id"]);
+ $title = clean($_REQUEST["title"]);
- if (isset($_SESSION["profile"]) && $_SESSION["profile"] == $line["id"]) {
- $is_active = __("(active)");
- } else {
- $is_active = "";
- }
+ if ($id == 0) {
+ print __("Default profile");
+ return;
+ }
- print "<td><span dojoType='dijit.InlineEditBox'
- width='300px' autoSave='false'
- profile-id='$profile_id'>" . $edit_title .
- "<script type='dojo/method' event='onChange' args='item'>
- var elem = this;
- dojo.xhrPost({
- url: 'backend.php',
- content: {op: 'rpc', method: 'saveprofile',
- value: this.value,
- id: this.srcNodeRef.getAttribute('profile-id')},
- load: function(response) {
- elem.attr('value', response);
- }
- });
- </script>
- </span> $is_active</td>";
+ if ($title) {
+ $sth = $this->pdo->prepare("UPDATE ttrss_settings_profiles
+ SET title = ? WHERE id = ? AND
+ owner_uid = ?");
- print "</tr>";
+ $sth->execute([$title, $id, $_SESSION['uid']]);
+ print $title;
}
+ }
- print "</table>";
- print "</div>";
+ // TODO: this maybe needs to be unified with Public::getProfiles()
+ function getProfiles() {
+ $rv = [];
- print "<footer>
- <button style='float : left' class='alt-danger' dojoType='dijit.form.Button' onclick='App.dialogOf(this).removeSelected()'>".
- __('Remove selected profiles')."</button>
- <button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick='App.dialogOf(this).execute()'>".
- __('Activate profile')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>";
- print "</footer>";
+ $sth = $this->pdo->prepare("SELECT title,id FROM ttrss_settings_profiles
+ WHERE owner_uid = ? ORDER BY title");
+ $sth->execute([$_SESSION['uid']]);
- print "</form>";
+ array_push($rv, ["title" => __("Default profile"),
+ "id" => 0,
+ "active" => empty($_SESSION["profile"])
+ ]);
+ while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
+ $row["active"] = isset($_SESSION["profile"]) && $_SESSION["profile"] == $row["id"];
+ array_push($rv, $row);
+ };
+
+ print json_encode($rv);
}
- private function getShortDesc($pref_name) {
+ private function _get_short_desc($pref_name) {
if (isset($this->pref_help[$pref_name][0])) {
return $this->pref_help[$pref_name][0];
}
return "";
}
- private function getHelpText($pref_name) {
+ private function _get_help_text($pref_name) {
if (isset($this->pref_help[$pref_name][1])) {
return $this->pref_help[$pref_name][1];
}
@@ -1284,56 +1288,54 @@ class Pref_Prefs extends Handler_Protected {
}
private function appPasswordList() {
- print "<div dojoType='fox.Toolbar'>";
- print "<div dojoType='fox.form.DropDownButton'>" .
- "<span>" . __('Select') . "</span>";
- print "<div dojoType='dijit.Menu' style='display: none'>";
- print "<div onclick=\"Tables.select('app-password-list', true)\"
- dojoType=\"dijit.MenuItem\">" . __('All') . "</div>";
- print "<div onclick=\"Tables.select('app-password-list', false)\"
- dojoType=\"dijit.MenuItem\">" . __('None') . "</div>";
- print "</div></div>";
- print "</div>"; #toolbar
-
- print "<div class='panel panel-scrollable'>";
- print "<table width='100%' id='app-password-list'>";
- print "<tr>";
- print "<th width='2%'></th>";
- print "<th align='left'>".__("Description")."</th>";
- print "<th align='right'>".__("Created")."</th>";
- print "<th align='right'>".__("Last used")."</th>";
- print "</tr>";
-
- $sth = $this->pdo->prepare("SELECT id, title, created, last_used
- FROM ttrss_app_passwords WHERE owner_uid = ?");
- $sth->execute([$_SESSION['uid']]);
-
- while ($row = $sth->fetch()) {
-
- $row_id = $row["id"];
-
- print "<tr data-row-id='$row_id'>";
-
- print "<td align='center'>
- <input onclick='Tables.onRowChecked(this)' dojoType='dijit.form.CheckBox' type='checkbox'></td>";
- print "<td>" . htmlspecialchars($row["title"]) . "</td>";
-
- print "<td align='right' class='text-muted'>";
- print TimeHelper::make_local_datetime($row['created'], false);
- print "</td>";
-
- print "<td align='right' class='text-muted'>";
- print TimeHelper::make_local_datetime($row['last_used'], false);
- print "</td>";
-
- print "</tr>";
- }
-
- print "</table>";
- print "</div>";
+ ?>
+ <div dojoType='fox.Toolbar'>
+ <div dojoType='fox.form.DropDownButton'>
+ <span><?= __('Select') ?></span>
+ <div dojoType='dijit.Menu' style='display: none'>
+ <div onclick="Tables.select('app-password-list', true)"
+ dojoType="dijit.MenuItem"><?= __('All') ?></div>
+ <div onclick="Tables.select('app-password-list', false)"
+ dojoType="dijit.MenuItem"><?= __('None') ?></div>
+ </div>
+ </div>
+ </div>
+
+ <div class='panel panel-scrollable'>
+ <table width='100%' id='app-password-list'>
+ <tr>
+ <th width='2%'> </th>
+ <th align='left'><?= __("Description") ?></th>
+ <th align='right'><?= __("Created") ?></th>
+ <th align='right'><?= __("Last used") ?></th>
+ </tr>
+ <?php
+ $sth = $this->pdo->prepare("SELECT id, title, created, last_used
+ FROM ttrss_app_passwords WHERE owner_uid = ?");
+ $sth->execute([$_SESSION['uid']]);
+
+ while ($row = $sth->fetch()) { ?>
+ <tr data-row-id='<?= $row['id'] ?>'>
+ <td align='center'>
+ <input onclick='Tables.onRowChecked(this)' dojoType='dijit.form.CheckBox' type='checkbox'>
+ </td>
+ <td>
+ <?= htmlspecialchars($row["title"]) ?>
+ </td>
+ <td align='right' class='text-muted'>
+ <?= TimeHelper::make_local_datetime($row['created'], false) ?>
+ </td>
+ <td align='right' class='text-muted'>
+ <?= TimeHelper::make_local_datetime($row['last_used'], false) ?>
+ </td>
+ </tr>
+ <?php } ?>
+ </table>
+ </div>
+ <?php
}
- private function encryptAppPassword($password) {
+ private function _encrypt_app_password($password) {
$salt = substr(bin2hex(get_random_bytes(24)), 0, 24);
return "SSHA-512:".hash('sha512', $salt . $password). ":$salt";
@@ -1352,7 +1354,7 @@ class Pref_Prefs extends Handler_Protected {
function generateAppPassword() {
$title = clean($_REQUEST['title']);
$new_password = make_password(16);
- $new_password_hash = $this->encryptAppPassword($new_password);
+ $new_password_hash = $this->_encrypt_app_password($new_password);
print_warning(T_sprintf("Generated password <strong>%s</strong> for %s. Please remember it for future reference.", $new_password, $title));
@@ -1366,7 +1368,7 @@ class Pref_Prefs extends Handler_Protected {
$this->appPasswordList();
}
- static function initialize_user_prefs($uid, $profile = false) {
+ static function _init_user_prefs($uid, $profile = false) {
if (get_schema_version() < 63) $profile_qpart = "";
diff --git a/classes/pref/system.php b/classes/pref/system.php
index d91339698..67f7133c6 100644
--- a/classes/pref/system.php
+++ b/classes/pref/system.php
@@ -1,20 +1,9 @@
<?php
-class Pref_System extends Handler_Protected {
+class Pref_System extends Handler_Administrative {
private $log_page_limit = 15;
- function before($method) {
- if (parent::before($method)) {
- if ($_SESSION["access_level"] < 10) {
- print __("Your access level is insufficient to open this tab.");
- return false;
- }
- return true;
- }
- return false;
- }
-
function csrf_ignore($method) {
$csrf_ignored = array("index");
@@ -25,7 +14,16 @@ class Pref_System extends Handler_Protected {
$this->pdo->query("DELETE FROM ttrss_error_log");
}
- private function log_viewer(int $page, int $severity) {
+ function getphpinfo() {
+ ob_start();
+ phpinfo();
+ $info = ob_get_contents();
+ ob_end_clean();
+
+ print preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', (string)$info);
+ }
+
+ private function _log_viewer(int $page, int $severity) {
$errno_values = [];
switch ($severity) {
@@ -62,125 +60,121 @@ class Pref_System extends Handler_Protected {
$total_pages = 0;
}
- print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
-
- print "<div region='top' dojoType='fox.Toolbar'>";
-
- print "<button dojoType='dijit.form.Button'
- onclick='Helpers.EventLog.refresh()'>".__('Refresh')."</button>";
-
- $prev_page_disabled = $page <= 0 ? "disabled" : "";
-
- print "<button dojoType='dijit.form.Button' $prev_page_disabled
- onclick='Helpers.EventLog.prevPage()'>".__('&lt;&lt;')."</button>";
-
- print "<button dojoType='dijit.form.Button' disabled>".T_sprintf('Page %d of %d', $page+1, $total_pages+1)."</button>";
-
- $next_page_disabled = $page >= $total_pages ? "disabled" : "";
-
- print "<button dojoType='dijit.form.Button' $next_page_disabled
- onclick='Helpers.EventLog.nextPage()'>".__('&gt;&gt;')."</button>";
-
- print "<button dojoType='dijit.form.Button'
- onclick='Helpers.EventLog.clear()'>".__('Clear')."</button>";
-
- print "<div class='pull-right'>";
-
- print __("Severity:") . " ";
- print_select_hash("severity", $severity,
- [
- E_USER_ERROR => __("Errors"),
- E_USER_WARNING => __("Warnings"),
- E_USER_NOTICE => __("Everything")
- ], 'dojoType="fox.form.Select" onchange="Helpers.EventLog.refresh()"');
-
- print "</div>"; # pull-right
-
- print "</div>"; # toolbar
-
- print '<div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">';
-
- print "<table width='100%' class='event-log'>";
-
- print "<tr class='title'>
- <td width='5%'>".__("Error")."</td>
- <td>".__("Filename")."</td>
- <td>".__("Message")."</td>
- <td width='5%'>".__("User")."</td>
- <td width='5%'>".__("Date")."</td>
- </tr>";
-
- $sth = $this->pdo->prepare("SELECT
- errno, errstr, filename, lineno, created_at, login, context
- FROM
- ttrss_error_log LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id)
- WHERE
- $errno_filter_qpart
- ORDER BY
- ttrss_error_log.id DESC
- LIMIT $limit OFFSET $offset");
-
- $sth->execute($errno_values);
-
- while ($line = $sth->fetch()) {
- print "<tr>";
-
- foreach ($line as $k => $v) {
- $line[$k] = htmlspecialchars($v);
- }
-
- print "<td class='errno'>" . Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")</td>";
- print "<td class='filename'>" . $line["filename"] . ":" . $line["lineno"] . "</td>";
- print "<td class='errstr'>" . $line["errstr"] . "\n" . $line["context"] . "</td>";
- print "<td class='login'>" . $line["login"] . "</td>";
-
- print "<td class='timestamp'>" .
- TimeHelper::make_local_datetime($line["created_at"], false) . "</td>";
-
- print "</tr>";
- }
-
- print "</table>";
+ ?>
+ <div dojoType='dijit.layout.BorderContainer' gutters='false'>
+ <div region='top' dojoType='fox.Toolbar'>
+
+ <button dojoType='dijit.form.Button' onclick='Helpers.EventLog.refresh()'>
+ <?= __('Refresh') ?>
+ </button>
+
+ <button dojoType='dijit.form.Button' <?= ($page <= 0 ? "disabled" : "") ?>
+ onclick='Helpers.EventLog.prevPage()'>
+ <?= __('&lt;&lt;') ?>
+ </button>
+
+ <button dojoType='dijit.form.Button' disabled>
+ <?= T_sprintf('Page %d of %d', $page+1, $total_pages+1) ?>
+ </button>
+
+ <button dojoType='dijit.form.Button' <?= ($page >= $total_pages ? "disabled" : "") ?>
+ onclick='Helpers.EventLog.nextPage()'>
+ <?= __('&gt;&gt;') ?>
+ </button>
+
+ <button dojoType='dijit.form.Button'
+ onclick='Helpers.EventLog.clear()'>
+ <?= __('Clear') ?>
+ </button>
+
+ <div class='pull-right'>
+ <label><?= __("Severity:") ?></label>
+
+ <?= \Controls\select_hash("severity", $severity,
+ [
+ E_USER_ERROR => __("Errors"),
+ E_USER_WARNING => __("Warnings"),
+ E_USER_NOTICE => __("Everything")
+ ], ["onchange"=> "Helpers.EventLog.refresh()"], "severity") ?>
+ </div>
+ </div>
+
+ <div style="padding : 0px" dojoType="dijit.layout.ContentPane" region="center">
+
+ <table width='100%' class='event-log'>
+
+ <tr class='title'>
+ <td width='5%'><?= __("Error") ?></td>
+ <td><?= __("Filename") ?></td>
+ <td><?= __("Message") ?></td>
+ <td width='5%'><?= __("User") ?></td>
+ <td width='5%'><?= __("Date") ?></td>
+ </tr>
+
+ <?php
+ $sth = $this->pdo->prepare("SELECT
+ errno, errstr, filename, lineno, created_at, login, context
+ FROM
+ ttrss_error_log LEFT JOIN ttrss_users ON (owner_uid = ttrss_users.id)
+ WHERE
+ $errno_filter_qpart
+ ORDER BY
+ ttrss_error_log.id DESC
+ LIMIT $limit OFFSET $offset");
+
+ $sth->execute($errno_values);
+
+ while ($line = $sth->fetch()) {
+ foreach ($line as $k => $v) { $line[$k] = htmlspecialchars($v); }
+ ?>
+ <tr>
+ <td class='errno'>
+ <?= Logger::$errornames[$line["errno"]] . " (" . $line["errno"] . ")" ?>
+ </td>
+ <td class='filename'><?= $line["filename"] . ":" . $line["lineno"] ?></td>
+ <td class='errstr'><?= $line["errstr"] . "\n" . $line["context"] ?></td>
+ <td class='login'><?= $line["login"] ?></td>
+ <td class='timestamp'>
+ <?= TimeHelper::make_local_datetime($line["created_at"], false) ?>
+ </td>
+ </tr>
+ <?php } ?>
+ </table>
+ </div>
+ </div>
+ <?php
}
function index() {
$severity = (int) ($_REQUEST["severity"] ?? E_USER_WARNING);
$page = (int) ($_REQUEST["page"] ?? 0);
-
- print "<div dojoType='dijit.layout.AccordionContainer' region='center'>";
- print "<div dojoType='dijit.layout.AccordionPane' style='padding : 0'
- title='<i class=\"material-icons\">report</i> ".__('Event Log')."'>";
-
- if (LOG_DESTINATION == "sql") {
-
- $this->log_viewer($page, $severity);
-
- } else {
- print_notice("Please set LOG_DESTINATION to 'sql' in config.php to enable database logging.");
- }
-
- print "</div>"; # content pane
- print "</div>"; # container
- print "</div>"; # accordion pane
-
- print "<div dojoType='dijit.layout.AccordionPane'
- title='<i class=\"material-icons\">info</i> ".__('PHP Information')."'>";
-
- ob_start();
- phpinfo();
- $info = ob_get_contents();
- ob_end_clean();
-
- print "<div class='phpinfo'>";
- print preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', $info);
- print "</div>";
-
- print "</div>"; # accordion pane
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefSystem");
-
- print "</div>"; #container
+ ?>
+ <div dojoType='dijit.layout.AccordionContainer' region='center'>
+ <div dojoType='dijit.layout.AccordionPane' style='padding : 0' title='<i class="material-icons">report</i> <?= __('Event Log') ?>'>
+ <?php
+ if (Config::get(Config::LOG_DESTINATION) == "sql") {
+ $this->_log_viewer($page, $severity);
+ } else {
+ print_notice("Please set Config::get(Config::LOG_DESTINATION) to 'sql' in config.php to enable database logging.");
+ }
+ ?>
+ </div>
+
+ <div dojoType='dijit.layout.AccordionPane' title='<i class="material-icons">info</i> <?= __('PHP Information') ?>'>
+ <script type='dojo/method' event='onSelected' args='evt'>
+ if (this.domNode.querySelector('.loading'))
+ window.setTimeout(() => {
+ xhr.post("backend.php", {op: 'pref-system', method: 'getphpinfo'}, (reply) => {
+ this.attr('content', `<div class='phpinfo'>${reply}</div>`);
+ });
+ }, 200);
+ </script>
+ <span class='loading'><?= __("Loading, please wait...") ?></span>
+ </div>
+
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefSystem") ?>
+ </div>
+ <?php
}
-
}
diff --git a/classes/pref/users.php b/classes/pref/users.php
index 5c622a9b1..13f808cb3 100644
--- a/classes/pref/users.php
+++ b/classes/pref/users.php
@@ -1,18 +1,7 @@
<?php
-class Pref_Users extends Handler_Protected {
- function before($method) {
- if (parent::before($method)) {
- if ($_SESSION["access_level"] < 10) {
- print __("Your access level is insufficient to open this tab.");
- return false;
- }
- return true;
- }
- return false;
- }
-
+class Pref_Users extends Handler_Administrative {
function csrf_ignore($method) {
- $csrf_ignored = array("index", "userdetails");
+ $csrf_ignored = array("index");
return array_search($method, $csrf_ignored) !== false;
}
@@ -20,105 +9,17 @@ class Pref_Users extends Handler_Protected {
function edit() {
global $access_level_names;
- print "<form id='user_edit_form' onsubmit='return false' dojoType='dijit.form.Form'>";
-
- print '<div dojoType="dijit.layout.TabContainer" style="height : 400px">
- <div dojoType="dijit.layout.ContentPane" title="'.__('Edit user').'">';
-
- //print "<form id=\"user_edit_form\" onsubmit='return false' dojoType=\"dijit.form.Form\">";
-
- $id = (int) clean($_REQUEST["id"]);
-
- print_hidden("id", "$id");
- print_hidden("op", "pref-users");
- print_hidden("method", "editSave");
+ $id = (int)clean($_REQUEST["id"]);
- $sth = $this->pdo->prepare("SELECT * FROM ttrss_users WHERE id = ?");
+ $sth = $this->pdo->prepare("SELECT id, login, access_level, email FROM ttrss_users WHERE id = ?");
$sth->execute([$id]);
- if ($row = $sth->fetch()) {
-
- $login = $row["login"];
- $access_level = $row["access_level"];
- $email = $row["email"];
-
- $sel_disabled = ($id == $_SESSION["uid"] || $login == "admin") ? "disabled" : "";
-
- print "<header>".__("User")."</header>";
- print "<section>";
-
- if ($sel_disabled) {
- print_hidden("login", "$login");
- }
-
- print "<fieldset>";
- print "<label>" . __("Login:") . "</label>";
- print "<input style='font-size : 16px'
- dojoType='dijit.form.ValidationTextBox' required='1'
- $sel_disabled name='login' value=\"$login\">";
- print "</fieldset>";
-
- print "</section>";
-
- print "<header>".__("Authentication")."</header>";
- print "<section>";
-
- print "<fieldset>";
-
- print "<label>" . __('Access level: ') . "</label> ";
-
- if (!$sel_disabled) {
- print_select_hash("access_level", $access_level, $access_level_names,
- "dojoType=\"fox.form.Select\" $sel_disabled");
- } else {
- print_select_hash("", $access_level, $access_level_names,
- "dojoType=\"fox.form.Select\" $sel_disabled");
- print_hidden("access_level", "$access_level");
- }
-
- print "</fieldset>";
- print "<fieldset>";
-
- print "<label>" . __("New password:") . "</label> ";
- print "<input dojoType='dijit.form.TextBox' type='password' size='20' placeholder='Change password'
- name='password'>";
-
- print "</fieldset>";
-
- print "</section>";
-
- print "<header>".__("Options")."</header>";
- print "<section>";
-
- print "<fieldset>";
- print "<label>" . __("E-mail:") . "</label> ";
- print "<input dojoType='dijit.form.TextBox' size='30' name='email'
- value=\"$email\">";
- print "</fieldset>";
-
- print "</section>";
-
- print "</table>";
-
+ if ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
+ print json_encode([
+ "user" => $row,
+ "access_level_names" => $access_level_names
+ ]);
}
-
- print '</div>'; #tab
- print "<div href=\"backend.php?op=pref-users&method=userdetails&id=$id\"
- dojoType=\"dijit.layout.ContentPane\" title=\"".__('User details')."\">";
-
- print '</div>';
- print '</div>';
-
- print "<footer>
- <button dojoType='dijit.form.Button' class='alt-primary' type='submit' onclick='App.dialogOf(this).execute()'>".
- __('Save')."</button>
- <button dojoType='dijit.form.Button' onclick='App.dialogOf(this).hide()'>".
- __('Cancel')."</button>
- </footer>";
-
- print "</form>";
-
- return;
}
function userdetails() {
@@ -135,7 +36,6 @@ class Pref_Users extends Handler_Protected {
$sth->execute([$id]);
if ($row = $sth->fetch()) {
- print "<table width='100%'>";
$last_login = TimeHelper::make_local_datetime(
$row["last_login"], true);
@@ -145,47 +45,62 @@ class Pref_Users extends Handler_Protected {
$stored_articles = $row["stored_articles"];
- print "<tr><td>".__('Registered')."</td><td>$created</td></tr>";
- print "<tr><td>".__('Last logged in')."</td><td>$last_login</td></tr>";
-
$sth = $this->pdo->prepare("SELECT COUNT(id) as num_feeds FROM ttrss_feeds
WHERE owner_uid = ?");
$sth->execute([$id]);
$row = $sth->fetch();
- $num_feeds = $row["num_feeds"];
-
- print "<tr><td>".__('Subscribed feeds count')."</td><td>$num_feeds</td></tr>";
- print "<tr><td>".__('Stored articles')."</td><td>$stored_articles</td></tr>";
- print "</table>";
+ $num_feeds = $row["num_feeds"];
- print "<h1>".__('Subscribed feeds')."</h1>";
+ ?>
- $sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds
- WHERE owner_uid = ? ORDER BY title");
- $sth->execute([$id]);
+ <fieldset>
+ <label><?= __('Registered') ?>:</label>
+ <?= $created ?>
+ </fieldset>
- print "<ul class=\"panel panel-scrollable list list-unstyled\">";
+ <fieldset>
+ <label><?= __('Last logged in') ?>:</label>
+ <?= $last_login ?>
+ </fieldset>
- while ($line = $sth->fetch()) {
+ <fieldset>
+ <label><?= __('Subscribed feeds') ?>:</label>
+ <?= $num_feeds ?>
+ </fieldset>
- $icon_file = ICONS_URL."/".$line["id"].".ico";
+ <fieldset>
+ <label><?= __('Stored articles') ?>:</label>
+ <?= $stored_articles ?>
+ </fieldset>
- if (file_exists($icon_file) && filesize($icon_file) > 0) {
- $feed_icon = "<img class=\"icon\" src=\"$icon_file\">";
- } else {
- $feed_icon = "<img class=\"icon\" src=\"images/blank_icon.gif\">";
- }
+ <?php
+ $sth = $this->pdo->prepare("SELECT id,title,site_url FROM ttrss_feeds
+ WHERE owner_uid = ? ORDER BY title");
+ $sth->execute([$id]);
+ ?>
- print "<li>$feed_icon&nbsp;<a href=\"".$line["site_url"]."\">".$line["title"]."</a></li>";
+ <ul class="panel panel-scrollable list list-unstyled">
+ <?php while ($row = $sth->fetch()) { ?>
+ <li>
+ <?php
+ $icon_file = Config::get(Config::ICONS_URL) . "/" . $row["id"] . ".ico";
+ $icon = file_exists($icon_file) ? $icon_file : "images/blank_icon.gif";
+ ?>
- }
+ <img class="icon" src="<?= $icon_file ?>">
- print "</ul>";
+ <a target="_blank" href="<?= htmlspecialchars($row["site_url"]) ?>">
+ <?= htmlspecialchars($row["title"]) ?>
+ </a>
+ </li>
+ <?php } ?>
+ </ul>
+ <?php
} else {
- print "<h1>".__('User not found')."</h1>";
+ print_error(__('User not found'));
}
}
@@ -197,6 +112,12 @@ class Pref_Users extends Handler_Protected {
$email = clean($_REQUEST["email"]);
$password = clean($_REQUEST["password"]);
+ // no blank usernames
+ if (!$login) return;
+
+ // forbid renaming admin
+ if ($uid == 1) $login = "admin";
+
if ($password) {
$salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
$pwd_hash = encrypt_password($password, $salt, true);
@@ -246,67 +167,25 @@ class Pref_Users extends Handler_Protected {
if ($new_uid = UserHelper::find_user_by_login($login)) {
- $new_uid = $row['id'];
-
print T_sprintf("Added user %s with password %s",
$login, $tmp_user_pwd);
- $this->initialize_user($new_uid);
-
} else {
-
print T_sprintf("Could not create user %s", $login);
-
}
} else {
print T_sprintf("User %s already exists.", $login);
}
}
- static function resetUserPassword($uid, $format_output = false) {
-
- $pdo = Db::pdo();
-
- $sth = $pdo->prepare("SELECT login FROM ttrss_users WHERE id = ?");
- $sth->execute([$uid]);
-
- if ($row = $sth->fetch()) {
-
- $login = $row["login"];
-
- $new_salt = substr(bin2hex(get_random_bytes(125)), 0, 250);
- $tmp_user_pwd = make_password();
-
- $pwd_hash = encrypt_password($tmp_user_pwd, $new_salt, true);
-
- $sth = $pdo->prepare("UPDATE ttrss_users
- SET pwd_hash = ?, salt = ?, otp_enabled = false
- WHERE id = ?");
- $sth->execute([$pwd_hash, $new_salt, $uid]);
-
- $message = T_sprintf("Changed password of user %s to %s", "<strong>$login</strong>", "<strong>$tmp_user_pwd</strong>");
-
- if ($format_output)
- print_notice($message);
- else
- print $message;
-
- }
- }
-
function resetPass() {
- $uid = clean($_REQUEST["id"]);
- self::resetUserPassword($uid);
+ UserHelper::reset_password(clean($_REQUEST["id"]));
}
function index() {
global $access_level_names;
- print "<div dojoType='dijit.layout.BorderContainer' gutters='false'>";
- print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>";
- print "<div dojoType='fox.Toolbar'>";
-
$user_search = clean($_REQUEST["search"] ?? "");
if (array_key_exists("search", $_REQUEST)) {
@@ -315,146 +194,111 @@ class Pref_Users extends Handler_Protected {
$user_search = ($_SESSION["prefs_user_search"] ?? "");
}
- print "<div style='float : right; padding-right : 4px;'>
- <input dojoType='dijit.form.TextBox' id='user_search' size='20' type='search'
- value=\"$user_search\">
- <button dojoType='dijit.form.Button' onclick='Users.reload()'>".
- __('Search')."</button>
- </div>";
-
$sort = clean($_REQUEST["sort"] ?? "");
if (!$sort || $sort == "undefined") {
$sort = "login";
}
- print "<div dojoType='fox.form.DropDownButton'>".
- "<span>" . __('Select')."</span>";
- print "<div dojoType='dijit.Menu' style='display: none'>";
- print "<div onclick=\"Tables.select('users-list', true)\"
- dojoType='dijit.MenuItem'>".__('All')."</div>";
- print "<div onclick=\"Tables.select('users-list', false)\"
- dojoType='dijit.MenuItem'>".__('None')."</div>";
- print "</div></div>";
-
- print "<button dojoType='dijit.form.Button' onclick='Users.add()'>".__('Create user')."</button>";
-
- print "
- <button dojoType='dijit.form.Button' onclick='Users.editSelected()'>".
- __('Edit')."</button dojoType=\"dijit.form.Button\">
- <button dojoType='dijit.form.Button' onclick='Users.removeSelected()'>".
- __('Remove')."</button dojoType=\"dijit.form.Button\">
- <button dojoType='dijit.form.Button' onclick='Users.resetSelected()'>".
- __('Reset password')."</button dojoType=\"dijit.form.Button\">";
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefUsersToolbar");
-
- print "</div>"; #toolbar
- print "</div>"; #pane
- print "<div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>";
-
- $sort = $this->validate_field($sort,
+ $sort = $this->_validate_field($sort,
["login", "access_level", "created", "num_feeds", "created", "last_login"], "login");
if ($sort != "login") $sort = "$sort DESC";
- $sth = $this->pdo->prepare("SELECT
- tu.id,
- login,access_level,email,
- ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login,
- ".SUBSTRING_FOR_DATE."(created,1,16) as created,
- (SELECT COUNT(id) FROM ttrss_feeds WHERE owner_uid = tu.id) AS num_feeds
- FROM
- ttrss_users tu
- WHERE
- (:search = '' OR login LIKE :search) AND tu.id > 0
- ORDER BY $sort");
- $sth->execute([":search" => $user_search ? "%$user_search%" : ""]);
-
- print "<table width='100%' class='users-list' id='users-list'>";
-
- print "<tr class='title'>
- <td align='center' width='5%'>&nbsp;</td>
- <td width='20%'><a href='#' onclick=\"Users.reload('login')\">".__('Login')."</a></td>
- <td width='20%'><a href='#' onclick=\"Users.reload('access_level')\">".__('Access Level')."</a></td>
- <td width='10%'><a href='#' onclick=\"Users.reload('num_feeds')\">".__('Subscribed feeds')."</a></td>
- <td width='20%'><a href='#' onclick=\"Users.reload('created')\">".__('Registered')."</a></td>
- <td width='20%'><a href='#' onclick=\"Users.reload('last_login')\">".__('Last login')."</a></td></tr>";
-
- $lnum = 0;
-
- while ($line = $sth->fetch()) {
-
- $uid = $line["id"];
-
- print "<tr data-row-id='$uid' onclick='Users.edit($uid)'>";
-
- $line["login"] = htmlspecialchars($line["login"]);
- $line["created"] = TimeHelper::make_local_datetime($line["created"], false);
- $line["last_login"] = TimeHelper::make_local_datetime($line["last_login"], false);
-
- print "<td align='center'><input onclick='Tables.onRowChecked(this); event.stopPropagation();'
- dojoType='dijit.form.CheckBox' type='checkbox'></td>";
-
- print "<td title='".__('Click to edit')."'><i class='material-icons'>person</i> " . $line["login"] . "</td>";
-
- print "<td>" . $access_level_names[$line["access_level"]] . "</td>";
- print "<td>" . $line["num_feeds"] . "</td>";
- print "<td>" . $line["created"] . "</td>";
- print "<td>" . $line["last_login"] . "</td>";
-
- print "</tr>";
-
- ++$lnum;
- }
-
- print "</table>";
-
- if ($lnum == 0) {
- if (!$user_search) {
- print_warning(__('No users defined.'));
- } else {
- print_warning(__('No matching users found.'));
- }
- }
-
- print "</div>"; #pane
-
- PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefUsers");
-
- print "</div>"; #container
-
- }
+ ?>
+
+ <div dojoType='dijit.layout.BorderContainer' gutters='false'>
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='top'>
+ <div dojoType='fox.Toolbar'>
+
+ <div style='float : right'>
+ <input dojoType='dijit.form.TextBox' id='user_search' size='20' type='search'
+ value="<?= htmlspecialchars($user_search) ?>">
+ <button dojoType='dijit.form.Button' onclick='Users.reload()'>
+ <?= __('Search') ?>
+ </button>
+ </div>
+
+ <div dojoType='fox.form.DropDownButton'>
+ <span><?= __('Select') ?></span>
+ <div dojoType='dijit.Menu' style='display: none'>
+ <div onclick="Tables.select('users-list', true)"
+ dojoType='dijit.MenuItem'><?= __('All') ?></div>
+ <div onclick="Tables.select('users-list', false)"
+ dojoType='dijit.MenuItem'><?= __('None') ?></div>
+ </div>
+ </div>
+
+ <button dojoType='dijit.form.Button' onclick='Users.add()'>
+ <?= __('Create user') ?>
+ </button>
+
+ <button dojoType='dijit.form.Button' onclick='Users.removeSelected()'>
+ <?= __('Remove') ?>
+ </button>
+
+ <button dojoType='dijit.form.Button' onclick='Users.resetSelected()'>
+ <?= __('Reset password') ?>
+ </button>
+
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB_SECTION, "prefUsersToolbar") ?>
+
+ </div>
+ </div>
+ <div style='padding : 0px' dojoType='dijit.layout.ContentPane' region='center'>
+
+ <table width='100%' class='users-list' id='users-list'>
+
+ <tr class='title'>
+ <td align='center' width='5%'> </td>
+ <td width='20%'><a href='#' onclick="Users.reload('login')"><?= ('Login') ?></a></td>
+ <td width='20%'><a href='#' onclick="Users.reload('access_level')"><?= ('Access Level') ?></a></td>
+ <td width='10%'><a href='#' onclick="Users.reload('num_feeds')"><?= ('Subscribed feeds') ?></a></td>
+ <td width='20%'><a href='#' onclick="Users.reload('created')"><?= ('Registered') ?></a></td>
+ <td width='20%'><a href='#' onclick="Users.reload('last_login')"><?= ('Last login') ?></a></td>
+ </tr>
+
+ <?php
+ $sth = $this->pdo->prepare("SELECT
+ tu.id,
+ login,access_level,email,
+ ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login,
+ ".SUBSTRING_FOR_DATE."(created,1,16) as created,
+ (SELECT COUNT(id) FROM ttrss_feeds WHERE owner_uid = tu.id) AS num_feeds
+ FROM
+ ttrss_users tu
+ WHERE
+ (:search = '' OR login LIKE :search) AND tu.id > 0
+ ORDER BY $sort");
+ $sth->execute([":search" => $user_search ? "%$user_search%" : ""]);
+
+ while ($row = $sth->fetch()) { ?>
+
+ <tr data-row-id='<?= $row["id"] ?>' onclick='Users.edit(<?= $row["id"] ?>)' title="<?= __('Click to edit') ?>">
+ <td align='center'>
+ <input onclick='Tables.onRowChecked(this); event.stopPropagation();'
+ dojoType='dijit.form.CheckBox' type='checkbox'>
+ </td>
+
+ <td><i class='material-icons'>person</i> <?= htmlspecialchars($row["login"]) ?></td>
+ <td><?= $access_level_names[$row["access_level"]] ?></td>
+ <td><?= $row["num_feeds"] ?></td>
+ <td><?= TimeHelper::make_local_datetime($row["created"], false) ?></td>
+ <td><?= TimeHelper::make_local_datetime($row["last_login"], false) ?></td>
+ </tr>
+ <?php } ?>
+ </table>
+ </div>
+ <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefUsers") ?>
+ </div>
+ <?php
+ }
- function validate_field($string, $allowed, $default = "") {
+ private function _validate_field($string, $allowed, $default = "") {
if (in_array($string, $allowed))
return $string;
else
return $default;
}
- // this is called after user is created to initialize default feeds, labels
- // or whatever else
- // user preferences are checked on every login, not here
- static function initialize_user($uid) {
-
- $pdo = Db::pdo();
-
- $sth = $pdo->prepare("insert into ttrss_feeds (owner_uid,title,feed_url)
- values (?, 'Tiny Tiny RSS: Forum',
- 'https://tt-rss.org/forum/rss.php')");
- $sth->execute([$uid]);
- }
-
- static function logout_user() {
- if (session_status() === PHP_SESSION_ACTIVE)
- session_destroy();
-
- if (isset($_COOKIE[session_name()])) {
- setcookie(session_name(), '', time()-42000, '/');
-
- }
- session_commit();
- }
-
}