diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index df82802..c9dc99d 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -374,21 +374,25 @@ class H5PDefaultStorage implements \H5PFileStorage { $target = $this->getEditorPath(); } - $content_files = array_diff(scandir($content_path), array('.','..', 'content.json')); - foreach ($content_files as $file) { - if (is_dir($source)) { - self::copyFileTree($source, $taget); + $contentSource = $source . DIRECTORY_SEPARATOR . 'content'; + $contentFiles = array_diff(scandir($contentSource), array('.','..', 'content.json')); + foreach ($contentFiles as $file) { + if (is_dir($contentSource)) { + self::copyFileTree($contentSource, $target); } else { - copy($tmp_file_path, $editor_file_path); + copy($contentSource . DIRECTORY_SEPARATOR . $file, $target . DIRECTORY_SEPARATOR . $file); } } // Successfully loaded content json of file into editor - $h5pJson = $this->getContent($path . DIRECTORY_SEPARATOR . 'h5p.json'); - $contentJson = $core->fs->getContent($path . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . 'content.json'); + $h5pJson = $this->getContent($source . DIRECTORY_SEPARATOR . 'h5p.json'); + $contentJson = $this->getContent($contentSource . DIRECTORY_SEPARATOR . 'content.json'); - return array(); + return (object) array( + 'h5pJson' => $h5pJson, + 'contentJson' => $contentJson + ); } /** diff --git a/h5p.classes.php b/h5p.classes.php index 13c271d..a48efa0 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -584,12 +584,6 @@ interface H5PFrameworkInterface { * containing the new content type cache that should replace the old one. */ public function replaceContentTypeCache($contentTypeCache); - - public function getLatestLibraryVersions(); - - public function getContentTypeCache(); - - public function getAuthorsRecentlyUsedLibraries(); } /** @@ -1712,6 +1706,9 @@ abstract class H5PDisplayOptionBehaviour { const CONTROLLED_BY_PERMISSIONS = 4; } +abstract class H5PHubEndpoints { + const CONTENT_TYPES = 'api.h5p.org/v1/content-types/'; +} /** * Functions and storage shared by the other H5P classes @@ -1742,12 +1739,6 @@ class H5PCore { 'js/h5p-utils.js', ); - const CONTENT_TYPES = 0; - - public static $hubEndpoints = array( - self::CONTENT_TYPES => 'api.h5p.org/v1/content-types/' - ); - public static $defaultContentWhitelist = 'json png jpg jpeg gif bmp tif tiff svg eot ttf woff woff2 otf webm mp4 ogg mp3 txt pdf rtf doc docx xls xlsx ppt pptx odt ods odp xml csv diff patch swf md textile'; public static $defaultLibraryWhitelistExtras = 'js css'; @@ -2812,7 +2803,7 @@ class H5PCore { $postData['current_cache'] = $this->h5pF->getOption('content_type_cache_updated_at', 0); $protocol = (extension_loaded('openssl') ? 'https' : 'http'); - $endpoint = H5PCore::$hubEndpoints[H5PCore::CONTENT_TYPES]; + $endpoint = H5PHubEndpoints::CONTENT_TYPES; $data = $interface->fetchExternalData("{$protocol}://{$endpoint}", $postData); // No data received @@ -2842,145 +2833,6 @@ class H5PCore { return $data; } - /** - * Extract library properties from cached library so they are ready to be - * returned as JSON - * - * @param object $cached_library A single library from the content type cache - * - * @return array A map containing the necessary properties for a cached - * library to send to the front-end - */ - public function getCachedLibsMap($cached_library) { - // Add mandatory fields - $lib = array( - 'id' => intval($cached_library->id), - 'machineName' => $cached_library->machine_name, - 'majorVersion' => intval( $cached_library->major_version), - 'minorVersion' => intval($cached_library->minor_version), - 'patchVersion' => intval($cached_library->patch_version), - 'h5pMajorVersion' => intval($cached_library->h5p_major_version), - 'h5pMinorVersion' => intval($cached_library->h5p_minor_version), - 'title' => $cached_library->title, - 'summary' => $cached_library->summary, - 'description' => $cached_library->description, - 'icon' => $cached_library->icon, - 'createdAt' => intval($cached_library->created_at), - 'updatedAt' => intval($cached_library->updated_at), - 'isRecommended' => $cached_library->is_recommended != 0, - 'popularity' => intval($cached_library->popularity), - 'screenshots' => json_decode($cached_library->screenshots), - 'license' => $cached_library->license, - 'owner' => $cached_library->owner, - 'installed' => FALSE, - 'isUpToDate' => FALSE, - 'restricted' => isset($cached_library->restricted) ? $cached_library->restricted : FALSE - ); - - // Add optional fields - if (!empty($cached_library->categories)) { - $lib['categories'] = json_decode($cached_library->categories); - } - if (!empty($cached_library->keywords)) { - $lib['keywords'] = json_decode($cached_library->keywords); - } - if (!empty($cached_library->tutorial)) { - $lib['tutorial'] = $cached_library->tutorial; - } - if (!empty($cached_library->example)) { - $lib['example'] = $cached_library->example; - } - - return $lib; - } - - /** - * Merge local libraries into cached libraries so that local libraries will - * get supplemented with the additional info from externally cached libraries. - * - * Also sets whether a given cached library is installed and up to date with - * the locally installed libraries - * - * @param array $local_libraries Locally installed libraries - * @param array $cached_libraries Cached libraries from the H5P hub - */ - public function mergeLocalLibsIntoCachedLibs($local_libraries, &$cached_libraries) { - $can_create_restricted = $this->h5pF->hasPermission(H5PPermission::CREATE_RESTRICTED); - - // Add local libraries to supplement content type cache - foreach ($local_libraries as $local_lib) { - $is_local_only = TRUE; - - // Check if icon is available locally: - if($local_lib->has_icon) { - // Create path to icon: - $library_folder = H5PCore::libraryToString(array( - 'machineName' => $local_lib->machine_name, - 'majorVersion' => $local_lib->major_version, - 'minorVersion' => $local_lib->minor_version - ), TRUE); - $icon_path = $this->h5pF->getLibraryFileUrl($library_folder, 'icon.svg'); - } - - foreach ($cached_libraries as &$cached_lib) { - // Determine if library is local - $is_matching_library = $cached_lib['machineName'] === $local_lib->machine_name; - if ($is_matching_library) { - $is_local_only = FALSE; - - // Set icon if it exists locally - if(isset($icon_path)) { - $cached_lib['icon'] = $icon_path; - } - - // Set local properties - $cached_lib['installed'] = TRUE; - $cached_lib['restricted'] = $can_create_restricted ? FALSE - : $local_lib->restricted; - - // Determine if library is the same as ct cache - $is_updated_library = - $cached_lib['majorVersion'] === $local_lib->major_version && - $cached_lib['minorVersion'] === $local_lib->minor_version && - $cached_lib['patchVersion'] === $local_lib->patch_version; - - if ($is_updated_library) { - $cached_lib['isUpToDate'] = TRUE; - } - } - } - - // Add minimal data to display local only libraries - if ($is_local_only) { - $local_only_lib = array( - 'id' => $local_lib->id, - 'machineName' => $local_lib->machine_name, - 'majorVersion' => $local_lib->major_version, - 'minorVersion' => $local_lib->minor_version, - 'patchVersion' => $local_lib->patch_version, - 'installed' => TRUE, - 'isUpToDate' => TRUE, - 'restricted' => $can_create_restricted ? FALSE : $local_lib->restricted - ); - - if (isset($icon_path)) { - $local_only_lib['icon'] = $icon_path; - } - - $cached_libraries[] = $local_only_lib; - } - } - - // Restrict LRS dependent content - if (!$this->h5pF->getOption('enable_lrs_content_types')) { - foreach ($cached_libraries as &$lib) { - if ($lib['machineName'] === 'H5P.Questionnaire') { - $lib['restricted'] = TRUE; - } - } - } - } - /** * Check if the current server setup is valid and set error messages * @@ -3113,46 +2965,6 @@ class H5PCore { return $can; } - - /** - * Gets content type cache, applies user specific properties and formats - * as camelCase. - * - * @return array $libraries Cached libraries from the H5P Hub with user specific - * permission properties - */ - public function getUserSpecificContentTypeCache() { - $cached_libraries = $this->h5pF->getContentTypeCache(); - - // Determine access - $can_install_all = $this->h5pF->hasPermission(H5PPermission::UPDATE_LIBRARIES); - $can_install_recommended = $this->h5pF->hasPermission(H5PPermission::INSTALL_RECOMMENDED); - - - // Check if user has access to install libraries and format to json - $libraries = array(); - foreach ($cached_libraries as &$result) { - $can_install_lib = $can_install_all || $result->is_recommended && $can_install_recommended; - $result->restricted = !$can_install_lib; - $libraries[] = $this->getCachedLibsMap($result); - } - - return $libraries; - } - - /** - * Gets local and external libraries data with metadata to display - * all libraries that are currently available for the user. - * - * @return array $libraries Latest local and external libraries data with - * user specific permissions - */ - public function getLatestGlobalLibrariesData() { - $latest_local_libraries = $this->h5pF->getLatestLibraryVersions(); - $cached_libraries = $this->getUserSpecificContentTypeCache(); - $this->mergeLocalLibsIntoCachedLibs($latest_local_libraries, $cached_libraries); - return $cached_libraries; - } } /**