<?php
/*
Plugin Name: SprintPhoto_Debug
Version: 0.2.2x
Plugin URI: http://bekit.net/archives/category/blog-development/
Description: Allow Sprint Picture Share to be posted with email blogging.
Author: Brint E. Kriebel
Author URI: http://bekit.net
*/
/*
Notes: Based partially off of code from phone2blog by LaughingLizard: http://weblogtoolscollection.com/archives/2004/07/17/sprint-pcs-moblog-to-wordpress-12-mingus/
To be used in addition to cool_blade's modified wp-mail.php code.
Instructions:
1. Install the modified wp-mail.php code from http://blade.lansmash.com/index.php?cat=5 (or my modified version of it).
2. Copy SprintPhoto.php into the wordpress plugins directory (typically wp-content/plugins)
3. Create the directories for photo storage specified in wp-mail.php. Downloaded images will be stored here.
4. Activate the SprintPhoto plugin through your administrative pages.
5. Follow the "How to Blog by eMail" guide:
http://wiki.wordpress.org/How%20To%20Blog%20By%20Email
6. Send a picture share as usual to the email adress you have created.
a. Voice attachments not currently implimented.
b. For text messages:
By default it will pull a text message in as the title (example: "This is my title!")
You can modify the Category of the post using brackets with the category id (example: "[2] This is my title!" - this will post into the category with id #2)
You can add a text post that will show under the image by sepating the title with a semicolon (example: "[2] This is my title!; This is the text of the post.")
If no text message is selected, the default title can be defined by the variable "$defaultTitle".
7. Browse to the wp-mail.php page - it will begin processing your email.
8. Regular emails will process as normal posts.
9. The full scale image as well as a thumbnail will be downloaded to the photos directory.
A blog will be posted per your configuration of wp-mail.php with the thumbnail linking to the
full image, the category, title and text of the post will be implimented as described above.
Changelog:
0.2.2x
Added debugging lines to help resolve issues.
0.2.2
Change to filehandling.
The plugin should no longer require the GD Libraries.
PHP => 4.3.0 is required for the new file handling.
0.2.1
Minor bugfix
Fixed:
Special characters (such as & or ') would cause the script to bomb with an SQL error
0.2
Fixed:
Incorrect date/time stamp.
Permalinks not working correctly.
Added:
Title can now be adjusted (and defaulted).
Now using wp-mail.php hack from http://blade.lansmash.com/index.php?cat=5 (Some modifications made).
Category can be adjusted (thanks to blade's wp-mail).
A message can be planted in addition to the Title.
The downloaded images are named to the date-title.
0.1
Initial release.
To-Do:
1. Bug-fix as needed.
Known bugs:
None that i've found :)
2. Add functionality for voice messages.
3. Possibly turn this into a full Sprint Vision plugin for text messages, picturemail and videomail. (Optimism is a good thing).
Last Modified: 2004-11-10
*/
function SprintPictureShare($post_ID) {
print "Sprintphoto activated on post id:" . $post_ID . "<br>";
//Initiate global variables
global $wpdb, $tableposts,$post_categories,$photosdir;
print "Getting post data<br>";
//Pull in post information
$postData = get_postdata($post_ID);
//Define variables.
$defaultTitle = "MobLog: " . $postData['Date']; //Default title is none is specified in the message.
$thumbSize = "235"; //Thumbnail image size - largest side. (Default: 235)
print "Gathering content<br>";
//Gather content to be examined / modified
$content = $postData['Content'];
$post_title = $postData['Title'];
print "Checking for Vision header<br>";
//Check if it is a Sprint Picture Mail message.
if (preg_match('/A Picture from my PCS Vision Camera/', $content)) {
print "Header found - continuing with script<br>";
print "Getting posision of image URL<br>";
//Get the position of the image URL from the message
$imagePos = strpos($content, "shareImage") + 11;
$imageLength = strpos($content, "_235.jpg", $imagePos) - $imagePos;
print "Getting invite string<br>";
//The invite string is needed for authorization
$invitePos = strpos($content, "invite=") + 7;
$inviteLength = strpos($content, """, $invitePos) - $invitePos;
print "Getting text portion of message<br>";
//Get the text portion of the message - this will be attached to the blog entry
$messagePos = strpos($content, "Message:</b><br/>") + 29;
$messageLength = strpos($content, "</font>", $messagePos) - $messagePos;
print "Pulling data from message<br>";
//Take all of the locations and pull the data from the message
$imageName = substr($content, $imagePos, $imageLength);
$inviteName = substr($content, $invitePos, $inviteLength);
if ($messageLength != 0) $message = substr($content, $messagePos, $messageLength);
print "Determining category<br>";
//Try and determine category.
if ( preg_match('/.*\[(.+)\](.+)/', $message, $matches) )
{
$post_categories[0] = $matches[1];
$message = $matches[2];
}
if (empty($post_categories)) $post_categories[] = get_settings('default_category');
print "Check for semicolon for post text<br>";
//If there is a semicolon, make the text after it be the post text.
list($mypost_title, $mypost_text) = explode(";", html_entity_decode($message));
trim($mypost_title);
trim($mypost_text);
print "Setting title<br>";
//If there is a text message, set the title of the post to the text.
if ($mypost_title) {
$post_title = $mypost_title;
} elseif($defaultTitle) {
$post_title = $defaultTitle;
}
print "Creating post slug<br>";
//Create the post name (slug) from the post title.
$post_name = sanitize_title($post_title);
print "Setting locations<br>";
//Put together the location of the full quality image and the thumbnail
$thumbLoc = "http://pictures.sprintpcs.com//shareImage/" . $imageName . "_$thumbSize.jpg?invite=$inviteName";
$imageLoc = "http://pictures.sprintpcs.com//shareImage/$imageName.jpg?invite=$inviteName";
print "Creating image name<br>";
//Create image name. (format at will)
$myImageName = sanitize_title($postData['Date']) . "-" . $post_name;
print "Downloading thumbnail<br>";
//Download the thumbnail
copy($thumbLoc, ABSPATH.$photosdir.$myImageName."_thumb.jpg");
print "Downloading image<br>";
//Download the image
copy($imageLoc, ABSPATH.$photosdir.$myImageName.".jpg");
print "Creating local URLs<br>";
//Create the local image/thumb URLs
$photosdir = preg_replace('|^/+|', '', $photosdir); //Clean up spare forward slashes
$localImage = get_settings('home') . "/" . $photosdir . $myImageName . ".jpg";
$localThumb = get_settings('home') . "/" . $photosdir . $myImageName . "_thumb.jpg";
print "Creating link from thumnail to image<br>";
//Create the link from the thumbnail to the full image
$imageLink = "<a href=$localImage><img src=$localThumb></a>";
print "Creating content of post<br>";
//Post the image as the message content. Add formatting at will.
if (!$mypost_text) {
$myContent = "$imageLink";
} else {
$myContent = "$imageLink<p>$mypost_text";
}
print "Cleaning the data of the post<br>";
//Clean up the data to avoid special characters
$myContent = addslashes($myContent);
$post_title = addslashes($post_title);
print "Outputing data to database<br>";
//Output reformatted data.
$wpdb->query("UPDATE $tableposts SET post_content = '$myContent', post_title = '$post_title', post_name = '$post_name' WHERE ID = '$post_ID'");
}
print "Done.<br>";
}
//Add the action to be used in the wp-mail.php script through the "publish_phone" hook
add_action('publish_phone', 'SprintPictureShare', 9);
?>