PageRenderTime 57ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/inc/app/sitellite/lib/geshi/contrib/langcheck.php

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