Пример #1
0
 public function remove($key)
 {
     if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'REMOVE: ' . $key, $this);
     }
     unset($this->_local[$key]);
     return $this->_memcache->delete($key);
 }
Пример #2
0
 public function __construct()
 {
     // Init title data
     $this->_pageTitleConfig = \Kalibri::config()->get('page.title');
     $data = \Kalibri::data();
     // Init page data
     $data->merge(array(\Kalibri\View::VAR_CONTENT => $data->get(\Kalibri\View::VAR_CONTENT, ''), \Kalibri\View::VAR_TITLE => $data->get(\Kalibri\View::VAR_TITLE, $this->_pageTitleConfig['default']), \Kalibri\View::VAR_META => $data->get(\Kalibri\View::VAR_META, array()), \Kalibri\View::VAR_SCRIPTS => $data->get(\Kalibri\View::VAR_SCRIPTS, array()), \Kalibri\View::VAR_STYLES => $data->get(\Kalibri\View::VAR_STYLES, array())));
     $this->setMetaContentType($this->_contentType);
 }
Пример #3
0
 public function __construct()
 {
     $config = \Kalibri::config()->get('l10n');
     $this->_isTranslationAllowed = isset($config['is-allowed']) && $config['is-allowed'];
     if ($this->_isTranslationAllowed) {
         $this->_currentLang = $config['language'];
         $this->_languages = isset($config['languages']) ? $config['languages'] : array($this->_currentLang => $this->_currentLang);
     }
 }
Пример #4
0
 protected function init()
 {
     \Kalibri::config()->load();
     if ($this->_mode) {
         \Kalibri::config()->load($this->_mode);
     }
     // Set list of classes that will be auto inited on use
     \Kalibri::setAutoInitClasses(\Kalibri::config()->get('init.classes'));
     if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'init', $this);
     }
 }
Пример #5
0
 public function init(array $options = null)
 {
     if ($options) {
         $this->_options = $options;
     }
     // Load options from config if not initialized yet
     if (!$this->_options) {
         $this->_options = \Kalibri::config()->get('debug.log');
     }
     // Set default date format if skipped in config
     if (!isset($this->_options['date-format'])) {
         $this->_options['date-format'] = self::DEFAULT_DATE_FORMAT;
     }
     $this->_uniq = uniqid();
 }
Пример #6
0
 public function register()
 {
     if (\Kalibri::auth()->getProfile()) {
         \Url::redirect(\Kalibri::config()->get('page.after-login'));
     }
     $this->page()->setTitle(tr('Sign up'));
     if (isset($_POST['login'], $_POST['password'], $_POST['re-password'])) {
         $errors = array();
         if (empty($_POST['password'])) {
             $errors[] = tr('Password should not be empty.');
         }
         if ($_POST['password'] !== $_POST['re-password']) {
             $errors[] = tr('Password and Re-password should match.');
         }
         if (strlen($_POST['password']) < \Kalibri::config()->get('auth.min-password-length')) {
             $errors[] = tr('Password should be minimum :min-length letters.', array('min-length' => \Kalibri::config()->get('auth.min-password-length')));
         }
         if (empty($_POST['login'])) {
             $errors[] = tr('Login should not be empty.');
         }
         if (!\Kalibri::auth()->isValidLogin($_POST['login'])) {
             $errors[] = tr('Login should contain latin letters or digits and be from 4 to 15 chars long.');
         }
         if (\Kalibri::auth()->getProfileByLogin($_POST['login'])) {
             $errors[] = tr('Profile with this name already registered.');
         }
         $this->page()->errorMsg = $errors;
         if (!count($errors)) {
             $model = \Kalibri::auth()->getModel();
             //$model->register(
             $model->getEmpty()->setLogin($_POST['login'])->setPassword(\Kalibri::auth()->encryptPassword($_POST['password']))->save();
             //);
             if (\Kalibri::auth()->tryLogin($_POST['login'], $_POST['password'])) {
                 \Url::redirect(\Kalibri::config()->get('page.after-login'));
             } else {
                 \Kalibri::error()->show(tr('Ooops. Something go wrong.'));
             }
         }
     }
 }
Пример #7
0
 public function encryptPassword($rawPassword)
 {
     return md5($rawPassword . \Kalibri::config()->get('auth.salt'));
 }
Пример #8
0
 public function execStatment($query, array $params = null)
 {
     if (\Kalibri::config()->get('debug.log.is-enabled', false) && \Kalibri::config()->get('debug.log.collect-db-queries', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'SQL query:' . $query, $this);
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'SQL params:' . var_export($params, true), $this);
     }
     try {
         $stmt = $this->connect()->prepare($query);
         $stmt->execute($params);
     } catch (\Exception $e) {
         $exception = new \Kalibri\Db\Exception($e->getMessage());
         $exception->setQueryinfo($query, $params);
         throw $exception;
     }
     return new \Kalibri\Db\Result\Mysql($stmt);
 }
Пример #9
0
 public function __construct()
 {
     $this->_config = \Kalibri::config()->get('db');
     $this->_useCache = \Kalibri::config()->get('cache.is-enabled');
     $this->_defaultConnectName = $this->_config['default'];
 }
Пример #10
0
 public static function current($fullPath = false)
 {
     /**
      * @todo Add protocol detection
      */
     $uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
     $root = \Kalibri::config()->get('base') . \Kalibri::config()->get('entry');
     return $fullPath ? $uri : str_replace($root, '', $uri);
 }
Пример #11
0
    require_once 'Kalibri/Application.php';
    require_once 'Kalibri/Config.php';
    require_once 'Kalibri/Controller/Base.php';
    require_once 'Kalibri/Uri.php';
    require_once 'Kalibri/Router.php';
    require_once 'Kalibri/Benchmark.php';
}
// Register autoloader
spl_autoload_register(function ($className) {
    if (@(include_once str_replace('\\', '/', $className) . '.php')) {
        return true;
    }
    // Not loaded yet, try to load helper
    return \Kalibri::autoload()->helper($className);
});
\Kalibri::config(new \Kalibri\Config());
\Kalibri::benchmark(new \Kalibri\Benchmark())->start('kalibri-total');
function tr($key, array $params = null, $language = null)
{
    return \Kalibri::l10n()->tr($key, $params, $language);
}
function url($path, $subdomain = null)
{
    return \Kalibri\Helper\Url::site($path, $subdomain);
}
function k_ob_get_end($flush = false)
{
    $output = ob_get_clean();
    ob_end_clean();
    if ($flush) {
        echo $output;
Пример #12
0
 protected function _setTableName($tableName, $alias = null)
 {
     if ($this->usePrefix()) {
         $tableName = \Kalibri::config()->get("db.connections.{$this->_connectName}.table-prefix", '') . $tableName;
     }
     if ($alias) {
         $this->_data['table_name'] = array($alias => $tableName);
         return;
     }
     $this->_data['table_name'] = $tableName;
 }
Пример #13
0
 protected function init()
 {
     K_COMPILE_ROUTES && \Kalibri::compiler()->compile(Compiler::NAME_BASE);
     \Kalibri::config()->load();
     if ($this->_mode) {
         try {
             \Kalibri::config()->load($this->_mode);
         } catch (\Exception $e) {
         }
     }
     // Set list of classes that will be auto inited on use
     \Kalibri::setAutoInitClasses(\Kalibri::config()->get('init.classes'));
     //\Kalibri::logger()->init( \Kalibri::config()->get('debug.log') );
     \Kalibri::router()->setSegments(\Kalibri::uri()->getSegments());
     if (session_status() == PHP_SESSION_NONE) {
         session_start();
     }
     if (\Kalibri::config()->get('debug.log.is-enabled', false)) {
         \Kalibri::logger()->add(\Kalibri\Logger\Base::L_DEBUG, 'init', $this);
     }
     ob_start();
 }
Пример #14
0
 public function checkProjectBase()
 {
     $map = \Kalibri::config()->get('route.map-project');
     if ($map) {
         foreach ($map as $way => $name) {
             if ($way == $this->_segments[0]) {
                 // Remove first segment that contains map key
                 array_shift($this->_segments);
                 return $name;
             }
         }
     }
     return \Kalibri::app()->getNamespace();
 }
Пример #15
0
 /**
  * @param string
  * @return bool
  */
 public function isValidUri($uri)
 {
     return (bool) preg_match("/^[" . \Kalibri::config()->get('permitted-uri-chars') . "\\/]+\$/", $uri);
 }
Пример #16
0
 /**
  * Show access denied page
  */
 public function show403()
 {
     @ob_end_clean();
     $viewName = \Kalibri::config()->get('error.view.403');
     if ($viewName) {
         if (\Kalibri::controller() instanceof \Kalibri\Controller\Page) {
             \Kalibri::controller()->page()->setViewName($viewName)->render();
         } else {
             (new \Kalibri\View($viewName))->render();
         }
     }
     exit;
 }