TODOs.txt updated :(
[mailer.git] / DOCS / tpl-validator.php
index 7eb7e500e0cd97f3841cda927d1d5ca69fb9137b..d3e41e271511370ae13ea2631e5e8a4427e07fc8 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 09/11/2008 *
- * ===============                              Last change: 09/11/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 09/11/2008 *
+ * ===================                          Last change: 09/11/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : tpl-validator.php                                *
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Validiert Templates auf korrektes HTML           *
  * -------------------------------------------------------------------- *
- * $Revision:: 856                                                    $ *
- * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. March 2009)             $ *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
  * $Tag:: 0.2.1-FINAL                                                 $ *
- * $Author:: stelzi                                                   $ *
- * Needs to be in all Files and every File needs "svn propset           *
- * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
+ * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
- * For more information visit: http://www.mxchange.org                  *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009 - 2013 by Mailer Developer Team                   *
+ * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  * it under the terms of the GNU General Public License as published by *
  ************************************************************************/
 
 if ($_SERVER['argc'] < 2) {
-       echo "Usage: ".basename(__FILE__)." <template> [--write]\n\n";
-       echo "Validates a template against the DOM model. Use --write with caution!\n";
+       print "Usage: ".basename(__FILE__)." <template> [--write]\n\n";
+       print "Validates a template against the DOM model. Use --write with caution!\n";
+       exit;
+} elseif (strpos($_SERVER['argv'][1], '/js/') > 0) {
+       // Not parsing JavaScript templates!
+       print "Warning: Not parsing JavaScript ".$_SERVER['argv'][1].".\n";
        exit;
 }
 
+print "Validating template ".$_SERVER['argv'][1]."...\n";
+
 $doc = new DOMDocument();
-$doc->formatOutput = true;
-$doc->preserveWhiteSpace = false;
-$doc->encoding = "utf-8";
-$doc->xmlVersion = "1.1";
+$doc->formatOutput = TRUE;
+$doc->preserveWhiteSpace = FALSE;
+$doc->encoding = 'UTF-8';
+$doc->xmlVersion = '1.1';
 $doc->loadHTMLFile($_SERVER['argv'][1]);
 
 $data = $doc->saveHTML();
-$data = str_replace("<br>", "<br />\n", $data);
-$data = str_replace("\n\n", "\n", $data);
+$newData = str_replace("<br>", "<br />\n", $data);
+$newData = str_replace(PHP_EOL . PHP_EOL, PHP_EOL, $newData);
 
-$array = explode("\n", $data);
+$array = explode(PHP_EOL, $newData);
 array_shift($array);
 array_shift($array);
 unset($array[count($array) - 1]);
 unset($array[count($array) - 1]);
 
-$data = implode("\n", $array)."\n";
+$newData = implode(PHP_EOL, $array).PHP_EOL;
 
-if (strtolower($_SERVER['arv'][2]) == "--write") {
-       echo "Writing document...\n";
-       file_put_contents($_SERVER['argv'][1], $data);
+// Has a template changed?
+if ($data != $newData) {
+       // Has changed
+       print "Template ".$_SERVER['argv'][1]." has maybe issues.\n";
+} else {
+       // Has not changed
+       print "Template ".$_SERVER['argv'][1]." might be issue-free.\n";
 }
 
+if ((isset($_SERVER['arv'][2])) && (strtolower($_SERVER['arv'][2]) == '--write')) {
+       print "Writing document...\n";
+       file_put_contents($_SERVER['argv'][1], $data);
+} // END - if
+
+// [EOF]
 ?>