diff options
Diffstat (limited to 'lib/ocsclient.php')
-rw-r--r-- | lib/ocsclient.php | 86 |
1 files changed, 36 insertions, 50 deletions
diff --git a/lib/ocsclient.php b/lib/ocsclient.php index 32c2cfe6e48..12e5026a877 100644 --- a/lib/ocsclient.php +++ b/lib/ocsclient.php @@ -55,20 +55,11 @@ class OC_OCSClient{ * This function calls an OCS server and returns the response. It also sets a sane timeout */ private static function getOCSresponse($url) { - // set a sensible timeout of 10 sec to stay responsive even if the server is down. - $ctx = stream_context_create( - array( - 'http' => array( - 'timeout' => 10 - ) - ) - ); - $data=@file_get_contents($url, 0, $ctx); + $data = \OC_Util::getUrlContent($url); return($data); } - - /** + /** * @brief Get all the categories from the OCS server * @returns array with category ids * @note returns NULL if config value appstoreenabled is set to false @@ -105,18 +96,18 @@ class OC_OCSClient{ * * This function returns a list of all the applications on the OCS server */ - public static function getApplications($categories,$page,$filter) { + public static function getApplications($categories, $page, $filter) { if(OC_Config::getValue('appstoreenabled', true)==false) { return(array()); } if(is_array($categories)) { - $categoriesstring=implode('x',$categories); + $categoriesstring=implode('x', $categories); }else{ $categoriesstring=$categories; } - $version='&version='.implode('x',\OC_Util::getVersion()); + $version='&version='.implode('x', \OC_Util::getVersion()); $filterurl='&filter='.urlencode($filter); $url=OC_OCSClient::getAppStoreURL().'/content/data?categories='.urlencode($categoriesstring).'&sortmode=new&page='.urlencode($page).'&pagesize=100'.$filterurl.$version; $apps=array(); @@ -162,7 +153,7 @@ class OC_OCSClient{ $xml=OC_OCSClient::getOCSresponse($url); if($xml==false) { - OC_Log::write('core','Unable to parse OCS content',OC_Log::FATAL); + OC_Log::write('core', 'Unable to parse OCS content', OC_Log::FATAL); return null; } $data=simplexml_load_string($xml); @@ -192,7 +183,7 @@ class OC_OCSClient{ * * This function returns an download url for an applications from the OCS server */ - public static function getApplicationDownload($id,$item) { + public static function getApplicationDownload($id, $item) { if(OC_Config::getValue('appstoreenabled', true)==false) { return null; } @@ -200,7 +191,7 @@ class OC_OCSClient{ $xml=OC_OCSClient::getOCSresponse($url); if($xml==false) { - OC_Log::write('core','Unable to parse OCS content',OC_Log::FATAL); + OC_Log::write('core', 'Unable to parse OCS content', OC_Log::FATAL); return null; } $data=simplexml_load_string($xml); @@ -222,40 +213,35 @@ class OC_OCSClient{ * * This function returns a list of all the knowledgebase entries from the OCS server */ - public static function getKnownledgebaseEntries($page,$pagesize,$search='') { - if(OC_Config::getValue('knowledgebaseenabled', true)==false) { - $kbe=array(); - $kbe['totalitems']=0; - return $kbe; - } - - $p= (int) $page; - $s= (int) $pagesize; - if($search<>'') $searchcmd='&search='.urlencode($search); else $searchcmd=''; - $url=OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='.$p.'&pagesize='.$s.$searchcmd; - - $kbe=array(); - $xml=OC_OCSClient::getOCSresponse($url); - - if($xml==false) { - OC_Log::write('core','Unable to parse knowledgebase content',OC_Log::FATAL); - return null; - } - $data=simplexml_load_string($xml); - - $tmp=$data->data->content; - for($i = 0; $i < count($tmp); $i++) { - $kb=array(); - $kb['id']=$tmp[$i]->id; - $kb['name']=$tmp[$i]->name; - $kb['description']=$tmp[$i]->description; - $kb['answer']=$tmp[$i]->answer; - $kb['preview1']=$tmp[$i]->smallpreviewpic1; - $kb['detailpage']=$tmp[$i]->detailpage; - $kbe[]=$kb; + public static function getKnownledgebaseEntries($page, $pagesize, $search='') { + $kbe = array('totalitems' => 0); + if(OC_Config::getValue('knowledgebaseenabled', true)) { + $p = (int) $page; + $s = (int) $pagesize; + $searchcmd = ''; + if ($search) { + $searchcmd = '&search='.urlencode($search); + } + $url = OC_OCSClient::getKBURL().'/knowledgebase/data?type=150&page='. $p .'&pagesize='. $s . $searchcmd; + $xml = OC_OCSClient::getOCSresponse($url); + $data = @simplexml_load_string($xml); + if($data===false) { + OC_Log::write('core', 'Unable to parse knowledgebase content', OC_Log::FATAL); + return null; + } + $tmp = $data->data->content; + for($i = 0; $i < count($tmp); $i++) { + $kbe[] = array( + 'id' => $tmp[$i]->id, + 'name' => $tmp[$i]->name, + 'description' => $tmp[$i]->description, + 'answer' => $tmp[$i]->answer, + 'preview1' => $tmp[$i]->smallpreviewpic1, + 'detailpage' => $tmp[$i]->detailpage + ); + } + $kbe['totalitems'] = $data->meta->totalitems; } - $total=$data->meta->totalitems; - $kbe['totalitems']=$total; return $kbe; } |