allow overriding built-in templates via templates.local

This commit is contained in:
Andrew Dolgov 2020-03-13 14:40:35 +03:00
parent 82326187f9
commit 1f2a721905
10 changed files with 48 additions and 40 deletions

View File

@ -90,13 +90,11 @@ class Digest
static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) { static function prepare_headlines_digest($user_id, $days = 1, $limit = 1000) {
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl_t = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("digest_template_html.txt");
$tpl_t = new MiniTemplator; $tpl_t->readTemplateFromFile("digest_template.txt");
$tpl->readTemplateFromFile("templates/digest_template_html.txt");
$tpl_t->readTemplateFromFile("templates/digest_template.txt");
$user_tz_string = get_pref('USER_TIMEZONE', $user_id); $user_tz_string = get_pref('USER_TIMEZONE', $user_id);
$local_ts = convert_timestamp(time(), 'UTC', $user_tz_string); $local_ts = convert_timestamp(time(), 'UTC', $user_tz_string);

View File

@ -5,8 +5,6 @@ class Handler_Public extends Handler {
$limit, $offset, $search, $limit, $offset, $search,
$view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) { $view_mode = false, $format = 'atom', $order = false, $orig_guid = false, $start_ts = false) {
require_once "lib/MiniTemplator.class.php";
$note_style = "background-color : #fff7d5; $note_style = "background-color : #fff7d5;
border-width : 1px; ". border-width : 1px; ".
"padding : 5px; border-style : dashed; border-color : #e7d796;". "padding : 5px; border-style : dashed; border-color : #e7d796;".
@ -80,9 +78,9 @@ class Handler_Public extends Handler {
if (!$feed_site_url) $feed_site_url = get_self_url_prefix(); if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
if ($format == 'atom') { if ($format == 'atom') {
$tpl = new MiniTemplator; $tpl = new Templator();
$tpl->readTemplateFromFile("templates/generated_feed.txt"); $tpl->readTemplateFromFile("generated_feed.txt");
$tpl->setVariable('FEED_TITLE', $feed_title, true); $tpl->setVariable('FEED_TITLE', $feed_title, true);
$tpl->setVariable('VERSION', get_version(), true); $tpl->setVariable('VERSION', get_version(), true);
@ -1030,11 +1028,9 @@ class Handler_Public extends Handler {
$resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token . $resetpass_link = get_self_url_prefix() . "/public.php?op=forgotpass&hash=" . $resetpass_token .
"&login=" . urlencode($login); "&login=" . urlencode($login);
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("resetpass_link_template.txt");
$tpl->readTemplateFromFile("templates/resetpass_link_template.txt");
$tpl->setVariable('LOGIN', $login); $tpl->setVariable('LOGIN', $login);
$tpl->setVariable('RESETPASS_LINK', $resetpass_link); $tpl->setVariable('RESETPASS_LINK', $resetpass_link);

View File

@ -213,11 +213,9 @@ class Pref_Prefs extends Handler_Protected {
if ($old_email != $email) { if ($old_email != $email) {
$mailer = new Mailer(); $mailer = new Mailer();
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("mail_change_template.txt");
$tpl->readTemplateFromFile("templates/mail_change_template.txt");
$tpl->setVariable('LOGIN', $row["login"]); $tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('NEWMAIL', $email); $tpl->setVariable('NEWMAIL', $email);
@ -1087,11 +1085,9 @@ class Pref_Prefs extends Handler_Protected {
if ($row = $sth->fetch()) { if ($row = $sth->fetch()) {
$mailer = new Mailer(); $mailer = new Mailer();
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("otp_disabled_template.txt");
$tpl->readTemplateFromFile("templates/otp_disabled_template.txt");
$tpl->setVariable('LOGIN', $row["login"]); $tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);

21
classes/templator.php Normal file
View File

@ -0,0 +1,21 @@
<?php
require_once "lib/MiniTemplator.class.php";
class Templator extends MiniTemplator {
/* this reads tt-rss template from templates.local/ or templates/ if only base filename is given */
function readTemplateFromFile ($fileName) {
if (strpos($fileName, "/") === FALSE) {
$fileName = basename($fileName);
if (file_exists("templates.local/$fileName"))
return parent::readTemplateFromFile("templates.local/$fileName");
else
return parent::readTemplateFromFile("templates/$fileName");
} else {
return parent::readTemplateFromFile($fileName);
}
}
}

View File

@ -31,13 +31,11 @@ class Af_Comics_Gocomics extends Af_ComicFilter {
$body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false)); $body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false));
require_once 'lib/MiniTemplator.class.php';
$feed_title = htmlspecialchars($comic[1]); $feed_title = htmlspecialchars($comic[1]);
$site_url = htmlspecialchars($site_url); $site_url = htmlspecialchars($site_url);
$article_link = htmlspecialchars($article_link); $article_link = htmlspecialchars($article_link);
$tpl = new MiniTemplator(); $tpl = new Templator();
$tpl->readTemplateFromFile('templates/generated_feed.txt'); $tpl->readTemplateFromFile('templates/generated_feed.txt');

View File

@ -25,11 +25,10 @@ class Af_Comics_Gocomics_FarSide extends Af_ComicFilter {
public function on_fetch($url) { public function on_fetch($url) {
if (preg_match("#^https?://www\.thefarside\.com#", $url)) { if (preg_match("#^https?://www\.thefarside\.com#", $url)) {
require_once 'lib/MiniTemplator.class.php';
$article_link = htmlspecialchars("https://www.thefarside.com" . date('/Y/m/d')); $article_link = htmlspecialchars("https://www.thefarside.com" . date('/Y/m/d'));
$tpl = new MiniTemplator(); $tpl = new Templator();
$tpl->readTemplateFromFile('templates/generated_feed.txt'); $tpl->readTemplateFromFile('templates/generated_feed.txt');

View File

@ -235,11 +235,9 @@ class Auth_Internal extends Plugin implements IAuthModule {
if ($row = $sth->fetch()) { if ($row = $sth->fetch()) {
$mailer = new Mailer(); $mailer = new Mailer();
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("password_change_template.txt");
$tpl->readTemplateFromFile("templates/password_change_template.txt");
$tpl->setVariable('LOGIN', $row["login"]); $tpl->setVariable('LOGIN', $row["login"]);
$tpl->setVariable('TTRSS_HOST', SELF_URL_PATH); $tpl->setVariable('TTRSS_HOST', SELF_URL_PATH);

View File

@ -92,18 +92,20 @@ class Mail extends Plugin {
if ($row = $sth->fetch()) { if ($row = $sth->fetch()) {
$user_email = htmlspecialchars($row['email']); $user_email = htmlspecialchars($row['email']);
$user_name = htmlspecialchars($row['full_name']); $user_name = htmlspecialchars($row['full_name']);
} else {
$user_name = "";
$user_email = "";
} }
if (!$user_name) $user_name = $_SESSION['name']; if (!$user_name)
$user_name = $_SESSION['name'];
print_hidden("from_email", "$user_email"); print_hidden("from_email", "$user_email");
print_hidden("from_name", "$user_name"); print_hidden("from_name", "$user_name");
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("email_article_template.txt");
$tpl->readTemplateFromFile("templates/email_article_template.txt");
$tpl->setVariable('USER_NAME', $_SESSION["name"], true); $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
$tpl->setVariable('USER_EMAIL', $user_email, true); $tpl->setVariable('USER_EMAIL', $user_email, true);
@ -116,6 +118,8 @@ class Mail extends Plugin {
if (count($ids) > 1) { if (count($ids) > 1) {
$subject = __("[Forwarded]") . " " . __("Multiple articles"); $subject = __("[Forwarded]") . " " . __("Multiple articles");
} else {
$subject = "";
} }
while ($line = $sth->fetch()) { while ($line = $sth->fetch()) {

View File

@ -29,11 +29,9 @@ class MailTo extends Plugin {
$ids = explode(",", $_REQUEST['param']); $ids = explode(",", $_REQUEST['param']);
$ids_qmarks = arr_qmarks($ids); $ids_qmarks = arr_qmarks($ids);
require_once "lib/MiniTemplator.class.php"; $tpl = new Templator();
$tpl = new MiniTemplator; $tpl->readTemplateFromFile("email_article_template.txt");
$tpl->readTemplateFromFile("templates/email_article_template.txt");
$tpl->setVariable('USER_NAME', $_SESSION["name"], true); $tpl->setVariable('USER_NAME', $_SESSION["name"], true);
//$tpl->setVariable('USER_EMAIL', $user_email, true); //$tpl->setVariable('USER_EMAIL', $user_email, true);

View File