getKey('basepath') . '?')) { $this->_error = 'Trying to shorten a URL that isn\'t pointing at our instance.'; return; } $data = $this->_getcontents($conf, $link); if ($data == null) { $this->_error = 'Error calling proxy. Probably a configuration issue'; error_log('Error calling proxy: ' . $this->_error); return; } if ($data === false) { $http_response_header = $http_response_header ?? array(); $statusCode = ''; if (!empty($http_response_header) && preg_match('/HTTP\/\d+\.\d+\s+(\d+)/', $http_response_header[0], $matches)) { $statusCode = $matches[1]; } $this->_error = 'Error calling proxy. HTTP request failed. Status code: ' . $statusCode; error_log('Error calling proxy: ' . $this->_error); return; } try { $data = Json::decode($data); } catch (Exception $e) { $this->_error = 'Error calling proxy. Probably a configuration issue, like wrong or missing config keys.'; error_log('Error calling proxy: ' . $e->getMessage()); return; } $url = $this->_extractShortUrl($data); if ($url === null) { $this->_error = 'Error calling proxy. Probably a configuration issue, like wrong or missing config keys.'; } else { $this->_url = $url; } } /** * Returns the (untranslated) error message * * @access public * @return string */ public function getError() { return $this->_error; } /** * Returns the shortened URL * * @access public * @return string */ public function getUrl() { return $this->_url; } /** * Returns true if any error has occurred * * @access public * @return bool */ public function isError() { return !empty($this->_error); } /** * Abstract method to get contents from a URL. * * @param Configuration $conf * @param string $link * @return mixed */ abstract protected function _getcontents(Configuration $conf, string $link); /** * Abstract method to extract the shortUrl from the response * * @param array $data * @return ?string */ abstract protected function _extractShortUrl(array $data): ?string; }