From 82008f93e715e096218ef3d680ac0b0302c77ac7 Mon Sep 17 00:00:00 2001 From: dignajar Date: Thu, 31 Dec 2015 20:31:51 -0300 Subject: [PATCH] New class User --- kernel/admin/controllers/edit-user.php | 6 +-- kernel/admin/themes/default/css/default.css | 2 + kernel/admin/views/edit-user.php | 52 +++++++++++++++------ kernel/boot/rules/70.pages.php | 16 ++----- kernel/boot/rules/70.posts.php | 16 ++----- kernel/dbusers.class.php | 18 +++++++ 6 files changed, 66 insertions(+), 44 deletions(-) diff --git a/kernel/admin/controllers/edit-user.php b/kernel/admin/controllers/edit-user.php index 6b85671d..8dfaf909 100644 --- a/kernel/admin/controllers/edit-user.php +++ b/kernel/admin/controllers/edit-user.php @@ -85,11 +85,9 @@ if($Login->role()!=='admin') { $layout['parameters'] = $Login->username(); } -$_user = $dbUsers->getDb($layout['parameters']); +$_User = $dbUsers->getUser($layout['parameters']); // If the user doesn't exist, redirect to the users list. -if($_user===false) { +if($_User===false) { Redirect::page('admin', 'users'); } - -$_user['username'] = $layout['parameters']; diff --git a/kernel/admin/themes/default/css/default.css b/kernel/admin/themes/default/css/default.css index 8ce47fe4..8cd02bac 100644 --- a/kernel/admin/themes/default/css/default.css +++ b/kernel/admin/themes/default/css/default.css @@ -272,6 +272,8 @@ button.delete-button:hover { } +/* ----------- BLUDIT PROFILE PICTURE ----------- */ + /* ----------- LOGIN FORM ----------- */ div.login-box > h1 { diff --git a/kernel/admin/views/edit-user.php b/kernel/admin/views/edit-user.php index 5ef805bc..de550f9f 100644 --- a/kernel/admin/views/edit-user.php +++ b/kernel/admin/views/edit-user.php @@ -16,7 +16,7 @@ HTML::formOpen(array('id'=>'edit-user-profile-form','class'=>'uk-form-horizontal // Security token HTML::formInputHidden(array( 'name'=>'username', - 'value'=>$_user['username'] + 'value'=>$_User->username() )); HTML::legend(array('value'=>$L->g('Profile'), 'class'=>'first-child')); @@ -24,7 +24,7 @@ HTML::formOpen(array('id'=>'edit-user-profile-form','class'=>'uk-form-horizontal HTML::formInputText(array( 'name'=>'usernameDisable', 'label'=>$L->g('Username'), - 'value'=>$_user['username'], + 'value'=>$_User->username(), 'class'=>'uk-width-1-2 uk-form-medium', 'disabled'=>true, 'tip'=>'' @@ -33,7 +33,7 @@ HTML::formOpen(array('id'=>'edit-user-profile-form','class'=>'uk-form-horizontal HTML::formInputText(array( 'name'=>'firstName', 'label'=>$L->g('First name'), - 'value'=>$_user['firstName'], + 'value'=>$_User->firstName(), 'class'=>'uk-width-1-2 uk-form-medium', 'tip'=>'' )); @@ -41,7 +41,7 @@ HTML::formOpen(array('id'=>'edit-user-profile-form','class'=>'uk-form-horizontal HTML::formInputText(array( 'name'=>'lastName', 'label'=>$L->g('Last name'), - 'value'=>$_user['lastName'], + 'value'=>$_User->lastName(), 'class'=>'uk-width-1-2 uk-form-medium', 'tip'=>'' )); @@ -49,7 +49,7 @@ HTML::formOpen(array('id'=>'edit-user-profile-form','class'=>'uk-form-horizontal echo '
'; @@ -59,7 +59,7 @@ if($Login->role()==='admin') { 'name'=>'role', 'label'=>$L->g('Role'), 'options'=>array('editor'=>$L->g('Editor'), 'admin'=>$L->g('Administrator')), - 'selected'=>$_user['role'], + 'selected'=>$_User->role(), 'tip'=>'' )); @@ -67,17 +67,41 @@ if($Login->role()==='admin') { HTML::formInputText(array( 'name'=>'email', 'label'=>$L->g('Email'), - 'value'=>$_user['email'], + 'value'=>$_User->email(), 'class'=>'uk-width-1-2 uk-form-medium', 'tip'=>$L->g('email-will-not-be-publicly-displayed') )); - HTML::legend(array('value'=>$L->g('Social network'))); + HTML::legend(array('value'=>'Social networks')); HTML::formInputText(array( 'name'=>'twitterUsername', - 'label'=>$L->g('Twitter username'), - 'value'=>$_user['twitterUsername'], + 'label'=>'Twitter username', + 'value'=>$_User->twitterUsername(), + 'class'=>'uk-width-1-2 uk-form-medium', + 'tip'=>'' + )); + + HTML::formInputText(array( + 'name'=>'facebookUsername', + 'label'=>'Facebook username', + 'value'=>$_User->facebookUsername(), + 'class'=>'uk-width-1-2 uk-form-medium', + 'tip'=>'' + )); + + HTML::formInputText(array( + 'name'=>'googleUsername', + 'label'=>'Google username', + 'value'=>$_User->googleUsername(), + 'class'=>'uk-width-1-2 uk-form-medium', + 'tip'=>'' + )); + + HTML::formInputText(array( + 'name'=>'instagramUsername', + 'label'=>'Instagram username', + 'value'=>$_User->instagramUsername(), 'class'=>'uk-width-1-2 uk-form-medium', 'tip'=>'' )); @@ -89,7 +113,7 @@ if($Login->role()==='admin') { '; -if( ($Login->role()==='admin') && ($_user['username']!='admin') ) { +if( ($Login->role()==='admin') && ($_User->username()!='admin') ) { HTML::legend(array('value'=>$L->g('Delete'))); @@ -108,15 +132,15 @@ echo ''; echo '
'; echo '
'; -if(file_exists(PATH_UPLOADS_PROFILES.$_user['username'].'.jpg')) { - echo ''; +if(file_exists(PATH_UPLOADS_PROFILES.$_User->username().'.jpg')) { + echo ''; } else { echo '
'.$L->g('Profile picture').'
'; } echo '
'; -HTML::profileUploader($_user['username']); +HTML::profileUploader($_User->username()); echo '
'; echo ''; diff --git a/kernel/boot/rules/70.pages.php b/kernel/boot/rules/70.pages.php index 4ee67b24..f9c2ae55 100644 --- a/kernel/boot/rules/70.pages.php +++ b/kernel/boot/rules/70.pages.php @@ -66,19 +66,9 @@ function build_page($key) $pageDateFormated = $Page->dateRaw( $Site->dateFormat() ); $Page->setField('date', $pageDateFormated, true); - // Parse username for the page. - if( $dbUsers->userExists( $Page->username() ) ) - { - $User = new User(); - $userDatabase = $dbUsers->getDb( $Page->username() ); - - foreach($userDatabase as $key=>$value) { - $User->setField($key, $value); - } - - // Save the User object inside the Page object - $Page->setField('user', $User); - } + // User object + $username = $Page->username(); + $Page->setField('user', $dbUsers->getUser($username)); return $Page; } diff --git a/kernel/boot/rules/70.posts.php b/kernel/boot/rules/70.posts.php index 4775937e..7ab169d6 100644 --- a/kernel/boot/rules/70.posts.php +++ b/kernel/boot/rules/70.posts.php @@ -75,19 +75,9 @@ function buildPost($key) $postDateFormated = $Post->dateRaw( $Site->dateFormat() ); $Post->setField('date', $postDateFormated, true); - // Parse username for the page. - if( $dbUsers->userExists( $Post->username() ) ) - { - $User = new User(); - $userDatabase = $dbUsers->getDb( $Post->username() ); - - foreach($userDatabase as $key=>$value) { - $User->setField($key, $value); - } - - // Save the User object inside the Page object - $Post->setField('user', $User); - } + // User object + $username = $Post->username(); + $Post->setField('user', $dbUsers->getUser($username)); return $Post; } diff --git a/kernel/dbusers.class.php b/kernel/dbusers.class.php index d9eaf1d0..8a1b4fb3 100644 --- a/kernel/dbusers.class.php +++ b/kernel/dbusers.class.php @@ -24,6 +24,24 @@ class dbUsers extends dbJSON parent::__construct(PATH_DATABASES.'users.php'); } + public function getUser($username) + { + $User = new User(); + + if($this->userExists($username)) + { + $User->setField('username', $username); + + foreach($this->db[$username] as $key=>$value) { + $User->setField($key, $value); + } + + return $User; + } + + return false; + } + public function getAll() { return $this->db;