getKey('apiurl', 'chhoto'); } /** * Overrides the abstract parent function to get contents from Chhoto API. * * @access protected * @param Configuration $conf * @param string $link * @return array */ protected function _getProxyPayload(Configuration $conf, string $link): array { $apiKey = $conf->getKey('apikey', 'chhoto'); $body = [ 'shortlink' => '', // empty = auto-generate 'longlink' => $link, 'expiry_delay' => 0, // 0 = never expire 'notes' => 'PrivateBin paste', ]; try { return [ 'method' => 'POST', 'header' => "Content-Type: application/json\r\n" . 'X-API-Key: ' . $apiKey . "\r\n" . "Accept: application/json\r\n", 'content' => Json::encode($body), ]; } catch (JsonException $e) { error_log('[' . get_class($this) . '] Error encoding body: ' . $e->getMessage()); return []; } } /** * Extracts the short URL from the Chhoto API response. * * @access protected * @param array $data * @return ?string */ protected function _extractShortUrl(array $data): ?string { // Chhoto usually returns "shorturl" if (!empty($data['shorturl'])) { return $data['shorturl']; } // Fallback for older versions that return only the slug if (!empty($data['shortlink'])) { $apiUrl = $this->_getProxyUrl(new Configuration()); // not ideal, but works // Better: hardcode or get base from config return 'https://lix.sk/' . ltrim($data['shortlink'], '/'); } return null; } }