ID, "ite-topic")); else $channels = ''; $ite_html = '

(Separate multiple channel names with spaces.)

'; $key_text = 'ID, "ite-topic"); if (!sizeof($ite_channels)) return $content; $channels = Array(); foreach ($ite_channels as $ch) array_push($channels, "$ch"); $channels_html = implode("; ", $channels); $html = "

More posts like this on the Topic Exchange: $channels_html.

"; return $content . $html; } // Save any topics the user might have specified function ite_save_topics($post_ID) { global $wpdb; $post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID = $post_ID"); // figure out which channels have been specified $topics = explode(" ", $_POST['ite_channels']); $topics = array_map("trim", $topics); $known_topics = get_post_meta($post_ID, "ite-topic"); // flag to let us avoid doing any work if we don't have to $something_changed = false; // add any new channels into the post metadata foreach ($topics as $new_topic) { $is_new = true; foreach ($known_topics as $old_topic) if ($new_topic == $old_topic) $is_new = false; if ($is_new) { add_post_meta($post_ID, "ite-topic", $new_topic); $something_changed = true; } } // now get rid of topics we aren't pinging any more foreach ($known_topics as $old_topic) { $still_used = false; foreach ($topics as $new_topic) if ($new_topic == $old_topic) $still_used = true; if (!$still_used) { delete_post_meta($post_ID, 'ite-topic', $old_topic); $something_changed = true; } } // now ping the topic exchange - using its xml-rpc api global $wp_version; include_once (ABSPATH . WPINC . '/class-IXR.php'); $client = new IXR_Client("http://topicexchange.com/RPC2"); $client->timeout = 10; $client->useragent .= ' -- WordPress/'.$wp_version.'/topicexchange'; $client->debug = false; $ex = $post->post_excerpt; if (!strlen(trim($ex))) $ex = substr($post->post_content, 0, 500); $client->query('topicExchange.ping', $topics, Array( 'blog_name' => get_bloginfo("name"), 'title' => $post->post_title, 'url' => get_permalink($post_ID), 'excerpt' => $ex)); return $post_ID; } // Add in all the hooks so we do the right stuff at the right time add_action("admin_head", "ite_head"); add_action("admin_footer", "ite_footer"); add_action("the_content", "ite_modify_content"); add_action("save_post", "ite_save_topics"); add_action("edit_post", "ite_save_topics");