Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users.class.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <?
  2. class Users {
  3. /**
  4. * Get $Classes (list of classes keyed by ID) and $ClassLevels
  5. * (list of classes keyed by level)
  6. * @return array ($Classes, $ClassLevels)
  7. */
  8. public static function get_classes() {
  9. global $Debug;
  10. // Get permissions
  11. list($Classes, $ClassLevels) = G::$Cache->get_value('classes');
  12. if (!$Classes || !$ClassLevels) {
  13. $QueryID = G::$DB->get_query_id();
  14. G::$DB->query('
  15. SELECT ID, Name, Abbreviation, Level, Secondary
  16. FROM permissions
  17. ORDER BY Level');
  18. $Classes = G::$DB->to_array('ID');
  19. $ClassLevels = G::$DB->to_array('Level');
  20. G::$DB->set_query_id($QueryID);
  21. G::$Cache->cache_value('classes', array($Classes, $ClassLevels), 0);
  22. }
  23. $Debug->set_flag('Loaded permissions');
  24. return array($Classes, $ClassLevels);
  25. }
  26. /**
  27. * Get user info, is used for the current user and usernames all over the site.
  28. *
  29. * @param $UserID int The UserID to get info for
  30. * @return array with the following keys:
  31. * int ID
  32. * string Username
  33. * int PermissionID
  34. * array Paranoia - $Paranoia array sent to paranoia.class
  35. * boolean Artist
  36. * boolean Donor
  37. * string Warned - When their warning expires in international time format
  38. * string Avatar - URL
  39. * boolean Enabled
  40. * string Title
  41. * string CatchupTime - When they last caught up on forums
  42. * boolean Visible - If false, they don't show up on peer lists
  43. * array ExtraClasses - Secondary classes.
  44. * int EffectiveClass - the highest level of their main and secondary classes
  45. */
  46. public static function user_info($UserID) {
  47. global $Classes;
  48. $UserInfo = G::$Cache->get_value("user_info_$UserID");
  49. // the !isset($UserInfo['Paranoia']) can be removed after a transition period
  50. if (empty($UserInfo) || empty($UserInfo['ID']) || !isset($UserInfo['Paranoia']) || empty($UserInfo['Class'])) {
  51. $OldQueryID = G::$DB->get_query_id();
  52. G::$DB->query("
  53. SELECT
  54. m.ID,
  55. m.Username,
  56. m.PermissionID,
  57. m.Paranoia,
  58. i.Artist,
  59. i.Donor,
  60. i.Warned,
  61. i.Avatar,
  62. m.Enabled,
  63. m.Title,
  64. i.CatchupTime,
  65. m.Visible,
  66. la.Type AS LockedAccount,
  67. GROUP_CONCAT(ul.PermissionID SEPARATOR ',') AS Levels
  68. FROM users_main AS m
  69. INNER JOIN users_info AS i ON i.UserID = m.ID
  70. LEFT JOIN locked_accounts AS la ON la.UserID = m.ID
  71. LEFT JOIN users_levels AS ul ON ul.UserID = m.ID
  72. WHERE m.ID = '$UserID'
  73. GROUP BY m.ID");
  74. if (!G::$DB->has_results()) { // Deleted user, maybe?
  75. $UserInfo = array(
  76. 'ID' => $UserID,
  77. 'Username' => '',
  78. 'PermissionID' => 0,
  79. 'Paranoia' => array(),
  80. 'Artist' => false,
  81. 'Donor' => false,
  82. 'Warned' => '0000-00-00 00:00:00',
  83. 'Avatar' => '',
  84. 'Enabled' => 0,
  85. 'Title' => '',
  86. 'CatchupTime' => 0,
  87. 'Visible' => '1',
  88. 'Levels' => '',
  89. 'Class' => 0);
  90. } else {
  91. $UserInfo = G::$DB->next_record(MYSQLI_ASSOC, array('Paranoia', 'Title'));
  92. $UserInfo['CatchupTime'] = strtotime($UserInfo['CatchupTime']);
  93. $UserInfo['Paranoia'] = unserialize($UserInfo['Paranoia']);
  94. if ($UserInfo['Paranoia'] === false) {
  95. $UserInfo['Paranoia'] = array();
  96. }
  97. $UserInfo['Class'] = $Classes[$UserInfo['PermissionID']]['Level'];
  98. }
  99. if (isset($UserInfo['LockedAccount']) && $UserInfo['LockedAccount'] == "") {
  100. unset($UserInfo['LockedAccount']);
  101. }
  102. if (!empty($UserInfo['Levels'])) {
  103. $UserInfo['ExtraClasses'] = array_fill_keys(explode(',', $UserInfo['Levels']), 1);
  104. } else {
  105. $UserInfo['ExtraClasses'] = array();
  106. }
  107. unset($UserInfo['Levels']);
  108. $EffectiveClass = $UserInfo['Class'];
  109. foreach ($UserInfo['ExtraClasses'] as $Class => $Val) {
  110. $EffectiveClass = max($EffectiveClass, $Classes[$Class]['Level']);
  111. }
  112. $UserInfo['EffectiveClass'] = $EffectiveClass;
  113. G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
  114. G::$DB->set_query_id($OldQueryID);
  115. }
  116. if (strtotime($UserInfo['Warned']) < time()) {
  117. $UserInfo['Warned'] = '0000-00-00 00:00:00';
  118. G::$Cache->cache_value("user_info_$UserID", $UserInfo, 2592000);
  119. }
  120. return $UserInfo;
  121. }
  122. /**
  123. * Gets the heavy user info
  124. * Only used for current user
  125. *
  126. * @param $UserID The userid to get the information for
  127. * @return fetched heavy info.
  128. * Just read the goddamn code, I don't have time to comment this shit.
  129. */
  130. public static function user_heavy_info($UserID) {
  131. $HeavyInfo = G::$Cache->get_value("user_info_heavy_$UserID");
  132. if (empty($HeavyInfo)) {
  133. $QueryID = G::$DB->get_query_id();
  134. G::$DB->query("
  135. SELECT
  136. m.Invites,
  137. m.torrent_pass,
  138. m.IP,
  139. m.CustomPermissions,
  140. m.can_leech AS CanLeech,
  141. i.AuthKey,
  142. i.RatioWatchEnds,
  143. i.RatioWatchDownload,
  144. i.StyleID,
  145. i.StyleURL,
  146. i.DisableInvites,
  147. i.DisablePosting,
  148. i.DisableUpload,
  149. i.DisableWiki,
  150. i.DisableAvatar,
  151. i.DisablePM,
  152. i.DisableNips,
  153. i.DisableRequests,
  154. i.DisableForums,
  155. i.DisableTagging,
  156. i.SiteOptions,
  157. i.DownloadAlt,
  158. i.LastReadNews,
  159. i.LastReadBlog,
  160. i.RestrictedForums,
  161. i.PermittedForums,
  162. m.FLTokens,
  163. m.BonusPoints,
  164. m.HnR,
  165. m.PermissionID
  166. FROM users_main AS m
  167. INNER JOIN users_info AS i ON i.UserID = m.ID
  168. WHERE m.ID = '$UserID'");
  169. $HeavyInfo = G::$DB->next_record(MYSQLI_ASSOC, array('CustomPermissions', 'SiteOptions'));
  170. if (!empty($HeavyInfo['CustomPermissions'])) {
  171. $HeavyInfo['CustomPermissions'] = unserialize($HeavyInfo['CustomPermissions']);
  172. } else {
  173. $HeavyInfo['CustomPermissions'] = array();
  174. }
  175. if (!empty($HeavyInfo['RestrictedForums'])) {
  176. $RestrictedForums = array_map('trim', explode(',', $HeavyInfo['RestrictedForums']));
  177. } else {
  178. $RestrictedForums = array();
  179. }
  180. unset($HeavyInfo['RestrictedForums']);
  181. if (!empty($HeavyInfo['PermittedForums'])) {
  182. $PermittedForums = array_map('trim', explode(',', $HeavyInfo['PermittedForums']));
  183. } else {
  184. $PermittedForums = array();
  185. }
  186. unset($HeavyInfo['PermittedForums']);
  187. G::$DB->query("
  188. SELECT PermissionID
  189. FROM users_levels
  190. WHERE UserID = $UserID");
  191. $PermIDs = G::$DB->collect('PermissionID');
  192. foreach ($PermIDs AS $PermID) {
  193. $Perms = Permissions::get_permissions($PermID);
  194. if (!empty($Perms['PermittedForums'])) {
  195. $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',', $Perms['PermittedForums'])));
  196. }
  197. }
  198. $Perms = Permissions::get_permissions($HeavyInfo['PermissionID']);
  199. unset($HeavyInfo['PermissionID']);
  200. if (!empty($Perms['PermittedForums'])) {
  201. $PermittedForums = array_merge($PermittedForums, array_map('trim', explode(',', $Perms['PermittedForums'])));
  202. }
  203. if (!empty($PermittedForums) || !empty($RestrictedForums)) {
  204. $HeavyInfo['CustomForums'] = array();
  205. foreach ($RestrictedForums as $ForumID) {
  206. $HeavyInfo['CustomForums'][$ForumID] = 0;
  207. }
  208. foreach ($PermittedForums as $ForumID) {
  209. $HeavyInfo['CustomForums'][$ForumID] = 1;
  210. }
  211. } else {
  212. $HeavyInfo['CustomForums'] = null;
  213. }
  214. if (isset($HeavyInfo['CustomForums'][''])) {
  215. unset($HeavyInfo['CustomForums']['']);
  216. }
  217. $HeavyInfo['SiteOptions'] = unserialize($HeavyInfo['SiteOptions']);
  218. if (!empty($HeavyInfo['SiteOptions'])) {
  219. $HeavyInfo = array_merge($HeavyInfo, $HeavyInfo['SiteOptions']);
  220. }
  221. unset($HeavyInfo['SiteOptions']);
  222. G::$DB->set_query_id($QueryID);
  223. G::$Cache->cache_value("user_info_heavy_$UserID", $HeavyInfo, 0);
  224. }
  225. return $HeavyInfo;
  226. }
  227. /**
  228. * Updates the site options in the database
  229. *
  230. * @param int $UserID the UserID to set the options for
  231. * @param array $NewOptions the new options to set
  232. * @return false if $NewOptions is empty, true otherwise
  233. */
  234. public static function update_site_options($UserID, $NewOptions) {
  235. if (!is_number($UserID)) {
  236. error(0);
  237. }
  238. if (empty($NewOptions)) {
  239. return false;
  240. }
  241. $QueryID = G::$DB->get_query_id();
  242. // Get SiteOptions
  243. G::$DB->query("
  244. SELECT SiteOptions
  245. FROM users_info
  246. WHERE UserID = $UserID");
  247. list($SiteOptions) = G::$DB->next_record(MYSQLI_NUM, false);
  248. $SiteOptions = unserialize($SiteOptions);
  249. // Get HeavyInfo
  250. $HeavyInfo = Users::user_heavy_info($UserID);
  251. // Insert new/replace old options
  252. $SiteOptions = array_merge($SiteOptions, $NewOptions);
  253. $HeavyInfo = array_merge($HeavyInfo, $NewOptions);
  254. // Update DB
  255. G::$DB->query("
  256. UPDATE users_info
  257. SET SiteOptions = '".db_string(serialize($SiteOptions))."'
  258. WHERE UserID = $UserID");
  259. G::$DB->set_query_id($QueryID);
  260. // Update cache
  261. G::$Cache->cache_value("user_info_heavy_$UserID", $HeavyInfo, 0);
  262. // Update G::$LoggedUser if the options are changed for the current
  263. if (G::$LoggedUser['ID'] == $UserID) {
  264. G::$LoggedUser = array_merge(G::$LoggedUser, $NewOptions);
  265. G::$LoggedUser['ID'] = $UserID; // We don't want to allow userid switching
  266. }
  267. return true;
  268. }
  269. /**
  270. * Generate a random string
  271. *
  272. * @param Length
  273. * @return random alphanumeric string
  274. */
  275. public static function make_secret($Length = 32) {
  276. $Secret = '';
  277. $Chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  278. for ($i = 0; $i < $Length; $i++) {
  279. $Secret .= $Chars[random_int(0, strlen($Chars)-1)];
  280. }
  281. return str_shuffle($Secret);
  282. }
  283. /**
  284. * Verify a password against a password hash
  285. *
  286. * @param $Password password
  287. * @param $Hash password hash
  288. * @return true on correct password
  289. */
  290. public static function check_password($Password, $Hash) {
  291. if (!$Password || !$Hash) { return false; }
  292. return password_verify(hash("sha512", $Password, true), $Hash);
  293. }
  294. /**
  295. * Create salted hash for a given string
  296. *
  297. * @param $Str string to hash
  298. * @return salted hash
  299. */
  300. public static function make_sec_hash($Str) {
  301. return password_hash(hash("sha512", $Str, true), PASSWORD_DEFAULT);
  302. }
  303. /**
  304. * Returns a username string for display
  305. *
  306. * @param int $UserID
  307. * @param boolean $Badges whether or not badges (donor, warned, enabled) should be shown
  308. * @param boolean $IsWarned
  309. * @param boolean $IsEnabled
  310. * @param boolean $Class whether or not to show the class
  311. * @param boolean $Title whether or not to show the title
  312. * @param boolean $IsDonorForum for displaying donor forum honorific prefixes and suffixes
  313. * @return HTML formatted username
  314. */
  315. public static function format_username($UserID, $Badges = false, $IsWarned = true, $IsEnabled = true, $Class = false, $Title = false, $IsDonorForum = false) {
  316. global $Classes;
  317. // This array is a hack that should be made less retarded, but whatevs
  318. // PermID => ShortForm
  319. $SecondaryClasses = array(
  320. );
  321. if ($UserID == 0) {
  322. return 'System';
  323. }
  324. $UserInfo = self::user_info($UserID);
  325. if ($UserInfo['Username'] == '') {
  326. return "Unknown [$UserID]";
  327. }
  328. $Str = '';
  329. $Username = $UserInfo['Username'];
  330. $Paranoia = $UserInfo['Paranoia'];
  331. if ($UserInfo['Class'] < $Classes[MOD]['Level']) {
  332. $OverrideParanoia = check_perms('users_override_paranoia', $UserInfo['Class']);
  333. } else {
  334. // Don't override paranoia for mods who don't want to show their donor heart
  335. $OverrideParanoia = false;
  336. }
  337. $ShowDonorIcon = (!in_array('hide_donor_heart', $Paranoia) || $OverrideParanoia);
  338. if ($IsDonorForum) {
  339. list($Prefix, $Suffix, $HasComma) = Donations::get_titles($UserID);
  340. $Username = "$Prefix $Username" . ($HasComma ? ', ' : ' ') . "$Suffix ";
  341. }
  342. if ($Title) {
  343. $Str .= "<strong><a href=\"user.php?id=$UserID\">$Username</a></strong>";
  344. } else {
  345. $Str .= "<a href=\"user.php?id=$UserID\">$Username</a>";
  346. }
  347. if ($Badges) {
  348. $DonorRank = Donations::get_rank($UserID);
  349. if ($DonorRank == 0 && $UserInfo['Donor'] == 1) {
  350. $DonorRank = 1;
  351. }
  352. if ($ShowDonorIcon && $DonorRank > 0) {
  353. $IconLink = 'donate.php';
  354. $IconImage = 'donor.png';
  355. $IconText = 'Donor';
  356. $DonorHeart = $DonorRank;
  357. $SpecialRank = Donations::get_special_rank($UserID);
  358. $EnabledRewards = Donations::get_enabled_rewards($UserID);
  359. $DonorRewards = Donations::get_rewards($UserID);
  360. if ($EnabledRewards['HasDonorIconMouseOverText'] && !empty($DonorRewards['IconMouseOverText'])) {
  361. $IconText = display_str($DonorRewards['IconMouseOverText']);
  362. }
  363. if ($EnabledRewards['HasDonorIconLink'] && !empty($DonorRewards['CustomIconLink'])) {
  364. $IconLink = display_str($DonorRewards['CustomIconLink']);
  365. }
  366. if ($EnabledRewards['HasCustomDonorIcon'] && !empty($DonorRewards['CustomIcon'])) {
  367. $IconImage = ImageTools::process($DonorRewards['CustomIcon'], false, 'donoricon', $UserID);
  368. } else {
  369. if ($SpecialRank === MAX_SPECIAL_RANK) {
  370. $DonorHeart = 6;
  371. } elseif ($DonorRank === 5) {
  372. $DonorHeart = 4; // Two points between rank 4 and 5
  373. } elseif ($DonorRank >= MAX_RANK) {
  374. $DonorHeart = 5;
  375. }
  376. if ($DonorHeart === 1) {
  377. $IconImage = STATIC_SERVER . 'common/symbols/donor.png';
  378. } else {
  379. $IconImage = STATIC_SERVER . "common/symbols/donor_{$DonorHeart}.png";
  380. }
  381. }
  382. $Str .= "<a target=\"_blank\" href=\"$IconLink\"><img class=\"donor_icon tooltip\" src=\"$IconImage\" alt=\"$IconText\" title=\"$IconText\" /></a>";
  383. }
  384. $Str .= Badges::display_badges(Badges::get_displayed_badges($UserID), true);
  385. }
  386. $Str .= ($IsWarned && $UserInfo['Warned'] != '0000-00-00 00:00:00') ? '<a href="wiki.php?action=article&amp;id=218"'
  387. . '><img src="'.STATIC_SERVER.'common/symbols/warned.png" alt="Warned" title="Warned'
  388. . (G::$LoggedUser['ID'] === $UserID ? ' - Expires ' . date('Y-m-d H:i', strtotime($UserInfo['Warned'])) : '')
  389. . '" class="tooltip" /></a>' : '';
  390. $Str .= ($IsEnabled && $UserInfo['Enabled'] == 2) ? '<a href="rules.php"><img src="'.STATIC_SERVER.'common/symbols/disabled.png" alt="Banned" title="Disabled" class="tooltip" /></a>' : '';
  391. if ($Badges) {
  392. $ClassesDisplay = array();
  393. foreach (array_intersect_key($SecondaryClasses, $UserInfo['ExtraClasses']) as $PermID => $PermShort) {
  394. $ClassesDisplay[] = '<span class="tooltip secondary_class" title="'.$Classes[$PermID]['Name'].'">'.$PermShort.'</span>';
  395. }
  396. if (!empty($ClassesDisplay)) {
  397. $Str .= '&nbsp;'.implode('&nbsp;', $ClassesDisplay);
  398. }
  399. }
  400. if ($Class) {
  401. foreach (array_keys($UserInfo['ExtraClasses']) as $ExtraClass) {
  402. $Str .= ' ['.Users::make_class_abbrev_string($ExtraClass).']';
  403. }
  404. if ($Title) {
  405. $Str .= ' <strong>('.Users::make_class_string($UserInfo['PermissionID']).')</strong>';
  406. } else {
  407. $Str .= ' ('.Users::make_class_string($UserInfo['PermissionID']).')';
  408. }
  409. }
  410. if ($Title) {
  411. // Image proxy CTs
  412. if (check_perms('site_proxy_images') && !empty($UserInfo['Title'])) {
  413. $UserInfo['Title'] = preg_replace_callback('~src=("?)(http.+?)(["\s>])~',
  414. function($Matches) {
  415. return 'src=' . $Matches[1] . ImageTools::process($Matches[2]) . $Matches[3];
  416. },
  417. $UserInfo['Title']);
  418. }
  419. if ($UserInfo['Title']) {
  420. $Str .= ' <span class="user_title">('.$UserInfo['Title'].')</span>';
  421. }
  422. }
  423. return $Str;
  424. }
  425. /**
  426. * Given a class ID, return its name.
  427. *
  428. * @param int $ClassID
  429. * @return string name
  430. */
  431. public static function make_class_string($ClassID) {
  432. global $Classes;
  433. return $Classes[$ClassID]['Name'];
  434. }
  435. public static function make_class_abbrev_string($ClassID) {
  436. global $Classes;
  437. return '<acronym title="'.$Classes[$ClassID]['Name'].'">'.$Classes[$ClassID]['Abbreviation'].'</acronym>';
  438. }
  439. /**
  440. * Returns an array with User Bookmark data: group IDs, collage data, torrent data
  441. * @param string|int $UserID
  442. * @return array Group IDs, Bookmark Data, Torrent List
  443. */
  444. public static function get_bookmarks($UserID) {
  445. $UserID = (int)$UserID;
  446. if (($Data = G::$Cache->get_value("bookmarks_group_ids_$UserID"))) {
  447. list($GroupIDs, $BookmarkData) = $Data;
  448. } else {
  449. $QueryID = G::$DB->get_query_id();
  450. G::$DB->query("
  451. SELECT GroupID, Sort, `Time`
  452. FROM bookmarks_torrents
  453. WHERE UserID = $UserID
  454. ORDER BY Sort, `Time` ASC");
  455. $GroupIDs = G::$DB->collect('GroupID');
  456. $BookmarkData = G::$DB->to_array('GroupID', MYSQLI_ASSOC);
  457. G::$DB->set_query_id($QueryID);
  458. G::$Cache->cache_value("bookmarks_group_ids_$UserID",
  459. array($GroupIDs, $BookmarkData), 3600);
  460. }
  461. $TorrentList = Torrents::get_groups($GroupIDs);
  462. return array($GroupIDs, $BookmarkData, $TorrentList);
  463. }
  464. /**
  465. * Generate HTML for a user's avatar or just return the avatar URL
  466. * @param unknown $Avatar
  467. * @param unknown $UserID
  468. * @param unknown $Username
  469. * @param unknown $Setting
  470. * @param number $Size
  471. * @param string $ReturnHTML
  472. * @return string
  473. */
  474. public static function show_avatar($Avatar, $UserID, $Username, $Setting, $Size = 150, $ReturnHTML = true) {
  475. $Avatar = ImageTools::process($Avatar, false, 'avatar', $UserID);
  476. $Style = 'style="max-height: 400px;"';
  477. $AvatarMouseOverText = '';
  478. $SecondAvatar = '';
  479. $Class = 'class="double_avatar"';
  480. $EnabledRewards = Donations::get_enabled_rewards($UserID);
  481. if ($EnabledRewards['HasAvatarMouseOverText']) {
  482. $Rewards = Donations::get_rewards($UserID);
  483. $AvatarMouseOverText = $Rewards['AvatarMouseOverText'];
  484. }
  485. if (!empty($AvatarMouseOverText)) {
  486. $AvatarMouseOverText = "title=\"$AvatarMouseOverText\" alt=\"$AvatarMouseOverText\"";
  487. } else {
  488. $AvatarMouseOverText = "alt=\"$Username's avatar\"";
  489. }
  490. if ($EnabledRewards['HasSecondAvatar'] && !empty($Rewards['SecondAvatar'])) {
  491. $SecondAvatar = ' data-gazelle-second-avatar="' . ImageTools::process($Rewards['SecondAvatar'], false, 'avatar2', $UserID) . '"';
  492. }
  493. // case 1 is avatars disabled
  494. switch ($Setting) {
  495. case 0:
  496. if (!empty($Avatar)) {
  497. $ToReturn = ($ReturnHTML ? "<a href=\"user.php?id=$UserID\"><img src=\"$Avatar\" ".($Size?"width=\"$Size\" ":"")."$Style $AvatarMouseOverText$SecondAvatar $Class /></a>" : $Avatar);
  498. } else {
  499. $URL = STATIC_SERVER.'common/avatars/default.png';
  500. $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar />" : $URL);
  501. }
  502. break;
  503. case 2:
  504. $ShowAvatar = true;
  505. case 3:
  506. switch (G::$LoggedUser['Identicons']) {
  507. case 0:
  508. $Type = 'identicon';
  509. break;
  510. case 1:
  511. $Type = 'monsterid';
  512. break;
  513. case 2:
  514. $Type = 'wavatar';
  515. break;
  516. case 3:
  517. $Type = 'retro';
  518. break;
  519. case 4:
  520. $Type = '1';
  521. $Robot = true;
  522. break;
  523. case 5:
  524. $Type = '2';
  525. $Robot = true;
  526. break;
  527. case 6:
  528. $Type = '3';
  529. $Robot = true;
  530. break;
  531. default:
  532. $Type = 'identicon';
  533. }
  534. $Rating = 'pg';
  535. if (!isset($Robot) || !$Robot) {
  536. $URL = 'https://secure.gravatar.com/avatar/'.md5(strtolower(trim($Username)))."?s=$Size&amp;d=$Type&amp;r=$Rating";
  537. } else {
  538. $URL = 'https://robohash.org/'.md5($Username)."?set=set$Type&amp;size={$Size}x$Size";
  539. }
  540. if ($ShowAvatar == true && !empty($Avatar)) {
  541. $ToReturn = ($ReturnHTML ? "<img src=\"$Avatar\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar $Class />" : $Avatar);
  542. } else {
  543. $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText $Class />" : $URL);
  544. }
  545. break;
  546. default:
  547. $URL = STATIC_SERVER.'common/avatars/default.png';
  548. $ToReturn = ($ReturnHTML ? "<img src=\"$URL\" width=\"$Size\" $Style $AvatarMouseOverText$SecondAvatar $Class/>" : $URL);
  549. }
  550. return $ToReturn;
  551. }
  552. public static function has_avatars_enabled() {
  553. global $HeavyInfo;
  554. return isset($HeavyInfo['DisableAvatars']) && ($HeavyInfo['DisableAvatars'] != 1);
  555. }
  556. /**
  557. * Checks whether user has autocomplete enabled
  558. *
  559. * 0 - Enabled everywhere (default), 1 - Disabled, 2 - Searches only
  560. *
  561. * @param string $Type the type of the input.
  562. * @param boolean $Output echo out HTML
  563. * @return boolean
  564. */
  565. public static function has_autocomplete_enabled($Type, $Output = true) {
  566. $Enabled = false;
  567. if (empty(G::$LoggedUser['AutoComplete'])) {
  568. $Enabled = true;
  569. } elseif (G::$LoggedUser['AutoComplete'] !== 1) {
  570. switch ($Type) {
  571. case 'search':
  572. if (G::$LoggedUser['AutoComplete'] == 2) {
  573. $Enabled = true;
  574. }
  575. break;
  576. case 'other':
  577. if (G::$LoggedUser['AutoComplete'] != 2) {
  578. $Enabled = true;
  579. }
  580. break;
  581. }
  582. }
  583. if ($Enabled && $Output) {
  584. echo ' data-gazelle-autocomplete="true"';
  585. }
  586. if (!$Output) {
  587. // don't return a boolean if you're echoing HTML
  588. return $Enabled;
  589. }
  590. }
  591. /*
  592. * Initiate a password reset
  593. *
  594. * @param int $UserID The user ID
  595. * @param string $Username The username
  596. * @param string $Email The email address
  597. */
  598. public static function resetPassword($UserID, $Username, $Email) {
  599. $ResetKey = Users::make_secret();
  600. G::$DB->query("
  601. UPDATE users_info
  602. SET
  603. ResetKey = '" . db_string($ResetKey) . "',
  604. ResetExpires = '" . time_plus(60 * 60) . "'
  605. WHERE UserID = '$UserID'");
  606. require(SERVER_ROOT . '/classes/templates.class.php');
  607. $TPL = NEW TEMPLATE;
  608. $TPL->open(SERVER_ROOT . '/templates/password_reset.tpl'); // Password reset template
  609. $TPL->set('Username', $Username);
  610. $TPL->set('ResetKey', $ResetKey);
  611. $TPL->set('IP', $_SERVER['REMOTE_ADDR']);
  612. $TPL->set('SITE_NAME', SITE_NAME);
  613. $TPL->set('SITE_DOMAIN', SITE_DOMAIN);
  614. Misc::send_email($Email, 'Password reset information for ' . SITE_NAME, $TPL->get(), 'noreply');
  615. }
  616. }