Normalized indentation to use tab character and unix style line endings for the wp-fdroid plugin.

This is consistent with the wordpress PHP source style.
This commit is contained in:
Hans-Emil Skogh 2011-12-29 19:45:18 +01:00
parent 5bf68469cb
commit e3af9bf78f

View file

@ -15,56 +15,56 @@ Revision history
class FDroid class FDroid
{ {
// Our text domain, for internationalisation // Our text domain, for internationalisation
private $textdom='wp-fdroid'; private $textdom='wp-fdroid';
private $site_path; private $site_path;
// 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;
$this->site_path=getenv('DOCUMENT_ROOT'); $this->site_path=getenv('DOCUMENT_ROOT');
} }
// 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';
$qvars[]='fdstyle'; $qvars[]='fdstyle';
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];
} }
// 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();
// Init local query vars // Init local query vars
foreach($this->queryvars(array()) as $qv) { foreach($this->queryvars(array()) as $qv) {
@ -87,134 +87,134 @@ class FDroid
} }
if($query_vars['fdid']!==null) { if($query_vars['fdid']!==null) {
$out.=$this->get_app($query_vars); $out.=$this->get_app($query_vars);
} else { } else {
if($query_vars['fdfilter'] !== null) if($query_vars['fdfilter'] !== null)
$out.=$this->show_search($query_vars); $out.=$this->show_search($query_vars);
$out.=$this->get_apps($query_vars); $out.=$this->get_apps($query_vars);
} }
return $out; return $out;
} }
function get_app($query_vars) { function get_app($query_vars) {
$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']==$query_vars['fdid']) { if($attrs['id']==$query_vars['fdid']) {
$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 "donate": case "donate":
$donate=$el; $donate=$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 "srcname": case "srcname":
$thisapk['srcname']=$pel; $thisapk['srcname']=$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 />';
if($donate && strlen($donate)>0) if($donate && strlen($donate)>0)
$out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</a><br />'; $out.='<b>Donate:</b> <a href="'.$donate.'">'.$donate.'</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";
if($apk['srcname']) if($apk['srcname'])
$out.='<br><a href="http://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a>'; $out.='<br><a href="http://f-droid.org/repo/'.$apk['srcname'].'">source tarball</a>';
$out.="</p>"; $out.="</p>";
} }
$out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>'; $out.='<hr><p><a href="'.makelink($query_vars,array('fdid'=>null)).'">Index</a></p>';
return $out; return $out;
} }
} }
return "<p>Application not found</p>"; return "<p>Application not found</p>";
} }
function get_apps($query_vars) { function get_apps($query_vars) {
$xml = simplexml_load_file($this->site_path."/repo/index.xml"); $xml = simplexml_load_file($this->site_path."/repo/index.xml");
$matches = $this->show_apps($xml,$query_vars,$numpages); $matches = $this->show_apps($xml,$query_vars,$numpages);
$out=''; $out='';
@ -260,11 +260,11 @@ class FDroid
$out.='<p>No matches</p>'; $out.='<p>No matches</p>';
} }
return $out; return $out;
} }
function show_search($query_vars) { function show_search($query_vars) {
$out=''; $out='';
$out.='<form name="searchform" action="" method="get">'; $out.='<form name="searchform" action="" method="get">';
@ -279,15 +279,15 @@ class FDroid
$out.='</form>'."\n"; $out.='</form>'."\n";
return $out; return $out;
} }
function show_apps($xml,$query_vars,&$numpages) { function show_apps($xml,$query_vars,&$numpages) {
$skipped=0; $skipped=0;
$got=0; $got=0;
$total=0; $total=0;
if($query_vars['fdstyle']=='grid') { if($query_vars['fdstyle']=='grid') {
$outputter = new FDOutGrid(); $outputter = new FDOutGrid();
@ -299,37 +299,37 @@ class FDroid
$out.=$outputter->outputStart(); $out.=$outputter->outputStart();
foreach($xml->children() as $app) { foreach($xml->children() as $app) {
if($app->getName() == 'repo') continue; if($app->getName() == 'repo') continue;
$appinfo['attrs']=$app->attributes(); $appinfo['attrs']=$app->attributes();
$appinfo['id']=$appinfo['attrs']['id']; $appinfo['id']=$appinfo['attrs']['id'];
foreach($app->children() as $el) { foreach($app->children() as $el) {
switch($el->getName()) { switch($el->getName()) {
case "name": case "name":
$appinfo['name']=$el; $appinfo['name']=$el;
break; break;
case "icon": case "icon":
$appinfo['icon']=$el; $appinfo['icon']=$el;
break; break;
case "summary": case "summary":
$appinfo['summary']=$el; $appinfo['summary']=$el;
break; break;
case "license": case "license":
$appinfo['license']=$el; $appinfo['license']=$el;
break; break;
} }
} }
if($query_vars['fdfilter']===null || $query_vars['fdfilter']!='' && (stristr($appinfo['name'],$query_vars['fdfilter']) || stristr($appinfo['summary'],$query_vars['fdfilter']))) { if($query_vars['fdfilter']===null || $query_vars['fdfilter']!='' && (stristr($appinfo['name'],$query_vars['fdfilter']) || stristr($appinfo['summary'],$query_vars['fdfilter']))) {
if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) { if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) {
$skipped++; $skipped++;
} else if($got<$outputter->perpage) { } else if($got<$outputter->perpage) {
$out.=$outputter->outputEntry($query_vars, $appinfo); $out.=$outputter->outputEntry($query_vars, $appinfo);
$got++; $got++;
} }
$total++; $total++;
} }
} }
$out.=$outputter->outputEnd(); $out.=$outputter->outputEnd();