-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdfw.php
executable file
·62 lines (47 loc) · 1.58 KB
/
dfw.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
Plugin Name: Fubra DoubleClick for WordPress
Description: Responsive DoubleClick ads in WordPress. Modified copy of https://wordpress.org/plugins/doubleclick-for-wp/
Version: 1.0.0
*/
global $DoubleClick;
include('dfw-init.php');
// Get json file with size configurations
$sizeMap = json_decode( file_get_contents( dirname(__FILE__) . '/sizemap.json' ), TRUE );
// Internal helper function
function _str_clean($s) {
$s = strtolower($s);
$s = str_replace(' ', '', $s);
return $s;
}
// Template function
function dfp( $ad, $type, $user_map = NULL ) {
global $DoubleClick, $sizeMap;
// Error html
$err = '<h1 style="color:white;background:red;padding:10px;font-size:25px;">';
$err .= 'DFP AD ERROR - ';
$err .= '<a style="color:white;text-decoration:underline;" target="_blank" href="https://github.com/fubralimited/fubra-dfp-wp">';
$err .= 'Check Documentation</a></h1>';
// Check ad code is set
$ad = _str_clean($ad);
if( !$ad ) return $err;
// Start with empty size map
$map = array();
// Check if a custom map was defined
if ( isset($user_map) ) {
$user_map = _str_clean($user_map);
$map = explode( ',', $user_map );
$map = array_combine( array_keys($DoubleClick->breakpoints), $map );
// Format size string if set
} else if ( isset($type) ) {
$type = _str_clean($type);
$map = $sizeMap[$type];
// Else return err
} else { return $err; }
// Return ad code
return $DoubleClick->place_ad( $ad, $map );
}
// Shortcode function
add_shortcode('dfp', function($args){
return dfp( $args['ad'], $args['type'], $args['map'] );
});