基于 ImgURL 1.x 的二次开发版本,主要变更:
1. 更名
- 项目定名为 TinyImg,源码中不再出现旧品牌字样(0 处)
- static/imgurl.js -> static/tinyimg.js
- db/imgurl-simple.db3 -> db/tinyimg-simple.db3
2. 移除 SM.MS 上传
- 删除 embed.js 中的 upload.render / smshow / deletesm
- miniup.html 去掉 SM.MS 选项卡;前台与后台导航移除入口
- sm.php、functions/sm.php、admin/smadmin.php 改为下线说明页
- admin/delete.php 移除 type=sm 分支;class.admin.php 删除 querysm()/deletesm()
3. 新增后台 Token 设置(admin/setting.php + functions/token.php)
- 生成 / 自定义 / 启用 / 停用 / 清空,全部校验 Session CSRF
- 存储于 db/tinyimg-token.php(首行 <?php exit; 守卫)
- config.php 的 api_token 仅作兼容回退,保存一次后由文件接管
- 完整 Token 不写入页面 HTML:默认只渲染掩码,点「显示/复制」时
经 POST action=reveal(同源 + CSRF + 仅登录会话)按需取回
4. 上传端点鉴权
- 统一使用 X-TinyImg-Token 请求头,hash_equals 比较,空配置 fail closed
- 新增 ?ping=1 自检,返回版本、鉴权方式、管理员目录,供写作插件测试连接
5. 版本号
- 统一为 v2.0.0(20261104),前后台页脚引用 functions/version.php
6. 兼容性修复
- class.upload.php 中 $size{...} 花括号下标改为 $size[...](PHP 8 已移除该语法)
7. 仓库整理
- .gitignore 排除 config.php / db/tinyimg-token.php / 运行时目录,
保留 db/.htaccess 与空模板 db/tinyimg-simple.db3
- .gitattributes 统一 LF
97 lines
2.1 KiB
PHP
97 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Tinify;
|
|
|
|
const VERSION = "1.5.2";
|
|
|
|
class Tinify {
|
|
private static $key = NULL;
|
|
private static $appIdentifier = NULL;
|
|
private static $proxy = NULL;
|
|
|
|
private static $compressionCount = NULL;
|
|
private static $client = NULL;
|
|
|
|
public static function setKey($key) {
|
|
self::$key = $key;
|
|
self::$client = NULL;
|
|
}
|
|
|
|
public static function setAppIdentifier($appIdentifier) {
|
|
self::$appIdentifier = $appIdentifier;
|
|
self::$client = NULL;
|
|
}
|
|
|
|
public static function setProxy($proxy) {
|
|
self::$proxy = $proxy;
|
|
self::$client = NULL;
|
|
}
|
|
|
|
public static function getCompressionCount() {
|
|
return self::$compressionCount;
|
|
}
|
|
|
|
public static function setCompressionCount($compressionCount) {
|
|
self::$compressionCount = $compressionCount;
|
|
}
|
|
|
|
public static function getClient() {
|
|
if (!self::$key) {
|
|
throw new AccountException("Provide an API key with Tinify\setKey(...)");
|
|
}
|
|
|
|
if (!self::$client) {
|
|
self::$client = new Client(self::$key, self::$appIdentifier, self::$proxy);
|
|
}
|
|
|
|
return self::$client;
|
|
}
|
|
|
|
public static function setClient($client) {
|
|
self::$client = $client;
|
|
}
|
|
}
|
|
|
|
function setKey($key) {
|
|
return Tinify::setKey($key);
|
|
}
|
|
|
|
function setAppIdentifier($appIdentifier) {
|
|
return Tinify::setAppIdentifier($appIdentifier);
|
|
}
|
|
|
|
function setProxy($proxy) {
|
|
return Tinify::setProxy($proxy);
|
|
}
|
|
|
|
function getCompressionCount() {
|
|
return Tinify::getCompressionCount();
|
|
}
|
|
|
|
function compressionCount() {
|
|
return Tinify::getCompressionCount();
|
|
}
|
|
|
|
function fromFile($path) {
|
|
return Source::fromFile($path);
|
|
}
|
|
|
|
function fromBuffer($string) {
|
|
return Source::fromBuffer($string);
|
|
}
|
|
|
|
function fromUrl($string) {
|
|
return Source::fromUrl($string);
|
|
}
|
|
|
|
function validate() {
|
|
try {
|
|
Tinify::getClient()->request("post", "/shrink");
|
|
} catch (AccountException $err) {
|
|
if ($err->status == 429) return true;
|
|
throw $err;
|
|
} catch (ClientException $err) {
|
|
return true;
|
|
}
|
|
}
|