langcheck.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769
  1. <?php
  2. /**
  3. * GeSHi language file validation script
  4. *
  5. * Just point your browser at this script (with geshi.php in the parent directory)
  6. * and the language files in subdirectory "../geshi/" are being validated
  7. *
  8. * CLI mode is supported
  9. *
  10. * @author Benny Baumann
  11. * @version $Id: langcheck.php 2510 2012-06-27 15:57:55Z reedy_boy $
  12. */
  13. header('Content-Type: text/html; charset=utf-8');
  14. set_time_limit(0);
  15. error_reporting(E_ALL);
  16. $time_start = explode(' ', microtime());
  17. function colorize($level, $string) {
  18. static $colors, $end;
  19. if ( !isset($colors) ) {
  20. if ( PHP_SAPI != 'cli' ) {
  21. $end = '</span>';
  22. $colors = array(
  23. TYPE_NOTICE => '<span style="color:#080;font-weight:bold;">',
  24. TYPE_WARNING => '<span style="color:#CC0; font-weight: bold;">',
  25. TYPE_ERROR => '<span style="color:#F00; font-weight: bold;">',
  26. TYPE_OK => '<span style="color: #080; font-weight: bold;">'
  27. );
  28. } else {
  29. $end = chr(27).'[0m';
  30. $colors = array(
  31. TYPE_NOTICE => chr(27).'[1m',
  32. TYPE_WARNING => chr(27).'[1;33m',
  33. TYPE_ERROR => chr(27).'[1;31m',
  34. TYPE_OK => chr(27).'[1;32m'
  35. );
  36. }
  37. }
  38. if ( !isset($colors[$level]) ) {
  39. trigger_error("no colors for level $level", E_USER_ERROR);
  40. }
  41. return $colors[$level].$string.$end;
  42. }
  43. define ('TYPE_NOTICE', 0);
  44. define ('TYPE_WARNING', 1);
  45. define ('TYPE_ERROR', 2);
  46. define ('TYPE_OK', 3);
  47. $error_abort = false;
  48. $error_cache = array();
  49. function output_error_cache(){
  50. global $error_cache, $error_abort;
  51. if(count($error_cache)) {
  52. echo colorize(TYPE_ERROR, "Failed");
  53. if ( PHP_SAPI == 'cli' ) {
  54. echo "\n\n";
  55. } else {
  56. echo "<br /><ol>\n";
  57. }
  58. foreach($error_cache as $error_msg) {
  59. if ( PHP_SAPI == 'cli' ) {
  60. echo "\n";
  61. } else {
  62. echo "<li>";
  63. }
  64. switch($error_msg['t']) {
  65. case TYPE_NOTICE:
  66. $msg = 'NOTICE';
  67. break;
  68. case TYPE_WARNING:
  69. $msg = 'WARNING';
  70. break;
  71. case TYPE_ERROR:
  72. $msg = 'ERROR';
  73. break;
  74. }
  75. echo colorize($error_msg['t'], $msg);
  76. if ( PHP_SAPI == 'cli' ) {
  77. echo "\t" . $error_msg['m'];
  78. } else {
  79. echo " " . $error_msg['m'] . "</li>";
  80. }
  81. }
  82. if ( PHP_SAPI == 'cli' ) {
  83. echo "\n";
  84. } else {
  85. echo "</ol>\n";
  86. }
  87. } else {
  88. echo colorize(TYPE_OK, "OK");
  89. if ( PHP_SAPI == 'cli' ) {
  90. echo "\n";
  91. } else {
  92. echo "\n<br />";
  93. }
  94. }
  95. echo "\n";
  96. $error_cache = array();
  97. }
  98. function report_error($type, $message) {
  99. global $error_cache, $error_abort;
  100. $error_cache[] = array('t' => $type, 'm' => $message);
  101. if(TYPE_ERROR == $type) {
  102. $error_abort = true;
  103. }
  104. }
  105. function dupfind_strtolower(&$value){
  106. $value = strtolower($value);
  107. }
  108. if ( PHP_SAPI != 'cli' ) { ?>
  109. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  110. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  111. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  112. <head>
  113. <title>GeSHi Language File Validation Script</title>
  114. <style type="text/css">
  115. <!--
  116. html {
  117. background-color: #f0f0f0;
  118. }
  119. body {
  120. font-family: Verdana, Arial, sans-serif;
  121. margin: 10px;
  122. border: 2px solid #e0e0e0;
  123. background-color: #fcfcfc;
  124. padding: 5px;
  125. font-size: 10pt;
  126. }
  127. h2 {
  128. margin: .1em 0 .2em .5em;
  129. border-bottom: 1px solid #b0b0b0;
  130. color: #b0b0b0;
  131. font-weight: normal;
  132. font-size: 150%;
  133. }
  134. h3 {
  135. margin: .1em 0 .2em .5em;
  136. color: #b0b0b0;
  137. font-weight: normal;
  138. font-size: 120%;
  139. }
  140. #footer {
  141. text-align: center;
  142. font-size: 80%;
  143. color: #a9a9a9;
  144. }
  145. #footer a {
  146. color: #9999ff;
  147. }
  148. textarea {
  149. border: 1px solid #b0b0b0;
  150. font-size: 90%;
  151. color: #333;
  152. margin-left: 20px;
  153. }
  154. select, input {
  155. margin-left: 20px;
  156. }
  157. p {
  158. font-size: 90%;
  159. margin-left: .5em;
  160. }
  161. -->
  162. </style>
  163. </head>
  164. <body>
  165. <h2>GeSHi Language File Validation Script</h2>
  166. <p>To use this script, make sure that <strong>geshi.php</strong> is in the
  167. parent directory or in your include_path, and that the language files are in a
  168. subdirectory of GeSHi's directory called <strong>geshi/</strong>.</p>
  169. <p>Everything else will be done by this script automatically. After the script
  170. finished you should see messages of what could cause trouble with GeSHi or where
  171. your language files can be improved. Please be patient, as this might take some time.</p>
  172. <ol>
  173. <li>Checking where to find GeSHi installation ...<?php
  174. } else { ?>
  175. <?php echo colorize(TYPE_NOTICE, "#### GeSHi Language File Validation Script ####") ?>
  176. To use this script, make sure that <?php echo colorize(TYPE_NOTICE, "geshi.php"); ?> is in the
  177. parent directory or in your include_path, and that the language files are in a
  178. subdirectory of GeSHi's directory called <?php echo colorize(TYPE_NOTICE, "geshi/"); ?>.
  179. Everything else will be done by this script automatically. After the script
  180. finished you should see messages of what could cause trouble with GeSHi or where
  181. your language files can be improved. Please be patient, as this might take some time.
  182. Checking where to find GeSHi installation ...<?php echo "\t";
  183. }
  184. // Rudimentary checking of where GeSHi is. In a default install it will be in ../, but
  185. // it could be in the current directory if the include_path is set. There's nowhere else
  186. // we can reasonably guess.
  187. if (is_readable('../geshi.php')) {
  188. $path = '../';
  189. } elseif (is_readable('geshi.php')) {
  190. $path = './';
  191. } else {
  192. report_error(TYPE_ERROR, 'Could not find geshi.php - make sure it is in your include path!');
  193. }
  194. if(!$error_abort) {
  195. require $path . 'geshi.php';
  196. if(!class_exists('GeSHi')) {
  197. report_error(TYPE_ERROR, 'The GeSHi class was not found, although it seemed we loaded the correct file!');
  198. }
  199. }
  200. if(!$error_abort) {
  201. if(!defined('GESHI_LANG_ROOT')) {
  202. report_error(TYPE_ERROR, 'There\'s no information present on where to find the language files!');
  203. } elseif(!is_dir(GESHI_LANG_ROOT)) {
  204. report_error(TYPE_ERROR, 'The path "'.GESHI_LANG_ROOT.'" given, does not ressemble a directory!');
  205. } elseif(!is_readable(GESHI_LANG_ROOT)) {
  206. report_error(TYPE_ERROR, 'The path "'.GESHI_LANG_ROOT.'" is not readable to this script!');
  207. }
  208. }
  209. output_error_cache();
  210. if(!$error_abort) {
  211. if ( PHP_SAPI == 'cli' ) {
  212. echo "Listing available language files ...\t\t";
  213. } else {
  214. echo "</li>\n<li>Listing available language files ... ";
  215. }
  216. if (!($dir = @opendir(GESHI_LANG_ROOT))) {
  217. report_error(TYPE_ERROR, 'Error requesting listing for available language files!');
  218. }
  219. $languages = array();
  220. if(!$error_abort) {
  221. while ($file = readdir($dir)) {
  222. if (!$file || $file[0] == '.' || strpos($file, '.php') === false) {
  223. continue;
  224. }
  225. $lang = substr($file, 0, strpos($file, '.'));
  226. if(4 != strlen($file) - strlen($lang)) {
  227. continue;
  228. }
  229. $languages[] = $lang;
  230. }
  231. closedir($dir);
  232. }
  233. $languages = array_unique($languages);
  234. sort($languages);
  235. if(!count($languages)) {
  236. report_error(TYPE_WARNING, 'Unable to locate any usable language files in "'.GESHI_LANG_ROOT.'"!');
  237. }
  238. output_error_cache();
  239. }
  240. if ( PHP_SAPI == 'cli' ) {
  241. if (isset($_SERVER['argv'][1]) && in_array($_SERVER['argv'][1], $languages)) {
  242. $languages = array($_SERVER['argv'][1]);
  243. }
  244. } else {
  245. if (isset($_REQUEST['show']) && in_array($_REQUEST['show'], $languages)) {
  246. $languages = array($_REQUEST['show']);
  247. }
  248. }
  249. if(!$error_abort) {
  250. foreach ($languages as $lang) {
  251. if ( PHP_SAPI == 'cli' ) {
  252. echo "Validating language file for '$lang' ...\t\t";
  253. } else {
  254. echo "</li>\n<li>Validating language file for '$lang' ... ";
  255. }
  256. $langfile = GESHI_LANG_ROOT . $lang . '.php';
  257. $language_data = array();
  258. if(!is_file($langfile)) {
  259. report_error(TYPE_ERROR, 'The path "' .$langfile. '" does not ressemble a regular file!');
  260. } elseif(!is_readable($langfile)) {
  261. report_error(TYPE_ERROR, 'Cannot read file "' .$langfile. '"!');
  262. } else {
  263. $langfile_content = file_get_contents($langfile);
  264. if(preg_match("/\?>(?:\r?\n|\r(?!\n)){2,}\Z/", $langfile_content)) {
  265. report_error(TYPE_ERROR, 'Language file contains trailing empty lines at EOF!');
  266. }
  267. if(!preg_match("/\?>(?:\r?\n|\r(?!\n))?\Z/", $langfile_content)) {
  268. report_error(TYPE_ERROR, 'Language file contains no PHP end marker at EOF!');
  269. }
  270. if(preg_match("/\t/", $langfile_content)) {
  271. report_error(TYPE_NOTICE, 'Language file contains unescaped tabulator chars (probably for indentation)!');
  272. }
  273. if(preg_match('/^(?: )*(?! )(?! \*) /m', $langfile_content)) {
  274. report_error(TYPE_NOTICE, 'Language file contains irregular indentation (other than 4 spaces per indentation level)!');
  275. }
  276. if(!preg_match("/\/\*\*((?!\*\/).)*?Author:((?!\*\/).)*?\*\//s", $langfile_content)) {
  277. report_error(TYPE_WARNING, 'Language file does not contain a specification of an author!');
  278. }
  279. if(!preg_match("/\/\*\*((?!\*\/).)*?Copyright:((?!\*\/).)*?\*\//s", $langfile_content)) {
  280. report_error(TYPE_WARNING, 'Language file does not contain a specification of the copyright!');
  281. }
  282. if(!preg_match("/\/\*\*((?!\*\/).)*?Release Version:((?!\*\/).)*?\*\//s", $langfile_content)) {
  283. report_error(TYPE_WARNING, 'Language file does not contain a specification of the release version!');
  284. }
  285. if(!preg_match("/\/\*\*((?!\*\/).)*?Date Started:((?!\*\/).)*?\*\//s", $langfile_content)) {
  286. report_error(TYPE_WARNING, 'Language file does not contain a specification of the date it was started!');
  287. }
  288. if(!preg_match("/\/\*\*((?!\*\/).)*?This file is part of GeSHi\.((?!\*\/).)*?\*\//s", $langfile_content)) {
  289. report_error(TYPE_WARNING, 'Language file does not state that it belongs to GeSHi!');
  290. }
  291. if(!preg_match("/\/\*\*((?!\*\/).)*?language file for GeSHi\.((?!\*\/).)*?\*\//s", $langfile_content)) {
  292. report_error(TYPE_WARNING, 'Language file does not state that it is a language file for GeSHi!');
  293. }
  294. if(!preg_match("/\/\*\*((?!\*\/).)*?GNU General Public License((?!\*\/).)*?\*\//s", $langfile_content)) {
  295. report_error(TYPE_WARNING, 'Language file does not state that it is provided under the terms of the GNU GPL!');
  296. }
  297. unset($langfile_content);
  298. include $langfile;
  299. if(!isset($language_data)) {
  300. report_error(TYPE_ERROR, 'Language file does not contain a $language_data structure to check!');
  301. } elseif (!is_array($language_data)) {
  302. report_error(TYPE_ERROR, 'Language file contains a $language_data structure which is not an array!');
  303. }
  304. }
  305. if(!$error_abort) {
  306. if(!isset($language_data['LANG_NAME'])) {
  307. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'LANG_NAME\'] specification!');
  308. } elseif (!is_string($language_data['LANG_NAME'])) {
  309. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'LANG_NAME\'] specification which is not a string!');
  310. }
  311. if(!isset($language_data['COMMENT_SINGLE'])) {
  312. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'COMMENT_SIGNLE\'] structure to check!');
  313. } elseif (!is_array($language_data['COMMENT_SINGLE'])) {
  314. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'COMMENT_SINGLE\'] structure which is not an array!');
  315. }
  316. if(!isset($language_data['COMMENT_MULTI'])) {
  317. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'COMMENT_MULTI\'] structure to check!');
  318. } elseif (!is_array($language_data['COMMENT_MULTI'])) {
  319. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'COMMENT_MULTI\'] structure which is not an array!');
  320. }
  321. if(isset($language_data['COMMENT_REGEXP'])) {
  322. if (!is_array($language_data['COMMENT_REGEXP'])) {
  323. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'COMMENT_REGEXP\'] structure which is not an array!');
  324. }
  325. }
  326. if(!isset($language_data['QUOTEMARKS'])) {
  327. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'QUOTEMARKS\'] structure to check!');
  328. } elseif (!is_array($language_data['QUOTEMARKS'])) {
  329. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'QUOTEMARKS\'] structure which is not an array!');
  330. }
  331. if(isset($language_data['HARDQUOTE'])) {
  332. if (!is_array($language_data['HARDQUOTE'])) {
  333. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'HARDQUOTE\'] structure which is not an array!');
  334. }
  335. }
  336. if(!isset($language_data['ESCAPE_CHAR'])) {
  337. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'ESCAPE_CHAR\'] specification to check!');
  338. } elseif (!is_string($language_data['ESCAPE_CHAR'])) {
  339. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'ESCAPE_CHAR\'] specification which is not a string!');
  340. } elseif (1 < strlen($language_data['ESCAPE_CHAR'])) {
  341. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'ESCAPE_CHAR\'] specification is not empty or exactly one char!');
  342. }
  343. if(!isset($language_data['CASE_KEYWORDS'])) {
  344. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'CASE_KEYWORDS\'] specification!');
  345. } elseif (!is_int($language_data['CASE_KEYWORDS'])) {
  346. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'CASE_KEYWORDS\'] specification which is not an integer!');
  347. } elseif (GESHI_CAPS_NO_CHANGE != $language_data['CASE_KEYWORDS'] &&
  348. GESHI_CAPS_LOWER != $language_data['CASE_KEYWORDS'] &&
  349. GESHI_CAPS_UPPER != $language_data['CASE_KEYWORDS']) {
  350. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'CASE_KEYWORDS\'] specification which is neither of GESHI_CAPS_NO_CHANGE, GESHI_CAPS_LOWER nor GESHI_CAPS_UPPER!');
  351. }
  352. if(!isset($language_data['KEYWORDS'])) {
  353. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'KEYWORDS\'] structure to check!');
  354. } elseif (!is_array($language_data['KEYWORDS'])) {
  355. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'KEYWORDS\'] structure which is not an array!');
  356. } else {
  357. foreach($language_data['KEYWORDS'] as $kw_key => $kw_value) {
  358. if(!is_integer($kw_key)) {
  359. report_error(TYPE_WARNING, "Language file contains an key '$kw_key' in \$language_data['KEYWORDS'] that is not integer!");
  360. } elseif (!is_array($kw_value)) {
  361. report_error(TYPE_ERROR, "Language file contains a \$language_data['KEYWORDS']['$kw_value'] structure which is not an array!");
  362. }
  363. }
  364. }
  365. if(!isset($language_data['SYMBOLS'])) {
  366. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'SYMBOLS\'] structure to check!');
  367. } elseif (!is_array($language_data['SYMBOLS'])) {
  368. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'SYMBOLS\'] structure which is not an array!');
  369. }
  370. if(!isset($language_data['CASE_SENSITIVE'])) {
  371. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'CASE_SENSITIVE\'] structure to check!');
  372. } elseif (!is_array($language_data['CASE_SENSITIVE'])) {
  373. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'CASE_SENSITIVE\'] structure which is not an array!');
  374. } else {
  375. foreach($language_data['CASE_SENSITIVE'] as $cs_key => $cs_value) {
  376. if(!is_integer($cs_key)) {
  377. report_error(TYPE_WARNING, "Language file contains an key '$cs_key' in \$language_data['CASE_SENSITIVE'] that is not integer!");
  378. } elseif (!is_bool($cs_value)) {
  379. report_error(TYPE_ERROR, "Language file contains a Case Sensitivity specification for \$language_data['CASE_SENSITIVE']['$cs_value'] which is not a boolean!");
  380. }
  381. }
  382. }
  383. if(!isset($language_data['URLS'])) {
  384. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'URLS\'] structure to check!');
  385. } elseif (!is_array($language_data['URLS'])) {
  386. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'URLS\'] structure which is not an array!');
  387. } else {
  388. foreach($language_data['URLS'] as $url_key => $url_value) {
  389. if(!is_integer($url_key)) {
  390. report_error(TYPE_WARNING, "Language file contains an key '$url_key' in \$language_data['URLS'] that is not integer!");
  391. } elseif (!is_string($url_value)) {
  392. report_error(TYPE_ERROR, "Language file contains a Documentation URL specification for \$language_data['URLS']['$url_value'] which is not a string!");
  393. } elseif (preg_match('#&([^;]*(=|$))#U', $url_value)) {
  394. report_error(TYPE_ERROR, "Language file contains unescaped ampersands (&amp;) in \$language_data['URLS']!");
  395. }
  396. }
  397. }
  398. if(!isset($language_data['OOLANG'])) {
  399. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'OOLANG\'] specification!');
  400. } elseif (!is_int($language_data['OOLANG']) && !is_bool($language_data['OOLANG'])) {
  401. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'OOLANG\'] specification which is neither boolean nor integer!');
  402. } elseif (false !== $language_data['OOLANG'] &&
  403. true !== $language_data['OOLANG'] &&
  404. 2 !== $language_data['OOLANG']) {
  405. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'OOLANG\'] specification which is neither of false, true or 2!');
  406. }
  407. if(!isset($language_data['OBJECT_SPLITTERS'])) {
  408. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'OBJECT_SPLITTERS\'] structure to check!');
  409. } elseif (!is_array($language_data['OBJECT_SPLITTERS'])) {
  410. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'OBJECT_SPLITTERS\'] structure which is not an array!');
  411. }
  412. if(!isset($language_data['REGEXPS'])) {
  413. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'REGEXPS\'] structure to check!');
  414. } elseif (!is_array($language_data['REGEXPS'])) {
  415. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'REGEXPS\'] structure which is not an array!');
  416. }
  417. if(!isset($language_data['STRICT_MODE_APPLIES'])) {
  418. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'STRICT_MODE_APPLIES\'] specification!');
  419. } elseif (!is_int($language_data['STRICT_MODE_APPLIES'])) {
  420. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'STRICT_MODE_APPLIES\'] specification which is not an integer!');
  421. } elseif (GESHI_MAYBE != $language_data['STRICT_MODE_APPLIES'] &&
  422. GESHI_ALWAYS != $language_data['STRICT_MODE_APPLIES'] &&
  423. GESHI_NEVER != $language_data['STRICT_MODE_APPLIES']) {
  424. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'STRICT_MODE_APPLIES\'] specification which is neither of GESHI_MAYBE, GESHI_ALWAYS nor GESHI_NEVER!');
  425. }
  426. if(!isset($language_data['SCRIPT_DELIMITERS'])) {
  427. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'SCRIPT_DELIMITERS\'] structure to check!');
  428. } elseif (!is_array($language_data['SCRIPT_DELIMITERS'])) {
  429. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'SCRIPT_DELIMITERS\'] structure which is not an array!');
  430. }
  431. if(!isset($language_data['HIGHLIGHT_STRICT_BLOCK'])) {
  432. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'HIGHLIGHT_STRICT_BLOCK\'] structure to check!');
  433. } elseif (!is_array($language_data['HIGHLIGHT_STRICT_BLOCK'])) {
  434. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'HIGHLIGHT_STRICT_BLOCK\'] structure which is not an array!');
  435. }
  436. if(isset($language_data['TAB_WIDTH'])) {
  437. if (!is_int($language_data['TAB_WIDTH'])) {
  438. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'TAB_WIDTH\'] specification which is not an integer!');
  439. } elseif (1 > $language_data['TAB_WIDTH']) {
  440. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'TAB_WIDTH\'] specification which is less than 1!');
  441. }
  442. }
  443. if(isset($language_data['PARSER_CONTROL'])) {
  444. if (!is_array($language_data['PARSER_CONTROL'])) {
  445. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'PARSER_CONTROL\'] structure which is not an array!');
  446. }
  447. }
  448. if(!isset($language_data['STYLES'])) {
  449. report_error(TYPE_ERROR, 'Language file contains no $language_data[\'STYLES\'] structure to check!');
  450. } elseif (!is_array($language_data['STYLES'])) {
  451. report_error(TYPE_ERROR, 'Language file contains a $language_data[\'STYLES\'] structure which is not an array!');
  452. } else {
  453. $style_arrays = array('KEYWORDS', 'COMMENTS', 'ESCAPE_CHAR',
  454. 'BRACKETS', 'STRINGS', 'NUMBERS', 'METHODS', 'SYMBOLS',
  455. 'REGEXPS', 'SCRIPT');
  456. foreach($style_arrays as $style_kind) {
  457. if(!isset($language_data['STYLES'][$style_kind])) {
  458. report_error(TYPE_ERROR, "Language file contains no \$language_data['STYLES']['$style_kind'] structure to check!");
  459. } elseif (!is_array($language_data['STYLES'][$style_kind])) {
  460. report_error(TYPE_ERROR, "Language file contains a \$language_data['STYLES\']['$style_kind'] structure which is not an array!");
  461. } else {
  462. foreach($language_data['STYLES'][$style_kind] as $sk_key => $sk_value) {
  463. if(!is_int($sk_key) && ('COMMENTS' != $style_kind && 'MULTI' != $sk_key)
  464. && !(('STRINGS' == $style_kind || 'ESCAPE_CHAR' == $style_kind) && 'HARD' == $sk_key)) {
  465. report_error(TYPE_WARNING, "Language file contains an key '$sk_key' in \$language_data['STYLES']['$style_kind'] that is not integer!");
  466. } elseif (!is_string($sk_value)) {
  467. report_error(TYPE_WARNING, "Language file contains a CSS specification for \$language_data['STYLES']['$style_kind'][$key] which is not a string!");
  468. }
  469. }
  470. }
  471. }
  472. unset($style_arrays);
  473. }
  474. }
  475. if(!$error_abort) {
  476. //Initial sanity checks survived? --> Let's dig deeper!
  477. foreach($language_data['KEYWORDS'] as $key => $keywords) {
  478. if(!isset($language_data['CASE_SENSITIVE'][$key])) {
  479. report_error(TYPE_ERROR, "Language file contains no \$language_data['CASE_SENSITIVE'] specification for keyword group $key!");
  480. }
  481. if(!isset($language_data['URLS'][$key])) {
  482. report_error(TYPE_ERROR, "Language file contains no \$language_data['URLS'] specification for keyword group $key!");
  483. }
  484. if(empty($keywords)) {
  485. report_error(TYPE_WARNING, "Language file contains an empty keyword list in \$language_data['KEYWORDS'] for group $key!");
  486. }
  487. foreach($keywords as $id => $kw) {
  488. if(!is_string($kw)) {
  489. report_error(TYPE_WARNING, "Language file contains an non-string entry at \$language_data['KEYWORDS'][$key][$id]!");
  490. } elseif (!strlen($kw)) {
  491. report_error(TYPE_ERROR, "Language file contains an empty string entry at \$language_data['KEYWORDS'][$key][$id]!");
  492. } elseif (preg_match('/^([\(\)\{\}\[\]\^=.,:;\-+\*\/%\$\"\'\?]|&[\w#]\w*;)+$/i', $kw)) {
  493. report_error(TYPE_NOTICE, "Language file contains an keyword ('$kw') at \$language_data['KEYWORDS'][$key][$id] which seems to be better suited for the symbols section!");
  494. }
  495. }
  496. if(isset($language_data['CASE_SENSITIVE'][$key]) && !$language_data['CASE_SENSITIVE'][$key]) {
  497. array_walk($keywords, 'dupfind_strtolower');
  498. }
  499. if(count($keywords) != count(array_unique($keywords))) {
  500. $kw_diffs = array_count_values($keywords);
  501. foreach($kw_diffs as $kw => $kw_count) {
  502. if($kw_count > 1) {
  503. report_error(TYPE_WARNING, "Language file contains per-group duplicate keyword '$kw' in \$language_data['KEYWORDS'][$key]!");
  504. }
  505. }
  506. }
  507. }
  508. $disallowed_before = "(?<![a-zA-Z0-9\$_\|\#;>|^&";
  509. $disallowed_after = "(?![a-zA-Z0-9_\|%\\-&;";
  510. foreach($language_data['KEYWORDS'] as $key => $keywords) {
  511. foreach($language_data['KEYWORDS'] as $key2 => $keywords2) {
  512. if($key2 <= $key) {
  513. continue;
  514. }
  515. $kw_diffs = array_intersect($keywords, $keywords2);
  516. foreach($kw_diffs as $kw) {
  517. if(isset($language_data['PARSER_CONTROL']['KEYWORDS'])) {
  518. //Check the precondition\post-cindition for the involved keyword groups
  519. $g1_pre = $disallowed_before;
  520. $g2_pre = $disallowed_before;
  521. $g1_post = $disallowed_after;
  522. $g2_post = $disallowed_after;
  523. if(isset($language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'])) {
  524. $g1_pre = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'];
  525. $g2_pre = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_BEFORE'];
  526. }
  527. if(isset($language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'])) {
  528. $g1_post = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'];
  529. $g2_post = $language_data['PARSER_CONTROL']['KEYWORDS']['DISALLOWED_AFTER'];
  530. }
  531. if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_BEFORE'])) {
  532. $g1_pre = $language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_BEFORE'];
  533. }
  534. if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_AFTER'])) {
  535. $g1_post = $language_data['PARSER_CONTROL']['KEYWORDS'][$key]['DISALLOWED_AFTER'];
  536. }
  537. if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_BEFORE'])) {
  538. $g2_pre = $language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_BEFORE'];
  539. }
  540. if(isset($language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_AFTER'])) {
  541. $g2_post = $language_data['PARSER_CONTROL']['KEYWORDS'][$key2]['DISALLOWED_AFTER'];
  542. }
  543. if($g1_pre != $g2_pre || $g1_post != $g2_post) {
  544. continue;
  545. }
  546. }
  547. report_error(TYPE_WARNING, "Language file contains cross-group duplicate keyword '$kw' in \$language_data['KEYWORDS'][$key] and \$language_data['KEYWORDS'][$key2]!");
  548. }
  549. }
  550. }
  551. foreach($language_data['CASE_SENSITIVE'] as $key => $keywords) {
  552. if(!isset($language_data['KEYWORDS'][$key]) && $key != GESHI_COMMENTS) {
  553. report_error(TYPE_WARNING, "Language file contains an superfluous \$language_data['CASE_SENSITIVE'] specification for non-existing keyword group $key!");
  554. }
  555. }
  556. foreach($language_data['URLS'] as $key => $keywords) {
  557. if(!isset($language_data['KEYWORDS'][$key])) {
  558. report_error(TYPE_WARNING, "Language file contains an superfluous \$language_data['URLS'] specification for non-existing keyword group $key!");
  559. }
  560. }
  561. foreach($language_data['STYLES']['KEYWORDS'] as $key => $keywords) {
  562. if(!isset($language_data['KEYWORDS'][$key])) {
  563. report_error(TYPE_WARNING, "Language file contains an superfluous \$language_data['STYLES']['KEYWORDS'] specification for non-existing keyword group $key!");
  564. }
  565. }
  566. foreach($language_data['COMMENT_SINGLE'] as $ck => $cv) {
  567. if(!is_int($ck)) {
  568. report_error(TYPE_WARNING, "Language file contains an key '$ck' in \$language_data['COMMENT_SINGLE'] that is not integer!");
  569. }
  570. if(!is_string($cv)) {
  571. report_error(TYPE_WARNING, "Language file contains an non-string entry at \$language_data['COMMENT_SINGLE'][$ck]!");
  572. }
  573. if(!isset($language_data['STYLES']['COMMENTS'][$ck])) {
  574. report_error(TYPE_WARNING, "Language file contains no \$language_data['STYLES']['COMMENTS'] specification for comment group $ck!");
  575. }
  576. }
  577. if(isset($language_data['COMMENT_REGEXP'])) {
  578. foreach($language_data['COMMENT_REGEXP'] as $ck => $cv) {
  579. if(!is_int($ck)) {
  580. report_error(TYPE_WARNING, "Language file contains an key '$ck' in \$language_data['COMMENT_REGEXP'] that is not integer!");
  581. }
  582. if(!is_string($cv)) {
  583. report_error(TYPE_WARNING, "Language file contains an non-string entry at \$language_data['COMMENT_REGEXP'][$ck]!");
  584. }
  585. if(!isset($language_data['STYLES']['COMMENTS'][$ck])) {
  586. report_error(TYPE_WARNING, "Language file contains no \$language_data['STYLES']['COMMENTS'] specification for comment group $ck!");
  587. }
  588. }
  589. }
  590. foreach($language_data['STYLES']['COMMENTS'] as $ck => $cv) {
  591. if($ck != 'MULTI' && !isset($language_data['COMMENT_SINGLE'][$ck]) &&
  592. !isset($language_data['COMMENT_REGEXP'][$ck])) {
  593. report_error(TYPE_NOTICE, "Language file contains an superfluous \$language_data['STYLES']['COMMENTS'] specification for Single Line or Regular-Expression Comment key $ck!");
  594. }
  595. }
  596. if (isset($language_data['STYLES']['STRINGS']['HARD'])) {
  597. if (empty($language_data['HARDQUOTE'])) {
  598. report_error(TYPE_NOTICE, "Language file contains superfluous \$language_data['STYLES']['STRINGS'] specification for key 'HARD', but no 'HARDQUOTE's are defined!");
  599. }
  600. unset($language_data['STYLES']['STRINGS']['HARD']);
  601. }
  602. foreach($language_data['STYLES']['STRINGS'] as $sk => $sv) {
  603. if($sk && !isset($language_data['QUOTEMARKS'][$sk])) {
  604. report_error(TYPE_NOTICE, "Language file contains an superfluous \$language_data['STYLES']['STRINGS'] specification for non-existing quotemark key $sk!");
  605. }
  606. }
  607. foreach($language_data['REGEXPS'] as $rk => $rv) {
  608. if(!is_int($rk)) {
  609. report_error(TYPE_WARNING, "Language file contains an key '$rk' in \$language_data['REGEXPS'] that is not integer!");
  610. }
  611. if(is_string($rv)) {
  612. //Check for unmasked / in regular expressions ...
  613. if(empty($rv)) {
  614. report_error(TYPE_WARNING, "Language file contains an empty regular expression at \$language_data['REGEXPS'][$rk]!");
  615. } else {
  616. if(preg_match("/(?<!\\\\)\//s", $rv)) {
  617. report_error(TYPE_WARNING, "Language file contains a regular expression with an unmasked / character at \$language_data['REGEXPS'][$rk]!");
  618. } elseif (preg_match("/(?<!<)(\\\\\\\\)*\\\\\|(?!>)/s", $rv)) {
  619. report_error(TYPE_WARNING, "Language file contains a regular expression with an unescaped match for a pipe character '|' which needs escaping as '&lt;PIPE&gt;' instead at \$language_data['REGEXPS'][$rk]!");
  620. }
  621. }
  622. } elseif(is_array($rv)) {
  623. if(!isset($rv[GESHI_SEARCH])) {
  624. report_error(TYPE_ERROR, "Language file contains no GESHI_SEARCH entry in extended regular expression at \$language_data['REGEXPS'][$rk]!");
  625. } elseif(!is_string($rv[GESHI_SEARCH])) {
  626. report_error(TYPE_ERROR, "Language file contains a GESHI_SEARCH entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!");
  627. } else {
  628. if(preg_match("/(?<!\\\\)\//s", $rv[GESHI_SEARCH])) {
  629. report_error(TYPE_WARNING, "Language file contains a regular expression with an unmasked / character at \$language_data['REGEXPS'][$rk]!");
  630. } elseif (preg_match("/(?<!<)(\\\\\\\\)*\\\\\|(?!>)/s", $rv[GESHI_SEARCH])) {
  631. report_error(TYPE_WARNING, "Language file contains a regular expression with an unescaped match for a pipe character '|' which needs escaping as '&lt;PIPE&gt;' instead at \$language_data['REGEXPS'][$rk]!");
  632. }
  633. }
  634. if(!isset($rv[GESHI_REPLACE])) {
  635. report_error(TYPE_WARNING, "Language file contains no GESHI_REPLACE entry in extended regular expression at \$language_data['REGEXPS'][$rk]!");
  636. } elseif(!is_string($rv[GESHI_REPLACE])) {
  637. report_error(TYPE_ERROR, "Language file contains a GESHI_REPLACE entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!");
  638. }
  639. if(!isset($rv[GESHI_MODIFIERS])) {
  640. report_error(TYPE_WARNING, "Language file contains no GESHI_MODIFIERS entry in extended regular expression at \$language_data['REGEXPS'][$rk]!");
  641. } elseif(!is_string($rv[GESHI_MODIFIERS])) {
  642. report_error(TYPE_ERROR, "Language file contains a GESHI_MODIFIERS entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!");
  643. }
  644. if(!isset($rv[GESHI_BEFORE])) {
  645. report_error(TYPE_WARNING, "Language file contains no GESHI_BEFORE entry in extended regular expression at \$language_data['REGEXPS'][$rk]!");
  646. } elseif(!is_string($rv[GESHI_BEFORE])) {
  647. report_error(TYPE_ERROR, "Language file contains a GESHI_BEFORE entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!");
  648. }
  649. if(!isset($rv[GESHI_AFTER])) {
  650. report_error(TYPE_WARNING, "Language file contains no GESHI_AFTER entry in extended regular expression at \$language_data['REGEXPS'][$rk]!");
  651. } elseif(!is_string($rv[GESHI_AFTER])) {
  652. report_error(TYPE_ERROR, "Language file contains a GESHI_AFTER entry in extended regular expression at \$language_data['REGEXPS'][$rk] which is not a string!");
  653. }
  654. } else {
  655. report_error(TYPE_WARNING, "Language file contains an non-string and non-array entry at \$language_data['REGEXPS'][$rk]!");
  656. }
  657. if(!isset($language_data['STYLES']['REGEXPS'][$rk])) {
  658. report_error(TYPE_WARNING, "Language file contains no \$language_data['STYLES']['REGEXPS'] specification for regexp group $rk!");
  659. }
  660. }
  661. foreach($language_data['STYLES']['REGEXPS'] as $rk => $rv) {
  662. if(!isset($language_data['REGEXPS'][$rk])) {
  663. report_error(TYPE_NOTICE, "Language file contains an superfluous \$language_data['STYLES']['REGEXPS'] specification for regexp key $rk!");
  664. }
  665. }
  666. }
  667. output_error_cache();
  668. flush();
  669. if($error_abort) {
  670. break;
  671. }
  672. }
  673. }
  674. $time_end = explode(' ', microtime());
  675. $time_diff = $time_end[0] + $time_end[1] - $time_start[0] - $time_start[1];
  676. if ( PHP_SAPI != 'cli' ) {
  677. ?></li>
  678. </ol>
  679. <p>Validation process completed in <? printf("%.2f", $time_diff); ?> seconds.</p>
  680. <div id="footer">GeSHi &copy; 2004-2007 Nigel McNie, 2007-2008 Benny Baumann, released under the GNU GPL</div>
  681. </body>
  682. </html>
  683. <?php } else { ?>
  684. Validation process completed in <? printf("%.2f", $time_diff); ?> seconds.
  685. GeSHi &copy; 2004-2007 Nigel McNie, 2007-2012 Benny Baumann, released under the GNU GPL
  686. <?php } ?>