Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7165246
Add CI workflow for lbbs_dev branch
ytht Nov 11, 2025
dd4045b
设置不合并yml文件
ytht Nov 11, 2025
c0345b7
Add lbbs_dev branch to CI workflow
ytht Nov 11, 2025
f7a34bf
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 14, 2025
927ad82
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 16, 2025
649b302
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
eed0fed
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
919364e
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
3c58c8b
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 17, 2025
e576a07
增加 文章收录/移出文摘区 功能
ytht Nov 17, 2025
4eb5a15
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 19, 2025
d9e6bc0
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 20, 2025
e703e1e
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 21, 2025
fdbc07e
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 22, 2025
4633091
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 23, 2025
87535cc
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 23, 2025
8a27ea7
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 23, 2025
27dd4df
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 24, 2025
0dea966
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 26, 2025
9a31e02
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 27, 2025
608f8fb
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 27, 2025
c6299a4
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 28, 2025
5125da3
Merge branch 'leafok:main' into lbbs_dev
ytht Nov 30, 2025
a8f548b
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 2, 2025
66b558e
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 2, 2025
b391b41
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 4, 2025
f4b1df2
优化 文章收录/移出文摘区 功能
ytht Dec 4, 2025
fb8aca0
Merge branch 'lbbs_dev' of https://github.com/ytht/lbbs into lbbs_dev
ytht Dec 4, 2025
f97b252
优化 文章收录/移出文摘区 功能
ytht Dec 7, 2025
59cc0ba
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 17, 2025
769de21
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 19, 2025
049da93
Merge branch 'leafok:main' into lbbs_dev
ytht Dec 20, 2025
aacdade
优化 文章收录/移出文摘区 功能
ytht Dec 20, 2025
7aae77c
Merge pull request #75 from ytht/lbbs_dev
leafok88 Dec 20, 2025
303a76e
Remove unwanted change
leafok88 Dec 20, 2025
48e49b0
Refine logic to keep consistent with Web version
leafok88 Dec 20, 2025
ce90ba0
Remove unwanted change
leafok88 Dec 20, 2025
a52994c
Add required header file
leafok88 Dec 20, 2025
009dec1
Fix bug: checklevel2() should be called after load_user_info()
leafok88 Dec 21, 2025
db201f4
User with special privilege is not allowed to re-confirm EULA in plai…
leafok88 Dec 21, 2025
250e4f7
Refine
leafok88 Dec 22, 2025
a731472
Refact handling of cmdline arguments
leafok88 Dec 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/article_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#ifndef _ARTICLE_OP_H_
#define _ARTICLE_OP_H_

#include "section_list.h"
#include <stdint.h>

extern int display_article_meta(int32_t aid);
extern int article_excerption_set(SECTION_LIST *p_section, int32_t aid, int8_t set);

#endif //_ARTICLE_OP_H_
242 changes: 242 additions & 0 deletions src/article_op.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@

#include "article_op.h"
#include "bbs.h"
#include "database.h"
#include "io.h"
#include "log.h"
#include "screen.h"
#include "user_priv.h"
#include <stdlib.h>

int display_article_meta(int32_t aid)
{
Expand All @@ -26,3 +30,241 @@ int display_article_meta(int32_t aid)

return 0;
}

int article_excerption_set(SECTION_LIST *p_section, int32_t aid, int8_t set)
{
MYSQL *db = NULL;
MYSQL_RES *rs = NULL;
MYSQL_ROW row;
char sql[SQL_BUFFER_LEN];
int ret = 0;
int uid = 0;
int tid = 0;
int sid = 0;
int8_t transship = 0;
int8_t excerption = 0;

if (p_section == NULL)
{
log_error("NULL pointer error");
ret = -1;
goto cleanup;
}

if (set)
{
set = 1;
}

db = db_open();
if (db == NULL)
{
log_error("db_open() error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}

// Begin transaction
if (mysql_query(db, "SET autocommit=0") != 0)
{
log_error("SET autocommit=0 error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}

if (mysql_query(db, "BEGIN") != 0)
{
log_error("Begin transaction error: %s", mysql_error(db));
ret = -1;
goto cleanup;
}

snprintf(sql, sizeof(sql),
"SELECT UID, TID, SID, transship, excerption FROM bbs "
"WHERE AID = %d AND visible FOR UPDATE",
aid);
if (mysql_query(db, sql) != 0)
{
log_error("Query article error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}

if ((rs = mysql_store_result(db)) == NULL)
{
log_error("Get article data failed");
ret = -2;
goto cleanup;
}

if ((row = mysql_fetch_row(rs)))
{
uid = atoi(row[0]);
tid = atoi(row[1]);
sid = atoi(row[2]);
transship = (int8_t)atoi(row[3]);
excerption = (int8_t)atoi(row[4]);
}
else
{
log_error("Article not found: aid=%d", aid);
ret = -2;
goto cleanup;
}
mysql_free_result(rs);
rs = NULL;

if (p_section->sid != sid)
{
log_error("Inconsistent SID of article (aid=%d): %d!=%d", aid, p_section->sid, sid);
ret = -2;
goto cleanup;
}

// Check if already set
if (excerption != set)
{
snprintf(sql, sizeof(sql),
"UPDATE bbs SET excerption = %d WHERE AID = %d",
set, aid);
if (mysql_query(db, sql) != 0)
{
log_error("Set excerption error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}

// Clear gen_ex if unset excerption
if (set == 0)
{
snprintf(sql, sizeof(sql),
"UPDATE bbs SET gen_ex = 0, static = 0 WHERE AID = %d OR TID = %d",
aid, aid);

if (mysql_query(db, sql) != 0)
{
log_error("Set gen_ex error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}

// Delete ex_dir path if head of thread
if (tid == 0)
{
snprintf(sql, sizeof(sql),
"DELETE FROM ex_file WHERE AID = %d",
aid);

if (mysql_query(db, sql) != 0)
{
log_error("Delete ex_file error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}
}
}

// Change UID of attachments
snprintf(sql, sizeof(sql),
"UPDATE upload_file SET UID = %d "
"WHERE ref_AID = %d AND deleted = 0",
(set ? 0 : uid), aid);
if (mysql_query(db, sql) != 0)
{
log_error("Set attachment status error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}

// Modify exp
if (checkpriv(&BBS_priv, sid, S_GETEXP)) // Except in test section
{
snprintf(sql, sizeof(sql),
"UPDATE user_pubinfo SET exp = exp + %d WHERE UID = %d",
(set ? 1 : -1) * (tid == 0 ? (transship ? 20 : 50) : 10), uid);

if (mysql_query(db, sql) != 0)
{
log_error("Change exp error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}
}

// Add log
snprintf(sql, sizeof(sql),
"INSERT INTO bbs_article_op(AID, UID, type, op_dt, op_ip) "
"VALUES(%d, %d, '%c', NOW(), '%s')",
aid, BBS_priv.uid, (set ? 'E' : 'O'), hostaddr_client);

if (mysql_query(db, sql) != 0)
{
log_error("Add log error: %s", mysql_error(db));
ret = -2;
goto cleanup;
}
}

if (section_list_rw_lock(p_section) < 0)
{
log_error("section_list_rw_lock(sid=%d) error", sid);
ret = -3;
goto cleanup;
}

ret = section_list_set_article_excerption(p_section, aid, set);
if (ret < 0)
{
log_error("section_list_set_article_excerption(sid=%d, aid=%d, set=%d) error", sid, aid, set);
ret = -3;
goto cleanup;
}

if (section_list_rw_unlock(p_section) < 0)
{
log_error("section_list_rw_unlock(sid=%d) error", sid);
ret = -3;
goto cleanup;
}

// Commit transaction
if (mysql_query(db, "COMMIT") != 0)
{
log_error("Mysqli error: %s", mysql_error(db));

// Rollback change to avoid data inconsistency
if (section_list_rw_lock(p_section) < 0)
{
log_error("section_list_rw_lock(sid=%d) error", sid);
ret = -3;
goto cleanup;
}

ret = section_list_set_article_excerption(p_section, aid, excerption);
if (ret < 0)
{
log_error("section_list_set_article_excerption(sid=%d, aid=%d, set=%d) error", sid, aid, excerption);
ret = -3;
goto cleanup;
}

if (section_list_rw_unlock(p_section) < 0)
{
log_error("section_list_rw_unlock(sid=%d) error", sid);
ret = -3;
goto cleanup;
}

ret = 0;
}
else
{
ret = 1; // Success
}

cleanup:
mysql_free_result(rs);
mysql_close(db);

return ret;
}
Loading