/** * ... * * @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() { $file = file_get_contents('https://raw.githubusercontent.com/CleanTalk/php-antispam/master/cleantalk.class.php'); if ($file === FALSE) { return FALSE; } if (file_put_contents(dirname($_SERVER['SCRIPT_FILENAME']) . "/../uploads/cleantalk.class.php", $file) === FALSE) { return FALSE; } $file = file_get_contents('https://raw.githubusercontent.com/CleanTalk/php-antispam/master/JSON.php'); if ($file === FALSE) { return FALSE; } if (file_put_contents(dirname($_SERVER['SCRIPT_FILENAME']) . "/../uploads/JSON.php", $file) === FALSE) { return FALSE; } $file = file_get_contents('https://raw.githubusercontent.com/CleanTalk/ips4-antispam/master/cleantalk-sfw.class.php'); if ($file === FALSE) { return FALSE; } if (file_put_contents(dirname($_SERVER['SCRIPT_FILENAME']) . "/../uploads/cleantalk-sfw.class.php", $file) === FALSE) { return FALSE; } $file = file_get_contents('https://raw.githubusercontent.com/CleanTalk/ips4-antispam/master/sfw_die_page.html'); if ($file === FALSE) { return FALSE; } if (file_put_contents(dirname($_SERVER['SCRIPT_FILENAME']) . "/../uploads/sfw_die_page.html", $file) === FALSE) { return FALSE; } \IPS\Db::i()->query("CREATE TABLE IF NOT EXISTS cleantalk_timelabels (ct_key varchar(50), ct_value int(11), PRIMARY KEY (ct_key) ) ENGINE=myisam"); \IPS\Db::i()->query("CREATE TABLE IF NOT EXISTS cleantalk_server (work_url varchar(50), server_ttl int(11), server_changed int(11) ) ENGINE=myisam"); \IPS\Db::i()->query("CREATE TABLE IF NOT EXISTS cleantalk_settings (ct_key varchar(50), ct_value varchar(50), PRIMARY KEY (ct_key) ) ENGINE=myisam"); return TRUE; }
/** * Generate a fake node * * @param \IPS\Node\Model|null $parent Parent node, or NULL to generate a root node * @param array $values Generator form values * @return \IPS\Node\Model */ public function generateSingle($parent = NULL, array $values) { $nodeClass = static::$nodeClass; $node = new $nodeClass(); /* Handle submissions */ if (isset($node::$databaseColumnOrder)) { $orderColumn = $node::$databaseColumnOrder; $node->{$orderColumn} = \IPS\Db::i()->select('MAX(' . $node::$databasePrefix . $orderColumn . ')', $node::$databaseTable)->first() + 1; } $nodeValues = array('forum_name' => $this->generator->title(), 'forum_description' => $values['description'] ? $this->generator->description() : ' ', 'forum_type' => $values['forum_type'], 'forum_parent_id' => $parent, 'forum_password' => $values['password']); if ($parent) { $parentColumn = NULL; if (\IPS\Request::i()->subnode) { if (isset($nodeClass::$parentNodeColumnId)) { $parentColumn = $nodeClass::$parentNodeColumnId; } } elseif (isset($nodeClass::$databaseColumnParent)) { $parentColumn = $nodeClass::$databaseColumnParent; } if ($parentColumn !== NULL) { $node->{$parentColumn} = $parent; } } $node->saveForm($node->formatFormValues($nodeValues)); $this->map(static::$nodeClass, $node->_id); $this->setPermissions($node); return \IPS\Member::loggedIn()->language()->addToStack(static::$message, TRUE, array('sprintf' => array($parent ? $parent->_title : 'root'))); }
/** * Assign default permissions to the node * * @param \IPS\Node\Model $node */ public function setPermissions(\IPS\Node\Model $node) { $nodeClass = static::$nodeClass; /* Recommended permissions */ $current = array(); foreach ($nodeClass::$permissionMap as $k => $v) { switch ($k) { case 'view': case 'read': $current["perm_{$v}"] = '*'; break; case 'add': case 'reply': case 'review': case 'upload': case 'download': default: $current["perm_{$v}"] = implode(',', array_keys(\IPS\Member\Group::groups(TRUE, FALSE))); break; } } $_perms = array(); /* Check for "all" checkboxes */ foreach ($nodeClass::$permissionMap as $k => $v) { if (isset(\IPS\Request::i()->__all[$k])) { $_perms[$v] = '*'; } else { $_perms[$v] = array(); } } /* Prepare insert */ $insert = array('app' => $nodeClass::$permApp, 'perm_type' => $nodeClass::$permType, 'perm_type_id' => $node->_id); if (isset($current['perm_id'])) { $insert['perm_id'] = $current['perm_id']; } /* Loop groups */ /*foreach ( $current as $group => $perms ) { foreach ( $nodeClass::$permissionMap as $k => $v ) { if ( isset( $perms[ $k ] ) and $perms[ $k ] and is_array( $current[ $v ] ) ) { $current[ $v ][] = $group; } } }*/ /* Finalise */ foreach ($current as $k => $v) { $insert[$k] = is_array($v) ? implode($v, ',') : $v; } /* Delete existing permissions */ \IPS\Db::i()->delete('core_permission_index', array('app=? AND perm_type=? AND perm_type_id=?', $nodeClass::$permApp, $nodeClass::$permType, $node->_id)); /* Insert */ \IPS\Db::i()->insert('core_permission_index', $insert); }
/** * Code to execute after the application has been uninstalled * * @param string $application Application directory * @return array */ public function postUninstall($application) { if (\IPS\Db::i()->checkForColumn('core_groups', 'g_membermap_canAdd')) { \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canAdd'); } if (\IPS\Db::i()->checkForColumn('core_groups', 'g_membermap_canEdit')) { \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canEdit'); } if (\IPS\Db::i()->checkForColumn('core_groups', 'g_membermap_canDelete')) { \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canDelete'); } if (\IPS\Db::i()->checkForColumn('core_members', 'membermap_location_synced')) { \IPS\Db::i()->dropColumn('core_members', 'membermap_location_synced'); } }
/** * ... * * @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() { /* Remove MapQuest.OSM, as it's no longer "free" */ $maps = json_decode(\IPS\Settings::i()->membermap_activemaps, true); if (is_array($maps)) { $osm = array_search('MapQuestOpen.OSM', $maps['basemaps']); if ($osm !== FALSE) { $maps['basemaps'][$osm] = 'OpenStreetMap.France'; $maps['basemaps'] = array_unique($maps['basemaps'], SORT_REGULAR); \IPS\Settings::i()->membermap_activemaps = json_encode($maps); \IPS\Db::i()->update('core_sys_conf_settings', array('conf_value' => \IPS\Settings::i()->membermap_activemaps), array('conf_key=?', 'membermap_activemaps')); unset(\IPS\Data\Store::i()->settings); } } return TRUE; }
/** * ... * * @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() { /* These changes should have been done by the 3.1.0 upgrader, but I forgot. */ if (!\IPS\Db::i()->checkForIndex('membermap_markers_groups', 'group_position')) { \IPS\Db::i()->addIndex('membermap_markers_groups', array('type' => 'key', 'name' => 'group_position', 'columns' => array('group_position'))); } if (!\IPS\Db::i()->checkForIndex('membermap_markers', 'marker_member_id')) { \IPS\Db::i()->addIndex('membermap_markers', array('type' => 'key', 'name' => 'marker_member_id', 'columns' => array('marker_member_id'))); } if (!\IPS\Db::i()->checkForIndex('membermap_markers', 'marker_parent_id')) { \IPS\Db::i()->addIndex('membermap_markers', array('type' => 'key', 'name' => 'marker_parent_id', 'columns' => array('marker_parent_id'))); } \IPS\Db::i()->changeColumn('membermap_markers', 'marker_open', array('name' => 'marker_open', 'type' => 'tinyint', 'length' => 1, 'allow_null' => false, 'default' => 0)); \IPS\Db::i()->update('membermap_markers', array('marker_open' => 0), 'marker_open IS NULL'); \IPS\Task::queue('membermap', 'RebuildCache', array('class' => '\\IPS\\membermap\\Map'), 1, array('class')); return TRUE; }
/** * Update default maps * @return void */ public function update() { $maps = \IPS\Request::i()->maps; if (!isset($maps['basemaps'])) { /* You can't have a map with no basemap. Defaulting to OpenStreetMap.France */ $maps['basemaps'] = array('OpenStreetMap.France'); } if (!isset($maps['overlays'])) { $maps['overlays'] = array(); } \IPS\Settings::i()->membermap_activemaps = json_encode($maps); \IPS\Db::i()->update('core_sys_conf_settings', array('conf_value' => \IPS\Settings::i()->membermap_activemaps), array('conf_key=?', 'membermap_activemaps')); unset(\IPS\Data\Store::i()->settings); if (\IPS\Request::i()->isAjax()) { \IPS\Output::i()->output = 1; return; } \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=mapmanager"), 'saved'); }
/** * Run Background Task * * @param mixed $data Data as it was passed to \IPS\Task::queue() * @param int $offset Offset * @return int|null New offset or NULL if complete * @throws \OutOfRangeException Indicates offset doesn't exist and thus task is complete */ public function run($data, $offset) { $currentMemUsage = memory_get_usage(TRUE); /* Wipe out the old files on the first run */ if ($offset === 0) { \IPS\membermap\Map::i()->deleteCacheFiles(); } $count = 0; $memberMarkers = array(); $customMarkers = array(); $selectColumns = array('mm.*', 'mg.*', 'm.member_id', 'm.name', 'm.members_seo_name', 'm.member_group_id', 'm.pp_photo_type', 'm.pp_main_photo', 'm.pp_thumb_photo'); if (\IPS\Settings::i()->allow_gravatars) { $selectColumns[] = 'm.pp_gravatar'; $selectColumns[] = 'm.email'; $selectColumns[] = 'm.members_bitoptions'; } /* Remember to update membermap\Map too */ $_markers = \IPS\Db::i()->select(implode(',', $selectColumns), array('membermap_markers', 'mm'), array('marker_open=1'), 'mg.group_position ASC, mm.marker_id DESC', array($offset, $this->perCycle))->join(array('membermap_markers_groups', 'mg'), 'mm.marker_parent_id=mg.group_id')->join(array('core_members', 'm'), 'mm.marker_member_id=m.member_id'); foreach ($_markers as $marker) { $count++; if ($marker['group_type'] == 'member') { $memberMarkers[] = $marker; } else { $customMarkers[] = $marker; } } if ($count > 0) { $markers = \IPS\membermap\Map::i()->formatMemberMarkers($memberMarkers); $custMarkers = \IPS\membermap\Map::i()->formatCustomMarkers($customMarkers); $markers = array_merge($markers, $custMarkers); $fileNumber = $offset / $this->perCycle; touch(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileNumber . '.json'); chmod(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileNumber . '.json', \IPS\IPS_FILE_PERMISSION); \file_put_contents(\IPS\ROOT_PATH . '/datastore/membermap_cache/membermap-' . $fileNumber . '.json', json_encode(array('markers' => $markers, 'memUsage' => (memory_get_usage(TRUE) - $currentMemUsage) / 1024 . 'kB', 'fromQueue' => 1))); /* Store the timestamp of the cache to force the browser to purge its local storage */ \IPS\Data\Store::i()->membermap_cacheTime = time(); } if (!$count) { throw new \IPS\Task\Queue\OutOfRangeException(); } return $offset + $count; }
/** * ... * * @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() { if (!\IPS\Db::i()->checkForColumn('core_members', 'steamid')) { \IPS\Db::i()->addColumn('core_members', ['name' => 'steamid', 'type' => 'VARCHAR', 'length' => 17]); } if (!\IPS\Db::i()->checkForIndex('core_members', 'steamid')) { \IPS\Db::i()->addIndex('core_members', array('name' => 'steamid', 'type' => 'key', 'columns' => array('steamid'))); } $doesNotExist = false; try { \IPS\Db::i()->select('login_key', 'core_login_handlers', array('login_key=?', 'steam'))->first(); } catch (UnderflowException $e) { $doesNotExist = true; } if ($doesNotExist) { $maxLoginOrder = \IPS\Db::i()->select('MAX(login_order)', 'core_login_handlers')->first(); \IPS\Db::i()->insert('core_login_handlers', array('login_settings' => '{"steam_apikey":"","use_steam_name":true}', 'login_key' => 'Steam', 'login_enabled' => 1, 'login_order' => $maxLoginOrder + 1, 'login_acp' => 0)); } return TRUE; }
/** * 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; }
/** * 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; }
/** * 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 ) { $url = $url->setQueryString( 'loginProcess', 'vk' ); try { /* CSRF Check */ if ( \IPS\Request::i()->state !== \IPS\Session::i()->csrfKey ) { throw new \IPS\Login\Exception( 'CSRF_FAIL', \IPS\Login\Exception::INTERNAL_ERROR ); } if(isset(\IPS\Request::i()->error) || !isset(\IPS\Request::i()->code)) { throw new \IPS\Login\Exception( 'generic_error', \IPS\Login\Exception::INTERNAL_ERROR ); } /* Get a token */ try { $response = \IPS\Http\Url::external( "https://oauth.vk.com/access_token" )->setQueryString( array( 'client_id' => $this->settings['app_id'], 'redirect_uri' => (string) \IPS\Http\Url::internal( 'applications/core/interface/vk/auth.php', 'none' ), 'client_secret' => $this->settings['app_secret'], 'code' => \IPS\Request::i()->code ) )->request()->Get()->decodeJson(); if(isset($response['error'])) { throw new \IPS\Login\Exception( 'generic_error', \IPS\Login\Exception::INTERNAL_ERROR ); } } catch( \RuntimeException $e ) { throw new \IPS\Login\Exception( 'generic_error', \IPS\Login\Exception::INTERNAL_ERROR ); } /* Get the user data */ $userData = \IPS\Http\Url::external( "https://api.vk.com/method/getProfiles?uid={$response['user_id']}&access_token={$response['access_token']}&fields=first_name,last_name,screen_name,bdate,nickname" )->request()->get()->decodeJson(); $userData = $userData['response'][0]; /* Find or create member */ $newMember = FALSE; if ( $member === NULL ) { $member = \IPS\Member::load( $response['user_id'], 'vk_id' ); if ( !$member->member_id ) { if(isset($response['email'])) { $existingEmail = \IPS\Member::load( $response['email'], 'email' ); if ( $existingEmail->member_id ) { $exception = new \IPS\Login\Exception( 'generic_error', \IPS\Login\Exception::MERGE_SOCIAL_ACCOUNT ); $exception->handler = 'vk'; $exception->member = $existingEmail; $exception->details = array($response['access_token'], $response['user_id']); throw $exception; } } $member = new \IPS\Member; if ( \IPS\Settings::i()->reg_auth_type == 'admin' or \IPS\Settings::i()->reg_auth_type == 'admin_user' ) { $member->members_bitoptions['validating'] = TRUE; } $member->member_group_id = \IPS\Settings::i()->member_group; $member->email = isset($response['email'])?$response['email']:''; $member->name = $userData['nickname']; if ( empty($member->name) AND $this->settings['real_name'] ) { $name = $userData['first_name'] . ' ' . $userData['last_name']; $existingUsername = \IPS\Member::load( $name, 'name' ); if ( !$existingUsername->member_id ) { $member->name = $name; } } $member->profilesync = json_encode( array( 'vk' => array( 'photo' => TRUE, 'status' => '' ) ) ); $newMember = TRUE; } } /* Update details */ $member->vk_id = $response['user_id']; $member->vk_token = $response['access_token']; $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\VK( $member ); $sync->sync(); } /* Return */ return $member; } catch ( \IPS\Http\Request\Exception $e ) { throw new \IPS\Login\Exception( 'generic_error', \IPS\Login\Exception::INTERNAL_ERROR ); } }
/** * Do formatation to the array of markers * * @param array Markers * @return array Markers */ public function formatMemberMarkers(array $markers) { $markersToKeep = array(); $groupCache = \IPS\Data\Store::i()->groups; if (is_array($markers) and count($markers)) { foreach ($markers as $marker) { /* Member don't exists or lat/lon == 0 (Middle of the ocean) */ if ($marker['member_id'] === NULL or $marker['marker_lat'] == 0 and $marker['marker_lon'] == 0) { \IPS\Db::i()->delete('membermap_markers', array('marker_id=?', $marker['marker_id'])); continue; } $photo = \IPS\Member::photoUrl($marker); try { $groupName = \IPS\Lang::load(\IPS\Lang::defaultLanguage())->get('core_group_' . $marker['member_group_id']); } catch (\UnderflowException $e) { $groupName = ''; } if (isset($groupCache[$marker['member_group_id']]['g_membermap_markerColour'])) { $markerColour = $groupCache[$marker['member_group_id']]['g_membermap_markerColour']; } else { $markerColour = 'darkblue'; } $markersToKeep[] = array('type' => "member", 'lat' => round((double) $marker['marker_lat'], 5), 'lon' => round((double) $marker['marker_lon'], 5), 'member_id' => $marker['marker_member_id'], 'parent_id' => $marker['member_group_id'], 'parent_name' => $groupName, 'popup' => \IPS\Theme::i()->getTemplate('map', 'membermap', 'front')->popupContent($marker, $photo), 'markerColour' => $markerColour); } } return $markersToKeep; }
/** * Get all children of a specific group. * * @param INT $groupId Group ID to fetch children from * @return array */ public static function getChildren($groupId = 0) { $children = array(); foreach (\IPS\Db::i()->select('*', static::$databaseTable, array(static::$databasePrefix . 'parent_id=?', intval($groupId)), static::$databasePrefix . 'name ASC') as $child) { $children[$child[static::$databasePrefix . static::$databaseColumnId]] = static::load($child[static::$databasePrefix . static::$databaseColumnId]); } return $children; }
/** * @param \IPS\nexus\Invoice $invoice */ private function registerMember(\IPS\nexus\Invoice &$invoice) { // Create the member account if this was a guest if (!$invoice->member->member_id and $invoice->guest_data) { $profileFields = $invoice->guest_data['profileFields']; $memberToSave = new \IPS\nexus\Customer(); foreach ($invoice->guest_data['member'] as $k => $v) { $memberToSave->_data[$k] = $v; $memberToSave->changed[$k] = $v; } $memberToSave->save(); $invoice->member = $memberToSave; $invoice->guest_data = NULL; $invoice->save(); // If we've entered an address during checkout, save it if ($invoice->billaddress !== NULL) { $billing = new \IPS\nexus\Customer\Address(); $billing->member = $invoice->member; $billing->address = $invoice->billaddress; $billing->primary_billing = 1; $billing->save(); } if ($this->shipaddress !== NULL) { $shipping = new \IPS\nexus\Customer\Address(); $shipping->member = $invoice->member; $shipping->address = $invoice->shipaddress; $shipping->primary_shipping = 1; $shipping->save(); } $profileFields['member_id'] = $memberToSave->member_id; \IPS\Db::i()->replace('core_pfields_content', $profileFields); // Notify the incoming mail address if (\IPS\Settings::i()->new_reg_notify) { \IPS\Email::buildFromTemplate('core', 'registration_notify', array($memberToSave, $profileFields))->send(\IPS\Settings::i()->email_in); } // Update associated transactions \IPS\Db::i()->update('nexus_transactions', array('t_member' => $invoice->member->member_id), array('t_invoice=? AND t_member=0', $invoice->id)); } }
public function import() { $id = isset(\IPS\Request::i()->id) ? intval(\IPS\Request::i()->id) : 0; /* Build form */ $form = new \IPS\Helpers\Form(NULL, 'import'); if (isset(\IPS\Request::i()->id)) { $group = \IPS\membermap\Markers\Groups::load(intval(\IPS\Request::i()->id)); if ($group->type == 'member') { \IPS\Output::i()->error('generic_error', '1MM4/1', 403, ''); } } $form->add(new \IPS\Helpers\Form\Upload('import_upload', NULL, TRUE, array('allowedFileTypes' => array('kml'), 'temporary' => TRUE))); $form->add(new \IPS\Helpers\Form\YesNo('import_creategroups', FALSE, FALSE, array('togglesOff' => array('import_group')))); $form->add(new \IPS\Helpers\Form\Node('import_group', $id ?: 0, FALSE, array('class' => '\\IPS\\membermap\\Markers\\Groups', 'permissionCheck' => 'add', 'subnodes' => false, 'where' => array('group_type != ?', 'member')), NULL, NULL, NULL, 'import_group')); if ($values = $form->values()) { try { $xml = \IPS\Xml\SimpleXML::loadFile($values['import_upload']); } catch (\InvalidArgumentException $e) { $form->error = \IPS\Member::loggedIn()->language()->addToStack('xml_upload_invalid'); \IPS\Output::i()->output = $form; return; } /* No group selected, and don't create groups?! */ if ($values['import_creategroups'] == FALSE and !$values['import_group']) { $form->error = \IPS\Member::loggedIn()->language()->addToStack('membermap_error_no_id_no_create'); \IPS\Output::i()->output = $form; return; } $markers = array(); $groupOrder = NULL; $imported = 0; foreach ($xml->Document->Folder as $folder) { if (!isset($folder->Placemark)) { continue; } $folderName = (string) $folder->name; foreach ($folder->Placemark as $placemark) { if (!isset($placemark->Point->coordinates)) { continue; } list($lon, $lat, $elev) = explode(',', $placemark->Point->coordinates); $markers[] = array('marker_name' => (string) $placemark->name, 'marker_name_seo' => \IPS\Http\Url::seoTitle((string) $placemark->name), 'marker_description' => (string) $placemark->description, 'marker_lat' => $lat, 'marker_lon' => $lon, 'marker_member_id' => \IPS\Member::loggedIn()->member_id, 'marker_added' => time(), 'marker_open' => 1, 'marker_parent_id' => isset($values['import_group']) ? $values['import_group']->id : NULL); } /* Create a new group per "folder" */ if ($values['import_creategroups'] == TRUE and count($markers) > 0) { if ($groupOrder === NULL) { $groupOrder = \IPS\Db::i()->select(array("MAX( `group_position` ) as position"), 'membermap_markers_groups')->first(); } $groupOrder = $groupOrder + 1; $group = new \IPS\membermap\Markers\Groups(); $group->name = $folderName; $group->name_seo = \IPS\Http\Url::seoTitle($folderName); $group->type = 'custom'; $group->pin_colour = '#FFFFFF'; $group->pin_bg_colour = 'red'; $group->pin_icon = 'fa-globe'; $group->position = $groupOrder; $group->save(); \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}", trim($folderName)); \IPS\Lang::saveCustom('membermap', "membermap_marker_group_{$group->id}_JS", trim($folderName), 1); // Add group id to all elements of the array array_walk($markers, function (&$v, $k) use($group) { $v['marker_parent_id'] = $group->id; }); // Insert \IPS\Db::i()->insert('membermap_markers', $markers); $group->setLastComment(); $group->save(); // Set default permissions $perms = $group->permissions(); \IPS\Db::i()->update('core_permission_index', array('perm_view' => '*', 'perm_2' => '*', 'perm_3' => \IPS\Settings::i()->admin_group, 'perm_4' => \IPS\Settings::i()->admin_group), array('perm_id=?', $perms['perm_id'])); // Reset $imported += count($markers); $markers = array(); } } /* If we still got markers here, it's all pushed to one group, probably */ if (is_array($markers) and count($markers) > 0) { \IPS\Db::i()->insert('membermap_markers', $markers); $group = $values['import_group']; $group->setLastComment(); $group->save(); $imported += count($markers); } \IPS\membermap\Map::i()->invalidateJsonCache(); $message = \IPS\Member::loggedIn()->language()->addToStack('membermap_import_thumbup', FALSE, array('sprintf' => array($imported))); \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=markers"), $message); } /* Display */ \IPS\Output::i()->output = $form; }
/** * Create a map to a fake content item * * @param string $class Content class * @param int $contentId Content ID * @param \IPS\Member|null $author Member that generated the item, or NULL for the logged in member * @return int Insert ID */ public static function createMap($class, $contentId, $author = NULL) { $author = $author ?: \IPS\Member::loggedIn(); return \IPS\Db::i()->insert(static::$databaseTable, array('class' => trim($class, '\\'), 'content_id' => $contentId, 'author' => $author->member_id, 'created_at' => time())); }
/** * Execute Version Query * * @return void */ protected function executeVersionQuery() { $version = \IPS\Request::i()->version == 'install' ? 'install' : intval(\IPS\Request::i()->version); $json = $this->_getQueries($version); $query = $json[intval(\IPS\Request::i()->query)]; $db = \IPS\Db::i(); call_user_func_array(array($db, $query['method']), $query['params']); }
/** * 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); } }
/** * Clean up */ public function step4() { unset($_SESSION['_membermapMemberGroupId']); /* Restore content in the search index */ \IPS\Task::queue('core', 'RebuildSearchIndex', array('class' => 'IPS\\membermap\\Markers\\Markers')); try { // \IPS\Db::i()->dropTable( 'membermap_members', TRUE ); # Want to keep this table as backup for a couple of versions \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canAdd'); \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canEdit'); \IPS\Db::i()->dropColumn('core_groups', 'g_membermap_canDelete'); } catch (\IPS\Db\Exception $e) { } #meh return TRUE; }
/** * Set last file data * * @param \IPS\downloads\File|NULL $file The latest file or NULL to work it out * @return void */ public function setlastMarker(\IPS\membermap\Markers\Markers $marker = NULL) { if ($marker === NULL) { try { $marker = \IPS\membermap\Markers\Markers::constructFromData(\IPS\Db::i()->select('*', 'membermap_markers', array('marker_parent_id=? AND marker_open=1', $this->id), 'marker_updated DESC, marker_added DESC', 1)->first()); } catch (\UnderflowException $e) { $this->last_marker_id = 0; $this->last_marker_date = 0; return; } } $this->last_marker_id = $marker->id; $this->last_marker_date = $marker->updated > $marker->added ? $marker->updated : $marker->added; }