diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php index 7d1b1dfc..ea9aa95d 100644 --- a/wp-fdroid/wp-fdroid.php +++ b/wp-fdroid/wp-fdroid.php @@ -18,7 +18,7 @@ class FDroid // Our text domain, for internationalisation private $textdom='wp-fdroid'; - private $site_path; + private $site_path; // Constructor function FDroid() { @@ -66,35 +66,35 @@ class FDroid global $wp_query,$wp_rewrite; $this->lazyinit(); - - // Init local query vars - foreach($this->queryvars(array()) as $qv) { - if(array_key_exists($qv,$wp_query->query_vars)) { - $query_vars[$qv] = $wp_query->query_vars[$qv]; - } else { - $query_vars[$qv] = null; - } - } - - // Santiy check query vars - if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) { - $query_vars['fdpage'] = 1; - } + + // Init local query vars + foreach($this->queryvars(array()) as $qv) { + if(array_key_exists($qv,$wp_query->query_vars)) { + $query_vars[$qv] = $wp_query->query_vars[$qv]; + } else { + $query_vars[$qv] = null; + } + } + + // Santiy check query vars + if(!isset($query_vars['fdpage']) || !is_numeric($query_vars['fdpage']) || $query_vars['fdpage'] <= 0) { + $query_vars['fdpage'] = 1; + } - $out = ''; + $out = ''; - if(isset($attribs['search']) && $query_vars['fdfilter']===null) { - $query_vars['fdfilter'] = ''; - } + if(isset($attribs['search']) && $query_vars['fdfilter']===null) { + $query_vars['fdfilter'] = ''; + } - if($query_vars['fdid']!==null) { + if($query_vars['fdid']!==null) { $out.=$this->get_app($query_vars); - } else { - if($query_vars['fdfilter'] !== null) - $out.=$this->show_search($query_vars); + } else { + if($query_vars['fdfilter'] !== null) + $out.=$this->show_search($query_vars); $out.=$this->get_apps($query_vars); - } + } return $out; } @@ -214,91 +214,91 @@ class FDroid function get_apps($query_vars) { - $xml = simplexml_load_file($this->site_path."/repo/index.xml"); - $matches = $this->show_apps($xml,$query_vars,$numpages); - - $out=''; + $xml = simplexml_load_file($this->site_path."/repo/index.xml"); + $matches = $this->show_apps($xml,$query_vars,$numpages); + + $out=''; - if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0) - { - $out.='
'; - if($query_vars['fdpage']==1) { - $out.="<<first "; - $out.="<prev "; - } else { - $out.='<<first '; - $out.='<<prev '; - } - $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' '; - if($query_vars['fdpage']==$numpages) { - $out.="next> "; - $out.="last>> "; - } else { - $out.='next> '; - $out.='last>> '; - } - $out.='
'; - } else if($query_vars['fdfilter']!='') { - $out.='No matches
'; - } + $out.=''; + if($query_vars['fdpage']==1) { + $out.="<<first "; + $out.="<prev "; + } else { + $out.='<<first '; + $out.='<<prev '; + } + $out.=' Page '.$query_vars['fdpage'].' of '.$numpages.' '; + if($query_vars['fdpage']==$numpages) { + $out.="next> "; + $out.="last>> "; + } else { + $out.='next> '; + $out.='last>> '; + } + $out.='
'; + } else if($query_vars['fdfilter']!='') { + $out.='No matches
'; + } return $out; } - + function show_search($query_vars) { - $out=''; - $out.=''."\n"; - + $out.=''; + foreach($query_vars as $name => $value) { + if($value !== null && $name != 'fdfilter') + $out.=''; + } + + $out.=''."\n"; + return $out; } - + function show_apps($xml,$query_vars,&$numpages) { - + $skipped=0; $got=0; $total=0; - if($query_vars['fdstyle']=='grid') { - $outputter = new FDOutGrid(); - } else { - $outputter = new FDOutList(); - } - - $out = ""; - - $out.=$outputter->outputStart(); - + if($query_vars['fdstyle']=='grid') { + $outputter = new FDOutGrid(); + } else { + $outputter = new FDOutList(); + } + + $out = ""; + + $out.=$outputter->outputStart(); + foreach($xml->children() as $app) { if($app->getName() == 'repo') continue; @@ -325,128 +325,128 @@ class FDroid if($skipped<($query_vars['fdpage']-1)*$outputter->perpage) { $skipped++; } else if($got<$outputter->perpage) { - $out.=$outputter->outputEntry($query_vars, $appinfo); + $out.=$outputter->outputEntry($query_vars, $appinfo); $got++; } $total++; } } - - $out.=$outputter->outputEnd(); - - $numpages = ceil((float)$total/$outputter->perpage); - - return $out; - } + + $out.=$outputter->outputEnd(); + + $numpages = ceil((float)$total/$outputter->perpage); + + return $out; + } } // Class to output app entries in a detailed list format class FDOutList { - var $perpage=30; + var $perpage=30; - function FDOutList() { - } + function FDOutList() { + } - function outputStart() { - return ''; - } - - function outputEntry($query_vars, $appinfo) { - $out=""; - $out.="Details...'; - $out.="
"; - $out.="Details...'; + $out.="
"; + $out.="'.$appinfo['name']."";
- $out.="
".$appinfo['summary']."
'.$appinfo['name']."";
+ $out.="
".$appinfo['summary']."
| ';
- $out.=' '; - $out.=' ';
+ $out.=' ";
+ $out.='';
+ $out.="';
+ $out.=' | \n";
-
- $this->itemCount++;
- return $out;
- }
+ $out.="'; + $out.=' ';
- $out.='';
- $out.=' ";
- $out.='';
- $out.="'; - $out.=$appinfo['name'].' '; - $out.=''; + $out.=''; + $out.=' '; + $out.=$appinfo['name'].' '; + $out.=''; - $out.=" | \n";
+
+ $this->itemCount++;
+ return $out;
+ }
- function outputEnd() {
- return '