aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/user/main.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/include/user/main.php')
-rw-r--r--core/include/user/main.php116
1 files changed, 54 insertions, 62 deletions
diff --git a/core/include/user/main.php b/core/include/user/main.php
index 34ec883..c0cb20d 100644
--- a/core/include/user/main.php
+++ b/core/include/user/main.php
@@ -1,81 +1,73 @@
<?php
#===============================================================================
-# Get instances
+# Get repositories
#===============================================================================
-$Database = Application::getDatabase();
-$Language = Application::getLanguage();
+$PageRepository = Application::getRepository('Page');
+$PostRepository = Application::getRepository('Post');
+$UserRepository = Application::getRepository('User');
#===============================================================================
-# TRY: User\Exception
+# Try to find user by slug URL or unique ID
#===============================================================================
-try {
- if(Application::get('USER.SLUG_URLS')) {
- $User = User\Factory::buildBySlug($param);
+if(Application::get('USER.SLUG_URLS')) {
+ if(!$User = $UserRepository->findBy('slug', $param)) {
+ if($User = $UserRepository->find($param)) {
+ HTTP::redirect(Application::getEntityURL($User));
+ }
}
+}
- else {
- $User = User\Factory::build($param);
+else {
+ if(!$User = $UserRepository->find($param)) {
+ if($User = $UserRepository->findBy('slug', $param)) {
+ HTTP::redirect(Application::getEntityURL($User));
+ }
}
+}
- $user_data = generateItemTemplateData($User);
-
- #===============================================================================
- # Add user data for previous and next user
- #===============================================================================
- try {
- $PrevUser = User\Factory::build($User->getPrevID());
- $user_data['PREV'] = generateItemTemplateData($PrevUser);
- } catch(User\Exception $Exception){}
-
- try {
- $NextUser = User\Factory::build($User->getNextID());
- $user_data['NEXT'] = generateItemTemplateData($NextUser);
- } catch(User\Exception $Exception){}
-
- $PostCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s WHERE user = %d', Post\Attribute::TABLE, $User->getID()));
- $PageCountStatement = $Database->query(sprintf('SELECT COUNT(*) FROM %s WHERE user = %d', Page\Attribute::TABLE, $User->getID()));
-
- #===============================================================================
- # Build document
- #===============================================================================
- $UserTemplate = Template\Factory::build('user/main');
- $UserTemplate->set('USER', $user_data);
- $UserTemplate->set('COUNT', [
- 'POST' => $PostCountStatement->fetchColumn(),
- 'PAGE' => $PageCountStatement->fetchColumn()
- ]);
+#===============================================================================
+# Throw 404 error if user could not be found
+#===============================================================================
+if(!isset($User)) {
+ Application::error404();
+}
- $MainTemplate = Template\Factory::build('main');
- $MainTemplate->set('HTML', $UserTemplate);
- $MainTemplate->set('HEAD', [
- 'NAME' => $user_data['ATTR']['FULLNAME'],
- 'DESC' => description($user_data['BODY']['HTML'](), Application::get('USER.DESCRIPTION_SIZE')),
- 'PERM' => $user_data['URL'],
- 'OG_IMAGES' => $user_data['FILE']['LIST']
- ]);
+#===============================================================================
+# Generate template data
+#===============================================================================
+$user_data = generateItemTemplateData($User);
- # Get access to the current item data from main template
- $MainTemplate->set('TYPE', 'USER');
- $MainTemplate->set('USER', $user_data);
+#===============================================================================
+# Add template data for previous and next user
+#===============================================================================
+if($PrevUser = $UserRepository->findPrev($User)) {
+ $user_data['PREV'] = generateItemTemplateData($PrevUser);
+}
- echo $MainTemplate;
+if($NextUser = $UserRepository->findNext($User)) {
+ $user_data['NEXT'] = generateItemTemplateData($NextUser);
}
#===============================================================================
-# CATCH: User\Exception
+# Build document
#===============================================================================
-catch(User\Exception $Exception) {
- try {
- if(Application::get('USER.SLUG_URLS') === FALSE) {
- $User = User\Factory::buildBySlug($param);
- } else {
- $User = User\Factory::build($param);
- }
+$UserTemplate = Template\Factory::build('user/main');
+$UserTemplate->set('USER', $user_data);
+$UserTemplate->set('COUNT', [
+ 'POST' => $PostRepository->getCountByUser($User),
+ 'PAGE' => $PageRepository->getCountByUser($User)
+]);
- HTTP::redirect(Application::getEntityURL($User));
- }
+$MainTemplate = Template\Factory::build('main');
+$MainTemplate->set('TYPE', 'USER');
+$MainTemplate->set('USER', $user_data);
+$MainTemplate->set('HTML', $UserTemplate);
+$MainTemplate->set('HEAD', [
+ 'NAME' => $user_data['ATTR']['FULLNAME'],
+ 'DESC' => description($user_data['BODY']['HTML'](),
+ Application::get('USER.DESCRIPTION_SIZE')),
+ 'PERM' => $user_data['URL'],
+ 'OG_IMAGES' => $user_data['FILE']['LIST']
+]);
- catch(User\Exception $Exception) {
- Application::error404();
- }
-}
+echo $MainTemplate;