* -------------------------------------------------------------------- *
* 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 $ *
+ * $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]
?>