affilinet Performance Ads - Version 1.9.4

Version Description

  • Release Date: March 9, 2018
  • Fix: Suppress warnings on file write for ads.txt
Download this release

Release Info

Developer Affilinet
Plugin Icon 128x128 affilinet Performance Ads
Version 1.9.4
Comparing to
See all releases

Code changes from version 1.9.3 to 1.9.4

Files changed (4) hide show
  1. affilinet.php +1 -1
  2. classes/Plugin.php +50 -40
  3. readme.txt +5 -1
  4. views/settings.php +19 -0
affilinet.php CHANGED
@@ -3,7 +3,7 @@
3
  /*
4
  Plugin Name: affilinet Performance Ads
5
  Description: Integrate our data driven and automated performance display plugin into your WordPress platform and serve your users targeted ads in real time.
6
- Version: 1.9.3
7
  Author: affilinet
8
  Author URI: https://www.affili.net/de/publisher/tools/performance-ads
9
  Text Domain: affilinet-performance-module
3
  /*
4
  Plugin Name: affilinet Performance Ads
5
  Description: Integrate our data driven and automated performance display plugin into your WordPress platform and serve your users targeted ads in real time.
6
+ Version: 1.9.4
7
  Author: affilinet
8
  Author URI: https://www.affili.net/de/publisher/tools/performance-ads
9
  Text Domain: affilinet-performance-module
classes/Plugin.php CHANGED
@@ -23,25 +23,7 @@ class Affilinet_Plugin
23
 
24
 
25
  // check for ads.txt
26
-
27
- // manual update
28
- add_action( 'upgrader_process_complete', array($this, 'plugin_upgraded'));
29
- // manual activation
30
-
31
- register_activation_hook( AFFILINET_PLUGIN_FILE, array( $this, 'plugin_upgraded' ) );
32
-
33
- // check for version changes
34
- $pluginVersion = get_file_data( AFFILINET_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'affilinet.php', array( 'Version' => 'Version' ), 'plugin' );
35
- if ( get_option( 'affilinet-performance-ads-version', false ) !== $pluginVersion['Version'] ) {
36
- $this->plugin_upgraded();
37
- update_option( 'affilinet-performance-ads-version', $pluginVersion['Version'] );
38
- }
39
-
40
- // if file was deleted restore it
41
- $filePath = ABSPATH . DIRECTORY_SEPARATOR . 'ads.txt';
42
- if ( ! file_exists( $filePath ) ) {
43
- $this->plugin_upgraded();
44
- }
45
  }
46
 
47
  function admin_notice() {
@@ -54,6 +36,17 @@ class Affilinet_Plugin
54
  </div>
55
  <?php
56
  }
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
 
59
 
@@ -262,32 +255,49 @@ class Affilinet_Plugin
262
  echo Affilinet_Yieldkit::getAdCode();
263
  }
264
 
 
 
 
 
265
 
266
- public function plugin_upgraded() {
267
  // check for correct ads.txt
268
 
269
- $filePath = ABSPATH.DIRECTORY_SEPARATOR.'ads.txt';
270
-
271
- $neededContent =
272
- '# affilinet-performance-module-start' . PHP_EOL .
273
- '# Do not modify the following lines' . PHP_EOL .
274
- '# Ver. 1.9.1' . PHP_EOL .
275
- 'appnexus.com, 8332, RESELLER, f5ab79cb980f11d1' . PHP_EOL .
276
- 'appnexus.com, 8327, RESELLER, f5ab79cb980f11d1' . PHP_EOL .
277
- 'appnexus.com, 8334, RESELLER, f5ab79cb980f11d1' . PHP_EOL .
278
- 'appnexus.com, 8333, RESELLER, f5ab79cb980f11d1'. PHP_EOL .
279
- '# affilinet-performance-module-end' . PHP_EOL;
280
-
281
- if (file_exists($filePath)) {
282
- $adsTxtFile = file_get_contents($filePath);
283
- if (strpos($adsTxtFile, $neededContent) === false) {
284
- // write to file
285
- file_put_contents($filePath, PHP_EOL . $neededContent, FILE_APPEND);
286
- }
287
- }else {
288
- file_put_contents($filePath, $neededContent, FILE_APPEND);
289
  }
290
 
291
  }
292
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
293
  }
23
 
24
 
25
  // check for ads.txt
26
+ $this->updateAdsTxtOnDemand();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  }
28
 
29
  function admin_notice() {
36
  </div>
37
  <?php
38
  }
39
+
40
+ if (!$this->adsTxtExistsAndIsUpToDate()) {
41
+ ?>
42
+ <div class="notice notice-warning is-dismissible">
43
+ <p><?php _e('<strong>affilinet Performance Ads:</strong><br> Missing ads.txt file. Please see instructions on settings page ', 'affilinet-performance-module' ); ?>
44
+ <a class="button" href="admin.php?page=affilinet_settings"><?php _e('Check your settings.', 'affilinet-performance-module');?></a>
45
+ </p>
46
+ </div>
47
+ <?php
48
+ }
49
+
50
  }
51
 
52
 
255
  echo Affilinet_Yieldkit::getAdCode();
256
  }
257
 
258
+ public static function adsTxtExistsAndIsUpToDate() {
259
+ $filePath = ABSPATH.'ads.txt';
260
+ return file_exists($filePath) && strpos(file_get_contents($filePath), self::getAdsTxtContent()) !== false;
261
+ }
262
 
263
+ public function updateAdsTxtOnDemand() {
264
  // check for correct ads.txt
265
 
266
+ $filePath = ABSPATH.'ads.txt';
267
+
268
+ if (!$this->adsTxtExistsAndIsUpToDate()) {
269
+ $this->writeAdsTxt($filePath, $this->getAdsTxtContent());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  }
271
 
272
  }
273
 
274
+ public static function getAdsTxtContent() {
275
+ return '# affilinet-performance-module-start' . PHP_EOL .
276
+ '# Do not modify the following lines' . PHP_EOL .
277
+ '# Ver. 1.9.1' . PHP_EOL .
278
+ 'appnexus.com, 8332, RESELLER, f5ab79cb980f11d1' . PHP_EOL .
279
+ 'appnexus.com, 8327, RESELLER, f5ab79cb980f11d1' . PHP_EOL .
280
+ 'appnexus.com, 8334, RESELLER, f5ab79cb980f11d1' . PHP_EOL .
281
+ 'appnexus.com, 8333, RESELLER, f5ab79cb980f11d1'. PHP_EOL .
282
+ '# affilinet-performance-module-end' . PHP_EOL;
283
+ }
284
+
285
+ private function writeAdsTxt($filePath, $content) {
286
+
287
+ try
288
+ {
289
+ $fp = @fopen($filePath, "a+");
290
+ if ( !$fp ) {
291
+ throw new Exception('File open failed.');
292
+ }
293
+ @fwrite($fp, $content);
294
+ @fclose($fp);
295
+
296
+
297
+ } catch ( Exception $e ) {
298
+ // no output intended
299
+ }
300
+
301
+ }
302
+
303
  }
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: affilinet, teraone
3
  Tags: Affiliate, affilinet, advertising, banner, performance marketing
4
  Requires at least: 3.0.1
5
  Tested up to: 4.9
6
- Stable tag: 1.9.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -79,6 +79,10 @@ It may take up to 90 minutes for ads to show, additionally all publisher account
79
 
80
  == Changelog ==
81
 
 
 
 
 
82
  = 1.9.3 =
83
  * Release Date: March 6, 2018
84
  * Fix: Update ads.txt on Plugin version change
3
  Tags: Affiliate, affilinet, advertising, banner, performance marketing
4
  Requires at least: 3.0.1
5
  Tested up to: 4.9
6
+ Stable tag: 1.9.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
79
 
80
  == Changelog ==
81
 
82
+ = 1.9.4 =
83
+ * Release Date: March 9, 2018
84
+ * Fix: Suppress warnings on file write for ads.txt
85
+
86
  = 1.9.3 =
87
  * Release Date: March 6, 2018
88
  * Fix: Update ads.txt on Plugin version change
views/settings.php CHANGED
@@ -153,6 +153,25 @@
153
 
154
  </table>
155
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  <?php
157
  if ( function_exists('submit_button')) {
158
  submit_button();
153
 
154
  </table>
155
 
156
+ <?php
157
+ if (Affilinet_Plugin::adsTxtExistsAndIsUpToDate() === false) {
158
+ ?>
159
+ <div class="wrap">
160
+ <h2 class="alert">Ads.txt Error:</h2>
161
+ <p>The Plugin could not create an ads.txt file in your root folder. <br>
162
+ Please create a file named 'ads.txt' in your root folder (next to wp-config.php) with the following content:
163
+ <br>
164
+ This file is needed to improve your revenue.
165
+ <a href="https://iabtechlab.com/ads-txt/" target="_blank">Details about ads.txt.</a>
166
+
167
+ </div>
168
+ <textarea cols="60" rows="10"><?php echo Affilinet_Plugin::getAdsTxtContent(); ?></textarea>
169
+ </div>
170
+
171
+ <?php
172
+ }
173
+ ?>
174
+
175
  <?php
176
  if ( function_exists('submit_button')) {
177
  submit_button();