Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class page_profile_settings
- {
- /**
- * UserProfile instance.
- *
- * @var UserProfile
- */
- protected $user;
- /**
- * Initializer.
- *
- * @return void
- */
- public function __init()
- {
- if (!login::$logged_in)
- redirect::handle('');
- login::$user->check_banned();
- $this->user = UserProfile::get(login::$user->data['username']);
- if (isset($_POST['about'])) {
- $this->handleForm();
- }
- $this->printForm();
- base::$b->page->add_content_right('<div class="panel panel-red">
- <div class="panel-heading">
- <h3 class="panel-title"><i class="fa fa-cog"></i> '.base::$b->lb->word('settings/more').'</h3>
- </div>
- <div class="panel-body">
- <ul class="menu-list">
- <li><a href="'.redirect::url('settings').'"><i class="fa fa-angle-double-right"></i> '.base::$b->lb->word('settings/more/edit').'</a></li>
- <li><a href="'.redirect::url(['security', 'change-password']).'"><i class="fa fa-angle-double-right"></i> '.base::$b->lb->word('settings/more/password').'</a></li>
- <li><a href="'.redirect::url(['security', 'login-sessions']).'"><i class="fa fa-angle-double-right"></i> '.base::$b->lb->word('settings/more/security').'</a></li>
- </ul>
- </div>
- </div>');
- base::$b->page->title_prepend(''.base::$b->lb->word('settings/profile/title').' • ');
- base::$b->page->theme_instance->menu_active = 'me';
- base::$b->page->load();
- }
- /**
- * @return void
- */
- protected function handleForm()
- {
- $set = [];
- $errors = [];
- $about = trim($_POST['about']);
- $maxAboutLength = $this->user->extUnlocked('FancyBio') ? 2000 : 140;
- if (mb_strlen($about) > $maxAboutLength) {
- $errors[] = ''.base::$b->lb->word('settings/profile/warning/1').' '.$maxAboutLength.' '.base::$b->lb->word('settings/profile/warning/2').'';
- } else {
- $set[] = "about_text = ".base::$b->db->quote($about);
- }
- if ($this->user->extUnlocked('Stats') && isset($_POST['city']) && mb_strlen($_POST['city']) <= 30) {
- $set[] = "profile_city = ".base::$b->db->quote($_POST['city']);
- }
- if ($this->user->extUnlocked('FancyName') && isset($_POST['link_style'], UserProfile::$userLinkStyles[$_POST['link_style']])) {
- $set[] = "link_style = ".(int)$_POST['link_style'];
- }
- if ($this->user->extUnlocked('Avatar') && isset($_POST['avatar'])) {
- $set[] = "avatar_img = ".base::$b->db->quote($_POST['avatar']);
- }
- if ($this->user->extUnlocked('YouTube') && isset($_POST['youtube']) && $_POST['youtube'] != $this->user->data['youtube_id']) {
- $v = $_POST['youtube'] == ''
- ? ''
- : $this->parseYouTubeId($_POST['youtube']);
- if ($v === false) {
- $errors[] = ''.base::$b->lb->word('settings/profile/warning/3').'';
- } else {
- $set[] = "youtube_id = ".base::$b->db->quote($v);
- }
- }
- if ($this->user->extUnlocked('CoverBg') && isset($_POST['cover'])) {
- $set[] = "cover_img = ".base::$b->db->quote($_POST['cover']);
- }
- if ($errors) {
- base::$b->page->add_message(implode('<br>', $errors), 'error');
- return;
- }
- if (!$set) {
- return;
- }
- base::$b->db->query(
- "UPDATE user_profile
- SET ".implode(', ', $set)."
- WHERE u_id = {$this->user->id}");
- base::$b->page->add_message(''.base::$b->lb->word('settings/profile/saved').'', 'info');
- redirect::handle();
- }
- /**
- * @return void
- */
- protected function printForm()
- {
- if (!$this->user->exts) {
- echo '<div class="alert alert-red" style="font-size: 16px;">'.base::$b->lb->word('settings/profile/goto').' <a href="'.redirect::url(['shop', 'profile']).'" class="alert-link"><strong><u>'.base::$b->lb->word('dashboard/menu/shop').'</u></strong></a> '.base::$b->lb->word('settings/profile/buymore').'<br><a href="'.redirect::url(['shop', 'profile']).'" class="btn btn-blue btn-lg" style="margin-top: 10px;">'.base::$b->lb->word('settings/profile/goto/button').'</a></div>';
- }
- echo '
- <div class="panel panel-primary">
- <div class="panel-heading">
- <h3 class="panel-title"><i class="fa fa-cog"></i> '.base::$b->lb->word('settings/profile/title/edit').'</h3>
- </div>
- <div class="panel-body">
- <div class="alert alert-orange" style="font-size: 12px;">'.base::$b->lb->text('settings/profile/guide/1').'</div>
- <boxes />
- <form method="post" action="'.redirect::url().'" role="form">';
- if ($this->user->extUnlocked('FancyName')) {
- echo '
- <div class="form-group">
- <label style="display: block;">'.base::$b->lb->word('settings/profile/fancyname').'</label>';
- foreach (UserProfile::$userLinkStyles as $i => $s) {
- echo '
- <label style="margin-right: 60px;">
- <input type="radio" name="link_style" value="'.$i.'"'.(
- $i == $this->user->data['link_style']
- ? 'checked' : '').'>
- <span style="font-size: 18px; color: #'.$s['color'].'; background: url('.__URL_STATIC__.'/dashboard/img/userLinkStyles/'.$s['bgImg'].') center;">
- '.htmlspecialchars($this->user->data['username']).'
- </span>
- </label>';
- }
- echo '
- </div>';
- }
- if ($this->user->extUnlocked('Stats')) {
- echo '
- <div class="form-group">
- <label for="city">'.base::$b->lb->word('settings/profile/city').'</label>
- <input type="text" class="form-control" name="city" id="city" value="'.formval('city', $this->user->data['profile_city']).'">
- </div>';
- }
- if ($this->user->extUnlocked('Avatar')) {
- echo '
- <div class="form-group">
- <label for="avatar">'.base::$b->lb->word('settings/profile/avatar').'</label>
- <input type="text" class="form-control" name="avatar" id="avatar" value="'.formval('avatar', $this->user->data['avatar_img']).'">
- <span class="help-block">'.base::$b->lb->text('settings/profile/help/url').'</span>
- </div>';
- }
- if ($this->user->extUnlocked('YouTube')) {
- echo '
- <div class="form-group">
- <label for="youtube">'.base::$b->lb->word('settings/profile/youtube').'</label>
- <input type="text" class="form-control" name="youtube" id="youtube" value="'.formval('youtube', $this->user->data['youtube_id']).'">
- <span class="help-block">'.base::$b->lb->word('settings/profile/help/youtube').'</span>
- </div>';
- }
- if ($this->user->extUnlocked('CoverBg')) {
- echo '
- <div class="form-group">
- <label for="cover">'.base::$b->lb->word('settings/profile/background').'</label>
- <input type="text" class="form-control" name="cover" id="cover" value="'.formval('cover', $this->user->data['cover_img']).'">
- <span class="help-block">'.base::$b->lb->text('settings/profile/help/url').'</span>
- </div>';
- }
- echo '
- <div class="form-group">
- <label for="about">'.base::$b->lb->word('settings/profile/about').'</label>
- <textarea class="form-control" name="about" id="about" rows="5">'.formval('about', $this->user->data['about_text']).'</textarea>';
- if (!$this->user->extUnlocked('FancyBio')) {
- echo '
- <span class="help-block">'.base::$b->lb->text('settings/profile/buy').'</span>';
- }
- else
- {
- echo '<span class="help-block">'.base::$b->lb->text('settings/profile/guide/2').'</span>';
- }
- echo '
- </div>';
- echo '
- '.csrf::html_input().'
- <button type="submit" class="btn btn-green btn-lg"><i class="fa fa-save"></i> '.base::$b->lb->word('settings/save').'</button>
- </form>
- </div>
- </div>';
- }
- /**
- * @param string $url
- * @return string|bool
- */
- protected function parseYouTubeId($url)
- {
- $query = parse_url($url, PHP_URL_QUERY);
- if (!$query) {
- return false;
- }
- parse_str($query, $queryData);
- if (!isset($queryData['v']) || strlen($queryData['v']) !== 11) {
- return false;
- }
- return $queryData['v'];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement