From: Hans-Emil Skogh Date: Tue, 17 Jan 2012 20:48:48 +0000 (+0100) Subject: Replaced the nifty anonymous permissions sorting comparison function with inherited... X-Git-Tag: 0.1~1063^2~5 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e915f71a81d996c4802835553f4667949497ae7c;p=fdroidserver.git 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... --- diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php index 0ea58d6c..6c981d83 100644 --- a/wp-fdroid/wp-fdroid.php +++ b/wp-fdroid/wp-fdroid.php @@ -102,6 +102,7 @@ class FDroid 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_data = $permissions_object->get_permissions_array(); @@ -226,29 +227,7 @@ class FDroid $out.='
view permissions
'; $out.='
'; $permissions = explode(',',$apk['permissions']); - usort($permissions, - 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); - } - ); + usort($permissions, "permissions_cmp"); $permission_group_last = ''; foreach($permissions as $permission) { @@ -536,6 +515,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 function makelink($query_vars, $params=array()) { $link=get_permalink();