';
$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'];
- return strcmp($aGroup, $bGroup);
- }
+ if($aGroup != $bGroup) {
+ return strcmp($aGroup, $bGroup);
+ }
-
-
+ return strcmp($a, $b);
+ }
);
$permission_group_last = '';
foreach($permissions as $permission) {
$permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
if($permission_group != $permission_group_last) {
- $out.='
'.strtoupper($permissions_data['permission-group'][$permission_group]['label']).'';
+ $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
+ if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
+ $out.='
'.strtoupper($permission_group_label).'';
$permission_group_last = $permission_group;
}
$out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
$out.='
'.$permissions_data['permission'][$permission]['label'].' [
'.$permission.'
]
';
- $out.=$permissions_data['permission'][$permission]['description'].'
';
+ if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'
';
//$out.=$permissions_data['permission'][$permission]['comment'].'
';
$out.='
';
}
@@ -284,7 +288,7 @@ class FDroid
}
else
{
- return '
!';
+ return '
⚙';
}
}
From 044914777f619defcf30da0c75f3415181c86379 Mon Sep 17 00:00:00 2001
From: Hans-Emil Skogh
Date: Thu, 12 Jan 2012 21:27:32 +0100
Subject: [PATCH 17/20] Normalized indentation and eol.
---
wp-fdroid/android-permissions.php | 204 +++---
wp-fdroid/wp-fdroid.php | 1072 ++++++++++++++---------------
2 files changed, 638 insertions(+), 638 deletions(-)
diff --git a/wp-fdroid/android-permissions.php b/wp-fdroid/android-permissions.php
index c1c73c61..7e1288a9 100644
--- a/wp-fdroid/android-permissions.php
+++ b/wp-fdroid/android-permissions.php
@@ -1,103 +1,103 @@
-load($android_manifest_file_path);
- $manifestXpath = new DOMXPath($manifestDoc);
-
- $stringsDoc = new DOMDocument;
- $stringsDoc->load($android_strings_file_path);
- $stringsXpath = new DOMXPath($stringsDoc);
-
- $comment = '';
- foreach ($manifestXpath->query('node()') as $node) {
- // Save permissions and permission groups from tags
- if($node->nodeName == 'permission-group' || $node->nodeName == 'permission') {
- $name = $node->attributes->getNamedItem('name')->value;
- $name = substr(strrchr($name,'.'), 1);
-
- // Lookup the human readable title
- $labelObject = $node->attributes->getNamedItem('label');
- $labelString = $name;
- if( $labelObject !== NULL ) {
- $labelName = substr(strrchr($labelObject->value,'/'),1);
- $labelStringObject = $stringsXpath->query('//string[@name="'.$labelName.'"]');
- $labelString = ucfirst($labelStringObject->item(0)->nodeValue);
- }
-
- // Lookup the human readable description
- $descriptionObject = $node->attributes->getNamedItem('description');
- $descriptionString = '(Description missing)';
- if($descriptionObject !== NULL) {
- $descriptionName = substr(strrchr($descriptionObject->value,'/'),1);
- $descriptionStringObject = $stringsXpath->query('//string[@name="'.$descriptionName.'"]');
- $descriptionString = ucfirst($descriptionStringObject->item(0)->nodeValue);
- }
-
- $permissions[$node->nodeName][$name]['label'] = stripslashes($labelString);
- $permissions[$node->nodeName][$name]['description'] = stripslashes($descriptionString);
- $permissions[$node->nodeName][$name]['comment'] = stripslashes(str_replace(array("\r\n", "\r", "\n", "\t", ' '), '', $comment));
-
- if($node->nodeName == 'permission') {
- $permissionGroupObject = $node->attributes->getNamedItem('permissionGroup');
- $permissionGroup = 'none';
- if($permissionGroupObject !== NULL) {
- $permissionGroup = substr(strrchr($permissionGroupObject->value,'.'), 1);
- }
-
- $permissions[$node->nodeName][$name]['permissionGroup'] = $permissionGroup;
- $permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;
- }
- }
-
- // Cache descriptions from comments preceding the tags
- if($node->nodeName == '#comment') {
- $comment .= $node->textContent;
- }
- elseif($node->nodeName != '#text') {
- $comment = '';
- }
- }
-
- // Update cache with serialized permissions
- $cache_file_handle = fopen($cache_file_path, 'w');
- fwrite($cache_file_handle, serialize($permissions));
- fclose($cache_file_handle);
-
- return $permissions;
-}
+load($android_manifest_file_path);
+ $manifestXpath = new DOMXPath($manifestDoc);
+
+ $stringsDoc = new DOMDocument;
+ $stringsDoc->load($android_strings_file_path);
+ $stringsXpath = new DOMXPath($stringsDoc);
+
+ $comment = '';
+ foreach ($manifestXpath->query('node()') as $node) {
+ // Save permissions and permission groups from tags
+ if($node->nodeName == 'permission-group' || $node->nodeName == 'permission') {
+ $name = $node->attributes->getNamedItem('name')->value;
+ $name = substr(strrchr($name,'.'), 1);
+
+ // Lookup the human readable title
+ $labelObject = $node->attributes->getNamedItem('label');
+ $labelString = $name;
+ if( $labelObject !== NULL ) {
+ $labelName = substr(strrchr($labelObject->value,'/'),1);
+ $labelStringObject = $stringsXpath->query('//string[@name="'.$labelName.'"]');
+ $labelString = ucfirst($labelStringObject->item(0)->nodeValue);
+ }
+
+ // Lookup the human readable description
+ $descriptionObject = $node->attributes->getNamedItem('description');
+ $descriptionString = '(Description missing)';
+ if($descriptionObject !== NULL) {
+ $descriptionName = substr(strrchr($descriptionObject->value,'/'),1);
+ $descriptionStringObject = $stringsXpath->query('//string[@name="'.$descriptionName.'"]');
+ $descriptionString = ucfirst($descriptionStringObject->item(0)->nodeValue);
+ }
+
+ $permissions[$node->nodeName][$name]['label'] = stripslashes($labelString);
+ $permissions[$node->nodeName][$name]['description'] = stripslashes($descriptionString);
+ $permissions[$node->nodeName][$name]['comment'] = stripslashes(str_replace(array("\r\n", "\r", "\n", "\t", ' '), '', $comment));
+
+ if($node->nodeName == 'permission') {
+ $permissionGroupObject = $node->attributes->getNamedItem('permissionGroup');
+ $permissionGroup = 'none';
+ if($permissionGroupObject !== NULL) {
+ $permissionGroup = substr(strrchr($permissionGroupObject->value,'.'), 1);
+ }
+
+ $permissions[$node->nodeName][$name]['permissionGroup'] = $permissionGroup;
+ $permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;
+ }
+ }
+
+ // Cache descriptions from comments preceding the tags
+ if($node->nodeName == '#comment') {
+ $comment .= $node->textContent;
+ }
+ elseif($node->nodeName != '#text') {
+ $comment = '';
+ }
+ }
+
+ // Update cache with serialized permissions
+ $cache_file_handle = fopen($cache_file_path, 'w');
+ fwrite($cache_file_handle, serialize($permissions));
+ fclose($cache_file_handle);
+
+ return $permissions;
+}
?>
\ No newline at end of file
diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php
index 8e073371..e3ec52d5 100644
--- a/wp-fdroid/wp-fdroid.php
+++ b/wp-fdroid/wp-fdroid.php
@@ -1,536 +1,536 @@
-inited=false;
- $this->site_path=getenv('DOCUMENT_ROOT');
- }
-
-
- // Register additional query variables. (Handler for the 'query_vars' filter)
- function queryvars($qvars) {
- $qvars[]='fdfilter';
- $qvars[]='fdid';
- $qvars[]='fdpage';
- $qvars[]='fdstyle';
- return $qvars;
- }
-
-
- // Lazy initialise. All non-trivial members should call this before doing anything else.
- function lazyinit() {
- if(!$this->inited) {
- load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
-
- $this->inited=true;
- }
- }
-
- // Gets a required query parameter by name.
- function getrequiredparam($name) {
- global $wp_query;
- if(!isset($wp_query->query_vars[$name]))
- wp_die("Missing parameter ".$name,"Error");
- return $wp_query->query_vars[$name];
- }
-
- // Handler for the 'fdroidrepo' shortcode.
- // $attribs - shortcode attributes
- // $content - optional content enclosed between the starting and
- // ending shortcode
- // Returns the generated content.
- function do_shortcode($attribs,$content=null) {
- global $wp_query,$wp_rewrite;
- $this->lazyinit();
-
-
- // Init local query vars
- foreach($this->queryvars(array()) as $qv) {
- if(array_key_exists($qv,$wp_query->query_vars)) {
- $query_vars[$qv] = $wp_query->query_vars[$qv];
- } else {
- $query_vars[$qv] = null;
- }
- }
-
- // Santiy check query vars
- if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) {
- $query_vars['fdpage'] = 1;
- }
-
- $out = '';
-
- if(isset($attribs['search']) && $query_vars['fdfilter']===null) {
- $query_vars['fdfilter'] = '';
- }
-
- if($query_vars['fdid']!==null) {
- $out.=$this->get_app($query_vars);
- } else {
- if($query_vars['fdfilter'] !== null)
- $out.=$this->show_search($query_vars);
-
- $out.=$this->get_apps($query_vars);
- }
- return $out;
-
- }
-
-
- function get_app($query_vars) {
- $permissions_data = get_android_permissions_array($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');
-
- $xml = simplexml_load_file($this->site_path.'/repo/index.xml');
- foreach($xml->children() as $app) {
-
- $attrs=$app->attributes();
- if($attrs['id']==$query_vars['fdid']) {
- $apks=array();;
- foreach($app->children() as $el) {
- switch($el->getName()) {
- case "name":
- $name=$el;
- break;
- case "icon":
- $icon=$el;
- break;
- case "summary":
- $summary=$el;
- break;
- case "description":
- $desc=$el;
- break;
- case "license":
- $license=$el;
- break;
- case "source":
- $source=$el;
- break;
- case "tracker":
- $issues=$el;
- break;
- case "donate":
- $donate=$el;
- break;
- case "web":
- $web=$el;
- break;
- case "package":
- $thisapk=array();
- foreach($el->children() as $pel) {
- switch($pel->getName()) {
- case "version":
- $thisapk['version']=$pel;
- break;
- case "vercode":
- $thisapk['vercode']=$pel;
- break;
- case "apkname":
- $thisapk['apkname']=$pel;
- break;
- case "srcname":
- $thisapk['srcname']=$pel;
- break;
- case "hash":
- $thisapk['hash']=$pel;
- break;
- case "size":
- $thisapk['size']=$pel;
- break;
- case "sdkver":
- $thisapk['sdkver']=$pel;
- break;
- case "permissions":
- $thisapk['permissions']=$pel;
- break;
- }
- }
- $apks[]=$thisapk;
-
- }
- }
-
- $out='";
-
- $out.="".$desc."
";
-
- $out.="License: ".$license."
";
-
- $out.="";
- if(strlen($web)>0)
- $out.='Website: '.$web.'
';
- if(strlen($issues)>0)
- $out.='Issue Tracker: '.$issues.'
';
- if(strlen($source)>0)
- $out.='Source Code: '.$source.'
';
- if($donate && strlen($donate)>0)
- $out.='Donate: '.$donate.'
';
- $out.="
";
-
- $out.='';
-
- $out.="Packages
";
- $i=0;
- foreach($apks as $apk) {
- $out.="Version ".$apk['version']."
";
- $out.='download apk ';
- $out.=$apk['size']." bytes";
- if($apk['srcname'])
- $out.='
source tarball';
-
- /*if($i==0)
- $divStyleDisplay='block';
- else*/
- $divStyleDisplay='none';
- $divId='permissions'.$i;
- $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);
- }
- );
-
- $permission_group_last = '';
- foreach($permissions as $permission) {
- $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
- if($permission_group != $permission_group_last) {
- $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
- if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
- $out.=''.strtoupper($permission_group_label).'
';
- $permission_group_last = $permission_group;
- }
-
- $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
- $out.=''.$permissions_data['permission'][$permission]['label'].' ['.$permission.'
]
';
- if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'
';
- //$out.=$permissions_data['permission'][$permission]['comment'].'
';
- $out.='
';
- }
- $out.='
';
-
- $out.='';
- $i++;
- }
-
- $out.='
Index
';
-
- return $out;
- }
- }
- return "Application not found
";
- }
-
- private function get_permission_protection_level_icon($protection_level) {
- if($protection_level=='dangerous')
- {
- return '⚠';
- }
- elseif($protection_level=='normal')
- {
- return 'ⓘ';
- }
- else
- {
- return '⚙';
- }
- }
-
- function get_apps($query_vars) {
-
- $xml = simplexml_load_file($this->site_path."/repo/index.xml");
- $matches = $this->show_apps($xml,$query_vars,$numpages);
-
- $out='';
-
- if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0)
- {
- $out.='';
- if($query_vars['fdfilter']===null)
- $out.="All applications";
- else
- $out.='Applications matching "'.$query_vars['fdfilter'].'"';
- $out.="
";
-
- $out.='';
- $out.='
List | ';
- $out.='
Grid';
- $out.='
';
-
- $out.='
';
- }
-
- if($numpages>0) {
- $out.=$matches;
-
- $out.='
';
- if($query_vars['fdpage']==1) {
- $out.="<<first ";
- $out.="<prev ";
- } else {
- $out.='<<first ';
- $out.='<<prev ';
- }
- $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
- if($query_vars['fdpage']==$numpages) {
- $out.="next> ";
- $out.="last>> ";
- } else {
- $out.='next> ';
- $out.='last>> ';
- }
- $out.='
';
- } else if($query_vars['fdfilter']!='') {
- $out.='No matches
';
- }
-
- return $out;
- }
-
-
- function show_search($query_vars) {
-
- $out='';
- $out.=''."\n";
-
- return $out;
- }
-
-
- function show_apps($xml,$query_vars,&$numpages) {
-
- $skipped=0;
- $got=0;
- $total=0;
-
- if($query_vars['fdstyle']=='grid') {
- $outputter = new FDOutGrid();
- } else {
- $outputter = new FDOutList();
- }
-
- $out = "";
-
- $out.=$outputter->outputStart();
-
- foreach($xml->children() as $app) {
-
- if($app->getName() == 'repo') continue;
- $appinfo['attrs']=$app->attributes();
- $appinfo['id']=$appinfo['attrs']['id'];
- foreach($app->children() as $el) {
- switch($el->getName()) {
- case "name":
- $appinfo['name']=$el;
- break;
- case "icon":
- $appinfo['icon']=$el;
- break;
- case "summary":
- $appinfo['summary']=$el;
- break;
- case "license":
- $appinfo['license']=$el;
- break;
- }
- }
-
- if($query_vars['fdfilter']===null || $query_vars['fdfilter']!='' && (stristr($appinfo['name'],$query_vars['fdfilter']) || stristr($appinfo['summary'],$query_vars['fdfilter']))) {
- if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
- $skipped++;
- } else if($got<$outputter->perpage) {
- $out.=$outputter->outputEntry($query_vars, $appinfo);
- $got++;
- }
- $total++;
- }
-
- }
-
- $out.=$outputter->outputEnd();
-
- $numpages = ceil((float)$total/$outputter->perpage);
-
- return $out;
- }
-}
-
-// Class to output app entries in a detailed list format
-class FDOutList
-{
- var $perpage=30;
-
- function FDOutList() {
- }
-
- function outputStart() {
- return '';
- }
-
- function outputEntry($query_vars, $appinfo) {
- $out="";
- $out.="
\n";
- $out.='\n";
-
- return $out;
- }
-
- function outputEnd() {
- return '';
- }
-}
-
-// Class to output app entries in a compact grid format
-class FDOutGrid
-{
- var $perpage=80;
-
- var $itemCount = 0;
-
- function FDOutGrid() {
- }
-
- function outputStart() {
- return "\n".''."\n";
- }
-
- function outputEntry($query_vars, $appinfo) {
- $link=makelink($query_vars, array('fdid'=>$appinfo['id']));
-
- $out='';
-
- if($this->itemCount%4 == 0 && $this->itemCount > 0)
- {
- $out.='
'."\n";
- }
-
- $out.='';
- $out.=' ';
- $out.=' ";
- $out.='';
- $out.=" | \n";
-
- $this->itemCount++;
- return $out;
- }
-
- function outputEnd() {
- return '
'."\n";
- }
-}
-
-// 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();
- $vars=linkify(array_merge($query_vars, $params));
- if(strlen($vars)==0)
- return $link;
- if(strpos($link,'?')===false)
- $link.='?';
- else
- $link.='&';
- return $link.$vars;
-}
-
-// Return the key value pairs in http-get-parameter format as a string
-function linkify($vars) {
- $retvar = '';
- foreach($vars as $k => $v) {
- if($k!==null && $v!==null && $v!='')
- $retvar .= $k.'='.$v.'&';
- }
- return substr($retvar,0,-1);
-}
-
-
-$wp_fdroid = new FDroid();
-
-
-?>
+inited=false;
+ $this->site_path=getenv('DOCUMENT_ROOT');
+ }
+
+
+ // Register additional query variables. (Handler for the 'query_vars' filter)
+ function queryvars($qvars) {
+ $qvars[]='fdfilter';
+ $qvars[]='fdid';
+ $qvars[]='fdpage';
+ $qvars[]='fdstyle';
+ return $qvars;
+ }
+
+
+ // Lazy initialise. All non-trivial members should call this before doing anything else.
+ function lazyinit() {
+ if(!$this->inited) {
+ load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
+
+ $this->inited=true;
+ }
+ }
+
+ // Gets a required query parameter by name.
+ function getrequiredparam($name) {
+ global $wp_query;
+ if(!isset($wp_query->query_vars[$name]))
+ wp_die("Missing parameter ".$name,"Error");
+ return $wp_query->query_vars[$name];
+ }
+
+ // Handler for the 'fdroidrepo' shortcode.
+ // $attribs - shortcode attributes
+ // $content - optional content enclosed between the starting and
+ // ending shortcode
+ // Returns the generated content.
+ function do_shortcode($attribs,$content=null) {
+ global $wp_query,$wp_rewrite;
+ $this->lazyinit();
+
+
+ // Init local query vars
+ foreach($this->queryvars(array()) as $qv) {
+ if(array_key_exists($qv,$wp_query->query_vars)) {
+ $query_vars[$qv] = $wp_query->query_vars[$qv];
+ } else {
+ $query_vars[$qv] = null;
+ }
+ }
+
+ // Santiy check query vars
+ if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) {
+ $query_vars['fdpage'] = 1;
+ }
+
+ $out = '';
+
+ if(isset($attribs['search']) && $query_vars['fdfilter']===null) {
+ $query_vars['fdfilter'] = '';
+ }
+
+ if($query_vars['fdid']!==null) {
+ $out.=$this->get_app($query_vars);
+ } else {
+ if($query_vars['fdfilter'] !== null)
+ $out.=$this->show_search($query_vars);
+
+ $out.=$this->get_apps($query_vars);
+ }
+ return $out;
+
+ }
+
+
+ function get_app($query_vars) {
+ $permissions_data = get_android_permissions_array($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');
+
+ $xml = simplexml_load_file($this->site_path.'/repo/index.xml');
+ foreach($xml->children() as $app) {
+
+ $attrs=$app->attributes();
+ if($attrs['id']==$query_vars['fdid']) {
+ $apks=array();;
+ foreach($app->children() as $el) {
+ switch($el->getName()) {
+ case "name":
+ $name=$el;
+ break;
+ case "icon":
+ $icon=$el;
+ break;
+ case "summary":
+ $summary=$el;
+ break;
+ case "description":
+ $desc=$el;
+ break;
+ case "license":
+ $license=$el;
+ break;
+ case "source":
+ $source=$el;
+ break;
+ case "tracker":
+ $issues=$el;
+ break;
+ case "donate":
+ $donate=$el;
+ break;
+ case "web":
+ $web=$el;
+ break;
+ case "package":
+ $thisapk=array();
+ foreach($el->children() as $pel) {
+ switch($pel->getName()) {
+ case "version":
+ $thisapk['version']=$pel;
+ break;
+ case "vercode":
+ $thisapk['vercode']=$pel;
+ break;
+ case "apkname":
+ $thisapk['apkname']=$pel;
+ break;
+ case "srcname":
+ $thisapk['srcname']=$pel;
+ break;
+ case "hash":
+ $thisapk['hash']=$pel;
+ break;
+ case "size":
+ $thisapk['size']=$pel;
+ break;
+ case "sdkver":
+ $thisapk['sdkver']=$pel;
+ break;
+ case "permissions":
+ $thisapk['permissions']=$pel;
+ break;
+ }
+ }
+ $apks[]=$thisapk;
+
+ }
+ }
+
+ $out='";
+
+ $out.="".$desc."
";
+
+ $out.="License: ".$license."
";
+
+ $out.="";
+ if(strlen($web)>0)
+ $out.='Website: '.$web.'
';
+ if(strlen($issues)>0)
+ $out.='Issue Tracker: '.$issues.'
';
+ if(strlen($source)>0)
+ $out.='Source Code: '.$source.'
';
+ if($donate && strlen($donate)>0)
+ $out.='Donate: '.$donate.'
';
+ $out.="
";
+
+ $out.='';
+
+ $out.="Packages
";
+ $i=0;
+ foreach($apks as $apk) {
+ $out.="Version ".$apk['version']."
";
+ $out.='download apk ';
+ $out.=$apk['size']." bytes";
+ if($apk['srcname'])
+ $out.='
source tarball';
+
+ /*if($i==0)
+ $divStyleDisplay='block';
+ else*/
+ $divStyleDisplay='none';
+ $divId='permissions'.$i;
+ $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);
+ }
+ );
+
+ $permission_group_last = '';
+ foreach($permissions as $permission) {
+ $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
+ if($permission_group != $permission_group_last) {
+ $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
+ if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
+ $out.=''.strtoupper($permission_group_label).'
';
+ $permission_group_last = $permission_group;
+ }
+
+ $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
+ $out.=''.$permissions_data['permission'][$permission]['label'].' ['.$permission.'
]
';
+ if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'
';
+ //$out.=$permissions_data['permission'][$permission]['comment'].'
';
+ $out.='
';
+ }
+ $out.='
';
+
+ $out.='';
+ $i++;
+ }
+
+ $out.='
Index
';
+
+ return $out;
+ }
+ }
+ return "Application not found
";
+ }
+
+ private function get_permission_protection_level_icon($protection_level) {
+ if($protection_level=='dangerous')
+ {
+ return '⚠';
+ }
+ elseif($protection_level=='normal')
+ {
+ return 'ⓘ';
+ }
+ else
+ {
+ return '⚙';
+ }
+ }
+
+ function get_apps($query_vars) {
+
+ $xml = simplexml_load_file($this->site_path."/repo/index.xml");
+ $matches = $this->show_apps($xml,$query_vars,$numpages);
+
+ $out='';
+
+ if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0)
+ {
+ $out.='';
+ if($query_vars['fdfilter']===null)
+ $out.="All applications";
+ else
+ $out.='Applications matching "'.$query_vars['fdfilter'].'"';
+ $out.="
";
+
+ $out.='';
+ $out.='
List | ';
+ $out.='
Grid';
+ $out.='
';
+
+ $out.='
';
+ }
+
+ if($numpages>0) {
+ $out.=$matches;
+
+ $out.='
';
+ if($query_vars['fdpage']==1) {
+ $out.="<<first ";
+ $out.="<prev ";
+ } else {
+ $out.='<<first ';
+ $out.='<<prev ';
+ }
+ $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
+ if($query_vars['fdpage']==$numpages) {
+ $out.="next> ";
+ $out.="last>> ";
+ } else {
+ $out.='next> ';
+ $out.='last>> ';
+ }
+ $out.='
';
+ } else if($query_vars['fdfilter']!='') {
+ $out.='No matches
';
+ }
+
+ return $out;
+ }
+
+
+ function show_search($query_vars) {
+
+ $out='';
+ $out.=''."\n";
+
+ return $out;
+ }
+
+
+ function show_apps($xml,$query_vars,&$numpages) {
+
+ $skipped=0;
+ $got=0;
+ $total=0;
+
+ if($query_vars['fdstyle']=='grid') {
+ $outputter = new FDOutGrid();
+ } else {
+ $outputter = new FDOutList();
+ }
+
+ $out = "";
+
+ $out.=$outputter->outputStart();
+
+ foreach($xml->children() as $app) {
+
+ if($app->getName() == 'repo') continue;
+ $appinfo['attrs']=$app->attributes();
+ $appinfo['id']=$appinfo['attrs']['id'];
+ foreach($app->children() as $el) {
+ switch($el->getName()) {
+ case "name":
+ $appinfo['name']=$el;
+ break;
+ case "icon":
+ $appinfo['icon']=$el;
+ break;
+ case "summary":
+ $appinfo['summary']=$el;
+ break;
+ case "license":
+ $appinfo['license']=$el;
+ break;
+ }
+ }
+
+ if($query_vars['fdfilter']===null || $query_vars['fdfilter']!='' && (stristr($appinfo['name'],$query_vars['fdfilter']) || stristr($appinfo['summary'],$query_vars['fdfilter']))) {
+ if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
+ $skipped++;
+ } else if($got<$outputter->perpage) {
+ $out.=$outputter->outputEntry($query_vars, $appinfo);
+ $got++;
+ }
+ $total++;
+ }
+
+ }
+
+ $out.=$outputter->outputEnd();
+
+ $numpages = ceil((float)$total/$outputter->perpage);
+
+ return $out;
+ }
+}
+
+// Class to output app entries in a detailed list format
+class FDOutList
+{
+ var $perpage=30;
+
+ function FDOutList() {
+ }
+
+ function outputStart() {
+ return '';
+ }
+
+ function outputEntry($query_vars, $appinfo) {
+ $out="";
+ $out.="
\n";
+ $out.='\n";
+
+ return $out;
+ }
+
+ function outputEnd() {
+ return '';
+ }
+}
+
+// Class to output app entries in a compact grid format
+class FDOutGrid
+{
+ var $perpage=80;
+
+ var $itemCount = 0;
+
+ function FDOutGrid() {
+ }
+
+ function outputStart() {
+ return "\n".''."\n";
+ }
+
+ function outputEntry($query_vars, $appinfo) {
+ $link=makelink($query_vars, array('fdid'=>$appinfo['id']));
+
+ $out='';
+
+ if($this->itemCount%4 == 0 && $this->itemCount > 0)
+ {
+ $out.='
'."\n";
+ }
+
+ $out.='';
+ $out.=' ';
+ $out.=' ";
+ $out.='';
+ $out.=" | \n";
+
+ $this->itemCount++;
+ return $out;
+ }
+
+ function outputEnd() {
+ return '
'."\n";
+ }
+}
+
+// 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();
+ $vars=linkify(array_merge($query_vars, $params));
+ if(strlen($vars)==0)
+ return $link;
+ if(strpos($link,'?')===false)
+ $link.='?';
+ else
+ $link.='&';
+ return $link.$vars;
+}
+
+// Return the key value pairs in http-get-parameter format as a string
+function linkify($vars) {
+ $retvar = '';
+ foreach($vars as $k => $v) {
+ if($k!==null && $v!==null && $v!='')
+ $retvar .= $k.'='.$v.'&';
+ }
+ return substr($retvar,0,-1);
+}
+
+
+$wp_fdroid = new FDroid();
+
+
+?>
From 5f4a422b622260a00475a4daee37555e314ddd7c Mon Sep 17 00:00:00 2001
From: Hans-Emil Skogh
Date: Thu, 12 Jan 2012 21:46:49 +0100
Subject: [PATCH 18/20] Wrapped the android permissions function in a class
holding config variables.
---
wp-fdroid/android-permissions.php | 197 ++++++++++++++++--------------
wp-fdroid/wp-fdroid.php | 3 +-
2 files changed, 106 insertions(+), 94 deletions(-)
diff --git a/wp-fdroid/android-permissions.php b/wp-fdroid/android-permissions.php
index 7e1288a9..6b8c2805 100644
--- a/wp-fdroid/android-permissions.php
+++ b/wp-fdroid/android-permissions.php
@@ -1,103 +1,114 @@
android_manifest_file_path = $android_manifest_file_path_in;
+ $this->android_strings_file_path = $android_strings_file_path_in;
+ $this->cache_file_path = $cache_file_path_in;
}
+
+ // Returns an associative array with android permissions and data about them
+ function get_permissions_array() {
- // If the cache is fresh, use it instead
- if($android_manifest_file_mtime < $cache_file_mtime && $android_strings_file_mtime < $cache_file_mtime ) {
- $cache_file_handle = fopen($cache_file_path, 'r');
- $cache_file_content = fread($cache_file_handle, filesize($cache_file_path));
+ // Check status of cache
+ $android_manifest_file_stat = stat($this->android_manifest_file_path);
+ $android_manifest_file_mtime = $android_manifest_file_stat['mtime'];
+ $android_strings_file_stat = stat($this->android_strings_file_path);
+ $android_strings_file_mtime = $android_strings_file_stat['mtime'];
+ $cache_file_mtime = 0;
+ if(file_exists($this->cache_file_path)) {
+ $cache_file_stat = stat($this->cache_file_path);
+ $cache_file_mtime = $cache_file_stat['mtime'];
+ }
+
+ // If the cache is fresh, use it instead
+ if($android_manifest_file_mtime < $cache_file_mtime && $android_strings_file_mtime < $cache_file_mtime ) {
+ $cache_file_handle = fopen($this->cache_file_path, 'r');
+ $cache_file_content = fread($cache_file_handle, filesize($this->cache_file_path));
+ fclose($cache_file_handle);
+
+ $permissions = unserialize($cache_file_content);
+
+ return $permissions;
+ }
+
+ // We are updating the cache, touch the file (note: race condition possible between stating the cache file above and this line...)
+ touch($this->cache_file_path);
+
+ // Get permission raw data from XML
+ $manifestDoc = new DOMDocument;
+ $manifestDoc->load($this->android_manifest_file_path);
+ $manifestXpath = new DOMXPath($manifestDoc);
+
+ $stringsDoc = new DOMDocument;
+ $stringsDoc->load($this->android_strings_file_path);
+ $stringsXpath = new DOMXPath($stringsDoc);
+
+ $comment = '';
+ foreach ($manifestXpath->query('node()') as $node) {
+ // Save permissions and permission groups from tags
+ if($node->nodeName == 'permission-group' || $node->nodeName == 'permission') {
+ $name = $node->attributes->getNamedItem('name')->value;
+ $name = substr(strrchr($name,'.'), 1);
+
+ // Lookup the human readable title
+ $labelObject = $node->attributes->getNamedItem('label');
+ $labelString = $name;
+ if( $labelObject !== NULL ) {
+ $labelName = substr(strrchr($labelObject->value,'/'),1);
+ $labelStringObject = $stringsXpath->query('//string[@name="'.$labelName.'"]');
+ $labelString = ucfirst($labelStringObject->item(0)->nodeValue);
+ }
+
+ // Lookup the human readable description
+ $descriptionObject = $node->attributes->getNamedItem('description');
+ $descriptionString = '(Description missing)';
+ if($descriptionObject !== NULL) {
+ $descriptionName = substr(strrchr($descriptionObject->value,'/'),1);
+ $descriptionStringObject = $stringsXpath->query('//string[@name="'.$descriptionName.'"]');
+ $descriptionString = ucfirst($descriptionStringObject->item(0)->nodeValue);
+ }
+
+ $permissions[$node->nodeName][$name]['label'] = stripslashes($labelString);
+ $permissions[$node->nodeName][$name]['description'] = stripslashes($descriptionString);
+ $permissions[$node->nodeName][$name]['comment'] = stripslashes(str_replace(array("\r\n", "\r", "\n", "\t", ' '), '', $comment));
+
+ if($node->nodeName == 'permission') {
+ $permissionGroupObject = $node->attributes->getNamedItem('permissionGroup');
+ $permissionGroup = 'none';
+ if($permissionGroupObject !== NULL) {
+ $permissionGroup = substr(strrchr($permissionGroupObject->value,'.'), 1);
+ }
+
+ $permissions[$node->nodeName][$name]['permissionGroup'] = $permissionGroup;
+ $permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;
+ }
+ }
+
+ // Cache descriptions from comments preceding the tags
+ if($node->nodeName == '#comment') {
+ $comment .= $node->textContent;
+ }
+ elseif($node->nodeName != '#text') {
+ $comment = '';
+ }
+ }
+
+ // Update cache with serialized permissions
+ $cache_file_handle = fopen($cache_file_path, 'w');
+ fwrite($cache_file_handle, serialize($permissions));
fclose($cache_file_handle);
- $permissions = unserialize($cache_file_content);
-
return $permissions;
}
-
- // We are updating the cache, touch the file (note: race condition possible between stating the cache file above and this line...)
- touch($cache_file_path);
-
- // Get permission raw data from XML
- $manifestDoc = new DOMDocument;
- $manifestDoc->load($android_manifest_file_path);
- $manifestXpath = new DOMXPath($manifestDoc);
-
- $stringsDoc = new DOMDocument;
- $stringsDoc->load($android_strings_file_path);
- $stringsXpath = new DOMXPath($stringsDoc);
-
- $comment = '';
- foreach ($manifestXpath->query('node()') as $node) {
- // Save permissions and permission groups from tags
- if($node->nodeName == 'permission-group' || $node->nodeName == 'permission') {
- $name = $node->attributes->getNamedItem('name')->value;
- $name = substr(strrchr($name,'.'), 1);
-
- // Lookup the human readable title
- $labelObject = $node->attributes->getNamedItem('label');
- $labelString = $name;
- if( $labelObject !== NULL ) {
- $labelName = substr(strrchr($labelObject->value,'/'),1);
- $labelStringObject = $stringsXpath->query('//string[@name="'.$labelName.'"]');
- $labelString = ucfirst($labelStringObject->item(0)->nodeValue);
- }
-
- // Lookup the human readable description
- $descriptionObject = $node->attributes->getNamedItem('description');
- $descriptionString = '(Description missing)';
- if($descriptionObject !== NULL) {
- $descriptionName = substr(strrchr($descriptionObject->value,'/'),1);
- $descriptionStringObject = $stringsXpath->query('//string[@name="'.$descriptionName.'"]');
- $descriptionString = ucfirst($descriptionStringObject->item(0)->nodeValue);
- }
-
- $permissions[$node->nodeName][$name]['label'] = stripslashes($labelString);
- $permissions[$node->nodeName][$name]['description'] = stripslashes($descriptionString);
- $permissions[$node->nodeName][$name]['comment'] = stripslashes(str_replace(array("\r\n", "\r", "\n", "\t", ' '), '', $comment));
-
- if($node->nodeName == 'permission') {
- $permissionGroupObject = $node->attributes->getNamedItem('permissionGroup');
- $permissionGroup = 'none';
- if($permissionGroupObject !== NULL) {
- $permissionGroup = substr(strrchr($permissionGroupObject->value,'.'), 1);
- }
-
- $permissions[$node->nodeName][$name]['permissionGroup'] = $permissionGroup;
- $permissions[$node->nodeName][$name]['protectionLevel'] = $node->attributes->getNamedItem('protectionLevel')->value;
- }
- }
-
- // Cache descriptions from comments preceding the tags
- if($node->nodeName == '#comment') {
- $comment .= $node->textContent;
- }
- elseif($node->nodeName != '#text') {
- $comment = '';
- }
- }
-
- // Update cache with serialized permissions
- $cache_file_handle = fopen($cache_file_path, 'w');
- fwrite($cache_file_handle, serialize($permissions));
- fclose($cache_file_handle);
-
- return $permissions;
}
-?>
\ No newline at end of file
+?>
diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php
index e3ec52d5..48ad80e0 100644
--- a/wp-fdroid/wp-fdroid.php
+++ b/wp-fdroid/wp-fdroid.php
@@ -103,7 +103,8 @@ class FDroid
function get_app($query_vars) {
- $permissions_data = get_android_permissions_array($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();
$xml = simplexml_load_file($this->site_path.'/repo/index.xml');
foreach($xml->children() as $app) {
From 82f5332af6229fb9e72371387621285ca7618ee1 Mon Sep 17 00:00:00 2001
From: Hans-Emil Skogh
Date: Thu, 12 Jan 2012 21:49:47 +0100
Subject: [PATCH 19/20] Removed executable permissions on strings.xml. *sigh*
---
wp-fdroid/strings.xml | 0
1 file changed, 0 insertions(+), 0 deletions(-)
mode change 100755 => 100644 wp-fdroid/strings.xml
diff --git a/wp-fdroid/strings.xml b/wp-fdroid/strings.xml
old mode 100755
new mode 100644
From a2569989b4529a5b56b1863f97aa6f889831f006 Mon Sep 17 00:00:00 2001
From: Hans-Emil Skogh
Date: Sat, 14 Jan 2012 12:39:33 +0100
Subject: [PATCH 20/20] Handle if a package has no permissions.
---
wp-fdroid/wp-fdroid.php | 98 +++++++++++++++++++++--------------------
1 file changed, 50 insertions(+), 48 deletions(-)
diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php
index 729345b8..1fb3d1ac 100644
--- a/wp-fdroid/wp-fdroid.php
+++ b/wp-fdroid/wp-fdroid.php
@@ -215,55 +215,60 @@ class FDroid
if($apk['srcname'])
$out.='
source tarball';
- /*if($i==0)
- $divStyleDisplay='block';
- else*/
- $divStyleDisplay='none';
- $divId='permissions'.$i;
- $out.='
view permissions
';
- $out.='';
- $permissions = explode(',',$apk['permissions']);
- usort($permissions,
- function ($a, $b) use (&$permissions_data) {
+ if(isset($apk['permissions'])) {
+ /*if($i==0)
+ $divStyleDisplay='block';
+ else*/
+ $divStyleDisplay='none';
+ $divId='permissions'.$i;
+ $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'];
+ $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;
+ if($aProtectionLevel != $bProtectionLevel) {
+ if(strlen($aProtectionLevel)==0) return 1;
+ if(strlen($bProtectionLevel)==0) return -1;
- return strcmp($aProtectionLevel, $bProtectionLevel);
+ 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 = '';
+ foreach($permissions as $permission) {
+ $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
+ if($permission_group != $permission_group_last) {
+ $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
+ if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
+ $out.=''.strtoupper($permission_group_label).'
';
+ $permission_group_last = $permission_group;
}
- $aGroup = $permissions_data['permission'][$a]['permissionGroup'];
- $bGroup = $permissions_data['permission'][$b]['permissionGroup'];
-
- if($aGroup != $bGroup) {
- return strcmp($aGroup, $bGroup);
- }
-
- return strcmp($a, $b);
+ $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
+ $out.=''.$permissions_data['permission'][$permission]['label'].' ['.$permission.'
]
';
+ if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'
';
+ //$out.=$permissions_data['permission'][$permission]['comment'].'
';
+ $out.='
';
}
- );
-
- $permission_group_last = '';
- foreach($permissions as $permission) {
- $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
- if($permission_group != $permission_group_last) {
- $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
- if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
- $out.=''.strtoupper($permission_group_label).'
';
- $permission_group_last = $permission_group;
- }
-
- $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
- $out.=''.$permissions_data['permission'][$permission]['label'].' ['.$permission.'
]
';
- if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'
';
- //$out.=$permissions_data['permission'][$permission]['comment'].'
';
- $out.='
';
+ $out.='
';
+ }
+ else {
+ $out.='
no permissions';
}
- $out.='
';
$out.='';
$i++;
@@ -278,16 +283,13 @@ class FDroid
}
private function get_permission_protection_level_icon($protection_level) {
- if($protection_level=='dangerous')
- {
+ if($protection_level=='dangerous') {
return '⚠';
}
- elseif($protection_level=='normal')
- {
+ elseif($protection_level=='normal') {
return 'ⓘ';
}
- else
- {
+ else {
return '⚙';
}
}