*/ class RestClient { private $curl ; private $url ; private $response =""; private $headers = array(); private $method="GET"; private $params=array(); private $contentType = null; private $file =null; /** * Private Constructor, sets default options */ private function __construct() { $this->curl = curl_init(); curl_setopt($this->curl,CURLOPT_RETURNTRANSFER,true); curl_setopt($this->curl,CURLOPT_AUTOREFERER,true); // This make sure will follow redirects //curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,true); // This too curl_setopt($this->curl,CURLOPT_HEADER,true); // THis verbose option for extracting the headers } /** * Execute the call to the webservice * @return RestClient */ public function execute() { if($this->method === "POST") { curl_setopt($this->curl,CURLOPT_POST,true); //curl_setopt($this->curl,CURLOPT_POSTFIELDS,urlencode($this->params)); //curl_setopt($this->curl,CURLOPT_POSTFIELDS,http_build_query($this->params)); /* * curl postfield doesn't accept array * -> http://curl.haxx.se/mail/curlphp-2003-03/0000.html * * in case of $data -> pass to query string (get), when isfile=true , regulrar POST way (for file upload) */ if($this->params['isfile'] == 'true') { curl_setopt($this->curl,CURLOPT_POSTFIELDS,$this->params); } else { curl_setopt($this->curl,CURLOPT_POSTFIELDS,http_build_query($this->params)); $httpquery = '?' .http_build_query($this->params); } //curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); } else if($this->method === "GET"){ curl_setopt($this->curl,CURLOPT_HTTPGET,true); $this->treatURL(); $httpquery = ''; } else if($this->method === "PUT") { curl_setopt($this->curl,CURLOPT_POSTFIELDS,http_build_query($this->params)); curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST, "PUT"); $httpquery = '?' .http_build_query($this->params); /* curl_setopt($this->curl,CURLOPT_PUT,true); $this->treatURL(); $this->file = tmpFile(); fwrite($this->file,$this->params); fseek($this->file,0); curl_setopt($this->curl,CURLOPT_INFILE,$this->file); curl_setopt($this->curl,CURLOPT_INFILESIZE,strlen($this->params)); $httpquery = ''; */ } else { $httpquery = '?' .http_build_query($this->params); curl_setopt($this->curl,CURLOPT_CUSTOMREQUEST,$this->method); } if($this->contentType != null) { curl_setopt($this->curl,CURLOPT_HTTPHEADER,array("Content-Type: ".$this->contentType)); } curl_setopt($this->curl,CURLOPT_URL,$this->url . $httpquery); $r = curl_exec($this->curl); $this->treatResponse($r); // Extract the headers and response //mail('chris.s@kryap.com', 'Sous-Chef debug from site', print_r($this->params, true) . print_r($this->method, true) . print_r($this->url, true) . print_r($this->curl, true) . print_r($r, true)); return $this ; } /** * Treats URL */ private function treatURL(){ if(is_array($this->params) && count($this->params) >= 1) { // Transform parameters in key/value pars in URL if(!strpos($this->url,'?')) $this->url .= '?' ; /* foreach($this->params as $k=>$v) { $this->url .= "&".urlencode($k)."=".urlencode($v); } */ $this->url .= "&".http_build_query($this->params); } return $this->url; } /* * Treats the Response for extracting the Headers and Response */ private function treatResponse($r) { if($r == null or strlen($r) < 1) { return; } $parts = explode("\n\r",$r); // HTTP packets define that Headers end in a blank line (\n\r) where starts the body if(preg_match('@HTTP/1.[0-1] 100 Continue@',$parts[0])) { // Continue header must be bypass for($i=1;$iheaders['content-type'] = $reg[1]; preg_match("@HTTP/1.[0-1] ([0-9]{3}) ([a-zA-Z ]+)@",$parts[0],$reg); // This extracts the response header Code and Message $this->headers['code'] = $reg[1]; $this->headers['message'] = $reg[2]; $this->response = ""; for($i=1;$i 1) { $this->response .= "\n\r"; } $this->response .= $parts[$i]; } } /* * @return array */ public function getHeaders() { return $this->headers; } /* * @return string */ public function getResponse() { return $this->response ; } /* * HTTP response code (404,401,200,etc) * @return int */ public function getResponseCode() { return (int) $this->headers['code']; } /* * HTTP response message (Not Found, Continue, etc ) * @return string */ public function getResponseMessage() { return $this->headers['message']; } /* * Content-Type (text/plain, application/xml, etc) * @return string */ public function getResponseContentType() { return $this->headers['content-type']; } /** * This sets that will not follow redirects * @return RestClient */ public function setNoFollow() { curl_setopt($this->curl,CURLOPT_AUTOREFERER,false); curl_setopt($this->curl,CURLOPT_FOLLOWLOCATION,false); return $this; } /** * This closes the connection and release resources * @return RestClient */ public function close() { curl_close($this->curl); $this->curl = null ; if($this->file !=null) { fclose($this->file); } return $this ; } /** * Sets the URL to be Called * @return RestClient */ public function setUrl($url) { $this->url = $url; return $this; } /** * Set the Content-Type of the request to be send * Format like "application/xml" or "text/plain" or other * @param string $contentType * @return RestClient */ public function setContentType($contentType) { $this->contentType = $contentType; return $this; } /** * Set the Credentials for BASIC Authentication * @param string $user * @param string $pass * @return RestClient */ public function setCredentials($user,$pass) { if($user != null) { curl_setopt($this->curl,CURLOPT_HTTPAUTH,CURLAUTH_BASIC); curl_setopt($this->curl,CURLOPT_USERPWD,"{$user}:{$pass}"); } return $this; } /** * Set the Request HTTP Method * For now, only accepts GET and POST * @param string $method * @return RestClient */ public function setMethod($method) { $this->method=$method; return $this; } /** * Set Parameters to be send on the request * It can be both a key/value par array (as in array("key"=>"value")) * or a string containing the body of the request, like a XML, JSON or other * Proper content-type should be set for the body if not a array * @param mixed $params * @return RestClient */ public function setParameters($params) { $this->params=$params; return $this; } /** * Creates the RESTClient * @param string $url=null [optional] * @return RestClient */ public static function createClient($url=null) { $client = new RestClient ; if($url != null) { $client->setUrl($url); } return $client; } /** * Convenience method wrapping a commom POST call * @param string $url * @param mixed params * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType="multpary/form-data" [optional] commom post (multipart/form-data) as default * @return RestClient */ public static function post($url,$params=null,$user=null,$pwd=null,$contentType="multipart/form-data") { return self::call("POST",$url,$params,$user,$pwd,$contentType); } /** * Convenience method wrapping a commom PUT call * @param string $url * @param string $body * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType=null [optional] * @return RestClient */ public static function put($url,$body,$user=null,$pwd=null,$contentType=null) { return self::call("PUT",$url,$body,$user,$pwd,$contentType); } /** * Convenience method wrapping a commom GET call * @param string $url * @param array params * @param string $user=null [optional] * @param string $password=null [optional] * @return RestClient */ public static function get($url,array $params=null,$user=null,$pwd=null) { return self::call("GET",$url,$params,$user,$pwd); } /** * Convenience method wrapping a commom delete call * @param string $url * @param array params * @param string $user=null [optional] * @param string $password=null [optional] * @return RestClient */ public static function delete($url,array $params=null,$user=null,$pwd=null) { return self::call("DELETE",$url,$params,$user,$pwd); } /** * Convenience method wrapping a commom custom call * @param string $method * @param string $url * @param string $body * @param string $user=null [optional] * @param string $password=null [optional] * @param string $contentType=null [optional] * @return RestClient */ public static function call($method,$url,$body,$user=null,$pwd=null,$contentType=null) { /* if($method == 'PUT') { echo '
';
     		var_dump($url);
     		echo '
'; echo '
';
     		var_dump($body);
     		echo '
'; } */ if($method == 'DELETE') { /* echo '
';
     		var_dump($url);
     		echo '
'; echo '
';
     		var_dump($body);
     		echo '
'; echo '
';
     		var_dump($method);
     		echo '
'; echo '
';
     		var_dump($contentType);
     		echo '

'; */ } return self::createClient($url) ->setParameters($body) ->setMethod($method) ->setCredentials($user,$pwd) ->setContentType($contentType) ->execute() ->close(); } } ?> _elements = array(); /* GA code */ $this->_elements['google_analytics'] = " "; /* Ads */ /* $this->_elements['ads_leaderbord'] = ''; $this->_elements['ads_imu'] = ' '; */ $this->_elements['ads_leaderbord'] = ''; $this->_elements['ads_imu'] = ''; $this->_elements['ads_imu2'] = ''; $rand = rand(0,4); //if($rand == 1) { if(1 == 1) { $this->_elements['ads_leaderbord'] = ' '; $this->_elements['ads_imu'] = ' '; $this->_elements['ads_imu2'] = ' '; } /* Advanced search */ /*
*/ $this->_elements['asearch'] = ''; /* boxsearch */ $this->_elements['boxsearch'] = ''; /* Background switcher */ $this->_elements['bgswitcher'] = '
'; /* Boxlabels - Menu */ //
/* Dranken */ /*Recepten */ $this->_elements['boxlabels'] = ''; $this->_elements['boxlabels_restaurants'] = ''; $this->_elements['boxlabels_recipes'] = ''; $this->_elements['boxlabels_drinks'] = ''; /* facebook meta tags */ $this->_elements['facebook_tags'] = ' '; /* feedback script */ $this->_elements['give_feedback'] = '
'; /* $this->_elements['boxEvents'] = '

Berichten

12-03-2011

Title van bericht

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

12-03-2011

Title van bericht

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

12-03-2011

Title van bericht

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

12-03-2011

Title van bericht

Lorem ipsum dolor sit amet, consectetur adipiscing elit.

';*/ $this->_elements['boxEvents'] = '
'; /*
*/ } public function display($key) { if(array_key_exists($key, $this->_elements)){ return $this->_elements[$key]; } return; } /* * prepare Quick stats (index page, etc) * @return string */ public function displayQuickStats() { /* get index stats */ SousChefCache::init(600); if (!(SousChefCache::test('quickstats'))) { try { $api = new SousChefAPI(); $api->setMethod('site/quick-stats'); $api->setState('get'); //$api->setParams(); $stats = $api->call(); if($stats->code == 2) { $quickstats = $stats->data; SousChefCache::save($quickstats, 'quickstats'); } } catch (Exception $ex) { print($ex->getMessage()); } } else { $quickstats = SousChefCache::load('quickstats'); } /* * Zoek in meer dan ' .number_format($quickstats->recipes, 0, '.', ' '). ' recepten, ' .number_format($quickstats->restaurants, 0, '.', ' '). ' eetadresjes en deel je ervaring met ' .number_format($quickstats->users, 0, '.', ' '). ' souschefs!! */ $output = '

het social food platform, waar je werkelijk alles vindt over gezond en lekker eten.

» uitgebreid zoeken
'; return $output; } /* * prepare Website block footer (social stats) * @return string */ public function displayBlockFooter() { // what feed? $whatfeed = (LOGGED_IN) ? 'mysouschef' : 'souschef'; $recres_cache_id = (LOGGED_IN) ? 'footer_recommended_restaurants_' .USER_ID : 'footer_recommended_restaurants'; $recfoo_cache_id = (LOGGED_IN) ? 'footer_recommended_food_' .USER_ID : 'footer_recommended_food'; // ---------------------------------------------------------------------------------------------------------------------------------- // GET DATA FROM API // ---------------------------------------------------------------------------------------------------------------------------------- /* get recommended restaurants */ SousChefCache::init(600); $recresbool = true; if (!(SousChefCache::test($recres_cache_id))) { /* DO AJAX */ $recommended_restaurants = ' '; $recresbool = false; } else { $recommended_restaurants = SousChefCache::load($recres_cache_id); } /* get recommended food */ SousChefCache::init(600); $recfoobool = true; if (!(SousChefCache::test($recfoo_cache_id))) { /* DO AJAX */ $recommended_food = ' '; $recfoobool = false; } else { $recommended_food = SousChefCache::load($recfoo_cache_id); } // ---------------------------------------------------------------------------------------------------------------------------------- // MAKE OUTPUT // ---------------------------------------------------------------------------------------------------------------------------------- //$output = ''; $output = '

Aanbevolen
door jouw netwerk

'; if($recresbool) { if(count($recommended_restaurants) > 0) { foreach($recommended_restaurants as $key=>$value) { // make facebook-like: Chris Schalenborgh en 4 anderen waren hier $hierwareno = ''; if(count($value->friends_here) > 0) { // add friends $friendscounter = 0; $hierwaren = array(); foreach($value->friends_here as $key2=>$value2) { $hierwaren[] = '' .$value2->name. ''; $friendscounter++; if($friendscounter == 3) break; } $whatsleft = ($value->total_users - $friendscounter); if(count($hierwaren) == 1) { $hierwareno = $hierwaren[0]. ' was hier'; } elseif(count($hierwaren) == 2 && $whatsleft == 0) { $hierwareno = implode(' en ', $hierwaren). ' waren hier'; } elseif($whatsleft == 1) { $hierwareno = implode(', ', $hierwaren). ' en 1 andere persoon waren hier'; } elseif($whatsleft > 0) { $hierwareno = implode(', ', $hierwaren). ' en ' .$whatsleft. ' anderen waren hier'; } else { $hierwareno = implode(', ', $hierwaren). ' waren hier'; } } elseif($value->total_unique_users == 1) { $hierwareno = '1 persoon was hier'; } else { $hierwareno = $value->total_unique_users. ' personen waren hier'; } // ' .$this->escape($value->restaurant->geo->street). ', ' .$this->escape($value->restaurant->geo->city->postal). ' ' .$this->escape($value->restaurant->geo->city->name). ', ' .$this->escape($value->restaurant->geo->city->province->country->code). ' $output .= '
' .$value->restaurant->name. '

' .$value->restaurant->name. '

' .$hierwareno. '

'; } } } else { $output .= $recommended_restaurants; } $output .= ' Meer populaire restaurants

Populaire
gerechten

'; if($recfoobool) { if(count($recommended_food) > 0) { foreach($recommended_food as $key=>$value) { // make facebook-like: Chris Schalenborgh en 4 anderen waren hier $hierwareno = ''; if(count($value->friends_here) > 0) { // add friends $friendscounter = 0; $hierwaren = array(); foreach($value->friends_here as $key2=>$value2) { $hierwaren[] = '' .$value2->name. ''; $friendscounter++; if($friendscounter == 3) break; } $whatsleft = ($value->total_users - $friendscounter); if(count($hierwaren) == 1) { $hierwareno = $hierwaren[0]. ' heeft dit gegeten'; } elseif(count($hierwaren) == 2 && $whatsleft == 0) { $hierwareno = implode(' en ', $hierwaren). ' hebben dit gegeten'; } elseif($whatsleft == 1) { $hierwareno = implode(', ', $hierwaren). ' en 1 andere persoon hebben dit gegeten'; } elseif($whatsleft > 0) { $hierwareno = implode(', ', $hierwaren). ' en ' .$whatsleft. ' anderen hebben dit gegeten'; } else { $hierwareno = implode(', ', $hierwaren). ' hebben dit gegeten'; } } elseif($value->total_unique_users == 1) { $hierwareno = '1 persoon heeft dit gegeten'; } else { $hierwareno = $value->total_unique_users. ' personen hebben dit gegeten'; } $output .= '
' .$value->recipe->name. '

' .$value->recipe->name. '

' .$hierwareno. '

'; } } } else { $output .= $recommended_food; } $output .= ' Meer populair eten
 
'; return $output; } }
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Session must be started before any output has been sent to the browser; output started in /home/souschef/domains/souschef.be/application/configs/RestClient.class.php/373' in /home/souschef/domains/souschef.be/library/Zend/Session.php:454 Stack trace: #0 /home/souschef/domains/souschef.be/public_html/index.php(44): Zend_Session::start() #1 {main} thrown in /home/souschef/domains/souschef.be/library/Zend/Session.php on line 454