geshi et quotes

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : geshi et quotes

Re: [RESOLU] geshi et quotes

par graffx » 28 déc. 2009, 01:17

Merci mon ami, c' est sur que ce forum est fait pour l' entraide, mais c' est le seul qui a pas attrappé la grosse tête :mrgreen:

A charge de revanche comme promis =D>

Re: [RESOLU] geshi et quotes

par djtec » 28 déc. 2009, 01:15

De rien graffx PhpFrance à été conçu pour l'entraide.

Ravie de t'avoir aidé et bonne continuation pour ton site.

++

Re: geshi et quotes

par graffx » 28 déc. 2009, 01:12

Alors milles mercis a DJTEC qui a pris de son temps pour m' aider, et avoir trouver aussi vite la reponse.

Pour ceux donc qui utilisent geshi avec ce probleme de nl2br ou de <br /> pour les debutants, adaptez ce morceaux a votre code.

					                                                    <?php


 $tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));


function getGeshi($match) {
        include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

        $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"
       
        $code_geshi = $geshi->parse_code();
       
        $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td></tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>'.$code_geshi.'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif"></td></tr></table>';

        return $code; // Retourne le résultat
}

$text = code(nl2br(stripslashes($tuto['tuto_tuto'])));

function ChangeBR($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '[[br]]', $retour[1]);
       
        return $retour[1];
}

function nl2brCallback($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '', $retour[1]);
        $retour[1] = preg_replace("`\[\[br\]\]+`ims", "\r", $retour[1]);
       
        return $retour[1];
}

$text = preg_replace_callback("`(\[quote=(as|php|css|sql|javascript|html4strict)\]+(.*?)\[\/quote\])`isSm", 'ChangeBR', $text);
$text = preg_replace_callback("`(\[quote=(as|php|css|sql|javascript|html4strict)\]+(.*?)\[\/quote\])`isSm", 'nl2brCallback', $text);
$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>

Re: geshi et quotes

par djtec » 28 déc. 2009, 00:54

C'est bon j'ai trouver grasse a ton lien

Voici la fonction exact:
<?php

function getGeshi($match) {
        include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

        $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"
       
        $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td></tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>'.$geshi->parse_code().'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif"></td></tr></table>';

        return $code; // Retourne le résultat
}

function ChangeBR($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '[[br]]', $retour[1]);
       
        return $retour[1];
}

function nl2brCallback($retour) {
        $retour[1] = preg_replace("`\<br((\s*)\/?)\>`ims", '', $retour[1]);
        $retour[1] = preg_replace("`\[\[br\]\]+`ims", "\r", $retour[1]);
       
        return $retour[1];
}

$text = code(nl2br($tuto['tuto_tuto']));

$text = preg_replace_callback("`(\[quote=(as|php|css)\]+(.*?)\[\/quote\])`isSm", 'ChangeBR', $text);
$text = preg_replace_callback("`(\[quote=(as|php|css)\]+(.*?)\[\/quote\])`isSm", 'nl2brCallback', $text);
$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>
Dans le masque (as|php|css) de la regex il faudra que tu mette tout les language autorisé comme ceci:

(as|php|css|js|html|sharp|java|sql|etc)

Re: geshi et quotes

par graffx » 28 déc. 2009, 00:18

Effectivement il faut mettre precisement quote=html4strict et ca marche.


Cependant, encore un leger detail troublant.

j' ai enlever le nl2br sur la totalité du contenu. Geshi doit deja avoir un nl2br quelque part.


Ce qui fait que si j' enleve le nl2br de mon contenu, les quotes sont parfaites mais le hors-quote , tout se suit a la ligne. Si je remet le nl2br sur le contenu, le hors-quote est nickel mais des <br /> apparait dans les quotes. Quel casse-tete!!!

Auriez vous une solution svp?

Re: geshi et quotes

par djtec » 28 déc. 2009, 00:03

Et ben pour tout les language il faut faire quote=php ou quote=css ou quote=sql etc

Et pour le html aussi sinon le formulaire apparait hors que si tu spécifie html dans quote le html sera affiché comme il doit

Re: geshi et quotes

par graffx » 27 déc. 2009, 23:57

Merci a toi pour ce probleme que tu as durement résolu, je n' aurai pas réussi avec mes compétences.

Cependant, y-a t il un moyen pour que geshi colorise tous les language? sql, html, php au lieu de seulement php?

Re: geshi et quotes

par graffx » 27 déc. 2009, 21:34

Je t' envoi un mp pour que tu vois par toi-meme

j' ai copié collé ton code dans le doute

Re: geshi et quotes

par djtec » 27 déc. 2009, 21:13

Chez moi je fais:
<?php

$tuto = "voici un test [quote=php]<?php funcion get() { return; } ?>[/quote] une autre citation [ quote]Ma citation du jour[/ quote] et un autre code [quote=css]#class{ text-align:center; }[/quote]";

function code($texte)
{

$texte = preg_replace('`\[quote\](.+)\[/quote\]`isU', '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>$1</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">&nbsp;</td></tr></table>', $texte);


//On retourne la variable texte
return $texte;
}

function getGeshi($match) {
     
         include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

     $language = 'php'; // Définir le langage à utiliser
 
     $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"

     $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>Geshi -> '.$match[1].'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">'.$geshi->parse_code().'</td></tr></table>';

     return $code; // Retourne le résultat
}

$text = code(nl2br(stripslashes($tuto)));

$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>
Et le code se colorise très bien et le background apparait.

Donne moi le code complet de ta page stp.

Re: geshi et quotes

par graffx » 27 déc. 2009, 20:12

avec ton code donc, background ok mais plus coloré:
					<?php
function code($texte)
{

$texte = preg_replace('`\[quote\](.+)\[/quote\]`isU', '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>$1</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">&nbsp;</td></tr></table>', $texte);


//On retourne la variable texte
return $texte;
}
?>


         <?php

                                         
                                         
                                        $tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));
                               

 

                                       
                               



function getGeshi($match) {
     
         include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

     $language = 'php'; // Définir le langage à utiliser
 
     $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"

     $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>Geshi -> '.$match[1].'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">'.$geshi->parse_code().'</td></tr></table>';

     return $code; // Retourne le résultat
}

$text = code(nl2br(htmlentities(stripslashes($tuto['tuto_tuto']))));

$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;
?>

  
					  
				<?php

				}
				?>

Re: geshi et quotes

par graffx » 27 déc. 2009, 19:26

je n' ai pas reussi, soit encore ca met bien le background mais rien n' est coloré, sois coloré mais sans background .

voila a nouveau mon texte:
					<?php
function code($texte)
{

$texte = preg_replace('`\[quote\](.+)\[/quote\]`isU', '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>$1</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">&nbsp;</td></tr></table>', $texte);



//etc., etc.

//On retourne la variable texte
return $texte;
}
?>
					      <?php

					  
					  
					$tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));
				

 

					
				



function getGeshi($match) {
     
         include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

     $language = 'php'; // Définir le langage à utiliser
 
     $geshi = new GeSHi($match[1], $language); // Créer un objet "GeSHi"

     return $geshi->parse_code(); // Retourne le résultat
}

$text = stripslashes($tuto['tuto_tuto']);

$text = preg_replace_callback('/\[quote\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>

  
					  
				<?php

				}
				?>
J' ai pas trop compris peu etre comment adapter ce que tu m' a dit, donc je te laisse jeter un oeil :oops:

Re: geshi et quotes

par djtec » 27 déc. 2009, 11:49

Oui Geshi accepte plusieurs language le principe serait ainsi:

[ quote=php][/ quote] ou [ quote=css][/ quote]

Et dans la fontion tu change:
$geshi = new GeSHi($match[1], $language);
En:
$geshi = new GeSHi($match[2], $match[1]);
Mais l'expression régulière sera celle-ci:
'/\[quote=(.+?)\](.+?)\[\/quote\]/is'
Après pour modifié le parse il faut faire ainsi:
                                              <?php

                                         
                                         
                                        $tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));
                               

 

                                       
                               



function getGeshi($match) {
     
         include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

     $language = 'php'; // Définir le langage à utiliser
 
     $geshi = new GeSHi($match[2], $match[1]); // Créer un objet "GeSHi"

     $code = '<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>Geshi -> '.$match[1].'</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">'.$geshi->parse_code().'</td></tr></table>'; 

     return $code; // Retourne le résultat
}

$text = code(nl2br(htmlentities(stripslashes($tuto['tuto_tuto']))));

$text = preg_replace_callback('/\[quote=(.*?)\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;
Voilà.

Re: geshi et quotes

par graffx » 27 déc. 2009, 02:55

alors, je suis a nouveau coincé entre deux resultats, celui avec le code donné plus haut, coloré mais pas trop de mise en forme et le second, avec un background sur les quotes qui rend pas mal, mais plus rien n' est coloré, voici ce que j' ai fait pour le deuxieme resultat:

					      <?php

					  
					  
					$tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));
				

 

					
				



function getGeshi($match) {
     
         include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

     $language = 'php'; // Définir le langage à utiliser
 
     $geshi = new GeSHi($match[1], $language); // Créer un objet "GeSHi"

     return $geshi->parse_code(); // Retourne le résultat
}

$text = code(nl2br(htmlentities(stripslashes($tuto['tuto_tuto']))));

$text = preg_replace_callback('/\[quote\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>


edit:

le mieux serait que j' arrive a placer dans le preg_replace_callback:


<table width="1000" border="0" cellspacing="0" cellpadding="0"><tr><td height="20" background="images/quoteh.gif">&nbsp;</td>
</tr><tr><td background="images/quotem.gif"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td>Geshi</td></tr></table></td></tr><tr><td height="20" background="images/quoteb.gif">&nbsp;</td></tr></table>


Saurais tu comment placer ca? Moi je n' ai eu que des erreurs, bizarre

Re: geshi et quotes

par graffx » 27 déc. 2009, 02:46

bon alors j' ai resolu tous les soucis, sauf un, la couleur est tres pauvre pour l' instant, je sais pas si c' est normal.

voici en attendant mon code presque parfait :)
					      <?php

					  
					  
					$tuto_tuto = nl2br(htmlentities(stripslashes($tuto['tuto_tuto'])));
				

 

					
				



function getGeshi($match) {
     
         include_once('geshi/geshi.php'); // Inclure la librairie GeSHi

     $language = 'php'; // Définir le langage à utiliser
 
     $geshi = new GeSHi($match[1], $language); // Créer un objet "GeSHi"

     return $geshi->parse_code(); // Retourne le résultat
}

$text = stripslashes($tuto['tuto_tuto']);

$text = preg_replace_callback('/\[quote\](.*?)\[\/quote\]/is', 'getGeshi', $text);

echo $text;

?>

Re: geshi et quotes

par graffx » 27 déc. 2009, 02:33

Ha, la j' ai quelque chose. le texte apparait bien en ce qui concerne le php, je ne sais pas si on peut selectionner plusieurs language dans geshi, voici ce que j' obtiens

inscription.php :

<form method="post" action="traitement-inscription.php"><br />
pseudo : <input name="pseudo" type="text"/><br />
Mot de passe : <input name="passe" type="password"/><br />
<input name="submit" type="submit" value="OK" /><br />
</form>




traitement_inscription.php :

<?php<br />
$pseudo = mysql_real_escape_string(htmlspecialchars($_POST['pseudo']));<br />
$passe = mysql_real_escape_string(htmlspecialchars($_POST['passe']));<br />
$passe = sha1($passe);<br />
				  <br />
mysql_query("INSERT INTO VOTRE_TABLE VALUES('', '$pseudo', '$passe')");<br />
<br />
<br />
echo 'Membre ajout&eacute; avec succ&eacute;s';<br />
?>