| Current Path : /var/www/html/mmishra/nweb/ |
| Current File : /var/www/html/mmishra/nweb/icdp.inc.php |
<?php
//function to locate expiry date in P tag
function filterObsolete($str) {
date_default_timezone_set('Asia/Calcutta');
$today = date("d-M-Y");
//trim string
$str = trim(preg_replace('/\s+/', ' ', $str));
$attr = 'expDate="';
$i = 0;
$j = 0;
$k = 0;
$slen = 0;
$oTAG = '';
$cTAG = '';
$summary = '';
//check existance of expDate
while (($i = @strpos($str, $attr, $k)) !== false) {
//find value of expDate
$expDateValue = substr($str, $i + strlen($attr), 11);
//if value of expDate is found in string, locate opening/closing TAGs
//check value of expDate against system date
if ($expDateValue && ($expDateValue < $today)) {
//find position of opening TAG
$j = $i;
while ($str[$j] != '<') {
$j--;
}
//find opening TAG name
$oTAG = substr($str, $j, strpos($str, ' ', $j) - $j);
//find closing TAG name
$cTAG = str_replace('<', '</', $oTAG) .'>';
//find position of closing TAG
$k = strpos($str, $cTAG, $i) + strlen($cTAG);
//number of obsolete characters
$slen = $k - $j;
//mark obsolescence and filter from content
$obsolete = substr($str, $j, $slen);
$str = str_replace($obsolete, '', $str);
$summary .= "$slen Obsolete characters filtered (".htmlspecialchars($oTAG).">) $j-$k<br>";
$k = $j;
}
$k = $k + strlen($attr);
if ($i >= strlen($str)) break;
}
//return filtered content
$str .= '<hr>' .$summary;
return $str;
}
//function to locate expiry date in P tag
function filterExpiry($str) {
date_default_timezone_set('Asia/Calcutta');
$today = date("d-M-Y");
//trim string
$str = trim(preg_replace('/\s+/', ' ', $str));
//check existance of expDate
while (($i = @strpos($str, "expDate", $k)) !== false) {
//find value of expDate
$expDateValue = substr($str, $i+9, 11);
//if value of expDate is found in string, locate opening TAG
if ($expDateValue && ($expDateValue < $today)) {
$j = $i;
//find position of opening TAG
while ($j >= 0 && $str[$j] != '<') {
$j--;
}
//$j = tagStart($str, $i);
$k = $j;
//find position of closing TAG
$slen = strlen($str);
while ($k < $slen) {
if ($str[$k] == '<' && $str[$k+1] == '/') {
$k = $k+4;
break;
}
$k++;
}
//$k = tagEnd($str, $i) + 1;
$slen = $k-$j;
//check value of expDate against system date
$obsolete = substr($str, $j, $slen);
$summary .= "\n$slen Obsolete characters\n<br>";
$str = str_replace($obsolete, '', $str);
$k = $j;
}
$k = $k + 8;
if ($i >= strlen($str)) break;
}
//return filtered content
$str .= '<hr>' .$summary;
return $str;
}
//function to locate expiry date in P tag
function checkExpiry($str) {
date_default_timezone_set('Asia/Calcutta');
$today = date("d-M-Y");
//trim string
$str = trim($str);
//get length of string
$slen = strlen($str);
//check existance of expDate
if (substr_count($str, "expDate")) {
//find position of expDate in string
$i = strpos($str, "expDate");
//find value of expDate
$expDateValue = substr($str, $i+9, 11);
//if value of expDate is found in string, locate opening TAG
if ($expDateValue) {
//find position of opening TAG
$j = tagStart($str, $i);
//find position of closing TAG
$k = tagEnd($str, $i);
//if closing TAG could not be found
if (!$k) {
//mark end of string with unpaired TAG
$k = $slen-1;
$pair = FALSE;
} else {
//mark end of string with paired TAG
$pair = TRUE;
}
} else {
//mark end of string with unpaired TAG
$j = $i+1;
$pair = FALSE;
}
//check value of expDate against system date
if ($expDateValue < $today) {
//chop first part of string with unexpired content
$str1 = substr($str, 0, $j);
//chop second part of string with probable expired content
$str2 = substr($str, $k+1);
if ($str2) {
//few content is expired
//check probable expired content in second part
$str = $str1. checkExpiry($str2);
} else {
//no expired content
$str = $str1;
}
} else {
//chop first part of string with unexpired content
$str1 = substr($str, 0, $k);
//chop second part of string with probable expired content
$str2 = substr($str, $k+1);
//check for next expired content
$str = $str1. checkExpiry($str2);
}
}
//return filtered content
return $str;
}
//function to locate HTML tag opening
function tagStart($str, $j) {
while ($j >= 0 && $str[$j] != '<'){
$j--;
}
return $j;
}
//function to locate HTML tag closing
function tagEnd($str, $k) {
$open = 1;
$close = 0;
$slen = strlen($str);
while ($k < $slen) {
if ($str[$k] == '<') {
//$check = 0;
while ($k < $slen && $str[$k] != '>') {
if ($str[$k] == '<' && $str[$k+1] == '/') {
return $k+4;
//$check = 1;
}
$k++;
}
//if ($check) {
// $close++;
//} else {
// $open++;
//}
//if ($open == $close) {
// return ($k+1);
//}
}
$k++;
}
}
/*
function tagFilter1($str) {
$i = 0;
while($i < $httplen) {
if($httpbuffer[i] == $str[0]) {
$j = i;
$k = 0;
$check = 0;
while($j < $httplen && $str[$k] != '\0') {
if($str[$k] != $httpbuffer[$j]) {
$check = 1;
break;
}
$j++;
$k++;
}
if(!$check) {
$ax=0;
$date[8]='';
$ax = $j + 2;
//Assuming date format as exp="dd/mm/yyyy"
$date[0] = $httpbuffer[$ax] - 48;
$date[1] = $httpbuffer[$ax+1] - 48;
$date[2] = $httpbuffer[$ax+3] - 48;
$date[3] = $httpbuffer[$ax+4] - 48;
$date[4] = $httpbuffer[$ax+6] - 48;
$date[5] = $httpbuffer[$ax+7] - 48;
$date[6] = $httpbuffer[$ax+8] - 48;
$date[7] = $httpbuffer[$ax+9] - 48;
//Catched_date contains the date extracted from the HTML.
$catched_date = (struct tm *)malloc(sizeof(struct tm));
$catched_date -> tm_mday = (date[0] * 10) + date[1];
$catched_date -> tm_mon = (date[2] * 10) + date[3];
$catched_date -> tm_year = (date[4] * 1000) + (date[5] * 100) + (date[6] * 10) + date[7];
if(dateisexpired($catched_date)) {
$start = tagStart($i);
$end = tagEnd($j);
tagDelete($start,$end);
}
}
}
$i++;
}
}
*/
?>