From 9dd710a8fb3f5f92ceb97d9dc8d8b07d20f208c4 Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Thu, 14 Nov 2013 23:42:10 +0100 Subject: [PATCH] Renaming functions --- h5p.classes.php | 206 ++++++++++++++++++++++++------------------------ js/h5p.js | 2 +- 2 files changed, 104 insertions(+), 104 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 33375b9..5f22337 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -246,109 +246,7 @@ interface H5PFrameworkInterface { /** * Check if export is enabled. */ - public function exportEnabled(); -} - -/** -* This class is used for exporting zips -*/ -Class H5PExport { - public $h5pF; - public $h5pC; - - /** - * Constructor for the H5PStorage - * - * @param object $H5PFramework - * The frameworks implementation of the H5PFrameworkInterface - */ - public function __construct($H5PFramework, $H5PCore) { - $this->h5pF = $H5PFramework; - $this->h5pC = $H5PCore; - } - /** - * Create the h5p package - * - * @param object $exports - * The data to be exported. - * @return h5p package. - */ - public function exportToZip($exports) { - $h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR; - $tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $exports['contentId']; - $zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $exports['contentId'] . '.h5p'; - // Check if h5p-package already exists. - if (!file_exists($zipPath) == true) { - // Temp dir to put the h5p files in - @mkdir($tempPath); - $this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $exports['contentId'], $tempPath . DIRECTORY_SEPARATOR . 'content'); - // Copies libraries to temp dir and create mention in h5p.json - foreach($exports['libraries'] as $library) { - $source = $h5pDir . 'libraries' . DIRECTORY_SEPARATOR . $library['machineName'] . '-' . $library['majorVersion'] . '.' . $library['minorVersion']; - $destination = $tempPath . DIRECTORY_SEPARATOR . $library['machineName']; - $this->h5pC->copyTree($source, $destination); - - // Set preloaded and dynamic dependencies - if ($library['preloaded']) { - $preloadedDependencies[] = array( - 'machineName' => $library['machineName'], - 'majorVersion' => $library['majorVersion'], - 'minorVersion' => $library['minorVersion'], - ); - } else { - $dynamicDependencies[] = array( - 'machineName' => $library['machineName'], - 'majorVersion' => $library['majorVersion'], - 'minorVersion' => $library['minorVersion'], - ); - } - } - // Make embedTypes into an array - $embedTypes = explode(', ', $exports['embedType']); - - // Build h5p.json - $h5pJson = array ( - 'title' => $exports['title'], - 'language' => $exports['language'], - 'mainLibrary' => $exports['mainLibrary'], - 'embedTypes' => $embedTypes, - ); - // Add preloaded and dynamic dependencies if they exist - if ($preloadedDependencies) { $h5pJson['preloadedDependencies'] = $preloadedDependencies; } - if ($dynamicDependencies) { $h5pJson['dynamicDependencies'] = $dynamicDependencies; } - - // Save h5p.json - $results = print_r(json_encode($h5pJson), true); - file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'h5p.json', $results); - - // Create new zip instance. - $zip = new ZipArchive(); - $zip->open($zipPath, ZIPARCHIVE::CREATE); - - // Get all files and folders in $tempPath - $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR)); - // Add files to zip - foreach ($iterator as $key=>$value) { - $test = '.'; - // Do not add the folders '.' and '..' to the zip. This will make zip invalid. - if (substr_compare($key, $test, -strlen($test), strlen($test)) !== 0) { - // Get files path in $tempPath - $filePath = explode($tempPath . DIRECTORY_SEPARATOR, $key); - // Add files to the zip with the intended file-structure - $zip->addFile($key, $filePath[1]); - } - } - // Close zip and remove temp dir - $zip->close(); - @rmdir($tempPath); - } - - // Set headers for automagic download!! - header('Content-Description: File Transfer'); - header('Content-Type: application/zip'); - header('Content-Disposition: attachment; filename=' . $exports['title'] . '.h5p'); - readfile ($zipPath); - } + public function isExportEnabled(); } /** @@ -1133,6 +1031,108 @@ class H5PStorage { } } +/** +* This class is used for exporting zips +*/ +Class H5PExport { + public $h5pF; + public $h5pC; + + /** + * Constructor for the H5PStorage + * + * @param object $H5PFramework + * The frameworks implementation of the H5PFrameworkInterface + */ + public function __construct($H5PFramework, $H5PCore) { + $this->h5pF = $H5PFramework; + $this->h5pC = $H5PCore; + } + /** + * Create the h5p package + * + * @param object $exports + * The data to be exported. + * @return h5p package. + */ + public function exportToZip($exports) { + $h5pDir = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR; + $tempPath = $h5pDir . 'temp' . DIRECTORY_SEPARATOR . $exports['contentId']; + $zipPath = $h5pDir . 'exports' . DIRECTORY_SEPARATOR . $exports['contentId'] . '.h5p'; + // Check if h5p-package already exists. + if (!file_exists($zipPath) == true) { + // Temp dir to put the h5p files in + @mkdir($tempPath); + $this->h5pC->copyTree($h5pDir . 'content' . DIRECTORY_SEPARATOR . $exports['contentId'], $tempPath . DIRECTORY_SEPARATOR . 'content'); + // Copies libraries to temp dir and create mention in h5p.json + foreach($exports['libraries'] as $library) { + $source = $h5pDir . 'libraries' . DIRECTORY_SEPARATOR . $library['machineName'] . '-' . $library['majorVersion'] . '.' . $library['minorVersion']; + $destination = $tempPath . DIRECTORY_SEPARATOR . $library['machineName']; + $this->h5pC->copyTree($source, $destination); + + // Set preloaded and dynamic dependencies + if ($library['preloaded']) { + $preloadedDependencies[] = array( + 'machineName' => $library['machineName'], + 'majorVersion' => $library['majorVersion'], + 'minorVersion' => $library['minorVersion'], + ); + } else { + $dynamicDependencies[] = array( + 'machineName' => $library['machineName'], + 'majorVersion' => $library['majorVersion'], + 'minorVersion' => $library['minorVersion'], + ); + } + } + // Make embedTypes into an array + $embedTypes = explode(', ', $exports['embedType']); + + // Build h5p.json + $h5pJson = array ( + 'title' => $exports['title'], + 'language' => $exports['language'], + 'mainLibrary' => $exports['mainLibrary'], + 'embedTypes' => $embedTypes, + ); + // Add preloaded and dynamic dependencies if they exist + if ($preloadedDependencies) { $h5pJson['preloadedDependencies'] = $preloadedDependencies; } + if ($dynamicDependencies) { $h5pJson['dynamicDependencies'] = $dynamicDependencies; } + + // Save h5p.json + $results = print_r(json_encode($h5pJson), true); + file_put_contents($tempPath . DIRECTORY_SEPARATOR . 'h5p.json', $results); + + // Create new zip instance. + $zip = new ZipArchive(); + $zip->open($zipPath, ZIPARCHIVE::CREATE); + + // Get all files and folders in $tempPath + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tempPath . DIRECTORY_SEPARATOR)); + // Add files to zip + foreach ($iterator as $key=>$value) { + $test = '.'; + // Do not add the folders '.' and '..' to the zip. This will make zip invalid. + if (substr_compare($key, $test, -strlen($test), strlen($test)) !== 0) { + // Get files path in $tempPath + $filePath = explode($tempPath . DIRECTORY_SEPARATOR, $key); + // Add files to the zip with the intended file-structure + $zip->addFile($key, $filePath[1]); + } + } + // Close zip and remove temp dir + $zip->close(); + @rmdir($tempPath); + } + + // Set headers for automagic download!! + header('Content-Description: File Transfer'); + header('Content-Type: application/zip'); + header('Content-Disposition: attachment; filename=' . $exports['title'] . '.h5p'); + readfile ($zipPath); + } +} + /** * Functions and storage shared by the other H5P classes */ diff --git a/js/h5p.js b/js/h5p.js index 3a9b15d..b14d893 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -64,7 +64,7 @@ H5P.init = function () { }); }; - if (H5PIntegration.getExport()) { + if (H5PIntegration.isExportEnabled()) { H5P.jQuery('
Last ned H5P
').insertAfter($el).children(); } });