From f7757734399eef1988252dbdf39f02826bd47ebb Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Sat, 22 Jan 2011 13:15:10 +0000 Subject: [PATCH] Retabbed the wordpress plugin --- wp-fdroid/wp-fdroid.php | 452 ++++++++++++++++++++-------------------- 1 file changed, 226 insertions(+), 226 deletions(-) diff --git a/wp-fdroid/wp-fdroid.php b/wp-fdroid/wp-fdroid.php index 0d27665c..7cb186ee 100644 --- a/wp-fdroid/wp-fdroid.php +++ b/wp-fdroid/wp-fdroid.php @@ -15,276 +15,276 @@ Revision history class FDroid { - // Our text domain, for internationalisation - var $textdom='wp-fdroid'; + // Our text domain, for internationalisation + var $textdom='wp-fdroid'; var $site_path = "/var/www/fdroid"; - // Constructor - function FDroid() { - // Add filters etc here! - add_shortcode('fdroidrepo',array($this, 'do_shortcode')); - add_filter('query_vars',array($this, 'queryvars')); - $this->inited=false; - } + // Constructor + function FDroid() { + // Add filters etc here! + add_shortcode('fdroidrepo',array($this, 'do_shortcode')); + add_filter('query_vars',array($this, 'queryvars')); + $this->inited=false; + } - // Register additional query variables. (Handler for the 'query_vars' filter) - function queryvars($qvars) { - $qvars[]='fdfilter'; - $qvars[]='fdid'; - $qvars[]='fdpage'; - return $qvars; - } + // 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__))); + // 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; - } - } + $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]; - } + // 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; - } + // 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(); + // 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; - } + $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']; + $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; + if($fdid!==null) + $out=$this->get_app($fdid); + else + $out=$this->get_apps($page,$filter); + return $out; - } + } - function get_app($id) { + function get_app($id) { - $xml = simplexml_load_file($this->site_path."/repo/index.xml"); - foreach($xml->children() as $app) { + $xml = simplexml_load_file($this->site_path."/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; + $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='
'; - $out.='
'; - $out.='

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

"; - $out.="
"; + $out='
'; + $out.='
'; + $out.='

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

"; + $out.="
"; - $out.="

".$desc."

"; + $out.="

".$desc."

"; - $out.="

License: ".$license."

"; + $out.="

License: ".$license."

"; - $out.="

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

"; + $out.="

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

"; - $out.="

Packages

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

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

"; - } + $out.="

Packages

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

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

"; + } - $out.='

Index

'; + $out.='

Index

'; - return $out; - } - } - return "

Application not found

"; - } + return $out; + } + } + return "

Application not found

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

All applications"; - else - $out="

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

"; + if($filter===null) + $out="

All applications"; + else + $out="

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

"; - $perpage=30; - $skipped=0; - $got=0; - $total=0; + $perpage=30; + $skipped=0; + $got=0; + $total=0; - $xml = simplexml_load_file($this->site_path."/repo/index.xml"); - foreach($xml->children() as $app) { + $xml = simplexml_load_file($this->site_path."/repo/index.xml"); + foreach($xml->children() as $app) { - if($app->getName() == 'repo') continue; - $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($app->getName() == 'repo') continue; + $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) { + if($filter===null || stristr($name,$filter)) { + if($skipped<($page-1)*$perpage) { + $skipped++; + } else if($got<$perpage) { - $out.="
\n"; - $out.='
'; + $out.="
\n"; + $out.='
'; - $out.='
'; + $out.='
'; - $out.='
'; - $out.='

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

"; - $out.="
\n"; + $out.='
'; + $out.='

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

"; + $out.="
\n"; - $out.='

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

\n"; + $out.='

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

\n"; - $out.="
\n"; + $out.="
\n"; - $got++; - } - $total++; - } + $got++; + } + $total++; + } - } + } - $numpages=ceil((float)$total/$perpage); + $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.='

'; + $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; - } + return $out; + }