<?php
defined('PHP168_PATH') or die();

/**
* 添加内容
**/

$this_controller->check_admin_action($ACTION) or message('no_privilege');

if(REQUEST_METHOD == 'GET'){
	
	$data = array();
	
	isset($_GET['cid']) && $data['cid'] = $_GET['cid'];
	
	$attributes = array();
/**
* your code
**/
	include template($this_module, 'edit', 'admin');
	
}else if(REQUEST_METHOD == 'POST'){

set_time_limit(0);
$_POST = p8_stripslashes2($_POST);

$category = &$this_system->load_module('category');
$category->get_cache();

$dir = '../gxnu/novel/';
$d = opendir($dir);
$i = 0;
while(($item = readdir($d)) !== false){
	if($item == '.' || $item == '..') continue;
	
	$fc = explode("\r\n", file_get_contents($dir.$item));
	$i++;
	foreach($fc as $v){
	//如果魔法引号开启strip掉
	
	while(true){
		$_POST['cid'] = array_rand($category->categories);
		if($category->categories[$_POST['cid']]['type'] == 2) break;
	}
	
	$_POST['attribute'] = array();
	
	//1/10的机会是图片
	$s = mt_rand(0, 10);
	if($s){
		unset($_POST['frame']);
	}else{
		//1/20的机会是首页幻灯
		$s = mt_rand(0, 20);
		if($s){
			unset($_POST['attribute'][1]);
		}else{
			$_POST['attribute'][1] = 1;
		}
		$_POST['frame'] = 'http://www.16865.com/attachment/php168.jpg';
	}
	
	//1/100机会是首页头条
	$s = mt_rand(0, 100);
	if($s){
		unset($_POST['attribute'][2]);
	}else{
		$_POST['attribute'][2] = 2;
	}
	
	//1/20的机会是推荐
	$s = mt_rand(0, 20);
	if($s){
		unset($_POST['attribute'][5]);
	}else{
		$_POST['attribute'][5] = 5;
	}
	
	//1/100机会是未验证
	$_POST['verify'] = mt_rand(0, 100) ? 1 : 0;
	
	$_POST['title'] = $item . $i;
	$_POST['#field_content_posted'] = 1;
	$_POST['field#']['content'] = $v;
	
	//preg_split("/<div style=\"page-break-after\: always; display\: none;\">.*?<\/div>/s", $_POST['#field']['content']);
	//for($i=0;$i<20000;$i++){
		//$_POST['cid'] = mt_rand(1, 500);
		$this_controller->add($_POST) or message('fail');
	//}
	}
}
/**
* your code
**/
	message('done');
}
