Hash tag links now do a redir

This commit is contained in:
Michael
2017-08-19 09:22:50 +00:00
parent f8946c9e0a
commit 17b05c9ad9
7 changed files with 33 additions and 15 deletions

View File

@@ -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);

View File

@@ -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[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
$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 = '';
}

View File

@@ -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"]);

View File

@@ -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[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
$prefix = "#";