<?php
/*
 BMForum Forum Systems
 
 This is a freeware, but don't change the copyright information.
 A SourceForge Project.
 Web Site: http://www.bmforum.com
 Copyright (C) Bluview Technology
*/
function process_attach($showdes, $exts, $ias, $filename, $lineid, $read_post, $showdesa, $showdesb, $showdtim, $checkattachpic, $somepostinfo, $bcode_post, $loaded)
{
	$exts = basename($exts);
	if (file_exists("include/attachext/". $exts .".php")) {
		@include("include/attachext/". $exts .".php");
	} else {
		if ($loaded != 1) $pro_results = "<a target='_blank' href='attachment.php?am=$ias&amp;filename=$filename&amp;article={$lineid}'><img border='0' src='images/attach/attach.gif' alt='' /> $read_post[26] $showdesa$showdesb $showdtim</a><br />";
	}
	
	return $pro_results;
}
function fast_reply ()
{
	global $emot_every, $DISABLEDAJAX, $usertype, $reply_post, $bgcolor, $allow_ajax_reply, $html_codeinfo, $login_status, $username, $max_upload_size, $max_daily_upload_size, $uploadfiletoday, $min_post_length, $max_post_length, $emot_lines, $max_upload_post, $allow_upload, $upload_type_available, $forum_pos;

    $html_codeinfo = $usertype[26];

    // ------ Emoticons -------
    if (file_exists("datafile/emoticon.php")) {
        $emotfile = "datafile/emoticon.php";
        $emotfiledata = file($emotfile);
    } 

    if ($DISABLEDAJAX == 1) $allow_ajax_reply = 0;
    
    $count = count($emotfiledata) + 1;
    $emot_max = $emot_lines * $emot_every + 1;
    if ($count > $emot_max) $count = $emot_max;
    
    for ($i = 1;$i < $count;$i++) {
        $ci = $i-1;
        $br = "";
        $emotfd = explode("＊＊", $emotfiledata[$ci]);
        if ($emotfd[2] == 1) $emotfd[1] = "thumb/$emotfd[1]";
        if ((floor($i / $emot_every) * $emot_every) == $i) $br = "<br />";
        $wemotinfoshow .= "<img onclick=\"javascript:AddText('$emotfd[0]');\" src=\"images/face/$emotfd[1]\" alt='' />$br";
    } 
    
    if ($allow_upload) {
        $available_ext = explode(' ', $upload_type_available);
        $extcount = count($available_ext);
        $showtype = "<select><option value=''>$forum_pos[18]</option><option value=''>---------</option>";
        for ($i = 0; $i < $extcount; $i++) {
            $showtype .= "<option value=''>$available_ext[$i]</option>";
        } 
        $showtype .= "</select>";
        $showuploads = "<input size=\"55\" onchange=\"javascript:check_file_ext(this,$extcount);\" type=\"file\" name=\"attachment[]\" id=\"upload_filename\" /> $showtype";
        $uploadinfoshow = ' ' . $forum_pos[19] . '</strong><br />' . $forum_pos[20] . $max_upload_size . $forum_pos[21] . '</font><br />' . $forum_pos[22] . $max_upload_post . $forum_pos[23] . '</font><br />';
    } 
    else $uploadinfoshow = "<input type=\"hidden\" value=\"\" name=\"attachment[]\" id=\"upload_filename\" /> $forum_pos[6]</strong>";

    $leftuploadnum = $max_daily_upload_size - $uploadfiletoday;
    if ($html_codeinfo != "yes") {
        $htmlcodeinfo = "<input type='checkbox' name='' disabled='disabled' value='checkbox' id='closedhtml' /><label for='closedhtml'><strong>$forum_pos[24]</strong></label><br />";
    } else {
        $htmlcodeinfo = '<input type="checkbox" name="openhtmlcode" value="checkbox" id="open_1" /><label for="open_1">' . $forum_pos[6] . '<strong>HTML Code</strong></label><br />';
    } 

    if ($bgcolor == "article_color1") $dbgcolor = "article_color2";
    else $dbgcolor = "article_color1";
    
    if (file_exists("datafile/actinfo.php")) {
        $filedata = file("datafile/actinfo.php");
        $count = count($filedata);
        for ($i = 0;$i < $count;$i++) {
            list($act, $actinfo) = explode("|", $filedata[$i]);
            $acta = str_replace("/", "", $act);
            $actshows .= "<option value='$act'>$acta</option>";
        } 
    } 
    if ($login_status == 0) { // 开关
        $addinfoone = '<br />' . $forum_pos[25] . '<input maxlength="25" size="15" tabindex="1" name="username" /><br />' . $forum_pos[26] . '<input maxlength="25" size="15" name="password" tabindex="2" type="password" />';
    } 
	$reply_post = array("allow_ajax_reply" => $allow_ajax_reply, "wemotinfoshow" => $wemotinfoshow, "showinfoofforum" => $showinfoofforum, "min_post_length" => $min_post_length, "max_post_length" => $max_post_length, "dbgcolor" => $dbgcolor, "htmlcodeinfo" => $htmlcodeinfo, "codeinfoc" => $codeinfoc, "uploadinfoshow" => $uploadinfoshow, "leftuploadnum" => $leftuploadnum, "actshows" => $actshows, "showuploads" => $showuploads, "addinfoone" => $addinfoone);
}
function text_watermark($contentconverted) 
{
	global $script_pos, $bbs_title;
	
	$text_wm['tmp']		=	explode("<br />", $contentconverted);
	$text_wm['count']	=	count($text_wm['tmp']);
	for ($i = 0; $i < $text_wm['count']; $i++) {
		if ($i%3==0)
		$text_wm['tmp'][$i].= "<div style='display:none;'>[url=$script_pos]".getCode()."$bbs_title".getCode()."[/url]</div>";
	}
	
	$text_wm['tmp'] = implode("<br />", $text_wm['tmp']);
	
	return $text_wm['tmp'];
}
function similar_threads($tid, $ttag_ex, $is_article = 0)
{
	global $database_up, $bmfopt, $sthread_list, $usertype, $login_status, $forum_admin, $detail, $forumscount, $sxfourmrow, $username;
	
	$max_similar_tags = $bmfopt["tags_max_similar"];
	
	$c_tags = count($ttag_ex);
	if ($c_tags > 0 && $max_similar_tags > 0) {
		
		for ($i = 0; $i < $c_tags; $i++){
			$ttags_name .= $ttags_name ? ",'$ttag_ex[$i]'" : "'$ttag_ex[$i]'";
		}
		
		$tags_real_count = 0;
		
	    $result = bmbdb_query("SELECT * FROM {$database_up}tags WHERE tagname in($ttags_name)");
	    while (false !== ($tag_row = bmbdb_fetch_array($result))) {
	    	$this_tags = substr($tag_row['filename'], 1);
	    	$tags_detail = explode(",", $this_tags);
	    	$count_tags	 = count($tags_detail);
	    	for ($ti = 0;$ti < $count_tags; $ti++){
	    		if (!@in_array($tags_detail[$ti], $tags_array) && $tags_detail[$ti] != $tid && $tags_detail[$ti]) {
	    			$tags_real_count++;
		    		$tags_array[]=$tags_detail[$ti];
		    		$th_tags .= $th_tags ? ",".$tags_detail[$ti] : $tags_detail[$ti]; 
		    	}
	    	}
	    	
	    }
	    
	    $limit_similar_tags = min($tags_real_count, $max_similar_tags);
	    
	    if ($limit_similar_tags < 1) return;

		
	    for($i = 0;$i < $forumscount;$i++) {
	        if (!(!check_forum_permission(0, 1, $sxfourmrow[$i])) && $sxfourmrow[$i][type] != "category" && check_permission($username, $sxfourmrow[$i][type]) && !$sxfourmrow[$i][forumpass] && $sxfourmrow[$i][forumpass] <> "d41d8cd98f00b204e9800998ecf8427e") {
	            $forumnum["{$sxfourmrow[$i][id]}"] = $sxfourmrow[$i][bbsname];
	        } else {
	            if ($sxfourmrow[$i][type] != "category" && $countbyself != 1) $countbyself = 1;
	            $add_sql .= $add_sql ? ",'{$sxfourmrow[$i][id]}'" : "'{$sxfourmrow[$i][id]}'";
	        } 
	    } 
	    if ($add_sql != "") $add_sql = "AND forumid not in($add_sql)";

		$result = bmbdb_query("SELECT * FROM {$database_up}threads WHERE tid in ($th_tags) AND `tid`!= $tid $add_sql ORDER BY `changetime` DESC LIMIT 0,$limit_similar_tags");
		while (false !== ($line = bmbdb_fetch_array($result))) {
			$tmp_forumid	= $line['forumid'];
			$urlauthor	= $line["author"];
			
		    $lmd	=	explode(",", $line['lastreply']);
		    $time_tmp	=	getfulldate($lmd[2]);
		    if ($time_2) {
		        $timetmp_a	=	$timestamp - $lmd[2];
		        $lmdtime	=	get_add_date($timetmp_a);
		        if ($lmdtime == "getfulldate") {
		            $lmdtime	=	$time_tmp;
		        } 
		    } else {
		        $lmdtime	=	$time_tmp;
		    } 
		    
		    if ($is_article == 1) {
		    	$tagstothread = "article.php?filename={$line['id']}";
		    } else $tagstothread = $bmfopt['rewrite'] ? "topic_{$line['id']}" :"topic.php?filename={$line['id']}";
		    $tagstoforums = $bmfopt['rewrite'] ? "forums_{$tmp_forumid}" :"forums.php?forumid=$tmp_forumid";
			
			$sthread_list[]= array("tagstoforums" => $tagstoforums, "tagstothread" => $tagstothread, "timetoshow" => $lmdtime, "tag_forumid" => $tmp_forumid, "hit" => $line['hits'], "reply" => $line['replys'], "urlauthor" => $urlauthor, "viewauthor" => $line["author"], "forum_name" => $forumnum["$tmp_forumid"], "tag_filename" => $line['id'], "title" => stripslashes($line['title']));
		}
		
	}
}