From 3b22be94e8e18fedb22f15f2dff879bda172b8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9drix?= Date: Sat, 16 May 2026 10:56:43 +0200 Subject: [PATCH] =?UTF-8?q?feat=20:=20barre=20de=20partage=20articles=20+?= =?UTF-8?q?=20d=C3=A9duplication=20images=20upload=C3=A9es=20(v1.6.20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - post_view.php : barre de partage (mail, X, LinkedIn, Mastodon, copier, Web Share) sur articles publiés (#47) - share.js : logique clipboard + navigator.share sans script tiers, compatible CSP (#47) - addFile() : hardlink vers fichier identique si même hash16-size.ext dans un autre article (#35) Co-Authored-By: Claude Sonnet 4.6 --- CHANGELOG.md | 8 ++++++++ public/assets/js/share.js | 40 +++++++++++++++++++++++++++++++++++++++ public/version.txt | 2 +- src/ArticleManager.php | 11 ++++++++++- templates/layout.php | 3 +++ templates/post_view.php | 23 ++++++++++++++++++++++ 6 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 public/assets/js/share.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 8806ef3..69cf609 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ Format : [Keep a Changelog](https://keepachangelog.com/fr/1.0.0/) — versionnag --- +## [1.6.20] - 2026-05-16 + +### Ajouté +- Barre de partage sur les articles publiés : mail, X, LinkedIn, Mastodon, copie de lien, Web Share API mobile (#47) +- Déduplication des images uploadées par hardlink si même hash+taille existe déjà dans un autre article (#35) + +--- + ## [1.6.19] - 2026-05-16 ### Ajouté diff --git a/public/assets/js/share.js b/public/assets/js/share.js new file mode 100644 index 0000000..1ec196c --- /dev/null +++ b/public/assets/js/share.js @@ -0,0 +1,40 @@ +(function () { + 'use strict'; + + var bar = document.getElementById('share-bar'); + if (!bar) { return; } + + var url = bar.getAttribute('data-url') || window.location.href; + var title = bar.getAttribute('data-title') || document.title; + + var copyBtn = document.getElementById('share-copy'); + if (copyBtn) { + copyBtn.addEventListener('click', function () { + if (!navigator.clipboard) { + var ta = document.createElement('textarea'); + ta.value = url; + document.body.appendChild(ta); + ta.select(); + document.execCommand('copy'); + document.body.removeChild(ta); + copyBtn.textContent = 'Copié !'; + setTimeout(function () { copyBtn.textContent = 'Copier le lien'; }, 2000); + return; + } + navigator.clipboard.writeText(url).then(function () { + copyBtn.textContent = 'Copié !'; + setTimeout(function () { copyBtn.textContent = 'Copier le lien'; }, 2000); + }); + }); + } + + var nativeBtn = document.getElementById('share-native'); + if (nativeBtn) { + if (navigator.share) { + nativeBtn.hidden = false; + nativeBtn.addEventListener('click', function () { + navigator.share({ title: title, url: url }).catch(function () {}); + }); + } + } +}()); diff --git a/public/version.txt b/public/version.txt index e55f803..c45801e 100644 --- a/public/version.txt +++ b/public/version.txt @@ -1 +1 @@ -1.6.19 +1.6.20 diff --git a/src/ArticleManager.php b/src/ArticleManager.php index 9946ab9..405fd11 100644 --- a/src/ArticleManager.php +++ b/src/ArticleManager.php @@ -1197,7 +1197,16 @@ class ArticleManager $size = filesize($uploadedFile['tmp_name']); $name = "{$hash}-{$size}.{$ext}"; $dest = $dir . '/' . $name; - if (!rename($uploadedFile['tmp_name'], $dest) && !move_uploaded_file($uploadedFile['tmp_name'], $dest)) { + // Déduplication : si ce fichier identique existe déjà dans un autre article, crée un hardlink + if (!file_exists($dest)) { + $existing = glob($this->dataDir . '/*/files/' . $name); + if (!empty($existing) && is_file($existing[0])) { + link($existing[0], $dest) || copy($existing[0], $dest); + @unlink($uploadedFile['tmp_name']); + return $name; + } + } + if (!file_exists($dest) && !rename($uploadedFile['tmp_name'], $dest) && !move_uploaded_file($uploadedFile['tmp_name'], $dest)) { return null; } return $name; diff --git a/templates/layout.php b/templates/layout.php index 23abc9c..b50cc95 100644 --- a/templates/layout.php +++ b/templates/layout.php @@ -163,6 +163,9 @@ $_layoutCurrentCat = trim($_GET['cat'] ?? ''); + + + diff --git a/templates/post_view.php b/templates/post_view.php index 1f9ae0b..a90214a 100644 --- a/templates/post_view.php +++ b/templates/post_view.php @@ -261,6 +261,28 @@ $hasSources = (!empty($externalLinks) || !empty($files)) + + +
+ Partager : + ✉ Mail + X + in + 🐘 + + +
+ @@ -397,6 +419,7 @@ $hasSources = (!empty($externalLinks) || !empty($files))