first commit

This commit is contained in:
2024-11-11 15:28:20 +01:00
commit 3f5649dbc7
6231 changed files with 999089 additions and 0 deletions

View File

@@ -0,0 +1,611 @@
<?php
namespace admin\factory;
class Articles
{
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;
}
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 ] );
$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, $entry, $text, $status, $show_title, $show_date_add, $date_add, $show_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, $params )
{
global $mdb, $user;
$event_date = explode( ' - ', $event_date );
if ( !$article_id )
{
$mdb -> insert( 'pp_articles', [
'show_title' => $show_title == 'on' ? 1 : 0,
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
'date_add' => $date_add ? $date_add : date( 'Y-m-d H:i:s' ),
'date_modify' => $date_add ? $date_add : 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 = $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,
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
'text' => $text[ $i ] != '' ? $text[ $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,
'entry' => $entry != '' ? $entry : null,
'text' => $text != '' ? $text : 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_date_add' => $show_date_add == 'on' ? 1 : 0,
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
'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' => (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,
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
'text' => $text[ $i ] != '' ? $text[ $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,
'entry' => $entry != '' ? $entry : null,
'text' => $text != '' ? $text : 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,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,136 @@
<?php
namespace admin\factory;
class Globelus
{
public static function save_to_db( $table, $column_id, $row_id, $column, $operation, $value, $values = '' )
{
global $mdb;
if ( $column == 'date_of_birth' and $value != '' )
$value = date( 'Y-m-d', strtotime( $value ) );
if ( $operation == 'insert_update' )
{
if ( $mdb -> count( $table, [ $column_id => $row_id ] ) )
{
if ( $mdb -> update( $table, [
$column => $value === '' ? null : $value
], [
$column_id => $row_id
] ) )
return $row_id;
}
else
{
if ( $values )
{
$values_s1 = explode( '|', $values );
foreach ( $values_s1 as $value_s1 )
{
$values_s2 = explode( ';', $value_s1 );
$columns[ $values_s2[0] ] = $values_s2[1];
}
}
if ( $mdb -> insert( $table, [
array_merge( [
$column => $value,
$column_id => $row_id
], $columns )
] ) )
return $mdb -> id();
}
}
if ( $operation == 'update_insert' )
{
if ( $mdb -> count( $table, [ $column_id => $row_id ] ) )
return $mdb -> update( $table, [
$column => $value
], [
$column_id => $row_id
] );
else
return $mdb -> insert( $table, [
$column => $value,
$column_id => $row_id
] );
}
if ( $operation == 'update' )
{
if ( $column == 'cv_access_date' or $column == 'id_voivodeship' )
{
if ( $value == '' )
$value = null;
}
if ( $value == null and $column == 'id_position' )
{
return $mdb -> delete( $table, [ $column_id => $row_id ] );
}
else
{
if ( $mdb -> update( $table, [
$column => $value
], [
$column_id => $row_id
] ) )
{
if ( $column == 'cv_access_date' ) {
if ( $value != '' ) {
$mdb -> update( $table, [
'cv_access' => 1
], [
$column_id => $row_id
] );
} else {
$mdb -> update( $table, [
'cv_access' => 0
], [
$column_id => $row_id
] );
}
}
}
return $row_id;
}
}
if ( $operation == 'insert_delete' )
{
if ( !$value )
{
if ( $values )
{
$values_s1 = explode( '|', $values );
foreach ( $values_s1 as $value_s1 )
{
$values_s2 = explode( ';', $value_s1 );
$columns[ $values_s2[0] ] = $values_s2[1];
}
}
if ( is_array( $columns ) )
return $mdb -> delete( $table, $columns );
}
else
{
if ( $values )
{
$values_s1 = explode( '|', $values );
foreach ( $values_s1 as $value_s1 )
{
$values_s2 = explode( ';', $value_s1 );
$columns[ $values_s2[0] ] = $values_s2[1];
}
}
if ( is_array( $columns ) )
return $mdb -> insert( $table, $columns );
}
}
return false;
}
}

View File

@@ -0,0 +1,74 @@
<?php
namespace admin\factory;
class GlobelusAdverts
{
public static function disabled_by_admin( $advert_id, $disabled_by_admin ) {
global $mdb;
return $mdb -> update( 'globelus_adverts', [ 'disabled_by_admin' => $disabled_by_admin ], [ 'id' => $advert_id ] );
}
public static function update_active_to() {
global $mdb;
$results = $mdb -> select( 'globelus_adverts', [ 'id', 'date_add' ], [ 'active_to' => null ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$mdb -> update( 'globelus_adverts', [ 'active_to' => date( 'Y-m-d', strtotime( '+6 months', strtotime( $row['date_add'] ) ) ) ], [ 'id' => $row['id'] ] );
}
public static function firms_list()
{
global $mdb;
$results = $mdb -> query( 'SELECT '
. 'gu.id, gfd.firm_name '
. 'FROM '
. 'globelus_users AS gu '
. 'INNER JOIN globelus_firms_data AS gfd ON gfd.user_id = gu.id '
. 'WHERE '
. 'type = 1' ) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $results ) and count( $results ) ) foreach ( $results as $row )
$firms[ $row['id'] ] = $row['firm_name'];
return $firms;
}
public static function answers_list( $advert_id )
{
global $mdb;
return $mdb -> query( 'SELECT '
. 'id, name, surname, email, phone, text, cv, cv_extension, displayed, date_add, user_id '
. 'FROM '
. 'globelus_adverts_answers AS gaa '
. 'WHERE '
. 'advert_id = ' . (int)$advert_id . ' AND deleted = 0 '
. 'ORDER BY '
. 'date_add DESC, id DESC' ) -> fetchAll();
}
public static function advert_details( $advert_id )
{
global $mdb;
return $mdb -> query( 'SELECT '
. 'ga.id, title, ga.user_id, category_id, ga.country_id, ga.city, ga.region, text, contact_person, email, ga.phone, firm_name, highlight, highlight_to, main_page, main_page_to, '
. 'gac.name AS category_name, gc.name AS country_name, gfd.firm_name_profile, date_add, ga.clauses, salary, work_type, without_language, without_experience, for_couples, from_now,'
. 'disabled_by_admin, accommodation, accommodation_cost, overtime, overtime_quantity, travel_refund, outside_ue, id_voivodeship '
. 'FROM '
. 'globelus_adverts AS ga '
. 'LEFT JOIN globelus_adverts_categories AS gac ON gac.id = ga.category_id '
. 'LEFT JOIN globelus_countries AS gc ON gc.id = ga.country_id '
. 'INNER JOIN globelus_firms_data AS gfd ON gfd.user_id = ga.user_id '
. 'WHERE '
. 'ga.id = ' . (int)$advert_id ) -> fetch( \PDO::FETCH_ASSOC );
}
public static function advert_delete( $advert_id )
{
global $mdb, $settings;
$answers_cv = $mdb -> select( 'globelus_adverts_answers', 'cv', [ 'AND' => [ 'advert_id' => $advert_id, 'cv[!]' => null ] ] );
if ( is_array( $answers_cv ) and count( $answers_cv ) ) foreach ( $answers_cv as $cv )
{
if ( strpos( $cv, 'files/cv_tmp/' ) and file_exists( '../' . $cv ) )
unlink( '../' . $cv );
}
return $mdb -> delete( 'globelus_adverts', [ 'id' => $advert_id ] );
}
}

View File

@@ -0,0 +1,113 @@
<?php
namespace admin\factory;
class GlobelusCandidates
{
public static function switch_account_type( $user_id ) {
\R::exec( 'DELETE FROM globelus_candidates_adverts WHERE user_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_candidates_categories WHERE user_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_candidates_countries WHERE user_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_candidates_data WHERE user_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_candidates_languages WHERE user_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_candidates_positions WHERE user_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_candidates_visits WHERE candidate_id = ?', [ (int)$user_id ] );
\R::exec( 'DELETE FROM globelus_firms_candidates WHERE candidate_id = ?', [ (int)$user_id ] );
return \R::exec( 'UPDATE globelus_users SET type = 1 WHERE id = ?', [ (int)$user_id ] );
}
public static function candidate_highlight( $user_id )
{
global $mdb, $settings;
$mdb -> update( 'globelus_users', [ 'highlight' => 1, 'highlight_to' => date( 'Y-m-d', strtotime( '+14 days', time() ) ) ], [ 'id' => $user_id ] );
$email = \front\factory\GlobelusUser::get_email( $user_id );
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#profil-zostal-wyrozniony' );
$text .= $settings['newsletter_footer_1'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$send = \S::send_email( $email, 'Twój profil w serwisie GLOBELUS.PL został właśnie wyróżniony!', $text );
return true;
}
public static function candidate_details( $user_id )
{
global $mdb;
$g_user = $mdb -> get( 'globelus_users', '*', [ 'id' => $user_id ] );
$g_user_data = $mdb -> get( 'globelus_candidates_data', '*', [ 'user_id' => $user_id ] );
if ( is_array( $g_user_data ) )
{
$g_user['data_id'] = $g_user_data['id'];
unset( $g_user_data['id'] );
$g_user = array_merge( $g_user, $g_user_data );
}
$g_user['countries'] = $mdb -> select( 'globelus_candidates_countries', [ '[><]globelus_countries' => [ 'country_id' => 'id' ] ], 'country_id', [ 'user_id' => $user_id ] );
$g_user['voivodeships'] = $mdb -> select( 'globelus_candidates_voivodeships', [ '[><]globelus_voivodeships' => [ 'id_voivodeship' => 'id' ] ], 'id_voivodeship', [ 'id_user' => $user_id ] );
$g_user['categories'] = $mdb -> select( 'globelus_candidates_categories', [ '[><]globelus_adverts_categories' => [ 'category_id' => 'id' ] ], 'category_id', [ 'user_id' => $user_id ] );
$g_user['positions'] = $mdb -> select( 'globelus_candidates_positions', [ 'id', 'position', 'experience', 'id_position' ], [ 'user_id' => $user_id ] );
$g_user['languages'] = $mdb -> select( 'globelus_candidates_languages', [ 'id', 'language', 'experience' ], [ 'user_id' => $user_id ] );
$g_user['adverts'] = $mdb -> select( 'globelus_candidates_adverts', 'advert_id', [ 'user_id' => $user_id ] );
$g_user['cv_hash'] = \front\factory\GlobelusCandidates::cv_hash( $user_id );
return $g_user;
}
public static function candidate_delete( $user_id )
{
global $mdb, $settings;
$email = \front\factory\GlobelusUser::get_email( $user_id );
$answers_cv = $mdb -> select( 'globelus_adverts_answers', 'cv', [ 'AND' => [ 'user_id' => $user_id, 'cv[!]' => null ] ] );
if ( is_array( $answers_cv ) and count( $answers_cv ) ) foreach ( $answers_cv as $cv )
{
if ( '../' . file_exists( $cv ) )
unlink( '../' . $cv );
}
$mdb -> delete( 'globelus_adverts', [ 'user_id' => $user_id ] );
$mdb -> delete( 'globelus_adverts_answers', [ 'user_id' => $user_id ] );
$cv_file = \front\factory\GlobelusCandidates::cv_url( $user_id );
if ( file_exists( '../' . $cv_file ) )
unlink( '../' . $cv_file );
$avatar_img = \front\factory\GlobelusCandidates::avatar_url( $user_id );
if ( file_exists( '../' . $avatar_img ) )
unlink( '../' . $avatar_img );
$logo_img = \front\factory\GlobelusFirms::logo_url( $user_id );
if ( file_exists( '../' . $avatar_img ) )
unlink( '../' . $avatar_img );
$mdb -> delete( 'globelus_users', [ 'id' => $user_id ] );
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#globelus-usnieto-konto' );
$text .= $settings['newsletter_footer_1'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$send = \S::send_email( $email, 'Twoje konto w serwisie GLOBELUS.PL zostało usunięte!', $text );
return true;
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace admin\factory;
class GlobelusFirms
{
public static function order_fvat_switch( $order_id )
{
global $mdb;
if ( $mdb -> get( 'globelus_orders', 'fvat', [ 'id' => $order_id ] ) )
$mdb -> update( 'globelus_orders', [ 'fvat' => 0 ], [ 'id' => $order_id ] );
else
$mdb -> update( 'globelus_orders', [ 'fvat' => 1 ], [ 'id' => $order_id ] );
}
public static function firm_enabled( $user_id )
{
global $mdb, $settings;
$mdb -> update( 'globelus_users', [ 'status' => 1 ], [ 'id' => $user_id ] );
$email = $mdb -> get( 'globelus_users', 'email', [ 'id' => $user_id ] );
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#globelus-potwierdzenie-aktywacji-konta' );
$text .= $settings['newsletter_footer_1'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$send = \S::send_email( $email, 'Potwierdzenie aktywacji konta w portalu GLOBELUS.PL', $text );
return true;
}
public static function firm_details( $user_id )
{
global $mdb;
$g_user = $mdb -> get( 'globelus_users', '*', [ 'id' => $user_id ] );
$g_user_data = $mdb -> get( 'globelus_firms_data', '*', [ 'user_id' => $user_id ] );
$g_user_data['country'] = $mdb -> get( 'globelus_countries', 'name', [ 'id' => $g_user_data['country_id'] ] );
if ( is_array( $g_user_data ) )
{
unset( $g_user_data['id'] );
$g_user = array_merge( $g_user, $g_user_data );
}
$g_user['categories'] = $mdb -> select( 'globelus_firms_categories', 'category_id', [ 'user_id' => $user_id ] );
$g_user['candidates'] = $mdb -> select( 'globelus_firms_candidates', 'candidate_id', [ 'user_id' => $user_id ] );
return $g_user;
}
public static function firm_delete( $user_id )
{
global $mdb, $settings;
$email = \front\factory\GlobelusUser::get_email( $user_id );
$answers_cv = $mdb -> select( 'globelus_adverts_answers', 'cv', [ 'AND' => [ 'user_id' => $user_id, 'cv[!]' => null ] ] );
if ( is_array( $answers_cv ) and count( $answers_cv ) ) foreach ( $answers_cv as $cv )
{
if ( '../' . file_exists( $cv ) )
unlink( '../' . $cv );
}
$mdb -> delete( 'globelus_adverts', [ 'user_id' => $user_id ] );
$mdb -> delete( 'globelus_adverts_answers', [ 'user_id' => $user_id ] );
$cv_file = \front\factory\GlobelusCandidates::cv_url( $user_id );
if ( file_exists( '../' . $cv_file ) )
unlink( '../' . $cv_file );
$avatar_img = \front\factory\GlobelusCandidates::avatar_url( $user_id );
if ( file_exists( '../' . $avatar_img ) )
unlink( '../' . $avatar_img );
$logo_img = \front\factory\GlobelusFirms::logo_url( $user_id );
if ( file_exists( '../' . $avatar_img ) )
unlink( '../' . $avatar_img );
$mdb -> delete( 'globelus_users', [ 'id' => $user_id ] );
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#globelus-usnieto-konto' );
$text .= $settings['newsletter_footer_1'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$send = \S::send_email( $email, 'Twoje konto w serwisie GLOBELUS.PL zostało usunięte!', $text );
return true;
}
}

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,514 @@
<?
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,150 @@
<?
namespace admin\factory;
class Settings
{
public static function settings_update( $param, $value )
{
global $mdb;
$mdb -> delete( 'pp_settings', [ 'param' => $param ] );
$mdb -> insert( 'pp_settings', [ 'param' => $param, 'value' => $value ] );
return true;
}
public static function settings_save(
$firm_name, $firm_adress, $additional_info, $contact_form, $contact_email, $email_host, $email_port, $email_login, $email_password, $google_maps,
$facebook_link, $statistic_code, $htaccess, $robots, $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, $newsletter_cron )
{
global $mdb;
$mdb -> query( 'TRUNCATE pp_settings' );
$mdb -> insert( 'pp_settings', [
[
'param' => 'firm_name',
'value' => $firm_name,
], [
'param' => 'firm_adress',
'value' => $firm_adress
], [
'param' => 'additional_info',
'value' => $additional_info
], [
'param' => 'contact_form',
'value' => $contact_form == 'on' ? 1 : 0
], [
'param' => 'contact_email',
'value' => $contact_email
], [
'param' => 'email_host',
'value' => $email_host
], [
'param' => 'email_port',
'value' => $email_port
], [
'param' => 'email_login',
'value' => $email_login
], [
'param' => 'email_password',
'value' => $email_password
], [
'param' => 'google_maps',
'value' => $google_maps == '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
], [
'param' => 'newsletter_cron',
'value' => $newsletter_cron
]
]
);
\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,161 @@
<?php
namespace admin\factory;
class Sitemap
{
public static function sitemap( $sitemap, $available_domains, $domain_prefix, $www, $url )
{
global $mdb;
$site_map_tmp = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$site_map_tmp .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
$results = $mdb -> select( 'globelus_adverts', [ 'id', 'title', 'last_refresh', 'date_add' ], [ 'AND' => [ 'visible' => 1, 'disabled_by_admin' => 0, 'OR' => [ 'active_to' => null, 'active_to[>=]' => date( 'Y-m-d' ) ] ] ] );
foreach ( $results as $row )
{
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/oferta/' . $row['id'] . '/' . \S::seo( $row['title'], true ) . '</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . ( $row['last_refresh'] ? date( 'Y-m-d', strtotime( $row['last_refresh'] ) ) : date( 'Y-m-d', strtotime( $row['date_add'] ) ) ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
}
$site_map_tmp .= '</urlset>' . PHP_EOL;
$fp = fopen( '../sitemap-oferty-pracy.xml', 'w' );
fwrite( $fp, $site_map_tmp );
fclose( $fp );
$site_map_tmp = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
$site_map_tmp .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL;
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
$results = $mdb -> select( 'globelus_countries', [ 'id', 'name' ] );
foreach ( $results as $row )
{
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/oferty-pracy/' . \S::seo( $row['name'], true ) . '</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/oferty-pracy/' . \S::seo( $row['name'], true ) . '/bez-jezyka</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/oferty-pracy/' . \S::seo( $row['name'], true ) . '/bez-doswiadczenia</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/oferty-pracy/' . \S::seo( $row['name'], true ) . '/dla-par</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
$site_map_tmp .= '<url>' . PHP_EOL;
$site_map_tmp .= '<loc>https://www.globelus.pl/oferty-pracy/' . \S::seo( $row['name'], true ) . '/od-zaraz</loc>' . PHP_EOL;
$site_map_tmp .= '<lastmod>' . date( 'Y-m-d' ) . '</lastmod>' . PHP_EOL;
$site_map_tmp .= '<changefreq>daily</changefreq>' . PHP_EOL;
$site_map_tmp .= '<priority>1</priority>' . PHP_EOL;
$site_map_tmp .= '</url>' . PHP_EOL;
}
$site_map_tmp .= '</urlset>' . PHP_EOL;
$fp = fopen( '../sitemap-panstwa.xml', 'w' );
fwrite( $fp, $site_map_tmp );
fclose( $fp );
// if ( is_array( $available_domains ) and count( $available_domains ) )
// {
// /* to do */
// }
// else
// {
// $sitemap_tmp = $sitemap[ $url ];
// try {
// $results = $mdb -> query( 'SELECT '
// . 'name_seo '
// . 'FROM '
// . 'globelus_adverts_categories AS gac' ) -> fetchAll( \PDO::FETCH_ASSOC );
// if ( is_array( $results ) and count( $results ) ) foreach ( $results as $row )
// {
// $urls .= '<url>' . PHP_EOL;
// $urls .= '<loc>' . $domain_prefix . '://' . $www . $url . '/oferty-pracy/' . $row['name_seo'] . '</loc>' . PHP_EOL;
// $urls .= '<changefreq>weekly</changefreq>' . PHP_EOL;
// $urls .= '<priority>1</priority>' . PHP_EOL;
// $urls .= '</url>' . PHP_EOL;
// }
// }
// catch ( \Throwable $t ) {
// \S::pre( $mdb -> error() );
// }
// try {
// $results = $mdb -> query( 'SELECT '
// . 'name_seo '
// . 'FROM '
// . 'globelus_countries AS gc' ) -> fetchAll( \PDO::FETCH_ASSOC );
// if ( is_array( $results ) and count( $results ) ) foreach ( $results as $row )
// {
// $urls .= '<url>' . PHP_EOL;
// $urls .= '<loc>' . $domain_prefix . '://' . $www . $url . '/oferty-pracy/' . $row['name_seo'] . '</loc>' . PHP_EOL;
// $urls .= '<changefreq>weekly</changefreq>' . PHP_EOL;
// $urls .= '<priority>1</priority>' . PHP_EOL;
// $urls .= '</url>' . PHP_EOL;
// }
// }
// catch ( \Throwable $t ) {
// \S::pre( $mdb -> error() );
// }
// try {
// $results = $mdb -> query( 'SELECT '
// . 'id, title '
// . 'FROM '
// . 'globelus_adverts AS ga '
// . 'WHERE '
// . 'visible = 1 '
// . 'AND '
// . '( active_to IS NULL OR active_to <= \'' . date( 'Y-m-d' ) . '\' )' ) -> fetchAll( \PDO::FETCH_ASSOC );
// if ( is_array( $results ) and count( $results ) ) foreach ( $results as $row )
// {
// $urls .= '<url>' . PHP_EOL;
// $urls .= '<loc>' . $domain_prefix . '://' . $www . $url . '/oferta/' . $row['id'] . '/' . \S::seo( $row['title'], true ) . '</loc>' . PHP_EOL;
// $urls .= '<changefreq>weekly</changefreq>' . PHP_EOL;
// $urls .= '<priority>1</priority>' . PHP_EOL;
// $urls .= '</url>' . PHP_EOL;
// }
// }
// catch ( \Throwable $t ) {
// \S::pre( $mdb -> error() );
// }
// $sitemap_tmp = str_replace( '</urlset>', $urls . '</urlset>', $sitemap_tmp );
// $sitemap[ $url ] = $sitemap_tmp;
// }
return $sitemap;
}
}

View File

@@ -0,0 +1,88 @@
<?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;
$file = file_get_contents( 'http://www.cmspro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '.zip' );
$dlHandler = fopen( 'update.zip' , 'w' );
if ( !fwrite( $dlHandler, $file ) )
return false;
fclose( $dlHandler );
if ( !file_exists( 'update.zip' ) )
return false;
else
{
/* aktualizacja bazy danych */
$sql = file_get_contents( 'http://www.cmspro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt' );
$sql = explode( PHP_EOL, $sql );
if ( is_array( $sql ) and !empty( $sql ) ) foreach ( $sql as $query )
{
if ( $sql )
$result = $mdb -> query( $query );
}
/* usuwanie zbędnych plików */
$lines = file_get_contents( 'http://www.cmspro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt' );
$lines = explode( PHP_EOL, $lines );
if ( is_array( $lines ) ) foreach ( $lines as $line )
{
if ( strpos( $line, 'F: ' ) !== false )
{
$file = substr( $line, 3, strlen( $line ) );
if ( file_exists( $file ) )
unlink( $file );
}
if ( strpos( $line, 'D: ' ) !== false )
{
$dir = substr( $line, 3, strlen( $line ) );
if ( is_dir( $dir ) )
\S::delete_dir( $dir );
}
}
/* wgrywanie nowych plików */
$file_name = 'update.zip';
$path = pathinfo( realpath( $file_name ), PATHINFO_DIRNAME );
$path = substr( $path, 0, strlen( $path ) - 5 );
$zip = new \ZipArchive;
$res = $zip -> open( $file_name );
if ( $res === TRUE )
{
$zip -> extractTo( $path );
$zip -> close();
unlink( $file_name );
}
$updateThis = fopen( '../libraries/version.ini', 'w' );
fwrite( $updateThis, $ver );
fclose( $updateThis );
return true;
}
}
}
}
}

View File

@@ -0,0 +1,185 @@
<?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 )
{
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 ),
] ) )
$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
], [
'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;
}
}
}
?>