/wp-content/plugins/buddypress/bp-core/admin/bp-core-schema.php

https://github.com/voidit/nycga2 · PHP · 300 lines · 250 code · 47 blank · 3 comment · 4 complexity · 0ea775f5b8a7a1ff0ebdb0cbc4523515 MD5 · raw file

  1. <?php
  2. // Exit if accessed directly
  3. if ( !defined( 'ABSPATH' ) ) exit;
  4. function bp_core_set_charset() {
  5. global $wpdb;
  6. require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
  7. /* BuddyPress component DB schema */
  8. if ( !empty($wpdb->charset) )
  9. return "DEFAULT CHARACTER SET $wpdb->charset";
  10. return '';
  11. }
  12. function bp_core_install_notifications() {
  13. global $wpdb;
  14. $charset_collate = bp_core_set_charset();
  15. $bp_prefix = bp_core_get_table_prefix();
  16. $sql[] = "CREATE TABLE {$bp_prefix}bp_notifications (
  17. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  18. user_id bigint(20) NOT NULL,
  19. item_id bigint(20) NOT NULL,
  20. secondary_item_id bigint(20),
  21. component_name varchar(75) NOT NULL,
  22. component_action varchar(75) NOT NULL,
  23. date_notified datetime NOT NULL,
  24. is_new bool NOT NULL DEFAULT 0,
  25. KEY item_id (item_id),
  26. KEY secondary_item_id (secondary_item_id),
  27. KEY user_id (user_id),
  28. KEY is_new (is_new),
  29. KEY component_name (component_name),
  30. KEY component_action (component_action),
  31. KEY useritem (user_id,is_new)
  32. ) {$charset_collate};";
  33. dbDelta($sql);
  34. }
  35. function bp_core_install_activity_streams() {
  36. global $wpdb;
  37. $charset_collate = bp_core_set_charset();
  38. $bp_prefix = bp_core_get_table_prefix();
  39. $sql[] = "CREATE TABLE {$bp_prefix}bp_activity (
  40. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  41. user_id bigint(20) NOT NULL,
  42. component varchar(75) NOT NULL,
  43. type varchar(75) NOT NULL,
  44. action text NOT NULL,
  45. content longtext NOT NULL,
  46. primary_link varchar(150) NOT NULL,
  47. item_id varchar(75) NOT NULL,
  48. secondary_item_id varchar(75) DEFAULT NULL,
  49. date_recorded datetime NOT NULL,
  50. hide_sitewide bool DEFAULT 0,
  51. mptt_left int(11) NOT NULL DEFAULT 0,
  52. mptt_right int(11) NOT NULL DEFAULT 0,
  53. KEY date_recorded (date_recorded),
  54. KEY user_id (user_id),
  55. KEY item_id (item_id),
  56. KEY secondary_item_id (secondary_item_id),
  57. KEY component (component),
  58. KEY type (type),
  59. KEY mptt_left (mptt_left),
  60. KEY mptt_right (mptt_right),
  61. KEY hide_sitewide (hide_sitewide)
  62. ) {$charset_collate};";
  63. $sql[] = "CREATE TABLE {$bp_prefix}bp_activity_meta (
  64. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  65. activity_id bigint(20) NOT NULL,
  66. meta_key varchar(255) DEFAULT NULL,
  67. meta_value longtext DEFAULT NULL,
  68. KEY activity_id (activity_id),
  69. KEY meta_key (meta_key)
  70. ) {$charset_collate};";
  71. dbDelta($sql);
  72. }
  73. function bp_core_install_friends() {
  74. global $wpdb;
  75. $charset_collate = bp_core_set_charset();
  76. $bp_prefix = bp_core_get_table_prefix();
  77. $sql[] = "CREATE TABLE {$bp_prefix}bp_friends (
  78. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  79. initiator_user_id bigint(20) NOT NULL,
  80. friend_user_id bigint(20) NOT NULL,
  81. is_confirmed bool DEFAULT 0,
  82. is_limited bool DEFAULT 0,
  83. date_created datetime NOT NULL,
  84. KEY initiator_user_id (initiator_user_id),
  85. KEY friend_user_id (friend_user_id)
  86. ) {$charset_collate};";
  87. dbDelta($sql);
  88. }
  89. function bp_core_install_groups() {
  90. global $wpdb;
  91. $charset_collate = bp_core_set_charset();
  92. $bp_prefix = bp_core_get_table_prefix();
  93. $sql[] = "CREATE TABLE {$bp_prefix}bp_groups (
  94. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  95. creator_id bigint(20) NOT NULL,
  96. name varchar(100) NOT NULL,
  97. slug varchar(200) NOT NULL,
  98. description longtext NOT NULL,
  99. status varchar(10) NOT NULL DEFAULT 'public',
  100. enable_forum tinyint(1) NOT NULL DEFAULT '1',
  101. date_created datetime NOT NULL,
  102. KEY creator_id (creator_id),
  103. KEY status (status)
  104. ) {$charset_collate};";
  105. $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_members (
  106. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  107. group_id bigint(20) NOT NULL,
  108. user_id bigint(20) NOT NULL,
  109. inviter_id bigint(20) NOT NULL,
  110. is_admin tinyint(1) NOT NULL DEFAULT '0',
  111. is_mod tinyint(1) NOT NULL DEFAULT '0',
  112. user_title varchar(100) NOT NULL,
  113. date_modified datetime NOT NULL,
  114. comments longtext NOT NULL,
  115. is_confirmed tinyint(1) NOT NULL DEFAULT '0',
  116. is_banned tinyint(1) NOT NULL DEFAULT '0',
  117. invite_sent tinyint(1) NOT NULL DEFAULT '0',
  118. KEY group_id (group_id),
  119. KEY is_admin (is_admin),
  120. KEY is_mod (is_mod),
  121. KEY user_id (user_id),
  122. KEY inviter_id (inviter_id),
  123. KEY is_confirmed (is_confirmed)
  124. ) {$charset_collate};";
  125. $sql[] = "CREATE TABLE {$bp_prefix}bp_groups_groupmeta (
  126. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  127. group_id bigint(20) NOT NULL,
  128. meta_key varchar(255) DEFAULT NULL,
  129. meta_value longtext DEFAULT NULL,
  130. KEY group_id (group_id),
  131. KEY meta_key (meta_key)
  132. ) {$charset_collate};";
  133. dbDelta($sql);
  134. }
  135. function bp_core_install_private_messaging() {
  136. global $wpdb;
  137. $charset_collate = bp_core_set_charset();
  138. $bp_prefix = bp_core_get_table_prefix();
  139. $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_messages (
  140. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  141. thread_id bigint(20) NOT NULL,
  142. sender_id bigint(20) NOT NULL,
  143. subject varchar(200) NOT NULL,
  144. message longtext NOT NULL,
  145. date_sent datetime NOT NULL,
  146. KEY sender_id (sender_id),
  147. KEY thread_id (thread_id)
  148. ) {$charset_collate};";
  149. $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_recipients (
  150. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  151. user_id bigint(20) NOT NULL,
  152. thread_id bigint(20) NOT NULL,
  153. unread_count int(10) NOT NULL DEFAULT '0',
  154. sender_only tinyint(1) NOT NULL DEFAULT '0',
  155. is_deleted tinyint(1) NOT NULL DEFAULT '0',
  156. KEY user_id (user_id),
  157. KEY thread_id (thread_id),
  158. KEY is_deleted (is_deleted),
  159. KEY sender_only (sender_only),
  160. KEY unread_count (unread_count)
  161. ) {$charset_collate};";
  162. $sql[] = "CREATE TABLE {$bp_prefix}bp_messages_notices (
  163. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  164. subject varchar(200) NOT NULL,
  165. message longtext NOT NULL,
  166. date_sent datetime NOT NULL,
  167. is_active tinyint(1) NOT NULL DEFAULT '0',
  168. KEY is_active (is_active)
  169. ) {$charset_collate};";
  170. dbDelta($sql);
  171. }
  172. function bp_core_install_extended_profiles() {
  173. global $wpdb;
  174. $charset_collate = bp_core_set_charset();
  175. $bp_prefix = bp_core_get_table_prefix();
  176. bp_update_option( 'bp-xprofile-base-group-name', _x( 'Base', 'First XProfile group name', 'buddypress' ) );
  177. bp_update_option( 'bp-xprofile-fullname-field-name', _x( 'Name', 'XProfile fullname field name', 'buddypress' ) );
  178. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_groups (
  179. id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  180. name varchar(150) NOT NULL,
  181. description mediumtext NOT NULL,
  182. group_order bigint(20) NOT NULL DEFAULT '0',
  183. can_delete tinyint(1) NOT NULL,
  184. KEY can_delete (can_delete)
  185. ) {$charset_collate};";
  186. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_fields (
  187. id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  188. group_id bigint(20) unsigned NOT NULL,
  189. parent_id bigint(20) unsigned NOT NULL,
  190. type varchar(150) NOT NULL,
  191. name varchar(150) NOT NULL,
  192. description longtext NOT NULL,
  193. is_required tinyint(1) NOT NULL DEFAULT '0',
  194. is_default_option tinyint(1) NOT NULL DEFAULT '0',
  195. field_order bigint(20) NOT NULL DEFAULT '0',
  196. option_order bigint(20) NOT NULL DEFAULT '0',
  197. order_by varchar(15) NOT NULL DEFAULT '',
  198. can_delete tinyint(1) NOT NULL DEFAULT '1',
  199. KEY group_id (group_id),
  200. KEY parent_id (parent_id),
  201. KEY field_order (field_order),
  202. KEY can_delete (can_delete),
  203. KEY is_required (is_required)
  204. ) {$charset_collate};";
  205. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_data (
  206. id bigint(20) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
  207. field_id bigint(20) unsigned NOT NULL,
  208. user_id bigint(20) unsigned NOT NULL,
  209. value longtext NOT NULL,
  210. last_updated datetime NOT NULL,
  211. KEY field_id (field_id),
  212. KEY user_id (user_id)
  213. ) {$charset_collate};";
  214. $sql[] = "CREATE TABLE {$bp_prefix}bp_xprofile_meta (
  215. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  216. object_id bigint(20) NOT NULL,
  217. object_type varchar(150) NOT NULL,
  218. meta_key varchar(255) DEFAULT NULL,
  219. meta_value longtext DEFAULT NULL,
  220. KEY object_id (object_id),
  221. KEY meta_key (meta_key)
  222. ) {$charset_collate};";
  223. dbDelta( $sql );
  224. // Insert the default group and fields
  225. $insert_sql = array();
  226. if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_groups WHERE id = 1" ) )
  227. $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_groups ( name, description, can_delete ) VALUES ( " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-base-group-name' ) ) ) . ", '', 0 );";
  228. if ( !$wpdb->get_var( "SELECT id FROM {$bp_prefix}bp_xprofile_fields WHERE id = 1" ) )
  229. $insert_sql[] = "INSERT INTO {$bp_prefix}bp_xprofile_fields ( group_id, parent_id, type, name, description, is_required, can_delete ) VALUES ( 1, 0, 'textbox', " . $wpdb->prepare( '%s', stripslashes( bp_get_option( 'bp-xprofile-fullname-field-name' ) ) ) . ", '', 1, 0 );";
  230. dbDelta( $insert_sql );
  231. }
  232. function bp_core_install_blog_tracking() {
  233. global $wpdb;
  234. $charset_collate = bp_core_set_charset();
  235. $bp_prefix = bp_core_get_table_prefix();
  236. $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs (
  237. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  238. user_id bigint(20) NOT NULL,
  239. blog_id bigint(20) NOT NULL,
  240. KEY user_id (user_id),
  241. KEY blog_id (blog_id)
  242. ) {$charset_collate};";
  243. $sql[] = "CREATE TABLE {$bp_prefix}bp_user_blogs_blogmeta (
  244. id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  245. blog_id bigint(20) NOT NULL,
  246. meta_key varchar(255) DEFAULT NULL,
  247. meta_value longtext DEFAULT NULL,
  248. KEY blog_id (blog_id),
  249. KEY meta_key (meta_key)
  250. ) {$charset_collate};";
  251. dbDelta($sql);
  252. }
  253. ?>