public static function encoding() { if (is_null(static::$encoding)) { static::$encoding = Config::app('encoding'); } return static::$encoding; }
public function parsePath($path) { $path = Tools::parsePath($path); if (strpos($path, '/') === 0) { $path = substr($path, 1); } $app = substr($path, 0, strpos($path, '/')); if ($app && file_exists(INJI_SYSTEM_DIR . '/program/' . $app)) { $path = substr($path, strpos($path, '/') + 1); if (\App::$cur->name != $app) { $scriptApp = new App(); $scriptApp->name = $app; $scriptApp->system = true; $scriptApp->staticPath = "/" . $scriptApp->name . "/static"; $scriptApp->templatesPath = "/" . $scriptApp->name . "/static/templates"; $scriptApp->path = INJI_SYSTEM_DIR . '/program/' . $scriptApp->name; $scriptApp->type = 'app' . ucfirst(strtolower($scriptApp->name)); $scriptApp->installed = true; $scriptApp->params = []; $scriptApp->config = Config::app($scriptApp); } else { $scriptApp = \App::$cur; } } else { $scriptApp = \App::$cur->system ? \App::$primary : \App::$cur; } if (strpos($path, 'static/') !== false && strpos($path, 'static/') <= 1) { $path = substr($path, strpos($path, 'static') + 7); } $type = substr($path, 0, strpos($path, '/')); switch ($type) { case 'libs': return App::$cur->Libs->getPath(array_slice(explode('/', $path), 2)); case 'templates': $path = substr($path, strpos($path, '/') + 1); return $scriptApp->view->templatesPath . '/' . $path; case 'system': $path = substr($path, strpos($path, '/') + 1); return INJI_SYSTEM_DIR . '/static/' . $path; case 'moduleAsset': $path = substr($path, strpos($path, '/') + 1); if (!strpos($path, '/')) { return false; } $module = substr($path, 0, strpos($path, '/')); if (!$scriptApp->{$module}) { return false; } $path = substr($path, strpos($path, '/') + 1); if (is_callable([$module, 'staticCalled'])) { return $scriptApp->{$module}->staticCalled($path, $scriptApp->{$module}->path . '/static/'); } return $scriptApp->{$module}->path . '/static/' . $path; default: return $scriptApp->path . '/static/' . $path; } }
public static function open($action, $method = 'POST', $attributes = array()) { $attributes['method'] = static::method(strtoupper($method)); $attributes['action'] = static::action($action); if (!array_key_exists('accept-charset', $attributes)) { $attributes['accept-charset'] = Config::app('encoding'); } return '<form' . Html::attributes($attributes) . '>'; }
public static function format($date, $format = null) { // set the meta format if (is_null($format)) { $format = Config::meta('date_format', 'jS F, Y'); } $date = new DateTime($date, new DateTimeZone('GMT')); $date->setTimezone(new DateTimeZone(Config::app('timezone'))); return $date->format($format); }
static function currentUser() { $cookie = new CookieSigner(Config::app()['BASE_KEY']); if (isset($_SESSION['userId']) && ($userId = $_SESSION['userId'])) { $user = new User(); return $user->findOne($userId); } else { if ($userId = $cookie->get('userId')) { $user = new User(); $user->findOne($userId); if ($user && $user->isAuthenticated('remember', $cookie->get('rememberToken'))) { self::logIn($user); return $user; } } } return null; }
public function configureAction() { $appOptions = Apps\App::get(filter_input(INPUT_GET, 'item_pk', FILTER_SANITIZE_NUMBER_INT)); $app = new App(); $app->name = $appOptions->name; $app->system = true; $app->staticPath = "/" . $appOptions->dir . "/static"; $app->templatesPath = "/" . $appOptions->dir . "/static/templates"; $app->path = INJI_PROGRAM_DIR . '/' . $appOptions->dir; $app->type = 'app'; $app->installed = true; $app->params = []; $app->config = Config::app($app); $modules = Module::getInstalled($app, $app); $inputs = []; foreach ($modules as $module) { $info = Module::getInfo($module); if (!empty($info['configure'])) { $config = Config::module($module, false, $app); foreach ($info['configure'] as $optionName => $params) { if (filter_input(INPUT_POST, $optionName)) { $config[$optionName] = filter_input(INPUT_POST, $optionName); Config::save('module', $config, $module, $app); } $input = []; $input['name'] = $optionName; $input['type'] = $params['type']; $input['label'] = $params['label']; $input['options']['value'] = !empty($config[$optionName]) ? $config[$optionName] : ''; $input['options']['values'] = ['' => 'Не выбрано']; $input['options']['values'] += $params['model']::getList(['forSelect' => true, 'key' => $params['col']]); $inputs[] = $input; } } } if (!empty($_POST)) { Tools::redirect('/setup'); } $this->view->page(['data' => compact('inputs')]); }
function relative_time($date) { if (is_numeric($date)) { $date = '@' . $date; } $user_timezone = new DateTimeZone(Config::app('timezone')); $date = new DateTime($date, $user_timezone); // get current date in user timezone $now = new DateTime('now', $user_timezone); $elapsed = $now->format('U') - $date->format('U'); if ($elapsed <= 1) { return 'Just now'; } $times = array(31104000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second'); foreach ($times as $seconds => $title) { $rounded = $elapsed / $seconds; if ($rounded > 1) { $rounded = round($rounded); return $rounded . ' ' . pluralise($rounded, $title) . ' ago'; } } }
<?php /* * Set your applications current timezone */ date_default_timezone_set(Config::app('timezone', 'UTC')); /* * Define the application error reporting level based on your environment */ switch (constant('ENV')) { case 'dev': ini_set('display_errors', true); error_reporting(-1); break; default: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); } /* * Set autoload directories to include your app models and libraries */ Autoloader::directory(array(APP . 'models', APP . 'libraries')); /** * Helpers */ require APP . 'helpers' . EXT; /** * Anchor setup */ Anchor::setup(); /** * Import defined routes
<h1>Установка модулей</h1> <form> <?php $config = Config::app(App::$primary ? App::$primary : App::$cur); $modules = array_flip(Module::getInstalled(App::$cur)); $systemModules = array_slice(scandir(INJI_SYSTEM_DIR . '/modules'), 2); foreach ($systemModules as $module) { $info = Module::getInfo($module); if (!$info || isset($modules[$module])) { continue; } ?> <div class ="form-group"> <div class="checkbox"> <label> <input type ="checkbox" name ="modules[]" value ="<?php echo $module; ?> " /> <?php echo $info['name']; ?> </label> </div> </div> <?php } ?> <button class="btn btn-primary">Установить</button> </form>
public function install($module, $params = []) { $installed = Module::getInstalled(App::$primary); if (in_array($module, $installed)) { return true; } $info = Module::getInfo($module); if (!empty($info['requires'])) { foreach ($info['requires'] as $requireModuleName) { $this->install($requireModuleName); } } $config = Config::app(); $type = 'modules'; $path = INJI_SYSTEM_DIR . '/modules/'; $location = 'modules'; $config[$location][] = $module; if (!empty($info['autoload'])) { $config['autoloadModules'][] = $module; } if (!empty($info['menu'])) { foreach ($info['menu'] as $appType => $items) { $this->addInMenu($items, $appType); } } Config::save('app', $config, null, App::$primary); if (file_exists($path . $module . '/install_script.php')) { $installFunction = (include $path . $module . '/install_script.php'); $installFunction(1, $params); } }
private static function path($file) { $language = Config::app('language', 'en_GB'); return APP . 'language/' . $language . '/' . $file . '.php'; }
$input['status'] = 'spam'; } $comment = Comment::create($input); Notify::success(__('comments.created')); // dont notify if we have marked as spam if (!$spam and Config::meta('comment_notifications')) { $comment->notify(); } return Response::redirect($posts_page->slug . '/' . $slug . '#comment'); }); /** * Rss feed */ Route::get(array('rss', 'feeds/rss'), function () { $uri = 'http://' . $_SERVER['HTTP_HOST']; $rss = new Rss(Config::meta('sitename'), Config::meta('description'), $uri, Config::app('language')); $query = Post::where('status', '=', 'published')->sort(Base::table('posts.created'), 'desc'); foreach ($query->get() as $article) { $rss->item($article->title, Uri::full(Registry::get('posts_page')->slug . '/' . $article->slug), $article->description, $article->created); } $xml = $rss->output(); return Response::create($xml, 200, array('content-type' => 'application/xml')); }); /** * Json feed */ Route::get('feeds/json', function () { $json = Json::encode(array('meta' => Config::get('meta'), 'posts' => Post::where('status', '=', 'published')->sort(Base::table('posts.created'), 'desc')->get())); return Response::create($json, 200, array('content-type' => 'application/json')); }); /**
/** * Execute the console command. * * @return mixed */ public function handle() { DB::table('firewall')->where('typeofsave', 'temporary')->where('created_at', '>', date("Y-m-d H:i:s", time() + Config::app('firewall.timeip')))->delete(); }
?> "> <link rel="stylesheet" media="(max-width: 980px), (max-device-width: 480px)" href="<?php echo asset('anchor/views/assets/css/small.css'); ?> "> <meta http-equiv="X-UA-Compatible" content="chrome=1"> <meta name="viewport" content="width=600"> </head> <body class="<?php echo Auth::guest() ? 'login' : 'admin'; ?> <?php echo str_replace('_', '-', Config::app('language')); ?> "> <?php echo Notify::read(); ?> <header class="top"> <div class="wrap"> <?php if (Auth::user()) { ?> <nav> <ul> <li class="logo">
$vars['pages'] = Page::dropdown(array('exclude' => array($id), 'show_empty_option' => true)); $vars['statuses'] = array('published' => __('global.published'), 'draft' => __('global.draft'), 'archived' => __('global.archived')); // extended fields $vars['fields'] = Extend::fields('page', $id); return View::create('pages/edit', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer')->partial('editor', 'partials/editor'); }); Route::post('admin/pages/edit/(:num)', function ($id) { $input = Input::get(array('parent', 'name', 'title', 'slug', 'content', 'status', 'redirect', 'show_in_menu')); // if there is no slug try and create one from the title if (empty($input['slug'])) { $input['slug'] = $input['title']; } // convert to ascii $input['slug'] = slug($input['slug']); // encode title $input['title'] = htmlspecialchars($input['title'], ENT_QUOTES, Config::app('encoding'), false); $validator = new Validator($input); $validator->add('duplicate', function ($str) use($id) { return Page::where('slug', '=', $str)->where('id', '<>', $id)->count() == 0; }); $validator->check('title')->is_max(3, __('pages.title_missing')); $validator->check('slug')->is_max(3, __('pages.slug_missing'))->is_duplicate(__('pages.slug_duplicate'))->not_regex('#^[0-9_-]+$#', __('pages.slug_invalid')); if ($input['redirect']) { $validator->check('redirect')->is_url(__('pages.redirect_missing')); } if ($errors = $validator->errors()) { Input::flash(); Notify::error($errors); return Response::redirect('admin/pages/edit/' . $id); } if (empty($input['name'])) {
/** * Encode html to entities */ function e($str, $quotes = ENT_NOQUOTES) { if (is_array($str)) { $arr = array(); foreach ($str as $key => $value) { if (!is_array($value)) { $arr += array($key => e($value)); } else { $arr[$key] = e($value); } } return $arr; } return htmlspecialchars($str, $quotes, Config::app('encoding'), false); }
/** * Encode html to entities */ function e($str, $quotes = ENT_NOQUOTES) { return htmlspecialchars($str, $quotes, Config::app('encoding'), false); }
App::$cur->path = INJI_PROGRAM_DIR . '/' . App::$cur->dir; App::$cur->params = $params; App::$cur->config = Config::app(App::$cur); App::$primary = App::$cur; if (!empty($params[0]) && file_exists(INJI_SYSTEM_DIR . '/program/' . $params[0] . '/')) { App::$primary->params = []; App::$cur = new App(); App::$cur->name = $params[0]; App::$cur->system = true; App::$cur->staticPath = "/" . App::$cur->name . "/static"; App::$cur->templatesPath = "/" . App::$cur->name . "/static/templates"; App::$cur->path = INJI_SYSTEM_DIR . '/program/' . App::$cur->name; App::$cur->type = 'app' . ucfirst(strtolower(App::$cur->name)); App::$cur->installed = true; App::$cur->params = array_slice($params, 1); App::$cur->config = Config::app(App::$cur); Inji::$inst->listen('Config-change-app-' . App::$primary->name, 'primaryAppConfig', function ($event) { App::$primary->config = $event['eventObject']; return $event['eventObject']; }); } Inji::$inst->listen('Config-change-app-' . App::$cur->name, 'curAppConfig', function ($event) { App::$cur->config = $event['eventObject']; return $event['eventObject']; }); $shareConfig = Config::share(); if (empty($shareConfig['installed']) && App::$cur->name != 'setup' && (empty(App::$cur->params[0]) || App::$cur->params[0] != 'static')) { Tools::redirect('/setup'); } putenv('COMPOSER_HOME=' . getcwd()); putenv('COMPOSER_CACHE_DIR=' . getcwd() . DIRECTORY_SEPARATOR . 'composerCache');
List extend */ Route::get('admin/extend', array('before' => 'auth', 'main' => function ($page = 1) { $vars['messages'] = Notify::read(); $vars['token'] = Csrf::token(); return View::create('extend/index', $vars)->partial('header', 'partials/header')->partial('footer', 'partials/footer'); })); Route::post('admin/get_fields', array('before' => 'auth', 'main' => function () { $input = Input::get(array('id', 'pagetype')); // get the extended fields $vars['fields'] = Extend::fields('page', -1, $input['pagetype']); $html = View::create('pages/fields', $vars)->render(); $token = '<input name="token" type="hidden" value="' . Csrf::token() . '">'; return Response::json(array('token' => $token, 'html' => $html)); })); /* Upload an image */ Route::post('admin/upload', array('before' => 'auth', 'main' => function () { $uploader = new Uploader(PATH . 'content', array('png', 'jpg', 'bmp', 'gif', 'pdf')); $filepath = $uploader->upload($_FILES['file']); $uri = Config::app('url', '/') . 'content/' . basename($filepath); $output = array('uri' => $uri); return Response::json($output); })); /* 404 error */ Route::error('404', function () { return Response::error(404); });