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)) {
$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) {
// 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 {
$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 );
// 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
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";
} 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));
}
}
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 = file_get_contents('http://api.hostip.info/country.php?ip='.$_SERVER['REMOTE_ADDR']);
$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');
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, date(createdWhen) as datum from '.$tablename.'
where createdWhen >= DATE_SUB(CURDATE(),INTERVAL 90 DAY)
group by DATE(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");
$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);
$cacheimageurl = getImage($myrows->appid, $artworkUrl60);
$AffLink = WP_PLUGIN_URL."/".PLUGIN_BASE_DIRECTORY."/AppStore.php?appid=".$myrows->appid;
$counter++;
$result .= "
".$myrows->clicks."
".$myrows->appid."
".$trackName."
".$price."
";
}
$result .= "
";
return $result;
}
?>