示例#1
0
	function xsns_new_base( $mydirname, $limit=0, $offset=0 ) 
	{
		if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid mydirname' ) ;
		$constpref = '_MB_' . strtoupper( $mydirname ) ;

		$URL_MOD = XOOPS_URL."/modules/".$mydirname;

		$mytrustdirpath = dirname(dirname( __FILE__ )) ;

		$db =& Database::getInstance();
		$myts =& MyTextSanitizer::getInstance();

		$block = array();
		$perm_arr = array();
	
		$own_uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : -1;
	
		// naao from
		//各トピの最新コメントIDを取得
		$sql = "SELECT c_commu_topic_id AS tid, MAX(c_commu_topic_comment_id) AS com_id FROM ". $db->prefix($mydirname.'_c_commu_topic_comment')." GROUP BY tid;";

		$result = $db->query($sql);
		if(!$result || $db->getRowsNum($result) < 1){
			return array();
		}
	
		while ( $dbdat = $db->fetchArray($result)){
			$com_num[] = intval($dbdat['com_id']);
		}

 	 	$whr_num = "tc.c_commu_topic_comment_id IN (" .implode( "," , $com_num ). ") ";

		// topic search
		$sql = "SELECT ".
			"c.c_commu_id AS cid,".
			"c.name AS cname,".
			"c.uid_admin AS cadmin,".
			"c.uid_sub_admin AS csubadmin,".
			"c.public_flag AS cflag,".
			"t.c_commu_topic_id AS tid,".
			"t.name AS tname,".
			"tc.body AS tcbody,".
			"tc.uid AS tcuid,".
			"tc.number AS comment_count,".
			"tc.r_datetime AS r_datetime,".
			"tc.c_commu_topic_comment_id ".
			" FROM (". $db->prefix($mydirname.'_c_commu'). " c".
			" INNER JOIN ". $db->prefix($mydirname.'_c_commu_topic_comment'). " tc".
			" USING(c_commu_id))".
			" INNER JOIN ". $db->prefix($mydirname.'_c_commu_topic'). " t".
			" USING(c_commu_topic_id)".
			" WHERE ".$whr_num.
			" ORDER BY r_datetime DESC";
		// naao to
	
		$rs = $db->query($sql);
		if(!$rs || $db->getRowsNum($rs) < 1){
			return array();
		}
	
		$today = date('Y-m-d');
		$i = 0;
		require_once dirname(dirname(__FILE__)).'/userlib/utils.php';
	
		$ret	= array();
		while($row = $db->fetchArray($rs)) {
		
			if($limit <= $i){
				break;
			}
		
			// check community permission
			if($row['cflag']==3 && !$xoopsUserIsAdmin && $row['cadmin']!=$own_uid && $row['csubadmin']!=$own_uid){
				if($own_uid < 0){
					continue;
				}
				$cid = intval($row['cid']);
				if(!isset($perm_arr[$cid])){
					$perm_arr[$cid] = xsns_is_community_member($mydirname, $cid, $own_uid);
				}
				if(!$perm_arr[$cid]){
					continue;
				}
			}
		
			$r_time = strtotime($row['r_datetime']);
			$comment_index = intval(intval($row['comment_count'])/20)*20;	//naao
			
				$ret[$i]['description']	= trim( $myts->htmlSpecialChars($row['tcbody']));
				$ret[$i]['link']	= XOOPS_URL.'/modules/'.$mydirname.'/?p=topic&tid='.intval($row['tid']).'&s='.$comment_index.'#'.intval($row['comment_count']);
				$ret[$i]['cname'] 	=  $myts->htmlSpecialChars($row['cname']);
				$ret[$i]['cat_link'] 	= XOOPS_URL.'/modules/'.$mydirname.'/?cid='.intval($row['cid']);
				$ret[$i]['title']    	= $myts->htmlSpecialChars($row['tname']);
				$ret[$i]['time']	= $r_time;
				$ret[$i]['uid']  	= intval($row['tcuid']);
			//	$ret[$i]['hits'] 	= $row['view'];
				$ret[$i]['replies'] 	= intval($row['comment_count']) ;
			//	$ret[$i]['image']	= !empty($row['photo']) ? $URL_MOD."/upimg/".$row['photo'] : "";
				$ret[$i]['id']   	= intval($row['tid']);
				$i++;
		}

		return $ret;
	}
示例#2
0
function b_xsns_recent_topic_show($options)
{
	global $xoopsUser, $xoopsUserIsAdmin;
	
	require_once dirname(dirname(__FILE__)).'/include/common_functions.php';
	
	$db =& Database::getInstance();
	$myts =& MyTextSanitizer::getInstance();
	
	$mydirname = empty($options[0]) ? 'xsns' : $options[0];
	$item_limit = empty($options[1]) ? 5 : intval($options[1]);
	
	if( preg_match( '/[^0-9a-zA-Z_-]/' , $mydirname ) ) die( 'Invalid dirname' ) ;
	
	$constpref = '_MB_'.strtoupper($mydirname);
	
	$block = array();
	$perm_arr = array();
	
	$own_uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : -1;
	
	// naao from
	//各トピの最新コメントIDを取得
	$sql = "SELECT c_commu_topic_id AS tid, MAX(c_commu_topic_comment_id) AS com_id FROM ". $db->prefix($mydirname.'_c_commu_topic_comment')." GROUP BY tid;";

	$result = $db->query($sql);
	if(!$result || $db->getRowsNum($result) < 1){
		return array();
	}
	
	while ( $dbdat = $db->fetchArray($result)){
		$com_num[] = intval($dbdat['com_id']);
	}

  	$whr_num = "tc.c_commu_topic_comment_id IN (" .implode( "," , $com_num ). ") ";

	// topic search
	$sql = "SELECT ".
			"c.c_commu_id AS cid,".
			"c.name AS cname,".
			"c.uid_admin AS cadmin,".
			"c.uid_sub_admin AS csubadmin,".
			"c.public_flag AS cflag,".
			"t.c_commu_topic_id AS tid,".
			"t.name AS tname,".
			"tc.body AS tcbody,".
			"tc.uid AS tcuid,".
			"tc.number AS comment_count,".
			"tc.r_datetime AS r_datetime,".
			"tc.c_commu_topic_comment_id ".
			" FROM (". $db->prefix($mydirname.'_c_commu'). " c".
			" INNER JOIN ". $db->prefix($mydirname.'_c_commu_topic_comment'). " tc".
			" USING(c_commu_id))".
			" INNER JOIN ". $db->prefix($mydirname.'_c_commu_topic'). " t".
			" USING(c_commu_topic_id)".
			" WHERE ".$whr_num.
			" ORDER BY r_datetime DESC";
	// naao to
	
	$rs = $db->query($sql);
	if(!$rs || $db->getRowsNum($rs) < 1){
		return array();
	}
	
	$today = date('Y-m-d');
	$item_count = 0;
	require_once dirname(dirname(__FILE__)).'/userlib/utils.php';
	
	while($row = $db->fetchArray($rs)) {
		
		if($item_limit <= $item_count){
			break;
		}
		
		// check community permission
		if($row['cflag']==3 && !$xoopsUserIsAdmin && $row['cadmin']!=$own_uid && $row['csubadmin']!=$own_uid){
			if($own_uid < 0){
				continue;
			}
			$cid = intval($row['cid']);
			if(!isset($perm_arr[$cid])){
				$perm_arr[$cid] = xsns_is_community_member($mydirname, $cid, $own_uid);
			}
			if(!$perm_arr[$cid]){
				continue;
			}
		}
		
		//$date_arr = explode(' ', XsnsUtils::getUserDatetime($row['max_r_datetime']), 2);
		$date_arr = explode(' ', XsnsUtils::getUserDatetime($row['r_datetime']), 2);	//naao
		if(!is_array($date_arr)){
			continue;
		}
		if($today==$date_arr[0]){
			$r_time_arr = explode(':', $date_arr[1], 3);
			if(!is_array($r_time_arr)){
				continue;
			}
			$r_time = $r_time_arr[0].':'.$r_time_arr[1];
		}
		else{
			$r_time_arr = explode('-', $date_arr[0], 3);
			if(!is_array($r_time_arr)){
				continue;
			}
			$r_time = $r_time_arr[1]. constant($constpref.'_MONTH'). $r_time_arr[2]. constant($constpref.'_DAY');
		}
		
			$comment_index = intval(intval($row['comment_count'])/20)*20;	//naao
			
		$block['topic_list'][] = array(
			'link' => XOOPS_URL.'/modules/'.$mydirname.'/?p=topic&tid='.intval($row['tid']).'&s='.$comment_index.'#'.intval($row['comment_count']),	//naao
			'title' => $myts->htmlSpecialChars($row['tname']),
			'body' => $myts->htmlSpecialChars($row['tcbody']),
			'comment_count' => intval($row['comment_count']),
			'datetime' => $r_time,
		//	'time' => XsnsUtils::getUserTimestamp($row['max_r_datetime']),	//naao
			'time' => XsnsUtils::getUserTimestamp($row['r_datetime']),	//naao
			'uid' => intval($row['tcuid']),
			'community' => array(
				'link' => XOOPS_URL.'/modules/'.$mydirname.'/?cid='.intval($row['cid']),
				'title' => $myts->htmlSpecialChars($row['cname']),
			),
		);
		
		$item_count++;
	}
	
	if(empty($options['disable_renderer'])){
		require_once XOOPS_ROOT_PATH.'/class/template.php' ;
		$tpl = new XoopsTpl();
		$tpl->assign('block', $block);
		$ret['content'] = $tpl->fetch('db:'.$mydirname.'_block_recent_topic.html');
		return $ret;
	}
	else{
		return $block;
	}
}
示例#3
0
function xsns_search($mydirname, $queryarray, $andor, $limit, $offset, $userid)
{
	global $xoopsDB, $xoopsUser, $xoopsUserIsAdmin, $xoopsConfig;
	
	$lang_file = dirname(__FILE__).'/language/'.$xoopsConfig['language'].'/main.php';
	if(file_exists($lang_file)){
		require_once $lang_file;
	}
	
	require_once dirname(__FILE__).'/include/common_functions.php';
	
	$temp_arr = array();
	$datetime_arr = array();
	$perm_arr = array();
	$ret = array();
	
	$myts =& MyTextSanitizer::getInstance();
	$own_uid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : -1;
	
	$count = is_array($queryarray) ? count($queryarray) : 0;
	
	// community search
	$where_sql = "";
	$uid_sql = empty($userid) ? "" : "uid_admin=".intval($userid);
	
	$sql = "SELECT * FROM ".$xoopsDB->prefix($mydirname.'_c_commu');
	if($count > 0){
		$kw_sql = "LIKE '%$queryarray[0]%'";
		$where_sql = " WHERE ((name $kw_sql OR info $kw_sql)";
		for($i=1; $i<$count; $i++){
			$kw_sql = "LIKE '%$queryarray[$i]%'";
			$where_sql .= " $andor (name $kw_sql OR info $kw_sql)";
		}
		$where_sql .= ")";
	}
	
	if(!empty($uid_sql)){
		if(!empty($where_sql)){
			$where_sql = $where_sql." AND ".$uid_sql;
		}
		else{
			$where_sql = " WHERE ".$uid_sql;
		}
	}
	$sql .= $where_sql. " ORDER BY r_datetime DESC";
	$rs = $xoopsDB->query($sql, $limit, $offset);
	
	$n = 0;
	
	while($row = $xoopsDB->fetchArray($rs)) {
		$temp_arr[$n] = array(
			'image' => '',
			'link' => '?cid='.intval($row['c_commu_id']),
			'title' => "["._MD_XSNS_COMMU."] ".$myts->htmlSpecialChars($row['name']),
			'time' => strtotime($row['r_datetime']),
			'uid' => intval($row['uid_admin']),
		);
		$datetime_arr[$n++] = strtotime($row['r_datetime']);
	}
	
	// topic search
	$where_sql = "";
	$uid_sql = empty($userid) ? "" : "tc.uid=".intval($userid);
	
	$sql = "SELECT ".
			"c.c_commu_id AS cid,".
			"c.uid_admin AS cadmin,".
			"c.uid_sub_admin AS csubadmin,".
			"c.public_flag AS cflag,".
			"t.c_commu_topic_id AS tid,".
			"t.name AS tname,".
			"tc.body AS tcbody,".
			"tc.uid AS tcuid,".
			"MAX(tc.r_datetime) AS max_r_datetime".
			" FROM (". $xoopsDB->prefix($mydirname.'_c_commu'). " c".
			" INNER JOIN ". $xoopsDB->prefix($mydirname.'_c_commu_topic_comment'). " tc".
			" USING(c_commu_id))".
			" INNER JOIN ". $xoopsDB->prefix($mydirname.'_c_commu_topic'). " t".
			" USING(c_commu_topic_id)";
	
	if($count > 0){
		$kw_sql = "LIKE '%$queryarray[0]%'";
		$where_sql = " WHERE ((t.name $kw_sql OR tc.body $kw_sql)";
		for($i=1; $i<$count; $i++){
			$kw_sql = "LIKE '%$queryarray[$i]%'";
			$where_sql .= " $andor (t.name $kw_sql OR tc.body $kw_sql)";
		}
		$where_sql .= ")";
	}
	
	if(!empty($uid_sql)){
		if(!empty($where_sql)){
			$where_sql = $where_sql." AND ".$uid_sql;
		}
		else{
			$where_sql = " WHERE ".$uid_sql;
		}
	}
	$sql .= $where_sql. " GROUP BY tid ORDER BY max_r_datetime DESC";
	$rs = $xoopsDB->query($sql, $limit, $offset);
	
	while($row = $xoopsDB->fetchArray($rs)) {
		// check community permission
		if($row['cflag']==3 && !$xoopsUserIsAdmin && $row['cadmin']!=$own_uid && $row['csubadmin']!=$own_uid){
			if($own_uid < 0){
				continue;
			}
			$cid = intval($row['cid']);
			if(!isset($perm_arr[$cid])){
				$perm_arr[$cid] = xsns_is_community_member($mydirname, $cid, $own_uid);
			}
			if(!$perm_arr[$cid]){
				continue;
			}
		}
		
		$temp_arr[$n] = array(
			'image' => '',
			'link' => '?p=topic&tid='.intval($row['tid']),
			'title' => "["._MD_XSNS_TOPIC."] ".$myts->htmlSpecialChars($row['tname']),
			'time' => strtotime($row['max_r_datetime']),
			'uid' => intval($row['tcuid']),
		);
		$datetime_arr[$n++] = strtotime($row['max_r_datetime']);
	}
	
	arsort($datetime_arr);
	
	$n = 0;
	foreach($datetime_arr as $id => $value){
		$ret[] =& $temp_arr[$id];
		if($limit==++$n){
			break;
		}
	}
	return $ret;
}