Skip to content

Instantly share code, notes, and snippets.

@atwellpub
Created April 19, 2015 16:13
Show Gist options
  • Save atwellpub/63b1cf86eb8d18dd213a to your computer and use it in GitHub Desktop.
Save atwellpub/63b1cf86eb8d18dd213a to your computer and use it in GitHub Desktop.
Builds a dataset of downloads and extensions
<?php
class DownloadsDataSetBuilder {
static $downloads;
public function __construct() {
self::get_downloads();
self::include_post_meta();
self::print_results();
}
public static function get_downloads() {
self::$downloads = get_posts( array(
'post_type' => 'download',
'post_status' => 'publish',
'posts_per_page' => -1
));
}
public static function include_post_meta() {
foreach ( self::$downloads as $key => $download ) {
/* skip these downloads */
if ( in_array( $download->ID , array('7118','21060','45917') ) ) {
continue;
}
/* get permalink */
self::$downloads[$key]->permalink = get_permalink( $download->ID );
/* get download repo */
$files = get_post_meta( $download->ID , 'edd_download_files' );
$repo = $files[0][0]['file'];
$parts = explode('giturl=' , $repo);
self::$downloads[$key]->fileserver = $files[0][0]['file'];
self::$downloads[$key]->repo = $parts[1];
/* get zip name */
$zip = explode( '.' , $files[0][0]['name'] );
self::$downloads[$key]->zip_filename = $zip[0];
/* get current version */
$server_version = get_post_meta( $download->ID , '_edd_licenses_version_number' );
self::$downloads[$key]->server_version = ($server_version[0]) ? $server_version[0] : '1.0.1';
/* get demo page */
$preview = get_post_meta( $download->ID , 'extra_meta_demo_link' );
self::$downloads[$key]->preview = ($preview) ? $preview : '';
/* get post thumbnail */
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $download->ID ), 'single-post-thumbnail' );
self::$downloads[$key]->featured_image = $image[0];
/* determines what kind of download it is and what core components it corresponds to from reading the categoreis */
self::determin_download_type( $key , $download );
/* clean object */
self::filter_object( $key , $download );
}
}
/**
* determines what kind of download it is and what core components it corresponds to from reading the categoreis
*/
public static function determin_download_type( $key , $download ) {
$terms = wp_get_post_terms( $download->ID , 'download_category' , $args );
self::$downloads[$key]->plugins = array();
foreach( $terms as $term) {
switch ($term->term_id) {
case '7580':
self::$downloads[$key]->download_type = 'extension';
BREAK;
case '6947':
self::$downloads[$key]->download_type = 'extension';
BREAK;
case '6695':
self::$downloads[$key]->download_type = 'extension';
BREAK;
case '7581':
self::$downloads[$key]->download_type = 'template';
BREAK;
case '7502':
self::$downloads[$key]->download_type = 'template';
BREAK;
case '6699':
self::$downloads[$key]->download_type = 'template';
BREAK;
case '6946':
self::$downloads[$key]->plugins[] = 'calls-to-action';
BREAK;
case '100':
self::$downloads[$key]->plugins[] = 'landing-pages';
BREAK;
case '6945':
self::$downloads[$key]->plugins[] = 'leads';
BREAK;
}
}
}
public static function filter_object( $key , $download ) {
$remove = array(
'post_author' , 'post_password' , 'to_ping' , 'pinged' , 'post_modified' , 'post_modified_gmt' ,
'post_content_filtered' , 'post_parent' , 'guid', 'menu_order' , 'post_type' , 'post_mime_type' ,
'comment_count' , 'filter' , 'original_source' , 'bs_campaign_id' , 'comment_status' , 'ping_status'
);
/* convert content to utf8 */
//self::$downloads[$key]->post_content = utf8_encode( self::$downloads[$key]->post_content );
foreach ( $remove as $value ) {
if (isset(self::$downloads[$key]->$value)) {
unset( self::$downloads[$key]->$value );
}
}
}
public static function print_results() {
echo serialize(self::$downloads);exit;
}
}
if (isset($_POST['get_downloads']) && $_POST['key'] == 'hudson11') {
add_action( 'init' , 'build_product_array' );
function build_product_array() {
new DownloadsDataSetBuilder;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment