PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/convert/boards/phpbb2/posts.php

https://gitlab.com/mybbpl/merge-1.6-pl
PHP | 156 lines | 102 code | 23 blank | 31 comment | 10 complexity | e01cf9301950acf89fd704663d1fb0fc MD5 | raw file
  1. <?php
  2. /**
  3. * Polish Language File developed by mybboard.pl for MyBB Merge System
  4. * Tłumaczenie: szulcu, Gigi
  5. * Poprawki: Ekipa Polskiego Supportu MyBB (mybboard.pl)
  6. * Wersja 1.0
  7. **/
  8. /**
  9. * MyBB 1.6
  10. * Copyright 2009 MyBB Group, All Rights Reserved
  11. *
  12. * Website: http://www.mybb.com
  13. * License: http://www.mybb.com/about/license
  14. */
  15. // Disallow direct access to this file for security reasons
  16. if(!defined("IN_MYBB"))
  17. {
  18. die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  19. }
  20. class PHPBB2_Converter_Module_Posts extends Converter_Module_Posts {
  21. var $settings = array(
  22. 'friendly_name' => 'postów',
  23. 'progress_column' => 'post_id',
  24. 'default_per_screen' => 1000,
  25. 'check_table_type' => array("posts", "posts_text"),
  26. );
  27. function import()
  28. {
  29. global $import_session;
  30. $query = $this->old_db->query("
  31. SELECT p.*, pt.*
  32. FROM ".OLD_TABLE_PREFIX."posts p
  33. LEFT JOIN ".OLD_TABLE_PREFIX."posts_text pt ON(p.post_id=pt.post_id)
  34. LIMIT ".$this->trackers['start_posts'].", ".$import_session['posts_per_screen']
  35. );
  36. while($post = $this->old_db->fetch_array($query))
  37. {
  38. $this->insert($post);
  39. }
  40. }
  41. function convert_data($data)
  42. {
  43. $insert_data = array();
  44. // phpBB 2 values
  45. $insert_data['import_pid'] = $data['post_id'];
  46. $insert_data['tid'] = $this->get_import->tid($data['topic_id']);
  47. // Check the last post for any NULL's, converted by phpBB's parser to a default topic
  48. if($data['post_subject'] === 'NULL')
  49. {
  50. $data['post_subject'] = 'Welcome to phpBB 2';
  51. }
  52. // Get Username
  53. $topic_poster = $this->get_user($data['poster_id']);
  54. // Check to see if we need to inherit any post subjects from the thread
  55. if(empty($data['post_subject']))
  56. {
  57. $query = $this->old_db->simple_select("topics", "topic_first_post_id, topic_title", "topic_first_post_id='{$data['post_id']}'", array('limit' => 1));
  58. $topic = $this->old_db->fetch_array($query);
  59. $this->old_db->free_result($query);
  60. if($topic['topic_first_post_id'] == $data['post_id'])
  61. {
  62. $data['post_subject'] = 'RE: '.$topic['topic_title'];
  63. }
  64. }
  65. $insert_data['fid'] = $this->get_import->fid_f($data['forum_id']);
  66. $insert_data['subject'] = encode_to_utf8(utf8_unhtmlentities($data['post_subject']), "posts", "posts");
  67. $insert_data['uid'] = $this->get_import->uid($data['poster_id']);
  68. $insert_data['import_uid'] = $data['poster_id'];
  69. $insert_data['username'] = $this->get_import->username($data['poster_id'], $topic_poster['username']);
  70. $insert_data['dateline'] = $data['post_time'];
  71. $insert_data['message'] = encode_to_utf8($this->bbcode_parser->convert($data['post_text'], $data['bbcode_uid']), "posts", "posts");
  72. $insert_data['ipaddress'] = $this->decode_ip($data['poster_ip']);
  73. $insert_data['includesig'] = $data['enable_sig'];
  74. $insert_data['smilieoff'] = int_to_01($data['enable_smilies']);
  75. return $insert_data;
  76. }
  77. function after_insert($data, $insert_data, $pid)
  78. {
  79. global $db;
  80. $db->update_query("threads", array('firstpost' => $pid), "tid = '{$insert_data['tid']}' AND import_firstpost = '{$insert_data['import_pid']}'");
  81. if($db->affected_rows() == 0)
  82. {
  83. $query = $db->simple_select("threads", "firstpost", "tid = '{$insert_data['tid']}'");
  84. $first_post = $db->fetch_field($query, "firstpost");
  85. $db->free_result($query);
  86. $db->update_query("posts", array('replyto' => $first_post), "pid = '{$pid}'");
  87. }
  88. }
  89. /**
  90. * Get a user from the phpBB database
  91. *
  92. * @param int User ID
  93. * @return array If the uid is 0, returns an array of username as Guest. Otherwise returns the user
  94. */
  95. function get_user($uid)
  96. {
  97. if($uid == 0)
  98. {
  99. return array(
  100. 'username' => 'Gość',
  101. 'user_id' => 0,
  102. );
  103. }
  104. $query = $this->old_db->simple_select("users", "*", "user_id='{$uid}'", array('limit' => 1));
  105. $results = $this->old_db->fetch_array($query);
  106. $this->old_db->free_result($query);
  107. return $results;
  108. }
  109. /**
  110. * Decode function for phpBB's IP Addresses
  111. *
  112. * @param string Encoded IP Address
  113. * @return string Decoded IP Address
  114. */
  115. function decode_ip($ip)
  116. {
  117. $hex_ip = explode('.', chunk_split($ip, 2, '.'));
  118. return hexdec($hex_ip[0]). '.' . hexdec($hex_ip[1]) . '.' . hexdec($hex_ip[2]) . '.' . hexdec($hex_ip[3]);
  119. }
  120. function fetch_total()
  121. {
  122. global $import_session;
  123. // Get number of posts
  124. if(!isset($import_session['total_posts']))
  125. {
  126. $query = $this->old_db->simple_select("posts", "COUNT(*) as count");
  127. $import_session['total_posts'] = $this->old_db->fetch_field($query, 'count');
  128. $this->old_db->free_result($query);
  129. }
  130. return $import_session['total_posts'];
  131. }
  132. }
  133. ?>