chiark / gitweb /
Added missing break...
[fdroidserver.git] / wp-fdroid / wp-fdroid.php
1 <?php
2 /*
3 Plugin Name: WP FDroid
4 Plugin URI: http://f-droid.org/repository
5 Description: An FDroid repository browser
6 Author: Ciaran Gultnieks
7 Version: 0.01
8 Author URI: http://ciarang.com
9
10 Revision history
11 0.01 - 2010-12-04: Initial development version
12
13 */
14
15 include('android-permissions.php');
16
17 class FDroid
18 {
19
20         // Our text domain, for internationalisation
21         private $textdom='wp-fdroid';
22
23         private $site_path;
24
25         // Constructor
26         function FDroid() {
27                 // Add filters etc here!
28                 add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
29                 add_filter('query_vars',array($this, 'queryvars'));
30                 $this->inited=false;
31                 $this->site_path=getenv('DOCUMENT_ROOT');
32         }
33
34
35         // Register additional query variables. (Handler for the 'query_vars' filter)
36         function queryvars($qvars) {
37                 $qvars[]='fdfilter';
38                 $qvars[]='fdid';
39                 $qvars[]='fdpage';
40                 $qvars[]='fdstyle';
41                 return $qvars;
42         }
43
44
45         // Lazy initialise. All non-trivial members should call this before doing anything else.
46         function lazyinit() {
47                 if(!$this->inited) {
48                         load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
49
50                         $this->inited=true;
51                 }
52         }
53
54         // Gets a required query parameter by name.
55         function getrequiredparam($name) {
56                 global $wp_query;
57                 if(!isset($wp_query->query_vars[$name]))
58                         wp_die("Missing parameter ".$name,"Error");
59                 return $wp_query->query_vars[$name];
60         }
61
62         // Handler for the 'fdroidrepo' shortcode.
63         //  $attribs - shortcode attributes
64         //  $content - optional content enclosed between the starting and
65         //                       ending shortcode
66         // Returns the generated content.
67         function do_shortcode($attribs,$content=null) {
68                 global $wp_query,$wp_rewrite;
69                 $this->lazyinit();
70
71                 // Init local query vars
72                 foreach($this->queryvars(array()) as $qv) {
73                         if(array_key_exists($qv,$wp_query->query_vars)) {
74                                 $query_vars[$qv] = $wp_query->query_vars[$qv];
75                         } else {
76                                 $query_vars[$qv] = null;
77                         }
78                 }
79
80                 // Santiy check query vars
81                 if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) {
82                         $query_vars['fdpage'] = 1;
83                 }
84
85                 $out = '';
86
87                 if(isset($attribs['search']) && $query_vars['fdfilter']===null) {
88                         $query_vars['fdfilter'] = '';
89                 }
90
91                 if($query_vars['fdid']!==null) {
92                         $out.=$this->get_app($query_vars);
93                 } else {
94                         if($query_vars['fdfilter'] !== null)
95                                 $out.=$this->show_search($query_vars);
96
97                         $out.=$this->get_apps($query_vars);
98                 }
99
100                 return $out;
101         }
102
103
104         function get_app($query_vars) {
105                 global $permissions_data;
106                 $permissions_object = new AndroidPermissions($this->site_path.'/wp-content/plugins/wp-fdroid/AndroidManifest.xml',
107                         $this->site_path.'/wp-content/plugins/wp-fdroid/strings.xml',
108                         sys_get_temp_dir().'/android-permissions.cache');
109                 $permissions_data = $permissions_object->get_permissions_array();
110
111                 // Get app data
112                 $xml = simplexml_load_file($this->site_path.'/repo/index.xml');
113                 foreach($xml->children() as $app) {
114
115                         $attrs=$app->attributes();
116                         if($attrs['id']==$query_vars['fdid']) {
117                                 $apks=array();;
118                                 foreach($app->children() as $el) {
119                                         switch($el->getName()) {
120                                                 case "name":
121                                                         $name=$el;
122                                                         break;
123                                                 case "icon":
124                                                         $icon=$el;
125                                                         break;
126                                                 case "summary":
127                                                         $summary=$el;
128                                                         break;
129                                                 case "description":
130                                                         $desc=$el;
131                                                         break;
132                                                 case "license":
133                                                         $license=$el;
134                                                         break;
135                                                 case "source":
136                                                         $source=$el;
137                                                         break;
138                                                 case "tracker":
139                                                         $issues=$el;
140                                                         break;
141                                                 case "donate":
142                                                         $donate=$el;
143                                                         break;
144                                                 case "web":
145                                                         $web=$el;
146                                                         break;
147                                                 case "antifeatures";
148                                                         $antifeatures=$el;
149                                                         break;
150                                                 case "package":
151                                                         $thisapk=array();
152                                                         foreach($el->children() as $pel) {
153                                                                 switch($pel->getName()) {
154                                                                 case "version":
155                                                                         $thisapk['version']=$pel;
156                                                                         break;
157                                                                 case "vercode":
158                                                                         $thisapk['vercode']=$pel;
159                                                                         break;
160                                                                 case "apkname":
161                                                                         $thisapk['apkname']=$pel;
162                                                                         break;
163                                                                 case "srcname":
164                                                                         $thisapk['srcname']=$pel;
165                                                                         break;
166                                                                 case "hash":
167                                                                         $thisapk['hash']=$pel;
168                                                                         break;
169                                                                 case "size":
170                                                                         $thisapk['size']=$pel;
171                                                                         break;
172                                                                 case "sdkver":
173                                                                         $thisapk['sdkver']=$pel;
174                                                                         break;
175                                                                 case "permissions":
176                                                                         $thisapk['permissions']=$pel;
177                                                                         break;
178                                                                 }
179                                                         }
180                                                         $apks[]=$thisapk;
181
182                                         }
183                                 }
184
185                                 // Generate app diff data
186                                 foreach(array_reverse($apks, true) as $key=>$apk) {
187                                         if(isset($previous)) {
188                                                 // Apk size
189                                                 $apks[$key]['diff']['size'] = $apk['size']-$previous['size'];
190                                         }
191
192                                         // Permissions
193                                         $permissions = explode(',',$apk['permissions']);
194                                         $permissionsPrevious = isset($previous['permissions'])?explode(',',$previous['permissions']):array();
195                                         $apks[$key]['diff']['permissions']['added'] = array_diff($permissions, $permissionsPrevious);
196                                         $apks[$key]['diff']['permissions']['removed'] = array_diff($permissionsPrevious, $permissions);
197
198                                         $previous = $apk;
199                                 }
200
201                                 // Output app information
202                                 $out='<div id="appheader">';
203                                 $out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" width=48></div>';
204                                 $out.='<p><span style="font-size:20px">'.$name."</span>";
205                                 $out.="<br>".$summary."</p>";
206                                 $out.="</div>";
207
208                                 $out.="<p>".$desc."</p>";
209
210                                 if(isset($antifeatures)) {
211                                         $antifeaturesArray = explode(',',$antifeatures);
212                                         foreach($antifeaturesArray as $antifeature) {
213                                                 $antifeatureDesctiption = $this->get_antifeature_description($antifeature);
214                                                 $out.='<p style="border:3px solid #CC0000;background-color:#FFDDDD;padding:5px;"><strong>'.$antifeatureDesctiption['name'].'</strong><br />';
215                                                 $out.=$antifeatureDesctiption['description'].'</p>';
216                                         }
217                                 }
218
219                                 $out.="<p><b>License:</b> ".$license."</p>";
220
221                                 $out.="<p>";
222                                 if(strlen($web)>0)
223                                         $out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
224                                 if(strlen($issues)>0)
225                                         $out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
226                                 if(strlen($source)>0)
227                                         $out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
228                                 if($donate && strlen($donate)>0)
229                                         $out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />';
230                                 $out.="</p>";
231
232                                 $out.='<script type="text/javascript">';
233                                 $out.='function showHidePermissions(id) {';
234                                 $out.='  if(document.getElementById(id).style.display==\'none\')';
235                                 $out.=' document.getElementById(id).style.display=\'block\';';
236                                 $out.='  else';
237                                 $out.=' document.getElementById(id).style.display=\'none\';';
238                                 $out.='  return false;';
239                                 $out.='}';
240                                 $out.='</script>';
241
242                                 $out.="<h3>Packages</h3>";
243                                 $i=0;
244                                 foreach($apks as $apk) {
245                                         $first = $i+1==count($apks);
246                                         $out.="<p><b>Version ".$apk['version']."</b><br />";
247                                         $out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download apk</a> ';
248                                         $out.=$this->human_readable_size($apk['size']);
249                                         $diffSize = $apk['diff']['size'];
250                                         if(abs($diffSize) > 500) {
251                                                 $out.=' <span style="color:#AAAAAA;">(';
252                                                 $out.=$diffSize>0?'+':'';
253                                                 $out.=$this->human_readable_size($diffSize, 1).')</span>';
254                                         }
255                                         if(isset($apk['srcname']) && file_exists($this->site_path.'/repo/'.$apk['srcname'])) {
256                                                 $out.='<br /><a href="http://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a> ';
257                                                 $out.=$this->human_readable_size(filesize($this->site_path.'/repo/'.$apk['srcname']));
258                                         }
259
260                                         if(isset($apk['permissions'])) {
261                                                 // Permissions diff link
262                                                 if($first == false) {
263                                                         $permissionsAddedCount = count($apk['diff']['permissions']['added']);
264                                                         $permissionsRemovedCount = count($apk['diff']['permissions']['removed']);
265                                                         $divIdDiff='permissionsDiff'.$i;
266                                                         if($permissionsAddedCount || $permissionsRemovedCount) {
267                                                                 $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divIdDiff.'\');">permissions diff</a>';
268                                                                 $out.=' <span style="color:#AAAAAA;">(';
269                                                                 if($permissionsAddedCount)
270                                                                         $out.='+'.$permissionsAddedCount;
271                                                                 if($permissionsAddedCount && $permissionsRemovedCount)
272                                                                         $out.='/';
273                                                                 if($permissionsRemovedCount)
274                                                                         $out.='-'.$permissionsRemovedCount;
275                                                                 $out.=')</span>';
276                                                         }
277                                                         else
278                                                         {
279                                                                 $out.='<br /><span style="color:#999999;">no permission changes</span>';
280                                                         }
281                                                 }
282
283                                                 // Permissions list link
284                                                 $permissionsListString = $this->get_permission_list_string(explode(',',$apk['permissions']), $permissions_data, $summary);
285                                                 /*if($i==0)
286                                                         $divStyleDisplay='block';
287                                                 else*/
288                                                         $divStyleDisplay='none';
289                                                 $divId='permissions'.$i;
290                                                 $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divId.'\');">view permissions</a>';
291                                                 $out.=' <span style="color:#AAAAAA;">['.$summary.']</span>';
292                                                 $out.='<br/>';
293
294                                                 // Permissions list
295                                                 $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divId.'">';
296                                                 $out.=$permissionsListString;
297                                                 $out.='</div>';
298
299                                                 // Permissions diff
300                                                 {
301                                                         $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divIdDiff.'">';
302                                                         $permissionsRemoved = $apk['diff']['permissions']['removed'];
303                                                         usort($permissionsRemoved, "permissions_cmp");
304
305                                                         // Added permissions
306                                                         if($permissionsAddedCount) {
307                                                                 $out.='<h5>ADDED</h5><br />';
308                                                                 $out.=$this->get_permission_list_string($apk['diff']['permissions']['added'], $permissions_data, $summary);
309                                                         }
310
311                                                         // Removed permissions
312                                                         if($permissionsRemovedCount) {
313                                                                 $out.='<h5>REMOVED</h5><br />';
314                                                                 $out.=$this->get_permission_list_string($apk['diff']['permissions']['removed'], $permissions_data, $summary);
315                                                         }
316
317                                                         $out.='</div>';
318                                                 }
319                                         }
320                                         else {
321                                                 $out.='<br /><span style="color:#999999;">no extra permissions needed</span><br />';
322                                         }
323
324                                         $out.='</p>';
325                                         $i++;
326                                 }
327
328                                 $out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>';
329
330                                 return $out;
331                         }
332                 }
333                 return "<p>Application not found</p>";
334         }
335
336         private function get_permission_list_string($permissions, $permissions_data, &$summary) {
337                 $out='';
338                 usort($permissions, "permissions_cmp");
339                 $permission_group_last = '';
340                 foreach($permissions as $permission) {
341                         $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
342                         if($permission_group != $permission_group_last) {
343                                 $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
344                                 if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
345                                 $out.='<strong>'.strtoupper($permission_group_label).'</strong><br/>';
346                                 $permission_group_last = $permission_group;
347                         }
348
349                         $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
350                         $out.='<strong>'.$permissions_data['permission'][$permission]['label'].'</strong> [<code>'.$permission.'</code>]<br/>';
351                         if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'<br/>';
352                         //$out.=$permissions_data['permission'][$permission]['comment'].'<br/>';
353                         $out.='<br/>';
354
355                         if(!isset($summaryCount[$permissions_data['permission'][$permission]['protectionLevel']]))
356                                 $summaryCount[$permissions_data['permission'][$permission]['protectionLevel']] = 0;
357                         $summaryCount[$permissions_data['permission'][$permission]['protectionLevel']]++;
358                 }
359
360                 $summary = '';
361                 foreach($summaryCount as $protectionLevel => $count) {
362                         $summary .= $this->get_permission_protection_level_icon($protectionLevel, 'regular').' '.$count;
363                         $summary .= ', ';
364                 }
365                 $summary = substr($summary,0,-2);
366
367                 return $out;
368         }
369
370         private function get_permission_protection_level_icon($protection_level, $size='adjusted') {
371                 $iconString = '';
372                 if($protection_level=='dangerous') {
373                         $iconString .= '<span style="color:#DD9900;';
374                         if($size=='adjusted')
375                                 $iconString .= 'font-size:150%;';
376                         $iconString .= '">&#x26a0;</span>';
377                 }
378                 elseif($protection_level=='normal') {
379                         $iconString .= '<span style="color:#6666FF;';
380                         if($size=='adjusted')
381                                 $iconString .= 'font-size:110%;';
382                         $iconString .= '">&#x24D8;</span>';
383                 }
384                 else {
385                         $iconString .= '<span style="color:#33AA33';
386                         if($size=='adjusted')
387                                 $iconString .= ';font-size:130%;';
388                         $iconString .= '">&#x2699;</span>';
389                 }
390
391                 return $iconString;
392         }
393
394         private function human_readable_size($size, $minDiv=0) {
395                 $si_prefix = array('bytes','kB','MB');
396                 $div = 1000;
397
398                 for($i=0;(abs($size) > $div && $i < count($si_prefix)) || $i<$minDiv;$i++) {
399                         $size /= $div;
400                 }
401
402                 return round($size,max(0,$i-1)).' '.$si_prefix[$i];
403         }
404
405         private function get_antifeature_description($antifeature) {
406                 // Anti feature names and descriptions
407                 $antifeatureDesctiption['ads']['name'] = 'Advertising';
408                 $antifeatureDesctiption['ads']['description'] = 'This application contains advertising';
409                 $antifeatureDesctiption['tracking']['name'] = 'Tracks You';
410                 $antifeatureDesctiption['tracking']['description'] = 'This application tracks and reports your activity to somewhere';
411                 $antifeatureDesctiption['nonfreenet']['name'] = 'Non-Free Network Services';
412                 $antifeatureDesctiption['nonfreenet']['description'] = 'This application promotes a non-Free network service';
413                 $antifeatureDesctiption['nonfreeadd']['name'] = 'Non-Free Addons';
414                 $antifeatureDesctiption['nonfreeadd']['description'] = 'This application promotes non-Free add-ons';
415                 $antifeatureDesctiption['nonfreedep']['name'] = 'Non-Free Dependencies';
416                 $antifeatureDesctiption['nonfreedep']['description'] = 'This application depends on another non-Free application';
417
418                 $antifeatureLower = strtolower($antifeature);
419                 if(isset($antifeatureDesctiption[$antifeatureLower])) {
420                         return $antifeatureDesctiption[$antifeatureLower];
421                 }
422                 return array('name'=>$antifeature);
423         }
424
425
426         function get_apps($query_vars) {
427
428                 $xml = simplexml_load_file($this->site_path."/repo/index.xml");
429                 $matches = $this->show_apps($xml,$query_vars,$numpages);
430
431                 $out='';
432
433                 if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0)
434                 {
435                         $out.='<div style="float:left;">';
436                         if($query_vars['fdfilter']===null)
437                                 $out.="All applications";
438                         else
439                                 $out.='Applications matching "'.$query_vars['fdfilter'].'"';
440                         $out.="</div>";
441
442                         $out.='<div style="float:right;">';
443                                 $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list','fdpage'=>'1')).'">List</a> | ';
444                                 $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid','fdpage'=>'1')).'">Grid</a>';
445                         $out.='</div>';
446
447                         $out.='<br break="all"/>';
448                 }
449
450                 if($numpages>0) {
451                         $out.=$matches;
452
453                         $out.='<hr><p>';
454
455                         $out.='<div style="width:20%; float:left; text-align:left;">';
456                         $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
457                         $out.='</div>';
458
459                         $out.='<div style="width:60%; float:left; text-align:center;">';
460                         if($numpages>1) {
461                                 for($i=1;$i<=$numpages;$i++) {
462                                         if($i == $query_vars['fdpage']) {
463                                                 $out.='<b>'.$i.'</b>';
464                                         } else {
465                                                 $out.='<a href="'.makelink($query_vars, array('fdpage'=>$i)).'">';
466                                                 $out.=$i;
467                                                 $out.='</a>';
468                                         }
469                                         $out.=' ';
470                                 }
471                                 $out.=' ';
472                         }
473                         $out.='</div>';
474
475                         $out.='<div style="width:20%; float:left; text-align:right;">';
476                         if($query_vars['fdpage']!=$numpages) {
477                                 $out.='<a href="'.makelink($query_vars, array('fdpage'=>($query_vars['fdpage']+1))).'">next&gt;</a> ';
478                         }
479                         $out.='</div>';
480
481                         $out.='</p>';
482                 } else if($query_vars['fdfilter']!='') {
483                         $out.='<p>No matches</p>';
484                 }
485
486                 return $out;
487         }
488
489
490         function show_search($query_vars) {
491
492                 $out='';
493                 $out.='<form name="searchform" action="" method="get">';
494                 $out.='<p><input name="fdfilter" type="text" value="'.$query_vars['fdfilter'].'" size="30"> ';
495                 $out.='<input type="submit" value="Search"></p>';
496
497                 $out.='<input type="hidden" name="page_id" value="'.get_query_var('page_id').'">';
498                 foreach($query_vars as $name => $value) {
499                         if($value !== null && $name != 'fdfilter')
500                                 $out.='<input type="hidden" name="'.$name.'" value="'.$value.'">';
501                 }
502
503                 $out.='</form>'."\n";
504
505                 return $out;
506         }
507
508
509         function show_apps($xml,$query_vars,&$numpages) {
510
511                 $skipped=0;
512                 $got=0;
513                 $total=0;
514
515                 if($query_vars['fdstyle']=='grid') {
516                         $outputter = new FDOutGrid();
517                 } else {
518                         $outputter = new FDOutList();
519                 }
520
521                 $out = "";
522
523                 $out.=$outputter->outputStart();
524
525                 foreach($xml->children() as $app) {
526
527                         if($app->getName() == 'repo') continue;
528                         $appinfo['attrs']=$app->attributes();
529                         $appinfo['id']=$appinfo['attrs']['id'];
530                         foreach($app->children() as $el) {
531                                 switch($el->getName()) {
532                                         case "name":
533                                                 $appinfo['name']=$el;
534                                                 break;
535                                         case "icon":
536                                                 $appinfo['icon']=$el;
537                                                 break;
538                                         case "summary":
539                                                 $appinfo['summary']=$el;
540                                                 break;
541                                         case "description":
542                                                 $appinfo['description']=$el;
543                                                 break;
544                                         case "license":
545                                                 $appinfo['license']=$el;
546                                                 break;
547                                 }
548                         }
549
550                         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']))) {
551                                 if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
552                                         $skipped++;
553                                 } else if($got<$outputter->perpage) {
554                                         $out.=$outputter->outputEntry($query_vars, $appinfo);
555                                         $got++;
556                                 }
557                                 $total++;
558                         }
559
560                 }
561
562                 $out.=$outputter->outputEnd();
563
564                 $numpages = ceil((float)$total/$outputter->perpage);
565
566                 return $out;
567         }
568 }
569
570 // Class to output app entries in a detailed list format
571 class FDOutList
572 {
573         var $perpage=30;
574
575         function FDOutList() {
576         }
577
578         function outputStart() {
579                 return '';
580         }
581
582         function outputEntry($query_vars, $appinfo) {
583                 $out="";
584                 $out.="<hr>\n";
585                 $out.='<div id="appheader">';
586
587                 $out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;"></div>';
588
589                 $out.='<div style="float:right;">';
590                 $out.='<p><a href="';
591                 $out.=makelink($query_vars, array('fdid'=>$appinfo['id']));
592                 $out.='">Details...</a>';
593                 $out.="</p>";
594                 $out.="</div>\n";
595
596                 $out.='<p><span style="font-size:20px">'.$appinfo['name']."</span>";
597                 $out.="<br>".$appinfo['summary']."</p>\n";
598
599                 $out.="</div>\n";
600
601                 return $out;
602         }
603
604         function outputEnd() {
605                 return '';
606         }
607 }
608
609 // Class to output app entries in a compact grid format
610 class FDOutGrid
611 {
612         var $perpage=80;
613
614         var $itemCount = 0;
615
616         function FDOutGrid() {
617         }
618
619         function outputStart() {
620                 return "\n".'<table border="0" width="100%"><tr>'."\n";
621         }
622
623         function outputEntry($query_vars, $appinfo) {
624                 $link=makelink($query_vars, array('fdid'=>$appinfo['id']));
625
626                 $out='';
627
628                 if($this->itemCount%4 == 0 && $this->itemCount > 0)
629                 {
630                         $out.='</tr><tr>'."\n";
631                 }
632
633                 $out.='<td align="center" valign="top" style="background-color:#F8F8F8;">';
634                 $out.='<p>';
635                 $out.='<div id="appheader" style="text-align:center;width:110px;">';
636
637                 $out.='<a href="'.$link.'" style="border-bottom-style:none;">';
638                 $out.='<img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;border-width:0;padding-top:5px;padding-bottom:5px;"><br/>';
639                 $out.=$appinfo['name'].'<br/>';
640                 $out.='</a>';
641
642                 $out.="</div>";
643                 $out.='</p>';
644                 $out.="</td>\n";
645
646                 $this->itemCount++;
647                 return $out;
648         }
649
650         function outputEnd() {
651                 return '</tr></table>'."\n";
652         }
653 }
654
655 function permissions_cmp($a, $b) {
656         global $permissions_data;
657
658         $aProtectionLevel = $permissions_data['permission'][$a]['protectionLevel'];
659         $bProtectionLevel = $permissions_data['permission'][$b]['protectionLevel'];
660
661         if($aProtectionLevel != $bProtectionLevel) {
662                 if(strlen($aProtectionLevel)==0) return 1;
663                 if(strlen($bProtectionLevel)==0) return -1;
664
665                 return strcmp($aProtectionLevel, $bProtectionLevel);
666         }
667
668         $aGroup = $permissions_data['permission'][$a]['permissionGroup'];
669         $bGroup = $permissions_data['permission'][$b]['permissionGroup'];
670
671         if($aGroup != $bGroup) {
672                 return strcmp($aGroup, $bGroup);
673         }
674
675         return strcmp($a, $b);
676 }
677
678 // Make a link to this page, with the current query vars attached and desired params added/modified
679 function makelink($query_vars, $params=array()) {
680         $link=get_permalink();
681         $vars=linkify(array_merge($query_vars, $params));
682         if(strlen($vars)==0)
683                 return $link;
684         if(strpos($link,'?')===false)
685                 $link.='?';
686         else
687                 $link.='&';
688         return $link.$vars;
689 }
690
691 // Return the key value pairs in http-get-parameter format as a string
692 function linkify($vars) {
693         $retvar = '';
694         foreach($vars as $k => $v) {
695                 if($k!==null && $v!==null && $v!='')
696                         $retvar .= $k.'='.$v.'&';
697         }
698         return substr($retvar,0,-1);
699 }
700
701
702 $wp_fdroid = new FDroid();
703
704
705 ?>