'); if ($posSpace !== false && $posClose !== false) { $element = substr($startContentStr, 1, $posSpace < $posClose ? $posSpace : $posClose); } else if ($posSpace !== false) { $element = substr($startContentStr, 1, $posSpace - 1); } else if ($posClose !== false) { $element = substr($startContentStr, 1, $posClose - 1); } else { $element = substr($startContentStr, 1); } $element = trim($element); } if ($startContentStr == '^') { $startContentStr = ''; $contentPos = 0; } else { $contentPos = strpos($contents, $startContentStr); //if ($contentPos === false) die('Problem reading page '.$startContentStr); if ($contentPos === false) { $contents = ''; return ''; } } $start = $contentPos + strlen($startContentStr); if ($endContentStr == '^') { $end = strlen($contents); } else { $end = strpos($contents, $endContentStr, $start); if (strlen($element) > 0) { // make sure we find the right ending element. count the number of open element tags $result = substr($contents, $start, $end - $start); while (substr_count($result, '<'.$element) <> substr_count($result, '') && $end !== false) { $end = strpos($contents, $endContentStr, $end + 1); $result = substr($contents, $start, $end - $start); } if ($end === false) { // something went wrong. incorrect number of elements $end = strlen($contents); } } } $result = substr($contents, $start, $end - $start); $contents = substr($contents, $end); return $result; } // it seems file_get_contents does not return the full page function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, str_replace('&', '&', $URL)); $contents = curl_exec($c); curl_close($c); if ($contents) return $contents; else return FALSE; } function AlreadyRead($date) { global $postsAlreadyRead; if (strpos($postsAlreadyRead, $date) === false) { return false; } return true; } function getLatestPosts($SearchUrl) { global $url; global $postsAlreadyRead; $email=""; if (strlen($SearchUrl) == 0) { $latestPosts = curl_get_file_contents($url."view_all_bug_page.php?filter=187"); } else { $latestPosts = curl_get_file_contents($SearchUrl); } $content = ''); while (strlen($content) > 0) { $item = getContent(&$content, ''); if (strlen($item) > 0) { $itemBackup = $item; # for Mantis 1.2.14, I had to add the slash before view.php $id = getContent($itemBackup, ' href="/view.php?id=', '"'); $dummy = getContent($itemBackup, '', ''); $dummy = getContent($itemBackup, ''); $status = getContent($dummy, '">', '^'); $status = str_replace('', '', $status); $date = getContent($itemBackup, '', ''); $date = str_replace('', '', $date); $date = str_replace('', '', $date); $title = getContent($itemBackup, '', ''); $link=$url."view.php?id=".$id; $latestPost = $id.$date; if (!AlreadyRead($latestPost)) { echo $id." ".$date." ".$title." ".$status."\n"; $email .= $status." ".$link." ".$date." ".$title."
\n"; $postsAlreadyRead .= "\n".$latestPost; } else { echo "Already read: ".$latestPost."

\n"; } } } return $email; } function sendMail($message) { global $EmailTo, $EmailFrom, $EmailSubject; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$EmailFrom . "\r\n"; if (mail($EmailTo, $EmailSubject, $message, $headers) == true) { echo "mail has been sent to $EmailSubject"; } } $postsAlreadyRead = file_get_contents($historyFile); $emailText = getLatestPosts(''); if (strlen($emailText) > 0) { sendMail($emailText); } else { echo "nothing to be sent"; } file_put_contents ($historyFile, $postsAlreadyRead); ?>