Plugin Directory

Changeset 1837049


Ignore:
Timestamp:
03/09/2018 02:12:01 PM (8 years ago)
Author:
Affilinet
Message:

Fix: Suppress warnings on file write for ads.txt

Location:
affilinet-performance-module
Files:
74 added
4 edited
3 copied

Legend:

Unmodified
Added
Removed
  • affilinet-performance-module/tags/1.9.4/affilinet.php

    r1834651 r1837049  
    44Plugin Name: affilinet Performance Ads
    55Description: 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
     6Version: 1.9.4
    77Author: affilinet
    88Author URI: https://www.affili.net/de/publisher/tools/performance-ads
  • affilinet-performance-module/tags/1.9.4/readme.txt

    r1834651 r1837049  
    44Requires at least: 3.0.1
    55Tested up to: 4.9
    6 Stable tag: 1.9.3
     6Stable tag: 1.9.4
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8080== Changelog ==
    8181
     82= 1.9.4 =
     83* Release Date: March 9, 2018
     84* Fix: Suppress warnings on file write for ads.txt
     85
    8286= 1.9.3 =
    8387* Release Date: March 6, 2018
  • affilinet-performance-module/trunk/affilinet.php

    r1834636 r1837049  
    44Plugin Name: affilinet Performance Ads
    55Description: 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
     6Version: 1.9.4
    77Author: affilinet
    88Author URI: https://www.affili.net/de/publisher/tools/performance-ads
  • affilinet-performance-module/trunk/classes/Plugin.php

    r1834651 r1837049  
    2424
    2525        // 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 
    35         // check for version changes
    36         $pluginVersion = get_file_data( AFFILINET_PLUGIN_DIR . DIRECTORY_SEPARATOR . 'affilinet.php', array( 'Version' => 'Version' ), 'plugin' );
    37         if ( get_option( 'affilinet-performance-ads-version', false ) !== $pluginVersion['Version'] ) {
    38             $this->plugin_upgraded();
    39             update_option( 'affilinet-performance-ads-version', $pluginVersion['Version'] );
    40         }
    41 
    42         // if file was deleted restore it
    43         $filePath = ABSPATH . DIRECTORY_SEPARATOR . 'ads.txt';
    44         if ( ! file_exists( $filePath ) ) {
    45             $this->plugin_upgraded();
    46         }
    47 
     26        $this->updateAdsTxtOnDemand();
    4827    }
    4928
     
    5837            <?php
    5938        }
     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
    6050    }
    6151
     
    266256    }
    267257
    268 
    269     public function plugin_upgraded() {
     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() {
    270264        // check for correct ads.txt
    271265
    272         $filePath = ABSPATH.DIRECTORY_SEPARATOR.'ads.txt';
    273 
    274         $neededContent =
    275             '# 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         if (file_exists($filePath)) {
    285             $adsTxtFile = file_get_contents($filePath);
    286             if (strpos($adsTxtFile, $neededContent) === false) {
    287                 // write to file
    288                 file_put_contents($filePath, PHP_EOL . $neededContent, FILE_APPEND);
    289             }
    290         }else {
    291             file_put_contents($filePath, $neededContent, FILE_APPEND);
    292         }
     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        }
    293300
    294301    }
  • affilinet-performance-module/trunk/readme.txt

    r1834636 r1837049  
    44Requires at least: 3.0.1
    55Tested up to: 4.9
    6 Stable tag: 1.9.3
     6Stable tag: 1.9.4
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    8080== Changelog ==
    8181
     82= 1.9.4 =
     83* Release Date: March 9, 2018
     84* Fix: Suppress warnings on file write for ads.txt
     85
    8286= 1.9.3 =
    8387* Release Date: March 6, 2018
  • affilinet-performance-module/trunk/views/settings.php

    r1624836 r1837049  
    155155
    156156        <?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
    157176        if ( function_exists('submit_button')) {
    158177            submit_button();
Note: See TracChangeset for help on using the changeset viewer.