<?php
|
/*---------------------------------------------------------------*/
|
/*
|
Titre : Colorer n'importe quel langage avec Geshi
|
|
URL : https://phpsources.net/code_s.php?id=418
|
Auteur : zaknaou
|
Date édition : 21 Juin 2008
|
Date mise à jour : 28 Aout 2019
|
Rapport de la maj:
|
- fonctionnement du code vérifié
|
*/
|
/*---------------------------------------------------------------*/?>
|
Comment fonctionne Geshi :
|
|
<?php // Simple GeSHi demo
|
|
// Include the GeSHi library
|
include('geshi.php');
|
|
// Make a new GeSHi object, with the source, language and path set
|
$source = 'echo "hello, world!";
|
// weeeeee!!!!';
|
$language = 'php';
|
$path = 'geshi/';
|
|
$geshi = new GeSHi($source, $language, $path);
|
|
// and simply dump the code!
|
echo $geshi->parse_code(); ?>
|
|
|
<?php
|
|
include_once('geshi/geshi.php');
|
|
$source = $_POST['source'];
|
|
$offset = 0;
|
$exploded = array();
|
$continue = TRUE;
|
while ($continue)
|
{
|
$Nb = preg_match('@[code=([^]]*)]@', $source, $result, PREG_OFFSET_CAPTURE,
|
$offset);
|
$continue = ($Nb == 1);
|
if ($continue)
|
{
|
$langage = $result[1][0];
|
$avancee = $result[0][1] - $offset;
|
if ($avancee > 0)
|
{
|
$exploded[] = array('text', substr($source, $offset, $avancee));
|
}
|
$offset = $result[1][1] + strlen($result[1][0]) + 1;
|
$Nb = preg_match('@[/code]@', $source, $result, PREG_OFFSET_CAPTURE,
|
$offset);
|
|
//-->> CONTENU DES BALISES //-->> COLORATION DU code VIA GESHI
|
if ($Nb == 1)
|
{
|
$exploded[] = array($langage, substr($source, $offset, $result[0][1]
|
- $offset));
|
$offset = $result[0][1] + strlen('[/code]');
|
}
|
}
|
else
|
{
|
$reste = strlen($source) - $offset;
|
if ($reste > 0)
|
{
|
$exploded[] = array('text', substr($source, $offset, $reste));
|
}
|
}
|
}
|
|
foreach($exploded as $data)
|
{
|
|
//-->> MET EN MINUSCULE LE TYPE DE BALISE (HTML, PHP, CSS -->> html, php, css)
|
$data[0] = strtolower($data[0]);
|
|
//-->> CONDITION DU LANGAGE
|
if($data[0] == "actionscript") {$type_code = "actionscript";}
|
elseif($data[0] == "actionscript-fr") {$type_code =
|
"actionscript-french";}
|
elseif($data[0] == "ada") {$type_code = "ada";}
|
elseif($data[0] == "applescript") {$type_code = "applescript";}
|
elseif($data[0] == "asm") {$type_code = "asm";}
|
elseif($data[0] == "asp") {$type_code = "asp";}
|
elseif($data[0] == "autoit") {$type_code = "autoit";}
|
elseif($data[0] == "bash") {$type_code = "bash";}
|
elseif($data[0] == "blitzbasic") {$type_code = "blitzbasic";}
|
elseif($data[0] == "c") {$type_code = "c";}
|
elseif($data[0] == "c-mac") {$type_code = "c_mac";}
|
elseif($data[0] == "c#") {$type_code = "csharp";}
|
elseif($data[0] == "c++") {$type_code = "cpp";}
|
elseif($data[0] == "cad-dcl") {$type_code = "caddcl";}
|
elseif($data[0] == "cadlisp") {$type_code = "cadlisp";}
|
elseif($data[0] == "cfdg") {$type_code = "cfdg";}
|
elseif($data[0] == "coldfusion") {$type_code = "cfm";}
|
elseif($data[0] == "css") {$type_code = "css";}
|
elseif($data[0] == "delphi") {$type_code = "delphi";}
|
elseif($data[0] == "dev") {$type_code = "dev";}
|
elseif($data[0] == "dos") {$type_code = "dos";}
|
elseif($data[0] == "eiffel") {$type_code = "eiffel";}
|
elseif($data[0] == "fortran") {$type_code = "fortran";}
|
elseif($data[0] == "freebasic") {$type_code = "freebasic";}
|
elseif($data[0] == "gml") {$type_code = "gml";}
|
elseif($data[0] == "html") {$type_code = "html4strict";}
|
elseif($data[0] == "inno") {$type_code = "inno";}
|
elseif($data[0] == "java") {$type_code = "java";}
|
elseif($data[0] == "java-5") {$type_code = "java5";}
|
elseif($data[0] == "javascript") {$type_code = "javascript";}
|
elseif($data[0] == "lisp") {$type_code = "lisp";}
|
elseif($data[0] == "lua") {$type_code = "lua";}
|
elseif($data[0] == "microprocessor-asm") {$type_code = "mpasm";}
|
elseif($data[0] == "mysql") {$type_code = "mysql";}
|
elseif($data[0] == "nsis") {$type_code = "nsis";}
|
elseif($data[0] == "objective-c") {$type_code = "objc";}
|
elseif($data[0] == "ocaml") {$type_code = "ocaml";}
|
elseif($data[0] == "openoffice-basic") {$type_code = "oobas";}
|
elseif($data[0] == "oracle-8-sql") {$type_code = "oracle8";}
|
elseif($data[0] == "pascal") {$type_code = "pascal";}
|
elseif($data[0] == "perl") {$type_code = "perl";}
|
elseif($data[0] == "php") {$type_code = "php";}
|
elseif($data[0] == "python") {$type_code = "python";}
|
elseif($data[0] == "quick-basic") {$type_code = "qbasic";}
|
elseif($data[0] == "robots-txt") {$type_code = "robots";}
|
elseif($data[0] == "ruby") {$type_code = "ruby";}
|
elseif($data[0] == "sas") {$type_code = "sas";}
|
elseif($data[0] == "scheme") {$type_code = "scheme";}
|
elseif($data[0] == "sdlbasic") {$type_code = "sdlbasic";}
|
elseif($data[0] == "smarty") {$type_code = "smarty";}
|
elseif($data[0] == "sql") {$type_code = "sql";}
|
elseif($data[0] == "t-sql") {$type_code = "tsql";}
|
elseif($data[0] == "vbnet") {$type_code = "vbnet";}
|
elseif($data[0] == "vb") {$type_code = "vb";}
|
elseif($data[0] == "visual-fox-pro") {$type_code = "visualfoxpro";}
|
elseif($data[0] == "xml") {$type_code = "xml";}
|
elseif($data[0] == "dhtml") {$type_code = "html4strict";}
|
elseif($data[0] == "xhtml") {$type_code = "html4strict";}
|
elseif($data[0] == "autre") {$type_code = "autre";}
|
else {$type_code = "aucun";}
|
|
if($type_code != "autre" AND $type_code != "aucun")
|
{
|
//-->> SUPPRIME LES ESPACES DEVANT ET DERIERRE
|
$data[1] = trim($data[1]);
|
|
//-->> SUPPRIME LES SLASHES
|
$data[1] = stripslashes($data[1]);
|
|
//-->> GESHI
|
$geshi_1 =& new GeSHi($data[1], $type_code);
|
$geshi_1->set_keyword_group_style(1,
|
'color: #006600; background-color:#EAF4FE');
|
$geshi_1->set_keyword_group_style(2,
|
'color: #CC0000; background-color:#EAF4FE');
|
$geshi_1->set_keyword_group_style(3,
|
'color: #003399; background-color:#EAF4FE');
|
$geshi_1->set_keyword_group_style(4,
|
'color: #336699; background-color:#EAF4FE');
|
$geshi_1->set_comments_style('1',
|
'color:FF9D00; font-variant:small-caps;');
|
$geshi_1->set_symbols_style('font-weight:bold; size:24px;');
|
$geshi_1->set_strings_style('color:#CC0000;');
|
$geshi_1->set_numbers_style('font-size:16px;');
|
$geshi_1->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS, 1);
|
$geshi_1->set_line_style('color: #CC0000;');
|
$geshi_1->set_header_type(GESHI_HEADER_PRE);
|
$data[1] = $geshi_1->parse_code();
|
}
|
|
if($data[0] != "text" AND $data[1] != "" AND $type_code != "aucun" AND
|
$type_code != "autre")
|
{
|
echo'
|
<table border="1" cellpadding="0" style="border-collapse: collapse"' .
|
' width="100%" bgcolor="#EAF4FF" bordercolor="#99CCFF">
|
<tr>
|
<td bordercolor="#D5EAFF" height="12">
|
<font face="Verdana" size="2" color="#3366CC">Langage : '.$data[0].
|
'</font></td>
|
</tr>
|
<tr>
|
<td bordercolor="#D5EAFF" height="11"><p> </p><p><pre>'.$data[1].
|
'</pre></p>
|
<p> </td>
|
</tr>
|
</table>
|
';
|
}
|
elseif($data[0] == "text" AND $data[1] != "")
|
{
|
echo''.$data[1].'';
|
}
|
else
|
{
|
}
|
}
|
?>
|
|
|
KOogar
21 Juin 2008 à 03:24URL de la classe à télécharger:
ici