<?php
	@ini_set('display_errors','0');
	error_reporting (E_ALL & ~E_NOTICE);
	define('DIRCMSS_ROOT', str_replace("\\", '/',substr(dirname(__FILE__),0,-4)));
	include DIRCMSS_ROOT.'include/common.inc.php';

	if($_userid)
	{
		if($catid)
		{
			showmsg('您已经登陆，现转到会员发布页面...',$DIRCMS['site_url'].'member/index.php?file=content&action=add&catid='.$catid);
		}
		else
		{
			showmsg('您已经登陆，现转到会员发布页面...',$DIRCMS['site_url'].'member/index.php?file=content&action=manage');
		}
	}

	if(!ANONY)showmsg('网站管理员已禁止游客发布信息!',$DIRCMS['site_url'].'member');
	session_start();
	require_once(DIRCMS_ROOT.'include/admin/content.class.php');
	$content=new content();
	require_once(DIRCMS_ROOT.'include/content.input.class.php');
	if(isset($do_submit))
	{
		/* 防垃圾信息，游客每日限制发帖数量  2010-11-12 */

		unset($t);
		$r=cache_read('ip.cache.php',DIRCMS_ROOT.'post/data/');
		$timekey=strtotime(date('Y-m-d'));
		$t[$timekey]=$r[$timekey];
		$num=$t[$timekey][IP]=intval($t[$timekey][IP])+1;
		unset($r);
		cache_write('ip.cache.php',$t,DIRCMS_ROOT.'post/data/');

		if($num>PERNUM)showmsg('游客每日发帖不得超过'.PERNUM.'篇!');
		if($_SESSION['checkcode']!=$chkcode || !$_SESSION['checkcode'])showmsg('验证码不正确!');
		if(CHK_ASK && $chk_req!=CHK_REQ)showmsg('验证回答答案不正确!');
		$info['catid']=intval($info['catid']);
		$r=cache_read('category'.$info['catid'].'.cache.php',DIRCMS_ROOT.'data/cache_category/');
		$postpriv=explode(',',$r['postpriv']);
		$passpriv=explode(',',$r['passpriv']);
		if(!in_array($_groupid,$postpriv) && $_groupid!=1)showmsg('此栏目禁止您当前的会员组发布内容!');
		if(!$info['catid'] || !$r)showmsg('发布失败!',$DIRCMS['site_url'].'post/index.php');
		$content_input=new content_input($r['modelid']);
		$info=$content_input->check($info);
		if(!trim($info['title']))showmsg('请输入信息标题!');
		if(!trim($info['content']))showmsg('请输入信息内容!');
		$info['description']=($auto_description && !$info['description'])?sub_string(strip_tags($info['content']),200,''):sub_string($info['description'],200,'');
		$info['content']=add_alt($info['content'],$info['title']); //////////////////////自动加 ALT标签
		$info['title']=sub_string($info['title'],160,'');
		$info['keywords']=sub_string($info['keywords'],100,'');
		$info['content']=stripslashes($info['content']);
		$info['status']=in_array($_groupid,$passpriv) || $_groupid==1?1:0;
		if($auto_image)
		{
			$info['content']=down_url_images($info['content']);
		}

		if($auto_thumb && !$info['thumb'])
		{
			$imgindex=intval($imgindex);
			$thumb_r=get_images($info['content']);
			$imgindex=$imgindex>count($thumb_r)?count($thumb_r):$imgindex;
			$imgindex--;
			if($thumb_r && $r['isthumb'])
			{
				require_once(DIRCMS_ROOT.'include/image.class.php');
				$image=new image();
				if(substr($thumb_r[$imgindex],0,7)!='http://')
				{
					$info['thumb']=substr($image->thumb($_SERVER['DOCUMENT_ROOT'].$thumb_r[$imgindex],$r['thumb_width'],$r['thumb_height']),strlen($_SERVER['DOCUMENT_ROOT']));
				}
				else
				{
					$info['thumb']=$thumb_r[$imgindex];
				}
			}
			else
			{
				$info['thumb']=$thumb_r[$imgindex];
			}
		}
		$info['thumb']=substr($info['thumb'],0,strlen(DIRCMS_PATH))==DIRCMS_PATH?substr($info['thumb'],strlen(DIRCMS_PATH)):$info['thumb'];
		if($content->add($info))showmsg('发布成功!','index.php?file=content&action=add&catid='.$info['catid']);
		else showmsg('发布失败!','index.php?file=content&action=add&catid='.$info['catid']);
	}
	if($catid)
	{
		$catid=$info['catid']?$info['catid']:($catid?$catid:0);
		$catid=intval($catid);
		$r=cache_read('category'.$catid.'.cache.php',DIRCMS_ROOT.'data/cache_category/');
		if(!$r)showmsg('不存在该栏目!',$DIRCMS['site_url'].'post/index.php');
		$modelid=$r['modelid'];
		require_once(DIRCMS_ROOT.'include/form.class.php');	
		$f=new form($modelid);
		$base_r=$f->get();	
		$catid_select=$f->catid($catid,$catid);
		$menu=cache_read('parent.cache.php',DIRCMS_ROOT.'data/cache_category/');
		$dir_postion=$position='<a href="'.$DIRCMS['site_url'].'">首页</a> > 游客投稿 > <a href="'.$DIRCMS['site_url'].'/post/index.php">选择栏目</a> > <font color="#ff0000">发布信息</font>';
		$finalcatid_r=cache_read('finalcatid.cache.php',DIRCMS_ROOT.'data/cache_category/');
		
		$template=$r['contenttlp'];	
	}
	else
	{
		$t=array();
		$r=cache_read('category.cache.php',DIRCMS_ROOT.'data/cache_category/');
		if($r)foreach($r as $_r)
		{
			$postpriv=explode(',',$_r['postpriv']);
			if($_r['isshow'] && !$_r['ispage']&& !$_r['parentid'] && in_array($_groupid,$postpriv))$t[]=$_r;
		}

		$dir_postion=$position='<a href="'.$DIRCMS['site_url'].'">首页</a> > 游客投稿 > <font color="#ff0000">选择栏目</font></a> > 发布信息';
	}
	include template('post');
?>