本篇实现发表博客。
八、发表博客
(1)、界面实现file.php
<tr> <td colSpan=3 valign="baseline" style="BACKGROUND-IMAGE: url( images/bg.jpg); VERTICAL-ALIGN: middle; HEIGHT: 450px; TEXT-ALIGN: center"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td height="451" align="center" valign="top"> <!-- 发表文章 --> <table width="640" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="613" height="223" align="center"><br> <span style="white-space:pre"> </span><table width="500" border="0" cellpadding="0" cellspacing="0"> <tr> <td> <span style="white-space:pre"> </span> <form name="myform" method="post" action="check_file.php?flag=<?php echo $flag; if($flag){echo "&id=".$_GET['file_id'];}?>"> <span style="white-space:pre"> </span> <table width="630" border="1" cellpadding="3" cellspacing="1" bordercolor="#D6E7A5"> <tr> <td class="i_table" colspan="2"> <span class="tableBorder_LTR">添加博客文章</span></td> </tr> <tr> <td valign="top" align="right" width="14%">博客主题:<br></td> <td width="86%"><input name="txt_title" type="text" id="txt_title" size="68" value="<?php if($flag){echo $title;}?>"></td> </tr> <tr> <td align="right" width="14%">文字编辑区:</td> <td width="86%"> <img src=" images/UBB/B.gif" width="21" height="20" onClick="bold()"> <img src=" images/UBB/I.gif" width="21" height="20" onClick="italicize()"> <img src=" images/UBB/U.gif" width="21" height="20" onClick="underline()"> <span style="white-space:pre"> </span> 字体 <select name="font" class="wenbenkuang" id="font" onChange="showfont(this.options[this.selectedIndex].value)"> <option value="宋体" selected>宋体</option> <option value="黑体">黑体</option> <option value="隶书">隶书</option> <option value="楷体">楷体</option> </select> 字号<span class="pt9"> <select name=size class="wenbenkuang" onChange="showsize(this.options[this.selectedIndex].value)"> <option value=1>1</option> <option value=2>2</option> <option value=3 selected>3</option> <option value=4>4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> </select> 颜色 <select onChange="showcolor(this.options[this.selectedIndex].value)" name="color" size="1" class="wenbenkuang" id="select"> <option selected>默认颜色</option> <option style="color:#FF0000" value="#FF0000">红色热情</option> <option style="color:#0000FF" value="#0000ff">蓝色开朗</option> <option style="color:#ff00ff" value="#ff00ff">桃色浪漫</option> <option style="color:#009900" value="#009900">绿色青春</option> <option style="color:#009999" value="#009999">青色清爽</option> <option style="color:#990099" value="#990099">紫色拘谨</option> <option style="color:#990000" value="#990000">暗夜兴奋</option> <option style="color:#000099" value="#000099">深蓝忧郁</option> <option style="color:#999900" value="#999900">卡其制服</option> <option style="color:#ff9900" value="#ff9900">镏金岁月</option> <option style="color:#0099ff" value="#0099ff">湖波荡漾</option> <option style="color:#9900ff" value="#9900ff">发亮蓝紫</option> <option style="color:#ff0099" value="#ff0099">爱的暗示</option> <option style="color:#006600" value="#006600">墨绿深沉</option> <option style="color:#999999" value="#999999">烟雨蒙蒙</option> </select></span> </td> </tr> <tr> <td align="right" width="14%">文章内容:</td> <td width="86%"> <span style="white-space:pre"> </span> <div class="file"><span style="white-space:pre"> </span> <span style="white-space:pre"> </span><textarea name="file" cols="75" rows="20" id="file" style="border:0px;width:520px;"><?php if($flag){echo $content;}?></textarea> <span style="white-space:pre"> </span> </div> <span style="white-space:pre"> </span> </td> </tr> <tr align="center"> <td colspan="2"><input name="btn_tj" type="submit" id="btn_tj" value="提交" onClick="return check();"> <input name="btn_cx" type="reset" id="btn_cx" value="重写"> </td> </tr> </table> <span style="white-space:pre"> </span></form> <span style="white-space:pre"> </span></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr>
编辑文章时各个选项使用js实现:UBBCode.js
helpstat = false; basic = false; function AddText(NewCode) { document.all("file").value+=NewCode } function showsize(size) { if (helpstat) { alert("文字大小标记\n设置文字大小.\n可变范围 1 - 6.\n 1 为最小 6 为最大.\n用法: <size="+size+">这是 "+size+" 文字</size>"); } else if (basic) { AddTxt="<font size="+size+"></font>"; AddText(AddTxt); } else { txt=prompt("大小 "+size,"文字"); if (txt!=null) { AddTxt="<font size="+size+">"+txt; AddText(AddTxt); AddTxt="</font>"; AddText(AddTxt); } } } function bold() { if (helpstat) { alert("加粗标记\n使文本加粗.\n用法: <b>这是加粗的文字</b>"); } else if (basic) { AddTxt="<b></b>"; AddText(AddTxt); } else { txt=prompt("文字将被变粗.","请在这里输入要加粗的文字!"); if (txt!=null) { AddTxt="<b>"+txt; AddText(AddTxt); AddTxt="</b>"; AddText(AddTxt); } } } function italicize() { if (helpstat) { alert("斜体标记\n使文本字体变为斜体.\n用法: <i>这是斜体字</i>"); } else if (basic) { AddTxt="<i></i>"; AddText(AddTxt); } else { txt=prompt("文字将变斜体","请在这里输入要倾斜的文字!"); if (txt!=null) { AddTxt="<i>"+txt; AddText(AddTxt); AddTxt="</i>"; AddText(AddTxt); } } } function showcolor(color) { if (helpstat) { alert("颜色标记\n设置文本颜色. 任何颜色名都可以被使用.\n用法: <color="+color+">颜色要改变为"+color+"的文字</color>"); } else if (basic) { AddTxt="<font color="+color+"></font>"; AddText(AddTxt); } else { txt=prompt("选择的颜色是: "+color,"请在这里输入要改变颜色的文字!"); if(txt!=null) { AddTxt="<font color="+color+">"+txt; AddText(AddTxt); AddTxt="</font>"; AddText(AddTxt); } } } function showfont(font) { if (helpstat){ alert("字体标记\n给文字设置字体.\n用法: <font="+font+">改变文字字体为"+font+"</font>"); } else if (basic) { AddTxt="<font face="+font+"></font>"; AddText(AddTxt); } else { txt=prompt("要设置字体的文字"+font,"请在这里输入要改变字体的文字!"); if (txt!=null) { AddTxt="<font face="+font+">"+txt; AddText(AddTxt); AddTxt="</font>"; AddText(AddTxt); } } } function underline() { if (helpstat) { alert("下划线标记\n给文字加下划线.\n用法: <u>要加下划线的文字</u>"); } else if (basic) { AddTxt="<u></u>"; AddText(AddTxt); } else { txt=prompt("下划线文字.","文字"); if (txt!=null) { AddTxt="<u>"+txt; AddText(AddTxt); AddTxt="</u>"; AddText(AddTxt); } } }
(2)后台添加到数据库实现check_file.php
<?php session_start(); require_once 'Conn/SqlHelper.class.php'; $flag = $_GET['flag']; if($flag!=2){ $txt_title = $_POST['txt_title']; $file = $_POST['file']; $author = $_SESSION['username']; $date = date("Y-m-d H:i:s"); } $sqlHelper = new SqlHelper(); if($flag==0){ $sql = "insert into tb_article(title,content,author,now)values('$txt_title','$file','$author','$date')"; } $res = $sqlHelper->execute_dml($sql); if($res==1){ echo "<script>alert('操作成功!');</script>"; echo "<script>window.location.href='myfiles.php';</script>"; }else{ echo "<script>alert('对不起失败了!');</script>"; echo "<script> history.go(-1);</script>"; } ?>
时间: 2024-12-12 13:51:35