[LUA] Create, rename and get detail categories (forum) with lua for Wapka

Share your ideas & teach other
Post Reply
jesuisnk
Posts: 14
Joined: Mon May 06, 2024 11:06 pm

[LUA] Create, rename and get detail categories (forum) with lua for Wapka

Post by jesuisnk »

- Creator:

Code: Select all

-- CATEGORY
---- /api/Category/Creator.json
if url.map("/api/Category/Creator.json") then
    result = "false"
    msg = "Thao tác không hợp lệ"
    if (env.userid ~= 0) then
        if (req.method == "POST") then
            local param = {
                name = req.post.title
            }
            local title = param.name 
            if title then
                local title_length = string.len(title)
                if (title_length < 5 or title_length > 70) then
                    msg = "Độ dài tiêu đề chuyên mục không hợp lệ (min. 5, max. 70)"
                else
                    local is_ok = api.forum_create(param)
                    if is_ok then
                        result = "true"
                        msg = "Tạo chuyên mục thành công"
                    else
                        result = "false"
                        msg = "Đã xảy ra lỗi trong quá trình tạo chuyên mục"
                    end
                end
            end
        end
    end
    print('{ "result" : "' .. result .. '", "msg" : "' .. msg .. '" }')
end
- Rename: As same as create, param: name

Code: Select all

api.forum_edit({name:req.post.title})
- Detail:

Code: Select all

local check, detail, stats = api.forum_info({id=24715})
print(detail) --// return: [ { "name": "Technical Software", "parentid": 0, "id": 24715, "postnum": 0 } ]
print(stats) --// return: { "total": 1, "count": 1, "pagenum": 1 }
jesuisnk
Posts: 14
Joined: Mon May 06, 2024 11:06 pm

Re: [LUA] Create, rename and get detail categories (forum) with lua for Wapka

Post by jesuisnk »

Full code: List categories

DEMO:
Image


LUA:

Code: Select all

local cat_check, cat_check_list, cat_check_stats = api.forum_info()
cat_total = cat_check_stats['total']
local cat_check1, cat_list, cat_stats = api.forum_info({limit=cat_total})
table.insert(cat_list, 1, cat_list[0])
if tonumber(cat_total) > 0 then
    for loopindex, category in ipairs(cat_list) do
        print(string.format('<div class="danhmuc"><i class="fa fa-arrow-right" aria-hidden="true"></i> <a href="/category/%s-%s.html/">%s</a></div>', category['id'], slugVN(category['name']), category['name']))
    end
else
    print([[<div class="menu">Chưa có chuyên mục nào!</div>]])
end
Post Reply