direct_mail icon indicating copy to clipboard operation
direct_mail copied to clipboard

Statistic - Link to linkedin.com -> Status code must be an integer value between 1xx and 5xx

Open bernd-reindl opened this issue 3 years ago • 2 comments

Linkedin returns HTTP 999 in some cases. (https://stackoverflow.com/questions/46214017/public-linkedin-profile-url-returns-server-status-code-999/49856601)

If so .... $content = GeneralUtility::getURL($url); in \DirectMailTeam\DirectMail\Module\Statistics::getLinkLabel() throws an exception (Status code must be an integer value between 1xx and 5xx) and the statistics can't be shown.

I have added a try..catch Block around the method call to avoid the statistic break. try { $content = GeneralUtility::getURL($url); } catch(\Exception $e) { $content = ''; }

Maybe this is useful for others too.

bernd-reindl avatar Sep 21 '21 14:09 bernd-reindl

I can confirm that this patch solves the problem.

I would suggest to wrap the whole content fetching into an if statement because it is only needed when either showContentTitle or prependContentTitle is set to 1 in configuration:

if ($this->params['showContentTitle'] == 1 || $this->params['prependContentTitle'] == 1) {
	$urlParts = parse_url($url);
	if (!$forceFetch && (substr($url, 0, strlen($pathSite)) === $pathSite)) {
		if ($urlParts['fragment'] && (substr($urlParts['fragment'], 0, 1) == 'c')) {
			// linking directly to a content
			$elementUid = intval(substr($urlParts['fragment'], 1));
			$row = BackendUtility::getRecord('tt_content', $elementUid);
			if ($row) {
				$contentTitle = BackendUtility::getRecordTitle('tt_content', $row, false, true);
			}
		} else {
			$contentTitle = $this->getLinkLabel($url, $urlStr, true);
		}
	} else {
		if (empty($urlParts['host']) && (substr($url, 0, strlen($pathSite)) !== $pathSite)) {
			// it's internal
			$url = $pathSite . $url;
		}

		try { $content = GeneralUtility::getURL($url); } catch(\Exception $e) { $content = ''; }

		if (preg_match('/\<\s*title\s*\>(.*)\<\s*\/\s*title\s*\>/i', $content, $matches)) {
			// get the page title
			$contentTitle = GeneralUtility::fixed_lgd_cs(trim($matches[1]), 50);
		} else {
			// file?
			$file = GeneralUtility::split_fileref($url);
			$contentTitle = $file['file'];
		}
	}
}

fishgit avatar Feb 11 '22 09:02 fishgit

We had the same problem and decided to just remove this handling since the usufulness of using website titles here is questionable.

lorenzulrich avatar Dec 03 '22 15:12 lorenzulrich