<?php
set_time_limit(0);
ini_set('pcre.backtrack_limit', -1);
include(dirname(__FILE__)."/require.php");
if($ppurview[45]!=1)
  jump("jump.php?id=25&jump=main.php");
if($_GET['action']=="zt")
{
  if(!isset($_GET['mubiao']))
  {
    $_GET['mubiao']=$_POST['mubiao'];
	$_GET['bar']=$_POST['bar'];
	$_GET['author']=$_POST['author'];
	$_GET['bendihua']=$_POST['bendihua'];
	$_GET['url']=$_POST['url'];
	$_GET['page']=1;
	$_GET['cjpage']=$_POST['cjpage'];
  }
  if($_GET['bar']=="")
    jump("jump.php?id=2&jump=reprint.php");
  $phpcolor->table="bar";
  $phpcolor->field="id";
  $phpcolor->where="barname = '".$_GET['bar']."'";
  if(!$bar=$phpcolor->exist(1))
    jump("jump.php?id=7&jump=reprint.php");
  include(dirname(__FILE__)."/./configs/".$_GET['mubiao']."_post.php");
  //×÷Õß
  $author=$_SERVER['REMOTE_ADDR'];
  if($_GET['author']=="1")
    $author = $_COOKIE["core_user_name"];
  if($theme=="")
    jump("jump.php?id=2&jump=reprint.php");
  if($_GET['page']==1)
  {
    $phpcolor->table="cache_post";
    $phpcolor->field="theme,content,file,author,published,belong,barurl";
    $phpcolor->where="'".$theme."','".$contents[0]."','".$tupian[0]."','".$author."','".$zttime[0]."','".$bar['id']."','".$barurl."'";
    $phpcolor->write();
    $postid=mysql_insert_id();
    for($i=1;$i<count($contents);$i++)
    {
      $phpcolor->where="'','".$contents[$i]."','".$tupian[$i]."','".$author."','".$zttime[$i]."','".$postid."','".$barurl."'";
      $phpcolor->write();
    }
	$_GET['postid']=$postid;
  }
  else
  {
	$phpcolor->table="cache_post";
	$phpcolor->field="theme,content,file,author,published,belong,barurl";
    for($i=0;$i<count($contents);$i++)
    {
      $phpcolor->where="'','".$contents[$i]."','".$tupian[$i]."','".$author."','".$zttime[$i]."','".$_GET['postid']."','".$barurl."'";
      $phpcolor->write();
    }
  }
  if($_GET['cjpage']<=$_GET['page'])
	jump("jump.php?id=24&jump=reprint.php");
  else
    jump("jump.php?page=".$_GET['page']."&id=26&jump=reprint.php?action=zt=and=mubiao=".$_GET['mubiao']."=and=bar=".$_GET['bar']."=and=author=".$_GET['author']."=and=bendihua=".$_GET['bendihua']."=and=url=".$_GET['url']."=and=cjpage=".$_GET['cjpage']."=and=page=".($_GET['page']+1)."=and=postid=".$_GET['postid']);
}
elseif($_GET['action']=="ztok")
{
  $_POST['content'][0]=nl2br(autolink($_POST['content'][0]));
  for($i=0;$i<count($_POST['tupian'][0]);$i++)
  {
    $filename = time().random(6);
    $picname="../upload/reprint/".$filename.".jpg";
    GrabImage($_POST['tupian'][0][$i],$picname,$_POST['barurl']);
    $piclink=$core_url."upload/reprint/".$filename.".jpg";
    $_POST['content'][0]=str_replace($_POST['tupian'][0][$i],$piclink,$_POST['content'][0]);;
  }
  $phpcolor->table="topic";
  $phpcolor->field="theme, content, file, author, ip, published, republished, pxtime, belong, state, remind";
  $phpcolor->where="'".$_POST['theme']."','".$_POST['content'][0]."','','".$_POST['author']."','".$_SERVER['REMOTE_ADDR']."','".$_POST['zttime'][0]."','".$_POST['zttime'][0]."','".$_POST['zttime'][0]."','".$_POST['barid']."','1','0'";
  $phpcolor->write();
  $postid=mysql_insert_id();
  if(!is_ip($_POST['author']))
  {
    $phpcolor->newswrite($postid,$_POST['zttime'][0],$userv['id'],5);
  }
  for($i=1;$i<count($_POST['content']);$i++)
  {
	for($j=0;$j<count($_POST['tupian'][$i]);$j++)
    {
      $filename = time().random(6);
	  $picname="../upload/reprint/".$filename.".jpg";
      GrabImage($_POST['tupian'][$i][$j],$picname,$_POST['barurl']);
	  $piclink=$core_url."upload/reprint/".$filename.".jpg";
	  $_POST['content'][$i]=str_replace($_POST['tupian'][$i][$j],$piclink,$_POST['content'][$i]);;
    }
    $phpcolor->table="repost";
    $phpcolor->field="content, file, author, ip, published, belong, floor, state";
    $phpcolor->where="'".$_POST['content'][$i]."','','".$_POST['author']."','".$_SERVER['REMOTE_ADDR']."','".$_POST['zttime'][$i]."','".$postid."','".$i."','1'";
    $phpcolor->write();
	if(!is_ip($_POST['author']))
	{
	  $rsid=mysql_insert_id();
	  $phpcolor->newswrite($rsid,$_POST['zttime'][$i],$userv['id'],6);
	}
  }
  if($i>=2)
  {
    $phpcolor->table="topic";
    $phpcolor->field="reauthor='".$_POST['author']."',republished = '".$_POST['zttime'][($i-1)]."',pxtime = '".$_POST['zttime'][($i-1)]."',reply = '".($i-1)."',click = '".(($i-1)*2)."'";
    $phpcolor->where="id = '".$postid."'";
    $phpcolor->upgrade();
  }
  $phpcolor->table="cache_post";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->delete();
  $phpcolor->where="belong = '".$_GET['id']."' and theme = ''";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=reprint.php");
}
elseif($_GET['action']=="show")
{
  $phpcolor->table="cache_post";
  $phpcolor->field="*";
  $phpcolor->where="id = '".$_GET['id']."'";
  $post=$phpcolor->exist(1);
  $tupian[0]=split("\|", $post['file']);
  
  
  $phpcolor->table="bar";
  $phpcolor->field="barname";
  $phpcolor->where="id = '".$post['belong']."'";
  $rs=$phpcolor->exist(1);
  $post['belongbn']=$rs['barname'];
  $phpcolor->table="cache_post";
  $phpcolor->field="*";
  $phpcolor->where="belong = '".$_GET['id']."' and theme = '' order by published,id";
  $repost=$phpcolor->assignment();
  for($count=0;$count<count($repost);$count++)
  {
    $tupian[$count+1] = split("\|", $repost[$count]['file']);
  }
  $tpl -> assign("post", $post);
  $tpl -> assign("repost", $repost);
  $tpl -> assign("tupian", $tupian);
  $tpl -> display("reprint_show.htm");
}
elseif($_GET['action']=="del")
{
  $phpcolor->table="cache_post";
  $phpcolor->where="id = '".$_GET['id']."'";
  $phpcolor->delete(); 
  $phpcolor->where="belong = '".$_GET['id']."' and theme = ''";
  $phpcolor->delete();
  jump("jump.php?id=24&jump=reprint.php");
}
else
{
  $phpcolor->table="cache_post";
  $phpcolor->field="*";
  $phpcolor->where="theme != '' order by published desc";
  $post=$phpcolor->assignment();
  $phpcolor->table="bar";
  for($count=0;$count<count($post);$count++)
  {
    $phpcolor->field="barname";
    $phpcolor->where="id = '".$post[$count]['belong']."'";
    $rs=$phpcolor->exist(1);
    $post[$count]['belong']=$rs['barname'];
  }
  $tpl -> assign("post", $post);
  $tpl -> display("reprint.htm");
}
?>