]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
rename CSS attributes notify => notification
[friendica.git] / mod / item.php
index 7c8ebee4abfdf5e3ae5c8271b394bd8bf4d0147e..a9c5d43580794d660e7fa2a83099c994bd36c6a4 100644 (file)
@@ -19,15 +19,14 @@ use Friendica\App;
 use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Content\Text\HTML;
-use Friendica\Core\Config;
 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\DI;
 use Friendica\Model\Attach;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
@@ -35,6 +34,7 @@ use Friendica\Model\FileTag;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
 use Friendica\Model\Term;
+use Friendica\Protocol\Activity;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
 use Friendica\Util\DateTimeFormat;
@@ -79,7 +79,7 @@ function item_post(App $a) {
        if (!$preview && !empty($_REQUEST['post_id_random'])) {
                if (!empty($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
                        Logger::log("item post: duplicate post", Logger::DEBUG);
-                       item_post_return(System::baseUrl(), $api_source, $return_path);
+                       item_post_return(DI::baseUrl(), $api_source, $return_path);
                } else {
                        $_SESSION['post-random'] = $_REQUEST['post_id_random'];
                }
@@ -121,9 +121,9 @@ function item_post(App $a) {
                }
 
                if (!DBA::isResult($toplevel_item)) {
-                       notice(L10n::t('Unable to locate original post.') . EOL);
+                       notice(DI::l10n()->t('Unable to locate original post.') . EOL);
                        if (!empty($_REQUEST['return'])) {
-                               $a->internalRedirect($return_path);
+                               DI::baseUrl()->redirect($return_path);
                        }
                        exit();
                }
@@ -131,7 +131,7 @@ function item_post(App $a) {
                $toplevel_item_id = $toplevel_item['id'];
                $parent_user = $toplevel_item['uid'];
 
-               $objecttype = ACTIVITY_OBJ_COMMENT;
+               $objecttype = Activity\ObjectType::COMMENT;
        }
 
        if ($toplevel_item_id) {
@@ -168,10 +168,10 @@ function item_post(App $a) {
 
        // Now check that valid personal details have been provided
        if (!Security::canWriteToUserWall($profile_uid) && !$allow_comment) {
-               notice(L10n::t('Permission denied.') . EOL);
+               notice(DI::l10n()->t('Permission denied.') . EOL);
 
                if (!empty($_REQUEST['return'])) {
-                       $a->internalRedirect($return_path);
+                       DI::baseUrl()->redirect($return_path);
                }
 
                exit();
@@ -244,7 +244,7 @@ function item_post(App $a) {
                $app               = $orig_post['app'];
                $categories        = $orig_post['file'];
                $title             = Strings::escapeTags(trim($_REQUEST['title']));
-               $body              = Strings::escapeHtml(trim($body));
+               $body              = trim($body);
                $private           = $orig_post['private'];
                $pubmail_enabled   = $orig_post['pubmail'];
                $network           = $orig_post['network'];
@@ -269,10 +269,13 @@ function item_post(App $a) {
                        $str_contact_deny  = $user['deny_cid'];
                } else {
                        // use the posted permissions
-                       $str_group_allow   = perms2str($_REQUEST['group_allow'] ?? '');
-                       $str_contact_allow = perms2str($_REQUEST['contact_allow'] ?? '');
-                       $str_group_deny    = perms2str($_REQUEST['group_deny'] ?? '');
-                       $str_contact_deny  = perms2str($_REQUEST['contact_deny'] ?? '');
+
+                       $aclFormatter = DI::aclFormatter();
+
+                       $str_group_allow   = $aclFormatter->toString($_REQUEST['group_allow'] ?? '');
+                       $str_contact_allow = $aclFormatter->toString($_REQUEST['contact_allow'] ?? '');
+                       $str_group_deny    = $aclFormatter->toString($_REQUEST['group_deny'] ?? '');
+                       $str_contact_deny  = $aclFormatter->toString($_REQUEST['contact_deny'] ?? '');
                }
 
                $title             = Strings::escapeTags(trim($_REQUEST['title']    ?? ''));
@@ -280,7 +283,7 @@ function item_post(App $a) {
                $coord             = Strings::escapeTags(trim($_REQUEST['coord']    ?? ''));
                $verb              = Strings::escapeTags(trim($_REQUEST['verb']     ?? ''));
                $emailcc           = Strings::escapeTags(trim($_REQUEST['emailcc']  ?? ''));
-               $body              = Strings::escapeHtml(trim($body));
+               $body              = trim($body);
                $network           = Strings::escapeTags(trim(($_REQUEST['network']  ?? '') ?: Protocol::DFRN));
                $guid              = System::createUUID();
 
@@ -311,7 +314,7 @@ function item_post(App $a) {
 
                // if using the API, we won't see pubmail_enable - figure out if it should be set
                if ($api_source && $profile_uid && $profile_uid == local_user() && !$private) {
-                       if (function_exists('imap_open') && !Config::get('system', 'imap_disabled')) {
+                       if (function_exists('imap_open') && !DI::config()->get('system', 'imap_disabled')) {
                                $pubmail_enabled = DBA::exists('mailacct', ["`uid` = ? AND `server` != ? AND `pubmail`", local_user(), '']);
                        }
                }
@@ -320,9 +323,9 @@ function item_post(App $a) {
                        if ($preview) {
                                exit();
                        }
-                       info(L10n::t('Empty post discarded.') . EOL);
+                       info(DI::l10n()->t('Empty post discarded.') . EOL);
                        if (!empty($_REQUEST['return'])) {
-                               $a->internalRedirect($return_path);
+                               DI::baseUrl()->redirect($return_path);
                        }
                        exit();
                }
@@ -460,7 +463,7 @@ function item_post(App $a) {
        $match = null;
 
        if (!$preview && Photo::setPermissionFromBody($body, $profile_uid, $original_contact_id, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny)) {
-               $objecttype = ACTIVITY_OBJ_IMAGE;
+               $objecttype = Activity\ObjectType::IMAGE;
        }
 
        /*
@@ -496,28 +499,27 @@ function item_post(App $a) {
        if ((preg_match_all("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism", $body, $match, PREG_SET_ORDER) || isset($data["type"]))
                && ($posttype != Item::PT_PERSONAL_NOTE)) {
                $posttype = Item::PT_PAGE;
-               $objecttype = ACTIVITY_OBJ_BOOKMARK;
+               $objecttype =  Activity\ObjectType::BOOKMARK;
        }
 
-       $body = bb_translate_video($body);
-
+       $body = DI::bbCodeVideo()->transform($body);
 
        // Fold multi-line [code] sequences
        $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body);
 
-       $body = BBCode::scaleExternalImages($body, false);
+       $body = BBCode::scaleExternalImages($body);
 
        // Setting the object type if not defined before
        if (!$objecttype) {
-               $objecttype = ACTIVITY_OBJ_NOTE; // Default value
+               $objecttype = Activity\ObjectType::NOTE; // Default value
                $objectdata = BBCode::getAttachedData($body);
 
                if ($objectdata["type"] == "link") {
-                       $objecttype = ACTIVITY_OBJ_BOOKMARK;
+                       $objecttype = Activity\ObjectType::BOOKMARK;
                } elseif ($objectdata["type"] == "video") {
-                       $objecttype = ACTIVITY_OBJ_VIDEO;
+                       $objecttype = Activity\ObjectType::VIDEO;
                } elseif ($objectdata["type"] == "photo") {
-                       $objecttype = ACTIVITY_OBJ_IMAGE;
+                       $objecttype = Activity\ObjectType::IMAGE;
                }
 
        }
@@ -533,7 +535,7 @@ function item_post(App $a) {
                                if (strlen($attachments)) {
                                        $attachments .= ',';
                                }
-                               $attachments .= '[attach]href="' . System::baseUrl() . '/attach/' . $attachment['id'] .
+                               $attachments .= '[attach]href="' . DI::baseUrl() . '/attach/' . $attachment['id'] .
                                                '" length="' . $attachment['filesize'] . '" type="' . $attachment['filetype'] .
                                                '" title="' . ($attachment['filename'] ? $attachment['filename'] : '') . '"[/attach]';
                        }
@@ -542,7 +544,7 @@ function item_post(App $a) {
        }
 
        if (!strlen($verb)) {
-               $verb = ACTIVITY_POST;
+               $verb = Activity::POST;
        }
 
        if ($network == "") {
@@ -644,6 +646,9 @@ function item_post(App $a) {
        if ($orig_post) {
                $datarray['edit'] = true;
        } else {
+               // If this was a share, add missing data here
+               $datarray = Item::addShareDataFromOriginal($datarray);
+
                $datarray['edit'] = false;
        }
 
@@ -660,7 +665,7 @@ function item_post(App $a) {
                $datarray["item_id"] = -1;
                $datarray["author-network"] = Protocol::DFRN;
 
-               $o = conversation($a, [array_merge($contact_record, $datarray)], new Pager($a->query_string), 'search', false, true);
+               $o = conversation($a, [array_merge($contact_record, $datarray)], new Pager(DI::args()->getQueryString()), 'search', false, true);
                Logger::log('preview: ' . $o);
                echo json_encode(['preview' => $o]);
                exit();
@@ -671,12 +676,12 @@ function item_post(App $a) {
        if (!empty($datarray['cancel'])) {
                Logger::log('mod_item: post cancelled by addon.');
                if ($return_path) {
-                       $a->internalRedirect($return_path);
+                       DI::baseUrl()->redirect($return_path);
                }
 
                $json = ['cancel' => 1];
                if (!empty($_REQUEST['jsreload'])) {
-                       $json['reload'] = System::baseUrl() . '/' . $_REQUEST['jsreload'];
+                       $json['reload'] = DI::baseUrl() . '/' . $_REQUEST['jsreload'];
                }
 
                echo json_encode($json);
@@ -706,7 +711,7 @@ function item_post(App $a) {
 
                if (!empty($_REQUEST['return']) && strlen($return_path)) {
                        Logger::log('return: ' . $return_path);
-                       $a->internalRedirect($return_path);
+                       DI::baseUrl()->redirect($return_path);
                }
                exit();
        }
@@ -726,14 +731,14 @@ function item_post(App $a) {
 
        if (!$post_id) {
                Logger::log("Item wasn't stored.");
-               $a->internalRedirect($return_path);
+               DI::baseUrl()->redirect($return_path);
        }
 
        $datarray = Item::selectFirst(Item::ITEM_FIELDLIST, ['id' => $post_id]);
 
        if (!DBA::isResult($datarray)) {
                Logger::log("Item with id ".$post_id." couldn't be fetched.");
-               $a->internalRedirect($return_path);
+               DI::baseUrl()->redirect($return_path);
        }
 
        // update filetags in pconfig
@@ -750,11 +755,11 @@ function item_post(App $a) {
                                'to_email'     => $user['email'],
                                'uid'          => $user['uid'],
                                'item'         => $datarray,
-                               'link'         => System::baseUrl().'/display/'.urlencode($datarray['guid']),
+                               'link'         => DI::baseUrl().'/display/'.urlencode($datarray['guid']),
                                'source_name'  => $datarray['author-name'],
                                'source_link'  => $datarray['author-link'],
                                'source_photo' => $datarray['author-avatar'],
-                               'verb'         => ACTIVITY_POST,
+                               'verb'         => Activity::POST,
                                'otype'        => 'item',
                                'parent'       => $toplevel_item_id,
                                'parent_uri'   => $toplevel_item['uri']
@@ -770,11 +775,11 @@ function item_post(App $a) {
                                'to_email'     => $user['email'],
                                'uid'          => $user['uid'],
                                'item'         => $datarray,
-                               'link'         => System::baseUrl().'/display/'.urlencode($datarray['guid']),
+                               'link'         => DI::baseUrl().'/display/'.urlencode($datarray['guid']),
                                'source_name'  => $datarray['author-name'],
                                'source_link'  => $datarray['author-link'],
                                'source_photo' => $datarray['author-avatar'],
-                               'verb'         => ACTIVITY_POST,
+                               'verb'         => Activity::POST,
                                'otype'        => 'item'
                        ]);
                }
@@ -790,16 +795,16 @@ function item_post(App $a) {
                                if (!strlen($addr)) {
                                        continue;
                                }
-                               $disclaimer = '<hr />' . L10n::t('This message was sent to you by %s, a member of the Friendica social network.', $a->user['username'])
+                               $disclaimer = '<hr />' . DI::l10n()->t('This message was sent to you by %s, a member of the Friendica social network.', $a->user['username'])
                                        . '<br />';
-                               $disclaimer .= L10n::t('You may visit them online at %s', System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL;
-                               $disclaimer .= L10n::t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
+                               $disclaimer .= DI::l10n()->t('You may visit them online at %s', DI::baseUrl() . '/profile/' . $a->user['nickname']) . EOL;
+                               $disclaimer .= DI::l10n()->t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
                                if (!$datarray['title']=='') {
                                        $subject = Email::encodeHeader($datarray['title'], 'UTF-8');
                                } else {
-                                       $subject = Email::encodeHeader('[Friendica]' . ' ' . L10n::t('%s posted an update.', $a->user['username']), 'UTF-8');
+                                       $subject = Email::encodeHeader('[Friendica]' . ' ' . DI::l10n()->t('%s posted an update.', $a->user['username']), 'UTF-8');
                                }
-                               $link = '<a href="' . System::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
+                               $link = '<a href="' . DI::baseUrl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
                                $html    = Item::prepareBody($datarray);
                                $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
                                $params =  [
@@ -834,21 +839,21 @@ function item_post(App $a) {
                return $post_id;
        }
 
-       item_post_return(System::baseUrl(), $api_source, $return_path);
+       item_post_return(DI::baseUrl(), $api_source, $return_path);
        // NOTREACHED
 }
 
 function item_post_return($baseurl, $api_source, $return_path)
 {
        // figure out how to return, depending on from whence we came
-    $a = \get_app();
+    $a = DI::app();
 
        if ($api_source) {
                return;
        }
 
        if ($return_path) {
-               $a->internalRedirect($return_path);
+               DI::baseUrl()->redirect($return_path);
        }
 
        $json = ['success' => 1];
@@ -871,7 +876,7 @@ function item_content(App $a)
        $o = '';
 
        if (($a->argc >= 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
-               if ($a->isAjax()) {
+               if (DI::mode()->isAjax()) {
                        $o = Item::deleteForUser(['id' => $a->argv[2]], local_user());
                } else {
                        if (!empty($a->argv[3])) {
@@ -882,7 +887,7 @@ function item_content(App $a)
                        }
                }
 
-               if ($a->isAjax()) {
+               if (DI::mode()->isAjax()) {
                        // ajax return: [<item id>, 0 (no perm) | <owner id>]
                        echo json_encode([intval($a->argv[2]), intval($o)]);
                        exit();
@@ -1054,7 +1059,7 @@ function handle_tag(&$body, &$inform, &$str_tags, $profile_uid, $tag, $network =
 
 function item_add_implicit_mentions(array $tags, array $thread_parent_contact, $thread_parent_id)
 {
-       if (Config::get('system', 'disable_implicit_mentions')) {
+       if (DI::config()->get('system', 'disable_implicit_mentions')) {
                // Add a tag if the parent contact is from ActivityPub or OStatus (This will notify them)
                if (in_array($thread_parent_contact['network'], [Protocol::OSTATUS, Protocol::ACTIVITYPUB])) {
                        $contact = Term::TAG_CHARACTER[Term::MENTION] . '[url=' . $thread_parent_contact['url'] . ']' . $thread_parent_contact['nick'] . '[/url]';