Update of /cvsroot/php-blog/additional_plugins/serendipity_event_ljupdate
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv484/serendipity_event_ljupdate
Added Files:
serendipity_event_ljupdate.php
Log Message:
LJ Update plugin by Rob Sayers. Crossposts an entry made in your s9y blog to your LiveJournal.
--- NEW FILE: serendipity_event_ljupdate.php ---
<?php
switch ($serendipity['lang']) {
case 'en':
default:
@define('PLUGIN_LJUPDATE_TITLE', 'LJ Update Plugin');
@define('PLUGIN_LJUPDATE_DESCRIPTION', 'Uses XMLRPC to post to your Livejournal');
break;
}
class serendipity_event_ljupdate extends serendipity_event
{
function introspect(&$propbag)
{
global $serendipity;
$propbag->add('name', PLUGIN_LJUPDATE_TITLE);
$propbag->add('description', PLUGIN_LJUPDATE_DESCRIPTION);
$propbag->add('event_hooks', array(
'backend_display' => true,
'backend_publish' => true
));
$propbag->add(
'configuration',
array(
'ljserver',
'ljusername',
'ljpass',
'ljcuttext'
)
);
}
function introspect_config_item($name, &$propbag)
{
switch($name) {
case 'ljserver':
$propbag->add('type', 'string');
$propbag->add('name', 'LJ Server');
$propbag->add('description', 'The server you use (normally www.livejournal.com)');
break;
case 'ljusername':
$propbag->add('type', 'string');
$propbag->add('name', 'LJ Username');
$propbag->add('description', 'The username you use to login to LJ');
break;
case 'ljpass':
$propbag->add('type', 'string');
$propbag->add('name', 'LJ Password');
$propbag->add('description', 'The password you use to login to LJ');
break;
case 'ljcuttext':
$propbag->add('type', 'string');
$propbag->add('name', 'LJ Cut Text');
$propbag->add('description', 'This text will be inserted before a cut. Any extended entries will show up on livejournal with a cut.');
break;
}
return true;
}
function generate_content(&$title) {
$title = PLUGIN_LJUPDATE_TITLE;
}
function event_hook($event, &$bag, &$eventData) {
global $serendipity;
$hooks = &$bag->get('event_hooks');
if (isset($hooks[$event])) {
switch($event) {
case 'backend_publish':
if ($serendipity[POST][ljmirror]){
$event=$serendipity[POST][body];
if ($serendipity[POST][extended]){
$event=$event."\n<lj-cut text='".$this->get_config('ljcuttext')."'>\n".$serendipity[POST][extended];
}
//Make LJ Entries not doublespaced
$event = str_replace("\n","",$event);
$params[username] = new XML_RPC_Value($this->get_config('ljusername'),'string');
$params[hpassword] = new XML_RPC_Value(md5($this->get_config('ljpass')),'string');
$params[event] = new XML_RPC_Value($event,'string');
$params[subject] = new XML_RPC_Value($serendipity[POST][title],'string');
$params[year] = new XML_RPC_Value(date('Y'),'string');
$params[mon] = new XML_RPC_Value(date('m'),'string');
$params[day] = new XML_RPC_Value(date('d'),'string');
$params[hour] = new XML_RPC_Value(date('H'),'string');
$params[min] = new XML_RPC_Value(date('i'),'string');
$params[security] = new XML_RPC_Value($serendipity[POST][ljsecurity],'string');
if ($serendipity[security]=='usemask'){
$params[allowmask] = new XML_RPC_Value(1,'string');
}
$props[current_mood] = new XML_RPC_Value($serendipity[POST][ljmood],'string');
$props[current_music] = new XML_RPC_Value($serendipity[POST][ljmusic],'string');
$props[picture_keyword] = new XML_RPC_Value($serendipity[POST][ljuserpic],'string');
$params[props] = new XML_RPC_Value($props,'struct');
$client = new XML_RPC_Client(
'/interface/xmlrpc',
$this->get_config('ljserver')
);
$data=new XML_RPC_Value($params,'struct');
$msg = new XML_RPC_Message('LJ.XMLRPC.postevent',array($data));
$res = $client->send($msg,10);
}
return true;
break;
case 'backend_display':
$params['username'] = new XML_RPC_Value($this->get_config('ljusername'),'string');
$params['hpassword'] = new XML_RPC_Value(md5($this->get_config('ljpass')),'string');
$params['getpickws'] = new XML_RPC_Value(1,'string');
$client = new XML_RPC_Client(
'/interface/xmlrpc',
$this->get_config('ljserver')
);
$data=new XML_RPC_Value($params,'struct');
$msg = new XML_RPC_Message('LJ.XMLRPC.login',array($data));
$res = $client->send($msg,10);
$v = $res->value();
$tmp=$v->scalarval();
$pictmp=$tmp[pickws]->scalarval();
?>
<table border="0">
<tr>
<td colspan="2"><b>LJ Update Options</b></td>
<tr>
<tr>
<td colspan="2">
<input type="checkbox" name="serendipity[ljmirror]" value="1" checked> Mirror this entry in my Livejournal
</td>
</tr>
<td>
User Picture: <select name="serendipity[ljuserpic]">
<?
for($i=0; $i<count($pictmp);$i++){
echo "<option value=\"".$pictmp[$i]->scalarval()."\">".$pictmp[$i]->scalarval()."</option>";
}
?>
</td>
<td>
Security: <select name="serendipity[ljsecurity]">
<option value="public">Public</option>
<option value="private">Private</option>
<option value="usemask">Friends</option>
</select>
</tr>
<td>Current Music: <input size="50" name="serendipity[ljmusic]"></td>
<td>Current Mood: <input size="50" name="serendipity[ljmood]"></td>
</tr>
</table>
<?
default:
return false;
break;
}
} else {
return false;
}
}
}
?>
|