/** * Import data into the database from an XML file * * @param int $step * @param str $file_name */ public function process_file($h, $step = 0, $file_name = '') { $uploads_folder = PLUGINS . "pligg_importer/uploads/"; $xml = simplexml_load_file($uploads_folder . $file_name); echo "<h2>Importing data from <i>" . $xml->getName() . "</i></h2>"; switch ($step) { case 1: $this->create_temp_table($h); $cats = new PliggImp1(); $cats->step1($h, $xml, $file_name); break; case 2: $links = new PliggImp2(); $links->step2($h, $xml, $file_name); break; case 3: $comms = new PliggImp3(); $comms->step3($h, $xml, $file_name); break; case 4: $tags = new PliggImp4(); $tags->step4($h, $xml, $file_name); break; case 5: $users = new PliggImp5(); $users->step5($h, $xml, $file_name); break; case 6: $votes = new PliggImp6(); $votes->step6($h, $xml, $file_name); break; default: break; } echo "<br /><br />"; }
/** * Step 2 - Import Links * * @param array $xml * @param string $file_name * @return bool */ function step2($h, $xml, $file_name) { echo "<b>Table:</b> Links...<br /><br />"; $this_table = "posts"; $h->db->query($h->db->prepare("TRUNCATE " . DB_PREFIX . $this_table)); echo "<i>Number of records added:</i> "; $count = 0; foreach ($xml->children() as $child) { // Skip any record that has no title if ($child->link_title != "") { $count++; // Store old id. We need this to work out authors and categories later... $link[$count]['old_id'] = $child->link_id; $link[$count]['old_id']['category'] = $child->link_category; $link[$count]['old_id']['author'] = $child->link_author; switch ($child->link_status) { case 'discard': $child->link_status = 'buried'; break; case 'queued': $child->link_status = 'new'; break; case 'published': $child->link_status = 'top'; break; case 'processing': // JapanSoc custom status $child->link_status = 'buried'; break; case 'pending': // SWCMS Submission Approval module $child->link_status = 'pending'; break; case 'page': // SWCMS Pages module $child->link_status = 'page'; break; default: break; } // Get the original domain $parsed = parse_url($child->link_url); if (isset($parsed['scheme']) && isset($parsed['host'])) { $domain = $parsed['scheme'] . "://" . $parsed['host']; } else { $domain = ''; } $columns = "post_author, post_category, post_status, post_type, post_date, post_title, post_orig_url, post_domain, post_url, post_content, post_votes_up, post_votes_down, post_tags, post_updateby"; $sql = "INSERT INTO " . DB_PREFIX . $this_table . " (" . $columns . ") VALUES(%d, %d, %s, %s, %s, %s, %s, %s, %s, %s, %d, %d, %s, %d)"; $cts = new PliggImp1(); // Insert into links table $h->db->query($h->db->prepare($sql, $child->link_author, $cts->get_new_cat_id($h, $child->link_category), $child->link_status, urlencode('news'), $child->link_date, urlencode(trim($child->link_title)), urlencode($child->link_url), urlencode($domain), urlencode(strtolower(str_replace('_', '-', $child->link_title_url))), urlencode(trim($child->link_content)), $child->link_votes, $child->link_reports, urlencode($child->link_tags), $h->currentUser->id)); // Grab the ID of the last insert. $link[$count]['old_id']['new_id'] = $h->db->get_var($h->db->prepare("SELECT LAST_INSERT_ID()")); $sql = "REPLACE INTO " . DB_PREFIX . "pliggimp_temp (pliggimp_setting, pliggimp_old_value, pliggimp_new_value) VALUES(%s, %d, %d)"; $h->db->query($h->db->prepare($sql, 'link_id', $link[$count]['old_id'], $link[$count]['old_id']['new_id'])); } } //Output the number of records added echo $count . "<br /><br />"; echo "<span style='color: green;'><b>Links table imported successfully!</b></span><br /><br />"; echo "<a class='pliggimp_next' href='" . BASEURL . "admin_index.php?page=plugin_settings&plugin=pligg_importer&step=3'>Continue</a>"; return true; }