示例#1
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);
    }
}
示例#2
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);
}
示例#3
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);
    }
}
示例#4
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}\"");
    }
}