From 17b05c9ad9a8b87c6db77a4bbfafcb2ebc8dc3d3 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 19 Aug 2017 09:22:50 +0000 Subject: [PATCH] Hash tag links now do a redir --- doc/htconfig.md | 1 + include/bbcode.php | 1 + include/conversation.php | 30 +++++++++++++++++++----------- include/items.php | 4 ++-- include/text.php | 8 ++++++++ mod/dfrn_poll.php | 3 ++- object/Item.php | 1 - 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/doc/htconfig.md b/doc/htconfig.md index a452ecfc1..aeb0c9202 100644 --- a/doc/htconfig.md +++ b/doc/htconfig.md @@ -48,6 +48,7 @@ Example: To set the directory value please add this line to your .htconfig.php: * **like_no_comment** (Boolean) - Don't update the "commented" value of an item when it is liked. * **local_block** (Boolean) - Used in conjunction with "block_public". * **local_search** (Boolean) - Blocks search for users who are not logged in to prevent crawlers from blocking your system. +* **local_tags** (Boolean) - If activated, all hashtags will point to the local server. * **max_connections** - The maximum number of database connections which can be in use before the poller process is deferred to it's next interval. When the system can't detect the maximum numbers of connection then this value can be used. * **max_connections_level** - The maximum level of connections that are allowed to let the poller start. It is a percentage value. Default value is 75. * **max_contact_queue** - Default value is 500. diff --git a/include/bbcode.php b/include/bbcode.php index 109ca743d..99f997762 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1315,6 +1315,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa // Always allowed protocol even if config isn't set or not including it $allowed_link_protocols[] = 'http'; + $allowed_link_protocols[] = 'redir/'; $regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism'; $Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text); diff --git a/include/conversation.php b/include/conversation.php index f81fb3eb8..4f40bc288 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -358,7 +358,7 @@ function localize_item(&$item) { $x = stristr($item['plink'],'/display/'); if ($x) { $sparkle = false; - $y = best_link_url($item, $sparkle, true); + $y = best_link_url($item, $sparkle); if (strstr($y, '/redir/')) { $item['plink'] = $y . '?f=&url=' . $item['plink']; @@ -680,6 +680,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $hashtags = array(); $mentions = array(); + $searchpath = App::get_baseurl()."/search?tag="; + $taglist = dba::select('term', array('type', 'term', 'url'), array("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION), array('order' => array('tid'))); @@ -689,6 +691,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { $tag["url"] = $searchpath . strtolower($tag["term"]); } + $tag["url"] = best_link_url($item, $sp, $tag["url"]); + if ($tag["type"] == TERM_HASHTAG) { $hashtags[] = "#" . $tag["term"] . ""; $prefix = "#"; @@ -701,7 +705,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { dba::close($taglist); $sp = false; - $profile_link = best_link_url($item,$sp); + $profile_link = best_link_url($item, $sp); if ($profile_link === 'mailbox') { $profile_link = ''; } @@ -914,7 +918,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) { return $o; }} -function best_link_url($item, &$sparkle, $ssl_state = false) { +function best_link_url($item, &$sparkle, $url = '') { $best_url = ''; $sparkle = false; @@ -928,10 +932,20 @@ function best_link_url($item, &$sparkle, $ssl_state = false) { if (dbm::is_result($r)) { $best_url = 'redir/' . $r['id']; $sparkle = true; + if ($url != '') { + $hostname = get_app()->get_hostname(); + if (!strstr($url, $hostname)) { + $best_url .= "?url=".$url; + } else { + $best_url = $url; + } + } } } if (! $best_url) { - if (strlen($item['author-link'])) { + if ($url != '') { + $best_url = $url; + } elseif (strlen($item['author-link'])) { $best_url = $item['author-link']; } else { $best_url = $item['url']; @@ -943,12 +957,6 @@ function best_link_url($item, &$sparkle, $ssl_state = false) { function item_photo_menu($item) { - $ssl_state = false; - - if (local_user()) { - $ssl_state = true; - } - $sub_link = ''; $poke_link = ''; $contact_url = ''; @@ -963,7 +971,7 @@ function item_photo_menu($item) { } $sparkle = false; - $profile_link = best_link_url($item, $sparkle, $ssl_state); + $profile_link = best_link_url($item, $sparkle); if ($profile_link === 'mailbox') { $profile_link = ''; } diff --git a/include/items.php b/include/items.php index db426fd82..d8f615a2c 100644 --- a/include/items.php +++ b/include/items.php @@ -1178,8 +1178,8 @@ function item_body_set_hashtags(&$item) { $URLSearchString = "^\[\]"; - // All hashtags should point to the home server if "local_search" is activated - if (Config::get('system', 'local_search')) { + // All hashtags should point to the home server if "local_tags" is activated + if (Config::get('system', 'local_tags')) { $item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", "#[url=".App::get_baseurl()."/search?tag=$2]$2[/url]", $item["body"]); diff --git a/include/text.php b/include/text.php index 1d1515c17..cd271676c 100644 --- a/include/text.php +++ b/include/text.php @@ -1326,6 +1326,14 @@ function prepare_body(&$item, $attach = false, $preview = false) { $tag["url"] = $searchpath.strtolower($tag["term"]); } + $orig_tag = $tag["url"]; + + $tag["url"] = best_link_url($item, $sp, $tag["url"]); + + if ($orig_tag != $tag["url"]) { + $item['body'] = str_replace($orig_tag, $tag["url"], $item['body']); + } + if ($tag["type"] == TERM_HASHTAG) { $hashtags[] = "#".$tag["term"].""; $prefix = "#"; diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 91fa49618..ba845e41f 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -511,7 +511,8 @@ function dfrn_poll_content(App $a) { $dest = App::get_baseurl() . '/profile/' . $profile; break; default: - $dest = $destination_url . '?f=&redir=1'; + $appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1'); + $dest = $destination_url . $appendix; break; } diff --git a/object/Item.php b/object/Item.php index e8110f5ff..f81b8ea4e 100644 --- a/object/Item.php +++ b/object/Item.php @@ -180,7 +180,6 @@ class Item extends BaseObject { call_hooks('render_location',$locate); $location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate)); - $searchpath = "search?tag="; $tags=array(); $hashtags = array(); $mentions = array();