PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/discuzx/utility/convert/source/uch2.0_x1.5/table/home_group.php

https://github.com/bluelovers/Discuz
PHP | 251 lines | 217 code | 29 blank | 5 comment | 24 complexity | 16d4349fa46dc19b3c1e94c7946ae9ac MD5 | raw file
  1. <?php
  2. /**
  3. * DiscuzX Convert
  4. *
  5. * $Id: home_group.php 19554 2011-01-07 04:26:02Z zhengqingpeng $
  6. */
  7. $curprg = basename(__FILE__);
  8. $table_source = $db_source->table('mtag');
  9. require_once DISCUZ_ROOT.'./include/editor.func.php';
  10. $fieldid = intval(getgpc('fieldid'));
  11. $tagid = intval(getgpc('tagid'));
  12. $gid = intval(getgpc('gid'));
  13. $fid = intval(getgpc('fid'));
  14. $sid = intval(getgpc('sid'));
  15. $limit = $setting['limit']['mtag'] ? $setting['limit']['mtag'] : 100;
  16. $nextid = 0;
  17. $threadquery = $db_source->query("SELECT * FROM ".$db_source->table('thread')." WHERE tid > '$start' AND tagid='$tagid' ORDER BY tid LIMIT $limit");
  18. while($value = $db_source->fetch_array($threadquery)) {
  19. $nextid = $value['tid'];
  20. $value = daddslashes($value);
  21. $value['replynum'] = intval($value['replynum']);
  22. $threadarr = array(
  23. 'fid' => $sid,
  24. 'author' => $value['username'],
  25. 'authorid' => $value['uid'],
  26. 'subject' => $value['subject'],
  27. 'dateline' => $value['dateline'],
  28. 'lastpost' => $value['lastpost'],
  29. 'lastposter' => $value['lastauthor'],
  30. 'views' => $value['viewnum'],
  31. 'replies' => $value['replynum'],
  32. 'digest' => $value['digest'],
  33. 'displayorder' => $value['displayorder'] ? 1 : 0,
  34. 'isgroup' => 1
  35. );
  36. $tid = $db_target->insert('forum_thread', $threadarr, true);
  37. $lastpost = array();
  38. $query = $db_source->query("SELECT * FROM ".$db_source->table('post')." WHERE tid='$value[tid]' ORDER BY dateline");
  39. while($post = $db_source->fetch_array($query)) {
  40. $post['message'] = html2bbcode($post['message']);
  41. $post = daddslashes($post);
  42. $postarr = array(
  43. 'fid' => $sid,
  44. 'tid' => $tid,
  45. 'first' => $post['isthread'] ? 1 : 0,
  46. 'author' => $post['username'],
  47. 'authorid' => $post['uid'],
  48. 'subject' => $post['isthread'] ? $value['subject'] : $post['subject'],
  49. 'dateline' => $post['dateline'],
  50. 'message' => $post['message'],
  51. 'useip' => $post['ip']
  52. );
  53. $lastpost = array(
  54. 'lastpost' => $post['dateline'],
  55. 'lastposter' => $post['username'],
  56. );
  57. $db_target->insert('forum_post', $postarr);
  58. $db_target->insert('common_member_count', array('uid' => $value['uid']), 0, false, true);
  59. $db_target->query("UPDATE ".$db_target->table('common_member_count')." SET posts=posts+1 WHERE uid='$post[uid]'", 'UNBUFFERED');
  60. $db_target->query("UPDATE ".$db_target->table('forum_groupuser')." SET replies=replies+1 WHERE fid='$sid' AND uid='$post[uid]'", 'UNBUFFERED');
  61. }
  62. if($lastpost) {
  63. $db_target->update('forum_thread', $lastpost, array('tid' => $tid));
  64. } else {
  65. $lastpost['lastpost'] = $value['lastpost'];
  66. }
  67. $db_target->insert('common_member_count', array('uid' => $value['uid']), 0, false, true);
  68. $db_target->query("UPDATE ".$db_target->table('common_member_count')." SET threads=threads+1 WHERE uid='$value[uid]'", 'UNBUFFERED');
  69. $db_target->query("UPDATE ".$db_target->table('forum_groupuser')." SET threads=threads+1 WHERE fid='$sid' AND uid='$value[uid]'", 'UNBUFFERED');
  70. $db_target->query("UPDATE ".$db_target->table('forum_forum')." SET lastpost='$lastpost[lastpost]', threads=threads+1, posts=posts+$value[replynum] WHERE fid='$sid'", 'UNBUFFERED');
  71. }
  72. $force = false;
  73. if(!$nextid) {
  74. if(!getmtag($tagid)) {
  75. if(!getprofield($fieldid)) {
  76. $nextid = 0;
  77. } else {
  78. $force = true;
  79. }
  80. } else {
  81. $force = true;
  82. }
  83. $nextid = $force ? 1 : 0;
  84. }
  85. if($nextid) {
  86. if($force) $nextid = 0;
  87. $mtag = array();
  88. if($tagid) {
  89. $mtag = $db_source->fetch_first("SELECT * FROM ".$db_source->table('mtag')." WHERE tagid='$tagid'");
  90. }
  91. $profield = $db_source->fetch_first("SELECT * FROM ".$db_source->table('profield')." WHERE fieldid='$fieldid'");
  92. showmessage("繼續轉換數據表 ".$table_source." : $profield[title] ".(!empty($mtag) ? "&rsaquo; $mtag[tagname] &rsaquo; tid > $nextid":""), "index.php?a=$action&source=$source&prg=$curprg&start=$nextid&gid=$gid&fid=$fid&sid=$sid&fieldid=$fieldid&tagid=$tagid");
  93. }
  94. $maxpid = $db_target->result_first("SELECT MAX(pid) FROM ".$db_target->table('forum_post'));
  95. $maxpid = intval($maxpid) + 1;
  96. $db_target->query("ALTER TABLE ".$db_target->table('forum_post_tableid')." AUTO_INCREMENT=$maxpid");
  97. function getmtag($start) {
  98. global $db_source, $db_target, $fieldid, $gid, $fid, $sid, $tagid;
  99. if(empty($fieldid)) {
  100. getprofield($fieldid);
  101. }
  102. $mtag = $db_source->fetch_first("SELECT * FROM ".$db_source->table('mtag')." WHERE fieldid='$fieldid' AND tagid>'$start' ORDER BY tagid LIMIT 1");
  103. if(empty($mtag)) {
  104. $tagid = $sid = 0;
  105. return false;
  106. }
  107. $tagid = $mtag['tagid'];
  108. $founder = $groupuser = array();
  109. $query = $db_source->query("SELECT * FROM ".$db_source->table('tagspace')." WHERE tagid='$mtag[tagid]'");
  110. while($space = $db_source->fetch_array($query)) {
  111. $space['level'] = 4;
  112. if($space['grade'] == 9) {
  113. $space['level'] = 1;
  114. if(empty($founder)) {
  115. $founder = array('founderuid' => $space['uid'], 'foundername' => daddslashes($space['username']));
  116. }
  117. } elseif($space['grade'] == 8) {
  118. $space['level'] = 2;
  119. } elseif($space['grade'] == 1) {
  120. $space['level'] = 3;
  121. } elseif($space['grade'] == -2) {
  122. $space['level'] = 0;
  123. }
  124. $groupuser[$space['uid']] = $space;
  125. }
  126. if(empty($founder)) {
  127. $member = $db_target->fetch_first("SELECT uid,username FROM ".$db_target->table('common_member')." WHERE adminid='1' ORDER BY uid LIMIT 1");
  128. $founder = array('founderuid' => $member['uid'], 'foundername' => daddslashes($member['username']));
  129. $groupuser[$member['uid']] = array('uid' => $member['uid'], 'username' => $member['username'], 'level' => 1);
  130. }
  131. $levelid = $db_target->result_first("SELECT levelid FROM ".$db_target->table('forum_grouplevel')." WHERE creditshigher<='0' AND '0'<creditslower LIMIT 1");
  132. $forumarr = array(
  133. 'fup' => $fid,
  134. 'type' => 'sub',
  135. 'name' => daddslashes($mtag['tagname']),
  136. 'status' => 3,
  137. 'allowsmilies' => 1,
  138. 'allowbbcode' => 1,
  139. 'allowimgcode' => 1,
  140. 'level' => $levelid
  141. );
  142. $sid = $db_target->insert('forum_forum', $forumarr, true);
  143. $forumfieldarr = array(
  144. 'fid' => $sid,
  145. 'description' => daddslashes(html2bbcode($mtag['announcement'])),
  146. 'jointype' => $mtag['joinperm'] ? ($mtag['joinperm'] == 1 ? 2 : 1) : 0,
  147. 'gviewperm' => $mtag['viewperm'] ? 0 : 1,
  148. 'dateline' => TIMESTAMP,
  149. 'founderuid' => $founder['founderuid'],
  150. 'foundername' => $founder['foundername'],
  151. 'membernum' => $mtag['membernum']
  152. );
  153. $db_target->insert('forum_forumfield', $forumfieldarr);
  154. $db_target->query("UPDATE ".$db_target->table('forum_forumfield')." SET groupnum=groupnum+1 WHERE fid='$fid'");
  155. foreach($groupuser as $uid => $user) {
  156. $userarr = array(
  157. 'fid' => $sid,
  158. 'uid' => $uid,
  159. 'username' => daddslashes($user['username']),
  160. 'level' => $user['level'],
  161. 'threads' => 0,
  162. 'replies' => 0,
  163. 'joindateline' => TIMESTAMP,
  164. 'lastupdate' => TIMESTAMP,
  165. 'privacy' => '',
  166. );
  167. $db_target->insert('forum_groupuser', $userarr, 0, true);
  168. }
  169. $query = $db_source->query("SELECT * FROM ".$db_source->table('mtaginvite')." WHERE tagid='$mtag[tagid]'");
  170. while($invite = $db_source->fetch_array($query)) {
  171. $invitearr = array(
  172. 'fid' => $sid,
  173. 'uid' => $invite['fromuid'],
  174. 'inviteuid' => $invite['uid'],
  175. 'dateline' => $invite['dateline']
  176. );
  177. $db_target->insert('forum_groupinvite', $invitearr, 0, true);
  178. }
  179. return true;
  180. }
  181. function getprofield($start) {
  182. global $db_source, $db_target, $fieldid, $gid, $fid, $tagid;
  183. if(!$gid) {
  184. $gid = $db_target->insert('forum_forum', array('type' => 'group', 'name' => '空間群組', 'status' => 3), 1);
  185. $db_target->insert('forum_forumfield', array('fid' => $gid));
  186. }
  187. $profield = $db_source->fetch_first("SELECT * FROM ".$db_source->table('profield')." WHERE fieldid>'$start' ORDER BY fieldid LIMIT 1");
  188. if(empty($profield)) {
  189. $fid = 0;
  190. $tagid = 0;
  191. return false;
  192. }
  193. $fieldid = $profield['fieldid'];
  194. $table_forum_columns = array('fup', 'type', 'name', 'status', 'displayorder', 'styleid', 'allowsmilies', 'allowhtml', 'allowbbcode', 'allowimgcode', 'allowanonymous', 'allowpostspecial', 'alloweditrules', 'alloweditpost', 'modnewposts', 'recyclebin', 'jammer', 'forumcolumns', 'threadcaches', 'disablewatermark', 'autoclose', 'simple');
  195. $table_forumfield_columns = array('fid', 'attachextensions', 'threadtypes', 'postcredits', 'replycredits', 'digestcredits', 'postattachcredits', 'getattachcredits', 'viewperm', 'postperm', 'replyperm', 'getattachperm', 'postattachperm');
  196. $forumfields = array(
  197. 'allowsmilies' => 1,
  198. 'allowbbcode' => 1,
  199. 'allowimgcode' => 1,
  200. 'allowpostspecial' => 127,
  201. 'fup' => $gid,
  202. 'type' => 'forum',
  203. 'name' => daddslashes($profield['title']),
  204. 'status' => 3
  205. );
  206. $data = array();
  207. foreach($table_forum_columns as $field) {
  208. if(isset($forumfields[$field])) {
  209. $data[$field] = $forumfields[$field];
  210. }
  211. }
  212. $forumfields['fid'] = $fid = $db_target->insert('forum_forum', $data, 1);
  213. $data = array();
  214. foreach($table_forumfield_columns as $field) {
  215. if(isset($forumfields[$field])) {
  216. $data[$field] = $forumfields[$field];
  217. }
  218. }
  219. $db_target->insert('forum_forumfield', $data);
  220. return true;
  221. }
  222. ?>