');
} else if ($boundary != "") {
$content = explode('--'.$boundary, $content);
$content = $content[2];
if (preg_match('/Content-Type: multipart\/related\;[^"]*"([^"]*)"/i',$content,$matches)) {
$hatt_boundary = trim($matches[0]);
$hatt_boundary = explode('"', $hatt_boundary);
$hatt_boundary = $hatt_boundary[1];
$contents = explode('--'.$hatt_boundary, $content);
$content = $contents[1];
}
$charset = preg_match("/charset=\"([^\"]*)\"/i",$content,$matches);
if ($charset) $charset = $matches[1];
$content = explode('Content-Transfer-Encoding: quoted-printable', $content);
$content = strip_tags($content[1], '
- ,
');
}
$content = trim($content);
echo " Content-type: $content_type, boundary: $boundary \n";
echo "att_boundary: $att_boundary, hatt_boundary: $hatt_boundary \n";
// echo "Raw content:
".$content.' ';
$btpos = strpos($content, $bodyterminator);
if ($btpos) {
$content = substr($content, 0, $btpos);
}
$content = trim($content);
$blah = explode("\n", preg_replace("/^[\n\r\s]*/","",strip_tags($content)));
$firstline = preg_replace("/[\n\r]/","",$blah[0]);
$secondline = $blah[1];
if ($use_phoneemail) {
$btpos = strpos($firstline, $phoneemail_separator);
if ($btpos) {
$userpassstring = trim(substr($firstline, 0, $btpos));
$content = trim(substr($content, $btpos+strlen($phoneemail_separator), strlen($content)));
$btpos = strpos($content, $phoneemail_separator);
if ($btpos) {
$userpassstring = trim(substr($content, 0, $btpos));
$content = trim(substr($content, $btpos+strlen($phoneemail_separator), strlen($content)));
}
}
$contentfirstline = $blah[1];
} else {
$userpassstring = strip_tags($firstline);
$contentfirstline = '';
}
$flat = 999.0;
$flon = 999.0;
$secondlineParts = explode(':',strip_tags($secondline));
if(strncmp($secondlineParts[0],"POS",3)==0) {
echo "Found POS: \n";
//echo "Second parts is:".$secondlineParts[1];
// the second line is the postion listing line
$secLineParts = explode(',',$secondlineParts[1]);
$flatStr = $secLineParts[0];
$flonStr = $secLineParts[1];
//echo "String are ".$flatStr.$flonStr;
$flat = floatval($secLineParts[0]);
$flon = floatval($secLineParts[1]);
//echo "values are ".$flat." and ".$flon;
// ok remove that position... we should not have it in the final output
$content = str_replace($secondline,'',$content);
}
$blah = explode(':', $userpassstring);
$user_login = $blah[0];
$user_pass = $blah[1];
$content = $contentfirstline.str_replace($firstline, '', $content);
$content = trim($content);
//Please uncomment following line, only if you want to check user and password.
// echo "Login: $user_login, Pass: $user_pass ";
if ($xoopsDB) {
$sql = "SELECT ID, user_level FROM $tableusers WHERE user_login='".trim($user_login)."' ORDER BY ID DESC LIMIT 1";
$result = $wpdb->get_row($sql);
if (!$result) {
echo 'Wrong login ';
continue;
} else {
$sql = "SELECT * FROM ".$xoopsDB->prefix('users')." WHERE uname='".trim($user_login)."' AND pass='".md5(trim($user_pass))."' ORDER BY uid DESC LIMIT 1";
$result1 = $wpdb->get_row($sql);
if (!$result1) {
echo 'Wrong password. ';
continue;
}
}
} else {
$sql = "SELECT ID, user_level FROM $tableusers WHERE user_login='$user_login' AND user_pass='$user_pass' ORDER BY ID DESC LIMIT 1";
$result = $wpdb->get_row($sql);
if (!$result) {
echo 'Wrong login or password. ';
continue;
}
}
$user_level = $result->user_level;
$post_author = $result->ID;
if ($user_level > 0) {
$post_title = xmlrpc_getposttitle($content);
if ($post_title == '') {
$post_title = $subject;
}
$post_category = get_settings('default_category');
if (preg_match('/(.+?)<\/category>/is', $content, $matchcat)) {
$post_category = xmlrpc_getpostcategory($content);
}
if ($post_category == '') {
$post_category = get_settings('default_post_category');
}
if (function_exists('mb_convert_encoding')) {
echo "Subject : ".mb_convert_encoding($subject,$blog_charset,"auto")." ";
} else {
echo "Subject : ".$subject." ";
}
echo "Category : $post_category ";
if (!$emailtestonly) {
//Attaching Image Files Save
if ($att_boundary != "") {
$attachment = wp_getattach($contents[2],trim($user_login),1);
}
if (($boundary != "")&&($hatt_boundary != "")) {
for ($i = 2; $i < count($contents); $i++) {
$hattachment = wp_getattach($contents[$i],trim($user_login),0);
if ($hattachment) {
if (preg_match("/Content-Id: \<([^\>]*)>/i",$contents[$i],$matches)) {
$content = preg_replace("/(cid:".preg_quote($matches[1]).")/","$siteurl/attach/".$hattachment,$content);
}
}
}
}
if($boundary != "") {
$content = preg_replace("/\=[\r\n]/","",$content);
$content = preg_replace("/[\r\n]/"," ",$content);
}
$content = preg_replace("|\n([^\n])|", " $1", $content);
if ($charset == "") $charset = "JIS";
if (trim($charset) == "Shift_JIS") $charset = "SJIS";
$content = preg_replace("/\=([0-9a-fA-F]{2,2})/e", "pack('c',base_convert('\\1',16,10))", $content);
if (function_exists('mb_convert_encoding')) {
$content = addslashes(mb_convert_encoding(trim($content), $blog_charset, $charset));
$post_title = addslashes(trim(mb_convert_encoding($post_title,$blog_charset,"auto")));
} else {
$content = addslashes(trim($content));
$post_title = addslashes(trim($post_title));
}
#If we find an attachment, add it to the post
if ($attachment) {
if (file_exists("attach/thumb-".$attachment)) {
$content = "".$content." ";
} else {
$content = "".$content." ";
}
}
if($flat > 500) {
$sql = "INSERT INTO $tableposts (post_author, post_date, post_content, post_title, post_category) VALUES ($post_author, '$post_date', '$content', '$post_title', $post_category)";
} else {
$sql = "INSERT INTO $tableposts (post_author, post_date, post_content, post_title, post_category, post_lat, post_lon) VALUES ($post_author, '$post_date', '$content', '$post_title', $post_category, $flat, $flon)";
}
$result = $wpdb->query($sql);
$post_ID = $wpdb->insert_id;
echo "Post ID = $post_ID ";
if (isset($sleep_after_edit) && $sleep_after_edit > 0) {
sleep($sleep_after_edit);
}
$blog_ID = 1;
if($flat < 500) {
pingGeoUrl($post_ID);
}
pingWeblogs($blog_ID);
pingBlogs($blog_ID);
pingback($content, $post_ID);
}
echo "\nPosted title: $post_title ";
echo "\nPosted content:
".$content.' ';
// Double check it's not there already
$exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category");
if (!$exists && $result) {
$wpdb->query("
INSERT INTO $tablepost2cat
(post_id, category_id)
VALUES
($post_ID, $post_category)
");
}
if(!$pop3->delete($iCount)) {
echo 'Oops '.$pop3->ERROR.' ';
$pop3->reset();
exit;
} else {
echo "Mission complete, message $iCount deleted. ";
}
} else {
echo 'Level 0 users can\'t post. ';
}
echo '';
if ($output_debugging_info) {
ob_end_flush();
} else {
ob_end_clean();
}
}
}
$pop3->quit();
timer_stop($output_debugging_info);
exit;
function wp_getattach($content,$prefix="",$create_thumbs=0)
{
$contents = explode("\r\n\r\n",$content);
$subtype = preg_match("/Content-Type: [^\/]*\/([^\;]*);/",$contents[0],$matches);
if ($subtype) $subtype = strtolower($matches[1]);
$temp_file = "";
if (in_array($subtype, array("gif","jpg","jpeg","png"))) {
if (($prefix == 0) && eregi("name=\"?([^\"\n]+)\"?",$contents[0], $filereg)) {
$filename = ereg_replace("[\t\r\n]", "", $filereg[1]);
if (function_exists('mb_convert_encoding')) {
$temp_file = mb_convert_encoding(mb_decode_mimeheader($filename,$blog_charset,"auto"));
} else {
$temp_file = $filename;
}
}
// 添付データをデコードして保存
if (eregi("Content-Transfer-Encoding:.*base64", $contents[0])) {
$tmp = base64_decode($contents[1]);
if (!$temp_file) {
$temp_file_base = $prefix."_".time();
} else {
$temp_file_info = pathinfo($temp_file);
$temp_file_base = basename($temp_file,".".$temp_file_info["extension"]);
}
$i = 0;
$temp_file = $temp_file_base.".$subtype";
while (file_exists("attach/".$temp_file)) {
$temp_file = $temp_file_base."-".$i.".$subtype";;
$i++;
}
if (!($temp_fp = fopen("attach/" . $temp_file, "w"))) {
echo("error1");
continue;
}
fputs($temp_fp, $tmp);
fclose($temp_fp);
if ($create_thumbs) {
wp_create_thumbnail("attach/" .$temp_file,180,"");
}
}
echo "$temp_file ";
return $temp_file;
}
return false;
}
function wp_create_thumbnail($file, $max_side, $effect = '') {
// 1 = GIF, 2 = JPEG, 3 = PNG
if(file_exists($file)) {
$type = getimagesize($file);
// if the associated function doesn't exist - then it's not
// handle. duh. i hope.
if(!function_exists('imagegif') && $type[2] == 1) {
$error = 'Filetype not supported. Thumbnail not created.';
}elseif(!function_exists('imagejpeg') && $type[2] == 2) {
$error = 'Filetype not supported. Thumbnail not created.';
}elseif(!function_exists('imagepng') && $type[2] == 3) {
$error = 'Filetype not supported. Thumbnail not created.';
} else {
// create the initial copy from the original file
if($type[2] == 1) {
$image = imagecreatefromgif($file);
} elseif($type[2] == 2) {
$image = imagecreatefromjpeg($file);
} elseif($type[2] == 3) {
$image = imagecreatefrompng($file);
}
if (function_exists('imageantialias'))
imageantialias($image, TRUE);
$image_attr = getimagesize($file);
// figure out the longest side
if($image_attr[0] > $image_attr[1]) {
$image_width = $image_attr[0];
$image_height = $image_attr[1];
$image_new_width = $max_side;
$image_ratio = $image_width/$image_new_width;
$image_new_height = $image_height/$image_ratio;
//width is > height
} else {
$image_width = $image_attr[0];
$image_height = $image_attr[1];
$image_new_height = $max_side;
$image_ratio = $image_height/$image_new_height;
$image_new_width = $image_width/$image_ratio;
//height > width
}
$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
@imagecopyresized($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
// move the thumbnail to it's final destination
$path = explode('/', $file);
$thumbpath = substr($file, 0, strrpos($file, '/')) . '/thumb-' . $path[count($path)-1];
if($type[2] == 1) {
if(!imagegif($thumbnail, $thumbpath)) {
$error = "Thumbnail path invalid";
}
} elseif($type[2] == 2) {
if(!imagejpeg($thumbnail, $thumbpath)) {
$error = "Thumbnail path invalid";
}
} elseif($type[2] == 3) {
if(!imagepng($thumbnail, $thumbpath)) {
$error = "Thumbnail path invalid";
}
}
}
}
if(!empty($error))
{
return $error;
}
else
{
return 1;
}
}
?>
|
|