Changeset 7915 for sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/includes/indesign-badges.php
- Timestamp:
- 11/29/2018 03:19:31 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-badge-generator/includes/indesign-badges.php
r7913 r7915 2 2 3 3 namespace CampTix\Badge_Generator\InDesign; 4 use \CampTix\Badge_Generator; 5 use \CampTix\Badge_Generator\HTML; 6 use \WordCamp\Logger; 4 use Exception; 5 use CampTix_Plugin; 6 use CampTix\Badge_Generator; 7 use CampTix\Badge_Generator\HTML; 8 use WordCamp\Logger; 7 9 use WordCamp\Utilities; 8 10 9 defined( 'WPINC' ) ordie();11 defined( 'WPINC' ) || die(); 10 12 11 13 add_action( 'camptix_menu_tools_indesign_badges', __NAMESPACE__ . '\render_indesign_page' ); … … 28 30 * 29 31 * @param array $options 32 * 33 * @throws Exception 30 34 */ 31 35 function build_assets( $options ) { … … 53 57 create_zip_file( $zip_filename, $zip_local_folder, $csv_filename, $gravatar_folder ); 54 58 } finally { 55 // todo Delete contents of $assets_folder, then rmdir( $assets_folder ); 59 // todo Delete contents of $assets_folder, then rmdir( $assets_folder );. 56 60 } 57 61 } … … 65 69 * @param string $gravatar_folder 66 70 * 67 * @throws \Exception71 * @throws Exception 68 72 */ 69 73 function download_gravatars( $attendees, $gravatar_folder ) { … … 87 91 if ( ! $gravatar_file ) { 88 92 Logger\log( 'gravatar_open_failed', compact( 'attendee', 'gravatar_folder', 'filename' ) ); 89 throw new \Exception( __( "Couldn't save all Gravatars.", 'wordcamporg' ) );93 throw new Exception( __( "Couldn't save all Gravatars.", 'wordcamporg' ) ); 90 94 } 91 95 … … 112 116 * @todo Update this to use wcorg_redundant_remote_get() instead, for DRYness 113 117 * 114 * @throws \Exception when the HTTP request fails118 * @throws Exception when the HTTP request fails 115 119 */ 116 120 function download_single_gravatar( $request_url ) { … … 124 128 $retry_after = min( $retry_after * $attempt_count, 30 ); 125 129 126 // A 404 is expected when the attendee doesn't have a Gravatar setup, so don't retry them 130 // A 404 is expected when the attendee doesn't have a Gravatar setup, so don't retry them. 127 131 if ( 404 == $status_code ) { 128 132 return false; … … 134 138 135 139 if ( is_array( $response ) && isset( $response['body'] ) ) { 136 $response['body'] = '[redacted]'; // Avoid cluttering the logs with a ton of binary data 140 $response['body'] = '[redacted]'; // Avoid cluttering the logs with a ton of binary data. 137 141 } 138 142 … … 142 146 } else { 143 147 Logger\log( 'request_failed_permenantly', compact( 'request_url', 'response' ) ); 144 throw new \Exception( __( "Couldn't download all Gravatars.", 'wordcamporg' ) );148 throw new Exception( __( "Couldn't download all Gravatars.", 'wordcamporg' ) ); 145 149 } 146 150 … … 170 174 * Get the filename for the Zip file 171 175 * 172 * @param $assets_folder176 * @param string $assets_folder 173 177 * 174 178 * @return string … … 197 201 * @param string $gravatar_folder 198 202 * 199 * @throws \Exception203 * @throws Exception 200 204 */ 201 205 function generate_csv( $csv_filename, $zip_local_folder, $attendees, $gravatar_folder ) { 202 /** @var \CampTix_Plugin $camptix */206 /** @var CampTix_Plugin $camptix */ 203 207 global $camptix; 204 208 … … 211 215 if ( ! $csv_handle ) { 212 216 Logger\log( 'open_csv_failed' ); 213 throw new \Exception( __( "Couldn't open CSV file.", 'wordcamporg' ) );217 throw new Exception( __( "Couldn't open CSV file.", 'wordcamporg' ) ); 214 218 } 215 219 … … 235 239 */ 236 240 function get_admin_flags() { 237 /** @var \CampTix_Plugin $camptix */241 /** @var CampTix_Plugin $camptix */ 238 242 global $camptix; 239 243 … … 280 284 $row = array(); 281 285 282 if ( 'unknown.attendee@example.org' == $attendee->tix_email ) {286 if ( 'unknown.attendee@example.org' === $attendee->tix_email ) { 283 287 return $row; 284 288 } … … 327 331 */ 328 332 function get_twitter_username( $attendee ) { 329 /** @global \CampTix_Plugin $camptix */333 /** @global CampTix_Plugin $camptix */ 330 334 global $camptix; 331 335 … … 353 357 * @param string $username 354 358 * @param string $first_name 355 * @param string $empty_mode 'replace' to replace empty usernames with first names 359 * @param string $empty_mode 'replace' to replace empty usernames with first names. 356 360 * 357 361 * @return string 358 362 */ 359 363 function format_twitter_username( $username, $first_name, $empty_mode = '' ) { 360 if ( empty 364 if ( empty( $username ) ) { 361 365 if ( 'replace' === $empty_mode ) { 362 366 $username = $first_name; 363 367 } 364 368 } else { 365 // Strip out everything but the username, and prefix a @369 // Strip out everything but the username, and prefix a `@` character. 366 370 $username = '@' . preg_replace( 367 371 '/ … … 408 412 * @param string $gravatar_folder 409 413 * 410 * @throws \Exception414 * @throws Exception 411 415 */ 412 416 function create_zip_file( $zip_filename, $zip_local_folder, $csv_filename, $gravatar_folder ) { 413 417 if ( ! class_exists( 'ZipArchive') ) { 414 418 Logger\log( 'zip_ext_not_installed' ); 415 throw new \Exception( __( 'The Zip extension for PHP is not installed.', 'wordcamporg' ) );419 throw new Exception( __( 'The Zip extension for PHP is not installed.', 'wordcamporg' ) ); 416 420 } 417 421 … … 421 425 if ( true !== $open_status ) { 422 426 Logger\log( 'zip_open_failed', compact( 'zip_filename', 'open_status' ) ); 423 throw new \Exception( __( 'The Zip file could not be created.', 'wordcamporg' ) );427 throw new Exception( __( 'The Zip file could not be created.', 'wordcamporg' ) ); 424 428 } 425 429 … … 453 457 * @param string $filename 454 458 * 455 * @throws \Exception459 * @throws Exception 456 460 */ 457 461 function serve_zip_file( $filename ) { 458 462 if ( ! current_user_can( Badge_Generator\REQUIRED_CAPABILITY ) ) { 459 463 Logger\log( 'access_denied' ); 460 throw new \Exception( __( "You don't have authorization to perform this action.", 'wordcamporg' ) );464 throw new Exception( __( "You don't have authorization to perform this action.", 'wordcamporg' ) ); 461 465 } 462 466
Note: See TracChangeset
for help on using the changeset viewer.