Changeset 3830437
- Timestamp:
- 11/27/2026 08:34:35 PM (2 hours ago)
- Location:
- pi-giveaways
- Files:
-
- 4 added
- 10 edited
- 1 copied
-
tags/1.0.13 (copied) (copied from pi-giveaways/trunk )
-
tags/1.0.13/README.md (added)
-
tags/1.0.13/assets/winner-photos.js (added)
-
tags/1.0.13/includes/class-pigi-admin.php (modified) (3 diffs)
-
tags/1.0.13/includes/class-pigi-frontend.php (modified) (3 diffs)
-
tags/1.0.13/includes/class-pigi-repository.php (modified) (3 diffs)
-
tags/1.0.13/pi-giveaways.php (modified) (2 diffs)
-
tags/1.0.13/readme.txt (modified) (3 diffs)
-
trunk/README.md (added)
-
trunk/assets/winner-photos.js (added)
-
trunk/includes/class-pigi-admin.php (modified) (3 diffs)
-
trunk/includes/class-pigi-frontend.php (modified) (3 diffs)
-
trunk/includes/class-pigi-repository.php (modified) (3 diffs)
-
trunk/pi-giveaways.php (modified) (2 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pi-giveaways/tags/1.0.13/includes/class-pigi-admin.php
r3761409 r3830437 285 285 wp_enqueue_style( 'pigiveaways-admin-preview', PIGIVEAWAYS_URL . 'assets/admin-preview.css', array( 'pigiveaways-admin' ), PIGIVEAWAYS_VERSION ); 286 286 wp_enqueue_script( 'pigiveaways-admin', PIGIVEAWAYS_URL . 'assets/admin.js', array(), PIGIVEAWAYS_VERSION, true ); 287 if ( $screen && 'pigiveaways_giveaway' === $screen->post_type && 'post' === $screen->base && current_user_can( 'upload_files' ) ) { 288 wp_enqueue_media(); 289 wp_enqueue_script( 'pigiveaways-winner-photos', PIGIVEAWAYS_URL . 'assets/winner-photos.js', array( 'media-editor' ), PIGIVEAWAYS_VERSION, true ); 290 } 287 291 if ( false !== strpos( $hook, 'pigiveaways' ) ) { 288 292 $settings = wp_parse_args( get_option( $this->option, array() ), $this->defaults() ); … … 351 355 add_meta_box( 'pig-details', __( 'Giveaway Details', 'pi-giveaways' ), array( $this, 'details_box' ), 'pigiveaways_giveaway', 'normal', 'high' ); 352 356 add_meta_box( 'pig-form-builder', __( 'Giveaway Entry Form', 'pi-giveaways' ), array( $this, 'form_builder_box' ), 'pigiveaways_giveaway', 'normal', 'default' ); 357 add_meta_box( 'pig-winner-publication', __( 'Public Winners and Reviews', 'pi-giveaways' ), array( $this, 'winner_publication_box' ), 'pigiveaways_giveaway', 'normal', 'default' ); 358 } 359 360 public function winner_publication_box( $post ) { 361 $publication = (array) get_post_meta( $post->ID, '_pigiveaways_winner_publication', true ); 362 echo '<input type="hidden" name="pig_winner_publication_present" value="1">'; 363 echo '<p><label><input type="checkbox" name="pig_historical_giveaway" value="1" ' . checked( ! empty( $publication['historical'] ), true, false ) . '> ' . esc_html__( 'Historical giveaway: record past winners silently', 'pi-giveaways' ) . '</label></p>'; 364 echo '<p>' . esc_html__( 'Set the giveaway status to Ended or Awarded before recording historical winners.', 'pi-giveaways' ) . '</p>'; 365 echo '<p><label><input type="checkbox" name="pig_publish_winners" value="1" ' . checked( ! empty( $publication['enabled'] ), true, false ) . '> ' . esc_html__( 'Automatically display recorded winners on the closed giveaway page', 'pi-giveaways' ) . '</label></p>'; 366 echo '<p>' . esc_html__( 'This setting publishes winner names, reviews, and photos on Ended and Awarded giveaways. Enable it only with the winners’ permission. Paste image URLs, one per line, or paste HTML image tags.', 'pi-giveaways' ) . '</p>'; 367 foreach ( PIGI_Repository::publication_winner_slots( $post->ID ) as $award ) { 368 $row = $publication['winners'][ $award->id ] ?? array(); 369 $key = 'pig_public_winner[' . $award->id . ']'; 370 $label = trim( $award->first_name . ' ' . $award->last_name ); 371 echo '<fieldset><legend><strong>' . esc_html( $label ?: __( 'Historical winner', 'pi-giveaways' ) ) . '</strong></legend>'; 372 echo '<p><label>' . esc_html__( 'Public display name (optional)', 'pi-giveaways' ) . '<br><input class="regular-text" name="' . esc_attr( $key . '[name]' ) . '" value="' . esc_attr( $row['name'] ?? '' ) . '"></label></p>'; 373 echo '<p><label>' . esc_html__( 'Winner review', 'pi-giveaways' ) . '<br><textarea class="large-text" rows="4" name="' . esc_attr( $key . '[review]' ) . '">' . esc_textarea( $row['review'] ?? '' ) . '</textarea></label></p>'; 374 echo '<div data-pig-winner-photos>'; 375 if ( current_user_can( 'upload_files' ) ) { 376 echo '<p><button type="button" class="button" data-pig-choose-photos data-title="' . esc_attr__( 'Select or upload winner photos', 'pi-giveaways' ) . '" data-confirm="' . esc_attr__( 'Add photos', 'pi-giveaways' ) . '">' . esc_html__( 'Select or upload photos', 'pi-giveaways' ) . '</button></p>'; 377 } 378 echo '<p><label>' . esc_html__( 'Photo URLs (remove a line to remove a photo)', 'pi-giveaways' ) . '<br><textarea class="large-text" rows="3" name="' . esc_attr( $key . '[photos]' ) . '">' . esc_textarea( implode( "\n", $row['photos'] ?? array() ) ) . '</textarea></label></p></div>'; 379 echo '<p><label>' . esc_html__( 'Video or reel URLs (YouTube, Instagram or Facebook, one per line)', 'pi-giveaways' ) . '<br><textarea class="large-text" rows="3" name="' . esc_attr( $key . '[videos]' ) . '">' . esc_textarea( implode( "\n", $row['videos'] ?? array() ) ) . '</textarea></label></p></fieldset>'; 380 } 381 } 382 383 private function save_winner_publication( $post_id ) { 384 if ( ! isset( $_POST['pig_winner_publication_present'] ) ) { 385 return; 386 } 387 $submitted = (array) wp_unslash( $_POST['pig_public_winner'] ?? array() ); 388 $previous = (array) get_post_meta( $post_id, '_pigiveaways_winner_publication', true ); 389 $winners = (array) ( $previous['winners'] ?? array() ); 390 foreach ( PIGI_Repository::publication_winner_slots( $post_id ) as $award ) { 391 $row = $submitted[ $award->id ] ?? null; 392 if ( ! is_array( $row ) ) { 393 continue; 394 } 395 $winners[ $award->id ] = array( 396 'name' => sanitize_text_field( $row['name'] ?? '' ), 397 'review' => sanitize_textarea_field( $row['review'] ?? '' ), 398 'photos' => $this->parse_winner_photos( $row['photos'] ?? '' ), 399 'videos' => PIGI_Repository::winner_video_urls( $row['videos'] ?? '' ), 400 ); 401 } 402 update_post_meta( $post_id, '_pigiveaways_winner_publication', wp_slash( array( 403 'enabled' => isset( $_POST['pig_publish_winners'] ), 404 'historical' => isset( $_POST['pig_historical_giveaway'] ), 405 'winners' => $winners, 406 ) ) ); 407 } 408 409 private function parse_winner_photos( $input ) { 410 if ( ! is_string( $input ) ) { 411 return array(); 412 } 413 414 $candidates = array(); 415 $tags = new WP_HTML_Tag_Processor( $input ); 416 while ( $tags->next_tag( 'IMG' ) ) { 417 $src = $tags->get_attribute( 'src' ); 418 if ( is_string( $src ) ) { 419 $candidates[] = $src; 420 } 421 } 422 foreach ( preg_split( '/\R/', $input ) as $line ) { 423 if ( preg_match( '~^(https?://|//|/)~i', trim( $line ) ) && false === strpos( $line, '<' ) ) { 424 $candidates[] = $line; 425 } 426 } 427 428 $photos = array(); 429 foreach ( $candidates as $candidate ) { 430 $url = trim( $candidate ); 431 if ( 0 === strpos( $url, '//' ) ) { 432 $url = 'https:' . $url; 433 } elseif ( 0 === strpos( $url, '/' ) ) { 434 $url = home_url( $url ); 435 } 436 if ( ! preg_match( '~^https?://~i', $url ) ) { 437 continue; 438 } 439 $url = esc_url_raw( $url, array( 'http', 'https' ) ); 440 if ( wp_parse_url( $url, PHP_URL_HOST ) ) { 441 $photos[] = $url; 442 } 443 } 444 return array_values( array_unique( $photos ) ); 353 445 } 354 446 … … 522 614 update_post_meta( $post_id, '_pigiveaways_form_fields', $stored_fields ); 523 615 update_post_meta( $post_id, '_pigiveaways_form_mode', $mode ); 616 $this->save_winner_publication( $post_id ); 524 617 } 525 618 -
pi-giveaways/tags/1.0.13/includes/class-pigi-frontend.php
r3751015 r3830437 241 241 echo '<p class="pig-related-event"><a href="' . esc_url( $d['event_url'] ) . '">' . esc_html__( 'View related event', 'pi-giveaways' ) . ' →</a></p>'; 242 242 } 243 $winners = ''; 244 if ( 'publish' === $post->post_status && ! post_password_required( $post ) && in_array( $state, array( 'ended', 'awarded' ), true ) ) { 245 $winners = $this->render_public_winners( $id ); 246 } 243 247 if ( 'active' === $state ) { 244 248 $this->form( $id, $d, $settings ); … … 246 250 echo '<p>' . esc_html__( 'This giveaway is coming soon.', 'pi-giveaways' ) . '</p>'; 247 251 } elseif ( 'ended' === $state ) { 248 echo '<p>' . esc_html __( 'Entries are closed. Any award will be assigned manually by the promoter.', 'pi-giveaways') . '</p>';252 echo '<p>' . esc_html( $winners ? __( 'Entries are closed.', 'pi-giveaways' ) : __( 'Entries are closed. Any award will be assigned manually by the promoter.', 'pi-giveaways' ) ) . '</p>'; 249 253 } elseif ( 'awarded' === $state ) { 250 254 $announcement = $d['announcement'] ? $d['announcement'] : __( 'The award has been announced.', 'pi-giveaways' ); … … 255 259 echo '<p>' . esc_html__( 'This giveaway is not accepting entries.', 'pi-giveaways' ) . '</p>'; 256 260 } 261 // The winner section escapes its data when building the markup. 262 echo $winners; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 257 263 echo '</div></section>'; 258 264 return ob_get_clean(); 265 } 266 267 private function render_public_winners( $id ) { 268 $publication = (array) get_post_meta( $id, '_pigiveaways_winner_publication', true ); 269 if ( empty( $publication['enabled'] ) ) { 270 return ''; 271 } 272 273 ob_start(); 274 foreach ( PIGI_Repository::publication_winner_slots( $id ) as $award ) { 275 $row = $publication['winners'][ $award->id ] ?? array(); 276 $initial = preg_match( '/^\p{L}/u', trim( (string) $award->last_name ), $match ) ? $match[0] . '.' : ''; 277 $name = $row['name'] ?? ''; 278 if ( '' === $name && empty( $row['review'] ) && empty( $row['photos'] ) && empty( $row['videos'] ) && 0 === strpos( (string) $award->id, 'historical-' ) ) { 279 continue; 280 } 281 if ( '' === $name ) { 282 $name = trim( $award->first_name . ' ' . $initial ); 283 } 284 echo '<article class="pig-winner"><h3>' . esc_html( $name ?: __( 'Giveaway winner', 'pi-giveaways' ) ) . '</h3>'; 285 if ( ! empty( $row['review'] ) ) { 286 echo '<div class="pig-winner-review">' . wp_kses_post( wpautop( esc_html( $row['review'] ) ) ) . '</div>'; 287 } 288 foreach ( $row['photos'] ?? array() as $photo ) { 289 echo '<img class="pig-winner-photo" src="' . esc_url( $photo, array( 'http', 'https' ) ) . '" loading="lazy" alt="' . esc_attr__( 'Photo shared by a giveaway winner', 'pi-giveaways' ) . '">'; 290 } 291 foreach ( $row['videos'] ?? array() as $video ) { 292 $this->render_winner_video( $id, $video ); 293 } 294 echo '</article>'; 295 } 296 $cards = ob_get_clean(); 297 return $cards ? '<section class="pig-winners"><h2>' . esc_html__( 'Giveaway Winners', 'pi-giveaways' ) . '</h2>' . $cards . '</section>' : ''; 298 } 299 300 private function render_winner_video( $post_id, $url ) { 301 if ( ! PIGI_Repository::winner_video_urls( $url ) ) { 302 return; 303 } 304 $host = strtolower( wp_parse_url( $url, PHP_URL_HOST ) ); 305 $path = wp_parse_url( $url, PHP_URL_PATH ); 306 $player = ''; 307 if ( preg_match( '~^(?:www\.|m\.)?instagram\.com$~', $host ) && preg_match( '~^/(reel|p|tv)/([A-Za-z0-9_-]+)/?$~', $path, $match ) ) { 308 $player = 'https://www.instagram.com/' . $match[1] . '/' . $match[2] . '/embed/'; 309 } elseif ( preg_match( '~^(?:(?:www\.|m\.)?facebook\.com|fb\.watch)$~', $host ) ) { 310 $player = add_query_arg( 'href', rawurlencode( $url ), 'https://www.facebook.com/plugins/video.php' ); 311 } 312 if ( $player ) { 313 echo '<div class="pig-winner-video"><iframe src="' . esc_url( $player ) . '" title="' . esc_attr__( 'Winner video', 'pi-giveaways' ) . '" width="500" height="480" style="max-width:100%;border:0" loading="lazy" allowfullscreen></iframe>'; 314 echo '<p><a href="' . esc_url( $url ) . '">' . esc_html__( 'Watch on the original platform', 'pi-giveaways' ) . '</a></p></div>'; 315 return; 316 } 317 $embed_url = preg_replace( '~^https://(?:www\.|m\.)?youtube\.com/shorts/([a-zA-Z0-9_-]{11})(?:[/?#].*)?$~i', 'https://www.youtube.com/watch?v=$1', $url ); 318 global $wp_embed; 319 $previous_post_id = $wp_embed->post_ID; 320 $previous_link = $wp_embed->linkifunknown; 321 $wp_embed->post_ID = $post_id; 322 $wp_embed->linkifunknown = false; 323 try { 324 $embed = $wp_embed->shortcode( array( 'discover' => false ), $embed_url ); 325 } finally { 326 $wp_embed->post_ID = $previous_post_id; 327 $wp_embed->linkifunknown = $previous_link; 328 } 329 echo '<div class="pig-winner-video">'; 330 if ( $embed && $embed_url !== $embed && esc_html( $embed_url ) !== $embed ) { 331 echo $embed; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- WordPress-generated oEmbed HTML. 332 } else { 333 echo '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Watch the winner’s video', 'pi-giveaways' ) . '</a>'; 334 } 335 echo '</div>'; 259 336 } 260 337 -
pi-giveaways/tags/1.0.13/includes/class-pigi-repository.php
r3761409 r3830437 177 177 } 178 178 179 public static function winner_video_urls( $input ) { 180 $urls = array(); 181 foreach ( preg_split( '/\R/', is_string( $input ) ? $input : '' ) as $line ) { 182 $url = esc_url_raw( trim( $line ), array( 'https' ) ); 183 if ( ! preg_match( '~^https://(?:www\.|m\.)?(?:youtube\.com|youtu\.be|instagram\.com|facebook\.com|fb\.watch)/[^\s]+$~i', $url ) ) { 184 continue; 185 } 186 $urls[] = $url; 187 } 188 return array_values( array_unique( $urls ) ); 189 } 190 191 public static function is_historical( $giveaway_id ) { 192 $publication = (array) get_post_meta( $giveaway_id, '_pigiveaways_winner_publication', true ); 193 $details = (array) get_post_meta( $giveaway_id, '_pigiveaways_details', true ); 194 return ! empty( $publication['historical'] ) && in_array( $details['status'] ?? '', array( 'ended', 'awarded' ), true ); 195 } 196 197 public static function publication_winner_slots( $giveaway_id ) { 198 $awards = array_values( array_filter( self::active_awards( $giveaway_id ), static function ( $award ) { 199 return 'winner' === $award->award_type; 200 } ) ); 201 if ( self::is_historical( $giveaway_id ) ) { 202 $remaining = self::winner_limit( $giveaway_id ) - count( $awards ); 203 for ( $slot = 1; $slot <= $remaining; ++$slot ) { 204 $awards[] = (object) array( 205 'id' => 'historical-' . $slot, 206 'first_name' => '', 207 'last_name' => '', 208 ); 209 } 210 } 211 return $awards; 212 } 213 179 214 public static function award( $entry_id, $note = '' ) { 180 215 global $wpdb; … … 183 218 return new WP_Error( 'invalid_entry', __( 'Only a valid entry can receive an award.', 'pi-giveaways' ) ); 184 219 } 220 $historical = self::is_historical( $entry->giveaway_id ); 185 221 $permission = apply_filters( 'pigiveaways_can_award_entry', true, $entry ); 186 222 if ( is_wp_error( $permission ) ) { … … 216 252 } 217 253 $award_id = (int) $wpdb->insert_id; 218 do_action( 'pigiveaways_winner_awarded', $award_id, $entry ); 254 if ( ! $historical ) { 255 do_action( 'pigiveaways_winner_awarded', $award_id, $entry ); 256 } 219 257 return $award_id; 220 258 } -
pi-giveaways/tags/1.0.13/pi-giveaways.php
r3761409 r3830437 4 4 * Plugin URI: https://wordpress.org/plugins/pi-giveaways/ 5 5 * Description: Create giveaways, collect entries, and manually award winners through a focused, privacy-aware workflow. 6 * Version: 1.0. 76 * Version: 1.0.13 7 7 * Author: Ali Qureshi 8 8 * Author URI: https://www.parorrey.com/ … … 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 define( 'PIGIVEAWAYS_VERSION', '1.0. 7' );20 define( 'PIGIVEAWAYS_VERSION', '1.0.13' ); 21 21 define( 'PIGIVEAWAYS_FILE', __FILE__ ); 22 22 define( 'PIGIVEAWAYS_DIR', plugin_dir_path( __FILE__ ) ); -
pi-giveaways/tags/1.0.13/readme.txt
r3811301 r3830437 6 6 Tested up to: 7.1.5 7 7 Requires PHP: 7.4 8 Stable tag: 1.0. 78 Stable tag: 1.0.13 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 26 26 * Giveaway listings with current and past sections. 27 27 * Entry moderation, CSV export, and unlimited manual winner records. 28 * Winner reviews, Media Library photo selection, and YouTube, Instagram, or Facebook video/reel URLs. 29 * Historical giveaways with silent entry-linked or manually named winner records and separate opt-in public display. 28 30 * Entry confirmation and administrator notification emails through `wp_mail()`. 29 31 * Honeypot protection and optional Google reCAPTCHA v3. … … 100 102 == Changelog == 101 103 104 = 1.0.13 = 105 * Add a Select or upload photos button for each winner using the WordPress Media Library. 106 * Add a Video or reel URLs field alongside each winner’s photos and review, supporting YouTube, Instagram, and Facebook. 107 * Add optional Historical giveaway mode to record past winners from existing entries or by public display name when no entry is on file. 108 * Support reviews and photos for both entry-linked and manually recorded historical winners. 109 * Record historical winners silently without triggering winner-award notifications. 110 * Keep publication of winner details on the giveaway page controlled by a separate checkbox. 111 112 = 1.0.12 = 113 * Select or upload multiple winner photos using the WordPress Media Library. 114 115 = 1.0.11 = 116 * Accept pasted HTML image tags in winner photo fields and preserve URL encoding. 117 118 = 1.0.10 = 119 * Display historical winner reviews and photos when the optional public name is blank. 120 121 = 1.0.9 = 122 * Add optional historical giveaway mode for silently recording and publishing past winners. 123 124 = 1.0.8 = 125 * Add optional public winner names, reviews, and photos on closed giveaway pages. 126 102 127 = 1.0.7 = 103 128 * Adds extension hooks so eligibility-aware add-ons can replace a premature Award winner link with their confirmation workflow. -
pi-giveaways/trunk/includes/class-pigi-admin.php
r3761409 r3830437 285 285 wp_enqueue_style( 'pigiveaways-admin-preview', PIGIVEAWAYS_URL . 'assets/admin-preview.css', array( 'pigiveaways-admin' ), PIGIVEAWAYS_VERSION ); 286 286 wp_enqueue_script( 'pigiveaways-admin', PIGIVEAWAYS_URL . 'assets/admin.js', array(), PIGIVEAWAYS_VERSION, true ); 287 if ( $screen && 'pigiveaways_giveaway' === $screen->post_type && 'post' === $screen->base && current_user_can( 'upload_files' ) ) { 288 wp_enqueue_media(); 289 wp_enqueue_script( 'pigiveaways-winner-photos', PIGIVEAWAYS_URL . 'assets/winner-photos.js', array( 'media-editor' ), PIGIVEAWAYS_VERSION, true ); 290 } 287 291 if ( false !== strpos( $hook, 'pigiveaways' ) ) { 288 292 $settings = wp_parse_args( get_option( $this->option, array() ), $this->defaults() ); … … 351 355 add_meta_box( 'pig-details', __( 'Giveaway Details', 'pi-giveaways' ), array( $this, 'details_box' ), 'pigiveaways_giveaway', 'normal', 'high' ); 352 356 add_meta_box( 'pig-form-builder', __( 'Giveaway Entry Form', 'pi-giveaways' ), array( $this, 'form_builder_box' ), 'pigiveaways_giveaway', 'normal', 'default' ); 357 add_meta_box( 'pig-winner-publication', __( 'Public Winners and Reviews', 'pi-giveaways' ), array( $this, 'winner_publication_box' ), 'pigiveaways_giveaway', 'normal', 'default' ); 358 } 359 360 public function winner_publication_box( $post ) { 361 $publication = (array) get_post_meta( $post->ID, '_pigiveaways_winner_publication', true ); 362 echo '<input type="hidden" name="pig_winner_publication_present" value="1">'; 363 echo '<p><label><input type="checkbox" name="pig_historical_giveaway" value="1" ' . checked( ! empty( $publication['historical'] ), true, false ) . '> ' . esc_html__( 'Historical giveaway: record past winners silently', 'pi-giveaways' ) . '</label></p>'; 364 echo '<p>' . esc_html__( 'Set the giveaway status to Ended or Awarded before recording historical winners.', 'pi-giveaways' ) . '</p>'; 365 echo '<p><label><input type="checkbox" name="pig_publish_winners" value="1" ' . checked( ! empty( $publication['enabled'] ), true, false ) . '> ' . esc_html__( 'Automatically display recorded winners on the closed giveaway page', 'pi-giveaways' ) . '</label></p>'; 366 echo '<p>' . esc_html__( 'This setting publishes winner names, reviews, and photos on Ended and Awarded giveaways. Enable it only with the winners’ permission. Paste image URLs, one per line, or paste HTML image tags.', 'pi-giveaways' ) . '</p>'; 367 foreach ( PIGI_Repository::publication_winner_slots( $post->ID ) as $award ) { 368 $row = $publication['winners'][ $award->id ] ?? array(); 369 $key = 'pig_public_winner[' . $award->id . ']'; 370 $label = trim( $award->first_name . ' ' . $award->last_name ); 371 echo '<fieldset><legend><strong>' . esc_html( $label ?: __( 'Historical winner', 'pi-giveaways' ) ) . '</strong></legend>'; 372 echo '<p><label>' . esc_html__( 'Public display name (optional)', 'pi-giveaways' ) . '<br><input class="regular-text" name="' . esc_attr( $key . '[name]' ) . '" value="' . esc_attr( $row['name'] ?? '' ) . '"></label></p>'; 373 echo '<p><label>' . esc_html__( 'Winner review', 'pi-giveaways' ) . '<br><textarea class="large-text" rows="4" name="' . esc_attr( $key . '[review]' ) . '">' . esc_textarea( $row['review'] ?? '' ) . '</textarea></label></p>'; 374 echo '<div data-pig-winner-photos>'; 375 if ( current_user_can( 'upload_files' ) ) { 376 echo '<p><button type="button" class="button" data-pig-choose-photos data-title="' . esc_attr__( 'Select or upload winner photos', 'pi-giveaways' ) . '" data-confirm="' . esc_attr__( 'Add photos', 'pi-giveaways' ) . '">' . esc_html__( 'Select or upload photos', 'pi-giveaways' ) . '</button></p>'; 377 } 378 echo '<p><label>' . esc_html__( 'Photo URLs (remove a line to remove a photo)', 'pi-giveaways' ) . '<br><textarea class="large-text" rows="3" name="' . esc_attr( $key . '[photos]' ) . '">' . esc_textarea( implode( "\n", $row['photos'] ?? array() ) ) . '</textarea></label></p></div>'; 379 echo '<p><label>' . esc_html__( 'Video or reel URLs (YouTube, Instagram or Facebook, one per line)', 'pi-giveaways' ) . '<br><textarea class="large-text" rows="3" name="' . esc_attr( $key . '[videos]' ) . '">' . esc_textarea( implode( "\n", $row['videos'] ?? array() ) ) . '</textarea></label></p></fieldset>'; 380 } 381 } 382 383 private function save_winner_publication( $post_id ) { 384 if ( ! isset( $_POST['pig_winner_publication_present'] ) ) { 385 return; 386 } 387 $submitted = (array) wp_unslash( $_POST['pig_public_winner'] ?? array() ); 388 $previous = (array) get_post_meta( $post_id, '_pigiveaways_winner_publication', true ); 389 $winners = (array) ( $previous['winners'] ?? array() ); 390 foreach ( PIGI_Repository::publication_winner_slots( $post_id ) as $award ) { 391 $row = $submitted[ $award->id ] ?? null; 392 if ( ! is_array( $row ) ) { 393 continue; 394 } 395 $winners[ $award->id ] = array( 396 'name' => sanitize_text_field( $row['name'] ?? '' ), 397 'review' => sanitize_textarea_field( $row['review'] ?? '' ), 398 'photos' => $this->parse_winner_photos( $row['photos'] ?? '' ), 399 'videos' => PIGI_Repository::winner_video_urls( $row['videos'] ?? '' ), 400 ); 401 } 402 update_post_meta( $post_id, '_pigiveaways_winner_publication', wp_slash( array( 403 'enabled' => isset( $_POST['pig_publish_winners'] ), 404 'historical' => isset( $_POST['pig_historical_giveaway'] ), 405 'winners' => $winners, 406 ) ) ); 407 } 408 409 private function parse_winner_photos( $input ) { 410 if ( ! is_string( $input ) ) { 411 return array(); 412 } 413 414 $candidates = array(); 415 $tags = new WP_HTML_Tag_Processor( $input ); 416 while ( $tags->next_tag( 'IMG' ) ) { 417 $src = $tags->get_attribute( 'src' ); 418 if ( is_string( $src ) ) { 419 $candidates[] = $src; 420 } 421 } 422 foreach ( preg_split( '/\R/', $input ) as $line ) { 423 if ( preg_match( '~^(https?://|//|/)~i', trim( $line ) ) && false === strpos( $line, '<' ) ) { 424 $candidates[] = $line; 425 } 426 } 427 428 $photos = array(); 429 foreach ( $candidates as $candidate ) { 430 $url = trim( $candidate ); 431 if ( 0 === strpos( $url, '//' ) ) { 432 $url = 'https:' . $url; 433 } elseif ( 0 === strpos( $url, '/' ) ) { 434 $url = home_url( $url ); 435 } 436 if ( ! preg_match( '~^https?://~i', $url ) ) { 437 continue; 438 } 439 $url = esc_url_raw( $url, array( 'http', 'https' ) ); 440 if ( wp_parse_url( $url, PHP_URL_HOST ) ) { 441 $photos[] = $url; 442 } 443 } 444 return array_values( array_unique( $photos ) ); 353 445 } 354 446 … … 522 614 update_post_meta( $post_id, '_pigiveaways_form_fields', $stored_fields ); 523 615 update_post_meta( $post_id, '_pigiveaways_form_mode', $mode ); 616 $this->save_winner_publication( $post_id ); 524 617 } 525 618 -
pi-giveaways/trunk/includes/class-pigi-frontend.php
r3751015 r3830437 241 241 echo '<p class="pig-related-event"><a href="' . esc_url( $d['event_url'] ) . '">' . esc_html__( 'View related event', 'pi-giveaways' ) . ' →</a></p>'; 242 242 } 243 $winners = ''; 244 if ( 'publish' === $post->post_status && ! post_password_required( $post ) && in_array( $state, array( 'ended', 'awarded' ), true ) ) { 245 $winners = $this->render_public_winners( $id ); 246 } 243 247 if ( 'active' === $state ) { 244 248 $this->form( $id, $d, $settings ); … … 246 250 echo '<p>' . esc_html__( 'This giveaway is coming soon.', 'pi-giveaways' ) . '</p>'; 247 251 } elseif ( 'ended' === $state ) { 248 echo '<p>' . esc_html __( 'Entries are closed. Any award will be assigned manually by the promoter.', 'pi-giveaways') . '</p>';252 echo '<p>' . esc_html( $winners ? __( 'Entries are closed.', 'pi-giveaways' ) : __( 'Entries are closed. Any award will be assigned manually by the promoter.', 'pi-giveaways' ) ) . '</p>'; 249 253 } elseif ( 'awarded' === $state ) { 250 254 $announcement = $d['announcement'] ? $d['announcement'] : __( 'The award has been announced.', 'pi-giveaways' ); … … 255 259 echo '<p>' . esc_html__( 'This giveaway is not accepting entries.', 'pi-giveaways' ) . '</p>'; 256 260 } 261 // The winner section escapes its data when building the markup. 262 echo $winners; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 257 263 echo '</div></section>'; 258 264 return ob_get_clean(); 265 } 266 267 private function render_public_winners( $id ) { 268 $publication = (array) get_post_meta( $id, '_pigiveaways_winner_publication', true ); 269 if ( empty( $publication['enabled'] ) ) { 270 return ''; 271 } 272 273 ob_start(); 274 foreach ( PIGI_Repository::publication_winner_slots( $id ) as $award ) { 275 $row = $publication['winners'][ $award->id ] ?? array(); 276 $initial = preg_match( '/^\p{L}/u', trim( (string) $award->last_name ), $match ) ? $match[0] . '.' : ''; 277 $name = $row['name'] ?? ''; 278 if ( '' === $name && empty( $row['review'] ) && empty( $row['photos'] ) && empty( $row['videos'] ) && 0 === strpos( (string) $award->id, 'historical-' ) ) { 279 continue; 280 } 281 if ( '' === $name ) { 282 $name = trim( $award->first_name . ' ' . $initial ); 283 } 284 echo '<article class="pig-winner"><h3>' . esc_html( $name ?: __( 'Giveaway winner', 'pi-giveaways' ) ) . '</h3>'; 285 if ( ! empty( $row['review'] ) ) { 286 echo '<div class="pig-winner-review">' . wp_kses_post( wpautop( esc_html( $row['review'] ) ) ) . '</div>'; 287 } 288 foreach ( $row['photos'] ?? array() as $photo ) { 289 echo '<img class="pig-winner-photo" src="' . esc_url( $photo, array( 'http', 'https' ) ) . '" loading="lazy" alt="' . esc_attr__( 'Photo shared by a giveaway winner', 'pi-giveaways' ) . '">'; 290 } 291 foreach ( $row['videos'] ?? array() as $video ) { 292 $this->render_winner_video( $id, $video ); 293 } 294 echo '</article>'; 295 } 296 $cards = ob_get_clean(); 297 return $cards ? '<section class="pig-winners"><h2>' . esc_html__( 'Giveaway Winners', 'pi-giveaways' ) . '</h2>' . $cards . '</section>' : ''; 298 } 299 300 private function render_winner_video( $post_id, $url ) { 301 if ( ! PIGI_Repository::winner_video_urls( $url ) ) { 302 return; 303 } 304 $host = strtolower( wp_parse_url( $url, PHP_URL_HOST ) ); 305 $path = wp_parse_url( $url, PHP_URL_PATH ); 306 $player = ''; 307 if ( preg_match( '~^(?:www\.|m\.)?instagram\.com$~', $host ) && preg_match( '~^/(reel|p|tv)/([A-Za-z0-9_-]+)/?$~', $path, $match ) ) { 308 $player = 'https://www.instagram.com/' . $match[1] . '/' . $match[2] . '/embed/'; 309 } elseif ( preg_match( '~^(?:(?:www\.|m\.)?facebook\.com|fb\.watch)$~', $host ) ) { 310 $player = add_query_arg( 'href', rawurlencode( $url ), 'https://www.facebook.com/plugins/video.php' ); 311 } 312 if ( $player ) { 313 echo '<div class="pig-winner-video"><iframe src="' . esc_url( $player ) . '" title="' . esc_attr__( 'Winner video', 'pi-giveaways' ) . '" width="500" height="480" style="max-width:100%;border:0" loading="lazy" allowfullscreen></iframe>'; 314 echo '<p><a href="' . esc_url( $url ) . '">' . esc_html__( 'Watch on the original platform', 'pi-giveaways' ) . '</a></p></div>'; 315 return; 316 } 317 $embed_url = preg_replace( '~^https://(?:www\.|m\.)?youtube\.com/shorts/([a-zA-Z0-9_-]{11})(?:[/?#].*)?$~i', 'https://www.youtube.com/watch?v=$1', $url ); 318 global $wp_embed; 319 $previous_post_id = $wp_embed->post_ID; 320 $previous_link = $wp_embed->linkifunknown; 321 $wp_embed->post_ID = $post_id; 322 $wp_embed->linkifunknown = false; 323 try { 324 $embed = $wp_embed->shortcode( array( 'discover' => false ), $embed_url ); 325 } finally { 326 $wp_embed->post_ID = $previous_post_id; 327 $wp_embed->linkifunknown = $previous_link; 328 } 329 echo '<div class="pig-winner-video">'; 330 if ( $embed && $embed_url !== $embed && esc_html( $embed_url ) !== $embed ) { 331 echo $embed; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- WordPress-generated oEmbed HTML. 332 } else { 333 echo '<a href="' . esc_url( $url ) . '">' . esc_html__( 'Watch the winner’s video', 'pi-giveaways' ) . '</a>'; 334 } 335 echo '</div>'; 259 336 } 260 337 -
pi-giveaways/trunk/includes/class-pigi-repository.php
r3761409 r3830437 177 177 } 178 178 179 public static function winner_video_urls( $input ) { 180 $urls = array(); 181 foreach ( preg_split( '/\R/', is_string( $input ) ? $input : '' ) as $line ) { 182 $url = esc_url_raw( trim( $line ), array( 'https' ) ); 183 if ( ! preg_match( '~^https://(?:www\.|m\.)?(?:youtube\.com|youtu\.be|instagram\.com|facebook\.com|fb\.watch)/[^\s]+$~i', $url ) ) { 184 continue; 185 } 186 $urls[] = $url; 187 } 188 return array_values( array_unique( $urls ) ); 189 } 190 191 public static function is_historical( $giveaway_id ) { 192 $publication = (array) get_post_meta( $giveaway_id, '_pigiveaways_winner_publication', true ); 193 $details = (array) get_post_meta( $giveaway_id, '_pigiveaways_details', true ); 194 return ! empty( $publication['historical'] ) && in_array( $details['status'] ?? '', array( 'ended', 'awarded' ), true ); 195 } 196 197 public static function publication_winner_slots( $giveaway_id ) { 198 $awards = array_values( array_filter( self::active_awards( $giveaway_id ), static function ( $award ) { 199 return 'winner' === $award->award_type; 200 } ) ); 201 if ( self::is_historical( $giveaway_id ) ) { 202 $remaining = self::winner_limit( $giveaway_id ) - count( $awards ); 203 for ( $slot = 1; $slot <= $remaining; ++$slot ) { 204 $awards[] = (object) array( 205 'id' => 'historical-' . $slot, 206 'first_name' => '', 207 'last_name' => '', 208 ); 209 } 210 } 211 return $awards; 212 } 213 179 214 public static function award( $entry_id, $note = '' ) { 180 215 global $wpdb; … … 183 218 return new WP_Error( 'invalid_entry', __( 'Only a valid entry can receive an award.', 'pi-giveaways' ) ); 184 219 } 220 $historical = self::is_historical( $entry->giveaway_id ); 185 221 $permission = apply_filters( 'pigiveaways_can_award_entry', true, $entry ); 186 222 if ( is_wp_error( $permission ) ) { … … 216 252 } 217 253 $award_id = (int) $wpdb->insert_id; 218 do_action( 'pigiveaways_winner_awarded', $award_id, $entry ); 254 if ( ! $historical ) { 255 do_action( 'pigiveaways_winner_awarded', $award_id, $entry ); 256 } 219 257 return $award_id; 220 258 } -
pi-giveaways/trunk/pi-giveaways.php
r3761409 r3830437 4 4 * Plugin URI: https://wordpress.org/plugins/pi-giveaways/ 5 5 * Description: Create giveaways, collect entries, and manually award winners through a focused, privacy-aware workflow. 6 * Version: 1.0. 76 * Version: 1.0.13 7 7 * Author: Ali Qureshi 8 8 * Author URI: https://www.parorrey.com/ … … 18 18 defined( 'ABSPATH' ) || exit; 19 19 20 define( 'PIGIVEAWAYS_VERSION', '1.0. 7' );20 define( 'PIGIVEAWAYS_VERSION', '1.0.13' ); 21 21 define( 'PIGIVEAWAYS_FILE', __FILE__ ); 22 22 define( 'PIGIVEAWAYS_DIR', plugin_dir_path( __FILE__ ) ); -
pi-giveaways/trunk/readme.txt
r3811301 r3830437 6 6 Tested up to: 7.1.5 7 7 Requires PHP: 7.4 8 Stable tag: 1.0. 78 Stable tag: 1.0.13 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 26 26 * Giveaway listings with current and past sections. 27 27 * Entry moderation, CSV export, and unlimited manual winner records. 28 * Winner reviews, Media Library photo selection, and YouTube, Instagram, or Facebook video/reel URLs. 29 * Historical giveaways with silent entry-linked or manually named winner records and separate opt-in public display. 28 30 * Entry confirmation and administrator notification emails through `wp_mail()`. 29 31 * Honeypot protection and optional Google reCAPTCHA v3. … … 100 102 == Changelog == 101 103 104 = 1.0.13 = 105 * Add a Select or upload photos button for each winner using the WordPress Media Library. 106 * Add a Video or reel URLs field alongside each winner’s photos and review, supporting YouTube, Instagram, and Facebook. 107 * Add optional Historical giveaway mode to record past winners from existing entries or by public display name when no entry is on file. 108 * Support reviews and photos for both entry-linked and manually recorded historical winners. 109 * Record historical winners silently without triggering winner-award notifications. 110 * Keep publication of winner details on the giveaway page controlled by a separate checkbox. 111 112 = 1.0.12 = 113 * Select or upload multiple winner photos using the WordPress Media Library. 114 115 = 1.0.11 = 116 * Accept pasted HTML image tags in winner photo fields and preserve URL encoding. 117 118 = 1.0.10 = 119 * Display historical winner reviews and photos when the optional public name is blank. 120 121 = 1.0.9 = 122 * Add optional historical giveaway mode for silently recording and publishing past winners. 123 124 = 1.0.8 = 125 * Add optional public winner names, reviews, and photos on closed giveaway pages. 126 102 127 = 1.0.7 = 103 128 * Adds extension hooks so eligibility-aware add-ons can replace a premature Award winner link with their confirmation workflow.
Note:
See TracChangeset
for help on using the changeset viewer.