Пример #1
0
 public function display()
 {
     $render = false;
     if (\saloos::is_Ajax()) {
         $this->data->display['main'] = "content/main/layout-xhr.html";
         $this->data->display['home'] = "content/home/display-xhr.html";
         $this->data->display['cp'] = "content_cp/home/layout-xhr.html";
         $this->data->display['account'] = "content_account/home/layout-xhr.html";
         if ($this->method_exists("pushState")) {
             $this->ipushState();
         }
     }
     $module = preg_replace("/^[^\\/]*\\/?content/", "content", get_class($this->controller));
     $module = preg_replace("/^content\\\\|(model|view|controller)\$/", "", $module);
     $module = preg_replace("/[\\\\]/", "/", $module);
     $a_repository = preg_split("/[\\/]/", router::get_repository(), -1, PREG_SPLIT_NO_EMPTY);
     $repository = end($a_repository);
     $repository = $repository === 'content' ? $repository . '/' : null;
     // $tmpname      = ($this->controller()->display_name)? $this->controller()->display_name : $repository.'/'.$module.'display.html';
     $tmpname = $this->controller()->display_name ? $this->controller()->display_name : $repository . $module . 'display.html';
     // ************************************************************************************ Twig
     // twig method
     $this->add_twig_filter('fcache');
     $this->add_twig_filter('jdate');
     $this->add_twig_filter('tdate');
     $this->add_twig_filter('sdate');
     $this->add_twig_filter('readableSize');
     $this->add_twig_filter('persian');
     $this->add_twig_filter('humantime');
     $this->add_twig_filter('exist');
     $this->add_twig_filter('decode');
     $this->add_twig_function('breadcrumb');
     $this->add_twig_function('posts');
     require_once core . 'Twig/lib/Twig/Autoloader.php';
     \Twig_Autoloader::register();
     $loader = new \Twig_Loader_Filesystem($this->twig_include_path);
     $array_option = array();
     if ($this->controller()->debug()) {
         $array_option['debug'] = true;
     }
     // twig var_dump filter for dumping value
     $filter_dump = new \Twig_SimpleFilter('dump', 'var_dump');
     // Delete a key of an array
     $filter_unset_type = new \Twig_SimpleFilter('unset_type', function ($array = null) {
         unset($array['attr']['type']);
         return $array;
     });
     $twig = new \Twig_Environment($loader, $array_option);
     $twig->addFilter($filter_dump);
     // add a new filter to twig
     $twig->addFilter($filter_unset_type);
     // add a new filter to twig
     $twig->addGlobal("session", $_SESSION);
     if ($this->controller()->debug()) {
         $twig->addExtension(new \Twig_Extension_Debug());
     } else {
         $this->add_twig_function('dump');
     }
     $twig->addExtension(new \Twig_Extensions_Extension_I18n());
     $this->twig_Extentions($twig);
     $template = $twig->loadTemplate($tmpname);
     if (\saloos::is_Ajax()) {
         $this->data->global->debug = \lib\debug::compile();
         $req = apache_request_headers();
         $xhr_render = $template->render($this->data->_toArray());
         // $this->data->display['mvc'] = $this->data->display['xhr'];
         $md5 = md5(json_encode($this->data->global) . $xhr_render);
         if (isset($req['Cached-MD5']) && $req['Cached-MD5'] == $md5) {
             echo json_encode(array("getFromCache" => true));
         } else {
             // $this->data->global->md5 = $md5;
             echo json_encode($this->data->global);
             echo "\n";
             echo $xhr_render;
         }
     } else {
         $template->display($this->data->_toArray());
     }
 }
Пример #2
0
 /**
  * [_processor description]
  * @param  boolean $options [description]
  * @return [type]           [description]
  */
 public function _processor($options = false)
 {
     if (is_array($options)) {
         $options = (object) $options;
     }
     $force_json = gettype($options) == 'object' && isset($options->force_json) && $options->force_json ? true : false;
     $force_stop = gettype($options) == 'object' && isset($options->force_stop) && $options->force_stop ? true : false;
     $not_redirect = gettype($options) == 'object' && isset($options->not_redirect) && $options->not_redirect ? true : false;
     if ($not_redirect) {
         $this->controller()->redirector = false;
     }
     if (\saloos::is_json_accept() || $force_json) {
         header('Content-Type: application/json');
         if (isset($this->controller()->redirector) && $this->controller()->redirector) {
             $_SESSION['debug'][md5(strtok($this->redirector()->redirect(true), '?'))] = debug::compile();
             debug::msg("redirect", $this->redirector()->redirect(true));
         }
         echo debug::compile(true);
     } elseif (!\lib\router::get_storage('api') && strtolower($_SERVER['REQUEST_METHOD']) == "post") {
         $this->redirector();
     }
     if (isset($this->controller()->redirector) && $this->controller()->redirector && !\saloos::is_json_accept()) {
         $_SESSION['debug'][md5(strtok($this->redirector()->redirect(true), '?'))] = debug::compile();
         $this->redirector()->redirect();
     }
     if ($force_stop) {
         exit;
     }
 }