diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2012-11-17 12:31:25 -0800 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2012-11-17 12:31:25 -0800 |
commit | ac3e9627323b37fe1613b6879d5757241abac3ef (patch) | |
tree | c26c85e95eb52a9d07a60d926de4cea9efdfcc00 | |
parent | 9e9bf20b07a274fee5ff2e29568e4929f488d459 (diff) | |
parent | d2047a00cf0fa7383a6dd1834d3d3500f58b1931 (diff) | |
download | nextcloud-server-ac3e9627323b37fe1613b6879d5757241abac3ef.tar.gz nextcloud-server-ac3e9627323b37fe1613b6879d5757241abac3ef.zip |
Merge pull request #375 from tdevos/master
Use curl to get remote file content
-rw-r--r-- | lib/ocsclient.php | 13 | ||||
-rwxr-xr-x | lib/util.php | 39 |
2 files changed, 41 insertions, 11 deletions
diff --git a/lib/ocsclient.php b/lib/ocsclient.php index b6b5ad8f0a9..e730b159afd 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 diff --git a/lib/util.php b/lib/util.php index da57b226ba0..725278a39e6 100755 --- a/lib/util.php +++ b/lib/util.php @@ -669,4 +669,43 @@ class OC_Util { return false; } + + /** + * @Brief Get file content via curl. + * @param string $url Url to get content + * @return string of the response or false on error + * This function get the content of a page via curl, if curl is enabled. + * If not, file_get_element is used. + */ + + public static function getUrlContent($url){ + + if (function_exists('curl_init')) { + + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_HEADER, 0); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($curl, CURLOPT_URL, $url); + + $data = curl_exec($curl); + curl_close($curl); + + } else { + + $ctx = stream_context_create( + array( + 'http' => array( + 'timeout' => 10 + ) + ) + ); + $data=@file_get_contents($url, 0, $ctx); + + } + + return $data; + } + } |