定义文件:\source\function\function_admincp.php
函数定义:
function cpmsg($message, $url = '', $type = '', $values = array(), $extra = '', $halt = TRUE, $cancelurl = '') {
global $_G;
$vars = explode(':', $message);
$values['ADMINSCRIPT'] = ADMINSCRIPT;
if(count($vars) == 2) {
$message = lang('plugin/'.$vars[0], $vars[1], $values);
} else {
$message = cplang($message, $values);
}
switch($type) {
case 'download':
case 'succeed': $classname = 'infotitle2';break;
case 'error': $classname = 'infotitle3';break;
case 'loadingform': case 'loading': $classname = 'infotitle1';break;
default: $classname = 'marginbot normal';break;
}
if($url) {
$url = substr($url, 0, 5) == 'http:' ? $url : ADMINSCRIPT.'?'.$url;
}
$message = "<h4 class=\"$classname\">$message</h4>";
$url .= $url && !empty($_GET['scrolltop']) ? '&scrolltop='.intval($_GET['scrolltop']) : '';
if($type == 'form') {
$message = "<form method=\"post\" action=\"$url\"><input type=\"hidden\" name=\"formhash\" value=\"".FORMHASH."\">".
"<br />$message$extra<br />".
"<p class=\"margintop\"><input type=\"submit\" class=\"btn\" name=\"confirmed\" value=\"".cplang('ok')."\"> \n".
($cancelurl ? "<input type=\"button\" class=\"btn\" value=\"".cplang('cancel')."\" onClick=\"location.href='$cancelurl'\">" :
"<script type=\"text/javascript\">".
"if(history.length > (BROWSER.ie ? 0 : 1)) document.write('<input type=\"button\" class=\"btn\" value=\"".cplang('cancel')."\" onClick=\"history.go(-1);\">');".
"</script>").
"</p></form><br />";
} elseif($type == 'loadingform') {
$message = "<form method=\"post\" action=\"$url\" id=\"loadingform\"><input type=\"hidden\" name=\"formhash\" value=\"".FORMHASH."\"><br />$message$extra<img src=\"static/image/admincp/ajax_loader.gif\" class=\"marginbot\" /><br />".
'<p class="marginbot"><a href="###" οnclick="$(\'loadingform\').submit();" class="lightlink">'.cplang('message_redirect').'</a></p></form><br /><script type="text/JavaScript">setTimeout("$(\'loadingform\').submit();", 2000);</script>';
} else {
$message .= $extra.($type == 'loading' ? '<img src="static/image/admincp/ajax_loader.gif" class="marginbot" />' : '');
if($url) {
if($type == 'button') {
$message = "<br />$message<br /><p class=\"margintop\"><input type=\"submit\" class=\"btn\" name=\"submit\" value=\"".cplang('start')."\" οnclick=\"location.href='$url'\" />";
} else {
$message .= '<p class="marginbot"><a href="'.$url.'" class="lightlink">'.cplang($type == 'download' ? 'message_download' : 'message_redirect').'</a></p>';
$timeout = $type != 'loading' ? 3000 : 1000;
$message .= "<script type=\"text/JavaScript\">setTimeout(\"redirect('$url');\", $timeout);</script>";
}
} elseif($type != 'succeed') {
$message .= '<p class="marginbot">'.
"<script type=\"text/javascript\">".
"if(history.length > (BROWSER.ie ? 0 : 1)) document.write('<a href=\"javascript:history.go(-1);\" class=\"lightlink\">".cplang('message_return')."</a>');".
"</script>".
'</p>';
}
}
if($halt) {
echo '<h3>'.cplang('discuz_message').'</h3><div class="infobox">'.$message.'</div>';
exit();
} else {
echo '<div class="infobox">'.$message.'</div>';
}
}
参数介绍:
$message - lang_admincp_msg.php 语言包中需要输出的key
$url - 提示信息后跳转的页面,留空则返回上一页
$type - 特殊提示信息时指定页面的提示样式,可选参数:succeed、error、download、loadingform
$values - 为语言包中的变量关键词指定值,以数组形式输入
$extra - 消息文字扩展
$halt - 是否输出“Discuz! 提示”标题
使用方法举例:
//成功提示信息
cpmsg('tasks_installed', 'action=tasks&operation=type', 'succeed');
//错误提示信息,并传递变量(cachethreaddir为要传递如语言包中的变量关键词)
cpmsg('cachethread_dir_noexists', '', 'error', array('cachethreaddir' => $settingnew['cachethreaddir']));