From 2b0da24e6e460fbb6647037d5561b60432f0aba6 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Sun, 25 May 2014 16:39:44 +0300 Subject: [PATCH] Change indentation to 4 spaces and removed closing php tag. --- xkcd-mailer.php | 87 +++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 43 deletions(-) diff --git a/xkcd-mailer.php b/xkcd-mailer.php index 8fa3cf3..5670209 100644 --- a/xkcd-mailer.php +++ b/xkcd-mailer.php @@ -12,7 +12,7 @@ **/ // Use config.example.php as base for your configurations. - $lastfile = "last.txt"; + $lastfile = "last.txt"; $here = dirname( __FILE__ ); if( !is_readable($here . '/config.php') ) { @@ -25,57 +25,58 @@ // Check if http:// wrapper is allowed if( ini_get('allow_url_fopen') ) { - $data = simplexml_load_file($feed); + $data = simplexml_load_file($feed); } else { - // If http:// wrapper is disabled (by allow_url_fopen=0, for example), then fall back on cURL - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $feed); - curl_setopt($ch, CURLOPT_FAILONERROR, 1); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 15); - $result = curl_exec($ch); - curl_close($ch); + // If http:// wrapper is disabled (by allow_url_fopen=0, for example), then fall back on cURL + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $feed); + curl_setopt($ch, CURLOPT_FAILONERROR, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 15); + $result = curl_exec($ch); + curl_close($ch); - $data = simplexml_load_string($result); + $data = simplexml_load_string($result); } $item = $data->entry[0]; - if (file_exists($lastfile)) { - $f = fopen($lastfile, 'r'); - $last = (int) fread($f, 1024); - fclose($f); - } else { - $last = 0; - } - $parts = explode('/', $item->id); - $current = (int) $parts[3]; - if ($current > $last) { - $date = date("Y-m-d", strtotime($item->updated)); - preg_match("#title=\"(.+)\"#iU", $item->summary, $t); + if (file_exists($lastfile)) { + $f = fopen($lastfile, 'r'); + $last = (int) fread($f, 1024); + fclose($f); + } else { + $last = 0; + } - // To send HTML mail, the Content-type header must be set - //$headers = 'MIME-Version: 1.0' . "\r\n"; - $headers = 'Content-type: text/html; charset=UTF-8' . "\r\n"; - $headers .= 'From: '. $from . "\r\n"; + $parts = explode('/', $item->id); + $current = (int) $parts[3]; - $subject = "xkcd {$date}: {$item->title}"; - $punchline = $t[1]; + if ($current > $last) { + $date = date("Y-m-d", strtotime($item->updated)); + preg_match("#title=\"(.+)\"#iU", $item->summary, $t); - $msg = "

id}\">{$item->title}

\n" - . "Posted {$date}
\n" - . $item->summary."
\n" - . "

{$punchline}

\n"; + // To send HTML mail, the Content-type header must be set + //$headers = 'MIME-Version: 1.0' . "\r\n"; + $headers = 'Content-type: text/html; charset=UTF-8' . "\r\n"; + $headers .= 'From: '. $from . "\r\n"; - mail($mail, $subject, $msg, $headers); + $subject = "xkcd {$date}: {$item->title}"; + $punchline = $t[1]; - $f = fopen($lastfile, 'w'); - fwrite($f, $current); - fclose($f); + $msg = "

id}\">{$item->title}

\n" + . "Posted {$date}
\n" + . $item->summary."
\n" + . "

{$punchline}

\n"; - echo "New last is $current (was $last)\n"; - } else { - echo "No new XKCD: last=$last current=$current\n"; - } -?> + mail($mail, $subject, $msg, $headers); + + $f = fopen($lastfile, 'w'); + fwrite($f, $current); + fclose($f); + + echo "New last is $current (was $last)\n"; + } else { + echo "No new XKCD: last=$last current=$current\n"; + }