trackName; } function ios_app_icon( $atts ) { return ''; } function ios_app_icon_url( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); $artwork_url = $app->artworkUrl100; if(ios_app_setting('cache_images_locally') == '1') { $upload_dir = wp_upload_dir(); $artwork_url = $upload_dir['baseurl'] . '/ios-app/' . $app->trackId . '/' . basename($app->artworkUrl100); } return $artwork_url; } function ios_app_version( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); return $app->version; } function ios_app_price( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); if($app->price == 0) return "Free"; else return $app->price; } function ios_app_release_notes( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); return nl2br($app->releaseNotes); } function ios_app_description( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); return nl2br($app->description); } function ios_app_rating( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); if(isset($app->userRatingCount)) return 'Rated' . $app->averageUserRating . ' out of 5 by ' . $app->userRatingCount . ' users.'; else return ''; } function ios_app_iphoness( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); $retval = ''; return $retval; } function ios_app_ipadss( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); $retval = ''; return $retval; } function ios_app_itunes_link( $atts ) { $app = ios_app_get_data(ios_ap_extract_id($atts)); return $app->trackViewUrl; } function ios_app_page_shortcode( $atts ) { extract( shortcode_atts( array( 'id' => '', 'download_url' => '' ), $atts ) ); //Don't do anything if the ID is blank or non-numeric if($id == "" || !is_numeric($id))return; $app = ios_app_get_data($id); if($app) return ios_app_page_output($app, $download_url); else wp_die('No valid data for app id: ' . $id); } function ios_app_get_data( $id ) { //Check to see if we have a cached version of the JSON. $ios_app_options = get_option('ios-app-' . $id, ''); if($ios_app_options == '' || $ios_app_options['next_check'] < time()) { $ios_app_options_data = ios_app_page_get_json($id); $ios_app_options = array('next_check' => time() + app_display_page_settings('cache_time_select_box'), 'app_data' => $ios_app_options_data); update_option('ios-app-' . $id, $ios_app_options); if(ios_app_setting('cache_images_locally') == '1')ios_app_save_images_locally($ios_app_options['app_data']); } return $ios_app_options['app_data']; } function ios_app_page_add_stylesheet() { wp_register_style('app-display-page-styles', plugins_url( 'app-display-page-styles.css', __FILE__ )); wp_enqueue_style( 'app-display-page-styles'); } function ios_app_page_get_json($id) { if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) $json_data = ios_app_page_get_json_via_fopen($id); else if(function_exists('curl_exec')) $json_data = ios_app_page_get_json_via_curl($id); else wp_die('

You must have either file_get_contents() or curl_exec() enabled on your web server. Please contact your hosting provider.

'); if($json_data->resultCount == 0) { wp_die('

Apple returned no record for that app ID.
Please check your app ID.

'); } return $json_data->results[0]; } function ios_app_page_get_json_via_fopen($id) { return json_decode(ios_app_fopenme(IOS_APP_PAGE_APPSTORE_URL . $id)); } function ios_app_page_get_json_via_curl($id) { return json_decode(ios_app_curlme(IOS_APP_PAGE_APPSTORE_URL . $id)); } function ios_app_fopenme ($url) { return file_get_contents($url); } function ios_app_curlme ($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); curl_close($ch); return $output; } function ios_app_fopen_or_curl($url) { if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) return ios_app_fopenme($url); else if(function_exists('curl_exec')) return ios_app_curlme($url); else wp_die('

You must have either file_get_contents() or curl_exec() enabled on your web server. Please contact your hosting provider.

'); } function ios_app_page_output($app, $download_url) { ob_start(); ?>
artworkUrl100; if(ios_app_setting('cache_images_locally') == '1') { $upload_dir = wp_upload_dir(); $artwork_url = $upload_dir['baseurl'] . '/ios-app/' . $app->trackId . '/' . basename($app->artworkUrl100); } ?>

trackName; ?> version; ?>

userRatingCount)) { ?>
Rated averageUserRating; ?> out of 5 by userRatingCount; ?> users.
price == 0) { ?> Free!
Only $price; ?>!
App Store

Latest Release Notes:

releaseNotes); ?>

Description:

description); ?>
screenshotUrls) > 0) { ?>

iPhone Screenshots:

 
ipadScreenshotUrls) > 0) { ?>

iPad Screenshots:

 
'' ), $atts ) ); return $id; } function ios_app_save_images_locally($app) { $upload_dir = wp_upload_dir(); if(!is_writeable($upload_dir['basedir'])) { //Uploads dir isn't writeable. bummer. ios_app_set_setting('cache_images_locally', '0'); return; } else { //Loop through screenshots and the app icons and cache everything if(!is_dir($upload_dir['basedir'] . '/ios-app/' . $app->trackId)) { if(!mkdir($upload_dir['basedir'] . '/ios-app/' . $app->trackId, 0755, true)) { ios_app_set_setting('cache_images_locally', '0'); return; } } $urls_to_cache = array(); $urls_to_cache[] = $app->artworkUrl60; $urls_to_cache[] = $app->artworkUrl100; $urls_to_cache[] = $app->artworkUrl512; foreach($app->screenshotUrls as $ssurl) { $ssurl2 = str_replace(".png", ".320x480-75.jpg", $ssurl); $urls_to_cache[] = $ssurl; $urls_to_cache[] = $ssurl2; } foreach($app->ipadScreenshotUrls as $ssurl) { $ssurl2 = str_replace(".png", ".320x480-75.jpg", $ssurl); $urls_to_cache[] = $ssurl; $urls_to_cache[] = $ssurl2; } foreach($urls_to_cache as $url) { $content = ios_app_fopen_or_curl($url); if($fp = fopen($upload_dir['basedir'] . '/ios-app/' . $app->trackId . '/' . basename($url), "w+")) { fwrite($fp, $content); fclose($fp); } else { //Couldnt write the file. Permissions must be wrong. ios_app_set_setting('cache_images_locally', '0'); return; } } } } $app_display_page_settings = array(); function ios_app_setting($name) { global $app_display_page_settings; $app_display_page_settings = get_option('adp_options'); if(!$app_display_page_settings) { adp_add_defaults(); $app_display_page_settings = get_option('adp_options'); } return $app_display_page_settings[$name]; } function ios_app_set_setting($name, $value) { global $app_display_page_settings; $app_display_page_settings = get_option('adp_options'); if(!$app_display_page_settings) { adp_add_defaults(); $app_display_page_settings = get_option('adp_options'); } $app_display_page_settings[$name] = $value; } ?>