Commit 3ed3a9a3 authored by Aaron Dudenhofer's avatar Aaron Dudenhofer Committed by Jonathan Sacksick

Add the Commerce Kickstart DFP module.

Change-Id: I8daaef38a44a5f9e9634a71f0234e8a0de7dcfb1
Reviewed-on: https://code.drupalcommerce.org/661Tested-by: 's avatarJenkinsCG <jenkins@drupalcommerce.org>
Reviewed-by: 's avatarJonathan Sacksick <jonathan.sacksick@gmail.com>
parent de4eb168
......@@ -110,6 +110,7 @@ dependencies[] = commerce_kickstart_payment
dependencies[] = commerce_kickstart_comment
dependencies[] = commerce_kickstart_migrate
dependencies[] = commerce_kickstart_service_provider
dependencies[] = commerce_kickstart_dfp
; System Requirements.
php_memory_limit = 128M
name = Commerce Kickstart DFP
description = Provides in-distribution content for Commerce Kickstart.
core = 7.x
package = Commerce Kickstart
<?php
/**
* @file
* Sets a status message when DFP is enabled.
*/
/**
* Implements hook_enable().
*/
function commerce_kickstart_dfp_enable() {
// Only display the message if the activation of the module is done after the
// installation of the distribution.
if (variable_get('install_task') == 'done') {
if (!variable_get('commerce_kickstart_dfp_eula', FALSE)) {
$t = get_t();
drupal_set_message($t('The Commerce Kickstart DFP module requires you to accept the !eula before displaying content.', array('!eula' => l('Privacy Policy and User Agreement','admin/config/services/dfp'))), 'warning');
}
}
}
<?php
/**
* @file
* Creates a "Commerce Kickstart DFP" Page to accept the EULA.
* Also checks that EULA is accepted before displaying DFP information.
*/
/**
* Implements hook_page_build().
*/
function commerce_kickstart_dfp_page_build(&$page) {
// Check that the dfp eula has been accepted.
if (variable_get('commerce_kickstart_dfp_eula', FALSE)) {
$current_path = current_path();
$dfp_settings = module_invoke_all('commerce_kickstart_dfp_paths');
// Check if it's a DFP path.
if (!empty($dfp_settings[$current_path])) {
// Add defaults settings.
$dfp_settings[$current_path] += array(
'dfp_id' => drupal_html_id('div-gpt-ad-' . REQUEST_TIME),
'dfp_position' => 'before',
'dfp_height' => 60,
'dfp_width' => 468,
);
drupal_add_css(drupal_get_path('module', 'commerce_kickstart_dfp') . '/theme/commerce_kickstart_dfp.css');
drupal_add_js('//www.googletagservices.com/tag/js/gpt.js');
drupal_add_js(array(
'dfp' => $dfp_settings[$current_path],
), 'setting');
drupal_add_js(drupal_get_path('module', 'commerce_kickstart_dfp') . '/js/commerce_kickstart_dfp.js');
}
}
}
/**
* Implements hook_commerce_kickstart_dfp_paths().
*/
function commerce_kickstart_dfp_commerce_kickstart_dfp_paths() {
// List of paths that display dfp content and campaign information.
$dfp_settings = array(
'admin/commerce/products' => array(
'dfp_selector' => '.page-admin-commerce-products #title-wrapper',
'dfp_class' => array('dfp-products'),
'dfp_unit' => 'Kickstart_Products_Admin',
),
'admin/commerce/orders' => array(
'dfp_selector' => '.page-admin-commerce-orders #title-wrapper',
'dfp_class' => array('dfp-orders'),
'dfp_unit' => 'Kickstart_Orders_Admin',
),
'admin/commerce/jirafe' => array(
'dfp_selector' => '.page-admin-commerce-jirafe #block-system-main .content:not(:has(#jirafe))',
'dfp_class' => array('dfp-jirafe'),
'dfp_position' => 'after',
'dfp_height' => 540,
'dfp_width' => 960,
'dfp_unit' => 'Kickstart_Jirafe',
),
'admin/commerce/customer-profiles' => array(
'dfp_selector' => '.page-admin-commerce-customer-profiles #title-wrapper',
'dfp_class' => array('dfp-customer-profiles'),
'dfp_unit' => 'Kickstart_Customer_Profile',
),
'admin/commerce/config/shipping' => array(
'dfp_selector' => '.page-admin-commerce-config-shipping ul.action-links',
'dfp_class' => array('dfp-shipping'),
'dfp_unit' => 'Kickstart_Shipping',
),
'admin/commerce/config/taxes' => array(
'dfp_selector' => '.page-admin-commerce-config-taxes ul.action-links',
'dfp_class' => array('dfp-taxes'),
'dfp_position' => 'before',
'dfp_unit' => 'Kickstart_Taxes',
),
'admin/commerce/config/payment-methods' => array(
'dfp_selector' => '.page-admin-commerce-config-payment-methods ul.action-links',
'dfp_class' => array('dfp-payment-methods'),
'dfp_unit' => 'Kickstart_Payment_Methods',
),
);
return $dfp_settings;
}
/**
* Implements hook_menu().
*/
function commerce_kickstart_dfp_menu() {
$items['admin/config/services/dfp'] = array(
'title' => 'Commerce Kickstart DFP',
'description' => 'Enable or disable the DFP media.',
'page callback' => 'drupal_get_form',
'page arguments' => array('commerce_kickstart_dfp_settings_form'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Creates the DFP Acceptance form.
*/
function commerce_kickstart_dfp_settings_form($form, &$form_state) {
$form['#attached']['css'] = array(
drupal_get_path('module', 'commerce_kickstart_dfp') . '/theme/commerce_kickstart_dfp.css',
);
$eula = '<p>' . t('While we have a rather long, boring Privacy Policy just like any other technology company, here is a short summary of some key items we feel are important:') . '</p>';
$items = array();
$dfp_link = l("Google's DoubleClick for Publishers (\"DFP\")", "http://www.google.com/dfp/info/sb/index.html", array('attributes' => array('target' => '_blank')));
$items[] = t("Commerce Kickstart makes use of !dfp;", array('!dfp' => $dfp_link));
$items[] = t('We use DFP to show you content relevant to Drupal Commerce at various points and places in Commerce Kickstart, including during installation;');
$items[] = t('DFP is a third-party technology. It uses audience management tags which collect and use certain data;');
$items[] = t('Commerce Guys does not collect any personally identifiable information;');
$items[] = t('If at any time after installation you do not want us to utilize DFP through Commerce Kickstart, you can easily opt out of it;');
$eula .= theme('item_list', array('items' => $items));
$eula_link = l('Privacy Policy and User Agreement', 'https://marketplace.commerceguys.com/privacy/commerce-kickstart', array('attributes' => array('target' => '_blank')));
$eula .= '<p>' . t('That is it for the main points. The full !policy can be viewed on our website. Thank you again for choosing Commerce Kickstart!', array('!policy' => $eula_link)) . '</p>';
$form['description'] = array(
'#type' => 'item',
'#title' => t('For Commerce Kickstart DFP to work, you must accept the Privacy Policy and User Agreement.'),
);
$form['eula'] = array(
'#prefix' => '<div id="eula-accept">',
'#markup' => $eula,
);
$form['commerce_kickstart_dfp_eula'] = array(
'#title' => t('I agree to the Privacy Policy and User Agreement'),
'#type' => 'checkbox',
'#default_value' => variable_get('commerce_kickstart_dfp_eula', FALSE),
'#suffix' => '</div>',
);
$form['actions'] = array(
'#type' => 'actions',
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t("Save"),
'#weight' => 10,
);
return system_settings_form($form);
}
/**
* Implements hook_requirements().
*/
function commerce_kickstart_dfp_requirements($phase) {
$requirements = array();
if ($phase == 'runtime') {
// Check that the EULA Agreement is accepted.
if (variable_get('commerce_kickstart_dfp_eula', FALSE)) {
$requirements['dfp'] = array(
'title' => t('Commerce Kickstart DFP'),
'value' => t('End User License Agreement Accepted'),
'severity' => REQUIREMENT_OK,
);
}
else {
$requirements['dfp'] = array(
'title' => t('Commerce Kickstart DFP'),
'value' => t('Acceptance Required'),
'severity' => REQUIREMENT_WARNING,
'description' => t('You can not display DFP content until the <a href="@url">End User License Agreement</a> has been accepted', array('@url' => url('admin/config/services/dfp'))),
);
}
}
return $requirements;
}
(function ($) {
Drupal.behaviors.commerceKickstartDfpAdmin = {
attach: function (context, settings) {
// Setting the variables from dfp_settings array.
var dfpSelector = Drupal.settings.dfp.dfp_selector;
var dfpClass = Drupal.settings.dfp.dfp_class;
var dfpPosition = Drupal.settings.dfp.dfp_position;
var dfpHeight = parseInt(Drupal.settings.dfp.dfp_height);
var dfpWidth = parseInt(Drupal.settings.dfp.dfp_width);
var dfpId = Drupal.settings.dfp.dfp_id;
var dfpUnit = Drupal.settings.dfp.dfp_unit;
// Wrapping titles for header placement consistency between standard and overlay.
$('.page-admin-commerce-orders h1:not(#overlay-content h1, #page h1, #title-wrapper h1)').wrap('<div id="title-wrapper" />');
$('.page-admin-commerce-products h1:not(#overlay-content h1, #page h1, #title-wrapper h1)').wrap('<div id="title-wrapper" />');
$('.page-admin-commerce-customer-profiles h1:not(#overlay-content h1, #page h1, #title-wrapper h1)').wrap('<div id="title-wrapper" />');
// DFP placement script.
$(dfpSelector, context).once('commerce-kickstart-dfp', function () {
if (typeof googletag != 'undefined') {
var slot = $('<div id="dfp-wrapper"><div id="' + dfpId + '" class="dfp-unit ' + dfpClass.join(' ') + '"></div></div>');
if (dfpPosition == 'before') {
$(this).prepend(slot);
} else {
$(this).append(slot);
}
googletag.cmd.push(function() {
googletag.defineSlot('/17601239/' + dfpUnit, [dfpWidth, dfpHeight], dfpId).addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
googletag.display(dfpId);
}
});
}
};
})(jQuery);
#eula-accept {
background: #f4f4f4;
border: 1px solid #edebeb;
max-width: 600px;
padding: 0 20px 10px;
font-size: .9em;
line-height: 1.5em;
}
#eula-accept ul {
margin-bottom: 20px;
}
#eula-accept ul li {
margin-bottom: 10px;
}
#eula-accept .form-type-checkbox label.option {
line-height: 2em;
}
#dfp-wrapper {
float: right;
}
#dfp-wrapper .dfp-unit {
background: transparent url("offline.png") no-repeat 0 0;
}
#title-wrapper #dfp-wrapper {
margin: 0 0 10px 0;
}
/* Overlay Specific Styles */
.commerce-kickstart-dfp-processed h1.page-title,
.commerce-kickstart-dfp-processed h1#overlay-title {
padding-top: 35px;
padding-bottom: 0;
}
#overlay-titlebar #title-wrapper #dfp-wrapper {
margin: 10px 65px 0 0;
}
.page-admin-commerce-customer-profiles #overlay-titlebar #title-wrapper #dfp-wrapper {
margin: 10px 65px 10px 0;
}
/* DFP Page Specific Styles */
/* 468x60 Style Sizes */
.dfp-unit {
height: 60px;
width: 468px;
}
.dfp-jirafe {
height: 540px;
width: 960px;
}
.page-admin-commerce-jirafe #dfp-wrapper {
float: none;
padding-top: 20px;
}
......@@ -320,3 +320,13 @@ html.js #-commerce-kickstart-help-store fieldset.collapsible {
.page-admin-commerce-jirafe #overlay #overlay-content #page {
padding: 0 0 30px;
}
/* Customer Profiles Fix */
.view-commerce-customer-profiles .views-exposed-form #edit-name-wrapper {
width: 520px;
}
.view-commerce-customer-profiles .views-exposed-form label {
float: left;
margin-right: 15px;
}
......@@ -292,3 +292,11 @@ html.js #-commerce-kickstart-help-store fieldset.collapsible {
.page-admin-commerce-jirafe #overlay #overlay-content #page {
padding: 0 0 30px;
}
/* Customer Profiles Fix */
.view-commerce-customer-profiles .views-exposed-form #edit-name-wrapper {
width: 520px;
}
.view-commerce-customer-profiles .views-exposed-form label {
float: left;
margin-right:15px;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment