More fixes for updating from older revisions
[mailer.git] / DOCS / tpl-validator.php
index 147af4910ef9f7648fa891564e439cdad0eedd29..1bfedac7afe09818415b6367d82cf82f9d3b4f7a 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                                *
@@ -17,7 +17,7 @@
  * 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]
 ?>