Commits

root <>  committed a4eca6a

Refactoring

  • Participants
  • Parent commits 2838151

Comments (0)

Files changed (35)

File .hgignore

-syntax: regexp
-^www/(css|img|js)
-^www/system/app
-^nbproject
+<?php
+// cheack access
+if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
+    die('You are not allowed to access this file.');
+}
+
+// start timer
+$startTime = microtime(true);
+
+// initialize application
+require_once dirname(__FILE__) . '/system/init.php';
+
+// go
+Zend_Registry::get('zendApplication')
+        ->bootstrap()
+        ->run();
+
+if (SYSTEM_LOG) {
+    $stopTime = microtime(true);
+    Zend_Registry::get('zendLog')->debug('Final time: ' . ($stopTime - $startTime) . PHP_EOL);
+}

File www/index.php

 $startTime = microtime(true);
 
 // set environment
-define('SYSTEM_ENV', 'prod');
+define('APPLICATION_ENV', 'prod');
 
 // initialize application
 require_once dirname(__FILE__) . '/system/init.php';
 
 // go
-Zend_Registry::get('zendApp')
+Zend_Registry::get('zendApplication')
         ->bootstrap()
         ->run();
 

File www/index_dev.php

-<?php
-// cheack access
-if (!in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', '::1'))) {
-    die('You are not allowed to access this file.');
-}
-
-// start timer
-$startTime = microtime(true);
-
-// initialize application
-require_once dirname(__FILE__) . '/system/init.php';
-
-// go
-Zend_Registry::get('zendApp')
-        ->bootstrap()
-        ->run();
-
-if (SYSTEM_LOG) {
-    $stopTime = microtime(true);
-    Zend_Registry::get('zendLog')->debug('Final time: ' . ($stopTime - $startTime) . PHP_EOL);
-}

File www/system/init.php

 date_default_timezone_set('UTC');
 
 // define environment
-if (!defined('SYSTEM_ENV')) {
-    define('SYSTEM_ENV', 'dev');
+if (!defined('APPLICATION_ENV')) {
+    define('APPLICATION_ENV', 'dev');
 }
 
 // system pathes
 define('MODULES_DIR', SYSTEM_DIR . '/modules');
 
 // application specific pathes
-define('APP_DIR', SYSTEM_DIR . '/app');
-define('CONFIGS_DIR', APP_DIR . '/configs');
-define('LOGS_DIR', APP_DIR . '/logs');
-define('CACHE_DIR', APP_DIR . '/cache');
+define('APPLICATION_DIR', SYSTEM_DIR . '/application');
+define('CONFIGS_DIR', APPLICATION_DIR . '/configs');
+define('LOGS_DIR', APPLICATION_DIR . '/logs');
+define('CACHE_DIR', APPLICATION_DIR . '/cache/' . APPLICATION_ENV);
 
 // Zend Framework requires library dir to be on include_path
 set_include_path(LIBRARY_DIR);
         ));
 
 // load cache if exists
-if ('prod' === SYSTEM_ENV) {
-    $cacheFile = CACHE_DIR . '/include.php';
-    if (file_exists($cacheFile)) {
-        require $cacheFile;
-    } else {
-        Neno_Loader::getInstance()
-                ->setTrackFiles(true)
-                ->addTrackDir(LIBRARY_DIR)
-                ->addIgnoreDir(LIBRARY_DIR . '/yaml')
-                ->setCacheFile($cacheFile);
-    }
-} else {
-    $cacheFile = CACHE_DIR . '/include.php';
-    if (file_exists($cacheFile)) {
-        require $cacheFile;
-    }
-    Neno_Loader::getInstance()
-            ->setTrackFiles(true)
-            ->addTrackDir(LIBRARY_DIR)
-            ->addIgnoreDir(LIBRARY_DIR . '/yaml')
-            ->setCacheFile($cacheFile);
-}
+//if ('prod' === APPLICATION_ENV) {
+//    $cacheFile = CACHE_DIR . '/include.php';
+//    if (file_exists($cacheFile)) {
+//        require $cacheFile;
+//    } else {
+//        Neno_Loader::getInstance()
+//                ->setTrackFiles(true)
+//                ->addTrackDir(LIBRARY_DIR)
+//                ->addIgnoreDir(LIBRARY_DIR . '/yaml')
+//                ->setCacheFile($cacheFile);
+//    }
+//} else {
+//    $cacheFile = CACHE_DIR . '/include.php';
+//    if (file_exists($cacheFile)) {
+//        require $cacheFile;
+//    }
+//    Neno_Loader::getInstance()
+//            ->setTrackFiles(true)
+//            ->addTrackDir(LIBRARY_DIR)
+//            ->addIgnoreDir(LIBRARY_DIR . '/yaml')
+//            ->setCacheFile($cacheFile);
+//}
 
 // disable Zend_Loader_Autoloader
 Zend_Loader_Autoloader::getInstance();
 }
 
 // inject toolkit to Zend_Registry to initialize system
-Zend_Registry::setInstance(new ZendY_Registry_Toolkit());
-$toolkit = Zend_Registry::getInstance();
-$toolkit
-    ->addTool(new Neno_Tool())
-    ->addTool(new ZendY_Tool());
+$registry = new ZendY_Registry();
+$registry
+        ->appendToolkit(new Neno_Toolkit())
+        ->appendToolkit(new ZendY_Toolkit());
+
+Zend_Registry::setInstance($registry);

File www/system/library/Neno/ConfigLoader.php

     public function load($dirs, $file)
     {
         if ($this->logger) {
-            $this->logger->debug("Loading {$file}...");
+            $this->logger->debug(sprintf('Loading %s...', $file));
         }
 
         $config = array();
 
         foreach ((array) $dirs as $dir) {
             $files = array(
-                "{$dir}/{$file}",
-                $dir . '/' . $this->injectEnv($file),
+                sprintf('%s/%s', $dir, $file),
+                sprintf('%s/%s', $dir, $this->injectEnv($file)),
             );
 
             foreach ($files as $filepath) {
                         $config = Neno_Utils::merge($config, $r);
 
                         if ($this->logger) {
-                            $this->logger->debug("    {$filepath}");
+                            $this->logger->debug(sprintf('    ', $filepath));
                         }
                     }
                 }

File www/system/library/Neno/Tool.php

-<?php
-class Neno_Tool extends ZendY_Registry_Tool
-{
-    public function httpHostTool()
-    {
-        return isset($_SERVER['HTTP_HOST']) ? ltrim($_SERVER['HTTP_HOST'], 'www.') : null;
-    }
-
-    public function httpUrlTool()
-    {
-        return 'http://' . Zend_Registry::get('httpHost');
-    }
-
-    public function httpRefererTool()
-    {
-        return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
-    }
-
-    public function requestUriTool()
-    {
-        return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
-    }
-
-    public function documentRootTool()
-    {
-        return $_SERVER['DOCUMENT_ROOT'];
-    }
-
-    public function defaultLangTool()
-    {
-        return Zend_Registry::get('appConfig')->settings->defaultLang;
-    }
-
-    public function langsTool()
-    {
-        return Zend_Registry::get('appConfig')->settings->langs->toArray();
-    }
-
-    public function configCacheTool()
-    {
-        return Zend_Cache::factory(
-            'Core',
-            Zend_Registry::get('zendCacheBackend'),
-            array(
-                'caching' => defined('SYSTEM_CACHE')
-                        ? SYSTEM_CACHE
-                        : SYSTEM_ENV == 'prod',
-                'lifetime' => null,
-                'automatic_serialization' => true,
-            ),
-            array(),
-            false,
-            false,
-            true
-        );
-    }
-
-    public function configTool()
-    {
-        $cache = Zend_Registry::get('configCache');
-        if (!($config = $cache->load('config'))) {
-            $configDirs = array(CONFIGS_DIR);
-            $loader = new Neno_ConfigLoader(SYSTEM_ENV);
-
-            $config['app'] = $loader->load($configDirs, 'app.yml');
-            foreach ($config['app']['modules'] as $moduleName) {
-                $configDirs[] = MODULES_DIR . "/{$moduleName}/configs";
-            }
-
-            if ($config['app']['settings']['log']) {
-                $loader->setLogger(Zend_Registry::get('zendLog'));
-            }
-            if (isset($config['app']['phpSettings']['date.timezone'])) {
-                ini_set('date.timezone', $config['app']['phpSettings']['date.timezone']);
-            }
-
-            $config['app'] = $loader->load($configDirs, 'app.yml');
-            $config['routes'] = $loader->load($configDirs, 'routes.yml');
-            $config['view'] = $loader->load($configDirs, 'view.yml');
-            $config['acl'] = $loader->load($configDirs, 'acl.yml');
-
-            foreach ($config['app']['modules'] as $moduleName) {
-                $config['app']['resources']['frontController']['controllerDirectory'][$moduleName]
-                        = MODULES_DIR . "/{$moduleName}/controllers";
-            }
-
-            $cache->save($config);
-        }
-
-        define('SYSTEM_CACHE', $config['app']['settings']['cache']);
-        define('SYSTEM_LOG', $config['app']['settings']['log']);
-
-        return $config;
-    }
-
-    public function appConfigTool()
-    {
-        $config = Zend_Registry::get('config');
-        return new Zend_Config($config['app']);
-    }
-
-    public function routesConfigTool()
-    {
-        $config = Zend_Registry::get('config');
-        return new Zend_Config($config['routes']);
-    }
-
-    public function viewConfigTool()
-    {
-        $config = Zend_Registry::get('config');
-        return $config['view'];
-    }
-
-    public function aclConfigTool()
-    {
-        $config = Zend_Registry::get('config');
-        return $config['acl'];
-    }
-
-    public function userTool()
-    {
-        $auth = Zend_Auth::getInstance();
-        if ($auth->hasIdentity()) {
-            $user = Identity_User::factory($auth->getIdentity());
-        } else {
-            $user = new Identity_User();
-        }
-
-        if (SYSTEM_LOG) {
-            $user->setLogger(Zend_Registry::get('zendLog'));
-        }
-
-        return $user;
-    }
-}

File www/system/library/Neno/Toolkit.php

+<?php
+class Neno_Toolkit
+{
+    public function getHttpHost()
+    {
+        return isset($_SERVER['HTTP_HOST']) ? ltrim($_SERVER['HTTP_HOST'], 'www.') : null;
+    }
+
+    public function getHttpUrl()
+    {
+        return 'http://' . Zend_Registry::get('httpHost');
+    }
+
+    public function getHttpReferer()
+    {
+        return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
+    }
+
+    public function getRequestUri()
+    {
+        return isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
+    }
+
+    public function getDocumentRoot()
+    {
+        return $_SERVER['DOCUMENT_ROOT'];
+    }
+
+    public function getDefaultLang()
+    {
+        return Zend_Registry::get('applicationConfig')->settings->defaultLang;
+    }
+
+    public function getLangs()
+    {
+        return Zend_Registry::get('applicationConfig')->settings->langs->toArray();
+    }
+
+    public function getConfigCache()
+    {
+        return Zend_Cache::factory(
+            'Core',
+            Zend_Registry::get('zendCacheBackend'),
+            array(
+                'caching' => defined('SYSTEM_CACHE')
+                        ? SYSTEM_CACHE
+                        : APPLICATION_ENV == 'prod',
+                'lifetime' => null,
+                'automatic_serialization' => true,
+            ),
+            array(),
+            false,
+            false,
+            true
+        );
+    }
+
+    public function getConfig()
+    {
+        $cache = Zend_Registry::get('configCache');
+        if (!($config = $cache->load('config'))) {
+            $configDirs = array(CONFIGS_DIR);
+            $loader = new Neno_ConfigLoader(APPLICATION_ENV);
+
+            $config['application'] = $loader->load($configDirs, 'app.yml');
+            foreach ($config['application']['modules'] as $moduleName) {
+                $configDirs[] = MODULES_DIR . "/{$moduleName}/configs";
+            }
+
+            if ($config['application']['settings']['log']) {
+                $loader->setLogger(Zend_Registry::get('zendLog'));
+            }
+            if (isset($config['application']['phpSettings']['date.timezone'])) {
+                ini_set('date.timezone', $config['app']['phpSettings']['date.timezone']);
+            }
+
+            $config['application'] = $loader->load($configDirs, 'app.yml');
+            $config['routes'] = $loader->load($configDirs, 'routes.yml');
+            $config['view'] = $loader->load($configDirs, 'view.yml');
+            $config['acl'] = $loader->load($configDirs, 'acl.yml');
+
+            foreach ($config['application']['modules'] as $moduleName) {
+                $config['application']['resources']['frontController']['controllerDirectory'][$moduleName]
+                        = MODULES_DIR . "/{$moduleName}/controllers";
+            }
+
+            $cache->save($config);
+        }
+
+        define('SYSTEM_CACHE', $config['application']['settings']['cache']);
+        define('SYSTEM_LOG', $config['application']['settings']['log']);
+
+        return $config;
+    }
+
+    public function getApplicationConfig()
+    {
+        $config = Zend_Registry::get('config');
+        return new Zend_Config($config['application']);
+    }
+
+    public function getRoutesConfig()
+    {
+        $config = Zend_Registry::get('config');
+        return new Zend_Config($config['routes']);
+    }
+
+    public function getViewConfig()
+    {
+        $config = Zend_Registry::get('config');
+        return $config['view'];
+    }
+
+    public function getAclConfig()
+    {
+        $config = Zend_Registry::get('config');
+        return $config['acl'];
+    }
+
+    public function getUser()
+    {
+        $auth = Zend_Auth::getInstance();
+        if ($auth->hasIdentity()) {
+            $user = Identity_User::factory($auth->getIdentity());
+        } else {
+            $user = new Identity_User();
+        }
+
+        if (SYSTEM_LOG) {
+            $user->setLogger(Zend_Registry::get('zendLog'));
+        }
+
+        return $user;
+    }
+}

File www/system/library/ZendY/Registry.php

+<?php
+class ZendY_Registry extends Zend_Registry
+{
+    protected $toolkits = array();
+
+    public function setToolkits($toolkits)
+    {
+        $this->toolkits = $toolkits;
+        return $this;
+    }
+
+    public function appendToolkit($toolkit)
+    {
+        $this->toolkits[] = $toolkit;
+        return $this;
+    }
+
+    public function prependToolkit($toolkit)
+    {
+        array_unshift($this->toolkits, $toolkit);
+        return $this;
+    }
+
+    public function offsetExists($index)
+    {
+        if (parent::offsetExists($index)) {
+            return true;
+        } else {
+            foreach ($this->toolkits as $toolkit) {
+                $method = 'get' . $index;
+                if (method_exists($toolkit, $method)) {
+                    $this->offsetSet($index, $toolkit->$method());
+                    return true;
+                }
+            }
+            return false;
+        }
+    }
+}

File www/system/library/ZendY/Registry/Tool.php

-<?php
-
-class ZendY_Registry_Tool
-{
-    protected $_previous = null;
-
-    public function setPrevious(ZendY_Registry_Tool $previous)
-    {
-        if ($this->_previous) {
-            $this->_previous->setPrevious($previous);
-        } else {
-            $this->_previous = $previous;
-        }
-        return $this;
-    }
-
-    public function getPrevious()
-    {
-        return $this->_previous;
-    }
-
-    public function __construct(ZendY_Registry_Tool $previous = null)
-    {
-        if (null !== $previous) {
-            $this->setPrevious($previous);
-        }
-    }
-
-    public function __call($method, $args)
-    {
-        if (null !== $this->_previous) {
-            return $this->_previous->$method();
-        } else {
-            throw new ZendY_Registry_Tool_Exception('Undefined tool "' . $method . '"');
-        }
-    }
-
-    public function get($index)
-    {
-        $method = $index . 'Tool';
-        return $this->$method();
-    }
-}

File www/system/library/ZendY/Registry/Tool/Exception.php

-<?php
-
-class ZendY_Registry_Tool_Exception extends Exception
-{}

File www/system/library/ZendY/Registry/Toolkit.php

-<?php
-class ZendY_Registry_Toolkit extends Zend_Registry
-{
-    protected $_tool = null;
-
-    public function setTool(ZendY_Registry_Tool $tool)
-    {
-        $this->_tool = $tool;
-        return $this;
-    }
-
-    public function getTool()
-    {
-        return $this->_tool;
-    }
-
-    public function addTool(ZendY_Registry_Tool $tool)
-    {
-        if ($this->_tool) {
-            $tool->setPrevious($this->_tool);
-        }
-        $this->_tool = $tool;
-        return $this;
-    }
-
-    public function emptyTool()
-    {
-        $this->_tool = null;
-        return $this;
-    }
-
-    public function offsetExists($index)
-    {
-        if (parent::offsetExists($index)) {
-            return true;
-        } else {
-            try {
-                $this->offsetSet($index, $this->_tool->get($index));
-                return true;
-            } catch (ZendY_Registry_Tool_Exception $e) {
-                return false;
-            }        
-        }
-    }
-}

File www/system/library/ZendY/Tool.php

-<?php
-class ZendY_Tool extends ZendY_Registry_Tool
-{
-    public function langTool()
-    {
-        $request = Zend_Controller_Front::getInstance()->getRequest();
-        if (null === $request) {
-            throw new Exception('Can not define lang as $request object is not initialized yet');
-        }
-
-        if (null !== ($lang = $request->getParam('lang'))) {
-            return $lang;
-        } else {
-            return Zend_Registry::get('defaultLang');
-        }
-    }
-
-    public function zendAclTool()
-    {
-        $acl = new Zend_Acl();
-
-        $aclConfig = Zend_Registry::get('aclConfig');
-
-        foreach ($aclConfig as $role => $resources) {
-            if (!$acl->hasRole($role)) {
-                $acl->addRole($role);
-            }
-
-            foreach ($resources as $resource => $resourceInfo) {
-                if (!$acl->has($resource)) {
-                    $acl->add(new Zend_Acl_Resource($resource));
-                }
-
-                if (isset($resourceInfo['allow'])) {
-                    if ($resourceInfo['allow']) {
-                        $acl->allow($role, $resource);
-                    } else {
-                        $acl->deny($role, $resource);
-                    }
-                }
-
-                if (isset($resourceInfo['privileges'])) {
-                    foreach ($resourceInfo['privileges'] as $privilege => $allow) {
-                        if ($allow) {
-                            $acl->allow($role, $resource, $privilege);
-                        } else {
-                            $acl->deny($role, $resource, $privilege);
-                        }
-                    }
-                }
-            }
-        }
-
-        $acl->addRole('admin');
-        $acl->allow('admin');
-
-        return $acl;
-    }
-
-    public function zendAppTool()
-    {
-        $application = new Zend_Application(
-            SYSTEM_ENV,
-            Zend_Registry::get('appConfig')
-        );
-
-        if (SYSTEM_LOG) {
-            $logger = Zend_Registry::get('zendLog');
-            $logger->debug('Application loaded');
-            $logger->debug('  environment: ' . SYSTEM_ENV);
-            $logger->debug('  error_reporting: ' . ini_get('error_reporting'));
-            $logger->debug('  display_errors: ' . (ini_get('display_errors')
-                    ? 'true'
-                    : 'false'));
-            $logger->debug(sprintf('  modules: [ %s ]', implode(', ',
-                    Zend_Registry::get('appConfig')->modules->toArray())));
-        }
-
-        return $application;
-    }
-
-    public function zendLogTool()
-    {
-        $logger = new Zend_Log();
-        $logger->setEventItem('requestUri', Zend_Registry::get('requestUri'));
-
-        $format = '%priorityName% (%priority%): %message%' . PHP_EOL;
-        $formatter = new Zend_Log_Formatter_Simple($format);
-
-        $writer = new Zend_Log_Writer_Stream(LOGS_DIR . '/system.log');
-        $writer->setFormatter($formatter);
-        $logger->addWriter($writer);
-
-        $holder = new ZendY_Log_Writer_Holder();
-        $holder->setFormatter($formatter);
-        $logger->addWriter($holder);
-        Zend_Registry::set('holderWriter', $holder);
-
-        return $logger;
-    }
-
-    public function zendDbTool()
-    {
-        return Zend_Registry::get('zendApp')
-                ->getBootstrap()
-                ->getPluginResource('db')
-                ->getDbAdapter();
-    }
-
-    public function zendLogFirebugTool()
-    {
-        $writer = new Zend_Log_Writer_Firebug();
-        $logger = new Zend_Log($writer);
-
-        return $logger;
-    }
-
-    public function zendLocaleTool()
-    {
-        Zend_Locale::setCache(Zend_Registry::get('configCache'));
-
-        return new Zend_Locale(
-            Zend_Registry::get('lang')
-        );
-    }
-
-    public function zendTranslateTool()
-    {
-        $zendLocale = Zend_Registry::get('zendLocale');
-
-        $translator = new ZendY_Translate(
-            'array',
-            array(),
-            (string) $zendLocale,
-            array(
-                'scan' => Zend_Translate::LOCALE_DIRECTORY,
-                'disableNotices' => true,
-            )
-        );
-        $translator->setDefault(Zend_Registry::get('langs'));
-
-        $cache = Zend_Registry::get('configCache');
-        $cacheId = 'translate' . (string) $zendLocale;
-        $data = $cache->load($cacheId);
-        if ($data) {
-            foreach ($data as $locale => $messages) {
-                $translator->addTranslation(array(
-                    'content' => $messages,
-                    'locale' => $locale,
-                ));
-            }
-        } else {
-            if (SYSTEM_LOG) {
-                Zend_Registry::get('zendLog')->debug('Loading translation...');
-            }
-
-            $translator->addTranslation(array(
-                'content' => RESOURCES_DIR . '/language',
-                'locale' => null,
-            ));
-
-            $modules = Zend_Registry::get('appConfig')->modules;
-            foreach ($modules as $moduleName) {
-                $translationDir = MODULES_DIR . "/{$moduleName}/i18n";
-                if (file_exists($translationDir)) {
-                    $translator->addTranslation(array(
-                        'content' => $translationDir,
-                        'locale' => null,
-                    ));
-
-                    if (SYSTEM_LOG) {
-                        Zend_Registry::get('zendLog')->debug('  dir: ' . $translationDir);
-                    }
-                }
-            }
-
-            $cache->save($translator->getMessages('all'));
-        }
-
-        return $translator;
-    }
-
-    public function zendCacheBackendFileTool()
-    {
-        return new Zend_Cache_Backend_File(array(
-            'cache_dir' => CACHE_DIR,
-        ));
-    }
-
-    public function zendCacheBackendTool()
-    {
-        return Zend_Registry::get('zendCacheBackendFile');
-    }
-}

File www/system/library/ZendY/Tool/Manifest.php

     public function getProviders()
     {
         return array(
-            new ZendY_Tool_Provider_Doctrine(),
             new ZendY_Tool_Provider_Clean(),
             new ZendY_Tool_Provider_Modules(),
         );

File www/system/library/ZendY/Tool/Provider/AbstractProvider.php

         extends Zend_Tool_Framework_Provider_Abstract
         implements Zend_Tool_Framework_Provider_Pretendable
 {
+    protected static $initialized = false;
+
     protected function initialize()
     {
-        if (Zend_Registry::isRegistered('zendApp')) {
+        if (self::$initialized) {
             return false;
         }
+        self::$initialized = true;
 
-        $file = dirname($_SERVER['PHP_SELF']) . '/../app/init.php';
+        $file = dirname($_SERVER['PHP_SELF']) . '/../init.php';
         require_once $file;
 
-        $application = Zend_Registry::get('zendApp');
+        $application = Zend_Registry::get('zendApplication');
         $application->bootstrap();
 
-        $config = Zend_Registry::get('appConfig')->doctrine;
+        $config = Zend_Registry::get('applicationConfig')->doctrine;
         $manager = Doctrine_Manager::getInstance();
         $manager->closeConnection($manager->getConnection('default'));
         $manager->openConnection($config->dsn, 'default');

File www/system/library/ZendY/Tool/Provider/Modules.php

     protected function getModules($modules)
     {
         if ('' === $modules) {
-            return Zend_Registry::get('appConfig')->modules;
+            return Zend_Registry::get('applicationConfig')->modules;
         } else {
             return explode(', ', $modules);
         }

File www/system/library/ZendY/Toolkit.php

+<?php
+class ZendY_Toolkit
+{
+    public function getLang()
+    {
+        $request = Zend_Controller_Front::getInstance()->getRequest();
+        if (null === $request) {
+            throw new Exception('Can not define lang as $request object is not initialized yet');
+        }
+
+        if (null !== ($lang = $request->getParam('lang'))) {
+            return $lang;
+        } else {
+            return Zend_Registry::get('defaultLang');
+        }
+    }
+
+    public function getZendAcl()
+    {
+        $acl = new ZendY_Acl();
+
+        $aclConfig = Zend_Registry::get('aclConfig');
+
+        foreach ($aclConfig as $role => $resources) {
+            if (!$acl->hasRole($role)) {
+                $acl->addRole($role);
+            }
+
+            foreach ($resources as $resource => $resourceInfo) {
+                if (!$acl->has($resource)) {
+                    $acl->add(new Zend_Acl_Resource($resource));
+                }
+
+                if (isset($resourceInfo['allow'])) {
+                    if ($resourceInfo['allow']) {
+                        $acl->allow($role, $resource);
+                    } else {
+                        $acl->deny($role, $resource);
+                    }
+                }
+
+                if (isset($resourceInfo['privileges'])) {
+                    foreach ($resourceInfo['privileges'] as $privilege => $allow) {
+                        if ($allow) {
+                            $acl->allow($role, $resource, $privilege);
+                        } else {
+                            $acl->deny($role, $resource, $privilege);
+                        }
+                    }
+                }
+            }
+        }
+
+        $acl->addRole('admin');
+        $acl->allow('admin');
+
+        return $acl;
+    }
+
+    public function getZendApplication()
+    {
+        $application = new Zend_Application(
+            APPLICATION_ENV,
+            Zend_Registry::get('applicationConfig')
+        );
+
+        if (SYSTEM_LOG) {
+            $logger = Zend_Registry::get('zendLog');
+            $logger->debug('Application loaded');
+            $logger->debug('  environment: ' . APPLICATION_ENV);
+            $logger->debug('  error_reporting: ' . ini_get('error_reporting'));
+            $logger->debug('  display_errors: ' . (ini_get('display_errors')
+                    ? 'true'
+                    : 'false'));
+            $logger->debug(sprintf('  modules: [ %s ]', implode(', ',
+                    Zend_Registry::get('applicationConfig')->modules->toArray())));
+        }
+
+        return $application;
+    }
+
+    public function getZendLog()
+    {
+        $logger = new Zend_Log();
+        $logger->setEventItem('requestUri', Zend_Registry::get('requestUri'));
+
+        $format = '%priorityName% (%priority%): %message%' . PHP_EOL;
+        $formatter = new Zend_Log_Formatter_Simple($format);
+
+        $writer = new Zend_Log_Writer_Stream(LOGS_DIR . '/system.log');
+        $writer->setFormatter($formatter);
+        $logger->addWriter($writer);
+
+        $holder = new ZendY_Log_Writer_Holder();
+        $holder->setFormatter($formatter);
+        $logger->addWriter($holder);
+        Zend_Registry::set('holderWriter', $holder);
+
+        return $logger;
+    }
+
+    public function getZendDb()
+    {
+        return Zend_Registry::get('zendApplication')
+                ->getBootstrap()
+                ->getPluginResource('db')
+                ->getDbAdapter();
+    }
+
+    public function getZendLogFirebug()
+    {
+        $writer = new Zend_Log_Writer_Firebug();
+        $logger = new Zend_Log($writer);
+
+        return $logger;
+    }
+
+    public function getZendLocale()
+    {
+        Zend_Locale::setCache(Zend_Registry::get('configCache'));
+
+        return new Zend_Locale(
+            Zend_Registry::get('lang')
+        );
+    }
+
+    public function getZendTranslate()
+    {
+        $zendLocale = Zend_Registry::get('zendLocale');
+
+        $translator = new ZendY_Translate(
+            'array',
+            array(),
+            (string) $zendLocale,
+            array(
+                'scan' => Zend_Translate::LOCALE_DIRECTORY,
+                'disableNotices' => true,
+            )
+        );
+        $translator->setDefault(Zend_Registry::get('langs'));
+
+        $cache = Zend_Registry::get('configCache');
+        $cacheId = 'translate' . (string) $zendLocale;
+        $data = $cache->load($cacheId);
+        if ($data) {
+            foreach ($data as $locale => $messages) {
+                $translator->addTranslation(array(
+                    'content' => $messages,
+                    'locale' => $locale,
+                ));
+            }
+        } else {
+            if (SYSTEM_LOG) {
+                Zend_Registry::get('zendLog')->debug('Loading translation...');
+            }
+
+            $translator->addTranslation(array(
+                'content' => RESOURCES_DIR . '/language',
+                'locale' => null,
+            ));
+
+            $modules = Zend_Registry::get('applicationConfig')->modules;
+            foreach ($modules as $moduleName) {
+                $translationDir = MODULES_DIR . "/{$moduleName}/i18n";
+                if (file_exists($translationDir)) {
+                    $translator->addTranslation(array(
+                        'content' => $translationDir,
+                        'locale' => null,
+                    ));
+
+                    if (SYSTEM_LOG) {
+                        Zend_Registry::get('zendLog')->debug('  dir: ' . $translationDir);
+                    }
+                }
+            }
+
+            $cache->save($translator->getMessages('all'));
+        }
+
+        return $translator;
+    }
+
+    public function getZendCacheBackendFile()
+    {
+        return new Zend_Cache_Backend_File(array(
+            'cache_dir' => CACHE_DIR,
+        ));
+    }
+
+    public function getZendCacheBackend()
+    {
+        return Zend_Registry::get('zendCacheBackendFile');
+    }
+}

File www/system/library/ZendY/View.php

 <?php
 class ZendY_View extends Zend_View
 {
+    /**
+     * @var array Registry of helper classes used
+     */
+    protected $_localHelperObjects = array();
+
     public function __set($name, $value)
     {
         $value = ZendY_Escape_Escaper::escape($value, array($this, 'escape'));
 
         return $value;
     }
+
+    /**
+     * Proxy to url view helper
+     *
+     * @param  array $urlOptions Options passed to the assemble method
+     *                           of the Route object.
+     * @param  mixed $name The name of a Route to use. If null it will
+     *                     use the current Route
+     * @param  bool $reset Whether or not to reset the route defaults
+     *                     with those provided
+     * @return string Url for the link href attribute.
+     */
+    public function url(array $urlOptions = array(), $name = null,
+            $reset = false, $encode = true) {
+        if (!isset($this->_localHelperObjects['url'])) {
+            $this->_localHelperObjects['url'] = new Zend_View_Helper_Url();
+            $this->_localHelperObjects['url']->setView($this);
+        }
+        return $this->_localHelperObjects['url']->url($urlOptions, $name, $reset, $encode);
+    }
 }

File www/system/library/ZendY/View/Helper/GoogleAnalytics.php

 
     public function toString()
     {
-        if (SYSTEM_ENV === 'production') {
+        if (APPLICATION_ENV === 'production') {
             $this->view->inlineScript()->appendScript(sprintf($this->js, $this->id));
         }
         return '';

File www/system/modules/blog/configs/acl.yml

     privileges:
       list: true
       emptyList: true
-      show: true
+      show: true
+      tag: true
+      category: true
+  Blog_Feed:
+    privileges:
+      list: true
+      category: true
+  Blog_Profile:
+    privileges:
+      index: true

File www/system/modules/blog/configs/routes.yml

     controller: entry
     action: list
 
+blog_entry_comments:
+  route: entries/comments/:id/*
+  defaults:
+    module: blog
+    controller: entry
+    action: comments
+
 blog_entry_list:
   route: entries
   defaults:
     controller: entry
     action: list
 
+blog_entry_emptyList:
+  route: entries/empty
+  defaults:
+    module: blog
+    controller: entry
+    action: empty-list
+
 blog_entry_manage:
   route: entries/manage
   defaults:
     action: delete
 
 blog_entry_tag:
-  route: tag/:name_slug/:page
+  route: tags/:name_slug/:page
   defaults:
     module: blog
     controller: entry

File www/system/modules/blog/controllers/EntryController.php

 {
     public function init()
     {
+        parent::init();
+
+        $this->_helper->contextSwitch
+                ->addActionContext('comments', 'xml')
+                ->initContext();
+
         $this->view->highlight()
                 ->setBasePath('js/text/highlight')
                 ->setScriptPath('/highlight.pack.js')
         $this->view->page('Blog entries', array('route' => 'blog_entry_list'));
     }
 
+    public function commentsAction()
+    {
+        $service = new Blog_Service_Entry();
+        $this->view->entry = $entry = $service->get($this->_getParam('title_slug'));
+
+        $commentService = new Blog_Service_Comment();
+        $this->view->comments = $commentService->getEntryComments($entry->getId());
+    }
+
     public function listAction()
     {
         $service = new Blog_Service_Entry();
             return;
         }
 
-        $this->view->page(array('Entries in category %s',
+        $this->view->page(array('Entries in category "%s"',
                 $this->_getParam('name_slug')));
     }
 
 
     public function emptyListAction()
     {
-        $this->view->page('No entries');
     }
 
     public function manageAction()
             return;
         }
 
-        $this->view->page(array('Entries tagged with %s',
+        $this->view->page(array('Entries tagged with "%s"',
                 $this->_getParam('name_slug')));
     }
 
             }
         }
     }
-}
+}

File www/system/modules/blog/library/Category.php

 
     public function getFeedUri()
     {
-        $uri = Zend_Registry::get('appConfig')->blog->feed_category;
+        $uri = Zend_Registry::get('applicationConfig')->blog->feed_category;
         return sprintf($uri, $this->getNameSlug());
     }
 }

File www/system/modules/blog/library/Service/Feed.php

 
     public function getFeedUri()
     {
-        return Zend_Registry::get('appConfig')->blog->feed;
+        return Zend_Registry::get('applicationConfig')->blog->feed;
     }
 }

File www/system/modules/blog/views/scripts/entry/comments.html.phtml

+<?php echo $this->render('comment/_list.phtml') ?>

File www/system/modules/blog/views/scripts/entry/comments.phtml

Empty file added.

File www/system/modules/blog/views/scripts/entry/show.phtml

     <?php echo $this->entry->getCreatedAt(); ?>
 </div>
 
-<h3>
-    <?php echo $this->translate('Comments'); ?> (<?php echo $this->entry->getCommentNumber(); ?>)
-</h3>
-
 <?php echo $this->render('comment/create.phtml'); ?>
 
-<?php foreach($this->comments as $comment): ?>
-    <div class="b-comment" style="margin-left: <?php echo ($comment->getLevel() - 1) * 30;
-            ?>px" id="comment_<?php echo $comment->getId(); ?>">
+<?php echo $this->render('comment/_list.phtml') ?>
 
-        <h3><?php echo $comment->getName(); ?></h3>
-        <?php if ($comment->getEmail()): ?>
-            <?php echo $this->mailto($comment->getEmail(), '@'); ?>
-        <?php endif; ?>
-        <?php if ($comment->getSite()): ?>
-            <a href="<?php echo $comment->getSite(); ?>">www</a>
-        <?php endif; ?>
-        <small>
-            <a href="<?php echo $this->url(array('titleSlug' => $this->entry->getTitleSlug()),
-                    'blog_entry_show', true); ?>#comment_<?=
-                    $comment->getId(); ?>">#<?php echo $comment->getId(); ?></a>
+<a href="" id="reload">reload</a>
 
-            <?php echo $comment->getCreatedAt(); ?>
-        </small>
-        <?php if ($this->user()->isAllowed('Blog_Comment', 'delete')): ?>
-            <a href="<?php echo $this->url(array('id' => $comment->getId()),
-                    'blog_comment_delete', true); ?>"><?php
-                    echo $this->translate('delete'); ?></a>
-        <?php endif; ?>
+<script type="text/javascript">
+(function($) {
 
-        <?php echo $this->unescape($comment->getTextHtml()); ?>
-        
-        <a href="<?php echo $this->url(array('title_slug' => $this->entry->getTitleSlug()),
-                'blog_entry_show', true); ?>#comment_<?php echo $comment->getId(); ?>"
-                class="b-comment-answer" onclick="return false;"><small><?php
-                echo $this->translate('Answer'); ?></small></a>
-    </div>
-<?php endforeach; ?>
+$('#reload').click(function() {
+    $.get('<?php echo $this->url(array('title_slug' => $this->entry->getTitleSlug(), 'format' => 'html'), 'blog_entry_comments', true) ?>', function(data) {
+        $('#comments').html(data);
+    });
+    return false;
+});
+
+$(document).ajaxError(function(event, request, settings){
+   console.log(event);
+   console.log(request);
+   console.log(settings);
+ });
+
+})(jQuery);
+</script>

File www/system/modules/blog/web/css/screen.css

 ul.Zend_Tag_Cloud li {
     display: inline;
 }
+
+.zendy_form_element_honeypot {
+    display: none;
+}
 /******************************************************************************/
 .b-table td {
     padding: 4px;

File www/system/modules/blog/web/js/Comment.js

         }
 
         var self = this;
-        $('.b-comment-answer').click(function() {
+        $('.b-comment-answer').live('click', function() {
             var found = /#comment_(\d+)/.exec($(this).attr('href'));
             var parent_id = parseInt(found[1]);
             self.$parent_id.val(parent_id);

File www/system/modules/collector/controllers/InviteController.php

     public function indexAction()
     {
         $inviteService = new Collector_Service_Invite(
-                Zend_Registry::get('appConfig')->collector->invites_config_file);
+                Zend_Registry::get('applicationConfig')->collector->invites_config_file);
 
         $this->view->form = $form = $inviteService->getForm();
 
         }
 
         $registrationService = new Collector_Service_Registration(
-                Zend_Registry::get('appConfig')->collector->form_config_file);
+                Zend_Registry::get('applicationConfig')->collector->form_config_file);
         $this->view->form = $form = $registrationService->getForm();
 
         if ($this->_request->isPost()) {
         $secret = $this->_getParam('secret');
 
         $secretValidator = new Collector_Validate_Secret(array(
-            'expiration_time' => Zend_Registry::get('appConfig')->collector
+            'expiration_time' => Zend_Registry::get('applicationConfig')->collector
                     ->link_expiration_time,
         ));
 
         if ($secretValidator->isValid($secret)) {
             $registrationService = new Collector_Service_Registration(
-                    Zend_Registry::get('appConfig')->collector->form_config_file);
+                    Zend_Registry::get('applicationConfig')->collector->form_config_file);
             $registration = $registrationService->getBySecret($secret);
 
             $inviteService = new Collector_Service_Invite(
-                    Zend_Registry::get('appConfig')->collector->invites_config_file);
+                    Zend_Registry::get('applicationConfig')->collector->invites_config_file);
 
             $inviteValidator = new Collector_Validate_Invite(array(
                 'invites' => $inviteService->getInvites()
     public function regenerateAction()
     {
         $registrationService = new Collector_Service_Registration(
-                Zend_Registry::get('appConfig')->collector->form_config_file);
+                Zend_Registry::get('applicationConfig')->collector->form_config_file);
         $registrationService->generateTable();
 
         $this->page(__METHOD__);
     public function enterInviteFirstAction()
     {
         $inviteService = new Collector_Service_Invite(
-                Zend_Registry::get('appConfig')->collector->invites_config_file);
+                Zend_Registry::get('applicationConfig')->collector->invites_config_file);
 
         $this->view->form = $form = $inviteService->getForm();
         $form->setAction($this->_helper->url->url(array(), 'collector_invite_invite', true));
         $invite = $this->_getParam('invite');
 
         $inviteService = new Collector_Service_Invite(
-                Zend_Registry::get('appConfig')->collector->invites_config_file);
+                Zend_Registry::get('applicationConfig')->collector->invites_config_file);
 
         $inviteValidator = new Collector_Validate_Invite(array(
             'invites' => $inviteService->getInvites()

File www/system/modules/collector/library/Service/Registration.php

     {
         $model = parent::create($data, $model);
         if ($model) {
-            $config = Zend_Registry::get('appConfig')->collector;
+            $config = Zend_Registry::get('applicationConfig')->collector;
             $view = Zend_Registry::get('zendView');
             $view->registration = $model;
             $view->registrationForm = $this->getForm($model);

File www/system/modules/system/Bootstrap.php

     protected function _initDoctrine()
     {
         //
-        $config = Zend_Registry::get('appConfig')->doctrine;
+        $config = Zend_Registry::get('applicationConfig')->doctrine;
 
         $manager = Doctrine_Manager::getInstance();
         if ($this->getApplication()->hasPluginResource('db')) {

File www/system/modules/zfdebug/Bootstrap.php

 
     protected function _initZFDebug()
     {
-        $config = Zend_Registry::get('appConfig');
+        $config = Zend_Registry::get('applicationConfig');
 
         // is debug console enabled?
         if (!$config->settings->debug) {

File www/system/tests/TestCase.php

     public function __construct($name = NULL, array $data = array(), $dataName = '')
     {
         parent::__construct($name, $data, $dataName);
-        Zend_Registry::get('zendApp')->bootstrap();
+        Zend_Registry::get('zendApplication')->bootstrap();
     }
 }

File www/system/tests/init.php

 <?php
-define('SYSTEM_ENV', 'testing');
+define('APPLICATION_ENV', 'testing');
 
 require_once dirname(__FILE__) . '/../init.php';