* * @version 1.0 * @date 20 October 2010 * * Copyright (C)2010 MOVIM project * * See COPYING for licensing information. */ class ProfileData extends WidgetBase { function WidgetLoad() { $this->addjs('profiledata.js'); $this->registerEvent('locationpublished', 'onLocationPublished'); $this->registerEvent('locationpublisherror', 'onLocationPublishError'); } function ajaxLocationPublish($pos) { $pos = json_decode($pos); if($pos->place_id) { $geo = array( 'latitude' => (string)$pos->lat, 'longitude' => (string)$pos->lon, 'altitude' => (string)$pos->alt, 'country' => (string)$pos->address->country, 'countrycode' => (string)$pos->address->country_code, 'region' => (string)$pos->address->county, 'postalcode' => (string)$pos->address->postcode, 'locality' => (string)$pos->address->city, 'street' => (string)$pos->address->path, 'building' => (string)$pos->address->building, 'text' => (string)$pos->display_name, 'uri' => ''//'http://www.openstreetmap.org/'.urlencode('?lat='.(string)$pos->lat.'&lon='.(string)$pos->lon.'&zoom=10') ); $p = new moxl\LocationPublish(); $p->setTo($this->user->getLogin()) ->setGeo($geo) ->request(); } else { $html = '
'.t('Wrong position').'
'; RPC::call('movim_fill', 'maperror', RPC::cdata($html)); RPC::commit(); } } function onLocationPublished($me) { $html = $me->getPlace(); RPC::call('movim_fill', 'mapdata', RPC::cdata($html)); $html = '
'.t('Location updated').'
'; RPC::call('movim_fill', 'maperror', RPC::cdata($html)); RPC::call('movim_delete', 'mapdiv'); RPC::commit(); } function onLocationPublishError($error) { $html = '
'.$error.'
'; RPC::call('movim_fill', 'maperror', RPC::cdata($html)); RPC::call('movim_delete', 'mapdiv'); RPC::call('movim_delete', 'mapdata'); RPC::commit(); } function prepareProfileData() { $submit = $this->genCallAjax('ajaxLocationPublish', "getMyPositionData()"); $query = Contact::query() ->select() ->where( array('jid' => $this->user->getLogin()) ); $c = Contact::run_query($query); if($c) { $c = $c[0]; $data = $c->getPlace(); } else { $data = ''; } $html = ''; $html .= '

'.t('Location').'

'.$data.'
'. t('Update my position').'
'; return $html; } function build() { echo $this->prepareProfileData(); } }