News:

Please note these forums are mostly a testing ground for my SMF work and I don't really use them otherwise.

Main Menu

Paste-1217552302:v:use_geshi-1:v:type-php

Started by Oldiesmann, Aug 01, 2008, 12:58 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Oldiesmann

<?php
error_reporting(E_ALL);
/**
 * @author Oldiesmann
 * @copyright 2008
 */

$connect = mysql_connect('localhost', 'oldies_oldiesman', 'WHHS2001');
$db = mysql_select_db('oldies_dhtest');

// Get the forum info...
$query = mysql_query("SELECT id_board, name FROM smf_boards");
while($results = mysql_fetch_assoc($query))
{
   $boards[$results['name']] = $results['id_board'];
}
mysql_free_result($query);

$db = mysql_select_db('oldies_dhdata');

// Now that we've done that, we go ahead and pull the topics... - we only have 1457 topics
$query = mysql_query("SELECT DISTINCT(`boardtopics.topicname`) AS topicname FROM client_183_message_board LIMIT 1457");
while($results = mysql_fetch_assoc($query))
{
   // Now... Pull the forum for this topic...
   $query2 = mysql_query("SELECT `boardforums.forumname` AS forumname FROM client_183_message_board WHERE `boardtopics.topicname` = '" . mysql_real_escape_string($results['topicname']) . "'");
   $results['forumname'] = mysql_result($query2, 0);
   mysql_free_result($query2);

   // Get the ID of the member who started it...
   $query3 = mysql_query("SELECT `boardpost.cuckey` FROM client_183_message_board WHERE `boardtopics.topicname` = '" . mysql_real_escape_string($results['topicname']) . "'");
   $cuckey = mysql_result($query3, 0);
   mysql_free_result($query3);

   $query4 = mysql_query("SELECT id_member FROM client_183_community WHERE cuckey = '$cuckey' LIMIT 1");
   $results['id_member'] = mysql_result($query4, 0);
   mysql_free_result($query4);

   $data = array(
      'id_board' => $boards[$results['forumname']],
      'id_member_started' => $results['id_member']
   );

   // Now we insert the data...
   $query5 = mysql_query("INSERT INTO smf_topics (" . implode(', ', array_keys($data)) . ") VALUES(" . implode(', ', array_values($data)) . ")");
   $topic_id = mysql_insert_id();

   $query6 = mysql_query("UPDATE client_183_message_board SET id_topic = '$topic_id' WHERE `boardtopics.topicname` = '" . mysql_real_escape_string($results['topicname']) . "'");
}
mysql_free_result($query);

// Ok... Now that we've done that, on to the real fun... Update the messages...
$query = mysql_query("SELECT id_topic FROM smf_topics");
//$query = mysql_query("SELECT `boardforums.forumname`, `boardtopics.topicname`, `boardpost.cuckey`, `boardpost.post`, `id_topic` FROM client_183_message_board");
while($results = mysql_fetch_assoc($query))
{
   $query2 = mysql_query("SELECT `boardforums.forumname`, `boardtopics.topicname`, `boardpost.cuckey`, `boardpost.post` FROM client_183_message_board WHERE id_topic = $results[id_topic]");
   $board_info = mysql_fetch_assoc($query2);

   $board_info['cuckey'] = $board_info['boardpost.cuckey'];
   
   // Figure out who posted this...
   $query3 = mysql_query("SELECT id_member, emailaddress, username FROM client_183_community WHERE cuckey = '$board_info[cuckey]'");
   $temp = mysql_fetch_array($query3);
   mysql_free_result($query3);

   // Now we look for something else here...

   /* Info we need:
      id_msg = automatically set
      id_topic
      id_member
      id_msg_modified -> ?
      subject
      poster_name
      poster_email
      id_board*/

   $forumname = $board_info['boardforums.forumname'];

   $data = array(
      'id_topic' => $results['id_topic'],
      'id_board' => $boards[$forumname],
      'id_member' => $temp['id_member'],
      'subject' => "'" . mysql_real_escape_string($board_info['boardtopics.topicname']) . "'",
      'poster_name' => "'" . $temp['username'] . "'"
   );

   // Now we fix the \\n's
   $results['boardpost.post'] = str_replace("\\\n", '
', $board_info['boardpost.post']);

   // Now fix the other stuff...
   $results['boardpost.post'] = str_replace(array("\n", "'"), array('
', '''), $results['boardpost.post']);
   
   $data['message'] = $results['boardpost.post'];
   
   // Now the fun part...
   $query4 = mysql_query("INSERT INTO smf_messages(" . implode(', ', array_keys($data)) . ") VALUES (" . implode(', ', array_values($data)) . ")");
}

?>