*/
function wppost_install() {
register_hook('post_local_end', 'addon/wppost/wppost.php', 'wppost_send');
register_hook('jot_networks', 'addon/wppost/wppost.php', 'wppost_jot_nets');
register_hook('plugin_settings', 'addon/wppost/wppost.php', 'wppost_settings');
register_hook('plugin_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
}
function wppost_uninstall() {
unregister_hook('post_local_end', 'addon/wppost/wppost.php', 'wppost_send');
unregister_hook('jot_networks', 'addon/wppost/wppost.php', 'wppost_jot_nets');
unregister_hook('plugin_settings', 'addon/wppost/wppost.php', 'wppost_settings');
unregister_hook('plugin_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
}
function wppost_jot_nets(&$a,&$b) {
if(! local_user())
return;
$wp_post = get_pconfig(local_user(),'wppost','post');
if(intval($wp_post) == 1) {
$wp_defpost = get_pconfig(local_user(),'wppost','post_by_default');
$selected = ((intval($wp_defpost) == 1) ? ' checked="checked" ' : '');
$b .= '
'
. t('Post to Wordpress') . '
';
}
}
function wppost_settings(&$a,&$s) {
if(! local_user())
return;
/* Add our stylesheet to the page so we can make our settings look nice */
$a->page['htmlhead'] .= '' . "\r\n";
/* Get the current state of our config variables */
$enabled = get_pconfig(local_user(),'wppost','post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$def_enabled = get_pconfig(local_user(),'wppost','post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$wp_username = get_pconfig(local_user(), 'wppost', 'wp_username');
$wp_password = get_pconfig(local_user(), 'wppost', 'wp_password');
$wp_blog = get_pconfig(local_user(), 'wppost', 'wp_blog');
/* Add some HTML to the existing form */
$s .= '';
$s .= '
' . t('WordPress Post Settings') . '
';
$s .= '
';
$s .= '';
$s .= '';
$s .= '
';
$s .= '
';
$s .= '';
$s .= '';
$s .= '
';
$s .= '
';
$s .= '';
$s .= '';
$s .= '
';
$s .= '
';
$s .= '';
$s .= '';
$s .= '
';
$s .= '
';
$s .= '';
$s .= '';
$s .= '
';
/* provide a submit button */
$s .= '
';
}
function wppost_settings_post(&$a,&$b) {
if(x($_POST,'wppost-submit')) {
set_pconfig(local_user(),'wppost','post',intval($_POST['wppost']));
set_pconfig(local_user(),'wppost','post_by_default',intval($_POST['wp_bydefault']));
set_pconfig(local_user(),'wppost','wp_username',trim($_POST['wp_username']));
set_pconfig(local_user(),'wppost','wp_password',trim($_POST['wp_password']));
set_pconfig(local_user(),'wppost','wp_blog',trim($_POST['wp_blog']));
}
}
function wppost_send(&$a,&$b) {
if((! local_user()) || (local_user() != $b['uid']))
return;
if($b['prvnets'] && $b['private'])
return;
if($b['parent'])
return;
$wp_username = get_pconfig(local_user(),'wppost','wp_username');
$wp_password = get_pconfig(local_user(),'wppost','wp_password');
$wp_blog = get_pconfig(local_user(),'wppost','wp_blog');
$wp_post = intval(get_pconfig(local_user(),'wppost','post'));
$wp_enable = (($wp_post && x($_POST,'wppost_enable')) ? intval($_POST['wppost_enable']) : 0);
if($_POST['api_source'] && intval(get_pconfig(local_user(),'wppost','post_by_default')))
$wp_enable = 1;
if($wp_username && $wp_password && $wp_blog && $wp_post && $wp_enable) {
require_once('include/bbcode.php');
$post = (($b['title']) ? '' . $b['title'] . '' : '');
$post .= bbcode($b['body']);
$post = xmlify($post);
$xml = <<< EOT
blogger.newPost
$wp_username
$wp_password
$post
1
EOT;
logger('wppost: data: ' . $xml, LOGGER_DATA);
if($wp_blog !== 'test')
$x = post_url($wp_blog,$xml);
logger('posted to wordpress');
}
}