Skip to:
Content

BuddyPress.org

Changeset 7539


Ignore:
Timestamp:
11/09/2013 05:47:04 AM (13 years ago)
Author:
johnjamesjacoby
Message:

Add functions for permalinks, mark and delete links, and use in action links output. See #5148.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-notifications/bp-notifications-template.php

    r7536 r7539  
    2828        function bp_get_notifications_slug() {
    2929                return apply_filters( 'bp_get_notifications_slug', buddypress()->notifications->slug );
     30        }
     31
     32/**
     33 * Output the notifications permalink.
     34 *
     35 * @since BuddyPress (1.9.0)
     36 */
     37function bp_notifications_permalink() {
     38        echo bp_get_notifications_permalink();
     39}
     40        /**
     41         * Return the notifications permalink.
     42         *
     43         * @since BuddyPress (1.9.0)
     44         *
     45         * @return string Notifications permalink
     46         */
     47        function bp_get_notifications_permalink() {
     48                $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() );
     49                return apply_filters( 'bp_get_notifications_permalink', $retval );
     50        }
     51
     52/**
     53 * Output the unread notifications permalink.
     54 *
     55 * @since BuddyPress (1.9.0)
     56 */
     57function bp_notifications_unread_permalink() {
     58        echo bp_get_notifications_unread_permalink();
     59}
     60        /**
     61         * Return the unread notifications permalink.
     62         *
     63         * @since BuddyPress (1.9.0)
     64         *
     65         * @return string Unread notifications permalink
     66         */
     67        function bp_get_notifications_unread_permalink() {
     68                $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() . '/unread' );
     69                return apply_filters( 'bp_get_notifications_unread_permalink', $retval );
     70        }
     71
     72/**
     73 * Output the read notifications permalink.
     74 *
     75 * @since BuddyPress (1.9.0)
     76 */
     77function bp_notifications_read_permalink() {
     78        echo bp_get_notifications_read_permalink();
     79}
     80        /**
     81         * Return the read notifications permalink.
     82         *
     83         * @since BuddyPress (1.9.0)
     84         *
     85         * @return string Read notifications permalink
     86         */
     87        function bp_get_notifications_read_permalink() {
     88                $retval = trailingslashit( bp_loggedin_user_domain() . bp_get_notifications_slug() . '/read' );
     89                return apply_filters( 'bp_get_notifications_unread_permalink', $retval );
    3090        }
    3191
     
    186246                        'page'         => $this->pag_page,
    187247                        'per_page'     => $this->pag_num,
    188                         'search_terms' => $this->search_terms,
     248                        'search_terms' => $this->search_terms
    189249                ) );
    190250
     
    363423                'max'          => false,
    364424                'search_terms' => isset( $_REQUEST['s'] ) ? stripslashes( $_REQUEST['s'] ) : '',
    365                 'page_arg'     => 'npage',
     425                'page_arg'     => 'npage'
    366426        ) );
    367427
     
    534594                if ( '0000-00-00 00:00:00' !== $date_notified ) {
    535595                        $retval = bp_core_time_since( $date_notified );
    536 
     596                       
    537597                // Notified date is empty, so return a fun string
    538598                } else {
     
    585645
    586646/**
     647 * Output the mark read link for the current notification.
     648 *
     649 * @since BuddyPress (1.9.0)
     650 *
     651 * @uses bp_get_the_notification_mark_read_link()
     652 */
     653function bp_the_notification_mark_read_link() {
     654        echo bp_get_the_notification_mark_read_link();
     655}
     656        /**
     657         * Return the mark read link for the current notification.
     658         *
     659         * @since BuddyPress (1.9.0)
     660         */
     661        function bp_get_the_notification_mark_read_link() {
     662
     663                ob_start(); ?>
     664
     665                <a href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'read', 'id' => bp_get_the_notification_id() ), bp_get_notifications_unread_permalink() ), 'bp_notification_' . bp_get_the_notification_id() ); ?>" class="mark-read primary"><?php _e( 'Read', 'buddypress' ); ?></a>
     666
     667                <?php $retval = ob_get_clean();
     668
     669                return apply_filters( 'bp_get_the_notification_mark_read_link', $retval );
     670        }
     671
     672/**
     673 * Output the mark read link for the current notification.
     674 *
     675 * @since BuddyPress (1.9.0)
     676 *
     677 * @uses bp_get_the_notification_mark_unread_link()
     678 */
     679function bp_the_notification_mark_unread_link() {
     680        echo bp_get_the_notification_mark_unread_link();
     681}
     682        /**
     683         * Return the mark read link for the current notification.
     684         *
     685         * @since BuddyPress (1.9.0)
     686         */
     687        function bp_get_the_notification_mark_unread_link() {
     688
     689                ob_start(); ?>
     690
     691                <a href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'unread', 'id' => bp_get_the_notification_id() ), bp_get_notifications_read_permalink() ), 'bp_notification_' . bp_get_the_notification_id() ); ?>" class="mark-unread primary"><?php _e( 'Unread', 'buddypress' ); ?></a>
     692
     693                <?php $retval = ob_get_clean();
     694
     695                return apply_filters( 'bp_get_the_notification_mark_unread_link', $retval );
     696        }
     697
     698/**
     699 * Output the mark link for the current notification.
     700 *
     701 * @since BuddyPress (1.9.0)
     702 *
     703 * @uses bp_get_the_notification_mark_unread_link()
     704 */
     705function bp_the_notification_mark_link() {
     706        echo bp_get_the_notification_mark_link();
     707}
     708        /**
     709         * Return the mark link for the current notification.
     710         *
     711         * @since BuddyPress (1.9.0)
     712         */
     713        function bp_get_the_notification_mark_link() {
     714
     715                if ( bp_is_current_action( 'read' ) ) {
     716                        $retval = bp_get_the_notification_mark_unread_link();
     717                } else {
     718                        $retval = bp_get_the_notification_mark_read_link();
     719                }
     720
     721                return apply_filters( 'bp_get_the_notification_mark_link', $retval );
     722        }
     723
     724/**
     725 * Output the delete link for the current notification.
     726 *
     727 * @since BuddyPress (1.9.0)
     728 *
     729 * @uses bp_get_the_notification_delete_link()
     730 */
     731function bp_the_notification_delete_link() {
     732        echo bp_get_the_notification_delete_link();
     733}
     734        /**
     735         * Return the delete link for the current notification.
     736         *
     737         * @since BuddyPress (1.9.0)
     738         */
     739        function bp_get_the_notification_delete_link() {
     740
     741                // URL to add nonce to
     742                if ( bp_is_current_action( 'unread' ) ) {
     743                        $link = bp_get_notifications_unread_permalink();
     744                } elseif ( bp_is_current_action( 'read' ) ) {
     745                        $link = bp_get_notifications_read_permalink();
     746                }
     747
     748                // Start the output buffer
     749                ob_start(); ?>
     750
     751                <a href="<?php echo wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'id' => bp_get_the_notification_id() ), $link ), 'bp_notification_' . bp_get_the_notification_id() ); ?>" class="delete secondary"><?php _e( 'Delete', 'buddypress' ); ?></a>
     752
     753                <?php $retval = ob_get_clean();
     754
     755                return apply_filters( 'bp_get_the_notification_delete_link', $retval );
     756        }
     757
     758/**
    587759 * Output the action links for the current notification.
    588760 *
    589761 * @since BuddyPress (1.9.0)
    590762 */
    591 function bp_the_notification_action_links() {
    592         echo bp_get_the_notification_action_links();
     763function bp_the_notification_action_links( $args = '' ) {
     764        echo bp_get_the_notification_action_links( $args );
    593765}
    594766        /**
     
    597769         * @since BuddyPress (1.9.0)
    598770         *
     771         * @param array $args {
     772         *     @type string $before HTML before the links
     773         *     @type string $after HTML after the links
     774         *     @type string $sep HTML between the links
     775         *     @type array $links Array of links to implode by 'sep'
     776         * }
     777         *
    599778         * @return string HTML links for actions to take on single notifications.
    600779         */
    601         function bp_get_the_notification_action_links() {
    602 
    603                 // Setup the return value
    604                 $retval = '';
    605 
    606                 // Start the output buffer
    607                 ob_start();
    608 
    609                 // Get and empty the output buffer
    610                 $retval = ob_get_clean();
     780        function bp_get_the_notification_action_links( $args = '' ) {
     781
     782                // Parse
     783                $r = wp_parse_args( $args, array(
     784                        'before' => '',
     785                        'after'  => '',
     786                        'sep'    => ' | ',
     787                        'links'  => array(
     788                                bp_get_the_notification_mark_link(),
     789                                bp_get_the_notification_delete_link()
     790                        )
     791                ) );
     792
     793                // Build the links
     794                $retval = $r['before'] . implode( $r['links'], $r['sep'] ) . $r['after'];
    611795
    612796                return apply_filters( 'bp_get_the_notification_action_links', $retval );
Note: See TracChangeset for help on using the changeset viewer.