2010-12-05 00:59:29 +01:00
|
|
|
<?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';
|
|
|
|
|
2010-12-21 01:16:56 +01:00
|
|
|
var $site_path = "/var/www/fdroid";
|
|
|
|
|
2010-12-05 00:59:29 +01:00
|
|
|
// 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
|
2010-12-06 00:23:23 +01:00
|
|
|
// $content - optional content enclosed between the starting and
|
|
|
|
// ending shortcode
|
2010-12-05 00:59:29 +01:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2010-12-05 12:30:11 +01:00
|
|
|
$filter=$wp_query->query_vars['fdfilter'];
|
|
|
|
$fdid=$wp_query->query_vars['fdid'];
|
2010-12-05 00:59:29 +01:00
|
|
|
|
2010-12-05 12:30:11 +01:00
|
|
|
if($fdid!==null)
|
|
|
|
$out=$this->get_app($fdid);
|
|
|
|
else
|
|
|
|
$out=$this->get_apps($page,$filter);
|
2010-12-05 00:59:29 +01:00
|
|
|
return $out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-05 12:30:11 +01:00
|
|
|
function get_app($id) {
|
|
|
|
|
2010-12-21 01:16:56 +01:00
|
|
|
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
2010-12-05 12:30:11 +01:00
|
|
|
foreach($xml->children() as $app) {
|
|
|
|
|
|
|
|
$attrs=$app->attributes();
|
|
|
|
if($attrs['id']==$id) {
|
2010-12-06 00:23:23 +01:00
|
|
|
$apks=array();;
|
2010-12-05 12:30:11 +01:00
|
|
|
foreach($app->children() as $el) {
|
|
|
|
switch($el->getName()) {
|
|
|
|
case "name":
|
|
|
|
$name=$el;
|
|
|
|
break;
|
|
|
|
case "icon":
|
|
|
|
$icon=$el;
|
|
|
|
break;
|
|
|
|
case "summary":
|
|
|
|
$summary=$el;
|
|
|
|
break;
|
2010-12-06 00:23:23 +01:00
|
|
|
case "description":
|
|
|
|
$desc=$el;
|
|
|
|
break;
|
2010-12-05 12:30:11 +01:00
|
|
|
case "license":
|
|
|
|
$license=$el;
|
|
|
|
break;
|
|
|
|
case "source":
|
|
|
|
$source=$el;
|
|
|
|
break;
|
2010-12-06 00:23:23 +01:00
|
|
|
case "tracker":
|
2010-12-05 12:30:11 +01:00
|
|
|
$issues=$el;
|
|
|
|
break;
|
|
|
|
case "web":
|
|
|
|
$web=$el;
|
|
|
|
break;
|
2010-12-06 00:23:23 +01:00
|
|
|
case "package":
|
|
|
|
$thisapk=array();
|
|
|
|
foreach($el->children() as $pel) {
|
|
|
|
switch($pel->getName()) {
|
|
|
|
case "version":
|
|
|
|
$thisapk['version']=$pel;
|
|
|
|
break;
|
|
|
|
case "vercode":
|
|
|
|
$thisapk['vercode']=$pel;
|
|
|
|
break;
|
|
|
|
case "apkname":
|
|
|
|
$thisapk['apkname']=$pel;
|
|
|
|
break;
|
|
|
|
case "hash":
|
|
|
|
$thisapk['hash']=$pel;
|
|
|
|
break;
|
|
|
|
case "size":
|
|
|
|
$thisapk['size']=$pel;
|
|
|
|
break;
|
|
|
|
case "sdkver":
|
|
|
|
$thisapk['sdkver']=$pel;
|
|
|
|
break;
|
|
|
|
case "permissions":
|
|
|
|
$thisapk['permissions']=$pel;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$apks[]=$thisapk;
|
|
|
|
|
2010-12-05 12:30:11 +01:00
|
|
|
}
|
|
|
|
}
|
2010-12-06 22:06:16 +01:00
|
|
|
|
|
|
|
$out='<div id="appheader">';
|
|
|
|
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" width=48></div>';
|
|
|
|
$out.='<p><span style="font-size:20px">'.$name."</span>";
|
|
|
|
$out.="<br>".$summary."</p>";
|
|
|
|
$out.="</div>";
|
2010-12-06 00:23:23 +01:00
|
|
|
|
|
|
|
$out.="<p>".$desc."</p>";
|
|
|
|
|
|
|
|
$out.="<p><b>License:</b> ".$license."</p>";
|
|
|
|
|
2010-12-21 01:30:08 +01:00
|
|
|
$out.="<p>";
|
2010-12-06 00:23:23 +01:00
|
|
|
if(strlen($web)>0)
|
2010-12-21 01:30:08 +01:00
|
|
|
$out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
|
2010-12-06 00:23:23 +01:00
|
|
|
if(strlen($issues)>0)
|
2010-12-21 01:30:08 +01:00
|
|
|
$out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
|
2010-12-06 00:23:23 +01:00
|
|
|
if(strlen($source)>0)
|
2010-12-21 01:30:08 +01:00
|
|
|
$out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
|
2010-12-06 00:23:23 +01:00
|
|
|
$out.="</p>";
|
|
|
|
|
|
|
|
$out.="<h3>Packages</h3>";
|
|
|
|
foreach($apks as $apk) {
|
|
|
|
$out.="<p><b>Version ".$apk['version']."</b> - ";
|
|
|
|
$out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download</a> ';
|
|
|
|
$out.=$apk['size']." bytes";
|
|
|
|
$out.="</p>";
|
|
|
|
}
|
|
|
|
|
2010-12-06 22:06:16 +01:00
|
|
|
$out.='<hr><p><a href="'.$this->makelink("").'">Index</a></p>';
|
|
|
|
|
2010-12-05 12:30:11 +01:00
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "<p>Application not found</p>";
|
|
|
|
}
|
|
|
|
|
2010-12-05 00:59:29 +01:00
|
|
|
|
|
|
|
function get_apps($page,$filter=null) {
|
|
|
|
|
|
|
|
if($filter===null)
|
|
|
|
$out="<p>All applications";
|
|
|
|
else
|
|
|
|
$out="<p>Applications matching ".$filter;
|
|
|
|
$out.="</p>";
|
|
|
|
|
2010-12-21 01:22:57 +01:00
|
|
|
$perpage=30;
|
2010-12-05 00:59:29 +01:00
|
|
|
$skipped=0;
|
|
|
|
$got=0;
|
|
|
|
$total=0;
|
|
|
|
|
2010-12-21 01:16:56 +01:00
|
|
|
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
2010-12-05 00:59:29 +01:00
|
|
|
foreach($xml->children() as $app) {
|
|
|
|
|
2010-12-21 01:22:57 +01:00
|
|
|
if($app->getName() == 'repo') continue;
|
2010-12-05 12:30:11 +01:00
|
|
|
$attrs=$app->attributes();
|
|
|
|
$id=$attrs['id'];
|
2010-12-05 00:59:29 +01:00
|
|
|
foreach($app->children() as $el) {
|
|
|
|
switch($el->getName()) {
|
|
|
|
case "name":
|
|
|
|
$name=$el;
|
|
|
|
break;
|
2010-12-05 01:19:21 +01:00
|
|
|
case "icon":
|
|
|
|
$icon=$el;
|
|
|
|
break;
|
|
|
|
case "summary":
|
|
|
|
$summary=$el;
|
|
|
|
break;
|
|
|
|
case "license":
|
|
|
|
$license=$el;
|
|
|
|
break;
|
2010-12-05 00:59:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($filter===null || stristr($name,$filter)) {
|
|
|
|
if($skipped<($page-1)*$perpage) {
|
|
|
|
$skipped++;
|
|
|
|
} else if($got<$perpage) {
|
2010-12-06 22:06:16 +01:00
|
|
|
|
2010-12-21 01:22:57 +01:00
|
|
|
$out.="<hr>\n";
|
2010-12-06 22:06:16 +01:00
|
|
|
$out.='<div id="appheader">';
|
|
|
|
|
2010-12-21 01:22:57 +01:00
|
|
|
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" style="width:48px;"></div>';
|
2010-12-06 22:06:16 +01:00
|
|
|
|
|
|
|
$out.='<div style="float:right;">';
|
|
|
|
$out.='<p><a href="';
|
2010-12-05 12:30:11 +01:00
|
|
|
$out.=$this->makelink("fdid=".$id);
|
|
|
|
$out.='">Details...</a>';
|
2010-12-05 01:19:21 +01:00
|
|
|
$out.="</p>";
|
2010-12-21 01:22:57 +01:00
|
|
|
$out.="</div>\n";
|
2010-12-06 22:06:16 +01:00
|
|
|
|
|
|
|
$out.='<p><span style="font-size:20px">'.$name."</span>";
|
2010-12-21 01:22:57 +01:00
|
|
|
$out.="<br>".$summary."</p>\n";
|
2010-12-06 22:06:16 +01:00
|
|
|
|
2010-12-21 01:22:57 +01:00
|
|
|
$out.="</div>\n";
|
2010-12-06 22:06:16 +01:00
|
|
|
|
2010-12-05 00:59:29 +01:00
|
|
|
$got++;
|
|
|
|
}
|
|
|
|
$total++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$numpages=ceil((float)$total/$perpage);
|
|
|
|
|
2010-12-06 22:06:16 +01:00
|
|
|
$out.='<hr><p>';
|
2010-12-05 00:59:29 +01:00
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
?>
|