Skip to content

Instantly share code, notes, and snippets.

@stbuehler
Created October 19, 2011 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stbuehler/1299743 to your computer and use it in GitHub Desktop.
Save stbuehler/1299743 to your computer and use it in GitHub Desktop.
fetch comments for webos appcatalog apps
<?php
global $token;
/* Insert real token data to use search/app details
luna-send -n 1 palm://com.palm.accountservices/getAccountToken '{}'
luna-send -n 1 palm://com.palm.deviceprofile/getDeviceId '{}'
luna-send -n 1 palm://com.palm.preferences/systemProperties/Get '{"key":"com.palm.properties.DMCARRIER"}'
*/
$token = array(
"token" => "",
"deviceId" => "",
"email" => "",
"carrier" => "ROW");
function palmreq($path, $reqobject) {
// Data captured from Pre-, WebOS 2.1.0
$serverurl = 'https://ps.palmws.com/palmcsext/services/deviceJ/';
$ch = curl_init($serverurl . $path);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($reqobject));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
# 'X-Requested-With: XMLHttpRequest',
# 'X-$PrototypeBI-Version: 1.6.0.3',
# 'User-Agent: Mozilla/5.0 (webOS/1.0; U; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/1.0 Safari/525.27.1 Pre/1.0',
'Content-Type: application/json; charset=UTF-8',
# 'Accept: text/javascript, text/html, application/xml, text/xml, */*',
# 'Accept-Language: en-us,en;q=0.5',
# 'X-Palm-Carrier: c019-00'
));
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}
function appCommentsNr($nr) {
return palmreq('getUserRatings', array("InGetUserRatings" => array("appId" => $nr, "startPosition" => 0, "count" => 1000)));
}
function searchApps($query) {
global $token;
return palmreq('appList_ext2', array("InGetAppListV2" => array(
"tagName" => "",
"queryStr" => $query.'*',
"categoryid" => "",
"startPosition" => 0,
"count" => "10",
"sort" => "RATING_DESC",
"locale" => "en_US",
"accountTokenInfo" => $token
)));
}
function appDetails($appId) {
global $token;
return palmreq('appDetail_ext2', array("InGetAppDetailV2" => array(
"packageId" => $appId,
"locale" => "en_US",
"accountTokenInfo" => $token
)));
}
function q($text) {
$text = str_replace('&nbsp;', ' ', $text);
return htmlentities($text, ENT_COMPAT, 'UTF-8');
}
function score($val) {
$stars = round($val);
$s = '<span style="color: #AA0">';
$n = 0;
while ($n < 5 && $n < $stars) {
$s .= "&#x272D;";
$n++;
}
$s .= '</span>';
while ($n < 5) {
$s .= "&#x2730;";
$n++;
}
$s .= ' '.round($val, 1);
return $s;
}
function showComments($title, $nr) {
$nr = 0 + $nr;
header("Content-Type: text/html; charset=UTF-8");
$result = appCommentsNr($nr);
$comments = $result['UserRatingList']['ratings'];
echo '<html><head><title>'.count($comments).' Comments for '.q($title).'</title></head><body><h1>'.count($comments).' Comments for '.q($title).'</h1><ul>'."\n";
foreach ($comments as $c) {
$date = DateTime::createFromFormat(DateTime::ISO8601, $c['creationtime']);
echo '<li>'.score($c['score']).' '.q($c['comment']).' <i>'.q($c['creator']).' - '.$date->format('Y-m-d H:i:s').'</i></li>';
// echo '<!-- '; var_dump($c); echo ' -->';
echo "\n";
}
echo '</ul></body></html>';
}
function showSearch($query) {
header("Content-Type: text/html; charset=UTF-8");
if ($query) {
$result = searchApps($query);
echo '<html><head><title>Search for '.q($query).'</title></head><body><h1>Search for '.q($query).'</h1>'."\n";
echo '<form method="GET"><input name="query" value="'.q($query).'"><input type="submit" value="Search"></form>'."\n";
echo '<ul>'."\n";
$result = $result["OutGetAppList"]["appList"]["appSummary"];
foreach ($result as $r) {
echo '<li><div><span style="float: left">'.score($r["weightedRating"]).': '
.'<img style="vertical-align: top" alt="appIcon" src="'.q($r['appIcon']).'" /></span>'
.'<a href="?appid='.urlencode($r['publicApplicationId']).'">'.q($r['title']).' '.q($r['appVersion']).' ('.q($r['publicApplicationId']).' - '.q($r['id']).')</a><br/>'.q($r['summary'])
.'...<br/><a href="?reviews='.urlencode($r['id']).'&amp;title='.urlencode($r['title']).'">Reviews</a></div></li>'."\n";
// echo '<!-- '; var_dump($r); echo ' -->';
}
echo '</ul></body></html>';
} else {
echo '<html><head><title>Search</title></head><body><h1>Search</h1>'."\n";
echo '<form method="GET"><input name="query"><input type="submit" value="Search"></form>'."\n";
echo '</ul></body></html>';
}
}
function showApp($appid) {
$result = appDetails($appid);
$d = $result["OutGetAppDetailV2"]["appDetail"];
echo '<html><head><title>Application details for '.q($d['title']).'</title></head><body><h1>Application details for '.q($d['title']).' - '.q($d['version']).'</h1>'."\n";
echo '<ul><li>Application ID: '.q($appid).' - '.q($d['id']).'</li>'
.'<li>Rating: '.score($d['weightedRating']).'</li>'
.'<li>Icon: <img style="vertical-align: top" alt="appIcon" src="'.q($d['appIcon']).'" /></li>'
.'<li>Description: '.q($d['description']).'</li>'
.'<li>Download: '.q($d['appLocation']).'</li>'
.'<li><a href="?reviews='.urlencode($d['id']).'&amp;title='.urlencode($d['title']).'">Reviews</a></li>'
.'</ul>';
echo '<!-- '; var_dump($d); echo ' -->';
echo '</body></html>';
}
if ($_GET['query']) {
showSearch($_GET['query']);
# header('Content-Type: text/plain; charset=UTF-8');
# var_dump(searchApps($_GET['query']));
} else if ($_GET['appid']) {
showApp($_GET['appid']);
# header('Content-Type: text/plain; charset=UTF-8');
} else if ($_GET['reviews']) {
showComments($_GET['title'], $_GET['reviews']);
} else {
showSearch('');
# header('Status: 403');
# header("Content-Type: text/html; charset=UTF-8");
# echo '<html><head><title>Forbidden</title></head><body><h1>Forbidden</h1>Check the <a href="https://gist.github.com/1299743">gist</a></body></html>';
# showComments('QR offline Decoder', 8912);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment