From 1ad7b352cbefdb035ad29f0c056db8927d08964b Mon Sep 17 00:00:00 2001 From: dignajar Date: Thu, 31 Dec 2015 15:47:34 -0300 Subject: [PATCH] New class User --- kernel/boot/init.php | 2 + kernel/boot/rules/70.pages.php | 11 +++-- kernel/boot/rules/70.posts.php | 13 ++++-- kernel/dbtags.class.php | 10 ++++ kernel/page.class.php | 16 +++++++ kernel/post.class.php | 26 +++++++++-- kernel/user.class.php | 84 ++++++++++++++++++++++++++++++++++ themes/pure/php/home.php | 6 +-- 8 files changed, 153 insertions(+), 15 deletions(-) create mode 100644 kernel/user.class.php diff --git a/kernel/boot/init.php b/kernel/boot/init.php index d7e8a4a5..b9faa5a1 100644 --- a/kernel/boot/init.php +++ b/kernel/boot/init.php @@ -123,12 +123,14 @@ include(PATH_KERNEL.'dblanguage.class.php'); include(PATH_KERNEL.'dbsite.class.php'); include(PATH_KERNEL.'post.class.php'); include(PATH_KERNEL.'page.class.php'); +include(PATH_KERNEL.'user.class.php'); include(PATH_KERNEL.'url.class.php'); include(PATH_KERNEL.'login.class.php'); include(PATH_KERNEL.'parsedown.class.php'); include(PATH_KERNEL.'parsedownextra.class.php'); include(PATH_KERNEL.'security.class.php'); + // Include Helpers Classes include(PATH_HELPERS.'text.class.php'); include(PATH_HELPERS.'log.class.php'); diff --git a/kernel/boot/rules/70.pages.php b/kernel/boot/rules/70.pages.php index ad804872..4ee67b24 100644 --- a/kernel/boot/rules/70.pages.php +++ b/kernel/boot/rules/70.pages.php @@ -69,10 +69,15 @@ function build_page($key) // Parse username for the page. if( $dbUsers->userExists( $Page->username() ) ) { - $user = $dbUsers->getDb( $Page->username() ); + $User = new User(); + $userDatabase = $dbUsers->getDb( $Page->username() ); - $Page->setField('authorFirstName', $user['firstName'], false); - $Page->setField('authorLastName', $user['lastName'], false); + foreach($userDatabase as $key=>$value) { + $User->setField($key, $value); + } + + // Save the User object inside the Page object + $Page->setField('user', $User); } return $Page; diff --git a/kernel/boot/rules/70.posts.php b/kernel/boot/rules/70.posts.php index 92320204..4775937e 100644 --- a/kernel/boot/rules/70.posts.php +++ b/kernel/boot/rules/70.posts.php @@ -75,13 +75,18 @@ function buildPost($key) $postDateFormated = $Post->dateRaw( $Site->dateFormat() ); $Post->setField('date', $postDateFormated, true); - // Parse username for the post. + // Parse username for the page. if( $dbUsers->userExists( $Post->username() ) ) { - $user = $dbUsers->getDb( $Post->username() ); + $User = new User(); + $userDatabase = $dbUsers->getDb( $Post->username() ); - $Post->setField('authorFirstName', $user['firstName'], false); - $Post->setField('authorLastName', $user['lastName'], false); + foreach($userDatabase as $key=>$value) { + $User->setField($key, $value); + } + + // Save the User object inside the Page object + $Post->setField('user', $User); } return $Post; diff --git a/kernel/dbtags.class.php b/kernel/dbtags.class.php index 9b196aeb..157734e6 100644 --- a/kernel/dbtags.class.php +++ b/kernel/dbtags.class.php @@ -18,6 +18,16 @@ class dbTags extends dbJSON parent::__construct(PATH_DATABASES.'tags.php'); } + // Returns an array with all tags names + public function getAll() + { + $tmp = array(); + foreach($this->db['postsIndex'] as $tagSlug=>$tagInfo) { + $tmp[$tagSlug] = $tagInfo['name']; + } + return $tmp; + } + // Returns an array with a list of posts keys, filtered by a page number and a tag key. public function getList($pageNumber, $postPerPage, $tagKey) { diff --git a/kernel/page.class.php b/kernel/page.class.php index 549c905b..e4456981 100644 --- a/kernel/page.class.php +++ b/kernel/page.class.php @@ -198,16 +198,32 @@ class Page extends fileContent return $tmp; } + // Returns the user object if $field is false, otherwise returns the field's value. + public function user($field=false) + { + // Get the user object. + $User = $this->getField('user'); + + if($field) { + return $User->getField($field); + } + + return $User; + } + + // DEPRECATED public function username() { return $this->getField('username'); } + // DEPRECATED public function authorFirstName() { return $this->getField('authorFirstName'); } + // DEPRECATED public function authorLastName() { return $this->getField('authorLastName'); diff --git a/kernel/post.class.php b/kernel/post.class.php index cfde1ff8..5550de7a 100644 --- a/kernel/post.class.php +++ b/kernel/post.class.php @@ -78,11 +78,6 @@ class Post extends fileContent return ($this->getField('status')=='draft'); } - public function username() - { - return $this->getField('username'); - } - public function coverImage($absolute=true) { $fileName = $this->getField('coverImage'); @@ -99,11 +94,32 @@ class Post extends fileContent return HTML_PATH_UPLOADS_PROFILES.$this->username().'.jpg'; } + // Returns the user object if $field is false, otherwise returns the field's value. + public function user($field=false) + { + // Get the user object. + $User = $this->getField('user'); + + if($field) { + return $User->getField($field); + } + + return $User; + } + + // DEPRECATED + public function username() + { + return $this->getField('username'); + } + + // DEPRECATED public function authorFirstName() { return $this->getField('authorFirstName'); } + // DEPRECATED public function authorLastName() { return $this->getField('authorLastName'); diff --git a/kernel/user.class.php b/kernel/user.class.php new file mode 100644 index 00000000..0b80c92a --- /dev/null +++ b/kernel/user.class.php @@ -0,0 +1,84 @@ +db[$field] = $value; + + return true; + } + + public function getField($field) + { + if(isset($this->db[$field])) { + return $this->db[$field]; + } + + return false; + } + + // Returns username + public function username() + { + return $this->getField('username'); + } + + public function firstName() + { + return $this->getField('firstName'); + } + + public function lastName() + { + return $this->getField('lastName'); + } + + public function role() + { + return $this->getField('role'); + } + + public function password() + { + return $this->getField('password'); + } + + public function salt() + { + return $this->getField('salt'); + } + + public function email() + { + return $this->getField('email'); + } + + public function registered() + { + return $this->getField('registered'); + } + + public function twitterUsername() + { + return $this->getField('twitterUsername'); + } + + public function facebookUsername() + { + return $this->getField('facebookUsername'); + } + + public function googleUsername() + { + return $this->getField('googleUsername'); + } + + public function instagramUsername() + { + return $this->getField('instagramUsername'); + } + +} \ No newline at end of file diff --git a/themes/pure/php/home.php b/themes/pure/php/home.php index 5bfb4060..49bfbc6d 100644 --- a/themes/pure/php/home.php +++ b/themes/pure/php/home.php @@ -22,11 +22,11 @@ get('Posted By').' '; - if( Text::isNotEmpty($Post->authorFirstName()) || Text::isNotEmpty($Post->authorLastName()) ) { - echo $Post->authorFirstName().' '.$Post->authorLastName(); + if( Text::isNotEmpty($Post->user('firstName')) || Text::isNotEmpty($Post->user('lastName')) ) { + echo $Post->user('firstName').' '.$Post->user('lastName'); } else { - echo $Post->username(); + echo $Post->user('username'); } ?>