[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Blogs Template tags
   4   *
   5   * @since 3.0.0
   6   * @version 3.0.0
   7   */
   8  
   9  // Exit if accessed directly.
  10  defined( 'ABSPATH' ) || exit;
  11  
  12  /**
  13   * Template tag to wrap all Legacy actions that was used
  14   * before the blogs directory content
  15   *
  16   * @since 3.0.0
  17   */
  18  function bp_nouveau_before_blogs_directory_content() {
  19      /**
  20       * Fires at the begining of the templates BP injected content.
  21       *
  22       * @since 2.3.0
  23       */
  24      do_action( 'bp_before_directory_blogs_page' );
  25  
  26      /**
  27       * Fires before the display of the blogs.
  28       *
  29       * @since 1.5.0
  30       */
  31      do_action( 'bp_before_directory_blogs' );
  32  
  33      /**
  34       * Fires before the display of the blogs listing content.
  35       *
  36       * @since 3.0.0
  37       */
  38      do_action( 'bp_before_directory_blogs_content' );
  39  
  40      /**
  41       * Fires before the display of the blogs list tabs.
  42       *
  43       * @since 2.3.0
  44       */
  45      do_action( 'bp_before_directory_blogs_tabs' );
  46  }
  47  
  48  /**
  49   * Template tag to wrap all Legacy actions that was used after the blogs directory content
  50   *
  51   * @since 3.0.0
  52   */
  53  function bp_nouveau_after_blogs_directory_content() {
  54      /**
  55       * Fires inside and displays the blogs content.
  56       *
  57       * @since 3.0.0
  58       */
  59      do_action( 'bp_directory_blogs_content' );
  60  
  61      /**
  62       * Fires after the display of the blogs listing content.
  63       *
  64       * @since 3.0.0
  65       */
  66      do_action( 'bp_after_directory_blogs_content' );
  67  
  68      /**
  69       * Fires at the bottom of the blogs directory template file.
  70       *
  71       * @since 1.5.0
  72       */
  73      do_action( 'bp_after_directory_blogs' );
  74  
  75      /**
  76       * Fires at the bottom of the blogs directory template file.
  77       *
  78       * @since 2.3.0
  79       */
  80      do_action( 'bp_after_directory_blogs_page' );
  81  }
  82  
  83  /**
  84   * Fire specific hooks into the blogs create template
  85   *
  86   * @since 3.0.0
  87   *
  88   * @param string $when   Optional. Either 'before' or 'after'.
  89   * @param string $suffix Optional. Use it to add terms at the end of the hook name.
  90   */
  91  function bp_nouveau_blogs_create_hook( $when = '', $suffix = '' ) {
  92      $hook = array( 'bp' );
  93  
  94      if ( $when ) {
  95          $hook[] = $when;
  96      }
  97  
  98      // It's a create a blog hook
  99      $hook[] = 'create_blog';
 100  
 101      if ( $suffix ) {
 102          $hook[] = $suffix;
 103      }
 104  
 105      bp_nouveau_hook( $hook );
 106  }
 107  
 108  /**
 109   * Fire an isolated hook inside the blogs loop
 110   *
 111   * @since 3.0.0
 112   */
 113  function bp_nouveau_blogs_loop_item() {
 114      /**
 115       * Fires after the listing of a blog item in the blogs loop.
 116       *
 117       * @since 1.2.0
 118       */
 119      do_action( 'bp_directory_blogs_item' );
 120  }
 121  
 122  /**
 123   * Output the action buttons inside the blogs loop.
 124   *
 125   * @since 3.0.0
 126   *
 127   * @param array $args See bp_nouveau_wrapper() for the description of parameters.
 128   */
 129  function bp_nouveau_blogs_loop_buttons( $args = array() ) {
 130      if ( empty( $GLOBALS['blogs_template'] ) ) {
 131          return;
 132      }
 133  
 134      $args['type'] = 'loop';
 135  
 136      $output = join( ' ', bp_nouveau_get_blogs_buttons( $args ) );
 137  
 138      ob_start();
 139      /**
 140       * Fires inside the blogs action listing area.
 141       *
 142       * @since 3.0.0
 143       */
 144      do_action( 'bp_directory_blogs_actions' );
 145      $output .= ob_get_clean();
 146  
 147      if ( ! $output ) {
 148          return;
 149      }
 150  
 151      bp_nouveau_wrapper( array_merge( $args, array( 'output' => $output ) ) );
 152  }
 153  
 154      /**
 155       * Get the action buttons for the current blog in the loop.
 156       *
 157       * @since 3.0.0
 158       *
 159       * @param string $type Type of Group of buttons to get.
 160       *
 161       * @return array
 162       */
 163  	function bp_nouveau_get_blogs_buttons( $args ) {
 164          $type = ( ! empty( $args['type'] ) ) ? $args['type'] : 'loop';
 165  
 166          // @todo Not really sure why BP Legacy needed to do this...
 167          if ( 'loop' !== $type && is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
 168              return array();
 169          }
 170  
 171          $buttons = array();
 172  
 173          if ( isset( $GLOBALS['blogs_template']->blog ) ) {
 174              $blog = $GLOBALS['blogs_template']->blog;
 175          }
 176  
 177          if ( empty( $blog->blog_id ) ) {
 178              return $buttons;
 179          }
 180  
 181          /*
 182           * If the 'container' is set to 'ul', set a var $parent_element to li,
 183           * otherwise simply pass any value found in args or set var false.
 184           */
 185          if ( ! empty( $args['container'] ) && 'ul' === $args['container'] ) {
 186              $parent_element = 'li';
 187          } elseif ( ! empty( $args['parent_element'] ) ) {
 188              $parent_element = $args['parent_element'];
 189          } else {
 190              $parent_element = false;
 191          }
 192  
 193          /*
 194           * If we have a arg value for $button_element passed through
 195           * use it to default all the $buttons['button_element'] values
 196           * otherwise default to 'a' (anchor)
 197           * Or override & hardcode the 'element' string on $buttons array.
 198           *
 199           * Icons sets a class for icon display if not using the button element
 200           */
 201          $icons = '';
 202          if ( ! empty( $args['button_element'] ) ) {
 203              $button_element = $args['button_element'] ;
 204          } else {
 205              $button_element = 'a';
 206              $icons = ' icons';
 207          }
 208  
 209          /*
 210           * This filter workaround is waiting for a core adaptation
 211           * so that we can directly get the groups button arguments
 212           * instead of the button.
 213           *
 214           * See https://buddypress.trac.wordpress.org/ticket/7126
 215           */
 216          add_filter( 'bp_get_blogs_visit_blog_button', 'bp_nouveau_blogs_catch_button_args', 100, 1 );
 217  
 218          bp_get_blogs_visit_blog_button();
 219  
 220          remove_filter( 'bp_get_blogs_visit_blog_button', 'bp_nouveau_blogs_catch_button_args', 100, 1 );
 221  
 222          if ( isset( bp_nouveau()->blogs->button_args ) && bp_nouveau()->blogs->button_args ) {
 223              $button_args = bp_nouveau()->blogs->button_args ;
 224  
 225              // If we pass through parent classes add them to $button array
 226              $parent_class = '';
 227              if ( ! empty( $args['parent_attr']['class'] ) ) {
 228                  $parent_class = $args['parent_attr']['class'];
 229              }
 230  
 231              $buttons['visit_blog'] = array(
 232                  'id'                => 'visit_blog',
 233                  'position'          => 5,
 234                  'component'         => $button_args['component'],
 235                  'must_be_logged_in' => $button_args['must_be_logged_in'],
 236                  'block_self'        => $button_args['block_self'],
 237                  'parent_element'    => $parent_element,
 238                  'button_element'    => $button_element,
 239                  'link_text'         => $button_args['link_text'],
 240                  'parent_attr'       => array(
 241                      'id'              => $button_args['wrapper_id'],
 242                      'class'           => $parent_class,
 243                  ),
 244                  'button_attr'       => array(
 245                      'href'             => $button_args['link_href'],
 246                      'id'               => $button_args['link_id'],
 247                      'class'            => $button_args['link_class'] . ' button',
 248                      'rel'              => $button_args['link_rel'],
 249                      'title'            => '',
 250                  ),
 251              );
 252  
 253              unset( bp_nouveau()->blogs->button_args );
 254          }
 255  
 256          /**
 257           * Filter to add your buttons, use the position argument to choose where to insert it.
 258           *
 259           * @since 3.0.0
 260           *
 261           * @param array  $buttons The list of buttons.
 262           * @param object $blog    The current blog object.
 263           * @param string $type    Whether we're displaying a blogs loop or a the blogs single item (in the future!).
 264           */
 265          $buttons_group = apply_filters( 'bp_nouveau_get_blogs_buttons', $buttons, $blog, $type );
 266  
 267          if ( ! $buttons_group ) {
 268              return $buttons;
 269          }
 270  
 271          // It's the first entry of the loop, so build the Group and sort it
 272          if ( ! isset( bp_nouveau()->blogs->group_buttons ) || ! is_a( bp_nouveau()->blogs->group_buttons, 'BP_Buttons_Group' ) ) {
 273              $sort = true;
 274              bp_nouveau()->blogs->group_buttons = new BP_Buttons_Group( $buttons_group );
 275  
 276          // It's not the first entry, the order is set, we simply need to update the Buttons Group
 277          } else {
 278              $sort = false;
 279              bp_nouveau()->blogs->group_buttons->update( $buttons_group );
 280          }
 281  
 282          $return = bp_nouveau()->blogs->group_buttons->get( $sort );
 283  
 284          if ( ! $return ) {
 285              return array();
 286          }
 287  
 288          /**
 289           * Leave a chance to adjust the $return
 290           *
 291           * @since 3.0.0
 292           *
 293           * @param array  $return  The list of buttons ordered.
 294           * @param object $blog    The current blog object.
 295           * @param string $type    Whether we're displaying a blogs loop or a the blogs single item (in the future!).
 296           */
 297          do_action_ref_array( 'bp_nouveau_return_blogs_buttons', array( &$return, $blog, $type ) );
 298  
 299          return $return;
 300      }
 301  
 302  /**
 303   * Check if the Sites has a latest post
 304   *
 305   * @since 3.0.0
 306   *
 307   * @return bool True if the sites has a latest post. False otherwise.
 308   */
 309  function bp_nouveau_blog_has_latest_post() {
 310      return (bool) bp_get_blog_latest_post_title();
 311  }


Generated: Mon Jul 22 01:01:43 2019 Cross-referenced by PHPXref 0.7.1