sajt u izradi..
English French German Italian Portuguese Russian Spanish
XACoverterAll class[PHP][Source File]
Created: Sunday, 18.August.2013. 15:14
/*
 * @copyright	Copyright (C) 2013 Branislav Kešelj . All rights reserved.
 * @license		GNU/GPLv2
 * v.1.1 - 18.11.2013
*/

class tl
    {
    private $R,$K,$N;

    private $T=['(<script[^>]*>.*?<\/script>)','(<style[^>]*>.*?<\/style>)','{#x}(.*?){\/#x}','(<.*?>)',
    '(&quot;)', '(&apos;)', '(&amp;)', '(&lt;)', '(&gt;)', '(&nbsp;)', '(&iexcl;)', '(&cent;)', '(&pound;)',
    '(&curren;)', '(&yen;)', '(&brvbar;)', '(&sect;)', '(&uml;)', '(&copy;)', '(&ordf;)', '(&laquo;)', '(&not;)', '(&shy;)',
    '(&reg;)', '(&macr;)', '(&deg;)', '(&plusmn;)', '(&sup2;)', '(&sup3;)', '(&acute;)', '(&micro;)', '(&para;)', '(&middot;)',
    '(&cedil;)', '(&sup1;)', '(&ordm;)', '(&raquo;)', '(&frac14;)', '(&frac12;)', '(&frac34;)', '(&iquest;)', '(&times;)', '(&divide;)',
    '(&Oslash;)', '(&oslash;)', '(&forall;)', '(&part;)', '(&exists;)', '(&empty;)', '(&nabla;)', '(&isin;)', '(&notin;)', '(&ni;)',
    '(&prod;)', '(&sum;)', '(&minus;)', '(&lowast;)', '(&radic;)', '(&prop;)', '(&infin;)', '(&ang;)', '(&and;)', '(&or;)',
    '(&cap;)', '(&cup;)', '(&int;)', '(&there4;)', '(&sim;)', '(&cong;)', '(&asymp;)', '(&ne;)', '(&equiv;)', '(&le;)', '(&ge;)',
    '(&sub;)', '(&sup;)', '(&nsub;)', '(&sube;)', '(&supe;)', '(&oplus;)', '(&otimes;)', '(&perp;)', '(&sdot;)',
    '(&Alpha;)', '(&Beta;)', '(&Gamma;)', '(&Delta;)', '(&Epsilon;)', '(&Zeta;)', '(&Eta;)', '(&Theta;)', '(&Iota;)', '(&Kappa;)',
    '(&Lambda;)', '(&Mu;)', '(&Nu;)', '(&Xi;)', '(&Omicron;)', '(&Pi;)', '(&Rho;)', '(&Sigma;)', '(&Tau;)', '(&Upsilon;)', '(&Phi;)',
    '(&Chi;)', '(&Psi;)', '(&Omega;)', '(&alpha;)', '(&beta;)', '(&gamma;)', '(&delta;)', '(&epsilon;)', '(&zeta;)', '(&eta;)', '(&theta;)',
    '(&iota;)', '(&kappa;)', '(&lambda;)', '(&mu;)', '(&nu;)', '(&xi;)', '(&omicron;)', '(&pi;)', '(&rho;)', '(&sigmaf;)', '(&sigma;)',
    '(&tau;)', '(&upsilon;)', '(&phi;)', '(&chi;)', '(&psi;)', '(&omega;)', '(&thetasym;)', '(&upsih;)', '(&piv;)', '(&OElig;)', '(&oelig;)',
    '(&Scaron;)', '(&scaron;)', '(&Yuml;)', '(&fnof;)', '(&circ;)', '(&tilde;)', '(&ensp;)', '(&emsp;)', '(&thinsp;)', '(&zwnj;)', '(&zwj;)',
    '(&lrm;)', '(&rlm;)', '(&ndash;)', '(&mdash;)', '(&lsquo;)', '(&rsquo;)', '(&sbquo;)', '(&ldquo;)', '(&rdquo;)', '(&bdquo;)', '(&dagger;)',
    '(&Dagger;)', '(&bull;)', '(&hellip;)', '(&permil;)', '(&prime;)', '(&Prime;)', '(&lsaquo;)', '(&rsaquo;)', '(&oline;)', '(&euro;)', '(&trade;)',
    '(&larr;)', '(&uarr;)', '(&rarr;)', '(&darr;)', '(&harr;)', '(&crarr;)', '(&lceil;)', '(&rceil;)', '(&lfloor;)', '(&rfloor;)', '(&loz;)',
    '(&spades;)', '(&clubs;)', '(&hearts;)', '(&diams;)'];

    private $S=['konju[^avjrshš][a-z]*', 3, 'injek[a-z]*', 2, 'nadživ[a-z]*', 3, 'tanjug[a-z]*', 3, 'panjeliniz[a-z]*', 3, 'injunkt[a-z]*', 2, 'nadžet[a-z]*',3,
        'nadžnj[a-z]*', 3, 'nadžanj[a-z]*', 3, 'nadždrel[a-z]*', 3, 'nadžup[a-z]*', 3, 'odžal[^j][a-z]*', 2, 'odžaljen', 2, 'podžupan[a-z]*', 3];

    private $I=['<input[^>]*type="submit"[^>]*>','<input[^>]*type="button"[^>]*>'];

    private $C=['џ', 'љ', 'њ', 'а', 'б', 'в', 'г', 'д', 'ђ', 'е', 'ж', 'з', 'и', 'ј', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'ћ', 'у', 'ф', 'х', 'ц', 'ч', 'ш',
                'Џ', 'Џ', 'Љ', 'Љ', 'Њ', 'Њ', 'А', 'Б', 'В', 'Г', 'Д', 'Ђ', 'Е', 'Ж', 'З', 'И', 'Ј', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'Ћ', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш'];
    private $L=['dž', 'lj', 'nj' , 'a', 'b' , 'v', 'g', 'd', 'đ', 'e', 'ž', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'ć', 'u', 'f', 'h', 'c', 'č', 'š',
                'Dž', 'DŽ', 'Lj', 'LJ', 'Nj', 'NJ', 'A', 'B' , 'V', 'G', 'D', 'Đ', 'E', 'Ž', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'Ć', 'U', 'F', 'H', 'C', 'Č', 'Š'];

    public function encode($w)
        {
        $this->N=1000;
        foreach($this->T as $v)
            { $w=preg_replace_callback('/'.$v.'/si',array($this,'e_'),$w); }
        return $w;
        }

    private function e_($m)
        {
        $this->N++;
        $this->R[]='##'.$this->N.'###';
        $this->R[]=$m[1];
        return '##'.$this->N.'###';
        }

    public function encode_($w)
        {
        for($i=0;$i<count($this->S);$i+=2)
            { $this->K=$i; $w=preg_replace_callback('/'.$this->S[$i].'/si',array($this,'e__'),$w); }
        return $w;
        }

    private function e__($m)
        { return substr($m[0],0,$this->S[$this->K+1]).'#q#q##'.substr($m[0],$this->S[$this->K+1]); }

    public function lang($w)
        {
        $l=0;$c=0;
        $l_=implode('',$this->L);
        $c_=implode('',$this->C);
        for($i=0;$i<strlen($w);$i++)
            {
            if(strpos($l_,$w[$i])!==FALSE) $l++;
                else if(strpos($c_,$w[$i])!==FALSE) $c++;
            if($c>10) return 'l';
            if($l>10) return 'c';
            }
        return FALSE;
        }

    public function convert($w,$l)
        {
        if($l=='c')
            {
            $l=$this->L;
            foreach($l as $k=>$v)
                {$l[$k]='/'.$v.'/';}
            $w=preg_replace($l,$this->C,$w);
            }
            else
                {
                $c=$this->C;
                foreach($c as $k=>$v)
                    {$c[$k]='/'.$v.'/';}
                $w=preg_replace($c,$this->L,$w);
                }
        return $w;
        }

    public function decode($w)
        {
        for($i=0;$i<count($this->R);$i+=2)
            { $w=preg_replace('/'.$this->R[$i].'/',$this->R[$i+1],$w); }
        $this->R='';
        return $w;
        }

    public function decode_($w)
        { return $w=preg_replace('/#q#q##/','',$w); }

    public function convertInputTag($w,$l)
        {
        $this->K=$l;
        foreach($this->I as $v)
            { $w=preg_replace_callback('/'.$v.'/si',array($this,'i_'),$w); }
        return $w;
        }

    private function i_($m)
        { return preg_replace_callback('/value="(.*?)"/',array($this,'i__'),$m[0]); }

    private function i__($m)
        { return  'value="'.$this->convert($m[1],$this->K).'"'; }

    public function translate($w)
        {
        $w=$this->encode($w);
        $l=$this->lang($w);
        if($l=='c') $w=$this->encode_($w);
        $w=$this->convert($w,$l);
        $w=$this->decode($w);
        if($l=='c') $w=$this->decode_($w);
        return $this->convertInputTag($w,$l);
        }
}

$a='Ovo je tekst koji se prevodi {#x}<span style="color:#f00">tekst koji se ne prevodi</span>{/#x} i opet tekst koji se prevodi ...';
$o=new tl();
//echo $o->translate($a);

 

Post a comment
0
Comments | Add yours
  • No comments found
Free visitor tracking, live stats, counter, conversions for Joomla, Wordpress, Drupal, Magento and Prestashop