Skip to content

Commit 64c851b

Browse files
committed
styleguide: spaces for better readability
1 parent 407a2f9 commit 64c851b

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

google-play.php

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GooglePlay {
1919
*/
2020
protected function getRegVal($regEx) {
2121
preg_match($regEx, $this->input, $res);
22-
if(isset($res["content"])) return trim($res["content"]);
22+
if (isset($res["content"])) return trim($res["content"]);
2323
else return null;
2424
}
2525

@@ -38,56 +38,56 @@ protected function getRegVal($regEx) {
3838
* if not explicitly specified otherwise, values are strings
3939
*/
4040
public function parseApplication($packageName, $lang='en_US', $loc='US') {
41-
$link="https://play.google.com/store/apps/details?id=".$packageName."&hl=$lang&gl=$loc";
41+
$link = "https://play.google.com/store/apps/details?id=" . $packageName . "&hl=$lang&gl=$loc";
4242
if ( ! $this->input = @file_get_contents($link) ) {
43-
return ['success'=>0,'message'=>'Google returned: '.$http_response_header[0]];
43+
return ['success'=>0,'message'=>'Google returned: ' . $http_response_header[0]];
4444
}
45-
$values=[];
46-
$values["packageName"]=$packageName;
45+
$values = [];
46+
$values["packageName"] = $packageName;
4747

4848
$values["name"] = strip_tags($this->getRegVal('/itemprop="name">(?<content>.*?)<\/h1>/'));
4949
if ($values["name"]==null) {
50-
return ['success'=>0,'message'=>'No app data found'];
50+
return ['success'=>0, 'message'=>'No app data found'];
5151
}
5252

5353
$values["developer"] = strip_tags($this->getRegVal('/href="\/store\/apps\/developer\?id=(?<id>[^\"]+)"([^\>]+|)>(?<content>[^\<]+)<\/a>/i'));
5454

5555
preg_match('/itemprop="genre" href="\/store\/apps\/category\/(?<id>[^\"]+)"([^\>]+|)>(?<content>[^\<]+)<\/a><\/span>/i', $this->input, $category);
56-
if(isset($category["id"], $category["content"])) {
57-
$values["category"]=trim(strip_tags($category["content"]));
58-
$catId=trim(strip_tags($category["id"]));
59-
if($catId=='GAME' || substr($catId,0,5)=='GAME_') $values["type"]="game";
60-
elseif($catId=='FAMILY' || substr($catId,0,7)=='FAMILY?') $values["type"]="family";
61-
else $values["type"]="app";
56+
if (isset($category["id"], $category["content"])) {
57+
$values["category"] = trim(strip_tags($category["content"]));
58+
$catId = trim(strip_tags($category["id"]));
59+
if ($catId=='GAME' || substr($catId,0,5)=='GAME_') $values["type"] = "game";
60+
elseif ($catId=='FAMILY' || substr($catId,0,7)=='FAMILY?') $values["type"] = "family";
61+
else $values["type"] = "app";
6262
} else {
63-
$values["category"]=null;
64-
$values["type"]=null;
63+
$values["category"] = null;
64+
$values["type"] = null;
6565
}
6666

6767
$proto = json_decode($this->getRegVal('/data:(?<content>\[\[\[.+?). sideChannel: .*?\);<\/script/ims'));
6868
$values["summary"] = $proto[0][10][1][1];
6969
$values["description"] = $this->getRegVal('/itemprop="description"><span jsslot><div jsname="sngebd">(?<content>.*?)<\/div><\/span><div/i');
7070
$values["icon"] = $this->getRegVal('/<div class="hkhL9e"><div class="xSyT2c"><img src="(?<content>[^\"]+)"/i');
71-
$values["featureGraphic"] = preg_replace('!(.*)=w\d+.*!i','$1',$this->getRegVal('/<meta name="twitter:image" content="(?<content>[^\"]+)"/i'));
71+
$values["featureGraphic"] = preg_replace('!(.*)=w\d+.*!i', '$1', $this->getRegVal('/<meta name="twitter:image" content="(?<content>[^\"]+)"/i'));
7272

7373
preg_match('/<div class="Rx5dXb"([^\>]+|)>(?<content>.*?)<c-data/i', $this->input, $image);
74-
if(isset($image["content"])) {
74+
if ( isset($image["content"]) ) {
7575
preg_match_all('/<img data-src="(?<content>[^\"]+)"/i', $image["content"], $images);
76-
if(isset($images["content"]) && !empty($images["content"])) {
77-
$values["images"]=$images["content"];
76+
if ( isset($images["content"]) && !empty($images["content"]) ) {
77+
$values["images"] = $images["content"];
7878
} else {
7979
preg_match_all('/<img src="[^"]*" srcset="(?<content>[^\s"]+)/i', $image["content"], $images);
80-
if(isset($images["content"])) {
81-
$values["images"]=$images["content"];
80+
if ( isset($images["content"]) ) {
81+
$values["images"] = $images["content"];
8282
} else {
83-
$values["images"]=null;
83+
$values["images"] = null;
8484
}
8585
}
8686
} else {
87-
$values["images"]=null;
87+
$values["images"] = null;
8888
}
8989

90-
if (substr(strtolower($lang),0,2)=='en') {
90+
if ( substr(strtolower($lang),0,2)=='en' ) {
9191
$values["lastUpdated"] = strip_tags($this->getRegVal('/<div class="BgcNfc">Updated<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>.*?)<\/span><\/div><\/span><\/div>/i'));
9292
$values["versionName"] = strip_tags($this->getRegVal('/<div class="BgcNfc">Current Version<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>.*?)<\/span><\/div><\/span><\/div>/i'));
9393
$values["minimumSDKVersion"] = strip_tags($this->getRegVal('/<div class="hAyfc"><div class="BgcNfc">Requires Android<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>.*?)<\/span><\/div><\/span><\/div>/i'));
@@ -96,14 +96,14 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {
9696
$values["size"] = $this->getRegVal('/<div class="BgcNfc">Size<\/div><span class="htlgb"><div class="IQ1z0d"><span class="htlgb">(?<content>[^<]+)<\/span>/i');
9797
} else {
9898
$envals = $this->parseApplication($packageName);
99-
foreach(["lastUpdated","versionName","minimumSDKVersion","installs","age","size"] as $val) $values[$val]=$envals[$val];
99+
foreach(["lastUpdated","versionName","minimumSDKVersion","installs","age","size"] as $val) $values[$val] = $envals[$val];
100100
}
101101

102102
$values["rating"] = $this->getRegVal('/<div class="BHMmbe"[^>]*>(?<content>[^<]+)<\/div>/i');
103103
$values["votes"] = $this->getRegVal('/<span class="AYi5wd TBRnV"><span[^>]*>(?<content>[^>]+)<\/span>/i');
104104
$values["price"] = $this->getRegVal('/<meta itemprop="price" content="(?<content>[^"]+)">/i');
105105

106-
if($this->debug) {
106+
if ($this->debug) {
107107
print_r($values);
108108
}
109109
$values['success'] = 1;
@@ -117,18 +117,18 @@ public function parseApplication($packageName, $lang='en_US', $loc='US') {
117117
*/
118118
public function parse($link=null) {
119119
if($link == "" || $link == null) {
120-
$link="https://play.google.com/apps";
120+
$link = "https://play.google.com/apps";
121121
}
122-
$input=file_get_contents($link);
122+
$input = file_get_contents($link);
123123
preg_match_all('/href="\/store\/apps\/details\?id=(?<ids>[^\"]+)"/i', $input, $ids);
124-
if(isset($ids["ids"])) {
125-
$ids=$ids["ids"];
126-
$ids=array_values(array_unique($ids));
127-
$values=$ids;
124+
if ( isset($ids["ids"]) ) {
125+
$ids = $ids["ids"];
126+
$ids = array_values(array_unique($ids));
127+
$values = $ids;
128128
} else {
129-
$values=[];
129+
$values = [];
130130
}
131-
if($this->debug) {
131+
if ($this->debug) {
132132
print_r($values);
133133
}
134134
return $values;
@@ -152,29 +152,29 @@ public function parsePerms($packageName, $lang='en') {
152152
'method' => 'POST',
153153
'header' => 'Content-type: application/x-www-form-urlencoded;charset=utf-8'
154154
."\r\n".'Referer: https://play.google.com/',
155-
'content' => 'f.req=%5B%5B%5B%22xdSrCf%22%2C%22%5B%5Bnull%2C%5B%5C%22'.$packageName.'%5C%22%2C7%5D%2C%5B%5D%5D%5D%22%2Cnull%2C%221%22%5D%5D%5D',
155+
'content' => 'f.req=%5B%5B%5B%22xdSrCf%22%2C%22%5B%5Bnull%2C%5B%5C%22' . $packageName . '%5C%22%2C7%5D%2C%5B%5D%5D%5D%22%2Cnull%2C%221%22%5D%5D%5D',
156156
'ignore_errors' => TRUE
157157
)
158158
];
159159
$context = stream_context_create($opts);
160-
if ( $proto = @file_get_contents('https://play.google.com/_/PlayStoreUi/data/batchexecute?rpcids=xdSrCf&bl=boq_playuiserver_20201201.06_p0&hl='.$lang.'&authuser&soc-app=121&soc-platform=1&soc-device=1&rt=c&f.sid=-8792622157958052111&_reqid=257685', false, $context) ) { // raw proto_buf data
161-
preg_match("!HTTP/1\.\d\s+(\d{3})\s+(.+)$!i",$http_response_header[0],$match);
160+
if ( $proto = @file_get_contents('https://play.google.com/_/PlayStoreUi/data/batchexecute?rpcids=xdSrCf&bl=boq_playuiserver_20201201.06_p0&hl=' . $lang . '&authuser&soc-app=121&soc-platform=1&soc-device=1&rt=c&f.sid=-8792622157958052111&_reqid=257685', false, $context) ) { // raw proto_buf data
161+
preg_match("!HTTP/1\.\d\s+(\d{3})\s+(.+)$!i", $http_response_header[0], $match);
162162
$response_code = $match[1];
163163
switch ($response_code) {
164164
case "200" : // HTTP/1.0 200 OK
165165
break;
166166
case "400" : // echo "! No XHR for '$pkg'\n";
167167
case "404" : // app no longer on play
168168
default:
169-
return ['success'=>0,'message'=>$http_response_header[0]];
169+
return ['success'=>0, 'message'=>$http_response_header[0]];
170170
break;
171171
}
172172
} else { // network error (e.g. "failed to open stream: Connection timed out")
173-
return ['success'=>0,'message'=>'network error'];
173+
return ['success'=>0, 'message'=>'network error'];
174174
}
175175

176176
$perms = $perms_unique = [];
177-
$json = preg_replace('!.*?(\[.+?\])\s*\d.*!ims','$1',$proto);
177+
$json = preg_replace('!.*?(\[.+?\])\s*\d.*!ims', '$1', $proto);
178178
$arr = json_decode(json_decode($json)[0][2]);
179179
if (!empty($arr[0])) foreach ($arr[0] as $group) { // 0: group name, 1: group icon, 2: perms, 3: group_id
180180
if (empty($group)) continue;
@@ -191,7 +191,7 @@ public function parsePerms($packageName, $lang='en') {
191191
foreach($arr[2] as $perm) $perms_unique[] = $perm[1];
192192
}
193193

194-
return ['success'=>1,'grouped'=>$perms,'perms'=>array_unique($perms_unique)];
194+
return ['success'=>1, 'grouped'=>$perms, 'perms'=>array_unique($perms_unique)];
195195
}
196196

197197
/** Parse Play Store page for a given category and return package names
@@ -201,7 +201,7 @@ public function parsePerms($packageName, $lang='en') {
201201
* @return array array of package names
202202
*/
203203
public function parseCategory($category) {
204-
$link="https://play.google.com/store/apps/category/".$category;
204+
$link = "https://play.google.com/store/apps/category/" . $category;
205205
return $this->parse($link);
206206
}
207207

@@ -211,7 +211,7 @@ public function parseCategory($category) {
211211
*/
212212
public function parseCategories() {
213213
$input = file_get_contents('https://play.google.com/store/apps/details?id=com.google.android.gm&hl=en&gl=US');
214-
preg_match_all('!href="/store/apps/category/([^"]+)"[^>]*>([^<]+)!i',$input,$cats);
214+
preg_match_all('!href="/store/apps/category/([^"]+)"[^>]*>([^<]+)!i', $input, $cats);
215215
return array_unique($cats[1]);
216216
}
217217

@@ -221,7 +221,7 @@ public function parseCategories() {
221221
* @return array array of package names
222222
*/
223223
public function parseSearch($query) {
224-
$link="https://play.google.com/store/search?q=".$query."&c=apps";
224+
$link = "https://play.google.com/store/search?q=". $query ."&c=apps";
225225
return $this->parse($link);
226226
}
227227
}

0 commit comments

Comments
 (0)