public static function update($data) { //CHECK $checks = array('defaultLanguage' => 'is_string-!is_empty', 'availableLanguages' => 'is_array-!is_empty', 'defaultBaseUrl' => 'is_string-!is_empty', 'availableBaseUrl' => 'is_array-!is_empty'); if (!KLib\Validator::arrayCheck($data, $checks)) { throw new Exception('INVALID CONFIG DATA', 500); } if (!array_key_exists($data['defaultLanguage'], C::g('LIST_LANGUAGE'))) { throw new Exception('INVALID CONFIG DATA', 500); } foreach ($data['availableLanguages'] as $id) { if (!array_key_exists(strtoupper($id), C::g('LIST_LANGUAGE'))) { throw new Exception('INVALID CONFIG DATA', 500); } $availableLanguages[] = "'" . strtoupper($id) . "'"; } if (!filter_var('http://' . $data['defaultBaseUrl'], FILTER_VALIDATE_URL)) { throw new Exception('INVALID CONFIG DATA', 500); } foreach ($data['availableBaseUrl'] as $id) { if (!filter_var('http://' . $id, FILTER_VALIDATE_URL)) { throw new Exception('INVALID CONFIG DATA', 500); } $availableBaseUrls[] = "'" . $id . "'"; } $raw = "<?php\n### Default language\n### Index of LIST_LANGUAGE\nC::s('DEFAULT_LANG', '" . $data['defaultLanguage'] . "');\n### Language available\n### List of index of LIST_LANGUAGE\nC::s('DEFAULT_AVAILABLE_LANG', array(" . implode(', ', $availableLanguages) . "));\n### Default baseUrl\n### eg. 'www.korona.io'\nC::s('DEFAULT_BASEURL', '" . $data['defaultBaseUrl'] . "');\n### List of available baseUrl\n### eg. 'www.korona.io'\nC::s('DEFAULT_AVAILABLE_BASEURL', array(" . implode(', ', $availableBaseUrls) . "));"; return file_put_contents(self::$configPath, $raw); }
public function setType($data) { if (!is_string($data) || !array_key_exists($data, C::g('MENUITEM_TYPE'))) { throw new Exception('INVALID MENUITEM TYPE PARAMETER', 500); } $this->type = $data; }
public function updatePo() { if (KLib\File::fileNameExtension($_FILES['file']['name']) != 'po') { throw new Exception('FORBIDDEN ACCESS', 403); } if (move_uploaded_file($_FILES['file']['tmp_name'], $this->path . C::g('LANG_DOMAIN_CURRENT') . '.po')) { return array('error' => 'OK'); } return array('error' => 'FAIL'); }
/** * Init a routing algo * @param string $from URL source if not provide, Route::go will determine the good route from $_SERVER parameter * @return mixed[] */ public static function go($published = true, $lang = 'FR', $host = null) { $host = !is_string($host) ? $_SERVER['HTTP_HOST'] : $host; C::s('FULLURL', 'http://' . $host); if (array_key_exists('HTTPS', $_SERVER)) { C::s('FULLURL', 'https://' . $host); } $uri = parse_url($_SERVER['REQUEST_URI']); if (substr($uri['path'], -1) == '/') { $uri['path'] = substr($uri['path'], 0, -1); } $route = self::getRoute($host, $uri['path'], $_SERVER['REQUEST_METHOD']); if (!is_a($route, 'KLib\\Router')) { //PAGE $data = \Page::getByUrl($host, $uri['path'], $lang, $published); if (!is_a($data, 'Page') && $lang != C::g('DEFAULT_LANG')) { $data = \Page::getByUrl($host, $uri['path'], C::g('DEFAULT_LANG'), $published); } if (!is_a($data, 'Page')) { throw new \Exception('PAGE NOT FOUND', 404); } $route = new Self($data->getBaseUrl(), $uri['path'], $data->getAction(), $data->getMethod(), array_merge($_GET, array('page' => $data))); } if (!is_a($route, 'KLib\\Router')) { throw new \Exception('PAGE NOT FOUND', 404); } return BaseController::run($route->getController(), $route->getAction(), $route->getArgs()); }
<?php error_reporting(E_ALL | E_STRICT); trait T { protected function f() { return 1; } private function p() { return 2; } function g() { return $this->f(); } function h() { return $this->p(); } } class C { use T; } $c = new C(); echo $c->g(); echo $c->h();
public function urls() { return array('static' => C::g('STATICURL')); }
/** * Remove the page * * @param string $collection Collection to store * @return null */ public function remove() { //LOAD $datas = json_decode(file_get_contents(C::g('AUTH_FILE')), true); //REMOVE foreach ($datas as $k => $d) { if ($d['id'] == $this->id) { unset($datas[$k]); } } file_put_contents(C::g('AUTH_FILE'), json_encode(array_values($datas), JSON_PRETTY_PRINT)); return true; }
<?php class B { public function f1() { var_dump(get_called_class()); if ($this !== null) { var_dump(get_class($this)); } else { var_dump(null); } echo "\n"; } } class C extends B { public function g() { $obj = new B(); forward_static_call(array('B', 'f1')); call_user_func(array('B', 'f1')); } } $obj = new C(); $obj->g();
public function setLanguage($data) { if (!is_string($data) || empty($data) || !array_key_exists(strtoupper($data), C::g('LIST_LANGUAGE'))) { $data = C::g('DEFAULT_LANG'); } $this->language = strtoupper($data); }
public function view() { $ret = array('defaultLanguage' => C::g('DEFAULT_LANG'), 'availableLanguages' => C::g('DEFAULT_AVAILABLE_LANG'), 'defaultBaseUrl' => C::g('DEFAULT_BASEURL'), 'availableBaseUrl' => C::g('DEFAULT_AVAILABLE_BASEURL')); return $ret; }
class C { /** * @return self */ function f() { return $this; } /** * @return static */ function g() { return $this; } /** * @return $this */ function h() { return $this; } function test(C $c) { } } $c = new C(); $f = $c->test($c->f()); $g = $c->test($c->g()); $h = $c->test($c->h());
public function setLanguage($data) { if (!is_string($data) || empty($data) || !in_array(strtoupper($data), C::g('DEFAULT_AVAILABLE_LANG'))) { $data = C::g('DEFAULT_LANG'); } $this->language = strtoupper($data); }
RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/page/{is_mongoid}', 'Page::delete', 'DELETE'); //KADMIN RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/user', 'Kadmin::all', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/user', 'Kadmin::add', 'POST'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/user/already', 'Kadmin::already', 'POST'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/user/{is_string}', 'Kadmin::view', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/user/{is_string}', 'Kadmin::update', 'PUT'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/user/{is_string}', 'Kadmin::delete', 'DELETE'); //MENU RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/menu', 'Menu::all', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/menu', 'Menu::add', 'POST'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/menu/{is_mongoid}', 'Menu::view', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/menu/{is_mongoid}', 'Menu::update', 'PUT'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/menu/{is_mongoid}', 'Menu::delete', 'DELETE'); //CONFIG RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/config', 'Config::view', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/config', 'Config::update', 'PUT'); //SEO RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/robot', 'Seo::robotView', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/robot', 'Seo::robotUpdate', 'PUT'); //BLOCK RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/block', 'Block::list', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/block/clone/{is_mongoid}', 'Block::clone', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/block/{is_mongoid}', 'Block::view', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/block/{is_mongoid}', 'Block::update', 'PUT'); //TRANSLATE RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/translate/po', 'Translate::po', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/translate/pot', 'Translate::pot', 'GET'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/translate/po', 'Translate::updatePo', 'POST'); RK::a(C::g('DEFAULT_BASEURL'), '/kadmin/translate/mo', 'Translate::updateMo', 'POST');
session_name('KNSESSID'); session_start(); require_once __DIR__ . '/global.inc.php'; try { Router::loadPost(); Router::loadGet(); $published = true; if (isset($_GET['force']) && $_GET['force'] == '1') { $published = null; } KLib\RouterKorona::go($published); } catch (Exception $e) { //LOG EXCEPTION if (!in_array($e->getCode(), array(200, 204, 542))) { KLib\Log::info($e->getCode() . ' ' . $e->getMessage()); if (C::g('DEV')) { KLib\Log::warning("\n" . $e->getTraceAsString()); } header('Content-Type: text/html'); } //FORMAT EXCEPTION switch ($e->getCode()) { case 204: header('HTTP/1.1 204 OK'); break; case 401: KLib\BaseController::run('error', 'authenticate', array('exception' => $e)); break; case 403: KLib\BaseController::run('error', 'forbidden', array('exception' => $e)); break;
public function setLanguage($data) { if (!is_string($data) || empty($data)) { throw new Exception('INVALID LANGUAGE BLOCK PARAMETER', 500); } if (in_array(strtoupper($data), C::g('DEFAULT_AVAILABLE_LANG'))) { $this->language = strtoupper($data); } else { $this->language = C::g('DEFAULT_LANG'); } }