0) {
// extract the package name
$packagename = substr($packagename, 0, $ampersandpos);
// create a new Web Market URL, without the redundant info after the ampersand
$url = substr($url, 0, strpos($url, "&"));
}
// create the Android Market search string for the QR code
$qrURL = "market://search?q=pname:".$packagename;
// it's an AppBrain link, obviously
} else if (strpos($url, "www.appbrain.com") !== false) {
// what to find: a slash
$findthis = "/";
$packagepos = strlen($url) - (strpos(strrev($url), strrev($findthis)) + strlen($findthis));
$packagename = substr($url,$packagepos+1);
$qrURL = "market://search?q=pname:".$packagename;
// save this info for later
$isappbrain = true;
// it's just a name
} else {
// add hyphens to the app title for the Web Market search
// code for replacing hyphens with spaces
$apptitle = $url; // we need the title for later, in case the "show title" option is activated
$appsearchstring = strtolower($url);
$appsearchstring = trim(preg_replace("/[\s-]+/", " ", $appsearchstring));
$appsearchstring = trim(substr($appsearchstring, 0, 45));
$appsearchstring = preg_replace("/\s/", "-", $appsearchstring);
// create a search string
$qrURL = "market://search?q=".$appsearchstring;
$url = "https://market.android.com/search?q=".$appsearchstring."&c=apps";
// save this info for later
$istitleonly = true;
}
// pull the app info from the Web Market - but only if that options is turned on,
// we've actually found an icon, the link is not an appbrain link, and that not just a title has been supplied
if ($qrcshowmarketinfo == "yes" and $isappbrain == false and $istitleonly == false){
// try to extract the name of the app by grabbing the
tag from the Web Market or AppBrain page
$pagecode = file_get_contents($url); // grab the code for the entire page
// extract the full title of the page, i.e. the name of the app
if (preg_match('/(.*?)<\/title>/is',$pagecode,$foundit)) {
$apptitle = $foundit[1];
// check where in the page title the hyphen is
$hyphenpos = strpos($apptitle, "-");
// extract the part before the hyphen (i.e. the app name)
$apptitle = substr($apptitle,0, $hyphenpos);
// cut down the title a bit if it's too long
if (strlen ($apptitle) > 29) {$apptitle = substr ($apptitle, 0,25); $apptitle = $apptitle.'...';}
} else {
$apptitle = "";
}
// extract the freakin' image:
// 
if (preg_match('/(.*?)<\/div>/is',$pagecode,$foundit2)) {
$appiconurl = $foundit2[1];
$appiconurl = substr($appiconurl, 0,strlen($appiconurl) -2); // grab that image, except the closing "/>"
// no icon to be found
} else {
$appiconurl = false;
}
// extract the rating:
//
if (preg_match('//is',$pagecode,$foundit3)) {
$apprating = $foundit3[1];
// remove the "Rating: " part
$apprating = substr($apprating, strpos($apprating, ":") +1);
// remove the parenthesis as well, we don't want it
$parpos = strpos($apprating, "(");
$apprating = substr($apprating, 0, $parpos);
// we couldn't find a rating
} else {
$apprating = false;
}
// finally, extract the size of the QR codes, and add some pixels for the box
$xpos = strpos($qrcsize, "x");$pxlsize = substr($qrcsize,0, $xpos); $boxwidth = ($pxlsize + 10)*2;
$boxheight = $pxlsize + 20;
}
// now that we have extracted and decided all the important stuff, let's print out the actual QR code...
// if the page is viewed from computer, do this:
if (!$this->is_android()) {
// the clickable link should point to the web, since we're on a computer
$thelinkurl = $url;
// the page is viewed with an android device, and we want to link
// directly to the mobile Market instead
} else {
// point the link to the phone Market instead
$thelinkurl = $qrURL;
$qronandroid = true;
}
// finally, if there is no app icon URL, it means that either the icon couldn't be extracted
// or that the setting is turned off - but if it's true, let's rock.
if ($appiconurl == !false){
// build the seemingly gigantic return string
$returnstring = '';
// skip the app info from the Market and just show the QR code
} else {
$returnstring = '
';
}
// final thing, a little workaround: if we're on android, and the custom icon option is on, we need to change the return string
if ($qronandroid and (strlen($qrcandroidimg))){$returnstring = '
';}
// send away...
return $returnstring;
}
}
?>