GNUsocialProfileExtensionsPlugin.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /**
  3. * GNU Social
  4. * Copyright (C) 2010, Free Software Foundation, Inc.
  5. *
  6. * PHP version 5
  7. *
  8. * LICENCE:
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * @category Widget
  23. * @package GNU Social
  24. * @author Max Shinn <trombonechamp@gmail.com>
  25. * @copyright 2011 Free Software Foundation, Inc.
  26. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
  27. */
  28. if (!defined('STATUSNET')) {
  29. exit(1);
  30. }
  31. include_once $dir . '/lib/profiletools.php';
  32. class GNUsocialProfileExtensionsPlugin extends Plugin
  33. {
  34. function onCheckSchema()
  35. {
  36. $schema = Schema::get();
  37. $schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
  38. $schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
  39. }
  40. function onRouterInitialized($m)
  41. {
  42. $m->connect(':nickname/bio', array('action' => 'bio'));
  43. $m->connect('admin/profilefields', array('action' => 'profilefieldsAdminPanel'));
  44. $m->connect('notice/respond', array('action' => 'newresponse'));
  45. return true;
  46. }
  47. function onEndProfileFormData($action)
  48. {
  49. $fields = GNUsocialProfileExtensionField::allFields();
  50. $user = common_current_user();
  51. $profile = $user->getProfile();
  52. gnusocial_profile_merge($profile);
  53. foreach ($fields as $field) {
  54. $action->elementStart('li');
  55. $fieldname = $field->systemname;
  56. if ($field->type == 'str') {
  57. $action->input($fieldname, $field->title,
  58. ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
  59. $field->description);
  60. }
  61. else if ($field->type == 'text') {
  62. $action->textarea($fieldname, $field->title,
  63. ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
  64. $field->description);
  65. }
  66. $action->elementEnd('li');
  67. }
  68. }
  69. function onEndProfileSaveForm($action)
  70. {
  71. $fields = GNUsocialProfileExtensionField::allFields();
  72. $user = common_current_user();
  73. $profile = $user->getProfile();
  74. foreach ($fields as $field) {
  75. $val = $action->trimmed($field->systemname);
  76. $response = new GNUsocialProfileExtensionResponse();
  77. $response->profile_id = $profile->id;
  78. $response->extension_id = $field->id;
  79. if ($response->find()) {
  80. $response->fetch();
  81. $response->value = $val;
  82. if ($response->validate()) {
  83. if (empty($val))
  84. $response->delete();
  85. else
  86. $response->update();
  87. }
  88. }
  89. else {
  90. $response->value = $val;
  91. $response->insert();
  92. }
  93. }
  94. }
  95. function onEndShowStyles($action)
  96. {
  97. $action->cssLink('/plugins/GNUsocialProfileExtensions/res/style.css');
  98. }
  99. function onEndShowScripts($action)
  100. {
  101. $action->script('plugins/GNUsocialProfileExtensions/js/profile.js');
  102. }
  103. function onEndAdminPanelNav($nav)
  104. {
  105. if (AdminPanelAction::canAdmin('profilefields')) {
  106. $action_name = $nav->action->trimmed('action');
  107. $nav->out->menuItem(
  108. '/admin/profilefields',
  109. _m('Profile Fields'),
  110. _m('Custom profile fields'),
  111. $action_name == 'profilefieldsadminpanel',
  112. 'nav_profilefields_admin_panel'
  113. );
  114. }
  115. return true;
  116. }
  117. function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
  118. {
  119. $nav->out->menuItem(common_local_url('bio',
  120. array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
  121. _('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio');
  122. }
  123. //Why the heck is this shoved into this plugin!?!? It deserves its own!
  124. function onShowStreamNoticeList($notice, $action, &$pnl)
  125. {
  126. //TODO: This function is called after the notices in $notice are superfluously retrieved in showstream.php
  127. $newnotice = new Notice();
  128. $newnotice->profile_id = $action->user->id;
  129. $newnotice->orderBy('modified DESC');
  130. $newnotice->whereAdd('reply_to IS NULL');
  131. $newnotice->limit(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
  132. $newnotice->find();
  133. $pnl = new NoticeTree($newnotice, $action);
  134. return false;
  135. }
  136. }