| Current Path : /var/www/html/mmishra/icdp/ |
| Current File : /var/www/html/mmishra/icdp/icdp.inc |
<?php
require('classes/PHPMailerAutoload.php');
//require('classes/class.smtp.php');
//function to locate date attribute in HTML tag
function obsolescence_filter_on_time($str) {
date_default_timezone_set('Asia/Kolkata');
$now = date("H:i:s");
//trim string
$str = trim(preg_replace('/\s+/', ' ', $str));
//if (!@strpos($str, 'meta name="Obsolescence-Filter" content="yes"')) {
// return $str;
//}
$attr = 'Time="';
$timeAttr = '';
$timeValue = '';
$i = 0; $j = 0; $k = 0;
$slen = 0;
$totWO = 0;
$oTAG = '';
$cTAG = '';
$obsolescence = '';
while (($i = @strpos($str, $attr, $k)) !== false) {
//find value of pub/exp Time
$timeAttr = substr($str, $i - 3, 3);
$timeValue = substr($str, $i + strlen($attr), 8);
//if value of pub/exp Time is found in string, check its value against system time
if (($timeAttr == 'pub' && (strtotime($timeValue) > strtotime($now))) || ($timeAttr == 'exp' && (strtotime($timeValue) < strtotime($now)))) {
//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;
$totWO = $totWO + $slen;
//chop obsolescence
$obsolete = substr($str, $j, $slen);
//accumulate obsolete content
$obsolescence .= "<li>$obsolete</li>";
//filter obsolescence
$str = str_replace($obsolete, '', $str);
$k = $j;
}
if ($i >= strlen($str)) break;
$k = $k + strlen($attr);
}
//web obsolescence list
$str .= "<hr> <font size='-2x' color='red'>Total $totWO bytes web obsolescence has been filtered.</font> <hr>";
return $str;
}
//function to locate date attribute in HTML tag
function obsolescence_filter_on_date($str) {
date_default_timezone_set('Asia/Kolkata');
$today = date("d-m-Y");
//trim string
$str = trim(preg_replace('/\s+/', ' ', $str));
//if (!@strpos($str, 'meta name="Obsolescence-Filter" content="yes"')) {
// return $str;
//}
$attr = 'Date="';
$dateAttr = '';
$dateValue = '';
$i = 0; $j = 0; $k = 0;
$slen = 0;
$totWO = 0;
$oTAG = '';
$cTAG = '';
$obsolescence = '';
while (($i = @strpos($str, $attr, $k)) !== false) {
//find value of pub/exp Date
$dateAttr = substr($str, $i - 3, 3);
$dateValue = substr($str, $i + strlen($attr), 10);
//if value of pubDate or expDate is found in string, check its value against system date
if (($dateAttr == 'pub' && (strtotime($dateValue) > strtotime($today))) || ($dateAttr == 'exp' && (strtotime($dateValue) < strtotime($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;
$totWO = $totWO + $slen;
//chop obsolescence
$obsolete = substr($str, $j, $slen);
//accumulate obsolete content
$obsolescence .= "<li>$obsolete</li>";
//filter obsolescence
$str = str_replace($obsolete, '', $str);
$k = $j;
}
$k = $k + strlen($attr);
if ($i >= strlen($str)) break;
}
//web obsolescence list
$str .= "<hr> <font size='-2x' color='red'>Total $totWO bytes web obsolescence has been filtered.</font> <hr>";
//<font size='-2x' color='red'>Total $totWO bytes web obsolescence as listed below have been filtered</font>.
//<ol id='wo' style='font-size:-2x'>$obsolescence</ol>
//sent alert mail to webmaster
//if ($obsolescence) {
//automailer('mmishra@iiita.ac.in','Web obsolescence',$obsolescence);
//}
return $str;
}
//function to locate expiry date in P tag
function filterExpiry($str) {
date_default_timezone_set('Asia/Kolkata');
$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);
$expDateValue = substr($str, $i+9, 10);
//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;
$tlen = $tlen + $slen;
//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);
$expDateValue = substr($str, $i+9, 10);
//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++;
}
}
*/
function automailer($email, $subject, $body) {
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it
//if you don't have access to that
//date_default_timezone_set('Asia/Culcutta');
date_default_timezone_set('Asia/Kolkata');
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Tell PHPMailer to use SMTP
$mail->isHTML(true);
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "icure@iiita.ac.in";
//Password to use for SMTP authentication
$mail->Password = "irp@2015";
//Set who the message is to be sent from
$mail->setFrom('icure@iiita.ac.in','Automailer');
//Set an alternative reply-to address
//$mail->addReplyTo('icure@iiita.ac.in', 'iCure@IIITA');
//Set who the message is to be sent to
$mail->addAddress($email, $email);
//Set the subject line
$mail->Subject = $subject;
$mail->Body = $body;
$mail->WordWrap = 75;
//send the message, check for errors
if (!$mail->send()) {
echo "<div>Automailer Said: ".$mail->ErrorInfo."</div>";
} else {
echo "<div>Automailer Said: OK</div>";
}
}
?>