• First of all, thanks for your plugin. I just switched to a different hoster. This hoster has disabled allow_url_fopen and neither allows to change this setting via .htaccess or .user.ini nor is willing to change this setting. As a consequence, “view” links no longer work.

    From what I understand, this is due to WP_Publication_Archive::open_link() using readfile() which in turn uses fopen() to read the content of a file from a (possibly) remote location. This seems to be deprecated, a growing number of hosters disable allow_url_fopen.

    For now, I’ve applied a quick fix, replacing readfile( $uri ) in WP_Publication_Archive::open_link() with fsockopen, but it’s ugly and doesn’t work (I get the HTTP headers wrong; it’s been a long day and will give up for now, maybe I’ll have another look at another time):

    if ( 'https://' == substr( $uri, 0, 7 ) ) {
    	$noschema = explode( '/', substr( $uri, 7 ), 2 );
    	$host = $noschema[0];
    	$path = $noschema[1];
    
    	$socket = fsockopen( $host, 80 );
    	if ( $socket ) {
    		$out = 'GET /' . $path . " HTTP/1.1\n" .
    			'Host: ' . $host . "\n" .
    			"Connection: close\n\n";
    		fwrite( $socket, $out );
    		while ( ! feof( $socket ) ) {
    			echo fread( $socket, 8192 );
    		}
    		fclose( $socket );
    	} else {
    		trigger_error( 'Could not connect to ' . $host, E_USER_ERROR );
    	}
    }

    Of course, this fix will be gone with the next update. Could you look into this? Thanks a lot!

    https://www.ads-software.com/plugins/wp-publication-archive/

Viewing 1 replies (of 1 total)
  • Thread Starter jpod

    (@jpod)

    So, this is my new work around, which works, sort of (i.e., it displays HTTP URIs, but lacks proper error handling of any sort). I’d really appreciate if you would include a saner solution.

    if ( 'https://' == substr( $uri, 0, 7 ) ) {
    	$noschema = explode( '/', substr( $uri, 7 ), 2 );
    	$host = $noschema[0];
    	$path = $noschema[1];
    
    	$socket = fsockopen( $host, 80 );
    	if ( $socket ) {
    		$http_request = 'GET /' . $path . " HTTP/1.1\n" .
    			'Host: ' . $host . "\n" .
    			"Connection: close\n\n";
    		fwrite( $socket, $http_request );
    
    		while ( ! feof( $socket ) ) {
    			$line = fgets( $socket );
    			if ( "\n" == $line || "\r\n" == $line ) {
    				break;
    			}
    		}
    		while ( ! feof( $socket ) ) {
    			print fread( $socket, 8192 );
    		}
    
    		fclose( $socket );
    	} else {
    		trigger_error( 'Could not connect to ' . $host, E_USER_ERROR );
    	}
    } else {
    
    // Return the file
    	ob_clean();
    	flush();
    	readfile( $uri );
    }
Viewing 1 replies (of 1 total)
  • The topic ‘Could you drop the allow_url_fopen requirement?’ is closed to new replies.