download all files

This commit is contained in:
Roman Pyrih
2025-06-24 14:14:35 +02:00
parent ebed09c00b
commit 4c71b5d9c2
72007 changed files with 10407727 additions and 40029 deletions

View File

@@ -0,0 +1,76 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProAjaxModuleFrontController extends ModuleFrontController
{
public $auth = false;
public $ssl = false;
/**
* @var NewsletterPro
*/
public $module;
public $response;
private $request;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->response = new NewsletterProResponse();
$this->request = new NewsletterProRequest();
}
public function setMedia()
{
parent::setMedia();
}
public function postProcess()
{
parent::postProcess();
if ($this->request->has('pqnpAction')) {
$action = $this->request->get('pqnpAction');
switch ($action) {
case 'popup':
return NewsletterProPopupAction::newInstance()->call($this->request->get('target'));
}
}
// content from scripts/ajax_newsletterpro_front.php
header('Access-Control-Allow-Origin: *');
if (_PS_MAGIC_QUOTES_GPC_ && class_exists('NewsletterPro')) {
$_POST = NewsletterPro::strip($_POST);
$_GET = NewsletterPro::strip($_GET);
}
$this->module->ajaxProcess();
exit('Invalid Action');
}
}

View File

@@ -0,0 +1,91 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProApiModuleFrontController extends ModuleFrontController
{
/**
* @var false
*/
public $auth = false;
/**
* @var true
*/
public $ssl = false;
/**
* @var NewsletterProResponse
*/
protected $response;
/**
* @var NewsletterProRequest
*/
protected $request;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->response = new NewsletterProResponse();
$this->request = new NewsletterProRequest();
}
public function initContent()
{
switch ($this->request->get('action', '')) {
case 'bounce':
$api = new NewsletterProApiBounce(true);
exit($api->call());
case 'css':
$api = new NewsletterProApiCss(false, 'text/css');
exit($api->call());
case 'mailchimp':
$api = new NewsletterProApiMailchimp(true);
exit($api->call());
case 'openedEmail':
$api = new NewsletterProApiOpenedEmail(false);
exit($api->call());
case 'syncChimp':
$api = new NewsletterProApiSyncChimp(true, 'text/html');
exit($api->call());
case 'syncNewsletterBlock':
$api = new NewsletterProApiSyncNewsletterBlock(true, 'text/html');
exit($api->call());
case 'task':
$api = new NewsletterProApiTask(true, 'text/html');
exit($api->call());
}
exit('Invalid action');
}
public function setMedia()
{
parent::setMedia();
}
public function postProcess()
{
parent::postProcess();
}
}

View File

@@ -0,0 +1,306 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
require_once dirname(__FILE__).'/../../classes/NewsletterProForward.php';
class NewsletterProForwardModuleFrontController extends ModuleFrontController
{
public $id_newsletter;
private $translate;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->translate = new NewsletterProTranslate(pathinfo(__FILE__, PATHINFO_FILENAME));
}
/**
* DEPRACTED.
*/
public function npl($string)
{
return Translate::getModuleTranslation($this->module, $string, Tools::getValue('controller'));
}
public function initContent()
{
parent::initContent();
if (NewsletterProTools::is17()) {
$this->setTemplate('module:newsletterpro/views/templates/front/1.7/forward.tpl');
} else {
$this->setTemplate('forward.tpl');
}
}
public function setMedia()
{
parent::setMedia();
$css_path = $this->module->getCssPath();
$this->addCss($css_path.'forward_front.css');
}
public function getEmailsFromPost()
{
$emails = [];
$grep_keys = preg_grep('/^email_\d+$/', array_keys($_POST));
foreach ($grep_keys as $key) {
$email = trim(Tools::getValue($key));
if (Validate::isEmail($email) && !in_array($email, $emails)) {
$emails[] = $email;
} else {
$this->errors = sprintf($this->translate->l('The email %s is invalid.'), $email);
}
}
return $emails;
}
public function getLink($params = [])
{
$email = (Tools::isSubmit('email') ? Tools::getValue('email') : '');
$token = (Tools::isSubmit('token') ? Tools::getValue('token') : '');
$params = array_merge($params, [
'email' => $email,
'token' => $token,
]);
return urldecode($this->context->link->getModuleLink($this->module->name, 'forward', $params));
// $email = (Tools::isSubmit('email') ? '&email='.Tools::getValue('email'):'');
// $token = (Tools::isSubmit('token') ? '&token='.Tools::getValue('token'):'');
// return 'index.php?fc=module&module=newsletterpro&controller=forward'.$email.$token.(!empty($params) ? '&'.http_build_query($params) : '');
}
public function postProcess()
{
try {
if (pqnp_config('FWD_FEATURE_ACTIVE')) {
if (Tools::isSubmit('email') && ($email = Tools::getValue('email'))) {
$token = Tools::getValue('token');
$token_ok = false;
if (Tools::isSubmit('mc_token')) {
$token_ok = NewsletterProMailChimpToken::validateToken('mc_token');
}
if (!$token_ok) {
$token_ok = $token == Tools::encrypt($email);
}
if ($token_ok) {
$this->context->smarty->assign([
'dispalyForm' => true,
'email' => $email,
'emails_js' => Tools::jsonEncode(NewsletterProForward::getEmailsToByEmailFrom($email)),
'fwd_limit' => NewsletterProForward::FOREWORD_LIMIT - count(NewsletterProForward::getEmailsToByEmailFrom($email)),
'self_link' => $this->getLink(),
'ajax_link' => $this->getLink(),
'jsData' => pqnp_addcslashes(Tools::jsonEncode([
'token' => Tools::getValue('token'),
])),
]);
// this is ajax request
if ('submitForward' == Tools::getValue('action')) {
$response = ['status' => false, 'errors' => [], 'emails' => []];
$to_email = Tools::getValue('to_email');
if (Validate::isEmail($to_email)) {
$forward = new NewsletterProForward();
$forward->from = $email;
$forward->to = $to_email;
if ($info = $this->getUserTableByEmail($forward->to)) {
$subscribed = false;
if (NewsletterProTools::tableExists($info['table'])) {
$subscribed = (int) Db::getInstance()->getValue('SELECT `'.$info['newsletter'].'` FROM `'._DB_PREFIX_.$info['table'].'` WHERE `'.$info['email'].'` = "'.pSQL($forward->to).'"');
}
if ($subscribed) {
$this->errors[] = sprintf($this->translate->l('The email %s is already subscribed at our newsletter.'), $forward->to);
} else {
$output = sprintf($this->translate->l('The email %s is already registered in our database, but is not subscribed at our newsletter. You can send him a subcription request by clicking '), $forward->to);
$output .= '<a class="subscription" href="javascript:{}" style="color: blue;" onclick="NewsletterPro.modules.frontForward.requestFriendSubscription($(this), \''.$token.'\', \''.addcslashes($email, "'").'\', \''.addcslashes($forward->to, "'").'\');">'.$this->translate->l('here').'</a>';
$output .= '.';
$this->errors[] = $output;
}
} else {
if ($forward->from != $forward->to) {
if (!$forward->add()) {
$this->errors = array_merge($forward->getErrors(), $this->errors);
}
} else {
$this->errors[] = $this->translate->l('You cannot add your own email address.');
}
}
} else {
$this->errors[] = sprintf($this->translate->l('The email address %s is invalid.'), $to_email);
}
if (empty($this->errors)) {
$response['status'] = true;
} else {
$response['errors'] = array_merge($response['errors'], $this->errors);
}
$response['emails'] = NewsletterProForward::getEmailsToByEmailFrom($email);
exit(Tools::jsonEncode($response));
} elseif ('deleteEmail' == Tools::getValue('action')) {
$response = ['status' => false, 'errors' => [], 'emails' => []];
$delete_email = Tools::getValue('delete_email');
if ($forward = NewsletterProForward::getInstanceByTo($delete_email)) {
if ($forward->from == $email) {
if (!$forward->delete()) {
$this->errors = array_merge($forward->getErrors(), $this->errors);
}
} else {
$this->errors[] = $this->translate->l('Permission denied. You cannot delete this email address.');
}
} else {
$this->errors[] = sprintf($this->translate->l('The email %s cannot be deleted.'), $delete_email);
}
if (empty($this->errors)) {
$response['status'] = true;
} else {
$response['errors'] = array_merge($response['errors'], $this->errors);
}
$response['emails'] = NewsletterProForward::getEmailsToByEmailFrom($email);
exit(Tools::jsonEncode($response));
} elseif ('requestFriendSubscription' == Tools::getValue('action')) {
$response = ['status' => false, 'errors' => [], 'message' => ''];
$post_token = Tools::getValue('token');
$from_email = Tools::getValue('from_email');
$friend_email = Tools::getValue('friend_email');
if ($post_token == Tools::encrypt($from_email)) {
try {
$file_tpl = dirname(__FILE__).'/../../views/templates/front/forward_subscribe.tpl';
$this->context->smarty->assign([
'from_email' => $from_email,
]);
$content = $this->context->smarty->fetch($file_tpl);
$template = NewsletterProTemplate::newString(['', $content], $friend_email)->load()->setVariables([
'friend_email' => $from_email,
]);
$message = $template->message();
$send = NewsletterProSendManager::getInstance()->sendNewsletter(
$this->translate->l('Your friend want to subscribe!'),
$message['body'],
$friend_email,
['user' => $template->user],
[],
false
);
if (!is_array($send) && true == $send) {
$response['message'] = $this->translate->l('Your request was successfully sent.');
} else {
$this->errors = $this->translate->l('An error occurred when sending the email.');
}
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
}
} else {
$this->errors[] = $this->translate->l('You cannot make this action because the token is not valid.');
}
if (empty($this->errors)) {
$response['status'] = true;
} else {
$response['errors'] = array_merge($response['errors'], $this->errors);
}
exit(Tools::jsonEncode($response));
}
} else {
$this->errors[] = $this->translate->l('Invalid token.');
}
} else {
$this->errors[] = sprintf($this->translate->l('The email %s is not valid.'), (string) Tools::getValue('email'));
}
} else {
$this->errors[] = $this->translate->l('This feature is no longer active.');
}
} catch (Exception $e) {
$this->errors[] = $this->translate->l('There is an error, please report this error to the website developer.');
if (_PS_MODE_DEV_) {
$this->errors[] = $e->getMessage();
}
NewsletterProLog::writeStrip($e->__toString(), NewsletterProLog::ERROR_FILE);
}
}
public function getUserTableByEmail($email)
{
$definition = [
'customer' => ['email' => 'email', 'newsletter' => 'newsletter'],
'newsletter_pro_email' => ['email' => 'email', 'newsletter' => 'active'],
];
if ((bool) pqnp_config('SUBSCRIPTION_ACTIVE')) {
$definition['newsletter_pro_subscribers'] = ['email' => 'email', 'newsletter' => 'active'];
} elseif (NewsletterProTools::tableExists('newsletter')) {
$definition['newsletter'] = ['email' => 'email', 'newsletter' => 'active'];
} elseif (NewsletterProTools::tableExists('emailsubscription')) {
$definition['emailsubscription'] = ['email' => 'email', 'newsletter' => 'active'];
}
foreach ($definition as $table => $fields) {
if (NewsletterProTools::tableExists($table)) {
$sql = 'SELECT COUNT(*) FROM `'._DB_PREFIX_.$table.'` WHERE `'.$fields['email'].'` = "'.pSQL($email).'"';
if (Db::getInstance()->getValue($sql)) {
return [
'table' => $table,
'email' => $fields['email'],
'newsletter' => $fields['newsletter'],
];
}
}
}
return false;
}
public function getHistoryIdByToken($token)
{
return (int) Db::getInstance()->getValue('SELECT `id_newsletter_pro_tpl_history` FROM `'._DB_PREFIX_.'newsletter_pro_tpl_history` WHERE `token` = "'.pSQL($token).'"');
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,229 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProMyAccountModuleFrontController extends ModuleFrontController
{
/**
* @var NewsletterPro
*/
public $module;
private $translate;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->translate = new NewsletterProTranslate(pathinfo(__FILE__, PATHINFO_FILENAME));
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = $this->addMyAccountToBreadcrumb();
return $breadcrumb;
}
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['body_classes'] = array_merge($page['body_classes'], [
'page-customer-account' => true,
]);
return $page;
}
public function initContent()
{
$this->display_column_left = false;
parent::initContent();
$this->module = Module::getInstanceByName('newsletterpro');
if (!Validate::isLoadedObject($this->module)) {
Tools::redirect('index.php');
}
if (!$this->context->customer->isLogged(true)) {
Tools::redirect('index.php?controller=authentication&redirect=module&module=newsletterpro&back='.urlencode($this->module->my_account_url));
}
if (!$this->isFeatureActivated()) {
Tools::redirect('index.php');
}
$is_subscribed = (bool) Db::getInstance()->getValue(
'
SELECT `newsletter` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int) $this->context->customer->id
);
$this->context->smarty->assign([
'id_module' => $this->module->id,
'tpl_location' => $this->module->dir_location.'views/',
'my_account_url' => $this->module->my_account_url,
'is_subscribed' => $is_subscribed,
'list_of_interest' => NewsletterProListOfInterest::getListActiveCustomer($this->context->customer->id),
'category_tree' => $this->getCategoryTree(),
'subscribe_by_category_active' => (bool) pqnp_config('SUBSCRIBE_BY_CATEGORY'),
'customer_subscribe_by_loi_active' => (bool) pqnp_config('CUSTOMER_SUBSCRIBE_BY_LOI'),
]);
$this->context->smarty->assign([
'subscribed_categories' => NewsletterProCustomerCategory::getCategoriesByIdCustomer($this->context->customer->id),
]);
if (NewsletterProTools::is17()) {
$this->setTemplate('module:newsletterpro/views/templates/front/1.7/my_account.tpl');
} elseif ($this->module->isPS16()) {
$this->setTemplate('1.6/my_account.tpl');
} else {
$this->setTemplate('1.5/my_account.tpl');
}
}
public function setMedia()
{
parent::setMedia();
if (NewsletterProTools::is17()) {
$this->context->controller->addCSS([
$this->module->uri_location.'views/css/1.7/my_account.css',
]);
} else {
$this->context->controller->addCSS([
$this->module->uri_location.'views/css/my_account.css',
]);
}
}
public function isFeatureActivated()
{
return (bool) pqnp_config('DISPLYA_MY_ACCOUNT_NP_SETTINGS');
}
public function getCategoryTree()
{
$root = Category::getRootCategory();
$tab_root = [
'id_category' => $root->id,
'name' => $root->name,
];
$customer_category = NewsletterProCustomerCategory::getInstanceByCustomerId((int) $this->context->customer->id);
$selected_cat = [];
if (Validate::isLoadedObject($customer_category)) {
$selected_cat = $customer_category->getCategories();
}
$category_tree = $this->module->renderCategoryTree([
'root' => $tab_root,
'selected_cat' => $selected_cat,
'input_name' => 'categoryBox',
'use_radio' => false,
'disabled_categories' => [],
'use_search' => true,
'use_in_popup' => false,
'use_shop_context' => true,
'ajax_request_url' => Context::getContext()->link->getModuleLink(NewsletterProTools::module()->name, 'ajax', []),
]);
return $category_tree;
}
public function postProcess()
{
if (Tools::isSubmit('submitNewsletterProSettings')) {
$newsletter = (Tools::isSubmit('newsletter') ? (int) Tools::getValue('newsletter') : 0);
if ((bool) pqnp_config('CUSTOMER_SUBSCRIBE_BY_LOI')) {
$list_of_interest = Tools::getValue('list_of_interest');
$customer_loi = NewsletterProCustomerListOfInterests::getInstanceByCustomerId((int) $this->context->customer->id);
if (!empty($list_of_interest)) {
$customer_loi->setCategories($list_of_interest);
$customer_loi->id_customer = (int) $this->context->customer->id;
if (!$customer_loi->save()) {
$this->errors[] = $this->translate->l('Error on updating the list of interests.');
} else {
$subscriber = NewsletterProSubscribers::getInstanceByEmail($this->context->customer->email, (int) $this->context->shop->id);
if (Validate::isLoadedObject($subscriber)) {
$subscriber->setListOfInterest($list_of_interest);
$subscriber->update();
}
}
} else {
if (Validate::isLoadedObject($customer_loi)) {
$customer_loi->setCategories([]);
$customer_loi->update();
}
}
}
if (empty($this->errors)) {
if ((bool) $newsletter) {
NewsletterProSubscriptionManager::newInstance()->subscribe($this->context->customer->email, (int) $this->context->shop->id, true);
} else {
NewsletterProSubscriptionManager::newInstance()->unsubscribe($this->context->customer->email, (int) $this->context->shop->id, true);
}
}
if ((bool) pqnp_config('SUBSCRIBE_BY_CATEGORY')) {
$category_box = Tools::isSubmit('categoryBox') && is_array(Tools::getValue('categoryBox')) ? Tools::getValue('categoryBox') : [];
if (empty($this->errors)) {
if (Tools::isSubmit('subscribed_categories')) {
$subscribed_categories = Tools::getValue('subscribed_categories');
if (Tools::strlen($subscribed_categories) > 0) {
$subscribed_categories = explode(',', $subscribed_categories);
foreach ($subscribed_categories as $id_category) {
$count = (int) Db::getInstance()->getValue('
SELECT COUNT(*) FROM `'._DB_PREFIX_.'category`
WHERE `id_category` = '.(int) $id_category.'
');
if ($count > 0) {
$category_box[] = $id_category;
}
}
}
}
$customer_category = NewsletterProCustomerCategory::getInstanceByCustomerId((int) $this->context->customer->id);
$customer_category->setCategories($category_box);
$customer_category->id_customer = (int) $this->context->customer->id;
if ($customer_category->save()) {
$this->context->customer->newsletter = $newsletter;
} else {
$this->errors[] = $this->translate->l('Error on updating the categories!');
}
}
}
}
}
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProNewsletterModuleFrontController extends ModuleFrontController
{
/**
* @var false
*/
public $auth = false;
/**
* @var true
*/
public $ssl = false;
/**
* @var NewsletterProResponse
*/
protected $response;
/**
* @var NewsletterProRequest
*/
protected $request;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->response = new NewsletterProResponse();
$this->request = new NewsletterProRequest();
}
public function setMedia()
{
parent::setMedia();
}
public function initContent()
{
$module = NewsletterProTools::module();
$context = Context::getContext();
if (!$this->request->has('token_tpl')) {
exit($this->l('Invalid template token'));
}
if (!$this->request->has('email')) {
exit($this->l('Invalid email address'));
}
$idTplHistory = (int) $this->getTplHistoryIdByToken($this->request->get('token_tpl'));
$email = $this->request->get('email');
if (0 == (int) $idTplHistory) {
exit($this->l('Invalid template'));
}
$template = new NewsletterProTemplateHistory((int) $idTplHistory, $email);
$idLang = (int) $context->language->id;
$template = $template->load((int) $idLang);
$message = $template->message(null, false, (int) $idLang);
@ob_end_clean();
$context->smarty->assign([
'template' => $message['body'],
'page_title' => $message['title'],
'jquery_url' => $module->url_location.'views/js/jquery-1.7.2.min.js',
'jquery_url_exists' => file_exists($module->dir_location.'views/js/jquery-1.7.2.min.js'),
'jquery_no_conflict' => (int) $this->request->has('jQueryNoConflict'),
]);
exit($context->smarty->display(pqnp_template_path($module->dir_location.'views/templates/front/newsletter.tpl')));
}
private function getTplHistoryIdByToken($token)
{
return (int) Db::getInstance()->getValue('
SELECT `id_newsletter_pro_tpl_history`
FROM `'._DB_PREFIX_.'newsletter_pro_tpl_history`
WHERE `token` = "'.pSQL($token).'"
');
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProSubscribeModuleFrontController extends ModuleFrontController
{
public $id_newsletter;
private $translate;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->translate = new NewsletterProTranslate(pathinfo(__FILE__, PATHINFO_FILENAME));
}
public function initContent()
{
parent::initContent();
if (NewsletterProTools::is17()) {
$this->setTemplate('module:newsletterpro/views/templates/front/1.7/subscribe.tpl');
} else {
$this->setTemplate('subscribe.tpl');
}
}
public function postProcess()
{
try {
if (Tools::isSubmit('email') && ($email = Tools::getValue('email'))) {
$token = Tools::getValue('token');
$token_ok = false;
if (Tools::isSubmit('mc_token')) {
$token_ok = NewsletterProMailChimpToken::validateToken('mc_token');
}
if (!$token_ok) {
$token_ok = $token == Tools::encrypt($email);
}
if ($token_ok) {
$errors = $this->module->subscribe($email);
$this->errors = array_merge($this->errors, $errors);
} else {
$this->errors[] = $this->translate->l('Invalid token for subscription.');
}
} else {
$this->errors[] = sprintf($this->translate->l('The email %s is not valid.'), (string) Tools::getValue('email'));
}
if (empty($this->errors)) {
$this->context->smarty->assign([
'success_message' => $this->translate->l('You have successfully subscribed at our newsletter.'),
]);
}
} catch (Exception $e) {
$this->errors[] = $this->translate->l('There is an error, please report this error to the website developer.');
if (_PS_MODE_DEV_) {
$this->errors[] = $e->getMessage();
}
NewsletterProLog::writeStrip($e->getMessage(), NewsletterProLog::ERROR_FILE);
}
}
public function getHistoryIdByToken($token)
{
return (int) Db::getInstance()->getValue('SELECT `id_newsletter_pro_tpl_history` FROM `'._DB_PREFIX_.'newsletter_pro_tpl_history` WHERE `token` = "'.pSQL($token).'"');
}
}

View File

@@ -0,0 +1,134 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProSubscribeConfirmationModuleFrontController extends ModuleFrontController
{
public $id_newsletter;
public $auth = false;
public $ssl = true;
private $translate;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->translate = new NewsletterProTranslate(pathinfo(__FILE__, PATHINFO_FILENAME));
}
public function initContent()
{
parent::initContent();
if (NewsletterProTools::is17()) {
$this->setTemplate('module:newsletterpro/views/templates/front/1.7/subscribeconfirmation.tpl');
} else {
$this->setTemplate('subscribeconfirmation.tpl');
}
}
public function getLink($params = [])
{
$params = array_merge($params, [
'token' => Tools::getValue('token'),
]);
return urldecode($this->context->link->getModuleLink($this->module->name, 'subscribeconfirmation', $params));
}
public function postProcess()
{
try {
$token = Tools::getValue('token');
$id = NewsletterProSubscribersTemp::getIdByToken($token);
$subscriber_temp = new NewsletterProSubscribersTemp($id);
if (Validate::isLoadedObject($subscriber_temp)) {
$subscriber_id = (int) $subscriber_temp->moveToSubscribers();
if (0 == $subscriber_id) {
$this->errors = array_merge($this->errors, $subscriber_temp->getErrors());
} else {
NewsletterProSubscriptionManager::newInstance()->subscribe($subscriber_temp->email, (int) $this->context->shop->id, true);
$subscriber = new NewsletterProSubscribers((int) $subscriber_id, (int) $this->context->shop->id);
if (Validate::isLoadedObject($subscriber)) {
// update the customer lif of interest
$customer_loi = NewsletterProCustomerListOfInterests::getInstanceByCustomerEmail($subscriber->email);
if (Validate::isLoadedObject($customer_loi)) {
$customer_loi->setCategories($subscriber->getListOfInterest());
$customer_loi->update();
}
}
}
} else {
$this->errors[] = $this->translate->l('This link has expired or the token in invalid.');
}
if (empty($this->errors)) {
$success_message = [];
$success_message[] = $this->translate->l('You have successfully subscribed at our newsletter.');
$subscrbtion_template = $subscriber_temp->getSubscriptionTemplateInstance();
if (is_object($subscrbtion_template)) {
if ($subscrbtion_template->hasValidVoucher()) {
$unsubscribe_link = urldecode($this->context->link->getModuleLink(NewsletterProTools::module()->name, 'unsubscribe', [
'email' => $subscriber_temp->email,
'u_token' => Tools::encrypt($subscriber_temp->email),
'msg' => true,
], null, $this->context->language->id, $this->context->shop->id));
$subscrbtion_template->extendVars([
'unsubscribe_link' => $unsubscribe_link,
'unsubscribe' => '<a href="'.$unsubscribe_link.'" target="_blank">'.NewsletterProTools::module()->l('unsubscribe').'</a>',
]);
$message = trim($subscrbtion_template->renderEmailSubscribeVoucherMessage((int) $this->context->language->id));
$subject = NewsletterProHTMLRender::getTitle($message);
$success_message[] = sprintf($this->translate->l('You can use this voucher %s.'), $subscrbtion_template->getVoucherCode());
if ((bool) pqnp_config('DEBUG_MODE')) {
NewsletterProSendManager::getInstance()->sendNewsletter($subject, $message, $subscriber_temp->email, [], [], false);
} else {
@NewsletterProSendManager::getInstance()->sendNewsletter($subject, $message, $subscriber_temp->email, [], [], false);
}
}
}
$this->context->smarty->assign([
'success_message' => $success_message,
]);
}
} catch (Exception $e) {
if (_PS_MODE_DEV_) {
$this->errors[] = $e->getMessage();
} else {
$this->errors[] = $this->translate->l('There is an error, please report this error to the website developer.');
}
NewsletterProLog::writeStrip($e->getMessage(), NewsletterProLog::ERROR_FILE);
}
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProSubscriptionModuleFrontController extends ModuleFrontController
{
public $auth = false;
public $ssl = true;
private $translate;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->translate = new NewsletterProTranslate(pathinfo(__FILE__, PATHINFO_FILENAME));
if (!(bool) pqnp_config_get('SUBSCRIPTION_CONTROLLER_ENABLED', false)) {
return $this->displayPageNotFound();
}
$template = new NewsletterProSubscriptionTpl((int) pqnp_config_get('SUBSCRIPTION_CONTROLLER_TEMPLATE_ID', 0));
if (!Validate::isLoadedObject($template)) {
return $this->displayPageNotFound();
}
}
private function displayPageNotFound()
{
Controller::getController('PageNotFoundController')->run();
exit;
}
public function setMedia()
{
parent::setMedia();
}
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['body_classes'] = array_merge($page['body_classes'], [
'page-customer-account' => true,
]);
return $page;
}
public function getLink($params = [])
{
$params = array_merge($params, []);
return urldecode($this->context->link->getModuleLink($this->module->name, 'subscription', $params));
}
public function initContent()
{
parent::initContent();
if (NewsletterProTools::is17()) {
$this->setTemplate('module:newsletterpro/views/templates/front/1.7/subscription.tpl');
} else {
$this->setTemplate('subscription.tpl');
}
}
public function postProcess()
{
}
}

View File

@@ -0,0 +1,163 @@
<?php
/**
* Since 2013 Ovidiu Cimpean.
*
* Ovidiu Cimpean - Newsletter Pro © All rights reserved.
*
* DISCLAIMER
*
* Do not edit, modify or copy this file.
* If you wish to customize it, contact us at addons4prestashop@gmail.com.
*
* @author Ovidiu Cimpean <addons4prestashop@gmail.com>
* @copyright Since 2013 Ovidiu Cimpean
* @license Do not edit, modify or copy this file
*
* @version Release: 4
*/
class NewsletterProUnsubscribeModuleFrontController extends ModuleFrontController
{
public $id_newsletter;
private $translate;
public function __construct()
{
if ((bool) Configuration::get('PS_SSL_ENABLED')) {
$this->ssl = true;
}
parent::__construct();
$this->translate = new NewsletterProTranslate(pathinfo(__FILE__, PATHINFO_FILENAME));
}
public function initContent()
{
parent::initContent();
if (NewsletterProTools::is17()) {
$this->setTemplate('module:newsletterpro/views/templates/front/1.7/unsubscribe.tpl');
} else {
$this->setTemplate('unsubscribe.tpl');
}
}
public function postProcess()
{
try {
if (Tools::isSubmit('email')) {
$email = trim(Tools::getValue('email'));
if (Validate::isEmail($email)) {
$token_ok = false;
if (Tools::isSubmit('mc_token')) {
$token_ok = NewsletterProMailChimpToken::validateToken('mc_token');
}
if (!$token_ok) {
$token_ok = Tools::isSubmit('u_token') && Tools::getValue('u_token') === Tools::encrypt($email);
}
if (!$token_ok) {
$this->context->smarty->assign([
'token_not_valid' => true,
]);
} else {
$result = NewsletterProSubscriptionManager::newInstance()->unsubscribe($email, (int) $this->context->shop->id, true);
if (in_array(true, $result)) {
$this->id_newsletter = $this->getHistoryIdByToken(Tools::getValue('token'));
if ($this->id_newsletter) {
if (self::isForwarder($result)) {
// deleted the forwarders is he unsubscribe
Db::getInstance()->delete('newsletter_pro_forward', '`from` = "'.pSQL($email).'"');
if ($this->updateFwdUnsubscribed()) {
$fwd_unsubscribed = new NewsletterProFwdUnsubscribed();
$fwd_unsubscribed->id_newsletter_pro_tpl_history = (int) $this->id_newsletter;
$fwd_unsubscribed->email = $email;
$fwd_unsubscribed->add();
}
} else {
if ($this->updateUnsubscribed()) {
$unsubscribed = new NewsletterProUnsubscribed();
$unsubscribed->id_newsletter_pro_tpl_history = (int) $this->id_newsletter;
$unsubscribed->email = $email;
$unsubscribed->add();
}
}
}
$this->context->smarty->assign([
'unsubscribe' => true,
]);
} else {
$this->context->smarty->assign([
'email_not_found' => true,
]);
}
}
} else {
$this->context->smarty->assign([
'email_not_valid' => true,
]);
}
} else {
Tools::redirect('index.php');
}
if ('false' == Tools::getValue('msg') || '0' == Tools::getValue('msg')) {
Tools::redirect('index.php');
}
} catch (Exception $e) {
NewsletterProLog::writeStrip($e->__toString(), NewsletterProLog::ERROR_FILE);
$this->context->smarty->assign([
'pqnp_errors' => $this->translate->l('Oops, an error has occurred.'),
]);
}
}
public static function isForwarder($result)
{
if (isset($result['newsletter_pro_forward']) && true == $result['newsletter_pro_forward']) {
return true;
}
return false;
}
public function getHistoryIdByToken($token)
{
return (int) Db::getInstance()->getValue('SELECT `id_newsletter_pro_tpl_history` FROM `'._DB_PREFIX_.'newsletter_pro_tpl_history` WHERE `token` = "'.pSQL($token).'"');
}
public function updateUnsubscribed()
{
if (!isset($this->id_newsletter)) {
return false;
}
$sql = 'UPDATE `'._DB_PREFIX_.'newsletter_pro_tpl_history`
SET `unsubscribed` = unsubscribed + 1
WHERE `id_newsletter_pro_tpl_history` = '.(int) $this->id_newsletter.';';
return Db::getInstance()->execute($sql);
}
public function updateFwdUnsubscribed()
{
if (!isset($this->id_newsletter)) {
return false;
}
$sql = 'UPDATE `'._DB_PREFIX_.'newsletter_pro_tpl_history`
SET `fwd_unsubscribed` = fwd_unsubscribed + 1
WHERE `id_newsletter_pro_tpl_history` = '.(int) $this->id_newsletter.';';
return Db::getInstance()->execute($sql);
}
}