public function getFilePaths($libraryId) { $file_paths = array('js' => array(), 'css' => array()); $h5p_core = H5PJoomla::getInstance('core'); $h5p_joomla = H5PJoomla::getInstance('interface'); $h5p_path = $h5p_joomla->getH5pPath(); // Ensure paths exists. $lib_path = 'media/h5p/libraries/'; $db = JFactory::getDbo(); $db->setQuery(sprintf("SELECT hl.preloaded_css, hl.preloaded_js, hl.library_id, hl.machine_name as machineName, hl.major_version as majorVersion, hl.minor_version as minorVersion\n\t\t\t FROM #__h5p_libraries hl\n\t\t\tWHERE hl.library_id = %d", (int) $libraryId)); $results = $db->loadAssocList(); foreach ($results as $paths) { if (!empty($paths['preloaded_js'])) { foreach (explode(',', $paths['preloaded_js']) as $js_path) { $file_paths['js'][] = $lib_path . $h5p_core->libraryToString($paths, TRUE) . '/' . trim($js_path); } } if (!empty($paths['preloaded_css'])) { foreach (explode(',', $paths['preloaded_css']) as $css_path) { $file_paths['css'][] = $lib_path . $h5p_core->libraryToString($paths, TRUE) . '/' . trim($css_path); } } } return $file_paths; }
public function delete(&$pks) { $h5p_storage = H5PJoomla::getInstance('storage'); $pks = (array) $pks; foreach ($pks as $i => $pk) { // Let the H5P library handle removal of files and database rows. $h5p_storage->deletePackage($pk); } }
} else { // Get Title, JSON and main library for given H5P content ID. $header = 'Edit H5P'; $db = JFactory::getDbo(); $db->setQuery(sprintf("SELECT h.title, h.json_content, hl.machine_name as machineName, hl.major_version as majorVersion, hl.minor_version as minorVersion, hl.semantics\n\t\t\tFROM #__h5p as h, #__h5p_libraries as hl\n\t\t\tWHERE h.h5p_id=%s\n\t\t\t AND h.main_library_id=hl.library_id", $db->quote($contentId))); $res = $db->loadAssoc(); $h5p_core = H5PJoomla::getInstance('core'); $mainLibrary = $h5p_core->libraryToString($res); $title = $res['title']; // Get H5P params as object $h5p_params = json_decode($res['json_content']); // Validate and filter against main library semantics. This is done // after the hook above, to prevent modules that might inject invalid // data in the content. $h5p_joomla = H5PJoomla::getInstance('interface'); $validator = H5PJoomla::getInstance('contentvalidator'); $semantics = $h5p_joomla->getLibrarySemantics($res['machineName'], $res['majorVersion'], $res['minorVersion']); $validator->validateBySemantics($h5p_params, $semantics); $jsonContent = json_encode($h5p_params); } $h5p_path = JURI::root(true) . '/media/h5p'; $ajaxPath = JURI::root(true) . '/index.php?option=com_h5p&format=raw&task='; $js = "var h5peditordata = {\n\tfileIcon: {\n\t\tpath: \"{$fileIconPath}\",\n\t\twidth: 50,\n\t\theight: 50\n\t},\n\tajaxPath: \"{$ajaxPath}\",\n\tbasePath: \"{$editorbase}\",\n\tcontentId: \"{$contentId}\"\n};\nH5PIntegration = H5PIntegration || {};\nH5PIntegration.jsonContentPath = \"{$h5p_path}/content/\";\nH5PIntegration.libraryPath = \"{$h5p_path}/libraries/\";\n\n// Joomla stylesheets interferes massively with our CSS due to its use of\n// scoping everything in #main. Therefore, rename #main within our little\n// iFrame.\n// PS: domready is Mootools. jQuery.ready() does not work properly in iFrames\nwindow.addEvent('domready', function() {\n\tH5P.jQuery('#main').attr('id', 'joomlamain');\n});\n"; $doc->addScriptDeclaration($js); $formaction = JURI::root(true) . '/index.php?option=com_h5p&task=save&tmpl=component&cid=' . $contentId; ?> <h2 id="h5phead"><?php echo $header; ?> </h2> <form id="h5peditor-form" method="post" action="<?php
public function save() { $input = JFactory::getApplication()->input; $contentId = $input->getVar('cid'); // Cannot use input->get() here. It eats all HTML, with no option to // tell it not to... H5P does its own XSS filtering of HTML fields, // but it does so when returning it from the database. $h5p_params = $_POST['edit-h5p-params']; $library = $input->get('edit-h5p-library', '', 'string'); $h5p_core = H5PJoomla::getInstance('core'); $h5p_joomla = H5PJoomla::getInstance('interface'); $library_data = $h5p_core->libraryFromString($library); $libraryId = $h5p_joomla->getLibraryId($library_data['machineName'], $library_data['majorVersion'], $library_data['minorVersion']); $db = JFactory::getDbo(); $jsonQuoted = $db->quote($h5p_params); $title = $input->get('h5p-title', 'My H5P', 'string'); if (!$title) { $title = 'Untitled ' . $library_data['machineName']; } $titleQuoted = $db->quote($title); $db->setQuery(sprintf("INSERT INTO #__h5p (h5p_id, title, json_content, embed_type, main_library_id)\n\t\t\t VALUES (%s, %s, %s, 'div, iframe', %d)\n\t\t\t ON DUPLICATE KEY UPDATE title=%s, json_content=%s, main_library_id=%d", $db->quote($contentId), $titleQuoted, $jsonQuoted, $libraryId, $titleQuoted, $jsonQuoted, $libraryId)); $db->query(); $storage = H5PJoomla::getInstance('editorstorage'); $h5pStorage = H5PJoomla::getInstance('storage'); $editor = new H5peditor($storage, JPATH_ROOT . DIRECTORY_SEPARATOR . 'media', JURI::root(true), $h5pStorage); if (!$editor->createDirectories($contentId)) { print "<p>Unable to create content directories on the server. Please contact the system administrator.</p>"; return; } // Move files. $editor->processParameters($contentId, $library_data, json_decode($h5p_params), NULL, NULL); // Response HTML header('Content-Type: text/html'); print "\n\t\t\t<script type=\"text/javascript\">\n\t\t\t\twindow.parent.insertH5P('{$contentId}', '{$title}');\n\t\t\t</script>\n\t\t"; }