function check_websites_for_change()
{
    global $websites_to_check;
    $snoopy = new Snoopy();
    $snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
    $snoopy->maxredirs = 2;
    $snoopy->offsiteok = true;
    $snoopy->expandlinks = false;
    echo "In here";
    foreach ($websites_to_check as $websitename => $websiteurl) {
        //only check if the page was fetched and responded with a 200
        if ($snoopy->fetch($websiteurl)) {
            if ($snoopy->status == 200) {
                $response = $snoopy->results;
                $filename = DUMP_LOCATION . strtolower($websitename) . ".dump";
                if (file_exists($filename)) {
                    $oldpage = read_content($filename);
                    //something changed, send email alert
                    if (md5($oldpage) != md5($response)) {
                        $subject = "URL Content Has Changed for " . $websitename;
                        $body = "URL: " . $websiteurl . " Content Changed";
                        email_notify($subject, $body);
                        //overwrite old page with new page for new checks
                        write_content($filename, $response);
                    }
                } else {
                    /*
                     * if file does not exist this is the first time we are loading it
                     * this will create the dump file and it will be used for compare next time
                     */
                    write_content($filename, $response);
                }
            }
        }
    }
}
Example #2
0
/**
 * find_files_and_replace_absolute find files and search and replace absolute paths with relative paths
 * @param   $dir        string  the directory where to start
 * @param   $pattern    string  the type of files on which to apply the search and replace
 * @param   $root_path  string  the root path
 */
function find_files_and_replace_absolute($dir = '.', $pattern = '/./', $root_path)
{
    $prefix = $dir . '/';
    $dir = dir($dir);
    while (false !== ($file = $dir->read())) {
        if ($file === '.' || $file === '..') {
            continue;
        }
        $file = $prefix . $file;
        if (is_dir($file)) {
            find_files_and_replace_absolute($file, $pattern, $root_path);
        }
        if (preg_match($pattern, $file)) {
            $content = read_content($file);
            $backtrack = get_backtrack($root_path, $file, $pattern);
            $content = format_content_for_local_use(get_site_url(), $backtrack, $content);
            $content = str_replace('../fonts.g', 'fonts.g', $content);
            $content = str_replace('../maxcdn.b', 'maxcdn.b', $content);
            $content = str_replace('../cdnjs.c', 'cdnjs.c', $content);
            $content = str_replace('../vjs.z', 'vjs.z', $content);
            unlink($file);
            // delete the file
            write_content($file, $content);
        }
    }
}