Skip to content

Commit

Permalink
Initial Commit. V 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswgerber committed Mar 24, 2015
0 parents commit bb86022
Show file tree
Hide file tree
Showing 16 changed files with 2,501 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Numerous always-ignore extensions
*.diff
*.err
*.orig
*.log
*.rej
*.swo
*.swp
*.vi
*~
*.sass-cache

# OS or Editor folders
.DS_Store
Thumbs.db
.cache
.project
.settings
.tmproj
*.esproj
nbproject
*.sublime-project
*.sublime-workspace

# Dreamweaver added files
_notes
dwsync.xml

# Komodo
*.komodoproject
.komodotools

# Folders to ignore
.hg
.svn
.CVS
intermediate
.idea
cache
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

95 changes: 95 additions & 0 deletions inc/class.csv_importer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* Managing CSV Files
*
* Description.
*
* @link http://www.chriswgerber.com/dfp-ads
* @since
*
* @package WordPress
* @subpackage DFP-Ads
*/

class CSV_Importer {

/**
* @var
*/
private $fp;

/**
* @var
*/
private $parse_header;

/**
* @var
*/
private $delimiter;

/**
* @var
*/
private $length;

/**
* @param string $file_name
* @param bool $parse_header
* @param string $delimiter
* @param int $length
*/
public function __construct( $file_name, $parse_header = false, $delimiter = "\t", $length = 8000 ) {
$this->fp = fopen( $file_name, "r" );
$this->parse_header = $parse_header;
$this->delimiter = $delimiter;
$this->length = $length;
$this->lines = $lines;

if ( $this->parse_header ) {
$this->header = fgetcsv( $this->fp, $this->length, $this->delimiter );
}

}

/**
* PHP5 Destruct
*/
public function __destruct() {
if ( $this->fp ) {
fclose( $this->fp );
}
}

/**
* @param int $max_lines
*
* @return array
*/
public function get( $max_lines = 0 ) {
//if $max_lines is set to 0, then get all the data
$data = array();
if ( $max_lines > 0 ) {
$line_count = 0;
} else {
$line_count = -1; // so loop limit is ignored
}

while ( $line_count < $max_lines && ( $row = fgetcsv( $this->fp, $this->length, $this->delimiter ) ) !== FALSE ) {
if ( $this->parse_header ) {
foreach ( $this->header as $i => $heading_i ) {
$row_new[$heading_i] = $row[$i];
}
$data[] = $row_new;
} else {
$data[] = $row;
}

if ( $max_lines > 0 ) {
$line_count ++;
}
}

return $data;
}
}
138 changes: 138 additions & 0 deletions inc/class.dfp_ad_position.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php
/**
* Class for Ad Positions
*
* Holds data for an ad position.
*
* @link http://www.chriwgerber.com/dfp-ads/
* @since 0.0.1
*
* @package WordPress
* @subpackage DFP-Ads
*/

class DFP_Ad_Position {

/**
* ID of the CPT
*
* @access public
* @since 0.0.1
*
* @var int
*/
public $post_id;

/**
* Title of the position
*
* @access public
* @since 0.0.1
*
* @var string
*/
public $title;

/**
* Name of the Ad Slot
* Ex. SNG_ROS_Leaderboard
*
* @access public
* @since 0.0.1
*
* @var string
*/
public $ad_name;

/**
* Div ID of the ad position
* Ex. div-gpt-ad-1375829763909
*
* @access public
* @since 0.0.1
*
* @var string
*/
public $position_tag;

/**
* Ad sizes. Slot with multiple sizes needs to be nested.
* Ex. [728, 90] or [ [728, 90], [970, 90] ]
*
* @access public
* @since 0.0.1
*
* @var array
*/
public $sizes = [];

/**
* Defines whether the slot should include Out of Page position
*
* @access public
* @since 0.0.1
*
* @var bool
*/
public $out_of_page = false;

/**
* Defines targeting for the ad slot
*
* Targeting should be defined as an array of key => value pairs
*
* @access public
* @since 0.0.1
*
* @var array
*/
public $targeting = array();

/**
* PHP5 Constructor
*
* Constructs the object using the information provided by default in every installation. Values
* will come from CPT meta data.
*
* @access public
* @since 0.0.1
*
* @param $id int|null Post ID to grab the post object and create the position
*/
public function __construct( $id = null ) {

/**
* @param $position WP_Post
*/
if ( $id !== null && ( $position = get_post( $id ) ) ) {
$meta = get_post_meta( $position->ID );

$this->post_id = $id;
$this->title = $position->post_title;
$this->ad_name = $meta['dfp_ad_code'][0];
$this->position_tag = strtolower('Ad_Pos_' . $this->ad_name);
$this->sizes = dfp_get_ad_sizes($meta['dfp_position_sizes'][0]);
$this->out_of_page = ( $meta['dfp_out_of_page'][0] ? true : false );
}
}

/**
* Create ad position HTML
*
* @access public
* @since 0.0.1
*
* @return mixed
*/
public function display_position( ) {
printf( __( '<!-- %1s -->', 'dfp-ads' ), $this->ad_name );
?>
<div id='<?php _e( $this->position_tag, 'dfp-ads'); ?>' class="<?php _e( $this->position_tag, 'dfp-ads'); ?> <?php _e( $this->ad_name, 'dfp-ads' ); ?>">
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('<?php _e( $this->position_tag, 'dfp-ads'); ?>'); });
</script>
</div>
<?php
}

}
Loading

0 comments on commit bb86022

Please sign in to comment.