<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 <https://pydio.com>.
 */
namespace Pydio\Access\Driver\StreamProvider\Inbox;

use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\ContentFilter;
use Pydio\Access\Driver\StreamProvider\FS\FsAccessDriver;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Model\ContextInterface;

use Pydio\Core\Controller\Controller;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Services\ApplicationState;
use Pydio\Core\Utils\Vars\StatHelper;

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

/**
 * Driver for inbox repository
 * Class inboxAccessDriver
 * @package Pydio\Access\Driver\StreamProvider\Inbox
 */
class InboxAccessDriver extends FsAccessDriver
{
    private static $output;

    /**
     * @param ContextInterface $contextInterface
     * @throws PydioException
     * @throws \Exception
     */
    protected function initRepository(ContextInterface $contextInterface)
    {
        $this->urlBase = $contextInterface->getUrlBase();
    }

    /**
     * Hook to node.info event
     * @param AJXP_Node $ajxpNode
     * @param bool $parentNode
     * @param bool $details
     */
    public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
    {
        parent::loadNodeInfo($ajxpNode, $parentNode, $details);
        if(!$ajxpNode->isRoot()){

            // Retrieving stored details
            $originalNode = self::$output[$ajxpNode->getLabel()];
            if(isSet($originalNode["meta"])){
                $meta = $originalNode["meta"];
            }else{
                $meta = [];
            }
            $label = $originalNode["label"];

            if(!$ajxpNode->isLeaf()){
                $meta["icon"] = "mime_empty.png";
            }

            // Overriding display name with repository name
            $ajxpNode->setLabel($label);
            $ajxpNode->mergeMetadata($meta);
        }
    }

    /**
     * Hook for load_repository_info event
     * @param ContextInterface $ctx
     * @param $data
     */
    public function loadRepositoryInfo(ContextInterface $ctx, &$data){
        $allNodes = self::getNodes($ctx, false, false);
        $data['access.inbox'] = [
            'files' => count($allNodes)
        ];
    }

    /**
     * @param string $nodePath Url of a node
     * @return array|mixed
     */
    public static function getNodeData($nodePath){
        $nodeObject = new AJXP_Node($nodePath);
        $basename = $nodeObject->getLabel();
        if($nodeObject->isRoot()){
            return ['stat' => stat(ApplicationState::getTemporaryFolder())];
        }
        $allNodes = self::getNodes($nodeObject->getContext(), false);
        $nodeData = $allNodes[$basename];
        if(!isSet($nodeData["stat"])){
            if(in_array(pathinfo($basename, PATHINFO_EXTENSION), ["error", "invitation"])){
                $stat = stat(ApplicationState::getTemporaryFolder());
            }else{
                $url = $nodeData["url"];
                $node = new AJXP_Node($url);
                try{
                    $node->getDriver()->detectStreamWrapper(true);<commit_msg>Throw exception on error<commit_after><?php
/*
 * Copyright 2007-2015 Abstrium <contact (at) py<EMAIL>>
 * 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 <https://pydio.com>.
 */
namespace Pydio\Access\Driver\StreamProvider\Inbox;

use Pydio\Access\Core\Exception\FileNotFoundException;
use Pydio\Access\Core\Model\AJXP_Node;
use Pydio\Access\Core\Filter\ContentFilter;
use Pydio\Access\Driver\StreamProvider\FS\FsAccessDriver;
use Pydio\Core\Exception\PydioException;
use Pydio\Core\Model\ContextInterface;

use Pydio\Core\Controller\Controller;
use Pydio\Core\Services\LocaleService;
use Pydio\Core\Services\UsersService;
use Pydio\Core\Services\ApplicationState;
use Pydio\Core\Utils\Vars\StatHelper;

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

/**
 * Driver for inbox repository
 * Class inboxAccessDriver
 * @package Pydio\Access\Driver\StreamProvider\Inbox
 */
class InboxAccessDriver extends FsAccessDriver
{
    private static $output;

    /**
     * @param ContextInterface $contextInterface
     * @throws PydioException
     * @throws \Exception
     */
    protected function initRepository(ContextInterface $contextInterface)
    {
        $this->urlBase = $contextInterface->getUrlBase();
    }

    /**
     * Hook to node.info event
     * @param AJXP_Node $ajxpNode
     * @param bool $parentNode
     * @param bool $details
     */
    public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false)
    {
        parent::loadNodeInfo($ajxpNode, $parentNode, $details);
        if(!$ajxpNode->isRoot()){

            // Retrieving stored details
            $originalNode = self::$output[$ajxpNode->getLabel()];
            if(isSet($originalNode["meta"])){
                $meta = $originalNode["meta"];
            }else{
                $meta = [];
            }
            $label = $originalNode["label"];

            if(!$ajxpNode->isLeaf()){
                $meta["icon"] = "mime_empty.png";
            }

            // Overriding display name with repository name
            $ajxpNode->setLabel($label);
            $ajxpNode->mergeMetadata($meta);
        }
    }

    /**
     * Hook for load_repository_info event
     * @param ContextInterface $ctx
     * @param $data
     */
    public function loadRepositoryInfo(ContextInterface $ctx, &$data){
        $allNodes = self::getNodes($ctx, false, false);
        $data['access.inbox'] = [
            'files' => count($allNodes)
        ];
    }

    /**
     * @param string $nodePath Url of a node
     * @return array|mixed
     * @throws FileNotFoundException
     */
    public static function getNodeData($nodePath){
        $nodeObject = new AJXP_Node($nodePath);
        $basename = $nodeObject->getLabel();
        if($nodeObject->isRoot()){
            return ['stat' => stat(ApplicationState::getTemporaryFolder())];
        }
        $allNodes = self::getNodes($nodeObject->getContext(), false);
        if(!isSet($allNodes[$basename])){
            throw new FileNotFoundException($basename);
        }
        $nodeData = $allNodes[$basename];
        if(!isSet($nodeData["stat"])){
            if(in_array(pathinfo($basename, PATHINFO_EXTENSION), ["error", "invitation"])){
                $stat = stat(ApplicationState::getTemporaryFolder());
            }else{
                $url = $nodeData["url"];
                $node = new AJXP_Node($url);
                try{
                    $node->getDriver()->detectStreamWrapper(true);
{'fraction_non_alphanumeric': 0.12243629583592293, 'fraction_numerical': 0.0022374145431945307, 'mean_word_length': 2.7388475836431225, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 38, 'https://': 2, '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': '524496', 'n_tokens_mistral': 2343, 'n_tokens_neox': 2274, 'n_words': 580}