| 58 | | $plazes_password_md5 = md5("PLAZES{$plazes_password}"); |
|---|
| 59 | | |
|---|
| 60 | | // These are the required XML-RPC parameters |
|---|
| 61 | | $params = array |
|---|
| 62 | | ( |
|---|
| 63 | | new XML_RPC_Value($this->_config->get('plazes_developer_key'), 'string'), |
|---|
| 64 | | new XML_RPC_Value($plazes_username, 'string'), |
|---|
| 65 | | new XML_RPC_Value($plazes_password_md5, 'string') |
|---|
| 66 | | ); |
|---|
| 67 | | |
|---|
| 68 | | return $params; |
|---|
| | 48 | $client = new org_openpsa_httplib(); |
|---|
| | 49 | $xml = $client->get('http://plazes.com/me.xml', 'User-agent: device: midgard', $plazes_username, $plazes_password); |
|---|
| | 50 | |
|---|
| | 51 | $simplexml = simplexml_load_string($xml); |
|---|
| | 52 | |
|---|
| | 53 | if (!isset($simplexml->id)) |
|---|
| | 54 | { |
|---|
| | 55 | return null; |
|---|
| | 56 | } |
|---|
| | 57 | |
|---|
| | 58 | $user_id = (int) $simplexml->id; |
|---|
| | 59 | |
|---|
| | 60 | if ($cache) |
|---|
| | 61 | { |
|---|
| | 62 | $user->set_parameter('org.routamc.positioning:plazes', 'user_id', $user_id); |
|---|
| | 63 | } |
|---|
| | 64 | |
|---|
| | 65 | return $user_id; |
|---|
| 71 | | function _parse_w3cdtf($date_str) |
|---|
| 72 | | { |
|---|
| 73 | | |
|---|
| 74 | | # regex to match wc3dtf |
|---|
| 75 | | $pat = "/(\d{4})(\d{2})(\d{2})T(\d{2}):(\d{2}):((\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))/"; |
|---|
| 76 | | |
|---|
| 77 | | if ( preg_match( $pat, $date_str, $match ) ) |
|---|
| 78 | | { |
|---|
| 79 | | list( $year, $month, $day, $hours, $minutes, $seconds) = |
|---|
| 80 | | array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[6]); |
|---|
| 81 | | |
|---|
| 82 | | # calc epoch for current date assuming GMT |
|---|
| 83 | | $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); |
|---|
| 84 | | |
|---|
| 85 | | $offset = 0; |
|---|
| 86 | | if ( $match[10] == 'Z' ) |
|---|
| 87 | | { |
|---|
| 88 | | # zulu time, aka GMT |
|---|
| 89 | | } |
|---|
| 90 | | else |
|---|
| 91 | | { |
|---|
| 92 | | $tz_mod = $match[8]; |
|---|
| 93 | | $tz_hour = $match[9]; |
|---|
| 94 | | $tz_min = $match[10]; |
|---|
| 95 | | |
|---|
| 96 | | # zero out the variables |
|---|
| 97 | | if (!$tz_hour) |
|---|
| 98 | | { |
|---|
| 99 | | $tz_hour = 0; |
|---|
| 100 | | } |
|---|
| 101 | | if (!$tz_min) |
|---|
| 102 | | { |
|---|
| 103 | | $tz_min = 0; |
|---|
| 104 | | } |
|---|
| 105 | | |
|---|
| 106 | | $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|---|
| 107 | | |
|---|
| 108 | | # is timezone ahead of GMT? then subtract offset |
|---|
| 109 | | # |
|---|
| 110 | | if ( $tz_mod == '+' ) |
|---|
| 111 | | { |
|---|
| 112 | | $offset_secs = $offset_secs * -1; |
|---|
| 113 | | } |
|---|
| 114 | | |
|---|
| 115 | | $offset = $offset_secs; |
|---|
| 116 | | } |
|---|
| 117 | | $epoch = $epoch + $offset; |
|---|
| 118 | | return $epoch; |
|---|
| 119 | | } |
|---|
| 120 | | else |
|---|
| 121 | | { |
|---|
| 122 | | return -1; |
|---|
| 123 | | } |
|---|
| 124 | | } |
|---|
| 125 | | |
|---|
| 126 | | function _fetch_plazes_positions($plazes_username, $plazes_password, $days = 0) |
|---|
| | 68 | function _fetch_plazes_positions($plazes_username, $plazes_password) |
|---|
| 130 | | $params = $this->_prepare_plazes_params($plazes_username, $plazes_password); |
|---|
| 131 | | $params[] = new XML_RPC_Value($days, 'int'); |
|---|
| 132 | | |
|---|
| 133 | | // Name of the XML-RPC method to be called |
|---|
| 134 | | $msg = new XML_RPC_Message('user.trazes', $params); |
|---|
| 135 | | |
|---|
| 136 | | // URI of the XML-RPC stub |
|---|
| 137 | | $cli = new XML_RPC_Client('/api/plazes/xmlrpc', 'http://beta.plazes.com'); |
|---|
| 138 | | $resp = @$cli->send($msg); |
|---|
| 139 | | |
|---|
| 140 | | if ( !$resp |
|---|
| 141 | | || !is_object($resp) |
|---|
| 142 | | || !method_exists($resp, 'faultCode')) |
|---|
| | 72 | $client = new org_openpsa_httplib(); |
|---|
| | 73 | $xml = $client->get("http://plazes.com/users/{$plazes_username}/past_activities.xml", 'User-agent: device: midgard', $plazes_username, $plazes_password); |
|---|
| | 74 | $simplexml = simplexml_load_string($xml); |
|---|
| | 75 | |
|---|
| | 76 | if (!isset($simplexml->activity)) |
|---|
| 169 | | if (count($trazes) > 0) |
|---|
| 170 | | { |
|---|
| 171 | | foreach ($trazes as $traze) |
|---|
| 172 | | { |
|---|
| 173 | | @$positions[] = array |
|---|
| 174 | | ( |
|---|
| 175 | | 'plaze' => $traze['plaze']['key'], |
|---|
| 176 | | 'latitude' => $traze['plaze']['latitude'], |
|---|
| 177 | | 'longitude' => $traze['plaze']['longitude'], |
|---|
| 178 | | 'country' => $traze['plaze']['country'], |
|---|
| 179 | | 'city' => $traze['plaze']['city'], |
|---|
| 180 | | 'date' => $this->_parse_w3cdtf("{$traze['start']}{$timezone}"), |
|---|
| 181 | | ); |
|---|
| 182 | | } |
|---|
| 183 | | return $positions; |
|---|
| 184 | | } |
|---|
| 185 | | else |
|---|
| 186 | | { |
|---|
| 187 | | $this->error = 'POSITIONING_PLAZES_CONNECTION_NORESULTS'; |
|---|
| 188 | | return null; |
|---|
| 189 | | } |
|---|
| | 90 | $positions[] = array |
|---|
| | 91 | ( |
|---|
| | 92 | 'plaze' => (int) $activity->plaze->id, |
|---|
| | 93 | 'latitude' => (float) $activity->plaze->latitude, |
|---|
| | 94 | 'longitude' => (float) $activity->plaze->longitude, |
|---|
| | 95 | 'country' => (string) $activity->plaze->country_code, |
|---|
| | 96 | 'city' => (string) $activity->plaze->city, |
|---|
| | 97 | 'date' => strtotime((string) $activity->scheduled_at), |
|---|
| | 98 | ); |
|---|
| 208 | | $plazes_username = $user->parameter('org.routamc.positioning:plazes', 'username'); |
|---|
| 209 | | $plazes_password = $user->parameter('org.routamc.positioning:plazes', 'password'); |
|---|
| | 113 | $plazes_username = $user->get_parameter('org.routamc.positioning:plazes', 'username'); |
|---|
| | 114 | $plazes_password = $user->get_parameter('org.routamc.positioning:plazes', 'password'); |
|---|
| | 115 | |
|---|
| | 116 | /* |
|---|
| | 117 | $plazes_userid = $user->get_parameter('org.routamc.positioning:plazes', 'user_id'); |
|---|
| | 118 | if (!$plazes_userid) |
|---|
| | 119 | { |
|---|
| | 120 | $plazes_userid = $this->_get_plazes_userid($user, $plazes_username, $plazes_password, $cache); |
|---|
| | 121 | }*/ |
|---|