<?php
class addshare
{
	public function index()
	{
		require_once APP_ROOT_PATH."system/libs/user.php";
		$root = array();		
		$content = strim($GLOBALS['request']['content']);
		$source = strim($GLOBALS['request']['source']);
		$source = str_replace("来自","",$source);
		$email = strim($GLOBALS['request']['email']);
		$pwd = strim($GLOBALS['request']['pwd']);

		
		$result = do_login_user($email,$pwd);
		$GLOBALS['user_info'] = $user_data = es_session::get('user_info');
		$user_data['id'] = intval($user_data['id']);
		if(intval($user_data['id'])==0)
		{
			$root['return'] = 0;
			$root['info'] = "请先登录";
			output($root);			
		}
		
		if(isset($_FILES['image_1']))
		{
			//开始上传
			//上传处理
			//创建comment目录
			if (!is_dir(APP_ROOT_PATH."public/comment")) { 
		             @mkdir(APP_ROOT_PATH."public/comment");
		             @chmod(APP_ROOT_PATH."public/comment", 0777);
		        }
			
		    $dir = to_date(get_gmtime(),"Ym");
		    if (!is_dir(APP_ROOT_PATH."public/comment/".$dir)) { 
		             @mkdir(APP_ROOT_PATH."public/comment/".$dir);
		             @chmod(APP_ROOT_PATH."public/comment/".$dir, 0777);
		        }
		        
		    $dir = $dir."/".to_date(get_gmtime(),"d");
		    if (!is_dir(APP_ROOT_PATH."public/comment/".$dir)) { 
		             @mkdir(APP_ROOT_PATH."public/comment/".$dir);
		             @chmod(APP_ROOT_PATH."public/comment/".$dir, 0777);
		        }
		     
		    $dir = $dir."/".to_date(get_gmtime(),"H");
		    if (!is_dir(APP_ROOT_PATH."public/comment/".$dir)) { 
		             @mkdir(APP_ROOT_PATH."public/comment/".$dir);
		             @chmod(APP_ROOT_PATH."public/comment/".$dir, 0777);
		        }
		        
		         
	   		if(app_conf("IS_WATER_MARK")==1)
	   		$img_result = save_image_upload($_FILES,"image_1","comment/".$dir,$whs=array('thumb'=>array(100,100,1,0)),1,1);	
			else
	   		$img_result = save_image_upload($_FILES,"image_1","comment/".$dir,$whs=array('thumb'=>array(100,100,1,0)),0,1);	
			
			
			if(app_conf("PUBLIC_DOMAIN_ROOT")!='')
        	{
        		$paths = pathinfo($img_result['topic_image']['url']);
        		$path = str_replace("./","",$paths['dirname']);
        		$filename = $paths['basename'];
        		$pathwithoupublic = str_replace("public/","",$path);
	        	$syn_url = app_conf("PUBLIC_DOMAIN_ROOT")."/es_file.php?username=".app_conf("IMAGE_USERNAME")."&password=".app_conf("IMAGE_PASSWORD")."&file=".get_domain().APP_ROOT."/".$path."/".$filename."&path=".$pathwithoupublic."/&name=".$filename."&act=0";
	        	@file_get_contents($syn_url);
        	}
			
			require_once APP_ROOT_PATH."system/utils/es_imagecls.php";
			$image = new es_imagecls();
			$info = $image->getImageInfo($img_result['image_1']['path']);
			
			$image_data['width'] = intval($info[0]);
			$image_data['height'] = intval($info[1]);
			$image_data['name'] = valid_str($_FILES['image_1']['name']);
			$image_data['filesize'] = filesize($img_result['image_1']['path']);
			$image_data['create_time'] = get_gmtime();
			$image_data['user_id'] = intval($GLOBALS['user_info']['id']);
			$image_data['user_name'] = addslashes($GLOBALS['user_info']['user_name']);
			$image_data['path'] = $img_result['image_1']['thumb']['thumb']['url'];
			$image_data['o_path'] = $img_result['image_1']['url'];
			$GLOBALS['db']->autoExecute(DB_PREFIX."topic_image",$image_data);	
			$image_id = intval($GLOBALS['db']->insert_id());
			//end 上传
		}
		
		if($image_id>0)
		$attach_list = array(array("id"=>$image_id,"type"=>"image"));
		else
		$attach_list = array();

		$id = insert_topic(valid_str($content),$title="",$type="",$group="",$relay_id=0,$fav_id=0,$group_data=array(),$attach_list);
		if($id)
		{
			increase_user_active($user_data['id'],"发表了一则分享");
				$GLOBALS['db']->query("update ".DB_PREFIX."topic set source_name = '".$source."' where id = ".intval($id));
		}
		
		$root['return'] = 1;
		$root['status'] = 1;
		output($root);
	}
}
?>