'); 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 getThread($URL) { global $url; global $postsAlreadyRead; $email = ""; $content = curl_get_file_contents($URL); while (strlen($content) > 0) { $postContent = getContent(&$content, '
', '
'); if (strlen($postContent) > 0) { $Backup = $postContent; $postDate = getContent($Backup, ' » ', '

'); $Backup = $postContent; $sid='&sid'.getContent($Backup, '&sid', '#'); $postContent = str_replace($sid, '', $postContent); $Backup = $postContent; $postUrl = getContent($Backup, 'viewtopic.php?', '"'); $Backup = $URL; $topicUrl = getContent($Backup, 'viewtopic.php?', '^'); $postContent = str_replace('href="./', 'href="'.$url, $postContent); $postContent = str_replace('href="#', 'href="'.$url.'viewtopic.php?'.substr($postUrl, 0, strpos($postUrl,'#')).'#', $postContent); $id = $postDate." ".$topicUrl." " .$postUrl; if (!AlreadyRead($postUrl)) { echo 'sending '.$postDate.' '.$postUrl."\n"; //. " " .$postContent."\n"; $email = $email.$postContent."\n"; $postsAlreadyRead .= "\n".$id; } } } return $email; } function getLatestPosts($SearchUrl) { global $url; $email=""; if (strlen($SearchUrl) == 0) { $latestPosts = curl_get_file_contents($url."search.php?search_id=newposts"); // get second and more pages of latest posts as well? $Backup = $latestPosts; $Backup = getContent($Backup, ''); while (strpos($Backup, './search.php?') !== false) { $otherSearchPage = 'search.php?'.getContent($Backup, './search.php?', '"'); $linkBackup = $otherSearchPage; $sid='&sid'.getContent($linkBackup, '&sid', '&'); $otherSearchPage = str_replace($sid, '', $otherSearchPage); $email = getLatestPosts($url.$otherSearchPage).$email; } } else { $latestPosts = curl_get_file_contents($SearchUrl); } $content = getContent($latestPosts, ''); while (strlen($content) > 0) { $item = getContent(&$content, ''); if (strlen($item) > 0) { $itemBackup = $item; $date = getContent($itemBackup, 'View the latest post" />
', '
'); $link = getContent($item, '', '^'); $latestPost = 'p='.getContent($latestPost, '&p=', '"'); if (!AlreadyRead($latestPost)) { if (strpos($item, 'class="pagination"') !== false) { // there are several pages while (strpos($item, '&start') !== false) { $page = '&start'.getContent($item, '&start', '"'); echo $date." ".$link.$page."\n"; $email = getThread($link.$page, $latestPost).$email; } } else { echo $date." ".$link."\n"; $email = getThread($link, $latestPost).$email; } } 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"; mail($EmailTo, $EmailSubject, $message, $headers); } $postsAlreadyRead = file_get_contents($historyFile); $emailText = getLatestPosts(''); if (strlen($emailText) > 0) { sendMail($emailText); } else { echo "nothing to be sent"; } file_put_contents ($historyFile, $postsAlreadyRead); ?>