chiark / gitweb /
Merge branch 'dev'
[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 "requirements";
151                                                         $requirements=$el;
152                                                         break;
153                                                 case "package":
154                                                         $thisapk=array();
155                                                         foreach($el->children() as $pel) {
156                                                                 switch($pel->getName()) {
157                                                                 case "version":
158                                                                         $thisapk['version']=$pel;
159                                                                         break;
160                                                                 case "vercode":
161                                                                         $thisapk['vercode']=$pel;
162                                                                         break;
163                                                                 case "apkname":
164                                                                         $thisapk['apkname']=$pel;
165                                                                         break;
166                                                                 case "srcname":
167                                                                         $thisapk['srcname']=$pel;
168                                                                         break;
169                                                                 case "hash":
170                                                                         $thisapk['hash']=$pel;
171                                                                         break;
172                                                                 case "size":
173                                                                         $thisapk['size']=$pel;
174                                                                         break;
175                                                                 case "sdkver":
176                                                                         $thisapk['sdkver']=$pel;
177                                                                         break;
178                                                                 case "permissions":
179                                                                         $thisapk['permissions']=$pel;
180                                                                         break;
181                                                                 }
182                                                         }
183                                                         $apks[]=$thisapk;
184
185                                         }
186                                 }
187
188                                 // Generate app diff data
189                                 foreach(array_reverse($apks, true) as $key=>$apk) {
190                                         if(isset($previous)) {
191                                                 // Apk size
192                                                 $apks[$key]['diff']['size'] = $apk['size']-$previous['size'];
193                                         }
194
195                                         // Permissions
196                                         $permissions = explode(',',$apk['permissions']);
197                                         $permissionsPrevious = isset($previous['permissions'])?explode(',',$previous['permissions']):array();
198                                         $apks[$key]['diff']['permissions']['added'] = array_diff($permissions, $permissionsPrevious);
199                                         $apks[$key]['diff']['permissions']['removed'] = array_diff($permissionsPrevious, $permissions);
200
201                                         $previous = $apk;
202                                 }
203
204                                 // Output app information
205                                 $out='<div id="appheader">';
206                                 $out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" width=48></div>';
207                                 $out.='<p><span style="font-size:20px">'.$name."</span>";
208                                 $out.="<br>".$summary."</p>";
209                                 $out.="</div>";
210
211                                 $out.="<p>".$desc."</p>";
212
213                                 if(isset($antifeatures)) {
214                                         $antifeaturesArray = explode(',',$antifeatures);
215                                         foreach($antifeaturesArray as $antifeature) {
216                                                 $antifeatureDesctiption = $this->get_antifeature_description($antifeature);
217                                                 $out.='<p style="border:3px solid #CC0000;background-color:#FFDDDD;padding:5px;"><strong>'.$antifeatureDesctiption['name'].'</strong><br />';
218                                                 $out.=$antifeatureDesctiption['description'].'</p>';
219                                         }
220                                 }
221
222                                 $out.="<p>";
223                                 $out.="<b>License:</b> ".$license;
224                                 if(isset($requirements)) {
225                                         $out.='<br /><b>Additional requirements:</b> '.$requirements;
226                                 }
227                                 $out.="</p>";
228
229                                 $out.="<p>";
230                                 if(strlen($web)>0)
231                                         $out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
232                                 if(strlen($issues)>0)
233                                         $out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
234                                 if(strlen($source)>0)
235                                         $out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
236                                 if($donate && strlen($donate)>0)
237                                         $out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />';
238                                 $out.="</p>";
239
240                                 $out.='<script type="text/javascript">';
241                                 $out.='function showHidePermissions(id) {';
242                                 $out.='  if(document.getElementById(id).style.display==\'none\')';
243                                 $out.=' document.getElementById(id).style.display=\'block\';';
244                                 $out.='  else';
245                                 $out.=' document.getElementById(id).style.display=\'none\';';
246                                 $out.='  return false;';
247                                 $out.='}';
248                                 $out.='</script>';
249
250                                 $out.="<h3>Packages</h3>";
251                                 $i=0;
252                                 foreach($apks as $apk) {
253                                         $first = $i+1==count($apks);
254                                         $out.="<p><b>Version ".$apk['version']."</b><br />";
255                                         $out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download apk</a> ';
256                                         $out.=$this->human_readable_size($apk['size']);
257                                         $diffSize = $apk['diff']['size'];
258                                         if(abs($diffSize) > 500) {
259                                                 $out.=' <span style="color:#AAAAAA;">(';
260                                                 $out.=$diffSize>0?'+':'';
261                                                 $out.=$this->human_readable_size($diffSize, 1).')</span>';
262                                         }
263                                         if(isset($apk['srcname']) && file_exists($this->site_path.'/repo/'.$apk['srcname'])) {
264                                                 $out.='<br /><a href="http://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a> ';
265                                                 $out.=$this->human_readable_size(filesize($this->site_path.'/repo/'.$apk['srcname']));
266                                         }
267
268                                         if(isset($apk['permissions'])) {
269                                                 // Permissions diff link
270                                                 if($first == false) {
271                                                         $permissionsAddedCount = count($apk['diff']['permissions']['added']);
272                                                         $permissionsRemovedCount = count($apk['diff']['permissions']['removed']);
273                                                         $divIdDiff='permissionsDiff'.$i;
274                                                         if($permissionsAddedCount || $permissionsRemovedCount) {
275                                                                 $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divIdDiff.'\');">permissions diff</a>';
276                                                                 $out.=' <span style="color:#AAAAAA;">(';
277                                                                 if($permissionsAddedCount)
278                                                                         $out.='+'.$permissionsAddedCount;
279                                                                 if($permissionsAddedCount && $permissionsRemovedCount)
280                                                                         $out.='/';
281                                                                 if($permissionsRemovedCount)
282                                                                         $out.='-'.$permissionsRemovedCount;
283                                                                 $out.=')</span>';
284                                                         }
285                                                         else
286                                                         {
287                                                                 $out.='<br /><span style="color:#999999;">no permission changes</span>';
288                                                         }
289                                                 }
290
291                                                 // Permissions list link
292                                                 $permissionsListString = $this->get_permission_list_string(explode(',',$apk['permissions']), $permissions_data, $summary);
293                                                 /*if($i==0)
294                                                         $divStyleDisplay='block';
295                                                 else*/
296                                                         $divStyleDisplay='none';
297                                                 $divId='permissions'.$i;
298                                                 $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divId.'\');">view permissions</a>';
299                                                 $out.=' <span style="color:#AAAAAA;">['.$summary.']</span>';
300                                                 $out.='<br/>';
301
302                                                 // Permissions list
303                                                 $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divId.'">';
304                                                 $out.=$permissionsListString;
305                                                 $out.='</div>';
306
307                                                 // Permissions diff
308                                                 {
309                                                         $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divIdDiff.'">';
310                                                         $permissionsRemoved = $apk['diff']['permissions']['removed'];
311                                                         usort($permissionsRemoved, "permissions_cmp");
312
313                                                         // Added permissions
314                                                         if($permissionsAddedCount) {
315                                                                 $out.='<h5>ADDED</h5><br />';
316                                                                 $out.=$this->get_permission_list_string($apk['diff']['permissions']['added'], $permissions_data, $summary);
317                                                         }
318
319                                                         // Removed permissions
320                                                         if($permissionsRemovedCount) {
321                                                                 $out.='<h5>REMOVED</h5><br />';
322                                                                 $out.=$this->get_permission_list_string($apk['diff']['permissions']['removed'], $permissions_data, $summary);
323                                                         }
324
325                                                         $out.='</div>';
326                                                 }
327                                         }
328                                         else {
329                                                 $out.='<br /><span style="color:#999999;">no extra permissions needed</span><br />';
330                                         }
331
332                                         $out.='</p>';
333                                         $i++;
334                                 }
335
336                                 $out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>';
337
338                                 return $out;
339                         }
340                 }
341                 return "<p>Application not found</p>";
342         }
343
344         private function get_permission_list_string($permissions, $permissions_data, &$summary) {
345                 $out='';
346                 usort($permissions, "permissions_cmp");
347                 $permission_group_last = '';
348                 foreach($permissions as $permission) {
349                         $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
350                         if($permission_group != $permission_group_last) {
351                                 $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
352                                 if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
353                                 $out.='<strong>'.strtoupper($permission_group_label).'</strong><br/>';
354                                 $permission_group_last = $permission_group;
355                         }
356
357                         $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
358                         $out.='<strong>'.$permissions_data['permission'][$permission]['label'].'</strong> [<code>'.$permission.'</code>]<br/>';
359                         if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'<br/>';
360                         //$out.=$permissions_data['permission'][$permission]['comment'].'<br/>';
361                         $out.='<br/>';
362
363                         if(!isset($summaryCount[$permissions_data['permission'][$permission]['protectionLevel']]))
364                                 $summaryCount[$permissions_data['permission'][$permission]['protectionLevel']] = 0;
365                         $summaryCount[$permissions_data['permission'][$permission]['protectionLevel']]++;
366                 }
367
368                 $summary = '';
369                 foreach($summaryCount as $protectionLevel => $count) {
370                         $summary .= $this->get_permission_protection_level_icon($protectionLevel, 'regular').' '.$count;
371                         $summary .= ', ';
372                 }
373                 $summary = substr($summary,0,-2);
374
375                 return $out;
376         }
377
378         private function get_permission_protection_level_icon($protection_level, $size='adjusted') {
379                 $iconString = '';
380                 if($protection_level=='dangerous') {
381                         $iconString .= '<span style="color:#DD9900;';
382                         if($size=='adjusted')
383                                 $iconString .= 'font-size:150%;';
384                         $iconString .= '">&#x26a0;</span>';
385                 }
386                 elseif($protection_level=='normal') {
387                         $iconString .= '<span style="color:#6666FF;';
388                         if($size=='adjusted')
389                                 $iconString .= 'font-size:110%;';
390                         $iconString .= '">&#x24D8;</span>';
391                 }
392                 else {
393                         $iconString .= '<span style="color:#33AA33';
394                         if($size=='adjusted')
395                                 $iconString .= ';font-size:130%;';
396                         $iconString .= '">&#x2699;</span>';
397                 }
398
399                 return $iconString;
400         }
401
402         private function human_readable_size($size, $minDiv=0) {
403                 $si_prefix = array('bytes','kB','MB');
404                 $div = 1000;
405
406                 for($i=0;(abs($size) > $div && $i < count($si_prefix)) || $i<$minDiv;$i++) {
407                         $size /= $div;
408                 }
409
410                 return round($size,max(0,$i-1)).' '.$si_prefix[$i];
411         }
412
413         private function get_antifeature_description($antifeature) {
414                 // Anti feature names and descriptions
415                 $antifeatureDesctiption['ads']['name'] = 'Advertising';
416                 $antifeatureDesctiption['ads']['description'] = 'This application contains advertising';
417                 $antifeatureDesctiption['tracking']['name'] = 'Tracks You';
418                 $antifeatureDesctiption['tracking']['description'] = 'This application tracks and reports your activity to somewhere';
419                 $antifeatureDesctiption['nonfreenet']['name'] = 'Non-Free Network Services';
420                 $antifeatureDesctiption['nonfreenet']['description'] = 'This application promotes a non-Free network service';
421                 $antifeatureDesctiption['nonfreeadd']['name'] = 'Non-Free Addons';
422                 $antifeatureDesctiption['nonfreeadd']['description'] = 'This application promotes non-Free add-ons';
423                 $antifeatureDesctiption['nonfreedep']['name'] = 'Non-Free Dependencies';
424                 $antifeatureDesctiption['nonfreedep']['description'] = 'This application depends on another non-Free application';
425
426                 $antifeatureLower = strtolower($antifeature);
427                 if(isset($antifeatureDesctiption[$antifeatureLower])) {
428                         return $antifeatureDesctiption[$antifeatureLower];
429                 }
430                 return array('name'=>$antifeature);
431         }
432
433
434         function get_apps($query_vars) {
435
436                 $xml = simplexml_load_file($this->site_path."/repo/index.xml");
437                 $matches = $this->show_apps($xml,$query_vars,$numpages);
438
439                 $out='';
440
441                 if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0)
442                 {
443                         $out.='<div style="float:left;">';
444                         if($query_vars['fdfilter']===null)
445                                 $out.="All applications";
446                         else
447                                 $out.='Applications matching "'.$query_vars['fdfilter'].'"';
448                         $out.="</div>";
449
450                         $out.='<div style="float:right;">';
451                                 $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list','fdpage'=>'1')).'">List</a> | ';
452                                 $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid','fdpage'=>'1')).'">Grid</a>';
453                         $out.='</div>';
454
455                         $out.='<br break="all"/>';
456                 }
457
458                 if($numpages>0) {
459                         $out.=$matches;
460
461                         $out.='<hr><p>';
462
463                         $out.='<div style="width:20%; float:left; text-align:left;">';
464                         $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
465                         $out.='</div>';
466
467                         $out.='<div style="width:60%; float:left; text-align:center;">';
468                         if($numpages>1) {
469                                 for($i=1;$i<=$numpages;$i++) {
470                                         if($i == $query_vars['fdpage']) {
471                                                 $out.='<b>'.$i.'</b>';
472                                         } else {
473                                                 $out.='<a href="'.makelink($query_vars, array('fdpage'=>$i)).'">';
474                                                 $out.=$i;
475                                                 $out.='</a>';
476                                         }
477                                         $out.=' ';
478                                 }
479                                 $out.=' ';
480                         }
481                         $out.='</div>';
482
483                         $out.='<div style="width:20%; float:left; text-align:right;">';
484                         if($query_vars['fdpage']!=$numpages) {
485                                 $out.='<a href="'.makelink($query_vars, array('fdpage'=>($query_vars['fdpage']+1))).'">next&gt;</a> ';
486                         }
487                         $out.='</div>';
488
489                         $out.='</p>';
490                 } else if($query_vars['fdfilter']!='') {
491                         $out.='<p>No matches</p>';
492                 }
493
494                 return $out;
495         }
496
497
498         function show_search($query_vars) {
499
500                 $out='';
501                 $out.='<form name="searchform" action="" method="get">';
502                 $out.='<p><input name="fdfilter" type="text" value="'.$query_vars['fdfilter'].'" size="30"> ';
503                 $out.='<input type="submit" value="Search"></p>';
504
505                 $out.='<input type="hidden" name="page_id" value="'.get_query_var('page_id').'">';
506                 foreach($query_vars as $name => $value) {
507                         if($value !== null && $name != 'fdfilter')
508                                 $out.='<input type="hidden" name="'.$name.'" value="'.$value.'">';
509                 }
510
511                 $out.='</form>'."\n";
512
513                 return $out;
514         }
515
516
517         function show_apps($xml,$query_vars,&$numpages) {
518
519                 $skipped=0;
520                 $got=0;
521                 $total=0;
522
523                 if($query_vars['fdstyle']=='grid') {
524                         $outputter = new FDOutGrid();
525                 } else {
526                         $outputter = new FDOutList();
527                 }
528
529                 $out = "";
530
531                 $out.=$outputter->outputStart();
532
533                 foreach($xml->children() as $app) {
534
535                         if($app->getName() == 'repo') continue;
536                         $appinfo['attrs']=$app->attributes();
537                         $appinfo['id']=$appinfo['attrs']['id'];
538                         foreach($app->children() as $el) {
539                                 switch($el->getName()) {
540                                         case "name":
541                                                 $appinfo['name']=$el;
542                                                 break;
543                                         case "icon":
544                                                 $appinfo['icon']=$el;
545                                                 break;
546                                         case "summary":
547                                                 $appinfo['summary']=$el;
548                                                 break;
549                                         case "description":
550                                                 $appinfo['description']=$el;
551                                                 break;
552                                         case "license":
553                                                 $appinfo['license']=$el;
554                                                 break;
555                                 }
556                         }
557
558                         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']))) {
559                                 if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
560                                         $skipped++;
561                                 } else if($got<$outputter->perpage) {
562                                         $out.=$outputter->outputEntry($query_vars, $appinfo);
563                                         $got++;
564                                 }
565                                 $total++;
566                         }
567
568                 }
569
570                 $out.=$outputter->outputEnd();
571
572                 $numpages = ceil((float)$total/$outputter->perpage);
573
574                 return $out;
575         }
576 }
577
578 // Class to output app entries in a detailed list format
579 class FDOutList
580 {
581         var $perpage=30;
582
583         function FDOutList() {
584         }
585
586         function outputStart() {
587                 return '';
588         }
589
590         function outputEntry($query_vars, $appinfo) {
591                 $out="";
592                 $out.="<hr>\n";
593                 $out.='<div id="appheader">';
594
595                 $out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;"></div>';
596
597                 $out.='<div style="float:right;">';
598                 $out.='<p><a href="';
599                 $out.=makelink($query_vars, array('fdid'=>$appinfo['id']));
600                 $out.='">Details...</a>';
601                 $out.="</p>";
602                 $out.="</div>\n";
603
604                 $out.='<p><span style="font-size:20px">'.$appinfo['name']."</span>";
605                 $out.="<br>".$appinfo['summary']."</p>\n";
606
607                 $out.="</div>\n";
608
609                 return $out;
610         }
611
612         function outputEnd() {
613                 return '';
614         }
615 }
616
617 // Class to output app entries in a compact grid format
618 class FDOutGrid
619 {
620         var $perpage=80;
621
622         var $itemCount = 0;
623
624         function FDOutGrid() {
625         }
626
627         function outputStart() {
628                 return "\n".'<table border="0" width="100%"><tr>'."\n";
629         }
630
631         function outputEntry($query_vars, $appinfo) {
632                 $link=makelink($query_vars, array('fdid'=>$appinfo['id']));
633
634                 $out='';
635
636                 if($this->itemCount%4 == 0 && $this->itemCount > 0)
637                 {
638                         $out.='</tr><tr>'."\n";
639                 }
640
641                 $out.='<td align="center" valign="top" style="background-color:#F8F8F8;">';
642                 $out.='<p>';
643                 $out.='<div id="appheader" style="text-align:center;width:110px;">';
644
645                 $out.='<a href="'.$link.'" style="border-bottom-style:none;">';
646                 $out.='<img src="http://f-droid.org/repo/icons/'.$appinfo['icon'].'" style="width:48px;border-width:0;padding-top:5px;padding-bottom:5px;"><br/>';
647                 $out.=$appinfo['name'].'<br/>';
648                 $out.='</a>';
649
650                 $out.="</div>";
651                 $out.='</p>';
652                 $out.="</td>\n";
653
654                 $this->itemCount++;
655                 return $out;
656         }
657
658         function outputEnd() {
659                 return '</tr></table>'."\n";
660         }
661 }
662
663 function permissions_cmp($a, $b) {
664         global $permissions_data;
665
666         $aProtectionLevel = $permissions_data['permission'][$a]['protectionLevel'];
667         $bProtectionLevel = $permissions_data['permission'][$b]['protectionLevel'];
668
669         if($aProtectionLevel != $bProtectionLevel) {
670                 if(strlen($aProtectionLevel)==0) return 1;
671                 if(strlen($bProtectionLevel)==0) return -1;
672
673                 return strcmp($aProtectionLevel, $bProtectionLevel);
674         }
675
676         $aGroup = $permissions_data['permission'][$a]['permissionGroup'];
677         $bGroup = $permissions_data['permission'][$b]['permissionGroup'];
678
679         if($aGroup != $bGroup) {
680                 return strcmp($aGroup, $bGroup);
681         }
682
683         return strcmp($a, $b);
684 }
685
686 // Make a link to this page, with the current query vars attached and desired params added/modified
687 function makelink($query_vars, $params=array()) {
688         $link=get_permalink();
689         $vars=linkify(array_merge($query_vars, $params));
690         if(strlen($vars)==0)
691                 return $link;
692         if(strpos($link,'?')===false)
693                 $link.='?';
694         else
695                 $link.='&';
696         return $link.$vars;
697 }
698
699 // Return the key value pairs in http-get-parameter format as a string
700 function linkify($vars) {
701         $retvar = '';
702         foreach($vars as $k => $v) {
703                 if($k!==null && $v!==null && $v!='')
704                         $retvar .= $k.'='.$v.'&';
705         }
706         return substr($retvar,0,-1);
707 }
708
709
710 $wp_fdroid = new FDroid();
711
712
713 ?>