<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[5641] sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums: Support Forums: Allow moderators to add notes to users.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/5641">5641</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/5641","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>SergeyBiryukov</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-07-10 20:23:25 +0000 (Mon, 10 Jul 2017)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Support Forums: Allow moderators to add notes to users.

Props Clorith for initial patch.
Fixes <a href="http://meta.trac.wordpress.org/ticket/2272">#2272</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumscssstylesmoderatorscss">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassmoderatorsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumssupportforumsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusernotesphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php</a></li>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/js/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsjsusernotesjs">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/js/user-notes.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumscssstylesmoderatorscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css 2017-07-10 20:22:50 UTC (rev 5640)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css   2017-07-10 20:23:25 UTC (rev 5641)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5,3 +5,29 @@
</span><span class="cx" style="display: block; padding: 0 10px"> #bbpress-forums .status-archived.odd {
</span><span class="cx" style="display: block; padding: 0 10px">        background-color: #fdd !important;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/*--------------------------------------------------------------
+# User notes
+--------------------------------------------------------------*/
+
+.wporg-bbp-user-notes.hidden-notes {
+       display: none;
+}
+
+.wporg-bbp-user-note-meta {
+       text-align: right;
+}
+
+.wporg-bbp-add-user-note {
+       padding-bottom: 20px;
+       overflow: hidden;
+}
+
+.wporg-bbp-add-user-note textarea {
+       width: 100%;
+}
+
+.wporg-bbp-add-user-note button {
+       float: right;
+       color: #555; /* Back-compat for wporg-forums theme */
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassmoderatorsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php  2017-07-10 20:22:50 UTC (rev 5640)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php    2017-07-10 20:23:25 UTC (rev 5641)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -120,7 +120,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        public function enqueue_styles() {
</span><span class="cx" style="display: block; padding: 0 10px">                if ( current_user_can( 'moderate' ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        wp_enqueue_style( 'support-forums-moderators', plugins_url( 'css/styles-moderators.css', __DIR__ ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 wp_enqueue_style( 'support-forums-moderators', plugins_url( 'css/styles-moderators.css', __DIR__ ), array(), '20170710' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclasspluginphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php      2017-07-10 20:22:50 UTC (rev 5640)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-plugin.php        2017-07-10 20:23:25 UTC (rev 5641)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,6 +38,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><span class="cx" style="display: block; padding: 0 10px">        private function __construct() {
</span><span class="cx" style="display: block; padding: 0 10px">                $this->users       = new Users;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $this->user_notes  = new User_Notes;
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->moderators  = new Moderators;
</span><span class="cx" style="display: block; padding: 0 10px">                $this->hooks       = new Hooks;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassusernotesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-user-notes.php    2017-07-10 20:23:25 UTC (rev 5641)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,402 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Forums;
+
+class User_Notes {
+
+       /**
+        * An array of authors who have written notes.
+        *
+        * These are stored to avoid looking up user IDs for every note.
+        *
+        * @access private
+        *
+        * @var array $moderators
+        */
+       private $moderators = array();
+
+       /**
+        * An array of all notes for each user.
+        *
+        * As users may have written multiple replies in a thread, this will help us
+        * to avoid looking up all the notes multiple times.
+        *
+        * @access private
+        *
+        * @var array $user_notes
+        */
+       private $user_notes = array();
+
+       public function __construct() {
+               add_action( 'wp_enqueue_scripts',                   array( $this, 'enqueue_scripts' ) );
+
+               add_action( 'bbp_post_request',                     array( $this, 'add_user_note' ) );
+               add_action( 'bbp_get_request',                      array( $this, 'delete_user_note' ) );
+
+               add_action( 'bbp_theme_after_topic_author_details', array( $this, 'add_user_notes_toggle_link' ) );
+               add_action( 'bbp_theme_after_reply_author_details', array( $this, 'add_user_notes_toggle_link' ) );
+
+               add_action( 'bbp_theme_after_topic_content',        array( $this, 'display_user_notes_in_content' ) );
+               add_action( 'bbp_theme_after_reply_content',        array( $this, 'display_user_notes_in_content' ) );
+               add_action( 'bbp_template_after_user_profile',      array( $this, 'display_user_notes_in_profile' ) );
+       }
+
+       /**
+        * Registers scripts and styles.
+        */
+       function enqueue_scripts() {
+               if ( ! current_user_can( 'moderate' ) ) {
+                       return;
+               }
+
+               wp_enqueue_script( 'wporg-bbp-user-notes', plugins_url( '/js/user-notes.js', __DIR__ ), array( 'jquery' ), '20170710', true );
+       }
+
+       /**
+        * Checks if a note is added to a post and save it to the user's meta data.
+        *
+        * @param string $action Requested action.
+        */
+       function add_user_note( $action = '' ) {
+               if ( 'wporg_bbp_add_user_note' !== $action || ! current_user_can( 'moderate' ) ) {
+                       return;
+               }
+
+               $user_id   = isset( $_POST['user_id'] ) ? (int) $_POST['user_id'] : 0;
+               $post_id   = isset( $_POST['post_id'] ) ? (int) $_POST['post_id'] : 0;
+
+               $note_id   = isset( $_POST['note_id'] ) ? (int) $_POST['note_id'] : 0;
+               $note_text = isset( $_POST['note_text'] ) ? wp_kses( $_POST['note_text'], array( 'a' => array( 'href' => true ) ) ) : '';
+
+               if ( ! $user_id || ! $note_text ) {
+                       return;
+               }
+
+               // Make sure our nonces are in order.
+               if ( ! bbp_verify_nonce_request( sprintf( 'wporg-bbp-add-user-note_%d_%d', $user_id, $post_id ) ) ) {
+                       return;
+               }
+
+               // Make sure the user exists.
+               $user = get_userdata( $user_id );
+               if ( ! $user ) {
+                       return;
+               }
+
+               // Get an array of existing notes, or create an array if there are none.
+               $user_notes = get_user_meta( $user_id, '_wporg_bbp_user_notes', true );
+               if ( ! $user_notes ) {
+                       $user_notes = array();
+               }
+
+               $edit_note = isset( $user_notes[ $note_id ] );
+               if ( ! $edit_note ) {
+                       $note_id = count( $user_notes ) + 1;
+               }
+
+               // Add the new note to the array of notes.
+               $user_notes[ $note_id ] = (object) array(
+                       'text'      => $note_text,
+                       'date'      => current_time( 'mysql' ),
+                       'post_id'   => $post_id,
+                       'moderator' => wp_get_current_user()->user_nicename
+               );
+
+               update_user_meta( $user_id, '_wporg_bbp_user_notes', $user_notes );
+
+               $redirect_url = set_url_scheme( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
+
+               // Redirect to clear form data.
+               bbp_redirect( $redirect_url );
+       }
+
+       /**
+        * Deletes a previously added note from user's meta data.
+        *
+        * @param string $action Requested action.
+        */
+       function delete_user_note( $action = '' ) {
+               if ( 'wporg_bbp_delete_user_note' !== $action || ! current_user_can( 'moderate' ) ) {
+                       return;
+               }
+
+               $user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0;
+               $note_id = isset( $_GET['note_id'] ) ? (int) $_GET['note_id'] : 0;
+
+               if ( ! $user_id || ! $note_id ) {
+                       return;
+               }
+
+               // Make sure our nonces are in order.
+               if ( ! bbp_verify_nonce_request( sprintf( 'wporg-bbp-delete-user-note_%d_%d', $user_id, $note_id ) ) ) {
+                       return;
+               }
+
+               // Make sure the user exists.
+               $user = get_userdata( $user_id );
+               if ( ! $user ) {
+                       return;
+               }
+
+               // Get an array of existing notes.
+               $user_notes = get_user_meta( $user_id, '_wporg_bbp_user_notes', true );
+               if ( ! $user_notes ) {
+                       return;
+               }
+
+               if ( isset( $user_notes[ $note_id ] ) ) {
+                       $post_id = $user_notes[ $note_id ]->post_id;
+                       unset( $user_notes[ $note_id ] );
+               } else {
+                       $post_id = 0;
+               }
+
+               // Reindex the array from 1.
+               if ( $user_notes ) {
+                       $user_notes = array_combine( range( 1, count( $user_notes ) ), array_values( $user_notes ) );
+               }
+
+               update_user_meta( $user_id, '_wporg_bbp_user_notes', $user_notes );
+
+               $redirect_url = remove_query_arg( array( 'action', 'user_id', 'note_id', '_wpnonce' ) );
+
+               // Redirect to clear URL.
+               bbp_redirect( $redirect_url );
+       }
+
+       /**
+        * Retrieves all notes for a particular user.
+        *
+        * @param int $user_id User ID. Defaults to the current post author.
+        * @return array Array of user notes.
+        */
+       function get_user_notes( $user_id = 0 ) {
+               if ( ! $user_id ) {
+                       $user_id = get_the_author_meta( 'ID' );
+               }
+
+               // Bail early if the notes are already grabbed for this session.
+               if ( isset( $this->user_notes[ $user_id ] ) ) {
+                       return $this->user_notes[ $user_id ];
+               }
+
+               $user_notes = get_user_meta( $user_id, '_wporg_bbp_user_notes', true );
+               if ( ! $user_notes ) {
+                       $user_notes = array();
+               }
+
+               $this->user_notes[ $user_id ] = $user_notes;
+
+               return $user_notes;
+       }
+
+       /**
+        * Adds the toggle link for notes to the author area of a post.
+        */
+       function add_user_notes_toggle_link() {
+               if ( ! current_user_can( 'moderate' ) ) {
+                       return;
+               }
+
+               printf( '<div class="wporg-bbp-user-notes-toggle"><a href="#" data-post-id="%d">%s</a></div>',
+                       esc_attr( get_the_ID() ),
+                       esc_html(
+                               /* translators: %d: user notes count */
+                               sprintf( __( 'Toggle user notes (%d)', 'wporg-forums' ),
+                                       count( $this->get_user_notes() )
+                               )
+                       )
+               );
+       }
+
+       /**
+        * Retrieves permalink to the post associated with a note.
+        *
+        * If the note is not associated with a particular post, returns a link
+        * to user profile.
+        *
+        * @param int $post_id Post ID. Default 0.
+        * @param int $user_id User ID. Defaults to the current post author.
+        * @return string Post permalink or user profile URL.
+        */
+       function get_user_note_post_permalink( $post_id = 0, $user_id = 0 ) {
+               $post_type = $post_id ? get_post_type( $post_id ) : '';
+
+               if ( 'topic' === $post_type ) {
+                       $permalink = bbp_get_topic_permalink( $post_id ) . '#post-' . (int) $post_id;
+                       $permalink = add_query_arg( 'show_user_notes', $post_id, $permalink );
+               } elseif ( 'reply' === $post_type ) {
+                       $permalink = bbp_get_reply_url( $post_id );
+                       $permalink = add_query_arg( 'show_user_notes', $post_id, $permalink );
+               } else {
+                       $permalink = bbp_get_user_profile_url( $user_id ) . '#user-notes';
+               }
+
+               return $permalink;
+       }
+
+       /**
+        * Displays notes for a particular user and a form for adding new ones.
+        *
+        * @param int $user_id User ID. Defaults to the current post author.
+        */
+       function display_user_notes( $user_id = 0 ) {
+               $note_id    = isset( $_GET['note_id'] ) ? (int) $_GET['note_id'] : 0;
+               $user_notes = $this->get_user_notes( $user_id );
+               $edit_note  = isset( $user_notes[ $note_id ] );
+
+               $current_post_type = get_post_type();
+
+               foreach ( $user_notes as $key => $note ) {
+                       $moderator = $note->moderator;
+
+                       if ( ! isset( $this->moderators[ $moderator ] ) ) {
+                               $this->moderators[ $moderator ] = $moderator;
+                       }
+
+                       $post_permalink     = $this->get_user_note_post_permalink( $note->post_id, $user_id );
+                       $redirect_on_delete = $this->get_user_note_post_permalink( get_the_ID(), $user_id );
+
+                       printf( '<div class="bbp-template-notice warning"><p>%s</p> %s</div>' . "\n",
+                               wp_kses( $note->text, array( 'a' => array( 'href' => true ) ) ),
+                               sprintf( '<p class="wporg-bbp-user-note-meta">%s | %s | %s</p>' . "\n",
+                                       /* translators: 1: author's display name, 2: link to post, 3: user note date, 4: user note time */
+                                       sprintf( __( 'By %1$s on <a href="%2$s">%3$s at %4$s</a>', 'wporg-forums' ),
+                                               sprintf( '<a href="%s">%s</a>', esc_url( home_url( "/users/$moderator/" ) ), $moderator ),
+                                               esc_url( $post_permalink ),
+                                               /* translators: localized date format, see https://secure.php.net/date */
+                                               mysql2date( __( 'F j, Y', 'wporg-forums' ), $note->date ),
+                                               /* translators: localized time format, see https://secure.php.net/date */
+                                               mysql2date( __( 'g:i a', 'wporg-forums' ), $note->date )
+                                       ),
+                                       sprintf( '<a href="%s">%s</a>',
+                                               esc_url(
+                                                       add_query_arg( array(
+                                                               'action'  => 'wporg_bbp_edit_user_note',
+                                                               'user_id' => $user_id,
+                                                               'note_id' => $key,
+                                                       ), $post_permalink )
+                                               ),
+                                               __( 'Edit', 'wporg-forums' )
+                                       ),
+                                       sprintf( '<a href="%s">%s</a>',
+                                               esc_url( wp_nonce_url(
+                                                       add_query_arg( array(
+                                                               'action'  => 'wporg_bbp_delete_user_note',
+                                                               'user_id' => $user_id,
+                                                               'note_id' => $key,
+                                                       ), $redirect_on_delete ),
+                                                       sprintf( 'wporg-bbp-delete-user-note_%d_%d', $user_id, $key )
+                                               ) ),
+                                               __( 'Delete', 'wporg-forums' )
+                                       )
+                               )
+                       );
+
+                       if ( $edit_note && $key == $note_id ) {
+                               $this->display_note_form( $user_id );
+                       }
+               }
+
+               if ( ! $user_notes ) {
+                       printf( '<div class="bbp-template-notice info"><p>%s</p></div>',
+                               esc_html__( 'No notes have been added for this user.', 'wporg-forums' )
+                       );
+               }
+
+               if ( ! $edit_note ) {
+                       $this->display_note_form( $user_id );
+               }
+       }
+
+       /**
+        * Displays the form for adding new notes or editing existing notes.
+        *
+        * @param int $user_id User ID. Defaults to the current post author.
+        */
+       function display_note_form( $user_id = 0 ) {
+               if ( ! $user_id ) {
+                       $user_id = get_the_author_meta( 'ID' );
+               }
+
+               if ( ! bbp_is_single_user_profile() ) {
+                       $post_id = get_the_ID();
+               } else {
+                       $post_id = 0;
+               }
+
+               $note_id    = isset( $_GET['note_id'] ) ? (int) $_GET['note_id'] : 0;
+               $user_notes = $this->get_user_notes( $user_id );
+
+               if ( isset( $user_notes[ $note_id ] ) ) {
+                       $edit_note    = true;
+                       $note_text    = $user_notes[ $note_id ]->text;
+                       $button_label = esc_html__( 'Save note', 'wporg-forums' );
+               } else {
+                       $edit_note    = false;
+                       $note_text    = '';
+                       $button_label = esc_html__( 'Add your note', 'wporg-forums' );
+               }
+
+               $post_permalink = $this->get_user_note_post_permalink( $post_id );
+               ?>
+               <form action="<?php echo esc_url( $post_permalink ); ?>" method="post" class="wporg-bbp-add-user-note">
+                       <?php wp_nonce_field( sprintf( 'wporg-bbp-add-user-note_%d_%d', $user_id, $post_id ) ); ?>
+                       <input type="hidden" name="action" value="wporg_bbp_add_user_note">
+                       <input type="hidden" name="user_id" value="<?php echo esc_attr( $user_id ); ?>">
+                       <input type="hidden" name="post_id" value="<?php echo esc_attr( $post_id ); ?>">
+                       <?php if ( $edit_note ) : ?>
+                               <input type="hidden" name="note_id" value="<?php echo esc_attr( $note_id ); ?>">
+                       <?php endif; ?>
+
+                       <label for="wporg-bbp-user-note-text" class="screen-reader-text"><?php esc_html_e( 'Note text:', 'wporg-forums' ); ?></label>
+                       <textarea name="note_text" id="wporg-bbp-user-note-text" cols="40" rows="5"><?php echo esc_textarea( $note_text ); ?></textarea>
+
+                       <button type="submit" class="button"><?php echo $button_label; ?></button>
+               </form>
+               <?php
+       }
+
+       /**
+        * Displays existing notes and the form for adding new ones after post content
+        * in topics or replies.
+        */
+       function display_user_notes_in_content() {
+               if ( ! current_user_can( 'moderate' ) ) {
+                       return;
+               }
+
+               $user_id = get_the_author_meta( 'ID' );
+               $post_id = get_the_ID();
+
+               $show_user_notes = isset( $_GET['show_user_notes'] ) && (int) $_GET['show_user_notes'] == $post_id;
+
+               $class = 'wporg-bbp-user-notes';
+               if ( ! $show_user_notes ) {
+                       $class .= ' hidden-notes';
+               }
+               ?>
+               <div class="<?php echo esc_attr( $class ); ?>" id="wporg-bbp-user-notes-<?php echo esc_attr( $post_id ); ?>">
+                       <?php $this->display_user_notes( $user_id ); ?>
+               </div>
+               <?php
+       }
+
+       /**
+        * Displays existing notes and the form for adding new ones in user profile.
+        */
+       function display_user_notes_in_profile() {
+               if ( ! current_user_can( 'moderate' ) ) {
+                       return;
+               }
+               ?>
+               <div class="wporg-bbp-user-notes">
+                       <h2 id="user-notes" class="entry-title"><?php esc_html_e( 'User Notes', 'wporg-forums' ); ?></h2>
+                       <div class="bbp-user-section">
+                               <?php $this->display_user_notes( bbp_get_displayed_user_id() ); ?>
+                       </div>
+               </div>
+               <?php
+       }
+
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsjsusernotesjs"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/js/user-notes.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/js/user-notes.js                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/js/user-notes.js    2017-07-10 20:23:25 UTC (rev 5641)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,8 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+jQuery( document ).ready( function( $ ) {
+
+       $( '.bbp-topic-author, .bbp-reply-author' ).on( 'click', '.wporg-bbp-user-notes-toggle a', function( event ) {
+               event.preventDefault();
+               $( '#wporg-bbp-user-notes-' + $(this).data( 'post-id' ) ).toggle();
+       });
+
+});
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumssupportforumsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php        2017-07-10 20:22:50 UTC (rev 5640)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/support-forums.php  2017-07-10 20:23:25 UTC (rev 5641)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -16,6 +16,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> // General includes.
</span><span class="cx" style="display: block; padding: 0 10px"> include( dirname( __FILE__ ) . '/inc/class-plugin.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> include( dirname( __FILE__ ) . '/inc/class-users.php' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+include( dirname( __FILE__ ) . '/inc/class-user-notes.php' );
</ins><span class="cx" style="display: block; padding: 0 10px"> include( dirname( __FILE__ ) . '/inc/class-moderators.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> include( dirname( __FILE__ ) . '/inc/class-hooks.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre>
</div>
</div>

</body>
</html>