Ad rotation: Display the first suitable ad after shuffle
authorAlexander Ebert <ebert@woltlab.com>
Sat, 19 May 2018 21:31:47 +0000 (23:31 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 19 May 2018 21:31:47 +0000 (23:31 +0200)
The previous implementation just picked one ad and tried to display it, regardless if it should be displayed based on the condition. The change will show the first random ad that fulfills the display conditions.

wcfsetup/install/files/lib/system/ad/AdHandler.class.php

index 803f77ce02180bb364a7668677227ee39a875da0..79703f05b879dd1c753e03d667624f553b590d17 100644 (file)
@@ -51,11 +51,7 @@ class AdHandler extends SingletonFactory {
                        $ads[] = $ad;
                }
                
-               if (ENABLE_AD_ROTATION && count($ads) > 1) {
-                       $ads = [
-                               $ads[mt_rand(0, count($ads) - 1)]
-                       ];
-               }
+               if (ENABLE_AD_ROTATION) shuffle($ads);
                
                $output = '';
                foreach ($ads as $ad) {
@@ -67,6 +63,7 @@ class AdHandler extends SingletonFactory {
                        }
                        
                        $output .= '<div>' . $ad->ad . '</div>';
+                       if (ENABLE_AD_ROTATION) break;
                }
                
                if (!empty($output)) {