chiark / gitweb /
Add Author Name and Author Email fields. (Closes: #90)
[fdroidserver.git] / wp-fdroid / wp-fdroid.php
index fe19edd822c75f9079b5045572b8647fec70705a..12cc02e6601d8009756617433a43f2df79014e30 100644 (file)
@@ -1,19 +1,77 @@
 <?php
 /*
 Plugin Name: WP FDroid
-Plugin URI: https://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
 {
 
@@ -24,12 +82,13 @@ 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');
+               });
        }
 
 
@@ -112,7 +171,7 @@ class FDroid
                        $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);
@@ -162,8 +221,11 @@ class FDroid
                }
        }
        function androidversion($sdkLevel) {
-               if ($sdkLevel < 1) return null;
                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";
@@ -218,12 +280,21 @@ class FDroid
                                        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;
@@ -334,13 +405,20 @@ class FDroid
                                $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($flattr && strlen($flattr)>0)
+                               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>";
 
@@ -385,7 +463,7 @@ class FDroid
                                        $hasabis = isset($apk['nativecode']);
                                        if($hasabis) {
                                                $abis = str_replace(',', ' ', $apk['nativecode']);
-                                               $out.="<p>This version uses native code and will only run on: ".$abis."</p>";
+                                               $out.="<p>This version uses native code and is built for: ".$abis."</p>";
                                        }
 
                                        // Is this source or binary?
@@ -405,6 +483,9 @@ class FDroid
                                                $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']));
@@ -583,6 +664,8 @@ class FDroid
                $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];
@@ -627,7 +710,7 @@ class FDroid
                                $out.='</form>'."\n";
                        }
                        else {
-                               $out.='Applications matching "'.$query_vars['fdfilter'].'"';
+                               $out.='Applications matching "'.esc_attr($query_vars['fdfilter']).'"';
                        }
                        $out.="</div>";
 
@@ -686,7 +769,7 @@ class FDroid
                $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')
-                               $out.='<input type="hidden" name="'.$name.'" value="'.sanitize_text_field($value).'">';
+                               $out.='<input type="hidden" name="'.esc_attr($name).'" value="'.esc_attr($value).'">';
                }
 
                return $out;
@@ -892,36 +975,11 @@ function linkify($vars) {
        $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();