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 . '/' . ios_app_ss_baseurl($app->artworkUrl100);
}
return $artwork_url;
}
// Output an app smart banner
// http://developer.apple.com/library/ios/Documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
function ios_app_header_meta( $atts ) {
global $post;
$pattern = get_shortcode_regex();
if ( preg_match_all( '/'. $pattern .'/s', $post->post_content, $matches )
&& array_key_exists( 2, $matches )
&& in_array( 'ios-app', $matches[2] ) )
{
// shortcode is being used
$atts = shortcode_parse_atts($matches[0][0]);
$id = preg_replace("/[^0-9]/", "", $atts['id']);
if($id)
echo "\n" . '' . "\n";
}
}
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));
return ios_app_ss($app->screenshotUrls, $app);
}
function ios_app_ipadss( $atts ) {
$app = ios_app_get_data(ios_ap_extract_id($atts));
return ios_app_ss($app->ipadScreenshotUrls, $app);
}
function ios_app_ss($shots, $app) {
$retval = '
';
foreach($shots as $ssurl) {
$ssurl = str_replace(".png", ".320x480-75.jpg", $ssurl);
if(ios_app_setting('cache_images_locally') == '1')
{
$upload_dir = wp_upload_dir();
$ssurl = $upload_dir['baseurl'] . '/ios-app/' . $app->trackId . '/' . ios_app_ss_baseurl($ssurl);
}
$retval .= '
';
}
$retval .= '
';
return $retval;
}
function ios_app_itunes_link( $atts ) {
if(is_object($atts))
$app = $atts;
else
$app = ios_app_get_data(ios_ap_extract_id($atts));
$url = $app->trackViewUrl;
$partner_id = trim(ios_app_setting('phg_partner_id'));
if($partner_id != "")
{
$url .= "&at=" . $partner_id;
$campaign_id = trim(ios_app_setting('phg_campaign_id'));
if($campaign_id != ""){
$url .= "&ct=" . $campaign_id;
}
}
return $url;
}
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 ) {
if(is_object($id)) return $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_setting('cache_time_select_box') == 0) {
$ios_app_options_data = ios_app_page_get_json($id);
$ios_app_options = array('next_check' => time() + ios_app_setting('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_url( $id ) ) );
}
function ios_app_page_get_json_via_curl($id) {
return json_decode( ios_app_curlme( ios_app_page_url( $id ) ) );
}
function ios_app_page_url( $id ) {
$url = IOS_APP_PAGE_APPSTORE_URL . $id;
$store = ios_app_setting('store_country');
if($store)
$url = $url . "&country=" . $store;
return $url;
}
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();
?>
userRatingCount)) : ?>
price == 0) { ?>
Only $!
Latest Release Notes:
Description:
screenshotUrls) > 0) { ?>
ipadScreenshotUrls) > 0) { ?>
''
), $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
$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);
$filename = $upload_dir['basedir'] . '/ios-app/' . $app->trackId . '/' . ios_app_ss_baseurl($url);
$dirname = dirname($filename);
if (!is_dir($dirname)) mkdir($dirname, 0755, true);
if($fp = fopen($filename, "w+"))
{
fwrite($fp, $content);
fclose($fp);
}
else {
//Couldnt write the file. Permissions must be wrong.
ios_app_set_setting('cache_images_locally', '0');
return;
}
}
}
}
function ios_app_ss_baseurl($url) {
$s = explode("/", $url);
return implode("-", array_slice($s, -2, 2, true));
}
$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;
}
?>