<?php require 'authentication_manager.php'; ?>
<?php
//栏目分类设置
if (POWER != 5) {
  err('该命令必须以基本管理员身份登陆！请重登陆');
}

$err_pldr = '';

if ($_GET['act'] == 'del') {
  if (!empty($_GET['imgurl']) && file_exists($_GET['imgurl'])) {
    @unlink($_GET['imgurl']);
  }
  err('<script>
try{
  parent.$("n_img'.$_GET['id'].'").innerHTML="";
  parent.$("linkimg'.$_GET['id'].'").value="";
  parent.$("linkimgold'.$_GET['id'].'").value="";
}catch(e){}
</script>');


}

@ require 'readonly/function/read_file.php';

if ($_GET['act'] == 'zhua') {
  if (empty($_GET['http']) || !preg_match('/^https?:\/\/.+/i', $_GET['http'])) {
    err('<script> alert("请填写准确的网址先！"); </script>');
  } 
  if (empty($_GET['id'])) {
    err('<script> alert("参数缺失！"); </script>');
  }
  if ($f=read_file($_GET['http'])){
    if (function_exists('mb_detect_encoding')) {
      $cha=mb_detect_encoding($f, array('EUC-CN','GB2312','GBK','UTF-8','ASCII','CP936','BIG-5'));
    }
    if (!$cha) {
      if(preg_match('/<meta [^>]*charset[\s\r\n]*=[\s\r\n]*[\"\']?([\w\-]+)[\"\']?[^\>]*>/i',$f,$m)){
        $cha=$m[1];
      }  
    }
    if ($cha) {
      $cha=strtolower($cha);
      preg_match('/<meta [^>]*description[^>]*content[\s\r\n]*=[\s\r\n]*[\"\']?([^>\"\']*)[\"\']?[^>]*>/i', $f, $mm) || preg_match('/<meta [^>]*content[\s\r\n]*=[\s\r\n]*[\"\']?([^>\"\']*)[\"\']?[^>]*description[^>]*>/i', $f, $mm);
      if (empty($mm[1])) {
        if (preg_match('/<meta [^>]*keywords[^>]*content[\s\r\n]*=[\s\r\n]*[\"\']?([^>\"\']*)[\"\']?[^>]*>/i', $f, $mm) || preg_match('/<meta [^>]*content[\s\r\n]*=[\s\r\n]*[\"\']?([^>\"\']*)[\"\']?[^>]*keywords[^>]*>/i', $f, $mm)) {
          $mmmm = 1;
        }
      }
      if ($mm[1]) {
        if($cha!='utf-8'){
          if ($cha == 'gb2312' || $cha == 'euc-cn') {
            $cha = 'gbk';
          }
          $mm[1]=iconv($cha,'utf-8//IGNORE',$mm[1]);
        }
        err('<script>
try{
  parent.document.getElementById("linkdescription'.$_GET['id'].'").value="'.str_replace('|','&#124;',preg_replace('/[\'\"\>\<\n\r]+/','',$mm[1])).'";
  parent.document.getElementById("zhua'.$_GET['id'].'").innerHTML="抓";
}catch(e){}
var zhua = parent.document.getElementById("zhua_'.$_GET['id'].'");
if (zhua!=null) {
  zhua.className="red_err redword";
  '.(isset($mmmm) ? '
  zhua.innerHTML="└ 没有抓到description（简介），用替代方案，抓到的是keywords（关键词）";
  ' : '
  zhua.innerHTML="<center>抓取成功！</center>";
  setTimeout(function(){zhua.innerHTML="";},1000);
  ').'
}
</script>');
      } else {
        err('<script>
  parent.document.getElementById("linkdescription'.$_GET['id'].'").value="";
  parent.$("zhua'.$_GET['id'].'").innerHTML="抓";

if (parent.document.getElementById("zhua_'.$_GET['id'].'")!=null) {
  parent.document.getElementById("zhua_'.$_GET['id'].'").innerHTML="└ 抓取失败！此网站简介（description）为空";
  parent.document.getElementById("zhua_'.$_GET['id'].'").className="red_err blueword";
}
</script>');
      }
    } else {
      chunk_echo('<script>
if (parent.document.getElementById("zhua_'.$_GET['id'].'")!=null) {
  parent.document.getElementById("zhua_'.$_GET['id'].'").innerHTML="└ 抓取失败！此网站可能编码不是UTF-8，或者防抓取，或者无法访问";
  parent.document.getElementById("zhua_'.$_GET['id'].'").className="red_err blueword";
}
</script>');

    }

  } else {
    err('<script>
  parent.$("zhua_'.$_GET['id'].'").innerHTML="└ 此网址'.$_GET['http'].'打不开！网站可能无法访问";
  parent.$("zhua'.$_GET['id'].'").innerHTML="抓";
</script>');
  }
}

if ($_POST['act'] == 'zhua_all') {
  if ($_POST['c'] == 'c') {
    foreach ((array)$_POST['_linkhttp'] as $k => $v) {
      list($h_id, $h_url) = @explode('|', $v);
      chunk_echo('<script>
if (parent.document.getElementById("linkdescription['.$_POST['id'].']'.$h_id.'")!=null) {
  parent.document.getElementById("linkdescription['.$_POST['id'].']'.$h_id.'").value="";
}
</script>');
    }
    err('<script> parent.delSubmitSafe(); </script>', 'ok');
  }



  err('当前版本可能无法进行此项！<a href="http://www.162100.com/pay/for_s_162100.php">建议您升级到商业版，谢谢支持</a><script> alert("当前版本可能无法进行此项！建议您升级到商业版，谢谢支持"); window.open("http://www.162100.com/pay/for_s_162100.php"); parent.$("mainform").act.value=""; parent.delSubmitSafe(); </script>');
}


if ($_POST['act'] == 'up') {
  $err1 = '<script> alert("';
  $err2 = '"); </script>';
}
@ require 'writable/set/set_area.php';

//if (!(isset($_GET['column_id']) && array_key_exists($_GET['column_id'], $web['area']))) {
if (!(isset($_GET['column_id']) && isset($web['area'][$_GET['column_id']]))) {
  err($err1.'频道参数缺失或错误'.$err2);
}
//if (!(isset($_GET['class_id']) && array_key_exists($_GET['class_id'], $web['area'][$_GET['column_id']]))) {
if (!(isset($_GET['class_id']) && isset($web['area'][$_GET['column_id']][$_GET['class_id']]))) {
  err($err1.'栏目参数缺失或错误'.$err2);
}





if ($_POST['act'] == 'up') {
  if (empty($_POST['up'])) {
    err('<script> alert("参数缺失！[01]"); </script>');
  }

  if (is_array($_FILES['uploadfile_'.$_POST['up']]) && $_FILES['uploadfile_'.$_POST['up']]['size']) {

    $inis = ini_get_all();
    $uploadmax = $inis['upload_max_filesize'];
    if ($_FILES['uploadfile_'.$_POST['up']]['size'] > 30 * 1024) {
      err('<script> alert("图片上传不成功！上传的文件请小于30KB"); </script>');
    }
    if (!preg_match('/\.(jpg|gif|png)$/i', strtolower($_FILES['uploadfile_'.$_POST['up']]['name']), $matches)) {
      err('<script> alert("图片上传不成功！请选择一个有效的文件：允许的格式有（jpg|gif|png）"); </script>');
    }
    $upload_dir = 'writable/__web__/images/'.$_GET['column_id'].'_'.$_GET['class_id'].'';
    if (!file_exists($upload_dir) && !@mkdir($upload_dir)) {
      $upload_dir = 'writable/__web__/images';
      if (!file_exists($upload_dir) && !@mkdir($upload_dir)) {
        $upload_dir = 'writable/__web__';
        if (!file_exists($upload_dir) && !@mkdir($upload_dir)) {
          err('<script> alert("图片无法上传，上传目录不存在或无法创建"); </script>');
        }
      }
    }
    //@chmod($upload_dir, 0777);
    eval('@chmod($upload_dir, 0'.$web['chmod'].');');
    $upload_file = gmdate('YmdHis', time() + (floatval($web['time_pos']) * 3600));
    if ($fp = @fopen($_FILES['uploadfile_'.$_POST['up']]['tmp_name'], 'rb')) {
      $img_contents = @fread($fp, $_FILES['uploadfile_'.$_POST['up']]['size']);
      @fclose($fp);
    } else {
      $img_contents = @file_get_contents($_FILES['uploadfile_'.$_POST['up']]['tmp_name']);
    }
    if (preg_match('/<\?php|eval|POST|base64_decode|base64_encode/i', $img_contents, $m_err)) {
      err('<script> alert("提示！禁止提交。该文件含有禁止的代码'.str_replace('?', '\?', $m_err[0]).'"); </script>');
    }

    list($type, $n) = @explode('_', $_POST['up']);

    if (@move_uploaded_file($_FILES['uploadfile_'.$_POST['up']]['tmp_name'], $upload_dir.'/'.$upload_file.'.'.strtolower($matches[1]))) {

      list($im_w, $im_h) = getimagesize($upload_dir.'/'.$upload_file.'.'.strtolower($matches[1]));
      if ((is_numeric($im_w) && is_numeric($im_h)) && ($im_w > 0 &&  $im_h > 0)) {
        $im_size = ' width=\"'.$im_w.'\" height=\"'.$im_h.'\"';
      } else {
        $im_size = '';
      }

      if (!empty($_POST['linkimgold'][$type][$n]) && file_exists($_POST['linkimgold'][$type][$n])) {
        @unlink($_POST['linkimgold'][$type][$n]);
      }
      err('<script>
try{
  parent.$("n_img['.$type.']['.$n.']").innerHTML="<img src=\"'.$upload_dir.'/'.$upload_file.'.'.strtolower($matches[1]).'\"'.$im_size.' onmouseover=\"showBig(this);\" /><br /><a href=\"javascript:void(0)\" onclick=\"delFile(\'['.$type.']['.$n.']\');\">×</a>";
  parent.$("linkimg['.$type.']['.$n.']").value="<img class=\"site_icon\" src=\"'.$upload_dir.'/'.$upload_file.'.'.strtolower($matches[1]).'\"'.$im_size.' />";
  parent.$("linkimgold['.$type.']['.$n.']").value="'.$upload_dir.'/'.$upload_file.'.'.strtolower($matches[1]).'";
}catch(e){}

parent.$("mainform").act.value="";
parent.delSubmitSafe();
alert("图片上传成功！");

</script>');


    } else {
      err('<script> alert("图片上传不成功！[03]"); </script>');
    }
  } else {
    err('<script> alert("图片不存在！路径不正确；或系统出错，请稍候再试"); </script>');
  }

}

$text_del = 0;
$text_caiji = '';
$text_p = '';
$p_b = $p_e = NULL;

if (!empty($_POST['p_url'])) {
  if (!preg_match("/^https?:\/\//i", $_POST['p_url'])) {
    err('采集源URL填写不对！应以http://或https://开头');
  }
  if (empty($_POST['p_b']) && empty($_POST['p_e'])) {
    err('采集前后标记必填一项！');
  }
  $text_caiji = '采集也成功执行完毕。';
  $time_step = time() + floatval($web['time_pos']) * 3600;


  if (!isset($_POST['p_time']) || !is_numeric($_POST['p_time']) || $_POST['p_time'] == '') {
    $_POST["p_time"] = "";
    $time_stamp = $time_step + 100 * 365 * 24 * 60 * 60;
  } else {
    if ($_POST['p_time'] == 1) {
      if (!abs($_POST['p_time_val']) > 0) {
        err('采集时效若以分钟为间隔必须大于0啊！');
      } else {
        $_POST['p_time'] = abs($_POST['p_time_val']);
        $time_stamp = $time_step + $_POST['p_time'] * 60;
      }
    } else {
      $_POST['p_time_key'] = abs($_POST['p_time_key']);
      $_POST['p_time'] = $_POST['p_time_key'] > 0 ? '-'.$_POST['p_time_key'] : 0;
      $time_0 = $time_step - (gmdate('H', $time_step) * 3600 + gmdate('i', $time_step) * 60 + gmdate('s', $time_step));
      $time_stamp = $time_0 + $_POST['p_time_key'] * 3600 + ($_POST['p_time_key'] > abs(gmdate('H', $time_step)) ? 0 : 24 * 3600);
    }
  }

  $eval_caiji = 1;

  
} else {
  $text_caiji = '未填写采集源URL，未进行采集。';
}


function run_URLdecode($e) {
/*
    $text = "";
    if ($m = preg_split('/%3F/i', $e[1], 2)) {
      $text .= preg_match("/%[0-9A-Z]+/", $m[0]) ? urldecode($m[0]) : $m[0];
      if (count($m) == 2) {
        $text .= (!empty($m[1]) && preg_match("/(%[0-9A-Z]{4}){2,}/", $m[1])) ? '?'.urldecode($m[1]) : '?'.$m[1];
      }
    }
    return $text;
*/
    return '<a href='.urldecode($e[1]).'>';
}






if (!isset($sql['db_err'])) {
  $db = db_conn();
}
if ($sql['db_err'] != '') {
  err($sql['db_err']);
}

//为旧版列增加长度
db_exec($db, 'ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` MODIFY COLUMN column_id VARCHAR(32)');
db_exec($db, 'ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` MODIFY COLUMN http_name_style LONGTEXT');
db_exec($db, 'ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` ADD COLUMN `class_grab` text');

@ require 'readonly/function/filter.php';

$e0 = $e1 = $text_correct = $text_chongfu = $text_cc = $up_err = '';

$_GET['class_title'] = preg_replace('/\|.*$/', '', $_GET['class_title']);

if (!empty($_GET['class_title']) && !empty($_GET['detail_title'])) {
  $_GET['detail_title'] = str_replace('/', '-', filter(htmlspecialchars($_GET['detail_title']))); //&#47;
  @ require 'readonly/function/pinyin.php';
  $dpy = pinyin($_GET['detail_title']);

  $result = db_query($db, 'SELECT id, detail_title FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.$_GET['class_title'].'" AND detail_title LIKE "'.$_GET['detail_title'].'|%" AND http_name_style=""');// AND LENGTH(class_priority)>0
  if ($result != false) {
    if ($row = db_fetch($db, $result)) { //专题已存在，进行更新
      $key_id = ' AND id<>"'.$row['id'].'"';
      list(, $dpy, ) = @explode('|', $row['detail_title']);
      unset($row);
    }
  }
  $result = NULL;
  $result = db_query($db, 'SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE detail_title LIKE "%|'.$dpy.'|%"'.$key_id.' AND http_name_style=""');// AND LENGTH(class_priority)>0
  unset($key_id);
  if ($result != false) {
    while ($row = db_fetch($db, $result)) {
      list($detail_cf, $dpy_cf, ) = @explode('|', $row['detail_title']);
      $text_chongfu .= '
<div class="blueword">'.$web['area'][$row['column_id']]['name'][0].'/'.$web['area'][$row['column_id']][$row['class_id']][0].'/'.$row['class_title'].'/'.$detail_cf.'：<input type="text" size="10" name="detail_correct['.$row['column_id'].'_'.$row['class_id'].'_'.urlencode($row['class_title']).'_'.urlencode($detail_cf).'_'.$dpy_cf.']" value="'.$dpy_cf.'" />
<input type="hidden" name="detail_pinyin_cfid['.$row['column_id'].'_'.$row['class_id'].'_'.urlencode($row['class_title']).'_'.urlencode($detail_cf).'_'.$dpy_cf.']" value="'.$row['id'].'" />
</div>';
      unset($row, $detail_cf, $dpy_cf);
    }
  }

  $result = NULL;
  if (isset($duoyin_mark[$_GET['detail_title']])) {
    $text_correct .= '<span class="redword">（'.$duoyin_mark[$_GET['detail_title']].'）</span>';
  }

  $name = '专题';
  if (isset($_POST['dside']) && is_numeric($_POST['dside']) && ($_POST['dside'] == 1 || $_POST['dside'] == 2 || $_POST['dside'] == 3)) {
    $ds .= $_POST['dside'];
    $ds .= '-';
    $ds .= $_POST['dside_'] == 'l' || $_POST['dside_'] == 'r' ? $_POST['dside_'] : 'r';
    $ds .= '-';
    $ds .= $_POST['dside'] == 1 || $_POST['dside'] == 3 ? ($_POST['dside__'] == 1 ? (abs($_POST['dside__n']) >= 1 && abs($_POST['dside__n']) <= 4 ? abs($_POST['dside__n']) : 2) : 0) : 0;
    $ds .= '-';
    $ds .= abs($_POST['dside___']) < 120 ? 120 : (abs($_POST['dside___']) > 380 ? 380 : abs($_POST['dside___']));
  } else {
    $ds .= '';
  }
  $e0 = $_GET['detail_title'].'|'.$dpy.'|'.$ds.'';
  $e_ = $_GET['detail_title'].'|';
  $e1 = ' AND detail_title LIKE "'.$_GET['detail_title'].'|%"';
  $eh1 = 'detail.php';
  $eh2 = $dpy.'.html';
  $html_page = $dpy.'.html';

} else {
  $name = '栏目';
  $e0 = $e_ = '';
  $e1 = ' AND detail_title=""';
  //$eh1 = 'class.php';
  //$eh2 = $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html';
  $html_page = $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html';
  $_GET['class_title'] = '栏目头栏';
  $chan_zt = 1;
}

$beiarr = $imarro = $imarrn = array();
$imgreg = '/<img [^>]*src\s*=\s*"?(writable/__web__\/images\/'.$_GET['column_id'].'_'.$_GET['class_id'].'\/[^\/\"\s]+)"?/i';
$result = db_query($db, 'SELECT * FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'"'.$e1.'');// ORDER BY id
if ($result != false) {
  while ($row = db_fetch($db, $result)) {
    preg_match_all($imgreg, $row['http_name_style'], $m1);
    preg_match_all($imgreg, $row['class_priority'], $m2);
    $imarro = @array_merge((array)$imarro, (array)$m1[1], (array)$m2[1]);
    $beiarr[$row['id']] = $row['id'];
    unset($row, $m1, $m2);
  }
}
$result = NULL;

$_POST['class_title'] = (array)$_POST['class_title'];

$o_n = $s_n = 0;

if (count($_POST['class_title']) > 0) {
  if (count($_POST['class_title']) > count(array_unique($_POST['class_title']))) {
    err('栏目分类名称不能空也不能有重名！');
  }
  if (count($_POST['class_title']) > count(array_filter(preg_replace('/^\s+|\s+$/', '', $_POST['class_title'])))) {
    err('栏目分类名称不能有空值！');
  }
  foreach ($_POST['class_title'] as $class_title_old => $class_title_new) {
    if (/*$class_title_new == '栏目置顶' || */$class_title_new == '栏目头栏') {
      err('栏目分类名称不能为“栏目头栏”！与系统默认词冲突！');
    }
    $class_priority = stripslashes_(preg_replace("/<\!--|-->/", "", $_POST['class_priority'][$class_title_old])); //分类头栏
    $http_name_style = stripslashes_(preg_replace("/<\!--|-->/", "", $_POST['http_name_style'][$class_title_old]));
    $img_t .= $http_name_style;
    $class_n = (!empty($_POST['class_n'][$class_title_old]) && is_numeric($_POST['class_n'][$class_title_old]) && $_POST['class_n'][$class_title_old] >= 2 && $_POST['class_n'][$class_title_old] <= 8) ? $_POST['class_n'][$class_title_old] : 4;
    $class_more = (!empty($_POST['class_more'][$class_title_old]) && is_numeric($_POST['class_more'][$class_title_old])) ? $_POST['class_more'][$class_title_old] : '';
    
    if (db_exec($db, "INSERT INTO `".$sql["pref"]."".$sql["data"]["承载网址数据的表名"]."` (`column_id`,`class_id`,`class_title`,`http_name_style`,`class_priority`,`detail_title`) VALUES ('".$_GET["column_id"]."','".$_GET["class_id"]."','".filter($class_title_new)."|".$class_n."|".$class_more."',".db_escape_string($db, $http_name_style).",".db_escape_string($db, $class_priority).",'".$e_."')")) {
	  $res = 1;
	}
    //echo $sql['db_err'];
    $n_this = substr_count($http_name_style, "\n");
    $o_n += $n_this;

    if (!$res) {
      $s_n += $n_this;
    } else {
      if (isset($chan_zt)) { //该栏目下的专题一起带过来
        db_exec($db, 'UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET class_title="'.filter($class_title_new).'" WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.urldecode($class_title_old).'" AND detail_title<>"" AND http_name_style=""');// AND LENGTH(class_priority)>0
      }
    }
    unset($n_this);

    preg_match_all($imgreg, $img_t, $m1);
    preg_match_all($imgreg, $class_priority, $m2);
    $imarrn = @array_merge((array)$imarrn, (array)$m1[1], (array)$m2[1]);
    if (isset($chan_zt)) { //该栏目下的专题一起带过来
      db_exec($db, 'UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET class_title="'.filter($class_title_new).'" WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.urldecode($class_title_old).'" AND detail_title<>"" AND http_name_style=""');// AND LENGTH(class_priority)>0
    }
    unset($class_title_old, $class_title_new, $class_priority, $http_name_style, $class_n, $class_more, $img_t, $m1, $m2);
  }

} else {
  $text_del ++;
  db_exec($db, 'DELETE FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND NOT (class_title="'.$_GET['class_title'].'" AND http_name_style="")'.$e1.'');// AND LENGTH(class_priority)>0 //删除除头栏之外的分类列表
}





@ ini_set('track_errors', 1);


//$_POST['priority'] = filter2($_POST['priority']);

$_POST['priority'] = stripslashes_($_POST['priority']);
if (isset($eval_caiji)) {
  $php_errormsg = NULL;
  $_POST["p_url"] = filter($_POST["p_url"]);
  if ($str_caiji = read_file($_POST["p_url"])) {

	if (function_exists("mb_detect_encoding")) {
	  $cha = mb_detect_encoding($str_caiji, array("UTF-8","ASCII","EUC-CN","CP936","BIG-5","GB2312","GBK"));
	}
    if (!$cha) {
      if(preg_match("/charset[\s\r\n]*=[\s\r\n'\"]*([\w\-]+)[^\>]*>/i", $str_caiji, $m_cha)){
	    $cha = $m_cha[1];
      }
    }
    if (isset($cha) && $cha != "") {
      if(strtolower($cha) != "utf-8"){
        $str_caiji = @iconv($cha, "utf-8", $str_caiji);
      }
    }

    $_POST["p_b"] = preg_replace("/[\s\r\n]+/", " ", $_POST["p_b"]);
    $_POST["p_b"] = get_magic_quotes_gpc() ? stripslashes($_POST["p_b"]) : $_POST["p_b"];
    $p_b = addcslashes($_POST["p_b"], '.\+*?[^]$(){}=!<>|:-"/'); //preg_quote
    $p_b = preg_replace("/[\s\r\n]+/", "[\\s\\r\\n]+", $p_b);
    $p_b = (isset($_POST["p_b_is"]) && $_POST["p_b_is"] == 1) ? $p_b."(" : "(".$p_b;
    $_POST["p_e"] = preg_replace("/[\s\r\n]+/", " ", $_POST["p_e"]);
    $_POST["p_e"] = get_magic_quotes_gpc() ? stripslashes($_POST["p_e"]) : $_POST["p_e"];
    $p_e = addcslashes($_POST["p_e"], '.\+*?[^]$(){}=!<>|:-"/'); //preg_quote
    $p_e = preg_replace("/[\s\r\n]+/", "[\\s\\r\\n]+", $p_e);
    $p_e = (isset($_POST["p_e_is"]) && $_POST["p_e_is"] == 1) ? ")".$p_e : $p_e.")";

    preg_match("/".$p_b.".+".$p_e."/is", $str_caiji, $m_caiji);

    if ($php_errormsg !== NULL) {
      $text_caiji = "<b>采集标记填写得不对！请填写准确的正则。错误代码：</b><i>[".$php_errormsg."]</i><br>";
      $php_errormsg = NULL;
    } else {
      if (!$m_caiji) {
        $text_caiji = "<b>采集源URL或采集标记填写得不对！请检查。没有采集数据被存储。</b><br>";
      } else {
        $_POST["priority"] = $m_caiji[1];
        $_POST["p_change_fr"] = array_filter($_POST["p_change_fr"]);
        $_POST["p_change_to"] = array_filter($_POST["p_change_to"]);
        if ($_POST["p_change_fr"] && $_POST["p_change_to"]) {
          $text_caiji = "";
          foreach((array)$_POST["p_change_fr"] as $p_key => $p_val) {
            $p_val = get_magic_quotes_gpc() ? stripslashes($p_val) : $p_val;
            $p_val = trim($p_val);
            $p_val = preg_replace("/[\s\r\n]+/", "[\\s\\r\\n]+", $p_val);
            $p_val = preg_replace("/\{162100\~mark\d+\}/i", "", $p_val);
            $_POST["p_change_to"][$p_key] = !isset($_POST["p_change_to"][$p_key]) || empty($_POST["p_change_to"][$p_key]) ? "" : $_POST["p_change_to"][$p_key];
            $_POST["p_change_to"][$p_key] = get_magic_quotes_gpc() ? stripslashes($_POST["p_change_to"][$p_key]) : $_POST["p_change_to"][$p_key];
            $_POST["p_change_to"][$p_key] = trim($_POST["p_change_to"][$p_key]);
            $_POST["p_change_to"][$p_key] = preg_replace("/\{162100\~mark\d+\}/i", "", $_POST["p_change_to"][$p_key]);
            if ($p_val != "") {
              $priority_temp = preg_replace(''.$p_val.'', ''.$_POST['p_change_to'][$p_key].'', $_POST["priority"]);
              if ($php_errormsg !== NULL) {
                $text_caiji .= "<b>过滤正则[".($p_key+1)."]填写得不对！故没有对采集到的数据进行过滤。错误代码：</b><i>[".$php_errormsg."]</i><br>";
                $php_errormsg = NULL;
                continue;
              } else {
                $_POST["priority"] = $priority_temp;
                $p_change_arr[] = $p_val."{162100~mark1}".$_POST["p_change_to"][$p_key];
              }
              unset($priority_temp);
            }
          }
          if ($_POST["URLdecode"] == 1) {
            $_POST["priority"] = preg_replace_callback('/<a [^>]*href=([^>]+)>/iU', 'run_URLdecode', $_POST["priority"]);
          }
          $text_caiji = $text_caiji == "" ? "采集也成功执行完毕。" : $text_caiji;
        }
        $text_p = "".$time_stamp."\n".$_POST["p_time"]."\n".$_POST["p_url"]."\n".$_POST["p_b"]."\n".$_POST["p_e"]."\n".((isset($_POST["p_b_is"]) && $_POST["p_b_is"] == 1) ? 1 : 0)."\n".((isset($_POST["p_e_is"]) && $_POST["p_e_is"] == 1) ? 1 : 0)."\n".(isset($p_change_arr) && is_array($p_change_arr) && count($p_change_arr) > 0 ? @implode("{162100~mark2}", $p_change_arr) : "")."\n".(!empty($_POST["priority_pos"]) ? "1" : "")."\n".(!empty($_POST["URLdecode"]) ? "1" : "")."";
      }
    }

  } else {
    $text_caiji = "<b>采集源URL填写得不对！没有采集到数据。</b><br>";
  }
}



if ((!empty($_POST['priority']) && trim($_POST['priority']) != '') || !empty($text_p)) {
  if (!db_exec($db, "INSERT INTO `".$sql["pref"]."".$sql["data"]["承载网址数据的表名"]."` (`column_id`,`class_id`,`class_title`,`detail_title`,`http_name_style`,`class_priority`,`class_grab`) VALUES ('".$_GET["column_id"]."','".$_GET["class_id"]."','".$_GET["class_title"]."','".$e0."','',".db_escape_string($db, $_POST["priority"]).",".db_escape_string($db, $text_p).")")) {
    $text_caiji = '<b>栏目头栏储存失败！错误代码：</b><i>['.$sql['db_err'].']</i><br>';
  }
  $pinyin_cf_id = db_insert_id($db);
} else {

  if ($name == '专题' && $text_del == 0) { //如果专题的头栏没有内容，也不能为空，否则失去专题引导
    $result = db_query($db, 'SELECT id FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.$_GET['class_title'].'" AND http_name_style=""'.$e1.' LIMIT 1');// AND LENGTH(class_priority)>0
    $row = db_fetch($db, $result);
    $result = NULL;
    if ($row) {
      db_exec($db, 'UPDATE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` SET class_priority=" " WHERE id="'.$row['id'].'"');
      $pinyin_cf_id = $row['id'];
      unset($beiarr[$row['id']]);
      unset($row);
    } else {
      db_exec($db, "INSERT INTO `".$sql["pref"]."".$sql["data"]["承载网址数据的表名"]."` (`column_id`,`class_id`,`class_title`,`detail_title`,`http_name_style`,`class_priority`,`class_grab`) VALUES ('".$_GET["column_id"]."','".$_GET["class_id"]."','".$_GET["class_title"]."','".$e0."','',' ','')");
      $pinyin_cf_id = db_insert_id($db);
    }
  } else {
    $text_del ++;
    db_exec($db, 'DELETE FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title="'.$_GET['class_title'].'" AND http_name_style=""'.$e1.''); // AND LENGTH(class_priority)>0
  }
}

if (count($beiarr) > 0) {
  foreach ($beiarr as $id) {
    if ($id && is_numeric($id) && $id > 0) {
      db_exec($db, 'DELETE FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE id="'.$id.'"');
    }
  }
}


if ($name == '专题') {
  if (isset($_POST['detail_list']) && $_POST['detail_list'] == 1) { //自动将专题链接加入上级栏目列表中
    $up_img = '';
/*
    $url = $dpy.'.html';
    $result = db_query($db, 'SELECT id,http_name_style FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND class_title LIKE "'.$_GET['class_title'].'|%" AND detail_title=""'); //其实应该 LIMIT 1
    if ($result != false) {
      while ($row = db_fetch($db, $result)) {
        $row['http_name_style'] = preg_replace('/.*'.preg_quote($url, '/').'\|[^\r\n]+[\r\n]+/', '', $row['http_name_style']);
*/
        if ($text_del != 2) {
          $up_img = get_up_img();
/*
          $row['http_name_style'] = $row["http_name_style"]."".$url."|".$up_img."".$_GET['detail_title']."||\n";
*/
        }
/*
        if (!db_exec($db, "UPDATE `".$sql["pref"]."".$sql["data"]["承载网址数据的表名"]."` SET http_name_style=".db_escape_string($db, $row["http_name_style"])." WHERE id='".$row["id"]."'")) {
          $up_err .= '[加入上级分类列表失败]';
        }
        unset($row);
      }
    }
    $result = NULL;
*/
    //$eh1 = 'class.php';
    //$eh2 = $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html';
  }
} else {
  if (!(isset($_POST['detail_keep']) && $_POST['detail_keep'] == 1)) { //如果删除失去上级栏目的专题
    //if (count($_POST['class_title']) > 0) {
      db_exec($db, 'DELETE FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` WHERE column_id="'.$_GET['column_id'].'" AND class_id="'.$_GET['class_id'].'" AND detail_title<>"" AND detail_title NOT IN (SELECT TEMP.detail_title FROM (SELECT M.* FROM `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` M) TEMP WHERE TEMP.column_id="'.$_GET['column_id'].'" AND TEMP.class_id="'.$_GET['class_id'].'" AND (TEMP.class_title LIKE "'.@implode('|%" OR TEMP.class_title LIKE "', $_POST['class_title']).'|%") AND TEMP.detail_title<>"" AND (TEMP.http_name_style="" AND TEMP.class_priority<>""))');
    //}
  }
}

/*
//重置MYSQL ID
db_exec($db, 'ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` DROP `id`');
db_exec($db, 'ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` ADD `id` INT(10) NOT NULL FIRST');
db_exec($db, 'ALTER TABLE `'.$sql['pref'].''.$sql['data']['承载网址数据的表名'].'` MODIFY COLUMN `id` INT(10) NOT NULL AUTO_INCREMENT,ADD PRIMARY KEY(id)');
*/

db_close($db);
$out_detail_title = $_GET['detail_title'];

@ require 'readonly/function/write_file.php';
reset_indexhtml('index.php', 'index.html');
if ($eh1 && $eh2) {
  reset_indexhtml($eh1, $eh2);
}
reset_indexhtml('class.php', $web['area'][$_GET['column_id']]['name'][1].'_'.$web['area'][$_GET['column_id']][$_GET['class_id']][1].'.html');
reset_indexhtml('column.php', $web['area'][$_GET['column_id']]['name'][1].'.html');

if ($text_del == 2) {
  $out_text = '数据删除成功！';
  @ require 'writable/set/set_html.php';
  if ($web['html'] == true) {
    if (file_exists($html_page)) {
	  @unlink($html_page);
	}
  }
  @ require 'readonly/function/deldir.php';
  deldir('writable/__web__/images/'.$_GET['column_id'].'_'.$_GET['class_id'].'');
} else {
  $out_text = '设置成功！';
}


if ($name == '专题' || ($name == '栏目' && (isset($_POST['detail_keep']) && $_POST['detail_keep'] == 1))) {
  if (!(isset($_POST['img_keep']) && $_POST['img_keep'] == 1)) {
    if (count($imarro) > 0) {
      foreach ($imarro as $im) {
        if (!in_array($im, $imarrn)) {
          @unlink($im);
        }
      }
    }
  }
}


if (($text_correct != '' || $text_chongfu != '') && $text_del != 2) {

  $text_cc .= '
<form action="?post=http_p" method="post" style="border:1px #FF6600 solid; margin:0 10px; padding:5px; color:#333333; font-size:12px;">';

  if ($text_correct != '') {
    $text_cc .= '
  <p><b class="redword">发现多音字！因为专题页面以拼音命名，请进行校正再提交，否则同名文件将被覆盖。</b></p>';
  }
  if ($text_chongfu != '') {
    $text_cc .= '
  <p><b class="blueword">发现拼音重名！因为专题页面以拼音命名，请进行校正再提交，否则同名文件将被覆盖</b></p>
  '.$text_chongfu;
  }

  $text_cc .= '
  <div>'.$web['area'][$_GET['column_id']]['name'][0].'/'.$web['area'][$_GET['column_id']][$_GET['class_id']][0].'/'.$_GET['class_title'].'/'.$_GET['detail_title'].'（当前）：<input type="text" size="10" name="detail_correct['.$_GET['column_id'].'_'.$_GET['class_id'].'_'.urlencode($_GET['class_title']).'_'.urlencode($out_detail_title).'_'.$dpy.']" value="'.$dpy.'" />'.$text_correct.'
<input type="hidden" name="detail_pinyin_cfid['.$_GET['column_id'].'_'.$_GET['class_id'].'_'.urlencode($_GET['class_title']).'_'.urlencode($out_detail_title).'_'.$dpy.']" value="'.$pinyin_cf_id.'" />

</div>';

  $text_cc .= '
  <button type="submit">提交</button>
  <button type="button" onclick="window.history.back();">放弃，返回</button>
</form>';
  err(''.$err_pldr.$name.$out_text.''.$text_cc.$up_err.$text_caiji.'', 'ok');
}



alert(''.$err_pldr.$name.$out_text.'（总计提交'.$o_n.'条，实际导入'.($o_n - $s_n).'条）'.$text_cc.$up_err.$text_caiji, 'webmaster_central.php?get=http&column_id='.$_GET['column_id'].'&class_id='.$_GET['class_id'].'&class_title='.urlencode($_GET['class_title']).'&detail_title='.urlencode($out_detail_title).'');



function filter($text) {
  $text = trim($text);
  $text = stripslashes($text);
  //$text = htmlspecialchars($text);
  $text = preg_replace('/[\r\n\'\"\s\<\>]+/', '', $text);
  $text = str_replace('|', '&#124;', $text);
  //$text = str_replace('/', '&#47;', $text);
  return $text;
}


function get_up_img() {
  global $dpy, $up_err, $web;
  $img = '';
  $br = (isset($_POST['detail_logo']) && $_POST['detail_logo'] == 1) ? '<br />' : '';
  $upload_dir = 'writable/__web__/images/'.$_GET['column_id'].'_'.$_GET['class_id'];
  if (is_array($_FILES['uploadfile']) && $_FILES['uploadfile']['size']) {
    $max_size = 100 * 10000;
    if ($_FILES['uploadfile']['size'] <= $max_size) {
      if (preg_match('/\.(gif|jpe?g|png)$/i', $_FILES['uploadfile']['name'], $im)) {
        //@chmod('writable/__web__', 0777);
        //@chmod('writable/__web__/images', 0777);
        eval('@chmod(\'writable/__web__\', 0'.$web['chmod'].');');
        eval('@chmod(\'writable/__web__/images\', 0'.$web['chmod'].');');
        if (!file_exists($upload_dir)) {
          @mkdir($upload_dir);
        }
        if (file_exists($upload_dir)) {
          //@chmod($upload_dir, 0777);
          eval('@chmod($upload_dir, 0'.$web['chmod'].');');
          $upload_filename = $dpy.'.'.strtolower($im[1]);
          if (@move_uploaded_file($_FILES['uploadfile']['tmp_name'], $upload_dir.'/'.$upload_filename)) {
            $img = '<img src="'.$upload_dir.'/'.$upload_filename.'" />'.$br.'';
          } else {
            $up_err .= '（上传专题图标失败[上传失败，主机系统权限不足]）';
          }
        } else {
          $up_err .= '（上传专题图标失败[上传路径'.$upload_dir.'不存在且不能建立]）';
        }
      } else {
        $up_err .= '（上传专题图标失败[图片格式不是gif|jpg|jpeg|png]）';
      }
    } else {
      $up_err .= '（上传专题图标失败[上传尺寸大于100KB]）';
    }
  } else {
    $up_err .= '（上传专题图标失败[没选择图片]）';
  }
  return $img != '' ? $img : ($_POST['detail_logo_old'] == 1 ? (@file_exists($upload_dir.'/'.$dpy.'.gif') ? '<img src="'.$upload_dir.'/'.$dpy.'.gif" />'.$br : (@file_exists($upload_dir.'/'.$dpy.'.jpg') ? '<img src="'.$upload_dir.'/'.$dpy.'.jpg" />'.$br : (@file_exists($upload_dir.'/'.$dpy.'.png') ? '<img src="'.$upload_dir.'/'.$dpy.'.png" />'.$br : ''))) : '');
}










?>