Example #1
0
	function XsnsCommunity()
	{
		// $key, $data_type, $default, $required, $size
		$this->initVar('c_commu_id', XOBJ_DTYPE_INT);
		$this->initVar('name', XOBJ_DTYPE_TXTBOX);
		$this->initVar('uid_admin', XOBJ_DTYPE_INT);
		$this->initVar('uid_sub_admin', XOBJ_DTYPE_INT);
		$this->initVar('info', XOBJ_DTYPE_TXTAREA);
		$this->initVar('c_commu_category_id', XOBJ_DTYPE_INT);
		$this->initVar('r_datetime', XOBJ_DTYPE_DATETIME);
		$this->initVar('r_date', XOBJ_DTYPE_DATE);
		$this->initVar('public_flag', XOBJ_DTYPE_INT);
		$this->initVar('access_count', XOBJ_DTYPE_INT);
		$this->initVar('update_freq', XOBJ_DTYPE_FLOAT);
		$this->initVar('popularity', XOBJ_DTYPE_FLOAT);
		$this->initVar('up_datetime', XOBJ_DTYPE_DATETIME);
		
		$this->handler = array(
			'community' => XsnsCommunityHandler::getInstance(),
			'user' => XsnsUserHandler::getInstance(),
			'member' => XsnsMemberHandler::getInstance(),
			'image' => XsnsImageHandler::getInstance(),
			'topic' => XsnsTopicHandler::getInstance(),
			'comment' => XsnsTopicCommentHandler::getInstance(),
			'category' => XsnsCategoryHandler::getInstance(),
			'access_log' => XsnsAccessLogHandler::getInstance(),
		);
	}
Example #2
0
function getRedirectURL($target, $target_id)
{
	if($target == 1){
		// for community
		return XSNS_URL_COMMU.'?'.XSNS_ACTION_ARG.'=edit&cid='.$target_id;
	}
	elseif($target == 2){
		// for topic
		$comment_handler =& XsnsTopicCommentHandler::getInstance();
		$comment =& $comment_handler->get($target_id);
		if(is_object($comment)){
			return XSNS_URL_TOPIC.'&'.XSNS_ACTION_ARG.'=edit&tcid='.$target_id;
		}
	}
	return NULL;
}
Example #3
0
	function XsnsTopicComment()
	{
		// $key, $data_type, $default, $required, $size
		$this->initVar('c_commu_topic_comment_id', XOBJ_DTYPE_INT);
		$this->initVar('c_commu_topic_id', XOBJ_DTYPE_INT);
		$this->initVar('c_commu_id', XOBJ_DTYPE_INT);
		$this->initVar('uid', XOBJ_DTYPE_INT);
		$this->initVar('body', XOBJ_DTYPE_TXTAREA);
		$this->initVar('r_datetime', XOBJ_DTYPE_DATETIME);
		$this->initVar('r_date', XOBJ_DTYPE_DATE);
		$this->initVar('number', XOBJ_DTYPE_INT);

		$this->handler = array(
			'image' => XsnsImageHandler::getInstance(),
			'file' => XsnsFileHandler::getInstance(),
			'comment' => XsnsTopicCommentHandler::getInstance(),
		);
	}
Example #4
0
function checkAuthority($image_id, $file_id)
{
	global $xoopsUser, $xoopsUserIsAdmin;
	
	if($xoopsUserIsAdmin){
		return true;
	}
	
	if($this->isGuest()){
		return false;
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	if($image_id > 0){
		$image_handler =& XsnsImageHandler::getInstance();
		$data =& $image_handler->get($image_id);
	}
	elseif($file_id > 0){
		$file_handler =& XsnsFileHandler::getInstance();
		$data =& $file_handler->get($file_id);
	}
	else{
		return false;
	}
	
	if(!is_object($data)){
		return false;
	}
	
	$target = $data->getVar('target');
	$target_id = $data->getVar('target_id');
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$c_member_handler =& XsnsMemberHandler::getInstance();
	
	if($target == 1){
		// for community
		$community =& $commu_handler->get($target_id);
		if(!is_object($community)){
			return false;
		}
		
		$c_member =& $c_member_handler->getOne($target_id, $own_uid);
		if(!is_object($c_member)){
			return false;
		}
		
		if($own_uid == $community->getVar('uid_admin')){	// admin only
			return true;
		}
	}
	elseif($target == 2){
		// for topic/comment
		$comment_handler =& XsnsTopicCommentHandler::getInstance();
		$comment =& $comment_handler->get($target_id);
		if(!is_object($comment)){
			return false;
		}
		
		$tid = $comment->getVar('c_commu_topic_id');
		$topic_handler =& XsnsTopicHandler::getInstance();
		$topic =& $topic_handler->get($tid);
		if(!is_object($topic)){
			return false;
		}
		
		$cid = $comment->getVar('c_commu_id');
		$community =& $commu_handler->get($cid);
		if(!is_object($community)){
			return false;
		}
		
		$c_member =& $c_member_handler->getOne($cid, $own_uid);
		if(!is_object($c_member)){
			return false;
		}
		
		if($own_uid == $comment->getVar('uid')
		   || $own_uid == $topic->getVar('uid')
		   || $own_uid == $community->getVar('uid_admin')
		   || $own_uid == $community->getVar('uid_sub_admin')){
			return true;
		}
	}
	return false;
}
Example #5
0
function dispatch()
{
	global $xoopsUser;
	
	if($this->isGuest()){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	$tcid = $this->getIntRequest('tcid', XSNS_REQUEST_GET);
	if(!isset($tcid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
	$token_handler = new XoopsMultiTokenHandler();
	$token = new XoopsFormToken($token_handler->create('TOPIC_EDIT'));
	// Hidden
	$token_tag = '<input type="hidden" name="'.$token->_name.'" value="'.$token->_value.'">';
	$this->context->setAttribute('token_tag', $token_tag);
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	
	// コメントの取得
	$comment =& $comment_handler->get($tcid);
	if(!is_object($comment)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$tid = $comment->getVar('c_commu_topic_id');
	
	// トピックの取得
	$topic =& $topic_handler->get($tid);
	if(!is_object($topic)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$cid = $topic->getVar('c_commu_id');
	
	// コミュニティの取得
	$community =& $commu_handler->get($cid);
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$commu_auth = $community->getAuthority();
	if($commu_auth < XSNS_AUTH_MEMBER){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$topic_uid = $topic->getVar('uid');
	$comment_uid = $comment->getVar('uid');
	$comment_number = $comment->getNumber();
	
	if($comment_uid > 0
	   && ($own_uid == $topic_uid || $own_uid == $comment_uid || $commu_auth >= XSNS_AUTH_SUB_ADMIN)){
		
		$topic_vars = array(
			'id' => $tid,
			'tcid' => $tcid,
			'name' => $topic->getVar('name', 'e'),
			'lang_page_title' => ($comment_number > 0) ? _MD_XSNS_TITLE_TOPIC_RES_EDIT : _MD_XSNS_TITLE_TOPIC_EDIT,
		);
		
		$comment_vars = array(
			'number' => $comment_number,
			'body' => $comment->getVar('body', 'e'),
			'images' => $comment->getImageList(2, XSNS_IMAGE_SIZE_S),
			'files' => $comment->getFileList(2),
		);
		
		$commu_vars = array('id' => $cid, 'name' => $community->getVar('name'));
		
		$this->context->setAttribute('commu', $commu_vars);
		$this->context->setAttribute('topic', $topic_vars);
		$this->context->setAttribute('comment', $comment_vars);
	}
	else{
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
}
Example #6
0
function &getResList($tid, $res_ids)
{
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	return $comment_handler->getListByNumbers($tid, $res_ids);
}
Example #7
0
function dispatch()
{
	if($this->isGuest()){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$tid = $this->getIntRequest('tid');
	if(!isset($tid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
	$token_handler = new XoopsMultiTokenHandler();
	$token = new XoopsFormToken($token_handler->create('TOPIC_COMMENT_ADD'));
	// Hidden
	$token_tag = '<input type="hidden" name="'.$token->_name.'" value="'.$token->_value.'">';
	$this->context->setAttribute('token_tag', $token_tag);

	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	
	// トピックの取得
	$topic =& $topic_handler->get($tid);
	if(!is_object($topic) || $topic->getCommentCount() >= 1001){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	// コミュニティの取得
	$cid = $topic->getVar('c_commu_id');
	$community =& $commu_handler->get($cid);
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$commu_auth = $community->getAuthority();
	if($commu_auth < XSNS_AUTH_NON_MEMBER
	   || ($commu_auth < XSNS_AUTH_MEMBER && $community->getVar('public_flag')==3) ){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$errors = array();
	
	$body = $this->getTextRequest('body');
	if(empty($body)){
		$errors[] = _MD_XSNS_TOPIC_RES_BODY_NG;
	}
	
	if(count($errors) > 0){
		redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_RES_BODY_NG);
	}
	
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	$new_comment =& $comment_handler->create();
	$new_comment->setVar('body', $body);
	
	$commu_vars = array('id' => $cid, 'name' => $community->getVar('name'));
	
	$sess_handler =& XsnsSessionHandler::getInstance();
	$sess_handler->setVar('comment_body', $body);
	
	$image_handler =& XsnsImageHandler::getInstance();
	$file_handler =& XsnsFileHandler::getInstance();
	
	$topic_vars = array(
		'id' => $tid,
		'name' => $topic->getVar('name'),
		'body' => preg_replace('/\[res\]([1-9]\\d*)\[\/res\]/', '>>\1', $new_comment->getVar('body', 'p')),
		'images' => $image_handler->uploadImageTemp('images'),
		'files' => $file_handler->uploadFileTemp('files'),
	);
	
	$this->context->setAttribute('topic', $topic_vars);
	$this->context->setAttribute('commu', $commu_vars);
}
Example #8
0
function dispatch()
{
	global $xoopsModuleConfig;
	
	$err = $this->checkPermission();
	if(!is_array($err) || count($err) > 0){
		$this->context->setAttribute('perm_error', $err);
		return "default";
	}
	
	$limit = 10;
	$start = $this->getIntRequest('s', XSNS_REQUEST_GET);
	if(!isset($start) || $start<0){
		$start = 0;
	}
	
	$criteria = new CriteriaCompo(NULL);
	$criteria->setLimit($limit);
	$criteria->setStart($start);
	$criteria->setSort('c_file_id');
	$criteria->setOrder('DESC');
	
	$file_handler =& XsnsFileHandler::getInstance();
	$file_obj_list =& $file_handler->getObjects($criteria);
	$file_list = array();
	
	$user_handler =& xoops_gethandler('user');
	
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	$comment = array();
	
	foreach($file_obj_list as $file_obj){
		$file_id = $file_obj->getVar('c_file_id');
		$filename = $file_obj->getVar('filename');
		
		$file_path = $xoopsModuleConfig['file_upload_path']. '/'. $filename;
		$file_info = @stat($file_path);
		$author_obj =& $user_handler->get($file_obj->getVar('uid'));
		$author_name = is_object($author_obj) ? $author_obj->getVar('uname') : "";
		
		$page_url = "";
		
		$target = $file_obj->getVar('target');
		$target_id = $file_obj->getVar('target_id');
		
		if($target==1){
			$page_url = XSNS_URL_COMMU.'?cid='.$target_id;
		}
		elseif($target==2){
			if(!isset($comment[$target_id])){
				$comment[$target_id] =& $comment_handler->get($target_id);
			}
			if(is_object($comment[$target_id])){
				$page_url = XSNS_URL_TOPIC.'&tid='.$comment[$target_id]->getVar('c_commu_topic_id');
			}
		}
		
		$file_list[$file_id] = array(
			'id' => $file_id,
			'url' => XSNS_FILE_URL."?id=".$file_id,
			'ref_link' => empty($page_url) ? "-" : "<a href='".$page_url."' target='_blank'>URL</a>",
			'filename' => rawurldecode($file_obj->getVar('org_filename')),
			'author' => $author_name,
			'size' => number_format($file_info['size']),
			'time' => str_replace(" ", "<br>", date('Y-m-d H:i:s', $file_info['mtime'])),
			'active' => "checked",
		);
		unset($author_obj);
	}
	
	$pager = $this->getPageSelector('index.php?'.XSNS_ACTION_ARG.'=file', 
						$start, $limit, count($file_list), $file_handler->getCount(), "#FFCCCC");
	
	$this->context->setAttribute('file_list', $file_list);
	$this->context->setAttribute('pager', $pager);
}
Example #9
0
function dispatch()
{
	global $xoopsUser;
	
	if($this->isGuest() || !$this->validateToken('TOPIC_ADD')){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	$cid = $this->getIntRequest('cid');
	if(!isset($cid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	// コミュニティの取得
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$community =& $commu_handler->get($cid);
	if(!is_object($community) || !$community->checkAuthority()){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$sess_handler =& XsnsSessionHandler::getInstance();
	$topic = $sess_handler->getVar('topic');
	
	if(!is_array($topic) || !isset($topic['name']) || !isset($topic['body'])){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$r_datetime = date('Y-m-d H:i:s');
	$r_date = date('Y-m-d');
	
	$topic_handler =& XsnsTopicHandler::getInstance();
	$new_topic =& $topic_handler->create();
	
	$new_topic->setVars(array(
		'c_commu_id' => $cid,
		'name' => $topic['name'],
		'r_datetime' => $r_datetime,
		'r_date' => $r_date,
		'uid' => $own_uid,
	));
	
	if($tid = $topic_handler->insert($new_topic)){
		$comment_handler =& XsnsTopicCommentHandler::getInstance();
		$new_comment =& $comment_handler->create();
		
		$new_comment->setVars(array(
			'c_commu_topic_id' => $tid,
			'c_commu_id' => $cid,
			'uid' => $own_uid,
			'body' => $topic['body'],
			'r_datetime' => $r_datetime,
			'r_date' => $r_date,
			'number' => 0,
		));
		
		if($tcid = $comment_handler->insert($new_comment)){
			
			// トピックのコメントに対して画像を添付
			$image_handler =& XsnsImageHandler::getInstance();
			$image_ids = $image_handler->uploadImage('t', 2, $tcid);
			
			// トピックのコメントに対してファイルを添付
			$file_handler =& XsnsFileHandler::getInstance();
			$file_ids = $file_handler->uploadFile('t', 2, $tcid);
			
			// イベント通知
			if(include_once(XSNS_TRUST_PATH.'/include/notification.php')){
				$tags = array(
					'COMMU_NAME' => $community->getVar('name'),
					'TOPIC_NAME' => $new_topic->getVar('name'),
					'TOPIC_BODY' => $new_comment->getVar('body', 'e'),	// disallow HTML
					'AUTHOR_NAME' => $xoopsUser->getVar('uname'),
					'TOPIC_URI' => XSNS_URL_TOPIC.'&tid='.$tid,
				);
				// コミュニティメンバー以外には送信しない
				$c_member_obj_list =& $community->getMemberObjects();
				$c_member_ids = array();
				foreach($c_member_obj_list as $c_member_obj){
					$c_member_ids[] = $c_member_obj->getVar('uid');
				}
				xsns_main_trigger_event('topic', $cid, 'create', $tags, $c_member_ids);
			}
			
			$xoopsUser->incrementPost();
			$sess_handler->clearVars();
			
			redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_ADD_OK);
		}
	}
	redirect_header(XSNS_URL_TOPIC.'&'.XSNS_ACTION_ARG.'=add&cid='.$cid, 2, _MD_XSNS_TOPIC_ADD_NG);
}
Example #10
0
function dispatch()
{
	global $xoopsUser;
	if($this->isGuest()){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	$tcid = $this->getIntRequest('tcid', XSNS_REQUEST_GET);
	if(!isset($tcid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	$user_handler =& XsnsUserHandler::getInstance();
	
	// コメントの取得
	$comment =& $comment_handler->get($tcid);
	if(!is_object($comment)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$tid = $comment->getVar('c_commu_topic_id');
	$num = $comment->getNumber();
	
	// トピックの取得
	$topic =& $topic_handler->get($tid);
	if(!is_object($topic)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$topic_uid = $topic->getVar('uid');
	
	// コミュニティの取得
	$cid = $topic->getVar('c_commu_id');
	$community =& $commu_handler->get($cid);
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$commu_auth = $community->getAuthority();
	if($commu_auth < XSNS_AUTH_MEMBER){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$comment_uid = $comment->getVar('uid');
	if($comment_uid < 1 || ($commu_auth < XSNS_AUTH_SUB_ADMIN && $own_uid != $comment_uid && $own_uid != $topic_uid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$author =& $user_handler->get($comment->getVar('uid'));
	$author_info = is_object($author) ? $author->getInfo() : array('name'=>'', 'page_url'=>'');
	
	$target_topic = array(
		'tcid' => $tcid,
		'tid' => $tid,
		'number' => $num,
		'title' => $topic->getVar('name'),
		'lang_title' => ($num>0) ? _MD_XSNS_TITLE_TOPIC_RES_DEL : _MD_XSNS_TITLE_TOPIC_DEL,
		'body' => preg_replace('/\[res\]([1-9]\\d*)\[\/res\]/', '>>\1', $comment->getVar('body', 'p')),
		'author_name' => $author_info['name'],
		'author_url' => $author_info['page_url'],
	);

	$commu = array('id' => $cid, 'name' => $community->getVar('name'));
	$message = ($num==0)? _MD_XSNS_TOPIC_DEL_CONFIRM : _MD_XSNS_TOPIC_RES_DEL_CONFIRM;
	
	$this->context->setAttribute('topic', $target_topic);
	$this->context->setAttribute('commu', $commu);
	$this->context->setAttribute('message', $message);
}
Example #11
0
	function &getListForCommunity($cid, $limit=0, $start=0, $get_body=false)
	{
		$ts =& XsnsTextSanitizer::getInstance();
		$image_handler =& XsnsImageHandler::getInstance();
		$file_handler =& XsnsFileHandler::getInstance();
		
		$ret = array();
		$base_url = XSNS_URL_TOPIC.'&tid=';
		
		$sql = "SELECT ".
				"ct.c_commu_topic_id AS tid,".
				"ct.name AS tname,".
				"MAX(ctc.r_datetime) AS max_r_datetime,".
				"ctc.c_commu_topic_comment_id AS tcid,".
				"COUNT(*) AS comment_count".
				" FROM ". $this->prefix('c_commu_topic_comment'). " ctc".
				" INNER JOIN ". $this->prefix('c_commu_topic'). " ct".
				" USING(c_commu_topic_id)".
				" WHERE ct.c_commu_id='".intval($cid)."'".
				" GROUP BY ctc.c_commu_topic_id".
				" ORDER BY max_r_datetime DESC";
		$rs = $this->db->query($sql, $limit, $start);
		if(!$rs){
			return $ret;
		}
		if($get_body){
			$comment_handler =& XsnsTopicCommentHandler::getInstance();
			
			while($row = $this->db->fetchArray($rs)){
				$comment =& $comment_handler->getByNumber($row['tid'], 0);
				
				$ret[] = array(
					'name' => $ts->makeTboxData4Show($row['tname']),
					'time' => XsnsUtils::getUserTimestamp($row['max_r_datetime']),
					'page_url' => $base_url. intval($row['tid']),
					'comment_count' => intval($row['comment_count'])-1,	// except comment No.0
					'body' => $comment->getVar('body'),
					'images' => $image_handler->getList(2, intval($row['tcid'])),
					'files' => $file_handler->getList(2, intval($row['tcid'])),
				);
				unset($comment);
			}
		}
		else{
			while($row = $this->db->fetchArray($rs)){
				$ret[] = array(
					'name' => $ts->makeTboxData4Show($row['tname']),
					'time' => XsnsUtils::getUserTimestamp($row['max_r_datetime']),
					'page_url' => $base_url. intval($row['tid']),
					'comment_count' => intval($row['comment_count'])-1,	// except comment No.0
					'body' => '',
				);
				unset($comment);
			}
		}
		return $ret;
	}
Example #12
0
function dispatch()
{
	global $xoopsUser;
	
	if($this->isGuest() || !$this->validateToken('TOPIC_EDIT')){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	$tcid = $this->getIntRequest('tcid');
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	$image_handler =& XsnsImageHandler::getInstance();
	$file_handler =& XsnsFileHandler::getInstance();
	
	// コメントの取得
	$comment =& $comment_handler->get($tcid);
	if(!is_object($comment)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$tid = $comment->getVar('c_commu_topic_id');
	
	// トピックの取得
	$topic =& $topic_handler->get($tid);
	if(!is_object($topic)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$cid = $topic->getVar('c_commu_id');
	
	// コミュニティの取得
	$community =& $commu_handler->get($topic->getVar('c_commu_id'));
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$commu_auth = $community->getAuthority();
	if($commu_auth < XSNS_AUTH_MEMBER){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$param = array(
		'number' => $comment->getNumber(),
		'name' => $this->getTextRequest('name'),
		'body' => $this->getTextRequest('body'),
	);
	
	$errors = array();
	
	$this->checkParam(&$param, &$errors);
	
	$temp_topic =& $topic_handler->create();
	$temp_topic->setVars(array(
		'name' => $param['name'],
	));
	
	$temp_comment =& $comment_handler->create();
	$temp_comment->setVar('body', $param['body']);
	
	if(count($errors) > 0){
		$topic_name = $temp_topic->getVar('name', 'e');
		$topic_vars = array(
			'id' => $tid,
			'tcid' => $tcid,
			'name' => empty($topic_name) ? $topic->getVar('name', 'e') : $topic_name,
		);
		
		$comment_body = $temp_comment->getVar('body', 'e');
		$comment_vars = array(
			'number' => $param['number'],
			'body' => empty($comment_body) ? $comment->getVar('body', 'e') : $comment_body,
			'images' => $comment->getImageList(2, XSNS_IMAGE_SIZE_S),
			'files' => $comment->getFileList(2),
		);
		
		$commu_vars = array(
			'id' => $cid,
			'name' => $community->getVar('name'),
		);
		
		$this->context->setAttribute('topic', $topic_vars);
		$this->context->setAttribute('commu', $commu_vars);
		$this->context->setAttribute('comment', $comment_vars);
		$this->context->setAttribute('errors', $errors);
		return "edit";	// → topic/editView.php
	}
	
	$topic_uid = $topic->getVar('uid');
	$comment_uid = $comment->getVar('uid');
	
	if($comment_uid > 0
	   && ($own_uid == $topic_uid || $own_uid == $comment_uid || $commu_auth >= XSNS_AUTH_SUB_ADMIN)){
		
		$r_datetime = date('Y-m-d H:i:s');
//		$r_date = date('Y-m-d');
		
		$topic->setVars(array(
			'name' => $param['name'],
		//	'r_datetime' => $r_datetime, // naao 編集時に、トピ日時を更新しない
//			'r_date' => $r_date,
		));
		
		if($topic_handler->insert($topic)){
			$tcid = $comment->getVar('c_commu_topic_comment_id');
			
			if($image_handler->uploadImageTemp('images')){
				$image_handler->uploadImage('t', 2, $tcid);
			}
			
			if($file_handler->uploadFileTemp('files')){
				$file_handler->uploadFile('t', 2, $tcid);
			}
			
			$comment->setVars(array(
				'body' => $param['body'],
				'number' => $param['number'],
		//		'r_datetime' => $r_datetime, // naao 編集時に、トピ日時を更新しない
//				'r_date' => $r_date,
			));
			
			if($comment_handler->insert($comment)){
				$msg = ($param['number']==0)? _MD_XSNS_TOPIC_EDIT_OK : _MD_XSNS_TOPIC_EDIT_RES_OK;
			}
			else{
				$msg = ($param['number']==0)? _MD_XSNS_TOPIC_EDIT_NG : _MD_XSNS_TOPIC_EDIT_RES_NG;
			}
		}
		else{
			$msg = _MD_XSNS_TOPIC_EDIT_NG;
		}
		redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, $msg);
	}
	redirect_header(XOOPS_URL, 2, _NOPERM);
}
Example #13
0
function checkPermission($target, $target_id)
{
	global $xoopsUserIsAdmin;
	if($xoopsUserIsAdmin){
		return true;
	}
	
	include_once dirname(__FILE__).'/config.php';
	include_once XSNS_USERLIB_DIR.'/config.php';
	include_once XSNS_USERLIB_DIR.'/loader.php';
	
	$commu_handler = XsnsCommunityHandler::getInstance();
	$comment_handler = XsnsTopicCommentHandler::getInstance();
	
	if($target==1){
		$commu_id = $target_id;
	}
	elseif($target==2){
		$comment = $comment_handler->get($target_id);
		if(!is_object($comment)){
			return false;
		}
		$commu_id = $comment->getVar('c_commu_id');
	}
	else{
		return false;
	}
	
	$community = $commu_handler->get($commu_id);
	if(!is_object($community)
	  || ($community->getVar('public_flag')==3 && $community->getAuthority() < XSNS_AUTH_MEMBER)){
		return false;
	}
	return true;
}
Example #14
0
function getCommunityDetail($cid)
{
	global $xoopsUser;
	$topic_limit = 10;
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$c_member_handler =& XsnsMemberHandler::getInstance();
	$user_handler =& XsnsUserHandler::getInstance();
	$image_handler =& XsnsImageHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	
	// コミュニティの取得
	$community =& $commu_handler->get($cid);
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$community->setStatistics();
	
	// コミュニティメンバー一覧の取得
	$c_member_obj_list =& $community->getMemberObjects(9, 0, true);
	$c_member_list = array();
	foreach($c_member_obj_list as $c_member_obj){
		$c_member_list[] =& $c_member_obj->getInfo();
	}
	
	$c_member_count = count($c_member_obj_list);
	if($c_member_count < 9){
		for($i=0; $i<9-$c_member_count; $i++){
			$c_member_list[] = array();
		}
	}
	
	$uid_admin = $community->getVar('uid_admin');
	$own_uid = ($this->isXoopsUser()) ? $xoopsUser->getVar('uid') : 0;
	
	if($c_member_handler->getOne($cid, $own_uid)){
		$is_member = true;
		$is_admin = ($own_uid == $uid_admin)? true : false;
	}
	else{
		$is_member = $is_admin = false;
	}
	
	$commu_auth = $community->getAuthority();
	$public_flag = $community->getVar('public_flag');
	
	$admin_obj =& $user_handler->get($uid_admin);
	$admin_name = is_object($admin_obj) ? $admin_obj->getVar('uname') : "";
	
	$public_flag_desc = array(
		1 => _MD_XSNS_INDEX_DETAIL_PUBLIC_L1,
		2 => _MD_XSNS_INDEX_DETAIL_PUBLIC_L2,
		3 => _MD_XSNS_INDEX_DETAIL_PUBLIC_L3,
	);
	
	$ret = array(
		'id' => $cid,
		'name' => $community->getVar('name'),
		'info' => $community->getVar('info'),
		'time' => $community->getVar('r_datetime'),
		'image' => $community->getImage(XSNS_IMAGE_SIZE_L),
		'category' => $community->getCategoryName(),
		'public' => $public_flag_desc[$public_flag],
		'admin_name' => $admin_name,
		'admin_url' => XSNS_URL_MYPAGE.'&uid='.$uid_admin,
		'statistics' => $community->getStatistics(),
		'member_list' => $c_member_list,
		'member_count' => $community->getMemberCount(),
		'topic_list' => $community->getTopicList($topic_limit),
		'topic_count' => $community->getTopicCount(),
		
		'show_commu_join' => (!$is_member && $commu_auth > XSNS_AUTH_GUEST) ? true : false,
		'show_commu_leave' => ($is_member && !$is_admin) ? true : false,
		'show_commu_notify' => ($is_member) ? true : false,
		'show_commu_config' => ($commu_auth >= XSNS_AUTH_ADMIN) ? true : false,
		'show_topic_list' => ($public_flag!=3 || $commu_auth>=XSNS_AUTH_MEMBER) ? true : false,
		'show_topic_add' => ($commu_auth >= XSNS_AUTH_MEMBER) ? true : false,
		'show_send_message' => ($commu_auth >= XSNS_AUTH_MEMBER) ? true : false,
		'show_member_config' => ($commu_auth >= XSNS_AUTH_ADMIN) ? true : false,
	);
	return $ret;
}
Example #15
0
function dispatch()
{
	global $xoopsUser;
	
	if($this->isGuest() || !$this->validateToken('TOPIC_COMMENT_ADD')){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	$tid = $this->getIntRequest('tid');
	if(!isset($tid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$body = $this->getTextRequest('comment_body', XSNS_REQUEST_SESSION);
	if(!isset($body)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	
	// トピックの取得
	$topic =& $topic_handler->get($tid);
	if(!is_object($topic) || $topic->getCommentCount() >= 1001){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	// コミュニティの取得
	$cid = $topic->getVar('c_commu_id');
	$community =& $commu_handler->get($cid);
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$commu_auth = $community->getAuthority();
	if($commu_auth < XSNS_AUTH_NON_MEMBER
	   || ($commu_auth < XSNS_AUTH_MEMBER && $community->getVar('public_flag')==3) ){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	// コメントの投稿
	$new_comment =& $comment_handler->create();
	$new_comment->setVars(array(
		'c_commu_topic_id' => $tid,
		'c_commu_id' => $cid,
		'uid' => $own_uid,
		'body' => $body,
		'r_datetime' => date('Y-m-d H:i:s'),
		'r_date' => date('Y-m-d'),
		'number' => $topic->getCommentCount(),
	));
	
	if($tcid = $comment_handler->insert($new_comment)){
		
		// 画像のアップロード
		$image_handler =& XsnsImageHandler::getInstance();
		$image_handler->uploadImage('t', 2, $tcid);
		
		// ファイルのアップロード
		$file_handler =& XsnsFileHandler::getInstance();
		$file_handler->uploadFile('t', 2, $tcid);
		
		// イベント通知
		if(include_once(XSNS_TRUST_PATH.'/include/notification.php')){
			$tags = array(
				'COMMU_NAME' => $community->getVar('name'),
				'TOPIC_NAME' => $topic->getVar('name'),
				'TOPIC_BODY' => $new_comment->getVar('body', 'e'),	// disallow HTML
				'AUTHOR_NAME' => $xoopsUser->getVar('uname'),
				'TOPIC_URI' => XSNS_URL_TOPIC.'&tid='.$tid,
			);
			// コミュニティメンバー以外には送信しない
			$c_member_obj_list =& $community->getMemberObjects();
			$c_member_ids = array();
			foreach($c_member_obj_list as $c_member_obj){
				$c_member_ids[] = $c_member_obj->getVar('uid');
			}
			xsns_main_trigger_event('topic', $cid, 'post', $tags, $c_member_ids);
		}
		
		$xoopsUser->incrementPost();
		$sess_handler =& XsnsSessionHandler::getInstance();
		$sess_handler->clearVars();
		
		redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_ADD_RES_OK);
	}
	
	redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_ADD_RES_NG);
}
Example #16
0
function dispatch()
{
	global $xoopsUser;
	if($this->isGuest() || !$this->validateToken('TOPIC_DELETE')){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$own_uid = $xoopsUser->getVar('uid');
	
	$tcid = $this->getIntRequest('tcid');
	if(!isset($tcid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	
	// コメントの取得
	$comment =& $comment_handler->get($tcid);
	if(!is_object($comment)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$tid = $comment->getVar('c_commu_topic_id');
	$num = $comment->getNumber();
	
	// トピックの取得
	$topic =& $topic_handler->get($tid);
	if(!is_object($topic)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$topic_uid = $topic->getVar('uid');
	
	// コミュニティの取得
	$cid = $topic->getVar('c_commu_id');
	$community =& $commu_handler->get($cid);
	if(!is_object($community)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	$commu_auth = $community->getAuthority();
	if($commu_auth < XSNS_AUTH_MEMBER){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$comment_uid = $comment->getVar('uid');
	if($comment_uid < 1 || ($commu_auth < XSNS_AUTH_SUB_ADMIN && $own_uid != $comment_uid && $own_uid != $topic_uid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	if($num > 0){
		// コメントの削除 ・・・ 投稿者・本文データのみ削除する
		$comment->setVar('uid', 0);
		$comment->setVar('body', '');
		
		if($comment_handler->insert($comment)){
			// コメントに添付された画像・ファイルを削除
			$criteria = new CriteriaCompo(new Criteria('target', 2));
			$criteria->add(new Criteria('target_id', $tcid));
			$image_handler =& XsnsImageHandler::getInstance();
			$image_handler->deleteObjects($criteria);
			$file_handler =& XsnsFileHandler::getInstance();
			$file_handler->deleteObjects($criteria);
			
			redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_DEL_RES_OK);
		}
		redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_DEL_RES_NG);
	}
	else{
		// トピックの削除 ・・・ トピックおよびコメントを完全に削除する
		if($topic->deleteCommentsAll() && $topic_handler->delete($topic)){
			redirect_header(XSNS_URL_COMMU.'?cid='.$cid, 2, _MD_XSNS_TOPIC_DEL_OK);
		}
		redirect_header(XSNS_URL_TOPIC.'&tid='.$tid, 2, _MD_XSNS_TOPIC_DEL_NG);
	}
}
Example #17
0
function dispatch()
{
	if($this->isGuest()){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}

	require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
	$token_handler = new XoopsMultiTokenHandler();
	$token = new XoopsFormToken($token_handler->create('TOPIC_ADD'));
	// Hidden
	$token_tag = '<input type="hidden" name="'.$token->_name.'" value="'.$token->_value.'">';
	$this->context->setAttribute('token_tag', $token_tag);
	
	$cid = $this->getIntRequest('cid');
	if(!isset($cid)){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$commu_handler =& XsnsCommunityHandler::getInstance();
	$topic_handler =& XsnsTopicHandler::getInstance();
	$comment_handler =& XsnsTopicCommentHandler::getInstance();
	$sess_handler =& XsnsSessionHandler::getInstance();
	$image_handler =& XsnsImageHandler::getInstance();
	$file_handler =& XsnsFileHandler::getInstance();
	
	// コミュニティの取得
	$community =& $commu_handler->get($cid);
	if(!is_object($community) || !$community->checkAuthority()){
		redirect_header(XOOPS_URL, 2, _NOPERM);
	}
	
	$param = array(
		'number' => 0,
		'name' => $this->getTextRequest('name'),
		'body' => $this->getTextRequest('body'),
	);
	
	$errors = array();
	
	$this->checkParam(&$param, &$errors);
	
	$new_topic =& $topic_handler->create();
	$new_topic->setVar('name', $param['name']);
	
	$new_comment =& $comment_handler->create();
	$new_comment->setVar('body', $param['body']);
	
	$commu_vars = array('id' => $cid, 'name' => $community->getVar('name'));
	
	// 入力エラー
	if(count($errors) > 0){
		$default = array(
			'name' => $new_topic->getVar('name', 'f'),
			'body' => $new_comment->getVar('body', 'f'),
		);
		$this->context->setAttribute('commu', $commu_vars);
		$this->context->setAttribute('default', $default);
		$this->context->setAttribute('errors', $errors);
		
		return "add";	// → topic/addView.php
	}
	
	$topic_vars_temp = array(
		'name' => $param['name'],
		'body' => $param['body'],
	);
	$sess_handler->setVar('topic', $topic_vars_temp);
	
	$topic_vars = array(
		'name' => $new_topic->getVar('name', 'p'),
		'body' => $new_comment->getVar('body', 'p'),
		'images' => $image_handler->uploadImageTemp('images'),
		'files' => $file_handler->uploadFileTemp('files'),
	);
	$this->context->setAttribute('topic', $topic_vars);
	$this->context->setAttribute('commu', $commu_vars);
}