" . $obj['body_html']; if ($settings['display-copyright'] == "on") { $content.= ""; // $obj['copyrightnotice'] } $guid = wp_strip_all_tags($obj['guid']); $sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'"); if ($sync) { $edit_post = array( 'ID' => $sync->post_id, 'post_title' => wp_strip_all_tags($obj['headline']), 'post_name' => wp_strip_all_tags($obj['headline']), 'post_content' => $content, 'post_content_filtered' => $content ); wp_update_post($edit_post); } else { if ($settings['author-byline'] && $settings['author-byline'] == 'on') { $author_name = str_replace("By ", "", $obj['byline']); $authorExist = $wpdb->get_row("SELECT ID user_id FROM " . $wpdb->prefix . DB_TABLE_USERS . " WHERE display_name = '" . wp_strip_all_tags($author_name) . "'"); if (!$authorExist) { $table_name = $wpdb->prefix . DB_TABLE_USERS; $userArray = array( 'user_login' => strtolower(str_replace(" ", "-", $author_name)), 'user_pass' => generatePassword(), 'display_name' => wp_strip_all_tags($author_name) ); $author_id = wp_insert_user($userArray); } else { $author_id = $authorExist->user_id; } } else { $author_id = $settings['author']; } foreach ($obj['service'] as $service) { if ($settings['subject-type'] == 'tags') { $taxonomyTag[] = wp_strip_all_tags($service['name']); } elseif ($settings['subject-type'] == 'categories') { $categoryExist = $wpdb->get_row("SELECT terms.term_id, term_taxonomy.term_taxonomy_id FROM " . $wpdb->prefix . "terms terms JOIN " . $wpdb->prefix . "term_taxonomy term_taxonomy ON term_taxonomy.term_id = terms.term_id WHERE term_taxonomy.taxonomy = 'category' AND terms.name = '" . wp_strip_all_tags($service['name']) . "'"); if ($categoryExist) { $taxonomyCategory[] = $categoryExist->term_taxonomy_id; } else { $category_id = wp_insert_term(wp_strip_all_tags($service['name']), 'category'); $taxonomyCategory[] = $category_id['term_taxonomy_id']; } } } if ($taxonomyCategory && !empty($taxonomyCategory)) { $category = $taxonomyCategory; } else { $category = $settings['category']; } $postarr = array( 'post_title' => wp_strip_all_tags($obj['headline']), 'post_name' => wp_strip_all_tags($obj['headline']), 'post_content' => $content, 'post_content_filtered' => $content, 'post_author' => (int) $author_id, 'post_status' => $settings['status'], 'post_category' => $category, ); $post_ID = wp_insert_post($postarr, true); if ($taxonomyTag && !empty($taxonomyTag)) { wp_set_post_tags($post_ID, $taxonomyTag); } $table_name = $wpdb->prefix . DB_TABLE_SYNC_POST; $wpdb->insert( $table_name, array( 'post_id' => $post_ID, 'guid' => wp_strip_all_tags($obj['guid']), 'time' => current_time('mysql') ) ); if ($obj['associations']['featuremedia'] && $obj['associations']['featuremedia']['type'] == 'picture') { /* save featured media */ $picture = $obj['associations']['featuremedia']; $filenameQ = explode("/", $picture['renditions']['original']['media']); $filename = $filenameQ[1]; saveFile($picture['renditions']['original']['href'], wp_upload_dir()['path'] . "/" . $filename); $attachment = array( 'guid' => wp_upload_dir()['url'] . '/' . basename($filename), 'post_mime_type' => $picture['mimetype'], 'post_title' => preg_replace('/\.[^.]+$/', '', basename($picture['headline'])), 'post_content' => '', 'post_status' => 'inherit' ); $attach_id = wp_insert_attachment($attachment, date("Y") . "/" . date("m") . "/" . $filename, $post_ID); require_once( ABSPATH . 'wp-admin/includes/image.php' ); $attach_data = wp_generate_attachment_metadata($attach_id, wp_upload_dir()['path'] . "/" . $filename); wp_update_attachment_metadata($attach_id, $attach_data); set_post_thumbnail($post_ID, $attach_id); } } } elseif ($obj['pubstatus'] == 'canceled') { /* remove article */ $guid = wp_strip_all_tags($obj['guid']); $sync = $wpdb->get_row("SELECT post_id FROM " . $wpdb->prefix . DB_TABLE_SYNC_POST . " WHERE guid = '" . $guid . "'"); if ($sync) { $edit_post = array( 'ID' => $sync->post_id, 'post_status' => 'draft' ); wp_update_post($edit_post); } } }