]> source.dussan.org Git - nextcloud-server.git/commitdiff
change and transfert getUrlContent
authorthomas <thomas@thomas-VirtualBox.(none)>
Wed, 14 Nov 2012 22:14:04 +0000 (23:14 +0100)
committerthomas <thomas@thomas-VirtualBox.(none)>
Wed, 14 Nov 2012 22:14:04 +0000 (23:14 +0100)
lib/ocsclient.php
lib/util.php

index 795ce30190c407ccbf9aab94c4bb6845d2d185d3..e730b159afdbdd18973e21b57cec7664067c8017 100644 (file)
@@ -55,31 +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) {
-               $data = self::fileGetContentCurl($url);
+               $data = \OC_Util::getUrlContent($url);
                return($data);
        }
 
         /**
-         * @Brief Get file content via curl.
-         * @return string of the response
-         * This function get the content of a page via curl.
-         */
-        
-        private static function fileGetContentCurl($url){
-            $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($data);
-            
-            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
index 40b44bf9d6eb2d6d760c114785813362f074531c..497b78792277945c2814b3618eb7818bf5f6dfc8 100755 (executable)
@@ -642,4 +642,43 @@ class OC_Util {
 
                return false;
        }
+        
+        /**
+         * @Brief Get file content via curl.
+         * @param string $url Url to get content
+         * @return string of the response
+         * 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($data);
+
+            } else {
+                
+                $ctx = stream_context_create(
+                    array(
+                        'http' => array(
+                            'timeout' => 10
+                        )
+                    )
+                );
+                $data=@file_get_contents($url, 0, $ctx);
+                
+            }
+            
+            return($data);
+        }
+        
 }