1 | <?php |
||||
2 | /** |
||||
3 | * Utility script that can translate a text with Mailcode commands |
||||
4 | * to any of the available translation syntaxes. Meant to be opened |
||||
5 | * in a browser. |
||||
6 | * |
||||
7 | * @package Mailcode |
||||
8 | * @subpackage Tools |
||||
9 | * @author Sebastian Mordziol <[email protected]> |
||||
10 | */ |
||||
11 | |||||
12 | declare(strict_types=1); |
||||
13 | |||||
14 | use AppUtils\Request; |
||||
15 | use Mailcode\Mailcode; |
||||
16 | use Mailcode\Mailcode_Exception; |
||||
17 | use Mailcode\Mailcode_Translator_Exception; |
||||
18 | use function \AppLocalize\pt; |
||||
0 ignored issues
–
show
introduced
by
![]() |
|||||
19 | use function \AppLocalize\pts;use function AppLocalize\t; |
||||
0 ignored issues
–
show
|
|||||
20 | |||||
21 | require_once 'prepend.php'; |
||||
22 | |||||
23 | $request = new Request(); |
||||
24 | $mailcode = Mailcode::create(); |
||||
25 | |||||
26 | $commandsText = ''; |
||||
27 | $translated = ''; |
||||
28 | $error = null; |
||||
29 | $highlighted = ''; |
||||
30 | |||||
31 | if($request->getBool('highlight')) |
||||
32 | { |
||||
33 | $commandsText = $request->registerParam('mailcode')->getString(); |
||||
34 | |||||
35 | try |
||||
36 | { |
||||
37 | $safeguard = $mailcode->createSafeguard($commandsText); |
||||
38 | $safe = htmlspecialchars($safeguard->makeSafe(), ENT_QUOTES, 'UTF-8'); |
||||
39 | $highlighted = $safeguard->makeHighlighted($safe); |
||||
40 | } |
||||
41 | catch (Mailcode_Exception $e) |
||||
42 | { |
||||
43 | $error = $e->getMessage(); |
||||
44 | |||||
45 | $collection = $e->getCollection(); |
||||
46 | if($collection) |
||||
47 | { |
||||
48 | $first = $collection->getFirstError(); |
||||
49 | $error = $first->getMessage(); |
||||
50 | $matched = $first->getMatchedText(); |
||||
51 | if(!empty($matched)) { |
||||
52 | $error .= '<br>'. t('In command:').' <code>'.$matched.'</code>'; |
||||
53 | } |
||||
54 | } |
||||
55 | } |
||||
56 | } |
||||
57 | |||||
58 | ?><!doctype html> |
||||
59 | <html lang="en"> |
||||
60 | <head> |
||||
61 | <meta charset="utf-8"> |
||||
62 | <title><?php pts('Syntax highlighter'); ?> - <?php echo Mailcode::getName(); ?></title> |
||||
0 ignored issues
–
show
The function
pts was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
63 | <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous"> |
||||
64 | <link href="main.css" rel="stylesheet"> |
||||
65 | <style> |
||||
66 | <?php echo $mailcode->createStyler()->getCSS() ?> |
||||
67 | </style> |
||||
68 | </head> |
||||
69 | <body> |
||||
70 | <div class="container"> |
||||
71 | <p> |
||||
72 | <a href="./">« <?php pts('Back to overview'); ?></a> |
||||
73 | </p> |
||||
74 | <h1><?php pt('Syntax highlighter') ?></h1> |
||||
0 ignored issues
–
show
The function
pt was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
75 | <p> |
||||
76 | <?php |
||||
77 | pts('Enter the text that contains the mailcode commands to convert, and choose the output language to convert them to.'); |
||||
78 | pts('Can be any kind of text, including HTML/XML.'); |
||||
79 | ?> |
||||
80 | </p> |
||||
81 | <p class="text-warning"> |
||||
82 | <strong><?php pt('Note:') ?></strong> |
||||
83 | <?php pt('The Mailcode commands must be valid.') ?> |
||||
84 | </p> |
||||
85 | <form method="post"> |
||||
86 | <p> |
||||
87 | <textarea class="form-control" name="mailcode" rows="10"><?php echo htmlspecialchars($commandsText) ?></textarea> |
||||
88 | </p> |
||||
89 | <button type="submit" name="highlight" value="yes" class="btn btn-primary"> |
||||
90 | <?php pt('Highlight commands') ?> |
||||
91 | </button> |
||||
92 | </form> |
||||
93 | <p></p><br> |
||||
94 | <h2><?php pt('Highlighted commands') ?></h2> |
||||
95 | <?php |
||||
96 | if(empty($commandsText)) |
||||
97 | { |
||||
98 | ?> |
||||
99 | <div class="alert alert-info"> |
||||
100 | <?php pt('No commands specified.') ?> |
||||
101 | </div> |
||||
102 | <?php |
||||
103 | } |
||||
104 | else if($error) |
||||
105 | { |
||||
106 | ?> |
||||
107 | <div class="alert alert-danger"> |
||||
108 | <strong><?php pt('Error parsing commands:') ?></strong> |
||||
109 | <?php echo $error ?> |
||||
110 | </div> |
||||
111 | <?php |
||||
112 | } |
||||
113 | else |
||||
114 | { |
||||
115 | ?> |
||||
116 | <pre style="border: solid 1px #ccc;padding:12px;border-radius: 5px"><?php |
||||
117 | echo $highlighted; |
||||
118 | ?></pre> |
||||
119 | <?php |
||||
120 | } |
||||
121 | ?> |
||||
122 | </div> |
||||
123 | </body> |
||||
124 | </html> |
||||
125 |