<!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>[3666] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution: Support: Topic Resolution initial commit.</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/3666">3666</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/3666","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-07-11 13:46:28 +0000 (Mon, 11 Jul 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: Topic Resolution initial commit.</pre>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/inc/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbptopicresolutionincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/inc/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbptopicresolutionwporgbbptopicresolutionphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/wporg-bbp-topic-resolution.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbptopicresolutionincclasspluginphp"></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/wporg-bbp-topic-resolution/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/wporg-bbp-topic-resolution/inc/class-plugin.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/inc/class-plugin.php    2016-07-11 13:46:28 UTC (rev 3666)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,270 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Forums\Topic_Resolution;
+
+class Plugin {
+
+       /**
+        * @todo Views: yes/no/mu -- all available for all enabled forums
+        * @todo Edit enabled forums - will need to be updateable from the admin interface for administrators during forum setup
+        * @todo Add topic title filter
+        * Decisions: default topic resolution is 'no'
+        */
+
+       /**
+        * @var Plugin The singleton instance.
+        */
+       private static $instance;
+
+       const META_KEY = 'topic_resolved';
+
+       /**
+        * Always return the same instance of this plugin.
+        *
+        * @return Plugin
+        */
+       public static function get_instance() {
+               if ( ! ( self::$instance instanceof Plugin ) ) {
+                       self::$instance = new Plugin();
+               }
+               return self::$instance;
+       }
+
+       /**
+        * Instantiates a new Plugin object.
+        */
+       private function __construct() {
+               add_action( 'bbp_loaded', array( $this, 'bbp_loaded' ) );
+       }
+
+       /**
+        * Initializes the plugin.
+        */
+       public function bbp_loaded() {
+               // Display the form depending on context
+               add_action( 'bbp_theme_before_topic_form_content', array( $this, 'form_topic_resolution_dropdown' ) );
+               add_action( 'bbp_theme_before_topic_form_subscriptions', array( $this, 'form_topic_resolution_checkbox' ) );
+
+               // Process field submission
+               add_action( 'bbp_new_topic_post_extras', array( $this, 'topic_post_extras' ) );
+               add_action( 'bbp_edit_topic_post_extras', array( $this, 'topic_post_extras' ) );
+
+               // Admin interface for enabling on forums
+               add_filter( 'manage_forum_posts_columns', array( $this, 'add_forum_topic_resolution_column' ), 11 );
+               add_action( 'manage_forum_posts_custom_column', array( $this, 'add_forum_topic_resolution_value' ), 10, 2 );
+
+               // Process field submission
+               // @todo Bulk actions aren't filterable, so this might be hacky.
+       }
+
+       /**
+        * Output topic resolution selection dropdown.
+        */
+       public function form_topic_resolution_dropdown() {
+               // Only display on forums where this is enabled
+               if ( ! $this->is_enabled_on_forum() ) {
+                       return;
+               }
+
+               // Only display on topic edits
+               if ( ! bbp_is_topic_edit() ) {
+                       return;
+               }
+
+               $resolutions = $this->get_topic_resolutions();
+
+               // Post value passed
+               if ( bbp_is_topic_form_post_request() && isset( $_POST[ self::META_KEY ] ) ) {
+                       $resolution = $this->sanitize_topic_resolution( $_POST[ self::META_KEY ] );
+
+               // No post value passed
+               } else if ( bbp_is_single_topic() || bbp_is_topic_edit() ) {
+                       $resolution = $this->get_topic_resolution( array( 'id' => bbp_get_topic_id() ) );
+               }
+
+               if ( empty( $resolution ) ) {
+                       $resolution = $this->get_default_topic_resolution();
+               }
+               ?>
+               <p><label for="<?php echo esc_attr( self::META_KEY ); ?>"><?php echo esc_html( __( 'This topic is', 'wporg' ) ); ?></label><br />
+
+               <select name="<?php echo esc_attr( self::META_KEY ); ?>" id="topic-resolved">
+
+               <?php foreach ( $resolutions as $key => $label ) : ?>
+
+                       <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $resolution ); ?>><?php echo esc_html( $label ); ?></option>
+
+               <?php endforeach; ?>
+
+               </select></p>
+               <?php
+       }
+
+       /**
+        * Output topic resolution checkbox for non-support topics.
+        */
+       public function form_topic_resolution_checkbox() {
+               // Only display on forums where this is enabled
+               if ( ! $this->is_enabled_on_forum() ) {
+                       return;
+               }
+
+               // Only display on new topics
+               if ( bbp_is_topic_edit() ) {
+                       return;
+               }
+               ?>
+               <p><label for="<?php echo esc_attr( self::META_KEY ); ?>"><input type="checkbox" name="<?php echo esc_attr( self::META_KEY ); ?>" id="topic-resolved" value="mu"> <?php echo esc_html( __( 'This topic is not a support question' ) ); ?></label></p>
+               <?php
+       }
+
+       /**
+        * Process topic form submission.
+        */
+       public function topic_post_extras( $topic_id ) {
+               // Only set a topic resolution on forums where this is enabled
+               if ( ! $this->is_enabled_on_forum( bbp_get_topic_forum_id( $topic_id ) ) ) {
+                       return;
+               }
+
+               $resolution = $this->get_default_topic_resolution();
+               if ( isset( $_POST[ self::META_KEY ] ) ) {
+                       $resolution = $this->sanitize_topic_resolution( $_POST[ self::META_KEY ] );
+               }
+
+               $this->set_topic_resolution( array(
+                       'id'         => $topic_id,
+                       'resolution' => $resolution,
+               ) );
+       }
+
+       public function add_forum_topic_resolution_column( $columns ) {
+               return array_merge( $columns, array(
+                       'bbp_topic_resolution' => __( 'Support', 'wporg' ),
+               ) );
+       }
+
+       public function add_forum_topic_resolution_value( $column, $forum_id ) {
+               if ( $column === 'bbp_topic_resolution' && $this->is_enabled_on_forum( $forum_id ) ) {
+                       ?>
+                       <span class="dashicons dashicons-yes"></span>
+                       <?php
+               }
+       }
+
+       public function is_enabled_on_forum( $forum_id = 0 ) {
+               // @todo Make this actually check the option; for testing, 'true' is okay
+               return true;
+
+               $forum = bbp_get_forum( $forum_id );
+               if ( empty( $forum ) ) {
+                       return;
+               }
+
+               $enabled = $this->get_enabled_forums();
+               if ( $enabled && in_array( $forum_id, $enabled ) ) {
+                       return true;
+               }
+               return false;
+       }
+
+       public function get_enabled_forums() {
+               $retval = get_option( '_bbp_topic_resolution_enabled', array() );
+               return apply_filters( 'wporg_bbp_get_enabled_forums', $retval );
+       }
+
+       public function enable_on_forum( $forum_id = 0 ) {
+               $forum = bbp_get_forum( $forum_id );
+               if ( empty( $forum ) ) {
+                       return;
+               }
+
+               if ( ! $this->is_enabled_on_forum( $forum_id ) ) {
+                       $enabled = $this->get_enabled_forums();
+                       $enabled[] = $forum_id;
+                       update_option( '_bbp_topic_resolution_enabled', array_values( $enabled ) );
+               }
+       }
+
+       public function disable_on_forum( $forum_id = 0 ) {
+               $forum = bbp_get_forum( $forum_id );
+               if ( empty( $forum ) ) {
+                       return;
+               }
+
+               if ( $this->is_enabled_on_forum( $forum_id ) ) {
+                       $enabled = $this->get_enabled_forums();
+                       $enabled = array_diff( $enabled, array( $forum_id ) );
+                       update_option( '_bbp_topic_resolution_enabled', array_values( $enabled ) );
+               }
+       }
+
+       public function get_topic_resolution( $args = array() ) {
+               // Parse arguments against default values
+               $r = bbp_parse_args( $args, array(
+                       'id' => 0,
+               ), 'get_topic_resolution' );
+
+               $topic = bbp_get_topic( $r['id'] );
+
+               if ( empty( $topic ) ) {
+                       return;
+               }
+
+               // Only return a value on forums where this is enabled
+               if ( ! $this->is_enabled_on_forum( bbp_get_topic_forum_id( $topic->ID ) ) ) {
+                       return;
+               }
+
+               $retval = get_post_meta( $topic->ID, self::META_KEY, true );
+               return apply_filters( 'wporg_bbp_get_topic_resolution', $retval, $r, $args );
+       }
+
+       public function set_topic_resolution( $args = array() ) {
+               // Parse arguments against default values
+               $r = bbp_parse_args( $args, array(
+                       'id'         => 0,
+                       'resolution' => '',
+               ), 'set_topic_resolution' );
+
+               $topic = bbp_get_topic( $r['id'] );
+
+               if ( empty( $topic ) ) {
+                       return;
+               }
+
+               // Only run this on forums where this is enabled
+               if ( ! $this->is_enabled_on_forum( bbp_get_topic_forum_id( $topic->ID ) ) ) {
+                       return;
+               }
+
+               $resolution = $this->sanitize_topic_resolution( $r['resolution'] );
+
+               update_post_meta( $r['id'], self::META_KEY, $resolution );
+       }
+
+       public function get_topic_resolutions() {
+               return apply_filters( 'wporg_bbp_get_topic_resolutions', array(
+                               'no'  => __( 'not resolved', 'wporg' ),
+                               'yes' => __( 'resolved', 'wporg' ),
+                               'mu'  => __( 'not a support question', 'wporg' ),
+               ) );
+       }
+
+       public function get_default_topic_resolution() {
+               $retval = get_option( '_bbp_default_topic_resolution' );
+               if ( false == $retval ) {
+                       $retval = 'no';
+               }
+               return apply_filters( 'wporg_bbp_default_topic_resolution', $retval );
+       }
+
+       public function sanitize_topic_resolution( $resolution ) {
+               if ( array_key_exists( $resolution, $this->get_topic_resolutions() ) ) {
+                       $retval = $resolution;
+               } else {
+                       $retval = $this->get_default_topic_resolution();
+               }
+               return apply_filters( 'wporg_bbp_sanitize_topic_resolution', $retval );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/inc/class-plugin.php
</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_htmlwpcontentpluginswporgbbptopicresolutionwporgbbptopicresolutionphp"></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/wporg-bbp-topic-resolution/wporg-bbp-topic-resolution.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/wporg-bbp-topic-resolution/wporg-bbp-topic-resolution.php                                (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/wporg-bbp-topic-resolution.php  2016-07-11 13:46:28 UTC (rev 3666)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,31 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Plugin Name: bbPress: Topic Resolution
+ * Description: Display a topic resolution on new/edit topic forms.
+ * Version:     1.0
+ * Author:      WordPress.org
+ * Author URI:  http://wordpress.org/
+ * License:     GPLv2 or later
+ *
+ * Based on Support Forum 3.0.6 by Aditya Naik and Sam Bauers.
+ *
+ *
+ */
+
+
+
+namespace WordPressdotorg\Forums\Topic_Resolution;
+
+// Store the root plugin file for usage with functions which use the plugin basename
+define( __NAMESPACE__ . '\PLUGIN_FILE', __FILE__ );
+
+// Includes
+include( dirname( __FILE__ ) . '/inc/class-plugin.php' );
+
+// Instantiate the Plugin
+Plugin::get_instance();
+
+// Easy access for templates
+function get_topic_resolution( $topic_id ) {
+       return Plugin::get_topic_resolution( array( 'id' => $topic_id ) );
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-topic-resolution/wporg-bbp-topic-resolution.php
</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></div>

</body>
</html>