public function __get($name)
 {
     if ($name == 'tpl') {
         if (!$this->_templateInitialized) {
             $this->initTemplate();
         }
         return $this->_template;
     }
     if ($name == 'router') {
         return Router::getInstance();
     }
     if ($name == 'session') {
         return Session::getInstance();
     }
     if ($name == 'config') {
         return Config::getInstance();
     }
     if ($name == 'log') {
         return Logger::getInstance();
     }
     if ($name == 'language') {
         return Language::getInstance();
     }
     if ($name == 'model') {
         return Model::getInstance();
     }
 }
예제 #2
0
 public function __construct($options = array())
 {
     if (isset($options['timeValidity'])) {
         $this->_timeValidity = (int) $options['timeValidity'];
     }
     if (isset($options['urlReferer'])) {
         if (is_array($options['urlReferer'])) {
             foreach ($options['urlReferer'] as &$url) {
                 $this->_urlsReferer[] = Router::getUrl($url);
             }
         } else {
             $this->_urlsReferer[] = Router::getUrl($options['urlReferer']);
         }
     }
 }
예제 #3
0
 public function notify()
 {
     // Erase buffer
     $buffer = ob_get_status();
     if (!empty($buffer)) {
         ob_end_clean();
     }
     if ($this->_observers->count()) {
         foreach ($this->_observers as $observer) {
             $observer->update($this);
         }
     }
     // Clear error for avoid multiple call
     if ($this->_clearErrorAfterSending) {
         $this->_error = false;
     }
     // Show internal server error (500)
     if (!Application::getDebug()) {
         Router::getInstance()->show500();
     }
     // Exit script
     exit;
 }
예제 #4
0
 public function run()
 {
     if ($this->_isRun) {
         throw new \Exception('Application already runned');
     }
     //Cli
     if (Cli::isCli()) {
         throw new \Exception('CLI not yet');
     }
     // Check maitenance mode activated => show503
     if (defined('SITE_MAINTENANCE') && SITE_MAINTENANCE) {
         Router::getInstance()->show503();
     } else {
         // Run router
         Router::getInstance()->run();
     }
     $this->_isRun = true;
 }
예제 #5
0
 public function update(\SplSubject $subject, $isException = false)
 {
     Router::getInstance()->showDebugger($isException);
 }
예제 #6
0
 public function load(Reader $reader)
 {
     $routes = $reader->read();
     foreach ($routes as $name => $datas) {
         // Check name
         if (!Validate::isVariableName($name)) {
             throw new \Exception('Route name must be a valid variable');
         }
         // Check controller info
         if (!isset($datas['controller'])) {
             throw new \Exception('Miss controller into route "' . $name . '"');
         }
         // create instance of route
         $route = new RouterRoute($name, $datas['controller']);
         // Optionnals parameters
         if (isset($datas['regex'])) {
             $route->setRegex(Tools::castValue($datas['regex']));
         }
         if (isset($datas['requireSsl'])) {
             $route->setRequireSsl(Tools::castValue($datas['requireSsl']));
         }
         if (isset($datas['requireAjax'])) {
             $route->setRequireAjax(Tools::castValue($datas['requireAjax']));
         }
         if (isset($datas['autoSetAjax'])) {
             $route->setAutoSetAjax(Tools::castValue($datas['autoSetAjax']));
         }
         if (isset($datas['requireHttpMethod'])) {
             $route->setRequireHttpMethod(Tools::castValue($datas['requireHttpMethod']));
         }
         if (isset($datas['httpResponseStatusCode'])) {
             $route->setHttpResponseStatusCode(Tools::castValue($datas['httpResponseStatusCode']));
         }
         if (isset($datas['httpProtocol'])) {
             $route->setHttpProtocol(Tools::castValue($datas['httpProtocol']));
         }
         if (isset($datas['rules'])) {
             if (is_array($datas['rules'])) {
                 if (isset($datas['rules']['rule']) && is_array($datas['rules']['rule'])) {
                     $datas['rules'] = $datas['rules']['rule'];
                 }
             }
             $route->setRules($datas['rules']);
         }
         if (isset($datas['methods'])) {
             if (is_array($datas['methods'])) {
                 $methods = $datas['methods'];
                 foreach ($methods as $method => $val) {
                     //no have parameters, replace wtih empty parameters list
                     if (is_int($method)) {
                         //TODO fix : replace methode into good order
                         unset($methods[$method]);
                         $methods[$val] = array();
                     }
                 }
                 $route->setMethods($methods);
             }
         }
         // Add into router
         Router::addRoute($route, true);
     }
 }
예제 #7
0
 public function getUrlAsset($type, $ssl = false)
 {
     if (!is_string($type)) {
         throw new \Exception('Asset type must be a string');
     }
     if (Http::isHttps()) {
         $ssl = true;
     }
     if (!is_array($this->_assets)) {
         return false;
     }
     if (!array_key_exists($type, $this->_assets)) {
         return false;
     }
     $asset = $this->_assets[$type];
     return Router::getHost(true, $ssl) . str_replace(DS, '/', str_replace(PATH_ROOT, '', $asset['directory']));
 }
예제 #8
0
        }
    }
}
if (defined('LOGGER_MAIL') && LOGGER_MAIL && defined('LOGGER_MAIL_TO_EMAIL') && defined('LOGGER_MAIL_TO_NAME') && !static::getDebug()) {
    $mailConfig = array('fromEmail' => ADMIN_EMAIL, 'fromName' => $language->getVar('site_name'), 'toEmail' => LOGGER_MAIL_TO_EMAIL, 'toName' => LOGGER_MAIL_TO_NAME, 'mailSubject' => $language->getVar('site_name') . '  logs');
    $log->attach(new Mail($mailConfig));
}
if (defined('LOGGER_ERROR') && LOGGER_ERROR) {
    $exc->attach(new Log());
    $err->attach(new Log());
}
// Config router host
if (!defined('HOSTNAME')) {
    throw new \Exception('Miss hostname constant');
}
Router::setHost(HOSTNAME);
// Auto set language, by session
$languageLoaded = Language::getInstance()->getLanguage();
$langSession = Session::getInstance()->get('language');
if (!is_null($langSession) && $langSession != $languageLoaded) {
    $language->setLanguage($langSession);
    $languageLoaded = $langSession;
}
// Auto set language, by cookie
$langCookie = Cookie::get('language');
if (!is_null($langCookie) && $langCookie != $languageLoaded) {
    $language->setLanguage($langCookie);
    $languageLoaded = $langSession;
}
// Security
Security::autorun();
예제 #9
0
 protected function _check($ip, $userAgent)
 {
     if (Http::getQuery($this->_trapName) && !Validate::isGoogleBot()) {
         $isBadCrawler = false;
         $isGoodCrawler = false;
         if ($this->_badCrawlerFile) {
             $badCrawlerXml = simplexml_load_file($this->_badCrawlerFile);
             if (is_null($badCrawlerXml) || !$badCrawlerXml) {
                 throw new \Exception('Invalid xml file : "' . $this->_badCrawlerFile . '"');
             }
         }
         if ($this->_goodCrawlerFile) {
             $goodCrawlerXml = simplexml_load_file($this->_goodCrawlerFile);
             if (is_null($goodCrawlerXml) || !$goodCrawlerXml) {
                 throw new \Exception('Invalid xml file : "' . $this->_goodCrawlerFile . '"');
             }
         }
         if ($badCrawlerXml) {
             $badCrawlerList = $badCrawlerXml->crawler;
             foreach ($badCrawlerList as $crawler) {
                 if (isset($crawler->ip) && (string) $crawler->ip == $ip) {
                     $isBadCrawler = true;
                 }
                 if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) {
                     $isBadCrawler = true;
                 }
                 if ($isBadCrawler) {
                     $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
                     Session::getInstance()->add(md5($ip . 'badcrawler'), true, true, true);
                     Router::getInstance()->show403(true);
                     break;
                 }
             }
             unset($crawler);
         }
         if ($goodCrawlerXml) {
             $goodCrawlerList = $goodCrawlerXml->crawler;
             foreach ($goodCrawlerList as $crawler) {
                 if (isset($crawler->ip) && (string) $crawler->ip == $ip) {
                     $isGoodCrawler = true;
                 }
                 if (isset($crawler->userAgent) && strripos((string) $crawler->userAgent, $userAgent) !== false) {
                     $isGoodCrawler = true;
                 }
                 if ($isGoodCrawler) {
                     $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
                     break;
                 }
             }
             unset($crawler);
         }
         // unknown
         if (!$isBadCrawler && !$isGoodCrawler) {
             $this->_catch($ip, $userAgent, self::CRAWLER_BAD);
         }
     }
 }
예제 #10
0
 protected function _getContent()
 {
     if ($this->_type == Template::ASSET_CSS) {
         $content = '';
         foreach ($this->_files as $file) {
             $f = file_get_contents($file['name']);
             if ($this->_compress && !$file['alreadyCompressed']) {
                 $f = $this->_compressCss($f);
             }
             $content .= $f;
         }
         //rewrite url path
         if ($this->getRewriteUrls()) {
             return preg_replace("#\\[HOSTNAME]#", Router::getHost(true, Http::isHttps()), $content);
         }
         return $content;
     } elseif ($this->_type == Template::ASSET_JS) {
         $notCompressed = $content = '';
         foreach ($this->_files as $file) {
             $js = file_get_contents($file['name']);
             if ($this->_compress && !$file['alreadyCompressed']) {
                 // Compress file with Javascript Packer plugin
                 $packer = new JavaScriptPacker($js);
                 $notCompressed .= trim($packer->pack());
             } else {
                 $content .= $js;
             }
             if (substr($notCompressed, -1) != ';') {
                 $notCompressed .= ';';
             }
         }
         //rewrite url path
         if ($this->getRewriteUrls()) {
             return preg_replace("#\\[HOSTNAME]#", Router::getHost(true, Http::isHttps()), $content . $notCompressed);
         }
         return $content . $notCompressed;
     }
 }
예제 #11
0
 public function getRefreshUrl()
 {
     return Router::getUrl($this->_refreshUrl, array($this->getFormName(), 'refresh'));
 }