Kanji Frequency Data as Compiled from Aozora Bunko
Written by John Rozewicki   
Monday, 26 March 2007

This is PHP from the geshibot.php File
  1. <?php
  2.  
  3. /**
  4. * Geshi Syntax Higlighting Plugin for Joomla. Uses the Geshi Highlighting Engine/Class.
  5. * @version 1.0.1
  6. * @copyright (c) 2006, Fiji Web Design, www.fijiwebdesign.com
  7. * @license GNU/GPL
  8. */
  9.  
  10. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  11.  
  12. $_MAMBOTS->registerFunction( 'onPrepareContent', 'geshibot_onDisplayContent');
  13.  
  14. // load the geshi bot to parse content
  15. function geshibot_onDisplayContent ($published, &$row, &$params, $page = 0 ) {
  16. global $mosConfig_absolute_path;
  17. // check whether mambot has been unpublished
  18. if ( !$published ) {
  19. return true;
  20. }
  21. // params
  22. if (!isset($GLOBALS['GESHIBOT_PARAMS'])) {
  23. $GLOBALS['GESHIBOT_PARAMS'] = geshibot_getParams('geshibot', 'content'); // parameters
  24. }
  25. $botParams =& $GLOBALS['GESHIBOT_PARAMS'];
  26. if (intval($botParams->def( 'tag' )) == 0) {
  27. $regex = "/<pre\s*(.*?)>(.*?)<\/pre>/is";
  28. } else {
  29. $regex = "/{geshibot(\s| )*(.*?)}(.*?){\/geshibot}/is";
  30. }
  31. // define users gid for access priviledges
  32. if (isset($row->modified_by) && $row->modified_by != 0) {
  33. $author_id = $row->modified_by;
  34. } else {
  35. $author_id = isset($row->created_by) ? $row->created_by : 0;
  36. }
  37. geshibot_setGID($author_id);
  38. //echo geshibot_object2HTML($row);
  39. // replace code with syntax highlighted code
  40. $row->text = str_replace('{joomla_dir}', $mosConfig_absolute_path, $row->text);
  41. $row->text = preg_replace_callback($regex, 'geshibot_replace_init', $row->text);
  42. ?>
  43. <script type="text/javascript">
  44. <!--
  45. <?php
  46. if ($botParams->def( 'joomla_css' ) == 'yes' && !defined('geshi_joomla_css')) {
  47. define('geshi_joomla_css', 1);
  48. ?>
  49. /**
  50. * Replaces the geshi default classes with mambo/joomla classes
  51. */
  52. function replaceGeshiWithMamboClasses() {
  53. if (document && document.getElementsByTagName) {
  54. var pre_items = document.getElementsByTagName('pre');
  55. var n = pre_items.length;
  56. for(var i = 0; i < n; i++) {
  57. // divs
  58. var divs = pre_items[i].getElementsByTagName('div');
  59. var dlen = divs.length;
  60. for (var j = 0; j < dlen; j++) {
  61. if (divs[j].className == 'head') { // header
  62. var className = 'sectiontableheader';
  63. } else if (divs[j].className == 'foot') { // footer
  64. var className = 'small';
  65. } else if (divs[j].className == ' ') { // code lines
  66. var className = 'sectiontableentry1';
  67. } else {
  68. var className = '';
  69. }
  70. divs[j].className += ' '+className;
  71. }
  72. // anchors
  73. var a_items = pre_items[i].getElementsByTagName('a');
  74. var alen = a_items.length;
  75. for (var l = 0; l < alen; l++) {
  76. a_items[l].target = '_blank';
  77. a_items[l].setAttribute('target', '_blank');
  78. }
  79. // list items
  80. var li_items = pre_items[i].getElementsByTagName('li');
  81. var ilen = li_items.length;
  82. for (var k = 0; k < ilen; k++) {
  83. li_items[k].className += ' sectiontableentry1';
  84. }
  85. }
  86. }
  87. }
  88. // initiate our class replacements
  89. addLoadEvent(replaceGeshiWithMamboClasses);
  90. <?php } ?>
  91. <?php
  92. if ($botParams->def( 'show_copy' ) == 'yes' && !defined('geshi_show_copy')) {
  93. define('geshi_show_copy', 1);
  94. ?>
  95.  
  96. // add copy link to code highlights
  97. function addCodeView() {
  98. if (document && document.getElementsByTagName) {
  99. var divs = document.getElementsByTagName('div');
  100. var dlen = divs.length;
  101. for (var j = 0; j < dlen; j++) {
  102. var pattern = new RegExp("(^|\\s)foot(\\s|$)");
  103. if ( pattern.test(divs[j].className) ) { // footer class
  104. if (divs[j]._button == 1) continue;
  105. <?php if (intval($botParams->def( 'show_copy_type')) == 0) { ?>
  106. divs[j].innerHTML += ' <input type="button" onclick="botgeshi_copy(this); return false;" value="<?php echo $botParams->def( 'show_copy_label', 'View Source' ); ?>" class="button" />';
  107. <?php } else { ?>
  108. divs[j].innerHTML += ' <a href="#" onclick="botgeshi_copy(this); return false;"><?php echo $botParams->def( 'show_copy_label', 'View Source' ); ?></a>';
  109. <?php } ?>
  110. divs[j]._button = 1;
  111. }
  112. }
  113. }
  114. }
  115. // copy the code text to new window
  116. function botgeshi_copy(_this) {
  117. if (_this && _this.parentNode) {
  118. var source = _this.parentNode.parentNode.nextSibling;
  119. var name = source.className;
  120. var _source = botgeshi_decode(source.innerHTML);
  121. _source = '<textarea style="width: 100%; height: 100%;">'+html2entities(_source)+'</textarea>';
  122. writeSourceWindow(_source, name, '[source view]');
  123. }
  124. }
  125. // writes content to a new window
  126. function writeSourceWindow(txt, name, title) {
  127. top.winRef = window.open('', name,
  128. 'width=550,height=450'
  129. +',menubar=0'
  130. +',toolbar=0'
  131. +',status=0'
  132. +',scrollbars=0'
  133. +',resizable=1');
  134. top.winRef.document.writeln(
  135. '<html><head><title>'+title+'</title></head>'
  136. +'<body bgcolor=white onLoad="self.focus()">'
  137. +txt
  138. +'</body></html>'
  139. );
  140. top.winRef.document.body.style.overflow = 'hidden'; // hide scroll in FF
  141. top.winRef.document.close();
  142. top.winRef.focus();
  143. }
  144. // decode uriencoded text
  145. function botgeshi_decode(txt) {
  146. txt = txt.replace(/\+/g, ' ');
  147. if (decodeURIComponent) {
  148. return decodeURIComponent(txt);
  149. }
  150. if (unescape) {
  151. return unescape(txt);
  152. }
  153. return txt;
  154. }
  155. function html2entities(str){
  156. var re = /[<>"'&]/g
  157. str = str.replace(re, function(m) { return replacechar(m); });
  158. return str;
  159. }
  160. function replacechar(match){
  161. if (match=="<")
  162. return "<";
  163. else if (match==">")
  164. return ">";
  165. else if (match=="\"")
  166. return """;
  167. else if (match=="'")
  168. return "&#039;";
  169. else if (match=="&")
  170. return "&";
  171. }
  172. // initiate our class replacements
  173. addLoadEvent(addCodeView);
  174. <?php } ?>
  175. /**
  176. * Adds an onload event to the window
  177. */
  178. function addLoadEvent(fn) {
  179. if (typeof(window.onload) == 'function') {
  180. var _fn = window.onload;
  181. window.onload = function() {
  182. _fn();
  183. fn();
  184. }
  185. } else {
  186. window.onload = fn;
  187. }
  188. }
  189. //-->
  190. </script>
  191. <?php
  192. return true;
  193. }
  194.  
  195. // get the right match before sending it to our replace function
  196. function geshibot_replace_init($matches) {
  197. $botParams = $GLOBALS['GESHIBOT_PARAMS'];
  198. //echo geshibot_object2HTML($matches);
  199. if (intval($botParams->def( 'tag' )) == 0) {
  200. return geshibot_replace($matches);
  201. } else {
  202. $_matches = array($matches[0], str_replace('"', '"', $matches[2]), $matches[3]);
  203. return geshibot_replace($_matches);
  204. }
  205. }
  206.  
  207. // callback function for preg_replace_callback
  208. function geshibot_replace($matches) {
  209. // language
  210. preg_match("/(language|lang)=\"([^\"]*)\"/", $matches[1], $_matches);
  211. $language = isset($_matches[2]) ? $_matches[2] : '';
  212. // file
  213. preg_match("/(filepath|file)=\"([^\"]*)\"/", $matches[1], $_matches);
  214. $file = isset($_matches[2]) ? $_matches[2] : false;
  215. // source, htmlDecoded
  216. if ($file) {
  217. $source = geshibot_file_get_contents($file);
  218. } else {
  219. $source = geshibot_decodeHtmlEntities($matches[2]);
  220. }
  221. // header
  222. preg_match("/(header|head)=\"([^\"]*)\"/", $matches[1], $_matches);
  223. $header = isset($_matches[2]) ? $_matches[2] : '';
  224. // footer
  225. preg_match("/(footer|foot)=\"([^\"]*)\"/", $matches[1], $_matches);
  226. $footer = isset($_matches[2]) ? $_matches[2] : '   ';
  227. //echo geshibot_object2HTML(array('tag_attribs'=>$matches[1], 'language'=>$language, 'header'=>$header, 'footer'=>$footer, 'file'=>$file,'source'=>$source)); // debug
  228. // highlight code
  229. $h_source = geshibot_geshi ($source, $language, $header, $footer);
  230. // retrieve the geshibot params from super globals Array
  231. $botParams = $GLOBALS['GESHIBOT_PARAMS'];
  232. if ($botParams->def( 'show_copy' ) == 'yes') {
  233. // return the highlighted code and original code in a div with unique id
  234. $id = (isset($GLOBALS['geshibot_load_id'])) ? $GLOBALS['geshibot_load_id']++ : 0;
  235. $GLOBALS['geshibot_load_id'] = $id;
  236. $o_source = '<div class="original_source_'.$id.'" style="display:none;">'.rawurlencode($source).'</div>';
  237. return '<div id="geshibot_load_'.$id.'_'.sha1($source).'">'.$h_source.$o_source.'</div>';
  238. } else {
  239. // return just the highlighted source
  240. return $h_source;
  241. }
  242. }
  243.  
  244. function geshibot_geshi ($source, $language = 'php', $header = 'Code:', $footer = ' ') {
  245.  
  246. // include the geshi class
  247. if (!require_once($GLOBALS['mosConfig_absolute_path'].'/mambots/content/geshibot/geshi.class.php')) {
  248. return false;
  249. }
  250. // First the initialisation: source code to highlight and the language to use. Make sure
  251. // you sanitise correctly if you use $_POST of course - this very script has had a security
  252. // advisory against it in the past because of this. Please try not to use this script on a
  253. // live site.
  254. $geshi =& new GeSHi($source, $language);
  255. // retrieve the geshibot params from super globals Array
  256. $botParams =& $GLOBALS['GESHIBOT_PARAMS'];
  257. // Load the Geshi CSS once for each language, if set in Parameters
  258. if ($botParams->def( 'geshibot_css' ) == 'yes') {
  259. if ( !defined($language.'_css') ) {
  260. echo '<style type="text/css">';
  261. echo $geshi->get_stylesheet();
  262. echo '</style>';
  263. define($language.'_css', true);
  264. }
  265. }
  266. // Use the PRE header. This means less output source since we don't have to output  
  267. // everywhere. Of course it also means you can't set the tab width.
  268. $geshi->set_header_type(GESHI_HEADER_PRE);
  269. // Enable CSS classes. You can use get_stylesheet() to output a stylesheet for your code. Using
  270. // CSS classes results in much less output source.
  271. $geshi->enable_classes();
  272. // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy
  273. if ($botParams->def( 'lines' ) == 'yes') {
  274. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $botParams->def( 'fancylinenum' ));
  275. }
  276. // Set the style for the PRE around the code. The line numbers are contained within this box (not
  277. // XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate
  278. // the reduced source output).
  279. //$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
  280. // Set the style for line numbers. In order to get style for line numbers working, the <li> element
  281. // is being styled. This means that the code on the line will also be styled, and most of the time
  282. // you don't want this. So the set_code_style reverts styles for the line (by using a <div> on the line).
  283. // So the source output looks like this:
  284. //
  285. // <pre style="[set_overall_style styles]"><ol>
  286. // <li style="[set_line_style styles]"><div style="[set_code_style styles]>...</div></li>
  287. // ...
  288. // </ol></pre>
  289. $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
  290. $geshi->set_code_style('color: #000020;', 'color: #000020;');
  291.  
  292. // Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
  293. // note that classes must be enabled for this to work.
  294. $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
  295. $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  296.  
  297. // Use the header/footer functionality. This puts a div with content within the PRE element, so it is
  298. // affected by the styles set by set_overall_style. So if the PRE has a border then the header/footer will
  299. // appear inside it.
  300. $geshi->set_header_content($header);
  301. //$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
  302.  
  303. // You can use <TIME> and <VERSION> as placeholders
  304. $geshi->set_footer_content($footer);
  305. //$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
  306. // highlight the code using geshi
  307. return $geshi->parse_code();
  308. }
  309.  
  310. // get the params set for the plugin
  311. function geshibot_getParams($botname, $folder = 'content') {
  312. global $database, $_MAMBOTS;
  313. if ( !isset($_MAMBOTS->_content_mambot_params[$botname]) ) {
  314. // load mambot params info
  315. $query = "SELECT params"
  316. . "\n FROM #__mambots"
  317. . "\n WHERE element = '$botname'"
  318. . "\n AND folder = '$folder'"
  319. ;
  320. $database->setQuery( $query );
  321. $database->loadObject($mambot);
  322.  
  323. // save query to class variable
  324. $_MAMBOTS->_content_mambot_params[$botname] = $mambot;
  325. }
  326.  
  327. $mambot = $_MAMBOTS->_content_mambot_params[$botname];
  328.  
  329. $botParams = new mosParameters( $mambot->params );
  330. return $botParams;
  331. }
  332.  
  333. // decodes html entities
  334. function geshibot_decodeHtmlEntities($text) {
  335.  
  336. $html_entities_match = array( "|\<BR>|","|\<br \/\>|", "#<#", "#>#", "|&#39;|", '#"#', '# #' );
  337. $html_entities_replace = array( "\n","\n", '<', '>', "'", '"', ' ' );
  338.  
  339. $text = preg_replace( $html_entities_match, $html_entities_replace, $text );
  340.  
  341. $text = str_replace('<', '<', $text);
  342. $text = str_replace('>', '>', $text);
  343.  
  344. /*
  345. // Replace 2 spaces with "  " so non-tabbed code indents without making huge long lines.
  346. $text = str_replace(" ", "  ", $text);
  347. // now Replace 2 spaces with "  " to catch odd #s of spaces.
  348. $text = str_replace(" ", "  ", $text);
  349. */
  350. // Replace tabs with "   " so tabbed code indents sorta right without making huge long lines.
  351. $text = str_replace("\t", "   ", $text);
  352. //$text = str_replace( "\t", ' ', $text );
  353. return $text;
  354. }
  355.  
  356. // sets the GID of the author
  357. function geshibot_setGID($id) {
  358. global $database;
  359. $query = "SELECT gid from #__users WHERE id = $id LIMIT 1";
  360. $database->setQuery($query);
  361. $gid = $database->loadResult();
  362. $GLOBALS['geshibot_author_gid'] = $gid;
  363. }
  364.  
  365. // gets the content of a file if the article author is allowed access
  366. function geshibot_file_get_contents($file) {
  367.  
  368. $botParams =& $GLOBALS['GESHIBOT_PARAMS'];
  369. if ($GLOBALS['geshibot_author_gid'] < intval($botParams->def( 'acl_files' ))) {
  370. // this user does not have enough access to get file contents
  371. $content = $botParams->def( 'acl_files_msg' ).' author gid:'.$GLOBALS['geshibot_author_gid'].' allowed gid:'.intval($botParams->def( 'acl_files' ));
  372. } else {
  373. $content = file_get_contents($file);
  374. }
  375.  
  376. return $content;
  377. }
  378.  
  379. // object dump function, debugging only
  380. define('geshi_debug', 0); // 0: off, 1: on
  381. define('geshi_dump_type', 1); // 0: html, 1: raw txt
  382. function geshibot_object2HTML($obj, $depth = 0) {
  383. if (geshi_debug == 0) return '';
  384. $html = '';
  385. if ((is_array($obj) || is_object($obj)) && count($obj) > 0) {
  386. foreach($obj as $i=>$x) {
  387. if (is_object($x) || is_array($x)) {
  388. $html .= '<div class="obj_parent">';
  389. $html .= '<span>'.$i.'</span>';
  390. $html .= geshibot_object2HTML($x, $depth+1);
  391. $html .= '</div>';
  392. } else {
  393. $html .= '<div class="obj_child" style="padding-left:10px;">'.$i.'=>'.geshi_dump2HTML($x).'</div>';
  394. }
  395. }
  396. } else if ((is_array($obj) || is_object($obj))) {
  397. $html .= '<div class="obj_child">'.var_dump($obj).'</div>'; // catch empty array
  398. } else {
  399. $html .= '<div class="obj_child">'.geshi_dump2HTML($obj).'</div>'; // cactch non-arrays/objects
  400. }
  401. return $html;
  402. }
  403.  
  404. function geshi_dump2HTML($var) {
  405. if (defined('geshi_dump_type') && geshi_dump_type != 0) {
  406. return htmlentities($var);
  407. } else {
  408. return nl2br($var);
  409. }
  410. }
  411.  
  412.  
  413. if (geshi_debug == 1) {
  414. ?>
  415.  
  416. <style type="text/css">
  417.  
  418. .obj_parent {
  419. border: 1px solid gray;
  420. margin: 1px;
  421. }
  422.  
  423. .obj_child {
  424. border: 1px dotted gray;
  425. margin: 1px;
  426. }
  427.  
  428. </style>
  429.  
  430. <?php } ?>
 
 

This is PHP from the geshibot.php File
  1. <?php
  2.  
  3. /**
  4. * Geshi Syntax Higlighting Plugin for Joomla. Uses the Geshi Highlighting Engine/Class.
  5. * @version 1.0.1
  6. * @copyright (c) 2006, Fiji Web Design, www.fijiwebdesign.com
  7. * @license GNU/GPL
  8. */
  9.  
  10. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  11.  
  12. $_MAMBOTS->registerFunction( 'onPrepareContent', 'geshibot_onDisplayContent');
  13.  
  14. // load the geshi bot to parse content
  15. function geshibot_onDisplayContent ($published, &$row, &$params, $page = 0 ) {
  16. global $mosConfig_absolute_path;
  17. // check whether mambot has been unpublished
  18. if ( !$published ) {
  19. return true;
  20. }
  21. // params
  22. if (!isset($GLOBALS['GESHIBOT_PARAMS'])) {
  23. $GLOBALS['GESHIBOT_PARAMS'] = geshibot_getParams('geshibot', 'content'); // parameters
  24. }
  25. $botParams =& $GLOBALS['GESHIBOT_PARAMS'];
  26. if (intval($botParams->def( 'tag' )) == 0) {
  27. $regex = "/<pre\s*(.*?)>(.*?)<\/pre>/is";
  28. } else {
  29. $regex = "/{geshibot(\s| )*(.*?)}(.*?){\/geshibot}/is";
  30. }
  31. // define users gid for access priviledges
  32. if (isset($row->modified_by) && $row->modified_by != 0) {
  33. $author_id = $row->modified_by;
  34. } else {
  35. $author_id = isset($row->created_by) ? $row->created_by : 0;
  36. }
  37. geshibot_setGID($author_id);
  38. //echo geshibot_object2HTML($row);
  39. // replace code with syntax highlighted code
  40. $row->text = str_replace('{joomla_dir}', $mosConfig_absolute_path, $row->text);
  41. $row->text = preg_replace_callback($regex, 'geshibot_replace_init', $row->text);
  42. ?>
  43. <script type="text/javascript">
  44. <!--
  45. <?php
  46. if ($botParams->def( 'joomla_css' ) == 'yes' && !defined('geshi_joomla_css')) {
  47. define('geshi_joomla_css', 1);
  48. ?>
  49. /**
  50. * Replaces the geshi default classes with mambo/joomla classes
  51. */
  52. function replaceGeshiWithMamboClasses() {
  53. if (document && document.getElementsByTagName) {
  54. var pre_items = document.getElementsByTagName('pre');
  55. var n = pre_items.length;
  56. for(var i = 0; i < n; i++) {
  57. // divs
  58. var divs = pre_items[i].getElementsByTagName('div');
  59. var dlen = divs.length;
  60. for (var j = 0; j < dlen; j++) {
  61. if (divs[j].className == 'head') { // header
  62. var className = 'sectiontableheader';
  63. } else if (divs[j].className == 'foot') { // footer
  64. var className = 'small';
  65. } else if (divs[j].className == ' ') { // code lines
  66. var className = 'sectiontableentry1';
  67. } else {
  68. var className = '';
  69. }
  70. divs[j].className += ' '+className;
  71. }
  72. // anchors
  73. var a_items = pre_items[i].getElementsByTagName('a');
  74. var alen = a_items.length;
  75. for (var l = 0; l < alen; l++) {
  76. a_items[l].target = '_blank';
  77. a_items[l].setAttribute('target', '_blank');
  78. }
  79. // list items
  80. var li_items = pre_items[i].getElementsByTagName('li');
  81. var ilen = li_items.length;
  82. for (var k = 0; k < ilen; k++) {
  83. li_items[k].className += ' sectiontableentry1';
  84. }
  85. }
  86. }
  87. }
  88. // initiate our class replacements
  89. addLoadEvent(replaceGeshiWithMamboClasses);
  90. <?php } ?>
  91. <?php
  92. if ($botParams->def( 'show_copy' ) == 'yes' && !defined('geshi_show_copy')) {
  93. define('geshi_show_copy', 1);
  94. ?>
  95.  
  96. // add copy link to code highlights
  97. function addCodeView() {
  98. if (document && document.getElementsByTagName) {
  99. var divs = document.getElementsByTagName('div');
  100. var dlen = divs.length;
  101. for (var j = 0; j < dlen; j++) {
  102. var pattern = new RegExp("(^|\\s)foot(\\s|$)");
  103. if ( pattern.test(divs[j].className) ) { // footer class
  104. if (divs[j]._button == 1) continue;
  105. <?php if (intval($botParams->def( 'show_copy_type')) == 0) { ?>
  106. divs[j].innerHTML += ' <input type="button" onclick="botgeshi_copy(this); return false;" value="<?php echo $botParams->def( 'show_copy_label', 'View Source' ); ?>" class="button" />';
  107. <?php } else { ?>
  108. divs[j].innerHTML += ' <a href="#" onclick="botgeshi_copy(this); return false;"><?php echo $botParams->def( 'show_copy_label', 'View Source' ); ?></a>';
  109. <?php } ?>
  110. divs[j]._button = 1;
  111. }
  112. }
  113. }
  114. }
  115. // copy the code text to new window
  116. function botgeshi_copy(_this) {
  117. if (_this && _this.parentNode) {
  118. var source = _this.parentNode.parentNode.nextSibling;
  119. var name = source.className;
  120. var _source = botgeshi_decode(source.innerHTML);
  121. _source = '<textarea style="width: 100%; height: 100%;">'+html2entities(_source)+'</textarea>';
  122. writeSourceWindow(_source, name, '[source view]');
  123. }
  124. }
  125. // writes content to a new window
  126. function writeSourceWindow(txt, name, title) {
  127. top.winRef = window.open('', name,
  128. 'width=550,height=450'
  129. +',menubar=0'
  130. +',toolbar=0'
  131. +',status=0'
  132. +',scrollbars=0'
  133. +',resizable=1');
  134. top.winRef.document.writeln(
  135. '<html><head><title>'+title+'</title></head>'
  136. +'<body bgcolor=white onLoad="self.focus()">'
  137. +txt
  138. +'</body></html>'
  139. );
  140. top.winRef.document.body.style.overflow = 'hidden'; // hide scroll in FF
  141. top.winRef.document.close();
  142. top.winRef.focus();
  143. }
  144. // decode uriencoded text
  145. function botgeshi_decode(txt) {
  146. txt = txt.replace(/\+/g, ' ');
  147. if (decodeURIComponent) {
  148. return decodeURIComponent(txt);
  149. }
  150. if (unescape) {
  151. return unescape(txt);
  152. }
  153. return txt;
  154. }
  155. function html2entities(str){
  156. var re = /[<>"'&]/g
  157. str = str.replace(re, function(m) { return replacechar(m); });
  158. return str;
  159. }
  160. function replacechar(match){
  161. if (match=="<")
  162. return "<";
  163. else if (match==">")
  164. return ">";
  165. else if (match=="\"")
  166. return """;
  167. else if (match=="'")
  168. return "&#039;";
  169. else if (match=="&")
  170. return "&";
  171. }
  172. // initiate our class replacements
  173. addLoadEvent(addCodeView);
  174. <?php } ?>
  175. /**
  176. * Adds an onload event to the window
  177. */
  178. function addLoadEvent(fn) {
  179. if (typeof(window.onload) == 'function') {
  180. var _fn = window.onload;
  181. window.onload = function() {
  182. _fn();
  183. fn();
  184. }
  185. } else {
  186. window.onload = fn;
  187. }
  188. }
  189. //-->
  190. </script>
  191. <?php
  192. return true;
  193. }
  194.  
  195. // get the right match before sending it to our replace function
  196. function geshibot_replace_init($matches) {
  197. $botParams = $GLOBALS['GESHIBOT_PARAMS'];
  198. //echo geshibot_object2HTML($matches);
  199. if (intval($botParams->def( 'tag' )) == 0) {
  200. return geshibot_replace($matches);
  201. } else {
  202. $_matches = array($matches[0], str_replace('"', '"', $matches[2]), $matches[3]);
  203. return geshibot_replace($_matches);
  204. }
  205. }
  206.  
  207. // callback function for preg_replace_callback
  208. function geshibot_replace($matches) {
  209. // language
  210. preg_match("/(language|lang)=\"([^\"]*)\"/", $matches[1], $_matches);
  211. $language = isset($_matches[2]) ? $_matches[2] : '';
  212. // file
  213. preg_match("/(filepath|file)=\"([^\"]*)\"/", $matches[1], $_matches);
  214. $file = isset($_matches[2]) ? $_matches[2] : false;
  215. // source, htmlDecoded
  216. if ($file) {
  217. $source = geshibot_file_get_contents($file);
  218. } else {
  219. $source = geshibot_decodeHtmlEntities($matches[2]);
  220. }
  221. // header
  222. preg_match("/(header|head)=\"([^\"]*)\"/", $matches[1], $_matches);
  223. $header = isset($_matches[2]) ? $_matches[2] : '';
  224. // footer
  225. preg_match("/(footer|foot)=\"([^\"]*)\"/", $matches[1], $_matches);
  226. $footer = isset($_matches[2]) ? $_matches[2] : '   ';
  227. //echo geshibot_object2HTML(array('tag_attribs'=>$matches[1], 'language'=>$language, 'header'=>$header, 'footer'=>$footer, 'file'=>$file,'source'=>$source)); // debug
  228. // highlight code
  229. $h_source = geshibot_geshi ($source, $language, $header, $footer);
  230. // retrieve the geshibot params from super globals Array
  231. $botParams = $GLOBALS['GESHIBOT_PARAMS'];
  232. if ($botParams->def( 'show_copy' ) == 'yes') {
  233. // return the highlighted code and original code in a div with unique id
  234. $id = (isset($GLOBALS['geshibot_load_id'])) ? $GLOBALS['geshibot_load_id']++ : 0;
  235. $GLOBALS['geshibot_load_id'] = $id;
  236. $o_source = '<div class="original_source_'.$id.'" style="display:none;">'.rawurlencode($source).'</div>';
  237. return '<div id="geshibot_load_'.$id.'_'.sha1($source).'">'.$h_source.$o_source.'</div>';
  238. } else {
  239. // return just the highlighted source
  240. return $h_source;
  241. }
  242. }
  243.  
  244. function geshibot_geshi ($source, $language = 'php', $header = 'Code:', $footer = ' ') {
  245.  
  246. // include the geshi class
  247. if (!require_once($GLOBALS['mosConfig_absolute_path'].'/mambots/content/geshibot/geshi.class.php')) {
  248. return false;
  249. }
  250. // First the initialisation: source code to highlight and the language to use. Make sure
  251. // you sanitise correctly if you use $_POST of course - this very script has had a security
  252. // advisory against it in the past because of this. Please try not to use this script on a
  253. // live site.
  254. $geshi =& new GeSHi($source, $language);
  255. // retrieve the geshibot params from super globals Array
  256. $botParams =& $GLOBALS['GESHIBOT_PARAMS'];
  257. // Load the Geshi CSS once for each language, if set in Parameters
  258. if ($botParams->def( 'geshibot_css' ) == 'yes') {
  259. if ( !defined($language.'_css') ) {
  260. echo '<style type="text/css">';
  261. echo $geshi->get_stylesheet();
  262. echo '</style>';
  263. define($language.'_css', true);
  264. }
  265. }
  266. // Use the PRE header. This means less output source since we don't have to output  
  267. // everywhere. Of course it also means you can't set the tab width.
  268. $geshi->set_header_type(GESHI_HEADER_PRE);
  269. // Enable CSS classes. You can use get_stylesheet() to output a stylesheet for your code. Using
  270. // CSS classes results in much less output source.
  271. $geshi->enable_classes();
  272. // Enable line numbers. We want fancy line numbers, and we want every 5th line number to be fancy
  273. if ($botParams->def( 'lines' ) == 'yes') {
  274. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, $botParams->def( 'fancylinenum' ));
  275. }
  276. // Set the style for the PRE around the code. The line numbers are contained within this box (not
  277. // XHTML compliant btw, but if you are liberally minded about these things then you'll appreciate
  278. // the reduced source output).
  279. //$geshi->set_overall_style('color: #000066; border: 1px solid #d0d0d0; background-color: #f0f0f0;', true);
  280. // Set the style for line numbers. In order to get style for line numbers working, the <li> element
  281. // is being styled. This means that the code on the line will also be styled, and most of the time
  282. // you don't want this. So the set_code_style reverts styles for the line (by using a <div> on the line).
  283. // So the source output looks like this:
  284. //
  285. // <pre style="[set_overall_style styles]"><ol>
  286. // <li style="[set_line_style styles]"><div style="[set_code_style styles]>...</div></li>
  287. // ...
  288. // </ol></pre>
  289. $geshi->set_line_style('font: normal normal 95% \'Courier New\', Courier, monospace; color: #003030;', 'font-weight: bold; color: #006060;', true);
  290. $geshi->set_code_style('color: #000020;', 'color: #000020;');
  291.  
  292. // Styles for hyperlinks in the code. GESHI_LINK for default styles, GESHI_HOVER for hover style etc...
  293. // note that classes must be enabled for this to work.
  294. $geshi->set_link_styles(GESHI_LINK, 'color: #000060;');
  295. $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  296.  
  297. // Use the header/footer functionality. This puts a div with content within the PRE element, so it is
  298. // affected by the styles set by set_overall_style. So if the PRE has a border then the header/footer will
  299. // appear inside it.
  300. $geshi->set_header_content($header);
  301. //$geshi->set_header_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-bottom: 1px solid #d0d0d0; padding: 2px;');
  302.  
  303. // You can use <TIME> and <VERSION> as placeholders
  304. $geshi->set_footer_content($footer);
  305. //$geshi->set_footer_content_style('font-family: Verdana, Arial, sans-serif; color: #808080; font-size: 70%; font-weight: bold; background-color: #f0f0ff; border-top: 1px solid #d0d0d0; padding: 2px;');
  306. // highlight the code using geshi
  307. return $geshi->parse_code();
  308. }
  309.  
  310. // get the params set for the plugin
  311. function geshibot_getParams($botname, $folder = 'content') {
  312. global $database, $_MAMBOTS;
  313. if ( !isset($_MAMBOTS->_content_mambot_params[$botname]) ) {
  314. // load mambot params info
  315. $query = "SELECT params"
  316. . "\n FROM #__mambots"
  317. . "\n WHERE element = '$botname'"
  318. . "\n AND folder = '$folder'"
  319. ;
  320. $database->setQuery( $query );
  321. $database->loadObject($mambot);
  322.  
  323. // save query to class variable
  324. $_MAMBOTS->_content_mambot_params[$botname] = $mambot;
  325. }
  326.  
  327. $mambot = $_MAMBOTS->_content_mambot_params[$botname];
  328.  
  329. $botParams = new mosParameters( $mambot->params );
  330. return $botParams;
  331. }
  332.  
  333. // decodes html entities
  334. function geshibot_decodeHtmlEntities($text) {
  335.  
  336. $html_entities_match = array( "|\<BR>|","|\<br \/\>|", "#<#", "#>#", "|&#39;|", '#"#', '# #' );
  337. $html_entities_replace = array( "\n","\n", '<', '>', "'", '"', ' ' );
  338.  
  339. $text = preg_replace( $html_entities_match, $html_entities_replace, $text );
  340.  
  341. $text = str_replace('<', '<', $text);
  342. $text = str_replace('>', '>', $text);
  343.  
  344. /*
  345. // Replace 2 spaces with "  " so non-tabbed code indents without making huge long lines.
  346. $text = str_replace(" ", "  ", $text);
  347. // now Replace 2 spaces with "  " to catch odd #s of spaces.
  348. $text = str_replace(" ", "  ", $text);
  349. */
  350. // Replace tabs with "   " so tabbed code indents sorta right without making huge long lines.
  351. $text = str_replace("\t", "   ", $text);
  352. //$text = str_replace( "\t", ' ', $text );
  353. return $text;
  354. }
  355.  
  356. // sets the GID of the author
  357. function geshibot_setGID($id) {
  358. global $database;
  359. $query = "SELECT gid from #__users WHERE id = $id LIMIT 1";
  360. $database->setQuery($query);
  361. $gid = $database->loadResult();
  362. $GLOBALS['geshibot_author_gid'] = $gid;
  363. }
  364.  
  365. // gets the content of a file if the article author is allowed access
  366. function geshibot_file_get_contents($file) {
  367.  
  368. $botParams =& $GLOBALS['GESHIBOT_PARAMS'];
  369. if ($GLOBALS['geshibot_author_gid'] < intval($botParams->def( 'acl_files' ))) {
  370. // this user does not have enough access to get file contents
  371. $content = $botParams->def( 'acl_files_msg' ).' author gid:'.$GLOBALS['geshibot_author_gid'].' allowed gid:'.intval($botParams->def( 'acl_files' ));
  372. } else {
  373. $content = file_get_contents($file);
  374. }
  375.  
  376. return $content;
  377. }
  378.  
  379. // object dump function, debugging only
  380. define('geshi_debug', 0); // 0: off, 1: on
  381. define('geshi_dump_type', 1); // 0: html, 1: raw txt
  382. function geshibot_object2HTML($obj, $depth = 0) {
  383. if (geshi_debug == 0) return '';
  384. $html = '';
  385. if ((is_array($obj) || is_object($obj)) && count($obj) > 0) {
  386. foreach($obj as $i=>$x) {
  387. if (is_object($x) || is_array($x)) {
  388. $html .= '<div class="obj_parent">';
  389. $html .= '<span>'.$i.'</span>';
  390. $html .= geshibot_object2HTML($x, $depth+1);
  391. $html .= '</div>';
  392. } else {
  393. $html .= '<div class="obj_child" style="padding-left:10px;">'.$i.'=>'.geshi_dump2HTML($x).'</div>';
  394. }
  395. }
  396. } else if ((is_array($obj) || is_object($obj))) {
  397. $html .= '<div class="obj_child">'.var_dump($obj).'</div>'; // catch empty array
  398. } else {
  399. $html .= '<div class="obj_child">'.geshi_dump2HTML($obj).'</div>'; // cactch non-arrays/objects
  400. }
  401. return $html;
  402. }
  403.  
  404. function geshi_dump2HTML($var) {
  405. if (defined('geshi_dump_type') && geshi_dump_type != 0) {
  406. return htmlentities($var);
  407. } else {
  408. return nl2br($var);
  409. }
  410. }
  411.  
  412.  
  413. if (geshi_debug == 1) {
  414. ?>
  415.  
  416. <style type="text/css">
  417.  
  418. .obj_parent {
  419. border: 1px solid gray;
  420. margin: 1px;
  421. }
  422.  
  423. .obj_child {
  424. border: 1px dotted gray;
  425. margin: 1px;
  426. }
  427.  
  428. </style>
  429.  
  430. <?php } ?>
 
Trackback(0)
Comments (0)add comment

Write comment
password
 

busy
 
< Prev   Next >