Add view classes for articles, banners, languages, menu, newsletter, containers, shop categories, clients, payment methods, products, and search
- Created `Articles` class for rendering article views including full articles, miniature lists, and news sections. - Added `Banners` class for handling banner displays. - Introduced `Languages` class for rendering language options. - Implemented `Menu` class for rendering page and menu structures. - Developed `Newsletter` class for newsletter rendering. - Created `Scontainers` class for rendering specific containers. - Added `ShopCategory` class for managing shop category views and pagination. - Implemented `ShopClient` class for client-related views including address management and login forms. - Created `ShopPaymentMethod` class for displaying payment methods in the basket. - Added `ShopProduct` class for generating product URLs. - Introduced `ShopSearch` class for rendering a simple search form. - Added `.htaccess` file in the plugins directory to enhance security by restricting access to sensitive files and directories.
This commit is contained in:
241
autoload/front/Views/Articles.php
Normal file
241
autoload/front/Views/Articles.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Articles
|
||||
{
|
||||
/**
|
||||
* Renderuje pelny widok pojedynczego artykulu.
|
||||
*/
|
||||
public static function fullArticle( $article )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->article = $article;
|
||||
return $tpl->render( 'articles/article' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderuje liste artykulow w trybie miniaturek z pagerem.
|
||||
*/
|
||||
public static function miniatureArticlesList( $articles, $ls, $bs, $page )
|
||||
{
|
||||
$out = '';
|
||||
|
||||
if ( is_array( $articles ) ) foreach ( $articles as $article )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->article = $article;
|
||||
$out .= $tpl->render( 'articles/article-miniature' );
|
||||
}
|
||||
|
||||
if ( $ls > 1 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->ls = $ls;
|
||||
$tpl->bs = $bs ? $bs : 1;
|
||||
$tpl->page = $page;
|
||||
$out .= $tpl->render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderuje liste artykulow w trybie wprowadzen z pagerem.
|
||||
*/
|
||||
public static function entryArticlesList( $articles, $ls, $bs, $page )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->page_id = $page['id'];
|
||||
$tpl->articles = $articles;
|
||||
$out = $tpl->render( 'articles/articles-entries' );
|
||||
|
||||
if ( $ls > 1 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->ls = $ls;
|
||||
$tpl->bs = $bs ? $bs : 1;
|
||||
$tpl->page = $page;
|
||||
$out .= $tpl->render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderuje liste pelnych artykulow z pagerem.
|
||||
*/
|
||||
public static function fullArticlesList( $articles, $ls, $bs, $page )
|
||||
{
|
||||
$out = '';
|
||||
|
||||
if ( is_array( $articles ) ) foreach ( $articles as $article )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->article = $article;
|
||||
$out .= $tpl->render( 'articles/article-full' );
|
||||
}
|
||||
|
||||
if ( $ls > 1 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->ls = $ls;
|
||||
$tpl->bs = $bs ? $bs : 1;
|
||||
$tpl->page = $page;
|
||||
$out .= $tpl->render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderuje box z aktualnosciami.
|
||||
*/
|
||||
public static function news( $page_id, $articles )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->page_id = $page_id;
|
||||
$tpl->articles = $articles;
|
||||
return $tpl->render( 'articles/news' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderuje prosta liste artykulow (news-list).
|
||||
*/
|
||||
public static function newsList( $articles )
|
||||
{
|
||||
return \Shared\Tpl\Tpl::view( 'articles/news-list', [
|
||||
'articles' => $articles
|
||||
] );
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// UTILITY (czyste transformacje HTML, brak DB)
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Generuje spis tresci z naglowkow HTML.
|
||||
*/
|
||||
public static function generateTableOfContents( $content )
|
||||
{
|
||||
$result = '';
|
||||
$currentLevel = [];
|
||||
|
||||
preg_match_all( '/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER );
|
||||
|
||||
$firstLevel = true;
|
||||
|
||||
foreach ( $matches as $match )
|
||||
{
|
||||
$level = intval( substr( $match[1], 1 ) );
|
||||
|
||||
while ( $level < count( $currentLevel ) )
|
||||
{
|
||||
$result .= '</li></ol>';
|
||||
array_pop( $currentLevel );
|
||||
}
|
||||
|
||||
if ( $level > count( $currentLevel ) )
|
||||
{
|
||||
while ( $level > count( $currentLevel ) )
|
||||
{
|
||||
if ( count( $currentLevel ) > 0 || $firstLevel )
|
||||
{
|
||||
$result .= '<ol>';
|
||||
$firstLevel = false;
|
||||
}
|
||||
array_push( $currentLevel, 0 );
|
||||
}
|
||||
$result .= '<li>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$result .= '</li><li>';
|
||||
}
|
||||
|
||||
$currentLevel[ count( $currentLevel ) - 1 ]++;
|
||||
|
||||
preg_match( '/\sid="([^"]*)"/', $match[2], $idMatches );
|
||||
$id = isset( $idMatches[1] ) ? $idMatches[1] : '';
|
||||
|
||||
$result .= sprintf(
|
||||
'<a href="#%s">%s</a>',
|
||||
urlencode( strtolower( $id ) ),
|
||||
$match[3]
|
||||
);
|
||||
}
|
||||
|
||||
while ( !empty( $currentLevel ) )
|
||||
{
|
||||
$result .= '</li></ol>';
|
||||
array_pop( $currentLevel );
|
||||
}
|
||||
|
||||
if ( substr( $result, 0, 8 ) === '<ol><ol>' )
|
||||
return substr( $result, 4, -5 );
|
||||
else
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback dla processHeaders.
|
||||
*/
|
||||
public static function processHeaders( $matches )
|
||||
{
|
||||
$level = $matches[1];
|
||||
$attrs = $matches[2];
|
||||
$content = $matches[3];
|
||||
$id_attr = 'id=';
|
||||
$id_attr_pos = strpos( $attrs, $id_attr );
|
||||
if ( $id_attr_pos === false )
|
||||
{
|
||||
$id = \Shared\Helpers\Helpers::seo( $content );
|
||||
$attrs .= sprintf( ' id="%s"', $id );
|
||||
}
|
||||
|
||||
return sprintf( '<h%d%s>%s</h%d>', $level, $attrs, $content, $level );
|
||||
}
|
||||
|
||||
/**
|
||||
* Dodaje atrybuty id do naglowkow HTML.
|
||||
*/
|
||||
public static function generateHeadersIds( $text )
|
||||
{
|
||||
$pattern = '/<h([1-6])(.*?)>(.*?)<\/h\1>/si';
|
||||
$text = preg_replace_callback( $pattern, array( __CLASS__, 'processHeaders' ), $text );
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pobiera glowne zdjecie artykulu (z entry, text lub galerii).
|
||||
*/
|
||||
public static function getImage( $article )
|
||||
{
|
||||
if ( $main_img = $article['language']['main_image'] )
|
||||
return $main_img;
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@$dom->loadHTML( mb_convert_encoding( $article['language']['entry'], 'HTML-ENTITIES', 'UTF-8' ) );
|
||||
$images = $dom->getElementsByTagName( 'img' );
|
||||
foreach ( $images as $img )
|
||||
{
|
||||
$src = $img->getAttribute( 'src' );
|
||||
if ( file_exists( substr( $src, 1, strlen( $src ) ) ) )
|
||||
return $src;
|
||||
}
|
||||
|
||||
$dom = new \DOMDocument();
|
||||
@$dom->loadHTML( mb_convert_encoding( $article['language']['text'], 'HTML-ENTITIES', 'UTF-8' ) );
|
||||
$images = $dom->getElementsByTagName( 'img' );
|
||||
foreach ( $images as $img )
|
||||
{
|
||||
$src = $img->getAttribute( 'src' );
|
||||
if ( file_exists( substr( $src, 1, strlen( $src ) ) ) )
|
||||
return $src;
|
||||
}
|
||||
|
||||
if ( $article['images'] )
|
||||
return $article['images'][0]['src'];
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
21
autoload/front/Views/Banners.php
Normal file
21
autoload/front/Views/Banners.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Banners
|
||||
{
|
||||
public static function banners($banners)
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->banners = $banners;
|
||||
return $tpl->render('banner/banners');
|
||||
}
|
||||
|
||||
public static function mainBanner($banner)
|
||||
{
|
||||
if (!\Shared\Helpers\Helpers::get_session('banner_close') && is_array($banner)) {
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->banner = $banner;
|
||||
return $tpl->render('banner/main-banner');
|
||||
}
|
||||
}
|
||||
}
|
||||
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 \Shared\Tpl\Tpl;
|
||||
$tpl -> languages = $languages;
|
||||
return $tpl -> render( 'site/languages' );
|
||||
}
|
||||
}
|
||||
22
autoload/front/Views/Menu.php
Normal file
22
autoload/front/Views/Menu.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public static function pages($pages, $level = 0, $current_page = 0)
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->pages = $pages;
|
||||
$tpl->level = $level;
|
||||
$tpl->current_page = $current_page;
|
||||
return $tpl->render('menu/pages');
|
||||
}
|
||||
|
||||
public static function menu($menu, $current_page)
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->menu = $menu;
|
||||
$tpl->current_page = $current_page;
|
||||
return $tpl->render('menu/menu');
|
||||
}
|
||||
}
|
||||
11
autoload/front/Views/Newsletter.php
Normal file
11
autoload/front/Views/Newsletter.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function render()
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl -> render( 'newsletter/newsletter' );
|
||||
}
|
||||
}
|
||||
12
autoload/front/Views/Scontainers.php
Normal file
12
autoload/front/Views/Scontainers.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function scontainer( $scontainer )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->scontainer = $scontainer;
|
||||
return $tpl->render( 'scontainers/scontainer' );
|
||||
}
|
||||
}
|
||||
66
autoload/front/Views/ShopCategory.php
Normal file
66
autoload/front/Views/ShopCategory.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopCategory
|
||||
{
|
||||
public static function categoryDescription($category): string
|
||||
{
|
||||
return \Shared\Tpl\Tpl::view('shop-category/category-description', [
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function categoryView($category, string $langId, int $currentPage = 1): string
|
||||
{
|
||||
global $settings, $page;
|
||||
|
||||
$categoryRepo = new \Domain\Category\CategoryRepository($GLOBALS['mdb']);
|
||||
|
||||
if (!$settings['infinitescroll']) {
|
||||
$results = $categoryRepo->paginatedCategoryProducts(
|
||||
(int)$category['id'],
|
||||
(int)($category['sort_type'] ?? 0),
|
||||
$langId,
|
||||
$currentPage
|
||||
);
|
||||
|
||||
$pager = '';
|
||||
if ($results['ls'] > 1) {
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->ls = $results['ls'];
|
||||
$tpl->bs = $currentPage > 0 ? $currentPage : 1;
|
||||
$tpl->page = $page;
|
||||
$tpl->link = !empty($category['language']['seo_link'])
|
||||
? $category['language']['seo_link']
|
||||
: 'k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo($category['language']['title'] ?? '');
|
||||
$pager = $tpl->render('site/pager');
|
||||
}
|
||||
|
||||
return \Shared\Tpl\Tpl::view('shop-category/category', [
|
||||
'category' => $category,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager,
|
||||
'category_description' => $currentPage <= 1,
|
||||
'category_additional_text' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$productsCount = $categoryRepo->categoryProductsCount((int)$category['id'], $langId);
|
||||
|
||||
return \Shared\Tpl\Tpl::view('shop-category/category-infinitescroll', [
|
||||
'category' => $category,
|
||||
'products_count' => $productsCount,
|
||||
'category_description' => $currentPage <= 1,
|
||||
'category_additional_text' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function categories($categories, $currentCategory = 0, $level = 0): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->level = $level;
|
||||
$tpl->current_category = $currentCategory;
|
||||
$tpl->categories = $categories;
|
||||
return $tpl->render('shop-category/categories');
|
||||
}
|
||||
}
|
||||
80
autoload/front/Views/ShopClient.php
Normal file
80
autoload/front/Views/ShopClient.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopClient
|
||||
{
|
||||
public static function addressEdit($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/address-edit');
|
||||
}
|
||||
|
||||
public static function clientAddresses($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/client-addresses');
|
||||
}
|
||||
|
||||
public static function clientMenu($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/client-menu');
|
||||
}
|
||||
|
||||
public static function clientOrders($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/client-orders');
|
||||
}
|
||||
|
||||
public static function recoverPassword(): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl->render('shop-client/recover-password');
|
||||
}
|
||||
|
||||
public static function miniLogin(): string
|
||||
{
|
||||
global $client;
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->client = $client;
|
||||
return $tpl->render('shop-client/mini-login');
|
||||
}
|
||||
|
||||
public static function loginForm($values = ''): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/login-form');
|
||||
}
|
||||
|
||||
public static function registerForm(): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl->render('shop-client/register-form');
|
||||
}
|
||||
}
|
||||
13
autoload/front/Views/ShopPaymentMethod.php
Normal file
13
autoload/front/Views/ShopPaymentMethod.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function basketPaymentMethods( $payment_methods, $payment_id )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->payment_methods = $payment_methods;
|
||||
$tpl->payment_id = $payment_id;
|
||||
return $tpl->render( 'shop-basket/basket-payments-methods' );
|
||||
}
|
||||
}
|
||||
18
autoload/front/Views/ShopProduct.php
Normal file
18
autoload/front/Views/ShopProduct.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopProduct
|
||||
{
|
||||
public static function productUrl( $product )
|
||||
{
|
||||
if ( $product['language']['seo_link'] )
|
||||
{
|
||||
return '/' . $product['language']['seo_link'];
|
||||
}
|
||||
|
||||
if ( $product['parent_id'] )
|
||||
return '/p-' . $product['parent_id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
|
||||
|
||||
return '/p-' . $product['id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
|
||||
}
|
||||
}
|
||||
10
autoload/front/Views/ShopSearch.php
Normal file
10
autoload/front/Views/ShopSearch.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopSearch
|
||||
{
|
||||
public static function simpleForm()
|
||||
{
|
||||
return \Shared\Tpl\Tpl::view( 'shop-search/simple-form' );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user