first commit

This commit is contained in:
2023-05-29 16:01:03 +02:00
commit 078c88d008
6259 changed files with 829186 additions and 0 deletions

View File

@@ -0,0 +1,693 @@
<?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;
}
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, $main_image, $entry, $text, $table_of_contents, $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, $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_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_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_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_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,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;
}
}
}
?>