Advertisement
BaxAndrei

profile.php

Jul 14th, 2018
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.16 KB | None | 0 0
  1. <?php
  2. /*
  3. * Made by Samerton
  4. * https://github.com/NamelessMC/Nameless/
  5. * NamelessMC version 2.0.0-pr3
  6. *
  7. * License: MIT
  8. *
  9. * User profile page
  10. */
  11.  
  12. // Always define page name
  13. define('PAGE', 'profile');
  14.  
  15. $timeago = new Timeago(TIMEZONE);
  16.  
  17. require(ROOT_PATH . '/core/includes/emojione/autoload.php'); // Emojione
  18. $emojione = new Emojione\Client(new Emojione\Ruleset());
  19.  
  20. require(ROOT_PATH . '/core/includes/paginate.php'); // Get number of wall posts on a page
  21. ?>
  22. <!DOCTYPE html>
  23. <html<?php if(defined('HTML_CLASS')) echo ' class="' . HTML_CLASS . '"'; ?> lang="<?php echo (defined('HTML_LANG') ? HTML_LANG : 'en'); ?>" <?php if(defined('HTML_RTL') && HTML_RTL === true) echo ' dir="rtl"'; ?>>
  24. <head>
  25. <!-- Standard Meta -->
  26. <meta charset="<?php echo (defined('LANG_CHARSET') ? LANG_CHARSET : 'utf-8'); ?>">
  27. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  28. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  29.  
  30. <!-- Site Properties -->
  31. <?php
  32. $title = $language->get('user', 'profile');
  33. require(ROOT_PATH . '/core/templates/header.php');
  34. ?>
  35.  
  36. <link rel="stylesheet" href="<?php if(defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/ckeditor/plugins/spoiler/css/spoiler.css">
  37. <link rel="stylesheet" href="<?php if(defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/image-picker/image-picker.css">
  38. <style type="text/css">
  39. .thumbnails li img{
  40. width: 200px;
  41. }
  42. </style>
  43.  
  44. </head>
  45. <body>
  46. <?php
  47. require(ROOT_PATH . '/core/templates/navbar.php');
  48. require(ROOT_PATH . '/core/templates/footer.php');
  49. ?>
  50.  
  51. <?php
  52. $profile = explode('/', $route);
  53. if(count($profile) >= 3 && ($profile[count($profile) - 1] != 'profile' || $profile[count($profile) - 2] == 'profile') && !isset($_GET['error'])){
  54. // User specified
  55. $profile = $profile[count($profile) - 1];
  56.  
  57. $query = $queries->getWhere('users', array('username', '=', $profile));
  58.  
  59. if(!count($query)) Redirect::to(URL::build('/profile/', 'error=not_exist'));
  60. $query = $query[0];
  61.  
  62. // Deal with input
  63. if(Input::exists()){
  64. if($user->isLoggedIn()){
  65. if(isset($_POST['action'])){
  66. switch ($_POST['action']){
  67. case 'banner':
  68. if($user->data()->username == $profile){
  69. if(Token::check(Input::get('token'))){
  70. // Update banner
  71. if(isset($_POST['banner'])){
  72. // Check image specified actually exists
  73. if(is_file(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'uploads', 'profile_images', $_POST['banner'])))){
  74. // Exists
  75. // Is it an image file?
  76. if(in_array(pathinfo(join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'uploads', 'profile_images', $_POST['banner'])), PATHINFO_EXTENSION), array('gif', 'png', 'jpg', 'jpeg'))){
  77. // Yes, update settings
  78. $user->update(array(
  79. 'banner' => Output::getClean($_POST['banner'])
  80. ));
  81.  
  82. // Requery to update banner
  83. $user = new User();
  84. $query = $queries->getWhere('users', array('username', '=', $profile));
  85. $query = $query[0];
  86. }
  87. }
  88. }
  89. }
  90. }
  91. break;
  92.  
  93. case 'new_post':
  94. if(Token::check(Input::get('token'))){
  95. // Valid token
  96. $validate = new Validate();
  97.  
  98. $validation = $validate->check($_POST, array(
  99. 'post' => array(
  100. 'required' => true,
  101. 'min' => 1,
  102. 'max' => 10000
  103. )
  104. ));
  105.  
  106. if($validation->passed()){
  107. // Validation successful
  108. // Input into database
  109. $queries->create('user_profile_wall_posts', array(
  110. 'user_id' => $query->id,
  111. 'author_id' => $user->data()->id,
  112. 'time' => date('U'),
  113. 'content' => Output::getClean(Input::get('post'))
  114. ));
  115.  
  116. if($query->id !== $user->data()->id){
  117. // Alert user
  118. Alert::create($query->id, 'profile_post', str_replace('{x}', Output::getClean($user->data()->nickname), $language->get('user', 'new_wall_post')), str_replace('{x}', Output::getClean($user->data()->nickname), $language->get('user', 'new_wall_post')), URL::build('/profile/' . Output::getClean($query->username)));
  119. }
  120.  
  121. // Redirect to clear input
  122. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  123. die();
  124.  
  125. } else {
  126. // Validation failed
  127. $error = $language->get('user', 'invalid_wall_post');
  128. }
  129.  
  130. } else {
  131. $error = $language->get('general', 'invalid_token');
  132. }
  133. break;
  134.  
  135. case 'reply':
  136. if(Token::check(Input::get('token'))){
  137. // Valid token
  138. $validate = new Validate();
  139.  
  140. $validation = $validate->check($_POST, array(
  141. 'reply' => array(
  142. 'required' => true,
  143. 'min' => 1,
  144. 'max' => 10000
  145. ),
  146. 'post' => array(
  147. 'required' => true
  148. )
  149. ));
  150.  
  151. if($validation->passed()){
  152. // Validation successful
  153.  
  154. // Ensure post exists
  155. $post = $queries->getWhere('user_profile_wall_posts', array('id', '=', $_POST['post']));
  156. if(!count($post)){
  157. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  158. die();
  159. }
  160.  
  161. // Input into database
  162. $queries->create('user_profile_wall_posts_replies', array(
  163. 'post_id' => $_POST['post'],
  164. 'author_id' => $user->data()->id,
  165. 'time' => date('U'),
  166. 'content' => Output::getClean(Input::get('reply'))
  167. ));
  168.  
  169. if($post[0]->author_id != $query->id && $query->id != $user->data()->id)
  170. Alert::create($query->id, 'profile_post', str_replace('{x}', Output::getClean($user->data()->nickname), $language->get('user', 'new_wall_post')), str_replace('{x}', Output::getClean($user->data()->nickname), $language->get('user', 'new_wall_post')), URL::build('/profile/' . Output::getClean($query->username)));
  171.  
  172. else if($post[0]->author_id != $user->data()->id){
  173. // Alert post author
  174. if($post[0]->author_id == $query->id)
  175. Alert::create($query->id, 'profile_post_reply', str_replace('{x}', Output::getClean($user->data()->nickname), $language->get('user', 'new_wall_post_reply_your_profile')), str_replace('{x}', Output::getClean($user->data()->nickname), $language->get('user', 'new_wall_post_reply_your_profile')), URL::build('/profile/' . Output::getClean($query->username)));
  176. else
  177. Alert::create($post[0]->author_id, 'profile_post_reply', str_replace(array('{x}', '{y}'), array(Output::getClean($user->data()->nickname), Output::getClean($query->nickname)), $language->get('user', 'new_wall_post_reply')), str_replace(array('{x}', '{y}'), array(Output::getClean($user->data()->nickname), Output::getClean($query->nickname)), $language->get('user', 'new_wall_post_reply')), URL::build('/profile/' . Output::getClean($query->username)));
  178. }
  179.  
  180. // Redirect to clear input
  181. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  182. die();
  183.  
  184. } else {
  185. // Validation failed
  186. $error = $language->get('user', 'invalid_wall_post');
  187. }
  188.  
  189. } else {
  190. $error = $language->get('general', 'invalid_token');
  191. }
  192. break;
  193.  
  194. case 'block':
  195. if(Token::check(Input::get('token'))){
  196. if($user->isBlocked($user->data()->id, $query->id)){
  197. // Unblock
  198. $blocked_id = $queries->getWhere('blocked_users', array('user_id', '=', $user->data()->id));
  199. if(count($blocked_id)){
  200. foreach($blocked_id as $id){
  201. if($id->user_blocked_id == $query->id){
  202. $blocked_id = $id->id;
  203. break;
  204. }
  205. }
  206.  
  207. if(is_numeric($blocked_id)){
  208. $queries->delete('blocked_users', array('id', '=', $blocked_id));
  209. $success = $language->get('user', 'user_unblocked');
  210. }
  211. }
  212.  
  213. } else {
  214. // Block
  215. $queries->create('blocked_users', array(
  216. 'user_id' => $user->data()->id,
  217. 'user_blocked_id' => $query->id
  218. ));
  219. $success = $language->get('user', 'user_blocked');
  220. }
  221. } else
  222. $error = $language->get('general', 'invalid_token');
  223. break;
  224.  
  225. case 'edit':
  226. // Ensure user is mod or owner of post
  227. if(Token::check(Input::get('token'))){
  228. if(isset($_POST['post_id']) && is_numeric($_POST['post_id'])) {
  229. $post = $queries->getWhere('user_profile_wall_posts', array('id', '=', $_POST['post_id']));
  230. if(count($post)) {
  231. $post = $post[0];
  232. if($user->canViewMCP() || $post->author_id == $user->data()->id){
  233. if(isset($_POST['content']) && strlen($_POST['content']) < 10000 && strlen($_POST['content']) >= 1){
  234. try {
  235. $queries->update('user_profile_wall_posts', $_POST['post_id'], array(
  236. 'content' => Output::getClean($_POST['content'])
  237. ));
  238. } catch(Exception $e){
  239. $error = $e->getMessage();
  240. }
  241. } else
  242. $error = $language->get('user', 'invalid_wall_post');
  243. }
  244. }
  245. }
  246. } else
  247. $error = $language->get('general', 'invalid_token');
  248. break;
  249.  
  250. case 'delete':
  251. // Ensure user is mod or owner of post
  252. if(Token::check(Input::get('token'))){
  253. if(isset($_POST['post_id']) && is_numeric($_POST['post_id'])) {
  254. $post = $queries->getWhere('user_profile_wall_posts', array('id', '=', $_POST['post_id']));
  255. if(count($post)) {
  256. $post = $post[0];
  257. if($user->canViewMCP() || $post->author_id == $user->data()->id){
  258. try {
  259. $queries->delete('user_profile_wall_posts', array('id', '=', $_POST['post_id']));
  260. $queries->delete('user_profile_wall_posts_replies', array('post_id', '=', $_POST['post_id']));
  261. } catch(Exception $e){
  262. $error = $e->getMessage();
  263. }
  264. }
  265. }
  266. }
  267. } else
  268. $error = $language->get('general', 'invalid_token');
  269. break;
  270.  
  271. /*
  272. case 'editReply':
  273. // Ensure user is mod or owner of reply
  274. if(Token::check(Input::get('token'))){
  275. if(isset($_POST['post_id']) && is_numeric($_POST['post_id'])) {
  276. $post = $queries->getWhere('user_profile_wall_posts_replies', array('id', '=', $_POST['post_id']));
  277. if(count($post)) {
  278. $post = $post[0];
  279. if($user->canViewMCP() || $post->author_id == $user->data()->id){
  280. if(isset($_POST['content']) && strlen($_POST['content']) < 10000 && strlen($_POST['content']) >= 1){
  281. try {
  282. $queries->update('user_profile_wall_posts_replies', $_POST['post_id'], array(
  283. 'content' => Output::getClean($_POST['content'])
  284. ));
  285. } catch(Exception $e){
  286. $error = $e->getMessage();
  287. }
  288. } else
  289. $error = $language->get('user', 'invalid_wall_post');
  290. }
  291. }
  292. }
  293. } else
  294. $error = $language->get('general', 'invalid_token');
  295. break;
  296. */
  297.  
  298. case 'deleteReply':
  299. // Ensure user is mod or owner of reply
  300. if(Token::check(Input::get('token'))){
  301. if(isset($_POST['post_id']) && is_numeric($_POST['post_id'])) {
  302. $post = $queries->getWhere('user_profile_wall_posts_replies', array('id', '=', $_POST['post_id']));
  303. if(count($post)) {
  304. $post = $post[0];
  305. if($user->canViewMCP() || $post->author_id == $user->data()->id){
  306. try {
  307. $queries->delete('user_profile_wall_posts_replies', array('id', '=', $_POST['post_id']));
  308. } catch(Exception $e){
  309. $error = $e->getMessage();
  310. }
  311. }
  312. }
  313. }
  314. } else
  315. $error = $language->get('general', 'invalid_token');
  316. break;
  317. }
  318. }
  319. }
  320. }
  321.  
  322. if($user->isLoggedIn()){
  323. if(isset($_GET['action'])){
  324. switch($_GET['action']){
  325. case 'react':
  326. if(!isset($_GET['post']) || !is_numeric($_GET['post'])){
  327. // Post ID required
  328. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  329. die();
  330. }
  331.  
  332. // Does the post exist?
  333. $post = $queries->getWhere('user_profile_wall_posts', array('id', '=', $_GET['post']));
  334. if(!count($post)){
  335. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  336. die();
  337. }
  338.  
  339. // Can't like our own post
  340. if($post[0]->author_id == $user->data()->id){
  341. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  342. die();
  343. }
  344.  
  345. // Liking or unliking?
  346. $post_likes = $queries->getWhere('user_profile_wall_posts_reactions', array('post_id', '=', $_GET['post']));
  347. if(count($post_likes)){
  348. foreach($post_likes as $like){
  349. if($like->user_id == $user->data()->id){
  350. $has_liked = $like->id;
  351. break;
  352. }
  353. }
  354. }
  355.  
  356. if(isset($has_liked)){
  357. // Unlike
  358. $queries->delete('user_profile_wall_posts_reactions', array('id', '=', $has_liked));
  359. } else {
  360. // Like
  361. $queries->create('user_profile_wall_posts_reactions', array(
  362. 'user_id' => $user->data()->id,
  363. 'post_id' => $_GET['post'],
  364. 'reaction_id' => 1,
  365. 'time' => date('U')
  366. ));
  367. }
  368.  
  369. // Redirect
  370. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  371. die();
  372.  
  373. break;
  374. }
  375. }
  376. }
  377.  
  378. // Get page
  379. if(isset($_GET['p'])){
  380. if(!is_numeric($_GET['p'])){
  381. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  382. die();
  383. } else {
  384. if($_GET['p'] == 1){
  385. // Avoid bug in pagination class
  386. Redirect::to(URL::build('/profile/' . Output::getClean($query->username)));
  387. die();
  388. }
  389. $p = $_GET['p'];
  390. }
  391. } else {
  392. $p = 1;
  393. }
  394.  
  395. // View count
  396. // Check if user is logged in and the viewer is not the owner of this profile.
  397. if(($user->isLoggedIn() && $user->data()->id != $query->id)
  398. // If no one is logged in check if they have accepted the cookies.
  399. || (!$user->isLoggedIn() && Cookie::exists('alert-box'))){
  400. if(!Cookie::exists('nl-profile-' . $query->id)) {
  401. $queries->increment("users", $query->id, "profile_views");
  402. Cookie::put("nl-profile-" . $query->id, "true", 3600);
  403. }
  404. } else if(!Session::exists('nl-profile-' . $query->id)){
  405. $queries->increment("users", $query->id, "profile_views");
  406. Session::put("nl-profile-" . $query->id, "true");
  407. }
  408.  
  409. // Set Can view
  410. if($user->isPrivateProfile($query->id) && $user->canPrivateProfile($query->id)) {
  411. $smarty->assign(array(
  412. 'PRIVATE_PROFILE' => $language->get('user', 'private_profile_page'),
  413. 'CAN_VIEW' => false
  414. ));
  415. }else {
  416. $smarty->assign(array(
  417. 'CAN_VIEW' => true
  418. ));
  419. }
  420.  
  421. // Generate Smarty variables to pass to template
  422. if($user->isLoggedIn()){
  423. // Form token
  424. $smarty->assign(array(
  425. 'TOKEN' => Token::get(),
  426. 'LOGGED_IN' => true,
  427. 'SUBMIT' => $language->get('general', 'submit'),
  428. 'CANCEL' => $language->get('general', 'cancel'),
  429. 'CAN_MODERATE' => ($user->canViewMCP() || $user->canViewACP())
  430. ));
  431.  
  432. if($user->hasPermission('profile.private.bypass')){
  433. $smarty->assign(array(
  434. 'CAN_VIEW' => true
  435. ));
  436. }
  437.  
  438. if($user->data()->id == $query->id){
  439. // Custom profile banners
  440. $banners = array();
  441.  
  442. $image_path = join(DIRECTORY_SEPARATOR, array(ROOT_PATH, 'uploads', 'profile_images'));
  443. $images = scandir($image_path);
  444.  
  445. // Only display jpeg, png, jpg, gif
  446. $allowed_exts = array('gif', 'png', 'jpg', 'jpeg');
  447.  
  448. foreach($images as $image){
  449. $ext = pathinfo($image, PATHINFO_EXTENSION);
  450. if(!in_array($ext, $allowed_exts)){
  451. continue;
  452. }
  453.  
  454. $banners[] = array(
  455. 'src' => ((defined('CONFIG_PATH')) ? CONFIG_PATH . '/' : '/') . 'uploads/profile_images/' . Output::getClean($image),
  456. 'name' => Output::getClean($image),
  457. 'active' => ($user->data()->banner == $image) ? true : false
  458. );
  459. }
  460.  
  461. $smarty->assign(array(
  462. 'SELF' => true,
  463. 'SETTINGS_LINK' => URL::build('/user/settings'),
  464. 'CHANGE_BANNER' => $language->get('user', 'change_banner'),
  465. 'BANNERS' => $banners,
  466. 'CAN_VIEW' => true,
  467. ));
  468. } else {
  469. $smarty->assign(array(
  470. 'MESSAGE_LINK' => URL::build('/user/messaging/', 'action=new&amp;uid=' . $query->id),
  471. 'FOLLOW_LINK' => URL::build('/user/follow/', 'user=' . $query->id),
  472. 'CONFIRM' => $language->get('general', 'confirm'),
  473. 'MOD_OR_ADMIN' => ($user->canViewMCP($query->id) || $user->canViewACP($query->id))
  474. ));
  475.  
  476. // Is the user blocked?
  477. if($user->isBlocked($user->data()->id, $query->id)){
  478. $smarty->assign(array(
  479. 'UNBLOCK_USER' => $language->get('user', 'unblock_user'),
  480. 'CONFIRM_UNBLOCK_USER' => $language->get('user', 'confirm_unblock_user')
  481. ));
  482. } else {
  483. $smarty->assign(array(
  484. 'BLOCK_USER' => $language->get('user', 'block_user'),
  485. 'CONFIRM_BLOCK_USER' => $language->get('user', 'confirm_block_user')
  486. ));
  487. }
  488. }
  489. }
  490.  
  491. // Get user's group
  492. $group = $queries->getWhere('groups', array('id', '=', $query->group_id));
  493. $group = $group[0]->group_html;
  494.  
  495. // Get list of reactions
  496. //$reactions = $queries->getWhere('reactions', array('enabled', '=', 1));
  497.  
  498. $smarty->assign(array(
  499. 'NICKNAME' => Output::getClean($query->nickname),
  500. 'USERNAME' => Output::getClean($query->username),
  501. 'GROUP' => Output::getPurified($group),
  502. 'GROUPS' => (isset($query) ? $user->getAllGroups($query->id, 'true') : array(Output::getPurified($group))),
  503. 'USERNAME_COLOUR' => $user->getGroupClass($query->id),
  504. 'USER_TITLE' => Output::getClean($query->user_title),
  505. 'FOLLOW' => $language->get('user', 'follow'),
  506. 'AVATAR' => $user->getAvatar($query->id, '../', 500),
  507. 'BANNER' => ((defined('CONFIG_PATH')) ? CONFIG_PATH : '/') . 'uploads/profile_images/' . Output::getClean($query->banner),
  508. 'POST_ON_WALL' => str_replace('{x}', Output::getClean($query->nickname), $language->get('user', 'post_on_wall')),
  509. 'FEED' => $language->get('user', 'feed'),
  510. 'ABOUT' => $language->get('user', 'about'),
  511. 'REACTIONS_TITLE' => $language->get('user', 'likes'),
  512. //'REACTIONS' => $reactions,
  513. 'CLOSE' => $language->get('general', 'close'),
  514. 'REPLIES_TITLE' => $language->get('user', 'replies'),
  515. 'NO_REPLIES' => $language->get('user', 'no_replies_yet'),
  516. 'NEW_REPLY' => $language->get('user', 'new_reply'),
  517. 'DELETE' => $language->get('general', 'delete'),
  518. 'CONFIRM_DELETE' => $language->get('general', 'confirm_deletion'),
  519. 'EDIT' => $language->get('general', 'edit')
  520. ));
  521.  
  522. // Wall posts
  523. $wall_posts = array();
  524. $wall_posts_query = $queries->orderWhere('user_profile_wall_posts', 'user_id = ' . $query->id, 'time', 'DESC');
  525.  
  526. if(count($wall_posts_query)){
  527. // Pagination
  528. $paginator = new Paginator((isset($template_pagination) ? $template_pagination : array()));
  529. $results = $paginator->getLimited($wall_posts_query, 10, $p, count($wall_posts_query));
  530. $pagination = $paginator->generate(7, URL::build('/profile/' . Output::getClean($query->username) . '/', true));
  531.  
  532. $smarty->assign('PAGINATION', $pagination);
  533.  
  534. // Display the correct number of posts
  535. for($n = 0; $n < count($results->data); $n++){
  536. $post_user = $queries->getWhere('users', array('id', '=', $results->data[$n]->author_id));
  537.  
  538. if(!count($post_user)) continue;
  539.  
  540. // Get reactions/replies
  541. $reactions = array();
  542. $replies = array();
  543.  
  544. $reactions_query = $queries->getWhere('user_profile_wall_posts_reactions', array('post_id', '=', $results->data[$n]->id));
  545. if(count($reactions_query)){
  546. if(count($reactions_query) == 1)
  547. $reactions['count'] = $language->get('user', '1_like');
  548. else
  549. $reactions['count'] = str_replace('{x}', count($reactions_query), $language->get('user', 'x_likes'));
  550.  
  551. foreach($reactions_query as $reaction){
  552. // Get reaction name and icon
  553. // TODO
  554. /*
  555. $reaction_name = $queries->getWhere('reactions', array('id', '=', $reaction->reaction_id));
  556.  
  557. if(!count($reaction_name) || $reaction_name[0]->enabled == 0) continue;
  558. $reaction_html = $reaction_name[0]->html;
  559. $reaction_name = Output::getClean($reaction_name[0]->name);
  560. */
  561.  
  562. $reactions['reactions'][] = array(
  563. 'username' => Output::getClean($user->idToName($reaction->user_id)),
  564. 'nickname' => Output::getClean($user->idToNickname($reaction->user_id)),
  565. 'style' => $user->getGroupClass($reaction->user_id),
  566. 'profile' => URL::build('/profile/' . Output::getClean($user->idToName($reaction->user_id))),
  567. 'avatar' => $user->getAvatar($reaction->user_id, '../', 500),
  568. //'reaction_name' => $reaction_name,
  569. //'reaction_html' => $reaction_html
  570. );
  571. }
  572. } else $reactions['count'] = str_replace('{x}', 0, $language->get('user', 'x_likes'));
  573. $reactions_query = null;
  574.  
  575. $replies_query = $queries->orderWhere('user_profile_wall_posts_replies', 'post_id = ' . $results->data[$n]->id, 'time', 'ASC');
  576. if(count($replies_query)){
  577. if(count($replies_query) == 1)
  578. $replies['count'] = $language->get('user', '1_reply');
  579. else
  580. $replies['count'] = str_replace('{x}', count($replies_query), $language->get('user', 'x_replies'));
  581.  
  582. foreach($replies_query as $reply){
  583. $replies['replies'][] = array(
  584. 'username' => Output::getClean($user->idToName($reply->author_id)),
  585. 'nickname' => Output::getClean($user->idToNickname($reply->author_id)),
  586. 'style' => $user->getGroupClass($reply->author_id),
  587. 'profile' => URL::build('/profile/' . Output::getClean($user->idToName($reply->author_id))),
  588. 'avatar' => $user->getAvatar($reply->author_id, '../', 500),
  589. 'time_friendly' => $timeago->inWords(date('d M Y, H:i', $reply->time), $language->getTimeLanguage()),
  590. 'time_full' => date('d M Y, H:i', $reply->time),
  591. 'content' => Output::getPurified($reply->content),
  592. 'self' => (($user->isLoggedIn() && $user->data()->id == $reply->author_id) ? 1 : 0),
  593. 'id' => $reply->id
  594. );
  595. }
  596. } else $replies['count'] = str_replace('{x}', 0, $language->get('user', 'x_replies'));
  597. $replies_query = null;
  598.  
  599. $wall_posts[] = array(
  600. 'id' => $results->data[$n]->id,
  601. 'username' => Output::getClean($post_user[0]->username),
  602. 'nickname' => Output::getClean($post_user[0]->nickname),
  603. 'profile' => URL::build('/profile/' . Output::getClean($post_user[0]->username)),
  604. 'user_style' => $user->getGroupClass($post_user[0]->id),
  605. 'avatar' => $user->getAvatar($results->data[$n]->author_id, '../', 500),
  606. 'content' => Output::getPurified(htmlspecialchars_decode($results->data[$n]->content)),
  607. 'date_rough' => $timeago->inWords(date('d M Y, H:i', $results->data[$n]->time), $language->getTimeLanguage()),
  608. 'date' => date('d M Y, H:i', $results->data[$n]->time),
  609. 'reactions' => $reactions,
  610. 'replies' => $replies,
  611. 'self' => (($user->isLoggedIn() && $user->data()->id == $results->data[$n]->author_id) ? true : false),
  612. 'reactions_link' => ($user->isLoggedIn() && ($post_user[0]->id != $user->data()->id) ? URL::build('/profile/' . Output::getClean($query->username) . '/', 'action=react&amp;post=' . $results->data[$n]->id) : '#')
  613. );
  614. }
  615.  
  616. } else $smarty->assign('NO_WALL_POSTS', $language->get('user', 'no_wall_posts'));
  617.  
  618. $smarty->assign('WALL_POSTS', $wall_posts);
  619.  
  620. if(isset($error)) $smarty->assign('ERROR', $error);
  621. if(isset($success)) $smarty->assign('SUCCESS', $success);
  622.  
  623. // About tab
  624. $fields = array();
  625.  
  626. // Get profile fields
  627. $profile_fields = $queries->getWhere('users_profile_fields', array('user_id', '=', $query->id));
  628. if(count($profile_fields)){
  629. foreach($profile_fields as $field){
  630. // Get field
  631. $profile_field = $queries->getWhere('profile_fields', array('id', '=', $field->field_id));
  632. if(!count($profile_field)) continue;
  633. else $profile_field = $profile_field[0];
  634.  
  635. if($profile_field->public == 0) continue;
  636.  
  637. // Get field type
  638. switch($profile_field->type){
  639. case 1:
  640. $type = 'text';
  641. break;
  642. case 2:
  643. $type = 'textarea';
  644. break;
  645. case 3:
  646. $type = 'date';
  647. break;
  648. }
  649.  
  650. $fields[] = array(
  651. 'title' => Output::getClean($profile_field->name),
  652. 'type' => $type,
  653. 'value' => Output::getPurified(Util::urlToAnchorTag(htmlspecialchars_decode($field->value)))
  654. );
  655. }
  656. } else
  657. $smarty->assign('NO_ABOUT_FIELDS', $language->get('user', 'no_about_fields'));
  658.  
  659. // Minecraft?
  660. $minecraft_integration = $queries->getWhere('settings', array('name', '=', 'mc_integration'));
  661. $minecraft_integration = $minecraft_integration[0];
  662.  
  663. if($minecraft_integration->value == '1'){
  664. $fields['minecraft'] = array(
  665. 'title' => $language->get('user', 'ign'),
  666. 'type' => 'text',
  667. 'value' => Output::getClean($query->username),
  668. 'image' => 'https://crafatar.com/renders/body/' . $query->uuid . '?overlay'
  669. );
  670. }
  671.  
  672. // Add date registered and last seen
  673. $fields['registered'] = array(
  674. 'title' => $language->get('user', 'registered'),
  675. 'type' => 'text',
  676. 'value' => $timeago->inWords(date('d M Y, H:i', $query->joined), $language->getTimeLanguage()),
  677. 'tooltip' => date('d M Y, H:i', $query->joined)
  678. );
  679. $fields['last_seen'] = array(
  680. 'title' => $language->get('user', 'last_seen'),
  681. 'type' => 'text',
  682. 'value' => $timeago->inWords(date('d M Y, H:i', $query->last_online), $language->getTimeLanguage()),
  683. 'tooltip' => date('d M Y, H:i', $query->last_online)
  684. );
  685.  
  686. // Add Profile views
  687. $fields['profile_views'] = array(
  688. 'title' => $language->get("user", 'views'),
  689. 'type' => 'text',
  690. 'value' => $query->profile_views
  691. );
  692.  
  693. $smarty->assign('ABOUT_FIELDS', $fields);
  694.  
  695. // Custom tabs
  696. $tabs = array();
  697. if(isset($profile_tabs) && count($profile_tabs)){
  698. foreach($profile_tabs as $key => $tab){
  699. $tabs[$key] = array('title' => $tab['title'], 'include' => $tab['smarty_template']);
  700. if(is_file($tab['require'])) require($tab['require']);
  701. }
  702. }
  703.  
  704. // Assign profile tabs
  705. $smarty->assign('TABS', $tabs);
  706.  
  707. // Template
  708. $smarty->display(ROOT_PATH . '/custom/templates/' . TEMPLATE . '/profile.tpl');
  709.  
  710. } else {
  711. if(isset($_GET['error'])){
  712. // User not exist
  713. $smarty->assign(array(
  714. 'BACK' => $language->get('general', 'back'),
  715. 'HOME' => $language->get('general', 'home'),
  716. 'NOT_FOUND' => $language->get('user', 'couldnt_find_that_user')
  717. ));
  718. $smarty->display(ROOT_PATH . '/custom/templates/' . TEMPLATE . '/user_not_exist.tpl');
  719. }
  720. // Search for user
  721. // TODO
  722. }
  723.  
  724. // Footer and scripts
  725. require(ROOT_PATH . '/core/templates/footer.php');
  726. require(ROOT_PATH . '/core/templates/scripts.php');
  727.  
  728. if(isset($directories[1]) && !empty($directories[1]) && !isset($_GET['error']) && $user->isLoggedIn()){
  729. if($user->data()->username == $profile){
  730. // Script for banner selector
  731. ?>
  732. <script src="<?php if(defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/image-picker/image-picker.min.js"></script>
  733.  
  734. <script>
  735. $('#imageModal').on('show.bs.modal', function (e) {
  736. $("select").imagepicker();
  737. })
  738. </script>
  739. <?php
  740. }
  741. }
  742. ?>
  743. <script src="<?php if(defined('CONFIG_PATH')) echo CONFIG_PATH . '/'; else echo '/'; ?>core/assets/plugins/ckeditor/plugins/spoiler/js/spoiler.js"></script>
  744.  
  745. </body>
  746. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement