예제 #1
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);
}
예제 #2
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);
    }
}
예제 #3
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);
 }
예제 #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}\"");
    }
}