Esempio n. 1
0
 public static function addCss($url)
 {
     if (BigPipe::isOpen()) {
         self::getInstance()->cssList[$url] = 0;
     } else {
         echo '<link rel="stylesheet" type="text/css" href="' . $url . '" />';
     }
 }
Esempio n. 2
0
/**
 * smarty 块函数 script
 * 处理 {script} 标签
 *
 * @param array $params
 * @param string $content
 * @param Smarty $smarty
 * @param bool $repeat 
 * @see BigPipe::currentContext
 * @see PageletContext->addRequire
 * @see PageletContext->addRequireAsync
 * @see PageletContext->addHook
 */
function smarty_block_script($params, $content, $smarty, &$repeat)
{
    if (!$repeat && isset($content)) {
        $eventType = isset($params['on']) ? $params['on'] : "load";
        $context = BigPipe::currentContext();
        if (isset($params["sync"])) {
            $context->addRequire($eventType, $params["sync"]);
        }
        if (isset($params["async"])) {
            $context->addRequireAsync($eventType, $params["async"]);
        }
        $context->addHook($eventType, $content);
    }
}
Esempio n. 3
0
/**
 * smarty 模版函数 require
 * 处理 {require} 标签
 * @author zhangwentao <*****@*****.**>
 *
 * @param array $params
 * @param Smarty $smarty
 * @return void
 * @see BigPipeResource::registModule
 * @see BigPipe::currentContext
 * @see PageletContext->addRequire
 */
function smarty_function_require($params, $smarty)
{
    $link = $params['name'];
    unset($params['name']);
    BigPipeResource::registModule($link);
    $context = BigPipe::currentContext();
    $resource = BigPipeResource::getResourceByPath($link);
    switch ($resource["type"]) {
        case 'css':
            $on = isset($params['on']) ? $params['on'] : 'beforedisplay';
            break;
        case 'js':
            $on = isset($params['on']) ? $params['on'] : 'load';
            break;
    }
    $context->addRequire($on, $link);
}
 public static function getDependResource($resources, $asyncs = true)
 {
     $dependResources = array();
     //$dependResources = $resources;
     $depends = $resources;
     while (!empty($depends)) {
         $last = end($depends);
         array_pop($depends);
         $id = $last['id'];
         if (isset($dependResources[$id])) {
             continue;
         }
         $dependResources[$id] = $last;
         $lastDepends = self::getDepend($last, $asyncs);
         if (!empty($lastDepends)) {
             $depends = BigPipe::array_merge($depends, $lastDepends);
         }
     }
     return array_reverse($dependResources, true);
 }
Esempio n. 5
0
/**
 * smarty 块函数 script
 * 处理 {script} 标签
 * @author zhangwentao <*****@*****.**>
 *
 * @param array $params
 * @param string $content
 * @param Smarty $smarty
 * @param bool $repeat 
 * @see BigPipe::currentContext
 * @see PageletContext->addRequire
 * @see PageletContext->addRequireAsync
 * @see PageletContext->addHook
 */
function smarty_block_script($params, $content, $smarty, &$repeat)
{
    if (!$repeat && isset($content)) {
        $eventType = isset($params['on']) ? $params['on'] : "load";
        $strict = isset($params['strict']) && $params['strict'] == false ? false : true;
        $context = BigPipe::currentContext();
        if (isset($params["sync"])) {
            foreach ($params["sync"] as $resource) {
                BigPipeResource::registModule($resource);
            }
            $context->addRequire($eventType, $params["sync"]);
        }
        if (isset($params["async"])) {
            foreach ($params["async"] as $resource) {
                BigPipeResource::registModule($resource);
            }
            $context->addRequireAsync($eventType, $params["async"]);
        }
        $context->addHook($eventType, $content, $strict);
    }
}
Esempio n. 6
0
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'marquee_box';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'slide';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'top_sidebar';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'searchdoctor';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    */
    $id = 'thread';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'middle_sidebar';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'bottom_sidebar';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'appointment';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'share';
    include 'index_bigpipe_inc/pushback_pagelet.php';
    //$id = 'footer';
    //include 'index_bigpipe_inc/pushback_pagelet.php';
    $id = 'side_banner';
    include 'index_bigpipe_inc/pushback_pagelet.php';

    BigPipe::end();
}

include 'index_bigpipe_inc/index_frame_end.php';
?>
Esempio n. 7
0
?>
			  

		<h2>Content replace with external javascript file</h2>
                <div id="external_js">Be patient, this will be completed in the end after delayed rendering</div>
<?php 
$pagelet = new Pagelet('external_javascript_test');
$pagelet->add_javascript('test.js');
echo $pagelet;
?>
			  

		<h2>Content replace with external javascript and inline javascript</h2>
		<div id="external_js2">be patient, this will be completed in the end after delayed rendering test</div>
<?php 
$pagelet = new Pagelet('external_javascript_test2');
$pagelet->add_javascript('test2.js');
$pagelet->add_javascript_code("test2('external_js2', 'Ok');");
echo $pagelet;
// Inject google analytics
$pagelet = new Pagelet('google_analytics');
$pagelet->add_javascript_code(get_google_analytics_script('UA-18754626-1'));
echo $pagelet;
// Test with a pagelet which contains additional javascript payload
$pagelet = new Pagelet('final_ok');
$pagelet->add_javascript("test.js");
$pagelet->add_javascript_code("\$('header').innerHTML = 'All done';", 12);
echo $pagelet;
echo "</body>\n";
BigPipe::render();
<?php

BigPipe::loadClass("PageController");
BigPipe::loadClass("BigPipeResource");
class NoScriptController extends PageController
{
    const STAT_COLLECT = 1;
    const STAT_OUTPUT = 2;
    private $state = self::STAT_COLLECT;
    private $bodyHTML = null;
    private $bodyStyleLinks = array();
    public function __construct()
    {
        $this->actionChain = array('default' => false, 'collect_html_open' => array('outputOpenTag', true), 'collect_body_open' => array('startCollect', true), 'collect_block_open' => array('outputOpenTag', true), 'collect_block_close' => array('outputCloseTag'), 'collect_body_close' => array('collectBody'), 'collect_more' => array('changeState', true), 'output_head_open' => array('outputOpenTag', 'outputScriptReload', true), 'output_title_open' => array('outputOpenTag', true), 'output_title_close' => array('outputCloseTag'), 'output_head_close' => array('outputStyle', 'outputCloseTag'), 'output_body_open' => array('outputOpenTag', 'outputBody', false), 'output_body_close' => array('outputCloseTag'), 'output_html_close' => array('outputCloseTag'), 'output_more' => false);
    }
    protected function collectBody($context)
    {
        $this->bodyHTML = ob_get_clean();
    }
    //	protected function collectStyle($context){
    //		$this->bodyStyleLinks = array_merge($this->bodyStyleLinks, $context->styleLinks);
    //	}
    protected function outputStyle($context)
    {
        $event = $context->parent->getEvent('beforedisplay');
        if ($event != false) {
            $styleLinks = $event->requires;
            $styleResources = BigPipeResource::pathToResource($styleLinks, 'css');
            $styleResources = BigPipeResource::getDependResource($styleResources);
        }
        foreach ($styleResources as $resource) {
 /**
  * 按Quickling模式输出一个pagelet
  *
  * @param PageletContext $context
  */
 protected function outputPagelet($pagelet)
 {
     $resourceMap = array();
     $hooks = array();
     $config = $this->getPageletConfig($pagelet, $html, $resourceMap, $hooks);
     $config['quickling'] = true;
     if (!empty($hooks)) {
         foreach ($hooks as $id => $hook) {
             // echo "BigPipe.hooks[\"$id\"]=function(){{$hook}};\n";
         }
     }
     //设置资源表
     if (!empty($resourceMap)) {
         $resourceMap = BigPipeResource::pathToResource($resourceMap);
         $resourceMap = BigPipeResource::getDependResource($resourceMap);
         $resourceMap = BigPipe::array_merge($resourceMap, $this->loadedResource);
         $outputMap = array();
         foreach ($resourceMap as $id => $resource) {
             if (isset(BigPipeResource::$knownResources[$id])) {
                 continue;
             }
             $requires = $resource['requires'];
             unset($resource['requires']);
             unset($resource['requireAsyncs']);
             $requireIds = array();
             if (!empty($requires)) {
                 $requires = BigPipeResource::pathToResource($requires);
                 $requireIds = array_keys($requires);
             }
             $resource['deps'] = $requireIds;
             $resource['mods'] = $resource['defines'];
             unset($resource['defines']);
             unset($resource['id']);
             $outputMap[$id] = $resource;
             BigPipeResource::$knownResources[$id] = $resource;
         }
         //echo "BigPipe.setResourceMap(", json_encode($outputMap), ");\n";
     }
     $config["resourceMap"] = $outputMap;
     return $config;
     //echo json_encode($config);
     //输出 pagelet 配置
     //echo "BigPipe.onPageletArrive(", json_encode($config), ");\n";
     //echo "</script>";
 }
Esempio n. 10
0
 /**
  * 保存断言配置
  *
  * @static
  * @access private
  * @return void
  */
 private static function saveAssertOptions()
 {
     self::$savedAssertOptions = array();
     foreach (array(ASSERT_ACTIVE, ASSERT_WARNING, ASSERT_BAIL, ASSERT_QUIET_EVAL, ASSERT_CALLBACK) as $key) {
         self::$savedAssertOptions[] = array('key' => $key, 'val' => assert_options($key));
     }
 }
Esempio n. 11
0
/**
 * smarty 编译插件 titleclose
 *
 * 处理 {/title} 标签
 * 
 * @param array $params
 * @param Smarty $smarty 
 * @access public
 * @return string 编译后的php代码
 * @see BigPipe::compileCloseTag
 */
function smarty_compiler_titleclose($params, $smarty)
{
    return '<?php ' . '}' . 'if(' . BigPipe::compileCloseTag(BigPipe::TAG_TITLE, $params) . '){' . '?>';
}
 /**
  * 按Quickling模式输出一个pagelet
  *
  * @param PageletContext $context
  */
 protected function outputPagelet($pagelet)
 {
     $resourceMap = array();
     $hooks = array();
     $config = $this->getPageletConfig($pagelet, $html, $resourceMap, $hooks);
     $config['quickling'] = true;
     //设置资源表
     if (!empty($resourceMap)) {
         $resourceMap = BigPipeResource::pathToResource($resourceMap);
         $resourceMap = BigPipeResource::getDependResource($resourceMap);
         $resourceMap = BigPipe::array_merge($resourceMap, $this->loadedResource);
         $outputMap = array();
         foreach ($resourceMap as $id => $resource) {
             if (isset(BigPipeResource::$knownResources[$id])) {
                 continue;
             }
             $requires = $resource['requires'];
             unset($resource['requires']);
             unset($resource['requireAsyncs']);
             $requireIds = array();
             if (!empty($requires)) {
                 $requires = BigPipeResource::pathToResource($requires);
                 $requireIds = array_keys($requires);
             }
             $resource['deps'] = $requireIds;
             $resource['mods'] = $resource['defines'];
             unset($resource['defines']);
             unset($resource['id']);
             $outputMap[$id] = $resource;
             BigPipeResource::$knownResources[$id] = $resource;
         }
     }
     $config["resourceMap"] = $outputMap;
     return $config;
 }
Esempio n. 13
0
<?php
include 'content_' . $id . '.php';
BigPipe::printPagelet($id);
?>
Esempio n. 14
0
/**
 * smarty function widget
 * called by {widget} tag
 * @author zhangwentao <*****@*****.**>
 *
 * @param array $params
 * @param Smarty $template
 * @return Smarty template funtion call
 * @see BigPipeResource::registModule
 * @see BigPipeResource::getTplByPath
 * @see BigPipe::currentContext
 * @see PageletContext->addRequire
 */
function smarty_function_widget($params, $template)
{
    $name = $params['name'];
    $method = $params['method'];
    unset($params['name']);
    unset($params['method']);
    if (isset($params['call'])) {
        $call = $params['call'];
        unset($params['call']);
    }
    BigPipeResource::registModule($name);
    $tpl = BigPipeResource::getTplByPath($name);
    // Auto add widget css and less deps (no js) to currentContext.
    if (!empty($tpl["deps"])) {
        $deps = $tpl["deps"];
        $context = BigPipe::currentContext();
        foreach ($deps as $dep) {
            BigPipeResource::registModule($dep);
            $depResource = BigPipeResource::getResourceByPath($dep);
            if ($depResource["type"] === "css") {
                $on = 'beforedisplay';
                $context->addRequire($on, $dep);
            }
        }
    }
    $smarty = $template->smarty;
    $tplpath = $tpl["uri"];
    // First try to call the mothed passed via the $call param,
    // in order to made it compatible for fisp.
    if (isset($call)) {
        $call = 'smarty_template_function_' . $call;
        if (!function_exists($call)) {
            try {
                $smarty->fetch($tplpath);
            } catch (Exception $e) {
                throw new Exception("\nNo tpl here, via call \n\"{$name}\" \n@ \"{$tplpath}\"");
            }
        }
        if (function_exists($call)) {
            return $call($template, $params);
        }
    }
    // If there is no method named $call,
    // try to call mothed passed via the $method param
    $fn = 'smarty_template_function_' . $method;
    if (!function_exists($fn)) {
        try {
            $smarty->fetch($tplpath);
        } catch (Exception $e) {
            throw new Exception("\nNo tpl here,via method \n\"{$name}\" \n@ \"{$tplpath}\"");
        }
    }
    if (function_exists($fn)) {
        return $fn($template, $params);
    } else {
        $methodName = preg_replace('/^_[a-fA-F0-9]{32}_/', '', $method);
        if ($method !== $methodName) {
            $method = '_' . md5($name) . '_' . $methodName;
            $fn = 'smarty_template_function_' . $method;
            if (function_exists($fn)) {
                return $fn($template, $params);
            }
        }
        throw new Exception("\nUndefined function \"{$method}\" \nin \"{$name}\" \n@ \"{$tplpath}\"");
    }
}
Esempio n. 15
0
/**
 * smarty 编译插件 htmlclose
 *
 * 处理 {/html} 标签
 *
 * @param array $params
 * @param Smarty $smarty
 * @access public
 * @return string 编译后的php代码
 */
function smarty_compiler_htmlclose($params, $smarty)
{
    return '<?php ' . '}' . BigPipe::compileCloseTag(BigPipe::TAG_HTML, $params) . ";" . '}while(BigPipe::more());' . '}' . '?>';
}
Esempio n. 16
0
/**
 * smarty 编译插件 pageletclose
 *
 * 处理 {/pagelet} 标签
 * 
 * @param array $params
 * @param Smarty $smarty 
 * @access public
 * @return string 编译后的php代码
 * @see BigPipe::compileCloseTag
 */
function smarty_compiler_pageletclose($params, $smarty)
{
    return '<?php ' . '}' . 'if(' . BigPipe::compileCloseTag(BigPipe::TAG_PAGELET, $params) . '){' . '?>';
}
Esempio n. 17
0
/**
 * smarty 编译插件 headclose
 *
 * 处理 {/head} 标签
 * 
 * @param array $params
 * @param Smarty $smarty 
 * @access public
 * @return string 编译后的php代码
 */
function smarty_compiler_headclose($params, $smarty)
{
    return '<?php ' . '}' . 'if(' . BigPipe::compileCloseTag(BigPipe::TAG_HEAD, $params) . '){' . '?>';
}
<?php

BigPipe::loadClass("PageletEvent");
/**
 * Pagelet 节点上下文
 * 用于保存 Pagelet 的属性
 * 
 * @uses PageletEvent
 * @author Zhang Yuanwei <*****@*****.**> 
 */
class PageletContext
{
    /**
     * 空标志 
     */
    const FLG_NONE = 0;
    /**
     * 自动添加事件的标志
     * @see getEvent 
     */
    const FLG_AUTO_ADD_EVENT = 1;
    /**
     * 如果指定参数没有值则添加参数
     * @see getParam
     */
    const FLG_APPEND_PARAM = 2;
    /**
     * 标签类型 
     * 
     * @var int
     * @access public
 protected function outputPagelet($pagelet)
 {
     $resourceMap = array();
     $hooks = array();
     $config = $this->getPageletConfig($pagelet, $html, $resourceMap, $hooks);
     // 输出注释里的 HTML
     if (!empty($html)) {
         echo "\n" . $html;
     }
     echo "\n<script>\"use strict\";\n";
     // 输出函数
     if (!empty($hooks)) {
         foreach ($hooks as $id => $hook) {
             echo "BigPipe.hooks[\"{$id}\"]=function(){{$hook}};\n";
         }
     }
     //设置资源表
     if (!empty($resourceMap)) {
         $resourceMap = BigPipeResource::pathToResource($resourceMap);
         $resourceMap = BigPipeResource::getDependResource($resourceMap);
         $resourceMap = BigPipe::array_merge($resourceMap, $this->loadedResource);
         $outputMap = array();
         foreach ($resourceMap as $id => $resource) {
             if (isset(BigPipeResource::$knownResources[$id])) {
                 continue;
             }
             $requires = $resource['requires'];
             unset($resource['requires']);
             unset($resource['requireAsyncs']);
             $requireIds = array();
             if (!empty($requires)) {
                 $requires = BigPipeResource::pathToResource($requires);
                 $requireIds = array_keys($requires);
             }
             $resource['deps'] = $requireIds;
             $resource['mods'] = $resource['defines'];
             unset($resource['defines']);
             unset($resource['id']);
             $outputMap[$id] = $resource;
             BigPipeResource::$knownResources[$id] = $resource;
         }
         echo "BigPipe.setResourceMap(", json_encode($outputMap), ");\n";
     }
     //输出 pagelet 配置
     echo "BigPipe.onPageletArrive(", json_encode($config), ");\n";
     echo "</script>";
 }