1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: namespace Flea;
28:
29: 30: 31: 32: 33:
34: class General {
35:
36: private static $_INSTANCE;
37: private $_pagesInitialised = false;
38:
39: 40: 41: 42: 43:
44: public function isPagesInitialized() {
45: return $this->_pagesInitialised;
46: }
47:
48: 49: 50: 51: 52:
53: public function isDBInitialized() {
54: return DataBase::getInstance(_DB_DSN_PAGE)->exist(DataBase::objectToTableName(Page::getEmptyPage()));
55: }
56:
57: 58: 59:
60: public function initializesPages() {
61: if (file_exists(_CONTENT_DIRECTORY . 'initBegin.php')) {
62: include _CONTENT_DIRECTORY . 'initBegin.php';
63: }
64:
65: if (file_exists(_CONTENT_DIRECTORY . 'initLang.php')) {
66: include _CONTENT_DIRECTORY . 'initLang.php';
67: } elseif (_DEBUG) {
68: Debug::getInstance()->addError('The file: ' . _CONTENT_DIRECTORY . 'initLang.php don\'t exist');
69: }
70:
71: if (!$this->isDBInitialized()) {
72: include_once _SYSTEM_DIRECTORY . 'data/list/PageListCreate.php';
73:
74: PageListCreate::getInstance()->addPagesByCSV(_CONTENT_DIRECTORY);
75:
76: if (file_exists(_CONTENT_DIRECTORY . 'initDB.php')) {
77: PageListCreate::getInstance()->commands(_CONTENT_DIRECTORY . 'initDB.php');
78: }
79: }
80:
81: $this->_pagesInitialised = true;
82: }
83:
84: private $_currentPageName;
85:
86: 87: 88: 89: 90:
91: public function getCurrentPageName() {
92: if (_DEBUG && !General::getInstance()->isPagesInitialized()) {
93: Debug::getInstance()->addError('You can\'t access to the current '
94: . 'page name if the pages isn\'tinitialised');
95: }
96: return $this->_currentPageName;
97: }
98:
99: private $_currentPage;
100:
101: 102: 103: 104: 105:
106: public function getCurrentPage() {
107: if (_DEBUG && !General::getInstance()->isPagesInitialized()) {
108: Debug::getInstance()->addError('You can\'t access to the current '
109: . 'page if the pages isn\'tinitialised');
110: }
111: return $this->_currentPage;
112: }
113:
114: private $_currentLang;
115:
116: 117: 118: 119: 120:
121: public function getCurrentLang() {
122: if (_DEBUG && !General::getInstance()->isPagesInitialized()) {
123: Debug::getInstance()->addError('You can\'t access to the current '
124: . 'language if the pages isn\'tinitialised');
125: }
126: return $this->_currentLang;
127: }
128:
129: private $_currentGetUrl;
130:
131: 132: 133: 134: 135:
136: public function getCurrentGetUrl() {
137: if (_DEBUG && !General::getInstance()->isPagesInitialized()) {
138: Debug::getInstance()->addError('You can\'t access to the current '
139: . 'global variable GET if the pages isn\'tinitialised');
140: }
141: return $this->_currentGetUrl;
142: }
143:
144: private $_currentPostUrl = null;
145:
146: 147: 148: 149: 150:
151: public function getCurrentPostUrl() {
152: if ($this->_currentPostUrl === null) {
153: $this->_currentPostUrl = array();
154: foreach ($_POST as $key => $value) {
155: $this->_currentPostUrl[$key] = filter_input(INPUT_POST, $key, FILTER_SANITIZE_STRING);
156: }
157: }
158:
159: return $this->_currentPostUrl;
160: }
161:
162: private $_currentPageUrl;
163:
164: 165: 166: 167: 168:
169: public function getCurrentPageUrl() {
170: if (_DEBUG && !General::getInstance()->isPagesInitialized()) {
171: Debug::getInstance()->addError('You can\'t access to the current '
172: . 'language if the pages isn\'tinitialised');
173: }
174: return $this->_currentPageUrl;
175: }
176:
177: 178: 179: 180: 181:
182: public function setCurrentPage(&$page) {
183: $this->_currentPage = $page;
184: $this->_currentLang = $page->getLang();
185: $this->_currentPageName = $page->getName();
186: $this->_pagesInitialised = true;
187: }
188:
189: 190: 191: 192: 193: 194: 195:
196: public function setCurrentUrl($pageUrl, array $getUrl = null, array $postUrl = null) {
197: if ($getUrl === null) {
198: $getUrl = array();
199: }
200: if ($postUrl === null) {
201: $postUrl = array();
202: }
203:
204: $this->_currentPageUrl = $pageUrl;
205: $this->_currentGetUrl = $getUrl;
206: }
207:
208: private function __construct() {
209:
210: }
211:
212: private function __clone() {
213:
214: }
215:
216: 217: 218: 219: 220:
221: public static function getInstance() {
222: if (!isset(self::$_INSTANCE)) {
223: self::$_INSTANCE = new self();
224: }
225:
226: return self::$_INSTANCE;
227: }
228:
229: }
230: