From 725e7ddc51118db357b39998a179dd6db71b72a1 Mon Sep 17 00:00:00 2001 From: Marcelo Vani Date: Fri, 3 Mar 2017 12:21:44 +0000 Subject: [PATCH 1/5] #2349001; implemented hook_uninstall --- dfp.admin.inc | 7 +++++++ dfp.install | 8 ++++++++ dfp.module | 3 +++ 3 files changed, 18 insertions(+) diff --git a/dfp.admin.inc b/dfp.admin.inc index a01fe6b..bfbe4af 100644 --- a/dfp.admin.inc +++ b/dfp.admin.inc @@ -156,6 +156,13 @@ function dfp_admin_settings($form, $form_state) { ), ), ); + $form['global_display_options']['dfp_set_centering'] = array( + '#type' => 'checkbox', + '#title' => t('Set DFP Ad Centering'), + '#default_value' => variable_get('dfp_set_centering', 0), + '#description' => t('Enables/disables centering of ads. This mode must be set before the service is enabled. Centering is disabled by default. In legacy gpt_mobile.js, centering is enabled by default.'), + ); + // Global targeting options. $form['targeting_settings'] = array( diff --git a/dfp.install b/dfp.install index 0a64ccf..ad09014 100644 --- a/dfp.install +++ b/dfp.install @@ -129,6 +129,14 @@ function dfp_install() { } } +/** + * Implements hook_uninstall(). + */ +function dfp_uninstall() { + // Delete variables. + variable_del('dfp_set_centering'); +} + /** * Migrate existing DART tags to DFP tags. Note: this migration will destroy * the any DFP global settings that have already been set. diff --git a/dfp.module b/dfp.module index 51b249d..b61fe48 100644 --- a/dfp.module +++ b/dfp.module @@ -709,6 +709,9 @@ function _dfp_js_global_settings() { if (variable_get('dfp_disable_init_load', 0)) { $js .= ' googletag.pubads().disableInitialLoad();' . "\n"; } + if (variable_get('dfp_set_centering', 0)) { + $js .= ' googletag.pubads().setCentering(true);' . "\n"; + } // Set global targeting values for this page. $targeting = variable_get('dfp_targeting', array()); From 7cd2e364a9029c7dd68f653054f27ab9dc3ed296 Mon Sep 17 00:00:00 2001 From: Marcelo Vani Date: Fri, 3 Mar 2017 12:28:33 +0000 Subject: [PATCH 2/5] #2383341; Applied patch --- dfp.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dfp.module b/dfp.module index 51b249d..5c5c3d4 100644 --- a/dfp.module +++ b/dfp.module @@ -556,15 +556,15 @@ function dfp_format_targeting($targeting, $tag = '') { $target['target'] = '"' . check_plain($target['target']) . '"'; $target['value'] = token_replace(check_plain($target['value']), $data, array('sanitize' => TRUE, 'clear' => TRUE)); + // Allow other modules to alter the target. + drupal_alter('dfp_target', $target); + // The target value could be blank if tokens are used. If so, removed it. if (empty($target['value'])) { unset($targeting[$key]); continue; } - // Allow other modules to alter the target. - drupal_alter('dfp_target', $target); - // Convert the values into an array and trim the whitespace from each value. $values = explode(',', $target['value']); $values = array_map('trim', $values); From c317a2469ab429fc7b7da9b1f33eda95237b1c5b Mon Sep 17 00:00:00 2001 From: Marcelo Vani Date: Fri, 3 Mar 2017 12:30:41 +0000 Subject: [PATCH 3/5] #2383919; Applied patch --- dfp.admin.inc | 8 ++++---- dfp.module | 5 ++++- tests/dfp.test | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/dfp.admin.inc b/dfp.admin.inc index a01fe6b..a6819e3 100644 --- a/dfp.admin.inc +++ b/dfp.admin.inc @@ -436,14 +436,14 @@ function dfp_breakpoint_form_validate($element, &$form_state) { form_error($element['browser_size'], t('The browser size cannot be empty if ad size(s) exists.')); } elseif (!empty($element['browser_size']['#value']) && empty($element['ad_sizes']['#value'])) { - form_error($element['ad_sizes'], t('The ad size(s) cannot be empty if a browser size exists.')); + form_error($element['ad_sizes'], t('The ad size(s) cannot be empty if a browser size exists. If you wish to suppress an ad slot for a given browser size, you can enter "!none" in the ad size(s) field.', array('!none' => htmlspecialchars('')))); } if (!empty($element['browser_size']['#value']) && !empty($element['ad_sizes']['#value'])) { if (preg_match('/[^x|0-9]/', $element['browser_size']['#value'])) { form_error($element['browser_size'], t('The browser size can only contain numbers and the character x.')); } - elseif (preg_match('/[^x|,|0-9]/', $element['ad_sizes']['#value'])) { - form_error($element['ad_sizes'], t('The ad size(s) can only contain numbers, the character x and commas.')); + elseif ($element['ad_sizes']['#value'] != '' && preg_match('/[^x|,|0-9]/', $element['ad_sizes']['#value'])) { + form_error($element['ad_sizes'], t('The ad size(s) string can only contain numbers, the character x and commas (unless it is the special keyword "!none").', array('!none' => htmlspecialchars('')))); } } } @@ -569,7 +569,7 @@ function _dfp_breakpoint_form(&$form, $key, $data = array()) { ); if (empty($data)) { $form['breakpoints'][$key]['browser_size']['#description'] = t('Example: 1024x768'); - $form['breakpoints'][$key]['ad_sizes']['#description'] = t('Example: 300x600,300x250'); + $form['breakpoints'][$key]['ad_sizes']['#description'] = t('Example: 300x600,300x250. Enter "!none" to suppress this slot for a given browser size.', array('!none' => htmlspecialchars(''))); } } diff --git a/dfp.module b/dfp.module index 51b249d..c3ea4a4 100644 --- a/dfp.module +++ b/dfp.module @@ -746,7 +746,10 @@ function _dfp_js_slot_definition($tag) { $breakpoints = $tag->breakpoints; $js .= 'var mapping = googletag.sizeMapping()' . "\n"; foreach ($breakpoints as $breakpoint) { - $js .= ' .addSize(' . dfp_format_size($breakpoint['browser_size']) . ', ' . dfp_format_size($breakpoint['ad_sizes']) . ')' . "\n"; + // If the ad sizes string contains the special keyword "," use an + // empty size list in order to suppress slot display. + $ad_sizes = strpos($breakpoint['ad_sizes'], '') !== FALSE ? '' : $breakpoint['ad_sizes']; + $js .= ' .addSize(' . dfp_format_size($breakpoint['browser_size']) . ', ' . dfp_format_size($ad_sizes) . ')' . "\n"; } $js .= ' .build();' . "\n"; } diff --git a/tests/dfp.test b/tests/dfp.test index 48480fa..99497ad 100644 --- a/tests/dfp.test +++ b/tests/dfp.test @@ -181,7 +181,7 @@ class dfpDisplayTagTest extends dfpBaseTest { $edit['breakpoints[0][browser_size]'] = $this->dfpGenerateSize(); $edit['breakpoints[0][ad_sizes]'] = $this->randomName(8); $this->editTag($tag->machinename, $edit); - $this->assertText(t('The ad size(s) can only contain numbers, the character x and commas.'), 'An error was correctly thrown when invalid characters.'); + $this->assertText(t('The ad size(s) string can only contain numbers, the character x and commas (unless it is the special keyword "!none").', array('!none' => htmlspecialchars(''))), 'An error was correctly thrown when the Ad Size(s) field contained an invalid pattern.'); } function testSlug() { From 63b2fd58faa3481f35c29de8a152be933910739a Mon Sep 17 00:00:00 2001 From: Marcelo Vani Date: Mon, 6 Mar 2017 11:25:53 +0000 Subject: [PATCH 4/5] Re-rolled patch --- dfp.module | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dfp.module b/dfp.module index e1ad37e..775a133 100755 --- a/dfp.module +++ b/dfp.module @@ -554,15 +554,15 @@ function dfp_format_targeting($targeting, $tag = '') { $target['target'] = '"' . check_plain($target['target']) . '"'; $target['value'] = dfp_token_replace(check_plain($target['value']), $tag, array('sanitize' => TRUE, 'clear' => TRUE)); + // Allow other modules to alter the target. + drupal_alter('dfp_target', $target); + // The target value could be blank if tokens are used. If so, removed it. if (empty($target['value'])) { unset($targeting[$key]); continue; } - // Allow other modules to alter the target. - drupal_alter('dfp_target', $target); - // Convert the values into an array and trim the whitespace from each value. $values = explode(',', $target['value']); $values = array_map('trim', $values); From b9f8ed6329c41ba15a9deaf0a08d5b0a94e71223 Mon Sep 17 00:00:00 2001 From: Marcelo Vani Date: Tue, 4 Apr 2017 10:46:14 +0100 Subject: [PATCH 5/5] Removed wrong merge --- dfp.admin.inc | 8 ++++---- dfp.module | 5 +---- tests/dfp.test | 2 +- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/dfp.admin.inc b/dfp.admin.inc index 1b7b9eb..ce0f01f 100644 --- a/dfp.admin.inc +++ b/dfp.admin.inc @@ -469,14 +469,14 @@ function dfp_breakpoint_form_validate($element, &$form_state) { form_error($element['browser_size'], t('The browser size cannot be empty if ad size(s) exists.')); } elseif (!empty($element['browser_size']['#value']) && empty($element['ad_sizes']['#value'])) { - form_error($element['ad_sizes'], t('The ad size(s) cannot be empty if a browser size exists. If you wish to suppress an ad slot for a given browser size, you can enter "!none" in the ad size(s) field.', array('!none' => htmlspecialchars('')))); + form_error($element['ad_sizes'], t('The ad size(s) cannot be empty if a browser size exists.')); } if (!empty($element['browser_size']['#value']) && !empty($element['ad_sizes']['#value'])) { if (preg_match('/[^x|0-9]/', $element['browser_size']['#value'])) { form_error($element['browser_size'], t('The browser size can only contain numbers and the character x.')); } - elseif ($element['ad_sizes']['#value'] != '' && preg_match('/[^x|,|0-9]/', $element['ad_sizes']['#value'])) { - form_error($element['ad_sizes'], t('The ad size(s) string can only contain numbers, the character x and commas (unless it is the special keyword "!none").', array('!none' => htmlspecialchars('')))); + elseif (preg_match('/[^x|,|0-9]/', $element['ad_sizes']['#value'])) { + form_error($element['ad_sizes'], t('The ad size(s) can only contain numbers, the character x and commas.')); } } } @@ -602,7 +602,7 @@ function _dfp_breakpoint_form(&$form, $key, $data = array()) { ); if (empty($data)) { $form['breakpoints'][$key]['browser_size']['#description'] = t('Example: 1024x768'); - $form['breakpoints'][$key]['ad_sizes']['#description'] = t('Example: 300x600,300x250. Enter "!none" to suppress this slot for a given browser size.', array('!none' => htmlspecialchars(''))); + $form['breakpoints'][$key]['ad_sizes']['#description'] = t('Example: 300x600,300x250'); } } diff --git a/dfp.module b/dfp.module index 169fac4..1e96a4f 100755 --- a/dfp.module +++ b/dfp.module @@ -753,10 +753,7 @@ function _dfp_js_slot_definition($tag) { $breakpoints = $tag->breakpoints; $js .= 'var mapping = googletag.sizeMapping()' . "\n"; foreach ($breakpoints as $breakpoint) { - // If the ad sizes string contains the special keyword "," use an - // empty size list in order to suppress slot display. - $ad_sizes = strpos($breakpoint['ad_sizes'], '') !== FALSE ? '' : $breakpoint['ad_sizes']; - $js .= ' .addSize(' . dfp_format_size($breakpoint['browser_size']) . ', ' . dfp_format_size($ad_sizes) . ')' . "\n"; + $js .= ' .addSize(' . dfp_format_size($breakpoint['browser_size']) . ', ' . dfp_format_size($breakpoint['ad_sizes']) . ')' . "\n"; } $js .= ' .build();' . "\n"; } diff --git a/tests/dfp.test b/tests/dfp.test index d4bc621..c8d344c 100644 --- a/tests/dfp.test +++ b/tests/dfp.test @@ -192,7 +192,7 @@ class dfpDisplayTagTest extends dfpBaseTest { $edit['breakpoints[0][browser_size]'] = $this->dfpGenerateSize(); $edit['breakpoints[0][ad_sizes]'] = $this->randomName(8); $this->editTag($tag->machinename, $edit); - $this->assertText(t('The ad size(s) string can only contain numbers, the character x and commas (unless it is the special keyword "!none").', array('!none' => htmlspecialchars(''))), 'An error was correctly thrown when the Ad Size(s) field contained an invalid pattern.'); + $this->assertText(t('The ad size(s) can only contain numbers, the character x and commas.'), 'An error was correctly thrown when invalid characters.'); } function testSlug() {