Last active
February 22, 2019 16:07
-
-
Save zexeder/4520fd8ee093655845b75e08e81ed9d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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