Add checks for inbound email filter columns

This commit is contained in:
David Bomba 2025-01-28 05:36:27 +11:00
parent aea0236068
commit d441665e98
5 changed files with 222 additions and 136 deletions

View File

@ -1993,34 +1993,44 @@ class PdfBuilder
return $element; return $element;
} }
private function isMarkdown(string $content): bool
{
$content = str_ireplace('<br>', "\n", $content);
$markdownPatterns = [
'/^\s*#{1,6}\s/m', // Headers
'/^\s*[-+*]\s/m', // Lists
'/\[.*?\]\(.*?\)/', // Links
'/!\[.*?\]\(.*?\)/', // Images
'/\*\*.*?\*\*/', // Bold
'/\*.*?\*/', // Italic
'/__.*?__/', // Bold
'/_.*?_/', // Italic
'/`.*?`/', // Inline code
'/^\s*>/m', // Blockquotes
'/^\s*```/m', // Code blocks
];
// Check if any pattern matches the text
foreach ($markdownPatterns as $pattern) {
if (preg_match($pattern, $content)) {
return true;
}
}
return false;
}
public function createElementContent($element, $children): self public function createElementContent($element, $children): self
{ {
foreach ($children as $child) { foreach ($children as $child) {
$contains_html = false; $contains_html = false;
$contains_markdown = false;
$child['content'] = $child['content'] ?? ''; $child['content'] = $child['content'] ?? '';
$lines = explode("\n", $child['content']); if ($this->service->company->markdown_enabled && $this->isMarkdown($child['content']) && $child['element'] !== 'script') {
$contains_markdown = false;
foreach ($lines as $line) {
$trimmed = ltrim($line);
if (empty($trimmed)) {
continue;
}
$first_char = substr($trimmed, 0, 1);
if (in_array($first_char, ['#', '>', '-', '+', '*', '_', '`', '[']) || // Markdown characters
str_contains($trimmed, '**') // Bold (special case)
) {
$contains_markdown = true;
break;
}
}
if ($this->service->company->markdown_enabled && $contains_markdown && $child['element'] !== 'script') {
$child['content'] = str_ireplace('<br>', "\r", $child['content']); $child['content'] = str_ireplace('<br>', "\r", $child['content']);
$child['content'] = $this->commonmark->convert($child['content']); //@phpstan-ignore-line $child['content'] = $this->commonmark->convert($child['content']); //@phpstan-ignore-line
} }

View File

@ -87,34 +87,43 @@ trait PdfMakerUtilities
return $element; return $element;
} }
private function isMarkdown(string $content): bool
{
$content = str_ireplace('<br>', "\n", $content);
$markdownPatterns = [
'/^\s*#{1,6}\s/m', // Headers
'/^\s*[-+*]\s/m', // Lists
'/\[.*?\]\(.*?\)/', // Links
'/!\[.*?\]\(.*?\)/', // Images
'/\*\*.*?\*\*/', // Bold
'/\*.*?\*/', // Italic
'/__.*?__/', // Bold
'/_.*?_/', // Italic
'/`.*?`/', // Inline code
'/^\s*>/m', // Blockquotes
'/^\s*```/m', // Code blocks
];
// Check if any pattern matches the text
foreach ($markdownPatterns as $pattern) {
if (preg_match($pattern, $content)) {
return true;
}
}
return false;
}
public function createElementContent($element, $children) public function createElementContent($element, $children)
{ {
foreach ($children as $child) { foreach ($children as $child) {
$contains_html = false; $contains_html = false;
$contains_markdown = false;
$child['content'] = $child['content'] ?? ''; $child['content'] = $child['content'] ?? '';
$lines = explode("\n", $child['content']); if (isset($this->data['process_markdown']) && $this->data['process_markdown'] && $this->isMarkdown($child['content']) && $child['element'] !== 'script') {
$contains_markdown = false;
foreach ($lines as $line) {
$trimmed = ltrim($line);
if (empty($trimmed)) {
continue;
}
$first_char = substr($trimmed, 0, 1);
if (
in_array($first_char, ['#', '>', '-', '+', '*', '_', '`', '[']) || // Markdown characters
str_contains($trimmed, '**') // Bold (special case)
) {
$contains_markdown = true;
break;
}
}
if (isset($this->data['process_markdown']) && $this->data['process_markdown'] && $contains_markdown &&$child['element'] !== 'script') {
$child['content'] = str_replace('<br>', "\r", $child['content']); $child['content'] = str_replace('<br>', "\r", $child['content']);
$child['content'] = $this->commonmark->convert($child['content']); //@phpstan-ignore-line $child['content'] = $this->commonmark->convert($child['content']); //@phpstan-ignore-line
} }

View File

@ -37,7 +37,7 @@
"ext-json": "*", "ext-json": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-simplexml": "*", "ext-simplexml": "*",
"afosto/yaac": "^1.4", "afosto/yaac": "^1.5",
"asm/php-ansible": "dev-main", "asm/php-ansible": "dev-main",
"authorizenet/authorizenet": "^2.0", "authorizenet/authorizenet": "^2.0",
"awobaz/compoships": "^2.1", "awobaz/compoships": "^2.1",
@ -64,6 +64,7 @@
"hyvor/php-json-exporter": "^0.0.3", "hyvor/php-json-exporter": "^0.0.3",
"imdhemy/laravel-purchases": "^1.7", "imdhemy/laravel-purchases": "^1.7",
"intervention/image": "^2.5", "intervention/image": "^2.5",
"invoiceninja/admin-api": "dev-main",
"invoiceninja/einvoice": "dev-main", "invoiceninja/einvoice": "dev-main",
"invoiceninja/inspector": "^3.0", "invoiceninja/inspector": "^3.0",
"invoiceninja/ubl_invoice": "^2", "invoiceninja/ubl_invoice": "^2",
@ -222,6 +223,10 @@
{ {
"type": "vcs", "type": "vcs",
"url": "https://github.com/turbo124/snappdf" "url": "https://github.com/turbo124/snappdf"
},
{
"type": "path",
"url": "../admin-api"
} }
], ],
"minimum-stability": "dev", "minimum-stability": "dev",

245
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "0fd554859df6ddb888c01b8ea86ac68b", "content-hash": "85d7d0f33ab492d51d6a34782e4ee826",
"packages": [ "packages": [
{ {
"name": "adrienrn/php-mimetyper", "name": "adrienrn/php-mimetyper",
@ -1400,6 +1400,85 @@
], ],
"time": "2025-01-08T16:17:16+00:00" "time": "2025-01-08T16:17:16+00:00"
}, },
{
"name": "composer/pcre",
"version": "3.3.2",
"source": {
"type": "git",
"url": "https://github.com/composer/pcre.git",
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0"
},
"conflict": {
"phpstan/phpstan": "<1.11.10"
},
"require-dev": {
"phpstan/phpstan": "^1.12 || ^2",
"phpstan/phpstan-strict-rules": "^1 || ^2",
"phpunit/phpunit": "^8 || ^9"
},
"type": "library",
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
},
"branch-alias": {
"dev-main": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Pcre\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
"keywords": [
"PCRE",
"preg",
"regex",
"regular expression"
],
"support": {
"issues": "https://github.com/composer/pcre/issues",
"source": "https://github.com/composer/pcre/tree/3.3.2"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2024-11-12T16:29:46+00:00"
},
{ {
"name": "dasprid/enum", "name": "dasprid/enum",
"version": "1.0.6", "version": "1.0.6",
@ -2953,16 +3032,16 @@
}, },
{ {
"name": "google/apiclient-services", "name": "google/apiclient-services",
"version": "v0.391.0", "version": "v0.392.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/googleapis/google-api-php-client-services.git", "url": "https://github.com/googleapis/google-api-php-client-services.git",
"reference": "911ebf7a6b570780fb994c007344cf3da4187de6" "reference": "a74c2790865bd1f06c0a49460ef1c0edb0be0e7e"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/911ebf7a6b570780fb994c007344cf3da4187de6", "url": "https://api.github.com/repos/googleapis/google-api-php-client-services/zipball/a74c2790865bd1f06c0a49460ef1c0edb0be0e7e",
"reference": "911ebf7a6b570780fb994c007344cf3da4187de6", "reference": "a74c2790865bd1f06c0a49460ef1c0edb0be0e7e",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2991,9 +3070,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/googleapis/google-api-php-client-services/issues", "issues": "https://github.com/googleapis/google-api-php-client-services/issues",
"source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.391.0" "source": "https://github.com/googleapis/google-api-php-client-services/tree/v0.392.0"
}, },
"time": "2025-01-20T01:04:13+00:00" "time": "2025-01-27T01:10:20+00:00"
}, },
{ {
"name": "google/auth", "name": "google/auth",
@ -4432,6 +4511,65 @@
], ],
"time": "2022-05-21T17:30:32+00:00" "time": "2022-05-21T17:30:32+00:00"
}, },
{
"name": "invoiceninja/admin-api",
"version": "dev-main",
"dist": {
"type": "path",
"url": "../admin-api",
"reference": "d81eee08da4003cfa893a23cd02694d885a37af7"
},
"require": {
"afosto/yaac": "^1.5",
"asm/php-ansible": "dev-main",
"ext-curl": "*",
"ext-dom": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"illuminate/database": "^11",
"illuminate/support": "^11",
"imdhemy/laravel-purchases": "^1.7",
"php": "^8.2|^8.3|^8.4"
},
"require-dev": {
"larastan/larastan": "^3.0",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^11.0"
},
"type": "library",
"extra": {
"laravel": {
"providers": [
"InvoiceNinja\\AdminApi\\Providers\\AdminApiServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"InvoiceNinja\\AdminApi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"InvoiceNinja\\AdminApi\\Tests\\": "tests/"
}
},
"license": [
"Elastic"
],
"authors": [
{
"name": "David Bomba",
"email": "turbo124@gmail.com"
}
],
"description": "API endpoints for the admin interface",
"transport-options": {
"relative": true
}
},
{ {
"name": "invoiceninja/einvoice", "name": "invoiceninja/einvoice",
"version": "dev-main", "version": "dev-main",
@ -9459,19 +9597,20 @@
}, },
{ {
"name": "phpoffice/phpspreadsheet", "name": "phpoffice/phpspreadsheet",
"version": "2.3.6", "version": "2.3.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/PHPOffice/PhpSpreadsheet.git", "url": "https://github.com/PHPOffice/PhpSpreadsheet.git",
"reference": "098b848ee6688cb9a252d9ce97889defc517ee88" "reference": "cf357183b1d17a3862e8e4b9b056a556654dcae6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/098b848ee6688cb9a252d9ce97889defc517ee88", "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/cf357183b1d17a3862e8e4b9b056a556654dcae6",
"reference": "098b848ee6688cb9a252d9ce97889defc517ee88", "reference": "cf357183b1d17a3862e8e4b9b056a556654dcae6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"composer/pcre": "^3.2",
"ext-ctype": "*", "ext-ctype": "*",
"ext-dom": "*", "ext-dom": "*",
"ext-fileinfo": "*", "ext-fileinfo": "*",
@ -9557,9 +9696,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues", "issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues",
"source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/2.3.6" "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/2.3.7"
}, },
"time": "2025-01-12T03:22:26+00:00" "time": "2025-01-26T04:53:06+00:00"
}, },
{ {
"name": "phpoption/phpoption", "name": "phpoption/phpoption",
@ -17498,85 +17637,6 @@
], ],
"time": "2024-11-25T16:11:06+00:00" "time": "2024-11-25T16:11:06+00:00"
}, },
{
"name": "composer/pcre",
"version": "3.3.2",
"source": {
"type": "git",
"url": "https://github.com/composer/pcre.git",
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/pcre/zipball/b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
"reference": "b2bed4734f0cc156ee1fe9c0da2550420d99a21e",
"shasum": ""
},
"require": {
"php": "^7.4 || ^8.0"
},
"conflict": {
"phpstan/phpstan": "<1.11.10"
},
"require-dev": {
"phpstan/phpstan": "^1.12 || ^2",
"phpstan/phpstan-strict-rules": "^1 || ^2",
"phpunit/phpunit": "^8 || ^9"
},
"type": "library",
"extra": {
"phpstan": {
"includes": [
"extension.neon"
]
},
"branch-alias": {
"dev-main": "3.x-dev"
}
},
"autoload": {
"psr-4": {
"Composer\\Pcre\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jordi Boggiano",
"email": "j.boggiano@seld.be",
"homepage": "http://seld.be"
}
],
"description": "PCRE wrapping library that offers type-safe preg_* replacements.",
"keywords": [
"PCRE",
"preg",
"regex",
"regular expression"
],
"support": {
"issues": "https://github.com/composer/pcre/issues",
"source": "https://github.com/composer/pcre/tree/3.3.2"
},
"funding": [
{
"url": "https://packagist.com",
"type": "custom"
},
{
"url": "https://github.com/composer",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/composer/composer",
"type": "tidelift"
}
],
"time": "2024-11-12T16:29:46+00:00"
},
{ {
"name": "composer/semver", "name": "composer/semver",
"version": "3.4.3", "version": "3.4.3",
@ -21210,6 +21270,7 @@
"asm/php-ansible": 20, "asm/php-ansible": 20,
"beganovich/snappdf": 20, "beganovich/snappdf": 20,
"horstoeko/orderx": 20, "horstoeko/orderx": 20,
"invoiceninja/admin-api": 20,
"invoiceninja/einvoice": 20, "invoiceninja/einvoice": 20,
"socialiteproviders/apple": 20 "socialiteproviders/apple": 20
}, },

View File

@ -6,6 +6,7 @@ parameters:
level: 5 level: 5
paths: paths:
- app - app
- vendor/invoiceninja/admin-api
- Modules - Modules
excludePaths: excludePaths:
analyseAndScan: analyseAndScan: