<commit_before><?php
/*
 * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
 * This file is part of Pydio.
 *
 * Pydio is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Pydio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Pydio.  If not, see <http://www.gnu.org/licenses/>.
 *
 * The latest code can be found at <http://pyd.io/>.
 */

defined('AJXP_EXEC') or die('Access not allowed');


class AJXP_SchemeTranslatorWrapper extends AJXP_MetaStreamWrapper implements AjxpWrapper
{
    /**
     * @var resource
     */
    protected $handle;

    /**
     * @var string
     */
    protected $currentDirPath;


    /**
     * Get a "usable" reference to a file : the real file or a tmp copy.
     *
     * @param string $path
     * @param bool $persistent
     * @return string
     * @throws Exception
     */
    public static function getRealFSReference($path, $persistent = false)
    {
        $wrapper = AJXP_MetaStreamWrapper::findSubWrapperClassName($path);
        return call_user_func(array($wrapper, "getRealFSReference"), AJXP_MetaStreamWrapper::translateScheme($path), $persistent);
    }

    /**
     * Read a file (by chunks) and copy the data directly inside the given stream.
     *
     * @param string $path
     * @param resource $stream
     */
    public static function copyFileInStream($path, $stream)
    {
        $wrapper = AJXP_MetaStreamWrapper::findSubWrapperClassName($path);
        call_user_func(array($wrapper, "copyFileInStream"), AJXP_MetaStreamWrapper::translateScheme($path), $stream);
    }

    /**
     * Chmod implementation for this type of access.
     *
     * @param string $path
     * @param number $chmodValue
     */
    public static function changeMode($path, $chmodValue)
    {
        $wrapper = AJXP_MetaStreamWrapper::findSubWrapperClassName($path);
        call_user_func(array($wrapper, "changeMode"), AJXP_MetaStreamWrapper::translateScheme($path), $chmodValue);
    }

    /**
     *
     *
     * @return bool
     */
    public function dir_closedir()
    {
        if(isSet($this->handle) && is_resource($this->handle)){
            closedir($this->handle);
        }
    }

    /**
     * Enter description here...
     *
     * @param string $path
     * @param int $options
     * @return bool
     */
    public function dir_opendir($path, $options)
    {
        $newPath = AJXP_MetaStreamWrapper::translateScheme($path);
        $this->handle = opendir($newPath);
        if($this->handle !== false){
            $this->currentDirPath = parse_url($path, PHP_URL_PATH);
            return true;
        }else{
            return false;
        }
    }

    /**
     * Enter description here...
     *
     * @return string
     */
    public function dir_readdir()
    {
        if(isSet($this->handle) && is_resource($this->handle)){
            $value = readdir($this->handle);
            if($this->currentDirPath."/".$value == "/inbox") {
                return ".";
            } else {
                return $value;
            }
        }
        return false;
    }

    /**
     * Enter description here...
     *
     * @return bool
     */
    public function dir_rewinddir()
    {
        $this->currentDirPath = null;
        if(isSet($this->handle) && is_resource($this->handle)){
            return rewind($this->handle);
        }
        return false;
    }

    /**
     * Enter description here...
     *
     * @param string $path
     * @param int $mode
     * @param int $options
     * @return bool<commit_msg>Fix SchemeTranslatorWrapper. Store url instead of path when reading dir.<commit_after><?php
/*
 * Copyright 2007-2015 Abstrium <contact (at) pydio.com>
 * This file is part of Pydio.
 *
 * Pydio is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Pydio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with Pydio.  If not, see <http://www.gnu.org/licenses/>.
 *
 * The latest code can be found at <http://pyd.io/>.
 */

defined('AJXP_EXEC') or die('Access not allowed');


class AJXP_SchemeTranslatorWrapper extends AJXP_MetaStreamWrapper implements AjxpWrapper
{
    /**
     * @var resource
     */
    protected $handle;

    /**
     * @var string
     */
    protected $currentDirPath;


    /**
     * Get a "usable" reference to a file : the real file or a tmp copy.
     *
     * @param string $path
     * @param bool $persistent
     * @return string
     * @throws Exception
     */
    public static function getRealFSReference($path, $persistent = false)
    {
        $wrapper = AJXP_MetaStreamWrapper::findSubWrapperClassName($path);
        return call_user_func(array($wrapper, "getRealFSReference"), AJXP_MetaStreamWrapper::translateScheme($path), $persistent);
    }

    /**
     * Read a file (by chunks) and copy the data directly inside the given stream.
     *
     * @param string $path
     * @param resource $stream
     */
    public static function copyFileInStream($path, $stream)
    {
        $wrapper = AJXP_MetaStreamWrapper::findSubWrapperClassName($path);
        call_user_func(array($wrapper, "copyFileInStream"), AJXP_MetaStreamWrapper::translateScheme($path), $stream);
    }

    /**
     * Chmod implementation for this type of access.
     *
     * @param string $path
     * @param number $chmodValue
     */
    public static function changeMode($path, $chmodValue)
    {
        $wrapper = AJXP_MetaStreamWrapper::findSubWrapperClassName($path);
        call_user_func(array($wrapper, "changeMode"), AJXP_MetaStreamWrapper::translateScheme($path), $chmodValue);
    }

    /**
     *
     *
     * @return bool
     */
    public function dir_closedir()
    {
        if(isSet($this->handle) && is_resource($this->handle)){
            closedir($this->handle);
        }
    }

    /**
     * Enter description here...
     *
     * @param string $path
     * @param int $options
     * @return bool
     */
    public function dir_opendir($path, $options)
    {
        $newPath = AJXP_MetaStreamWrapper::translateScheme($path);
        $this->handle = opendir($newPath);
        if($this->handle !== false){
            $this->currentDirPath = $path;
            return true;
        }else{
            return false;
        }
    }

    /**
     * Enter description here...
     *
     * @return string
     */
    public function dir_readdir()
    {
        if(isSet($this->handle) && is_resource($this->handle)){
            return readdir($this->handle);
        }
        return false;
    }

    /**
     * Enter description here...
     *
     * @return bool
     */
    public function dir_rewinddir()
    {
        $this->currentDirPath = null;
        if(isSet($this->handle) && is_resource($this->handle)){
            return rewind($this->handle);
        }
        return false;
    }

    /**
     * Enter description here...
     *
     * @param string $path
     * @param int $mode
     * @param int $options
     * @return bool
{'fraction_non_alphanumeric': 0.11572246976448122, 'fraction_numerical': 0.0022915340547422025, 'mean_word_length': 2.3949870354364737, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4938086', 'n_tokens_mistral': 2294, 'n_tokens_neox': 2204, 'n_words': 637}