j'ai récupérer une modification permettant d'intégrer la coloration syntaxique dans le bbcode code du forum sur http://www.phpbb.de/community/viewtopic ... 8&t=169688
L'intégration est très facile mais provoquait un soucis de notice debug de phpbb3. J'ai donc fait une procédure de vérification supplémentaire et je pense que c'est devenu assez stable.
Version de phpbb3: 3.0.4
Voici comment procéder:
Télécharger geshi sur http://qbnz.com/highlighter/
{PHPBB_ROOT} sera le chemin ou est installé votre forum.
Créer un dossier nommé geshi dans {PHPBB_ROOT}/include
Mettre le contenu de l'archive de geshi dans {PHPBB_ROOT}/include/geshi
Faire une sauvegarde des fichiers suivant:
- {PHPBB_ROOT}/include/bbcode.php
- {PHPBB_ROOT}/include/message_parser.php
Recherchez :
- Code: Tout sélectionner
/**
* Second parse code tag
*/
function bbcode_second_pass_code($type, $code)
{
// when using the /e modifier, preg_replace slashes double-quotes but does not
// seem to slash anything else
$code = str_replace('\"', '"', $code);
switch ($type)
{
case 'php':
// Not the english way, but valid because of hardcoded syntax highlighting
if (strpos($code, '<span class="syntaxdefault"><br /></span>') === 0)
{
$code = substr($code, 41);
}
// no break;
default:
$code = str_replace("\t", ' ', $code);
$code = str_replace(' ', ' ', $code);
$code = str_replace(' ', ' ', $code);
// remove newline at the beginning
if (!empty($code) && $code[0] == "\n")
{
$code = substr($code, 1);
}
break;
}
$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
return $code;
}
}
Et remplacez par :
- Code: Tout sélectionner
/**
* Second parse code tag
*/
function bbcode_second_pass_code($type, $code)
{
// when using the /e modifier, preg_replace slashes double-quotes but does not
// seem to slash anything else
$code = str_replace('\"', '"', $code);
// ------------------------------------------------------------------------------------
// edited by jb (nebler.org)
// including geshi
// geshipfad, relativ zum haupt-ordner (oder absolut (untested))
$geshi_path = $phpbb_root_path . 'includes/geshi/geshi.php';
if (empty($type))
{
$code = str_replace("\t", ' ', $code);
$code = str_replace(' ', ' ', $code);
$code = str_replace(' ', ' ', $code);
// remove newline at the beginning
if (!empty($code) && $code[0] == "\n")
{
$code = substr($code, 1);
}
}
else if(!include_once( $geshi_path ) ) { // include = zur laufzeit, requier zum start
echo 'geshi n\'a pas pu être!';
} else
{
// Es kommt nicht ursprünglicher Code an ...
// hier die rückformatierung, vllt nicht schön aber selten ;)
// Not the english way ... steht irgendwo im quellcode :)
$astr_to = array('<', '>', '[', ']', '.', ':','"');
$astr_from = array('<', '>', '[', ']', '.', ':','"');
$code = str_replace($astr_from, $astr_to, $code);
// binde geshi ein, siehe geshi-faq
// geshi Objekt erzeugen und code erzeuegn
$geshi = new GeSHi( $code, $type );
// header type setzten, siehe documentation von geshi
$geshi->set_header_type(GESHI_HEADER_NONE);
// code parsen und highlighten
$code = $geshi->parse_code();
// überflüssige <br /> entfernen
$code = str_replace( '<br />', '', $code );
}
// ------------------------------------------------------------------------------------
$code = $this->bbcode_tpl('code_open') . $code . $this->bbcode_tpl('code_close');
return $code;
}
}
Édition du fichier {PHPBB_ROOT}/include/message_parger.php
Recherchez:
- Code: Tout sélectionner
/**
* Parse code text from code tag
* @access private
*/
function bbcode_parse_code($stx, &$code)
{
switch (strtolower($stx))
{
case 'php':
$remove_tags = false;
$str_from = array('<', '>', '[', ']', '.', ':', ':');
$str_to = array('<', '>', '[', ']', '.', ':', ':');
$code = str_replace($str_from, $str_to, $code);
if (!preg_match('/\<\?.*?\?\>/is', $code))
{
$remove_tags = true;
$code = "<?php $code ?>";
}
$conf = array('highlight.bg', 'highlight.comment', 'highlight.default', 'highlight.html', 'highlight.keyword', 'highlight.string');
foreach ($conf as $ini_var)
{
@ini_set($ini_var, str_replace('highlight.', 'syntax', $ini_var));
}
// Because highlight_string is specialcharing the text (but we already did this before), we have to reverse this in order to get correct results
$code = htmlspecialchars_decode($code);
$code = highlight_string($code, true);
$str_from = array('<span style="color: ', '<font color="syntax', '</font>', '<code>', '</code>','[', ']', '.', ':');
$str_to = array('<span class="', '<span class="syntax', '</span>', '', '', '[', ']', '.', ':');
if ($remove_tags)
{
$str_from[] = '<span class="syntaxdefault"><?php </span>';
$str_to[] = '';
$str_from[] = '<span class="syntaxdefault"><?php ';
$str_to[] = '<span class="syntaxdefault">';
}
$code = str_replace($str_from, $str_to, $code);
$code = preg_replace('#^(<span class="[a-z_]+">)\n?(.*?)\n?(</span>)$#is', '$1$2$3', $code);
if ($remove_tags)
{
$code = preg_replace('#(<span class="[a-z]+">)?\?>(</span>)#', '$1 $2', $code);
}
$code = preg_replace('#^<span class="[a-z]+"><span class="([a-z]+)">(.*)</span></span>#s', '<span class="$1">$2</span>', $code);
$code = preg_replace('#(?:\s++| )*+</span>$#u', '</span>', $code);
// remove newline at the end
if (!empty($code) && substr($code, -1) == "\n")
{
$code = substr($code, 0, -1);
}
return "[code=$stx:" . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
break;
default:
return '[code:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($code) . '[/code:' . $this->bbcode_uid . ']';
break;
}
}
Et remplacez par:
- Code: Tout sélectionner
/**
* Parse code text from code tag
* @access private
*/
function bbcode_parse_code($stx, &$code)
{
// ------------------------------------------------------------------------------------
// edited by jb (nebler.org)
// includes geshi mod
if( strlen( $stx ) > 0 ) {
return "[code=$stx:" . $this->bbcode_uid . ']' . $code . '[/code:' . $this->bbcode_uid . ']';
} else {
return '[code:' . $this->bbcode_uid . ']' . $this->bbcode_specialchars($code) . '[/code:' . $this->bbcode_uid . ']';
}
// ------------------------------------------------------------------------------------
}
Voila.
Pour utilise la coloration il suffit de mettre =langage dans la balise ouvrante de [code]
Exemple: [code=java]
- Titre édité par Morgyanne -
Titre d'origine : Intégrer Geshi à phpbb3







