add error handling

Signed-off-by: Jasmine Amalia <67263692+jasm1nii@users.noreply.github.com>
This commit is contained in:
Jasmine Amalia 2023-10-23 12:07:36 +07:00
parent 3f1287d172
commit 6ca25658c5
Signed by untrusted user who does not match committer: jasm1nii
GPG Key ID: 9C88CED5BF43BD08
1 changed files with 21 additions and 14 deletions

View File

@ -1,6 +1,7 @@
<?php <?php
date_default_timezone_set($timezone); date_default_timezone_set($timezone);
if (glob($blog_entries.'.php')) {
$i = 0; $i = 0;
foreach ((glob($blog_entries.'.php')) as $article_php) { foreach ((glob($blog_entries.'.php')) as $article_php) {
ob_start(); ob_start();
@ -10,6 +11,9 @@
file_put_contents($article_php.'_generator-tmp.html', $compiled); file_put_contents($article_php.'_generator-tmp.html', $compiled);
if(++$i > ($max_entries-1) ) break; if(++$i > ($max_entries-1) ) break;
} }
} else {
$article_php = null;
}
$i = 0; $i = 0;
foreach ((glob($blog_entries.'html')) as $article) { foreach ((glob($blog_entries.'html')) as $article) {
@ -168,13 +172,16 @@
$sxe->saveXML($blog_root . DIRECTORY_SEPARATOR . $file); $sxe->saveXML($blog_root . DIRECTORY_SEPARATOR . $file);
$del_tmp = unlink($article_php.'_generator-tmp.html');
echo nl2br(strtoupper(date("h:i:sa")) . ' - Feed successfully generated in ' . realpath($blog_root) . DIRECTORY_SEPARATOR . $file . "\n"); echo nl2br(strtoupper(date("h:i:sa")) . ' - Feed successfully generated in ' . realpath($blog_root) . DIRECTORY_SEPARATOR . $file . "\n");
if(file_exists($article_php)) {
$del_tmp = unlink($article_php.'_generator-tmp.html');
if ($del_tmp) { if ($del_tmp) {
echo 'Temporary generator files successfully deleted.'; echo 'Temporary generator files successfully deleted.';
} else { } else {
echo 'Temporary generator files could not be automatically deleted - check your directories to delete them manually.'; echo 'Temporary generator files could not be automatically deleted - check your directories to delete them manually.';
} }
}
echo 'Validate your feed at https://validator.w3.org/feed/'; echo 'Validate your feed at https://validator.w3.org/feed/';
?> ?>