| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |  * Extra profile bio-like fields and allows administrators to define | 
					
						
							|  |  |  |  * additional profile fields for the users of a GNU social installation. | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |  * @category  Widget | 
					
						
							|  |  |  |  * @package   GNU social | 
					
						
							|  |  |  |  * @author    Brion Vibber <brion@status.net> | 
					
						
							|  |  |  |  * @author    Max Shinn <trombonechamp@gmail.com> | 
					
						
							|  |  |  |  * @author    Diogo Cordeiro <diogo@fc.up.pt> | 
					
						
							|  |  |  |  * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | defined('GNUSOCIAL') || die(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | include_once __DIR__ . '/lib/profiletools.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  | class ExtendedProfilePlugin extends Plugin | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |     const PLUGIN_VERSION = '3.0.0'; | 
					
						
							| 
									
										
										
										
											2019-06-03 01:56:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-12 15:03:30 +01:00
										 |  |  |     public function onPluginVersion(array &$versions): bool | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |         $versions[] = [ | 
					
						
							| 
									
										
										
										
											2011-03-16 16:17:02 -07:00
										 |  |  |             'name' => 'ExtendedProfile', | 
					
						
							| 
									
										
										
										
											2019-06-03 01:56:52 +01:00
										 |  |  |             'version' => self::PLUGIN_VERSION, | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             'author' => 'Brion Vibber, Samantha Doherty, Zach Copley, Max Shinn, Diogo Cordeiro', | 
					
						
							| 
									
										
										
										
											2016-01-22 16:38:42 +00:00
										 |  |  |             'homepage' => 'https://git.gnu.io/gnu/gnu-social/tree/master/plugins/ExtendedProfile', | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             // TRANS: Module description.
 | 
					
						
							| 
									
										
										
										
											2011-04-07 22:25:16 +02:00
										 |  |  |             'rawdescription' => _m('UI extensions for additional profile fields.') | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Add paths to the router table | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * Hook for RouterInitialized event. | 
					
						
							|  |  |  |      * | 
					
						
							| 
									
										
										
										
											2014-11-07 15:24:05 +01:00
										 |  |  |      * @param URLMapper $m URL mapper | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  |      * | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |      * @return bool hook return | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  |      */ | 
					
						
							| 
									
										
										
										
											2014-11-07 15:24:05 +01:00
										 |  |  |     public function onStartInitializeRouter(URLMapper $m) | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-03-15 18:45:08 -07:00
										 |  |  |         $m->connect( | 
					
						
							|  |  |  |             ':nickname/detail', | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             ['action' => 'profiledetail'], | 
					
						
							|  |  |  |             ['nickname' => Nickname::DISPLAY_FMT] | 
					
						
							| 
									
										
										
										
											2011-03-15 18:45:08 -07:00
										 |  |  |         ); | 
					
						
							|  |  |  |         $m->connect( | 
					
						
							|  |  |  |             '/settings/profile/finduser', | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             ['action' => 'Userautocomplete'] | 
					
						
							| 
									
										
										
										
											2011-03-15 18:45:08 -07:00
										 |  |  |         ); | 
					
						
							|  |  |  |         $m->connect( | 
					
						
							|  |  |  |             'settings/profile/detail', | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             ['action' => 'profiledetailsettings'] | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |         $m->connect( | 
					
						
							|  |  |  |             'admin/profilefields', | 
					
						
							|  |  |  |             ['action' => 'profilefieldsAdminPanel'] | 
					
						
							| 
									
										
										
										
											2011-03-15 18:45:08 -07:00
										 |  |  |         ); | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |     public function onCheckSchema() | 
					
						
							| 
									
										
										
										
											2011-02-03 17:15:12 -08:00
										 |  |  |     { | 
					
						
							|  |  |  |         $schema = Schema::get(); | 
					
						
							|  |  |  |         $schema->ensureTable('profile_detail', Profile_detail::schemaDef()); | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |         $schema->ensureTable('gnusocialprofileextensionfield', GNUsocialProfileExtensionField::schemaDef()); | 
					
						
							|  |  |  |         $schema->ensureTable('gnusocialprofileextensionresponse', GNUsocialProfileExtensionResponse::schemaDef()); | 
					
						
							| 
									
										
										
										
											2011-02-03 17:15:12 -08:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |     public function onEndShowAccountProfileBlock(HTMLOutputter $out, Profile $profile) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |         $user = User::getKV('id', $profile->id); | 
					
						
							| 
									
										
										
										
											2011-02-02 16:38:01 -08:00
										 |  |  |         if ($user) { | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             $url = common_local_url('profiledetail', ['nickname' => $user->nickname]); | 
					
						
							| 
									
										
										
										
											2011-04-07 22:25:16 +02:00
										 |  |  |             // TRANS: Link text on user profile page leading to extended profile page.
 | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |             $out->element('a', ['href' => $url, 'class' => 'profiledetail'], _m('More details...')); | 
					
						
							| 
									
										
										
										
											2011-02-02 16:38:01 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /** | 
					
						
							|  |  |  |      * Menu item for personal subscriptions/groups area | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @param Action $action action being executed | 
					
						
							|  |  |  |      * | 
					
						
							|  |  |  |      * @return bool hook return | 
					
						
							|  |  |  |      * @throws Exception | 
					
						
							|  |  |  |      */ | 
					
						
							|  |  |  |     public function onEndAccountSettingsNav(Action $action) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $action_name = $action->trimmed('action'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         $action->menuItem( | 
					
						
							|  |  |  |             common_local_url('profiledetailsettings'), | 
					
						
							|  |  |  |             // TRANS: Extended profile plugin menu item on user settings page.
 | 
					
						
							|  |  |  |             _m('MENU', 'Full Profile'), | 
					
						
							|  |  |  |             // TRANS: Extended profile plugin tooltip for user settings menu item.
 | 
					
						
							|  |  |  |             _m('Change your extended profile settings'), | 
					
						
							|  |  |  |             $action_name === 'profiledetailsettings' | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /*public function onEndProfileFormData(Action $action): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $fields = GNUsocialProfileExtensionField::allFields(); | 
					
						
							|  |  |  |         $user = common_current_user(); | 
					
						
							|  |  |  |         $profile = $user->getProfile(); | 
					
						
							|  |  |  |         gnusocial_profile_merge($profile); | 
					
						
							|  |  |  |         foreach ($fields as $field) { | 
					
						
							|  |  |  |             $action->elementStart('li'); | 
					
						
							|  |  |  |             $fieldname = $field->systemname; | 
					
						
							|  |  |  |             if ($field->type == 'str') { | 
					
						
							|  |  |  |                 $action->input( | 
					
						
							|  |  |  |                     $fieldname, | 
					
						
							|  |  |  |                     $field->title, | 
					
						
							|  |  |  |                     ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname, | 
					
						
							|  |  |  |                     $field->description | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } elseif ($field->type == 'text') { | 
					
						
							|  |  |  |                 $action->textarea( | 
					
						
							|  |  |  |                     $fieldname, | 
					
						
							|  |  |  |                     $field->title, | 
					
						
							|  |  |  |                     ($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname, | 
					
						
							|  |  |  |                     $field->description | 
					
						
							|  |  |  |                 ); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $action->elementEnd('li'); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function onEndProfileSaveForm(Action $action): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $fields = GNUsocialProfileExtensionField::allFields(); | 
					
						
							|  |  |  |         $user = common_current_user(); | 
					
						
							|  |  |  |         $profile = $user->getProfile(); | 
					
						
							|  |  |  |         foreach ($fields as $field) { | 
					
						
							|  |  |  |             $val = $action->trimmed($field->systemname); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $response = new GNUsocialProfileExtensionResponse(); | 
					
						
							|  |  |  |             $response->profile_id = $profile->id; | 
					
						
							|  |  |  |             $response->extension_id = $field->id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if ($response->find()) { | 
					
						
							|  |  |  |                 $response->fetch(); | 
					
						
							|  |  |  |                 $response->value = $val; | 
					
						
							|  |  |  |                 if ($response->validate()) { | 
					
						
							|  |  |  |                     if (empty($val)) { | 
					
						
							|  |  |  |                         $response->delete(); | 
					
						
							|  |  |  |                     } else { | 
					
						
							|  |  |  |                         $response->update(); | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } else { | 
					
						
							|  |  |  |                 $response->value = $val; | 
					
						
							|  |  |  |                 $response->insert(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     }*/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function onEndShowStyles(Action $action): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $action->cssLink('/plugins/ExtendedProfile/css/profiledetail.css'); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function onEndShowScripts(Action $action): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         $action->script('plugins/ExtendedProfile/js/profiledetail.js'); | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     public function onEndAdminPanelNav(AdminPanelNav $nav): bool | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         if (AdminPanelAction::canAdmin('profilefields')) { | 
					
						
							|  |  |  |             $action_name = $nav->action->trimmed('action'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             $nav->out->menuItem( | 
					
						
							| 
									
										
										
										
											2019-08-21 17:11:37 +01:00
										 |  |  |                 common_local_url('profilefieldsAdminPanel'), | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |                 _m('Profile Fields'), | 
					
						
							|  |  |  |                 _m('Custom profile fields'), | 
					
						
							| 
									
										
										
										
											2019-08-21 17:11:37 +01:00
										 |  |  |                 $action_name == 'profilefieldsAdminPanel', | 
					
						
							| 
									
										
										
										
											2019-08-09 15:22:55 +01:00
										 |  |  |                 'nav_profilefields_admin_panel' | 
					
						
							|  |  |  |             ); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-02-02 16:23:24 -08:00
										 |  |  | } |