timeline = $timeline; $this->filter_on = $filteron; $this->url = 'http://fanfou.com/'.$id.'/p.'; } function get_daily () { while ($this->flag) { $this->parse_post($this->url.$this->flag); if ( $this->flag ) { $this->flag += 1 ; $this->iHtmlTextIndex = 0 ; } } if ( $this->post_data != '' ) { return "
    \n".$this->post_data."
\n"; } else { return $this->post_data; } } function parse_post ($url) { $resp = $this->fetch_html($url); if ( !$this->is_success( $resp->status ) ) { $this->flag = 0; return false; } $this->iHtmlText = $resp->results; if ( $this->skipToStringInTag('
') == '' ) { $this->flag = 0; return false; } if ( $this->skipToStringInTag('
  1. ') == '' ) { $this->flag = 0; return false; } while ( $this->skipToStringInTag('class="content">') != '' ) { $item_content = $this->skipToStringInTag(''); if ( (!$this->filter_on ? false : $this->filtertrim($item_content)) ) continue; $item_info = $this->getinfo($this->skipToStringInTag('')); if ( is_array($item_info) ) { $item_time = strtotime($item_info[2]); if ( $item_time < $this->timeline ) { $this->flag = 0; break; } else if ( $item_time < ( $this->timeline + 86400 ) ) { $this->post_data .= '
  2. '.$this->trimclass( $item_content ); if ( $item_info[1] == '' ) { $this->post_data .= ' >> '.$item_info[2]."
  3. \n"; } else { $this->post_data .= ' >> '.$item_info[2]."\n"; } } } } return true; } function fetch_html ($url, $headers = "" ) { if ( !isset($url) ) return false; require_once ABSPATH.WPINC.'/class-snoopy.php'; $client = new Snoopy(); if ( is_array($headers) ) { $client->rawheaders = $headers; } @$client->fetch($url); return $client; } function skipToStringInTag ($needle) { $pos = strpos ($this->iHtmlText, $needle, $this->iHtmlTextIndex); if ($pos === false) { return ""; } $top = $pos + strlen($needle); $retvalue = substr ($this->iHtmlText, $this->iHtmlTextIndex, $top - $this->iHtmlTextIndex - strlen($needle)); $this->iHtmlTextIndex = $top; return $retvalue; } function trimclass ($string) { $pattern = '/class="\w*"/i'; $replacement = ""; return preg_replace($pattern, $replacement, $string); } function getinfo ($string) { $pattern1 = '/href="(\S*)".*title="(.*)">/i'; $pattern2 = '/title="(.*)">/i'; $matches1 = array(); $matches2 = array(); if ( preg_match($pattern1, $string, $matches1) ) { return $matches1; } else if ( preg_match($pattern2, $string, $matches2) ){ $matches1[0] = $matches1[1] = ''; $matches1[2] = $matches2[1]; return $matches1; } else { return ''; } } function filtertrim ($string) { $filter = '@= 200 && $sc < 300; } } ?>