mirror of
https://github.com/ivuorinen/xkcd-Mailer.git
synced 2026-03-16 19:04:22 +00:00
Drop indentation by one.
This commit is contained in:
136
xkcd-mailer.php
136
xkcd-mailer.php
@@ -1,84 +1,84 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* xkcd-Mailer
|
* xkcd-Mailer
|
||||||
*
|
*
|
||||||
* Sends HTML-email containing hotlinked latest xkcd
|
* Sends HTML-email containing hotlinked latest xkcd
|
||||||
* strip with alt/title-text underneath the image.
|
* strip with alt/title-text underneath the image.
|
||||||
*
|
*
|
||||||
* @category Default
|
* @category Default
|
||||||
* @package Default
|
* @package Default
|
||||||
* @author Ismo Vuorinen <ivuorinen@me.com>
|
* @author Ismo Vuorinen <ivuorinen@me.com>
|
||||||
* @author wojas <https://github.com/wojas>
|
* @author wojas <https://github.com/wojas>
|
||||||
* @author Raam Dev <https://github.com/raamdev>
|
* @author Raam Dev <https://github.com/raamdev>
|
||||||
* @license The MIT License http://www.opensource.org/licenses/mit-license.php
|
* @license The MIT License http://www.opensource.org/licenses/mit-license.php
|
||||||
* @version 1.0.20140525
|
* @version 1.0.20140525
|
||||||
* @link https://github.com/ivuorinen/xkcd-Mailer
|
* @link https://github.com/ivuorinen/xkcd-Mailer
|
||||||
**/
|
**/
|
||||||
|
|
||||||
// Use config.example.php as base for your configurations.
|
// Use config.example.php as base for your configurations.
|
||||||
$lastfile = "last.txt";
|
$lastfile = "last.txt";
|
||||||
|
|
||||||
$here = dirname(__FILE__);
|
$here = dirname(__FILE__);
|
||||||
if (! is_readable($here . '/config.php')) {
|
if (! is_readable($here . '/config.php')) {
|
||||||
die("Please configure me. I don't know where I should sent the comic. (Config file {$here}/config.php missing.)");
|
die("Please configure me. I don't know where I should sent the comic. (Config file {$here}/config.php missing.)");
|
||||||
}
|
}
|
||||||
require_once $here . '/config.php';
|
require_once $here . '/config.php';
|
||||||
|
|
||||||
$feed = "http://xkcd.com/atom.xml";
|
$feed = "http://xkcd.com/atom.xml";
|
||||||
|
|
||||||
// Check if http:// wrapper is allowed
|
// Check if http:// wrapper is allowed
|
||||||
if (ini_get('allow_url_fopen')) {
|
if (ini_get('allow_url_fopen')) {
|
||||||
$data = simplexml_load_file($feed);
|
$data = simplexml_load_file($feed);
|
||||||
} else {
|
} else {
|
||||||
// If http:// wrapper is disabled (by allow_url_fopen=0, for example), then fall back on cURL
|
// If http:// wrapper is disabled (by allow_url_fopen=0, for example), then fall back on cURL
|
||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
curl_setopt($ch, CURLOPT_URL, $feed);
|
curl_setopt($ch, CURLOPT_URL, $feed);
|
||||||
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
$data = simplexml_load_string($result);
|
$data = simplexml_load_string($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = $data->entry[0];
|
$item = $data->entry[0];
|
||||||
|
|
||||||
$last = 0;
|
$last = 0;
|
||||||
if (file_exists($lastfile)) {
|
if (file_exists($lastfile)) {
|
||||||
$f = fopen($lastfile, 'r');
|
$f = fopen($lastfile, 'r');
|
||||||
$last = (int) fread($f, 1024);
|
$last = (int) fread($f, 1024);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
}
|
}
|
||||||
|
|
||||||
$parts = explode('/', $item->id);
|
$parts = explode('/', $item->id);
|
||||||
$current = (int) $parts[3];
|
$current = (int) $parts[3];
|
||||||
|
|
||||||
if ($current > $last) {
|
if ($current > $last) {
|
||||||
$date = date("Y-m-d", strtotime($item->updated));
|
$date = date("Y-m-d", strtotime($item->updated));
|
||||||
preg_match("#title=\"(.+)\"#iU", $item->summary, $t);
|
preg_match("#title=\"(.+)\"#iU", $item->summary, $t);
|
||||||
|
|
||||||
// To send HTML mail, the Content-type header must be set
|
// To send HTML mail, the Content-type header must be set
|
||||||
//$headers = 'MIME-Version: 1.0' . "\r\n";
|
//$headers = 'MIME-Version: 1.0' . "\r\n";
|
||||||
$headers = 'Content-type: text/html; charset=UTF-8' . "\r\n";
|
$headers = 'Content-type: text/html; charset=UTF-8' . "\r\n";
|
||||||
$headers .= 'From: '. $from . "\r\n";
|
$headers .= 'From: '. $from . "\r\n";
|
||||||
|
|
||||||
$subject = "xkcd {$date}: {$item->title}";
|
$subject = "xkcd {$date}: {$item->title}";
|
||||||
$punchline = $t[1];
|
$punchline = $t[1];
|
||||||
|
|
||||||
$msg = "<html><body><h1><a href=\"{$item->id}\">{$item->title}</a></h1>\n"
|
$msg = "<html><body><h1><a href=\"{$item->id}\">{$item->title}</a></h1>\n"
|
||||||
. "<small>Posted {$date}</small><br />\n"
|
. "<small>Posted {$date}</small><br />\n"
|
||||||
. $item->summary."<br />\n"
|
. $item->summary."<br />\n"
|
||||||
. "<p>{$punchline}</p></body></html>\n";
|
. "<p>{$punchline}</p></body></html>\n";
|
||||||
|
|
||||||
mail($mail, $subject, $msg, $headers);
|
mail($mail, $subject, $msg, $headers);
|
||||||
|
|
||||||
$f = fopen($lastfile, 'w');
|
$f = fopen($lastfile, 'w');
|
||||||
fwrite($f, $current);
|
fwrite($f, $current);
|
||||||
fclose($f);
|
fclose($f);
|
||||||
|
|
||||||
echo "New last is $current (was $last)\n";
|
echo "New last is $current (was $last)\n";
|
||||||
} else {
|
} else {
|
||||||
echo "No new XKCD: last=$last current=$current\n";
|
echo "No new XKCD: last=$last current=$current\n";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user