<commit_before><?php

/**
 * CommandCollection
 *
 * @author Team phpManufaktur <<EMAIL>>
 * @link https://kit2.phpmanufaktur.de
 * @copyright 2012 <NAME> <<EMAIL>>
 * @license MIT License (MIT) http://www.opensource.org/licenses/MIT
 */

namespace phpManufaktur\CommandCollection\Control\ExcelRead;

use phpManufaktur\Basic\Control\kitCommand\Basic;
use Silex\Application;

require_once MANUFAKTUR_PATH.'/CommandCollection/Control/ExcelRead/BiffWorkbook/CompoundDocument.inc.php';
require_once MANUFAKTUR_PATH.'/CommandCollection/Control/ExcelRead/BiffWorkbook/BiffWorkbook.inc.php';

class ExcelRead extends Basic
{
    /**
     * Initialize the iFrame for ExcelRead
     * Return the Welcome page if no file is specified. otherwise show the Excel file
     *
     * @param Application $app
     */
    public function InitFrame(Application $app)
    {
        // initialize the Basic class
        $this->initParameters($app);
        // get the command parameters
        $parameter = $this->getCommandParameters();

        if (!isset($parameter['file'])) {
            // missing the 'file' parameter, so show the welcome file from Gist
            return $this->createIFrame('/basic/help/excelread/welcome');
        }
        else {
            // execute ExcelRead within the iFrame
            return $this->createIFrame('/excelread/exec');
        }
    }

    /**
     * Show the specified Excel file
     *
     * @param Application $app
     * @throws \Exception
     * @return string rendered Excel file
     */
    public function Exec(Application $app)
    {
        // initialize the Basic class
        $this->initParameters($app);
        // get the command parameters
        $parameter = $this->getCommandParameters();

        // check the parameter 'base'
        if (!isset($parameter['base'])) {
            $base = 'cms_media';
        }
        else {
            $base_array = array('cms_media', 'media', 'media_protected', 'path', 'url');
            $base = strtolower($parameter['base']);
            if (!in_array($base, $base_array)) {
                throw new \Exception("The value '$base' for the parameter 'base' is unknown!");
            }
        }

        // check the parameter 'file'
        if (!isset($parameter['file'])) {
            throw new \Exception("Missing the parameter 'file'!");
        }

        if ($base == 'url') {
            $file = trim($parameter['file']);
        }
        else {
            $file = $this->app['utils']->sanitizePath(trim($parameter['file']));
            if ($file[0] != '/') {
                $file = '/'.$file;
            }
        }

        // build the path
        switch ($base) {
            case 'cms_media':
                $path = CMS_MEDIA_PATH.$file; break;
            case 'media':
                $path = FRAMEWORK_MEDIA_PATH.$file; break;
            case 'media_protected':
                $path = FRAMEWORK_MEDIA_PROTECTED_PATH.$file; break;
            case 'url':
            case 'path':
                $path = $file; break;
            default:
                throw new \Exception("Missing the handling for the 'base' parameter with the value $base");
        }
<commit_msg>added urlencode for URL mode<commit_after><?php

/**
 * CommandCollection
 *
 * @author Team phpManufaktur <<EMAIL>>
 * @link https://kit2.phpmanufaktur.de
 * @copyright 2012 <NAME> <<EMAIL>>
 * @license MIT License (MIT) http://www.opensource.org/licenses/MIT
 */

namespace phpManufaktur\CommandCollection\Control\ExcelRead;

use phpManufaktur\Basic\Control\kitCommand\Basic;
use Silex\Application;

require_once MANUFAKTUR_PATH.'/CommandCollection/Control/ExcelRead/BiffWorkbook/CompoundDocument.inc.php';
require_once MANUFAKTUR_PATH.'/CommandCollection/Control/ExcelRead/BiffWorkbook/BiffWorkbook.inc.php';

class ExcelRead extends Basic
{
    /**
     * Initialize the iFrame for ExcelRead
     * Return the Welcome page if no file is specified. otherwise show the Excel file
     *
     * @param Application $app
     */
    public function InitFrame(Application $app)
    {
        // initialize the Basic class
        $this->initParameters($app);
        // get the command parameters
        $parameter = $this->getCommandParameters();

        if (!isset($parameter['file'])) {
            // missing the 'file' parameter, so show the welcome file from Gist
            return $this->createIFrame('/basic/help/excelread/welcome');
        }
        else {
            // execute ExcelRead within the iFrame
            return $this->createIFrame('/excelread/exec');
        }
    }

    /**
     * Show the specified Excel file
     *
     * @param Application $app
     * @throws \Exception
     * @return string rendered Excel file
     */
    public function Exec(Application $app)
    {
        // initialize the Basic class
        $this->initParameters($app);
        // get the command parameters
        $parameter = $this->getCommandParameters();

        // check the parameter 'base'
        if (!isset($parameter['base'])) {
            $base = 'cms_media';
        }
        else {
            $base_array = array('cms_media', 'media', 'media_protected', 'path', 'url');
            $base = strtolower($parameter['base']);
            if (!in_array($base, $base_array)) {
                throw new \Exception("The value '$base' for the parameter 'base' is unknown!");
            }
        }

        // check the parameter 'file'
        if (!isset($parameter['file'])) {
            throw new \Exception("Missing the parameter 'file'!");
        }

        if ($base == 'url') {
            $file = trim($parameter['file']);
        }
        else {
            $file = $this->app['utils']->sanitizePath(trim($parameter['file']));
            if ($file[0] != '/') {
                $file = '/'.$file;
            }
        }

        // build the path
        switch ($base) {
            case 'cms_media':
                $path = CMS_MEDIA_PATH.$file; break;
            case 'media':
                $path = FRAMEWORK_MEDIA_PATH.$file; break;
            case 'media_protected':
                $path = FRAMEWORK_MEDIA_PROTECTED_PATH.$file; break;
            case 'url':
                $path = urlencode($file); break;
            case 'path':
                $path = $file; break;
            default:
                throw new \Exception("Missing the handling for the 'base' parameter with the value $base");
        }

{'fraction_non_alphanumeric': 0.12872670807453415, 'fraction_numerical': 0.0018633540372670807, 'mean_word_length': 2.0656830080913853, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '7367268', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1739, 'n_words': 441}