summaryrefslogtreecommitdiff
path: root/replace-photos.php
diff options
context:
space:
mode:
Diffstat (limited to 'replace-photos.php')
-rw-r--r--replace-photos.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/replace-photos.php b/replace-photos.php
new file mode 100644
index 0000000..9715932
--- /dev/null
+++ b/replace-photos.php
@@ -0,0 +1,33 @@
+<?php
+
+require_once __DIR__.'/common.php';
+
+$file = $argv[1] ?? '';
+if (!$file)
+ fatalError("no file provided");
+
+$str = file_get_contents($file);
+$str = iconv('windows-1251', 'utf-8//IGNORE', $str);
+
+try {
+ $doc = onEachMessageOrAttachment($str,
+ null,
+ function (simplehtmldom\HtmlDocument $doc, string $href, simplehtmldom\HtmlNode $link_node) {
+ $local_href = '../../'.preg_replace('#^https?://#', '', $href);
+
+ /** @var simplehtmldom\HtmlNode $parent */
+ $parent = $link_node->parent();
+ $link_node->remove();
+
+ $img = $doc->createElement('img');
+ $img->setAttribute('src', $local_href);
+ $img->setAttribute('alt', $href);
+
+ $parent->appendChild($doc->createElement('br'));
+ $parent->appendChild($img);
+ });
+} catch (Exception $e) {
+ fatalError($e->getMessage());
+}
+
+file_put_contents($file, iconv('utf-8', 'windows-1251//IGNORE', $doc->outertext)); \ No newline at end of file