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 class GNUsocialProfileExtensionsPlugin extends Plugin
36 function onAutoload($cls)
38 $dir = dirname(__FILE__);
43 case 'NewresponseAction':
44 include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -6)) . '.php';
46 case 'ProfilefieldsAdminPanelAction':
47 include_once $dir . '/actions/' . strtolower(mb_substr($cls, 0, -16)) . '.php';
52 include_once $dir . '/classes/GNUsocialProfileExtensionField.php';
53 include_once $dir . '/classes/GNUsocialProfileExtensionResponse.php';
54 include_once $dir . '/lib/profiletools.php';
55 include_once $dir . '/lib/noticetree.php';
59 function onCheckSchema()
61 $schema = Schema::get();
62 $schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
63 $schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
67 function onRouterInitialized($m)
69 $m->connect(':nickname/bio', array('action' => 'bio'));
70 $m->connect('admin/profilefields', array('action' => 'profilefieldsAdminPanel'));
71 $m->connect('notice/respond', array('action' => 'newresponse'));
75 function onEndProfileFormData($action)
77 $fields = GNUsocialProfileExtensionField::allFields();
78 $user = common_current_user();
79 $profile = $user->getProfile();
80 gnusocial_profile_merge($profile);
81 foreach ($fields as $field) {
82 $action->elementStart('li');
83 $fieldname = $field->systemname;
84 if ($field->type == 'str') {
85 $action->input($fieldname, $field->title,
86 ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
89 else if ($field->type == 'text') {
90 $action->textarea($fieldname, $field->title,
91 ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
94 $action->elementEnd('li');
98 function onEndProfileSaveForm($action)
100 $fields = GNUsocialProfileExtensionField::allFields();
101 $user = common_current_user();
102 $profile = $user->getProfile();
103 foreach ($fields as $field) {
104 $val = $action->trimmed($field->systemname);
106 $response = new GNUsocialProfileExtensionResponse();
107 $response->profile_id = $profile->id;
108 $response->extension_id = $field->id;
110 if ($response->find()) {
112 $response->value = $val;
113 if ($response->validate()) {
121 $response->value = $val;
127 function onEndShowStyles($action)
129 $action->cssLink('/plugins/GNUsocialProfileExtensions/res/style.css');
132 function onEndShowScripts($action)
134 $action->script('plugins/GNUsocialProfileExtensions/js/profile.js');
137 function onEndAdminPanelNav($nav)
139 if (AdminPanelAction::canAdmin('profilefields')) {
141 $action_name = $nav->action->trimmed('action');
144 '/admin/profilefields',
145 _m('Profile Fields'),
146 _m('Custom profile fields'),
147 $action_name == 'profilefieldsadminpanel',
148 'nav_profilefields_admin_panel'
155 function onStartPersonalGroupNav($nav)
157 $nav->out->menuItem(common_local_url('bio',
158 array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
159 _('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio');
162 //Why the heck is this shoved into this plugin!?!? It deserves its own!
163 function onShowStreamNoticeList($notice, $action, &$pnl)
165 //TODO: This function is called after the notices in $notice are superfluously retrieved in showstream.php
166 $newnotice = new Notice();
167 $newnotice->profile_id = $action->user->id;
168 $newnotice->orderBy('modified DESC');
169 $newnotice->whereAdd('reply_to IS NULL');
170 $newnotice->limit(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
173 $pnl = new NoticeTree($newnotice, $action);