ver. 0.279: Newsletter frontend migration, Languages facade elimination, bug fix newsletter_unsubscribe
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
namespace Domain\Newsletter;
|
||||
|
||||
use Domain\Settings\SettingsRepository;
|
||||
use Domain\Article\ArticleRepository;
|
||||
|
||||
class NewsletterRepository
|
||||
{
|
||||
@@ -9,11 +10,29 @@ class NewsletterRepository
|
||||
|
||||
private $db;
|
||||
private SettingsRepository $settingsRepository;
|
||||
private ?ArticleRepository $articleRepository;
|
||||
private ?NewsletterPreviewRenderer $previewRenderer;
|
||||
|
||||
public function __construct($db, ?SettingsRepository $settingsRepository = null)
|
||||
{
|
||||
public function __construct(
|
||||
$db,
|
||||
?SettingsRepository $settingsRepository = null,
|
||||
?ArticleRepository $articleRepository = null,
|
||||
?NewsletterPreviewRenderer $previewRenderer = null
|
||||
) {
|
||||
$this->db = $db;
|
||||
$this->settingsRepository = $settingsRepository ?? new SettingsRepository($db);
|
||||
$this->articleRepository = $articleRepository;
|
||||
$this->previewRenderer = $previewRenderer;
|
||||
}
|
||||
|
||||
private function getArticleRepository(): ArticleRepository
|
||||
{
|
||||
return $this->articleRepository ?? ($this->articleRepository = new ArticleRepository($this->db));
|
||||
}
|
||||
|
||||
private function getPreviewRenderer(): NewsletterPreviewRenderer
|
||||
{
|
||||
return $this->previewRenderer ?? ($this->previewRenderer = new NewsletterPreviewRenderer());
|
||||
}
|
||||
|
||||
public function getSettings(): array
|
||||
@@ -289,4 +308,138 @@ class NewsletterRepository
|
||||
'total' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
// ── Frontend methods ──
|
||||
|
||||
public function unsubscribe(string $hash): bool
|
||||
{
|
||||
$id = $this->db->get('pp_newsletter', 'id', ['hash' => $hash]);
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->delete('pp_newsletter', ['id' => $id]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function confirmSubscription(string $hash): bool
|
||||
{
|
||||
$id = $this->db->get('pp_newsletter', 'id', ['AND' => ['hash' => $hash, 'status' => 0]]);
|
||||
if (!$id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->update('pp_newsletter', ['status' => 1], ['id' => $id]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getHashByEmail(string $email): ?string
|
||||
{
|
||||
$hash = $this->db->get('pp_newsletter', 'hash', ['email' => $email]);
|
||||
return $hash ? (string)$hash : null;
|
||||
}
|
||||
|
||||
public function removeByEmail(string $email): bool
|
||||
{
|
||||
if (!$this->db->get('pp_newsletter', 'id', ['email' => $email])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool)$this->db->delete('pp_newsletter', ['email' => $email]);
|
||||
}
|
||||
|
||||
public function signup(string $email, string $serverName, bool $ssl, array $settings): bool
|
||||
{
|
||||
if (!\S::email_check($email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->db->get('pp_newsletter', 'id', ['email' => $email])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hash = md5(time() . $email);
|
||||
|
||||
$text = ($settings['newsletter_header'] ?? '');
|
||||
$text .= $this->templateByName('#potwierdzenie-zapisu-do-newslettera');
|
||||
$text .= ($settings['newsletter_footer'] ?? '');
|
||||
|
||||
$base = $ssl ? 'https' : 'http';
|
||||
$link = '/newsletter/confirm/hash=' . $hash;
|
||||
$text = str_replace('[LINK]', $link, $text);
|
||||
$text = str_replace('[WYPISZ_SIE]', '', $text);
|
||||
|
||||
$text = preg_replace(
|
||||
"-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i",
|
||||
"$1" . $base . "://" . $serverName . "$2$4",
|
||||
$text
|
||||
);
|
||||
$text = preg_replace(
|
||||
"-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i",
|
||||
"$1" . $base . "://" . $serverName . "$2$4",
|
||||
$text
|
||||
);
|
||||
|
||||
$lang = \S::get_session('lang-' . \S::get_session('current-lang'));
|
||||
$subject = $lang['potwierdz-zapisanie-sie-do-newslettera'] ?? 'Newsletter';
|
||||
\S::send_email($email, $subject, $text);
|
||||
|
||||
$this->db->insert('pp_newsletter', ['email' => $email, 'hash' => $hash, 'status' => 0]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function sendQueued(int $limit, string $serverName, bool $ssl, string $unsubscribeLabel): bool
|
||||
{
|
||||
$settingsDetails = $this->settingsRepository->getSettings();
|
||||
|
||||
$results = $this->db->query('SELECT * FROM pp_newsletter_send ORDER BY id ASC LIMIT ' . (int)$limit);
|
||||
$results = $results ? $results->fetchAll() : [];
|
||||
|
||||
if (!is_array($results) || empty($results)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$renderer = $this->getPreviewRenderer();
|
||||
$articleRepo = $this->getArticleRepository();
|
||||
|
||||
foreach ($results as $row) {
|
||||
$dates = explode(' - ', $row['dates']);
|
||||
|
||||
$articles = [];
|
||||
if (isset($dates[0], $dates[1])) {
|
||||
$articles = $articleRepo->articlesByDateAdd($dates[0], $dates[1]);
|
||||
}
|
||||
|
||||
$text = $renderer->render(
|
||||
is_array($articles) ? $articles : [],
|
||||
$settingsDetails,
|
||||
$this->templateDetails((int)$row['id_template']),
|
||||
(string)$row['dates']
|
||||
);
|
||||
|
||||
$base = $ssl ? 'https' : 'http';
|
||||
|
||||
$text = preg_replace(
|
||||
"-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|http://).)*)(['\"][^>]*>)-i",
|
||||
"$1" . $base . "://" . $serverName . "$2$4",
|
||||
$text
|
||||
);
|
||||
$text = preg_replace(
|
||||
"-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|http://).)*)(['\"][^>]*>)-i",
|
||||
"$1" . $base . "://" . $serverName . "$2$4",
|
||||
$text
|
||||
);
|
||||
|
||||
$hash = $this->getHashByEmail($row['email']);
|
||||
$link = $base . "://" . $serverName . '/newsletter/unsubscribe/hash=' . $hash;
|
||||
$text = str_replace('[WYPISZ_SIE]', '<a href="' . $link . '">' . $unsubscribeLabel . '</a>', $text);
|
||||
|
||||
\S::send_email($row['email'], 'Newsletter ze strony: ' . $serverName, $text);
|
||||
|
||||
$this->db->delete('pp_newsletter_send', ['id' => $row['id']]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +394,8 @@ class App
|
||||
global $mdb;
|
||||
return new \admin\Controllers\ShopProductController(
|
||||
new \Domain\Product\ProductRepository( $mdb ),
|
||||
new \Domain\Integrations\IntegrationsRepository( $mdb )
|
||||
new \Domain\Integrations\IntegrationsRepository( $mdb ),
|
||||
new \Domain\Languages\LanguagesRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'ShopClients' => function() {
|
||||
|
||||
@@ -91,7 +91,7 @@ class SettingsController
|
||||
$likeNormalized = '%' . $phraseNormalized . '%';
|
||||
|
||||
$items = [];
|
||||
$defaultLang = (string)\front\factory\Languages::default_language();
|
||||
$defaultLang = (string)$this->languagesRepository->defaultLanguage();
|
||||
|
||||
try {
|
||||
$productStmt = $mdb->query(
|
||||
|
||||
@@ -20,7 +20,7 @@ class ShopCategoryController
|
||||
return \Tpl::view('shop-category/categories-list', [
|
||||
'categories' => $this->repository->subcategories(null),
|
||||
'level' => 0,
|
||||
'dlang' => \front\factory\Languages::default_language(),
|
||||
'dlang' => $this->languagesRepository->defaultLanguage(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ class ShopCategoryController
|
||||
'pid' => \S::get('pid'),
|
||||
'languages' => $this->languagesRepository->languagesList(),
|
||||
'sort_types' => $this->repository->sortTypes(),
|
||||
'dlang' => $this->languagesRepository->defaultLanguage(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ class ShopCategoryController
|
||||
echo \Tpl::view('shop-category/category-browse-list', [
|
||||
'categories' => $this->repository->subcategories(null),
|
||||
'level' => 0,
|
||||
'dlang' => \front\factory\Languages::default_language(),
|
||||
'dlang' => $this->languagesRepository->defaultLanguage(),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace admin\Controllers;
|
||||
use Domain\Product\ProductRepository;
|
||||
use Domain\Category\CategoryRepository;
|
||||
use Domain\Integrations\IntegrationsRepository;
|
||||
use Domain\Languages\LanguagesRepository;
|
||||
use admin\ViewModels\Forms\FormEditViewModel;
|
||||
use admin\ViewModels\Forms\FormField;
|
||||
use admin\ViewModels\Forms\FormTab;
|
||||
@@ -19,11 +20,13 @@ class ShopProductController
|
||||
{
|
||||
private ProductRepository $repository;
|
||||
private IntegrationsRepository $integrationsRepository;
|
||||
private LanguagesRepository $languagesRepository;
|
||||
|
||||
public function __construct(ProductRepository $repository, IntegrationsRepository $integrationsRepository)
|
||||
public function __construct(ProductRepository $repository, IntegrationsRepository $integrationsRepository, LanguagesRepository $languagesRepository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
$this->integrationsRepository = $integrationsRepository;
|
||||
$this->languagesRepository = $languagesRepository;
|
||||
}
|
||||
|
||||
// ─── Krok 6: Lista / widok ───────────────────────────────────────
|
||||
@@ -35,7 +38,7 @@ class ShopProductController
|
||||
{
|
||||
$apiloEnabled = $this->integrationsRepository->getSetting( 'apilo', 'enabled' );
|
||||
$shopproEnabled = $this->integrationsRepository->getSetting( 'shoppro', 'enabled' );
|
||||
$dlang = \front\factory\Languages::default_language();
|
||||
$dlang = $this->languagesRepository->defaultLanguage();
|
||||
|
||||
$sortableColumns = [ 'id', 'name', 'price_brutto', 'status', 'promoted', 'quantity' ];
|
||||
|
||||
@@ -221,7 +224,7 @@ class ShopProductController
|
||||
$sets = \shop\ProductSet::sets_list();
|
||||
$producers = ( new \Domain\Producer\ProducerRepository( $db ) )->allProducers();
|
||||
$units = ( new \Domain\Dictionaries\DictionariesRepository( $db ) )->allUnits();
|
||||
$dlang = \front\factory\Languages::default_language();
|
||||
$dlang = $this->languagesRepository->defaultLanguage();
|
||||
|
||||
$viewModel = $this->buildProductFormViewModel(
|
||||
$product, $languages, $categories, $layouts, $products, $sets, $producers, $units, $dlang
|
||||
@@ -949,7 +952,7 @@ class ShopProductController
|
||||
return \Tpl::view( 'shop-product/product-combination', [
|
||||
'product' => $this->repository->findForAdmin( (int) \S::get( 'product_id' ) ),
|
||||
'attributes' => ( new \Domain\Attribute\AttributeRepository( $db ) )->getAttributesListForCombinations(),
|
||||
'default_language' => \front\factory\Languages::default_language(),
|
||||
'default_language' => $this->languagesRepository->defaultLanguage(),
|
||||
'product_permutations' => $this->repository->getCombinationsForTable( (int) \S::get( 'product_id' ) ),
|
||||
] );
|
||||
}
|
||||
@@ -1146,7 +1149,7 @@ class ShopProductController
|
||||
return \Tpl::view( 'shop-product/mass-edit', [
|
||||
'products' => $this->repository->allProductsForMassEdit(),
|
||||
'categories' => $categoryRepository->subcategories( null ),
|
||||
'dlang' => \front\factory\Languages::default_language(),
|
||||
'dlang' => $this->languagesRepository->defaultLanguage(),
|
||||
] );
|
||||
}
|
||||
|
||||
|
||||
49
autoload/front/Controllers/NewsletterController.php
Normal file
49
autoload/front/Controllers/NewsletterController.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
namespace front\Controllers;
|
||||
|
||||
use Domain\Newsletter\NewsletterRepository;
|
||||
|
||||
class NewsletterController
|
||||
{
|
||||
private NewsletterRepository $repository;
|
||||
|
||||
public function __construct( NewsletterRepository $repository )
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function signin()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$result = [ 'status' => 'bad' ];
|
||||
|
||||
if ( $this->repository->signup( \S::get( 'email' ), $_SERVER['SERVER_NAME'], !empty( $settings['ssl'] ), $settings ) )
|
||||
$result = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( $this->repository->confirmSubscription( \S::get( 'hash' ) ) )
|
||||
\S::alert( $lang['email-zostal-dodany-do-listy-newsletter'] );
|
||||
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function unsubscribe()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( $this->repository->unsubscribe( \S::get( 'hash' ) ) )
|
||||
\S::alert( $lang['email-zostal-usuniety-z-listy-newsletter'] );
|
||||
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
12
autoload/front/Views/Languages.php
Normal file
12
autoload/front/Views/Languages.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function render( $languages )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> languages = $languages;
|
||||
return $tpl -> render( 'site/languages' );
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
namespace front\Views;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function newsletter()
|
||||
{
|
||||
public static function render()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'newsletter/newsletter' );
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function signin()
|
||||
{
|
||||
$result = [ 'status' => 'bad' ];
|
||||
|
||||
if ( \front\factory\Newsletter::newsletter_signin( \S::get( 'email' ) ) )
|
||||
$result = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function confirm()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( \front\factory\Newsletter::newsletter_confirm( \S::get( 'hash' ) ) )
|
||||
\S::alert( $lang['email-zostal-dodany-do-listy-newsletter'] );
|
||||
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function unsubscribe()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( \front\factory\Newsletter::newsletter_unsubscribe( \S::get( 'hash' ) ) )
|
||||
\S::alert( $lang['email-zostal-usuniety-z-listy-newsletter'] );
|
||||
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -53,14 +53,21 @@ class Site
|
||||
if ( $category )
|
||||
return \front\view\ShopCategory::category_view( $category, $lang_id, \S::get( 'bs' ) );
|
||||
|
||||
// stare klasy
|
||||
$class = '\front\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
// nowe kontrolery z DI
|
||||
$module = \S::get( 'module' );
|
||||
$action = \S::get( 'action' );
|
||||
$controllerFactories = self::getControllerFactories();
|
||||
|
||||
$moduleName = implode( '', array_map( 'ucfirst', explode( '_', $module ) ) );
|
||||
if ( isset( $controllerFactories[$moduleName] ) and $action )
|
||||
{
|
||||
$controller = $controllerFactories[$moduleName]();
|
||||
if ( method_exists( $controller, $action ) )
|
||||
return $controller->$action();
|
||||
}
|
||||
|
||||
// stare klasy
|
||||
$class = '\front\controls\\' . $moduleName;
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $action ) )
|
||||
return call_user_func_array( array( $class, $action ), array() );
|
||||
@@ -132,5 +139,17 @@ class Site
|
||||
if ( file_exists( 'modules/actions.php' ) )
|
||||
include 'modules/actions.php';
|
||||
}
|
||||
|
||||
public static function getControllerFactories()
|
||||
{
|
||||
return [
|
||||
'Newsletter' => function() {
|
||||
global $mdb;
|
||||
return new \front\Controllers\NewsletterController(
|
||||
new \Domain\Newsletter\NewsletterRepository( $mdb )
|
||||
);
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
/**
|
||||
* Fasada delegujaca do Domain\Languages\LanguagesRepository.
|
||||
*/
|
||||
class Languages
|
||||
{
|
||||
public static function default_language()
|
||||
{
|
||||
global $mdb;
|
||||
$repo = new \Domain\Languages\LanguagesRepository($mdb);
|
||||
return $repo->defaultLanguage();
|
||||
}
|
||||
|
||||
public static function active_languages()
|
||||
{
|
||||
global $mdb;
|
||||
$repo = new \Domain\Languages\LanguagesRepository($mdb);
|
||||
return $repo->activeLanguages();
|
||||
}
|
||||
|
||||
public static function lang_translations($language = 'pl')
|
||||
{
|
||||
global $mdb;
|
||||
$repo = new \Domain\Languages\LanguagesRepository($mdb);
|
||||
return $repo->translations($language);
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function newsletter_unsubscribe( $hash )
|
||||
{
|
||||
global $mdb;
|
||||
if ( !$id = $mdb -> get( 'pp_newsletter', 'id', [ 'hash' => $hash ] ) )
|
||||
return false;
|
||||
else
|
||||
$mdb -> delete( 'pp_newsletter', [ 'status' => 1 ], [ 'id' => $id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function newsletter_confirm( $hash )
|
||||
{
|
||||
global $mdb;
|
||||
if ( !$id = $mdb -> get( 'pp_newsletter', 'id', [ 'AND' => [ 'hash' => $hash, 'status' => 0 ] ] ) )
|
||||
return false;
|
||||
else
|
||||
$mdb -> update( 'pp_newsletter', [ 'status' => 1 ], [ 'id' => $id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function newsletter_send( $limit = 5 )
|
||||
{
|
||||
global $mdb, $settings, $lang;
|
||||
$settingsRepository = new \Domain\Settings\SettingsRepository( $mdb );
|
||||
$newsletterRepository = new \Domain\Newsletter\NewsletterRepository( $mdb, $settingsRepository );
|
||||
$previewRenderer = new \Domain\Newsletter\NewsletterPreviewRenderer();
|
||||
$settingsDetails = $settingsRepository -> getSettings();
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_newsletter_send ORDER BY id ASC LIMIT ' . $limit ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) )
|
||||
{
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$dates = explode( ' - ', $row['dates'] );
|
||||
|
||||
$articles = [];
|
||||
$articleRepository = new \Domain\Article\ArticleRepository( $mdb );
|
||||
if ( isset( $dates[0], $dates[1] ) )
|
||||
$articles = $articleRepository->articlesByDateAdd( $dates[0], $dates[1] );
|
||||
|
||||
$text = $previewRenderer -> render(
|
||||
is_array( $articles ) ? $articles : [],
|
||||
$settingsDetails,
|
||||
$newsletterRepository -> templateDetails( (int)$row['id_template'] ),
|
||||
(string)$row['dates']
|
||||
);
|
||||
|
||||
if ( $settings['ssl'] ) $base = 'https'; else $base = 'http';
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|http://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|http://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$link = $base . "://" . $_SERVER['SERVER_NAME'] . '/newsletter/unsubscribe/hash=' . \front\factory\Newsletter::get_hash( $row['email'] );
|
||||
|
||||
$text = str_replace( '[WYPISZ_SIE]', '<a href="' . $link . '">' . $lang['wypisz-sie'] . '</a>', $text );
|
||||
|
||||
\S::send_email( $row['email'], 'Newsletter ze strony: ' . $_SERVER['SERVER_NAME'], $text );
|
||||
|
||||
$mdb -> delete( 'pp_newsletter_send', [ 'id' => $row['id'] ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_hash( $email )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_newsletter', 'hash', [ 'email' => $email ] );
|
||||
}
|
||||
|
||||
public static function newsletter_signin( $email )
|
||||
{
|
||||
global $mdb, $lang, $settings;
|
||||
|
||||
if ( !\S::email_check( $email ) )
|
||||
return false;
|
||||
|
||||
if ( !$mdb -> get( 'pp_newsletter', 'id', [ 'email' => $email ] ) )
|
||||
{
|
||||
$hash = md5( time() . $email );
|
||||
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= \front\factory\Newsletter::get_template( '#potwierdzenie-zapisu-do-newslettera' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
|
||||
$link = '/newsletter/confirm/hash=' . $hash;
|
||||
|
||||
$text = str_replace( '[LINK]', $link, $text );
|
||||
|
||||
$text = str_replace( '[WYPISZ_SIE]', '', $text );
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$send = \S::send_email( $email, $lang['potwierdz-zapisanie-sie-do-newslettera'], $text );
|
||||
|
||||
$mdb -> insert( 'pp_newsletter', [ 'email' => $email, 'hash' => $hash, 'status' => 0 ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_template( $template_name )
|
||||
{
|
||||
global $mdb;
|
||||
$repository = new \Domain\Newsletter\NewsletterRepository( $mdb );
|
||||
return $repository -> templateByName( (string)$template_name );
|
||||
}
|
||||
|
||||
public static function newsletter_signout( $email )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> get( 'pp_newsletter', 'id', [ 'email' => $email ] ) )
|
||||
return $mdb -> delete( 'pp_newsletter', [ 'email' => $email ] );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ class Pages
|
||||
|
||||
$page['language']['seo_link'] ? $url = '/' . $page['language']['seo_link'] : $url = '/s-' . $page['id'] . '-' . \S::seo( $page['language']['title'] );
|
||||
|
||||
if ( $lang_id != \front\factory\Languages::default_language() and $url != '#' )
|
||||
if ( $lang_id != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' )
|
||||
$url = '/' . $lang_id . $url;
|
||||
|
||||
return $url;
|
||||
|
||||
@@ -35,7 +35,7 @@ class ShopCategory
|
||||
|
||||
$category['language']['seo_link'] ? $url = '/' . $category['language']['seo_link'] : $url = '/k-' . $category['id'] . '-' . \S::seo( $category['language']['title'] );
|
||||
|
||||
if ( \S::get_session( 'current-lang' ) != \front\factory\Languages::default_language() and $url != '#' )
|
||||
if ( \S::get_session( 'current-lang' ) != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' )
|
||||
$url = '/' . \S::get_session( 'current-lang' ) . $url;
|
||||
|
||||
return $url;
|
||||
|
||||
@@ -93,7 +93,7 @@ class ShopClient
|
||||
if ( $data = $mdb -> get( 'pp_shop_clients', [ 'id', 'email', 'register_date' ], [ 'AND' => [ 'hash' => $hash, 'status' => 1, 'password_recovery' => 1 ] ] ) )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= \front\factory\Newsletter::get_template( '#nowe-haslo' );
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#nowe-haslo' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
@@ -129,7 +129,7 @@ class ShopClient
|
||||
if ( $hash = $mdb -> get( 'pp_shop_clients', 'hash', [ 'AND' => [ 'email' => $email, 'status' => 1 ] ] ) )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= \front\factory\Newsletter::get_template( '#odzyskiwanie-hasla-link' );
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#odzyskiwanie-hasla-link' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
@@ -164,7 +164,7 @@ class ShopClient
|
||||
$email = $mdb -> get( 'pp_shop_clients', 'email', [ 'id' => $id ] );
|
||||
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= \front\factory\Newsletter::get_template( '#potwierdzenie-aktywacji-konta' );
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#potwierdzenie-aktywacji-konta' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
@@ -201,7 +201,7 @@ class ShopClient
|
||||
] ) )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= \front\factory\Newsletter::get_template( '#potwierdzenie-rejestracji' );
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#potwierdzenie-rejestracji' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function languages()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> languages = \front\factory\Languages::active_languages();
|
||||
return $tpl -> render( 'site/languages' );
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ class Site
|
||||
] ),
|
||||
$html );
|
||||
$html = str_replace( '[NEWSLETTER]',
|
||||
\front\view\Newsletter::newsletter(),
|
||||
\front\Views\Newsletter::render(),
|
||||
$html );
|
||||
$html = str_replace( '[UZYTKOWNIK_MINI_LOGOWANIE]',
|
||||
\front\view\ShopClient::mini_login(),
|
||||
@@ -333,7 +333,7 @@ class Site
|
||||
$html = str_replace( '[TITLE]', $page['language']['meta_title'] ? $page['language']['meta_title'] . ' | ' . $settings['firm_name'] : $page['language']['title'] . ' | ' . $settings['firm_name'], $html );
|
||||
$html = str_replace( '[META_KEYWORDS]', $page['language']['meta_keywords'], $html );
|
||||
$html = str_replace( '[META_DESCRIPTION]', $page['language']['meta_description'], $html );
|
||||
$html = str_replace( '[JEZYKI]', \front\view\Languages::languages(), $html );
|
||||
$html = str_replace( '[JEZYKI]', \front\Views\Languages::render( ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->activeLanguages() ), $html );
|
||||
$html = str_replace( '[TYTUL_STRONY]', self::title( $page['language']['title'], $page['show_title'], $page['language']['page_title'] ), $html );
|
||||
$html = str_replace( '[WYSZUKIWARKA]', \shop\Search::simple_form(), $html );
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class Category implements \ArrayAccess
|
||||
global $mdb;
|
||||
|
||||
if ( !$lang_id )
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
$lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage();
|
||||
|
||||
return $mdb -> get( 'pp_shop_categories_langs', 'title', [ 'AND' => [ 'category_id' => $category_id, 'lang_id' => $lang_id ] ] );
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ class Product implements \ArrayAccess
|
||||
global $mdb;
|
||||
|
||||
if ( !$lang_id )
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
$lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage();
|
||||
|
||||
$result = $mdb -> get( 'pp_shop_products', '*', [ 'id' => $product_id ] );
|
||||
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
|
||||
@@ -292,7 +292,7 @@ class Product implements \ArrayAccess
|
||||
global $mdb;
|
||||
|
||||
if ( !$lang_id )
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
$lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage();
|
||||
|
||||
$repository = new \Domain\Product\ProductRepository($mdb);
|
||||
return $repository->getName($product_id, $lang_id);
|
||||
@@ -377,7 +377,7 @@ class Product implements \ArrayAccess
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
$lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage();
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_products_langs', '*', [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => $lang_id ] ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row )
|
||||
|
||||
@@ -47,7 +47,7 @@ class ProductAttribute implements \ArrayAccess
|
||||
global $mdb;
|
||||
|
||||
if ( !$lang_id )
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
$lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage();
|
||||
|
||||
$result = $mdb -> get( 'pp_shop_attributes', '*', [ 'id' => $attribute_id ] );
|
||||
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
|
||||
|
||||
Reference in New Issue
Block a user