From 40a8b4d13f301565c4300983448c76b2249c49c6 Mon Sep 17 00:00:00 2001 From: Friendika Date: Wed, 7 Sep 2011 21:10:56 -0700 Subject: [PATCH] first commit - Wordpress post plugin --- wppost.tgz | Bin 0 -> 1890 bytes wppost/wppost.css | 16 +++++ wppost/wppost.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 wppost.tgz create mode 100644 wppost/wppost.css create mode 100644 wppost/wppost.php diff --git a/wppost.tgz b/wppost.tgz new file mode 100644 index 0000000000000000000000000000000000000000..d18ed64fc8d62a2feb86306e5d5e04ba80ab5027 GIT binary patch literal 1890 zcmV-o2c7sIiwFP+Kxj??1MOK`bJ|7}=GFX)6V+ou1`uGtE&)8AG?R8FX*`MBKExhI zNDHVIk}9pho+kgjXK#`~*g>hCPNwXO(eAnJcP@K&y$S+9qDJW{M-#`%Nw?JQc23&u zPN~`LwR@cwpO>T5YW0rW%?|$TmYS{hakE!~?vq+2M;uWz1Sl;`YvzPY$Ge9vn00%t z)6>&$VbeDpE8&0fr(s3W6X;+L?)5tN`oG&cmi|9J>GgW({|^2rLGuZ0$<H|I0rJ z*Vl<>PFzxV%?WX9pl0KUgr2#`%?D-_t^Cm5oS(S?%p13E))s^EraY)S ziYE()Gp&(zCE0)N%C8#h`5(-KC(yz3zjI&yw~l*Q>^Jhi(`@ha|67c~8T!0jHl9B( z!*lo*^QaGhVD4OmB#Phyg92Xqo<}U|hm7KP5=M^iVc0jC?E5^Xb3g3ETjz$rTZJJE z=9C6~!$?qVSpLEYLVxPG#8@El2)T`Nc^Z2bMS&n9aO`;K57(_!G0gx+NM=q%NjRSS z{!K;aG_G%%?wEMCUPB7qv~Axra)FGCx)d5Q+UkpK0{`^s*dr9n#ZAP;?IcigMfV5| z+!)IPs-@KNW?b%0R!Z`ngpL_cLCJy##bdeJ1U~jQp^v>s2R|qBap2Ee`X~2kxp@2!HCb!wh-n=$)kXuy3t|fNE+A4A zwh=g`P(X;H zSeQ)Ah{Pc)EQpD*Emx3{G3XjBi0zm|4eJoYnoVj~;gzSQyM4{JhkLW)FeDzuU7Hkl zHRT%<0SQYpbeJcjbX&r;cCpkDtTOI+s46*M3{Am`;XE#^c_U|1No$5=M1R?s1D0E= zQ+~)2NK9eB5*8+e%TT>_0U3%Vk-@t00{o1eZz3D-k&pZM`SR@>73$;`D>cS6O#N_? zx;@Gj1{M44QefR^Dm@kD{Fp}_CiO-e^dUJNL~1j_7da)4t%`}dQLREV2uPSyBrZdF zdOokQZ6qs6wNj?N;-s66+66zJlzm*zrczM@GfLA!_)uZgAgzErvsEOrgx=J_i(VFS z%Oxi6KdFWfftFl2cZO~KinXJExTtmm95ap$z8rI5U&p628wD~06oMkyzY&vH5CgU`aV+kETU zIhSr;K;Y9SSW^$rhIsY*sK*Ys6b((TCXAmg1>ut4)UV;_2*iZ5#D*Q|x00Kzr{7%M zwRzp{ts<@KcK__!xaPef@2JVe9FSecugve3vnNPcs;)tcOFDooauko*-p zAsPFgMJl@ES#E3-V=}RPoA5UnoMOsc6V*PPwM_E@43^`el zU%Bq9_ydkd0Y;3-QEOnZKU>Jw_Q5u(*%u7~y1NE%-o1YP z>izhq^UHG)7BXIWJU$!ZIZg>nOkBZ;!FUl5sG*xs)tDe2cuE%|!6pNHo>lrrBueu4 c`mdw?*pL0#kNwz>{rFDDKORNT9sno+01}z3cmMzZ literal 0 HcmV?d00001 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'); + + } +} + -- 2.39.5