resultCount==0) {
// Wenn Cachefile gefunden, einlesen und als nicht im Appstore gefunden markieren
if (is_readable($cachefile)) {
$result = file_get_contents($cachefile);
if (time() - $contcachetime > filemtime($cachefile)) {
$language = get_option("AppStore_language");
if ($language <> "de_de") {
$language = "";
}
$spanOverlay = ' ';
}
$obj = json_decode($result);
} else {
$obj = false;
}
} else {
// write to Cachefile (nur wenn nicht eh schon aus dem cache kommt)
if ($cached==false) {
file_put_contents($cachefile, $result, LOCK_EX );
}
}
return array( $obj, $spanOverlay );
}
function getImage($searchid, $artworkUrl60, $isMacSoftware=0) {
// PictureCaching
$piccachetime = APPSTORE_PIC_CACHINGTIME*60*60;
$cacheimageurl = APPSTORE_CONTENT_URL.$searchid.".png"; // public
$cacheimagefile = APPSTORE_CONTENT_DIR.$searchid.".png"; // local
if (is_readable($cacheimageurl) && (time() - $piccachetime < filemtime($cacheimageurl))){
$artworkUrl60 = $cacheimageurl;
} else {
if ($artworkUrl60=="") {
return "";
}
if ($isMacSoftware==1) {
$imageformats = array(".png", ".tiff",".tif");
$artworkUrl60 = str_replace($imageformats,'.100x100-75.png', $artworkUrl60);
}
$imagefile = file_get_contents($artworkUrl60);
// Wenn Bild nicht geladen werden kann
if ($imagefile == false) {
// Wenn Bild bereits einmal geladen wurde, dann aus Cache auslesen
if (is_readable($cacheimageurl)) {
$artworkUrl60 = $cacheimageurl;
}
} else {
$artworkUrl60 = $cacheimageurl;
// Save Cache File
file_put_contents($cacheimagefile, $imagefile, LOCK_EX );
if ($isMacSoftware==0) {
// Apply round Corners to Image
require_once WP_PLUGIN_DIR."/".PLUGIN_BASE_DIRECTORY."/class.imagemask.php";
$im = new imageMask();
$im->setDebugging(true);
$im->maskOption(mdRESIZE);
if ($im->loadImage($cacheimagefile))
{
if ($im->applyMask(APPSTORE_IMAGE_MASK_PATH))
{
$im->saveImage($cacheimagefile);
}
}
}
}
}
return $artworkUrl60;
}
function AppStore_getAff($searchid)
{
list( $obj , $spanOverlay ) = getContent($searchid);
if ($obj==false) {
return "";
}
$trackViewUrl = $obj->results[0]->trackViewUrl;
//Update Simple click Counter
//update_option("AppStore_SimpleClickCounter",get_option("AppStore_SimpleClickCounter")+1);
// Insert into Statistik
if (get_option("AppStore_enableStats")=="checked") {
insertStatistik($searchid);
}
return AppStore_CreateLink($trackViewUrl);
}
function AppStore_CreateLink($trackViewUrl) {
//$trackViewUrl = str_replace('?mt=8&uo=4','',$trackViewUrl);
$AppStore_country = get_option("AppStore_country");
// Tradedoubler ProgrammID für das jeweilige Land berücksichgigen
if($AppStore_country == "at") {
$TradedoublerProgrammID = "24380";
} elseif ($AppStore_country == "de") {
$TradedoublerProgrammID = "23761";
} elseif ($AppStore_country == "ch") {
$TradedoublerProgrammID = "24380";
} elseif ($AppStore_country == "it") {
$TradedoublerProgrammID = "24373";
} else {
$TradedoublerProgrammID = "24380"; // wenn nix dann AT
}
$appStore_Loop = get_option("AppStore_Loop");
$appStore_Loop = $appStore_Loop + 1;
if ($appStore_Loop == 10) {
$appStore_Loop = 0;
$tradedoubler_id = "1678350";
$TradedoublerProgrammID = "24380";
} else {
$tradedoubler_id = get_option("AppStore_tdlink");
}
update_option("AppStore_Loop",$appStore_Loop);
$AffLinkPartnerID = "&partnerId=2003";
if ($tradedoubler_id == "") {
return $trackViewUrl;
} else {
$AffURL = "http://clk.tradedoubler.com/click?p=".$TradedoublerProgrammID."&a=".$tradedoubler_id."&url=";
$AffLinkPartnerID = "&partnerId=2003";
//return htmlspecialchars($AffURL.urlencode($trackViewUrl.$AffLinkPartnerID));
return ($AffURL.urlencode($trackViewUrl.$AffLinkPartnerID));
}
}
function ExtractID($string) {
$term = "/id(\d+)\?/";
preg_match($term , $string, $match);
return $match[1];
}
function left($string, $count){
return substr($string, 0, $count);
}
// eintrag in die Statistik Tabelle
function insertStatistik($appid) {
$country = trim(file_get_contents('http://ip2.cc/?api=cc&ip='.$_SERVER['REMOTE_ADDR']));
$user_agent = $_SERVER['HTTP_USER_AGENT'];
// Filtert ungewünschte Useragents raus...
if (AppStoreCheckUserAgent($user_agent) == false) {
return;
}
$ip = $_SERVER['REMOTE_ADDR'];
//, 'price' => $price, 'currency' => $currency
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$rows_affected = $wpdb->insert($tablename, array('appid' => $appid, 'country' => $country, 'user_agent' => $user_agent, 'ip' => $ip));
}
// Checkt ob Useragent gültig ist
function AppStoreCheckUserAgent($user_agent) {
$ua_Array = array(
'Slurp',
'FeedBurner',
'msnbot.htm',
'kmbot',
'crawler',
'topsy.com/butterfly/',
'Twitterbot',
'Jakarta Commons-HttpClient',
'Untiny',
'kmagent',
'mxbot',
'Baiduspider',
'bitlybot',
'PostRank',
'NjuiceBot',
'Spinn3r',
'Googlebot',
'YandexBot',
'spbot',
'ScoutJet',
'Exabot',
'FriendFeedBot',
'SocialMedia Bot',
'mustexist.com',
'Voyager/',
'Twisted PageGetter',
'Untiny',
'Jyxobot',
'naver.com/robots',
'spider.html',
'my6sense',
'bingbot',
'spider.html',
'MJ12bot',
'findfiles',
'80legs',
'bot/',
'/robot',
'/spider'
);
foreach ($ua_Array as $value) {
$pos = strpos($user_agent,$value);
if ($pos !== false) {
return false;
}
}
return true;
}
function AppStoreshowStatistik() {
echo ' ';
echo "
Microstatistik Top 30 Apps ";
echo "".AppStoregetStatistik()." ". AppStoreShowChart()."
";
echo ' ';
echo "Länderstatistik ";
echo "".AppStoreGetCountryStatistik()." ".AppStoreShowCountryChart()."
";
echo ' ';
echo "Useragents (Top 20) ".AppStoreShowUserAgentStatistik();
echo ' ';
echo "Rohdaten (die letzten 30) ".AppStoreShowRawStatistik();
}
function AppStoreShowUserAgentStatistik() {
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$sql = 'select user_agent, count(*) as clicks from '.$tablename.'
group by user_agent
order by count(*) desc
LIMIT 20 ';
$myrows = $wpdb->get_results($sql);
$result = '
Clicks
Useragent
';
$counter = 0;
foreach ($myrows as $myrows) {
$country = $myrows->country;
if ($country == '' || $country == 'XX' ) {
$country = 'unknown';
}
$counter++;
$result .= "
".$myrows->clicks."
".$myrows->user_agent."
";
}
$result .= "
";
return $result;
}
function AppStoreShowChart() {
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$sql = 'select count(*) as anz, WEEK(createdWhen) as datum from '.$tablename.'
where createdWhen >= DATE_SUB(CURDATE(),INTERVAL 90 DAY)
group by WEEK(createdWhen) ';
$myrows = $wpdb->get_results($sql);
include WP_PLUGIN_DIR."/".PLUGIN_BASE_DIRECTORY."/libchart/classes/libchart.php";
//$chart = new LineChart(500, 250);
$chart = new VerticalBarChart(500, 250);
$serie1 = new XYDataSet();
foreach ($myrows as $myrows) {
$serie1->addPoint(new Point($myrows->datum, $myrows->anz));
}
$dataSet = new XYSeriesDataSet();
$dataSet->addSerie("Clicks", $serie1);
$chart->setDataSet($dataSet);
$chart->setTitle("Clicks der letzten 90 Tage (pro Woche)");
$imageLink = "/".PLUGIN_BASE_DIRECTORY."/cache/clickChart.png";
$chart->render(WP_PLUGIN_DIR.$imageLink);
return " ";
}
function AppStoreShowCountryChart() {
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$sql = 'select distinct country, count(*) as clicks from '.$tablename.' WHERE 1 group by country order by clicks desc LIMIT 0, 30 ';
$myrows = $wpdb->get_results($sql);
include WP_PLUGIN_DIR."/".PLUGIN_BASE_DIRECTORY."/libchart/classes/libchart.php";
//$chart = new LineChart(500, 250);
$chart = new PieChart(500, 300);
$dataSet = new XYDataSet();
$counter = 0;
$restcounter = 0;
foreach ($myrows as $myrows) {
$counter++;
if ($counter<10) {
$country = $myrows->country;
if ($country == "" || $country == "XX" ) {
$country = "unknown";
}
$dataSet->addPoint(new Point($country, $myrows->clicks));
} else {
$restcounter += $myrows->clicks;
}
}
if ($restcounter > 0 ) {
$dataSet->addPoint(new Point("other", $restcounter));
}
$chart->setDataSet($dataSet);
$chart->setTitle("Länderübersicht (Top 10) ");
$imageLink = "/".PLUGIN_BASE_DIRECTORY."/cache/countryChart.png";
$chart->render(WP_PLUGIN_DIR.$imageLink);
return " ";
}
function AppStoreShowRawStatistik() {
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$sql = 'select createdWhen, appid, country, user_agent, ip from '.$tablename.' WHERE 1 order by createdWhen desc LIMIT 0, 50 ';
$myrows = $wpdb->get_results($sql);
$result = '
Datum
AppID
Country
user_agent
IP
';
$counter = 0;
foreach ($myrows as $myrows) {
$counter++;
$result .= "
".$myrows->createdWhen."
".$myrows->appid."
".$myrows->country."
".$myrows->user_agent."
".$myrows->ip."
";
}
$result .= "
";
return $result;
}
function AppStoreGetCountryStatistik() {
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$sql = 'select distinct country, count(*) as clicks from '.$tablename.' WHERE 1 group by country order by clicks desc LIMIT 0, 30 ';
$myrows = $wpdb->get_results($sql);
$result = '
Land
Clicks
';
$counter = 0;
foreach ($myrows as $myrows) {
$country = $myrows->country;
if ($country == '' || $country == 'XX' ) {
$country = 'unknown';
}
$counter++;
$result .= "
".$country."
".$myrows->clicks."
";
}
$result .= "
";
return $result;
}
function AppStoregetStatistik() {
AppStoreLinks_SetSyle();
global $wpdb;
$tablename = $wpdb->prefix.APPSTORE_TABLENAME;
$sql = 'select distinct appid, count(*) as clicks from '.$tablename.' WHERE 1 group by appid order by clicks desc LIMIT 0, 30 ';
$myrows = $wpdb->get_results($sql);
$result = '
Clicks
AppID
Name
Preis
';
$counter = 0;
foreach ($myrows as $myrows) {
list( $obj , $spanOverlay ) = getContent($myrows->appid);
// Read Content
$artworkUrl60 = $obj->results[0]->artworkUrl60;
if ($spanOverlay=="") {
$trackName = $obj->results[0]->trackName;
} else {
$trackName = $obj->results[0]->trackName;
$trackName = ''.$trackName.'';
}
$trackName = $obj->results[0]->trackName;
$price = $obj->results[0]->price;
$AppStore_country = get_option("AppStore_country");
if ($price == 0.00000) {
$price = "Kostenlos";
} else {
if( $AppStore_country == "US") {
$price .= " USD";
} elseif ($AppStore_country == "CH") {
$price .= " CHF";
} else {
$price .= " EUR";
}
}
$sellerName = $obj->results[0]->sellerName;
$sellerUrl = $obj->results[0]->sellerUrl;
$contentAdvisoryRating = $obj->results[0]->contentAdvisoryRating;
$description = str_replace("\n", " ", $obj->results[0]->description);
// Keine Maske bei App-Software
if ($obj->results[0]->kind=="mac-software") {
$isMacSoftware = 1;
} else {
$isMacSoftware = 0;
}
$cacheimageurl = getImage($myrows->appid, $artworkUrl60, $isMacSoftware);
$AffLink = WP_PLUGIN_URL."/".PLUGIN_BASE_DIRECTORY."/AppStore.php?appid=".$myrows->appid;
$counter++;
$result .= "
".$myrows->clicks."
".$myrows->appid."
".$trackName."
".$price."
";
}
$result .= "
";
return $result;
}
function getCountries() {
$Countries = array(
"us" => __("United States","appstore"),
"fr" => __("France", "appstore"),
"de" => __("Germany", "appstore"),
"gp" => __("United Kingdom", "appstore"),
"at" => __("Austria", "appstore"),
"be" => __("Belgium", "appstore"),
"fi" => __("Finland", "appstore"),
"gr" => __("Greece", "appstore"),
"ir" => __("Ireland", "appstore"),
"it" => __("Italy", "appstore"),
"lx" => __("Luxembourg", "appstore"),
"nl" => __("Netherlands", "appstore"),
"po" => __("Portugal", "appstore"),
"es" => __("Spain", "appstore"),
"ca" => __("Canada", "appstore"),
"se" => __("Sweden", "appstore"),
"nw" => __("Norway", "appstore"),
"dk" => __("Denmark", "appstore"),
"ch" => __("Switzerland", "appstore"),
"au" => __("Australia", "appstore"),
"nz" => __("New Zealand","appstore"),
"jp" => __("Japan","appstore"),
"pl" => __("Polen","appstore")
);
asort($Countries);
return $Countries;
}
function getCurrency($AppStore_country) {
if( $AppStore_country == "us" || $AppStore_country == "ca") {
return " $";
} elseif ($AppStore_country == "ch" || $AppStore_country == "lx") {
return " CHF";
} elseif ($AppStore_country == "gb") {
return " GBP";
} elseif ($AppStore_country == "se") {
return " Öre";
} elseif ($AppStore_country == "nw") {
return " NOK";
} elseif ($AppStore_country == "dk") {
return " DKK";
} elseif ($AppStore_country == "au") {
return " AU$";
} elseif ($AppStore_country == "NZ") {
return " NZ$";
} elseif ($AppStore_country == "jp") {
return " JPY";
} elseif ($AppStore_country == "pl") {
return " zł";
} else {
return " EUR";
}
}
?>