Configuration & Layout architecture updates

Fixed production bug
Fixed styles
Updated Action Controller

Signed-off-by: Gregory PLANCHAT <g.planchat@gmail.com>
This commit is contained in:
Gregory PLANCHAT 2012-01-13 23:36:03 +01:00
commit 66805034a6
815 changed files with 4020 additions and 1138 deletions

View file

@ -291,7 +291,7 @@ CREATE TABLE IF NOT EXISTS {$this->getTableName('planets')} (
`b_building_id` TEXT NOT NULL,
`b_tech` SMALLINT UNSIGNED NOT NULL,
`b_tech_id` SMALLINT UNSIGNED NOT NULL,
`b_hangar` SMALLINT UNSIGNED NOT NULL,
`b_hangar` INT UNSIGNED NOT NULL,
`b_hangar_id` TEXT NOT NULL,
`b_hangar_plus` SMALLINT UNSIGNED NOT NULL,
`image` VARCHAR(50) NOT NULL DEFAULT 'normaltempplanet01',

View file

@ -55,68 +55,73 @@ class Wootook
*
* @var Legacies_Core_Controller_Request_Http
*/
protected static $_request = null;
private static $_request = null;
/**
* HTTP response management object
*
* @var Legacies_Core_Controller_Response
*/
protected static $_response = null;
private static $_response = null;
/**
* The current timestamp
*
* @var int
*/
protected static $_now = null;
private static $_now = null;
/**
* Default locale identifier
*
* @var string
*/
protected static $_defaultLocale = 'fr_FR';
private static $_defaultLocale = 'fr_FR';
/**
*
* Enter description here ...
* @var Wootook_Core_Config_Adapter_Abstract
*/
protected static $_config = null;
private static $_config = null;
/**
*
* Enter description here ...
* @var Wootook_Core_Config_Adapter_Abstract
*/
protected static $_globalConfig = null;
private static $_globalConfig = null;
/**
*
* Enter description here ...
* @var array
*/
protected static $_websiteConfigs = array();
private static $_websiteConfigs = array();
/**
*
* Enter description here ...
* @var array
*/
protected static $_gameConfigs = array();
private static $_gameConfigs = array();
/**
*
* Enter description here ...
* @var array
*/
protected static $_ignoreDatabaseConfig = false;
private static $_ignoreDatabaseConfig = false;
protected static $_websitesById = array();
protected static $_websitesByCode = array();
protected static $_gamesById = array();
protected static $_gamesByCode = array();
private static $_defaultWebsite = null;
private static $_defaultGame = null;
private static $_websitesById = array();
private static $_websitesByCode = array();
private static $_gamesById = array();
private static $_gamesByCode = array();
public static $isInstalled = true;
/**
* Registers an event listener to be called later in the application.
@ -329,13 +334,25 @@ class Wootook
self::$_config = new Wootook_Core_Config_Adapter_Array();
try {
if (!is_array($filename)) {
if ($filename === null) {
$filename = ROOT_PATH . 'config.php';
self::$_config->load(APPLICATION_PATH . 'config' . DIRECTORY_SEPARATOR . 'system.php');
if ($filename === null) {
$filename = APPLICATION_PATH . 'config' . DIRECTORY_SEPARATOR . 'local.php';
}
if (is_string($filename)) {
if (!self::$isInstalled) {
throw new Wootook_Core_Exception_DataAccessException();
}
self::$_config->load($filename);
$localConfig = new Wootook_Core_Config_Adapter_Array($filename);
self::$_config->merge($localConfig);
} else if (is_array($filename)) {
$localConfig = new Wootook_Core_Config_Node($filename);
self::$_config->merge($localConfig);
} else if ($filename instanceof Wootook_Core_Config_Node) {
self::$_config->merge($filename);
} else {
self::$_config->setData($filename);
throw new Wootook_Core_Exception_DataAccessException();
}
} catch (Wootook_Core_Exception_DataAccessException $e) {
self::$_globalConfig = new Wootook_Core_Config_Node(array(), self::$_config);
@ -353,7 +370,7 @@ class Wootook
return self::$_config;
}
protected static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $model = null)
private static function _appendDatabaseConfig(Wootook_Core_Config_Node $config, $type = 'global', $model = null)
{
if (self::$_ignoreDatabaseConfig) {
return $config;
@ -462,25 +479,67 @@ class Wootook
}
}
public static function setWebsite($websiteId, $website)
public static function addWebsite(Wootook_Core_Model_Website $website)
{
$websiteId = $website->getId();
$websiteKey = $website->getData('code');
self::$_websitesById[$websiteId] = $website;
self::$_websitesByCode[$websiteKey] = $website;
}
public static function setGame($gameId, $game)
public static function addGame(Wootook_Core_Model_Game $game)
{
$gameId = $game->getId();
$gameKey = $game->getData('code');
self::$_gamesById[$gameId] = $game;
self::$_gamesByCode[$gameKey] = $game;
}
protected static function _initWebsiteConfig($websiteId)
public static function setDefaultWebsite(Wootook_Core_Model_Website $website)
{
self::$_defaultWebsite = $website;
}
public static function getDefaultWebsite()
{
if (self::$_defaultWebsite === null) {
self::$_defaultWebsite = new Wootook_Core_Model_Website();
self::$_defaultWebsite->setId(1)->setData('code', Wootook_Core_Model_Website::DEFAULT_CODE);
}
return self::$_defaultWebsite;
}
public static function getDefaultGame()
{
if (self::$_defaultGame === null) {
self::$_defaultGame = new Wootook_Core_Model_Game();
self::$_defaultGame->setId(1)->setData('code', Wootook_Core_Model_Game::DEFAULT_CODE);
}
return self::$_defaultGame;
}
public static function setDefaultGame(Wootook_Core_Model_Game $game)
{
self::$_defaultGame = $game;
}
private static function _initWebsiteConfig($websiteId)
{
if (self::$_config === null) {
self::loadConfig();
}
if (!self::$isInstalled) {
if (isset(self::$_config['default'])) {
self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE] = clone self::$_config['default'];
} else {
self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE] = new Wootook_Core_Config_Node(array(), self::$_config);
}
if (isset(self::$_config['install'])) {
self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE]->merge(self::$_config['install']);
}
return self::$_websiteConfigs[Wootook_Core_Model_Website::DEFAULT_CODE];
}
try {
$website = self::getWebsite($websiteId);
@ -493,8 +552,10 @@ class Wootook
if (!isset(self::$_websiteConfigs[$websiteKey])) {
self::$_websiteConfigs[$websiteKey] = clone self::$_config['default'];
if (isset(self::$_config['frontend'])) {
if ($websiteId != 0 && isset(self::$_config['frontend'])) {
self::$_websiteConfigs[$websiteKey]->merge(self::$_config['frontend']);
} else if ($websiteId == 0 && isset(self::$_config['backend'])) {
self::$_websiteConfigs[$websiteKey]->merge(self::$_config['backend']);
}
$websiteConfig = self::$_config->getConfig("website/{$websiteKey}");
@ -508,11 +569,23 @@ class Wootook
return self::$_websiteConfigs[$websiteKey];
}
protected static function _initGameConfig($gameId)
private static function _initGameConfig($gameId)
{
if (self::$_config === null) {
self::loadConfig();
}
if (!self::$isInstalled) {
if (isset(self::$_config['default'])) {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = clone self::$_config['default'];
} else {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE] = new Wootook_Core_Config_Node(array(), self::$_config);
}
if (isset(self::$_config['install'])) {
self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE]->merge(self::$_config['install']);
}
return self::$_gameConfigs[Wootook_Core_Model_Game::DEFAULT_CODE];
}
try {
$game = self::getGame($gameId);
@ -562,7 +635,8 @@ class Wootook
}
if ($websiteKey === null) {
$websiteKey = Wootook_Core_Model_Website::DEFAULT_CODE;
//$websiteKey = Wootook_Core_Model_Website::DEFAULT_CODE;
$websiteKey = self::getDefaultWebsite()->getData('code');
}
$config = self::_initWebsiteConfig($websiteKey);
@ -583,7 +657,8 @@ class Wootook
}
if ($gameKey === null) {
$gameKey = Wootook_Core_Model_Game::DEFAULT_CODE;
//$gameKey = Wootook_Core_Model_Game::DEFAULT_CODE;
$gameKey = self::getDefaultGame()->getData('code');
}
$config = self::_initGameConfig($gameKey);
@ -631,14 +706,28 @@ class Wootook
return true;
}
public static function getBaseUrl()
public static function getBaseUrl($domain = 'base')
{
return self::getConfig('web/base_url');
$urlConfig = self::getGameConfig('web/url');
if (!$urlConfig instanceof Wootook_Core_Config_Node) {
return null;
}
if (!is_string($domain) || !isset($urlConfig->$domain)) {
return $urlConfig->base;
}
return $urlConfig->$domain;
}
public static function getSkinUrl($package, $theme, $uri, Array $params = array())
public static function getBasePath($domain = 'base')
{
return self::getUrl("skin/{$package}/{$theme}/{$uri}", $params);
$pathConfig = self::getGameConfig('system/path');
if (!$pathConfig instanceof Wootook_Core_Config_Node) {
return null;
}
if (!is_string($domain) || !isset($pathConfig->$domain)) {
return $pathConfig->base;
}
return $pathConfig->$domain;
}
public static function getUrl($uri, Array $params = array())

View file

@ -0,0 +1,13 @@
<?php
abstract class Wootook_Admin_Controller_Front_Action
extends Wootook_Core_Controller_Front_Action
{
protected function _initLayout()
{
$layout = new Wootook_Core_Layout(Wootook_Core_Layout::DOMAIN_BACKEND);
$layout->registerBlockNamespace('admin', 'Wootook_Admin_Block_', 'Wootook/Admin/Block');
return $layout;
}
}

View file

@ -0,0 +1,10 @@
<?php
class Wootook_Admin_IndexController
extends Wootook_Admin_Controller_Front_Action
{
public function indexAction()
{
$this->_forward('index', 'user');
}
}

View file

@ -0,0 +1,40 @@
<?php
class Wootook_Admin_UserController
extends Wootook_Admin_Controller_Front_Action
{
public function indexAction()
{
$this->_forward('grid');
}
public function gridAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function newAction()
{
}
public function editAction()
{
}
public function saveAction()
{
}
public function saveMassAction()
{
}
public function deleteAction()
{
}
public function deleteMassAction()
{
}
}

View file

@ -3,6 +3,7 @@
class Wootook_Core_Block_Html_Head
extends Wootook_Core_Block_Template
{
const TYPE_GLOBAL_CSS = 'global_css';
const TYPE_GLOBAL_JS = 'global_js';
const TYPE_SKIN_CSS = 'skin_css';
@ -19,7 +20,7 @@ class Wootook_Core_Block_Html_Head
protected $_title = '';
protected $_titleDefaultConcat = self::TITLE_CONCAT_AFTER;
protected $_titleSeparator = ' | ';
protected $_titleSeparator = ' ¤ ';
protected $_titleConcatTypes = array(
self::TITLE_CONCAT_AFTER,
@ -85,37 +86,56 @@ class Wootook_Core_Block_Html_Head
return $this;
}
public function addJs($script, $type = 'text/javascript', Array $options = array())
public function addJs($script, $type = 'text/javascript', Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $script;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_GLOBAL_JS, $options);
return $this;
}
public function addCss($stylesheet, $type = 'text/css', $condition = null, Array $options = array())
public function addCss($stylesheet, $type = 'text/css', $condition = null, Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $stylesheet;
$options['condition'] = $condition;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_SKIN_CSS, $options);
$this->addItem(self::TYPE_GLOBAL_CSS, $options);
return $this;
}
public function addSkinJs($script, $type = 'text/javascript', Array $options = array())
public function addSkinJs($script, $type = 'text/javascript', Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $script;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_SKIN_JS, $options);
return $this;
}
public function addSkinCss($stylesheet, $type = 'text/css', $condition = null, Array $options = array(), $theme = null, $package = null)
{
$options['type'] = $type;
$options['path'] = $stylesheet;
$options['condition'] = $condition;
$options['theme'] = $theme;
$options['package'] = $package;
$this->addItem(self::TYPE_SKIN_CSS, $options);
return $this;
}
public function addInlineJs($content, $type = 'text/javascript', Array $options = array())
{
$options['type'] = $type;
@ -129,7 +149,6 @@ class Wootook_Core_Block_Html_Head
public function addInlineCss($content, $type = 'text/css', Array $options = array())
{
$options['type'] = $type;
$options['path'] = $path;
$options['content'] = $content;
$this->addItem(self::TYPE_INLINE_CSS, $options);
@ -138,6 +157,14 @@ class Wootook_Core_Block_Html_Head
}
public function getCss()
{
if (isset($this->_items[self::TYPE_GLOBAL_CSS])) {
return $this->_items[self::TYPE_GLOBAL_CSS];
}
return array();
}
public function getSkinCss()
{
if (isset($this->_items[self::TYPE_SKIN_CSS])) {
return $this->_items[self::TYPE_SKIN_CSS];
@ -184,8 +211,35 @@ class Wootook_Core_Block_Html_Head
if (!isset($css['media'])) {
$css['media'] = 'all';
}
$url = $this->getUrl($css['path'], array());
$render .=<<<HTML_EOF
<link rel="stylesheet" type="{$css['type']}" src="{$css['path']}" media="{$css['media']}" />
<link rel="stylesheet" type="{$css['type']}" src="{$url}" media="{$css['media']}" />
HTML_EOF;
}
}
public function renderSkinCss()
{
$render = '';
foreach ($this->getSkinCss() as $css) {
if (!isset($css['media'])) {
$css['media'] = 'all';
}
$url = $this->getSkinUrl($css['path'], array(), $css['theme'], $css['package']);
$render .=<<<HTML_EOF
<link rel="stylesheet" type="{$css['type']}" src="{$url}" media="{$css['media']}" />
HTML_EOF;
}
}
public function renderInlineCss()
{
foreach ($this->getInlineCss() as $css) {
if (!isset($css['media'])) {
$css['media'] = 'all';
}
$render .=<<<HTML_EOF
<style type="{$css['type']}">/*<![CDATA[*/{$css['content']}/*]]>*/</style>
HTML_EOF;
}
return $render;
@ -198,8 +252,34 @@ HTML_EOF;
if (!isset($js['type'])) {
$js['type'] = 'text/javascript';
}
$url = $this->getUrl($js['path']);
$render .=<<<HTML_EOF
<script type="{$js['type']}" src="{$js['path']}"></script>
<script type="{$js['type']}" src="{$url}"></script>
HTML_EOF;
}
return $render;
}
public function renderSkinJs()
{
$render = '';
foreach ($this->getJs() as $js) {
if (!isset($js['type'])) {
$js['type'] = 'text/javascript';
}
$url = $this->getSkinUrl($js['path'], array(), $js['theme'], $js['package']);
$render .=<<<HTML_EOF
<script type="{$js['type']}" src="{$url}"></script>
HTML_EOF;
}
return $render;
}
public function renderInlineJs()
{
foreach ($this->getInlineJs() as $js) {
$render .=<<<HTML_EOF
<script type="{$js['type']}">/*<![CDATA[*/{$js['content']}/*]]>*/</script>
HTML_EOF;
}
return $render;

View file

@ -65,13 +65,7 @@ class Wootook_Core_Collection
public function quote($data)
{
static $database = null;
if ($database === null) {
$database = Wootook_Database::getSingleton();
}
return $database->quote($data);
return $this->getReadConnection()->quote($data);
}
public function column($column = '*', $alias = null)
@ -102,11 +96,7 @@ class Wootook_Core_Collection
public function join($table, $condition, $fields = array('*'), $mode = 'INNER')
{
static $database = null;
if ($database === null) {
$database = Wootook_Database::getSingleton();
}
$database = $this->getReadConnection();
if (is_array($table)) {
$alias = key($table);
@ -160,7 +150,7 @@ class Wootook_Core_Collection
protected function _prepareSql()
{
if (empty($this->_union)) {
$database = Wootook_Database::getSingleton();
$database = $this->getReadConnection();
$fields = array();
foreach ($this->_columns as $field) {
@ -301,7 +291,7 @@ SQL_EOF;
$sql = $clone->_prepareSql();
$database = Wootook_Database::getSingleton();
$database = $this->getReadConnection();
$statement = $database->prepare($sql);
$args = func_get_args();

View file

@ -12,6 +12,9 @@ class Wootook_Core_Config_Adapter_Array
public function load($filename)
{
if (!file_exists($filename)) {
throw new Wootook_Core_Exception_DataAccessException(sprintf('Could not load config file "%s"', $filename));
}
$data = include $filename;
if (!is_array($data)) {

View file

@ -1,50 +0,0 @@
<?php
class Wootook_Core_Controller_Action
{
private $_request = null;
private $_response = null;
public function init()
{
}
public function preDispatch()
{
}
public function postDispatch()
{
}
public function getRequest()
{
return $this->_request;
}
public function getResponse()
{
return $this->_response;
}
protected function _forward($action, $controller = null, $module = null)
{
$request = $this->getRequest();
$request->setAction($action);
if ($controller !== null) {
$request->setController($controller);
if ($module != null) {
$request->setModule($module);
}
}
$request->setIsDispatched(false);
}
protected function _redirect($url)
{
$this->getResponse()->setRedirect($url);
return $this;
}
}

View file

@ -0,0 +1,136 @@
<?php
abstract class Wootook_Core_Controller_Front_Action
{
private $_request = null;
private $_response = null;
private $_layout = null;
public function __construct(Wootook_Core_Controller_Request_Http $request, Wootook_Core_Controller_Response_Http $response)
{
$this->setRequest($request);
$this->setResponse($response);
}
public function init()
{
}
public function preDispatch()
{
}
public function postDispatch()
{
}
public function setRequest(Wootook_Core_Controller_Request_Http $request)
{
$this->_request = $request;
return $this;
}
public function setResponse(Wootook_Core_Controller_Response_Http $response)
{
$this->_response = $response;
return $this;
}
/**
*
* @return Wootook_Core_Controller_Request_Http
*/
public function getRequest()
{
return $this->_request;
}
/**
*
* @return Wootook_Core_Controller_Response_Http
*/
public function getResponse()
{
return $this->_response;
}
protected function _forward($action, $controller = null, $module = null)
{
$request = $this->getRequest();
$request->setActionName($action);
if ($controller !== null) {
$request->setControllerName($controller);
if ($module != null) {
$request->setModuleName($module);
}
}
$request->setIsDispatched(false);
}
protected function _redirect($uri, Array $params = array(), $code = Wootook_Core_Controller_Response_Http::REDIRECT_FOUND)
{
$this->getResponse()
->setRedirect(Wootook::getUrl($uri, $params), $code);
return $this;
}
protected function _redirectUrl($url, $code = Wootook_Core_Controller_Response_Http::REDIRECT_FOUND)
{
$this->getResponse()->setRedirect($url, $code);
return $this;
}
protected function _buildLayoutHandle()
{
$request = $this->getRequest();
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
return "{$module}.{$controller}.{$action}";
}
public function loadLayout($handle = null)
{
if ($this->_layout === null) {
$this->_layout = $this->_initLayout();
}
if ($handle === null) {
$handle = $this->_buildLayoutHandle();
}
$this->_layout->load($handle);
return $this;
}
protected function _initLayout()
{
return new Wootook_Core_Layout(Wootook_Core_Layout::DOMAIN_FRONTEND);
}
public function getLayout()
{
return $this->_layout;
}
public function renderLayout()
{
try {
$content = $this->getLayout()->render();
} catch (Wootook_Core_Exception_LayoutException $e) {
Wootook_Core_ErrorProfiler::getSingleton()->addException($e);
return $this;
}
$this->getResponse()->setBody($content);
return $this;
}
}

View file

@ -0,0 +1,26 @@
<?php
abstract class Wootook_Core_Controller_Request_Abstract
extends Wootook_Object
{
public function setParam($key, $value)
{
return $this->setData($key, $value);
}
public function getParam($key, $default = null)
{
if ($this->hasData($key)) {
return $this->getData($key);
}
return $default;
}
abstract public function getModuleName();
abstract public function getControllerName();
abstract public function getActionName();
abstract public function setModuleName($name);
abstract public function setControllerName($name);
abstract public function setActionName($name);
}

View file

@ -1,12 +1,13 @@
<?php
class Wootook_Core_Controller_Request_Http
extends Wootook_Object
extends Wootook_Core_Controller_Request_Abstract
{
public function __construct()
{
parent::__construct(array());
}
protected $_actionKey = 'action';
protected $_controllerKey = 'controller';
protected $_moduleKey = 'module';
protected $_isDispatched = false;
public function setParam($key, $value)
{
@ -149,4 +150,82 @@ class Wootook_Core_Controller_Request_Http
}
return false;
}
public function getModuleKey()
{
return $this->_moduleKey;
}
public function setModuleKey($key)
{
$this->_moduleKey = $key;
return $this;
}
public function getModuleName()
{
return $this->getParam($this->getModuleKey());
}
public function setModuleName($name)
{
return $this->setParam($this->getModuleKey(), $name);
}
public function getControllerKey()
{
return $this->_controllerKey;
}
public function setControllerKey($key)
{
$this->_controllerKey = $key;
return $this;
}
public function getControllerName()
{
return $this->getParam($this->getControllerKey(), 'index');
}
public function setControllerName($name)
{
return $this->setParam($this->getControllerKey(), $name);
}
public function getActionKey()
{
return $this->_actionKey;
}
public function setActionKey($key)
{
$this->_actionKey = $key;
return $this;
}
public function getActionName()
{
return $this->getParam($this->getActionKey(), 'index');
}
public function setActionName($name)
{
return $this->setParam($this->getActionKey(), $name);
}
public function setIsDispatched($dispatched = true)
{
$this->_isDispatched = $dispatched;
return $this;
}
public function isDispatched()
{
return $this->_isDispatched;
}
}

View file

@ -0,0 +1,18 @@
<?php
abstract class Wootook_Core_Controller_Response_Abstract
extends Wootook_Object
{
public function setParam($key, $value)
{
return $this->setData($key, $value);
}
public function getParam($key, $default = null)
{
if ($this->hasData($key)) {
return $this->getData($key);
}
return $default;
}
}

View file

@ -1,7 +1,7 @@
<?php
class Wootook_Core_Controller_Response_Http
extends Wootook_Object
extends Wootook_Core_Controller_Response_Abstract
{
const REDIRECT_MOVED_PERMANENTLY = 301;
const REDIRECT_FOUND = 302;
@ -15,11 +15,6 @@ class Wootook_Core_Controller_Response_Http
self::REDIRECT_TEMPORARY => 'Temporary Redirect'
);
public function __construct()
{
parent::__construct(array());
}
public function setBody($data)
{
$this->clearBody();
@ -46,6 +41,9 @@ class Wootook_Core_Controller_Response_Http
public function sendBody()
{
if (!isset($this->_data['body']) || empty($this->_data['body'])) {
return '';
}
return implode('', $this->_data['body']);
}

View file

@ -133,7 +133,6 @@ class Wootook_Core_ErrorProfiler
$microsec = (int) ($error['time'][0] * 1000000);
return <<<ERROR_EOF
Message #{$id}
On: {$date} +{$microsec}µs
Type: {$code}
Message: {$error['message']}
@ -150,47 +149,66 @@ ERROR_EOF;
}
$index = 0;
echo '<div style="background:#FFF;border:1px solid #F00;color:#000;padding:10px;margin:20px;text-align:left;">';
echo '<h1>Debug profiler</h1>';
echo '<div style="background:#FFF;border:5px solid #933;border-top-width:15px;border-radius:5px;color:#000;padding:0;margin:20px;text-align:left;margin:50px auto;width:800px;">';
echo '<h1 style="margin:0;padding:0 10px;text-decoration:none;border-bottom:3px solid #933;">Debug profiler</h1>';
if (count($this->_errors) <= 0 && count($this->_warnings) <= 0 &&
count($this->_notices) <= 0 && count($this->_otherErrors) <= 0 &&
count($this->_exceptions) <= 0) {
echo '<p>Profiler was empty.</p>';
echo '<p style="color:#666;font-style:italic;margin:20px 10px 10px;">Error profiler was empty.</p>';
} else {
echo '<pre>';
echo '<div style="margin:0;overflow:auto;">';
foreach ($this->_errors as $error) {
echo $this->_renderError(++$index, $error);
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:0 5px;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
foreach ($this->_warnings as $error) {
echo $this->_renderError(++$index, $error);
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
foreach ($this->_notices as $error) {
echo $this->_renderError(++$index, $error);
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
foreach ($this->_otherErrors as $errorList) {
foreach ($errorList as $error) {
echo $this->_renderError(++$index, $error);
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $this->_renderError($index, $error);
echo '</pre>';
}
}
foreach ($this->_exceptions as $exception) {
$index++;
echo "Message #{$index}". PHP_EOL;
++$index;
echo '<h2 style="font-size:1.2em;text-decoration:none;margin:10px 5px 0;">Message #' . $index . '</h2>';
echo '<pre style="margin:0 5px;">';
echo $exception->getMessage() . PHP_EOL;
echo $exception->getTraceAsString() . PHP_EOL;
echo PHP_EOL;
echo '</pre>';
$child = 0;
$current = $exception;
while (($current = $current->getPrevious()) !== null) {
$child++;
echo " Child level #{$child}". PHP_EOL;
echo " " . $current->getMessage() . PHP_EOL;
echo '<h3 style="font-size:1em;text-decoration:none;margin:10px 30px 0;">Message #' . $index . ', child level #' . $child . '</h3>';
echo '<pre style="margin:0 30px;">';
echo $current->getMessage() . PHP_EOL;
echo $current->getTraceAsString() . PHP_EOL;
echo PHP_EOL;
echo '</pre>';
}
echo PHP_EOL;
}
echo '</pre>';
echo '</div>';
}
echo '</div>';
}

View file

@ -0,0 +1,6 @@
<?php
class Wootook_Core_Exception_LayoutException
extends Wootook_Core_Exception_RuntimeException
{
}

View file

@ -2,16 +2,16 @@
class Wootook_Core_Form
{
protected $_fields = array();
protected $_elements = array();
protected $_request = null;
/**
*
* Field class loader
* @var Wootook_Core_Form_FieldLoader
* Element class loader
* @var Wootook_Core_Form_ElementLoader
*/
protected $_fieldLoader = null;
protected $_elementLoader = null;
/**
*
@ -27,30 +27,30 @@ class Wootook_Core_Form
*/
protected $_session = null;
public function __construct(Wootook_Core_Model_Session $session, Array $fields = array())
public function __construct(Wootook_Core_Model_Session $session, Array $elements = array())
{
$this->_session = $session;
$this->_fieldLoader = new Wootook_Core_Form_FieldLoader($this, array(
'Wootook_Core_Form_Field_' => 'Wootook/Core/Form/Field'
$this->_elementLoader = new Wootook_Core_Form_ElementLoader($this, array(
'Wootook_Core_Form_Element_' => 'Wootook/Core/Form/Element'
));
$this->_validatorLoader = new Wootook_Core_Form_ValidatorLoader($this, array(
'Wootook_Core_Form_Validator_' => 'Wootook/Core/Form/Validator'
));
$this->addField('__formkey', 'text', array('form_key' => 'formKey'));
$this->addElement('__formkey', 'text', array('form_key' => 'formKey'));
foreach ($fields as $fieldName => $fieldConfig) {
if (is_string($fieldConfig)) {
$this->addField($fieldName, $fieldConfig);
} else if ($fieldConfig instanceof Wootook_Core_Form_FieldAbstract) {
$this->addField($fieldName, $fieldConfig);
foreach ($elements as $elementName => $elementConfig) {
if (is_string($elementConfig)) {
$this->addElement($elementName, $elementConfig);
} else if ($elementConfig instanceof Wootook_Core_Form_ElementAbstract) {
$this->addElement($elementName, $elementConfig);
} else {
if (isset($fieldConfig['validators'])) {
$this->addField($fieldName, $fieldConfig['type'], $fieldConfig['validators']);
if (isset($elementConfig['validators'])) {
$this->addElement($elementName, $elementConfig['type'], $elementConfig['validators']);
} else {
$this->addField($fieldName, $fieldConfig['type']);
$this->addElement($elementName, $elementConfig['type']);
}
}
}
@ -58,8 +58,8 @@ class Wootook_Core_Form
public function validate()
{
foreach ($this->_fields as $field) {
if (!$field->validate()) {
foreach ($this->_elements as $element) {
if (!$element->validate()) {
return false;
}
}
@ -70,36 +70,37 @@ class Wootook_Core_Form
*
* Enter description here ...
* @param string $name
* @param string|Wootook_Core_Form_FieldAbstract $type
* @param string|Wootook_Core_Form_ElementAbstract $type
* @return Wootook_Core_Form
*/
public function addField($name, $type = 'text', Array $validators = array())
public function addElement($name, $type = 'text', Array $validators = array())
{
if ($type instanceof Wootook_Core_Form_FieldAbstract) {
$this->_fields[$name] = $name;
$this->_fields[$name]->setForm($this);
if ($type instanceof Wootook_Core_Form_ElementAbstract) {
$this->_elements[$name] = $name;
$this->_elements[$name]->setForm($this);
} else {
$field = $this->_fieldLoader->load($type);
$element = $this->_elementLoader->load($type);
if ($field === null) {
trigger_error(sprintf('Field %1$s (type: %2$s) could not be created.', $name, $type), E_USER_WARNING);
if ($element === null) {
trigger_error(sprintf('Element %1$s (type: %2$s) could not be created.', $name, $type), E_USER_WARNING);
return $this;
}
$this->_fields[$name] = $field;
$this->_elements[$name] = $element;
}
$this->_fields[$name]->setName($name);
$this->_elements[$name]->setName($name);
foreach ($validators as $validatorName => $validatorType) {
if ($validatorType instanceof Wootook_Core_Form_FieldAbstract) {
$this->_fields[$name]->addValidator($validatorType, $validatorName);
if ($validatorType instanceof Wootook_Core_Form_ElementAbstract) {
$this->_elements[$name]->addValidator($validatorType, $validatorName);
} else {
$validator = $this->_validatorLoader->load($validatorType);
if ($validator === null) {
trigger_error(sprintf('Validator %1$s (type: %2$s) could not be created.', $validatorName, $validatorType), E_USER_WARNING);
Wootook_Core_ErrorProfiler::getSingleton()
->addException(new Wootook_Core_Exception_RuntimeException(sprintf('Validator %1$s (type: %2$s) could not be created.', $validatorName, $validatorType)));
return $this;
}
$this->_fields[$name]->addValidator($validator, $validatorName);
$this->_elements[$name]->addValidator($validator, $validatorName);
}
}
@ -110,15 +111,15 @@ class Wootook_Core_Form
*
* Enter description here ...
* @param string $name
* @return Wootook_Core_Form_FieldAbstract
* @return Wootook_Core_Form_ElementAbstract
*/
public function getField($name)
public function getElement($name)
{
if (!isset($this->_fields[$name])) {
if (!isset($this->_elements[$name])) {
return null;
}
return $this->_fields[$name];
return $this->_elements[$name];
}
/**
@ -165,13 +166,13 @@ class Wootook_Core_Form
{
$request = $this->getRequest();
foreach ($this->_fields as $fieldName => $field) {
if (isset($datas[$fieldName])) {
$field->populate($datas[$fieldName]);
foreach ($this->_elements as $elementName => $element) {
if (isset($datas[$elementName])) {
$element->populate($datas[$elementName]);
} else if ($request->isPost()) {
$field->populate($request->getPost($fieldName));
$element->populate($request->getPost($elementName));
} else {
$field->populate($request->getQuery($fieldName));
$element->populate($request->getQuery($elementName));
}
}
}

View file

@ -0,0 +1,11 @@
<?php
class Wootook_Core_Form_Element_Button
extends Wootook_Core_Form_ElementAbstract
{
public function getType()
{
return 'button';
}
}

View file

@ -0,0 +1,11 @@
<?php
class Wootook_Core_Form_Element_Text
extends Wootook_Core_Form_ElementAbstract
{
public function getType()
{
return 'text';
}
}

View file

@ -1,18 +1,23 @@
<?php
abstract class Wootook_Core_Form_FieldAbstract
abstract class Wootook_Core_Form_ElementAbstract
{
protected $_name = null;
protected $_form = null;
protected $_value = null;
protected $_params = null;
protected $_validators = array();
public function __construct(Wootook_Core_Form $form = null)
public function __construct($name, $params, Wootook_Core_Form $form = null)
{
if ($form !== null) {
$this->setForm($form);
}
$this->setName($name);
$this->setParams($params);
}
abstract public function getType();
@ -41,6 +46,42 @@ abstract class Wootook_Core_Form_FieldAbstract
return $this->_name;
}
public function setAllParams($params)
{
$this->_params = $params;
return $this;
}
public function getAllParams()
{
return $this->_params;
}
public function setParam($param, $value)
{
$this->_params[$param] = $value;
return $this;
}
public function getParam($param)
{
return $this->_params[$param];
}
public function hasParam($param)
{
return isset($this->_params[$param]);
}
public function unsetParam($param)
{
unset($this->_params[$param]);
return $this;
}
public function setForm(Wootook_Core_Form $form)
{
$this->_form = $form;

View file

@ -1,6 +1,6 @@
<?php
class Wootook_Core_Form_FieldLoader
class Wootook_Core_Form_ElementLoader
extends Wootook_Core_Plugin_LoaderAbstract
{
protected $_form = null;

View file

@ -1,11 +0,0 @@
<?php
class Wootook_Core_Form_Field_Text
extends Wootook_Core_Form_FieldAbstract
{
public function getType()
{
return 'text';
}
}

View file

@ -6,6 +6,9 @@ class Wootook_Core_Layout
const DEFAULT_PACKAGE = 'base';
const DEFAULT_THEME = 'default';
const DOMAIN_FRONTEND = 'frontend';
const DOMAIN_BACKEND = 'backend';
protected $_blocks = array();
protected $_messageBlock = null;
@ -14,15 +17,37 @@ class Wootook_Core_Layout
protected $_eventPrefix = 'layout';
protected $_eventObject = 'layout';
protected $_domain = self::DOMAIN_FRONTEND;
protected $_package = self::DEFAULT_PACKAGE;
protected $_theme = self::DEFAULT_THEME;
protected $_namespaces = array(
'core' => array(
'Wootook_Core_Block_' => 'Wootook/core/Block'
'Wootook_Core_Block_' => 'Wootook/Core/Block'
)
);
public function __construct($domain = null, $package = null, $theme = null, Array $data = array())
{
if ($domain === null) {
if (Wootook::getDefaultWebsite()->getId() == 0) {
$this->_domain = self::DOMAIN_BACKEND;
} else {
$this->_domain = self::DOMAIN_FRONTEND;
}
} else {
$this->_domain = $domain;
}
if ($package !== null) {
$this->setPackage($package);
}
if ($theme !== null) {
$this->setTheme($theme);
}
parent::__construct($data);
}
public function _init()
{
$modules = Wootook_Core_Model_Config_Modules::getSingleton();
@ -33,22 +58,31 @@ class Wootook_Core_Layout
}
}
$fileList = Wootook::getConfig('layout');
$fileList = Wootook::getGameConfig('layout');
if ($fileList instanceof Wootook_Core_Config_Node) {
$fileList = $fileList->toArray();
}
if (!is_array($fileList) || empty($fileList)) {
$fileList = $this->getAllDatas();
} else {
$fileList = array_merge($fileList, $this->getAllDatas());
$fileList = array();
}
$this->_data = array();
$this->setPackage(Wootook::getConfig('package'));
$this->setTheme(Wootook::getConfig('theme'));
$this->setPackage(Wootook::getWebsiteConfig('package'));
$this->setTheme(Wootook::getGameConfig('theme'));
foreach ($fileList as $layoutFile) {
foreach (include $this->_getLayoutPath($layoutFile) as $layoutId => $layoutConfig) {
try {
$layoutData = include $this->_getLayoutPath($layoutFile);
} catch (Wootook_Core_Exception_LayoutException $e) {
Wootook_Core_ErrorProfiler::getSingleton()->addException($e);
continue;
}
if (!is_array($layoutData)) {
continue;
}
foreach ($layoutData as $layoutId => $layoutConfig) {
if ($this->hasData($layoutId)) {
$declared = $this->getData($layoutId);
@ -326,7 +360,7 @@ class Wootook_Core_Layout
$callParamaters[$paramterPosition] = $parameter->getDefaultValue();
//} else if (!$parameter->isOptionnal()) {
} else if ($paramterPosition <= $requiredParameterCount) {
throw new Wootook_Core_Exception_RuntimeException(Wootook::__('Method %s requires parameter %d ($%s) to be defined.',
throw new Wootook_Core_Exception_LayoutException(Wootook::__('Method %s requires parameter %d ($%s) to be defined.',
$reflectionMethod->getName(), $paramterPosition + 1, $paramterName));
}
}
@ -342,6 +376,19 @@ class Wootook_Core_Layout
}
}
public function getDomain()
{
return $this->_domain;
}
public function setDomain($domain)
{
$this->_domain = $domain;
$this->_init();
return $this;
}
public function getPackage()
{
return $this->_package;
@ -368,7 +415,7 @@ class Wootook_Core_Layout
public function getScriptPath()
{
return APPLICATION_PATH . DIRECTORY_SEPARATOR . 'design';
return APPLICATION_PATH . 'design' . DIRECTORY_SEPARATOR . $this->getDomain();
}
public function getBlock($code)
@ -382,7 +429,7 @@ class Wootook_Core_Layout
public function render()
{
if (!$this->_view instanceof Wootook_Core_View) {
throw new Wootook_Core_Exception_RuntimeException(Wootook::__('No root view declared.'));
throw new Wootook_Core_Exception_LayoutException(Wootook::__('No root view declared.'));
}
$scriptPath = $this->getScriptPath();
@ -403,14 +450,18 @@ class Wootook_Core_Layout
$theme = $this->getTheme();
$pattern = "{$this->getScriptPath()}/%s/%s/layouts/{$file}";
$path = sprintf($pattern, $package, $theme);
if (Wootook::fileExists($path)) {
return $path;
if ($package !== null && $theme !== null) {
$path = sprintf($pattern, $package, $theme);
if (Wootook::fileExists($path)) {
return $path;
}
}
$path = sprintf($pattern, $package, self::DEFAULT_THEME);
if (Wootook::fileExists($path)) {
return $path;
if ($package !== null) {
$path = sprintf($pattern, $package, self::DEFAULT_THEME);
if (Wootook::fileExists($path)) {
return $path;
}
}
$path = sprintf($pattern, self::DEFAULT_PACKAGE, self::DEFAULT_THEME);
@ -418,9 +469,7 @@ class Wootook_Core_Layout
return $path;
}
trigger_error(Wootook::__("Layout file '%s' does not exist.", $file), E_USER_NOTICE);
return null;
throw new Wootook_Core_Exception_LayoutException(sprintf("Layout file '%s' does not exist.", $file));
}
/**

View file

@ -70,7 +70,7 @@ abstract class Wootook_Core_Model
call_user_func_array(array($this, '_afterLoad'), $params);
$this->_setOriginalData($this->_data);
} catch (PDOException $e) {
throw new Wootook_Core_Exception_DataAccessException('Could not load data: ' . $e->getMessage(), 0);
throw new Wootook_Core_Exception_DataAccessException('Could not load data: ' . $e->getMessage(), 0, $e);
}
return $this;
}

View file

@ -6,7 +6,7 @@ abstract class Wootook_Core_Model_Config_Abstract
{
protected function _initData($filename)
{
$config = Wootook::getConfig('storyline');
$config = Wootook::getGameConfig('engine/storyline');
if ($config === null) {
$config = array(

View file

@ -11,7 +11,7 @@ class Wootook_Core_Model_Session
extends Wootook_Object
{
const CRIT = 0x80;
const ERROR = 0x40;
const ERR = 0x40;
const WARN = 0x20;
const INFO = 0x10;
const DEBUG = 0x01;
@ -19,21 +19,26 @@ class Wootook_Core_Model_Session
protected static $_instances = null;
protected static $_levels = null;
protected static $_levels = array(
self::CRIT => 'CRIT',
self::ERR => 'ERR',
self::WARN => 'WARN',
self::INFO => 'INFO',
self::DEBUG => 'DEBUG',
self::SUCCESS => 'SUCCESS'
);
const COOKIE_LIFETIME_CONFIG_KEY = 'web/session/time';
const COOKIE_DOMAIN_CONFIG_KEY = 'web/session/domain';
const COOKIE_PATH_CONFIG_KEY = 'web/session/path';
const IDENTIFIER_EXPIRES = '__expires';
const IDENTIFIER_MESSAGES = '__messages';
public static function factory($namespace)
{
$namespace = (string) $namespace;
if (!isset(self::$_instances[$namespace])) {
if (self::$_levels === null) {
$reflection = new ReflectionClass(__CLASS__);
self::$_levels = array_flip($reflection->getConstants());
}
self::$_instances[$namespace] = new self($namespace);
}
return self::$_instances[$namespace];
@ -49,22 +54,26 @@ class Wootook_Core_Model_Session
if (session_id() == '') {
session_set_cookie_params($this->getCookieLifetime(), $this->getCookiePath(), $this->getCookieDomain(), false, true);
session_start();
session_regenerate_id(true);
}
if (!isset($_SESSION[$namespace])) {
$_SESSION[$namespace] = array();
if (!isset($_SESSION[$namespace]) || !isset($_SESSION[$namespace][self::IDENTIFIER_EXPIRES]) || $_SESSION[$namespace][self::IDENTIFIER_EXPIRES] < time()) {
$_SESSION[$namespace] = array(
self::IDENTIFIER_EXPIRES => time() + $this->getCookieLifetime(),
self::IDENTIFIER_MESSAGES => array()
);
}
$this->_data = &$_SESSION[$namespace];
if (!isset($this->_data['messages'])) {
$this->_data['messages'] = array();
if (!isset($this->_data[self::IDENTIFIER_MESSAGES]) || !is_array($this->_data[self::IDENTIFIER_MESSAGES])) {
$this->_data[self::IDENTIFIER_MESSAGES] = array();
}
}
public function getCookieLifetime()
{
$lifetime = Wootook::getWebsiteConfig(self::COOKIE_LIFETIME_CONFIG_KEY);
if ($lifetime <= 0) {
if (!is_numeric($lifetime) || $lifetime <= 0) {
return 900;
}
@ -73,19 +82,27 @@ class Wootook_Core_Model_Session
public function getCookieDomain()
{
return Wootook::getWebsiteConfig(self::COOKIE_DOMAIN_CONFIG_KEY);
$domain = Wootook::getWebsiteConfig(self::COOKIE_DOMAIN_CONFIG_KEY);
if ($domain === null) {
return $_SERVER['SERVER_NAME'];
}
return $domain;
}
public function getCookiePath()
{
return Wootook::getWebsiteConfig(self::COOKIE_PATH_CONFIG_KEY);
$path = Wootook::getWebsiteConfig(self::COOKIE_PATH_CONFIG_KEY);
if ($path === null) {
return '/';
}
return $path;
}
public function getMessages($clear = true)
{
$messages = $this->_data['messages'];
$messages = $this->_data[self::IDENTIFIER_MESSAGES];
if ($clear == true) {
$this->_data['messages'] = array();
$this->_data[self::IDENTIFIER_MESSAGES] = array();
}
return $messages;
}
@ -96,13 +113,13 @@ class Wootook_Core_Model_Session
$type = self::DEBUG;
}
if (!isset($this->_data['messages'])) {
$this->_data['messages'] = array();
if (!isset($this->_data[self::IDENTIFIER_MESSAGES])) {
$this->_data[self::IDENTIFIER_MESSAGES] = array();
}
if (!isset($this->_data['messages'][self::$_levels[$type]])) {
$this->_data['messages'][self::$_levels[$type]] = array();
if (!isset($this->_data[self::IDENTIFIER_MESSAGES][self::$_levels[$type]])) {
$this->_data[self::IDENTIFIER_MESSAGES][self::$_levels[$type]] = array();
}
$this->_data['messages'][self::$_levels[$type]][] = $message;
$this->_data[self::IDENTIFIER_MESSAGES][self::$_levels[$type]][] = $message;
return $this;
}
@ -120,7 +137,7 @@ class Wootook_Core_Model_Session
$args = func_get_args();
array_shift($args);
return $this->addMessage(vsprintf($message, $args), self::ERROR);
return $this->addMessage(vsprintf($message, $args), self::ERR);
}
public function addWarning($message, $_ = null)

View file

@ -6,7 +6,7 @@ class Wootook_Core_Time
public static function init($timezone = null)
{
if ($timezone === null) {
$timezone = Wootook::getConfig('date/timezone');
$timezone = Wootook::getConfig('system/date/timezone');
}
if ($timezone === null) {
$timezone = 'GMT';

View file

@ -129,34 +129,51 @@ class Wootook_Core_View
return Wootook::getUrl($uri, $params);
}
public function getSkinUrl($uri, Array $params = array())
public function getSkinUrl($uri, Array $params = array(), $theme = null, $package = null)
{
$package = $this->getLayout()->getPackage();
if (empty($package)) {
$package = Wootook_Core_Layout::DEFAULT_PACKAGE;
}
$user = Wootook_Empire_Model_User::getSingleton();
if ($user !== null && $user->getId()) {
$theme = $user->getSkinPath();
}
if (empty($theme)) {
if ($theme === null || empty($theme)) {
$theme = $this->getLayout()->getTheme();
}
if (empty($theme)) {
if ($theme === null || empty($theme)) {
$theme = Wootook_Core_Layout::DEFAULT_THEME;
}
$pattern = ROOT_PATH . DIRECTORY_SEPARATOR . 'skin/%s/%s/{$uri}';
if (Wootook::fileExists(sprintf($pattern, $package, $theme))) {
return Wootook::getSkinUrl($package, $theme, $uri, $params);
if ($package === null || empty($package)) {
$package = $this->getLayout()->getPackage();
}
if (Wootook::fileExists(sprintf($pattern, $package, Wootook_Core_Layout::DEFAULT_THEME))) {
return Wootook::getSkinUrl($package, Wootook_Core_Layout::DEFAULT_THEME, $uri, $params);
if ($package === null || empty($package)) {
$package = Wootook_Core_Layout::DEFAULT_PACKAGE;
}
$domain = $this->getLayout()->getDomain();
$baseUrl = Wootook::getBaseUrl('skin');
$basePath = Wootook::getBasePath('skin');
$pathPattern = $basePath . "{$domain}/%s/%s/{$uri}";
$urlPattern = $baseUrl . "{$domain}/%s/%s/{$uri}";
if (count($params) > 0) {
$serializedParams = array();
foreach ($params as $paramKey => $paramValue) {
if ($paramValue) {
$serializedParams[] = "{$paramKey}={$paramValue}";
}
}
$urlPattern .= '?' . implode('&', $serializedParams);
}
return Wootook::getSkinUrl(Wootook_Core_Layout::DEFAULT_PACKAGE, Wootook_Core_Layout::DEFAULT_THEME, $uri, $params);
if (Wootook::fileExists(sprintf($pathPattern, $package, $theme))) {
return sprintf($urlPattern, $package, $theme);
}
if (Wootook::fileExists(sprintf($pathPattern, $package, Wootook_Core_Layout::DEFAULT_THEME))) {
return sprintf($urlPattern, $package, Wootook_Core_Layout::DEFAULT_THEME);
}
return sprintf($urlPattern, Wootook_Core_Layout::DEFAULT_PACKAGE, Wootook_Core_Layout::DEFAULT_THEME);
}
public function setPartial($name, $content)
@ -172,6 +189,9 @@ class Wootook_Core_View
public function getPartial($name)
{
if (!$this->hasPartial($name)) {
return null;
}
return $this->_partials[$name];
}

View file

@ -161,16 +161,16 @@ INSERT IGNORE INTO {$this->getTableName('core_config')} (`website_id`, `game_id`
(1, 1, 'game/noob-protection/points-cap', '5000'),
(1, 1, 'game/noob-protection/multiplier', '5'),
(0, 0, 'web/cookie/name', '__wtk'),
(0, 0, 'web/cookie/time', '2592000'),
(0, 0, 'web/cookie/domain', ''),
(0, 0, 'web/cookie/path', ''),
-- (0, 0, 'web/cookie/name', '__wtk'),
-- (0, 0, 'web/cookie/time', '2592000'),
-- (0, 0, 'web/cookie/domain', ''),
-- (0, 0, 'web/cookie/path', ''),
(1, 1, 'web/cookie/name', '__wtk_1_1'),
(0, 0, 'web/session/time', '900'),
(0, 0, 'web/session/domain', '.wootook.org'),
(0, 0, 'web/session/path', '/'),
-- (0, 0, 'web/session/time', '900'),
-- (0, 0, 'web/session/domain', '.wootook.org'),
-- (0, 0, 'web/session/path', '/'),
(0, 0, 'engine/options/bbcode', '1'),
(0, 0, 'engine/options/ga', '1'),

View file

@ -38,47 +38,64 @@ class Wootook_Database
return self::$_connectionAliases[$connectionName];
}
if ($alias = Wootook::getConfig("database/{$connectionName}/use")) {
$connectionConfig = Wootook::getConfig("resource/database/{$connectionName}");
if ($alias = $connectionConfig->use) {
self::$_connectionAliases[$connectionName] = self::getConnection($alias);
return self::$_connectionAliases[$connectionName];
}
self::$_connections[$connectionName] = self::_initConnection($connectionName);
self::$_connections[$connectionName] = self::_initConnection($connectionName,
$connectionConfig->engine, $connectionConfig->params, $connectionConfig->options);
}
return self::$_connections[$connectionName];
}
private static function _initConnection($connectionName)
private static function _initConnection($connectionName, $engine, $params, $options = array())
{
$hostname = Wootook::getConfig("database/{$connectionName}/params/hostname");
$username = Wootook::getConfig("database/{$connectionName}/params/username");
$password = Wootook::getConfig("database/{$connectionName}/params/password");
$database = Wootook::getConfig("database/{$connectionName}/params/database");
if (is_array($params)) {
$params = new Wootook_Core_Config_Node($params);
} else if (!$params instanceof Wootook_Core_Config_Node) {
$params = new Wootook_Core_Config_Node(array());
}
if (empty($hostname) || empty($username) || empty($database)) {
if ($options instanceof Wootook_Core_Config_Node) {
$options = $options->toArray();
} else if (!is_array($options)) {
$options = array();
}
$hostname = $params->hostname;
$username = $params->username;
$password = $params->password;
$database = $params->database;
if (empty($params->hostname) || empty($params->username) || empty($params->database)) {
return null;
}
$dsn = "mysql:dbname={$database};host={$hostname}";
if (($port = Wootook::getConfig("database/{$connectionName}/params/port")) && is_numeric($port)) {
$dsn .= ";port={$port}";
$dsn = "mysql:dbname={$params->database};host={$params->hostname}";
if (is_numeric($params->port)) {
$dsn .= ";port={$params->database}";
}
$event = Wootook::dispatchEvent('database.prepare-options', array(
'name' => $connectionName,
'options' => array_merge(self::$options, Wootook::getConfig("database/{$connectionName}/options")->toArray())
'options' => array_merge(self::$options, $options)
));
$options = $event->getData('options');
$connection = new self($dsn, $username, $password, $options);
$connection = new self($dsn, $params->username, $params->password, $options);
$connection->_dsn = $dsn;
$connection->_username = $username;
$connection->_password = $password;
if (($prefix = Wootook::getConfig("database/{$connectionName}/table_prefix")) !== null) {
if (defined('DEBUG')) {
$connection->_password = $password;
}
if (($prefix = Wootook::getConfig("resource/database/{$connectionName}/table_prefix")) !== null) {
$connection->setTablePrefix($prefix);
}

View file

@ -98,7 +98,7 @@ abstract class Wootook_Empire_Block_Planet_Builder_ItemAbstract
$lang = includeLang('imperium');
}
if ($resourceId == 'cristal') {
$resourceId = 'crystal';
$resourceId = 'crystal'; // FIXME: backward compatibility
}
if (isset($lang[$resourceId])) {

View file

@ -160,12 +160,12 @@ class Wootook_Empire_Model_Planet
public function getLastUpdate()
{
return $this->getData('last_update');
return strtotime($this->getData('last_update'));
}
public function setLastUpdate($time)
{
return $this->setData('last_update', $time);
return $this->setData('last_update', date('Y-m-d G:i:s', $time));
}
public function getBuildingFields()
@ -199,8 +199,8 @@ class Wootook_Empire_Model_Planet
continue;
}
if ($this->getElement($resourceData['storage'])) {
$storageEnhancementFactor = Math::floor(Math::pow(1.6, $this->getElement($resourceData['storage'])));
if ($this->getElement($resourceData['storage_field'])) {
$storageEnhancementFactor = Math::floor(Math::pow(1.6, $this->getElement($resourceData['storage_field'])));
$storageEnhancement = Math::mul(BASE_STORAGE_SIZE / 2, $storageEnhancementFactor);
} else {
$storageEnhancement = 0;
@ -987,7 +987,7 @@ class Wootook_Empire_Model_Planet
$planet->updateBuildingQueue($time);
$planet->updateResources($time);
$planet->getShipyard()->updateQueue($time);
$planet->getShipyard()->updateQueue($time); // FIXME
$planet->setLastUpdate($time);
}
}

View file

@ -58,11 +58,11 @@ class Wootook_Empire_Model_Planet_Builder
{
$types = Wootook_Empire_Model_Game_Types::getSingleton();
if ($types->is($buildingId, Legacies_Empire::TYPE_BUILDING)) {
return true;
if (!$types->is($buildingId, Legacies_Empire::TYPE_BUILDING)) {
return false;
}
return false;
return true;
}
public function getBuildingTime($buildingId, $level)