• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[pre-release] dev cms

Status
Not open for further replies.
Legendary Battlemage
Joined
Aug 16, 2008
Messages
600
Reaction score
259
Alright, I didn't do anything last night cause I went out. ANYWAY.

I've created the function to show people who are online, including a pagination to limit the number of people shown, per page.

PHP:
	public static function users ($ID = NULL)
	{
		GLOBAL $config, $db;
		$query = ('SELECT count(ID) FROM users WHERE online = "1"');
		if ($statement = $db->prepare($query))
		{
			$statement->execute();
			$statement->bind_result($id);
			$rows = array();
			while ($statement->fetch())
			{
				 $rows[] = array('id' => $id);
			}
			$statement->close();
			$rows = $id;
			$pages = ceil($rows / 10);
			for ($i = 1; $i <= $pages; $i++)
			{
				$result2 .= '<a href="'.$config['www']['url'].'?p=users&sub='.$i.'" target="_self">'.$i.'</a>';
			}
		}
		
		$query = ('SELECT username, look FROM users WHERE online = "1" ORDER BY username ASC LIMIT '.(($ID - 1) * 10).', 10');
		if ($statement = $db->prepare($query))
		{
			$statement->execute();
			$statement->bind_result($username, $look);
			while ($statement->fetch())
			{
				$class = ($x % 2 == 0) ? 'odd' : 'even';
				$result1 .= ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="'.$class.'">
						<div class="users-image"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
						<div class="users-p"><b>'.$username.'</b><br />Online</div>
					</a>');
				$x++;
			}
			$statement->close();
		}
		return ('<div class="container-title orange">'.$config['www']['name'].'s online</div>
				<div class="container-body">
					'.$result1.'
					<div class="container-body-form">Pages: '.$result2.'</div>
				</div>');
	}

I'm probably going to review the code for this, but in the mean time, it is what it is.

Quick review of the code and I've added the latest member function inside, I was planning to do this already. I just wanted to make sure the first part of the code was correct (and working)

PHP:
	public static function users ($ID = NULL)
	{
		GLOBAL $config, $db;
		if ($ID == NULL) // LATEST MEMBER
		{
			$query = ('SELECT username, look FROM users ORDER BY ID DESC LIMIT 1');
			if ($statement = $db->prepare($query))
			{
				$statement->execute();
				$statement->bind_result($username, $look);
				$statement->fetch();
				$statement->close();
			}
			
			return ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="odd">
						<div class="users-image" style="width: 80px;"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
						<div class="users-p" style="width: 178px;"><b>'.$username.'</b><br />Latest Member</div>
					</a>');
		}
		else // USERS ONLINE
		{
			$query = ('SELECT username, look FROM users WHERE online = "1" ORDER BY username ASC LIMIT '.(($ID - 1) * 10).', 10');
			if ($statement = $db->prepare($query))
			{
				$statement->execute();
				$statement->bind_result($username, $look);
				while ($statement->fetch())
				{
					$class = ($x % 2 == 0) ? 'odd' : 'even';
					$result1 .= ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="'.$class.'">
						<div class="users-image"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
						<div class="users-p"><b>'.$username.'</b><br />Online</div>
					</a>');
					$x++;
				}
				$statement->close();
			}
			
			$query = ('SELECT count(ID) FROM users WHERE online = "1"');
			$count = array();
			if ($statement = $db->prepare($query))
			{
				$statement->execute();
				$statement->bind_result($id);
				while ($statement->fetch())
				{
					$count[] = array('id' => $id);
				}
				$statement->close();
				$pages = ceil($count = $id / 10);
				for ($i = 1; $i <= $pages; $i++)
				{
					$result2 .= '<a href="'.$config['www']['url'].'?p=users&sub='.$i.'" target="_self">'.$i.'</a>';
				}
			}
			
			return ('<div class="container-title orange">'.$config['www']['name'].'s online</div>
				<div class="container-body">
					'.$result1.'
					<div class="container-body-form">Pages: '.$result2.'</div>
				</div>');
		}
	}
 
Joined
Jun 23, 2010
Messages
2,324
Reaction score
2,195
Do you mind to explain this peace of code, by code I mean the $count part?

PHP:
                $statement->bind_result($id);
                while ($statement->fetch())
                {
                    $count[] = array('id' => $id);
                }
                $statement->close();
                $pages = ceil($count = $id / 10);
 
Legendary Battlemage
Joined
Aug 16, 2008
Messages
600
Reaction score
259
Do you mind to explain this peace of code, by code I mean the $count part?

PHP:
                $statement->bind_result($id);
                while ($statement->fetch())
                {
                    $count[] = array('id' => $id);
                }
                $statement->close();
                $pages = ceil($count = $id / 10);

I created the array above the loop (while()) to first set up the appropriate condition because of variable scoping, then with the variable that has [] adds a new element to the array, just like the push(), but without the overhead of calling a function.

http://us1.php.net/array_push

PHP:
public static function users_search ()
{
        GLOBAL $db;
        $query = ('SELECT username, look FROM users WHERE username LIKE = ?'); // ADD PAGINATION WITH COUNT(ID) on USERS
        if ($statement = $db->prepare($query))
        {\
                $statement->bind_param('s', $user);
                $statement->execute();
                $statement->bind_result($username, $look);
                while ($statement->fetch())
                {
                        $result .= ('<a href="#" target="_self"><img src="'.$look.'" alt="'.$username.'" /></a>'); //assuming we have our markup
                }
                $statement->close();
        }
       
        return ($result);
}

I haven't fully finalised the user_search function, as of yet because I didn't have the markup language when I was coding this. I'll implement it and give you guys a heads up on the final result.
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Oct 26, 2012
Messages
2,357
Reaction score
1,086
PHP:
public static function users_search ()
{
        GLOBAL $db;
        $query = ('SELECT username, look FROM users WHERE username LIKE = ?'); // ADD PAGINATION WITH COUNT(ID) on USERS
        if ($statement = $db->prepare($query))
        {\
                $statement->bind_param('s', $user);
                $statement->execute();
                $statement->bind_result($username, $look);
                while ($statement->fetch())
                {
                        $result .= ('<a href="#" target="_self"><img src="'.$look.'" alt="'.$username.'" /></a>'); //assuming we have our markup
                }
                $statement->close();
        }
       
        return ($result);
}

Why are you using GLOBAL and not something like a static core class like this:

PHP:
<?php

class Core {

	private static $configuration;
	private static $database;
	private static $settings;

	public static function includeClasses() {
		foreach(glob('includes/classes/class.*.php') as $file) {
			if ($file == 'includes/classes/class.core.php') {
				continue;
			}
			
			include($file);
		}
	}
	
	public static function initialize() {
		self::$configuration = new Configuration();
		
		self::$database = new Database();
		self::$settings = new Settings();
	}
	
	public static function getConfiguration() {
		return self::$configuration;
	}
	
	public static function getDatabase() {
		return self::$database;
	}
	
	public static function getSettings() {
		return self::$settings;
	}
}

?>

default.php:

PHP:
<?php

include('includes/classes/class.core.php');

Core::includeClasses();
Core::initialize();

?>

(TO BE IMPROVED I KNOW, JUST GIVING EXAMPLE)
 
Joined
Jun 23, 2010
Messages
2,324
Reaction score
2,195
I think you didn't notice it but I'll tell you why I asked:

PHP:
$pages = ceil($count = $id / 10);

You create a array $count send some random values in a array and then suddenly, you use it as a int/float.
 
Legendary Battlemage
Joined
Aug 16, 2008
Messages
600
Reaction score
259
Why are you using GLOBAL and not something like a static core class like this:

PHP:
<?php

class Core {

	private static $configuration;
	private static $database;
	private static $settings;

	public static function includeClasses() {
		foreach(glob('includes/classes/class.*.php') as $file) {
			if ($file == 'includes/classes/class.core.php') {
				continue;
			}
			
			include($file);
		}
	}
	
	public static function initialize() {
		self::$configuration = new Configuration();
		
		self::$database = new Database();
		self::$settings = new Settings();
	}
	
	public static function getConfiguration() {
		return self::$configuration;
	}
	
	public static function getDatabase() {
		return self::$database;
	}
	
	public static function getSettings() {
		return self::$settings;
	}
}

?>

default.php:

PHP:
<?php

include('includes/classes/class.core.php');

Core::includeClasses();
Core::initialize();

?>

(TO BE IMPROVED I KNOW, JUST GIVING EXAMPLE)

They introduce global state into a program. Most programmers should be familiar with why global state is bad.
They introduce tight coupling between the singleton and any class that uses it. This means you can't reuse the classes in question without reusing the singleton too.
They make unit testing of classes that depend on the singleton problematic because you can't easily replace the singleton with a mock.
They encourage a coding style where classes attempt to resolve their own dependencies. This is bad because it can reduce clarity regarding what dependencies the class has.
PHP has a Share Nothing Architecture, meaning that PHP singletons aren't really singletons at all, there can be multiple instances alive at any one time (one per open request).
What happens if you suddenly discover at some later date that you actually need more than one of the resource that's being provided by the singleton? It's a more common scenario than you might think

A few reasons why Singleton is bad
 
Custom Title Activated
Loyal Member
Joined
Oct 26, 2012
Messages
2,357
Reaction score
1,086
They introduce global state into a program. Most programmers should be familiar with why global state is bad.
They introduce tight coupling between the singleton and any class that uses it. This means you can't reuse the classes in question without reusing the singleton too.
They make unit testing of classes that depend on the singleton problematic because you can't easily replace the singleton with a mock.
They encourage a coding style where classes attempt to resolve their own dependencies. This is bad because it can reduce clarity regarding what dependencies the class has.
PHP has a Share Nothing Architecture, meaning that PHP singletons aren't really singletons at all, there can be multiple instances alive at any one time (one per open request).
What happens if you suddenly discover at some later date that you actually need more than one of the resource that's being provided by the singleton? It's a more common scenario than you might think

A few reasons why Singleton is bad

Could be, but global aint 'awesome' too. Why not concider using it as a parameter of the function? Would be still better than either singleton or global.
 
Legendary Battlemage
Joined
Aug 16, 2008
Messages
600
Reaction score
259
PHP:
	public static function users_search ($user)
	{
		GLOBAL $config, $db;
		$query = ('SELECT username, look FROM users WHERE username LIKE = ?');
		if ($statement = $db->prepare($query))
		{
			$statement->bind_param('s', '%'.$user.'%');
			$statement->execute();
			$statement->bind_result($username, $look);
			while ($statement->fetch())
			{
				$class = ($x % 2 == 0) ? 'odd' : 'even';
				$result .= ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="'.$class.'">
						<div class="users-image"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
						<div class="users-p"><b>'.$username.'</b></div>
					</a>');
				$x++;
			}
			$statement->close();
		}
		
		return ($result);
	}

Uhm, can someone tell me what's wrong with this code? Mainly the part for the the query and bind_param (wildcard). Can't seem to get it working x.x

Besides this, I think I'm going to move on with the project. I haven't been active within the pre-release/dev because I've had other stuff to do.

Release on the current patch is in the attachments.
 

Attachments

  • private (2).zip
    168 KB · Views: 25
Web & Interaction Design
Loyal Member
Joined
Dec 18, 2010
Messages
1,506
Reaction score
712
PHP:
  if (isset($_GET['p'])) 
        { 
            if ($_GET['p'] == 'me') 
            { 
                $colour[0] = ' white'; 
            } 
            else if ($_GET['p'] == 'home') 
            { 
                $colour[1] = ' class="white"'; 
            } 
            else if ($_GET['p'] == 'account') 
            { 
                $colour[2] = ' class="white"'; 
            } 
            else if ($_GET['p'] == 'news') 
            { 
                $colour[3] = ' class="white"'; 
            } 
            else if ($_GET['p'] == 'staff') 
            { 
                $colour[4] = ' class="white"'; 
            } 
            else if ($_GET['p'] == 'shop') 
            { 
                $colour[5] = ' class="white"'; 
            } 
            else 
            { 
                $colour = NULL; 
            } 
        }

Start using switch statements man...

There are no real benefits to using switch case, other than looking prettier.
 
Newbie Spellweaver
Joined
Nov 6, 2013
Messages
10
Reaction score
0
ok, um isn't this wabbo/wubbo cms if not then nice edit I guess?
 
Banned
Banned
Joined
May 6, 2009
Messages
531
Reaction score
165
Well, i'm not expert in this area... But i did a little code to verify if email is already registered... Isn't a GREAT fix, but... :)

1° Go to private/application/library and open the class.user.php, then search for this public function user_name($username), then add this after void founded:
PHP:
public function user_mail($username)
	{
		GLOBAL $db;
		$query = ('SELECT mail FROM users WHERE mail = ? LIMIT 1');
		if ($statement = $db->prepare($query))
		{
			$statement->bind_param('s', $username);
			$statement->execute();
			$statement->bind_result($username);
			$statement->fetch();
			$statement->close();
			return ($username);
		}
	}

2° Go to private/application/theme/public and open the login.php, then search for this:
PHP:
else if ($usr->user_name($_POST['reg_username']))
		{
			$errors[] = 'Please enter an username that does not already exist.';
		}
After of found, add this:
PHP:
else if ($usr->user_mail($_POST['reg_email']))
		{
			$errors[] = 'Please enter an email that does not already exist.';
		}

Now you will have a verification of email!
If have something wrong with code, tell me, i'm new in PHP :p
 
Legendary Battlemage
Joined
Aug 16, 2008
Messages
600
Reaction score
259
Well, i'm not expert in this area... But i did a little code to verify if email is already registered... Isn't a GREAT fix, but... :)

...

Great work :)

Sorry I haven't been active with the project, recently.
What I've done since the last update, I've changed, renamed, removed and updated the directories, I somewhat like the new folder structure and when you get chance, please give feedback.

I've modified some of the code inside the library.html.php (previously class.html.php) that I saw a few flaws inside. The users_search function doesn't want to play ball, so I'm going to leave the function as it is and move onto something else. Moreover to Housekeeping, infact. I really need to recode the .CSS for the layout because it doesn't work properly in some browsers, I'm hoping to keep the code the same.
 
Joined
Sep 15, 2010
Messages
519
Reaction score
88
Not 100% sure of this as i just skimmed through ur code. I believe this line:

$statement->bind_param('s', '%'.$user.'%');

need to be

$statement->bind_param($query, '%'.$user.'%');

Due to the fact that its calling ur query to select users then selecting the user as follows.
 
Joined
Jun 23, 2010
Messages
2,324
Reaction score
2,195
Not 100% sure of this as i just skimmed through ur code. I believe this line:

$statement->bind_param('s', '%'.$user.'%');

need to be

$statement->bind_param($query, '%'.$user.'%');

Due to the fact that its calling ur query to select users then selecting the user as follows.

PHP: mysqli_stmt::bind_param - Manual

Predict - [pre-release] dev cms - RaGEZONE Forums


duck, where's the dislike button when you need it.
 
Status
Not open for further replies.
Back
Top