diff --git a/composer.json b/composer.json
index 52b4f2c86..5cb33e67d 100644
--- a/composer.json
+++ b/composer.json
@@ -30,6 +30,7 @@
"bower-asset/base64": "^1.0",
"bower-asset/Chart-js": "^2.7",
"bower-asset/perfect-scrollbar": "^0.6",
+ "bower-asset/vue": "^2.5",
"npm-asset/jquery": "^2.0",
"npm-asset/jquery-colorbox": "^1.6",
"npm-asset/jquery-datetimepicker": "^2.4.0",
diff --git a/composer.lock b/composer.lock
index 28199f4f5..34362cb1b 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "12b8df66213734281765cb6e2c5a786e",
+ "content-hash": "96062c2020a40f14b52e5e91c79995a7",
"packages": [
{
"name": "asika/simple-console",
@@ -133,6 +133,22 @@
"description": "Minimalistic but perfect custom scrollbar plugin",
"time": "2017-01-10T01:04:09+00:00"
},
+ {
+ "name": "bower-asset/vue",
+ "version": "v2.5.16",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/vuejs/vue.git",
+ "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/vuejs/vue/zipball/25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6",
+ "reference": "25342194016dc3bcc81cb3e8e229b0fb7ba1d1d6",
+ "shasum": ""
+ },
+ "type": "bower-asset-library"
+ },
{
"name": "divineomega/password_exposed",
"version": "v2.5.1",
diff --git a/include/conversation.php b/include/conversation.php
index 8a2887d6b..41f10959b 100644
--- a/include/conversation.php
+++ b/include/conversation.php
@@ -668,33 +668,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
$profile_name = $item['author-link'];
}
- $tags = [];
- $hashtags = [];
- $mentions = [];
-
- $searchpath = System::baseUrl()."/search?tag=";
-
- $taglist = dba::select('term', ['type', 'term', 'url'],
- ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
- ['order' => ['tid']]);
-
- while ($tag = dba::fetch($taglist)) {
- if ($tag["url"] == "") {
- $tag["url"] = $searchpath . strtolower($tag["term"]);
- }
-
- $tag["url"] = best_link_url($item, $sp, $tag["url"]);
-
- if ($tag["type"] == TERM_HASHTAG) {
- $hashtags[] = "#" . $tag["term"] . "";
- $prefix = "#";
- } elseif ($tag["type"] == TERM_MENTION) {
- $mentions[] = "@" . $tag["term"] . "";
- $prefix = "@";
- }
- $tags[] = $prefix."" . $tag["term"] . "";
- }
- dba::close($taglist);
+ $tags = \Friendica\Model\Term::populateTagsFromItem($item);
$sp = false;
$profile_link = best_link_url($item, $sp);
@@ -764,9 +738,9 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
}
$body_e = $body;
- $tags_e = $tags;
- $hashtags_e = $hashtags;
- $mentions_e = $mentions;
+ $tags_e = $tags['tags'];
+ $hashtags_e = $tags['hashtags'];
+ $mentions_e = $tags['mentions'];
$location_e = $location;
$owner_name_e = $owner_name;
diff --git a/include/security.php b/include/security.php
index af424df26..b13a507cf 100644
--- a/include/security.php
+++ b/include/security.php
@@ -405,12 +405,21 @@ function get_form_security_token($typename = '')
function check_form_security_token($typename = '', $formname = 'form_security_token')
{
- if (!x($_REQUEST, $formname)) {
- return false;
+ $hash = null;
+
+ if (!empty($_REQUEST[$formname])) {
+ /// @TODO Careful, not secured!
+ $hash = $_REQUEST[$formname];
}
- /// @TODO Careful, not secured!
- $hash = $_REQUEST[$formname];
+ if (!empty($_SERVER['HTTP_X_CSRF_TOKEN'])) {
+ /// @TODO Careful, not secured!
+ $hash = $_SERVER['HTTP_X_CSRF_TOKEN'];
+ }
+
+ if (empty($hash)) {
+ return false;
+ }
$max_livetime = 10800; // 3 hours
diff --git a/include/text.php b/include/text.php
index ee8a213ff..2ec017caf 100644
--- a/include/text.php
+++ b/include/text.php
@@ -1234,12 +1234,6 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
$a = get_app();
Addon::callHooks('prepare_body_init', $item);
- $searchpath = System::baseUrl() . "/search?tag=";
-
- $tags = [];
- $hashtags = [];
- $mentions = [];
-
// In order to provide theme developers more possibilities, event items
// are treated differently.
if ($item['object-type'] === ACTIVITY_OBJ_EVENT && isset($item['event-id'])) {
@@ -1247,37 +1241,11 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
return $ev;
}
- $taglist = dba::p("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = ? AND `oid` = ? AND `type` IN (?, ?) ORDER BY `tid`",
- intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
+ $tags = \Friendica\Model\Term::populateTagsFromItem($item);
- while ($tag = dba::fetch($taglist)) {
- if ($tag["url"] == "") {
- $tag["url"] = $searchpath . strtolower($tag["term"]);
- }
-
- $orig_tag = $tag["url"];
-
- $tag["url"] = best_link_url($item, $sp, $tag["url"]);
-
- if ($tag["type"] == TERM_HASHTAG) {
- if ($orig_tag != $tag["url"]) {
- $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
- }
-
- $hashtags[] = "#" . $tag["term"] . "";
- $prefix = "#";
- } elseif ($tag["type"] == TERM_MENTION) {
- $mentions[] = "@" . $tag["term"] . "";
- $prefix = "@";
- }
-
- $tags[] = $prefix . "" . $tag["term"] . "";
- }
- dba::close($taglist);
-
- $item['tags'] = $tags;
- $item['hashtags'] = $hashtags;
- $item['mentions'] = $mentions;
+ $item['tags'] = $tags['tags'];
+ $item['hashtags'] = $tags['hashtags'];
+ $item['mentions'] = $tags['mentions'];
// Compile eventual content filter reasons
$filter_reasons = [];
diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php
index 67c8d7b8a..bccd70372 100644
--- a/src/Database/DBStructure.php
+++ b/src/Database/DBStructure.php
@@ -1803,6 +1803,8 @@ class DBStructure
]
];
+ \Friendica\Core\Addon::callHooks('dbstructure_definition', $database);
+
return $database;
}
}
diff --git a/src/Model/Term.php b/src/Model/Term.php
index d950d1d5f..03f19197a 100644
--- a/src/Model/Term.php
+++ b/src/Model/Term.php
@@ -9,6 +9,7 @@ use Friendica\Database\DBM;
use dba;
require_once 'boot.php';
+require_once 'include/conversation.php';
require_once 'include/dba.php';
class Term
@@ -168,4 +169,56 @@ class Term
}
}
}
+
+ /**
+ * Sorts an item's tags into mentions, hashtags and other tags. Generate personalized URLs by user and modify the
+ * provided item's body with them.
+ *
+ * @param array $item
+ * @return array
+ */
+ public static function populateTagsFromItem(&$item)
+ {
+ $return = [
+ 'tags' => [],
+ 'hashtags' => [],
+ 'mentions' => [],
+ ];
+
+ $searchpath = System::baseUrl() . "/search?tag=";
+
+ $taglist = dba::select(
+ 'term',
+ ['type', 'term', 'url'],
+ ["`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION],
+ ['order' => ['tid']]
+ );
+
+ while ($tag = dba::fetch($taglist)) {
+ if ($tag["url"] == "") {
+ $tag["url"] = $searchpath . strtolower($tag["term"]);
+ }
+
+ $orig_tag = $tag["url"];
+
+ $tag["url"] = best_link_url($item, $sp, $tag["url"]);
+
+ if ($tag["type"] == TERM_HASHTAG) {
+ if ($orig_tag != $tag["url"]) {
+ $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']);
+ }
+
+ $return['hashtags'][] = "#" . $tag["term"] . "";
+ $prefix = "#";
+ } elseif ($tag["type"] == TERM_MENTION) {
+ $return['mentions'][] = "@" . $tag["term"] . "";
+ $prefix = "@";
+ }
+
+ $return['tags'][] = $prefix . "" . $tag["term"] . "";
+ }
+ dba::close($taglist);
+
+ return $return;
+ }
}