first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
<?php
// Those default options are used ONLY on FIRST setup and on plugin updates but limited to
// new options that may have been added between your and new version.
//
// This is the main language file, too, which is always loaded by Newsletter. Other language
// files are loaded according the WPLANG constant defined in wp-config.php file. Those language
// specific files are "merged" with this one and the language specific configuration
// keys override the ones in this file.
//
// Language specific files only need to override configurations containing texts
// langiage dependant.
$options = array();
$options['unsubscribe_text'] = '<p>' . __('Please confirm you want to unsubscribe <a href="{unsubscription_confirm_url}">clicking here</a>.', 'newsletter') . '</p>';
$options['error_text'] = '<p>' . __("Subscriber not found, it probably has already been removed. No further actions are required.", 'newsletter') . '</p>';
// When you finally loosed your subscriber
$options['unsubscribed_text'] = "<p>" . __('Your subscription has been deleted. If that was an error you can <a href="{reactivate_url}">subscribe again here</a>.', 'newsletter') . "</p>";
$options['unsubscribed_subject'] = __("Goodbye", 'newsletter');
$options['unsubscribed_message'] = '<p>' . __('This message confirms that you have unsubscribed from our newsletter. Thank you.', 'newsletter') . '</p>';
$options['reactivated_text'] = '<p>' . __('Your subscription has been reactivated.', 'newsletter') . '</p>';

View File

@@ -0,0 +1,125 @@
<?php
defined('ABSPATH') || exit;
@include_once NEWSLETTER_INCLUDES_DIR . '/controls.php';
$controls = new NewsletterControls();
$module = NewsletterUnsubscription::instance();
$current_language = $module->get_current_language();
$is_all_languages = $module->is_all_languages();
if (!$is_all_languages) {
$controls->warnings[] = 'You are configuring the language <strong>' . $current_language . '</strong>. Switch to "all languages" to see every options.';
}
if (!$controls->is_action()) {
$controls->data = $module->get_options('', $current_language);
} else {
if ($controls->is_action('save')) {
//$controls->data['unsubscription_text'] = NewsletterModule::clean_url_tags($controls->data['unsubscription_text']);
//$controls->data['unsubscribed_text'] = NewsletterModule::clean_url_tags($controls->data['unsubscribed_text']);
//$controls->data['unsubscribed_message'] = NewsletterModule::clean_url_tags($controls->data['unsubscribed_message']);
$module->save_options($controls->data, '', null, $current_language);
$controls->data = $module->get_options('', $current_language);
$controls->add_message_saved();
}
if ($controls->is_action('reset')) {
// On reset we ignore the current language
$controls->data = $module->reset_options();
}
}
?>
<div class="wrap" id="tnp-wrap">
<?php include NEWSLETTER_DIR . '/tnp-header.php'; ?>
<div id="tnp-heading">
<h2><?php _e('Cancellation', 'newsletter')?></h2>
<?php $controls->panel_help('https://www.thenewsletterplugin.com/documentation/cancellation')?>
</div>
<div id="tnp-body">
<form method="post" action="">
<?php $controls->init(); ?>
<p>
<?php $controls->button_save() ?>
<?php $controls->button_reset() ?>
</p>
<div id="tabs">
<ul>
<li><a href="#tabs-cancellation"><?php _e('Cancellation', 'newsletter') ?></a></li>
<li><a href="#tabs-reactivation"><?php _e('Reactivation', 'newsletter') ?></a></li>
</ul>
<div id="tabs-cancellation">
<table class="form-table">
<tr>
<th><?php _e('Cancellation message', 'newsletter') ?></th>
<td>
<?php $controls->wp_editor('unsubscribe_text', array('editor_height'=>250)); ?>
<p class="description">
</p>
</td>
</tr>
<tr>
<th><?php _e('Goodbye message', 'newsletter') ?></th>
<td>
<?php $controls->wp_editor('unsubscribed_text', array('editor_height'=>250)); ?>
<p class="description">
</p>
</td>
</tr>
<tr>
<th><?php _e('Goodbye email', 'newsletter') ?></th>
<td>
<?php $controls->email('unsubscribed', 'wordpress', $is_all_languages, array('editor_height'=>250)); ?>
<p class="description">
</p>
</td>
</tr>
<tr>
<th><?php _e('On error', 'newsletter')?></th>
<td>
<?php $controls->wp_editor('error_text', array('editor_height'=>150)); ?>
<p class="description">
</p>
</td>
</tr>
</table>
</div>
<div id="tabs-reactivation">
<table class="form-table">
<tr>
<th><?php _e('Reactivated message', 'newsletter') ?></th>
<td>
<?php $controls->wp_editor('reactivated_text', array('editor_height'=>250)); ?>
<p class="description">
</p>
</td>
</tr>
</table>
</div>
</div>
<p>
<?php $controls->button_save() ?>
<?php $controls->button_reset() ?>
</p>
</form>
</div>
<?php include NEWSLETTER_DIR . '/tnp-footer.php'; ?>
</div>

View File

@@ -0,0 +1,203 @@
<?php
defined('ABSPATH') || exit;
require_once NEWSLETTER_INCLUDES_DIR . '/module.php';
class NewsletterUnsubscription extends NewsletterModule {
static $instance;
/**
* @return NewsletterUnsubscription
*/
static function instance() {
if (self::$instance == null) {
self::$instance = new NewsletterUnsubscription();
}
return self::$instance;
}
function __construct() {
parent::__construct('unsubscription', '1.0.0');
add_action('init', array($this, 'hook_init'), 1);
add_action('wp_loaded', array($this, 'hook_wp_loaded'));
}
function hook_init() {
add_filter('newsletter_replace', array($this, 'hook_newsletter_replace'), 10, 3);
add_filter('newsletter_page_text', array($this, 'hook_newsletter_page_text'), 10, 3);
}
function hook_wp_loaded() {
global $wpdb;
switch (Newsletter::instance()->action) {
case 'u':
$user = $this->get_user_from_request();
$email = $this->get_email_from_request();
if ($user == null) {
$url = $this->build_message_url(null, 'unsubscription_error', $user);
} else {
$url = $this->build_message_url(null, 'unsubscribe', $user);
}
wp_redirect($url);
die();
break;
case 'uc':
if ($this->antibot_form_check()) {
$user = $this->unsubscribe();
if ($user->status == 'E') {
$url = $this->build_message_url(null, 'unsubscription_error', $user);
} else {
$url = $this->build_message_url(null, 'unsubscribed', $user);
}
wp_redirect($url);
} else {
$this->request_to_antibot_form('Unsubscribe');
}
die();
break;
case 'reactivate':
if ($this->antibot_form_check()) {
$user = $this->reactivate();
$url = $this->build_message_url(null, 'reactivated', $user);
wp_redirect($url);
} else {
$this->request_to_antibot_form('Reactivate');
}
die();
break;
}
}
/**
* Unsubscribes the subscriber from the request. Die on subscriber extraction failure.
*
* @return TNP_User
*/
function unsubscribe() {
$user = $this->get_user_from_request(true);
if ($user->status == TNP_User::STATUS_UNSUBSCRIBED) {
return $user;
}
$user = $this->refresh_user_token($user);
$user = $this->set_user_status($user, TNP_User::STATUS_UNSUBSCRIBED);
$this->add_user_log($user, 'unsubscribe');
do_action('newsletter_unsubscribed', $user);
global $wpdb;
$email = $this->get_email_from_request();
if ($email) {
$wpdb->update(NEWSLETTER_USERS_TABLE, array('unsub_email_id' => (int) $email_id, 'unsub_time' => time()), array('id' => $user->id));
}
$this->send_unsubscribed_email($user);
NewsletterSubscription::instance()->notify_admin($user, 'Newsletter unsubscription');
return $user;
}
function send_unsubscribed_email($user, $force = false) {
$options = $this->get_options('', $this->get_user_language($user));
if (!$force && !empty($options['unsubscribed_disabled'])) {
return true;
}
$message = $options['unsubscribed_message'];
$subject = $options['unsubscribed_subject'];
return NewsletterSubscription::instance()->mail($user, $subject, $message);
}
/**
* Reactivate the subscriber extracted from the request setting his status
* to confirmed and logging. No email are sent. Dies on subscriber extraction failure.
*
* @return TNP_User
*/
function reactivate() {
$user = $this->get_user_from_request(true);
$user = $this->set_user_status($user, TNP_User::STATUS_CONFIRMED);
$this->add_user_log($user, 'reactivate');
return $user;
}
function hook_newsletter_replace($text, $user, $email) {
if (!$user) {
return $text;
}
$text = $this->replace_url($text, 'UNSUBSCRIPTION_CONFIRM_URL', $this->build_action_url('uc', $user, $email));
$text = $this->replace_url($text, 'UNSUBSCRIPTION_URL', $this->build_action_url('u', $user, $email));
$text = $this->replace_url($text, 'REACTIVATE_URL', $this->build_action_url('reactivate', $user, $email));
return $text;
}
function hook_newsletter_page_text($text, $key, $user = null) {
$options = $this->get_options('', $this->get_current_language($user));
if ($key == 'unsubscribe') {
if (!$user) {
return 'Subscriber not found.';
}
return $options['unsubscribe_text'];
}
if ($key == 'unsubscribed') {
if (!$user) {
return $options['error_text'];
}
return $options['unsubscribed_text'];
}
if ($key == 'reactivated') {
if (!$user) {
return $options['error_text'];
}
return $options['reactivated_text'];
}
if ($key == 'unsubscription_error') {
return $options['error_text'];
}
return $text;
}
function upgrade() {
global $wpdb, $charset_collate;
parent::upgrade();
// Migration code
if (empty($this->options) || empty($this->options['unsubscribe_text'])) {
// Options of the subscription module (worng name, I know)
$options = get_option('newsletter');
$this->options['unsubscribe_text'] = $options['unsubscription_text'];
$this->options['reactivated_text'] = $options['reactivated_text'];
$this->options['unsubscribed_text'] = $options['unsubscribed_text'];
$this->options['unsubscribed_message'] = $options['unsubscribed_message'];
$this->options['unsubscribed_subject'] = $options['unsubscribed_subject'];
$this->save_options($this->options);
}
}
function admin_menu() {
$this->add_admin_page('index', 'Unsubscribe');
}
}
NewsletterUnsubscription::instance();