- Hot from the Sphere
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; } function reduce_lines( $html ) { $lines = explode("\n", $html); $found = 0; $bloglist = ''; for ($i = 0; $i < count($lines); $i++) { if ($lines[$i] == "
$domain: " . $match[3] . "\n"; if (preg_match('`href=\'(.*?)\'.*?>\s*(.*?)\s*`m', $match[3], $m)) { #echo "
" . $match[3] . "\n"; $lasturl = $m[1]; $lasttitle = $m[2]; /* echo "Last post 1:" . $lasturl . "\n"; */ $timestamp = make_timestamp($match[4]) + $offset; } else { if ( strpos($domain, 'lfi-online.de') === 0 ) list($timestamp, $lasturl, $lasttitle) = update_lfi($url, $list); if ( strpos($domain, 'jims-ramblings.blogspot.com') === 0 ) list($timestamp, $lasturl, $lasttitle) = update_jims_ramblings($url, $list); if ( strpos($domain, 'www.orengrad.com') === 0) list($timestamp, $lasturl, $lasttitle) = update_oren_grad($url, $domain, $list); else { // echo "unmatched domain $domain\n"; $id = array_search($domain, array_column($list, 'domain')); $timestamp = $list[$id]['timestamp']; // $timestamp = make_timestamp($match[4]) + $offset; } } return ['domain' => $domain, 'url' => $url, 'title' => $title, 'lasturl' => $lasturl, 'lasttitle' => $lasttitle, 'timestamp' => $timestamp, 'housekeeping' => $housekeeping]; } function debug_echo ( $flag, $args ) { if ($flag == 1) echo "
'; echo print_r($list); echo ''; $id = array_search($url, array_column($list, 'url')); // $id = array_search($domain, array_column($list, 'domain')); $lasttitle = ''; if ( $id === false ) { // not found in list debug_echo($debug, "OG: $domain not found in list"); preg_match('/bodycontent[\'"]>\s*
$GLOBALS['external_service_min_time'] ) {
debug_echo($debug, "OG: $domain found in list but outdated");
preg_match('/bodycontent[\'"]>\s*
\s*?(.*?)<\/a/', curlDownload($url), $m);
$timestamp = time() - $GLOBALS['external_service_pre_aged'];
$lasturl = $m[1];
$lasttitle = $m[2];
} else { // found
// echo "$url found in list\n";
$timestamp = $list[$id]['timestamp'];
$lasturl = $list[$id]['lasturl'];
$lasttitle = $list[$id]['lasttitle'];
}
// echo "lasturl age " . (time() - $timestamp - 600 ) . "s\n";
if ( (time() - $timestamp ) > $GLOBALS['external_service_min_time'] + 600 ) {
// echo "$url found in list but outdated\n";
preg_match('/
\s*?(.*?)<\/a/', curlDownload($url), $m);
$timestamp = time() - $GLOBALS['external_service_pre_aged'];
$lasturl = $m[1];
$lasttitle = $m[2];
if ( $lasttitle == $list[$id]['lasttitle'] )
$timestamp = $list[$id]['timestamp'];
}
return [$timestamp, $lasturl, $lasttitle];
}
function update_lfi($url, $list) {
$id = array_search($url, array_column($list, 'url'));
if ( $id === false ) { // not found in list
// echo "$url not found in list\n";
preg_match('/location = \'(.*?)\'">\s*?
(.*?) $GLOBALS['external_service_min_time'] + 600 ) {
// echo "$url found in list but outdated\n";
preg_match('/location = \'(.*?)\'">\s*?
(.*?)' . $housekeeping . '
';
$debug = 0;
$hurl = "http://spring2life-links.blogspot.de";
debug_echo($debug, $hurl);
$html = curlDownload($hurl);
$bloglines = reduce_lines($html);
// debug_echo($debug, $bloglines);
# matches: 1: url 2: blog title 3. post title 4. time indicator
$re = '/$op
";
unset($list[$op]);
// while ( $hk < $housekeeping ) {
// debug_echo($debug, $hk);
// while ( is_int($to_delete = array_search($hk, array_column($list, 'housekeeping' ))) ) {
// echo '' . $hk . ' ';
// echo print_r( $list[$to_delete] );
// echo '';
// unset($list[$to_delete]);
// }
// // while ( $to_delete = array_search($hk, array_column($list, 'housekeeping' )) !== NULL) {
// // debug_echo(1, $to_delete);
// // unset($list[$to_delete]);
// // }
// $hk = $hk + 1;
// }
return $list;
}
function retrieve_list() {
$debug = 0;
$time1 = (float) microtime(true);
// echo "getting content from stored list " . (time() - filemtime('/tmp/file.ser')) . "s\n";
// $str = file_get_contents('/tmp/file.ser');
// $str = get_transient( $hurl + "_hp" );
// if ( $str === false ) { // not found
// $list = create_linklist([]);
// } else { // found
// // $list = unserialize( $str );
// $list = create_linklist($str);
// }
$queried_object = get_queried_object();
if ( $queried_object ) {
$post_id = $queried_object->ID;
}
// $post_id = 23342; // for testing, fixed to the blogs-i-read page id
debug_echo($debug, $post_id);
$cache_key = '_blogs_i_read';
$cache = get_post_meta( $post_id, $cache_key, true );
$housekeeping = -1;
// $cache = [];
if ( empty( $cache ) || $cache['expires'] < time() ) {
debug_echo($debug, 'empty or expired');
if (empty($cache)) {
$list = [];
$housekeeping = 0;
} else {
debug_echo($debug, 'expired');
$housekeeping = $cache['housekeeping'] + 1;
debug_echo($debug, 'housekeeping:' . $housekeeping);
$list = $cache['data'];
}
$list = create_linklist($list, $housekeeping);
debug_echo($debug, 'after creating linklist');
$cache = array(
'expires' => time() + $GLOBALS['blogs_i_read_min_time'],
'data' => $list,
'housekeeping' => $housekeeping );
update_post_meta( $post_id, $cache_key, $cache );
debug_echo($debug, 'after updating post meta');
} else {
debug_echo($debug, 'neither empty nor expired');
$housekeeping = $cache['housekeeping'];
create_linklist($cache['data'], $housekeeping);
}
debug_echo($debug, 'before printing');
return(print_list( $cache['data'], $time1 ));
}
function print_list ( $list, $time1 ) {
$list2 = array_msort($list, array('timestamp' => SORT_DESC));
$s = '';
$dayflag = $weekflag = $monthflag = $yearflag = false;
foreach ($list2 as $l) {
if ( ! $dayflag and ((time() - $l['timestamp']) > 24*3600) ) {
$s .= "\n";
$s .= "\n\n";
$dayflag = true;
} elseif ( ! $weekflag and ((time() - $l['timestamp']) > 7*24*3600) ) {
$s .= "
\n\n";
$weekflag = true;
} elseif ( ! $monthflag and ((time() - $l['timestamp']) > 30*24*3600) ) {
$s .= "
\n\n";
$monthflag = true;
} elseif ( ! $yearflag and ((time() - $l['timestamp']) > 365*24*3600) ) {
$s .= "
\n\n";
$yearflag = true;
}
$s .= '
Blogs I read