Hash tag links now do a redir
This commit is contained in:
parent
f8946c9e0a
commit
17b05c9ad9
7 changed files with 33 additions and 15 deletions
|
@ -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.
|
* **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_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_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** - 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_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.
|
* **max_contact_queue** - Default value is 500.
|
||||||
|
|
|
@ -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
|
// Always allowed protocol even if config isn't set or not including it
|
||||||
$allowed_link_protocols[] = 'http';
|
$allowed_link_protocols[] = 'http';
|
||||||
|
$allowed_link_protocols[] = 'redir/';
|
||||||
|
|
||||||
$regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism';
|
$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);
|
$Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text);
|
||||||
|
|
|
@ -358,7 +358,7 @@ function localize_item(&$item) {
|
||||||
$x = stristr($item['plink'],'/display/');
|
$x = stristr($item['plink'],'/display/');
|
||||||
if ($x) {
|
if ($x) {
|
||||||
$sparkle = false;
|
$sparkle = false;
|
||||||
$y = best_link_url($item, $sparkle, true);
|
$y = best_link_url($item, $sparkle);
|
||||||
|
|
||||||
if (strstr($y, '/redir/')) {
|
if (strstr($y, '/redir/')) {
|
||||||
$item['plink'] = $y . '?f=&url=' . $item['plink'];
|
$item['plink'] = $y . '?f=&url=' . $item['plink'];
|
||||||
|
@ -680,6 +680,8 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
|
||||||
$hashtags = array();
|
$hashtags = array();
|
||||||
$mentions = array();
|
$mentions = array();
|
||||||
|
|
||||||
|
$searchpath = App::get_baseurl()."/search?tag=";
|
||||||
|
|
||||||
$taglist = dba::select('term', array('type', 'term', 'url'),
|
$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("`otype` = ? AND `oid` = ? AND `type` IN (?, ?)", TERM_OBJ_POST, $item['id'], TERM_HASHTAG, TERM_MENTION),
|
||||||
array('order' => array('tid')));
|
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"] = $searchpath . strtolower($tag["term"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$tag["url"] = best_link_url($item, $sp, $tag["url"]);
|
||||||
|
|
||||||
if ($tag["type"] == TERM_HASHTAG) {
|
if ($tag["type"] == TERM_HASHTAG) {
|
||||||
$hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
|
$hashtags[] = "#<a href=\"" . $tag["url"] . "\" target=\"_blank\">" . $tag["term"] . "</a>";
|
||||||
$prefix = "#";
|
$prefix = "#";
|
||||||
|
@ -701,7 +705,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
|
||||||
dba::close($taglist);
|
dba::close($taglist);
|
||||||
|
|
||||||
$sp = false;
|
$sp = false;
|
||||||
$profile_link = best_link_url($item,$sp);
|
$profile_link = best_link_url($item, $sp);
|
||||||
if ($profile_link === 'mailbox') {
|
if ($profile_link === 'mailbox') {
|
||||||
$profile_link = '';
|
$profile_link = '';
|
||||||
}
|
}
|
||||||
|
@ -914,7 +918,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
|
||||||
return $o;
|
return $o;
|
||||||
}}
|
}}
|
||||||
|
|
||||||
function best_link_url($item, &$sparkle, $ssl_state = false) {
|
function best_link_url($item, &$sparkle, $url = '') {
|
||||||
|
|
||||||
$best_url = '';
|
$best_url = '';
|
||||||
$sparkle = false;
|
$sparkle = false;
|
||||||
|
@ -928,10 +932,20 @@ function best_link_url($item, &$sparkle, $ssl_state = false) {
|
||||||
if (dbm::is_result($r)) {
|
if (dbm::is_result($r)) {
|
||||||
$best_url = 'redir/' . $r['id'];
|
$best_url = 'redir/' . $r['id'];
|
||||||
$sparkle = true;
|
$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 (! $best_url) {
|
||||||
if (strlen($item['author-link'])) {
|
if ($url != '') {
|
||||||
|
$best_url = $url;
|
||||||
|
} elseif (strlen($item['author-link'])) {
|
||||||
$best_url = $item['author-link'];
|
$best_url = $item['author-link'];
|
||||||
} else {
|
} else {
|
||||||
$best_url = $item['url'];
|
$best_url = $item['url'];
|
||||||
|
@ -943,12 +957,6 @@ function best_link_url($item, &$sparkle, $ssl_state = false) {
|
||||||
|
|
||||||
|
|
||||||
function item_photo_menu($item) {
|
function item_photo_menu($item) {
|
||||||
$ssl_state = false;
|
|
||||||
|
|
||||||
if (local_user()) {
|
|
||||||
$ssl_state = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sub_link = '';
|
$sub_link = '';
|
||||||
$poke_link = '';
|
$poke_link = '';
|
||||||
$contact_url = '';
|
$contact_url = '';
|
||||||
|
@ -963,7 +971,7 @@ function item_photo_menu($item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$sparkle = false;
|
$sparkle = false;
|
||||||
$profile_link = best_link_url($item, $sparkle, $ssl_state);
|
$profile_link = best_link_url($item, $sparkle);
|
||||||
if ($profile_link === 'mailbox') {
|
if ($profile_link === 'mailbox') {
|
||||||
$profile_link = '';
|
$profile_link = '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -1178,8 +1178,8 @@ function item_body_set_hashtags(&$item) {
|
||||||
|
|
||||||
$URLSearchString = "^\[\]";
|
$URLSearchString = "^\[\]";
|
||||||
|
|
||||||
// All hashtags should point to the home server if "local_search" is activated
|
// All hashtags should point to the home server if "local_tags" is activated
|
||||||
if (Config::get('system', 'local_search')) {
|
if (Config::get('system', 'local_tags')) {
|
||||||
$item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
|
$item["body"] = preg_replace("/#\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
|
||||||
"#[url=".App::get_baseurl()."/search?tag=$2]$2[/url]", $item["body"]);
|
"#[url=".App::get_baseurl()."/search?tag=$2]$2[/url]", $item["body"]);
|
||||||
|
|
||||||
|
|
|
@ -1326,6 +1326,14 @@ function prepare_body(&$item, $attach = false, $preview = false) {
|
||||||
$tag["url"] = $searchpath.strtolower($tag["term"]);
|
$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) {
|
if ($tag["type"] == TERM_HASHTAG) {
|
||||||
$hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
|
$hashtags[] = "#<a href=\"".$tag["url"]."\" target=\"_blank\">".$tag["term"]."</a>";
|
||||||
$prefix = "#";
|
$prefix = "#";
|
||||||
|
|
|
@ -511,7 +511,8 @@ function dfrn_poll_content(App $a) {
|
||||||
$dest = App::get_baseurl() . '/profile/' . $profile;
|
$dest = App::get_baseurl() . '/profile/' . $profile;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$dest = $destination_url . '?f=&redir=1';
|
$appendix = (strstr($destination_url, '?') ? '&f=&redir=1' : '?f=&redir=1');
|
||||||
|
$dest = $destination_url . $appendix;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -180,7 +180,6 @@ class Item extends BaseObject {
|
||||||
call_hooks('render_location',$locate);
|
call_hooks('render_location',$locate);
|
||||||
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
|
$location = ((strlen($locate['html'])) ? $locate['html'] : render_location_dummy($locate));
|
||||||
|
|
||||||
$searchpath = "search?tag=";
|
|
||||||
$tags=array();
|
$tags=array();
|
||||||
$hashtags = array();
|
$hashtags = array();
|
||||||
$mentions = array();
|
$mentions = array();
|
||||||
|
|
Loading…
Reference in a new issue