Add compression negotiation to curl and enable default SSL verification.

This commit is contained in:
mm 2025-03-30 23:49:06 +08:00
parent 99af4fcd67
commit 0e90cd090d

View file

@ -12,7 +12,7 @@ class replaceEntryUrlExtension extends Minz_Extension {
throw new FreshRSS_Context_Exception('System configuration not initialised!'); throw new FreshRSS_Context_Exception('System configuration not initialised!');
} }
$save = false; $save = false;
/*If you want to replace it during refresh, uncomment this line and comment out the line below. it used in test*/ /*If you want to replace it during refresh, uncomment next line and comment out the line below. it used in test*/
//$this->registerHook('entry_before_display', [self::class, 'processEntry']); //$this->registerHook('entry_before_display', [self::class, 'processEntry']);
$this->registerHook('entry_before_insert', [self::class, 'processEntry']); $this->registerHook('entry_before_insert', [self::class, 'processEntry']);
if (FreshRSS_Context::userConf()->attributeString('replaceEntryUrl_matchUrlKeyValues') === null) { if (FreshRSS_Context::userConf()->attributeString('replaceEntryUrl_matchUrlKeyValues') === null) {
@ -45,7 +45,7 @@ class replaceEntryUrlExtension extends Minz_Extension {
* @throws FreshRSS_Context_Exception * @throws FreshRSS_Context_Exception
*/ */
public static function processEntry(FreshRSS_Entry $entry): FreshRSS_Entry { public static function processEntry(FreshRSS_Entry $entry): FreshRSS_Entry {
$useDefaultIfEmpty = FreshRSS_Context::userConf()->attributeBool('replaceEntryUrl_filterXPathContent') ?? false; $use_default_if_empty = FreshRSS_Context::userConf()->attributeBool('replaceEntryUrl_filterXPathContent') ?? self::GET_FULL_CONTENT;
$allow_array = ""; $allow_array = "";
$allow_url_str = FreshRSS_Context::userConf()->attributeString('replaceEntryUrl_matchUrlKeyValues'); $allow_url_str = FreshRSS_Context::userConf()->attributeString('replaceEntryUrl_matchUrlKeyValues');
if (!is_string($allow_url_str) || $allow_url_str === '') { if (!is_string($allow_url_str) || $allow_url_str === '') {
@ -75,7 +75,7 @@ class replaceEntryUrlExtension extends Minz_Extension {
$response = self::curlDownloadContent($link); $response = self::curlDownloadContent($link);
$article = ""; $article = "";
if($response != false){ if($response != false){
$article = self:: extractMainContent($response,$my_xpath,$useDefaultIfEmpty); $article = self:: extractMainContent($response,$my_xpath,$use_default_if_empty);
} }
if($article != ""){ if($article != ""){
$entry->_content ($article); $entry->_content ($article);
@ -93,9 +93,9 @@ class replaceEntryUrlExtension extends Minz_Extension {
if ($link !== '') { if ($link !== '') {
curl_setopt($ch, CURLOPT_URL, $link); curl_setopt($ch, CURLOPT_URL, $link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_ENCODING, "gzip, deflate");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Optional: set timeout curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch); $response = curl_exec($ch);
if (curl_errno($ch)) { if (curl_errno($ch)) {
error_log('cURL Error: ' . curl_error($ch)); error_log('cURL Error: ' . curl_error($ch));
@ -110,7 +110,7 @@ class replaceEntryUrlExtension extends Minz_Extension {
} }
public static function extractMainContent(string $content,string $my_xpath,bool $useDefaultIfEmpty): string { public static function extractMainContent(string $content,string $my_xpath,bool $use_default_if_empty): string {
$doc = new DOMDocument(); $doc = new DOMDocument();
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')); $doc->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
@ -121,7 +121,7 @@ class replaceEntryUrlExtension extends Minz_Extension {
if ($nodes instanceof DOMNodeList && $nodes->length > 0) { if ($nodes instanceof DOMNodeList && $nodes->length > 0) {
$mainContent = $doc->saveHTML($nodes->item(0)); $mainContent = $doc->saveHTML($nodes->item(0));
} }
elseif($useDefaultIfEmpty) elseif($use_default_if_empty)
{ {
$mainContent = $content; $mainContent = $content;
} }