WordPress.org

Making WordPress.org

Ticket #262: 262.2.diff

File 262.2.diff, 8.6 KB (added by iandunn, 4 years ago)
  • camptix-badge-generator/includes/indesign-badges.php

    diff --git camptix-badge-generator/includes/indesign-badges.php camptix-badge-generator/includes/indesign-badges.php
    index 1fa4c08..6d5fa97 100644
    defined( 'WPINC' ) or die(); 
    99
    1010add_action( 'camptix_menu_tools_indesign_badges', __NAMESPACE__ . '\render_indesign_page' );
    1111
     12/*
     13 * todo
     14 *
     15 * can't call serve_zip_file() in build_assets() because headers already sent
     16 * also, downloading gravatars takes too long to do while user is waiting for page to load
     17 * so, when user hit `generate assets` button, use javascript to hide the button and show a spinner and a message that say it'll take a few minutes
     18 * send ajax post to kick off build
     19 * send ajax get to check if build is done every ~10 seconds
     20 * maybe show progress
     21 * when it's done, hide spinner/message and show a `download` button
     22 * clicking that button reloads php page with param to serve the zip, then delete it
     23 *
     24 * post-deploy:
     25 *      - update documentation at https://make.wordpress.org/community/handbook/wordcamp-organizer/first-steps/helpful-documents-and-templates/create-wordcamp-badges-with-gravatars/
     26 *      - Post to make/community announcing to organizers that it's available now
     27 *      - update dashboard widget with link to both html and indesign
     28 */
     29
    1230/**
    1331 * Render the Indesign Badges page
    1432 */
    function render_indesign_page() { 
    1735                return;
    1836        }
    1937
     38        //$_POST['generate-indesign-assets'] = 1; //todo testing
     39
     40        if ( isset( $_POST['generate-indesign-assets'] ) ) {
     41                // todo verify nonce
     42
     43                try {
     44                        build_assets();
     45                } catch ( \Exception $exception ) {
     46                        /*
     47                         * There's nothing more to do here, we just needed to capture the $exception variable so the view can
     48                         * display the message to the user.
     49                         *
     50                         * Because the message is being displayed, make sure you don't put anything overly technical, or
     51                         * anything sensitive inside it.
     52                         */
     53                }
     54        }
     55
    2056        $html_customizer_url = HTML\get_customizer_section_url();
    2157
    2258        require_once( dirname( __DIR__ ) . '/views/indesign-badges/page-indesign-badges.php' );
    function build_assets() { 
    3975                download_gravatars( $attendees, $gravatar_folder );
    4076                generate_csv( $csv_filename, $zip_local_folder, $attendees, $gravatar_folder );
    4177                create_zip_file( $zip_filename, $zip_local_folder, $csv_filename, $gravatar_folder );
     78                serve_zip_file( $zip_filename );
    4279        } finally {
    4380                // todo Delete contents of $assets_folder, then rmdir( $assets_folder );
    4481        }
  • new file camptix-badge-generator/javascript/indesign-badges.js

    diff --git camptix-badge-generator/javascript/indesign-badges.js camptix-badge-generator/javascript/indesign-badges.js
    new file mode 100644
    index 0000000..dcfe3ec
    - +  
     1jQuery( document ).ready( function( $ ) {
     2        'use strict';
     3
     4        var app = window.CampTixInDesignBadges = {
     5
     6                /**
     7                 * Main entry point
     8                 */
     9                init: function() {
     10                        try {
     11                                $( '#cbg-generate-assets' ).click( app.requestAssetGeneration );
     12                        } catch ( exception ) {
     13                                app.log( exception );
     14                        }
     15                },
     16
     17                /**
     18                 * todo
     19                 *
     20                 * @param {object} event
     21                 */
     22                requestAssetGeneration : function( event ) {
     23                        try {
     24                        } catch ( exception ) {
     25                                wcb.log( exception );
     26                        }
     27                },
     28
     29                /**
     30                 * Log a message to the console
     31                 *
     32                 * @param {*} error
     33                 */
     34                log : function( error ) {
     35                        if ( ! window.console ) {
     36                                return;
     37                        }
     38
     39                        if ( 'string' === typeof error ) {
     40                                console.log( 'CampTix Badge Generator: ' + error );
     41                        } else {
     42                                console.log( 'CampTix Badge Generator: ', error );
     43                        }
     44                }
     45        };
     46
     47        app.init();
     48} );
  • camptix-badge-generator/views/common/page-generate-badges.php

    diff --git camptix-badge-generator/views/common/page-generate-badges.php camptix-badge-generator/views/common/page-generate-badges.php
    index 89d3117..161c30c 100644
     
    33namespace CampTix\Badge_Generator;
    44defined( 'WPINC' ) or die();
    55
     6/**
     7 * @var string $html_customizer_url
     8 * @var string $indesign_page_url
     9 * @var string $notify_tool_url
     10 */
    611?>
    712
    813<p>
  • camptix-badge-generator/views/indesign-badges/page-indesign-badges.php

    diff --git camptix-badge-generator/views/indesign-badges/page-indesign-badges.php camptix-badge-generator/views/indesign-badges/page-indesign-badges.php
    index 1693e97..92bf61e 100644
    namespace CampTix\Badge_Generator\InDesign; 
    44defined( 'WPINC' ) or die();
    55
    66/**
    7  * @var string $html_customizer_url
     7 * @var \Exception $exception
    88 */
    99
     10/*
     11todo
     12
     13- Update the rest of this text
     14        bring in documentation from handbook, or just link to it? has more details on using data merge, screenshots, etc</li>
     15        https://make.wordpress.org/community/handbook/wordcamp-organizer/planning-details/wordcamp-name-badge-templates
     16        https://make.wordpress.org/community/handbook/wordcamp-organizer/first-steps/helpful-documents-and-templates/create-wordcamp-badges-with-gravatars/personalized-badges-with-indesign/
     17- Bring documentation inline instead of being in handbook, similar to Remote CSS
     18- Maybe link to http://ollehost.dk/blog/2016/02/16/convert-character-encoding-of-a-csv-file-for-indesign-data-merge/
     19        Or can just fix that during the export?
     20
     21*/
     22
    1023?>
    1124
    1225<h2>
    1326        <?php _e( 'InDesign Badges', 'wordcamporg' ); ?>
    1427</h2>
    1528
    16 <p>
    17         <?php _e(
    18                 "The process for building InDesign badges hasn't been automated yet, so it requires a developer to run a script.
    19                  That script will create a CSV file and will download Gravatar images for all attendees.
    20                  Once that's done, a designer can take those files into InDesign and use the Data Merge feature to create personalized badges for each attendee.",
    21                 'wordcamporg'
    22         ); ?>
    23 </p>
     29<?php if ( isset( $exception ) ) : ?>
     30        <div class="notice notice-error notice-large inline">
     31                <?php esc_html_e( 'Error: ', 'wordcamporg' ); ?>
     32                <?php echo esc_html( $exception->getMessage() ); ?>
     33        </div>
     34<?php endif; ?>
    2435
    25 <p>
    26         <?php printf(
    27                 __(
    28                         'Full instructions are <a href="%s">available in the WordCamp Organizer Handbook</a>.
    29                         If you\'d prefer an easier way, <a href="%s">the HTML/CSS method</a> is much more automated at this time.',
    30                         'wordcamporg'
    31                 ),
    32                 'https://make.wordpress.org/community/handbook/wordcamp-organizer-handbook/first-steps/helpful-documents-and-templates/create-wordcamp-badges-with-gravatars/',
    33                 esc_url( $html_customizer_url )
    34         ); ?>
    35 </p>
     36<button id="cbg-generate-assets" class="button button-primary">
     37        <?php esc_html_e( 'Generate Assets', 'wordcamporg' ); ?>
     38</button>
     39
     40<span class="spinner is-active"></span>
     41
     42<button id="cbg-download-assets" class="button button-primary">
     43        <?php esc_html_e( 'Download Assets', 'wordcamporg' ); ?>
     44</button>
    3645
    3746<p>
    38         <?php printf(
    39                 __( 'if you\'d like to help automate the InDesign process, you can contribute to <a href="%s">Meta ticket #262</a>.', 'wordcamporg' ),
    40                 'https://meta.trac.wordpress.org/ticket/262'
    41         ); ?>
     47        intro sentence<br/>
     48        good to do dry run early on, make sure everything works, printer will accept output, etc<br/>
     49        but then wait until last minute to do complete steps, because don't want to have to repeat the process several times
    4250</p>
     51
     52<ol>
     53        <li><?php echo wp_kses( __( 'Click on the <code>Generate Assets</code> button.', 'wordcamporg' ), 'post' ); ?></li>
     54        <li><?php esc_html_e( 'Wait while the assets are being generated. This can take 5+ minutes, especially if you have hundreds of attendees.', 'wordcamporg' ); ?></li>
     55        <li><?php echo wp_kses( __( 'Click on the <code>Download Assets</code> button once it appears.', 'wordcamporg' ), 'post' ); ?></li>
     56        <li><?php esc_html_e( 'Unzip the downloaded file on your computer, and use a spreadsheet application to open the CSV file inside.', 'wordcamporg' ); ?></li>
     57        <li><?php echo wp_kses( __( 'Use the find/replace feature to change the file paths in the <code>Gravatar</code> column. It should match the location on your computer where you extracted the assets to.', 'wordcamporg' ), 'post' ); ?></li>
     58        <li><?php esc_html_e( "Remove any columns that you don't plan on merging, since InDesign will complain about them.", 'wordcamporg' ); ?></li>
     59        <li><?php esc_html_e( 'Review the data in the CSV and fix anything that will look bad on the badges. For example, inconsistent capitalization, typos, etc.', 'wordcamporg' ); ?></li>
     60        <li><?php esc_html_e( 'Open InDesign and use the Data Merge feature to generate a unique badge for each attendee.', 'wordcamporg' ); ?></li>
     61        <li><?php esc_html_e( 'Export the results into a file that you can give to your print vendor.', 'wordcamporg' ); ?></li>
     62</ol>