1.1.3:兼容七牛 EXIF 包裹层,横排不再被顶掉
This commit is contained in:
24
.gitignore
vendored
Normal file
24
.gitignore
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# Runtime data, cache and logs
|
||||
data/
|
||||
cache/
|
||||
*.log
|
||||
|
||||
# Backups and temporary files
|
||||
备份/
|
||||
*.bak
|
||||
*.tmp
|
||||
.DS_Store
|
||||
|
||||
# Environment and secrets
|
||||
.env
|
||||
.env.*
|
||||
*key*.txt
|
||||
credentials*.json
|
||||
|
||||
# Editor and build artifacts
|
||||
.idea/
|
||||
.vscode/
|
||||
node_modules/
|
||||
vendor/
|
||||
dist/
|
||||
build/
|
||||
42
CHANGELOG.md
Normal file
42
CHANGELOG.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# FlexPhoto 更新日志
|
||||
|
||||
> 本文件记录本插件的所有修改与变化。仓库建立于 2026-12-03,此前历史见插件目录内的 `更新日志.MD`。
|
||||
|
||||
## 2026-12-03 · 1.1.3:兼容七牛 EXIF 包裹层,横排不再被顶掉
|
||||
|
||||
- 同步源码更新 2 个文件(新增/修改 2,删除 0)。
|
||||
|
||||
## 插件信息
|
||||
|
||||
- 名称:FlexPhoto(图片横排)
|
||||
- 版本:1.1.3
|
||||
- 作者:石头厝
|
||||
- 说明:正文里的多图等宽等高横排,配合 Fancybox 放大
|
||||
|
||||
## 记录格式约定
|
||||
|
||||
每次修改按如下格式在**最上方**追加一条记录(新的在上):
|
||||
|
||||
```
|
||||
## YYYY-MM-DD · 版本号 —— 一句话概述
|
||||
|
||||
- 改动点 1
|
||||
- 改动点 2
|
||||
- 影响范围 / 注意事项(若有)
|
||||
```
|
||||
|
||||
## 2026-12-03 · 1.1.3 —— 兼容第三方图片包裹层
|
||||
|
||||
- `style.css` 新增兼容层:`.flexphoto > .qiniu-exif-container` 与 `.flexphoto .flexphoto-link > .qiniu-exif-container` 都按 flex 子项处理,由包裹层承担 `--flexphoto-ratio` 比例、列宽与圆角裁切
|
||||
- 包裹层内的 `figure` 退化为「撑满即可」(`flex:1`、`width:auto`、`aspect-ratio:auto`),避免 4:3 被二次约束压扁高度
|
||||
- 包裹层内的 `img` 统一 `100% × 100% + object-fit:cover`,与原有缩略图裁切口径一致
|
||||
- 样式表引用加 `?20261203a` 防缓存
|
||||
- 纯 CSS 改动,不改 `buildPhotoItem()` 的结构产出;无包裹层时选择器不命中,原有排版不受影响
|
||||
|
||||
## 2026-11-22 · 1.1.2 —— 统一作者与链接
|
||||
|
||||
- `Plugin.php` 头部 `@author` 统一为「石头厝」,`@link` 统一为 `https://www.shitoucuo.com/`
|
||||
|
||||
## 2026-11-22 · 1.1.2 —— 建立规范化备份与更新日志
|
||||
|
||||
- 建立 `备份/` 文件夹与更新日志,作为后续修改的记录起点
|
||||
19
CONTRIBUTING.md
Normal file
19
CONTRIBUTING.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# 贡献指南
|
||||
|
||||
欢迎对本项目提出改进建议或提交代码。
|
||||
|
||||
## 提交前检查
|
||||
|
||||
- 仅提交插件实现代码、静态资源与必要文档;不要提交 `data/`、`cache/`、调试日志、备份目录或 API Key 等敏感信息。
|
||||
- 变更涉及 Typecho 钩子或 PHP 版本兼容时,请确认兼容 Typecho 1.3 与 PHP 8.5。
|
||||
- 影响用户配置或后台展示的改动,请同步更新 `README.md` 与 `CHANGELOG.md`。
|
||||
|
||||
## 提交流程
|
||||
|
||||
1. Fork 仓库并创建功能分支。
|
||||
2. 完成修改后提交 Pull Request,说明改动目的与影响范围。
|
||||
3. 重要变更请补充变更记录。
|
||||
|
||||
## 问题反馈
|
||||
|
||||
请通过仓库 Issue 反馈问题,并附上插件版本、Typecho / PHP 版本与复现步骤。
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 石头厝
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
139
Plugin.php
Normal file
139
Plugin.php
Normal file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||
/**
|
||||
* FlexPhoto图片并列排版工具
|
||||
*
|
||||
* @package FlexPhoto
|
||||
* @author XIGE
|
||||
* @version 1.1.2
|
||||
* @link https://www.sangushui.com/
|
||||
*/
|
||||
class FlexPhoto_Plugin implements Typecho_Plugin_Interface
|
||||
{
|
||||
/**
|
||||
* 激活插件方法,如果激活失败,直接抛出异常
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function activate()
|
||||
{
|
||||
Typecho_Plugin::factory('Widget_Archive')->header = array('FlexPhoto_Plugin', 'skinhead');
|
||||
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = array('FlexPhoto_Plugin','tutu');
|
||||
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = array('FlexPhoto_Plugin','tus');
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用插件方法,如果禁用失败,直接抛出异常
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws Typecho_Plugin_Exception
|
||||
*/
|
||||
public static function deactivate(){}
|
||||
|
||||
/**
|
||||
* 获取插件配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form 配置面板
|
||||
* @return void
|
||||
*/
|
||||
public static function config(Typecho_Widget_Helper_Form $form)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* 个人用户的配置面板
|
||||
*
|
||||
* @access public
|
||||
* @param Typecho_Widget_Helper_Form $form
|
||||
* @return void
|
||||
*/
|
||||
public static function personalConfig(Typecho_Widget_Helper_Form $form){}
|
||||
|
||||
public static function skinhead(){
|
||||
?>
|
||||
<link rel="stylesheet" href="<?php Helper::options()->pluginUrl(); ?>/FlexPhoto/style.css?20261111c">
|
||||
<?php
|
||||
}
|
||||
public static function tutu($data, $ojbk,$last)
|
||||
{
|
||||
$text = empty($last)?$data:$last;
|
||||
$text = self::parsePhotoSet($text);
|
||||
return $text;
|
||||
}
|
||||
static public function parsePhotoSet($content)
|
||||
{
|
||||
$regx = '/\{flex(.*?)}(.*?)\/flex\}/s';
|
||||
$new = preg_replace_callback($regx, array('FlexPhoto_Plugin', 'parsePhotoSetCallBack'), $content);
|
||||
$new = preg_replace_callback($regx, array('FlexPhoto_Plugin', 'parsePhotoSetCol'), $new);
|
||||
|
||||
$reg='/(<p>)?\{flex(.*?)\}(.*?)\{\/flex\}(<\/p>)?(<br>)?/s';
|
||||
|
||||
$rp = '<div${2}>${3}</div>';
|
||||
$new=preg_replace($reg, $rp, $new);
|
||||
return $new;
|
||||
}
|
||||
private static function parsePhotoSetCallBack($match)
|
||||
{
|
||||
$new='{flex'.$match[1].'}'. str_replace(['<br>', '<br/>', '<br />', '<p>', '</p>'], '', $match[2]) .'/flex}';
|
||||
|
||||
/* 逐个匹配 img 标签,保留原标签里的关键信息(data-src / alt),
|
||||
并自行生成 Fancybox 触发元素,避免依赖主题对 img 属性顺序的强制要求 */
|
||||
$new = preg_replace_callback('/<img\b[^>]*>/i', array('FlexPhoto_Plugin', 'buildPhotoItem'), $new);
|
||||
return $new;
|
||||
}
|
||||
|
||||
private static function buildPhotoItem($match)
|
||||
{
|
||||
$tag = $match[0];
|
||||
|
||||
$src = '';
|
||||
if (preg_match('/\bdata-src=["\']([^"\']+)["\']/i', $tag, $m)) {
|
||||
$src = trim($m[1]);
|
||||
} elseif (preg_match('/\bsrc=["\']([^"\']+)["\']/i', $tag, $m)) {
|
||||
$src = trim($m[1]);
|
||||
}
|
||||
if ($src === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$alt = preg_match('/\balt=["\']([^"\']*)["\']/i', $tag, $m) ? $m[1] : '';
|
||||
|
||||
// 先解码再编码,避免已转义的地址被二次转义
|
||||
$src = htmlspecialchars(html_entity_decode($src, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
|
||||
$alt = htmlspecialchars(html_entity_decode($alt, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, 'UTF-8');
|
||||
|
||||
return '<figure><a class="flexphoto-link" data-fancybox="gallery" href="'.$src.'" data-caption="'.$alt.'">'
|
||||
. '<img alt="'.$alt.'" src="'.$src.'" loading="lazy"></a></figure>';
|
||||
}
|
||||
private static function parsePhotoSetCol($match)
|
||||
{
|
||||
if(empty($match[1])){
|
||||
return '{flex class="flexphoto"}'.$match[2].'/flex}';
|
||||
}
|
||||
|
||||
preg_match_all('/<img\s*[^>]*>/i', $match[2], $matches);
|
||||
// 返回匹配到的数量
|
||||
$num = count($matches[0]);
|
||||
|
||||
$set = preg_replace('/(.*?)set="(.*?)"/', '$2', $match[1]);
|
||||
$set = explode(",", $set);
|
||||
$mobile = trim($set[0])==0 ? $num : trim($set[0]);
|
||||
$tablet = trim($set[1])==0 ? $num : trim($set[1]);
|
||||
$desktop = trim($set[2])==0 ? $num : trim($set[2]);
|
||||
|
||||
|
||||
return '{flex class="flexphoto diycol" style="--desktop-col: '.$desktop.'; --tablet-col: '.$tablet.'; --mobile-col: '.$mobile.';"}'.$match[2].'/flex}';
|
||||
}
|
||||
|
||||
public static function tus($text, $ojbk)
|
||||
{
|
||||
$text = str_replace('{flex}', '', $text);
|
||||
$text = str_replace('{/flex}', '', $text);
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
60
README.md
60
README.md
@@ -1,2 +1,60 @@
|
||||
# FlexPhoto
|
||||
# FlexPhoto(图片横排)
|
||||
|
||||
> 仓库:`FlexPhoto` · 类型:Typecho 插件 · 版本:`1.1.3` · 作者:石头厝
|
||||
|
||||
在正文里用一对标记把多张图片排成等宽等高的一行,点击用 Fancybox 放大。本仓库仅包含插件实现代码与必要文档,不包含备份目录与运行时数据。
|
||||
|
||||
## 用法
|
||||
|
||||
在正文里包住图片:
|
||||
|
||||
```
|
||||
{flex}
|
||||
<img src="a.jpg" alt="A">
|
||||
<img src="b.jpg" alt="B">
|
||||
<img src="c.jpg" alt="C">
|
||||
{/flex}
|
||||
```
|
||||
|
||||
指定各端列数(手机,平板,桌面,写 `0` 表示跟随图片数量):
|
||||
|
||||
```
|
||||
{flex set="2,2,3"}
|
||||
...
|
||||
{/flex}
|
||||
```
|
||||
|
||||
## 功能
|
||||
|
||||
- **等宽等高**:默认按 `4/3` 比例裁切,每排高度一致;比例由 `.flexphoto` 的 `--flexphoto-ratio` 一处控制
|
||||
- **响应式列数**:`set="手机,平板,桌面"` 通过 CSS 变量下发,1024px / 768px 两个断点切换
|
||||
- **Fancybox 集成**:每张图自行生成 `figure > a.flexphoto-link[data-fancybox=gallery]`,不依赖主题对 `img` 属性顺序的要求
|
||||
- **摘要清理**:`excerptEx` 里只剥掉标记,不在列表页输出横排结构
|
||||
- **包裹层兼容**:第三方插件若把 `<img>` 包了一层(如七牛的 EXIF 浮层),兼容层会让包裹元素充当 flex 子项,列宽与比例照旧
|
||||
|
||||
## 环境要求
|
||||
|
||||
- Typecho 1.3.0 及以上。
|
||||
- 主题需加载 Fancybox(本插件只生成触发属性,不自带脚本与依赖)。
|
||||
|
||||
## 安装与升级
|
||||
|
||||
1. 将本仓库目录上传到 `usr/plugins/FlexPhoto/`,在后台启用。
|
||||
2. 升级直接覆盖 `Plugin.php` 与 `style.css`;样式表引用带 `?20261203a` 防缓存参数,覆盖后无需手动清缓存。
|
||||
|
||||
## 兼容说明
|
||||
|
||||
- 与「七牛云存储」插件:七牛 2.9.1 起会跳过 `{flex}` 块、不在画廊内注入 EXIF 包裹层;本插件 1.1.3 起的兼容层则保证即使存在包裹层,横排也不会散架。两侧独立生效。
|
||||
- 与主题 ViewImage 灯箱:主题若对 `.markdown-body img` 绑定了灯箱,点击画廊缩略图可能同时触发 Fancybox 与灯箱,属已知现象,与本插件的排版无关。
|
||||
|
||||
## 开发与贡献
|
||||
|
||||
详见 [CONTRIBUTING.md](CONTRIBUTING.md)。
|
||||
|
||||
## 授权
|
||||
|
||||
授权条款见 [LICENSE](LICENSE)(MIT License)。
|
||||
|
||||
## 变更记录
|
||||
|
||||
详见 [CHANGELOG.md](CHANGELOG.md)。
|
||||
|
||||
58
style.css
Normal file
58
style.css
Normal file
@@ -0,0 +1,58 @@
|
||||
:root{
|
||||
--gap: 10px; /* 把间距也抽成变量,方便统一修改 */
|
||||
}
|
||||
.flexphoto {
|
||||
display: flex;
|
||||
gap: var(--gap); /* 使用变量统一控制间距 */
|
||||
flex-wrap: wrap;
|
||||
padding: 0;
|
||||
margin: 10px 0;
|
||||
/* 缩略图统一裁切比例:每排高度一致,改这里即可(如 3 / 2、16 / 9、1 / 1) */
|
||||
--flexphoto-ratio: 4 / 3;
|
||||
}
|
||||
.flexphoto figure {
|
||||
margin: 0 !important;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex; /* 让内部的 a 撑满整块,整行高度由 flex 拉伸统一 */
|
||||
aspect-ratio: var(--flexphoto-ratio); /* 统一比例,图片按 cover 裁切 */
|
||||
}
|
||||
/* 点击放大的触发层(Fancybox 绑定在 a.flexphoto-link 上) */
|
||||
.flexphoto .flexphoto-link,
|
||||
.flexphoto .flexphoto-link:hover {
|
||||
display: flex; /* 同时作为 img 的容器,让 img 拉伸填满 */
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
cursor: zoom-in;
|
||||
text-decoration: none; /* 屏蔽主题 a:hover 的点状下划线 */
|
||||
}
|
||||
.flexphoto figure img{
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
object-fit: cover;
|
||||
max-height: 100%;
|
||||
}
|
||||
|
||||
.flexphoto.diycol figure {
|
||||
flex: none;
|
||||
/* 正确计算宽度:100%均分 - 分摊的间距 */
|
||||
width: calc((100% / var(--col-num)) - (var(--gap) * (var(--col-num) - 1) / var(--col-num)));
|
||||
/* 关键:给figure设置最小高度,避免img的height:100%无参考 */
|
||||
}
|
||||
.flexphoto.diycol{
|
||||
--col-num: var(--desktop-col, 4);
|
||||
}
|
||||
|
||||
/* 平板端(≤1024px):读取data-tablet-col */
|
||||
@media (max-width: 1024px) {
|
||||
.flexphoto.diycol {
|
||||
--col-num: var(--tablet-col, 3);
|
||||
}
|
||||
}
|
||||
|
||||
/* 手机端(≤768px):读取data-mobile-col */
|
||||
@media (max-width: 768px) {
|
||||
.flexphoto.diycol {
|
||||
--col-num: var(--mobile-col, 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user