post_title; $post_author = get_userdata ($post->post_author)->display_name; $feed_title = '[' . $blog_title . "] " . $post_title . " (publisher: " . $post_author . ')'; $feed_content = $post->post_content; $feed_excerpt = $post->post_excerpt; $link = $post->guid; $id = $post_ID; $xs = new xmpp_stream ($configuration['node'], $configuration['domain'], $configuration['password'], 'bot', $configuration['server'], $configuration['port']); $history = get_option('jabber_feed_post_history'); if (! ($xs->log () && $xs->notify ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/posts', $id, $feed_title, $link, $feed_content, $feed_excerpt) && $xs->create_leaf ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/comments/' . $id) && $xs->quit ())) { echo '

' . __('Jabber Feed error') . '
'; echo $xs->last_error . '

'; $history[$post_ID] = array ('error' => $xs->last_error); } else { if (array_key_exists ($post_ID, $history)) { if (array_key_exists ('error', $history[$post_ID])) { unset ($history['$post_ID']['error']); $history[$post_ID] = array ('published' => date ('c'), 'updated' => date ('c'), 'id' => $id); } else $history[$post_ID]['updated'] = date ('c'); } else $history[$post_ID] = array ('published' => date ('c'), 'updated' => date ('c'), 'id' => $id); } update_option('jabber_feed_post_history', $history); return $post_ID; } // }}} function xmpp_delete_post_page ($ID) // {{{ { $configuration = get_option ('jabber_feed_configuration'); $history = get_option('jabber_feed_post_history'); if (empty ($configuration['publish_posts']) || ! array_key_exists ($ID, $history) || array_key_exists ('error', $history[$ID])) return $ID; $xs = new xmpp_stream ($configuration['node'], $configuration['domain'], $configuration['password'], 'bot', $configuration['server'], $configuration['port']); if (! ($xs->log () && $xs->delete_item ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/posts', $history[$ID]['id']) && $xs->delete_node ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/comments/' . $ID) && $xs->quit ())) { echo '

' . __('Jabber Feed error:') . '
'; echo $xs->last_error . '

'; } else { unset ($history[$ID]); } update_option('jabber_feed_post_history', $history); return $ID; } // }}} add_action ('publish_post', 'xmpp_publish_post'); add_action ('delete_post', 'xmpp_delete_post_page'); /////////////////////////// // Comment Publication // ////////////////////////// function xmpp_publish_comment ($comment_ID, $status) // {{{ { $configuration = get_option ('jabber_feed_configuration'); if (empty ($configuration['publish_comments'])) return $comment_ID; if ($status == 1) { $blog_title = get_bloginfo ('name'); $comment = get_comment ($comment_ID, OBJECT); $post = get_post ($comment->comment_post_ID, OBJECT); $post_title = $post->post_title; $comment_author = $comment->comment_author; $feed_title = '[' . $blog_title . "] " . $post_title . " (commenter: " . $comment_author . ')'; $feed_content = $comment->comment_content; $link = $post->guid; $id = $comment_ID; $xs = new xmpp_stream ($configuration['node'], $configuration['domain'], $configuration['password'], 'bot', $configuration['server'], $configuration['port']); // Must check whether container already exists and create it otherwise! $history = get_option('jabber_feed_comment_history'); if (! ($xs->log () && $xs->notify ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/comments/' . $post->ID, $id, $feed_title, $link, $feed_content) && $xs->quit ())) $history[$id] = array ('error' => $xs->last_error); else { if (array_key_exists ($id, $history)) { if (array_key_exists ('error', $history[$comment_ID])) { unset ($history['$comment_ID']['error']); $history[$id] = array ('published' => date ('c'), 'updated' => date ('c'), 'id' => $id); } else $history[$id]['updated'] = date ('c'); } else $history[$id] = array ('published' => date ('c'), 'updated' => date ('c'), 'id' => $id); } } update_option('jabber_feed_comment_history', $history); return $comment_ID; } // }}} // TODO: history for comments function xmpp_delete_comment ($comment_ID) // {{{ { $configuration = get_option ('jabber_feed_configuration'); if (empty ($configuration['publish_comments'])) return $comment_ID; $history = get_option('jabber_feed_comment_history'); $comment = get_comment ($comment_ID, OBJECT); $xs = new xmpp_stream ($configuration['node'], $configuration['domain'], $configuration['password'], 'bot', $configuration['server'], $configuration['port']); if (! ($xs->log () && $xs->delete_item ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/comments/' . $comment->comment_post_ID, $comment_ID) && $xs->quit ())) { echo '

' . __('Jabber Feed error:') . '
'; echo $xs->last_error . '

'; } else unset ($history[$comment_ID]); update_option('jabber_feed_comment_history', $history); return $comment_ID; } // }}} function xmpp_comment_status ($comment_ID, $status) // {{{ { $configuration = get_option ('jabber_feed_configuration'); if (empty ($configuration['publish_comments'])) return $comment_ID; if ($status == 'approve') xmpp_publish_comment ($comment_ID, 1); else xmpp_delete_comment ($comment_ID); return $comment_ID; } // }}} add_action ('comment_post', 'xmpp_publish_comment', 10, 2); add_action ('delete_comment', 'xmpp_delete_comment'); add_action ('wp_set_comment_status', 'xmpp_comment_status', 10, 2); /**********************\ // Configuration Page \\ \**********************/ add_option('jabber_feed_configuration', array (), 'Configuration of the Jabber Feed plugin', 'yes'); add_option ('jabber_feed_post_history', array (), 'All information about fed posts and pages, successes and failures', 'yes'); add_option ('jabber_feed_comment_history', array (), 'All information about fed comments, successes and failures', 'yes'); function jabber_feed_configuration_page () // {{{ { global $wpdb; if (isset($_POST['update_configuration'])) { $configuration['node'] = strip_tags (trim($_POST['node'])); $configuration['domain'] = strip_tags (trim ($_POST['domain'])); $configuration['password'] = strip_tags (trim($_POST['password'])); $posted_server = strip_tags (trim($_POST['server'])); if ($posted_server == '') $configuration['server'] = $configuration['domain']; else $configuration['server'] = $posted_server; $posted_port = strip_tags (trim($_POST['port'])); if ($posted_port == '' || ! is_numeric ($posted_port)) $configuration['port'] = 5222; else $configuration['port'] = intval ($posted_port); $configuration['pubsub_server'] = strip_tags (trim($_POST['pubsub_server'])); $configuration['pubsub_node'] = strip_tags (trim($_POST['pubsub_node'])); $configuration['publish_posts'] = strip_tags (trim($_POST['publish_posts'])); $configuration['publish_comments'] = strip_tags (trim($_POST['publish_comments'])); //$configuration['publish_pages'] = strip_tags (trim($_POST['publish_pages'])); $xs = new xmpp_stream ($configuration['node'], $configuration['domain'], $configuration['password'], 'bot', $configuration['server'], $configuration['port']); if ($xs->log () && $xs->create_leaf ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/posts') && $xs->create_collection ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/comments') && $xs->create_leaf ($configuration['pubsub_server'], $configuration['pubsub_node'] . '/pages') && $xs->quit ()) { update_option('jabber_feed_configuration', $configuration); echo '

' . __('Configuration saved') . '

'; } else echo '

' . __('Configuration not saved. The following error occured:
') . $xs->last_error . '

'; } else // If we are just displaying the page or if we reset to last saved config, we first load up the options array. $configuration = get_option('jabber_feed_configuration'); //now we drop into html to display the option page form. ?>

These are advanced settings. If you don't understand them, they are probably useless and default values will be enough.


checked="checked" />
checked="checked" />

'; echo 'Error on publication'; } else { echo ''; echo $history[$id]['published'] . ''; } } else echo 'Not Published'; } } // }}} function jabber_feed_publish_button () // {{{ { ?>