Example #1
0
 /**
  * Display firewall code
  *
  * @package     las
  * @version     1.0
  */
 public static function display($path, $vars = [])
 {
     $di = \Phalcon\DI::getDefault();
     if ($di->getShared('router')->getModuleName() == 'cli') {
         $view = $di->getShared('view');
     } else {
         $view = new \Phalcon\Mvc\View();
         $view->setDI($di);
         $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di));
     }
     $settings = json_decode(json_encode(\Las\Library\Arr::from_model(Settings::find('status=' . Settings::ACTIVE), 'name', 'value')));
     $lans = Networks::find('status = ' . Networks::ACTIVE . ' AND type = ' . Networks::LAN);
     $wans = Networks::find('status = ' . Networks::ACTIVE . ' AND type = ' . Networks::WAN);
     $vars = ['clients' => Clients::find(), 'devices' => Devices::find('status=' . Devices::ACTIVE), 'messages' => Messages::find('status=' . Messages::ACTIVE), 'tariffs' => Tariffs::find('status=' . Tariffs::ACTIVE), 'settings' => $settings, 'redirects' => Redirects::find('status=' . Redirects::ACTIVE), 'services' => Services::find('status=' . Services::ACTIVE . ' AND client_id=0 AND device_id=0'), 'lans' => $lans, 'lan' => $lans->getFirst(), 'wans' => $wans, 'wan' => $wans->getFirst(), 'ipt' => $settings->iptables, 'tc' => $settings->tc, 'EOL' => PHP_EOL];
     $view->setViewsDir(ROOT_PATH . '/app/common/cache/volt/app/cli/views/');
     ob_start();
     $view->partial($path, $vars);
     return preg_replace(['/^\\s+|^[\\t\\s]*\\n+/m', "/\r/"], '', ob_get_clean());
     //return preg_replace('/^\s+|^[\t\s]*\n+/m', "/\x0D/"], '', $view->partial($path, $vars, false));
 }
Example #2
0
 /**
  * Generate a new View object with preset parameters.
  *
  * @param array $options
  * @param \Phalcon\DiInterface $di
  * @return \Phalcon\Mvc\View
  */
 public static function getView($options = array(), \Phalcon\DiInterface $di = null)
 {
     if ($di == null) {
         $di = \Phalcon\Di::getDefault();
     }
     $defaults = array('base_dir' => FA_INCLUDE_BASE . '/', 'views_dir' => 'modules/frontend/views/scripts/', 'partials_dir' => '', 'layouts_dir' => '../../../../templates/', 'layout' => 'main');
     $options = array_merge($defaults, (array) $options);
     // Temporary fix to force "views_dir" to be the full path, because "base_dir" is not used in some Phalcon calculations.
     $options['views_dir'] = $options['base_dir'] . $options['views_dir'];
     $options['base_dir'] = '';
     $view = new \Phalcon\Mvc\View();
     $view->setDI($di);
     $eventsManager = new \Phalcon\Events\Manager();
     $view->setEventsManager($eventsManager);
     // Base directory from which all views load.
     $view->setBasePath($options['base_dir']);
     $view->setViewsDir($options['views_dir']);
     // Relative path of main templates.
     $view->setLayoutsDir($options['layouts_dir']);
     $view->setTemplateAfter($options['layout']);
     // Use present directory for partials by default.
     $view->setPartialsDir($options['partials_dir']);
     // Register template engines.
     $view->registerEngines(array(".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Php', ".volt" => function ($view, $di) {
         $volt = new Volt($view, $di);
         $volt->setOptions(array('compileAlways' => FA_APPLICATION_ENV == 'development', 'compiledPath' => function ($templatePath) {
             // Clean up the template path and remove non-application folders from path.
             $templatePath = realpath($templatePath);
             $templatePath = ltrim(str_replace(FA_INCLUDE_BASE, '', $templatePath), '/');
             $find_replace = array('/views/scripts/' => '_', '../' => '', '/' => '_', '.volt' => '');
             $templatePath = str_replace(array_keys($find_replace), array_values($find_replace), $templatePath);
             return FA_INCLUDE_CACHE . '/volt_' . $templatePath . '.compiled.php';
         }));
         $compiler = $volt->getCompiler();
         $compiler->addExtension(new \FA\Phalcon\Service\ViewHelper());
         return $volt;
     }));
     return $view;
 }
Example #3
0
 /**
  * Generate a new View object with preset parameters.
  *
  * @param array $options
  * @param \Phalcon\DiInterface $di
  * @return \Phalcon\Mvc\View
  */
 public static function getView($options = array(), \Phalcon\DiInterface $di = null)
 {
     if ($di == null) {
         $di = \Phalcon\Di::getDefault();
     }
     $defaults = array('base_dir' => DF_INCLUDE_BASE . '/', 'views_dir' => 'modules/frontend/views/scripts/', 'partials_dir' => '', 'layouts_dir' => '../../../../templates/', 'layout' => 'main');
     $options = array_merge($defaults, (array) $options);
     $view = new \Phalcon\Mvc\View();
     $view->setDI($di);
     $eventsManager = new \Phalcon\Events\Manager();
     $view->setEventsManager($eventsManager);
     // Base directory from which all views load.
     $view->setBasePath($options['base_dir']);
     $view->setViewsDir($options['views_dir']);
     // Relative path of main templates.
     $view->setLayoutsDir($options['layouts_dir']);
     $view->setTemplateAfter($options['layout']);
     // Use present directory for partials by default.
     $view->setPartialsDir($options['partials_dir']);
     // Register template engines.
     $view->registerEngines(array(".phtml" => 'Phalcon\\Mvc\\View\\Engine\\Php', ".volt" => function ($view, $di) {
         $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
         $volt->setOptions(array('compiledPath' => function ($templatePath) {
             $find_replace = array(DF_INCLUDE_BASE => '', '/modules/' => '', '/views/scripts/' => '_', '/' => '_');
             $templatePath = str_replace(array_keys($find_replace), array_values($find_replace), $templatePath);
             return DF_INCLUDE_CACHE . '/volt_' . $templatePath . '.compiled.php';
         }));
         $compiler = $volt->getCompiler();
         $compiler->addFunction('helper', function ($resolvedArgs, $exprArgs) use($di) {
             return '$this->viewHelper->handle(' . $resolvedArgs . ')';
         });
         return $volt;
     }));
     // Register global escaper.
     $view->setVar('e', new \Phalcon\Escaper());
     return $view;
 }
Example #4
0
 public function testTwigMixedEnginePartials()
 {
     if ($this->_loadTwig() == false) {
         return;
     }
     $di = new Phalcon\DI();
     $view = new Phalcon\Mvc\View();
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->registerEngines(array('.twig' => 'My_Twig_Engine', '.phtml' => 'Phalcon\\Mvc\\View\\Engine\\Php'));
     $view->setParamToView('name', 'Sonny');
     $view->start();
     $view->setRenderLevel(Phalcon\Mvc\View::LEVEL_LAYOUT);
     $view->render('test12', 'info');
     $view->finish();
     $this->assertEquals($view->getContent(), 'Well, this is the view content: Hello Sonny.');
 }
 public function testVoltEngineBuiltInFunctions()
 {
     @unlink('unit-tests/views/test11/index.volt.php');
     $di = new Phalcon\DI();
     $view = new Phalcon\Mvc\View();
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $view->registerEngines(array('.volt' => 'Phalcon\\Mvc\\View\\Engine\\Volt'));
     $view->setVar('arr', array(1, 2, 3, 4));
     $view->setVar('obj', new SomeObject(array(1, 2, 3, 4)));
     $view->setVar('str', 'hello');
     $view->setVar('no_str', 1234);
     $view->start();
     $view->render('test11', 'index');
     $view->finish();
     $this->assertEquals($view->getContent(), 'Length Array: 4Length Object: 4Length String: 5Length No String: 4Slice Array: 1,2,3,4Slice Array: 2,3Slice Array: 1,2,3Slice Object: 2,3,4Slice Object: 2,3Slice Object: 1,2Slice String: helSlice String: elSlice String: lloSlice No String: 123Slice No String: 23Slice No String: 34');
 }
Example #6
-1
 public function testViewOptions()
 {
     $config = array('cache' => array('service' => 'otherCache'));
     $di = new Phalcon\DI();
     $di->set('otherCache', function () {
         $frontend = new Phalcon\Cache\Frontend\Output(array('lifetime' => 60));
         return new Phalcon\Cache\Backend\File($frontend, array('cacheDir' => 'unit-tests/cache/'));
     });
     $view = new Phalcon\Mvc\View($config);
     $view->setDI($di);
     $view->setViewsDir('unit-tests/views/');
     $date = date("r");
     $content = '<html>' . $date . '</html>' . PHP_EOL;
     $view->setVar("date", $date);
     $view->start();
     $view->cache(true);
     $view->render('test8', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), $content);
     $view->reset();
     sleep(1);
     $view->setVar("date", date("r"));
     $view->start();
     $view->cache(true);
     $view->render('test8', 'other');
     $view->finish();
     $this->assertEquals($view->getContent(), $content);
 }