<!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>[3937] sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums: Support Forums: Add "archived" queue for moderator use.</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/3937">3937</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/3937","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>jmdodd</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-09-03 00:40:00 +0000 (Sat, 03 Sep 2016)</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: Add "archived" queue for moderator use.
Archived posts are those that should not be visible, but may need to be referenced later.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassmoderatorsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumscssstylesmoderatorscss">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumscssstylesmoderatorscss"></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/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 (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css 2016-09-03 00:40:00 UTC (rev 3937)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,7 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+#bbpress-forums .status-archived.even {
+ background-color: #fee !important;
+}
+
+#bbpress-forums .status-archived.odd {
+ background-color: #fdd !important;
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/css/styles-moderators.css
</span><span class="cx" style="display: block; padding: 0 10px">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: svn:eol-style</h4></div>
<ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+native
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><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 2016-09-02 22:28:12 UTC (rev 3936)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-moderators.php 2016-09-03 00:40:00 UTC (rev 3937)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,8 +4,24 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> class Moderators {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ const ARCHIVED = 'archived';
+ const ARCHIVED_META = '_wporg_bbp_unarchived_post_status';
+ const DEFAULT_STATUS = 'publish';
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function __construct() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- add_action( 'parse_query', array( $this, 'register_views' ), 1 );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Moderator-specific views.
+ add_action( 'bbp_register_views', array( $this, 'register_views' ), 1 );
+
+ // Scripts and styles.
+ add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
+
+ // Archived post status.
+ add_action( 'bbp_register_post_statuses', array( $this, 'register_post_statuses' ) );
+ add_action( 'bbp_get_request', array( $this, 'archive_handler' ) );
+ add_filter( 'bbp_after_has_topics_parse_args', array( $this, 'add_post_status_to_query' ) );
+ add_filter( 'bbp_after_has_replies_parse_args', array( $this, 'add_post_status_to_query' ) );
+ add_filter( 'bbp_topic_admin_links', array( $this, 'admin_links' ), 10, 2 );
+ add_filter( 'bbp_reply_admin_links', array( $this, 'admin_links' ), 10, 2 );
</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"> public function register_views() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -42,5 +58,254 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'orderby' => 'ID',
</span><span class="cx" style="display: block; padding: 0 10px"> )
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ bbp_register_view(
+ 'archived',
+ __( 'Archived', 'wporg-forums' ),
+ array(
+ 'meta_key' => null,
+ 'post_type' => array(
+ 'topic',
+ 'reply',
+ ),
+ 'post_status' => 'archived',
+ 'show_stickies' => false,
+ 'orderby' => 'ID',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ public function enqueue_styles() {
+ if ( current_user_can( 'moderate' ) ) {
+ wp_enqueue_style( 'support-forums-moderators', plugins_url( 'css/styles-moderators.css', __DIR__ ) );
+ }
+ }
+
+ public function register_post_statuses() {
+
+ /**
+ * Add archived post status.
+ *
+ * Archived posts are intended for moderator use in determining a pattern
+ * of behavior. They are not duplicates, or spam, but should not be moved
+ * to the trash because they record user activity.
+ */
+ register_post_status(
+ self::ARCHIVED,
+ array(
+ 'label' => _x( 'Archived', 'post', 'wporg-forums' ),
+ 'label_count' => _nx_noop( 'Archived <span class="count">(%s)</span>', 'Archived <span class="count">(%s)</span>', 'post', 'wporg-forums' ),
+ 'protected' => true,
+ 'exclude_from_search' => true,
+ 'show_in_admin_status_list' => true,
+ 'show_in_admin_add_list' => false,
+ )
+ );
+
+ }
+
+ public function archive_handler( $action = '' ) {
+ if ( ! current_user_can( 'moderate' ) ) {
+ return;
+ }
+ $user_id = get_current_user_id();
+
+ if ( ! in_array( $action, $this->get_valid_actions() ) ) {
+ return;
+ }
+
+ if ( empty( $_GET['post_id'] ) ) {
+ return;
+ }
+
+ $post = get_post( absint( $_GET['post_id'] ) );
+ if ( ! $post ) {
+ return false;
+ }
+
+ // Check for empty post id.
+ if ( ! $post ) {
+ bbp_add_error( 'wporg_bbp_archive_post_id', __( '<strong>ERROR</strong>: No post was found! Which post are you archiving?', 'wporg-forums' ) );
+
+ // Check for current user.
+ } elseif ( empty( $user_id ) ) {
+ bbp_add_error( 'wporg_bbp_archive_logged_in', __( '<strong>ERROR</strong>: You must be logged in to do this!', 'wporg-forums' ) );
+
+ // Check nonce.
+ } elseif ( ! bbp_verify_nonce_request( 'toggle-post-archive_' . $user_id . '_' . $post->ID ) ) {
+ bbp_add_error( 'wporg_bbp_archive_nonce', __( '<strong>ERROR</strong>: Are you sure you wanted to do that?', 'wporg-forums' ) );
+
+ }
+
+ if ( bbp_has_errors() ) {
+ return;
+ }
+
+ $is_archived = $this->is_post_archived( $post->ID );
+ $success = false;
+ $add_view_all = false;
+
+ if ( true == $is_archived && 'wporg_bbp_unarchive_post' === $action ) {
+ $success = $this->unarchive_post( $post->ID );
+ } elseif ( false == $is_archived && 'wporg_bbp_archive_post' === $action ) {
+ $success = $this->archive_post( $post->ID );
+ $add_view_all = true;
+ }
+
+ $permalink = $this->get_permalink( $post->ID );
+ if ( $add_view_all ) {
+ $permalink = bbp_add_view_all( $permalink, true );
+ }
+
+ if ( true === $success ) {
+ $redirect = $this->get_permalink( $post->ID );
+ bbp_redirect( $redirect );
+ } elseif ( true === $is_archived && 'wporg_bbp_archive_post' === $action ) {
+ bbp_add_error( 'wporg_bbp_archive_post', __( '<strong>ERROR</strong>: There was a problem archiving that post!', 'wporg-forums' ) );
+ } elseif ( false === $is_archived && 'wporg_bbp_unarchive_post' === $action ) {
+ bbp_add_error( 'wporg_bbp_unarchive_post', __( '<strong>ERROR</strong>: There was a problem unarchiving that post!', 'wporg-forums' ) );
+ }
+ }
+
+ public function add_post_status_to_query( $args = array() ) {
+ if ( bbp_get_view_all() ) {
+ $post_stati = explode( ',', $args['post_status'] );
+ $post_stati[] = self::ARCHIVED;
+ $args['post_status'] = implode( ',', $post_stati );
+ }
+ return $args;
+ }
+
+ public function admin_links( $r, $post_id ) {
+ $r['archive'] = $this->get_archive_link( array( 'post_id' => $post_id ) );
+ return $r;
+ }
+
+ public function get_archive_link( $args = array() ) {
+ if ( ! current_user_can( 'moderate' ) ) {
+ return false;
+ }
+ $user_id = get_current_user_id();
+
+ $r = bbp_parse_args( $args, array(
+ 'post_id' => get_the_ID(),
+ 'archive' => esc_html__( 'Archive', 'wporg-forums' ),
+ 'unarchive' => esc_html__( 'Unarchive', 'wporg-forums' ),
+ ), 'get_post_archive_link' );
+ if ( empty( $r['post_id'] ) ) {
+ return false;
+ }
+ $post_id = $r['post_id'];
+
+ $post = get_post( $post_id );
+ if ( ! $post ) {
+ return false;
+ }
+
+ if ( $this->is_post_archived( $post->ID ) ) {
+ $text = $r['unarchive'];
+ $query_args = array( 'action' => 'wporg_bbp_unarchive_post', 'post_id' => $post->ID );
+ } else {
+ $text = $r['archive'];
+ $query_args = array( 'action' => 'wporg_bbp_archive_post', 'post_id' => $post->ID );
+ }
+
+ $permalink = $this->get_permalink( $post->ID );
+
+ $url = esc_url( wp_nonce_url( add_query_arg( $query_args, $permalink ), 'toggle-post-archive_' . $user_id . '_' . $post->ID ) );
+ return sprintf( "<a href='%s'>%s</a>", $url, esc_html( $text ) );
+ }
+
+ public function is_post_archived( $post_id ) {
+ $post = get_post( $post_id );
+ if ( ! $post ) {
+ return false;
+ }
+
+ return $post->post_status == self::ARCHIVED;
+ }
+
+ public function archive_post( $post_id ) {
+ if ( empty( $post_id ) ) {
+ return false;
+ }
+
+ $post = get_post( $post_id );
+ if ( ! $post ) {
+ return false;
+ }
+
+ if ( ! $this->is_post_archived( $post->ID ) ) {
+ $post_id = wp_update_post( array(
+ 'ID' => $post->ID,
+ 'post_status' => self::ARCHIVED,
+ ), true );
+ if ( $post_id ) {
+ update_post_meta( $post->ID, self::ARCHIVED_META, $post->post_status );
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function unarchive_post( $post_id ) {
+ if ( empty( $post_id ) ) {
+ return false;
+ }
+
+ $post = get_post( $post_id );
+ if ( ! $post ) {
+ return false;
+ }
+
+ if ( $this->is_post_archived( $post->ID ) ) {
+ $post_status = get_post_meta( $post->ID, self::ARCHIVED_META, true );
+ if ( ! $post_status ) {
+ $post_status = self::DEFAULT_STATUS;
+ }
+ $post_id = wp_update_post( array(
+ 'ID' => $post->ID,
+ 'post_status' => $post_status,
+ ) );
+ if ( $post_id ) {
+ delete_post_meta( $post->ID, self::ARCHIVED_META );
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public function get_permalink( $post_id ) {
+ if ( empty( $post_id ) ) {
+ return false;
+ }
+
+ $post = get_post( $post_id );
+ if ( ! $post ) {
+ return false;
+ }
+
+ switch ( $post->post_type ) {
+ case 'topic' :
+ $permalink = bbp_get_topic_permalink( $post->ID );
+ break;
+ case 'reply' :
+ $permalink = bbp_get_topic_permalink( bbp_get_reply_topic_id( $post->ID ) );
+ break;
+ case 'post' :
+ default :
+ $permalink = get_permalink( $post->ID );
+ }
+
+ return $permalink;
+ }
+
+ public function get_valid_actions() {
+ return array(
+ 'wporg_bbp_archive_post',
+ 'wporg_bbp_unarchive_post',
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>