'; } function wp_autoblog_xmlrpc($xmethods) { $xmethods['autoblog.hack'] = 'wp_autoblog'; return $xmethods; } function wp_autoblog_trim_excerpt($text) { $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $excerpt_length = 150; $words = explode(' ', $text, $excerpt_length + 1); if (count($words) > $excerpt_length) { array_pop($words); array_push($words, '[...]'); $text = implode(' ', $words); } return $text; } function lookup_cat($cat){ global $wpdb; $cat = apply_filters('pre_category_nicename', trim($cat)); $results = $wpdb->get_results("SELECT cat_ID, cat_name FROM $wpdb->categories WHERE cat_name = '$cat'"); if(!$results || count($results) < 1){ $wpdb->query("INSERT INTO $wpdb->categories SET cat_name='$cat', category_nicename='" . sanitize_title($cat) . "'"); return $wpdb->insert_id; } else { return $results[0]->cat_ID; } } function wp_autoblog(){ global $wpdb; $feeds = preg_split("|[\r\n]+|i", get_option('wp_autoblog_feeds'), -1, PREG_SPLIT_NO_EMPTY); if(count($feeds) < 1) return; foreach($feeds as $feed){ $rss = auto_blog_fetch_rss($feed); if (!$rss) continue; if(count($rss->items) < 1) continue; foreach($rss->items as $item){ $post = array(); // Content if($item['content']['encoded'] != "") $content = $item['content']['encoded']; else if($item['xhtml']['div'] != "") $content = $item['xhtml']['div']; else if($item['xhtml']['body'] != "") $content = $item['xhtml']['body']; else $content = $item['description']; $post['post_content'] = $content; if(get_option('wp_autoblog_full') == 0) $post['post_content'] = wp_autoblog_trim_excerpt($post['post_content']); $replacements = preg_split("|[\r\n]+|i", get_option('wp_autoblog_replace'), -1, PREG_SPLIT_NO_EMPTY); foreach($replacements as $replacement){ preg_match("|\((.*?),(.*?)\)|si", $replacement, $matches); $post['post_content'] = preg_replace('|' . $matches[1] . '|si', $matches[2], $post['post_content']); } // Title $post['post_title'] = strip_tags(trim($item['title'])); // Categories $post['post_category'] = array(); if(isset($item['category#'])){ for ($i = 1; $i <= $item['category#']; $i++){ $cat_idx = (($i > 1) ? "#{$i}" : ""); $cat = $item["category{$cat_idx}"]; $post['post_category'][] = $cat; } } else if($item['dc']['subject'] != ""){ $post['post_category'][] = $item['dc']['subject']; } for($i = 0; $i < count($post['post_category']); $i++){ $post['post_category'][$i] = lookup_cat(strip_tags(trim($post['post_category'][$i]))); } // Post date $date = ""; if($item['published'] != "") $date = auto_blog_parse_w3cdtf($item['published']); // Atom 1.0 else if($item['issued'] != "") $date = auto_blog_parse_w3cdtf($item['issued']); // Atom 0.3 else if($item['dcterms']['issued'] != "") $date = auto_blog_parse_w3cdtf($item['dcterms']['issued']); else if($item['dc']['date'] != "") $date = auto_blog_parse_w3cdtf($item['dc']['date']); else if($item['pubdate'] != "") $date = strtotime($item['pubdate']); // RSS 2.0 else $date = time(); $post['post_date'] = date('Y-m-d H:i:s', $date); // Post status $post['post_status'] = 'publish'; // Attribution if(get_option('wp_autoblog_attribution') == 1){ if($item['author'] != "") $author = $item['author']; else if($item['dc']['creator'] != "") $author = $item['dc']['creator']; else if($item['author_name'] != "") $author = $item['author_name']; else if($item['source'] != "") $author = $item['source']; else if($item['dc']['contributor'] != "") $author = $item['dc']['contributor']; // if there is no author, try two things: if($author == "") $author = $rss->channel['title']; if($author == "") $author = 'Unknown'; $author = strip_tags(trim($author)); $post['post_content'] .= '
'; if($author != ""){ $post['post_content'] .= 'Original post by ' . htmlentities($author) . ''; $post['post_content'] .= ' and software by Elliott Back'; } else { $post['post_content'] .= 'Created using software by Elliott Back'; } $post['post_content'] .= '
'; } // Escaping $post['post_content'] = $wpdb->escape($post['post_content']); $post['post_title'] = $wpdb->escape($post['post_title']); // Check existence $sql = "SELECT ID FROM $wpdb->posts WHERE post_title = '" . apply_filters('title_save_pre', $post['post_title']) . "'"; if($wpdb->query($sql) === 0){ $pid = wp_insert_post($post); do_action('publish_post', $pid); } } } } /**** * 3) ADMIN PANEL */ // Update admin options function wp_autoblog_update() { if(isset($_POST['runnow'])) wp_autoblog(); if (isset ($_POST['update'])) { update_option('wp_autoblog_feeds', $_POST['feeds']); update_option('wp_autoblog_replace', $_POST['replace']); update_option('wp_autoblog_full', $_POST['full']); update_option('wp_autoblog_attribution', $_POST['attribution']); } } // Admin options function wp_autoblog_editor() { wp_autoblog_update(); echo ''; echo '