username = $username; if($user_id){ $this->user_id = $user_id; }else{ //$this->get_user_id(); } } /***/ private function get_page_contents($urlofpage){ $options = array( CURLOPT_URL => $urlofpage, CURLOPT_RETURNTRANSFER => 1, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 10, CURLOPT_FAILONERROR => 1, CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/531.22.7 (KHTML, like Gecko) Version/4.0.5 Safari/531.22.7', ); $ch = curl_init(); curl_setopt_array($ch, $options); $response = curl_exec($ch); if (curl_errno($ch)) { $response = ''; } else { $responsecode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($responsecode != '200') { $response = ''; } } curl_close($ch); return $response; } private function retrieve_user_id(){ $page = $this->get_page_contents("http://sportstracker.nokia.com/nts/user/profile.do?u=" . $this->username); // extract the user id ereg('', $page, $matches); if(isset($matches[1])){ $this->user_id = $matches[1]; }else{ $this->user_id = null; $this->errors['user_id_error'] = "Unable to get User ID for usename: " . $this->username; } } /** * */ public function getErrors(){ return $this->errors; } /** * */ public function get_user_id(){ if(!$this->user_id){ $this->retrieve_user_id(); } return $this->user_id; } /** * */ public function get_username(){ return $this->username; } /** * gets the list of workouts and **/ function get_workouts($offset=0, $limit=99999999, $forceload=false){ if(!$this->workouts || $force){ if($id = $this->get_user_id()){ $data = json_decode($this->get_page_contents("http://sportstracker.nokia.com/nts/json/specificlatest.do?firstResult=" . $offset . "&maxResults=" . $limit."&orderBy=true&user_id=" . $id ."&ph=n"),true); $this->workouts = $data; }else{ // cannot get user id $this->errors['get_workouts_error'] = "Unable to get user workouts - (could not get user id)"; } }else{ // workouts allready loaded } return $this->workouts; } /** * */ function getRecentWorkoutSWFURL(){ return "http://sportstracker.nokia.com/nts/flash/summaryChart.swf?summaryServiceUrl=/nts/workoutgraph/summaryservice.do?id=" . $this->get_user_id() ."&localeChain=en_US"; } /** */ function getAvatarURL(){ return "http://sportstracker.nokia.com/nts/user/avatar.do?ph=n&u=" . $this->get_user_id() .""; } /** */ function getWorkoutGraph($workout_id){ return "http://sportstracker.nokia.com//nts/flash/workoutChart.swf?workoutServiceUrl=/nts/workoutgraph/workoutservice.do?id=" . $workout_id."&heartRateServiceUrl=/nts/workoutgraph/heartrateservice.do?id=" . workout_id."&localeChain=en_US"; } function getWorkoutURL($workout_id){ return "http://sportstracker.nokia.com/nts/workoutdetail/index.do?id=" . $workout_id; } } ?>