Пример #1
0
 public function register()
 {
     $this->container->add('service.http.request', function () {
         return Request::createFromGlobals();
     });
     $this->container->add('service.http.route', function () {
         $route = new Route($this->container);
         foreach ($this->container->get('config')['http']['routes'] as $item) {
             $route->addRoute(strtoupper($item['method']), $item['path'], $item['target']);
         }
         return $route;
     });
     $this->container->add('Symfony\\Component\\HttpFoundation\\Request', function () {
         return $this->container->get('service.http.request');
     });
     $this->container->add('service.view.view', function () {
         $view = new View();
         foreach ($this->container->get('config')['http']['views_path'] as $name => $path) {
             $view->addFolder($name, $path);
         }
         $request = $this->container->get('service.http.request');
         $view->loadExtension(new RequestExtension($request));
         $view->loadExtension(new FlashBagExtension($request->getSession()->getFlashBag()));
         $view->loadExtension(new BaseUrlExtension($request->getBasePath()));
         $assetBaseUrl = $this->container->get('config')['asset_base_url'];
         $view->loadExtension(new AssetUrlExtension($assetBaseUrl));
         if ($this->container->get('service.account.auth')->hasAuthenticatedUser()) {
             $authenticatedUser = $this->container->get('service.account.auth')->getAuthenticatedUser();
             $view->loadExtension(new AuthenticatedUserExtension($authenticatedUser));
         }
         $view->addData(['applicationName' => $this->container->get('config')['application_name']]);
         return $view;
     });
 }
Пример #2
0
 private function plates()
 {
     $league = new Plates\Engine(APP . 'views');
     $league->setFileExtension('tpl');
     $league->loadExtension(new Plates\Extension\URI(trim(strtok(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['REQUEST_URI']), '?'), '/')));
     $league->loadExtension(new MY\Plates\Extension());
     return $league;
 }
 /**
  * @MethodInit()
  */
 public function init()
 {
     $this->loadDebug();
     foreach ($this->plateExtensions as $extension) {
         $this->templateEngine->loadExtension($extension);
     }
     $routes = $this->routes;
     foreach ($routes as $route) {
         $this->registerRoute($route);
     }
 }
 /**
  * MY_Controller constructor.
  */
 public function __construct()
 {
     parent::__construct();
     // Profiler only development environment
     if (ENVIRONMENT === 'development' and $this->config->item('profiler') === TRUE) {
         $this->load->add_package_path(APPPATH . 'packages/codeigniter-forensics');
         $this->output->enable_profiler(TRUE);
     }
     // Templates
     $this->template = new League\Plates\Engine(APPPATH . 'views');
     $this->template->registerFunction('CI', function () {
         return $this;
     });
     $this->template->loadExtension(new League\Plates\Extension\Asset(FCPATH));
 }
 public function __invoke(array $input)
 {
     $name = 'index';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     //		$filename = APPPATH . 'templates/static/' . $name;
     //		if (file_exists($filename)) {
     //			echo "The file $filename does not exist";
     //			die('the file does not exist');
     //		}
     // Create new Plates instance
     $plates = new Engine(APPPATH . 'templates');
     // Register extension
     $plates->loadExtension(new Utils());
     // Check static page or partial exists
     if ($plates->exists('static/' . $name)) {
         // Render a template
         $template = $plates->render('static/' . $name);
     } else {
         header("HTTP/1.0 404 Not Found");
         echo "PHP continues.\n";
         echo "Not after a die, however.\n";
         die;
     }
     // return
     return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template]);
 }
Пример #6
0
 /**
  * @param  Engine $engine
  */
 public function register(Engine $engine)
 {
     // Load the built in URI extension
     $engine->loadExtension(new URI($this->request->getPathInfo()));
     // Custom methods
     $engine->registerFunction('route', [$this, 'route']);
     $engine->registerFunction('asset', [$this, 'asset']);
 }
Пример #7
0
 /**
  * Get an instance of the Plates Engine
  *
  * @return \League\Plates\Engine
  */
 public function getInstance()
 {
     if (!$this->engineInstance) {
         $this->engineInstance = new Engine($this->templatesPath ?: $this->getTemplatesDirectory());
         if ($this->fileExtension) {
             $this->engineInstance->setFileExtension($this->fileExtension);
         }
         if (count($this->templatesFolders) > 0) {
             foreach ($this->templatesFolders as $name => $path) {
                 $this->engineInstance->addFolder($name, $path);
             }
         }
         if (count($this->parserExtensions) > 0) {
             foreach ($this->parserExtensions as $extension) {
                 $this->engineInstance->loadExtension($extension);
             }
         }
     }
     return $this->engineInstance;
 }
Пример #8
0
 public function dispatch()
 {
     // strip index.php and query string (if any) to get a real base url
     $baseUrl = preg_replace('/(index\\.php.*|\\?.*)$/', '', $_SERVER['REQUEST_URI']);
     $templates = new Engine(CURRENT_DIR . '/src/Resources/views/');
     $templates->loadExtension(new Asset(CURRENT_DIR . '/pub/', false));
     $templates->loadExtension(new URI($baseUrl));
     // Check if the user is logged-in
     if (!$this->isLoggedIn()) {
         return $this->showLogin($templates);
     }
     if (is_null($this->command)) {
         /** @var Checkpoint $checkpoint */
         $checkpoint = $this->container['utils.checkpoint'];
         $checkpoints = $checkpoint->getAll();
         $content = $templates->render('partials/inner', ['title' => 'Updater', 'version' => $this->container['application']->getVersion(), 'checkpoints' => $checkpoints]);
     } else {
         header('Content-Type: application/json');
         $content = json_encode($this->ajaxAction(), JSON_UNESCAPED_SLASHES);
     }
     return $content;
 }
Пример #9
0
 /**
  * Create instance
  *
  * @return Engine
  */
 public function create(Request $request)
 {
     $engine = new Engine($this->options['view_path'], null);
     // Add folder shortcut (assets::file.js)
     $engine->addFolder('assets', $this->options['assets_path']);
     $engine->addFolder('view', $this->options['view_path']);
     $session = $request->getAttribute(SessionMiddleware::ATTRIBUTE);
     $baseUrl = $request->getAttribute('base_url');
     // Register Asset extension
     $cacheOptions = array('cachepath' => $this->options['cache_path'], 'cachekey' => $session->get('user.locale'), 'baseurl' => $baseUrl, 'minify' => $this->options['minify']);
     $engine->loadExtension(new \Odan\Plates\Extension\AssetCache($cacheOptions));
     return $engine;
 }
Пример #10
0
 public function register(App $glue)
 {
     $glue->singleton('League\\Plates\\Engine', function ($glue) {
         if (!$glue->config->exists('plates.path')) {
             // We need a default template folder
             throw new \Exception("You must configure the plates.path");
         }
         $engine = new Engine($glue->config->get('plates.path'));
         // Register some extensions
         $engine->loadExtension($glue->make('Glue\\Plates\\Extensions\\UrlHelpers'));
         return $engine;
     });
     $glue->alias('League\\Plates\\Engine', 'plates');
 }
Пример #11
0
 public function __invoke(array $input)
 {
     $name = 'world';
     if (!empty($input['name'])) {
         $name = $input['name'];
     }
     ////////////////////
     $application = new Application();
     $application_data = $application->is_pjax();
     //print_r( '<pre>' );
     // print_r( $application_data );
     //print_r( '</pre>');
     ////////////////////
     // simple
     // Create new Plates instance
     //		$plates = new Engine(APPPATH.'templates');
     // Render a template
     // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]);
     //		$template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]);
     $data = ['friends' => ['mikka', 'makka', 'zorro']];
     //			$friends = [
     //			  ['name', 'zorro'],
     //			];
     ////////////////////
     // using folders
     // Create new Plates instance
     $plates = new Engine(APPPATH . 'templates');
     // Register a Plates extension
     $plates->loadExtension(new Utils());
     // Add folders
     $plates->addFolder('layout', APPPATH . 'templates');
     $plates->addFolder('partials', APPPATH . 'templates/partials');
     $plates->addFolder('static', APPPATH . 'templates/static');
     // assign data to plates
     $plates->addData($data, 'layout');
     // Render
     $template = $plates->render('partials::profile', ['name' => $name]);
     ////////////////////
     $invitation = 'I invite you';
     // return
     return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]);
 }
 public function prepareTemplates(Engine $template, Injector $injector)
 {
     $template->addData(['pages' => $this->getPages()]);
     $template->setFileExtension('phtml');
     $template->loadExtension(new DirectoryExtension());
 }
Пример #13
0
 /**
  * Set Asset path from Plates Asset Extension.
  *
  * @param string $assetPath
  *
  * @return \League\Plates\Engine
  */
 public function setAssetPath($assetPath)
 {
     return $this->plates->loadExtension(new Asset($assetPath, $this->settings['timestampInFilename']));
 }
Пример #14
0
 /**
  * Set Asset path from Plates Asset Extension
  *
  * @param string $assetPath
  */
 public function setAssetPath($assetPath)
 {
     return $this->plates->loadExtension(new Asset($assetPath));
 }
Пример #15
0
 /**
  * Init view assets cache
  *
  * @return void
  */
 protected static function initViewCache(Engine $view, ServiceContainer $app)
 {
     // Register Asset extension
     $options = array('cachepath' => $app->config['path']['view_cache'], 'cachekey' => $app->session->get('locale'), 'baseurl' => $app->http->getBaseUrl('/'), 'minify' => $app->config['view']['minify']);
     $view->loadExtension(new \Odan\Plates\Extension\AssetCache($options));
 }
Пример #16
0
 /**
  * setup the template engine and sends the parsed content to the engine
  *
  * @uses    \League\Plates\Extension\Asset
  * @uses    \League\Plates\Engine
  * @uses    url
  * @since   1.0
  */
 public function setup()
 {
     $engine = new Engine($this->relativePath . "include" . DS . "styles" . DS . config::init()->style);
     $engine->loadExtension(new Asset($this->relativePath . "include" . DS . "styles" . DS . config::init()->style . DS . "assets", true));
     // add infos for theme
     $this->setStyleParameter("isZipEnabled", false);
     $this->setStyleParameter("showWarnings", false);
     $breadcrumbs = $this->generateBreadcrumbs(url::GET("dir"));
     $this->setStyleParameter("breadcrumbs", $breadcrumbs);
     $this->setStyleParameter("assetspath", common::getRelativePath(getcwd(), dirname(__FILE__)) . DS . "styles" . DS . config::init()->style . DS . "assets");
     $this->setStyleParameter("title", "SimpleDirLister | " . common::fixPaths(implode(DS, array_keys($breadcrumbs))));
     $this->setStyleParameter("path", common::fixPaths(implode(DS, array_keys($breadcrumbs))));
     $this->setStyleParameter("header", config::init()->header ? file::init(config::init()->header)->getFilename() : false);
     $this->setStyleParameter("footer", config::init()->footer ? file::init(config::init()->footer)->getFilename() : false);
     $engine->addFolder('static', $this->getBasePath() . DS . config::init()->headerFooterDir);
     try {
         $files = $this->getRawPaths();
         $files = $this->cleanArray($files);
         if (config::init()->showReadme) {
             $readmeContent = [];
             foreach (config::init()->readme as $readme) {
                 if (isset($files[$readme])) {
                     $c = file_get_contents($files[$readme]["path"]);
                     $ext = pathinfo($files[$readme]["path"], PATHINFO_EXTENSION);
                     if ($ext == "md") {
                         $md = new Parsedown();
                         $readmeContent[] = '<div class="md">' . $md->text($c) . '</div>';
                     } elseif ($ext == "php") {
                         $readmeContent[] = (require $files[$readme]["path"]);
                     } else {
                         $readmeContent[] = $c;
                     }
                     if (config::init()->removeReadme) {
                         unset($files[$readme]);
                     }
                 }
             }
             $this->setStyleParameter("readme", $readmeContent);
         }
     } catch (\Exception $e) {
         $this->setStyleParameter("showWarnings", true);
         $this->setStyleParameter("warnings", [["message" => "dir not found", "type" => "danger"]]);
         $files = [];
     } finally {
         $this->setStyleParameter("files", $files);
     }
     $engine->registerFunction('fileicon', [&$this, "getIconFromSet"]);
     $this->setStyleParameter("search", url::GET("s"));
     $engine->addData($this->styleParameter);
     if (!empty(url::GET("s"))) {
         echo $engine->render("search", $this->styleParameter);
     } else {
         echo $engine->render("index", $this->styleParameter);
     }
 }
 /**
  * Inject an extension into the engine.
  *
  * Valid extension specifications include:
  *
  * - ExtensionInterface instances
  * - String service names that resolve to ExtensionInterface instances
  * - String class names that resolve to ExtensionInterface instances
  *
  * If anything else is provided, an exception is raised.
  *
  * @param ContainerInterface $container
  * @param PlatesEngine $engine
  * @param ExtensionInterface|string $extension
  * @return void
  * @throws Exception\InvalidExtensionException for non-string,
  *     non-extension $extension values.
  * @throws Exception\InvalidExtensionException for string $extension values
  *     that do not resolve to an extension instance.
  */
 private function injectExtension(ContainerInterface $container, PlatesEngine $engine, $extension)
 {
     if ($extension instanceof ExtensionInterface) {
         $engine->loadExtension($extension);
         return;
     }
     if (!is_string($extension)) {
         throw new Exception\InvalidExtensionException(sprintf('%s expects extension instances, service names, or class names; received %s', __CLASS__, is_object($extension) ? get_class($extension) : gettype($extension)));
     }
     if ($container->has($extension)) {
         $engine->loadExtension($container->get($extension));
         return;
     }
     if (class_exists($extension)) {
         $engine->loadExtension(new $extension());
         return;
     }
     throw new Exception\InvalidExtensionException(sprintf('%s expects extension service names or class names; "%s" does not resolve to either', __CLASS__, $extension));
 }