From 0dd8f9bb70df02b248ec608b74d805ce09178bca Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Sat, 4 Dec 2010 23:59:29 +0000 Subject: [PATCH] The very simplest repository browser you could imagine, as a WordPress plugin --- wp-fdroid/readme.txt | 34 +++++++++ wp-fdroid/wp-fdroid.php | 161 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 195 insertions(+) create mode 100644 wp-fdroid/readme.txt create mode 100644 wp-fdroid/wp-fdroid.php diff --git a/wp-fdroid/readme.txt b/wp-fdroid/readme.txt new file mode 100644 index 00000000..0dfba563 --- /dev/null +++ b/wp-fdroid/readme.txt @@ -0,0 +1,34 @@ + +=== WP FDroid === +Contributors: CiaranG +Tags: android, repository +Requires at least: 2.9 +Tested up to: 2.9 +Stable tag: 0.1 + +Provides the ability to browse the contents of an FDroid repository. + +== Description == + +This plugin provides the ability to browse the contents of an FDroid +repository. The repository browser can be inserted into the site by +creating a page containing the 'fdroidrepo' shortcode. + +License: GPL v3 + +== Installation == + +1. Download and extract the zip file. +2. Upload the plugin directory to /wp-content/plugins on your server. +3. Go to the Plugins screen in your Wordpress Admin and activate it. + +== Frequently Asked Questions == + += Is this finished? = + +No it isn't. I'm working on it. + +== Screenshots == + +1. There isn't one yet actually. + diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php new file mode 100644 index 00000000..62e1a044 --- /dev/null +++ b/wp-fdroid/wp-fdroid.php @@ -0,0 +1,161 @@ +inited=false; + } + + + // Register additional query variables. (Handler for the 'query_vars' filter) + function queryvars($qvars) { + $qvars[]='fdfilter'; + $qvars[]='fdid'; + $qvars[]='fdpage'; + return $qvars; + } + + + // Lazy initialise. All non-trivial members should call this before doing anything else. + function lazyinit() { + if(!$this->inited) { + load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__))); + + $this->inited=true; + } + } + + // Gets a required query parameter by name. + function getrequiredparam($name) { + global $wp_query; + if(!isset($wp_query->query_vars[$name])) + wp_die("Missing parameter ".$name,"Error"); + return $wp_query->query_vars[$name]; + } + + // Make a link to this page, with the given query parameter string added + function makelink($params) { + $link=get_permalink(); + if(strlen($params)==0) + return $link; + if(strpos($link,'?')===false) + $link.='?'; + else + $link.='&'; + $link.=$params; + return $link; + } + + // Handler for the 'fdroidrepo' shortcode. + // $attribs - shortcode attributes + // $content - optional content enclosed between the starting and ending shortcode + // Returns the generated content. + function do_shortcode($attribs,$content=null) { + global $wp_query,$wp_rewrite; + $this->lazyinit(); + + $page=1; + if(isset($wp_query->query_vars['fdpage'])) { + $page=(int)$wp_query->query_vars['fdpage']; + if($page==0) + $page=1; + } + + $filter=null; + if(isset($wp_query->query_vars['fdfilter'])) + $filter=$wp_query->query_vars['fdfilter']; + + $out=$this->get_apps($page,$filter); + return $out; + + } + + + + function get_apps($page,$filter=null) { + + if($filter===null) + $out="

All applications"; + else + $out="

Applications matching ".$filter; + $out.="

"; + + $perpage=10; + $skipped=0; + $got=0; + $total=0; + + $xml = simplexml_load_file("/home/fdroid/public_html/repo/index.xml"); + foreach($xml->children() as $app) { + + foreach($app->children() as $el) { + switch($el->getName()) { + case "name": + $name=$el; + break; + } + } + + if($filter===null || stristr($name,$filter)) { + if($skipped<($page-1)*$perpage) { + $skipped++; + } else if($got<$perpage) { + $out.="

".$name."

"; + $got++; + } + $total++; + } + + } + + $numpages=ceil((float)$total/$perpage); + + $out.='

'; + if($page==1) { + $out.="<<first "; + $out.="<prev "; + } else { + $out.='<<first '; + $out.='<<prev '; + } + $out.=" Page $page of $numpages "; + if($page==$numpages) { + $out.="next> "; + $out.="last>> "; + } else { + $out.='next> '; + $out.='last>> '; + } + $out.='

'; + + return $out; + } + + + +} + +$wp_fdroid = new FDroid(); + + +?> -- 2.30.2