Fix for endless loop
[mailer.git] / DOCS / tpl-validator.php
index 5576f66e07aba622c7342618455cb243b8185dbb..132a3c01fb46d121d0a42c7e20b14f194e2c010d 100644 (file)
  * -------------------------------------------------------------------- *
  * Kurzbeschreibung  : Validiert Templates auf korrektes HTML           *
  * -------------------------------------------------------------------- *
- *                                                                      *
+ * $Revision::                                                        $ *
+ * $Date::                                                            $ *
+ * $Tag:: 0.2.1-FINAL                                                 $ *
+ * $Author::                                                          $ *
+ * Needs to be in all Files and every File needs "svn propset           *
+ * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder                           *
+ * Copyright (c) 2003 - 2009 by Roland Haeder                           *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
  ************************************************************************/
 
 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->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("\n\n", "\n", $newData);
 
-$array = explode("\n", $data);
+$array = explode("\n", $newData);
 array_shift($array);
 array_shift($array);
 unset($array[count($array) - 1]);
 unset($array[count($array) - 1]);
 
-$data = implode("\n", $array)."\n";
+$newData = implode("\n", $array)."\n";
 
-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 (strtolower($_SERVER['arv'][2]) == '--write') {
+       print "Writing document...\n";
+       file_put_contents($_SERVER['argv'][1], $data);
+} // END - if
+
+// [EOF]
 ?>