Convert HTML description to MD

pull/22/head
Alex Puiu 2022-04-13 13:31:54 +03:00
rodzic 82c869f6ba
commit 4c3f68a52c
7 zmienionych plików z 166 dodań i 7 usunięć

3
.gitignore vendored
Wyświetl plik

@ -1 +1,2 @@
config.php
config.php
vendor/

5
composer.json 100644
Wyświetl plik

@ -0,0 +1,5 @@
{
"require": {
"league/html-to-markdown": "^5.1"
}
}

108
composer.lock wygenerowano 100644
Wyświetl plik

@ -0,0 +1,108 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "55d22588d74c4cd2af8b00fa004ab06f",
"packages": [
{
"name": "league/html-to-markdown",
"version": "5.1.0",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/html-to-markdown.git",
"reference": "e0fc8cf07bdabbcd3765341ecb50c34c271d64e1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/e0fc8cf07bdabbcd3765341ecb50c34c271d64e1",
"reference": "e0fc8cf07bdabbcd3765341ecb50c34c271d64e1",
"shasum": ""
},
"require": {
"ext-dom": "*",
"ext-xml": "*",
"php": "^7.2.5 || ^8.0"
},
"require-dev": {
"mikehaertl/php-shellcommand": "^1.1.0",
"phpstan/phpstan": "^0.12.99",
"phpunit/phpunit": "^8.5 || ^9.2",
"scrutinizer/ocular": "^1.6",
"unleashedtech/php-coding-standard": "^2.7",
"vimeo/psalm": "^4.22"
},
"bin": [
"bin/html-to-markdown"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "5.2-dev"
}
},
"autoload": {
"psr-4": {
"League\\HTMLToMarkdown\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Colin O'Dell",
"email": "colinodell@gmail.com",
"homepage": "https://www.colinodell.com",
"role": "Lead Developer"
},
{
"name": "Nick Cernis",
"email": "nick@cern.is",
"homepage": "http://modernnerd.net",
"role": "Original Author"
}
],
"description": "An HTML-to-markdown conversion helper for PHP",
"homepage": "https://github.com/thephpleague/html-to-markdown",
"keywords": [
"html",
"markdown"
],
"support": {
"issues": "https://github.com/thephpleague/html-to-markdown/issues",
"source": "https://github.com/thephpleague/html-to-markdown/tree/5.1.0"
},
"funding": [
{
"url": "https://www.colinodell.com/sponsor",
"type": "custom"
},
{
"url": "https://www.paypal.me/colinpodell/10.00",
"type": "custom"
},
{
"url": "https://github.com/colinodell",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/league/html-to-markdown",
"type": "tidelift"
}
],
"time": "2022-03-02T17:24:08+00:00"
}
],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.1.0"
}

Wyświetl plik

@ -1,8 +1,10 @@
<?php
error_reporting(E_ERROR | E_PARSE);
require __DIR__ . '/vendor/autoload.php';
require_once("config.php");
require_once('lib/DeckClass.php');
require_once('lib/MailClass.php');
require_once('lib/ConvertToMD.php');
$inbox = new MailClass();
$emails = $inbox->getNewMessages();
@ -64,11 +66,16 @@ if ($emails)
$overview = $inbox->headerInfo($emails[$j]);
$board = null;
if(strstr($overview->to[0]->mailbox, '+')) {
$board = substr($overview->to[0]->mailbox, strpos($overview->to[0]->mailbox, '+') + 1);
if(strstr($board, '+')) $board = str_replace('+', ' ', $board);
}
if(isset($overview->{'X-Original-To'}) && strstr($overview->{'X-Original-To'}, '+')) {
$board = strstr(substr($overview->{'X-Original-To'}, strpos($overview->{'X-Original-To'}, '+') + 1), '@', true);
} else {
if(strstr($overview->to[0]->mailbox, '+')) {
$board = substr($overview->to[0]->mailbox, strpos($overview->to[0]->mailbox, '+') + 1);
}
};
if(strstr($board, '+')) $board = str_replace('+', ' ', $board);
$data = new stdClass();
$data->title = DECODE_SPECIAL_CHARACTERS ? mb_decode_mimeheader($overview->subject) : $overview->subject;
$data->type = "plain";
@ -82,6 +89,7 @@ if ($emails)
if($base64encode) {
$description = base64_decode($description);
}
$description = (new ConvertToMD($description))->execute();
$data->description = $description;
$mailSender = new stdClass();
$mailSender->userId = $overview->reply_to[0]->mailbox;

Wyświetl plik

@ -0,0 +1,22 @@
<?php
use League\HTMLToMarkdown\HtmlConverter;
class ConvertToMD {
protected $html;
public function __construct($html) {
$this->converter = new HtmlConverter([
'strip_tags' => true,
'remove_nodes' => 'title'
]);
$this->html = $html;
}
public function execute()
{
return $this->converter->convert($this->html);
}
}
?>

Wyświetl plik

@ -47,6 +47,7 @@ class DeckClass {
}
$boards = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards");
$boardId = $boardName = null;
foreach($boards as $board) {
if(strtolower($board->title) == strtolower($boardFromMail)) {
if(!$this->checkBotPermissions($board)) {

Wyświetl plik

@ -27,7 +27,21 @@ class MailClass {
}
public function headerInfo($email) {
return imap_headerinfo($this->inbox, $email);
$headerInfo = imap_headerinfo($this->inbox, $email);
$additionalHeaderInfo = imap_fetchheader($this->inbox, $email);
$infos = explode("\n", $additionalHeaderInfo);
foreach($infos as $info) {
$data = explode(":", $info);
if( count($data) == 2 && !isset($head[$data[0]])) {
if(trim($data[0]) === 'X-Original-To') {
$headerInfo->{'X-Original-To'} = trim($data[1]);
break;
}
}
}
return $headerInfo;
}
public function reply($sender, $response = null) {