All pastes #901691 Raw Edit

Something

public text v1 · immutable
·published 2008-02-12 21:30 UTC
rendered paste body
##        Mod title:  E-Univers RE
##
##      Mod version:  1.0
##   Works on PunBB:  1.2.14
##     Release date:  2008-01-12
##           Author:  Marthym & Verite
##
##      Description:  This mod show E-Univers Spy report great
##
##   Affected files:  include/parser.php
##
##       Affects DB:  No
##
##            Notes:  This mod make good presentation of E-Univers Spy report
##                    by add [re][/re] bbcode tag for parse Spy report and
##                    make great table
##
##       DISCLAIMER:  Please note that "mods" are not officially supported by
##                    PunBB. Installation of this modification is done at your
##                    own risk. Backup all applicable files before proceeding.
##


#
#---------[ 1. OPEN ]---------------------------------------------------------
#

parser.php


#
#---------[ 2. FIND (line: 44) ]---------------------------------------------
#

	$a = array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]');
   $b = array('[b]', '[i]', '[u]', '[/b]', '[/i]', '[/u]');

#
#---------[ 3. REPLACE WITH ]-------------------------------------------------
#

	//$a = array('[B]', '[I]', '[U]', '[/B]', '[/I]', '[/U]'); // [re] : del
   //$b = array('[b]', '[i]', '[u]', '[/b]', '[/i]', '[/u]'); // [re] : del
	$a = array('[B]', '[I]', '[U]', '[RE]', '[/B]', '[/I]', '[/U]', '[/RE]');  // [re] : Add
	$b = array('[b]', '[i]', '[u]', '[re]', '[/b]', '[/i]', '[/u]', '[/re]');  // [re] : Add


#
#---------[ 12. FIND (line: 392) ]--------------------------------------------
#

//
// Convert a series of smilies to images
//
function do_smilies($text)
{
	global $smiley_text, $smiley_img;

	$text = ' '.$text.' ';

	$num_smilies = count($smiley_text);
	for ($i = 0; $i < $num_smilies; ++$i)
		$text = preg_replace("#(?<=.\W|\W.|^\W)".preg_quote($smiley_text[$i], '#')."(?=.\W|\W.|\W$)#m", '$1<img src="img/smilies/'.$smiley_img[$i].'" width="15" height="15" alt="'.substr($smiley_img[$i], 0, strrpos($smiley_img[$i], '.')).'" />$2', $text);

	return substr($text, 1, -1);
}

#
#---------[ 13. AFTER, ADD ]---------------------------------------------------
#

//[re] : Begin Add
//
// Parse Spy Reports
//

function do_bbcodere($text)
{
        //Compatibilité UNIX/Windows
        $text = str_replace("\r\n","\n",$text);

        //Compatibilité IE/Firefox
        $text = str_replace("\t",' ',$text);

        $text = stripslashes($text);

        $text = str_replace("Les sondes ont été interceptées et détruites ...", "<br />Les sondes ont été interceptées et détruites ...", $text);

        $lines = explode("\n", $text);
        $estVide = false;

        //On commence par vérifier que le re est valide
        if (preg_match("#Matières premières sur#", $lines[1]))
        {
                //Récupération des infos générales sur la planètes sondées
                $lines[1] = str_replace("Matières premières sur", "", $lines[1]);

                //Récupération des resources présentes
                preg_match("#Titane:\s([0-9 ]+)\sCarbone:\s([0-9 ]+)#", $lines[2], $ressources);
                preg_match("#Tritium:\s([0-9 ]+)#", $lines[3], $ressources2);
                $titane = $ressources[1];
                $carbone = $ressources[2];
                $tritium = $ressources2[1];

                $lines[2] = "<table style=\"width: auto;\" class=\"espionnage\"><tbody><tr><th>Titane</th><th>Carbone</th><th>Tritium</th></tr>";
                $lines[3] = "<tr><td>".$titane."</td><td>".$carbone."</td><td>".$tritium."</td></tr></tbody></table><br />";

                //Récupération du reste du re
				for ($num_line = 4; $num_line < sizeof($lines); $num_line++)
                {
                        $lines[$num_line] = trim($lines[$num_line]);

                        if ($lines[$num_line] == "Flotte")
                        {
                                $lines[$num_line] = "<table style=\"width: auto;\" class=\"espionnage\"><caption>".$lines[$num_line]."</caption>";
                                if ($estVide) $lines[$num_line] = "<tr><td>Rien</td></tr>".$lines[$num_line];
                                $estVide = true;
                        }

                        elseif ($lines[$num_line] == "Défense")
                        {
                                $lines[$num_line] = "</table><br /><table style=\"width: auto;\" class=\"espionnage\"><caption>".$lines[$num_line]."</caption>";
                                if ($estVide) $lines[$num_line] = "<tr><td>Rien</td></tr>".$lines[$num_line];
                                $estVide = true;
                        }

                        elseif ($lines[$num_line] == "Batiments")
                        {
                                $lines[$num_line] = "</table><br /><table style=\"width: auto;\" class=\"espionnage\"><caption>".$lines[$num_line]."</caption>";
                                if ($estVide) $lines[$num_line] = "<tr><td>Rien</td></tr>".$lines[$num_line];
                                $estVide = true;
                        }

                        elseif ($lines[$num_line] == "Recherche")
						{
                                $lines[$num_line] = "</table><br /><table style=\"width: auto;\" class=\"espionnage\"><caption>".$lines[$num_line]."</caption>";
                                if ($estVide) $lines[$num_line] = "<tr><td>Rien</td></tr>".$lines[$num_line];
                                $estVide = true;
                        }

                        elseif (substr($lines[$num_line], 0, 11) == "Probabilité")
                        {
                                $lines[$num_line] = "</table><br />\n".$lines[$num_line];
                                break;
                        }

                        else
                        {
                                $estVide = false;
                                if (strlen($lines[$num_line]) > 0)
                                {
                                        $line = explode(" ", str_replace("\t", " ", str_replace(":", "", $lines[$num_line])));
                                        $lines[$num_line] = "<tr><th>";

                                        foreach ($line as $key => $val)
                                        {
                                                $val = trim($val);
                                                if (is_numeric($val))
                                                {
                                                        $lines[$num_line] .= "</th><td>".$val;
                                                        if ($key < sizeof($line)-1)
                                                        {
                                                                $lines[$num_line] .= "</td><th>";
                                                        }
                                                }
                                                else
                                                {
                                                        $lines[$num_line] .= " ".$val;
                                                }
                                        }

                                $lines[$num_line] .= "</td></tr>\n";
                                }
                                else
                                {
                                        $lines[$num_line] = "<tr><td colspan=\"2\">&nbsp;</td></tr></table>";
								}
                        }
                }
        }
        //echo "<pre>".htmlspecialchars(implode('', $lines))."</pre>";
        return implode('', $lines);
}

//[re] : End Add



#
#---------[ 14. FIND (line: 478) ]--------------------------------------------
#

	// If the message contains a code tag we have to split it up (text within [code][/code] shouldn't be touched)
	if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
	{
		list($inside, $outside) = split_text($text, '[code]', '[/code]');
		$outside = array_map('ltrim', $outside);
		$text = implode('<">', $outside);
	}

#
#---------[ 15. AFTER, ADD ]---------------------------------------------------
#

//[re] : Begin Add
   // If the message contains a rc tag we have to split it up (text within [rc][/rc] shouldn't be touched)
	if (strpos($text, '[re]') !== false && strpos($text, '[/re]') !== false)
	{
		list($inside_re, $outside_re) = split_text($text, '[re]', '[/re]');
		$outside_re = array_map('ltrim', $outside_re);
		$text = implode('<">', $outside_re);
	}
//[re] : End Add

#
#---------[ 16. FIND (line: 518) ]--------------------------------------------
#

	// If we split up the message before we have to concatenate it together again (code tags)
	if (isset($inside))
	{
		$outside = explode('<">', $text);
		$text = '';

		$num_tokens = count($outside);

		for ($i = 0; $i < $num_tokens; ++$i)
		{
			$text .= $outside[$i];
			if (isset($inside[$i]))
			{
				$num_lines = ((substr_count($inside[$i], "\n")) + 3) * 1.5;
				$height_str = ($num_lines > 35) ? '35em' : $num_lines.'em';
				$text .= '</p><div class="codebox"><div class="incqbox"><h4>'.$lang_common['Code'].':</h4><div class="scrollbox" style="height: '.$height_str.'"><pre>'.$inside[$i].'</pre></div></div></div><p>';
			}
		}
	}

#
#---------[ 17. AFTER, ADD ]---------------------------------------------------
#

//[re] : Begin Add
        // If we split up the message before we have to concatenate it together again (re tags)
        if (isset($inside_re))
        {
                $outside_re = explode('<">', $text);
                $text = '';

                $num_tokens = count($outside_re);

                for ($i = 0; $i < $num_tokens; ++$i)
                {
                        $text .= $outside_re[$i];
                        if (isset($inside_re[$i]))
                        {
                                $inside_re[$i] = do_bbcodere($inside_re[$i]);
                                $num_lines = ((substr_count($inside_re[$i], "\n")) + 3) * 1.5;
                                $height_str = ($num_lines > 35) ? '35em' : $num_lines.'em';
                                $text .= '</p><div class="codebox"><div class="incqbox"><h4>'.stripslashes("Rapport d\'espionnage :").'</h4><div class="scrollbox" style="height: '.$height_str.'"><pre>'.$inside_re[$i].'</pre></div></div></div><p>';
                        }
                }
        }
//[re] : End Add


#
#---------[ 18. SAVE/UPLOAD ]-------------------------------------------------
#