示例#1
0
/**
 * do rendering
 * @param array [in|out] data
 * @param array [in|out] result
 * @param Object [in] smarty
 */
function render(&$data, &$result, $smarty, $render_header_flag = false)
{
    /**
     * init render result
     */
    $result['status'] = $GLOBALS['STATUS_CODE']['OK'];
    $result['msg'] = $GLOBALS['STATUS_MSG'][$result['status']];
    //$result['page'] = '';
    if ($render_header_flag) {
        $GLOBALS['mulit_render_flag'] = 0;
        $page = $smarty->do_render($data['uiData'], $data['uiControl']['templateName'], $data['uiControl']['templateSwitch'], $data['uiControl']['templateVersion']);
    } else {
        if ($data['uiControl']['singleItem'] == 1) {
            /**
             * tplt name from gss  data 
             */
            $templateName = $data['uiData']['asResult']['item'][0]['dispData']['strategy']['tempName'];
            /**
             * tplt name from uiCrontrol
             */
            if (empty($templateName)) {
                $templateName = $data['uiControl']['templateName'];
            }
            $data['uiData']['asResult']['item'][0]['dispData']['resultData']['queryInfo'] = CSmarty::getQueryInfo();
            $data['uiData']['asResult']['item'][0]['dispData']['resultData']['templateConfig'] = CSmarty::getTemplateConfig();
            $conf = CSmarty::getConf();
            backend_encrypt_url($data['uiData']['asResult']['item'][0]['dispData'], $conf['platform'], $conf['language'], $conf['type'], $templateName);
            $page = $smarty->do_render($data['uiData']['asResult']['item'][0]['dispData'], $templateName, $data['uiControl']['templateSwitch'], $data['uiControl']['templateVersion']);
        } else {
            //并行渲染需要的数据,预处理时顺便就分类了,避免并行渲染时需要再循环遍历一次
            $arrAlaData = array();
            $arrAsData = array();
            // HHVM直连状态下,直接关闭并行渲染
            if (!empty($_ENV['HHVM'])) {
                $GLOBALS['globalConf']['FEATURE_LIST']['MULTI_RENDER']['TURN'] = 'OFF';
            }
            #		$arrMultiRenderConf = Util::getConf('/multi_render', 'MULTI_RENDER');
            #		$bolPreRenderFeature = (Util::getConf('/feature', 'FEATURE_LIST/PREDATA/TURN') === 'ON') ? true : false;
            #		$bolMultiRenderFeature = (Util::getConf('/feature', 'FEATURE_LIST/MULTI_RENDER/TURN') === 'ON') ? true : false;
            $arrMultiRenderConf = $GLOBALS['globalConf']['MULTI_RENDER'];
            $bolPreRenderFeature = $GLOBALS['globalConf']['FEATURE_LIST']['PREDATA']['TURN'] === 'ON' ? true : false;
            $bolMultiRenderFeature = $GLOBALS['globalConf']['FEATURE_LIST']['MULTI_RENDER']['TURN'] === 'ON' ? true : false;
            //限定baidu模板
            //给FE加参数确定是否有预处理
            if ($data['uiControl']['platform'] == 'pc' && $data['uiControl']['templateName'] == 'baidu' && $bolPreRenderFeature) {
                $time_start = Volatile::microtime(true) * 1000;
                pre_render($data, $arrAlaData, $arrAsData);
                $data['uiData']['queryInfo']['multiRenderFlag'] = true;
                $GLOBALS['logArr']['time_pre_render'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
            }
            if ($bolMultiRenderFeature && $bolPreRenderFeature && $data['uiControl']['templateName'] == 'baidu' && $data['uiControl']['platform'] == 'pc' && (!empty($arrAlaData) || !empty($arrAsData))) {
                CSmarty::setQueryInfo($data['uiData']['queryInfo']);
                CSmarty::setEncKeyStr($data['uiData']['queryInfo']['encryptionKey']);
                $time_start = Volatile::microtime(true) * 1000;
                try {
                    $page = multi_render($data, $smarty, $arrAlaData, $arrAsData, $arrMultiRenderConf);
                } catch (Exception $e) {
                    $page = "";
                    if (isset($GLOBALS['multi_render_shmid'])) {
                        $shmid = $GLOBALS['multi_render_shmid'];
                        shmop_delete($shmid);
                        shmop_close($shmid);
                    }
                    CLog::warning("milti error:" . $e->getMessage());
                }
                $GLOBALS['logArr']['time_multi_render_total'] = round(Volatile::microtime(true) * 1000 - $time_start, 2);
            }
            if (empty($page)) {
                $GLOBALS['mulit_render_flag'] = 0;
                $page = $smarty->do_render($data['uiData'], $data['uiControl']['templateName'], $data['uiControl']['templateSwitch'], $data['uiControl']['templateVersion']);
            }
        }
    }
    $GLOBALS['logArr']['result_tpl_tm'] = @implode(',', CSmarty::getResultTplRenderTime());
    if ($page === false) {
        $result['page'] = '';
        $errors = CSmarty::getError();
        $errors_str = implode(";", $errors);
        $status = $GLOBALS['STATUS_CODE']['RENDER_FAIL'];
        $result['status'] = $status;
        $result['msg'] = $GLOBALS['STATUS_MSG'][$status] . ", errors[{$errors_str}]";
        CLog::warning($GLOBALS['STATUS_MSG'][$status] . ", errors[{$errors_str}]", $status);
        return $status;
    } else {
        $result['page'] .= $page;
    }
    return $GLOBALS['STATUS_CODE']['OK'];
}