--- /dev/null
+\r
+=== WP FDroid ===\r
+Contributors: CiaranG\r
+Tags: android, repository\r
+Requires at least: 2.9\r
+Tested up to: 2.9\r
+Stable tag: 0.1\r
+\r
+Provides the ability to browse the contents of an FDroid repository.\r
+\r
+== Description ==\r
+\r
+This plugin provides the ability to browse the contents of an FDroid\r
+repository. The repository browser can be inserted into the site by\r
+creating a page containing the 'fdroidrepo' shortcode.\r
+\r
+License: GPL v3\r
+\r
+== Installation ==\r
+\r
+1. Download and extract the zip file.\r
+2. Upload the plugin directory to /wp-content/plugins on your server.\r
+3. Go to the Plugins screen in your Wordpress Admin and activate it.\r
+\r
+== Frequently Asked Questions ==\r
+\r
+= Is this finished? =\r
+\r
+No it isn't. I'm working on it.\r
+\r
+== Screenshots ==\r
+\r
+1. There isn't one yet actually.\r
+\r
--- /dev/null
+<?php\r
+/*\r
+Plugin Name: WP FDroid\r
+Plugin URI: http://f-droid.org/repository\r
+Description: An FDroid repository browser\r
+Author: Ciaran Gultnieks\r
+Version: 0.01\r
+Author URI: http://ciarang.com\r
+\r
+Revision history\r
+0.01 - 2010-12-04: Initial development version\r
+\r
+*/\r
+\r
+class FDroid\r
+{\r
+\r
+ // Our text domain, for internationalisation\r
+ var $textdom='wp-fdroid';\r
+\r
+ // Constructor\r
+ function FDroid() {\r
+ // Add filters etc here!\r
+ add_shortcode('fdroidrepo',array($this, 'do_shortcode'));\r
+ add_filter('query_vars',array($this, 'queryvars'));\r
+ $this->inited=false;\r
+ }\r
+\r
+\r
+ // Register additional query variables. (Handler for the 'query_vars' filter)\r
+ function queryvars($qvars) {\r
+ $qvars[]='fdfilter';\r
+ $qvars[]='fdid';\r
+ $qvars[]='fdpage';\r
+ return $qvars;\r
+ }\r
+\r
+\r
+ // Lazy initialise. All non-trivial members should call this before doing anything else.\r
+ function lazyinit() {\r
+ if(!$this->inited) {\r
+ load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));\r
+\r
+ $this->inited=true;\r
+ }\r
+ }\r
+\r
+ // Gets a required query parameter by name.\r
+ function getrequiredparam($name) {\r
+ global $wp_query;\r
+ if(!isset($wp_query->query_vars[$name]))\r
+ wp_die("Missing parameter ".$name,"Error");\r
+ return $wp_query->query_vars[$name];\r
+ }\r
+\r
+ // Make a link to this page, with the given query parameter string added\r
+ function makelink($params) {\r
+ $link=get_permalink();\r
+ if(strlen($params)==0)\r
+ return $link;\r
+ if(strpos($link,'?')===false)\r
+ $link.='?';\r
+ else\r
+ $link.='&';\r
+ $link.=$params;\r
+ return $link;\r
+ }\r
+\r
+ // Handler for the 'fdroidrepo' shortcode.\r
+ // $attribs - shortcode attributes\r
+ // $content - optional content enclosed between the starting and ending shortcode\r
+ // Returns the generated content.\r
+ function do_shortcode($attribs,$content=null) {\r
+ global $wp_query,$wp_rewrite;\r
+ $this->lazyinit();\r
+\r
+ $page=1;\r
+ if(isset($wp_query->query_vars['fdpage'])) {\r
+ $page=(int)$wp_query->query_vars['fdpage'];\r
+ if($page==0)\r
+ $page=1;\r
+ }\r
+\r
+ $filter=null;\r
+ if(isset($wp_query->query_vars['fdfilter']))\r
+ $filter=$wp_query->query_vars['fdfilter'];\r
+\r
+ $out=$this->get_apps($page,$filter);\r
+ return $out;\r
+\r
+ }\r
+\r
+\r
+\r
+ function get_apps($page,$filter=null) {\r
+\r
+ if($filter===null)\r
+ $out="<p>All applications";\r
+ else\r
+ $out="<p>Applications matching ".$filter;\r
+ $out.="</p>";\r
+\r
+ $perpage=10;\r
+ $skipped=0;\r
+ $got=0;\r
+ $total=0;\r
+\r
+ $xml = simplexml_load_file("/home/fdroid/public_html/repo/index.xml");\r
+ foreach($xml->children() as $app) {\r
+\r
+ foreach($app->children() as $el) {\r
+ switch($el->getName()) {\r
+ case "name":\r
+ $name=$el;\r
+ break;\r
+ }\r
+ }\r
+\r
+ if($filter===null || stristr($name,$filter)) {\r
+ if($skipped<($page-1)*$perpage) {\r
+ $skipped++;\r
+ } else if($got<$perpage) {\r
+ $out.="<p>".$name."</p>";\r
+ $got++;\r
+ }\r
+ $total++;\r
+ }\r
+\r
+ }\r
+\r
+ $numpages=ceil((float)$total/$perpage);\r
+\r
+ $out.='<p>';\r
+ if($page==1) {\r
+ $out.="<<first ";\r
+ $out.="<prev ";\r
+ } else {\r
+ $out.='<a href="'.$this->makelink("fdpage=1").'"><<first</a> ';\r
+ $out.='<a href="'.$this->makelink("fdpage=".($page-1)).'"><<prev</a> ';\r
+ }\r
+ $out.=" Page $page of $numpages ";\r
+ if($page==$numpages) {\r
+ $out.="next> ";\r
+ $out.="last>> ";\r
+ } else {\r
+ $out.='<a href="'.$this->makelink("fdpage=".($page+1)).'">next></a> ';\r
+ $out.='<a href="'.$this->makelink("fdpage=".$numpages).'">last>></a> ';\r
+ }\r
+ $out.='</p>';\r
+\r
+ return $out;\r
+ }\r
+\r
+\r
+\r
+}\r
+\r
+$wp_fdroid = new FDroid();\r
+\r
+\r
+?>\r