PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Profile.php

https://bitbucket.org/nexea/x00n
PHP | 458 lines | 455 code | 3 blank | 0 comment | 0 complexity | f5aa6396eacb39ac7dc4c3a7a9e51d68 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. class UserProfile{
  3. public function userControlProfile(){
  4. global $user_info, $HTTP_SERVER_VARS, $PHP_SELF, $tzs, $timezone, $domain;
  5. stdhead($user_info["username"] . "'s", true, false);
  6. if (isset($_GET["edited"])) {
  7. print("<h2>Profile updated!</h2>\n");
  8. if ($_GET["mailsent"])
  9. print("<h2>Confirmation email has been sent!</h2>\n");
  10. }
  11. elseif (isset($_GET["emailch"]))
  12. print("<h2>Email address changed!</h2>\n");
  13. else
  14. echo "<h2>Welcome, <a href=\"?action=user&amp;id=" . $user_info['id'] . "\">$user_info[username]</a>!</h2>\n";
  15. ?>
  16. <h2><font color="red">Are you new. We want to help you get started. Please <a href="gettingstarted">click here</a> for help on getting started.</font></h2>
  17. <table border="1" cellspacing="0" cellpadding="10" align="center">
  18. <tr>
  19. <td align="center" width="33%"><a href="?action=logout"><b>Logout</b></a></td>
  20. <td align="center" width="33%"><a href="?action=mytorrents"><b>My torrents</b></a></td>
  21. <td align="center" width="33%"><a href="?action=friends"><b>My Friends</b></a></td>
  22. </tr>
  23. <tr>
  24. <td colspan="3">
  25. <form enctype="multipart/form-data" id="creator" name="creator" accept-charset="UTF-8" method="post" action="index.php?action=profile2">
  26. <table border="1" cellspacing="0" cellpadding="5" width="100%">
  27. <?php
  28. $countries = "<option value=\"0\">---- None selected ----</option>\n";
  29. $ct_r = mysql_query("SELECT id,name FROM countries ORDER BY name") or die;
  30. while ($ct_a = mysql_fetch_array($ct_r))
  31. $countries .= "<option value=\"$ct_a[id]\"" . ($user_info["country"] == $ct_a['id'] ? " selected=\"yes\"" : "") . ">$ct_a[name]</option>\n";
  32. ksort($tzs);
  33. reset($tzs);
  34. while (list($key, $val) = each($tzs)) {
  35. if ($user_info["tzoffset"] == $key) {
  36. $timezone .= "<option value=\"$key\" selected>$val</option>\n";
  37. }
  38. else
  39. {
  40. $timezone .= "<option value=\"$key\">$val</option>\n";
  41. }
  42. }
  43. tr("Accept PMs", "<input type=\"radio\" name=\"acceptpms\"" . ($user_info["acceptpms"] == "yes" ? " checked" : "") . " value=\"yes\">All (except blocks)
  44. <input type=\"radio\" name=\"acceptpms\"" . ($user_info["acceptpms"] == "friends" ? " checked" : "") . " value=\"friends\">Friends only
  45. <input type=\"radio\" name=\"acceptpms\"" . ($user_info["acceptpms"] == "no" ? " checked" : "") . " value=\"no\">Staff only" ,1);
  46. tr("Delete PMs", "<input type=\"checkbox\" name=\"deletepms\"" . ($user_info["deletepms"] == "yes" ? " checked" : "") . "\"> (Default value for \"Delete PM on reply\")",1);
  47. tr("Save PMs", "<input type=\"checkbox\" name=\"savepms\"" . ($user_info["savepms"] == "yes" ? " checked" : "") . "\"> (Default value for \"Save PM to Sentbox\")",1);
  48. $r = mysql_query("SELECT id,name FROM categories ORDER BY name") or mysql_error();
  49. if (mysql_num_rows($r) > 0)
  50. {
  51. $categories = "<table><tr>\n";
  52. $i = 0;
  53. while ($a = mysql_fetch_assoc($r))
  54. {
  55. $categories .= ($i && $i % 2 == 0) ? "</tr><tr>" : "";
  56. $categories .= "<td class=\"bottom\" style=\"padding-right: 5px\">
  57. <input name=\"cat" . $a['id'] . "\" type=\"checkbox\"" . (strpos($user_info['notifs'], "[cat$a[id]]") !== false ? " checked" : "") . " value=\"yes\">&nbsp;" . htmlspecialchars($a["name"]) . "</td>\n";
  58. $i++;
  59. }
  60. $categories .= "</tr></table>\n";
  61. }
  62. tr("Email notification", "<input type=\"checkbox\" name=\"pmnotif\"" . (strpos($user_info['notifs'], "[pm]") !== false ? " checked" : "") . "\" value=\"yes\"> Notify me when I have received a PM<br>\n" .
  63. "<input type=checkbox name=emailnotif" . (strpos($user_info['notifs'], "[email]") !== false ? " checked" : "") . " value=yes> Notify me when a torrent is uploaded in one of <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my default browsing categories.\n", 1);
  64. tr("Browse default<br>categories",$categories,1);
  65. tr("Country", "<select name=country>\n$countries\n</select>",1);
  66. tr("Time zone", "<select name=tzoffset>\n$timezone\n</select><br />Be sure to select the correct time zone and be aware of Daylight Savings Time.(In the toolbar/forum/inbox)",1);
  67. tr("Avatar URL", "<input name=avatar size=50 value=\"" . htmlspecialchars($user_info["avatar"]) .
  68. "\"><br>\nWidth should be 150 pixels (will be resized if necessary)\n<br>If you need a host for the picture, try the <a href=bitbucket-upload>bitbucket</a>.",1);
  69. tr("Torrents per page", "<input type=text size=10 name=torrentsperpage value=$user_info[torrentsperpage]> (0=use default setting)",1);
  70. tr("Topics per page", "<input type=text size=10 name=topicsperpage value=$user_info[topicsperpage]> (0=use default setting)",1);
  71. tr("Posts per page", "<input type=text size=10 name=postsperpage value=$user_info[postsperpage]> (0=use default setting)",1);
  72. tr("View avatars", "<input type=checkbox name=avatars" . ($user_info["avatars"] == "yes" ? " checked" : "") . "> (Low bandwidth users might want to turn this off)",1);
  73. tr("Info", "<textarea name=info cols=50 rows=4>" . $user_info["info"] . "</textarea><br>Displayed on your public page. May contain <a href=tags target=_new>BB codes</a>.", 1);
  74. tr("Email address", "<input type=\"text\" name=\"email\" size=50 value=\"" . htmlspecialchars($user_info["email"]) . "\" />", 1);
  75. print("<tr><td colspan=\"2\" align=left><b>Note:</b> In order to change your email address, you will receive another<br>confirmation email to your new address.</td></tr>\n");
  76. tr("Reset passkey","<input type=checkbox name=resetpasskey value=1 /><br><font class=small>Any active torrents must be downloaded again to continue leeching/seeding.</font>", 1);
  77. tr("Change password", "<input type=\"password\" name=\"chpassword\" size=\"50\" />", 1);
  78. tr("Type password again", "<input type=\"password\" name=\"passagain\" size=\"50\" />", 1);
  79. ?>
  80. <tr>
  81. <td colspan="2" align="center">
  82. <input type="submit" value="Submit changes!" style='height: 25px'>
  83. <input type="reset" value="Revert changes!" style='height: 25px'>
  84. </td>
  85. </tr>
  86. </table>
  87. </form>
  88. </td>
  89. </tr>
  90. </table>
  91. <?
  92. if ($messages){
  93. print("<p>You have $messages message" . ($messages != 1 ? "s" : "") . " ($unread new) in your <a href=inbox><b>inbox</b></a>,<br>\n");
  94. if ($outmessages)
  95. print("and $outmessages message" . ($outmessages != 1 ? "s" : "") . " in your <a href=inbox?out=1><b>sentbox</b></a>.\n</p>");
  96. else
  97. print("and your <a href=inbox?out=1>sentbox</a> is empty.</p>");
  98. }
  99. else
  100. {
  101. print("<p>Your <a href=inbox>inbox</a> is empty, <br>\n");
  102. if ($outmessages)
  103. print("and you have $outmessages message" . ($outmessages != 1 ? "s" : "") . " in your <a href=inbox?out=1><b>sentbox</b></a>.\n</p>");
  104. else
  105. print("and so is your <a href=inbox?out=1>sentbox</a>.</p>");
  106. }
  107. print("<p><a href=users><b>Find User/Browse User List</b></a></p>");
  108. stdfoot();
  109. }
  110. private function bark($msg)
  111. {
  112. stdhead();
  113. stdmsg("Error", $msg);
  114. stdfoot();
  115. exit;
  116. }
  117. public function userViewProfile(){
  118. global $user_info, $HTTP_SERVER_VARS, $PHP_SELF, $tzs, $timezone, $domain;
  119. $id = $_GET["id"];
  120. if(!is_valid_id($id))
  121. bark("Bad ID $id.");
  122. if(!is_numeric($id)){
  123. die("EPIC FAIL");
  124. }
  125. $userSQL = "SELECT * FROM `users` WHERE `id`=$id";
  126. $r = @mysql_query($userSQL) or mysql_error();
  127. $user = mysql_fetch_array($r) or $this->bark("No user with ID $id.");
  128. if ($user["status"] == "pending") die;
  129. $r = mysql_query("SELECT id, name, seeders, leechers, category FROM torrents WHERE owner=$id ORDER BY name") or mysql_error();
  130. if ($user["ip"] && (get_user_class() >= UC_MODERATOR || $user["id"] == $user_info["id"]))
  131. {
  132. $ip = $user["ip"];
  133. $dom = @gethostbyaddr($user["ip"]);
  134. if ($dom == $user["ip"] || @gethostbyname($dom) != $user["ip"]){
  135. $addr = $ip;
  136. }
  137. else
  138. {
  139. $dom = strtoupper($dom);
  140. $domparts = explode(".", $dom);
  141. $domain = $domparts[count($domparts) - 2];
  142. }
  143. if ($domain == "COM" || $domain == "CO" || $domain == "NET" || $domain == "NE" || $domain == "ORG" || $domain == "OR" ){
  144. $l = 2;
  145. }
  146. else
  147. {
  148. $l = 1;
  149. $addr = "$ip ($dom)";
  150. }
  151. }
  152. if ($user[added] == "0000-00-00 00:00:00"){
  153. $joindate = 'N/A';
  154. }
  155. else
  156. {
  157. $joindate = "$user[added] (" . get_elapsed_time(sql_timestamp_to_unix_timestamp($user["added"])) . " ago)";
  158. $lastseen = $user["last_access"];
  159. }
  160. if ($lastseen == "0000-00-00 00:00:00"){
  161. $lastseen = "never";
  162. }
  163. else
  164. {
  165. $lastseen .= " (" . get_elapsed_time(sql_timestamp_to_unix_timestamp($lastseen)) . " ago)";
  166. }
  167. $res = mysql_query("SELECT COUNT(*) FROM comments WHERE user=" . $user[id]) or mysql_error();
  168. $arr3 = mysql_fetch_row($res);
  169. $torrentcomments = $arr3[0];
  170. $res = mysql_query("SELECT COUNT(*) FROM posts WHERE userid=" . $user[id]) or mysql_error();
  171. $arr3 = mysql_fetch_row($res);
  172. $forumposts = $arr3[0];
  173. if ($user['donated'] > 0){
  174. $don = "<img src=\"images/starbig.gif\">";
  175. }
  176. $res = mysql_query("SELECT name,flagpic FROM countries WHERE id=$user[country] LIMIT 1") or mysql_error();
  177. if (mysql_num_rows($res) == 1)
  178. {
  179. $arr = mysql_fetch_assoc($res);
  180. $country = "<img height=\"11\" width=\"16\" src=\"images/flag/$arr[flagpic]\" alt=\"" . $arr['name'] . "\">";
  181. $countryName = $arr['name'];
  182. }
  183. $res = mysql_query("SELECT torrent,added,uploaded,downloaded,torrents.name as torrentname,categories.name as catname,size,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id WHERE userid=$id AND seeder='no'") or mysql_error();
  184. if (mysql_num_rows($res) > 0){
  185. $leeching = maketable($res);
  186. $res = mysql_query("SELECT torrent,added,uploaded,downloaded,torrents.name as torrentname,categories.name as catname,size,image,category,seeders,leechers FROM peers LEFT JOIN torrents ON peers.torrent = torrents.id LEFT JOIN categories ON torrents.category = categories.id WHERE userid=$id AND seeder='yes'") or mysql_error();
  187. }
  188. if (mysql_num_rows($res) > 0){
  189. $seeding = maketable($res);
  190. }
  191. stdhead("Details for " . $user["username"]);
  192. $enabled = $user["enabled"] == 'yes';
  193. ?>
  194. <table width="100%" cellspacing="0" cellpadding="0" border="0">
  195. <tbody>
  196. <tr>
  197. <td width="100%" class="ctable_content">
  198. <table width="100%" cellspacing="0" cellpadding="3" border="0" class="font_12px">
  199. <tbody>
  200. <tr>
  201. <td height="94" align="center" rowspan="5"><img width="74" height="74" border="0" alt="" src="<?=htmlspecialchars($user["avatar"])?>"/></td>
  202. <td width="76" nowrap="" class="tone_1"><strong>Last visit:</strong></td>
  203. <td class="tone_1"><?=$lastseen?></td>
  204. <td width="76" nowrap="" class="tone_1"><strong>Country:</strong></td>
  205. <td class="tone_1"><?=$country?> <?=$countryName?></td>
  206. </tr>
  207. <tr>
  208. <td nowrap=""><strong>Join date: </strong></td>
  209. <td><?=$joindate?></td>
  210. <td nowrap=""><strong>Gender:</strong></td>
  211. <td>Not specified</td>
  212. </tr>
  213. <tr>
  214. <td nowrap="" class="tone_1"><strong>Rank:</strong></td>
  215. <td class="tone_1"><?=get_user_class_name($user["class"])?></td>
  216. <td nowrap="" class="tone_1"><strong>Forum Posts:</strong></td>
  217. <?php
  218. if ($forumposts && (($user["class"] >= UC_POWER_USER && $user["id"] == $user_info["id"]) || get_user_class() >= UC_MODERATOR))
  219. {
  220. print("<td class=\"tone_1\"><a href=\"userhistory.php?action=viewposts&id=$id\">$forumposts</a></td>\n");
  221. }
  222. else
  223. {
  224. print("<td class=\"tone_1\">$forumposts</td>\n");
  225. }
  226. ?>
  227. </tr>
  228. <tr>
  229. <td nowrap=""><strong>Downloaded:</strong></td>
  230. <td><?=mksize($user["downloaded"])?></td>
  231. <td nowrap=""><strong>Warnings:</strong></td>
  232. <td>0 <i class="font_10px">(5 to ban)</i></td>
  233. </tr>
  234. <tr>
  235. <td nowrap="" class="tone_1"><strong>Uploaded:</strong></td>
  236. <td class="tone_1"><?=mksize($user["uploaded"])?></td>
  237. <td nowrap="" class="tone_1"><strong>Uploaded torrents: </strong></td>
  238. <td class="tone_1">1</td>
  239. </tr>
  240. <tr>
  241. <?php
  242. if ($user["downloaded"] > 0)
  243. {
  244. $sr = $user["uploaded"] / $user["downloaded"];
  245. if ($sr >= 4)
  246. {
  247. $s = "w00t";
  248. }
  249. else if ($sr >= 2)
  250. {
  251. $s = "grin";
  252. }
  253. else if ($sr >= 1)
  254. {
  255. $s = "smile1";
  256. }
  257. else if ($sr >= 0.5)
  258. {
  259. $s = "noexpression";
  260. }
  261. else if ($sr >= 0.25)
  262. {
  263. $s = "sad";
  264. }
  265. else
  266. {
  267. $s = "cry";
  268. $sr = floor($sr * 1000) / 1000;
  269. $sr = "<table border=0 cellspacing=0 cellpadding=0><tr><td class=embedded><font color=" . get_ratio_color($sr) . ">" . number_format($sr, 3) . "</font></td><td class=embedded>&nbsp;&nbsp;<img src=images/smilies/$s.gif></td></tr></table>";
  270. }
  271. }
  272. ?>
  273. <td valign="top" nowrap="" align="center"><a class="user" href="index.php?action=profile&amp;id=<?=$user["id"]?>"><img width="8" height="8" border="0" title="Ratio: <?=round($sr,2)?>" alt="Ratio: <?=round($sr,2)?>" src="/images/ratio/n05.gif"/><img width="2" height="1" border="0" alt="" src="/images/p.gif"/><?=$user["username"]?></a></td>
  274. <td valign="top" nowrap=""><strong>Ratio:</strong></td>
  275. <?php print("<td valign=\"top\">" . round($sr,2) . "</td>\n"); ?>
  276. <td valign="top"><strong>Torrent comments: </strong></td>
  277. <?php
  278. if ($torrentcomments && (($user["class"] >= UC_POWER_USER && $user["id"] == $user_info["id"]) || get_user_class() >= UC_MODERATOR))
  279. print("<td><a href=userhistory.php?action=viewcomments&id=$id>$torrentcomments</a></td>\n");
  280. else
  281. print("<td>$torrentcomments</td>\n");
  282. ?>
  283. </tr>
  284. <tr>
  285. <td nowrap="" align="left" class="tone_1" colspan="5"><strong>Favorite quote:</strong></td>
  286. </tr>
  287. <tr>
  288. </tr>
  289. <tr>
  290. <td nowrap="" align="left" colspan="5">It isn't illegal, we are copying not stealing.</td>
  291. </tr>
  292. <tr>
  293. <td nowrap="" align="left" class="tone_1" colspan="5"><strong>Signature:</strong></td>
  294. </tr>
  295. <tr>
  296. </tr>
  297. <tr>
  298. <td nowrap="" align="left" colspan="5">x00n.com<br/>Join the revolution</td>
  299. </tr>
  300. <tr align="left" class="tone_1">
  301. <td colspan="5"><b>More options:</b></td>
  302. </tr>
  303. <tr valign="top" align="left">
  304. <td colspan="5">
  305. <center>
  306. <a onclick="SWPop('/private_message.php?to=4025189','500', '450'); return false;" href="/private_message.php?to=4025189&amp;go_back=%2Fusers%2Fdemonflicks">Send a private message</a> :: <a href="/files/?uid=4025189&amp;seeded=2">View this user's torrents</a> :: <a href="/rss/users/demonflicks.xml">RSS Feed<img width="16" hspace="5" height="16" border="0" alt="" src="/images/rss.jpg"/></a>
  307. </center>
  308. </td>
  309. </tr>
  310. </tbody>
  311. </table>
  312. </td>
  313. </tr>
  314. </tbody>
  315. </table>
  316. <?php
  317. if (get_user_class() >= UC_MODERATOR && $user["class"] < get_user_class())
  318. {
  319. begin_frame("Edit User", true);
  320. echo "<form method=\"post\" action=\"modtask.php\">
  321. <input type=\"hidden\" name=\"action\" value=\"edituser\">
  322. <input type=\"hidden\" name=\"userid\" value=\"$id\">
  323. <input type=\"hidden\" name=\"returnto\" value=\"index.php?action=profile&amp;id=$id\">
  324. <table class=\"main\" border=\"1\" cellspacing=\"0\" cellpadding=\"5\">
  325. <tr><td class=\"rowhead\">Title</td><td colspan=\"2\" align=\"left\"><input type=\"text\" size=\"60\" name=\"title\" value=\"" . htmlspecialchars($user[title]) . "\"></tr>\n";
  326. $avatar = htmlspecialchars($user["avatar"]);
  327. echo "<tr><td class=\"rowhead\">Avatar&nbsp;URL</td><td colspan=\"2\" align=\"left\"><input type=\"text\" size=\"60\" name=\"avatar\" value=\"$avatar\"></tr>";
  328. // we do not want mods to be able to change user classes or amount donated...
  329. if ($user_info["class"] > UC_ADMINISTRATOR){
  330. print("<tr><td class=\"rowhead\">Donor</td><td colspan=\"2\" align=\"left\"><input type=\"radio\" name=\"donor\" value=\"yes" .($user["donor"] == "yes" ? " checked" : "")."\">Yes <input type=\"radio\" name=\"donor\" value=\"no" .($user["donor"] == "no" ? " checked" : "")."\">No</td></tr>\n");
  331. }
  332. elseif($user_info["class"] < UC_ADMINISTRATOR)
  333. {
  334. print("<input type=\"hidden\" name=\"donor\" value=\"$user[donor]\">\n");
  335. }
  336. else
  337. {
  338. }
  339. if (get_user_class() == UC_MODERATOR && $user["class"] > UC_DONOR)
  340. printf("<input type=hidden name=class value=$user[class]\n");
  341. else
  342. {
  343. print("<tr><td class=rowhead>Class</td><td colspan=2 align=left><select name=class>\n");
  344. if (get_user_class() == UC_MODERATOR)
  345. $maxclass = UC_DONOR;
  346. else
  347. $maxclass = get_user_class() - 1;
  348. for ($i = 0; $i <= $maxclass; ++$i)
  349. print("<option value=$i" . ($user["class"] == $i ? " selected" : "") . ">$prefix" . get_user_class_name($i) . "\n");
  350. print("</select></td></tr>\n");
  351. }
  352. $modcomment = htmlspecialchars($user["modcomment"]);
  353. print("<tr><td class=rowhead>Comment</td><td colspan=2 align=left><textarea cols=60 rows=6 name=modcomment>$modcomment</textarea></td></tr>\n");
  354. $warned = $user["warned"] == "yes";
  355. print("<tr><td class=rowhead" . (!$warned ? " rowspan=2": "") . ">Warned</td>
  356. <td align=left width=20%>" .
  357. ( $warned
  358. ? "<input name=warned value='yes' type=radio checked>Yes<input name=warned value='no' type=radio>No"
  359. : "No" ) ."</td>");
  360. if ($warned)
  361. {
  362. $warneduntil = $user['warneduntil'];
  363. if ($warneduntil == '0000-00-00 00:00:00')
  364. print("<td align=center>(arbitrary duration)</td></tr>\n");
  365. else
  366. {
  367. print("<td align=center>Until $warneduntil");
  368. print(" (" . mkprettytime(strtotime($warneduntil) - gmtime()) . " to go)</td></tr>\n");
  369. }
  370. }
  371. else
  372. {
  373. echo "
  374. <td>Warn for <select name=\"warnlength\">
  375. <option value=\"0\">------</option>
  376. <option value=\"1\">1 week</option>
  377. <option value=\"2\">2 weeks</option>
  378. <option value=\"4\">4 weeks</option>
  379. <option value=\"8\">8 weeks</option>
  380. <option value=\"255\">Unlimited</option>
  381. </select>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PM comment:</td></tr>
  382. <tr><td colspan=\"2\" align=\"left\"><input type=\"text\" size=\"60\" name=\"warnpm\"></td></tr>
  383. ";
  384. }
  385. print("<tr><td class=rowhead>Enabled</td><td colspan=2 align=left><input name=enabled value='yes' type=radio" . ($enabled ? " checked" : "") . ">Yes <input name=enabled value='no' type=radio" . (!$enabled ? " checked" : "") . ">No</td></tr>\n");
  386. print("<tr><td class=rowhead>Passkey</td><td colspan=2 align=left><input name=resetkey value=1 type=checkbox> Reset passkey</td></tr>n");
  387. print("</td></tr>");
  388. print("<tr><td colspan=3 align=center><input type=submit class=btn value='Okay'></td></tr>\n");
  389. print("</table>\n");
  390. print("</form>\n");
  391. end_frame();
  392. }
  393. end_main_frame();
  394. stdfoot();
  395. }
  396. }