]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / GNUsocialProfileExtensions / GNUsocialProfileExtensionsPlugin.php
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
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 include_once $dir . '/lib/profiletools.php';
34
35 class GNUsocialProfileExtensionsPlugin extends Plugin
36 {
37
38     function onCheckSchema()
39     {
40         $schema = Schema::get();
41         $schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
42         $schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
43                                           
44     }
45
46     function onRouterInitialized($m)
47     {
48         $m->connect(':nickname/bio', array('action' => 'bio'));
49         $m->connect('admin/profilefields', array('action' => 'profilefieldsAdminPanel'));
50         $m->connect('notice/respond', array('action' => 'newresponse'));
51         return true;
52     }
53
54     function onEndProfileFormData($action)
55     {
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, 
66                                $field->description);
67             }
68             else if ($field->type == 'text') {
69                 $action->textarea($fieldname, $field->title,
70                                   ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
71                                   $field->description);
72             }
73             $action->elementEnd('li');
74         }
75     }
76
77     function onEndProfileSaveForm($action)
78     {
79         $fields = GNUsocialProfileExtensionField::allFields();
80         $user = common_current_user();
81         $profile = $user->getProfile();
82         foreach ($fields as $field) {
83             $val = $action->trimmed($field->systemname);
84
85             $response = new GNUsocialProfileExtensionResponse();
86             $response->profile_id = $profile->id;
87             $response->extension_id = $field->id;
88             
89             if ($response->find()) {
90                 $response->fetch();
91                 $response->value = $val;
92                 if ($response->validate()) {
93                     if (empty($val))
94                         $response->delete();
95                     else
96                         $response->update();
97                 }
98             }
99             else {
100                 $response->value = $val;
101                 $response->insert();
102             }
103         }
104     }
105     
106     function onEndShowStyles($action)
107     {
108         $action->cssLink('/plugins/GNUsocialProfileExtensions/res/style.css');
109     }
110
111     function onEndShowScripts($action)
112     {
113         $action->script('plugins/GNUsocialProfileExtensions/js/profile.js');
114     }
115
116     function onEndAdminPanelNav($nav)
117     {
118         if (AdminPanelAction::canAdmin('profilefields')) {
119
120             $action_name = $nav->action->trimmed('action');
121
122             $nav->out->menuItem(
123                 '/admin/profilefields',
124                 _m('Profile Fields'),
125                 _m('Custom profile fields'),
126                 $action_name == 'profilefieldsadminpanel',
127                 'nav_profilefields_admin_panel'
128             );
129         }
130
131         return true;
132     }
133
134     function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
135     { 
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');
139     }
140 }