Replaced the nifty anonymous permissions sorting comparison function with inherited scope variables with a regular function and a global (ick!) variable.

Now the code should work with PHP versions prior to 5.3.0 as well...
This commit is contained in:
Hans-Emil Skogh 2012-01-17 21:48:48 +01:00 committed by Ciaran Gultnieks
parent d4179f925e
commit eb42f470b1

View file

@ -102,6 +102,7 @@ class FDroid
function get_app($query_vars) { function get_app($query_vars) {
global $permissions_data;
$permissions_object = new AndroidPermissions($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache'); $permissions_object = new AndroidPermissions($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');
$permissions_data = $permissions_object->get_permissions_array(); $permissions_data = $permissions_object->get_permissions_array();
@ -224,29 +225,7 @@ class FDroid
$out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divId.'\');">view permissions</a><br/>'; $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divId.'\');">view permissions</a><br/>';
$out.='<div style="display:'.$divStyleDisplay.';" id="'.$divId.'">'; $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divId.'">';
$permissions = explode(',',$apk['permissions']); $permissions = explode(',',$apk['permissions']);
usort($permissions, usort($permissions, "permissions_cmp");
function ($a, $b) use (&$permissions_data) {
$aProtectionLevel = $permissions_data['permission'][$a]['protectionLevel'];
$bProtectionLevel = $permissions_data['permission'][$b]['protectionLevel'];
if($aProtectionLevel != $bProtectionLevel) {
if(strlen($aProtectionLevel)==0) return 1;
if(strlen($bProtectionLevel)==0) return -1;
return strcmp($aProtectionLevel, $bProtectionLevel);
}
$aGroup = $permissions_data['permission'][$a]['permissionGroup'];
$bGroup = $permissions_data['permission'][$b]['permissionGroup'];
if($aGroup != $bGroup) {
return strcmp($aGroup, $bGroup);
}
return strcmp($a, $b);
}
);
$permission_group_last = ''; $permission_group_last = '';
foreach($permissions as $permission) { foreach($permissions as $permission) {
@ -523,6 +502,29 @@ class FDOutGrid
} }
} }
function permissions_cmp($a, $b) {
global $permissions_data;
$aProtectionLevel = $permissions_data['permission'][$a]['protectionLevel'];
$bProtectionLevel = $permissions_data['permission'][$b]['protectionLevel'];
if($aProtectionLevel != $bProtectionLevel) {
if(strlen($aProtectionLevel)==0) return 1;
if(strlen($bProtectionLevel)==0) return -1;
return strcmp($aProtectionLevel, $bProtectionLevel);
}
$aGroup = $permissions_data['permission'][$a]['permissionGroup'];
$bGroup = $permissions_data['permission'][$b]['permissionGroup'];
if($aGroup != $bGroup) {
return strcmp($aGroup, $bGroup);
}
return strcmp($a, $b);
}
// Make a link to this page, with the current query vars attached and desired params added/modified // Make a link to this page, with the current query vars attached and desired params added/modified
function makelink($query_vars, $params=array()) { function makelink($query_vars, $params=array()) {
$link=get_permalink(); $link=get_permalink();