From: Friendika Date: Thu, 8 Sep 2011 04:10:56 +0000 (-0700) Subject: first commit - Wordpress post plugin X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=40a8b4d13f301565c4300983448c76b2249c49c6;p=friendica-addons.git first commit - Wordpress post plugin --- diff --git a/wppost.tgz b/wppost.tgz new file mode 100644 index 00000000..d18ed64f Binary files /dev/null and b/wppost.tgz differ diff --git a/wppost/wppost.css b/wppost/wppost.css new file mode 100644 index 00000000..de876958 --- /dev/null +++ b/wppost/wppost.css @@ -0,0 +1,16 @@ + +#wppost-enable-label, #wppost-username-label, #wppost-password-label, #wppost-blog-label, #wppost-bydefault-label { + float: left; + width: 200px; + margin-top: 10px; +} + +#wppost-checkbox, #wppost-username, #wppost-password, #wppost-blog, #wppost-bydefault { + float: left; + margin-top: 10px; +} + +#wppost-submit { + margin-top: 15px; +} + diff --git a/wppost/wppost.php b/wppost/wppost.php new file mode 100644 index 00000000..479ad6f1 --- /dev/null +++ b/wppost/wppost.php @@ -0,0 +1,166 @@ + + */ + +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 = xmlify(bbcode($b['body'])); + + $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'); + + } +} +