[GNUsocialProfileExtensions] Fixed plugin

This commit is contained in:
Diogo Cordeiro 2019-08-08 15:08:23 +01:00
parent 01cf8ab82c
commit 90bd9088bb
13 changed files with 462 additions and 772 deletions

View File

@ -16,6 +16,7 @@
"ext-simplexml": "*",
"ext-xml": "*",
"ext-xmlwriter": "*",
"ext-ctype": "*",
"apereo/phpcas": "^1.3",
"diogocomposer/xmpphp": "^3.0",
"embed/embed": "^3.4",

View File

@ -87,8 +87,8 @@ class NoticeForm extends Form
/**
* Constructor
*
* @param Action $action Action we're being embedded into
* @param array $options Array of optional parameters
* @param Action $action Action we're being embedded into
* @param array $options Array of optional parameters
* 'user' a user instead of current
* 'content' notice content
* 'inreplyto' ID of notice to reply to
@ -96,8 +96,9 @@ class NoticeForm extends Form
* 'lon' Longitude
* 'location_id' ID of location
* 'location_ns' Namespace of location
* @throws UserNoProfileException
*/
function __construct($action, $options=null)
function __construct(Action $action, array $options = [])
{
parent::__construct($action);
@ -105,10 +106,6 @@ class NoticeForm extends Form
// possibly existing HTML elements, as naming conventions are similar.
$this->id_suffix = rand();
if (is_null($options)) {
$options = array();
}
$this->actionName = $action->trimmed('action');
$prefill = array('content', 'inreplyto', 'lat',

View File

@ -1,57 +1,51 @@
<?php
// 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/>.
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* Allows administrators to define additional profile fields for the users of a GNU social installation.
*
* @category Widget
* @package GNU Social
* @package GNU social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2011 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @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
*/
if (!defined('STATUSNET')) {
exit(1);
}
defined('GNUSOCIAL') || die();
include_once $dir . '/lib/profiletools.php';
include_once __DIR__ . '/lib/profiletools.php';
class GNUsocialProfileExtensionsPlugin extends Plugin
{
function onCheckSchema()
public function onCheckSchema(): bool
{
$schema = Schema::get();
$schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
$schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
}
function onRouterInitialized($m)
{
$m->connect(':nickname/bio', ['action' => 'bio']);
$m->connect('admin/profilefields', ['action' => 'profilefieldsAdminPanel']);
$m->connect('notice/respond', ['action' => 'newresponse']);
$schema->ensureTable('gnusocialprofileextensionfield', GNUsocialProfileExtensionField::schemaDef());
$schema->ensureTable('gnusocialprofileextensionresponse', GNUsocialProfileExtensionResponse::schemaDef());
return true;
}
function onEndProfileFormData($action)
public function onRouterInitialized($m): bool
{
$m->connect('admin/profilefields', ['action' => 'profilefieldsAdminPanel']);
return true;
}
public function onEndProfileFormData($action): bool
{
$fields = GNUsocialProfileExtensionField::allFields();
$user = common_current_user();
@ -61,20 +55,26 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
$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);
}
else if ($field->type == 'text') {
$action->textarea($fieldname, $field->title,
($action->arg($fieldname)) ? $action->arg($fieldname) : $profile->$fieldname,
$field->description);
$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;
}
function onEndProfileSaveForm($action)
public function onEndProfileSaveForm($action): bool
{
$fields = GNUsocialProfileExtensionField::allFields();
$user = common_current_user();
@ -85,38 +85,40 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
$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))
if (empty($val)) {
$response->delete();
else
} else {
$response->update();
}
}
}
else {
} else {
$response->value = $val;
$response->insert();
}
}
return true;
}
function onEndShowStyles($action)
public function onEndShowStyles($action): bool
{
$action->cssLink('/plugins/GNUsocialProfileExtensions/res/style.css');
return true;
}
function onEndShowScripts($action)
public function onEndShowScripts($action): bool
{
$action->script('plugins/GNUsocialProfileExtensions/js/profile.js');
return true;
}
function onEndAdminPanelNav($nav)
public function onEndAdminPanelNav($nav): bool
{
if (AdminPanelAction::canAdmin('profilefields')) {
$action_name = $nav->action->trimmed('action');
$nav->out->menuItem(
@ -130,11 +132,4 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
return true;
}
function onStartPersonalGroupNav(Menu $nav, Profile $target, Profile $scoped=null)
{
$nav->out->menuItem(common_local_url('bio',
array('nickname' => $nav->action->trimmed('nickname'))), _('Bio'),
_('The user\'s extended profile'), $nav->action->trimmed('action') == 'bio', 'nav_bio');
}
}

View File

@ -1,15 +1,14 @@
GNU Social Profile Extensions
GNU social Profile Extensions
=============================
Allows administrators to define additional profile fields for the
users of a GNU Social installation.
users of a GNU social installation.
Installation
------------
To install, copy this directory into your plugins directory and add
the following lines to your config.php file:
To enable, add the following lines to your config.php file:
addPlugin('GNUsocialProfileExtensions');
$config['admin']['panels'][] = 'profilefields';

View File

@ -1,104 +0,0 @@
<?php
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package GNU Social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2011 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
*/
if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/personalgroupnav.php';
require_once INSTALLDIR . '/classes/Profile.php';
require_once INSTALLDIR . '/lib/profilelist.php';
class BioAction extends Action
{
var $user = null;
function prepare(array $args = array())
{
parent::prepare($args);
$args = $this->returnToArgs();
$this->profile = Profile::getKV('nickname', $args[1]['nickname']);
//die(print_r($this->profile));
gnusocial_profile_merge($this->profile);
return true;
}
function handle()
{
parent::handle();
$this->showPage();
}
function title()
{
return sprintf(_m("%s's Bio."), $this->profile->nickname);
}
function showLocalNav()
{
$nav = new PersonalGroupNav($this);
$nav->show();
}
function showContent()
{
if(empty($this->profile)) {
return;
}
$profilelistitem = new ProfileListItem($this->profile, $this);
$profilelistitem->show();
$this->elementStart('ul');
$fields = GNUsocialProfileExtensionField::allFields();
foreach ($fields as $field) {
$fieldname = $field->systemname;
if (!empty($this->profile->$fieldname)) {
$this->elementStart('li', array('class' => 'biolistitem'));
$this->elementStart('div', array('class' => 'biolistitemcontainer'));
if ($field->type == 'text') {
$this->element('h3', array(), $field->title);
$this->element('p', array('class' => 'biovalue'), $this->profile->$fieldname);
}
else {
$this->element('span', array('class' => 'biotitle'), $field->title);
$this->text(' ');
$this->element('span', array('class' => 'biovalue'), $this->profile->$fieldname);
}
$this->elementEnd('div');
$this->elementEnd('li');
}
}
$this->elementEnd('ul');
}
}

View File

@ -1,53 +0,0 @@
<?php
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package GNU Social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2011 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
*/
require_once INSTALLDIR . '/actions/newnotice.php';
class NewresponseAction extends NewnoticeAction
{
/**
* Same as the parent, but not including the @-whoever in replies
*
* @return void
*/
function showNoticeForm()
{
$content = $this->trimmed('status_textarea');
if (!$content) {
$replyto = $this->trimmed('replyto');
$inreplyto = $this->trimmed('inreplyto');
} else {
// @fixme most of these bits above aren't being passed on above
$inreplyto = null;
}
$notice_form = new NoticeForm($this, '', $content, null, $inreplyto);
$notice_form->show();
}
}

View File

@ -1,175 +0,0 @@
<?php
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package GNU Social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2010 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
*/
if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/lib/adminpanelaction.php';
class ProfilefieldsAdminPanelAction extends AdminPanelAction
{
function title()
{
return _('Profile fields');
}
function getInstructions()
{
return _('GNU Social custom profile fields');
}
function showForm()
{
$form = new ProfilefieldsAdminForm($this);
$form->show();
return;
}
function saveSettings()
{
$field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
if (!$field)
$field = new GNUsocialProfileExtensionField();
$field->title = $this->trimmed('title');
$field->description = $this->trimmed('description');
$field->type = $this->trimmed('type');
$field->systemname = $this->trimmed('systemname');
if (!gnusocial_field_systemname_validate($field->systemname)) {
$this->clientError(_('Internal system name must be unique and consist of only alphanumeric characters!'));
}
if ($field->id) {
if ($field->validate())
$field->update();
else {
$this->clientError(_('There was an error with the field data.'));
}
}
else {
$field->insert();
}
return;
}
}
class ProfilefieldsAdminForm extends AdminForm
{
function id()
{
return 'form_profilefields_admin_panel';
}
function formClass()
{
return 'form_settings';
}
function action()
{
return '/admin/profilefields';
}
function formData()
{
$title = null;
$description = null;
$type = null;
$systemname = null;
$id = null;
$fieldsettitle = _("New Profile Field");
//Edit a field
if ($this->out->trimmed('edit')) {
$field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit'));
$title = $field->title;
$description = $field->description;
$type = $field->type;
$systemname = $field->systemname;
$this->out->hidden('id', $field->id, 'id');
$fieldsettitle = _("Edit Profile Field");
}
//Don't show the list of all fields when editing one
else {
$this->out->elementStart('fieldset');
$this->out->element('legend', null, _('Existing Custom Profile Fields'));
$this->out->elementStart('ul', 'form_data');
$fields = GNUsocialProfileExtensionField::allFields();
foreach ($fields as $field) {
$this->li();
$content =
$this->out->elementStart('div');
$this->out->element('a', array('href' => '/admin/profilefields?edit=' . $field->id),
$field->title);
$this->out->text(' (' . $field->type . '): ' . $field->description);
$this->out->elementEnd('div');
$this->unli();
}
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
}
//New fields
$this->out->elementStart('fieldset');
$this->out->element('legend', null, $fieldsettitle);
$this->out->elementStart('ul', 'form_data');
$this->li();
$this->out->input('title', _('Title'), $title,
_('The title of the field'));
$this->unli();
$this->li();
$this->out->input('systemname', _('Internal name'), $systemname,
_('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)'));
$this->unli();
$this->li();
$this->out->input('description', _('Description'), $description,
_('An optional more detailed description of the field'));
$this->unli();
$this->li();
$this->out->dropdown('type', _('Type'), array('text' => _("Text"),
'str' => _("String")),
_('The type of the datafield'), false, $type);
$this->unli();
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
$this->out->submit('submit', _('Save'), 'submit', null, _('Save new field'));
}
}

View File

@ -0,0 +1,183 @@
<?php
// 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/>.
/**
* Allows administrators to define additional profile fields for the users of a GNU social installation.
*
* @category Widget
* @package GNU social
* @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
*/
defined('GNUSOCIAL') || die();
class ProfilefieldsAdminPanelAction extends AdminPanelAction
{
public function title(): string
{
return _m('Profile fields');
}
public function getInstructions(): string
{
return _m('GNU Social custom profile fields');
}
public function showForm(): void
{
$form = new ProfilefieldsAdminForm($this);
$form->show();
}
public function saveSettings(): void
{
$field = GNUsocialProfileExtensionField::getKV('id', $this->trimmed('id'));
if (!$field) {
$field = new GNUsocialProfileExtensionField();
$field->systemname = $this->trimmed('systemname');
if (!gnusocial_field_systemname_validate($field->systemname)) {
$this->clientError(_m('Internal system name must be unique and consist of only alphanumeric characters!'));
}
}
$field->title = $this->trimmed('title');
$field->description = $this->trimmed('description');
$field->type = $this->trimmed('type');
if ($field->id) {
if ($field->validate()) {
$field->update();
} else {
$this->clientError(_m('There was an error with the field data.'));
}
} else {
$field->insert();
}
}
}
class ProfilefieldsAdminForm extends AdminForm
{
public function id(): string
{
return 'form_profilefields_admin_panel';
}
public function formClass(): string
{
return 'form_settings';
}
public function action(): string
{
return '/admin/profilefields';
}
public function formData(): void
{
$title = null;
$description = null;
$type = null;
$systemname = null;
$id = null;
$fieldsettitle = _m("New Profile Field");
// Edit a field
if ($this->out->trimmed('edit')) {
$field = GNUsocialProfileExtensionField::getKV('id', $this->out->trimmed('edit'));
$title = $field->title;
$description = $field->description;
$type = $field->type;
$systemname = $field->systemname;
$this->out->hidden('id', $field->id, 'id');
$fieldsettitle = _m("Edit Profile Field");
} // Don't show the list of all fields when editing one
else {
$this->out->elementStart('fieldset');
$this->out->element('legend', null, _m('Existing Custom Profile Fields'));
$this->out->elementStart('ul', 'form_data');
$fields = GNUsocialProfileExtensionField::allFields();
foreach ($fields as $field) {
$this->li();
$this->out->elementStart('div');
$this->out->element(
'a',
array('href' => '/admin/profilefields?edit=' . $field->id),
$field->title
);
$this->out->text(' (' . $field->type . '): ' . $field->description);
$this->out->elementEnd('div');
$this->unli();
}
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
}
// New fields
$this->out->elementStart('fieldset');
$this->out->element('legend', null, $fieldsettitle);
$this->out->elementStart('ul', 'form_data');
$this->li();
$this->out->input(
'title',
_m('Title'),
$title,
_m('The title of the field')
);
$this->unli();
$this->li();
$this->out->input(
'systemname',
_m('Internal name'),
$systemname,
_m('The alphanumeric name used internally for this field. Also the key used in OStatus user info. (optional)')
);
$this->unli();
$this->li();
$this->out->input(
'description',
_m('Description'),
$description,
_m('An optional more detailed description of the field')
);
$this->unli();
$this->li();
$this->out->dropdown(
'type',
_m('Type'),
array('text' => _m("Text"),
'str' => _m("String")),
_m('The type of the datafield'),
false,
$type
);
$this->unli();
$this->out->elementEnd('ul');
$this->out->elementEnd('fieldset');
}
/**
* Action elements
*
* @return void
* @throws Exception
*/
public function formActions(): void
{
$this->out->submit('submit', _m('Save'), 'submit', null, _m('Save new field'));
}
}

View File

@ -1,36 +1,31 @@
<?php
// 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/>.
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* Allows administrators to define additional profile fields for the users of a GNU social installation.
*
* @category Widget
* @package GNU Social
* @package GNU social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2010 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @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
*/
if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
defined('GNUSOCIAL') || die();
class GNUsocialProfileExtensionField extends Managed_DataObject
{
@ -40,53 +35,54 @@ class GNUsocialProfileExtensionField extends Managed_DataObject
public $title; // varchar(191) not 255 because utf8mb4 takes more space
public $description; // text
public $type; // varchar(191) not 255 because utf8mb4 takes more space
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public static function schemaDef()
public static function schemaDef(): array
{
return array(
'fields' => array(
'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension field'),
'systemname' => array('type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'field systemname'),
'title' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'field title'),
'description' => array('type' => 'text', 'not null' => true, 'description' => 'field description'),
'type' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'field type'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
'primary key' => array('id'),
'indexes' => array(
'gnusocialprofileextensionfield_title_idx' => array('title'),
),
);
return [
'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension field'],
'systemname' => ['type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'field systemname'],
'title' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'field title'],
'description' => ['type' => 'text', 'not null' => true, 'description' => 'field description'],
'type' => ['type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'field type'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'],
'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['id'],
'indexes' => [
'gnusocialprofileextensionfield_title_idx' => ['title'],
],
];
}
static function newField($title, $description=null, $type='str', $systemname=null)
public static function newField($title, $description = null, $type = 'str', $system_name = null): GNUsocialProfileExtensionField
{
$field = new GNUsocialProfileExtensionField();
$field->title = $title;
$field->description = $description;
$field->type = $type;
if (empty($systemname))
$field->systemname = 'field' + $field->id;
else
$field->systemname = $systemname;
if (empty($system_name)) {
$field->systemname = 'field' . $field->id;
} else {
$field->systemname = $system_name;
}
$field->id = $field->insert();
if (!$field->id){
if (!$field->id) {
common_log_db_error($field, 'INSERT', __FILE__);
throw new ServerException(_m('Error creating new field.'));
}
return $field;
}
static function allFields()
public static function allFields(): array
{
$field = new GNUsocialProfileExtensionField();
$fields = array();
$fields = [];
if ($field->find()) {
while($field->fetch()) {
while ($field->fetch()) {
$fields[] = clone($field);
}
}

View File

@ -1,36 +1,31 @@
<?php
// 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/>.
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* Allows administrators to define additional profile fields for the users of a GNU social installation.
*
* @category Widget
* @package GNU Social
* @package GNU social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2010 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @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
*/
if (!defined('STATUSNET')) {
exit(1);
}
require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
defined('GNUSOCIAL') || die();
class GNUsocialProfileExtensionResponse extends Managed_DataObject
{
@ -38,56 +33,56 @@ class GNUsocialProfileExtensionResponse extends Managed_DataObject
public $id; // int(11)
public $extension_id; // int(11)
public $profile_id; // int(11)
public $value; // text
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
public $value; // text
public $created; // datetime() not_null default_0000-00-00%2000%3A00%3A00
public $modified; // datetime() not_null default_CURRENT_TIMESTAMP
public static function schemaDef()
public static function schemaDef(): array
{
return array(
'fields' => array(
'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension response'),
'extension_id' => array('type' => 'int', 'not null' => true, 'description' => 'The extension field ID'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile id that made the response'),
'value' => array('type' => 'text', 'not null' => true, 'description' => 'response entry'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
),
'primary key' => array('id'),
'foreign keys' => array(
'gnusocialprofileextensionresponse_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'gnusocialprofileextensionresponse_extension_id_fkey' => array('gnusocialprofileextensionfield', array('extension_id' => 'id')),
),
'indexes' => array(
'gnusocialprofileextensionresponse_extension_id_idx' => array('extension_id'),
),
);
return [
'fields' => [
'id' => ['type' => 'serial', 'not null' => true, 'description' => 'Unique ID for extension response'],
'extension_id' => ['type' => 'int', 'not null' => true, 'description' => 'The extension field ID'],
'profile_id' => ['type' => 'int', 'not null' => true, 'description' => 'Profile id that made the response'],
'value' => ['type' => 'text', 'not null' => true, 'description' => 'response entry'],
'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'],
'modified' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
],
'primary key' => ['id'],
// Syntax: foreign_key_name => [remote_table, local_key => remote_key]]
'foreign keys' => [
'gnusocialprofileextensionresponse_profile_id_fkey' => ['profile', ['profile_id' => 'id']],
'gnusocialprofileextensionresponse_extension_id_fkey' => ['gnusocialprofileextensionfield', ['extension_id' => 'id']],
],
'indexes' => [
'gnusocialprofileextensionresponse_extension_id_idx' => ['extension_id'],
],
];
}
static function newResponse($extension_id, $profile_id, $value)
public static function newResponse($extension_id, $profile_id, $value): GNUsocialProfileExtensionResponse
{
$response = new GNUsocialProfileExtensionResponse();
$response->extension_id = $extension_id;
$response->profile_id = $profile_id;
$response->value = $value;
$response->id = $response->insert();
if (!$response->id){
if (!$response->id) {
common_log_db_error($response, 'INSERT', __FILE__);
throw new ServerException(_m('Error creating new response.'));
}
return $response;
}
static function findResponsesByProfile($id)
public static function findResponsesByProfile($id): array
{
$extf = 'gnusocialprofileextensionfield';
$extr = 'gnusocialprofileextensionresponse';
$sql = "SELECT $extr.*, $extf.title, $extf.description, $extf.type, $extf.systemname FROM $extr JOIN $extf ON $extr.extension_id=$extf.id WHERE $extr.profile_id = $id";
$response = new GNUsocialProfileExtensionResponse();
$response->query($sql);
$responses = array();
$responses = [];
while ($response->fetch()) {
$responses[] = clone($response);
@ -95,5 +90,4 @@ class GNUsocialProfileExtensionResponse extends Managed_DataObject
return $responses;
}
}

View File

@ -1,223 +0,0 @@
<?php
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Widget
* @package GNU Social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2011 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
*/
//functions to sort replies
class NoticeTree extends NoticeList
{
function show()
{
$this->out->elementStart('div', array('id' =>'notices_primary'));
// TRANS: Header on conversation page. Hidden by default (h2).
$this->out->element('h2', null, _('Notices'));
$this->out->elementStart('ol', array('class' => 'notices xoxo'));
$cnt = 0;
while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
if (!empty($this->notice->reply_to))
continue;
$cnt++;
if ($cnt > NOTICES_PER_PAGE) {
break;
}
try {
$this->showNoticePlus($this->newListItem($this->notice));
} catch (Exception $e) {
// we log exceptions and continue
print "ERROR!" . $e->getMessage();
common_log(LOG_ERR, $e->getMessage());
continue;
}
}
$this->out->elementEnd('ol');
$this->out->elementEnd('div');
return $cnt;
}
function _cmpDate($a, $b) { return strcmp($a->notice->modified, $b->notice->modified); }
function _cmpFav($a, $b) { return (int)$a->faves < (int)$b->faves; }
function showNoticePlus($item)
{
$replies = new Notice();
$replies->reply_to = $item->notice->id;
// We take responsibility for doing the li
$this->out->elementStart('li', array('class' => 'h-entry notice',
'id' => 'notice-' . $item->notice->id));
$item->show();
if ($replies->find()) {
$this->out->elementStart('ol', array('class' => 'notices'));
$replieslist = array();
while ($replies->fetch()) {
$replieslist[] = $this->newListItem(clone($replies));
}
//Sorting based on url argument
if($_GET['sort'] == 'faves')
usort($replieslist, array($this, '_cmpFav'));
else
usort($replieslist, array($this, '_cmpDate'));
foreach($replieslist as $reply) {
$this->showNoticePlus($reply);
}
$this->out->elementEnd('ol');
}
$this->out->elementEnd('li');
}
function newListItem($notice)
{
return new NoticeTreeItem($notice, $this->out);
}
}
class NoticeTreeItem extends NoticeListItem
{
function __construct($notice, $out=null)
{
parent::__construct($notice, $out);
//TODO: Rewrite this
//Showing number of favorites
$fave = new Fave();
$fave->notice_id = $this->notice->id;
$cnt = 0;
if ($fave->find()) {
while ($fave->fetch())
$cnt++;
}
$this->faves = $cnt;
}
function showStart()
{
return;
}
function showEnd()
{
if ($this->faves > 0) {
$this->out->text(_m("Favorited by $this->faves user"));
if ($this->faves > 1) $this->out->text("s"); //there has to be a better way to do this...
}
//Show response form
$this->out->elementStart('div', array('id' => 'form' . $this->notice->id, 'class' => 'replyform'));
$noticeform = new ReplyForm($this->out, null, null, null, $this->notice->id);
$noticeform->show();
$this->out->elementEnd('div');
return;
}
//Just changing the link...
function showReplyLink()
{
if (common_logged_in()) {
$this->out->text(' ');
//Why doesn't common_local_url work here?
$reply_url = '/notice/respond?replyto=' . $this->profile->nickname . '&inreplyto=' . $this->notice->id;
$this->out->elementStart('a', array('href' => $reply_url,
'class' => 'notice_reply',
'title' => _('Reply to this notice')));
$this->out->text(_('Reply'));
$this->out->text(' ');
$this->out->element('span', 'notice_id', $this->notice->id);
$this->out->elementEnd('a');
}
}
}
class ReplyForm extends NoticeForm
{
//Changing the text. We have to either repeat ids or get hacky. I vote repeat ids.
function formData()
{
if (Event::handle('StartShowNoticeFormData', array($this))) {
// XXX: vary by defined max size
$this->out->element('textarea', array('id' => 'notice_data-text',
'cols' => 35,
'rows' => 4,
'name' => 'status_textarea'),
($this->content) ? $this->content : '');
$contentLimit = Notice::maxContent();
if ($contentLimit > 0) {
$this->out->elementStart('dl', 'form_note');
$this->out->element('dt', null, _('Available characters'));
$this->out->element('dd', array('id' => 'notice_text-count'),
$contentLimit);
$this->out->elementEnd('dl');
}
if (common_config('attachments', 'uploads')) {
$this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
$this->out->element('input', array('id' => 'notice_data-attach',
'type' => 'file',
'name' => 'attach',
'title' => _('Attach a file')));
$this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
}
if ($this->action) {
$this->out->hidden('notice_return-to', $this->action, 'returnto');
}
$this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
if ($this->profile->shareLocation()) {
$this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
$this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
$this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id');
$this->out->hidden('notice_data-location_ns', empty($this->location_ns) ? (empty($this->profile->location_ns) ? null : $this->profile->location_ns) : $this->location_ns, 'location_ns');
$this->out->elementStart('div', array('id' => 'notice_data-geo_wrap',
'title' => common_local_url('geocode')));
$this->out->checkbox('notice_data-geo', _('Share my location'), true);
$this->out->elementEnd('div');
$this->out->inlineScript(' var NoticeDataGeo_text = {'.
'ShareDisable: ' .json_encode(_('Do not share my location')).','.
'ErrorTimeout: ' .json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')).
'}');
}
Event::handle('EndShowNoticeFormData', array($this));
}
}
}

View File

@ -1,47 +1,52 @@
<?php
// 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/>.
/**
* GNU Social
* Copyright (C) 2010, Free Software Foundation, Inc.
*
* PHP version 5
*
* LICENCE:
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* Allows administrators to define additional profile fields for the users of a GNU social installation.
*
* @category Widget
* @package GNU Social
* @package GNU social
* @author Max Shinn <trombonechamp@gmail.com>
* @copyright 2010 Free Software Foundation, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @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
*/
defined('GNUSOCIAL') || die();
function gnusocial_profile_merge(&$profile)
{
$responses = GNUsocialProfileExtensionResponse::findResponsesByProfile($profile->id);
$profile->customfields = array();
$profile->customfields = [];
foreach ($responses as $response) {
$title = $response->systemname;
$profile->$title = $response->value;
$profile->customfields[] = $title;
}
}
function gnusocial_field_systemname_validate($systemname)
{
// Ensure it doesn't exist already
$fields = GNUsocialProfileExtensionField::allFields();
foreach ($fields as $field)
if ($field->systemname == $systemname)
foreach ($fields as $field) {
if ($field->systemname == $systemname) {
return false;
return ctype_alphanum($systemname);
}
}
}
// Ensure that it consist of only alphanumeric characters
return ctype_alnum($systemname);
}

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-14 14:51+0100\n"
"POT-Creation-Date: 2019-08-14 14:54+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -25,15 +25,90 @@ msgstr ""
msgid "Custom profile fields"
msgstr ""
#: actions/bio.php:62
#, php-format
msgid "%s's Bio."
#: actions/profilefieldsadminpanel.php:34
msgid "Profile fields"
msgstr ""
#: classes/GNUsocialProfileExtensionField.php:79
#: actions/profilefieldsadminpanel.php:39
msgid "GNU Social custom profile fields"
msgstr ""
#: actions/profilefieldsadminpanel.php:55
msgid ""
"Internal system name must be unique and consist of only alphanumeric "
"characters!"
msgstr ""
#: actions/profilefieldsadminpanel.php:65
msgid "There was an error with the field data."
msgstr ""
#: actions/profilefieldsadminpanel.php:97
msgid "New Profile Field"
msgstr ""
#: actions/profilefieldsadminpanel.php:106
msgid "Edit Profile Field"
msgstr ""
#: actions/profilefieldsadminpanel.php:110
msgid "Existing Custom Profile Fields"
msgstr ""
#: actions/profilefieldsadminpanel.php:137
msgid "Title"
msgstr ""
#: actions/profilefieldsadminpanel.php:139
msgid "The title of the field"
msgstr ""
#: actions/profilefieldsadminpanel.php:145
msgid "Internal name"
msgstr ""
#: actions/profilefieldsadminpanel.php:147
msgid ""
"The alphanumeric name used internally for this field. Also the key used in "
"OStatus user info. (optional)"
msgstr ""
#: actions/profilefieldsadminpanel.php:153
msgid "Description"
msgstr ""
#: actions/profilefieldsadminpanel.php:155
msgid "An optional more detailed description of the field"
msgstr ""
#: actions/profilefieldsadminpanel.php:161
msgid "Type"
msgstr ""
#: actions/profilefieldsadminpanel.php:162
msgid "Text"
msgstr ""
#: actions/profilefieldsadminpanel.php:163
msgid "String"
msgstr ""
#: actions/profilefieldsadminpanel.php:164
msgid "The type of the datafield"
msgstr ""
#: actions/profilefieldsadminpanel.php:181
msgid "Save"
msgstr ""
#: actions/profilefieldsadminpanel.php:181
msgid "Save new field"
msgstr ""
#: classes/GNUsocialProfileExtensionField.php:75
msgid "Error creating new field."
msgstr ""
#: classes/GNUsocialProfileExtensionResponse.php:78
#: classes/GNUsocialProfileExtensionResponse.php:73
msgid "Error creating new response."
msgstr ""