4 * Name: WordPress Post Connector
6 * Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
9 function wppost_install() {
10 register_hook('post_local_end', 'addon/wppost/wppost.php', 'wppost_send');
11 register_hook('jot_networks', 'addon/wppost/wppost.php', 'wppost_jot_nets');
12 register_hook('plugin_settings', 'addon/wppost/wppost.php', 'wppost_settings');
13 register_hook('plugin_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
16 function wppost_uninstall() {
17 unregister_hook('post_local_end', 'addon/wppost/wppost.php', 'wppost_send');
18 unregister_hook('jot_networks', 'addon/wppost/wppost.php', 'wppost_jot_nets');
19 unregister_hook('plugin_settings', 'addon/wppost/wppost.php', 'wppost_settings');
20 unregister_hook('plugin_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
24 function wppost_jot_nets(&$a,&$b) {
28 $wp_post = get_pconfig(local_user(),'wppost','post');
29 if(intval($wp_post) == 1) {
30 $wp_defpost = get_pconfig(local_user(),'wppost','post_by_default');
31 $selected = ((intval($wp_defpost) == 1) ? ' checked="checked" ' : '');
32 $b .= '<div class="profile-jot-net"><input type="checkbox" name="wppost_enable"' . $selected . 'value="1" /> '
33 . t('Post to Wordpress') . '</div>';
38 function wppost_settings(&$a,&$s) {
43 /* Add our stylesheet to the page so we can make our settings look nice */
45 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/wppost/wppost.css' . '" media="all" />' . "\r\n";
47 /* Get the current state of our config variables */
49 $enabled = get_pconfig(local_user(),'wppost','post');
51 $checked = (($enabled) ? ' checked="checked" ' : '');
53 $def_enabled = get_pconfig(local_user(),'wppost','post_by_default');
55 $def_checked = (($def_enabled) ? ' checked="checked" ' : '');
57 $wp_username = get_pconfig(local_user(), 'wppost', 'wp_username');
58 $wp_password = get_pconfig(local_user(), 'wppost', 'wp_password');
59 $wp_blog = get_pconfig(local_user(), 'wppost', 'wp_blog');
62 /* Add some HTML to the existing form */
64 $s .= '<div class="settings-block">';
65 $s .= '<h3>' . t('WordPress Post Settings') . '</h3>';
66 $s .= '<div id="wppost-enable-wrapper">';
67 $s .= '<label id="wppost-enable-label" for="wppost-checkbox">' . t('Enable WordPress Post Plugin') . '</label>';
68 $s .= '<input id="wppost-checkbox" type="checkbox" name="wppost" value="1" ' . $checked . '/>';
69 $s .= '</div><div class="clear"></div>';
71 $s .= '<div id="wppost-username-wrapper">';
72 $s .= '<label id="wppost-username-label" for="wppost-username">' . t('WordPress username') . '</label>';
73 $s .= '<input id="wppost-username" type="text" name="wp_username" value="' . $wp_username . '" />';
74 $s .= '</div><div class="clear"></div>';
76 $s .= '<div id="wppost-password-wrapper">';
77 $s .= '<label id="wppost-password-label" for="wppost-password">' . t('WordPress password') . '</label>';
78 $s .= '<input id="wppost-password" type="password" name="wp_password" value="' . $wp_password . '" />';
79 $s .= '</div><div class="clear"></div>';
81 $s .= '<div id="wppost-blog-wrapper">';
82 $s .= '<label id="wppost-blog-label" for="wppost-blog">' . t('WordPress API URL') . '</label>';
83 $s .= '<input id="wppost-blog" type="text" name="wp_blog" value="' . $wp_blog . '" />';
84 $s .= '</div><div class="clear"></div>';
86 $s .= '<div id="wppost-bydefault-wrapper">';
87 $s .= '<label id="wppost-bydefault-label" for="wppost-bydefault">' . t('Post to WordPress by default') . '</label>';
88 $s .= '<input id="wppost-bydefault" type="checkbox" name="wp_bydefault" value="1" ' . $def_checked . '/>';
89 $s .= '</div><div class="clear"></div>';
91 /* provide a submit button */
93 $s .= '<div class="settings-submit-wrapper" ><input type="submit" id="wppost-submit" name="wppost-submit" class="settings-submit" value="' . t('Submit') . '" /></div></div>';
98 function wppost_settings_post(&$a,&$b) {
100 if(x($_POST,'wppost-submit')) {
102 set_pconfig(local_user(),'wppost','post',intval($_POST['wppost']));
103 set_pconfig(local_user(),'wppost','post_by_default',intval($_POST['wp_bydefault']));
104 set_pconfig(local_user(),'wppost','wp_username',trim($_POST['wp_username']));
105 set_pconfig(local_user(),'wppost','wp_password',trim($_POST['wp_password']));
106 set_pconfig(local_user(),'wppost','wp_blog',trim($_POST['wp_blog']));
115 function wppost_send(&$a,&$b) {
117 if((! local_user()) || (local_user() != $b['uid']))
120 if($b['prvnets'] && $b['private'])
126 $wp_username = get_pconfig(local_user(),'wppost','wp_username');
127 $wp_password = get_pconfig(local_user(),'wppost','wp_password');
128 $wp_blog = get_pconfig(local_user(),'wppost','wp_blog');
129 $wp_post = intval(get_pconfig(local_user(),'wppost','post'));
131 $wp_enable = (($wp_post && x($_POST,'wppost_enable')) ? intval($_POST['wppost_enable']) : 0);
133 if($_POST['api_source'] && intval(get_pconfig(local_user(),'wppost','post_by_default')))
136 if($wp_username && $wp_password && $wp_blog && $wp_post && $wp_enable) {
138 require_once('include/bbcode.php');
139 $post = xmlify(bbcode($b['body']));
143 <?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
145 <methodName>blogger.newPost</methodName>
147 <param><value><string/></value></param>
148 <param><value><string/></value></param>
149 <param><value><string>$wp_username</string></value></param>
150 <param><value><string>$wp_password</string></value></param>
151 <param><value><string>$post</string></value></param>
152 <param><value><int>1</int></value></param>
158 logger('wppost: data: ' . $xml, LOGGER_DATA);
160 if($wp_blog !== 'test')
161 $x = post_url($wp_blog,$xml);
162 logger('posted to wordpress');