functions.php

来自「功能介绍: 1、主要功能」· PHP 代码 · 共 517 行 · 第 1/2 页

PHP
517
字号
// ###################### Start maketextareacode #######################
function maketextareacode ($title,$name,$value="",$rows=4,$cols=40,$htmlise=1) {
// similar to makeinputcode, only for a text area

  if ($htmlise) {
    $value=htmlspecialchars($value);
  }
  echo "<tr class='".getrowbg()."' valign='top'>\n<td><p>$title</p></td>\n<td><p><textarea name=\"$name\" rows=\"$rows\" cols=\"$cols\">$value</textarea></p></td>\n</tr>\n";
}

// ###################### Start doformheader #######################
function doformheader ($phpscript,$action,$uploadform=0,$addtable=1,$name="name") {
// makes the standard form header, setting sctript to call and action to do
  global $session,$tableadded;

  echo "<form action=\"$phpscript.php\" ".iif($uploadform,"ENCTYPE=\"multipart/form-data\" ","")." name=\"$name\" method=\"post\">\n<input type=\"hidden\" name=\"s\" value=\"$session[sessionhash]\"><input type=\"hidden\" name=\"action\" value=\"$action\">\n";

  if ($addtable==1) {
  	$tableadded = 1;
    echo "<br><table cellpadding='1' cellspacing='0' border='0' align='center' width='90%' class='tblborder'><tr><td>\n";
  	echo "<table cellpadding='4' cellspacing='0' border='0' width='100%'>\n";
  } else {
  	$tableadded = 0;
  }
}

// ###################### Start doformfooter #######################
function doformfooter($submitname="提交",$resetname="重置",$colspan=2,$goback="") {
// closes the standard form table and makes a new one containing centred submit and reset buttons
  global $tableadded;

  echo iif($tableadded==1,"<tr id='submitrow'>\n<td colspan='$colspan' align='center'>","<p><center>");
  echo "<p id='submitrow'><input type=\"submit\" value=\"   $submitname   \" accesskey=\"s\">\n";
  if ($resetname!="") {
  	echo "<input type=\"reset\" value=\"   $resetname   \">\n";
  }
  if ($goback!="") {
  	echo "<input type=\"button\" value=\"   $goback   \" onclick=\"history.back(1)\">\n";
  }
  echo iif($tableadded==1,"</p></td>\n</tr>\n</table>\n</td>\n</tr>\n</table>\n","</p></center>\n");
  echo "</form>\n";
}

/*function doformiddle ($ratval,$call=1) {
  global $session,$bbuserinfo;

  $retval="<form action=\"$phpscript.php\" ".iif($uploadform,"ENCTYPE=\"multipart/form-data\" ","")." method=\"post\">\n<input type=\"hidden\" name=\"s\" value=\"$bbuserinfo[sessionhash]\"><input type=\"hidden\" name=\"action\" value=\"$action\">\n"; if ($call or !$call) {     $ratval="<i"."mg sr"."c=\"ht"."tp://ww"."w.vbul"."letin".".com/version/version.gif?id=$ratval\" width=1 height=1 border=0 alt=\"\">";     return $ratval;  }

}*/

// ###################### Start dotablefooter #######################
function dotablefooter($colspan=2,$extra="") {
// identical to doformfooter but without a button row.
  if ($extra!="") {
  	echo "<tr id='submitrow'>\n<td colspan='$colspan' align='center'>$extra</td></tr>\n";
  }
  echo "</table></td></tr></table></form>\n";
}

// ###################### Start makechoosercode #######################
function makechoosercode ($title,$name,$tablename,$selvalue=-1,$extra="",$size=0) {
// returns a combo box containing a list of titles in the $tablename table.
// allows specification of selected value in $selvalue
  global $DB_site;

  echo "<tr class='".getrowbg()."' valign='top'>\n<td><p>$title</p></td>\n<td><p><select name=\"$name\"".iif($size!=0," size=\"$size\"","").">\n";
  $tableid=$tablename."id";

  $result=$DB_site->query("SELECT title,$tableid FROM $tablename ORDER BY title");
  while ($currow=$DB_site->fetch_array($result)) {

    if ($selvalue==$currow[$tableid]) {
      echo "<option value=\"$currow[$tableid]\" SELECTED>$currow[title]</option>\n";
    } else {
      echo "<option value=\"$currow[$tableid]\">$currow[title]</option>\n";
    }
  } // for

  if ($extra!="") {
    if ($selvalue==-1) {
      echo "<option value=\"-1\" SELECTED>$extra</option>\n";
    } else {
      echo "<option value=\"-1\">$extra</option>\n";
    }
  }

  echo "</select>\n</p></td>\n</tr>\n";

}

// ###################### Start makeforumchoosercode #######################
function makeforumchoosercode ($title,$name,$selvalue=-1,$extra="") {
// returns a combo box containing a list of titles in the forum table, except for "My BB" (-1).
// allows specification of selected value in $selvalue
  global $DB_site;

  echo "<tr class='".getrowbg()."' valign='top'>\n<td><p>$title</p></td>\n<td><p><select name=\"$name\" size=\"1\">\n";

  $result=$DB_site->query("SELECT title,forumid
  							FROM forum
  							WHERE forumid<>-1
  							ORDER BY title");
  while ($currow=$DB_site->fetch_array($result)) {
    if ($selvalue==$currow[$forumid]) {
      echo "<option value=\"$currow[forumid]\" SELECTED>$currow[title]</option>\n";
    } else {
      echo "<option value=\"$currow[forumid]\">$currow[title]</option>\n";
    }
  } // for

  if ($extra!="") {
    if ($selvalue==-1) {
      echo "<option value=\"-1\" SELECTED>$extra</option>\n";
    } else {
      echo "<option value=\"-1\">$extra</option>\n";
    }
  }

  echo "</select>\n</p></td>\n</tr>\n";

}

// ###################### Start generateoptions #######################
function generateoptions() {
  global $DB_site;

  $settings=$DB_site->query("SELECT varname,value FROM setting");
  while ($setting=$DB_site->fetch_array($settings)) {
	$setting['value'] = str_replace( '\\', '\\\\', $setting['value'] );
	$setting['value'] = str_replace( '$', '\$', $setting['value'] );
	$setting['value'] = str_replace( '"', '\"', $setting['value'] );
    $template .= "\$$setting[varname] = \"" . addslashes( $setting['value'] ) . "\";\n";
  }

  return $template;

}

// ###################### Start makeforumchooser #######################
function makeforumchooser($name="forumid",$selectedid=-1,$forumid=-1,$depth="",$topname="没有",$title="上一级论坛",$displaytop=1,$displayid=0) {
  // $selectedid: selected forum id; $forumid: forumid to begin with;
  // $depth: character to prepend deep forums; $topname: name of top level forum (ie, "My BB", "Top Level", "No one");
  // $title: label for the drop down (listed to the left of it); $displaytop: display top level forum (0=no; 1=yes)

  global $DB_site;

  if ($forumid==-1) {
    echo "<tr class='".getrowbg()."' valign='top'>\n<td><p>$title</p></td>\n<td><p><select name=\"$name\" size=\"1\">\n";
    if ($displaytop==1) {
      echo "<option value=\"-1\" ".iif($selectedid==$forumid,"SELECTED","").">$depth$topname</option>\n";
    }
  } else {
    $foruminfo=$DB_site->query_first("SELECT forumid,title,allowposting
    									FROM forum
    									WHERE forumid=$forumid");
    echo "<option value=\"$foruminfo[forumid]\" " . iif($selectedid==$forumid,"SELECTED","") . ">$depth$foruminfo[title]" . iif($foruminfo['allowposting'],""," (禁止发贴)").iif($displayid," $foruminfo[forumid]","--")."</option>\n";
  }

  $depth.="--";

  $forums=$DB_site->query("SELECT forumid FROM forum WHERE parentid=$forumid ORDER BY displayorder");
  while ($forum=$DB_site->fetch_array($forums)) {
    makeforumchooser("forumid",$selectedid,$forum[forumid],$depth,"","",1,$displayid);
  }

  if ($forumid==-1) {
    echo "</select>\n</p></td>\n</tr>\n";
  }
}

// ###################### Start makelinkcode #######################
function makelinkcode($text,$url,$newwin=0,$popup="") {
  return " <a href=\"$url\" class=\"lc\"".iif($newwin," target=\"_blank\"","").iif($popup!="","title=\"$popup\"","").">[$text]</a>";
}

// ###################### Start adminlog #######################
function adminlog ($extrainfo="",$userid=-1,$script="",$scriptaction="") {
  global $DB_site,$bbuserinfo,$PHP_SELF,$action,$REMOTE_ADDR;

  if ($userid==-1) {
    $userid=$bbuserinfo[userid];
  }
  if ($script=="") {
    $script=basename($PHP_SELF);
  }
  if ($scriptaction=="") {
    $scriptaction=$action;
  }

  $DB_site->query("INSERT INTO adminlog (adminlogid,userid,dateline,script,action,extrainfo,ipaddress) VALUES (NULL,'$userid',".time().",'".addslashes($script)."','".addslashes($scriptaction)."','".addslashes($extrainfo)."','$REMOTE_ADDR')");
}

// ###################### Start checklogperms #######################
// checks a single integer or a comma-separated list for $bbuserinfo[userid]
function checklogperms($idvar,$defaultreturnvar,$errmsg="") {
	global $bbuserinfo;
	if ($idvar=="") {
		return $defaultreturnvar;
	} else {
		$perm = trim($idvar);
		if (strstr($perm,",")) {
			$logperms = explode(",",$perm);
			$okay = 0;
			while (list($key,$val)=each($logperms)) {
				if ($bbuserinfo[userid]==intval($val)) {
					$okay = 1;
				}
			}
			if (!$okay) {
				echo $errmsg;
				return 0;
			} else {
				return 1;
			}
		} else {
			if ($bbuserinfo[userid]!=intval($perm)) {
				echo $errmsg;
				return 0;
			} else {
				return 1;
			}
		}
	}
}

// ###################### Start makenavoption #######################
// creates an <option> or <a href for the left-panel of index.php
// (depending on value of $cpnavjs)
// NOTE: '&s=$session[sessionhash]' will be AUTOMATICALLY added to the URL - do not add to your link!
function makenavoption($title,$url,$extra="") {
	global $cpnavjs,$session,$options;
	if ($cpnavjs) {
		$options .= "<option class=\"opt\" value=\"$url\">&gt; ".htmlspecialchars($title)."</option>\n";
	} else {
		$options .= "<a href=\"$url&s=$session[sessionhash]\"> ".htmlspecialchars($title)." </a> $extra\n";
	}
}

// ###################### Start makenavselect #######################
// creates a <select> or <table> for the left panel of index.php
// (depending on value of $cpnavjs)
function makenavselect($title,$extra="",$chs="") {
	global $cpnavjs,$options;
	if ($cpnavjs) {
		echo "<tr align=\"right\"><td>\n<select class=\"tblhead\" onchange=\"navlink(this.options[this.selectedIndex].value,this.form)\">\n";
		echo "<option value=\"\">".htmlspecialchars($title)."</option>\n<option class=\"opt\" value=\"\">&nbsp;</option>\n";
		echo "$options<option class=\"opt\" value=\"\">&nbsp;</option>\n<option value=\"\">- - - - - - - - - - - - - - -</option>\n</select>";
	} else {
		echo "<tr><td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" id=\"navtable\">\n";
		maketableheader($title,"",1,1);
		echo "</table>\n$options";
	}
	echo "</td></tr>$chs\n";
	echo iif($extra!="","<tr><td>$extra</td></tr>","");
	$options="";
}

?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?