]> git.mxchange.org Git - friendica.git/blobdiff - include/items.php
Merge pull request #6206 from annando/parent
[friendica.git] / include / items.php
index ff9559b2879b9ea5dbcaf090dd1a52429b6024d2..b4793b888f3fb6a531852560a54650a749524c15 100644 (file)
@@ -21,6 +21,7 @@ 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';
@@ -96,7 +97,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 +148,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]";
                }
        }
 
@@ -308,7 +309,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;
 
@@ -345,13 +346,13 @@ function drop_items(array $items)
        }
 }
 
-function drop_item($id)
+function drop_item($id, $return = '')
 {
        $a = BaseObject::getApp();
 
        // 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)) {
@@ -391,7 +392,7 @@ function drop_item($id)
                                }
                        }
 
-                       return Renderer::replaceMacros(get_markup_template('confirm.tpl'), [
+                       return Renderer::replaceMacros(Renderer::getMarkupTemplate('confirm.tpl'), [
                                '$method' => 'get',
                                '$message' => L10n::t('Do you really want to delete this item?'),
                                '$extra_inputs' => $inputs,
@@ -406,11 +407,44 @@ function drop_item($id)
                        $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());
 
-               $a->internalRedirect('network');
-               //NOTREACHED
+               $return_url = hex2bin($return);
+
+               // 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 {
+                       // 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);
                $a->internalRedirect('display/' . $item['guid']);
@@ -444,7 +478,7 @@ function list_post_dates($uid, $wall)
                $dend = substr($dnow, 0, 8) . Temporal::getDaysInMonth(intval($dnow), intval(substr($dnow, 5)));
                $start_month = DateTimeFormat::utc($dstart, 'Y-m-d');
                $end_month = DateTimeFormat::utc($dend, 'Y-m-d');
-               $str = day_translate(DateTimeFormat::utc($dnow, 'F'));
+               $str = L10n::getDay(DateTimeFormat::utc($dnow, 'F'));
 
                if (empty($ret[$dyear])) {
                        $ret[$dyear] = [];
@@ -482,7 +516,7 @@ function posted_date_widget($url, $uid, $wall)
        $cutoff_year = intval(DateTimeFormat::localNow('Y')) - $visible_years;
        $cutoff = ((array_key_exists($cutoff_year, $ret))? true : false);
 
-       $o = Renderer::replaceMacros(get_markup_template('posted_date_widget.tpl'),[
+       $o = Renderer::replaceMacros(Renderer::getMarkupTemplate('posted_date_widget.tpl'),[
                '$title' => L10n::t('Archives'),
                '$size' => $visible_years,
                '$cutoff_year' => $cutoff_year,