From f736789f5b2eea87180e0ca64f32f4792cb27445 Mon Sep 17 00:00:00 2001 From: troy Date: Sat, 9 Oct 2021 13:44:04 +0200 Subject: [PATCH] . --- mail.php | 5 +--- markdown.php | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 markdown.php diff --git a/mail.php b/mail.php index cfe8c02..56d40a6 100644 --- a/mail.php +++ b/mail.php @@ -5,15 +5,12 @@ function send_mail($an, $betreff, $text, $ok = '', $error = '') { if (isset ( $_sendermail )) { $sender = $_sendermail; } - if (is_array ( $text )) { - $text = print_r ( $text, true ); - } $header = 'From: ' . $sender . "\r\n"; $header .= 'To: ' . $an . "\r\n"; $header .= 'Content-Type:text/html' . "\r\n"; $header .= 'Content-Transfer-Encoding: 8bit' . "\r\n"; $header .= 'X-Mailer: PHP/' . phpversion (); - + if (mail ( $an, $betreff, $text, $header ) === true) { echo $ok; } else { diff --git a/markdown.php b/markdown.php new file mode 100644 index 0000000..0d90701 --- /dev/null +++ b/markdown.php @@ -0,0 +1,84 @@ +'; + $lv = 0; + $str = explode ( "\n", str_replace ( "\r\n", "\n", $str ) ); + // var_dump ( $str ); + foreach ( $str as $t ) { + // echo '
' . $t . '
'; + $t = preg_replace_callback ( '/\[\[([^\]]*)\]\]/m', '_md_link_replacer', $t ); + $nlv = 0; + if (startsWith ( $t, '**** ' )) { + // echo - 1; + $t = substr ( $t, 5 ); + $nlv = 4; + } + if (startsWith ( $t, '*** ' )) { + // echo - 2; + $t = substr ( $t, 4 ); + $nlv = 3; + } + if (startsWith ( $t, '** ' )) { + // echo - 3; + $t = substr ( $t, 3 ); + $nlv = 2; + } + if (startsWith ( $t, '* ' )) { + // echo - 4; + $t = substr ( $t, 2 ); + $nlv = 1; + } + if ($lv != $nlv) { + while ( $lv < $nlv ) { + // echo '-5 (' . $lv . '-' . $nlv . ')'; + $text .= ''; + $lv --; + } + } + if (startsWith ( $t, '!!!!! ' )) { + $t = '
' . substr ( $t, 6 ) . '
'; + } + if (startsWith ( $t, '!!!! ' )) { + $t = '

' . substr ( $t, 5 ) . '

'; + } + if (startsWith ( $t, '!!! ' )) { + $t = '

' . substr ( $t, 4 ) . '

'; + } + if (startsWith ( $t, '!! ' )) { + $t = '

' . substr ( $t, 3 ) . '

'; + } + if (startsWith ( $t, '! ' )) { + $t = '

' . substr ( $t, 2 ) . '

'; + } + if ($lv == 0) { + if ($t == '') { + $text .= '

'; + } else { + $text .= $t; + } + } else { + $text .= '

  • ' . $t . '
  • '; + } + // var_dump ( $t ); + } + while ( $lv > 0 ) { + $text .= ''; + $lv --; + } + $text .= '

    '; + return $text; +} +function _md_link_replacer($in) { + // var_dump ( $in ); + $in = explode ( '|', $in [1], 2 ); + + return '' . (isset ( $in [1] ) ? $in [1] : $in [0]) . ''; +} +?> \ No newline at end of file