From 6bbd2bf4097d5d2fffe86c3beec798ab10230b0e Mon Sep 17 00:00:00 2001 From: Hans-Emil Skogh Date: Sun, 18 Dec 2011 21:16:20 +0100 Subject: [PATCH] Implemented searching for apps in the repository. Adds a new shortcode attribute "search" for the shortcode "fdroidrepo". When this is set, a search field will be shown above the app listing. Uses the fdfilter search code to do the search result filtering. --- wp-fdroid/wp-fdroid.php | 113 ++++++++++++++++++++++++++-------------- 1 file changed, 75 insertions(+), 38 deletions(-) diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php index fe05c092..7d1b1dfc 100644 --- a/wp-fdroid/wp-fdroid.php +++ b/wp-fdroid/wp-fdroid.php @@ -81,10 +81,20 @@ class FDroid $query_vars['fdpage'] = 1; } - if($query_vars['fdid']!==null) - $out=$this->get_app($query_vars); - else - $out=$this->get_apps($query_vars); + $out = ''; + + if(isset($attribs['search']) && $query_vars['fdfilter']===null) { + $query_vars['fdfilter'] = ''; + } + + if($query_vars['fdid']!==null) { + $out.=$this->get_app($query_vars); + } else { + if($query_vars['fdfilter'] !== null) + $out.=$this->show_search($query_vars); + + $out.=$this->get_apps($query_vars); + } return $out; } @@ -204,46 +214,74 @@ 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=''; - $out.='
'; - if($query_vars['fdfilter']===null) - $out.="All applications"; - else - $out.="Applications matching ".$query_vars['fdfilter']; - $out.="
"; + if(($query_vars['fdfilter']===null || $query_vars['fdfilter']!='') && $numpages>0) + { + $out.='
'; + if($query_vars['fdfilter']===null) + $out.="All applications"; + else + $out.='Applications matching "'.$query_vars['fdfilter'].'"'; + $out.="
"; - $out.='
'; - $out.='List | '; - $out.='Grid'; - $out.='
'; + $out.='
'; + $out.='List | '; + $out.='Grid'; + $out.='
'; - $out.='
'; - - $xml = simplexml_load_file($this->site_path."/repo/index.xml"); - $out.=$this->show_apps($xml,$query_vars,$numpages); - - $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.='

'; + $out.='
'; + } + + if($numpages>0) { + $out.=$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.='
'; + $out.='

'; + $out.='

'; + + $out.=''; + foreach($query_vars as $name => $value) { + if($value !== null && $name != 'fdfilter') + $out.=''; + } + + $out.='
'."\n"; + + return $out; + } + function show_apps($xml,$query_vars,&$numpages) { @@ -283,11 +321,10 @@ class FDroid } } - if($query_vars['fdfilter']===null || stristr($appinfo['name'],$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) { $skipped++; } else if($got<$outputter->perpage) { - $out.=$outputter->outputEntry($query_vars, $appinfo); $got++; }