Skip to content

Commit bb86022

Browse files
committed
Initial Commit. V 0.1.0
0 parents  commit bb86022

16 files changed

+2501
-0
lines changed

.gitignore

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Numerous always-ignore extensions
2+
*.diff
3+
*.err
4+
*.orig
5+
*.log
6+
*.rej
7+
*.swo
8+
*.swp
9+
*.vi
10+
*~
11+
*.sass-cache
12+
13+
# OS or Editor folders
14+
.DS_Store
15+
Thumbs.db
16+
.cache
17+
.project
18+
.settings
19+
.tmproj
20+
*.esproj
21+
nbproject
22+
*.sublime-project
23+
*.sublime-workspace
24+
25+
# Dreamweaver added files
26+
_notes
27+
dwsync.xml
28+
29+
# Komodo
30+
*.komodoproject
31+
.komodotools
32+
33+
# Folders to ignore
34+
.hg
35+
.svn
36+
.CVS
37+
intermediate
38+
.idea
39+
cache

LICENSE

+339
Large diffs are not rendered by default.

inc/class.csv_importer.php

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* Managing CSV Files
4+
*
5+
* Description.
6+
*
7+
* @link http://www.chriswgerber.com/dfp-ads
8+
* @since
9+
*
10+
* @package WordPress
11+
* @subpackage DFP-Ads
12+
*/
13+
14+
class CSV_Importer {
15+
16+
/**
17+
* @var
18+
*/
19+
private $fp;
20+
21+
/**
22+
* @var
23+
*/
24+
private $parse_header;
25+
26+
/**
27+
* @var
28+
*/
29+
private $delimiter;
30+
31+
/**
32+
* @var
33+
*/
34+
private $length;
35+
36+
/**
37+
* @param string $file_name
38+
* @param bool $parse_header
39+
* @param string $delimiter
40+
* @param int $length
41+
*/
42+
public function __construct( $file_name, $parse_header = false, $delimiter = "\t", $length = 8000 ) {
43+
$this->fp = fopen( $file_name, "r" );
44+
$this->parse_header = $parse_header;
45+
$this->delimiter = $delimiter;
46+
$this->length = $length;
47+
$this->lines = $lines;
48+
49+
if ( $this->parse_header ) {
50+
$this->header = fgetcsv( $this->fp, $this->length, $this->delimiter );
51+
}
52+
53+
}
54+
55+
/**
56+
* PHP5 Destruct
57+
*/
58+
public function __destruct() {
59+
if ( $this->fp ) {
60+
fclose( $this->fp );
61+
}
62+
}
63+
64+
/**
65+
* @param int $max_lines
66+
*
67+
* @return array
68+
*/
69+
public function get( $max_lines = 0 ) {
70+
//if $max_lines is set to 0, then get all the data
71+
$data = array();
72+
if ( $max_lines > 0 ) {
73+
$line_count = 0;
74+
} else {
75+
$line_count = -1; // so loop limit is ignored
76+
}
77+
78+
while ( $line_count < $max_lines && ( $row = fgetcsv( $this->fp, $this->length, $this->delimiter ) ) !== FALSE ) {
79+
if ( $this->parse_header ) {
80+
foreach ( $this->header as $i => $heading_i ) {
81+
$row_new[$heading_i] = $row[$i];
82+
}
83+
$data[] = $row_new;
84+
} else {
85+
$data[] = $row;
86+
}
87+
88+
if ( $max_lines > 0 ) {
89+
$line_count ++;
90+
}
91+
}
92+
93+
return $data;
94+
}
95+
}

inc/class.dfp_ad_position.php

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* Class for Ad Positions
4+
*
5+
* Holds data for an ad position.
6+
*
7+
* @link http://www.chriwgerber.com/dfp-ads/
8+
* @since 0.0.1
9+
*
10+
* @package WordPress
11+
* @subpackage DFP-Ads
12+
*/
13+
14+
class DFP_Ad_Position {
15+
16+
/**
17+
* ID of the CPT
18+
*
19+
* @access public
20+
* @since 0.0.1
21+
*
22+
* @var int
23+
*/
24+
public $post_id;
25+
26+
/**
27+
* Title of the position
28+
*
29+
* @access public
30+
* @since 0.0.1
31+
*
32+
* @var string
33+
*/
34+
public $title;
35+
36+
/**
37+
* Name of the Ad Slot
38+
* Ex. SNG_ROS_Leaderboard
39+
*
40+
* @access public
41+
* @since 0.0.1
42+
*
43+
* @var string
44+
*/
45+
public $ad_name;
46+
47+
/**
48+
* Div ID of the ad position
49+
* Ex. div-gpt-ad-1375829763909
50+
*
51+
* @access public
52+
* @since 0.0.1
53+
*
54+
* @var string
55+
*/
56+
public $position_tag;
57+
58+
/**
59+
* Ad sizes. Slot with multiple sizes needs to be nested.
60+
* Ex. [728, 90] or [ [728, 90], [970, 90] ]
61+
*
62+
* @access public
63+
* @since 0.0.1
64+
*
65+
* @var array
66+
*/
67+
public $sizes = [];
68+
69+
/**
70+
* Defines whether the slot should include Out of Page position
71+
*
72+
* @access public
73+
* @since 0.0.1
74+
*
75+
* @var bool
76+
*/
77+
public $out_of_page = false;
78+
79+
/**
80+
* Defines targeting for the ad slot
81+
*
82+
* Targeting should be defined as an array of key => value pairs
83+
*
84+
* @access public
85+
* @since 0.0.1
86+
*
87+
* @var array
88+
*/
89+
public $targeting = array();
90+
91+
/**
92+
* PHP5 Constructor
93+
*
94+
* Constructs the object using the information provided by default in every installation. Values
95+
* will come from CPT meta data.
96+
*
97+
* @access public
98+
* @since 0.0.1
99+
*
100+
* @param $id int|null Post ID to grab the post object and create the position
101+
*/
102+
public function __construct( $id = null ) {
103+
104+
/**
105+
* @param $position WP_Post
106+
*/
107+
if ( $id !== null && ( $position = get_post( $id ) ) ) {
108+
$meta = get_post_meta( $position->ID );
109+
110+
$this->post_id = $id;
111+
$this->title = $position->post_title;
112+
$this->ad_name = $meta['dfp_ad_code'][0];
113+
$this->position_tag = strtolower('Ad_Pos_' . $this->ad_name);
114+
$this->sizes = dfp_get_ad_sizes($meta['dfp_position_sizes'][0]);
115+
$this->out_of_page = ( $meta['dfp_out_of_page'][0] ? true : false );
116+
}
117+
}
118+
119+
/**
120+
* Create ad position HTML
121+
*
122+
* @access public
123+
* @since 0.0.1
124+
*
125+
* @return mixed
126+
*/
127+
public function display_position( ) {
128+
printf( __( '<!-- %1s -->', 'dfp-ads' ), $this->ad_name );
129+
?>
130+
<div id='<?php _e( $this->position_tag, 'dfp-ads'); ?>' class="<?php _e( $this->position_tag, 'dfp-ads'); ?> <?php _e( $this->ad_name, 'dfp-ads' ); ?>">
131+
<script type='text/javascript'>
132+
googletag.cmd.push(function() { googletag.display('<?php _e( $this->position_tag, 'dfp-ads'); ?>'); });
133+
</script>
134+
</div>
135+
<?php
136+
}
137+
138+
}

0 commit comments

Comments
 (0)