PageRenderTime 60ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 1ms

/plugins/content/geshi/geshi/geshi.php

https://bitbucket.org/eternaware/joomus
PHP | 4758 lines | 2706 code | 404 blank | 1648 comment | 704 complexity | bbe3d4b64ec53426fcc480f675dd6d8a MD5 | raw file
Possible License(s): LGPL-2.1

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

  1. <?php
  2. // no direct access
  3. defined('_JEXEC') or die;
  4. /**
  5. * GeSHi - Generic Syntax Highlighter
  6. *
  7. * The GeSHi class for Generic Syntax Highlighting. Please refer to the
  8. * documentation at http://qbnz.com/highlighter/documentation.php for more
  9. * information about how to use this class.
  10. *
  11. * For changes, release notes, TODOs etc, see the relevant files in the docs/
  12. * directory.
  13. *
  14. * This file is part of GeSHi.
  15. *
  16. * GeSHi is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * GeSHi is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with GeSHi; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. *
  30. * @package geshi
  31. * @subpackage core
  32. * @author Nigel McNie <nigel@geshi.org>, Benny Baumann <BenBE@omorphia.de>
  33. * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann
  34. * @license http://gnu.org/copyleft/gpl.html GNU GPL
  35. *
  36. */
  37. //
  38. // GeSHi Constants
  39. // You should use these constant names in your programs instead of
  40. // their values - you never know when a value may change in a future
  41. // version
  42. //
  43. /** The version of this GeSHi file */
  44. define('GESHI_VERSION', '1.0.8.10');
  45. // Define the root directory for the GeSHi code tree
  46. if (!defined('GESHI_ROOT')) {
  47. /** The root directory for GeSHi */
  48. define('GESHI_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);
  49. }
  50. /** The language file directory for GeSHi
  51. @access private */
  52. define('GESHI_LANG_ROOT', GESHI_ROOT . 'geshi' . DIRECTORY_SEPARATOR);
  53. // Define if GeSHi should be paranoid about security
  54. if (!defined('GESHI_SECURITY_PARANOID')) {
  55. /** Tells GeSHi to be paranoid about security settings */
  56. define('GESHI_SECURITY_PARANOID', false);
  57. }
  58. // Line numbers - use with enable_line_numbers()
  59. /** Use no line numbers when building the result */
  60. define('GESHI_NO_LINE_NUMBERS', 0);
  61. /** Use normal line numbers when building the result */
  62. define('GESHI_NORMAL_LINE_NUMBERS', 1);
  63. /** Use fancy line numbers when building the result */
  64. define('GESHI_FANCY_LINE_NUMBERS', 2);
  65. // Container HTML type
  66. /** Use nothing to surround the source */
  67. define('GESHI_HEADER_NONE', 0);
  68. /** Use a "div" to surround the source */
  69. define('GESHI_HEADER_DIV', 1);
  70. /** Use a "pre" to surround the source */
  71. define('GESHI_HEADER_PRE', 2);
  72. /** Use a pre to wrap lines when line numbers are enabled or to wrap the whole code. */
  73. define('GESHI_HEADER_PRE_VALID', 3);
  74. /**
  75. * Use a "table" to surround the source:
  76. *
  77. * <table>
  78. * <thead><tr><td colspan="2">$header</td></tr></thead>
  79. * <tbody><tr><td><pre>$linenumbers</pre></td><td><pre>$code></pre></td></tr></tbody>
  80. * <tfooter><tr><td colspan="2">$footer</td></tr></tfoot>
  81. * </table>
  82. *
  83. * this is essentially only a workaround for Firefox, see sf#1651996 or take a look at
  84. * https://bugzilla.mozilla.org/show_bug.cgi?id=365805
  85. * @note when linenumbers are disabled this is essentially the same as GESHI_HEADER_PRE
  86. */
  87. define('GESHI_HEADER_PRE_TABLE', 4);
  88. // Capatalisation constants
  89. /** Lowercase keywords found */
  90. define('GESHI_CAPS_NO_CHANGE', 0);
  91. /** Uppercase keywords found */
  92. define('GESHI_CAPS_UPPER', 1);
  93. /** Leave keywords found as the case that they are */
  94. define('GESHI_CAPS_LOWER', 2);
  95. // Link style constants
  96. /** Links in the source in the :link state */
  97. define('GESHI_LINK', 0);
  98. /** Links in the source in the :hover state */
  99. define('GESHI_HOVER', 1);
  100. /** Links in the source in the :active state */
  101. define('GESHI_ACTIVE', 2);
  102. /** Links in the source in the :visited state */
  103. define('GESHI_VISITED', 3);
  104. // Important string starter/finisher
  105. // Note that if you change these, they should be as-is: i.e., don't
  106. // write them as if they had been run through htmlentities()
  107. /** The starter for important parts of the source */
  108. define('GESHI_START_IMPORTANT', '<BEGIN GeSHi>');
  109. /** The ender for important parts of the source */
  110. define('GESHI_END_IMPORTANT', '<END GeSHi>');
  111. /**#@+
  112. * @access private
  113. */
  114. // When strict mode applies for a language
  115. /** Strict mode never applies (this is the most common) */
  116. define('GESHI_NEVER', 0);
  117. /** Strict mode *might* apply, and can be enabled or
  118. disabled by {@link GeSHi->enable_strict_mode()} */
  119. define('GESHI_MAYBE', 1);
  120. /** Strict mode always applies */
  121. define('GESHI_ALWAYS', 2);
  122. // Advanced regexp handling constants, used in language files
  123. /** The key of the regex array defining what to search for */
  124. define('GESHI_SEARCH', 0);
  125. /** The key of the regex array defining what bracket group in a
  126. matched search to use as a replacement */
  127. define('GESHI_REPLACE', 1);
  128. /** The key of the regex array defining any modifiers to the regular expression */
  129. define('GESHI_MODIFIERS', 2);
  130. /** The key of the regex array defining what bracket group in a
  131. matched search to put before the replacement */
  132. define('GESHI_BEFORE', 3);
  133. /** The key of the regex array defining what bracket group in a
  134. matched search to put after the replacement */
  135. define('GESHI_AFTER', 4);
  136. /** The key of the regex array defining a custom keyword to use
  137. for this regexp's html tag class */
  138. define('GESHI_CLASS', 5);
  139. /** Used in language files to mark comments */
  140. define('GESHI_COMMENTS', 0);
  141. /** Used to work around missing PHP features **/
  142. define('GESHI_PHP_PRE_433', !(version_compare(PHP_VERSION, '4.3.3') === 1));
  143. /** make sure we can call stripos **/
  144. if (!function_exists('stripos')) {
  145. // the offset param of preg_match is not supported below PHP 4.3.3
  146. if (GESHI_PHP_PRE_433) {
  147. /**
  148. * @ignore
  149. */
  150. function stripos($haystack, $needle, $offset = null) {
  151. if (!is_null($offset)) {
  152. $haystack = substr($haystack, $offset);
  153. }
  154. if (preg_match('/'. preg_quote($needle, '/') . '/', $haystack, $match, PREG_OFFSET_CAPTURE)) {
  155. return $match[0][1];
  156. }
  157. return false;
  158. }
  159. }
  160. else {
  161. /**
  162. * @ignore
  163. */
  164. function stripos($haystack, $needle, $offset = null) {
  165. if (preg_match('/'. preg_quote($needle, '/') . '/', $haystack, $match, PREG_OFFSET_CAPTURE, $offset)) {
  166. return $match[0][1];
  167. }
  168. return false;
  169. }
  170. }
  171. }
  172. /** some old PHP / PCRE subpatterns only support up to xxx subpatterns in
  173. regular expressions. Set this to false if your PCRE lib is up to date
  174. @see GeSHi->optimize_regexp_list()
  175. **/
  176. define('GESHI_MAX_PCRE_SUBPATTERNS', 500);
  177. /** it's also important not to generate too long regular expressions
  178. be generous here... but keep in mind, that when reaching this limit we
  179. still have to close open patterns. 12k should do just fine on a 16k limit.
  180. @see GeSHi->optimize_regexp_list()
  181. **/
  182. define('GESHI_MAX_PCRE_LENGTH', 12288);
  183. //Number format specification
  184. /** Basic number format for integers */
  185. define('GESHI_NUMBER_INT_BASIC', 1); //Default integers \d+
  186. /** Enhanced number format for integers like seen in C */
  187. define('GESHI_NUMBER_INT_CSTYLE', 2); //Default C-Style \d+[lL]?
  188. /** Number format to highlight binary numbers with a suffix "b" */
  189. define('GESHI_NUMBER_BIN_SUFFIX', 16); //[01]+[bB]
  190. /** Number format to highlight binary numbers with a prefix % */
  191. define('GESHI_NUMBER_BIN_PREFIX_PERCENT', 32); //%[01]+
  192. /** Number format to highlight binary numbers with a prefix 0b (C) */
  193. define('GESHI_NUMBER_BIN_PREFIX_0B', 64); //0b[01]+
  194. /** Number format to highlight octal numbers with a leading zero */
  195. define('GESHI_NUMBER_OCT_PREFIX', 256); //0[0-7]+
  196. /** Number format to highlight octal numbers with a prefix 0o (logtalk) */
  197. define('GESHI_NUMBER_OCT_PREFIX_0O', 512); //0[0-7]+
  198. /** Number format to highlight octal numbers with a leading @ (Used in HiSofts Devpac series). */
  199. define('GESHI_NUMBER_OCT_PREFIX_AT', 1024); //@[0-7]+
  200. /** Number format to highlight octal numbers with a suffix of o */
  201. define('GESHI_NUMBER_OCT_SUFFIX', 2048); //[0-7]+[oO]
  202. /** Number format to highlight hex numbers with a prefix 0x */
  203. define('GESHI_NUMBER_HEX_PREFIX', 4096); //0x[0-9a-fA-F]+
  204. /** Number format to highlight hex numbers with a prefix $ */
  205. define('GESHI_NUMBER_HEX_PREFIX_DOLLAR', 8192); //$[0-9a-fA-F]+
  206. /** Number format to highlight hex numbers with a suffix of h */
  207. define('GESHI_NUMBER_HEX_SUFFIX', 16384); //[0-9][0-9a-fA-F]*h
  208. /** Number format to highlight floating-point numbers without support for scientific notation */
  209. define('GESHI_NUMBER_FLT_NONSCI', 65536); //\d+\.\d+
  210. /** Number format to highlight floating-point numbers without support for scientific notation */
  211. define('GESHI_NUMBER_FLT_NONSCI_F', 131072); //\d+(\.\d+)?f
  212. /** Number format to highlight floating-point numbers with support for scientific notation (E) and optional leading zero */
  213. define('GESHI_NUMBER_FLT_SCI_SHORT', 262144); //\.\d+e\d+
  214. /** Number format to highlight floating-point numbers with support for scientific notation (E) and required leading digit */
  215. define('GESHI_NUMBER_FLT_SCI_ZERO', 524288); //\d+(\.\d+)?e\d+
  216. //Custom formats are passed by RX array
  217. // Error detection - use these to analyse faults
  218. /** No sourcecode to highlight was specified
  219. * @deprecated
  220. */
  221. define('GESHI_ERROR_NO_INPUT', 1);
  222. /** The language specified does not exist */
  223. define('GESHI_ERROR_NO_SUCH_LANG', 2);
  224. /** GeSHi could not open a file for reading (generally a language file) */
  225. define('GESHI_ERROR_FILE_NOT_READABLE', 3);
  226. /** The header type passed to {@link GeSHi->set_header_type()} was invalid */
  227. define('GESHI_ERROR_INVALID_HEADER_TYPE', 4);
  228. /** The line number type passed to {@link GeSHi->enable_line_numbers()} was invalid */
  229. define('GESHI_ERROR_INVALID_LINE_NUMBER_TYPE', 5);
  230. /**#@-*/
  231. /**
  232. * The GeSHi Class.
  233. *
  234. * Please refer to the documentation for GeSHi 1.0.X that is available
  235. * at http://qbnz.com/highlighter/documentation.php for more information
  236. * about how to use this class.
  237. *
  238. * @package geshi
  239. * @author Nigel McNie <nigel@geshi.org>, Benny Baumann <BenBE@omorphia.de>
  240. * @copyright (C) 2004 - 2007 Nigel McNie, (C) 2007 - 2008 Benny Baumann
  241. */
  242. class GeSHi {
  243. /**#@+
  244. * @access private
  245. */
  246. /**
  247. * The source code to highlight
  248. * @var string
  249. */
  250. var $source = '';
  251. /**
  252. * The language to use when highlighting
  253. * @var string
  254. */
  255. var $language = '';
  256. /**
  257. * The data for the language used
  258. * @var array
  259. */
  260. var $language_data = array();
  261. /**
  262. * The path to the language files
  263. * @var string
  264. */
  265. var $language_path = GESHI_LANG_ROOT;
  266. /**
  267. * The error message associated with an error
  268. * @var string
  269. * @todo check err reporting works
  270. */
  271. var $error = false;
  272. /**
  273. * Possible error messages
  274. * @var array
  275. */
  276. var $error_messages = array(
  277. GESHI_ERROR_NO_SUCH_LANG => 'GeSHi could not find the language {LANGUAGE} (using path {PATH})',
  278. GESHI_ERROR_FILE_NOT_READABLE => 'The file specified for load_from_file was not readable',
  279. GESHI_ERROR_INVALID_HEADER_TYPE => 'The header type specified is invalid',
  280. GESHI_ERROR_INVALID_LINE_NUMBER_TYPE => 'The line number type specified is invalid'
  281. );
  282. /**
  283. * Whether highlighting is strict or not
  284. * @var boolean
  285. */
  286. var $strict_mode = false;
  287. /**
  288. * Whether to use CSS classes in output
  289. * @var boolean
  290. */
  291. var $use_classes = false;
  292. /**
  293. * The type of header to use. Can be one of the following
  294. * values:
  295. *
  296. * - GESHI_HEADER_PRE: Source is outputted in a "pre" HTML element.
  297. * - GESHI_HEADER_DIV: Source is outputted in a "div" HTML element.
  298. * - GESHI_HEADER_NONE: No header is outputted.
  299. *
  300. * @var int
  301. */
  302. var $header_type = GESHI_HEADER_PRE;
  303. /**
  304. * Array of permissions for which lexics should be highlighted
  305. * @var array
  306. */
  307. var $lexic_permissions = array(
  308. 'KEYWORDS' => array(),
  309. 'COMMENTS' => array('MULTI' => true),
  310. 'REGEXPS' => array(),
  311. 'ESCAPE_CHAR' => true,
  312. 'BRACKETS' => true,
  313. 'SYMBOLS' => false,
  314. 'STRINGS' => true,
  315. 'NUMBERS' => true,
  316. 'METHODS' => true,
  317. 'SCRIPT' => true
  318. );
  319. /**
  320. * The time it took to parse the code
  321. * @var double
  322. */
  323. var $time = 0;
  324. /**
  325. * The content of the header block
  326. * @var string
  327. */
  328. var $header_content = '';
  329. /**
  330. * The content of the footer block
  331. * @var string
  332. */
  333. var $footer_content = '';
  334. /**
  335. * The style of the header block
  336. * @var string
  337. */
  338. var $header_content_style = '';
  339. /**
  340. * The style of the footer block
  341. * @var string
  342. */
  343. var $footer_content_style = '';
  344. /**
  345. * Tells if a block around the highlighted source should be forced
  346. * if not using line numbering
  347. * @var boolean
  348. */
  349. var $force_code_block = false;
  350. /**
  351. * The styles for hyperlinks in the code
  352. * @var array
  353. */
  354. var $link_styles = array();
  355. /**
  356. * Whether important blocks should be recognised or not
  357. * @var boolean
  358. * @deprecated
  359. * @todo REMOVE THIS FUNCTIONALITY!
  360. */
  361. var $enable_important_blocks = false;
  362. /**
  363. * Styles for important parts of the code
  364. * @var string
  365. * @deprecated
  366. * @todo As above - rethink the whole idea of important blocks as it is buggy and
  367. * will be hard to implement in 1.2
  368. */
  369. var $important_styles = 'font-weight: bold; color: red;'; // Styles for important parts of the code
  370. /**
  371. * Whether CSS IDs should be added to the code
  372. * @var boolean
  373. */
  374. var $add_ids = false;
  375. /**
  376. * Lines that should be highlighted extra
  377. * @var array
  378. */
  379. var $highlight_extra_lines = array();
  380. /**
  381. * Styles of lines that should be highlighted extra
  382. * @var array
  383. */
  384. var $highlight_extra_lines_styles = array();
  385. /**
  386. * Styles of extra-highlighted lines
  387. * @var string
  388. */
  389. var $highlight_extra_lines_style = 'background-color: #ffc;';
  390. /**
  391. * The line ending
  392. * If null, nl2br() will be used on the result string.
  393. * Otherwise, all instances of \n will be replaced with $line_ending
  394. * @var string
  395. */
  396. var $line_ending = null;
  397. /**
  398. * Number at which line numbers should start at
  399. * @var int
  400. */
  401. var $line_numbers_start = 1;
  402. /**
  403. * The overall style for this code block
  404. * @var string
  405. */
  406. var $overall_style = 'font-family:monospace;';
  407. /**
  408. * The style for the actual code
  409. * @var string
  410. */
  411. var $code_style = 'font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;';
  412. /**
  413. * The overall class for this code block
  414. * @var string
  415. */
  416. var $overall_class = '';
  417. /**
  418. * The overall ID for this code block
  419. * @var string
  420. */
  421. var $overall_id = '';
  422. /**
  423. * Line number styles
  424. * @var string
  425. */
  426. var $line_style1 = 'font-weight: normal; vertical-align:top;';
  427. /**
  428. * Line number styles for fancy lines
  429. * @var string
  430. */
  431. var $line_style2 = 'font-weight: bold; vertical-align:top;';
  432. /**
  433. * Style for line numbers when GESHI_HEADER_PRE_TABLE is chosen
  434. * @var string
  435. */
  436. var $table_linenumber_style = 'width:1px;text-align:right;margin:0;padding:0 2px;vertical-align:top;';
  437. /**
  438. * Flag for how line numbers are displayed
  439. * @var boolean
  440. */
  441. var $line_numbers = GESHI_NO_LINE_NUMBERS;
  442. /**
  443. * Flag to decide if multi line spans are allowed. Set it to false to make sure
  444. * each tag is closed before and reopened after each linefeed.
  445. * @var boolean
  446. */
  447. var $allow_multiline_span = true;
  448. /**
  449. * The "nth" value for fancy line highlighting
  450. * @var int
  451. */
  452. var $line_nth_row = 0;
  453. /**
  454. * The size of tab stops
  455. * @var int
  456. */
  457. var $tab_width = 8;
  458. /**
  459. * Should we use language-defined tab stop widths?
  460. * @var int
  461. */
  462. var $use_language_tab_width = false;
  463. /**
  464. * Default target for keyword links
  465. * @var string
  466. */
  467. var $link_target = '';
  468. /**
  469. * The encoding to use for entity encoding
  470. * NOTE: Used with Escape Char Sequences to fix UTF-8 handling (cf. SF#2037598)
  471. * @var string
  472. */
  473. var $encoding = 'utf-8';
  474. /**
  475. * Should keywords be linked?
  476. * @var boolean
  477. */
  478. var $keyword_links = true;
  479. /**
  480. * Currently loaded language file
  481. * @var string
  482. * @since 1.0.7.22
  483. */
  484. var $loaded_language = '';
  485. /**
  486. * Wether the caches needed for parsing are built or not
  487. *
  488. * @var bool
  489. * @since 1.0.8
  490. */
  491. var $parse_cache_built = false;
  492. /**
  493. * Work around for Suhosin Patch with disabled /e modifier
  494. *
  495. * Note from suhosins author in config file:
  496. * <blockquote>
  497. * The /e modifier inside <code>preg_replace()</code> allows code execution.
  498. * Often it is the cause for remote code execution exploits. It is wise to
  499. * deactivate this feature and test where in the application it is used.
  500. * The developer using the /e modifier should be made aware that he should
  501. * use <code>preg_replace_callback()</code> instead
  502. * </blockquote>
  503. *
  504. * @var array
  505. * @since 1.0.8
  506. */
  507. var $_kw_replace_group = 0;
  508. var $_rx_key = 0;
  509. /**
  510. * some "callback parameters" for handle_multiline_regexps
  511. *
  512. * @since 1.0.8
  513. * @access private
  514. * @var string
  515. */
  516. var $_hmr_before = '';
  517. var $_hmr_replace = '';
  518. var $_hmr_after = '';
  519. var $_hmr_key = 0;
  520. /**#@-*/
  521. /**
  522. * Creates a new GeSHi object, with source and language
  523. *
  524. * @param string The source code to highlight
  525. * @param string The language to highlight the source with
  526. * @param string The path to the language file directory. <b>This
  527. * is deprecated!</b> I've backported the auto path
  528. * detection from the 1.1.X dev branch, so now it
  529. * should be automatically set correctly. If you have
  530. * renamed the language directory however, you will
  531. * still need to set the path using this parameter or
  532. * {@link GeSHi->set_language_path()}
  533. * @since 1.0.0
  534. */
  535. function GeSHi($source = '', $language = '', $path = '') {
  536. if (!empty($source)) {
  537. $this->set_source($source);
  538. }
  539. if (!empty($language)) {
  540. $this->set_language($language);
  541. }
  542. $this->set_language_path($path);
  543. }
  544. /**
  545. * Returns an error message associated with the last GeSHi operation,
  546. * or false if no error has occured
  547. *
  548. * @return string|false An error message if there has been an error, else false
  549. * @since 1.0.0
  550. */
  551. function error() {
  552. if ($this->error) {
  553. //Put some template variables for debugging here ...
  554. $debug_tpl_vars = array(
  555. '{LANGUAGE}' => $this->language,
  556. '{PATH}' => $this->language_path
  557. );
  558. $msg = str_replace(
  559. array_keys($debug_tpl_vars),
  560. array_values($debug_tpl_vars),
  561. $this->error_messages[$this->error]);
  562. return "<br /><strong>GeSHi Error:</strong> $msg (code {$this->error})<br />";
  563. }
  564. return false;
  565. }
  566. /**
  567. * Gets a human-readable language name (thanks to Simon Patterson
  568. * for the idea :))
  569. *
  570. * @return string The name for the current language
  571. * @since 1.0.2
  572. */
  573. function get_language_name() {
  574. if (GESHI_ERROR_NO_SUCH_LANG == $this->error) {
  575. return $this->language_data['LANG_NAME'] . ' (Unknown Language)';
  576. }
  577. return $this->language_data['LANG_NAME'];
  578. }
  579. /**
  580. * Sets the source code for this object
  581. *
  582. * @param string The source code to highlight
  583. * @since 1.0.0
  584. */
  585. function set_source($source) {
  586. $this->source = $source;
  587. $this->highlight_extra_lines = array();
  588. }
  589. /**
  590. * Sets the language for this object
  591. *
  592. * @note since 1.0.8 this function won't reset language-settings by default anymore!
  593. * if you need this set $force_reset = true
  594. *
  595. * @param string The name of the language to use
  596. * @since 1.0.0
  597. */
  598. function set_language($language, $force_reset = false) {
  599. if ($force_reset) {
  600. $this->loaded_language = false;
  601. }
  602. //Clean up the language name to prevent malicious code injection
  603. $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
  604. $language = strtolower($language);
  605. //Retreive the full filename
  606. $file_name = $this->language_path . $language . '.php';
  607. if ($file_name == $this->loaded_language) {
  608. // this language is already loaded!
  609. return;
  610. }
  611. $this->language = $language;
  612. $this->error = false;
  613. $this->strict_mode = GESHI_NEVER;
  614. //Check if we can read the desired file
  615. if (!is_readable($file_name)) {
  616. $this->error = GESHI_ERROR_NO_SUCH_LANG;
  617. return;
  618. }
  619. // Load the language for parsing
  620. $this->load_language($file_name);
  621. }
  622. /**
  623. * Sets the path to the directory containing the language files. Note
  624. * that this path is relative to the directory of the script that included
  625. * geshi.php, NOT geshi.php itself.
  626. *
  627. * @param string The path to the language directory
  628. * @since 1.0.0
  629. * @deprecated The path to the language files should now be automatically
  630. * detected, so this method should no longer be needed. The
  631. * 1.1.X branch handles manual setting of the path differently
  632. * so this method will disappear in 1.2.0.
  633. */
  634. function set_language_path($path) {
  635. if(strpos($path, ':')) {
  636. //Security Fix to prevent external directories using fopen wrappers.
  637. if(DIRECTORY_SEPARATOR == "\\") {
  638. if(!preg_match('#^[a-zA-Z]:#', $path) || false !== strpos($path, ':', 2)) {
  639. return;
  640. }
  641. } else {
  642. return;
  643. }
  644. }
  645. if(preg_match('#[^/a-zA-Z0-9_\.\-\\\s:]#', $path)) {
  646. //Security Fix to prevent external directories using fopen wrappers.
  647. return;
  648. }
  649. if(GESHI_SECURITY_PARANOID && false !== strpos($path, '/.')) {
  650. //Security Fix to prevent external directories using fopen wrappers.
  651. return;
  652. }
  653. if(GESHI_SECURITY_PARANOID && false !== strpos($path, '..')) {
  654. //Security Fix to prevent external directories using fopen wrappers.
  655. return;
  656. }
  657. if ($path) {
  658. $this->language_path = ('/' == $path[strlen($path) - 1]) ? $path : $path . '/';
  659. $this->set_language($this->language); // otherwise set_language_path has no effect
  660. }
  661. }
  662. /**
  663. * Get supported langs or an associative array lang=>full_name.
  664. * @param boolean $longnames
  665. * @return array
  666. */
  667. function get_supported_languages($full_names=false)
  668. {
  669. // return array
  670. $back = array();
  671. // we walk the lang root
  672. $dir = dir($this->language_path);
  673. // foreach entry
  674. while (false !== ($entry = $dir->read()))
  675. {
  676. $full_path = $this->language_path.$entry;
  677. // Skip all dirs
  678. if (is_dir($full_path)) {
  679. continue;
  680. }
  681. // we only want lang.php files
  682. if (!preg_match('/^([^.]+)\.php$/', $entry, $matches)) {
  683. continue;
  684. }
  685. // Raw lang name is here
  686. $langname = $matches[1];
  687. // We want the fullname too?
  688. if ($full_names === true)
  689. {
  690. if (false !== ($fullname = $this->get_language_fullname($langname)))
  691. {
  692. $back[$langname] = $fullname; // we go associative
  693. }
  694. }
  695. else
  696. {
  697. // just store raw langname
  698. $back[] = $langname;
  699. }
  700. }
  701. $dir->close();
  702. return $back;
  703. }
  704. /**
  705. * Get full_name for a lang or false.
  706. * @param string $language short langname (html4strict for example)
  707. * @return mixed
  708. */
  709. function get_language_fullname($language)
  710. {
  711. //Clean up the language name to prevent malicious code injection
  712. $language = preg_replace('#[^a-zA-Z0-9\-_]#', '', $language);
  713. $language = strtolower($language);
  714. // get fullpath-filename for a langname
  715. $fullpath = $this->language_path.$language.'.php';
  716. // we need to get contents :S
  717. if (false === ($data = file_get_contents($fullpath))) {
  718. $this->error = sprintf('Geshi::get_lang_fullname() Unknown Language: %s', $language);
  719. return false;
  720. }
  721. // match the langname
  722. if (!preg_match('/\'LANG_NAME\'\s*=>\s*\'((?:[^\']|\\\')+)\'/', $data, $matches)) {
  723. $this->error = sprintf('Geshi::get_lang_fullname(%s): Regex can not detect language', $language);
  724. return false;
  725. }
  726. // return fullname for langname
  727. return stripcslashes($matches[1]);
  728. }
  729. /**
  730. * Sets the type of header to be used.
  731. *
  732. * If GESHI_HEADER_DIV is used, the code is surrounded in a "div".This
  733. * means more source code but more control over tab width and line-wrapping.
  734. * GESHI_HEADER_PRE means that a "pre" is used - less source, but less
  735. * control. Default is GESHI_HEADER_PRE.
  736. *
  737. * From 1.0.7.2, you can use GESHI_HEADER_NONE to specify that no header code
  738. * should be outputted.
  739. *
  740. * @param int The type of header to be used
  741. * @since 1.0.0
  742. */
  743. function set_header_type($type) {
  744. //Check if we got a valid header type
  745. if (!in_array($type, array(GESHI_HEADER_NONE, GESHI_HEADER_DIV,
  746. GESHI_HEADER_PRE, GESHI_HEADER_PRE_VALID, GESHI_HEADER_PRE_TABLE))) {
  747. $this->error = GESHI_ERROR_INVALID_HEADER_TYPE;
  748. return;
  749. }
  750. //Set that new header type
  751. $this->header_type = $type;
  752. }
  753. /**
  754. * Sets the styles for the code that will be outputted
  755. * when this object is parsed. The style should be a
  756. * string of valid stylesheet declarations
  757. *
  758. * @param string The overall style for the outputted code block
  759. * @param boolean Whether to merge the styles with the current styles or not
  760. * @since 1.0.0
  761. */
  762. function set_overall_style($style, $preserve_defaults = false) {
  763. if (!$preserve_defaults) {
  764. $this->overall_style = $style;
  765. } else {
  766. $this->overall_style .= $style;
  767. }
  768. }
  769. /**
  770. * Sets the overall classname for this block of code. This
  771. * class can then be used in a stylesheet to style this object's
  772. * output
  773. *
  774. * @param string The class name to use for this block of code
  775. * @since 1.0.0
  776. */
  777. function set_overall_class($class) {
  778. $this->overall_class = $class;
  779. }
  780. /**
  781. * Sets the overall id for this block of code. This id can then
  782. * be used in a stylesheet to style this object's output
  783. *
  784. * @param string The ID to use for this block of code
  785. * @since 1.0.0
  786. */
  787. function set_overall_id($id) {
  788. $this->overall_id = $id;
  789. }
  790. /**
  791. * Sets whether CSS classes should be used to highlight the source. Default
  792. * is off, calling this method with no arguments will turn it on
  793. *
  794. * @param boolean Whether to turn classes on or not
  795. * @since 1.0.0
  796. */
  797. function enable_classes($flag = true) {
  798. $this->use_classes = ($flag) ? true : false;
  799. }
  800. /**
  801. * Sets the style for the actual code. This should be a string
  802. * containing valid stylesheet declarations. If $preserve_defaults is
  803. * true, then styles are merged with the default styles, with the
  804. * user defined styles having priority
  805. *
  806. * Note: Use this method to override any style changes you made to
  807. * the line numbers if you are using line numbers, else the line of
  808. * code will have the same style as the line number! Consult the
  809. * GeSHi documentation for more information about this.
  810. *
  811. * @param string The style to use for actual code
  812. * @param boolean Whether to merge the current styles with the new styles
  813. * @since 1.0.2
  814. */
  815. function set_code_style($style, $preserve_defaults = false) {
  816. if (!$preserve_defaults) {
  817. $this->code_style = $style;
  818. } else {
  819. $this->code_style .= $style;
  820. }
  821. }
  822. /**
  823. * Sets the styles for the line numbers.
  824. *
  825. * @param string The style for the line numbers that are "normal"
  826. * @param string|boolean If a string, this is the style of the line
  827. * numbers that are "fancy", otherwise if boolean then this
  828. * defines whether the normal styles should be merged with the
  829. * new normal styles or not
  830. * @param boolean If set, is the flag for whether to merge the "fancy"
  831. * styles with the current styles or not
  832. * @since 1.0.2
  833. */
  834. function set_line_style($style1, $style2 = '', $preserve_defaults = false) {
  835. //Check if we got 2 or three parameters
  836. if (is_bool($style2)) {
  837. $preserve_defaults = $style2;
  838. $style2 = '';
  839. }
  840. //Actually set the new styles
  841. if (!$preserve_defaults) {
  842. $this->line_style1 = $style1;
  843. $this->line_style2 = $style2;
  844. } else {
  845. $this->line_style1 .= $style1;
  846. $this->line_style2 .= $style2;
  847. }
  848. }
  849. /**
  850. * Sets whether line numbers should be displayed.
  851. *
  852. * Valid values for the first parameter are:
  853. *
  854. * - GESHI_NO_LINE_NUMBERS: Line numbers will not be displayed
  855. * - GESHI_NORMAL_LINE_NUMBERS: Line numbers will be displayed
  856. * - GESHI_FANCY_LINE_NUMBERS: Fancy line numbers will be displayed
  857. *
  858. * For fancy line numbers, the second parameter is used to signal which lines
  859. * are to be fancy. For example, if the value of this parameter is 5 then every
  860. * 5th line will be fancy.
  861. *
  862. * @param int How line numbers should be displayed
  863. * @param int Defines which lines are fancy
  864. * @since 1.0.0
  865. */
  866. function enable_line_numbers($flag, $nth_row = 5) {
  867. if (GESHI_NO_LINE_NUMBERS != $flag && GESHI_NORMAL_LINE_NUMBERS != $flag
  868. && GESHI_FANCY_LINE_NUMBERS != $flag) {
  869. $this->error = GESHI_ERROR_INVALID_LINE_NUMBER_TYPE;
  870. }
  871. $this->line_numbers = $flag;
  872. $this->line_nth_row = $nth_row;
  873. }
  874. /**
  875. * Sets wether spans and other HTML markup generated by GeSHi can
  876. * span over multiple lines or not. Defaults to true to reduce overhead.
  877. * Set it to false if you want to manipulate the output or manually display
  878. * the code in an ordered list.
  879. *
  880. * @param boolean Wether multiline spans are allowed or not
  881. * @since 1.0.7.22
  882. */
  883. function enable_multiline_span($flag) {
  884. $this->allow_multiline_span = (bool) $flag;
  885. }
  886. /**
  887. * Get current setting for multiline spans, see GeSHi->enable_multiline_span().
  888. *
  889. * @see enable_multiline_span
  890. * @return bool
  891. */
  892. function get_multiline_span() {
  893. return $this->allow_multiline_span;
  894. }
  895. /**
  896. * Sets the style for a keyword group. If $preserve_defaults is
  897. * true, then styles are merged with the default styles, with the
  898. * user defined styles having priority
  899. *
  900. * @param int The key of the keyword group to change the styles of
  901. * @param string The style to make the keywords
  902. * @param boolean Whether to merge the new styles with the old or just
  903. * to overwrite them
  904. * @since 1.0.0
  905. */
  906. function set_keyword_group_style($key, $style, $preserve_defaults = false) {
  907. //Set the style for this keyword group
  908. if (!$preserve_defaults) {
  909. $this->language_data['STYLES']['KEYWORDS'][$key] = $style;
  910. } else {
  911. $this->language_data['STYLES']['KEYWORDS'][$key] .= $style;
  912. }
  913. //Update the lexic permissions
  914. if (!isset($this->lexic_permissions['KEYWORDS'][$key])) {
  915. $this->lexic_permissions['KEYWORDS'][$key] = true;
  916. }
  917. }
  918. /**
  919. * Turns highlighting on/off for a keyword group
  920. *
  921. * @param int The key of the keyword group to turn on or off
  922. * @param boolean Whether to turn highlighting for that group on or off
  923. * @since 1.0.0
  924. */
  925. function set_keyword_group_highlighting($key, $flag = true) {
  926. $this->lexic_permissions['KEYWORDS'][$key] = ($flag) ? true : false;
  927. }
  928. /**
  929. * Sets the styles for comment groups. If $preserve_defaults is
  930. * true, then styles are merged with the default styles, with the
  931. * user defined styles having priority
  932. *
  933. * @param int The key of the comment group to change the styles of
  934. * @param string The style to make the comments
  935. * @param boolean Whether to merge the new styles with the old or just
  936. * to overwrite them
  937. * @since 1.0.0
  938. */
  939. function set_comments_style($key, $style, $preserve_defaults = false) {
  940. if (!$preserve_defaults) {
  941. $this->language_data['STYLES']['COMMENTS'][$key] = $style;
  942. } else {
  943. $this->language_data['STYLES']['COMMENTS'][$key] .= $style;
  944. }
  945. }
  946. /**
  947. * Turns highlighting on/off for comment groups
  948. *
  949. * @param int The key of the comment group to turn on or off
  950. * @param boolean Whether to turn highlighting for that group on or off
  951. * @since 1.0.0
  952. */
  953. function set_comments_highlighting($key, $flag = true) {
  954. $this->lexic_permissions['COMMENTS'][$key] = ($flag) ? true : false;
  955. }
  956. /**
  957. * Sets the styles for escaped characters. If $preserve_defaults is
  958. * true, then styles are merged with the default styles, with the
  959. * user defined styles having priority
  960. *
  961. * @param string The style to make the escape characters
  962. * @param boolean Whether to merge the new styles with the old or just
  963. * to overwrite them
  964. * @since 1.0.0
  965. */
  966. function set_escape_characters_style($style, $preserve_defaults = false, $group = 0) {
  967. if (!$preserve_defaults) {
  968. $this->language_data['STYLES']['ESCAPE_CHAR'][$group] = $style;
  969. } else {
  970. $this->language_data['STYLES']['ESCAPE_CHAR'][$group] .= $style;
  971. }
  972. }
  973. /**
  974. * Turns highlighting on/off for escaped characters
  975. *
  976. * @param boolean Whether to turn highlighting for escape characters on or off
  977. * @since 1.0.0
  978. */
  979. function set_escape_characters_highlighting($flag = true) {
  980. $this->lexic_permissions['ESCAPE_CHAR'] = ($flag) ? true : false;
  981. }
  982. /**
  983. * Sets the styles for brackets. If $preserve_defaults is
  984. * true, then styles are merged with the default styles, with the
  985. * user defined styles having priority
  986. *
  987. * This method is DEPRECATED: use set_symbols_style instead.
  988. * This method will be removed in 1.2.X
  989. *
  990. * @param string The style to make the brackets
  991. * @param boolean Whether to merge the new styles with the old or just
  992. * to overwrite them
  993. * @since 1.0.0
  994. * @deprecated In favour of set_symbols_style
  995. */
  996. function set_brackets_style($style, $preserve_defaults = false) {
  997. if (!$preserve_defaults) {
  998. $this->language_data['STYLES']['BRACKETS'][0] = $style;
  999. } else {
  1000. $this->language_data['STYLES']['BRACKETS'][0] .= $style;
  1001. }
  1002. }
  1003. /**
  1004. * Turns highlighting on/off for brackets
  1005. *
  1006. * This method is DEPRECATED: use set_symbols_highlighting instead.
  1007. * This method will be remove in 1.2.X
  1008. *
  1009. * @param boolean Whether to turn highlighting for brackets on or off
  1010. * @since 1.0.0
  1011. * @deprecated In favour of set_symbols_highlighting
  1012. */
  1013. function set_brackets_highlighting($flag) {
  1014. $this->lexic_permissions['BRACKETS'] = ($flag) ? true : false;
  1015. }
  1016. /**
  1017. * Sets the styles for symbols. If $preserve_defaults is
  1018. * true, then styles are merged with the default styles, with the
  1019. * user defined styles having priority
  1020. *
  1021. * @param string The style to make the symbols
  1022. * @param boolean Whether to merge the new styles with the old or just
  1023. * to overwrite them
  1024. * @param int Tells the group of symbols for which style should be set.
  1025. * @since 1.0.1
  1026. */
  1027. function set_symbols_style($style, $preserve_defaults = false, $group = 0) {
  1028. // Update the style of symbols
  1029. if (!$preserve_defaults) {
  1030. $this->language_data['STYLES']['SYMBOLS'][$group] = $style;
  1031. } else {
  1032. $this->language_data['STYLES']['SYMBOLS'][$group] .= $style;
  1033. }
  1034. // For backward compatibility
  1035. if (0 == $group) {
  1036. $this->set_brackets_style ($style, $preserve_defaults);
  1037. }
  1038. }
  1039. /**
  1040. * Turns highlighting on/off for symbols
  1041. *
  1042. * @param boolean Whether to turn highlighting for symbols on or off
  1043. * @since 1.0.0
  1044. */
  1045. function set_symbols_highlighting($flag) {
  1046. // Update lexic permissions for this symbol group
  1047. $this->lexic_permissions['SYMBOLS'] = ($flag) ? true : false;
  1048. // For backward compatibility
  1049. $this->set_brackets_highlighting ($flag);
  1050. }
  1051. /**
  1052. * Sets the styles for strings. If $preserve_defaults is
  1053. * true, then styles are merged with the default styles, with the
  1054. * user defined styles having priority
  1055. *
  1056. * @param string The style to make the escape characters
  1057. * @param boolean Whether to merge the new styles with the old or just
  1058. * to overwrite them
  1059. * @param int Tells the group of strings for which style should be set.
  1060. * @since 1.0.0
  1061. */
  1062. function set_strings_style($style, $preserve_defaults = false, $group = 0) {
  1063. if (!$preserve_defaults) {
  1064. $this->language_data['STYLES']['STRINGS'][$group] = $style;
  1065. } else {
  1066. $this->language_data['STYLES']['STRINGS'][$group] .= $style;
  1067. }
  1068. }
  1069. /**
  1070. * Turns highlighting on/off for strings
  1071. *
  1072. * @param boolean Whether to turn highlighting for strings on or off
  1073. * @since 1.0.0
  1074. */
  1075. function set_strings_highlighting($flag) {
  1076. $this->lexic_permissions['STRINGS'] = ($flag) ? true : false;
  1077. }
  1078. /**
  1079. * Sets the styles for strict code blocks. If $preserve_defaults is
  1080. * true, then styles are merged with the default styles, with the
  1081. * user defined styles having priority
  1082. *
  1083. * @param string The style to make the script blocks
  1084. * @param boolean Whether to merge the new styles with the old or just
  1085. * to overwrite them
  1086. * @param int Tells the group of script blocks for which style should be set.
  1087. * @since 1.0.8.4
  1088. */
  1089. function set_script_style($style, $preserve_defaults = false, $group = 0) {
  1090. // Update the style of symbols
  1091. if (!$preserve_defaults) {
  1092. $this->language_data['STYLES']['SCRIPT'][$group] = $style;
  1093. } else {
  1094. $this->language_data['STYLES']['SCRIPT'][$group] .= $style;
  1095. }
  1096. }
  1097. /**
  1098. * Sets the styles for numbers. If $preserve_defaults is
  1099. * true, then styles are merged with the default styles, with the
  1100. * user defined styles having priority
  1101. *
  1102. * @param string The style to make the numbers
  1103. * @param boolean Whether to merge the new styles with the old or just
  1104. * to overwrite them
  1105. * @param int Tells the group of numbers for which style should be set.
  1106. * @since 1.0.0
  1107. */
  1108. function set_numbers_style($style, $preserve_defaults = false, $group = 0) {
  1109. if (!$preserve_defaults) {
  1110. $this->language_data['STYLES']['NUMBERS'][$group] = $style;
  1111. } else {
  1112. $this->language_data['STYLES']['NUMBERS'][$group] .= $style;
  1113. }
  1114. }
  1115. /**
  1116. * Turns highlighting on/off for numbers
  1117. *
  1118. * @param boolean Whether to turn highlighting for numbers on or off
  1119. * @since 1.0.0
  1120. */
  1121. function set_numbers_highlighting($flag) {
  1122. $this->lexic_permissions['NUMBERS'] = ($flag) ? true : false;
  1123. }
  1124. /**
  1125. * Sets the styles for methods. $key is a number that references the
  1126. * appropriate "object splitter" - see the language file for the language
  1127. * you are highlighting to get this number. If $preserve_defaults is
  1128. * true, then styles are merged with the default styles, with the
  1129. * user defined styles having priority
  1130. *
  1131. * @param int The key of the object splitter to change the styles of
  1132. * @param string The style to make the methods
  1133. * @param boolean Whether to merge the new styles with the old or just
  1134. * to overwrite them
  1135. * @since 1.0.0
  1136. */
  1137. function set_methods_style($key, $style, $preserve_defaults = false) {
  1138. if (!$preserve_defaults) {
  1139. $this->language_data['STYLES']['METHODS'][$key] = $style;
  1140. } else {
  1141. $this->language_data['STYLES']['METHODS'][$key] .= $style;
  1142. }
  1143. }
  1144. /**
  1145. * Turns highlighting on/off for methods
  1146. *
  1147. * @param boolean Whether to turn highlighting for methods on or off
  1148. * @since 1.0.0
  1149. */
  1150. function set_methods_highlighting($flag) {
  1151. $this->lexic_permissions['METHODS'] = ($flag) ? true : false;
  1152. }
  1153. /**
  1154. * Sets the styles for regexps. If $preserve_defaults is
  1155. * true, then styles are merged with the default styles, with the
  1156. * user defined styles having priority
  1157. *
  1158. * @param string The style to make the regular expression matches
  1159. * @param boolean Whether to merge the new styles with the old or just
  1160. * to overwrite them
  1161. * @since 1.0.0
  1162. */
  1163. function set_regexps_style($key, $style, $preserve_defaults = false) {
  1164. if (!$preserve_defaults) {
  1165. $this->language_data['STYLES']['REGEXPS'][$key] = $style;
  1166. } else {
  1167. $this->language_data['STYLES']['REGEXPS'][$key] .= $style;
  1168. }
  1169. }
  1170. /**
  1171. * Turns highlighting on/off for regexps
  1172. *
  1173. * @param int The key of the regular expression group to turn on or off
  1174. * @param boolean Whether to turn highlighting for the regular expression group on or off
  1175. * @since 1.0.0
  1176. */
  1177. function set_regexps_highlighting($key, $flag) {
  1178. $this->lexic_permissions['REGEXPS'][$key] = ($flag) ? true : false;
  1179. }
  1180. /**
  1181. * Sets whether a set of keywords are checked for in a case sensitive manner
  1182. *
  1183. * @param int The key of the keyword group to change the case sensitivity of
  1184. * @param boolean Whether to check in a case sensitive manner or not
  1185. * @since 1.0.0
  1186. */
  1187. function set_case_sensitivity($key, $case) {
  1188. $this->language_data['CASE_SENSITIVE'][$key] = ($case) ? true : false;
  1189. }
  1190. /**
  1191. * Sets the case that keywords should use when found. Use the constants:
  1192. *
  1193. * - GESHI_CAPS_NO_CHANGE: leave keywords as-is
  1194. * - GESHI_CAPS_UPPER: convert all keywords to uppercase where found
  1195. * - GESHI_CAPS_LOWER: convert all keywords to lowercase where found
  1196. *
  1197. * @param int A constant specifying what to do with matched keywords
  1198. * @since 1.0.1
  1199. */
  1200. function set_case_keywords($case) {
  1201. if (in_array($case, array(
  1202. GESHI_CAPS_NO_CHANGE, GESHI_CAPS_UPPER, GESHI_CAPS_LOWER))) {
  1203. $this->language_data['CASE_KEYWORDS'] = $case;
  1204. }
  1205. }
  1206. /**
  1207. * Sets how many spaces a tab is substituted for
  1208. *
  1209. * Widths below zero are ignored
  1210. *
  1211. * @param int The tab width
  1212. * @since 1.0.0
  1213. */
  1214. function set_tab_width($width) {
  1215. $this->tab_width = (int) $width;
  1216. //Check if it fit's the constraints:
  1217. if ($this->tab_width < 1) {
  1218. //Return it to the default
  1219. $this->tab_width = 8;
  1220. }
  1221. }
  1222. /**
  1223. * Sets whether or not to use tab-stop width specifed by language
  1224. *
  1225. * @param boolean Whether to use language-specific tab-stop widths
  1226. * @since 1.0.7.20
  1227. */
  1228. function set_use_language_tab_width($use) {
  1229. $this->use_language_tab_width = (bool) $use;
  1230. }
  1231. /**
  1232. * Returns the tab width to use, based on the current language and user
  1233. * preference
  1234. *
  1235. * @return int Tab width
  1236. * @since 1.0.7.20
  1237. */
  1238. function get_real_tab_width() {
  1239. if (!$this->use_language_tab_width ||
  1240. !isset($this->language_data['TAB_WIDTH'])) {
  1241. return $this->tab_width;
  1242. } else {
  1243. return $this->language_data['TAB_WIDTH'];
  1244. }
  1245. }
  1246. /**
  1247. * Enables/disables strict highlighting. Default is off, calling this
  1248. * method without parameters will turn it on. See documentation
  1249. * for more details on strict mode and where to use it.
  1250. *
  1251. * @param boolean Whether to enable strict mode or not
  1252. * @since 1.0.0
  1253. */
  1254. function enable_strict_mode($mode = true) {
  1255. if (GESHI_MAYBE == $this->language_data['STRICT_MODE_APPLIES']) {
  1256. $this->strict_mode = ($mode) ? GESHI_ALWAYS : GESHI_NEVER;
  1257. }
  1258. }
  1259. /**
  1260. * Disables all highlighting
  1261. *
  1262. * @since 1.0.0
  1263. * @todo Rewrite with array traversal
  1264. * @deprecated In favour of enable_highlighting
  1265. */
  1266. function disable_highlighting() {
  1267. $this->enable_highlighting(false);
  1268. }
  1269. /**
  1270. * Enables all highlighting
  1271. *
  1272. * The optional flag parameter was added in version 1.0.7.21 and can be used
  1273. * to enable (true) or disable (false) all highlighting.
  1274. *
  1275. * @since 1.0.0
  1276. * @param boolean A flag specifying whether to enable or disable all highlighting
  1277. * @todo Rewrite with array traversal
  1278. */
  1279. function enable_highlighting($flag = true) {
  1280. $flag = $flag ? true : false;
  1281. foreach ($this->lexic_permissions as $key => $value) {
  1282. if (is_array($value)) {
  1283. foreach ($value as $k => $v) {
  1284. $this->lexic_permissions[$key][$k] = $flag;
  1285. }
  1286. } else {
  1287. $this->lexic_permissions[$key] = $flag;
  1288. }
  1289. }
  1290. // Context blocks
  1291. $this->enable_important_blocks = $flag;
  1292. }
  1293. /**
  1294. * Given a file extension, this method returns either a valid geshi language
  1295. * name, or the empty string if it couldn't be found
  1296. *
  1297. * @param string The extension to get a language name for
  1298. * @param array A lookup array to use instead of the default one
  1299. * @since 1.0.5
  1300. * @todo Re-think about how this method works (maybe make it private and/or make it
  1301. * a extension->lang lookup?)
  1302. * @todo static?
  1303. */
  1304. function get_language_name_from_extension( $extension, $lookup = array() ) {
  1305. if ( !is_array($lookup) || empty($lookup)) {
  1306. $lookup = array(
  1307. '6502acme' => array( 'a', 's', 'asm', 'inc' ),
  1308. '6502tasm' => array( 'a', 's', 'asm', 'inc' ),
  1309. '6502kickass' => array( 'a', 's', 'asm', 'inc' ),
  1310. '68000devpac' => array( 'a', 's', 'asm', 'inc' ),
  1311. 'abap' => array('abap'),
  1312. 'actionscript' => array('as'),
  1313. 'ada' => array('a', 'ada', 'adb', 'ads'),
  1314. 'apache' => array('conf'),
  1315. 'asm' => array('ash', 'asm', 'inc'),
  1316. 'asp' => array('asp'),
  1317. 'bash' => array('sh'),
  1318. 'bf' => array('bf'),
  1319. 'c' => array('c', 'h'),
  1320. 'c_mac' => array('c', 'h'),
  1321. 'caddcl' => array(),
  1322. 'cadlisp' => array(),
  1323. 'cdfg' => array('cdfg'),
  1324. 'cobol' => array('cbl'),
  1325. 'cpp' => array('cpp', 'hpp', 'C', 'H', 'CPP', 'HPP'),
  1326. 'csharp' => array('cs'),
  1327. 'css' => array('css'),
  1328. 'd' => array('d'),
  1329. 'delphi' => array('dpk', 'dpr', 'pp', 'pas'),
  1330. 'diff' => array('diff', 'patch'),
  1331. 'dos' => array('bat', 'cmd'),
  1332. 'gdb' => array('kcrash', 'crash', 'bt'),
  1333. 'gettext' => array('po', 'pot'),
  1334. 'gml' => array('gml'),
  1335. 'gnuplot' => array('plt'),
  1336. 'groovy' => array('groovy'),
  1337. 'haskell' => array('hs'),
  1338. 'html4strict' => array('html', 'htm'),
  1339. 'ini' => array('ini', 'desktop'),
  1340. 'java' => array('java'),
  1341. 'javascript' => array('js'),
  1342. 'klonec' => array('kl1'),
  1343. 'klonecpp' => array('klx'),
  1344. 'latex' => arra

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