Guest User

Untitled

a guest
Jan 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. <?php
  2. class TK_WP_Detect {
  3. /**
  4. * PHP 4 constructor
  5. *
  6. * @package Custom Community
  7. * @since 1.8.3
  8. */
  9. function tk_detect_page_type() {
  10. $this->__construct();
  11. }
  12.  
  13. /**
  14. * PHP 5 constructor
  15. *
  16. * @package Custom Community
  17. * @since 1.8.3
  18. */
  19. function __construct() {
  20. if( $this->tk_is_buddypress() ){
  21. add_filter( 'tk_get_page_type', array( $this, 'tk_get_bp_page_type' ) );
  22. }
  23. }
  24.  
  25. /**
  26. * tk_get_wp_type
  27. *
  28. * @returns string 'wp' for a wordpress blog 'wpmu' for a wordpress network blog
  29. */
  30. function tk_get_wp_type(){
  31. global $blog_id;
  32.  
  33. if( defined( 'SITE_ID_CURRENT_SITE' ) ){
  34. if ( $blog_id != SITE_ID_CURRENT_SITE ){
  35. $wp_type = 'mu';
  36. }else{
  37. $wp_type = 'wp';
  38. }
  39. }else{
  40. $wp_type = 'wp';
  41. }
  42. return apply_filters( 'tk_wp_type', $wp_type );
  43. }
  44.  
  45. /**
  46. * tk_is_buddypress
  47. *
  48. * @returns boolean true if buddypress is installed, false if not
  49. */
  50. function tk_is_buddypress(){
  51. if ( defined( 'BP_VERSION' ) ){ return true; }else{ return false; }
  52. }
  53.  
  54. /**
  55. * tk_get_page_type
  56. *
  57. * @returns string returns the page type of the actual shown page
  58. */
  59. function tk_get_page_type(){
  60.  
  61. // If is wordpress and no buddypress
  62. if( $this->tk_get_wp_type() == "wp" ) {
  63. if( is_admin() ) $page_type = 'wp-admin';
  64. if( ( is_home() || is_front_page()) && !$this->tk_is_signup() ) $page_type = 'wp-home';
  65. if( is_single() ) $page_type = 'wp-post';
  66. if( is_page() && !is_front_page() ){ $page_type = 'wp-page'; }
  67. if( is_sticky() && !is_home()) $page_type = 'wp-sticky';
  68. if( is_category() ) $page_type = 'wp-category';
  69. if( is_tag() ) $page_type = 'wp-tag';
  70. if( is_tax() ) $page_type = 'wp-tax';
  71. if( is_author() ) $page_type = 'wp-author';
  72. if( is_archive() ) $page_type = 'wp-archive';
  73. if( is_search() ) $page_type = 'wp-search';
  74. if( $this->tk_is_signup() ) $page_type = 'wp-signup';
  75. if( is_404() ) $page_type = 'wp-404';
  76. }
  77.  
  78. // If is wordpress mu
  79. if( $this->tk_get_wp_type() == "mu" ) {
  80. if( is_admin() ) $page_type = 'mu-admin'; // Whats happening here on mu blogs?
  81. if( ( is_home() || is_front_page()) && !tk_is_signup() ) $page_type = 'mu-home';
  82. if( is_single() ) $page_type = 'mu-post';
  83. if( is_page() ) $page_type = 'mu-page';
  84. if( is_sticky() ) $page_type = 'mu-sticky';
  85. if( is_category() ) $page_type = 'mu-category';
  86. if( is_tag() ) $page_type = 'mu-tag';
  87. if( is_tax() ) $page_type = 'mu-tax';
  88. if( is_author() ) $page_type = 'mu-author';
  89. if( is_archive() ) $page_type = 'mu-archive';
  90. if( is_search() ) $page_type = 'mu-search';
  91. if( is_404() ) $page_type = 'mu-404';
  92. }
  93.  
  94. return apply_filters( 'tk_get_page_type', $page_type );
  95. }
  96.  
  97. function tk_is_signup(){
  98. if( $_REQUEST['action'] == 'register' ){
  99. return true;
  100. }else{
  101. return false;
  102. }
  103. }
  104.  
  105. function tk_get_bp_page_type( $page_type ){
  106. global $bp;
  107.  
  108. if( is_page() && $this->tk_is_buddypress() && $bp->current_component != '' ){
  109.  
  110. $slug = $bp->current_component;
  111. $action = $bp->current_action;
  112.  
  113. if($bp->displayed_user-id != 0 && $slug == 'activity' && $action == 'just-me'){
  114. $slug = profil;
  115. }
  116.  
  117. $component = $this->tk_get_bp_component_by_slug( $slug );
  118.  
  119.  
  120. if( $component != '' ){
  121. if( $action != '' ){
  122. if( bp_is_group_forum_topic() ){
  123. $page_type = 'bp-component-' . $component . '-' . $action . '-topic';
  124.  
  125. }elseif ( !bp_is_activity_front_page() && bp_is_activity_component() && $action != 'just-me' ){
  126. $page_type = 'bp-component-activity-activity';
  127. }else{
  128. $page_type = 'bp-component-' . $component . '-' . $action;
  129. }
  130. }else{
  131. $page_type = 'bp-component-' . $component;
  132. }
  133. }
  134. }
  135. return apply_filters( 'tk_get_bp_page_type', $page_type );
  136. }
  137.  
  138. function tk_get_bp_component_by_slug( $slug ){
  139.  
  140. $component_slugs = array();
  141.  
  142. if ( defined( 'BP_ACTIVITY_SLUG' ) ) $component_slugs[ BP_ACTIVITY_SLUG ] = "activity";
  143. if ( defined( 'BP_BLOGS_SLUG' ) ) $component_slugs[ BP_BLOGS_SLUG ] = "blogs";
  144. if ( defined( 'BP_MEMBERS_SLUG' ) ) $component_slugs[ BP_MEMBERS_SLUG ] = "members";
  145. if ( defined( 'BP_FRIENDS_SLUG' ) ) $component_slugs[ BP_FRIENDS_SLUG ] = "friends";
  146. if ( defined( 'BP_GROUPS_SLUG' ) ) $component_slugs[ BP_GROUPS_SLUG ] = "groups";
  147. if ( defined( 'BP_FORUMS_SLUG' ) ) $component_slugs[ BP_FORUMS_SLUG ] = "forums";
  148. if ( defined( 'BP_MESSAGES_SLUG' ) ) $component_slugs[ BP_MESSAGES_SLUG ] = "messages";
  149. if ( defined( 'BP_WIRE_SLUG' ) ) $component_slugs[ BP_WIRE_SLUG ] = "wire";
  150. if ( defined( 'BP_XPROFILE_SLUG' ) ) $component_slugs[ BP_XPROFILE_SLUG ] = "profile";
  151.  
  152. if ( defined( 'BP_REGISTER_SLUG' ) ) $component_slugs[ BP_REGISTER_SLUG ] = "register";
  153. if ( defined( 'BP_ACTIVATION_SLUG' ) ) $component_slugs[ BP_ACTIVATION_SLUG ] = "activate";
  154. if ( defined( 'BP_SEARCH_SLUG' ) ) $component_slugs[ BP_SEARCH_SLUG ] = "search";
  155.  
  156. if( $component_slugs[ $slug ] != '' ){
  157. $component = $component_slugs[ $slug ];
  158. }else{
  159. $component = $slug;
  160. }
  161. return $component;
  162. }
  163.  
  164. function tk_bp_is_active_component( $slug ){
  165. global $bp;
  166.  
  167. $component_name = tk_get_bp_component_by_slug( $slug );
  168.  
  169. $components = array_keys( $bp->active_components );
  170.  
  171. foreach( $components AS $key => $component ){
  172. $components_arr[ $key ] = tk_get_bp_component_by_slug( $component );
  173. }
  174.  
  175. if( is_array( $components ) ){
  176. if( in_array( $component_name, $components_arr ) ){
  177. return true;
  178. }else{
  179. return false;
  180. }
  181. }else{
  182. return false;
  183. }
  184. }
  185.  
  186. }
  187. ?>
Add Comment
Please, Sign In to add comment