mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-11-20 13:50:12 +01:00
The very simplest repository browser you could imagine, as a WordPress plugin
This commit is contained in:
parent
9f8e950374
commit
0dd8f9bb70
34
wp-fdroid/readme.txt
Normal file
34
wp-fdroid/readme.txt
Normal file
@ -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.
|
||||
|
161
wp-fdroid/wp-fdroid.php
Normal file
161
wp-fdroid/wp-fdroid.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: WP FDroid
|
||||
Plugin URI: http://f-droid.org/repository
|
||||
Description: An FDroid repository browser
|
||||
Author: Ciaran Gultnieks
|
||||
Version: 0.01
|
||||
Author URI: http://ciarang.com
|
||||
|
||||
Revision history
|
||||
0.01 - 2010-12-04: Initial development version
|
||||
|
||||
*/
|
||||
|
||||
class FDroid
|
||||
{
|
||||
|
||||
// Our text domain, for internationalisation
|
||||
var $textdom='wp-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;
|
||||
}
|
||||
|
||||
|
||||
// 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="<p>All applications";
|
||||
else
|
||||
$out="<p>Applications matching ".$filter;
|
||||
$out.="</p>";
|
||||
|
||||
$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.="<p>".$name."</p>";
|
||||
$got++;
|
||||
}
|
||||
$total++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$numpages=ceil((float)$total/$perpage);
|
||||
|
||||
$out.='<p>';
|
||||
if($page==1) {
|
||||
$out.="<<first ";
|
||||
$out.="<prev ";
|
||||
} else {
|
||||
$out.='<a href="'.$this->makelink("fdpage=1").'"><<first</a> ';
|
||||
$out.='<a href="'.$this->makelink("fdpage=".($page-1)).'"><<prev</a> ';
|
||||
}
|
||||
$out.=" Page $page of $numpages ";
|
||||
if($page==$numpages) {
|
||||
$out.="next> ";
|
||||
$out.="last>> ";
|
||||
} else {
|
||||
$out.='<a href="'.$this->makelink("fdpage=".($page+1)).'">next></a> ';
|
||||
$out.='<a href="'.$this->makelink("fdpage=".$numpages).'">last>></a> ';
|
||||
}
|
||||
$out.='</p>';
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$wp_fdroid = new FDroid();
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user