<?php
-
/**
* Gaslight Media Members Database
* Admin Development
*/
public function __construct ($wpdb, $config)
{
-
// Save WordPress Database object
$this->wpdb = $wpdb;
*/
public function modelAction ($actionData = false)
{
+
$resultMessage = '';
$success = false;
case 'importBoard':
// check for members.csv
$upload_dir = wp_upload_dir();
+
if ( is_file( $upload_dir['basedir'].'/Members.csv' ) && ( $fh = fopen( $upload_dir['basedir'].'/Members.csv', 'r' ) ) !== false ) {
$resultMessage .= '<p>Member file found</p>';
$row = 0;
fclose( $fh );
$resultMessage .= '<pre>$Members: ' . print_r( $Members, true ) . '</pre>';
}
- if ( is_file( $upload_dir['basedir'].'/MessageBoards.csv' ) && ( $fh = fopen( $upload_dir['basedir'].'/MessageBoards.csv', 'r' ) ) !== false ) {
- $resultMessage .= '<p>Forum file found</p>';
- $row = 0;
- while( ( $data = fgetcsv( $fh, 4000, '|' ) ) !== false ) {
- if ( $row === 0 ) {
- // First row grab as headers.
- $file_headers = $data;
- } else {
- // All other rows are data.
- $file_data[] = array_combine( $file_headers, $data );
- }
- $row++;
+
+
+ $url = get_site_url() . '/wp-admin/admin.php?page=glm-members-admin-menu-management&glm_action=csvimport&option=importBoard';
+ $limit = 110;
+
+ if ( isset( $_REQUEST['start'] ) ) {
+ $start = filter_var( $_REQUEST['start'], FILTER_VALIDATE_INT );
+ } else {
+ $start = 0;
+ }
+ global $wpdb;
+
+ $sql = "SELECT * FROM MessageBoards ORDER BY ReplyID ASC LIMIT $limit OFFSET $start";
+ $forum = $wpdb->get_results( $sql, ARRAY_A );
+// echo '<pre>', print_r($forum), '</pre>';
+
+ foreach($forum as $key => $fd){
+
+ if ( isset( $Members[$fd['PostedBy']] ) ){
+ $name = $Members[$fd['PostedBy']];
+
+ $new_id = get_user_by('slug',$name);
+ $post_author = $new_id->ID;
+ } else {
+ $post_author = $fd['PostedBy'];
+ }
+ $old_post_id = $fd['MessageID'];
+ $post_content = $fd['Message'];
+ $post_title = $fd['Subject'];
+ $post_date = $fd['PostedDate'];
+ $reply = $fd['ReplyID'];
+
+ if( strpos( $post_title, 'Re:') !== false ){
+ $args = array(
+ 'post_author' => $post_author,
+ 'post_content' => $post_content,
+ 'post_title' => $post_title,
+ 'post_date' => $post_date,
+ 'post_name' => $old_post_id,
+ 'post_type' => 'reply',
+ 'post_status' => 'publish',
+ );
+
+ }else if( strpos( $post_title, 'Re:') === false ){
+ $args = array(
+ 'post_author' => $post_author,
+ 'post_content' => $post_content,
+ 'post_title' => $post_title,
+ 'post_date' => $post_date,
+ 'post_name' => $old_post_id,
+ 'post_type' => 'topic',
+ 'post_status' => 'publish',
+ 'post_parent' => 28850
+ );
+ }
+ $new_post_id = wp_insert_post($args);
+ add_post_meta($new_post_id, '_bbp_forum_id', 28850);
+ add_post_meta($new_post_id, '_bbp_last_active_time', $post_date);
+
+
+ if($reply === '0'){
+ add_post_meta($new_post_id, '_bbp_topic_id', $new_post_id);
+ } else if($reply !== '0'){
+ $args = array(
+ 'name' => $reply,
+ 'post_type' => 'topic',
+ 'post_status' => 'publish',
+ 'numberposts' => 1
+ );
+ $topic = get_posts($args);
+ add_post_meta( $new_post_id, '_bbp_topic_id', $topic[0]->ID );
+// $post_update = "UPDATE glm_posts SET post_parent= $topic[0]->ID WHERE ID = $new_post_id";
+// wp_update_post( array( 'ID' => $new_post_id,'post_parent' => $topic[0]->ID ) );
+ $wpdb->update('glm_posts', array('post_parent' => $topic[0]->ID),array('ID' => $new_post_id));
}
- fclose( $fh );
}
- $resultMessage .= '<pre>$file_data: ' . print_r( $file_data, true ) . '</pre>';
+
+ $resultMessage = "<pre>Start: $start</pre>";
+ $start += $limit;
+ $resultMessage .= "<p><a class='next-import-btn' href=\"". $url . "&limit=$limit&start=$start\">Next</a></p>";
+
break;
default: