/** * Generate a fake topic post * * @param \IPS\Content\Item $topic The topic * @param array $values Generator form values * @param bool $first Indicates this is the first post in a topic * @return string|\IPS\Content\Comment Progress message or comment object if first comment */ public function generateSingle(\IPS\Content\Item $topic, array $values, $first = FALSE) { $commentClass = static::$commentClass; /* Generate the author */ if ($first) { $member = $topic->author(); } elseif ($values['author']) { $member = $values['author']; } elseif ($values['author_type'] == 'random_fake') { $member = $this->generator->fakeMember(); } else { $member = $this->generator->guest(); } /* Create and save the post */ $obj = $commentClass::create($topic, $this->generator->comment(), $first, !$member->name ? NULL : $member->name, $topic->hidden() ? FALSE : NULL, $member); $obj->ip_address = $this->generator->ipAddress(); $obj->save(); if (!$first) { $this->map($commentClass, $obj->pid); } // Only map if this is NOT the first comment $itemClass = static::$itemClass; call_user_func_array(array('IPS\\File', 'claimAttachments'), array_merge(array('newContentItem-' . $topic::$application . '/' . $itemClass::$module . '-' . 0), $obj->attachmentIds())); return $first ? $obj : \IPS\Member::loggedIn()->language()->addToStack(static::$message, TRUE, array('sprintf' => array($topic->mapped('title')))); }
/** * 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'))); }
/** * Add Input * * @param \IPS\Helpers\Form\Abstract $input Form element to add * @param string|NULL $after The key of element to insert after * @param string|NULL $tab The tab to insert onto * @return void */ public function add($input, $after = NULL, $tab = NULL) { if ($this->langPrefix && !$input->label) { $input->label = \IPS\Member::loggedIn()->language()->addToStack("{$this->langPrefix}_{$input->name}"); } return call_user_func_array('parent::add', func_get_args()); }
/** * Show edit form * * @return void */ protected function edit() { if (!$this->marker->canEdit() and !\IPS\Request::i()->form_submitted) { \IPS\Output::i()->error('edit_no_perm_err', '2MM1/2', 403, ''); } $form = $this->marker->buildEditForm(); if ($values = $form->values()) { if ($this->marker->canEdit()) { $this->marker->processForm($values); /* Old custom markers did not store the author ID, update them now to the current member */ if ($this->marker->member_id == 0) { $this->marker->member_id = \IPS\Member::loggedIn()->member_id; } $this->marker->updated = time(); $this->marker->save(); $this->marker->processAfterEdit($values); \IPS\Output::i()->redirect($this->marker->url()); } else { $form->error = \IPS\Member::loggedIn()->language()->addToStack('edit_no_perm_err'); } } /* Display */ \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('membermap_edit_a_marker'); \IPS\Output::i()->sidebar['enabled'] = FALSE; \IPS\Output::i()->breadcrumb[] = array(NULL, \IPS\Member::loggedIn()->language()->addToStack('membermap_edit_a_marker')); \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('submit')->submitPage($form->customTemplate(array(call_user_func_array(array(\IPS\Theme::i(), 'getTemplate'), array('submit', 'membermap')), 'submitForm'))); }
/** * Show marker group index * * @return void */ protected function _index() { /* Online User Location */ \IPS\Session::i()->setLocation(\IPS\Http\Url::internal('app=membermap&module=markers&controller=groups', 'front', 'markers'), array(), 'loc_membermap_browsing_groups'); \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('membermap_marker_groups'); \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('markers')->index(); }
/** * Generate a fake member account * * @param array $values Generator form values * @return string Progress message */ public function generateSingle(array $values) { /* Create Member */ $member = new \IPS\Member(); $member->name = $values['__generator_message'] = $this->generator->userName(); $password = isset($values['password']) ? $member->name : $this->generator->password(); $member->email = $this->generator->email(); $member->members_pass_salt = $member->generateSalt(); $member->members_pass_hash = $member->encryptedPassword($password); $member->allow_admin_mails = 0; $member->member_group_id = $values['member_group']; $member->members_bitoptions['view_sigs'] = TRUE; if ($values['profile_photo']) { $photoUrl = new \IPS\Http\Url($this->generator->photoUrl()); $response = $photoUrl->request()->get(); $filename = preg_replace("/(.+?)(\\?|\$)/", "\$1", mb_substr((string) $photoUrl, mb_strrpos((string) $photoUrl, '/') + 1)); $photoFile = \IPS\File::create('core_Profile', $filename, $response); $member->pp_photo_type = 'custom'; $member->pp_main_photo = NULL; $member->pp_main_photo = (string) $photoFile; $thumbnail = $photoFile->thumbnail('core_Profile', \IPS\PHOTO_THUMBNAIL_SIZE, \IPS\PHOTO_THUMBNAIL_SIZE, TRUE); $member->pp_thumb_photo = (string) $thumbnail; } $member->save(); $this->map(static::$activeRecordClass, $member->member_id); return \IPS\Member::loggedIn()->language()->addToStack(static::$message, true, array('sprintf' => array($member->name))); }
/** * ... * * @return void */ protected function manage() { $defaultMaps = \IPS\membermap\Application::getEnabledMaps(); \IPS\Output::i()->jsVars['membermap_defaultMaps'] = $defaultMaps; \IPS\Output::i()->sidebar['actions']['preview'] = array('icon' => 'eye', 'link' => \IPS\Http\Url::external('https://leaflet-extras.github.io/leaflet-providers/preview/index.html'), 'title' => 'membermap_mapmanager_preview', 'target' => '_blank'); \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__membermap_membermap_mapmanager'); \IPS\Output::i()->output .= \IPS\Theme::i()->getTemplate('mapmanager')->wrapper(); }
/** * Process Form * * @param \IPS\Helpers\Form $form The form * @param \IPS\Member\Group $group Existing Group * @return void */ public function process(&$form, $group) { $bgColour = $group->g_membermap_markerColour ? $group->g_membermap_markerColour : 'darkblue'; /* Selected a valid colour? */ $bgColour = in_array($bgColour, $this->colours) ? $bgColour : 'darkblue'; foreach ($this->colours as $c) { $radioOpt[$c] = \IPS\Theme::i()->resource("awesome-marker-icon-{$c}.png", "membermap", 'admin'); } $form->add(new \IPS\Helpers\Form\Radio('g_membermap_markerColour', $bgColour, TRUE, array('options' => $radioOpt, 'parse' => 'image', 'descriptions' => array('white' => \IPS\Member::loggedIn()->language()->addToStack('group_pin_bg_colour_white'))))); }
/** * Bulk process generations * * @param array|null $values Form submission values * @return \IPS\Helpers\MultipleRedirect */ public function generateBulk($values = NULL) { $self = $this; $vCookie = static::$app . '_faker_' . static::$_controller . '_generator_values'; /* If this is a form submission, store our values now */ if ($values) { /* If we have a custom author defined, we need to save the ID manually for json encoding */ if (!empty($values['author']) and $values['author'] instanceof \IPS\Member) { $values['author'] = $values['author']->member_id; } $values['total'] = mt_rand($values['comment_range']['start'], $values['comment_range']['end']); unset(\IPS\Request::i()->cookie[$vCookie]); \IPS\Request::i()->setCookie($vCookie, json_encode($values)); } $values = $values ?: json_decode(\IPS\Request::i()->cookie[$vCookie], true); /* <sarcasm>Serialization is fun</sarcasm> @TODO: Clean this up */ if (!empty($values['author']) and is_int($values['author'])) { $values['author'] = \IPS\Member::load($values['author']); } if (!empty($values['item_url']) and is_array($values['item_url'])) { $values['item_url'] = \IPS\Http\Url::createFromArray($values['item_url']['data']); } /* Generate the MultipleRedirect page */ $perGo = isset($values['per_go']) ? (int) $values['per_go'] : 25; $reflect = new \ReflectionClass($this); $extension = $reflect->getShortName(); $processUrl = \IPS\Http\Url::internal("app=faker&module=generator&controller={$self::$_controller}&extApp={$self::$app}&extension={$extension}&do=process"); return new \IPS\Helpers\MultipleRedirect($processUrl, function ($doneSoFar) use($self, $perGo, $values, $vCookie) { /* Have we processed everything? */ if ($doneSoFar >= $values['total']) { return NULL; } /* Load our content item container */ $itemClass = $self::$itemClass; $item = $itemClass::loadFromUrl($values['item_url']); $count = 0; $limit = $values['total'] - $doneSoFar; $generated = array(); while ($count < $limit and count($generated) < $perGo) { ++$count; $generated[] = $self->generateSingle($item, $values); } $doneSoFar += $perGo; /* Update our session cookies and proceed to the next chunk */ \IPS\Request::i()->setCookie($vCookie, json_encode($values)); return array($doneSoFar, end($generated), 100 * $doneSoFar / $values['total']); }, function () use($self, $values, $extension) { \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=faker&module=generator&controller={$self::$_controller}&extApp={$self::$app}&extension={$extension}"), 'completed'); }); }
/** * Payment Screen */ public function paymentScreen(\IPS\Helpers\Form $form, $member, $donation) { /* Get any gateway settings */ $settings = json_decode($this->settings, TRUE); /* We need this before continuing */ if (!isset($settings['api_key']) or !isset($settings['api_secretkey']) or !isset($settings['widget_code'])) { return $form; } /* Init paymentwall */ $this->initPaymentwall($settings['api_key'], $settings['api_secretkey']); /* Setup widget */ $productNames[] = \IPS\Member::loggedIn()->language()->get('forum_donation'); $product = new \Paymentwall_Product("D1", $donation['amount'], $donation['currency'], implode(',', $productNames)); $widget = new \Paymentwall_Widget(\IPS\Member::loggedIn()->member_id, $settings['widget_code'], array($product), array('goal' => $donation['goal'])); /* Add widget to form */ $form->addHtml($widget->getHtmlCode()); return $form; }
public function formatValue() { if (in_array($this->htmlId, array('marker_lat', 'marker_lon'))) { $value = $this->value; $value = floatval($value); $value = round($value, 6); /* Convert decimal point and thousand separators to a way PHP understand */ $value = str_replace(trim(\IPS\Member::loggedIn()->language()->locale['thousands_sep']), '', $value); $value = str_replace(trim(\IPS\Member::loggedIn()->language()->locale['decimal_point']), '.', $value); /* If it's not numeric, throw an exception */ if (!is_numeric($value) and $value !== '' and $this->required === FALSE or !is_numeric($value) and $this->required === TRUE) { throw new \InvalidArgumentException('form_number_bad'); } return $value; } else { return parent::formatValue(); } }
/** * Display the generator form * * @return void */ protected function manage() { list($ext, $extApp, $extension, $controller) = $this->extData(); /* Build the generator form */ $form = new \IPS\faker\Decorators\Form('form', 'faker_form_generate', \IPS\Http\Url::internal("app=faker&module=generator&controller={$controller}&extApp={$extApp}&extension={$extension}")); $form->langPrefix = "{$extApp}_faker_{$controller}"; $ext->buildGenerateForm($form); /* Cycle field */ $cycle = new \IPS\Helpers\Form\Number('per_go', $ext::$cycleDefault, TRUE, array('min' => 1)); $cycle->label = \IPS\Member::loggedIn()->language()->addToStack('faker_perGo'); $form->add($cycle); if ($values = $form->values()) { \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('faker_generator_title', true, array('sprintf' => \IPS\Member::loggedIn()->language()->addToStack("menu__faker_{$extApp}_{$extension}"))); \IPS\Output::i()->output = (string) $ext->generateBulk($values); return; } \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack($ext::$title); \IPS\Output::i()->output = $form; }
/** * ... * * @return void */ protected function manage() { \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__membermap_membermap_settings'); \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('jquery/jquery-ui.js', 'membermap', 'interface')); \IPS\Output::i()->jsFiles = array_merge(\IPS\Output::i()->jsFiles, \IPS\Output::i()->js('admin_membermap.js', 'membermap', 'admin')); \IPS\Output::i()->cssFiles = array_merge(\IPS\Output::i()->cssFiles, \IPS\Theme::i()->css('jquery-ui.css', 'membermap', 'global')); \IPS\Output::i()->jsVars['membermap_mapquestAPI'] = \IPS\membermap\Application::getApiKeys('mapquest'); $form = new \IPS\Helpers\Form(); $form->addHeader('api_settings'); $form->add(new \IPS\Helpers\Form\Text('membermap_mapQuestAPI', \IPS\Settings::i()->membermap_mapQuestAPI, TRUE, array(), NULL, NULL, NULL, 'membermap_mapQuestAPI')); if (!empty(\IPS\Settings::i()->membermap_mapQuestAPI)) { $form->attributes['data-controller'] = 'membermap.admin.membermap.settings'; $form->attributes['id'] = 'membermap_form_settings'; $form->addHeader('map_settings'); $form->add(new \IPS\Helpers\Form\YesNo('membermap_groupByMemberGroup', \IPS\Settings::i()->membermap_groupByMemberGroup)); $form->add(new \IPS\Helpers\Form\YesNo('membermap_enable_clustering', \IPS\Settings::i()->membermap_enable_clustering)); $form->add(new \IPS\Helpers\Form\Text('membermap_bbox_location', \IPS\Settings::i()->membermap_bbox_location, FALSE, array(), NULL, NULL, NULL, 'membermap_bbox_location')); $form->add(new \IPS\Helpers\Form\Number('membermap_bbox_zoom', intval(\IPS\Settings::i()->membermap_bbox_zoom), FALSE, array('min' => 1, 'max' => 18))); $form->hiddenValues['membermap_bbox'] = \IPS\Settings::i()->membermap_bbox; $form->addHeader('membermap_autoUpdate'); $profileFields = array('' => ' -- ' . \IPS\Member::loggedIn()->language()->addToStack('membermap_profileLocationField') . ' -- '); foreach (\IPS\core\ProfileFields\Field::fields(array(), \IPS\core\ProfileFields\Field::PROFILE) as $group => $fields) { foreach ($fields as $id => $field) { $profileFields['core_pfieldgroups_' . $group][$id] = $field->name; } } $form->add(new \IPS\Helpers\Form\YesNo('membermap_monitorLocationField', \IPS\Settings::i()->membermap_monitorLocationField, FALSE, array('togglesOn' => array('membermap_profileLocationField', 'membermap_monitorLocationField_groupPerm', 'membermap_syncLocationField')))); $form->add(new \IPS\Helpers\Form\Select('membermap_profileLocationField', \IPS\Settings::i()->membermap_profileLocationField ? intval(\IPS\Settings::i()->membermap_profileLocationField) : NULL, FALSE, array('options' => $profileFields), NULL, NULL, NULL, 'membermap_profileLocationField')); $form->add(new \IPS\Helpers\Form\Select('membermap_monitorLocationField_groupPerm', \IPS\Settings::i()->membermap_monitorLocationField_groupPerm != '' ? \IPS\Settings::i()->membermap_monitorLocationField_groupPerm === '*' ? '*' : explode(",", \IPS\Settings::i()->membermap_monitorLocationField_groupPerm) : '*', FALSE, array('options' => \IPS\Member\Group::groups(), 'multiple' => TRUE, 'parse' => 'normal', 'unlimited' => '*', 'unlimitedLang' => 'all'), NULL, NULL, NULL, 'membermap_monitorLocationField_groupPerm')); $form->add(new \IPS\Helpers\Form\YesNo('membermap_syncLocationField', \IPS\Settings::i()->membermap_syncLocationField, FALSE, array(), NULL, NULL, NULL, 'membermap_syncLocationField')); } if ($values = $form->values(TRUE)) { $values['membermap_bbox'] = \IPS\Request::i()->membermap_bbox; if (empty($values['membermap_bbox_location'])) { $values['membermap_bbox'] = ""; } \IPS\DB::i()->update('core_tasks', array('enabled' => isset($values['membermap_syncLocationField']) and $values['membermap_syncLocationField'] ? 1 : 0), array('`key`=?', 'locationSync')); $form->saveAsSettings($values); \IPS\Session::i()->log('acplogs__membermap_settings'); \IPS\Output::i()->redirect(\IPS\Http\Url::internal("app=membermap&module=membermap&controller=settings"), 'saved'); } \IPS\Output::i()->output = $form; }
/** * 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; }
/** * Submit Event * * @return void */ protected function manage() { $group = NULL; if (isset(\IPS\Request::i()->group)) { try { $group = \IPS\membermap\Markers\Groups::loadAndCheckPerms(\IPS\Request::i()->group); \IPS\Output::i()->breadcrumb[] = array(\IPS\Http\Url::internal('app=membermap&module=groups&controller=groups&id=' . $group->_id, 'front', 'markers_group', $group->name_seo), $group->_title); } catch (\OutOfRangeException $e) { } } $form = \IPS\membermap\Markers\Markers::create($group); if (\IPS\membermap\Markers\Markers::moderateNewItems(\IPS\Member::loggedIn())) { $form = \IPS\Theme::i()->getTemplate('forms', 'core')->modQueueMessage(\IPS\Member::loggedIn()->warnings(5, NULL, 'mq'), \IPS\Member::loggedIn()->mod_posts) . $form; } /* Display */ \IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('membermap_submit_a_marker'); \IPS\Output::i()->sidebar['enabled'] = FALSE; \IPS\Output::i()->breadcrumb[] = array(NULL, \IPS\Member::loggedIn()->language()->addToStack('membermap_submit_a_marker')); \IPS\Output::i()->output = \IPS\Theme::i()->getTemplate('submit')->submitPage($form->customTemplate(array(call_user_func_array(array(\IPS\Theme::i(), 'getTemplate'), array('submit', 'membermap')), 'submitForm'))); }
/** * Get API keys * Currently it only serves MapQuest, but others may be added in the future * * @param string $service Name of the service, will return all keys if param is empty * @return mixed Single API key, or all in an array */ public static function getApiKeys($service) { if (!isset(static::$apiKeys['mapquest'])) { if (\IPS\Settings::i()->membermap_mapQuestAPI) { static::$apiKeys['mapquest'] = \IPS\Settings::i()->membermap_mapQuestAPI; } } if (\IPS\Dispatcher::i()->controllerLocation == 'front' and (!isset(static::$apiKeys['mapquest']) or empty(static::$apiKeys['mapquest']))) { if (\IPS\Member::loggedIn()->isAdmin()) { \IPS\Output::i()->error('membermap_noAPI_admin', '4MM5/1', 401); } else { \IPS\Output::i()->error('401_error_title', '4MM5/2', 401); } } try { if ($service) { return static::$apiKeys[$service]; } } catch (\Exception $e) { } return static::$apiKeys; }
/** * Member account has been updated * * @param $member \IPS\Member Member updating profile * @param $changes array The changes * @return void */ public function onProfileUpdate($member, $changes) { /* An endless loop is formed when \Item::createItem() is saving \Member, which then fire this membersync, which then calls \Item::createItem, and so on, and so on */ static $wereDoneHere = false; if ($wereDoneHere) { return; } $wereDoneHere = true; if (isset($changes['name'])) { $existingMarker = \IPS\membermap\Map::i()->getMarkerByMember($member->member_id, FALSE, FALSE); if ($existingMarker instanceof \IPS\membermap\Markers\Markers) { $existingMarker->name = $member->name; $existingMarker->updated = time(); $existingMarker->save(); } } if (count($changes) and \IPS\Settings::i()->membermap_monitorLocationField and !$member->members_bitoptions['bw_is_spammer']) { if (\IPS\Settings::i()->membermap_monitorLocationField_groupPerm === '*' or \IPS\Member::loggedIn()->inGroup(explode(',', \IPS\Settings::i()->membermap_monitorLocationField_groupPerm))) { if (isset($changes['field_' . \IPS\Settings::i()->membermap_profileLocationField]) and !empty($changes['field_' . \IPS\Settings::i()->membermap_profileLocationField])) { try { $lat = $lng = $location = NULL; $fieldValue = $changes['field_' . \IPS\Settings::i()->membermap_profileLocationField]; /* If it's an array, it might be from an address field, which already have the lat/lng data */ if (is_array(json_decode($fieldValue, TRUE))) { $addressData = json_decode($fieldValue, 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 */ $fieldValue = preg_replace("/[\\x00-\\x20]|\\xc2|\\xa0+/", ' ', strip_tags($fieldValue)); $fieldValue = trim(preg_replace("/\\s\\s+/", ' ', $fieldValue)); /* 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($fieldValue); if (is_array($nominatim) and count($nominatim)) { $lat = $nominatim['lat']; $lng = $nominatim['lng']; $location = $nominatim['location']; } } if ($lat and $lng) { $existingMarker = \IPS\membermap\Map::i()->getMarkerByMember($member->member_id, FALSE); if ($existingMarker instanceof \IPS\membermap\Markers\Markers) { $marker = $existingMarker; $marker->updated = time(); } else { $groupId = \IPS\membermap\Map::i()->getMemberGroupId(); $marker = \IPS\membermap\Markers\Markers::createItem($member, \IPS\Request::i()->ipAddress(), new \IPS\DateTime(), \IPS\membermap\Markers\Groups::load($groupId)); } $marker->name = $member->name; $marker->lat = $lat; $marker->lon = $lng; $marker->location = $location ?: $fieldValue; /* Save and add to search index */ $marker->save(); \IPS\Content\Search\Index::i()->index($marker); } } catch (\Exception $e) { /* Something went wrong. Such as the input field being an editor */ \IPS\Log::log($e, 'membermap'); return false; } } } } }
/** * Link Account * * @param \IPS\Member $member The member * @param mixed $details Details as they were passed to the exception thrown in authenticate() * @return void */ public static function link( \IPS\Member $member, $details ) { try { $userData = \IPS\Http\Url::external( "https://api.vk.com/method/getProfiles?uid={$details[1]}&access_token={$details[0]}&fields=first_name,last_name,screen_name,bdate,nickname" )->request()->get()->decodeJson(); $userData = $userData['response'][0]; $member->vk_id = $details[1]; $member->vk_token = $details[0]; $member->save(); }catch(\Exception $e) {} }
/** * 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())); }
/** * 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; }
/** * Generate a fake forum topic * * @param \IPS\Node\Model $forum The forum container * @param array $values Generator form values * @return string Progress message */ public function generateSingle(\IPS\Node\Model $forum = null, array $values) { $itemClass = static::$itemClass; $tagsContainer = $values['add_tags'] ? $this->generator->tags() : array('tags' => null, 'prefix' => null); /* Generate the author */ if ($values['author']) { $member = $values['author']; } elseif ($values['author_type'] == 'random_fake') { $member = $this->generator->fakeMember(); } else { $member = $this->generator->guest(); } /* Assign topic values */ $topicValues = array('topic_title' => $this->generator->title(), 'topic_content' => $this->generator->comment(), 'topic_tags' => $tagsContainer['tags'], 'topic_tags_prefix' => $tagsContainer['prefix'], 'topic_create_state' => $values['after_posting']); /* Create and save the topic */ $itemClass = static::$itemClass; $obj = $itemClass::createItem($member, $ipAddress = $this->generator->ipAddress(), new \IPS\DateTime(), $forum); $obj->processForm($topicValues); $obj->save(); $this->map(static::$itemClass, $obj->tid); /* Create and save the first post in the topic */ $comment = $this->commentExt()->generateSingle($obj, $values, TRUE); /* Create any additional posts if necessary */ if ($values['add_comments']) { $postCount = mt_rand($values['comment_range']['start'], $values['comment_range']['end']); for ($pc = 0; $pc < $postCount; $pc++) { $this->commentExt()->generateSingle($obj, $values); } } /* Claim attachments and map the first comment ID */ $commentClass = $itemClass::$commentClass; $commentIdColumn = $commentClass::$databaseColumnId; call_user_func_array(array('IPS\\File', 'claimAttachments'), array_merge(array('newContentItem-' . \IPS\forums\Topic::$application . '/' . \IPS\forums\Topic::$module . '-' . ($forum ? $forum->_id : 0)), $comment->attachmentIds())); if (isset(\IPS\forums\Topic::$databaseColumnMap['first_comment_id'])) { $firstCommentIdColumn = \IPS\forums\Topic::$databaseColumnMap['first_comment_id']; $obj->{$firstCommentIdColumn} = $comment->{$commentIdColumn}; $obj->save(); } return \IPS\Member::loggedIn()->language()->addToStack(static::$message, TRUE, array('sprintf' => array($forum->_title))); }
/** * Generate a random guest member object * * @return \IPS\Member */ public function guest() { $member = \IPS\Member::load(0); $member->name = $this->userName(); return $member; }
/** * Check permissions * * @param mixed $permission A key which has a value in static::$permissionMap['view'] matching a column ID in core_permission_index * @param \IPS\Member|\IPS\Member\Group|NULL $member The member or group to check (NULL for currently logged in member) * @return bool * @throws \OutOfBoundsException If $permission does not exist in static::$permissionMap */ public function can($permission, $member = NULL) { $parent = parent::can($permission, $member); if ($parent === TRUE) { $_member = $member ?: \IPS\Member::loggedIn(); if ($this->type == 'member' and $permission == 'add') { $existing = \IPS\membermap\Map::i()->getMarkerByMember($_member->member_id, FALSE); return isset($existing) and $existing !== FALSE ? FALSE : TRUE; } } return $parent; }
/** * Build a dynamic set of query schema elements for use in individual query types * * @param $form * @param string $prefix * @param array $noAutoToggle * @param array $exclude * @param array $defaults */ protected function _buildQueryBoxSchema(&$form, $prefix = 'database_', $noAutoToggle = array(), $exclude = array(), $defaults = array()) { $toggles = array('TINYINT' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_auto_increment", "{$prefix}column_default"), 'SMALLINT' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_auto_increment", "{$prefix}column_default"), 'MEDIUMINT' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_auto_increment", "{$prefix}column_default"), 'INT' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_auto_increment", "{$prefix}column_default"), 'BIGINT' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_auto_increment", "{$prefix}column_default"), 'DECIMAL' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_decimals", "{$prefix}column_default"), 'FLOAT' => array("{$prefix}column_length", "{$prefix}column_unsigned", "{$prefix}column_zerofill", "{$prefix}column_decimals", "{$prefix}column_default"), 'BIT' => array("{$prefix}column_length", "{$prefix}column_default"), 'DATE' => array("{$prefix}column_default"), 'DATETIME' => array("{$prefix}column_default"), 'TIMESTAMP' => array("{$prefix}column_default"), 'TIME' => array("{$prefix}column_default"), 'YEAR' => array("{$prefix}column_default"), 'CHAR' => array("{$prefix}column_length", "{$prefix}column_binary", "{$prefix}column_default"), 'VARCHAR' => array("{$prefix}column_length", "{$prefix}column_binary", "{$prefix}column_default"), 'TINYTEXT' => array("{$prefix}column_binary"), 'TEXT' => array("{$prefix}column_binary"), 'MEDIUMTEXT' => array("{$prefix}column_binary"), 'LONGTEXT' => array("{$prefix}column_binary"), 'BINARY' => array("{$prefix}column_length", "{$prefix}column_default"), 'VARBINARY' => array("{$prefix}column_length", "{$prefix}column_default"), 'TINYBLOB' => array(), 'BLOB' => array(), 'MEDIUMBLOB' => array(), 'BIGBLOB' => array(), 'ENUM' => array("{$prefix}column_values", "{$prefix}column_default"), 'SET' => array("{$prefix}column_values", "{$prefix}column_default")); if ($noAutoToggle) { foreach ($toggles as &$toggle) { foreach ($noAutoToggle as $toBeRemoved) { if (($key = array_search($prefix . $toBeRemoved, $toggle)) !== false) { unset($toggle[$key]); } } } } $elements = array(); $elements[] = new \IPS\Helpers\Form\Select("{$prefix}column_type", 'VARCHAR', TRUE, array('options' => \IPS\Db::$dataTypes, 'toggles' => $toggles)); $elements[] = new \IPS\Helpers\Form\Number("{$prefix}column_length", -1, FALSE, array('unlimited' => -1, 'unlimitedLang' => 'no_value'), NULL, NULL, NULL, "{$prefix}column_length"); $elements[] = new \IPS\Helpers\Form\Number("{$prefix}column_decimals", -1, FALSE, array('unlimited' => -1, 'unlimitedLang' => 'no_value'), NULL, NULL, NULL, "{$prefix}column_decimals"); $elements[] = new \IPS\Helpers\Form\Stack("{$prefix}column_values", NULL, FALSE, array(), NULL, NULL, NULL, "{$prefix}column_values"); $elements[] = new \IPS\Helpers\Form\YesNo("{$prefix}column_allow_null", FALSE, TRUE); $elements[] = new \IPS\Helpers\Form\TextArea("{$prefix}column_default", NULL, FALSE, array('nullLang' => 'NULL'), NULL, NULL, NULL, "{$prefix}column_default"); $elements[] = new \IPS\Helpers\Form\TextArea("{$prefix}column_comment", NULL, FALSE); $elements[] = new \IPS\Helpers\Form\YesNo("{$prefix}column_unsigned", TRUE, FALSE, array(), NULL, NULL, NULL, "{$prefix}column_unsigned"); $elements[] = new \IPS\Helpers\Form\YesNo("{$prefix}column_zerofill", FALSE, FALSE, array(), NULL, NULL, NULL, "{$prefix}column_zerofill"); $elements[] = new \IPS\Helpers\Form\YesNo("{$prefix}column_auto_increment", FALSE, FALSE, array(), NULL, NULL, NULL, "{$prefix}column_auto_increment"); $elements[] = new \IPS\Helpers\Form\YesNo("{$prefix}column_binary", FALSE, FALSE, array(), NULL, NULL, NULL, "{$prefix}column_binary"); $lang = \IPS\Member::loggedIn()->language(); foreach ($elements as $element) { // Trim the prefix so we can replace the label with the standard database_ language string $label = mb_substr($element->name, mb_strlen($prefix)); $element->label = $lang->addToStack("database_{$label}"); // Is this element being excluded? if (in_array($label, $exclude)) { continue; } // Do we have a custom default value for this element? if (isset($defaults[$label])) { $element->defaultValue = $defaults[$label]; $element->setValue(TRUE); } $form->add($element); } }
$_SERVER['SCRIPT_FILENAME'] = __FILE__; $path = ''; require_once $path . 'init.php'; \IPS\Session\Front::i(); $key = md5(md5(\IPS\Settings::i()->sql_user . \IPS\Settings::i()->sql_pass) . \IPS\Settings::i()->board_start); $login_type = 'email'; /* Alowed IP addresses, uncomment for more security */ // $ip_address = array('x.x.x.x'); // EDIT THIS LINE!! /* -~-~-~-~-~-~ Stop Editing -~-~-~-~-~-~ */ if (isset($ip_address) and in_array($_SERVER['REMOTE_ADDR'], $ip_address) !== TRUE) { \IPS\Output::i()->json(array('status' => 'FAILD', 'msg' => 'BAD_IP_ADDR')); } if (!\IPS\Request::i()->do || !\IPS\Request::i()->id || !\IPS\Request::i()->key || !\IPS\Login::compareHashes(\IPS\Request::i()->key, md5($key . \IPS\Request::i()->id))) { \IPS\Output::i()->json(array('status' => 'FAILD', 'msg' => 'BAD_KEY')); } $member = \IPS\Member::load(\IPS\Request::i()->id, $login_type); if (!$member->member_id) { \IPS\Output::i()->json(array('status' => 'FAILD', 'msg' => 'ACCOUNT_NOT_FOUND')); } switch (\IPS\Request::i()->do) { case 'get_salt': \IPS\Output::i()->json(array('status' => 'SUCCESS', 'pass_salt' => $member->members_pass_salt)); break; case 'login': if (\IPS\Login::compareHashes($member->members_pass_hash, \IPS\Request::i()->password) === TRUE) { \IPS\Output::i()->json(array('status' => 'SUCCESS', 'connect_status' => $member->members_bitoptions['validating'] ? 'VALIDATING' : 'SUCCESS', 'email' => $member->email, 'name' => $member->name, 'connect_id' => $member->member_id)); } break; case 'field': $fields = $member->profileFields(); if (isset($fields['core_pfieldgroups_' . \IPS\Request::i()->fgroup]) and isset($fields['core_pfieldgroups_' . \IPS\Request::i()->fgroup]['core_pfield_' . \IPS\Request::i()->fid])) {
/** * Get Title * * @return string */ public function title() { return \IPS\Member::loggedIn()->language()->addToStack('frontnavigation_membermap'); }
/** * Delete a marker * * @return void */ protected function delete() { \IPS\Session::i()->csrfCheck(); if (!\IPS\Member::loggedIn()->member_id or !intval(\IPS\Request::i()->member_id)) { \IPS\Output::i()->error('no_permission', '2MM3/4', 403, ''); } /* Get the marker */ $existing = \IPS\membermap\Map::i()->getMarkerByMember(intval(\IPS\Request::i()->member_id), FALSE); if (isset($existing)) { $is_supmod = \IPS\Member::loggedIn()->modPermission() ?: 0; if ($is_supmod or $existing->mapped('author') == \IPS\Member::loggedIn()->member_id and $existing->canDelete()) { $existing->delete(); \IPS\Output::i()->json('OK'); } } /* Fall back to a generic error */ \IPS\Output::i()->error('no_permission', '2MM3/5', 403, ''); }
public static function create($item, $comment, $first = FALSE, $guestName = NULL, $incrementPostCount = NULL, $member = NULL, \IPS\DateTime $time = NULL) { $topic = $item; if ($member === NULL) { $member = \IPS\Member::loggedIn(); } if (isset($_POST['topic_title'])) { $comment = $_POST['topic_title'] . "\n" . $comment; } $access_key = \IPS\Settings::i()->access_key; if (isset($member) && !$member->isAdmin() && $member->member_posts <= 10 && \IPS\Settings::i()->moderate_new == 1) { require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/cleantalk.class.php"; require_once dirname($_SERVER['SCRIPT_FILENAME']) . "/uploads/JSON.php"; session_name('cleantalksession'); if (!isset($_SESSION)) { session_start(); } if (array_key_exists('formtime', $_SESSION)) { $submit_time = time() - (int) $_SESSION['formtime']; } else { $submit_time = NULL; } $_SESSION['formtime'] = time(); $post_info = ''; $lang = \IPS\Lang::getEnabledLanguages(); $locale = $lang[\IPS\Lang::defaultLanguage()]->short; if (function_exists('json_encode')) { $arr = array('cms_lang' => $locale, 'REFFERRER' => $_SERVER['HTTP_REFERER'], 'USER_AGENT' => $_SERVER['HTTP_USER_AGENT']); $post_info = json_encode($arr); } if ($post_info === FALSE) { $post_info = ''; } $ct_url = 'http://moderate.cleantalk.ru'; $config_work_url = $ct_url; $config_ttl = 43200; $config_changed = 1349162987; $config_key = $access_key; $ct = new \Cleantalk(); $ct->work_url = $config_work_url; $ct->server_url = $ct_url; $ct->server_ttl = $config_ttl; $ct->server_changed = $config_changed; $sender_email = filter_var($member->email, FILTER_SANITIZE_EMAIL); $sender_ip = $ct->ct_session_ip($_SERVER['REMOTE_ADDR']); $ct_request = new \CleantalkRequest(); $ct_request->auth_key = $config_key; if (isset($_POST['guest_name'])) { $ct_request->sender_nickname = $_POST['guest_name']; } else { $ct_request->sender_nickname = $member->name; } $ct_request->sender_ip = $sender_ip; $ct_request->sender_email = $sender_email; $ct_request->sender_info = $post_info; $ct_request->agent = 'ipboard4-18'; $js_keys = array(); for ($i = -5; $i <= 1; $i++) { $js_keys[] = md5(\IPS\Settings::i()->access_key . '+' . \IPS\Settings::i()->email_in . date("Ymd", time() + 86400 * $i)); } $ct_request->js_on = in_array($_COOKIE['ct_checkjs'], $js_keys) ? 1 : 0; $ct_request->submit_time = $submit_time; $ct_request->message = $comment; $ct_result = $ct->isAllowMessage($ct_request); if (isset($ct_result->errno) && $ct_result->errno > 0) { //sendErrorMessage("CleanTalk has some problems, errno is ".$ct_result->errno.", errstr is '".$ct_result->errstr."'") } if ($ct_result->allow == 1) { // Not spammer. //call_user_func_array( 'parent::save', func_get_args() ); return call_user_func_array('parent::create', func_get_args()); } else { if (isset($_POST['topic_title'])) { $topic->delete(); } if (\IPS\Request::i()->isAjax()) { $result = array("type" => "error", "message" => $ct_result->comment); $result = json_encode($result); \IPS\Output::i()->sendOutput($result, 200, "application/json"); } else { \IPS\Output::i()->sidebar['enabled'] = FALSE; \IPS\Output::i()->sendOutput(\IPS\Theme::i()->getTemplate('global', 'core')->globalTemplate("Forbidden", \IPS\Theme::i()->getTemplate('global', 'core')->error("Forbidden", $ct_result->comment, 1, ""), array('app' => \IPS\Dispatcher::i()->application ? \IPS\Dispatcher::i()->application->directory : NULL, 'module' => \IPS\Dispatcher::i()->module ? \IPS\Dispatcher::i()->module->key : NULL, 'controller' => \IPS\Dispatcher::i()->controller)), 200, 'text/html', array(), FALSE, FALSE); } die; return call_user_func_array('parent::create', func_get_args()); } } return call_user_func_array('parent::create', func_get_args()); }
<?php /** * @author Sijad aka Mr.Wosi * @link <a href='http://skinod.com'>Skinod.com</a> * @copyright 2015 <a href='http://skinod.com'>Skinod.com</a> */ /** * Path to your IP.Board directory with a trailing / */ $_SERVER['SCRIPT_FILENAME'] = __FILE__; $path = ''; require_once $path . 'init.php'; \IPS\Session\Front::i(); if (\IPS\Member::loggedIn()->member_id) { \IPS\Member::loggedIn()->skin = (int) \IPS\Request::i()->id; \IPS\Member::loggedIn()->save(); } else { \IPS\Request::i()->setCookie('theme', (int) \IPS\Request::i()->id); } /* Make sure VSE cookie is killed */ if (isset(\IPS\Request::i()->cookie['vseThemeId'])) { \IPS\Request::i()->setCookie('vseThemeId', 0); } \IPS\Output::i()->redirect(\IPS\Http\Url::internal(''));
/** * Test Settings * * @return bool * @throws \IPS\Http\Request\Exception * @throws \UnexpectedValueException If response code is not 200 */ public function testSettings() { if ($this->settings['api_key']) { try { $response = \IPS\Http\Url::external("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={$this->settings['api_key']}&steamids=")->request()->get(); if ($response->httpResponseCode != 200) { throw new \InvalidArgumentException(\IPS\Member::loggedIn()->language()->addToStack('login_3p_bad', false, array('sprintf' => array(\IPS\Member::loggedIn()->language()->addToStack('login_handler_steam'))))); } } catch (\IPS\Http\Request\Exception $e) { throw new \InvalidArgumentException(\IPS\Member::loggedIn()->language()->addToStack('login_3p_bad', false, array('sprintf' => array(\IPS\Member::loggedIn()->language()->addToStack('login_handler_steam'))))); } } return true; }