![]() |
![]() ![]() ![]() |
3 năm trước | #1 |
Share code twig hiển thị thành viên online cho wap4
Chức năng của code là hiển thị người dùng đang online. Các bạn có thể mod thêm nhé.Demo: chính là site này, xem bên dưới foot thấy ai đang online, và online ở đâu nhé...
Tạo file online_input
{# config: time online (s) #}
{% set cookie_nick = '' %}
{% set svo = get_data('online_'~cookie_nick)[0].data %}
{% set time = "now"|date("U") %}
{% if cookie_nick %}
{% if svo %}
{{ update_data_by_id('online_'~cookie_nick,get_data('online_'~cookie_nick)[0].id,time) }}
{% else %}
{% set save_online = save_data('online_'~cookie_nick,time) %}
{% endif %}
{% set svu = get_data('online_where_'~cookie_nick)[0].data %}
{% if svu %}
{{ update_data_by_id('online_where_'~cookie_nick,get_data('online_where_'~cookie_nick)[0].id,where) }}
{% else %}
{% set save_online = save_data('online_where_'~cookie_nick,where) %}
{% endif %}
{% set lo = get_data_by_id('forum', mi[4]).data|trim|replace({' ':''})|lower %}
{% set lo2 = lo~'.' %}
{% set cookie_nick2 = '.'~cookie_nick~'.' %}
{% set lo_new = lo2|replace({(cookie_nick2):'.'}) %}
{% set lo_new = lo_new|slice(0,lo_new|length-1) %}
{{ update_data_by_id('forum',mi[4], '.'~cookie_nick~lo_new) }}
{% endif %}
Lưu ý: Bạn set biến cookie_nick chính là nick thành viên. Ví dụ chính là biến cookie của user.
Tạo file online_output chính là show ra danh sách người đang online.
{% set time = "now"|date("U") %}
{% set time_online = 300 %}
{% set list_on = get_data_by_id('forum', mi[4]).data|trim|replace({' ':''}) %}
{% set num_on = list_on|length-list_on|replace({'.':''})|length %}
{% set ur = list_on|split('.') %}
{% set list_online %}
{% for u in ur|keys %}
{% set check_online=get_data('online_'~ur[u])[0].data %}{% if (time-check_online)<=time_online %}<a href="/profile/{{ur[u]}}.html" style="color:{{function.UserColor(ur[u])}}" title="{{function.time(check_online)}}, ở {{get_data('online_where_'~ur[u])[0].data|raw|striptags}}">{{ur[u]}}</a> {% if u!=num_on %}, {% endif %}{% endif %}
{% endfor %}
{% endset %}
{% set list_online2 %}{% for u in ur|keys %}{% set check_online=get_data('online_'~ur[u])[0].data %}{% if (time-check_online)<=time_online and u>0 and ur[u] %}.{{ur[u]}}{% endif %}{% endfor %}{% endset %}
{{ update_data_by_id('forum',mi[4], list_online2) }}
{% set num_on = list_online2|length-list_online2|replace({'.':''})|length %}
<div class="phdr">{% if list_online2 %}{{num_on}} trực tuyến {% endif %} <a href="/member" title="Danh sách thành viên">{{(function.md_get_data('user_list_all')|length-function.md_get_data('user_list_all')|replace({'.':''})|length)}} thành viên</a></div><div class="online">{% if not list_online2 %}<center>Không có thành viên nào online.</center>{% else %}<center>{{list_online}}</center>{% endif %}</div>
Cách dùng:
{% set where='Trang chủ' %}
{% include'online_input' %}
{% include 'online_output' %}
Sau khi thêm code đó thì nó sẽ hiển thị ai đang online, biến where chính là hiển thị địa chỉ người dùng đang online.
Lưu ý: đoạn code trên có danh sách thành viên bên trong (tùy wap, đây là đối với wap mình) nên ai dùng code khác thì bỏ đoạn đếm thành viên đi.
Code này nhẹ nhàng nhé. Ai chưa hiểu có thể comment bên dưới để mình hướng dẫn kĩ hơn nhé!
Nguồn: mrducz95
admin đã chỉnh sửa, 3 năm trước [2]
3 bot, pupy, mikun