user-edit.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('database.php');
  16. require_once('templating.php');
  17. require_once('user-menu.php');
  18. require_once('data/User.php');
  19. require_once('data/TagCloud.php');
  20. if ($logged_in == false) {
  21. displayError("Error", "Not logged in. You shouldn't be here.");
  22. }
  23. $errors = array();
  24. if ($_POST['submit']) {
  25. if (!empty($_POST['id'])) {
  26. # Need better URI validation, but this will do for now. I think
  27. # PEAR has a suitable module to help out here.
  28. if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['id'])) {
  29. $errors[] = 'WebID must be a URI.';
  30. }
  31. if (preg_match('/\s/', $_POST['id'])) {
  32. $errors[] = 'WebID must be a URI. Valid URIs cannot contain whitespace.';
  33. }
  34. }
  35. if (!empty($_POST['delete_account'])) {
  36. header('Location: ' . $base_url . '/delete-profile.php');
  37. die();
  38. }
  39. if (!empty($_POST['homepage'])) {
  40. # Need better URI validation, but this will do for now. I think
  41. # PEAR has a suitable module to help out here.
  42. if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['homepage'])) {
  43. $errors[] = 'Homepage must be a URI.';
  44. }
  45. if (preg_match('/\s/', $_POST['homepage'])) {
  46. $errors[] = 'Homepage must be a URI. Valid URIs cannot contain whitespace.';
  47. }
  48. }
  49. if (!empty($_POST['avatar_uri'])) {
  50. # Need better URI validation, but this will do for now. I think
  51. # PEAR has a suitable module to help out here.
  52. if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['avatar_uri'])) {
  53. $errors[] = 'Avatar must be a URI.';
  54. }
  55. if (preg_match('/\s/', $_POST['avatar_uri'])) {
  56. $errors[] = 'Avatar must be a URI. Valid URIs cannot contain whitespace.';
  57. }
  58. }
  59. if (!empty($_POST['laconica_profile'])) {
  60. # Need better URI validation, but this will do for now. I think
  61. # PEAR has a suitable module to help out here.
  62. if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['laconica_profile'])) {
  63. $errors[] = 'Laconica profile must be a URI.';
  64. }
  65. if (preg_match('/\s/', $_POST['laconica_profile'])) {
  66. $errors[] = 'Laconica profile must be a URI. Valid URIs cannot contain whitespace.';
  67. }
  68. }
  69. if (!empty($_POST['journal_rss'])) {
  70. # Need better URI validation, but this will do for now. I think
  71. # PEAR has a suitable module to help out here.
  72. if (!preg_match('/^[a-z0-9\+\.\-]+\:/i', $_POST['journal_rss'])) {
  73. $errors[] = 'Journal RSS must be a URI.';
  74. }
  75. if (preg_match('/\s/', $_POST['journal_rss'])) {
  76. $errors[] = 'Journal RSS must be a URI. Valid URIs cannot contain whitespace.';
  77. }
  78. }
  79. if (!empty($_POST['password_1'])) {
  80. if ($_POST['password_1'] != $_POST['password_2']) {
  81. $errors[] = 'Passwords do not match.';
  82. }
  83. }
  84. if (!empty($_POST['location_uri'])) {
  85. # Currently only allow geonames URIs, but there's no reason we can't accept
  86. # others at some point in the future. (e.g. dbpedia)
  87. if (!preg_match('/^http:\/\/sws.geonames.org\/[0-9]+\/$/', $_POST['location_uri'])) {
  88. $errors[] = 'This should be a geonames.org semantic web service URI.';
  89. }
  90. }
  91. if (!isset($errors[0])) {
  92. # Currently we don't allow them to change e-mail as we probably should
  93. # have some kind of confirmation login to do so.
  94. $this_user->id = $_POST['id'];
  95. $this_user->fullname = $_POST['fullname'];
  96. $this_user->homepage = $_POST['homepage'];
  97. $this_user->bio = $_POST['bio'];
  98. $this_user->location = $_POST['location'];
  99. $this_user->location_uri = $_POST['location_uri'];
  100. $this_user->avatar_uri = $_POST['avatar_uri'];
  101. $this_user->laconica_profile = $_POST['laconica_profile'];
  102. $this_user->journal_rss = $_POST['journal_rss'];
  103. $this_user->anticommercial = $_POST['anticommercial'] == 'on' ? 1 : 0;
  104. $this_user->receive_emails = $_POST['receive_emails'] == 'on' ? 1 : 0;
  105. if (!empty($_POST['password_1'])) {
  106. $this_user->password = md5($_POST['password_1']);
  107. }
  108. $this_user->save();
  109. header('Location: ' . $this_user->getURL());
  110. exit;
  111. }
  112. }
  113. if (isset($this_user->name)) {
  114. if (isset($errors[0])) {
  115. $smarty->assign('errors', $errors);
  116. }
  117. # Stuff which cannot be changed.
  118. $smarty->assign('acctid', $this_user->acctid);
  119. $smarty->assign('avatar', $this_user->getAvatar());
  120. $smarty->assign('user', $this_user->name);
  121. # Stuff which cannot be changed *here*
  122. $smarty->assign('userlevel', $this_user->userlevel);
  123. # Stuff which cannot be changed *yet*
  124. $smarty->assign('email', $this_user->email);
  125. if ($_POST['submit']) {
  126. $smarty->assign('id', $_POST['id']);
  127. $smarty->assign('fullname', $_POST['fullname']);
  128. $smarty->assign('bio', $_POST['bio']);
  129. $smarty->assign('homepage', $_POST['homepage']);
  130. $smarty->assign('location', $_POST['location']);
  131. $smarty->assign('location_uri', $_POST['location_uri']);
  132. $smarty->assign('avatar_uri', $_POST['avatar_uri']);
  133. $smarty->assign('laconica_profile', $_POST['laconica_profile']);
  134. $smarty->assign('journal_rss', $_POST['journal_rss']);
  135. $smarty->assign('anticommercial', $_POST['anticommercial'] == 'on' ? 1 : 0);
  136. $smarty->assign('receive_emails', $_POST['receive_emails'] == 'on' ? 1 : 0);
  137. } else {
  138. $smarty->assign('id', $this_user->webid_uri);
  139. $smarty->assign('fullname', $this_user->fullname);
  140. $smarty->assign('bio', $this_user->bio);
  141. $smarty->assign('homepage', $this_user->homepage);
  142. $smarty->assign('location', $this_user->location);
  143. $smarty->assign('location_uri', $this_user->location_uri);
  144. $smarty->assign('avatar_uri', $this_user->avatar_uri);
  145. $smarty->assign('laconica_profile', $this_user->laconica_profile);
  146. $smarty->assign('journal_rss', $this_user->journal_rss);
  147. $smarty->assign('anticommercial', $this_user->anticommercial);
  148. $smarty->assign('receive_emails', $this_user->receive_emails);
  149. }
  150. # And display the page.
  151. $submenu = user_menu($this_user, 'Edit');
  152. $smarty->assign('submenu', $submenu);
  153. $smarty->assign('me', $this_user);
  154. $smarty->assign('errors', $errors);
  155. $smarty->display('user-edit.tpl');
  156. } else {
  157. displayError("User not found", "User not found, shall I call in a missing persons report?");
  158. }