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());
45 function onRouterInitialized(URLMapper $m)
47 $m->connect(':nickname/bio', array('action' => 'bio'));
48 $m->connect('admin/profilefields', array('action' => 'profilefieldsAdminPanel'));
49 $m->connect('notice/respond', array('action' => 'newresponse'));
53 function onEndProfileFormData($action)
55 $fields = GNUsocialProfileExtensionField::allFields();
56 $user = common_current_user();
57 $profile = $user->getProfile();
58 gnusocial_profile_merge($profile);
59 foreach ($fields as $field) {
60 $action->elementStart('li');
61 $fieldname = $field->systemname;
62 if ($field->type == 'str') {
63 $action->input($fieldname, $field->title,
64 ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
67 else if ($field->type == 'text') {
68 $action->textarea($fieldname, $field->title,
69 ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
72 $action->elementEnd('li');
76 function onEndProfileSaveForm($action)
78 $fields = GNUsocialProfileExtensionField::allFields();
79 $user = common_current_user();
80 $profile = $user->getProfile();
81 foreach ($fields as $field) {
82 $val = $action->trimmed($field->systemname);
84 $response = new GNUsocialProfileExtensionResponse();
85 $response->profile_id = $profile->id;
86 $response->extension_id = $field->id;
88 if ($response->find()) {
90 $response->value = $val;
91 if ($response->validate()) {
99 $response->value = $val;
105 function onEndShowStyles(Action $action)
107 $action->cssLink('/plugins/GNUsocialProfileExtensions/res/style.css');
110 function onEndShowScripts(Action $action)
112 $action->script('plugins/GNUsocialProfileExtensions/js/profile.js');
115 function onEndAdminPanelNav(Menu $nav)
117 if (AdminPanelAction::canAdmin('profilefields')) {
119 $action_name = $nav->action->trimmed('action');
122 '/admin/profilefields',
123 _m('Profile Fields'),
124 _m('Custom profile fields'),
125 $action_name == 'profilefieldsadminpanel',
126 'nav_profilefields_admin_panel'
133 function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
135 $nav->out->menuItem(common_local_url('bio',
136 array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
137 _('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio');
140 //Why the heck is this shoved into this plugin!?!? It deserves its own!
141 function onShowStreamNoticeList($notice, $action, &$pnl)
143 //TODO: This function is called after the notices in $notice are superfluously retrieved in showstream.php
144 $newnotice = new Notice();
145 $newnotice->profile_id = $action->user->id;
146 $newnotice->orderBy('modified DESC');
147 $newnotice->whereAdd('reply_to IS NULL');
148 $newnotice->limit(($action->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
151 $pnl = new NoticeTree($newnotice, $action);