Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*function __autoload($class_name) {
- require $classname.'inc.php';
- }*/
- if ($_SERVER["SERVER_NAME"]!='localhost')
- require 'autoinfo.inc.php';
- class Baser extends AutoInfo {
- const LOGFILE='../baserlogz.txt';
- const STFILE='stylmoves4.txt';
- const ZADDR='http://house-of-dance.ru';
- const YADDR='/learn/picport/req4.php?reqg=getzsite&pgn=';
- protected $db_host;
- protected $db_name;
- protected $db_login;
- protected $db_password;
- protected $db_conn;
- protected $connected;
- protected $actual_query;
- protected $actual_position;
- protected $logging;
- public $logfile;
- protected $f_handle;
- public $errornum;
- public $errorname;
- public $errormessage;
- //---------------------------
- private $debugmode=false;
- private $zpages=array (
- 0=>'',
- 1=>'contacts',
- 2=>'rotations',
- 3=>'teachers',
- 4=>'prices',
- 5=>'news',
- 6=>'gallerynew',
- 7=>'gallery/65',
- 8=>'collectives',
- 9=>'arenda'
- );
- //------------------------
- private $zcommon_replaces=array (
- 0=> array ('s'=>'/<\s*(font|b|strong)[^>]*>/ims',
- 't'=>'', 'iter'=>true
- ),
- 1=> array ('s'=>'',
- 't'=>'', 'iter'=>true)
- );
- //------------------------
- private $zstyles=array();
- //--------------------------------------------------
- function __construct($inmyname, $inhost,$inlogin, $inpass,$inname, $logging=false) {
- parent::__construct($inmyname);
- $this->init_logfile();
- $this->db_host=$inhost;
- $this->db_name=$inname;
- $this->db_login=$inlogin;
- $this->db_password=$inpass;
- $this->logging=$logging;
- if ($this->connect()!=0)
- $this->set_error($this->errormessage);
- else
- $this->set_ok();
- }
- //--------------------------------------------------
- function __destruct() {
- $this->disconnect();
- }
- //--------------------------------------------------
- public function init_logfile() {
- if (isset($_SESSION['logfile'])) {
- $this->logfile=$_SESSION['logfile'];
- } else {
- $p=strrpos(Baser::LOGFILE,'/');
- $zfile=substr(Baser::LOGFILE,$p+1);
- $zdir=substr(Baser::LOGFILE,0,$p+1);
- $zz=explode('.',$zfile);
- $this->logfile=$zdir.array_shift($zz).'_'.
- date('dmYHis').'_'.rand(200,8000).'.'.array_shift($zz);
- $_SESSION['logfile']=$this->logfile;
- }
- }
- //--------------------------------------------------
- public function prep_structs() {
- for ($i=0; $i<count($this->zpages); $i++) {
- $zrepl_elem=array();
- $zrepl_elem['num']=$i;
- $zrepl_elem['pg']=$this->zpages[$i];
- $zrepl_elem['repls']=array_merge($this->zcommon_replaces);
- $this->zrepl_arr[$this->zpages[$i]]=$zrepl_elem;
- }
- }
- //--------------------------------------------------
- public function connect() {
- $this->db_conn=mysql_connect($this->db_host, $this->db_login, $this->db_password);
- mysql_select_db($this->db_name);
- if (mysql_errno()<>0) {
- $this->errornum=mysql_errno();
- $this->errorname=mysql_error();
- $this->errormessage=$this->errornum.":".$this->errorname;
- $this->connected=false;
- return -1;
- }
- else {
- $this->connected=true;
- return 0;
- }
- }
- //--------------------------------------------------
- public function disconnect() {
- if (!$this->connected) return;
- mysql_close($this->db_conn);
- }
- //--------------------------------------------------
- protected function logt($instr) {
- if (!$this->logging) return;
- if (file_exists($this->logfile))
- $this->f_handle=fopen($this->logfile,'ab');
- else
- $this->f_handle=fopen($this->logfile,'wb');
- // fwrite($this->f_handle, $instr."\r\n", strlen($instr)+2);
- fwrite($this->f_handle, date('d.m.Y H:i:s').' '.$instr."\r\n");
- fclose($this->f_handle);
- }
- //--------------------------------------------------
- protected function checksqlerror() {
- if (mysql_errno()>0) {
- $this->errornum=mysql_errno();
- $this->errorname=mysql_error();
- $this->errormessage=$this->errornum.':'.$this->errorname;
- $this->set_error($this->errormessage);
- } else {
- $this->set_ok();
- }
- }
- //--------------------------------------------------
- public function insertQuery($insql,$fields,$values) {
- if (!$this->connected) return;
- $sql=str_replace('%fields%',implode(',',$fields),$insql);
- $sql=str_replace('%values%',implode(',',$values),$sql);
- $this->actual_query=$sql;
- $this->logt($sql);
- mysql_query($sql);
- $this->checksqlerror();
- $this->logt($this->show_status());
- }
- //--------------------------------------------------
- public function execQuery($insql) {
- if (!$this->connected) return;
- $this->actual_query=$insql;
- $this->logt($insql);
- mysql_query($insql);
- $this->checksqlerror();
- $this->logt($this->show_status());
- return $this->actual_query;
- }
- //--------------------------------------------------
- public function getSingle($insql) {
- if (!$this->connected) return;
- $this->actual_query=$insql;
- $this->logt($insql);
- $result=mysql_query($insql);
- $this->checksqlerror();
- $this->logt($this->show_status());
- if ($this->is_error()) return;
- $row=mysql_fetch_array($result,MYSQL_NUM);
- return $row[0];
- }
- //--------------------------------------------------
- public function getQuery($insql,$start,$num, $isassoc=false) {
- if (!$this->connected) return;
- $this->actual_query=$insql;
- $this->logt($insql);
- $result=mysql_query($insql);
- $this->checksqlerror();
- $this->logt($this->show_status());
- if ($this->is_error()) return;
- $nfields=mysql_num_fields($result);
- $n_items=1;
- if ($n_items<$start) {
- while (($row=mysql_fetch_array($result,MYSQL_NUM)) && ($n_items<$start)) {
- $n_items++;
- }}
- $items=array();
- if ($isassoc) {
- while (($row=mysql_fetch_array($result,MYSQL_ASSOC)) && ($n_items<($start+$num))) {
- $n_items++;
- $item=array();
- foreach ($row as $key=>$value) {
- $item[$key]=$value;
- }
- $items[]=$item;
- }
- } else {
- while (($row=mysql_fetch_array($result,MYSQL_NUM)) && ($n_items<($start+$num))) {
- $n_items++;
- $item=array();
- for ($i=0;$i<$nfields;$i++) {
- $item[]=$row[$i];
- }
- $items[]=$item;
- }
- }
- $this->actual_position=$n_items;
- return $items;
- }
- //--------------------------------------------------
- public function showRegs() {
- $items=$this->getQuery('select reg_name from regs order by id desc',1,300,true);
- if (count($items)==0) return;
- for ($i=0;$i<count($items);$i++) {
- $items[$i]["reg_name"]=htmlspecialchars($items[$i]["reg_name"]);
- }
- return json_encode($items);
- }
- //--------------------------------------------------
- public function showDir($inpath) {
- //----------------------------
- function cmp($a,$b) {
- if ($a["isdir"]) {
- if ($b["isdir"]) {
- if ($a["name"]==$b["name"]) return 0;
- return ($a["name"]<$b["name"]) ? -1 : 1;
- }
- else
- return -1;
- }
- else {
- if ($b["isdir"]) {
- return 1;
- }
- else {
- if ($a["name"]==$b["name"]) return 0;
- return ($a["name"]<$b["name"]) ? -1 : 1;
- }
- }
- }
- //----------------------------
- $dir=opendir($inpath);
- $files_m=array();
- while ($name=readdir($dir)) {
- if (($name!='.') && ($name!='..')) {
- $files_item=array();
- $files_item["name"]=$name;
- $files_item["full"]=$inpath.$name;
- $files_item["isdir"]=is_dir($inpath.$name);
- if (is_file($inpath.$name)) {
- $files_item["filesize"]=filesize($inpath.$name);
- $files_item["fileatime"]=date('d.m.Y',fileatime($inpath.$name));
- $files_item["filemtime"]=date('d.m.Y',filemtime($inpath.$name));
- $files_item["filectime"]=date('d.m.Y',filectime($inpath.$name));
- }
- $files_m[]=$files_item;
- }
- }
- closedir($dir);
- //uasort($files_m,'cmp');
- return json_encode($files_m);
- }
- //--------------------------------------------------
- public function showPics($reztype,$num=5,$cycle=false) {
- //----------------------------------------------
- function ispic($var) {
- if (@file_get_contents("small/${var[0]}.${var[1]}")==false)
- return false;
- else
- return true;
- }
- //----------------------------------------------
- $items=array();
- $tmp_num=$num;
- if (isset($_SESSION["startpic"]))
- $startpic=$_SESSION["startpic"];
- else
- $startpic=1;
- do {
- $itz=$this->getQuery('select id, ext from pics order by id',$startpic,$tmp_num);
- $startpic=$this->actual_position;
- //if (count($itz)==0) return;
- $cnt=(count($itz)==$tmp_num);
- //-------------------
- if (($cycle==true) && (!$cnt)) {
- $cnt=true;
- $startpic=1;
- }
- //-------------------
- $itz=array_filter($itz,"ispic");
- $items=array_merge($items,$itz);
- $tmp_num=$num-count($items);
- }
- while (($cnt) && (count($items)<$num));
- $_SESSION["startpic"]=$startpic;
- //---------------------------------------------xml output
- if ($reztype=='xml') {
- $dom= new DOMDocument();
- $root=$dom->appendChild($dom->createElement('pics'));
- foreach ($items as $item) {
- $pic=$dom->createElement('pic');
- $big=$dom->createElement('big');
- $small=$dom->createElement('small');
- $big->appendChild($dom->createTextNode("pic/{$item[0]}.{$item[1]}"));
- $small->appendChild($dom->createTextNode("small/{$item[0]}.{$item[1]}"));
- $pic->appendChild($big);
- $pic->appendChild($small);
- $root->appendChild($pic);
- }
- return $dom->saveXML();
- }
- //--------------------------------------------json output
- if ($reztype=='json') {
- $items_out=array();
- foreach ($items as $item) {
- //if (@file_get_contents("small/${item[0]}.${item[1]}")==false)
- // continue;
- $item_out=array();
- $item_out['big']="pic/${item[0]}.${item[1]}";
- $item_out['small']="small/${item[0]}.${item[1]}";
- $items_out[]=$item_out;
- }
- return json_encode($items_out);
- }
- }
- //--------------------------------------------------
- public function showparsed($num=5) {
- $inf=file('../parsed4.txt');
- if (isset($_SESSION["startpic"]))
- $startpic=$_SESSION["startpic"];
- else
- $startpic=1;
- $items_out=array();
- for ($i=$startpic-1;$i<$startpic-1+$num;$i++) {
- $item_out=array();
- $item_out['big']=$inf[$i];
- $item_out['small']=$inf[$i];
- $items_out[]=$item_out;
- }
- $_SESSION["startpic"]=$startpic+$num;
- return json_encode($items_out);
- }
- //--------------------------------------------------old
- private function parse_go($intmps) {
- $dom = new domDocument('1.0','utf-8');
- //$dom->encoding='utf-8';
- @$dom->loadHTML($intmps);
- $inel = $dom->getElementsByTagName('font');
- $nodes=array();
- //foreach ($inel as $node) {
- //$nodes[]=$node;
- //}
- for ($i=0; $i<$inel->length; $i++) {
- $nodes[]=array(
- //'tvalue'=>$inel->item($i)->textContent,
- 'tg'=>$inel->item($i)->nodeName,
- 'face'=>$inel->item($i)->getAttribute('face'),
- 'color'=>$inel->item($i)->getAttribute('color'),
- 'size'=>$inel->item($i)->getAttribute('size'),
- 'value'=>$inel->item($i)->nodeValue);
- }
- echo print_r($nodes);
- unset($dom);
- }
- //--------------------------------------------------
- public function get_siteall() {
- if ($_SESSION["npage"]<count($this->zpages)) {
- $this->logt('page: '.$_SESSION["npage"].' '.
- $this->zpages[$_SESSION["npage"]]);
- if (isset($_SESSION["zstyles"]))
- $this->zstyles=$_SESSION["zstyles"];
- $this->get_sitecont_new($this->zpages[$_SESSION["npage"]]);
- $this->logt(print_r($this->zstyles,true));
- $_SESSION["zstyles"]=$this->zstyles;
- header('Location: '.$_SERVER["PHP_SELF"].'?reqg=getzsite');
- }
- else {
- if (isset($_SESSION["zstyles"]))
- $this->zstyles=$_SESSION["zstyles"];
- $fhandle=fopen(Baser::STFILE,'wb');
- for ($i=0; $i<count($this->zstyles); $i++) {
- fwrite($fhandle,$this->zstyles[$i]."::\r\n");
- }
- fclose($fhandle);
- }
- }
- //--------------------------------------------------
- // expand parsed element
- //--------------------------------------------------
- private function zelem_iter(&$elems,&$tmps4) {
- $found=false;
- for ($i=0;$i<count($elems);$i++) {
- $z=array();
- preg_match('/((<\s*(font|b|strong|h1|h2|h3|h4|span)(\b[^>]*>|>))\s*)'.
- '\[ZZ-'.$elems[$i]['code'].'-ZZ\]'.
- '(\s*<\s*\/\s*(\3)[^>]*>)/ims',
- $tmps4, $z);
- if (count($z)>0) {
- $elems[$i]['format'][]=$z[2];
- $elems[$i]['base']=$z[1].$elems[$i]['base'].$z[5];
- $elems[$i]['length']+=strlen($z[1])+strlen($z[5]);
- $elems[$i]['offset']-=strlen($z[1]);
- $found=true;
- $tmps4=str_replace($z[1].'[ZZ-'.$elems[$i]['code'].'-ZZ]'.$z[5],
- '[ZZ-'.$elems[$i]['code'].'-ZZ]',$tmps4);
- }
- }
- return $found;
- }
- //----------------------------------------------------------
- // parse html page
- //----------------------------------------------------------
- public function get_sitecont_new($inaddr) {
- $this->prep_structs();
- if (!file_exists('housepages'))
- mkdir('housepages');
- $zaddr=str_replace('/','_',$inaddr);
- $zaddr=($zaddr=='' ? 'zstbase' : substr($zaddr,0,strlen($zaddr)-1));
- $tmpf='housepages/'.$zaddr.'.txt';
- if ((file_exists($tmpf)) && (time()-filemtime($tmpf)<3600) && (filesize($tmpf)>100))
- {
- //echo time()-filemtime($tmpf);
- $tmps=file_get_contents($tmpf);
- }
- else
- {
- $opts= array (
- 'http'=>array (
- 'method'=>'GET',
- 'header'=>"Accept: text/html\r\n".
- "Accept-Charset: windows-1251,utf-8\r\n".
- "Accept-Language: ru-RU,en-US,en\r\n".
- "Cache-Control: max-age=0\r\n".
- "Connection: keep-alive\r\n".
- "Cookie: BITRIX_SM_LOGIN=dancadmin\r\n".
- "User-Agent: Mozilla/5.0\r\n"));
- $context=stream_context_create($opts);
- $tmps=file_get_contents(Baser::ZADDR.'/'.$inaddr, false, $context);
- if ($tmps===false) {
- if (file_exists($tmpf))
- $tmps=file_get_contents($tmpf);
- else
- $tmps='failed open remote site '.date('d.m.Y H:I:s', time());
- }
- /*if (!file_exists($tmpf)) {
- $tmphh=fopen($tmpf,'w');
- fclose($tmphh);
- }*/
- file_put_contents($tmpf,$tmps);
- }
- $stss='<td id="leftcontent">';
- $sta=stripos($tmps,$stss);
- $fin=stripos($tmps,'<td id="rightmenu">',$sta);
- $tmps=substr($tmps,$sta+strlen($stss),$fin-$sta-strlen($stss));
- $fin=strrpos($tmps,'</td>');
- $tmps=substr($tmps,0,$fin);
- //header('Content-type: text/plain; charset=utf-8');
- $tmps=iconv('windows-1251','UTF-8',$tmps);
- $tmps='<div id="incl">'.$tmps.'</div>';
- $tmps=preg_replace('/(<\s*img[^>]*src=(["\']))(?!https?:)\/?([^\2>]*)(\2[^>]*>)/ims',
- '$1'.Baser::ZADDR.'/$3$4',$tmps);
- $tmps=preg_replace('/(<\s*a[^>]*href=(["\']))(?!https?:)\/?([^\2>:]*)(\2([^>]*>))/ims',
- '$1#$2 rel="$3" class="ajaxlink" $5',$tmps);
- $tmps=preg_replace('/(<\s*a[^>]*href=(["\']))http:\/\/www.house-of-dance.ru\/([^\2>:]*)(\2([^>]*>))/ims',
- '$1#$2 rel="$3" class="ajaxlink" $5',$tmps);
- //$tmps='<meta http-equiv="Content-type" content="text/html; charset=utf-8" />'.$tmps;
- //$tmps='<font> <strong> <font> hjhj g</font> </strong></font>'.$tmps;
- //echo $tmps;
- //$this->parse_go($tmps);
- //-------------------------------------------------
- $tmps= preg_replace('/<(\s*\/?\s*(br|hr|p|a|img|table|tr|td|th|tbody|div|li|ul)(\b[^>]*|\s*))>/ims','[\1]',
- $tmps);
- $found=false;
- $nested_elss=array();
- $num=0;
- //------------------------------------------------------
- // parse doc
- //------------------------------------------------------
- do {
- $z=array();
- preg_match_all('/(<\s*(font|b|strong|h1|h2|h3|h4|span)(\b[^>]*>|>))([^<>]*)<\s*\/\s*(\2)[^>]*>/ims',
- $tmps,$z,
- PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER);
- //----------------------------------
- $nested_els=array();
- for ($i=0; $i<count($z[0]); $i++) {
- $nested_el=array();
- $nested_el['base']=$z[0][$i][0];
- $nested_el['inbase']=$z[4][$i][0];
- $nested_el['length']=strlen($z[0][$i][0]);
- $nested_el['offset']=$z[0][$i][1];
- $nested_el['format'][]=$z[1][$i][0];
- $nested_el['code']=10000+$num;
- $num++;
- $nested_els[]=$nested_el;
- }
- //echo print_r($nested_els);
- //----------------------------------
- $tmps4='';
- $zsta=0;
- for ($i=0; $i<count($nested_els); $i++) {
- $zfin= $nested_els[$i]['offset'];
- $tmps4.=substr($tmps,$zsta,$zfin-$zsta).
- '[ZZ-'.$nested_els[$i]['code'].'-ZZ]';
- $zsta=$zfin+$nested_els[$i]['length'];
- }
- //----------------------------------
- $tmps4.=substr($tmps,$zsta);
- do {}
- while( $this->zelem_iter( $nested_els, $tmps4));
- //----------------------------------
- $nested_elss[]=$nested_els;
- $tmps=$tmps4;
- $found=(count($nested_els)>0);
- } while ($found);
- //$zstyles=array();
- //-----------------------
- $this->zstyles=file(Baser::STFILE);
- $stinf=array();
- for ($i=0;$i<count($this->zstyles);$i++) {
- $stcode = substr($this->zstyles[$i],strpos($this->zstyles[$i],'::')+2);
- $stcode = substr($stcode,0, strlen($stcode)-2);
- $stinf[$stcode]=substr($this->zstyles[$i],0, strpos($this->zstyles[$i],'::'));
- }
- /*$uu=array_unique($stcode);
- sort($uu);
- echo print_r($uu);*/
- //-----------------------
- for ($i=0; $i<count($nested_elss); $i++)
- for ($j=0; $j<count($nested_elss[$i]); $j++) {
- sort($nested_elss[$i][$j]['format']);
- $zstyle=implode('',$nested_elss[$i][$j]['format']);
- $zkey=array_search($zstyle,$stinf);
- if (($zkey!==false) && ($nested_elss[$i][$j]['inbase']!=''))
- $nested_elss[$i][$j]['stcode']=$zkey;
- else
- $nested_elss[$i][$j]['stcode']='';
- }
- //echo print_r($this->zstyles);
- //echo print_r($nested_elss);
- //echo $tmps;
- //---------------------------------------------------------------
- // assemble doc
- //---------------------------------------------------------------
- for ($i=count($nested_elss)-1;$i>=0;$i--) {
- for ($j=0; $j<count($nested_elss[$i]); $j++) {
- $zstr3 = ($nested_elss[$i][$j]['stcode']!='') ?
- '<span class="'.$nested_elss[$i][$j]['stcode'].'">' : '';
- $zstr4 = ($nested_elss[$i][$j]['stcode']!='') ? '</span>' : '';
- $tmps=str_replace('[ZZ-'.$nested_elss[$i][$j]['code'].'-ZZ]',
- $zstr3.$nested_elss[$i][$j]['inbase'].$zstr4,$tmps);
- }
- }
- $tmps= preg_replace(
- '/\[(\s*\/?\s*(br|hr|p|a|img|table|tr|td|th|tbody|div|li|ul)(\b[^\]]*|\s*))\]/ims',
- '<\1>',$tmps);
- echo $tmps;
- }
- //--------------------------------------------------old
- private function repl($zinf, $zinf3, $tmps, $debug=false) {
- $cnt=0;
- $iter=0;
- do {
- if (($debug) || ($this->debugmode)) {
- preg_match_all($zinf,$tmps,$out,PREG_SET_ORDER);
- echo "\r\n--------------------------------------------\r\n".
- $zinf.' - '.$iter.
- "\r\n--------------------------------------------\r\n";
- echo print_r($out);
- }
- $tmps=preg_replace($zinf, $zinf3, $tmps,-1,$cnt);
- $iter++;
- } while($cnt>0);
- return $tmps;
- }
- //--------------------------------------------------old
- public function get_sitecont($inaddr) {
- //-----------------------------------
- $this->prep_structs();
- //-----------------------------------
- $tmps=file_get_contents(Baser::ZADDR.'/'.$inaddr);
- $stss='<td id="leftcontent">';
- $sta=stripos($tmps,$stss);
- $fin=stripos($tmps,'<td id="rightmenu">',$sta);
- $tmps=substr($tmps,$sta+strlen($stss),$fin-$sta-strlen($stss));
- $fin=strrpos($tmps,'</td>');
- $tmps=substr($tmps,0,$fin);
- //$this->debugmode=true;
- //header('Content-type:text/plain');
- //--------------------------------------------------------
- $tmps=$this->repl('/<\s*(strong|b|font|p|span)(\s+[^>]*>|>)\s*<\/[^>]*\1[^>]*>/ims','',$tmps);
- //echo $cnt.'</br>';
- //--------------------------------------------------------
- $tmps=$this->repl('/(<\s*img[^>]*src=(["\']))(?!https?:)\/?([^\2>]*)(\2[^>]*>)/ims',
- '$1'.Baser::ZADDR.'/$3$4',$tmps);
- $tmps=$this->repl('/(<\s*a[^>]*href=(["\']))(?!https?:)\/?([^\2>:]*)(\2[^>]*>)/ims',
- '$1'.Baser::ZADDR.'/$3$4',$tmps);
- //--------------------------------------------------------
- $tmps=$this->repl('/<\s*font[^>]*color="#ffff99"[^>]*>(.*?)<\/\s*font\s*>/ims',
- '<span class="zbright">$1</span>',$tmps);
- $tmps=$this->repl('/<\s*font[^>]*color="#ff6600"[^>]*>(.*?)<\/\s*font\s*>/ims',
- '<span class="zbright3">$1</span>',$tmps);
- $tmps=$this->repl('/<b>\s*<\s*font[^>]*color="#ff0000"[^>]*>(.*?)<\/\s*font\s*>\s*<\/b>/ims',
- '<span class="zbright4b">$1</span>',$tmps);
- $tmps=$this->repl('/<\s*font[^>]*color="#ff0000"[^>]*>(.*?)<\/\s*font\s*>/ims',
- '<span class="zbright4">$1</span>',$tmps);
- $tmps=$this->repl('/<\s*font[^>]*color="#993366"[^>]*>(.*?)<\/\s*font\s*>/ims',
- '<span class="zbright5">$1</span>',$tmps);
- //--------------------------------------------------------
- $tmps=$this->repl('/<\s*font[^>]*size="1"[^>]*>(.*?)<\/\s*font\s*>/ims',
- '<span class="zsmallxx">$1</span>',$tmps);
- $tmps=$this->repl('/<\s*font[^>]*size="[45]"[^>]*>(.*?)<\/\s*font\s*>/ims',
- '<span class="zbigg">$1</span>',$tmps);
- $tmps=$this->repl('/<\s*font[^>]*color="#c0c0c0"[^>]*>(.*?)<\/s*font\s*>/ims',
- '<span class="zstd">$1</span>',$tmps);
- $tmps=$this->repl('/<\s*\/?\s*font[^>]*>/i','',$tmps);
- //----------------------------------------------------
- //----------------------------------------------------
- /*preg_match_all('/<strong>(?>.*?(?<!<\/strong>)<\/span>)/ims',$tmps,$out,PREG_SET_ORDER);*/
- //header('Content-type:text/plain');
- //echo print_r($out);
- //echo $cnt;
- //die;
- //----------------------------------------------------
- //$tmps=preg_replace(
- //'/<(strong|b)>(\s*<[^>]*span[^>]*>[^<>]*<\/\s*span\s*>)<\/\1\>/ims',
- //'$2',$tmps);
- //$tmps=preg_replace('/<[^>]*(strong|b)[^>]*>\s*<\/[^>]*\1[^>]*>/ims','',$tmps);
- echo $tmps;
- }
- //--------------------------------------------------
- public function resizeImage($src, $area, $res) {
- list($w,$h)=getimagesize($src);
- /*$koef=$w*$h/$area;
- $koef=sqrt($koef);
- $nw=$w/$koef;
- $nh=$h/$koef;*/
- $nh=200;
- $nw=$w*($nh/$h);
- $thumb=imagecreatetruecolor($nw,$nh);
- $source=imagecreatefromjpeg($src);
- //imagecopyresized($thumb,$source,0,0,0,0,$nw,$nh,$w,$h);
- imagecopyresampled($thumb,$source,0,0,0,0,$nw,$nh,$w,$h);
- imagejpeg($thumb,$res,100);
- imagedestroy($source);
- imagedestroy($thumb);
- }
- //--------------------------------------------------
- public function resizeall($area) {
- $dir=opendir('pic');
- while ($name=readdir($dir)) {
- if (($name!='.') && ($name!='..')) {
- if (is_file('pic/'.$name)) {
- $this->resizeImage('pic/'.$name,$area,'small/'.$name);
- }
- }
- }
- closedir($dir);
- }
- //--------------------------------------------------
- public function load_parsed() {
- $inf=file('../parsed.txt');
- for ($i=0;$i<count($inf);$i++) {
- $this->insertPic($inf[$i]);
- }
- }
- //--------------------------------------------------
- //--------------------------------------------------
- public function insertReg($inreg) {
- if (!$this->connected) return;
- $inreg8=addslashes($inreg);
- $this->insertQuery('insert into regs(%fields%) values(%values%)',array('reg_name'),array("'$inreg8'"));
- return $this->actual_query;
- }
- //--------------------------------------------------
- public function insertPic($inpic) {
- if (!$this->connected) return;
- if (strpos($inpic,'.')===false) $inpic.='.jpg';
- $pic_ext=strtolower(array_pop(explode(".",$inpic)));
- $this->insertQuery('insert into pics(%fields%) values(%values%)',
- array('src_address','ext'), array('\''.urlencode($inpic).'\'','\''.$pic_ext.'\''));
- if ($this->is_error()) return; //FTG
- $pic_num=($this->getSingle('select max(id) from pics'));
- if ($this->is_error()) return;
- $ss=file_get_contents($inpic);
- if ($ss==false) {
- $this->set_error('error loading from url');
- return;
- }
- //$ss=http_get(urlencode($inpic));
- file_put_contents('pic/'.$pic_num.'.'.$pic_ext,$ss);
- $this->resizeImage('pic/'.$pic_num.'.'.$pic_ext,300000,'small/'.$pic_num.'.'.$pic_ext);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement