Вход Регистрация
Файл: files.php
Строк: 108
<?php
/*(с) Im !eee*/
$lock_fp=''$p_nm_cch=false;
function 
lock($md){
    global 
$lock_fp;
    if(
$md=='r'){
        
$lock_fp=fopen(PG_PREF.'lock.txt','r');
        
flock($lock_fp,LOCK_SH);
    }else{
        
$lock_fp=fopen(PG_PREF.'lock.txt','w');
        
flock($lock_fp,LOCK_EX);
    }
}

function 
rel_lock(){
    global 
$lock_fp;
    
flock($lock_fpLOCK_UN);
    
fclose($lock_fp);
}

function 
m_on_p(&$p, &$l){
    
$p=(int)$p;
    if(
file_exists(PG_PREF.$p.'.txt')){
        
$t=file(PG_PREF.$p.'.txt');
    } else {
        
$p=p_num();
        
$t=file(PG_PREF.$p.'.txt');
    }
    
$l=sizeof($t); $ret=array(array(), array(), array());
    for(
$i=0;$i<$l;$i++){
        
$t2=explode(chr(1), $t[$i]);
        
$ret[0][$i]=$t2[0];
        
$ret[1][$i]=$t2[1];
        
$ret[2][$i]=rtrim($t2[2]);
    }
    return 
$ret;
}

function 
p_num(){
    global 
$p_nm_cch;
    if(
$p_nm_cch!==false){return $p_nm_cch;}
    return (
$p_nm_cch=file_get_contents(PG_PREF.'total.txt'));
}

function 
last_wr(){
    return 
time()-filemtime(PG_PREF.'last.txt');
}

function 
wr($n$m){
    
$n=str_replace(chr(1),'',$n);
    
$m=str_replace(chr(1),'',$m);
    
$l=file_get_contents(PG_PREF.'last.txt')+1;
    if((
$l>MESS_TOT)||$l==1){
        
file_put_contents(PG_PREF.'last.txt'1);
        
$t=p_num()+1;
        
file_put_contents(PG_PREF.'total.txt'$t);
        
file_put_contents(PG_PREF.$t.'.txt'$n.chr(1).time().chr(1).$m);
    }else{
        
file_put_contents(PG_PREF.'last.txt'$l);
        
file_put_contents(PG_PREF.p_num().'.txt'PHP_EOL.$n.chr(1).time().chr(1).$mFILE_APPEND);
    }
}

function 
get_mes($p$n){
    
$p=(int)$p$n=(int)$n;
    
file_exists(PG_PREF.$p.'.txt') or exit(ex_hn('Сообщение не найдено'));
    
$arr=file(PG_PREF.$p.'.txt'); 
    isset(
$arr[$n]) or exit(ex_hn('Сообщение не найдено'));
    
$arr=explode(chr(1), $arr[$n]);
    
$arr[2]=rtrim($arr[2]);
    return 
$arr;
}

function 
ed_m($p$n$a$d$m){
    
$p=(int)$p$n=(int)$n;
    
file_exists(PG_PREF.$p.'.txt') or exit(ex_hn('Сообщение не найдено'));
    
$arr=file(PG_PREF.$p.'.txt');
    isset(
$arr[$n]) or exit(ex_hn('Сообщение не найдено'));
    
$arr[$n]=str_replace(chr(1),'',$a).chr(1).$d.chr(1).str_replace(chr(1),'',$m);
    
file_put_contents(PG_PREF.$p.'.txt'join(PHP_EOLarray_map('rtrim',$arr)));
}

function 
del_m($p,$n){
    
$p=(int)$p$n=(int)$n;
    
file_exists(PG_PREF.$p.'.txt') or exit(ex_hn('Сообщение не найдено'));
    
$arr=file(PG_PREF.$p.'.txt'); 
    isset(
$arr[$n]) or exit(ex_hn('Сообщение не найдено'));
    unset(
$arr[$n]);
    
$tot=p_num();
    for(;
$p<$tot;$p++){
        
$arr2=file(PG_PREF.($p+1).'.txt');
        
$arr[]=$arr2[0];
        unset(
$arr2[0]);
        
file_put_contents(PG_PREF.$p.'.txt'join(PHP_EOLarray_map('rtrim',$arr)));
        
$arr=$arr2;
    }
    if(
sizeof($arr)==0){
        
unlink(PG_PREF.$tot.'.txt');
        
file_put_contents(PG_PREF.'last.txt', ($tot==1)?0:MESS_TOT);
        
file_put_contents(PG_PREF.'total.txt'$tot-1);
    } else {
        
file_put_contents(PG_PREF.$tot.'.txt',$arr);
        
file_put_contents(PG_PREF.'last.txt',sizeof($arr));
    }
}

function 
ct_all(){
    
lock('r');
    
$t=(p_num()-1)*MESS_TOT+file_get_contents(PG_PREF.'last.txt');
    
rel_lock();
    return 
$t;
}
?>
Онлайн: 1
Реклама