/** * WIDGET START * 解析参数,收集widget所用到的静态资源 * @param $id * @param $mode * @param $group * @return bool */ public static function start($id, $mode = null, $group = null) { $has_parent = !empty(self::$_context); if ($mode) { $widget_mode = self::_parseMode($mode); } else { $widget_mode = self::$mode; } self::$_pagelet_id = $id; $parent_id = $has_parent ? self::$_context['id'] : ''; $qk_flag = self::$mode == self::MODE_QUICKLING ? '_qk_' : ''; $id = empty($id) ? '__elm_' . $parent_id . '_' . $qk_flag . self::$_session_id++ : $id; $parent = self::$_context; $has_parent = !empty($parent); //$hit $hit = true; $context = array('id' => $id, 'mode' => $widget_mode, 'hit' => $hit); if ($has_parent) { $context['parent_id'] = $parent['id']; self::$_contextMap[$parent['id']] = $parent; } if ($widget_mode == self::MODE_NOSCRIPT) { //只有指定paglet_id的widget才嵌套一层div if (self::$_pagelet_id) { echo '<div id="' . $id . '">'; } } else { if ($widget_mode == self::MODE_BIGRENDER) { //widget 为bigrender时,将内容渲染到html注释里面 if (!$has_parent) { echo '<div id="' . $id . '">'; echo '<code class="g_bigrender"><!--'; } } else { echo '<div id="' . $id . '">'; } if (self::$mode == self::MODE_QUICKLING) { $hit = self::$filter[$id]; //如果父widget被命中,则子widget设置为命中 if ($has_parent && $parent['hit']) { $hit = true; } else { if ($hit) { //指定获取一个子widget时,需要单独处理这个widget $context['parent_id'] = null; $has_parent = false; } } } else { if ($widget_mode == self::MODE_QUICKLING) { //渲染模式不是quickling时,可以认为是首次渲染 if (self::$_pagelet_id && self::$mode != self::MODE_QUICKLING) { if (!$group) { echo '<textarea class="g_fis_bigrender" style="display:none;">' . 'BigPipe.asyncLoad({id: "' . $id . '"});' . '</textarea>'; } else { if (isset(self::$_pagelet_group[$group])) { self::$_pagelet_group[$group][] = $id; } else { self::$_pagelet_group[$group] = array($id); echo "<!--" . $group . "-->"; } } } // 不需要渲染这个widget $hit = false; } } $context['hit'] = $hit; if ($hit) { if (!$has_parent) { //获取widget内部的静态资源 FISResource::widgetStart(); } //start a buffer ob_start(); } } //设置当前处理context self::$_context = $context; return $hit; }
/** * WIDGET START * 解析参数,收集widget所用到的静态资源 * @param $id * @param $mode * @param $group * @param $class * @return bool */ public static function start($id, $mode = null, $group = null, $class = null, $is_rend = 1, $textarea_style = null, $fetch_widget = null) { $has_parent = !empty(self::$_context); $special_flag = false; if ($mode !== null) { $special_flag = true; } if ($mode) { self::$widget_mode = self::_parseMode($mode); } else { self::$widget_mode = self::$mode; } //是否渲染div self::$rend_div = $is_rend; $parent_id = $has_parent ? self::$_context['id'] : ''; $qk_flag = self::$mode == self::MODE_QUICKLING ? '_qk_' : ''; $id = empty($id) ? '__elm_' . $parent_id . '_' . $qk_flag . self::$_session_id++ : $id; $class = empty($class) ? self::DEFAULT_TEXTAREA_CLASS : $class; $textarea_style = empty($textarea_style) ? self::DEFAULT_TEXTAREA_STYLE : $textarea_style; //widget是否命中,没有指定fetch_widget默认命中,否则默认不命中 $hit = empty($fetch_widget) ? true : false; //url强迫模式,优先级最高 if (self::$force_mode !== false) { self::$widget_mode = self::$force_mode; $hit = true; } switch (self::$widget_mode) { case self::MODE_NOSCRIPT: break; case self::MODE_QUICKLING: $hit = self::$filter[$id]; case self::MODE_BIGPIPE: $context = array('id' => $id, 'async' => false); //widget调用时mode='quickling',so,打出异步加载代码 if ($special_flag && !$hit) { if (!$group) { echo "<textarea class=\"{$class}\" style=\"{$textarea_style}\"><script>" . "BigPipe.asyncLoad({id: \"{$id}\"},\"{$fetch_widget}\");" . '</script></textarea>'; } else { if (isset(self::$_pagelet_group[$group])) { self::$_pagelet_group[$group]["ids"][] = $id; self::$_pagelet_group[$group]["class"][] = $class; self::$_pagelet_group[$group]["style"][] = $textarea_style; } else { self::$_pagelet_group[$group] = array("ids" => array($id), "class" => array($class), "style" => array($textarea_style), "url" => $fetch_widget); echo "<!--" . $group . "-->"; } } $context['async'] = true; } $parent = self::$_context; if (!empty($parent)) { $parent_id = $parent['id']; self::$_contextMap[$parent_id] = $parent; $context['parent_id'] = $parent_id; if ($parent['hit']) { $hit = true; } else { if ($hit && self::$mode === self::MODE_QUICKLING) { unset($context['parent_id']); } } } $context['hit'] = $hit; self::$_context = $context; if (empty($parent) && $hit) { FISResource::widgetStart(); } else { if (!empty($parent) && !$parent['hit'] && $hit) { FISResource::widgetStart(); } } //指定自动渲染div if (!empty(self::$rend_div)) { echo '<div id="' . $id . '">'; } ob_start(); break; } return $hit; }