Advertisement
campusboy

Перенос постов

Jul 8th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: DLE to WP
  4. Description: Convert DLE to WP
  5. Version: 1.0
  6. Author: campusboy
  7. */
  8.  
  9. //set_time_limit(1000);
  10. ini_set('max_execution_time', -1);
  11. ini_set("memory_limit",-1 );
  12.  
  13. wp_suspend_cache_addition( true );
  14.  
  15. // Создаем пункт меню в правой части админки
  16. add_action('admin_menu', 'dle_to_wp_menu');
  17. function dle_to_wp_menu() {
  18.     add_menu_page( 'Конвертер DLE в Wordpress', 'DLE-to-WP', 'manage_options', 'converter-dle-to-wp', 'dle_to_wp_page', '', 4 );
  19. }
  20.  
  21. // Подключение ко 2 базе (ДЛЕ)
  22. $dledb = new wpdb( DB_USER, DB_PASSWORD, 'u10462_phototur', DB_HOST );
  23.  
  24.  
  25.  
  26. // ЗАПИСИ
  27. function convert_posts_dle_to_wp(){
  28.  
  29.   $go_time = microtime(true);
  30.  
  31.   global $dledb;
  32.   $cnt = 0;
  33.  
  34.   printf( '<br>%s сек - %s Mb', round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
  35.  
  36.   $dle_posts_id = $dledb->get_col( "SELECT id FROM dle_post" );
  37.  
  38.   printf( '<br>%s сек - %s Mb<br>', round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
  39.  
  40.  
  41.   $cnt=0;
  42.  
  43.   foreach ( $dle_posts_id as $dle_post_id ){
  44.    
  45.     $dle_posts_data = $dledb->get_row( "SELECT * FROM dle_post WHERE id={$dle_post_id->id}" );
  46.  
  47.     //insert_post_to_wp( $dle_posts_data );
  48.    
  49.     unset ( $dle_posts_data );
  50.    
  51.     printf( '<br>%s. %s сек - %s Mb', ++$cnt, round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
  52.    
  53.   }
  54.  
  55.   printf( '<br>%s сек - %s Mb<br>', round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
  56.  
  57. }
  58.  
  59. function insert_post_to_wp($dle_posts_data){
  60.  
  61.     $approve = ( $wp_post_data->approve ) ? 'publish' : 'pending';
  62.  
  63.     $post_data = array(
  64.        'post_title'    => $dle_posts_data->title,
  65.        'post_excerpt'  => $dle_posts_data->short_story,
  66.        'post_content'  => $dle_posts_data->full_story,
  67.        'post_name'     => $dle_posts_data->alt_name,
  68.        'post_status'   => $approve,
  69.        'post_author'   => 1,
  70.        'post_category' => array( 1 )
  71.       );
  72.  
  73.     wp_insert_post( $post_data );
  74.  
  75.   unset( $approve, $post_data, $wp_post_data, $dle_posts_data);
  76.  
  77. }
  78.  
  79. function dle_to_wp_page(){
  80. ?>
  81.     <div class="wrap">
  82.         <h2><?php echo get_admin_page_title() ?></h2>
  83.  
  84.         <?php convert_posts_dle_to_wp(); ?>
  85.    
  86.    
  87.    
  88.     </div>
  89.     <?php
  90. }
  91. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement