add digest preview button, also fix a bunch of bugs

This commit is contained in:
Andrew Dolgov 2021-03-02 19:21:21 +03:00
parent 386316aba1
commit ba86c64d38
4 changed files with 51 additions and 17 deletions

View File

@ -78,7 +78,7 @@ class Digest
Debug::log("All done.");
}
static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) {
static function prepare_headlines_digest(int $user_id, int $days = 1, int $limit = 1000) {
$tpl = new Templator();
$tpl_t = new Templator();
@ -87,20 +87,22 @@ class Digest
$tpl_t->readTemplateFromFile("digest_template.txt");
$user_tz_string = get_pref(Prefs::USER_TIMEZONE, $user_id);
if ($user_tz_string == 'Automatic')
$user_tz_string = 'GMT';
$local_ts = TimeHelper::convert_timestamp(time(), 'UTC', $user_tz_string);
$tpl->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
$tpl->setVariable('CUR_TIME', date('G:i', $local_ts));
$tpl->setVariable('TTRSS_HOST', Config::get(Config::get(Config::SELF_URL_PATH)));
$tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$tpl_t->setVariable('CUR_DATE', date('Y/m/d', $local_ts));
$tpl_t->setVariable('CUR_TIME', date('G:i', $local_ts));
$tpl_t->setVariable('TTRSS_HOST', Config::get(Config::get(Config::SELF_URL_PATH)));
$tpl_t->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH));
$affected_ids = array();
$days = (int) $days;
if (Config::get(Config::DB_TYPE) == "pgsql") {
$interval_qpart = "ttrss_entries.date_updated > NOW() - INTERVAL '$days days'";
} else /* if (Config::get(Config::DB_TYPE) == "mysql") */ {
@ -131,9 +133,7 @@ class Digest
AND score >= 0
ORDER BY ttrss_feed_categories.title, ttrss_feeds.title, score DESC, date_updated DESC
LIMIT :limit");
$sth->bindParam(':user_id', intval($user_id, 10), PDO::PARAM_INT);
$sth->bindParam(':limit', intval($limit, 10), PDO::PARAM_INT);
$sth->execute();
$sth->execute([':user_id' => $user_id, ':limit' => $limit]);
$headlines_count = 0;
$headlines = array();

View File

@ -664,6 +664,10 @@ class Pref_Prefs extends Handler_Protected {
print \Controls\checkbox_tag($pref_name, $is_checked, "true",
["disabled" => $is_disabled], "CB_$pref_name");
if ($pref_name == Prefs::DIGEST_ENABLE) {
print \Controls\button_tag(__('Preview'), '', ['onclick' => 'Helpers.Digest.preview()', 'style' => 'margin-left : 10px']);
}
} else if (in_array($pref_name, ['FRESH_ARTICLE_MAX_AGE',
'PURGE_OLD_DAYS', 'LONG_DATE_FORMAT', 'SHORT_DATE_FORMAT'])) {
@ -698,11 +702,10 @@ class Pref_Prefs extends Handler_Protected {
"class" => "alt-info",
"onclick" => "window.open('https://tt-rss.org/wiki/SSL%20Certificate%20Authentication')"]);
} else if ($pref_name == 'DIGEST_PREFERRED_TIME') {
} else if ($pref_name == Prefs::DIGEST_PREFERRED_TIME) {
print "<input dojoType=\"dijit.form.ValidationTextBox\"
id=\"$pref_name\" regexp=\"[012]?\d:\d\d\" placeHolder=\"12:00\"
name=\"$pref_name\" value=\"$value\">";
$item['help_text'] .= ". " . T_sprintf("Current server time: %s", date("H:i"));
} else {
$regexp = ($type_hint == Config::T_INT) ? 'regexp="^\d*$"' : '';
@ -1408,6 +1411,10 @@ class Pref_Prefs extends Handler_Protected {
$this->appPasswordList();
}
function previewDigest() {
print json_encode(Digest::prepare_headlines_digest($_SESSION["uid"], 1, 16));
}
static function _get_ssl_certificate_id() {
if ($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] ?? false) {
return sha1($_SERVER["REDIRECT_SSL_CLIENT_M_SERIAL"] .

View File

@ -53,6 +53,33 @@ const Helpers = {
return false;
},
},
Digest: {
preview: function() {
const dialog = new fox.SingleUseDialog({
title: __("Digest Preview"),
content: `
<div class='panel panel-scrollable digest-preview'>
<div class='text-center'>${__("Loading, please wait...")}</div>
</div>
<footer class='text-center'>
${App.FormFields.submit_tag(__('Close this window'))}
</footer>
`
});
const tmph = dojo.connect(dialog, 'onShow', function () {
dojo.disconnect(tmph);
xhr.json("backend.php", {op: "pref-prefs", method: "previewDigest"}, (reply) => {
dialog.domNode.querySelector('.digest-preview').innerHTML = reply[0];
});
});
dialog.show();
}
},
System: {
//
},

View File

@ -1,20 +1,20 @@
<!-- $BeginBlock digest -->
<h1 style='font-size : x-large'>New headlines for last 24 hours, as of ${CUR_DATE} ${CUR_TIME}</h1>
<h1>New headlines for last 24 hours, as of ${CUR_DATE} ${CUR_TIME}</h1>
<hr/>
<!-- $BeginBlock feed -->
<h2 style='font-size : large'>${FEED_TITLE}</h2>
<h2>${FEED_TITLE}</h2>
<ul>
<!-- $BeginBlock article -->
<li><a href="${ARTICLE_LINK}">${ARTICLE_TITLE}</a> &mdash; <strong>${ARTICLE_UPDATED}</strong>
<div style='font-style : italic'>${ARTICLE_LABELS}</div>
<div style='color : gray'>${ARTICLE_EXCERPT}</div>
<div><em>${ARTICLE_LABELS}</em></div>
<div>${ARTICLE_EXCERPT}</div>
<!-- $EndBlock article -->
</ul>
<!-- $EndBlock feed -->
<hr>
<em>To unsubscribe, visit your configuration options or contact instance owner.</em><br/>
<em>Sent by tt-rss mailer daemon at ${TTRSS_HOST}.</em>
<em style='color : gray'>To unsubscribe, visit your configuration options or contact instance owner.<br/>
Sent by tt-rss mailer daemon at ${TTRSS_HOST}.</em>
<!-- $EndBlock digest -->