PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/mysql-profiler/lib/geshi/geshi.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 2913 lines | 1487 code | 213 blank | 1213 comment | 478 complexity | ae8f957a5e00d4d5ed7bcc73a22ab1f3 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * GeSHi - Generic Syntax Highlighter
  4. *
  5. * The GeSHi class for Generic Syntax Highlighting. Please refer to the
  6. * documentation at http://qbnz.com/highlighter/documentation.php for more
  7. * information about how to use this class.
  8. *
  9. * For changes, release notes, TODOs etc, see the relevant files in the docs/
  10. * directory.
  11. *
  12. * This file is part of GeSHi.
  13. *
  14. * GeSHi is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * GeSHi is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with GeSHi; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. * @package geshi
  29. * @subpackage core
  30. * @author Nigel McNie <nigel@geshi.org>
  31. * @copyright (C) 2004 - 2007 Nigel McNie
  32. * @license http://gnu.org/copyleft/gpl.html GNU GPL
  33. *
  34. */
  35. //
  36. // GeSHi Constants
  37. // You should use these constant names in your programs instead of
  38. // their values - you never know when a value may change in a future
  39. // version
  40. //
  41. /** The version of this GeSHi file */
  42. define('GESHI_VERSION', '1.0.7.20');
  43. // Define the root directory for the GeSHi code tree
  44. if (!defined('GESHI_ROOT')) {
  45. /** The root directory for GeSHi */
  46. define('GESHI_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  47. }
  48. /** The language file directory for GeSHi
  49. @access private */
  50. define('GESHI_LANG_ROOT', GESHI_ROOT . 'geshi' . DIRECTORY_SEPARATOR);
  51. // Line numbers - use with enable_line_numbers()
  52. /** Use no line numbers when building the result */
  53. define('GESHI_NO_LINE_NUMBERS', 0);
  54. /** Use normal line numbers when building the result */
  55. define('GESHI_NORMAL_LINE_NUMBERS', 1);
  56. /** Use fancy line numbers when building the result */
  57. define('GESHI_FANCY_LINE_NUMBERS', 2);
  58. // Container HTML type
  59. /** Use nothing to surround the source */
  60. define('GESHI_HEADER_NONE', 0);
  61. /** Use a "div" to surround the source */
  62. define('GESHI_HEADER_DIV', 1);
  63. /** Use a "pre" to surround the source */
  64. define('GESHI_HEADER_PRE', 2);
  65. // Capatalisation constants
  66. /** Lowercase keywords found */
  67. define('GESHI_CAPS_NO_CHANGE', 0);
  68. /** Uppercase keywords found */
  69. define('GESHI_CAPS_UPPER', 1);
  70. /** Leave keywords found as the case that they are */
  71. define('GESHI_CAPS_LOWER', 2);
  72. // Link style constants
  73. /** Links in the source in the :link state */
  74. define('GESHI_LINK', 0);
  75. /** Links in the source in the :hover state */
  76. define('GESHI_HOVER', 1);
  77. /** Links in the source in the :active state */
  78. define('GESHI_ACTIVE', 2);
  79. /** Links in the source in the :visited state */
  80. define('GESHI_VISITED', 3);
  81. // Important string starter/finisher
  82. // Note that if you change these, they should be as-is: i.e., don't
  83. // write them as if they had been run through htmlentities()
  84. /** The starter for important parts of the source */
  85. define('GESHI_START_IMPORTANT', '<BEGIN GeSHi>');
  86. /** The ender for important parts of the source */
  87. define('GESHI_END_IMPORTANT', '<END GeSHi>');
  88. /**#@+
  89. * @access private
  90. */
  91. // When strict mode applies for a language
  92. /** Strict mode never applies (this is the most common) */
  93. define('GESHI_NEVER', 0);
  94. /** Strict mode *might* apply, and can be enabled or
  95. disabled by {@link GeSHi::enable_strict_mode()} */
  96. define('GESHI_MAYBE', 1);
  97. /** Strict mode always applies */
  98. define('GESHI_ALWAYS', 2);
  99. // Advanced regexp handling constants, used in language files
  100. /** The key of the regex array defining what to search for */
  101. define('GESHI_SEARCH', 0);
  102. /** The key of the regex array defining what bracket group in a
  103. matched search to use as a replacement */
  104. define('GESHI_REPLACE', 1);
  105. /** The key of the regex array defining any modifiers to the regular expression */
  106. define('GESHI_MODIFIERS', 2);
  107. /** The key of the regex array defining what bracket group in a
  108. matched search to put before the replacement */
  109. define('GESHI_BEFORE', 3);
  110. /** The key of the regex array defining what bracket group in a
  111. matched search to put after the replacement */
  112. define('GESHI_AFTER', 4);
  113. /** The key of the regex array defining a custom keyword to use
  114. for this regexp's html tag class */
  115. define('GESHI_CLASS', 5);
  116. /** Used in language files to mark comments */
  117. define('GESHI_COMMENTS', 0);
  118. // Error detection - use these to analyse faults
  119. /** No sourcecode to highlight was specified
  120. * @deprecated
  121. */
  122. define('GESHI_ERROR_NO_INPUT', 1);
  123. /** The language specified does not exist */
  124. define('GESHI_ERROR_NO_SUCH_LANG', 2);
  125. /** GeSHi could not open a file for reading (generally a language file) */
  126. define('GESHI_ERROR_FILE_NOT_READABLE', 3);
  127. /** The header type passed to {@link GeSHi::set_header_type()} was invalid */
  128. define('GESHI_ERROR_INVALID_HEADER_TYPE', 4);
  129. /** The line number type passed to {@link GeSHi::enable_line_numbers()} was invalid */
  130. define('GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5);
  131. /**#@-*/
  132. /**
  133. * The GeSHi Class.
  134. *
  135. * Please refer to the documentation for GeSHi 1.0.X that is available
  136. * at http://qbnz.com/highlighter/documentation.php for more information
  137. * about how to use this class.
  138. *
  139. * @package geshi
  140. * @author Nigel McNie <nigel@geshi.org>
  141. * @copyright (C) 2004 - 2007 Nigel McNie
  142. */
  143. class GeSHi {
  144. /**#@+
  145. * @access private
  146. */
  147. /**
  148. * The source code to highlight
  149. * @var string
  150. */
  151. var $source = '';
  152. /**
  153. * The language to use when highlighting
  154. * @var string
  155. */
  156. var $language = '';
  157. /**
  158. * The data for the language used
  159. * @var array
  160. */
  161. var $language_data = array();
  162. /**
  163. * The path to the language files
  164. * @var string
  165. */
  166. var $language_path = GESHI_LANG_ROOT;
  167. /**
  168. * The error message associated with an error
  169. * @var string
  170. * @todo check err reporting works
  171. */
  172. var $error = false;
  173. /**
  174. * Possible error messages
  175. * @var array
  176. */
  177. var $error_messages = array(
  178. GESHI_ERROR_NO_SUCH_LANG => 'GeSHi could not find the language {LANGUAGE} (using path {PATH})',
  179. GESHI_ERROR_FILE_NOT_READABLE => 'The file specified for load_from_file was not readable',
  180. GESHI_ERROR_INVALID_HEADER_TYPE => 'The header type specified is invalid',
  181. GESHI_ERROR_INVALID_LINE_NUMBER_TYPE => 'The line number type specified is invalid'
  182. );
  183. /**
  184. * Whether highlighting is strict or not
  185. * @var boolean
  186. */
  187. var $strict_mode = false;
  188. /**
  189. * Whether to use CSS classes in output
  190. * @var boolean
  191. */
  192. var $use_classes = false;
  193. /**
  194. * The type of header to use. Can be one of the following
  195. * values:
  196. *
  197. * - GESHI_HEADER_PRE: Source is outputted in a "pre" HTML element.
  198. * - GESHI_HEADER_DIV: Source is outputted in a "div" HTML element.
  199. * - GESHI_HEADER_NONE: No header is outputted.
  200. *
  201. * @var int
  202. */
  203. var $header_type = GESHI_HEADER_PRE;
  204. /**
  205. * Array of permissions for which lexics should be highlighted
  206. * @var array
  207. */
  208. var $lexic_permissions = array(
  209. 'KEYWORDS' => array(),
  210. 'COMMENTS' => array('MULTI' => true),
  211. 'REGEXPS' => array(),
  212. 'ESCAPE_CHAR' => true,
  213. 'BRACKETS' => true,
  214. 'SYMBOLS' => true,
  215. 'STRINGS' => true,
  216. 'NUMBERS' => true,
  217. 'METHODS' => true,
  218. 'SCRIPT' => true
  219. );
  220. /**
  221. * The time it took to parse the code
  222. * @var double
  223. */
  224. var $time = 0;
  225. /**
  226. * The content of the header block
  227. * @var string
  228. */
  229. var $header_content = '';
  230. /**
  231. * The content of the footer block
  232. * @var string
  233. */
  234. var $footer_content = '';
  235. /**
  236. * The style of the header block
  237. * @var string
  238. */
  239. var $header_content_style = '';
  240. /**
  241. * The style of the footer block
  242. * @var string
  243. */
  244. var $footer_content_style = '';
  245. /**
  246. * Tells if a block around the highlighted source should be forced
  247. * if not using line numbering
  248. * @var boolean
  249. */
  250. var $force_code_block = false;
  251. /**
  252. * The styles for hyperlinks in the code
  253. * @var array
  254. */
  255. var $link_styles = array();
  256. /**
  257. * Whether important blocks should be recognised or not
  258. * @var boolean
  259. * @deprecated
  260. * @todo REMOVE THIS FUNCTIONALITY!
  261. */
  262. var $enable_important_blocks = false;
  263. /**
  264. * Styles for important parts of the code
  265. * @var string
  266. * @deprecated
  267. * @todo As above - rethink the whole idea of important blocks as it is buggy and
  268. * will be hard to implement in 1.2
  269. */
  270. var $important_styles = 'font-weight: bold; color: red;'; // Styles for important parts of the code
  271. /**
  272. * Whether CSS IDs should be added to the code
  273. * @var boolean
  274. */
  275. var $add_ids = false;
  276. /**
  277. * Lines that should be highlighted extra
  278. * @var array
  279. */
  280. var $highlight_extra_lines = array();
  281. /**
  282. * Styles of extra-highlighted lines
  283. * @var string
  284. */
  285. var $highlight_extra_lines_style = 'color: #cc0; background-color: #ffc;';
  286. /**
  287. * The line ending
  288. * If null, nl2br() will be used on the result string.
  289. * Otherwise, all instances of \n will be replaced with $line_ending
  290. * @var string
  291. */
  292. var $line_ending = null;
  293. /**
  294. * Number at which line numbers should start at
  295. * @var int
  296. */
  297. var $line_numbers_start = 1;
  298. /**
  299. * The overall style for this code block
  300. * @var string
  301. */
  302. var $overall_style = '';
  303. /**
  304. * The style for the actual code
  305. * @var string
  306. */
  307. var $code_style = 'font-family: \'Courier New\', Courier, monospace; font-weight: normal;';
  308. /**
  309. * The overall class for this code block
  310. * @var string
  311. */
  312. var $overall_class = '';
  313. /**
  314. * The overall ID for this code block
  315. * @var string
  316. */
  317. var $overall_id = '';
  318. /**
  319. * Line number styles
  320. * @var string
  321. */
  322. var $line_style1 = 'font-family: \'Courier New\', Courier, monospace; color: black; font-weight: normal; font-style: normal;';
  323. /**
  324. * Line number styles for fancy lines
  325. * @var string
  326. */
  327. var $line_style2 = 'font-weight: bold;';
  328. /**
  329. * Flag for how line nubmers are displayed
  330. * @var boolean
  331. */
  332. var $line_numbers = GESHI_NO_LINE_NUMBERS;
  333. /**
  334. * The "nth" value for fancy line highlighting
  335. * @var int
  336. */
  337. var $line_nth_row = 0;
  338. /**
  339. * The size of tab stops
  340. * @var int
  341. */
  342. var $tab_width = 8;
  343. /**
  344. * Should we use language-defined tab stop widths?
  345. * @var int
  346. */
  347. var $use_language_tab_width = false;
  348. /**
  349. * Default target for keyword links
  350. * @var string
  351. */
  352. var $link_target = '';
  353. /**
  354. * The encoding to use for entity encoding
  355. * NOTE: no longer used
  356. * @var string
  357. */
  358. var $encoding = 'ISO-8859-1';
  359. /**
  360. * Should keywords be linked?
  361. * @var boolean
  362. */
  363. var $keyword_links = true;
  364. /**#@-*/
  365. /**
  366. * Creates a new GeSHi object, with source and language
  367. *
  368. * @param string The source code to highlight
  369. * @param string The language to highlight the source with
  370. * @param string The path to the language file directory. <b>This
  371. * is deprecated!</b> I've backported the auto path
  372. * detection from the 1.1.X dev branch, so now it
  373. * should be automatically set correctly. If you have
  374. * renamed the language directory however, you will
  375. * still need to set the path using this parameter or
  376. * {@link GeSHi::set_language_path()}
  377. * @since 1.0.0
  378. */
  379. function GeSHi($source, $language, $path = '') {
  380. $this->set_source($source);
  381. $this->set_language_path($path);
  382. $this->set_language($language);
  383. }
  384. /**
  385. * Returns an error message associated with the last GeSHi operation,
  386. * or false if no error has occured
  387. *
  388. * @return string|false An error message if there has been an error, else false
  389. * @since 1.0.0
  390. */
  391. function error() {
  392. if ($this->error) {
  393. $msg = $this->error_messages[$this->error];
  394. $debug_tpl_vars = array(
  395. '{LANGUAGE}' => $this->language,
  396. '{PATH}' => $this->language_path
  397. );
  398. foreach ($debug_tpl_vars as $tpl => $var) {
  399. $msg = str_replace($tpl, $var, $msg);
  400. }
  401. return "<br /><strong>GeSHi Error:</strong> $msg (code $this->error)<br />";
  402. }
  403. return false;
  404. }
  405. /**
  406. * Gets a human-readable language name (thanks to Simon Patterson
  407. * for the idea :))
  408. *
  409. * @return string The name for the current language
  410. * @since 1.0.2
  411. */
  412. function get_language_name() {
  413. if (GESHI_ERROR_NO_SUCH_LANG == $this->error) {
  414. return $this->language_data['LANG_NAME'] . ' (Unknown Language)';
  415. }
  416. return $this->language_data['LANG_NAME'];
  417. }
  418. /**
  419. * Sets the source code for this object
  420. *
  421. * @param string The source code to highlight
  422. * @since 1.0.0
  423. */
  424. function set_source($source) {
  425. $this->source = $source;
  426. $this->highlight_extra_lines = array();
  427. }
  428. /**
  429. * Sets the language for this object
  430. *
  431. * @param string The name of the language to use
  432. * @since 1.0.0
  433. */
  434. function set_language($language) {
  435. $this->error = false;
  436. $this->strict_mode = GESHI_NEVER;
  437. $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
  438. $this->language = strtolower($language);
  439. $file_name = $this->language_path . $this->language . '.php';
  440. if (!is_readable($file_name)) {
  441. $this->error = GESHI_ERROR_NO_SUCH_LANG;
  442. return;
  443. }
  444. // Load the language for parsing
  445. $this->load_language($file_name);
  446. }
  447. /**
  448. * Sets the path to the directory containing the language files. Note
  449. * that this path is relative to the directory of the script that included
  450. * geshi.php, NOT geshi.php itself.
  451. *
  452. * @param string The path to the language directory
  453. * @since 1.0.0
  454. * @deprecated The path to the language files should now be automatically
  455. * detected, so this method should no longer be needed. The
  456. * 1.1.X branch handles manual setting of the path differently
  457. * so this method will disappear in 1.2.0.
  458. */
  459. function set_language_path($path) {
  460. if ($path) {
  461. $this->language_path = ('/' == substr($path, strlen($path) - 1, 1)) ? $path : $path . '/';
  462. $this->set_language($this->language); // otherwise set_language_path has no effect
  463. }
  464. }
  465. /**
  466. * Sets the type of header to be used.
  467. *
  468. * If GESHI_HEADER_DIV is used, the code is surrounded in a "div".This
  469. * means more source code but more control over tab width and line-wrapping.
  470. * GESHI_HEADER_PRE means that a "pre" is used - less source, but less
  471. * control. Default is GESHI_HEADER_PRE.
  472. *
  473. * From 1.0.7.2, you can use GESHI_HEADER_NONE to specify that no header code
  474. * should be outputted.
  475. *
  476. * @param int The type of header to be used
  477. * @since 1.0.0
  478. */
  479. function set_header_type($type) {
  480. if (GESHI_HEADER_DIV != $type && GESHI_HEADER_PRE != $type && GESHI_HEADER_NONE != $type) {
  481. $this->error = GESHI_ERROR_INVALID_HEADER_TYPE;
  482. return;
  483. }
  484. $this->header_type = $type;
  485. // Set a default overall style if the header is a <div>
  486. if (GESHI_HEADER_DIV == $type && !$this->overall_style) {
  487. $this->overall_style = 'font-family: monospace;';
  488. }
  489. }
  490. /**
  491. * Sets the styles for the code that will be outputted
  492. * when this object is parsed. The style should be a
  493. * string of valid stylesheet declarations
  494. *
  495. * @param string The overall style for the outputted code block
  496. * @param boolean Whether to merge the styles with the current styles or not
  497. * @since 1.0.0
  498. */
  499. function set_overall_style($style, $preserve_defaults = false) {
  500. if (!$preserve_defaults) {
  501. $this->overall_style = $style;
  502. }
  503. else {
  504. $this->overall_style .= $style;
  505. }
  506. }
  507. /**
  508. * Sets the overall classname for this block of code. This
  509. * class can then be used in a stylesheet to style this object's
  510. * output
  511. *
  512. * @param string The class name to use for this block of code
  513. * @since 1.0.0
  514. */
  515. function set_overall_class($class) {
  516. $this->overall_class = $class;
  517. }
  518. /**
  519. * Sets the overall id for this block of code. This id can then
  520. * be used in a stylesheet to style this object's output
  521. *
  522. * @param string The ID to use for this block of code
  523. * @since 1.0.0
  524. */
  525. function set_overall_id($id) {
  526. $this->overall_id = $id;
  527. }
  528. /**
  529. * Sets whether CSS classes should be used to highlight the source. Default
  530. * is off, calling this method with no arguments will turn it on
  531. *
  532. * @param boolean Whether to turn classes on or not
  533. * @since 1.0.0
  534. */
  535. function enable_classes($flag = true) {
  536. $this->use_classes = ($flag) ? true : false;
  537. }
  538. /**
  539. * Sets the style for the actual code. This should be a string
  540. * containing valid stylesheet declarations. If $preserve_defaults is
  541. * true, then styles are merged with the default styles, with the
  542. * user defined styles having priority
  543. *
  544. * Note: Use this method to override any style changes you made to
  545. * the line numbers if you are using line numbers, else the line of
  546. * code will have the same style as the line number! Consult the
  547. * GeSHi documentation for more information about this.
  548. *
  549. * @param string The style to use for actual code
  550. * @param boolean Whether to merge the current styles with the new styles
  551. */
  552. function set_code_style($style, $preserve_defaults = false) {
  553. if (!$preserve_defaults) {
  554. $this->code_style = $style;
  555. }
  556. else {
  557. $this->code_style .= $style;
  558. }
  559. }
  560. /**
  561. * Sets the styles for the line numbers.
  562. *
  563. * @param string The style for the line numbers that are "normal"
  564. * @param string|boolean If a string, this is the style of the line
  565. * numbers that are "fancy", otherwise if boolean then this
  566. * defines whether the normal styles should be merged with the
  567. * new normal styles or not
  568. * @param boolean If set, is the flag for whether to merge the "fancy"
  569. * styles with the current styles or not
  570. * @since 1.0.2
  571. */
  572. function set_line_style($style1, $style2 = '', $preserve_defaults = false) {
  573. if (is_bool($style2)) {
  574. $preserve_defaults = $style2;
  575. $style2 = '';
  576. }
  577. if (!$preserve_defaults) {
  578. $this->line_style1 = $style1;
  579. $this->line_style2 = $style2;
  580. }
  581. else {
  582. $this->line_style1 .= $style1;
  583. $this->line_style2 .= $style2;
  584. }
  585. }
  586. /**
  587. * Sets whether line numbers should be displayed.
  588. *
  589. * Valid values for the first parameter are:
  590. *
  591. * - GESHI_NO_LINE_NUMBERS: Line numbers will not be displayed
  592. * - GESHI_NORMAL_LINE_NUMBERS: Line numbers will be displayed
  593. * - GESHI_FANCY_LINE_NUMBERS: Fancy line numbers will be displayed
  594. *
  595. * For fancy line numbers, the second parameter is used to signal which lines
  596. * are to be fancy. For example, if the value of this parameter is 5 then every
  597. * 5th line will be fancy.
  598. *
  599. * @param int How line numbers should be displayed
  600. * @param int Defines which lines are fancy
  601. * @since 1.0.0
  602. */
  603. function enable_line_numbers($flag, $nth_row = 5) {
  604. if (GESHI_NO_LINE_NUMBERS != $flag && GESHI_NORMAL_LINE_NUMBERS != $flag
  605. && GESHI_FANCY_LINE_NUMBERS != $flag) {
  606. $this->error = GESHI_ERROR_INVALID_LINE_NUMBER_TYPE;
  607. }
  608. $this->line_numbers = $flag;
  609. $this->line_nth_row = $nth_row;
  610. }
  611. /**
  612. * Sets the style for a keyword group. If $preserve_defaults is
  613. * true, then styles are merged with the default styles, with the
  614. * user defined styles having priority
  615. *
  616. * @param int The key of the keyword group to change the styles of
  617. * @param string The style to make the keywords
  618. * @param boolean Whether to merge the new styles with the old or just
  619. * to overwrite them
  620. * @since 1.0.0
  621. */
  622. function set_keyword_group_style($key, $style, $preserve_defaults = false) {
  623. if (!$preserve_defaults) {
  624. $this->language_data['STYLES']['KEYWORDS'][$key] = $style;
  625. }
  626. else {
  627. $this->language_data['STYLES']['KEYWORDS'][$key] .= $style;
  628. }
  629. }
  630. /**
  631. * Turns highlighting on/off for a keyword group
  632. *
  633. * @param int The key of the keyword group to turn on or off
  634. * @param boolean Whether to turn highlighting for that group on or off
  635. * @since 1.0.0
  636. */
  637. function set_keyword_group_highlighting($key, $flag = true) {
  638. $this->lexic_permissions['KEYWORDS'][$key] = ($flag) ? true : false;
  639. }
  640. /**
  641. * Sets the styles for comment groups. If $preserve_defaults is
  642. * true, then styles are merged with the default styles, with the
  643. * user defined styles having priority
  644. *
  645. * @param int The key of the comment group to change the styles of
  646. * @param string The style to make the comments
  647. * @param boolean Whether to merge the new styles with the old or just
  648. * to overwrite them
  649. * @since 1.0.0
  650. */
  651. function set_comments_style($key, $style, $preserve_defaults = false) {
  652. if (!$preserve_defaults) {
  653. $this->language_data['STYLES']['COMMENTS'][$key] = $style;
  654. }
  655. else {
  656. $this->language_data['STYLES']['COMMENTS'][$key] .= $style;
  657. }
  658. }
  659. /**
  660. * Turns highlighting on/off for comment groups
  661. *
  662. * @param int The key of the comment group to turn on or off
  663. * @param boolean Whether to turn highlighting for that group on or off
  664. * @since 1.0.0
  665. */
  666. function set_comments_highlighting($key, $flag = true) {
  667. $this->lexic_permissions['COMMENTS'][$key] = ($flag) ? true : false;
  668. }
  669. /**
  670. * Sets the styles for escaped characters. If $preserve_defaults is
  671. * true, then styles are merged with the default styles, with the
  672. * user defined styles having priority
  673. *
  674. * @param string The style to make the escape characters
  675. * @param boolean Whether to merge the new styles with the old or just
  676. * to overwrite them
  677. * @since 1.0.0
  678. */
  679. function set_escape_characters_style($style, $preserve_defaults = false) {
  680. if (!$preserve_defaults) {
  681. $this->language_data['STYLES']['ESCAPE_CHAR'][0] = $style;
  682. }
  683. else {
  684. $this->language_data['STYLES']['ESCAPE_CHAR'][0] .= $style;
  685. }
  686. }
  687. /**
  688. * Turns highlighting on/off for escaped characters
  689. *
  690. * @param boolean Whether to turn highlighting for escape characters on or off
  691. * @since 1.0.0
  692. */
  693. function set_escape_characters_highlighting($flag = true) {
  694. $this->lexic_permissions['ESCAPE_CHAR'] = ($flag) ? true : false;
  695. }
  696. /**
  697. * Sets the styles for brackets. If $preserve_defaults is
  698. * true, then styles are merged with the default styles, with the
  699. * user defined styles having priority
  700. *
  701. * This method is DEPRECATED: use set_symbols_style instead.
  702. * This method will be removed in 1.2.X
  703. *
  704. * @param string The style to make the brackets
  705. * @param boolean Whether to merge the new styles with the old or just
  706. * to overwrite them
  707. * @since 1.0.0
  708. * @deprecated In favour of set_symbols_style
  709. */
  710. function set_brackets_style($style, $preserve_defaults = false) {
  711. if (!$preserve_defaults) {
  712. $this->language_data['STYLES']['BRACKETS'][0] = $style;
  713. }
  714. else {
  715. $this->language_data['STYLES']['BRACKETS'][0] .= $style;
  716. }
  717. }
  718. /**
  719. * Turns highlighting on/off for brackets
  720. *
  721. * This method is DEPRECATED: use set_symbols_highlighting instead.
  722. * This method will be remove in 1.2.X
  723. *
  724. * @param boolean Whether to turn highlighting for brackets on or off
  725. * @since 1.0.0
  726. * @deprecated In favour of set_symbols_highlighting
  727. */
  728. function set_brackets_highlighting($flag) {
  729. $this->lexic_permissions['BRACKETS'] = ($flag) ? true : false;
  730. }
  731. /**
  732. * Sets the styles for symbols. If $preserve_defaults is
  733. * true, then styles are merged with the default styles, with the
  734. * user defined styles having priority
  735. *
  736. * @param string The style to make the symbols
  737. * @param boolean Whether to merge the new styles with the old or just
  738. * to overwrite them
  739. * @since 1.0.1
  740. */
  741. function set_symbols_style($style, $preserve_defaults = false) {
  742. if (!$preserve_defaults) {
  743. $this->language_data['STYLES']['SYMBOLS'][0] = $style;
  744. }
  745. else {
  746. $this->language_data['STYLES']['SYMBOLS'][0] .= $style;
  747. }
  748. // For backward compatibility
  749. $this->set_brackets_style ($style, $preserve_defaults);
  750. }
  751. /**
  752. * Turns highlighting on/off for symbols
  753. *
  754. * @param boolean Whether to turn highlighting for symbols on or off
  755. * @since 1.0.0
  756. */
  757. function set_symbols_highlighting($flag) {
  758. $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false;
  759. // For backward compatibility
  760. $this->set_brackets_highlighting ($flag);
  761. }
  762. /**
  763. * Sets the styles for strings. If $preserve_defaults is
  764. * true, then styles are merged with the default styles, with the
  765. * user defined styles having priority
  766. *
  767. * @param string The style to make the escape characters
  768. * @param boolean Whether to merge the new styles with the old or just
  769. * to overwrite them
  770. * @since 1.0.0
  771. */
  772. function set_strings_style($style, $preserve_defaults = false) {
  773. if (!$preserve_defaults) {
  774. $this->language_data['STYLES']['STRINGS'][0] = $style;
  775. }
  776. else {
  777. $this->language_data['STYLES']['STRINGS'][0] .= $style;
  778. }
  779. }
  780. /**
  781. * Turns highlighting on/off for strings
  782. *
  783. * @param boolean Whether to turn highlighting for strings on or off
  784. * @since 1.0.0
  785. */
  786. function set_strings_highlighting($flag) {
  787. $this->lexic_permissions['STRINGS'] = ($flag) ? true : false;
  788. }
  789. /**
  790. * Sets the styles for numbers. If $preserve_defaults is
  791. * true, then styles are merged with the default styles, with the
  792. * user defined styles having priority
  793. *
  794. * @param string The style to make the numbers
  795. * @param boolean Whether to merge the new styles with the old or just
  796. * to overwrite them
  797. * @since 1.0.0
  798. */
  799. function set_numbers_style($style, $preserve_defaults = false) {
  800. if (!$preserve_defaults) {
  801. $this->language_data['STYLES']['NUMBERS'][0] = $style;
  802. }
  803. else {
  804. $this->language_data['STYLES']['NUMBERS'][0] .= $style;
  805. }
  806. }
  807. /**
  808. * Turns highlighting on/off for numbers
  809. *
  810. * @param boolean Whether to turn highlighting for numbers on or off
  811. * @since 1.0.0
  812. */
  813. function set_numbers_highlighting($flag) {
  814. $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false;
  815. }
  816. /**
  817. * Sets the styles for methods. $key is a number that references the
  818. * appropriate "object splitter" - see the language file for the language
  819. * you are highlighting to get this number. If $preserve_defaults is
  820. * true, then styles are merged with the default styles, with the
  821. * user defined styles having priority
  822. *
  823. * @param int The key of the object splitter to change the styles of
  824. * @param string The style to make the methods
  825. * @param boolean Whether to merge the new styles with the old or just
  826. * to overwrite them
  827. * @since 1.0.0
  828. */
  829. function set_methods_style($key, $style, $preserve_defaults = false) {
  830. if (!$preserve_defaults) {
  831. $this->language_data['STYLES']['METHODS'][$key] = $style;
  832. }
  833. else {
  834. $this->language_data['STYLES']['METHODS'][$key] .= $style;
  835. }
  836. }
  837. /**
  838. * Turns highlighting on/off for methods
  839. *
  840. * @param boolean Whether to turn highlighting for methods on or off
  841. * @since 1.0.0
  842. */
  843. function set_methods_highlighting($flag) {
  844. $this->lexic_permissions['METHODS'] = ($flag) ? true : false;
  845. }
  846. /**
  847. * Sets the styles for regexps. If $preserve_defaults is
  848. * true, then styles are merged with the default styles, with the
  849. * user defined styles having priority
  850. *
  851. * @param string The style to make the regular expression matches
  852. * @param boolean Whether to merge the new styles with the old or just
  853. * to overwrite them
  854. * @since 1.0.0
  855. */
  856. function set_regexps_style($key, $style, $preserve_defaults = false) {
  857. if (!$preserve_defaults) {
  858. $this->language_data['STYLES']['REGEXPS'][$key] = $style;
  859. }
  860. else {
  861. $this->language_data['STYLES']['REGEXPS'][$key] .= $style;
  862. }
  863. }
  864. /**
  865. * Turns highlighting on/off for regexps
  866. *
  867. * @param int The key of the regular expression group to turn on or off
  868. * @param boolean Whether to turn highlighting for the regular expression group on or off
  869. * @since 1.0.0
  870. */
  871. function set_regexps_highlighting($key, $flag) {
  872. $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false;
  873. }
  874. /**
  875. * Sets whether a set of keywords are checked for in a case sensitive manner
  876. *
  877. * @param int The key of the keyword group to change the case sensitivity of
  878. * @param boolean Whether to check in a case sensitive manner or not
  879. * @since 1.0.0
  880. */
  881. function set_case_sensitivity($key, $case) {
  882. $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false;
  883. }
  884. /**
  885. * Sets the case that keywords should use when found. Use the constants:
  886. *
  887. * - GESHI_CAPS_NO_CHANGE: leave keywords as-is
  888. * - GESHI_CAPS_UPPER: convert all keywords to uppercase where found
  889. * - GESHI_CAPS_LOWER: convert all keywords to lowercase where found
  890. *
  891. * @param int A constant specifying what to do with matched keywords
  892. * @since 1.0.1
  893. * @todo Error check the passed value
  894. */
  895. function set_case_keywords($case) {
  896. $this->language_data['CASE_KEYWORDS'] = $case;
  897. }
  898. /**
  899. * Sets how many spaces a tab is substituted for
  900. *
  901. * Widths below zero are ignored
  902. *
  903. * @param int The tab width
  904. * @since 1.0.0
  905. */
  906. function set_tab_width($width) {
  907. $this->tab_width = intval($width);
  908. //Check if it fit's the constraints:
  909. if($this->tab_width < 1) {
  910. //Return it to the default
  911. $this->tab_width = 8;
  912. }
  913. }
  914. /**
  915. * Sets whether or not to use tab-stop width specifed by language
  916. *
  917. * @param boolean Whether to use language-specific tab-stop widths
  918. */
  919. function set_use_language_tab_width($use) {
  920. $this->use_language_tab_width = (bool) $use;
  921. }
  922. /**
  923. * Returns the tab width to use, based on the current language and user
  924. * preference
  925. *
  926. * @return int Tab width
  927. */
  928. function get_real_tab_width() {
  929. if (!$this->use_language_tab_width || !isset($this->language_data['TAB_WIDTH'])) {
  930. return $this->tab_width;
  931. } else {
  932. return $this->language_data['TAB_WIDTH'];
  933. }
  934. }
  935. /**
  936. * Enables/disables strict highlighting. Default is off, calling this
  937. * method without parameters will turn it on. See documentation
  938. * for more details on strict mode and where to use it.
  939. *
  940. * @param boolean Whether to enable strict mode or not
  941. * @since 1.0.0
  942. */
  943. function enable_strict_mode($mode = true) {
  944. if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) {
  945. $this->strict_mode = ($mode) ? true : false;
  946. }
  947. }
  948. /**
  949. * Disables all highlighting
  950. *
  951. * @since 1.0.0
  952. * @todo Rewrite with an array traversal
  953. */
  954. function disable_highlighting() {
  955. foreach ($this->lexic_permissions as $key => $value) {
  956. if (is_array($value)) {
  957. foreach ($value as $k => $v) {
  958. $this->lexic_permissions[$key][$k] = false;
  959. }
  960. }
  961. else {
  962. $this->lexic_permissions[$key] = false;
  963. }
  964. }
  965. // Context blocks
  966. $this->enable_important_blocks = false;
  967. }
  968. /**
  969. * Enables all highlighting
  970. *
  971. * @since 1.0.0
  972. * @todo Rewrite with array traversal
  973. */
  974. function enable_highlighting() {
  975. foreach ($this->lexic_permissions as $key => $value) {
  976. if (is_array($value)) {
  977. foreach ($value as $k => $v) {
  978. $this->lexic_permissions[$key][$k] = true;
  979. }
  980. }
  981. else {
  982. $this->lexic_permissions[$key] = true;
  983. }
  984. }
  985. // Context blocks
  986. $this->enable_important_blocks = true;
  987. }
  988. /**
  989. * Given a file extension, this method returns either a valid geshi language
  990. * name, or the empty string if it couldn't be found
  991. *
  992. * @param string The extension to get a language name for
  993. * @param array A lookup array to use instead of the default
  994. * @since 1.0.5
  995. * @todo Re-think about how this method works (maybe make it private and/or make it
  996. * a extension->lang lookup?)
  997. * @todo static?
  998. */
  999. function get_language_name_from_extension( $extension, $lookup = array() ) {
  1000. if ( !$lookup ) {
  1001. $lookup = array(
  1002. 'actionscript' => array('as'),
  1003. 'ada' => array('a', 'ada', 'adb', 'ads'),
  1004. 'apache' => array('conf'),
  1005. 'asm' => array('ash', 'asm'),
  1006. 'asp' => array('asp'),
  1007. 'bash' => array('sh'),
  1008. 'c' => array('c', 'h'),
  1009. 'c_mac' => array('c', 'h'),
  1010. 'caddcl' => array(),
  1011. 'cadlisp' => array(),
  1012. 'cdfg' => array('cdfg'),
  1013. 'cpp' => array('cpp', 'h', 'hpp'),
  1014. 'csharp' => array(),
  1015. 'css' => array('css'),
  1016. 'delphi' => array('dpk', 'dpr'),
  1017. 'html4strict' => array('html', 'htm'),
  1018. 'java' => array('java'),
  1019. 'javascript' => array('js'),
  1020. 'lisp' => array('lisp'),
  1021. 'lua' => array('lua'),
  1022. 'mpasm' => array(),
  1023. 'nsis' => array(),
  1024. 'objc' => array(),
  1025. 'oobas' => array(),
  1026. 'oracle8' => array(),
  1027. 'pascal' => array('pas'),
  1028. 'perl' => array('pl', 'pm'),
  1029. 'php' => array('php', 'php5', 'phtml', 'phps'),
  1030. 'python' => array('py'),
  1031. 'qbasic' => array('bi'),
  1032. 'sas' => array('sas'),
  1033. 'smarty' => array(),
  1034. 'vb' => array('bas'),
  1035. 'vbnet' => array(),
  1036. 'visualfoxpro' => array(),
  1037. 'xml' => array('xml')
  1038. );
  1039. }
  1040. foreach ($lookup as $lang => $extensions) {
  1041. foreach ($extensions as $ext) {
  1042. if ($ext == $extension) {
  1043. return $lang;
  1044. }
  1045. }
  1046. }
  1047. return '';
  1048. }
  1049. /**
  1050. * Given a file name, this method loads its contents in, and attempts
  1051. * to set the language automatically. An optional lookup table can be
  1052. * passed for looking up the language name. If not specified a default
  1053. * table is used
  1054. *
  1055. * The language table is in the form
  1056. * <pre>array(
  1057. * 'lang_name' => array('extension', 'extension', ...),
  1058. * 'lang_name' ...
  1059. * );</pre>
  1060. *
  1061. * @todo Complete rethink of this and above method
  1062. * @since 1.0.5
  1063. */
  1064. function load_from_file($file_name, $lookup = array()) {
  1065. if (is_readable($file_name)) {
  1066. $this->set_source(implode('', file($file_name)));
  1067. $this->set_language($this->get_language_name_from_extension(substr(strrchr($file_name, '.'), 1), $lookup));
  1068. }
  1069. else {
  1070. $this->error = GESHI_ERROR_FILE_NOT_READABLE;
  1071. }
  1072. }
  1073. /**
  1074. * Adds a keyword to a keyword group for highlighting
  1075. *
  1076. * @param int The key of the keyword group to add the keyword to
  1077. * @param string The word to add to the keyword group
  1078. * @since 1.0.0
  1079. */
  1080. function add_keyword($key, $word) {
  1081. $this->language_data['KEYWORDS'][$key][] = $word;
  1082. }
  1083. /**
  1084. * Removes a keyword from a keyword group
  1085. *
  1086. * @param int The key of the keyword group to remove the keyword from
  1087. * @param string The word to remove from the keyword group
  1088. * @since 1.0.0
  1089. */
  1090. function remove_keyword($key, $word) {
  1091. $this->language_data['KEYWORDS'][$key] =
  1092. array_diff($this->language_data['KEYWORDS'][$key], array($word));
  1093. }
  1094. /**
  1095. * Creates a new keyword group
  1096. *
  1097. * @param int The key of the keyword group to create
  1098. * @param string The styles for the keyword group
  1099. * @param boolean Whether the keyword group is case sensitive ornot
  1100. * @param array The words to use for the keyword group
  1101. * @since 1.0.0
  1102. */
  1103. function add_keyword_group($key, $styles, $case_sensitive = true, $words = array()) {
  1104. $words = (array) $words;
  1105. $this->language_data['KEYWORDS'][$key] = $words;
  1106. $this->lexic_permissions['KEYWORDS'][$key] = true;
  1107. $this->language_data['CASE_SENSITIVE'][$key] = $case_sensitive;
  1108. $this->language_data['STYLES']['KEYWORDS'][$key] = $styles;
  1109. }
  1110. /**
  1111. * Removes a keyword group
  1112. *
  1113. * @param int The key of the keyword group to remove
  1114. * @since 1.0.0
  1115. */
  1116. function remove_keyword_group ($key) {
  1117. unset($this->language_data['KEYWORDS'][$key]);
  1118. unset($this->lexic_permissions['KEYWORDS'][$key]);
  1119. unset($this->language_data['CASE_SENSITIVE'][$key]);
  1120. unset($this->language_data['STYLES']['KEYWORDS'][$key]);
  1121. }
  1122. /**
  1123. * Sets the content of the header block
  1124. *
  1125. * @param string The content of the header block
  1126. * @since 1.0.2
  1127. */
  1128. function set_header_content($content) {
  1129. $this->header_content = $content;
  1130. }
  1131. /**
  1132. * Sets the content of the footer block
  1133. *
  1134. * @param string The content of the footer block
  1135. * @since 1.0.2
  1136. */
  1137. function set_footer_content($content) {
  1138. $this->footer_content = $content;
  1139. }
  1140. /**
  1141. * Sets the style for the header content
  1142. *
  1143. * @param string The style for the header content
  1144. * @since 1.0.2
  1145. */
  1146. function set_header_content_style($style) {
  1147. $this->header_content_style = $style;
  1148. }
  1149. /**
  1150. * Sets the style for the footer content
  1151. *
  1152. * @param string The style for the footer content
  1153. * @since 1.0.2
  1154. */
  1155. function set_footer_content_style($style) {
  1156. $this->footer_content_style = $style;
  1157. }
  1158. /**
  1159. * Sets whether to force a surrounding block around
  1160. * the highlighted code or not
  1161. *
  1162. * @param boolean Tells whether to enable or disable this feature
  1163. * @since 1.0.7.20
  1164. */
  1165. function enable_inner_code_block($flag) {
  1166. $this->force_code_block = (bool)$flag;
  1167. }
  1168. /**
  1169. * Sets the base URL to be used for keywords
  1170. *
  1171. * @param int The key of the keyword group to set the URL for
  1172. * @param string The URL to set for the group. If {FNAME} is in
  1173. * the url somewhere, it is replaced by the keyword
  1174. * that the URL is being made for
  1175. * @since 1.0.2
  1176. */
  1177. function set_url_for_keyword_group($group, $url) {
  1178. $this->language_data['URLS'][$group] = $url;
  1179. }
  1180. /**
  1181. * Sets styles for links in code
  1182. *
  1183. * @param int A constant that specifies what state the style is being
  1184. * set for - e.g. :hover or :visited
  1185. * @param string The styles to use for that state
  1186. * @since 1.0.2
  1187. */
  1188. function set_link_styles($type, $styles) {
  1189. $this->link_styles[$type] = $styles;
  1190. }
  1191. /**
  1192. * Sets the target for links in code
  1193. *
  1194. * @param string The target for links in the code, e.g. _blank
  1195. * @since 1.0.3
  1196. */
  1197. function set_link_target($target) {
  1198. if (!$target) {
  1199. $this->link_target = '';
  1200. }
  1201. else {
  1202. $this->link_target = ' target="' . $target . '" ';
  1203. }
  1204. }
  1205. /**
  1206. * Sets styles for important parts of the code
  1207. *
  1208. * @param string The styles to use on important parts of the code
  1209. * @since 1.0.2
  1210. */
  1211. function set_important_styles($styles) {
  1212. $this->important_styles = $styles;
  1213. }
  1214. /**
  1215. * Sets whether context-important blocks are highlighted
  1216. *
  1217. * @todo REMOVE THIS SHIZ FROM GESHI!
  1218. * @deprecated
  1219. */
  1220. function enable_important_blocks($flag) {
  1221. $this->enable_important_blocks = ( $flag ) ? true : false;
  1222. }
  1223. /**
  1224. * Whether CSS IDs should be added to each line
  1225. *
  1226. * @param boolean If true, IDs will be added to each line.
  1227. * @since 1.0.2
  1228. */
  1229. function enable_ids($flag = true) {
  1230. $this->add_ids = ($flag) ? true : false;
  1231. }
  1232. /**
  1233. * Specifies which lines to highlight extra
  1234. *
  1235. * @param mixed An array of line numbers to highlight, or just a line
  1236. * number on its own.
  1237. * @since 1.0.2
  1238. * @todo Some data replication here that could be cut down on
  1239. */
  1240. function highlight_lines_extra($lines) {
  1241. if (is_array($lines)) {
  1242. foreach ($lines as $line) {
  1243. $this->highlight_extra_lines[intval($line)] = intval($line);
  1244. }
  1245. }
  1246. else {
  1247. $this->highlight_extra_lines[intval($lines)] = intval($lines);
  1248. }
  1249. }
  1250. /**
  1251. * Sets the style for extra-highlighted lines
  1252. *
  1253. * @param string The style for extra-highlighted lines
  1254. * @since 1.0.2
  1255. */
  1256. function set_highlight_lines_extra_style($styles) {
  1257. $this->highlight_extra_lines_style = $styles;
  1258. }
  1259. /**
  1260. * Sets the line-ending
  1261. *
  1262. * @param string The new line-ending
  1263. */
  1264. function set_line_ending($line_ending) {
  1265. $this->line_ending = (string)$line_ending;
  1266. }
  1267. /**
  1268. * Sets what number line numbers should start at. Should
  1269. * be a positive integer, and will be converted to one.
  1270. *
  1271. * <b>Warning:</b> Using this method will add the "start"
  1272. * attribute to the &lt;ol&gt; that is used for line numbering.
  1273. * This is <b>not</b> valid XHTML strict, so if that's what you
  1274. * care about then don't use this method. Firefox is getting
  1275. * support for the CSS method of doing this in 1.1 and Opera
  1276. * has support for the CSS method, but (of course) IE doesn't
  1277. * so it's not worth doing it the CSS way yet.
  1278. *
  1279. * @param int The number to start line numbers at
  1280. * @since 1.0.2
  1281. */
  1282. function start_line_numbers_at($number) {
  1283. $this->line_numbers_start = abs(intval($number));
  1284. }
  1285. /**
  1286. * Sets the encoding used for htmlspecialchars(), for international
  1287. * support.
  1288. *
  1289. * NOTE: This is not needed for now because htmlspecialchars() is not
  1290. * being used (it has a security hole in PHP4 that has not been patched).
  1291. * Maybe in a future version it may make a return for speed reasons, but
  1292. * I doubt it.
  1293. *
  1294. * @param string The encoding to use for the source
  1295. * @since 1.0.3
  1296. */
  1297. function set_encoding($encoding) {
  1298. if ($encoding) {
  1299. $this->encoding = $encoding;
  1300. }
  1301. }
  1302. /**
  1303. * Turns linking of keywords on or off.
  1304. *
  1305. * @param boolean If true, links will be added to keywords
  1306. */
  1307. function enable_keyword_links($enable = true) {
  1308. $this->keyword_links = ($enable) ? true : false;
  1309. }
  1310. /**
  1311. * Returns the code in $this->source, highlighted and surrounded by the
  1312. * nessecary HTML.
  1313. *
  1314. * This should only be called ONCE, cos it's SLOW! If you want to highlight
  1315. * the same source multiple times, you're better off doing a whole lot of
  1316. * str_replaces to replace the &lt;span&gt;s
  1317. *
  1318. * @since 1.0.0
  1319. */
  1320. function parse_code () {
  1321. // Start the timer
  1322. $start_time = microtime();
  1323. // Firstly, if there is an error, we won't highlight
  1324. if ($this->error) {
  1325. $result = GeSHi::hsc($this->source);
  1326. // Timing is irrelevant
  1327. $this->set_time($start_time, $start_time);
  1328. return $this->finalise($result);
  1329. }
  1330. // Replace all newlines to a common form.
  1331. $code = str_replace("\r\n", "\n", $this->source);
  1332. $code = str_replace("\r", "\n", $code);
  1333. // Add spaces for regular expression matching and line numbers
  1334. $code = "\n" . $code . "\n";
  1335. // Initialise various stuff
  1336. $length = strlen($code);
  1337. $STRING_OPEN = '';
  1338. $CLOSE_STRING = false;
  1339. $ESCAPE_CHAR_OPEN = false;
  1340. $COMMENT_MATCHED = false;
  1341. // Turn highlighting on if strict mode doesn't apply to this language
  1342. $HIGHLIGHTING_ON = ( !$this->strict_mode ) ? true : '';
  1343. // Whether to highlight inside a block of code
  1344. $HIGHLIGHT_INSIDE_STRICT = false;
  1345. $HARDQUOTE_OPEN = false;
  1346. $STRICTATTRS = '';
  1347. $stuff_to_parse = '';
  1348. $result = '';
  1349. // "Important" selections are handled like multiline comments
  1350. // @todo GET RID OF THIS SHIZ
  1351. if ($this->enable_important_blocks) {
  1352. $this->language_data['COMMENT_MULTI'][GESHI_START_IMPORTANT] = GESHI_END_IMPORTANT;
  1353. }
  1354. if ($this->strict_mode) {
  1355. // Break the source into bits. Each bit will be a portion of the code
  1356. // within script delimiters - for example, HTML between < and >
  1357. $parts = array(0 => array(0 => ''));
  1358. $k = 0;
  1359. for ($i = 0; $i < $length; $i++) {
  1360. $char = substr($code, $i, 1);
  1361. if (!$HIGHLIGHTING_ON) {
  1362. foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {
  1363. foreach ($delimiters as $open => $close) {
  1364. // Get the next little bit for this opening string
  1365. $check = substr($code, $i, strlen($open));
  1366. // If it matches...
  1367. if ($check == $open) {
  1368. // We start a new block with the highlightable
  1369. // code in it
  1370. $HIGHLIGHTING_ON = $open;
  1371. $i += strlen($open) - 1;
  1372. $char = $open;
  1373. $parts[++$k][0] = $char;
  1374. // No point going around again...
  1375. break(2);
  1376. }
  1377. }
  1378. }
  1379. }
  1380. else {
  1381. foreach ($this->language_data['SCRIPT_DELIMITERS'] as $key => $delimiters) {
  1382. foreach ($delimiters as $open => $close) {
  1383. if ($open == $HIGHLIGHTING_ON) {
  1384. // Found the closing tag
  1385. break(2);
  1386. }
  1387. }
  1388. }
  1389. // We check code from our current position BACKWARDS. This is so
  1390. // the ending string for highlighting can be included in the block
  1391. $check = substr($code, $i - strlen($close) + 1, strlen($close));
  1392. if ($check == $close) {
  1393. $HIGHLIGHTING_ON = '';
  1394. // Add the string to the rest of the string for this part
  1395. $parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char;
  1396. $parts[++$k][0] = '';
  1397. $char = '';
  1398. }
  1399. }
  1400. $parts[$k][1] = ( isset($parts[$k][1]) ) ? $parts[$k][1] . $char : $char;
  1401. }
  1402. $HIGHLIGHTING_ON = '';
  1403. }
  1404. else {
  1405. // Not strict mode - simply dump the source into
  1406. // the array at index 1 (the first highlightable block)
  1407. $parts = array(
  1408. 1 => array(
  1409. 0 => '',
  1410. 1 => $code

Large files files are truncated, but you can click here to view the full file