function wppost_send(&$a, &$b) { if (!is_item_normal($b) || $b['item_private']) { return; } if (!perm_is_allowed($b['uid'], '', 'view_stream')) { return; } if (!strstr($b['postopts'], 'wppost')) { return; } $edited = $b['created'] !== $b['edited'] ? true : false; if ($b['parent'] != $b['id']) { return; } logger('Wordpress xpost invoked', LOGGER_DEBUG); $wp_blog = get_pconfig($b['uid'], 'wppost', 'wp_blog'); $DR = new Zotlabs\Zot\DReport(z_root(), $b['owner_xchan'], 'wordpress wordpress', $b['mid']); if ($edited) { $r = q("select * from iconfig left join item on item.id = iconfig.iid \n\t\t\twhere cat = 'system' and k = 'wordpress' and v = %d and item.uid = %d limit 1", intval($b['id']), intval($b['uid'])); if (!$r) { wppost_dreport($DR, 'original post not found'); return; } $wp_post_id = intval(basename($r[0]['v'])); } $tags = null; $categories = null; if (is_array($b['term']) && $b['term']) { foreach ($b['term'] as $term) { if ($term['ttype'] == TERM_CATEGORY) { $categories[] = $term['term']; } if ($term['ttype'] == TERM_HASHTAG) { $tags[] = $term['term']; } } } $terms_names = array(); if ($tags) { $terms_names['post_tag'] = $tags; } if ($categories) { $terms_names['category'] = $categories; } $wp_username = get_pconfig($b['uid'], 'wppost', 'wp_username'); $wp_password = z_unobscure(get_pconfig($b['uid'], 'wppost', 'wp_password')); $wp_blogid = get_pconfig($b['uid'], 'wppost', 'wp_blogid'); if (!$wp_blogid) { $wp_blogid = 1; } if ($wp_username && $wp_password && $wp_blog) { require_once 'include/bbcode.php'; $data = array('post_title' => trim($b['title']), 'post_content' => bbcode($b['body']), 'post_type' => 'post', 'post_status' => 'publish', 'comment_status' => 'open', 'custom_fields' => array(array('key' => 'post_from_red', 'value' => '1'))); if ($terms_names) { $data['terms_names'] = $terms_names; } // We currently have Incutio set to produce debugging output, which goes to stdout. // We'll catch the stdout buffer contents and direct them to the logfile at LOGGER_ALL // level if a failure is encountered. ob_start(); $client = new IXR_Client($wp_blog); if ($edited) { $res = $client->query('wp.editPost', $wp_blogid, $wp_username, $wp_password, $wp_post_id, $data); } else { $res = $client->query('wp.newPost', $wp_blogid, $wp_username, $wp_password, $data); } $output = ob_get_contents(); ob_end_clean(); if (!$res) { logger('wppost: failed.'); logger('incutio debug: ' . $output, LOGGER_DATA); wppost_dreport($DR, 'connection or authentication failure'); return; } $post_id = $client->getResponse(); logger('wppost: returns post_id: ' . $post_id, LOGGER_DEBUG); wppost_dreport($DR, $edited ? 'updated' : 'posted'); if ($edited) { return; } if ($post_id) { q("insert into iconfig ( iid, cat, v, k, sharing ) values ( %d, 'system', '%s', '%s', 1 )", intval($b['id']), dbesc(dirname($wp_blog) . '/' . $post_id), dbesc('wordpress')); } } else { wppost_dreport($DR, 'wppost settings incomplete'); } }
function wppost_send(&$a, &$b) { if (!is_item_normal($b) || $b['item_private']) { return; } if (!perm_is_allowed($b['uid'], '', 'view_stream')) { return; } if (!strstr($b['postopts'], 'wppost')) { return; } $edited = $b['created'] !== $b['edited'] ? true : false; if ($b['parent'] != $b['id']) { return; } logger('Wordpress xpost invoked', LOGGER_DEBUG); $wp_blog = get_pconfig($b['uid'], 'wppost', 'wp_blog'); $DR = new Zotlabs\Zot\DReport(z_root(), $b['owner_xchan'], 'wordpress wordpress', $b['mid']); if ($edited) { $r = q("select * from item_id where service = 'wordpress' and iid = %d and uid = %d limit 1", intval($b['id']), intval($b['uid'])); if (!$r) { wppost_dreport($DR, 'original post not found'); return; } $wp_post_id = intval(basename($r[0]['sid'])); } $tags = null; $categories = null; if (is_array($b['term']) && $b['term']) { foreach ($b['term'] as $term) { if ($term['ttype'] == TERM_CATEGORY) { $categories[] = $term['term']; } if ($term['ttype'] == TERM_HASHTAG) { $tags[] = $term['term']; } } } $terms_names = array(); if ($tags) { $terms_names['post_tag'] = $tags; } if ($categories) { $terms_names['category'] = $categories; } $wp_username = get_pconfig($b['uid'], 'wppost', 'wp_username'); $wp_password = z_unobscure(get_pconfig($b['uid'], 'wppost', 'wp_password')); if ($wp_username && $wp_password && $wp_blog) { require_once 'include/bbcode.php'; $data = array('post_title' => trim($b['title']), 'post_content' => bbcode($b['body']), 'post_type' => 'post', 'post_status' => 'publish', 'comment_status' => 'open', 'custom_fields' => array(array('key' => 'post_from_red', 'value' => '1'))); if ($terms_names) { $data['terms_names'] = $terms_names; } $client = new IXR_Client($wp_blog); if ($edited) { $res = $client->query('wp.editPost', 1, $wp_username, $wp_password, $wp_post_id, $data); } else { $res = $client->query('wp.newPost', 1, $wp_username, $wp_password, $data); } if (!$res) { logger('wppost: failed.'); wppost_dreport($DR, 'connection or authentication failure'); return; } $post_id = $client->getResponse(); logger('wppost: returns post_id: ' . $post_id, LOGGER_DEBUG); wppost_dreport($DR, $edited ? 'updated' : 'posted'); if ($edited) { return; } if ($post_id) { q("insert into item_id ( iid, uid, sid, service ) values ( %d, %d, '%s','%s' )", intval($b['id']), intval($b['uid']), dbesc(dirname($wp_blog) . '/' . $post_id), dbesc('wordpress')); } } else { wppost_dreport($DR, 'wppost settings incomplete'); } }