Bootstrap.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ ywBq0GD/Wfo6NkXOTpHP+JXJC2leduaTfdJqu899Nds=
  5. *
  6. * @link https://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license https://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.10 [rev.7.10.01]
  11. */
  12. namespace Install;
  13. use Cube\Application\Bootstrap as ApplicationBootstrap,
  14. Cube\Authentication\Authentication,
  15. Ppb\View\Helper,
  16. Ppb\Service;
  17. class Bootstrap extends ApplicationBootstrap
  18. {
  19. /**
  20. *
  21. * settings array
  22. *
  23. * @var array
  24. */
  25. protected $_settings = array();
  26. /**
  27. *
  28. * database connection flag
  29. *
  30. * @var bool
  31. */
  32. protected $_connected = false;
  33. /**
  34. *
  35. * acl object
  36. *
  37. * @var \Cube\Permissions\Acl
  38. */
  39. protected $_acl;
  40. /**
  41. *
  42. * acl role
  43. *
  44. * @var string|\Cube\Permissions\RoleInterface
  45. */
  46. protected $_role = 'Guest';
  47. /**
  48. *
  49. * current logged in user storage
  50. *
  51. * @var array|null
  52. */
  53. protected $_storage;
  54. protected function _initConnected()
  55. {
  56. $this->bootstrap('db');
  57. $db = $this->getResource('db');
  58. if ($db instanceof \Cube\Db\Adapter\AbstractAdapter) {
  59. /** @var \Cube\Db\Adapter\PDO\Mysql $db */
  60. try {
  61. $this->_connected = $db->canConnect();
  62. } catch (\Exception $e) {
  63. }
  64. }
  65. return $this->_connected;
  66. }
  67. protected function _initSettings()
  68. {
  69. if ($this->_connected === true) {
  70. $settingsService = new Service\Settings();
  71. try {
  72. $this->_settings = $settingsService->get();
  73. } catch (\Exception $e) {
  74. }
  75. }
  76. return $this->_settings;
  77. }
  78. protected function _initAuthentication()
  79. {
  80. $authentication = Authentication::getInstance();
  81. if ($authentication->hasIdentity()) {
  82. $storage = $authentication->getStorage()->read();
  83. if ($storage['role'] == 'Admin') {
  84. $this->_role = $storage['role'];
  85. $this->_storage = $storage;
  86. }
  87. }
  88. $view = $this->getResource('view');
  89. $view->loggedInUser = $this->_storage;
  90. }
  91. protected function _initUser()
  92. {
  93. if (isset($this->_storage['id'])) {
  94. $usersService = new Service\Users();
  95. $user = $usersService->findBy('id', $this->_storage['id']);
  96. if (count($user) > 0) {
  97. if ($user['role'] == 'Admin') {
  98. $this->_role = $user['role'];
  99. return $user;
  100. }
  101. }
  102. }
  103. return null;
  104. }
  105. protected function _initAcl()
  106. {
  107. $front = $this->getResource('FrontController');
  108. $this->_acl = new Model\Acl();
  109. $front->registerPlugin(
  110. new Controller\Plugin\Acl($this->_acl, $this->_role));
  111. $view = $this->getResource('view');
  112. $view->navigation()->setAcl($this->_acl)
  113. ->setRole($this->_role);
  114. }
  115. protected function _initControllerPlugins()
  116. {
  117. $front = $this->getResource('FrontController');
  118. $front->registerPlugin(
  119. new Controller\Plugin\InstallerEnabled());
  120. }
  121. protected function _initModRewrite()
  122. {
  123. $modRewriteSetting = (isset($this->_settings['mod_rewrite_urls'])) ? $this->_settings['mod_rewrite_urls'] : 0;
  124. if (!\Ppb\Utility::checkModRewrite() && !$modRewriteSetting) {
  125. \Ppb\Utility::activateStandardRouter();
  126. }
  127. }
  128. protected function _initViewHelpers()
  129. {
  130. $dateFormat = '%m/%d/%Y %H:%M:%S';
  131. $sitePath = (!empty($this->_settings['site_path'])) ? $this->_settings['site_path'] : '/';
  132. $view = $this->getResource('view');
  133. $view->setHelper('request', new Helper\Request())
  134. ->setHelper('url', new Helper\Url($sitePath))
  135. ->setHelper('date', new Helper\Date($dateFormat))
  136. ->setHelper('liveTime', new Helper\LiveTime($dateFormat))
  137. ->setHelper('thumbnail', new Helper\Thumbnail());
  138. $view->themesFolder = \Ppb\Utility::getFolder('themes');
  139. $view->script()
  140. ->addHeaderCode('<!--[if lt IE 9]> <script type="text/javascript" src="' . $view->baseUrl . '/js/html5shiv.min.js"></script><![endif]-->')
  141. ->addHeaderCode('<link href="' . $view->baseUrl . '/css/bootstrap.min.css" rel="stylesheet" type="text/css">')
  142. ->addHeaderCode('<link href="' . $view->baseUrl . '/css/font-awesome.min.css" media="screen" rel="stylesheet" type="text/css">')
  143. ->addHeaderCode('<link href="' . $view->baseUrl . '/css/style.global.css" rel="stylesheet" type="text/css">')
  144. ->addHeaderCode('<!--[if lt IE 9]><link href="' . $view->baseUrl . '/css/style.ie.css" media="all" rel="stylesheet" type="text/css"><![endif]-->')
  145. ->addHeaderCode('<link href="' . $view->baseUrl . '/css/responsive.css" rel="stylesheet" type="text/css">')
  146. ->addHeaderCode('<link href="' . $view->baseUrl . '/css/mods.css" rel="stylesheet" type="text/css">')
  147. ->addHeaderCode('<link href="' . $view->baseUrl . '/img/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon">');
  148. /* add javascript plugins */
  149. $view->script()->addBodyCode('<script type="text/javascript" src="' . $view->baseUrl . '/js/jquery.min.js"></script>')
  150. ->addBodyCode('<script type="text/javascript" src="' . $view->baseUrl . '/js/bootstrap.min.js"></script>')
  151. ->addBodyCode('<script type="text/javascript" src="' . $view->baseUrl . '/js/masonry.pkgd.min.js"></script>')
  152. ->addBodyCode('<script type="text/javascript" src="' . $view->baseUrl . '/js/bootbox.min.js"></script>')
  153. ->addBodyCode('<script type="text/javascript" src="' . $view->baseUrl . '/js/cookie.js"></script>')
  154. ->addBodyCode('<script type="text/javascript" src="' . $view->baseUrl . '/js/global.js"></script>')
  155. ->addBodyCode('<!--[if lt IE 9]> <script type="text/javascript" src="' . $view->baseUrl . '/js/respond.min.js"></script><![endif]-->')
  156. ->addBodyCode('<!--[if lt IE 10]> <script type="text/javascript" src="' . $view->baseUrl . '/js/placeholders.jquery.min.js"></script><![endif]-->');
  157. }
  158. }