Code sẽ hiểu thị nick và tin nhắn theo mỗi sub domain khi tv chát
Dành cho bạn nào đang làm wapbuilder trên wapego
Bước 1: tạo tệp tin tên chatbox
Thêm mả twig
{%macro blog(xmsg,form_url)%} {%set sid=0%}{%set sdata={}%} {%set sotrang=8%}{%set hiencmt="false"%}{%set hienform="false"%} {%for i in 0..xmsg|length-1%} {%if "[-uid-]" in xmsg[i] and "[-xcmt-]" not in xmsg[i]%} {%set uid=xmsg[i]|split("[-uid-]")[1]|split("[-msg-]")[0]%} {%set msg=xmsg[i]|split("[-msg-]")[1]|split("[-url-]")[0]%} {%set date=xmsg[i]|split("[-date-]")[1]|split("[-lin-]")[0]%} {%set nicks=api.u.get(xmsg[i]|split("[-nick-]")[1]|split("[-date-]")[0])%} {%set socmt=0%}{%set comment=""%}{%set datecmt="-"%} {%if "[-hidden-]" in msg and api.u.get(api.user_id).uid!=nicks.uid%}{%set ghidden="true"%}{%else%}{%set ghidden=""%}{%endif%} {%set fuid%}{%if api.r.get("f")>=100%}main.php?f={{api.r.get("f")}}{%else%}main.php?{%endif%}{%endset%} {%for i in xmsg|length-1..0%} {%set amsg=xmsg[i]|split("[-msg-]")[1]|split("[-url-]")[0]%} {%set adate=xmsg[i]|split("[-date-]")[1]|split("[-lin-]")[0]%} {%set anicks=api.u.get(xmsg[i]|split("[-nick-]")[1]|split("[-date-]")[0])%} {%if amsg|split("[-xcmt-]")[0]==uid and "[-xcmt-]" in amsg%}{%set socmt=socmt+1%} {#<a href="user_info.php?uid='~api.u.get(lmsg[y]|slice(0,9)).uid~'" class="'~api.u.get(lmsg[y]|slice(0,9)).levelCSS~'">#} {%set binhluan%}{%set lmsg=amsg|split("[-xcmt-]")[1]|split("@[")%}{%set sbody=""%}{%for y in 0..lmsg|length%}{%if api.u.get(lmsg[y]|split("]")[0]).uid>5%}{%set sbody=sbody~'<img src="/files/953350/quote1.png">'~api.u.get(lmsg[y]|slice(0,8)).nick~'<img src="/files/953350/quote2.png">'~lmsg[y]|split("]")[1]%}{%else%}{%endif%} {%endfor%} {%if sbody|length < 3%}{%set sbody=message%}{%endif%} {%set sbody=sbody|default(amsg|split("[-xcmt-]")[1])%} </div><div class="left">» {{anicks.nick}}: {{sbody|raw}}<br/><a href="/{{fuid}}&cmt=true&suid={{uid}}&ten={{anicks.uid}}"> Trả lời</a></div>[-yota-]{%endset%} {%set comment=comment~binhluan%} {%set datecmt=xmsg[i]|split("[-uid-]")[1]|split("[-msg-]")[0]%} {%endif%}{%endfor%}{%if datecmt=="-"%}{%set datecmt=uid%}{%endif%} {%set status2%}[-xtcmt-]{{datecmt}}[-page-]{% set host=api.r.createFromGlobals().Host %} {%set conts=msg|split('[body]')[1]|split('[/body]')[0]|raw%} {% if host==conts|striptags~'' %} <div class="menu"> <b>{{nicks.nick}}</b>: {{msg|split('[title]')[1]|split('[/title]')[0]|raw}} </div></div>{% endif %} {%if socmt>100 and api.r.get("cmt")!="true"%}<img src="/files/1020011/icons-new%20copy.png"><a href="/{{fuid}}&cmt=true&suid={{uid}}">Xem thêm {{socmt100}} bình luận</a>{%endif%}{%endset%}{%set status%}{%if api.r.get('cmt')=='true'%}[-xtcmt-]{{datecmt}}[-page-]<div class="title"><textarea style="display:none" id="title"> {{msg|split('[title]')[1]|split('[/title]')[0]|raw}}{% set host=api.r.createFromGlobals().Host %} {% if host!='xego.wap.mu' %} </textarea><script type="text/javascript">document.title=document.getElementById('title').innerHTML;</script><a href="http://{{nicks.nick}}.xego.wap.mu"><font color="ffffff">Trang chủ</font></a> > <a href="/{{fuid}}&cmt=true&suid={{uid}}"><font color="ffffff">{{msg|split('[title]')[1]|split('[/title]')[0]|raw}}</font></a></div><div class="left4">» Ngày đăng: {{date}}<br/></small></div><div id="bg"></div><font color="red"><b>Nội dung</b></font>: {%set conts=msg|split('[body]')[1]|split('[/body]')[0]|raw%}{{conts|raw}}<br/></center> <div class="title"> Bình luận {{socmt}}</div></div></div></div></div>{%if socmt>100 and api.r.get("cmt")!="true"%}<div class="left"><a href="/{{fuid}}&cmt=true&suid={{uid}}">Xem thêm {{socmt100}} bình luận</a>{% endif %}{%endif%}{%else%}{%if api.r.get('search') is not empty%}{%set skey=api.r.get('type')%}{%set ssearch=api.r.get('search')%}{%if (skey=='nick' and ssearch==nicks.nick) or (skey=='title' and ssearch in ('!'~msg|split('[title]')[1]|split('[/title]')[0])) or (skey=='body' and ssearch in ('!'~msg|split('[body]')[1]|split('[/body]')[0])) or (skey=='date' and ssearch in ('!'~date))%}{{status2}}{%endif%}{%elseif api.r.get('search') is empty%}{{status2}}{%endif%}{%endif%}{%endset%} {%set form%}<form action="{{form_url}}" method="post" class="nhanh" onsubmit="writef(this,'{{uid}}')"><div class="title"><input name="desc" type="text" value="{%if api.r.get("ten")>4%}@[{{api.r.get("ten")}}] {%endif%}"><input type="hidden" name="text" value=""><input type="hidden" name="suid" value="{{uid}}"/><input type="submit" value="Bình luận"></form></div>{%endset%} {%set zcmt=comment|split("[-yota-]")%} {%if api.r.get("cmt")=="true"%} {%if api.r.get("suid")==uid%}{%set messages=status~'<div class="left">'~comment|split("[-yota-]")|join("")~form~'</div>'%} {%else%}{%set messages=""%}{%endif%} {%else%}{%set messages=hiencmt=="true"?status~'<div class="vdata">'~zcmt[socmt-5]~zcmt[socmt-4]~zcmt[socmt-3]~zcmt[socmt-2]~zcmt[socmt-1]~(hienform=="true"?form:"")~'</div>':status%} {%endif%} {%if ghidden=="true"%}{%set messages=""%}{%endif%} {% set sdata = sdata|merge({ ("thaian"~sid): messages}) %} {% set sid=sid+1%} {%endif%} {%endfor%} {%for i in 0..sid%} {%for j in (i+1)..sid%} {%if (sdata["thaian"~i]|split("[-xtcmt-]")[1]|slice(0,14))*1 < (sdata["thaian"~j]|split("[-xtcmt-]")[1]|slice(0,14))*1 %} {%set temp=sdata["thaian"~j]%} {%set sdata=sdata|merge({("thaian"~j):sdata["thaian"~i]})%} {%set sdata=sdata|merge({("thaian"~i):temp})%} {%endif%} {%endfor%} {%endfor%} {%set spage=api.r.get("pusl")|default(0)%} {%if spage>0%}{%set dau=spage*sotrang%}{%set cuoi=((spage+1)*sotrang)-1%}{%else%}{%set dau=spage*sotrang%}{%set cuoi=((spage+1)*sotrang)-1%}{%endif%}<span id="khung">{%for i in dau..cuoi%} <span id="xkhung">{{sdata["thaian"~i]|split("[-page-]")[1]|raw}}</span><i></i>{%endfor%}</span></div> {% set host=api.r.createFromGlobals().Host %} {% if host!='xego.wap.mu' %} <center>{%if spage>0%}<a href="main.php?{%if api.r.get('f')>=5%}f={{api.r.get('f')}}{%endif%}&pusl={%if spage==null%}1{%else%}{{spage-1}}{%endif%}#chatne"></a> {%endif%}<a href="main.php?{%if api.r.get('f')>=5%}f={{api.r.get('f')}}{%endif%}&pusl={%if spage==null%}1{%else%}{{spage+1}}{%endif%}#chatne"><font color="red"><b></a></b></div></font></center>{% endif %} {%endmacro%} {%macro content(message,nick,message_date,delete_post_button)%}{%set dates=message_date%} {%if "[-xcmt-]" in message|slice(0,14)%}[-cmt-]{{message|split("[-xcmt-]")[0]}}{%endif%}[-uid-]{{dates|date("YmdHis")}}[-msg-]{{message}}{{delete_post_button|raw}}[-url-]{{file_url}}[-nick-]{{nick|slice(27,8)}}[-date-]{{dates|date("d-m-Y H:i:s")}}[-lin-][-msS-]{%endmacro%} {%import _self as blog%} {%set sdata=''%} {{_self.env.addGlobal('blog',blog)}} {{_self.env.addGlobal('sdata',sdata)}}
Bước 2: Thêm shoutbox lịch sử
Ô1:
{%set msg=message_list|split('[-msS-]')%} {%set sdata=_self.env.getGlobals()['sdata']%} {%set sdata=sdata~message_list%}{{_self.env.addGlobal('sdata',sdata)}} {%set surl=_self.env.getGlobals()['surl']%} {%if msg|length>=99%} {%if surl is empty%} {%set url=''%} {%else%} {%set url=surl%} {%endif%} {%else%} {%if surl is not empty%} {%set url=surl%} {%else%} {%set url=form_url%} {%endif%} {%endif%} {{_self.env.addGlobal('surl',url)}}
Ô2:
{{blog.content(message,nick,message_date,delete_post_button)}} {% set host=api.r.createFromGlobals().Host %} {% if host=='xego.wap.mu' %} {{blog.content(message,nick,message_date,delete_post_button)}} {% endif %}
Bước 3: thêm mả tiwg
<script type="text/javascript"> function writef(ff,vl) { var md=ff.desc.value; ff.text.value=vl+"[-xcmt-]"+md; } </script> {%if api.r.get('cmt')!='true'%}{% if api.u.get(api.user_id).level >= 0 %} {%if api.r.getMethod()=='GET' and api.r.get('them') is empty%}<a href="main.php?f=3552314&them=ok"></a>{%endif%} {%if api.r.getMethod()=='POST' and api.r.get('title') is not empty %}<div class="title">Chỉnh sửa</div><div class="gmenu"> Bạn vừa chỉnh sửa có tiêu đề là <font color="red">{{api.r.get('title')}}</font>. Bạn có muốn thêm vào wapsite của bạn?<br/> <form action="http://xego.wap.mu/{{_self.env.getGlobals()['surl']|replace({'them%3Dok':'them=title'})|raw}}" method="post"> <textarea name="text" style="display:none">[title]{{api.r.get('title')|default('Tiêu đề blog')}}[/title] </textarea> <input type="submit" value="Đồng ý thêm"/> </form><br/><a href="/"><font color="red">Về trang chủ</a></b> {%endif%}</div> {% endif %} {%if api.r.get('them')!='ok'%}</div> {%endif%} {%endif%}{% set host=api.r.createFromGlobals().Host %} {% if host!='xego.wap.mu' %}{%if api.r.get('chat')!='box'%} <div class="title">Chatbox</div>{%if api.user_id%} <div class="top">Chào<b>: <font color="red">[nick]</font></b> (<a href="http://{{host}}/main.php?[ses]&id=logout">Thoát</a>) </div>{%else%} <div class="top">Vui lòng <a href="http://{{host}}/main.php?f=3554250"><b><font color="red">Đăng kí</a></b></font> hoặc<a href="http://{{host}}/main.php?f=3554251"><b><font color="red"> Đăng nhập</font></b></a> để chát cùng {{host}}</div>{%endif%} <div class="menu"> <form action="/main.php?&chat=box" method="post"> <textarea rows="3" cols="20" name="text" style="width:auto"></textarea><br/> <input type="submit" value="Gửi tin"/></form></div>{%endif%} {%if api.r.get('chat')=='box'%} {% set host=api.r.createFromGlobals().Host %}Đã gửi tin nhắn thành công! Đang load...<center> <form action="http://{{host}}/main.php?[ses]&id=ch_topic_h&uid=236006&back_url=%2Fmain.php?" method="post"> <textarea rows="3" cols="20" name="text" style="width:auto; display:none">[title]{{api.r.get('text')}}[/title][body]{{host}}[/body]</textarea><br/> <input type="submit" value=" Gửi tin" id="load" style="display:none"/></form></center> <script language="javascript"> document.getElementById("load").click(); </script> {%endif%} <div class="shoutbox_message">{{message_list}}</div> {{paging_def}} </div>{% endif %} {%if api.r.get('them')!='ok'%} {%set sdata=_self.env.getGlobals()['sdata']|split('[-msS-]')%} {{blog.blog(sdata,_self.env.getGlobals()['surl'])}} {%endif%} <style type="text/css"> .khung{background-color: #ffffff; color: #339933; border: 1px #cacbc9 solid; margin: 1px; padding: 2px; text-align: left;}.xam { background-color: #cacbc9; color: #000000; padding-top: 2px; padding-bottom: 2px; text-align: center; font-weight: bold; }.khung img { vertical-align: top; }</style>
Bước 4:
Vào index tập tin khi vào wap cua bạn» bao gồm tệp tin khac » chọn tệp tin chatbox
Sửa ".xego.wap.mu" lại thanh wap ban
Vậy là xong, code dư thừa nhiều thứ bac nào rảnh thì xóa ko thì để cũng được
Demo: http://xego.wap.mu
Nguồn: http://taolap.net
![[OFF]](/assets/images/off.gif)