public static function reset()
 {
     self::$arrMap = array();
     self::$arrLoaded = array();
     self::$arrStaticCollection = array();
     self::$arrScriptPool = array();
 }
示例#2
0
 public static function addHashTable($strId, $smarty)
 {
     $staticInfo = FISResource::getStaticInfo($strId, $smarty);
     if ($staticInfo['hash']) {
         self::addStatic($staticInfo['hash']);
     }
 }
 public static function setFramework($strFramework)
 {
     self::$framework = $strFramework;
 }
示例#4
0
<?php

ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
//引用静态资源管理类
require_once 'Resource.class.php';
//设置配置和模板文件夹
$root = dirname(__FILE__) . DIRECTORY_SEPARATOR;
FISResource::setConfig(array('config_dir' => $root . '/tpl/config/', 'template_dir' => $root . '/tpl/'));
//渲染首页
display("page/index.php");
示例#5
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 function testLoadAsync()
 {
     FISResource::load('common:static/common/index/index.js', new Smarty());
     $this->assertEqualsIgnoreSeparator(FISResource::getResourceMap(), '{"res":{"common:static/common/ui/async/async.js":{"url":"/static/common/ui/async/async.js","deps":[]}}}');
 }
示例#7
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;
 }