<?php
/**
 * wap 手机版-文章资讯最终页
 */

use SelfVendor\SelfSpecial;
use SelfVendor\SelfUrl;

require_once('../self_define/setting.php');
require_once(SYSTEM_ROOT.'include/smarty_setting.php');
require_once(WAP_ROOT.'include/public.php');

//拼接数据资源,防止与后台系统调用数据起冲突。
$source      = '11$'.$channel_info['id'].'$'.$doc_info['id'];
$big_id      = $doc_info['big_id'];
$sub_id      = $doc_info['sub_id'];
$pro_referer = $_SERVER['HTTP_REFERER'];
if ($pro_referer) {
    $temp_pro_referer        = parse_url($pro_referer);
    $temp_pro_referer_domain = $temp_pro_referer['host'];
    if ($temp_pro_referer_domain != $_SERVER['SERVER_NAME']) {
        $pro_referer = '';
    }
}
$doc_channel_ids = $wap_user_info['doc_channel_ids'] ? explode(',', $wap_user_info['doc_channel_ids']) : [];
//表单如需登录，直接跳转到登录界面
$is_add = $_REQUEST['is_add'] ? (int)$_REQUEST['is_add'] : 0;
if ($channel_info['hy_id'] && $is_add) {
    $tmpFormInfo = Model_Form::getFormInfoNew(array('is_member' => 'is_member', 'is_shopping_card' => 'is_shopping_card'));
    if ($tmpFormInfo->is_shopping_card == 1) {
        Model_User::checkUser($zz_userid, $user_id, $user_name);
    } else {
        if ($tmpFormInfo->is_member == 2 || $doc_info['is_pay']) {
            Model_User::checkUser($zz_userid, $user_id, $user_name);
        }
    }
}

//获取内容
$userInfo = Model_User::getUserUserInfo((int)$zz_userid, array('vip' => 'vip',));

$limit_replay = 1;
if ((int)$system_arr['is_limit'] === 0) {
    $limit_replay = 0;
} else {
    $user_vip_arr = explode(',', $system_arr['review_purview']);
    $user_vip_arr = array_diff($user_vip_arr, array(null));

    if (!is_array($user_vip_arr)) {
        $limit_replay = 0;
    }
    if (in_array($userInfo['vip'], $user_vip_arr)) {
        $limit_replay = 0;
    }
}

//非行业模块不显示导读图设置
$is_show_sql  = 'select hy_id from ev_user_channel where userid='.$USERID.' and id='.$channel_id.' limit 0,1';
$is_hy        = $DB_Ev123->get_var($is_show_sql);
$is_show_guid = $is_hy ? 1 : 0;

$tmp_table = get_doc_con_table($id, 1);
$conInfo   = (array)Model_Doc::getDocContentInfo($tmp_table, $id);
if ($conInfo['content']) {

    //地图
    $conInfo['content'] = Model_Doc::re_reg($conInfo['content'], 1);


    if ($USERID != 1479824) {
        preg_match_all(
            '/http:\/\/(aimg8.dlszyht.net.cn|aimg8.dlszywz.com|aimg8.dlssyht.cn)\/ueditor\/file(.*?)(docx|jpg|jpeg|png|txt|mp4|mp3|pdf)/',
            $conInfo['content'],
            $matches
        );
        if ($isWxBrowser) {
            foreach ($matches[0] as $key => $val) {
                $conInfo['content'] = str_replace($val, "javascript:load_down()", $conInfo['content']);
            }
        } elseif ($IOS) {
            foreach ($matches[0] as $key => $val) {
                $conInfo['content'] = str_replace($val, "javascript:window.ev123:downLoadFile('{$val}');", $conInfo['content']);
            }
        } elseif ($is_app) {
            foreach ($matches[0] as $key => $val) {
                $conInfo['content'] = str_replace($val, "javascript:window.android.downLoadFile('{$val}');", $conInfo['content']);
            }
        } else {
            preg_match_all('/http:\/\/aimg8.dlszyht.net.cn\/ueditor\/file(.*?) title=\"(.*?)\"/', $conInfo['content'], $matches1);
            foreach ($matches1[2] as $key => $val) {
                $downUrl            = $matches[0][$key];
                $conInfo['content'] = str_replace($matches[0][$key], "javascript:down_file('{$downUrl}', '{$val}')", $conInfo['content']);
            }
        }
    }

    //文章内容图片
    $pattern = '/<img(.*?)src="(.*?)"(.*?)>/';
    preg_match_all($pattern, $conInfo['content'], $match);
    if (!empty($match[2])) {
        $match = $match[2];
    } else {
        $match = '';
    }

    if ($doc_info['is_wap_add']) {
        if (USER_ID == 2256625) {
            $doc_info['content'] = "<p>{$conInfo['content']}</p>";
        } else {
            $doc_info['content'] = "<p style=\"text-indent: 2em;\">{$conInfo['content']}</p>";
        }
        $doc_info['content'] = nl2br($doc_info['content']);
        $doc_info['content'] = str_replace('<br />', '&nbsp;</p><p >', $doc_info['content']);
    } else {
        $doc_info['content'] = "<p>{$conInfo['content']}</p>";
    }

    //获取格式
    $page    = $_REQUEST['page'] ? (int)$_REQUEST['page'] : 1;
    $baseUrl = $_SERVER['REQUEST_URI'];
    if (!$is_show_guid) {
        $doc_info['content'] = Job_Doc::getPreNextWap($doc_info['content'], $page, $baseUrl);
    }
}
if ($conInfo['re_title']) {
    $doc_info['re_title'] = $conInfo['re_title'];
}

$is_replay    = $_REQUEST['is_replay'] ? (int)$_REQUEST['is_replay'] : 0;
$is_compleate = $_REQUEST['is_compleate'] ? (int)$_REQUEST['is_compleate'] : 0;
$is_banshi    = $_REQUEST['banshi'] ? (int)$_REQUEST['banshi'] : 0;
$is_add       = $_REQUEST['is_add'] ? (int)$_REQUEST['is_add'] : 0;

if ($conInfo['img_id']) {
    $sql     = 'select * from ev_user_pic_data where id in ('.$conInfo['img_id'].')';
    $picList = $DB_Ev123->get_results($sql, 'O');

    if ($picList) {
        foreach ($picList as $k => $v) {
            if (strpos($v->url, 'own_pic_channel')) {
                $v->url = Job_Pic::format([
                    'type'   => 10,
                    'pic'    => $v->url,
                    'width'  => 800,
                    'height' => 1500,
                    'field'  => 'showPic',
                ]);
            } else {
                $v->url = Job_Pic::format([
                    'type'   => 11,
                    'pic'    => $v->url,
                    'width'  => 800,
                    'height' => 1500,
                    'field'  => 'showPic',
                ]);
            }
            $doc_info['content'] .= '<img src="'.$v->url.'">';
        }
    }
}

$class_param = array(
    'id'   => 'id',
    'name' => 'name',
);

if (!empty($big_id) && !empty($sub_id)) {
    // 大小类信息
    $big_sub_arr['big_id'] = Model_Doc::getDocClassId($USERID, $channel_id, $big_id, $class_param);
    if (!empty($big_sub_arr['big_id'])) {
        $big_sub_arr['big_id']['link'] = web_channel_nav_link($channel_info['type'], $channel_id, $big_id);
    }
    $big_sub_arr['sub_id'] = Model_Doc::getDocClassId($USERID, $channel_id, $sub_id, $class_param);
    if (!empty($big_sub_arr['sub_id'])) {
        $big_sub_arr['sub_id']['link'] = web_channel_nav_link($channel_info['type'], $channel_id, $big_id, $sub_id);
    }
} elseif (!empty($big_id)) {
    // 大类信息
    $big_sub_arr['big_id'] = Model_Doc::getDocClassId($USERID, $channel_id, $big_id, $class_param);
    if (!empty($big_sub_arr['big_id'])) {
        $big_sub_arr['big_id']['link'] = web_channel_nav_link($channel_info['type'], $channel_id, $big_id);
    }
}

// 判断是否为自定义设置
$is_define        = Model_Doc::isPowerParam($channel_id);
$selfSpecialRule9 = SelfSpecial::rule9(USER_ID) && $channel_info['hy_id'] && $is_add;

// 自定义设置
if (!empty($is_define)) {
    $user_param      = get_doc_forget_param($channel_id, $doc_info, 1);
    $define_yes      = 0;
    $paramType18     = 0;
    $paramType19     = 0;
    $param_phone_arr = array();
    $param_qq_arr    = array();
    $param_num       = 1;
    $phone_num       = 1;
    $qq_num          = 1;
    $mp3Info         = [];
    if (!empty($user_param)) {
        $guige = array();
        foreach ($user_param as $k => $v) {
            if ($v['value'] && !$define_yes) {
                $define_yes = 1;
            }

            if (in_array($v['type'], array(3, 16, 13, 30))) {
                if ($v['value'] || $v['mapHtml']) {
                    $param_num++;
                }
                if ($v['type'] == 3) {
                    $v['value']     = Model_Doc::re_reg($v['value'], 1);
                    $user_param[$k] = $v;
                }
            }

            if ($v['type'] == 31) {
                $tmpMp3Info          = explode(';', $v['value']);
                $mp3Info['name']     = $v['name'];
                $mp3Info['mp3Url']   = $tmpMp3Info[0] ?? '';
                $mp3Info['mp3Title'] = $tmpMp3Info[1] ?? '';
                unset($user_param[$k]);
            }

            if ($v['type'] == 14 && $v['value']) {
                if (!$selfSpecialRule9) {
                    $doc_info['paramType14']    = 1;
                    $doc_info['paramType14Val'] = $v['value'];
                    if ($v['price']) {
                        $doc_price = $v['price'];
                    }
                    if ($v['price_unit']) {
                        $doc_unit = $v['price_unit'];
                    }
                    unset($user_param[$k]);
                }
            } elseif ($v['type'] == 18) {
                $paramType18 = 1;
            } elseif ($v['type'] == 19) {
                $paramType19 = 1;
            } elseif ($v['type'] == 20) {
                $paramType20 = 1;
                if ($v['value'][0]) {
                    $guige[] = $v;
                }
                unset($user_param[$k]);
            } elseif ($v['type'] == 21) {
                if ($v['value']) {
                    if (!$is_type21) {
                        $is_type21 = 1;
                    }
                    $param_phone_arr[$phone_num]['name']  = $v['name'];
                    $param_phone_arr[$phone_num]['value'] = $v['value'];
                    $paramType21['name']                  = $v['name'];
                    $paramType21['value']                 = $v['value'];
                    $phone_num++;
                } else {
                    $is_type21 = 0;
                }
            } elseif ($v['type'] == 22) {
                if ($v['value']) {
                    if (!$is_type22) {
                        $is_type22 = 1;
                    }
                    $param_qq_arr[$qq_num]['name']  = $v['name'];
                    $param_qq_arr[$qq_num]['value'] = $v['value'];
                    $qq_num++;
                } else {
                    $is_type22 = 0;
                }
            } elseif ($v['type'] == 1) {
                if (strpos($v['value'], 'http') === 0 || strpos($v['value'], 'https') === 0) {
                    $user_param[$k]['value'] = '<a href="'.$v['value'].'" target="_blank">'.$v['value'].'</a>';
                }
            }
        }
        $param_num_new = $param_num - 1;
        if ($param_num_new) {
            //兼顾行业版文章内容
            $param_width = '25';
        }
        if ($paramType20) {
            $guigePrice = Model_Doc::getDynamicPriceInfo(
                'id',
                'is_del=0 && doc_id='.$doc_info['id']
            );
            if (!$guigePrice) {
                unset($paramType20, $guige);
            }
        }

        $imgKey = 0; //判断有几个图片集
        foreach ($user_param as $k => $v) {
            if (($v['type'] == 13 || $v['type'] == 30) && $v['value']) {
                if (strpos($v['value'], ',') === false) {
                    $mapVal = explode('#', $v['value']);
                } else {
                    $mapVal    = explode(',', $v['value']);
                    $tmpPoint  = Functions::Convert_BD09_To_GCJ02($point[1], $point[0]);
                    $mapVal[0] = $point[0];
                    $mapVal[1] = $point[1];
                }
                $smarty->assign('isMap', 1);
                if ($v['type'] == 30) {
                    $remind_info = Model_Doc::get_relation_parma_val($id, $v['id'], $channel_id, array('param_val' => 'param_val'));
                    if ($remind_info[0]->param_val) {
                        $tmp_info = $remind_info[0]->param_val;
                    } else {
                        $tmp_info = $doc_info['title'];
                    }
                } else {
                    $tmp_info = $doc_info['title'];
                }

                if ($channel_info['wap_detail_style'] == 3) {
                    $mapStyle = 'height:400px; width:94%; display:block;';
                } else {
                    $mapStyle = 'height:400px; width:94%;';
                }
                $mapStr_1                  = 'http://api.map.baidu.com/marker?location='.$mapVal[1].','.$mapVal[0].'&title='.urlencode($tmp_info).'&output=html';
                $mapStr_2                  = '&zoom=4&src=webapp.baidu.openAPIdemo';
                $user_param[$k]['mapHtml'] = '<div style="'.$mapStyle.'" class="detailsTab detailsList'.$v['id'].'" id="detail'.$v['id']
                                             .'"><iframe style="width:100%; height:100%;" frameborder="0" allowtransparency="true" src="'.$mapStr_1.$mapStr_2.'"></iframe></div>';
                $smarty->assign('leftmap', $mapVal[0]);
                $smarty->assign('rightmap', $mapVal[1]);
                $smarty->assign('map_href', $mapStr_1);
            }
            if ($v['type'] == 16) {
                $user_param[$k]['imgKey'] = $imgKey;
                //生成图片数组
                $sql            = 'select id,power_param_id from ev_user_power_param
                      where user_id='.$USERID.' and channel_id='.$channel_id.' and type = 16 and is_del=0 and is_show=1
                      order by order_sort desc,id asc limit '.$imgKey.',1';
                $tmp_user_param = $DB_User_Doc->get_row($sql);
                if (!$tmp_user_param['is_index']) {
                    $user_param_value = get_doc_param_val($tmp_user_param['id'], $id);
                } else {
                    $user_param_value = get_doc_index_val($channel_id, $tmp_user_param['power_param_id'], $id);
                }
                $pic_arr = get_doc_pic_info($user_param_value);
                if ($is_show_guid) {
                    $user_param[$k]['pic_arr'] = array_slice($pic_arr, 0, 1);
                } else {
                    $user_param[$k]['pic_arr'] = array_slice($pic_arr, 0, 3);
                }
                $imgKey++;
            }
        }
    }
}

// 非自定义设置
if (empty($is_define) || empty($define_yes)) {
    $content_info = (array)Model_Doc::getDocContentInfo($tmp_table, $id);
}

// 相关文章
if ($doc_info['xiangguan_doc'] > 0) {
    $correlation_where = "";
    if ($doc_info['xiangguan_doc'] == 1 && $doc_info['big_id']) {
        $correlation_where = " && big_id={$big_id} ";
    }
    if ($doc_info['xiangguan_doc'] == 2 && $doc_info['sub_id']) {
        $correlation_where = " && sub_id={$sub_id}";
    }

    $correlation_param = array(
        'id'     => 'id',
        'title'  => 'title',
        'pic'    => 'pic',
        'author' => 'author',
    );
    $correlation_where = 'userid='.$user_id.' and is_del=0 and channel_id='.$channel_id.'  '.$correlation_where.' and id !='.$doc_info['id'];
    $currelation_list  = Model_Doc::getWebDocArr($correlation_where, $limit = array(0, 10), $correlation_param);

    if ($currelation_list) {
        foreach ($currelation_list as $k => $v) {
            $currelation_list[$k]['link'] = web_channel_detail_link($channel_info['type'], $channel_id, $v['id']);
            $currelation_list[$k]['pic']  = Job_Pic::format([
                'type'     => 11,
                'pic'      => $v['pic'],
                'width'    => 600,
                'height'   => 600,
                'sizeType' => 2,
                'field'    => 'showPic',
            ]);

            //查询对应的数据
            $tmp_re_where                       = ' s.re_type=11 and doc_id='.$v['id'].' and channel_id='.$channel_id.' and user_id='.$user_id.' and parent_id = 0';
            $tmp_replay_cnt                     = Model_Public::getReplyArr($tmp_re_where, array(), array(0, 1), 1);
            $currelation_list[$k]['replay_cnt'] = $tmp_replay_cnt;
        }
    }
    $smarty->assign('currelation_list', $currelation_list);
}

//获取是否有关联表单
$form_info = get_relation_form($channel_info['type'], $channel_id, $id);

$isAddPayment = 0;
$isCommonPay  = Job_Form::isCommonPay($formInfo);

if ($isCommonPay) {
    $isAddPayment = Model_Pay::pay_check(USER_ID);
    $isAddPayment = Job_Form::isPay($isAddPayment);
}

if (!$isAddPayment || $isCommonPay) {
    $form_info['is_shopping_card'] = 0;
}

if ($form_info['is_member'] == 2 || $form_info['is_shopping_card'] == 1) {
    $isFormLogin = 1;

    if (!defined('USER_USER_ID')) {
        $isFormLogin = 0;
    }
} else {
    $isFormLogin = 1;
}

if ($form_info) {
    //获取表单频道信息
    if ($form_info['ch_id']) {
        $channel_info_form = Model_Channel::getChannelInfoNew(array(), 'id='.$form_info['ch_id']);
    }

    if (!$channel_info_form) {
    } else {
        //获取表单信息
        $form_info_detail  = Model_Form::getFormInfo($channel_info_form->form_id);
        $form_channel_id   = $channel_info_form->id;
        $channel_info_form = (array)$channel_info_form;

        $channel_info_form['link'] = web_channel_nav_link(11, $form_info['id']);

        $wap_user_info['row_ids'] = ($view == 1) ? 's3,s1' : 's1';

        if (in_array($channel_info_form['type'], array(10, 11, 14, 12, 15, 18, 20, 39))) {
            $smarty->assign('but_group_position', 1);
        }

        $group_id = $_REQUEST['group_id'] ? (int)$_REQUEST['group_id'] : 0;
        $guige_id = $_REQUEST['guige_id'] ? (int)$_REQUEST['guige_id'] : 0;

        if ($view == 1) {
            // 频道类型$频道id$文章id
            $sign_info = $source;
            if ($sign_info) {
                $sign_info = '$'.$sign_info.'$1';
            }
        }

        if (empty($channel_info_form['form_id'])) {
            wap_web_msg_page(array(), 'js_history');
        }

        if (empty($channel_info_form['id'])) {
            wap_web_msg_page(array(), 'js_history');
        }

        $channel_info_form['form_info'] = $form_info_detail;
        //分析数据源
        if (!empty($sign_info)) {
            $source_info = reservation_string_format_arr($sign_info);
        }

        if (!empty($source_info)) {
            $channel_info_form['source_info'] = $source_info;
        }
        if (!empty($sign_info)) {
            $channel_info_form['sign_info'] = $sign_info;
        }
        $channel_info_form['group_id'] = $group_id;

        $channel_info_form['view']     = $view;
        $channel_info_form['guige_id'] = $guige_id;
        //新走表单样式
        $channel_info_form['doc_new'] = 1;

        require_once(WAP_ROOT."/FormHtml.class.php");
        $classObjDoc = new FormHtml($form_info['id'], 1, $user_param, $source);

        $classObjDoc->channelInfo = $channel_info_form;
        $submit_name              = $channel_info_form['form_info']['submit_name'];
        if (!$submit_name) {
            $submit_name = '在线预定';
        }
        $moduleArrDoc       = $classObjDoc->getModuleSortInfo($wap_user_info['row_ids']);
        $newModuleConfigDoc = array();

        if ($moduleArrDoc) {
            foreach ($moduleArrDoc as $k => $v) {
                if ($v['module_layout_id'] == 's2' || $v['module_layout_id'] == 's5') {
                    continue;
                }
                $layoutId                      = $v['module_layout_id'];
                $newModuleConfigDoc[$layoutId] = $classObjDoc->getWapModuleDetailInfo($v);
            }
        }
        if ($classObjDoc->formUploadFile) {
            $smarty->assign('formUploadFile', $classObjDoc->formUploadFile);
        }
    }
}

//不显示在副标题的自定义参数
if ($is_app) {
    $except_arr = array(2, 3, 7, 13, 16, 18, 19, 24, 30, 22);
} else {
    $except_arr = array(2, 3, 7, 13, 16, 18, 19, 24, 30, 22);
}
$param_is_show = 0;
if (!empty($user_param)) {
    foreach ($user_param as $k => $v) {
        if ($v['type'] == 16) {
            foreach ($v['value'] as $pic_k => $pic_v) {
                $picCover150[$k] = $pic_v['150'];
                $picCover200[$k] = $pic_v['200'];
                $picCover800[$k] = $pic_v['800'];
                break;
            }
        }
        if ($v['type'] == 17) {
            unset($user_param[$k]);
        }
        if ($v['type'] == 3) {
            $user_param[$k]['value'] = Model_Doc::re_reg($v['value']);
        }
        if ((!in_array($v['type'], $except_arr) || $v['type'] == 2)) {
            if ($v['value']) {
                $param_is_show = 1;
            }
        }
    }
}

if ($form_info['id'] && defined('USER_USER_ID') && USER_USER_ID) {
    $sql1      = "select zf_state from ev_user_form_record where form_id=".$form_info['id'].' and user_user_id='.USER_USER_ID.' and zf_state=1 and doc_id='.$id;
    $orderInfo = $DB_Dom->get_row($sql1);
}
if ((!$orderInfo['zf_state'] || !defined('USER_USER_ID')) && USER_ID == 1303752) {
    foreach ($user_param as $key => $val) {
        if (preg_match('/(.*?)联系(.*?)/', $val['name'])) {
            unset($user_param[$key]);
        }
    }
}
if ($paramType18) {
    $hourInfo     = Model_HourlyWorker::getInfo($id);
    $hourworkHtml = Model_HourlyWorker::getDocHtml($hourInfo, $form_info);
    $hourworkUrl  = $form_info['url'];
    $smarty->assign('hourInfo', $hourInfo);
    $smarty->assign('hourworkUrl', $hourworkUrl);
    $smarty->assign('hourworkHtml', $hourworkHtml);
}
if ($paramType19) {
    $roomorderHtml = Model_RoomOrder::getDocHtml(
        Model_RoomOrder::getInfo($id),
        $form_info
    );

    $hourworkUrl = $form_info['url'];
    $smarty->assign('roomorderUrl', $roomorderUrl);
    $smarty->assign('roomorderHtml', $roomorderHtml);
}

$guige = Job_DocGuiGe::get_guige_arr($channel_id, $doc_info['id']);
if ($guige) {
    $guigeHtml = Job_DocGuiGe::guigeWapHtmlNew($guige, array(
        'guigeIds'    => $doc_info['guigeIds'],
        'id'          => $doc_info['id'],
        'price_unit'  => $doc_info['price_unit'],
        'isFormLogin' => $isFormLogin,
        'doc_price'   => $doc_price,
    ));
    $smarty->assign('guigeHtml', $guigeHtml);
}

$bannerArr = array();
if ($doc_info['pic']) {
    $doc_info['pic']       = Job_Pic::format([
        'type'   => 11,
        'pic'    => $doc_info['pic'],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]);
    $doc_info['small_pic'] = Job_Pic::format([
        'type'   => 11,
        'pic'    => $doc_info['pic'],
        'width'  => 100,
        'height' => 80,
        'field'  => 'showPic',
    ]);
}

if ($doc_info['pic']) {
    $bannerArr[1]['pic']   = $doc_info['pic'];
    $bannerArr[1]['small'] = Job_Pic::format([
        'type'   => 11,
        'pic'    => $bannerArr[1]['pic'],
        'width'  => 100,
        'height' => 80,
        'field'  => 'showPic',
    ]);
}
if ($doc_info['pic2']) {
    $bannerArr[2]['pic']   = Job_Pic::format([
        'type'   => 11,
        'pic'    => $doc_info['pic2'],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]);
    $bannerArr[2]['small'] = Job_Pic::format([
        'type'   => 11,
        'pic'    => $bannerArr[2]['pic'],
        'width'  => 100,
        'height' => 80,
        'field'  => 'showPic',
    ]);
}
if ($doc_info['pic3']) {
    $bannerArr[3]['pic']   = Job_Pic::format([
        'type'   => 11,
        'pic'    => $doc_info['pic3'],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]);
    $bannerArr[3]['small'] = Job_Pic::format([
        'type'   => 11,
        'pic'    => $bannerArr[3]['pic'],
        'width'  => 100,
        'height' => 80,
        'field'  => 'showPic',
    ]);
}
if ($doc_info['pic4']) {
    $bannerArr[4]['pic']   = Job_Pic::format([
        'type'   => 11,
        'pic'    => $doc_info['pic4'],
        'width'  => 600,
        'height' => 600,
        'field'  => 'showPic',
    ]);
    $bannerArr[4]['small'] = Job_Pic::format([
        'type'   => 11,
        'pic'    => $bannerArr[4]['pic'],
        'width'  => 100,
        'height' => 80,
        'field'  => 'showPic',
    ]);
}

$bannerCount = count($bannerArr);

if (!empty($define_yes)) {
    $smarty->assign('user_param', $user_param);
}
$brief = trim($doc_info['brief']) ? trim(cnsubstr($doc_info['brief'], 60)) : cnsubstr(new_format_mysql_insert($doc_info['content']), 60);

if ($isWxBrowser || $is_app || $IOS) {
    $wxUrl       = web_channel_detail_link($channel_info['type'], $channel_info['id'], $id);
    $wxShareInfo = array(
        'title' => addslashes(str_replace(array("\r\n", "\r", "\n", "&nbsp;"), '', $doc_info['title'])).'_'.$system_arr['name'],
        'brief' => addslashes(str_replace(array("\r\n", "\r", "\n", "&nbsp;"), '', $brief)),
        'url'   => SelfUrl::getHttpProtocol().$user_host.$wxUrl,
        'img'   => $doc_info['pic'],
    );
    if ($wxShareInfo['url'] && $zz_userid) {
        $wxShareInfo['url'] = Model_Fenxiao::getUrlParam($wxShareInfo['url']);
    }
    $smarty->assign('wxShareInfo', $wxShareInfo);
}

if ($bannerArr) {
    $smarty->assign('bannerArr', $bannerArr);
}

Model_Doc::$channel_id = $channel_id;
//标签
$labelList = Model_Doc::getDocLableList(array('id' => 'id', 'name' => 'name', 'color' => 'color', 'wap_target' => 'wap_target', 'wap_href' => 'wap_href'));
if ($doc_info['label_ids']) {
    $tmplabelStr = '<p class="detal_summary_info" style="height:28px;">';
    foreach ($labelList as $lk => $lv) {
        if (in_array($lv->id, explode(',', $doc_info['label_ids']))) {
            $tmpLabelColor  = $lv->color ? 'style="color:'.$lv->color.';border:1px solid '.$lv->color.'; background:none;"' : '';
            $tmpLabelColorA = $lv->color ? 'style="color:'.$lv->color.'"' : '';
            if ($lv->wap_target) {
                $wap_target = "target='_blank'";
            } else {
                $wap_target = "";
            }
            if ($lv->wap_href) {
                $wap_href = "href='{$lv->wap_href}'";
            } else {
                $wap_href = "href='###'";
            }
            $tmplabelStr .= '<em '.$tmpLabelColor.'><a '.$wap_href.' '.$wap_target.' '.$tmpLabelColorA.'>'.$lv->name.'</a></em>';
        }
    }
    $tmplabelStr          .= '</p>';
    $doc_info['labelStr'] = $tmplabelStr;
}

//打赏功能
require_once(UPPER_ROOT.'dom/publicFile/scReward.php');
if ($doc_info['user_user_id']
    && SITE_BUY_VERSION_IS_SHOP_INFO) {

    //发布的数量
    $shopDocCount  = Model_Doc::getDocCount(USER_ID, $doc_info['user_user_id']);
    $publisherInfo = Model_User::getUserUserField(
        array(
            'pic'       => 'pic',
            'nick_name' => 'nick_name',
            'user_name' => 'user_name',
            'tel'       => 'tel',
            'qq'        => 'qq',
            'weixin'    => 'weixin',
        ),
        'is_del=0 && id='.$doc_info['user_user_id'].' && user_id='.USER_ID
    );
    if ($publisherInfo) {
        $publisherInfo->nickName = $publisherInfo->nick_name ?: $publisherInfo->user_name;
        if ($publisherInfo->qq) {
            $publisherInfo->qqStr = '<span class="footer_qq_url footer_url"><a href="http://wpa.qq.com/msgrd?v=3&uin='.$publisherInfo->qq
                                    .'&site=qq&menu=yes"><img src="/images/wap/qq.png"></a></span>';
        }
        if ($publisherInfo->weixin) {
            $publisherInfo->weixinStr = '<span class="footer_wx_url footer_url"><a href="javascript:;" data-weixin="'.$publisherInfo->weixin
                                        .'" id="showWeiXin"><img src="/images/wap/weixin.png"></a></span>';
        }
        if ($publisherInfo->tel) {
            $publisherInfo->telStr = '<span class="footer_tel_url footer_url"><a href="tel:'.$publisherInfo->tel.'"><img src="/images/wap/tel.png"></a></span>';
            $publisherInfo->telStr = '<a class="fr" href="tel:'.$publisherInfo->tel.'">联系店主</a>';
        }
        $publisherInfo->pic = $publisherInfo->pic ?: 'http://img.ev123.com/pic/vf.jpg';
        $shopUrl            = '/wap/shops/shopinfo.php?username='.USER_NAME.'&channel_id='.$channel_id.'&u_u_id='.$doc_info['user_user_id'].'&m=0&wap=1';
        $shopDocUrl         = '/wap/shops/shop.php?username='.USER_NAME.'&channel_id='.$channel_id.'&u_u_id='.$doc_info['user_user_id'].'&wap=1';
        $publisherHtml      = <<<EOF
        <div class="ev_t_bk clearfix explain_bw_bo">
                <div class="detal_shop_info clearfix detal_shop_margin_b">
                    <span class="detal_shop_img"><img src="{$publisherInfo->pic}"></span>
                    <span class="detal_shop_summary fl">
                        <p>{$publisherInfo->nickName}</p>
                        <p>信息数量:{$shopDocCount}</p>
                    </span>
                    <a class="detal_shop_url fr" href="{$shopUrl}">进店看看&gt;&gt;</a>
                </div>
                <div class="detal_shop_btn clearfix">
                    <a class="fl" href="{$shopDocUrl}">全部信息</a>{$publisherInfo->telStr}
                </div>
            </div>
EOF;
        $smarty->assign('publisherHtml', $publisherHtml);
    }
}

//查询用户是否收藏过该文章
$exitsWhere = ' type =11 AND channel_id = '.$channel_id.' and doc_id = '.$id;
$is_exist   = Model_Public::getUserCollect(USER_USER_ID, array('id' => 'id'), $exitsWhere);

//获取总的回复数，最新回复时间和参与回复的总的人数
$re_args    = array(
    'id'           => 'id',
    'user_user_id' => 'user_user_id',
    're_contents'  => 're_contents',
    'input_time'   => 'input_time',
    'parent_id'    => 'parent_id',
    'hot_num'      => 'hot_num',
);
$re_where   = ' s.re_type=11 and doc_id='.$id.' and channel_id='.$channel_id.' and user_id='.$user_id.' and parent_id = 0';
$replay_cnt = Model_Public::getReplyArr($re_where, array(), array(0, 1), 1);

$replay_new = Model_Public::getReplyArr($re_where, $re_args, array(0, 1));
$replay_col = Model_Doc::doc_replay_cnt($re_where);

$input_time = (int)strtotime($replay_new['input_time'][0]);
$new_time   = time();
if ($input_time) {
    $tmp_date = Model_Doc::cha_time($input_time, $new_time);
} else {
    $tmp_date = '';
}

if (!$zz_userid) {
    $zz_userid = 0;
}
//不显示购物车
$wap_doc_detail = 1;

if ($is_show_guid) {
    //数据源
    $smarty->assign('source_doc', $source);

    //前台底部显示样式
    if ($is_type21 && $is_type22) {
        $show_style = 'w33_3';
    } elseif (($is_type21 && !$is_type22) || (!$is_type21 && $is_type22)) {
        $show_style = 'w50';
    } elseif (!$is_type21 && !$is_type22) {
        $show_style = 'w100';
    }
    $smarty->assign('show_style', $show_style);

    // 是否为行业添加的频道，是否开通了在线支付功能
    $isPay = 0;
    if ($channel_info['hy_form_id']) {
        $isPay = Model_Form::getFormInfoNew(
            'is_shopping_card',
            'id='.$channel_info['hy_form_id']
        );
    }
}

//上一页和下一页
if ($doc_info['is_next']) {
    Job_Doc::$user_name = $user_name;
    $pageArr            = Job_Doc::getPreNext($doc_info, $channel_id, 1);
    $doc_info['pre']    = $pageArr['preDoc'];
    $doc_info['nex']    = $pageArr['nexDoc'];
}

if (!$is_show_guid) {
    //站内广告
    $webAd['head'] = Job_Doc::isShowAd($channel_id, 2, $doc_info['big_id'], $doc_info['sub_id'], 1);
    $webAd['foot'] = Job_Doc::isShowAd($channel_id, 2, $doc_info['big_id'], $doc_info['sub_id'], 2);
}

//兼顾产品公用头部返回
$returnUrl = $_SERVER['HTTP_REFERER'];
if (strpos($returnUrl, '/dom/denglu.php') === true
    || strpos($returnUrl, '/dom/zhuce.php') === true
    || strpos($returnUrl, $_SERVER['HTTP_HOST']) === false
    || strpos($returnUrl, 'is_replay=1')
    || strpos($returnUrl, 'is_compleate=1')) {
    $returnUrl = "/".USER_NAME."/wap_doc/{$channel_id}_{$big_id}_{$sub_id}_1.html";
} else {
    $returnUrl = 'javascript:history.go(-1)';
}

$returnUrl = getShortLink($returnUrl, 11, $user_name);

$channel_info['link']  = $returnUrl;
$channel_info['link2'] = "/".USER_NAME."/wap_doc/{$channel_id}_0_0_0.html";
if (LANGUAGE_TYPE == 1) {
    $wei = 'recommended for you';
} else {
    $wei = '为你推荐';
}
if ($form_info['is_shopping_card'] == 0 && count($form_info) == 1) {
    unset($form_info['is_shopping_card']);
}


$docExtendInfo = Model_Doc::getDocExtendInfo('doc_id='.$id);
$seoDefine     = array();
if ($docExtendInfo->seo_title) {
    $seoDefine['title']       = $docExtendInfo->seo_title;
    $seoDefine['keyword']     = $docExtendInfo->seo_keyword;
    $seoDefine['description'] = $docExtendInfo->seo_describe;
}

$brief = str_replace("\'", "\\\'", $brief);
$brief = str_replace(array("\r\n", "\r", "\n", "\t"), '', $brief);

//交易跳转
$tradeLocationData = [];
$sysBtn            = ['外部链接', '电话咨询', 'QQ', '微信'];
$tmpTradeData      = $docExtendInfo->web_trade_location_json ? var_json_decode($docExtendInfo->web_trade_location_json)[(int)$docExtendInfo->web_trade_location_type] : null;
if ($tmpTradeData) {
}
{
    if ($docExtendInfo->web_trade_location_type == 1) {
        $tradeLocationData['name'] = $tmpTradeData['link_name'];
        $tradeLocationData['val']  = $tmpTradeData['link_val'];
    } elseif ($docExtendInfo->web_trade_location_type == 2) {
        $tradeLocationData['name'] = $tmpTradeData['phone_name'];
        $tradeLocationData['val']  = $tmpTradeData['phone_val'];
    } elseif ($docExtendInfo->web_trade_location_type == 3) {
        $tradeLocationData['name'] = $tmpTradeData['qq_name'];
        $tradeLocationData['val']  = $tmpTradeData['qq_val'];
    } elseif ($docExtendInfo->web_trade_location_type == 4) {
        $tradeLocationData['name'] = $tmpTradeData['wx_name'];
        $tradeLocationData['val']  = $tmpTradeData['wx_val'];
    }
    $tradeLocationData['type'] = $docExtendInfo->web_trade_location_type;
}

$smarty->assign('seoDefine', $seoDefine);
$smarty->assign('docExtendInfo', $docExtendInfo);
$smarty->assign('wei', $wei);
$smarty->assign('webAd', $webAd);
$smarty->assign('returnUrl', $returnUrl);
$smarty->assign('LA', $LA);
$smarty->assign('match', $match);
$smarty->assign('is_shopping_card', $isPay);
$smarty->assign('param_is_show', $param_is_show);
$smarty->assign('submit_name', $submit_name);
$smarty->assign('phone_num', $phone_num);
$smarty->assign('qq_num', $qq_num);
$smarty->assign('param_phone_arr', $param_phone_arr);
$smarty->assign('param_qq_arr', $param_qq_arr);
$smarty->assign('param_num', $param_num);
$smarty->assign('doc_unit', $doc_unit);
$smarty->assign('doc_price', $doc_price);
$smarty->assign('bannerCount', $bannerCount);
$smarty->assign('param_width', $param_width);
$smarty->assign('wap_doc_detail', $wap_doc_detail);
$smarty->assign('limit_replay', $limit_replay);
$smarty->assign('doc_time', $input_time);
$smarty->assign('zz_userid', $zz_userid);
$smarty->assign('replay_col', $replay_col);
$smarty->assign('replay_new', $tmp_date);
$smarty->assign('replay_cnt', $replay_cnt);
$smarty->assign('form_channel_id', $form_channel_id);
$smarty->assign('newModuleConfigDoc', $newModuleConfigDoc);
$smarty->assign('except_arr', $except_arr);
$smarty->assign('is_exist', $is_exist);
$smarty->assign('is_show_guid', $is_show_guid);
$smarty->assign('isFormLogin', $isFormLogin);
$smarty->assign('form_info', $form_info);
$smarty->assign('big_sub_arr', $big_sub_arr);
$smarty->assign('doc_info', $doc_info);
$smarty->assign('paramType21', $paramType21);
$smarty->assign('channel_info', $channel_info);
$smarty->assign('picCover200', $picCover200);
$smarty->assign('picCover150', $picCover150);
$smarty->assign('picCover800', $picCover800);
$smarty->assign('doc_id', $id);
$smarty->assign('is_hy', $is_hy);
$smarty->assign('showHead', in_array($channel_id, $doc_channel_ids) && !$wap_user_info['del_head']);
$smarty->assign('app_share_brief', $brief);
if ($wap_style == 6) {
    $wap_style = 2;
}
$smarty->assign('list_or_detail_tag', 1);
$smarty->assign('pro_referer', $pro_referer);
$smarty->assign('tradeLocationData', $tradeLocationData);

// 熊掌号
$xzhRecord = $xzhHeader = $xzhAttention = '';
if (in_array($channel_info['type'], Job_BaiduXzh::$type)) {
    $xzhRecord = Job_BaiduXzh::record();
    if ($xzhRecord) {
        $xzhHeader    = Job_BaiduXzh::header($channel_info, $doc_info);
        $xzhAttention = Job_BaiduXzh::attention($xzhRecord->attention_btn);
    }
}

$smarty->assign('xzhRecord', $xzhRecord);
$smarty->assign('xzhAttention', $xzhAttention);
$smarty->assign('xzhHeader', $xzhHeader);
$smarty->assign('mp3Info', $mp3Info);

if ($is_replay && !$is_show_guid) {
    if ($system_arr['article_review']) {
        $smarty->display('wap/doc/public/doc_replay_all.tpl');
    } else {
        Util::redirect("/{$user_name}/wap_doc/{$id}.html", '文章评论功能未开启');
    }
} elseif ($is_compleate) {
    if ($system_arr['article_review']) {
        $smarty->display('wap/doc/public/doc_compleate.tpl');
    } else {
        Util::redirect("/{$user_name}/wap_doc/{$id}.html", '文章评论功能未开启');
    }
} elseif (!$is_show_guid) {
    $selfSpecialRule19 = SelfSpecial::rule19(USER_ID);

    $smarty->assign('selfSpecialRule19', $selfSpecialRule19);
    $smarty->display('wap/doc/public/doc_doc_new.tpl');
} elseif ($is_add) {
    $smarty->display('wap/doc/public/doc_add.tpl');
} else {
    $wap_detail_style = empty($channel_info['wap_detail_style']) ? 2 : $channel_info['wap_detail_style'];
    if ($wap_detail_style == 3) {
        $smarty->assign("is_show_reply", 1);
        $smarty->display('wap/doc/public/doc_hy_1.tpl');
    } else {
        $smarty->display('wap/doc/public/doc_hy.tpl');
    }
}
