mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-05 23:10:29 +03:00
Merge branch 'merge-requests/52'
This commit is contained in:
commit
6141b04a4c
4 changed files with 5695 additions and 456 deletions
1639
wp-fdroid/AndroidManifest.xml
Normal file
1639
wp-fdroid/AndroidManifest.xml
Normal file
File diff suppressed because it is too large
Load diff
114
wp-fdroid/android-permissions.php
Normal file
114
wp-fdroid/android-permissions.php
Normal file
|
|
@ -0,0 +1,114 @@
|
||||||
|
<?php
|
||||||
|
// Class that provides PHP-friendly android permissions information from the raw Andoid source XML files that describes the permissions.
|
||||||
|
class AndroidPermissions
|
||||||
|
{
|
||||||
|
|
||||||
|
// Path to the AndroidManifest.xml-file from the Android source. Get it from https://raw.github.com/android/platform_frameworks_base/master/core/res/AndroidManifest.xml for example.
|
||||||
|
private $android_manifest_file_path;
|
||||||
|
// Path to the strings.xml-file from the Android source. Get it from https://raw.github.com/android/platform_frameworks_base/master/core/res/res/values/strings.xml for example.
|
||||||
|
private $android_strings_file_path;
|
||||||
|
// Path to the file where the resulting permissions data will be cached. NOTE: Must be writable by PHP!
|
||||||
|
private $cache_file_path;
|
||||||
|
|
||||||
|
public function __construct($android_manifest_file_path_in = 'AndroidManifest.xml', $android_strings_file_path_in = 'strings.xml', $cache_file_path_in = 'android-permissions.cache') {
|
||||||
|
$this->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() {
|
||||||
|
|
||||||
|
// 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($this->cache_file_path, 'w');
|
||||||
|
fwrite($cache_file_handle, serialize($permissions));
|
||||||
|
fclose($cache_file_handle);
|
||||||
|
|
||||||
|
return $permissions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
3389
wp-fdroid/strings.xml
Normal file
3389
wp-fdroid/strings.xml
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -12,441 +12,538 @@ Revision history
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
include('android-permissions.php');
|
||||||
|
|
||||||
class FDroid
|
class FDroid
|
||||||
{
|
{
|
||||||
|
|
||||||
// Our text domain, for internationalisation
|
// Our text domain, for internationalisation
|
||||||
private $textdom='wp-fdroid';
|
private $textdom='wp-fdroid';
|
||||||
|
|
||||||
private $site_path;
|
private $site_path;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function FDroid() {
|
function FDroid() {
|
||||||
// Add filters etc here!
|
// Add filters etc here!
|
||||||
add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
|
add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
|
||||||
add_filter('query_vars',array($this, 'queryvars'));
|
add_filter('query_vars',array($this, 'queryvars'));
|
||||||
$this->inited=false;
|
$this->inited=false;
|
||||||
$this->site_path=getenv('DOCUMENT_ROOT');
|
$this->site_path=getenv('DOCUMENT_ROOT');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Register additional query variables. (Handler for the 'query_vars' filter)
|
// Register additional query variables. (Handler for the 'query_vars' filter)
|
||||||
function queryvars($qvars) {
|
function queryvars($qvars) {
|
||||||
$qvars[]='fdfilter';
|
$qvars[]='fdfilter';
|
||||||
$qvars[]='fdid';
|
$qvars[]='fdid';
|
||||||
$qvars[]='fdpage';
|
$qvars[]='fdpage';
|
||||||
$qvars[]='fdstyle';
|
$qvars[]='fdstyle';
|
||||||
return $qvars;
|
return $qvars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Lazy initialise. All non-trivial members should call this before doing anything else.
|
// Lazy initialise. All non-trivial members should call this before doing anything else.
|
||||||
function lazyinit() {
|
function lazyinit() {
|
||||||
if(!$this->inited) {
|
if(!$this->inited) {
|
||||||
load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
|
load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
|
||||||
|
|
||||||
$this->inited=true;
|
$this->inited=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a required query parameter by name.
|
// Gets a required query parameter by name.
|
||||||
function getrequiredparam($name) {
|
function getrequiredparam($name) {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
if(!isset($wp_query->query_vars[$name]))
|
if(!isset($wp_query->query_vars[$name]))
|
||||||
wp_die("Missing parameter ".$name,"Error");
|
wp_die("Missing parameter ".$name,"Error");
|
||||||
return $wp_query->query_vars[$name];
|
return $wp_query->query_vars[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for the 'fdroidrepo' shortcode.
|
// Handler for the 'fdroidrepo' shortcode.
|
||||||
// $attribs - shortcode attributes
|
// $attribs - shortcode attributes
|
||||||
// $content - optional content enclosed between the starting and
|
// $content - optional content enclosed between the starting and
|
||||||
// ending shortcode
|
// ending shortcode
|
||||||
// Returns the generated content.
|
// Returns the generated content.
|
||||||
function do_shortcode($attribs,$content=null) {
|
function do_shortcode($attribs,$content=null) {
|
||||||
global $wp_query,$wp_rewrite;
|
global $wp_query,$wp_rewrite;
|
||||||
$this->lazyinit();
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Init local query vars
|
function get_app($query_vars) {
|
||||||
foreach($this->queryvars(array()) as $qv) {
|
$permissions_object = new AndroidPermissions($this->site_path.'/repo/AndroidManifest.xml', $this->site_path.'/repo/strings.xml', $this->site_path.'/repo/android-permissions.cache');
|
||||||
if(array_key_exists($qv,$wp_query->query_vars)) {
|
$permissions_data = $permissions_object->get_permissions_array();
|
||||||
$query_vars[$qv] = $wp_query->query_vars[$qv];
|
|
||||||
} else {
|
|
||||||
$query_vars[$qv] = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Santiy check query vars
|
$xml = simplexml_load_file($this->site_path.'/repo/index.xml');
|
||||||
if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) {
|
foreach($xml->children() as $app) {
|
||||||
$query_vars['fdpage'] = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$out = '';
|
$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;
|
||||||
|
|
||||||
if(isset($attribs['search']) && $query_vars['fdfilter']===null) {
|
}
|
||||||
$query_vars['fdfilter'] = '';
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if($query_vars['fdid']!==null) {
|
$out='<div id="appheader">';
|
||||||
$out.=$this->get_app($query_vars);
|
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" width=48></div>';
|
||||||
} else {
|
$out.='<p><span style="font-size:20px">'.$name."</span>";
|
||||||
if($query_vars['fdfilter'] !== null)
|
$out.="<br>".$summary."</p>";
|
||||||
$out.=$this->show_search($query_vars);
|
$out.="</div>";
|
||||||
|
|
||||||
$out.=$this->get_apps($query_vars);
|
$out.="<p>".$desc."</p>";
|
||||||
}
|
|
||||||
return $out;
|
|
||||||
|
|
||||||
}
|
$out.="<p><b>License:</b> ".$license."</p>";
|
||||||
|
|
||||||
|
$out.="<p>";
|
||||||
|
if(strlen($web)>0)
|
||||||
|
$out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
|
||||||
|
if(strlen($issues)>0)
|
||||||
|
$out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
|
||||||
|
if(strlen($source)>0)
|
||||||
|
$out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
|
||||||
|
if($donate && strlen($donate)>0)
|
||||||
|
$out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />';
|
||||||
|
$out.="</p>";
|
||||||
|
|
||||||
|
$out.='<script type="text/javascript">';
|
||||||
|
$out.='function showHidePermissions(id) {';
|
||||||
|
$out.=' if(document.getElementById(id).style.display==\'none\')';
|
||||||
|
$out.=' document.getElementById(id).style.display=\'block\';';
|
||||||
|
$out.=' else';
|
||||||
|
$out.=' document.getElementById(id).style.display=\'none\';';
|
||||||
|
$out.=' return false;';
|
||||||
|
$out.='}';
|
||||||
|
$out.='</script>';
|
||||||
|
|
||||||
|
$out.="<h3>Packages</h3>";
|
||||||
|
$i=0;
|
||||||
|
foreach($apks as $apk) {
|
||||||
|
$out.="<p><b>Version ".$apk['version']."</b><br />";
|
||||||
|
$out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download apk</a> ';
|
||||||
|
$out.=$apk['size']." bytes";
|
||||||
|
if($apk['srcname'])
|
||||||
|
$out.='<br><a href="http://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a>';
|
||||||
|
|
||||||
|
if(isset($apk['permissions'])) {
|
||||||
|
/*if($i==0)
|
||||||
|
$divStyleDisplay='block';
|
||||||
|
else*/
|
||||||
|
$divStyleDisplay='none';
|
||||||
|
$divId='permissions'.$i;
|
||||||
|
$out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divId.'\');">view permissions</a><br/>';
|
||||||
|
$out.='<div style="display:'.$divStyleDisplay.';" id="'.$divId.'">';
|
||||||
|
$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.='<strong>'.strtoupper($permission_group_label).'</strong><br/>';
|
||||||
|
$permission_group_last = $permission_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
|
||||||
|
$out.='<strong>'.$permissions_data['permission'][$permission]['label'].'</strong> [<code>'.$permission.'</code>]<br/>';
|
||||||
|
if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'<br/>';
|
||||||
|
//$out.=$permissions_data['permission'][$permission]['comment'].'<br/>';
|
||||||
|
$out.='<br/>';
|
||||||
|
}
|
||||||
|
$out.='</div>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$out.='<br /><span style="color:#999999;">no permissions</span><br />';
|
||||||
|
}
|
||||||
|
|
||||||
|
$out.='</p>';
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>';
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "<p>Application not found</p>";
|
||||||
|
}
|
||||||
|
|
||||||
|
private function get_permission_protection_level_icon($protection_level) {
|
||||||
|
if($protection_level=='dangerous') {
|
||||||
|
return '<span style="color:#DD9900;font-size:150%;">⚠</span>';
|
||||||
|
}
|
||||||
|
elseif($protection_level=='normal') {
|
||||||
|
return '<span style="color:#6666FF;font-size:110%;">ⓘ</span>';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return '<span style="color:#33AA33;font-size:130%;">⚙</span>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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.='<div style="float:left;">';
|
||||||
|
if($query_vars['fdfilter']===null)
|
||||||
|
$out.="All applications";
|
||||||
|
else
|
||||||
|
$out.='Applications matching "'.$query_vars['fdfilter'].'"';
|
||||||
|
$out.="</div>";
|
||||||
|
|
||||||
|
$out.='<div style="float:right;">';
|
||||||
|
$out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list','fdpage'=>'1')).'">List</a> | ';
|
||||||
|
$out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid','fdpage'=>'1')).'">Grid</a>';
|
||||||
|
$out.='</div>';
|
||||||
|
|
||||||
|
$out.='<br break="all"/>';
|
||||||
|
}
|
||||||
|
|
||||||
|
if($numpages>0) {
|
||||||
|
$out.=$matches;
|
||||||
|
|
||||||
|
$out.='<hr><p>';
|
||||||
|
|
||||||
|
$out.='<div style="width:20%; float:left; text-align:left;">';
|
||||||
|
$out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
|
||||||
|
$out.='</div>';
|
||||||
|
|
||||||
|
$out.='<div style="width:60%; float:left; text-align:center;">';
|
||||||
|
if($numpages>1) {
|
||||||
|
for($i=1;$i<=$numpages;$i++) {
|
||||||
|
if($i == $query_vars['fdpage']) {
|
||||||
|
$out.='<b>'.$i.'</b>';
|
||||||
|
} else {
|
||||||
|
$out.='<a href="'.makelink($query_vars, array('fdpage'=>$i)).'">';
|
||||||
|
$out.=$i;
|
||||||
|
$out.='</a>';
|
||||||
|
}
|
||||||
|
$out.=' ';
|
||||||
|
}
|
||||||
|
$out.=' ';
|
||||||
|
}
|
||||||
|
$out.='</div>';
|
||||||
|
|
||||||
|
$out.='<div style="width:20%; float:left; text-align:right;">';
|
||||||
|
if($query_vars['fdpage']!=$numpages) {
|
||||||
|
$out.='<a href="'.makelink($query_vars, array('fdpage'=>($query_vars['fdpage']+1))).'">next></a> ';
|
||||||
|
}
|
||||||
|
$out.='</div>';
|
||||||
|
|
||||||
|
$out.='</p>';
|
||||||
|
} else if($query_vars['fdfilter']!='') {
|
||||||
|
$out.='<p>No matches</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_app($query_vars) {
|
function show_search($query_vars) {
|
||||||
|
|
||||||
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
$out='';
|
||||||
foreach($xml->children() as $app) {
|
$out.='<form name="searchform" action="" method="get">';
|
||||||
|
$out.='<p><input name="fdfilter" type="text" value="'.$query_vars['fdfilter'].'" size="30"> ';
|
||||||
|
$out.='<input type="submit" value="Search"></p>';
|
||||||
|
|
||||||
$attrs=$app->attributes();
|
$out.='<input type="hidden" name="page_id" value="'.get_query_var('page_id').'">';
|
||||||
if($attrs['id']==$query_vars['fdid']) {
|
foreach($query_vars as $name => $value) {
|
||||||
$apks=array();;
|
if($value !== null && $name != 'fdfilter')
|
||||||
foreach($app->children() as $el) {
|
$out.='<input type="hidden" name="'.$name.'" value="'.$value.'">';
|
||||||
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.='</form>'."\n";
|
||||||
}
|
|
||||||
|
|
||||||
$out='<div id="appheader">';
|
return $out;
|
||||||
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" width=48></div>';
|
}
|
||||||
$out.='<p><span style="font-size:20px">'.$name."</span>";
|
|
||||||
$out.="<br>".$summary."</p>";
|
|
||||||
$out.="</div>";
|
|
||||||
|
|
||||||
$out.="<p>".$desc."</p>";
|
|
||||||
|
|
||||||
$out.="<p><b>License:</b> ".$license."</p>";
|
|
||||||
|
|
||||||
$out.="<p>";
|
|
||||||
if(strlen($web)>0)
|
|
||||||
$out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
|
|
||||||
if(strlen($issues)>0)
|
|
||||||
$out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
|
|
||||||
if(strlen($source)>0)
|
|
||||||
$out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
|
|
||||||
if($donate && strlen($donate)>0)
|
|
||||||
$out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />';
|
|
||||||
$out.="</p>";
|
|
||||||
|
|
||||||
$out.="<h3>Packages</h3>";
|
|
||||||
foreach($apks as $apk) {
|
|
||||||
$out.="<p><b>Version ".$apk['version']."</b> - ";
|
|
||||||
$out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download</a> ';
|
|
||||||
$out.=$apk['size']." bytes";
|
|
||||||
if($apk['srcname'])
|
|
||||||
$out.='<br><a href="http://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a>';
|
|
||||||
$out.="</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>';
|
|
||||||
|
|
||||||
return $out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "<p>Application not found</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function get_apps($query_vars) {
|
function show_apps($xml,$query_vars,&$numpages) {
|
||||||
|
|
||||||
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
$skipped=0;
|
||||||
$matches = $this->show_apps($xml,$query_vars,$numpages);
|
$got=0;
|
||||||
|
$total=0;
|
||||||
|
|
||||||
$out='';
|
if($query_vars['fdstyle']=='grid') {
|
||||||
|
$outputter = new FDOutGrid();
|
||||||
|
} else {
|
||||||
|
$outputter = new FDOutList();
|
||||||
|
}
|
||||||
|
|
||||||
if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0)
|
$out = "";
|
||||||
{
|
|
||||||
$out.='<div style="float:left;">';
|
|
||||||
if($query_vars['fdfilter']===null)
|
|
||||||
$out.="All applications";
|
|
||||||
else
|
|
||||||
$out.='Applications matching "'.$query_vars['fdfilter'].'"';
|
|
||||||
$out.="</div>";
|
|
||||||
|
|
||||||
$out.='<div style="float:right;">';
|
$out.=$outputter->outputStart();
|
||||||
$out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list','fdpage'=>'1')).'">List</a> | ';
|
|
||||||
$out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid','fdpage'=>'1')).'">Grid</a>';
|
|
||||||
$out.='</div>';
|
|
||||||
|
|
||||||
$out.='<br break="all"/>';
|
foreach($xml->children() as $app) {
|
||||||
}
|
|
||||||
|
|
||||||
if($numpages>0) {
|
if($app->getName() == 'repo') continue;
|
||||||
$out.=$matches;
|
$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 "description":
|
||||||
|
$appinfo['description']=$el;
|
||||||
|
break;
|
||||||
|
case "license":
|
||||||
|
$appinfo['license']=$el;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$out.='<hr><p>';
|
if($query_vars['fdfilter']===null || $query_vars['fdfilter']!='' && (stristr($appinfo['name'],$query_vars['fdfilter']) || stristr($appinfo['summary'],$query_vars['fdfilter']) || stristr($appinfo['description'],$query_vars['fdfilter']))) {
|
||||||
if($query_vars['fdpage']==1) {
|
if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
|
||||||
$out.="<<first ";
|
$skipped++;
|
||||||
$out.="<prev ";
|
} else if($got<$outputter->perpage) {
|
||||||
} else {
|
$out.=$outputter->outputEntry($query_vars, $appinfo);
|
||||||
$out.='<a href="'.makelink($query_vars, array('fdpage'=>1)).'"><<first</a> ';
|
$got++;
|
||||||
$out.='<a href="'.makelink($query_vars, array('fdpage'=>($query_vars['fdpage']-1))).'"><<prev</a> ';
|
}
|
||||||
}
|
$total++;
|
||||||
$out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
|
}
|
||||||
if($query_vars['fdpage']==$numpages) {
|
|
||||||
$out.="next> ";
|
|
||||||
$out.="last>> ";
|
|
||||||
} else {
|
|
||||||
$out.='<a href="'.makelink($query_vars, array('fdpage'=>($query_vars['fdpage']+1))).'">next></a> ';
|
|
||||||
$out.='<a href="'.makelink($query_vars, array('fdpage'=>$numpages)).'">last>></a> ';
|
|
||||||
}
|
|
||||||
$out.='</p>';
|
|
||||||
} else if($query_vars['fdfilter']!='') {
|
|
||||||
$out.='<p>No matches</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $out;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
$out.=$outputter->outputEnd();
|
||||||
|
|
||||||
function show_search($query_vars) {
|
$numpages = ceil((float)$total/$outputter->perpage);
|
||||||
|
|
||||||
$out='';
|
return $out;
|
||||||
$out.='<form name="searchform" action="" method="get">';
|
}
|
||||||
$out.='<p><input name="fdfilter" type="text" value="'.$query_vars['fdfilter'].'" size="30"> ';
|
|
||||||
$out.='<input type="submit" value="Search"></p>';
|
|
||||||
|
|
||||||
$out.='<input type="hidden" name="page_id" value="'.get_query_var('page_id').'">';
|
|
||||||
foreach($query_vars as $name => $value) {
|
|
||||||
if($value !== null && $name != 'fdfilter')
|
|
||||||
$out.='<input type="hidden" name="'.$name.'" value="'.$value.'">';
|
|
||||||
}
|
|
||||||
|
|
||||||
$out.='</form>'."\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 to output app entries in a detailed list format
|
||||||
class FDOutList
|
class FDOutList
|
||||||
{
|
{
|
||||||
var $perpage=30;
|
var $perpage=30;
|
||||||
|
|
||||||
function FDOutList() {
|
function FDOutList() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputStart() {
|
function outputStart() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputEntry($query_vars, $appinfo) {
|
function outputEntry($query_vars, $appinfo) {
|
||||||
$out="";
|
$out="";
|
||||||
$out.="<hr>\n";
|
$out.="<hr>\n";
|
||||||
$out.='<div id="appheader">';
|
$out.='<div id="appheader">';
|
||||||
|
|
||||||
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;"></div>';
|
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;"></div>';
|
||||||
|
|
||||||
$out.='<div style="float:right;">';
|
$out.='<div style="float:right;">';
|
||||||
$out.='<p><a href="';
|
$out.='<p><a href="';
|
||||||
$out.=makelink($query_vars, array('fdid'=>$appinfo['id']));
|
$out.=makelink($query_vars, array('fdid'=>$appinfo['id']));
|
||||||
$out.='">Details...</a>';
|
$out.='">Details...</a>';
|
||||||
$out.="</p>";
|
$out.="</p>";
|
||||||
$out.="</div>\n";
|
$out.="</div>\n";
|
||||||
|
|
||||||
$out.='<p><span style="font-size:20px">'.$appinfo['name']."</span>";
|
$out.='<p><span style="font-size:20px">'.$appinfo['name']."</span>";
|
||||||
$out.="<br>".$appinfo['summary']."</p>\n";
|
$out.="<br>".$appinfo['summary']."</p>\n";
|
||||||
|
|
||||||
$out.="</div>\n";
|
$out.="</div>\n";
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputEnd() {
|
function outputEnd() {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class to output app entries in a compact grid format
|
// Class to output app entries in a compact grid format
|
||||||
class FDOutGrid
|
class FDOutGrid
|
||||||
{
|
{
|
||||||
var $perpage=80;
|
var $perpage=80;
|
||||||
|
|
||||||
var $itemCount = 0;
|
var $itemCount = 0;
|
||||||
|
|
||||||
function FDOutGrid() {
|
function FDOutGrid() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputStart() {
|
function outputStart() {
|
||||||
return "\n".'<table border="0" width="100%"><tr>'."\n";
|
return "\n".'<table border="0" width="100%"><tr>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputEntry($query_vars, $appinfo) {
|
function outputEntry($query_vars, $appinfo) {
|
||||||
$link=makelink($query_vars, array('fdid'=>$appinfo['id']));
|
$link=makelink($query_vars, array('fdid'=>$appinfo['id']));
|
||||||
|
|
||||||
$out='';
|
$out='';
|
||||||
|
|
||||||
if($this->itemCount%4 == 0 && $this->itemCount > 0)
|
if($this->itemCount%4 == 0 && $this->itemCount > 0)
|
||||||
{
|
{
|
||||||
$out.='</tr><tr>'."\n";
|
$out.='</tr><tr>'."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='<td align="center" valign="top" style="background-color:#F8F8F8;">';
|
$out.='<td align="center" valign="top" style="background-color:#F8F8F8;">';
|
||||||
$out.='<p>';
|
$out.='<p>';
|
||||||
$out.='<div id="appheader" style="text-align:center;width:110px;">';
|
$out.='<div id="appheader" style="text-align:center;width:110px;">';
|
||||||
|
|
||||||
$out.='<a href="'.$link.'" style="border-bottom-style:none;">';
|
$out.='<a href="'.$link.'" style="border-bottom-style:none;">';
|
||||||
$out.='<img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;border-width:0;padding-top:5px;padding-bottom:5px;"><br/>';
|
$out.='<img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;border-width:0;padding-top:5px;padding-bottom:5px;"><br/>';
|
||||||
$out.=$appinfo['name'].'<br/>';
|
$out.=$appinfo['name'].'<br/>';
|
||||||
$out.='</a>';
|
$out.='</a>';
|
||||||
|
|
||||||
$out.="</div>";
|
$out.="</div>";
|
||||||
$out.='</p>';
|
$out.='</p>';
|
||||||
$out.="</td>\n";
|
$out.="</td>\n";
|
||||||
|
|
||||||
$this->itemCount++;
|
$this->itemCount++;
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
function outputEnd() {
|
function outputEnd() {
|
||||||
return '</tr></table>'."\n";
|
return '</tr></table>'."\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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();
|
||||||
$vars=linkify(array_merge($query_vars, $params));
|
$vars=linkify(array_merge($query_vars, $params));
|
||||||
if(strlen($vars)==0)
|
if(strlen($vars)==0)
|
||||||
return $link;
|
return $link;
|
||||||
if(strpos($link,'?')===false)
|
if(strpos($link,'?')===false)
|
||||||
$link.='?';
|
$link.='?';
|
||||||
else
|
else
|
||||||
$link.='&';
|
$link.='&';
|
||||||
return $link.$vars;
|
return $link.$vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the key value pairs in http-get-parameter format as a string
|
// Return the key value pairs in http-get-parameter format as a string
|
||||||
function linkify($vars) {
|
function linkify($vars) {
|
||||||
$retvar = '';
|
$retvar = '';
|
||||||
foreach($vars as $k => $v) {
|
foreach($vars as $k => $v) {
|
||||||
if($k!==null && $v!==null && $v!='')
|
if($k!==null && $v!==null && $v!='')
|
||||||
$retvar .= $k.'='.$v.'&';
|
$retvar .= $k.'='.$v.'&';
|
||||||
}
|
}
|
||||||
return substr($retvar,0,-1);
|
return substr($retvar,0,-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue