Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. <?php
  2.  
  3. class page_profile_settings
  4. {
  5. /**
  6. * UserProfile instance.
  7. *
  8. * @var UserProfile
  9. */
  10. protected $user;
  11.  
  12. /**
  13. * Initializer.
  14. *
  15. * @return void
  16. */
  17. public function __init()
  18. {
  19. if (!login::$logged_in)
  20. redirect::handle('');
  21.  
  22. login::$user->check_banned();
  23.  
  24. $this->user = UserProfile::get(login::$user->data['username']);
  25.  
  26. if (isset($_POST['about'])) {
  27. $this->handleForm();
  28. }
  29.  
  30. $this->printForm();
  31.  
  32. base::$b->page->add_content_right('<div class="panel panel-red">
  33. <div class="panel-heading">
  34. <h3 class="panel-title"><i class="fa fa-cog"></i> '.base::$b->lb->word('settings/more').'</h3>
  35. </div>
  36. <div class="panel-body">
  37. <ul class="menu-list">
  38. <li><a href="'.redirect::url('settings').'"><i class="fa fa-angle-double-right"></i> '.base::$b->lb->word('settings/more/edit').'</a></li>
  39. <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>
  40. <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>
  41. </ul>
  42. </div>
  43. </div>');
  44.  
  45. base::$b->page->title_prepend(''.base::$b->lb->word('settings/profile/title').' &bull; ');
  46. base::$b->page->theme_instance->menu_active = 'me';
  47. base::$b->page->load();
  48. }
  49.  
  50. /**
  51. * @return void
  52. */
  53. protected function handleForm()
  54. {
  55. $set = [];
  56. $errors = [];
  57.  
  58. $about = trim($_POST['about']);
  59. $maxAboutLength = $this->user->extUnlocked('FancyBio') ? 2000 : 140;
  60.  
  61. if (mb_strlen($about) > $maxAboutLength) {
  62. $errors[] = ''.base::$b->lb->word('settings/profile/warning/1').' '.$maxAboutLength.' '.base::$b->lb->word('settings/profile/warning/2').'';
  63. } else {
  64. $set[] = "about_text = ".base::$b->db->quote($about);
  65. }
  66.  
  67. if ($this->user->extUnlocked('Stats') && isset($_POST['city']) && mb_strlen($_POST['city']) <= 30) {
  68. $set[] = "profile_city = ".base::$b->db->quote($_POST['city']);
  69. }
  70.  
  71. if ($this->user->extUnlocked('FancyName') && isset($_POST['link_style'], UserProfile::$userLinkStyles[$_POST['link_style']])) {
  72. $set[] = "link_style = ".(int)$_POST['link_style'];
  73. }
  74.  
  75. if ($this->user->extUnlocked('Avatar') && isset($_POST['avatar'])) {
  76. $set[] = "avatar_img = ".base::$b->db->quote($_POST['avatar']);
  77. }
  78.  
  79. if ($this->user->extUnlocked('YouTube') && isset($_POST['youtube']) && $_POST['youtube'] != $this->user->data['youtube_id']) {
  80. $v = $_POST['youtube'] == ''
  81. ? ''
  82. : $this->parseYouTubeId($_POST['youtube']);
  83.  
  84. if ($v === false) {
  85. $errors[] = ''.base::$b->lb->word('settings/profile/warning/3').'';
  86. } else {
  87. $set[] = "youtube_id = ".base::$b->db->quote($v);
  88. }
  89. }
  90.  
  91. if ($this->user->extUnlocked('CoverBg') && isset($_POST['cover'])) {
  92. $set[] = "cover_img = ".base::$b->db->quote($_POST['cover']);
  93. }
  94.  
  95. if ($errors) {
  96. base::$b->page->add_message(implode('<br>', $errors), 'error');
  97. return;
  98. }
  99.  
  100. if (!$set) {
  101. return;
  102. }
  103.  
  104. base::$b->db->query(
  105. "UPDATE user_profile
  106. SET ".implode(', ', $set)."
  107. WHERE u_id = {$this->user->id}");
  108.  
  109. base::$b->page->add_message(''.base::$b->lb->word('settings/profile/saved').'', 'info');
  110. redirect::handle();
  111. }
  112.  
  113. /**
  114. * @return void
  115. */
  116. protected function printForm()
  117. {
  118. if (!$this->user->exts) {
  119. 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>';
  120. }
  121. echo '
  122. <div class="panel panel-primary">
  123. <div class="panel-heading">
  124. <h3 class="panel-title"><i class="fa fa-cog"></i> '.base::$b->lb->word('settings/profile/title/edit').'</h3>
  125. </div>
  126. <div class="panel-body">
  127. <div class="alert alert-orange" style="font-size: 12px;">'.base::$b->lb->text('settings/profile/guide/1').'</div>
  128. <boxes />
  129. <form method="post" action="'.redirect::url().'" role="form">';
  130.  
  131. if ($this->user->extUnlocked('FancyName')) {
  132. echo '
  133. <div class="form-group">
  134. <label style="display: block;">'.base::$b->lb->word('settings/profile/fancyname').'</label>';
  135.  
  136. foreach (UserProfile::$userLinkStyles as $i => $s) {
  137. echo '
  138. <label style="margin-right: 60px;">
  139. <input type="radio" name="link_style" value="'.$i.'"'.(
  140. $i == $this->user->data['link_style']
  141. ? 'checked' : '').'>
  142. <span style="font-size: 18px; color: #'.$s['color'].'; background: url('.__URL_STATIC__.'/dashboard/img/userLinkStyles/'.$s['bgImg'].') center;">
  143. '.htmlspecialchars($this->user->data['username']).'
  144. </span>
  145. </label>';
  146. }
  147.  
  148. echo '
  149. </div>';
  150. }
  151.  
  152. if ($this->user->extUnlocked('Stats')) {
  153. echo '
  154. <div class="form-group">
  155. <label for="city">'.base::$b->lb->word('settings/profile/city').'</label>
  156. <input type="text" class="form-control" name="city" id="city" value="'.formval('city', $this->user->data['profile_city']).'">
  157. </div>';
  158. }
  159.  
  160. if ($this->user->extUnlocked('Avatar')) {
  161. echo '
  162. <div class="form-group">
  163. <label for="avatar">'.base::$b->lb->word('settings/profile/avatar').'</label>
  164. <input type="text" class="form-control" name="avatar" id="avatar" value="'.formval('avatar', $this->user->data['avatar_img']).'">
  165. <span class="help-block">'.base::$b->lb->text('settings/profile/help/url').'</span>
  166. </div>';
  167. }
  168.  
  169. if ($this->user->extUnlocked('YouTube')) {
  170. echo '
  171. <div class="form-group">
  172. <label for="youtube">'.base::$b->lb->word('settings/profile/youtube').'</label>
  173. <input type="text" class="form-control" name="youtube" id="youtube" value="'.formval('youtube', $this->user->data['youtube_id']).'">
  174. <span class="help-block">'.base::$b->lb->word('settings/profile/help/youtube').'</span>
  175. </div>';
  176. }
  177.  
  178. if ($this->user->extUnlocked('CoverBg')) {
  179. echo '
  180. <div class="form-group">
  181. <label for="cover">'.base::$b->lb->word('settings/profile/background').'</label>
  182. <input type="text" class="form-control" name="cover" id="cover" value="'.formval('cover', $this->user->data['cover_img']).'">
  183. <span class="help-block">'.base::$b->lb->text('settings/profile/help/url').'</span>
  184. </div>';
  185. }
  186.  
  187. echo '
  188. <div class="form-group">
  189. <label for="about">'.base::$b->lb->word('settings/profile/about').'</label>
  190. <textarea class="form-control" name="about" id="about" rows="5">'.formval('about', $this->user->data['about_text']).'</textarea>';
  191.  
  192. if (!$this->user->extUnlocked('FancyBio')) {
  193. echo '
  194. <span class="help-block">'.base::$b->lb->text('settings/profile/buy').'</span>';
  195. }
  196. else
  197. {
  198. echo '<span class="help-block">'.base::$b->lb->text('settings/profile/guide/2').'</span>';
  199. }
  200.  
  201. echo '
  202. </div>';
  203.  
  204. echo '
  205. '.csrf::html_input().'
  206. <button type="submit" class="btn btn-green btn-lg"><i class="fa fa-save"></i> '.base::$b->lb->word('settings/save').'</button>
  207. </form>
  208. </div>
  209. </div>';
  210. }
  211.  
  212. /**
  213. * @param string $url
  214. * @return string|bool
  215. */
  216. protected function parseYouTubeId($url)
  217. {
  218. $query = parse_url($url, PHP_URL_QUERY);
  219.  
  220. if (!$query) {
  221. return false;
  222. }
  223.  
  224. parse_str($query, $queryData);
  225.  
  226. if (!isset($queryData['v']) || strlen($queryData['v']) !== 11) {
  227. return false;
  228. }
  229.  
  230. return $queryData['v'];
  231. }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement