aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/page/main.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/include/page/main.php')
-rw-r--r--core/include/page/main.php113
1 files changed, 53 insertions, 60 deletions
diff --git a/core/include/page/main.php b/core/include/page/main.php
index 01ef40d..39e1d3c 100644
--- a/core/include/page/main.php
+++ b/core/include/page/main.php
@@ -1,79 +1,72 @@
<?php
#===============================================================================
-# Get instances
+# Get repositories
#===============================================================================
-$Database = Application::getDatabase();
-$Language = Application::getLanguage();
+$PageRepository = Application::getRepository('Page');
+$UserRepository = Application::getRepository('User');
#===============================================================================
-# TRY: Page\Exception
+# Try to find page by slug URL or unique ID
#===============================================================================
-try {
- if(Application::get('PAGE.SLUG_URLS')) {
- $Page = Page\Factory::buildBySlug($param);
+if(Application::get('PAGE.SLUG_URLS')) {
+ if(!$Page = $PageRepository->findBy('slug', $param)) {
+ if($Page = $PageRepository->find($param)) {
+ HTTP::redirect(Application::getEntityURL($Page));
+ }
}
+}
- else {
- $Page = Page\Factory::build($param);
+else {
+ if(!$Page = $PageRepository->find($param)) {
+ if($Page = $PageRepository->findBy('slug', $param)) {
+ HTTP::redirect(Application::getEntityURL($Page));
+ }
}
+}
- $User = User\Factory::build($Page->get('user'));
-
- $page_data = generateItemTemplateData($Page);
- $user_data = generateItemTemplateData($User);
-
- #===============================================================================
- # Add page data for previous and next page
- #===============================================================================
- try {
- $PrevPage = Page\Factory::build($Page->getPrevID());
- $page_data['PREV'] = generateItemTemplateData($PrevPage);
- } catch(Page\Exception $Exception){}
-
- try {
- $NextPage = Page\Factory::build($Page->getNextID());
- $page_data['NEXT'] = generateItemTemplateData($NextPage);
- } catch(Page\Exception $Exception){}
-
- #===============================================================================
- # Build document
- #===============================================================================
- $PageTemplate = Template\Factory::build('page/main');
- $PageTemplate->set('PAGE', $page_data);
- $PageTemplate->set('USER', $user_data);
+#===============================================================================
+# Throw 404 error if page could not be found
+#===============================================================================
+if(!isset($Page)) {
+ Application::error404();
+}
- $MainTemplate = Template\Factory::build('main');
- $MainTemplate->set('HTML', $PageTemplate);
- $MainTemplate->set('HEAD', [
- 'NAME' => $page_data['ATTR']['NAME'],
- 'DESC' => description($page_data['BODY']['HTML'](), Application::get('PAGE.DESCRIPTION_SIZE')),
- 'PERM' => $page_data['URL'],
- 'OG_IMAGES' => $page_data['FILE']['LIST']
- ]);
+#===============================================================================
+# Generate template data
+#===============================================================================
+$User = $UserRepository->find($Page->get('user'));
+$page_data = generateItemTemplateData($Page);
+$user_data = generateItemTemplateData($User);
- # Get access to the current item data from main template
- $MainTemplate->set('TYPE', 'PAGE');
- $MainTemplate->set('PAGE', $page_data);
- $MainTemplate->set('USER', $user_data);
+#===============================================================================
+# Add template data for previous and next page
+#===============================================================================
+if($PrevPage = $PageRepository->findPrev($Page)) {
+ $page_data['PREV'] = generateItemTemplateData($PrevPage);
+}
- echo $MainTemplate;
+if($NextPage = $PageRepository->findNext($Page)) {
+ $page_data['NEXT'] = generateItemTemplateData($NextPage);
}
#===============================================================================
-# CATCH: Page\Exception
+# Build document
#===============================================================================
-catch(Page\Exception $Exception) {
- try {
- if(Application::get('PAGE.SLUG_URLS') === FALSE) {
- $Page = Page\Factory::buildBySlug($param);
- } else {
- $Page = Page\Factory::build($param);
- }
+$PageTemplate = Template\Factory::build('page/main');
+$PageTemplate->set('PAGE', $page_data);
+$PageTemplate->set('USER', $user_data);
- HTTP::redirect(Application::getEntityURL($Page));
- }
+$MainTemplate = Template\Factory::build('main');
+$MainTemplate->set('TYPE', 'PAGE');
+$MainTemplate->set('PAGE', $page_data);
+$MainTemplate->set('USER', $user_data);
+$MainTemplate->set('HTML', $PageTemplate);
+$MainTemplate->set('HEAD', [
+ 'NAME' => $page_data['ATTR']['NAME'],
+ 'DESC' => description($page_data['BODY']['HTML'](),
+ Application::get('PAGE.DESCRIPTION_SIZE')),
+ 'PERM' => $page_data['URL'],
+ 'OG_IMAGES' => $page_data['FILE']['LIST']
+]);
- catch(Page\Exception $Exception) {
- Application::error404();
- }
-}
+echo $MainTemplate;