Fix for non-working admin login if no extension is installed (an other fixed broke it)
[mailer.git] / DOCS / tpl-validator.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 09/11/2008 *
4  * ===============                              Last change: 09/11/2008 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : tpl-validator.php                                *
8  * -------------------------------------------------------------------- *
9  * Short description : Only validates templates for correctness         *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Validiert Templates auf korrektes HTML           *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 if ($_SERVER['argc'] < 2) {
35         echo "Usage: ".basename(__FILE__)." <template> [--write]\n\n";
36         echo "Validates a template against the DOM model. Use --write with caution!\n";
37         exit;
38 }
39
40 $doc = new DOMDocument();
41 $doc->formatOutput = true;
42 $doc->preserveWhiteSpace = false;
43 $doc->encoding = "utf-8";
44 $doc->xmlVersion = "1.1";
45 $doc->loadHTMLFile($_SERVER['argv'][1]);
46
47 $data = $doc->saveHTML();
48 $data = str_replace("<br>", "<br />\n", $data);
49 $data = str_replace("\n\n", "\n", $data);
50
51 $array = explode("\n", $data);
52 array_shift($array);
53 array_shift($array);
54 unset($array[count($array) - 1]);
55 unset($array[count($array) - 1]);
56
57 $data = implode("\n", $array)."\n";
58
59 if (strtolower($_SERVER['arv'][2]) == "--write") {
60         echo "Writing document...\n";
61         file_put_contents($_SERVER['argv'][1], $data);
62 }
63
64 ?>