first commit
This commit is contained in:
BIN
autoload/.DS_Store
vendored
Normal file
BIN
autoload/.DS_Store
vendored
Normal file
Binary file not shown.
79
autoload/admin/class.Site.php
Normal file
79
autoload/admin/class.Site.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
namespace admin;
|
||||
|
||||
class Site
|
||||
{
|
||||
public static function special_actions()
|
||||
{
|
||||
$sa = \S::get( 's-action' );
|
||||
|
||||
switch ( $sa )
|
||||
{
|
||||
case 'user-logon':
|
||||
|
||||
$result = \admin\factory\Users::logon( \S::get( 'login' ), \S::get( 'password' ) );
|
||||
|
||||
if ( $result == 1 )
|
||||
\S::set_session( 'user', \admin\factory\Users::details( \S::get( 'login' ) ) );
|
||||
else
|
||||
{
|
||||
if ( $result == -1 )
|
||||
\S::alert( 'Z powodu nieudanych 5 prób logowania Twoje konto zostało zablokowane.' );
|
||||
else
|
||||
\S::alert( 'Podane hasło jest nieprawidłowe, lub brak użytkownika o podanym loginie.' );
|
||||
}
|
||||
header( 'Location: /admin/dashboard/main_view/' );
|
||||
exit;
|
||||
break;
|
||||
|
||||
case 'user-logout':
|
||||
session_destroy();
|
||||
header( 'Location: /admin/' );
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static function route()
|
||||
{
|
||||
$_SESSION['admin'] = true;
|
||||
|
||||
if ( \S::get( 'p' ) )
|
||||
\S::set_session( 'p' , \S::get( 'p' ) );
|
||||
|
||||
$page = \S::get_session( 'p' );
|
||||
|
||||
$class = '\admin\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$action = \S::get( 'action' );
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $action ) )
|
||||
return call_user_func_array( array( $class, $action ), array() );
|
||||
else
|
||||
{
|
||||
\S::alert( 'Nieprawidłowy adres url.' );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static public function update()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $results = $mdb -> select( 'pp_updates', [ 'name' ], [ 'done' => 0 ] ) )
|
||||
{
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$class = '\admin\factory\Update';
|
||||
$method = $row['name'];
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $method ) )
|
||||
call_user_func_array( array( $class, $method ), array() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
autoload/admin/controls/class.Archive.php
Normal file
25
autoload/admin/controls/class.Archive.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
class Archive {
|
||||
static public function products_list() {
|
||||
|
||||
$current_page = \S::get_session( 'archive_products_list_current_page' );
|
||||
|
||||
if ( !$current_page ) {
|
||||
$current_page = 1;
|
||||
\S::set_session( 'archive_products_list_current_page', $current_page );
|
||||
}
|
||||
|
||||
$query = \S::get_session( 'archive_products_list_query' );
|
||||
if ( $query ) {
|
||||
$query_array = [];
|
||||
parse_str( $query, $query_array );
|
||||
}
|
||||
|
||||
return \Tpl::view( 'archive/products-list', [
|
||||
'current_page' => $current_page,
|
||||
'query_array' => $query_array,
|
||||
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product() / 10 )
|
||||
] );
|
||||
}
|
||||
}
|
||||
62
autoload/admin/controls/class.Articles.php
Normal file
62
autoload/admin/controls/class.Articles.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Articles
|
||||
{
|
||||
public static function gallery_order_save()
|
||||
{
|
||||
if ( \admin\factory\Articles::gallery_order_save( \S::get( 'article_id' ), \S::get( 'order' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.' ] );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function browse_list()
|
||||
{
|
||||
return \admin\view\Articles::browse_list();
|
||||
}
|
||||
|
||||
public static function article_delete()
|
||||
{
|
||||
if ( \admin\factory\Articles::articles_set_archive( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Artykuł został przeniesiony do archiwum.' );
|
||||
header( 'Location: /admin/articles/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function article_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania artykułu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Articles::article_save(
|
||||
$values['id'], $values['title'], $values['main_image'], $values['entry'], $values['text'], $values['table_of_contents'], $values['status'], $values['show_title'], $values['show_table_of_contents'], $values['show_date_add'], $values['date_add'], $values['show_date_modify'], $values['date_modify'], $values['seo_link'], $values['meta_title'],
|
||||
$values['meta_description'], $values['meta_keywords'], $values['layout_id'], $values['pages'], $values['noindex'], $values['repeat_entry'], $values['copy_from'], $values['social_icons'], $values['block_direct_access']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function article_edit()
|
||||
{
|
||||
\admin\factory\Articles::delete_nonassigned_images();
|
||||
\admin\factory\Articles::delete_nonassigned_files();
|
||||
|
||||
return \admin\view\Articles::article_edit(
|
||||
\admin\factory\Articles::article_details(
|
||||
\S::get( 'id' )
|
||||
),
|
||||
\admin\factory\Pages::menus_list(),
|
||||
\admin\factory\Languages::languages_list(),
|
||||
\admin\factory\Layouts::layouts_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\Articles::articles_list();
|
||||
}
|
||||
}
|
||||
?>
|
||||
26
autoload/admin/controls/class.ArticlesArchive.php
Normal file
26
autoload/admin/controls/class.ArticlesArchive.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class ArticlesArchive
|
||||
{
|
||||
public static function article_restore()
|
||||
{
|
||||
if ( \admin\factory\ArticlesArchive::article_restore( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Artykuł został przywrócony.' );
|
||||
header( 'Location: /admin/articles_archive/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function article_delete()
|
||||
{
|
||||
if ( \admin\factory\ArticlesArchive::article_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Artykuł został usunięty.' );
|
||||
header( 'Location: /admin/articles_archive/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\ArticlesArchive::articles_list();
|
||||
}
|
||||
}
|
||||
43
autoload/admin/controls/class.Banners.php
Normal file
43
autoload/admin/controls/class.Banners.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace admin\controls;
|
||||
|
||||
class Banners
|
||||
{
|
||||
public static function banner_delete()
|
||||
{
|
||||
if ( \admin\factory\Banners::banner_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Baner został usunięty.' );
|
||||
header( 'Location: /admin/banners/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function banner_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania baneru wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $banner_id = \admin\factory\Banners::banner_save( $values['id'], $values['name'], $values['status'], $values['date_start'], $values['date_end'],
|
||||
$values['home_page'], $values['src'], $values['url'], $values['html'], $values['text'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Baner został zapisany.', 'id' => $banner_id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function banner_edit()
|
||||
{
|
||||
return \admin\view\Banners::banner_edit(
|
||||
\admin\factory\Banners::banner_details(
|
||||
\S::get( 'id' )
|
||||
),
|
||||
\admin\factory\Languages::languages_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\Banners::banners_list();
|
||||
}
|
||||
}
|
||||
?>
|
||||
20
autoload/admin/controls/class.Baselinker.php
Normal file
20
autoload/admin/controls/class.Baselinker.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Baselinker {
|
||||
|
||||
// widok wiązania produktów
|
||||
static public function bundling_products() {
|
||||
return \Tpl::view( 'baselinker/bundling-products', [
|
||||
'products' => \admin\factory\ShopProduct::products_list_for_baselinker(),
|
||||
'baselinker_products' => \admin\factory\Baselinker::products_list()
|
||||
] );
|
||||
}
|
||||
|
||||
// zapis wiązania produktów
|
||||
static public function bundling_products_save() {
|
||||
\admin\factory\Baselinker::bundling_products_save( $_POST );
|
||||
header( 'Location: /admin/baselinker/bundling_products/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
18
autoload/admin/controls/class.Dashboard.php
Normal file
18
autoload/admin/controls/class.Dashboard.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
class Dashboard
|
||||
{
|
||||
static public function main_view()
|
||||
{
|
||||
return \Tpl::view( 'dashboard/main-view', [
|
||||
'last_orders' => \shop\Dashboard::last_orders(),
|
||||
'order_statuses' => \shop\Order::order_statuses(),
|
||||
'sales' => \shop\Dashboard::last_24_months_sales(),
|
||||
'best_sales_products' => \shop\Dashboard::best_sales_products(),
|
||||
'most_view_products' => \shop\Dashboard::most_view_products(),
|
||||
'sales_grid' => \shop\Dashboard::sales_grid(),
|
||||
'summary_sales' => \shop\Dashboard::summary_sales(),
|
||||
'summary_orders' => \shop\Dashboard::summary_orders(),
|
||||
] );
|
||||
}
|
||||
}
|
||||
39
autoload/admin/controls/class.Dictionaries.php
Normal file
39
autoload/admin/controls/class.Dictionaries.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Dictionaries {
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'dictionaries/units-list' );
|
||||
}
|
||||
|
||||
public static function unit_edit()
|
||||
{
|
||||
return \Tpl::view( 'dictionaries/unit-edit', [
|
||||
'unit' => \admin\factory\Dictionaries::unit_details( \S::get( 'id' )),
|
||||
'languages' => \admin\factory\Languages::languages_list(),
|
||||
] );
|
||||
}
|
||||
|
||||
static public function unit_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania jednostki miary wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Dictionaries::unit_save( $values['id'], $values['text']) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Jednostka miary została zapisana.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
static public function unit_delete()
|
||||
{
|
||||
if ( \admin\factory\Dictionaries::unit_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Jesdnostka miary została usunięta.' );
|
||||
|
||||
header( 'Location: /admin/dictionaries/view_list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
11
autoload/admin/controls/class.Filemanager.php
Normal file
11
autoload/admin/controls/class.Filemanager.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Filemanager
|
||||
{
|
||||
public function draw()
|
||||
{
|
||||
return \admin\view\FileManager::filemanager();
|
||||
}
|
||||
}
|
||||
?>
|
||||
846
autoload/admin/controls/class.Integrations.php
Normal file
846
autoload/admin/controls/class.Integrations.php
Normal file
@@ -0,0 +1,846 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class Integrations {
|
||||
|
||||
// apilo_create_product
|
||||
static public function apilo_create_product()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$product = new \shop\Product( $product_id );
|
||||
|
||||
$methodParams = [
|
||||
"sku" => $product -> sku,
|
||||
"ean" => $product -> ean,
|
||||
"name" => $product -> language['name'],
|
||||
"tax" => (int) $product -> vat,
|
||||
'status' => 1,
|
||||
"quantity" => (int) $product -> quantity,
|
||||
"priceWithTax" => $product -> price_brutto,
|
||||
'description' => $product -> language['description'] . '<br>' . $product -> language['short_description'],
|
||||
'shortDescription' => '',
|
||||
'images' => []
|
||||
];
|
||||
|
||||
foreach ($product->images as $image) {
|
||||
$methodParams["images"][] = "https://" . $_SERVER['HTTP_HOST'] . $image['src'];
|
||||
}
|
||||
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/api/warehouse/product/" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [ $methodParams ] ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData['products'] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => reset( $responseData['products'] ), 'apilo_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
|
||||
}
|
||||
|
||||
\S::alert( 'Produkt został dodany do magazynu APILO.' );
|
||||
}
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker_create_product
|
||||
static public function baselinker_create_product()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$product = \shop\Product::getFromCache( $product_id, 'pl' );
|
||||
|
||||
$methodParams = [
|
||||
"storage_id" => \admin\factory\Integrations::baselinker_settings('storage_id'),
|
||||
"ean" => $product->ean,
|
||||
"sku" => $product->sku,
|
||||
"name" => $product->language['name'],
|
||||
"quantity" => "0",
|
||||
"price_brutto" => $product->price_brutto,
|
||||
"tax_rate" => $product->vat,
|
||||
"description" => $product->language['short_description'],
|
||||
"description_extra1" => $product->language['description'],
|
||||
"images" => []
|
||||
];
|
||||
|
||||
foreach ($product->images as $image) {
|
||||
$methodParams["images"][] = "url:https://" . $_SERVER['HTTP_HOST'] . $image['src'];
|
||||
}
|
||||
|
||||
$methodParams = json_encode( $methodParams, JSON_UNESCAPED_SLASHES );
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "addProduct",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
if ( $response['product_id'] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $response['product_id'], 'baselinker_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
|
||||
}
|
||||
|
||||
\S::alert( 'Produkt został dodany do magazynu Baselinker.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Podczas dodawania produktu wystąpił błąd.' );
|
||||
}
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker pobierz listę magazynów
|
||||
static public function baselinker_get_storages_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "getStoragesList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
\admin\factory\Integrations::baselinker_settings_save( 'storages_list', $response['storages'] );
|
||||
\S::alert( 'Lista magazynów została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/baselinker_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker_get_order_status_list
|
||||
static public function baselinker_get_order_status_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "getOrderStatusList",
|
||||
"parameters" => []
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
\admin\factory\Integrations::baselinker_settings_save( 'order_status_list', $response['statuses'] );
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/baselinker_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_sellasist_carriers_list
|
||||
static public function get_sellasist_shipments_list()
|
||||
{
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/shipments" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
else {
|
||||
if ( $responseData ) {
|
||||
\admin\factory\Integrations::sellasist_settings_save( 'shipments_methods', $responseData );
|
||||
\S::alert( 'Lista przewoźników została pobrana.' );
|
||||
} else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/sellasist_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_sellasist_payment_types_list
|
||||
static public function get_sellasist_payment_types_list()
|
||||
{
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/payments" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
else {
|
||||
if ( $responseData ) {
|
||||
\admin\factory\Integrations::sellasist_settings_save( 'payment_types_list', $responseData );
|
||||
\S::alert( 'Lista metod płatności została pobrana.' );
|
||||
} else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/sellasist_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function get_sellasist_status_types_list()
|
||||
{
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/statuses" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
else {
|
||||
if ( $responseData ) {
|
||||
\admin\factory\Integrations::sellasist_settings_save( 'status_types_list', $responseData );
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
} else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/sellasist_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_platform_list
|
||||
static public function get_platform_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/platform/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'platform-list', $responseData );
|
||||
\S::alert( 'Lista platform została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_status_types_list
|
||||
static public function get_status_types_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/status/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'status-types-list', $responseData );
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_carrier_account_list
|
||||
static public function get_carrier_account_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/carrier-account/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'carrier-account-list', $responseData );
|
||||
\S::alert( 'Lista kont przewoźników została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_payment_types_list
|
||||
static public function get_payment_types_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/payment/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'payment-types-list', $responseData );
|
||||
\S::alert( 'Lista metod płatności została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// settings for the sellasist integration
|
||||
static public function sellasist_settings()
|
||||
{
|
||||
return \Tpl::view( 'integrations/sellasist-settings', [
|
||||
'settings' => \admin\factory\Integrations::sellasist_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// settings for the Baselinker integration
|
||||
static public function baselinker_settings()
|
||||
{
|
||||
return \Tpl::view( 'integrations/baselinker-settings', [
|
||||
'settings' => \admin\factory\Integrations::baselinker_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// settings for shoppro
|
||||
static public function shoppro_settings()
|
||||
{
|
||||
return \Tpl::view( 'integrations/shoppro-settings', [
|
||||
'settings' => \admin\factory\Integrations::shoppro_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// Settings for the APILO plugin
|
||||
static public function apilo_settings()
|
||||
{
|
||||
|
||||
return \Tpl::view( 'integrations/apilo-settings', [
|
||||
'settings' => \admin\factory\Integrations::apilo_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// save settings for the shoppro integration
|
||||
static public function shoppro_settings_save()
|
||||
{
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::shoppro_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// save settings for the sellasist integration
|
||||
static public function sellasist_settings_save()
|
||||
{
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::sellasist_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// save settings for the Baselinker integration
|
||||
static public function baselinker_settings_save()
|
||||
{
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::baselinker_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Save settings for the APILO plugin
|
||||
static public function apilo_settings_save() {
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Authorization in apilo.com
|
||||
static public function apilo_authorization() {
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$settings = \admin\factory\Integrations::apilo_settings();
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_authorization( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sellasist product search by sku
|
||||
static public function sellasist_product_search() {
|
||||
global $mdb, $settings;
|
||||
|
||||
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$url = "https://projectpro.sellasist.pl/api/v1/products";
|
||||
$params['symbol '] = $sku;
|
||||
$url .= '?' . http_build_query( $params );
|
||||
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
echo 'Błąd cURL: ' . curl_error( $ch );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData['error'] )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_data = array();
|
||||
$return_data['status'] = 'SUCCESS';
|
||||
$return_data['products'] = $responseData;
|
||||
echo json_encode( $return_data );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// apilo product search by sku
|
||||
static public function apilo_product_search() {
|
||||
global $mdb, $settings;
|
||||
|
||||
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/warehouse/product/";
|
||||
$params['sku'] = $sku;
|
||||
$url .= '?' . http_build_query( $params );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) ) {
|
||||
echo 'Błąd cURL: ' . curl_error( $ch );
|
||||
} else {
|
||||
if ( $responseData && isset( $responseData['products'] ) ) {
|
||||
$responseData['status'] = 'SUCCESS';
|
||||
echo json_encode( $responseData );
|
||||
exit;
|
||||
} else {
|
||||
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// wyszukiwanie produktu w bazie baselinkera
|
||||
static public function baselinker_product_search()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1",
|
||||
"filter_sku": "' . $sku . '"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "getProductsList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sellasist_product_select_delete
|
||||
static public function sellasist_product_select_delete()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::sellasist_product_select_delete( \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// apilo product select delete
|
||||
static public function apilo_product_select_delete()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_product_select_delete( \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker delete product linking
|
||||
static public function baselinker_product_select_delete()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::baselinker_product_select_delete( \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sellasist_product_select_save
|
||||
static public function sellasist_product_select_save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::sellasist_product_select_save( \S::get( 'product_id' ), \S::get( 'sellasist_product_id' ), \S::get( 'sellasist_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// apilo product select save
|
||||
static public function apilo_product_select_save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_product_select_save( \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function baselinker_product_select_save() {
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::baselinker_product_select_save( \S::get( 'product_id' ), \S::get( 'baselinker_product_id' ), \S::get( 'baselinker_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// shoppro_product_import
|
||||
static public function shoppro_product_import()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$shoppro_settings = \admin\factory\Integrations::shoppro_settings();
|
||||
|
||||
$mdb2 = new \medoo( [
|
||||
'database_type' => 'mysql',
|
||||
'database_name' => $shoppro_settings[ 'db_name' ],
|
||||
'server' => $shoppro_settings[ 'db_host' ],
|
||||
'username' => $shoppro_settings[ 'db_user' ],
|
||||
'password' => $shoppro_settings[ 'db_password' ],
|
||||
'charset' => 'utf8'
|
||||
] );
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
|
||||
$product = $mdb2 -> get( 'pp_shop_products', '*', [ 'id' => $product_id ] );
|
||||
if ( $product )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_products', [
|
||||
'price_netto' => $product[ 'price_netto' ],
|
||||
'price_brutto' => $product[ 'price_brutto' ],
|
||||
'vat' => $product[ 'vat' ],
|
||||
'stock_0_buy' => $product[ 'stock_0_buy' ],
|
||||
'quantity' => $product[ 'quantity' ],
|
||||
'wp' => $product[ 'wp' ],
|
||||
'sku' => $product[ 'sku' ],
|
||||
'ean' => $product[ 'ean' ],
|
||||
'custom_label_0' => $product[ 'custom_label_0' ],
|
||||
'custom_label_1' => $product[ 'custom_label_1' ],
|
||||
'custom_label_2' => $product[ 'custom_label_2' ],
|
||||
'custom_label_3' => $product[ 'custom_label_3' ],
|
||||
'custom_label_4' => $product[ 'custom_label_4' ],
|
||||
'additional_message' => $product[ 'additional_message' ],
|
||||
'additional_message_text' => $product[ 'additional_message_text' ],
|
||||
'additional_message_required' => $product[ 'additional_message_required' ],
|
||||
'weight' => $product[ 'weight' ]
|
||||
] );
|
||||
|
||||
$new_product_id = $mdb -> id();
|
||||
if ( $new_product_id )
|
||||
{
|
||||
$languages = $mdb2 -> select( 'pp_shop_products_langs', '*', [ 'product_id' => $product_id ] );
|
||||
if ( is_array( $languages ) )
|
||||
{
|
||||
foreach ( $languages as $language )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_products_langs', [
|
||||
'product_id' => $new_product_id,
|
||||
'lang_id' => $language['lang_id'],
|
||||
'name' => $language['name'],
|
||||
'short_description' => $language['short_description'],
|
||||
'description' => $language['description'],
|
||||
'tab_name_1' => $language['tab_name_1'],
|
||||
'tab_description_1' => $language['tab_description_1'],
|
||||
'tab_name_2' => $language['tab_name_2'],
|
||||
'tab_description_2' => $language['tab_description_2'],
|
||||
'meta_title' => $language['meta_title'],
|
||||
'meta_description' => $language['meta_description'],
|
||||
'meta_keywords' => $language['meta_keywords'],
|
||||
'seo_link' => $language['seo_link'],
|
||||
'copy_from' => $language['copy_from'],
|
||||
'warehouse_message_zero' => $language['warehouse_message_zero'],
|
||||
'warehouse_message_nonzero' => $language['warehouse_message_nonzero'],
|
||||
'canonical' => $language['canonical'],
|
||||
'xml_name' => $language['xml_name']
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
$images = $mdb2 -> select( 'pp_shop_products_images', '*', [ 'product_id' => $product_id ] );
|
||||
if ( is_array( $images ) )
|
||||
{
|
||||
foreach ( $images as $image )
|
||||
{
|
||||
$image_url = 'https://' . $shoppro_settings['domain'] . $image['src'];
|
||||
|
||||
// pobierz zdjęcie za pomocą curl
|
||||
$ch = curl_init( $image_url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
|
||||
$image_data = curl_exec( $ch );
|
||||
$image_data;
|
||||
curl_close( $ch );
|
||||
|
||||
// ścieżdka do nowego zdjęcia to "/upload/product_images/product_[product_id]/[nazwa_zdjęcia]
|
||||
$image_name = basename( $image_url );
|
||||
$image_path = '../upload/product_images/product_' . $new_product_id . '/' . $image_name;
|
||||
|
||||
// utwórz katalog dla zdjęć produktu jeśli nie istnieje
|
||||
if ( !file_exists( '../upload/product_images/product_' . $new_product_id ) )
|
||||
mkdir( '../upload/product_images/product_' . $new_product_id, 0777, true );
|
||||
|
||||
// zapisz zdjęcie
|
||||
file_put_contents( $image_path, $image_data );
|
||||
|
||||
// zapisz zdjęcie w bazie danych
|
||||
$mdb -> insert( 'pp_shop_products_images', [
|
||||
'product_id' => $new_product_id,
|
||||
'src' => '/upload/product_images/product_' . $new_product_id . '/' . $image_name,
|
||||
'o' => $image['o']
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
\S::alert( 'Produkt został zaimportowany.' );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
\S::alert( 'Podczas importowania produktu wystąpił błąd.' );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
83
autoload/admin/controls/class.Languages.php
Normal file
83
autoload/admin/controls/class.Languages.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function language_delete()
|
||||
{
|
||||
if ( \admin\factory\Languages::language_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Język został usunięty.' );
|
||||
header( 'Location: /admin/languages/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function language_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania języka wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( \admin\factory\Languages::language_save(
|
||||
$values['id'], $values['name'], $values['status'],
|
||||
$values['start'], $values['o'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Język został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function language_edit()
|
||||
{
|
||||
return \admin\view\Languages::language_edit(
|
||||
\admin\factory\Languages::language_details(
|
||||
\S::get( 'id' )
|
||||
), \admin\factory\Languages::max_order()
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\Languages::languages_list();
|
||||
}
|
||||
|
||||
public static function translation_delete()
|
||||
{
|
||||
if ( \admin\factory\Languages::translation_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Tłumaczenie zostało usunięte.' );
|
||||
header( 'Location: /admin/languages/translation_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function translation_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania tłumaczenia wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
$languages_list = \admin\factory\Languages::languages_list();
|
||||
if ( is_array( $languages_list ) and !empty( $languages_list ) ) foreach ( $languages_list as $language )
|
||||
{
|
||||
\S::delete_session( 'lang-' . $language['id'] );
|
||||
$languages[ $language['id'] ] = $values[ $language['id'] ];
|
||||
}
|
||||
|
||||
if ( $id = \admin\factory\Languages::translation_save( $values['id'], $values['text'], $languages ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Tłumaczenie zostało zapisane.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function translation_edit()
|
||||
{
|
||||
return \admin\view\Languages::translation_edit(
|
||||
\admin\factory\Languages::translation_details( \S::get( 'id' ) ),
|
||||
\admin\factory\Languages::languages_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function translation_list()
|
||||
{
|
||||
return \admin\view\Languages::translations_list();
|
||||
}
|
||||
}
|
||||
?>
|
||||
43
autoload/admin/controls/class.Layouts.php
Normal file
43
autoload/admin/controls/class.Layouts.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Layouts
|
||||
{
|
||||
public static function layout_delete()
|
||||
{
|
||||
if ( \admin\factory\Layouts::layout_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Szablon został usunięty.' );
|
||||
header( 'Location: /admin/layouts/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function layout_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania szablonu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Layouts::layout_save( $values['id'], $values['name'], $values['status'], $values['pages'], $values['html'], $values['css'], $values['js'], $values['m_html'],
|
||||
$values['m_css'], $values['m_js'], $values['categories'], $values['categories_default'] )
|
||||
)
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Szablon został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function layout_edit()
|
||||
{
|
||||
return \Tpl::view( 'layouts/layout-edit', [
|
||||
'layout' => \admin\factory\Layouts::layout_details( \S::get( 'id' ) ),
|
||||
'menus' => \admin\factory\Layouts::menus_list(),
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'dlang' => \front\factory\Languages::default_language()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\Layouts::layouts_list();
|
||||
}
|
||||
}
|
||||
?>
|
||||
92
autoload/admin/controls/class.Newsletter.php
Normal file
92
autoload/admin/controls/class.Newsletter.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function emails_list()
|
||||
{
|
||||
return \admin\view\Newsletter::emails_list();
|
||||
}
|
||||
|
||||
public static function send()
|
||||
{
|
||||
if ( \admin\factory\Newsletter::send( \S::get( 'dates' ), \S::get('template')) )
|
||||
\S::alert( 'Newsletter został dodany do kolejki wysyłania.' );
|
||||
|
||||
header( 'Location: /admin/newsletter/prepare/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function prepare()
|
||||
{
|
||||
return \admin\view\Newsletter::prepare(
|
||||
\admin\factory\Newsletter::templates_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function settings_save()
|
||||
{
|
||||
$settings = \admin\factory\Settings::settings_details();
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
\admin\factory\Settings::settings_update( 'newsletter_footer', $values['newsletter_footer'] );
|
||||
\admin\factory\Settings::settings_update( 'newsletter_header', $values['newsletter_header'] );
|
||||
|
||||
\S::alert( 'Ustawienia zostały zapisane.' );
|
||||
|
||||
echo json_encode( [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function settings()
|
||||
{
|
||||
return \admin\view\Newsletter::settings(
|
||||
\admin\factory\Settings::settings_details()
|
||||
);
|
||||
}
|
||||
|
||||
public static function email_templates_user()
|
||||
{
|
||||
return \admin\view\Newsletter::email_templates_user();
|
||||
}
|
||||
|
||||
public static function email_templates_admin()
|
||||
{
|
||||
return \admin\view\Newsletter::email_templates_admin();
|
||||
}
|
||||
|
||||
public static function email_template_delete()
|
||||
{
|
||||
$is_admin = \admin\factory\Newsletter::is_admin_template( \S::get( 'id' ) );
|
||||
|
||||
if ( !$is_admin and \admin\factory\Newsletter::newsletter_template_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Szablon newslettera został usunięty.' );
|
||||
|
||||
if ( $is_admin )
|
||||
header( 'Location: /admin/newsletter/email_templates_admin/' );
|
||||
else
|
||||
header( 'Location: /admin/newsletter/email_templates_user/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function email_template_edit()
|
||||
{
|
||||
return \admin\view\Newsletter::email_template_edit(
|
||||
\admin\factory\Newsletter::email_template_detalis(
|
||||
\S::get( 'id' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function template_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Newsletter::template_save( $values['id'], $values['name'], $values['text'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Zmiany zostały zapisane.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
100
autoload/admin/controls/class.Pages.php
Normal file
100
autoload/admin/controls/class.Pages.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class Pages
|
||||
{
|
||||
public static function pages_url_browser()
|
||||
{
|
||||
echo \Tpl::view( 'pages/pages-browse-list', [
|
||||
'menus' => \admin\factory\Pages::menus_list(),
|
||||
'modal' => \S::get( 'modal' )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function browse_list()
|
||||
{
|
||||
return \admin\view\Pages::browse_list(
|
||||
\admin\factory\Pages::menus_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function menu_delete()
|
||||
{
|
||||
if ( \admin\factory\Pages::menu_delete( \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Menu zostało usunięte.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania menu wystąpił błąd. Aby usunąć menu nie może ono posiadać przypiętych stron.' );
|
||||
header( 'Location: /admin/pages/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function page_delete()
|
||||
{
|
||||
if ( \admin\factory\Pages::page_delete( \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Strona została usunięta.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania strony wystąpił błąd. Aby usunąć stronę nie może ona posiadać przypiętych podstron.' );
|
||||
header( 'Location: /admin/pages/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function page_articles()
|
||||
{
|
||||
return \admin\view\Pages::page_articles( \S::get( 'id' ), \admin\factory\Pages::page_articles( \S::get( 'id' ) ) );
|
||||
}
|
||||
|
||||
public static function page_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania strony wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Pages::page_save(
|
||||
$values['id'], $values['title'], $values['seo_link'], $values['meta_title'], $values['meta_description'], $values['meta_keywords'], $values['menu_id'], $values['parent_id'], $values['page_type'],
|
||||
$values['sort_type'], $values['layout_id'], $values['articles_limit'], $values['show_title'], $values['status'], $values['link'], $values['noindex'], $values['start'], $values['page_title'],
|
||||
$values['canonical'], $values['category_id']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Strona została zapisana.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function page_edit()
|
||||
{
|
||||
return \Tpl::view( 'pages/page-edit', [
|
||||
'page' => \admin\factory\Pages::page_details( \S::get( 'id' ) ),
|
||||
'parent_id' => \S::get( 'pid' ),
|
||||
'menu_id' => \S::get( 'menu_id' ),
|
||||
'menus' => \admin\factory\Pages::menu_lists(),
|
||||
'layouts' => \admin\factory\Layouts::layouts_list(),
|
||||
'languages' => \admin\factory\Languages::languages_list()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function menu_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania menu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( \admin\factory\Pages::menu_save( $values['id'], $values['name'], $values['status'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Menu zostało zapisane.' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function menu_edit()
|
||||
{
|
||||
return \admin\view\Pages::menu_edit(
|
||||
\admin\factory\Pages::menu_details( \S::get( 'id' ) )
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'pages/pages-list', [
|
||||
'menus' => \admin\factory\Pages::menus_list()
|
||||
] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
40
autoload/admin/controls/class.Scontainers.php
Normal file
40
autoload/admin/controls/class.Scontainers.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function container_delete()
|
||||
{
|
||||
if ( \admin\factory\Scontainers::container_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Kontener został usunięty.' );
|
||||
header( 'Location: /admin/scontainers/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function container_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kontenera wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\Scontainers::container_save( $values['id'], $values['title'], $values['text'], $values['status'], $values['show_title'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Kontener został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function container_edit()
|
||||
{
|
||||
return \admin\view\Scontainers::container_edit(
|
||||
\admin\factory\Scontainers::container_details(
|
||||
\S::get( 'id' )
|
||||
),
|
||||
\admin\factory\Languages::languages_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\Scontainers::containers_list();
|
||||
}
|
||||
}
|
||||
60
autoload/admin/controls/class.Settings.php
Normal file
60
autoload/admin/controls/class.Settings.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public static function settings_save()
|
||||
{
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
$settings = \admin\factory\Settings::settings_details( true );
|
||||
|
||||
$response = \admin\factory\Settings::settings_save(
|
||||
$values['firm_name'], $values['firm_adress'], $values['additional_info'], $values['contact_form'], $values['contact_email'], $values['email_host'],
|
||||
$values['email_port'], $values['email_login'], $values['email_password'], $values['google_maps'], $values['facebook_link'], $values['statistic_code'], $values['htaccess'],
|
||||
$values['robots'], $values['shop_bank_account_info'], $values['update'], $values['boot_animation'], $settings['newsletter_header'], $settings['newsletter_footer'], $values['hotpay_api']
|
||||
);
|
||||
|
||||
\admin\factory\Settings::settings_update( 'devel', $values['devel'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'ssl', $values['ssl'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'htaccess_cache', $values['htaccess_cache'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'free_delivery', $values['free_delivery'] );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_sandbox', $values['przelewy24_sandbox'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_merchant_id', $values['przelewy24_merchant_id'] );
|
||||
\admin\factory\Settings::settings_update( 'przelewy24_crc_key', $values['przelewy24_crc_key'] );
|
||||
\admin\factory\Settings::settings_update( 'update_key', $values['update_key'] );
|
||||
\admin\factory\Settings::settings_update( 'tpay_id', $values['tpay_id'] );
|
||||
\admin\factory\Settings::settings_update( 'tpay_sandbox', $values['tpay_sandbox'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'tpay_security_code', $values['tpay_security_code'] );
|
||||
\admin\factory\Settings::settings_update( 'piksel', $values['piksel'] );
|
||||
\admin\factory\Settings::settings_update( 'generate_webp', $values['generate_webp'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'lazy_loading', $values['lazy_loading'] == 'on' ? 1 : 0 );
|
||||
\admin\factory\Settings::settings_update( 'ekomi_survey', $values['ekomi_survey'] );
|
||||
\admin\factory\Settings::settings_update( 'google_tag_manager_id', $values['google_tag_manager_id'] );
|
||||
\admin\factory\Settings::settings_update( 'infinitescroll', $values['infinitescroll'] == 'on' ? 1 : 0 );
|
||||
// own_gtm_js
|
||||
\admin\factory\Settings::settings_update( 'own_gtm_js', $values['own_gtm_js'] );
|
||||
// own_gtm_html
|
||||
\admin\factory\Settings::settings_update( 'own_gtm_html', $values['own_gtm_html'] );
|
||||
|
||||
foreach ( $values[ 'warehouse_message_zero'] as $key => $val )
|
||||
\admin\factory\Settings::settings_update( 'warehouse_message_zero_' . $key, $val );
|
||||
|
||||
foreach ( $values[ 'warehouse_message_nonzero'] as $key => $val )
|
||||
\admin\factory\Settings::settings_update( 'warehouse_message_nonzero_' . $key, $val );
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::htacces();
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function view()
|
||||
{
|
||||
return \Tpl::view( 'settings/settings', [
|
||||
'languages' => \admin\factory\Languages::languages_list(),
|
||||
'settings' => \admin\factory\Settings::settings_details()
|
||||
] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
71
autoload/admin/controls/class.ShopAttribute.php
Normal file
71
autoload/admin/controls/class.ShopAttribute.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopAttribute
|
||||
{
|
||||
static public function attribute_value_tpl()
|
||||
{
|
||||
$html = \Tpl::view( 'shop-attribute/_partials/value', [
|
||||
'i' => \S::get( 'i' ),
|
||||
'value' => \S::get( 'value' ),
|
||||
'languages' => \S::get( 'languages' ),
|
||||
'attribute' => \S::get( 'attribute' ),
|
||||
] );
|
||||
echo $html;
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function values_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania wartości atrybutu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
;
|
||||
if ( $id = \admin\factory\ShopAttribute::values_save( (int) \S::get( 'attribute_id' ), $values['name'], $values['value'], $values['ids'], $values['default_value'], $values['impact_on_the_price'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Wartości atrybutu zostały zapisane.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function values_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-attribute/values-edit', [
|
||||
'attribute' => \admin\factory\ShopAttribute::attribute_details( (int) \S::get( 'attribute-id' ) ),
|
||||
'values' => \admin\factory\ShopAttribute::get_attribute_values( (int) \S::get( 'attribute-id' ) ),
|
||||
'languages' => \admin\factory\Languages::languages_list()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function delete_attribute()
|
||||
{
|
||||
if ( \admin\factory\ShopAttribute::delete_attribute( (int) \S::get( 'id' ) ) )
|
||||
\S::alert( 'Atrybut został usunięty.' );
|
||||
|
||||
header( 'Location: /admin/shop_attribute/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function attribute_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania atrybutu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopAttribute::attribute_save( (int) $values['id'], $values['name'], $values['status'] == 'on' ? 1 : 0, (int) $values['type'], (int) $values['o'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Atrybut został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function attribute_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-attribute/attribute-edit', [
|
||||
'attribute' => \admin\factory\ShopAttribute::attribute_details( (int) \S::get( 'id' ) ),
|
||||
'languages' => \admin\factory\Languages::languages_list()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-attribute/attributes-list' );
|
||||
}
|
||||
}
|
||||
66
autoload/admin/controls/class.ShopCategory.php
Normal file
66
autoload/admin/controls/class.ShopCategory.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopCategory
|
||||
{
|
||||
public static function category_products()
|
||||
{
|
||||
return \Tpl::view( 'shop-category/category-products', [
|
||||
'category_id' => \S::get( 'id' ),
|
||||
'products' => \admin\factory\ShopCategory::category_products( (int)\S::get( 'id' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function category_url_browser() {
|
||||
echo \Tpl::view( 'shop-category/category-browse-list', [
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'level' => 0,
|
||||
'dlang' => \front\factory\Languages::default_language()
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function category_delete()
|
||||
{
|
||||
if ( \admin\factory\ShopCategory::category_delete( \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Kategoria została usunięta.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania kategorii wystąpił błąd. Aby usunąć kategorię nie może ona posiadać przypiętych podkategorii.' );
|
||||
header( 'Location: /admin/shop_category/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kategorii wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopCategory::save(
|
||||
$values['id'], $values['title'], $values['text'], $values['text_hidden'], $values['seo_link'], $values['meta_title'], $values['meta_description'], $values['meta_keywords'], $values['parent_id'], $values['status'],
|
||||
$values['noindex'], $values['category_title'], $values['sort_type'], $values['additional_text'], $values['view_subcategories']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Kategoria została zapisana.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function category_edit()
|
||||
{
|
||||
return \admin\view\ShopCategory::category_edit(
|
||||
\admin\factory\ShopCategory::category_details(
|
||||
\S::get( 'id' )
|
||||
),
|
||||
\S::get( 'pid' ),
|
||||
\admin\factory\Languages::languages_list()
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-category/categories-list', [
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'level' => 0,
|
||||
'dlang' => \front\factory\Languages::default_language()
|
||||
] );
|
||||
}
|
||||
}
|
||||
28
autoload/admin/controls/class.ShopClients.php
Normal file
28
autoload/admin/controls/class.ShopClients.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopClients
|
||||
{
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view(
|
||||
'shop-clients/view-list'
|
||||
);
|
||||
}
|
||||
|
||||
public static function clients_details()
|
||||
{
|
||||
$query_string = $_SERVER['REDIRECT_QUERY_STRING'];
|
||||
parse_str($query_string, $query_array);
|
||||
|
||||
$orders_info = \admin\factory\ShopClients::get_order_all_info( $query_array['name'], $query_array['surname'], $query_array['email'] );
|
||||
|
||||
return \Tpl::view('shop-clients/clients-details', [
|
||||
'name' => $query_array['name'],
|
||||
'surname' => $query_array['surname'],
|
||||
'email' => $query_array['email'],
|
||||
'total_spent' => $query_array['total_spent'],
|
||||
'orders_info' => $orders_info
|
||||
]);
|
||||
}
|
||||
}
|
||||
?>
|
||||
58
autoload/admin/controls/class.ShopCoupon.php
Normal file
58
autoload/admin/controls/class.ShopCoupon.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class ShopCoupon
|
||||
{
|
||||
public static function coupon_delete()
|
||||
{
|
||||
$coupon = new \shop\Coupon( (int)\S::get( 'id' ) );
|
||||
if ( $coupon -> delete() )
|
||||
\S::alert( 'Kupon został usunięty.' );
|
||||
header( 'Location: /admin/shop_coupon/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function coupon_save()
|
||||
{
|
||||
$response = ['status' => 'error', 'msg' => 'Podczas zapisywania kuponu wystąpił błąd. Proszę spróbować ponownie.'];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $values['categories'] != null )
|
||||
$categories = is_array( $values['categories'] ) ? json_encode( $values['categories'] ) : json_encode( [ $values['categories'] ] );
|
||||
else
|
||||
$categories = null;
|
||||
|
||||
if ( \admin\factory\ShopCoupon::save(
|
||||
$values['id'],
|
||||
$values['name'],
|
||||
$values['status'] == 'on' ? 1 : 0,
|
||||
$values['send'] == 'on' ? 1 : 0,
|
||||
$values['used'] == 'on' ? 1 : 0,
|
||||
$values['type'],
|
||||
$values['amount'],
|
||||
$values['one_time'] == 'on' ? 1 : 0,
|
||||
$values['include_discounted_product'] == 'on' ? 1 : 0,
|
||||
$categories
|
||||
)
|
||||
)
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Kupon został zapisany.', 'id' => $values['id'] ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function coupon_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-coupon/coupon-edit', [
|
||||
'coupon' => \admin\factory\ShopCoupon::details( (int)\S::get( 'id' ) ),
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'dlang' => \front\factory\Languages::default_language()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-coupon/view-list' );
|
||||
}
|
||||
|
||||
}
|
||||
103
autoload/admin/controls/class.ShopOrder.php
Normal file
103
autoload/admin/controls/class.ShopOrder.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopOrder
|
||||
{
|
||||
static public function order_resend_confirmation_email()
|
||||
{
|
||||
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
|
||||
$response = $order -> order_resend_confirmation_email();
|
||||
|
||||
echo json_encode( [ 'result' => $response ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function notes_save()
|
||||
{
|
||||
\shop\Order::notes_save( \S::get( 'order_id' ), \S::get( 'notes' ) );
|
||||
}
|
||||
|
||||
static public function order_save()
|
||||
{
|
||||
if ( \shop\Order::order_save_by_admin(
|
||||
\S::get( 'order_id' ), \S::get( 'client_name' ), \S::get( 'client_surname' ), \S::get( 'client_firm' ), \S::get( 'client_street' ), \S::get( 'client_postal_code' ), \S::get( 'client_city' ), \S::get( 'client_email' ),
|
||||
\S::get( 'transport_id' ), \S::get( 'inpost_paczkomat' ), \S::get( 'payment_method_id' )
|
||||
) )
|
||||
\S::alert( 'Zamówienie zostało zapisane.' );
|
||||
|
||||
header( 'Location: /admin/shop_order/order_details/order_id=' . \S::get( 'order_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function order_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-order/order-edit', [
|
||||
'order' => new \shop\Order( (int)\S::get( 'order_id' ) ),
|
||||
'order_statuses' => \shop\Order::order_statuses(),
|
||||
'transport' => \shop\Transport::transport_list(),
|
||||
'payment_methods' => \shop\PaymentMethod::method_list()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function order_details()
|
||||
{
|
||||
return \Tpl::view( 'shop-order/order-details', [
|
||||
'order' => new \shop\Order( (int)\S::get( 'order_id' ) ),
|
||||
'order_statuses' => \shop\Order::order_statuses(),
|
||||
'next_order_id' => \admin\factory\ShopOrder::next_order_id( (int)\S::get( 'order_id' ) ),
|
||||
'prev_order_id' => \admin\factory\ShopOrder::prev_order_id( (int)\S::get( 'order_id' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view(
|
||||
'shop-order/view-list'
|
||||
);
|
||||
}
|
||||
|
||||
public static function order_status_change()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
|
||||
$response = $order -> update_status( (int)\S::get( 'status' ), \S::get( 'email' ) == 'true' ? 1 : 0 );
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function order_delete()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ( \shop\Order::order_delete( (int)\S::get( 'id' ) ) )
|
||||
{
|
||||
\S::alert( 'Zamówienie zostało usunięte' );
|
||||
\Log::save_log( 'Usunięcie zamówienia | ID: ' . (int)\S::get( 'id' ), $user['id'] );
|
||||
}
|
||||
|
||||
header( 'Location: /admin/shop_order/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// set_order_as_unpaid
|
||||
public static function set_order_as_unpaid()
|
||||
{
|
||||
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
|
||||
$order -> set_as_unpaid();
|
||||
header( 'Location: /admin/shop_order/order_details/order_id=' . (int)\S::get( 'order_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// set_order_as_paid
|
||||
public static function set_order_as_paid()
|
||||
{
|
||||
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
|
||||
if ( $order -> set_as_paid() )
|
||||
{
|
||||
$order -> update_status( 4, (int)\S::get( 'send_mail' ) );
|
||||
}
|
||||
header( 'Location: /admin/shop_order/order_details/order_id=' . (int)\S::get( 'order_id' ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
12
autoload/admin/controls/class.ShopPaymentMethod.php
Normal file
12
autoload/admin/controls/class.ShopPaymentMethod.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-payment-method/view-list', [
|
||||
'apilo_payment_types_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'payment-types-list' ) ),
|
||||
'sellasist_payment_types_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'payment_types_list' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
37
autoload/admin/controls/class.ShopProducer.php
Normal file
37
autoload/admin/controls/class.ShopProducer.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
class ShopProducer
|
||||
{
|
||||
static public function delete()
|
||||
{
|
||||
if ( \admin\factory\ShopProducer::delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Producent został usunięty' );
|
||||
header( 'Location: /admin/shop_producer/list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania producenta wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $producer_id = \admin\factory\ShopProducer::save( $values['id'], $values['name'], $values['status'] == 'on' ? 1 : 0, $values['img'], $values['description'], $values['meta_title'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Producent został zapisany.', 'id' => $producer_id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-producer/edit', [
|
||||
'producer' => \S::get( 'id' ) ? new \shop\Producer( \S::get( 'id' ) ) : null,
|
||||
'languages' => \admin\factory\Languages::languages_list()
|
||||
] );
|
||||
}
|
||||
|
||||
static public function list()
|
||||
{
|
||||
return \Tpl::view( 'shop-producer/list' );
|
||||
}
|
||||
}
|
||||
419
autoload/admin/controls/class.ShopProduct.php
Normal file
419
autoload/admin/controls/class.ShopProduct.php
Normal file
@@ -0,0 +1,419 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopProduct
|
||||
{
|
||||
static public function mass_edit_save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \S::get( 'discount_percent' ) != '' and \S::get( 'products' ) )
|
||||
{
|
||||
$product_details = \admin\factory\ShopProduct::product_details( \S::get( 'products' )[0] );
|
||||
|
||||
$vat = $product_details['vat'];
|
||||
$price_brutto = $product_details['price_brutto'];
|
||||
$price_brutto_promo = $price_brutto - ( $price_brutto * ( \S::get( 'discount_percent' ) / 100 ) );
|
||||
$price_netto = $product_details['price_netto'];
|
||||
$price_netto_promo = $price_netto - ( $price_netto * ( \S::get( 'discount_percent' ) / 100 ) );
|
||||
|
||||
if ( $price_brutto == $price_brutto_promo)
|
||||
$price_brutto_promo = null;
|
||||
|
||||
if ( $price_netto == $price_netto_promo )
|
||||
$price_netto_promo = null;
|
||||
|
||||
$mdb -> update( 'pp_shop_products', [ 'price_brutto_promo' => $price_brutto_promo, 'price_netto_promo' => $price_netto_promo ], [ 'id' => \S::get( 'products' )[0] ] );
|
||||
|
||||
\admin\factory\ShopProduct::update_product_combinations_prices( \S::get( 'products' )[0], $price_netto, $vat, $price_netto_promo );
|
||||
|
||||
echo json_encode( [ 'status' => 'ok', 'price_brutto_promo' => $price_brutto_promo, 'price_brutto' => $price_brutto ] );
|
||||
exit;
|
||||
}
|
||||
echo json_encode( [ 'status' => 'error' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_products_by_category
|
||||
static public function get_products_by_category() {
|
||||
global $mdb;
|
||||
|
||||
$products = $mdb -> select( 'pp_shop_products_categories', 'product_id', [ 'category_id' => \S::get( 'category_id' ) ] );
|
||||
|
||||
echo json_encode( [ 'status' => 'ok', 'products' => $products ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function mass_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-product/mass-edit', [
|
||||
'products' => \admin\factory\ShopProduct::products_list(),
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'dlang' => \front\factory\Languages::default_language()
|
||||
] );
|
||||
}
|
||||
|
||||
static public function generate_combination()
|
||||
{
|
||||
foreach ( $_POST as $key => $val )
|
||||
{
|
||||
if ( strpos( $key, 'attribute_' ) !== false )
|
||||
{
|
||||
$attribute = explode( 'attribute_', $key );
|
||||
$attributes[ $attribute[1] ] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if ( \admin\factory\ShopProduct::generate_permutation( (int) \S::get( 'product_id' ), $attributes ) )
|
||||
\S::alert( 'Kombinacje produktu zostały wygenerowane.' );
|
||||
|
||||
header( 'Location: /admin/shop_product/product_combination/product_id=' . (int) \S::get( 'product_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
//usunięcie kombinacji produktu
|
||||
static public function delete_combination()
|
||||
{
|
||||
if ( \admin\factory\ShopProduct::delete_combination( (int)\S::get( 'combination_id' ) ) )
|
||||
\S::alert( 'Kombinacja produktu została usunięta' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania kombinacji produktu wystąpił błąd. Proszę spróbować ponownie' );
|
||||
|
||||
header( 'Location: /admin/shop_product/product_combination/product_id=' . \S::get( 'product_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function duplicate_product()
|
||||
{
|
||||
if ( \admin\factory\ShopProduct::duplicate_product( (int)\S::get( 'product-id' ), (int)\S::get( 'combination' ) ) )
|
||||
\S::set_message( 'Produkt został zduplikowany.' );
|
||||
else
|
||||
\S::alert( 'Podczas duplikowania produktu wystąpił błąd. Proszę spróbować ponownie' );
|
||||
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function image_delete()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas usuwania zdjecia wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \admin\factory\ShopProduct::delete_img( \S::get( 'image_id' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function images_order_save()
|
||||
{
|
||||
if ( \admin\factory\ShopProduct::images_order_save( \S::get( 'product_id' ), \S::get( 'order' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok', 'msg' => 'Produkt został zapisany.' ] );
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function image_alt_change()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany atrybutu alt zdjęcia wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \admin\factory\ShopProduct::image_alt_change( \S::get( 'image_id' ), \S::get( 'image_alt' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// szybka zmiana statusu produktu
|
||||
static public function change_product_status() {
|
||||
|
||||
if ( \admin\factory\ShopProduct::change_product_status( (int)\S::get( 'product-id' ) ) )
|
||||
\S::set_message( 'Status produktu został zmieniony' );
|
||||
|
||||
header( 'Location: ' . $_SERVER['HTTP_REFERER'] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// szybka zmiana google xml label
|
||||
static public function product_change_custom_label()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany google xml label wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \admin\factory\ShopProduct::product_change_custom_label( (int) \S::get( 'product_id' ), \S::get( 'custom_label' ), \S::get( 'value' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// szybka zmiana ceny promocyjnej
|
||||
static public function product_change_price_brutto_promo()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany ceny wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \admin\factory\ShopProduct::product_change_price_brutto_promo( (int) \S::get( 'product_id' ), \S::get( 'price' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// szybka zmiana ceny
|
||||
static public function product_change_price_brutto()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zmiany ceny wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \admin\factory\ShopProduct::product_change_price_brutto( (int) \S::get( 'product_id' ), \S::get( 'price' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// pobierz bezpośredni url produktu
|
||||
static public function ajax_product_url()
|
||||
{
|
||||
echo json_encode( [ 'url' => \shop\Product::getProductUrl( \S::get( 'product_id' ) ) ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// zapisanie produktu
|
||||
public static function save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopProduct::save(
|
||||
$values['id'], $values['name'], $values['short_description'], $values['description'], $values['status'], $values['meta_description'], $values['meta_keywords'], $values['seo_link'],
|
||||
$values['copy_from'], $values['categories'], $values['price_netto'], $values['price_brutto'], $values['vat'], $values['promoted'], $values['warehouse_message_zero'], $values['warehouse_message_nonzero'], $values['tab_name_1'],
|
||||
$values['tab_description_1'], $values['tab_name_2'], $values['tab_description_2'], $values['layout_id'], $values['products_related'], (int) $values['set'], $values['price_netto_promo'], $values['price_brutto_promo'],
|
||||
$values['new_to_date'], $values['stock_0_buy'], $values['wp'], $values['custom_label_0'], $values['custom_label_1'], $values['custom_label_2'], $values['custom_label_3'], $values['custom_label_4'], $values['additional_message'], (int)$values['quantity'], $values['additional_message_text'], $values['additional_message_required'] == 'on' ? 1 : 0, $values['canonical'], $values['meta_title'], $values['producer_id'], $values['sku'], $values['ean'], $values['product_unit'], $values['weight'], $values['xml_name'], $values['custom_field_name']
|
||||
) ) {
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Produkt został zapisany.', 'id' => $id ];
|
||||
}
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// product_unarchive
|
||||
static public function product_unarchive()
|
||||
{
|
||||
if ( \admin\factory\ShopProduct::product_unarchive( (int) \S::get( 'product_id' ) ) )
|
||||
\S::alert( 'Produkt został przywrócony z archiwum.' );
|
||||
else
|
||||
\S::alert( 'Podczas przywracania produktu z archiwum wystąpił błąd. Proszę spróbować ponownie' );
|
||||
|
||||
header( 'Location: /admin/archive/products_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function product_archive()
|
||||
{
|
||||
if ( \admin\factory\ShopProduct::product_archive( (int) \S::get( 'product_id' ) ) )
|
||||
\S::alert( 'Produkt został przeniesiony do archiwum.' );
|
||||
else
|
||||
\S::alert( 'Podczas przenoszenia produktu do archiwum wystąpił błąd. Proszę spróbować ponownie' );
|
||||
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function product_delete()
|
||||
{
|
||||
if ( \admin\factory\ShopProduct::product_delete( (int) \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Produkt został usunięty.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie' );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// edycja produktu
|
||||
public static function product_edit()
|
||||
{
|
||||
\admin\factory\ShopProduct::delete_nonassigned_images();
|
||||
\admin\factory\ShopProduct::delete_nonassigned_files();
|
||||
|
||||
return \Tpl::view( 'shop-product/product-edit', [
|
||||
'product' => \admin\factory\ShopProduct::product_details( (int) \S::get( 'id' ) ),
|
||||
'languages' => \admin\factory\Languages::languages_list(),
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'layouts' => \admin\factory\Layouts::layouts_list(),
|
||||
'products' => \admin\factory\ShopProduct::products_list(),
|
||||
'dlang' => \front\factory\Languages::default_language(),
|
||||
'sets' => \shop\ProductSet::sets_list(),
|
||||
'producers' => \admin\factory\ShopProducer::all(),
|
||||
'units' => \admin\factory\Dictionaries::all_units()
|
||||
] );
|
||||
}
|
||||
|
||||
// ajax_load_products ARCHIVE
|
||||
static public function ajax_load_products_archive()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas ładowania produktów wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
\S::set_session( 'products_list_current_page', \S::get( 'current_page' ) );
|
||||
\S::set_session( 'products_list_query', \S::get( 'query' ) );
|
||||
|
||||
if ( $products = \admin\factory\ShopProduct::ajax_products_list_archive( \S::get_session( 'products_list_current_page' ), \S::get_session( 'products_list_query' ) ) ) {
|
||||
$response = [
|
||||
'status' => 'ok',
|
||||
'pagination_max' => ceil( $products['products_count'] / 10 ),
|
||||
'html' => \Tpl::view( 'archive/products-list-table', [
|
||||
'products' => $products['products'],
|
||||
'current_page' => \S::get( 'current_page' ),
|
||||
] )
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ajax_load_products
|
||||
static public function ajax_load_products() {
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas ładowania produktów wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
\S::set_session( 'products_list_current_page', \S::get( 'current_page' ) );
|
||||
\S::set_session( 'products_list_query', \S::get( 'query' ) );
|
||||
|
||||
if ( $products = \admin\factory\ShopProduct::ajax_products_list( \S::get_session( 'products_list_current_page' ), \S::get_session( 'products_list_query' ) ) ) {
|
||||
$response = [
|
||||
'status' => 'ok',
|
||||
'pagination_max' => ceil( $products['products_count'] / 10 ),
|
||||
'html' => \Tpl::view( 'shop-product/products-list-table', [
|
||||
'products' => $products['products'],
|
||||
'current_page' => \S::get( 'current_page' ),
|
||||
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
|
||||
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
|
||||
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
|
||||
'show_xml_data' => \S::get_session( 'show_xml_data' )
|
||||
] )
|
||||
];
|
||||
}
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function view_list()
|
||||
{
|
||||
$current_page = \S::get_session( 'products_list_current_page' );
|
||||
|
||||
if ( !$current_page ) {
|
||||
$current_page = 1;
|
||||
\S::set_session( 'products_list_current_page', $current_page );
|
||||
}
|
||||
|
||||
$query = \S::get_session( 'products_list_query' );
|
||||
if ( $query ) {
|
||||
$query_array = [];
|
||||
parse_str( $query, $query_array );
|
||||
}
|
||||
|
||||
if ( \S::get( 'show_xml_data' ) === 'true' ) {
|
||||
\S::set_session( 'show_xml_data', true );
|
||||
} else if ( \S::get( 'show_xml_data' ) === 'false' ) {
|
||||
\S::set_session( 'show_xml_data', false );
|
||||
}
|
||||
|
||||
return \Tpl::view( 'shop-product/products-list', [
|
||||
'current_page' => $current_page,
|
||||
'query_array' => $query_array,
|
||||
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product() / 10 ),
|
||||
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
|
||||
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
|
||||
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
|
||||
'show_xml_data' => \S::get_session( 'show_xml_data' ),
|
||||
'shoppro_enabled' => \admin\factory\Integrations::shoppro_settings( 'enabled' )
|
||||
] );
|
||||
}
|
||||
|
||||
//
|
||||
// KOMBINACJE PRODUKTU
|
||||
//
|
||||
|
||||
// zapisanie możliwości zakupu przy stanie 0 w kombinacji produktu
|
||||
static public function product_combination_stock_0_buy_save()
|
||||
{
|
||||
\admin\factory\ShopProduct::product_combination_stock_0_buy_save( (int)\S::get( 'product_id' ), \S::get( 'stock_0_buy' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// zapisanie sku w kombinacji produktu
|
||||
static public function product_combination_sku_save()
|
||||
{
|
||||
\admin\factory\ShopProduct::product_combination_sku_save( (int)\S::get( 'product_id' ), \S::get( 'sku' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// zapisanie ilości w kombinacji produktu
|
||||
static public function product_combination_quantity_save()
|
||||
{
|
||||
\admin\factory\ShopProduct::product_combination_quantity_save( (int)\S::get( 'product_id' ), \S::get( 'quantity' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
// zapisanie ceny w kombinacji produktu
|
||||
static public function product_combination_price_save()
|
||||
{
|
||||
\admin\factory\ShopProduct::product_combination_price_save( (int)\S::get( 'product_id' ), \S::get( 'price' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
//wyświetlenie kombinacji produktu
|
||||
static public function product_combination()
|
||||
{
|
||||
return \Tpl::view( 'shop-product/product-combination', [
|
||||
'product' => \admin\factory\ShopProduct::product_details( (int) \S::get( 'product_id' ) ),
|
||||
'attributes' => \admin\factory\ShopAttribute::get_attributes_list(),
|
||||
'default_language' => \front\factory\Languages::default_language(),
|
||||
'product_permutations' => \admin\factory\ShopProduct::get_product_permutations( (int) \S::get( 'product_id' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
// generate_sku_code
|
||||
static public function generate_sku_code() {
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas generowania kodu sku wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( $sku = \shop\Product::generate_sku_code( \S::get( 'product_id' ) ) )
|
||||
$response = [ 'status' => 'ok', 'sku' => $sku ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// product_xml_name_save
|
||||
static public function product_xml_name_save() {
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania nazwy produktu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \shop\Product::product_xml_name_save( \S::get( 'product_id' ), \S::get( 'product_xml_name' ), \S::get( 'lang_id' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// product_custom_label_suggestions
|
||||
static public function product_custom_label_suggestions() {
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas pobierania sugestii dla custom label wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( $suggestions = \shop\Product::product_custom_label_suggestions( \S::get( 'custom_label' ), \S::get( 'label_type' ) ) )
|
||||
$response = [ 'status' => 'ok', 'suggestions' => $suggestions ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// product_custom_label_save
|
||||
static public function product_custom_label_save() {
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania custom label wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
|
||||
if ( \shop\Product::product_custom_label_save( \S::get( 'product_id' ), \S::get( 'custom_label' ), \S::get( 'label_type' ) ) )
|
||||
$response = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
43
autoload/admin/controls/class.ShopProductSets.php
Normal file
43
autoload/admin/controls/class.ShopProductSets.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopProductSets
|
||||
{
|
||||
|
||||
static public function set_delete()
|
||||
{
|
||||
if ( \shop\ProductSet::set_delete( \S::get( 'id' ) ) )
|
||||
\S::set_message( 'Komplet produktów usunięty.' );
|
||||
else
|
||||
\S::alert( 'Podczas usuwania kompletu produktów wystąpił błąd. Proszę spróbować ponownie' );
|
||||
header( 'Location: /admin/shop_product_sets/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kompletu produktów wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopProductSet::save(
|
||||
(int)$values['id'], $values['name'], (string) $values['status'], $values['set_products_id']
|
||||
) ) {
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Komplet produktów został zapisany.', 'id' => $id ];
|
||||
}
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function set_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-product-sets/set-edit', [
|
||||
'set' => new \shop\ProductSet( (int) \S::get( 'id' ) ),
|
||||
'products' => \admin\factory\ShopProduct::products_list()
|
||||
] );
|
||||
}
|
||||
|
||||
static public function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-product-sets/view-list' );
|
||||
}
|
||||
}
|
||||
59
autoload/admin/controls/class.ShopPromotion.php
Normal file
59
autoload/admin/controls/class.ShopPromotion.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopPromotion
|
||||
{
|
||||
// usunięcie promocji
|
||||
static public function promotion_delete()
|
||||
{
|
||||
$promotion = \R::load( 'pp_shop_promotion', (int)\S::get( 'id' ) );
|
||||
if ( \R::trash( $promotion ) )
|
||||
\S::alert( 'Promocja została usunięta' );
|
||||
|
||||
header( 'Location: /admin/shop_promotion/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// zapisanie promocji
|
||||
static public function save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania promocji wystąpił błąd. Proszę spróbować ponownie' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopPromotion::save(
|
||||
$values['id'],
|
||||
$values['name'],
|
||||
$values['status'] == 'on' ? 1 : 0,
|
||||
$values['condition_type'],
|
||||
$values['discount_type'],
|
||||
$values['amount'],
|
||||
$values['date_to'],
|
||||
$values['categories'],
|
||||
$values['condition_categories'],
|
||||
$values['include_coupon'] == 'on' ? 1 : 0,
|
||||
$values['include_product_promo'] == 'on' ? 1 : 0,
|
||||
$values['min_product_count'],
|
||||
$values['price_cheapest_product']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Promocja została zapisana', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// edycja promocji
|
||||
static public function edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-promotion/promotion-edit', [
|
||||
'promotion' => \admin\factory\ShopPromotion::promotion_details( (int)\S::get( 'id' ) ),
|
||||
'categories' => \admin\factory\ShopCategory::subcategories( null ),
|
||||
'dlang' => \front\factory\Languages::default_language()
|
||||
] );
|
||||
}
|
||||
|
||||
// lista promocji
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-promotion/view-list' );
|
||||
}
|
||||
|
||||
}
|
||||
38
autoload/admin/controls/class.ShopStatuses.php
Normal file
38
autoload/admin/controls/class.ShopStatuses.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class ShopStatuses {
|
||||
|
||||
// status_save
|
||||
public static function status_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania statusu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'], $values['sellasist_status_id'], $values['baselinker_status_id'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Status został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// status_edit
|
||||
public static function status_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-statuses/status-edit', [
|
||||
'status' => \admin\factory\ShopStatuses::get_status( \S::get( 'id' ) ),
|
||||
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
|
||||
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
|
||||
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
static public function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-statuses/view-list', [
|
||||
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
|
||||
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
|
||||
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
36
autoload/admin/controls/class.ShopTransport.php
Normal file
36
autoload/admin/controls/class.ShopTransport.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
class ShopTransport
|
||||
{
|
||||
public static function transport_save()
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania rodzaju transportu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopTransport::transport_save(
|
||||
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['sellasist_shipment_method_id'], $values['delivery_free']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Rodzaj transportu został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function transport_edit()
|
||||
{
|
||||
return \Tpl::view( 'shop-transport/transport-edit', [
|
||||
'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
|
||||
'payments_list' => \admin\factory\ShopPaymentMethod::payments_list(),
|
||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
||||
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \Tpl::view( 'shop-transport/view-list', [
|
||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
||||
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
29
autoload/admin/controls/class.Update.php
Normal file
29
autoload/admin/controls/class.Update.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Update
|
||||
{
|
||||
public static function update()
|
||||
{
|
||||
if ( !\admin\factory\Update::update() )
|
||||
\S::alert( 'W trakcie aktualizacji systemu wystąpił błąd. Proszę spróbować ponownie.' );
|
||||
else
|
||||
\S::set_message( 'Aktualizacja przebiegła pomyślnie.' );
|
||||
|
||||
header( 'Location: /admin/update/main_view/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function updateAll()
|
||||
{
|
||||
$response['status'] = \admin\factory\Update::update();
|
||||
$response['version'] = number_format( \S::get('version_current') + 0.001, 3, '.', '' );
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function main_view()
|
||||
{
|
||||
return \admin\view\Update::main_view();
|
||||
}
|
||||
}
|
||||
36
autoload/admin/controls/class.Users.php
Normal file
36
autoload/admin/controls/class.Users.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Users
|
||||
{
|
||||
public static function user_delete()
|
||||
{
|
||||
if ( \admin\factory\Users::user_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( 'Użytkownik został usunięty.' );
|
||||
header( 'Location: /admin/users/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function user_save()
|
||||
{
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
$response = \admin\factory\Users::user_save( $values['id'], $values['login'], $values['status'], $values['password'], $values['password_re'], $values['admin'] );
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function user_edit()
|
||||
{
|
||||
return \admin\view\Users::user_edit(
|
||||
\admin\factory\Users::user_details(
|
||||
\S::get( 'id' )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static function view_list()
|
||||
{
|
||||
return \admin\view\Users::users_list();
|
||||
}
|
||||
}
|
||||
?>
|
||||
473
autoload/admin/factory/class.Articles.php
Normal file
473
autoload/admin/factory/class.Articles.php
Normal file
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class Articles
|
||||
{
|
||||
public static function gallery_order_save( $article_id, $order )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$order = explode( ';', $order );
|
||||
if ( is_array( $order ) and !empty( $order ) ) foreach ( $order as $image_id )
|
||||
{
|
||||
$mdb -> update( 'pp_articles_images', [
|
||||
'o' => $i++
|
||||
], [
|
||||
'AND' => [
|
||||
'article_id' => $article_id,
|
||||
'id' => $image_id
|
||||
]
|
||||
] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function image_alt_change( $image_id, $image_alt )
|
||||
{
|
||||
global $mdb;
|
||||
$result = $mdb -> update( 'pp_articles_images', [
|
||||
'alt' => $image_alt
|
||||
], [
|
||||
'id' => $image_id
|
||||
] );
|
||||
\S::delete_cache();
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function article_url( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT seo_link FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = " . (int)$article_id . " AND seo_link != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = self::article_title( $article_id );
|
||||
return 'a-' . $article_id . '-' . \S::seo( $title );
|
||||
}
|
||||
else
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public static function articles_by_date_add( $date_start, $date_end )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'id '
|
||||
. 'FROM '
|
||||
. 'pp_articles '
|
||||
. 'WHERE '
|
||||
. 'status = 1 '
|
||||
. 'AND '
|
||||
. 'date_add BETWEEN \'' . $date_start . '\' AND \'' . $date_end . '\' '
|
||||
. 'ORDER BY '
|
||||
. 'date_add DESC' ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$articles[] = \front\factory\Articles::article_details( $row['id'], 'pl' );
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public static function article_pages( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT page_id FROM pp_articles_pages WHERE article_id = " . (int)$article_id ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( $out == '' )
|
||||
$out .= ' - ';
|
||||
|
||||
$out .= \admin\factory\Pages::page_title( $row['page_id'] );
|
||||
|
||||
if ( end( $results ) != $row )
|
||||
$out .= ' / ';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function article_title( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
$results = $mdb -> query( "SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = " . (int)$article_id . " AND title != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
return $results[0]['title'];
|
||||
}
|
||||
|
||||
public static function articles_set_archive( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_articles', [ 'status' => -1 ], [ 'id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
public static function file_name_change( $file_id, $file_name )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_files', [ 'name' => $file_name ], [ 'id' => (int)$file_id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delete_file( $file_id )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_files', [ 'to_delete' => 1 ], [ 'id' => (int)$file_id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function delete_img( $image_id )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_images', [ 'to_delete' => 1 ], [ 'id' => (int)$image_id ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function article_details( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] ) )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_articles_langs', '*', [ 'article_id' => (int)$article_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$article['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'DESC' ] ] );
|
||||
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
|
||||
$article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_articles_pages', 'o' );
|
||||
}
|
||||
|
||||
public static function article_save(
|
||||
$article_id, $title, $main_image, $entry, $text, $table_of_contents, $status, $show_title, $show_table_of_contents, $show_date_add, $date_add, $show_date_modify, $date_modify, $seo_link, $meta_title, $meta_description, $meta_keywords, $layout_id, $pages,
|
||||
$noindex, $repeat_entry, $copy_from, $social_icons, $block_direct_access )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$article_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles', [
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
|
||||
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
|
||||
'date_add' => date( 'Y-m-d H:i:s' ),
|
||||
'date_modify' => date( 'Y-m-d H:i:s' ),
|
||||
'modify_by' => $user['id'],
|
||||
'layout_id' => $layout_id ? (int)$layout_id : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeat_entry == 'on' ? 1 : 0,
|
||||
'social_icons' => $social_icons == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $show_table_of_contents == 'on' ? 1 : 0,
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'main_image' => $main_image[$key] != '' ? $main_image[$key] : null,
|
||||
'entry' => $entry[$key] != '' ? $entry[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'table_of_contents' => $table_of_contents[$key] != '' ? $table_of_contents[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key] == 'on' ? 1 : 0,
|
||||
'copy_from' => $copy_from[$key] != '' ? $copy_from[$key] : null,
|
||||
'block_direct_access' => $block_direct_access[$key] == 'on' ? 1 : 0
|
||||
] );
|
||||
}
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$pages,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_files/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => $id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
/* zdjęcia */
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_images/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '../' . $new_file_name ) )
|
||||
{
|
||||
$ext = strrpos( $new_file_name, '.' );
|
||||
$fileName_a = substr( $new_file_name, 0, $ext );
|
||||
$fileName_b = substr( $new_file_name, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
while ( file_exists( '../' . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
$new_file_name = $fileName_a . '_' . $count . $fileName_b;
|
||||
}
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_articles', [
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
|
||||
'date_add' => $date_add,
|
||||
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
|
||||
'date_modify' => $date_modify,
|
||||
'modify_by' => $user['id'],
|
||||
'layout_id' => $layout_id ? (int)$layout_id : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeat_entry == 'on' ? 1 : 0,
|
||||
'social_icons' => $social_icons == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $show_table_of_contents == 'on' ? 1 : 0,
|
||||
], [
|
||||
'id' => (int)$article_id
|
||||
] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_articles_langs', 'id', [ 'AND' => [ 'article_id' => $article_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_articles_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'main_image' => $main_image[$key] != '' ? $main_image[$key] : null,
|
||||
'entry' => $entry[$key] != '' ? $entry[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'table_of_contents' => $table_of_contents[$key] != '' ? $table_of_contents[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key] == 'on' ? 1 : 0,
|
||||
'copy_from' => $copy_from[$key] != '' ? $copy_from[$key] : null,
|
||||
'block_direct_access' => $block_direct_access[$key] == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$article_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'main_image' => $main_image[$key] != '' ? $main_image[$key] : null,
|
||||
'entry' => $entry[$key] != '' ? $entry[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'table_of_contents' => $table_of_contents[$key] != '' ? $table_of_contents[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key] == 'on' ? 1 : 0,
|
||||
'copy_from' => $copy_from[$key] != '' ? $copy_from[$key] : null,
|
||||
'block_direct_access' => $block_direct_access[$key] == 'on' ? 1 : 0
|
||||
] );
|
||||
}
|
||||
|
||||
$not_in = [ 0 ];
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
$not_in[] = $page;
|
||||
else if ( $pages )
|
||||
$not_in[] = $pages;
|
||||
|
||||
$mdb -> delete( 'pp_articles_pages', [ 'AND' => [ 'article_id' => (int)$article_id, 'page_id[!]' => $not_in ] ] );
|
||||
|
||||
$pages_tmp = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
if ( !is_array( $pages ) )
|
||||
$pages = [ $pages ];
|
||||
|
||||
$pages = array_diff( $pages, $pages_tmp );
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$article_id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $article_id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_files/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => (int)$article_id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
/* zdjęcia */
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $article_id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_images/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '../' . $new_file_name ) )
|
||||
{
|
||||
$ext = strrpos( $new_file_name, '.' );
|
||||
$fileName_a = substr( $new_file_name, 0, $ext );
|
||||
$fileName_b = substr( $new_file_name, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
while ( file_exists( '../' . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
$new_file_name = $fileName_a . '_' . $count . $fileName_b;
|
||||
}
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$article_id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_images', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_files', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
|
||||
\S::htacces();
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $article_id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function delete_nonassigned_files()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_files', [ 'article_id' => null ] );
|
||||
}
|
||||
|
||||
public static function delete_nonassigned_images()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_images', [ 'article_id' => null ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
27
autoload/admin/factory/class.ArticlesArchive.php
Normal file
27
autoload/admin/factory/class.ArticlesArchive.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class ArticlesArchive
|
||||
{
|
||||
public static function article_restore( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_articles', [ 'status' => 0 ], [ 'id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
public static function article_delete( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> delete( 'pp_articles_pages', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles_langs', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles_images', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles_files', [ 'article_id' => (int)$article_id ] );
|
||||
$mdb -> delete( 'pp_articles', [ 'id' => (int)$article_id ] );
|
||||
|
||||
\S::delete_dir( '../upload/article_images/article_' . (int)$article_id . '/' );
|
||||
\S::delete_dir( '../upload/article_files/article_' . (int)$article_id . '/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
108
autoload/admin/factory/class.Banners.php
Normal file
108
autoload/admin/factory/class.Banners.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace admin\factory;
|
||||
|
||||
class Banners
|
||||
{
|
||||
public static function banner_delete( $banner_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> delete( 'pp_banners', [ 'id' => (int) $banner_id ] );
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function banner_save( $banner_id, $name, $status, $date_start, $date_end, $home_page, $src, $url, $html, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$banner_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_banners', [
|
||||
'name' => $name,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'date_start' => $date_start != '' ? $date_start : null,
|
||||
'date_end' => $date_end != '' ? $date_end : null,
|
||||
'home_page' => $home_page == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $src as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_banners_langs', [
|
||||
'id_banner' => (int)$id,
|
||||
'id_lang' => $key,
|
||||
'src' => $src[$key],
|
||||
'url' => $url[$key],
|
||||
'html' => $html[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_banners', [
|
||||
'name' => $name,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'date_start' => $date_start != '' ? $date_start : null,
|
||||
'date_end' => $date_end != '' ? $date_end : null,
|
||||
'home_page' => $home_page == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$banner_id
|
||||
] );
|
||||
|
||||
foreach ( $src as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_banners_langs', 'id', [ 'AND' => [ 'banner_id' => $banner_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_banners_langs', [
|
||||
'id_lang' => $key,
|
||||
'src' => $src[$key],
|
||||
'url' => $url[$key],
|
||||
'html' => $html[$key],
|
||||
'text' => $text[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_banners_langs', [
|
||||
'id_banner' => (int)$banner_id,
|
||||
'id_lang' => $key,
|
||||
'src' => $src[$key],
|
||||
'url' => $url[$key],
|
||||
'html' => $html[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $banner_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function banner_details( $id_banner )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$banner = $mdb -> get( 'pp_banners', '*', [ 'id' => (int)$id_banner ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_banners_langs', '*', [ 'id_banner' => (int)$id_banner ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$banner['languages'][$row['id_lang']] = $row;
|
||||
|
||||
return $banner;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
39
autoload/admin/factory/class.Baselinker.php
Normal file
39
autoload/admin/factory/class.Baselinker.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Baselinker {
|
||||
|
||||
// zapis wiązania produktów
|
||||
static public function bundling_products_save( $values ) {
|
||||
global $mdb;
|
||||
|
||||
foreach ( $values as $key => $val ) {
|
||||
$key = explode( '_', $key );
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $val ], [ 'id' => $key[1] ] );
|
||||
}
|
||||
}
|
||||
|
||||
// pobranie produktów z Baselinkera
|
||||
static public function products_list() {
|
||||
global $settings;
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $settings['baselinker_api'],
|
||||
"method" => "getProductsList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
return $response['products'];
|
||||
}
|
||||
}
|
||||
89
autoload/admin/factory/class.Dictionaries.php
Normal file
89
autoload/admin/factory/class.Dictionaries.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
class Dictionaries
|
||||
{
|
||||
static public function all_units()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_units', '*' );
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$resutls2 = $mdb -> query( 'SELECT text FROM pp_units_langs AS psl, pp_langs AS pl WHERE unit_id = ' . $row['id'] . ' AND lang_id = pl.id AND text != \'\' ORDER BY o ASC LIMIT 1' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$row['text'] = $resutls2[0]['text'];
|
||||
$units[ $row['id'] ] = $row;
|
||||
}
|
||||
return $units;
|
||||
}
|
||||
|
||||
static public function unit_details( $unit_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$unit = $mdb -> get( 'pp_units', '*', [ 'id' => (int)$unit_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_units_langs', '*', [ 'unit_id' => (int)$unit_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$unit['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
return $unit;
|
||||
|
||||
}
|
||||
|
||||
static public function unit_save( $unit_id, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$unit_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_units', array());
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $text as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_units_langs', [
|
||||
'unit_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ( $text as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_units_langs', 'id', [ 'AND' => [ 'unit_id' => $unit_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_units_langs', [
|
||||
'lang_id' => $key,
|
||||
'text' => $text[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_units_langs', [
|
||||
'unit_id' => (int)$unit_id,
|
||||
'lang_id' => $key,
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/dictionaries' );
|
||||
|
||||
return $unit_id;
|
||||
}
|
||||
}
|
||||
|
||||
static public function unit_delete( $unit_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_units', [ 'id' => (int)$unit_id ] );
|
||||
}
|
||||
}
|
||||
264
autoload/admin/factory/class.Integrations.php
Normal file
264
autoload/admin/factory/class.Integrations.php
Normal file
@@ -0,0 +1,264 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Integrations {
|
||||
|
||||
// sellasist_product_select_delete
|
||||
static public function sellasist_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => null, 'sellasist_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// sellasist_product_select_save
|
||||
static public function sellasist_product_select_save( int $product_id, $sellasist_product_id, $sellasist_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => $sellasist_product_id, 'sellasist_product_name' => \S::remove_special_chars( $sellasist_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo delete product linking
|
||||
static public function apilo_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => null, 'apilo_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// baselinker delete product linking
|
||||
static public function baselinker_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => null, 'baselinker_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo product select save
|
||||
static public function apilo_product_select_save( int $product_id, $apilo_product_id, $apilo_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => $apilo_product_id, 'apilo_product_name' => \S::remove_special_chars( $apilo_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
static public function baselinker_product_select_save( int $product_id, $baselinker_product_id, $baselinker_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $baselinker_product_id, 'baselinker_product_name' => $baselinker_product_name ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// get settings for shoppro integration
|
||||
static public function shoppro_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_shoppro_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_shoppro_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the sellasist integration
|
||||
static public function sellasist_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_sellasist_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_sellasist_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the Baselinker integration
|
||||
static public function baselinker_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_baselinker_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_baselinker_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the APILO plugin
|
||||
static public function apilo_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_apilo_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_apilo_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// save settings for shoppro integration
|
||||
static public function shoppro_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_shoppro_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_shoppro_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_shoppro_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the sellasist integration
|
||||
static public function sellasist_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_sellasist_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_sellasist_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_sellasist_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the Baselinker integration
|
||||
static public function baselinker_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_baselinker_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_baselinker_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_baselinker_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the APILO plugin
|
||||
static public function apilo_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_apilo_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_apilo_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_apilo_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// authorization in apilo.com
|
||||
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/auth/token/";
|
||||
|
||||
$postData['grantType'] = 'authorization_code';
|
||||
$postData['token'] = $authorization_code;
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $client_id . ":" . $client_secret ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// get access token or refresh it apilo.com
|
||||
static public function apilo_get_access_token()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$apilo_settings = self::apilo_settings();
|
||||
|
||||
$date1 = new \DateTime( $apilo_settings['access-token-expire-at'] );
|
||||
$date2 = new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
if ( $date1 < $date2 )
|
||||
{
|
||||
$post_data = [
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $apilo_settings['refresh-token']
|
||||
];
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $apilo_settings['client-id'] . ":" . $apilo_settings['client-secret'] ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_POST, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post_data ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
if ( $access_token == '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
return $apilo_settings['access-token'];
|
||||
}
|
||||
}
|
||||
136
autoload/admin/factory/class.Languages.php
Normal file
136
autoload/admin/factory/class.Languages.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?
|
||||
|
||||
namespace admin\factory;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function translation_delete( $translation_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_langs_translations', [ 'id' => $translation_id ] );
|
||||
}
|
||||
|
||||
public static function translation_save( $translation_id, $text, $languages )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $translation_id )
|
||||
{
|
||||
$mdb -> update( 'pp_langs_translations', [ 'text' => $text ], [ 'id' => $translation_id ] );
|
||||
if ( is_array( $languages ) and !empty( $languages ) ): foreach ( $languages as $key => $val ):
|
||||
$mdb -> update( 'pp_langs_translations', [ $key => $val ], [ 'id' => $translation_id ] );
|
||||
endforeach; endif;
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $translation_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> insert( 'pp_langs_translations', [ 'text' => $text ] );
|
||||
if ( $translation_id = $mdb -> id() )
|
||||
{
|
||||
if ( is_array( $languages ) and !empty( $languages ) ): foreach ( $languages as $key => $val ):
|
||||
$mdb -> update( 'pp_langs_translations', [ $key => $val ], [ 'id' => $translation_id ] );
|
||||
endforeach; endif;
|
||||
}
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $translation_id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function translation_details( $translation_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_langs_translations', '*', [ 'id' => $translation_id ] );
|
||||
}
|
||||
|
||||
public static function language_delete( $language_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_langs' ) > 1 )
|
||||
{
|
||||
if ( $mdb -> query( 'ALTER TABLE pp_langs_translations DROP ' . $language_id )
|
||||
and
|
||||
$mdb -> delete( 'pp_langs', [ 'id' => $language_id ] )
|
||||
)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_langs', 'o' );
|
||||
}
|
||||
|
||||
public static function language_save( $language_id, $name, $status, $start, $o )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $start == 'on' )
|
||||
$mdb -> update( 'pp_langs', [
|
||||
'start' => 0
|
||||
], [
|
||||
'id[!]' => $language_id
|
||||
] );
|
||||
|
||||
if ( $mdb -> count( 'pp_langs', [ 'id' => $language_id ] ) )
|
||||
{
|
||||
$mdb -> update( 'pp_langs',
|
||||
[
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'name' => $name,
|
||||
'o' => $o
|
||||
], [
|
||||
'id' => $language_id
|
||||
] );
|
||||
|
||||
if ( !$mdb -> count( 'pp_langs', [ 'start' => 1 ] ) )
|
||||
{
|
||||
$id_tmp = $mdb -> get( 'pp_langs', 'id', [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
$mdb -> update( 'pp_langs', [ 'start' => 1 ], [ 'id' => $id_tmp ] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $language_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $mdb -> query( 'ALTER TABLE pp_langs_translations ADD ' . $language_id . ' TEXT NULL DEFAULT NULL' ) )
|
||||
{
|
||||
$mdb -> insert( 'pp_langs',
|
||||
[
|
||||
'id' => $language_id,
|
||||
'name' => $name,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'o' => $o
|
||||
] );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $language_id;
|
||||
}
|
||||
}
|
||||
|
||||
return faslse;
|
||||
}
|
||||
|
||||
public static function language_details( $language_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_langs', '*', [ 'id' => $language_id ] );
|
||||
}
|
||||
|
||||
public static function languages_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_langs', '*', [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
190
autoload/admin/factory/class.Layouts.php
Normal file
190
autoload/admin/factory/class.Layouts.php
Normal file
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Layouts
|
||||
{
|
||||
public static function layout_delete( $layout_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_layouts' ) > 1 )
|
||||
return $mdb -> delete( 'pp_layouts', [ 'id' => (int)$layout_id ] );
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function layout_details( $layout_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'id' => (int)$layout_id ] );
|
||||
|
||||
$layout['pages'] = $mdb -> select( 'pp_layouts_pages', 'page_id', [ 'layout_id' => (int)$layout_id ] );
|
||||
$layout['categories'] = $mdb -> select( 'pp_layouts_categories', 'category_id', [ 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public static function layout_save( $layout_id, $name, $status, $pages, $html, $css, $js, $m_html, $m_css, $m_js, $categories, $categories_default )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$layout_id )
|
||||
{
|
||||
if ( $status == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'status' => 0 ] );
|
||||
|
||||
if ( $categories_default == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'categories_default' => 0 ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts', [
|
||||
'name' => $name,
|
||||
'html' => $html,
|
||||
'css' => $css,
|
||||
'js' => $js,
|
||||
'm_html' => $m_html,
|
||||
'm_css' => $m_css,
|
||||
'm_js' => $m_js,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'categories_default' => $categories_default == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$id,
|
||||
'page_id' => (int)$page
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$pages ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$id,
|
||||
'page_id' => (int)$pages
|
||||
] );
|
||||
}
|
||||
|
||||
if ( is_array( $categories ) ) foreach ( $categories as $category )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$category ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$id,
|
||||
'category_id' => (int)$category
|
||||
] );
|
||||
}
|
||||
else if ( $categories )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$categories ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$id,
|
||||
'category_id' => (int)$categories
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $status == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'status' => 0 ] );
|
||||
|
||||
if ( $categories_default == 'on' )
|
||||
$mdb -> update( 'pp_layouts', [ 'categories_default' => 0 ] );
|
||||
|
||||
$mdb -> update( 'pp_layouts', [
|
||||
'name' => $name,
|
||||
'html' => $html,
|
||||
'css' => $css,
|
||||
'js' => $js,
|
||||
'm_html' => $m_html,
|
||||
'm_css' => $m_css,
|
||||
'm_js' => $m_js,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'categories_default' => $categories_default == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $layout_id
|
||||
] );
|
||||
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'page_id' => (int)$page
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$pages ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_pages', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'page_id' => (int)$pages
|
||||
] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
if ( is_array( $categories ) ) foreach ( $categories as $category )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$category ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'category_id' => (int)$category
|
||||
] );
|
||||
}
|
||||
else if ( $categories )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_categories', [ 'category_id' => (int)$categories ] );
|
||||
|
||||
$mdb -> insert( 'pp_layouts_categories', [
|
||||
'layout_id' => (int)$layout_id,
|
||||
'category_id' => (int)$categories
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $layout_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_menus', 'id', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$menu = \admin\factory\Pages::menu_details( $row );
|
||||
$menu['pages'] = \admin\factory\Pages::menu_pages( $row );
|
||||
|
||||
$menus[] = $menu;
|
||||
}
|
||||
return $menus;
|
||||
}
|
||||
|
||||
public static function layouts_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_layouts', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
76
autoload/admin/factory/class.Newsletter.php
Normal file
76
autoload/admin/factory/class.Newsletter.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function is_admin_template( $template_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_newsletter_templates', 'is_admin', [ 'id' => (int)$template_id ] );
|
||||
}
|
||||
|
||||
public static function newsletter_template_delete( $template_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_newsletter_templates', [ 'id' => (int)$template_id ] );
|
||||
}
|
||||
|
||||
public static function send( $dates, $template )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_newsletter', 'email', [ 'status' => 1 ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_newsletter_send', [
|
||||
'email' => $row,
|
||||
'dates' => $dates,
|
||||
'id_template' => $template ? $template : null
|
||||
] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function email_template_detalis ($id_template)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get ('pp_newsletter_templates', '*', [ 'id' => (int)$id_template ] );
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function template_save( $id, $name, $text )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_newsletter_templates', [
|
||||
'name' => $name,
|
||||
'text' => $text
|
||||
] ) )
|
||||
{
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $mdb -> id();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_newsletter_templates', [
|
||||
'name' => $name,
|
||||
'text' => $text
|
||||
], [
|
||||
'id' => (int)$id
|
||||
] );
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function templates_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_newsletter_templates', '*', [ 'is_admin' => 0, 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
}
|
||||
407
autoload/admin/factory/class.Pages.php
Normal file
407
autoload/admin/factory/class.Pages.php
Normal file
@@ -0,0 +1,407 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Pages
|
||||
{
|
||||
public static $_page_types = [ 0 => 'pełne artykuły', 1 => 'wprowadzenia', 2 => 'miniaturki', 3 => 'link', 4 => 'kontakt', 5 => 'kategoria sklepu' ];
|
||||
public static $_sort_types = [
|
||||
0 => 'data dodania - najstarsze na początku',
|
||||
1 => 'data dodania - najnowsze na początku',
|
||||
2 => 'data modyfikacji - rosnąco',
|
||||
3 => 'data mofyfikacji - malejąco',
|
||||
4 => 'ręczne',
|
||||
5 => 'alfabetycznie - A - Z',
|
||||
6 => 'alfabetycznie - Z - A'
|
||||
];
|
||||
|
||||
public static function save_articles_order( $page_id, $articles )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $articles ) )
|
||||
{
|
||||
$mdb -> update( 'pp_articles_pages', [ 'o' => 0 ], [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $articles ); $i++ )
|
||||
{
|
||||
if ( $articles[$i]['item_id'] )
|
||||
{
|
||||
$x++;
|
||||
$mdb -> update( 'pp_articles_pages', [ 'o' => $x ], [ 'AND' => [ 'page_id' => (int)$page_id, 'article_id' => $articles[ $i ]['item_id'] ] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function page_articles( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'article_id, o, status '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'page_id = ' . (int)$page_id . ' AND status != -1 '
|
||||
. 'ORDER BY '
|
||||
. 'o ASC' ) -> fetchAll();
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = \admin\factory\Articles::article_title( $row['article_id'] );
|
||||
$articles[] = $row;
|
||||
}
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function save_pages_order( $menu_id, $pages )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $pages ) )
|
||||
{
|
||||
$mdb -> update( 'pp_pages', [ 'o' => 0 ], [ 'menu_id' => (int)$menu_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $pages ); $i++ )
|
||||
{
|
||||
if ( $pages[$i]['item_id'] )
|
||||
{
|
||||
$pages[$i]['parent_id'] ? $parent_id = $pages[$i]['parent_id'] : $parent_id = 0;
|
||||
|
||||
if ( $pages[$i]['item_id'] && $pages[$i]['depth'] > 1 )
|
||||
{
|
||||
if ( $pages[$i]['depth'] == 2 )
|
||||
$parent_id = null;
|
||||
|
||||
$x++;
|
||||
|
||||
$mdb -> update( 'pp_pages', [ 'o' => $x, 'parent_id' => $parent_id ], [ 'id' => (int)$pages[ $i ]['item_id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function page_delete( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'parent_id' => (int)$page_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_pages', [ 'id' => (int)$page_id ] );
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_pages', 'o' );
|
||||
}
|
||||
|
||||
public static function page_save(
|
||||
$page_id, $title, $seo_link, $meta_title, $meta_description, $meta_keywords, $menu_id, $parent_id, $page_type, $sort_type, $layout_id, $articles_limit, $show_title, $status,
|
||||
$link, $noindex, $start, $page_title, $canonical, $category_id
|
||||
)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$parent_id )
|
||||
$parent_id = null;
|
||||
|
||||
if ( !$page_id )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_pages', [
|
||||
'menu_id' => (int)$menu_id,
|
||||
'page_type' => $page_type,
|
||||
'sort_type' => $sort_type,
|
||||
'articles_limit' => $articles_limit,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'o' => (int)$order,
|
||||
'parent_id' => $parent_id,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'category_id' => ( $category_id and $page_type == 5 ) ? $category_id : null
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( $start )
|
||||
$mdb -> update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int)$id ] );
|
||||
|
||||
if ( $layout_id )
|
||||
$mdb -> insert( 'pp_layouts_pages', [ 'page_id' => (int)$id, 'layout_id' => (int)$layout_id ] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_pages_langs', [
|
||||
'page_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_pages', [
|
||||
'menu_id' => (int)$menu_id,
|
||||
'page_type' => $page_type,
|
||||
'sort_type' => $sort_type,
|
||||
'articles_limit' => $articles_limit,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'parent_id' => $parent_id,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'category_id' => ( $category_id and $page_type == 5 ) ? $category_id : null
|
||||
], [
|
||||
'id' => (int)$page_id
|
||||
] );
|
||||
|
||||
if ( $layout_id )
|
||||
{
|
||||
$mdb -> delete( 'pp_layouts_pages', [ 'page_id' => (int)$page_id ] );
|
||||
$mdb -> insert( 'pp_layouts_pages', [ 'layout_id' => (int)$layout_id, 'page_id' => (int)$page_id ] );
|
||||
}
|
||||
|
||||
if ( $start )
|
||||
$mdb -> update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int)$page_id ] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_pages_langs', 'id', [ 'AND' => [ 'page_id' => $page_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_pages_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_pages_langs', [
|
||||
'page_id' => (int)$page_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'page_title' => $page_title[$key] != '' ? $page_title[$key] : null,
|
||||
'link' => ( $link[$key] and $page_type == 3 ) ? $link[$key] : null,
|
||||
'canonical' => $canonical[$key] != '' ? $canonical[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
self::update_supages_menu_id( $page_id, $menu_id );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $page_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function update_supages_menu_id( $parent_id, $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_pages', [ 'menu_id' => (int)$menu_id ], [ 'parent_id' => $parent_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_pages', [ 'id' ], [ 'parent_id' => $parent_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
self::update_supages_menu_id( $row['id'], $menu_id );
|
||||
}
|
||||
|
||||
public static function generate_seo_link( $title, $page_id, $article_id, $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$seo_link = \S::seo( $title );
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_pages_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'page_id[!]' => (int)$page_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
$seo_link_check = false;
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_articles_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'article_id[!]' => (int)$article_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
$seo_link_check = false;
|
||||
|
||||
while ( !$seo_link_check )
|
||||
{
|
||||
if ( $mdb -> count( 'pp_shop_categories_langs', [ 'AND' => [ 'seo_link' => $seo_link, 'category_id[!]' => (int)$category_id ] ] ) )
|
||||
$seo_link = \S::seo( $title ) . '-' . ( ++$i );
|
||||
else
|
||||
$seo_link_check = true;
|
||||
}
|
||||
|
||||
return $seo_link;
|
||||
}
|
||||
|
||||
public static function menu_delete( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'menu_id' => (int)$menu_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_menus', [ 'id' => (int)$menu_id ] );
|
||||
}
|
||||
|
||||
public static function menu_details( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_menus', '*', [ 'id' => (int)$menu_id ] );
|
||||
}
|
||||
|
||||
public static function menu_save( $menu_id, $name, $status )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$status == 'on' ? $status = 1 : $status = 0;
|
||||
|
||||
if ( !$menu_id )
|
||||
{
|
||||
return $mdb -> insert( 'pp_menus', [
|
||||
'name' => $name,
|
||||
'status' => $status
|
||||
] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_menus', [
|
||||
'name' => $name,
|
||||
'status' => $status
|
||||
], [
|
||||
'id' => (int)$menu_id
|
||||
] );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function menu_lists()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function page_details( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$page = $mdb -> get( 'pp_pages', '*', [ 'id' => (int)$page_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_pages_langs', '*', [ 'page_id' => (int)$page_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$page['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$page['layout_id'] = $mdb -> get( 'pp_layouts_pages', 'layout_id', [ 'page_id' => (int)$page_id ] );
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public static function page_url( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( "SELECT seo_link FROM pp_pages_langs AS ppl, pp_langs AS pl WHERE lang_id = pl.id AND page_id = " . (int)$page_id . " AND seo_link != '' ORDER BY o ASC LIMIT 1" ) -> fetchAll();
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = self::page_title( $article_id );
|
||||
return 's-' . $page_id . '-' . \S::seo( $title );
|
||||
}
|
||||
else
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public static function page_title( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> select( 'pp_pages_langs', [
|
||||
'[><]pp_langs' => [ 'lang_id' => 'id' ]
|
||||
], 'title', [
|
||||
'AND' => [
|
||||
'page_id' => (int)$page_id, 'title[!]' => ''
|
||||
],
|
||||
'ORDER' => [ 'o' => 'ASC' ],
|
||||
'LIMIT' => 1
|
||||
] );
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function page_languages( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_pages_langs', '*',
|
||||
[ 'AND' => [ 'page_id' => (int) $page_id, 'title[!]' => null ] ] );
|
||||
}
|
||||
|
||||
public static function menu_pages( $menu_id, $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_pages',
|
||||
[ 'id', 'menu_id', 'status', 'parent_id', 'start' ],
|
||||
[ 'AND' => [ 'menu_id' => $menu_id, 'parent_id' => $parent_id ], 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = self::page_title( $row['id'] );
|
||||
$row['languages'] = self::page_languages( $row['id'] );
|
||||
$row['subpages'] = self::menu_pages( $menu_id, $row['id'] );
|
||||
|
||||
$pages[] = $row;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
}
|
||||
?>
|
||||
88
autoload/admin/factory/class.Scontainers.php
Normal file
88
autoload/admin/factory/class.Scontainers.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function container_delete( $container_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_scontainers', [ 'id' => (int)$container_id ] );
|
||||
}
|
||||
|
||||
public static function container_save( $container_id, $title, $text, $status, $show_title )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$container_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_scontainers', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_scontainers_langs', [
|
||||
'container_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_scontainers', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'show_title' => $show_title == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$container_id
|
||||
] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_scontainers_langs', 'id', [ 'AND' => [ 'container_id' => $container_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_scontainers_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key],
|
||||
'text' => $text[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_scontainers_langs', [
|
||||
'container_id' => (int)$container_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key],
|
||||
'text' => $text[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $container_id;
|
||||
}
|
||||
}
|
||||
|
||||
public static function container_details( $container_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$container = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int)$container_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'container_id' => (int)$container_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$container['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
104
autoload/admin/factory/class.Settings.php
Normal file
104
autoload/admin/factory/class.Settings.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public static function settings_update( $param, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> delete( 'pp_settings', [ 'param' => $param ] );
|
||||
$mdb -> insert( 'pp_settings', [ 'param' => $param, 'value' => $value ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function settings_save(
|
||||
$firm_name, $firm_adress, $additional_info, $contact_form, $contact_email, $email_host, $email_port, $email_login, $email_password, $google_maps, $facebook_link, $statistic_code, $htaccess,
|
||||
$robots, $shop_bank_account_info, $update, $boot_animation, $newsletter_header, $newsletter_footer, $hotpay_api
|
||||
)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> query( 'TRUNCATE pp_settings' );
|
||||
|
||||
$mdb -> insert( 'pp_settings', [
|
||||
[
|
||||
'param' => 'firm_name',
|
||||
'value' => $firm_name,
|
||||
], [
|
||||
'param' => 'firm_adress',
|
||||
'value' => $firm_adress
|
||||
], [
|
||||
'param' => 'additional_info',
|
||||
'value' => $additional_info
|
||||
], [
|
||||
'param' => 'contact_form',
|
||||
'value' => $contact_form == 'on' ? 1 : 0
|
||||
], [
|
||||
'param' => 'contact_email',
|
||||
'value' => $contact_email
|
||||
], [
|
||||
'param' => 'email_host',
|
||||
'value' => $email_host
|
||||
], [
|
||||
'param' => 'email_port',
|
||||
'value' => $email_port
|
||||
], [
|
||||
'param' => 'email_login',
|
||||
'value' => $email_login
|
||||
], [
|
||||
'param' => 'email_password',
|
||||
'value' => $email_password
|
||||
], [
|
||||
'param' => 'google_maps',
|
||||
'value' => $google_maps
|
||||
], [
|
||||
"param" => 'facebook_link',
|
||||
'value' => $facebook_link
|
||||
], [
|
||||
'param' => 'statistic_code',
|
||||
'value' => $statistic_code
|
||||
], [
|
||||
'param' => 'htaccess',
|
||||
'value' => $htaccess
|
||||
], [
|
||||
'param' => 'robots',
|
||||
'value' => $robots
|
||||
], [
|
||||
'param' => 'shop_bank_account_info',
|
||||
'value' => $shop_bank_account_info
|
||||
], [
|
||||
'param' => 'update',
|
||||
'value' => $update == 'on' ? 1 : 0
|
||||
], [
|
||||
'param' => 'boot_animation',
|
||||
'value' => $boot_animation
|
||||
], [
|
||||
'param' => 'newsletter_header',
|
||||
'value' => $newsletter_header
|
||||
], [
|
||||
'param' => 'newsletter_footer',
|
||||
'value' => $newsletter_footer
|
||||
], [
|
||||
'param' => 'hotpay_api',
|
||||
'value' => $hotpay_api
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
\S::set_message( 'Ustawienia zostały zapisane' );
|
||||
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.' ];
|
||||
}
|
||||
|
||||
public static function settings_details()
|
||||
{
|
||||
global $mdb;
|
||||
$results = $mdb -> select( 'pp_settings', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$settings[ $row['param'] ] = $row['value'];
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
?>
|
||||
263
autoload/admin/factory/class.ShopAttribute.php
Normal file
263
autoload/admin/factory/class.ShopAttribute.php
Normal file
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopAttribute
|
||||
{
|
||||
static public function get_attributes_list()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_attributes', '*', [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
{
|
||||
$attribute = \admin\factory\ShopAttribute::attribute_details( $row['id'] );
|
||||
$attribute['values'] = \admin\factory\ShopAttribute::get_attribute_values( $row['id'] );
|
||||
$attributes[] = $attribute;
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
// pobierz nazwę wartości atrybutu
|
||||
static public function get_attribute_value_by_id( int $value_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_attributes_values_langs', 'name', [ 'AND' => [ 'value_id' => $value_id, 'lang_id' => \front\factory\Languages::default_language() ] ] );
|
||||
}
|
||||
|
||||
//pobierz nazwę atrybutu
|
||||
static public function get_attribute_name_by_id( int $attribute_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_attributes_langs', 'name', [ 'AND' => [ 'attribute_id' => $attribute_id, 'lang_id' => \front\factory\Languages::default_language() ] ] );
|
||||
}
|
||||
|
||||
static public function values_save( int $attribute_id, $names, $values, $ids, $default_value = '', $impact_on_the_price )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$main_language = \front\factory\Languages::default_language();
|
||||
|
||||
if ( \S::is_array_fix( $ids[$main_language] ) )
|
||||
$ids_delete = implode( ',', $ids[$main_language] );
|
||||
else
|
||||
{
|
||||
if ( $ids[$main_language] )
|
||||
$ids_delete = $ids[$main_language];
|
||||
}
|
||||
|
||||
if ( $ids_delete )
|
||||
$mdb -> query( 'DELETE FROM pp_shop_attributes_values WHERE id NOT IN (' . $ids_delete . ') AND attribute_id = ' . $attribute_id );
|
||||
|
||||
for ( $i = 0; $i < count( $names[$main_language] ); ++$i )
|
||||
{
|
||||
if ( $ids[$main_language][$i] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values', [
|
||||
'impact_on_the_price' => $impact_on_the_price[$i] ? \S::normalize_decimal( $impact_on_the_price[$i] ) : null,
|
||||
], [
|
||||
'id' => $ids[$main_language][$i],
|
||||
] );
|
||||
|
||||
\admin\factory\ShopProduct::update_product_price_by_attribute_value_impact( $ids[$main_language][$i], $impact_on_the_price[$i] );
|
||||
|
||||
$langs = \admin\factory\Languages::languages_list();
|
||||
|
||||
foreach ( $langs as $lang )
|
||||
{
|
||||
if ( $names[$lang['id']][$i] and $mdb -> count( 'pp_shop_attributes_values_langs', [ 'AND' => [ 'value_id' => $ids[$main_language][$i], 'lang_id' => $lang['id'] ] ] ) )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values_langs', [
|
||||
'name' => $names[$lang['id']][$i],
|
||||
'value' => $values[$lang['id']][$i] ? $values[$lang['id']][$i] : null,
|
||||
], [
|
||||
'AND' => [
|
||||
'value_id' => $ids[$main_language][$i],
|
||||
'lang_id' => $lang['id'],
|
||||
],
|
||||
] );
|
||||
}
|
||||
elseif ( $names[$lang['id']][$i] and !$mdb -> count( 'pp_shop_attributes_values_langs', [ 'AND' => [ 'value_id' => $ids[$main_language][$i], 'lang_id' => $lang['id'] ] ] ) )
|
||||
{
|
||||
$mdb -> insert('pp_shop_attributes_values_langs', [
|
||||
'value_id' => $ids[$main_language][$i],
|
||||
'lang_id' => $lang['id'],
|
||||
'name' => $names[$lang['id']][$i],
|
||||
'value' => $values[$lang['id']][$i] ? $values[$lang['id']][$i] : null,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $default_value == $i )
|
||||
$default_value_id = $ids[$main_language][$i];
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_attributes_values', [ 'attribute_id' => $attribute_id ] );
|
||||
$value_id = $mdb -> id();
|
||||
|
||||
if ( $value_id )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values', [
|
||||
'impact_on_the_price' => $impact_on_the_price[$i] ? \S::normalize_decimal( $impact_on_the_price[$i] ) : null,
|
||||
], [
|
||||
'id' => $value_id,
|
||||
] );
|
||||
|
||||
if ( $impact_on_the_price[$i] )
|
||||
\admin\factory\ShopProduct::update_product_price_by_attribute_value_impact( $value_id, \S::normalize_decimal( $impact_on_the_price[$i] ) );
|
||||
|
||||
$langs = \admin\factory\Languages::languages_list();
|
||||
if ( \S::is_array_fix( $langs ) ) foreach ( $langs as $lang )
|
||||
{
|
||||
if ( $names[$lang['id']][$i] )
|
||||
{
|
||||
$mdb -> insert('pp_shop_attributes_values_langs', [
|
||||
'value_id' => $value_id,
|
||||
'lang_id' => $lang['id'],
|
||||
'name' => $names[$lang['id']][$i],
|
||||
'value' => $values[$lang['id']][$i] ? $values[$lang['id']][$i] : null,
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( $default_value == $i )
|
||||
$default_value_id = $value_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $default_value_id )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes_values', [ 'is_default' => 0 ], [ 'attribute_id' => $attribute_id ] );
|
||||
$mdb -> update( 'pp_shop_attributes_values', [ 'is_default' => 1 ], [ 'id' => $default_value_id ] );
|
||||
}
|
||||
|
||||
\S::delete_cache();
|
||||
|
||||
return $attribute_id;
|
||||
}
|
||||
|
||||
static public function get_attribute_values( int $attribute_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_attributes_values', [ 'id', 'is_default', 'impact_on_the_price' ], [ 'attribute_id' => $attribute_id ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$results2 = $mdb -> select( 'pp_shop_attributes_values_langs', [ 'lang_id', 'name', 'value' ], [ 'value_id' => $row['id'] ] );
|
||||
if ( \S::is_array_fix( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
$row['languages'][$row2['lang_id']] = $row2;
|
||||
|
||||
$values[] = $row;
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
static public function delete_attribute( int $attribute_id )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( $mdb -> delete( 'pp_shop_attributes', [ 'id' => $attribute_id ] ) )
|
||||
{
|
||||
\Log::save_log( 'Atrybut został usunięty | ID: ' . $attribute_id, $user['id'] );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function attribute_save( int $attribute_id, $name, int $status, int $type, int $o )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$attribute_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_attributes', [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'o' => $o
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( !$id )
|
||||
return false;
|
||||
|
||||
\Log::save_log( 'Dodano nowy atrybut | ID: ' . $id, $user['id'] );
|
||||
|
||||
foreach ( $name as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_attributes_langs', [
|
||||
'attribute_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'name' => $name[$key],
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_attributes', [
|
||||
'status' => $status,
|
||||
'type' => $type,
|
||||
'o' => $o
|
||||
], [
|
||||
'id' => $attribute_id,
|
||||
] );
|
||||
|
||||
\Log::save_log( 'Zaktualizowano atrybut | ID: ' . $attribute_id, $user['id'] );
|
||||
|
||||
foreach ( $name as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_shop_attributes_langs', 'id', [ 'AND' => [ 'attribute_id' => $attribute_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_shop_attributes_langs', [
|
||||
'lang_id' => $key,
|
||||
'name' => $name[$key],
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_shop_attributes_langs', [
|
||||
'attribute_id' => (int)$attribute_id,
|
||||
'lang_id' => $key,
|
||||
'name' => $name[$key],
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $attribute_id;
|
||||
}
|
||||
}
|
||||
|
||||
static public function value_details( int $value_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$value = $mdb -> get( 'pp_shop_attributes_values', '*', [ 'id' => (int) $value_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_attributes_values_langs', [ 'lang_id', 'name', 'value' ], [ 'value_id' => (int) $value_id ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row)
|
||||
$value['languages'][$row['lang_id']] = $row;
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
static public function attribute_details( int $attribute_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$attribute = $mdb -> get( 'pp_shop_attributes', '*', [ 'id' => (int) $attribute_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_attributes_langs', [ 'lang_id', 'name' ], [ 'attribute_id' => (int) $attribute_id ] );
|
||||
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row)
|
||||
$attribute['languages'][$row['lang_id']] = $row;
|
||||
|
||||
return $attribute;
|
||||
}
|
||||
}
|
||||
245
autoload/admin/factory/class.ShopCategory.php
Normal file
245
autoload/admin/factory/class.ShopCategory.php
Normal file
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopCategory
|
||||
{
|
||||
public static $_sort_types = [
|
||||
0 => 'data dodania - najstarsze na początku',
|
||||
1 => 'data dodania - najnowsze na początku',
|
||||
2 => 'data modyfikacji - rosnąco',
|
||||
3 => 'data mofyfikacji - malejąco',
|
||||
4 => 'ręczne',
|
||||
5 => 'alfabetycznie - A - Z',
|
||||
6 => 'alfabetycznie - Z - A'
|
||||
];
|
||||
|
||||
public static function save_product_order( $category_id, $products )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $products ) )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products_categories', [ 'o' => 0 ], [ 'category_id' => (int)$category_id ] );
|
||||
|
||||
for ( $i = 0; $i < count( $products ); $i++ )
|
||||
{
|
||||
if ( $products[$i]['item_id'] )
|
||||
{
|
||||
$x++;
|
||||
$mdb -> update( 'pp_shop_products_categories', [ 'o' => $x ], [ 'AND' => [ 'category_id' => (int)$category_id, 'product_id' => $products[ $i ]['item_id'] ] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function category_products( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> query( 'SELECT '
|
||||
. 'product_id, o, status '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'category_id = :category_id '
|
||||
. 'ORDER BY '
|
||||
. 'o ASC', [
|
||||
':category_id' => $category_id
|
||||
] ) -> fetchAll();
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$row['name'] = \admin\factory\ShopProduct::product_name( $row['product_id'] );
|
||||
$products[] = $row;
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
|
||||
public static function save_categories_order( $categories )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( is_array( $categories ) )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_categories', [ 'o' => 0 ] );
|
||||
|
||||
for ( $i = 0; $i < count( $categories ); $i++ )
|
||||
{
|
||||
if ( $categories[$i]['item_id'] )
|
||||
{
|
||||
$categories[$i]['parent_id'] ? $parent_id = $categories[$i]['parent_id'] : $parent_id = null;
|
||||
|
||||
$x++;
|
||||
$mdb -> update( 'pp_shop_categories', [ 'o' => $x, 'parent_id' => $parent_id ], [ 'id' => (int)$categories[ $i ]['item_id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function category_delete( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_categories', [ 'parent_id' => (int)$category_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_shop_categories', [ 'id' => (int)$category_id ] );
|
||||
}
|
||||
|
||||
public static function category_languages( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_categories_langs', '*', [ 'AND' => [ 'category_id' => (int)$category_id, 'title[!]' => null ] ] );
|
||||
}
|
||||
|
||||
public static function category_title( $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> select( 'pp_shop_categories_langs', [
|
||||
'[><]pp_langs' => [ 'lang_id' => 'id' ]
|
||||
], 'title', [
|
||||
'AND' => [
|
||||
'category_id' => (int)$category_id, 'title[!]' => ''
|
||||
],
|
||||
'ORDER' => [ 'o' => 'ASC' ],
|
||||
'LIMIT' => 1
|
||||
] );
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public static function subcategories( $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_categories', [ 'id' ], [ 'parent_id' => $parent_id, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$categories[] = self::category_details( $row['id'] );
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_shop_categories', 'o' );
|
||||
}
|
||||
|
||||
public static function save( $category_id, $title, $text, $text_hidden, $seo_link, $meta_title, $meta_description, $meta_keywords, $parent_id, $status, $noindex, $category_title, $sort_type, $additional_text, $view_subcategories )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$parent_id )
|
||||
$parent_id = null;
|
||||
|
||||
if ( !$category_id )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_shop_categories', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'o' => (int)$order,
|
||||
'parent_id' => $parent_id,
|
||||
'sort_type' => $sort_type,
|
||||
'view_subcategories' => $view_subcategories == 'on' ? 1 : 0,
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_categories_langs', [
|
||||
'category_id' => (int)$id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'text_hidden' => $text_hidden[$key] != '' ? $text_hidden[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'category_title' => $category_title[$key] != '' ? $category_title[$key] : null,
|
||||
'additional_text' => $additional_text[$key] != '' ? $additional_text[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_categories', [
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'parent_id' => $parent_id,
|
||||
'sort_type' => $sort_type,
|
||||
'view_subcategories' => $view_subcategories == 'on' ? 1 : 0,
|
||||
], [
|
||||
'id' => (int)$category_id
|
||||
] );
|
||||
|
||||
foreach ( $title as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_shop_categories_langs', 'id', [ 'AND' => [ 'category_id' => $category_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_shop_categories_langs', [
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'text_hidden' => $text_hidden[$key] != '' ? $text_hidden[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'category_title' => $category_title[$key] != '' ? $category_title[$key] : null,
|
||||
'additional_text' => $additional_text[$key] != '' ? $additional_text[$key] : null
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_shop_categories_langs', [
|
||||
'category_id' => (int)$category_id,
|
||||
'lang_id' => $key,
|
||||
'title' => $title[$key] != '' ? $title[$key] : null,
|
||||
'text' => $text[$key] != '' ? $text[$key] : null,
|
||||
'text_hidden' => $text_hidden[$key] != '' ? $text_hidden[$key] : null,
|
||||
'meta_description' => $meta_description[$key] != '' ? $meta_description[$key] : null,
|
||||
'meta_keywords' => $meta_keywords[$key] != '' ? $meta_keywords[$key] : null,
|
||||
'meta_title' => $meta_title[$key] != '' ? $meta_title[$key] : null,
|
||||
'seo_link' => \S::seo( $seo_link[$key] ) != '' ? \S::seo( $seo_link[$key] ) : null,
|
||||
'noindex' => $noindex[$key],
|
||||
'category_title' => $category_title[$key] != '' ? $category_title[$key] : null,
|
||||
'additional_text' => $additional_text[$key] != '' ? $additional_text[$key] : null
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $category_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function category_details( $category_id = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$category = $mdb -> get( 'pp_shop_categories', '*', [ 'id' => (int)$category_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_categories_langs', '*', [ 'category_id' => (int)$category_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$category['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
17
autoload/admin/factory/class.ShopClients.php
Normal file
17
autoload/admin/factory/class.ShopClients.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopClients
|
||||
{
|
||||
public static function get_order_all_info($name, $surname, $email)
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb->select('pp_shop_orders', '*', [
|
||||
'client_name' => $name,
|
||||
'client_surname' => $surname,
|
||||
'client_email' => $email
|
||||
]);
|
||||
|
||||
return $results;}
|
||||
}
|
||||
?>
|
||||
54
autoload/admin/factory/class.ShopCoupon.php
Normal file
54
autoload/admin/factory/class.ShopCoupon.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopCoupon
|
||||
{
|
||||
static public function details( int $coupon_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_coupon', '*', [ 'id' => $coupon_id ] );
|
||||
}
|
||||
|
||||
public static function coupon_delete( $coupon_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_shop_coupon', [ 'id' => $coupon_id ] );
|
||||
}
|
||||
|
||||
public static function save( $coupon_id, $name, $status, $send, $used, $type, $amount, $one_time, $include_discounted_product, $categories )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$coupon_id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_shop_coupon', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'used' => $used,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'one_time' => $one_time,
|
||||
'send' => $send,
|
||||
'include_discounted_product' => $include_discounted_product,
|
||||
'categories' => $categories
|
||||
] ) )
|
||||
return $mdb -> id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_coupon', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'used' => $used,
|
||||
'type' => $type,
|
||||
'amount' => $amount,
|
||||
'one_time' => $one_time,
|
||||
'send' => $send,
|
||||
'include_discounted_product' => $include_discounted_product,
|
||||
'categories' => $categories
|
||||
], [
|
||||
'id' => $coupon_id
|
||||
] );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
24
autoload/admin/factory/class.ShopOrder.php
Normal file
24
autoload/admin/factory/class.ShopOrder.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopOrder
|
||||
{
|
||||
static public function next_order_id( int $order_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$order_id )
|
||||
return false;
|
||||
|
||||
return $mdb -> get( 'pp_shop_orders', 'id', [ 'id[>]' => $order_id, 'ORDER' => [ 'id' => 'ASC' ], 'LIMIT' => 1 ] );
|
||||
}
|
||||
|
||||
static public function prev_order_id( int $order_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$order_id )
|
||||
return false;
|
||||
|
||||
return $mdb -> get( 'pp_shop_orders', 'id', [ 'id[<]' => $order_id, 'ORDER' => [ 'id' => 'DESC' ], 'LIMIT' => 1 ] );
|
||||
}
|
||||
}
|
||||
10
autoload/admin/factory/class.ShopPaymentMethod.php
Normal file
10
autoload/admin/factory/class.ShopPaymentMethod.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function payments_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_payment_methods', '*', [ 'ORDER' => [ 'name' => 'ASC'] ] );
|
||||
}
|
||||
}
|
||||
80
autoload/admin/factory/class.ShopProducer.php
Normal file
80
autoload/admin/factory/class.ShopProducer.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
class ShopProducer
|
||||
{
|
||||
static public function all()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_producer', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
static public function delete( int $producer_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_shop_producer', [ 'id' => $producer_id ] );
|
||||
}
|
||||
|
||||
static public function save( $producer_id, $name, int $status, $img, $description, $meta_title )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$producer_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_producer', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'img' => $img
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
foreach ( $description as $key => $val )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_producer_lang', [
|
||||
'producer_id' => $id,
|
||||
'lang_id' => $key,
|
||||
'description' => $val,
|
||||
'meta_title' => $meta_title[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_producer', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'img' => $img
|
||||
], [
|
||||
'id' => (int) $producer_id
|
||||
] );
|
||||
|
||||
foreach ( $description as $key => $val )
|
||||
{
|
||||
if ( $translation_id = $mdb -> get( 'pp_shop_producer_lang', 'id', [ 'AND' => [ 'producer_id' => $producer_id, 'lang_id' => $key ] ] ) )
|
||||
$mdb -> update( 'pp_shop_producer_lang', [
|
||||
'description' => $val,
|
||||
'meta_title' => $meta_title[$key]
|
||||
], [
|
||||
'id' => $translation_id
|
||||
] );
|
||||
else
|
||||
$mdb -> insert( 'pp_shop_producer_lang', [
|
||||
'producer_id' => $producer_id,
|
||||
'lang_id' => $key,
|
||||
'description' => $val,
|
||||
'meta_title' => $meta_title[$key]
|
||||
] );
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_dir( '../temp/' );
|
||||
return $producer_id;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
1540
autoload/admin/factory/class.ShopProduct.php
Normal file
1540
autoload/admin/factory/class.ShopProduct.php
Normal file
File diff suppressed because it is too large
Load Diff
68
autoload/admin/factory/class.ShopProductSet.php
Normal file
68
autoload/admin/factory/class.ShopProductSet.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopProductSet
|
||||
{
|
||||
// zapisywanie kompletu produktów
|
||||
static public function save( int $set_id, string $name, string $status, $set_products_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$set_id )
|
||||
{
|
||||
$mdb -> insert('pp_shop_product_sets', [
|
||||
'name' => $name,
|
||||
'status' => 'on' === $status ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $set_products_id == null )
|
||||
$not_in = [ 0 ];
|
||||
elseif ( !is_array( $set_products_id ) )
|
||||
$not_in = [ 0, $set_products_id ];
|
||||
elseif ( is_array( $set_products_id ) )
|
||||
$not_in = $set_products_id;
|
||||
|
||||
foreach ( $not_in as $product_id )
|
||||
{
|
||||
if ( $product_id != 0 )
|
||||
$mdb -> insert( 'pp_shop_product_sets_products', [ 'set_id' => $id, 'product_id' => $product_id ] );
|
||||
}
|
||||
|
||||
\S::delete_dir('../temp/');
|
||||
\S::delete_dir('../thumbs/');
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update('pp_shop_product_sets', [
|
||||
'name' => $name,
|
||||
'status' => 'on' === $status ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$set_id,
|
||||
] );
|
||||
|
||||
$mdb -> delete( 'pp_shop_product_sets_products', [ 'set_id' => $set_id ] );
|
||||
|
||||
if ( $set_products_id == null )
|
||||
$not_in = [ 0 ];
|
||||
elseif ( !is_array( $set_products_id ) )
|
||||
$not_in = [ 0, $set_products_id ];
|
||||
elseif ( is_array( $set_products_id ) )
|
||||
$not_in = $set_products_id;
|
||||
|
||||
foreach ( $not_in as $product_id )
|
||||
{
|
||||
if ( $product_id != 0 )
|
||||
$mdb -> insert( 'pp_shop_product_sets_products', [ 'set_id' => $set_id, 'product_id' => $product_id ] );
|
||||
}
|
||||
|
||||
\S::delete_dir('../temp/');
|
||||
\S::delete_dir('../thumbs/');
|
||||
|
||||
return $set_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
autoload/admin/factory/class.ShopPromotion.php
Normal file
55
autoload/admin/factory/class.ShopPromotion.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopPromotion
|
||||
{
|
||||
static public function promotion_details( int $promotion_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_promotion', '*', [ 'id' => $promotion_id ] );
|
||||
}
|
||||
|
||||
static public function save( $promotion_id, $name, $status, $condition_type, $discount_type, $amount, $date_to, $categories, $condition_categories, $include_coupon, $include_product_promo, $min_product_count, $price_cheapest_product )
|
||||
{
|
||||
global $mdb, $user;
|
||||
|
||||
if ( !$promotion_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_promotion', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'condition_type' => $condition_type,
|
||||
'discount_type' => $discount_type,
|
||||
'amount' => $amount,
|
||||
'date_to' => $date_to != '' ? $date_to : null,
|
||||
'categories' => $categories != null ? ( is_array( $categories ) ? json_encode( $categories ) : json_encode( [ $categories ] ) ) : null,
|
||||
'condition_categories' => $condition_categories != null ? ( is_array( $condition_categories ) ? json_encode( $condition_categories ) : json_encode( [ $condition_categories ] ) ) : null,
|
||||
'include_coupon' => $include_coupon,
|
||||
'include_product_promo' => $include_product_promo,
|
||||
'min_product_count' => $min_product_count ? $min_product_count : null,
|
||||
'price_cheapest_product' => $price_cheapest_product ? $price_cheapest_product : null
|
||||
] );
|
||||
|
||||
return $mdb -> id();
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_promotion', [
|
||||
'name' => $name,
|
||||
'status' => $status,
|
||||
'condition_type' => $condition_type,
|
||||
'discount_type' => $discount_type,
|
||||
'amount' => $amount,
|
||||
'date_to' => $date_to != '' ? $date_to : null,
|
||||
'categories' => $categories != null ? ( is_array( $categories ) ? json_encode( $categories ) : json_encode( [ $categories ] ) ) : null,
|
||||
'condition_categories' => $condition_categories != null ? ( is_array( $condition_categories ) ? json_encode( $condition_categories ) : json_encode( [ $condition_categories ] ) ) : null,
|
||||
'include_coupon' => $include_coupon,
|
||||
'include_product_promo' => $include_product_promo,
|
||||
'min_product_count' => $min_product_count ? $min_product_count : null,
|
||||
'price_cheapest_product' => $price_cheapest_product ? $price_cheapest_product : null
|
||||
], [
|
||||
'id' => $promotion_id
|
||||
] );
|
||||
return $promotion_id;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
autoload/admin/factory/class.ShopStatuses.php
Normal file
26
autoload/admin/factory/class.ShopStatuses.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class ShopStatuses {
|
||||
// get_status
|
||||
public static function get_status( $id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', '*', [ 'id' => $id ] );
|
||||
}
|
||||
|
||||
// status_save
|
||||
public static function status_save( $status_id, $color, $apilo_status_id, $sellasi_status_id, $baselinker_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_shop_statuses', [
|
||||
'color' => $color,
|
||||
'apilo_status_id' => $apilo_status_id ? $apilo_status_id : null,
|
||||
'sellasist_status_id' => $sellasi_status_id ? $sellasi_status_id : null,
|
||||
'baselinker_status_id' => $baselinker_status_id ? $baselinker_status_id : null
|
||||
], [ 'id' => $status_id ] );
|
||||
|
||||
return $status_id;
|
||||
}
|
||||
}
|
||||
108
autoload/admin/factory/class.ShopTransport.php
Normal file
108
autoload/admin/factory/class.ShopTransport.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
class ShopTransport
|
||||
{
|
||||
public static function lowest_transport_price( $wp ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_transports', 'cost', [ 'AND' => [ 'status' => 1, 'id' => [ 2, 4, 6, 8 ], 'max_wp[>=]' => $wp ], 'ORDER' => [ 'cost' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $sellasist_shipment_method_id, $delivery_free )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$transport_id )
|
||||
{
|
||||
if ( $default == 'on' )
|
||||
$mdb -> update( 'pp_shop_transports', [ 'default' => '0' ] );
|
||||
|
||||
$mdb -> insert( 'pp_shop_transports', [
|
||||
'name' => $name,
|
||||
'name_visible' => $name_visible,
|
||||
'description' => $description,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'default' => $default == 'on' ? 1 : 0,
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( is_array( $payment_methods ) ) foreach ( $payment_methods as $payment_method )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_method,
|
||||
'id_transport' => (int)$id
|
||||
] );
|
||||
}
|
||||
else if ( $payment_methods )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_methods,
|
||||
'id_transport' => (int)$id
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $default == 'on' )
|
||||
$mdb -> update( 'pp_shop_transports', [ 'default' => '0' ] );
|
||||
|
||||
$mdb -> update( 'pp_shop_transports', [
|
||||
'name' => $name,
|
||||
'name_visible' => $name_visible,
|
||||
'description' => $description,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'default' => $default == 'on' ? 1 : 0,
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $transport_id
|
||||
] );
|
||||
|
||||
$mdb -> delete( 'pp_shop_transport_payment_methods', [ 'id_transport' => (int)$transport_id ] );
|
||||
|
||||
if ( is_array( $payment_methods ) ) foreach ( $payment_methods as $payment_method )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_method,
|
||||
'id_transport' => (int)$transport_id
|
||||
] );
|
||||
}
|
||||
else if ( $payment_methods )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_transport_payment_methods', [
|
||||
'id_payment_method' => (int)$payment_methods,
|
||||
'id_transport' => (int)$transport_id
|
||||
] );
|
||||
}
|
||||
|
||||
\S::delete_dir( '../temp/' );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static function transport_details( $transport_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$transport = $mdb -> get( 'pp_shop_transports', '*', [ 'id' => $transport_id ] );
|
||||
$transport['payment_methods'] = $mdb -> select( 'pp_shop_transport_payment_methods', 'id_payment_method', [ 'id_transport' => $transport_id ] );
|
||||
|
||||
return $transport;
|
||||
}
|
||||
}
|
||||
105
autoload/admin/factory/class.Update.php
Normal file
105
autoload/admin/factory/class.Update.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Update
|
||||
{
|
||||
public static function update()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
\S::delete_session( 'new-version' );
|
||||
|
||||
$versions = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'] );
|
||||
$versions = explode( PHP_EOL, $versions );
|
||||
|
||||
foreach ( $versions as $ver )
|
||||
{
|
||||
$ver = trim( $ver );
|
||||
if ( (float)$ver > (float)\S::get_version() )
|
||||
{
|
||||
if ( strlen( $ver ) == 5 )
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||
else
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 1 ) . 0;
|
||||
|
||||
$file = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '.zip' );
|
||||
|
||||
$dlHandler = fopen( 'update.zip' , 'w' );
|
||||
if ( !fwrite( $dlHandler, $file ) )
|
||||
return false;
|
||||
fclose( $dlHandler );
|
||||
|
||||
if ( !file_exists( 'update.zip' ) )
|
||||
return false;
|
||||
else
|
||||
{
|
||||
/* aktualizacja bazy danych */
|
||||
$sql = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt' );
|
||||
$sql = explode( PHP_EOL, $sql );
|
||||
if ( is_array( $sql ) and !empty( $sql ) ) foreach ( $sql as $query )
|
||||
{
|
||||
if ( $sql )
|
||||
$result = $mdb -> query( $query );
|
||||
}
|
||||
|
||||
/* usuwanie zbędnych plików */
|
||||
$lines = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt' );
|
||||
$lines = explode( PHP_EOL, $lines );
|
||||
if ( is_array( $lines ) ) foreach ( $lines as $line )
|
||||
{
|
||||
if ( strpos( $line, 'F: ' ) !== false )
|
||||
{
|
||||
$file = substr( $line, 3, strlen( $line ) );
|
||||
if ( file_exists( $file ) )
|
||||
unlink( $file );
|
||||
}
|
||||
|
||||
if ( strpos( $line, 'D: ' ) !== false )
|
||||
{
|
||||
$dir = substr( $line, 3, strlen( $line ) );
|
||||
if ( is_dir( $dir ) )
|
||||
\S::delete_dir( $dir );
|
||||
}
|
||||
}
|
||||
|
||||
/* wgrywanie nowych plików */
|
||||
$file_name = 'update.zip';
|
||||
|
||||
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
|
||||
$path = substr( $path, 0, strlen( $path ) - 5 );
|
||||
$zip = new \ZipArchive;
|
||||
$res = $zip -> open( $file_name );
|
||||
if ( $res === TRUE )
|
||||
{
|
||||
$zip -> extractTo( $path );
|
||||
$zip -> close();
|
||||
unlink( $file_name );
|
||||
}
|
||||
|
||||
$updateThis = fopen( '../libraries/version.ini', 'w' );
|
||||
fwrite( $updateThis, $ver );
|
||||
fclose( $updateThis );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function update0197()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_order_products', [ 'id', 'product_id' ], [ 'parent_product_id' => null ] );
|
||||
foreach ( $rows as $row )
|
||||
{
|
||||
$parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $row['product_id'] ] );
|
||||
if ( $parent_id )
|
||||
$mdb -> update( 'pp_shop_order_products', [ 'parent_product_id' => $parent_id ], [ 'id' => $row['id'] ] );
|
||||
else
|
||||
$mdb -> update( 'pp_shop_order_products', [ 'parent_product_id' => $row['product_id'] ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_updates', [ 'done' => 1 ], [ 'name' => 'update0197' ] );
|
||||
}
|
||||
}
|
||||
110
autoload/admin/factory/class.Users.php
Normal file
110
autoload/admin/factory/class.Users.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Users
|
||||
{
|
||||
public static function user_delete( $user_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_users', [ 'id' => (int)$user_id ] );
|
||||
}
|
||||
|
||||
public static function user_details( $user_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_users', '*', [ 'id' => (int)$user_id ] );
|
||||
}
|
||||
|
||||
public static function user_save( $user_id = '', $login, $status, $password, $password_re, $admin )
|
||||
{
|
||||
global $mdb, $lang, $config;
|
||||
|
||||
if ( !$user_id )
|
||||
{
|
||||
if ( strlen( $password ) < 5 )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasło jest zbyt krótkie.' ];
|
||||
|
||||
if ( $password != $password_re )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasła są różne' ];
|
||||
|
||||
if ( $mdb -> insert( 'pp_users', [
|
||||
'login' => $login,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'admin' => $admin,
|
||||
'password' => md5( $password )
|
||||
] ) )
|
||||
{
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Użytkownik został zapisany.' ];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $password and strlen( $password ) < 5 )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasło jest zbyt krótkie.' ];
|
||||
|
||||
if ( $password and $password != $password_re )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podane hasła są różne' ];
|
||||
|
||||
if ( $password )
|
||||
$mdb -> update( 'pp_users', [
|
||||
'password' => md5( $password )
|
||||
], [
|
||||
'id' => (int)$user_id
|
||||
] );
|
||||
|
||||
$mdb -> update( 'pp_users', [
|
||||
'login' => $login,
|
||||
'admin' => $admin,
|
||||
'status' => $status == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => (int)$user_id
|
||||
] );
|
||||
|
||||
return $response = [ 'status' => 'ok', 'msg' => 'Uzytkownik został zapisany.' ];
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_login( $login, $user_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> get( 'pp_users', 'login', [ 'AND' => [ 'login' => $login, 'id[!]' => (int)$user_id ] ] ) )
|
||||
return $response = [ 'status' => 'error', 'msg' => 'Podany login jest już zajęty.' ];
|
||||
|
||||
return $response = [ 'status' => 'ok' ];
|
||||
}
|
||||
|
||||
public static function logon( $login, $password )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$mdb -> get( 'pp_users', '*', [ 'login' => $login ] ) )
|
||||
return 0;
|
||||
|
||||
if ( !$mdb -> get( 'pp_users', '*', [ 'AND' => [ 'login' => $login, 'status' => 1, 'error_logged_count[<]' => 5 ] ] ) )
|
||||
return -1;
|
||||
|
||||
if ( $mdb -> get( 'pp_users', '*', [ 'AND' => [ 'login' => $login, 'status' => 1, 'password' => md5( $password ) ] ] ) )
|
||||
{
|
||||
$mdb -> update( 'pp_users', [ 'last_logged' => date( 'Y-m-d H:i:s' ), 'error_logged_count' => 0 ], [ 'login' => $login ] );
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_users', [ 'last_error_logged' => date( 'Y-m-d H:i:s' ), 'error_logged_count[+]' => 1 ], [ 'login' => $login ] );
|
||||
if ( $mdb -> get( 'pp_users', 'error_logged_count', [ 'login' => $login ] ) >= 5 )
|
||||
{
|
||||
$mdb -> update( 'pp_users', [ 'status' => 0 ], [ 'login' => $login ] );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function details( $login )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_users', '*', [ 'login' => $login ] );
|
||||
}
|
||||
}
|
||||
?>
|
||||
38
autoload/admin/view/class.Articles.php
Normal file
38
autoload/admin/view/class.Articles.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Articles
|
||||
{
|
||||
public static function browse_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'articles/articles-browse-list' );
|
||||
}
|
||||
|
||||
public static function subpages_list( $pages, $article_pages, $parent_id = 0, $step = 1 )
|
||||
{
|
||||
$tpl = new \Tpl();
|
||||
$tpl -> pages = $pages;
|
||||
$tpl -> parent_id = $parent_id;
|
||||
$tpl -> step = $step;
|
||||
$tpl -> article_pages = $article_pages;
|
||||
return $tpl -> render( 'articles/subpages-list' );
|
||||
}
|
||||
|
||||
public static function articles_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'articles/articles-list' );
|
||||
}
|
||||
|
||||
public static function article_edit( $article, $menus, $languages, $layouts )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> article = $article;
|
||||
$tpl -> menus = $menus;
|
||||
$tpl -> languages = $languages;
|
||||
$tpl -> layouts = $layouts;
|
||||
return $tpl -> render( 'articles/article-edit' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
11
autoload/admin/view/class.ArticlesArchive.php
Normal file
11
autoload/admin/view/class.ArticlesArchive.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class ArticlesArchive
|
||||
{
|
||||
public static function articles_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'articles/articles-archive-list' );
|
||||
}
|
||||
}
|
||||
20
autoload/admin/view/class.Banners.php
Normal file
20
autoload/admin/view/class.Banners.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Banners
|
||||
{
|
||||
public static function banners_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'banners/banners-list' );
|
||||
}
|
||||
|
||||
public static function banner_edit( $banner, $languages )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> banner = $banner;
|
||||
$tpl -> languages = $languages;
|
||||
return $tpl -> render( 'banners/banner-edit' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
12
autoload/admin/view/class.FileManager.php
Normal file
12
autoload/admin/view/class.FileManager.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class FileManager
|
||||
{
|
||||
public function filemanager()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'filemanager/filemanager' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
34
autoload/admin/view/class.Languages.php
Normal file
34
autoload/admin/view/class.Languages.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?
|
||||
namespace admin\view;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function translation_edit( $translation, $languages )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> languages = $languages;
|
||||
$tpl -> translation = $translation;
|
||||
return $tpl -> render( 'languages/translation-edit' );
|
||||
}
|
||||
|
||||
public static function language_edit( $language, $order )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> language = $language;
|
||||
$tpl -> order = $order;
|
||||
return $tpl -> render( 'languages/language-edit' );
|
||||
}
|
||||
|
||||
public static function translations_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'languages/translations-list' );
|
||||
}
|
||||
|
||||
public static function languages_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'languages/languages-list' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
21
autoload/admin/view/class.Layouts.php
Normal file
21
autoload/admin/view/class.Layouts.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Layouts
|
||||
{
|
||||
public static function subpages_list( $pages, $layout_pages, $parent_id = null, $step = 1 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> pages = $pages;
|
||||
$tpl -> step = $step;
|
||||
$tpl -> layout_pages = $layout_pages;
|
||||
return $tpl -> render( 'layouts/subpages-list' );
|
||||
}
|
||||
|
||||
public static function layouts_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'layouts/layouts-list' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
55
autoload/admin/view/class.Newsletter.php
Normal file
55
autoload/admin/view/class.Newsletter.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function emails_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'newsletter/emails-list' );
|
||||
}
|
||||
|
||||
public static function preview( $articles, $settings, $template, $dates = '' )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> articles = $articles;
|
||||
$tpl -> settings = $settings;
|
||||
$tpl -> template = $template;
|
||||
$tpl -> dates = $dates;
|
||||
return $tpl -> render( 'newsletter/preview' );
|
||||
}
|
||||
|
||||
public static function prepare( $templates )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> templates = $templates;
|
||||
return $tpl -> render( 'newsletter/prepare' );
|
||||
}
|
||||
|
||||
public static function settings( $settings )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> settings = $settings;
|
||||
return $tpl -> render( 'newsletter/settings' );
|
||||
}
|
||||
|
||||
public static function email_templates_user()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'newsletter/email-templates-user' );
|
||||
}
|
||||
|
||||
public static function email_templates_admin()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'newsletter/email-templates-admin' );
|
||||
}
|
||||
|
||||
public static function email_template_edit($template)
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> email_template = $template;
|
||||
return $tpl -> render( 'newsletter/email-template-edit' );
|
||||
}
|
||||
}
|
||||
|
||||
18
autoload/admin/view/class.Page.php
Normal file
18
autoload/admin/view/class.Page.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Page {
|
||||
|
||||
public static function show()
|
||||
{
|
||||
global $user;
|
||||
|
||||
if ( !$user || !$user['admin'] )
|
||||
return \admin\view\Users::login_form();
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> content = \admin\Site::route();
|
||||
return $tpl -> render( 'site/main-layout' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
21
autoload/admin/view/class.PagePanel.php
Normal file
21
autoload/admin/view/class.PagePanel.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class PagePanel {
|
||||
|
||||
public static function show( $add = false, $save = false, $cancel = false, $title = '', $form = 'formularz', $back = false, $update = false, $save_ajax = false, $delete_ajax = false )
|
||||
{
|
||||
$tpl = new \Tpl();
|
||||
$tpl -> _add = $add;
|
||||
$tpl -> _save = $save;
|
||||
$tpl -> _cancel = $cancel;
|
||||
$tpl -> _id_form = $form;
|
||||
$tpl -> _title = $title;
|
||||
$tpl -> _back = $back;
|
||||
$tpl -> _update = $update;
|
||||
$tpl -> _save_ajax = $save_ajax;
|
||||
$tpl -> _delete_ajax = $delete_ajax;
|
||||
return $tpl -> render( 'other/page-panel' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
37
autoload/admin/view/class.Pages.php
Normal file
37
autoload/admin/view/class.Pages.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?
|
||||
namespace admin\view;
|
||||
|
||||
class Pages
|
||||
{
|
||||
public static function subpages_browse_list( $pages, $parent_id = null, $step = 1 )
|
||||
{
|
||||
$tpl = new \Tpl();
|
||||
$tpl -> pages = $pages;
|
||||
$tpl -> parent_id = $parent_id;
|
||||
$tpl -> step = $step;
|
||||
return $tpl -> render( 'pages/subpages-browse-list' );
|
||||
}
|
||||
|
||||
public static function browse_list( $menus )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> menus = $menus;
|
||||
return $tpl -> render( 'pages/pages-browse-list' );
|
||||
}
|
||||
|
||||
public static function page_articles( $page_id, $articles )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> page_id = $page_id;
|
||||
$tpl -> articles = $articles;
|
||||
return $tpl -> render( 'pages/page-articles' );
|
||||
}
|
||||
|
||||
public static function menu_edit( $menu )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> menu = $menu;
|
||||
return $tpl -> render( 'pages/menu-edit' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
20
autoload/admin/view/class.Scontainers.php
Normal file
20
autoload/admin/view/class.Scontainers.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function container_edit( $container, $languages )
|
||||
{
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> container = $container;
|
||||
$tpl -> languages = $languages;
|
||||
return $tpl -> render( 'scontainers/container-edit' );
|
||||
}
|
||||
|
||||
public static function containers_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'scontainers/containers-list' );
|
||||
}
|
||||
}
|
||||
13
autoload/admin/view/class.Settings.php
Normal file
13
autoload/admin/view/class.Settings.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?
|
||||
namespace admin\view;
|
||||
|
||||
class Settings
|
||||
{
|
||||
public static function view( $settings )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> settings = $settings;
|
||||
return $tpl -> render( 'settings/settings' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
13
autoload/admin/view/class.ShopAttribute.php
Normal file
13
autoload/admin/view/class.ShopAttribute.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
class ShopAttribute
|
||||
{
|
||||
public static function values_edit( $attribute, $values, $languages )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> attribute = $attribute;
|
||||
$tpl -> values = $values;
|
||||
$tpl -> languages = $languages;
|
||||
return $tpl -> render( 'shop-attribute/values-edit' );
|
||||
}
|
||||
}
|
||||
21
autoload/admin/view/class.ShopCategory.php
Normal file
21
autoload/admin/view/class.ShopCategory.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
class ShopCategory
|
||||
{
|
||||
public static function category_edit( $category, $pid = '', $languages )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> languages = $languages;
|
||||
$tpl -> pid = $pid;
|
||||
$tpl -> category = $category;
|
||||
return $tpl -> render( 'shop-category/category-edit' );
|
||||
}
|
||||
|
||||
public static function subcategories_list( $categories_list, $level )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> level = $level;
|
||||
$tpl -> categories = $categories_list;
|
||||
return $tpl -> render( 'shop-category/subcategories-list' );
|
||||
}
|
||||
}
|
||||
6
autoload/admin/view/class.ShopPaymentMethod.php
Normal file
6
autoload/admin/view/class.ShopPaymentMethod.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
|
||||
}
|
||||
11
autoload/admin/view/class.ShopProduct.php
Normal file
11
autoload/admin/view/class.ShopProduct.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class ShopProduct
|
||||
{
|
||||
public static function products_list()
|
||||
{
|
||||
$tpl = new \Tpl();
|
||||
return $tpl -> render('shop-product/products-list');
|
||||
}
|
||||
}
|
||||
5
autoload/admin/view/class.ShopTransport.php
Normal file
5
autoload/admin/view/class.ShopTransport.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
class ShopTransport
|
||||
{
|
||||
}
|
||||
13
autoload/admin/view/class.Update.php
Normal file
13
autoload/admin/view/class.Update.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Update
|
||||
{
|
||||
public static function main_view()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> ver = \S::get_version();
|
||||
$tpl -> new_ver = \S::get_new_version();
|
||||
return $tpl -> render( 'update/main-view' );
|
||||
}
|
||||
}
|
||||
25
autoload/admin/view/class.Users.php
Normal file
25
autoload/admin/view/class.Users.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace admin\view;
|
||||
|
||||
class Users
|
||||
{
|
||||
public static function login_form()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'site/unlogged-layout' );
|
||||
}
|
||||
|
||||
public static function users_list()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'users/users-list' );
|
||||
}
|
||||
|
||||
public static function user_edit( $user )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> user = $user;
|
||||
return $tpl -> render( 'users/user-edit' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
219
autoload/class.Article.php
Normal file
219
autoload/class.Article.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
class Article implements \ArrayAccess
|
||||
{
|
||||
public function __construct( $article_id, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] );
|
||||
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang_id ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( $row['copy_from'] )
|
||||
{
|
||||
$results2 = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $row['copy_from'] ] ] );
|
||||
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
$this -> language = $row2;
|
||||
}
|
||||
else
|
||||
$this -> language = $row;
|
||||
|
||||
preg_match_all( \front\view\Site::container_pattern, $this -> language['entry'], $container_list );
|
||||
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
|
||||
{
|
||||
$container_list_tmp = explode( ':', $container_list_tmp );
|
||||
$this -> language['entry'] = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $this -> language['entry'] );
|
||||
}
|
||||
|
||||
preg_match_all( \front\view\Site::container_pattern, $this -> language['text'], $container_list );
|
||||
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
|
||||
{
|
||||
$container_list_tmp = explode( ':', $container_list_tmp );
|
||||
$this -> language['text'] = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $this -> language['text'] );
|
||||
}
|
||||
}
|
||||
|
||||
$this -> images = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
||||
$this -> files = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
|
||||
$this -> pages = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
$this -> tags = $mdb -> select( 'pp_tags', [ '[><]pp_articles_tags' => [ 'id' => 'tag_id' ] ], 'name', [ 'article_id' => (int)$article_id ] );
|
||||
$results = $mdb -> select( 'pp_articles_additional_params', [ '[><]pp_articles_additional_values' => [ 'id' => 'param_id' ] ], [ 'name', 'value', 'language_id' ], [ 'article_id' => (int)$article_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( !$row['language_id'] )
|
||||
$params[ $row['name'] ] = $row['value'];
|
||||
else
|
||||
$params[ $row['name'] ][$row['language_id']] = $row['value'];
|
||||
}
|
||||
$this -> params = $params;
|
||||
}
|
||||
|
||||
public function get_from_cache( $article_id, $lang_id )
|
||||
{
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheKey = "\Article::get_from_cache:$article_id:$lang_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$article = new \Article( $article_id, $lang_id );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $article );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public function updateView()
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles', [ 'views[+]' => 1 ], [ 'id' => $this -> id ] );
|
||||
}
|
||||
|
||||
static public function newsList( $articles )
|
||||
{
|
||||
return \Tpl::view( 'articles/news-list', [
|
||||
'articles' => $articles
|
||||
] );
|
||||
}
|
||||
|
||||
// pobierz najczęściej wyświtlane artykuły
|
||||
static public function getTopNews( $page_id, $limit = 6, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheKey = "\Article::getTopNews:$page_id:$limit:$lang_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$articles_id = $mdb -> query( 'SELECT * FROM ( '
|
||||
. 'SELECT '
|
||||
. 'a.id, date_add, views, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN title '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = al.copy_from AND article_id = a.id '
|
||||
. ') '
|
||||
. 'END ) AS title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.title IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. 'q1.views DESC '
|
||||
. 'LIMIT '
|
||||
. '0, ' . (int)$limit ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $articles_id );
|
||||
}
|
||||
else
|
||||
{
|
||||
$articles_id = unserialize( $objectData );
|
||||
}
|
||||
|
||||
if ( \S::is_array_fix( $articles_id ) ) foreach ( $articles_id as $article_tmp )
|
||||
{
|
||||
$article = \Article::get_from_cache( $article_tmp['id'], $lang_id );
|
||||
$articles[] = $article;
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
static public function getNews( $page_id, $limit = 6, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$articles_id = \Cache::fetch( "getNews:$page_id:$limit:$lang_id" ) )
|
||||
{
|
||||
$articles_id = $mdb -> query( 'SELECT * FROM ( '
|
||||
. 'SELECT '
|
||||
. 'a.id, date_add, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN title '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = al.copy_from AND article_id = a.id '
|
||||
. ') '
|
||||
. 'END ) AS title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.title IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. 'q1.date_add DESC '
|
||||
. 'LIMIT '
|
||||
. '0, ' . (int)$limit ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
\Cache::store( "getNews:$page_id:$limit:$lang_id", $articles_id );
|
||||
}
|
||||
|
||||
if ( \S::is_array_fix( $articles_id ) ) foreach ( $articles_id as $article_tmp )
|
||||
{
|
||||
$article = \Article::get_from_cache( $article_tmp['id'], $lang_id );
|
||||
$articles[] = $article;
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( array_key_exists( $variable, $this -> data ) )
|
||||
return $this -> $variable;
|
||||
}
|
||||
|
||||
public function __set( $variable, $value )
|
||||
{
|
||||
$this -> $variable = $value;
|
||||
}
|
||||
|
||||
public function offsetExists( $offset )
|
||||
{
|
||||
return isset( $this -> $offset );
|
||||
}
|
||||
|
||||
public function offsetGet( $offset )
|
||||
{
|
||||
return $this -> $offset;
|
||||
}
|
||||
|
||||
public function offsetSet( $offset, $value )
|
||||
{
|
||||
$this -> $offset = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset( $offset )
|
||||
{
|
||||
unset( $this -> $offset );
|
||||
}
|
||||
}
|
||||
57
autoload/class.Cache.php
Normal file
57
autoload/class.Cache.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
class Cache
|
||||
{
|
||||
public static function store( $key, $data, $ttl = 86400, $subdir = '' )
|
||||
{
|
||||
if ( defined( 'SP_CACHE' ) and constant( "SP_CACHE" ) == false ) {
|
||||
return false;
|
||||
}
|
||||
file_put_contents( self::get_file_name( $key, $subdir ), base64_encode( serialize( array( time() + $ttl, $data ) ) ) );
|
||||
}
|
||||
|
||||
private static function get_file_name( $key, $subdir )
|
||||
{
|
||||
$md5 = md5( $key );
|
||||
|
||||
if ( $subdir )
|
||||
$dir = 'temp/' . $subdir . '/' . $md5[0] . '/';
|
||||
else
|
||||
$dir = 'temp/' . $md5[0] . '/';
|
||||
|
||||
if ( !is_dir( $dir ) )
|
||||
mkdir( $dir , 0755 , true );
|
||||
|
||||
return $dir . 's_cache_' . $md5;
|
||||
}
|
||||
|
||||
static public function fetch( $key, $subdir = '' )
|
||||
{
|
||||
global $config;
|
||||
|
||||
if ( !$config['cache'] )
|
||||
return false;
|
||||
|
||||
$filename = self::get_file_name( $key );
|
||||
|
||||
if ( !file_exists( $filename ) || !is_readable( $filename ) )
|
||||
return false;
|
||||
|
||||
$data = base64_decode( file_get_contents( $filename ) );
|
||||
|
||||
$data = @unserialize( $data );
|
||||
if ( !$data )
|
||||
{
|
||||
unlink( $filename );
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( time() > $data[0] )
|
||||
{
|
||||
if ( file_exists( $filename ) )
|
||||
unlink( $filename );
|
||||
return false;
|
||||
}
|
||||
return $data[1];
|
||||
}
|
||||
}
|
||||
?>
|
||||
39
autoload/class.CacheHandler.php
Normal file
39
autoload/class.CacheHandler.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?
|
||||
class CacheHandler
|
||||
{
|
||||
protected $redis;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (class_exists('Redis')) {
|
||||
try {
|
||||
$this->redis = \RedisConnection::getInstance()->getConnection();
|
||||
} catch (\Exception $e) {
|
||||
$this->redis = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function get($key)
|
||||
{
|
||||
if ($this->redis) {
|
||||
return $this->redis->get($key);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function set($key, $value, $ttl = 86400) // 86400 = 60 * 60 * 24 (1 dzień)
|
||||
{
|
||||
if ($this->redis) {
|
||||
$this->redis->setex($key, $ttl, serialize($value));
|
||||
}
|
||||
}
|
||||
|
||||
public function exists($key)
|
||||
{
|
||||
if ($this->redis) {
|
||||
return $this->redis->exists($key);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
79
autoload/class.DbModel.php
Normal file
79
autoload/class.DbModel.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
class DbModel
|
||||
{
|
||||
public $data;
|
||||
public $table;
|
||||
public $table_key = 'id';
|
||||
|
||||
public function __construct( $id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
$result = $mdb -> get( $this -> table, '*', [ $this -> table_key => $id ] );
|
||||
if ( is_array( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
|
||||
if ( is_array( $this -> otm ) ) foreach ( $this -> otm as $otm )
|
||||
{
|
||||
if ( $otm['skey'] )
|
||||
{
|
||||
$result2 = $mdb -> select( $otm['table'], '*', [ $otm['fkey'] => $id ] );
|
||||
if ( is_array( $result2 ) ) foreach ( $result2 as $row2 )
|
||||
{
|
||||
$this -> data[ $otm['name'] ][ $row2[ $otm['skey'] ] ] = $row2;
|
||||
}
|
||||
}
|
||||
else
|
||||
$this -> data[ $otm['name'] ] = $mdb -> select( $otm['table'], '*', [ $otm['fkey'] => $id ] );
|
||||
}
|
||||
|
||||
if ( is_array( $this -> sotm ) ) foreach ( $this -> sotm as $sotm )
|
||||
{
|
||||
$this -> data[ $sotm['name'] ] = $mdb -> select( $sotm['table'], $sotm['column'], [ $sotm['fkey'] => $id ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( array_key_exists( $variable, $this -> data ) )
|
||||
return $this -> data[$variable];
|
||||
}
|
||||
|
||||
public function __set( $variable, $value )
|
||||
{
|
||||
$this -> data[$variable] = $value;
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $this -> __get( $this -> table_key ) )
|
||||
{
|
||||
$table_id_param = $this -> table_key;
|
||||
$table_id_value = $this -> __get( $this -> table_key );
|
||||
$data_tmp = $this -> data;
|
||||
unset( $data_tmp[ $table_id_param ] );
|
||||
|
||||
$mdb -> update( $this -> table, $data_tmp, [ $table_id_param => $table_id_value ] );
|
||||
|
||||
return $table_id_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> insert( $this -> table, $this -> data );
|
||||
$this -> __set( $this -> table_key, $mdb -> id() );
|
||||
}
|
||||
return $this -> __get( $this -> table_key );
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( $this -> table, [ $this -> table_key => $this -> __get( $this -> table_key ) ] );
|
||||
}
|
||||
|
||||
}
|
||||
79
autoload/class.Email.php
Normal file
79
autoload/class.Email.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
class Email extends DbModel
|
||||
{
|
||||
public $table = 'pp_newsletter_templates';
|
||||
|
||||
public function load_by_name( string $name )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get( $this -> table, '*', [ 'name' => $name ] );
|
||||
if ( is_array( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
}
|
||||
|
||||
public function email_check( $email )
|
||||
{
|
||||
return filter_var( $email, FILTER_VALIDATE_EMAIL );
|
||||
}
|
||||
|
||||
public function send( string $email, string $subject, bool $newsletter_headers = false, string $file = null )
|
||||
{
|
||||
global $settings;
|
||||
|
||||
if ( $newsletter_headers )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= $this -> text;
|
||||
$text .= $settings['newsletter_footer'];
|
||||
}
|
||||
else
|
||||
$text = $this -> text;
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1https://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1https://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
if ( $this -> email_check( $email ) and $subject )
|
||||
{
|
||||
$mail = new \PHPMailer();
|
||||
$mail -> IsSMTP();
|
||||
$mail -> SMTPAuth = true;
|
||||
$mail -> Host = $settings['email_host'];
|
||||
$mail -> Port = $settings['email_port'];
|
||||
$mail -> Username = $settings['email_login'];
|
||||
$mail -> Password = $settings['email_password'];
|
||||
$mail -> CharSet = "UTF-8";
|
||||
$mail -> SMTPOptions = array(
|
||||
'ssl' => array(
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true
|
||||
)
|
||||
);
|
||||
$mail -> AddReplyTo( $settings['contact_email'], $settings['firm_name'] );
|
||||
$mail -> SetFrom( $settings['contact_email'], $settings['firm_name'] );
|
||||
$mail -> AddAddress( $email, '' );
|
||||
$mail -> Subject = $subject;
|
||||
$mail -> Body = $text;
|
||||
if ( is_array( $file ) )
|
||||
{
|
||||
foreach ( $file as $file_tmp )
|
||||
{
|
||||
if ( file_exists( $file_tmp ) )
|
||||
$mail -> AddAttachment( $file_tmp );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( file_exists( $file ) )
|
||||
$mail -> AddAttachment( $file );
|
||||
}
|
||||
$mail -> IsHTML( true );
|
||||
return $mail -> Send();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
91
autoload/class.Html.php
Normal file
91
autoload/class.Html.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
class Html
|
||||
{
|
||||
public static function form_text( array $params = array() )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/form-text' );
|
||||
}
|
||||
|
||||
public static function input_switch( array $params = array() )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/input-switch' );
|
||||
}
|
||||
|
||||
public static function select( array $params = array() )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/select' );
|
||||
}
|
||||
|
||||
public static function textarea( array $params = array() )
|
||||
{
|
||||
$defaults = array(
|
||||
'rows' => 4,
|
||||
);
|
||||
|
||||
$params = array_merge( $defaults, $params );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/textarea' );
|
||||
}
|
||||
|
||||
public static function input_icon( array $params = array() )
|
||||
{
|
||||
$defaults = array(
|
||||
'type' => 'text',
|
||||
);
|
||||
|
||||
$params = array_merge( $defaults, $params );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/input-icon' );
|
||||
}
|
||||
|
||||
public static function input( array $params = array() )
|
||||
{
|
||||
$defaults = array(
|
||||
'type' => 'text',
|
||||
);
|
||||
|
||||
$params = array_merge( $defaults, $params );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/input' );
|
||||
}
|
||||
|
||||
public static function button( array $params = array() )
|
||||
{
|
||||
$defaults = array(
|
||||
'class' => 'btn-sm btn-info',
|
||||
);
|
||||
|
||||
$params = array_merge( $defaults, $params );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/button' );
|
||||
}
|
||||
|
||||
public static function panel( array $params = array() )
|
||||
{
|
||||
$defaults = array(
|
||||
'title' => 'panel-title',
|
||||
'class' => 'panel-primary',
|
||||
'content' => 'panel-content'
|
||||
);
|
||||
|
||||
$params = array_merge( $defaults, $params );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> params = $params;
|
||||
return $tpl -> render( 'html/panel' );
|
||||
}
|
||||
}
|
||||
291
autoload/class.Image.php
Normal file
291
autoload/class.Image.php
Normal file
@@ -0,0 +1,291 @@
|
||||
<?php
|
||||
class ImageManipulator
|
||||
{
|
||||
protected $width;
|
||||
protected $height;
|
||||
protected $image;
|
||||
protected $file;
|
||||
|
||||
/**
|
||||
* Image manipulator constructor
|
||||
*
|
||||
* @param string $file OPTIONAL Path to image file or image data as string
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($file = null)
|
||||
{
|
||||
if ( null !== $file )
|
||||
{
|
||||
$this -> file = $file;
|
||||
|
||||
if ( is_file( $file ) )
|
||||
$this->setImageFile($file);
|
||||
else
|
||||
$this->setImageString($file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from file
|
||||
*
|
||||
* @param string $file Path to image file
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function setImageFile($file)
|
||||
{
|
||||
if (!(is_readable($file) && is_file($file))) {
|
||||
throw new InvalidArgumentException("Image file $file is not readable");
|
||||
}
|
||||
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
list ( $this -> width, $this -> height, $type ) = getimagesize($file);
|
||||
|
||||
switch ($type) {
|
||||
case IMAGETYPE_GIF :
|
||||
$this->image = imagecreatefromgif($file);
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
$this->image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
case IMAGETYPE_PNG :
|
||||
$this->image = imagecreatefrompng($file);
|
||||
break;
|
||||
case IMAGETYPE_WEBP:
|
||||
$this -> image = imagecreatefromwebp($file);
|
||||
break;
|
||||
default :
|
||||
throw new InvalidArgumentException("Image type $type not supported");
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set image resource from string data
|
||||
*
|
||||
* @param string $data
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function setImageString($data)
|
||||
{
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
|
||||
if (!$this->image = imagecreatefromstring($data)) {
|
||||
throw new RuntimeException('Cannot create image from data string');
|
||||
}
|
||||
$this->width = imagesx($this->image);
|
||||
$this->height = imagesy($this->image);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resamples the current image
|
||||
*
|
||||
* @param int $width New width
|
||||
* @param int $height New height
|
||||
* @param bool $constrainProportions Constrain current image proportions when resizing
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function resample( $width, $height, $constrainProportions = true )
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
|
||||
if ( $constrainProportions )
|
||||
{
|
||||
if ( $height >= $width )
|
||||
{
|
||||
$width = round($height / $this->height * $this->width);
|
||||
}
|
||||
else
|
||||
{
|
||||
$height = round($width / $this->width * $this->height);
|
||||
}
|
||||
}
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
|
||||
|
||||
$transparent_index = imagecolortransparent( $this -> image );
|
||||
imagealphablending($temp, false);
|
||||
imagesavealpha($temp,true);
|
||||
$transparent = imagecolorallocatealpha($temp, 255, 255, 255, 127);
|
||||
imagefilledrectangle($temp, 0, 0, $this->width, $this->height, $transparent);
|
||||
imagecopyresampled($temp, $this->image, 0, 0, 0, 0, $width, $height, $this->width, $this->height);
|
||||
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enlarge canvas
|
||||
*
|
||||
* @param int $width Canvas width
|
||||
* @param int $height Canvas height
|
||||
* @param array $rgb RGB colour values
|
||||
* @param int $xpos X-Position of image in new canvas, null for centre
|
||||
* @param int $ypos Y-Position of image in new canvas, null for centre
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function enlargeCanvas($width, $height, array $rgb = array(), $xpos = null, $ypos = null)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
|
||||
$width = max($width, $this->width);
|
||||
$height = max($height, $this->height);
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
if (count($rgb) == 3) {
|
||||
$bg = imagecolorallocate($temp, $rgb[0], $rgb[1], $rgb[2]);
|
||||
imagefill($temp, 0, 0, $bg);
|
||||
}
|
||||
|
||||
if (null === $xpos) {
|
||||
$xpos = round(($width - $this->width) / 2);
|
||||
}
|
||||
if (null === $ypos) {
|
||||
$ypos = round(($height - $this->height) / 2);
|
||||
}
|
||||
|
||||
imagecopy($temp, $this->image, (int) $xpos, (int) $ypos, 0, 0, $this->width, $this->height);
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Crop image
|
||||
*
|
||||
* @param int|array $x1 Top left x-coordinate of crop box or array of coordinates
|
||||
* @param int $y1 Top left y-coordinate of crop box
|
||||
* @param int $x2 Bottom right x-coordinate of crop box
|
||||
* @param int $y2 Bottom right y-coordinate of crop box
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function crop($x1, $y1 = 0, $x2 = 0, $y2 = 0)
|
||||
{
|
||||
if (!is_resource($this->image)) {
|
||||
throw new RuntimeException('No image set');
|
||||
}
|
||||
if (is_array($x1) && 4 == count($x1)) {
|
||||
list($x1, $y1, $x2, $y2) = $x1;
|
||||
}
|
||||
|
||||
$x1 = max($x1, 0);
|
||||
$y1 = max($y1, 0);
|
||||
|
||||
$x2 = min($x2, $this->width);
|
||||
$y2 = min($y2, $this->height);
|
||||
|
||||
$width = $x2 - $x1;
|
||||
$height = $y2 - $y1;
|
||||
|
||||
$temp = imagecreatetruecolor($width, $height);
|
||||
imagecopy($temp, $this->image, 0, 0, $x1, $y1, $width, $height);
|
||||
|
||||
return $this->_replace($temp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace current image resource with a new one
|
||||
*
|
||||
* @param resource $res New image resource
|
||||
* @return ImageManipulator for a fluent interface
|
||||
* @throws UnexpectedValueException
|
||||
*/
|
||||
protected function _replace($res)
|
||||
{
|
||||
if (!is_resource($res)) {
|
||||
throw new UnexpectedValueException('Invalid resource');
|
||||
}
|
||||
if (is_resource($this->image)) {
|
||||
imagedestroy($this->image);
|
||||
}
|
||||
$this->image = $res;
|
||||
$this->width = imagesx($res);
|
||||
$this->height = imagesy($res);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save current image to file
|
||||
*
|
||||
* @param string $fileName
|
||||
* @return void
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public function save($fileName, $type = IMAGETYPE_JPEG)
|
||||
{
|
||||
$dir = dirname($fileName);
|
||||
if (!is_dir($dir)) {
|
||||
if (!mkdir($dir, 0755, true)) {
|
||||
throw new RuntimeException('Error creating directory ' . $dir);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch ($type) {
|
||||
case IMAGETYPE_WEBP:
|
||||
if ( !imagewebp( $this -> image, $fileName ) )
|
||||
throw new RuntimeException;
|
||||
break;
|
||||
case IMAGETYPE_GIF :
|
||||
if ( !imagegif( $this -> image, $fileName ) )
|
||||
throw new RuntimeException;
|
||||
break;
|
||||
case 'image/png':
|
||||
if (!imagepng($this->image, $fileName)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
break;
|
||||
case IMAGETYPE_JPEG :
|
||||
default :
|
||||
if (!imagejpeg($this->image, $fileName, 95)) {
|
||||
throw new RuntimeException;
|
||||
}
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
throw new RuntimeException('Error saving image file to ' . $fileName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GD image resource
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
public function getResource()
|
||||
{
|
||||
return $this->image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image resource width
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getWidth()
|
||||
{
|
||||
return $this->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current image height
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeight()
|
||||
{
|
||||
return $this->height;
|
||||
}
|
||||
}
|
||||
13
autoload/class.Log.php
Normal file
13
autoload/class.Log.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?
|
||||
class Log
|
||||
{
|
||||
static public function save_log( $message, $user_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> insert( 'pp_log', [
|
||||
'message' => $message,
|
||||
'user_id' => $user_id ? $user_id : null,
|
||||
'date' => date( 'Y-m-d H:i:s' )
|
||||
] );
|
||||
}
|
||||
}
|
||||
1431
autoload/class.Mobile_Detect.php
Normal file
1431
autoload/class.Mobile_Detect.php
Normal file
File diff suppressed because one or more lines are too long
30
autoload/class.RedisConnection.php
Normal file
30
autoload/class.RedisConnection.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?
|
||||
class RedisConnection {
|
||||
private static $instance = null;
|
||||
private $redis;
|
||||
|
||||
private function __construct() {
|
||||
global $config;
|
||||
|
||||
$this -> redis = new \Redis();
|
||||
if ( !$this -> redis -> connect( $config['redis']['host'], $config['redis']['port'] ) ) {
|
||||
throw new Exception("Nie udało się połączyć z serwerem Redis.");
|
||||
}
|
||||
|
||||
// Autentykacja za pomocą hasła
|
||||
if ( !$this -> redis -> auth( $config['redis']['password'] ) ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static function getInstance() {
|
||||
if ( self::$instance === null ) {
|
||||
self::$instance = new self();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
public function getConnection() {
|
||||
return $this->redis;
|
||||
}
|
||||
}
|
||||
946
autoload/class.S.php
Normal file
946
autoload/class.S.php
Normal file
@@ -0,0 +1,946 @@
|
||||
<?php
|
||||
class S
|
||||
{
|
||||
static public function clear_redis_cache()
|
||||
{
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
$redis -> flushAll();
|
||||
}
|
||||
|
||||
static public function remove_special_chars( $string ) {
|
||||
return str_ireplace( array( '\'', '"', ',' , ';', '<', '>' ), ' ', $string );
|
||||
}
|
||||
|
||||
static public function removeDuplicates( $array, $param ) {
|
||||
$result = [];
|
||||
foreach ($array as $key => $subArray) {
|
||||
$idsSeen = [];
|
||||
foreach ($subArray as $subKey => $item) {
|
||||
if (!in_array($item[ $param ], $idsSeen)) {
|
||||
$idsSeen[] = $item[ $param ];
|
||||
$result[$key][] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
static public function generate_webp_image($file, $compression_quality = 85)
|
||||
{
|
||||
if ( strpos( $file, 'thumb/' ) !== false )
|
||||
{
|
||||
$file_tmp = explode( '/', $file );
|
||||
|
||||
$width = $file_tmp[1];
|
||||
if ( empty( $width ) and $width !== '0' )
|
||||
$width = 500;
|
||||
|
||||
$height = $file_tmp[2];
|
||||
if ( empty( $height ) and $height !== '0' )
|
||||
$height = 500;
|
||||
|
||||
for ( $i = 0; $i <= 2; $i++ )
|
||||
unset( $file_tmp[$i] );
|
||||
|
||||
$img_src = implode( '/', $file_tmp );
|
||||
|
||||
$crop_w = $_GET['c_w'];
|
||||
$crop_h = $_GET['c_h'];
|
||||
|
||||
$img_md5 = md5( $img_src . $height . $width . $crop_h . $crop_w );
|
||||
$file = 'thumbs/' . $img_md5[0] . '/' . $img_md5[1] . '/' . $img_md5[2] . '/' . $img_md5;
|
||||
}
|
||||
|
||||
if ( !file_exists( $file ) )
|
||||
return false;
|
||||
|
||||
$output_file = 'cache/' . $file . '.webp';
|
||||
if ( file_exists( $output_file ) )
|
||||
return $output_file;
|
||||
|
||||
$file_type = mime_content_type( $file );
|
||||
|
||||
if ( function_exists( 'imagewebp' ) )
|
||||
{
|
||||
switch ( $file_type )
|
||||
{
|
||||
case 'image/jpeg':
|
||||
$image = imagecreatefromjpeg($file);
|
||||
break;
|
||||
|
||||
case 'image/png':
|
||||
$image = imagecreatefrompng($file);
|
||||
imagepalettetotruecolor($image);
|
||||
imagealphablending($image, true);
|
||||
imagesavealpha($image, true);
|
||||
break;
|
||||
|
||||
case 'image/gif':
|
||||
$image = imagecreatefromgif($file);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
$dir = dirname($output_file);
|
||||
if (!is_dir($dir))
|
||||
mkdir($dir, 0755, true);
|
||||
|
||||
$result = imagewebp($image, $output_file, $compression_quality);
|
||||
if (false === $result)
|
||||
return false;
|
||||
|
||||
imagedestroy($image);
|
||||
|
||||
return $output_file;
|
||||
}
|
||||
elseif (class_exists('Imagick'))
|
||||
{
|
||||
$dir = dirname($output_file);
|
||||
if (!is_dir($dir))
|
||||
mkdir($dir, 0755, true);
|
||||
|
||||
$image = new \Imagick();
|
||||
$image->readImage($file);
|
||||
|
||||
if ($file_type === 'png')
|
||||
{
|
||||
$image->setImageFormat('webp');
|
||||
$image->setImageCompressionQuality($compression_quality);
|
||||
$image->setOption('webp:lossless', 'true');
|
||||
}
|
||||
|
||||
$image->writeImage($output_file);
|
||||
return $output_file;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function is_array_fix( $value )
|
||||
{
|
||||
if ( is_array( $value ) and count( $value ) )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function get_domain( $url )
|
||||
{
|
||||
$parseUrl = parse_url( trim( $url ) );
|
||||
return trim( $parseUrl[host] ? str_replace( 'www.', '', $parseUrl[host] ) : str_replace( 'www.', '', array_shift( explode( '/', $parseUrl[path], 2 ) ) ) );
|
||||
}
|
||||
|
||||
static public function pre_dump( $value )
|
||||
{
|
||||
echo '<pre>';
|
||||
var_dump( $value );
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
public static function escape( $value )
|
||||
{
|
||||
$return = '';
|
||||
for ( $i = 0; $i < strlen( $value ); ++$i )
|
||||
{
|
||||
$char = $value[$i];
|
||||
$ord = ord( $char );
|
||||
if ( $char !== "'" && $char !== "\"" && $char !== '\\' && $ord >= 32 && $ord <= 126 )
|
||||
$return .= $char;
|
||||
else
|
||||
$return .= '\\x' . dechex( $ord );
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
public static function delete_cache()
|
||||
{
|
||||
\S::delete_dir( '../cache/' );
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::delete_dir( '../cron/temp/' );
|
||||
\S::delete_dir( 'temp/' );
|
||||
}
|
||||
|
||||
public static function pretty_date( $format, $timestamp = null )
|
||||
{
|
||||
$to_convert = array(
|
||||
'l' => array( 'dat' => 'N', 'str' => array( 'Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota', 'Niedziela' ) ),
|
||||
'F' => array( 'dat' => 'n', 'str' => array( 'styczeń', 'luty', 'marzec', 'kwiecień', 'maj', 'czerwiec', 'lipiec', 'sierpień', 'wrzesień', 'październik', 'listopad', 'grudzień' ) ),
|
||||
'f' => array( 'dat' => 'n', 'str' => array( 'stycznia', 'lutego', 'marca', 'kwietnia', 'maja', 'czerwca', 'lipca', 'sierpnia', 'września', 'października', 'listopada', 'grudnia' ) )
|
||||
);
|
||||
if ( $pieces = preg_split( '#[:/.\-, ]#', $format ) )
|
||||
{
|
||||
if ( $timestamp === null )
|
||||
$timestamp = time();
|
||||
|
||||
foreach ( $pieces as $datepart )
|
||||
{
|
||||
if ( array_key_exists( $datepart, $to_convert ) )
|
||||
$replace[] = $to_convert[$datepart]['str'][( date( $to_convert[$datepart]['dat'], $timestamp ) - 1)];
|
||||
else
|
||||
$replace[] = date( $datepart, $timestamp );
|
||||
}
|
||||
$result = strtr( $format, array_combine( $pieces, $replace ) );
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
public static function lang( $text )
|
||||
{
|
||||
global $lang;
|
||||
return $lang[$text] ? $lang[$text] : 'LANG-' . $text;
|
||||
}
|
||||
|
||||
public static function array_cartesian_product( $input )
|
||||
{
|
||||
$result = array();
|
||||
|
||||
while ( list($key, $values) = each( $input ) )
|
||||
{
|
||||
if ( empty( $values ) )
|
||||
continue;
|
||||
|
||||
if ( empty( $result ) )
|
||||
{
|
||||
foreach ( $values as $value )
|
||||
{
|
||||
$result[] = array( $key => $value );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$append = array();
|
||||
|
||||
foreach ( $result as &$product )
|
||||
{
|
||||
$product[$key] = array_shift( $values );
|
||||
$copy = $product;
|
||||
|
||||
foreach ( $values as $item )
|
||||
{
|
||||
$copy[$key] = $item;
|
||||
$append[] = $copy;
|
||||
}
|
||||
|
||||
array_unshift( $values, $product[$key] );
|
||||
}
|
||||
|
||||
$result = array_merge( $result, $append );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function normalize_decimal( $val, $precision = 2 )
|
||||
{
|
||||
$input = str_replace( ' ', '', $val );
|
||||
$number = str_replace( ',', '.', $input );
|
||||
if ( strpos( $number, '.' ) )
|
||||
{
|
||||
$groups = explode( '.', str_replace( ',', '.', $number ) );
|
||||
$lastGroup = array_pop( $groups );
|
||||
$number = implode( '', $groups ) . '.' . $lastGroup;
|
||||
}
|
||||
return bcadd( round( $number, $precision ), 0, $precision );
|
||||
}
|
||||
|
||||
public static function decimal( $val, $precision = 2, $dec_point = ',', $thousands_sep = ' ' )
|
||||
{
|
||||
return number_format( $val, $precision, $dec_point, $thousands_sep );
|
||||
}
|
||||
|
||||
public static function chmod_r( $path, $chmod = 0755 )
|
||||
{
|
||||
$dir = new DirectoryIterator( $path );
|
||||
foreach ( $dir as $item )
|
||||
{
|
||||
chmod( $item -> getPathname(), $chmod );
|
||||
if ( $item -> isDir() && !$item -> isDot() )
|
||||
self::chmod_r( $item -> getPathname() );
|
||||
}
|
||||
}
|
||||
|
||||
public static function rrmdir( $dir )
|
||||
{
|
||||
if ( is_dir( $dir ) )
|
||||
{
|
||||
$files = scandir( $dir );
|
||||
foreach ( $files as $file )
|
||||
if ( $file != "." && $file != ".." )
|
||||
\S::rrmdir( "$dir/$file" );
|
||||
rmdir( $dir );
|
||||
}
|
||||
else if ( file_exists( $dir ) )
|
||||
unlink( $dir );
|
||||
}
|
||||
|
||||
public static function rcopy( $src, $dst )
|
||||
{
|
||||
if ( is_dir( $src ) )
|
||||
{
|
||||
mkdir( $dst, 0755 );
|
||||
$files = scandir( $src );
|
||||
foreach ( $files as $file )
|
||||
if ( $file != "." && $file != ".." )
|
||||
\S::rcopy( "$src/$file", "$dst/$file" );
|
||||
}
|
||||
else if ( file_exists( $src ) )
|
||||
copy( $src, $dst );
|
||||
|
||||
\S::rrmdir( $src );
|
||||
}
|
||||
|
||||
public static function is_mobile()
|
||||
{
|
||||
$detect = new \Mobile_Detect;
|
||||
return $detect -> isMobile();
|
||||
}
|
||||
|
||||
public static function get_new_version()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
if ( $version = \S::get_session( 'new-version' ) )
|
||||
return $version;
|
||||
|
||||
$versions = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/versions.php?key=' . $settings['update_key'] );
|
||||
$versions = explode( PHP_EOL, $versions );
|
||||
$version = (float)max( $versions );
|
||||
|
||||
\S::set_session( 'new-version', $version );
|
||||
|
||||
return $version;
|
||||
}
|
||||
|
||||
public static function get_version()
|
||||
{
|
||||
return (float) @file_get_contents( '../libraries/version.ini' );
|
||||
}
|
||||
|
||||
public static function pre( $data, $type = '' )
|
||||
{
|
||||
$data = str_replace( 'Array
|
||||
(', '', $data );
|
||||
$data = str_replace( ')', '', $data );
|
||||
|
||||
echo '<pre';
|
||||
if ( $type == 'error' )
|
||||
echo ' style="color: #cc0000;" ';
|
||||
else if ( $type == 'info' )
|
||||
echo ' style="color: #2c539e;" ';
|
||||
else
|
||||
echo ' style="color: #8fc400;" ';
|
||||
echo '>' . print_r( $data, true ) . '</pre>';
|
||||
}
|
||||
|
||||
public static function json_to_array( $json )
|
||||
{
|
||||
$values_tmp = json_decode( $json, true );
|
||||
|
||||
if ( is_array( $values_tmp ) )
|
||||
foreach ( $values_tmp as $val )
|
||||
{
|
||||
if ( isset( $values[$val['name']] ) )
|
||||
{
|
||||
if ( is_array( $values[$val['name']] ) )
|
||||
$values[$val['name']][] = $val['value'];
|
||||
else
|
||||
$values[$val['name']] = array( $values[$val['name']], $val['value'] );
|
||||
}
|
||||
else
|
||||
$values[$val['name']] = $val['value'];
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
public static function set_session( $var, $val )
|
||||
{
|
||||
$_SESSION[$var] = $val;
|
||||
}
|
||||
|
||||
public static function get_session( $var )
|
||||
{
|
||||
return $_SESSION[$var];
|
||||
}
|
||||
|
||||
public static function delete_session( $var )
|
||||
{
|
||||
unset( $_SESSION[$var] );
|
||||
}
|
||||
|
||||
public static function get( $var, $clear = false )
|
||||
{
|
||||
if ( isset( $_POST[$var] ) )
|
||||
{
|
||||
if ( is_string( $_POST[$var] ) )
|
||||
{
|
||||
$value = $_POST[$var];
|
||||
|
||||
if ( $clear )
|
||||
{
|
||||
$value = strip_tags( $value );
|
||||
$value = preg_replace( '/[\'\"\\\\]/i', '', $value );
|
||||
}
|
||||
|
||||
return trim( $value );
|
||||
}
|
||||
else
|
||||
return $_POST[$var];
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( isset( $_GET[$var] ) )
|
||||
{
|
||||
if ( is_string( $_GET[$var] ) )
|
||||
return trim( $_GET[$var] );
|
||||
else
|
||||
return $_GET[$var];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function set_message( $text )
|
||||
{
|
||||
self::set_session( 'message', $text );
|
||||
}
|
||||
|
||||
public static function alert( $text )
|
||||
{
|
||||
self::set_session( 'alert', $text );
|
||||
}
|
||||
|
||||
public static function error( $text )
|
||||
{
|
||||
self::set_session( 'error', $text );
|
||||
}
|
||||
|
||||
public static function htacces( $dir = '../' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$settings = \front\factory\Settings::settings_details( true );
|
||||
|
||||
$url = preg_replace( '#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME'] );
|
||||
|
||||
$robots = 'User-agent: *' . PHP_EOL;
|
||||
$robots .= 'Allow: /' . PHP_EOL;
|
||||
|
||||
$site_map = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
|
||||
$site_map .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
|
||||
$site_map .= '<url>' . PHP_EOL;
|
||||
$site_map .= '<loc>https://' . $url . '</loc>' . PHP_EOL;
|
||||
$site_map .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
|
||||
$site_map .= '<changefreq>daily</changefreq>' . PHP_EOL;
|
||||
$site_map .= '<priority>1</priority>' . PHP_EOL;
|
||||
$site_map .= '</url>' . PHP_EOL;
|
||||
|
||||
$htaccess_data = file_get_contents( $dir . 'libraries/htaccess.conf' );
|
||||
$htaccess_data = str_replace( '{PAGE}', $url, $htaccess_data );
|
||||
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $row['id'] . '/$ index.php?a=change_language&id=' . $row['id'] . ' [L]';
|
||||
}
|
||||
|
||||
//
|
||||
// INNE
|
||||
//
|
||||
$htaccess_data .= PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^newsletter/signin/$ index.php?module=newsletter&action=signin [L]' . PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^newsletter/confirm/hash=(.*)$ index.php?module=newsletter&action=confirm&hash=$1 [L]' . PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^newsletter/unsubscribe/hash=(.*)$ index.php?module=newsletter&action=unsubscribe&hash=$1 [L]' . PHP_EOL;
|
||||
|
||||
//
|
||||
// PRODUCENCI
|
||||
//
|
||||
$htaccess_data .= 'RewriteRule ^producenci$ index.php?module=shop_producer&action=list&layout_id=' . \front\factory\Layouts::category_default_layout() . '&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_producer', '*', [ 'status' => 1 ] );
|
||||
if ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
{
|
||||
$htaccess_data .= 'RewriteRule ^producent/' . \S::seo( $row['name'] ) . '$ index.php?module=shop_producer&action=products&producer_id=' . $row['id'] . '&layout_id=' . \front\factory\Layouts::category_default_layout() . '&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
$htaccess_data .= 'RewriteRule ^producent/' . \S::seo( $row['name'] ) . '/([0-9]+)$ index.php?module=shop_producer&action=products&producer_id=' . $row['id'] . '&layout_id=' . \front\factory\Layouts::category_default_layout() . '&bs=$1&%{QUERY_STRING} [L]' . PHP_EOL;
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id', 'start' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
!$row['start'] ? $language_link = $row['id'] . '/' : $language_link = '';
|
||||
|
||||
$results2 = $mdb -> select( 'pp_shop_categories_langs', [ '[><]pp_shop_categories' => [ 'category_id' => 'id' ] ], [ 'seo_link', 'title', 'category_id' ], [ 'lang_id' => $row['id'], 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
{
|
||||
if ( $row2['title'] )
|
||||
{
|
||||
$site_map .= '<url>' . PHP_EOL;
|
||||
if ( $row2['seo_link'] )
|
||||
$site_map .= '<loc>https://' . $url . '/' . $language_link . \S::seo( $row2['seo_link'] ) . '</loc>' . PHP_EOL;
|
||||
else
|
||||
$site_map .= '<loc>https://' . $url . '/' . $language_link . 'k-' . $row2['category_id'] . '-' . \S::seo( $row2['title'] ) . '</loc>' . PHP_EOL;
|
||||
$site_map .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
|
||||
$site_map .= '<changefreq>daily</changefreq>' . PHP_EOL;
|
||||
$site_map .= '<priority>1</priority>' . PHP_EOL;
|
||||
$site_map .= '</url>' . PHP_EOL;
|
||||
|
||||
if ( $row2['seo_link'] )
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '$ index.php?category=' . $row2['category_id'] . '&lang=' . $row['id'] . '&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '/([0-9]+)$ index.php?category=' . $row2['category_id'] . '&lang=' . $row['id'] . '&bs=$1&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '/1$ ' . $language_link . \S::seo( $row2['seo_link'] ) . ' [R=301,L]';
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 'k-' . $row2['category_id'] . '-' . \S::seo( $row2['title'] ) . '$ index.php?category=' . $row2['category_id'] . '&lang=' . $row['id'] . '&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 'k-' . $row2['category_id'] . '-' . \S::seo( $row2['title'] ) . '/([0-9]+)$ index.php?category=' . $row2['category_id'] . '&lang=' . $row['id'] . '&bs=$1&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 'k-' . $row2['category_id'] . '-' . \S::seo( $row2['title'] ) . '/1$ ' . $language_link . 'k-' . $row2['category_id'] . '-' . \S::seo( $row2['title'] ) . ' [R=301,L]';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id', 'start' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) {
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
!$row['start'] ? $language_link = $row['id'] . '/' : $language_link = '';
|
||||
|
||||
$results2 = $mdb -> select( 'pp_shop_products_langs', [ '[><]pp_shop_products' => [ 'product_id' => 'id' ] ], [ 'seo_link', 'name', 'product_id' ], [ 'lang_id' => $row['id'], 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
if ( is_array( $results2 ) ) {
|
||||
foreach ( $results2 as $row2 )
|
||||
{
|
||||
if ( $row2['name'] )
|
||||
{
|
||||
$site_map .= '<url>' . PHP_EOL;
|
||||
if ( $row2['seo_link'] )
|
||||
$site_map .= '<loc>https://' . $url . '/' . $language_link . \S::seo( $row2['seo_link'] ) . '</loc>' . PHP_EOL;
|
||||
else
|
||||
$site_map .= '<loc>https://' . $url . '/' . $language_link . 'p-' . $row2['product_id'] . '-' . \S::seo( $row2['name'] ) . '</loc>' . PHP_EOL;
|
||||
$site_map .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
|
||||
$site_map .= '<changefreq>daily</changefreq>' . PHP_EOL;
|
||||
$site_map .= '<priority>1</priority>' . PHP_EOL;
|
||||
$site_map .= '</url>' . PHP_EOL;
|
||||
|
||||
if ( $row2['seo_link'] )
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '$ index.php?product=' . $row2['product_id'] . ' [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '/([0-9-]+)$ index.php?product=' . $row2['product_id'] . '&permutation_hash=$1 [L]';
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 'p-' . $row2['product_id'] . '-' . \S::seo( $row2['name'] ) . '$ index.php?product=' . $row2['product_id'] . ' [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 'p-' . $row2['product_id'] . '-' . \S::seo( $row2['name'] ) . '/([0-9-]+)$ index.php?product=' . $row2['product_id'] . '&permutation_hash=$1 [L]';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id', 'start' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
( !$row['start'] and count( $results ) > 1 ) ? $language_link = $row['id'] . '/' : $language_link = '';
|
||||
|
||||
$results2 = $mdb -> select( 'pp_pages_langs', [ '[><]pp_pages' => [ 'page_id' => 'id' ] ], [ 'seo_link', 'title', 'page_id', 'noindex', 'start', 'link', 'page_type' ], [ 'lang_id' => $row['id'], 'ORDER' => [ 'start' => 'DESC', 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results2 ) )
|
||||
foreach ( $results2 as $row2 )
|
||||
{
|
||||
if ( $row2['title'] and $row2['page_type'] != 3 and $row2['page_type'] != 5 )
|
||||
{
|
||||
if ( !$row2['noindex'] )
|
||||
{
|
||||
$site_map .= '<url>' . PHP_EOL;
|
||||
if ( $row2['seo_link'] )
|
||||
$site_map .= '<loc>https://' . $url . '/' . \S::seo( $row2['seo_link'] ) . '</loc>' . PHP_EOL;
|
||||
else
|
||||
$site_map .= '<loc>https://' . $url . '/s-' . $row2['page_id'] . '-' . self::seo( $row2['title'] ) . '</loc>' . PHP_EOL;
|
||||
$site_map .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
|
||||
$site_map .= '<changefreq>daily</changefreq>' . PHP_EOL;
|
||||
$site_map .= '<priority>1</priority>' . PHP_EOL;
|
||||
$site_map .= '</url>' . PHP_EOL;
|
||||
}
|
||||
else if ( $row2['noindex'] and $row2['seo_link'] )
|
||||
{
|
||||
$robots .= 'User-agent: GoogleBot' . PHP_EOL;
|
||||
$robots .= 'Disallow: /' . $row2['seo_link'] . PHP_EOL;
|
||||
}
|
||||
|
||||
if ( $row2['start'] )
|
||||
{
|
||||
if ( $row2['seo_link'] )
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteCond %{REQUEST_URI} ^/' . \S::seo( $row2['seo_link'] ) . '$';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^(.*)$ http://www.' . $url . '/' . $language_link . ' [R=permanent,L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteCond %{REQUEST_URI} ^/' . \S::seo( $row2['seo_link'] ) . '-1$';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^(.*)$ http://www.' . $url . '/' . $language_link . ' [R=permanent,L]';
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteCond %{REQUEST_URI} ^/s-' . $row2['page_id'] . '-' . \S::seo( $row2['title'] ) . '$';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^(.*)$ http://www.' . $url . '/' . $language_link . ' [R=permanent,L]';
|
||||
|
||||
$htaccess_data .= PHP_EOL . 'RewriteCond %{REQUEST_URI} ^/s-' . $row2['page_id'] . '-' . \S::seo( $row2['title'] ) . '-1$';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^(.*)$ http://www.' . $url . '/' . $language_link . ' [R=permanent,L]';
|
||||
}
|
||||
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^$ index.php?a=page&id=' . $row2['page_id'] . '&lang=' . $row['id'] . ' [L]';
|
||||
}
|
||||
|
||||
if ( $row2['seo_link'] )
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '$ index.php?a=page&id=' . $row2['page_id'] . '&lang=' . $row['id'] . '&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '/([0-9]+)$ index.php?a=page&id=' . $row2['page_id'] . '&lang=' . $row['id'] . '&bs=$1&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '/1$ ' . $language_link . \S::seo( $row2['seo_link'] ) . ' [R=301,L]';
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 's-' . $row2['page_id'] . '-' . \S::seo( $row2['title'] ) . '$ index.php?a=page&id=' . $row2['page_id'] . '&lang=' . $row['id'] . '&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 's-' . $row2['page_id'] . '-' . \S::seo( $row2['title'] ) . '/([0-9]+)$ index.php?a=page&id=' . $row2['page_id'] . '&lang=' . $row['id'] . '&bs=$1&%{QUERY_STRING} [L]';
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 's-' . $row2['page_id'] . '-' . \S::seo( $row2['title'] ) . '/1$ ' . $language_link . 's-' . $row2['page_id'] . '-' . \S::seo( $row2['title'] ) . ' [R=301,L]';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$results2 = $mdb -> select( 'pp_articles_langs', [ '[><]pp_articles' => [ 'article_id' => 'id' ] ], [ 'seo_link', 'title', 'article_id', 'noindex', 'copy_from' ], [ 'AND' => [ 'status' => 1, 'lang_id' => $row['id'], 'block_direct_access' => 0 ] ] );
|
||||
if ( is_array( $results2 ) )
|
||||
foreach ( $results2 as $row2 )
|
||||
{
|
||||
if ( $row2['copy_from'] != null )
|
||||
{
|
||||
$results_tmp = $mdb -> get( 'pp_articles_langs', [
|
||||
'seo_link',
|
||||
'title'
|
||||
], [
|
||||
'AND' => [
|
||||
'article_id' => $row2['article_id'],
|
||||
'lang_id' => $row2['copy_from']
|
||||
]
|
||||
] );
|
||||
$row2['seo_link'] = $results_tmp['seo_link'];
|
||||
$row2['title'] = $results_tmp['title'];
|
||||
}
|
||||
|
||||
if ( !$row2['noindex'] )
|
||||
{
|
||||
$site_map .= '<url>' . PHP_EOL;
|
||||
if ( $row2['seo_link'] )
|
||||
$site_map .= '<loc>https://' . $url . '/' . \S::seo( $row2['seo_link'] ) . '</loc>' . PHP_EOL;
|
||||
else
|
||||
$site_map .= '<loc>https://' . $url . '/a-' . $row2['article_id'] . '-' . self::seo( $row2['title'] ) . '</loc>' . PHP_EOL;
|
||||
$site_map .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
|
||||
$site_map .= '<changefreq>daily</changefreq>' . PHP_EOL;
|
||||
$site_map .= '<priority>1</priority>' . PHP_EOL;
|
||||
$site_map .= '</url>' . PHP_EOL;
|
||||
}
|
||||
else if ( $row2['noindex'] and $row2['seo_link'] )
|
||||
{
|
||||
$robots .= 'User-agent: GoogleBot' . PHP_EOL;
|
||||
$robots .= 'Disallow: /' . $row2['seo_link'] . PHP_EOL;
|
||||
}
|
||||
|
||||
if ( $row2['seo_link'] )
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . \S::seo( $row2['seo_link'] ) . '$ index.php?article=' . $row2['article_id'] . '&lang=' . $row['id'] . '&%{QUERY_STRING} [L]';
|
||||
else if ( $row2['title'] != null )
|
||||
$htaccess_data .= PHP_EOL . 'RewriteRule ^' . $language_link . 'a-' . $row2['article_id'] . '-' . \S::seo( $row2['title'] ) . '$ index.php?article=' . $row2['article_id'] . '&lang=' . $row['id'] . '&%{QUERY_STRING} [L]';
|
||||
}
|
||||
}
|
||||
|
||||
$results = $mdb -> get( 'pp_settings', 'value', [ 'param' => 'htaccess' ] );
|
||||
if ( $results )
|
||||
$htaccess_data .= PHP_EOL . $results;
|
||||
|
||||
$results = $mdb -> get( 'pp_settings', 'value', [ 'param' => 'robots' ] );
|
||||
if ( $results )
|
||||
$robots .= PHP_EOL . $results;
|
||||
|
||||
$site_map .= '</urlset>';
|
||||
|
||||
/* cache */
|
||||
if ( $settings['htaccess_cache'] )
|
||||
{
|
||||
$htaccess_data = str_replace( '{HTACCESS_CACHE}',
|
||||
'<IfModule mod_deflate.c>' . PHP_EOL
|
||||
. 'AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript' . PHP_EOL
|
||||
. '</IfModule>' . PHP_EOL
|
||||
. '<IfModule mod_headers.c>' . PHP_EOL
|
||||
. 'Header set Access-Control-Allow-Origin "*"' . PHP_EOL
|
||||
. '</IfModule>' . PHP_EOL
|
||||
. '<IfModule mod_expires.c>' . PHP_EOL
|
||||
. 'ExpiresActive on' . PHP_EOL
|
||||
. 'ExpiresDefault "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType text/css "access plus 1 year"' . PHP_EOL
|
||||
. 'ExpiresByType application/json "access plus 0 seconds"' . PHP_EOL
|
||||
. 'ExpiresByType application/xml "access plus 0 seconds"' . PHP_EOL
|
||||
. 'ExpiresByType text/xml "access plus 0 seconds"' . PHP_EOL
|
||||
. 'ExpiresByType image/x-icon "access plus 1 week"' . PHP_EOL
|
||||
. 'ExpiresByType text/x-component "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType text/html "access plus 0 seconds"' . PHP_EOL
|
||||
. 'ExpiresByType application/javascript "access plus 1 year"' . PHP_EOL
|
||||
. 'ExpiresByType application/x-web-app-manifest+json "access plus 0 seconds"' . PHP_EOL
|
||||
. 'ExpiresByType text/cache-manifest "access plus 0 seconds"' . PHP_EOL
|
||||
. 'ExpiresByType audio/ogg "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType image/gif "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType image/jpeg "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType image/png "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType video/mp4 "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType video/ogg "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType video/webm "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType application/atom+xml "access plus 1 hour"' . PHP_EOL
|
||||
. 'ExpiresByType application/rss+xml "access plus 1 hour"' . PHP_EOL
|
||||
. 'ExpiresByType application/font-woff "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType application/vnd.ms-fontobject "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType application/x-font-ttf "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType font/opentype "access plus 1 month"' . PHP_EOL
|
||||
. 'ExpiresByType image/svg+xml "access plus 1 month"' . PHP_EOL
|
||||
. '</IfModule>'
|
||||
, $htaccess_data );
|
||||
}
|
||||
else
|
||||
{
|
||||
$htaccess_data = str_replace( '{HTACCESS_CACHE}',
|
||||
'<IfModule mod_headers.c>' . PHP_EOL
|
||||
. 'Header set Cache-Control "no-cache, no-store, must-revalidate"' . PHP_EOL
|
||||
. 'Header set Pragma "no-cache"' . PHP_EOL
|
||||
. 'Header set Expires 0' . PHP_EOL
|
||||
. '</IfModule>',
|
||||
$htaccess_data );
|
||||
}
|
||||
|
||||
$fp = fopen( $dir . '.htaccess', 'w' );
|
||||
fwrite( $fp, $htaccess_data );
|
||||
fclose( $fp );
|
||||
|
||||
$fp = fopen( $dir . 'sitemap.xml', 'w' );
|
||||
fwrite( $fp, $site_map );
|
||||
fclose( $fp );
|
||||
|
||||
$fp = fopen( $dir . 'robots.txt', 'w' );
|
||||
fwrite( $fp, $robots );
|
||||
fclose( $fp );
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static function seo( $val, $delete_rhombs = false )
|
||||
{
|
||||
$array_rep1 = array('*', '_', ' ', '+', '"', "'", '?', '-', ',', '!', '~', '<', '>', '@', '#', '$', '%', '^', '&', '*' . '(', ')' . '-', '=', '\\', '|', '[', ']', ':', '(', ')');
|
||||
$array_rep2 = array('-', '-', '-', '-', '', '', '', '-', '-', '', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '', '-', '-', '-', '-', '-', '-', '-', '-');
|
||||
$val = self::noPl($val);
|
||||
$val = str_replace($array_rep1, $array_rep2, $val);
|
||||
if ($delete_rhombs)
|
||||
$val = str_replace('/', '', $val);
|
||||
|
||||
$val = strtolower($val);
|
||||
$val = preg_replace('/(-){2,}/', '-', $val);
|
||||
$val = ltrim($val, '-');
|
||||
$val = rtrim($val, '-');
|
||||
return $val;
|
||||
}
|
||||
|
||||
public static function noPL($string)
|
||||
{
|
||||
$chars = array( // Decompositions for Latin-1 Supplement chr(195).chr(128)=> 'A', chr(195).chr(129) => 'A',
|
||||
chr(195) . chr(130) => 'A', chr(195) . chr(131) => 'A',
|
||||
chr(195) . chr(132) => 'A', chr(195) . chr(133) => 'A',
|
||||
chr(195) . chr(135) => 'C', chr(195) . chr(136) => 'E',
|
||||
chr(195) . chr(137) => 'E', chr(195) . chr(138) => 'E',
|
||||
chr(195) . chr(139) => 'E', chr(195) . chr(140) => 'I',
|
||||
chr(195) . chr(141) => 'I', chr(195) . chr(142) => 'I',
|
||||
chr(195) . chr(143) => 'I', chr(195) . chr(145) => 'N',
|
||||
chr(195) . chr(146) => 'O', chr(195) . chr(147) => 'O',
|
||||
chr(195) . chr(148) => 'O', chr(195) . chr(149) => 'O',
|
||||
chr(195) . chr(150) => 'O', chr(195) . chr(153) => 'U',
|
||||
chr(195) . chr(154) => 'U', chr(195) . chr(155) => 'U',
|
||||
chr(195) . chr(156) => 'U', chr(195) . chr(157) => 'Y',
|
||||
chr(195) . chr(159) => 's', chr(195) . chr(160) => 'a',
|
||||
chr(195) . chr(161) => 'a', chr(195) . chr(162) => 'a',
|
||||
chr(195) . chr(163) => 'a', chr(195) . chr(164) => 'a',
|
||||
chr(195) . chr(165) => 'a', chr(195) . chr(167) => 'c',
|
||||
chr(195) . chr(168) => 'e', chr(195) . chr(169) => 'e',
|
||||
chr(195) . chr(170) => 'e', chr(195) . chr(171) => 'e',
|
||||
chr(195) . chr(172) => 'i', chr(195) . chr(173) => 'i',
|
||||
chr(195) . chr(174) => 'i', chr(195) . chr(175) => 'i',
|
||||
chr(195) . chr(177) => 'n', chr(195) . chr(178) => 'o',
|
||||
chr(195) . chr(179) => 'o', chr(195) . chr(180) => 'o',
|
||||
chr(195) . chr(181) => 'o', chr(195) . chr(182) => 'o',
|
||||
chr(195) . chr(182) => 'o', chr(195) . chr(185) => 'u',
|
||||
chr(195) . chr(186) => 'u', chr(195) . chr(187) => 'u',
|
||||
chr(195) . chr(188) => 'u', chr(195) . chr(189) => 'y',
|
||||
chr(195) . chr(191) => 'y',
|
||||
// Decompositions for Latin Extended-A
|
||||
chr(196) . chr(128) => 'A', chr(196) . chr(129) => 'a',
|
||||
chr(196) . chr(130) => 'A', chr(196) . chr(131) => 'a',
|
||||
chr(196) . chr(132) => 'A', chr(196) . chr(133) => 'a',
|
||||
chr(196) . chr(134) => 'C', chr(196) . chr(135) => 'c',
|
||||
chr(196) . chr(136) => 'C', chr(196) . chr(137) => 'c',
|
||||
chr(196) . chr(138) => 'C', chr(196) . chr(139) => 'c',
|
||||
chr(196) . chr(140) => 'C', chr(196) . chr(141) => 'c',
|
||||
chr(196) . chr(142) => 'D', chr(196) . chr(143) => 'd',
|
||||
chr(196) . chr(144) => 'D', chr(196) . chr(145) => 'd',
|
||||
chr(196) . chr(146) => 'E', chr(196) . chr(147) => 'e',
|
||||
chr(196) . chr(148) => 'E', chr(196) . chr(149) => 'e',
|
||||
chr(196) . chr(150) => 'E', chr(196) . chr(151) => 'e',
|
||||
chr(196) . chr(152) => 'E', chr(196) . chr(153) => 'e',
|
||||
chr(196) . chr(154) => 'E', chr(196) . chr(155) => 'e',
|
||||
chr(196) . chr(156) => 'G', chr(196) . chr(157) => 'g',
|
||||
chr(196) . chr(158) => 'G', chr(196) . chr(159) => 'g',
|
||||
chr(196) . chr(160) => 'G', chr(196) . chr(161) => 'g',
|
||||
chr(196) . chr(162) => 'G', chr(196) . chr(163) => 'g',
|
||||
chr(196) . chr(164) => 'H', chr(196) . chr(165) => 'h',
|
||||
chr(196) . chr(166) => 'H', chr(196) . chr(167) => 'h',
|
||||
chr(196) . chr(168) => 'I', chr(196) . chr(169) => 'i',
|
||||
chr(196) . chr(170) => 'I', chr(196) . chr(171) => 'i',
|
||||
chr(196) . chr(172) => 'I', chr(196) . chr(173) => 'i',
|
||||
chr(196) . chr(174) => 'I', chr(196) . chr(175) => 'i',
|
||||
chr(196) . chr(176) => 'I', chr(196) . chr(177) => 'i',
|
||||
chr(196) . chr(178) => 'IJ', chr(196) . chr(179) => 'ij',
|
||||
chr(196) . chr(180) => 'J', chr(196) . chr(181) => 'j',
|
||||
chr(196) . chr(182) => 'K', chr(196) . chr(183) => 'k',
|
||||
chr(196) . chr(184) => 'k', chr(196) . chr(185) => 'L',
|
||||
chr(196) . chr(186) => 'l', chr(196) . chr(187) => 'L',
|
||||
chr(196) . chr(188) => 'l', chr(196) . chr(189) => 'L',
|
||||
chr(196) . chr(190) => 'l', chr(196) . chr(191) => 'L',
|
||||
chr(197) . chr(128) => 'l', chr(197) . chr(129) => 'L',
|
||||
chr(197) . chr(130) => 'l', chr(197) . chr(131) => 'N',
|
||||
chr(197) . chr(132) => 'n', chr(197) . chr(133) => 'N',
|
||||
chr(197) . chr(134) => 'n', chr(197) . chr(135) => 'N',
|
||||
chr(197) . chr(136) => 'n', chr(197) . chr(137) => 'N',
|
||||
chr(197) . chr(138) => 'n', chr(197) . chr(139) => 'N',
|
||||
chr(197) . chr(140) => 'O', chr(197) . chr(141) => 'o',
|
||||
chr(197) . chr(142) => 'O', chr(197) . chr(143) => 'o',
|
||||
chr(197) . chr(144) => 'O', chr(197) . chr(145) => 'o',
|
||||
chr(197) . chr(146) => 'OE', chr(197) . chr(147) => 'oe',
|
||||
chr(197) . chr(148) => 'R', chr(197) . chr(149) => 'r',
|
||||
chr(197) . chr(150) => 'R', chr(197) . chr(151) => 'r',
|
||||
chr(197) . chr(152) => 'R', chr(197) . chr(153) => 'r',
|
||||
chr(197) . chr(154) => 'S', chr(197) . chr(155) => 's',
|
||||
chr(197) . chr(156) => 'S', chr(197) . chr(157) => 's',
|
||||
chr(197) . chr(158) => 'S', chr(197) . chr(159) => 's',
|
||||
chr(197) . chr(160) => 'S', chr(197) . chr(161) => 's',
|
||||
chr(197) . chr(162) => 'T', chr(197) . chr(163) => 't',
|
||||
chr(197) . chr(164) => 'T', chr(197) . chr(165) => 't',
|
||||
chr(197) . chr(166) => 'T', chr(197) . chr(167) => 't',
|
||||
chr(197) . chr(168) => 'U', chr(197) . chr(169) => 'u',
|
||||
chr(197) . chr(170) => 'U', chr(197) . chr(171) => 'u',
|
||||
chr(197) . chr(172) => 'U', chr(197) . chr(173) => 'u',
|
||||
chr(197) . chr(174) => 'U', chr(197) . chr(175) => 'u',
|
||||
chr(197) . chr(176) => 'U', chr(197) . chr(177) => 'u',
|
||||
chr(197) . chr(178) => 'U', chr(197) . chr(179) => 'u',
|
||||
chr(197) . chr(180) => 'W', chr(197) . chr(181) => 'w',
|
||||
chr(197) . chr(182) => 'Y', chr(197) . chr(183) => 'y',
|
||||
chr(197) . chr(184) => 'Y', chr(197) . chr(185) => 'Z',
|
||||
chr(197) . chr(186) => 'z', chr(197) . chr(187) => 'Z',
|
||||
chr(197) . chr(188) => 'z', chr(197) . chr(189) => 'Z',
|
||||
chr(197) . chr(190) => 'z', chr(197) . chr(191) => 's'
|
||||
);
|
||||
|
||||
$string = strtr($string, $chars);
|
||||
|
||||
$table = array(
|
||||
"А" => "a", "Б" => "b", "В" => "v", "Г" => "g", "Д" => "d",
|
||||
"Е" => "e", "Ё" => "yo", "Ж" => "zh", "З" => "z", "И" => "i",
|
||||
"Й" => "j", "К" => "k", "Л" => "l", "М" => "m", "Н" => "n",
|
||||
"О" => "o", "П" => "p", "Р" => "r", "С" => "s", "Т" => "t",
|
||||
"У" => "u", "Ф" => "f", "Х" => "kh", "Ц" => "ts", "Ч" => "ch",
|
||||
"Ш" => "sh", "Щ" => "sch", "Ъ" => "", "Ы" => "y", "Ь" => "",
|
||||
"Э" => "e", "Ю" => "yu", "Я" => "ya", "а" => "a", "б" => "b",
|
||||
"в" => "v", "г" => "g", "д" => "d", "е" => "e", "ё" => "yo",
|
||||
"ж" => "zh", "з" => "z", "и" => "i", "й" => "j", "к" => "k",
|
||||
"л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p",
|
||||
"р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f",
|
||||
"х" => "kh", "ц" => "ts", "ч" => "ch", "ш" => "sh", "щ" => "sch",
|
||||
"ъ" => "", "ы" => "y", "ь" => "", "э" => "e", "ю" => "yu",
|
||||
"я" => "ya", " " => "-", "." => "", "," => "",
|
||||
":" => "", ";" => "", "—" => "", "–" => "-"
|
||||
);
|
||||
|
||||
$string = strtr($string, $table);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function delete_dir( $dir )
|
||||
{
|
||||
if ( is_file( $dir ) )
|
||||
return @unlink( $dir );
|
||||
|
||||
else if ( is_dir( $dir ) )
|
||||
{
|
||||
$scan = glob( rtrim( $dir, '/' ) . '/*' );
|
||||
|
||||
if ( is_array( $scan ) )
|
||||
foreach ( $scan as $index => $path )
|
||||
self::delete_dir( $path );
|
||||
|
||||
if ( is_dir( $dir ) && self::is_empty_dir( $dir ) )
|
||||
return @rmdir( $dir );
|
||||
}
|
||||
}
|
||||
|
||||
public static function is_empty_dir( $dir )
|
||||
{
|
||||
return ( ( $files = @scandir( $dir ) ) && count( $files ) <= 2 );
|
||||
}
|
||||
|
||||
public static function email_check( $email )
|
||||
{
|
||||
return filter_var( $email, FILTER_VALIDATE_EMAIL );
|
||||
}
|
||||
|
||||
public static function send_email( $email, $subject, $text, $replay = '', $file = '' )
|
||||
{
|
||||
global $settings;
|
||||
|
||||
if ( self::email_check( $email ) and $subject )
|
||||
{
|
||||
$mail = new PHPMailer();
|
||||
$mail -> IsSMTP();
|
||||
$mail -> SMTPAuth = true;
|
||||
$mail -> Host = $settings['email_host'];
|
||||
$mail -> Port = $settings['email_port'];
|
||||
$mail -> Username = $settings['email_login'];
|
||||
$mail -> Password = $settings['email_password'];
|
||||
$mail -> CharSet = "UTF-8";
|
||||
$mail -> SMTPOptions = array(
|
||||
'ssl' => array(
|
||||
'verify_peer' => false,
|
||||
'verify_peer_name' => false,
|
||||
'allow_self_signed' => true
|
||||
)
|
||||
);
|
||||
|
||||
if ( self::email_check( $replay ) )
|
||||
{
|
||||
$mail -> AddReplyTo( $replay, $replay );
|
||||
$mail -> SetFrom( $replay, $replay );
|
||||
}
|
||||
else
|
||||
{
|
||||
$mail -> AddReplyTo( $settings['contact_email'], $settings['firm_name'] );
|
||||
$mail -> SetFrom( $settings['contact_email'], $settings['firm_name'] );
|
||||
}
|
||||
$mail -> AddAddress( $email, '' );
|
||||
$mail -> Subject = $subject;
|
||||
$mail -> Body = $text;
|
||||
if ( is_array( $file ) )
|
||||
{
|
||||
foreach ( $file as $file_tmp )
|
||||
{
|
||||
if ( file_exists( $file_tmp ) )
|
||||
$mail -> AddAttachment( $file_tmp );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( file_exists( $file ) )
|
||||
$mail -> AddAttachment( $file );
|
||||
}
|
||||
$mail -> IsHTML( true );
|
||||
return $mail -> Send();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
91
autoload/class.Tpl.php
Normal file
91
autoload/class.Tpl.php
Normal file
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
class Tpl
|
||||
{
|
||||
protected $dir = 'templates/';
|
||||
protected $vars = array();
|
||||
|
||||
function __construct( $dir = null )
|
||||
{
|
||||
if ( $dir !== null )
|
||||
$this -> dir = $dir;
|
||||
}
|
||||
|
||||
public static function view( $file, $values = '' )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( $file );
|
||||
}
|
||||
|
||||
public function secureHTML( $val )
|
||||
{
|
||||
$out = stripslashes( $val );
|
||||
$out = str_replace( "'", "'", $out );
|
||||
$out = str_replace( '"', """, $out );
|
||||
$out = str_replace( "<", "<", $out );
|
||||
$out = str_replace( ">", ">", $out );
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function render( $file )
|
||||
{
|
||||
if ( file_exists( 'templates_user/' . $file . '.php' ) )
|
||||
{
|
||||
ob_start();
|
||||
include 'templates_user/' . $file . '.php';
|
||||
$out = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $out;
|
||||
}
|
||||
else if ( file_exists( 'templates/' . $file . '.php' ) )
|
||||
{
|
||||
ob_start();
|
||||
include 'templates/' . $file . '.php';
|
||||
$out = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $out;
|
||||
}
|
||||
else if ( file_exists( '../templates_user/' . $file . '.php' ) )
|
||||
{
|
||||
ob_start();
|
||||
include '../templates/' . $file . '.php';
|
||||
$out = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $out;
|
||||
}
|
||||
else if ( file_exists( '../templates/' . $file . '.php' ) )
|
||||
{
|
||||
ob_start();
|
||||
include '../templates/' . $file . '.php';
|
||||
$out = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $out;
|
||||
}
|
||||
else if ( file_exists( $file . '.php' ) )
|
||||
{
|
||||
ob_start();
|
||||
include $file . '.php';
|
||||
$out = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $out;
|
||||
}
|
||||
else
|
||||
return '<div class="alert alert-danger" role="alert">Nie znaleziono pliku widoku: <b>' . $this -> dir . $file . '.php</b>';
|
||||
}
|
||||
|
||||
public function __set( $name, $value )
|
||||
{
|
||||
$this -> vars[ $name ] = $value;
|
||||
}
|
||||
|
||||
public function __get( $name )
|
||||
{
|
||||
return $this -> vars[ $name ];
|
||||
}
|
||||
}
|
||||
44
autoload/cms/class.Layout.php
Normal file
44
autoload/cms/class.Layout.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?
|
||||
namespace cms;
|
||||
class Layout implements \ArrayAccess
|
||||
{
|
||||
public function __construct( int $layout_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get( 'pp_layouts', '*', [ 'id' => $layout_id ] );
|
||||
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( array_key_exists( $variable, $this -> data ) )
|
||||
return $this -> $variable;
|
||||
}
|
||||
|
||||
public function __set( $variable, $value )
|
||||
{
|
||||
$this -> $variable = $value;
|
||||
}
|
||||
|
||||
public function offsetExists( $offset )
|
||||
{
|
||||
return isset( $this -> $offset );
|
||||
}
|
||||
|
||||
public function offsetGet( $offset )
|
||||
{
|
||||
return $this -> $offset;
|
||||
}
|
||||
|
||||
public function offsetSet( $offset, $value )
|
||||
{
|
||||
$this -> $offset = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset( $offset )
|
||||
{
|
||||
unset( $this -> $offset );
|
||||
}
|
||||
}
|
||||
48
autoload/curl.class.php
Normal file
48
autoload/curl.class.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
// ------------------------------------------------
|
||||
// This is a cURL Object
|
||||
// Created by: Gilberto C.
|
||||
// InteractiveUtopia.com
|
||||
// ------------------------------------------------
|
||||
|
||||
class CurlServer
|
||||
{
|
||||
private $access_token;
|
||||
|
||||
function __construct( $token )
|
||||
{
|
||||
$this->access_token = $token;
|
||||
}
|
||||
|
||||
function post_request($url, $submitJson, $debug = false )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $submitJson);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->access_token, 'Content-Type: application/json'));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$serverReponseObject = json_decode($server_output);
|
||||
|
||||
// Debug
|
||||
if ( $debug )
|
||||
print_r($serverReponseObject);
|
||||
}
|
||||
function get_request($url)
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, false);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $this->access_token));
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$server_output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$serverReponseObject = json_decode($server_output);
|
||||
|
||||
// Debug
|
||||
//print_r ( $server_output );
|
||||
print_r($serverReponseObject);
|
||||
}
|
||||
}
|
||||
BIN
autoload/front/.DS_Store
vendored
Normal file
BIN
autoload/front/.DS_Store
vendored
Normal file
Binary file not shown.
38
autoload/front/controls/class.Newsletter.php
Normal file
38
autoload/front/controls/class.Newsletter.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
412
autoload/front/controls/class.ShopBasket.php
Normal file
412
autoload/front/controls/class.ShopBasket.php
Normal file
@@ -0,0 +1,412 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
|
||||
class ShopBasket
|
||||
{
|
||||
public static $title = [
|
||||
'main_view' => 'Koszyk'
|
||||
];
|
||||
|
||||
public static function basket_message_save()
|
||||
{
|
||||
\S::set_session( 'basket_message', \S::get( 'basket_message' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_remove_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_increase_quantity_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
$basket[ $product_hash ][ 'quantity' ]++;
|
||||
|
||||
\shop\Basket::check_product_quantity_in_stock( $basket, false );
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
]
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_decrease_quantity_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
$basket[ $product_hash ][ 'quantity' ]--;
|
||||
|
||||
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_change_quantity_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
$basket[ $product_hash ][ 'quantity' ] = (int)\S::get( 'quantity' );
|
||||
|
||||
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\shop\Basket::check_product_quantity_in_stock( $basket, false );
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function product_message_change()
|
||||
{
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$basket[ \S::get( 'position_code' ) ]['message'] = \S::get( 'product_message' );
|
||||
\S::set_session( 'basket', $basket );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_add_product()
|
||||
{
|
||||
$basket = \shop\Basket::validate_basket( \S::get_session( 'basket' ) );
|
||||
$values_tmp = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
foreach( $values_tmp as $key => $val )
|
||||
$values[ $val['name'] ] = $val['value'];
|
||||
|
||||
// sprawdzam pola pod kątem wybranych atrybutów
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
if ( $key != 'product-id' and $key != 'quantity' and $key != 'product-message' and strpos( $key, 'custom_field' ) === false )
|
||||
$attributes[] = $val;
|
||||
}
|
||||
|
||||
// stwórz tablicę dodatkowych pól wyszukując na podstawie custom_field[1], custom_field[2] itd.
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
if ( strpos( $key, 'custom_field' ) !== false )
|
||||
{
|
||||
// extract number from custom_field[1], custom_field[2] etc.
|
||||
preg_match( '/\d+/', $key, $matches );
|
||||
$custom_field_id = $matches[0];
|
||||
|
||||
$custom_fields[ $custom_field_id ] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if ( \S::is_array_fix( $attributes ) )
|
||||
{
|
||||
$values['parent_id'] = $values[ 'product-id' ];
|
||||
$values['product-id'] = \shop\Product::get_product_id_by_attributes( $values[ 'product-id' ], $attributes );
|
||||
$values['attributes'] = $attributes;
|
||||
}
|
||||
|
||||
|
||||
$values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] );
|
||||
|
||||
// generuj unikalny kod produktu dodanego do koszyka
|
||||
$product_code = md5( $values['product-id'] . implode( '|', $attributes ) . $values['product-message'] . json_encode( $custom_fields ) );
|
||||
|
||||
if ( isset( $basket[ $product_code ] ) )
|
||||
$basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ];
|
||||
else
|
||||
$basket[ $product_code ] = $values;
|
||||
|
||||
$basket[ $product_code ]['message'] = $values['product-message'];
|
||||
$basket[ $product_code ]['custom_fields'] = $custom_fields;
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
|
||||
echo json_encode( [
|
||||
'result' => 'ok',
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'product_sets' => \shop\Product::product_sets_when_add_to_basket( (int)$values['product-id'] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sprawdzam czy została wybrana forma wysylki inpost i czy został wybrany paczkomat
|
||||
static public function transport_method_inpost_check()
|
||||
{
|
||||
if ( \S::get_session( 'basket-transport-method-id' ) === '2' or \S::get_session( 'basket-transport-method-id' ) === '1' )
|
||||
{
|
||||
if ( !\S::get_session( 'basket-inpost-info' ) )
|
||||
{
|
||||
echo json_encode( [
|
||||
'result' => 'bad'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sprawdzam czy został wybrany paczkomat
|
||||
static public function inpost_check() {
|
||||
if ( !\S::get_session( 'basket-inpost-info' ) )
|
||||
echo json_encode( [
|
||||
'result' => 'bad'
|
||||
] );
|
||||
else
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function inpost_save()
|
||||
{
|
||||
\S::set_session( 'basket-inpost-info', \S::get( 'paczkomat' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_payment_method_set()
|
||||
{
|
||||
\S::set_session( 'basket-payment-method-id', \S::get( 'payment_method_id' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_transport_method_set()
|
||||
{
|
||||
\S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_payments_methods()
|
||||
{
|
||||
\S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) );
|
||||
|
||||
echo json_encode( [
|
||||
'result' => 'ok',
|
||||
'payment_methods' => \front\view\ShopPaymentMethod::basket_payment_methods(
|
||||
\front\factory\ShopPaymentMethod::payment_methods_by_transport( \S::get( 'transport_method_id' ) ),
|
||||
\S::get( 'payment_method_id' )
|
||||
)
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function summary_view()
|
||||
{
|
||||
global $lang_id, $settings;
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$client = \S::get_session( 'client' );
|
||||
|
||||
return \Tpl::view( 'shop-basket/summary-view', [
|
||||
'lang_id' => $lang_id,
|
||||
'client' => \S::get_session( 'client' ),
|
||||
'basket' => \S::get_session( 'basket' ),
|
||||
'transport' => \front\factory\ShopTransport::transport( \S::get_session( 'basket-transport-method-id' ) ),
|
||||
'payment_method' => \front\factory\ShopPaymentMethod::payment_method( \S::get_session( 'basket-payment-method-id' ) ),
|
||||
'addresses' => \front\factory\ShopClient::client_addresses( $client[ 'id' ] ),
|
||||
'settings' => $settings,
|
||||
'coupon' => \S::get_session( 'coupon' ),
|
||||
'basket_message' => \S::get_session( 'basket_message' )
|
||||
] );
|
||||
}
|
||||
|
||||
// zapisanie koszyka jako zamówienie
|
||||
static public function basket_save()
|
||||
{
|
||||
$client = \S::get_session( 'client' );
|
||||
$payment_method = \S::get_session( 'basket-payment-method-id' );
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $order_id = \front\factory\ShopOrder::basket_save(
|
||||
$client[ 'id' ], \S::get_session( 'basket' ), \S::get_session( 'basket-transport-method-id' ), \S::get_session( 'basket-payment-method-id' ),
|
||||
\S::get( 'email', true ), \S::get( 'phone', true ), \S::get( 'name', true ), \S::get( 'surname', true ), \S::get( 'firm', true ), \S::get( 'street' ), \S::get( 'postal_code', true ), \S::get( 'city', true ),
|
||||
\S::get_session( 'basket-inpost-info' ), \S::get_session( 'coupon' ), \S::get_session( 'basket_message' )
|
||||
) )
|
||||
{
|
||||
\S::alert( \S::lang( 'zamowienie-zostalo-zlozone-komunikat' ) );
|
||||
\S::delete_session( 'basket' );
|
||||
\S::delete_session( 'basket-transport-method-id' );
|
||||
\S::delete_session( 'basket-payment-method-id' );
|
||||
\S::delete_session( 'basket-inpost-info' );
|
||||
\S::delete_session( 'coupon' );
|
||||
\S::delete_session( 'basket_message' );
|
||||
|
||||
\S::set_session( 'piksel_purchase', true );
|
||||
\S::set_session( 'google-adwords-purchase', true );
|
||||
\S::set_session( 'google-analytics-purchase', true );
|
||||
\S::set_session( 'ekomi-purchase', true );
|
||||
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
$redis -> flushAll();
|
||||
|
||||
header( 'Location: /zamowienie/' . \front\factory\ShopOrder::order_hash( $order_id ) );
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::error( \S::lang( 'zamowienie-zostalo-zlozone-komunikat-blad' ) );
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public static function main_view()
|
||||
{
|
||||
global $lang_id, $page, $settings;
|
||||
|
||||
$page[ 'language' ][ 'meta_title' ] = 'Koszyk';
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$payment_method_id = \S::get_session( 'payment_method_id' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( $basket ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
return \Tpl::view( 'shop-basket/basket', [
|
||||
'basket' => $basket,
|
||||
'coupon' => $coupon,
|
||||
'transport_id' => \S::get_session( 'basket-transport-method-id' ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] ),
|
||||
'payment_method_id' => $payment_method_id,
|
||||
'basket_details' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon,
|
||||
'basket_message' => \S::get_session( 'basket_message' ),
|
||||
'settings' => $settings
|
||||
] )
|
||||
] );
|
||||
}
|
||||
|
||||
}
|
||||
212
autoload/front/controls/class.ShopClient.php
Normal file
212
autoload/front/controls/class.ShopClient.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopClient
|
||||
{
|
||||
public static function mark_address_as_current()
|
||||
{
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
return false;
|
||||
|
||||
\front\factory\ShopClient::mark_address_as_current( $client['id'], \S::get( 'address_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function address_delete()
|
||||
{
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = \front\factory\ShopClient::address_details( \S::get( 'id' ) );
|
||||
if ( $address['client_id'] != $client['id'] )
|
||||
{
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \front\factory\ShopClient::address_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( \S::lang( 'adres-usuniety-komunikat' ) );
|
||||
else
|
||||
\S::error( \S::lang( 'adres-usuniety-blad' ) );
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function address_edit()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-edycja-adresu' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = \front\factory\ShopClient::address_details( \S::get( 'id' ) );
|
||||
if ( $address['client_id'] != $client['id'] )
|
||||
unset( $address );
|
||||
|
||||
return \front\view\ShopClient::address_edit( [
|
||||
'address' => \front\factory\ShopClient::address_details( \S::get( 'id' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function address_save()
|
||||
{
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \front\factory\ShopClient::address_save( $client['id'], \S::get( 'address_id' ), \S::get( 'name', true ), \S::get( 'surname', true ), \S::get( 'firm', true ), \S::get( 'street' ), \S::get( 'postal_code', true ), \S::get( 'city', true ), \S::get( 'phone', true ) ) )
|
||||
{
|
||||
\S::get( 'address_id' ) ? \S::alert( \S::lang( 'zmiana-adresu-sukces' ) ) : \S::alert( \S::lang( 'dodawanie-nowego-adresu-sukces' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::get( 'address_id' ) ? \S::error( \S::lang( 'zmiana-adresu-blad' ) ) : \S::error( \S::lang( 'dodawanie-nowego-adresu-blad' ) );
|
||||
}
|
||||
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function client_addresses()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-lista-adresow' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::client_addresses( [
|
||||
'client' => $client,
|
||||
'addresses' => \front\factory\ShopClient::client_addresses( $client['id'] )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function client_orders()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-historia-zamowien' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::client_orders( [
|
||||
'client' => $client,
|
||||
'orders' => \front\factory\ShopClient::client_orders( $client['id'] ),
|
||||
'statuses' => \shop\Order::order_statuses()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function new_password()
|
||||
{
|
||||
if ( \front\factory\ShopClient::new_password( \S::get( 'hash' ) ) )
|
||||
\S::alert( \S::lang( 'nowe-haslo-zostalo-wyslane-na-twoj-adres-email' ) );
|
||||
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function send_email_password_recovery()
|
||||
{
|
||||
if ( \front\factory\ShopClient::send_email_password_recovery( \S::get( 'email' ) ) )
|
||||
\S::alert( \S::lang( 'odzyskiwanie-hasla-link-komunikat' ) );
|
||||
else
|
||||
\S::alert( \S::lang( 'odzyskiwanie-hasla-blad' ) );
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function recover_password()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-odzyskiwanie-hasla' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
return \front\view\ShopClient::recover_password();
|
||||
}
|
||||
|
||||
public static function logout()
|
||||
{
|
||||
\S::delete_session( 'client' );
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function login()
|
||||
{
|
||||
if ( !\front\factory\ShopClient::login( \S::get( 'email' ), \S::get( 'password' ) ) )
|
||||
header( 'Location: /logowanie' );
|
||||
else
|
||||
{
|
||||
$client = \S::get_session( 'client' );
|
||||
if ( $redirect = \S::get( 'redirect' ) )
|
||||
header( 'Location: ' . $redirect );
|
||||
else
|
||||
header( 'Location: /panel-klienta' );
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function confirm()
|
||||
{
|
||||
if ( \front\factory\ShopClient::register_confirm( \S::get( 'hash' ) ) )
|
||||
\S::alert( \S::lang( 'rejestracja-potwierdzenie' ) );
|
||||
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function signup()
|
||||
{
|
||||
$result = \front\factory\ShopClient::signup( \S::get( 'email' ), \S::get( 'password' ), \S::get( 'agremment_marketing' ) );
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function login_form()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-logowanie' ) . ' | ' . $settings['firm_name'];
|
||||
$page['class'] = 'page-login-form';
|
||||
|
||||
if ( $client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /panel-klienta/zamowienia' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::login_form();
|
||||
}
|
||||
|
||||
public static function register_form()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-rejestracja' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( $client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /panel-klienta/zamowienia' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::register_form();
|
||||
}
|
||||
}
|
||||
25
autoload/front/controls/class.ShopCoupon.php
Normal file
25
autoload/front/controls/class.ShopCoupon.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopCoupon
|
||||
{
|
||||
public static function delete_coupon()
|
||||
{
|
||||
\S::delete_session( 'coupon' );
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function use_coupon()
|
||||
{
|
||||
$coupon = new \shop\Coupon( 0 );
|
||||
$coupon -> load_from_db_by_name( (string)\S::get( 'coupon' ) );
|
||||
|
||||
if ( $coupon -> is_available() )
|
||||
\S::set_session( 'coupon', $coupon );
|
||||
else
|
||||
\S::alert( 'Podany kod rabatowy jest nieprawidłowy.' );
|
||||
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
152
autoload/front/controls/class.ShopOrder.php
Normal file
152
autoload/front/controls/class.ShopOrder.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopOrder
|
||||
{
|
||||
public static function payment_confirmation()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$order = \front\factory\ShopOrder::order_details( null, \S::get( 'order_hash' ) );
|
||||
|
||||
return \Tpl::view( 'shop-order/payment-confirmation', [
|
||||
'order' => $order,
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
|
||||
public static function payment_status_tpay()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \S::get( 'tr_status' ) == 'TRUE' and \S::get( 'tr_crc' ) )
|
||||
{
|
||||
$order = new \shop\Order( 0, \S::get( 'tr_crc' ) );
|
||||
|
||||
if ( $order -> id )
|
||||
{
|
||||
$order -> set_as_paid( true );
|
||||
$order -> update_status( 4, true );
|
||||
echo 'TRUE';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo 'FALSE';
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function payment_status_przelewy24pl()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$post = [
|
||||
'p24_merchant_id' => \S::get( 'p24_merchant_id' ),
|
||||
'p24_pos_id' => \S::get( 'p24_pos_id' ),
|
||||
'p24_session_id' => \S::get( 'p24_session_id' ),
|
||||
'p24_amount' => \S::get( 'p24_amount' ),
|
||||
'p24_currency' => \S::get( 'p24_currency' ),
|
||||
'p24_order_id' => \S::get( 'p24_order_id' ),
|
||||
'p24_sign' => md5( \S::get( 'p24_session_id' ) . '|' . \S::get( 'p24_order_id' ) . '|' . \S::get( 'p24_amount' ) . '|' . \S::get( 'p24_currency' ) . '|' . $settings['przelewy24_crc_key'] )
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
if ( $settings['przelewy24_sandbox'] )
|
||||
curl_setopt( $ch, CURLOPT_URL, 'https://sandbox.przelewy24.pl/trnVerify' );
|
||||
if ( !$settings['przelewy24_sandbox'] )
|
||||
curl_setopt( $ch, CURLOPT_URL, 'https://secure.przelewy24.pl/trnVerify' );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
|
||||
$response = curl_exec( $ch );
|
||||
|
||||
$order = new \shop\Order( 0, '', \S::get( 'p24_session_id' ) );
|
||||
|
||||
if ( $order['status'] == 0 and $order['summary'] * 100 == \S::get( 'p24_amount' ) )
|
||||
{
|
||||
if ( $order['id'] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 1, 'paid' => 1 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 1, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 4;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Zamówienie opłacone przez przelewy24 | ID: ' . $order['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function payment_status_hotpay()
|
||||
{
|
||||
global $mdb, $lang;
|
||||
|
||||
if ( !empty( $_POST["KWOTA"] ) && !empty( $_POST["ID_PLATNOSCI"] ) && !empty( $_POST["ID_ZAMOWIENIA"] ) && !empty( $_POST["STATUS"] ) && !empty( $_POST["SEKRET"] ) && !empty( $_POST["HASH"] ) )
|
||||
{
|
||||
$order = new \shop\Order( $_POST['ID_ZAMOWIENIA'] );
|
||||
|
||||
if ( $order['id'] )
|
||||
{
|
||||
if ( is_array( $order['products'] ) and count( $order['products'] ) ):
|
||||
foreach ( $order['products'] as $product ):
|
||||
$product_tmp = \front\factory\ShopProduct::product_details( $product['product_id'], $lang['id'] );
|
||||
$summary_tmp += \S::normalize_decimal( $product['price_netto'] + $product['price_netto'] * $product['vat'] / 100 ) * $product['quantity'];
|
||||
endforeach;
|
||||
$summary_tmp += $order['transport_cost'];
|
||||
endif;
|
||||
|
||||
if ( hash( "sha256", "ProjectPro1916;" . round( $summary_tmp, 2 ) . ";" . $_POST["ID_PLATNOSCI"] . ";" . $_POST["ID_ZAMOWIENIA"] . ";" . $_POST["STATUS"] . ";" . $_POST["SEKRET"] ) == $_POST["HASH"] )
|
||||
{
|
||||
if ( $_POST["STATUS"] == "SUCCESS" )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 1, 'paid' => 1 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 1, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 4;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Zamówienie opłacone przez hotpay | ID: ' . $order['id'] );
|
||||
|
||||
echo \S::lang( 'zamowienie-zostalo-oplacone' );
|
||||
}
|
||||
else if ( $_POST["STATUS"] == "FAILURE" )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 2 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 2, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 2;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Płatność odrzucona hotpay | ID: ' . $order['id'] );
|
||||
|
||||
echo \S::lang( 'platnosc-zostala-odrzucona' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 3 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 3, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 3;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Płatność sprawdzana ręcznie hotpay | ID: ' . $order['id'] );
|
||||
|
||||
echo \S::lang( 'zamowienie-zostalo-oplacone-reczne' );
|
||||
}
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function order_details()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-szczegoly-zamowienia' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
return \Tpl::view( 'shop-order/order-details', [
|
||||
'order' => \front\factory\ShopOrder::order_details(
|
||||
\front\factory\ShopOrder::order_id( \S::get( 'order_hash' ) )
|
||||
),
|
||||
'client' => \S::get_session( 'client' ),
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
}
|
||||
48
autoload/front/controls/class.ShopProducer.php
Normal file
48
autoload/front/controls/class.ShopProducer.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?
|
||||
namespace front\controls;
|
||||
class ShopProducer
|
||||
{
|
||||
static public function products()
|
||||
{
|
||||
global $page, $lang_id;
|
||||
|
||||
$producer = new \shop\Producer( \S::get( 'producer_id' ) );
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = $producer['name'];
|
||||
|
||||
$results = \shop\Producer::producer_products( $producer['id'], $lang_id, (int) \S::get( 'bs' ) );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$pager = \Tpl::view( 'site/pager', [
|
||||
'ls' => $results['ls'],
|
||||
'bs' => (int) \S::get( 'bs' ) ? (int) \S::get( 'bs' ) : 1,
|
||||
'page' => $page,
|
||||
'link' => 'producent/' . \S::seo( $producer['name'] )
|
||||
] );
|
||||
}
|
||||
|
||||
return \Tpl::view( 'shop-producer/products', [
|
||||
'producer' => $producer,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager
|
||||
] );
|
||||
}
|
||||
|
||||
static public function list()
|
||||
{
|
||||
global $mdb, $page;
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = 'Producenci';
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_producer', 'id', [ 'status' => 1, 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
if ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
$producers[] = new \shop\Producer( $row );
|
||||
|
||||
return \Tpl::view( 'shop-producer/list', [
|
||||
'producers' => $producers
|
||||
] );
|
||||
}
|
||||
}
|
||||
63
autoload/front/controls/class.ShopProduct.php
Normal file
63
autoload/front/controls/class.ShopProduct.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
use shop\Product;
|
||||
|
||||
class ShopProduct
|
||||
{
|
||||
static public function lazy_loading_products()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$output = '';
|
||||
$products_ids = \front\factory\ShopCategory::products_id( \S::get( 'category_id' ), \front\factory\ShopCategory::get_category_sort( (int)\S::get( 'category_id' ) ), $lang_id, 8, \S::get( 'offset' ) );
|
||||
|
||||
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
|
||||
$output .= \Tpl::view('shop-product/product-mini', [
|
||||
'product' => Product::getFromCache( $product_id, $lang_id )
|
||||
] );
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
echo json_encode( [ 'html' => $output ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function warehouse_message()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
if ( $key != 'product-id' and $key != 'quantity' )
|
||||
$attributes[] = $val;
|
||||
}
|
||||
|
||||
$result = \shop\Product::getWarehouseMessage( $values['product-id'], $attributes, $lang_id );
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
// wyświetlenie atrybutów w widoku produktu
|
||||
static public function draw_product_attributes()
|
||||
{
|
||||
global $mdb, $lang_id;
|
||||
|
||||
$combination = '';
|
||||
|
||||
$selected_values = \S::get( 'selected_values' );
|
||||
foreach ( $selected_values as $value ) {
|
||||
$combination .= $value;
|
||||
if ( $value != end( $selected_values ) )
|
||||
$combination .= '|';
|
||||
}
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$product = Product::getFromCache( $product_id, $lang_id );
|
||||
$product_data = $product -> getProductDataBySelectedAttributes( $combination );
|
||||
|
||||
echo json_encode( [ 'product_data' => $product_data ] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
136
autoload/front/controls/class.Site.php
Normal file
136
autoload/front/controls/class.Site.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
|
||||
class Site
|
||||
{
|
||||
static public function page_title()
|
||||
{
|
||||
$class = '\front\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$property = \S::get( 'action' );
|
||||
if ( class_exists( $class ) and property_exists( new $class, 'page_title' ) )
|
||||
return $class::$title[$property];
|
||||
}
|
||||
|
||||
static public function title()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$class = '\front\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$property = \S::get( 'action' );
|
||||
if ( class_exists( $class ) and property_exists( new $class, 'title' ) )
|
||||
return $class::$title[$property] . ' | ' . $settings['firm_name'];
|
||||
}
|
||||
|
||||
public static function route( $product = '', $category = '' )
|
||||
{
|
||||
global $page, $lang_id, $settings;
|
||||
|
||||
if ( \S::get( 'article' ) )
|
||||
return \front\view\Articles::full_article( \S::get( 'article' ), $lang_id );
|
||||
|
||||
// wyświetlenie pojedynczego produktu
|
||||
if ( $product )
|
||||
{
|
||||
\shop\Product::add_visit( $product -> id );
|
||||
return \Tpl::view( 'shop-product/product', [
|
||||
'product' => $product,
|
||||
'settings' => $settings,
|
||||
'lang_id' => $lang_id,
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
|
||||
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 );
|
||||
|
||||
$action = \S::get( 'action' );
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $action ) )
|
||||
return call_user_func_array( array( $class, $action ), array() );
|
||||
|
||||
// klasy sklepowe
|
||||
$class = '\shop\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$action = \S::get( 'action' );
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $action ) )
|
||||
return call_user_func_array( array( $class, $action ), array() );
|
||||
|
||||
if ( $page['id'] )
|
||||
{
|
||||
switch ( $page['page_type'] )
|
||||
{
|
||||
/* pełne artykuły */
|
||||
case 0:
|
||||
return \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
break;
|
||||
|
||||
/* wprowadzenia */
|
||||
case 1:
|
||||
return \front\view\Articles::entry_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
break;
|
||||
|
||||
/* miniaturki */
|
||||
case 2:
|
||||
return \front\view\Articles::miniature_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
break;
|
||||
|
||||
/* strona kontaktu */
|
||||
case 4:
|
||||
$out = \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
$out .= \front\view\Site::contact();
|
||||
return $out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_url_params()
|
||||
{
|
||||
global $lang, $config;
|
||||
|
||||
$a = \S::get( 'a' );
|
||||
|
||||
switch ( $a )
|
||||
{
|
||||
case 'page':
|
||||
$page = \front\factory\Pages::page_details( \S::get( 'id' ) );
|
||||
\S::set_session( 'page', $page );
|
||||
break;
|
||||
|
||||
case 'change_language':
|
||||
\S::set_session( 'current-lang', \S::get( 'id' ) );
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( \S::get( 'lang' ) )
|
||||
\S::set_session( 'current-lang', \S::get( 'lang' ) );
|
||||
|
||||
if ( file_exists( 'modules/actions.php' ) )
|
||||
include 'modules/actions.php';
|
||||
}
|
||||
}
|
||||
?>
|
||||
317
autoload/front/factory/class.Articles.php
Normal file
317
autoload/front/factory/class.Articles.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
class Articles
|
||||
{
|
||||
static public 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;
|
||||
}
|
||||
}
|
||||
|
||||
// funkcja wywoływana dla każdego dopasowania do wyrażenia regularnego
|
||||
static public 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) { // jeśli nie ma atrybutu id
|
||||
$id = \S::seo( $content );
|
||||
$attrs .= sprintf(' id="%s"', $id);
|
||||
}
|
||||
|
||||
$html = sprintf( '<h%d%s>%s</h%d>', $level, $attrs, $content, $level );
|
||||
return $html;
|
||||
}
|
||||
|
||||
static public function generateHeadersIds( $text )
|
||||
{
|
||||
$pattern = '/<h([1-6])(.*?)>(.*?)<\/h\1>/si';
|
||||
|
||||
$text = preg_replace_callback( $pattern, array(__CLASS__, 'processHeaders'), $text );
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
public static function news( $page_id, $limit = 6, $lang_id )
|
||||
{
|
||||
$sort = \front\factory\Pages::page_sort( $page_id );
|
||||
|
||||
$articles_id = \front\factory\Articles::artciles_id( (int)$page_id, $lang_id, $limit, $sort, 0 );
|
||||
if ( is_array( $articles_id ) and !empty( $articles_id ) ) foreach ( $articles_id as $article_id )
|
||||
$articles[] = \front\factory\Articles::article_details( $article_id, $lang_id );
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public static function get_image( $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;
|
||||
}
|
||||
|
||||
public static function article_noindex( $article_id )
|
||||
{
|
||||
global $mdb, $lang;
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheKey = "\front\factory\Articles::article_noindex:$article_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$noindex = $mdb -> get( 'pp_articles_langs', 'noindex', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang[0] ] ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $noindex );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
return $noindex;
|
||||
}
|
||||
|
||||
public static function page_articles( $page, $lang_id, $bs )
|
||||
{
|
||||
$count = \front\factory\Articles::page_articles_count( $page['id'], $lang_id );
|
||||
$ls = ceil( $count / $page['articles_limit'] );
|
||||
|
||||
if ( $bs < 1 )
|
||||
$bs = 1;
|
||||
else if ( $bs > $ls )
|
||||
$bs = $ls;
|
||||
|
||||
$from = $page['articles_limit'] * ( $bs - 1 );
|
||||
|
||||
if ( $from < 0 )
|
||||
$from = 0;
|
||||
|
||||
$results['articles'] = \front\factory\Articles::artciles_id( (int)$page['id'], $lang_id, (int)$page['articles_limit'], $page['sort_type'], $from );
|
||||
$results['ls'] = $ls;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function article_details( $article_id, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheKey = "\front\factory\Articles::article_details:$article_id:$lang_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang_id ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( $row['copy_from'] )
|
||||
{
|
||||
$results2 = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $row['copy_from'] ] ] );
|
||||
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
$article['language'] = $row2;
|
||||
}
|
||||
else
|
||||
$article['language'] = $row;
|
||||
}
|
||||
|
||||
$article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'DESC' ] ] );
|
||||
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
|
||||
$article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $article );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function artciles_id( $page_id, $lang_id, $articles_limit, $sort_type, $from )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
switch ( $sort_type )
|
||||
{
|
||||
case 0: $order = 'date_add ASC'; break;
|
||||
case 1: $order = 'date_add DESC'; break;
|
||||
case 2: $order = 'date_modify ASC'; break;
|
||||
case 3: $order = 'date_modify DESC'; break;
|
||||
case 4: $order = 'o ASC'; break;
|
||||
case 5: $order = 'title ASC'; break;
|
||||
case 6: $order = 'title DESC'; break;
|
||||
default: $order = 'id ASC'; break;
|
||||
}
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheKey = "\front\factory\Artiles::artciles_id:$page_id:$lang_id:$articles_limit:$sort_type:$from:$order";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$results = $mdb -> query( 'SELECT * FROM ( '
|
||||
. 'SELECT '
|
||||
. 'a.id, date_modify, date_add, o, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN title '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = al.copy_from AND article_id = a.id '
|
||||
. ') '
|
||||
. 'END ) AS title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.title IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. 'q1.' . $order . ' '
|
||||
. 'LIMIT '
|
||||
. (int)$from . ',' . (int)$articles_limit ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$output[] = $row['id'];
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $output );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize($objectData);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function page_articles_count( $page_id, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \CacheHandler();
|
||||
$cacheKey = "\front\factory\Articles::page_articles_count:$page_id:$lang_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$results = $mdb -> query( 'SELECT COUNT(0) FROM ( '
|
||||
. 'SELECT '
|
||||
. 'a.id, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN title '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = al.copy_from AND article_id = a.id '
|
||||
. ') '
|
||||
. 'END ) AS title '
|
||||
. 'FROM '
|
||||
. 'pp_articles_pages AS ap '
|
||||
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
|
||||
. 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.title IS NOT NULL' ) -> fetchAll();
|
||||
$articles_count = $results[0][0];
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $articles_count );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $articles_count;
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user