Overview

Namespaces

  • Flea
  • None

Classes

  • Flea
  • Flea\BuildUtil
  • Flea\Cache
  • Flea\DataBase
  • Flea\DataBaseCRUD
  • Flea\DataList
  • Flea\DataUtil
  • Flea\Debug
  • Flea\FileUtil
  • Flea\General
  • Flea\Header
  • Flea\InitUtil
  • Flea\LangList
  • Flea\Login
  • Flea\LoginFormHelper
  • Flea\LoginTableName
  • Flea\LoginUser
  • Flea\Page
  • Flea\PageList
  • Flea\PageListCreate
  • Flea\SqlQuery
  • Flea\TagUtil
  • Flea\UrlUtil
  • Flea\ValueObject
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /*
  4:  * The MIT License
  5:  *
  6:  * Copyright 2014 Damien Doussaud (namide.com).
  7:  *
  8:  * Permission is hereby granted, free of charge, to any person obtaining a copy
  9:  * of this software and associated documentation files (the "Software"), to deal
 10:  * in the Software without restriction, including without limitation the rights
 11:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12:  * copies of the Software, and to permit persons to whom the Software is
 13:  * furnished to do so, subject to the following conditions:
 14:  *
 15:  * The above copyright notice and this permission notice shall be included in
 16:  * all copies or substantial portions of the Software.
 17:  *
 18:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21:  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24:  * THE SOFTWARE.
 25:  */
 26: 
 27: namespace Flea;
 28: 
 29: /**
 30:  * All the general data changeable (current page, state...)
 31:  *
 32:  * @author Namide
 33:  */
 34: class General {
 35: 
 36:     private static $_INSTANCE;
 37:     private $_pagesInitialised = false;
 38: 
 39:     /**
 40:      * All page initialised
 41:      * 
 42:      * @return bool     true if the pages are initialised, otherwise false
 43:      */
 44:     public function isPagesInitialized() {
 45:         return $this->_pagesInitialised;
 46:     }
 47: 
 48:     /**
 49:      * Database of the pages initialized
 50:      * 
 51:      * @return bool     true if the databases are initialised, otherwise false
 52:      */
 53:     public function isDBInitialized() {
 54:         return DataBase::getInstance(_DB_DSN_PAGE)->exist(DataBase::objectToTableName(Page::getEmptyPage()));
 55:     }
 56: 
 57:     /**
 58:      * All page initialised
 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:             //PageListCreate::getInstance()->addPagesByDir(_CONTENT_DIRECTORY);
 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:      * Name of the current page
 88:      * 
 89:      * @return string   Current page name
 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:      * Current page
103:      * 
104:      * @return Page     Current page
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:      * Current language
118:      * 
119:      * @return string       Current language
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:      * Current $_GET
133:      * 
134:      * @return array        GET variables
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:      * Current $_POST
148:      * 
149:      * @return array        POST variables
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:      * Current page URL
166:      * 
167:      * @return string       Current page URL
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:      * Change the current page
179:      * 
180:      * @param Page $page    Current page
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:      * Change the current URL
191:      * 
192:      * @param type $pageUrl     URL of the page
193:      * @param array $getUrl     List of the global variables GET
194:      * @param array $postUrl    List of the global variables POST
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:      * Get the instance of General
218:      * 
219:      * @return General      Object instancied
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: 
Flea API documentation generated by ApiGen