b2evolutionにモブログ機能付加
まずblogs/b2evocore/_functions_mailpost.php
ファイルを作成する。
<?php
/**
* Mailpost functions
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evocore
* @author Hiroshi Miura - {@link http://blogs.da-cha.jp/}
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
require_once('Mail/mimeDecode.php');
/**
* post_from_mail(-)
*
* post article from mail content
*
* H.Miura: split from getmail.php
*/
function post_from_mail($MsgOne, $output_debugging_info, $user_login=null, $user_pass=null)
{
global $thisisforfunonly,$Settings,$bodyterminator,$default_category;
$params['include_bodies'] = true;
$params['decode_bodies'] = true;
$params['decode_headers'] = true;
$params['input'] = $MsgOne;
if ($output_debugging_info > 0) {
echo T_('Processing content...'), "<br />\n";
}
$structure = Mail_mimeDecode::decode($params);
//$decode = new Mail_mimeDecode($MsgOne, "\r\n");
//$structure = $decode->decode($params);
$subject = trim($structure->headers['subject']);
$subject = htmlspecialchars(mb_convert_encoding($subject, 'utf-8', 'auto'));
$ddate = strtotime($structure->headers['date']);
$ddate += $Settings->get('time_difference')*3600;
$post_date = date('Y-m-d H:i:s', $ddate);
$ddate_today = time() + ($Settings->get('time_difference') * 3600);
$ddate_difference_days = ($ddate_today - $ddate) / 86400;
# starts buffering the output
ob_start();
if ($output_debugging_info > 0) {
echo T_('Check From address...'), "<br />\n";
}
$from = trim($structure->headers['from']);
$returnpath = trim($structure->headers['return-path']);
if (preg_match('/^[^<>]+<([^<>]+)>$/',$from, $matches) )
{
$from = $matches[1];
}
if ($ddate_difference_days > 14)
{
if ($output_debugging_info > 0) {
echo T_('Too old'), '<br />';
}
return(false);
}
if ($output_debugging_info > 1)
{
echo '<div style="border: 1px dashed #999; padding: 10px; margin: 10px;">';
echo "<p><strong>Subject: </strong>$subject</p>\n";
}
$content = get_content($structure);
$search = array (
'/ (\n|\r\n|\r)/','/(\n|\r\n|\r)/'
);
$replace = array (
' ',"\n"
);
$content = mb_convert_encoding($content, 'utf-8', "auto");
$content = preg_replace($search, $replace, trim($content));
if ($output_debugging_info > 1)
{
echo '<p><strong>', T_('Raw content:'), '</strong><br /><xmp>', $content, '</xmp></p>';
}
$btpos = strpos($content, $bodyterminator);
if ($btpos) {
$content = substr($content, 0, $btpos);
}
$content = trim($content);
if ($user_login==null || $user_pass==null)
{
$ret = retrive_userpass($content);
$content = trim($ret[2]);
$user_login = $ret[0];
$user_pass = $ret[1];
}
if ($output_debugging_info > 1)
{
echo '<p><strong>', T_('Login:'), '</strong> ', $user_login, ', <strong>', T_('Pass:'), '</strong> ', $user_pass, '</p>';
}
if( !user_pass_ok( $user_login, $user_pass ) )
{
if ($output_debugging_info > 1) {
echo '<p><strong>', T_('Wrong login or password.'), '</strong></p></div>';
}
return(false);
}
$userdata = get_userdatabylogin($user_login);
$loop_User = & new User( $userdata );
// --- get infos from content -----------
$post_title = xmlrpc_getposttitle($content);
if ($post_title == '')
{
$post_title = $subject;
}
if( ! ($post_category = xmlrpc_getpostcategory($content) ) )
{
$post_category = $default_category;
}
if ($output_debugging_info > 0) {
echo '<p><strong>', T_('Category ID'), ':</strong> ',$post_category,'</p>';
}
$content = xmlrpc_removepostdata( $content );
$blog_ID = get_catblog($post_category); // TODO: should not die, if cat does not exist!
if ($output_debugging_info > 0) {
echo '<p><strong>', T_('Blog ID'), ':</strong> ',$blog_ID,'</p>';
}
// Check permission:
if( ! $loop_User->check_perm( 'blog_post_statuses', 'published', false, $blog_ID ) )
{
if ($output_debugging_info > 1) {
echo "\n", T_('Permission denied.'), '<br />';
}
return(false);
}
if (!$thisisforfunonly)
{
// CHECK and FORMAT content
$post_title = format_to_post( trim($post_title), 0, 0 );
$content = format_to_post( trim($content), $Settings->get('AutoBR'), 0);
if( errors_display( T_('Cannot post, please correct these errors:'), '' ) )
{
$errors = array();
if ($output_debugging_info > 1) {
echo '</div>';
}
return(false);
}
// INSERT NEW POST INTO DB:
$post_ID = bpost_create( $loop_User->ID, $post_title, $content, $post_date, $post_category, array(), 'published', $loop_User->locale, '', $Settings->get('AutoBR'), true );
if (isset($sleep_after_edit) && $sleep_after_edit > 0)
{
sleep($sleep_after_edit);
}
$blogparams = get_blogparams_by_ID( $blog_ID );
pingback( true, $content, $post_title, '', $post_ID, $blogparams, true);
pingb2evonet( $blogparams, $post_ID, $post_title);
pingWeblogs($blogparams);
pingBlogs($blogparams);
pingTechnorati($blogparams);
}
if ($output_debugging_info > 1) {
echo "\n<p><strong>", T_('Posted title'), ':</strong> ', $post_title, '<br />';
echo "\n<strong>", T_('Posted content'), ':</strong><br /><xmp>', $content, '</xmp></p>';
echo '</div>';
ob_end_flush();
}
else
{
ob_end_clean();
}
return(true);
}
function get_content($part)
{
global $fileupload_realpath, $fileupload_url;
$piece_of_code = '';
switch (strtolower($part->ctype_primary))
{
case 'multipart':
$piece_of_code = '';
foreach ($part->parts as $section)
{
$piece_of_code .= get_content($section);
}
break;
case 'text':
if ($part->ctype_secondary == 'enriched') {
} else if ($part->ctype_secondary == 'html') {
$piece_of_code = strip_htmlmail_tags($part->body) . "\n";
} else if ($part->ctype_secondary == 'text') {
$piece_of_code = strip_tags(convert_to_html_entity($part->body)) . "\n";
} else {
$piece_of_code = strip_tags(convert_to_html_entity($part->body)) . "\n";
}
break;
case 'image':
$photo_save_dir = $fileupload_realpath;
$file_src = $part->ctype_parameters['name'];
$photo_save_filename = $photo_save_dir .'/'. $file_src;
// we need to detect filename duplication.
$fp = fopen($photo_save_filename,'w');
fwrite($fp, $part->body);
fclose($fp);
$img_size = GetImageSize($photo_save_filename);
$piece_of_code = '<img src="'.$fileupload_url.'/'.$file_src.'"';
if ( $img_dimensions = getimagesize( $photo_save_filename ) )
{ // add width and hight
$piece_of_code .= ' width="'.$img_dimensions[0].'" height="'.$img_dimensions[1].'"';
}
$piece_of_code .= ' alt="photo" />';
break;
}
return $piece_of_code;
}
function retrive_userpass ($content)
{
global $use_phoneemail, $phoneemail_separator;
$blah = explode("\n", $content);
$firstline = $blah[0];
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 = $firstline;
$contentfirstline = '';
}
$blah = explode(':', $userpassstring);
$user_login = trim($blah[0]);
$user_pass = @trim($blah[1]);
$content = $contentfirstline.str_replace($firstline, '', $content);
return (array($user_login, $user_pass, $content));
}
function from_match($my_mobile) {
if (eregi("[-!#$%&\'*+\\./0-9A-z^_`a-z{|}~]+@[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+", $my_mobile, $pattern)) {
return $pattern[0];
} else {
return false;
}
}
function strip_htmlmail_tags($content) {
return strip_tags($content[1], '<p><br><i><b><u><em><strong><strike><font><span><div>');
}
function convert_to_html_entity($string) {
$txt = str_replace('&','&',$string);
$txt = str_replace('"','"',$txt);
$txt = str_replace('<','<',$txt);
$txt = str_replace('>','>',$txt);
return $txt;
}
?>
これでメールからのポストで使用する共通的に使用するライブラリ部分の整備ができた。
次は、既存のgetmail.phpの置き換えである。
この記事へのトラックバック アドレス
トラックバック URL (右をクリックし、ショートカット/リンクをコピーして下さい)
モデレーション待ちのフィードバック
この投稿にはモデレーション待ちのフィードバックが 135 件あります....