Exemple #1
0
 /**
  * Register specific services for the module
  *
  * @package     las
  * @version     1.0
  *
  * @param object $di dependency Injector
  *
  * @return void
  */
 public function registerServices($di)
 {
     //Registering a dispatcher
     $di->set('dispatcher', function () {
         //Create/Get an EventManager
         $eventsManager = new \Phalcon\Events\Manager();
         //Attach a listener
         $eventsManager->attach("dispatch", function ($event, $dispatcher, $exception) {
             //controller or action doesn't exist
             if ($event->getType() == 'beforeException') {
                 switch ($exception->getCode()) {
                     case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
                     case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                         $dispatcher->forward(array('controller' => 'index', 'action' => 'notFound'));
                         return false;
                 }
             }
         });
         $dispatcher = new \Phalcon\Mvc\Dispatcher();
         //Set default namespace to doc module
         $dispatcher->setDefaultNamespace("Las\\Doc\\Controllers");
         //Bind the EventsManager to the dispatcher
         $dispatcher->setEventsManager($eventsManager);
         return $dispatcher;
     });
     //Registering the view component
     $di->set('view', function () use($di) {
         $view = new \Phalcon\Mvc\View();
         $view->setViewsDir(__DIR__ . '/views/');
         $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di));
         return $view;
     });
 }
Exemple #2
0
 /**
  * Minify css and js collection
  *
  * @package     las
  * @version     1.0
  */
 public function assetAction()
 {
     foreach (array('css', 'js') as $asset) {
         foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_PATH . '/public/' . $asset, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
             if (!$item->isDir() && ($item->getExtension() == 'css' || $item->getExtension() == 'js')) {
                 $subPath = $iterator->getSubPathName();
                 $dir = strstr($subPath, $item->getFilename(), true);
                 $add = 'add' . ucfirst($asset);
                 $this->assets->{$add}($asset . '/' . $dir . $item->getFilename());
             }
         }
     }
     // Minify css and js collection
     \Las\Library\Tool::assetsMinification();
 }
Exemple #3
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));
 }
Exemple #4
0
 /**
  * Catch the exception and log it, display pretty view
  *
  * @package     las
  * @version     1.0
  *
  * @param \Exception $e
  */
 public static function exception(\Exception $e)
 {
     $config = \Phalcon\DI::getDefault()->getShared('config');
     $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n");
     if ($config->app->env == "development") {
         // Display debug output
         echo Dump::all($errors);
     } else {
         // Display pretty view of the error
         $di = new \Phalcon\DI\FactoryDefault();
         $view = new \Phalcon\Mvc\View\Simple();
         $view->setDI($di);
         $view->setViewsDir(ROOT_PATH . '/app/frontend/views/');
         $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di));
         echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config));
         // Log errors to file and send email with errors to admin
         \Las\Bootstrap::log($errors);
     }
 }
Exemple #5
0
 /**
  * After Action
  *
  * @package     las
  * @version     1.0
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title and description
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     $this->view->setVar('site_desc', mb_substr($this->filter->sanitize($this->site_desc, 'string'), 0, 200, 'utf-8'));
     // Set scripts
     $this->scripts = ['$(document).ready(function() { $("pre code").each(function(i, e) {hljs.highlightBlock(e)}); });'];
     $this->view->setVar('scripts', $this->scripts);
     // Minify css and js collection
     \Las\Library\Tool::assetsMinification();
 }
Exemple #6
0
 /**
  * After Action
  *
  * @package     las
  * @version     1.0
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     // Set scripts
     $this->scripts[] = '$("#nav-' . $this->dispatcher->getControllerName() . '").collapse()';
     $this->view->setVar('scripts', $this->scripts);
     // Minify css and js collection
     \Las\Library\Tool::assetsMinification();
     $this->view->setVars(['action' => $this->dispatcher->getActionName(), 'controller' => $this->dispatcher->getControllerName()]);
 }
Exemple #7
0
 /**
  * After Action
  *
  * @package     las
  * @version     1.0
  */
 public function afterExecuteRoute($dispatcher)
 {
     // Set final title and description
     $this->tag->setTitleSeparator(' | ');
     $this->tag->appendTitle($this->config->app->name);
     $this->view->setVar('site_desc', mb_substr($this->filter->sanitize($this->site_desc, 'string'), 0, 200, 'utf-8'));
     // Set scripts
     $this->view->setVar('scripts', $this->scripts);
     // Minify css and js collection
     \Las\Library\Tool::assetsMinification();
 }