<?php
header('Content-type: text/javascript'); 
require("../../class/connect.php");
require(ECMS_PATH."e/class/db_sql.php");
require(ECMS_PATH."e/class/functions.php");
require(ECMS_PATH."e/data/dbcache/class.php");
require("class/class.com_pl.php");
require("class/class.jsmin.php");
require("config.php");
error_reporting(0); 
if(!$com_pl_lang[open]){
  die('console.error("评论插件已关闭");');
}

$empire=new mysqlquery();
$link=db_connect();
$id=(int)$_GET[id];
$classid=(int)$_GET[classid];
$tbname = $class_r[$classid][tbname];
if(!$tbname){
  die('console.error("您来自的链接不存在");');
}
//是否需要载入内部jQuery
$com_pl_lang['useJquery'] = RepPostVar($_GET['useJquery']);
//百搭背景颜色
$bgColor = RepPostVar($_GET['bgColor']);
if($bgColor){
  $com_pl_lang['bgColor'] = '#'.$bgColor;
}
//百搭背景颜色
$bgColor = RepPostVar($_GET['mainColor']);
if($bgColor){
  $com_pl_lang['currentColor'] = '#'.$bgColor;
}
//导入评论所需框架、脚本及样式
$css = stripSlashes($com_pl_lang[stylesheet]);//file_get_contents('data/style.css');
$template = stripSlashes($com_pl_lang[template]);
$html ='<style>'.$css.'</style>'.$template;
foreach ($com_pl_lang as $key => $value) {
  if($key=='template'||$key=='logintemp'||$key=='logintemp'||$key=='stylesheet'||$key=='listtemp')continue;
  $html = str_replace('[!--'.$key.'--]', ($value), $html);
}
//替换标签
$html = str_replace('currentColor', $com_pl_lang[currentColor], $html);
$html = str_replace('bgColor', $com_pl_lang[bgColor], $html);
$html = str_replace('borderRadius', $com_pl_lang[borderRadius], $html);
$html = str_replace('[!--userstatus--]', stripSlashes($userstatus), $html);
$html = str_replace('[!--plface--]', com_pl::plface(), $html);
$html = str_replace('[!--userpic--]', com_pl::randomFace(com_pl::makeFace()), $html);
$html = str_replace('[!--baseUrl--]', $public_r[newsurl].'e/extend/com_pl/', $html);
$html = str_replace('[!--newsurl--]', $public_r[newsurl], $html);

$plsetr=$empire->fetch1("select pltime,plsize,plincludesize,plclosewords,plmustf,plf,plmaxfloor,plquotetemp from {$dbtbpre}enewspl_set limit 1");

//js接口参数
$jsconfig =array(
  'logintemp'=>str_replace('[!--newsurl--]',$public_r[newsurl],htmlspecialchars_decode(stripSlashes($com_pl_lang[logintemp]))), //登录前模板
  'membertemp'=>str_replace('[!--newsurl--]',$public_r[newsurl],htmlspecialchars_decode(stripSlashes($com_pl_lang[membertemp]))), //登录后
  'showkey'=>$public_r['plkey_ok'], //是否开启评论验证码
  'showface'=>$com_pl_lang['face'][0]['show']||$com_pl_lang['face'][1]['show']?1:0, //是否开启评论表情
  'showimg'=>(int)$com_pl_lang['openImg'], //是否开启附加添加
  'randname'=>com_pl::makeFace(), //分配随机用户名
  'replyhidenum'=>(int)$com_pl_lang[replyHideLineNum], //回复超出行数自定隐藏
  'plsize'=>$plsetr[plsize],//最大评论字数
  'render'=>RepPostVar($_GET['render']), //指定渲染评论框架位置
  'newsurl'=>$public_r[newsurl],
  'baseUrl'=>$public_r[newsurl].'e/extend/com_pl/'
);
//脚本压缩后输出
echo JSMin::minify(($com_pl_lang[useJquery]?file_get_contents('data/jquery.min.js'):'').file_get_contents('data/com_pl.js'));
?>
;if(window.$){
  $(function(){
    com_pl.init("<?=addslashes(com_pl::compress_html($html))?>",'<?=$id?>','<?=$classid?>',<?=json_encode($jsconfig)?>);
    try{<?=JSMin::minify(stripSlashes($com_pl_lang[javascript]))?>;}catch(e){console.log(e);}
  });
}else{
  console.error('评论模块需要依赖jquery');
}