profiletools.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social 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. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Allows administrators to define additional profile fields for the users of a GNU social installation.
  18. *
  19. * @category Widget
  20. * @package GNU social
  21. * @author Max Shinn <trombonechamp@gmail.com>
  22. * @author Diogo Cordeiro <diogo@fc.up.pt>
  23. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  24. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  25. */
  26. defined('GNUSOCIAL') || die();
  27. function gnusocial_profile_merge(&$profile)
  28. {
  29. $responses = GNUsocialProfileExtensionResponse::findResponsesByProfile($profile->id);
  30. $profile->customfields = [];
  31. foreach ($responses as $response) {
  32. $title = $response->systemname;
  33. $profile->$title = $response->value;
  34. $profile->customfields[] = $title;
  35. }
  36. }
  37. function gnusocial_field_systemname_validate($systemname)
  38. {
  39. // Ensure it doesn't exist already
  40. $fields = GNUsocialProfileExtensionField::allFields();
  41. foreach ($fields as $field) {
  42. if ($field->systemname == $systemname) {
  43. return false;
  44. }
  45. }
  46. // Ensure that it consist of only alphanumeric characters
  47. return ctype_alnum($systemname);
  48. }