ExtendedProfilePlugin.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. * Extra profile bio-like fields and allows administrators to define
  18. * additional profile fields for the users of a GNU social installation.
  19. *
  20. * @category Widget
  21. * @package GNU social
  22. * @author Brion Vibber <brion@status.net>
  23. * @author Max Shinn <trombonechamp@gmail.com>
  24. * @author Diogo Cordeiro <diogo@fc.up.pt>
  25. * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org
  26. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  27. */
  28. defined('GNUSOCIAL') || die();
  29. include_once __DIR__ . '/lib/profiletools.php';
  30. class ExtendedProfilePlugin extends Plugin
  31. {
  32. const PLUGIN_VERSION = '3.0.2';
  33. public function onPluginVersion(array &$versions): bool
  34. {
  35. $versions[] = [
  36. 'name' => 'ExtendedProfile',
  37. 'version' => self::PLUGIN_VERSION,
  38. 'author' => 'Brion Vibber, Samantha Doherty, Zach Copley, Max Shinn, Diogo Cordeiro',
  39. 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/ExtendedProfile',
  40. // TRANS: Module description.
  41. 'rawdescription' => _m('UI extensions for additional profile fields.')
  42. ];
  43. return true;
  44. }
  45. /**
  46. * Add paths to the router table
  47. *
  48. * Hook for RouterInitialized event.
  49. *
  50. * @param URLMapper $m URL mapper
  51. *
  52. * @return bool hook return
  53. * @throws Exception
  54. */
  55. public function onStartInitializeRouter(URLMapper $m)
  56. {
  57. $m->connect(
  58. ':nickname/detail',
  59. ['action' => 'profiledetail'],
  60. ['nickname' => Nickname::DISPLAY_FMT]
  61. );
  62. $m->connect(
  63. '/settings/profile/finduser',
  64. ['action' => 'Userautocomplete']
  65. );
  66. $m->connect(
  67. 'settings/profile/detail',
  68. ['action' => 'profiledetailsettings']
  69. );
  70. $m->connect(
  71. 'panel/profilefields',
  72. ['action' => 'profilefieldsAdminPanel']
  73. );
  74. return true;
  75. }
  76. public function onCheckSchema()
  77. {
  78. $schema = Schema::get();
  79. $schema->ensureTable('profile_detail', Profile_detail::schemaDef());
  80. $schema->ensureTable('gnusocialprofileextensionfield', GNUsocialProfileExtensionField::schemaDef());
  81. $schema->ensureTable('gnusocialprofileextensionresponse', GNUsocialProfileExtensionResponse::schemaDef());
  82. return true;
  83. }
  84. public function onEndShowAccountProfileBlock(HTMLOutputter $out, Profile $profile)
  85. {
  86. $user = User::getKV('id', $profile->id);
  87. if ($user) {
  88. $url = common_local_url('profiledetail', ['nickname' => $user->nickname]);
  89. // TRANS: Link text on user profile page leading to extended profile page.
  90. $out->element('a', ['href' => $url, 'class' => 'profiledetail'], _m('More details...'));
  91. }
  92. }
  93. /**
  94. * Menu item for personal subscriptions/groups area
  95. *
  96. * @param Action $action action being executed
  97. *
  98. * @return bool hook return
  99. * @throws Exception
  100. */
  101. public function onEndAccountSettingsNav(Action $action)
  102. {
  103. $action_name = $action->trimmed('action');
  104. $action->menuItem(
  105. common_local_url('profiledetailsettings'),
  106. // TRANS: Extended profile plugin menu item on user settings page.
  107. _m('MENU', 'Full Profile'),
  108. // TRANS: Extended profile plugin tooltip for user settings menu item.
  109. _m('Change your extended profile settings'),
  110. $action_name === 'profiledetailsettings'
  111. );
  112. return true;
  113. }
  114. /*public function onEndProfileFormData(Action $action): bool
  115. {
  116. $fields = GNUsocialProfileExtensionField::allFields();
  117. $user = common_current_user();
  118. $profile = $user->getProfile();
  119. gnusocial_profile_merge($profile);
  120. foreach ($fields as $field) {
  121. $action->elementStart('li');
  122. $fieldname = $field->systemname;
  123. if ($field->type == 'str') {
  124. $action->input(
  125. $fieldname,
  126. $field->title,
  127. ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
  128. $field->description
  129. );
  130. } elseif ($field->type == 'text') {
  131. $action->textarea(
  132. $fieldname,
  133. $field->title,
  134. ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
  135. $field->description
  136. );
  137. }
  138. $action->elementEnd('li');
  139. }
  140. return true;
  141. }
  142. public function onEndProfileSaveForm(Action $action): bool
  143. {
  144. $fields = GNUsocialProfileExtensionField::allFields();
  145. $user = common_current_user();
  146. $profile = $user->getProfile();
  147. foreach ($fields as $field) {
  148. $val = $action->trimmed($field->systemname);
  149. $response = new GNUsocialProfileExtensionResponse();
  150. $response->profile_id = $profile->id;
  151. $response->extension_id = $field->id;
  152. if ($response->find()) {
  153. $response->fetch();
  154. $response->value = $val;
  155. if ($response->validate()) {
  156. if (empty($val)) {
  157. $response->delete();
  158. } else {
  159. $response->update();
  160. }
  161. }
  162. } else {
  163. $response->value = $val;
  164. $response->insert();
  165. }
  166. }
  167. return true;
  168. }*/
  169. public function onEndShowStyles(Action $action): bool
  170. {
  171. $action->cssLink('/plugins/ExtendedProfile/css/profiledetail.css');
  172. return true;
  173. }
  174. public function onEndShowScripts(Action $action): bool
  175. {
  176. $action->script('plugins/ExtendedProfile/js/profiledetail.js');
  177. return true;
  178. }
  179. public function onEndAdminPanelNav(AdminPanelNav $nav): bool
  180. {
  181. if (AdminPanelAction::canAdmin('profilefields')) {
  182. $action_name = $nav->action->trimmed('action');
  183. $nav->out->menuItem(
  184. common_local_url('profilefieldsAdminPanel'),
  185. _m('Profile Fields'),
  186. _m('Custom profile fields'),
  187. $action_name == 'profilefieldsAdminPanel',
  188. 'nav_profilefields_admin_panel'
  189. );
  190. }
  191. return true;
  192. }
  193. }