]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Add move function to storage manager and console command
[friendica.git] / include / items.php
index f28f8f57189ba321a12633c54d563f18e83226f6..db60519a2ce8d6ba8d247ae207ce11fe06642862 100644 (file)
@@ -21,12 +21,10 @@ use Friendica\Protocol\OStatus;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use Friendica\Util\ParseUrl;
+use Friendica\Util\Strings;
 use Friendica\Util\Temporal;
 
-require_once 'include/text.php';
 require_once 'mod/share.php';
-require_once 'include/enotify.php';
-
 function add_page_info_data(array $data, $no_photos = false)
 {
        Addon::callHooks('page_info_data', $data);
@@ -96,7 +94,7 @@ function add_page_info_data(array $data, $no_photos = false)
                        /// @TODO make a positive list of allowed characters
                        $hashtag = str_replace([" ", "+", "/", ".", "#", "'", "’", "`", "(", ")", "„", "“"],
                                                ["", "", "", "", "", "", "", "", "", "", "", ""], $keyword);
-                       $hashtags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url] ";
+                       $hashtags .= "#[url=" . System::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url] ";
                }
        }
 
@@ -147,7 +145,7 @@ function add_page_keywords($url, $photo = "", $keywords = false, $keyword_blackl
                                $tags .= ", ";
                        }
 
-                       $tags .= "#[url=" . System::baseUrl() . "/search?tag=" . rawurlencode($hashtag) . "]" . $hashtag . "[/url]";
+                       $tags .= "#[url=" . System::baseUrl() . "/search?tag=" . $hashtag . "]" . $hashtag . "[/url]";
                }
        }
 
@@ -205,8 +203,7 @@ function add_page_info_to_body($body, $texturl = false, $no_photos = false)
                        $body = $removedlink;
                }
 
-               $url = str_replace(['/', '.'], ['\/', '\.'], $matches[1]);
-               $removedlink = preg_replace("/\[url\=" . $url . "\](.*?)\[\/url\]/ism", '', $body);
+               $removedlink = preg_replace("/\[url\=" . preg_quote($matches[1], '/') . "\](.*?)\[\/url\]/ism", '', $body);
                if (($removedlink == "") || strstr($body, $removedlink)) {
                        $body = $removedlink;
                }
@@ -308,7 +305,7 @@ function subscribe_to_hub($url, array $importer, array $contact, $hubmode = 'sub
        $push_url = System::baseUrl() . '/pubsub/' . $user['nickname'] . '/' . $contact['id'];
 
        // Use a single verify token, even if multiple hubs
-       $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : random_string());
+       $verify_token = ((strlen($contact['hub-verify'])) ? $contact['hub-verify'] : Strings::getRandomHex());
 
        $params= 'hub.mode=' . $hubmode . '&hub.callback=' . urlencode($push_url) . '&hub.topic=' . urlencode($contact['poll']) . '&hub.verify=async&hub.verify_token=' . $verify_token;
 
@@ -351,7 +348,7 @@ function drop_item($id, $return = '')
 
        // locate item to be deleted
 
-       $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted'];
+       $fields = ['id', 'uid', 'guid', 'contact-id', 'deleted', 'gravity', 'parent'];
        $item = Item::selectFirstForUser(local_user(), $fields, ['id' => $id]);
 
        if (!DBA::isResult($item)) {
@@ -406,17 +403,43 @@ function drop_item($id, $return = '')
                        $a->internalRedirect('display/' . $item['guid']);
                }
 
+               $is_comment = ($item['gravity'] == GRAVITY_COMMENT) ? true : false;
+               $parentitem = null;
+               if (!empty($item['parent'])){
+                       $fields = ['guid'];
+                       $parentitem = Item::selectFirstForUser(local_user(), $fields, ['id' => $item['parent']]);
+               }
+
                // delete the item
                Item::deleteForUser(['id' => $item['id']], local_user());
 
                $return_url = hex2bin($return);
-               if (empty($return_url) || strpos($return_url, 'display') !== false) {
-                       $a->internalRedirect('network');
-                       //NOTREACHED
+
+               // removes update_* from return_url to ignore Ajax refresh
+               $return_url = str_replace("update_", "", $return_url);
+
+               // Check if delete a comment
+               if ($is_comment) {
+                       // Return to parent guid
+                       if (!empty($parentitem)) {
+                               $a->internalRedirect('display/' . $parentitem['guid']);
+                               //NOTREACHED
+                       }
+                       // In case something goes wrong
+                       else {
+                               $a->internalRedirect('network');
+                               //NOTREACHED
+                       }
                }
                else {
-                       $a->internalRedirect($return_url);
-                       //NOTREACHED
+                       // if unknown location or deleting top level post called from display
+                       if (empty($return_url) || strpos($return_url, 'display') !== false) {
+                               $a->internalRedirect('network');
+                               //NOTREACHED
+                       } else {
+                               $a->internalRedirect($return_url);
+                               //NOTREACHED
+                       }
                }
        } else {
                notice(L10n::t('Permission denied.') . EOL);