Skip to content

Instantly share code, notes, and snippets.

@zexeder
Last active February 22, 2019 16:07
Show Gist options
  • Save zexeder/4520fd8ee093655845b75e08e81ed9d5 to your computer and use it in GitHub Desktop.
Save zexeder/4520fd8ee093655845b75e08e81ed9d5 to your computer and use it in GitHub Desktop.
<?php
// $modx->log($modx::LOG_LEVEL_ERROR,'Testing my custom hook.');
$email = $hook->getValue('subscribe-email');
$base_path = $modx->getOption('base_path');
$fp = fopen($base_path . 'subscribe/subscribe_db.txt', 'a+');
$matches = false;
$lines = file($base_path . 'subscribe/subscribe_db.txt'); // reads a file into a array with the lines
foreach ($lines as $line) {
if (strstr($line, $email)) {
$matches = true;
}
}
if(!$matches) {
$text = $email . ",\n";
fwrite($fp, $text);
}
<?php
if($email = isset($_GET['unsubscribe'])) {
$email = $_GET['unsubscribe'];
$filename = $base_path . 'subscribe/subscribe_db.txt';
$lines = file($filename); // reads a file into a array with the lines
$output = '';
foreach ($lines as $line) {
if (!strstr($line, $email)) {
$output .= $line;
}
}
// replace the contents of the file with the output
file_put_contents($filename, $output);
fclose($filename);
echo "<p>Вы отписаны от рассылки!</p>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment