Updated alliances page, fixed SQL injections (hoegarden)

Fided minor bugs

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2011-09-15 09:08:32 +02:00
commit be8c6a6629
14 changed files with 1317 additions and 1215 deletions

View file

@ -207,7 +207,7 @@ class Legacies
public static function getResponse()
{
if (self::$_response === null) {
self::$_response = new Legacies_Core_Controller_Response();
self::$_response = new Legacies_Core_Controller_Response_Http();
}
return self::$_response;
}

View file

@ -1,6 +1,6 @@
<?php
class Legacies_Core_Controller_Response
class Legacies_Core_Controller_Response_Http
extends Legacies_Object
{
public function __construct()

View file

@ -5,8 +5,8 @@ abstract class Legacies_Core_Model
{
protected $_originalData = array();
protected $_eventPrefix = 'model';
protected $_eventObject = 'model';
protected $_eventPrefix = null;
protected $_eventObject = null;
public function __construct(Array $data = array())
{
@ -41,16 +41,22 @@ abstract class Legacies_Core_Model
protected function _beforeSave()
{
Legacies::dispatchEvent('model.before-save', array($this->_eventObject => $this));
Legacies::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this));
Legacies::dispatchEvent('model.before-save', array('model' => $this));
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
Legacies::dispatchEvent($this->_eventPrefix . '.before-save', array($this->_eventObject => $this));
}
return $this;
}
protected function _afterSave()
{
Legacies::dispatchEvent('model.after-save', array($this->_eventObject => $this));
Legacies::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this));
Legacies::dispatchEvent('model.after-save', array('model' => $this));
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
Legacies::dispatchEvent($this->_eventPrefix . '.after-save', array($this->_eventObject => $this));
}
return $this;
}
@ -73,16 +79,22 @@ abstract class Legacies_Core_Model
protected function _beforeLoad()
{
Legacies::dispatchEvent('model.before-load', array($this->_eventObject => $this));
Legacies::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this));
Legacies::dispatchEvent('model.before-load', array('model' => $this));
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
Legacies::dispatchEvent($this->_eventPrefix . '.before-load', array($this->_eventObject => $this));
}
return $this;
}
protected function _afterLoad()
{
Legacies::dispatchEvent('model.after-load', array($this->_eventObject => $this));
Legacies::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this));
Legacies::dispatchEvent('model.after-load', array('model' => $this));
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
Legacies::dispatchEvent($this->_eventPrefix . '.after-load', array($this->_eventObject => $this));
}
return $this;
}
@ -104,16 +116,22 @@ abstract class Legacies_Core_Model
protected function _beforeDelete()
{
Legacies::dispatchEvent('model.before-delete', array($this->_eventObject => $this));
Legacies::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this));
Legacies::dispatchEvent('model.before-delete', array('model' => $this));
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
Legacies::dispatchEvent($this->_eventPrefix . '.before-delete', array($this->_eventObject => $this));
}
return $this;
}
protected function _afterDelete()
{
Legacies::dispatchEvent('model.after-delete', array($this->_eventObject => $this));
Legacies::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this));
Legacies::dispatchEvent('model.after-delete', array('model' => $this));
if ($this->_eventPrefix !== null && $this->_eventObject !== null) {
Legacies::dispatchEvent($this->_eventPrefix . '.after-delete', array($this->_eventObject => $this));
}
return $this;
}

View file

@ -7,6 +7,10 @@ class Legacies_Database
protected static $_prefix = null;
public static $options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
public static function getSingleton()
{
if (self::$_singleton === null) {
@ -21,8 +25,16 @@ class Legacies_Database
$port = $config['global']['database']['options']['port'];
}
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
$event = Legacies::dispatchEvent('database.prepare-options', array(
'options' => self::$options
));
self::$options = $event->getData('options');
self::$_singleton = new self("mysql:dbname={$database};host={$hostname};port={$port}", $username, $password, self::$options);
Legacies::dispatchEvent('database.init', array(
'handler' => self::$_singleton
));
}
return self::$_singleton;

View file

@ -769,7 +769,7 @@ class Legacies_Empire_Model_Planet
return;
}
$collection = self::_searchMostFreeSystems();
$collection = self::searchMostFreeSystems();
$collection->limit(1)->load();
if ($collection->count() == 0) {
@ -832,22 +832,21 @@ class Legacies_Empire_Model_Planet
'user' => $user
));
//$planet->save();
$planet->save();
}
}
protected static function _searchMostFreeSystems($galaxyList = null, $systemList = null)
public static function searchMostFreeSystems($galaxyList = null, $systemList = null)
{
$collection = new Legacies_Core_Collection(array('planet' => 'planets'));
$collection = new Legacies_Core_Collection(array('galaxy' => 'galaxy'));
$collection
->column(array(
'galaxy' => 'planet.galaxy',
'system' => 'planet.system',
'count' => 'COUNT(planet.id)'
'galaxy' => 'galaxy.galaxy',
'system' => 'galaxy.system',
'count' => 'COUNT(*)'
))
->group('planet.galaxy')
->group('planet.system')
->where('planet.planet_type=1')
->group('galaxy.galaxy')
->group('galaxy.system')
;
$config = Legacies_Core_Model_Config::getSingleton();
@ -858,7 +857,7 @@ class Legacies_Empire_Model_Planet
if ($galaxyList !== null) {
array_walk($galaxyList, array(__CLASS__, '_cleanItemRanges'));
$collection->where('planet.galaxy IN(' . implode(', ', $galaxyList) . ')');
$collection->where('galaxy.galaxy IN(' . implode(', ', $galaxyList) . ')');
}
if ($systemList === null && $config->hasData('user/registration/system_list')) {
@ -867,16 +866,20 @@ class Legacies_Empire_Model_Planet
if ($systemList !== null) {
array_walk($systemList, array(__CLASS__, '_cleanItemRanges'));
$collection->where('planet.system IN(' . implode(', ', $systemList) . ')');
$collection->where('galaxy.system IN(' . implode(', ', $systemList) . ')');
}
$orders = array(
"1.5 / COUNT(planet.id)",
"ABS(planet.galaxy - CEIL({$collection->quote(MAX_GALAXY_IN_WORLD)} / 2))",
"ABS(planet.system - CEIL({$collection->quote(MAX_SYSTEM_IN_GALAXY)} / 2))"
"COUNT(*) / {$collection->quote(MAX_PLANET_IN_SYSTEM)}",
"1 + ABS(galaxy.galaxy - CEIL({$collection->quote(MAX_GALAXY_IN_WORLD)} / 2))",
"1 + 2 * ABS(galaxy.system - CEIL({$collection->quote(MAX_SYSTEM_IN_GALAXY)} / 2))",
"RAND() / 1000",
);
$collection
->order('((' . implode(') * (', $orders) . '))', 'ASC')
//->order("ABS(galaxy.system - CEIL({$collection->quote(MAX_SYSTEM_IN_GALAXY)} / 2))", 'ASC')
//->order("ABS(galaxy.galaxy - CEIL({$collection->quote(MAX_GALAXY_IN_WORLD)} / 2))", 'ASC')
//->order("1.5 / COUNT(*)", 'ASC')
->order('RAND()', 'ASC');
return $collection;

View file

@ -127,9 +127,7 @@ class Legacies_Empire_Model_User
public function logout()
{
if (Legacies::$response !== null) {
Legacies::$response->unsetCookie(self::$_cookieName);
}
Legacies::getResponse()->unsetCookie(self::$_cookieName);
Legacies_Core_Model_Session::destroy();
}

View file

@ -3,6 +3,9 @@
class Legacies_Empire_Model_User_Message
extends Legacies_Core_Entity_SubTable
{
protected $_eventObject = 'message';
protected $_eventPrefix = 'user.message';
protected function _init()
{
$this->_tableName = 'messages';