<!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>[623] sites/trunk/wordcamp.org/public_html/wp-content/plugins: Multi Event Sponsors: 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">
<dt>Revision</dt> <dd><a href="http://meta.trac.wordpress.org/changeset/623">623</a></dd>
<dt>Author</dt> <dd>iandunn</dd>
<dt>Date</dt> <dd>2014-05-20 20:09:47 +0000 (Tue, 20 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Multi Event Sponsors: Initial Commit.</pre>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsbootstrapphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/bootstrap.php</a></li>
<li>sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsclassesmessponsorphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsor.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsclassesmessponsorshiplevelphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsorship-level.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsclassesmultieventsponsorsphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/multi-event-sponsors.php</a></li>
<li>sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsviewsmetaboxcontributionperattendeephp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-contribution-per-attendee.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsviewsmetaboxregionalsponsorshipsphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-regional-sponsorships.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsviewsshortcodemultieventsponsorsphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/shortcode-multi-event-sponsors.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsbootstrapphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/bootstrap.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/bootstrap.php                               (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/bootstrap.php  2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,22 @@
</span><ins>+<?php
+/*
+Plugin Name: Multi-Event Sponsors
+Description: Store and display data on Multi-Event Sponsors
+Version:     0.1
+Author:      WordCamp Central
+Author URI:  http://wordcamp.org
+*/
+
+if ( ! defined( 'ABSPATH' ) ) {
+       die( 'Access denied.' );
+}
+
+require_once( __DIR__ . '/classes/multi-event-sponsors.php' );
+require_once( __DIR__ . '/classes/mes-sponsor.php' );
+require_once( __DIR__ . '/classes/mes-sponsorship-level.php' );
+
+$GLOBALS['multi_event_sponsors']  = new Multi_Event_Sponsors();
+$GLOBALS['mes_sponsor']           = new MES_Sponsor();
+$GLOBALS['mes_sponsorship_level'] = new MES_Sponsorship_Level();
+
+register_activation_hook( __FILE__, array( $GLOBALS['multi_event_sponsors'], 'activate' ) );
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsclassesmessponsorphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsor.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsor.php                             (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsor.php        2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,214 @@
</span><ins>+<?php
+
+/*
+ * Register the Multi-Event Sponsors custom post type and manage all of its functionality
+ *
+ * The use of custom post types and taxonomies for the regions and sponsorships levels is a little questionable,
+ * since neither fits perfectly. In an abstract sense, they're taxonomies, but they map between terms for a given post,
+ * rather than mapping terms to posts directly. Also, the sponsorship levels have extra meta data associated with them.
+ *
+ * So, a custom taxonomy is used for regions, and a custom post type is used for sponsorship levels, and then meta data
+ * is used on each sponsor post to map each region to a sponsorship level.
+ */
+
+class MES_Sponsor {
+       const POST_TYPE_SLUG     = 'mes';
+       const REGIONS_SLUG       = 'mes-regions';
+       
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               add_action( 'init',                                   array( $this, 'create_post_type' ) );
+               add_action( 'init',                                   array( $this, 'create_taxonomies' ) );
+               add_action( 'add_meta_boxes_' . self::POST_TYPE_SLUG, array( $this, 'remove_meta_boxes' ) );
+               add_action( 'admin_init',                             array( $this, 'add_meta_boxes' ) );
+               add_action( 'save_post',                              array( $this, 'save_post' ), 10, 2 );
+               add_filter( 'the_content',                            array( $this, 'add_header_footer_text' ) );
+       }
+
+       /**
+        * Registers the custom post type
+        */
+       public function create_post_type() {
+               if ( post_type_exists( self::POST_TYPE_SLUG ) ) {
+                       return;
+               }
+
+               $labels = array(
+                       'name'               => __( 'Multi-Event Sponsors',                   'wordcamporg' ),
+                       'singular_name'      => __( 'Multi-Event Sponsor',                    'wordcamporg' ),
+                       'add_new'            => __( 'Add New',                                'wordcamporg' ),
+                       'add_new_item'       => __( 'Add New Multi-Event Sponsor',            'wordcamporg' ),
+                       'edit'               => __( 'Edit',                                   'wordcamporg' ),
+                       'edit_item'          => __( 'Edit Multi-Event Sponsor',               'wordcamporg' ),
+                       'new_item'           => __( 'New Multi-Event Sponsor',                'wordcamporg' ),
+                       'view'               => __( 'View Multi-Event Sponsors',              'wordcamporg' ),
+                       'view_item'          => __( 'View Multi-Event Sponsor',               'wordcamporg' ),
+                       'search_items'       => __( 'Search Multi-Event Sponsors',            'wordcamporg' ),
+                       'not_found'          => __( 'No Multi-Event Sponsors found',          'wordcamporg' ),
+                       'not_found_in_trash' => __( 'No Multi-Event Sponsors found in Trash', 'wordcamporg' ),
+                       'parent'             => __( 'Parent Multi-Event Sponsor',             'wordcamporg' ),
+               );
+
+               $post_type_params = array(
+                       'labels'          => $labels,
+                       'singular_label'  => __( 'Multi-Event Sponsor', 'wordcamporg' ),
+                       'public'          => true,
+                       'menu_position'   => 20,
+                       'hierarchical'    => false,
+                       'capability_type' => 'page',
+                       'has_archive'     => true,
+                       'rewrite'         => array( 'slug' => 'multi-event-sponsor' ),
+                       'query_var'       => true,
+                       'supports'        => array( 'title', 'editor', 'author', 'revisions', 'thumbnail' ),
+                       'taxonomies'      => array( self::REGIONS_SLUG ),
+               );
+
+               register_post_type( self::POST_TYPE_SLUG, $post_type_params );
+       }
+
+       /**
+        * Registers the category taxonomy
+        */
+       public function create_taxonomies() {
+               $region_params = array(
+                       'label'                 => __( 'Region', 'wordcamporg' ),
+                       'labels'                => array(
+                               'name'          => __( 'Regions', 'wordcamporg' ),
+                               'singular_name' => __( 'Region', 'wordcamporg' )
+                       ),
+                       'hierarchical'          => true,
+                       'rewrite'               => array( 'slug' => self::REGIONS_SLUG ),
+               );
+
+               if ( ! taxonomy_exists( self::REGIONS_SLUG ) ) {
+                       register_taxonomy( self::REGIONS_SLUG, self::POST_TYPE_SLUG, $region_params );
+               }
+       }
+
+       /**
+        * Adds meta boxes for the custom post type
+        */
+       public function add_meta_boxes() {
+               add_meta_box(
+                       'mes_regional_sponsorships',
+                       __( 'Regional Sponsorships', 'wordcamporg' ),
+                       array( $this, 'markup_meta_boxes' ),
+                       self::POST_TYPE_SLUG,
+                       'normal',
+                       'core'
+               );
+       }
+
+       /**
+        * Remove the taxonomy meta boxes, since we don't assign them directly.
+        *
+        * @param WP_Post $post
+        */
+       public function remove_meta_boxes( $post ) {
+               remove_meta_box( 'mes-regionsdiv', null, 'side' );
+       }
+
+       /**
+        * Builds the markup for all meta boxes
+        *
+        * @param WP_Post $post
+        * @param array   $box
+        */
+       public function markup_meta_boxes( $post, $box ) {
+               /** @var $view string */
+
+               switch ( $box['id'] ) {
+                       case 'mes_regional_sponsorships':
+                               $regions               = get_terms( self::REGIONS_SLUG, array( 'hide_empty' => false ) );
+                               $sponsorship_levels    = get_posts( array( 'post_type' => MES_Sponsorship_Level::POST_TYPE_SLUG, 'numberposts' => -1 ) );
+                               $regional_sponsorships = $this->populate_default_regional_sponsorships( get_post_meta( $post->ID, 'mes_regional_sponsorships', true ), $regions );
+                               $view                  = 'metabox-regional-sponsorships.php';
+                               break;
+               }
+
+               require_once( dirname( __DIR__ ) . '/views/'. $view );
+       }
+
+       /**
+        * Populate the regional sponsorships array with default values.
+        *
+        * This helps to avoid any PHP notices from trying to access undefined indices.
+        *
+        * @param array $regional_sponsorships
+        * @param array $regions
+        * @return array
+        */
+       protected function populate_default_regional_sponsorships( $regional_sponsorships, $regions ) {
+               $region_ids = wp_list_pluck( $regions, 'term_id' );
+
+               foreach ( $region_ids as $region_id ) {
+                       if ( empty ( $regional_sponsorships[ $region_id ] ) ) {
+                               $regional_sponsorships[ $region_id ] = 'null';
+                       }
+               }
+
+               return $regional_sponsorships;
+       }
+
+       /**
+        * Save the post data
+        *
+        * @param int     $post_id
+        * @param WP_Post $post
+        */
+       public function save_post( $post_id, $post ) {
+               $ignored_actions = array( 'trash', 'untrash', 'restore' );
+
+               if ( isset( $_GET['action'] ) && in_array( $_GET['action'], $ignored_actions ) ) {
+                       return;
+               }
+
+               if ( ! $post || $post->post_type != self::POST_TYPE_SLUG || ! current_user_can( 'edit_post', $post_id ) ) {
+                       return;
+               }
+
+               if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || $post->post_status == 'auto-draft' ) {
+                       return;
+               }
+
+               $this->save_post_meta( $post_id, $_POST );
+       }
+
+       /**
+        * Save the post's meta fields
+        *
+        * @param int   $post_id
+        * @param array $new_values
+        */
+       protected function save_post_meta( $post_id, $new_values ) {
+               if ( isset( $new_values[ 'mes_regional_sponsorships' ] ) ) {
+                       array_walk( $new_values[ 'mes_regional_sponsorships' ], 'absint' );
+                       update_post_meta( $post_id, 'mes_regional_sponsorships', $new_values[ 'mes_regional_sponsorships' ] );
+               } else {
+                       delete_post_meta( $post_id, 'mes_regional_sponsorships' );
+               }
+       }
+
+       /**
+        * Add the header and footer copy to the sponsorship level content
+        *
+        * @param string $content
+        * @return string
+        */
+       public function add_header_footer_text( $content ) {
+               global $post;
+
+               if ( ! empty ( $post->post_type ) && self::POST_TYPE_SLUG == $post->post_type ) {
+                       $content = sprintf(
+                               '<p>Here’s the company description for %s for your website:</p>
+                               <div>%s</div>',
+                               $post->post_title,
+                               $content
+                       );
+               }
+
+               return $content;
+       }
+} // end MES_Sponsor
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsclassesmessponsorshiplevelphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsorship-level.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsorship-level.php                           (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/mes-sponsorship-level.php      2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,159 @@
</span><ins>+<?php
+
+/*
+ * Register the Sponsorship Levels custom post type and manage all of its functionality
+ *
+ * See note in MES_Sponsor class documentation on the use of custom post types and taxonomies for regions and
+ * sponsorship levels.
+ */
+
+class MES_Sponsorship_Level {
+       const POST_TYPE_SLUG = 'mes-sponsor-level';
+       
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               add_action( 'init',        array( $this, 'create_post_type' ) );
+               add_action( 'admin_init',  array( $this, 'add_meta_boxes' ) );
+               add_action( 'save_post',   array( $this, 'save_post' ), 10, 2 );
+               add_filter( 'the_content', array( $this, 'add_header_footer_text' ) );
+       }
+
+       /**
+        * Registers the custom post type
+        */
+       public function create_post_type() {
+               if ( post_type_exists( self::POST_TYPE_SLUG ) ) {
+                       return;
+               }
+
+               $labels = array(
+                       'name'               => __( 'Sponsorship Levels',                   'wordcamporg' ),
+                       'singular_name'      => __( 'Sponsorship Level',                    'wordcamporg' ),
+                       'add_new'            => __( 'Add New',                              'wordcamporg' ),
+                       'add_new_item'       => __( 'Add New Sponsorship Level',            'wordcamporg' ),
+                       'edit'               => __( 'Edit',                                 'wordcamporg' ),
+                       'edit_item'          => __( 'Edit Sponsorship Level',               'wordcamporg' ),
+                       'new_item'           => __( 'New Sponsorship Level',                'wordcamporg' ),
+                       'view'               => __( 'View Sponsorship Levels',              'wordcamporg' ),
+                       'view_item'          => __( 'View Sponsorship Level',               'wordcamporg' ),
+                       'search_items'       => __( 'Search Sponsorship Levels',            'wordcamporg' ),
+                       'not_found'          => __( 'No Sponsorship Levels found',          'wordcamporg' ),
+                       'not_found_in_trash' => __( 'No Sponsorship Levels found in Trash', 'wordcamporg' ),
+                       'parent'             => __( 'Parent Sponsorship Level',             'wordcamporg' ),
+               );
+
+               $post_type_params = array(
+                       'labels'          => $labels,
+                       'singular_label'  => __( 'Sponsorship Level', 'wordcamporg' ),
+                       'public'          => true,
+                       'show_in_menu'    => 'edit.php?post_type=' . MES_Sponsor::POST_TYPE_SLUG,
+                       'menu_position'   => 20,
+                       'hierarchical'    => false,
+                       'capability_type' => 'page',
+                       'has_archive'     => true,
+                       'rewrite'         => array( 'slug' => 'sponsorship-level' ),
+                       'query_var'       => true,
+                       'supports'        => array( 'title', 'editor', 'author', 'revisions' ),
+                       'taxonomies'      => array( MES_Sponsor::REGIONS_SLUG ),
+               );
+
+               register_post_type( self::POST_TYPE_SLUG, $post_type_params );
+       }
+
+       /**
+        * Adds meta boxes for the custom post type
+        */
+       public function add_meta_boxes() {
+               add_meta_box(
+                       'mes_contribution_per_attendee',
+                       __( 'Contribution Per Attendee', 'wordcamporg' ),
+                       array( $this, 'markup_meta_boxes' ),
+                       self::POST_TYPE_SLUG,
+                       'side',
+                       'low'
+               );
+       }
+
+       /**
+        * Builds the markup for all meta boxes
+        *
+        * @param WP_Post $post
+        * @param array   $box
+        */
+       public function markup_meta_boxes( $post, $box ) {
+               /** @var $view string */
+
+               switch ( $box['id'] ) {
+                       case 'mes_contribution_per_attendee':
+                               $contribution_per_attendee = (float) get_post_meta( $post->ID, 'mes_contribution_per_attendee', true );
+                               $view                      = 'metabox-contribution-per-attendee.php';
+                               break;
+               }
+
+               require_once( dirname( __DIR__ ) . '/views/'. $view );
+       }
+
+       /**
+        * Save the post data
+        *
+        * @param int     $post_id
+        * @param WP_Post $post
+        */
+       public function save_post( $post_id, $post ) {
+               $ignored_actions = array( 'trash', 'untrash', 'restore' );
+
+               if ( isset( $_GET['action'] ) && in_array( $_GET['action'], $ignored_actions ) ) {
+                       return;
+               }
+
+               if ( ! $post || $post->post_type != self::POST_TYPE_SLUG || ! current_user_can( 'edit_post', $post_id ) ) {
+                       return;
+               }
+
+               if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || $post->post_status == 'auto-draft' ) {
+                       return;
+               }
+
+               $this->save_post_meta( $post_id, $_POST );
+       }
+
+       /**
+        * Save the post's meta fields
+        *
+        * @param int   $post_id
+        * @param array $new_values
+        */
+       protected function save_post_meta( $post_id, $new_values ) {
+               if ( isset( $new_values[ 'mes_contribution_per_attendee' ] ) ) {
+                       update_post_meta( $post_id, 'mes_contribution_per_attendee', (float) $new_values[ 'mes_contribution_per_attendee' ] );
+               } else {
+                       delete_post_meta( $post_id, 'mes_contribution_per_attendee' );
+               }
+       }
+
+       /**
+        * Add the header and footer copy to the sponsorship level content
+        *
+        * @param string $content
+        * @return string
+        */
+       public function add_header_footer_text( $content ) {
+               global $post;
+
+               if ( ! empty ( $post->post_type ) && self::POST_TYPE_SLUG == $post->post_type ) {
+                       $content = sprintf(
+                               '<p>The sponsorship package associated with the %s sponsorship is:</p>
+                               <div>%s</div>
+                               <p>A %s contributes US $%s per attendee, rounded up to the nearest 50.</p>',
+                               $post->post_title,
+                               $content,
+                               $post->post_title,
+                               number_format_i18n( (float) get_post_meta( $post->ID, 'mes_contribution_per_attendee', true ), 2 )
+                       );
+               }
+
+               return $content;
+       }
+} // end MES_Sponsorship_Level
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsclassesmultieventsponsorsphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/multi-event-sponsors.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/multi-event-sponsors.php                            (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/classes/multi-event-sponsors.php       2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,155 @@
</span><ins>+<?php
+
+/*
+ * Main controller to handle general functionality
+ */
+
+class Multi_Event_Sponsors {
+       const VERSION = '0.1';
+       
+       /**
+        * Constructor
+        */
+       public function __construct() {
+               add_shortcode( 'multi-event-sponsors', array( $this, 'shortcode_multi_event_sponsors' ) );
+       }
+
+       /**
+        * Prepares the site to use the plugin.
+        *
+        * This plugin is only intended to run in single-site mode on central.wordcamp.org.
+        *
+        * @param bool $network_wide
+        */
+       public function activate( $network_wide ) {
+               /** @var $mes_sponsor           MES_Sponsor */
+               /** @var $mes_sponsorship_level MES_Sponsorship_Level */
+
+               global $mes_sponsor, $mes_sponsorship_level;
+
+               $mes_sponsor->create_post_type();
+               $mes_sponsorship_level->create_post_type();
+               flush_rewrite_rules();
+       }
+
+       /**
+        * Render the multi_event_sponsors shortcode output
+        *
+        * @param $parameters
+        * @return string
+        */
+       public function shortcode_multi_event_sponsors( $parameters ) {
+               $sponsors           = $this->reindex_array_by_object_id( get_posts( array( 'post_type' => MES_Sponsor::POST_TYPE_SLUG, 'numberposts' => -1 ) ) );
+               $regions            = $this->reindex_array_by_object_id( get_terms( MES_Sponsor::REGIONS_SLUG, array( 'hide_empty' => false ) ) );
+               $sponsorship_levels = $this->reindex_array_by_object_id( get_posts( array( 'post_type' => MES_Sponsorship_Level::POST_TYPE_SLUG, 'numberposts' => -1 ) ) );
+               $grouped_sponsors   = $this->group_sponsors_by_region_and_level( $sponsors );
+
+               ob_start();
+               require_once( dirname( __DIR__ ) . '/views/shortcode-multi-event-sponsors.php' );
+               return ob_get_clean();
+       }
+
+       /**
+        * Re-indexes an array of posts or terms by their id.
+        *
+        * This makes for efficient direct access when the ID is known.
+        *
+        * @param $array
+        * @return mixed
+        */
+       protected function reindex_array_by_object_id( $old_array ) {
+               $new_array = array();
+
+               foreach ( $old_array as $item ) {
+                       if ( ! empty ( $item->ID ) ) {
+                               $new_array[ $item->ID ] = $item;
+                       } elseif ( ! empty( $item->term_id ) ) {
+                               $new_array[ $item->term_id ] = $item;
+                       }
+               }
+
+               return $new_array;
+       }
+
+       /**
+        * Create a multidimensional array that groups sponsors by region and sponsorship level.
+        *
+        * US East
+        *   WordCamp Pillar
+        *     BlueHost
+        *     Wired Tree
+        *   WordCamp Champion
+        *     Dreamhost
+        * US West
+        *   WordCamp Accomplice
+        *     Disqus
+        * etc
+        *
+        * @param array $sponsors
+        * @param array $regions
+        * @return array
+        */
+       protected function group_sponsors_by_region_and_level( $sponsors ) {
+               $grouped_sponsors = array();
+
+               // Build the grouping
+               foreach ( $sponsors as $sponsor ) {
+                       $regional_sponsorships = get_post_meta( $sponsor->ID, 'mes_regional_sponsorships', true );
+
+                       foreach ( $regional_sponsorships as $region_id => $level_id ) {
+                               if ( 'null' != $level_id ) {
+                                       $grouped_sponsors[ $region_id ][ $level_id ][] = $sponsor->ID;
+                               }
+                       }
+               }
+
+               // Sort the grouping
+               uksort( $grouped_sponsors, array( $this, 'uksort_regions' ) );
+
+               foreach ( $grouped_sponsors as &$region ) {
+                       uksort( $region, array( $this, 'uksort_sponsorship_levels' ) );
+               }
+
+               return $grouped_sponsors;
+       }
+
+       /**
+        * Sort regions by their name
+        *
+        * This is a callback for uksort().
+        *
+        * @param int $region_a_id
+        * @param int $region_b_id
+        * @return int
+        */
+       protected function uksort_regions( $region_a_id, $region_b_id ) {
+               $region_a = get_term( $region_a_id, MES_Sponsor::REGIONS_SLUG );
+               $region_b = get_term( $region_b_id, MES_Sponsor::REGIONS_SLUG );
+
+               if ( $region_a->name == $region_b->name ) {
+                       return 0;
+               } else {
+                       return ( $region_a->name < $region_b->name ) ? -1 : 1;
+               }
+       }
+
+       /**
+        * Sort sponsorship levels by their contribution amount.
+        *
+        * This is a callback for uksort().
+        *
+        * @param int $level_a_id
+        * @param int $level_b_id
+        * @return int
+        */
+       protected function uksort_sponsorship_levels( $level_a_id, $level_b_id ) {
+               $level_a_contribution = (float) get_post_meta( $level_a_id, 'mes_contribution_per_attendee', true );
+               $level_b_contribution = (float) get_post_meta( $level_b_id, 'mes_contribution_per_attendee', true );
+
+               if ( $level_a_contribution == $level_b_contribution ) {
+                       return 0;
+               } else {
+                       return ( $level_a_contribution > $level_b_contribution ) ? -1 : 1;
+               }
+       }
+} // end Multi_Event_Sponsors
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsviewsmetaboxcontributionperattendeephp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-contribution-per-attendee.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-contribution-per-attendee.php                         (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-contribution-per-attendee.php    2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+<?php /** @var $contribution_per_attendee float */ ?>
+
+<label for="mes_contribution_per_attendee"><?php _e( 'Amount:', 'wordcamporg' ); ?></label>
+&nbsp;$<input
+       id="mes_contribution_per_attendee"
+       name="mes_contribution_per_attendee"
+       type="number"
+       step="0.01"
+       value="<?php echo esc_attr( number_format_i18n( $contribution_per_attendee, 2 ) ); ?>"
+       class="small-text"
+/>
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsviewsmetaboxregionalsponsorshipsphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-regional-sponsorships.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-regional-sponsorships.php                             (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/metabox-regional-sponsorships.php        2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+<?php /** @var $regions               array */ ?>
+<?php /** @var $sponsorship_levels    array */ ?>
+<?php /** @var $regional_sponsorships array */ ?>
+
+<table>
+       <thead>
+               <tr>
+                       <th>Region</th>
+                       <th>Sponsorship Level</th>
+               </tr>
+       </thead>
+
+       <tbody>
+               <?php foreach ( $regions as $region ) : ?>
+                       <tr>
+                               <td>
+                                       <label for="mes_regional_sponsorships-<?php echo esc_attr( $region->term_id ); ?>">
+                                               <?php echo esc_html( $region->name ); ?>
+                                       </label>
+                               </td>
+
+                               <td>
+                                       <select id="mes_regional_sponsorships-<?php echo esc_attr( $region->term_id ); ?>" name="mes_regional_sponsorships[<?php echo esc_attr( $region->term_id ); ?>]">
+                                               <option value="null">None</option>
+
+                                               <?php foreach ( $sponsorship_levels as $level ) : ?>
+                                                       <option value="<?php echo esc_attr( $level->ID ); ?>" <?php selected( $regional_sponsorships[ $region->term_id ], $level->ID ); ?>>
+                                                               <?php echo esc_html( $level->post_title ); ?>
+                                                       </option>
+                                               <?php endforeach; ?>
+                                       </select>
+                               </td>
+                       </tr>
+               <?php endforeach; ?>
+       </tbody>
+</table>
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginsmultieventsponsorsviewsshortcodemultieventsponsorsphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/shortcode-multi-event-sponsors.php (0 => 623)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/shortcode-multi-event-sponsors.php                            (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/multi-event-sponsors/views/shortcode-multi-event-sponsors.php       2014-05-20 20:09:47 UTC (rev 623)
</span><span class="lines">@@ -0,0 +1,23 @@
</span><ins>+<?php /** @var $grouped_sponsors   array */ ?>
+<?php /** @var $sponsors           array */ ?>
+<?php /** @var $regions            array */ ?>
+<?php /** @var $sponsorship_levels array */ ?>
+
+<?php foreach ( $grouped_sponsors as $region_id => $levels ) : ?>
+
+       If your WordCamp is in <?php echo esc_html( $regions[ $region_id ]->name ); ?>:
+
+       <ul>
+               <?php foreach( $levels as $level_id => $sponsor_ids ) : ?>
+                       <?php foreach( $sponsor_ids as $sponsor_id ) : ?>
+
+                               <li>
+                                       <a href="<?php echo esc_attr( esc_url( get_permalink( $sponsor_id ) ) ); ?>"><?php echo esc_html( $sponsors[ $sponsor_id ]->post_title ); ?></a> is a
+                                       <a href="<?php echo esc_attr( esc_url( get_permalink( $level_id ) ) ); ?>"><?php echo esc_html( $sponsorship_levels[ $level_id ]->post_title ); ?></a> for your event.
+                               </li>
+
+                       <?php endforeach; ?>
+               <?php endforeach; ?>
+       </ul>
+
+<?php endforeach; ?>
</ins></span></pre>
</div>
</div>

</body>
</html>