Changeset 2789 for branches/plugin/bbp-includes/bbp-functions.php
- Timestamp:
- 01/09/2011 10:06:53 PM (15 years ago)
- File:
-
- 1 edited
-
branches/plugin/bbp-includes/bbp-functions.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-includes/bbp-functions.php
r2788 r2789 275 275 276 276 return $reason; 277 } 278 279 /** Views *********************************************************************/ 280 281 /** 282 * Get the registered views 283 * 284 * Does nothing much other than return the {@link $bbp->views} variable 285 * 286 * @since bbPress (r2789) 287 * 288 * @return array Views 289 */ 290 function bbp_get_views() { 291 global $bbp; 292 293 return $bbp->views; 294 } 295 296 /** 297 * Register a bbPress view 298 * 299 * @todo Implement feeds - See {@link http://trac.bbpress.org/ticket/1422} 300 * 301 * @since bbPress (r2789) 302 * 303 * @param string $view View name 304 * @param string $title View title 305 * @param mixed $query_args {@link bbp_has_topics()} arguments. 306 * @param bool $feed Have a feed for the view? Defaults to true. NOT IMPLEMENTED 307 * @uses sanitize_title() To sanitize the view name 308 * @uses esc_html() To sanitize the view title 309 * @return array The just registered (but processed) view 310 */ 311 function bbp_register_view( $view, $title, $query_args = '', $feed = true ) { 312 global $bbp; 313 314 $view = sanitize_title( $view ); 315 $title = esc_html( $title ); 316 317 if ( empty( $view ) || empty( $title ) ) 318 return false; 319 320 $query_args = wp_parse_args( $query_args ); 321 322 // Set ignore_sticky_topics to true if it wasn't supplied 323 if ( !isset( $query_args['ignore_sticky_topics'] ) ) 324 $query_args['ignore_sticky_topics'] = true; 325 326 $bbp->views[$view]['title'] = $title; 327 $bbp->views[$view]['query'] = $query_args; 328 $bbp->views[$view]['feed'] = $feed; 329 330 return $bbp->views[$view]; 331 } 332 333 /** 334 * Deregister a bbPress view 335 * 336 * @since bbPress (r2789) 337 * 338 * @param string $view View name 339 * @uses sanitize_title() To sanitize the view name 340 * @return bool False if the view doesn't exist, true on success 341 */ 342 function bbp_deregister_view( $view ) { 343 global $bbp; 344 345 $view = sanitize_title( $view ); 346 347 if ( !isset( $bbp->views[$view] ) ) 348 return false; 349 350 unset( $bbp->views[$view] ); 351 352 return true; 353 } 354 355 /** 356 * Run the view's query 357 * 358 * @since bbPress (r2789) 359 * 360 * @param string $view Optional. View id 361 * @param mixed $new_args New arguments. See {@link bbp_has_topics()} 362 * @uses bbp_get_view_id() To get the view id 363 * @uses bbp_get_view_query_args() To get the view query args 364 * @uses sanitize_title() To sanitize the view name 365 * @uses bbp_has_topics() To make the topics query 366 * @return bool False if the view doesn't exist, otherwise if topics are there 367 */ 368 function bbp_view_query( $view = '', $new_args = '' ) { 369 global $bbp; 370 371 if ( !$view = bbp_get_view_id( $view ) ) 372 return false; 373 374 $query_args = bbp_get_view_query_args( $view ); 375 376 if ( !empty( $new_args ) ) { 377 $new_args = wp_parse_args( $new_args ); 378 $query_args = array_merge( $query_args, $new_args ); 379 } 380 381 return bbp_has_topics( $query_args ); 382 } 383 384 /** 385 * Run the view's query's arguments 386 * 387 * @since bbPress (r2789) 388 * 389 * @param string $view View name 390 * @uses bbp_get_view_id() To get the view id 391 * @uses sanitize_title() To sanitize the view name 392 * @return array Query arguments 393 */ 394 function bbp_get_view_query_args( $view ) { 395 global $bbp; 396 397 if ( !$views = bbp_get_view_id( $view ) ) 398 return false; 399 400 return $bbp->views[$view]['query']; 277 401 } 278 402 … … 1858 1982 * Load bbPress custom templates 1859 1983 * 1860 * Loads custom templates for bbPress user profile, user edit, topic edit and1861 * reply edit pages.1984 * Loads custom templates for bbPress view page, user profile, user edit, topic 1985 * edit and reply edit pages. 1862 1986 * 1863 1987 * @since bbPress (r2753) … … 1883 2007 $template = array( 'user-edit.php', 'user.php', 'author.php', 'index.php' ); 1884 2008 2009 // View page 2010 } elseif ( bbp_is_view() ) { 2011 $template = array( 'view-' . bbp_get_view_id(), 'view.php', 'index.php' ); 2012 1885 2013 // Editing a topic 1886 2014 } elseif ( bbp_is_topic_edit() ) { … … 1903 2031 1904 2032 /** 1905 * Add checks for user page, user edit, topic edit and reply edit pages. 2033 * Add checks for view page, user page, user edit, topic edit and reply edit 2034 * pages. 1906 2035 * 1907 2036 * If it's a user page, WP_Query::bbp_is_user_profile_page is set to true. … … 1914 2043 * If it's a topic edit, WP_Query::bbp_is_topic_edit is set to true and 1915 2044 * similarly, if it's a reply edit, WP_Query::bbp_is_reply_edit is set to true. 2045 * 2046 * If it's a view page, WP_Query::bbp_is_view is set to true 1916 2047 * 1917 2048 * @since bbPress (r2688) … … 1929 2060 1930 2061 $bbp_user = get_query_var( 'bbp_user' ); 2062 $bbp_view = get_query_var( 'bbp_view' ); 1931 2063 $is_edit = get_query_var( 'edit' ); 1932 2064 2065 // Profile page 1933 2066 if ( !empty( $bbp_user ) ) { 1934 2067 … … 1972 2105 // Set the displayed user global to this user 1973 2106 $bbp->displayed_user = $user; 2107 2108 // View Page 2109 } elseif ( !empty( $bbp_view ) ) { 2110 2111 // Check if the view exists by checking if there are query args are set or not 2112 $view_args = bbp_get_view_query_args( $bbp_view ); 2113 2114 // Stop if view args is false - means the view isn't registered 2115 if ( false === $view_args ) { 2116 $wp_query->set_404(); 2117 return; 2118 } 2119 2120 $wp_query->bbp_is_view = true; 2121 2122 // Topic/Reply Edit Page 1974 2123 } elseif ( !empty( $is_edit ) ) { 1975 2124 … … 2046 2195 $title = bbp_get_reply_title(); 2047 2196 2197 // Topic tag page 2048 2198 } elseif ( is_tax( $bbp->topic_tag_id ) ) { 2049 2199 2050 2200 $term = get_queried_object(); 2051 2201 $title = sprintf( __( 'Topic Tag: %s', 'bbpress' ), $term->name ); 2202 2203 // Views 2204 } elseif ( bbp_is_view() ) { 2205 2206 $title = sprintf( __( 'View: %s', 'bbpress' ), bbp_get_view_title() ); 2052 2207 2053 2208 }
Note: See TracChangeset
for help on using the changeset viewer.