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 // $content - optional content enclosed between the starting and // ending shortcode // 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; } $filter=$wp_query->query_vars['fdfilter']; $fdid=$wp_query->query_vars['fdid']; if($fdid!==null) $out=$this->get_app($fdid); else $out=$this->get_apps($page,$filter); return $out; } function get_app($id) { $xml = simplexml_load_file("/home/fdroid/public_html/repo/index.xml"); foreach($xml->children() as $app) { $attrs=$app->attributes(); if($attrs['id']==$id) { $apks=array();; foreach($app->children() as $el) { switch($el->getName()) { case "name": $name=$el; break; case "icon": $icon=$el; break; case "summary": $summary=$el; break; case "description": $desc=$el; break; case "license": $license=$el; break; case "source": $source=$el; break; case "tracker": $issues=$el; break; case "web": $web=$el; break; 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; } } $out="

".$name."

"; $out.='

'; $out.=$summary; $out.="

"; $out.="

".$desc."

"; $out.="

License: ".$license."

"; $out.="

Links: "; if(strlen($web)>0) $out.='Website '; if(strlen($issues)>0) $out.='Issue Tracker '; if(strlen($source)>0) $out.='Source Code'; $out.="

"; $out.="

Packages

"; foreach($apks as $apk) { $out.="

Version ".$apk['version']." - "; $out.='download '; $out.=$apk['size']." bytes"; $out.="

"; } return $out; } } return "

Application not found

"; } function get_apps($page,$filter=null) { if($filter===null) $out="

All applications"; else $out="

Applications matching ".$filter; $out.="

"; $perpage=10; $skipped=0; $got=0; $total=0; $xml = simplexml_load_file("/home/fdroid/public_html/repo/index.xml"); foreach($xml->children() as $app) { $attrs=$app->attributes(); $id=$attrs['id']; foreach($app->children() as $el) { switch($el->getName()) { case "name": $name=$el; break; case "icon": $icon=$el; break; case "summary": $summary=$el; break; case "license": $license=$el; break; } } if($filter===null || stristr($name,$filter)) { if($skipped<($page-1)*$perpage) { $skipped++; } else if($got<$perpage) { $out.="

".$name."

"; $out.='

'; $out.=$summary; $out.='
Details...'; $out.="

"; $got++; } $total++; } } $numpages=ceil((float)$total/$perpage); $out.='

'; if($page==1) { $out.="<<first "; $out.="<prev "; } else { $out.='<<first '; $out.='<<prev '; } $out.=" Page $page of $numpages "; if($page==$numpages) { $out.="next> "; $out.="last>> "; } else { $out.='next> '; $out.='last>> '; } $out.='

'; return $out; } } $wp_fdroid = new FDroid(); ?>