Recent Topics

1 May 16, 2005 01:25    

I'm not sure how many will find this useful.. I suppose if there's just one of you out there who use LiveJournal and don't want to sever your ties to that community, you may find this hack/mod of great use. I am far from a PHP professional but I was able to get this working from a WordPress plugin.

In its current state, this works as follows: A checkbox labeled "Update LiveJournal" is placed under the text entry area when you are creating a new post in your b2e blog. If the box is checked, a copy of your post is automatically sent to LiveJournal's API. And as you may imagine, unchecking the box will keep the post on your b2e blog only.

There are some slight bugs and limitations at the current time, which I'm working on. If anyone wants to pick this up and modify it, by all means feel free. The issues are:

--Currently, the livejournal login and password is 'hard coded', so if you have multiple users in b2e, anyone posting to their blog would have their post show up on your livejournal.
--The post's text is not 'cleaned up'. I have not tried this with anything beyond plain text and html formatting (img and href's). I do not know how LJ will treat the "more" tag, smiley graphics, 'code' and 'quote' text types, etc.
-- LJ appears to be adding extra line breaks to the post. A single return in b2e translates into 2 BR's when it gets to LJ. I'm sure this, as well as the above issue, can be fixed, I just need the time to look into it.

Implementation: 4 files need to be updated. b2evocore/_functions_bpost.php, admin/_edit_form.php, admin/edit_actions.php, and conf/hacks.php. (hacks.php did not exist in my installation, I had to create it. )

b2evocore/_functions_bpost.php:

Find the bpost_create function. Should be first in the file. Find the last item in the function variable list (around line 36) - after "$post_renderers = array('default')", add a comma and "$ljautoupdate". Final function should look like:


function bpost_create(
	$author_user_ID,              // Author
	$post_title,
	$post_content,
	$post_timestamp,              // 'Y-m-d H:i:s'
	$main_cat_ID = 1,             // Main cat ID
	$extra_cat_IDs = array(),     // Table of extra cats
	$post_status = 'published',
	$post_locale = '#',
	$post_trackbacks = '',
	$autobr = 0,                  // No AutoBR has been used by default
	$pingsdone = true,
	$post_urltitle = '',
	$post_url = '',
	$post_comments = 'open',
	$post_renderers = array('default'),
	$ljautoupdate )

At approximately line 76/77 should be the end of the statements that are writing your post variables to the database. At the end of this long statement, insert the following:


	if ( $ljautoupdate )
		{
		echo '<h3><font color=green>Posting to LiveJournal...</font></h3>';
		ljautoupdate( $post_content, $post_title );
		}

admin/_edit_form.php:

Find the "--TEXT AREA--" section at around line 152. This begins with 'div class="edit area"..'. At the end of this line, and BEFORE the ending DIV tag, insert the following:


	<!-- added for LJ checkbox -->
	&nbsp;&nbsp;<input value='1' type='checkbox' name='ljautoupdate' id='1' checked="checked" /> Update LiveJournal

Final should look like:


	<div class="edit_area"><img src="img/blank.gif" width="1" height="1" alt="" /><textarea rows="16" cols="40" name="content" id="content" tabindex="4"><?php echo $content ?></textarea><img src="img/blank.gif" width="1" height="1" alt="" />
	
	<!-- added for LJ checkbox -->
	&nbsp;&nbsp;<input value='1' type='checkbox' name='ljautoupdate' id='1' checked="checked" /> Update LiveJournal
</div>

admin/edit_actions.php:

At around line 125 you'll find the post function being called....


$post_ID = bpost_create( $user_ID,....

Before this line, enter:


$ljautoupdate = $HTTP_POST_VARS['ljautoupdate'];

Also, to the end of the bpost_create() function, add "$ljautoupdate", along with a comma after the previous variable.

Final here should look like:


		// INSERT NEW POST INTO DB:
     	$ljautoupdate = $HTTP_POST_VARS['ljautoupdate'];
		$post_ID = bpost_create( $user_ID, $post_title, $content, $post_date, $post_category,	
															$post_extracats, $post_status, $post_locale, '',	$post_autobr, 
															$pingsdone, $post_urltitle, $post_url, $post_comments,
															$post_renderers, $ljautoupdate );

Finally, hacks.php:

Again, if this doesn't exist in the 'conf' folder, create it. Enter the following, and be sure to enter your actual LJ userid and password in the lines provided:


<?php

function ljautoupdate ($content, $post_title ) {
		/*ljautoupdate*/
			$lj_userid = "xxx";  //Your LiveJournal username, please replace within quotes
			$lj_passwd = "xxx";  //Your LiveJournal password, please replace within quotes
			$lj_method = "LJ.XMLRPC.postevent";
			$lineendings = "pc";
			//$content = $content + "<BR><font size=-1>Posted via my B2E blog.";
				//$content = convert_bbcode($content);
				//$content = convert_gmcode($content);
				//$content = convert_smilies($content);
				//$content = convert_chars($content, 'html');
				//$content = apply_filters('the_content', $content);
				$event = $content;
				$subject = $post_title;
			   //$time_difference = get_settings("time_difference");
			   //$timenow = getdate();
			   $year = date('Y', (time() + ($time_difference * 3600)));
			   //$year = $timenow["year"];
			   $month = date('m', (time() + ($time_difference * 3600)));
			   //$month = $timenow["mon"];
			   $day = date('d', (time() + ($time_difference * 3600)));
			   //$day = $timenow["mday"];
		  	   $hour = date('H', (time() + ($time_difference * 3600)));
			   //$hour = $timenow["hours"];
			   $minute = date('i', (time() + ($time_difference * 3600)));
			   //$minute = $timenow["minutes"];
			    $client = new xmlrpc_client("/interface/xmlrpc", "www.livejournal.com", 80);
				$x_params_r = array( "username" => utf8_encode( $lj_userid ),
										"password" => utf8_encode( $lj_passwd ),
										"lineendings" => $lineendings,
										"event" => utf8_encode( $event ),
										"subject" => utf8_encode( $subject ),
										"year" => utf8_encode( $year ),
										"mon" => utf8_encode( $month ),
										"day" => utf8_encode( $day ),
										"hour" => utf8_encode( $hour ),
										"min" => utf8_encode( $minute ));
										//print_r($x_params_r);
				$params = array( xmlrpc_encode( $x_params_r ) );
				$msg = new xmlrpcmsg('LJ.XMLRPC.postevent', $params);
				$client->setDebug(0);
				$result = $client->send($msg);
				if ($result->faultCode() != 0)
				{
					print "Couldn't process request: " . $result->faultString();
					return 1;
				}
		/*end ljautoupdate*/
		}
?>

You'll see that I've commented out some items that are cleaning up the text before it's sent to LJ. These apparently are native functions to WordPress and don't work in B2E. I or someone else will need to create comparable code to clean the text prior to transmission.

Still a work in progress, but it works.

Good luck.. I'll post any updates if I have them. If you have used this, drop a note so I know I should continue working on it! :-)

2 Aug 16, 2005 03:11

Hello, thanks for this, its a cool idea
ive broken it tho :(

on edit_actions.php i get

:: Adding new post...
Recording post...

Warning: Missing argument 16 for bpost_create() in /home/lungshri/public_html/b2evocore/_functions_bposts.php on line 37

Done.

I've checked a few times your instructions

in edit_actions.php i have

// INSERT NEW POST INTO DB:
$ljautoupdate = $HTTP_POST_VARS['ljautoupdate'];
$post_ID = bpost_create( $user_ID, $post_title, $content, $post_date, $post_category, $post_extracats, $post_status, $post_locale, '', $post_autobr, $pingsdone, $post_urltitle, $post_url, $post_comments, $post_renderers, $ljautoupdate );

so if its getting via post, that would mean its not getting it from _edit_form.php
but there i have

<div class="edit_area"><img src="img/blank.gif" width="1" height="1" alt="" /><textarea rows="16" cols="40" name="content" id="content" tabindex="4"><?php echo $content ?></textarea><img src="img/blank.gif" width="1" height="1" alt="" />
<!-- added for LJ checkbox -->
&nbsp;&nbsp;<input value='1' type='checkbox' name='ljautoupdate' id='ljautoupdate' checked="checked" /> Update LiveJournal

</div>

Also I just noticed when editing template that this script causes.

Warning: Cannot modify header information - headers already sent by (output started at /home/lungshri/public_html/conf/hacks.php:54) in /home/lungshri/public_html/admin/b2template.php on line 41


Form is loading...