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

@ -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.

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 = "#";

View file

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

View file

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