Merge pull request #7381 from MrPetovan/task/7309-frio-compose

[frio] New Compose page
This commit is contained in:
Michael Vogel 2019-08-01 08:15:02 +02:00 committed by GitHub
commit e8459cce34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 1730 additions and 184 deletions

View file

@ -94,6 +94,7 @@ class Router
$this->routeCollector->addRoute(['GET'], '/attach/{item:\d+}', Module\Attach::class);
$this->routeCollector->addRoute(['GET'], '/babel', Module\Debug\Babel::class);
$this->routeCollector->addRoute(['GET'], '/bookmarklet', Module\Bookmarklet::class);
$this->routeCollector->addRoute(['GET', 'POST'], '/compose[/{type}]', Module\Item\Compose::class);
$this->routeCollector->addGroup('/contact', function (RouteCollector $collector) {
$collector->addRoute(['GET'], '[/]', Module\Contact::class);
$collector->addRoute(['GET', 'POST'], '/{id:\d+}[/]', Module\Contact::class);

View file

@ -25,6 +25,8 @@ class Protocol
const FEDERATED = [self::DFRN, self::DIASPORA, self::OSTATUS, self::ACTIVITYPUB];
const SUPPORT_PRIVATE = [self::DFRN, self::DIASPORA, self::MAIL, self::ACTIVITYPUB, self::PUMPIO];
// Supported through a connector
const DIASPORA2 = 'dspc'; // Diaspora connector
const LINKEDIN = 'lnkd'; // LinkedIn

View file

@ -2,12 +2,14 @@
/**
* @file src/Model/Group.php
*/
namespace Friendica\Model;
use Friendica\BaseModule;
use Friendica\BaseObject;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
@ -16,9 +18,21 @@ use Friendica\Database\DBA;
*/
class Group extends BaseObject
{
const FOLLOWERS = '~';
const MUTUALS = '&';
public static function getByUserId($uid, $includesDeleted = false)
{
$conditions = ['uid' => $uid];
if (!$includesDeleted) {
$conditions['deleted'] = false;
}
return DBA::selectToArray('group', [], $conditions);
}
/**
*
*
* @param int $group_id
* @return bool
* @throws \Exception
@ -76,8 +90,8 @@ class Group extends BaseObject
/**
* Update group information.
*
* @param int $id Group ID
* @param string $name Group name
* @param int $id Group ID
* @param string $name Group name
*
* @return bool Was the update successful?
* @throws \Exception
@ -96,14 +110,13 @@ class Group extends BaseObject
*/
public static function getIdsByContactId($cid)
{
$condition = ['contact-id' => $cid];
$stmt = DBA::select('group_member', ['gid'], $condition);
$return = [];
$stmt = DBA::select('group_member', ['gid'], ['contact-id' => $cid]);
while ($group = DBA::fetch($stmt)) {
$return[] = $group['gid'];
}
DBA::close($stmt);
return $return;
}
@ -170,8 +183,9 @@ class Group extends BaseObject
* @return boolean
* @throws \Exception
*/
public static function remove($gid) {
if (! $gid) {
public static function remove($gid)
{
if (!$gid) {
return false;
}
@ -215,14 +229,15 @@ class Group extends BaseObject
/**
* @brief Mark a group as deleted based on its name
*
* @deprecated Use Group::remove instead
*
* @param int $uid
* @param string $name
* @return bool
* @throws \Exception
* @deprecated Use Group::remove instead
*
*/
public static function removeByName($uid, $name) {
public static function removeByName($uid, $name)
{
$return = false;
if (!empty($uid) && !empty($name)) {
$gid = self::getIdByName($uid, $name);
@ -280,13 +295,13 @@ class Group extends BaseObject
/**
* @brief Removes a contact from a group based on its name
*
* @deprecated Use Group::removeMember instead
*
* @param int $uid
* @param string $name
* @param int $cid
* @return boolean
* @throws \Exception
* @deprecated Use Group::removeMember instead
*
*/
public static function removeMemberByName($uid, $name, $cid)
{
@ -300,23 +315,55 @@ class Group extends BaseObject
/**
* @brief Returns the combined list of contact ids from a group id list
*
* @param int $uid
* @param array $group_ids
* @param boolean $check_dead
* @return array
* @throws \Exception
*/
public static function expand($group_ids, $check_dead = false)
public static function expand($uid, array $group_ids, $check_dead = false)
{
if (!is_array($group_ids) || !count($group_ids)) {
return [];
}
$stmt = DBA::select('group_member', ['contact-id'], ['gid' => $group_ids]);
$return = [];
while($group_member = DBA::fetch($stmt)) {
$key = array_search(self::FOLLOWERS, $group_ids);
if ($key !== false) {
$followers = Contact::selectToArray(['id'], [
'uid' => $uid,
'rel' => [Contact::FOLLOWER, Contact::FRIEND],
'protocol' => Protocol::SUPPORT_PRIVATE,
]);
foreach ($followers as $follower) {
$return[] = $follower['id'];
}
unset($group_ids[$key]);
}
$key = array_search(self::MUTUALS, $group_ids);
if ($key !== false) {
$mutuals = Contact::selectToArray(['id'], [
'uid' => $uid,
'rel' => [Contact::FRIEND],
'protocol' => Protocol::SUPPORT_PRIVATE,
]);
foreach ($mutuals as $mutual) {
$return[] = $mutual['id'];
}
unset($group_ids[$key]);
}
$stmt = DBA::select('group_member', ['contact-id'], ['gid' => $group_ids]);
while ($group_member = DBA::fetch($stmt)) {
$return[] = $group_member['contact-id'];
}
DBA::close($stmt);
if ($check_dead) {
Contact::pruneUnavailable($return);
@ -332,12 +379,10 @@ class Group extends BaseObject
* @param int $gid An optional pre-selected group
* @param string $label An optional label of the list
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \Exception
*/
public static function displayGroupSelection($uid, $gid = 0, $label = '')
{
$stmt = DBA::select('group', [], ['deleted' => 0, 'uid' => $uid], ['order' => ['name']]);
$display_groups = [
[
'name' => '',
@ -345,6 +390,8 @@ class Group extends BaseObject
'selected' => ''
]
];
$stmt = DBA::select('group', [], ['deleted' => 0, 'uid' => $uid], ['order' => ['name']]);
while ($group = DBA::fetch($stmt)) {
$display_groups[] = [
'name' => $group['name'],
@ -352,7 +399,9 @@ class Group extends BaseObject
'selected' => $gid == $group['id'] ? 'true' : ''
];
}
Logger::log('groups: ' . print_r($display_groups, true));
DBA::close($stmt);
Logger::info('Got groups', $display_groups);
if ($label == '') {
$label = L10n::t('Default privacy group for new contacts');
@ -377,7 +426,7 @@ class Group extends BaseObject
* @param string $group_id
* @param int $cid
* @return string
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \Exception
*/
public static function sidebarWidget($every = 'contact', $each = 'group', $editmode = 'standard', $group_id = '', $cid = 0)
{
@ -394,13 +443,12 @@ class Group extends BaseObject
]
];
$stmt = DBA::select('group', [], ['deleted' => 0, 'uid' => local_user()], ['order' => ['name']]);
$member_of = [];
if ($cid) {
$member_of = self::getIdsByContactId($cid);
}
$stmt = DBA::select('group', [], ['deleted' => 0, 'uid' => local_user()], ['order' => ['name']]);
while ($group = DBA::fetch($stmt)) {
$selected = (($group_id == $group['id']) ? ' group-selected' : '');
@ -423,6 +471,7 @@ class Group extends BaseObject
'ismember' => in_array($group['id'], $member_of),
];
}
DBA::close($stmt);
// Don't show the groups on the network page when there is only one
if ((count($display_groups) <= 2) && ($each == 'network')) {
@ -445,7 +494,6 @@ class Group extends BaseObject
'$form_security_token' => BaseModule::getFormSecurityToken('group_edit'),
]);
return $o;
}
}

View file

@ -2802,7 +2802,7 @@ class Item extends BaseObject
$replace = true;
}
} elseif ($item) {
if (self::samePermissions($item, $photo)) {
if (self::samePermissions($uid, $item, $photo)) {
$replace = true;
}
}
@ -2852,7 +2852,7 @@ class Item extends BaseObject
!empty($obj['deny_cid']) || !empty($obj['deny_gid']);
}
private static function samePermissions($obj1, $obj2)
private static function samePermissions($uid, $obj1, $obj2)
{
// first part is easy. Check that these are exactly the same.
if (($obj1['allow_cid'] == $obj2['allow_cid'])
@ -2873,12 +2873,12 @@ class Item extends BaseObject
}
// returns an array of contact-ids that are allowed to see this object
public static function enumeratePermissions($obj)
public static function enumeratePermissions(array $obj)
{
$allow_people = expand_acl($obj['allow_cid']);
$allow_groups = Group::expand(expand_acl($obj['allow_gid']));
$allow_groups = Group::expand($obj['uid'], expand_acl($obj['allow_gid']));
$deny_people = expand_acl($obj['deny_cid']);
$deny_groups = Group::expand(expand_acl($obj['deny_gid']));
$deny_groups = Group::expand($obj['uid'], expand_acl($obj['deny_gid']));
$recipients = array_unique(array_merge($allow_people, $allow_groups));
$deny = array_unique(array_merge($deny_people, $deny_groups));
$recipients = array_diff($recipients, $deny);

217
src/Module/Item/Compose.php Normal file
View file

@ -0,0 +1,217 @@
<?php
namespace Friendica\Module\Item;
use Friendica\BaseModule;
use Friendica\Content\Feature;
use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\FileTag;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Module\Login;
use Friendica\Network\HTTPException\NotImplementedException;
use Friendica\Util\Crypto;
class Compose extends BaseModule
{
public static function post()
{
if (!empty($_REQUEST['body'])) {
$_REQUEST['return'] = 'network';
require_once 'mod/item.php';
item_post(self::getApp());
} else {
notice(L10n::t('Please enter a post body.'));
}
}
public static function content()
{
if (!local_user()) {
return Login::form('compose', false);
}
$a = self::getApp();
if ($a->getCurrentTheme() !== 'frio') {
throw new NotImplementedException(L10n::t('This feature is only available with the frio theme.'));
}
/// @TODO Retrieve parameter from router
$posttype = $a->argv[1] ?? Item::PT_ARTICLE;
if (!in_array($posttype, [Item::PT_ARTICLE, Item::PT_PERSONAL_NOTE])) {
switch ($posttype) {
case 'note':
$posttype = Item::PT_PERSONAL_NOTE;
break;
default:
$posttype = Item::PT_ARTICLE;
break;
}
}
$user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
switch ($posttype) {
case Item::PT_PERSONAL_NOTE:
$compose_title = L10n::t('Compose new personal note');
$type = 'note';
$doesFederate = false;
$contact_allow = $a->contact['id'];
$group_allow = '';
break;
default:
$compose_title = L10n::t('Compose new post');
$type = 'post';
$doesFederate = true;
$contact_allow = implode(',', expand_acl($user['allow_cid']));
$group_allow = implode(',', expand_acl($user['allow_gid'])) ?: Group::FOLLOWERS;
break;
}
$title = $_REQUEST['title'] ?? '';
$category = $_REQUEST['category'] ?? '';
$body = $_REQUEST['body'] ?? '';
$location = $_REQUEST['location'] ?? $user['default-location'];
$wall = $_REQUEST['wall'] ?? $type == 'post';
$contact_allow = $_REQUEST['contact_allow'] ?? $contact_allow;
$group_allow = $_REQUEST['group_allow'] ?? $group_allow;
$contact_deny = $_REQUEST['contact_deny'] ?? implode(',', expand_acl($user['deny_cid']));
$group_deny = $_REQUEST['group_deny'] ?? implode(',', expand_acl($user['deny_gid']));
$visibility = ($contact_allow . $user['allow_gid'] . $user['deny_cid'] . $user['deny_gid']) ? 'custom' : 'public';
$acl_contacts = Contact::selectToArray(['id', 'name', 'addr', 'micro'], ['uid' => local_user(), 'pending' => false, 'rel' => [Contact::FOLLOWER, Contact::FRIEND]]);
array_walk($acl_contacts, function (&$value) {
$value['type'] = 'contact';
});
$acl_groups = [
[
'id' => Group::FOLLOWERS,
'name' => L10n::t('Followers'),
'addr' => '',
'micro' => 'images/twopeople.png',
'type' => 'group',
],
[
'id' => Group::MUTUALS,
'name' => L10n::t('Mutuals'),
'addr' => '',
'micro' => 'images/twopeople.png',
'type' => 'group',
]
];
foreach (Group::getByUserId(local_user()) as $group) {
$acl_groups[] = [
'id' => $group['id'],
'name' => $group['name'],
'addr' => '',
'micro' => 'images/twopeople.png',
'type' => 'group',
];
}
$acl = array_merge($acl_groups, $acl_contacts);
$jotnets_fields = [];
$mail_enabled = false;
$pubmail_enabled = false;
if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) {
$mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', local_user()]);
if (DBA::isResult($mailacct)) {
$mail_enabled = true;
$pubmail_enabled = !empty($mailacct['pubmail']);
}
}
if (empty($user['hidewall'])) {
if ($mail_enabled) {
$jotnets_fields[] = [
'type' => 'checkbox',
'field' => [
'pubmail_enable',
L10n::t('Post to Email'),
$pubmail_enabled
]
];
}
Hook::callAll('jot_networks', $jotnets_fields);
}
$jotplugins = '';
Hook::callAll('jot_tool', $jotplugins);
// Output
$a->registerFooterScript('view/js/ajaxupload.js');
$a->registerFooterScript('view/js/linkPreview.js');
$a->registerFooterScript('view/asset/typeahead.js/dist/typeahead.bundle.js');
$a->registerFooterScript('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.js');
$a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput.css');
$a->registerStylesheet('view/theme/frio/frameworks/friendica-tagsinput/friendica-tagsinput-typeahead.css');
$tpl = Renderer::getMarkupTemplate('item/compose-footer.tpl');
$a->page['footer'] .= Renderer::replaceMacros($tpl, [
'$acl_contacts' => $acl_contacts,
'$acl_groups' => $acl_groups,
'$acl' => $acl,
]);
$tpl = Renderer::getMarkupTemplate('item/compose.tpl');
return Renderer::replaceMacros($tpl, [
'$compose_title'=> $compose_title,
'$id' => 0,
'$posttype' => $posttype,
'$type' => $type,
'$wall' => $wall,
'$default' => L10n::t(''),
'$mylink' => $a->removeBaseURL($a->contact['url']),
'$mytitle' => L10n::t('This is you'),
'$myphoto' => $a->removeBaseURL($a->contact['thumb']),
'$submit' => L10n::t('Submit'),
'$edbold' => L10n::t('Bold'),
'$editalic' => L10n::t('Italic'),
'$eduline' => L10n::t('Underline'),
'$edquote' => L10n::t('Quote'),
'$edcode' => L10n::t('Code'),
'$edimg' => L10n::t('Image'),
'$edurl' => L10n::t('Link'),
'$edattach' => L10n::t('Link or Media'),
'$prompttext' => L10n::t('Please enter a image/video/audio/webpage URL:'),
'$preview' => L10n::t('Preview'),
'$location_set' => L10n::t('Set your location'),
'$location_clear' => L10n::t('Clear the location'),
'$location_unavailable' => L10n::t('Location services are unavailable on your device'),
'$location_disabled' => L10n::t('Location services are disabled. Please check the website\'s permissions on your device'),
'$wait' => L10n::t('Please wait'),
'$placeholdertitle' => L10n::t('Set title'),
'$placeholdercategory' => (Feature::isEnabled(local_user(),'categories') ? L10n::t('Categories (comma-separated list)') : ''),
'$public_title' => L10n::t('Public'),
'$public_desc' => L10n::t('This post will be sent to all your followers and can be seen in the community pages and by anyone with its link.'),
'$custom_title' => L10n::t('Limited/Private'),
'$custom_desc' => L10n::t('This post will be sent only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.'),
'$emailcc' => L10n::t('CC: email addresses'),
'$title' => $title,
'$category' => $category,
'$body' => $body,
'$location' => $location,
'$visibility' => $visibility,
'$contact_allow'=> $contact_allow,
'$group_allow' => $group_allow,
'$contact_deny' => $contact_deny,
'$group_deny' => $group_deny,
'$jotplugins' => $jotplugins,
'$doesFederate' => $doesFederate,
'$jotnets_fields'=> $jotnets_fields,
'$sourceapp' => L10n::t($a->sourcename),
'$rand_num' => Crypto::randomDigits(12)
]);
}
}

View file

@ -271,9 +271,9 @@ class Notifier
}
$allow_people = expand_acl($parent['allow_cid']);
$allow_groups = Group::expand(expand_acl($parent['allow_gid']),true);
$allow_groups = Group::expand($uid, expand_acl($parent['allow_gid']),true);
$deny_people = expand_acl($parent['deny_cid']);
$deny_groups = Group::expand(expand_acl($parent['deny_gid']));
$deny_groups = Group::expand($uid, expand_acl($parent['deny_gid']));
// if our parent is a public forum (forum_mode == 1), uplink to the origional author causing
// a delivery fork. private groups (forum_mode == 2) do not uplink