New class User

This commit is contained in:
dignajar 2015-12-31 15:47:34 -03:00
parent b4f71abd23
commit 1ad7b352cb
8 changed files with 153 additions and 15 deletions

View File

@ -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');

View File

@ -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;

View File

@ -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;

View File

@ -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)
{

View File

@ -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');

View File

@ -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');

84
kernel/user.class.php Normal file
View File

@ -0,0 +1,84 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class User
{
public $db;
public function setField($field, $value)
{
$this->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');
}
}

View File

@ -22,11 +22,11 @@
<?php
echo $Language->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');
}
?>
</span>