Advertisement
terorama

slider / baser.inc.php

Aug 21st, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 26.19 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. /*function __autoload($class_name) {
  5.    require $classname.'inc.php';
  6. }*/
  7.  
  8. if ($_SERVER["SERVER_NAME"]!='localhost')
  9.    require  'autoinfo.inc.php';
  10.  
  11. class Baser extends AutoInfo {
  12.  
  13.    const LOGFILE='../baserlogz.txt';
  14.    const STFILE='stylmoves4.txt';
  15.    const ZADDR='http://house-of-dance.ru';
  16.    const YADDR='/learn/picport/req4.php?reqg=getzsite&pgn=';
  17.  
  18.    protected  $db_host;
  19.    protected  $db_name;
  20.    protected  $db_login;
  21.    protected  $db_password;
  22.    
  23.    protected  $db_conn;
  24.    protected  $connected;
  25.    protected  $actual_query;
  26.    protected  $actual_position;
  27.    protected  $logging;
  28.    
  29.    public     $logfile;
  30.    protected  $f_handle;
  31.    
  32.    public $errornum;
  33.    public $errorname;
  34.    public $errormessage;
  35.    
  36.    //---------------------------
  37.    private $debugmode=false;
  38.    
  39.    private $zpages=array (
  40.       0=>'',
  41.       1=>'contacts',
  42.       2=>'rotations',
  43.       3=>'teachers',
  44.       4=>'prices',
  45.       5=>'news',
  46.       6=>'gallerynew',
  47.       7=>'gallery/65',
  48.       8=>'collectives',
  49.       9=>'arenda'
  50.    );
  51.    //------------------------
  52.    private $zcommon_replaces=array (
  53.       0=> array ('s'=>'/<\s*(font|b|strong)[^>]*>/ims',
  54.          't'=>'', 'iter'=>true
  55.       ),
  56.       1=> array ('s'=>'',
  57.          't'=>'', 'iter'=>true)
  58.    );
  59.    //------------------------
  60.    private $zstyles=array();
  61.      
  62.    
  63.    
  64.    //--------------------------------------------------
  65.    function __construct($inmyname, $inhost,$inlogin, $inpass,$inname, $logging=false) {
  66.    
  67.       parent::__construct($inmyname);
  68.      
  69.       $this->init_logfile();
  70.    
  71.       $this->db_host=$inhost;
  72.       $this->db_name=$inname;
  73.       $this->db_login=$inlogin;
  74.       $this->db_password=$inpass;
  75.      
  76.       $this->logging=$logging;
  77.      
  78.       if ($this->connect()!=0)
  79.          $this->set_error($this->errormessage);
  80.       else
  81.          $this->set_ok();
  82.          
  83.    }
  84.    //--------------------------------------------------
  85.    function __destruct() {
  86.       $this->disconnect();
  87.            
  88.    }
  89.    //--------------------------------------------------
  90.    public function init_logfile() {
  91.    
  92.       if (isset($_SESSION['logfile'])) {
  93.      
  94.          $this->logfile=$_SESSION['logfile'];
  95.          
  96.       } else {
  97.          $p=strrpos(Baser::LOGFILE,'/');
  98.          $zfile=substr(Baser::LOGFILE,$p+1);
  99.          $zdir=substr(Baser::LOGFILE,0,$p+1);
  100.      
  101.          $zz=explode('.',$zfile);
  102.      
  103.          $this->logfile=$zdir.array_shift($zz).'_'.
  104.                 date('dmYHis').'_'.rand(200,8000).'.'.array_shift($zz);
  105.                
  106.          $_SESSION['logfile']=$this->logfile;      
  107.       }
  108.    }
  109.    //--------------------------------------------------
  110.    public function prep_structs() {
  111.       for ($i=0; $i<count($this->zpages); $i++) {
  112.          
  113.          $zrepl_elem=array();
  114.          $zrepl_elem['num']=$i;
  115.          $zrepl_elem['pg']=$this->zpages[$i];
  116.          
  117.                          
  118.          $zrepl_elem['repls']=array_merge($this->zcommon_replaces);
  119.          
  120.          $this->zrepl_arr[$this->zpages[$i]]=$zrepl_elem;
  121.  
  122.       }
  123.      
  124.    }
  125.    //--------------------------------------------------
  126.    public function connect() {
  127.       $this->db_conn=mysql_connect($this->db_host, $this->db_login, $this->db_password);
  128.       mysql_select_db($this->db_name);
  129.      
  130.       if (mysql_errno()<>0) {
  131.          $this->errornum=mysql_errno();
  132.          $this->errorname=mysql_error();
  133.          $this->errormessage=$this->errornum.":".$this->errorname;
  134.          
  135.          $this->connected=false;
  136.          return -1;
  137.       }
  138.       else {
  139.          $this->connected=true;
  140.          return 0;    
  141.          }
  142.    }
  143.    //--------------------------------------------------
  144.    public function disconnect() {
  145.       if (!$this->connected) return;
  146.          
  147.       mysql_close($this->db_conn);
  148.    }
  149.    
  150.    //--------------------------------------------------
  151.    protected function logt($instr) {
  152.    
  153.       if (!$this->logging) return;
  154.      
  155.       if (file_exists($this->logfile))
  156.          $this->f_handle=fopen($this->logfile,'ab');
  157.       else
  158.          $this->f_handle=fopen($this->logfile,'wb');
  159.          
  160.      // fwrite($this->f_handle, $instr."\r\n", strlen($instr)+2);
  161.      
  162.      fwrite($this->f_handle, date('d.m.Y H:i:s').' '.$instr."\r\n");
  163.      
  164.       fclose($this->f_handle);
  165.      
  166.          
  167.    }
  168.    
  169.    //--------------------------------------------------
  170.    protected function checksqlerror() {
  171.    
  172.       if (mysql_errno()>0) {
  173.          $this->errornum=mysql_errno();
  174.          $this->errorname=mysql_error();
  175.          $this->errormessage=$this->errornum.':'.$this->errorname;
  176.          
  177.          $this->set_error($this->errormessage);
  178.       } else {
  179.          $this->set_ok();
  180.       }  
  181.    }
  182.    //--------------------------------------------------
  183.    public function insertQuery($insql,$fields,$values) {
  184.    
  185.       if (!$this->connected) return;
  186.    
  187.       $sql=str_replace('%fields%',implode(',',$fields),$insql);
  188.       $sql=str_replace('%values%',implode(',',$values),$sql);
  189.      
  190.       $this->actual_query=$sql;  
  191.       $this->logt($sql);
  192.      
  193.       mysql_query($sql);  
  194.       $this->checksqlerror();
  195.       $this->logt($this->show_status());
  196.      
  197.    }
  198.    //--------------------------------------------------
  199.    public function execQuery($insql) {
  200.    
  201.       if (!$this->connected) return;
  202.      
  203.       $this->actual_query=$insql;
  204.       $this->logt($insql);
  205.      
  206.       mysql_query($insql);
  207.       $this->checksqlerror();
  208.       $this->logt($this->show_status());
  209.      
  210.       return $this->actual_query;
  211.    }
  212.    
  213.     //--------------------------------------------------
  214.     public function getSingle($insql) {
  215.    
  216.         if (!$this->connected) return;
  217.        
  218.         $this->actual_query=$insql;
  219.         $this->logt($insql);
  220.        
  221.         $result=mysql_query($insql);
  222.         $this->checksqlerror();
  223.         $this->logt($this->show_status());
  224.        
  225.         if ($this->is_error()) return;
  226.        
  227.         $row=mysql_fetch_array($result,MYSQL_NUM);
  228.         return $row[0];
  229.     }  
  230.     //--------------------------------------------------
  231.     public function getQuery($insql,$start,$num, $isassoc=false) { 
  232.        
  233.         if (!$this->connected) return;
  234.        
  235.         $this->actual_query=$insql;
  236.         $this->logt($insql);
  237.        
  238.         $result=mysql_query($insql);
  239.         $this->checksqlerror();
  240.         $this->logt($this->show_status());
  241.        
  242.         if ($this->is_error()) return;
  243.        
  244.         $nfields=mysql_num_fields($result);
  245.         $n_items=1;
  246.         if ($n_items<$start) {
  247.            while (($row=mysql_fetch_array($result,MYSQL_NUM)) && ($n_items<$start)) {
  248.               $n_items++;
  249.            }}
  250.            
  251.         $items=array();
  252.        
  253.         if ($isassoc) {
  254.            while (($row=mysql_fetch_array($result,MYSQL_ASSOC)) && ($n_items<($start+$num))) {
  255.               $n_items++;
  256.               $item=array();
  257.               foreach ($row as $key=>$value) {
  258.                  $item[$key]=$value;
  259.               }
  260.               $items[]=$item;
  261.            }
  262.        
  263.         } else {
  264.            
  265.              while (($row=mysql_fetch_array($result,MYSQL_NUM)) && ($n_items<($start+$num))) {
  266.                 $n_items++;
  267.                 $item=array();
  268.                 for ($i=0;$i<$nfields;$i++) {
  269.                    $item[]=$row[$i];
  270.                 }
  271.                 $items[]=$item;        
  272.              }
  273.         }
  274.         $this->actual_position=$n_items;
  275.         return $items;
  276.        
  277.     }
  278.     //--------------------------------------------------
  279.     public function showRegs() {
  280.        $items=$this->getQuery('select reg_name from regs order by id desc',1,300,true);
  281.        if (count($items)==0) return;
  282.        
  283.        for ($i=0;$i<count($items);$i++) {
  284.           $items[$i]["reg_name"]=htmlspecialchars($items[$i]["reg_name"]);
  285.        }
  286.        
  287.        return json_encode($items);
  288.     }
  289.     //--------------------------------------------------
  290.     public function showDir($inpath) {
  291.    
  292.        //----------------------------
  293.        function cmp($a,$b) {
  294.           if ($a["isdir"]) {
  295.              if ($b["isdir"]) {
  296.                 if ($a["name"]==$b["name"]) return 0;
  297.                 return ($a["name"]<$b["name"]) ? -1 : 1;
  298.                 }
  299.              else
  300.                 return -1;
  301.             }
  302.           else {
  303.              if ($b["isdir"]) {          
  304.                 return 1;              
  305.              }
  306.              else {
  307.                if ($a["name"]==$b["name"]) return 0;
  308.                return ($a["name"]<$b["name"]) ? -1 : 1;
  309.              }
  310.           }
  311.        }
  312.        //----------------------------
  313.        
  314.        $dir=opendir($inpath);
  315.        
  316.        $files_m=array();
  317.        
  318.        while ($name=readdir($dir)) {
  319.           if (($name!='.') && ($name!='..')) {
  320.              $files_item=array();
  321.              $files_item["name"]=$name;
  322.              $files_item["full"]=$inpath.$name;
  323.              $files_item["isdir"]=is_dir($inpath.$name);
  324.              
  325.              if (is_file($inpath.$name)) {
  326.              
  327.                 $files_item["filesize"]=filesize($inpath.$name);
  328.                 $files_item["fileatime"]=date('d.m.Y',fileatime($inpath.$name));
  329.                 $files_item["filemtime"]=date('d.m.Y',filemtime($inpath.$name));
  330.                 $files_item["filectime"]=date('d.m.Y',filectime($inpath.$name));
  331.              }
  332.              
  333.              $files_m[]=$files_item;
  334.           }
  335.        }
  336.        
  337.        closedir($dir);
  338.        //uasort($files_m,'cmp');
  339.        return json_encode($files_m);
  340.        
  341.     }
  342.     //--------------------------------------------------
  343.     public function showPics($reztype,$num=5,$cycle=false) {
  344.    
  345.        //----------------------------------------------
  346.        function ispic($var) {
  347.           if (@file_get_contents("small/${var[0]}.${var[1]}")==false)
  348.              return false;
  349.           else
  350.              return true;
  351.        }
  352.        //----------------------------------------------
  353.        $items=array();
  354.        $tmp_num=$num;
  355.        if (isset($_SESSION["startpic"]))
  356.           $startpic=$_SESSION["startpic"];
  357.        else
  358.           $startpic=1;
  359.        
  360.        do {
  361.           $itz=$this->getQuery('select id, ext from pics order by id',$startpic,$tmp_num);
  362.           $startpic=$this->actual_position;
  363.          
  364.           //if (count($itz)==0) return;
  365.           $cnt=(count($itz)==$tmp_num);
  366.           //-------------------
  367.           if (($cycle==true) && (!$cnt)) {
  368.              $cnt=true;
  369.              $startpic=1;
  370.           }
  371.           //-------------------
  372.           $itz=array_filter($itz,"ispic");
  373.          
  374.           $items=array_merge($items,$itz);
  375.           $tmp_num=$num-count($items);
  376.           }      
  377.        while (($cnt) && (count($items)<$num));
  378.        
  379.        $_SESSION["startpic"]=$startpic;
  380.  
  381.          
  382.        //---------------------------------------------xml output
  383.        if ($reztype=='xml') {
  384.        
  385.           $dom= new DOMDocument();
  386.           $root=$dom->appendChild($dom->createElement('pics'));
  387.        
  388.           foreach ($items as $item) {
  389.        
  390.              $pic=$dom->createElement('pic');
  391.              
  392.          
  393.              $big=$dom->createElement('big');
  394.              $small=$dom->createElement('small');
  395.          
  396.              $big->appendChild($dom->createTextNode("pic/{$item[0]}.{$item[1]}"));
  397.              $small->appendChild($dom->createTextNode("small/{$item[0]}.{$item[1]}"));
  398.              
  399.              $pic->appendChild($big);
  400.              $pic->appendChild($small);
  401.              $root->appendChild($pic);                   
  402.           }
  403.           return $dom->saveXML();
  404.          
  405.        
  406.        }
  407.        //--------------------------------------------json output
  408.        if ($reztype=='json') {
  409.           $items_out=array();
  410.          
  411.           foreach ($items as $item) {
  412.              
  413.              //if (@file_get_contents("small/${item[0]}.${item[1]}")==false)
  414.              //   continue;
  415.                
  416.              $item_out=array();
  417.              $item_out['big']="pic/${item[0]}.${item[1]}";
  418.              $item_out['small']="small/${item[0]}.${item[1]}";
  419.              $items_out[]=$item_out;
  420.           }
  421.          
  422.           return json_encode($items_out);
  423.        }
  424.     }
  425.     //--------------------------------------------------
  426.     public function showparsed($num=5) {
  427.    
  428.         $inf=file('../parsed4.txt');
  429.        
  430.         if (isset($_SESSION["startpic"]))
  431.            $startpic=$_SESSION["startpic"];
  432.         else
  433.            $startpic=1;
  434.        
  435.         $items_out=array();
  436.        
  437.         for ($i=$startpic-1;$i<$startpic-1+$num;$i++) {
  438.            $item_out=array();
  439.            $item_out['big']=$inf[$i];
  440.            $item_out['small']=$inf[$i];
  441.            $items_out[]=$item_out;
  442.        }
  443.        
  444.        $_SESSION["startpic"]=$startpic+$num;
  445.        
  446.         return json_encode($items_out);
  447.     }
  448.  
  449.     //--------------------------------------------------old
  450.     private function parse_go($intmps) {
  451.    
  452.        $dom = new domDocument('1.0','utf-8');
  453.        //$dom->encoding='utf-8';
  454.        @$dom->loadHTML($intmps);   
  455.        
  456.        $inel = $dom->getElementsByTagName('font');
  457.        $nodes=array();
  458.        //foreach ($inel as $node) {
  459.           //$nodes[]=$node;      
  460.        //}
  461.        for ($i=0; $i<$inel->length; $i++) {
  462.           $nodes[]=array(
  463.              //'tvalue'=>$inel->item($i)->textContent,
  464.              'tg'=>$inel->item($i)->nodeName,
  465.              'face'=>$inel->item($i)->getAttribute('face'),
  466.              'color'=>$inel->item($i)->getAttribute('color'),
  467.              'size'=>$inel->item($i)->getAttribute('size'),
  468.              'value'=>$inel->item($i)->nodeValue);
  469.              
  470.        }
  471.        
  472.        echo print_r($nodes);
  473.        
  474.        unset($dom);
  475.     }
  476.    
  477.     //--------------------------------------------------
  478.     public function get_siteall() {
  479.    
  480.           if ($_SESSION["npage"]<count($this->zpages)) {
  481.          
  482.              $this->logt('page: '.$_SESSION["npage"].' '.
  483.                 $this->zpages[$_SESSION["npage"]]);
  484.              
  485.              if (isset($_SESSION["zstyles"]))
  486.                 $this->zstyles=$_SESSION["zstyles"];
  487.                
  488.              $this->get_sitecont_new($this->zpages[$_SESSION["npage"]]);
  489.              $this->logt(print_r($this->zstyles,true));
  490.  
  491.              $_SESSION["zstyles"]=$this->zstyles;
  492.              
  493.              header('Location: '.$_SERVER["PHP_SELF"].'?reqg=getzsite');
  494.           }
  495.           else {         
  496.              if (isset($_SESSION["zstyles"]))
  497.                 $this->zstyles=$_SESSION["zstyles"];
  498.              
  499.              $fhandle=fopen(Baser::STFILE,'wb');
  500.              for ($i=0; $i<count($this->zstyles); $i++) {
  501.                 fwrite($fhandle,$this->zstyles[$i]."::\r\n");
  502.              }
  503.              fclose($fhandle);
  504.           }
  505.     }
  506.    
  507.     //--------------------------------------------------
  508.     //      expand parsed element
  509.     //--------------------------------------------------
  510.     private function zelem_iter(&$elems,&$tmps4) {
  511.    
  512.        $found=false;
  513.        for ($i=0;$i<count($elems);$i++) {
  514.           $z=array();
  515.           preg_match('/((<\s*(font|b|strong|h1|h2|h3|h4|span)(\b[^>]*>|>))\s*)'.
  516.                '\[ZZ-'.$elems[$i]['code'].'-ZZ\]'.
  517.                '(\s*<\s*\/\s*(\3)[^>]*>)/ims',
  518.                $tmps4, $z);
  519.                                
  520.           if (count($z)>0) {
  521.              $elems[$i]['format'][]=$z[2];
  522.              $elems[$i]['base']=$z[1].$elems[$i]['base'].$z[5];
  523.              $elems[$i]['length']+=strlen($z[1])+strlen($z[5]);
  524.              $elems[$i]['offset']-=strlen($z[1]);
  525.              $found=true;
  526.              
  527.              $tmps4=str_replace($z[1].'[ZZ-'.$elems[$i]['code'].'-ZZ]'.$z[5],
  528.              '[ZZ-'.$elems[$i]['code'].'-ZZ]',$tmps4);
  529.              }         
  530.        }
  531.        return $found;
  532.     }
  533.    
  534.     //----------------------------------------------------------
  535.     //              parse html page
  536.     //----------------------------------------------------------
  537.     public function get_sitecont_new($inaddr) {
  538.    
  539.        $this->prep_structs();
  540.        
  541.        if (!file_exists('housepages'))
  542.           mkdir('housepages');
  543.        
  544.        $zaddr=str_replace('/','_',$inaddr);
  545.        $zaddr=($zaddr=='' ? 'zstbase' : substr($zaddr,0,strlen($zaddr)-1));        
  546.        $tmpf='housepages/'.$zaddr.'.txt';    
  547.        
  548.        if ((file_exists($tmpf)) && (time()-filemtime($tmpf)<3600) && (filesize($tmpf)>100))
  549.           {
  550.              //echo time()-filemtime($tmpf);
  551.              $tmps=file_get_contents($tmpf);
  552.           }
  553.        else
  554.           {    
  555.           $opts= array (
  556.              'http'=>array (
  557.                 'method'=>'GET',
  558.                 'header'=>"Accept: text/html\r\n".
  559.                           "Accept-Charset: windows-1251,utf-8\r\n".
  560.                           "Accept-Language: ru-RU,en-US,en\r\n".
  561.                           "Cache-Control: max-age=0\r\n".
  562.                           "Connection: keep-alive\r\n".
  563.                           "Cookie: BITRIX_SM_LOGIN=dancadmin\r\n".
  564.                           "User-Agent: Mozilla/5.0\r\n"));
  565.            
  566.           $context=stream_context_create($opts);           
  567.                          
  568.           $tmps=file_get_contents(Baser::ZADDR.'/'.$inaddr, false, $context);
  569.           if ($tmps===false) {
  570.              if (file_exists($tmpf))
  571.                 $tmps=file_get_contents($tmpf);
  572.              else
  573.                 $tmps='failed open remote site '.date('d.m.Y H:I:s', time());
  574.           }
  575.              
  576.          
  577.           /*if (!file_exists($tmpf)) {
  578.              $tmphh=fopen($tmpf,'w');
  579.              fclose($tmphh);
  580.              }*/
  581.           file_put_contents($tmpf,$tmps);
  582.           }
  583.        
  584.        $stss='<td id="leftcontent">';
  585.        $sta=stripos($tmps,$stss);
  586.        $fin=stripos($tmps,'<td id="rightmenu">',$sta);
  587.        
  588.        $tmps=substr($tmps,$sta+strlen($stss),$fin-$sta-strlen($stss));
  589.        $fin=strrpos($tmps,'</td>');
  590.        $tmps=substr($tmps,0,$fin);
  591.        //header('Content-type: text/plain; charset=utf-8');
  592.  
  593.        
  594.        $tmps=iconv('windows-1251','UTF-8',$tmps);
  595.        $tmps='<div id="incl">'.$tmps.'</div>';
  596.        
  597.        $tmps=preg_replace('/(<\s*img[^>]*src=(["\']))(?!https?:)\/?([^\2>]*)(\2[^>]*>)/ims',
  598.           '$1'.Baser::ZADDR.'/$3$4',$tmps);
  599.          
  600.  
  601.        $tmps=preg_replace('/(<\s*a[^>]*href=(["\']))(?!https?:)\/?([^\2>:]*)(\2([^>]*>))/ims',
  602.           '$1#$2 rel="$3" class="ajaxlink" $5',$tmps);
  603.          
  604.        $tmps=preg_replace('/(<\s*a[^>]*href=(["\']))http:\/\/www.house-of-dance.ru\/([^\2>:]*)(\2([^>]*>))/ims',
  605.           '$1#$2 rel="$3" class="ajaxlink" $5',$tmps);
  606.          
  607.        //$tmps='<meta http-equiv="Content-type" content="text/html; charset=utf-8" />'.$tmps;
  608.        //$tmps='<font> <strong>  <font> hjhj g</font> </strong></font>'.$tmps;
  609.            //echo $tmps;
  610.            
  611.        //$this->parse_go($tmps);
  612.        //-------------------------------------------------
  613.        $tmps= preg_replace('/<(\s*\/?\s*(br|hr|p|a|img|table|tr|td|th|tbody|div|li|ul)(\b[^>]*|\s*))>/ims','[\1]',
  614.        $tmps);
  615.              
  616.        $found=false;
  617.        $nested_elss=array();
  618.        $num=0;
  619.        
  620.        //------------------------------------------------------
  621.        //              parse doc
  622.        //------------------------------------------------------
  623.        do {
  624.        
  625.           $z=array();
  626.           preg_match_all('/(<\s*(font|b|strong|h1|h2|h3|h4|span)(\b[^>]*>|>))([^<>]*)<\s*\/\s*(\2)[^>]*>/ims',
  627.           $tmps,$z,
  628.           PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER);     
  629.           //----------------------------------
  630.           $nested_els=array();
  631.  
  632.           for ($i=0; $i<count($z[0]); $i++) {
  633.        
  634.              $nested_el=array();
  635.              $nested_el['base']=$z[0][$i][0];
  636.              $nested_el['inbase']=$z[4][$i][0];
  637.              $nested_el['length']=strlen($z[0][$i][0]);
  638.              $nested_el['offset']=$z[0][$i][1];
  639.              $nested_el['format'][]=$z[1][$i][0];
  640.              $nested_el['code']=10000+$num;
  641.              $num++;
  642.          
  643.              $nested_els[]=$nested_el;       
  644.           }
  645.           //echo print_r($nested_els);
  646.           //----------------------------------
  647.           $tmps4='';
  648.           $zsta=0;
  649.          
  650.           for ($i=0; $i<count($nested_els); $i++) {
  651.        
  652.              $zfin= $nested_els[$i]['offset'];
  653.          
  654.              $tmps4.=substr($tmps,$zsta,$zfin-$zsta).
  655.              '[ZZ-'.$nested_els[$i]['code'].'-ZZ]';
  656.          
  657.              $zsta=$zfin+$nested_els[$i]['length'];
  658.           }
  659.           //----------------------------------
  660.           $tmps4.=substr($tmps,$zsta);
  661.    
  662.           do {}
  663.              while( $this->zelem_iter( $nested_els, $tmps4));  
  664.           //----------------------------------
  665.           $nested_elss[]=$nested_els;
  666.          
  667.           $tmps=$tmps4;  
  668.           $found=(count($nested_els)>0);
  669.          
  670.        } while ($found);
  671.        
  672.        //$zstyles=array();
  673.        //-----------------------
  674.        $this->zstyles=file(Baser::STFILE);
  675.        
  676.        $stinf=array();
  677.        
  678.        for ($i=0;$i<count($this->zstyles);$i++) {
  679.        
  680.           $stcode = substr($this->zstyles[$i],strpos($this->zstyles[$i],'::')+2);
  681.           $stcode = substr($stcode,0, strlen($stcode)-2);
  682.          
  683.           $stinf[$stcode]=substr($this->zstyles[$i],0, strpos($this->zstyles[$i],'::'));
  684.          
  685.        }
  686.        /*$uu=array_unique($stcode);
  687.        sort($uu);
  688.        echo print_r($uu);*/
  689.        //-----------------------
  690.        for ($i=0; $i<count($nested_elss); $i++)
  691.           for ($j=0; $j<count($nested_elss[$i]); $j++) {
  692.          
  693.              sort($nested_elss[$i][$j]['format']);                 
  694.              $zstyle=implode('',$nested_elss[$i][$j]['format']);
  695.              
  696.              $zkey=array_search($zstyle,$stinf);
  697.              
  698.              if (($zkey!==false) && ($nested_elss[$i][$j]['inbase']!=''))        
  699.                 $nested_elss[$i][$j]['stcode']=$zkey;
  700.              else
  701.                 $nested_elss[$i][$j]['stcode']='';
  702.      
  703.           }
  704.          
  705.        //echo print_r($this->zstyles);
  706.        //echo print_r($nested_elss);
  707.        //echo $tmps;
  708.        //---------------------------------------------------------------
  709.        //                    assemble doc
  710.        //---------------------------------------------------------------
  711.        for ($i=count($nested_elss)-1;$i>=0;$i--) {
  712.           for ($j=0; $j<count($nested_elss[$i]); $j++) {
  713.          
  714.              $zstr3 = ($nested_elss[$i][$j]['stcode']!='') ?
  715.                 '<span class="'.$nested_elss[$i][$j]['stcode'].'">' : '';
  716.              $zstr4 = ($nested_elss[$i][$j]['stcode']!='') ? '</span>' : '';
  717.              
  718.              $tmps=str_replace('[ZZ-'.$nested_elss[$i][$j]['code'].'-ZZ]',           
  719.                 $zstr3.$nested_elss[$i][$j]['inbase'].$zstr4,$tmps);
  720.           }
  721.        }
  722.        
  723.        $tmps= preg_replace(
  724.           '/\[(\s*\/?\s*(br|hr|p|a|img|table|tr|td|th|tbody|div|li|ul)(\b[^\]]*|\s*))\]/ims',
  725.           '<\1>',$tmps);
  726.        echo $tmps;
  727.  
  728.  
  729.     }
  730.     //--------------------------------------------------old
  731.     private function repl($zinf, $zinf3, $tmps, $debug=false) {
  732.          
  733.        $cnt=0;
  734.        $iter=0;
  735.        do {
  736.              if (($debug) || ($this->debugmode)) {
  737.                 preg_match_all($zinf,$tmps,$out,PREG_SET_ORDER);
  738.                 echo "\r\n--------------------------------------------\r\n".
  739.                 $zinf.' - '.$iter.
  740.                 "\r\n--------------------------------------------\r\n";
  741.                 echo print_r($out);
  742.              }           
  743.              $tmps=preg_replace($zinf, $zinf3, $tmps,-1,$cnt);
  744.              $iter++;
  745.              
  746.        } while($cnt>0);
  747.  
  748.        return  $tmps;
  749.          
  750.     }
  751.  
  752.     //--------------------------------------------------old
  753.     public function get_sitecont($inaddr) {
  754.  
  755.        //-----------------------------------
  756.        $this->prep_structs();
  757.        //-----------------------------------
  758.    
  759.        $tmps=file_get_contents(Baser::ZADDR.'/'.$inaddr);
  760.        
  761.        $stss='<td id="leftcontent">';
  762.        
  763.        $sta=stripos($tmps,$stss);
  764.        $fin=stripos($tmps,'<td id="rightmenu">',$sta);
  765.        
  766.        $tmps=substr($tmps,$sta+strlen($stss),$fin-$sta-strlen($stss));
  767.        
  768.        $fin=strrpos($tmps,'</td>');
  769.        $tmps=substr($tmps,0,$fin);
  770.        
  771.        //$this->debugmode=true;
  772.        //header('Content-type:text/plain');
  773.        //--------------------------------------------------------
  774.           $tmps=$this->repl('/<\s*(strong|b|font|p|span)(\s+[^>]*>|>)\s*<\/[^>]*\1[^>]*>/ims','',$tmps);
  775.           //echo $cnt.'</br>';
  776.        
  777.        //--------------------------------------------------------      
  778.        
  779.        $tmps=$this->repl('/(<\s*img[^>]*src=(["\']))(?!https?:)\/?([^\2>]*)(\2[^>]*>)/ims',
  780.           '$1'.Baser::ZADDR.'/$3$4',$tmps);
  781.          
  782.  
  783.        $tmps=$this->repl('/(<\s*a[^>]*href=(["\']))(?!https?:)\/?([^\2>:]*)(\2[^>]*>)/ims',
  784.           '$1'.Baser::ZADDR.'/$3$4',$tmps);
  785.          
  786.        //--------------------------------------------------------
  787.        
  788.        $tmps=$this->repl('/<\s*font[^>]*color="#ffff99"[^>]*>(.*?)<\/\s*font\s*>/ims',
  789.        '<span class="zbright">$1</span>',$tmps);
  790.        
  791.        $tmps=$this->repl('/<\s*font[^>]*color="#ff6600"[^>]*>(.*?)<\/\s*font\s*>/ims',
  792.        '<span class="zbright3">$1</span>',$tmps);
  793.        
  794.        $tmps=$this->repl('/<b>\s*<\s*font[^>]*color="#ff0000"[^>]*>(.*?)<\/\s*font\s*>\s*<\/b>/ims',
  795.        '<span class="zbright4b">$1</span>',$tmps);
  796.        
  797.        
  798.        $tmps=$this->repl('/<\s*font[^>]*color="#ff0000"[^>]*>(.*?)<\/\s*font\s*>/ims',
  799.        '<span class="zbright4">$1</span>',$tmps);
  800.        
  801.         $tmps=$this->repl('/<\s*font[^>]*color="#993366"[^>]*>(.*?)<\/\s*font\s*>/ims',
  802.        '<span class="zbright5">$1</span>',$tmps);
  803.        
  804.        //--------------------------------------------------------
  805.        
  806.         $tmps=$this->repl('/<\s*font[^>]*size="1"[^>]*>(.*?)<\/\s*font\s*>/ims',
  807.        '<span class="zsmallxx">$1</span>',$tmps);
  808.        
  809.         $tmps=$this->repl('/<\s*font[^>]*size="[45]"[^>]*>(.*?)<\/\s*font\s*>/ims',
  810.        '<span class="zbigg">$1</span>',$tmps);
  811.        
  812.        $tmps=$this->repl('/<\s*font[^>]*color="#c0c0c0"[^>]*>(.*?)<\/s*font\s*>/ims',
  813.        '<span class="zstd">$1</span>',$tmps);
  814.        
  815.        $tmps=$this->repl('/<\s*\/?\s*font[^>]*>/i','',$tmps);
  816.        //----------------------------------------------------
  817.        
  818.        //----------------------------------------------------
  819.        /*preg_match_all('/<strong>(?>.*?(?<!<\/strong>)<\/span>)/ims',$tmps,$out,PREG_SET_ORDER);*/
  820.        
  821.        //header('Content-type:text/plain');
  822.        //echo print_r($out);
  823.        //echo $cnt;
  824.        //die;
  825.        //----------------------------------------------------
  826.        //$tmps=preg_replace(
  827.        //'/<(strong|b)>(\s*<[^>]*span[^>]*>[^<>]*<\/\s*span\s*>)<\/\1\>/ims',
  828.        //'$2',$tmps);
  829.        
  830.        //$tmps=preg_replace('/<[^>]*(strong|b)[^>]*>\s*<\/[^>]*\1[^>]*>/ims','',$tmps);
  831.        
  832.        echo $tmps;
  833.     }
  834.    
  835.     //--------------------------------------------------
  836.    
  837.     public function resizeImage($src, $area, $res) {
  838.    
  839.        list($w,$h)=getimagesize($src);
  840.        
  841.        /*$koef=$w*$h/$area;
  842.        
  843.        $koef=sqrt($koef);
  844.        
  845.        $nw=$w/$koef;
  846.        $nh=$h/$koef;*/
  847.        
  848.        $nh=200;
  849.        $nw=$w*($nh/$h);
  850.        
  851.        $thumb=imagecreatetruecolor($nw,$nh);
  852.        
  853.        $source=imagecreatefromjpeg($src);
  854.        //imagecopyresized($thumb,$source,0,0,0,0,$nw,$nh,$w,$h);
  855.        imagecopyresampled($thumb,$source,0,0,0,0,$nw,$nh,$w,$h);
  856.        
  857.        imagejpeg($thumb,$res,100);
  858.        
  859.        imagedestroy($source);
  860.        imagedestroy($thumb);
  861.     }
  862.    
  863.     //--------------------------------------------------
  864.     public function resizeall($area) {
  865.    
  866.        $dir=opendir('pic');
  867.    
  868.        while ($name=readdir($dir)) {
  869.           if (($name!='.') && ($name!='..')) {
  870.      
  871.              if (is_file('pic/'.$name)) {
  872.                 $this->resizeImage('pic/'.$name,$area,'small/'.$name);
  873.              }
  874.  
  875.           }
  876.        }
  877.        closedir($dir);
  878.     }
  879.     //--------------------------------------------------
  880.     public function load_parsed() {
  881.    
  882.        $inf=file('../parsed.txt');
  883.        for ($i=0;$i<count($inf);$i++) {
  884.           $this->insertPic($inf[$i]);
  885.        }
  886.        
  887.     }
  888.     //--------------------------------------------------
  889.    
  890.    
  891.     //--------------------------------------------------
  892.     public function insertReg($inreg) {
  893.    
  894.        if (!$this->connected) return;
  895.        $inreg8=addslashes($inreg);
  896.        $this->insertQuery('insert into regs(%fields%) values(%values%)',array('reg_name'),array("'$inreg8'"));
  897.        
  898.        return $this->actual_query;
  899.     }
  900.     //--------------------------------------------------
  901.     public function insertPic($inpic) {
  902.    
  903.        if (!$this->connected) return;
  904.      
  905.       if (strpos($inpic,'.')===false) $inpic.='.jpg';
  906.       $pic_ext=strtolower(array_pop(explode(".",$inpic)));
  907.      
  908.       $this->insertQuery('insert into pics(%fields%) values(%values%)',
  909.       array('src_address','ext'), array('\''.urlencode($inpic).'\'','\''.$pic_ext.'\''));
  910.      
  911.       if ($this->is_error()) return; //FTG
  912.      
  913.       $pic_num=($this->getSingle('select max(id) from pics'));
  914.       if ($this->is_error()) return;
  915.      
  916.      
  917.       $ss=file_get_contents($inpic);
  918.       if ($ss==false) {
  919.          $this->set_error('error loading from url');
  920.          return;
  921.          }
  922.       //$ss=http_get(urlencode($inpic));
  923.       file_put_contents('pic/'.$pic_num.'.'.$pic_ext,$ss);
  924.       $this->resizeImage('pic/'.$pic_num.'.'.$pic_ext,300000,'small/'.$pic_num.'.'.$pic_ext);
  925.      
  926.      
  927.      
  928.     }
  929.    
  930. }
  931.  
  932.  
  933.  
  934. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement