Commit ceb0da63 authored by friendica's avatar friendica

wppost: drop item hook added, use this to remove crossposted wordpress items...

wppost: drop item hook added, use this to remove crossposted wordpress items when they are removed on red.
parent f12f3cdb
No preview for this file type
......@@ -17,6 +17,7 @@ function wppost_load () {
register_hook('jot_networks', 'addon/wppost/wppost.php', 'wppost_jot_nets');
register_hook('feature_settings', 'addon/wppost/wppost.php', 'wppost_settings');
register_hook('feature_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
register_hook('drop_item', 'addon/wppost/wppost.php', 'wppost_drop_item');
}
function wppost_unload () {
......@@ -25,6 +26,7 @@ function wppost_unload () {
unregister_hook('jot_networks', 'addon/wppost/wppost.php', 'wppost_jot_nets');
unregister_hook('feature_settings', 'addon/wppost/wppost.php', 'wppost_settings');
unregister_hook('feature_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post');
unregister_hook('drop_item', 'addon/wppost/wppost.php', 'wppost_drop_item');
}
......@@ -49,7 +51,7 @@ function wppost_settings(&$a,&$s) {
/* Add our stylesheet to the page so we can make our settings look nice */
$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . $a->get_baseurl() . '/addon/wppost/wppost.css' . '" media="all" />' . "\r\n";
head_add_css('/addon/wppost/wppost.css');
/* Get the current state of our config variables */
......@@ -58,10 +60,8 @@ function wppost_settings(&$a,&$s) {
$checked = (($enabled) ? ' checked="checked" ' : '');
$def_enabled = get_pconfig(local_user(),'wppost','post_by_default');
$back_enabled = get_pconfig(local_user(),'wppost','backlink');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$back_checked = (($back_enabled) ? ' checked="checked" ' : '');
$wp_username = get_pconfig(local_user(), 'wppost', 'wp_username');
$wp_password = get_pconfig(local_user(), 'wppost', 'wp_password');
......@@ -105,18 +105,14 @@ function wppost_settings(&$a,&$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']));
set_pconfig(local_user(),'wppost','backlink',trim($_POST['wp_backlink']));
info( t('Wordpress Settings saved.') . EOL);
info( t('Wordpress Settings saved.') . EOL);
}
}
function wppost_post_local(&$a,&$b) {
......@@ -204,3 +200,41 @@ function wppost_send(&$a,&$b) {
}
}
function wppost_drop_item(&$a,&$b) {
$wp_enabled = get_pconfig($b['item']['uid'],'wppost','post');
if(! $wp_enabled)
return;
$r = q("select * from item_id where service = 'wordpress' and iid = %d and uid = %d limit 1",
intval($b['item']['id']),
intval($b['item']['uid'])
);
if(! $r)
return;
$post_id = basename($r[0]['sid']);
$wp_username = get_pconfig($b['item']['uid'],'wppost','wp_username');
$wp_password = get_pconfig($b['item']['uid'],'wppost','wp_password');
$wp_blog = get_pconfig($b['item']['uid'],'wppost','wp_blog');
if($post_id && $wp_username && $wp_password && $wp_blog) {
$client = new IXR_Client($wp_blog);
$res = $client->query('wp.deletePost',1,$wp_username,$wp_password,$post_id);
if(! $res) {
logger('wppost: delete failed.');
return;
}
$result = intval($client->getResponse());
logger('wppost: delete post returns: ' . $result, LOGGER_DEBUG);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment