[\r\n]?/ism", "", $chunk);
$chunk = preg_replace("/
[\r\n]?/ism", "
", $chunk);
$chunk = preg_replace("/<\/div>[\r\n]?/ism", ": ", $chunk);
$chunk = preg_replace("/<\/span>/ism", "", $chunk);
return $chunk;
}
function blogs_i_read() {
$url = "http://spring2life-links.blogspot.de";
if ( false === ( $html = get_transient( $url ) ) ) {
$html = curlDownload($url);
if ( ! $html ) {
echo "
There is a problem with the http request!
";
} else {
if ( ! preg_match('/(
)/is', $html, $matches)) {
echo "Error: could not retrieve valid spring2life-links blogroll
", $html;
return;
} else {
set_transient( $url, $html, 3600 );
}
}
}
/* delete_transient($url); */
$html = preg_replace('/.*/ism', '', $html);
$newest_only = "";
$stundenflag = false;
$tagflag = false;
$wochenflag = false;
$monatflag = false;
$pleistoflag = false;
preg_match_all('/
.*
.*<\\/div>/Us', $html, $matches);
foreach ($matches[0] as $chunk) {
$omitflag = false;
if ( preg_match("/orengrad.com/ism", $chunk) ) {
list ($newest_only, $omitflag) = process_oren_grad($chunk, $newest_only, $omitflag);
}
if ( preg_match("#/lfi-online.de/ceemes/#", $chunk) ) {
list ($newest_only, $omitflag) = process_lfi_online($chunk, $newest_only, $omitflag);
}
if ( preg_match("/vor\s+\d+\s+(Minute|Stunde)/ism", $chunk) )
if (! $stundenflag) {
$chunk = "
Hot from the Sphere
\n\n
\n" . $chunk;
$stundenflag = true;
}
if ( preg_match("/vor\s+\d+\s+(Tag)/ism", $chunk) )
if (! $tagflag) {
$chunk = "
\n
A day and older
\n
\n" . $chunk;
$tagflag = true;
}
if ( preg_match("/vor\s+\d+\s+Woche/ism", $chunk) )
if (! $wochenflag) {
$chunk = "
\n
Less than a month old
\n
\n" . $chunk;
$wochenflag = true;
}
if ( preg_match("/vor\s+\d+\s+(Monat)/ism", $chunk) )
if (! $monatflag) {
$chunk = "
Older
\n
\n" . $chunk; $monatflag = true;
}
if ( preg_match("/vor\s+\d+\s+(Jahr)/ism", $chunk) )
if (! $pleistoflag) {
$chunk = "
From the Pleistozaen
\n
\n" . $chunk; $pleistoflag = true;
}
$chunk = cleanup_chunk($chunk);
if ( $omitflag == false )
$newest_only .= $chunk;
if ( preg_match('/href=\'(http:\/\/feedproxy.google.com.*?)\'/', $chunk, $match) ) {
$proxyurl = $match[1];
if ( false === ( $cleanurl = get_transient( md5('cleanurlof' . $proxyurl) ) ) ) {
$cleanurl = resolveUrl($proxyurl);
$cleanurl = doHardcore($cleanurl);
set_transient( md5("cleanurlof" . $proxyurl), $cleanurl, 90000 + rand(1,3600) );
} $chunk = str_replace($match[1], $cleanurl, $chunk);
}
}
return $newest_only;
}
function resolveUrl($url) {
try {
$header = doCurlRequest($url); return $header['redirect_url']; } catch (Exception $ex) {
_log("error freeing url $url: " . $ex->getMessage()); return $url;
}
}
function curlDownload($Url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_REFERER, "https://markus-spring.info");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
if(!function_exists('_log')) {
function _log( $message ) {
if( WP_DEBUG === true ) {
if( is_array( $message ) || is_object( $message ) ) {
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
}
function doCurlRequest($url) {
$curlSession = curl_init($url);
curl_setopt($curlSession, CURLOPT_NOBODY, 1);
$curlResponse = curl_exec($curlSession);
$header = curl_getinfo($curlSession);
curl_close($curlSession);
return $header;
}
function doHardcore($url) {
try {
$parts = explode("?", $url);
$ret = $parts[0];
_log("do hardcore: [$url] -> [$ret]");
return $ret;
} catch (Exception $ex) {
_log("error in hardcore: " . $ex->getMessage());
return $url;
}
}
?>