PageRenderTime 62ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/bbcodes/geshi_bbcode_include.php

https://gitlab.com/php-fusion/PHP-Fusion
PHP | 64 lines | 43 code | 3 blank | 18 comment | 10 complexity | 8a2b9ce3730a3d579e36b1b642da9e33 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, Apache-2.0
  1. <?php
  2. /*-------------------------------------------------------+
  3. | PHP-Fusion Content Management System
  4. | Copyright (C) PHP-Fusion Inc
  5. | https://www.php-fusion.co.uk/
  6. +--------------------------------------------------------+
  7. | Filename: geshi_bbcode_include.php
  8. | Author: Wooya
  9. | Fixed: slawekneo
  10. +--------------------------------------------------------+
  11. | This program is released as free software under the
  12. | Affero GPL license. You can redistribute it and/or
  13. | modify it under the terms of this license which you
  14. | can read by viewing the included agpl.txt or online
  15. | at www.gnu.org/licenses/agpl.html. Removal of this
  16. | copyright header is strictly prohibited without
  17. | written permission from the original author(s).
  18. +--------------------------------------------------------*/
  19. if (!defined("IN_FUSION")) { die("Access Denied"); }
  20. if (preg_match("/\/forum\//i", FUSION_REQUEST)) global $data;
  21. unset($lines);
  22. unset($ccount);
  23. unset($matches);
  24. include_once(INCLUDES."bbcodes/geshi/geshi.php");
  25. preg_match_all("#\[geshi=(.*?)\](.*?)\[/geshi\]#si", $text, $matches, PREG_PATTERN_ORDER);
  26. for ($i = 0; $i < count($matches[1]); $i++) {
  27. $lines = explode("\n", $matches[2][$i]);
  28. if (count($lines) < 200) {
  29. $input = str_replace('<br>', '', str_replace('<br />', '', str_replace('<br />', '', stripslashes($matches[2][$i]))));
  30. //replace problematic characters
  31. $search = array("\\", "&quot;", "&#39;", "&#92;", "&quot;", "&#39;", "&lt;", "&gt;", "&amp;");
  32. $replace = array("\\\\", "\"", "'", "\\", "\"", "\'", "<", ">", "&");
  33. $input = str_replace($search, $replace, $input);
  34. $geshi = new GeSHi($input, $matches[1][$i]);
  35. $geshi->set_header_type(GESHI_HEADER_PRE);
  36. $geshi->set_overall_style('font-family:\'Courier New\', Courier; font-size:12px;');
  37. $geshi->set_link_styles(GESHI_LINK, 'font-weight:bold;');
  38. $geshi->set_link_styles(GESHI_HOVER, 'background-color: #f0f000;');
  39. $geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 10);
  40. $geshi->set_footer_content($locale['bb_geshi_info']);
  41. $geshi->set_footer_content_style('font-family:Verdana,Arial,sans-serif;color:#808080;font-size:9px;font-weight:bold;background-color:#f0f0ff;border-top: 1px solid #d0d0d0;padding:2px;width:400px');
  42. if (preg_match("/\/forum\//i", FUSION_REQUEST) && isset($data['post_id'])) {
  43. $geshi_save = "<a href='".INCLUDES."bbcodes/geshi_bbcode_save.php?thread_id=".$_GET['thread_id']."&amp;post_id=".$data['post_id']."&amp;code_id=".$i."'><img src='".INCLUDES."bbcodes/images/geshi_save.png' alt='".$locale['bb_geshi_save']."' title='".$locale['bb_geshi_save']."' style='border:none' /></a>&nbsp;&nbsp;";
  44. } else {
  45. $geshi_save = "";
  46. }
  47. $text2 = "<div class='tbl-border tbl2' style='width:400px'>".$geshi_save."<strong>GeSHi: ".$geshi->get_language_name()."</strong></div><div class='tbl-border tbl1' style='width:400px;height:auto;white-space:nowrap;overflow:auto;background-color:#ffffff;'><code style='white-space:nowrap'>".$geshi->parse_code()."</code></div>";
  48. $text = str_replace($matches[0][$i], $text2, $text);
  49. } else {
  50. $ccount = substr_count($text, "[geshi=");
  51. for ($i = 0; $i < $ccount; $i++) {
  52. if (preg_match("/\/forum\//i", FUSION_REQUEST) && isset($data['post_id'])) {
  53. $geshi_save = "<a href=\'".INCLUDES."bbcodes/geshi_bbcode_save.php?thread_id=".$_GET['thread_id']."&amp;post_id=".$data['post_id']."&amp;code_id=".$i."\'><img src=\'".INCLUDES."bbcodes/images/geshi_save.png\' alt=\'".$locale['bb_geshi_save']."\' title=\'".$locale['bb_geshi_save']."\' style=\'border:none\' /></a>&nbsp;&nbsp;";
  54. } else {
  55. $geshi_save = "";
  56. }
  57. $text = preg_replace("#\[geshi=(.*?)\](.*?)\[/geshi\]#sie", "'<div class=\'tbl-border tbl2\' style=\'width:400px\'>".$geshi_save."<strong><i><u>".$locale['bb_geshi_parser1'].":</u></i> ".$locale['bb_geshi_parser2'].":</strong></div><div class=\'tbl-border tbl1\' style=\'width:400px;white-space:nowrap;overflow:auto\'><code style=\'white-space:nowrap\'>'.formatcode('\\2').'<br /><br /><br /></code></div>'", $text);
  58. }
  59. }
  60. unset($lines);
  61. }