. /** * This is a very rough importer for powerpoint slides * Export a powerpoint presentation with powerpoint as html pages * Do it with office 2002 (I think?) and no special settings * Then zip the directory with all of the html pages * and the zip file is what you want to upload * * The script supports book and lesson. * * @version $Id: importppt.php,v 1.3 2012/07/25 11:16:05 bdaloukas Exp $ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License * @package lesson **/ require_once("../../config.php"); require_once("locallib.php"); $id = required_param('id', PARAM_INT); // Course Module ID. $pageid = optional_param('pageid', '', PARAM_INT); // Page ID. global $matches; if (! $cm = get_coursemodule_from_id('lesson', $id)) { print_error('Course Module ID was incorrect'); } if (! $course = $DB->get_record('course', array( 'id' => $cm->course))) { print_error('Course is misconfigured'); } // Allows for adaption for multiple modules. if (!$modname = $DB->get_field('modules', 'name', array( 'id' => $cm->module))) { print_error('Could not find module name'); } if (! $mod = $DB->get_record($modname, array( "id" => $cm->instance))) { print_error('Course module is incorrect'); } require_login($course->id, false); $context = get_context_instance(CONTEXT_MODULE, $cm->id); require_capability('mod/lesson:edit', $context); $strimportppt = get_string("importppt", "lesson"); $strlessons = get_string("modulenameplural", "lesson"); echo $OUTPUT->heading("$strimportppt", " $strimportppt", "id\">$strlessons". " -> wwwroot}/mod/$modname/view.php?id=$cm->id\">".format_string($mod->name, true)."-> $strimportppt"); if ($form = data_submitted()) { // Filename. if (empty($_FILES['newfile'])) { // File was just uploaded. notify(get_string("uploadproblem") ); } if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) { notify(get_string("uploadnofilefound") ); } else { // Valid file is found. if ($rawpages = readdata($_FILES, $course->id, $modname)) { // First try to reall all of the data in. // parse all the html files into objects. $pageobjects = extract_data($rawpages, $course->id, $mod->name, $modname); clean_temp(); // All done with files so dump em. $modcreateobjects = $modname.'_create_objects'; $modsaveobjects = $modname.'_save_objects'; // Function to preps the data to be sent to DB. $objects = $modcreateobjects($pageobjects, $mod->id); if (! $modsaveobjects($objects, $mod->id, $pageid)) { // Sends it to DB. print_error( 'could not save'); } } else { print_error('could not get data'); } echo "
tags around each element and strip out \n which I have found to be uneccessary. foreach ($pageobject->contents as $content) { $content = str_replace("\n", '', $content); $content = str_replace("\r", '', $content); $content = str_replace(' ', '', $content); // Puts in returns? $content = '
'.$content.'
'; $page->contents .= addslashes($content); } return $page; } // Save the chapter objects to the database. function book_save_objects($chapters, $bookid, $pageid='0') { global $DB; // Nothing fancy, just save them all in order. foreach ($chapters as $chapter) { if (!$chapter->id = $DB->insert_record('book_chapters', $chapter)) { print_error('Could not update your book'); } } return true; }