Merge remote-tracking branch 'upstream/develop' into issue-3229
This commit is contained in:
@@ -54,7 +54,7 @@ class BaseObject
|
||||
*
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
protected static function getClass(string $name)
|
||||
public static function getClass(string $name)
|
||||
{
|
||||
if (empty(self::$dice)) {
|
||||
throw new InternalServerErrorException('DICE isn\'t initialized.');
|
||||
|
||||
79
src/Content/Item.php
Normal file
79
src/Content/Item.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Content;
|
||||
|
||||
use Friendica\Model\FileTag;
|
||||
|
||||
/**
|
||||
* A content helper class for displaying items
|
||||
*/
|
||||
final class Item
|
||||
{
|
||||
/**
|
||||
* Return array with details for categories and folders for an item
|
||||
*
|
||||
* @param array $item
|
||||
* @return [array, array]
|
||||
*
|
||||
* [
|
||||
* [ // categories array
|
||||
* {
|
||||
* 'name': 'category name',
|
||||
* 'removeurl': 'url to remove this category',
|
||||
* 'first': 'is the first in this array? true/false',
|
||||
* 'last': 'is the last in this array? true/false',
|
||||
* } ,
|
||||
* ....
|
||||
* ],
|
||||
* [ //folders array
|
||||
* {
|
||||
* 'name': 'folder name',
|
||||
* 'removeurl': 'url to remove this folder',
|
||||
* 'first': 'is the first in this array? true/false',
|
||||
* 'last': 'is the last in this array? true/false',
|
||||
* } ,
|
||||
* ....
|
||||
* ]
|
||||
* ]
|
||||
*/
|
||||
public function determineCategoriesTerms(array $item)
|
||||
{
|
||||
$categories = [];
|
||||
$folders = [];
|
||||
$first = true;
|
||||
|
||||
foreach (FileTag::fileToArray($item['file'] ?? '', 'category') as $savedFolderName) {
|
||||
$categories[] = [
|
||||
'name' => $savedFolderName,
|
||||
'url' => "#",
|
||||
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&cat=' . rawurlencode($savedFolderName) : ""),
|
||||
'first' => $first,
|
||||
'last' => false
|
||||
];
|
||||
$first = false;
|
||||
}
|
||||
|
||||
if (count($categories)) {
|
||||
$categories[count($categories) - 1]['last'] = true;
|
||||
}
|
||||
|
||||
if (local_user() == $item['uid']) {
|
||||
foreach (FileTag::fileToArray($item['file'] ?? '') as $savedFolderName) {
|
||||
$folders[] = [
|
||||
'name' => $savedFolderName,
|
||||
'url' => "#",
|
||||
'removeurl' => ((local_user() == $item['uid']) ? 'filerm/' . $item['id'] . '?f=&term=' . rawurlencode($savedFolderName) : ""),
|
||||
'first' => $first,
|
||||
'last' => false
|
||||
];
|
||||
$first = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($folders)) {
|
||||
$folders[count($folders) - 1]['last'] = true;
|
||||
}
|
||||
|
||||
return [$categories, $folders];
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ use Friendica\Model\Event;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\Map;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\ParseUrl;
|
||||
@@ -276,7 +277,7 @@ class BBCode extends BaseObject
|
||||
|
||||
if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
|
||||
if ((count($pictures) == 1) && !$has_title) {
|
||||
if (!empty($item['object-type']) && ($item['object-type'] == ACTIVITY_OBJ_IMAGE)) {
|
||||
if (!empty($item['object-type']) && ($item['object-type'] == Activity\ObjectType::IMAGE)) {
|
||||
// Replace the preview picture with the real picture
|
||||
$url = str_replace('-1.', '-0.', $pictures[0][2]);
|
||||
$data = ['url' => $url, 'type' => 'photo'];
|
||||
@@ -572,17 +573,17 @@ class BBCode extends BaseObject
|
||||
* Note: Can produce a [bookmark] tag in the returned string
|
||||
*
|
||||
* @brief Processes [attachment] tags
|
||||
* @param string $return
|
||||
* @param string $text
|
||||
* @param bool|int $simplehtml
|
||||
* @param bool $tryoembed
|
||||
* @return string
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function convertAttachment($return, $simplehtml = false, $tryoembed = true)
|
||||
private static function convertAttachment($text, $simplehtml = false, $tryoembed = true)
|
||||
{
|
||||
$data = self::getAttachmentData($return);
|
||||
$data = self::getAttachmentData($text);
|
||||
if (empty($data) || empty($data['url'])) {
|
||||
return $return;
|
||||
return $text;
|
||||
}
|
||||
|
||||
if (isset($data['title'])) {
|
||||
@@ -599,7 +600,10 @@ class BBCode extends BaseObject
|
||||
|
||||
$return = '';
|
||||
if (in_array($simplehtml, [7, 9])) {
|
||||
$return = self::convertUrlForActivityPub($data['url']);
|
||||
// Only add the link when it isn't already part of the body
|
||||
if (substr_count($text, $data['url']) == 1) {
|
||||
$return = self::convertUrlForActivityPub($data['url']);
|
||||
}
|
||||
} elseif (($simplehtml != 4) && ($simplehtml != 0)) {
|
||||
$return = sprintf('<a href="%s" target="_blank">%s</a><br>', $data['url'], $data['title']);
|
||||
} else {
|
||||
@@ -1552,7 +1556,7 @@ class BBCode extends BaseObject
|
||||
function ($matches) use ($simple_html) {
|
||||
$matches[1] = self::proxyUrl($matches[1], $simple_html);
|
||||
$matches[2] = htmlspecialchars($matches[2], ENT_COMPAT);
|
||||
return '<img src="' . $matches[1] . '" alt="' . $matches[2] . '">';
|
||||
return '<img src="' . $matches[1] . '" alt="' . $matches[2] . '" title="' . $matches[2] . '">';
|
||||
},
|
||||
$text);
|
||||
|
||||
@@ -1747,7 +1751,7 @@ class BBCode extends BaseObject
|
||||
$text = preg_replace_callback("/(?:#\[url\=.*?\]|\[url\=.*?\]#)(.*?)\[\/url\]/ism", function($matches) {
|
||||
return '#<a href="'
|
||||
. System::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
|
||||
. '" class="tag" title="' . XML::escape($matches[1]) . '">'
|
||||
. '" class="tag" rel="tag" title="' . XML::escape($matches[1]) . '">'
|
||||
. XML::escape($matches[1])
|
||||
. '</a>';
|
||||
}, $text);
|
||||
|
||||
32
src/Content/Text/BBCode/Video.php
Normal file
32
src/Content/Text/BBCode/Video.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Content\Text\BBCode;
|
||||
|
||||
/**
|
||||
* Video specific BBCode util class
|
||||
*/
|
||||
final class Video
|
||||
{
|
||||
/**
|
||||
* Transforms video BBCode tagged links to youtube/vimeo tagged links
|
||||
*
|
||||
* @param string $bbCodeString The input BBCode styled string
|
||||
*
|
||||
* @return string The transformed text
|
||||
*/
|
||||
public function transform(string $bbCodeString)
|
||||
{
|
||||
$matches = null;
|
||||
$found = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$bbCodeString,$matches,PREG_SET_ORDER);
|
||||
if ($found) {
|
||||
foreach ($matches as $match) {
|
||||
if ((stristr($match[1], 'youtube')) || (stristr($match[1], 'youtu.be'))) {
|
||||
$bbCodeString = str_replace($match[0], '[youtube]' . $match[1] . '[/youtube]', $bbCodeString);
|
||||
} elseif (stristr($match[1], 'vimeo')) {
|
||||
$bbCodeString = str_replace($match[0], '[vimeo]' . $match[1] . '[/vimeo]', $bbCodeString);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $bbCodeString;
|
||||
}
|
||||
}
|
||||
@@ -1,726 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @file src/Core/NotificationsManager.php
|
||||
* @brief Methods for read and write notifications from/to database
|
||||
* or for formatting notifications
|
||||
*/
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
use Friendica\Util\Temporal;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
/**
|
||||
* @brief Methods for read and write notifications from/to database
|
||||
* or for formatting notifications
|
||||
*/
|
||||
class NotificationsManager extends BaseObject
|
||||
{
|
||||
/**
|
||||
* @brief set some extra note properties
|
||||
*
|
||||
* @param array $notes array of note arrays from db
|
||||
* @return array Copy of input array with added properties
|
||||
*
|
||||
* Set some extra properties to note array from db:
|
||||
* - timestamp as int in default TZ
|
||||
* - date_rel : relative date string
|
||||
* - msg_html: message as html string
|
||||
* - msg_plain: message as plain text string
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private function _set_extra(array $notes)
|
||||
{
|
||||
$rets = [];
|
||||
foreach ($notes as $n) {
|
||||
$local_time = DateTimeFormat::local($n['date']);
|
||||
$n['timestamp'] = strtotime($local_time);
|
||||
$n['date_rel'] = Temporal::getRelativeDate($n['date']);
|
||||
$n['msg_html'] = BBCode::convert($n['msg'], false);
|
||||
$n['msg_plain'] = explode("\n", trim(HTML::toPlaintext($n['msg_html'], 0)))[0];
|
||||
|
||||
$rets[] = $n;
|
||||
}
|
||||
return $rets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get all notifications for local_user()
|
||||
*
|
||||
* @param array $filter optional Array "column name"=>value: filter query by columns values
|
||||
* @param array $order optional Array to order by
|
||||
* @param string $limit optional Query limits
|
||||
*
|
||||
* @return array|bool of results or false on errors
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function getAll($filter = [], $order = ['date' => 'DESC'], $limit = "")
|
||||
{
|
||||
$params = [];
|
||||
|
||||
$params['order'] = $order;
|
||||
|
||||
if (!empty($limit)) {
|
||||
$params['limit'] = $limit;
|
||||
}
|
||||
|
||||
$dbFilter = array_merge($filter, ['uid' => local_user()]);
|
||||
|
||||
$stmtNotifies = DBA::select('notify', [], $dbFilter, $params);
|
||||
|
||||
if (DBA::isResult($stmtNotifies)) {
|
||||
return $this->_set_extra(DBA::toArray($stmtNotifies));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get one note for local_user() by $id value
|
||||
*
|
||||
* @param int $id identity
|
||||
* @return array note values or null if not found
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function getByID($id)
|
||||
{
|
||||
$stmtNotify = DBA::selectFirst('notify', [], ['id' => $id, 'uid' => local_user()]);
|
||||
if (DBA::isResult($stmtNotify)) {
|
||||
return $this->_set_extra([$stmtNotify])[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of $note of local_user()
|
||||
*
|
||||
* @param array $note note array
|
||||
* @param bool $seen optional true or false, default true
|
||||
* @return bool true on success, false on errors
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setSeen($note, $seen = true)
|
||||
{
|
||||
return DBA::update('notify', ['seen' => $seen], [
|
||||
'(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
|
||||
$note['link'],
|
||||
$note['parent'],
|
||||
$note['otype'],
|
||||
local_user()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of all notifications of local_user()
|
||||
*
|
||||
* @param bool $seen optional true or false. default true
|
||||
* @return bool true on success, false on error
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function setAllSeen($seen = true)
|
||||
{
|
||||
return DBA::update('notify', ['seen' => $seen], ['uid' => local_user()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief List of pages for the Notifications TabBar
|
||||
*
|
||||
* @return array with with notifications TabBar data
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getTabs()
|
||||
{
|
||||
$selected = self::getApp()->argv[1] ?? '';
|
||||
|
||||
$tabs = [
|
||||
[
|
||||
'label' => L10n::t('System'),
|
||||
'url' => 'notifications/system',
|
||||
'sel' => (($selected == 'system') ? 'active' : ''),
|
||||
'id' => 'system-tab',
|
||||
'accesskey' => 'y',
|
||||
],
|
||||
[
|
||||
'label' => L10n::t('Network'),
|
||||
'url' => 'notifications/network',
|
||||
'sel' => (($selected == 'network') ? 'active' : ''),
|
||||
'id' => 'network-tab',
|
||||
'accesskey' => 'w',
|
||||
],
|
||||
[
|
||||
'label' => L10n::t('Personal'),
|
||||
'url' => 'notifications/personal',
|
||||
'sel' => (($selected == 'personal') ? 'active' : ''),
|
||||
'id' => 'personal-tab',
|
||||
'accesskey' => 'r',
|
||||
],
|
||||
[
|
||||
'label' => L10n::t('Home'),
|
||||
'url' => 'notifications/home',
|
||||
'sel' => (($selected == 'home') ? 'active' : ''),
|
||||
'id' => 'home-tab',
|
||||
'accesskey' => 'h',
|
||||
],
|
||||
[
|
||||
'label' => L10n::t('Introductions'),
|
||||
'url' => 'notifications/intros',
|
||||
'sel' => (($selected == 'intros') ? 'active' : ''),
|
||||
'id' => 'intro-tab',
|
||||
'accesskey' => 'i',
|
||||
],
|
||||
];
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format the notification query in an usable array
|
||||
*
|
||||
* @param array $notifs The array from the db query
|
||||
* @param string $ident The notifications identifier (e.g. network)
|
||||
* @return array
|
||||
* string 'label' => The type of the notification
|
||||
* string 'link' => URL to the source
|
||||
* string 'image' => The avatar image
|
||||
* string 'url' => The profile url of the contact
|
||||
* string 'text' => The notification text
|
||||
* string 'when' => The date of the notification
|
||||
* string 'ago' => T relative date of the notification
|
||||
* bool 'seen' => Is the notification marked as "seen"
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private function formatNotifs(array $notifs, $ident = "")
|
||||
{
|
||||
$arr = [];
|
||||
|
||||
if (DBA::isResult($notifs)) {
|
||||
foreach ($notifs as $it) {
|
||||
// Because we use different db tables for the notification query
|
||||
// we have sometimes $it['unseen'] and sometimes $it['seen].
|
||||
// So we will have to transform $it['unseen']
|
||||
if (array_key_exists('unseen', $it)) {
|
||||
$it['seen'] = ($it['unseen'] > 0 ? false : true);
|
||||
}
|
||||
|
||||
// For feed items we use the user's contact, since the avatar is mostly self choosen.
|
||||
if (!empty($it['network']) && $it['network'] == Protocol::FEED) {
|
||||
$it['author-avatar'] = $it['contact-avatar'];
|
||||
}
|
||||
|
||||
// Depending on the identifier of the notification we need to use different defaults
|
||||
switch ($ident) {
|
||||
case 'system':
|
||||
$default_item_label = 'notify';
|
||||
$default_item_link = System::baseUrl(true) . '/notify/view/' . $it['id'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($it['photo'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $it['url'];
|
||||
$default_item_text = strip_tags(BBCode::convert($it['msg']));
|
||||
$default_item_when = DateTimeFormat::local($it['date'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($it['date']);
|
||||
break;
|
||||
|
||||
case 'home':
|
||||
$default_item_label = 'comment';
|
||||
$default_item_link = System::baseUrl(true) . '/display/' . $it['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $it['author-link'];
|
||||
$default_item_text = L10n::t("%s commented on %s's post", $it['author-name'], $it['parent-author-name']);
|
||||
$default_item_when = DateTimeFormat::local($it['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($it['created']);
|
||||
break;
|
||||
|
||||
default:
|
||||
$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
|
||||
$default_item_link = System::baseUrl(true) . '/display/' . $it['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $it['author-link'];
|
||||
$default_item_text = (($it['id'] == $it['parent'])
|
||||
? L10n::t("%s created a new post", $it['author-name'])
|
||||
: L10n::t("%s commented on %s's post", $it['author-name'], $it['parent-author-name']));
|
||||
$default_item_when = DateTimeFormat::local($it['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($it['created']);
|
||||
}
|
||||
|
||||
// Transform the different types of notification in an usable array
|
||||
switch ($it['verb']) {
|
||||
case ACTIVITY_LIKE:
|
||||
$notif = [
|
||||
'label' => 'like',
|
||||
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $it['author-link'],
|
||||
'text' => L10n::t("%s liked %s's post", $it['author-name'], $it['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case ACTIVITY_DISLIKE:
|
||||
$notif = [
|
||||
'label' => 'dislike',
|
||||
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $it['author-link'],
|
||||
'text' => L10n::t("%s disliked %s's post", $it['author-name'], $it['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case ACTIVITY_ATTEND:
|
||||
$notif = [
|
||||
'label' => 'attend',
|
||||
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $it['author-link'],
|
||||
'text' => L10n::t("%s is attending %s's event", $it['author-name'], $it['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case ACTIVITY_ATTENDNO:
|
||||
$notif = [
|
||||
'label' => 'attendno',
|
||||
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $it['author-link'],
|
||||
'text' => L10n::t("%s is not attending %s's event", $it['author-name'], $it['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case ACTIVITY_ATTENDMAYBE:
|
||||
$notif = [
|
||||
'label' => 'attendmaybe',
|
||||
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $it['author-link'],
|
||||
'text' => L10n::t("%s may attend %s's event", $it['author-name'], $it['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case ACTIVITY_FRIEND:
|
||||
if (!isset($it['object'])) {
|
||||
$notif = [
|
||||
'label' => 'friend',
|
||||
'link' => $default_item_link,
|
||||
'image' => $default_item_image,
|
||||
'url' => $default_item_url,
|
||||
'text' => $default_item_text,
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
}
|
||||
/// @todo Check if this part here is used at all
|
||||
Logger::log('Complete data: ' . json_encode($it) . ' - ' . System::callstack(20), Logger::DEBUG);
|
||||
|
||||
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||
$obj = XML::parseString($xmlhead . $it['object']);
|
||||
$it['fname'] = $obj->title;
|
||||
|
||||
$notif = [
|
||||
'label' => 'friend',
|
||||
'link' => System::baseUrl(true) . '/display/' . $it['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($it['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $it['author-link'],
|
||||
'text' => L10n::t("%s is now friends with %s", $it['author-name'], $it['fname']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$notif = [
|
||||
'label' => $default_item_label,
|
||||
'link' => $default_item_link,
|
||||
'image' => $default_item_image,
|
||||
'url' => $default_item_url,
|
||||
'text' => $default_item_text,
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $it['seen']
|
||||
];
|
||||
}
|
||||
|
||||
$arr[] = $notif;
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get network notifications
|
||||
*
|
||||
* @param int|string $seen If 0 only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array with
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Network notifications
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function networkNotifs($seen = 0, $start = 0, $limit = 80)
|
||||
{
|
||||
$ident = 'network';
|
||||
$notifs = [];
|
||||
|
||||
$condition = ['wall' => false, 'uid' => local_user()];
|
||||
|
||||
if ($seen === 0) {
|
||||
$condition['unseen'] = true;
|
||||
}
|
||||
|
||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
|
||||
|
||||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBA::isResult($items)) {
|
||||
$notifs = $this->formatNotifs(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifs,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get system notifications
|
||||
*
|
||||
* @param int|string $seen If 0 only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array with
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => System notifications
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function systemNotifs($seen = 0, $start = 0, $limit = 80)
|
||||
{
|
||||
$ident = 'system';
|
||||
$notifs = [];
|
||||
$sql_seen = "";
|
||||
|
||||
$filter = ['uid' => local_user()];
|
||||
if ($seen === 0) {
|
||||
$filter['seen'] = false;
|
||||
}
|
||||
|
||||
$params = [];
|
||||
$params['order'] = ['date' => 'DESC'];
|
||||
$params['limit'] = [$start, $limit];
|
||||
|
||||
$stmtNotifies = DBA::select('notify',
|
||||
['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'],
|
||||
$filter,
|
||||
$params);
|
||||
|
||||
if (DBA::isResult($stmtNotifies)) {
|
||||
$notifs = $this->formatNotifs(DBA::toArray($stmtNotifies), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifs,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get personal notifications
|
||||
*
|
||||
* @param int|string $seen If 0 only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array with
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Personal notifications
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function personalNotifs($seen = 0, $start = 0, $limit = 80)
|
||||
{
|
||||
$ident = 'personal';
|
||||
$notifs = [];
|
||||
|
||||
$myurl = str_replace('http://', '', self::getApp()->contact['nurl']);
|
||||
$diasp_url = str_replace('/profile/', '/u/', $myurl);
|
||||
|
||||
$condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)",
|
||||
local_user(), public_contact(), $myurl . '\\]', $diasp_url . '\\]'];
|
||||
|
||||
if ($seen === 0) {
|
||||
$condition[0] .= " AND `unseen`";
|
||||
}
|
||||
|
||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
|
||||
|
||||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBA::isResult($items)) {
|
||||
$notifs = $this->formatNotifs(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifs,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get home notifications
|
||||
*
|
||||
* @param int|string $seen If 0 only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array with
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Home notifications
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
public function homeNotifs($seen = 0, $start = 0, $limit = 80)
|
||||
{
|
||||
$ident = 'home';
|
||||
$notifs = [];
|
||||
|
||||
$condition = ['wall' => true, 'uid' => local_user()];
|
||||
|
||||
if ($seen === 0) {
|
||||
$condition['unseen'] = true;
|
||||
}
|
||||
|
||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
|
||||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if (DBA::isResult($items)) {
|
||||
$notifs = $this->formatNotifs(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifs,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get introductions
|
||||
*
|
||||
* @param bool $all If false only include introductions into the query
|
||||
* which aren't marked as ignored
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
* @param int $id When set, only the introduction with this id is displayed
|
||||
*
|
||||
* @return array with
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Introductions
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function introNotifs($all = false, $start = 0, $limit = 80, $id = 0)
|
||||
{
|
||||
$ident = 'introductions';
|
||||
$notifs = [];
|
||||
$sql_extra = "";
|
||||
|
||||
if (empty($id)) {
|
||||
if (!$all) {
|
||||
$sql_extra = " AND NOT `ignore` ";
|
||||
}
|
||||
|
||||
$sql_extra .= " AND NOT `intro`.`blocked` ";
|
||||
} else {
|
||||
$sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
|
||||
}
|
||||
|
||||
/// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
|
||||
$stmtNotifies = DBA::p(
|
||||
"SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
|
||||
`fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
|
||||
`fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
|
||||
`gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
|
||||
`gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
|
||||
`gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
|
||||
FROM `intro`
|
||||
LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
|
||||
LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
|
||||
LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
|
||||
WHERE `intro`.`uid` = ? $sql_extra
|
||||
LIMIT ?, ?",
|
||||
$_SESSION['uid'],
|
||||
$start,
|
||||
$limit
|
||||
);
|
||||
if (DBA::isResult($stmtNotifies)) {
|
||||
$notifs = $this->formatIntros(DBA::toArray($stmtNotifies));
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'ident' => $ident,
|
||||
'notifications' => $notifs,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format the notification query in an usable array
|
||||
*
|
||||
* @param array $intros The array from the db query
|
||||
* @return array with the introductions
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
private function formatIntros($intros)
|
||||
{
|
||||
$knowyou = '';
|
||||
|
||||
$arr = [];
|
||||
|
||||
foreach ($intros as $it) {
|
||||
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
|
||||
// We have to distinguish between these two because they use different data.
|
||||
// Contact suggestions
|
||||
if ($it['fid']) {
|
||||
$return_addr = bin2hex(self::getApp()->user['nickname'] . '@' . self::getApp()->getHostName() . ((self::getApp()->getURLPath()) ? '/' . self::getApp()->getURLPath() : ''));
|
||||
|
||||
$intro = [
|
||||
'label' => 'friend_suggestion',
|
||||
'notify_type' => L10n::t('Friend Suggestion'),
|
||||
'intro_id' => $it['intro_id'],
|
||||
'madeby' => $it['name'],
|
||||
'madeby_url' => $it['url'],
|
||||
'madeby_zrl' => Contact::magicLink($it['url']),
|
||||
'madeby_addr' => $it['addr'],
|
||||
'contact_id' => $it['contact-id'],
|
||||
'photo' => (!empty($it['fphoto']) ? ProxyUtils::proxifyUrl($it['fphoto'], false, ProxyUtils::SIZE_SMALL) : "images/person-300.jpg"),
|
||||
'name' => $it['fname'],
|
||||
'url' => $it['furl'],
|
||||
'zrl' => Contact::magicLink($it['furl']),
|
||||
'hidden' => $it['hidden'] == 1,
|
||||
'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
|
||||
'knowyou' => $knowyou,
|
||||
'note' => $it['note'],
|
||||
'request' => $it['frequest'] . '?addr=' . $return_addr,
|
||||
];
|
||||
|
||||
// Normal connection requests
|
||||
} else {
|
||||
$it = $this->getMissingIntroData($it);
|
||||
|
||||
if (empty($it['url'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't show these data until you are connected. Diaspora is doing the same.
|
||||
if ($it['gnetwork'] === Protocol::DIASPORA) {
|
||||
$it['glocation'] = "";
|
||||
$it['gabout'] = "";
|
||||
$it['ggender'] = "";
|
||||
}
|
||||
$intro = [
|
||||
'label' => (($it['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'),
|
||||
'notify_type' => (($it['network'] !== Protocol::OSTATUS) ? L10n::t('Friend/Connect Request') : L10n::t('New Follower')),
|
||||
'dfrn_id' => $it['issued-id'],
|
||||
'uid' => $_SESSION['uid'],
|
||||
'intro_id' => $it['intro_id'],
|
||||
'contact_id' => $it['contact-id'],
|
||||
'photo' => (!empty($it['photo']) ? ProxyUtils::proxifyUrl($it['photo'], false, ProxyUtils::SIZE_SMALL) : "images/person-300.jpg"),
|
||||
'name' => $it['name'],
|
||||
'location' => BBCode::convert($it['glocation'], false),
|
||||
'about' => BBCode::convert($it['gabout'], false),
|
||||
'keywords' => $it['gkeywords'],
|
||||
'gender' => $it['ggender'],
|
||||
'hidden' => $it['hidden'] == 1,
|
||||
'post_newfriend' => (intval(PConfig::get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
|
||||
'url' => $it['url'],
|
||||
'zrl' => Contact::magicLink($it['url']),
|
||||
'addr' => $it['gaddr'],
|
||||
'network' => $it['gnetwork'],
|
||||
'knowyou' => $it['knowyou'],
|
||||
'note' => $it['note'],
|
||||
];
|
||||
}
|
||||
|
||||
$arr[] = $intro;
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for missing contact data and try to fetch the data from
|
||||
* from other sources
|
||||
*
|
||||
* @param array $arr The input array with the intro data
|
||||
*
|
||||
* @return array The array with the intro data
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private function getMissingIntroData($arr)
|
||||
{
|
||||
// If the network and the addr isn't available from the gcontact
|
||||
// table entry, take the one of the contact table entry
|
||||
if (empty($arr['gnetwork']) && !empty($arr['network'])) {
|
||||
$arr['gnetwork'] = $arr['network'];
|
||||
}
|
||||
if (empty($arr['gaddr']) && !empty($arr['addr'])) {
|
||||
$arr['gaddr'] = $arr['addr'];
|
||||
}
|
||||
|
||||
// If the network and addr is still not available
|
||||
// get the missing data data from other sources
|
||||
if (empty($arr['gnetwork']) || empty($arr['gaddr'])) {
|
||||
$ret = Contact::getDetailsByURL($arr['url']);
|
||||
|
||||
if (empty($arr['gnetwork']) && !empty($ret['network'])) {
|
||||
$arr['gnetwork'] = $ret['network'];
|
||||
}
|
||||
if (empty($arr['gaddr']) && !empty($ret['addr'])) {
|
||||
$arr['gaddr'] = $ret['addr'];
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Network\HTTPException\InternalServerErrorException;
|
||||
use Friendica\Util\FileSystem;
|
||||
use Friendica\Util\Introspection;
|
||||
use Friendica\Util\Logger\Monolog\DevelopHandler;
|
||||
use Friendica\Util\Logger\Monolog\IntrospectionProcessor;
|
||||
@@ -51,13 +52,11 @@ class LoggerFactory
|
||||
* @param Database $database The Friendica Database instance
|
||||
* @param Configuration $config The config
|
||||
* @param Profiler $profiler The profiler of the app
|
||||
* @param FileSystem $fileSystem FileSystem utils
|
||||
*
|
||||
* @return LoggerInterface The PSR-3 compliant logger instance
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function create( Database $database, Configuration $config, Profiler $profiler)
|
||||
public function create(Database $database, Configuration $config, Profiler $profiler, FileSystem $fileSystem)
|
||||
{
|
||||
if (empty($config->get('system', 'debugging', false))) {
|
||||
$logger = new VoidLogger();
|
||||
@@ -84,12 +83,22 @@ class LoggerFactory
|
||||
|
||||
// just add a stream in case it's either writable or not file
|
||||
if (!is_file($stream) || is_writable($stream)) {
|
||||
static::addStreamHandler($logger, $stream, $loglevel);
|
||||
try {
|
||||
static::addStreamHandler($logger, $stream, $loglevel);
|
||||
} catch (\Throwable $e) {
|
||||
// No Logger ..
|
||||
$logger = new VoidLogger();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'syslog':
|
||||
$logger = new SyslogLogger($this->channel, $introspection, $loglevel);
|
||||
try {
|
||||
$logger = new SyslogLogger($this->channel, $introspection, $loglevel);
|
||||
} catch (\Throwable $e) {
|
||||
// No logger ...
|
||||
$logger = new VoidLogger();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'stream':
|
||||
@@ -97,7 +106,12 @@ class LoggerFactory
|
||||
$stream = $config->get('system', 'logfile');
|
||||
// just add a stream in case it's either writable or not file
|
||||
if (!is_file($stream) || is_writable($stream)) {
|
||||
$logger = new StreamLogger($this->channel, $stream, $introspection, $loglevel);
|
||||
try {
|
||||
$logger = new StreamLogger($this->channel, $stream, $introspection, $fileSystem, $loglevel);
|
||||
} catch (\Throwable $t) {
|
||||
// No logger ...
|
||||
$logger = new VoidLogger();
|
||||
}
|
||||
} else {
|
||||
$logger = new VoidLogger();
|
||||
}
|
||||
@@ -125,13 +139,14 @@ class LoggerFactory
|
||||
*
|
||||
* @param Configuration $config The config
|
||||
* @param Profiler $profiler The profiler of the app
|
||||
* @param FileSystem $fileSystem FileSystem utils
|
||||
*
|
||||
* @return LoggerInterface The PSR-3 compliant logger instance
|
||||
*
|
||||
* @throws InternalServerErrorException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function createDev(Configuration $config, Profiler $profiler)
|
||||
public static function createDev(Configuration $config, Profiler $profiler, FileSystem $fileSystem)
|
||||
{
|
||||
$debugging = $config->get('system', 'debugging');
|
||||
$stream = $config->get('system', 'dlogfile');
|
||||
@@ -171,7 +186,7 @@ class LoggerFactory
|
||||
|
||||
case 'stream':
|
||||
default:
|
||||
$logger = new StreamLogger(self::DEV_CHANNEL, $stream, $introspection, LogLevel::DEBUG);
|
||||
$logger = new StreamLogger(self::DEV_CHANNEL, $stream, $introspection, $fileSystem, LogLevel::DEBUG);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -211,7 +226,6 @@ class LoggerFactory
|
||||
return LogLevel::INFO;
|
||||
// legacy DATA
|
||||
case "4":
|
||||
return LogLevel::DEBUG;
|
||||
// legacy ALL
|
||||
case "5":
|
||||
return LogLevel::DEBUG;
|
||||
@@ -230,7 +244,6 @@ class LoggerFactory
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws InternalServerErrorException if the logger is incompatible to the logger factory
|
||||
* @throws \Exception in case of general failures
|
||||
*/
|
||||
public static function addStreamHandler($logger, $stream, $level = LogLevel::NOTICE)
|
||||
@@ -249,8 +262,6 @@ class LoggerFactory
|
||||
$fileHandler->setFormatter($formatter);
|
||||
|
||||
$logger->pushHandler($fileHandler);
|
||||
} else {
|
||||
throw new InternalServerErrorException('Logger instance incompatible for MonologFactory');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,17 +12,17 @@ use Friendica\Core\Hook;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\DFRN;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Protocol\PortableContact;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
@@ -828,7 +828,7 @@ class Contact extends BaseObject
|
||||
} elseif (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
|
||||
// create an unfollow slap
|
||||
$item = [];
|
||||
$item['verb'] = NAMESPACE_OSTATUS . "/unfollow";
|
||||
$item['verb'] = Activity::O_UNFOLLOW;
|
||||
$item['follow'] = $contact["url"];
|
||||
$item['body'] = '';
|
||||
$item['title'] = '';
|
||||
@@ -2366,7 +2366,7 @@ class Contact extends BaseObject
|
||||
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
|
||||
// create a follow slap
|
||||
$item = [];
|
||||
$item['verb'] = ACTIVITY_FOLLOW;
|
||||
$item['verb'] = Activity::FOLLOW;
|
||||
$item['follow'] = $contact["url"];
|
||||
$item['body'] = '';
|
||||
$item['title'] = '';
|
||||
@@ -2568,7 +2568,7 @@ class Contact extends BaseObject
|
||||
'source_name' => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : L10n::t('[Name Withheld]')),
|
||||
'source_link' => $contact_record['url'],
|
||||
'source_photo' => $contact_record['photo'],
|
||||
'verb' => ($sharing ? ACTIVITY_FRIEND : ACTIVITY_FOLLOW),
|
||||
'verb' => ($sharing ? Activity::FRIEND : Activity::FOLLOW),
|
||||
'otype' => 'intro'
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Map;
|
||||
use Friendica\Util\Strings;
|
||||
@@ -303,7 +304,7 @@ class Event extends BaseObject
|
||||
|
||||
$item = Item::selectFirst(['id'], ['event-id' => $event['id'], 'uid' => $event['uid']]);
|
||||
if (DBA::isResult($item)) {
|
||||
$object = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$object = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$object .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
|
||||
$object .= '</object>' . "\n";
|
||||
|
||||
@@ -350,13 +351,13 @@ class Event extends BaseObject
|
||||
$item_arr['deny_gid'] = $event['deny_gid'];
|
||||
$item_arr['private'] = $private;
|
||||
$item_arr['visible'] = 1;
|
||||
$item_arr['verb'] = ACTIVITY_POST;
|
||||
$item_arr['object-type'] = ACTIVITY_OBJ_EVENT;
|
||||
$item_arr['verb'] = Activity::POST;
|
||||
$item_arr['object-type'] = Activity\ObjectType::EVENT;
|
||||
$item_arr['origin'] = $event['cid'] === 0 ? 1 : 0;
|
||||
$item_arr['body'] = self::getBBCode($event);
|
||||
$item_arr['event-id'] = $event['id'];
|
||||
|
||||
$item_arr['object'] = '<object><type>' . XML::escape(ACTIVITY_OBJ_EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item_arr['object'] = '<object><type>' . XML::escape(Activity\ObjectType::EVENT) . '</type><title></title><id>' . XML::escape($event['uri']) . '</id>';
|
||||
$item_arr['object'] .= '<content>' . XML::escape(self::getBBCode($event)) . '</content>';
|
||||
$item_arr['object'] .= '</object>' . "\n";
|
||||
|
||||
@@ -911,7 +912,7 @@ class Event extends BaseObject
|
||||
$tpl = Renderer::getMarkupTemplate('event_stream_item.tpl');
|
||||
$return = Renderer::replaceMacros($tpl, [
|
||||
'$id' => $item['event-id'],
|
||||
'$title' => prepare_text($item['event-summary']),
|
||||
'$title' => BBCode::convert($item['event-summary']),
|
||||
'$dtstart_label' => L10n::t('Starts:'),
|
||||
'$dtstart_title' => $dtstart_title,
|
||||
'$dtstart_dt' => $dtstart_dt,
|
||||
@@ -929,7 +930,7 @@ class Event extends BaseObject
|
||||
'$author_name' => $item['author-name'],
|
||||
'$author_link' => $profile_link,
|
||||
'$author_avatar' => $item['author-avatar'],
|
||||
'$description' => prepare_text($item['event-desc']),
|
||||
'$description' => BBCode::convert($item['event-desc']),
|
||||
'$location_label' => L10n::t('Location:'),
|
||||
'$show_map_label' => L10n::t('Show map'),
|
||||
'$hide_map_label' => L10n::t('Hide map'),
|
||||
@@ -979,7 +980,7 @@ class Event extends BaseObject
|
||||
}
|
||||
}
|
||||
|
||||
$location['name'] = prepare_text($location['name']);
|
||||
$location['name'] = BBCode::convert($location['name']);
|
||||
|
||||
// Construct the map HTML.
|
||||
if (isset($location['address'])) {
|
||||
|
||||
@@ -859,7 +859,9 @@ class GContact
|
||||
/**
|
||||
* Update a global contact via an ActivityPub Outbox
|
||||
*
|
||||
* @param string $data Probing result
|
||||
* @param string $feed
|
||||
* @param array $data Probing result
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private static function updateFromOutbox(string $feed, array $data)
|
||||
{
|
||||
@@ -872,6 +874,9 @@ class GContact
|
||||
$items = $outbox['orderedItems'];
|
||||
} elseif (!empty($outbox['first']['orderedItems'])) {
|
||||
$items = $outbox['first']['orderedItems'];
|
||||
} elseif (!empty($outbox['first']['href'])) {
|
||||
self::updateFromOutbox($outbox['first']['href'], $data);
|
||||
return;
|
||||
} elseif (!empty($outbox['first'])) {
|
||||
self::updateFromOutbox($outbox['first'], $data);
|
||||
return;
|
||||
|
||||
@@ -17,13 +17,15 @@ use Friendica\Core\Logger;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Map;
|
||||
use Friendica\Util\Network;
|
||||
@@ -95,7 +97,11 @@ class Item extends BaseObject
|
||||
|
||||
// Never reorder or remove entries from this list. Just add new ones at the end, if needed.
|
||||
// The item-activity table only stores the index and needs this array to know the matching activity.
|
||||
const ACTIVITIES = [ACTIVITY_LIKE, ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE, ACTIVITY_FOLLOW, ACTIVITY2_ANNOUNCE];
|
||||
const ACTIVITIES = [
|
||||
Activity::LIKE, Activity::DISLIKE,
|
||||
Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
|
||||
Activity::FOLLOW,
|
||||
Activity::ANNOUNCE];
|
||||
|
||||
private static $legacy_mode = null;
|
||||
|
||||
@@ -208,9 +214,9 @@ class Item extends BaseObject
|
||||
$row['object'] = '';
|
||||
}
|
||||
if (array_key_exists('object-type', $row)) {
|
||||
$row['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||
$row['object-type'] = Activity\ObjectType::NOTE;
|
||||
}
|
||||
} elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', ACTIVITY_POST, ACTIVITY_SHARE])) {
|
||||
} elseif (array_key_exists('verb', $row) && in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) {
|
||||
// Posts don't have an object or target - but having tags or files.
|
||||
// We safe some performance by building tag and file strings only here.
|
||||
// We remove object and target since they aren't used for this type.
|
||||
@@ -222,7 +228,7 @@ class Item extends BaseObject
|
||||
}
|
||||
}
|
||||
|
||||
if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', ACTIVITY_POST, ACTIVITY_SHARE])) {
|
||||
if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) {
|
||||
// Build the tag string out of the term entries
|
||||
if (array_key_exists('tag', $row) && empty($row['tag'])) {
|
||||
$row['tag'] = Term::tagTextFromItemId($row['internal-iid']);
|
||||
@@ -1151,14 +1157,14 @@ class Item extends BaseObject
|
||||
|
||||
private static function deleteTagsFromItem($item)
|
||||
{
|
||||
if (($item["verb"] != ACTIVITY_TAG) || ($item["object-type"] != ACTIVITY_OBJ_TAGTERM)) {
|
||||
if (($item["verb"] != Activity::TAG) || ($item["object-type"] != Activity\ObjectType::TAGTERM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$xo = XML::parseString($item["object"], false);
|
||||
$xt = XML::parseString($item["target"], false);
|
||||
|
||||
if ($xt->type != ACTIVITY_OBJ_NOTE) {
|
||||
if ($xt->type != Activity\ObjectType::NOTE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1357,13 +1363,16 @@ class Item extends BaseObject
|
||||
$item['parent-uri'] = $item['thr-parent'];
|
||||
}
|
||||
|
||||
/** @var Activity $activity */
|
||||
$activity = self::getClass(Activity::class);
|
||||
|
||||
if (isset($item['gravity'])) {
|
||||
$item['gravity'] = intval($item['gravity']);
|
||||
} elseif ($item['parent-uri'] === $item['uri']) {
|
||||
$item['gravity'] = GRAVITY_PARENT;
|
||||
} elseif (activity_match($item['verb'], ACTIVITY_POST)) {
|
||||
} elseif ($activity->match($item['verb'], Activity::POST)) {
|
||||
$item['gravity'] = GRAVITY_COMMENT;
|
||||
} elseif (activity_match($item['verb'], ACTIVITY_FOLLOW)) {
|
||||
} elseif ($activity->match($item['verb'], Activity::FOLLOW)) {
|
||||
$item['gravity'] = GRAVITY_ACTIVITY;
|
||||
} else {
|
||||
$item['gravity'] = GRAVITY_UNKNOWN; // Should not happen
|
||||
@@ -1559,14 +1568,14 @@ class Item extends BaseObject
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ($item['verb'] == ACTIVITY_FOLLOW) {
|
||||
if ($item['verb'] == Activity::FOLLOW) {
|
||||
if (!$item['origin'] && ($item['author-id'] == Contact::getPublicIdByUserId($uid))) {
|
||||
// Our own follow request can be relayed to us. We don't store it to avoid notification chaos.
|
||||
Logger::log("Follow: Don't store not origin follow request from us for " . $item['parent-uri'], Logger::DEBUG);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => $item['uid'],
|
||||
$condition = ['verb' => Activity::FOLLOW, 'uid' => $item['uid'],
|
||||
'parent-uri' => $item['parent-uri'], 'author-id' => $item['author-id']];
|
||||
if (self::exists($condition)) {
|
||||
// It happens that we receive multiple follow requests by the same author - we only store one.
|
||||
@@ -1673,7 +1682,7 @@ class Item extends BaseObject
|
||||
}
|
||||
}
|
||||
|
||||
if (stristr($item['verb'], ACTIVITY_POKE)) {
|
||||
if (stristr($item['verb'], Activity::POKE)) {
|
||||
$notify_type = Delivery::POKE;
|
||||
}
|
||||
|
||||
@@ -2686,7 +2695,7 @@ class Item extends BaseObject
|
||||
}
|
||||
|
||||
// Only forward posts
|
||||
if ($datarray["verb"] != ACTIVITY_POST) {
|
||||
if ($datarray["verb"] != Activity::POST) {
|
||||
Logger::log('No post', Logger::DEBUG);
|
||||
return false;
|
||||
}
|
||||
@@ -2892,10 +2901,13 @@ class Item extends BaseObject
|
||||
*/
|
||||
public static function enumeratePermissions(array $obj, bool $check_dead = false)
|
||||
{
|
||||
$allow_people = expand_acl($obj['allow_cid']);
|
||||
$allow_groups = Group::expand($obj['uid'], expand_acl($obj['allow_gid']), $check_dead);
|
||||
$deny_people = expand_acl($obj['deny_cid']);
|
||||
$deny_groups = Group::expand($obj['uid'], expand_acl($obj['deny_gid']), $check_dead);
|
||||
/** @var ACLFormatter $aclFormater */
|
||||
$aclFormater = self::getClass(ACLFormatter::class);
|
||||
|
||||
$allow_people = $aclFormater->expand($obj['allow_cid']);
|
||||
$allow_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['allow_gid']), $check_dead);
|
||||
$deny_people = $aclFormater->expand($obj['deny_cid']);
|
||||
$deny_groups = Group::expand($obj['uid'], $aclFormater->expand($obj['deny_gid']), $check_dead);
|
||||
$recipients = array_unique(array_merge($allow_people, $allow_groups));
|
||||
$deny = array_unique(array_merge($deny_people, $deny_groups));
|
||||
$recipients = array_diff($recipients, $deny);
|
||||
@@ -3036,23 +3048,23 @@ class Item extends BaseObject
|
||||
switch ($verb) {
|
||||
case 'like':
|
||||
case 'unlike':
|
||||
$activity = ACTIVITY_LIKE;
|
||||
$activity = Activity::LIKE;
|
||||
break;
|
||||
case 'dislike':
|
||||
case 'undislike':
|
||||
$activity = ACTIVITY_DISLIKE;
|
||||
$activity = Activity::DISLIKE;
|
||||
break;
|
||||
case 'attendyes':
|
||||
case 'unattendyes':
|
||||
$activity = ACTIVITY_ATTEND;
|
||||
$activity = Activity::ATTEND;
|
||||
break;
|
||||
case 'attendno':
|
||||
case 'unattendno':
|
||||
$activity = ACTIVITY_ATTENDNO;
|
||||
$activity = Activity::ATTENDNO;
|
||||
break;
|
||||
case 'attendmaybe':
|
||||
case 'unattendmaybe':
|
||||
$activity = ACTIVITY_ATTENDMAYBE;
|
||||
$activity = Activity::ATTENDMAYBE;
|
||||
break;
|
||||
default:
|
||||
Logger::log('like: unknown verb ' . $verb . ' for item ' . $item_id);
|
||||
@@ -3060,7 +3072,7 @@ class Item extends BaseObject
|
||||
}
|
||||
|
||||
// Enable activity toggling instead of on/off
|
||||
$event_verb_flag = $activity === ACTIVITY_ATTEND || $activity === ACTIVITY_ATTENDNO || $activity === ACTIVITY_ATTENDMAYBE;
|
||||
$event_verb_flag = $activity === Activity::ATTEND || $activity === Activity::ATTENDNO || $activity === Activity::ATTENDMAYBE;
|
||||
|
||||
Logger::log('like: verb ' . $verb . ' item ' . $item_id);
|
||||
|
||||
@@ -3114,7 +3126,7 @@ class Item extends BaseObject
|
||||
// event participation are essentially radio toggles. If you make a subsequent choice,
|
||||
// we need to eradicate your first choice.
|
||||
if ($event_verb_flag) {
|
||||
$verbs = [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE];
|
||||
$verbs = [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE];
|
||||
|
||||
// Translate to the index based activity index
|
||||
$activities = [];
|
||||
@@ -3144,7 +3156,7 @@ class Item extends BaseObject
|
||||
return true;
|
||||
}
|
||||
|
||||
$objtype = $item['resource-id'] ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE;
|
||||
$objtype = $item['resource-id'] ? Activity\ObjectType::IMAGE : Activity\ObjectType::NOTE;
|
||||
|
||||
$new_item = [
|
||||
'guid' => System::createUUID(),
|
||||
@@ -3310,7 +3322,7 @@ class Item extends BaseObject
|
||||
return L10n::t('event');
|
||||
} elseif (!empty($item['resource-id'])) {
|
||||
return L10n::t('photo');
|
||||
} elseif (!empty($item['verb']) && $item['verb'] !== ACTIVITY_POST) {
|
||||
} elseif (!empty($item['verb']) && $item['verb'] !== Activity::POST) {
|
||||
return L10n::t('activity');
|
||||
} elseif ($item['id'] != $item['parent']) {
|
||||
return L10n::t('comment');
|
||||
@@ -3342,10 +3354,9 @@ class Item extends BaseObject
|
||||
|| $rendered_hash != hash("md5", $item["body"])
|
||||
|| Config::get("system", "ignore_cache")
|
||||
) {
|
||||
$a = self::getApp();
|
||||
redir_private_images($a, $item);
|
||||
self::addRedirToImageTags($item);
|
||||
|
||||
$item["rendered-html"] = prepare_text($item["body"]);
|
||||
$item["rendered-html"] = BBCode::convert($item["body"]);
|
||||
$item["rendered-hash"] = hash("md5", $item["body"]);
|
||||
|
||||
$hook_data = ['item' => $item, 'rendered-html' => $item['rendered-html'], 'rendered-hash' => $item['rendered-hash']];
|
||||
@@ -3378,6 +3389,31 @@ class Item extends BaseObject
|
||||
$item["body"] = $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find any non-embedded images in private items and add redir links to them
|
||||
*
|
||||
* @param array &$item The field array of an item row
|
||||
*/
|
||||
private static function addRedirToImageTags(array &$item)
|
||||
{
|
||||
$app = self::getApp();
|
||||
|
||||
$matches = [];
|
||||
$cnt = preg_match_all('|\[img\](http[^\[]*?/photo/[a-fA-F0-9]+?(-[0-9]\.[\w]+?)?)\[\/img\]|', $item['body'], $matches, PREG_SET_ORDER);
|
||||
if ($cnt) {
|
||||
foreach ($matches as $mtch) {
|
||||
if (strpos($mtch[1], '/redir') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((local_user() == $item['uid']) && ($item['private'] == 1) && ($item['contact-id'] != $app->contact['id']) && ($item['network'] == Protocol::DFRN)) {
|
||||
$img_url = 'redir/' . $item['contact-id'] . '?url=' . urlencode($mtch[1]);
|
||||
$item['body'] = str_replace($mtch[0], '[img]' . $img_url . '[/img]', $item['body']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Given an item array, convert the body element from bbcode to html and add smilie icons.
|
||||
* If attach is true, also add icons for item attachments.
|
||||
@@ -3400,7 +3436,7 @@ class Item extends BaseObject
|
||||
|
||||
// In order to provide theme developers more possibilities, event items
|
||||
// are treated differently.
|
||||
if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
|
||||
if ($item['object-type'] === Activity\ObjectType::EVENT && isset($item['event-id'])) {
|
||||
$ev = Event::getItemHTML($item);
|
||||
return $ev;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ use Friendica\Model\Item;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Worker\Delivery;
|
||||
|
||||
@@ -80,7 +81,7 @@ class Mail
|
||||
'source_name' => $msg['from-name'],
|
||||
'source_link' => $msg['from-url'],
|
||||
'source_photo' => $msg['from-photo'],
|
||||
'verb' => ACTIVITY_POST,
|
||||
'verb' => Activity::POST,
|
||||
'otype' => 'mail'
|
||||
];
|
||||
|
||||
|
||||
775
src/Model/Notify.php
Normal file
775
src/Model/Notify.php
Normal file
@@ -0,0 +1,775 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Exception;
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Config\PConfiguration;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
use Friendica\Util\Temporal;
|
||||
use Friendica\Util\XML;
|
||||
use ImagickException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* @brief Methods for read and write notifications from/to database
|
||||
* or for formatting notifications
|
||||
*/
|
||||
final class Notify extends BaseObject
|
||||
{
|
||||
/** @var int The default limit of notifies per page */
|
||||
const DEFAULT_PAGE_LIMIT = 80;
|
||||
|
||||
const NETWORK = 'network';
|
||||
const SYSTEM = 'system';
|
||||
const PERSONAL = 'personal';
|
||||
const HOME = 'home';
|
||||
const INTRO = 'intro';
|
||||
|
||||
/** @var array Array of URL parameters */
|
||||
const URL_TYPES = [
|
||||
self::NETWORK => 'network',
|
||||
self::SYSTEM => 'system',
|
||||
self::HOME => 'home',
|
||||
self::PERSONAL => 'personal',
|
||||
self::INTRO => 'intros',
|
||||
];
|
||||
|
||||
/** @var array Array of the allowed notifies and their printable name */
|
||||
const PRINT_TYPES = [
|
||||
self::NETWORK => 'Network',
|
||||
self::SYSTEM => 'System',
|
||||
self::HOME => 'Home',
|
||||
self::PERSONAL => 'Personal',
|
||||
self::INTRO => 'Introductions',
|
||||
];
|
||||
|
||||
/** @var array The array of access keys for notify pages */
|
||||
const ACCESS_KEYS = [
|
||||
self::NETWORK => 'w',
|
||||
self::SYSTEM => 'y',
|
||||
self::HOME => 'h',
|
||||
self::PERSONAL => 'r',
|
||||
self::INTRO => 'i',
|
||||
];
|
||||
|
||||
/** @var Database */
|
||||
private $dba;
|
||||
/** @var L10n */
|
||||
private $l10n;
|
||||
/** @var App\Arguments */
|
||||
private $args;
|
||||
/** @var App\BaseURL */
|
||||
private $baseUrl;
|
||||
/** @var PConfiguration */
|
||||
private $pConfig;
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
public function __construct(Database $dba, L10n $l10n, App\Arguments $args, App\BaseURL $baseUrl,
|
||||
PConfiguration $pConfig, LoggerInterface $logger)
|
||||
{
|
||||
$this->dba = $dba;
|
||||
$this->l10n = $l10n;
|
||||
$this->args = $args;
|
||||
$this->baseUrl = $baseUrl;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set some extra properties to note array from db:
|
||||
* - timestamp as int in default TZ
|
||||
* - date_rel : relative date string
|
||||
* - msg_html: message as html string
|
||||
* - msg_plain: message as plain text string
|
||||
*
|
||||
* @param array $notes array of note arrays from db
|
||||
*
|
||||
* @return array Copy of input array with added properties
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function setExtra(array $notes)
|
||||
{
|
||||
$retNotes = [];
|
||||
foreach ($notes as $note) {
|
||||
$local_time = DateTimeFormat::local($note['date']);
|
||||
$note['timestamp'] = strtotime($local_time);
|
||||
$note['date_rel'] = Temporal::getRelativeDate($note['date']);
|
||||
$note['msg_html'] = BBCode::convert($note['msg'], false);
|
||||
$note['msg_plain'] = explode("\n", trim(HTML::toPlaintext($note['msg_html'], 0)))[0];
|
||||
|
||||
$retNotes[] = $note;
|
||||
}
|
||||
return $retNotes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all notifications for local_user()
|
||||
*
|
||||
* @param array $filter optional Array "column name"=>value: filter query by columns values
|
||||
* @param array $order optional Array to order by
|
||||
* @param string $limit optional Query limits
|
||||
*
|
||||
* @return array|bool of results or false on errors
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getAll(array $filter = [], array $order = ['date' => 'DESC'], string $limit = "")
|
||||
{
|
||||
$params = [];
|
||||
|
||||
$params['order'] = $order;
|
||||
|
||||
if (!empty($limit)) {
|
||||
$params['limit'] = $limit;
|
||||
}
|
||||
|
||||
$dbFilter = array_merge($filter, ['uid' => local_user()]);
|
||||
|
||||
$stmtNotifies = $this->dba->select('notify', [], $dbFilter, $params);
|
||||
|
||||
if ($this->dba->isResult($stmtNotifies)) {
|
||||
return $this->setExtra($this->dba->toArray($stmtNotifies));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get one note for local_user() by $id value
|
||||
*
|
||||
* @param int $id identity
|
||||
*
|
||||
* @return array note values or null if not found
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getByID(int $id)
|
||||
{
|
||||
$stmtNotify = $this->dba->selectFirst('notify', [], ['id' => $id, 'uid' => local_user()]);
|
||||
if ($this->dba->isResult($stmtNotify)) {
|
||||
return $this->setExtra([$stmtNotify])[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set seen state of $note of local_user()
|
||||
*
|
||||
* @param array $note note array
|
||||
* @param bool $seen optional true or false, default true
|
||||
*
|
||||
* @return bool true on success, false on errors
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setSeen(array $note, bool $seen = true)
|
||||
{
|
||||
return $this->dba->update('notify', ['seen' => $seen], [
|
||||
'(`link` = ? OR (`parent` != 0 AND `parent` = ? AND `otype` = ?)) AND `uid` = ?',
|
||||
$note['link'],
|
||||
$note['parent'],
|
||||
$note['otype'],
|
||||
local_user()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set seen state of all notifications of local_user()
|
||||
*
|
||||
* @param bool $seen optional true or false. default true
|
||||
*
|
||||
* @return bool true on success, false on error
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setAllSeen(bool $seen = true)
|
||||
{
|
||||
return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief List of pages for the Notifications TabBar
|
||||
*
|
||||
* @return array with with notifications TabBar data
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getTabs()
|
||||
{
|
||||
$selected = $this->args->get(1, '');
|
||||
|
||||
$tabs = [];
|
||||
|
||||
foreach (self::URL_TYPES as $type => $url) {
|
||||
$tabs[] = [
|
||||
'label' => $this->l10n->t(self::PRINT_TYPES[$type]),
|
||||
'url' => 'notifications/' . $url,
|
||||
'sel' => (($selected == $url) ? 'active' : ''),
|
||||
'id' => $type . '-tab',
|
||||
'accesskey' => self::ACCESS_KEYS[$type],
|
||||
];
|
||||
}
|
||||
|
||||
return $tabs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the notification query in an usable array
|
||||
*
|
||||
* @param array $notifies The array from the db query
|
||||
* @param string $ident The notifications identifier (e.g. network)
|
||||
*
|
||||
* @return array
|
||||
* string 'label' => The type of the notification
|
||||
* string 'link' => URL to the source
|
||||
* string 'image' => The avatar image
|
||||
* string 'url' => The profile url of the contact
|
||||
* string 'text' => The notification text
|
||||
* string 'when' => The date of the notification
|
||||
* string 'ago' => T relative date of the notification
|
||||
* bool 'seen' => Is the notification marked as "seen"
|
||||
* @throws Exception
|
||||
*/
|
||||
private function formatList(array $notifies, string $ident = "")
|
||||
{
|
||||
$formattedNotifies = [];
|
||||
|
||||
foreach ($notifies as $notify) {
|
||||
// Because we use different db tables for the notification query
|
||||
// we have sometimes $notify['unseen'] and sometimes $notify['seen].
|
||||
// So we will have to transform $notify['unseen']
|
||||
if (array_key_exists('unseen', $notify)) {
|
||||
$notify['seen'] = ($notify['unseen'] > 0 ? false : true);
|
||||
}
|
||||
|
||||
// For feed items we use the user's contact, since the avatar is mostly self choosen.
|
||||
if (!empty($notify['network']) && $notify['network'] == Protocol::FEED) {
|
||||
$notify['author-avatar'] = $notify['contact-avatar'];
|
||||
}
|
||||
|
||||
// Depending on the identifier of the notification we need to use different defaults
|
||||
switch ($ident) {
|
||||
case self::SYSTEM:
|
||||
$default_item_label = 'notify';
|
||||
$default_item_link = $this->baseUrl->get(true) . '/notify/view/' . $notify['id'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notify['photo'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notify['url'];
|
||||
$default_item_text = strip_tags(BBCode::convert($notify['msg']));
|
||||
$default_item_when = DateTimeFormat::local($notify['date'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notify['date']);
|
||||
break;
|
||||
|
||||
case self::HOME:
|
||||
$default_item_label = 'comment';
|
||||
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notify['author-link'];
|
||||
$default_item_text = $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name']);
|
||||
$default_item_when = DateTimeFormat::local($notify['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notify['created']);
|
||||
break;
|
||||
|
||||
default:
|
||||
$default_item_label = (($notify['id'] == $notify['parent']) ? 'post' : 'comment');
|
||||
$default_item_link = $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'];
|
||||
$default_item_image = ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO);
|
||||
$default_item_url = $notify['author-link'];
|
||||
$default_item_text = (($notify['id'] == $notify['parent'])
|
||||
? $this->l10n->t("%s created a new post", $notify['author-name'])
|
||||
: $this->l10n->t("%s commented on %s's post", $notify['author-name'], $notify['parent-author-name']));
|
||||
$default_item_when = DateTimeFormat::local($notify['created'], 'r');
|
||||
$default_item_ago = Temporal::getRelativeDate($notify['created']);
|
||||
}
|
||||
|
||||
// Transform the different types of notification in an usable array
|
||||
switch ($notify['verb']) {
|
||||
case Activity::LIKE:
|
||||
$formattedNotify = [
|
||||
'label' => 'like',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s liked %s's post", $notify['author-name'], $notify['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::DISLIKE:
|
||||
$formattedNotify = [
|
||||
'label' => 'dislike',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s disliked %s's post", $notify['author-name'], $notify['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::ATTEND:
|
||||
$formattedNotify = [
|
||||
'label' => 'attend',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s is attending %s's event", $notify['author-name'], $notify['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::ATTENDNO:
|
||||
$formattedNotify = [
|
||||
'label' => 'attendno',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s is not attending %s's event", $notify['author-name'], $notify['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::ATTENDMAYBE:
|
||||
$formattedNotify = [
|
||||
'label' => 'attendmaybe',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s may attend %s's event", $notify['author-name'], $notify['parent-author-name']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
case Activity::FRIEND:
|
||||
if (!isset($notify['object'])) {
|
||||
$formattedNotify = [
|
||||
'label' => 'friend',
|
||||
'link' => $default_item_link,
|
||||
'image' => $default_item_image,
|
||||
'url' => $default_item_url,
|
||||
'text' => $default_item_text,
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
}
|
||||
/// @todo Check if this part here is used at all
|
||||
$this->logger->info('Complete data.', ['notify' => $notify, 'callStack' => System::callstack(20)]);
|
||||
|
||||
$xmlHead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
|
||||
$obj = XML::parseString($xmlHead . $notify['object']);
|
||||
$notify['fname'] = $obj->title;
|
||||
|
||||
$formattedNotify = [
|
||||
'label' => 'friend',
|
||||
'link' => $this->baseUrl->get(true) . '/display/' . $notify['parent-guid'],
|
||||
'image' => ProxyUtils::proxifyUrl($notify['author-avatar'], false, ProxyUtils::SIZE_MICRO),
|
||||
'url' => $notify['author-link'],
|
||||
'text' => $this->l10n->t("%s is now friends with %s", $notify['author-name'], $notify['fname']),
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
break;
|
||||
|
||||
default:
|
||||
$formattedNotify = [
|
||||
'label' => $default_item_label,
|
||||
'link' => $default_item_link,
|
||||
'image' => $default_item_image,
|
||||
'url' => $default_item_url,
|
||||
'text' => $default_item_text,
|
||||
'when' => $default_item_when,
|
||||
'ago' => $default_item_ago,
|
||||
'seen' => $notify['seen']
|
||||
];
|
||||
}
|
||||
|
||||
$formattedNotifies[] = $formattedNotify;
|
||||
}
|
||||
|
||||
return $formattedNotifies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get network notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Network notifications
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getNetworkList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::NETWORK;
|
||||
$notifies = [];
|
||||
|
||||
$condition = ['wall' => false, 'uid' => local_user()];
|
||||
|
||||
if (!$seen) {
|
||||
$condition['unseen'] = true;
|
||||
}
|
||||
|
||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
|
||||
|
||||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if ($this->dba->isResult($items)) {
|
||||
$notifies = $this->formatList(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get system notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => System notifications
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getSystemList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::SYSTEM;
|
||||
$notifies = [];
|
||||
|
||||
$filter = ['uid' => local_user()];
|
||||
if (!$seen) {
|
||||
$filter['seen'] = false;
|
||||
}
|
||||
|
||||
$params = [];
|
||||
$params['order'] = ['date' => 'DESC'];
|
||||
$params['limit'] = [$start, $limit];
|
||||
|
||||
$stmtNotifies = $this->dba->select('notify',
|
||||
['id', 'url', 'photo', 'msg', 'date', 'seen', 'verb'],
|
||||
$filter,
|
||||
$params);
|
||||
|
||||
if ($this->dba->isResult($stmtNotifies)) {
|
||||
$notifies = $this->formatList($this->dba->toArray($stmtNotifies), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get personal notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Personal notifications
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getPersonalList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::PERSONAL;
|
||||
$notifies = [];
|
||||
|
||||
$myurl = str_replace('http://', '', self::getApp()->contact['nurl']);
|
||||
$diasp_url = str_replace('/profile/', '/u/', $myurl);
|
||||
|
||||
$condition = ["NOT `wall` AND `uid` = ? AND (`item`.`author-id` = ? OR `item`.`tag` REGEXP ? OR `item`.`tag` REGEXP ?)",
|
||||
local_user(), public_contact(), $myurl . '\\]', $diasp_url . '\\]'];
|
||||
|
||||
if (!$seen) {
|
||||
$condition[0] .= " AND `unseen`";
|
||||
}
|
||||
|
||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
|
||||
|
||||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if ($this->dba->isResult($items)) {
|
||||
$notifies = $this->formatList(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get home notifications
|
||||
*
|
||||
* @param bool $seen False => only include notifications into the query
|
||||
* which aren't marked as "seen"
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Home notifications
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getHomeList(bool $seen = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT)
|
||||
{
|
||||
$ident = self::HOME;
|
||||
$notifies = [];
|
||||
|
||||
$condition = ['wall' => true, 'uid' => local_user()];
|
||||
|
||||
if (!$seen) {
|
||||
$condition['unseen'] = true;
|
||||
}
|
||||
|
||||
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
|
||||
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
|
||||
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
|
||||
|
||||
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
|
||||
|
||||
if ($this->dba->isResult($items)) {
|
||||
$notifies = $this->formatList(Item::inArray($items), $ident);
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'notifications' => $notifies,
|
||||
'ident' => $ident,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get introductions
|
||||
*
|
||||
* @param bool $all If false only include introductions into the query
|
||||
* which aren't marked as ignored
|
||||
* @param int $start Start the query at this point
|
||||
* @param int $limit Maximum number of query results
|
||||
* @param int $id When set, only the introduction with this id is displayed
|
||||
*
|
||||
* @return array [string, array]
|
||||
* string 'ident' => Notification identifier
|
||||
* array 'notifications' => Introductions
|
||||
*
|
||||
* @throws ImagickException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getIntroList(bool $all = false, int $start = 0, int $limit = self::DEFAULT_PAGE_LIMIT, int $id = 0)
|
||||
{
|
||||
/// @todo sanitize wording according to SELF::INTRO
|
||||
$ident = 'introductions';
|
||||
$notifies = [];
|
||||
$sql_extra = "";
|
||||
|
||||
if (empty($id)) {
|
||||
if (!$all) {
|
||||
$sql_extra = " AND NOT `ignore` ";
|
||||
}
|
||||
|
||||
$sql_extra .= " AND NOT `intro`.`blocked` ";
|
||||
} else {
|
||||
$sql_extra = sprintf(" AND `intro`.`id` = %d ", intval($id));
|
||||
}
|
||||
|
||||
/// @todo Fetch contact details by "Contact::getDetailsByUrl" instead of queries to contact, fcontact and gcontact
|
||||
$stmtNotifies = $this->dba->p(
|
||||
"SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*,
|
||||
`fcontact`.`name` AS `fname`, `fcontact`.`url` AS `furl`, `fcontact`.`addr` AS `faddr`,
|
||||
`fcontact`.`photo` AS `fphoto`, `fcontact`.`request` AS `frequest`,
|
||||
`gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`,
|
||||
`gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`,
|
||||
`gcontact`.`network` AS `gnetwork`, `gcontact`.`addr` AS `gaddr`
|
||||
FROM `intro`
|
||||
LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id`
|
||||
LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl`
|
||||
LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
|
||||
WHERE `intro`.`uid` = ? $sql_extra
|
||||
LIMIT ?, ?",
|
||||
$_SESSION['uid'],
|
||||
$start,
|
||||
$limit
|
||||
);
|
||||
if ($this->dba->isResult($stmtNotifies)) {
|
||||
$notifies = $this->formatIntroList($this->dba->toArray($stmtNotifies));
|
||||
}
|
||||
|
||||
$arr = [
|
||||
'ident' => $ident,
|
||||
'notifications' => $notifies,
|
||||
];
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format the notification query in an usable array
|
||||
*
|
||||
* @param array $intros The array from the db query
|
||||
*
|
||||
* @return array with the introductions
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws ImagickException
|
||||
*/
|
||||
private function formatIntroList(array $intros)
|
||||
{
|
||||
$knowyou = '';
|
||||
|
||||
$formattedIntros = [];
|
||||
|
||||
foreach ($intros as $intro) {
|
||||
// There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
|
||||
// We have to distinguish between these two because they use different data.
|
||||
// Contact suggestions
|
||||
if ($intro['fid']) {
|
||||
$return_addr = bin2hex(self::getApp()->user['nickname'] . '@' .
|
||||
$this->baseUrl->getHostName() .
|
||||
(($this->baseUrl->getURLPath()) ? '/' . $this->baseUrl->getURLPath() : ''));
|
||||
|
||||
$intro = [
|
||||
'label' => 'friend_suggestion',
|
||||
'notify_type' => $this->l10n->t('Friend Suggestion'),
|
||||
'intro_id' => $intro['intro_id'],
|
||||
'madeby' => $intro['name'],
|
||||
'madeby_url' => $intro['url'],
|
||||
'madeby_zrl' => Contact::magicLink($intro['url']),
|
||||
'madeby_addr' => $intro['addr'],
|
||||
'contact_id' => $intro['contact-id'],
|
||||
'photo' => (!empty($intro['fphoto']) ? ProxyUtils::proxifyUrl($intro['fphoto'], false, ProxyUtils::SIZE_SMALL) : "images/person-300.jpg"),
|
||||
'name' => $intro['fname'],
|
||||
'url' => $intro['furl'],
|
||||
'zrl' => Contact::magicLink($intro['furl']),
|
||||
'hidden' => $intro['hidden'] == 1,
|
||||
'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
|
||||
'knowyou' => $knowyou,
|
||||
'note' => $intro['note'],
|
||||
'request' => $intro['frequest'] . '?addr=' . $return_addr,
|
||||
];
|
||||
|
||||
// Normal connection requests
|
||||
} else {
|
||||
$intro = $this->getMissingIntroData($intro);
|
||||
|
||||
if (empty($intro['url'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't show these data until you are connected. Diaspora is doing the same.
|
||||
if ($intro['gnetwork'] === Protocol::DIASPORA) {
|
||||
$intro['glocation'] = "";
|
||||
$intro['gabout'] = "";
|
||||
$intro['ggender'] = "";
|
||||
}
|
||||
$intro = [
|
||||
'label' => (($intro['network'] !== Protocol::OSTATUS) ? 'friend_request' : 'follower'),
|
||||
'notify_type' => (($intro['network'] !== Protocol::OSTATUS) ? $this->l10n->t('Friend/Connect Request') : $this->l10n->t('New Follower')),
|
||||
'dfrn_id' => $intro['issued-id'],
|
||||
'uid' => $_SESSION['uid'],
|
||||
'intro_id' => $intro['intro_id'],
|
||||
'contact_id' => $intro['contact-id'],
|
||||
'photo' => (!empty($intro['photo']) ? ProxyUtils::proxifyUrl($intro['photo'], false, ProxyUtils::SIZE_SMALL) : "images/person-300.jpg"),
|
||||
'name' => $intro['name'],
|
||||
'location' => BBCode::convert($intro['glocation'], false),
|
||||
'about' => BBCode::convert($intro['gabout'], false),
|
||||
'keywords' => $intro['gkeywords'],
|
||||
'gender' => $intro['ggender'],
|
||||
'hidden' => $intro['hidden'] == 1,
|
||||
'post_newfriend' => (intval($this->pConfig->get(local_user(), 'system', 'post_newfriend')) ? '1' : 0),
|
||||
'url' => $intro['url'],
|
||||
'zrl' => Contact::magicLink($intro['url']),
|
||||
'addr' => $intro['gaddr'],
|
||||
'network' => $intro['gnetwork'],
|
||||
'knowyou' => $intro['knowyou'],
|
||||
'note' => $intro['note'],
|
||||
];
|
||||
}
|
||||
|
||||
$formattedIntros[] = $intro;
|
||||
}
|
||||
|
||||
return $formattedIntros;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check for missing contact data and try to fetch the data from
|
||||
* from other sources
|
||||
*
|
||||
* @param array $intro The input array with the intro data
|
||||
*
|
||||
* @return array The array with the intro data
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
*/
|
||||
private function getMissingIntroData(array $intro)
|
||||
{
|
||||
// If the network and the addr isn't available from the gcontact
|
||||
// table entry, take the one of the contact table entry
|
||||
if (empty($intro['gnetwork']) && !empty($intro['network'])) {
|
||||
$intro['gnetwork'] = $intro['network'];
|
||||
}
|
||||
if (empty($intro['gaddr']) && !empty($intro['addr'])) {
|
||||
$intro['gaddr'] = $intro['addr'];
|
||||
}
|
||||
|
||||
// If the network and addr is still not available
|
||||
// get the missing data data from other sources
|
||||
if (empty($intro['gnetwork']) || empty($intro['gaddr'])) {
|
||||
$ret = Contact::getDetailsByURL($intro['url']);
|
||||
|
||||
if (empty($intro['gnetwork']) && !empty($ret['network'])) {
|
||||
$intro['gnetwork'] = $ret['network'];
|
||||
}
|
||||
if (empty($intro['gaddr']) && !empty($ret['addr'])) {
|
||||
$intro['gaddr'] = $ret['addr'];
|
||||
}
|
||||
}
|
||||
|
||||
return $intro;
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ use Friendica\Core\System;
|
||||
use Friendica\Core\Theme;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
@@ -692,7 +693,7 @@ class Profile
|
||||
|
||||
while ($rr = DBA::fetch($s)) {
|
||||
$condition = ['parent-uri' => $rr['uri'], 'uid' => $rr['uid'], 'author-id' => public_contact(),
|
||||
'activity' => [Item::activityToIndex(ACTIVITY_ATTEND), Item::activityToIndex(ACTIVITY_ATTENDMAYBE)],
|
||||
'activity' => [Item::activityToIndex( Activity::ATTEND), Item::activityToIndex(Activity::ATTENDMAYBE)],
|
||||
'visible' => true, 'deleted' => false];
|
||||
if (!Item::exists($condition)) {
|
||||
continue;
|
||||
@@ -823,51 +824,51 @@ class Profile
|
||||
$profile['religion'] = [L10n::t('Religion:'), $a->profile['religion']];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['about'])) {
|
||||
if ($txt = BBCode::convert($a->profile['about'])) {
|
||||
$profile['about'] = [L10n::t('About:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['interest'])) {
|
||||
if ($txt = BBCode::convert($a->profile['interest'])) {
|
||||
$profile['interest'] = [L10n::t('Hobbies/Interests:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['likes'])) {
|
||||
if ($txt = BBCode::convert($a->profile['likes'])) {
|
||||
$profile['likes'] = [L10n::t('Likes:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['dislikes'])) {
|
||||
if ($txt = BBCode::convert($a->profile['dislikes'])) {
|
||||
$profile['dislikes'] = [L10n::t('Dislikes:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['contact'])) {
|
||||
if ($txt = BBCode::convert($a->profile['contact'])) {
|
||||
$profile['contact'] = [L10n::t('Contact information and Social Networks:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['music'])) {
|
||||
if ($txt = BBCode::convert($a->profile['music'])) {
|
||||
$profile['music'] = [L10n::t('Musical interests:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['book'])) {
|
||||
if ($txt = BBCode::convert($a->profile['book'])) {
|
||||
$profile['book'] = [L10n::t('Books, literature:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['tv'])) {
|
||||
if ($txt = BBCode::convert($a->profile['tv'])) {
|
||||
$profile['tv'] = [L10n::t('Television:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['film'])) {
|
||||
if ($txt = BBCode::convert($a->profile['film'])) {
|
||||
$profile['film'] = [L10n::t('Film/dance/culture/entertainment:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['romance'])) {
|
||||
if ($txt = BBCode::convert($a->profile['romance'])) {
|
||||
$profile['romance'] = [L10n::t('Love/Romance:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['work'])) {
|
||||
if ($txt = BBCode::convert($a->profile['work'])) {
|
||||
$profile['work'] = [L10n::t('Work/employment:'), $txt];
|
||||
}
|
||||
|
||||
if ($txt = prepare_text($a->profile['education'])) {
|
||||
if ($txt = BBCode::convert($a->profile['education'])) {
|
||||
$profile['education'] = [L10n::t('School/education:'), $txt];
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use Friendica\Model\Register;
|
||||
use Friendica\Module\BaseAdminModule;
|
||||
use Friendica\Util\ConfigFileLoader;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\FileSystem;
|
||||
use Friendica\Util\Network;
|
||||
|
||||
class Summary extends BaseAdminModule
|
||||
@@ -76,11 +77,21 @@ class Summary extends BaseAdminModule
|
||||
|
||||
// Check logfile permission
|
||||
if (Config::get('system', 'debugging')) {
|
||||
$stream = Config::get('system', 'logfile');
|
||||
$file = Config::get('system', 'logfile');
|
||||
|
||||
if (is_file($stream) &&
|
||||
!is_writeable($stream)) {
|
||||
$warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
|
||||
/** @var FileSystem $fileSystem */
|
||||
$fileSystem = self::getClass(FileSystem::class);
|
||||
|
||||
try {
|
||||
$stream = $fileSystem->createStream($file);
|
||||
|
||||
if (is_file($stream) &&
|
||||
!is_writeable($stream)) {
|
||||
$warningtext[] = L10n::t('The logfile \'%s\' is not writable. No logging possible', $stream);
|
||||
}
|
||||
|
||||
} catch (\Throwable $exception) {
|
||||
$warningtext[] = L10n::t('The logfile \'%s\' is not usable. No logging possible (error: \'%s\')', $file, $exception->getMessage());
|
||||
}
|
||||
|
||||
$stream = Config::get('system', 'dlogfile');
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Friendica\Module\Diaspora;
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
@@ -34,7 +35,8 @@ class Receive extends BaseModule
|
||||
$enabled = $config->get('system', 'diaspora_enabled', false);
|
||||
if (!$enabled) {
|
||||
self::$logger->info('Diaspora disabled.');
|
||||
throw new HTTPException\InternalServerErrorException('Diaspora disabled.');
|
||||
$l10n = self::getClass(L10n::class);
|
||||
throw new HTTPException\ForbiddenException($l10n->t('Access denied.'));
|
||||
}
|
||||
|
||||
/** @var App\Arguments $args */
|
||||
|
||||
@@ -16,6 +16,7 @@ use Friendica\Model\Item;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Module\Login;
|
||||
use Friendica\Network\HTTPException\NotImplementedException;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
use Friendica\Util\Crypto;
|
||||
|
||||
class Compose extends BaseModule
|
||||
@@ -58,6 +59,9 @@ class Compose extends BaseModule
|
||||
|
||||
$user = User::getById(local_user(), ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'hidewall', 'default-location']);
|
||||
|
||||
/** @var ACLFormatter $aclFormatter */
|
||||
$aclFormatter = self::getClass(ACLFormatter::class);
|
||||
|
||||
switch ($posttype) {
|
||||
case Item::PT_PERSONAL_NOTE:
|
||||
$compose_title = L10n::t('Compose new personal note');
|
||||
@@ -70,8 +74,8 @@ class Compose extends BaseModule
|
||||
$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;
|
||||
$contact_allow = implode(',', $aclFormatter->expand($user['allow_cid']));
|
||||
$group_allow = implode(',', $aclFormatter->expand($user['allow_gid'])) ?: Group::FOLLOWERS;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -82,8 +86,8 @@ class Compose extends BaseModule
|
||||
$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']));
|
||||
$contact_deny = $_REQUEST['contact_deny'] ?? implode(',', $aclFormatter->expand($user['deny_cid']));
|
||||
$group_deny = $_REQUEST['group_deny'] ?? implode(',', $aclFormatter->expand($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]]);
|
||||
|
||||
78
src/Module/Item/Ignore.php
Normal file
78
src/Module/Item/Ignore.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Module\Item;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\L10n\L10n;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* Module for ignoring threads or user items
|
||||
*/
|
||||
class Ignore extends BaseModule
|
||||
{
|
||||
public static function rawContent()
|
||||
{
|
||||
/** @var L10n $l10n */
|
||||
$l10n = self::getClass(L10n::class);
|
||||
|
||||
if (!Session::isAuthenticated()) {
|
||||
throw new HttpException\ForbiddenException($l10n->t('Access denied.'));
|
||||
}
|
||||
|
||||
/** @var App\Arguments $args */
|
||||
$args = self::getClass(App\Arguments::class);
|
||||
/** @var Database $dba */
|
||||
$dba = self::getClass(Database::class);
|
||||
|
||||
$message_id = intval($args->get(2));
|
||||
|
||||
if (empty($message_id) || !is_int($message_id)) {
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
$thread = Item::selectFirstThreadForUser(local_user(), ['uid', 'ignored'], ['iid' => $message_id]);
|
||||
if (!$dba->isResult($thread)) {
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
// Numeric values are needed for the json output further below
|
||||
$ignored = !empty($thread['ignored']) ? 0 : 1;
|
||||
|
||||
switch ($thread['uid'] ?? 0) {
|
||||
// if the thread is from the current user
|
||||
case local_user():
|
||||
$dba->update('thread', ['ignored' => $ignored], ['iid' => $message_id]);
|
||||
break;
|
||||
// 0 (null will get transformed to 0) => it's a public post
|
||||
case 0:
|
||||
$dba->update('user-item', ['ignored' => $ignored], ['iid' => $message_id, 'uid' => local_user()], true);
|
||||
break;
|
||||
// Throws a BadRequestException and not a ForbiddenException on purpose
|
||||
// Avoids harvesting existing, but forbidden IIDs (security issue)
|
||||
default:
|
||||
throw new HTTPException\BadRequestException();
|
||||
}
|
||||
|
||||
// See if we've been passed a return path to redirect to
|
||||
$return_path = $_REQUEST['return'] ?? '';
|
||||
if (!empty($return_path)) {
|
||||
$rand = '_=' . time();
|
||||
if (strpos($return_path, '?')) {
|
||||
$rand = "&$rand";
|
||||
} else {
|
||||
$rand = "?$rand";
|
||||
}
|
||||
|
||||
self::getApp()->internalRedirect($return_path . $rand);
|
||||
}
|
||||
|
||||
// the json doesn't really matter, it will either be 0 or 1
|
||||
System::jsonExit([$ignored]);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,10 @@
|
||||
namespace Friendica\Module\Notifications;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\NotificationsManager;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\Notify as ModelNotify;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,8 @@ class Notify extends BaseModule
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
|
||||
$notificationsManager = new NotificationsManager();
|
||||
/** @var ModelNotify $notificationsManager */
|
||||
$notificationsManager = self::getClass(ModelNotify::class);
|
||||
$success = $notificationsManager->setAllSeen();
|
||||
|
||||
header('Content-type: application/json; charset=utf-8');
|
||||
@@ -49,7 +51,8 @@ class Notify extends BaseModule
|
||||
|
||||
// @TODO: Replace with parameter from router
|
||||
if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
|
||||
$notificationsManager = new NotificationsManager();
|
||||
/** @var ModelNotify $notificationsManager */
|
||||
$notificationsManager = BaseObject::getClass(ModelNotify::class);
|
||||
// @TODO: Replace with parameter from router
|
||||
$note = $notificationsManager->getByID($a->argv[2]);
|
||||
if (!empty($note)) {
|
||||
|
||||
@@ -131,9 +131,12 @@ class Profile extends BaseModule
|
||||
|
||||
$category = $datequery = $datequery2 = '';
|
||||
|
||||
/** @var DateTimeFormat $dtFormat */
|
||||
$dtFormat = self::getClass(DateTimeFormat::class);
|
||||
|
||||
if ($a->argc > 2) {
|
||||
for ($x = 2; $x < $a->argc; $x ++) {
|
||||
if (is_a_date_arg($a->argv[$x])) {
|
||||
if ($dtFormat->isYearMonth($a->argv[$x])) {
|
||||
if ($datequery) {
|
||||
$datequery2 = Strings::escapeHtml($a->argv[$x]);
|
||||
} else {
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace Friendica\Module;
|
||||
|
||||
use Friendica\BaseModule;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Photo;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
@@ -95,11 +95,11 @@ class Xrd extends BaseModule
|
||||
],
|
||||
'links' => [
|
||||
[
|
||||
'rel' => NAMESPACE_DFRN,
|
||||
'rel' => ActivityNamespace::DFRN ,
|
||||
'href' => $owner['url'],
|
||||
],
|
||||
[
|
||||
'rel' => NAMESPACE_FEED,
|
||||
'rel' => ActivityNamespace::FEED,
|
||||
'type' => 'application/atom+xml',
|
||||
'href' => $owner['poll'],
|
||||
],
|
||||
@@ -119,7 +119,7 @@ class Xrd extends BaseModule
|
||||
'href' => $baseURL . '/hcard/' . $owner['nickname'],
|
||||
],
|
||||
[
|
||||
'rel' => NAMESPACE_POCO,
|
||||
'rel' => ActivityNamespace::POCO,
|
||||
'href' => $owner['poco'],
|
||||
],
|
||||
[
|
||||
|
||||
@@ -18,11 +18,11 @@ use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Email;
|
||||
use Friendica\Protocol\Feed;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Strings;
|
||||
use Friendica\Util\XML;
|
||||
@@ -200,10 +200,10 @@ class Probe
|
||||
Logger::log('webfingerDfrn: '.$webbie.':'.print_r($links, true), Logger::DATA);
|
||||
if (!empty($links) && is_array($links)) {
|
||||
foreach ($links as $link) {
|
||||
if ($link['@attributes']['rel'] === NAMESPACE_DFRN) {
|
||||
if ($link['@attributes']['rel'] === ActivityNamespace::DFRN) {
|
||||
$profile_link = $link['@attributes']['href'];
|
||||
}
|
||||
if (($link['@attributes']['rel'] === NAMESPACE_OSTATUSSUB) && ($profile_link == "")) {
|
||||
if (($link['@attributes']['rel'] === ActivityNamespace::OSTATUSSUB) && ($profile_link == "")) {
|
||||
$profile_link = 'stat:'.$link['@attributes']['template'];
|
||||
}
|
||||
if ($link['@attributes']['rel'] === 'http://microformats.org/profile/hcard') {
|
||||
@@ -492,7 +492,7 @@ class Probe
|
||||
$has_key = false;
|
||||
|
||||
foreach ($webfinger['links'] as $link) {
|
||||
if ($link['rel'] == NAMESPACE_OSTATUSSUB) {
|
||||
if ($link['rel'] == ActivityNamespace::OSTATUSSUB) {
|
||||
$is_ostatus = true;
|
||||
}
|
||||
if ($link['rel'] == 'magic-public-key') {
|
||||
@@ -955,15 +955,15 @@ class Probe
|
||||
// The array is reversed to take into account the order of preference for same-rel links
|
||||
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
|
||||
foreach (array_reverse($webfinger["links"]) as $link) {
|
||||
if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
|
||||
if (($link["rel"] == ActivityNamespace::DFRN) && !empty($link["href"])) {
|
||||
$data["network"] = Protocol::DFRN;
|
||||
} elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
|
||||
} elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
|
||||
$data["poll"] = $link["href"];
|
||||
} elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (($link["type"] ?? "") == "text/html") && !empty($link["href"])) {
|
||||
$data["url"] = $link["href"];
|
||||
} elseif (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
|
||||
$hcard_url = $link["href"];
|
||||
} elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
|
||||
} elseif (($link["rel"] == ActivityNamespace::POCO) && !empty($link["href"])) {
|
||||
$data["poco"] = $link["href"];
|
||||
} elseif (($link["rel"] == "http://webfinger.net/rel/avatar") && !empty($link["href"])) {
|
||||
$data["photo"] = $link["href"];
|
||||
@@ -1171,9 +1171,9 @@ class Probe
|
||||
$data["guid"] = $link["href"];
|
||||
} elseif (($link["rel"] == "http://webfinger.net/rel/profile-page") && (($link["type"] ?? "") == "text/html") && !empty($link["href"])) {
|
||||
$data["url"] = $link["href"];
|
||||
} elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
|
||||
} elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
|
||||
$data["poll"] = $link["href"];
|
||||
} elseif (($link["rel"] == NAMESPACE_POCO) && !empty($link["href"])) {
|
||||
} elseif (($link["rel"] == ActivityNamespace::POCO) && !empty($link["href"])) {
|
||||
$data["poco"] = $link["href"];
|
||||
} elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
|
||||
$data["notify"] = $link["href"];
|
||||
@@ -1273,7 +1273,7 @@ class Probe
|
||||
$data["url"] = $link["href"];
|
||||
} elseif (($link["rel"] == "salmon") && !empty($link["href"])) {
|
||||
$data["notify"] = $link["href"];
|
||||
} elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
|
||||
} elseif (($link["rel"] == ActivityNamespace::FEED) && !empty($link["href"])) {
|
||||
$data["poll"] = $link["href"];
|
||||
} elseif (($link["rel"] == "magic-public-key") && !empty($link["href"])) {
|
||||
$pubkey = $link["href"];
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Friendica\Object;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Feature;
|
||||
use Friendica\Content\Item as ContentItem;
|
||||
use Friendica\Core\Addon;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Hook;
|
||||
@@ -14,13 +15,14 @@ use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
@@ -238,7 +240,7 @@ class Post extends BaseObject
|
||||
|
||||
$isevent = false;
|
||||
$attend = [];
|
||||
if ($item['object-type'] === ACTIVITY_OBJ_EVENT) {
|
||||
if ($item['object-type'] === Activity\ObjectType::EVENT) {
|
||||
$response_verbs[] = 'attendyes';
|
||||
$response_verbs[] = 'attendno';
|
||||
$response_verbs[] = 'attendmaybe';
|
||||
@@ -323,7 +325,10 @@ class Post extends BaseObject
|
||||
|
||||
$body = Item::prepareBody($item, true);
|
||||
|
||||
list($categories, $folders) = get_cats_and_terms($item);
|
||||
/** @var ContentItem $contItem */
|
||||
$contItem = self::getClass(ContentItem::class);
|
||||
|
||||
list($categories, $folders) = $contItem->determineCategoriesTerms($item);
|
||||
|
||||
$body_e = $body;
|
||||
$text_e = strip_tags($body);
|
||||
@@ -517,12 +522,17 @@ class Post extends BaseObject
|
||||
Logger::log('[WARN] Post::addChild : Item already exists (' . $item->getId() . ').', Logger::DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Activity $activity */
|
||||
$activity = self::getClass(Activity::class);
|
||||
|
||||
/*
|
||||
* Only add what will be displayed
|
||||
*/
|
||||
if ($item->getDataValue('network') === Protocol::MAIL && local_user() != $item->getDataValue('uid')) {
|
||||
return false;
|
||||
} elseif (activity_match($item->getDataValue('verb'), ACTIVITY_LIKE) || activity_match($item->getDataValue('verb'), ACTIVITY_DISLIKE)) {
|
||||
} elseif ($activity->match($item->getDataValue('verb'), Activity::LIKE) ||
|
||||
$activity->match($item->getDataValue('verb'), Activity::DISLIKE)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Friendica\Object;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\Security;
|
||||
|
||||
/**
|
||||
@@ -154,7 +155,7 @@ class Thread extends BaseObject
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($item->getDataValue('verb') === ACTIVITY_LIKE || $item->getDataValue('verb') === ACTIVITY_DISLIKE) {
|
||||
if ($item->getDataValue('verb') === Activity::LIKE || $item->getDataValue('verb') === Activity::DISLIKE) {
|
||||
Logger::log('[WARN] Conversation::addThread : Thread is a (dis)like ('. $item->getId() .').', Logger::DEBUG);
|
||||
return false;
|
||||
}
|
||||
|
||||
205
src/Protocol/Activity.php
Normal file
205
src/Protocol/Activity.php
Normal file
@@ -0,0 +1,205 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Protocol;
|
||||
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
|
||||
/**
|
||||
* Base class for the Activity Verbs
|
||||
*/
|
||||
final class Activity
|
||||
{
|
||||
/**
|
||||
* Indicates that the actor marked the object as an item of special interest.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const LIKE = ActivityNamespace::ACTIVITY_SCHEMA . 'like';
|
||||
/**
|
||||
* Dislike a message ("I don't like the post")
|
||||
*
|
||||
* @see http://purl.org/macgirvin/dfrn/1.0/dislike
|
||||
* @var string
|
||||
*/
|
||||
const DISLIKE = ActivityNamespace::DFRN . '/dislike';
|
||||
|
||||
/**
|
||||
* Attend an event
|
||||
*
|
||||
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attend
|
||||
* @var string
|
||||
*/
|
||||
const ATTEND = ActivityNamespace::ZOT . '/activity/attendyes';
|
||||
/**
|
||||
* Don't attend an event
|
||||
*
|
||||
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendno
|
||||
* @var string
|
||||
*/
|
||||
const ATTENDNO = ActivityNamespace::ZOT . '/activity/attendno';
|
||||
/**
|
||||
* Attend maybe an event
|
||||
*
|
||||
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_attendmaybe
|
||||
* @var string
|
||||
*/
|
||||
const ATTENDMAYBE = ActivityNamespace::ZOT . '/activity/attendmaybe';
|
||||
|
||||
/**
|
||||
* Indicates the creation of a friendship that is reciprocated by the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'make-friend';
|
||||
/**
|
||||
* Indicates the creation of a friendship that has not yet been reciprocated by the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const REQ_FRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'request-friend';
|
||||
/**
|
||||
* Indicates that the actor has removed the object from the collection of friends.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const UNFRIEND = ActivityNamespace::ACTIVITY_SCHEMA . 'remove-friend';
|
||||
/**
|
||||
* Indicates that the actor began following the activity of the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const FOLLOW = ActivityNamespace::ACTIVITY_SCHEMA . 'follow';
|
||||
/**
|
||||
* Indicates that the actor has stopped following the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const UNFOLLOW = ActivityNamespace::ACTIVITY_SCHEMA . 'stop-following';
|
||||
/**
|
||||
* Indicates that the actor has become a member of the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const JOIN = ActivityNamespace::ACTIVITY_SCHEMA . 'join';
|
||||
/**
|
||||
* Implementors SHOULD use verbs such as post where the actor is adding new items to a collection or similar.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const POST = ActivityNamespace::ACTIVITY_SCHEMA . 'post';
|
||||
/**
|
||||
* The "update" verb indicates that the actor has modified the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const UPDATE = ActivityNamespace::ACTIVITY_SCHEMA . 'update';
|
||||
/**
|
||||
* Indicates that the actor has identified the presence of a target inside another object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const TAG = ActivityNamespace::ACTIVITY_SCHEMA . 'tag';
|
||||
/**
|
||||
* Indicates that the actor marked the object as an item of special interest.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const FAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'favorite';
|
||||
/**
|
||||
* Indicates that the actor has removed the object from the collection of favorited items.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const UNFAVORITE = ActivityNamespace::ACTIVITY_SCHEMA . 'unfavorite';
|
||||
/**
|
||||
* Indicates that the actor has called out the object to readers.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const SHARE = ActivityNamespace::ACTIVITY_SCHEMA . 'share';
|
||||
/**
|
||||
* Indicates that the actor has deleted the object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#verbs
|
||||
* @var string
|
||||
*/
|
||||
const DELETE = ActivityNamespace::ACTIVITY_SCHEMA . 'delete';
|
||||
/**
|
||||
* Indicates that the actor is calling the target's attention the object.
|
||||
*
|
||||
* @see https://www.w3.org/TR/activitystreams-vocabulary/#dfn-announce
|
||||
* @var string
|
||||
*/
|
||||
const ANNOUNCE = ActivityNamespace::ACTIVITY2 . 'Announce';
|
||||
|
||||
/**
|
||||
* Pokes an user.
|
||||
*
|
||||
* @see https://github.com/friendica/friendica/wiki/ActivityStreams#activity_poke
|
||||
* @var string
|
||||
*/
|
||||
const POKE = ActivityNamespace::ZOT . '/activity/poke';
|
||||
|
||||
|
||||
const O_UNFOLLOW = ActivityNamespace::OSTATUS . '/unfollow';
|
||||
const O_UNFAVOURITE = ActivityNamespace::OSTATUS . '/unfavorite';
|
||||
|
||||
/**
|
||||
* likes (etc.) can apply to other things besides posts. Check if they are post children,
|
||||
* in which case we handle them specially
|
||||
*
|
||||
* Hidden activities, which doesn't need to be shown
|
||||
*/
|
||||
const HIDDEN_ACTIVITIES = [
|
||||
Activity::LIKE, Activity::DISLIKE,
|
||||
Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE,
|
||||
Activity::FOLLOW,
|
||||
Activity::ANNOUNCE,
|
||||
];
|
||||
|
||||
/**
|
||||
* Checks if the given activity is a hidden activity
|
||||
*
|
||||
* @param string $activity The current activity
|
||||
*
|
||||
* @return bool True, if the activity is hidden
|
||||
*/
|
||||
public function isHidden(string $activity)
|
||||
{
|
||||
foreach (self::HIDDEN_ACTIVITIES as $hiddenActivity) {
|
||||
if ($this->match($activity, $hiddenActivity)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare activity uri. Knows about activity namespace.
|
||||
*
|
||||
* @param string $haystack
|
||||
* @param string $needle
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function match(string $haystack, string $needle)
|
||||
{
|
||||
return (($haystack === $needle) ||
|
||||
((basename($needle) === $haystack) &&
|
||||
strstr($needle, ActivityNamespace::ACTIVITY_SCHEMA)));
|
||||
}
|
||||
}
|
||||
105
src/Protocol/Activity/ObjectType.php
Normal file
105
src/Protocol/Activity/ObjectType.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Protocol\Activity;
|
||||
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
|
||||
/**
|
||||
* This class contains the different object types in activities
|
||||
*/
|
||||
final class ObjectType
|
||||
{
|
||||
/**
|
||||
* The "bookmark" object type represents a pointer to some URL -- typically a web page.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#bookmark
|
||||
* @var string
|
||||
*/
|
||||
const BOOKMARK = ActivityNamespace::ACTIVITY_SCHEMA . 'bookmark';
|
||||
/**
|
||||
* The "comment" object type represents a textual response to another object.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#comment
|
||||
* @var string
|
||||
*/
|
||||
const COMMENT = ActivityNamespace::ACTIVITY_SCHEMA . 'comment';
|
||||
/**
|
||||
* The "comment" object type represents a textual response to another object.
|
||||
* (Default type for items)
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#note
|
||||
* @var string
|
||||
*/
|
||||
const NOTE = ActivityNamespace::ACTIVITY_SCHEMA . 'note';
|
||||
/**
|
||||
* The "person" object type represents a user account.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#person
|
||||
* @var string
|
||||
*/
|
||||
const PERSON = ActivityNamespace::ACTIVITY_SCHEMA . 'person';
|
||||
/**
|
||||
* The "image" object type represents a graphical image.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#image
|
||||
* @var string
|
||||
*/
|
||||
const IMAGE = ActivityNamespace::ACTIVITY_SCHEMA . 'image';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const PHOTO = ActivityNamespace::ACTIVITY_SCHEMA . 'photo';
|
||||
/**
|
||||
* The "video" object type represents video content,
|
||||
* which usually consists of a motion picture track and an audio track.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#video
|
||||
* @var string
|
||||
*/
|
||||
const VIDEO = ActivityNamespace::ACTIVITY_SCHEMA . 'video';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const PROFILE_PHOTO = ActivityNamespace::ACTIVITY_SCHEMA . 'profile-photo';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const ALBUM = ActivityNamespace::ACTIVITY_SCHEMA . 'photo-album';
|
||||
/**
|
||||
* The "event" object type represents an event that occurs in a certain place during a particular interval of time.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#event
|
||||
* @var string
|
||||
*/
|
||||
const EVENT = ActivityNamespace::ACTIVITY_SCHEMA . 'event';
|
||||
/**
|
||||
* The "group" object type represents a grouping of objects in which member objects can join or leave.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#group
|
||||
* @var string
|
||||
*/
|
||||
const GROUP = ActivityNamespace::ACTIVITY_SCHEMA . 'group';
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const HEART = ActivityNamespace::DFRN . '/heart';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const TAGTERM = ActivityNamespace::DFRN . '/tagterm';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const PROFILE = ActivityNamespace::DFRN . '/profile';
|
||||
|
||||
|
||||
/**
|
||||
* The "question" object type represents a question or poll.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html#question
|
||||
* @var string
|
||||
*/
|
||||
const QUESTION = 'http://activityschema.org/object/question';
|
||||
}
|
||||
132
src/Protocol/ActivityNamespace.php
Normal file
132
src/Protocol/ActivityNamespace.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Protocol;
|
||||
|
||||
/**
|
||||
* Activity namespaces constants
|
||||
*/
|
||||
final class ActivityNamespace
|
||||
{
|
||||
/**
|
||||
* Zot is a WebMTA which provides a decentralised identity and communications protocol using HTTPS/JSON.
|
||||
*
|
||||
* @var string
|
||||
* @see https://zotlabs.org/page/zotlabs/specs+zot6+home
|
||||
*/
|
||||
const ZOT = 'http://purl.org/zot';
|
||||
/**
|
||||
* Friendica is using ActivityStreams in version 1.0 for its activities and object types.
|
||||
* Additional types are used for non standard activities.
|
||||
*
|
||||
* @var string
|
||||
* @see https://github.com/friendica/friendica/wiki/ActivityStreams
|
||||
*/
|
||||
const DFRN = 'http://purl.org/macgirvin/dfrn/1.0';
|
||||
/**
|
||||
* This namespace defines an extension for expressing threaded
|
||||
* discussions within the Atom Syndication Format [RFC4287]
|
||||
*
|
||||
* @see https://tools.ietf.org/rfc/rfc4685.txt
|
||||
* @var string
|
||||
*/
|
||||
const THREAD = 'http://purl.org/syndication/thread/1.0';
|
||||
/**
|
||||
* This namespace adds mechanisms to the Atom Syndication Format
|
||||
* that publishers of Atom Feed and Entry documents can use to
|
||||
* explicitly identify Atom entries that have been removed.
|
||||
*
|
||||
* @see https://tools.ietf.org/html/rfc6721
|
||||
* @var string
|
||||
*/
|
||||
const TOMB = 'http://purl.org/atompub/tombstones/1.0';
|
||||
/**
|
||||
* This specification details a model for representing potential and completed activities
|
||||
* using the JSON format.
|
||||
*
|
||||
* @see https://www.w3.org/ns/activitystreams
|
||||
* @var string
|
||||
*/
|
||||
const ACTIVITY2 = 'https://www.w3.org/ns/activitystreams#';
|
||||
/**
|
||||
* Atom Activities 1.0
|
||||
*
|
||||
* This namespace presents an XML format that allows activities on social objects
|
||||
* to be expressed within the Atom Syndication Format.
|
||||
*
|
||||
* @see http://activitystrea.ms/spec/1.0
|
||||
* @var string
|
||||
*/
|
||||
const ACTIVITY = 'http://activitystrea.ms/spec/1.0/';
|
||||
/**
|
||||
* This namespace presents a base set of Object types and Verbs for use with Activity Streams.
|
||||
*
|
||||
* @see http://activitystrea.ms/head/activity-schema.html
|
||||
* @var string
|
||||
*/
|
||||
const ACTIVITY_SCHEMA = 'http://activitystrea.ms/schema/1.0/';
|
||||
/**
|
||||
* Atom Media Extensions
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const MEDIA = 'http://purl.org/syndication/atommedia';
|
||||
/**
|
||||
* The Salmon Protocol is an open, simple, standards-based solution that lets
|
||||
* aggregators and sources unify the conversations.
|
||||
*
|
||||
* @see http://www.salmon-protocol.org/salmon-protocol-summary
|
||||
* @var string
|
||||
*/
|
||||
const SALMON_ME = 'http://salmon-protocol.org/ns/magic-env';
|
||||
/**
|
||||
* OStatus is a minimal specification for distributed status updates or microblogging.
|
||||
*
|
||||
* @see https://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html
|
||||
* @var string
|
||||
*/
|
||||
const OSTATUSSUB = 'http://ostatus.org/schema/1.0/subscribe';
|
||||
/**
|
||||
* GeoRSS was designed as a lightweight, community driven way to extend existing feeds with geographic information.
|
||||
*
|
||||
* @see http://www.georss.org/
|
||||
* @var string
|
||||
*/
|
||||
const GEORSS = 'http://www.georss.org/georss';
|
||||
/**
|
||||
* The Portable Contacts specification is designed to make it easier for developers
|
||||
* to give their users a secure way to access the address books and friends lists
|
||||
* they have built up all over the web.
|
||||
*
|
||||
* @see http://portablecontacts.net/draft-spec/
|
||||
* @var string
|
||||
*/
|
||||
const POCO = 'http://portablecontacts.net/spec/1.0';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const FEED = 'http://schemas.google.com/g/2010#updates-from';
|
||||
/**
|
||||
* OStatus is a minimal specification for distributed status updates or microblogging.
|
||||
*
|
||||
* @see https://ostatus.github.io/spec/OStatus%201.0%20Draft%202.html
|
||||
* @var string
|
||||
*/
|
||||
const OSTATUS = 'http://ostatus.org/schema/1.0';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const STATUSNET = 'http://status.net/schema/api/1/';
|
||||
/**
|
||||
* This namespace describes the Atom Activity Streams in RDF Vocabulary (AAIR),
|
||||
* defined as a dictionary of named properties and classes using W3C's RDF technology,
|
||||
* and specifically a mapping of the Atom Activity Streams work to RDF.
|
||||
*
|
||||
* @see http://xmlns.notu.be/aair/#RFC4287
|
||||
* @var string
|
||||
*/
|
||||
const ATOM1 = 'http://www.w3.org/2005/Atom';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
const MASTODON = 'http://mastodon.social/schema/1.0';
|
||||
}
|
||||
@@ -4,20 +4,21 @@
|
||||
*/
|
||||
namespace Friendica\Protocol\ActivityPub;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Event;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Mail;
|
||||
use Friendica\Model\Term;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Model\Mail;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\JsonLD;
|
||||
@@ -167,15 +168,15 @@ class Processor
|
||||
public static function createItem($activity)
|
||||
{
|
||||
$item = [];
|
||||
$item['verb'] = ACTIVITY_POST;
|
||||
$item['verb'] = Activity::POST;
|
||||
$item['thr-parent'] = $activity['reply-to-id'];
|
||||
|
||||
if ($activity['reply-to-id'] == $activity['id']) {
|
||||
$item['gravity'] = GRAVITY_PARENT;
|
||||
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||
$item['object-type'] = Activity\ObjectType::NOTE;
|
||||
} else {
|
||||
$item['gravity'] = GRAVITY_COMMENT;
|
||||
$item['object-type'] = ACTIVITY_OBJ_COMMENT;
|
||||
$item['object-type'] = Activity\ObjectType::COMMENT;
|
||||
}
|
||||
|
||||
if (empty($activity['directmessage']) && ($activity['id'] != $activity['reply-to-id']) && !Item::exists(['uri' => $activity['reply-to-id']])) {
|
||||
@@ -254,7 +255,7 @@ class Processor
|
||||
$item['verb'] = $verb;
|
||||
$item['thr-parent'] = $activity['object_id'];
|
||||
$item['gravity'] = GRAVITY_ACTIVITY;
|
||||
$item['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||
$item['object-type'] = Activity\ObjectType::NOTE;
|
||||
|
||||
$item['diaspora_signed_text'] = $activity['diaspora:like'] ?? '';
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use Friendica\Model\APContact;
|
||||
use Friendica\Model\Conversation;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
@@ -400,26 +401,26 @@ class Receiver
|
||||
$announce_object_data['object_id'] = $object_data['object_id'];
|
||||
$announce_object_data['object_type'] = $object_data['object_type'];
|
||||
|
||||
ActivityPub\Processor::createActivity($announce_object_data, ACTIVITY2_ANNOUNCE);
|
||||
ActivityPub\Processor::createActivity($announce_object_data, Activity::ANNOUNCE);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'as:Like':
|
||||
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||
ActivityPub\Processor::createActivity($object_data, ACTIVITY_LIKE);
|
||||
ActivityPub\Processor::createActivity($object_data, Activity::LIKE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'as:Dislike':
|
||||
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||
ActivityPub\Processor::createActivity($object_data, ACTIVITY_DISLIKE);
|
||||
ActivityPub\Processor::createActivity($object_data, Activity::DISLIKE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'as:TentativeAccept':
|
||||
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||
ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDMAYBE);
|
||||
ActivityPub\Processor::createActivity($object_data, Activity::ATTENDMAYBE);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -444,7 +445,7 @@ class Receiver
|
||||
ActivityPub\Processor::followUser($object_data);
|
||||
} elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||
$object_data['reply-to-id'] = $object_data['object_id'];
|
||||
ActivityPub\Processor::createActivity($object_data, ACTIVITY_FOLLOW);
|
||||
ActivityPub\Processor::createActivity($object_data, Activity::FOLLOW);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -452,7 +453,7 @@ class Receiver
|
||||
if ($object_data['object_type'] == 'as:Follow') {
|
||||
ActivityPub\Processor::acceptFollowUser($object_data);
|
||||
} elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||
ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTEND);
|
||||
ActivityPub\Processor::createActivity($object_data, Activity::ATTEND);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -460,7 +461,7 @@ class Receiver
|
||||
if ($object_data['object_type'] == 'as:Follow') {
|
||||
ActivityPub\Processor::rejectFollowUser($object_data);
|
||||
} elseif (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
|
||||
ActivityPub\Processor::createActivity($object_data, ACTIVITY_ATTENDNO);
|
||||
ActivityPub\Processor::createActivity($object_data, Activity::ATTENDNO);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ use Friendica\Database\DBA;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Util\HTTPSignature;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Model\Conversation;
|
||||
@@ -761,25 +762,25 @@ class Transmitter
|
||||
|
||||
if ($reshared) {
|
||||
$type = 'Announce';
|
||||
} elseif ($item['verb'] == ACTIVITY_POST) {
|
||||
} elseif ($item['verb'] == Activity::POST) {
|
||||
if ($item['created'] == $item['edited']) {
|
||||
$type = 'Create';
|
||||
} else {
|
||||
$type = 'Update';
|
||||
}
|
||||
} elseif ($item['verb'] == ACTIVITY_LIKE) {
|
||||
} elseif ($item['verb'] == Activity::LIKE) {
|
||||
$type = 'Like';
|
||||
} elseif ($item['verb'] == ACTIVITY_DISLIKE) {
|
||||
} elseif ($item['verb'] == Activity::DISLIKE) {
|
||||
$type = 'Dislike';
|
||||
} elseif ($item['verb'] == ACTIVITY_ATTEND) {
|
||||
} elseif ($item['verb'] == Activity::ATTEND) {
|
||||
$type = 'Accept';
|
||||
} elseif ($item['verb'] == ACTIVITY_ATTENDNO) {
|
||||
} elseif ($item['verb'] == Activity::ATTENDNO) {
|
||||
$type = 'Reject';
|
||||
} elseif ($item['verb'] == ACTIVITY_ATTENDMAYBE) {
|
||||
} elseif ($item['verb'] == Activity::ATTENDMAYBE) {
|
||||
$type = 'TentativeAccept';
|
||||
} elseif ($item['verb'] == ACTIVITY_FOLLOW) {
|
||||
} elseif ($item['verb'] == Activity::FOLLOW) {
|
||||
$type = 'Follow';
|
||||
} elseif ($item['verb'] == ACTIVITY_TAG) {
|
||||
} elseif ($item['verb'] == Activity::TAG) {
|
||||
$type = 'Add';
|
||||
} else {
|
||||
$type = '';
|
||||
@@ -1571,7 +1572,7 @@ class Transmitter
|
||||
$uid = $first_user['uid'];
|
||||
}
|
||||
|
||||
$condition = ['verb' => ACTIVITY_FOLLOW, 'uid' => 0, 'parent-uri' => $object,
|
||||
$condition = ['verb' => Activity::FOLLOW, 'uid' => 0, 'parent-uri' => $object,
|
||||
'author-id' => Contact::getPublicIdByUserId($uid)];
|
||||
if (Item::exists($condition)) {
|
||||
Logger::log('Follow for ' . $object . ' for user ' . $uid . ' does already exist.', Logger::DEBUG);
|
||||
|
||||
@@ -10,8 +10,8 @@ namespace Friendica\Protocol;
|
||||
|
||||
use DOMDocument;
|
||||
use DOMXPath;
|
||||
use Friendica\App;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Content\OEmbed;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
@@ -20,7 +20,6 @@ use Friendica\Core\Hook;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Conversation;
|
||||
@@ -33,6 +32,7 @@ use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
@@ -381,18 +381,18 @@ class DFRN
|
||||
$type = 'html';
|
||||
|
||||
if ($conversation) {
|
||||
$root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
|
||||
$root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
|
||||
$doc->appendChild($root);
|
||||
|
||||
$root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$root->setAttribute("xmlns:at", NAMESPACE_TOMB);
|
||||
$root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$root->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
|
||||
$root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
$root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
|
||||
$root->setAttribute("xmlns:at", ActivityNamespace::TOMB);
|
||||
$root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
|
||||
$root->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
|
||||
$root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
|
||||
$root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
|
||||
$root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
|
||||
$root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
|
||||
|
||||
//$root = self::addHeader($doc, $owner, "dfrn:owner", "", false);
|
||||
|
||||
@@ -556,18 +556,18 @@ class DFRN
|
||||
$alternatelink = $owner['url'];
|
||||
}
|
||||
|
||||
$root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
|
||||
$root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
|
||||
$doc->appendChild($root);
|
||||
|
||||
$root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$root->setAttribute("xmlns:at", NAMESPACE_TOMB);
|
||||
$root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$root->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
|
||||
$root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
$root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
|
||||
$root->setAttribute("xmlns:at", ActivityNamespace::TOMB);
|
||||
$root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
|
||||
$root->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
|
||||
$root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
|
||||
$root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
|
||||
$root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
|
||||
$root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
|
||||
|
||||
XML::addElement($doc, $root, "id", System::baseUrl()."/profile/".$owner["nick"]);
|
||||
XML::addElement($doc, $root, "title", $owner["name"]);
|
||||
@@ -940,18 +940,18 @@ class DFRN
|
||||
if (!$single) {
|
||||
$entry = $doc->createElement("entry");
|
||||
} else {
|
||||
$entry = $doc->createElementNS(NAMESPACE_ATOM1, 'entry');
|
||||
$entry = $doc->createElementNS(ActivityNamespace::ATOM1, 'entry');
|
||||
$doc->appendChild($entry);
|
||||
|
||||
$entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$entry->setAttribute("xmlns:at", NAMESPACE_TOMB);
|
||||
$entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$entry->setAttribute("xmlns:dfrn", NAMESPACE_DFRN);
|
||||
$entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
$entry->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
|
||||
$entry->setAttribute("xmlns:at", ActivityNamespace::TOMB);
|
||||
$entry->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
|
||||
$entry->setAttribute("xmlns:dfrn", ActivityNamespace::DFRN);
|
||||
$entry->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
|
||||
$entry->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
|
||||
$entry->setAttribute("xmlns:poco", ActivityNamespace::POCO);
|
||||
$entry->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
|
||||
$entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
|
||||
}
|
||||
|
||||
if ($item['private']) {
|
||||
@@ -1078,9 +1078,9 @@ class DFRN
|
||||
if ($item['object-type'] != "") {
|
||||
XML::addElement($doc, $entry, "activity:object-type", $item['object-type']);
|
||||
} elseif ($item['id'] == $item['parent']) {
|
||||
XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
|
||||
XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE);
|
||||
} else {
|
||||
XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_COMMENT);
|
||||
XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::COMMENT);
|
||||
}
|
||||
|
||||
$actobj = self::createActivity($doc, "activity:object", $item['object']);
|
||||
@@ -1123,7 +1123,7 @@ class DFRN
|
||||
"link",
|
||||
"",
|
||||
["rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_GROUP,
|
||||
"ostatus:object-type" => Activity\ObjectType::GROUP,
|
||||
"href" => $mention]
|
||||
);
|
||||
} else {
|
||||
@@ -1133,7 +1133,7 @@ class DFRN
|
||||
"link",
|
||||
"",
|
||||
["rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_PERSON,
|
||||
"ostatus:object-type" => Activity\ObjectType::PERSON,
|
||||
"href" => $mention]
|
||||
);
|
||||
}
|
||||
@@ -1749,7 +1749,7 @@ class DFRN
|
||||
$obj_doc = new DOMDocument("1.0", "utf-8");
|
||||
$obj_doc->formatOutput = true;
|
||||
|
||||
$obj_element = $obj_doc->createElementNS(NAMESPACE_ATOM1, $element);
|
||||
$obj_element = $obj_doc->createElementNS( ActivityNamespace::ATOM1, $element);
|
||||
|
||||
$activity_type = $xpath->query("activity:object-type/text()", $activity)->item(0)->nodeValue;
|
||||
XML::addElement($obj_doc, $obj_element, "type", $activity_type);
|
||||
@@ -1906,7 +1906,7 @@ class DFRN
|
||||
'source_name' => $importer['name'],
|
||||
'source_link' => $importer['url'],
|
||||
'source_photo' => $importer['photo'],
|
||||
'verb' => ACTIVITY_REQ_FRIEND,
|
||||
'verb' => Activity::REQ_FRIEND,
|
||||
'otype' => 'intro']
|
||||
);
|
||||
|
||||
@@ -2116,7 +2116,7 @@ class DFRN
|
||||
}
|
||||
$xo = XML::parseString($item["object"], false);
|
||||
|
||||
if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) {
|
||||
if (($xo->type == Activity\ObjectType::PERSON) && ($xo->id)) {
|
||||
// somebody was poked/prodded. Was it me?
|
||||
$Blink = '';
|
||||
foreach ($xo->link as $l) {
|
||||
@@ -2180,34 +2180,37 @@ class DFRN
|
||||
// The functions below are partly used by ostatus.php as well - where we have this variable
|
||||
$contact = Contact::selectFirst([], ['id' => $importer['id']]);
|
||||
|
||||
/** @var Activity $activity */
|
||||
$activity = BaseObject::getClass(Activity::class);
|
||||
|
||||
// Big question: Do we need these functions? They were part of the "consume_feed" function.
|
||||
// This function once was responsible for DFRN and OStatus.
|
||||
if (activity_match($item["verb"], ACTIVITY_FOLLOW)) {
|
||||
if ($activity->match($item["verb"], Activity::FOLLOW)) {
|
||||
Logger::log("New follower");
|
||||
Contact::addRelationship($importer, $contact, $item);
|
||||
return false;
|
||||
}
|
||||
if (activity_match($item["verb"], ACTIVITY_UNFOLLOW)) {
|
||||
if ($activity->match($item["verb"], Activity::UNFOLLOW)) {
|
||||
Logger::log("Lost follower");
|
||||
Contact::removeFollower($importer, $contact, $item);
|
||||
return false;
|
||||
}
|
||||
if (activity_match($item["verb"], ACTIVITY_REQ_FRIEND)) {
|
||||
if ($activity->match($item["verb"], Activity::REQ_FRIEND)) {
|
||||
Logger::log("New friend request");
|
||||
Contact::addRelationship($importer, $contact, $item, true);
|
||||
return false;
|
||||
}
|
||||
if (activity_match($item["verb"], ACTIVITY_UNFRIEND)) {
|
||||
if ($activity->match($item["verb"], Activity::UNFRIEND)) {
|
||||
Logger::log("Lost sharer");
|
||||
Contact::removeSharer($importer, $contact, $item);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (($item["verb"] == ACTIVITY_LIKE)
|
||||
|| ($item["verb"] == ACTIVITY_DISLIKE)
|
||||
|| ($item["verb"] == ACTIVITY_ATTEND)
|
||||
|| ($item["verb"] == ACTIVITY_ATTENDNO)
|
||||
|| ($item["verb"] == ACTIVITY_ATTENDMAYBE)
|
||||
if (($item["verb"] == Activity::LIKE)
|
||||
|| ($item["verb"] == Activity::DISLIKE)
|
||||
|| ($item["verb"] == Activity::ATTEND)
|
||||
|| ($item["verb"] == Activity::ATTENDNO)
|
||||
|| ($item["verb"] == Activity::ATTENDMAYBE)
|
||||
) {
|
||||
$is_like = true;
|
||||
$item["gravity"] = GRAVITY_ACTIVITY;
|
||||
@@ -2234,11 +2237,11 @@ class DFRN
|
||||
$is_like = false;
|
||||
}
|
||||
|
||||
if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) {
|
||||
if (($item["verb"] == Activity::TAG) && ($item["object-type"] == Activity\ObjectType::TAGTERM)) {
|
||||
$xo = XML::parseString($item["object"], false);
|
||||
$xt = XML::parseString($item["target"], false);
|
||||
|
||||
if ($xt->type == ACTIVITY_OBJ_NOTE) {
|
||||
if ($xt->type == Activity\ObjectType::NOTE) {
|
||||
$item_tag = Item::selectFirst(['id', 'tag'], ['uri' => $xt->id, 'uid' => $importer["importer_uid"]]);
|
||||
|
||||
if (!DBA::isResult($item_tag)) {
|
||||
@@ -2513,7 +2516,7 @@ class DFRN
|
||||
// Now assign the rest of the values that depend on the type of the message
|
||||
if (in_array($entrytype, [DFRN::REPLY, DFRN::REPLY_RC])) {
|
||||
if (!isset($item["object-type"])) {
|
||||
$item["object-type"] = ACTIVITY_OBJ_COMMENT;
|
||||
$item["object-type"] = Activity\ObjectType::COMMENT;
|
||||
}
|
||||
|
||||
if ($item["contact-id"] != $owner["contact-id"]) {
|
||||
@@ -2537,11 +2540,11 @@ class DFRN
|
||||
$item["wall"] = 1;
|
||||
} elseif ($entrytype == DFRN::TOP_LEVEL) {
|
||||
if (!isset($item["object-type"])) {
|
||||
$item["object-type"] = ACTIVITY_OBJ_NOTE;
|
||||
$item["object-type"] = Activity\ObjectType::NOTE;
|
||||
}
|
||||
|
||||
// Is it an event?
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_EVENT) && !$owner_unknown) {
|
||||
if (($item["object-type"] == Activity\ObjectType::EVENT) && !$owner_unknown) {
|
||||
Logger::log("Item ".$item["uri"]." seems to contain an event.", Logger::DEBUG);
|
||||
$ev = Event::fromBBCode($item["body"]);
|
||||
if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
|
||||
@@ -2638,7 +2641,7 @@ class DFRN
|
||||
Item::distribute($posted_id);
|
||||
}
|
||||
|
||||
if (stristr($item["verb"], ACTIVITY_POKE)) {
|
||||
if (stristr($item["verb"], Activity::POKE)) {
|
||||
$item['id'] = $posted_id;
|
||||
self::doPoke($item, $importer);
|
||||
}
|
||||
@@ -2727,16 +2730,16 @@ class DFRN
|
||||
@$doc->loadXML($xml);
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
$xpath->registerNamespace("atom", NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace("thr", NAMESPACE_THREAD);
|
||||
$xpath->registerNamespace("at", NAMESPACE_TOMB);
|
||||
$xpath->registerNamespace("media", NAMESPACE_MEDIA);
|
||||
$xpath->registerNamespace("dfrn", NAMESPACE_DFRN);
|
||||
$xpath->registerNamespace("activity", NAMESPACE_ACTIVITY);
|
||||
$xpath->registerNamespace("georss", NAMESPACE_GEORSS);
|
||||
$xpath->registerNamespace("poco", NAMESPACE_POCO);
|
||||
$xpath->registerNamespace("ostatus", NAMESPACE_OSTATUS);
|
||||
$xpath->registerNamespace("statusnet", NAMESPACE_STATUSNET);
|
||||
$xpath->registerNamespace("atom", ActivityNamespace::ATOM1);
|
||||
$xpath->registerNamespace("thr", ActivityNamespace::THREAD);
|
||||
$xpath->registerNamespace("at", ActivityNamespace::TOMB);
|
||||
$xpath->registerNamespace("media", ActivityNamespace::MEDIA);
|
||||
$xpath->registerNamespace("dfrn", ActivityNamespace::DFRN);
|
||||
$xpath->registerNamespace("activity", ActivityNamespace::ACTIVITY);
|
||||
$xpath->registerNamespace("georss", ActivityNamespace::GEORSS);
|
||||
$xpath->registerNamespace("poco", ActivityNamespace::POCO);
|
||||
$xpath->registerNamespace("ostatus", ActivityNamespace::OSTATUS);
|
||||
$xpath->registerNamespace("statusnet", ActivityNamespace::STATUSNET);
|
||||
|
||||
$header = [];
|
||||
$header["uid"] = $importer["importer_uid"];
|
||||
@@ -2861,7 +2864,7 @@ class DFRN
|
||||
if ($item['verb']) {
|
||||
return $item['verb'];
|
||||
}
|
||||
return ACTIVITY_POST;
|
||||
return Activity::POST;
|
||||
}
|
||||
|
||||
private static function tgroupCheck($uid, $item)
|
||||
|
||||
@@ -32,6 +32,7 @@ use Friendica\Model\Mail;
|
||||
use Friendica\Model\Profile;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Util\Crypto;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Map;
|
||||
@@ -465,7 +466,7 @@ class Diaspora
|
||||
}
|
||||
}
|
||||
|
||||
$base = $basedom->children(NAMESPACE_SALMON_ME);
|
||||
$base = $basedom->children(ActivityNamespace::SALMON_ME);
|
||||
|
||||
// Not sure if this cleaning is needed
|
||||
$data = str_replace([" ", "\t", "\r", "\n"], ["", "", "", ""], $base->data);
|
||||
@@ -577,7 +578,7 @@ class Diaspora
|
||||
$author_link = str_replace('acct:', '', $idom->author_id);
|
||||
}
|
||||
|
||||
$dom = $basedom->children(NAMESPACE_SALMON_ME);
|
||||
$dom = $basedom->children(ActivityNamespace::SALMON_ME);
|
||||
|
||||
// figure out where in the DOM tree our data is hiding
|
||||
|
||||
@@ -1845,7 +1846,7 @@ class Diaspora
|
||||
$datarray["guid"] = $guid;
|
||||
$datarray["uri"] = self::getUriFromGuid($author, $guid);
|
||||
|
||||
$datarray["verb"] = ACTIVITY_POST;
|
||||
$datarray["verb"] = Activity::POST;
|
||||
$datarray["gravity"] = GRAVITY_COMMENT;
|
||||
|
||||
if ($thr_uri != "") {
|
||||
@@ -1854,7 +1855,7 @@ class Diaspora
|
||||
$datarray["parent-uri"] = $parent_item["uri"];
|
||||
}
|
||||
|
||||
$datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
|
||||
$datarray["object-type"] = Activity\ObjectType::COMMENT;
|
||||
|
||||
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
|
||||
$datarray["source"] = $xml;
|
||||
@@ -2062,9 +2063,9 @@ class Diaspora
|
||||
// "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
|
||||
// We would accept this anyhow.
|
||||
if ($positive == "true") {
|
||||
$verb = ACTIVITY_LIKE;
|
||||
$verb = Activity::LIKE;
|
||||
} else {
|
||||
$verb = ACTIVITY_DISLIKE;
|
||||
$verb = Activity::DISLIKE;
|
||||
}
|
||||
|
||||
$datarray = [];
|
||||
@@ -2085,7 +2086,7 @@ class Diaspora
|
||||
$datarray["gravity"] = GRAVITY_ACTIVITY;
|
||||
$datarray["parent-uri"] = $parent_item["uri"];
|
||||
|
||||
$datarray["object-type"] = ACTIVITY_OBJ_NOTE;
|
||||
$datarray["object-type"] = Activity\ObjectType::NOTE;
|
||||
|
||||
$datarray["body"] = $verb;
|
||||
|
||||
@@ -2684,9 +2685,9 @@ class Diaspora
|
||||
$datarray['uri'] = self::getUriFromGuid($author, $datarray['guid']);
|
||||
$datarray['parent-uri'] = $parent['uri'];
|
||||
|
||||
$datarray['verb'] = $datarray['body'] = ACTIVITY2_ANNOUNCE;
|
||||
$datarray['verb'] = $datarray['body'] = Activity::ANNOUNCE;
|
||||
$datarray['gravity'] = GRAVITY_ACTIVITY;
|
||||
$datarray['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||
$datarray['object-type'] = Activity\ObjectType::NOTE;
|
||||
|
||||
$datarray['protocol'] = $item['protocol'];
|
||||
|
||||
@@ -2757,7 +2758,7 @@ class Diaspora
|
||||
$datarray["guid"] = $guid;
|
||||
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
|
||||
|
||||
$datarray["verb"] = ACTIVITY_POST;
|
||||
$datarray["verb"] = Activity::POST;
|
||||
$datarray["gravity"] = GRAVITY_PARENT;
|
||||
|
||||
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
|
||||
@@ -2962,9 +2963,9 @@ class Diaspora
|
||||
XML::unescape($photo->remote_photo_name)."[/img]\n".$body;
|
||||
}
|
||||
|
||||
$datarray["object-type"] = ACTIVITY_OBJ_IMAGE;
|
||||
$datarray["object-type"] = Activity\ObjectType::IMAGE;
|
||||
} else {
|
||||
$datarray["object-type"] = ACTIVITY_OBJ_NOTE;
|
||||
$datarray["object-type"] = Activity\ObjectType::NOTE;
|
||||
|
||||
// Add OEmbed and other information to the body
|
||||
if (!self::isRedmatrix($contact["url"])) {
|
||||
@@ -2994,7 +2995,7 @@ class Diaspora
|
||||
$datarray["guid"] = $guid;
|
||||
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
|
||||
|
||||
$datarray["verb"] = ACTIVITY_POST;
|
||||
$datarray["verb"] = Activity::POST;
|
||||
$datarray["gravity"] = GRAVITY_PARENT;
|
||||
|
||||
$datarray["protocol"] = Conversation::PARCEL_DIASPORA;
|
||||
@@ -3780,9 +3781,9 @@ class Diaspora
|
||||
|
||||
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
|
||||
$positive = null;
|
||||
if ($item['verb'] === ACTIVITY_LIKE) {
|
||||
if ($item['verb'] === Activity::LIKE) {
|
||||
$positive = "true";
|
||||
} elseif ($item['verb'] === ACTIVITY_DISLIKE) {
|
||||
} elseif ($item['verb'] === Activity::DISLIKE) {
|
||||
$positive = "false";
|
||||
}
|
||||
|
||||
@@ -3811,13 +3812,13 @@ class Diaspora
|
||||
}
|
||||
|
||||
switch ($item['verb']) {
|
||||
case ACTIVITY_ATTEND:
|
||||
case Activity::ATTEND:
|
||||
$attend_answer = 'accepted';
|
||||
break;
|
||||
case ACTIVITY_ATTENDNO:
|
||||
case Activity::ATTENDNO:
|
||||
$attend_answer = 'declined';
|
||||
break;
|
||||
case ACTIVITY_ATTENDMAYBE:
|
||||
case Activity::ATTENDMAYBE:
|
||||
$attend_answer = 'tentative';
|
||||
break;
|
||||
default:
|
||||
@@ -3913,13 +3914,13 @@ class Diaspora
|
||||
*/
|
||||
public static function sendFollowup(array $item, array $owner, array $contact, $public_batch = false)
|
||||
{
|
||||
if (in_array($item['verb'], [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE])) {
|
||||
if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
|
||||
$message = self::constructAttend($item, $owner);
|
||||
$type = "event_participation";
|
||||
} elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
||||
} elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
|
||||
$message = self::constructLike($item, $owner);
|
||||
$type = "like";
|
||||
} elseif (!in_array($item["verb"], [ACTIVITY_FOLLOW, ACTIVITY_TAG])) {
|
||||
} elseif (!in_array($item["verb"], [Activity::FOLLOW, Activity::TAG])) {
|
||||
$message = self::constructComment($item, $owner);
|
||||
$type = "comment";
|
||||
}
|
||||
@@ -3948,7 +3949,7 @@ class Diaspora
|
||||
$message = ["author" => $item['signer'],
|
||||
"target_guid" => $signed_parts[0],
|
||||
"target_type" => $signed_parts[1]];
|
||||
} elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
||||
} elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
|
||||
$message = ["author" => $signed_parts[4],
|
||||
"guid" => $signed_parts[1],
|
||||
"parent_guid" => $signed_parts[3],
|
||||
@@ -3993,7 +3994,7 @@ class Diaspora
|
||||
{
|
||||
if ($item["deleted"]) {
|
||||
return self::sendRetraction($item, $owner, $contact, $public_batch, true);
|
||||
} elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
||||
} elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
|
||||
$type = "like";
|
||||
} else {
|
||||
$type = "comment";
|
||||
@@ -4054,7 +4055,7 @@ class Diaspora
|
||||
|
||||
if ($item['id'] == $item['parent']) {
|
||||
$target_type = "Post";
|
||||
} elseif (in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
||||
} elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
|
||||
$target_type = "Like";
|
||||
} else {
|
||||
$target_type = "Comment";
|
||||
@@ -4320,7 +4321,7 @@ class Diaspora
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
||||
if (!in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\XML;
|
||||
|
||||
@@ -59,13 +60,13 @@ class Feed {
|
||||
$doc = new DOMDocument();
|
||||
@$doc->loadXML(trim($xml));
|
||||
$xpath = new DOMXPath($doc);
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
|
||||
$xpath->registerNamespace('dc', "http://purl.org/dc/elements/1.1/");
|
||||
$xpath->registerNamespace('content', "http://purl.org/rss/1.0/modules/content/");
|
||||
$xpath->registerNamespace('rdf', "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
|
||||
$xpath->registerNamespace('rss', "http://purl.org/rss/1.0/");
|
||||
$xpath->registerNamespace('media', "http://search.yahoo.com/mrss/");
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
$xpath->registerNamespace('poco', ActivityNamespace::POCO);
|
||||
|
||||
$author = [];
|
||||
$entries = null;
|
||||
@@ -198,8 +199,8 @@ class Feed {
|
||||
$header["origin"] = 0;
|
||||
$header["gravity"] = GRAVITY_PARENT;
|
||||
$header["private"] = 2;
|
||||
$header["verb"] = ACTIVITY_POST;
|
||||
$header["object-type"] = ACTIVITY_OBJ_NOTE;
|
||||
$header["verb"] = Activity::POST;
|
||||
$header["object-type"] = Activity\ObjectType::NOTE;
|
||||
|
||||
$header["contact-id"] = $contact["id"];
|
||||
|
||||
@@ -420,7 +421,7 @@ class Feed {
|
||||
$item["title"] = "";
|
||||
$item["body"] = $item["body"].add_page_info($item["plink"], false, $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
|
||||
$item["tag"] = add_page_keywords($item["plink"], $preview, ($contact["fetch_further_information"] == 2), $contact["ffi_keyword_blacklist"]);
|
||||
$item["object-type"] = ACTIVITY_OBJ_BOOKMARK;
|
||||
$item["object-type"] = Activity\ObjectType::BOOKMARK;
|
||||
unset($item["attach"]);
|
||||
} else {
|
||||
if (!empty($summary)) {
|
||||
|
||||
@@ -10,21 +10,22 @@ use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Content\Text\HTML;
|
||||
use Friendica\Core\Cache;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Lock;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Conversation;
|
||||
use Friendica\Model\GContact;
|
||||
use Friendica\Model\APContact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Protocol\ActivityNamespace;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Network;
|
||||
use Friendica\Util\Proxy as ProxyUtils;
|
||||
@@ -261,14 +262,14 @@ class OStatus
|
||||
@$doc->loadXML($xml);
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
|
||||
$xpath->registerNamespace('georss', NAMESPACE_GEORSS);
|
||||
$xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
|
||||
$xpath->registerNamespace('media', NAMESPACE_MEDIA);
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
|
||||
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
|
||||
$xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
|
||||
$xpath->registerNamespace('thr', ActivityNamespace::THREAD);
|
||||
$xpath->registerNamespace('georss', ActivityNamespace::GEORSS);
|
||||
$xpath->registerNamespace('activity', ActivityNamespace::ACTIVITY);
|
||||
$xpath->registerNamespace('media', ActivityNamespace::MEDIA);
|
||||
$xpath->registerNamespace('poco', ActivityNamespace::POCO);
|
||||
$xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
|
||||
$xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
|
||||
|
||||
$contact = ["id" => 0];
|
||||
|
||||
@@ -342,14 +343,14 @@ class OStatus
|
||||
@$doc->loadXML($xml);
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
|
||||
$xpath->registerNamespace('georss', NAMESPACE_GEORSS);
|
||||
$xpath->registerNamespace('activity', NAMESPACE_ACTIVITY);
|
||||
$xpath->registerNamespace('media', NAMESPACE_MEDIA);
|
||||
$xpath->registerNamespace('poco', NAMESPACE_POCO);
|
||||
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
|
||||
$xpath->registerNamespace('statusnet', NAMESPACE_STATUSNET);
|
||||
$xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
|
||||
$xpath->registerNamespace('thr', ActivityNamespace::THREAD);
|
||||
$xpath->registerNamespace('georss', ActivityNamespace::GEORSS);
|
||||
$xpath->registerNamespace('activity', ActivityNamespace::ACTIVITY);
|
||||
$xpath->registerNamespace('media', ActivityNamespace::MEDIA);
|
||||
$xpath->registerNamespace('poco', ActivityNamespace::POCO);
|
||||
$xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
|
||||
$xpath->registerNamespace('statusnet', ActivityNamespace::STATUSNET);
|
||||
|
||||
$hub = "";
|
||||
$hub_items = $xpath->query("/atom:feed/atom:link[@rel='hub']")->item(0);
|
||||
@@ -428,12 +429,12 @@ class OStatus
|
||||
$item["verb"] = XML::getFirstNodeValue($xpath, 'activity:verb/text()', $entry);
|
||||
|
||||
// Delete a message
|
||||
if (in_array($item["verb"], ['qvitter-delete-notice', ACTIVITY_DELETE, 'delete'])) {
|
||||
if (in_array($item["verb"], ['qvitter-delete-notice', Activity::DELETE, 'delete'])) {
|
||||
self::deleteNotice($item);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (in_array($item["verb"], [NAMESPACE_OSTATUS."/unfavorite", ACTIVITY_UNFAVORITE])) {
|
||||
if (in_array($item["verb"], [Activity::O_UNFAVOURITE, Activity::UNFAVORITE])) {
|
||||
// Ignore "Unfavorite" message
|
||||
Logger::log("Ignore unfavorite message ".print_r($item, true), Logger::DEBUG);
|
||||
continue;
|
||||
@@ -447,7 +448,7 @@ class OStatus
|
||||
Logger::log('Processing post with URI '.$item["uri"].' for user '.$importer["uid"].'.', Logger::DEBUG);
|
||||
}
|
||||
|
||||
if ($item["verb"] == ACTIVITY_JOIN) {
|
||||
if ($item["verb"] == Activity::JOIN) {
|
||||
// ignore "Join" messages
|
||||
Logger::log("Ignore join message ".print_r($item, true), Logger::DEBUG);
|
||||
continue;
|
||||
@@ -459,29 +460,29 @@ class OStatus
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item["verb"] == ACTIVITY_FOLLOW) {
|
||||
if ($item["verb"] == Activity::FOLLOW) {
|
||||
Contact::addRelationship($importer, $contact, $item);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item["verb"] == NAMESPACE_OSTATUS."/unfollow") {
|
||||
if ($item["verb"] == Activity::O_UNFOLLOW) {
|
||||
$dummy = null;
|
||||
Contact::removeFollower($importer, $contact, $item, $dummy);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($item["verb"] == ACTIVITY_FAVORITE) {
|
||||
if ($item["verb"] == Activity::FAVORITE) {
|
||||
$orig_uri = $xpath->query("activity:object/atom:id", $entry)->item(0)->nodeValue;
|
||||
Logger::log("Favorite ".$orig_uri." ".print_r($item, true));
|
||||
|
||||
$item["verb"] = ACTIVITY_LIKE;
|
||||
$item["verb"] = Activity::LIKE;
|
||||
$item["parent-uri"] = $orig_uri;
|
||||
$item["gravity"] = GRAVITY_ACTIVITY;
|
||||
$item["object-type"] = ACTIVITY_OBJ_NOTE;
|
||||
$item["object-type"] = Activity\ObjectType::NOTE;
|
||||
}
|
||||
|
||||
// http://activitystrea.ms/schema/1.0/rsvp-yes
|
||||
if (!in_array($item["verb"], [ACTIVITY_POST, ACTIVITY_LIKE, ACTIVITY_SHARE])) {
|
||||
if (!in_array($item["verb"], [Activity::POST, Activity::LIKE, Activity::SHARE])) {
|
||||
Logger::log("Unhandled verb ".$item["verb"]." ".print_r($item, true), Logger::DEBUG);
|
||||
}
|
||||
|
||||
@@ -504,7 +505,7 @@ class OStatus
|
||||
if ($valid) {
|
||||
// Never post a thread when the only interaction by our contact was a like
|
||||
$valid = false;
|
||||
$verbs = [ACTIVITY_POST, ACTIVITY_SHARE];
|
||||
$verbs = [Activity::POST, Activity::SHARE];
|
||||
foreach (self::$itemlist as $item) {
|
||||
if (in_array($item['verb'], $verbs) && Contact::isSharingByURL($item['author-link'], $item['uid'])) {
|
||||
$valid = true;
|
||||
@@ -592,10 +593,10 @@ class OStatus
|
||||
{
|
||||
$item["body"] = HTML::toBBCode(XML::getFirstNodeValue($xpath, 'atom:content/text()', $entry));
|
||||
$item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $entry);
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_BOOKMARK) || ($item["object-type"] == ACTIVITY_OBJ_EVENT)) {
|
||||
if (($item["object-type"] == Activity\ObjectType::BOOKMARK) || ($item["object-type"] == Activity\ObjectType::EVENT)) {
|
||||
$item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
|
||||
$item["body"] = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
|
||||
} elseif ($item["object-type"] == ACTIVITY_OBJ_QUESTION) {
|
||||
} elseif ($item["object-type"] == Activity\ObjectType::QUESTION) {
|
||||
$item["title"] = XML::getFirstNodeValue($xpath, 'atom:title/text()', $entry);
|
||||
}
|
||||
|
||||
@@ -676,7 +677,7 @@ class OStatus
|
||||
}
|
||||
}
|
||||
// Is it a repeated post?
|
||||
if (($repeat_of != "") || ($item["verb"] == ACTIVITY_SHARE)) {
|
||||
if (($repeat_of != "") || ($item["verb"] == Activity::SHARE)) {
|
||||
$link_data = self::processRepeatedItem($xpath, $entry, $item, $importer);
|
||||
if (!empty($link_data['add_body'])) {
|
||||
$add_body .= $link_data['add_body'];
|
||||
@@ -691,7 +692,7 @@ class OStatus
|
||||
}
|
||||
|
||||
// Mastodon Content Warning
|
||||
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
|
||||
if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $entry)) {
|
||||
$clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $entry);
|
||||
if (!empty($clear_text)) {
|
||||
$item['content-warning'] = HTML::toBBCode($clear_text);
|
||||
@@ -803,9 +804,9 @@ class OStatus
|
||||
@$doc->loadXML($xml);
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
$xpath->registerNamespace('atom', NAMESPACE_ATOM1);
|
||||
$xpath->registerNamespace('thr', NAMESPACE_THREAD);
|
||||
$xpath->registerNamespace('ostatus', NAMESPACE_OSTATUS);
|
||||
$xpath->registerNamespace('atom', ActivityNamespace::ATOM1);
|
||||
$xpath->registerNamespace('thr', ActivityNamespace::THREAD);
|
||||
$xpath->registerNamespace('ostatus', ActivityNamespace::OSTATUS);
|
||||
|
||||
$entries = $xpath->query('/atom:feed/atom:entry');
|
||||
|
||||
@@ -1067,7 +1068,7 @@ class OStatus
|
||||
$item["object-type"] = XML::getFirstNodeValue($xpath, 'activity:object-type/text()', $activityobject);
|
||||
|
||||
// Mastodon Content Warning
|
||||
if (($item["verb"] == ACTIVITY_POST) && $xpath->evaluate('boolean(atom:summary)', $activityobject)) {
|
||||
if (($item["verb"] == Activity::POST) && $xpath->evaluate('boolean(atom:summary)', $activityobject)) {
|
||||
$clear_text = XML::getFirstNodeValue($xpath, 'atom:summary/text()', $activityobject);
|
||||
if (!empty($clear_text)) {
|
||||
$item['content-warning'] = HTML::toBBCode($clear_text);
|
||||
@@ -1105,8 +1106,8 @@ class OStatus
|
||||
switch ($attribute['rel']) {
|
||||
case "alternate":
|
||||
$item["plink"] = $attribute['href'];
|
||||
if (($item["object-type"] == ACTIVITY_OBJ_QUESTION)
|
||||
|| ($item["object-type"] == ACTIVITY_OBJ_EVENT)
|
||||
if (($item["object-type"] == Activity\ObjectType::QUESTION)
|
||||
|| ($item["object-type"] == Activity\ObjectType::EVENT)
|
||||
) {
|
||||
$item["body"] .= add_page_info($attribute['href']);
|
||||
}
|
||||
@@ -1135,7 +1136,7 @@ class OStatus
|
||||
}
|
||||
break;
|
||||
case "related":
|
||||
if ($item["object-type"] != ACTIVITY_OBJ_BOOKMARK) {
|
||||
if ($item["object-type"] != Activity\ObjectType::BOOKMARK) {
|
||||
if (!isset($item["parent-uri"])) {
|
||||
$item["parent-uri"] = $attribute['href'];
|
||||
}
|
||||
@@ -1281,17 +1282,17 @@ class OStatus
|
||||
*/
|
||||
private static function addHeader(DOMDocument $doc, array $owner, $filter, $feed_mode = false)
|
||||
{
|
||||
$root = $doc->createElementNS(NAMESPACE_ATOM1, 'feed');
|
||||
$root = $doc->createElementNS(ActivityNamespace::ATOM1, 'feed');
|
||||
$doc->appendChild($root);
|
||||
|
||||
$root->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$root->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$root->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$root->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$root->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$root->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
$root->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
|
||||
$root->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
|
||||
$root->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
|
||||
$root->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
|
||||
$root->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
|
||||
$root->setAttribute("xmlns:poco", ActivityNamespace::POCO);
|
||||
$root->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
|
||||
$root->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
|
||||
$root->setAttribute("xmlns:mastodon", ActivityNamespace::MASTODON);
|
||||
|
||||
$title = '';
|
||||
$selfUri = '/feed/' . $owner["nick"] . '/';
|
||||
@@ -1461,9 +1462,9 @@ class OStatus
|
||||
$author = $doc->createElement("author");
|
||||
XML::addElement($doc, $author, "id", $owner["url"]);
|
||||
if ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY) {
|
||||
XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_GROUP);
|
||||
XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::GROUP);
|
||||
} else {
|
||||
XML::addElement($doc, $author, "activity:object-type", ACTIVITY_OBJ_PERSON);
|
||||
XML::addElement($doc, $author, "activity:object-type", Activity\ObjectType::PERSON);
|
||||
}
|
||||
XML::addElement($doc, $author, "uri", $owner["url"]);
|
||||
XML::addElement($doc, $author, "name", $owner["nick"]);
|
||||
@@ -1544,7 +1545,7 @@ class OStatus
|
||||
return $item['verb'];
|
||||
}
|
||||
|
||||
return ACTIVITY_POST;
|
||||
return Activity::POST;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1556,11 +1557,11 @@ class OStatus
|
||||
*/
|
||||
private static function constructObjecttype(array $item)
|
||||
{
|
||||
if (!empty($item['object-type']) && in_array($item['object-type'], [ACTIVITY_OBJ_NOTE, ACTIVITY_OBJ_COMMENT])) {
|
||||
if (!empty($item['object-type']) && in_array($item['object-type'], [Activity\ObjectType::NOTE, Activity\ObjectType::COMMENT])) {
|
||||
return $item['object-type'];
|
||||
}
|
||||
|
||||
return ACTIVITY_OBJ_NOTE;
|
||||
return Activity\ObjectType::NOTE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1589,9 +1590,9 @@ class OStatus
|
||||
return $xml;
|
||||
}
|
||||
|
||||
if ($item["verb"] == ACTIVITY_LIKE) {
|
||||
if ($item["verb"] == Activity::LIKE) {
|
||||
return self::likeEntry($doc, $item, $owner, $toplevel);
|
||||
} elseif (in_array($item["verb"], [ACTIVITY_FOLLOW, NAMESPACE_OSTATUS."/unfollow"])) {
|
||||
} elseif (in_array($item["verb"], [Activity::FOLLOW, Activity::O_UNFOLLOW])) {
|
||||
return self::followEntry($doc, $item, $owner, $toplevel);
|
||||
} else {
|
||||
return self::noteEntry($doc, $item, $owner, $toplevel, $feed_mode);
|
||||
@@ -1705,11 +1706,11 @@ class OStatus
|
||||
|
||||
$title = $owner["nick"]." repeated a notice by ".$contact["nick"];
|
||||
|
||||
self::entryContent($doc, $entry, $item, $owner, $title, ACTIVITY_SHARE, false);
|
||||
self::entryContent($doc, $entry, $item, $owner, $title, Activity::SHARE, false);
|
||||
|
||||
$as_object = $doc->createElement("activity:object");
|
||||
|
||||
XML::addElement($doc, $as_object, "activity:object-type", NAMESPACE_ACTIVITY_SCHEMA."activity");
|
||||
XML::addElement($doc, $as_object, "activity:object-type", ActivityNamespace::ACTIVITY_SCHEMA . "activity");
|
||||
|
||||
self::entryContent($doc, $as_object, $repeated_item, $owner, "", "", false);
|
||||
|
||||
@@ -1759,7 +1760,7 @@ class OStatus
|
||||
|
||||
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
|
||||
|
||||
$verb = NAMESPACE_ACTIVITY_SCHEMA."favorite";
|
||||
$verb = ActivityNamespace::ACTIVITY_SCHEMA . "favorite";
|
||||
self::entryContent($doc, $entry, $item, $owner, "Favorite", $verb, false);
|
||||
|
||||
$parent = Item::selectFirst([], ['uri' => $item["thr-parent"], 'uid' => $item["uid"]]);
|
||||
@@ -1790,7 +1791,7 @@ class OStatus
|
||||
private static function addPersonObject(DOMDocument $doc, array $owner, array $contact)
|
||||
{
|
||||
$object = $doc->createElement("activity:object");
|
||||
XML::addElement($doc, $object, "activity:object-type", ACTIVITY_OBJ_PERSON);
|
||||
XML::addElement($doc, $object, "activity:object-type", Activity\ObjectType::PERSON);
|
||||
|
||||
if ($contact['network'] == Protocol::PHANTOM) {
|
||||
XML::addElement($doc, $object, "id", $contact['url']);
|
||||
@@ -1858,7 +1859,7 @@ class OStatus
|
||||
$connect_id = 0;
|
||||
}
|
||||
|
||||
if ($item['verb'] == ACTIVITY_FOLLOW) {
|
||||
if ($item['verb'] == Activity::FOLLOW) {
|
||||
$message = L10n::t('%s is now following %s.');
|
||||
$title = L10n::t('following');
|
||||
$action = "subscription";
|
||||
@@ -1918,7 +1919,7 @@ class OStatus
|
||||
|
||||
$entry = self::entryHeader($doc, $owner, $item, $toplevel);
|
||||
|
||||
XML::addElement($doc, $entry, "activity:object-type", ACTIVITY_OBJ_NOTE);
|
||||
XML::addElement($doc, $entry, "activity:object-type", Activity\ObjectType::NOTE);
|
||||
|
||||
self::entryContent($doc, $entry, $item, $owner, $title, '', true, $feed_mode);
|
||||
|
||||
@@ -1950,16 +1951,16 @@ class OStatus
|
||||
$entry->appendChild($author);
|
||||
}
|
||||
} else {
|
||||
$entry = $doc->createElementNS(NAMESPACE_ATOM1, "entry");
|
||||
$entry = $doc->createElementNS(ActivityNamespace::ATOM1, "entry");
|
||||
|
||||
$entry->setAttribute("xmlns:thr", NAMESPACE_THREAD);
|
||||
$entry->setAttribute("xmlns:georss", NAMESPACE_GEORSS);
|
||||
$entry->setAttribute("xmlns:activity", NAMESPACE_ACTIVITY);
|
||||
$entry->setAttribute("xmlns:media", NAMESPACE_MEDIA);
|
||||
$entry->setAttribute("xmlns:poco", NAMESPACE_POCO);
|
||||
$entry->setAttribute("xmlns:ostatus", NAMESPACE_OSTATUS);
|
||||
$entry->setAttribute("xmlns:statusnet", NAMESPACE_STATUSNET);
|
||||
$entry->setAttribute("xmlns:mastodon", NAMESPACE_MASTODON);
|
||||
$entry->setAttribute("xmlns:thr", ActivityNamespace::THREAD);
|
||||
$entry->setAttribute("xmlns:georss", ActivityNamespace::GEORSS);
|
||||
$entry->setAttribute("xmlns:activity", ActivityNamespace::ACTIVITY);
|
||||
$entry->setAttribute("xmlns:media", ActivityNamespace::MEDIA);
|
||||
$entry->setAttribute("xmlns:poco", ActivityNamespace::POCO);
|
||||
$entry->setAttribute("xmlns:ostatus", ActivityNamespace::OSTATUS);
|
||||
$entry->setAttribute("xmlns:statusnet", ActivityNamespace::STATUSNET);
|
||||
$entry->setAttribute("xmlns:mastodon", ActivityNamespace::MASTODON);
|
||||
|
||||
$author = self::addAuthor($doc, $owner);
|
||||
$entry->appendChild($author);
|
||||
@@ -2111,14 +2112,14 @@ class OStatus
|
||||
XML::addElement($doc, $entry, "link", "",
|
||||
[
|
||||
"rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_GROUP,
|
||||
"ostatus:object-type" => Activity\ObjectType::GROUP,
|
||||
"href" => $mention]
|
||||
);
|
||||
} else {
|
||||
XML::addElement($doc, $entry, "link", "",
|
||||
[
|
||||
"rel" => "mentioned",
|
||||
"ostatus:object-type" => ACTIVITY_OBJ_PERSON,
|
||||
"ostatus:object-type" => Activity\ObjectType::PERSON,
|
||||
"href" => $mention]
|
||||
);
|
||||
}
|
||||
@@ -2231,7 +2232,7 @@ class OStatus
|
||||
|
||||
if ($filter === 'comments') {
|
||||
$condition[0] .= " AND `object-type` = ? ";
|
||||
$condition[] = ACTIVITY_OBJ_COMMENT;
|
||||
$condition[] = Activity\ObjectType::COMMENT;
|
||||
}
|
||||
|
||||
if ($owner['account-type'] != User::ACCOUNT_TYPE_COMMUNITY) {
|
||||
|
||||
67
src/Util/ACLFormatter.php
Normal file
67
src/Util/ACLFormatter.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Util;
|
||||
|
||||
use Friendica\Model\Group;
|
||||
|
||||
/**
|
||||
* Util class for ACL formatting
|
||||
*/
|
||||
final class ACLFormatter
|
||||
{
|
||||
/**
|
||||
* Turn user/group ACLs stored as angle bracketed text into arrays
|
||||
*
|
||||
* @param string $ids A angle-bracketed list of IDs
|
||||
*
|
||||
* @return array The array based on the IDs
|
||||
*/
|
||||
public function expand(string $ids)
|
||||
{
|
||||
// turn string array of angle-bracketed elements into numeric array
|
||||
// e.g. "<1><2><3>" => array(1,2,3);
|
||||
preg_match_all('/<(' . Group::FOLLOWERS . '|'. Group::MUTUALS . '|[0-9]+)>/', $ids, $matches, PREG_PATTERN_ORDER);
|
||||
|
||||
return $matches[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap ACL elements in angle brackets for storage
|
||||
*
|
||||
* @param string $item The item to sanitise
|
||||
*/
|
||||
private function sanitize(string &$item) {
|
||||
if (intval($item)) {
|
||||
$item = '<' . intval(Strings::escapeTags(trim($item))) . '>';
|
||||
} elseif (in_array($item, [Group::FOLLOWERS, Group::MUTUALS])) {
|
||||
$item = '<' . $item . '>';
|
||||
} else {
|
||||
$item = '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an ACL array to a storable string
|
||||
*
|
||||
* Normally ACL permissions will be an array.
|
||||
* We'll also allow a comma-separated string.
|
||||
*
|
||||
* @param string|array $permissions
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function toString($permissions) {
|
||||
$return = '';
|
||||
if (is_array($permissions)) {
|
||||
$item = $permissions;
|
||||
} else {
|
||||
$item = explode(',', $permissions);
|
||||
}
|
||||
|
||||
if (is_array($item)) {
|
||||
array_walk($item, [$this, 'sanitize']);
|
||||
$return = implode('', $item);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -148,4 +148,37 @@ class DateTimeFormat
|
||||
|
||||
return $d->format($format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks, if the given string is a date with the pattern YYYY-MM
|
||||
*
|
||||
* @param string $dateString The given date
|
||||
*
|
||||
* @return boolean True, if the date is a valid pattern
|
||||
*/
|
||||
public function isYearMonth(string $dateString)
|
||||
{
|
||||
// Check format (2019-01, 2019-1, 2019-10)
|
||||
if (!preg_match('/^([12]\d{3}-(1[0-2]|0[1-9]|\d))$/', $dateString)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$date = DateTime::createFromFormat('Y-m', $dateString);
|
||||
|
||||
if (!$date) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$now = new DateTime();
|
||||
} catch (\Throwable $t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($date > $now) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
81
src/Util/FileSystem.php
Normal file
81
src/Util/FileSystem.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace Friendica\Util;
|
||||
|
||||
/**
|
||||
* Util class for filesystem manipulation
|
||||
*/
|
||||
final class FileSystem
|
||||
{
|
||||
/**
|
||||
* @var string a error message
|
||||
*/
|
||||
private $errorMessage;
|
||||
|
||||
/**
|
||||
* Creates a directory based on a file, which gets accessed
|
||||
*
|
||||
* @param string $file The file
|
||||
*
|
||||
* @return string The directory name (empty if no directory is found, like urls)
|
||||
*/
|
||||
public function createDir(string $file)
|
||||
{
|
||||
$dirname = null;
|
||||
$pos = strpos($file, '://');
|
||||
|
||||
if (!$pos) {
|
||||
$dirname = realpath(dirname($file));
|
||||
}
|
||||
|
||||
if (substr($file, 0, 7) === 'file://') {
|
||||
$dirname = realpath(dirname(substr($file, 7)));
|
||||
}
|
||||
|
||||
if (isset($dirname) && !is_dir($dirname)) {
|
||||
set_error_handler([$this, 'customErrorHandler']);
|
||||
$status = mkdir($dirname, 0777, true);
|
||||
restore_error_handler();
|
||||
|
||||
if (!$status && !is_dir($dirname)) {
|
||||
throw new \UnexpectedValueException(sprintf('Directory "%s" cannot get created: ' . $this->errorMessage, $dirname));
|
||||
}
|
||||
|
||||
return $dirname;
|
||||
} elseif (isset($dirname) && is_dir($dirname)) {
|
||||
return $dirname;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a stream based on a URL (could be a local file or a real URL)
|
||||
*
|
||||
* @param string $url The file/url
|
||||
*
|
||||
* @return false|resource the open stream ressource
|
||||
*/
|
||||
public function createStream(string $url)
|
||||
{
|
||||
$directory = $this->createDir($url);
|
||||
set_error_handler([$this, 'customErrorHandler']);
|
||||
if (!empty($directory)) {
|
||||
$url = $directory . DIRECTORY_SEPARATOR . pathinfo($url, PATHINFO_BASENAME);
|
||||
}
|
||||
|
||||
$stream = fopen($url, 'ab');
|
||||
restore_error_handler();
|
||||
|
||||
if (!is_resource($stream)) {
|
||||
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $url));
|
||||
}
|
||||
|
||||
return $stream;
|
||||
}
|
||||
|
||||
private function customErrorHandler($code, $msg)
|
||||
{
|
||||
$this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Friendica\Util\Logger;
|
||||
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\FileSystem;
|
||||
use Friendica\Util\Introspection;
|
||||
use Psr\Log\LogLevel;
|
||||
|
||||
@@ -36,10 +37,9 @@ class StreamLogger extends AbstractLogger
|
||||
private $pid;
|
||||
|
||||
/**
|
||||
* An error message
|
||||
* @var string
|
||||
* @var FileSystem
|
||||
*/
|
||||
private $errorMessage;
|
||||
private $fileSystem;
|
||||
|
||||
/**
|
||||
* Translates LogLevel log levels to integer values
|
||||
@@ -63,8 +63,10 @@ class StreamLogger extends AbstractLogger
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct($channel, $stream, Introspection $introspection, $level = LogLevel::DEBUG)
|
||||
public function __construct($channel, $stream, Introspection $introspection, FileSystem $fileSystem, $level = LogLevel::DEBUG)
|
||||
{
|
||||
$this->fileSystem = $fileSystem;
|
||||
|
||||
parent::__construct($channel, $introspection);
|
||||
|
||||
if (is_resource($stream)) {
|
||||
@@ -81,6 +83,8 @@ class StreamLogger extends AbstractLogger
|
||||
} else {
|
||||
throw new \InvalidArgumentException(sprintf('The level "%s" is not valid.', $level));
|
||||
}
|
||||
|
||||
$this->checkStream();
|
||||
}
|
||||
|
||||
public function close()
|
||||
@@ -155,43 +159,6 @@ class StreamLogger extends AbstractLogger
|
||||
throw new \LogicException('Missing stream URL.');
|
||||
}
|
||||
|
||||
$this->createDir();
|
||||
set_error_handler([$this, 'customErrorHandler']);
|
||||
$this->stream = fopen($this->url, 'ab');
|
||||
restore_error_handler();
|
||||
|
||||
if (!is_resource($this->stream)) {
|
||||
$this->stream = null;
|
||||
|
||||
throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: ' . $this->errorMessage, $this->url));
|
||||
}
|
||||
}
|
||||
|
||||
private function createDir()
|
||||
{
|
||||
$dirname = null;
|
||||
$pos = strpos($this->url, '://');
|
||||
if (!$pos) {
|
||||
$dirname = dirname($this->url);
|
||||
}
|
||||
|
||||
if (substr($this->url, 0, 7) === 'file://') {
|
||||
$dirname = dirname(substr($this->url, 7));
|
||||
}
|
||||
|
||||
if (isset($dirname) && !is_dir($dirname)) {
|
||||
set_error_handler([$this, 'customErrorHandler']);
|
||||
$status = mkdir($dirname, 0777, true);
|
||||
restore_error_handler();
|
||||
|
||||
if (!$status && !is_dir($dirname)) {
|
||||
throw new \UnexpectedValueException(sprintf('Directory "%s" cannot get created: ' . $this->errorMessage, $dirname));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function customErrorHandler($code, $msg)
|
||||
{
|
||||
$this->errorMessage = preg_replace('{^(fopen|mkdir)\(.*?\): }', '', $msg);
|
||||
$this->stream = $this->fileSystem->createStream($this->url);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Diaspora;
|
||||
use Friendica\Protocol\OStatus;
|
||||
use Friendica\Protocol\Salmon;
|
||||
use Friendica\Util\ACLFormatter;
|
||||
|
||||
require_once 'include/items.php';
|
||||
|
||||
@@ -272,10 +273,13 @@ class Notifier
|
||||
$public_message = false; // private recipients, not public
|
||||
}
|
||||
|
||||
$allow_people = expand_acl($parent['allow_cid']);
|
||||
$allow_groups = Group::expand($uid, expand_acl($parent['allow_gid']),true);
|
||||
$deny_people = expand_acl($parent['deny_cid']);
|
||||
$deny_groups = Group::expand($uid, expand_acl($parent['deny_gid']));
|
||||
/** @var ACLFormatter $aclFormatter */
|
||||
$aclFormatter = BaseObject::getClass(ACLFormatter::class);
|
||||
|
||||
$allow_people = $aclFormatter->expand($parent['allow_cid']);
|
||||
$allow_groups = Group::expand($uid, $aclFormatter->expand($parent['allow_gid']),true);
|
||||
$deny_people = $aclFormatter->expand($parent['deny_cid']);
|
||||
$deny_groups = Group::expand($uid, $aclFormatter->expand($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
|
||||
|
||||
@@ -14,6 +14,7 @@ use Friendica\Database\DBA;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\User;
|
||||
use Friendica\Protocol\Activity;
|
||||
use Friendica\Protocol\ActivityPub;
|
||||
use Friendica\Protocol\Email;
|
||||
use Friendica\Protocol\PortableContact;
|
||||
@@ -493,8 +494,8 @@ class OnePoll
|
||||
Logger::log("Mail: Parsing mail ".$msg_uid, Logger::DATA);
|
||||
|
||||
$datarray = [];
|
||||
$datarray['verb'] = ACTIVITY_POST;
|
||||
$datarray['object-type'] = ACTIVITY_OBJ_NOTE;
|
||||
$datarray['verb'] = Activity::POST;
|
||||
$datarray['object-type'] = Activity\ObjectType::NOTE;
|
||||
$datarray['network'] = Protocol::MAIL;
|
||||
// $meta = Email::messageMeta($mbox, $msg_uid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user