first commit

This commit is contained in:
2026-02-28 11:43:07 +01:00
commit 1946f96bf8
5772 changed files with 817711 additions and 0 deletions

View File

@@ -0,0 +1,216 @@
<?php
namespace admin;
class Site
{
// define APP_SECRET_KEY
const APP_SECRET_KEY = 'c3cb2537d25c0efc9e573d059d79c3b8';
public static function special_actions()
{
$sa = \S::get('s-action');
$domain = preg_replace('#^(http(s)?://)?w{3}\.#', '$1', $_SERVER['SERVER_NAME']);
$cookie_name = str_replace('.', '-', $domain);
switch ($sa)
{
case 'user-logon':
{
$login = \S::get('login');
$pass = \S::get('password');
$result = \admin\factory\Users::logon($login, $pass);
if ($result == 1)
{
$user = \admin\factory\Users::details($login);
if ($user['twofa_enabled'] == 1)
{
\S::set_session('twofa_pending', [
'uid' => (int)$user['id'],
'login' => $login,
'remember' => (bool)\S::get('remember'),
'started' => time(),
]);
if (!\admin\factory\Users::send_twofa_code((int)$user['id']))
{
\S::alert('Nie udało się wysłać kodu 2FA. Spróbuj ponownie.');
\S::delete_session('twofa_pending');
header('Location: /admin/');
exit;
}
header('Location: /admin/user/twofa/');
exit;
}
else
{
$user = \admin\factory\Users::details($login);
self::finalize_admin_login(
$user,
$domain,
$cookie_name,
(bool)\S::get('remember')
);
header('Location: /admin/articles/view_list/');
exit;
}
}
else
{
if ($result == -1)
{
\S::alert('Z powodu 5 nieudanych prób Twoje konto zostało zablokowane.');
}
else
{
\S::alert('Podane hasło jest nieprawidłowe lub użytkownik nie istnieje.');
}
header('Location: /admin/');
exit;
}
}
break;
case 'user-2fa-verify':
{
$pending = \S::get_session('twofa_pending');
if (!$pending || empty($pending['uid']))
{
\S::alert('Sesja 2FA wygasła. Zaloguj się ponownie.');
header('Location: /admin/');
exit;
}
$code = trim((string)\S::get('twofa'));
if (!preg_match('/^\d{6}$/', $code))
{
\S::alert('Nieprawidłowy format kodu.');
header('Location: /admin/user/twofa/');
exit;
}
$ok = \admin\factory\Users::verify_twofa_code((int)$pending['uid'], $code);
if (!$ok)
{
\S::alert('Błędny lub wygasły kod.');
header('Location: /admin/user/twofa/');
exit;
}
// 2FA OK — finalna sesja
$user = \admin\factory\Users::details($pending['login']);
\S::set_session('user', $user);
\S::delete_session('twofa_pending');
// Remember me BEZPIECZNY podpis HMAC:
if (!empty($pending['remember']))
{
$payloadArr = ['login' => $user['login'], 'ts' => time()];
$json = json_encode($payloadArr, JSON_UNESCAPED_SLASHES);
$sig = hash_hmac('sha256', $json, APP_SECRET_KEY);
$payload = base64_encode($json . '.' . $sig);
setcookie($cookie_name, $payload, [
'expires' => time() + (86400 * 14),
'path' => '/',
'domain' => $domain,
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);
}
header('Location: /admin/articles/view_list/');
exit;
}
break;
case 'user-2fa-resend':
{
$pending = \S::get_session('twofa_pending');
if (!$pending || empty($pending['uid']))
{
\S::alert('Sesja 2FA wygasła. Zaloguj się ponownie.');
header('Location: /admin/');
exit;
}
if (!\admin\factory\Users::send_twofa_code((int)$pending['uid'], true))
{
\S::alert('Kod można wysłać ponownie po krótkiej przerwie.');
}
else
{
\S::alert('Nowy kod został wysłany.');
}
header('Location: /admin/user/twofa/');
exit;
}
break;
case 'user-logout':
{
setcookie($cookie_name, "", time() - 86400, "/", $domain);
\S::delete_session('twofa_pending');
session_destroy();
header('Location: /admin/');
exit;
}
break;
}
}
public static function route()
{
$_SESSION['admin'] = true;
$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 finalize_admin_login(array $user, string $domain, string $cookie_name, bool $remember = false) {
\S::set_session('user', $user);
\S::delete_session('twofa_pending');
if ($remember)
{
$payloadArr = [
'login' => $user['login'],
'ts' => time()
];
$json = json_encode($payloadArr, JSON_UNESCAPED_SLASHES);
$sig = hash_hmac('sha256', $json, self::APP_SECRET_KEY);
$payload = base64_encode($json . '.' . $sig);
setcookie($cookie_name, $payload, [
'expires' => time() + (86400 * 14),
'path' => '/',
'domain' => $domain,
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);
}
}
}

View File

@@ -0,0 +1,163 @@
<?php
namespace admin\controls;
class Articles
{
//autorzy artykułów
static public function articles_authors()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( 'articles/articles-authors' );
}
public static function duplicate_article()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
if ( \admin\factory\Articles::duplicate_article( \S::get( 'id' ) ) )
\S::alert( 'Artykuł został zuplikowany' );
header( 'Location: /admin/articles/view_list/' );
exit;
}
static public function files_order_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
{
echo json_encode( [ 'status' => 'error', 'msg' => 'Nie masz uprawnień' ] );
exit;
}
if ( \admin\factory\Articles::files_order_save( \S::get( 'article_id' ), \S::get( 'order' ) ) )
echo json_encode( [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.' ] );
exit;
}
public static function gallery_order_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
{
echo json_encode( [ 'status' => 'error', 'msg' => 'Nie masz uprawnień' ] );
exit;
}
if ( \admin\factory\Articles::gallery_order_save( \S::get( 'article_id' ), \S::get( 'order' ) ) )
echo json_encode( [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.' ] );
exit;
}
static public function article_url_browser()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( 'articles/articles-browse-list', [
'modal' => true
] );
}
public static function browse_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Articles::browse_list();
}
public static function article_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania artykułu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
if ( is_array( $values ) ) foreach ( $values as $key => $val )
{
if ( strpos( $key, 'ap_' ) !== false )
$params[$key] = $val;
}
$values['params'] = $params;
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['event_date'], $values['hidden-tags'], $values['block_direct_access'],
$values['priority'], $values['password'], $values['pixieset'], $values['id_author'], $params
) )
$response = [ 'status' => 'ok', 'msg' => 'Artykuł został zapisany.', 'id' => $id ];
\admin\factory\Articles::insert_missing_hash();
echo json_encode( $response );
exit;
}
public static function article_edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
\admin\factory\Articles::delete_nonassigned_images();
\admin\factory\Articles::delete_nonassigned_files();
return \admin\view\Articles::article_edit( [
'article' => \admin\factory\Articles::article_details( \S::get( 'id' ) ),
'menus' => \admin\factory\Pages::menus_list(),
'languages' => \admin\factory\Languages::languages_list(),
'layouts' => \admin\factory\Layouts::layouts_list(),
'additional_params_lon' => \admin\factory\Articles::additional_params( 1 ),
'additional_params_loff' => \admin\factory\Articles::additional_params( 0 ),
'settings' => \admin\factory\Settings::settings_details(),
'authors' => \admin\factory\Authors::get_simple_list(),
'user' => $user
] );
}
public static function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Brak uprawnień.' );
return \admin\view\Articles::articles_list();
}
}
?>

View File

@@ -0,0 +1,44 @@
<?php
namespace admin\controls;
class ArticlesArchive
{
public static function article_restore()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\ArticlesArchive::articles_list();
}
}

View File

@@ -0,0 +1,65 @@
<?
namespace admin\controls;
class Authors
{
// usunięcie autora
static public function delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas usuwania autora wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
if ( \admin\factory\Authors::delete_author( \S::get( 'id' ) ) )
\S::alert( 'Autor został usunięty.' );
header( 'Location: /admin/authors/view_list/' );
exit;
}
// zapis autora
static public function save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania autora wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
if ( $author_id = \admin\factory\Authors::save_author( $values['id'], $values['author'], $values['image'], $values['description'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Autor został zapisany.', 'id' => $author_id ];
echo json_encode( $response );
exit;
}
// edycja autora
static public function edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( 'authors/author-edit', [
'author' => \admin\factory\Authors::get_single_author( \S::get( 'id' ) ),
'languages' => \admin\factory\Languages::languages_list()
] );
}
//autorzy artykułów
static public function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'article_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( 'authors/view-list' );
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace admin\controls;
class Backups
{
public static function download_restore_file()
{
$file = '../restore.php';
if ( file_exists( $file ) )
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize( $file ) );
readfile( $file );
exit;
}
}
public static function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'backups_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Backups::backups_list(
\admin\factory\Backups::backups_list()
);
}
public static function backup_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'backups_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = 'Podczas tworzenia kopi zapasowej wystąpił błąd. Proszę spróbować ponownie.';
if ( \admin\factory\Backups::backup_save() )
\S::alert( 'Kopia zapasowa został utworzona.' );
header( 'Location: /admin/backups/view_list/' );
exit;
}
public static function backup_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'backups_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = 'Podczas usuwania kopi zapasowej wystąpił błąd. Proszę spróbować ponownie.';
if ( \admin\factory\Backups::backup_delete( \S::get( 'name' ) ) )
\S::alert( 'Kopia zapasowa został usunięta.' );
header( 'Location: /admin/backups/view_list/' );
exit;
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace admin\controls;
class Banners
{
public static function banner_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'baners_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'baners_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania baneru wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'baners_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Banners::banner_edit(
\admin\factory\Banners::banner_details(
\S::get( 'id' )
),
\admin\factory\Languages::languages_list()
);
}
public static function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'baners_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Banners::banners_list();
}
}
?>

View File

@@ -0,0 +1,28 @@
<?php
namespace admin\controls;
class Emails{
public static function view_list()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'emails_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Emails::emails_list();
}
public static function email_details()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'emails_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Emails::email_details(
\admin\factory\Emails::email_details(
\S::get( 'id' )
)
);
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace admin\controls;
class Filemanager
{
public function draw()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'fileManager_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\FileManager::filemanager();
}
}
?>

View File

@@ -0,0 +1,126 @@
<?
namespace admin\controls;
class Languages
{
public static function language_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania języka wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
if ( \admin\factory\Languages::language_save(
$values['id'], $values['name'], $values['status'], $values['start'], $values['o'], $values['domain'], $values['main_domain']
) )
$response = [ 'status' => 'ok', 'msg' => 'Język został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function language_edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Languages::language_edit(
\admin\factory\Languages::language_details(
\S::get( 'id' )
), \admin\factory\Languages::max_order()
);
}
public static function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Languages::languages_list();
}
public static function translation_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania tłumaczenia wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
$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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Languages::translation_edit(
\admin\factory\Languages::translation_details( \S::get( 'id' ) ),
\admin\factory\Languages::languages_list()
);
}
public static function translation_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'language_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Languages::translations_list();
}
}
?>

View File

@@ -0,0 +1,59 @@
<?php
namespace admin\controls;
class Layouts
{
public static function layout_delete()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'template_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
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()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'template_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania szablonu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
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'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Szablon został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function layout_edit()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'template_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Layouts::layout_edit(
\admin\factory\Layouts::layout_details(
\S::get( 'id' )
),
\admin\factory\Layouts::menus_list()
);
}
public static function view_list()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'template_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Layouts::layouts_list();
}
}
?>

View File

@@ -0,0 +1,167 @@
<?php
namespace admin\controls;
class Newsletter
{
public static function emails_import()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$values = \S::json_to_array( \S::get( 'values' ) );
if ( \admin\factory\Newsletter::emails_import( $values['emails'] ) )
\S::alert( 'Emaile zostały zaimportowane.' );
echo json_encode( [ 'status' => 'ok', 'msg' => 'Emaile zostały zaimportowane.' ] );
exit;
}
public static function import()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( 'newsletter/import' );
}
public static function emails_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
return \admin\view\Newsletter::emails_list();
}
public static function send()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
if ( \admin\factory\Newsletter::send( \S::get( 'dates' ), \S::get( 'template' ), \S::get( 'only_once' ) ) )
\S::alert( 'Newsletter został dodany do kolejki wysyłania.' );
header( 'Location: /admin/newsletter/prepare/' );
exit;
}
public static function prepare()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
return \admin\view\Newsletter::prepare(
\admin\factory\Newsletter::templates_list()
);
}
public static function settings_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$values = \S::json_to_array( \S::get( 'values' ) );
\admin\factory\Settings::settings_update( 'newsletter_footer_1', $values['newsletter_footer_1'] );
\admin\factory\Settings::settings_update( 'newsletter_footer_2', $values['newsletter_footer_2'] );
\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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Newsletter::settings(
\admin\factory\Settings::settings_details()
);
}
public static function email_templates_user()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
return \admin\view\Newsletter::email_templates_user();
}
public static function email_templates_admin()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
return \admin\view\Newsletter::email_templates_admin();
}
public static function email_template_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Newsletter::email_template_edit(
\admin\factory\Newsletter::email_template_detalis(
\S::get( 'id' )
)
);
}
public static function template_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'newsletter_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
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;
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace admin\controls;
class Pages
{
static public function pages_url_browser()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( 'pages/pages-browse-list', [
'menus' => \admin\factory\Pages::menus_list(),
'modal' => true
] );
}
static public function browse_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Pages::browse_list(
\admin\factory\Pages::menus_list()
);
}
public static function menu_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Pages::page_articles( \S::get( 'id' ),
\admin\factory\Pages::page_articles( \S::get( 'id' ) ) );
}
public static function page_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania strony wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
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['site_title'], $values['block_direct_access'], $values['cache'], $values['canonical']
) )
$response = [ 'status' => 'ok', 'msg' => 'Strona została zapisana.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function page_edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Pages::page_edit(
\admin\factory\Pages::page_details(
\S::get( 'id' )
), \S::get( 'pid' ), \S::get( 'menu_id' ),
\admin\factory\Pages::menu_lists(),
\admin\factory\Layouts::layouts_list(),
\admin\factory\Languages::languages_list(),
\admin\factory\Settings::settings_details()
);
}
public static function menu_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania menu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Pages::menu_edit(
\admin\factory\Pages::menu_details( \S::get( 'id' ) )
);
}
public static function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'page_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Pages::pages_list(
\admin\factory\Pages::menus_list()
);
}
}
?>

View File

@@ -0,0 +1,75 @@
<?php
namespace admin\controls;
class Scontainers
{
static public function ckeditor_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'scontainers_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \Tpl::view( '/scontainers/ckeditor-list' );
}
public static function container_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'scontainers_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'scontainers_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kontenera wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
if ( $id = \admin\factory\Scontainers::container_save( $values['id'], $values['title'], $values['text'], $values['status'], $values['show_title'],
$values['src'], $values['html']
) )
$response = [ 'status' => 'ok', 'msg' => 'Kontener został zapisany.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function container_edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'scontainers_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Scontainers::container_edit(
\admin\factory\Scontainers::container_details(
\S::get( 'id' )
), \admin\factory\Languages::languages_list()
);
}
public static function view_list()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'scontainers_administration',
$user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\Scontainers::containers_list();
}
}

View File

@@ -0,0 +1,59 @@
<?php
namespace admin\controls;
class SeoAdditional
{
public static function element_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'seo_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
if ( \admin\factory\SeoAdditional::element_delete( \S::get( 'id' ) ) )
\S::alert( 'Element został usunięty.' );
header( 'Location: /admin/seo_additional/main_view/' );
exit;
}
public static function element_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'seo_administration', $user['id']))
return \S::alert( 'Nie masz uprawnień' );
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania elementu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = \S::json_to_array( \S::get( 'values' ) );
if ( $id = \admin\factory\SeoAdditional::element_save( $values['id'], $values['url'], $values['status'], $values['title'], $values['keywords'], $values['description'], $values['text'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Zmiany zostały zapisane.', 'id' => $id ];
echo json_encode( $response );
exit;
}
public static function element_edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'seo_administration', $user['id']))
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\SeoAdditional::element_edit(
\admin\factory\SeoAdditional::element_details(
\S::get( 'id' )
)
);
}
public static function main_view()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'seo_administration', $user['id'] ) )
return \S::alert( 'Nie masz uprawnień' );
return \admin\view\SeoAdditional::main_view();
}
}

View File

@@ -0,0 +1,77 @@
<?
namespace admin\controls;
class Settings
{
public static function settings_save()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'settings_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
$settings = \admin\factory\Settings::settings_details();
$values = \S::json_to_array( \S::get( 'values' ) );
\admin\factory\Settings::settings_save(
$values['firm_name'],
$values['firm_adress'],
$values['additional_info'],
$values['contact_form'] == 'on' ? 1 : 0,
$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'],
$settings['newsletter_header'],
$settings['newsletter_footer_1'],
$settings['newsletter_footer_2'],
$values['google_map_key'],
$values['google_search_console'],
$values['update'],
$values['devel'],
$values['news_limit'],
$values['visit_counter'],
$values['calendar'],
$values['tags'],
$values['ssl'],
$values['mysql_debug'],
$values['htaccess_cache'],
$settings['visits'],
$values['links_structure'],
$values['link_version'],
$values['widget_phone'],
$values['update_key']
);
\admin\factory\Settings::settings_update( 'image_px', $values['image_px'] );
\admin\factory\Settings::settings_update( 'newsletter_cron', $values['newsletter_cron'] );
\admin\factory\Settings::settings_update( 'lazy_loading', $values['lazy_loading'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'generate_webp', $values['generate_webp'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'contact_form_captcha', $values['contact_form_captcha'] == 'on' ? 1 : 0 );
\admin\factory\Settings::settings_update( 'url_version', $values['url_version'] );
\S::alert( 'Ustawienia zostały zapisane.' );
echo json_encode( [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.' ] );
exit;
}
public static function view()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'settings_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Settings::view(
\admin\factory\Settings::settings_details()
);
}
}
?>

View 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();
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace admin\controls;
class Users
{
public static function user_delete()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'users_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
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()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'users_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
$values = \S::json_to_array( \S::get( 'values' ) );
$response = \admin\factory\Users::user_save(
$values['id'], $values['login'], $values['status'], $values['active_to'], $values['password'], $values['password_re'], $values['admin'], $values['privileges'], $values['twofa_enabled'], $values['twofa_email']
);
echo json_encode( $response );
exit;
}
public static function user_edit()
{
global $user;
if ( !\admin\factory\Users::check_privileges( 'users_administration', $user['id'] ) )
return \S::alert('Nie masz uprawnień');
return \admin\view\Users::user_edit(
\admin\factory\Users::user_details(
\S::get( 'id' ) ),
\admin\factory\Users::user_privileges(
\S::get( 'id' ) )
);
}
public static function view_list()
{
global $user;
if( !\admin\factory\Users::check_privileges( 'users_administration', $user['id']))
return \S::alert('Nie masz uprawnień');
return \admin\view\Users::users_list();
}
static public function twofa() {
return \Tpl::view( 'site/unlogged', [
'content' => \Tpl::view( 'users/user-2fa' )
] );
}
}
?>

View File

@@ -0,0 +1,714 @@
<?php
namespace admin\factory;
class Articles
{
public static function duplicate_article( $article_id )
{
global $mdb, $user;
$article = \admin\factory\Articles::article_details( $article_id );
if ( $article )
{
$mdb -> insert( 'pp_articles', [
'show_title' => $article['show_title'],
'show_date_add' => $article['show_date_add'],
'show_date_modify' => $article['show_date_modify'],
'date_add' => date( 'Y-m-d H:i:s' ),
'date_modify' => date( 'Y-m-d H:i:s' ),
'modify_by' => $user['id'],
'layout_id' => $article['layout_id'],
'status' => $article['status'],
'repeat_entry' => $article['repeat_entry'],
'social_icons' => $article['social_icons'],
'date_start' => $article['date_start'],
'date_end' => $article['event_date'],
'priority' => $article['priority'],
'password' => $article['password'],
'pixieset' => $article['pixieset']
] );
$article_tmp_id = $mdb -> id();
if ( $article_tmp_id )
{
foreach ( $article['languages'] as $key => $val )
{
$mdb -> insert( 'pp_articles_langs', [
'article_id' => $article_tmp_id,
'lang_id' => $key,
'title' => 'Kopia: ' . $val['title'],
'entry' => $val['entry'],
'text' => $val['text'],
'meta_title' => null,
'meta_description' => null,
'meta_keywords' => null,
'seo_link' => null,
'copy_from' => $val['copy_from'],
'block_direct_access' => $val['block_direct_access']
] );
}
foreach ( $article['params'] as $param )
{
$mdb -> insert( 'pp_articles_additional_values', [
'param_id' => $param['param_id'],
'value' => $param['value'],
'article_id' => $article_tmp_id,
'language_id' => $param['language_id']
] );
}
foreach ( $article['pages'] as $page )
{
$order = self::max_order() + 1;
$mdb -> insert( 'pp_articles_pages', [
'article_id' => $article_tmp_id,
'page_id' => $page,
'o' => (int)$order
] );
}
return true;
}
}
return false;
}
public static function insert_missing_hash() {
global $mdb;
if ( $mdb -> count( 'pp_articles', [ 'hash' => null ] ) ) {
$rows = $mdb -> select( 'pp_articles', [ 'id', 'date_add' ], [ 'hash' => null ] );
if ( is_array( $rows ) ) foreach ( $rows as $row ) {
$mdb -> update( 'pp_articles', [ 'hash' => md5( $row['id'] . $row['date_add'] ) ], [ 'id' => $row['id'] ] );
}
}
return true;
}
static public function files_order_save( $article_id, $order )
{
global $mdb;
$order = explode( ';', $order );
if ( is_array( $order ) and !empty( $order ) ) foreach ( $order as $file_id )
{
$mdb -> update( 'pp_articles_files', [
'o' => (int)$i++
], [
'AND' => [
'article_id' => $article_id,
'id' => $file_id
]
] );
}
}
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
]
] );
}
}
public static function additional_params( $language = 0 )
{
global $mdb;
return $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => $language ] ] );
}
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 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_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 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;
$result = $mdb -> update( 'pp_articles', [ 'status' => -1 ], [ 'id' => (int)$article_id ] );
\S::htacces();
\S::delete_cache();
return $result;
}
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' => 'ASC' ] ] );
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
$article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
$article['tags'] = $mdb -> select( 'pp_tags', [ '[><]pp_articles_tags' => [ 'id' => 'tag_id' ] ], 'name', [ 'article_id' => (int)$article_id ] );
$article['params'] = $mdb -> select( 'pp_articles_additional_values', [ 'param_id', 'value', 'language_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, $event_date, $tags, $block_direct_access, $priority,
$password, $pixieset, $id_author, $params )
{
global $mdb, $user;
$event_date = explode( ' - ', $event_date );
if ( !$article_id )
{
$mdb -> insert( 'pp_articles', [
'show_title' => $show_title == 'on' ? 1 : 0,
'show_table_of_contents' => $show_table_of_contents == '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,
'date_start' => $event_date[0] ? $event_date[0] : null,
'date_end' => $event_date[1] ? $event_date[1] : null,
'priority' => $priority == 'on' ? 1 : 0,
'password' => $password ? $password : null,
'pixieset' => $pixieset,
'id_author' => $id_author ? $id_author : null
] );
$id = $mdb -> id();
if ( $id )
{
$i = 0;
/* tłumaczenia */
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_articles_langs', [
'article_id' => (int)$id,
'lang_id' => $row['id'],
'title' => $title[ $i ] != '' ? $title[ $i ] : null,
'main_image' => $main_image[$i] != '' ? $main_image[$i] : null,
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
'text' => $text[ $i ] != '' ? $text[ $i ] : null,
'table_of_contents' => $table_of_contents[$i] != '' ? $table_of_contents[$i] : null,
'meta_title' => $meta_title[ $i ] != '' ? $meta_title[ $i ] : null,
'meta_description' => $meta_description[ $i ] != '' ? $meta_description[ $i ] : null,
'meta_keywords' => $meta_keywords[ $i ] != '' ? $meta_keywords[ $i ] : null,
'seo_link' => \S::seo( $seo_link[ $i ] ) != '' ? \S::seo( $seo_link[ $i ] ) : null,
'noindex' => $noindex[ $i ],
'copy_from' => $copy_from[ $i ] != '' ? $copy_from[ $i ] : null,
'block_direct_access' => $block_direct_access[ $i ]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_articles_langs', [
'article_id' => (int)$id,
'lang_id' => $row['id'],
'title' => $title != '' ? $title : null,
'main_image' => $main_image != '' ? $main_image : null,
'entry' => $entry != '' ? $entry : null,
'text' => $text != '' ? $text : null,
'table_of_contents' => $table_of_contents != '' ? $table_of_contents : null,
'meta_title' => $meta_title != '' ? $meta_title : null,
'meta_description' => $meta_description != '' ? $meta_description : null,
'meta_keywords' => $meta_keywords != '' ? $meta_keywords : null,
'seo_link' => \S::seo( $seo_link ) != '' ? \S::seo( $seo_link ) : null,
'noindex' => $noindex,
'copy_from' => $copy_from != '' ? $copy_from : null,
'block_direct_access' => $block_direct_access
] );
}
/* parametry bez wersji językowych */
$results = $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 0 ] ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_articles_additional_values', [
'param_id' => $row['id'],
'value' => $params[ 'ap_' . $row['name'] ],
'article_id' => (int)$id,
'language_id' => null
] );
}
/* strony */
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
] );
}
/* pliki */
$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'] ] );
}
/* tagi */
$tags = explode( ',', $tags );
if ( is_array( $tags ) ) foreach ( $tags as $tag )
{
if ( trim( $tag ) != '' )
{
$tag_id = $mdb -> get( 'pp_tags', 'id', [ 'name' => $tag ] );
if ( !$tag_id )
{
$mdb -> insert( 'pp_tags', [ 'name' => $tag ] );
$tag_id = $mdb -> id();
}
$mdb -> insert( 'pp_articles_tags', [ 'article_id' => (int)$id, 'tag_id' => (int)$tag_id ] );
}
}
\S::htacces();
\S::delete_cache();
return $id;
}
}
else
{
$mdb -> update( 'pp_articles', [
'show_title' => $show_title == 'on' ? 1 : 0,
'show_table_of_contents' => $show_table_of_contents == '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 ? $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,
'date_start' => $event_date[0] ? $event_date[0] : null,
'date_end' => $event_date[1] ? $event_date[1] : null,
'priority' => $priority == 'on' ? 1 : 0,
'password' => $password ? $password : null,
'pixieset' => $pixieset,
'id_author' => $id_author ? $id_author : null
], [
'id' => (int)$article_id
] );
if ( $date_add )
$mdb -> update( 'pp_articles', [ 'date_add' => $date_add ], [ 'id' => (int)$article_id ] );
$i = 0;
/* tłumaczenia */
$mdb -> delete( 'pp_articles_langs', [ 'article_id' => (int)$article_id ] );
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_articles_langs', [
'article_id' => (int)$article_id,
'lang_id' => $row['id'],
'title' => $title[ $i ] != '' ? $title[ $i ] : null,
'main_image' => $main_image[$i] != '' ? $main_image[$i] : null,
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
'text' => $text[ $i ] != '' ? $text[ $i ] : null,
'table_of_contents' => $table_of_contents[$i] != '' ? $table_of_contents[$i] : null,
'meta_title' => $meta_title[ $i ] != '' ? $meta_title[ $i ] : null,
'meta_description' => $meta_description[ $i ] != '' ? $meta_description[ $i ] : null,
'meta_keywords' => $meta_keywords[ $i ] != '' ? $meta_keywords[ $i ] : null,
'seo_link' => \S::seo( $seo_link[ $i ] ) != '' ? \S::seo( $seo_link[ $i ] ) : null,
'noindex' => $noindex[ $i ],
'copy_from' => $copy_from[ $i ] != '' ? $copy_from[ $i ] : null,
'block_direct_access' => $block_direct_access[ $i ]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_articles_langs', [
'article_id' => (int)$article_id,
'lang_id' => $row['id'],
'title' => $title != '' ? $title : null,
'main_image' => $main_image != '' ? $main_image : null,
'entry' => $entry != '' ? $entry : null,
'text' => $text != '' ? $text : null,
'table_of_contents' => $table_of_contents != '' ? $table_of_contents : null,
'meta_title' => $meta_title != '' ? $meta_title : null,
'meta_description' => $meta_description != '' ? $meta_description : null,
'meta_keywords' => $meta_keywords != '' ? $meta_keywords : null,
'seo_link' => \S::seo( $seo_link ) != '' ? \S::seo( $seo_link ) : null,
'noindex' => $noindex,
'copy_from' => $copy_from != '' ? $copy_from : null,
'block_direct_access' => $block_direct_access
] );
}
/* dodatkowe parametry */
$mdb -> delete( 'pp_articles_additional_values', [ 'article_id' => (int)$article_id ] );
/* parametry bez wersji językowych */
$results = $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 0 ] ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_articles_additional_values', [
'param_id' => $row['id'],
'value' => $params[ 'ap_' . $row['name'] ],
'article_id' => (int)$article_id,
'language_id' => null
] );
}
/* parametry z wersjami językowymi */
$results = $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 1 ] ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$results2 = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
{
$mdb -> insert( 'pp_articles_additional_values', [
'param_id' => $row['id'],
'value' => $params[ 'ap_' . $row['name'] . '_' . $row2['id'] ],
'article_id' => (int)$article_id,
'language_id' => $row2['id']
] );
}
}
/* strony */
$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
] );
}
/* pliki */
$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 ] ] );
/* tagi */
$mdb -> delete( 'pp_articles_tags', [ 'article_id' => (int)$article_id ] );
$tags = explode( ',', $tags );
if ( is_array( $tags ) ) foreach ( $tags as $tag )
{
if ( trim( $tag ) != '' )
{
$tag_id = $mdb -> get( 'pp_tags', 'id', [ 'name' => $tag ] );
if ( !$tag_id )
{
$mdb -> insert( 'pp_tags', [ 'name' => $tag ] );
$tag_id = $mdb -> id();
}
$mdb -> insert( 'pp_articles_tags', [ 'article_id' => (int)$article_id, 'tag_id' => (int)$tag_id ] );
}
}
\S::htacces();
\S::delete_cache();
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 ] );
}
}
?>

View File

@@ -0,0 +1,29 @@
<?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_tags', [ '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;
}
}

View File

@@ -0,0 +1,117 @@
<?
namespace admin\factory;
class Authors
{
// prosta lista autorów
static public function get_simple_list()
{
global $mdb;
return $mdb -> select( 'pp_authors', '*', [ 'ORDER' => [ 'author' => 'ASC' ] ] );
}
// usunięcie autora
static public function delete_author( $id_author )
{
global $mdb;
$result = $mdb -> delete( 'pp_authors', [ 'id' => (int)$id_author ] );
\S::delete_cache();
return $result;
}
// zapis autora
static public function save_author( $id_author, $author, $image, $description )
{
global $mdb;
if ( !$id_author )
{
$mdb -> insert( 'pp_authors', [
'author' => $author,
'image' => $image
] );
$id = $mdb -> id();
if ( $id )
{
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_authors_langs', [
'id_author' => (int)$id,
'id_lang' => $row['id'],
'description' => $description[ $i ]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_authors_langs', [
'id_author' => (int)$id,
'id_lang' => $row['id'],
'description' => $description
] );
}
\S::delete_cache();
return $id;
}
}
else
{
$mdb -> update( 'pp_authors', [
'author' => $author,
'image' => $image
], [
'id' => (int)$id_author
] );
$mdb -> delete( 'pp_authors_langs', [ 'id_author' => (int)$id_author ] );
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_authors_langs', [
'id_author' => (int)$id_author,
'id_lang' => $row['id'],
'description' => $description[ $i ]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_authors_langs', [
'id_author' => (int)$id_author,
'id_lang' => $row['id'],
'description' => $description
] );
}
\S::delete_cache();
return $id_author;
}
return false;
}
// szczególy autora
static public function get_single_author( $id_author )
{
global $mdb;
$author = $mdb -> get( 'pp_authors', '*', [ 'id' => (int)$id_author ] );
$results = $mdb -> select( 'pp_authors_langs', '*', [ 'id_author' => (int)$id_author ] );
if ( is_array( $results ) ) foreach ( $results as $row )
$author['languages'][$row['id_lang']] = $row;
return $author;
}
}

View File

@@ -0,0 +1,77 @@
<?php
namespace admin\factory;
class Backups
{
public static function backups_list()
{
if ( $handle = opendir( '../backups' ) )
{
while ( false !== ( $file = readdir( $handle ) ) )
{
if ( $file != "." && $file != ".." )
{
$row['name'] = $file;
$dir[] = $row;
}
}
closedir( $handle );
}
return $dir;
}
public static function backup_save()
{
global $mdb, $database;
$dbhost = $database['host'];
$dbuser = $database['user'];
$dbpsw = $database['password'];
$dbname = $database['name'];
$connection = mysqli_connect( $dbhost, $dbuser, $dbpsw, $dbname );
mysqli_set_charset( $connection, 'utf8' );
if ( !file_exists( '../backups' ) )
mkdir( "../backups", 0755 );
$backupfile = date( "Y_m_d_H_i_s" );
include('../libraries/MySQLDump.php');
$dump = new \MySQLDump( $connection );
$dump -> save( '../backups/' . $backupfile . '.sql' );
$zipTo = '../backups/' . $backupfile . '.zip';
$zip = new \ZipArchive();
$zip -> open( $zipTo, \ZipArchive::CREATE );
$folder = '../';
$iter = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator( $folder, \RecursiveDirectoryIterator::SKIP_DOTS ),
\RecursiveIteratorIterator::SELF_FIRST,
\RecursiveIteratorIterator::CATCH_GET_CHILD
);
foreach ( $iter as $file )
{
if ( !strstr( $file, '../backups' ) and !strstr( $file, ' ../temp' ) and !strstr( $file, '../updates' ) )
{
if ( is_dir( $file ) )
{
$zip -> addEmptyDir( str_replace( $folder, '', $file . '/' ) );
}
else if ( is_file( $file ) )
{
$zip -> addFromString( str_replace( $folder, '', $file ),
file_get_contents( $file ) );
}
}
}
$zip -> close();
return true;
}
public static function backup_delete( $file )
{
if ( file_exists( '../backups/' . $file ) )
unlink( '../backups/' . $file );
return true;
}
}

View File

@@ -0,0 +1,129 @@
<?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_cache();
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 )
{
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_banners_langs', [
'id_banner' => (int)$id,
'id_lang' => $row['id'],
'src' => $src[ $i ],
'url' => $url[ $i ],
'html' => $html[ $i ],
'text' => $text[ $i ]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_banners_langs', [
'id_banner' => (int)$id,
'id_lang' => $row['id'],
'src' => $src,
'url' => $url,
'html' => $html,
'text' => $text
] );
}
\S::delete_cache();
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
] );
$mdb -> delete( 'pp_banners_langs', [ 'id_banner' => (int)$banner_id ] );
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_banners_langs', [
'id_banner' => (int)$banner_id,
'id_lang' => $row['id'],
'src' => $src[ $i ],
'url' => $url[ $i ],
'html' => $html[ $i ],
'text' => $text[ $i ]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_banners_langs', [
'id_banner' => (int)$banner_id,
'id_lang' => $row['id'],
'src' => $src,
'url' => $url,
'html' => $html,
'text' => $text
] );
}
\S::delete_cache();
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;
}
}
?>

View File

@@ -0,0 +1,11 @@
<?php
namespace admin\factory;
class Emails
{
public static function email_details( $email_id )
{
global $mdb;
return $mdb -> get( 'pp_contact_emails', '*', [ 'id' => (int)$email_id ] );
}
}

View File

@@ -0,0 +1,181 @@
<?
namespace admin\factory;
class Languages
{
public static function available_domains()
{
global $mdb;
return $mdb -> query( 'SELECT domain FROM pp_langs WHERE status = 1 AND domain IS NOT NULL GROUP BY domain' ) -> fetchAll( \PDO::FETCH_ASSOC );
}
public static function default_domain()
{
global $mdb;
$results = $mdb -> query( 'SELECT domain FROM pp_langs WHERE status = 1 AND domain IS NOT NULL AND main_domain = 1' ) -> fetchAll();
return $default_domain = $results[0][0];
}
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_cache();
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_cache();
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, $domain, $main_domain )
{
global $mdb;
if ( $start == 'on' and $status == 'on' and !\S::get_domain( $domain ) )
$mdb -> update( 'pp_langs', [
'start' => 0
], [
'id[!]' => $language_id
] );
if ( $start == 'on' and $status == 'on' and \S::get_domain( $domain ) )
$mdb -> update( 'pp_langs', [
'start' => 0
], [
'AND' => [ 'id[!]' => $language_id, 'domain' => \S::get_domain( $domain ) ]
] );
if ( $main_domain == 'on' and $domain and $status == 'on' )
$mdb -> update( 'pp_langs', [
'main_domain' => 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,
'domain' => \S::get_domain( $domain ) ? \S::get_domain( $domain ) : null,
'main_domain' => $main_domain == 'on' and \S::get_domain( $domain ) ? 1 : 0,
], [
'id' => $language_id
] );
}
else
{
if ( $mdb -> query( 'ALTER TABLE pp_langs_translations ADD ' . strtolower( $language_id ) . ' TEXT NULL DEFAULT NULL' ) )
{
$mdb -> insert( 'pp_langs', [
'id' => strtolower( $language_id ),
'name' => $name,
'status' => $status == 'on' ? 1 : 0,
'start' => $start == 'on' ? 1 : 0,
'o' => $o,
'domain' => \S::get_domain( $domain ) ? \S::get_domain( $domain ) : null,
'main_domain' => $main_domain == 'on' && \S::get_domain( $domain ) ? 1 : 0,
] );
}
}
if ( !$mdb -> count( 'pp_langs', [ 'AND' => [ 'status' => 1, 'domain[!]' => null ] ] ) )
{
if ( !$mdb -> count( 'pp_langs', [ 'AND' => [ 'status' => 1, 'start' => 1, 'domain' => null ] ] ) )
{
if ( $id_tmp = $mdb -> get( 'pp_langs', 'id', [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] ) )
$mdb -> update( 'pp_langs', [ 'start' => 1 ], [ 'id' => $id_tmp ] );
}
}
$domains = $mdb -> select( 'pp_langs', 'domain', [ 'domain[!]' => null, 'GROUP' => 'domain'] );
if ( is_array( $domains ) and !empty( $domains ) )
{
$mdb -> update( 'pp_langs', [ 'start' => 0 ], [ 'domain' => null ] );
foreach ( $domains as $domain )
{
if ( !$mdb -> count( 'pp_langs', [ 'AND' => [ 'status' => 1, 'start' => 1, 'domain' => $domain ] ] ) )
{
if ( $id_tmp = $mdb -> get( 'pp_langs', 'id', [ 'AND' => [ 'status' => 1, 'domain' => $domain ], 'ORDER' => [ 'o' => 'ASC' ] ] ) )
$mdb -> update( 'pp_langs', [ 'start' => 1 ], [ 'id' => $id_tmp ] );
}
}
}
if ( !$mdb -> count( 'pp_langs', [ 'AND' => [ 'status' => 1, 'main_domain' => 1 ] ] ) )
{
if ( $id_tmp = $mdb -> get( 'pp_langs', 'id', [ 'AND' => [ 'status' => 1, 'domain[!]' => null ], 'ORDER' => [ 'o' => 'ASC' ] ] ) )
$mdb -> update( 'pp_langs', [ 'main_domain' => 1 ], [ 'id' => $id_tmp ] );
}
\S::htacces();
\S::delete_cache();
return $language_id;
}
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' ] ] );
}
}
?>

View File

@@ -0,0 +1,141 @@
<?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 ] );
return $layout;
}
public static function layout_save( $layout_id, $name, $status, $pages, $html, $css, $js, $m_html, $m_css, $m_js )
{
global $mdb;
if ( !$layout_id )
{
if ( $status == 'on' )
$mdb -> update( 'pp_layouts', [ 'status' => 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
] );
$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
] );
}
\S::delete_cache();
return $id;
}
}
else
{
if ( $status == 'on' )
$mdb -> update( 'pp_layouts', [ 'status' => 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
], [
'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
] );
}
\S::delete_cache();
return $layout_id;
}
return false;
}
public static function menus_list()
{
global $mdb;
$results = $mdb -> select( 'pp_menus', 'id', [ 'ORDER' => [ 'name' => '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' ] ] );
}
}
?>

View File

@@ -0,0 +1,105 @@
<?php
namespace admin\factory;
class Newsletter
{
public static function emails_import( $emails )
{
global $mdb;
$emails = explode( PHP_EOL, $emails );
if ( is_array( $emails ) ) foreach ( $emails as $email )
{
if ( trim( $email ) and !$mdb -> count( 'pp_newsletter', [ 'email' => trim( $email ) ] ) )
$mdb -> insert( 'pp_newsletter', [
'email' => trim( $email ),
'hash' => md5( $email . time() ),
'status' => 1
] );
}
return true;
}
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, $only_once )
{
global $mdb;
$results = $mdb -> select( 'pp_newsletter', 'email', [ 'status' => 1 ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
if ( $template and $only_once )
{
if ( !$mdb -> count( 'pp_newsletter_send', [ 'AND' => [ 'id_template' => $template, 'email' => $row ] ] ) )
$mdb -> insert( 'pp_newsletter_send', [
'email' => $row,
'dates' => $dates,
'id_template' => $template ? $template : null,
'only_once' => ( $only_once == 'on' and $template ) ? 1 : 0
] );
}
else
$mdb -> insert( 'pp_newsletter_send', [
'email' => $row,
'dates' => $dates,
'id_template' => $template ? $template : null,
'only_once' => ( $only_once == 'on' and $template ) ? 1 : 0
] );
}
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_cache();
return $mdb -> id();
}
}
else
{
$mdb -> update( 'pp_newsletter_templates', [
'name' => $name,
'text' => $text
], [
'id' => (int)$id
] );
\S::delete_cache();
return $id;
}
}
public static function templates_list()
{
global $mdb;
return $mdb -> select( 'pp_newsletter_templates', '*', [ 'is_admin' => 0, 'ORDER' => [ 'name' => 'ASC' ] ] );
}
}

View File

@@ -0,0 +1,509 @@
<?
namespace admin\factory;
class Pages
{
public static $_page_types = [ 0 => 'pełne artykuły', 1 => 'wprowadzenia', 2 => 'miniaturki', 3 => 'link', 4 => 'kontakt' ];
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' => [ 'name' => '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_cache();
return true;
}
public static function page_delete( $page_id )
{
global $mdb;
if ( $mdb -> count( 'pp_pages', [ 'parent_id' => (int) $page_id ] ) )
return false;
if ( $mdb -> delete( 'pp_pages', [ 'id' => (int) $page_id ] ) )
{
\S::delete_cache();
\S::htacces();
return true;
}
return false;
}
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,
$site_title, $block_direct_access, $cache, $canonical
)
{
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,
'cache' => $cache == 'on' ? 1 : 0
] );
$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 ] );
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_pages_langs', [
'page_id' => (int) $id,
'lang_id' => $row['id'],
'title' => $title[$i] != '' ? $title[$i] : null,
'meta_description' => $meta_description[$i] != '' ? $meta_description[$i] : null,
'meta_keywords' => $meta_keywords[$i] != '' ? $meta_keywords[$i] : null,
'meta_title' => $meta_title[$i] != '' ? $meta_title[$i] : null,
'seo_link' => \S::seo( $seo_link[$i] ) != '' ? \S::seo( $seo_link[$i] ) : null,
'noindex' => $noindex[$i],
'site_title' => $site_title[$i] != '' ? $site_title[$i] : null,
'link' => $link[$i] != '' ? $link[$i] : null,
'block_direct_access' => $block_direct_access[$i],
'canonical' => $canonical[$i] != '' ? $canonical[$i] : null
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 )
{
foreach ( $results as $row )
{
$mdb -> insert( 'pp_pages_langs', [
'page_id' => (int) $id,
'lang_id' => $row['id'],
'title' => $title != '' ? $title : null,
'meta_description' => $meta_description != '' ? $meta_description : null,
'meta_keywords' => $meta_keywords != '' ? $meta_keywords : null,
'meta_title' => $meta_title != '' ? $meta_title : null,
'seo_link' => \S::seo( $seo_link ) != '' ? \S::seo( $seo_link ) : null,
'noindex' => $noindex,
'site_title' => $site_title != '' ? $site_title : null,
'link' => $link != '' ? $link : null,
'block_direct_access' => $block_direct_access,
'canonical' => $canonical != '' ? $canonical : null
] );
}
}
\S::htacces();
\S::delete_cache();
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,
'cache' => $cache == 'on' ? 1 : 0
], [
'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 ] );
$i = 0;
$mdb -> delete( 'pp_pages_langs', [ 'page_id' => (int) $page_id ] );
$results = $mdb -> select( 'pp_langs', [ 'id' ],
[ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 )
foreach ( $results as $row )
{
$mdb -> insert( 'pp_pages_langs',
[
'page_id' => (int) $page_id,
'lang_id' => $row['id'],
'title' => $title[$i] != '' ? $title[$i] : null,
'meta_description' => $meta_description[$i] != '' ? $meta_description[$i] : null,
'meta_keywords' => $meta_keywords[$i] != '' ? $meta_keywords[$i] : null,
'meta_title' => $meta_title[$i] != '' ? $meta_title[$i] : null,
'seo_link' => \S::seo( $seo_link[$i] ) != '' ? \S::seo( $seo_link[$i] ) : null,
'noindex' => $noindex[$i],
'site_title' => $site_title[$i] != '' ? $site_title[$i] : null,
'link' => $link[$i] != '' ? $link[$i] : null,
'block_direct_access' => $block_direct_access[$i],
'canonical' => $canonical[$i] != '' ? $canonical[$i] : null
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 )
foreach ( $results as $row )
{
$mdb -> insert( 'pp_pages_langs',
[
'page_id' => (int) $page_id,
'lang_id' => $row['id'],
'title' => $title != '' ? $title : null,
'meta_description' => $meta_description != '' ? $meta_description : null,
'meta_keywords' => $meta_keywords != '' ? $meta_keywords : null,
'meta_title' => $meta_title != '' ? $meta_title : null,
'seo_link' => \S::seo( $seo_link ) != '' ? \S::seo( $seo_link ) : null,
'noindex' => $noindex,
'site_title' => $site_title != '' ? $site_title : null,
'link' => $link != '' ? $link : null,
'block_direct_access' => $block_direct_access,
'canonical' => $canonical != '' ? $canonical : null
] );
}
self::update_supages_menu_id( $page_id, $menu_id );
\S::htacces();
\S::delete_cache();
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,
$lang, $pid )
{
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 = $seo_link . '-' . ( ++$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 = $seo_link . '-' . ( ++$i );
else
$seo_link_check = true;
}
return $seo_link;
}
public static function google_url_preview( $page_id, $title, $lang, $pid, $id, $seo_link, $language_link = '' )
{
global $mdb;
$prefix = $language_link;
$status = true;
$id_page = $page_id;
do
{
if ( $page_id )
{
$parent = \admin\factory\Pages::page_details( $page_id );
$parent_id = $parent['parent_id'];
}
else
$parent_id = $pid;
if ( $parent_id )
{
$results = $mdb -> query( "SELECT title, seo_link, page_id FROM pp_pages_langs AS ppl, pp_langs AS pl WHERE lang_id = pl.id AND page_id = " . (int) $parent_id . " AND ppl.lang_id = '" . $lang . "' " ) -> fetchAll();
if ( $results[0]['seo_link'] )
$seo = $results[0]['seo_link'] . '/' . $seo;
else
$seo = 's-' . $results[0]['page_id'] . '-' . \S::seo( $results[0]['title'] ) . '/' . $seo;
$page_id = $results[0]['page_id'];
}
else
$status = false;
}
while ( $status );
if ( $id )
{
if ( !$seo_link )
$seo = $seo . 's-' . $id . '-' . \S::seo( $title );
else
$seo = $seo . $seo_link;
}
else
{
if ( !$seo_link )
$seo = $seo . 's-' . $id_page . '-' . \S::seo( $title );
else
$seo = $seo . $seo_link;
}
if ( $prefix )
$seo = $prefix . $seo;
return $seo;
}
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, title lang_id 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;
}
}
?>

View File

@@ -0,0 +1,121 @@
<?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, $src, $html )
{
global $mdb;
if ( !$container_id )
{
$mdb -> insert( 'pp_scontainers',
[
'status' => $status == 'on' ? 1 : 0,
'show_title' => $show_title == 'on' ? 1 : 0,
'src' => $src
] );
$id = $mdb -> id();
if ( $id )
{
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_scontainers_langs',
[
'container_id' => (int) $id,
'lang_id' => $row['id'],
'title' => $title[$i],
'text' => $text[$i],
'html' => $html[$i]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_scontainers_langs', [
'container_id' => (int) $id,
'lang_id' => $row['id'],
'title' => $title,
'text' => $text,
'html' => $html
] );
}
\S::delete_cache();
return $id;
}
}
else
{
$mdb -> update( 'pp_scontainers',
[
'status' => $status == 'on' ? 1 : 0,
'show_title' => $show_title == 'on' ? 1 : 0,
'src' => $src
],
[
'id' => (int) $container_id
] );
$mdb -> delete( 'pp_scontainers_langs',
[ 'container_id' => (int) $container_id ] );
$i = 0;
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_scontainers_langs',
[
'container_id' => (int) $container_id,
'lang_id' => $row['id'],
'title' => $title[$i],
'text' => $text[$i],
'html' => $html[$i]
] );
$i++;
}
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
{
$mdb -> insert( 'pp_scontainers_langs',
[
'container_id' => (int) $container_id,
'lang_id' => $row['id'],
'title' => $title,
'text' => $text,
'html' => $html
] );
}
\S::delete_cache();
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;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace admin\factory;
class SeoAdditional
{
public static function element_delete( $element_id )
{
global $mdb;
return $mdb -> delete( 'pp_seo_additional', [ 'id' => (int)$element_id ] );
}
public static function element_save( $id, $url, $status, $title, $keywords, $description, $text )
{
global $mdb;
if ( !$id )
{
if ( $mdb -> insert( 'pp_seo_additional', [
'url' => $url,
'status' => $status == 'on' ? 1 : 0,
'title' => $title,
'keywords' => $keywords,
'description' => $description,
'text' => $text
] ) )
{
\S::delete_cache();
return $mdb -> id();
}
}
else
{
$mdb -> update( 'pp_seo_additional', [
'url' => $url,
'status' => $status == 'on' ? 1 : 0,
'title' => $title,
'keywords' => $keywords,
'description' => $description,
'text' => $text
], [
'id' => (int)$id
] );
\S::delete_cache();
return $id;
}
}
public static function element_details( $element_id )
{
global $mdb;
$result = $mdb -> get ( 'pp_seo_additional', '*', [ 'id' => (int)$element_id ] );
return $result;
}
}

View File

@@ -0,0 +1,147 @@
<?
namespace admin\factory;
class Settings
{
public static function settings_update( $param, $value )
{
global $mdb;
if ( $mdb -> count( 'pp_settings', [ 'param' => $param ] ) )
return $mdb -> update( 'pp_settings', [ 'value' => $value ], [ 'param' => $param ] );
else
return $mdb -> insert( 'pp_settings', [ 'param' => $param, 'value' => $value ] );
}
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, $newsletter_header, $newsletter_footer_1, $newsletter_footer_2, $google_map_key, $google_search_console, $update, $devel,
$news_limit, $visit_counter, $calendar, $tags, $ssl, $mysql_debug, $htaccess_cache, $visits, $links_structure, $link_version, $widget_phone, $update_key )
{
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
], [
'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 == 'on' ? 1 : 0
], [
"param" => 'facebook_link',
'value' => $facebook_link
], [
'param' => 'statistic_code',
'value' => $statistic_code
], [
'param' => 'htaccess',
'value' => $htaccess
], [
'param' => 'robots',
'value' => $robots
], [
'param' => 'newsletter_header',
'value' => $newsletter_header
], [
'param' => 'newsletter_footer_1',
'value' => $newsletter_footer_1
], [
'param' => 'newsletter_footer_2',
'value' => $newsletter_footer_2
], [
'param' => 'google_map_key',
'value' => $google_map_key
], [
'param' => 'google_search_console',
'value' => $google_search_console
], [
'param' => 'update',
'value' => $update == 'on' ? 1 : 0
], [
'param' => 'devel',
'value' => $devel == 'on' ? 1 : 0
], [
'param' => 'news_limit',
'value' => $news_limit
], [
'param' => 'visit_counter',
'value' => $visit_counter == 'on' ? 1 : 0
], [
'param' => 'calendar',
'value' => $calendar == 'on' ? 1 : 0
], [
'param' => 'tags',
'value' => $tags == 'on' ? 1 : 0
], [
'param' => 'ssl',
'value' => $ssl == 'on' ? 1 : 0
], [
'param' => 'mysql_debug',
'value' => $mysql_debug == 'on' ? 1 : 0
], [
'param' => 'htaccess_cache',
'value' => $htaccess_cache == 'on' ? 1 : 0
], [
'param' => 'visits',
'value' => $visits
], [
'param' => 'links_structure',
'value' => $links_structure
], [
'param' => 'link_version',
'value' => $link_version
], [
'param' => 'widget_phone',
'value' => $widget_phone == 'on' ? 1 : 0
], [
'param' => 'update_key',
'value' => $update_key
]
]
);
\S::set_message( 'Ustawienia zostały zapisane' );
\S::delete_cache();
\S::htacces();
return true;
}
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;
}
}
?>

View File

@@ -0,0 +1,156 @@
<?php
namespace admin\factory;
class Update
{
public static function update()
{
global $mdb, $settings;
\S::delete_session( 'new-version' );
$versions = file_get_contents( 'http://www.cmspro.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;
$baseUrl = 'http://www.cmspro.project-dc.pl/updates/' . $dir;
/* pobranie paczki ZIP */
$file = file_get_contents( $baseUrl . '/ver_' . $ver . '.zip' );
$dlHandler = fopen( 'update.zip' , 'w' );
if ( !fwrite( $dlHandler, $file ) )
return false;
fclose( $dlHandler );
if ( !file_exists( 'update.zip' ) )
return false;
/* pobranie manifestu JSON (nowy system) lub fallback na legacy _sql.txt / _files.txt */
$manifest = null;
$manifestJson = @file_get_contents( $baseUrl . '/ver_' . $ver . '_manifest.json' );
if ( $manifestJson )
{
if ( substr( $manifestJson, 0, 3 ) === "\xEF\xBB\xBF" )
$manifestJson = substr( $manifestJson, 3 );
$manifest = @json_decode( $manifestJson, true );
}
if ( is_array( $manifest ) )
{
/* weryfikacja checksum SHA256 */
if ( !empty( $manifest['checksum_zip'] ) )
{
$expectedHash = str_replace( 'sha256:', '', $manifest['checksum_zip'] );
$actualHash = hash_file( 'sha256', 'update.zip' );
if ( $expectedHash !== $actualHash )
{
unlink( 'update.zip' );
return false;
}
}
/* aktualizacja bazy danych z manifestu */
if ( !empty( $manifest['sql'] ) && is_array( $manifest['sql'] ) )
{
foreach ( $manifest['sql'] as $query )
{
$query = trim( $query );
if ( $query )
$mdb -> query( $query );
}
}
/* usuwanie plikow z manifestu */
if ( !empty( $manifest['files']['deleted'] ) && is_array( $manifest['files']['deleted'] ) )
{
foreach ( $manifest['files']['deleted'] as $filePath )
{
$fullPath = '../' . $filePath;
if ( file_exists( $fullPath ) )
unlink( $fullPath );
}
}
/* usuwanie katalogow z manifestu */
if ( !empty( $manifest['directories_deleted'] ) && is_array( $manifest['directories_deleted'] ) )
{
foreach ( $manifest['directories_deleted'] as $dirPath )
{
$fullPath = '../' . $dirPath;
if ( is_dir( $fullPath ) )
\S::delete_dir( $fullPath );
}
}
}
else
{
/* legacy: aktualizacja bazy danych z _sql.txt */
$sql = @file_get_contents( $baseUrl . '/ver_' . $ver . '_sql.txt' );
if ( $sql )
{
$sql = explode( PHP_EOL, $sql );
if ( is_array( $sql ) ) foreach ( $sql as $query )
{
$query = trim( $query );
if ( $query )
$mdb -> query( $query );
}
}
/* legacy: usuwanie zbednych plikow z _files.txt */
$lines = @file_get_contents( $baseUrl . '/ver_' . $ver . '_files.txt' );
if ( $lines )
{
$lines = explode( PHP_EOL, $lines );
if ( is_array( $lines ) ) foreach ( $lines as $line )
{
if ( strpos( $line, 'F: ' ) !== false )
{
$delFile = substr( $line, 3, strlen( $line ) );
if ( file_exists( $delFile ) )
unlink( $delFile );
}
if ( strpos( $line, 'D: ' ) !== false )
{
$delDir = substr( $line, 3, strlen( $line ) );
if ( is_dir( $delDir ) )
\S::delete_dir( $delDir );
}
}
}
}
/* wgrywanie nowych plikow */
$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;
}
}
}
}

View File

@@ -0,0 +1,306 @@
<?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_privileges($user_id)
{
global $mdb;
return $mdb->select('pp_users_privileges', '*', ['id_user' => (int)$user_id]);
}
public static function user_save($user_id, $login, $status, $active_to, $password, $password_re, $admin, $privileges, $twofa_enabled = 0, $twofa_email = '' )
{
global $mdb, $lang;
$mdb->delete('pp_users_privileges', ['id_user' => (int) $user_id]);
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,
'active_to' => $active_to == '' ? NULL : $active_to,
'admin' => $admin,
'password' => md5($password),
'twofa_enabled' => $twofa_enabled == 'on' ? 1 : 0,
'twofa_email' => $twofa_email
]
))
$id_user = $mdb->get('pp_users', 'id', ['ORDER' => ['id' => 'DESC']]);
if (is_array($privileges))
{
foreach ($privileges as $pri)
{
$mdb->insert(
'pp_users_privileges',
[
'name' => $pri,
'id_user' => $id_user
]
);
}
}
else
{
$mdb->insert(
'pp_users_privileges',
[
'name' => $privileges,
'id_user' => $id_user
]
);
}
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,
'active_to' => $active_to == '' ? NULL : $active_to,
'error_logged_count' => 0,
'twofa_enabled' => $twofa_enabled == 'on' ? 1 : 0,
'twofa_email' => $twofa_email
], [
'id' => (int) $user_id
]);
if (is_array($privileges))
{
foreach ($privileges as $pri)
{
$mdb->insert('pp_users_privileges', [
'name' => $pri,
'id_user' => $user_id
]);
}
}
else
{
$mdb->insert('pp_users_privileges', [
'name' => $privileges,
'id_user' => $user_id
]);
}
return $response = ['status' => 'ok', 'msg' => 'Uzytkownik został zapisany.'];
}
\S::delete_cache();
}
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),
'OR' => ['active_to[>=]' => date('Y-m-d'), 'active_to' => null]
]
]))
{
$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]);
}
public static function check_privileges($name, $user_id)
{
global $mdb;
if ($user_id == 1)
return true;
else
{
if (!$privilages = \Cache::fetch("check_privileges:$user_id:$name-tmp"))
{
$privilages = $mdb->count('pp_users_privileges', ['AND' => ['name' => $name, 'id_user' => (int)$user_id]]);
\Cache::store("check_privileges:$user_id:$name", $privilages);
}
return $privilages;
}
}
static public function get_by_id(int $userId): ?array
{
global $mdb;
return $mdb->get('pp_users', '*', ['id' => $userId]) ?: null;
}
static public function send_twofa_code(int $userId, bool $resend = false): bool
{
$user = self::get_by_id($userId);
if (!$user)
return false;
if ((int)$user['twofa_enabled'] !== 1)
{
return false;
}
$to = $user['twofa_email'] ?: $user['login'];
if (!filter_var($to, FILTER_VALIDATE_EMAIL))
{
return false;
}
if ($resend && !empty($user['twofa_sent_at']))
{
$last = strtotime($user['twofa_sent_at']);
if ($last && (time() - $last) < 30)
{
return false;
}
}
$code = random_int(100000, 999999);
$hash = password_hash((string)$code, PASSWORD_DEFAULT);
self::update_by_id($userId, [
'twofa_code_hash' => $hash,
'twofa_expires_at' => date('Y-m-d H:i:s', time() + 10 * 60), // 10 minut
'twofa_sent_at' => date('Y-m-d H:i:s'),
'twofa_failed_attempts' => 0,
]);
$subject = 'Twój kod logowania 2FA';
$body = "Twój kod logowania do panelu administratora: {$code}. Kod jest ważny przez 10 minut. Jeśli to nie Ty inicjowałeś logowanie zignoruj tę wiadomość i poinformuj administratora.";
$sent = \S::send_email($to, $subject, $body);
if (!$sent) {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=UTF-8\r\n";
$headers .= "From: no-reply@" . ($_SERVER['HTTP_HOST'] ?? 'localhost') . "\r\n";
$encodedSubject = mb_encode_mimeheader($subject, 'UTF-8');
$sent = mail($to, $encodedSubject, $body, $headers);
}
return $sent;
}
static public function update_by_id(int $userId, array $data): bool
{
global $mdb;
return (bool)$mdb->update('pp_users', $data, ['id' => $userId]);
}
static public function verify_twofa_code(int $userId, string $code): bool
{
$user = self::get_by_id( $userId );
if (!$user) return false;
if ((int)$user['twofa_failed_attempts'] >= 5)
{
return false; // zbyt wiele prób
}
// sprawdź ważność
if (empty($user['twofa_expires_at']) || time() > strtotime($user['twofa_expires_at']))
{
// wyczyść po wygaśnięciu
self::update_by_id($userId, [
'twofa_code_hash' => null,
'twofa_expires_at' => null,
]);
return false;
}
$ok = (!empty($user['twofa_code_hash']) && password_verify($code, $user['twofa_code_hash']));
if ($ok)
{
// sukces: czyścimy wszystko
self::update_by_id($userId, [
'twofa_code_hash' => null,
'twofa_expires_at' => null,
'twofa_sent_at' => null,
'twofa_failed_attempts' => 0,
'last_logged' => date('Y-m-d H:i:s'),
]);
return true;
}
// zła próba — inkrementacja
self::update_by_id($userId, [
'twofa_failed_attempts' => (int)$user['twofa_failed_attempts'] + 1,
'last_error_logged' => date('Y-m-d H:i:s'),
]);
return false;
}
}

View File

@@ -0,0 +1,37 @@
<?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( $values )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'articles/article-edit' );
}
}
?>

View 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' );
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace admin\view;
class Backups {
public static function backups_list($backups) {
$tpl = new \Tpl;
$tpl -> backups = $backups;
return $tpl -> render ('backups/backup-list');
}
}

View 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' );
}
}
?>

View File

@@ -0,0 +1,17 @@
<?php
namespace admin\view;
class Emails {
public static function emails_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'emails/emails-list' );
}
public static function email_details( $email )
{
$tpl = new \Tpl;
$tpl -> email = $email;
return $tpl -> render( 'emails/email-details' );
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace admin\view;
class FileManager
{
public function filemanager()
{
$tpl = new \Tpl;
return $tpl -> render( 'filemanager/filemanager' );
}
}
?>

View File

@@ -0,0 +1,32 @@
<?
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' );
}
}
?>

View File

@@ -0,0 +1,29 @@
<?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 layout_edit( $layout, $menus )
{
$tpl = new \Tpl;
$tpl -> layout = $layout;
$tpl -> menus = $menus;
return $tpl -> render( 'layouts/layout-edit' );
}
public static function layouts_list()
{
$tpl = new \Tpl;
return $tpl -> render( 'layouts/layouts-list' );
}
}
?>

View 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' );
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace admin\view;
class Page {
public static function show()
{
global $user;
if ( $_GET['module'] == 'user' && $_GET['action'] == 'twofa' ) {
return \admin\controls\Users::twofa();
}
if ( !$user || !$user['admin'] )
return \admin\view\Users::login_form();
$tpl = new \Tpl;
$tpl -> content = \admin\Site::route();
return $tpl -> render( 'site/main-layout' );
}
}
?>

View 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' );
}
}
?>

View File

@@ -0,0 +1,68 @@
<?
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' );
}
static public function browse_list( $menus, $modal = false )
{
return \Tpl::view( 'pages/pages-browse-list', [
'menus' => $menus,
'modal' => $modal
] );
}
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 page_edit( $page, $parent_id, $menu_id, $menus, $layouts, $languages, $settings )
{
$tpl = new \Tpl;
$tpl -> menu_id = $menu_id;
$tpl -> parent_id = $parent_id;
$tpl -> menus = $menus;
$tpl -> page = $page;
$tpl -> layouts = $layouts;
$tpl -> languages = $languages;
$tpl -> settings = $settings;
return $tpl -> render( 'pages/page-edit' );
}
public static function menu_edit( $menu )
{
$tpl = new \Tpl;
$tpl -> menu = $menu;
return $tpl -> render( 'pages/menu-edit' );
}
public static function pages_list( $menus )
{
$tpl = new \Tpl;
$tpl -> menus = $menus;
return $tpl -> render( 'pages/pages-list' );
}
public static function subpages_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-list' );
}
}
?>

View 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' );
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace admin\view;
class SeoAdditional
{
public static function element_edit( $element = '' )
{
$tpl = new \Tpl;
$tpl -> element = $element;
return $tpl -> render( 'seo-additional/element-edit' );
}
public static function main_view()
{
$tpl = new \Tpl;
return $tpl -> render( 'seo-additional/main-view' );
}
}

View 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' );
}
}
?>

View 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' );
}
}

View File

@@ -0,0 +1,26 @@
<?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, $privileges )
{
$tpl = new \Tpl;
$tpl -> user = $user;
$tpl -> privileges = $privileges;
return $tpl -> render( 'users/user-edit' );
}
}
?>