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) {
         echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"{$resource['src']}\" />";
     }
 }
 public static function registModule($name)
 {
     $intPos = strpos($name, ':');
     if ($intPos === false) {
         return;
     } else {
         $femodule = substr($name, 0, $intPos);
     }
     $configPath = BIGPIPE_CONF_DIR;
     if (!in_array($femodule, self::$registedMoudle)) {
         $mapPath = $configPath . '/' . $femodule . '-map.json';
         $map = json_decode(file_get_contents($mapPath), true);
         BigPipeResource::setupMap($map);
         self::$registedMoudle[] = $femodule;
     }
 }
/**
 * 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);
}
Example #4
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);
    }
}
 /**
  * 得到 pagelet 的配置,用于Quickling输出
  *
  * @param PageletContext $pagelet
  * @param string $html
  * @param array $resourceMap
  * @param array $hooks
  */
 private function getPageletConfig($pagelet, &$html, &$resourceMap, &$hooks)
 {
     $config = array();
     $config["id"] = $pagelet->getParam("id");
     $config["children"] = array();
     foreach ($pagelet->children as $child) {
         $config["children"][] = $child->getParam("id");
     }
     if ($pagelet->parent) {
         $config["parent"] = $pagelet->parent->getParam("id");
     }
     if (!empty($pagelet->html)) {
         //生成容器ID
         $containerId = $this->sessionUniqId("__cnt_");
         //生成注释的内容
         //$html = "<code id=\"$containerId\" style=\"display:none\"><!-- ";
         //$html = $this->getCommentHTML($pagelet->html);
         $html = $pagelet->html;
         //$html .= " --></code>";
         //设置html属性
         $config["html"]["container"] = $containerId;
         $config["html"]["html"] = $html;
     }
     foreach (self::$knownEvents as $type) {
         $event = $pagelet->getEvent($type);
         if ($event !== false) {
             foreach ($event->hooks as $hook) {
                 //$hookId                   = $this->sessionUniqId("__cb_");
                 //$hooks[$hookId]           = $hook;
                 $config["hooks"][$type][] = $hook;
             }
             //deps
             $requireResources = BigPipeResource::pathToResource($event->requires);
             $config["deps"][$type] = array_keys($requireResources);
             $resourceMap = array_merge($resourceMap, $event->requires, $event->requireAsyncs);
         }
     }
     return $config;
 }
Example #6
0
 /**
  * 模板调用函数。在标签打开时调用,用于控制标签内部是否执行。
  *
  * @param int $type 标签类型
  * @param string $uniqid 节点ID
  * @param array $params 标签参数
  * @static
  * @final
  * @access public
  * @return bool 是否需要执行标签内部内容
  * @see compileOpenTag
  * @see PageController::openTag
  */
 public static final function open($type, $uniqid, $params = null)
 {
     assert('self::$state === self::STAT_FIRST || self::$state === self::STAT_LOOP');
     if (self::has($uniqid)) {
         assert('isset(self::$context->children[$uniqid])');
         $context = self::$context->children[$uniqid];
         assert('$context->type === $type');
     } else {
         if (!isset($params)) {
             $params = array();
         }
         if ($type == self::TAG_HTML && isset($params['her'])) {
             BigPipeResource::registModule($params['her']);
             self::$jsLib = $params['her'];
             unset($params['her']);
             if (isset($params['bigrender'])) {
                 self::$bigrenderLib = $params['bigrender'];
                 unset($params['bigrender']);
             }
         }
         if (isset($params['bigrender'])) {
             $bigrender = true;
             unset($params['bigrender']);
         }
         $context = new PageletContext($type, $params);
         $context->parent = self::$context;
         self::$context->children[$uniqid] = $context;
         if (isset($bigrender) && $bigrender) {
             $context->bigrender = true;
         }
     }
     self::$context = $context;
     return $context->opened = self::$controller->openTag($context);
 }
Example #7
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}\"");
    }
}