Added support for global ad rotation
authorAlexander Ebert <ebert@woltlab.com>
Sun, 30 Apr 2017 12:23:51 +0000 (14:23 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 30 Apr 2017 12:23:51 +0000 (14:23 +0200)
See #2256

com.woltlab.wcf/option.xml
constants.php
wcfsetup/install/files/lib/system/ad/AdHandler.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index abe9d06790fcdf809b7134f468455a8954724495..99b1cc392a9fcac05fec55fd258d2753307c2500 100644 (file)
                                <optiontype>boolean</optiontype>
                                <defaultvalue>0</defaultvalue>
                        </option>
+                       <option name="enable_ad_rotation">
+                               <categoryname>general.page</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <defaultvalue>1</defaultvalue>
+                               <options>module_wcf_ad</options>
+                       </option>
                        <option name="head_code">
                                <categoryname>general.page</categoryname>
                                <optiontype>textarea</optiontype>
index 396eb740c708deb44467367b18f09a072fa5b1a0..b136507a6e69a58e0ba6c20e6f5ca90f0cbaee88 100644 (file)
@@ -220,3 +220,4 @@ define('OG_IMAGE', '');
 define('HEAD_CODE', '');
 define('AVATAR_DEFAULT_TYPE', 'initials');
 define('ARTICLE_ENABLE_VISIT_TRACKING', 1);
+define('ENABLE_AD_ROTATION', 1);
index 9bc072e5a210612ac3ff6c34b909af7b8d9032bb..9e18f5773152c69cd1971979a07caa950199dd6b 100644 (file)
@@ -45,8 +45,25 @@ class AdHandler extends SingletonFactory {
                        return '';
                }
                
-               $output = '';
+               /** @var Ad[] $ads */
+               $ads = [];
                foreach ($this->ads[$this->objectTypes[$adLocation]->objectTypeID] as $ad) {
+                       $ads[] = $ad;
+               }
+               
+               if (ENABLE_AD_ROTATION && count($ads) > 1) {
+                       $ads = [
+                               $ads[mt_rand(0, count($ads) - 1)]
+                       ];
+                       
+                       $a = [0, 0];
+                       for ($i = 0; $i < 10000; $i++) {
+                               $a[mt_rand(0, 1)]++;
+                       }
+               }
+               
+               $output = '';
+               foreach ($ads as $ad) {
                        $conditions = $ad->getConditions();
                        foreach ($conditions as $condition) {
                                if (!$condition->getObjectType()->getProcessor()->showContent($condition)) {
index d6e14ea3bc30aabe7a7a0dbb5ed44a978b37f44b..ec6ab48b2656ed9522e171c91f544b7005f3de51 100644 (file)
@@ -1267,6 +1267,8 @@ GmbH=Gesellschaft mit beschränkter Haftung]]></item>
                <item name="wcf.acp.option.avatar_default_type.initials"><![CDATA[Initialen]]></item>
                <item name="wcf.acp.option.avatar_default_type.silhouette"><![CDATA[Silhouette]]></item>
                <item name="wcf.acp.option.article_enable_visit_tracking"><![CDATA[Gelesen-Markierung für Artikel aktivieren]]></item>
+               <item name="wcf.acp.option.enable_ad_rotation"><![CDATA[Werbung abwechselnd anzeigen]]></item>
+               <item name="wcf.acp.option.enable_ad_rotation.description"><![CDATA[Sobald einer Position mehr als eine Werbung zugewiesen sein, so wird bei jedem Aufruf eine zufällige Werbung angezeigt. Bei Deaktivierung dieser Option werden alle Werbungen parallel angezeigt.]]></item>
        </category>
        
        <category name="wcf.acp.package">
index 7378d63a7cd441214309685272f9a1c7b38f126e..39a9e99887c0598a56dcbfb8366b8e578025c661 100644 (file)
@@ -1270,6 +1270,8 @@ Examples for medium ID detection:
                <item name="wcf.acp.option.avatar_default_type.initials"><![CDATA[Initials]]></item>
                <item name="wcf.acp.option.avatar_default_type.silhouette"><![CDATA[Silhouette]]></item>
                <item name="wcf.acp.option.article_enable_visit_tracking"><![CDATA[Enable “mark as read” for articles]]></item>
+               <item name="wcf.acp.option.enable_ad_rotation"><![CDATA[Enable ad rotation]]></item>
+               <item name="wcf.acp.option.enable_ad_rotation.description"><![CDATA[If there is more than one ad per placeholder, a random ad will be displayed every time. Disabling this option will display all ads simultaneously.]]></item>
        </category>
        
        <category name="wcf.acp.package">