<?php
class huochetouAction extends baseAction {
    public function add_post(){
    // echo convert_html_to_swf("http://v.qq.com/cover/j/jts0frrj1jankdg.html?vid=l0198e7fwvc");
    if(IS_POST){
			if(C('hct_password') == I('password')){
            $data = M('content_content');
            $content = str_replace("\n","<br/>",$_POST['content']);
            $content = str_replace(" ","&nbsp;",$content);//以上为正则替换基本内容
            $insert_data['title'] = $_POST['title'];
            $insert_data['content'] = $content;
            $insert_data['addtime'] = time();
            $insert_data['view'] = rand(1,50);
            $insert_data['yes'] = rand(1,50);
            $insert_data['no'] = rand(1,10);
            $insert_data['comment'] = rand(1,50);
            $insert_data['comment'] = rand(1,50);
            $insert_data['status'] = 1;//待审核
            $user = $this->user_info();
            $insert_data['author'] = 'feimao88';
            $insert_data['authorid'] = '6';
            $insert_data['comment_status'] = 'open';
            $insert_data['anonymous'] = '0';
            $insert_data['type'] = 1;
            if(I('thumb')) {
				$file_path = 'uploads/images/'.date("Y").date("m").date("d");
				if(!is_dir($file_path)){
					mkdir($file_path, 0777, true);
				}
				$thumb = $file_path.'/'.I('thumb');
            $insert_data['thumb'] = $thumb;
            $insert_data['content'] = "<img src='". __ROOT__ . '/' . $thumb ."'>";
			}
            if($insert_data['thumb']== '' && $insert_data['content'] == ''){
                echo '数据添加失败';
            }
            if($cid = $data->data($insert_data)->add()){
				if(I('tag')){
                $taglist = explode(',',I('tag'));
                foreach($taglist as $k=>$v){
                    if($k < 3){
                    $tags = M('tag')->where("title='". $v ."'")->find();
                    if($tags) {
                        M('tag')->where("title='". $v ."'")->save(array('number'=>$tags['number']+1));
                        $tid=$tags['id'];
                    }else{
                        $tid = M('tag')->data(array('title'=>$v,'addtime'=>time(),'number'=>1))->add();
                    }
                    M('content_tag')->data(array('tid'=>$tid,'cid'=>$cid))->add();
                    }
                }
                }
                echo '数据添加成功';
            }else{
                echo '数据添加失败';
            }
			}else{
				echo '发布密码不正确';
			}
        }else{
            echo '数据添加失败';
        }
    }
}