} else {
     $content_search = $connection->get("search/tweets", array("q" => $config['twitter_hashtag_search'], "result_type" => "recent", "count" => "10"));
 }
 foreach ($content_search->statuses as $elem_search) {
     $id_tweet = $elem_search->id_str;
     $lastId = $id_tweet;
     // https://dev.twitter.com/overview/api/users
     $nome = $elem_search->user->name;
     $nick = $elem_search->user->screen_name;
     $profile_image_url = $elem_search->user->profile_image_url;
     $testo_tweet = $elem_search->text;
     if (isset($elem_search->retweeted_status)) {
         $testo_tweet = 'RT: ' . $elem_search->retweeted_status->text;
     }
     if (isset($elem_search->coordinates)) {
         $point = \GeoJson\GeoJson::jsonUnserialize($elem_search->coordinates);
     }
     // Entites https://dev.twitter.com/overview/api/entities
     $hashtags = [];
     foreach ($elem_search->entities->hashtags as $ht) {
         // lo # non c'e' se serve va messo
         $hashtags[] = $ht->text;
     }
     $ann = Annotation::on($connection_name)->where('sourceId', $id_tweet)->get();
     if ($ann->count() == 0) {
         $annotation = new Annotation(array('author' => $nick, 'source' => Source::TWITTER, 'sourceId' => $id_tweet, 'text' => $testo_tweet, 'textHtml' => parseTweet($testo_tweet), 'hashtags' => $hashtags));
         $annotation->setConnection($connection_name);
         $annotation->save();
         $result = Parser::parse($testo_tweet);
         if ($result != false) {
             $evaluation = new Evaluation(array('annotation_id' => $annotation->id, 'sessione' => $result->sessione, 'evento' => $result->evento, 'punteggio' => $result->punteggio));
Exemplo n.º 2
0
    /**
     * @dataProvider provideJsonDecodeAssocOptions
     * @group functional
     */
    public function testUnserialization($assoc)
    {
        $json = <<<'JSON'
{
    "type": "Feature",
    "id": "test.feature.1",
    "properties": {
        "key": "value"
    },
    "geometry": {
        "type": "Point",
        "coordinates": [1, 1]
    }
}
JSON;
        $json = json_decode($json, $assoc);
        $feature = GeoJson::jsonUnserialize($json);
        $this->assertInstanceOf('GeoJson\\Feature\\Feature', $feature);
        $this->assertSame('Feature', $feature->getType());
        $this->assertSame('test.feature.1', $feature->getId());
        $this->assertSame(array('key' => 'value'), $feature->getProperties());
        $geometry = $feature->getGeometry();
        $this->assertInstanceOf('GeoJson\\Geometry\\Point', $geometry);
        $this->assertSame('Point', $geometry->getType());
        $this->assertSame(array(1, 1), $geometry->getCoordinates());
    }
Exemplo n.º 3
0
    /**
     * @dataProvider provideJsonDecodeAssocOptions
     * @group functional
     */
    public function testUnserializationWithCrs($assoc)
    {
        $json = <<<'JSON'
{
    "type": "Point",
    "coordinates": [1, 1],
    "crs": {
        "type": "name",
        "properties": {
            "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
        }
    }
}
JSON;
        $json = json_decode($json, $assoc);
        $point = GeoJson::jsonUnserialize($json);
        $this->assertInstanceOf('GeoJson\\Geometry\\Point', $point);
        $this->assertSame('Point', $point->getType());
        $this->assertSame(array(1, 1), $point->getCoordinates());
        $crs = $point->getCrs();
        $expectedProperties = array('name' => 'urn:ogc:def:crs:OGC:1.3:CRS84');
        $this->assertInstanceOf('GeoJson\\CoordinateReferenceSystem\\Named', $crs);
        $this->assertSame('name', $crs->getType());
        $this->assertSame($expectedProperties, $crs->getProperties());
    }
Exemplo n.º 4
0
 /**
  * @see http://php.net/manual/en/jsonserializable.jsonserialize.php
  */
 public function jsonSerialize()
 {
     $json = parent::jsonSerialize();
     if (isset($this->coordinates)) {
         $json['coordinates'] = $this->coordinates;
     }
     return $json;
 }
Exemplo n.º 5
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     Validator::extend('geometry', function ($attribute, $value, $parameters, $validator) {
         $value = json_decode($value);
         try {
             $value = GeoJson::jsonUnserialize($value);
             return $value instanceof GeoJson;
         } catch (Exception $e) {
             return false;
         }
     });
 }
Exemplo n.º 6
0
 /**
  * @see http://php.net/manual/en/jsonserializable.jsonserialize.php
  */
 public function jsonSerialize()
 {
     $json = parent::jsonSerialize();
     $json['geometry'] = isset($this->geometry) ? $this->geometry->jsonSerialize() : null;
     $json['properties'] = isset($this->properties) ? $this->properties : null;
     // Ensure empty associative arrays are encoded as JSON objects
     if ($json['properties'] === array()) {
         $json['properties'] = new \stdClass();
     }
     if (isset($this->id)) {
         $json['id'] = $this->id;
     }
     return $json;
 }
Exemplo n.º 7
0
    /**
     * @dataProvider provideJsonDecodeAssocOptions
     * @group functional
     */
    public function testUnserialization($assoc)
    {
        $json = <<<'JSON'
{
    "type": "Point",
    "coordinates": [1, 1]
}
JSON;
        $json = json_decode($json, $assoc);
        $point = GeoJson::jsonUnserialize($json);
        $this->assertInstanceOf('GeoJson\\Geometry\\Point', $point);
        $this->assertSame('Point', $point->getType());
        $this->assertSame(array(1, 1), $point->getCoordinates());
    }
Exemplo n.º 8
0
    /**
     * @dataProvider provideJsonDecodeAssocOptions
     * @group functional
     */
    public function testUnserialization($assoc)
    {
        $json = <<<'JSON'
{
    "type": "MultiPoint",
    "coordinates": [
        [1, 1],
        [2, 2]
    ]
}
JSON;
        $json = json_decode($json, $assoc);
        $multiPoint = GeoJson::jsonUnserialize($json);
        $expectedCoordinates = array(array(1, 1), array(2, 2));
        $this->assertInstanceOf('GeoJson\\Geometry\\MultiPoint', $multiPoint);
        $this->assertSame('MultiPoint', $multiPoint->getType());
        $this->assertSame($expectedCoordinates, $multiPoint->getCoordinates());
    }
    /**
     * @dataProvider provideJsonDecodeAssocOptions
     * @group functional
     */
    public function testUnserialization($assoc)
    {
        $json = <<<'JSON'
{
    "type": "MultiLineString",
    "coordinates": [
        [ [1, 1], [2, 2] ],
        [ [3, 3], [4, 4] ]
    ]
}
JSON;
        $json = json_decode($json, $assoc);
        $multiLineString = GeoJson::jsonUnserialize($json);
        $expectedCoordinates = array(array(array(1, 1), array(2, 2)), array(array(3, 3), array(4, 4)));
        $this->assertInstanceOf('GeoJson\\Geometry\\MultiLineString', $multiLineString);
        $this->assertSame('MultiLineString', $multiLineString->getType());
        $this->assertSame($expectedCoordinates, $multiLineString->getCoordinates());
    }
Exemplo n.º 10
0
    /**
     * @dataProvider provideJsonDecodeAssocOptions
     * @group functional
     */
    public function testUnserialization($assoc)
    {
        $json = <<<'JSON'
{
    "type": "MultiPolygon",
    "coordinates": [
        [ [ [0, 0], [0, 4], [4, 4], [4, 0], [0, 0] ] ],
        [ [ [1, 1], [1, 3], [3, 3], [3, 1], [1, 1] ] ]
    ]
}
JSON;
        $json = json_decode($json, $assoc);
        $multiPolygon = GeoJson::jsonUnserialize($json);
        $expectedCoordinates = array(array(array(array(0, 0), array(0, 4), array(4, 4), array(4, 0), array(0, 0))), array(array(array(1, 1), array(1, 3), array(3, 3), array(3, 1), array(1, 1))));
        $this->assertInstanceOf('GeoJson\\Geometry\\MultiPolygon', $multiPolygon);
        $this->assertSame('MultiPolygon', $multiPolygon->getType());
        $this->assertSame($expectedCoordinates, $multiPolygon->getCoordinates());
    }
 /**
  * @expectedException GeoJson\Exception\UnserializationException
  * @expectedExceptionMessage GeometryCollection expected "geometries" property of type array
  */
 public function testUnserializationShouldRequireGeometriesArray()
 {
     GeoJson::jsonUnserialize(array('type' => 'GeometryCollection', 'geometries' => null));
 }
Exemplo n.º 12
0
 protected function fromGeometry($geometry)
 {
     if ($geometry instanceof Geometry) {
         $extractor = new Extractor();
         $generator = new WKTGenerator($extractor);
         return $generator->generate($geometry);
     } elseif (is_string($geometry)) {
         if (json_decode($geometry)) {
             $geometry = json_decode($geometry);
             $geometry = GeoJson::jsonUnserialize($geometry);
             if ($geometry instanceof Feature) {
                 $geometry = $geometry->getGeometry();
             } elseif ($geometry instanceof FeatureCollection) {
                 $geometries = [];
                 foreach ($geometry->getFeatures() as $feature) {
                     $geometries[] = $feature->getGeometry();
                 }
                 return $this->fromGeometry(new GeometryCollection($geometries));
             }
             if ($geometry instanceof Geometry) {
                 return $this->fromGeometry($geometry);
             }
         }
         try {
             if ($this->toGeometry($geometry)) {
                 return $geometry;
             }
         } catch (Exception $e) {
         }
     }
     return 'POINT(0 0)';
 }
 /**
  * @expectedException GeoJson\Exception\UnserializationException
  * @expectedExceptionMessage FeatureCollection expected "features" property of type array
  */
 public function testUnserializationShouldRequireFeaturesArray()
 {
     GeoJson::jsonUnserialize(array('type' => 'FeatureCollection', 'features' => null));
 }
Exemplo n.º 14
0
/**
 * @param $content_search
 * @See https://dev.twitter.com/rest/reference/get/search/tweets
 */
function analyzeSearch($content_search)
{
    $lastId = '0';
    foreach ($content_search->statuses as $elem_search) {
        // https://dev.twitter.com/overview/api/tweets
        //metadata
        //created_at
        //id
        //id_str
        //text
        //source
        //truncated
        //in_reply_to_status_id
        //in_reply_to_status_id_str
        //in_reply_to_user_id
        //in_reply_to_user_id_str
        //in_reply_to_screen_name
        //user
        //geo
        //coordinates
        //place
        //contributors
        //is_quote_status
        //retweet_count
        //favorite_count
        //entities
        //favorited
        //retweeted
        //possibly_sensitive
        //lang
        $id_tweet = $elem_search->id_str;
        $lastId = $id_tweet;
        // https://dev.twitter.com/overview/api/users
        $nome = $elem_search->user->name;
        $nick = $elem_search->user->screen_name;
        $profile_image_url = $elem_search->user->profile_image_url;
        $testo_tweet = $elem_search->text;
        if (isset($elem_search->retweeted_status)) {
            // caso retweet
            $testo_tweet = 'RT: ' . $elem_search->retweeted_status->text;
        }
        //$coordinates = $elem_search->coordinates;
        // or full:
        //$place_name = $elem_search->place->name;
        if (isset($elem_search->coordinates)) {
            $point = \GeoJson\GeoJson::jsonUnserialize($elem_search->coordinates);
        }
        // Entites https://dev.twitter.com/overview/api/entities
        $hashtags = [];
        foreach ($elem_search->entities->hashtags as $ht) {
            // lo # non c'e' se serve va messo
            $hashtags[] = $ht->text;
        }
        $resources = [];
        $imageCount = 0;
        if (isset($elem_search->entities->media)) {
            foreach ($elem_search->entities->media as $media) {
                $imageCount++;
                $resources[] = $media->media_url;
                $dataImg = file_get_contents($media->media_url);
                $filename = basename($media->media_url);
                //"http://pbs.twimg.com/media/CPbPvS6UkAE7dYw.jpg",
                if ('' == trim($filename)) {
                    $url = $media->expanded_url;
                    $parts = parse_url($url);
                    // /Nonsprecare/status/645894353769111552/photo/1
                    echo $parts['path'];
                    $str = explode('/', $parts['path']);
                    $filename = $str[4];
                }
                // fixme: dove le salvo??
                file_put_contents($id_tweet . $imageCount . $filename, $dataImg);
            }
        }
        if (isset($elem_search->entities->urls)) {
            foreach ($elem_search->entities->urls as $url) {
                $resources[] = $url->expanded_url;
            }
        }
        $sizeResources = count($resources);
        echo "{$id_tweet} - {$testo_tweet} - [ {$sizeResources} / {$imageCount} ]\n";
        //    print_r($elem_search->contributors);
        //    print_r($elem_search->entities);
        //    break;
    }
    return $lastId;
}
Exemplo n.º 15
-1
 /**
  * @see http://php.net/manual/en/jsonserializable.jsonserialize.php
  */
 public function jsonSerialize()
 {
     return array_merge(parent::jsonSerialize(), array('features' => array_map(function (Feature $feature) {
         return $feature->jsonSerialize();
     }, $this->features)));
 }