Check if an extension is allowed to be uploaded.

@param  null $extension
@return bool
@throws \Exception
338894
private function isAllowedExtension($extension = null)
    {
        if(!$extension && $this->extension) {
            $extension = $this->extension;
        }

        if(!$extension) {
            throw new \Exception("No extension given");
        }

        if(array_intersect([strtolower($extension),strtoupper($extension)], self::allowedExtensions())) {
            return true;
        }
        return false;
    }
671682
public function hasSettingsForm(ExtensionContract $extension) : bool {
        $className = $extension->getRootNamespace() . self::$formClassName;

        return class_exists($className);
    }
672429
public static function mustBeEnabled(common_ext_Extension $extension) {
        foreach (common_ext_ExtensionsManager::singleton()->getEnabledExtensions() as $ext) {
            foreach ($ext->getDependencies() as $extId => $version) {
                if ($extId == $extension->getId()) {
                    return true;
                }
            }
        }
        return false;
    }
229117
public function getAllowedMaxFileSize($ext = null)
    {

        // Check if there is any defined instance max file sizes
        if (empty($this->allowedMaxFileSize)) {
            // Set default max file sizes if there isn't
            $fileSize = Config::inst()->get(__CLASS__, 'default_max_file_size');
            if ($fileSize) {
                $this->setAllowedMaxFileSize($fileSize);
            } else {
                // When no default is present, use maximum set by PHP
                $maxUpload = File::ini2bytes(ini_get('upload_max_filesize'));
                $maxPost = File::ini2bytes(ini_get('post_max_size'));
                $this->setAllowedMaxFileSize(min($maxUpload, $maxPost));
            }
        }

        if ($ext !== null) {
            $ext = strtolower($ext);
            if (isset($this->allowedMaxFileSize[$ext])) {
                return $this->allowedMaxFileSize[$ext];
            }

            $category = File::get_app_category($ext);
            if ($category && isset($this->allowedMaxFileSize['[' . $category . ']'])) {
                return $this->allowedMaxFileSize['[' . $category . ']'];
            }
        }

        return (isset($this->allowedMaxFileSize['*'])) ? $this->allowedMaxFileSize['*'] : false;
    }
990377
protected function _shouldSkipExtension($extension) {
		$whitelist = Configure::read('IdeHelper.templateExtensions') ?: static::TEMPLATE_EXTENSIONS;

		return !in_array($extension, $whitelist, true);
	}
1148475
public static function hasExtension($extension) {
		static::ensureDataLoaded();

		$extension = strtolower($extension);
		foreach (static::$mime_types as $extensions) {
			if (is_array($extensions)) {
				if (in_array($extension, $extensions, true)) {
					return true;
				}
			} else if ($extension === $extensions) {
				return true;
			}
		}

		return false;
	}
578440
private function normalizeFileExtension($extension = null)
    {
        $extension = strtolower($extension ? $extension : $this->extension);

        if ($extension == 'jpeg') {
                $extension = 'jpg';
        }

        return $extension;
    }
741894
public function enable($extension)
    {
        if (empty($extension)) {
            return false;
        }

        if (!$this->hasCapability('ENABLE')) {
            return false;
        }

        if (!is_array($extension)) {
            $extension = array($extension);
        }

        if (!empty($this->extensions_enabled)) {
            // check if all extensions are already enabled
            $diff = array_diff($extension, $this->extensions_enabled);

            if (empty($diff)) {
                return $extension;
            }

            // Make sure the mailbox isn't selected, before enabling extension(s)
            if ($this->selected !== null) {
                $this->close();
            }
        }

        list($code, $response) = $this->execute('ENABLE', $extension, 0, '/^\* ENABLED /i');

        if ($code == self::ERROR_OK && $response) {
            $response = substr($response, 10); // remove prefix "* ENABLED "
            $result   = (array) $this->tokenizeResponse($response);

            $this->extensions_enabled = array_unique(array_merge((array)$this->extensions_enabled, $result));

            return $this->extensions_enabled;
        }

        return false;
    }
943974
public function setAllowedExtensions($extensions)
    {
        if (is_string($extensions)) {
            $extensions = explode(',', $extensions);
        }

        $this->allowedExtensions = array_map('trim', $extensions);

        return $this;
    }
1147916
public static function getMimeType($extension)
    {
        if (!isset(self::$mimeTypes[$extension])) {
            return null;
        }

        return self::$mimeTypes[$extension];
    }
761957
public function getFilters($extension = null)
    {
        if ($extension === null) {
            return $this->filters;
        }
        elseif (isset($this->filters[$extension])) {
            return $this->filters[$extension];
        }
        else {
            return null;
        }
    }
1240240
public function getBundles($extension = null)
    {
        if ($extension === null) {
            return $this->bundles;
        }
        elseif (isset($this->bundles[$extension])) {
            return $this->bundles[$extension];
        }
        else {
            return null;
        }
    }
820076
public static function fromExtension($extension)
	{
		$extension = strtolower($extension);

		return isset(static::$mimetypes[$extension])
			? static::$mimetypes[$extension]
			: null;
	}
624694
public function acceptsExtension($ext)
    {
        $ext = trim(strtolower($ext), ".");

        if ($this->getRequiredExtension() && $ext !== $this->getRequiredExtension()) {
            return false;
        }

        if ($this->getAllowedExtensions() && !in_array($ext, $this->getAllowedExtensions())) {
            return false;
        }

        if ($this->getRejectedExtensions() && in_array($ext, $this->getRejectedExtensions())) {
            return false;
        }

        return true;
    }
77958
private function checkFileExtension($extension)
    {
        $valid = array('jpg', 'jpeg', 'png', 'gif', 'webp');

        in_array(strtolower($extension), $valid)
            or $this->raiseError('Not a valid file extension.');

        return $this;
    }
342960
public static boolean hasExtension(String extension) {
        if (extension == null || extension.isEmpty()) {
            return false;
        }
        return extensionToMimeTypeMap.containsKey(extension);
    }
299178
public function checkExt($ext)
    {
        if (strpos($ext, '.')) {
            $ext = pathinfo($ext, PATHINFO_EXTENSION);
        }
        if (strpos($this->allowedExts, $ext) === false) {
            return false;
        } else {
            return true;
        }
    }