Tfe

Ongi etorri tfe-ren webgunera...

Old stuff/old_sites/www/func.php

(Deskargatu)
<?php


// Fonction pour encoder les mails par neokraft.net
function hex_encode ($str)
{
$encoded = bin2hex($str); 
$encoded = chunk_split($encoded, 2, '%'); 
$encoded = '%'.substr($encoded, 0, strlen($encoded) - 1); 
return $encoded; 
}
function html2text($str)
{
$a = array(
	"/<span style=\"text-decoration:line-through\">(.+?)<\/span>/",
	"/<a target=\"_blank\" href=\"(.+?)\">(.+?)<\/a>/",
	"/<img alt=\"Image sans description\"  src=\"(.+?)\" \/>/"
	);
$b = array (
	"<n>$1</n>",
	"[$1|$2]",
	"[img=$1]"
	);
return preg_replace($a,$b,$str);
	

}


// Fonction pour enlever les balises non desirees
function text2html($str)
{
   $a=array(
	"/&lt;n&gt;(.+?)&lt;\/n&gt;/",	   
	"/&lt;i&gt;(.+?)&lt;\/i&gt;/",	
        "/&lt;b&gt;(.+?)&lt;\/b&gt;/",
	"/\[(http|ftp):\/\/([^\s\n\|]+)\|([^\]]+)\]/",
	"/\[img=([^\s\n\]]+)\]/"	
	);
   $b=array(
	"<span style=\"text-decoration:line-through\">$1</span>",
	"<i>$1</i>",
	"<b>$1</b>",
	"<a href=\"$1://$2\">$3</a>",
	"<img alt=\"Image sans description\"  src=\"$1\" \/>",	
	);
#   $str = htmlentities($str, ENT_QUOTES);
   $str = htmlentities($str);
#   $str = preg_replace("\n\-([^\n]+)","<li>$1</li>",$str);
   $str=  preg_replace($a,$b,$str);
   $str = preg_replace("/(?:\n|\s|$){2}(http|ftp):\/\/([^\s\n\<]+)/","<a href=\"$1://$2\">$1://$2</a>",$str);
    return preg_replace(
	"/<a href=\"([^\"]+)\">(http|ftp):\/\/([^<]{30})([^<]{4,})<\/a>/",
	"<a href=\"$1\">$2:\/\/$3(...)<\/a>",
	$str);
}	

// Fonction pour normaliser les titre, IE enlever les caracteres bizarres et espaces dans les urls
function normalise($str)
{
$str = preg_replace('/[^a-z0-9_-\s\']/','',strtolower($str));
$str = preg_replace('/[\s\']+/',' ',trim($str));
$str = str_replace(' ','-',$str);
return $str;
}



function dostats() // $var_ip , $article arguments
{
    foreach(array('account','article','breves','edito','mail','visites') as $key)
    {
    $fichier_stat = dirname(__FILE__)."/ips/$key";
    $hand  = fopen($fichier_stat,"r") or next;
    $contenu = fread($hand,filesize($fichier_stat));
    fclose($hand);
    $contenu = unserialize(base64_decode($contenu));

    ereg("([0-9]{4})([0-9]{2})([0-9]{2})",$contenu['date'],$regs);
    if ($regs[1] != 0 and $regs[2] != 0 and $regs[3] != 0)
    {
    echo "$contenu ,$key : $regs[1] $regs[2] $regs[3]  => OK<br>";
    array_shift($contenu);
    ${$key} = count($contenu);
    }
    }
    $query = "INSERT INTO stats (annee,mois,jour,account,article,breves,edito,mail,visites) VALUES ('$regs[1]','$regs[2]','$regs[3]',$account,$article,$breves,$edito,$mail,$visites)";
    echo "q: $account et $article et $breves et $edito et $mail et $visites: $query<br>";			  
#    mysql_query($query) or die(mysql_error()."<br />".$query);

}

function ip_read($art_f)
{
$ip_file = dirname(__FILE__)."/ips/$art_f";
$hd  = fopen($ip_file,"r");
$contenu = fread($hd,filesize($ip_file));
fclose($hd);
$var_ip = unserialize(base64_decode($contenu));
#

if ($var_ip['date'] != date(Ymd)) 
    { 


    unset($var_ip);    
    $var_ip = array('date' => date(Ymd));
    foreach(array('account','article','breves','edito','mail','visites') as $key)
    {
    ip_write($key,$var_ip);
    }
    }
return $var_ip;
}


function ip_write($art_f,$var_f)
{
$ip_file = dirname(__FILE__)."/ips/$art_f";
$hd  = fopen($ip_file,"w") or die("FATAL writing $art_f and ".$var_f['date']);
fwrite($hd,base64_encode(serialize($var_f)));
fclose($hd);
}


function affichage($var_a,$var_b,$var_c)
{
    if($var_b == 0 ) { $var_b = 1000000; }
    $i=0;
    $li = 0;
    $lignes = explode("\n",$var_a);
    foreach($lignes as $key)
    {
    $key = substr($key,0,$var_b);

    

     if ($i>$var_b) { break; }
     
     if (ereg("^\_{2}...$",$key)) { echo "<hr>"; }
     if (!$code and ereg("^\[code\](.*)\[\/code\]",$key,$regs)) { echo "<pre>$regs[1]</pre>"; }     
     
    elseif(ereg("(.*)\[\/code\]",$key) and $pre) { echo preg_replace("\[code\]","",$key)."</pre>"; $pre=0;}     
     elseif(ereg("^\[code\]",$key)) { echo "<pre>".preg_replace("\[code\]","",$key); $pre=1;}     

    elseif(ereg("(.*)\[\/cadre\]",$key) and $cadre) { echo preg_replace("\[cadre\]","",$key)."</pre>"; $cadre=0;}     
     elseif(!$cadre and ereg("^\[cadre\]",$key)) { echo "<div class=\"cadre\">".preg_replace("\[cadre\]","",$key); $cadre=1;}     

     
     
     elseif (ereg("^-",$key) and !$pre) 
     { 
        $key = preg_replace("/^-(.*)/","$1",$key);
	if($li == 0) 
	    { 
	    echo "<ul><li>$key</li>"; 
	    $li= 1;
	    }
	else { echo "<li>$key</li>"; }
    }
    elseif($li==1) { 
	    echo "</ul>"; 
	    $li=0;
    	    print "<p>$key</p>\n";
    }
     elseif (!$pre) { print "<p>$key</p>\n"; }
     else { print "$key\n"; }
     $i = 1+$i + count(split(".",$key));
    }
    if ($li==1) { echo "</ul>"; }
    if ($pre==1) { echo "</pre>"; }    
    if ($cadre==1) { echo "</div>"; }        
    
    if ($var_b != 1000000 and $i != count($lignes)) { echo "<p><a onclick=\"window.open('".$var_c."','Zoom sur l actualite','width=400,height=300,resizable=yes,statusbar=yes,scrollbar=yes')\"    href=\"#\" title=\"Suite\">[Suite]</a></p>"; }

}


function getmicrotime()
{

    list($usec,$sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}

function aide()
{
 echo "<p>Aide formattage des messages:</p><ul>
 <li>Seules les balises &lt;i&gt;(texte en italique) &lt;/i&gt; et &lt;b&gt; (texte en gras) &lt;/b&gt; sont acceptees. Toute autre balise sera converti en &amp;lt;balise&amp;gt;. </li>
 <li>Pour donner des urls en specifiant un nom, vous pouvez utiliser la syntaxe <span class=\"underline\">[http://votre_url.org|le nom du lien]</span>  ce qui donnera un affichage &quot;le nom du lien&quot;.</li>
 <li>Pour creer une liste, entrez les elements en debut de ligne en commen&#231;ant par des \"-\"</li>
 <li>Pour inserer une image, il suffit d'utiliser [img=url_de_l'image_voulue]. 
 <li>Pour inserer du code: [code] votre source [/code].  </li>
 <li>Pour inserer un encadr&eacute;: [cadre] votre texte encadr&eacute; [/cadre].  </li>
 <li>Barrer du texte: &lt;n&gt;Texte&lt;/n&gt;</li>
 
 </ul>

   ";
}




function miniature($picture,$dest) /* Tire de php.net */
{

$max=100; 
$src_img=ImagecreateFromJpeg($picture);

$oh = imagesy($src_img);  # original height
$ow = imagesx($src_img);  # original width

$new_h = $oh;
$new_w = $ow;

if($oh > $max || $ow > $max){
       $r = $oh/$ow;
              $new_h = ($oh > $ow) ? $max : $max*$r;
	             $new_w = $new_h/$r;
		     }
		     // note TrueColor does 256 and not.. 8
		     $dst_img = ImageCreateTrueColor($new_w,$new_h);

		    
		     ImageCopyResized($dst_img, $src_img, 0,0,0,0, $new_w, $new_h, ImageSX($src_img), ImageSY($src_img));
		        ImageJpeg($dst_img, $dest);
}			


?>