Example #1
0
function code_example($code, $lang)
{
    if (strtolower($lang) == 'html') {
        $lang = 'html5';
    }
    geshi_highlight($code, $lang);
}
 /**
  * @param string $message
  * @param object $entity
  * @param string $module - just for translate to insertImageAttach
  * @return string
  * 
  * bb code process. 
  * Parse BB-codes & attaches markers.
  */
 public function parseBBCodes($message, $entity = false, $module = false)
 {
     $register = Register::getInstance();
     if (is_object($entity)) {
         if (is_object($entity->getAuthor())) {
             $ustatus = $entity->getAuthor()->getStatus();
             $title = $entity->getTitle();
         } else {
             if ($entity->getStatus() != false) {
                 $ustatus = $entity->getStatus();
             }
         }
     } else {
         if (is_array($entity)) {
             $ustatus = !empty($entity['status']) ? $entity['status'] : false;
             $title = !empty($entity['title']) ? $entity['title'] : false;
         }
     }
     if (empty($ustatus) || !$ustatus) {
         $ustatus = false;
     }
     if (empty($title) || !$title) {
         $title = false;
     }
     // hook (for plugins)
     $message = Plugins::intercept('before_print_page', $message);
     // Announce tags
     $start_tag = mb_strpos($message, '[announce]');
     $end_tag = mb_strpos($message, '[/announce]');
     if (false !== $start_tag && false !== $end_tag && $end_tag > $start_tag) {
         $message = preg_replace('#\\[announce\\].+\\[/announce\\]#sui', '', $message);
     }
     // Разрезаем слишком длинные слова
     //$message = wordwrap($message, 70, ' ', 1);
     //$message = preg_replace("#([^\s/\]\[]{100})#ui", "\\1 ", $message);
     // Тэги - [code], [php], [sql]
     preg_match_all("#\\[php\\](.+)\\[\\/php\\]#uisU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $matches[1][$i] = preg_replace('#^\\s*<\\?php(.*)\\?>\\s*$#uis', '$1', $matches[1][$i]);
         $matches[1][$i] = preg_replace('#^\\s*<\\?(.*)\\?>\\s*$#uis', '$1', $matches[1][$i]);
         $phpBlocks[] = '<div class="codePHP">' . $this->highlight_php_string('<?php ' . trim($matches[1][$i]) . '?>', true) . '</div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $phpBlocks[$i] = str_replace('<div class="codePHP"><br />', '<div class="codePHP">', $phpBlocks[$i]);
         $uniqidPHP = '[php_' . uniqid('') . ']';
         $uniqidsPHP[] = $uniqidPHP;
         $message = str_replace($matches[0][$i], $uniqidPHP, $message);
     }
     $spaces = array(' ', "\t");
     $entities = array('&nbsp;', '&nbsp;&nbsp;&nbsp;&nbsp;');
     preg_match_all("#\\[code\\](.+)\\[\\/code\\]#uisU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $codeBlocks[] = '<div class="bbCodeBlock"><div class="bbCodeName" style="padding-left: 5px; font-weight: bold; font-size: 7pt;"><b>Code:</b></div><div class="codeMessage" style="border: 1px inset ; overflow: auto; max-height: 200px;">' . nl2br(str_replace($spaces, $entities, htmlspecialchars(trim($matches[1][$i])))) . '</div></div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $codeBlocks[$i] = str_replace('<div class="code"><br />', '<div class="code">', $codeBlocks[$i]);
         $uniqidCode = '[code_' . uniqid('') . ']';
         $uniqidsCode[] = $uniqidCode;
         $message = str_replace($matches[0][$i], $uniqidCode, $message);
     }
     preg_match_all("#\\[sql\\](.+)\\[\\/sql\\]#isU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $sqlBlocks[] = '<div class="codeSQL">' . $this->highlight_sql(trim($matches[1][$i])) . '</div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $sqlBlocks[$i] = str_replace('<div class="codeSQL"><br />', '<div class="codeSQL">', $sqlBlocks[$i]);
         $uniqidSQL = '[sql_' . uniqid('') . ']';
         $uniqidsSQL[] = $uniqidSQL;
         $message = str_replace($matches[0][$i], $uniqidSQL, $message);
     }
     preg_match_all("#\\[js\\](.+)\\[\\/js\\]#isU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $jsBlocks[] = '<div class="codeJS">' . geshi_highlight(trim($matches[1][$i]), 'javascript', '', true) . '</div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $jsBlocks[$i] = str_replace('<div class="codeJS"><code><br />', '<div class="codeJS"><code>', $jsBlocks[$i]);
         $uniqidJS = '[js_' . uniqid('') . ']';
         $uniqidsJS[] = $uniqidJS;
         $message = str_replace($matches[0][$i], $uniqidJS, $message);
     }
     preg_match_all("#\\[css\\](.+)\\[\\/css\\]#isU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $cssBlocks[] = '<div class="codeCSS">' . geshi_highlight(trim($matches[1][$i]), 'css', '', true) . '</div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $cssBlocks[$i] = str_replace('<div class="codeCSS"><code><br />', '<div class="codeCSS"><code>', $cssBlocks[$i]);
         $uniqidCSS = '[css_' . uniqid('') . ']';
         $uniqidsCSS[] = $uniqidCSS;
         $message = str_replace($matches[0][$i], $uniqidCSS, $message);
     }
     preg_match_all("#\\[html\\](.+)\\[\\/html\\]#isU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $htmlBlocks[] = '<div class="codeHTML">' . geshi_highlight(trim($matches[1][$i]), 'html4strict', '', true) . '</div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $htmlBlocks[$i] = str_replace('<div class="codeHTML"><br />', '<div class="codeHTML">', $htmlBlocks[$i]);
         $uniqidHTML = '[html_' . uniqid('') . ']';
         $uniqidsHTML[] = $uniqidHTML;
         $message = str_replace($matches[0][$i], $uniqidHTML, $message);
     }
     preg_match_all("#\\[xml\\](.+)\\[\\/xml\\]#isU", $message, $matches);
     $cnt = count($matches[0]);
     for ($i = 0; $i < $cnt; $i++) {
         $xmlBlocks[] = '<div class="codeHTML">' . geshi_highlight(trim($matches[1][$i]), 'xml', '', true) . '</div>';
         // Вот над этим надо будет подумать - усовершенствовать рег. выражение
         $xmlBlocks[$i] = str_replace('<div class="codeHTML"><br />', '<div class="codeHTML">', $xmlBlocks[$i]);
         $uniqidXML = '[xml_' . uniqid('') . ']';
         $uniqidsXML[] = $uniqidXML;
         $message = str_replace($matches[0][$i], $uniqidXML, $message);
     }
     $ACL = $register['ACL'];
     if (!$ustatus || !$ACL->turn(array('bbcodes', 'html'), false, $ustatus) || !Config::read('allow_html')) {
         $message = htmlspecialchars($message, ENT_NOQUOTES);
     }
     $message = $this->parseIBb($message);
     $message = $this->parseBBb($message);
     $message = $this->parseSBb($message);
     $message = $this->parseUBb($message);
     $message = preg_replace("#\\[quote\\](.+)\\[\\/quote\\]#uisU", '<div class="bbQuoteBlock"><div class="bbQuoteName" style=""><b></b>Цитата</div><div class="quoteMessage" style="">\\1</div></div>', $message);
     $message = preg_replace("#\\[quote=\"([-_ 0-9a-zа-я]{1,30})\"\\](.+)\\[\\/quote\\]#isuU", '<div class="bbQuoteBlock"><div class="bbQuoteName" style=""><b>\\1 пишет:</b></div><div class="quoteMessage" style="">\\2</div></div>', $message);
     $message = $this->parseImgBb($message, $title);
     $message = preg_replace("#\\[color=red\\](.+)\\[\\/color\\]#uisU", '<span style="color:#FF0000">\\1</span>', $message);
     $message = preg_replace("#\\[color=green\\](.+)\\[\\/color\\]#uisU", '<span style="color:#008000">\\1</span>', $message);
     $message = preg_replace("#\\[color=blue\\](.+)\\[\\/color\\]#uisU", '<span style="color:#0000FF">\\1</span>', $message);
     $message = preg_replace("#\\[color=\\#?([0-9a-z]{3,6})\\](.+)\\[\\/color\\]#uisU", '<span style="color:#\\1">\\2</span>', $message);
     $message = preg_replace_callback("#\\[list\\]\\s*((?:\\[\\*\\].+)+)\\[\\/list\\]#usiU", 'getUnorderedList', $message);
     $message = preg_replace_callback("#\\[list=([a|1])\\]\\s*((?:\\[\\*\\].+)+)\\[\\/list\\]#usiU", 'getOrderedList', $message);
     $message = $this->parseUrlBb($message);
     $message = preg_replace("#\\[size=(\\d+)\\]([^\\[]*)\\[/size\\]#uisU", '<span style="font-size:\\1%;">\\2</span>', $message);
     $message = preg_replace("#\\[h([123456]{1})\\]([^\\[]*)\\[/h[123456]{1}\\][\n\r]*?#uisU", '<h\\1>\\2</h\\1>', $message);
     $message = preg_replace("#\\[center\\]([^\\[]*)\\[/center\\]#uisU", '<span style="display:block;width:100%;text-align:center;">\\1</span>', $message);
     $message = preg_replace("#\\[right\\]([^\\[]*)\\[/right\\]#uisU", '<span style="display:block;width:100%;text-align:right;">\\1</span>', $message);
     $message = preg_replace("#\\[left\\]([^\\[]*)\\[/left\\]#uisU", '<span style="display:block;width:100%;text-align:left;">\\1</span>', $message);
     $message = preg_replace("#\\[spoiler\\](.+)\\[/spoiler\\]#suU", '<div onClick="if ($(this).next().css(\'display\') == \'none\') { $(this).next().toggle(1000); } else { $(this).next().toggle(1000); }" class="spoiler-open">' . __('Bb-spoiler open') . '</div><div class="spoiler-win">\\1</div>', $message);
     if (preg_match_all("#\\[video\\](http://(www\\.)*youtube\\.com/watch\\?v=([\\w-]+))\\[/video\\]#isU", $message, $match)) {
         if (!empty($match[1])) {
             foreach ($match[1] as $key => $url) {
                 $message = str_replace('[video]' . $url . '[/video]', '<object height="300" width="450" data="http://youtube.com/v/' . $match[3][$key] . '" type="application/x-shockwave-flash" class="restrain" id="yui-gen54">' . '<param value="http://youtube.com/v/' . $match[3][$key] . '" name="movie"><param value="transparent" name="wmode">' . '<!--[if IE 6]><embed width="400" height="300" type="application/x-shockwave-flash" src="http://youtube.com/v/' . $match[3][$key] . '" />' . '<![endif]--></object>', $message);
             }
         }
     }
     if (preg_match_all("#\\[video\\](http://(www\\.)*rutube\\.ru/tracks/[\\d]+\\.html\\?v=([\\w]+))\\[/video\\]#isU", $message, $match)) {
         if (!empty($match[1])) {
             foreach ($match[1] as $key => $url) {
                 $message = str_replace('[video]' . $url . '[/video]', '<object height="300" width="450" data="http://video.rutube.ru/' . $match[3][$key] . '" type="application/x-shockwave-flash" class="restrain" id="yui-gen54">' . '<param value="http://video.rutube.ru/' . $match[3][$key] . '" name="movie"><param value="transparent" name="wmode">' . '<!--[if IE 6]><embed width="400" height="300" type="application/x-shockwave-flash" src="http://video.rutube.ru/' . $match[3][$key] . '" />' . '<![endif]--></object>', $message);
             }
         }
     }
     if (!empty($_SESSION['user']['id'])) {
         $message = preg_replace("#\\[hide\\](.*)\\[/hide\\]#isU", '\\1', $message);
     } else {
         $message = preg_replace("#\\[hide\\](.*)\\[/hide\\]#isU", '<div class="hide">Необходима авторизация. <a href="' . WWW_ROOT . '/users/add_form/">Регистрация</a></div>', $message);
     }
     $message = nl2br($message);
     //work for smile
     if (Config::read('allow_smiles')) {
         $message = $this->smile($message);
     }
     //return block
     if (isset($uniqidCode)) {
         $message = str_replace($uniqidsCode, $codeBlocks, $message);
     }
     if (isset($uniqidPHP)) {
         $message = str_replace($uniqidsPHP, $phpBlocks, $message);
     }
     if (isset($uniqidSQL)) {
         $message = str_replace($uniqidsSQL, $sqlBlocks, $message);
     }
     if (isset($uniqidJS)) {
         $message = str_replace($uniqidsJS, $jsBlocks, $message);
     }
     if (isset($uniqidCSS)) {
         $message = str_replace($uniqidsCSS, $cssBlocks, $message);
     }
     if (isset($uniqidHTML)) {
         $message = str_replace($uniqidsHTML, $htmlBlocks, $message);
     }
     if (isset($uniqidXML)) {
         $message = str_replace($uniqidsXML, $xmlBlocks, $message);
     }
     // Над этим тоже надо будет подумать
     $message = str_replace('</div><br />', '</div>', $message);
     $message = $this->insertImageAttach($message, $entity, $module);
     return $message;
 }
    }
}
echo $pre;
?>
				</div>
				<div id="cv_real_code">
					<div id="cv_toolbar">
						<ul>
							<li class="cv_hidefiles"><div class="cv_icon sprite-application_side_contract"></div></li>	
							<li class="cv_appwindow"><div class="cv_icon sprite-application_double"></div></li>
							<li class="cv_raw"><div class="cv_icon sprite-page_code"></div></li>
						</ul>
					</div>
					<?php 
include_once 'lib/geshi.php';
geshi_highlight(file_get_contents("vpk_class.php"), 'php');
?>
		
				</div>
			</div>
		</div>
	</body>
</html>
<!--http://pastebin.com/7sP9RQjP-->






Example #4
0
function replace_ubbcode($str, $stdlang = false, $rootpath)
{
    // code
    $code_ids = array();
    while ($ereg = preg_match("/\\[code(=(.+?))*\\](.+?)\\[\\/code\\]/s", $str, $reg)) {
        $code_id = 0;
        do {
            $code_id = mt_rand(100, 10000);
        } while (array_key_exists($code_id, $code_ids));
        $lang = $reg[2];
        $str2 = $reg[3];
        if ($lang === null || $lang == "") {
            if ($stdlang) {
                $lang = $stdlang;
            } else {
                $lang = 'c';
            }
        }
        $humanreadable_lang = lang_name($lang);
        if ($humanreadable_lang == " (unknown language)") {
            $humanreadable_lang = $lang . $humanreadable_lang;
        }
        $str2 = stripslashes($str2);
        $str2 = geshi_highlight($str2, $lang, null, true);
        $str2 = eregi_replace("\\\\([ntr])", '\\\\\\\\1', $str2);
        $str2 = eregi_replace("<br />", "", $str2);
        $str2 = preg_replace("/\n<\\/span><\\/code>\$/", '</span></code>', $str2);
        $code_ids[$code_id] = "</p>\n<pre class=\"code\">\n{$str2}\n</pre>\n<p>";
        $str = preg_replace("/\\[code(=({$lang}))*\\](.+?)\\[\\/code\\]/s", "[code_id={$code_id}/]", $str, 1);
    }
    $str = htmlspecialchars($str);
    $str = nl2br($str);
    $str = eregi_replace("\\\\\\\\", "\\", $str);
    $str = eregi_replace("\\\\&quot;", "&quot;", $str);
    # $str = "<p>".$str."</p>";
    # $str = eregi_replace("\n.\n", "</p><p>", $str);
    # $str = eregi_replace("\n", "<br />\n", $str);
    # $str = eregi_replace("</p><p>", "</p>\n<p>", $str);
    $str = eregi_replace("=== ([^=]+) ===(<br />)?", "</p>\n<h4>\\1</h4>\n<p>", $str);
    $str = eregi_replace("== ([^=]+) ==(<br />)?", "</p>\n<h3>\\1</h3>\n<p>", $str);
    # $str = eregi_replace("_{([^}]+)}", "<sub>\\1</sub>", $str);
    # $str = eregi_replace("\^{([^}]+)}", "<sup>\\1</sup>", $str);
    // formatting
    $str = eregi_replace("\\[b]([^\\[]*)\\[/b\\]", "<strong>\\1</strong>", $str);
    // bold|strong
    $str = eregi_replace("\\[i]([^\\[]*)\\[/i\\]", "<i>\\1</i>", $str);
    // kursiv
    $str = eregi_replace("\\[u]([^\\[]*)\\[/u\\]", "<u>\\1</u>", $str);
    // underline
    $str = preg_replace('/\\[bq]([^\\[]*)\\[\\/bq\\]/i', "</p><blockquote><p>\\1</p></blockquote><p>", $str);
    $str = eregi_replace("\\[s]([^\\[]*)\\[/s\\]", "<s>\\1</s>", $str);
    // strike
    $str = eregi_replace("\\[color=([^\\[]*)\\]([^\\[]*)\\[/color\\]", "<span style=\"color:\\1;\">\\2</span>", $str);
    // color
    // flash
    $str = eregi_replace("\\[flash]([^\\[]*)\\[/flash\\]", "<object data=\"\\1\" type=\"application/x-shockwave-flash\" style=\"width: 425px; height: 355px\">\n <param name=\"movie\" value=\"\\1\" />\n <param name=\"wmode\" value=\"transparent\" />\n</object>", $str);
    // pic
    $str = eregi_replace("\\[img(=([^\\[]*))*\\]([^\\[]*)\\[/img\\]", "<a href=\"\\3\" rel=\"facebox\"><img src=\"\\3\" alt=\"\\3\" /></a>", $str);
    // bild
    $str = eregi_replace("\\[img(=([^\\[]*))*\\]([^\\[]*)\\[/img,([0-9]+),([0-9]+)\\]", "<a href=\"\\3\" rel=\"facebox\"><img src=\"\\3\" style=\"width:\\4px;height:\\5px\" alt=\"\\3\" /></a>", $str);
    // bild mit größe
    // links
    $str = preg_replace("/\\[\\[(.+?)\\|(.+?)\\]\\]/", "<a href=\"\\1\">\\2</a>", $str);
    // link with title
    $str = preg_replace("/\\[\\[(.+)\\]\\]/", "<a href=\"\\1\">\\1</a>", $str);
    // link without title
    // $str = eregi_replace("\[\[(.+?)\|(.+?)\]\]", "<a href=\"\\1\">\\2</a>", $str); // link with title
    // $str = eregi_replace("\[\[(.+)\]\]", "<a href=\"\\1\">\\1</a>", $str); // link without title
    $str = eregi_replace("\\[center]([^\\[]*)\\[/center\\]", "</p>\n<p style=\"text-align:center\">\\1</p>\n<p>", $str);
    $str = eregi_replace("\\[left]([^\\[]*)\\[/left\\]", "</p>\n<p style=\"text-align:left\">\\1</p>\n<p>", $str);
    $str = eregi_replace("\\[right]([^\\[]*)\\[/right\\]", "</p>\n<p style=\"text-align:right\">\\1</p>\n<p>", $str);
    $str = replace_smilies($str, $rootpath);
    $preg = array('/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[\\*(?::\\w+)?\\](.*?)(?=(?:\\s*<br\\s*\\/?>\\s*)?\\[\\*|(?:\\s*<br\\s*\\/?>\\s*)?\\[\\/?list)/si' => "\n<li class=\"bb-listitem\">\\1</li>", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[\\/list(:(?!u|o)\\w+)?\\](?:<br\\s*\\/?>)?/si' => "\n</ul>", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[\\/list:u(:\\w+)?\\](?:<br\\s*\\/?>)?/si' => "\n</ul>", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[\\/list:o(:\\w+)?\\](?:<br\\s*\\/?>)?/si' => "\n</ol>", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list(:(?!u|o)\\w+)?\\]\\s*(?:<br\\s*\\/?>)?/si' => "\n<ul class=\"bb-list-unordered\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list:u(:\\w+)?\\]\\s*(?:<br\\s*\\/?>)?/si' => "\n<ul class=\"bb-list-unordered\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list:o(:\\w+)?\\]\\s*(?:<br\\s*\\/?>)?/si' => "\n<ol class=\"bb-list-ordered\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list(?::o)?(:\\w+)?=1\\]\\s*(?:<br\\s*\\/?>)?/si' => "\n<ol class=\"bb-list-ordered bb-list-ordered-d\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list(?::o)?(:\\w+)?=i\\]\\s*(?:<br\\s*\\/?>)?/s' => "\n<ol class=\"bb-list-ordered bb-list-ordered-lr\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list(?::o)?(:\\w+)?=I\\]\\s*(?:<br\\s*\\/?>)?/s' => "\n<ol class=\"bb-list-ordered bb-list-ordered-ur\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list(?::o)?(:\\w+)?=a\\]\\s*(?:<br\\s*\\/?>)?/s' => "\n<ol class=\"bb-list-ordered bb-list-ordered-la\">", '/(?<!\\\\)(?:\\s*<br\\s*\\/?>\\s*)?\\[list(?::o)?(:\\w+)?=A\\]\\s*(?:<br\\s*\\/?>)?/s' => "\n<ol class=\"bb-list-ordered bb-list-ordered-ua\">", '/(?<!\\\\)\\[url(?::\\w+)?\\]www\\.(.*?)\\[\\/url(?::\\w+)?\\]/si' => "<a href=\"http://www.\\1\">www.\\1</a>", '/(?<!\\\\)\\[url(?::\\w+)?\\](.*?)\\[\\/url(?::\\w+)?\\]/si' => "<a href=\"\\1\">\\1</a>", '/(?<!\\\\)\\[url(?::\\w+)?=(.*?)?\\](.*?)\\[\\/url(?::\\w+)?\\]/si' => "<a href=\"\\1\">\\2</a>");
    $str = preg_replace(array_keys($preg), array_values($preg), $str);
    // code
    /*$i=0;
     while(($ereg= preg_match("/\[code(=(.+?))*\](.+?)\[\/code\]/s", $str,$reg)) && $i < 10)
     {
      $i++;
      $lang = $reg[2];
      $str2 = $reg[3];
      if($lang === null || $lang == "")
      {
        if($stdlang) $lang = $stdlang;
        else $lang = 'c';
      }
    
      $humanreadable_lang = lang_name($lang);
      if($humanreadable_lang == " (unknown language)")
        $humanreadable_lang = $lang.$humanreadable_lang;
    
      $str2 = eregi_replace("&quot;", "\"", $str2);
      $str2 = eregi_replace("&gt;", ">", $str2);
      $str2 = eregi_replace("&lt;", "<", $str2);
      $str2 = eregi_replace("<br />", "", $str2);
    
      $str2 = geshi_highlight($str2, $lang, null, true);
      $str2 = eregi_replace("\\\\n", '\\\\\\n', $str2);
      $str2 = eregi_replace("<br />", "", $str2);
      $str2 = preg_replace("/\n<\/span><\/code>$/", '</span></code>', $str2);
    
      $str = preg_replace("/\[code(=({$lang}))*\](.+?)\[\/code\]/s", "</p>\n<pre class=\"code\">\n{$str2}\n</pre>\n<p>", $str, 1);
     }*/
    #var_dump($code_ids);
    foreach ($code_ids as $c_id => $code_str) {
        $out = 0;
        $str = preg_replace("/\\[code_id={$c_id}\\/\\]/", $code_str, $str, 1, $out);
    }
    return $str;
}
 /**
  * Preview the new mod
  *
  * @todo convention ajaxaction_
  */
 public function action_admin_preview()
 {
     $view = $this->getView();
     // get parameter for module data
     $mod = $this->request->getParameter('m');
     var_dump($mod);
     // serialize the module data
     $mod['data'] = base64_encode(serialize($mod));
     // assign the whole pack to smarty
     $view->assign('mod', $mod);
     #$smarty->autoload_filters = array();
     #$smarty->unregister_prefilter('smarty_prefilter_inserttplnames');
     #error_reporting(0);
     /**
      * Include & Instantiate GeSHi
      * for the formatting of the sourcecode with geshi_highlight()
      */
     if (class_exists('GeSHi', false) == false) {
         include ROOT_LIBRARIES . 'geshi/geshi.php';
     }
     /**
      * Frontend = class Modulename
      */
     if (isset($mod['frontend']['checked']) && $mod['frontend']['checked'] == 1) {
         /**
          * Frontend Header
          */
         $frontend = $smarty->fetch(ROOT_MOD . 'scaffolding/module_frontend.tpl');
         $view->assign('frontend', geshi_highlight($frontend, 'php-brief', '', true));
         /**
          * Frontend Method
          */
         $frontend_methods = $smarty->fetch(ROOT_MOD . 'scaffolding/module_frontend_method.tpl');
         $view->assign('frontend_methods', $frontend_methods);
         /**
          * Widget Method (Module integrated)
          */
         if (isset($mod['widget']['checked']) && $mod['widget']['checked'] == 1) {
             $widget_methods = $smarty->fetch(ROOT_MOD . 'scaffolding/module_widget_method.tpl');
             $view->assign('widget_methods', $widget_methods);
         }
     }
     /**
      * BACKEND - Module_Modulename_Admin
      */
     if (isset($mod['backend']['checked']) && $mod['backend']['checked'] == 1) {
         /**
          * Admin Module Header
          */
         $backend = $smarty->fetch(ROOT_MOD . 'scaffolding/module_backend.tpl');
         $view->assign('backend', geshi_highlight($backend, 'php-brief', '', true));
         /**
          * Admin Module Method
          */
         $backend_methods = $smarty->fetch(ROOT_MOD . 'scaffolding/module_backend_method.tpl');
         $view->assign('backend_methods', $backend_methods);
     }
     /**
      * CONFIG - Module Configuration File
      */
     if (isset($mod['config']['checked']) && $mod['config']['checked'] == 1) {
         $config = $smarty->fetch(ROOT_MOD . 'scaffolding/module_config.tpl');
         $view->assign('config', geshi_highlight($config, 'php-brief', '', true));
     }
     #error_reporting( E_ALL || E_STRICT );
     #$smarty->register_prefilter('smarty_prefilter_inserttplnames');
     /**
      * Folder's writeable?
      */
     if (!is_writeable(ROOT_MOD)) {
         $err['mod_folder_not_writeable'] = 1;
     }
     $this->getView()->setRenderMode('NOT_WRAPPED');
     $this->display();
 }
Example #6
0
        ?>
 //
                            <a href="/user/<?php 
        echo $paste->user_id;
        ?>
"><?php 
        echo $paste->User->firstname;
        ?>
 <?php 
        echo $paste->User->lastname;
        ?>
</a>
                        </small>
                    </p>
                    <?php 
        geshi_highlight($paste->code, $paste->codestyle->short);
        ?>
                    <hr>
                </div>
            </div>
        <?php 
    }
    ?>

        <!-- PAGINATION -->
        <div class="row">
            <div class="col-sm-12 text-right">
                <?php 
    echo $pagination;
    ?>
            </div>
Example #7
0
 function _geshi_highlight($text = '', $prog_lang = 'html4strict')
 {
     require_once dirname(INCLUDE_PATH) . '/yf/__SANDBOX/geshi/geshi.php';
     $text = geshi_highlight($text, $prog_lang, '', 1);
     return $text;
 }
Example #8
0
function highlighter($text, $geshi_lang)
{
    include_once 'geshi/geshi.php';
    $geshi_path = 'geshi/geshi';
    $geshi = new geshi();
    $langs = array('actionscript', 'ada', 'apache', 'asm', 'asp', 'bash', 'c', 'c_mac', 'caddcl', 'cadlisp', 'cpp', 'csharp', 'css', 'd', 'delphi', 'diff', 'html4strict', 'java', 'javascript', 'lisp', 'lua', 'matlab', 'mpasm', 'nsis', 'objc', 'oobas', 'oracle8', 'pascal', 'perl', 'php', 'php-brief', 'python', 'qbasic', 'smarty', 'sql', 'vb', 'vbnet', 'vhdl', 'visualfoxpro', 'xml');
    $geshi_lang = in_array($geshi_lang, $langs) ? $geshi_lang : 'php';
    $source_lines = explode("\n", $text);
    foreach ($source_lines as $line) {
        $line = stripslashes($line);
        $line = str_replace(array('&lt;', '&gt;', '&amp;', '<br />'), array('<', '>', '&', "\n"), trim($line));
        $line = geshi_highlight($line, $geshi_lang, $geshi_path, TRUE);
        $text = $line;
    }
    return $text;
}
Example #9
0
    echo $details['time'] >= 1 ? round($details['time'], 2) . 's' : round($details['time'] * 1000, 1) . 'ms';
    ?>
</span>
            <span class="partial"><?php 
    echo $classname . $type . $function;
    ?>
()</span>
            <span class="partial hidden"> in <?php 
    echo join(DS, $file_details) . DS . '<b>' . $filename . '</b>';
    ?>
:<?php 
    echo $details['line'];
    ?>
</span>
            <div class="sql"><?php 
    geshi_highlight($details['sql'], 'sql');
    ?>
</div>
        </li>
    <?php 
}
?>
    </ol>
</li>
<li id="log_objectpopulation">
    <h1>ORM object population</h1>
    <?php 
if (!\b2db\Core::isDebugMode()) {
    ?>
        <div>Database debugging disabled</div>
    <?php 
Example #10
0
function jdReadFile($id)
{
    jimport('geshi.geshi');
    $id = (int) $id;
    $objResponse = new xajaxResponse();
    $row =& JTable::getInstance('Log', 'Table');
    if (!$row->load($id)) {
        $objResponse->alert(JText::_('Cannot find log entry'));
        return $objResponse;
    }
    if (!is_file($row->url)) {
        $objResponse->alert(JText::_('Cannot find file'));
        return $objResponse;
    }
    $lang = false;
    $ext = strtolower(JFile::getExt($row->url));
    switch ($ext) {
        case 'php':
        case 'css':
        case 'ini':
        case 'sql':
        case 'xml':
            $lang = $ext;
        case 'js':
            $lang = 'javascript';
    }
    $contents = JFile::read($row->url);
    $contents = geshi_highlight($contents, $lang, null, true);
    $objResponse->assign('file_contents', 'innerHTML', $contents);
    return $objResponse;
}