refactor(admin): przeniesienie Pages/Layouts/Articles do Domain repositories
This commit is contained in:
648
autoload/Domain/Articles/ArticlesRepository.php
Normal file
648
autoload/Domain/Articles/ArticlesRepository.php
Normal file
@@ -0,0 +1,648 @@
|
||||
<?php
|
||||
namespace Domain\Articles;
|
||||
|
||||
class ArticlesRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct( $db )
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function filesOrderSave( $articleId, $order ): void
|
||||
{
|
||||
$i = 0;
|
||||
$order = explode( ';', $order );
|
||||
|
||||
if ( is_array( $order ) && !empty( $order ) )
|
||||
foreach ( $order as $fileId )
|
||||
$this->db->update( 'pp_articles_files', [ 'o' => (int)$i++ ], [
|
||||
'AND' => [ 'article_id' => $articleId, 'id' => $fileId ]
|
||||
] );
|
||||
}
|
||||
|
||||
public function galleryOrderSave( $articleId, $order ): void
|
||||
{
|
||||
$i = 0;
|
||||
$order = explode( ';', $order );
|
||||
|
||||
if ( is_array( $order ) && !empty( $order ) )
|
||||
foreach ( $order as $imageId )
|
||||
$this->db->update( 'pp_articles_images', [ 'o' => $i++ ], [
|
||||
'AND' => [ 'article_id' => $articleId, 'id' => $imageId ]
|
||||
] );
|
||||
}
|
||||
|
||||
public function additionalParams( $language = 0 )
|
||||
{
|
||||
return $this->db->select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => $language ] ] );
|
||||
}
|
||||
|
||||
public function imageAltChange( $imageId, $imageAlt )
|
||||
{
|
||||
$result = $this->db->update( 'pp_articles_images', [ 'alt' => $imageAlt ], [ 'id' => $imageId ] );
|
||||
\S::delete_cache();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function articleUrl( $articleId )
|
||||
{
|
||||
$results = $this->db->query(
|
||||
"SELECT seo_link FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = " . (int)$articleId . " AND seo_link != '' ORDER BY o ASC LIMIT 1"
|
||||
)->fetchAll();
|
||||
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = $this->articleTitle( $articleId );
|
||||
return 'a-' . $articleId . '-' . \S::seo( $title );
|
||||
}
|
||||
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public function articlePages( $articleId )
|
||||
{
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $this->db );
|
||||
$results = $this->db->query( "SELECT page_id FROM pp_articles_pages WHERE article_id = " . (int)$articleId )->fetchAll();
|
||||
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( $out == '' )
|
||||
$out .= ' - ';
|
||||
|
||||
$out .= $pagesRepo->pageTitle( $row['page_id'] );
|
||||
|
||||
if ( end( $results ) != $row )
|
||||
$out .= ' / ';
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function articleTitle( $articleId )
|
||||
{
|
||||
$results = $this->db->query(
|
||||
"SELECT title FROM pp_articles_langs AS pal, pp_langs AS pl WHERE lang_id = pl.id AND article_id = " . (int)$articleId . " AND title != '' ORDER BY o ASC LIMIT 1"
|
||||
)->fetchAll();
|
||||
|
||||
return $results[0]['title'];
|
||||
}
|
||||
|
||||
public function deleteFile( $fileId ): bool
|
||||
{
|
||||
$this->db->update( 'pp_articles_files', [ 'to_delete' => 1 ], [ 'id' => (int)$fileId ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteImg( $imageId ): bool
|
||||
{
|
||||
$this->db->update( 'pp_articles_images', [ 'to_delete' => 1 ], [ 'id' => (int)$imageId ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function articleDetails( $articleId )
|
||||
{
|
||||
if ( $article = $this->db->get( 'pp_articles', '*', [ 'id' => (int)$articleId ] ) )
|
||||
{
|
||||
$results = $this->db->select( 'pp_articles_langs', '*', [ 'article_id' => (int)$articleId ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
$article['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$article['images'] = $this->db->select( 'pp_articles_images', '*', [ 'article_id' => (int)$articleId, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
||||
$article['files'] = $this->db->select( 'pp_articles_files', '*', [ 'article_id' => (int)$articleId, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
||||
$article['pages'] = $this->db->select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$articleId ] );
|
||||
$article['tags'] = $this->db->select( 'pp_tags', [ '[><]pp_articles_tags' => [ 'id' => 'tag_id' ] ], 'name', [ 'article_id' => (int)$articleId ] );
|
||||
$article['params'] = $this->db->select( 'pp_articles_additional_values', [ 'param_id', 'value', 'language_id' ], [ 'article_id' => (int)$articleId ] );
|
||||
}
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public function insertMissingHash(): bool
|
||||
{
|
||||
if ( $this->db->count( 'pp_articles', [ 'hash' => null ] ) )
|
||||
{
|
||||
$rows = $this->db->select( 'pp_articles', [ 'id', 'date_add' ], [ 'hash' => null ] );
|
||||
if ( is_array( $rows ) )
|
||||
foreach ( $rows as $row )
|
||||
$this->db->update( 'pp_articles', [ 'hash' => md5( $row['id'] . $row['date_add'] ) ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function articlesByDateAdd( $dateStart, $dateEnd )
|
||||
{
|
||||
$results = $this->db->query(
|
||||
'SELECT id FROM pp_articles WHERE status = 1 AND date_add BETWEEN \'' . $dateStart . '\' AND \'' . $dateEnd . '\' ORDER BY date_add DESC'
|
||||
)->fetchAll();
|
||||
|
||||
if ( is_array( $results ) && !empty( $results ) )
|
||||
foreach ( $results as $row )
|
||||
$articles[] = \front\factory\Articles::article_details( $row['id'], 'pl' );
|
||||
|
||||
return isset( $articles ) ? $articles : null;
|
||||
}
|
||||
|
||||
public function articlesSetArchive( $articleId )
|
||||
{
|
||||
$result = $this->db->update( 'pp_articles', [ 'status' => -1 ], [ 'id' => (int)$articleId ] );
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function fileNameChange( $fileId, $fileName ): bool
|
||||
{
|
||||
$this->db->update( 'pp_articles_files', [ 'name' => $fileName ], [ 'id' => (int)$fileId ] );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function deleteNonassignedFiles(): void
|
||||
{
|
||||
$results = $this->db->select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
|
||||
$this->db->delete( 'pp_articles_files', [ 'article_id' => null ] );
|
||||
}
|
||||
|
||||
public function deleteNonassignedImages(): void
|
||||
{
|
||||
$results = $this->db->select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
|
||||
$this->db->delete( 'pp_articles_images', [ 'article_id' => null ] );
|
||||
}
|
||||
|
||||
public function duplicateArticle( $articleId, $userId ): bool
|
||||
{
|
||||
$article = $this->articleDetails( $articleId );
|
||||
|
||||
if ( !$article )
|
||||
return false;
|
||||
|
||||
$this->db->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' => $userId,
|
||||
'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']
|
||||
] );
|
||||
|
||||
$articleTmpId = $this->db->id();
|
||||
if ( !$articleTmpId )
|
||||
return false;
|
||||
|
||||
foreach ( $article['languages'] as $key => $val )
|
||||
$this->db->insert( 'pp_articles_langs', [
|
||||
'article_id' => $articleTmpId,
|
||||
'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 )
|
||||
$this->db->insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $param['param_id'],
|
||||
'value' => $param['value'],
|
||||
'article_id' => $articleTmpId,
|
||||
'language_id' => $param['language_id']
|
||||
] );
|
||||
|
||||
foreach ( $article['pages'] as $page )
|
||||
{
|
||||
$order = $this->maxOrder() + 1;
|
||||
$this->db->insert( 'pp_articles_pages', [
|
||||
'article_id' => $articleTmpId,
|
||||
'page_id' => $page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function articleSave(
|
||||
$articleId, $title, $mainImage, $entry, $text, $tableOfContents, $status, $showTitle, $showTableOfContents, $showDateAdd, $dateAdd, $showDateModify, $dateModify, $seoLink, $metaTitle, $metaDescription,
|
||||
$metaKeywords, $layoutId, $pages, $noindex, $repeatEntry, $copyFrom, $socialIcons, $eventDate, $tags, $blockDirectAccess, $priority, $password, $pixieset, $idAuthor, $params, $userId
|
||||
)
|
||||
{
|
||||
$eventDate = explode( ' - ', $eventDate );
|
||||
|
||||
if ( !$articleId )
|
||||
{
|
||||
$this->db->insert( 'pp_articles', [
|
||||
'show_title' => $showTitle == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $showTableOfContents == 'on' ? 1 : 0,
|
||||
'show_date_add' => $showDateAdd == 'on' ? 1 : 0,
|
||||
'show_date_modify' => $showDateModify == 'on' ? 1 : 0,
|
||||
'date_add' => date( 'Y-m-d H:i:s' ),
|
||||
'date_modify' => date( 'Y-m-d H:i:s' ),
|
||||
'modify_by' => $userId,
|
||||
'layout_id' => $layoutId ? (int)$layoutId : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeatEntry == 'on' ? 1 : 0,
|
||||
'social_icons' => $socialIcons == 'on' ? 1 : 0,
|
||||
'date_start' => $eventDate[0] ? $eventDate[0] : null,
|
||||
'date_end' => $eventDate[1] ? $eventDate[1] : null,
|
||||
'priority' => $priority == 'on' ? 1 : 0,
|
||||
'password' => $password ? $password : null,
|
||||
'pixieset' => $pixieset,
|
||||
'id_author' => $idAuthor ? $idAuthor : null
|
||||
] );
|
||||
|
||||
$id = $this->db->id();
|
||||
if ( !$id )
|
||||
return false;
|
||||
|
||||
$i = 0;
|
||||
$results = $this->db->select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$id,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title[ $i ] != '' ? $title[ $i ] : null,
|
||||
'main_image' => $mainImage[$i] != '' ? $mainImage[$i] : null,
|
||||
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
|
||||
'text' => $text[ $i ] != '' ? $text[ $i ] : null,
|
||||
'table_of_contents' => $tableOfContents[$i] != '' ? $tableOfContents[$i] : null,
|
||||
'meta_title' => $metaTitle[ $i ] != '' ? $metaTitle[ $i ] : null,
|
||||
'meta_description' => $metaDescription[ $i ] != '' ? $metaDescription[ $i ] : null,
|
||||
'meta_keywords' => $metaKeywords[ $i ] != '' ? $metaKeywords[ $i ] : null,
|
||||
'seo_link' => \S::seo( $seoLink[ $i ] ) != '' ? \S::seo( $seoLink[ $i ] ) : null,
|
||||
'noindex' => $noindex[ $i ],
|
||||
'copy_from' => $copyFrom[ $i ] != '' ? $copyFrom[ $i ] : null,
|
||||
'block_direct_access' => $blockDirectAccess[ $i ]
|
||||
] );
|
||||
$i++;
|
||||
}
|
||||
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$id,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title != '' ? $title : null,
|
||||
'main_image' => $mainImage != '' ? $mainImage : null,
|
||||
'entry' => $entry != '' ? $entry : null,
|
||||
'text' => $text != '' ? $text : null,
|
||||
'table_of_contents' => $tableOfContents != '' ? $tableOfContents : null,
|
||||
'meta_title' => $metaTitle != '' ? $metaTitle : null,
|
||||
'meta_description' => $metaDescription != '' ? $metaDescription : null,
|
||||
'meta_keywords' => $metaKeywords != '' ? $metaKeywords : null,
|
||||
'seo_link' => \S::seo( $seoLink ) != '' ? \S::seo( $seoLink ) : null,
|
||||
'noindex' => $noindex,
|
||||
'copy_from' => $copyFrom != '' ? $copyFrom : null,
|
||||
'block_direct_access' => $blockDirectAccess
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $this->db->select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 0 ] ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $row['id'],
|
||||
'value' => $params[ 'ap_' . $row['name'] ],
|
||||
'article_id' => (int)$id,
|
||||
'language_id' => null
|
||||
] );
|
||||
}
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = $this->maxOrder() + 1;
|
||||
$this->db->insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$order = $this->maxOrder() + 1;
|
||||
$this->db->insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$pages,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $this->db->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 );
|
||||
}
|
||||
|
||||
$this->db->update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => $id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
$results = $this->db->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 );
|
||||
}
|
||||
|
||||
$this->db->update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$tags = explode( ',', $tags );
|
||||
if ( is_array( $tags ) ) foreach ( $tags as $tag )
|
||||
{
|
||||
if ( trim( $tag ) != '' )
|
||||
{
|
||||
$tag_id = $this->db->get( 'pp_tags', 'id', [ 'name' => $tag ] );
|
||||
if ( !$tag_id )
|
||||
{
|
||||
$this->db->insert( 'pp_tags', [ 'name' => $tag ] );
|
||||
$tag_id = $this->db->id();
|
||||
}
|
||||
|
||||
$this->db->insert( 'pp_articles_tags', [ 'article_id' => (int)$id, 'tag_id' => (int)$tag_id ] );
|
||||
}
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
|
||||
return $id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update( 'pp_articles', [
|
||||
'show_title' => $showTitle == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $showTableOfContents == 'on' ? 1 : 0,
|
||||
'show_date_add' => $showDateAdd == 'on' ? 1 : 0,
|
||||
'date_add' => $dateAdd,
|
||||
'show_date_modify' => $showDateModify == 'on' ? 1 : 0,
|
||||
'date_modify' => $dateModify ? $dateModify : date( 'Y-m-d H:i:s' ),
|
||||
'modify_by' => $userId,
|
||||
'layout_id' => $layoutId ? (int)$layoutId : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeatEntry == 'on' ? 1 : 0,
|
||||
'social_icons' => $socialIcons == 'on' ? 1 : 0,
|
||||
'date_start' => $eventDate[0] ? $eventDate[0] : null,
|
||||
'date_end' => $eventDate[1] ? $eventDate[1] : null,
|
||||
'priority' => $priority == 'on' ? 1 : 0,
|
||||
'password' => $password ? $password : null,
|
||||
'pixieset' => $pixieset,
|
||||
'id_author' => $idAuthor ? $idAuthor : null
|
||||
], [
|
||||
'id' => (int)$articleId
|
||||
] );
|
||||
|
||||
if ( $dateAdd )
|
||||
$this->db->update( 'pp_articles', [ 'date_add' => $dateAdd ], [ 'id' => (int)$articleId ] );
|
||||
|
||||
$i = 0;
|
||||
$this->db->delete( 'pp_articles_langs', [ 'article_id' => (int)$articleId ] );
|
||||
|
||||
$results = $this->db->select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$articleId,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title[ $i ] != '' ? $title[ $i ] : null,
|
||||
'main_image' => $mainImage[$i] != '' ? $mainImage[$i] : null,
|
||||
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
|
||||
'text' => $text[ $i ] != '' ? $text[ $i ] : null,
|
||||
'table_of_contents' => $tableOfContents[$i] != '' ? $tableOfContents[$i] : null,
|
||||
'meta_title' => $metaTitle[ $i ] != '' ? $metaTitle[ $i ] : null,
|
||||
'meta_description' => $metaDescription[ $i ] != '' ? $metaDescription[ $i ] : null,
|
||||
'meta_keywords' => $metaKeywords[ $i ] != '' ? $metaKeywords[ $i ] : null,
|
||||
'seo_link' => \S::seo( $seoLink[ $i ] ) != '' ? \S::seo( $seoLink[ $i ] ) : null,
|
||||
'noindex' => $noindex[ $i ],
|
||||
'copy_from' => $copyFrom[ $i ] != '' ? $copyFrom[ $i ] : null,
|
||||
'block_direct_access' => $blockDirectAccess[ $i ]
|
||||
] );
|
||||
$i++;
|
||||
}
|
||||
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$articleId,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title != '' ? $title : null,
|
||||
'main_image' => $mainImage != '' ? $mainImage : null,
|
||||
'entry' => $entry != '' ? $entry : null,
|
||||
'text' => $text != '' ? $text : null,
|
||||
'table_of_contents' => $tableOfContents != '' ? $tableOfContents : null,
|
||||
'meta_title' => $metaTitle != '' ? $metaTitle : null,
|
||||
'meta_description' => $metaDescription != '' ? $metaDescription : null,
|
||||
'meta_keywords' => $metaKeywords != '' ? $metaKeywords : null,
|
||||
'seo_link' => \S::seo( $seoLink ) != '' ? \S::seo( $seoLink ) : null,
|
||||
'noindex' => $noindex,
|
||||
'copy_from' => $copyFrom != '' ? $copyFrom : null,
|
||||
'block_direct_access' => $blockDirectAccess
|
||||
] );
|
||||
}
|
||||
|
||||
$this->db->delete( 'pp_articles_additional_values', [ 'article_id' => (int)$articleId ] );
|
||||
|
||||
$results = $this->db->select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 0 ] ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $row['id'],
|
||||
'value' => $params[ 'ap_' . $row['name'] ],
|
||||
'article_id' => (int)$articleId,
|
||||
'language_id' => null
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $this->db->select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 1 ] ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$results2 = $this->db->select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
{
|
||||
$this->db->insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $row['id'],
|
||||
'value' => $params[ 'ap_' . $row['name'] . '_' . $row2['id'] ],
|
||||
'article_id' => (int)$articleId,
|
||||
'language_id' => $row2['id']
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
$not_in = [ 0 ];
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
$not_in[] = $page;
|
||||
else if ( $pages )
|
||||
$not_in[] = $pages;
|
||||
|
||||
$this->db->delete( 'pp_articles_pages', [ 'AND' => [ 'article_id' => (int)$articleId, 'page_id[!]' => $not_in ] ] );
|
||||
|
||||
$pages_tmp = $this->db->select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$articleId ] );
|
||||
if ( !is_array( $pages ) )
|
||||
$pages = [ $pages ];
|
||||
|
||||
$pages = array_diff( $pages, $pages_tmp );
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = $this->maxOrder() + 1;
|
||||
$this->db->insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$articleId,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
$results = $this->db->select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $articleId;
|
||||
$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 );
|
||||
}
|
||||
|
||||
$this->db->update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => (int)$articleId ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
$results = $this->db->select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $articleId;
|
||||
$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 );
|
||||
}
|
||||
|
||||
$this->db->update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$articleId ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$results = $this->db->select( 'pp_articles_images', '*', [ 'AND' => [ 'article_id' => (int)$articleId, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
|
||||
$this->db->delete( 'pp_articles_images', [ 'AND' => [ 'article_id' => (int)$articleId, 'to_delete' => 1 ] ] );
|
||||
|
||||
$results = $this->db->select( 'pp_articles_files', '*', [ 'AND' => [ 'article_id' => (int)$articleId, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
|
||||
$this->db->delete( 'pp_articles_files', [ 'AND' => [ 'article_id' => (int)$articleId, 'to_delete' => 1 ] ] );
|
||||
|
||||
$this->db->delete( 'pp_articles_tags', [ 'article_id' => (int)$articleId ] );
|
||||
|
||||
$tags = explode( ',', $tags );
|
||||
if ( is_array( $tags ) ) foreach ( $tags as $tag )
|
||||
{
|
||||
if ( trim( $tag ) != '' )
|
||||
{
|
||||
$tag_id = $this->db->get( 'pp_tags', 'id', [ 'name' => $tag ] );
|
||||
if ( !$tag_id )
|
||||
{
|
||||
$this->db->insert( 'pp_tags', [ 'name' => $tag ] );
|
||||
$tag_id = $this->db->id();
|
||||
}
|
||||
|
||||
$this->db->insert( 'pp_articles_tags', [ 'article_id' => (int)$articleId, 'tag_id' => (int)$tag_id ] );
|
||||
}
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
return $articleId;
|
||||
}
|
||||
}
|
||||
|
||||
public function maxOrder()
|
||||
{
|
||||
return $this->db->max( 'pp_articles_pages', 'o' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
123
autoload/Domain/Layouts/LayoutsRepository.php
Normal file
123
autoload/Domain/Layouts/LayoutsRepository.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
namespace Domain\Layouts;
|
||||
|
||||
class LayoutsRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct( $db )
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function layoutDelete( $layoutId )
|
||||
{
|
||||
if ( $this->db->count( 'pp_layouts' ) > 1 )
|
||||
return $this->db->delete( 'pp_layouts', [ 'id' => (int)$layoutId ] );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function layoutDetails( $layoutId )
|
||||
{
|
||||
$layout = $this->db->get( 'pp_layouts', '*', [ 'id' => (int)$layoutId ] );
|
||||
$layout['pages'] = $this->db->select( 'pp_layouts_pages', 'page_id', [ 'layout_id' => (int)$layoutId ] );
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
public function layoutSave( $layoutId, $name, $status, $pages, $html, $css, $js, $mHtml, $mCss, $mJs )
|
||||
{
|
||||
if ( !$layoutId )
|
||||
return $this->createLayout( $name, $status, $pages, $html, $css, $js, $mHtml, $mCss, $mJs );
|
||||
|
||||
return $this->updateLayout( $layoutId, $name, $status, $pages, $html, $css, $js, $mHtml, $mCss, $mJs );
|
||||
}
|
||||
|
||||
public function menusList()
|
||||
{
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $this->db );
|
||||
$results = $this->db->select( 'pp_menus', 'id', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$menu = $pagesRepo->menuDetails( $row );
|
||||
$menu['pages'] = $pagesRepo->menuPages( $row );
|
||||
$menus[] = $menu;
|
||||
}
|
||||
|
||||
return isset( $menus ) ? $menus : null;
|
||||
}
|
||||
|
||||
public function layoutsList()
|
||||
{
|
||||
return $this->db->select( 'pp_layouts', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
private function createLayout( $name, $status, $pages, $html, $css, $js, $mHtml, $mCss, $mJs )
|
||||
{
|
||||
if ( $status == 'on' )
|
||||
$this->db->update( 'pp_layouts', [ 'status' => 0 ] );
|
||||
|
||||
$this->db->insert( 'pp_layouts', [
|
||||
'name' => $name,
|
||||
'html' => $html,
|
||||
'css' => $css,
|
||||
'js' => $js,
|
||||
'm_html' => $mHtml,
|
||||
'm_css' => $mCss,
|
||||
'm_js' => $mJs,
|
||||
'status' => $status == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
$id = $this->db->id();
|
||||
if ( !$id )
|
||||
return false;
|
||||
|
||||
$this->replaceLayoutPages( (int)$id, $pages );
|
||||
\S::delete_cache();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function updateLayout( $layoutId, $name, $status, $pages, $html, $css, $js, $mHtml, $mCss, $mJs )
|
||||
{
|
||||
if ( $status == 'on' )
|
||||
$this->db->update( 'pp_layouts', [ 'status' => 0 ] );
|
||||
|
||||
$this->db->update( 'pp_layouts', [
|
||||
'name' => $name,
|
||||
'html' => $html,
|
||||
'css' => $css,
|
||||
'js' => $js,
|
||||
'm_html' => $mHtml,
|
||||
'm_css' => $mCss,
|
||||
'm_js' => $mJs,
|
||||
'status' => $status == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $layoutId
|
||||
] );
|
||||
|
||||
$this->db->delete( 'pp_layouts_pages', [ 'layout_id' => (int)$layoutId ] );
|
||||
$this->replaceLayoutPages( (int)$layoutId, $pages );
|
||||
|
||||
\S::delete_cache();
|
||||
return $layoutId;
|
||||
}
|
||||
|
||||
private function replaceLayoutPages( int $layoutId, $pages ): void
|
||||
{
|
||||
if ( is_array( $pages ) )
|
||||
foreach ( $pages as $page )
|
||||
{
|
||||
$this->db->delete( 'pp_layouts_pages', [ 'page_id' => (int)$page ] );
|
||||
$this->db->insert( 'pp_layouts_pages', [ 'layout_id' => $layoutId, 'page_id' => (int)$page ] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$this->db->delete( 'pp_layouts_pages', [ 'page_id' => (int)$pages ] );
|
||||
$this->db->insert( 'pp_layouts_pages', [ 'layout_id' => $layoutId, 'page_id' => (int)$pages ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
451
autoload/Domain/Pages/PagesRepository.php
Normal file
451
autoload/Domain/Pages/PagesRepository.php
Normal file
@@ -0,0 +1,451 @@
|
||||
<?php
|
||||
namespace Domain\Pages;
|
||||
|
||||
class PagesRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
public function __construct( $db )
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
public function saveArticlesOrder( $pageId, $articles ): bool
|
||||
{
|
||||
if ( is_array( $articles ) )
|
||||
{
|
||||
$this->db->update( 'pp_articles_pages', [ 'o' => 0 ], [ 'page_id' => (int) $pageId ] );
|
||||
$x = 0;
|
||||
|
||||
for ( $i = 0; $i < count( $articles ); $i++ )
|
||||
{
|
||||
if ( $articles[$i]['item_id'] )
|
||||
{
|
||||
$x++;
|
||||
$this->db->update( 'pp_articles_pages', [ 'o' => $x ], [
|
||||
'AND' => [ 'page_id' => (int) $pageId, 'article_id' => $articles[$i]['item_id'] ]
|
||||
] );
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function pageArticles( $pageId )
|
||||
{
|
||||
$results = $this->db->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) $pageId . ' AND status != -1 ORDER BY o ASC'
|
||||
)->fetchAll();
|
||||
|
||||
$articles = [];
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = \admin\factory\Articles::article_title( $row['article_id'] );
|
||||
$articles[] = $row;
|
||||
}
|
||||
|
||||
return $articles;
|
||||
}
|
||||
|
||||
public function menusList()
|
||||
{
|
||||
return $this->db->select( 'pp_menus', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public function savePagesOrder( $menuId, $pages ): bool
|
||||
{
|
||||
if ( is_array( $pages ) )
|
||||
{
|
||||
$this->db->update( 'pp_pages', [ 'o' => 0 ], [ 'menu_id' => (int) $menuId ] );
|
||||
$x = 0;
|
||||
|
||||
for ( $i = 0; $i < count( $pages ); $i++ )
|
||||
{
|
||||
if ( $pages[$i]['item_id'] )
|
||||
{
|
||||
$parentId = $pages[$i]['parent_id'] ? $pages[$i]['parent_id'] : 0;
|
||||
|
||||
if ( $pages[$i]['item_id'] && $pages[$i]['depth'] > 1 )
|
||||
{
|
||||
if ( $pages[$i]['depth'] == 2 )
|
||||
$parentId = null;
|
||||
|
||||
$x++;
|
||||
$this->db->update( 'pp_pages', [ 'o' => $x, 'parent_id' => $parentId ], [ 'id' => (int) $pages[$i]['item_id'] ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
\S::delete_cache();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function pageDelete( $pageId ): bool
|
||||
{
|
||||
if ( $this->db->count( 'pp_pages', [ 'parent_id' => (int) $pageId ] ) )
|
||||
return false;
|
||||
|
||||
if ( $this->db->delete( 'pp_pages', [ 'id' => (int) $pageId ] ) )
|
||||
{
|
||||
\S::delete_cache();
|
||||
\S::htacces();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function maxOrder(): int
|
||||
{
|
||||
return (int) $this->db->max( 'pp_pages', 'o' );
|
||||
}
|
||||
|
||||
public function updateSubpagesMenuId( int $parentId, int $menuId ): void
|
||||
{
|
||||
$this->updateSubpagesMenuIdRecursive( $parentId, $menuId );
|
||||
}
|
||||
|
||||
public function generateSeoLink( $title, $pageId, $articleId, $lang, $pid )
|
||||
{
|
||||
$seoLink = \S::seo( $title );
|
||||
$seoLinkCheck = false;
|
||||
$i = 0;
|
||||
|
||||
while ( !$seoLinkCheck )
|
||||
{
|
||||
if ( $this->db->count( 'pp_pages_langs', [ 'AND' => [ 'seo_link' => $seoLink, 'page_id[!]' => (int) $pageId ] ] ) )
|
||||
$seoLink = $seoLink . '-' . ( ++$i );
|
||||
else
|
||||
$seoLinkCheck = true;
|
||||
}
|
||||
|
||||
$seoLinkCheck = false;
|
||||
|
||||
while ( !$seoLinkCheck )
|
||||
{
|
||||
if ( $this->db->count( 'pp_articles_langs', [ 'AND' => [ 'seo_link' => $seoLink, 'article_id[!]' => (int) $articleId ] ] ) )
|
||||
$seoLink = $seoLink . '-' . ( ++$i );
|
||||
else
|
||||
$seoLinkCheck = true;
|
||||
}
|
||||
|
||||
return $seoLink;
|
||||
}
|
||||
|
||||
public function googleUrlPreview( $pageId, $title, $lang, $pid, $id, $seoLink, $languageLink = '' )
|
||||
{
|
||||
$prefix = $languageLink;
|
||||
$status = true;
|
||||
$idPage = $pageId;
|
||||
$seo = '';
|
||||
|
||||
do
|
||||
{
|
||||
if ( $pageId )
|
||||
{
|
||||
$parent = $this->pageDetails( $pageId );
|
||||
$parentId = $parent['parent_id'];
|
||||
}
|
||||
else
|
||||
$parentId = $pid;
|
||||
|
||||
if ( $parentId )
|
||||
{
|
||||
$results = $this->db->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) $parentId . " 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;
|
||||
$pageId = $results[0]['page_id'];
|
||||
}
|
||||
else
|
||||
$status = false;
|
||||
}
|
||||
while ( $status );
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
if ( !$seoLink )
|
||||
$seo = $seo . 's-' . $id . '-' . \S::seo( $title );
|
||||
else
|
||||
$seo = $seo . $seoLink;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !$seoLink )
|
||||
$seo = $seo . 's-' . $idPage . '-' . \S::seo( $title );
|
||||
else
|
||||
$seo = $seo . $seoLink;
|
||||
}
|
||||
|
||||
if ( $prefix )
|
||||
$seo = $prefix . $seo;
|
||||
|
||||
return $seo;
|
||||
}
|
||||
|
||||
public function menuDelete( $menuId )
|
||||
{
|
||||
if ( $this->db->count( 'pp_pages', [ 'menu_id' => (int) $menuId ] ) )
|
||||
return false;
|
||||
|
||||
return $this->db->delete( 'pp_menus', [ 'id' => (int) $menuId ] );
|
||||
}
|
||||
|
||||
public function menuDetails( $menuId )
|
||||
{
|
||||
return $this->db->get( 'pp_menus', '*', [ 'id' => (int) $menuId ] );
|
||||
}
|
||||
|
||||
public function menuSave( $menuId, $name, $status )
|
||||
{
|
||||
$status == 'on' ? $status = 1 : $status = 0;
|
||||
|
||||
if ( !$menuId )
|
||||
{
|
||||
return $this->db->insert( 'pp_menus', [ 'name' => $name, 'status' => $status ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->update( 'pp_menus', [ 'name' => $name, 'status' => $status ], [ 'id' => (int) $menuId ] );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function menuLists()
|
||||
{
|
||||
return $this->db->select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public function pageDetails( $pageId )
|
||||
{
|
||||
$page = $this->db->get( 'pp_pages', '*', [ 'id' => (int) $pageId ] );
|
||||
|
||||
$results = $this->db->select( 'pp_pages_langs', '*', [ 'page_id' => (int) $pageId ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
$page['languages'][$row['lang_id']] = $row;
|
||||
|
||||
$page['layout_id'] = $this->db->get( 'pp_layouts_pages', 'layout_id', [ 'page_id' => (int) $pageId ] );
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function pageUrl( $pageId )
|
||||
{
|
||||
$results = $this->db->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) $pageId . " AND seo_link != '' ORDER BY o ASC LIMIT 1"
|
||||
)->fetchAll();
|
||||
|
||||
if ( !$results[0]['seo_link'] )
|
||||
{
|
||||
$title = $this->pageTitle( $article_id );
|
||||
return 's-' . $pageId . '-' . \S::seo( $title );
|
||||
}
|
||||
else
|
||||
return $results[0]['seo_link'];
|
||||
}
|
||||
|
||||
public function pageTitle( $pageId )
|
||||
{
|
||||
$result = $this->db->select( 'pp_pages_langs', [ '[><]pp_langs' => [ 'lang_id' => 'id' ] ], 'title', [
|
||||
'AND' => [ 'page_id' => (int) $pageId, 'title[!]' => '' ], 'ORDER' => [ 'o' => 'ASC' ], 'LIMIT' => 1
|
||||
] );
|
||||
return $result[0];
|
||||
}
|
||||
|
||||
public function pageLanguages( $pageId )
|
||||
{
|
||||
return $this->db->select( 'pp_pages_langs', '*', [ 'AND' => [ 'page_id' => (int) $pageId, 'title[!]' => null ] ] );
|
||||
}
|
||||
|
||||
public function menuPages( $menuId, $parentId = null )
|
||||
{
|
||||
$results = $this->db->select( 'pp_pages', [ 'id', 'menu_id', 'status', 'parent_id', 'start' ], [
|
||||
'AND' => [ 'menu_id' => $menuId, 'parent_id' => $parentId ], 'ORDER' => [ 'o' => 'ASC' ]
|
||||
] );
|
||||
|
||||
if ( !is_array( $results ) || !count( $results ) )
|
||||
return null;
|
||||
|
||||
foreach ( $results as $row )
|
||||
{
|
||||
$row['title'] = $this->pageTitle( $row['id'] );
|
||||
$row['languages'] = $this->pageLanguages( $row['id'] );
|
||||
$row['subpages'] = $this->menuPages( $menuId, $row['id'] );
|
||||
|
||||
$pages[] = $row;
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
public function pageSave(
|
||||
$pageId, $title, $seoLink, $metaTitle, $metaDescription, $metaKeywords, $menuId, $parentId, $pageType, $sortType, $layoutId, $articlesLimit, $showTitle, $status, $link, $noindex, $start,
|
||||
$siteTitle, $blockDirectAccess, $cache, $canonical
|
||||
)
|
||||
{
|
||||
$parentId = $parentId ? $parentId : null;
|
||||
|
||||
if ( !$pageId )
|
||||
return $this->createPage(
|
||||
$title, $seoLink, $metaTitle, $metaDescription, $metaKeywords, $menuId, $parentId, $pageType, $sortType, $layoutId, $articlesLimit, $showTitle, $status, $link, $noindex, $start,
|
||||
$siteTitle, $blockDirectAccess, $cache, $canonical
|
||||
);
|
||||
|
||||
return $this->updatePage(
|
||||
$pageId, $title, $seoLink, $metaTitle, $metaDescription, $metaKeywords, $menuId, $parentId, $pageType, $sortType, $layoutId, $articlesLimit, $showTitle, $status, $link, $noindex, $start,
|
||||
$siteTitle, $blockDirectAccess, $cache, $canonical
|
||||
);
|
||||
}
|
||||
|
||||
private function createPage(
|
||||
$title, $seoLink, $metaTitle, $metaDescription, $metaKeywords, $menuId, $parentId, $pageType, $sortType, $layoutId, $articlesLimit, $showTitle, $status, $link, $noindex, $start, $siteTitle,
|
||||
$blockDirectAccess, $cache, $canonical
|
||||
)
|
||||
{
|
||||
$order = $this->maxOrder() + 1;
|
||||
|
||||
$this->db->insert( 'pp_pages', [
|
||||
'menu_id' => (int) $menuId,
|
||||
'page_type' => $pageType,
|
||||
'sort_type' => $sortType,
|
||||
'articles_limit' => $articlesLimit,
|
||||
'show_title' => $showTitle == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'o' => (int) $order,
|
||||
'parent_id' => $parentId,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'cache' => $cache == 'on' ? 1 : 0,
|
||||
] );
|
||||
|
||||
$id = $this->db->id();
|
||||
if ( !$id )
|
||||
return false;
|
||||
|
||||
if ( $start )
|
||||
$this->db->update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int) $id ] );
|
||||
|
||||
if ( $layoutId )
|
||||
$this->db->insert( 'pp_layouts_pages', [ 'page_id' => (int) $id, 'layout_id' => (int) $layoutId ] );
|
||||
|
||||
$languages = $this->activeLanguages();
|
||||
$this->savePageLanguages( (int) $id, $languages, $title, $metaDescription, $metaKeywords, $metaTitle, $seoLink, $noindex, $siteTitle, $link, $blockDirectAccess, $canonical );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function updatePage(
|
||||
$pageId, $title, $seoLink, $metaTitle, $metaDescription, $metaKeywords, $menuId, $parentId, $pageType, $sortType, $layoutId, $articlesLimit, $showTitle, $status, $link, $noindex, $start,
|
||||
$siteTitle, $blockDirectAccess, $cache, $canonical
|
||||
)
|
||||
{
|
||||
$this->db->update( 'pp_pages', [
|
||||
'menu_id' => (int) $menuId,
|
||||
'page_type' => $pageType,
|
||||
'sort_type' => $sortType,
|
||||
'articles_limit' => $articlesLimit,
|
||||
'show_title' => $showTitle == 'on' ? 1 : 0,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'parent_id' => $parentId,
|
||||
'start' => $start == 'on' ? 1 : 0,
|
||||
'cache' => $cache == 'on' ? 1 : 0,
|
||||
], [
|
||||
'id' => (int) $pageId
|
||||
] );
|
||||
|
||||
if ( $layoutId )
|
||||
{
|
||||
$this->db->delete( 'pp_layouts_pages', [ 'page_id' => (int) $pageId ] );
|
||||
$this->db->insert( 'pp_layouts_pages', [ 'layout_id' => (int) $layoutId, 'page_id' => (int) $pageId ] );
|
||||
}
|
||||
|
||||
if ( $start )
|
||||
$this->db->update( 'pp_pages', [ 'start' => 0 ], [ 'id[!]' => (int) $pageId ] );
|
||||
|
||||
$this->db->delete( 'pp_pages_langs', [ 'page_id' => (int) $pageId ] );
|
||||
|
||||
$languages = $this->activeLanguages();
|
||||
$this->savePageLanguages( (int) $pageId, $languages, $title, $metaDescription, $metaKeywords, $metaTitle, $seoLink, $noindex, $siteTitle, $link, $blockDirectAccess, $canonical );
|
||||
|
||||
$this->updateSubpagesMenuIdRecursive( (int) $pageId, (int) $menuId );
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
|
||||
return $pageId;
|
||||
}
|
||||
|
||||
private function activeLanguages(): array
|
||||
{
|
||||
return $this->db->select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] ) ?: [];
|
||||
}
|
||||
|
||||
private function savePageLanguages(
|
||||
int $pageId, array $languages, $title, $metaDescription, $metaKeywords, $metaTitle, $seoLink, $noindex, $siteTitle, $link, $blockDirectAccess, $canonical
|
||||
): void
|
||||
{
|
||||
$isMulti = count( $languages ) > 1;
|
||||
|
||||
foreach ( $languages as $i => $row )
|
||||
{
|
||||
$titleValue = $this->languageValue( $title, $i, $isMulti );
|
||||
$metaDescriptionValue = $this->languageValue( $metaDescription, $i, $isMulti );
|
||||
$metaKeywordsValue = $this->languageValue( $metaKeywords, $i, $isMulti );
|
||||
$metaTitleValue = $this->languageValue( $metaTitle, $i, $isMulti );
|
||||
$seoLinkValue = $this->languageValue( $seoLink, $i, $isMulti );
|
||||
$noindexValue = $this->languageValue( $noindex, $i, $isMulti );
|
||||
$siteTitleValue = $this->languageValue( $siteTitle, $i, $isMulti );
|
||||
$linkValue = $this->languageValue( $link, $i, $isMulti );
|
||||
$blockDirectAccessValue = $this->languageValue( $blockDirectAccess, $i, $isMulti );
|
||||
$canonicalValue = $this->languageValue( $canonical, $i, $isMulti );
|
||||
|
||||
$seo = \S::seo( $seoLinkValue );
|
||||
|
||||
$this->db->insert( 'pp_pages_langs', [
|
||||
'page_id' => $pageId,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $this->nullIfEmpty( $titleValue ),
|
||||
'meta_description' => $this->nullIfEmpty( $metaDescriptionValue ),
|
||||
'meta_keywords' => $this->nullIfEmpty( $metaKeywordsValue ),
|
||||
'meta_title' => $this->nullIfEmpty( $metaTitleValue ),
|
||||
'seo_link' => $seo != '' ? $seo : null,
|
||||
'noindex' => $noindexValue,
|
||||
'site_title' => $this->nullIfEmpty( $siteTitleValue ),
|
||||
'link' => $this->nullIfEmpty( $linkValue ),
|
||||
'block_direct_access' => $blockDirectAccessValue,
|
||||
'canonical' => $this->nullIfEmpty( $canonicalValue )
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
private function languageValue( $value, int $index, bool $isMulti )
|
||||
{
|
||||
if ( $isMulti )
|
||||
return is_array( $value ) ? ( $value[$index] ?? null ) : null;
|
||||
|
||||
return is_array( $value ) ? ( $value[0] ?? null ) : $value;
|
||||
}
|
||||
|
||||
private function nullIfEmpty( $value )
|
||||
{
|
||||
return $value != '' ? $value : null;
|
||||
}
|
||||
|
||||
private function updateSubpagesMenuIdRecursive( int $parentId, int $menuId ): void
|
||||
{
|
||||
$this->db->update( 'pp_pages', [ 'menu_id' => $menuId ], [ 'parent_id' => $parentId ] );
|
||||
|
||||
$results = $this->db->select( 'pp_pages', [ 'id' ], [ 'parent_id' => $parentId ] );
|
||||
if ( is_array( $results ) )
|
||||
foreach ( $results as $row )
|
||||
$this->updateSubpagesMenuIdRecursive( (int) $row['id'], $menuId );
|
||||
}
|
||||
}
|
||||
@@ -1,714 +1,117 @@
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
class Articles
|
||||
{
|
||||
public static function duplicate_article( $article_id )
|
||||
private static function repo(): \Domain\Articles\ArticlesRepository
|
||||
{
|
||||
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;
|
||||
global $mdb;
|
||||
return new \Domain\Articles\ArticlesRepository( $mdb );
|
||||
}
|
||||
|
||||
public static function insert_missing_hash() {
|
||||
global $mdb;
|
||||
public static function duplicate_article( $article_id )
|
||||
{
|
||||
global $user;
|
||||
return self::repo()->duplicateArticle( $article_id, (int)$user['id'] );
|
||||
}
|
||||
|
||||
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 insert_missing_hash()
|
||||
{
|
||||
return self::repo()->insertMissingHash();
|
||||
}
|
||||
|
||||
static public function files_order_save( $article_id, $order )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$order = explode( ';', $order );
|
||||
if ( is_array( $order ) and !empty( $order ) ) foreach ( $order as $file_id )
|
||||
{
|
||||
$mdb -> update( 'pp_articles_files', [
|
||||
'o' => (int)$i++
|
||||
], [
|
||||
'AND' => [
|
||||
'article_id' => $article_id,
|
||||
'id' => $file_id
|
||||
]
|
||||
] );
|
||||
}
|
||||
self::repo()->filesOrderSave( $article_id, $order );
|
||||
}
|
||||
|
||||
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
|
||||
]
|
||||
] );
|
||||
}
|
||||
self::repo()->galleryOrderSave( $article_id, $order );
|
||||
}
|
||||
|
||||
public static function additional_params( $language = 0 )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => $language ] ] );
|
||||
return self::repo()->additionalParams( $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;
|
||||
return self::repo()->imageAltChange( $image_id, $image_alt );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->articlesByDateAdd( $date_start, $date_end );
|
||||
}
|
||||
|
||||
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'];
|
||||
return self::repo()->articleUrl( $article_id );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->articlePages( $article_id );
|
||||
}
|
||||
|
||||
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'];
|
||||
return self::repo()->articleTitle( $article_id );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->articlesSetArchive( $article_id );
|
||||
}
|
||||
|
||||
public static function file_name_change( $file_id, $file_name )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_files', [ 'name' => $file_name ], [ 'id' => (int)$file_id ] );
|
||||
return true;
|
||||
return self::repo()->fileNameChange( $file_id, $file_name );
|
||||
}
|
||||
|
||||
public static function delete_file( $file_id )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_files', [ 'to_delete' => 1 ], [ 'id' => (int)$file_id ] );
|
||||
return true;
|
||||
return self::repo()->deleteFile( $file_id );
|
||||
}
|
||||
|
||||
public static function delete_img( $image_id )
|
||||
{
|
||||
global $mdb;
|
||||
$mdb -> update( 'pp_articles_images', [ 'to_delete' => 1 ], [ 'id' => (int)$image_id ] );
|
||||
return true;
|
||||
return self::repo()->deleteImg( $image_id );
|
||||
}
|
||||
|
||||
public static function article_details( $article_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] ) )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_articles_langs', '*', [ 'article_id' => (int)$article_id ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$article['languages'][ $row['lang_id'] ] = $row;
|
||||
|
||||
$article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
||||
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
|
||||
$article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
$article['tags'] = $mdb -> select( 'pp_tags', [ '[><]pp_articles_tags' => [ 'id' => 'tag_id' ] ], 'name', [ 'article_id' => (int)$article_id ] );
|
||||
$article['params'] = $mdb -> select( 'pp_articles_additional_values', [ 'param_id', 'value', 'language_id' ], [ 'article_id' => (int)$article_id ] );
|
||||
}
|
||||
|
||||
return $article;
|
||||
return self::repo()->articleDetails( $article_id );
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_articles_pages', 'o' );
|
||||
return self::repo()->maxOrder();
|
||||
}
|
||||
|
||||
public static function article_save(
|
||||
$article_id, $title, $main_image, $entry, $text, $table_of_contents, $status, $show_title, $show_table_of_contents, $show_date_add, $date_add, $show_date_modify, $date_modify, $seo_link, $meta_title, $meta_description,
|
||||
$meta_keywords, $layout_id, $pages, $noindex, $repeat_entry, $copy_from, $social_icons, $event_date, $tags, $block_direct_access, $priority,
|
||||
$password, $pixieset, $id_author, $params )
|
||||
$article_id, $title, $main_image, $entry, $text, $table_of_contents, $status, $show_title, $show_table_of_contents, $show_date_add, $date_add, $show_date_modify, $date_modify, $seo_link, $meta_title, $meta_description,
|
||||
$meta_keywords, $layout_id, $pages, $noindex, $repeat_entry, $copy_from, $social_icons, $event_date, $tags, $block_direct_access, $priority,
|
||||
$password, $pixieset, $id_author, $params
|
||||
)
|
||||
{
|
||||
|
||||
global $mdb, $user;
|
||||
|
||||
$event_date = explode( ' - ', $event_date );
|
||||
|
||||
if ( !$article_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles', [
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $show_table_of_contents == 'on' ? 1 : 0,
|
||||
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
|
||||
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
|
||||
'date_add' => date( 'Y-m-d H:i:s' ),
|
||||
'date_modify' => date( 'Y-m-d H:i:s' ),
|
||||
'modify_by' => $user['id'],
|
||||
'layout_id' => $layout_id ? (int)$layout_id : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeat_entry == 'on' ? 1 : 0,
|
||||
'social_icons' => $social_icons == 'on' ? 1 : 0,
|
||||
'date_start' => $event_date[0] ? $event_date[0] : null,
|
||||
'date_end' => $event_date[1] ? $event_date[1] : null,
|
||||
'priority' => $priority == 'on' ? 1 : 0,
|
||||
'password' => $password ? $password : null,
|
||||
'pixieset' => $pixieset,
|
||||
'id_author' => $id_author ? $id_author : null
|
||||
] );
|
||||
|
||||
$id = $mdb -> id();
|
||||
|
||||
if ( $id )
|
||||
{
|
||||
$i = 0;
|
||||
|
||||
/* tłumaczenia */
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$id,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title[ $i ] != '' ? $title[ $i ] : null,
|
||||
'main_image' => $main_image[$i] != '' ? $main_image[$i] : null,
|
||||
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
|
||||
'text' => $text[ $i ] != '' ? $text[ $i ] : null,
|
||||
'table_of_contents' => $table_of_contents[$i] != '' ? $table_of_contents[$i] : null,
|
||||
'meta_title' => $meta_title[ $i ] != '' ? $meta_title[ $i ] : null,
|
||||
'meta_description' => $meta_description[ $i ] != '' ? $meta_description[ $i ] : null,
|
||||
'meta_keywords' => $meta_keywords[ $i ] != '' ? $meta_keywords[ $i ] : null,
|
||||
'seo_link' => \S::seo( $seo_link[ $i ] ) != '' ? \S::seo( $seo_link[ $i ] ) : null,
|
||||
'noindex' => $noindex[ $i ],
|
||||
'copy_from' => $copy_from[ $i ] != '' ? $copy_from[ $i ] : null,
|
||||
'block_direct_access' => $block_direct_access[ $i ]
|
||||
] );
|
||||
$i++;
|
||||
}
|
||||
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$id,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title != '' ? $title : null,
|
||||
'main_image' => $main_image != '' ? $main_image : null,
|
||||
'entry' => $entry != '' ? $entry : null,
|
||||
'text' => $text != '' ? $text : null,
|
||||
'table_of_contents' => $table_of_contents != '' ? $table_of_contents : null,
|
||||
'meta_title' => $meta_title != '' ? $meta_title : null,
|
||||
'meta_description' => $meta_description != '' ? $meta_description : null,
|
||||
'meta_keywords' => $meta_keywords != '' ? $meta_keywords : null,
|
||||
'seo_link' => \S::seo( $seo_link ) != '' ? \S::seo( $seo_link ) : null,
|
||||
'noindex' => $noindex,
|
||||
'copy_from' => $copy_from != '' ? $copy_from : null,
|
||||
'block_direct_access' => $block_direct_access
|
||||
] );
|
||||
}
|
||||
|
||||
/* parametry bez wersji językowych */
|
||||
$results = $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 0 ] ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $row['id'],
|
||||
'value' => $params[ 'ap_' . $row['name'] ],
|
||||
'article_id' => (int)$id,
|
||||
'language_id' => null
|
||||
] );
|
||||
}
|
||||
|
||||
/* strony */
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
else if ( $pages )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$id,
|
||||
'page_id' => (int)$pages,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
/* pliki */
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_files/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => $id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
/* zdjęcia */
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_images/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '../' . $new_file_name ) )
|
||||
{
|
||||
$ext = strrpos( $new_file_name, '.' );
|
||||
$fileName_a = substr( $new_file_name, 0, $ext );
|
||||
$fileName_b = substr( $new_file_name, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
while ( file_exists( '../' . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
$new_file_name = $fileName_a . '_' . $count . $fileName_b;
|
||||
}
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
/* tagi */
|
||||
$tags = explode( ',', $tags );
|
||||
if ( is_array( $tags ) ) foreach ( $tags as $tag )
|
||||
{
|
||||
if ( trim( $tag ) != '' )
|
||||
{
|
||||
$tag_id = $mdb -> get( 'pp_tags', 'id', [ 'name' => $tag ] );
|
||||
if ( !$tag_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_tags', [ 'name' => $tag ] );
|
||||
$tag_id = $mdb -> id();
|
||||
}
|
||||
|
||||
$mdb -> insert( 'pp_articles_tags', [ 'article_id' => (int)$id, 'tag_id' => (int)$tag_id ] );
|
||||
}
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
|
||||
return $id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_articles', [
|
||||
'show_title' => $show_title == 'on' ? 1 : 0,
|
||||
'show_table_of_contents' => $show_table_of_contents == 'on' ? 1 : 0,
|
||||
'show_date_add' => $show_date_add == 'on' ? 1 : 0,
|
||||
'date_add' => $date_add,
|
||||
'show_date_modify' => $show_date_modify == 'on' ? 1 : 0,
|
||||
'date_modify' => $date_modify ? $date_modify : date( 'Y-m-d H:i:s' ),
|
||||
'modify_by' => $user['id'],
|
||||
'layout_id' => $layout_id ? (int)$layout_id : null,
|
||||
'status' => $status == 'on' ? 1 : 0,
|
||||
'repeat_entry' => $repeat_entry == 'on' ? 1 : 0,
|
||||
'social_icons' => $social_icons == 'on' ? 1 : 0,
|
||||
'date_start' => $event_date[0] ? $event_date[0] : null,
|
||||
'date_end' => $event_date[1] ? $event_date[1] : null,
|
||||
'priority' => $priority == 'on' ? 1 : 0,
|
||||
'password' => $password ? $password : null,
|
||||
'pixieset' => $pixieset,
|
||||
'id_author' => $id_author ? $id_author : null
|
||||
], [
|
||||
'id' => (int)$article_id
|
||||
] );
|
||||
|
||||
if ( $date_add )
|
||||
$mdb -> update( 'pp_articles', [ 'date_add' => $date_add ], [ 'id' => (int)$article_id ] );
|
||||
|
||||
$i = 0;
|
||||
|
||||
/* tłumaczenia */
|
||||
$mdb -> delete( 'pp_articles_langs', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) and count( $results ) > 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$article_id,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title[ $i ] != '' ? $title[ $i ] : null,
|
||||
'main_image' => $main_image[$i] != '' ? $main_image[$i] : null,
|
||||
'entry' => $entry[ $i ] != '' ? $entry[ $i ] : null,
|
||||
'text' => $text[ $i ] != '' ? $text[ $i ] : null,
|
||||
'table_of_contents' => $table_of_contents[$i] != '' ? $table_of_contents[$i] : null,
|
||||
'meta_title' => $meta_title[ $i ] != '' ? $meta_title[ $i ] : null,
|
||||
'meta_description' => $meta_description[ $i ] != '' ? $meta_description[ $i ] : null,
|
||||
'meta_keywords' => $meta_keywords[ $i ] != '' ? $meta_keywords[ $i ] : null,
|
||||
'seo_link' => \S::seo( $seo_link[ $i ] ) != '' ? \S::seo( $seo_link[ $i ] ) : null,
|
||||
'noindex' => $noindex[ $i ],
|
||||
'copy_from' => $copy_from[ $i ] != '' ? $copy_from[ $i ] : null,
|
||||
'block_direct_access' => $block_direct_access[ $i ]
|
||||
] );
|
||||
$i++;
|
||||
}
|
||||
else if ( is_array( $results ) and count( $results ) == 1 ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_langs', [
|
||||
'article_id' => (int)$article_id,
|
||||
'lang_id' => $row['id'],
|
||||
'title' => $title != '' ? $title : null,
|
||||
'main_image' => $main_image != '' ? $main_image : null,
|
||||
'entry' => $entry != '' ? $entry : null,
|
||||
'text' => $text != '' ? $text : null,
|
||||
'table_of_contents' => $table_of_contents != '' ? $table_of_contents : null,
|
||||
'meta_title' => $meta_title != '' ? $meta_title : null,
|
||||
'meta_description' => $meta_description != '' ? $meta_description : null,
|
||||
'meta_keywords' => $meta_keywords != '' ? $meta_keywords : null,
|
||||
'seo_link' => \S::seo( $seo_link ) != '' ? \S::seo( $seo_link ) : null,
|
||||
'noindex' => $noindex,
|
||||
'copy_from' => $copy_from != '' ? $copy_from : null,
|
||||
'block_direct_access' => $block_direct_access
|
||||
] );
|
||||
}
|
||||
|
||||
/* dodatkowe parametry */
|
||||
$mdb -> delete( 'pp_articles_additional_values', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
/* parametry bez wersji językowych */
|
||||
$results = $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 0 ] ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $row['id'],
|
||||
'value' => $params[ 'ap_' . $row['name'] ],
|
||||
'article_id' => (int)$article_id,
|
||||
'language_id' => null
|
||||
] );
|
||||
}
|
||||
|
||||
/* parametry z wersjami językowymi */
|
||||
$results = $mdb -> select( 'pp_articles_additional_params', '*', [ 'AND' => [ 'status' => 1, 'language' => 1 ] ] );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$results2 = $mdb -> select( 'pp_langs', [ 'id' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
|
||||
{
|
||||
$mdb -> insert( 'pp_articles_additional_values', [
|
||||
'param_id' => $row['id'],
|
||||
'value' => $params[ 'ap_' . $row['name'] . '_' . $row2['id'] ],
|
||||
'article_id' => (int)$article_id,
|
||||
'language_id' => $row2['id']
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
/* strony */
|
||||
$not_in = [ 0 ];
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
$not_in[] = $page;
|
||||
else if ( $pages )
|
||||
$not_in[] = $pages;
|
||||
|
||||
$mdb -> delete( 'pp_articles_pages', [ 'AND' => [ 'article_id' => (int)$article_id, 'page_id[!]' => $not_in ] ] );
|
||||
|
||||
$pages_tmp = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
if ( !is_array( $pages ) )
|
||||
$pages = [ $pages ];
|
||||
|
||||
$pages = array_diff( $pages, $pages_tmp );
|
||||
|
||||
if ( is_array( $pages ) ) foreach ( $pages as $page )
|
||||
{
|
||||
$order = self::max_order() + 1;
|
||||
|
||||
$mdb -> insert( 'pp_articles_pages', [
|
||||
'article_id' => (int)$article_id,
|
||||
'page_id' => (int)$page,
|
||||
'o' => (int)$order
|
||||
] );
|
||||
}
|
||||
|
||||
/* pliki */
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_files/article_' . $article_id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_files/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_files', [ 'src' => $new_file_name, 'article_id' => (int)$article_id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$created = false;
|
||||
|
||||
/* zdjęcia */
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => null ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$dir = '/upload/article_images/article_' . $article_id;
|
||||
|
||||
$new_file_name = str_replace( '/upload/article_images/tmp', $dir, $row['src'] );
|
||||
|
||||
if ( file_exists( '../' . $new_file_name ) )
|
||||
{
|
||||
$ext = strrpos( $new_file_name, '.' );
|
||||
$fileName_a = substr( $new_file_name, 0, $ext );
|
||||
$fileName_b = substr( $new_file_name, $ext );
|
||||
|
||||
$count = 1;
|
||||
|
||||
while ( file_exists( '../' . $fileName_a . '_' . $count . $fileName_b ) )
|
||||
$count++;
|
||||
|
||||
$new_file_name = $fileName_a . '_' . $count . $fileName_b;
|
||||
}
|
||||
|
||||
if ( file_exists( '..' . $row['src'] ) )
|
||||
{
|
||||
if ( !is_dir( '../' . $dir ) and $created !== true )
|
||||
{
|
||||
if ( mkdir( '../' . $dir, 0755, true ) )
|
||||
$created = true;
|
||||
}
|
||||
rename( '..' . $row['src'], '..' . $new_file_name );
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_articles_images', [ 'src' => $new_file_name, 'article_id' => (int)$article_id ], [ 'id' => $row['id'] ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_images', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_images', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
|
||||
$results = $mdb -> select( 'pp_articles_files', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
if ( file_exists( '../' . $row['src'] ) )
|
||||
unlink( '../' . $row['src'] );
|
||||
}
|
||||
|
||||
$mdb -> delete( 'pp_articles_files', [ 'AND' => [ 'article_id' => (int)$article_id, 'to_delete' => 1 ] ] );
|
||||
|
||||
/* tagi */
|
||||
$mdb -> delete( 'pp_articles_tags', [ 'article_id' => (int)$article_id ] );
|
||||
|
||||
$tags = explode( ',', $tags );
|
||||
if ( is_array( $tags ) ) foreach ( $tags as $tag )
|
||||
{
|
||||
if ( trim( $tag ) != '' )
|
||||
{
|
||||
$tag_id = $mdb -> get( 'pp_tags', 'id', [ 'name' => $tag ] );
|
||||
if ( !$tag_id )
|
||||
{
|
||||
$mdb -> insert( 'pp_tags', [ 'name' => $tag ] );
|
||||
$tag_id = $mdb -> id();
|
||||
}
|
||||
|
||||
$mdb -> insert( 'pp_articles_tags', [ 'article_id' => (int)$article_id, 'tag_id' => (int)$tag_id ] );
|
||||
}
|
||||
}
|
||||
|
||||
\S::htacces();
|
||||
\S::delete_cache();
|
||||
return $article_id;
|
||||
}
|
||||
global $user;
|
||||
return self::repo()->articleSave(
|
||||
$article_id, $title, $main_image, $entry, $text, $table_of_contents, $status, $show_title, $show_table_of_contents, $show_date_add, $date_add, $show_date_modify, $date_modify, $seo_link, $meta_title, $meta_description,
|
||||
$meta_keywords, $layout_id, $pages, $noindex, $repeat_entry, $copy_from, $social_icons, $event_date, $tags, $block_direct_access, $priority,
|
||||
$password, $pixieset, $id_author, $params, (int)$user['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 ] );
|
||||
self::repo()->deleteNonassignedFiles();
|
||||
}
|
||||
|
||||
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 ] );
|
||||
self::repo()->deleteNonassignedImages();
|
||||
}
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -3,139 +3,36 @@ namespace admin\factory;
|
||||
|
||||
class Layouts
|
||||
{
|
||||
public static function layout_delete( $layout_id )
|
||||
private static function repo(): \Domain\Layouts\LayoutsRepository
|
||||
{
|
||||
global $mdb;
|
||||
if ( $mdb -> count( 'pp_layouts' ) > 1 )
|
||||
return $mdb -> delete( 'pp_layouts', [ 'id' => (int)$layout_id ] );
|
||||
return false;
|
||||
return new \Domain\Layouts\LayoutsRepository( $mdb );
|
||||
}
|
||||
|
||||
public static function layout_delete( $layout_id )
|
||||
{
|
||||
return self::repo()->layoutDelete( $layout_id );
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return self::repo()->layoutDetails( $layout_id );
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
{
|
||||
return self::repo()->layoutSave( $layout_id, $name, $status, $pages, $html, $css, $js, $m_html, $m_css, $m_js );
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
return self::repo()->menusList();
|
||||
}
|
||||
|
||||
public static function layouts_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_layouts', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
}
|
||||
return self::repo()->layoutsList();
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -1,120 +1,53 @@
|
||||
<?
|
||||
|
||||
<?php
|
||||
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'
|
||||
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'
|
||||
];
|
||||
|
||||
private static function repo(): \Domain\Pages\PagesRepository
|
||||
{
|
||||
global $mdb;
|
||||
return new \Domain\Pages\PagesRepository( $mdb );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->saveArticlesOrder( $page_id, $articles );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->pageArticles( $page_id );
|
||||
}
|
||||
|
||||
public static function menus_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
return self::repo()->menusList();
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->savePagesOrder( $menu_id, $pages );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->pageDelete( $page_id );
|
||||
}
|
||||
|
||||
public static function max_order()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> max( 'pp_pages', 'o' );
|
||||
return self::repo()->maxOrder();
|
||||
}
|
||||
|
||||
public static function page_save(
|
||||
@@ -122,388 +55,70 @@ class Pages
|
||||
$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;
|
||||
return self::repo()->pageSave(
|
||||
$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
|
||||
);
|
||||
}
|
||||
|
||||
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 );
|
||||
self::repo()->updateSubpagesMenuId( (int) $parent_id, (int) $menu_id );
|
||||
}
|
||||
|
||||
public static function generate_seo_link( $title, $page_id, $article_id,
|
||||
$lang, $pid )
|
||||
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;
|
||||
return self::repo()->generateSeoLink( $title, $page_id, $article_id, $lang, $pid );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->googleUrlPreview( $page_id, $title, $lang, $pid, $id, $seo_link, $language_link );
|
||||
}
|
||||
|
||||
public static function menu_delete( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_pages', [ 'menu_id' => (int) $menu_id ] ) )
|
||||
return false;
|
||||
|
||||
return $mdb -> delete( 'pp_menus', [ 'id' => (int) $menu_id ] );
|
||||
return self::repo()->menuDelete( $menu_id );
|
||||
}
|
||||
|
||||
public static function menu_details( $menu_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_menus', '*', [ 'id' => (int) $menu_id ] );
|
||||
return self::repo()->menuDetails( $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;
|
||||
return self::repo()->menuSave( $menu_id, $name, $status );
|
||||
}
|
||||
|
||||
public static function menu_lists()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_menus', '*', [ 'ORDER' => [ 'id' => 'ASC' ] ] );
|
||||
return self::repo()->menuLists();
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->pageDetails( $page_id );
|
||||
}
|
||||
|
||||
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'];
|
||||
return self::repo()->pageUrl( $page_id );
|
||||
}
|
||||
|
||||
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];
|
||||
return self::repo()->pageTitle( $page_id );
|
||||
}
|
||||
|
||||
public static function page_languages( $page_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_pages_langs', '*',
|
||||
[ 'AND' => [ 'page_id' => (int) $page_id, 'title[!]' => null ] ] );
|
||||
return self::repo()->pageLanguages( $page_id );
|
||||
}
|
||||
|
||||
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;
|
||||
return self::repo()->menuPages( $menu_id, $parent_id );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
@@ -57,17 +57,19 @@ autoload/Shared/
|
||||
Stare klasy (`class.S.php`, `class.Cache.php`, itd.) są teraz cienkimi
|
||||
wrapperami — zachowana pełna kompatybilność wsteczna.
|
||||
|
||||
### Faza 2 (w toku) — Domain Repositories (`autoload/Domain/`)
|
||||
### Faza 2 (w toku) - Domain Repositories (`autoload/Domain/`)
|
||||
|
||||
```
|
||||
autoload/Domain/
|
||||
├── Languages/LanguagesRepository.php ← \Domain\Languages\LanguagesRepository ✓
|
||||
├── Settings/SettingsRepository.php ← \Domain\Settings\SettingsRepository ✓
|
||||
└── User/UserRepository.php ← \Domain\User\UserRepository ✓
|
||||
|- Languages/LanguagesRepository.php <- \Domain\Languages\LanguagesRepository OK
|
||||
|- Settings/SettingsRepository.php <- \Domain\Settings\SettingsRepository OK
|
||||
|- User/UserRepository.php <- \Domain\User\UserRepository OK
|
||||
|- Pages/PagesRepository.php <- \Domain\Pages\PagesRepository OK
|
||||
|- Layouts/LayoutsRepository.php <- \Domain\Layouts\LayoutsRepository OK
|
||||
`- Articles/ArticlesRepository.php <- \Domain\Articles\ArticlesRepository OK (w toku)
|
||||
```
|
||||
|
||||
Następne: `Domain\Pages`, `Domain\Layouts`, `Domain\Articles`, ...
|
||||
|
||||
Nastepne: `Domain\Banners`, `Domain\Authors`, `Domain\Newsletter`, ...
|
||||
---
|
||||
|
||||
## Katalogi
|
||||
@@ -118,3 +120,4 @@ Główne tabele: `pp_users`, `pp_articles`, `pp_articles_langs`, `pp_pages`,
|
||||
- Tabela: `pp_languages`
|
||||
- Składnia w treści: `[LANG:klucz]`
|
||||
- Cache tłumaczeń: `$_SESSION['lang-{lang_id}']`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user