|
楼主 |
发表于 2012-1-8 10:09:04
|
显示全部楼层
我用的是免费版,火车头确实是可以做到标题加文章的组合,但是,它是一口气把所有文章都弄到一个txt里的,另外,这样就没法伪原创了。
我想自己改改那个TXTAsPost插件,可是又不懂php,唉,书到用时方恨少啊。不知有哪位达淫能帮忙看看怎么改啊,先贴出代码了:- <?php
- /*
- * Plugin Name: TXTAsPost
- * Version: 1.8
- * Plugin URI: http://www.s101.net/txt-as-post/
- * Description: Import .txt as post in bulk
- * Author: Jesse
- * Author URI: http://www.s101.net/txt-as-post/
- */
- require(dirname(__FILE__) . "/dUnzip2.inc.php");
- class TXTAsPost {
-
- /*Simple log*/
- var $log='';
- /*time interval retrieving from user input*/
- var $interval='';
-
- /*category retrieving from user input*/
- var $post_category='';
- /*tags retrieving from user input or second line of txt*/
- var $tags_input='';
- /* 0 means default process, 1 means fetch second line as date,2 means fetch second line as tags */
- var $option=0;
- /*default post type is post*/
- var $post_type='post';
- var $notify=0;
- function TXTAsPost(){
- add_action('admin_menu', array(&$this,'txtaspost_menu_setup'));
- add_action('admin_footer',array(&$this,'txtaspost_js'));
- }
- function txtaspost_menu_setup() {
- add_options_page('TxtAsPost Settings', 'TXT As Post', 10, __FILE__, array(&$this,'txtaspost_menu'));
-
-
- if (isset($_FILES["zip"])) {
- check_admin_referer( 'txtaspost_update'); // nonce
- if (is_uploaded_file($_FILES['zip']['tmp_name'])) {
- $this->txtaspost_process();
- }
- }
-
- }
-
- function txtaspost_process() {
-
- //I need much time xD
-
- set_time_limit(0);
- $zipfilename = $_FILES['zip']['tmp_name'];
- $zip = &new dUnzip2($zipfilename);
- $zip->debug = false;
- $list = $zip->getList();
- shuffle($list);
- $this->interval=absint($_POST['timeInterval']);
- $this->post_category= $this->process_category($_POST['category']);
- $this->post_type= $_POST['post_type'];
-
- if($_POST['version'] == 'date')
- $this->option=1;
- else if($_POST['version'] == 'tags')
- $this->option=2;
-
- $this->tags_input= $_POST['tags'];
- $tm = ($_POST['when']=='Now')? time() : ( $this->getLatestTime() + $this->interval*3600 );
- // echo $this->getLatestTime() + $this->interval;
- //echo date("Y-m-d H:i:s", $this->getLatestTime() + $this->interval);exit;
- foreach($list as $filename => $b) {
- $content = $zip->unzip($b['file_name']);
- // Process each article
- if($id=$this->process_content($content,$tm)){
-
- // time will be associated with the time of latest post
- $tm += strtotime($id->post_date) + $this->interval*3600 + rand(0,60);
- }
- else{
-
- $this->log .= "Duplicate post: $filename <br />";
-
- }
- }
- $this->notify=1;
-
-
-
-
- }
- function process_content($content,$post_date){
-
- global $wpdb;
- $content = str_replace("\n",'NEWLINE',$content);
- $content=preg_replace('/[\x0-\x1F|\x7F-\xFF]/','',$content);
- $content=str_replace('NEWLINE',"\n",$content);
- $post = explode("\n",$content);
- $post_title = $wpdb->escape(trim($post[0]));
- $i=1;
-
-
- /*1 means fetch second line as date*/
- if($this->option == 1){
-
- $post_date = strtotime($post[1]);
- $i=2;
- /*2 means fetch second line as tags*/
- }else if($this->option == 2){
- $this->tags_input=$wpdb->escape(trim($post[1]));
- $i=2;
- }
- $post_content = $wpdb->escape(trim( implode ( "\n" , array_slice( $post,$i ) ) ));
- $post_name = sanitize_title( $post_title);
- if (empty($post_title)||empty($post_content)) { return false; }
- // Avoid duplicated post
- if ( $wpdb->get_var( "SELECT post_title FROM $wpdb->posts WHERE post_title LIKE '$post_title' " )) {
- return false;
- }
- $id=$this->txtaspost_post($post_title,$post_content,$post_name,$post_date);
-
- return $id;
- }
- function txtaspost_post($post_title,$post_content,$post_name,$post_date) {
- global $wpdb;
- $id = wp_insert_post(array(
- "post_title" => $post_title ,
- "post_content" => $post_content,
- "post_name" => $post_name,
- "post_category" => $this->post_category,
- "tags_input" => $this->tags_input,
- "post_status" => "publish",
- "post_author" => 1,
- "post_type" => $this->post_type,
- "post_date" => date("Y-m-d H:i:s", $post_date)
- ) );
- return $id;
- }
- function process_category($category){
- $cats=explode(",",$category);
- $cats_id=array();
- foreach($cats as $cat){
- if($cat){
- if( 0 == get_cat_id($cat) ){
- if(!function_exists('wp_create_category')) include_once(ABSPATH.'wp-admin/includes/taxonomy.php');
- // 0 means default category, if wp_create_category fail, return 0. nice. xD
- array_push($cats_id,wp_create_category($cat));
- }else
- array_push($cats_id,get_cat_id($cat));
- }//who cares if cat name is empty?
- }
- return array_unique($cats_id);
- }
- function getLatestTime() {
- global $wpdb;
-
- $post = $wpdb->get_results( "SELECT post_date FROM $wpdb->posts ORDER BY post_date DESC limit 0,1" );
- $tm=strtotime($post[0]->post_date);
-
-
- // strtotime will return false if no post found
- if(false == $tm)
- $tm = time();
- return $tm;
-
- }
-
- function txtaspost_menu() {
-
- ?>
- <div class="wrap">
- <?php
- if( $this->notify ){
- echo '<div id="message" class="updated fade"><p><a href="'. get_option("siteurl").'/wp-admin/edit.php">Edit post</a></p></div>';
- }
- ?>
- <h2>TXT As post</h2>
- <form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data">
- <?php wp_nonce_field('txtaspost_update'); ?>
- <input type="hidden" name="action" value="update" />
- <p>
- <input type="radio" value="default" name="version" onclick="hidden(this.value);" checked/> Default Version
- <input type="radio" value="date" name="version" onclick="hidden(this.value);" /> Custom Date Version
- <input type="radio" value="tags" name="version" onclick="hidden(this.value);" /> Custom Tags Version<br />
- </p>
- <p>Upload zip file that contains plain text(.txt format files) <br />Format<br /><span id="promt" style="color:red;">1st line:[title]<br />the rest:[content]<br /></span></p>
-
-
- <p>Upload Zip: <input type="file" name="zip" /> Maximum file size <?php echo ini_get('upload_max_filesize');?></p>
-
- <div id="customDate">
- <p>Time Interval by hours:<input type="text" name="timeInterval" value="8"/></p>
- <p>Published time<br />
- <input type="radio" name="when" value="Next" checked>According to the time of latest post<br />
- <input type="radio" name="when" value="Now" >From Now On<br />
- </p>
- <p>Hint: the post date will be current servert time, if no post found.</p>
- </div>
-
-
- <div id="customTags">
- <p>
- Tags(separated by comma):<input type="text" name="tags" id="tags" value=""/>
- </p>
- </div>
- <p>Category/Categories to post(separated by comma):<input type="text" id="category" name="category" value=""/></p>
- <p>Hint: Category will automatically added if not exists. </p>
-
- <p>
- Post type: <select id="post_type" name="post_type">
- <option value="post" selected="selected">post</option>
- <option value="page" >page</option>
- </select>
- </p>
-
-
- <p><input type="submit" class="button" value="Upload" /></p>
- Error log:<br/>
- <div id="log" style="color:red;"><?php echo $this->log;?></div>
- </form>
- </div>
- <?php
- }
- function txtaspost_js(){
- ?>
- <script type='text/javascript'>
- function hidden(value){
-
-
- if(value == 'tags'){
- document.getElementById('customDate').style.display='';
- document.getElementById('customTags').style.display='none';
- document.getElementById('promt').innerHTML='1st line:[title]\<br \/\>2nd line:tag a,tag b,tag c\<br \/\>the rest:[content]';
- }else if(value == 'date'){
- document.getElementById('customDate').style.display='none';
- document.getElementById('customTags').style.display='';
- document.getElementById('promt').innerHTML='1st line:[title]\<br \/\>2nd line:02/16/2009 8:53 am\<br \/\>the rest:[content]';
- }else if(value == 'default'){
- document.getElementById('customTags').style.display='';
- document.getElementById('customDate').style.display='';
- document.getElementById('promt').innerHTML='1st line:[title]\<br \/\>the rest:[content]';
-
- }
- }
- </script>
- <?php
- }
- }
- $txtaspost = & new TXTAsPost();
- ?>
复制代码 |
|