forked from tcdirectmail/tcdirectmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.tx_tcdirectmail_plain_simple.php
53 lines (43 loc) · 1.61 KB
/
class.tx_tcdirectmail_plain_simple.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class tx_tcdirectmail_plain_simple extends tx_tcdirectmail_plain {
var $fetchMethod = 'src';
function setHtml($html) {
$linkcount = 0;
$links = array();
$html = str_replace ("\n", '', $html);
$html = str_replace ("\r", '', $html);
$html = preg_replace ('|.*<body[^>]*>(.*)</body>.*|Ui', '\1', $html);
preg_match_all ('|<h([1-6])[^>]*>(.*)</h1>|Ui', $html, $match);
foreach ($match[0] as $i => $m) {
$fill = str_repeat('=', abs(7-$match[1][$i]));
$html = str_replace($m, "\n\n$fill ".strtoupper($match[2][$i])." $fill\n\n", $html);
}
$html = preg_replace ('|<b>(.*)</b>|Ui', '*\1*', $html);
$html = preg_replace ('|<strong>(.*)</strong>|Ui', '*\1*', $html);
preg_match_all ('|<a[^>]*href="(.*)"[^>]*>(.*)</a>|Ui', $html, $match);
foreach ($match[0] as $i => $m) {
$linkcount++;
$links[$linkcount] = $match[1][$i];
$html = str_replace($m, $match[2][$i]."[$linkcount]", $html);
}
$html = str_replace ('</p>', "\n", $html);
$html = str_replace ('<br>', "\n", $html);
$html = str_replace ('<br />', "\n", $html);
$html = str_replace ('</div>', "\n", $html);
$html = str_replace ('</tr>', "\n", $html);
$html = str_replace ('</table>', "\n", $html);
$html = strip_tags ($html);
$html = html_entity_decode ($html);
$html = preg_replace("|[ ]+\n|", "\n", $html);
$html = preg_replace("|\n{2,}|", "\n\n", $html);
$html = implode("\n", array_map('trim', explode("\n", $html)));
if ($linkcount > 0) {
$html .= "\nLinks:\n";
foreach ($links as $i => $link) {
$html .= " $i. $link\n";
}
}
$html = wordwrap($html, 72);
$this->plainText = trim($html);
}
}