<!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>[3613] sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown: Support: bbPress Version Dropdown 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/3613">3613</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/3613","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-01 16:50:15 +0000 (Fri, 01 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: bbPress Version Dropdown initial commit.

See <a href="http://meta.trac.wordpress.org/ticket/1544">#1544</a>.</pre>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/inc/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpversiondropdownincclasspluginphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/inc/class-plugin.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpversiondropdownwporgbbpversiondropdownjs">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/wporg-bbp-version-dropdown.js</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpversiondropdownwporgbbpversiondropdownphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/wporg-bbp-version-dropdown.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpversiondropdownincclasspluginphp"></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-version-dropdown/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-version-dropdown/inc/class-plugin.php                          (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/inc/class-plugin.php    2016-07-01 16:50:15 UTC (rev 3613)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,163 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordPressdotorg\Forums\Version_Dropdown;
+
+class Plugin {
+
+       /**
+        * @var Plugin The singleton instance.
+        */
+       private static $instance;
+
+       const META_KEY = 'wp_version';
+
+       /**
+        * Returns always 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
+               add_action( 'bbp_theme_before_topic_form_content', array( $this, 'form_topic_version_dropdown' ) );
+
+               // 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' ) );
+
+               // Scripts and styles
+               add_action( 'bbp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
+       }
+
+       /**
+        * Output value topic version dropdown
+        */
+       public function form_topic_version_dropdown() {
+               $version = 0;
+               $versions = $this->get_wp_versions();
+
+               // Post value passed
+               if ( bbp_is_topic_form_post_request() && isset( $_POST[ self::META_KEY ] ) ) {
+                       $version = $this->sanitize_wp_version( $_POST[ self::META_KEY ] );
+
+               // No post value passed
+               } else if ( bbp_is_single_topic() || bbp_is_topic_edit() ) {
+                       $version = $this->get_topic_version( array( 'id' => bbp_get_topic_id() ) );
+                       if ( false === $version ) {
+                               $version = 0;
+                       }
+               }
+
+               if ( ! empty( $version ) && ! array_key_exists( $version, $versions ) ) {
+                       $other_version = $version;
+                       $version = 'other';
+               }
+               ?>
+               <p><label for="<?php echo esc_attr( self::META_KEY ); ?>"><?php echo esc_html( __('Version', 'wporg') ); ?></label><br />
+
+               <select name="<?php echo esc_attr( self::META_KEY ); ?>" id="wp-version">
+
+               <?php foreach ( $versions as $key => $label ) : ?>
+
+                       <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $key, $version ); ?>><?php echo esc_html( $label ); ?></option>
+
+               <?php endforeach; ?>
+
+               </select> <?php esc_html( __( 'Select the version of WordPress you are using', 'wporg' ) ); ?>
+
+               <label for="wp-other-version"><?php echo esc_html( __( 'Enter a different WordPress version here:', 'wporg' ) ); ?></label>
+
+               <input type="text" name="wp_other_version" id="wp-other-version" value="<?php echo esc_attr( $other_version ); ?>"></p>
+               <?php
+       }
+
+       public function topic_post_extras( $topic_id ) {
+               $version = false;
+               $versions = $this->get_wp_versions();
+               if ( ( $_POST[ self::META_KEY ] ) && in_array( $_POST[ self::META_KEY ], $versions ) ) {
+                       $version = $this->sanitize_wp_version( $_POST[ self::META_KEY ] );
+               } else if ( isset( $_POST['wp_other_version'] ) ) {
+                       $version = $this->sanitize_wp_version( $_POST['wp_other_version'] );
+               }
+
+               if ( false !== $version ) {
+                       $this->set_topic_version( array(
+                               'id' => $topic_id,
+                               'version' => $version
+                       ) );
+               }
+       }
+
+       public function enqueue_scripts() {
+               if ( bbp_is_single_forum() || bbp_is_single_topic() || bbp_is_topic_edit() ) {
+                       wp_enqueue_script( 'wporg-bbp-version-dropdown', plugins_url( 'wporg-bbp-version-dropdown.js', dirname( __FILE__ ) ), array( 'jquery' ) );
+               }
+       }
+
+       public function get_topic_version( $args = array() ) {
+
+               // Parse arguments against default values
+               $r = bbp_parse_args( $args, array(
+                       'id' => 0,
+               ), 'get_topic_version' );
+
+               $topic = bbp_get_topic( $r['id'] );
+
+               if ( empty( $topic ) ) {
+                       return;
+               }
+
+               $retval = get_post_meta( $topic->ID, self::META_KEY, true );
+               return apply_filters( 'get_topic_version', $retval, $r, $args );
+       }
+
+       public function set_topic_version( $args = array() ) {
+
+               // Parse arguments against default values
+               $r = bbp_parse_args( $args, array(
+                       'id'      => 0,
+                       'version' => '',
+               ), 'set_topic_version' );
+
+               $topic = bbp_get_topic( $r['id'] );
+
+               if ( empty( $topic ) ) {
+                       return;
+               }
+
+               if ( empty( $r['version'] ) ) {
+                       delete_post_meta( $r['id'], self::META_KEY );
+               } else {
+                       update_post_meta( $r['id'], self::META_KEY, $r['version'] );
+               }
+       }
+
+       public function get_wp_versions() {
+               $versions = array_merge(
+                       array( '0' => '' ),
+                       apply_filters( 'get_wp_versions', array() ),
+                       array( 'other' => __( 'Other:', 'wporg' ) )
+               );
+               return $versions;
+       }
+
+       public function sanitize_wp_version( $version ) {
+               return preg_replace( '#[^0-9a-z.-]#i', '', $version );
+       }
+}
</ins><span class="cx" style="display: block; padding: 0 10px">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/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_htmlwpcontentpluginswporgbbpversiondropdownwporgbbpversiondropdownjs"></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-version-dropdown/wporg-bbp-version-dropdown.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/wporg-bbp-version-dropdown/wporg-bbp-version-dropdown.js                         (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/wporg-bbp-version-dropdown.js   2016-07-01 16:50:15 UTC (rev 3613)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,11 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+jQuery( function($) {
+       versionChanger = $( '#wp-other-version' ).hide();
+       $( '#wp-version' ).on( 'change', function() {
+               if ( 'other' == $(this).val() ) {
+                       versionChanger.show().focus();
+               } else {
+                       versionChanger.hide();
+                       this.focus();
+               }
+       } ).change();
+} );
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswporgbbpversiondropdownwporgbbpversiondropdownphp"></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-version-dropdown/wporg-bbp-version-dropdown.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-version-dropdown/wporg-bbp-version-dropdown.php                                (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-bbp-version-dropdown/wporg-bbp-version-dropdown.php  2016-07-01 16:50:15 UTC (rev 3613)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,25 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Plugin Name: bbPress: Version Dropdown
+ * Description: Display a WordPress version dropdown on new/edit topic forms.
+ * Version:     2.0
+ * Author:      WordPress.org
+ * Author URI:  http://wordpress.org/
+ * License:     GPLv2 or later
+ */
+
+namespace WordPressdotorg\Forums\Version_Dropdown;
+
+// 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_version( $topic_id ) {
+       return Plugin::get_topic_version( 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-version-dropdown/wporg-bbp-version-dropdown.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>