query($query_del); } add_action('delete_post', 'cleanup_post_delete'); function import_posts($posts) { global $table_prefix, $wpdb; foreach ($posts as $post) { $guid = $post['guid']; $n = $wpdb->get_results("SELECT * FROM ".$table_prefix."ext_soap WHERE opt_value='".$guid."'"); if (!$n) { // ADD NEW POST $postid = wp_insert_post($post); if (0 != count($post['categories'])) { require_once(ABSPATH.'wp-admin/admin-db.php'); wp_create_categories($post['categories'], $postid); } $query_add = "INSERT INTO ".$table_prefix."ext_soap VALUES(".$postid.",'post_guid','".$guid."')"; $wpdb->query($query_add); } else { // MODIFY EXISTING POST $postid = $n[0]->ID; $post['ID'] = $postid; // check if we need to update wp_update_post($post); } } } function do_my_soap_query($request) { global $hostname, $username, $password; get_soap_credentials(); if (!hostname) return $request; $sessionclient = new SoapClient($hostname."/sqitool/sessionmanager/wsdl", array('trace' => true, 'exceptions' => true) ); $sessionID = $sessionclient->createSession($username, $password); $queryclient = new SoapClient($hostname."/sqitool/wsdl", array('trace' => 1, 'exceptions' => true) ); $query = ' '.$username.' blog title '; $result = $queryclient->synchronousQuery($sessionID, $query, 0); require_once(ABSPATH.'wp-admin/admin-functions.php'); require_once(ABSPATH.'wp-admin/import/rss.php'); $temp = tempnam('/tmp', 'wp-'); $f = fopen($temp, "w"); fwrite($f, $result); fclose($f); $rss_import->file = $temp; $rss_import->get_posts(); import_posts($rss_import->posts); unlink($temp); $sessionclient->destroySession($sessionID); return $request; }; add_filter('posts_request', 'do_my_soap_query'); // // INSTALL AND UNINSTALL // function initialize_soap() { global $table_prefix, $wpdb; $query_exists = "SHOW TABLES LIKE '".$table_prefix."ext_soap'"; $exists = $wpdb->query($query_exists); if ( !$exists ) { $query_create = "CREATE TABLE ".$table_prefix."ext_soap(ID bigint(20) unsigned, opt_name char(255), opt_value char(255))"; $res = $wpdb->query($query_create); } } function uninstall_soap() { global $table_prefix, $wpdb; $query_exists = "SHOW TABLES LIKE '".$table_prefix."ext_soap'"; $exists = $wpdb->query($query_exists); $query_del = "DROP TABLE ".$table_prefix."ext_soap"; $wpdb->query($query_del); } add_action('activate_wp-soap-blogger.php', 'initialize_soap'); add_action('deactivate_wp-soap-blogger.php', 'uninstall_soap'); // // MANAGEMENT! // function verify_credentials($hostname, $username, $password) { //global $hostname, $username, $password; $res = 0; $sessionclient = new SoapClient($hostname."/sqitool/sessionmanager/wsdl", array('trace' => true, 'exceptions' => true) ); try { $sessionID = $sessionclient->createSession($username, $password); if ( $sessionID == '0' ) $res = 2; $sessionclient->destroySession($sessionID); } catch(SoapFault $sf) { $res = 1; } return $res; } function save_soap_credentials($hostname, $username, $password) { global $table_prefix, $wpdb; $query_exists = "SHOW TABLES LIKE '".$table_prefix."ext_soap'"; $exists = $wpdb->query($query_exists); if ( !$exists ) { } $query_del_prev = "DELETE FROM ".$table_prefix."ext_soap WHERE opt_name='soap_hostname' OR opt_name='soap_username' OR opt_name='soap_password'"; $wpdb->query($query_del_prev); $query_ins = "INSERT INTO ".$table_prefix."ext_soap (opt_name, opt_value) values('soap_hostname','".$hostname."')"; $wpdb->query($query_ins); $query_ins = "INSERT INTO ".$table_prefix."ext_soap (opt_name, opt_value) values('soap_username','".$username."')"; $wpdb->query($query_ins); $query_ins = "INSERT INTO ".$table_prefix."ext_soap (opt_name, opt_value) values('soap_password','".$password."')"; $wpdb->query($query_ins); } function get_soap_credentials() { global $table_prefix, $wpdb, $hostname, $username, $password; $query_exists = "SHOW TABLES LIKE '".$table_prefix."ext_soap'"; $exists = $wpdb->query($query_exists); if ( !$exists ) return array('','',''); $query_sel = "SELECT opt_name, opt_value FROM ".$table_prefix."ext_soap WHERE opt_name='soap_hostname' OR opt_name='soap_username' OR opt_name='soap_password' "; $res = $wpdb->get_results($query_sel); if ( !$res ) return array('','',''); foreach ($res as $key) { if ( $key->opt_name == 'soap_hostname' ) $hostname = $key->opt_value; if ( $key->opt_name == 'soap_username' ) $username = $key->opt_value; if ( $key->opt_name == 'soap_password' ) $password = $key->opt_value; } $koll = array($hostname, $username, $password); return $koll; } function soap_config_menu() { ?>

Configure blog gateway

".$msg."

"; if ( !$status ) { save_soap_credentials($hostname, $username, $password); } } ?>