. /** * Extra profile bio-like fields and allows administrators to define * additional profile fields for the users of a GNU social installation. * * @category Widget * @package GNU social * @author Brion Vibber * @author Max Shinn * @author Diogo Cordeiro * @copyright 2011-2019 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ defined('GNUSOCIAL') || die(); include_once __DIR__ . '/lib/profiletools.php'; class ExtendedProfilePlugin extends Plugin { const PLUGIN_VERSION = '3.0.2'; public function onPluginVersion(array &$versions): bool { $versions[] = [ 'name' => 'ExtendedProfile', 'version' => self::PLUGIN_VERSION, 'author' => 'Brion Vibber, Samantha Doherty, Zach Copley, Max Shinn, Diogo Cordeiro', 'homepage' => GNUSOCIAL_ENGINE_REPO_URL . 'tree/master/plugins/ExtendedProfile', // TRANS: Module description. 'rawdescription' => _m('UI extensions for additional profile fields.') ]; return true; } /** * Add paths to the router table * * Hook for RouterInitialized event. * * @param URLMapper $m URL mapper * * @return bool hook return * @throws Exception */ public function onStartInitializeRouter(URLMapper $m) { $m->connect( ':nickname/detail', ['action' => 'profiledetail'], ['nickname' => Nickname::DISPLAY_FMT] ); $m->connect( '/settings/profile/finduser', ['action' => 'Userautocomplete'] ); $m->connect( 'settings/profile/detail', ['action' => 'profiledetailsettings'] ); $m->connect( 'panel/profilefields', ['action' => 'profilefieldsAdminPanel'] ); return true; } public function onCheckSchema() { $schema = Schema::get(); $schema->ensureTable('profile_detail', Profile_detail::schemaDef()); $schema->ensureTable('gnusocialprofileextensionfield', GNUsocialProfileExtensionField::schemaDef()); $schema->ensureTable('gnusocialprofileextensionresponse', GNUsocialProfileExtensionResponse::schemaDef()); return true; } public function onEndShowAccountProfileBlock(HTMLOutputter $out, Profile $profile) { $user = User::getKV('id', $profile->id); if ($user) { $url = common_local_url('profiledetail', ['nickname' => $user->nickname]); // TRANS: Link text on user profile page leading to extended profile page. $out->element('a', ['href' => $url, 'class' => 'profiledetail'], _m('More details...')); } } /** * 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( common_local_url('profilefieldsAdminPanel'), _m('Profile Fields'), _m('Custom profile fields'), $action_name == 'profilefieldsAdminPanel', 'nav_profilefields_admin_panel' ); } return true; } }