YaWK  24.1
Yet another WebKit
YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock Class Reference

Detect and react to user's installed AdBlocker. More...

Public Member Functions

 __construct ($db)
 Load all widget settings from database and fill object. More...
 
 init ()
 The main function to init fuckAdBlock. More...
 

Public Attributes

 $adBlockJS = ''
 
 $footerBtnCode = ''
 
 $fuckAdBlockBtnClass = ''
 
 $fuckAdBlockHighBtnText = ''
 
 $fuckAdBlockLevel = ''
 
 $fuckAdBlockLoadingType = ''
 
 $fuckAdBlockLowBtnText = ''
 
 $fuckAdBlockText = ''
 
 $fuckAdBlockTitle = ''
 
 $headerBtnCode = ''
 
 $widget = ''
 

Detailed Description

Detect and react to user's installed AdBlocker.

AdBlock Blocker Widget

If your website relay on advertising, this widget may be helpful. It can detect, if user has an AdBlocker installed. You can set different levels (low or high) - which means that you can say please disable your adblocker or force the user to disable, otherwise he dont see any content. Messages, title and buttons can get customized.

Author
Daniel Retzl danie.nosp@m.lret.nosp@m.zl@gm.nosp@m.ail..nosp@m.com
Version
1.0.0

Definition at line 17 of file fuckadblock.php.

Constructor & Destructor Documentation

◆ __construct()

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::__construct (   $db)

Load all widget settings from database and fill object.

Parameters
object$dbDatabase Object

Load all widget settings on object init.

Definition at line 47 of file fuckadblock.php.

49  {
50  // load this widget settings from db
51  $this->widget = new \YAWK\widget();
52  $settings = $this->widget->getWidgetSettingsArray($db);
53  foreach ($settings as $property => $value) {
54  $this->$property = $value;
55  }
56 
if(isset($_POST['save'])) $settings
$value

References $db, $settings, $value, and YAWK\widget\getWidgetSettingsArray().

Member Function Documentation

◆ init()

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::init ( )

The main function to init fuckAdBlock.

Prepare properties and init fuckAdBlock

Definition at line 62 of file fuckadblock.php.

64  {
65  echo "<script src=\"system/engines/fuckAdBlock/fuckAdBlock.js\"></script>";
66 
67  // check priority levels -
68  // high means that the user needs to disable his adblocker to see the content
69  if ($this->fuckAdBlockLevel === "high")
70  { // current url, this will be the url that will be loaded if user click on footerBtn
71  $link = $_SERVER['REQUEST_URI'];
72  $this->footerBtnCode = '<a href="'.$link.'" class="'.$this->fuckAdBlockBtnClass.'" style="color:#fff; text-shadow: none;">'.$this->fuckAdBlockHighBtnText.'</a>';
73  // strong toughness: no ability to close window, so no header button.
74  $this->headerBtnCode = '';
75  // force loadingType on every pageLoad
76  $this->fuckAdBlockLoadingType = "onPageLoad";
77  }
78  // low generates a more fair-use user-friendy de-clickable info message box.
79  if ($this->fuckAdBlockLevel === "low")
80  { // the 'ok, f*ck off and dismiss button'
81  $this->footerBtnCode = '<button type="button" class="'.$this->fuckAdBlockBtnClass.'" data-dismiss="modal">'.$this->fuckAdBlockLowBtnText.'</button>';
82  // the close button
83  $this->headerBtnCode = '<button type="button" class="close" data-dismiss="modal">&times;</button>';
84  }
85  // if loadingType = string (onPageLoad) the adBlock warning gets thrown on every page load.
86  if (is_string($this->fuckAdBlockLoadingType) && ($this->fuckAdBlockLoadingType === "onPageLoad"))
87  {
88  $this->adBlockJS = "
89  <script type=\"text/javascript\">
90  $( document ).ready(function() {
91  // Function called if AdBlock is not detected
92  function adBlockNotDetected() {
93  // alert('AdBlock is not enabled');
94  }
95 
96  // Function called if AdBlock is detected
97  function adBlockDetected() {
98  // alert('AdBlock is enabled');
99  // $('#myModal').modal('show');
100  $('#myModal').modal({backdrop: 'static', keyboard: false})
101  }
102 
103  // Recommended audit because AdBlock lock the file 'fuckadblock.js'
104  // If the file is not called, the variable does not exist 'fuckAdBlock'
105  // This means that AdBlock is present
106  if(typeof fuckAdBlock === 'undefined') {
107  adBlockDetected();
108  }
109  else {
110  fuckAdBlock.onDetected(adBlockDetected);
111  fuckAdBlock.onNotDetected(adBlockNotDetected);
112  // and|or
113  fuckAdBlock.on(true, adBlockDetected);
114  fuckAdBlock.on(false, adBlockNotDetected);
115  // and|or
116  fuckAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected);
117  }
118  });
119  </script>";
120  }
121  else
122  { // check if loadingType is numeric or integer to show adblock every x seconds
123  if (is_numeric($this->fuckAdBlockLoadingType) || (is_int($this->fuckAdBlockLoadingType)))
124  {
125  // wrap a setInterval function around adblock to show up every x seconds
126  $this->adBlockJS = "
127  <script type=\"text/javascript\">
128  $( document ).ready(function() {
129  var timerID = setInterval(function() {
130 
131  // Function called if AdBlock is not detected
132  function adBlockNotDetected() {
133  // alert('AdBlock is not enabled');
134  }
135  // Function called if AdBlock is detected
136  function adBlockDetected() {
137  // alert('AdBlock is enabled');
138  // $('#myModal').modal('show');
139  $('#myModal').modal({backdrop: 'static', keyboard: false})
140  }
141  // Recommended audit because AdBlock lock the file 'fuckadblock.js'
142  // If the file is not called, the variable does not exist 'fuckAdBlock'
143  // This means that AdBlock is present
144  if(typeof fuckAdBlock === 'undefined') {
145  adBlockDetected();
146  } else {
147  fuckAdBlock.onDetected(adBlockDetected);
148  fuckAdBlock.onNotDetected(adBlockNotDetected);
149  // and|or
150  fuckAdBlock.on(true, adBlockDetected);
151  fuckAdBlock.on(false, adBlockNotDetected);
152  // and|or
153  fuckAdBlock.on(true, adBlockDetected).onNotDetected(adBlockNotDetected);
154  }
155  }, $this->fuckAdBlockLoadingType * 1000);
156  // clearInterval(timerID); // The setInterval it cleared and doesn't run anymore.
157  });</script>";
158  }
159  }
160 
161 // $_GET['widgetID'] will be generated in \YAWK\widget\loadWidgets($db, $position)
162 
163 echo" <!-- Modal -->
164  <div id=\"myModal\" class=\"modal fade\" role=\"dialog\">
165  <div class=\"modal-dialog\">
166 
167  <!-- Modal content-->
168  <div class=\"modal-content\">
169  <div class=\"modal-header\">
170  $this->headerBtnCode
171  <h4>$this->fuckAdBlockTitle</h4>
172  </div>
173  <div class=\"modal-body\">
174  $this->fuckAdBlockText
175  </div>
176  <div class=\"modal-footer\">
177  $this->footerBtnCode
178  </div>
179  </div>
180  </div>
181  </div>";
182 
183  // output fuckAdBlock JS code
184  echo $this->adBlockJS;

References YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock\$adBlockJS.

Member Data Documentation

◆ $adBlockJS

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$adBlockJS = ''
Parameters
stringAblock JavaScript

Definition at line 40 of file fuckadblock.php.

Referenced by YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock\init().

◆ $footerBtnCode

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$footerBtnCode = ''
Parameters
stringfooter html markup

Definition at line 36 of file fuckadblock.php.

◆ $fuckAdBlockBtnClass

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockBtnClass = ''
Parameters
stringButton class

Definition at line 32 of file fuckadblock.php.

◆ $fuckAdBlockHighBtnText

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockHighBtnText = ''
Parameters
stringHigh level button text

Definition at line 30 of file fuckadblock.php.

◆ $fuckAdBlockLevel

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockLevel = ''
Parameters
stringLevel of strongness

Definition at line 26 of file fuckadblock.php.

◆ $fuckAdBlockLoadingType

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockLoadingType = ''
Parameters
stringLoading Type (on page load or every x seconds)

Definition at line 34 of file fuckadblock.php.

◆ $fuckAdBlockLowBtnText

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockLowBtnText = ''
Parameters
stringLow level button text

Definition at line 28 of file fuckadblock.php.

◆ $fuckAdBlockText

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockText = ''
Parameters
stringAdBlock custom text

Definition at line 24 of file fuckadblock.php.

◆ $fuckAdBlockTitle

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$fuckAdBlockTitle = ''
Parameters
stringText that will be shown as title

Definition at line 22 of file fuckadblock.php.

◆ $headerBtnCode

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$headerBtnCode = ''
Parameters
stringheader html markup

Definition at line 38 of file fuckadblock.php.

◆ $widget

YAWK\WIDGETS\FUCKADBLOCK\BLOCK\fuckadblock::$widget = ''
Parameters
objectglobal widget object data

Definition at line 20 of file fuckadblock.php.


The documentation for this class was generated from the following file: