'', 'more_info_text' => 'continued...' ), $atts ) ); //Don't do anything if the ID is blank or non-numeric if($id == "" || !is_numeric($id))return; //Get the App Data $app = appStore_get_data($id); if($app) return appStore_page_output($app,$more_info_text,"internal",$code); else wp_die('No valid data for app id: ' . $id); } function iTunesStore_handler( $atts,$content=null, $code="" ) { // Get iTunes ID and more_info_text from shortcode extract( shortcode_atts( array( 'id' => '', 'more_info_text' => 'continued...' ), $atts ) ); //Don't do anything if the ID is blank or non-numeric if($id == "" || !is_numeric($id))return; //Get the Music Data $iTunesItem = appStore_get_data($id); if($iTunesItem) return iTunesStore_page_output($iTunesItem,$more_info_text,"internal",$code); else wp_die('No valid data for iTunes id: ' . $id); } function iBooksStore_handler( $atts,$content=null, $code="" ) { // Get iBooks ID and more_info_text from shortcode extract( shortcode_atts( array( 'id' => '', 'more_info_text' => 'continued...' ), $atts ) ); //Don't do anything if the ID is blank or non-numeric if($id == "" || !is_numeric($id))return; //Get the Book Data return true; } function appStore_atomfeed_handler($atts, $content = null, $code="") { // Get ATOM URL and more_info_text from shortcode extract( shortcode_atts( array( 'atomurl' => '', 'more_info_text' => 'open in The App Store...' ), $atts ) ); $last = $atomurl[strlen($atomurl)-1]; if($last != "/") $AddSlash = "/"; $RSS_Feed = $atomurl.$AddSlash."xml"; //Check to see if feed is available cached $appStore_option = "appStore_rssfeed_".hash('md2', $RSS_Feed); $feedData = get_option($appStore_option); if (!empty($feedData)) { $appIDs = $feedData; } else { // Get Array of AppIDs for ATOM Feed $appIDs = appStore_getIDs_from_feed($RSS_Feed); update_option($appStore_option, $appIDs); } //Pair down array to number of apps preference array_splice($appIDs, appStore_setting('qty_of_apps')); //Load App data foreach($appIDs as $appID) { if($appID == "" || !is_numeric($appID)) return; $app = appStore_get_data($appID); if($app) echo appStore_page_output($app,$more_info_text,"external",$code); else wp_die('No valid data for app id: ' . $id); } return; } // ------------START OF MAIN FUNCTIONS----------------- function iTunesStore_page_output($iTunesItem, $more_info_text,$mode="internal",$platform="music_store") { GLOBAL $is_iphone; // Start capturing output so the text in the post comes first. ob_start(); switch ($iTunesItem->wrapperType) { case "collection": $unformattedPrice = $iTunesItem->collectionPrice; if($iTunesItem->collectionID) $iTunesID = $iTunesItem->collectionID; if($iTunesItem->collectionId) $iTunesID = $iTunesItem->collectionId; $iTunesName = $iTunesItem->collectionName; $isExplicit = $iTunesItem->collectionExplicitness; $trackCount = $iTunesItem->trackCount; $iTunesKind = $iTunesItem->collectionType; $iTunesURL = $iTunesItem->collectionViewUrl; break; case "track": $unformattedPrice = $iTunesItem->trackPrice; $iTunesID = $iTunesItem->trackId; $iTunesName = $iTunesItem->trackName; $fromAlbum = $iTunesItem->collectionName; $isExplicit = $iTunesItem->trackExplicitness; $trackTime = $iTunesItem->trackTimeMillis; $iTunesKind = $iTunesItem->kind; $iTunesURL = $iTunesItem->trackViewUrl; break; case "audiobook": $unformattedPrice = $iTunesItem->collectionPrice; $iTunesID = $iTunesItem->collectionId; $iTunesName = $iTunesItem->collectionName; $isExplicit = $iTunesItem->collectionExplicitness; $iTunesURL = $iTunesItem->collectionViewUrl; break; } $iTunesCategory = $iTunesItem->primaryGenreName; $artistName = $iTunesItem->artistName; $releaseDate = date( 'F j, Y', strtotime($iTunesItem->releaseDate)); $contentAdvisoryRating = $iTunesItem->contentAdvisoryRating; $artistType = "Artist"; $cavType = "Explicit"; $trackType = "Track Count"; switch ($iTunesItem->kind) { case "song": $artistType = "Artist"; break; case "feature-movie": $artistType = "Director"; $cavType = "Rated"; $description = $iTunesItem->longDescription; break; case "tv-episode": $artistType = "Series"; $cavType = "Rated"; $description = $iTunesItem->longDescription; break; } switch ($iTunesItem->collectionType) { case "TV Season": $trackType = "Episodes"; $artistType = "Series"; $cavType = "Rated"; $description = $iTunesItem->longDescription; break; } //Check to see if the app is free, or under a dollar if($unformattedPrice == 0) { $iTunesPrice = "Free!"; } elseif($unformattedPrice < 1) { $iTunesPrice = number_format($unformattedPrice,2)*100; $iTunesPrice .="¢"; } else { $iTunesPrice = "$".$unformattedPrice.""; } // iTunes Artwork switch (appStore_setting('itunesicon_to_use')) { case "30": $artwork_url = $iTunesItem->artworkUrl30; break; case "60": $artwork_url = $iTunesItem->artworkUrl60; break; case "100": $artwork_url = $iTunesItem->artworkUrl100; break; } if(appStore_setting('cache_images_locally') == '1') { $upload_dir = wp_upload_dir(); $artwork_url = $upload_dir['baseurl'] . '/appstoreassistant_cache/' . $iTunesID . '/' . basename($artwork_url); } $originalImageSize = getimagesize("$artwork_url"); $adjustIcon = appStore_setting('itunesicon_size_adjust')/100; if($is_iphone) $adjustIcon = appStore_setting('itunesicon_iOS_size_adjust')/100; $newImageWidth = $originalImageSize[0] * $adjustIcon; $newImageHeight = $originalImageSize[1] * $adjustIcon; $iTunesURL = getAffiliateURL($iTunesURL); if(appStore_setting('smaller_buy_button_iOS') == "yes" && $is_iphone) { $buttonText = $iTunesPrice." "; } else { $buttonText = $iTunesPrice." - View in iTunes"; } ?>
.')
";echo print_r($iTunesItem, true);echo ""; } $return = ob_get_contents(); ob_end_clean(); return $return; } function appStore_page_output($app, $more_info_text,$mode="internal",$platform="ios_app") { GLOBAL $is_iphone; // Start capturing output so the text in the post comes first. ob_start(); //Check to see if the app is free, or under a dollar if($app->price == 0) { $TheAppPrice = "Free!"; } elseif($app->price < 1) { $TheAppPrice = number_format($app->price,2)*100; $TheAppPrice .="¢"; } else { $TheAppPrice = "$".$app->price.""; } $appURL = getAffiliateURL($app->trackViewUrl); // App Artwork switch (appStore_setting('appstoreicon_to_use')) { case "60": $artwork_url = $app->artworkUrl60; break; case "512": $artwork_url = $app->artworkUrl512; break; } if(appStore_setting('cache_images_locally') == '1') { $upload_dir = wp_upload_dir(); $artwork_url = $upload_dir['baseurl'] . '/appstoreassistant_cache/' . $app->trackId . '/' . basename($artwork_url); } $originalImageSize = getimagesize("$artwork_url"); $adjustIcon = appStore_setting('appicon_size_adjust')/100; if($is_iphone) $adjustIcon = appStore_setting('appicon_iOS_size_adjust')/100; $newImageWidth = $originalImageSize[0] * $adjustIcon; $newImageHeight = $originalImageSize[1] * $adjustIcon; //App Category $appCategory = $app->genres; $appCategoryList = implode(', ', $appCategory); //App Rating if ($app->averageUserRating > 0 && $app->averageUserRating <=10) { $appRating = $app->averageUserRating * 20; }else { $appRating = 0; } $AppFeatures = $app->features; if(appStore_setting('smaller_buy_button_iOS') == "yes" && $is_iphone) { $buttonText = $TheAppPrice." "; } else { $buttonText = $TheAppPrice." - View in App Store "; } ?>
';
}
?>
";echo print_r($iTunesItem, true);echo ""; } $return = ob_get_contents(); ob_end_clean(); return $return; } function getAffiliateURL($iTunesURL){ switch (appStore_setting('affiliatepartnerid')) { case 30: $AffiliateURL = appStore_setting('affiliatecode'); if (strpos($iTunesURL, '?') !== false) { $AffiliateURL .= urlencode(urlencode($iTunesURL.'&partnerId=30')); } else { $AffiliateURL .= urlencode(urlencode($iTunesURL.'?partnerId=30')); } break; case 2003: $AffiliateURL = "http://clk.tradedoubler.com/click?p=".appStore_setting('tdprogramID')."&a=".appStore_setting('tdwebsiteID')."&url="; if (strpos($iTunesURL, '?') !== false) { $AffiliateURL .= urlencode(urlencode($iTunesURL.'&partnerId=2003')); } else { $AffiliateURL .= urlencode(urlencode($iTunesURL.'?partnerId=2003')); } break; case 1002: $AffiliateURL = appStore_setting('dgmwrapper'); if (strpos($iTunesURL, '?') !== false) { $AffiliateURL .= urlencode(urlencode($iTunesURL.'&partnerId=1002')); } else { $AffiliateURL .= urlencode(urlencode($iTunesURL.'?partnerId=1002')); } break; default: $AffiliateURL = "http://click.linksynergy.com/fs-bin/stat?id=uiuOb3Yu7Hg&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1="; if (strpos($iTunesURL, '?') !== false) { $AffiliateURL .= urlencode(urlencode($iTunesURL.'&partnerId=30')); } else { $AffiliateURL .= urlencode(urlencode($iTunesURL.'?partnerId=30')); } } return $AffiliateURL; } function appStore_get_data( $id ) { //Check to see if we have a cached version of the JSON. $appStore_options = get_option('appStore_appData_' . $id, ''); if($appStore_options == '' || $appStore_options['next_check'] < time()) { $appStore_options_data = appStore_page_get_json($id); $appStore_options = array('next_check' => time() + appStore_setting('cache_time_select_box'), 'app_data' => $appStore_options_data); update_option('appStore_appData_' . $id, $appStore_options); if(appStore_setting('cache_images_locally') == '1') appStore_save_images_locally($appStore_options['app_data']); } return $appStore_options['app_data']; } function appStore_getIDs_from_feed($atomurl) { $last = $atomurl[strlen($atomurl)-1]; if($last != "/") $AddSlash = "/"; $urlEnd = 'xml'; $RSS_Feed = $atomurl.$AddSlash.$urlEnd; $feed = new SimplePie(); $feed->set_feed_url($RSS_Feed); $feed->init(); $feed->handle_content_type(); foreach ($feed->get_items() as $item): $appID = $item->get_id(); $pattern = '(id[0-9]+)'; preg_match($pattern, $appID, $matches, PREG_OFFSET_CAPTURE, 3); $appIDs[] = substr($matches[0][0], 2); endforeach; return $appIDs; } function appStore_page_add_stylesheet() { wp_register_style('appStore-styles', plugins_url( 'appStore-styles.css', __FILE__ )); wp_enqueue_style( 'appStore-styles'); } function appStore_page_get_json($id) { if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) $json_data = appStore_page_get_json_via_fopen($id); else if(function_exists('curl_exec')) $json_data = appStore_page_get_json_via_curl($id); else wp_die('