[LUA] Article infomation with lua

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

[LUA] Article infomation with lua

Post by jesuisnk »

DEMO:
Image

URL: https://{yourdomain}/article/{post_id}-{post_slug}.html
Example:

Code: Select all

https://shared.wapka.top/article/70227-automation-studio-5-0-full-crack.html
LUA:

Code: Select all

include('jesuisnk')

local article = string.match(req.url, '/article/(%d+)')
if article then
    -- Get id's' article
    local parts = {}
    for part in string.gmatch(article, "%d+") do
        table.insert(parts, part)
    end
    local article_id = tonumber(parts[1])
    -- Get infomation's article
    local article_check, article_info, article_stats = api.post_info({id=article})
    if article_info[0]['id'] ~= article_id then
        url.redirect('/')
    end
    blog = article_info[0]
    category = blog['ForumInfo']
    thumbnail = string.match(blog['content'], "%[img%](.-)%[/img%]") or 'https://i.imgur.com/01T3Bxl.png'
    author = blog['UserInfo']
    print([[
    <script>document.title=']]..blog['title']..[['</script>
    <div class="phdr" itemscope itemtype="https://schema.org/BreadcrumbList">
        <i class="fa fa-spinner fa-pulse fa-fw"></i>
        <span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
            <a itemprop="item" href="/category/]]..category['id']..[[-]]..slugVN(category['name'])..[[.html/">
                <span itemprop="name">]]..category['name']..[[</span>
            </a>
            <meta itemprop="position" content="1" />
        </span>  » 
        <span itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">
            <a itemprop="item" href="/article/]]..blog['id']..[[-]]..slugVN(blog['title'])..[[.html/"></a>
            <span itemprop="name">]]..blog['title']..[[</span>
            <meta itemprop="position" content="2" />
        </span>
    </div>
    <div class="trithuc9x" style="border:1px solid #d5d5d5;padding:15px;padding-top:4px">
        <div style="float:left">
            <img src="]]..thumbnail..[[" title="]]..blog['title']..[[" alt="]]..blog['title']..[[" width="55" height="55" class="thumbnail"/>
        </div>
        <i class="fa fa-user"></i> Đăng bởi: <span style="color:red;font-weight:700" id="author">]]..author['username']..[[</span><br/>
        <i class="fa fa-clock-o"></i> ]]..blog['date']..[[</span><br/>
    </div>
    <div class="menu" style="text-align:justify;font-style:normal;padding:12px" id="content">
        ]]..bbcode(blog['content'])..[[
    </div>
    
    <div class="phdr"><i class="fa fa-share-alt"></i> Chia Sẻ</div>
    <div class="menu">
        <table style="width:100%">
            <tr>
                <td style="width:100%">
                    <input type="text" value="]]..req.url..[["/><br/>
                </td>
            </tr>
        </table>
    </div>
]])
end
Post Reply