From cc40dcf83cbaa953ca6878aeabf25c96549593a7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Apr 2018 23:28:05 -0400 Subject: [PATCH 1/5] Add dbstructure_definition hook call --- src/Database/DBStructure.php | 2 ++ 1 file changed, 2 insertions(+) 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; } } From 54b75026fce057829f65eb194fb1ff231b2fbf78 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 11 Apr 2018 23:28:51 -0400 Subject: [PATCH 2/5] Add header support for security token check --- include/security.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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 From 17a0cc4f3dafadf97b45b69f742130d7b4ae3e87 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 14 Apr 2018 17:54:16 -0400 Subject: [PATCH 3/5] Add Model\Term::populateTagsFromItem method --- src/Model/Term.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) 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; + } } From 98f64ed8242d3f3b270ad90cdc7a658a6bdca067 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 14 Apr 2018 17:55:07 -0400 Subject: [PATCH 4/5] Replace duplicate behaviors by Model\Term::populateTagsFromItem - Replaced in include/conversation - Replaced in include/text --- include/conversation.php | 34 ++++------------------------------ include/text.php | 40 ++++------------------------------------ 2 files changed, 8 insertions(+), 66 deletions(-) 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/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 = []; From 188158274cdb79c84c7e9c163a52a593179cbc12 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 17 Apr 2018 19:56:47 -0400 Subject: [PATCH 5/5] [Composer] Add bower-asset/vue dependency --- composer.json | 1 + composer.lock | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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",