View source
<?php
define('PREBID_VERSION_DOCS', '1.0');
define('PREBID_VERSION', '1.0');
define('PREBID_JS_FILE', 'prebid.js');
function prebid_libraries_info() {
$url_text = t('Prebid @version Publisher API Changes', array(
'@version' => PREBID_VERSION_DOCS,
));
$url_api_path = 'http://prebid.org/dev-docs/prebid-' . PREBID_VERSION_DOCS . '-API.html';
$libraries['prebidjs'] = array(
'name' => 'Prebid.js',
'vendor url' => 'http://prebid.org',
'download url' => 'http://prebid.org/download.html',
'git url' => 'https://github.com/prebid/Prebid.js.git',
'version arguments' => array(
'file' => PREBID_JS_FILE,
'pattern' => '/v(\\d.+)/',
'lines' => 1,
),
'error message' => t('Prebid JS library must be installed and at minimum version @version. To download see the !download. For API documentation see !url', array(
'@version' => PREBID_VERSION,
'!download' => l(t('download page'), 'http://prebid.org/download.html'),
'!url' => l($url_text, $url_api_path),
)),
'files' => array(
'js' => array(
PREBID_JS_FILE => array(
'type' => 'file',
'group' => JS_DEFAULT,
'every_page' => TRUE,
'weight' => -5,
'force header' => TRUE,
),
),
),
);
return $libraries;
}
function prebid_ctools_plugin_type() {
ctools_include('utility');
$items = array();
ctools_passthrough('prebid', 'plugin-type', $items);
return $items;
}
function prebid_ctools_plugin_api($owner, $api) {
if ($owner == 'prebid' && $api == 'prebid') {
return array(
'version' => 1,
'path' => drupal_get_path('module', 'prebid') . '/includes',
);
}
}
function prebid_preprocess_html(&$variables) {
if (($library = libraries_load('prebidjs')) && !empty($library['loaded'])) {
$options = $library['files']['js'][PREBID_JS_FILE];
$options['weight'] += 1;
drupal_add_js(drupal_get_path('module', 'prebid') . '/js/prebid.dfp.js', $options);
ctools_include('bidder', 'prebid');
$bidders = prebid_get_bidders();
$settings = array(
'prebidSettings' => array(
'bidders' => $bidders,
'buckets' => prebid_get_price_granularity(),
'global' => prebid_get_global_settings(),
'adUnits' => array(),
),
);
drupal_add_js($settings, 'setting');
}
}
function prebid_preprocess_dfp_tag(&$variables) {
$tag = $variables['tag'];
$name = $tag->machinename;
ctools_include('bidder', 'prebid');
$bidders = prebid_get_bidders();
foreach ($bidders as $bidder) {
$class = ctools_plugin_get_class($bidder, 'handler');
if ($class) {
$plugin = new $class();
$plugin
->init($bidder, $tag);
}
else {
$plugin = new stdClass();
$plugin->plugin = $bidder;
}
$settings = array(
'dfpTags' => array(
$name => array(
'bidderAdapters' => array(
$plugin->plugin,
),
),
),
);
drupal_add_js($settings, 'setting');
}
}