<?php
/*
Plugin Name: WP FDroid
-Plugin URI: http://f-droid.org/repository
+Plugin URI: https://f-droid.org/
Description: An FDroid repository browser
Author: Ciaran Gultnieks
-Version: 0.01
+Version: 0.02
Author URI: http://ciarang.com
Revision history
+0.02 - 2014-04-17: It's changed somewhat since then
0.01 - 2010-12-04: Initial development version
*/
include('android-permissions.php');
+
+// Widget for displaying latest apps.
+class FDroidLatestWidget extends WP_Widget {
+
+ function FDroidLatestWidget() {
+ parent::__construct(false, 'F-Droid Latest Apps');
+ }
+
+ function widget( $args, $instance ) {
+ extract($args);
+ $title = apply_filters('widget_title', $instance['title']);
+ echo $before_widget;
+ echo $before_title . $title . $after_title;
+
+ $handle = fopen(getenv('DOCUMENT_ROOT').'/repo/latestapps.dat', 'r');
+ if ($handle) {
+ while (($buffer = fgets($handle, 4096)) !== false) {
+ $app = explode("\t", $buffer);
+ echo '<div style="width:100%">';
+ if(isset($app[2]) && trim($app[2])) {
+ echo '<img src="' . site_url() . '/repo/icons/'.$app[2].'" style="width:32px;border:none;float:right;" />';
+ }
+ echo '<p style="margin:0px;"><a href="/repository/browse/?fdid='.$app[0].'">';
+ echo $app[1].'</a><br/>';
+ if(isset($app[3]) && trim($app[3])) {
+ echo '<span style="color:#BBBBBB;">'.$app[3].'</span></p>';
+ }
+ echo '</div>';
+ }
+ fclose($handle);
+ }
+ echo $after_widget;
+ }
+
+ function update($new_instance, $old_instance) {
+ $instance = array();
+ $instance['title'] = (!empty($new_instance['title'])) ? strip_tags($new_instance['title']) : '';
+ return $instance;
+ }
+
+ function form($instance) {
+ if (isset($instance['title'])) {
+ $title = $instance['title'];
+ }
+ else {
+ $title = __('New title', 'text_domain');
+ }
+ ?>
+ <p>
+ <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
+ <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); ?>">
+ </p>
+ <?php
+ }
+}
+
+
class FDroid
{
// Constructor
function FDroid() {
- // Add filters etc here!
add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
add_filter('query_vars',array($this, 'queryvars'));
$this->inited=false;
$this->site_path=getenv('DOCUMENT_ROOT');
- wp_register_sidebar_widget('fdroid_latest', 'FDroid Latest', 'widget_fdroidlatest');
+ add_action('widgets_init', function() {
+ register_widget('FDroidLatestWidget');
+ });
}
$out.=$this->get_app($query_vars);
} else {
$out.='<form name="searchform" action="" method="get">';
- $out.='<p><input name="fdfilter" type="text" value="'.$query_vars['fdfilter'].'" size="30"> ';
+ $out.='<p><input name="fdfilter" type="text" value="'.esc_attr($query_vars['fdfilter']).'" size="30"> ';
$out.='<input type="hidden" name="fdpage" value="1">';
$out.='<input type="submit" value="Search"></p>';
$out.=$this->makeformdata($query_vars);
function getlicenseurl($license) {
switch($license) {
case 'MIT':
- return 'http://www.gnu.org/licenses/license-list.html#X11License';
+ return 'https://www.gnu.org/licenses/license-list.html#X11License';
case 'NewBSD':
- return 'http://www.gnu.org/licenses/license-list.html#ModifiedBSD';
+ return 'https://www.gnu.org/licenses/license-list.html#ModifiedBSD';
case 'BSD':
- return 'http://www.gnu.org/licenses/license-list.html#OriginalBSD';
+ return 'https://www.gnu.org/licenses/license-list.html#OriginalBSD';
case 'GPLv3':
case 'GPLv3+':
- return 'http://www.gnu.org/licenses/license-list.html#GNUGPL';
+ return 'https://www.gnu.org/licenses/license-list.html#GNUGPLv3';
case 'GPLv2':
case 'GPLv2+':
- return 'http://www.gnu.org/licenses/license-list.html#GPLv2';
+ return 'https://www.gnu.org/licenses/license-list.html#GPLv2';
+ case 'AGPLv3':
+ case 'AGPLv3+':
+ return 'https://www.gnu.org/licenses/license-list.html#AGPLv3.0';
+ case 'LGPL':
+ return 'https://www.gnu.org/licenses/license-list.html#LGPL';
case 'LGPL':
- return 'http://www.gnu.org/licenses/license-list.html#LGPL';
+ case 'LGPLv3':
+ return 'https://www.gnu.org/licenses/license-list.html#LGPLv3';
+ case 'LGPLv2.1':
+ return 'https://www.gnu.org/licenses/license-list.html#LGPLv2.1';
case 'Apache2':
- return 'http://www.gnu.org/licenses/license-list.html#apache2';
+ return 'https://www.gnu.org/licenses/license-list.html#apache2';
+ case 'WTFPL':
+ return 'https://www.gnu.org/licenses/license-list.html#WTFPL';
default:
return null;
}
}
+ function androidversion($sdkLevel) {
+ switch ($sdkLevel) {
+ case 23: return "6.0";
+ case 22: return "5.1";
+ case 21: return "5.0";
+ case 20: return "4.4W";
+ case 19: return "4.4";
+ case 18: return "4.3";
+ case 17: return "4.2";
+ case 16: return "4.1";
+ case 15: return "4.0.3";
+ case 14: return "4.0";
+ case 13: return "3.2";
+ case 12: return "3.1";
+ case 11: return "3.0";
+ case 10: return "2.3.3";
+ case 9: return "2.3";
+ case 8: return "2.2";
+ case 7: return "2.1";
+ case 6: return "2.0.1";
+ case 5: return "2.0";
+ case 4: return "1.6";
+ case 3: return "1.5";
+ case 2: return "1.1";
+ case 1: return "1.0";
+ default: return "?";
+ }
+ }
function get_app($query_vars) {
global $permissions_data;
case "license":
$license=$el;
break;
+ case "author":
+ $author=$el;
+ break;
+ case "email":
+ $email=$el;
+ break;
case "source":
$source=$el;
break;
case "tracker":
$issues=$el;
break;
+ case "changelog":
+ $changelog=$el;
+ break;
case "donate":
$donate=$el;
break;
+ case "flattr":
+ $flattr=$el;
+ break;
case "web":
$web=$el;
break;
$thisapk['vercode']=$pel;
break;
case "added":
- $thisapk['added']=$el;
+ $thisapk['added']=$pel;
break;
case "apkname":
$thisapk['apkname']=$pel;
case "sdkver":
$thisapk['sdkver']=$pel;
break;
+ case "maxsdkver":
+ $thisapk['maxsdkver']=$pel;
+ break;
+ case "nativecode":
+ $thisapk['nativecode']=$pel;
+ break;
case "permissions":
$thisapk['permissions']=$pel;
break;
$out.="<p>";
if(strlen($web)>0)
$out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
+ if(isset($author) && strlen($author)>0)
+ if(isset($email) && strlen($email)>0)
+ $out.='<b>Author(s):</b> <a href="mailto:'.$email.'">'.$author.'</a><br />';
+ else
+ $out.='<b>Author(s):</b> '.$author.'<br />';
if(strlen($issues)>0)
$out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
if(strlen($source)>0)
$out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
- if($donate && strlen($donate)>0)
+ if(strlen($changelog)>0)
+ $out.='<b>Changelog:</b> <a href="'.$changelog.'">'.$changelog.'</a><br />';
+ if(isset($donate) && strlen($donate)>0)
$out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />';
+ if(isset($flattr) && strlen($flattr)>0)
+ $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 />';
$out.="</p>";
$out.="<p>For full details and additional technical information, see ";
$i=0;
foreach($apks as $apk) {
$first = $i+1==count($apks);
- $out.="<p><b>Version ".$apk['version']."</b><br />";
- $out.="Added on ".$apk['added']."<br />";
+ $out.="<p><b>Version ".$apk['version']."</b>";
+ $out.=" - Added on ".$apk['added']."<br />";
+
+ $hasminsdk = isset($apk['sdkver']);
+ $hasmaxsdk = isset($apk['maxsdkver']);
+ if($hasminsdk && $hasmaxsdk) {
+ $out.="<p>This version requires Android ".$this->androidversion($apk['sdkver'])." up to ".$this->androidversion($apk['maxsdkver'])."</p>";
+ } elseif($hasminsdk) {
+ $out.="<p>This version requires Android ".$this->androidversion($apk['sdkver'])." or newer.</p>";
+ } elseif($hasmaxsdk) {
+ $out.="<p>This version requires Android ".$this->androidversion($apk['maxsdkver'])." or old.</p>";
+ }
+
+ $hasabis = isset($apk['nativecode']);
+ if($hasabis) {
+ $abis = str_replace(',', ' ', $apk['nativecode']);
+ $out.="<p>This version uses native code and is built for: ".$abis."</p>";
+ }
// Is this source or binary?
$srcbuild = isset($apk['srcname']) && file_exists($this->site_path.'/repo/'.$apk['srcname']);
$out.=$diffSize>0?'+':'';
$out.=$this->human_readable_size($diffSize, 1).')</span>';
}
+ if(file_exists($this->site_path.'/repo/'.$apk['apkname'].'.asc')) {
+ $out.=' <a href="https://f-droid.org/repo/'.$apk['apkname'].'.asc">GPG Signature</a> ';
+ }
if($srcbuild) {
$out.='<br /><a href="https://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a> ';
$out.=$this->human_readable_size(filesize($this->site_path.'/repo/'.$apk['srcname']));
$antifeatureDescription['NonFreeDep']['description'] = 'This application depends on another non-Free application.';
$antifeatureDescription['UpstreamNonFree']['name'] = 'Upstream Non-Free';
$antifeatureDescription['UpstreamNonFree']['description'] = 'The upstream source code is non-free.';
+ $antifeatureDescription['NonFreeAssets']['name'] = 'Non-Free Assets';
+ $antifeatureDescription['NonFreeAssets']['description'] = 'This application contains non-free assets.';
if(isset($antifeatureDescription[$antifeature])) {
return $antifeatureDescription[$antifeature];
$out.='</form>'."\n";
}
else {
- $out.='Applications matching "'.$query_vars['fdfilter'].'"';
+ $out.='Applications matching "'.esc_attr($query_vars['fdfilter']).'"';
}
$out.="</div>";
$out.='<div style="float:right;">';
- $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list')).'">List</a> | ';
- $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid')).'">Grid</a>';
+ $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'list', 'fdpage'=>1)).'">List</a> | ';
+ $out.='<a href="'.makelink($query_vars, array('fdstyle'=>'grid', 'fdpage'=>1)).'">Grid</a>';
$out.='</div>';
$out.='<br break="all"/>';
$out.='<input type="hidden" name="page_id" value="'.(int)get_query_var('page_id').'">';
foreach($query_vars as $name => $value) {
- if($value !== null && $name != 'fdfilter' && !($name == 'fdpage' && (int)$value ==1))
- $out.='<input type="hidden" name="'.$name.'" value="'.sanitize_text_field($value).'">';
+ if($value !== null && $name != 'fdfilter' && $name != 'fdpage')
+ $out.='<input type="hidden" name="'.esc_attr($name).'" value="'.esc_attr($value).'">';
}
return $out;
}
}
- 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']))) && (!isset($query_vars['fdcategory']) || $query_vars['fdcategory'] && $query_vars['fdcategory']==$appinfo['category'])) {
+ 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'])) {
if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
$skipped++;
} else if($got<$outputter->perpage) {
$retvar = '';
foreach($vars as $k => $v) {
if($k!==null && $v!==null && $v!='')
- $retvar .= $k.'='.$v.'&';
+ $retvar .= $k.'='.urlencode($v).'&';
}
return substr($retvar,0,-1);
}
-function widget_fdroidlatest($args) {
- extract($args);
- echo $before_widget;
- echo $before_title . 'Latest Apps' . $after_title;
-
- $handle = fopen(getenv('DOCUMENT_ROOT').'/repo/latestapps.dat', 'r');
- if ($handle) {
- while (($buffer = fgets($handle, 4096)) !== false) {
- $app = explode("\t", $buffer);
- echo '<a href="/repository/browse/?fdid='.$app[0].'">';
- if(isset($app[2]) && trim($app[2])) {
- echo '<img src="' . site_url() . '/repo/icons/'.$app[2].'" style="width:32px;border:none;float:right;" />';
- }
- echo $app[1].'<br />';
- if(isset($app[3]) && trim($app[3])) {
- echo '<span style="color:#BBBBBB;">'.$app[3].'</span>';
- }
- echo '</a><br style="clear:both;" />';
- }
- fclose($handle);
- }
-
- echo $after_widget;
-}
-
$wp_fdroid = new FDroid();