$TITLE
// Version: 2.17 (2005-03-19)
// Author discontinued simsi support in apr 2005
// Modified for use on personal website mobipics.net sep 2005
// configuration variables
$BLOG_TITLE = "mobiPICS";
$BLOG_SUBTITLE = "mobile picture weblog";
$MAIL_SERVER = "mail.mobipics.net";
$MAIL_USERNAME = "pics@mobipics.net";
$MAIL_PASSWORD = "byj042";
$MAIL_QUERY_INTERVAL = 0;
$PICTURE_FOLDER = "pics";
$POSTS_PER_PAGE = 20;
$PREVIOUS_CAPTION = "<< PREVIOUS";
$NEXT_CAPTION = "NEXT >>";
$THUMBNAIL_SIZE = 180;
$SHARED_EMAIL = TRUE;
$ALLOWED_SENDERS = "@";
$DISPLAY_EMAIL = FALSE;
$DATE_FORMAT = 'm/d/Y H:i';
$MAX_IMAGE_SIZE = 4000000;
// create thumbnails of attachments
function create_thumbnail($filename)
{
global $THUMBNAIL_SIZE, $PICTURE_FOLDER;
$original = imagecreatefromjpeg("$PICTURE_FOLDER/$filename");
$twidth = $THUMBNAIL_SIZE;
$owidth = imagesx($original);
$oheight = imagesy($original);
$ratio = $owidth / $twidth;
$theight = $oheight / $ratio;
$thumbnail = imagecreatetruecolor($twidth, $theight);
imagecopyresampled($thumbnail, $original, 0, 0, 0, 0, $twidth, $theight, $owidth, $oheight);
imagejpeg($thumbnail, "$PICTURE_FOLDER/t_$filename");
imagejpeg($thumbnail, "latest.jpg");
imagedestroy($original);
imagedestroy($thumbnail);
}
$BLOG_URL = "http://" . preg_replace("/index.php/", "", $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']);
// read template.html and parse into correct header, posts and footer
if (! $template = @file_get_contents("template.html"))
die("could not open 'template.html'. quitting ...");
$template = preg_replace("/{BLOG_URL}/U", "$BLOG_URL", $template);
$template = preg_replace("/{BLOG_TITLE}/U", "$BLOG_TITLE", $template);
$template = preg_replace("/{BLOG_SUBTITLE}/U", "$BLOG_SUBTITLE", $template);
// read rss.xml, create a new file if necessary
if (! $file = @fopen("rss.xml", "r+"))
if (! $file = @fopen("rss.xml", "w+"))
die("permission problem with 'rss.xml'. quitting ...");
fclose($file);
$rss = file_get_contents("rss.xml");
// extract dates, authors and contents from rss.xml
preg_match_all("/(.*)?<\/title>/Ums", $rss, $titles);
$titles = array_splice($titles[1], 1);
preg_match_all("/(.*)?<\/date>/Ums", $rss, $dates);
$dates = $dates[1];
preg_match_all("/(.*)?<\/description>/Ums", $rss, $contents);
$contents = array_splice($contents[1], 1);
preg_match_all("/(.*)?<\/author>/Ums", $rss, $authors);
$authors = $authors[1];
// determine page to display
if (! isset($_GET["page"]))
$page = 0;
else
$page = $_GET["page"];
$prev = $page - 1;
$next = $page + 1;
if ($page > 0)
$PREVIOUS_PAGE = "$PREVIOUS_CAPTION";
else
$PREVIOUS_PAGE = "";
if ($page * $POSTS_PER_PAGE < count($titles) - $POSTS_PER_PAGE)
$NEXT_PAGE = "$NEXT_CAPTION";
else
$NEXT_PAGE = "";
$template = preg_replace("/{PREVIOUS_PAGE}/U", "$PREVIOUS_PAGE", $template);
$template = preg_replace("/{NEXT_PAGE}/U", "$NEXT_PAGE", $template);
$html = explode("-*!", $template);
echo $html[0];
if ($page == 0 && filemtime("rss.xml") + $MAIL_QUERY_INTERVAL < time()) {
// open mailbox and get emails from server
// if (! $mail = imap_open( "{" . $MAIL_SERVER . ":110/pop3/notls}INBOX", $MAIL_USERNAME, $MAIL_PASSWORD))
if (! $mail = imap_open( "{" .$MAIL_SERVER . ":110/pop3/notls}INBOX", $MAIL_USERNAME, $MAIL_PASSWORD))
die("could not connect to mailserver. quitting ...");
$headerstrings = imap_headers($mail);
foreach ($headerstrings as $headerstring)
{
$multipart = FALSE;
$imagecounter = 1;
preg_match("/[0-9]/", $headerstring, $number);
echo $number;
// parse message and sender
$header = imap_fetchheader($mail, $number[0]);
preg_match("/Date: (.*)?[\+|-]/", $header, $date);
$date = htmlentities($date[1]);
$date = date($DATE_FORMAT, strtotime($date));
echo $date;
$headerinfo = imap_headerinfo($mail, $number[0], 256, 256);
$email = " <" . $headerinfo->from[0]->mailbox . "@" . $headerinfo->from[0]->host . ">";
$decode = imap_mime_header_decode($headerinfo->from[0]->personal);
$sender = $decode[0]->text;
echo $sender;
$sender .= $email;
$decode = imap_mime_header_decode($headerinfo->fetchsubject);
$subject = $decode[0]->text;
echo $subject;
$imap = imap_fetchstructure($mail, $number[0]);
if (! empty($imap->parts))
{
for($i = 0, $j = count($imap->parts); $i < $j; $i++)
{
echo "count = " .$i;
$part = $imap->parts[$i];
echo $part->bytes;
if ($part->bytes < $MAX_IMAGE_SIZE)
{
$msg = imap_fetchbody($mail, $number[0], $i + 1);
// save image
//echo " pbytes=" . $part->bytes;
//echo " disposition=" . $part->disposition;
//echo " type= " . $part->type;
//echo " subtype= " . $part->subtype;
if ($part->disposition == ATTACHMENT || $part->type == TYPEIMAGE || ($part->type == TYPEAPPLICATION && $part->subtype <> "SMIL"))
{
if ($part->subtype == "JPEG" || $part->subtype == "OCTET-STREAM")
{
if (! $handle = @fopen("$PICTURE_FOLDER/" . md5($date) . "_$imagecounter.jpg", "w"))
die("no permission to write image. quitting ...");
fwrite($handle, imap_base64($msg));
fclose($handle);
create_thumbnail(md5($date)
zuhoheumpwx
upocihueresjg