4 Plugin URI: https://f-droid.org/
5 Description: An FDroid repository browser
6 Author: Ciaran Gultnieks
8 Author URI: http://ciarang.com
11 0.02 - 2014-04-17: It's changed somewhat since then
12 0.01 - 2010-12-04: Initial development version
16 include('android-permissions.php');
19 // Widget for displaying latest apps.
20 class FDroidLatestWidget extends WP_Widget {
22 function FDroidLatestWidget() {
23 parent::__construct(false, 'F-Droid Latest Apps');
26 function widget( $args, $instance ) {
28 $title = apply_filters('widget_title', $instance['title']);
30 echo $before_title . $title . $after_title;
32 $handle = fopen(getenv('DOCUMENT_ROOT').'/repo/latestapps.dat', 'r');
34 while (($buffer = fgets($handle, 4096)) !== false) {
35 $app = explode("\t", $buffer);
36 echo '<div style="width:100%">';
37 if(isset($app[2]) && trim($app[2])) {
38 echo '<img src="' . site_url() . '/repo/icons/'.$app[2].'" style="width:32px;border:none;float:right;" />';
40 echo '<p style="margin:0px;"><a href="/repository/browse/?fdid='.$app[0].'">';
41 echo $app[1].'</a><br/>';
42 if(isset($app[3]) && trim($app[3])) {
43 echo '<span style="color:#BBBBBB;">'.$app[3].'</span></p>';
52 function update($new_instance, $old_instance) {
54 $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
58 function form($instance) {
59 if (isset($instance['title'])) {
60 $title = $instance['title'];
63 $title = __('New title', 'text_domain');
67 <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
68 <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>">
78 // Our text domain, for internationalisation
79 private $textdom='wp-fdroid';
85 add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
86 add_filter('query_vars',array($this, 'queryvars'));
88 $this->site_path=getenv('DOCUMENT_ROOT');
89 add_action('widgets_init', function() {
90 register_widget('FDroidLatestWidget');
95 // Register additional query variables. (Handler for the 'query_vars' filter)
96 function queryvars($qvars) {
98 $qvars[]='fdcategory';
106 // Lazy initialise. All non-trivial members should call this before doing anything else.
107 function lazyinit() {
109 load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
115 // Gets a required query parameter by name.
116 function getrequiredparam($name) {
118 if(!isset($wp_query->query_vars[$name]))
119 wp_die("Missing parameter ".$name,"Error");
120 return $wp_query->query_vars[$name];
123 // Handler for the 'fdroidrepo' shortcode.
124 // $attribs - shortcode attributes
125 // $content - optional content enclosed between the starting and
127 // Returns the generated content.
128 function do_shortcode($attribs,$content=null) {
129 global $wp_query,$wp_rewrite;
132 // Init local query vars
133 foreach($this->queryvars(array()) as $qv) {
134 if(array_key_exists($qv,$wp_query->query_vars)) {
135 $query_vars[$qv] = $wp_query->query_vars[$qv];
137 $query_vars[$qv] = null;
141 // Sanity check and standardise all query variables...
142 if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) {
143 $query_vars['fdpage'] = 1;
145 $query_vars['fdpage'] = strval(intval($query_vars['fdpage']));
147 if(isset($query_vars['fdstyle']) && ($query_vars['fdstyle'] != 'list' && $query_vars['fdstyle'] != 'grid')) {
148 $query_vars['fdstyle'] = 'list';
150 if(isset($query_vars['fdcategory'])) {
151 if($query_vars['fdcategory'] == 'All categories') {
152 unset($query_vars['fdcategory']);
154 $query_vars['fdcategory'] = sanitize_text_field($query_vars['fdcategory']);
157 if(isset($query_vars['fdfilter'])) {
158 $query_vars['fdfilter'] = sanitize_text_field($query_vars['fdfilter']);
160 if(isset($attribs['search'])) {
161 $query_vars['fdfilter'] = '';
164 if(isset($query_vars['fdid'])) {
165 $query_vars['fdid'] = sanitize_text_field($query_vars['fdid']);
170 if($query_vars['fdid']!==null) {
171 $out.=$this->get_app($query_vars);
173 $out.='<form name="searchform" action="" method="get">';
174 $out.='<p><input name="fdfilter" type="text" value="'.$query_vars['fdfilter'].'" size="30"> ';
175 $out.='<input type="hidden" name="fdpage" value="1">';
176 $out.='<input type="submit" value="Search"></p>';
177 $out.=$this->makeformdata($query_vars);
178 $out.='</form>'."\n";
180 $out.=$this->get_apps($query_vars);
187 // Get a URL for a full description of a license, as given by one of our
188 // pre-defined license abbreviations. This is a temporary function, as this
189 // needs to be data-driven so the same information can be used by the client,
190 // the web site and the documentation.
191 function getlicenseurl($license) {
194 return 'https://www.gnu.org/licenses/license-list.html#X11License';
196 return 'https://www.gnu.org/licenses/license-list.html#ModifiedBSD';
198 return 'https://www.gnu.org/licenses/license-list.html#OriginalBSD';
201 return 'https://www.gnu.org/licenses/license-list.html#GNUGPLv3';
204 return 'https://www.gnu.org/licenses/license-list.html#GPLv2';
207 return 'https://www.gnu.org/licenses/license-list.html#AGPLv3.0';
209 return 'https://www.gnu.org/licenses/license-list.html#LGPL';
212 return 'https://www.gnu.org/licenses/license-list.html#LGPLv3';
214 return 'https://www.gnu.org/licenses/license-list.html#LGPLv2.1';
216 return 'https://www.gnu.org/licenses/license-list.html#apache2';
218 return 'https://www.gnu.org/licenses/license-list.html#WTFPL';
223 function androidversion($sdkLevel) {
224 if ($sdkLevel < 1) return null;
226 case 19: return "4.4";
227 case 18: return "4.3";
228 case 17: return "4.2";
229 case 16: return "4.1";
230 case 15: return "4.0.3";
231 case 14: return "4.0";
232 case 13: return "3.2";
233 case 12: return "3.1";
234 case 11: return "3.0";
235 case 10: return "2.3.3";
236 case 9: return "2.3";
237 case 8: return "2.2";
238 case 7: return "2.1";
239 case 6: return "2.0.1";
240 case 5: return "2.0";
241 case 4: return "1.6";
242 case 3: return "1.5";
243 case 2: return "1.1";
244 case 1: return "1.0";
249 function get_app($query_vars) {
250 global $permissions_data;
251 $permissions_object = new AndroidPermissions($this->site_path.'/wp-content/plugins/wp-fdroid/AndroidManifest.xml',
252 $this->site_path.'/wp-content/plugins/wp-fdroid/strings.xml',
253 sys_get_temp_dir().'/android-permissions.cache');
254 $permissions_data = $permissions_object->get_permissions_array();
257 $xml = simplexml_load_file($this->site_path.'/repo/index.xml');
258 foreach($xml->children() as $app) {
260 $attrs=$app->attributes();
261 if($attrs['id']==$query_vars['fdid']) {
263 foreach($app->children() as $el) {
264 switch($el->getName()) {
303 foreach($el->children() as $pel) {
304 switch($pel->getName()) {
306 $thisapk['version']=$pel;
309 $thisapk['vercode']=$pel;
312 $thisapk['added']=$pel;
315 $thisapk['apkname']=$pel;
318 $thisapk['srcname']=$pel;
321 $thisapk['hash']=$pel;
324 $thisapk['size']=$pel;
327 $thisapk['sdkver']=$pel;
330 $thisapk['maxsdkver']=$pel;
333 $thisapk['nativecode']=$pel;
336 $thisapk['permissions']=$pel;
345 // Generate app diff data
346 foreach(array_reverse($apks, true) as $key=>$apk) {
347 if(isset($previous)) {
349 $apks[$key]['diff']['size'] = $apk['size']-$previous['size'];
353 $permissions = explode(',',$apk['permissions']);
354 $permissionsPrevious = isset($previous['permissions'])?explode(',',$previous['permissions']):array();
355 $apks[$key]['diff']['permissions']['added'] = array_diff($permissions, $permissionsPrevious);
356 $apks[$key]['diff']['permissions']['removed'] = array_diff($permissionsPrevious, $permissions);
361 // Output app information
362 $out='<div id="appheader">';
363 $out.='<div style="float:left;padding-right:10px;"><img src="' . site_url() . '/repo/icons/'.$icon.'" width=48></div>';
364 $out.='<p><span style="font-size:20px">'.$name."</span>";
365 $out.="<br>".$summary."</p>";
368 $out.=str_replace('href="fdroid.app:', 'href="/repository/browse/?fdid=', $desc);
370 if(isset($antifeatures)) {
371 $antifeaturesArray = explode(',',$antifeatures);
372 foreach($antifeaturesArray as $antifeature) {
373 $antifeatureDescription = $this->get_antifeature_description($antifeature);
374 $out.='<p style="border:3px solid #CC0000;background-color:#FFDDDD;padding:5px;"><strong>'.$antifeatureDescription['name'].'</strong><br />';
375 $out.=$antifeatureDescription['description'].' <a href="/wiki/page/Antifeature:'.$antifeature.'">more...</a></p>';
380 $licenseurl=$this->getlicenseurl($license);
381 $out.="<b>License:</b> ";
383 $out.='<a href="'.$licenseurl.'" target="_blank">';
388 if(isset($requirements)) {
389 $out.='<br /><b>Additional requirements:</b> '.$requirements;
395 $out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
396 if(strlen($issues)>0)
397 $out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
398 if(strlen($source)>0)
399 $out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
400 if(isset($donate) && strlen($donate)>0)
401 $out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />';
402 if(isset($flattr) && strlen($flattr)>0)
403 $out.='<b>Flattr:</b> <a href="https://flattr.com/thing/'.$flattr.'"><img src="/wp-content/uploads/flattr-badge-large.png" style="border:0" /></a><br />';
406 $out.="<p>For full details and additional technical information, see ";
407 $out.="<a href=\"/wiki/page/".$query_vars['fdid']."\">this application's page</a> on the F-Droid wiki.</p>";
409 $out.='<script type="text/javascript">';
410 $out.='function showHidePermissions(id) {';
411 $out.=' if(document.getElementById(id).style.display==\'none\')';
412 $out.=' document.getElementById(id).style.display=\'block\';';
414 $out.=' document.getElementById(id).style.display=\'none\';';
415 $out.=' return false;';
419 $out.="<h3>Packages</h3>";
421 $out.='<div style="float:right; margin-left:10px;"><a id="downloadbutton" href="https://f-droid.org/FDroid.apk"><span>Download F-Droid</span></a></div>';
422 $out.="<p>Although APK downloads are available below to give ";
423 $out.="you the choice, you should be aware that by installing that way you ";
424 $out.="will not receive update notifications, and it's a less secure way ";
425 $out.="to download. ";
426 $out.="We recommend that you install the F-Droid client and use that.</p>";
429 foreach($apks as $apk) {
430 $first = $i+1==count($apks);
431 $out.="<p><b>Version ".$apk['version']."</b>";
432 $out.=" - Added on ".$apk['added']."<br />";
434 $hasminsdk = isset($apk['sdkver']);
435 $hasmaxsdk = isset($apk['maxsdkver']);
436 if($hasminsdk && $hasmaxsdk) {
437 $out.="<p>This version requires Android ".$this->androidversion($apk['sdkver'])." up to ".$this->androidversion($apk['maxsdkver'])."</p>";
438 } elseif($hasminsdk) {
439 $out.="<p>This version requires Android ".$this->androidversion($apk['sdkver'])." or newer.</p>";
440 } elseif($hasmaxsdk) {
441 $out.="<p>This version requires Android ".$this->androidversion($apk['maxsdkver'])." or old.</p>";
444 $hasabis = isset($apk['nativecode']);
446 $abis = str_replace(',', ' ', $apk['nativecode']);
447 $out.="<p>This version uses native code and will only run on: ".$abis."</p>";
450 // Is this source or binary?
451 $srcbuild = isset($apk['srcname']) && file_exists($this->site_path.'/repo/'.$apk['srcname']);
453 $out.="<p>This version is built and signed by ";
455 $out.="F-Droid, and guaranteed to correspond to the source tarball below.</p>";
457 $out.="the original developer.</p>";
459 $out.='<a href="https://f-droid.org/repo/'.$apk['apkname'].'">download apk</a> ';
460 $out.=$this->human_readable_size($apk['size']);
461 $diffSize = $apk['diff']['size'];
462 if(abs($diffSize) > 500) {
463 $out.=' <span style="color:#AAAAAA;">(';
464 $out.=$diffSize>0?'+':'';
465 $out.=$this->human_readable_size($diffSize, 1).')</span>';
467 if(file_exists($this->site_path.'/repo/'.$apk['apkname'].'.asc')) {
468 $out.=' <a href="https://f-droid.org/repo/'.$apk['apkname'].'.asc">GPG Signature</a> ';
471 $out.='<br /><a href="https://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a> ';
472 $out.=$this->human_readable_size(filesize($this->site_path.'/repo/'.$apk['srcname']));
475 if(isset($apk['permissions'])) {
476 // Permissions diff link
477 if($first == false) {
478 $permissionsAddedCount = count($apk['diff']['permissions']['added']);
479 $permissionsRemovedCount = count($apk['diff']['permissions']['removed']);
480 $divIdDiff='permissionsDiff'.$i;
481 if($permissionsAddedCount || $permissionsRemovedCount) {
482 $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divIdDiff.'\');">permissions diff</a>';
483 $out.=' <span style="color:#AAAAAA;">(';
484 if($permissionsAddedCount)
485 $out.='+'.$permissionsAddedCount;
486 if($permissionsAddedCount && $permissionsRemovedCount)
488 if($permissionsRemovedCount)
489 $out.='-'.$permissionsRemovedCount;
494 $out.='<br /><span style="color:#999999;">no permission changes</span>';
498 // Permissions list link
499 $permissionsListString = $this->get_permission_list_string(explode(',',$apk['permissions']), $permissions_data, $summary);
501 $divStyleDisplay='block';
503 $divStyleDisplay='none';
504 $divId='permissions'.$i;
505 $out.='<br /><a href="javascript:void(0);" onClick="showHidePermissions(\''.$divId.'\');">view permissions</a>';
506 $out.=' <span style="color:#AAAAAA;">['.$summary.']</span>';
510 $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divId.'">';
511 $out.=$permissionsListString;
516 $out.='<div style="display:'.$divStyleDisplay.';" id="'.$divIdDiff.'">';
517 $permissionsRemoved = $apk['diff']['permissions']['removed'];
518 usort($permissionsRemoved, "permissions_cmp");
521 if($permissionsAddedCount) {
522 $out.='<h5>ADDED</h5><br />';
523 $out.=$this->get_permission_list_string($apk['diff']['permissions']['added'], $permissions_data, $summary);
526 // Removed permissions
527 if($permissionsRemovedCount) {
528 $out.='<h5>REMOVED</h5><br />';
529 $out.=$this->get_permission_list_string($apk['diff']['permissions']['removed'], $permissions_data, $summary);
536 $out.='<br /><span style="color:#999999;">no extra permissions needed</span><br />';
543 $out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>';
548 return "<p>Application not found</p>";
551 private function get_permission_list_string($permissions, $permissions_data, &$summary) {
553 usort($permissions, "permissions_cmp");
554 $permission_group_last = '';
555 foreach($permissions as $permission) {
556 $permission_group = $permissions_data['permission'][$permission]['permissionGroup'];
557 if($permission_group != $permission_group_last) {
558 $permission_group_label = $permissions_data['permission-group'][$permission_group]['label'];
559 if($permission_group_label=='') $permission_group_label = 'Extra/Custom';
560 $out.='<strong>'.strtoupper($permission_group_label).'</strong><br/>';
561 $permission_group_last = $permission_group;
564 $out.=$this->get_permission_protection_level_icon($permissions_data['permission'][$permission]['protectionLevel']).' ';
565 $out.='<strong>'.$permissions_data['permission'][$permission]['label'].'</strong> [<code>'.$permission.'</code>]<br/>';
566 if($permissions_data['permission'][$permission]['description']) $out.=$permissions_data['permission'][$permission]['description'].'<br/>';
567 //$out.=$permissions_data['permission'][$permission]['comment'].'<br/>';
570 if(!isset($summaryCount[$permissions_data['permission'][$permission]['protectionLevel']]))
571 $summaryCount[$permissions_data['permission'][$permission]['protectionLevel']] = 0;
572 $summaryCount[$permissions_data['permission'][$permission]['protectionLevel']]++;
576 if(isset($summaryCount)) {
577 foreach($summaryCount as $protectionLevel => $count) {
578 $summary .= $this->get_permission_protection_level_icon($protectionLevel, 'regular').' '.$count;
582 $summary = substr($summary,0,-2);
587 private function get_permission_protection_level_icon($protection_level, $size='adjusted') {
589 if($protection_level=='dangerous') {
590 $iconString .= '<span style="color:#DD9900;';
591 if($size=='adjusted')
592 $iconString .= 'font-size:150%;';
593 $iconString .= '">⚠</span>'; // WARNING SIGN
595 elseif($protection_level=='normal') {
596 $iconString .= '<span style="color:#6666FF;';
597 if($size=='adjusted')
598 $iconString .= 'font-size:110%;';
599 $iconString .= '">ⓘ</span>'; // CIRCLED LATIN SMALL LETTER I
601 elseif($protection_level=='signature') {
602 $iconString .= '<span style="color:#33AAAA;';
603 if($size=='adjusted')
604 $iconString .= 'font-size:140%;';
605 $iconString .= '">✽</span>'; // HEAVY TEARDROP-SPOKED ASTERISK
607 elseif($protection_level=='signatureOrSystem') {
608 $iconString .= '<span style="color:#DD66DD;';
609 if($size=='adjusted')
610 $iconString .= 'font-size:140%;';
611 $iconString .= '">⚛</span>'; // ATOM SYMBOL
614 $iconString .= '<span style="color:#33AA33';
615 if($size=='adjusted')
616 $iconString .= ';font-size:130%;';
617 $iconString .= '">⚙</span>'; // GEAR
623 private function human_readable_size($size, $minDiv=0) {
624 $si_prefix = array('bytes','kB','MB');
627 for($i=0;(abs($size) > $div && $i < count($si_prefix)) || $i<$minDiv;$i++) {
631 return round($size,max(0,$i-1)).' '.$si_prefix[$i];
634 private function get_antifeature_description($antifeature) {
635 // Anti feature names and descriptions
636 $antifeatureDescription['Ads']['name'] = 'Advertising';
637 $antifeatureDescription['Ads']['description'] = 'This application contains advertising.';
638 $antifeatureDescription['Tracking']['name'] = 'Tracks You';
639 $antifeatureDescription['Tracking']['description'] = 'This application tracks and reports your activity to somewhere.';
640 $antifeatureDescription['NonFreeNet']['name'] = 'Non-Free Network Services';
641 $antifeatureDescription['NonFreeNet']['description'] = 'This application promotes a non-Free network service.';
642 $antifeatureDescription['NonFreeAdd']['name'] = 'Non-Free Addons';
643 $antifeatureDescription['NonFreeAdd']['description'] = 'This application promotes non-Free add-ons.';
644 $antifeatureDescription['NonFreeDep']['name'] = 'Non-Free Dependencies';
645 $antifeatureDescription['NonFreeDep']['description'] = 'This application depends on another non-Free application.';
646 $antifeatureDescription['UpstreamNonFree']['name'] = 'Upstream Non-Free';
647 $antifeatureDescription['UpstreamNonFree']['description'] = 'The upstream source code is non-free.';
649 if(isset($antifeatureDescription[$antifeature])) {
650 return $antifeatureDescription[$antifeature];
652 return array('name'=>$antifeature);
656 function get_apps($query_vars) {
658 $xml = simplexml_load_file($this->site_path."/repo/index.xml");
659 $matches = $this->show_apps($xml,$query_vars,$numpages);
663 if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0)
665 $out.='<div style="float:left;">';
666 if($query_vars['fdfilter']===null) {
668 $categories = array('All categories');
669 $handle = fopen(getenv('DOCUMENT_ROOT').'/repo/categories.txt', 'r');
671 while (($buffer = fgets($handle, 4096)) !== false) {
672 $categories[] = rtrim($buffer);
677 $out.='<form name="categoryform" action="" method="get">';
678 $out.=$this->makeformdata($query_vars);
680 $out.='<select name="fdcategory" style="color:#333333;" onChange="document.categoryform.submit();">';
681 foreach($categories as $category) {
683 if(isset($query_vars['fdcategory']) && $category==$query_vars['fdcategory'])
685 $out.='>'.$category.'</option>';
689 $out.='</form>'."\n";
692 $out.='Applications matching "'.$query_vars['fdfilter'].'"';
696 $out.='<div style="float:right;">';
697 $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list', 'fdpage'=>1)).'">List</a> | ';
698 $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid', 'fdpage'=>1)).'">Grid</a>';
701 $out.='<br break="all"/>';
709 $out.='<div style="width:20%; float:left; text-align:left;">';
710 $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' ';
713 $out.='<div style="width:60%; float:left; text-align:center;">';
715 for($i=1;$i<=$numpages;$i++) {
716 if($i == $query_vars['fdpage']) {
717 $out.='<b>'.$i.'</b>';
719 $out.='<a href="'.makelink($query_vars, array('fdpage'=>$i)).'">';
729 $out.='<div style="width:20%; float:left; text-align:right;">';
730 if($query_vars['fdpage']!=$numpages) {
731 $out.='<a href="'.makelink($query_vars, array('fdpage'=>($query_vars['fdpage']+1))).'">next></a> ';
736 } else if($query_vars['fdfilter']!='') {
737 $out.='<p>No matches</p>';
744 function makeformdata($query_vars) {
748 $out.='<input type="hidden" name="page_id" value="'.(int)get_query_var('page_id').'">';
749 foreach($query_vars as $name => $value) {
750 if($value !== null && $name != 'fdfilter' && $name != 'fdpage')
751 $out.='<input type="hidden" name="'.$name.'" value="'.sanitize_text_field($value).'">';
758 function show_apps($xml,$query_vars,&$numpages) {
764 if($query_vars['fdstyle']=='grid') {
765 $outputter = new FDOutGrid();
767 $outputter = new FDOutList();
772 $out.=$outputter->outputStart();
774 foreach($xml->children() as $app) {
776 if($app->getName() == 'repo') continue;
777 $appinfo['attrs']=$app->attributes();
778 $appinfo['id']=$appinfo['attrs']['id'];
779 foreach($app->children() as $el) {
780 switch($el->getName()) {
782 $appinfo['name']=$el;
785 $appinfo['icon']=$el;
788 $appinfo['summary']=$el;
791 $appinfo['description']=$el;
794 $appinfo['license']=$el;
797 $appinfo['category']=$el;
802 if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='' && (stristr($appinfo['name'],$query_vars['fdfilter']) || stristr($appinfo['id'],$query_vars['fdfilter']) || stristr($appinfo['summary'],$query_vars['fdfilter']) || stristr($appinfo['description'],$query_vars['fdfilter']))) && (!isset($query_vars['fdcategory']) || $query_vars['fdcategory'] && $query_vars['fdcategory']==$appinfo['category'])) {
803 if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
805 } else if($got<$outputter->perpage) {
806 $out.=$outputter->outputEntry($query_vars, $appinfo);
814 $out.=$outputter->outputEnd();
816 $numpages = ceil((float)$total/$outputter->perpage);
822 // Class to output app entries in a detailed list format
827 function FDOutList() {
830 function outputStart() {
834 function outputEntry($query_vars, $appinfo) {
836 $out.='<hr style="clear:both;" />'."\n";
837 $out.='<a href="'.makelink($query_vars, array('fdid'=>$appinfo['id'])).'">';
838 $out.='<div id="appheader">';
840 $out.='<div style="float:left;padding-right:10px;"><img src="' . site_url() . '/repo/icons/'.$appinfo['icon'].'" style="width:48px;border:none;"></div>';
842 $out.='<div style="float:right;">';
843 $out.='<p>Details...</p>';
846 $out.='<p style="color:#000000;"><span style="font-size:20px;">'.$appinfo['name']."</span>";
847 $out.="<br>".$appinfo['summary']."</p>\n";
855 function outputEnd() {
860 // Class to output app entries in a compact grid format
867 function FDOutGrid() {
870 function outputStart() {
871 return "\n".'<table border="0" width="100%"><tr>'."\n";
874 function outputEntry($query_vars, $appinfo) {
875 $link=makelink($query_vars, array('fdid'=>$appinfo['id']));
879 if($this->itemCount%4 == 0 && $this->itemCount > 0)
881 $out.='</tr><tr>'."\n";
884 $out.='<td align="center" valign="top" style="background-color:#F8F8F8;">';
886 $out.='<div id="appheader" style="text-align:center;width:110px;">';
888 $out.='<a href="'.$link.'" style="border-bottom-style:none;">';
889 $out.='<img src="' . site_url() . '/repo/icons/'.$appinfo['icon'].'" style="width:48px;border-width:0;padding-top:5px;padding-bottom:5px;"><br/>';
890 $out.=$appinfo['name'].'<br/>';
901 function outputEnd() {
902 return '</tr></table>'."\n";
906 function permissions_cmp($a, $b) {
907 global $permissions_data;
909 $aProtectionLevel = $permissions_data['permission'][$a]['protectionLevel'];
910 $bProtectionLevel = $permissions_data['permission'][$b]['protectionLevel'];
912 if($aProtectionLevel != $bProtectionLevel) {
913 if(strlen($aProtectionLevel)==0) return 1;
914 if(strlen($bProtectionLevel)==0) return -1;
916 return strcmp($aProtectionLevel, $bProtectionLevel);
919 $aGroup = $permissions_data['permission'][$a]['permissionGroup'];
920 $bGroup = $permissions_data['permission'][$b]['permissionGroup'];
922 if($aGroup != $bGroup) {
923 return strcmp($aGroup, $bGroup);
926 return strcmp($a, $b);
929 // Make a link to this page, with the current query vars attached and desired params added/modified
930 function makelink($query_vars, $params=array()) {
931 $link=get_permalink();
933 $p = array_merge($query_vars, $params);
935 // Page 1 is the default, don't clutter urls with it...
936 if($p['fdpage'] == 1)
938 // Likewise for list style...
939 if($p['fdstyle'] == 'list')
940 unset($p['fdstyle']);
945 if(strpos($link,'?')===false)
952 // Return the key value pairs in http-get-parameter format as a string
953 function linkify($vars) {
955 foreach($vars as $k => $v) {
956 if($k!==null && $v!==null && $v!='')
957 $retvar .= $k.'='.$v.'&';
959 return substr($retvar,0,-1);
962 $wp_fdroid = new FDroid();