diff --git a/config.php b/config.php index 79cd99e..683387b 100644 --- a/config.php +++ b/config.php @@ -8,7 +8,7 @@ error_reporting(E_ALL); session_start(); -define('DEFAULT_RADIUS', 50); +define('DEFAULT_SEARCH_RADIUS', 50); define('TAILLE_SPRITE', 32); define('DEMI_TAILLE_SPRITE', (TAILLE_SPRITE/2)); @@ -56,12 +56,6 @@ $players = [ new Player('8PTThXiUSwwuPoqQWw3tuAn4MpvzQzpKhs6LMuiozS7Z', 'kimamila') ]; -if (!isset($_SESSION['radius'])) { - - $_SESSION['radius'] = DEFAULT_RADIUS; -} - - /* ===================== diff --git a/lib/Gchange.traits.php b/lib/Gchange.traits.php new file mode 100644 index 0000000..99c94c4 --- /dev/null +++ b/lib/Gchange.traits.php @@ -0,0 +1,29 @@ +lat; + } + + public function getLon () { + + return $this->lon; + } +} + + +trait Avatarable { + + private $avatarImgSrc = null; + + public function getAvatarImgSrc () { + + return $this->avatarImgSrc; + } +} \ No newline at end of file diff --git a/lib/GchangeRecord.class.php b/lib/GchangeRecord.class.php index 289578a..a1ae8cd 100644 --- a/lib/GchangeRecord.class.php +++ b/lib/GchangeRecord.class.php @@ -2,6 +2,8 @@ class GchangeRecord { + use Locatable, Avatarable; + private $gchangeId; private $title; @@ -10,8 +12,6 @@ class GchangeRecord { private $type; - private $imgSrc = null; - public function __construct ($gchangeObject) { @@ -26,7 +26,7 @@ class GchangeRecord { if (isset($gchangeObject->_source->avatar->_content) and !empty($gchangeObject->_source->avatar->_content)) { - $this->imgSrc = 'data:'. $gchangeObject->_source->avatar->_content_type .';base64,' . $gchangeObject->_source->avatar->_content; + $this->avatarImgSrc = 'data:'. $gchangeObject->_source->avatar->_content_type .';base64,' . $gchangeObject->_source->avatar->_content; } } @@ -52,6 +52,6 @@ class GchangeRecord { public function getImgSrc () { - return $this->imgSrc; + return $this->getAvatarImgSrc(); } } \ No newline at end of file diff --git a/lib/GchangeUser.class.php b/lib/GchangeUser.class.php index a39390e..2dec913 100644 --- a/lib/GchangeUser.class.php +++ b/lib/GchangeUser.class.php @@ -1,17 +1,15 @@ _source->geoPoint->lat, $gchangeObject->_source->geoPoint->lon)) { - + $this->lat = $gchangeObject->_source->geoPoint->lat; $this->lon = $gchangeObject->_source->geoPoint->lon; } @@ -56,21 +54,6 @@ class GchangeUser { return $this->userName; } - public function getLat () { - - return $this->lat; - } - - public function getLon () { - - return $this->lon; - } - - public function getAvatarImgSrc () { - - return $this->avatarImgSrc; - } - public function jsonify () { return $this->gchangeObject; diff --git a/login.php b/login.php index d48e7f1..2ef6862 100644 --- a/login.php +++ b/login.php @@ -25,25 +25,9 @@ if (isset($_POST['salt'], $_POST['pepper'])) { ErrorsHandler::kaput($errMsg); } - $_SESSION['player_pubkey'] = $playerG1Id; - - $gchange = new Gchange(); - - try { - - $player = $gchange->getUser($_SESSION['player_pubkey']); - - } catch (Exception $errMsg) { - - ErrorsHandler::kaput($errMsg); - } - - $_SESSION['player_lat'] = $player->_source->geoPoint->lat; - $_SESSION['player_lon'] = $player->_source->geoPoint->lon; - $_SESSION['radius'] = DEFAULT_RADIUS; - $_SESSION['salt'] = $_POST['salt']; $_SESSION['pepper'] = $_POST['pepper']; + $_SESSION['player_pubkey'] = $playerG1Id; header('Location:home.php'); diff --git a/map.php b/map.php index 7467d66..016b5f1 100644 --- a/map.php +++ b/map.php @@ -12,13 +12,18 @@ if (!isset($_SESSION['player_pubkey'])) { if (isset($_GET['r']) and in_array($_GET['r'], $radiuses)) { - $_SESSION['radius'] = $_GET['r']; + $_SESSION['searchRadius'] = $_GET['r']; + +} else if (!isset($_SESSION['searchRadius'])) { + + $_SESSION['searchRadius'] = DEFAULT_SEARCH_RADIUS; } function getThemeScriptsFullPath ($themeScript) { return GAME_JS_DIR . '/' . $themeScript; } + $gameScripts = array_map('getThemeScriptsFullPath', array_slice(scandir(GAME_JS_DIR), 2)); @@ -26,10 +31,8 @@ $javascripts['footer'] = array_merge($javascripts['footer'], $gameScripts); $bodyIds = 'sonar'; include_once('header.php'); - $gchange = new Gchange(); - $player = $gchange->getUser($_SESSION['player_pubkey']); // die('
' . print_r($player, true) . '
'); @@ -79,7 +82,7 @@ echo ' id="map" data-orig-lat="'. $origLat .'" data-orig-lon="'. $origLon .'" - data-radius="'. $_SESSION['radius'] .'" + data-radius="'. $_SESSION['searchRadius'] .'" >
'; @@ -101,7 +104,7 @@ echo ' '; */ - $places = $gchange->getPlacesNearUser($player, $_SESSION['radius'], MAX_NEARBY_PLACES); + $places = $gchange->getPlacesNearUser($player, $_SESSION['searchRadius'], MAX_NEARBY_PLACES); $selectedPlace = NULL;