<?php
if(!isset($api2)){
$this->rs("请求失败:非法接口。");
}
if(!$this->here()){
$this->rs("请求失败",333);
}
$uid=$_SESSION["uid"];
//发布内容
if($api2=="contentadd"){
if(!isset($_POST["title"]) or empty($_POST["title"]) ){
$this->rs("创建失败:请输入标题");
}
$title=$_POST["title"];
$title=htmlspecialchars($title, ENT_QUOTES);
$title=strip_tags(str_replace(" "," ",$title));
if($title==""){
$this->rs("创建失败:请输入标题");
}
if(!isset($_POST["content"]) or empty($_POST["content"]) ){
$this->rs("创建失败:请输入内容");
}
$content=$_POST["content"];
if($content==""){
$this->rs("创建失败:请输入内容");
}
preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$content,$imgs);
$tu=array();
$tun-1;
if(count($imgs[2])>0){
foreach ($imgs[2] as $k => $v) {
if(preg_match('/^(data:\s*image\/(\w+);base64,)/',$v)){
preg_match('/^(data:\s*image\/(\w+);base64,)/',$v, $r3);
$base64_body = substr(strstr($v,','),1);
$img = base64_decode($base64_body);
$type =$r3[2];
$file_name_ok ="pub/pic/".md5($v).".".$type;
if($tun<=3){
$tu[]="/".$file_name_ok;
}
$content=str_replace($v, "/".$file_name_ok,$content);
file_put_contents($file_name_ok,$img);
$tun++;
}else if(preg_match('/^(http)/',$v) and !preg_match('/(link2)/',$v)){
if($tun<=3){
$tu[]=$v;
}
}
}
}
preg_match_all('/<\s*iframe\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$content,$iframes);
if(count($iframes[2])>0){
foreach ($iframes[2] as $k => $v) {
$frametxt='<div class="ifrsbx"><iframe width="100%" height="60%" style="min-height:350px;" src="'.$v.'" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"></iframe></div>';
break;
}
}
if(!isset($frametxt)){
$tucount=count($tu);
if($tucount>0){
if($tucount>3){
$tucount=3;
}
$tutxt="<div class='picsbx".$tucount."'>";
$t=0;
foreach($tu as $k=>$v){
if($t==3){break;}
$tutxt=$tutxt."<Div class='picsb'><img src='".$v."'/></div>";
$t++;
}
$tutxt=$tutxt."</div>";
}
}
$intro='';
if(isset($frametxt)){
$intro=$frametxt;
}else if(isset($tutxt)){
$intro=$tutxt;
}
$sa = new cleanHtml;
$sa->allow = array( 'id' );
$content=strip_tags($content, "<p> <img> <div> <a> <iframe> <span>");
$sa->exceptions = array(
'p'=>array( 'style'),
'span'=>array( 'style'),
'img' => array( 'src'),
'a' => array( 'href','target'),
'iframe'=> array( 'src','width','height','referrerpolicy','scrolling','border','frameborder','framespacing','allowfullscreen','style')
);
$content = $sa->strip($content);
$fulltext1=$title.strip_tags($content);
preg_match_all('/([\x{4e00}-\x{9fa5}])/u',$fulltext1,$zw);
$nww=array();
foreach($zw[0] as $k => $v){
$nww[md5($k)]['n']=$v;
$nww[md5($k)]['v']=str_replace('"','',str_replace('"\\','',json_encode($v)));
}
foreach($nww as $k2 => $v2){
$fulltext1=str_replace($v2['n']," ".$v2['v']." ",$fulltext1);
}
$fulltext1=str_replace(" "," ",$fulltext1);
$this->sql("INSERT INTO `j_content`( `uid`, `time`, `title`, `content`, `intro`, `fulltext1`) VALUES ('".$uid."','".time()."','".$this->res($title)."','".$this->res($content)."','".$this->res($intro)."','".$this->res($fulltext1)."')");
$cid=mysql_insert_id();
if($this->c["bdtoken"]!="" and $title!="测试"){
if($this->c["wjt"]=="on"){
$url='content/'.$cid.'.html';
}else{
$url='?type=content&cid='.$cid;
}
$urls = array(
$_SERVER["REQUEST_SCHEME"].'://'.$_SERVER["HTTP_HOST"].'/'.$url
);
$api33 = 'http://data.zz.baidu.com/urls?site='.$_SERVER["HTTP_HOST"].'&token='.$this->c["bdtoken"];
$ch = curl_init();
$options = array(
CURLOPT_URL => $api33,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("\n", $urls),
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
}
$this->rs($cid,1);
}
//delete
else if($api2=="delete"){
if(!isset($_POST["cid"]) or !is_numeric($_POST["cid"])){
$this->rs("抱歉错误");
}
$cid=$_POST["cid"];
$sqlc=$this->sql("select `cid`,`content` from `j_content` where `uid`='".$uid."' and `cid`='".$this->res($cid)."' ");
if($this->num($sqlc)==0){
$this->rs("抱歉错误:内容不存在");
}
$r=$this->row($sqlc);
$content=$r[1];
preg_match_all('/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i',$content,$imgs);
if(count($imgs[2])>0){
foreach ($imgs[2] as $k => $v) {
$file_name_ok =trim($v,"/");
rename($file_name_ok,str_replace("pic/","pic2/",$file_name_ok));
}
}
$this->Sql("INSERT INTO `j_content2`(`cid`, `uid`, `time`, `title`, `content`, `intro`, `fulltext1`, `view`, `liked`) (select `cid`, `uid`, `time`, `title`, replace(`content`, 'pic/', 'pic2/') as `content`, replace(`intro`, 'pic/', 'pic2/') as `intro`, `fulltext1`, `view`, `liked` from `j_content` where `uid`='".$uid."' and `cid`='".$this->res($cid)."') ");
$this->sql("delete from `j_view` where `cid`='".$this->res($cid)."' ");
$this->sql("delete from `j_liked` where `cid`='".$this->res($cid)."' ");
$this->sql("delete from `j_content` where `cid`='".$this->res($cid)."' ");
$this->rs("完成删除",1);
}
else //网站基本信息设置
if($api2=="configedit"){
$a=array();
if(!isset($_POST["webname"]) or empty($_POST["webname"]) ){
$this->rs("提交失败:webname错误");
}
$a["webname"]=$_POST["webname"];
if(!isset($_POST["webtitle"]) or empty($_POST["webtitle"]) ){
$this->rs("提交失败:webtitle错误");
}
$a["webtitle"]=$_POST["webtitle"];
if(!isset($_POST["beianhao"]) or empty($_POST["beianhao"]) ){
$this->rs("提交失败:beianhao错误");
}
$a["beianhao"]=$_POST["beianhao"];
if(!isset($_POST["lianxi"]) or empty($_POST["lianxi"]) ){
$this->rs("提交失败:lianxi错误");
}
$a["lianxi"]=$_POST["lianxi"];
if(!isset($_POST["bdtoken"]) ){
$this->rs("提交失败:bdtoken错误");
}
$a["bdtoken"]=$_POST["bdtoken"];
if(!isset($_POST["wjt"]) or empty($_POST["wjt"]) ){
$this->rs("提交失败:wjt错误");
}
$a["wjt"]=$_POST["wjt"];
$a["v"]="简单记典藏版";
$json=json_encode($a);
file_put_contents("pub/json/config.json",$json);
$this->rs("完成修改",1);
}
else //logo
if($api2=="logo"){
if(!isset($_POST["base64v"]) or empty($_POST["base64v"]) ){
$this->rs("修改失败:请输入内容");
}
$base64v=$_POST["base64v"];
preg_match('/^(data:\s*image\/(\w+);base64,)/',$base64v, $r3);
if(!isset($r3[2])){
$this->rs("修改失败:请输入内容");
}
$base64_body = substr(strstr($base64v,','),1);
$img = base64_decode($base64_body);
$type =$r3[2];
$file_name_ok ="favicon.png";
file_put_contents($file_name_ok,$img);
$this->rs("修改成功",1);
}
else //广告设置
if($api2=="configad"){
$a=array();
if(!isset($_POST["ad1"]) ){
$this->rs("提交失败:ad1");
}
$a["ad1"]=$_POST["ad1"];
if(!isset($_POST["ad2"]) ){
$this->rs("提交失败:ad2");
}
$a["ad2"]=$_POST["ad2"];
if(!isset($_POST["ad3"]) ){
$this->rs("提交失败:ad3");
}
$a["ad3"]=$_POST["ad3"];
$json=json_encode($a);
file_put_contents("pub/json/configad.json",$json);
$this->rs("完成修改",1);
}
//msgdel
else if($api2=="msgdel"){
if(!isset($_POST["mid"]) or !is_numeric($_POST["mid"])){
$this->rs("抱歉错误");
}
$mid=$_POST["mid"];
$sqlc=$this->sql("select `mid` from `j_msg` where `mid`='".$this->res($mid)."' ");
if($this->num($sqlc)==0){
$this->rs("抱歉错误:内容不存在");
}
$this->sql("delete from `j_msg` where `mid`='".$this->res($mid)."' ");
$this->rs("删除完毕",1);
}
//msgauto
else if($api2=="msgauto"){
if(