Get the file type in the POST request.

@param array $dataPost The POST data sent by the client.
@throws \Exception An exception is thrown when the POST data doesn't contain the key "templateType"
15678
public function GetFileType($dataPost) {
        $templateTypeKey = "templateType";
        if (!array_key_exists($templateTypeKey, $dataPost)) {
            throw new \Exception("The POST data doesn't contain the value $templateTypeKey. See dump" . var_dump($dataPost), 0, null);
        }

        $this->templateType = $dataPost[$templateTypeKey];
        return $this;
    }
1079453
public function downloadAction(Request $request, DataExport $dataExport)
    {
        $explode = explode('/', $dataExport->getPath());
        $fileName = end($explode);
        $file = $this->getParameter('kernel.root_dir'). '/../web/uploads/data_export/'.$dataExport->getPath();
        $response = new BinaryFileResponse($file);
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $fileName);

        return $response;
    }
115761
public function getFileTypeWidget(\DataContainer $dc)
  {
    $doc = $dc->activeRecord;

    return '
<div class="w50 widget">
  <h3><label for="ctrl_purge">'.$GLOBALS['TL_LANG']['tl_dms_documents']['data_file_type'][0].'</label></h3>
  <input type="text" class="tl_text" value="' . $doc->data_file_type . '" disabled="">
  <p class="tl_help tl_tip">'.$GLOBALS['TL_LANG']['tl_dms_documents']['data_file_type'][1].'</p>
</div>';
  }
1349237
public function setDataType($dataType)
    {
        $formDefinition = $this->getRootForm();
        $formDefinition->getProcessingRule($this->getIdentifier())->setDataType($dataType);
    }
331464
static function getArrayType($type){
        self::isArray($type) or \PhpBoot\abort(new \InvalidArgumentException("$type is not array"));
        if($type == 'array') {
            return 'mixed';
        }else{
            return substr($type,0,-2);
        }
    }
262120
@Override
    protected FileType doGetType() throws Exception {
        // JDK BUG: 6192331
        // if (!file.exists())
        if (!file.exists() && file.length() < 1) {
            return FileType.IMAGINARY;
        }

        if (file.isDirectory()) {
            return FileType.FOLDER;
        }

        // In doubt, treat an existing file as file
        // if (file.isFile())
        // {
        return FileType.FILE;
        // }

        // throw new FileSystemException("vfs.provider.local/get-type.error", file);
    }
303474
public function uploadAction() {
        $request = $this->getRequest();
        if (!$uploadType = $request->getParam('type')) {
            throw new Exception('When uploading files, \'type\' is a required parameter.');
        }

        if ($uploadType == self::UPLOAD_TYPE_ALL) {
            $uploadType = Garp_File::TYPE_DOCUMENTS;
            $filename = $request->getParam('filename');
            if (!$filename) {
                throw new Exception('When using type "all" a filename must be specified.');
            }
            $dotPos = strpos($filename, '.');
            if ($dotPos !== false) {
                $extension = substr($filename, $dotPos+1);
                $gif = new Garp_Image_File();
                if (in_array($extension, $gif->getAllowedExtensions())) {
                    $uploadType = Garp_File::TYPE_IMAGES;
                }
            }
        }
        $response   = array();
        $success    = false;
        if ($request->isPost()) {
            // Upload the file
            if ('raw' === $request->getParam('mode')) {
                $rawPostData = $request->getRawBody();
                $filename = $request->getParam('filename');
                if (!$filename) {
                    throw new Exception('When using raw upload-mode a filename must be specified.');
                }
                $response = $this->_helper->upload->uploadRaw($uploadType, $filename, $rawPostData);
                $success = true;
            } else {
                try {
                    $response = $this->_helper->upload(
                        $uploadType, null, false,
                        1 === (int)$this->getRequest()->getParam('overwrite')
                    );
                    $success = true;
                } catch (Exception $e) {
                    $response['messages'] = $e->getMessage();
                }
            }
            // Also create a new record for the uploaded file
            if ($request->getParam('insert') && $request->getParam('insert')) {
                $modelClass = Garp_File::TYPE_IMAGES == $uploadType ? 'Model_Image' :
                    'Model_Document';
                // create new record here...
                $model = new $modelClass();
                $model->setCmsContext(true);
                $_response = array();
                foreach ($response as $key => $value) {
                    // @todo Add method that allows the other columns of $model
                    // to be set via POST.
                    $data = array('filename' => $value);
                    if ($uploadType === Garp_File::TYPE_DOCUMENTS) {
                        // Create name from basename without extension.
                        $name = substr($value, 0, strrpos($value, '.'));
                        $data['name'] = $name;
                    }
                    $primary = $model->insert($data);
                    // Alter response a little to include columns
                    $_response[$key] = array(
                        'id' => $primary,
                        'filename' => $value
                    );
                }
                $response = $_response;
            }
        } else {
            throw new Exception('No POST data received.');
        }

        $response['success'] = $success;
        $this->_helper->layout->setLayout('blank');
        $this->view->response = $response;
    }
656553
public function parsePost(array $post)
    {
        $ret = [];
        foreach ($post as $key => $value) {
            if ($key) {
                $external  = $this->translateKeyOutput($key);
                $ret[$key] = [];
                if (strlen($value) > 0) {
                    if ($internal = $this->translateValueInput($external, $value)) {
                        $value = $internal;
                    }
                    $ret[$key][] = $value;
                }
            }
        }

        return $ret;
    }
360861
private function _validateDataType($data)
  {
    if(empty($this->allowed_file_types))
      return true;

    $finfo = new \finfo(FILEINFO_MIME_TYPE);

    if(!in_array($finfo->file($data['tmp_name']), $this->allowed_file_types))
      throw new FileTypeNotAllowedException();

    return true;
  }
703348
public function getPageTemplates(string $templateType = null)
    {
        $toolbox = $this->container->toolbox;
        $json = $this->container->json;

        // Validate inputs
        if ($templateType !== null && !in_array($templateType, ['page','collection'])) {
            throw new Exception("PitonCMS Unexpected $templateType paramter. Expecting 'page' or 'collection'");
        }

        $jsonPath = ROOT_DIR . "structure/definitions/pages/";
        $templates = [];

        foreach ($toolbox->getDirectoryFiles($jsonPath) as $row) {
            // Get definition files
            if (null === $definition = $json->getJson($jsonPath . $row['filename'], 'page')) {
                $this->setAlert('danger', 'Page JSON Definition Error', $json->getErrorMessages());
                break;
            }

            if ($templateType !== null && $definition->templateType !== $templateType) {
                continue;
            }

            $templates[] = [
                'filename' => $row['filename'],
                'name' => $definition->templateName,
                'description' => $definition->templateDescription
            ];
        }

        return $templates;
    }
776927
public static function copyFile($files, $dataPost, $caller) {

        $manager = $caller->managers()->getDalInstance("Document");
        $manager->setRootDirectory($caller->app()->config()->get(\Puzzlout\Framework\Enums\AppSettingKeys::RootDocumentUpload));
        $manager->setWebDirectory($caller->app()->config()->get(\Puzzlout\Framework\Enums\AppSettingKeys::BaseUrl) . $caller->app()->config()->get(\Puzzlout\Framework\Enums\AppSettingKeys::RootUploadsFolderPath));
        $directory = str_replace("_id", "", $dataPost['itemCategory']);
        $manager->setObjectDirectory($directory);
        if ($dataPost['itemReplace'] === "true") {
            $manager->selectManyByCategoryAndId($dataPost['itemCategory'], $dataPost['itemId']);
        }
        $manager->setFilenamePrefix($dataPost['itemId'] . '_');
        $document = new \Applications\EasyMvc\Models\Dao\Document();
        $document->setDocument_category($dataPost['itemCategory']);
        if (isset($dataPost['title']) && $dataPost['title'] != "") {
            $document->setDocument_title($dataPost['title']);
        } else {
            $document->setDocument_title($files['file']['name']);
        }

        $manager->copyWithFile($document, $files['file']);
    }
312346
public function getDataType(string $dataTypeHandle)
    {
        if (!isset($this->dataTypes[$dataTypeHandle])) {
            Schematic::error('DataType '.$dataTypeHandle.' is not registered');

            return null;
        }

        $dataTypeClass = $this->dataTypes[$dataTypeHandle];
        if (!class_exists($dataTypeClass)) {
            Schematic::error('Class '.$dataTypeClass.' does not exist');

            return null;
        }

        $dataType = new $dataTypeClass();
        if (!$dataType instanceof DataTypeInterface) {
            Schematic::error($dataTypeClass.' does not implement DataTypeInterface');

            return null;
        }

        return $dataType;
    }
109929
public static function get_request_type_string($requesttype) {
        $types = self::get_request_types();
        if (!isset($types[$requesttype])) {
            throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
        }
        return $types[$requesttype];
    }
926338
public function setPostData($post): HttpParser
    {
        if (is_array($post)) {
            $post = http_build_query($post);
        }

        $this
            ->setHeadersParam('Content-Type', 'application/x-www-form-urlencoded')
            ->setHeadersParam('Content-Length', (string)strlen($post));

        $this->headers_is_post = $post;

        return $this;
    }
379913
public function getFileType(): ?array
    {
        if (empty($this->byteCache)) {
            return null;
        }

        /** cache */
        if (is_null($this->fileType)) {
            $this->fileType = $this->checkFileType();
        }

        return $this->fileType;
    }
1165913
private function hasTemplateForPost(\WP_Post $post): bool
    {
        $postTemplate = get_post_meta($post->ID, '_wp_page_template', true);

        $templates = isset($this->template[$post->post_type]) ? $this->template[$post->post_type] : [];

        if (empty($templates)) {
            // No templates exist for the current post type so we let
            // pass through either in order to display the metabox.
            return true;
        }

        return in_array($postTemplate, $templates, true);
    }
919232
public function convert($type, $data)
    {
        foreach ($data as $k => $v) {
            if (is_array($v)) {
                $data[$k] = $this->convert($type, $v);
            }
        }

        switch (strtolower($type)) {
        case 'array':
            return (array) $data;
            break;
        case 'object':
            return (object) $data;
            break;
        default:
            throw new \Exception('Invalid conversion type given!');
        }
    }