bootstrap('db');
$db = $this->getResource('db');
if ($db instanceof \Cube\Db\Adapter\AbstractAdapter) {
/** @var \Cube\Db\Adapter\PDO\Mysql $db */
try {
$this->_connected = $db->canConnect();
} catch (\Exception $e) {
}
}
return $this->_connected;
}
protected function _initSettings()
{
if ($this->_connected === true) {
$settingsService = new Service\Settings();
try {
$this->_settings = $settingsService->get();
} catch (\Exception $e) {
}
}
return $this->_settings;
}
protected function _initAuthentication()
{
$authentication = Authentication::getInstance();
if ($authentication->hasIdentity()) {
$storage = $authentication->getStorage()->read();
if ($storage['role'] == 'Admin') {
$this->_role = $storage['role'];
$this->_storage = $storage;
}
}
$view = $this->getResource('view');
$view->loggedInUser = $this->_storage;
}
protected function _initUser()
{
if (isset($this->_storage['id'])) {
$usersService = new Service\Users();
$user = $usersService->findBy('id', $this->_storage['id']);
if (count($user) > 0) {
if ($user['role'] == 'Admin') {
$this->_role = $user['role'];
return $user;
}
}
}
return null;
}
protected function _initAcl()
{
$front = $this->getResource('FrontController');
$this->_acl = new Model\Acl();
$front->registerPlugin(
new Controller\Plugin\Acl($this->_acl, $this->_role));
$view = $this->getResource('view');
$view->navigation()->setAcl($this->_acl)
->setRole($this->_role);
}
protected function _initControllerPlugins()
{
$front = $this->getResource('FrontController');
$front->registerPlugin(
new Controller\Plugin\InstallerEnabled());
}
protected function _initModRewrite()
{
$modRewriteSetting = (isset($this->_settings['mod_rewrite_urls'])) ? $this->_settings['mod_rewrite_urls'] : 0;
if (!\Ppb\Utility::checkModRewrite() && !$modRewriteSetting) {
\Ppb\Utility::activateStandardRouter();
}
}
protected function _initViewHelpers()
{
$dateFormat = '%m/%d/%Y %H:%M:%S';
$sitePath = (!empty($this->_settings['site_path'])) ? $this->_settings['site_path'] : '/';
$view = $this->getResource('view');
$view->setHelper('request', new Helper\Request())
->setHelper('url', new Helper\Url($sitePath))
->setHelper('date', new Helper\Date($dateFormat))
->setHelper('liveTime', new Helper\LiveTime($dateFormat))
->setHelper('thumbnail', new Helper\Thumbnail());
$view->themesFolder = \Ppb\Utility::getFolder('themes');
$view->script()
->addHeaderCode('')
->addHeaderCode('')
->addHeaderCode('')
->addHeaderCode('')
->addHeaderCode('')
->addHeaderCode('')
->addHeaderCode('')
->addHeaderCode('');
/* add javascript plugins */
$view->script()->addBodyCode('')
->addBodyCode('')
->addBodyCode('')
->addBodyCode('')
->addBodyCode('')
->addBodyCode('')
->addBodyCode('')
->addBodyCode('');
}
}