[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-notifications/ -> bp-notifications-template.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Notifications Template Functions.
   4   *
   5   * @package BuddyPress
   6   * @subpackage TonificationsTemplate
   7   * @since 1.9.0
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Output the notifications component slug.
  15   *
  16   * @since 1.9.0
  17   */
  18  function bp_notifications_slug() {
  19      echo bp_get_notifications_slug();
  20  }
  21      /**
  22       * Return the notifications component slug.
  23       *
  24       * @since 1.9.0
  25       *
  26       * @return string Slug of the Notifications component.
  27       */
  28  	function bp_get_notifications_slug() {
  29  
  30          /**
  31           * Filters the notifications component slug.
  32           *
  33           * @since 1.9.0
  34           *
  35           * @param string $slug Notifications component slug.
  36           */
  37          return apply_filters( 'bp_get_notifications_slug', buddypress()->notifications->slug );
  38      }
  39  
  40  /**
  41   * Output the notifications permalink for a user.
  42   *
  43   * @since 1.9.0
  44   * @since 2.6.0 Added $user_id as a parameter.
  45   *
  46   * @param int $user_id The user ID.
  47   */
  48  function bp_notifications_permalink( $user_id = 0 ) {
  49      echo bp_get_notifications_permalink( $user_id );
  50  }
  51      /**
  52       * Return the notifications permalink.
  53       *
  54       * @since 1.9.0
  55       * @since 2.6.0 Added $user_id as a parameter.
  56       *
  57       * @param int $user_id The user ID.
  58       * @return string Notifications permalink.
  59       */
  60  	function bp_get_notifications_permalink( $user_id = 0 ) {
  61          if ( 0 === $user_id ) {
  62              $user_id = bp_loggedin_user_id();
  63              $domain  = bp_loggedin_user_domain();
  64          } else {
  65              $domain = bp_core_get_user_domain( (int) $user_id );
  66          }
  67  
  68          $retval = trailingslashit( $domain . bp_get_notifications_slug() );
  69  
  70          /**
  71           * Filters the notifications permalink.
  72           *
  73           * @since 1.9.0
  74           * @since 2.6.0 Added $user_id as a parameter.
  75           *
  76           * @param string $retval  Permalink for the notifications.
  77           * @param int    $user_id The user ID.
  78           */
  79          return apply_filters( 'bp_get_notifications_permalink', $retval, $user_id );
  80      }
  81  
  82  /**
  83   * Output the unread notifications permalink for a user.
  84   *
  85   * @since 1.9.0
  86   * @since 2.6.0 Added $user_id as a parameter.
  87   *
  88   * @param int $user_id The user ID.
  89   */
  90  function bp_notifications_unread_permalink( $user_id = 0 ) {
  91      echo bp_get_notifications_unread_permalink( $user_id );
  92  }
  93      /**
  94       * Return the unread notifications permalink.
  95       *
  96       * @since 2.6.0 Added $user_id as a parameter.
  97       *
  98       * @param int $user_id The user ID.
  99       * @return string Unread notifications permalink.
 100       */
 101  	function bp_get_notifications_unread_permalink( $user_id = 0 ) {
 102          if ( 0 === $user_id ) {
 103              $user_id = bp_loggedin_user_id();
 104              $domain  = bp_loggedin_user_domain();
 105          } else {
 106              $domain = bp_core_get_user_domain( (int) $user_id );
 107          }
 108  
 109          $retval = trailingslashit( $domain . bp_get_notifications_slug() . '/unread' );
 110  
 111          /**
 112           * Filters the unread notifications permalink.
 113           *
 114           * @since 1.9.0
 115           * @since 2.6.0 Added $user_id as a parameter.
 116           *
 117           * @param string $retval  Permalink for the unread notifications.
 118           * @param int    $user_id The user ID.
 119           */
 120          return apply_filters( 'bp_get_notifications_unread_permalink', $retval, $user_id );
 121      }
 122  
 123  /**
 124   * Output the read notifications permalink for a user.
 125   *
 126   * @since 1.9.0
 127   * @since 2.6.0 Added $user_id as a parameter.
 128   *
 129   * @param int $user_id The user ID.
 130   */
 131  function bp_notifications_read_permalink( $user_id = 0 ) {
 132      echo bp_get_notifications_read_permalink( $user_id );
 133  }
 134      /**
 135       * Return the read notifications permalink.
 136       *
 137       * @since 1.9.0
 138       *
 139       * @return string Read notifications permalink.
 140       */
 141  	function bp_get_notifications_read_permalink( $user_id = 0 ) {
 142          if ( 0 === $user_id ) {
 143              $user_id = bp_loggedin_user_id();
 144              $domain  = bp_loggedin_user_domain();
 145          } else {
 146              $domain = bp_core_get_user_domain( (int) $user_id );
 147          }
 148  
 149          $retval = trailingslashit( $domain . bp_get_notifications_slug() . '/read' );
 150  
 151          /**
 152           * Filters the read notifications permalink.
 153           *
 154           * @since 1.9.0
 155           * @since 2.6.0 Added $user_id as a parameter.
 156           *
 157           * @param string $retval  Permalink for the read notifications.
 158           * @param int    $user_id The user ID.
 159           */
 160          return apply_filters( 'bp_get_notifications_read_permalink', $retval, $user_id );
 161      }
 162  
 163  /** The Loop ******************************************************************/
 164  
 165  /**
 166   * Initialize the notifications loop.
 167   *
 168   * Based on the $args passed, bp_has_notifications() populates
 169   * buddypress()->notifications->query_loop global, enabling the use of BP
 170   * templates and template functions to display a list of notifications.
 171   *
 172   * @since 1.9.0
 173   *
 174   * @param array|string $args {
 175   *     Arguments for limiting the contents of the notifications loop. Can be
 176   *     passed as an associative array, or as a URL query string.
 177   *
 178   *     See {@link BP_Notifications_Notification::get()} for detailed
 179   *     information on the arguments.  In addition, also supports:
 180   *
 181   *     @type int    $max      Optional. Max items to display. Default: false.
 182   *     @type string $page_arg URL argument to use for pagination.
 183   *                            Default: 'npage'.
 184   * }
 185   * @return bool
 186   */
 187  function bp_has_notifications( $args = '' ) {
 188  
 189      // Get the default is_new argument.
 190      if ( bp_is_current_action( 'unread' ) ) {
 191          $is_new = 1;
 192      } elseif ( bp_is_current_action( 'read' ) ) {
 193          $is_new = 0;
 194  
 195      // Not on a notifications page? default to fetch new notifications.
 196      } else {
 197          $is_new = 1;
 198      }
 199  
 200      // Get the user ID.
 201      if ( bp_displayed_user_id() ) {
 202          $user_id = bp_displayed_user_id();
 203      } else {
 204          $user_id = bp_loggedin_user_id();
 205      }
 206  
 207      // Set the component action (by default false to get all actions)
 208      $component_action = false;
 209  
 210      if ( isset( $_REQUEST['type'] ) ) {
 211          $component_action = sanitize_key( $_REQUEST['type'] );
 212      }
 213  
 214      // Set the search terms (by default an empty string to get all notifications)
 215      $search_terms = '';
 216  
 217      if ( isset( $_REQUEST['s'] ) ) {
 218          $search_terms = stripslashes( $_REQUEST['s'] );
 219      }
 220  
 221      // Parse the args.
 222      $r = bp_parse_args(
 223          $args,
 224          array(
 225              'id'                => false,
 226              'user_id'           => $user_id,
 227              'secondary_item_id' => false,
 228              'component_name'    => bp_notifications_get_registered_components(),
 229              'component_action'  => $component_action,
 230              'is_new'            => $is_new,
 231              'search_terms'      => $search_terms,
 232              'order_by'          => 'date_notified',
 233              'sort_order'        => 'DESC',
 234              'meta_query'        => false,
 235              'date_query'        => false,
 236              'page'              => 1,
 237              'per_page'          => 25,
 238  
 239              // These are additional arguments that are not available in
 240              // BP_Notifications_Notification::get().
 241              'max'               => false,
 242              'page_arg'          => 'npage',
 243          ),
 244          'has_notifications'
 245      );
 246  
 247      // Get the notifications.
 248      $query_loop = new BP_Notifications_Template( $r );
 249  
 250      // Setup the global query loop.
 251      buddypress()->notifications->query_loop = $query_loop;
 252  
 253      /**
 254       * Filters whether or not the user has notifications to display.
 255       *
 256       * @since 1.9.0
 257       * @since 2.6.0 Added the `$r` parameter.
 258       *
 259       * @param bool                      $value      Whether or not there are notifications to display.
 260       * @param BP_Notifications_Template $query_loop BP_Notifications_Template object instance.
 261       * @param array                     $r          Array of arguments passed into the BP_Notifications_Template class.
 262       */
 263      return apply_filters( 'bp_has_notifications', $query_loop->has_notifications(), $query_loop, $r );
 264  }
 265  
 266  /**
 267   * Get the notifications returned by the template loop.
 268   *
 269   * @since 1.9.0
 270   *
 271   * @return array List of notifications.
 272   */
 273  function bp_the_notifications() {
 274      return buddypress()->notifications->query_loop->notifications();
 275  }
 276  
 277  /**
 278   * Get the current notification object in the loop.
 279   *
 280   * @since 1.9.0
 281   *
 282   * @return object The current notification within the loop.
 283   */
 284  function bp_the_notification() {
 285      return buddypress()->notifications->query_loop->the_notification();
 286  }
 287  
 288  /** Loop Output ***************************************************************/
 289  
 290  /**
 291   * Output the ID of the notification currently being iterated on.
 292   *
 293   * @since 1.9.0
 294   */
 295  function bp_the_notification_id() {
 296      echo bp_get_the_notification_id();
 297  }
 298      /**
 299       * Return the ID of the notification currently being iterated on.
 300       *
 301       * @since 1.9.0
 302       *
 303       * @return int ID of the current notification.
 304       */
 305  	function bp_get_the_notification_id() {
 306  
 307          /**
 308           * Filters the ID of the notification currently being iterated on.
 309           *
 310           * @since 1.9.0
 311           *
 312           * @param int $id ID of the notification being iterated on.
 313           */
 314          return apply_filters( 'bp_get_the_notification_id', buddypress()->notifications->query_loop->notification->id );
 315      }
 316  
 317  /**
 318   * Output the associated item ID of the notification currently being iterated on.
 319   *
 320   * @since 1.9.0
 321   */
 322  function bp_the_notification_item_id() {
 323      echo bp_get_the_notification_item_id();
 324  }
 325      /**
 326       * Return the associated item ID of the notification currently being iterated on.
 327       *
 328       * @since 1.9.0
 329       *
 330       * @return int ID of the item associated with the current notification.
 331       */
 332  	function bp_get_the_notification_item_id() {
 333  
 334          /**
 335           * Filters the associated item ID of the notification currently being iterated on.
 336           *
 337           * @since 1.9.0
 338           *
 339           * @param int $item_id ID of the associated item.
 340           */
 341          return apply_filters( 'bp_get_the_notification_item_id', buddypress()->notifications->query_loop->notification->item_id );
 342      }
 343  
 344  /**
 345   * Output the secondary associated item ID of the notification currently being iterated on.
 346   *
 347   * @since 1.9.0
 348   */
 349  function bp_the_notification_secondary_item_id() {
 350      echo bp_get_the_notification_secondary_item_id();
 351  }
 352      /**
 353       * Return the secondary associated item ID of the notification currently being iterated on.
 354       *
 355       * @since 1.9.0
 356       *
 357       * @return int ID of the secondary item associated with the current notification.
 358       */
 359  	function bp_get_the_notification_secondary_item_id() {
 360  
 361          /**
 362           * Filters the secondary associated item ID of the notification currently being iterated on.
 363           *
 364           * @since 1.9.0
 365           *
 366           * @param int $secondary_item_id ID of the secondary associated item.
 367           */
 368          return apply_filters( 'bp_get_the_notification_secondary_item_id', buddypress()->notifications->query_loop->notification->secondary_item_id );
 369      }
 370  
 371  /**
 372   * Output the name of the component associated with the notification currently being iterated on.
 373   *
 374   * @since 1.9.0
 375   */
 376  function bp_the_notification_component_name() {
 377      echo bp_get_the_notification_component_name();
 378  }
 379      /**
 380       * Return the name of the component associated with the notification currently being iterated on.
 381       *
 382       * @since 1.9.0
 383       *
 384       * @return int Name of the component associated with the current notification.
 385       */
 386  	function bp_get_the_notification_component_name() {
 387  
 388          /**
 389           * Filters the name of the component associated with the notification currently being iterated on.
 390           *
 391           * @since 1.9.0
 392           *
 393           * @param int $component_name Name of the component associated with the current notification.
 394           */
 395          return apply_filters( 'bp_get_the_notification_component_name', buddypress()->notifications->query_loop->notification->component_name );
 396      }
 397  
 398  /**
 399   * Output the name of the action associated with the notification currently being iterated on.
 400   *
 401   * @since 1.9.0
 402   */
 403  function bp_the_notification_component_action() {
 404      echo bp_get_the_notification_component_action();
 405  }
 406      /**
 407       * Return the name of the action associated with the notification currently being iterated on.
 408       *
 409       * @since 1.9.0
 410       *
 411       * @return int Name of the action associated with the current notification.
 412       */
 413  	function bp_get_the_notification_component_action() {
 414  
 415          /**
 416           * Filters the name of the action associated with the notification currently being iterated on.
 417           *
 418           * @since 1.9.0
 419           *
 420           * @param int $component_action Name of the action associated with the current notification.
 421           */
 422          return apply_filters( 'bp_get_the_notification_component_action', buddypress()->notifications->query_loop->notification->component_action );
 423      }
 424  
 425  /**
 426   * Output the timestamp of the current notification.
 427   *
 428   * @since 1.9.0
 429   */
 430  function bp_the_notification_date_notified() {
 431      echo bp_get_the_notification_date_notified();
 432  }
 433      /**
 434       * Return the timestamp of the current notification.
 435       *
 436       * @since 1.9.0
 437       *
 438       * @return string Timestamp of the current notification.
 439       */
 440  	function bp_get_the_notification_date_notified() {
 441  
 442          /**
 443           * Filters the timestamp of the current notification.
 444           *
 445           * @since 1.9.0
 446           *
 447           * @param string $date_notified Timestamp of the current notification.
 448           */
 449          return apply_filters( 'bp_get_the_notification_date_notified', buddypress()->notifications->query_loop->notification->date_notified );
 450      }
 451  
 452  /**
 453   * Output the timestamp of the current notification.
 454   *
 455   * @since 1.9.0
 456   */
 457  function bp_the_notification_time_since() {
 458      echo bp_get_the_notification_time_since();
 459  }
 460      /**
 461       * Return the timestamp of the current notification.
 462       *
 463       * @since 1.9.0
 464       *
 465       * @return string Timestamp of the current notification.
 466       */
 467  	function bp_get_the_notification_time_since() {
 468  
 469          // Get the notified date.
 470          $date_notified = bp_get_the_notification_date_notified();
 471  
 472          // Notified date has legitimate data.
 473          if ( '0000-00-00 00:00:00' !== $date_notified ) {
 474              $retval = bp_core_time_since( $date_notified );
 475  
 476          // Notified date is empty, so return a fun string.
 477          } else {
 478              $retval = __( 'Date not found', 'buddypress' );
 479          }
 480  
 481          /**
 482           * Filters the time since value of the current notification.
 483           *
 484           * @since 1.9.0
 485           *
 486           * @param string $retval Time since value for current notification.
 487           */
 488          return apply_filters( 'bp_get_the_notification_time_since', $retval );
 489      }
 490  
 491  /**
 492   * Output full-text description for a specific notification.
 493   *
 494   * @since 1.9.0
 495   */
 496  function bp_the_notification_description() {
 497      echo bp_get_the_notification_description();
 498  }
 499      /**
 500       * Get full-text description for a specific notification.
 501       *
 502       * @since 1.9.0
 503       *
 504       * @return string
 505       */
 506  	function bp_get_the_notification_description() {
 507          $bp           = buddypress();
 508          $notification = $bp->notifications->query_loop->notification;
 509  
 510          // Callback function exists.
 511          if ( isset( $bp->{ $notification->component_name }->notification_callback ) && is_callable( $bp->{ $notification->component_name }->notification_callback ) ) {
 512              $description = call_user_func( $bp->{ $notification->component_name }->notification_callback, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->id );
 513  
 514          // @deprecated format_notification_function - 1.5
 515          } elseif ( isset( $bp->{ $notification->component_name }->format_notification_function ) && function_exists( $bp->{ $notification->component_name }->format_notification_function ) ) {
 516              $description = call_user_func( $bp->{ $notification->component_name }->format_notification_function, $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1 );
 517  
 518          // Allow non BuddyPress components to hook in.
 519          } else {
 520  
 521              /** This filter is documented in bp-notifications/bp-notifications-functions.php */
 522              $description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->component_action, $notification->component_name, $notification->id ) );
 523          }
 524  
 525          /**
 526           * Filters the full-text description for a specific notification.
 527           *
 528           * @since 1.9.0
 529           * @since 2.3.0 Added the `$notification` parameter.
 530           *
 531           * @param string                        $description  Full-text description for a specific notification.
 532           * @param BP_Notifications_Notification $notification Notification object.
 533           */
 534          return apply_filters( 'bp_get_the_notification_description', $description, $notification );
 535      }
 536  
 537  /**
 538   * Output the mark read link for the current notification.
 539   *
 540   * @since 1.9.0
 541   * @since 2.6.0 Added $user_id as a parameter.
 542   *
 543   * @param int $user_id The user ID.
 544   */
 545  function bp_the_notification_mark_read_link( $user_id = 0 ) {
 546      echo bp_get_the_notification_mark_read_link( $user_id );
 547  }
 548      /**
 549       * Return the mark read link for the current notification.
 550       *
 551       * @since 1.9.0
 552       * @since 2.6.0 Added $user_id as a parameter.
 553       *
 554       * @param int $user_id The user ID.
 555       * @return string
 556       */
 557  	function bp_get_the_notification_mark_read_link( $user_id = 0 ) {
 558          // Set default user ID to use.
 559          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 560  
 561          $retval = sprintf( '<a href="%1$s" class="mark-read primary">%2$s</a>', esc_url( bp_get_the_notification_mark_read_url( $user_id ) ), __( 'Read', 'buddypress' ) );
 562  
 563          /**
 564           * Filters the mark read link for the current notification.
 565           *
 566           * @since 1.9.0
 567           * @since 2.6.0 Added $user_id as a parameter.
 568           *
 569           * @param string $retval  HTML for the mark read link for the current notification.
 570           * @param int    $user_id The user ID.
 571           */
 572          return apply_filters( 'bp_get_the_notification_mark_read_link', $retval, $user_id );
 573      }
 574  
 575  /**
 576   * Output the URL used for marking a single notification as read.
 577   *
 578   * Since this function directly outputs a URL, it is escaped.
 579   *
 580   * @since 2.1.0
 581   * @since 2.6.0 Added $user_id as a parameter.
 582   *
 583   * @param int $user_id The user ID.
 584   */
 585  function bp_the_notification_mark_read_url( $user_id = 0 ) {
 586      echo esc_url( bp_get_the_notification_mark_read_url( $user_id ) );
 587  }
 588      /**
 589       * Return the URL used for marking a single notification as read.
 590       *
 591       * @since 2.1.0
 592       * @since 2.6.0 Added $user_id as a parameter.
 593       *
 594       * @param int $user_id The user ID.
 595       * @return string
 596       */
 597  	function bp_get_the_notification_mark_read_url( $user_id = 0 ) {
 598  
 599          // Get the notification ID.
 600          $id   = bp_get_the_notification_id();
 601  
 602          // Get the args to add to the URL.
 603          $args = array(
 604              'action'          => 'read',
 605              'notification_id' => $id,
 606          );
 607  
 608          // Set default user ID to use.
 609          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 610  
 611          // Add the args to the URL.
 612          $url = add_query_arg( $args, bp_get_notifications_unread_permalink( $user_id ) );
 613  
 614          // Add the nonce.
 615          $url = wp_nonce_url( $url, 'bp_notification_mark_read_' . $id );
 616  
 617          /**
 618           * Filters the URL used for marking a single notification as read.
 619           *
 620           * @since 2.1.0
 621           * @since 2.6.0 Added $user_id as a parameter.
 622           *
 623           * @param string $url     URL to use for marking the single notification as read.
 624           * @param int    $user_id The user ID.
 625           */
 626          return apply_filters( 'bp_get_the_notification_mark_read_url', $url, $user_id );
 627      }
 628  
 629  /**
 630   * Output the mark unread link for the current notification.
 631   *
 632   * @since 1.9.0
 633   * @since 2.6.0 Added $user_id as a parameter.
 634   *
 635   * @param int $user_id The user ID.
 636   */
 637  function bp_the_notification_mark_unread_link( $user_id = 0 ) {
 638      echo bp_get_the_notification_mark_unread_link( $user_id );
 639  }
 640      /**
 641       * Return the mark unread link for the current notification.
 642       *
 643       * @since 1.9.0
 644       * @since 2.6.0 Added $user_id as a parameter.
 645       *
 646       * @param int $user_id The user ID.
 647       * @return string
 648       */
 649  	function bp_get_the_notification_mark_unread_link( $user_id = 0 ) {
 650          // Set default user ID to use.
 651          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 652  
 653          $retval = sprintf( '<a href="%1$s" class="mark-unread primary bp-tooltip">%2$s</a>', esc_url( bp_get_the_notification_mark_unread_url( $user_id ) ), __( 'Unread', 'buddypress' ) );
 654  
 655          /**
 656           * Filters the link used for marking a single notification as unread.
 657           *
 658           * @since 1.9.0
 659           * @since 2.6.0 Added $user_id as a parameter.
 660           *
 661           * @param string $retval  HTML for the mark unread link for the current notification.
 662           * @param int    $user_id The user ID.
 663           */
 664          return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval, $user_id );
 665      }
 666  
 667  /**
 668   * Output the URL used for marking a single notification as unread.
 669   *
 670   * Since this function directly outputs a URL, it is escaped.
 671   *
 672   * @since 2.1.0
 673   * @since 2.6.0 Added $user_id as a parameter.
 674   *
 675   * @param int $user_id The user ID.
 676   */
 677  function bp_the_notification_mark_unread_url( $user_id = 0 ) {
 678      echo esc_url( bp_get_the_notification_mark_unread_url( $user_id ) );
 679  }
 680      /**
 681       * Return the URL used for marking a single notification as unread.
 682       *
 683       * @since 2.1.0
 684       * @since 2.6.0 Added $user_id as a parameter.
 685       *
 686       * @param int $user_id The user ID.
 687       * @return string
 688       */
 689  	function bp_get_the_notification_mark_unread_url( $user_id = 0 ) {
 690  
 691          // Get the notification ID.
 692          $id   = bp_get_the_notification_id();
 693  
 694          // Get the args to add to the URL.
 695          $args = array(
 696              'action'          => 'unread',
 697              'notification_id' => $id,
 698          );
 699  
 700          // Set default user ID to use.
 701          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 702  
 703          // Add the args to the URL.
 704          $url = add_query_arg( $args, bp_get_notifications_read_permalink( $user_id ) );
 705  
 706          // Add the nonce.
 707          $url = wp_nonce_url( $url, 'bp_notification_mark_unread_' . $id );
 708  
 709          /**
 710           * Filters the URL used for marking a single notification as unread.
 711           *
 712           * @since 2.1.0
 713           * @since 2.6.0 Added $user_id as a parameter.
 714           *
 715           * @param string $url     URL to use for marking the single notification as unread.
 716           * @param int    $user_id The user ID.
 717           */
 718          return apply_filters( 'bp_get_the_notification_mark_unread_url', $url, $user_id );
 719      }
 720  
 721  /**
 722   * Output the mark link for the current notification.
 723   *
 724   * @since 1.9.0
 725   * @since 2.6.0 Added $user_id as a parameter.
 726   *
 727   * @param int $user_id The user ID.
 728   */
 729  function bp_the_notification_mark_link( $user_id = 0 ) {
 730      echo bp_get_the_notification_mark_link( $user_id );
 731  }
 732      /**
 733       * Return the mark link for the current notification.
 734       *
 735       * @since 1.9.0
 736       * @since 2.6.0 Added $user_id as a parameter.
 737       *
 738       * @param int $user_id The user ID.
 739       * @return string
 740       */
 741  	function bp_get_the_notification_mark_link( $user_id = 0 ) {
 742          // Set default user ID to use.
 743          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 744  
 745          if ( bp_is_current_action( 'read' ) ) {
 746              $retval = bp_get_the_notification_mark_unread_link( $user_id );
 747          } else {
 748              $retval = bp_get_the_notification_mark_read_link( $user_id );
 749          }
 750  
 751          /**
 752           * Filters the mark link for the current notification.
 753           *
 754           * @since 1.9.0
 755           * @since 2.6.0 Added $user_id as a parameter.
 756           *
 757           * @param string $retval  The mark link for the current notification.
 758           * @param int    $user_id The user ID.
 759           */
 760          return apply_filters( 'bp_get_the_notification_mark_link', $retval, $user_id );
 761      }
 762  
 763  /**
 764   * Output the delete link for the current notification.
 765   *
 766   * @since 1.9.0
 767   * @since 2.6.0 Added $user_id as a parameter.
 768   *
 769   * @param int $user_id The user ID.
 770   */
 771  function bp_the_notification_delete_link( $user_id = 0 ) {
 772      echo bp_get_the_notification_delete_link( $user_id );
 773  }
 774      /**
 775       * Return the delete link for the current notification.
 776       *
 777       * @since 1.9.0
 778       * @since 2.6.0 Added $user_id as a parameter.
 779       *
 780       * @param int $user_id The user ID.
 781       * @return string
 782       */
 783  	function bp_get_the_notification_delete_link( $user_id = 0 ) {
 784          // Set default user ID to use.
 785          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 786  
 787          $retval = sprintf( '<a href="%1$s" class="delete secondary confirm bp-tooltip">%2$s</a>', esc_url( bp_get_the_notification_delete_url( $user_id ) ), __( 'Delete', 'buddypress' ) );
 788  
 789          /**
 790           * Filters the delete link for the current notification.
 791           *
 792           * @since 1.9.0
 793           * @since 2.6.0 Added $user_id as a parameter.
 794           *
 795           * @param string $retval  HTML for the delete link for the current notification.
 796           * @param int    $user_id The user ID.
 797           */
 798          return apply_filters( 'bp_get_the_notification_delete_link', $retval, $user_id );
 799      }
 800  
 801  /**
 802   * Output the URL used for deleting a single notification.
 803   *
 804   * Since this function directly outputs a URL, it is escaped.
 805   *
 806   * @since 2.1.0
 807   * @since 2.6.0 Added $user_id as a parameter.
 808   *
 809   * @param int $user_id The user ID.
 810   */
 811  function bp_the_notification_delete_url( $user_id = 0 ) {
 812      echo esc_url( bp_get_the_notification_delete_url( $user_id ) );
 813  }
 814      /**
 815       * Return the URL used for deleting a single notification.
 816       *
 817       * @since 2.1.0
 818       * @since 2.6.0 Added $user_id as a parameter.
 819       *
 820       * @param int $user_id The user ID.
 821       * @return string
 822       */
 823  	function bp_get_the_notification_delete_url( $user_id = 0 ) {
 824          // Set default user ID to use.
 825          $user_id = 0 === $user_id ? bp_displayed_user_id() : $user_id;
 826  
 827          // URL to add nonce to.
 828          if ( bp_is_current_action( 'unread' ) ) {
 829              $link = bp_get_notifications_unread_permalink( $user_id );
 830          } elseif ( bp_is_current_action( 'read' ) ) {
 831              $link = bp_get_notifications_read_permalink( $user_id );
 832          }
 833  
 834          // Get the ID.
 835          $id = bp_get_the_notification_id();
 836  
 837          // Get the args to add to the URL.
 838          $args = array(
 839              'action'          => 'delete',
 840              'notification_id' => $id,
 841          );
 842  
 843          // Add the args.
 844          $url = add_query_arg( $args, $link );
 845  
 846          // Add the nonce.
 847          $url = wp_nonce_url( $url, 'bp_notification_delete_' . $id );
 848  
 849          /**
 850           * Filters the URL used for deleting a single notification.
 851           *
 852           * @since 2.1.0
 853           * @since 2.6.0 Added $user_id as a parameter.
 854           *
 855           * @param string $url     URL used for deleting a single notification.
 856           * @param int    $user_id The user ID.
 857           */
 858          return apply_filters( 'bp_get_the_notification_delete_url', $url, $user_id );
 859      }
 860  
 861  /**
 862   * Output the action links for the current notification.
 863   *
 864   * @since 1.9.0
 865   * @since 2.6.0 Added $user_id as a parameter to $args.
 866   *
 867   * @param array|string $args Array of arguments.
 868   */
 869  function bp_the_notification_action_links( $args = '' ) {
 870      echo bp_get_the_notification_action_links( $args );
 871  }
 872      /**
 873       * Return the action links for the current notification.
 874       *
 875       * @since 1.9.0
 876       * @since 2.6.0 Added $user_id as a parameter to $args.
 877       *
 878       * @param array|string $args {
 879       *     @type string $before  HTML before the links.
 880       *     @type string $after   HTML after the links.
 881       *     @type string $sep     HTML between the links.
 882       *     @type array  $links   Array of links to implode by 'sep'.
 883       *     @type int    $user_id User ID to fetch action links for. Defaults to displayed user ID.
 884       * }
 885       * @return string HTML links for actions to take on single notifications.
 886       */
 887  	function bp_get_the_notification_action_links( $args = '' ) {
 888          // Set default user ID to use.
 889          $user_id = isset( $args['user_id'] ) ? $args['user_id'] : bp_displayed_user_id();
 890  
 891          // Parse.
 892          $r = bp_parse_args(
 893              $args,
 894              array(
 895                  'before' => '',
 896                  'after'  => '',
 897                  'sep'    => ' | ',
 898                  'links'  => array(
 899                      bp_get_the_notification_mark_link( $user_id ),
 900                      bp_get_the_notification_delete_link( $user_id ),
 901                  ),
 902              )
 903          );
 904  
 905          // Build the links.
 906          $retval = $r['before'] . implode( $r['sep'], $r['links'] ) . $r['after'];
 907  
 908          /**
 909           * Filters the action links for the current notification.
 910           *
 911           * @since 1.9.0
 912           * @since 2.6.0 Added the `$r` parameter.
 913           *
 914           * @param string $retval HTML links for actions to take on single notifications.
 915           * @param array  $r      Array of parsed arguments.
 916           */
 917          return apply_filters( 'bp_get_the_notification_action_links', $retval, $r );
 918      }
 919  
 920  /**
 921   * Output the pagination count for the current notification loop.
 922   *
 923   * @since 1.9.0
 924   */
 925  function bp_notifications_pagination_count() {
 926      echo bp_get_notifications_pagination_count();
 927  }
 928      /**
 929       * Return the pagination count for the current notification loop.
 930       *
 931       * @since 1.9.0
 932       *
 933       * @return string HTML for the pagination count.
 934       */
 935  	function bp_get_notifications_pagination_count() {
 936          $query_loop = buddypress()->notifications->query_loop;
 937          $start_num  = intval( ( $query_loop->pag_page - 1 ) * $query_loop->pag_num ) + 1;
 938          $from_num   = bp_core_number_format( $start_num );
 939          $to_num     = bp_core_number_format( ( $start_num + ( $query_loop->pag_num - 1 ) > $query_loop->total_notification_count ) ? $query_loop->total_notification_count : $start_num + ( $query_loop->pag_num - 1 ) );
 940          $total      = bp_core_number_format( $query_loop->total_notification_count );
 941  
 942          if ( 1 == $query_loop->total_notification_count ) {
 943              $pag = __( 'Viewing 1 notification', 'buddypress' );
 944          } else {
 945              /* translators: 1: notification from number. 2: notification to number. 3: total notifications. */
 946              $pag = sprintf( _n( 'Viewing %1$s - %2$s of %3$s notification', 'Viewing %1$s - %2$s of %3$s notifications', $query_loop->total_notification_count, 'buddypress' ), $from_num, $to_num, $total );
 947          }
 948  
 949          /**
 950           * Filters the pagination count for the current notification loop.
 951           *
 952           * @since 1.9.0
 953           *
 954           * @param string $pag HTML for the pagination count.
 955           */
 956          return apply_filters( 'bp_notifications_pagination_count', $pag );
 957      }
 958  
 959  /**
 960   * Output the pagination links for the current notification loop.
 961   *
 962   * @since 1.9.0
 963   */
 964  function bp_notifications_pagination_links() {
 965      echo bp_get_notifications_pagination_links();
 966  }
 967      /**
 968       * Return the pagination links for the current notification loop.
 969       *
 970       * @since 1.9.0
 971       *
 972       * @return string HTML for the pagination links.
 973       */
 974  	function bp_get_notifications_pagination_links() {
 975  
 976          /**
 977           * Filters the pagination links for the current notification loop.
 978           *
 979           * @since 1.9.0
 980           *
 981           * @param string $pag_links HTML for the pagination links.
 982           */
 983          return apply_filters( 'bp_get_notifications_pagination_links', buddypress()->notifications->query_loop->pag_links );
 984      }
 985  
 986  /** Form Helpers **************************************************************/
 987  
 988  /**
 989   * Output the form for changing the sort order of notifications.
 990   *
 991   * @since 1.9.0
 992   */
 993  function bp_notifications_sort_order_form() {
 994  
 995      // Setup local variables.
 996      $orders   = array( 'DESC', 'ASC' );
 997      $selected = 'DESC';
 998  
 999      // Check for a custom sort_order.
1000      if ( ! empty( $_REQUEST['sort_order'] ) ) {
1001          if ( in_array( $_REQUEST['sort_order'], $orders, true ) ) {
1002              $selected = $_REQUEST['sort_order'];
1003          }
1004      } ?>
1005  
1006      <form action="" method="get" id="notifications-sort-order">
1007          <label for="notifications-sort-order-list"><?php esc_html_e( 'Order By:', 'buddypress' ); ?></label>
1008  
1009          <select id="notifications-sort-order-list" name="sort_order" onchange="this.form.submit();">
1010              <option value="DESC" <?php selected( $selected, 'DESC' ); ?>><?php _e( 'Newest First', 'buddypress' ); ?></option>
1011              <option value="ASC"  <?php selected( $selected, 'ASC'  ); ?>><?php _e( 'Oldest First', 'buddypress' ); ?></option>
1012          </select>
1013  
1014          <noscript>
1015              <input id="submit" type="submit" name="form-submit" class="submit" value="<?php esc_attr_e( 'Go', 'buddypress' ); ?>" />
1016          </noscript>
1017      </form>
1018  
1019  <?php
1020  }
1021  
1022  /**
1023   * Output the dropdown for bulk management of notifications.
1024   *
1025   * @since 2.2.0
1026   */
1027  function bp_notifications_bulk_management_dropdown() {
1028      ?>
1029      <label class="bp-screen-reader-text" for="notification-select"><?php
1030          /* translators: accessibility text */
1031          _e( 'Select Bulk Action', 'buddypress' );
1032      ?></label>
1033      <select name="notification_bulk_action" id="notification-select">
1034          <option value="" selected="selected"><?php _e( 'Bulk Actions', 'buddypress' ); ?></option>
1035  
1036          <?php if ( bp_is_current_action( 'unread' ) ) : ?>
1037              <option value="read"><?php _e( 'Mark read', 'buddypress' ); ?></option>
1038          <?php elseif ( bp_is_current_action( 'read' ) ) : ?>
1039              <option value="unread"><?php _e( 'Mark unread', 'buddypress' ); ?></option>
1040          <?php endif; ?>
1041          <option value="delete"><?php _e( 'Delete', 'buddypress' ); ?></option>
1042      </select>
1043      <input type="submit" id="notification-bulk-manage" class="button action" value="<?php esc_attr_e( 'Apply', 'buddypress' ); ?>">
1044      <?php
1045  }


Generated: Tue Mar 19 01:01:09 2024 Cross-referenced by PHPXref 0.7.1