]> git.mxchange.org Git - friendica.git/blobdiff - mod/item.php
Fix formatting and PHP Notice in frio theme
[friendica.git] / mod / item.php
index 8ae99948a103e5addc49cefb83a86259622c410e..1faef960163c7845bad16b15a814d58a747dd667 100644 (file)
@@ -1,4 +1,7 @@
 <?php
+/**
+ * @file mod/item.php
+ */
 
 /*
  * This is the POST destination for most all locally posted
  * Posts that originate externally or do not fall into the above
  * posting categories go through item_store() instead of this function.
  */
-
 use Friendica\App;
 use Friendica\Core\Config;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBM;
-use Friendica\Model\GlobalContact;
+use Friendica\Model\Contact;
+use Friendica\Model\GContact;
 use Friendica\Network\Probe;
-use Friendica\Object\Contact;
 use Friendica\Protocol\Diaspora;
+use Friendica\Protocol\Email;
 use Friendica\Util\Emailer;
 
-require_once 'include/crypto.php';
 require_once 'include/enotify.php';
-require_once 'include/email.php';
 require_once 'include/tags.php';
 require_once 'include/files.php';
 require_once 'include/threads.php';
@@ -37,7 +38,7 @@ require_once 'include/items.php';
 
 function item_post(App $a) {
 
-       if ((! local_user()) && (! remote_user()) && (! x($_REQUEST, 'commenter'))) {
+       if (!local_user() && !remote_user() && !x($_REQUEST, 'commenter')) {
                return;
        }
 
@@ -79,8 +80,8 @@ function item_post(App $a) {
        }
 
        // Is this a reply to something?
-       $parent = ((x($_REQUEST, 'parent')) ? intval($_REQUEST['parent']) : 0);
-       $parent_uri = ((x($_REQUEST, 'parent_uri')) ? trim($_REQUEST['parent_uri']) : '');
+       $parent = (x($_REQUEST, 'parent') ? intval($_REQUEST['parent']) : 0);
+       $parent_uri = (x($_REQUEST, 'parent_uri') ? trim($_REQUEST['parent_uri']) : '');
 
        $parent_item = null;
        $parent_contact = null;
@@ -120,7 +121,7 @@ function item_post(App $a) {
                        }
                }
 
-               if (! DBM::is_result($r)) {
+               if (!DBM::is_result($r)) {
                        notice( t('Unable to locate original post.') . EOL);
                        if (x($_REQUEST, 'return')) {
                                goaway($return_path);
@@ -199,7 +200,7 @@ function item_post(App $a) {
 
        // First check that the parent exists and it is a wall item.
 
-       if ((x($_REQUEST, 'commenter')) && ((! $parent) || (! $parent_item['wall']))) {
+       if (x($_REQUEST, 'commenter') && (!$parent || !$parent_item['wall'])) {
                notice(t('Permission denied.') . EOL) ;
                if (x($_REQUEST, 'return')) {
                        goaway($return_path);
@@ -207,11 +208,14 @@ function item_post(App $a) {
                killme();
        }
 
+       // Allow commenting if it is an answer to a public post
+       $allow_comment = ($profile_uid == 0) && $parent && in_array($parent_item['network'], [NETWORK_OSTATUS, NETWORK_DIASPORA]);
+
        /*
         * Now check that it is a page_type of PAGE_BLOG, and that valid personal details
         * have been provided, and run any anti-spam plugins
         */
-       if ((! can_write_wall($a, $profile_uid)) && (! $allow_moderated)) {
+       if (!(can_write_wall($a, $profile_uid) || $allow_comment) && !$allow_moderated) {
                notice(t('Permission denied.') . EOL) ;
                if (x($_REQUEST, 'return')) {
                        goaway($return_path);
@@ -375,11 +379,11 @@ function item_post(App $a) {
        $self   = false;
        $contact_id = 0;
 
-       if ((local_user()) && (local_user() == $profile_uid)) {
+       if (local_user() && ((local_user() == $profile_uid) || $allow_comment)) {
                $self = true;
-               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
                        intval($_SESSION['uid']));
-       } elseif(remote_user()) {
+       } elseif (remote_user()) {
                if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
                        foreach ($_SESSION['remote'] as $v) {
                                if ($v['uid'] == $profile_uid) {
@@ -402,10 +406,10 @@ function item_post(App $a) {
 
        // get contact info for owner
 
-       if ($profile_uid == local_user()) {
+       if ($profile_uid == local_user() || $allow_comment) {
                $contact_record = $author;
        } else {
-               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` LIMIT 1",
                        intval($profile_uid)
                );
                if (DBM::is_result($r)) {
@@ -512,6 +516,8 @@ function item_post(App $a) {
                }
        }
 
+       $original_contact_id = $contact_id;
+
        if (!$parent && count($forum_contact) && ($private_forum || $only_to_forum)) {
                // we tagged a forum in a top level post. Now we change the post
                $private = $private_forum;
@@ -548,15 +554,15 @@ function item_post(App $a) {
                        $objecttype = ACTIVITY_OBJ_IMAGE;
 
                        foreach ($images as $image) {
-                               if (! stristr($image,System::baseUrl() . '/photo/')) {
+                               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)) {
+                               if (!strlen($image_uri)) {
                                        continue;
                                }
-                               $srch = '<' . intval($contact_id) . '>';
+                               $srch = '<' . intval($original_contact_id) . '>';
 
                                $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''
                                        AND `resource-id` = '%s' AND `uid` = %d LIMIT 1",
@@ -577,7 +583,7 @@ function item_post(App $a) {
                                        dbesc($str_group_deny),
                                        dbesc($image_uri),
                                        intval($profile_uid),
-                                       dbesc( t('Wall Photos'))
+                                       dbesc(t('Wall Photos'))
                                );
                        }
                }
@@ -739,7 +745,7 @@ function item_post(App $a) {
        $datarray['postopts']      = $postopts;
        $datarray['origin']        = $origin;
        $datarray['moderated']     = $allow_moderated;
-       $datarray['gcontact-id']   = GlobalContact::getId(array("url" => $datarray['author-link'], "network" => $datarray['network'],
+       $datarray['gcontact-id']   = GContact::getId(array("url" => $datarray['author-link'], "network" => $datarray['network'],
                                                        "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']));
        $datarray['object']        = $object;
 
@@ -1028,9 +1034,9 @@ function item_post(App $a) {
                                $disclaimer .= sprintf( t('You may visit them online at %s'), System::baseUrl() . '/profile/' . $a->user['nickname']) . EOL;
                                $disclaimer .= 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_header_encode($datarray['title'], 'UTF-8');
+                                       $subject = Email::encodeHeader($datarray['title'], 'UTF-8');
                                } else {
-                                       $subject = email_header_encode('[Friendica]' . ' ' . sprintf( t('%s posted an update.'), $a->user['username']), 'UTF-8');
+                                       $subject = Email::encodeHeader('[Friendica]' . ' ' . sprintf( 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 />';
                                $html    = prepare_body($datarray);
@@ -1240,7 +1246,7 @@ function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $n
                        if (!DBM::is_result($r)) {
                                $probed = Probe::uri($name);
                                if ($result['network'] != NETWORK_PHANTOM) {
-                                       GlobalContact::update($probed);
+                                       GContact::update($probed);
                                        $r = q("SELECT `url`, `name`, `nick`, `network`, `alias`, `notify` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
                                                dbesc(normalise_link($probed["url"])));
                                }