Add support for [attach=config] (vB 5)
authorTim Düsterhus <tim@bastelstu.be>
Fri, 17 Jan 2020 17:51:47 +0000 (18:51 +0100)
committerTim Düsterhus <tim@bastelstu.be>
Fri, 17 Jan 2020 17:51:47 +0000 (18:51 +0100)
files/lib/system/exporter/VB5xExporter.class.php

index 9c7041f0ee4639d13b5e337bacc74efc8c5e1095..c8ad052a1ad7a20cfec1918aabf543c13cf6b3cf 100644 (file)
@@ -781,20 +781,31 @@ class VB5xExporter extends AbstractExporter {
                        $imgRegex = new Regex('\[img width=(\d+) height=\d+\](.*?)\[/img\]');
                        $mediaRegex = new Regex('\[video=([a-z]+);([a-z0-9-_]+)\]', Regex::CASE_INSENSITIVE);
                        
-                       $attachRegex = new Regex('\[attach=json\](\{.*?\})\[/attach\]', Regex::CASE_INSENSITIVE);
+                       $attachRegex = new Regex('\[attach=(?:json\](\{.*?\})|config\]([0-9]+))\[/attach\]', Regex::CASE_INSENSITIVE);
                        $attachCallback = function ($matches) {
-                               try {
-                                       $payload = JSON::decode($matches[1]);
+                               if (!empty($matches[1])) {
+                                       // json
+                                       try {
+                                               $payload = JSON::decode($matches[1]);
+                                       }
+                                       catch (SystemException $e) {
+                                               return '';
+                                       }
+                                       
+                                       if (empty($payload['data-attachmentid'])) {
+                                               return '';
+                                       }
+                                       
+                                       return "[attach]".$payload['data-attachmentid']."[/attach]";
                                }
-                               catch (SystemException $e) {
-                                       return '';
+                               else if (!empty($matches[2])) {
+                                       // config
+                                       return "[attach]".$matches[2]."[/attach]";
                                }
-                               
-                               if (empty($payload['data-attachmentid'])) {
-                                       return '';
+                               else {
+                                       // technically unreachable
+                                       return "";
                                }
-                               
-                               return "[attach]".$payload['data-attachmentid']."[/attach]";
                        };
                }