<!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>[2442] sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins: CampTix Tweaks: Open-source part of the CampTix Extras plugin.</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/2442">2442</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/2442","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iandunn</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-02-01 23:20:27 +0000 (Mon, 01 Feb 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'>CampTix Tweaks: Open-source part of the CampTix Extras plugin.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginsloadothermupluginsphp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/load-other-mu-plugins.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweakscamptixtweaksphp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php</a></li>
<li>sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweaksviewsnoticesandboxmodephp">sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/notice-sandbox-mode.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweakscamptixtweaksphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php                              (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/camptix-tweaks.php        2016-02-01 23:20:27 UTC (rev 2442)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,352 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\CampTix_Tweaks;
+
+defined( 'WPINC' ) or die();
+
+// Tickets
+add_action( 'camptix_admin_notices',                         __NAMESPACE__ . '\show_sandbox_mode_warning'           );
+add_action( 'init',                                          __NAMESPACE__ . '\hide_empty_tickets'                  );
+add_action( 'wp_print_styles',                               __NAMESPACE__ . '\print_login_message_styles'          );
+add_filter( 'camptix_require_login_please_login_message',    __NAMESPACE__ . '\override_please_login_message'       );
+add_action( 'camptix_form_start_errors',                     __NAMESPACE__ . '\add_form_start_error_messages'       );
+add_action( 'transition_post_status',                        __NAMESPACE__ . '\ticket_sales_opened',          10, 3 );
+
+// Attendees
+add_filter( 'camptix_name_order',                            __NAMESPACE__ . '\set_name_order'         );
+add_action( 'camptix_form_edit_attendee_custom_error_flags', __NAMESPACE__ . '\disable_attendee_edits' );
+
+// Miscellaneous
+add_filter( 'camptix_default_addons',                        __NAMESPACE__ . '\load_addons'            );
+add_filter( 'camptix_capabilities',                          __NAMESPACE__ . '\modify_capabilities'    );
+add_filter( 'camptix_default_options',                       __NAMESPACE__ . '\modify_default_options' );
+
+// todo security audit
+
+/**
+ * Warn organizers when CampTix is in sandbox mode
+ *
+ * If they open ticket sales while in sandbox mode, then attendees will be confused, etc.
+ *
+ * @todo This should probably be moved to CampTix itself, except for the check for the 'wordcamp-sandbox' account,
+ * which can stay here.
+ */
+function show_sandbox_mode_warning() {
+       /** @var $post    \WP_Post        */
+       /** @var $camptix \CampTix_Plugin */
+       global $post, $camptix;
+
+       $camptix_options = $camptix->get_options();
+       $post_types      = array( 'tix_ticket', 'tix_coupon', 'tix_email', 'tix_attendee', 'tix_question' );
+       $current_screen  = get_current_screen();
+
+       if ( ! isset( $camptix_options ) ) {
+               return;
+       }
+
+       $camptix_post_type      = in_array( $current_screen->post_type, $post_types );
+       $camptix_shortcode_page = isset( $post->post_content ) && has_shortcode( $post->post_content, 'camptix' );
+
+       if ( $camptix_post_type || $camptix_shortcode_page ) {
+               $sandbox = false;
+
+               // If any payment addons are in sandbox mode
+               foreach ( $camptix_options as $option_key => $option_value ) {
+                       if ( 'payment_options_' === substr( $option_key, 0, 16 ) ) {
+                               if ( isset( $option_value['sandbox'] ) && true === $option_value['sandbox'] ) {
+                                       $sandbox = true;
+                               }
+                       }
+               }
+
+               // If the WordCamp sandbox is picked from the predefs
+               if ( ! empty( $camptix_options['payment_options_paypal']['api_predef'] ) ) {
+                       if ( 'wordcamp-sandbox' == $camptix_options['payment_options_paypal']['api_predef'] ) {
+                               $sandbox = true;
+                       }
+               }
+
+               // And the event is not archived
+               if ( $sandbox && ! $camptix_options['archived'] ) {
+                       require_once( __DIR__ . '/views/notice-sandbox-mode.php' );
+               }
+       }
+}
+
+/*
+ * Show empty tickets
+ *
+ * This provides a way for individual WordCamps to decide if they want to show sold-out tickets in the [tickets]
+ * shortcode output. This can help avoid confusion if the camp has several types of tickets (e.g., General
+ * Admission, Micro-sponsorship, etc) and the General Admission ticket sells out. If the General Admission ticket
+ * was hidden, some users may mistakenly think that the Micro-sponsorship ticket is the "normal" ticket, even
+ * though it costs several hundred dollars. Since we value keeping regular tickets accessible by as many people
+ * as possible, we don't want anyone getting the impression that WordCamps are expensive to attend.
+ *
+ * @todo change this to use feature-flags similar to the skip-feature flags
+ */
+function hide_empty_tickets() {
+       $targeted_wordcamps_ids = array(
+               299, // San Francisco 2013
+               364, // San Francisco 2014
+       );
+
+       if ( in_array( get_current_blog_id(), $targeted_wordcamps_ids ) ) {
+               add_filter( 'camptix_hide_empty_tickets', '__return_false' );
+       }
+}
+
+/**
+ * Enqueue the login message styles on the tickets screen.
+ */
+function print_login_message_styles() {
+       global $post;
+
+       if ( $post && has_shortcode( $post->post_content, 'camptix' ) ) {
+               wcorg_login_css();
+       }
+}
+
+/**
+ * Override the default 'please login...' message that Require Login places on the ticket registration screen
+ *
+ * @param string $message
+ *
+ * @return string
+ */
+function override_please_login_message( $message ) {
+       $please_login_message = sprintf(
+               __( 'Before purchasing your tickets, please <a href="%s">log in with your WordPress.org account</a>*.', 'wordcamporg' ),
+               wp_login_url( get_redirect_return_url() )
+       );
+
+       $message = str_replace(
+               __( 'Please use your <strong>WordPress.org</strong>* account to log in.', 'wordcamporg' ),
+               $please_login_message,
+               wcorg_login_message( '', get_redirect_return_url() )
+       );
+
+       return $message;
+}
+
+/**
+ * Get the URL to return to after logging in or creating an account.
+ *
+ * @todo It'd be better to refactor CampTix so addons can be accessed directly by the class name,
+ *       but there could be backcompat issues, etc, and there's no time to deal with that right now.
+ *
+ * @return string
+ */
+function get_redirect_return_url() {
+       /** @var $camptix \CampTix_Plugin */
+       global $camptix;
+       $camptix_url = false;
+
+       foreach ( $camptix->addons_loaded as $addon ) {
+               if ( is_a( $addon, 'CampTix_Require_Login' ) ) {
+                       /** @var $addon \CampTix_Require_Login */
+                       $camptix_url = $addon->get_redirect_return_url();
+               }
+       }
+
+       if ( ! $camptix_url ) {
+               $camptix_url = $camptix->get_tickets_url();
+       }
+
+       return $camptix_url;
+}
+
+/**
+ * Define the error messages that correspond to our custom error codes.
+ *
+ * @param array $errors
+ */
+function add_form_start_error_messages( $errors ) {
+       /** @var $camptix \CampTix_Plugin */
+       global $camptix;
+
+       if ( isset( $errors['cannot_edit_registration_closed'] ) ) {
+               $camptix->error( __(
+                       "To help ensure that registration goes smoothly during WordCamp, we've stopped accepting new ticket purchases and are no longer allowing changes to be made to existing tickets.",
+                       'wordcamporg'
+               ) );
+       }
+}
+
+/**
+ * Perform various actions when ticket sales are opened
+ *
+ * @param string $new_status
+ * @param string $old_status
+ * @param \WP_Post $tickets_page
+ */
+function ticket_sales_opened( $new_status, $old_status, $tickets_page ) {
+       if ( 'publish' != $new_status || 'publish' == $old_status || ! has_shortcode( $tickets_page->post_content, 'camptix' ) ) {
+               return;
+       }
+
+       $all_pages = get_posts( array(
+               'post_status'    => 'any',
+               'post_type'      => 'page',
+               'posts_per_page' => -1,
+       ) );
+
+       foreach ( $all_pages as $attendees_page ) {
+               if ( 'publish' != $attendees_page->post_status && has_shortcode( $attendees_page->post_content, 'camptix_attendees' ) ) {
+                       wp_publish_post( $attendees_page );
+                       assign_no_sidebar_template( $attendees_page );
+                       add_attendees_page_to_primary_menu( $attendees_page );
+                       break;
+               }
+       }
+}
+
+/**
+ * Assign the template with no sidebar to the Attendees page
+ *
+ * @param \WP_Post $attendees_page
+ */
+function assign_no_sidebar_template( $attendees_page ) {
+       switch( get_template() ) {
+               case 'twentyten':
+                       $page_template = 'onecolumn-page.php';
+                       break;
+
+               case 'twentytwelve':
+                       $page_template = 'page-templates/full-width.php';
+                       break;
+
+               case 'twentyfourteen':
+                       $page_template = 'page-templates/full-width.php';
+                       break;
+
+               case 'wordcamp-base':
+                       $page_template = 'template-full-width.php';
+                       break;
+
+               case 'twentyeleven':
+               case 'twentythirteen':
+               default:
+                       $page_template = false;
+                       break;
+       }
+
+       if ( $page_template ) {
+               update_post_meta( $attendees_page->ID, '_wp_page_template', $page_template );
+       } else {
+               delete_post_meta( $attendees_page->ID, '_wp_page_template' );
+       }
+}
+
+/**
+ * Add the Attendees page to the primary menu
+ *
+ * @param \WP_Post $attendees_page
+ */
+function add_attendees_page_to_primary_menu( $attendees_page ) {
+       $menu_locations = get_nav_menu_locations();
+
+       if ( isset( $menu_locations['primary'] ) && $menu_locations['primary'] ) {
+               $existing_menu_items = wp_get_nav_menu_items( $menu_locations['primary'] );
+               $existing_menu_items = wp_list_pluck( $existing_menu_items, 'object_id' );
+
+               if ( ! in_array( $attendees_page->ID, $existing_menu_items ) ) {
+                       $attendees_menu_item = array(
+                               'menu-item-object-id' => $attendees_page->ID,
+                               'menu-item-object'    => $attendees_page->post_type,
+                               'menu-item-type'      => 'post_type',
+                               'menu-item-title'     => __( 'Attendees', 'camptix' ),
+                               'menu-item-status'    => 'publish',
+                       );
+                       wp_update_nav_menu_item( $menu_locations['primary'], 0, $attendees_menu_item );
+               }
+       }
+}
+
+/*
+ * Determines the name ordering scheme on a per-blog basis
+ */
+function set_name_order( $order ) {
+       switch( get_current_blog_id() ) {
+               case 304: // 2013.tokyo
+                       $order = 'eastern';
+                       break;
+       }
+
+       return $order;
+}
+
+/**
+ * Prevent attendees from making changes to their information after registration has closed.
+ *
+ * @param \WP_Post $attendee
+ */
+function disable_attendee_edits( $attendee ) {
+       /** @var $camptix \CampTix_Plugin */
+       global $camptix;
+
+       $disabled_sites_tickets = array(
+               364 => array( 648462, 648704 ),  // 2014.sf
+       );
+
+       $current_site_id    = get_current_blog_id();
+       $attendee_ticket_id = get_post_meta( $attendee->ID, 'tix_ticket_id', true );
+
+       foreach ( $disabled_sites_tickets as $disabled_site_id => $disabled_ticket_ids ) {
+               if ( $current_site_id == $disabled_site_id && in_array( $attendee_ticket_id, $disabled_ticket_ids ) ) {
+                       $camptix->error_flag( 'cannot_edit_registration_closed' );
+                       $camptix->redirect_with_error_flags();
+               }
+       }
+}
+
+/**
+ * Enable addons that are disabled by default
+ *
+ * @param array $addons
+ *
+ * @return array
+ */
+function load_addons( $addons ) {
+       /** @var $camptix \CampTix_Plugin */
+       global $camptix;
+
+       $require_login_sites = apply_filters( 'camptix_extras_require_login_site_ids', array(
+               206,    // testing.wordcamp.org
+               364,    // 2014.sf.wordcamp.org
+               447,    // belohorizonte.wordcamp.org/2015
+       ) );
+
+       if ( in_array( get_current_blog_id(), $require_login_sites, true ) ) {
+               /*
+                * todo -- NOTE: when this is opened up for all camps, it will have to be enabled ONLY on WCSF14 and sites
+                * that haven't opened tickets yet. Otherwise CampTix_Requre_login::hide_unconfirmed_attendees()
+                * will break pre-existing [attendee] pages.
+                */
+               $addons['require-login'] = $camptix->get_default_addon_path( 'require-login.php' );
+       }
+
+       $addons['track-attendance'] = $camptix->get_default_addon_path( 'track-attendance.php' );
+
+       return $addons;
+}
+
+/**
+ * Modify CampTix's default capabilities
+ */
+function modify_capabilities( $capabilities ) {
+       $capabilities['delete_attendees'] = 'manage_network';
+       $capabilities['refund_all']       = 'manage_network';
+
+       return $capabilities;
+}
+
+/**
+ * Modify CampTix's default options
+ */
+function modify_default_options( $options ) {
+       $options['payment_methods']        = array( 'paypal'     => true               );
+       $options['payment_options_paypal'] = array( 'api_predef' => 'wordcamp-sandbox' );
+
+       return $options;
+}
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginscamptixtweaksviewsnoticesandboxmodephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/notice-sandbox-mode.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/notice-sandbox-mode.php                           (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/camptix-tweaks/views/notice-sandbox-mode.php     2016-02-01 23:20:27 UTC (rev 2442)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,15 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\CampTix_Tweaks;
+defined( 'WPINC' ) or die();
+
+?>
+
+<div class="notice notice-warning">
+       <p>
+               <?php _e(
+                       'CampTix is in <strong>sandbox (test) mode</strong>. Make sure you disable it before you open ticket sales!',
+                       'wordcamporg'
+               ); ?>
+       </p>
+</div>
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentmupluginsloadothermupluginsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/load-other-mu-plugins.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/load-other-mu-plugins.php      2016-02-01 19:52:00 UTC (rev 2441)
+++ sites/trunk/wordcamp.org/public_html/wp-content/mu-plugins/load-other-mu-plugins.php        2016-02-01 23:20:27 UTC (rev 2442)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4,6 +4,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // mu-plugins in sub-directories
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( __DIR__ . '/wp-cli-commands/bootstrap.php' );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+require_once( __DIR__ . '/camptix-tweaks/camptix-tweaks.php' );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> // Private mu-plugins
</span><span class="cx" style="display: block; padding: 0 10px"> $private_mu_plugins = glob( WP_CONTENT_DIR . '/mu-plugins-private/*.php' );
</span></span></pre>
</div>
</div>

</body>
</html>