YaWK  24.1
Yet another WebKit
fuckadblock.php
Go to the documentation of this file.
1 <?php
3 {
4  /**
5  * @details<b>AdBlock Blocker Widget</b>
6  *
7  * <p>If your website relay on advertising, this widget may be helpful. It can detect, if
8  * user has an AdBlocker installed. You can set different levels (low or high) - which means
9  * that you can say please disable your adblocker or force the user to disable, otherwise he
10  * dont see any content. Messages, title and buttons can get customized.</p>
11  *
12  *
13  * @author Daniel Retzl <[email protected]>
14  * @copyright 2018 Daniel Retzl
15  * @version 1.0.0
16  * @brief Detect and react to user's installed AdBlocker.
17  */
18  class fuckadblock
19  {
20  /** @param object global widget object data */
21  public $widget = '';
22  /** @param string Text that will be shown as title */
23  public $fuckAdBlockTitle = '';
24  /** @param string AdBlock custom text */
25  public $fuckAdBlockText = '';
26  /** @param string Level of strongness */
27  public $fuckAdBlockLevel = '';
28  /** @param string Low level button text */
29  public $fuckAdBlockLowBtnText = '';
30  /** @param string High level button text */
31  public $fuckAdBlockHighBtnText = '';
32  /** @param string Button class */
33  public $fuckAdBlockBtnClass = '';
34  /** @param string Loading Type (on page load or every x seconds) */
35  public $fuckAdBlockLoadingType = '';
36  /** @param string footer html markup */
37  public $footerBtnCode = '';
38  /** @param string header html markup */
39  public $headerBtnCode = '';
40  /** @param string Ablock JavaScript */
41  public $adBlockJS = '';
42 
43  /**
44  * @brief Load all widget settings from database and fill object
45  * @param object $db Database Object
46  * @brief Load all widget settings on object init.
47  */
48  public function __construct($db)
49  {
50  // load this widget settings from db
51  $this->widget = new \YAWK\widget();
53  foreach ($settings as $property => $value) {
54  $this->$property = $value;
55  }
56 
57  }
58 
59  /**
60  * @brief The main function to init fuckAdBlock
61  * @brief Prepare properties and init fuckAdBlock
62  */
63  public function init()
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;
185  }
186  }
187 }
Detect and react to user's installed AdBlocker.
Definition: fuckadblock.php:18
__construct($db)
Load all widget settings from database and fill object.
Definition: fuckadblock.php:47
init()
The main function to init fuckAdBlock.
Definition: fuckadblock.php:62
Widgets are small, useful tools that you can include everywhere in your website.
Definition: widget.php:22
getWidgetSettingsArray($db)
Get widget settings and return it as array.
Definition: widget.php:69
if(isset($_POST['save'])) $settings
$value