Beispiel #1
0
 function prepare($args)
 {
     parent::prepare($args);
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->clientError(_('There was a problem with your session token. ' . 'Try again, please.'));
     }
     $this->lat = $this->trimmed('lat');
     $this->lon = $this->trimmed('lon');
     $this->location = Location::fromLatLon($this->lat, $this->lon);
     return true;
 }
Beispiel #2
0
 function prepare($args)
 {
     parent::prepare($args);
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. ' . 'Try again, please.'));
     }
     $this->lat = $this->trimmed('lat');
     $this->lon = $this->trimmed('lon');
     $this->location = Location::fromLatLon($this->lat, $this->lon);
     return true;
 }
Beispiel #3
0
 function prepare($args)
 {
     parent::prepare($args);
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->clientError(_('网页错误,请返回重试
                              '));
     }
     $this->lat = $this->trimmed('lat');
     $this->lon = $this->trimmed('lon');
     $this->location = Location::fromLatLon($this->lat, $this->lon);
     return true;
 }
 public function asLocation()
 {
     $location = null;
     if (!empty($this->location_id) && !empty($this->location_ns)) {
         $location = Location::fromId($this->location_id, $this->location_ns);
     }
     if (is_null($location)) {
         // no ID, or Location::fromId() failed
         $location = Location::fromLatLon($this->lat, $this->lon);
     }
     if (is_null($location)) {
         throw new ServerException('Location could not be looked up from existing data.');
     }
     return $location;
 }
Beispiel #5
0
 static function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null)
 {
     $options = array();
     if (!empty($location_id) && !empty($location_ns)) {
         $options['location_id'] = $location_id;
         $options['location_ns'] = $location_ns;
         $location = Location::fromId($location_id, $location_ns);
         if ($location instanceof Location) {
             $options['lat'] = $location->lat;
             $options['lon'] = $location->lon;
         }
     } else {
         if (!empty($lat) && !empty($lon)) {
             $options['lat'] = $lat;
             $options['lon'] = $lon;
             $location = Location::fromLatLon($lat, $lon);
             if ($location instanceof Location) {
                 $options['location_id'] = $location->location_id;
                 $options['location_ns'] = $location->location_ns;
             }
         } else {
             if (!empty($profile)) {
                 if (isset($profile->lat) && isset($profile->lon)) {
                     $options['lat'] = $profile->lat;
                     $options['lon'] = $profile->lon;
                 }
                 if (isset($profile->location_id) && isset($profile->location_ns)) {
                     $options['location_id'] = $profile->location_id;
                     $options['location_ns'] = $profile->location_ns;
                 }
             }
         }
     }
     return $options;
 }
 function asArray()
 {
     $object = array();
     if (Event::handle('StartActivityObjectOutputJson', array($this, &$object))) {
         // XXX: attachments are added by Activity
         // author (Add object for author? Could be useful for repeats.)
         // content (Add rendered version of the notice?)
         // downstreamDuplicates
         // id
         if ($this->id) {
             $object['id'] = $this->id;
         } else {
             if ($this->link) {
                 $object['id'] = $this->link;
             }
         }
         if ($this->type == ActivityObject::PERSON || $this->type == ActivityObject::GROUP) {
             // displayName
             $object['displayName'] = $this->title;
             // XXX: Not sure what the best avatar is to use for the
             // author's "image". For now, I'm using the large size.
             $imgLink = null;
             $avatarMediaLinks = array();
             foreach ($this->avatarLinks as $a) {
                 // Make a MediaLink for every other Avatar
                 $avatar = new ActivityStreamsMediaLink($a->url, $a->width, $a->height, $a->type, 'avatar');
                 // Find the big avatar to use as the "image"
                 if ($a->height == AVATAR_PROFILE_SIZE) {
                     $imgLink = $avatar;
                 }
                 $avatarMediaLinks[] = $avatar->asArray();
             }
             if (!array_key_exists('status_net', $object)) {
                 $object['status_net'] = array();
             }
             $object['status_net']['avatarLinks'] = $avatarMediaLinks;
             // extension
             // image
             if (!empty($imgLink)) {
                 $object['image'] = $imgLink->asArray();
             }
         }
         // objectType
         //
         // We can probably use the whole schema URL here but probably the
         // relative simple name is easier to parse
         $object['objectType'] = self::canonicalType($this->type);
         // summary
         $object['summary'] = $this->summary;
         // content, usually rendered HTML
         $object['content'] = $this->content;
         // published (probably don't need. Might be useful for repeats.)
         // updated (probably don't need this)
         // TODO: upstreamDuplicates
         if ($this->link) {
             $object['url'] = $this->link;
         }
         /* Extensions */
         // @fixme these may collide with XML extensions
         // @fixme multiple tags of same name will overwrite each other
         // @fixme text content from XML extensions will be lost
         foreach ($this->extra as $e) {
             list($objectName, $props, $txt) = array_pad($e, 3, null);
             if (!empty($objectName)) {
                 $parts = explode(":", $objectName);
                 if (count($parts) == 2 && $parts[0] == "statusnet") {
                     if (!array_key_exists('status_net', $object)) {
                         $object['status_net'] = array();
                     }
                     $object['status_net'][$parts[1]] = $props;
                 } else {
                     $object[$objectName] = $props;
                 }
             }
         }
         if (!empty($this->geopoint)) {
             list($lat, $lon) = explode(' ', $this->geopoint);
             if (!empty($lat) && !empty($lon)) {
                 $object['location'] = array('objectType' => 'place', 'position' => sprintf("%+02.5F%+03.5F/", $lat, $lon), 'lat' => $lat, 'lon' => $lon);
                 $loc = Location::fromLatLon((double) $lat, (double) $lon);
                 if ($loc) {
                     $name = $loc->getName();
                     if ($name) {
                         $object['location']['displayName'] = $name;
                     }
                     $url = $loc->getURL();
                     if ($url) {
                         $object['location']['url'] = $url;
                     }
                 }
             }
         }
         if (!empty($this->poco)) {
             $object['portablecontacts_net'] = array_filter($this->poco->asArray());
         }
         if (!empty($this->thumbnail)) {
             if (is_string($this->thumbnail)) {
                 $object['image'] = array('url' => $this->thumbnail);
             } else {
                 $object['image'] = array('url' => $this->thumbnail->getUrl());
                 if ($this->thumbnail->width) {
                     $object['image']['width'] = $this->thumbnail->width;
                 }
                 if ($this->thumbnail->height) {
                     $object['image']['height'] = $this->thumbnail->height;
                 }
             }
         }
         switch (self::canonicalType($this->type)) {
             case 'image':
                 if (!empty($this->largerImage)) {
                     $object['fullImage'] = array('url' => $this->largerImage);
                 }
                 break;
             case 'audio':
             case 'video':
                 if (!empty($this->stream)) {
                     $object['stream'] = array('url' => $this->stream);
                 }
                 break;
         }
         Event::handle('EndActivityObjectOutputJson', array($this, &$object));
     }
     return array_filter($object);
 }
 static function locationFromPoint($point)
 {
     $point = str_replace(',', ' ', $point);
     // per spec "treat commas as whitespace"
     $point = preg_replace('/\\s+/', ' ', $point);
     $point = trim($point);
     $coords = explode(' ', $point);
     if (count($coords) == 2) {
         list($lat, $lon) = $coords;
         if (is_numeric($lat) && is_numeric($lon)) {
             common_log(LOG_INFO, "Looking up location for {$lat} {$lon} from georss point");
             return Location::fromLatLon($lat, $lon);
         }
     }
     common_log(LOG_ERR, "Ignoring bogus georss:point value {$point}");
     return null;
 }
 /**
  * @dataProvider locationLatLons
  */
 public function testLocationFromLatLon($lat, $lon, $language, $location)
 {
     $result = Location::fromLatLon($lat, $lon, $language);
     $this->assertEquals($result, $location);
 }
Beispiel #9
0
 function getLocation()
 {
     $location = null;
     if (!empty($this->location_id) && !empty($this->location_ns)) {
         $location = Location::fromId($this->location_id, $this->location_ns);
     }
     if (is_null($location)) {
         // no ID, or Location::fromId() failed
         if (!empty($this->lat) && !empty($this->lon)) {
             $location = Location::fromLatLon($this->lat, $this->lon);
         }
     }
     if (is_null($location)) {
         // still haven't found it!
         if (!empty($this->location)) {
             $location = Location::fromName($this->location);
         }
     }
     return $location;
 }