<?php
$dn = dirname(__FILE__);
require_once $dn.'/mtfetcher_Class.php';
require_once 'PEAR.php';
/**
* Class of System controller
*
* Use this class under GPL license
* @author Eugene Panin <hide@address.com>, Lubertsy, Russia, 2004
* @home http://www.tortuga.pp.ru/index.php/processor/index/lang/en
* @package mtfetcher
* @depends PEAR (http://pear.php.net)
* @version 1.0
*/
class mtfetcher_Fetcher extends mtfetcher_Class {
/**
* Transport object
*
* @var object mtfetcher_Transport
* @access private
*/
var $_tr;
/**
* Selects transport
*
* @param string $trName Name of concrete transport
* @param array $trConf Configuration of transport
* @return void
* @throws object mtfetcher_Error
* @access public
*/
function selectTransport($trName,$trConf) {
$err = $this->_includeFile('mtfetcher_Transport');
if (PEAR::isError($err)) return $err;
$this->_tr = mtfetcher_Transport::factory($trName,$trConf);
if (PEAR::isError($this->_tr)) return $this->_tr;
} // selectTransport
/**
* Returns META-tags of indicated web page
*
* @param string $url URL of web page
* @return array Hash of META-tags
* Keys:
* title : string - Title of the web page
* description : string - Description of the web page
* keywords : string - Keywords of the web page
* @throws object mtfetcher_Error
* @access public
*/
function getTags($url) {
if (!is_a($this->_tr,'mtfetcher_Transport')) return new mtfetcher_NoTransportCreated_Error(' No transport selected');
// Getting web page from URL
$page = $this->_tr->getPage($url);
if (PEAR::isError($page)) return $page;
// Parsing tags from fetched page
return $this->_parseTags($page);
} // getTags
/**
* Parses web page and extracts META-tags
*
* @param string $page Web page
* @return array Hash of META-tags
* Keys:
* title : string - Title of the web page
* description : string - Description of the web page
* keywords : string - Keywords of the web page
* @throws object mtfetcher_Error
* @access private
*/
function _parseTags($page) {
$title = $description = $keywords = '';
if (preg_match('/<title>(.*)<\/title>/i',$page,$ar)) $title = $ar[1];
if (preg_match('/<meta name="description" content="(.*)"/i',$page,$ar)) $description = $ar[1];
if (preg_match('/<meta name="keywords" content="(.*)"/i',$page,$ar)) $keywords = $ar[1];
$res = array(
'title'=>$title,
'description'=>$description,
'keywords'=>$keywords,
);
return $res;
} // _parseTags
} // class
?>