Skip to content
Browse files

Merge pull request #76 from nickdaugherty/master

Add robots.txt entries for ad provider's crawler automatically, if applicable.
  • Loading branch information...
2 parents 89e8260 + 840beb7 commit c0637400be33d145af7d507612102d97ad60e8f5 @nickdaugherty nickdaugherty committed May 2, 2013
View
2 .gitignore
@@ -1,2 +1,4 @@
.svn
wpcom-helper.php
+
+.DS_Store
View
32 common/lib/acm-provider.php
@@ -18,6 +18,7 @@ class ACM_Provider {
public $output_tokens = array();
public $ad_tag_ids;
public $ad_code_args = array();
+ public $crawler_user_agent;
function __construct() {
if ( empty( $this->ad_code_args ) ) {
// This is not actual data, but rather format:
@@ -40,5 +41,36 @@ function __construct() {
if ( empty( $this->output_html ) ) {
$this->output_html = '<script type="text/javascript" src="%url%"></script>';
}
+
+ if ( ! empty( $this->crawler_user_agent ) ) {
+ $should_do_robotstxt = apply_filters( 'acm_should_do_robotstxt', true, $this );
+
+ if ( true === $should_do_robotstxt )
+ add_action( 'do_robotstxt', array( $this, 'action_do_robotstxt' ), 10 );
+ }
+ }
+
+ public function action_do_robotstxt() {
+ $public = get_option( 'blog_public' );
+
+ $disallowed = array();
+
+ if ( '0' == $public ) {
+ $disallowed[] = '/';
+ } else {
+ $disallowed[] = '';
+ }
+
+ $disallowed = apply_filters( 'acm_robotstxt_disallow', $disallowed, $this );
+
+ // If we have no disallows to add, don't add anything (including User-agent)
+ if ( ! is_array( $disallowed ) || empty( $disallowed ) )
+ return;
+
+ echo 'User-agent: ' . $this->crawler_user_agent . PHP_EOL;
+
+ foreach ( $disallowed as $disallow ) {
+ echo 'Disallow: ' . $disallow . PHP_EOL;
+ }
}
}
View
1 providers/doubleclick-for-publishers-async.php
@@ -1,6 +1,7 @@
<?php
class Doubleclick_For_Publishers_Async_ACM_Provider extends ACM_Provider {
+ public $crawler_user_agent = 'Mediapartners-Google';
public function __construct() {
View
2 providers/doubleclick-for-publishers.php
@@ -9,6 +9,8 @@ class Doubleclick_For_Publishers_Columns {
}
class Doubleclick_For_Publishers_ACM_Provider extends ACM_Provider {
+ public $crawler_user_agent = 'Mediapartners-Google';
+
function __construct() {
// Default output HTML
$this->output_html = '<script type="text/javascript" src="%url%"></script>';
View
1 providers/google-adsense.php
@@ -3,6 +3,7 @@
* Google AdSense Ad Provider for Ad Code manager
*/
class Google_AdSense_ACM_Provider extends ACM_Provider {
+ public $crawler_user_agent = 'Mediapartners-Google';
/**
* Register default options for Google AdSense
View
5 readme.txt
@@ -3,7 +3,7 @@ Contributors: rinatkhaziev, jeremyfelt, danielbachhuber, carldanley, zztimur, au
Tags: advertising, ad codes, ads, adsense, dfp, doubleclick for publishers
Requires at least: 3.1
Tested up to: 3.6-beta1
-Stable tag: 0.4.1
+Stable tag: 0.4.2
Manage your ad codes through the WordPress admin in a safe and easy way.
@@ -56,6 +56,9 @@ Flush the cache when adding or deleting ad codes, and set priority of 10 when a
== Changelog ==
+= 0.4.2 (May. 1, 2013) =
+* Added robots.txt entries for provider's crawlers
+
= 0.4.1 (Apr. 27, 2013) =
* Disabled rendering of ads on preview to avoid crawling errors. Thanks [Paul Gibbs](https://github.com/paulgibbs)
* Bug fix: Corrected "medium rectangle" ad size for DFP Async Provider. Thanks [Marco](https://github.com/NRG-R9T)

0 comments on commit c063740

Please sign in to comment.
Something went wrong with that request. Please try again.