Skip to content

Commit c62a2c2

Browse files
author
Andrew Dolgov
committed
digest improvements and bugfixes
1 parent 70364a4 commit c62a2c2

File tree

13 files changed

+1195
-253
lines changed

13 files changed

+1195
-253
lines changed

MiniTemplator.class.php

+922
Large diffs are not rendered by default.

config.php-dist

-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@
105105
define('DIGEST_ENABLE', true);
106106
// Global option to enable daily digests
107107

108-
define('DIGEST_HOSTNAME', 'your.domain.dom');
109-
// Hostname for email digest signature
110-
111108
define('DIGEST_EMAIL_LIMIT', 10);
112109
// The maximum amount of emails sent in one digest batch
113110

functions.php

+68-42
Original file line numberDiff line numberDiff line change
@@ -3208,47 +3208,40 @@ function send_headlines_digests($link, $limit = 100) {
32083208
$digest = $tuple[0];
32093209
$headlines_count = $tuple[1];
32103210
$affected_ids = $tuple[2];
3211+
$digest_text = $tuple[3];
32113212

32123213
if ($headlines_count > 0) {
32133214

3214-
if (!DIGEST_SMTP_HOST) {
3215+
$mail = new PHPMailer();
32153216

3216-
$rc = mail($line["login"] . " <" . $line["email"] . ">",
3217-
"[tt-rss] New headlines for last 24 hours", $digest,
3218-
"From: " . DIGEST_FROM_NAME . " <" . DIGEST_FROM_ADDRESS . ">\n".
3219-
"Content-Type: text/plain; charset=\"utf-8\"\n".
3220-
"Content-Transfer-Encoding: 8bit\n");
3217+
$mail->PluginDir = "phpmailer/";
3218+
$mail->SetLanguage("en", "phpmailer/language/");
32213219

3222-
} else {
3223-
3224-
$mail = new PHPMailer();
3225-
3226-
$mail->PluginDir = "phpmailer/";
3227-
$mail->SetLanguage("en", "phpmailer/language/");
3220+
$mail->CharSet = "UTF-8";
32283221

3229-
$mail->CharSet = "UTF-8";
3222+
$mail->From = DIGEST_FROM_ADDRESS;
3223+
$mail->FromName = DIGEST_FROM_NAME;
3224+
$mail->AddAddress($line["email"], $line["login"]);
32303225

3231-
$mail->From = DIGEST_FROM_ADDRESS;
3232-
$mail->FromName = DIGEST_FROM_NAME;
3233-
$mail->AddAddress($line["email"], $line["login"]);
3226+
if (DIGEST_SMTP_HOST) {
32343227
$mail->Host = DIGEST_SMTP_HOST;
32353228
$mail->Mailer = "smtp";
3236-
32373229
$mail->Username = DIGEST_SMTP_LOGIN;
32383230
$mail->Password = DIGEST_SMTP_PASSWORD;
3231+
}
32393232

3240-
$mail->Subject = "[tt-rss] New headlines for last 24 hours";
3241-
$mail->Body = $digest;
3233+
$mail->IsHTML(true);
3234+
$mail->Subject = "[tt-rss] New headlines for last 24 hours";
3235+
$mail->Body = $digest;
3236+
$mail->AltBody = $digest_text;
32423237

3243-
$rc = $mail->Send();
3238+
$rc = $mail->Send();
32443239

3245-
if (!$rc) print "ERROR: " . $mail->ErrorInfo;
3246-
3247-
}
3240+
if (!$rc) print "ERROR: " . $mail->ErrorInfo;
32483241

32493242
print "RC=$rc\n";
32503243

3251-
if ($rc) {
3244+
if ($rc && $do_catchup) {
32523245
print "Marking affected articles as read...\n";
32533246
catchupArticlesById($link, $affected_ids, 0, $line["id"]);
32543247
}
@@ -3261,15 +3254,25 @@ function send_headlines_digests($link, $limit = 100) {
32613254
}
32623255
}
32633256

3264-
// $digest = prepare_headlines_digest($link, $user_id, $days, $limit);
3265-
32663257
print "All done.\n";
32673258

32683259
}
32693260

32703261
function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
3271-
$tmp = __("New headlines for last 24 hours, as of ") . date("Y/m/d H:m") . "\n";
3272-
$tmp .= "=======================================================\n\n";
3262+
3263+
require_once "MiniTemplator.class.php";
3264+
3265+
$tpl = new MiniTemplator;
3266+
$tpl_t = new MiniTemplator;
3267+
3268+
$tpl->readTemplateFromFile("templates/digest_template_html.txt");
3269+
$tpl_t->readTemplateFromFile("templates/digest_template.txt");
3270+
3271+
$tpl->setVariable('CUR_DATE', date('Y/m/d'));
3272+
$tpl->setVariable('CUR_TIME', date('G:i'));
3273+
3274+
$tpl_t->setVariable('CUR_DATE', date('Y/m/d'));
3275+
$tpl_t->setVariable('CUR_TIME', date('G:i'));
32733276

32743277
$affected_ids = array();
32753278

@@ -3284,6 +3287,7 @@ function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
32843287
date_entered,
32853288
ttrss_user_entries.ref_id,
32863289
link,
3290+
SUBSTRING(content, 1, 120) AS excerpt,
32873291
SUBSTRING(last_updated,1,19) AS last_updated
32883292
FROM
32893293
ttrss_user_entries,ttrss_entries,ttrss_feeds
@@ -3293,38 +3297,60 @@ function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
32933297
AND $interval_query
32943298
AND hidden = false
32953299
AND ttrss_user_entries.owner_uid = $user_id
3296-
AND unread = true ORDER BY ttrss_feeds.title, date_entered DESC
3300+
AND unread = true
3301+
ORDER BY ttrss_feeds.title, date_entered DESC
32973302
LIMIT $limit");
32983303

32993304
$cur_feed_title = "";
33003305

33013306
$headlines_count = db_num_rows($result);
33023307

3308+
$headlines = array();
3309+
33033310
while ($line = db_fetch_assoc($result)) {
3311+
array_push($headlines, $line);
3312+
}
3313+
3314+
for ($i = 0; $i < sizeof($headlines); $i++) {
3315+
3316+
$line = $headlines[$i];
33043317

33053318
array_push($affected_ids, $line["ref_id"]);
33063319

33073320
$updated = smart_date_time(strtotime($line["last_updated"]));
3308-
$feed_title = $line["feed_title"];
33093321

3310-
if ($cur_feed_title != $feed_title) {
3311-
$cur_feed_title = $feed_title;
3322+
$tpl->setVariable('FEED_TITLE', $line["feed_title"]);
3323+
$tpl->setVariable('ARTICLE_TITLE', $line["title"]);
3324+
$tpl->setVariable('ARTICLE_LINK', $line["link"]);
3325+
$tpl->setVariable('ARTICLE_UPDATED', $updated);
3326+
// $tpl->setVariable('ARTICLE_EXCERPT',
3327+
// truncate_string(strip_tags($line["excerpt"]), 100));
33123328

3313-
$tmp .= "$feed_title\n\n";
3329+
$tpl->addBlock('article');
3330+
3331+
$tpl_t->setVariable('FEED_TITLE', $line["feed_title"]);
3332+
$tpl_t->setVariable('ARTICLE_TITLE', $line["title"]);
3333+
$tpl_t->setVariable('ARTICLE_LINK', $line["link"]);
3334+
$tpl_t->setVariable('ARTICLE_UPDATED', $updated);
3335+
// $tpl_t->setVariable('ARTICLE_EXCERPT',
3336+
// truncate_string(strip_tags($line["excerpt"]), 100));
3337+
3338+
$tpl_t->addBlock('article');
3339+
3340+
if ($headlines[$i]['feed_title'] != $headlines[$i+1]['feed_title']) {
3341+
$tpl->addBlock('feed');
3342+
$tpl_t->addBlock('feed');
33143343
}
33153344

3316-
$tmp .= " * " . trim($line["title"]) . " - $updated\n";
3317-
$tmp .= " " . trim($line["link"]) . "\n";
3318-
$tmp .= "\n";
33193345
}
33203346

3321-
$tmp .= "--- \n";
3322-
$tmp .= __("You have been sent this email because you have enabled daily digests in Tiny Tiny RSS at ") .
3323-
DIGEST_HOSTNAME . "\n".
3324-
__("To unsubscribe, visit your configuration options or contact instance owner.\n");
3325-
3347+
$tpl->addBlock('digest');
3348+
$tpl->generateOutputToString($tmp);
3349+
3350+
$tpl_t->addBlock('digest');
3351+
$tpl_t->generateOutputToString($tmp_t);
33263352

3327-
return array($tmp, $headlines_count, $affected_ids);
3353+
return array($tmp, $headlines_count, $affected_ids, $tmp_t);
33283354
}
33293355

33303356
function check_for_update($link, $brief_fmt = true) {

locale/fr_FR/LC_MESSAGES/messages.mo

-544 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)