@@ -3208,47 +3208,40 @@ function send_headlines_digests($link, $limit = 100) {
3208
3208
$ digest = $ tuple [0 ];
3209
3209
$ headlines_count = $ tuple [1 ];
3210
3210
$ affected_ids = $ tuple [2 ];
3211
+ $ digest_text = $ tuple [3 ];
3211
3212
3212
3213
if ($ headlines_count > 0 ) {
3213
3214
3214
- if (! DIGEST_SMTP_HOST ) {
3215
+ $ mail = new PHPMailer ();
3215
3216
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/ " );
3221
3219
3222
- } else {
3223
-
3224
- $ mail = new PHPMailer ();
3225
-
3226
- $ mail ->PluginDir = "phpmailer/ " ;
3227
- $ mail ->SetLanguage ("en " , "phpmailer/language/ " );
3220
+ $ mail ->CharSet = "UTF-8 " ;
3228
3221
3229
- $ mail ->CharSet = "UTF-8 " ;
3222
+ $ mail ->From = DIGEST_FROM_ADDRESS ;
3223
+ $ mail ->FromName = DIGEST_FROM_NAME ;
3224
+ $ mail ->AddAddress ($ line ["email " ], $ line ["login " ]);
3230
3225
3231
- $ mail ->From = DIGEST_FROM_ADDRESS ;
3232
- $ mail ->FromName = DIGEST_FROM_NAME ;
3233
- $ mail ->AddAddress ($ line ["email " ], $ line ["login " ]);
3226
+ if (DIGEST_SMTP_HOST ) {
3234
3227
$ mail ->Host = DIGEST_SMTP_HOST ;
3235
3228
$ mail ->Mailer = "smtp " ;
3236
-
3237
3229
$ mail ->Username = DIGEST_SMTP_LOGIN ;
3238
3230
$ mail ->Password = DIGEST_SMTP_PASSWORD ;
3231
+ }
3239
3232
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 ;
3242
3237
3243
- $ rc = $ mail ->Send ();
3238
+ $ rc = $ mail ->Send ();
3244
3239
3245
- if (!$ rc ) print "ERROR: " . $ mail ->ErrorInfo ;
3246
-
3247
- }
3240
+ if (!$ rc ) print "ERROR: " . $ mail ->ErrorInfo ;
3248
3241
3249
3242
print "RC= $ rc \n" ;
3250
3243
3251
- if ($ rc ) {
3244
+ if ($ rc && $ do_catchup ) {
3252
3245
print "Marking affected articles as read... \n" ;
3253
3246
catchupArticlesById ($ link , $ affected_ids , 0 , $ line ["id " ]);
3254
3247
}
@@ -3261,15 +3254,25 @@ function send_headlines_digests($link, $limit = 100) {
3261
3254
}
3262
3255
}
3263
3256
3264
- // $digest = prepare_headlines_digest($link, $user_id, $days, $limit);
3265
-
3266
3257
print "All done. \n" ;
3267
3258
3268
3259
}
3269
3260
3270
3261
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 ' ));
3273
3276
3274
3277
$ affected_ids = array ();
3275
3278
@@ -3284,6 +3287,7 @@ function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
3284
3287
date_entered,
3285
3288
ttrss_user_entries.ref_id,
3286
3289
link,
3290
+ SUBSTRING(content, 1, 120) AS excerpt,
3287
3291
SUBSTRING(last_updated,1,19) AS last_updated
3288
3292
FROM
3289
3293
ttrss_user_entries,ttrss_entries,ttrss_feeds
@@ -3293,38 +3297,60 @@ function prepare_headlines_digest($link, $user_id, $days = 1, $limit = 100) {
3293
3297
AND $ interval_query
3294
3298
AND hidden = false
3295
3299
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
3297
3302
LIMIT $ limit " );
3298
3303
3299
3304
$ cur_feed_title = "" ;
3300
3305
3301
3306
$ headlines_count = db_num_rows ($ result );
3302
3307
3308
+ $ headlines = array ();
3309
+
3303
3310
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 ];
3304
3317
3305
3318
array_push ($ affected_ids , $ line ["ref_id " ]);
3306
3319
3307
3320
$ updated = smart_date_time (strtotime ($ line ["last_updated " ]));
3308
- $ feed_title = $ line ["feed_title " ];
3309
3321
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));
3312
3328
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 ' );
3314
3343
}
3315
3344
3316
- $ tmp .= " * " . trim ($ line ["title " ]) . " - $ updated \n" ;
3317
- $ tmp .= " " . trim ($ line ["link " ]) . "\n" ;
3318
- $ tmp .= "\n" ;
3319
3345
}
3320
3346
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 );
3326
3352
3327
- return array ($ tmp , $ headlines_count , $ affected_ids );
3353
+ return array ($ tmp , $ headlines_count , $ affected_ids, $ tmp_t );
3328
3354
}
3329
3355
3330
3356
function check_for_update ($ link , $ brief_fmt = true ) {
0 commit comments