Advertisement
terorama

parser / statusparse.inc.php

Aug 21st, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.16 KB | None | 0 0
  1. <?PHP
  2.  
  3. //-----------------------------------------------------------------
  4. //          status object
  5. //-----------------------------------------------------------------
  6. class StatusParse {
  7.  
  8.    const LOGFILE='../parser.txt';
  9.    const PARSED='../parsed.txt';
  10.    
  11.    public $logfile;  //  файл трассировки
  12.    public $resfile;  //  файл результатов парсинга
  13.  
  14.    protected $logging;   // трассировка включена
  15.    protected $f_handle;
  16.    
  17.    public $regarr=Array(); // массив регулярных выражений для разбора сайта      
  18.    public $base_url;       //  стартовый url
  19.    public $formatstring;   // строка для форматирования результатов        
  20.    public $formatted;    //форматировать результаты парсинга на выходе
  21.    public $json_format;  //возвращать результаты парсинга в формате json
  22.    public $show_query;       
  23.    public $initquery;              
  24.    public $step=0;       //  шаг трассировки
  25.    
  26.    public $n_redirects=0;  // количество произведенных редиректов страницы
  27.    
  28.    public $urls=Array();   // список найденных адресов страниц
  29.    public $elems=Array();  // список найденных элементов
  30.    
  31.    //-----------------------------
  32.    function __construct($logging=false) {
  33.    
  34.       //-------------------установка флага включения трассировки
  35.       $this->logging=$logging;
  36.    
  37.       //--------------------указываем имя файла трассировки
  38.       $p=strrpos(StatusParse::LOGFILE,'/');
  39.       $zfile=substr(StatusParse::LOGFILE,$p+1);
  40.       $zdir=substr(StatusParse::LOGFILE,0,$p+1);
  41.      
  42.       $zz=explode('.',$zfile);
  43.      
  44.       $this->logfile=StatusParse::LOGFILE;
  45.              
  46.       //----------указываем имя файла, в который будут складываться результаты парсинга
  47.      
  48.       $p=strrpos(StatusParse::PARSED,'/');
  49.       $zfile=substr(StatusParse::PARSED,$p+1);
  50.       $zdir=substr(StatusParse::PARSED,0,$p+1);
  51.      
  52.       $zz=explode('.',$zfile);
  53.      
  54.       $this->resfile=$zdir.array_shift($zz).'_'.
  55.            date('dmYHis').rand(200,8000).'.'.array_shift($zz);
  56.      
  57.       $fhandle=fopen($this->resfile,'wb');
  58.       fclose($fhandle);
  59.    
  60.    }
  61.    //-----------------------------запись строки в файл трассировки
  62.    public function logt($instr) {
  63.    
  64.       if (!$this->logging) return;
  65.      
  66.       if (file_exists($this->logfile))
  67.          $this->f_handle=fopen($this->logfile,'ab');
  68.       else
  69.          $this->f_handle=fopen($this->logfile,'wb');
  70.          
  71.       fwrite($this->f_handle,date('d.m.Y H:i:s').' '.$instr."\r\n");
  72.      
  73.       fclose($this->f_handle);  
  74.    }
  75.    //-----------------------------запись строки в файл результатов парсинга
  76.    public function log_res($instr) {
  77.  
  78.       $fhandle=fopen($this->resfile,'ab');
  79.       fwrite($fhandle,$instr."\r\n");
  80.       fclose($fhandle);  
  81.    }
  82.    //-----------------------------
  83.    
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement