,,,,,
,',array('height','alt','width','clear','size','class','border','style'));
break;
}
$aReturn[$ffTag] = $val;
}
}
foreach ($aTags as $key=>$val) {
if (!isset($aReturn[$key])) {
switch ($key) {
case 'pubDate':
$t = time();
//$aReturn[$key] = date('d',$t).' '.$gaLang[date('M',$t)].' '.date(' Y H:i',$t);
$aReturn[$key] = _7feedsParseDate($t);
break;
default:
$aReturn[$key] = '';
}
}
}
return $aReturn;
}
/*=========================================*/
function _7feedsParseDate($t) {
global $gDateTemplate;
return date($gDateTemplate, $t);
$dateVal = $gDateTemplate;
preg_match_all('/(\w+)/iU',$dateVal, $aTmp);
foreach ($aTmp[1] as $key=>$val) {
$dateVal = str_replace($val, '~'.$val.'~', $dateVal);
}
preg_match_all('/~(.+)~/iU',$dateVal, $aTmp);
$aData = array();
foreach ($aTmp[1] as $key=>$val) {
$aData[$val] = date($val,$t);
$dateVal = str_replace('~'.$val.'~', date($val,$t), $dateVal);
}
return $dateVal;
}
function strip_tags_attributes($sSource, $aAllowedTags = '', $aDisabledAttributes = array()) {
if (empty($aDisabledAttributes)) return strip_tags($sSource, $aAllowedTags);
/*$aSpecialSymbols = array('■','●');
for ($i=0; $i < count($aSpecialSymbols); $i++) {
$sSource = str_replace($aSpecialSymbols[$i], '', $sSource);
}*/
$sSource = strip_tags($sSource, $aAllowedTags);
preg_match_all('/<(.*?)>/ie', $sSource, $aRes);
if (!empty($aRes) && !empty($aRes[0])) {
foreach ($aRes[0] as $key=>$val) {
$tPattern = $val;
$foundTag = false;
$foundQuote = false;
$startPos = 0;
$endPos = 0;
foreach ($aDisabledAttributes as $n=>$attr) {
$pos = mb_strpos($val,$attr,0,'UTF-8');
if ($pos === false) {
continue;
}
$foundTag = true;
$startPos = $pos;
$pos = mb_strpos($val, '=', $pos,'UTF-8');
if ($pos === false) {
continue;
}
do{
$pos ++;
$s = mb_substr($val, $pos, 1, 'UTF-8');
if ($s === '\'' || $s === '"') {
$foundQuote = $s;
break;
}
}while ($s === ' ' || $s === '\'' || $s === '"');
if ($foundQuote === false) {
$pos1 = mb_strpos($val, ' ',$pos,'UTF-8');
$pos2 = mb_strpos($val, '>',$pos,'UTF-8');
if ($pos1 === false && $pos2 !== false) {
$pos = $pos2;
}elseif ($pos2 === false && $pos1 !== false) {
$pos = $pos1;
}elseif ($pos2 !== false && $pos1 !== false) {
if ($pos1 < $pos2) {
$pos = $pos1;
}elseif ($pos1 > $pos2) {
$pos = $pos2;
}
}
}else {
$pos = mb_strpos($val, $foundQuote,$pos+1,'UTF-8')+1;
$foundQuote = false;
}
if ($pos !== false) {
$endPos = $pos;
}
$val = mb_substr($val,0,$startPos-1,'UTF-8').mb_substr($val,$endPos,(mb_strlen($val,'UTF-8')),'UTF-8');
$foundTag = false;
}
$aTmp = split(' ',$val);
if (!empty($aTmp)) {
foreach ($aTmp as $k=>$v) {
if (strpos($v,'=') !== false) {
$aTmp2 = split('=',$v);
$v = '';
if (count($aTmp2) > 0) {
$aTmp2[1] = str_replace('"','',$aTmp2[1]);
$aTmp2[1] = str_replace("'",'',$aTmp2[1]);
$aTmp2[1] = '"'.$aTmp2[1];
$t = $aTmp2[count($aTmp2)-1];
if (count($aTmp2)-1 > 1) {
$t = str_replace('"','',$t);
}
$t = str_replace("'",'',$t);
$t = str_replace(">",'',$t);
$aTmp2[count($aTmp2)-1] = $t.'"';
}
$v .= implode('=',$aTmp2);
}
$aTmp[$k] = $v;
}
if (strpos($aTmp[count($aTmp)-1],'>') === false) {
$aTmp[count($aTmp)-1] .= '>';
}
$val = implode(' ',$aTmp);
}
$sSource = str_replace($tPattern,$val,$sSource);
}
}
return $sSource;
}
/*=========================================*/
function xmParseFeedArray($aFeed) {
$aParentTag = array('rss'=>array('rss','rdf'));
$aFeedTags = array('channel'=>array('channel','feed'));
$aItemParentTags = array('item'=>array('item','entry'));
$aItemTags = array('title'=>array('title'),'description'=>array('content','description'),'link'=>array('id','link'),'pubDate'=>array('date','pubDate','pubdate','issued','modified'));
$aChannel = array('title'=>'','description'=>'','link'=>'','pubDate'=>'');
$aItems = array();
if (empty($aFeed)) {
return array($aChannel,$aItems);
}
foreach ($aFeed as $key=>$val) {
if (_in_array($key, $aParentTag['rss'])) {
$aFeed = $val;
break;
}
}
foreach ($aFeed as $key=>$val) {
if (_in_array($key, $aFeedTags['channel'])) {
$aChannel = $val;
break;
}
}
foreach ($aFeed as $key=>$val) {
if (_in_array($key, $aItemParentTags['item'])) {
$aItems = $val;
break;
}
}
if (empty($aItems)) {
foreach ($aChannel as $key=>$val) {
if (_in_array($key, $aItemParentTags['item'])) {
$aItems = $val;
break;
}
}
}
$aChannel = xmGetTagValues($aChannel);
if (isset($aItems[0])) {
foreach ($aItems as $key=>$val) {
$aItems[$key] = xmGetTagValues($val);
}
}else {
$aTmp = $aItems;
$aItems = array();
$aItems[0] = xmGetTagValues($aTmp);
}
return array($aChannel,$aItems);
}
/*=========================================*/
function _in_array($search, $array, $first_check = true) {
$re_check = false;
foreach ($array as $val) {
if (strpos($search,$val) !== false) {
if (strpos($search,$val) == 0 && $first_check) {
return true;
}else {
$re_check = true;
}
}
}
if ($re_check && $first_check) {
return _in_array($search, $array, false);
}
return false;
}
/*=========================================*/
function htFindInvObj($Content) {
$t = preg_match_all('/\<(img\b[^>]*?\bsrc[\s]*='.
'[\s]*([\'"`]?)'.
'(([^>\'"`\s]+)\.(jpg|jpe|jpeg|gif|png))?'.
'\2[\s]*'.
'[^>]*?)\>/im', $Content, $a);
if(!empty($a) && is_array($a)){
foreach($a[1] AS $key => $value){
if(empty($a[4][$key])){
$Content = str_replace('<'.$value.'>', '<'.$value.'>', $Content);
}
}
}
return $Content;
}
/*=========================================*/
function htValidURL($url) {
if(!preg_match("~^(?:(?:https?|ftp|telnet)://(?:[a-z0-9_-]{1,32}".
"(?::[a-z0-9_-]{1,32})?@)?)?(?:(?:[a-z0-9-]{1,128}\.)+(?:com|net|".
"org|mil|edu|arpa|gov|biz|info|aero|inc|name|[a-z]{2})|(?!0)(?:(?".
"!0[^.]|255)[0-9]{1,3}\.){3}(?!0|255)[0-9]{1,3})(?:/[a-z0-9.,_@%&".
"?+=\~/-]*)?(?:#[^ '\"&<>]*)?$~i", $url)){
return false;
}
return true;
}
/*=========================================*/
function htCheckSslURL() {
Global $gRootURL, $gRootCustURL, $gRootUrlSSL, $gSSLActive, $gAccessLevel, $gaEvSSL, $gCurEvent;
//Init
$Ret = false;
$tSSLAct = (strtolower(vrGetSerVar('HTTPS')) == 'on') ? true : false;
//Prepare url with correct proto
$gRootUrlSSL = htSetSslURL($gRootURL);
//Validation of url - prepare return value if redirection required
if(!(!empty($gaEvSSL) && !empty($gaEvSSL[$gAccessLevel]))){
$gRootURL = $gRootUrlSSL;
if(empty($tSSLAct) ^ empty($gSSLActive)){
$Ret = $gRootURL;
}
}elseif(in_array($gCurEvent, $gaEvSSL[$gAccessLevel])){
$gRootURL = $gRootUrlSSL;
if(empty($tSSLAct) ^ empty($gSSLActive)){
$Ret = $gRootURL;
}
}elseif(!in_array($gCurEvent, $gaEvSSL[$gAccessLevel]) && !empty($tSSLAct)){
$Ret = $gRootURL;
}
if(empty($Ret) && !empty($gSSLActive) && $gRootURL == $gRootUrlSSL){
$gRootCustURL = htSetSslURL($gRootCustURL);
}
//Exit
return $Ret;
}
/*=========================================*/
function htSetSslURL($Url) {
Global $gSSLActive;
//Parse url
$tUrl = htParseURL($Url);
//Prepare new proto
if(!empty($gSSLActive)){
$tUrl['scheme'] = 'https';
}else{
$tUrl['scheme'] = 'http';
}
//Prepare new url
$Url = $tUrl['scheme'].'://'.$tUrl['host'].(!empty($tUrl['port']) ? ':'.$tUrl['port'] : '').$tUrl['path'].(!empty($tUrl['query']) ? '?'.$tUrl['query'] : '');
//Exit
return $Url;
}
/*=========================================*/
function htParseURL($value) {
$aurl=array('scheme'=>'', 'host'=>'', 'port'=>'', 'useport'=>'', 'path'=>'', 'query'=>'');
$value=trim($value);
if(empty($value)){
return '';
}
if(preg_match("/^(https?:\/\/)?(.+)$/i", $value, $regs)){
$url=$regs[2];
}
$atmp=parse_url('http://'.$url);
//Host
if(isset($atmp['host'])){
$aurl['host']=$atmp['host'];
}else{
return $aurl;
}
//Proto
if((strpos($value, '://')) !== false){
$aurl['scheme']=substr($value, 0, strpos($value, '://'));
}else{
$aurl['scheme']='http';
}
//Port
if(isset($atmp['port'])){
$aurl['port']=$atmp['port'];
}else{
$aurl['port']='';
}
//Actual Port
if(!empty($atmp['port'])){
$aurl['useport']=$atmp['port'];
}elseif(strtolower($aurl['scheme']) == 'https'){
$aurl['useport']='443';
}elseif(strtolower($aurl['scheme']) == 'http'){
$aurl['useport']='80';
}
//Path after domain
if(isset($atmp['path'])){
$aurl['path']=$atmp['path'];
}else{
$aurl['path']='/';
}
//Query after path
if(isset($atmp['query'])){
$aurl['query']=$atmp['query'];
}else{
$aurl['query']='';
}
//Exit
return $aurl;
}
/*=========================================*/
function htCanonicalizeURL($URL) {
//Init, get proto, split to array
$URL=str_replace("\\", '/', $URL);
$url_up=strtoupper($URL);
if((strpos($url_up, 'HTTP://')===false || strpos($url_up, 'HTTP://')!=0) && (strpos($url_up, 'HTTPS://')===false || strpos($url_up, 'HTTPS://')!=0)){
$URL='http://'.$URL;
}
$URLa=explode('/', $URL);
//Canonicalize
foreach($URLa AS $key => $value){
if($key <= 2){continue;}
switch($value){
case '.' : {
unset($URLa[$key]);
break;
}
case '..' : {
unset($URLa[$key]);
for($i=$key; $i > 2; $i--){
if(isset($URLa[$i-1]) && ($i-1) > 2){
unset($URLa[$i-1]);
break;
}
}
break;
}
}
}
//Formatting
$URL=implode('/', $URLa);
$URL=preg_replace('/\s/s', '+', $URL);
$URL=str_replace('&', '&', $URL);
//Exit
return $URL;
}
/*=========================================*/
function htGetPageContent($URL, $Content, $HttpMethod, $GetBody, $ConvCharset=1, $ParseContent=0) {
Global $gRequestMethod, $gaCrwValidCodes, $gtsHost;
Global $gResponceContent, $gtiWrongHeader, $gtRespTime; //Internal
$PC=array();
$PC['URL']=$URL;
$PC['Size']=0;
$PC['UTime']=0;
$PC['RTime']=0;
$PC['Code']='';
$PC['Error']='';
$PC['Cache']='';
$PC['Title']='';
$PC['Header']='';
$PC['Content']='';
$PC['BaseURL']='';
$PC['Charset']='';
$PC['Keywords']='';
$PC['Description']='';
$PC['Content-Type']='';
$PC['Last-Modified']='';
$gResponceContent = Array('Header'=>'','Body'=>'','Error'=>'','BaseURL'=>'');
$gtiWrongHeader = 0;
$gtRespTime = 0;
if(empty($gtsHost)){
$gtsHost = htParseURL($URL);
$gtsHost = $gtsHost['host'];
}
$TimeStart = erGetMicroTime();
$Content=htHTTPRequest($URL, $Content, $gRequestMethod, $HttpMethod, $GetBody);
$TimeEnd = erGetMicroTime();
$PC['UTime'] = $TimeEnd - $TimeStart;
if(empty($gtRespTime)){
$gtRespTime = $TimeEnd;
}
$PC['RTime'] = $gtRespTime - $TimeStart;
unset($TimeStart, $TimeEnd, $gtRespTime);
//Get header and body
$PC['Header'] =$Content['Header'];
$PC['Content'] =$Content['Body'];
$PC['Error'] =$Content['Error'];
//Page size
$PC['Size']=strlen($PC['Content']);
//Get responce code
$array1=array();
if(!preg_match("/^[^\s]+ (\d{3})/i", $PC['Header'], $array1)){
$PC['Code']='';
}else{
$PC['Code']=trim($array1[1]);
}
if(!in_array($PC['Code'], $gaCrwValidCodes)){
$PC['Content']='';
$PC['Size']=0;
return $PC;
}
//Base URL
$array1=array();
if(!preg_match('/]+href[\s]*=[\s]*[\'"`]?([^>\'"`\s]+)[\'"`]?[\s]*[^>]*>/i', $PC['Content'], $array1)){
$PC['BaseURL'] = $Content['BaseURL'];
}else{
$PC['BaseURL'] = rtrim($array1[1], '/');
}
if(!empty($GetBody) && !empty($ConvCharset)){
//Get charset type from body
$array1=array();
$text=eregi_replace(">", " >", $PC['Content']);
if(!preg_match('/()/smi', $text, $array1)){
if(!preg_match('/()/smi', $text, $array1)){
$PC['Charset']='';
}else{
if(!preg_match('/encoding=([\'"`]?)([^>\'"`\s]+)\1/', $array1[1], $array2)){
$PC['Charset']='';
}else{
$PC['Charset']=strtoupper(trim($array2[2]));
}
}
}else{
if(!preg_match('/charset=([^"\';]+)/', $array1[1], $array2)){
$PC['Charset']='';
}else{
$PC['Charset']=strtoupper(trim($array2[1]));
}
}
//If charset not found in the body try to get it from the head
if($PC['Charset']==''){
//Get charset and content type from header
$text=eregi_replace(">", " >", $PC['Header']);
$array1=array();
if(!preg_match('/(Content-Type:.*charset.*\r?\n)/smi', $text, $array1)){
$PC['Charset']='';
}else{
$array2=array();
if(!preg_match('/charset=([^\r\n]+)/', trim($array1[1]), $array2)){
$PC['Charset']='';
}else{
$PC['Charset']=strtoupper(trim($array2[1]));
}
}
}
}
if(!empty($GetBody) && !empty($ParseContent)){
//Get data of last modification
$array1=array();
if(!preg_match("/\r?\nLast\-Modified[\s]*\: ([a-z]{3}, \d{1,2} [a-z]{3} \d{4} \d{1,2}\:\d{1,2}\:\d{1,2}[a-z ]+)\r?\n/i", $PC['Header'], $array1)){
$array1=array();
if(!preg_match("/\r?\nDate[\s]*\: ([a-z]{3}, \d{1,2} [a-z]{3} \d{4} \d{1,2}\:\d{1,2}\:\d{1,2}[a-z ]+)\r?\n/i", $PC['Header'], $array1)){
$PC['Last-Modified']='';
}else{
$PC['Last-Modified']=trim($array1[1]);
}
}else{
$PC['Last-Modified']=trim($array1[1]);
}
//----
//Get Cache
$array1=array();
if(!preg_match("/\r?\nCache\-Control[\s]*\:([^\r\n]+)\r?\n/i", $PC['Header'], $array1)){
$array1=array();
if(!preg_match("/\r?\nPragma[\s]*\:([^\r\n]+)\r?\n/i", $PC['Header'], $array1)){
$PC['Cache']='';
}else{
$PC['Cache']=trim($array1[1]);
}
}else{
$PC['Cache']=trim($array1[1]);
}
//----
//Remove comments
if($ParseContent == 2){
$PC['Content'] = preg_replace('/).)*-->/m', '', $PC['Content']);
$PC['Content'] = preg_replace('/(