implemented following users to receive (opt-in) email notifications when they publish an article.
This commit is contained in:
+36
-18
@@ -1,17 +1,36 @@
|
||||
<?php
|
||||
include_once 'functions/init.php';
|
||||
|
||||
if (!empty($_FILES['upload'])) {
|
||||
require_once '../vendor/autoload.php';
|
||||
use Postmark\PostmarkClient;
|
||||
|
||||
// Load environment variables.
|
||||
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
|
||||
$dotenv->safeLoad();
|
||||
if (!empty($_FILES['upload']))
|
||||
upload($_FILES['upload'], $_ENV['UPLOAD_TMP_FQ_PATH'], isset($_POST['filename']) ? $_POST['filename'] : null);
|
||||
|
||||
function notify_users($emails, $auther_username, $article_id, $article_title, $excerpt)
|
||||
{
|
||||
foreach ($emails as $email) {
|
||||
$email_html = '
|
||||
<h1>' . $article_title . '</h1>
|
||||
<p>An author you follow just published a new article! Read it <a href="https://vintagecoding.net/articles.php?view=read&article_id=' . $article_id . '" target="_blank">here</a></p>
|
||||
<p><strong>Here is a snippet from the article!</strong></p>
|
||||
<p>' . $excerpt . '</p>
|
||||
';
|
||||
|
||||
$client = new PostmarkClient($_ENV['POSTMARK_API_TOKEN']);
|
||||
|
||||
$client->sendEmail(
|
||||
'mailer@joshashton.dev',
|
||||
$email,
|
||||
$auther_username . ' just published a new article! - vintagecoding.net',
|
||||
$email_html
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function delete_dir($dir)
|
||||
{
|
||||
if (!is_dir($dir)) return false;
|
||||
if (!is_dir($dir))
|
||||
return false;
|
||||
|
||||
if (substr($dir, strlen($dir) - 1, 1) != '/') {
|
||||
$dir .= '/';
|
||||
@@ -28,7 +47,8 @@ function delete_dir($dir)
|
||||
|
||||
function delete_file($file)
|
||||
{
|
||||
if (!file_exists($file)) return false;
|
||||
if (!file_exists($file))
|
||||
return false;
|
||||
|
||||
unlink($file);
|
||||
}
|
||||
@@ -54,7 +74,7 @@ function upload($input, $dest_dir, $filename = null)
|
||||
|
||||
break;
|
||||
default:
|
||||
# code...
|
||||
// code...
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -66,7 +86,7 @@ function upload($input, $dest_dir, $filename = null)
|
||||
|
||||
function crop_image($img_path, $x, $y, $height, $width)
|
||||
{
|
||||
//$dest = $_ENV['UPLOAD_TMP_FQ_PATH'];
|
||||
// $dest = $_ENV['UPLOAD_TMP_FQ_PATH'];
|
||||
$dest = '/tmp/';
|
||||
// Get the image type
|
||||
$imageType = exif_imagetype($img_path);
|
||||
@@ -80,11 +100,11 @@ function crop_image($img_path, $x, $y, $height, $width)
|
||||
$sourceImage = imagecreatefrompng($img_path);
|
||||
break;
|
||||
default:
|
||||
return false; // Unsupported image type
|
||||
return false; // Unsupported image type
|
||||
}
|
||||
|
||||
if (!$sourceImage)
|
||||
return false; // Failed to create image resource
|
||||
return false; // Failed to create image resource
|
||||
|
||||
// Create a new image resource for the cropped image
|
||||
$croppedImage = imagecreatetruecolor($width, $height);
|
||||
@@ -109,7 +129,7 @@ function crop_image($img_path, $x, $y, $height, $width)
|
||||
imagedestroy($sourceImage);
|
||||
imagedestroy($croppedImage);
|
||||
|
||||
return true; // Cropping successful
|
||||
return true; // Cropping successful
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -132,7 +152,7 @@ function extract_content_from_tag($string, $start, $end)
|
||||
{
|
||||
$ini = strpos($string, $start);
|
||||
if ($ini != 0)
|
||||
return "nope";
|
||||
return 'nope';
|
||||
|
||||
$ini += strlen($start);
|
||||
$len = strpos($string, $end, $ini) - $ini;
|
||||
@@ -151,9 +171,7 @@ function check_csv_upload($target)
|
||||
|
||||
function pretty_dump($arr)
|
||||
{
|
||||
echo '
|
||||
<pre>
|
||||
' . print_r($arr) . '
|
||||
</pre>
|
||||
';
|
||||
echo '<pre>';
|
||||
print_r($arr);
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user