Пример #1
0
        public void libraryUpload(string[] uploadFilePath, string[] contentId)
        {
            if (uploadFilePath != null)
            {
                H5PCore.ajaxError(this.core.t("Could not get posted H5P."), "NO_CONTENT_TYPE", 0);
                return;
            }

            var file = this.saveFileTemporarily(uploadFilePath, true);

            if (!file)
            {
                return;
            }

            if (!this.isValidPackage())
            {
                return;
            }

            var storage = new H5PStorage(h5pF, core);

            storage.savePackage(null, null, true);

            var content = this.core.moveContentDirectory(this.getUploadedH5pFolderPath(), contentId);

            this.storage.removeTemporarilySavedFiles(this.core.getUploadedH5pFolderPath());

            Dictionary <string, dynamic> ht = new Dictionary <string, dynamic>();

            ht.Add("h5p", content.h5pJson());
            ht.Add("content", content.contentJson());
            ht.Add("contentTypes", this.getContentTypeCache());
            H5PCore.ajaxSuccess(ht);
        }
Пример #2
0
 public void libraryInstall(string[] machineName)
 {
     if (machineName != null)
     {
         H5PCore.ajaxError(this.core.t("No content type was specified."), "NO_CONTENT_TYPE", 0);
         return;
     }
 }
Пример #3
0
 public bool isHubOn()
 {
     if (!this.core.getOption("hub_is_enabled", true))
     {
         H5PCore.ajaxError(this.core.t("The hub is disabled. You can enable it in the H5P settings"), "HUB_DISABLED", 403);
         return(false);
     }
     return(true);
 }
Пример #4
0
 ////    /**
 ////     * Clean up temporary files
 ////     *
 ////     * @param string $filePath Path to file or directory
 ////     */
 public static void removeTemporarilySavedFiles(string filePath) ////    public static function removeTemporarilySavedFiles($filePath)
 {                                                               ////    {
     if (File.Exists(filePath))                                  ////        if (is_dir($filePath))
     {                                                           ////        {
         H5PCore.deleteFileTree(filePath);                       ////            \H5PCore::deleteFileTree($filePath);
     }////        }
     else////        else
     {                     ////        {
         unlink(filePath); ////            @unlink($filePath);
     }////        }
 }////    }
Пример #5
0
        public bool isValidEditorToken(string[] token)
        {
            isValidToken = this.editor.validateEditorToken(token[0]);

            if (!isValidToken)
            {
                H5PCore.ajaxError(this.core.t("Invalid security token"), "INVALID_TOKEN", 0);
                return(false);
            }
            return(true);
        }
Пример #6
0
        public bool saveFileTemporarily(string[] data, bool move_file = false)
        {
            var file = this.storage.saveFileTemporarily(data, move_file);

            if (!file)
            {
                H5PCore.ajaxError(this.core.t("Failed to download the requested H5P."), "DOWNLOAD_FAILED", 0);
                return(false);
            }
            return(file);
        }
Пример #7
0
        public bool callHubEndpoint(string endpoint)
        {
            var path     = this.core.getUploadedH5pPath();
            var response = this.core.fetchExternalData(H5PHubEndpoints.createURL(endpoint), null, true, string.IsNullOrEmpty(path) ? null : path);

            if (!response)
            {
                H5PCore.ajaxError(this.core.t("Failed to download the requested H5P"), "DOWNLOAD_FAILED", null, this.core.getMessages("error"));
                return(false);
            }
            return(true);
        }
Пример #8
0
        public bool isPostRequest()
        {
            var _SERVER = new Dictionary <string, dynamic>();

            _SERVER.Add("REQUEST_METHOD", "POST");
            if (_SERVER["REQUEST_METHOD"] != "POST")
            {
                H5PCore.ajaxError(this.core.t("A post message is required to access the given endpoint"), "REQUIRES_POST", 405);
                return(false);
            }
            return(true);
        }
Пример #9
0
        public bool isValidPackage(bool skipContent = false)
        {
            var validator = new H5PValidator(this.h5pF, this.core);

            if (!validator.isValidPackage(skipContent, false))
            {
                this.storage.removeTemporarilySavedFiles(this.core.getUploadedH5pPath());

                H5PCore.ajaxError(this.core.t("Validating h5p package failed."), "VALIDATION_FAILED", null, this.core.getMessages("Error"));
                return(false);
            }
            return(true);
        }
Пример #10
0
        public void fileUpload(int contentId = 0)
        {
            file = new H5peditorFile(this.core.h5pF);
            if (!file.isLoaded())
            {
                H5PCore.ajaxError(this.core.t("File not found on server. Check file upload settings."));
                return;
            }

            if (file.validate())
            {
                var file_id = this.core.saveFile(file, 0);
                this.storage.markFileForCleanup(file_id);
            }

            file.printResult();
        }
Пример #11
0
        public void action(string endpoint)
        {
            var token      = new string[1];
            var uploadPath = new string[2];
            var contentId  = new string[3];

            switch (endpoint)
            {
            case H5PEditorEndpoints.LIBRARIES:
                H5PCore.ajaxSuccess(this.editor.getLibraries(), true);
                break;

            case H5PEditorEndpoints.SINGLE_LIBRARY:
                //$args = func_get_args();
                //array_shift($args);
                //$library = call_user_func_array(
                //array($this->editor, 'getLibraryData'), $args
                //);
                Dictionary <string, dynamic> library = null;   //Temporary declaration
                H5PCore.ajaxSuccess(library, true);

                break;

            case H5PEditorEndpoints.CONTENT_TYPE_CACHE:
                if (!this.isHubOn())
                {
                    return;
                }
                H5PCore.ajaxSuccess(this.getContentTypeCache(!this.isContentTypeCacheUpdated()), true);
                break;

            case H5PEditorEndpoints.LIBRARY_INSTALL:
                if (!this.isPostRequest())
                {
                    return;
                }

                if (!this.isValidEditorToken(token))
                {
                    return;
                }

                var machineName = new string[2];
                this.libraryInstall(machineName);
                break;

            case H5PEditorEndpoints.LIBRARY_UPLOAD:
                if (!this.isPostRequest())
                {
                    return;
                }

                token      = new string[1];
                uploadPath = new string[2];
                contentId  = new string[3];
                if (!this.isValidEditorToken(token))
                {
                    return;
                }

                this.libraryUpload(uploadPath, contentId);
                break;

            case H5PEditorEndpoints.FILES:
                token     = new string[1];
                contentId = new string[2];
                this.libraryUpload(uploadPath, contentId);
                break;
            }
        }