Exemple #1
0
 /**
  * Purge old fake content
  *
  * @return	array	If returns TRUE, upgrader will proceed to next step. If it returns any other value, it will set this as the value of the 'extra' GET parameter and rerun this step (useful for loops)
  */
 public function step1()
 {
     try {
         $topics = \IPS\Db::i()->select('*', 'forums_topics', 'faker_fake=1');
         foreach ($topics as $topic) {
             $topic = \IPS\forums\Topic::constructFromData($topic);
             $topic->delete();
         }
     } catch (\Exception $e) {
     }
     try {
         $members = \IPS\Db::i()->select('*', 'core_members', 'faker_fake=1');
         foreach ($members as $member) {
             $member = \IPS\Member::constructFromData($member);
             $member->delete();
         }
     } catch (\Exception $e) {
     }
     return TRUE;
 }
 /**
  * Authenticate
  *
  * @param    string      $url    The URL for the login page
  * @param    \IPS\Member $member If we want to integrate this login method with an existing member, provide the
  *                               member object
  *
  * @return    \IPS\Member
  * @throws    \IPS\Login\Exception
  */
 public function authenticate($url, $member = null)
 {
     try {
         $steamId = $this->validate();
         if (!$steamId) {
             throw new \IPS\Login\Exception('generic_error', \IPS\Login\Exception::INTERNAL_ERROR);
         }
         /* If an api key is provided, attempt to load the user from steam */
         $response = null;
         $userData = null;
         if ($this->settings['api_key']) {
             try {
                 $response = \IPS\Http\Url::external("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$this->settings['api_key']}&steamids={$steamId}")->request()->get()->decodeJson();
                 if ($response) {
                     // Get the first player
                     $userData = $response['response']['players'][0];
                 }
             } catch (\IPS\Http\Request\Exception $e) {
                 throw new \IPS\Login\Exception('generic_error', \IPS\Login\Exception::INTERNAL_ERROR, $e);
             }
         }
         /* Find  member */
         $newMember = false;
         if ($member === null) {
             try {
                 $memberData = \IPS\Db::i()->select('*', 'core_members', array('steamid=?', $steamId))->first();
                 $member = \IPS\Member::constructFromData($memberData);
             } catch (\UnderflowException $e) {
                 $member = \IPS\Member::load(null);
             }
             if (!$member->member_id) {
                 if ($this->settings['api_key']) {
                     try {
                         $gameslist = \IPS\Http\Url::external("http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key={$this->settings['api_key']}&steamid={$steamId}")->request()->get()->decodeJson();
                         $hasgmod = false;
                         if (!isset($gameslist) or !isset($gameslist['response']) or !isset($gameslist['response']['games'])) {
                             throw new \IPS\Login\Exception('Your Steam account is private and we can\'t tell if you own Garry\'s Mod. Please change your game library to public!', \IPS\Login\Exception::NO_ACCOUNT, $e);
                         }
                         foreach ($gameslist['response']['games'] as $game) {
                             if ($game['appid'] == 4000) {
                                 $hasgmod = true;
                             }
                         }
                         if (!$hasgmod) {
                             throw new \IPS\Login\Exception('Your Steam account must own Garry\'s Mod to login.', \IPS\Login\Exception::NO_ACCOUNT, $e);
                         }
                     } catch (\IPS\Http\Request\Exception $e) {
                         throw new \IPS\Login\Exception('generic_error', \IPS\Login\Exception::INTERNAL_ERROR, $e);
                     }
                 }
                 $member = new \IPS\Member();
                 $member->member_group_id = \IPS\Settings::i()->member_group;
                 if (\IPS\Settings::i()->reg_auth_type == 'admin' or \IPS\Settings::i()->reg_auth_type == 'admin_user') {
                     $member->members_bitoptions['validating'] = true;
                 }
                 if (isset($userData)) {
                     if ($this->settings['use_steam_name']) {
                         $existingUsername = \IPS\Member::load($userData['personaname'], 'name');
                         if (!$existingUsername->member_id) {
                             $member->name = $userData['personaname'];
                         }
                     }
                     $member->profilesync = json_encode(array(static::$loginKey => array('photo' => true, 'cover' => false, 'status' => '')));
                 }
                 $newMember = true;
             }
         }
         /* Create member */
         $member->steamid = $steamId;
         $member->save();
         /* Sync */
         if ($newMember) {
             if (\IPS\Settings::i()->reg_auth_type == 'admin_user') {
                 \IPS\Db::i()->update('core_validating', array('user_verified' => 1), array('member_id=?', $member->member_id));
             }
             $sync = new \IPS\core\ProfileSync\Steam($member);
             $sync->sync();
         }
         /* Return */
         return $member;
     } catch (\IPS\Http\Request\Exception $e) {
         throw new \IPS\Login\Exception('generic_error', \IPS\Login\Exception::INTERNAL_ERROR);
     }
 }
Exemple #3
0
 /**
  * Execute
  *
  * If ran successfully, should return anything worth logging. Only log something
  * worth mentioning (don't log "task ran successfully"). Return NULL (actual NULL, not '' or 0) to not log (which will be most cases).
  * If an error occurs which means the task could not finish running, throw an \IPS\Task\Exception - do not log an error as a normal log.
  * Tasks should execute within the time of a normal HTTP request.
  *
  * @return	mixed	Message to log or NULL
  * @throws	\IPS\Task\Exception
  */
 public function execute()
 {
     if (!\IPS\Settings::i()->membermap_syncLocationField or !\IPS\Settings::i()->membermap_monitorLocationField or !\IPS\Settings::i()->membermap_profileLocationField) {
         $this->enabled = FALSE;
         $this->save();
         return;
     }
     $fieldKey = \IPS\Settings::i()->membermap_profileLocationField;
     $limit = 100;
     $counter = 0;
     $memberMarkerGroupId = \IPS\membermap\Map::i()->getMemberGroupId();
     try {
         $where = array();
         $where[] = array("( pf.field_{$fieldKey} IS NOT NULL OR pf.field_{$fieldKey} != '' )");
         $where[] = array("mm.marker_id IS NULL");
         $where[] = array("m.membermap_location_synced = 0");
         $where[] = array('( ! ' . \IPS\Db::i()->bitwiseWhere(\IPS\Member::$bitOptions['members_bitoptions'], 'bw_is_spammer') . ' )');
         if (\IPS\Settings::i()->membermap_monitorLocationField_groupPerm !== '*') {
             $where[] = \IPS\Db::i()->in('m.member_group_id', explode(',', \IPS\Settings::i()->membermap_monitorLocationField_groupPerm));
         }
         $members = \IPS\Db::i()->select('*', array('core_members', 'm'), $where, 'm.last_activity DESC', array(0, $limit))->join(array('core_pfields_content', 'pf'), 'pf.member_id=m.member_id')->join(array('membermap_markers', 'mm'), 'mm.marker_member_id=m.member_id AND mm.marker_parent_id=' . $memberMarkerGroupId);
         foreach ($members as $member) {
             $lat = $lng = $location = NULL;
             $_member = \IPS\Member::constructFromData($member);
             /* Need to set this to prevent us from looping over the same members with invalid locations over and over again */
             $_member->membermap_location_synced = 1;
             $_member->save();
             $_location = trim($member['field_' . $fieldKey]);
             if (empty($_location)) {
                 continue;
             }
             /* If it's an array, it might be from an address field, which already have the lat/lng data */
             if (is_array(json_decode($_location, TRUE))) {
                 $addressData = json_decode($_location, TRUE);
                 if (is_float($addressData['lat']) and is_float($addressData['long'])) {
                     $lat = floatval($addressData['lat']);
                     $lng = floatval($addressData['long']);
                 }
                 $addressData['addressLines'][] = $addressData['city'];
                 if (count($addressData['addressLines'])) {
                     $location = implode(', ', $addressData['addressLines']);
                 }
             } else {
                 /* Remove HTML, newlines, tab, etc, etc */
                 $_location = preg_replace("/[\\x00-\\x20]|\\xc2|\\xa0+/", ' ', strip_tags($_location));
                 $_location = trim(preg_replace("/\\s\\s+/", ' ', $_location));
                 /* To my understanding we're not allowed to use \IPS\Geolocation, as that uses Google API, and we're not showing the info on a Google Map. */
                 $nominatim = \IPS\membermap\Map::i()->getLatLng($_location);
                 if (is_array($nominatim) and count($nominatim)) {
                     $lat = $nominatim['lat'];
                     $lng = $nominatim['lng'];
                     $location = $nominatim['location'];
                 }
             }
             if ($lat and $lng) {
                 $marker = \IPS\membermap\Markers\Markers::createItem($_member, NULL, new \IPS\DateTime(), \IPS\membermap\Markers\Groups::load($memberMarkerGroupId), FALSE);
                 $marker->name = $_member->name;
                 $marker->lat = $lat;
                 $marker->lon = $lng;
                 $marker->location = $location ?: $_location;
                 $marker->save();
                 /* Add to index */
                 \IPS\Content\Search\Index::i()->index($marker);
                 $counter++;
             }
         }
     } catch (\UnderflowException $e) {
     } catch (\RuntimeException $e) {
         \IPS\Log::log(array($e->getMessage(), $nominatim), 'membermap');
     } catch (\Exception $e) {
         \IPS\Log::log(array($e->getMessage(), $nominatim), 'membermap');
         throw new \IPS\Task\Exception($this, $e->getMessage());
     }
     if ($counter > 0) {
         $foundRows = $members->count();
         return "Synchronised {$counter} out of {$foundRows} member locations";
     } else {
         $this->enabled = FALSE;
         $this->save();
         /* Turn the setting off as well */
         \IPS\Db::i()->update('core_sys_conf_settings', array('conf_value' => 0), array('conf_key=?', 'membermap_syncLocationField'));
         unset(\IPS\Data\Store::i()->settings);
         return;
     }
     return NULL;
 }