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

View file

@ -24,11 +24,12 @@
<input type="hidden" name="t" value="<?php echo $this->getData('t')?>">
<table width=519>
<tr>
<td class="c" colspan=2><?php echo $this->getData('Texts')?></td>
<td class="c" colspan=3><?php echo $this->getData('Texts')?></td>
</tr>
<tr>
<th><a href="?mode=admin&edit=ally&t=1"><?php echo $this->getData('External_text')?></a></th>
<th><a href="?mode=admin&edit=ally&t=2"><?php echo $this->getData('Internal_text')?></a></th>
<th><a href="?mode=admin&edit=ally&t=3"><?php echo $this->getData('Request_text')?></a></th>
</tr>
<tr>
<td class=c colspan=3><?php echo $this->getData('Show_of_request_text')?> (<span id="cntChars">0</span> / 5000 <?php echo $this->getData('characters')?>)</td>

View file

@ -1,27 +1,27 @@
<script src="scripts/cntchar.js" type="text/javascript"></script>
<br>
<form action="alliance.php?mode=admin&edit=requests&show=<?php echo $this->getData('id')?>&sort=0" method="POST">
<tr>
<th colspan=2><?php echo $this->getData('Request_from')?></th>
</tr>
<tr>
<th colspan=2><?php echo $this->getData('ally_request_text')?></th>
</tr>
<tr>
<td class="c" colspan=2><?php echo $this->getData('Request_responde')?></td>
</tr>
<tr>
<th>&#160;</th>
<th><input type="submit" name="action" value="Accepter"></th>
</tr>
<tr>
<th><?php echo $this->getData('Motive_optional')?> <span id="cntChars">0</span> / 500 <?php echo $this->getData('characters')?></th>
<th><textarea name="text" cols=40 rows=10 onkeyup="javascript:cntchar(500)"></textarea></th>
</tr>
<tr>
<th>&#160;</th>
<th><input type="submit" name="action" value="Refuser"></th>
</tr>
<tr>
<td colspan=2>&#160;</td>
</tr>
</form>
<tr>
<th colspan=2><?php echo $this->getData('Request_from')?></th>
</tr>
<tr>
<th colspan=2><?php echo $this->getData('ally_request_text')?></th>
</tr>
<tr>
<td class="c" colspan=2><?php echo $this->getData('Request_responde')?></td>
</tr>
<form action="alliance.php?mode=admin&edit=requests&show=<?php echo $this->getData('id')?>&sort=0" method="POST">
<tr>
<th><?php echo $this->getData('Motive_optional')?> (<span id="cntChars">0</span> / 500 <?php echo $this->getData('characters')?>)</th>
<th><textarea name="text" cols=40 rows=10 onkeyup="javascript:cntchar(500)"><?php echo $this->getData('text_apply')?></textarea></th>
</tr>
<tr>
<th>&#160;</th>
<th><input type="submit" name="action" value="Accepter">
<input type="submit" name="action" value="Refuser">
</th>
</tr>
</form>
<tr>
<td colspan=2>&#160;</td>
</tr>

View file

@ -1,3 +1,4 @@
<script src="scripts/cntchar.js" type="text/javascript"></script>
<br>
<h1><?php echo $this->getData('Send_Apply')?></h1>

View file

@ -38,7 +38,7 @@ function ShowGalaxyRows ($Galaxy, $System) {
global $lang, $planetcount, $CurrentRC, $dpath, $user;
$Result = "";
for ($Planet = 1; $Planet < 16; $Planet++) {
for ($Planet = 1; $Planet <= MAX_PLANET_IN_SYSTEM; $Planet++) {
unset($GalaxyRowPlanet);
unset($GalaxyRowMoon);
unset($GalaxyRowPlayer);