Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: DLE to WP
- Description: Convert DLE to WP
- Version: 1.0
- Author: campusboy
- */
- //set_time_limit(1000);
- ini_set('max_execution_time', -1);
- ini_set("memory_limit",-1 );
- wp_suspend_cache_addition( true );
- // Создаем пункт меню в правой части админки
- add_action('admin_menu', 'dle_to_wp_menu');
- function dle_to_wp_menu() {
- add_menu_page( 'Конвертер DLE в Wordpress', 'DLE-to-WP', 'manage_options', 'converter-dle-to-wp', 'dle_to_wp_page', '', 4 );
- }
- // Подключение ко 2 базе (ДЛЕ)
- $dledb = new wpdb( DB_USER, DB_PASSWORD, 'u10462_phototur', DB_HOST );
- // ЗАПИСИ
- function convert_posts_dle_to_wp(){
- $go_time = microtime(true);
- global $dledb;
- $cnt = 0;
- printf( '<br>%s сек - %s Mb', round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
- $dle_posts_id = $dledb->get_col( "SELECT id FROM dle_post" );
- printf( '<br>%s сек - %s Mb<br>', round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
- $cnt=0;
- foreach ( $dle_posts_id as $dle_post_id ){
- $dle_posts_data = $dledb->get_row( "SELECT * FROM dle_post WHERE id={$dle_post_id->id}" );
- //insert_post_to_wp( $dle_posts_data );
- unset ( $dle_posts_data );
- printf( '<br>%s. %s сек - %s Mb', ++$cnt, round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
- }
- printf( '<br>%s сек - %s Mb<br>', round(microtime(true) - $go_time, 5) , round(memory_get_usage()/1024/1024,2) );
- }
- function insert_post_to_wp($dle_posts_data){
- $approve = ( $wp_post_data->approve ) ? 'publish' : 'pending';
- $post_data = array(
- 'post_title' => $dle_posts_data->title,
- 'post_excerpt' => $dle_posts_data->short_story,
- 'post_content' => $dle_posts_data->full_story,
- 'post_name' => $dle_posts_data->alt_name,
- 'post_status' => $approve,
- 'post_author' => 1,
- 'post_category' => array( 1 )
- );
- wp_insert_post( $post_data );
- unset( $approve, $post_data, $wp_post_data, $dle_posts_data);
- }
- function dle_to_wp_page(){
- ?>
- <div class="wrap">
- <h2><?php echo get_admin_page_title() ?></h2>
- <?php convert_posts_dle_to_wp(); ?>
- </div>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement