#46314function http_makelinks does not find https links in Text (but could with some small changes)
Description
I would recommend that the function http_makelinks should also find “https://” in given text.
My solution to do this is like this:
(maybe there exists easier ways and maybe i am alone with this wish, but this works for me in 4.5.25)
1. rename “function http_makelinks” to “function http_makelinks_sub”
2. add 3. parameter scheme to renamede funktion
(so it looks like this: function http_makelinks_sub($data, $conf ,$scheme) {
3. add original function “function http_makelinks like this:
function http_makelinks($data, $conf) {
$datastep1 = $this->http_makelinks_sub($data, $conf ,"http://") ;
return $this->http_makelinks_sub( $datastep1, $conf ,"https://") ;
}
4. replace “http://” or ‘http://’ with $scheme 6 times in “function http_makelinks_sub”
so the result looks like this in Version 4.5.25:
/**
* Finds URLS in text and makes it to a real link.
* Will find all strings prefixed with "http://" OR "https://" in the $data string and make them into a link, linking to the URL we should have found.
*
* @param string The string in which to search for "http://"
* @param array Configuration for makeLinks, see link
* @return string The processed input string, being returned.
* @see _parseFunc()
*/
function http_makelinks($data, $conf) {
$datastep1 = $this->http_makelinks_sub($data, $conf ,"http://") ;
return $this->http_makelinks_sub( $datastep1, $conf ,"https://") ;
}
/**
* subfunction to http_makelinks: Finds URLS in text and makes it to a real link.
* Will find all strings prefixed with given $scheme in the $data string and make them into a link, linking to the URL we should have found.
*
* @param string The string in which to search for $sheme
* @param array Configuration for makeLinks, see link
* @param string scheme: "http://" or "https://"
* @return string The processed input string, being returned.
* @see _parseFunc()
*/
function http_makelinks_sub($data, $conf ,$scheme) {
$aTagParams = $this->getATagParams($conf);
$textpieces = explode($scheme, $data);
$pieces = count($textpieces);
$textstr = $textpieces[0];
$initP = '?id=' . $GLOBALS['TSFE']->id . '&type=' . $GLOBALS['TSFE']->type;
for ($i = 1; $i < $pieces; $i++) {
$len = strcspn($textpieces[$i], chr(32) . TAB . CRLF);
if (trim(substr($textstr, -1)) == '' && $len) {
$lastChar = substr($textpieces[$i], $len - 1, 1);
if (!preg_match('/[A-Za-z0-9\/#_-]/', $lastChar)) {
$len--;
} // Included '\/' 3/12
$parts[0] = substr($textpieces[$i], 0, $len);
$parts[1] = substr($textpieces[$i], $len);
$keep = $conf['keep'];
$linkParts = parse_url($scheme . $parts[0]);
$linktxt = '';
if (strstr($keep, 'scheme')) {
$linktxt = $scheme ;
}
$linktxt .= $linkParts['host'];
if (strstr($keep, 'path')) {
$linktxt .= $linkParts['path'];
if (strstr($keep, 'query') && $linkParts['query']) { // added $linkParts['query'] 3/12
$linktxt .= '?' . $linkParts['query'];
} elseif ($linkParts['path'] == '/') { // If query is NOT added and the path is '/' then remove the slash ('/') (added 3/12)
$linktxt = substr($linktxt, 0, -1);
}
}
$target = isset($conf['extTarget']) ? $conf['extTarget'] : $GLOBALS['TSFE']->extTarget;
if ($GLOBALS['TSFE']->config['config']['jumpurl_enable']) {
$jumpurl = $scheme . $parts[0];
$juHash = t3lib_div::hmac($jumpurl, 'jumpurl');
$res = '<a' . ' href="' . htmlspecialchars(($GLOBALS['TSFE']->absRefPrefix . $GLOBALS['TSFE']->config['mainScript'] . $initP . '&jumpurl=' . rawurlencode($jumpurl))) . '&juHash=' . $juHash . $GLOBALS['TSFE']->getMethodUrlIdToken . '"' . ($target ? ' target="' . $target . '"' : '') . $aTagParams . $this->extLinkATagParams(('http://' . $parts[0]), 'url') . '>';
} else {
$res = '<a' . ' href="'. $scheme . htmlspecialchars($parts[0]) . '"' .
($target ? ' target="' . $target . '"' : '') .
$aTagParams . $this->extLinkATagParams( $sheme . $parts[0], 'url') .
'>';
}
$wrap = isset($conf['wrap.'])
? $this->stdWrap($conf['wrap'], $conf['wrap.'])
: $conf['wrap'];
if ($conf['ATagBeforeWrap']) {
$res = $res . $this->wrap($linktxt, $wrap) . '</a>';
} else {
$res = $this->wrap($res . $linktxt . '</a>', $wrap);
}
$textstr .= $res . $parts[1];
} else {
$textstr .= $scheme . $textpieces[$i];
}
}
return $textstr;
}
PS: i added a DIFF file created with Eclipse on a a windows maschine after i upgraded to 4.5.25