[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-nouveau/includes/blogs/ -> functions.php (source)

   1  <?php
   2  /**
   3   * Blogs functions
   4   *
   5   * @since 3.0.0
   6   * @version 3.1.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * @since 3.0.0
  14   */
  15  function bp_nouveau_get_blogs_directory_nav_items() {
  16      $nav_items = array();
  17  
  18      $nav_items['all'] = array(
  19          'component' => 'blogs',
  20          'slug'      => 'all', // slug is used because BP_Core_Nav requires it, but it's the scope
  21          'li_class'  => array( 'selected' ),
  22          'link'      => bp_get_root_domain() . '/' . bp_get_blogs_root_slug(),
  23          'text'      => __( 'All Sites', 'buddypress' ),
  24          'count'     => bp_get_total_blog_count(),
  25          'position'  => 5,
  26      );
  27  
  28      if ( is_user_logged_in() ) {
  29          $my_blogs_count = bp_get_total_blog_count_for_user( bp_loggedin_user_id() );
  30  
  31          // If the user has blogs create a nav item
  32          if ( $my_blogs_count ) {
  33              $nav_items['personal'] = array(
  34                  'component' => 'blogs',
  35                  'slug'      => 'personal', // slug is used because BP_Core_Nav requires it, but it's the scope
  36                  'li_class'  => array(),
  37                  'link'      => bp_loggedin_user_domain() . bp_nouveau_get_component_slug( 'blogs' ),
  38                  'text'      => __( 'My Sites', 'buddypress' ),
  39                  'count'     => $my_blogs_count,
  40                  'position'  => 15,
  41              );
  42          }
  43  
  44          // If the user can create blogs, add the create nav
  45          if ( bp_blog_signup_enabled() ) {
  46              $nav_items['create'] = array(
  47                  'component' => 'blogs',
  48                  'slug'      => 'create', // slug is used because BP_Core_Nav requires it, but it's the scope
  49                  'li_class'  => array( 'no-ajax', 'site-create', 'create-button' ),
  50                  'link'      => trailingslashit( bp_get_blogs_directory_permalink() . 'create' ),
  51                  'text'      => __( 'Create a Site', 'buddypress' ),
  52                  'count'     => false,
  53                  'position'  => 999,
  54              );
  55          }
  56      }
  57  
  58      // Check for the deprecated hook :
  59      $extra_nav_items = bp_nouveau_parse_hooked_dir_nav( 'bp_blogs_directory_blog_types', 'blogs', 20 );
  60  
  61      if ( ! empty( $extra_nav_items ) ) {
  62          $nav_items = array_merge( $nav_items, $extra_nav_items );
  63      }
  64  
  65      /**
  66       * Use this filter to introduce your custom nav items for the blogs directory.
  67       *
  68       * @since 3.0.0
  69       *
  70       * @param  array $nav_items The list of the blogs directory nav items.
  71       */
  72      return apply_filters( 'bp_nouveau_get_blogs_directory_nav_items', $nav_items );
  73  }
  74  
  75  /**
  76   * Get Dropdown filters for the blogs component
  77   *
  78   * @since 3.0.0
  79   *
  80   * @param string $context 'directory' or 'user'
  81   *
  82   * @return array the filters
  83   */
  84  function bp_nouveau_get_blogs_filters( $context = '' ) {
  85      if ( empty( $context ) ) {
  86          return array();
  87      }
  88  
  89      $action = '';
  90      if ( 'user' === $context ) {
  91          $action = 'bp_member_blog_order_options';
  92      } elseif ( 'directory' === $context ) {
  93          $action = 'bp_blogs_directory_order_options';
  94      }
  95  
  96      /**
  97       * Recommended, filter here instead of adding an action to 'bp_member_blog_order_options'
  98       * or 'bp_blogs_directory_order_options'
  99       *
 100       * @since 3.0.0
 101       *
 102       * @param array  the blogs filters.
 103       * @param string the context.
 104       */
 105      $filters = apply_filters( 'bp_nouveau_get_blogs_filters', array(
 106          'active'       => __( 'Last Active', 'buddypress' ),
 107          'newest'       => __( 'Newest', 'buddypress' ),
 108          'alphabetical' => __( 'Alphabetical', 'buddypress' ),
 109      ), $context );
 110  
 111      if ( $action ) {
 112          return bp_nouveau_parse_hooked_options( $action, $filters );
 113      }
 114  
 115      return $filters;
 116  }
 117  
 118  /**
 119   * Catch the arguments for buttons
 120   *
 121   * @since 3.0.0
 122   *
 123   * @param array $buttons The arguments of the button that BuddyPress is about to create.
 124   *
 125   * @return array An empty array to stop the button creation process.
 126   */
 127  function bp_nouveau_blogs_catch_button_args( $button = array() ) {
 128      // Globalize the arguments so that we can use it  in bp_nouveau_get_blogs_buttons().
 129      bp_nouveau()->blogs->button_args = $button;
 130  
 131      // return an empty array to stop the button creation process
 132      return array();
 133  }
 134  
 135  /**
 136   * Add settings to the customizer for the blogs component.
 137   *
 138   * @since 3.0.0
 139   *
 140   * @param array $settings the settings to add.
 141   *
 142   * @return array the settings to add.
 143   */
 144  function bp_nouveau_blogs_customizer_settings( $settings = array() ) {
 145      return array_merge( $settings, array(
 146          'bp_nouveau_appearance[blogs_layout]' => array(
 147              'index'             => 'blogs_layout',
 148              'capability'        => 'bp_moderate',
 149              'sanitize_callback' => 'absint',
 150              'transport'         => 'refresh',
 151              'type'              => 'option',
 152          ),
 153      ) );
 154  }
 155  
 156  /**
 157   * Add controls for the settings of the customizer for the blogs component.
 158   *
 159   * @since 3.0.0
 160   *
 161   * @param array $controls the controls to add.
 162   *
 163   * @return array the controls to add.
 164   */
 165  function bp_nouveau_blogs_customizer_controls( $controls = array() ) {
 166      return array_merge( $controls, array(
 167          'blogs_layout' => array(
 168              'label'      => __( 'Sites loop:', 'buddypress' ),
 169              'section'    => 'bp_nouveau_loops_layout',
 170              'settings'   => 'bp_nouveau_appearance[blogs_layout]',
 171              'type'       => 'select',
 172              'choices'    => bp_nouveau_customizer_grid_choices(),
 173          ),
 174          'sites_dir_layout' => array(
 175              'label'      => __( 'Use column navigation for the Sites directory.', 'buddypress' ),
 176              'section'    => 'bp_nouveau_dir_layout',
 177              'settings'   => 'bp_nouveau_appearance[sites_dir_layout]',
 178              'type'       => 'checkbox',
 179          ),
 180          'sites_dir_tabs' => array(
 181              'label'      => __( 'Use tab styling for Sites directory navigation.', 'buddypress' ),
 182              'section'    => 'bp_nouveau_dir_layout',
 183              'settings'   => 'bp_nouveau_appearance[sites_dir_tabs]',
 184              'type'       => 'checkbox',
 185          ),
 186      ) );
 187  }
 188  
 189  /**
 190   * Inline script to toggle the signup blog form
 191   *
 192   * @since 3.0.0
 193   *
 194   * @return string Javascript output
 195   */
 196  function bp_nouveau_get_blog_signup_inline_script() {
 197      return '
 198          ( function( $ ) {
 199              if ( $( \'body\' ).hasClass( \'register\' ) ) {
 200                  var blog_checked = $( \'#signup_with_blog\' );
 201  
 202                  // hide "Blog Details" block if not checked by default
 203                  if ( ! blog_checked.prop( \'checked\' ) ) {
 204                      $( \'#blog-details\' ).toggle();
 205                  }
 206  
 207                  // toggle "Blog Details" block whenever checkbox is checked
 208                  blog_checked.change( function( event ) {
 209                      // Toggle HTML5 required attribute.
 210                      $.each( $( \'#blog-details\' ).find( \'[aria-required]\' ), function( i, input ) {
 211                          $( input ).prop( \'required\',  $( event.target ).prop( \'checked\' ) );
 212                      } );
 213  
 214                      $( \'#blog-details\' ).toggle();
 215                  } );
 216              }
 217          } )( jQuery );
 218      ';
 219  }
 220  
 221  /**
 222   * Filter bp_get_blog_class().
 223   * Adds a class if blog item has a latest post.
 224   *
 225   * @since 3.0.0
 226   */
 227  function bp_nouveau_blog_loop_item_has_lastest_post( $classes ) {
 228      if ( bp_get_blog_latest_post_title() ) {
 229          $classes[] = 'has-latest-post';
 230      }
 231  
 232      return $classes;
 233  }
 234  add_filter( 'bp_get_blog_class', 'bp_nouveau_blog_loop_item_has_lastest_post' );


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1