4 * Copyright (C) 2010, Free Software Foundation, Inc.
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.
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.
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/>.
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
29 if (!defined('STATUSNET')) {
33 include_once $dir . '/lib/profiletools.php';
35 class GNUsocialProfileExtensionsPlugin extends Plugin
38 function onCheckSchema()
40 $schema = Schema::get();
41 $schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
42 $schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
46 function onRouterInitialized($m)
48 $m->connect(':nickname/bio', array('action' => 'bio'));
49 $m->connect('admin/profilefields', array('action' => 'profilefieldsAdminPanel'));
50 $m->connect('notice/respond', array('action' => 'newresponse'));
54 function onEndProfileFormData($action)
56 $fields = GNUsocialProfileExtensionField::allFields();
57 $user = common_current_user();
58 $profile = $user->getProfile();
59 gnusocial_profile_merge($profile);
60 foreach ($fields as $field) {
61 $action->elementStart('li');
62 $fieldname = $field->systemname;
63 if ($field->type == 'str') {
64 $action->input($fieldname, $field->title,
65 ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
68 else if ($field->type == 'text') {
69 $action->textarea($fieldname, $field->title,
70 ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
73 $action->elementEnd('li');
77 function onEndProfileSaveForm($action)
79 $fields = GNUsocialProfileExtensionField::allFields();
80 $user = common_current_user();
81 $profile = $user->getProfile();
82 foreach ($fields as $field) {
83 $val = $action->trimmed($field->systemname);
85 $response = new GNUsocialProfileExtensionResponse();
86 $response->profile_id = $profile->id;
87 $response->extension_id = $field->id;
89 if ($response->find()) {
91 $response->value = $val;
92 if ($response->validate()) {
100 $response->value = $val;
106 function onEndShowStyles($action)
108 $action->cssLink('/plugins/GNUsocialProfileExtensions/res/style.css');
111 function onEndShowScripts($action)
113 $action->script('plugins/GNUsocialProfileExtensions/js/profile.js');
116 function onEndAdminPanelNav($nav)
118 if (AdminPanelAction::canAdmin('profilefields')) {
120 $action_name = $nav->action->trimmed('action');
123 '/admin/profilefields',
124 _m('Profile Fields'),
125 _m('Custom profile fields'),
126 $action_name == 'profilefieldsadminpanel',
127 'nav_profilefields_admin_panel'
134 function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
136 $nav->out->menuItem(common_local_url('bio',
137 array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
138 _('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio');