<?php
/*

发布前请先修改第55行左右的用户名及其用户ID

*/
/**************************************************************************************************/
//define('DEDEADMIN', ereg_replace("[/\\]{1,}", '/', dirname(__FILE__) ) );
define('DEDEADMIN', preg_replace("/[\/\\\\]{1,}/",'/', dirname(__FILE__)));
require_once(DEDEADMIN.'/../include/common.inc.php');
function ClearMyAddon($aid=0, $title='')
{
	global $dsql;
	$cacheFile = DEDEDATA.'/cache/addon-'.session_id().'.inc';
	$_SESSION['bigfile_info'] = array();
	$_SESSION['file_info'] = array();
	if(!file_exists($cacheFile))
	{
		return ;
	}
	//把附件与文档关连
	if(!empty($aid))
	{
		include($cacheFile);
		foreach($myaddons as $addons)
		{
			if(!empty($title)) {
				$dsql->ExecuteNoneQuery("Update `#@__uploads` set arcid='$aid',title='$title' where aid='{$addons[0]}'");
			}
			else {
				$dsql->ExecuteNoneQuery("Update `#@__uploads` set arcid='$aid' where aid='{$addons[0]}' ");
			}
		}
	}
	@unlink($cacheFile);
}
function DedeInclude($filename,$isabs=false)
{
	return $isabs ? $filename : DEDEADMIN.'/'.$filename;
}
/**************************************************************************************************/

require_once(DEDEINC.'/customfields.func.php');
require_once(DEDEADMIN.'/inc/inc_archives_functions.php');
if(file_exists(DEDEDATA.'/template.rand.php'))
{
	require_once(DEDEDATA.'/template.rand.php');
}
if(empty($dopost))
{
	$dopost = '';
}
/**************************************************************************************************/
//  ------      配置阶段开始        ------

$writer = 'zhouzhan';  // 发布时所用的用户名
$adminid = '1';  // 发布时所用的用户对应的ID号

//  ------      配置阶段结束        ------
/**************************************************************************************************/
if($dopost!='save')
{
	require_once(DEDEINC."/dedetag.class.php");
	require_once(DEDEADMIN."/inc/inc_catalog_options.php");
	ClearMyAddon();
	$channelid = empty($channelid) ? 0 : $channelid;
	$tl = new TypeLink($aid);
	$typeOptions = $tl->GetOptionArray(0, $admin_catalogs, $channelid);
	$typeOptions = "<select name='typeid'>
	<option value='0'>请选择发布栏目...</option>\r\n
	$typeOptions
	</select>";
	echo $typeOptions;
	exit();
}

/*--------------------------------
function __save(){  }
-------------------------------*/
else if($dopost=='save')
{
	require_once(DEDEINC.'/image.func.php');
	require_once(DEDEINC.'/oxwindow.class.php');
	$flag = isset($flags) ? join(',',$flags) : '';
	$notpost = isset($notpost) && $notpost == 1 ? 1: 0;

	if(empty($typeid2)) $typeid2 = '';
	if(!isset($autokey)) $autokey = 0;
	if(!isset($remote)) $remote = 0;
	if(!isset($dellink)) $dellink = 0;
	if(!isset($autolitpic)) $autolitpic = 0;
	if(empty($click)) $click = ($cfg_arc_click=='-1' ? mt_rand(50, 200) : $cfg_arc_click);
$comeformo=$comeform1;
echo $comeform;
switch($comeformo){
case '名人名言':
$typeid = 56+0;
$writer = 'yulu'; 
$adminid = '55'; 
$mtype = '2164'; 
break;
case '经典语录':
$typeid = 57+0;
$writer = 'yulu'; 
$adminid = '55'; 
$mtype = '2164'; 
break;
case '娱乐台词':
$typeid = 58+0;
$writer = 'yulu'; 
$adminid = '55'; 
$mtype = '2164'; 
break;
case '爱情心语':
$typeid = 59+0;
$writer = 'yulu'; 
$adminid = '55'; 
$mtype = '2164'; 
break;
case '生活课堂':
$typeid = 60+0;
$writer = 'yulu'; 
$adminid = '55'; 
$mtype = '2164'; 
break;
case '网络语录':
$typeid = 61+0;
$writer = 'yulu'; 
$adminid = '55'; 
$mtype = '2164'; 
break;
//-------------
case '爱情散文':
$typeid = 3+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '古代散文':
$typeid = 13+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '抒情散文':
$typeid = 4+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '名家散文':
$typeid = 14+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '散文诗':
$typeid = 5+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '经典散文':
$typeid = 15+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '精美散文':
$typeid = 6+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '亲情散文':
$typeid = 16+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '优美散文':
$typeid = 7+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '友情散文':
$typeid = 17+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '写物散文':
$typeid = 18+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '伤感散文':
$typeid = 8+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '写人散文':
$typeid = 19+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '情感散文':
$typeid = 9+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '哲理散文':
$typeid = 10+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '记事散文':
$typeid = 20+0;
break;
case '节日散文':
$typeid = 21+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '写景散文':
$typeid = 11+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
case '英语散文':
$typeid = 12+0;
$writer = 'sanwen'; 
$adminid = '2'; 
$mtype = '2160'; 
break;
//shige
case '现代诗歌':
$typeid = 23+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '古风词韵':
$typeid = 24+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '爱情诗歌':
$typeid = 25+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '赞美诗歌':
$typeid = 26+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '诗词鉴赏':
$typeid = 27+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '伤感诗歌':
$typeid = 28+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '写景诗歌':
$typeid = 29+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '节日诗歌':
$typeid = 30+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
case '亲情诗歌':
$typeid = 31+0;
$writer = 'shige'; 
$adminid = '22'; 
$mtype = '2161'; 
break;
//zawen
case '时事评论':
$typeid = 33+0;
$writer = 'zawen'; 
$adminid = '32'; 
$mtype = '2162'; 
break;
case '人生解读':
$typeid = 34+0;
$writer = 'zawen'; 
$adminid = '32'; 
$mtype = '2162'; 
break;
case '文化随笔':
$typeid = 35+0;
$writer = 'zawen'; 
$adminid = '32'; 
$mtype = '2162'; 
break;
case '世俗评说':
$typeid = 36+0;
$writer = 'zawen'; 
$adminid = '32'; 
$mtype = '2162'; 
break;
case '思想钩沉':
$typeid = 37+0;
$writer = 'zawen'; 
$adminid = '32'; 
$mtype = '2162'; 
break;
case '乱弹八卦':
$typeid = 38+0;
$writer = 'zawen'; 
$adminid = '32'; 
$mtype = '2162'; 
break;
//suibi
case '名家随笔':
$typeid = 40+0;
$writer = 'suibi'; 
$adminid = '39'; 
$mtype = '2165'; 
break;
case '生活随笔':
$typeid = 41+0;
$writer = 'suibi'; 
$adminid = '39'; 
$mtype = '2165'; 
break;
case '情感随笔':
$typeid = 42+0;
$writer = 'suibi'; 
$adminid = '39'; 
$mtype = '2165'; 
break;
case '读书随笔':
$typeid = 43+0;
$writer = 'suibi'; 
$adminid = '39'; 
$mtype = '2165'; 
break;
case '散文随笔':
$typeid = 44+0;
$writer = 'suibi'; 
$adminid = '39'; 
$mtype = '2165'; 
break;
case '含羞草':
$typeid = 45+0;
$writer = 'suibi'; 
$adminid = '39'; 
$mtype = '2165'; 
break;
//xiaoshuo
case '爱情小说':
$typeid = 47+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '江湖柔情':
$typeid = 48+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '戏说人生':
$typeid = 49+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '故事新编':
$typeid = 50+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '奇幻小说':
$typeid = 51+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '童话故事':
$typeid = 52+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '另类小说':
$typeid = 53+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
case '尖峰时刻'://寻记
$typeid = 54+0;
$writer = 'xiaoshuo'; 
$adminid = '46'; 
$mtype = '2163'; 
break;
//--------------
case '清纯靓丽':
$typeid = 10+0;
break;
case '清纯写真':
$typeid = 10+0;
break;
case ' 网络红人':
$typeid = 6+0;
break;
case ' 美女自拍':
$typeid = 7+0;
break;
case ' 性感美女':
$typeid = 8+0;
break;
case '性感美女':
$typeid = 8+0;
break;
case '性感诱惑':
$typeid = 8+0;
break;
case ' 体坛风情':
$typeid = 9+0;
break;
case ' 游戏美女':
$typeid = 6+0;
break;
case ' 惊艳模特':
$typeid = 3+0;
break;
case '香艳模特':
$typeid = 3+0;
break;
case ' 明星美女':
$typeid = 4+0;
break;
case ' 卡通美女':
$typeid = 11+0;
break;
case '艳照门':
$typeid = 14+0;
break;
case '90后门事件':
$typeid = 14+0;
break;
case '80后门事件':
$typeid = 14+0;
break;
case '娱乐门':
$typeid = 15+0;
break;
case '娱乐门事件':
$typeid = 15+0;
break;
case '体育门':
$typeid = 16+0;
break;
case '体育门事件':
$typeid = 16+0;
break;
case '社会门':
$typeid = 17+0;
break;
case '社会门事件':
$typeid = 17+0;
break;
case '科技门':
$typeid = 20+0;
break;
case '教育门':
$typeid = 19+0;
break;
case '教育门事件':
$typeid = 19+0;
break;
case '时政门':
$typeid = 20+0;
break;
case '国际门事件':
$typeid = 20+0;
break;
case '企业门':
$typeid = 18+0;
break;
case '财经门':
$typeid = 18+0;
break;
case '感情门':
$typeid = 22+0;
break;
case '游戏门':
$typeid = 23+0;
break;
case '人物门':
$typeid = 24+0;
break;
case '美女视频':
$typeid = 25+0;
break;
}	
$channelid=1;
$zzzxq=mt_rand(1,9);
$zzzxq=$zzzxq.$zzzxq;
$zzzdisplay="1";
$zzzbg="/templets/default/diary/play/bg/".mt_rand(10,18).".jpg";
$zzzmtype=mt_rand(1,2);
$zzztq="/templets/default/diary/tq/".mt_rand(1,10).".gif";
	if(empty($typeid))
	{
		ShowMsg("请指定文档的栏目！","-1");
		exit();
	}
	if(empty($channelid))
	{
		ShowMsg("文档为非指定的类型，请检查你发布内容的表单是否合法！","-1");
		exit();
	}
	if(!CheckChannel($typeid,$channelid))
	{
		ShowMsg("你所选择的栏目与当前模型不相符，请选择白色的选项！","-1");
		exit();
	}

	//对保存的内容进行处理
	//if(empty($writer))$writer=$cuserLogin->getUserName();
	if(empty($source))$source='未知';
	$pubdate = time();
	$senddate = time();
	$sortrank = AddDay($pubdate,$sortup);
	$ismake = $ishtml==0 ? -1 : 0;
	$title = ereg_replace('"', '＂', $title);
	$title = toHtmlChars(cn_substrR($title,$cfg_title_maxlen));
	$shorttitle = cn_substrR($shorttitle,36);
	$color =  cn_substrR($color,7);
	$writer =  cn_substrR($writer,20);
	$source = cn_substrR($source,30);
	$description = cn_substrR($description,$cfg_auot_description);
	$keywords = cn_substrR($keywords,60);
	$filename = trim(cn_substrR($filename,40));
	$userip = GetIP();

	//if(!TestPurview('a_Check,a_AccCheck,a_MyCheck'))
	//{
	//	$arcrank = -1;
	//}
	//$adminid = $cuserLogin->getUserID();

	//处理上传的缩略图
	if(empty($ddisremote))
	{
		$ddisremote = 0;
	}
	
	$litpic = GetDDImage('none', $picname, $ddisremote);

	//生成文档ID
	$arcID = GetIndexKey($arcrank,$typeid,$sortrank,$channelid,$senddate,$adminid);
    
	if(empty($arcID))
	{
		ShowMsg("无法获得主键，因此无法进行后续操作！","-1");
		exit();
	}
	if(trim($title) == '')
	{
		ShowMsg('标题不能为空', '-1');
		exit();
	}

	//处理body字段自动摘要、自动提取缩略图等
//$body=strstr($body,"/Yulu/","/tu/allimg/Yulu/");
$body=str_replace("Yulu/","/tu/allimg/Yulu/",$body);
$body=str_replace("Swen/","/tu/allimg/Swen/",$body);
$body=str_replace("Bixi/","/tu/allimg/Bixi/",$body);
$body=str_replace("SiZa/","/tu/allimg/SiZa/",$body);
$body=str_replace("alt=","zz=",$body);
//echo $body;
	//$body=strstr("src=\"/Yulu/","src=\"/tu/allimg/",$body);
//echo $body;

	$body = AnalyseHtmlBody($body,$description,$litpic,$keywords,'htmltext');
//$st=str_replace("/data/attachment/","",$st);
$keywords=$keyword;
if ($keyword==""){$keyword="美文";}
$body=str_replace("<img","<img alt=\"".$title."_".$keyword.",".$comeformo."_读多多\"",$body);
//if ($litpic==""){$litpic=getpic("读多多www.duduoduo.com<br>".$body);}
echo $litpic;
	//自动分页
	if($sptype=='auto')
	{
		//$body = SpLongBody($body,$spsize*1024,"#p#分页标题#e#");
	}

	//分析处理附加表数据
	$inadd_f = $inadd_v = '';
	if(!empty($dede_addonfields))
	{
		$addonfields = explode(';',$dede_addonfields);
		if(is_array($addonfields))
		{
			foreach($addonfields as $v)
			{
				if($v=='') continue;
				$vs = explode(',',$v);
				if($vs[1]=='htmltext'||$vs[1]=='textdata')
				{
					${$vs[0]} = AnalyseHtmlBody(${$vs[0]},$description,$litpic,$keywords,$vs[1]);
				}
				else
				{
					if(!isset(${$vs[0]})) ${$vs[0]} = '';
					${$vs[0]} = GetFieldValueA(${$vs[0]},$vs[1],$arcID);
				}
				$inadd_f .= ','.$vs[0];
				$inadd_v .= " ,'".${$vs[0]}."' ";
			}
		}
	}

	//处理图片文档的自定义属性
	if($litpic!='' && !ereg('p',$flag))
	{
		$flag = ($flag=='' ? 'p' : $flag.',p');
	}
	if($redirecturl!='' && !ereg('j',$flag))
	{
		$flag = ($flag=='' ? 'j' : $flag.',j');
	}
	
	if($litpic==''){$litpic="/images/defaultpic.gif";}
	//echo $litpic;
	//跳转网址的文档强制为动态
	if(ereg('j', $flag)) $ismake = -1;
$ismake = -1;
echo $keywords;
	//保存到主表
	$query = "INSERT INTO `#@__archives`(id,typeid,typeid2,sortrank,flag,ismake,channel,arcrank,click,money,title,shorttitle,
    color,writer,source,litpic,pubdate,senddate,mid,notpost,description,keywords,filename,dutyadmin,mtype,zzzxq,zzzdisplay,zzzbg,zzzmtype,zzztq)
    VALUES ('$arcID','$typeid','$typeid2','$sortrank','$flag','$ismake','$channelid','$arcrank','$click','$money',
    '$title','$shorttitle','$color','$writer','$source','$litpic','$pubdate','$senddate',
    '$adminid','$notpost','$description','$keywords','$filename','$adminid','$mtype','$zzzxq','$zzzdisplay','$zzzbg','$zzzmtype','$zzztq');";
//echo $query;
	if(!$dsql->ExecuteNoneQuery($query))
	{
		$gerr = $dsql->GetError();
		$dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
		ShowMsg("把数据保存到数据库主表 `#@__archives` 时出错，请把相关信息提交给DedeCms官方。".str_replace('"','',$gerr),"javascript:;");
		exit();
	}
if($keywords!=''){
$dsql->ExecuteNoneQuery("INSERT INTO `#@__taglist`(tid,aid,arcrank,typeid,tag) Values('$arcID','$arcID','0','$typeid','$keywords')");
}
//if(!$dsql->ExecuteNoneQuery("update `#@__member_tj` set article=article+1 where mid='$adminid'"))
$dsql->ExecuteNoneQuery("update `#@__member_tj` set article=article+1 where mid='$adminid'");

	//保存到附加表
	$cts = $dsql->GetOne("Select addtable From `#@__channeltype` where id='$channelid' ");
	$addtable = trim($cts['addtable']);
	if(empty($addtable))
	{
		$dsql->ExecuteNoneQuery("Delete From `#@__archives` where id='$arcID'");
		$dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
		ShowMsg("没找到当前模型[{$channelid}]的主表信息，无法完成操作！。","javascript:;");
		exit();
	}
	$useip = GetIP();
	$templet = empty($templet) ? '' : $templet;
	$query = "INSERT INTO `{$addtable}`(aid,typeid,redirecturl,templet,userip,body{$inadd_f}) Values('$arcID','$typeid','$redirecturl','$templet','$useip','$body'{$inadd_v})";echo $query;
	if(!$dsql->ExecuteNoneQuery($query))
	{
		$gerr = $dsql->GetError();
		$dsql->ExecuteNoneQuery("Delete From `#@__archives` where id='$arcID'");
		$dsql->ExecuteNoneQuery("Delete From `#@__arctiny` where id='$arcID'");
		ShowMsg("把数据保存到数据库附加表 `{$addtable}` 时出错，请把相关信息提交给DedeCms官方。".str_replace('"','',$gerr),"javascript:;");
		exit();
	}

	//生成HTML
	InsertTags($tags,$arcID);
	$artUrl = MakeArt($arcID,true,true);
	if($artUrl=='')
	{
		$artUrl = $cfg_phpurl."/view.php?aid=$arcID";
	}
	ClearMyAddon($arcID, $title);
	//返回成功信息
	$msg = "    　　请选择你的后续操作：
    <a href='article_add.php?cid=$typeid'><u>继续发布文章</u></a>
    &nbsp;&nbsp;
    <a href='$artUrl' target='_blank'><u>查看文章</u></a>
    &nbsp;&nbsp;
    <a href='archives_do.php?aid=".$arcID."&dopost=editArchives'><u>更改文章</u></a>
    &nbsp;&nbsp;
    <a href='catalog_do.php?cid=$typeid&dopost=listArchives'><u>已发布文章管理</u></a>
    &nbsp;&nbsp;
    $backurl
  ";
  $msg = "<div style=\"line-height:36px;height:36px\">{$msg}</div>".GetUpdateTest();
	$wintitle = "成功发布文章！";
	$wecome_info = "文章管理::发布文章";
	$win = new OxWindow();
	$win->AddTitle("成功发布文章：");
	$win->AddMsgItem($msg);
	$winform = $win->GetWindow("hand","&nbsp;",false);
	$win->Display();
}
function toHtmlChars($sHtml)
{
    static $maEntities =
        array ('&' => '&amp;', '<' => '&lt;', '>' => '&gt;', '\'' => '&apos;', '"' => '&quot;', "\n"=>'<br />', ' '=>'&nbsp;');
    return strtr($sHtml, $maEntities);
}
function getpic($str_img){
    preg_match_all("/<img.*\>/isU",$str_img,$ereg);//正则表达式把图片的整个都获取出来了 
	//if(isset($ereg[0][0])){//5.3之
	echo $preg_match[0][0];
if(isset($preg_match[0][0])){
    $img=$ereg[0][0];//图片 
    $p="#src=('|\")(.*)('|\")#isU";//正则表达式
    preg_match_all ($p, $img, $img1); 
    $img_path =$img1[2][0];//获取第一张图片路径  
    return $img_path; 
	}
    }
?>