mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-10-05 18:50:09 +02:00
Retabbed the wordpress plugin
This commit is contained in:
parent
035febb2bf
commit
f775773439
@ -15,276 +15,276 @@ Revision history
|
|||||||
class FDroid
|
class FDroid
|
||||||
{
|
{
|
||||||
|
|
||||||
// Our text domain, for internationalisation
|
// Our text domain, for internationalisation
|
||||||
var $textdom='wp-fdroid';
|
var $textdom='wp-fdroid';
|
||||||
|
|
||||||
var $site_path = "/var/www/fdroid";
|
var $site_path = "/var/www/fdroid";
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
function FDroid() {
|
function FDroid() {
|
||||||
// Add filters etc here!
|
// Add filters etc here!
|
||||||
add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
|
add_shortcode('fdroidrepo',array($this, 'do_shortcode'));
|
||||||
add_filter('query_vars',array($this, 'queryvars'));
|
add_filter('query_vars',array($this, 'queryvars'));
|
||||||
$this->inited=false;
|
$this->inited=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Register additional query variables. (Handler for the 'query_vars' filter)
|
// Register additional query variables. (Handler for the 'query_vars' filter)
|
||||||
function queryvars($qvars) {
|
function queryvars($qvars) {
|
||||||
$qvars[]='fdfilter';
|
$qvars[]='fdfilter';
|
||||||
$qvars[]='fdid';
|
$qvars[]='fdid';
|
||||||
$qvars[]='fdpage';
|
$qvars[]='fdpage';
|
||||||
return $qvars;
|
return $qvars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Lazy initialise. All non-trivial members should call this before doing anything else.
|
// Lazy initialise. All non-trivial members should call this before doing anything else.
|
||||||
function lazyinit() {
|
function lazyinit() {
|
||||||
if(!$this->inited) {
|
if(!$this->inited) {
|
||||||
load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
|
load_plugin_textdomain($this->textdom, PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)), dirname(plugin_basename(__FILE__)));
|
||||||
|
|
||||||
$this->inited=true;
|
$this->inited=true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets a required query parameter by name.
|
// Gets a required query parameter by name.
|
||||||
function getrequiredparam($name) {
|
function getrequiredparam($name) {
|
||||||
global $wp_query;
|
global $wp_query;
|
||||||
if(!isset($wp_query->query_vars[$name]))
|
if(!isset($wp_query->query_vars[$name]))
|
||||||
wp_die("Missing parameter ".$name,"Error");
|
wp_die("Missing parameter ".$name,"Error");
|
||||||
return $wp_query->query_vars[$name];
|
return $wp_query->query_vars[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a link to this page, with the given query parameter string added
|
// Make a link to this page, with the given query parameter string added
|
||||||
function makelink($params) {
|
function makelink($params) {
|
||||||
$link=get_permalink();
|
$link=get_permalink();
|
||||||
if(strlen($params)==0)
|
if(strlen($params)==0)
|
||||||
return $link;
|
return $link;
|
||||||
if(strpos($link,'?')===false)
|
if(strpos($link,'?')===false)
|
||||||
$link.='?';
|
$link.='?';
|
||||||
else
|
else
|
||||||
$link.='&';
|
$link.='&';
|
||||||
$link.=$params;
|
$link.=$params;
|
||||||
return $link;
|
return $link;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler for the 'fdroidrepo' shortcode.
|
// Handler for the 'fdroidrepo' shortcode.
|
||||||
// $attribs - shortcode attributes
|
// $attribs - shortcode attributes
|
||||||
// $content - optional content enclosed between the starting and
|
// $content - optional content enclosed between the starting and
|
||||||
// ending shortcode
|
// ending shortcode
|
||||||
// Returns the generated content.
|
// Returns the generated content.
|
||||||
function do_shortcode($attribs,$content=null) {
|
function do_shortcode($attribs,$content=null) {
|
||||||
global $wp_query,$wp_rewrite;
|
global $wp_query,$wp_rewrite;
|
||||||
$this->lazyinit();
|
$this->lazyinit();
|
||||||
|
|
||||||
$page=1;
|
$page=1;
|
||||||
if(isset($wp_query->query_vars['fdpage'])) {
|
if(isset($wp_query->query_vars['fdpage'])) {
|
||||||
$page=(int)$wp_query->query_vars['fdpage'];
|
$page=(int)$wp_query->query_vars['fdpage'];
|
||||||
if($page==0)
|
if($page==0)
|
||||||
$page=1;
|
$page=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$filter=$wp_query->query_vars['fdfilter'];
|
$filter=$wp_query->query_vars['fdfilter'];
|
||||||
$fdid=$wp_query->query_vars['fdid'];
|
$fdid=$wp_query->query_vars['fdid'];
|
||||||
|
|
||||||
if($fdid!==null)
|
if($fdid!==null)
|
||||||
$out=$this->get_app($fdid);
|
$out=$this->get_app($fdid);
|
||||||
else
|
else
|
||||||
$out=$this->get_apps($page,$filter);
|
$out=$this->get_apps($page,$filter);
|
||||||
return $out;
|
return $out;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_app($id) {
|
function get_app($id) {
|
||||||
|
|
||||||
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
||||||
foreach($xml->children() as $app) {
|
foreach($xml->children() as $app) {
|
||||||
|
|
||||||
$attrs=$app->attributes();
|
$attrs=$app->attributes();
|
||||||
if($attrs['id']==$id) {
|
if($attrs['id']==$id) {
|
||||||
$apks=array();;
|
$apks=array();;
|
||||||
foreach($app->children() as $el) {
|
foreach($app->children() as $el) {
|
||||||
switch($el->getName()) {
|
switch($el->getName()) {
|
||||||
case "name":
|
case "name":
|
||||||
$name=$el;
|
$name=$el;
|
||||||
break;
|
break;
|
||||||
case "icon":
|
case "icon":
|
||||||
$icon=$el;
|
$icon=$el;
|
||||||
break;
|
break;
|
||||||
case "summary":
|
case "summary":
|
||||||
$summary=$el;
|
$summary=$el;
|
||||||
break;
|
break;
|
||||||
case "description":
|
case "description":
|
||||||
$desc=$el;
|
$desc=$el;
|
||||||
break;
|
break;
|
||||||
case "license":
|
case "license":
|
||||||
$license=$el;
|
$license=$el;
|
||||||
break;
|
break;
|
||||||
case "source":
|
case "source":
|
||||||
$source=$el;
|
$source=$el;
|
||||||
break;
|
break;
|
||||||
case "tracker":
|
case "tracker":
|
||||||
$issues=$el;
|
$issues=$el;
|
||||||
break;
|
break;
|
||||||
case "web":
|
case "web":
|
||||||
$web=$el;
|
$web=$el;
|
||||||
break;
|
break;
|
||||||
case "package":
|
case "package":
|
||||||
$thisapk=array();
|
$thisapk=array();
|
||||||
foreach($el->children() as $pel) {
|
foreach($el->children() as $pel) {
|
||||||
switch($pel->getName()) {
|
switch($pel->getName()) {
|
||||||
case "version":
|
case "version":
|
||||||
$thisapk['version']=$pel;
|
$thisapk['version']=$pel;
|
||||||
break;
|
break;
|
||||||
case "vercode":
|
case "vercode":
|
||||||
$thisapk['vercode']=$pel;
|
$thisapk['vercode']=$pel;
|
||||||
break;
|
break;
|
||||||
case "apkname":
|
case "apkname":
|
||||||
$thisapk['apkname']=$pel;
|
$thisapk['apkname']=$pel;
|
||||||
break;
|
break;
|
||||||
case "hash":
|
case "hash":
|
||||||
$thisapk['hash']=$pel;
|
$thisapk['hash']=$pel;
|
||||||
break;
|
break;
|
||||||
case "size":
|
case "size":
|
||||||
$thisapk['size']=$pel;
|
$thisapk['size']=$pel;
|
||||||
break;
|
break;
|
||||||
case "sdkver":
|
case "sdkver":
|
||||||
$thisapk['sdkver']=$pel;
|
$thisapk['sdkver']=$pel;
|
||||||
break;
|
break;
|
||||||
case "permissions":
|
case "permissions":
|
||||||
$thisapk['permissions']=$pel;
|
$thisapk['permissions']=$pel;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$apks[]=$thisapk;
|
$apks[]=$thisapk;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$out='<div id="appheader">';
|
$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.='<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.='<p><span style="font-size:20px">'.$name."</span>";
|
||||||
$out.="<br>".$summary."</p>";
|
$out.="<br>".$summary."</p>";
|
||||||
$out.="</div>";
|
$out.="</div>";
|
||||||
|
|
||||||
$out.="<p>".$desc."</p>";
|
$out.="<p>".$desc."</p>";
|
||||||
|
|
||||||
$out.="<p><b>License:</b> ".$license."</p>";
|
$out.="<p><b>License:</b> ".$license."</p>";
|
||||||
|
|
||||||
$out.="<p>";
|
$out.="<p>";
|
||||||
if(strlen($web)>0)
|
if(strlen($web)>0)
|
||||||
$out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
|
$out.='<b>Website:</b> <a href="'.$web.'">'.$web.'</a><br />';
|
||||||
if(strlen($issues)>0)
|
if(strlen($issues)>0)
|
||||||
$out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
|
$out.='<b>Issue Tracker:</b> <a href="'.$issues.'">'.$issues.'</a><br />';
|
||||||
if(strlen($source)>0)
|
if(strlen($source)>0)
|
||||||
$out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
|
$out.='<b>Source Code:</b> <a href="'.$source.'">'.$source.'</a><br />';
|
||||||
$out.="</p>";
|
$out.="</p>";
|
||||||
|
|
||||||
$out.="<h3>Packages</h3>";
|
$out.="<h3>Packages</h3>";
|
||||||
foreach($apks as $apk) {
|
foreach($apks as $apk) {
|
||||||
$out.="<p><b>Version ".$apk['version']."</b> - ";
|
$out.="<p><b>Version ".$apk['version']."</b> - ";
|
||||||
$out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download</a> ';
|
$out.='<a href="http://f-droid.org/repo/'.$apk['apkname'].'">download</a> ';
|
||||||
$out.=$apk['size']." bytes";
|
$out.=$apk['size']." bytes";
|
||||||
$out.="</p>";
|
$out.="</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$out.='<hr><p><a href="'.$this->makelink("").'">Index</a></p>';
|
$out.='<hr><p><a href="'.$this->makelink("").'">Index</a></p>';
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "<p>Application not found</p>";
|
return "<p>Application not found</p>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function get_apps($page,$filter=null) {
|
function get_apps($page,$filter=null) {
|
||||||
|
|
||||||
if($filter===null)
|
if($filter===null)
|
||||||
$out="<p>All applications";
|
$out="<p>All applications";
|
||||||
else
|
else
|
||||||
$out="<p>Applications matching ".$filter;
|
$out="<p>Applications matching ".$filter;
|
||||||
$out.="</p>";
|
$out.="</p>";
|
||||||
|
|
||||||
$perpage=30;
|
$perpage=30;
|
||||||
$skipped=0;
|
$skipped=0;
|
||||||
$got=0;
|
$got=0;
|
||||||
$total=0;
|
$total=0;
|
||||||
|
|
||||||
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
$xml = simplexml_load_file($this->site_path."/repo/index.xml");
|
||||||
foreach($xml->children() as $app) {
|
foreach($xml->children() as $app) {
|
||||||
|
|
||||||
if($app->getName() == 'repo') continue;
|
if($app->getName() == 'repo') continue;
|
||||||
$attrs=$app->attributes();
|
$attrs=$app->attributes();
|
||||||
$id=$attrs['id'];
|
$id=$attrs['id'];
|
||||||
foreach($app->children() as $el) {
|
foreach($app->children() as $el) {
|
||||||
switch($el->getName()) {
|
switch($el->getName()) {
|
||||||
case "name":
|
case "name":
|
||||||
$name=$el;
|
$name=$el;
|
||||||
break;
|
break;
|
||||||
case "icon":
|
case "icon":
|
||||||
$icon=$el;
|
$icon=$el;
|
||||||
break;
|
break;
|
||||||
case "summary":
|
case "summary":
|
||||||
$summary=$el;
|
$summary=$el;
|
||||||
break;
|
break;
|
||||||
case "license":
|
case "license":
|
||||||
$license=$el;
|
$license=$el;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($filter===null || stristr($name,$filter)) {
|
if($filter===null || stristr($name,$filter)) {
|
||||||
if($skipped<($page-1)*$perpage) {
|
if($skipped<($page-1)*$perpage) {
|
||||||
$skipped++;
|
$skipped++;
|
||||||
} else if($got<$perpage) {
|
} else if($got<$perpage) {
|
||||||
|
|
||||||
$out.="<hr>\n";
|
$out.="<hr>\n";
|
||||||
$out.='<div id="appheader">';
|
$out.='<div id="appheader">';
|
||||||
|
|
||||||
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" style="width:48px;"></div>';
|
$out.='<div style="float:left;padding-right:10px;"><img src="http://f-droid.org/repo/icons/'.$icon.'" style="width:48px;"></div>';
|
||||||
|
|
||||||
$out.='<div style="float:right;">';
|
$out.='<div style="float:right;">';
|
||||||
$out.='<p><a href="';
|
$out.='<p><a href="';
|
||||||
$out.=$this->makelink("fdid=".$id);
|
$out.=$this->makelink("fdid=".$id);
|
||||||
$out.='">Details...</a>';
|
$out.='">Details...</a>';
|
||||||
$out.="</p>";
|
$out.="</p>";
|
||||||
$out.="</div>\n";
|
$out.="</div>\n";
|
||||||
|
|
||||||
$out.='<p><span style="font-size:20px">'.$name."</span>";
|
$out.='<p><span style="font-size:20px">'.$name."</span>";
|
||||||
$out.="<br>".$summary."</p>\n";
|
$out.="<br>".$summary."</p>\n";
|
||||||
|
|
||||||
$out.="</div>\n";
|
$out.="</div>\n";
|
||||||
|
|
||||||
$got++;
|
$got++;
|
||||||
}
|
}
|
||||||
$total++;
|
$total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$numpages=ceil((float)$total/$perpage);
|
$numpages=ceil((float)$total/$perpage);
|
||||||
|
|
||||||
$out.='<hr><p>';
|
$out.='<hr><p>';
|
||||||
if($page==1) {
|
if($page==1) {
|
||||||
$out.="<<first ";
|
$out.="<<first ";
|
||||||
$out.="<prev ";
|
$out.="<prev ";
|
||||||
} else {
|
} else {
|
||||||
$out.='<a href="'.$this->makelink("fdpage=1").'"><<first</a> ';
|
$out.='<a href="'.$this->makelink("fdpage=1").'"><<first</a> ';
|
||||||
$out.='<a href="'.$this->makelink("fdpage=".($page-1)).'"><<prev</a> ';
|
$out.='<a href="'.$this->makelink("fdpage=".($page-1)).'"><<prev</a> ';
|
||||||
}
|
}
|
||||||
$out.=" Page $page of $numpages ";
|
$out.=" Page $page of $numpages ";
|
||||||
if($page==$numpages) {
|
if($page==$numpages) {
|
||||||
$out.="next> ";
|
$out.="next> ";
|
||||||
$out.="last>> ";
|
$out.="last>> ";
|
||||||
} else {
|
} else {
|
||||||
$out.='<a href="'.$this->makelink("fdpage=".($page+1)).'">next></a> ';
|
$out.='<a href="'.$this->makelink("fdpage=".($page+1)).'">next></a> ';
|
||||||
$out.='<a href="'.$this->makelink("fdpage=".$numpages).'">last>></a> ';
|
$out.='<a href="'.$this->makelink("fdpage=".$numpages).'">last>></a> ';
|
||||||
}
|
}
|
||||||
$out.='</p>';
|
$out.='</p>';
|
||||||
|
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user