Changeset 14384

Show
Ignore:
Timestamp:
01/12/08 13:35:59 (11 months ago)
Author:
bergie
Message:

PlazeCamp?: use the latest Plazes API

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/midcom/org.routamc.positioning/config/manifest.inc

    r14049 r14384  
    3737      'net.nemein.rss' =>  
    3838      array ( 
    39       ), 
    40       'XML_RPC' =>  
    41       array ( 
    42         'channel' => 'pear.php.net', 
    4339      ), 
    4440      'midcom' =>  
  • trunk/midcom/org.routamc.positioning/importer/georss.php

    r14329 r14384  
    3030    { 
    3131        // TODO: With 1.8 we can query parameters more efficiently 
    32         $qb = new MidgardQueryBuilder('midgard_parameter'); 
     32        $qb = new midgard_query_builder('midgard_parameter'); 
    3333        $qb->add_constraint('domain', '=','org.routamc.positioning:georss'); 
    3434        $qb->add_constraint('name', '=','georss_url'); 
  • trunk/midcom/org.routamc.positioning/importer/html.php

    r14329 r14384  
    3030    { 
    3131        // TODO: With 1.8 we can query parameters more efficiently 
    32         $qb = new MidgardQueryBuilder('midgard_parameter'); 
     32        $qb = new midgard_query_builder('midgard_parameter'); 
    3333        $qb->add_constraint('domain', '=','org.routamc.positioning:html'); 
    3434        $qb->add_constraint('name', '=','icbm_url'); 
  • trunk/midcom/org.routamc.positioning/importer/plazes.php

    r14329 r14384  
    55 * @version $Id$ 
    66 * @copyright The Midgard Project, http://www.midgard-project.org 
    7  * 
    8  * Based on PlazesWhereAmIPhp by 
    9  * @author Peter Rukavina <peter@rukavina.net> 
    10  * @author Olle Jonsson <olle@olleolleolle.dk> 
    11  * @copyright Reinvented Inc., 2005 
    12  * @license http://creativecommons.org/licenses/by-sa/2.0/ca 
    137 */ 
    148 
    15 /** @ignore */ 
    16 // PEAR XML_RPC package 
    17 require_once 'XML/RPC.php'; 
    18  
    199/** 
    20  * Importer for fetching position data for Plazes users 
     10 * Importer for fetching position and activity data for Plazes users 
    2111 * 
    2212 * @package org.routamc.positioning 
     
    4030    { 
    4131        // TODO: With 1.8 we can query parameters more efficiently 
    42         $qb = new MidgardQueryBuilder('midgard_parameter'); 
     32        $qb = new midgard_query_builder('midgard_parameter'); 
    4333        $qb->add_constraint('domain', '=','org.routamc.positioning:plazes'); 
    4434        $qb->add_constraint('name', '=','username'); 
     
    5343        } 
    5444    } 
    55  
    56     function _prepare_plazes_params($plazes_username, $plazes_password
     45     
     46    function _get_plazes_userid($user, $plazes_username, $plazes_password, $cache
    5747    { 
    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; 
    6966    } 
    7067 
    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) 
    12769    { 
    12870        $positions = array(); 
    12971 
    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)) 
    14377        { 
    144             $this->error = 'POSITIONING_PLAZES_CONNECTION_FAILED'; 
    14578            return null; 
    14679        } 
    14780 
    148         if (!$resp->faultCode()
     81        foreach ($simplexml->activity as $activity
    14982        { 
    150             $results = $resp->value(); 
    151  
    152             $trazes = @XML_RPC_decode($results); 
    153  
    154             // Quick-and-dirty timezone handling since Plazes doesn't return timezone information like they should 
    155             // http://wwp.greenwichmeantime.com/time-zone/rules/eu.htm 
    156             $month = (int) date('m'); 
    157             if (   $month < 4 
    158                 || $month > 10) 
     83            if (   !isset($activity->plaze) 
     84                || !isset($activity->plaze->latitude)) 
    15985            { 
    160                 // Plazes is in CET 
    161                 $timezone = '+0100'; 
    162             } 
    163             else 
    164             { 
    165                 // Plazes is in CEST 
    166                 $timezone = '+0200'; 
     86                // No location, skip 
     87                continue; 
    16788            } 
    16889 
    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            ); 
    19099        } 
    191         else 
    192         { 
    193             $this->error = 'POSITIONING_PLAZES_FAULT_' . $resp->faultCode(); 
    194             $this->error_string = $resp->faultString(); 
    195             return null; 
    196         } 
     100 
     101        return $positions; 
    197102    } 
    198103 
     
    206111    function get_plazes_location($user, $cache = true) 
    207112    { 
    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        }*/ 
    210122 
    211123        if (   $plazes_username