Exemplo n.º 1
5
 public static function setFRender()
 {
     self::$fsFinish = true;
 }
Exemplo n.º 2
0
 public static function display($html)
 {
     $html = self::insertPageletGroup($html);
     $pagelets = self::$_pagelets;
     $mode = self::$mode;
     $res = array();
     //合并资源
     foreach (self::$inner_widget[$mode] as $item) {
         $res = self::merge_resource($res, $item);
     }
     if ($mode != self::MODE_NOSCRIPT) {
         //add cdn
         foreach ((array) $res['js'] as $key => $js) {
             $res['js'][$key] = self::getCdn() . $js;
         }
         foreach ((array) $res['css'] as $key => $css) {
             $res['css'][$key] = self::getCdn() . $css;
         }
     }
     //tpl信息没有必要打到页面
     switch ($mode) {
         case self::MODE_NOSCRIPT:
             //渲染widget以外静态文件
             $all_static = FISResource::getArrStaticCollection();
             $all_static = self::merge_resource($all_static, $res);
             $html = self::renderStatic($html, $all_static, true);
             break;
         case self::MODE_QUICKLING:
             header('Content-Type: text/json;charset: utf-8');
             if ($res['script']) {
                 $res['script'] = convertToUtf8(implode("\n", $res['script']));
             }
             if ($res['style']) {
                 $res['style'] = convertToUtf8(implode("\n", $res['style']));
             }
             foreach ($pagelets as &$pagelet) {
                 $pagelet['html'] = convertToUtf8(self::insertPageletGroup($pagelet['html']));
             }
             unset($pagelet);
             /*********************autopack *****************************/
             $jsCode = FISAutoPack::getCountUrl();
             if ($jsCode != "" && !$_GET['fis_widget']) {
                 $res['script'] = $res['script'] ? $res['script'] . $jsCode : $jsCode;
             }
             /*********************autopack end************************/
             $title = convertToUtf8(self::$_title);
             $html = json_encode(array('title' => $title, 'pagelets' => $pagelets, 'resource_map' => $res));
             break;
         case self::MODE_BIGPIPE:
             $external = FISResource::getArrStaticCollection();
             $page_script = $external['script'];
             unset($external['script']);
             $html = self::renderStatic($html, $external, true);
             $html .= "\n";
             $html .= '<script type="text/javascript">';
             $html .= 'BigPipe.onPageReady(function() {';
             $html .= implode("\n", $page_script);
             $html .= '});';
             $html .= '</script>';
             $html .= "\n";
             if ($res['script']) {
                 $res['script'] = convertToUtf8(implode("\n", $res['script']));
             }
             if ($res['style']) {
                 $res['style'] = convertToUtf8(implode("\n", $res['style']));
             }
             $html .= "\n";
             foreach ($pagelets as $index => $pagelet) {
                 $id = '__cnt_' . $index;
                 $html .= '<code style="display:none" id="' . $id . '"><!-- ';
                 $html .= str_replace(array('\\', '-->'), array('\\\\', '--\\>'), self::insertPageletGroup($pagelet['html']));
                 unset($pagelet['html']);
                 $pagelet['html_id'] = $id;
                 $html .= ' --></code>';
                 $html .= "\n";
                 $html .= '<script type="text/javascript">';
                 $html .= "\n";
                 $html .= 'BigPipe.onPageletArrived(';
                 $html .= json_encode($pagelet);
                 $html .= ');';
                 $html .= "\n";
                 $html .= '</script>';
                 $html .= "\n";
             }
             $html .= '<script type="text/javascript">';
             $html .= "\n";
             $html .= 'BigPipe.register(';
             if (empty($res)) {
                 $html .= '{}';
             } else {
                 $html .= json_encode($res);
             }
             $html .= ');';
             $html .= "\n";
             $html .= '</script>';
             break;
     }
     return $html;
 }
 public static function renderScriptPool()
 {
     $html = '';
     if (!empty(self::$arrScriptPool)) {
         $priorities = array_keys(self::$arrScriptPool);
         rsort($priorities);
         foreach ($priorities as $priority) {
             $html .= '<script type="text/javascript">!function(){' . implode("}();\n!function(){", self::$arrScriptPool[$priority]) . '}();</script>';
         }
     }
     /**************autopack getCountUrl for sending log*********************/
     if (class_exists('FISAutoPack')) {
         $jsCode = FISAutoPack::getCountUrl();
         if ($jsCode != "") {
             $html .= '<script type="text/javascript">' . $jsCode . '</script>';
         }
     }
     /**************autopack end*********************/
     return $html;
 }
Exemplo n.º 4
0
 public static function display($html)
 {
     $html = self::insertPageletGroup($html);
     $pagelets = self::$_pagelets;
     $mode = self::$mode;
     $res = array('js' => array(), 'css' => array(), 'script' => array(), 'style' => array(), 'async' => array('res' => array(), 'pkg' => array()));
     //{{{
     foreach (self::$inner_widget[$mode] as $item) {
         foreach ($res as $key => $val) {
             if (isset($item[$key]) && is_array($item[$key])) {
                 if ($key != 'async') {
                     $arr = array_merge($res[$key], $item[$key]);
                     $arr = array_merge(array_unique($arr));
                 } else {
                     $arr = array('res' => array_merge($res['async']['res'], (array) $item['async']['res']), 'pkg' => array_merge($res['async']['pkg'], (array) $item['async']['pkg']));
                 }
                 //合并收集
                 $res[$key] = $arr;
             }
         }
     }
     //if empty, unset it!
     foreach ($res as $key => $val) {
         if (empty($val)) {
             unset($res[$key]);
         }
     }
     //}}}
     //tpl信息没有必要打到页面
     switch ($mode) {
         case self::MODE_NOSCRIPT:
             //渲染widget以外静态文件
             $all_static = FISResource::getArrStaticCollection();
             $html = self::renderStatic($html, $all_static, true);
             break;
         case self::MODE_QUICKLING:
             header('Content-Type: text/plain;');
             if ($res['script']) {
                 $res['script'] = implode("\n", $res['script']);
             }
             if ($res['style']) {
                 $res['style'] = implode("\n", $res['style']);
             }
             foreach ($pagelets as &$pagelet) {
                 $pagelet['html'] = self::insertPageletGroup($pagelet['html']);
             }
             unset($pagelet);
             /*********************autopack *****************************/
             $jsCode = FISAutoPack::getCountUrl($res);
             if ($jsCode != "" && !$_GET['fis_widget']) {
                 $res['script'] = $res['script'] ? $res['script'] . $jsCode : $jsCode;
             }
             /*********************autopack end************************/
             //开放api
             if ($_GET["method"] === "jsonp") {
                 $html = "hao123.process(" . json_encode(array('title' => self::$_title, 'pagelets' => $pagelets, 'resource_map' => $res)) . ",'" . $_GET['containerId'] . "')";
                 //正常模式
             } else {
                 $html = json_encode(array('title' => self::$_title, 'pagelets' => $pagelets, 'resource_map' => $res));
             }
             break;
         case self::MODE_BIGPIPE:
             $external = FISResource::getArrStaticCollection();
             $page_script = $external['script'];
             unset($external['script']);
             $html = self::renderStatic($html, $external, true);
             $html .= "\n";
             $html .= '<script type="text/javascript">';
             $html .= 'BigPipe.onPageReady(function() {';
             $html .= implode("\n", $page_script);
             $html .= '});';
             $html .= '</script>';
             $html .= "\n";
             if ($res['script']) {
                 $res['script'] = implode("\n", $res['script']);
             }
             if ($res['style']) {
                 $res['style'] = implode("\n", $res['style']);
             }
             $html .= "\n";
             foreach ($pagelets as $index => $pagelet) {
                 $id = '__cnt_' . $index;
                 $html .= '<code style="display:none" id="' . $id . '"><!-- ';
                 $html .= str_replace(array('\\', '-->'), array('\\\\', '--\\>'), self::insertPageletGroup($pagelet['html']));
                 unset($pagelet['html']);
                 $pagelet['html_id'] = $id;
                 $html .= ' --></code>';
                 $html .= "\n";
                 $html .= '<script type="text/javascript">';
                 $html .= "\n";
                 $html .= 'BigPipe.onPageletArrived(';
                 $html .= json_encode($pagelet);
                 $html .= ');';
                 $html .= "\n";
                 $html .= '</script>';
                 $html .= "\n";
             }
             $html .= '<script type="text/javascript">';
             $html .= "\n";
             $html .= 'BigPipe.register(';
             if (empty($res)) {
                 $html .= '{}';
             } else {
                 $html .= json_encode($res);
             }
             $html .= ');';
             $html .= "\n";
             $html .= '</script>';
             break;
     }
     return $html;
 }