]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Issue 7285: Perform duplicate check for item URI also with AP
[friendica.git] / mod / item.php
index b126c4825b6ef7a8ca83f517a9edc52f08352e9c..51bbc76e7270b54151ba3dbc567c0439864c4540 100644 (file)
@@ -27,12 +27,12 @@ use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
+use Friendica\Model\Attach;
 use Friendica\Model\Contact;
 use Friendica\Model\Conversation;
 use Friendica\Model\FileTag;
 use Friendica\Model\Item;
 use Friendica\Model\Photo;
-use Friendica\Model\Attach;
 use Friendica\Model\Term;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Email;
@@ -40,6 +40,7 @@ use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Emailer;
 use Friendica\Util\Security;
 use Friendica\Util\Strings;
+use Friendica\Worker\Delivery;
 
 require_once 'include/items.php';
 
@@ -162,7 +163,7 @@ function item_post(App $a) {
        }
 
        // Allow commenting if it is an answer to a public post
-       $allow_comment = local_user() && ($profile_uid == 0) && $toplevel_item_id && in_array($toplevel_item['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN]);
+       $allow_comment = local_user() && ($profile_uid == 0) && $toplevel_item_id && in_array($toplevel_item['network'], Protocol::FEDERATED);
 
        // Now check that valid personal details have been provided
        if (!Security::canWriteToUserWall($profile_uid) && !$allow_comment) {
@@ -327,10 +328,9 @@ function item_post(App $a) {
                }
        }
 
-       if (!empty($categories))
-       {
+       if (!empty($categories)) {
                // get the "fileas" tags for this post
-               $filedas = FileTag::fileToList($categories, 'file');
+               $filedas = FileTag::fileToArray($categories);
        }
 
        // save old and new categories, so we can determine what needs to be deleted from pconfig
@@ -338,10 +338,9 @@ function item_post(App $a) {
        $categories = FileTag::listToFile(trim(defaults($_REQUEST, 'category', '')), 'category');
        $categories_new = $categories;
 
-       if (!empty($filedas))
-       {
+       if (!empty($filedas) && is_array($filedas)) {
                // append the fileas stuff to the new categories list
-               $categories .= FileTag::listToFile($filedas, 'file');
+               $categories .= FileTag::arrayToFile($filedas);
        }
 
        // get contact info for poster
@@ -470,43 +469,10 @@ function item_post(App $a) {
 
        $match = null;
 
-       /// @todo these lines should be moved to Model/Photo
-       if (!$preview && preg_match_all("/\[img([\=0-9x]*?)\](.*?)\[\/img\]/",$body,$match)) {
-               $images = $match[2];
-               if (count($images)) {
-
-                       $objecttype = ACTIVITY_OBJ_IMAGE;
-
-                       foreach ($images as $image) {
-                               if (!stristr($image, System::baseUrl() . '/photo/')) {
-                                       continue;
-                               }
-                               $image_uri = substr($image,strrpos($image,'/') + 1);
-                               $image_uri = substr($image_uri,0, strpos($image_uri,'-'));
-                               if (!strlen($image_uri)) {
-                                       continue;
-                               }
-
-                               // Ensure to only modify photos that you own
-                               $srch = '<' . intval($original_contact_id) . '>';
-
-                               $condition = [
-                                       'allow_cid' => $srch, 'allow_gid' => '', 'deny_cid' => '', 'deny_gid' => '',
-                                       'resource-id' => $image_uri, 'uid' => $profile_uid
-                               ];
-                               if (!Photo::exists($condition)) {
-                                       continue;
-                               }
-
-                               $fields = ['allow_cid' => $str_contact_allow, 'allow_gid' => $str_group_allow,
-                                               'deny_cid' => $str_contact_deny, 'deny_gid' => $str_group_deny];
-                               $condition = ['resource-id' => $image_uri, 'uid' => $profile_uid];
-                               Photo::update($fields, $condition);
-                       }
-               }
+       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;
        }
 
-
        /*
         * Next link in any attachment references we find in the post.
         */
@@ -605,8 +571,6 @@ function item_post(App $a) {
                $origin = $_REQUEST['origin'];
        }
 
-       $notify_type = ($toplevel_item_id ? 'comment-new' : 'wall-new');
-
        $uri = ($message_id ? $message_id : Item::newURI($api_source ? $profile_uid : $uid, $guid));
 
        // Fallback so that we alway have a parent uri
@@ -871,7 +835,7 @@ function item_post(App $a) {
        // When we are doing some forum posting via ! we have to start the notifier manually.
        // These kind of posts don't initiate the notifier call in the item class.
        if ($only_to_forum) {
-               Worker::add(PRIORITY_HIGH, "Notifier", $notify_type, $post_id);
+               Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => false], "Notifier", Delivery::POST, $post_id);
        }
 
        Logger::log('post_complete');