langwiz.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  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. *This script
  9. *
  10. * @author Nigel McNie, Benny Baumann (BenBE@geshi.org), Andreas 'Segaja' Schleifer (webmaster at segaja dot de)
  11. * @version $Id: langwiz.php 2285 2010-04-10 18:55:11Z segaja $
  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. //Handle crappy PHP magic:
  18. if (get_magic_quotes_gpc()) {
  19. function stripslashes_deep($value) {
  20. $value = is_array($value) ?
  21. array_map('stripslashes_deep', $value) :
  22. stripslashes($value);
  23. return $value;
  24. }
  25. $_POST = array_map('stripslashes_deep', $_POST);
  26. $_GET = array_map('stripslashes_deep', $_GET);
  27. $_COOKIE = array_map('stripslashes_deep', $_COOKIE);
  28. $_REQUEST = array_map('stripslashes_deep', $_REQUEST);
  29. }
  30. function htmlspecialchars_deep($value) {
  31. return is_array($value) ? array_map('htmlspecialchars_deep', $value) : htmlspecialchars($value);
  32. }
  33. define ('TYPE_NOTICE', 0);
  34. define ('TYPE_WARNING', 1);
  35. define ('TYPE_ERROR', 2);
  36. $error_abort = false;
  37. $error_cache = array();
  38. function output_error_cache(){
  39. global $error_cache, $error_abort;
  40. if(count($error_cache)) {
  41. echo "<span style=\"color: #F00; font-weight: bold;\">Failed</span><br />";
  42. echo "<ol>\n";
  43. foreach($error_cache as $error_msg) {
  44. echo "<li>";
  45. switch($error_msg['t']) {
  46. case TYPE_NOTICE:
  47. echo "<span style=\"color: #080; font-weight: bold;\">NOTICE:</span>";
  48. break;
  49. case TYPE_WARNING:
  50. echo "<span style=\"color: #CC0; font-weight: bold;\">WARNING:</span>";
  51. break;
  52. case TYPE_ERROR:
  53. echo "<span style=\"color: #F00; font-weight: bold;\">ERROR:</span>";
  54. break;
  55. }
  56. echo " " . $error_msg['m'] . "</li>";
  57. }
  58. echo "</ol>\n";
  59. } else {
  60. echo "<span style=\"color: #080; font-weight: bold;\">OK</span><br />";
  61. }
  62. echo "\n";
  63. $error_cache = array();
  64. }
  65. function report_error($type, $message) {
  66. global $error_cache, $error_abort;
  67. $error_cache[] = array('t' => $type, 'm' => $message);
  68. if(TYPE_ERROR == $type) {
  69. $error_abort = true;
  70. }
  71. }
  72. function extvar($name, $default){
  73. if(isset($_POST[$name])) {
  74. return $_POST[$name];
  75. }
  76. if(isset($_GET[$name])) {
  77. return $_GET[$name];
  78. }
  79. return $default;
  80. }
  81. ?>
  82. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  83. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  84. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  85. <head>
  86. <title>GeSHi Language File Generator Script</title>
  87. <style type="text/css">
  88. <!--
  89. html {
  90. background-color: #f0f0f0;
  91. }
  92. body {
  93. font-family: Verdana, Arial, sans-serif;
  94. margin: 10px;
  95. border: 2px solid #e0e0e0;
  96. background-color: #fcfcfc;
  97. padding: 5px;
  98. font-size: 10pt;
  99. }
  100. h2 {
  101. margin: .1em 0 .2em .5em;
  102. border-bottom: 1px solid #b0b0b0;
  103. color: #b0b0b0;
  104. font-weight: normal;
  105. font-size: 150%;
  106. }
  107. h3 {
  108. margin: .1em 0 .2em .5em;
  109. color: #b0b0b0;
  110. font-weight: normal;
  111. font-size: 120%;
  112. }
  113. #footer {
  114. text-align: center;
  115. font-size: 80%;
  116. color: #a9a9a9;
  117. }
  118. #footer a {
  119. color: #9999ff;
  120. }
  121. textarea {
  122. border: 1px solid #b0b0b0;
  123. font-size: 90%;
  124. color: #333;
  125. margin-left: 20px;
  126. }
  127. select, input {
  128. margin-left: 2px;
  129. border: 1px solid #808080;
  130. }
  131. p {
  132. font-size: 90%;
  133. margin-left: .5em;
  134. }
  135. fieldset {
  136. border: 1px dotted gray;
  137. background-color: #f0f0f0;
  138. margin-bottom: .5em;
  139. }
  140. legend {
  141. font-weight: bold;
  142. background-color: #f9f9f9;
  143. border: 1px solid #a0a0a0;
  144. border-width: 1px 2px 2px 1px;
  145. }
  146. fieldset table > tbody > tr > td {
  147. width: 20%;
  148. }
  149. fieldset table > tbody > tr > td+td {
  150. width: 80%;
  151. }
  152. fieldset table > tbody > tr > td+td > input {
  153. width: 98%;
  154. }
  155. -->
  156. </style>
  157. </head>
  158. <body>
  159. <h2>GeSHi Language File Generator Script</h2>
  160. <p>To use this script, make sure that <strong>geshi.php</strong> is in the
  161. parent directory or in your include_path, and that the language files are in a
  162. subdirectory of GeSHi's directory called <strong>geshi/</strong>.</p>
  163. <p>If not already done, select a language file below that will be used as
  164. base for the language file to generate or create a blank one. Following this
  165. you can do whatever you like to edit your language file. But note that not all
  166. features are made available through this script.</p>
  167. <p>Checking GeSHi installation ... <?php
  168. // Rudimentary checking of where GeSHi is. In a default install it will be in ../, but
  169. // it could be in the current directory if the include_path is set. There's nowhere else
  170. // we can reasonably guess.
  171. if (is_readable('../geshi.php')) {
  172. $path = '../';
  173. } elseif (is_readable('geshi.php')) {
  174. $path = './';
  175. } else {
  176. report_error(TYPE_ERROR, 'Could not find geshi.php - make sure it is in your include path!');
  177. }
  178. if(!$error_abort) {
  179. require $path . 'geshi.php';
  180. if(!class_exists('GeSHi')) {
  181. report_error(TYPE_ERROR, 'The GeSHi class was not found, although it seemed we loaded the correct file!');
  182. }
  183. }
  184. if(!$error_abort) {
  185. if(!defined('GESHI_LANG_ROOT')) {
  186. report_error(TYPE_ERROR, 'There\'s no information present on where to find the language files!');
  187. } else if(!is_dir(GESHI_LANG_ROOT)) {
  188. report_error(TYPE_ERROR, 'The path "'.GESHI_LANG_ROOT.'" given, does not ressemble a directory!');
  189. } else if(!is_readable(GESHI_LANG_ROOT)) {
  190. report_error(TYPE_ERROR, 'The path "'.GESHI_LANG_ROOT.'" is not readable to this script!');
  191. }
  192. }
  193. if(!$error_abort) {
  194. if (!($dir = @opendir(GESHI_LANG_ROOT))) {
  195. report_error(TYPE_ERROR, 'Error requesting listing for available language files!');
  196. }
  197. $languages = array();
  198. if(!$error_abort) {
  199. while ($file = readdir($dir)) {
  200. if (!$file || $file[0] == '.' || strpos($file, '.') === false) {
  201. continue;
  202. }
  203. $lang = substr($file, 0, strpos($file, '.'));
  204. $languages[] = $lang;
  205. }
  206. closedir($dir);
  207. }
  208. $languages = array_unique($languages);
  209. sort($languages);
  210. if(!count($languages)) {
  211. report_error(TYPE_WARNING, 'Unable to locate any usable language files in "'.GESHI_LANG_ROOT.'"!');
  212. }
  213. }
  214. output_error_cache();
  215. // --- empty variables for values of $_POST - begin ---
  216. $post_var_names = array('li', 'ai', 'ld');
  217. $li = array(
  218. 'file' => 'example',
  219. 'name' => 'Example'
  220. );
  221. $ai = array(
  222. 'name' => 'Benny Baumann',
  223. 'email' => 'BenBE@geshi.org',
  224. 'web' => 'http://qbnz.com/highlighter/'
  225. );
  226. $ld = array(
  227. 'cmt' => array(
  228. 'sl' => array(
  229. 1 => array(
  230. 'start' => '//',
  231. 'style' => 'font-style: italic; color: #666666;'
  232. ),
  233. 2 => array(
  234. 'start' => '#',
  235. 'style' => 'font-style: italic; color: #666666;'
  236. )
  237. ),
  238. 'ml' => array(
  239. 1 => array(
  240. 'start' => '/*',
  241. 'end' => '*/',
  242. 'style' => 'font-style: italic; color: #666666;'
  243. ),
  244. 2 => array(
  245. 'start' => '/**',
  246. 'end' => '*/',
  247. 'style' => 'font-style: italic; color: #006600;'
  248. )
  249. ),
  250. 'rxc' => array(
  251. 1 => array(
  252. 'rx' => '/Hello RegExp/',
  253. 'style' => 'font-style: italic; color: #666666;'
  254. )
  255. )
  256. ),
  257. 'str' => array(
  258. 'qm' => array(
  259. 1 => array(
  260. 'delim' => "'",
  261. 'style' => 'color: #0000FF;'
  262. ),
  263. 2 => array(
  264. 'delim' => "&quot;",
  265. 'style' => 'color: #0000FF;'
  266. )
  267. ),
  268. 'ec' => array(
  269. 'char' => '\\',
  270. 'style' => 'font-weight: bold; color: #000080;'
  271. ),
  272. 'erx' => array(
  273. 1 => array(
  274. 'rx' => '/\{\\\\$\w+\}/',
  275. 'style' => 'font-weight: bold; color: #008080;'
  276. ),
  277. 2 => array(
  278. 'rx'=> '/\{\\\\$\w+\}/',
  279. 'style' => 'font-weight: bold; color: #008080;'
  280. )
  281. )
  282. ),
  283. 'kw_case' => 'GESHI_CAPS_NO_CHANGE',
  284. 'kw' => array(
  285. 1 => array(
  286. 'list' => '',
  287. 'case' => '0',
  288. 'style' => 'color: #0000FF; font-weight: bold;',
  289. 'docs' => ''
  290. )
  291. ),
  292. 'sy' => array(
  293. 0 => array(
  294. 'list' => '',
  295. 'style' => 'color: #0000FF; font-weight: bold;'
  296. )
  297. )
  298. );
  299. $kw_case_sel = array(
  300. 'GESHI_CAPS_NO_CHANGE' => '',
  301. 'GESHI_CAPS_UPPER' => '',
  302. 'GESHI_CAPS_LOWER' => ''
  303. );
  304. $kw_cases_sel = array(
  305. 1 => array(
  306. 0 => '',
  307. 1 => ''
  308. )
  309. );
  310. // --- empty variables for values of $_POST - end ---
  311. echo "<pre>";
  312. //var_dump($languages);
  313. var_dump($_GET);
  314. var_dump($_POST);
  315. foreach($post_var_names as $varName) { // export wanted variables of $_POST array...
  316. if(array_key_exists($varName, $_POST)) {
  317. $$varName = htmlspecialchars_deep($_POST[$varName]);
  318. }
  319. }
  320. // determine the selected kw_case...
  321. $kw_case_sel[$ld['kw_case']] = ' selected="selected"';
  322. // determine the selected kw_cases...
  323. for($i = 1; $i <= count($kw_cases_sel); $i += 1) {
  324. $kw_cases_sel[$i][(int) $ld['kw'][$i]['case']] = ' selected="selected"';
  325. }
  326. $lang = validate_lang();
  327. var_dump($lang);
  328. echo "</pre>";
  329. ?>
  330. <form action="?action=test" method="post">
  331. <fieldset>
  332. <legend>Generic Information</legend>
  333. <table width="100%">
  334. <tr>
  335. <td>
  336. <label for="li[file]">Language File ID:</label>
  337. </td>
  338. <td>
  339. <input type="text" name="li[file]" id="li[file]" value="<?=$li['file']; ?>" />
  340. </td>
  341. </tr>
  342. <tr>
  343. <td>
  344. <label for="li[name]">Language Name:</label>
  345. </td>
  346. <td>
  347. <input type="text" name="li[name]" id="li[name]" value="<?=$li['name']; ?>" />
  348. </td>
  349. </tr>
  350. </table>
  351. </fieldset>
  352. <fieldset>
  353. <legend>Author</legend>
  354. <table width="100%">
  355. <tr>
  356. <td>
  357. <label for="ai[name]">Full Name:</label>
  358. </td>
  359. <td>
  360. <input type="text" name="ai[name]" id="ai[name]" value="<?=$ai['name']; ?>" />
  361. </td>
  362. </tr>
  363. <tr>
  364. <td>
  365. <label for="ai[email]">eMail address:</label>
  366. </td>
  367. <td>
  368. <input type="text" name="ai[email]" id="ai[email]" value="<?=$ai['email']; ?>" />
  369. </td>
  370. </tr>
  371. <tr>
  372. <td>
  373. <label for="ai[web]">Homepage:</label>
  374. </td>
  375. <td>
  376. <input type="text" name="ai[web]" id="ai[web]" value="<?=$ai['web']; ?>" />
  377. </td>
  378. </tr>
  379. </table>
  380. </fieldset>
  381. <fieldset>
  382. <legend>Comments</legend>
  383. <fieldset>
  384. <legend>Single Line</legend>
  385. <fieldset>
  386. <legend>Comment Group 1</legend>
  387. <table width="100%">
  388. <tr>
  389. <td>
  390. <label for="ld[cmt][sl][1][start]">Comment Start:</label>
  391. </td>
  392. <td>
  393. <input type="text" name="ld[cmt][sl][1][start]" id="ld[cmt][sl][1][start]" value="<?=$ld['cmt']['sl'][1]['start']; ?>" />
  394. </td>
  395. </tr>
  396. <tr>
  397. <td>
  398. <label for="ld[cmt][sl][1][style]">Comment Style:</label>
  399. </td>
  400. <td>
  401. <input type="text" name="ld[cmt][sl][1][style]" id="ld[cmt][sl][1][style]" value="<?=$ld['cmt']['sl'][1]['style']; ?>" />
  402. </td>
  403. </tr>
  404. </table>
  405. </fieldset>
  406. <fieldset>
  407. <legend>Comment Group 2</legend>
  408. <table width="100%">
  409. <tr>
  410. <td>
  411. <label for="ld[cmt][sl][2][start]">Comment Start:</label>
  412. </td>
  413. <td>
  414. <input type="text" name="ld[cmt][sl][2][start]" id="ld[cmt][sl][2][start]" value="<?=$ld['cmt']['sl'][2]['start']; ?>" />
  415. </td>
  416. </tr>
  417. <tr>
  418. <td>
  419. <label for="ld[cmt][sl][2][style]">Comment Style:</label>
  420. </td>
  421. <td>
  422. <input type="text" name="ld[cmt][sl][2][style]" id="ld[cmt][sl][2][style]" value="<?=$ld['cmt']['sl'][2]['style']; ?>" />
  423. </td>
  424. </tr>
  425. </table>
  426. </fieldset>
  427. </fieldset>
  428. <fieldset>
  429. <legend>Multiple Lines</legend>
  430. <fieldset>
  431. <legend>Comment Group 1</legend>
  432. <table width="100%">
  433. <tr>
  434. <td>
  435. <label for="ld[cmt][ml][1][start]">Comment Start:</label>
  436. </td>
  437. <td>
  438. <input type="text" name="ld[cmt][ml][1][start]" id="ld[cmt][ml][1][start]" value="<?=$ld['cmt']['ml'][1]['start']; ?>" />
  439. </td>
  440. </tr>
  441. <tr>
  442. <td>
  443. <label for="ld[cmt][ml][1][end]">Comment End:</label>
  444. </td>
  445. <td>
  446. <input type="text" name="ld[cmt][ml][1][end]" id="ld[cmt][ml][1][end]" value="<?=$ld['cmt']['ml'][1]['end']; ?>" />
  447. </td>
  448. </tr>
  449. <tr>
  450. <td>
  451. <label for="ld[cmt][ml][1][style]">Comment Style:</label>
  452. </td>
  453. <td>
  454. <input type="text" name="ld[cmt][ml][1][style]" id="ld[cmt][ml][1][style]" value="<?=$ld['cmt']['ml'][1]['style']; ?>" />
  455. </td>
  456. </tr>
  457. </table>
  458. </fieldset>
  459. <fieldset>
  460. <legend>Comment Group 2</legend>
  461. <table width="100%">
  462. <tr>
  463. <td>
  464. <label for="ld[cmt][ml][2][start]">Comment Start:</label>
  465. </td>
  466. <td>
  467. <input type="text" name="ld[cmt][ml][2][start]" id="ld[cmt][ml][2][start]" value="<?=$ld['cmt']['ml'][2]['start']; ?>" />
  468. </td>
  469. </tr>
  470. <tr>
  471. <td>
  472. <label for="ld[cmt][ml][2][end]">Comment End:</label>
  473. </td>
  474. <td>
  475. <input type="text" name="ld[cmt][ml][2][end]" id="ld[cmt][ml][2][end]" value="<?=$ld['cmt']['ml'][2]['end']; ?>" />
  476. </td>
  477. </tr>
  478. <tr>
  479. <td>
  480. <label for="ld[cmt][ml][2][style]">Comment Style:</label>
  481. </td>
  482. <td>
  483. <input type="text" name="ld[cmt][ml][2][style]" id="ld[cmt][ml][2][style]" value="<?=$ld['cmt']['ml'][2]['style']; ?>" />
  484. </td>
  485. </tr>
  486. </table>
  487. </fieldset>
  488. </fieldset>
  489. <fieldset>
  490. <legend>Regular Expressions</legend>
  491. <fieldset>
  492. <legend>Comment Group 1</legend>
  493. <table width="100%">
  494. <tr>
  495. <td>
  496. <label for="ld[cmt][rxc][1][rx]">Comment RX:</label>
  497. </td>
  498. <td>
  499. <input type="text" name="ld[cmt][rxc][1][rx]" id="ld[cmt][rxc][1][rx]" value="<?=$ld['cmt']['rxc'][1]['rx']; ?>" />
  500. </td>
  501. </tr>
  502. <tr>
  503. <td>
  504. <label for="ld[cmt][rxc][1][style]">Comment Style:</label>
  505. </td>
  506. <td>
  507. <input type="text" name="ld[cmt][rxc][1][style]" id="ld[cmt][rxc][1][style]" value="<?=$ld['cmt']['rxc'][1]['style']; ?>" />
  508. </td>
  509. </tr>
  510. </table>
  511. </fieldset>
  512. </fieldset>
  513. </fieldset>
  514. <fieldset>
  515. <legend>Strings</legend>
  516. <fieldset>
  517. <legend>String \ Quotes (delimiters, parsed)</legend>
  518. <fieldset>
  519. <legend>Quotemark Group 1</legend>
  520. <table width="100%">
  521. <tr>
  522. <td>
  523. <label for="ld[str][qm][1][delim]">String Delimiter:</label>
  524. </td>
  525. <td>
  526. <input type="text" name="ld[str][qm][1][delim]" id="ld[str][qm][1][delim]" value="<?=$ld['str']['qm'][1]['delim']; ?>" />
  527. </td>
  528. </tr>
  529. <tr>
  530. <td>
  531. <label for="ld[str][qm][1][style]">String Style:</label>
  532. </td>
  533. <td>
  534. <input type="text" name="ld[str][qm][1][style]" id="ld[str][qm][1][style]" value="<?=$ld['str']['qm'][1]['style']; ?>" />
  535. </td>
  536. </tr>
  537. </table>
  538. </fieldset>
  539. <fieldset>
  540. <legend>Quotemark Group 2</legend>
  541. <table width="100%">
  542. <tr>
  543. <td>
  544. <label for="ld[str][qm][1][delim]">String Delimiter:</label>
  545. </td>
  546. <td>
  547. <input type="text" name="ld[str][qm][2][delim]" id="ld[str][qm][2][delim]" value="<?=$ld['str']['qm'][2]['delim']; ?>" />
  548. </td>
  549. </tr>
  550. <tr>
  551. <td>
  552. <label for="ld[str][qm][1][style]">String Style:</label>
  553. </td>
  554. <td>
  555. <input type="text" name="ld[str][qm][2][style]" id="ld[str][qm][2][style]" value="<?=$ld['str']['qm'][2]['style']; ?>" />
  556. </td>
  557. </tr>
  558. </table>
  559. </fieldset>
  560. </fieldset>
  561. <fieldset>
  562. <legend>Escape Sequences</legend>
  563. <fieldset>
  564. <legend>Generic Escape Char</legend>
  565. <table width="100%">
  566. <tr>
  567. <td>
  568. <label for="ld[str][ec][char]">Escape Char:</label>
  569. </td>
  570. <td>
  571. <input type="text" name="ld[str][ec][char]" id="ld[str][ec][char]" value="<?=$ld['str']['ec']['char']; ?>" />
  572. </td>
  573. </tr>
  574. <tr>
  575. <td>
  576. <label for="ld[str][ec][style]">Escape Char Style:</label>
  577. </td>
  578. <td>
  579. <input type="text" name="ld[str][ec][style]" id="ld[str][ec][style]" value="<?=$ld['str']['ec']['style']; ?>" />
  580. </td>
  581. </tr>
  582. </table>
  583. </fieldset>
  584. <fieldset>
  585. <legend>Escape Regexp Group 1</legend>
  586. <table width="100%">
  587. <tr>
  588. <td>
  589. <label for="ld[str][erx][1][rx]">Escape Regexp:</label>
  590. </td>
  591. <td>
  592. <input type="text" name="ld[str][erx][1][rx]" id="ld[str][erx][1][rx]" value="<?=$ld['str']['erx'][1]['rx']; ?>" />
  593. </td>
  594. </tr>
  595. <tr>
  596. <td>
  597. <label for="ld[str][erx][1][style]">Escape Style:</label>
  598. </td>
  599. <td>
  600. <input type="text" name="ld[str][erx][1][style]" id="ld[str][erx][1][style]" value="<?=$ld['str']['erx'][1]['style']; ?>" />
  601. </td>
  602. </tr>
  603. </table>
  604. </fieldset>
  605. <fieldset>
  606. <legend>Escape Regexp Group 2</legend>
  607. <table width="100%">
  608. <tr>
  609. <td>
  610. <label for="ld[str][erx][2][rx]">Escape Regexp:</label>
  611. </td>
  612. <td>
  613. <input type="text" name="ld[str][erx][2][rx]" id="ld[str][erx][2][rx]" value="<?=$ld['str']['erx'][2]['rx']; ?>" />
  614. </td>
  615. </tr>
  616. <tr>
  617. <td>
  618. <label for="ld[str][erx][2][style]">Escape Style:</label>
  619. </td>
  620. <td>
  621. <input type="text" name="ld[str][erx][2][style]" id="ld[str][erx][2][style]" value="<?=$ld['str']['erx'][2]['style']; ?>" />
  622. </td>
  623. </tr>
  624. </table>
  625. </fieldset>
  626. </fieldset>
  627. </fieldset>
  628. <fieldset>
  629. <legend>Keywords</legend>
  630. <fieldset>
  631. <legend>Case of Keywords</legend>
  632. <table width="100%">
  633. <tr>
  634. <td>
  635. <label for="ld[kw_case]">Handling of keywords case:</label>
  636. </td>
  637. <td>
  638. <select name=ld[kw_case]" id="ld[kw_case]">
  639. <option value="GESHI_CAPS_NO_CHANGE"<?=$kw_case_sel['GESHI_CAPS_NO_CHANGE']; ?>>Don’t change the case of any keyword</option>
  640. <option value="GESHI_CAPS_UPPER"<?=$kw_case_sel['GESHI_CAPS_UPPER']; ?>>Convert the case of all keywords to upper case</option>
  641. <option value="GESHI_CAPS_LOWER"<?=$kw_case_sel['GESHI_CAPS_LOWER']; ?>>Convert the case of all keywords to lower case</option>
  642. </select>
  643. </td>
  644. </tr>
  645. </table>
  646. </fieldset>
  647. <fieldset>
  648. <legend>Keyword Group 1</legend>
  649. <table width="100%">
  650. <tr>
  651. <td>
  652. <label for="ld[kw][1][list]">Keyword List:</label>
  653. </td>
  654. <td>
  655. <textarea name="ld[kw][1][list]" id="ld[kw][1][list]" rows="10" cols="80"><?=$ld['kw'][1]['list']; ?></textarea>
  656. </td>
  657. </tr>
  658. <tr>
  659. <td>
  660. <label for="ld[kw][1][case]">Case Sensitive:</label>
  661. </td>
  662. <td>
  663. <select name="ld[kw][1][case]" id="ld[kw][1][case]">
  664. <option value="0"<?=$kw_cases_sel[1][0]; ?>>No</option>
  665. <option value="1"<?=$kw_cases_sel[1][1]; ?>>Yes</option>
  666. </select>
  667. </td>
  668. </tr>
  669. <tr>
  670. <td>
  671. <label for="ld[kw][1][style]">Keyword Style:</label>
  672. </td>
  673. <td>
  674. <input type="text" name="ld[kw][1][style]" id="ld[kw][1][style]" value="<?=$ld['kw'][1]['style']; ?>" />
  675. </td>
  676. </tr>
  677. <tr>
  678. <td>
  679. <label for="ld[kw][1][docs]">Documentation URL:</label>
  680. </td>
  681. <td>
  682. <input type="text" name="ld[kw][1][docs]" id="ld[kw][1][docs]" value="<?=$ld['kw'][1]['docs']; ?>" />
  683. </td>
  684. </tr>
  685. </table>
  686. </fieldset>
  687. </fieldset>
  688. <fieldset>
  689. <legend>Symbols</legend>
  690. <fieldset>
  691. <legend>Symbols Group 1</legend>
  692. <table width="100%">
  693. <tr>
  694. <td>
  695. <label for="ld[sy][0][list]">Symbols List:</label>
  696. </td>
  697. <td>
  698. <textarea name="ld[sy][0][list]" id="ld[sy][0][list]" rows="10" cols="80"><?=$ld['sy'][0]['list']; ?></textarea>
  699. </td>
  700. </tr>
  701. <tr>
  702. <td>
  703. <label for="ld[sy][0][style]">Symbols Style:</label>
  704. </td>
  705. <td>
  706. <input type="text" name="ld[sy][0][style]" id="ld[sy][0][style]" value="<?=$ld['sy'][0]['style']; ?>" />
  707. </td>
  708. </tr>
  709. </table>
  710. </fieldset>
  711. </fieldset>
  712. <div id="langfile">
  713. <fieldset>
  714. <legend>Language File Source</legend>
  715. <?
  716. $G = new GeSHi('', 'php');
  717. $langfile_source = gen_langfile($lang);
  718. $G->set_source($langfile_source);
  719. echo $G->parse_code();
  720. unset($G);
  721. ?>
  722. </fieldset>
  723. </div>
  724. <input type="submit" name="btn" value="Send!" />
  725. </form>
  726. <p>Operation completed in <?
  727. $time_end = explode(' ', microtime());
  728. $time_diff = $time_end[0] + $time_end[1] - $time_start[0] - $time_start[1];
  729. echo sprintf("%.2f", $time_diff);
  730. ?> seconds.</p>
  731. <div id="footer">GeSHi &copy; 2004-2007 Nigel McNie, 2007-2009 Benny Baumann, released under the GNU GPL</div>
  732. </body>
  733. </html>
  734. <?
  735. function str_to_phpstring($str, $doublequote = false){
  736. if($doublequote) {
  737. return '"' . strtr($str,
  738. array(
  739. "\"" => "\\\"",
  740. "\\" => "\\\\",
  741. "\0" => "\\0",
  742. "\n" => "\\n",
  743. "\r" => "\\r",
  744. "\t" => "\\t",
  745. "\$" => "\\\$"
  746. )
  747. ) . '"';
  748. } else {
  749. return "'" . strtr($str,
  750. array(
  751. "'" => "\\'",
  752. "\\" => "\\\\"
  753. )
  754. ) . "'";
  755. }
  756. }
  757. function validate_lang(){
  758. $ai = array(
  759. 'name' => 'Benny Baumann',
  760. 'email' => 'BenBE@geshi.org',
  761. 'web' => 'http://qbnz.com/highlighter/'
  762. );
  763. $li = array(
  764. 'file' => 'example',
  765. 'desc' => 'Example'
  766. );
  767. if(isset($_POST['ld'])) {
  768. $ld = $_POST['ld'];
  769. } else {
  770. $ld = array(
  771. 'cmt' => array(
  772. 'sl' => array(
  773. 1 => array(
  774. 'start' => '//',
  775. 'style' => 'test'
  776. )
  777. ),
  778. 'ml' => array(
  779. 1 => array(
  780. 'start' => '/*',
  781. 'end' => '*/',
  782. 'style' => 'font-style: italic; color: #666666;'
  783. )
  784. ),
  785. 'rxc' => array(
  786. 1 => array(
  787. 'rx' => '/Hello/',
  788. 'style' => 'color: #00000'
  789. )
  790. )
  791. ),
  792. 'str' => array(
  793. 'qm' => array(),
  794. 'ec' => array(
  795. 'char' => ''
  796. ),
  797. 'erx' => array()
  798. ),
  799. 'kw' => array(),
  800. 'kw_case' => 'GESHI_CAPS_NO_CHANGE',
  801. 'sy' => array()
  802. );
  803. }
  804. return array('ai' => $ai, 'li' => $li, 'ld' => $ld);
  805. }
  806. function gen_langfile($lang){
  807. $langfile = $lang['li']['file'];
  808. $langdesc = $lang['li']['desc'];
  809. $langauthor_name = $lang['ai']['name'];
  810. $langauthor_email = $lang['ai']['email'];
  811. $langauthor_web = $lang['ai']['web'];
  812. $langversion = GESHI_VERSION;
  813. $langdate = date('Y/m/d');
  814. $langyear = date('Y');
  815. $i = ' ';
  816. $i = array('', $i, $i.$i, $i.$i.$i);
  817. $src = <<<GESHI_LANGFILE_HEAD
  818. <?php
  819. /*************************************************************************************
  820. * {$langfile}.php
  821. * --------
  822. * Author: {$langauthor_name} ({$langauthor_email})
  823. * Copyright: (c) {$langyear} {$langauthor_name} ({$langauthor_web})
  824. * Release Version: {$langversion}
  825. * Date Started: {$langdate}
  826. *
  827. * {$langdesc} language file for GeSHi.
  828. *
  829. * CHANGES
  830. * -------
  831. * {$langdate} ({$langversion})
  832. * - First Release
  833. *
  834. * TODO (updated {$langdate})
  835. * -------------------------
  836. * * Complete language file
  837. *
  838. *************************************************************************************
  839. *
  840. * This file is part of GeSHi.
  841. *
  842. * GeSHi is free software; you can redistribute it and/or modify
  843. * it under the terms of the GNU General Public License as published by
  844. * the Free Software Foundation; either version 2 of the License, or
  845. * (at your option) any later version.
  846. *
  847. * GeSHi is distributed in the hope that it will be useful,
  848. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  849. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  850. * GNU General Public License for more details.
  851. *
  852. * You should have received a copy of the GNU General Public License
  853. * along with GeSHi; if not, write to the Free Software
  854. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  855. *
  856. ************************************************************************************/
  857. \$language_data = array(
  858. GESHI_LANGFILE_HEAD;
  859. //Language Name
  860. $src .= $i[1] . "'LANG_NAME' => ".str_to_phpstring($langdesc).",\n";
  861. //Comments
  862. $src .= $i[1] . "'COMMENT_SINGLE' => array(\n";
  863. foreach($lang['ld']['cmt']['sl'] as $idx_cmt_sl => $tmp_cmt_sl) {
  864. $src .= $i[2] . ((int)$idx_cmt_sl). " => ". str_to_phpstring($tmp_cmt_sl['start']) . ",\n";
  865. }
  866. $src .= $i[2] . "),\n";
  867. $src .= $i[1] . "'COMMENT_MULTI' => array(\n";
  868. foreach($lang['ld']['cmt']['ml'] as $tmp_cmt_ml) {
  869. $src .= $i[2] . str_to_phpstring($tmp_cmt_ml['start']). " => ". str_to_phpstring($tmp_cmt_ml['end']) . ",\n";
  870. }
  871. $src .= $i[2] . "),\n";
  872. $src .= $i[1] . "'COMMENT_REGEXP' => array(\n";
  873. foreach($lang['ld']['cmt']['rxc'] as $idx_cmt_rxc => $tmp_cmt_rxc) {
  874. $src .= $i[2] . ((int)$idx_cmt_rxc). " => ". str_to_phpstring($tmp_cmt_rxc['rx']) . ",\n";
  875. }
  876. $src .= $i[2] . "),\n";
  877. //Case Keywords
  878. $src .= $i[1] . "'CASE_KEYWORDS' => " . $lang['ld']['kw_case'] . ",\n";
  879. //Quotes \ Strings
  880. $src .= $i[1] . "'QUOTEMARKS' => array(\n";
  881. foreach($lang['ld']['str']['qm'] as $idx_str_qm => $tmp_str_qm) {
  882. $src .= $i[2] . ((int)$idx_str_qm). " => ". str_to_phpstring($tmp_str_qm['delim']) . ",\n";
  883. }
  884. $src .= $i[2] . "),\n";
  885. $src .= $i[1] . "'ESCAPE_CHAR' => " . str_to_phpstring($lang['ld']['str']['ec']['char']) . ",\n";
  886. $src .= $i[1] . "'ESCAPE_REGEXP' => array(\n";
  887. foreach($lang['ld']['str']['erx'] as $idx_str_erx => $tmp_str_erx) {
  888. $src .= $i[2] . ((int)$idx_str_erx). " => ". str_to_phpstring($tmp_str_erx['rx']) . ",\n";
  889. }
  890. $src .= $i[2] . "),\n";
  891. //HardQuotes
  892. $src .= $i[1] . "'HARDQUOTE' => array(\n";
  893. $src .= $i[2] . "),\n";
  894. $src .= $i[1] . "'HARDESCAPE' => array(\n";
  895. $src .= $i[2] . "),\n";
  896. $src .= $i[1] . "'HARDCHAR' => '',\n";
  897. //Numbers
  898. $src .= $i[1] . "'NUMBERS' =>\n";
  899. $src .= $i[2] . "GESHI_NUMBER_INT_BASIC | GESHI_NUMBER_OCT_PREFIX | GESHI_NUMBER_HEX_PREFIX |\n";
  900. $src .= $i[2] . "GESHI_NUMBER_FLT_SCI_ZERO,\n";
  901. //Keywords
  902. $src .= $i[1] . "'KEYWRODS' => array(\n";
  903. foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) {
  904. $src .= $i[2] . ((int)$idx_kw) . " => array(\n";
  905. if(!is_array($tmp_kw['list'])) {
  906. $tmp_kw['list'] = explode("\n", $tmp_kw['list']);
  907. }
  908. $tmp_kw['list'] = array_map('trim', $tmp_kw['list']);
  909. sort($tmp_kw['list']);
  910. $kw_esc = array_map('str_to_phpstring', $tmp_kw['list']);
  911. $kw_nl = true;
  912. $kw_pos = 0;
  913. foreach($kw_esc as $kw_data) {
  914. if((strlen($kw_data) + $kw_pos > 79) && $kw_pos > strlen($i[3])) {
  915. $src .= "\n";
  916. $kw_nl = true;
  917. $kw_pos = 0;
  918. }
  919. if($kw_nl) {
  920. $src .= $i[3];
  921. $kw_pos += strlen($i[3]);
  922. $kw_nl = false;
  923. }
  924. $src .= $kw_data . ', ';
  925. $kw_pos += strlen($kw_data) + 2;
  926. }
  927. $src .= "\n";
  928. $src .= $i[3] . "),\n";
  929. }
  930. $src .= $i[2] . "),\n";
  931. //Case Sensitivity
  932. $src .= $i[1] . "'CASE_SENSITIVE' => array(\n";
  933. foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) {
  934. $src .= $i[2] . ((int)$idx_kw) . " => " . ($tmp_kw['case'] ? 'true' : 'false') . ",\n";
  935. }
  936. $src .= $i[2] . "),\n";
  937. //Symbols
  938. $src .= $i[1] . "'SYMBOLS' => array(\n";
  939. foreach($lang['ld']['sy'] as $idx_kw => $tmp_kw) {
  940. $src .= $i[2] . ((int)$idx_kw) . " => array(\n";
  941. $tmp_kw['list'] = (array)$tmp_kw['list'];
  942. sort($tmp_kw['list']);
  943. $kw_esc = array_map('str_to_phpstring', $tmp_kw['list']);
  944. $kw_nl = true;
  945. $kw_pos = strlen($i[3]);
  946. foreach($kw_esc as $kw_data) {
  947. if((strlen($kw_data) + $kw_pos > 79) && $kw_pos > strlen($i[3])) {
  948. $src .= "\n";
  949. $kw_nl = true;
  950. $kw_pos = 0;
  951. }
  952. if($kw_nl) {
  953. $src .= $i[3];
  954. $kw_pos += strlen($i[3]);
  955. $kw_nl = false;
  956. }
  957. $src .= $kw_data . ', ';
  958. $kw_pos += strlen($kw_data) + 2;
  959. }
  960. $src .= "\n";
  961. $src .= $i[3] . "),\n";
  962. }
  963. $src .= $i[2] . "),\n";
  964. //Styles \ CSS
  965. $src .= $i[1] . "'STYLES' => array(\n";
  966. $src .= $i[2] . "'KEYWRODS' => array(\n";
  967. foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) {
  968. $src .= $i[3] . ((int)$idx_kw) . " => " . str_to_phpstring($tmp_kw['style']) . ",\n";
  969. }
  970. $src .= $i[3] . "),\n";
  971. $src .= $i[2] . "'COMMENTS' => array(\n";
  972. foreach($lang['ld']['cmt']['sl'] as $idx_cmt_sl => $tmp_cmt_sl) {
  973. $src .= $i[3] . ((int)$idx_cmt_sl) . " => " . str_to_phpstring($tmp_cmt_sl['style']) . ",\n";
  974. }
  975. foreach($lang['ld']['cmt']['rxc'] as $idx_cmt_rxc => $tmp_cmt_rxc) {
  976. $src .= $i[3] . ((int)$idx_cmt_rxc) . " => " . str_to_phpstring($tmp_cmt_rxc['style']) . ",\n";
  977. }
  978. $src .= $i[3] . "'MULTI' => " . str_to_phpstring($lang['ld']['cmt']['ml'][1]['style']) . "\n";
  979. $src .= $i[3] . "),\n";
  980. $src .= $i[2] . "'ESCAPE_CHAR' => array(\n";
  981. foreach($lang['ld']['str']['erx'] as $idx_str_erx => $tmp_str_erx) {
  982. $src .= $i[3] . ((int)$idx_str_erx). " => ". str_to_phpstring($tmp_str_erx['style']) . ",\n";
  983. }
  984. // 'HARD' => 'color: #000099; font-weight: bold;'
  985. $src .= $i[3] . "),\n";
  986. $src .= $i[2] . "'BRACKETS' => array(\n";
  987. $src .= $i[3] . "),\n";
  988. $src .= $i[2] . "'STRINGS' => array(\n";
  989. foreach($lang['ld']['str']['qm'] as $idx_str_qm => $tmp_str_qm) {
  990. $src .= $i[3] . ((int)$idx_str_qm). " => ". str_to_phpstring($tmp_str_qm['style']) . ",\n";
  991. }
  992. // 'HARD' => 'color: #0000ff;'
  993. $src .= $i[3] . "),\n";
  994. $src .= $i[2] . "'NUMBERS' => array(\n";
  995. $src .= $i[3] . "),\n";
  996. $src .= $i[2] . "'METHODS' => array(\n";
  997. $src .= $i[3] . "),\n";
  998. $src .= $i[2] . "'SYMBOLS' => array(\n";
  999. foreach($lang['ld']['sy'] as $idx_kw => $tmp_kw) {
  1000. $src .= $i[3] . ((int)$idx_kw) . " => " . str_to_phpstring($tmp_kw['style']) . ",\n";
  1001. }
  1002. $src .= $i[3] . "),\n";
  1003. $src .= $i[2] . "'REGEXPS' => array(\n";
  1004. $src .= $i[3] . "),\n";
  1005. $src .= $i[2] . "'SCRIPT' => array(\n";
  1006. $src .= $i[3] . "),\n";
  1007. $src .= $i[2] . "),\n";
  1008. //Keyword Documentation
  1009. $src .= $i[1] . "'URLS' => array(\n";
  1010. foreach($lang['ld']['kw'] as $idx_kw => $tmp_kw) {
  1011. $src .= $i[2] . ((int)$idx_kw) . " => " . str_to_phpstring($tmp_kw['docs']) . ",\n";
  1012. }
  1013. $src .= $i[2] . "),\n";
  1014. $src .= $i[1] . "'OOLANG' => false,\n";
  1015. $src .= $i[1] . "'OBJECT_SPLITTERS' => array(\n";
  1016. $src .= $i[2] . "),\n";
  1017. $src .= $i[1] . "'REGEXPS' => array(\n";
  1018. $src .= $i[2] . "),\n";
  1019. $src .= $i[1] . "'STRICT_MODE_APPLIES' => GESHI_MAYBE,\n";
  1020. $src .= $i[1] . "'SCRIPT_DELIMITERS' => array(\n";
  1021. $src .= $i[2] . "),\n";
  1022. $src .= $i[1] . "'HIGHLIGHT_STRICT_BLOCK' => array(\n";
  1023. $src .= $i[2] . "),\n";
  1024. $src .= $i[1] . "'TAB_WIDTH' => 4,\n";
  1025. $src .= <<<GESHI_LANGFILE_FOOTER
  1026. );
  1027. ?>
  1028. GESHI_LANGFILE_FOOTER;
  1029. //Reduce source ...
  1030. $src = preg_replace('/array\(\s*\)/s', 'array()', $src);
  1031. $src = preg_replace('/\,(\s*\))/s', '\1', $src);
  1032. $src = preg_replace('/\s+$/m', '', $src);
  1033. return $src;
  1034. }
  1035. // vim: shiftwidth=4 softtabstop=4
  1036. ?>