public static function form_for($context, $options) { Router::getInstance()->view->context->push($context); $html = static::form($context, $options); Router::getInstance()->view->context->pop(); return $html; }
public static function form_for($context, $options) { Router::getInstance()->view->context->push($context); $html = \Hook\Framework\BlockHelper::form($context, $options); Router::getInstance()->view->context->pop(); return $html; }
/** * url * @static * @param string $segments segments * @param array $options options * @return Database\CollectionDelegator */ public static function url($segments, $options = array()) { $request = Router::getInstance()->request; $options['X-App-Id'] = Context::getKey()->app_id; $options['X-App-Key'] = Context::getKey()->key; $segments .= '?' . http_build_query($options); return $request->getUrl() . $request->getScriptName() . '/' . $segments; }
public function getPaginationView($paginator, $view) { $links = array(); $current_page = $paginator->getCurrentPage(); $inside_window = true; for ($i = 1; $i < $paginator->getLastPage(); $i++) { $next_inside_window = abs($current_page - $i) <= $this->window; if ($inside_window || $next_inside_window) { array_push($links, array('i' => $i, 'label' => $i, 'current' => $i == $current_page, 'inside_window' => $next_inside_window)); } $inside_window = $next_inside_window; } $instance = Router::getInstance()->view; $instance->setData(array('first' => true, 'last' => array('i' => $paginator->getLastPage()), 'links' => $links)); return $instance->fetch("pagination/links"); }
public function show404() { if (Request::isPost()) { $page = App::collection(self::PAGES_COLLECTION)->create(Input::get('page')); Request::redirect($page->slug); } $layouts = array(); $layout_files = glob(Router::config('paths')['root'] . 'app/views/layouts/*'); foreach ($layout_files as $layout_file) { $layout_ext = pathinfo($layout_file, PATHINFO_EXTENSION); $layout_name = basename($layout_file, '.' . $layout_ext); $words = preg_split('/_/', $layout_name); $layout_label = join(' ', array_map(function ($word) { return ucfirst($word); }, $words)); $layouts[$layout_name] = $layout_label; } $this->render('cms/404', array('request_path' => Request::path(), 'layouts' => $layouts)); }
public static function select($args, $attributes) { $options = array_remove($attributes, 'options'); $selected_option = array_remove($attributes, 'selected'); if (!isset($attributes['name']) && isset($args[0])) { // TODO: analyse context recursively if (Router::getInstance()->view->context->count() > 0) { $attributes['name'] = Router::getInstance()->view->context->top() . '[' . $args[0] . ']'; } else { $attributes['name'] = $args[0]; } } $html_options = ''; foreach ($options as $key => $value) { $key = isset($value['_id']) ? $value['_id'] : $key; $value = isset($value['name']) ? $value['name'] : $value; $is_selected = $selected_option == $key ? ' selected="selected"' : ''; $html_options .= '<option value="' . $key . '"' . $is_selected . '>' . $value . '</option>'; } return array('<select' . html_attributes($attributes) . '>' . $html_options . '</select>', 'raw'); }
/** * shared_storage_dir * * @param mixed $relative * @param mixed $app_id */ function shared_storage_dir() { $paths = Router::config('paths'); return $paths['shared_storage']; }
public static function mounted($path) { return Router::mount('/admin', '\\Hook\\Admin\\Controllers\\AdminController'); }
/** * config * * @param mixed $name * * @return string */ public static function config($name) { return Router::getInstance()->config($name); }
public static function mounted($path) { Router::mount("{$path}/pages", 'Hook\\CMS\\Controllers\\PageController'); }
public static function notice($message) { return Router::getInstance()->log->notice("[NOTICE] " . to_json($message)); }
/** * view * * @param mixed $template * @param array $data */ protected function render($template, $data = array()) { Router::getInstance()->render($template, $data); $response = ob_get_contents(); return ob_get_clean(); }
/** * Add Hook Middlewares to Slim instance. * @param \Slim\Slim * @return \Slim\Slim; */ public static function mounted($path) { $app = Router::getInstance(); // Setup middlewares $app->add(new Middlewares\ResponseTypeMiddleware()); $app->add(new Middlewares\ChannelMiddleware()); $app->add(new Middlewares\LogMiddleware()); $app->add(new Middlewares\AuthMiddleware()); // $app->add(new Middlewares\SessionMiddleware()); $app->add(new Middlewares\AppMiddleware()); $app->add(new Middlewares\MethodOverride()); // System $app->get($path . 'system/time', 'Hook\\Controllers\\SystemController:time'); $app->get($path . 'system/ip', 'Hook\\Controllers\\SystemController:ip'); // Collections $app->get($path . 'collection/:name', 'Hook\\Controllers\\CollectionController:index'); $app->post($path . 'collection/:name', 'Hook\\Controllers\\CollectionController:store'); $app->get($path . 'collection/:name/:id', 'Hook\\Controllers\\CollectionController:show'); $app->put($path . 'collection/:name', 'Hook\\Controllers\\CollectionController:put'); $app->put($path . 'collection/:name/:id', 'Hook\\Controllers\\CollectionController:put'); $app->post($path . 'collection/:name/:id', 'Hook\\Controllers\\CollectionController:post'); $app->delete($path . 'collection/:name(/:id)', 'Hook\\Controllers\\CollectionController:delete'); // Auth $app->get($path . 'auth', 'Hook\\Controllers\\AuthController:show'); $app->post($path . 'auth/email', 'Hook\\Controllers\\AuthController:register'); $app->post($path . 'auth/email/login', 'Hook\\Controllers\\AuthController:login'); $app->post($path . 'auth/email/forgotPassword', 'Hook\\Controllers\\AuthController:forgotPassword'); $app->post($path . 'auth/email/resetPassword', 'Hook\\Controllers\\AuthController:resetPassword'); $app->post($path . 'auth/update', 'Hook\\Controllers\\AuthController:update'); // OAuth $app->get($path . 'oauth/relay_frame', 'Hook\\Controllers\\OAuthController:relay_frame'); $app->get($path . 'oauth/:strategy(/:callback)', 'Hook\\Controllers\\OAuthController:auth'); $app->post($path . 'oauth/callback', 'Hook\\Controllers\\OAuthController:auth'); // Key/Value $app->get($path . 'key/:name', 'Hook\\Controllers\\KeyValueController:show'); $app->post($path . 'key/:name', 'Hook\\Controllers\\KeyValueController:store'); $app->delete($path . 'key/:name', 'Hook\\Controllers\\KeyValueController:delete'); // Channels $app->get($path . 'channel/:name+', 'Hook\\Controllers\\ChannelController:index'); $app->post($path . 'channel/:name+', 'Hook\\Controllers\\ChannelController:store'); // Push Notifications $app->post($path . 'push/registration', 'Hook\\Controllers\\PushNotificationController:store'); $app->delete($path . 'push', 'Hook\\Controllers\\PushNotificationController:delete'); $app->get($path . 'push/notify', 'Hook\\Controllers\\PushNotificationController:notify'); // Application management $app->get($path . 'apps', 'Hook\\Controllers\\ApplicationController:index'); $app->post($path . 'apps', 'Hook\\Controllers\\ApplicationController:create'); $app->delete($path . 'apps', 'Hook\\Controllers\\ApplicationController:delete'); $app->delete($path . 'apps/cache', 'Hook\\Controllers\\ApplicationController:delete_cache'); $app->get($path . 'apps/logs', 'Hook\\Controllers\\ApplicationController:logs'); $app->get($path . 'apps/tasks', 'Hook\\Controllers\\ApplicationController:tasks'); $app->post($path . 'apps/tasks', 'Hook\\Controllers\\ApplicationController:recreate_tasks'); $app->get($path . 'apps/deploy', 'Hook\\Controllers\\ApplicationController:dump_deploy'); $app->post($path . 'apps/deploy', 'Hook\\Controllers\\ApplicationController:deploy'); $app->get($path . 'apps/configs', 'Hook\\Controllers\\ApplicationController:configs'); $app->get($path . 'apps/keys', 'Hook\\Controllers\\ApplicationController:keys'); $app->get($path . 'apps/modules', 'Hook\\Controllers\\ApplicationController:modules'); $app->get($path . 'apps/schema', 'Hook\\Controllers\\ApplicationController:schema'); $app->post($path . 'apps/schema', 'Hook\\Controllers\\ApplicationController:upload_schema'); $app->post($path . 'apps/evaluate', 'Hook\\Controllers\\ApplicationController:evaluate'); $app->notFound(function () use($app) { echo json_encode(array('error' => 'not_found')); }); // // Output exceptions as JSON {'error':'message'} // $app->error(function ($e) use($app) { echo json_encode(array('error' => $e->getMessage())); }); return $app; }
$connection = $capsule->connection(); class_alias('\\Illuminate\\Database\\Eloquent\\Model', 'DLModel'); } // // Setup default date format // Use a string representing an RFC2822 or ISO 8601 date // http://tools.ietf.org/html/rfc2822#page-14 // \Carbon\Carbon::setToStringFormat('Y-m-d\\TH:i:sP'); // Setup paginator $connection->setPaginator(new Hook\Pagination\Environment()); // Setup Schema Grammar // $connection->setSchemaGrammar(); // Setup cache manager $connection->setCacheManager(function () { $cache_driver = Router::config('cache'); if ($cache_driver == "filesystem") { $config = array('files' => new \Illuminate\Filesystem\Filesystem(), 'config' => array('cache.driver' => 'file', 'cache.path' => storage_dir() . '/cache')); } else { if ($cache_driver == "database") { $config = array('db' => \DLModel::getConnectionResolver(), 'encrypter' => Hook\Security\Encryption\Encrypter::getInstance(), 'config' => array('cache.driver' => 'database', 'cache.connection' => 'default', 'cache.table' => 'cache', 'cache.prefix' => '')); } } return new Illuminate\Cache\CacheManager($config); }); // // TODO: Create `hook migrate` command. // -------------------------------------- // // // Try to create schema.
<?php use Hook\Http\Router; $db_config = Router::config('database'); $container = new Illuminate\Container\Container(); $event_dispatcher = new Illuminate\Events\Dispatcher($container); // // Parse Database URI // Example: mysql://username:password@hostname.com/database?options=1 // if (isset($db_config['uri'])) { $parts = parse_url($db_config['uri']); if (isset($parts['query'])) { parse_str($parts['query'], $db_config); } $db_config['collation'] = 'utf8_general_ci'; $db_config['charset'] = 'utf8'; $db_config['driver'] = $parts['scheme']; $db_config['host'] = $parts['host']; if (isset($parts['user'])) { $db_config['username'] = $parts['user']; } if (isset($parts['pass'])) { $db_config['password'] = $parts['pass']; } if (isset($parts['path'])) { $db_config['database'] = substr($parts['path'], 1); } } // ------------------ // MongoDB connection