Discuz!X/后台HTML显示函数
来自Blueidea
discuzx 后台模块开发大多直接调用后台HTML函数输出,使用HTML输出函数更加方便快捷的构建一个后台WEB页面。
目录
- 函数原型
function shownav($header = '', $menu = '', $nav = '') { global $action, $operation; $title = 'cplog_'.$action.($operation ? '_'.$operation : ''); if(in_array($action, array('home', 'custommenu'))) { $customtitle = ''; } elseif(cplang($title, false)) { $customtitle = $title; } elseif(cplang('nav_'.($header ? $header : 'index'), false)) { $customtitle = 'nav_'.$header; } else { $customtitle = rawurlencode($nav ? $nav : ($menu ? $menu : '')); } $title = cplang('header_'.($header ? $header : 'index')).($menu ? ' » '.cplang($menu) : '').($nav ? ' » '.cplang($nav) : ''); $ctitle = cplang('header_'.($header ? $header : 'index')); if($menu) { $ctitle = cplang($menu); } if($nav) { $ctitle = cplang($nav); } $addtomenu = " <a target=\"main\" title=\"".cplang('custommenu_addto')."\" href=\"".ADMINSCRIPT."?action=misc&operation=custommenu&do=add&title=".rawurlencode($ctitle)."&url=".rawurlencode(cpurl())."\">[+]</a>"; $dtitle = str_replace("'", "\'", cplang('admincp_title').' - '.str_replace(' » ', ' - ', $title)); echo '<script type="text/JavaScript">parent.document.title = \''.$dtitle.'\';if(parent.$(\'admincpnav\')) parent.$(\'admincpnav\').innerHTML=\''.$title.$addtomenu.'\';</script>'; }
- 参数解释
$header 导航模块名 $menu 菜单 $nav 当前导航名
- 使用范例
//品网后台导航显示 shownav('pages', 'menu_pages_sortoption');
- 函数原型
function showsubmenu($title, $menus = array(), $right = '', $replace = array()) { if(empty($menus)) { $s = '<div class="itemtitle">'.$right.'<h3>'.cplang($title, $replace).'</h3></div>'; } elseif(is_array($menus)) { $s = '<div class="itemtitle">'.$right.'<h3>'.cplang($title, $replace).'</h3>'; if(is_array($menus)) { $s .= '<ul class="tab1">'; foreach($menus as $k => $menu) { if(is_array($menu[0])) { $s .= '<li id="addjs'.$k.'" class="'.($menu[1] ? 'current' : 'hasdropmenu').'" onmouseover="dropmenu(this);"><a href="#"><span>'.cplang($menu[0]['menu']).'<em> </em></span></a><div id="addjs'.$k.'child" class="dropmenu" style="display:none;">'; if(is_array($menu[0]['submenu'])) { foreach($menu[0]['submenu'] as $submenu) { $s .= $submenu[1] ? '<a href="'.ADMINSCRIPT.'?action='.$submenu[1].'" class="'.($submenu[2] ? 'current' : '').'" onclick="'.$submenu[3].'">'.cplang($submenu[0]).'</a>' : '<a><b>'.cplang($submenu[0]).'</b></a>'; } } $s .= '</div></li>'; } else { $s .= '<li'.($menu[2] ? ' class="current"' : '').'><a href="'.(!$menu[4] ? ADMINSCRIPT.'?action='.$menu[1] : $menu[1]).'"'.(!empty($menu[3]) ? ' target="_blank"' : '').'><span>'.cplang($menu[0]).'</span></a></li>'; } } $s .= '</ul>'; } $s .= '</div>'; } echo !empty($menus) ? '<div class="floattop">'.$s.'</div><div class="floattopempty"></div>' : $s; }
- 参数解释
$title 二级导航标题 $menus 展示的二级菜单(数组)
- 使用范例
showsubmenu('menu_pages_sortoption');
表单头示函数(showformheader)
- 函数原型
function showformheader($action, $extra = '', $name = 'cpform', $method = 'post') { global $_G; $anchor = isset($_G['gp_anchor']) ? htmlspecialchars($_G['gp_anchor']) : ''; echo '<form name="'.$name.'" method="'.$method.'" autocomplete="off" action="'.ADMINSCRIPT.'?action='.$action.'" id="'.$name.'"'.($extra == 'enctype' ? ' enctype="multipart/form-data"' : " $extra").'>'. '<input type="hidden" name="formhash" value="'.FORMHASH.'" />'. '<input type="hidden" id="formscrolltop" name="scrolltop" value="" />'. '<input type="hidden" name="anchor" value="'.$anchor.'" />'; }
- 参数解释
$action 提交页面地址 $extra 表单编码方式指定 $name 表单名称 $method 表单提交方式 例如 post,get 等
- 使用范例
showformheader('pages&operation=sort&do='.$do);
- 函数原型
function showformfooter() { global $_G; if(!empty($_G['setting_JS'])) { echo '<script type="text/JavaScript">'.$_G['setting_JS'].'</script>'; } updatesession(); echo '</form>'."\n"; if($scrolltop = intval(getgpc('scrolltop'))) { echo '<script type="text/JavaScript">_attachEvent(window, \'load\', function () { scroll(0,'.$scrolltop.') }, document);</script>'; } }
- 使用范例
//调用表单内容输出完毕后直接调用这个参数即可 showformfooter()
按钮显示函数(showsubmit)
- 函数原型
function showsubmit($name = '', $value = 'submit', $before = '', $after = '', $floatright = '', $entersubmit = true) { global $_G; if(!empty($_G['showsetting_multi'])) { return; } $str = '<tr>'; $str .= $name && in_array($before, array('del', 'select_all', 'td')) ? '<td class="td25">'.($before != 'td' ? '<input type="checkbox" name="chkall" id="chkall'.($chkkallid = random(4)).'" class="checkbox" onclick="checkAll(\'prefix\', this.form, \'delete\')" /><label for="chkall'.$chkkallid.'">'.cplang($before) : '').'</label></td>' : ''; $str .= '<td colspan="15">'; $str .= $floatright ? '<div class="cuspages right">'.$floatright.'</div>' : ''; $str .= '<div class="fixsel">'; $str .= $before && !in_array($before, array('del', 'select_all', 'td')) ? $before.' ' : ''; $str .= $name ? '<input type="submit" class="btn" id="submit_'.$name.'" name="'.$name.'" title="'.($entersubmit ? cplang('submit_tips') : '').'" value="'.cplang($value).'" />' : ''; $after = $after == 'more_options' ? '<input class="checkbox" type="checkbox" value="1" onclick="$(\'advanceoption\').style.display = $(\'advanceoption\').style.display == \'none\' ? \'\' : \'none\'; this.value = this.value == 1 ? 0 : 1; this.checked = this.value == 1 ? false : true" id="btn_more" /><label for="btn_more">'.cplang('more_options').'</label>' : $after; $str = $after ? $str.(($before && $before != 'del') || $name ? ' ' : '').$after : $str; $str .= '</div></td>'; $str .= '</tr>'; echo $str.($name && $entersubmit ? '<script type="text/JavaScript">_attachEvent(document.documentElement, \'keydown\', function (e) { entersubmit(e, \''.$name.'\'); });</script>' : ''); }
- 参数解释
$name 按钮名称 $value 按钮值
- 使用范例
showsubmit('editsubmit');
折叠式表单显示函数(showpages)
- 函数原型
function showpages(&$cate, $type = '', $last = '') { if($last == '') { $return = '<tr class="hover"><td class="td25"><input type="checkbox" class="checkbox" name="delete[]" value="'.$cate['sortid'].'" /></td><td class="td25"><input type="text" class="txt" name="order['.$cate['sortid'].']" value="'.$cate['displayorder'].'" /></td><td>'; if($type == 'parent') { $return .= '<div class="parentboard">'; } elseif($type == '') { $return .= '<div class="board">'; } elseif($type == 'child') { $return .= '<div id="cb_'.$cate['sortid'].'" class="childboard">'; } $return .= '<input type="text" name="name['.$cate['sortid'].']" value="'.htmlspecialchars($cate['title']).'" class="txt" />'; $return .= '</div></td></tr>'; } else { if($last == 'lastboard') { $return = '<tr><td></td><td colspan="3"><div class="lastboard"><a href="###" onclick="addrow(this, 1, '.$cate['sortid'].')" class="addtr">'.cplang('add_parentsort').'</a></div></td></tr>'; } elseif($last == 'lastchildboard' && $type) { $return = '<script type="text/JavaScript">$(\'cb_'.$type.'\').className = \'lastchildboard\';</script>'; } elseif($last == 'last') { $return = '<tr><td colspan="3"><div><a href="###" onclick="addrow(this, 0)" class="addtr">'.cplang('add_sort').'</a></div></td></tr>'; } } echo $return; }
- 参数解析
- 函数原型
function showtableheader($title = '', $classname = '', $extra = '', $titlespan = 15) { global $_G; $classname = str_replace(array('nobottom', 'notop'), array('nobdb', 'nobdt'), $classname); if(isset($_G['showsetting_multi'])) { if($_G['showsetting_multi'] == 0) { $extra .= ' style="width:'.($_G['showsetting_multicount'] * 270 + 20).'px"'; } else { return; } } echo "\n".'<table class="tb tb2 '.$classname.'"'.($extra ? " $extra" : '').'>'; if($title) { $span = $titlespan ? 'colspan="'.$titlespan.'"' : ''; echo "\n".'<tr><th '.$span.' class="partition">'.cplang($title).'</th></tr>'; showmultititle(); } }
- 参数解释
$title 表格标题 $classname 表格样式名 $extra 表格大小参数 $titlespan 表格列数
- 使用范例
showtableheader('admin', 'fixpadding');