mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-15 22:13:13 +00:00
Update geoname server service provider
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
"sinon-chai": "~2.4",
|
"sinon-chai": "~2.4",
|
||||||
"js-fixtures": "https://github.com/badunk/js-fixtures/archive/master.zip",
|
"js-fixtures": "https://github.com/badunk/js-fixtures/archive/master.zip",
|
||||||
"bootstrap-multiselect": "https://github.com/davidstutz/bootstrap-multiselect.git",
|
"bootstrap-multiselect": "https://github.com/davidstutz/bootstrap-multiselect.git",
|
||||||
"zxcvbn" : "https://github.com/lowe/zxcvbn.git"
|
"zxcvbn" : "https://github.com/lowe/zxcvbn.git",
|
||||||
|
"geonames-server-jquery-plugin" : "~0.1.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
"facebook/php-sdk" : "~3.0",
|
"facebook/php-sdk" : "~3.0",
|
||||||
"gedmo/doctrine-extensions" : "~2.3.0",
|
"gedmo/doctrine-extensions" : "~2.3.0",
|
||||||
"alchemy/google-plus-api-client" : "~0.6.2",
|
"alchemy/google-plus-api-client" : "~0.6.2",
|
||||||
|
"alchemy/geonames-api-consumer" : "~0.1.0",
|
||||||
"guzzle/guzzle" : "~3.0",
|
"guzzle/guzzle" : "~3.0",
|
||||||
"neutron/imagine" : "dev-neutron-colorspace@dev",
|
"neutron/imagine" : "dev-neutron-colorspace@dev",
|
||||||
"jms/serializer" : "~0.10",
|
"jms/serializer" : "~0.10",
|
||||||
@@ -49,7 +50,7 @@
|
|||||||
"behat/mink-extension" : "~1.0",
|
"behat/mink-extension" : "~1.0",
|
||||||
"behat/mink-goutte-driver" : "~1.0",
|
"behat/mink-goutte-driver" : "~1.0",
|
||||||
"behat/mink-selenium2-driver" : "~1.0",
|
"behat/mink-selenium2-driver" : "~1.0",
|
||||||
"fabpot/goutte" : "~1.0"
|
"fabpot/goutte" : "1.0.x-dev@dev"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
|
84
composer.lock
generated
84
composer.lock
generated
@@ -3,7 +3,7 @@
|
|||||||
"This file locks the dependencies of your project to a known state",
|
"This file locks the dependencies of your project to a known state",
|
||||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file"
|
||||||
],
|
],
|
||||||
"hash": "65785e460cf13c19d95073151e68f967",
|
"hash": "a265177770eb277554b943a7e807eac1",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "alchemy/binary-driver",
|
"name": "alchemy/binary-driver",
|
||||||
@@ -62,6 +62,44 @@
|
|||||||
],
|
],
|
||||||
"time": "2013-06-21 15:51:20"
|
"time": "2013-06-21 15:51:20"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "alchemy/geonames-api-consumer",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/alchemy-fr/GeonamesServer-PHP-Plugin.git",
|
||||||
|
"reference": "0.1.1"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/alchemy-fr/GeonamesServer-PHP-Plugin/zipball/0.1.1",
|
||||||
|
"reference": "0.1.1",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"guzzle/guzzle": "~3.5",
|
||||||
|
"php": ">=5.3.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "~3.7",
|
||||||
|
"silex/silex": "~1.0"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"autoload": {
|
||||||
|
"psr-0": {
|
||||||
|
"Alchemy": "src/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"description": "A connector to a geonames server",
|
||||||
|
"keywords": [
|
||||||
|
"geonames"
|
||||||
|
],
|
||||||
|
"time": "2013-07-02 11:28:34"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "alchemy/ghostscript",
|
"name": "alchemy/ghostscript",
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
@@ -894,16 +932,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "guzzle/guzzle",
|
"name": "guzzle/guzzle",
|
||||||
"version": "v3.3.1",
|
"version": "v3.6.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/guzzle/guzzle.git",
|
"url": "https://github.com/guzzle/guzzle.git",
|
||||||
"reference": "v3.3.1"
|
"reference": "v3.6.0"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/v3.3.1",
|
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/v3.6.0",
|
||||||
"reference": "v3.3.1",
|
"reference": "v3.6.0",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -939,16 +977,15 @@
|
|||||||
"doctrine/cache": "*",
|
"doctrine/cache": "*",
|
||||||
"monolog/monolog": "1.*",
|
"monolog/monolog": "1.*",
|
||||||
"phpunit/phpunit": "3.7.*",
|
"phpunit/phpunit": "3.7.*",
|
||||||
|
"psr/log": "1.0.*",
|
||||||
"symfony/class-loader": "*",
|
"symfony/class-loader": "*",
|
||||||
"zend/zend-cache1": "1.12",
|
|
||||||
"zend/zend-log1": "1.12",
|
|
||||||
"zendframework/zend-cache": "2.0.*",
|
"zendframework/zend-cache": "2.0.*",
|
||||||
"zendframework/zend-log": "2.0.*"
|
"zendframework/zend-log": "2.0.*"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"extra": {
|
"extra": {
|
||||||
"branch-alias": {
|
"branch-alias": {
|
||||||
"dev-master": "3.3-dev"
|
"dev-master": "3.6-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@@ -983,7 +1020,7 @@
|
|||||||
"rest",
|
"rest",
|
||||||
"web service"
|
"web service"
|
||||||
],
|
],
|
||||||
"time": "2013-03-10 23:05:38"
|
"time": "2013-05-30 07:01:25"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "jms/metadata",
|
"name": "jms/metadata",
|
||||||
@@ -3292,27 +3329,31 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "fabpot/goutte",
|
"name": "fabpot/goutte",
|
||||||
"version": "v1.0.1",
|
"version": "dev-master",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/fabpot/Goutte.git",
|
"url": "https://github.com/fabpot/Goutte.git",
|
||||||
"reference": "v1.0.1"
|
"reference": "2f5104765152d51b501de452a83153ac0b1492df"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/fabpot/Goutte/zipball/v1.0.1",
|
"url": "https://api.github.com/repos/fabpot/Goutte/zipball/2f5104765152d51b501de452a83153ac0b1492df",
|
||||||
"reference": "v1.0.1",
|
"reference": "2f5104765152d51b501de452a83153ac0b1492df",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"ext-curl": "*",
|
"ext-curl": "*",
|
||||||
"guzzle/guzzle": ">=3.0, <3.4",
|
"guzzle/http": ">=3.0.5,<3.7-dev",
|
||||||
"php": ">=5.3.0",
|
"php": ">=5.3.0",
|
||||||
"symfony/browser-kit": ">=2.1,<3.0",
|
"symfony/browser-kit": "~2.1",
|
||||||
"symfony/css-selector": ">=2.1,<3.0",
|
"symfony/css-selector": "~2.1",
|
||||||
"symfony/dom-crawler": ">=2.1,<3.0",
|
"symfony/dom-crawler": "~2.1",
|
||||||
"symfony/finder": ">=2.1,<3.0",
|
"symfony/finder": "~2.1",
|
||||||
"symfony/process": ">=2.1,<3.0"
|
"symfony/process": "~2.1"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"guzzle/plugin-history": ">=3.0.5,<3.7-dev",
|
||||||
|
"guzzle/plugin-mock": ">=3.0.5,<3.7-dev"
|
||||||
},
|
},
|
||||||
"type": "application",
|
"type": "application",
|
||||||
"extra": {
|
"extra": {
|
||||||
@@ -3340,7 +3381,7 @@
|
|||||||
"keywords": [
|
"keywords": [
|
||||||
"scraper"
|
"scraper"
|
||||||
],
|
],
|
||||||
"time": "2013-03-08 08:00:58"
|
"time": "2013-07-02 07:48:02"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "instaclick/php-webdriver",
|
"name": "instaclick/php-webdriver",
|
||||||
@@ -3766,7 +3807,8 @@
|
|||||||
"media-alchemyst/media-alchemyst": 20,
|
"media-alchemyst/media-alchemyst": 20,
|
||||||
"php-ffmpeg/php-ffmpeg": 20,
|
"php-ffmpeg/php-ffmpeg": 20,
|
||||||
"mrclay/minify": 20,
|
"mrclay/minify": 20,
|
||||||
"doctrine/data-fixtures": 20
|
"doctrine/data-fixtures": 20,
|
||||||
|
"fabpot/goutte": 20
|
||||||
},
|
},
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": ">=5.3.3"
|
"php": ">=5.3.3"
|
||||||
|
@@ -85,7 +85,7 @@ use Alchemy\Phrasea\Core\Provider\ConfigurationServiceProvider;
|
|||||||
use Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\ConfigurationTesterServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\FileServeServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\FileServeServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\FtpServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\FtpServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider;
|
use Alchemy\Geonames\GeonamesServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\InstallerServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\InstallerServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\JMSSerializerServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\JMSSerializerServiceProvider;
|
||||||
use Alchemy\Phrasea\Core\Provider\LocaleServiceProvider;
|
use Alchemy\Phrasea\Core\Provider\LocaleServiceProvider;
|
||||||
@@ -204,6 +204,9 @@ class Application extends SilexApplication
|
|||||||
$this->register(new FilesystemServiceProvider());
|
$this->register(new FilesystemServiceProvider());
|
||||||
$this->register(new FtpServiceProvider());
|
$this->register(new FtpServiceProvider());
|
||||||
$this->register(new GeonamesServiceProvider());
|
$this->register(new GeonamesServiceProvider());
|
||||||
|
$this['geonames.server-uri'] = $this->share(function (Application $app) {
|
||||||
|
return $app['phraseanet.registry']->get('GV_i18n_service', 'http://geoloc.preprod.alchemyasp.com/');
|
||||||
|
});
|
||||||
|
|
||||||
$this->register(new MediaAlchemystServiceProvider());
|
$this->register(new MediaAlchemystServiceProvider());
|
||||||
$this['media-alchemyst.configuration'] = $this->share(function(Application $app) {
|
$this['media-alchemyst.configuration'] = $this->share(function(Application $app) {
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Controller\Admin;
|
namespace Alchemy\Phrasea\Controller\Admin;
|
||||||
|
|
||||||
|
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ControllerProviderInterface;
|
use Silex\ControllerProviderInterface;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@@ -44,6 +45,38 @@ class ConnectedUsers implements ControllerProviderInterface
|
|||||||
$query = $app['EM']->createQuery($dql);
|
$query = $app['EM']->createQuery($dql);
|
||||||
$sessions = $query->getResult();
|
$sessions = $query->getResult();
|
||||||
|
|
||||||
|
$result = array();
|
||||||
|
|
||||||
|
foreach ($sessions as $session) {
|
||||||
|
$info = '';
|
||||||
|
try {
|
||||||
|
$geoname = $app['geonames.connector']->ip($session->getIpAddress());
|
||||||
|
$country = $geoname->get('country');
|
||||||
|
$city = $geoname->get('city');
|
||||||
|
$region = $geoname->get('region');
|
||||||
|
|
||||||
|
$countryName = isset($country['name']) ? $country['name'] : null;
|
||||||
|
$regionName = isset($region['name']) ? $region['name'] : null;
|
||||||
|
|
||||||
|
if (null !== $city) {
|
||||||
|
$info = $city . ($countryName ? ' (' . $countryName . ')' : null);
|
||||||
|
} elseif (null !== $regionName) {
|
||||||
|
$info = $regionName . ($countryName ? ' (' . $countryName . ')' : null);
|
||||||
|
} elseif (null !== $countryName) {
|
||||||
|
$info = $countryName;
|
||||||
|
} else {
|
||||||
|
$info = '';
|
||||||
|
}
|
||||||
|
} catch (GeonamesExceptionInterface $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = array(
|
||||||
|
'session' => $session,
|
||||||
|
'info' => $info,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$ret = array(
|
$ret = array(
|
||||||
'sessions' => $sessions,
|
'sessions' => $sessions,
|
||||||
'applications' => array(
|
'applications' => array(
|
||||||
|
@@ -317,7 +317,7 @@ class Users implements ControllerProviderInterface
|
|||||||
, $user->get_address()
|
, $user->get_address()
|
||||||
, $user->get_city()
|
, $user->get_city()
|
||||||
, $user->get_zipcode()
|
, $user->get_zipcode()
|
||||||
, $app['geonames']->get_country($user->get_geonameid())
|
, $user->get_country()
|
||||||
, $user->get_tel()
|
, $user->get_tel()
|
||||||
, $user->get_fax()
|
, $user->get_fax()
|
||||||
, $user->get_job()
|
, $user->get_job()
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Controller\Root;
|
namespace Alchemy\Phrasea\Controller\Root;
|
||||||
|
|
||||||
|
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
|
||||||
use Alchemy\Phrasea\Application as PhraseaApplication;
|
use Alchemy\Phrasea\Application as PhraseaApplication;
|
||||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||||
use Alchemy\Phrasea\Notification\Receiver;
|
use Alchemy\Phrasea\Notification\Receiver;
|
||||||
@@ -276,7 +277,38 @@ class Account implements ControllerProviderInterface
|
|||||||
$query->setParameters(array('usr_id' => $app['session']->get('usr_id')));
|
$query->setParameters(array('usr_id' => $app['session']->get('usr_id')));
|
||||||
$sessions = $query->getResult();
|
$sessions = $query->getResult();
|
||||||
|
|
||||||
return $app['twig']->render('account/sessions.html.twig', array('sessions' => $sessions));
|
$result = array();
|
||||||
|
foreach ($sessions as $session) {
|
||||||
|
$info = '';
|
||||||
|
try {
|
||||||
|
$geoname = $app['geonames.connector']->ip($session->getIpAddress());
|
||||||
|
$country = $geoname->get('country');
|
||||||
|
$city = $geoname->get('city');
|
||||||
|
$region = $geoname->get('region');
|
||||||
|
|
||||||
|
$countryName = isset($country['name']) ? $country['name'] : null;
|
||||||
|
$regionName = isset($region['name']) ? $region['name'] : null;
|
||||||
|
|
||||||
|
if (null !== $city) {
|
||||||
|
$info = $city . ($countryName ? ' (' . $countryName . ')' : null);
|
||||||
|
} elseif (null !== $regionName) {
|
||||||
|
$info = $regionName . ($countryName ? ' (' . $countryName . ')' : null);
|
||||||
|
} elseif (null !== $countryName) {
|
||||||
|
$info = $countryName;
|
||||||
|
} else {
|
||||||
|
$info = '';
|
||||||
|
}
|
||||||
|
} catch (GeonamesExceptionInterface $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$result[] = array(
|
||||||
|
'session' => $session,
|
||||||
|
'info' => $info,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $app['twig']->render('account/sessions.html.twig', array('sessions' => $result));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,30 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
|
||||||
*
|
|
||||||
* (c) 2005-2013 Alchemy
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Provider;
|
|
||||||
|
|
||||||
use Silex\Application;
|
|
||||||
use Silex\ServiceProviderInterface;
|
|
||||||
|
|
||||||
class GeonamesServiceProvider implements ServiceProviderInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
public function register(Application $app)
|
|
||||||
{
|
|
||||||
$app['geonames'] = $app->share(function($app) {
|
|
||||||
return new \geonames($app);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public function boot(Application $app)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@@ -12,6 +12,7 @@
|
|||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
use Alchemy\Phrasea\Exception\SessionNotFound;
|
use Alchemy\Phrasea\Exception\SessionNotFound;
|
||||||
|
use Alchemy\Geonames\Exception\ExceptionInterface as GeonamesExceptionInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -521,7 +522,17 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
public function get_country()
|
public function get_country()
|
||||||
{
|
{
|
||||||
if ($this->geonameid) {
|
if ($this->geonameid) {
|
||||||
return $this->app['geonames']->get_country($this->geonameid);
|
try {
|
||||||
|
$country = $this->app['geonames.connector']
|
||||||
|
->geoname($this->geonameid)
|
||||||
|
->get('country');
|
||||||
|
|
||||||
|
if (isset($country['name'])) {
|
||||||
|
return $country['name'];
|
||||||
|
}
|
||||||
|
} catch (GeonamesExceptionInterface $e) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
@@ -751,7 +762,20 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
|
|
||||||
public function set_geonameid($geonameid)
|
public function set_geonameid($geonameid)
|
||||||
{
|
{
|
||||||
$country_code = $this->app['geonames']->get_country_code($geonameid);
|
$country_code = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$country = $this->app['geonames.connector']
|
||||||
|
->geoname($this->geonameid)
|
||||||
|
->get('country');
|
||||||
|
|
||||||
|
if (isset($country['code'])) {
|
||||||
|
$country_code = $country['code'];
|
||||||
|
}
|
||||||
|
} catch (GeonamesExceptionInterface $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$sql = 'UPDATE usr SET geonameid = :geonameid, pays=:country_code WHERE usr_id = :usr_id';
|
$sql = 'UPDATE usr SET geonameid = :geonameid, pays=:country_code WHERE usr_id = :usr_id';
|
||||||
|
|
||||||
$datas = array(
|
$datas = array(
|
||||||
@@ -1102,7 +1126,7 @@ class User_Adapter implements User_Interface, cache_cacheableInterface
|
|||||||
$this->modificationdate = new DateTime($row['usr_modificationdate']);
|
$this->modificationdate = new DateTime($row['usr_modificationdate']);
|
||||||
$this->applied_template = $row['lastModel'];
|
$this->applied_template = $row['lastModel'];
|
||||||
|
|
||||||
$this->country = $this->app['geonames']->get_country($row['geonameid']);
|
$this->country = $this->get_country();
|
||||||
|
|
||||||
$this->is_guest = ($row['invite'] == '1');
|
$this->is_guest = ($row['invite'] == '1');
|
||||||
|
|
||||||
|
@@ -1,173 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of Phraseanet
|
|
||||||
*
|
|
||||||
* (c) 2005-2013 Alchemy
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
|
||||||
|
|
||||||
class geonames
|
|
||||||
{
|
|
||||||
private $app;
|
|
||||||
|
|
||||||
public function __construct(Application $app)
|
|
||||||
{
|
|
||||||
$this->app = $app;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function name_from_id($geonameid)
|
|
||||||
{
|
|
||||||
$url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/')
|
|
||||||
. 'get_name.php?geonameid='
|
|
||||||
. $geonameid;
|
|
||||||
|
|
||||||
$ret = '';
|
|
||||||
|
|
||||||
$xml = http_query::getUrl($url);
|
|
||||||
if ($xml) {
|
|
||||||
|
|
||||||
$sxe = simplexml_load_string($xml);
|
|
||||||
|
|
||||||
if ($sxe !== false && ($geoname = $sxe->geoname)) {
|
|
||||||
$ret = (string) $geoname->city . ', ' . (string) $geoname->country;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_country($geonameid)
|
|
||||||
{
|
|
||||||
if (trim($geonameid) === '' || trim($geonameid) <= 0) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/')
|
|
||||||
. 'get_name.php?geonameid='
|
|
||||||
. $geonameid;
|
|
||||||
|
|
||||||
$ret = '';
|
|
||||||
$xml = http_query::getUrl($url);
|
|
||||||
if ($xml) {
|
|
||||||
$sxe = simplexml_load_string($xml);
|
|
||||||
|
|
||||||
if ($sxe !== false && ($geoname = $sxe->geoname)) {
|
|
||||||
$ret = (string) $geoname->country;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function get_country_code($geonameid)
|
|
||||||
{
|
|
||||||
$url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/')
|
|
||||||
. 'get_name.php?geonameid='
|
|
||||||
. $geonameid;
|
|
||||||
|
|
||||||
$ret = '';
|
|
||||||
|
|
||||||
$xml = http_query::getUrl($url);
|
|
||||||
if ($xml) {
|
|
||||||
$sxe = simplexml_load_string($xml);
|
|
||||||
|
|
||||||
if ($sxe !== false && ($geoname = $sxe->geoname)) {
|
|
||||||
$ret = (string) $geoname->country_code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function clean_input($input)
|
|
||||||
{
|
|
||||||
return strip_tags(trim($input));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static function highlight($title, $length)
|
|
||||||
{
|
|
||||||
return '<span class="highlight">' . mb_substr($title, 0, $length) . '</span>'
|
|
||||||
. mb_substr($title, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find_city($cityName)
|
|
||||||
{
|
|
||||||
$output = array();
|
|
||||||
$cityName = self::clean_input($cityName);
|
|
||||||
|
|
||||||
if (strlen($cityName) === 0) {
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/')
|
|
||||||
. 'find_city.php?city='
|
|
||||||
. urlencode($cityName) . '&maxResult=30';
|
|
||||||
|
|
||||||
$sxe = simplexml_load_string(http_query::getUrl($url));
|
|
||||||
|
|
||||||
foreach ($sxe->geoname as $geoname) {
|
|
||||||
$length = mb_strlen($geoname->title_match);
|
|
||||||
|
|
||||||
$title_highlight = self::highlight($geoname->title, $length);
|
|
||||||
|
|
||||||
$country_highlight = (string) $geoname->country;
|
|
||||||
if (trim($geoname->country_match) !== '') {
|
|
||||||
$length = mb_strlen($geoname->country_match);
|
|
||||||
$country_highlight = self::highlight($geoname->country, $length);
|
|
||||||
}
|
|
||||||
|
|
||||||
$output[] = array(
|
|
||||||
'title_highlighted' => $title_highlight
|
|
||||||
, 'title' => (string) $geoname->title
|
|
||||||
, 'country_highlighted' => $country_highlight
|
|
||||||
, 'country' => (string) $geoname->country
|
|
||||||
, 'geoname_id' => (int) $geoname->geonameid
|
|
||||||
, 'region' => (string) $geoname->region
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
protected $cache_ips = array();
|
|
||||||
|
|
||||||
public function find_geoname_from_ip($ip)
|
|
||||||
{
|
|
||||||
if (array_key_exists($ip, $this->cache_ips)) {
|
|
||||||
return $this->cache_ips[$ip];
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = array(
|
|
||||||
'city' => '',
|
|
||||||
'country_code' => '',
|
|
||||||
'country' => '',
|
|
||||||
'fips' => '',
|
|
||||||
'longitude' => '',
|
|
||||||
'latitude' => ''
|
|
||||||
);
|
|
||||||
|
|
||||||
$url = $this->app['phraseanet.registry']->get('GV_i18n_service', 'http://localization.webservice.alchemyasp.com/')
|
|
||||||
. 'geoip.php?ip='
|
|
||||||
. urlencode($ip);
|
|
||||||
|
|
||||||
$xml = http_query::getUrl($url);
|
|
||||||
if ($xml) {
|
|
||||||
$sxe = simplexml_load_string($xml);
|
|
||||||
if ($sxe !== false && $sxe->geoname) {
|
|
||||||
$output['city'] = (string) $sxe->geoname->city;
|
|
||||||
$output['country_code'] = (string) $sxe->geoname->country_code;
|
|
||||||
$output['country'] = (string) $sxe->geoname->country;
|
|
||||||
$output['fips'] = (string) $sxe->geoname->fips;
|
|
||||||
$output['longitude'] = (string) $sxe->geoname->longitude;
|
|
||||||
$output['latitude'] = (string) $sxe->geoname->latitude;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$this->cache_ips[$ip] = $output;
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -79,7 +79,7 @@ return call_user_func_array(function(Application $app) {
|
|||||||
'type' => \registry::TYPE_STRING,
|
'type' => \registry::TYPE_STRING,
|
||||||
'name' => 'GV_i18n_service',
|
'name' => 'GV_i18n_service',
|
||||||
'comment' => _('Geonames server address'),
|
'comment' => _('Geonames server address'),
|
||||||
'default' => 'http://localization.webservice.alchemyasp.com/',
|
'default' => 'http://geoloc.preprod.alchemyasp.com/',
|
||||||
'end_slash' => true,
|
'end_slash' => true,
|
||||||
'required' => true
|
'required' => true
|
||||||
),
|
),
|
||||||
|
@@ -3903,7 +3903,7 @@
|
|||||||
<name>pays</name>
|
<name>pays</name>
|
||||||
<type>varchar(64)</type>
|
<type>varchar(64)</type>
|
||||||
|
|
||||||
<null></null>
|
<null>YES</null>
|
||||||
<extra></extra>
|
<extra></extra>
|
||||||
|
|
||||||
<default></default>
|
<default></default>
|
||||||
|
@@ -94,7 +94,7 @@
|
|||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="form_label control-label" for="form_city"><strong>{% trans "admin::compte-utilisateur ville" %}</strong></label>
|
<label class="form_label control-label" for="form_city"><strong>{% trans "admin::compte-utilisateur ville" %}</strong></label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input class="input_element input-xlarge geoname_field" type="text" name="form_geonameid" id="form_geonameid" geonameid="{{ app["authentication"].getUser().get_geonameid() }}" value="{{ app["geonames"].name_from_id(app["authentication"].getUser().get_geonameid()) }}" />
|
<input class="input_element input-xlarge geoname_field" type="text" name="form_geonameid" id="form_geonameid" value="{{ app["authentication"].getUser().get_geonameid() }}" />
|
||||||
<p class="form_alert help-block"></p>
|
<p class="form_alert help-block"></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -34,7 +34,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for row in sessions %}
|
{% for session in sessions %}
|
||||||
|
{% set row = session['session'] %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
{% if app['session'].get('phrasea_session_id') != row.Id() %}
|
{% if app['session'].get('phrasea_session_id') != row.Id() %}
|
||||||
@@ -48,20 +49,8 @@
|
|||||||
{{ app['date-formatter'].getDate(row.getUpdated()) }}
|
{{ app['date-formatter'].getDate(row.getUpdated()) }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{% set geoname = app['geonames'].find_geoname_from_ip(row.getIpAddress()) %}
|
|
||||||
|
|
||||||
{% if geoname['city'] %}
|
|
||||||
{% set ip_infos = geoname['city'] ~ ' (' ~ geoname['country'] ~ ')' %}
|
|
||||||
{% elseif geoname['fips'] %}
|
|
||||||
{% set ip_infos = geoname['fips'] ~ ' (' ~ geoname['country'] ~ ')' %}
|
|
||||||
{% elseif geoname['country'] %}
|
|
||||||
{% set ip_infos = geoname['country'] %}
|
|
||||||
{% else %}
|
|
||||||
{% set ip_infos = '' %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{{ row.getIpAddress() }}
|
{{ row.getIpAddress() }}
|
||||||
{{ ip_infos }}
|
{{ session['info'] }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ row.getBrowserName() }} {{ row.getBrowserVersion() }}
|
{{ row.getBrowserName() }} {{ row.getBrowserVersion() }}
|
||||||
|
@@ -97,7 +97,8 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for row in data['sessions'] %}
|
{% for session in data['sessions'] %}
|
||||||
|
{% set row = session['session'] %}
|
||||||
<tr title="{{ _self.tooltip_connected_users(row) | e }}" class="{% if loop.index is odd %}odd{% else %}even{% endif %} usrTips" id="TREXP_{{ row.getId()}}">
|
<tr title="{{ _self.tooltip_connected_users(row) | e }}" class="{% if loop.index is odd %}odd{% else %}even{% endif %} usrTips" id="TREXP_{{ row.getId()}}">
|
||||||
|
|
||||||
{% if row.getId() == app['session'].get('session_id') %}
|
{% if row.getId() == app['session'].get('session_id') %}
|
||||||
@@ -112,20 +113,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
{% set geoname = app['geonames'].find_geoname_from_ip(row.getIpAddress()) %}
|
<td>{{ row.getIpAddress() }}<br/>{{ session['info'] }}</td>
|
||||||
|
|
||||||
{% if geoname['city'] %}
|
|
||||||
{% set ip_infos = geoname['city'] ~ ' (' ~ geoname['country'] ~ ')' %}
|
|
||||||
{% elseif geoname['fips'] %}
|
|
||||||
{% set ip_infos = geoname['fips'] ~ ' (' ~ geoname['country'] ~ ')' %}
|
|
||||||
{% elseif geoname['country'] %}
|
|
||||||
{% set ip_infos = geoname['country'] %}
|
|
||||||
{% else %}
|
|
||||||
{% set ip_infos = '' %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
<td>{{ row.getIpAddress() }}<br/>{{ ip_infos }}</td>
|
|
||||||
<td>{{ app['date-formatter'].getDate(row.getCreated()) }}</td>
|
<td>{{ app['date-formatter'].getDate(row.getCreated()) }}</td>
|
||||||
<td>{{ app['date-formatter'].getPrettyString(row.getUpdated()) }}</td>
|
<td>{{ app['date-formatter'].getPrettyString(row.getUpdated()) }}</td>
|
||||||
|
|
||||||
|
@@ -515,7 +515,7 @@
|
|||||||
{% trans 'admin::compte-utilisateur ville' %}
|
{% trans 'admin::compte-utilisateur ville' %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" geonameid="{{main_user.get_geonameid()}}" value="{{ app['geonames'].name_from_id(main_user.get_geonameid()) }}" class="geoname_field" name="geonameid" />
|
<input type="text" value="{{ main_user.get_geonameid() }}" class="geoname_field" name="geonameid" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@@ -365,7 +365,7 @@
|
|||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<label class="control-label" for="command_geoname_field">{% trans 'admin::compte-utilisateur ville' %}</label>
|
<label class="control-label" for="command_geoname_field">{% trans 'admin::compte-utilisateur ville' %}</label>
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<input class="required geoname_field" type="text" name="geonameid" id="command_geoname_field" geonameid="{{ app['authentication'].getUser().get_geonameid() }}" value="{{ app['geonames'].name_from_id(app['authentication'].getUser().get_geonameid()) }}" />
|
<input class="required geoname_field" type="text" name="geonameid" id="command_geoname_field" value="{{ app['authentication'].getUser().get_geonameid() }}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Alchemy\Tests\Phrasea\Core\Provider;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider
|
|
||||||
*/
|
|
||||||
class GeonamesServiceProvidertest extends ServiceProviderTestCase
|
|
||||||
{
|
|
||||||
public function provideServiceDescription()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array('Alchemy\Phrasea\Core\Provider\GeonamesServiceProvider', 'geonames', 'geonames'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,76 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class geonamesTest extends PhraseanetPHPUnitAbstract
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @var geonames
|
|
||||||
*/
|
|
||||||
protected $object;
|
|
||||||
|
|
||||||
public function setUp()
|
|
||||||
{
|
|
||||||
parent::setUp();
|
|
||||||
$this->object = new geonames(self::$DI['app']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testName_from_id()
|
|
||||||
{
|
|
||||||
$result = $this->object->name_from_id(2989317);
|
|
||||||
$this->assertEquals("Orléans, France", $result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGet_country()
|
|
||||||
{
|
|
||||||
$orleans = $this->object->find_city('orléans, france');
|
|
||||||
$this->assertTrue(is_array($orleans));
|
|
||||||
$this->assertTrue(count($orleans) === 1);
|
|
||||||
$orleans = array_pop($orleans);
|
|
||||||
|
|
||||||
$found = $this->object->get_country($orleans['geoname_id']);
|
|
||||||
|
|
||||||
$this->assertEquals($found, $orleans['country']);
|
|
||||||
$this->assertEquals($found, 'France');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testGet_country_code()
|
|
||||||
{
|
|
||||||
$this->assertEquals('FR', $this->object->get_country_code(2989317));
|
|
||||||
$this->assertEquals('', $this->object->get_country_code(298945135163153317));
|
|
||||||
$this->assertEquals('', $this->object->get_country_code('29894513516315331dsfsd7'));
|
|
||||||
$this->assertEquals('', $this->object->get_country_code('dsfsd'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFind_city()
|
|
||||||
{
|
|
||||||
$orleans = $this->object->find_city('orléa');
|
|
||||||
$this->assertTrue(is_array($orleans));
|
|
||||||
foreach ($orleans as $potential) {
|
|
||||||
$this->assertArrayHasKey('region', $potential);
|
|
||||||
$this->assertArrayHasKey('title_highlighted', $potential);
|
|
||||||
$this->assertArrayHasKey('country', $potential);
|
|
||||||
$this->assertArrayHasKey('title', $potential);
|
|
||||||
$this->assertArrayHasKey('country_highlighted', $potential);
|
|
||||||
$this->assertArrayHasKey('geoname_id', $potential);
|
|
||||||
$this->assertTrue(is_int($potential['geoname_id']));
|
|
||||||
$this->assertTrue(is_string($potential['country_highlighted']));
|
|
||||||
$this->assertTrue(is_string($potential['title']));
|
|
||||||
$this->assertTrue(is_string($potential['country']));
|
|
||||||
$this->assertTrue(is_string($potential['title_highlighted']));
|
|
||||||
$this->assertTrue(is_string($potential['region']));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testFind_geoname_from_ip()
|
|
||||||
{
|
|
||||||
$result = $this->object->find_geoname_from_ip('80.12.81.18');
|
|
||||||
$this->assertArrayHasKey('city', $result);
|
|
||||||
$this->assertArrayHasKey('country_code', $result);
|
|
||||||
$this->assertArrayHasKey('country', $result);
|
|
||||||
$this->assertArrayHasKey('fips', $result);
|
|
||||||
$this->assertArrayHasKey('longitude', $result);
|
|
||||||
$this->assertArrayHasKey('latitude', $result);
|
|
||||||
$this->assertEquals("Paris", $result['city']);
|
|
||||||
$this->assertEquals("FR", $result['country_code']);
|
|
||||||
$this->assertEquals("France", $result['country']);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user