| [ Index ] |
PHP Cross Reference of BuddyPress SVN Code |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* Define the parent forum ID */ 4 if ( !defined( 'BP_FORUMS_PARENT_FORUM_ID' ) ) 5 define ( 'BP_FORUMS_PARENT_FORUM_ID', 1 ); 6 7 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-bbpress.php' ); 8 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-classes.php' ); 9 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-templatetags.php' ); 10 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-filters.php' ); 11 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-cssjs.php' ); 12 13 function bp_forums_setup() { 14 global $bp; 15 16 $bp->forums->image_base = BP_PLUGIN_URL . '/bp-forums/images'; 17 $bp->forums->bbconfig = get_site_option( 'bb-config-location' ); 18 } 19 add_action( 'plugins_loaded', 'bp_forums_setup', 5 ); 20 add_action( 'admin_head', 'bp_forums_setup', 3 ); 21 22 function bp_forums_is_installed_correctly() { 23 global $bp; 24 25 if ( file_exists( $bp->forums->bbconfig ) ) 26 return true; 27 28 return false; 29 } 30 31 function bp_forums_add_admin_menu() { 32 global $bp; 33 34 if ( !is_site_admin() ) 35 return false; 36 37 require ( BP_PLUGIN_DIR . '/bp-forums/bp-forums-admin.php' ); 38 39 /* Add the administration tab under the "Site Admin" tab for site administrators */ 40 add_submenu_page( 'bp-core.php', __( 'Forums Setup', 'buddypress' ), __( 'Forums Setup', 'buddypress' ), 2, __FILE__, "bp_forums_bbpress_admin" ); 41 } 42 add_action( 'admin_menu', 'bp_forums_add_admin_menu' ); 43 44 function bp_forums_get_forum( $forum_id ) { 45 do_action( 'bbpress_init' ); 46 return bb_get_forum( $forum_id ); 47 } 48 49 function bp_forums_get_forum_topics( $args = '' ) { 50 do_action( 'bbpress_init' ); 51 52 $defaults = array( 53 'forum_id' => false, 54 'page' => 1, 55 'per_page' => 15, 56 'exclude' => false 57 ); 58 59 $r = wp_parse_args( $args, $defaults ); 60 extract( $r, EXTR_SKIP ); 61 62 return get_latest_topics( array( 'forum' => $forum_id, 'page' => $page_num, 'number' => $per_page, 'exclude' => $exclude ) ); 63 } 64 65 function bp_forums_get_topic_details( $topic_id ) { 66 do_action( 'bbpress_init' ); 67 return get_topic( $topic_id ); 68 } 69 70 function bp_forums_get_topic_id_from_slug( $topic_slug ) { 71 do_action( 'bbpress_init' ); 72 return bb_get_id_from_slug( 'topic', $topic_slug ); 73 } 74 75 function bp_forums_get_topic_posts( $args = '' ) { 76 do_action( 'bbpress_init' ); 77 78 $defaults = array( 79 'topic_id' => false, 80 'page' => 1, 81 'per_page' => 15, 82 'order' => 'ASC' 83 ); 84 85 $args = wp_parse_args( $args, $defaults ); 86 87 $query = new BB_Query( 'post', $args, 'get_thread' ); 88 return $query->results; 89 } 90 91 function bp_forums_get_post( $post_id ) { 92 do_action( 'bbpress_init' ); 93 return bb_get_post( $post_id ); 94 } 95 96 function bp_forums_new_forum( $args = '' ) { 97 do_action( 'bbpress_init' ); 98 99 $defaults = array( 100 'forum_name' => '', 101 'forum_desc' => '', 102 'forum_parent_id' => BP_FORUMS_PARENT_FORUM_ID, 103 'forum_order' => false, 104 'forum_is_category' => 0 105 ); 106 107 $r = wp_parse_args( $args, $defaults ); 108 extract( $r, EXTR_SKIP ); 109 110 return bb_new_forum( array( 'forum_name' => stripslashes( $forum_name ), 'forum_desc' => stripslashes( $forum_desc ), 'forum_parent' => $forum_parent_id, 'forum_order' => $forum_order, 'forum_is_category' => $forum_is_category ) ); 111 } 112 113 function bp_forums_new_topic( $args = '' ) { 114 global $bp; 115 116 do_action( 'bbpress_init' ); 117 118 $defaults = array( 119 'topic_title' => '', 120 'topic_slug' => '', 121 'topic_poster' => $bp->loggedin_user->id, // accepts ids 122 'topic_poster_name' => $bp->loggedin_user->fullname, // accept names 123 'topic_last_poster' => $bp->loggedin_user->id, // accepts ids 124 'topic_last_poster_name' => $bp->loggedin_user->fullname, // accept names 125 'topic_start_time' => bb_current_time( 'mysql' ), 126 'topic_time' => bb_current_time( 'mysql' ), 127 'topic_open' => 1, 128 'forum_id' => 0 // accepts ids or slugs 129 ); 130 131 $r = wp_parse_args( $args, $defaults ); 132 extract( $r, EXTR_SKIP ); 133 134 if ( empty( $topic_slug ) ) 135 $topic_slug = sanitize_title( $topic_title ); 136 137 if ( !$topic_id = bb_insert_topic( array( 'topic_title' => stripslashes( $topic_title ), 'topic_slug' => $topic_slug, 'topic_poster' => $topic_poster, 'topic_poster_name' => $topic_poster_name, 'topic_last_poster' => $topic_last_poster, 'topic_last_poster_name' => $topic_last_poster_name, 'topic_start_time' => $topic_start_time, 'topic_time' => $topic_time, 'topic_open' => $topic_open, 'forum_id' => (int)$forum_id ) ) ) 138 return false; 139 140 /* Now insert the first post. */ 141 if ( !bp_forums_insert_post( array( 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $topic_time, 'poster_id' => $topic_poster ) ) ) 142 return false; 143 144 return $topic_id; 145 } 146 147 function bp_forums_update_topic( $args = '' ) { 148 global $bp; 149 150 do_action( 'bbpress_init' ); 151 152 $defaults = array( 153 'topic_id' => false, 154 'topic_title' => '', 155 'topic_text' => '' 156 ); 157 158 $r = wp_parse_args( $args, $defaults ); 159 extract( $r, EXTR_SKIP ); 160 161 if ( !$topic_id = bb_insert_topic( array( 'topic_id' => $topic_id, 'topic_title' => stripslashes( $topic_title ) ) ) ) 162 return false; 163 164 if ( !$post = bb_get_first_post( $topic_id ) ) 165 return false; 166 167 /* Update the first post */ 168 if ( !$post = bb_insert_post( array( 'post_id' => $post->post_id, 'topic_id' => $topic_id, 'post_text' => $topic_text, 'post_time' => $post->post_time, 'poster_id' => $post->poster_id, 'poster_ip' => $post->poster_ip, 'post_status' => $post->post_status, 'post_position' => $post->post_position ) ) ) 169 return false; 170 171 return bp_forums_get_topic_details( $topic_id ); 172 } 173 174 function bp_forums_sticky_topic( $args = '' ) { 175 global $bp; 176 177 do_action( 'bbpress_init' ); 178 179 $defaults = array( 180 'topic_id' => false, 181 'mode' => 'stick' // stick/unstick 182 ); 183 184 $r = wp_parse_args( $args, $defaults ); 185 extract( $r, EXTR_SKIP ); 186 187 if ( 'stick' == $mode ) 188 return bb_stick_topic( $topic_id ); 189 else if ( 'unstick' == $mode ) 190 return bb_unstick_topic( $topic_id ); 191 192 return false; 193 } 194 195 function bp_forums_openclose_topic( $args = '' ) { 196 global $bp; 197 198 do_action( 'bbpress_init' ); 199 200 $defaults = array( 201 'topic_id' => false, 202 'mode' => 'close' // stick/unstick 203 ); 204 205 $r = wp_parse_args( $args, $defaults ); 206 extract( $r, EXTR_SKIP ); 207 208 if ( 'close' == $mode ) 209 return bb_close_topic( $topic_id ); 210 else if ( 'open' == $mode ) 211 return bb_open_topic( $topic_id ); 212 213 return false; 214 } 215 216 function bp_forums_delete_topic( $args = '' ) { 217 global $bp; 218 219 do_action( 'bbpress_init' ); 220 221 $defaults = array( 222 'topic_id' => false 223 ); 224 225 $r = wp_parse_args( $args, $defaults ); 226 extract( $r, EXTR_SKIP ); 227 228 return bb_delete_topic( $topic_id, 1 ); 229 } 230 231 function bp_forums_insert_post( $args = '' ) { 232 global $bp; 233 234 do_action( 'bbpress_init' ); 235 236 $defaults = array( 237 'post_id' => false, 238 'topic_id' => false, 239 'post_text' => '', 240 'post_time' => bb_current_time( 'mysql' ), 241 'poster_id' => $bp->loggedin_user->id, // accepts ids or names 242 'poster_ip' => $_SERVER['REMOTE_ADDR'], 243 'post_status' => 0, // use bb_delete_post() instead 244 'post_position' => false 245 ); 246 247 $r = wp_parse_args( $args, $defaults ); 248 extract( $r, EXTR_SKIP ); 249 250 if ( !$post = bp_forums_get_post( $post_id ) ) 251 $post_id = false; 252 253 if ( !isset( $topic_id ) ) 254 $topic_id = $post->topic_id; 255 256 if ( empty( $post_text ) ) 257 $post_text = $post->post_text; 258 259 if ( !isset( $post_time ) ) 260 $post_time = $post->post_time; 261 262 if ( !isset( $post_position ) ) 263 $post_position = $post->post_position; 264 265 return bb_insert_post( array( 'post_id' => $post_id, 'topic_id' => $topic_id, 'post_text' => stripslashes( $post_text ), 'post_time' => $post_time, 'poster_id' => $poster_id, 'poster_ip' => $poster_ip, 'post_status' => $post_status, 'post_position' => $post_position ) ); 266 } 267 268 // List actions to clear super cached pages on, if super cache is installed 269 add_action( 'bp_forums_new_forum', 'bp_core_clear_cache' ); 270 add_action( 'bp_forums_new_topic', 'bp_core_clear_cache' ); 271 add_action( 'bp_forums_new_post', 'bp_core_clear_cache' ); 272 273 function bp_forums_filter_caps( $allcaps ) { 274 global $bp, $wp_roles, $bb_table_prefix; 275 276 $bb_cap = get_usermeta( $bp->loggedin_user->id, $bb_table_prefix . 'capabilities' ); 277 278 if ( empty( $bb_cap ) ) 279 return $allcaps; 280 281 $bb_cap = array_keys($bb_cap); 282 $bb_cap = $wp_roles->get_role( $bb_cap[0] ); 283 $bb_cap = $bb_cap->capabilities; 284 285 return array_merge( (array) $allcaps, (array) $bb_cap ); 286 } 287 add_filter( 'user_has_cap', 'bp_forums_filter_caps' ); 288 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Aug 22 14:49:03 2009 | Cross-referenced by PHPXref 0.7 Thanks to |