]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
New function "isAuthenticated"
[friendica.git] / mod / item.php
index b126c4825b6ef7a8ca83f517a9edc52f08352e9c..28f393ac602fcb51736a8d4a4b125551bb5993f6 100644 (file)
@@ -25,14 +25,15 @@ use Friendica\Core\L10n;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
+use Friendica\Core\Session;
 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,11 +41,12 @@ 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';
 
 function item_post(App $a) {
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return 0;
        }
 
@@ -162,7 +164,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) {
@@ -283,10 +285,6 @@ function item_post(App $a) {
 
                $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
 
-               if ($user['hidewall']) {
-                       $private = 2;
-               }
-
                // If this is a comment, set the permissions from the parent.
 
                if ($toplevel_item) {
@@ -327,10 +325,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 +335,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
@@ -353,18 +349,8 @@ function item_post(App $a) {
        if (local_user() && ((local_user() == $profile_uid) || $allow_comment)) {
                $self = true;
                $author = DBA::selectFirst('contact', [], ['uid' => local_user(), 'self' => true]);
-       } elseif (remote_user()) {
-               if (!empty($_SESSION['remote']) && is_array($_SESSION['remote'])) {
-                       foreach ($_SESSION['remote'] as $v) {
-                               if ($v['uid'] == $profile_uid) {
-                                       $contact_id = $v['cid'];
-                                       break;
-                               }
-                       }
-               }
-               if ($contact_id) {
-                       $author = DBA::selectFirst('contact', [], ['id' => $contact_id]);
-               }
+       } elseif (!empty(Session::getRemoteContactID($profile_uid))) {
+               $author = DBA::selectFirst('contact', [], ['id' => Session::getRemoteContactID($profile_uid)]);
        }
 
        if (DBA::isResult($author)) {
@@ -470,43 +456,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 +558,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 +822,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');
@@ -910,7 +861,7 @@ function item_post_return($baseurl, $api_source, $return_path)
 
 function item_content(App $a)
 {
-       if (!local_user() && !remote_user()) {
+       if (!Session::isAuthenticated()) {
                return;
        }