### GET /api/stat.php - Get Website Statistics
Source: https://context7.com/crogram/sitehub/llms.txt
Retrieves comprehensive statistics about the website, including counts for categories, sites, pending applications, and top-ranked sites.
```APIDOC
## GET /api/stat.php
### Description
Retrieves comprehensive statistics about the website, including counts for categories, sites, pending applications, and top-ranked sites.
### Method
GET
### Endpoint
/api/stat.php
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **msg** (string) - General message, e.g., "网站统计".
- **data** (object) - An object containing various statistics:
- **build_time** (string) - The build or deployment time of the system.
- **category** (integer) - The total number of categories.
- **site** (integer) - The total number of sites listed.
- **apply** (integer) - The number of pending site applications.
- **apply_reject** (integer) - The number of rejected site applications.
- **article** (integer) - The total number of articles (if applicable).
- **article_category** (integer) - The number of article categories (if applicable).
- **notice** (integer) - The number of published notices.
- **link** (integer) - The number of friendship links.
- **top_hits_day** (object) - Details of the top site by hits today.
- **top_hits_month** (object) - Details of the top site by hits this month.
- **top_hits_total** (object) - Details of the top site by total hits.
- **top_like** (object) - Details of the site with the most likes.
#### Response Example
```json
{
"code": 0,
"msg": "网站统计",
"data": {
"build_time": "2024-01-01",
"category": 15,
"site": 256,
"apply": 12,
"apply_reject": 3,
"article": 45,
"article_category": 8,
"notice": 5,
"link": 20,
"top_hits_day": {"id": 1, "name": "热门站点A"},
"top_hits_month": {"id": 2, "name": "热门站点B"},
"top_hits_total": {"id": 3, "name": "热门站点C"},
"top_like": {"id": 4, "name": "最受欢迎站点"}
}
}
```
```
--------------------------------
### GET /favicon.php - Get Favicon
Source: https://context7.com/crogram/sitehub/llms.txt
Retrieves the Favicon for a given website URL. Supports automatic caching for up to 30 days.
```APIDOC
## GET /favicon.php
### Description
Retrieves the Favicon for a given website URL. Supports automatic caching (default 30 days).
### Method
GET
### Endpoint
/favicon.php?url={domain}
### Parameters
#### Query Parameters
- **url** (string) - Required - The domain name of the website for which to fetch the favicon (e.g., github.com).
### Request Example
```bash
curl -X GET "https://your-site.com/favicon.php?url=github.com" --output favicon.ico
```
### Alternative (Pretty URL)
- `GET /img/favicon/{domain}.png`
### Request Example (Pretty URL)
```html
```
### Response
#### Success Response (200)
- **Content-Type**: `image/x-icon`
- **Cache-Control**: `public, max-age=2592000` (30 days)
- **X-Powered-By**: `IconHub` (Indicates the service used)
*The response body will be the raw favicon data.*
```
--------------------------------
### Initialize Database Connection
Source: https://context7.com/crogram/sitehub/llms.txt
Configure and instantiate the PdoHelper database connection.
```php
// config.php 配置示例
$dbconfig = [
'host' => 'localhost',
'port' => 3306,
'user' => 'root',
'pwd' => 'password',
'dbname' => 'sitehub',
'prefix' => 'pre'
];
// 初始化数据库连接
require_once 'includes/autoloader.php';
Autoloader::register();
$DB = new \lib\PdoHelper($dbconfig);
```
--------------------------------
### Submit Site Application
Source: https://context7.com/crogram/sitehub/llms.txt
Submit a new site for review. The system validates existence to prevent duplicates.
```php
// POST /api/apply.php?act=form
// Content-Type: application/x-www-form-urlencoded
// 请求参数
$params = [
'name' => '示例网站', // 网站名称(必填)
'url' => 'https://example.com', // 网站链接(必填)
'catename' => '开发工具', // 网站分类(必填)
'keywords' => 'PHP,MySQL,开发', // 关键词(选填)
'introduce' => '这是一个示例网站' // 网站简介(必填)
];
// cURL 请求示例
curl -X POST "https://your-site.com/api/apply.php?act=form" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Referer: https://your-site.com" \
-d "name=示例网站&url=https://example.com&catename=开发工具&introduce=这是一个示例网站"
// 成功响应
{"code":0,"msg":"提交成功,请耐心等待审核!"}
// 失败响应示例
{"code":-1,"msg":"该站点已经存在,请勿重复提交!"}
{"code":-1,"msg":"网站网址不能为空!"}
{"code":403} // Referer 验证失败
```
--------------------------------
### Manage System Configuration and Accounts
Source: https://context7.com/crogram/sitehub/llms.txt
Update website settings and administrator credentials via the admin API.
```php
// 修改网站配置
// POST /admin/ajax.php?act=settings
$settings = [
'title' => '我的网址导航',
'keywords' => '网址导航,资源导航',
'description' => '一个优质的网址导航系统',
'script_header' => '',
'script_footer' => ''
];
curl -X POST "https://your-site.com/admin/ajax.php?act=settings" \
-H "Cookie: admin_token=xxx" \
-d "title=我的网址导航&keywords=网址导航"
// 响应: {"code":0,"msg":"保存成功"}
// 修改管理员账号密码
// POST /admin/ajax.php?act=account
$account = [
'admin_user' => 'newadmin', // 新用户名
'admin_pwd' => 'oldpassword', // 当前密码
'newpwd' => 'newpassword', // 新密码(选填)
'newpwd2' => 'newpassword' // 确认新密码(选填)
];
// 响应: {"code":0,"msg":"保存成功"}
```
--------------------------------
### Execute Raw SQL Queries
Source: https://context7.com/crogram/sitehub/llms.txt
Run custom SQL queries with parameter binding for security.
```php
// exec($sql, $params) - 执行语句
// query($sql, $params) - 查询语句
// getRow($sql, $params) - 获取单行
// getAll($sql, $params) - 获取所有行
// getColumn($sql, $params) - 获取单个字段值
// 参数化查询
$row = $DB->getRow(
"SELECT * FROM pre_site WHERE id = :id",
[':id' => 1]
);
$rows = $DB->getAll(
"SELECT * FROM pre_site WHERE catename = :cat ORDER BY id DESC LIMIT :limit",
[':cat' => '开发工具', ':limit' => 10]
);
// 获取单个值
$name = $DB->getColumn(
"SELECT name FROM pre_site WHERE id = :id",
[':id' => 1]
);
// 执行更新
$DB->exec(
"UPDATE pre_site SET hits_total = hits_total + 1 WHERE id = :id",
[':id' => 1]
);
```
--------------------------------
### POST /api/like.php - Like a Site
Source: https://context7.com/crogram/sitehub/llms.txt
Allows users to 'like' a specific site. Each IP address can only like a given site once.
```APIDOC
## POST /api/like.php
### Description
Allows users to 'like' a specific site. Each IP address can only like a given site once.
### Method
POST
### Endpoint
/api/like.php
### Parameters
#### Request Body
- **id** (integer) - Required - The ID of the site to like.
### Request Example
```
POST /api/like.php HTTP/1.1
Host: your-site.com
Content-Type: application/x-www-form-urlencoded
id=1
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **data** (integer) - The new like count for the site.
- **msg** (string) - Success message, e.g., "点赞成功".
#### Error Response
- **code** (integer) - -1 for client errors.
- **msg** (string) - Error message, e.g., "已经赞过了", "缺失ID".
#### Response Example (Success)
```json
{
"code": 0,
"data": 128,
"msg": "点赞成功"
}
```
#### Response Example (Failure)
```json
{
"code": -1,
"msg": "已经赞过了"
}
```
```
--------------------------------
### POST /api/apply.php - Submit Site Application
Source: https://context7.com/crogram/sitehub/llms.txt
Allows users to submit a new site application. The system checks for existing sites or previous applications to prevent duplicates.
```APIDOC
## POST /api/apply.php
### Description
Submit a new site application. The system validates against existing sites and previous submissions.
### Method
POST
### Endpoint
/api/apply.php?act=form
### Parameters
#### Query Parameters
- **act** (string) - Required - Must be 'form'.
#### Request Body
- **name** (string) - Required - The name of the website.
- **url** (string) - Required - The URL of the website.
- **catename** (string) - Required - The category name for the website.
- **keywords** (string) - Optional - Comma-separated keywords for the website.
- **introduce** (string) - Required - A brief introduction or description of the website.
### Request Example
```
POST /api/apply.php?act=form HTTP/1.1
Host: your-site.com
Content-Type: application/x-www-form-urlencoded
Referer: https://your-site.com
name=示例网站&url=https://example.com&catename=开发工具&keywords=PHP,MySQL,开发&introduce=这是一个示例网站
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **msg** (string) - Success message, e.g., "提交成功,请耐心等待审核!".
#### Error Response
- **code** (integer) - -1 for client errors, 403 for forbidden (e.g., Referer mismatch).
- **msg** (string) - Error message, e.g., "该站点已经存在,请勿重复提交!", "网站网址不能为空!".
#### Response Example (Success)
```json
{
"code": 0,
"msg": "提交成功,请耐心等待审核!"
}
```
#### Response Example (Failure)
```json
{
"code": -1,
"msg": "该站点已经存在,请勿重复提交!"
}
```
```
--------------------------------
### 执行数据库事务处理
Source: https://context7.com/crogram/sitehub/llms.txt
使用 beginTransaction、commit 和 rollBack 方法确保批量数据库操作的原子性。
```php
try {
$DB->beginTransaction();
// 批量操作
$DB->insert('site', ['name' => '站点1', 'url' => 'https://site1.com', ...]);
$DB->insert('site', ['name' => '站点2', 'url' => 'https://site2.com', ...]);
$DB->update('category', ['count' => '`count`+2'], ['id' => 1]);
$DB->commit();
} catch (Exception $e) {
$DB->rollBack();
echo "操作失败: " . $e->getMessage();
}
```
--------------------------------
### 配置 Nginx 伪静态规则
Source: https://context7.com/crogram/sitehub/llms.txt
将动态 PHP 页面映射为 SEO 友好的静态 URL 结构。
```nginx
# Nginx 配置示例
rewrite ^/index.html$ /index.php last;
rewrite ^/about.html$ /about.php last;
rewrite ^/search.html$ /search.php last;
rewrite ^/apply.html$ /apply.php last;
rewrite ^/category-([1-9]+[0-9]*).html$ /category.php?id=$1 last;
rewrite ^/category-([a-zA-Z]+).html$ /category.php?alias=$1 last;
rewrite ^/site-([1-9]+[0-9]*).html$ /site.php?id=$1 last;
rewrite ^/article-([1-9]+[0-9]*).html$ /article_show.php?id=$1 last;
rewrite ^/img/favicon/(.*)$ /favicon.php?url=$1 last;
```
--------------------------------
### Manage Site Application Requests
Source: https://context7.com/crogram/sitehub/llms.txt
Perform administrative actions on site applications such as rejecting, resetting, or deleting entries.
```php
// 拒绝申请(加入黑名单)
// POST /admin/apply_ajax.php?act=reject
curl -X POST "https://your-site.com/admin/apply_ajax.php?act=reject" \
-H "Cookie: admin_token=xxx" \
-d "id=1"
// 响应: {"code":0,"msg":"拒绝申请,放进黑名单成功!"}
// 恢复审核(从黑名单移出)
// POST /admin/apply_ajax.php?act=reset
curl -X POST "https://your-site.com/admin/apply_ajax.php?act=reset" \
-H "Cookie: admin_token=xxx" \
-d "id=1"
// 响应: {"code":0,"msg":"恢复审核申请成功!"}
// 删除申请
// POST /admin/apply_ajax.php?act=del
curl -X POST "https://your-site.com/admin/apply_ajax.php?act=del" \
-H "Cookie: admin_token=xxx" \
-d "id=1"
// 响应: {"code":0,"msg":"删除成功!"}
```
--------------------------------
### System Configuration Management API
Source: https://context7.com/crogram/sitehub/llms.txt
APIs for modifying website configurations and administrator account details.
```APIDOC
## POST /admin/ajax.php?act=settings
### Description
Modifies website configuration settings.
### Method
POST
### Endpoint
/admin/ajax.php?act=settings
### Parameters
#### Request Body
- **title** (string) - Optional - The title of the website.
- **keywords** (string) - Optional - Keywords for the website.
- **description** (string) - Optional - Description of the website.
- **script_header** (string) - Optional - Custom script to be included in the header.
- **script_footer** (string) - Optional - Custom script to be included in the footer.
### Request Example
```json
{
"title": "我的网址导航",
"keywords": "网址导航,资源导航",
"description": "一个优质的网址导航系统",
"script_header": "",
"script_footer": ""
}
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **msg** (string) - Success message.
#### Response Example
```json
{
"code": 0,
"msg": "保存成功"
}
```
## POST /admin/ajax.php?act=account
### Description
Modifies the administrator account username and password.
### Method
POST
### Endpoint
/admin/ajax.php?act=account
### Parameters
#### Request Body
- **admin_user** (string) - Optional - The new administrator username.
- **admin_pwd** (string) - Required - The current administrator password.
- **newpwd** (string) - Optional - The new administrator password.
- **newpwd2** (string) - Optional - Confirmation of the new administrator password.
### Request Example
```json
{
"admin_user": "newadmin",
"admin_pwd": "oldpassword",
"newpwd": "newpassword",
"newpwd2": "newpassword"
}
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **msg** (string) - Success message.
#### Response Example
```json
{
"code": 0,
"msg": "保存成功"
}
```
```
--------------------------------
### 获取 IP 地址与归属地
Source: https://context7.com/crogram/sitehub/llms.txt
通过 get_real_ip 获取真实客户端 IP,并使用 get_ip_city 查询地理位置。
```php
// get_real_ip($type) - 获取真实IP(支持代理)
$ip = get_real_ip(); // 自动检测(支持 CF、X-Real-IP 等)
// 获取 IP 归属地
$location = get_ip_city($ip); // 返回: "广东省深圳市"
```
--------------------------------
### Site Like Interface
Source: https://context7.com/crogram/sitehub/llms.txt
Increment the like count for a specific site. Limited to one like per IP address.
```php
// POST /api/like.php
// Content-Type: application/x-www-form-urlencoded
// 请求参数
$params = [
'id' => 1 // 站点ID(必填)
];
// cURL 请求示例
curl -X POST "https://your-site.com/api/like.php" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "id=1"
// 成功响应
{"code":0,"data":128,"msg":"点赞成功"}
// 失败响应
{"code":-1,"msg":"已经赞过了"}
{"code":-1,"msg":"缺失ID"}
```
--------------------------------
### Website Statistics Interface
Source: https://context7.com/crogram/sitehub/llms.txt
Retrieve comprehensive site statistics including counts for categories, sites, and applications.
```php
// GET /api/stat.php
// Content-Type: application/json
// cURL 请求示例
curl -X GET "https://your-site.com/api/stat.php"
// 响应示例
{
"code": 0,
"msg": "网站统计",
"data": {
"build_time": "2024-01-01",
"category": 15,
"site": 256,
"apply": 12,
"apply_reject": 3,
"article": 45,
"article_category": 8,
"notice": 5,
"link": 20,
"top_hits_day": {"id": 1, "name": "热门站点A"},
"top_hits_month": {"id": 2, "name": "热门站点B"},
"top_hits_total": {"id": 3, "name": "热门站点C"},
"top_like": {"id": 4, "name": "最受欢迎站点"}
}
}
```
--------------------------------
### Administrator Login
Source: https://context7.com/crogram/sitehub/llms.txt
Authenticate as an administrator. Supports a 'remember me' feature for up to 30 days.
```php
// POST /admin/login.php?act=login
// Content-Type: application/x-www-form-urlencoded
$params = [
'user' => 'admin', // 管理员用户名
'password' => '123456', // 管理员密码
'remember' => 1 // 记住登录(可选,1=30天,0=24小时)
];
// cURL 请求示例
curl -X POST "https://your-site.com/admin/login.php?act=login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "user=admin&password=123456&remember=1"
// 成功响应
{"code":0,"msg":"登录成功!"}
// 失败响应
{"code":-1,"msg":"用户名不能为空!"}
{"code":-1,"msg":"密码不能为空!"}
{"code":-1,"msg":"用户名或密码不正确!"}
```
--------------------------------
### Retrieve Backend Statistics
Source: https://context7.com/crogram/sitehub/llms.txt
Fetch summary data for the management dashboard.
```php
// GET /admin/ajax.php?act=stat
curl -X GET "https://your-site.com/admin/ajax.php?act=stat" \
-H "Cookie: admin_token=xxx"
// 响应示例
{
"code": 0,
"count": {
"category": 15,
"site": 256,
"apply": 12,
"apply_reject": 3,
"article": 45,
"article_category": 8,
"notice": 5,
"link": 20
}
}
```
--------------------------------
### Perform Statistical Queries
Source: https://context7.com/crogram/sitehub/llms.txt
Calculate counts and sums for database tables.
```php
// count($table, $where)
// sum($table, $field, $where)
// 统计总数
$total = $DB->count('site');
// 按条件统计
$pending = $DB->count('apply', ['reject' => 0]);
// 字符串条件
$count = $DB->count('site', "`alias`='example' AND `id`<>1");
// 求和
$totalHits = $DB->sum('site', 'hits_total');
$categoryHits = $DB->sum('site', 'hits_total', ['catename' => '开发工具']);
```
--------------------------------
### 执行加密解密与随机字符串生成
Source: https://context7.com/crogram/sitehub/llms.txt
使用 authcode 进行数据加解密,或使用 random 生成随机字符串。
```php
// authcode($string, $operation, $key, $expiry)
// 加密
$token = authcode("user\tsession\t" . time(), 'ENCODE', SYS_KEY);
// 解密
$data = authcode($token, 'DECODE', SYS_KEY);
list($user, $session, $expiry) = explode("\t", $data);
// 生成随机字符串
$code = random(6); // 6位字母数字混合
$code = random(6, 1); // 6位纯数字
```
--------------------------------
### Site Management Interface
Source: https://context7.com/crogram/sitehub/llms.txt
Perform CRUD operations on sites. Requires administrator authentication.
```php
// 添加站点
// POST /admin/site_ajax.php?act=add
$add_params = [
'lid' => 1, // 分类ID
'tui' => 0, // 是否推荐(0/1)
'star' => 5, // 星级评分
'name' => '新站点', // 站点名称
'img' => '/assets/images/logo.png', // 站点图标
'catename' => '开发工具', // 分类名称
'url' => 'https://example.com', // 站点URL
'alias' => 'example', // URL别名(选填)
'keywords' => 'PHP,开发', // 关键词
'introduce' => '站点简介' // 站点描述
];
// 编辑站点
// POST /admin/site_ajax.php?act=edit
$edit_params = array_merge(['id' => 1], $add_params);
// 删除站点
// POST /admin/site_ajax.php?act=del
curl -X POST "https://your-site.com/admin/site_ajax.php?act=del" \
-H "Cookie: admin_token=xxx" \
-d "id=1"
// 删除成功响应
{"code":0,"msg":"删除成功!"}
// 删除失败响应
{"code":-1,"msg":"ID不能为空!"}
{"code":-1,"msg":"删除失败!"}
```
--------------------------------
### 管理系统配置
Source: https://context7.com/crogram/sitehub/llms.txt
通过全局函数获取或保存系统设置。
```php
// getAllSetting() - 获取所有配置
// getSetting($key) - 获取单个配置
// saveSetting($key, $value) - 保存配置
$conf = getAllSetting();
echo $conf['title'];
$title = getSetting('title');
saveSetting('title', '新标题');
```
--------------------------------
### POST /admin/login.php - Admin Login
Source: https://context7.com/crogram/sitehub/llms.txt
Authenticates administrators for backend access. Supports a 'remember me' option for extended login sessions.
```APIDOC
## POST /admin/login.php
### Description
Authenticates administrators for backend access. Supports a 'remember me' option for extended login sessions.
### Method
POST
### Endpoint
/admin/login.php?act=login
### Parameters
#### Query Parameters
- **act** (string) - Required - Must be 'login'.
#### Request Body
- **user** (string) - Required - Administrator username.
- **password** (string) - Required - Administrator password.
- **remember** (integer) - Optional - Set to 1 for a 30-day session, 0 for a 24-hour session. Defaults to 24 hours if not provided or invalid.
### Request Example
```
POST /admin/login.php?act=login HTTP/1.1
Host: your-site.com
Content-Type: application/x-www-form-urlencoded
user=admin&password=123456&remember=1
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **msg** (string) - Success message, e.g., "登录成功!".
#### Error Response
- **code** (integer) - -1 for client errors.
- **msg** (string) - Error message, e.g., "用户名不能为空!", "密码不能为空!", "用户名或密码不正确!".
#### Response Example (Success)
```json
{
"code": 0,
"msg": "登录成功!"
}
```
#### Response Example (Failure)
```json
{
"code": -1,
"msg": "用户名或密码不正确!"
}
```
```
--------------------------------
### IIS Rewrite Rules for SiteHub
Source: https://github.com/crogram/sitehub/blob/main/README.md
Configure IIS URL Rewrite module for SiteHub. These rules map clean URLs to their corresponding PHP files and handle dynamic routing.
```xml
```
--------------------------------
### PdoHelper Database Operations
Source: https://context7.com/crogram/sitehub/llms.txt
Documentation for the PdoHelper class, detailing methods for database interaction.
```APIDOC
## Database Connection Configuration
### Description
Configuration example for establishing a database connection using PdoHelper.
### Code Example
```php
// config.php configuration example
$dbconfig = [
'host' => 'localhost',
'port' => 3306,
'user' => 'root',
'pwd' => 'password',
'dbname' => 'sitehub',
'prefix' => 'pre'
];
// Initialize database connection
require_once 'includes/autoloader.php';
Autoloader::register();
$DB = new \lib\PdoHelper($dbconfig);
```
## find()
### Description
Queries a single record from the database.
### Method Signature
`find($table, $fields, $where, $sort, $limit)`
### Parameters
- **table** (string) - The database table to query.
- **fields** (string|array) - The fields to retrieve. Use '*' for all fields.
- **where** (array|string) - Conditions for the query. Can be an associative array or a raw SQL string.
- **sort** (string) - The order to sort the results (e.g., 'id DESC').
- **limit** (integer|string) - The maximum number of records to return.
### Example Usage
```php
// Query a single site by ID
$site = $DB->find('site', '*', ['id' => 1]);
// Query specific fields
$site = $DB->find('site', 'id, name, url', ['id' => 1]);
// Query with sorting
$latest = $DB->find('site', '*', null, 'id DESC');
```
### Response Example
```json
{
"id": 1,
"name": "示例站点",
"url": "https://example.com",
...
}
```
## findAll()
### Description
Queries multiple records from the database.
### Method Signature
`findAll($table, $fields, $where, $sort, $limit)`
### Parameters
- **table** (string) - The database table to query.
- **fields** (string|array) - The fields to retrieve. Use '*' for all fields.
- **where** (array|string) - Conditions for the query. Can be an associative array or a raw SQL string.
- **sort** (string) - The order to sort the results (e.g., 'id DESC').
- **limit** (array|integer|string) - The limit and offset for pagination (e.g., `[0, 10]`).
### Example Usage
```php
// Query all sites
$sites = $DB->findAll('site', '*');
// Query sites by category name
$sites = $DB->findAll('site', '*', ['catename' => '开发工具']);
// Paginated query
$sites = $DB->findAll('site', '*', null, 'id DESC', [0, 10]);
// Query with complex conditions
$sites = $DB->findAll('site', '*', ['tui' => 1], 'hits_total DESC', 5);
```
## insert()
### Description
Inserts a new record into the database.
### Method Signature
`insert($table, $data)`
### Parameters
- **table** (string) - The database table to insert into.
- **data** (array) - An associative array of data to insert.
### Example Usage
```php
$data = [
'name' => '新站点',
'url' => 'https://example.com',
'catename' => '开发工具',
'introduce' => '站点描述',
'time' => 'NOW()', // Supports MySQL functions
'date' => 'CURDATE()'
];
$insertId = $DB->insert('site', $data);
if ($insertId) {
echo "插入成功,ID: " . $insertId;
}
```
### SQL Example
```sql
INSERT INTO pre_site (name, url, catename, introduce, time, date)
VALUES ('新站点', 'https://example.com', '开发工具', '站点描述', NOW(), CURDATE())
```
## update()
### Description
Updates existing records in the database.
### Method Signature
`update($table, $data, $where)`
### Parameters
- **table** (string) - The database table to update.
- **data** (array|string) - The data to update. Can be an associative array or a raw SQL string (e.g., for incrementing values).
- **where** (array|string) - Conditions for the update. Can be an associative array or a raw SQL string.
### Example Usage
```php
// Update with an associative array
$result = $DB->update('site',
['name' => '新名称', 'hits_total' => 100],
['id' => 1]
);
// Update with a raw SQL string (e.g., incrementing hits_total)
$result = $DB->update('site',
'`hits_total`=`hits_total`+1',
['id' => 1]
);
// Update with complex conditions
$result = $DB->update('site',
['tui' => 1],
['catename' => '开发工具']
);
```
## delete()
### Description
Deletes records from the database.
### Method Signature
`delete($table, $where)`
### Parameters
- **table** (string) - The database table to delete from.
- **where** (array|string) - Conditions for the deletion. Can be an associative array or a raw SQL string.
### Example Usage
```php
// Delete by ID
$result = $DB->delete('site', ['id' => 1]);
// Delete by condition
$result = $DB->delete('apply', ['reject' => 1]);
if ($result) {
echo "删除成功";
}
```
## count() and sum()
### Description
Performs aggregate queries (count and sum) on database tables.
### Method Signatures
`count($table, $where)`
`sum($table, $field, $where)`
### Parameters
- **table** (string) - The database table to query.
- **field** (string) - The field to perform the sum operation on (for `sum()` method).
- **where** (array|string) - Conditions for the query. Can be an associative array or a raw SQL string.
### Example Usage
```php
// Count total number of sites
$total = $DB->count('site');
// Count pending applications
$pending = $DB->count('apply', ['reject' => 0]);
// Count with string condition
$count = $DB->count('site', "`alias`='example' AND `id`<>1");
// Sum total hits
$totalHits = $DB->sum('site', 'hits_total');
// Sum hits for a specific category
$categoryHits = $DB->sum('site', 'hits_total', ['catename' => '开发工具']);
```
## Raw SQL Queries
### Description
Executes raw SQL queries using parameterized statements for safety.
### Method Signatures
`exec($sql, $params)` - Executes a query (e.g., UPDATE, DELETE).
`query($sql, $params)` - Executes a query and returns a statement object.
`getRow($sql, $params)` - Fetches a single row.
`getAll($sql, $params)` - Fetches all rows.
`getColumn($sql, $params)` - Fetches a single column from the result set.
### Parameters
- **sql** (string) - The SQL query string.
- **params** (array) - An associative array of parameters for the query (e.g., `[':id' => 1]`).
### Example Usage
```php
// Fetch a single row using named parameters
$row = $DB->getRow(
"SELECT * FROM pre_site WHERE id = :id",
[':id' => 1]
);
// Fetch all rows with a limit and ordering
$rows = $DB->getAll(
"SELECT * FROM pre_site WHERE catename = :cat ORDER BY id DESC LIMIT :limit",
[':cat' => '开发工具', ':limit' => 10]
);
// Fetch a single column value
$name = $DB->getColumn(
"SELECT name FROM pre_site WHERE id = :id",
[':id' => 1]
);
// Execute an update query
$DB->exec(
"UPDATE pre_site SET hits_total = hits_total + 1 WHERE id = :id",
[':id' => 1]
);
```
```
--------------------------------
### 处理 HTTP 请求与参数
Source: https://context7.com/crogram/sitehub/llms.txt
使用内置辅助函数获取请求参数并进行 XSS 过滤,或通过 cURL 封装进行远程请求。
```php
// _get($field, $default) - 获取 GET 参数(自动 XSS 过滤)
// _post($field, $default) - 获取 POST 参数(自动 XSS 过滤)
$id = _get('id'); // 获取 GET 参数
$id = _get('id', 0); // 带默认值
$name = _post('name', ''); // 获取 POST 参数
$all = _post(); // 获取所有 POST 参数
// cURL 请求封装
// get_curl($url, $post, $referer, $cookie, $header, $ua, $nobody)
$response = get_curl('https://api.example.com/data');
$response = get_curl('https://api.example.com/data', 'key=value', 'https://example.com');
```
--------------------------------
### Category Management Interface
Source: https://context7.com/crogram/sitehub/llms.txt
Manage site categories via add, edit, and delete operations.
```php
// 添加分类
// POST /admin/category_ajax.php?act=add
$params = [
'sid' => 1, // 排序ID
'icon' => 'fa-code', // Font Awesome 图标类名
'catename' => '开发工具', // 分类名称
'alias' => 'dev-tools' // 分类别名(选填)
];
// 编辑分类
// POST /admin/category_ajax.php?act=edit
$edit_params = array_merge(['id' => 1], $params);
// 删除分类
// POST /admin/category_ajax.php?act=del
curl -X POST "https://your-site.com/admin/category_ajax.php?act=del" \
-H "Cookie: admin_token=xxx" \
-d "id=1"
// 成功响应
{"code":0,"msg":"删除成功!"}
```
--------------------------------
### Admin Site Management API
Source: https://context7.com/crogram/sitehub/llms.txt
APIs for managing sites within the admin panel, including adding, editing, and deleting sites. Requires administrator authentication.
```APIDOC
## Admin Site Management
### Description
APIs for managing sites within the admin panel, including adding, editing, and deleting sites. Requires administrator authentication.
### Method
POST
### Endpoints
- Add Site: `/admin/site_ajax.php?act=add`
- Edit Site: `/admin/site_ajax.php?act=edit`
- Delete Site: `/admin/site_ajax.php?act=del`
### Parameters (Add/Edit)
#### Query Parameters
- **act** (string) - Required - 'add' or 'edit'.
#### Request Body (Add/Edit)
- **lid** (integer) - Required - Category ID.
- **tui** (integer) - Required - Recommendation status (0 or 1).
- **star** (integer) - Required - Star rating (e.g., 1-5).
- **name** (string) - Required - Site name.
- **img** (string) - Required - URL or path to the site's logo/icon.
- **catename** (string) - Required - Category name.
- **url** (string) - Required - The website URL.
- **alias** (string) - Optional - An alias for the URL.
- **keywords** (string) - Required - Comma-separated keywords.
- **introduce** (string) - Required - Site description.
- **id** (integer) - Required for 'edit' action - The ID of the site to edit.
### Parameters (Delete)
#### Query Parameters
- **act** (string) - Required - Must be 'del'.
#### Request Body (Delete)
- **id** (integer) - Required - The ID of the site to delete.
### Request Example (Delete)
```
POST /admin/site_ajax.php?act=del HTTP/1.1
Host: your-site.com
Content-Type: application/x-www-form-urlencoded
Cookie: admin_token=xxx
id=1
```
### Response
#### Success Response (200)
- **code** (integer) - 0 for success.
- **msg** (string) - Success message, e.g., "删除成功!".
#### Error Response
- **code** (integer) - -1 for client errors.
- **msg** (string) - Error message, e.g., "ID不能为空!", "删除失败!".
#### Response Example (Delete Success)
```json
{
"code": 0,
"msg": "删除成功!"
}
```
```
--------------------------------
### Favicon Retrieval Interface
Source: https://context7.com/crogram/sitehub/llms.txt
Fetch a site's favicon with automatic 30-day caching.
```php
// GET /favicon.php?url={domain}
// 或使用伪静态: GET /img/favicon/{domain}.png
// 请求示例
curl -X GET "https://your-site.com/favicon.php?url=github.com" --output favicon.ico
// 伪静态 URL 示例
// 响应头
// Content-type: image/x-icon
// Cache-Control: public, max-age=2592000
// X-Powered-By: IconHub
```
--------------------------------
### Nginx Rewrite Rules for SiteHub
Source: https://github.com/crogram/sitehub/blob/main/README.md
Configure Nginx to handle URL rewriting for SiteHub. These rules map friendly URLs to PHP scripts.
```nginx
rewrite ^/index.html$ /index.php last;
rewrite ^/about.html$ /about.php last;
rewrite ^/search.html$ /search.php last;
rewrite ^/ranking.html$ /ranking.php last;
rewrite ^/apply.html$ /apply.php last;
rewrite ^/404.html$ /404.php last;
rewrite ^/category-([1-9]+[0-9]*).html$ /category.php?id=$1 last;
rewrite ^/category-([a-zA-Z]+).html$ /category.php?alias=$1 last;
rewrite ^/site-([1-9]+[0-9]*).html$ /site.php?id=$1 last;
rewrite ^/article.html$ /article.php last;
rewrite ^/article-list-([1-9]+[0-9]*).html$ /article_list.php?id=$1 last;
rewrite ^/article-([1-9]+[0-9]*).html$ /article_show.php?id=$1 last;
rewrite ^/img/favicon/(.*)$ /favicon.php?url=$1 last;
rewrite ^/img/favicon/(.*).png$ /favicon.php?url=$1 last;
rewrite ^/img/preview/(.*).png$ /preview.php?url=$1 last;
location ~ "^/img/favicon/([^/]+)/?.png$" {
try_files /$uri /$uri/ /favicon.php?url=$1;
}
location ~ "^/img/preview/([^/]+)/?.png$" {
try_files /$uri /$uri/ /preview.php?url=$1;
}
```