5 replaced http://stackoverflow.com/ with https://stackoverflow.com/
source | link

As @AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO@HPierce on SO.

As @AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO.

As @AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO.

4 replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
source | link

As @AlainSchlesser@AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO.

As @AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO.

As @AlainSchlesser suggested to follow the route (and as non working things always bug me), I retried building a stream wrapper for virtual files. I could not solve it (read: reading the return values on the docs) on my own, but solved it with the help of @HPierce on SO.

3 renamed class for clarity
source | link
class TemplateStreamWrapperVirtualTemplateWrapper
{
    public $context;

    public function stream_open( $path, $mode, $options, &$opened_path ) { return true; }

    public function stream_read( $count ) { return ''; }

    public function stream_eof() { return ''; }

    public function stream_stat() {
        # $user = posix_getpwuid( posix_geteuid() );
        $data = [
            'dev'     => 0,
            'ino'     => getmyinode(),
            'mode'    => 'r',
            'nlink'   => 0,
            'uid'     => getmyuid(),
            'gid'     => getmygid(),
            #'uid'     => $user['uid'],
            #'gid'     => $user['gid'],
            'rdev'    => 0,
            'size'    => 0,
            'atime'   => time(),
            'mtime'   => getlastmod(),
            'ctime'   => FALSE,
            'blksize' => 0,
            'blocks'  => 0,
        ];
        return array_merge( array_values( $data ), $data );
    }

    public function url_stat( $path, $flags ) {
        return $this->stream_stat();
    }
}
add_action( 'template_redirect', function() {
    stream_wrapper_register( 'virtual', 'TemplateStreamWrapper''VirtualTemplateWrapper' );
}, 0 );
class TemplateStreamWrapper
{
    public $context;

    public function stream_open( $path, $mode, $options, &$opened_path ) { return true; }

    public function stream_read( $count ) { return ''; }

    public function stream_eof() { return ''; }

    public function stream_stat() {
        # $user = posix_getpwuid( posix_geteuid() );
        $data = [
            'dev'     => 0,
            'ino'     => getmyinode(),
            'mode'    => 'r',
            'nlink'   => 0,
            'uid'     => getmyuid(),
            'gid'     => getmygid(),
            #'uid'     => $user['uid'],
            #'gid'     => $user['gid'],
            'rdev'    => 0,
            'size'    => 0,
            'atime'   => time(),
            'mtime'   => getlastmod(),
            'ctime'   => FALSE,
            'blksize' => 0,
            'blocks'  => 0,
        ];
        return array_merge( array_values( $data ), $data );
    }

    public function url_stat( $path, $flags ) {
        return $this->stream_stat();
    }
}
add_action( 'template_redirect', function() {
    stream_wrapper_register( 'virtual', 'TemplateStreamWrapper' );
}, 0 );
class VirtualTemplateWrapper
{
    public $context;

    public function stream_open( $path, $mode, $options, &$opened_path ) { return true; }

    public function stream_read( $count ) { return ''; }

    public function stream_eof() { return ''; }

    public function stream_stat() {
        # $user = posix_getpwuid( posix_geteuid() );
        $data = [
            'dev'     => 0,
            'ino'     => getmyinode(),
            'mode'    => 'r',
            'nlink'   => 0,
            'uid'     => getmyuid(),
            'gid'     => getmygid(),
            #'uid'     => $user['uid'],
            #'gid'     => $user['gid'],
            'rdev'    => 0,
            'size'    => 0,
            'atime'   => time(),
            'mtime'   => getlastmod(),
            'ctime'   => FALSE,
            'blksize' => 0,
            'blocks'  => 0,
        ];
        return array_merge( array_values( $data ), $data );
    }

    public function url_stat( $path, $flags ) {
        return $this->stream_stat();
    }
}
add_action( 'template_redirect', function() {
    stream_wrapper_register( 'virtual', 'VirtualTemplateWrapper' );
}, 0 );
2 Better safe then sorry: Unset the virtual pointer after usage
source | link
1
source | link