|
@ -1,4 +1,19 @@ |
|
|
<?php // $Id: importppt.php,v 1.3 2012/07/25 11:16:05 bdaloukas Exp $
|
|
|
<?php |
|
|
|
|
|
// This file is part of Moodle - http://moodle.org/ |
|
|
|
|
|
// |
|
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify |
|
|
|
|
|
// it under the terms of the GNU General Public License as published by |
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or |
|
|
|
|
|
// (at your option) any later version. |
|
|
|
|
|
// |
|
|
|
|
|
// Moodle is distributed in the hope that it will be useful, |
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
// GNU General Public License for more details. |
|
|
|
|
|
// |
|
|
|
|
|
// You should have received a copy of the GNU General Public License |
|
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* This is a very rough importer for powerpoint slides |
|
|
* This is a very rough importer for powerpoint slides |
|
|
* Export a powerpoint presentation with powerpoint as html pages |
|
|
* Export a powerpoint presentation with powerpoint as html pages |
|
@ -13,61 +28,64 @@ |
|
|
* @package lesson |
|
|
* @package lesson |
|
|
**/ |
|
|
**/ |
|
|
|
|
|
|
|
|
require_once("../../config.php"); |
|
|
require_once("../../config.php"); |
|
|
require_once("locallib.php"); |
|
|
require_once("locallib.php"); |
|
|
|
|
|
|
|
|
$id = required_param('id', PARAM_INT); // Course Module ID |
|
|
$id = required_param('id', PARAM_INT); // Course Module ID. |
|
|
$pageid = optional_param('pageid', '', PARAM_INT); // Page ID |
|
|
$pageid = optional_param('pageid', '', PARAM_INT); // Page ID. |
|
|
global $matches; |
|
|
global $matches; |
|
|
|
|
|
|
|
|
if (! $cm = get_coursemodule_from_id('lesson', $id)) { |
|
|
if (! $cm = get_coursemodule_from_id('lesson', $id)) { |
|
|
print_error('Course Module ID was incorrect'); |
|
|
print_error('Course Module ID was incorrect'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (! $course = $DB->get_record('course', array( 'id' => $cm->course))) { |
|
|
if (! $course = $DB->get_record('course', array( 'id' => $cm->course))) { |
|
|
print_error('Course is misconfigured'); |
|
|
print_error('Course is misconfigured'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// allows for adaption for multiple modules |
|
|
// Allows for adaption for multiple modules. |
|
|
if(! $modname = $DB->get_field('modules', 'name', array( 'id' => $cm->module))) { |
|
|
if (!$modname = $DB->get_field('modules', 'name', array( 'id' => $cm->module))) { |
|
|
print_error('Could not find module name'); |
|
|
print_error('Could not find module name'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (! $mod = $DB->get_record($modname, array( "id" => $cm->instance))) { |
|
|
if (! $mod = $DB->get_record($modname, array( "id" => $cm->instance))) { |
|
|
print_error('Course module is incorrect'); |
|
|
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"); |
|
|
require_login($course->id, false); |
|
|
$strlessons = get_string("modulenameplural", "lesson"); |
|
|
$context = get_context_instance(CONTEXT_MODULE, $cm->id); |
|
|
|
|
|
require_capability('mod/lesson:edit', $context); |
|
|
|
|
|
|
|
|
echo $OUTPUT->heading("$strimportppt", " $strimportppt", "<a href=\"index.php?id=$course->id\">$strlessons</a> -> <a href=\"{$CFG->wwwroot}/mod/$modname/view.php?id=$cm->id\">".format_string($mod->name,true)."</a>-> $strimportppt"); |
|
|
$strimportppt = get_string("importppt", "lesson"); |
|
|
|
|
|
$strlessons = get_string("modulenameplural", "lesson"); |
|
|
|
|
|
|
|
|
if ($form = data_submitted()) { /// Filename |
|
|
echo $OUTPUT->heading("$strimportppt", " $strimportppt", |
|
|
|
|
|
"<a href=\"index.php?id=$course->id\">$strlessons</a>". |
|
|
|
|
|
" -> <a href=\"{$CFG->wwwroot}/mod/$modname/view.php?id=$cm->id\">".format_string($mod->name, true)."</a>-> $strimportppt"); |
|
|
|
|
|
|
|
|
if (empty($_FILES['newfile'])) { // file was just uploaded |
|
|
if ($form = data_submitted()) { // Filename. |
|
|
|
|
|
if (empty($_FILES['newfile'])) { // File was just uploaded. |
|
|
notify(get_string("uploadproblem") ); |
|
|
notify(get_string("uploadproblem") ); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) { |
|
|
if ((!is_uploaded_file($_FILES['newfile']['tmp_name']) or $_FILES['newfile']['size'] == 0)) { |
|
|
notify(get_string("uploadnofilefound") ); |
|
|
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. |
|
|
|
|
|
|
|
|
} else { // Valid file is found |
|
|
$modcreateobjects = $modname.'_create_objects'; |
|
|
|
|
|
$modsaveobjects = $modname.'_save_objects'; |
|
|
if ($rawpages = readdata($_FILES, $course->id, $modname)) |
|
|
|
|
|
{ // first try to reall all of the data in |
|
|
|
|
|
$pageobjects = extract_data($rawpages, $course->id, $mod->name, $modname); // parse all the html files into objects |
|
|
|
|
|
clean_temp(); // all done with files so dump em |
|
|
|
|
|
|
|
|
|
|
|
$mod_create_objects = $modname.'_create_objects'; |
|
|
|
|
|
$mod_save_objects = $modname.'_save_objects'; |
|
|
|
|
|
|
|
|
|
|
|
$objects = $mod_create_objects($pageobjects, $mod->id); // function to preps the data to be sent to DB |
|
|
// Function to preps the data to be sent to DB. |
|
|
|
|
|
$objects = $modcreateobjects($pageobjects, $mod->id); |
|
|
|
|
|
|
|
|
if(! $mod_save_objects($objects, $mod->id, $pageid)) { // sends it to DB |
|
|
if (! $modsaveobjects($objects, $mod->id, $pageid)) { |
|
|
|
|
|
// Sends it to DB. |
|
|
print_error( 'could not save'); |
|
|
print_error( 'could not save'); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
@ -79,42 +97,42 @@ |
|
|
echo $OUTPUT->footer($course); |
|
|
echo $OUTPUT->footer($course); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// Print upload form |
|
|
|
|
|
|
|
|
|
|
|
print_heading_with_help($strimportppt, "importppt", "lesson"); |
|
|
// Print upload form. |
|
|
|
|
|
print_heading_with_help($strimportppt, "importppt", "lesson"); |
|
|
|
|
|
|
|
|
echo $OUTPUT->box_start('center'); |
|
|
echo $OUTPUT->box_start('center'); |
|
|
echo "<form id=\"theform\" enctype=\"multipart/form-data\" method=\"post\">"; |
|
|
echo "<form id=\"theform\" enctype=\"multipart/form-data\" method=\"post\">"; |
|
|
echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n"; |
|
|
echo "<input type=\"hidden\" name=\"id\" value=\"$cm->id\" />\n"; |
|
|
echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />\n"; |
|
|
echo "<input type=\"hidden\" name=\"pageid\" value=\"$pageid\" />\n"; |
|
|
echo "<table cellpadding=\"5\">"; |
|
|
echo "<table cellpadding=\"5\">"; |
|
|
|
|
|
|
|
|
echo "<tr><td align=\"right\">"; |
|
|
echo "<tr><td align=\"right\">"; |
|
|
print_string("upload"); |
|
|
print_string("upload"); |
|
|
echo ":</td><td>"; |
|
|
echo ":</td><td>"; |
|
|
echo "<input name=\"newfile\" type=\"file\" size=\"50\" />"; |
|
|
echo "<input name=\"newfile\" type=\"file\" size=\"50\" />"; |
|
|
echo "</td></tr><tr><td> </td><td>"; |
|
|
echo "</td></tr><tr><td> </td><td>"; |
|
|
echo "<input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />"; |
|
|
echo "<input type=\"submit\" name=\"save\" value=\"".get_string("uploadthisfile")."\" />"; |
|
|
echo "</td></tr>"; |
|
|
echo "</td></tr>"; |
|
|
|
|
|
|
|
|
echo "</table>"; |
|
|
echo "</table>"; |
|
|
echo "</form>"; |
|
|
echo "</form>"; |
|
|
echo $OUTPUT->box_end(); |
|
|
echo $OUTPUT->box_end(); |
|
|
|
|
|
|
|
|
echo $OUTPUT->footer($course); |
|
|
echo $OUTPUT->footer($course); |
|
|
|
|
|
|
|
|
// START OF FUNCTIONS |
|
|
// START OF FUNCTIONS. |
|
|
|
|
|
|
|
|
|
|
|
/* this function expects a zip file to be uploaded. Then it parses |
|
|
|
|
|
* outline.htm to determine the slide path. Then parses each |
|
|
|
|
|
* slide to get data for the content |
|
|
|
|
|
*/ |
|
|
function readdata($file, $courseid, $modname) { |
|
|
function readdata($file, $courseid, $modname) { |
|
|
// this function expects a zip file to be uploaded. Then it parses |
|
|
|
|
|
// outline.htm to determine the slide path. Then parses each |
|
|
|
|
|
// slide to get data for the content |
|
|
|
|
|
|
|
|
|
|
|
global $CFG; |
|
|
global $CFG; |
|
|
|
|
|
|
|
|
// create an upload directory in temp |
|
|
// Create an upload directory in temp. |
|
|
make_upload_directory('temp/'.$modname); |
|
|
make_upload_directory('temp/'.$modname); |
|
|
|
|
|
|
|
|
$base = $CFG->dataroot."/temp/$modname/"; |
|
|
$base = $CFG->dataroot."/temp/$modname/"; |
|
@ -122,22 +140,23 @@ function readdata($file, $courseid, $modname) { |
|
|
$zipfile = $_FILES["newfile"]["name"]; |
|
|
$zipfile = $_FILES["newfile"]["name"]; |
|
|
$tempzipfile = $_FILES["newfile"]["tmp_name"]; |
|
|
$tempzipfile = $_FILES["newfile"]["tmp_name"]; |
|
|
|
|
|
|
|
|
// create our directory |
|
|
// Create our directory. |
|
|
$path_parts = pathinfo($zipfile); |
|
|
$pathparts = pathinfo($zipfile); |
|
|
$dirname = substr($zipfile, 0, strpos($zipfile, '.'.$path_parts['extension'])); // take off the extension |
|
|
// Take off the extension. |
|
|
|
|
|
$dirname = substr($zipfile, 0, strpos($zipfile, '.'.$pathparts['extension'])); |
|
|
if (!file_exists($base.$dirname)) { |
|
|
if (!file_exists($base.$dirname)) { |
|
|
mkdir($base.$dirname); |
|
|
mkdir($base.$dirname); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// move our uploaded file to temp/lesson |
|
|
// Move our uploaded file to temp/lesson. |
|
|
move_uploaded_file($tempzipfile, $base.$zipfile); |
|
|
move_uploaded_file($tempzipfile, $base.$zipfile); |
|
|
|
|
|
|
|
|
// unzip it! |
|
|
// Unzip it! |
|
|
unzip_file($base.$zipfile, $base, false); |
|
|
unzip_file($base.$zipfile, $base, false); |
|
|
|
|
|
|
|
|
$base = $base.$dirname; // update the base |
|
|
$base = $base.$dirname; // Update the base. |
|
|
|
|
|
|
|
|
// this is the file where we get the names of the files for the slides (in the correct order too) |
|
|
// This is the file where we get the names of the files for the slides (in the correct order too). |
|
|
$outline = $base.'/outline.htm'; |
|
|
$outline = $base.'/outline.htm'; |
|
|
|
|
|
|
|
|
$pages = array(); |
|
|
$pages = array(); |
|
@ -145,9 +164,10 @@ function readdata($file, $courseid, $modname) { |
|
|
if (file_exists($outline) and is_readable($outline)) { |
|
|
if (file_exists($outline) and is_readable($outline)) { |
|
|
$outlinecontents = file_get_contents($outline); |
|
|
$outlinecontents = file_get_contents($outline); |
|
|
$filenames = array(); |
|
|
$filenames = array(); |
|
|
preg_match_all("/javascript:GoToSld\('(.*)'\)/", $outlinecontents, $filenames); // this gets all of our files names |
|
|
// This gets all of our files names. |
|
|
|
|
|
preg_match_all("/javascript:GoToSld\('(.*)'\)/", $outlinecontents, $filenames); |
|
|
|
|
|
|
|
|
// file $pages with the contents of all of the slides |
|
|
// File $pages with the contents of all of the slides. |
|
|
foreach ($filenames[1] as $file) { |
|
|
foreach ($filenames[1] as $file) { |
|
|
$path = $base.'/'.$file; |
|
|
$path = $base.'/'.$file; |
|
|
if (is_readable($path)) { |
|
|
if (is_readable($path)) { |
|
@ -157,10 +177,11 @@ function readdata($file, $courseid, $modname) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
// cannot find the outline, so grab all files that start with slide |
|
|
// Cannot find the outline, so grab all files that start with slide. |
|
|
$dh = opendir($base); |
|
|
$dh = opendir($base); |
|
|
while (false !== ($file = readdir($dh))) { // read throug the directory |
|
|
while (false !== ($file = readdir($dh))) { // Read throug the directory. |
|
|
if ('slide' == substr($file, 0, 5)) { // check for name (may want to check extension later) |
|
|
if ('slide' == substr($file, 0, 5)) { |
|
|
|
|
|
// Check for name (may want to check extension later). |
|
|
$path = $base.'/'.$file; |
|
|
$path = $base.'/'.$file; |
|
|
if (is_readable($path)) { |
|
|
if (is_readable($path)) { |
|
|
$pages[$path] = file_get_contents($path); |
|
|
$pages[$path] = file_get_contents($path); |
|
@ -170,7 +191,7 @@ function readdata($file, $courseid, $modname) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ksort($pages); // order them by file name |
|
|
ksort($pages); // Order them by file name. |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (empty($pages)) { |
|
|
if (empty($pages)) { |
|
@ -180,18 +201,20 @@ function readdata($file, $courseid, $modname) { |
|
|
return $pages; |
|
|
return $pages; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* This function attempts to extract the content out of the slides |
|
|
|
|
|
* the slides are ugly broken xml. and the xml is broken... yeah... |
|
|
|
|
|
*/ |
|
|
function extract_data($pages, $courseid, $lessonname, $modname) { |
|
|
function extract_data($pages, $courseid, $lessonname, $modname) { |
|
|
// this function attempts to extract the content out of the slides |
|
|
|
|
|
// the slides are ugly broken xml. and the xml is broken... yeah... |
|
|
|
|
|
|
|
|
|
|
|
global $CFG; |
|
|
global $CFG; |
|
|
global $matches; |
|
|
global $matches; |
|
|
|
|
|
|
|
|
$extratedpages = array(); |
|
|
$extratedpages = array(); |
|
|
|
|
|
|
|
|
// directory for images |
|
|
// Directory for images. |
|
|
make_mod_upload_directory($courseid); // make sure moddata is made |
|
|
make_mod_upload_directory($courseid); // Make sure moddata is made. |
|
|
make_upload_directory($courseid.'/moddata/'.$modname, false); // we store our images in a subfolder in here |
|
|
// We store our images in a subfolder in here. |
|
|
|
|
|
make_upload_directory($courseid.'/moddata/'.$modname, false); |
|
|
|
|
|
|
|
|
$imagedir = $CFG->dataroot.'/'.$courseid.'/moddata/'.$modname; |
|
|
$imagedir = $CFG->dataroot.'/'.$courseid.'/moddata/'.$modname; |
|
|
|
|
|
|
|
@ -201,12 +224,12 @@ function extract_data($pages, $courseid, $lessonname, $modname) { |
|
|
$imagelink = $CFG->wwwroot.'/file.php?file=/'.$courseid.'/moddata/'.$modname; |
|
|
$imagelink = $CFG->wwwroot.'/file.php?file=/'.$courseid.'/moddata/'.$modname; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// try to make a unique subfolder to store the images |
|
|
// Try to make a unique subfolder to store the images. |
|
|
$lessonname = str_replace(' ', '_', $lessonname); // get rid of spaces |
|
|
$lessonname = str_replace(' ', '_', $lessonname); // Get rid of spaces. |
|
|
$i = 0; |
|
|
$i = 0; |
|
|
while(true) { |
|
|
while (true) { |
|
|
if (!file_exists($imagedir.'/'.$lessonname.$i)) { |
|
|
if (!file_exists($imagedir.'/'.$lessonname.$i)) { |
|
|
// ok doesnt exist so make the directory and update our paths |
|
|
// Ok doesnt exist so make the directory and update our paths. |
|
|
mkdir($imagedir.'/'.$lessonname.$i); |
|
|
mkdir($imagedir.'/'.$lessonname.$i); |
|
|
$imagedir = $imagedir.'/'.$lessonname.$i; |
|
|
$imagedir = $imagedir.'/'.$lessonname.$i; |
|
|
$imagelink = $imagelink.'/'.$lessonname.$i; |
|
|
$imagelink = $imagelink.'/'.$lessonname.$i; |
|
@ -216,66 +239,69 @@ function extract_data($pages, $courseid, $lessonname, $modname) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach ($pages as $file => $content) { |
|
|
foreach ($pages as $file => $content) { |
|
|
// to make life easier on our preg_match_alls, we strip out all tags except |
|
|
/* to make life easier on our preg_match_alls, we strip out all tags except |
|
|
// for div and img (where our content is). We want div because sometimes we |
|
|
* for div and img (where our content is). We want div because sometimes we |
|
|
// can identify the content in the div based on the div's class |
|
|
* can identify the content in the div based on the div's class |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
$tags = '<div><img>'; // should also allow <b><i> |
|
|
$tags = '<div><img>'; // Should also allow <b><i>. |
|
|
$string = strip_tags($content,$tags); |
|
|
$string = strip_tags($content, $tags); |
|
|
//echo s($string); |
|
|
|
|
|
|
|
|
|
|
|
$matches = array(); |
|
|
$matches = array(); |
|
|
// this will look for a non nested tag that is closed |
|
|
/* this will look for a non nested tag that is closed |
|
|
// want to allow <b><i>(maybe more) tags but when we do that |
|
|
* want to allow <b><i>(maybe more) tags but when we do that |
|
|
// the preg_match messes up. |
|
|
* the preg_match messes up. |
|
|
|
|
|
*/ |
|
|
preg_match_all("/(<([\w]+)[^>]*>)([^<\\2>]*)(<\/\\2>)/", $string, $matches); |
|
|
preg_match_all("/(<([\w]+)[^>]*>)([^<\\2>]*)(<\/\\2>)/", $string, $matches); |
|
|
//(<([\w]+)[^>]*>)([^<\\2>]*)(<\/\\2>) original pattern |
|
|
|
|
|
//(<(div+)[^>]*>)[^(<div*)](<\/div>) work in progress |
|
|
|
|
|
|
|
|
|
|
|
$path_parts = pathinfo($file); |
|
|
$pathparts = pathinfo($file); |
|
|
$file = substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.')); // get rid of the extension |
|
|
// Get rid of the extension. |
|
|
|
|
|
$file = substr($pathparts['basename'], 0, strpos($pathparts['basename'], '.')); |
|
|
|
|
|
|
|
|
$imgs = array(); |
|
|
$imgs = array(); |
|
|
// this preg matches all images |
|
|
// This preg matches all images. |
|
|
preg_match_all("/<img[^>]*(src\=\"(".$file."\_image[^>^\"]*)\"[^>]*)>/i", $string, $imgs); |
|
|
preg_match_all("/<img[^>]*(src\=\"(".$file."\_image[^>^\"]*)\"[^>]*)>/i", $string, $imgs); |
|
|
|
|
|
|
|
|
// start building our page |
|
|
// Start building our page. |
|
|
$page = new stdClass; |
|
|
$page = new stdClass; |
|
|
$page->title = ''; |
|
|
$page->title = ''; |
|
|
$page->contents = array(); |
|
|
$page->contents = array(); |
|
|
$page->images = array(); |
|
|
$page->images = array(); |
|
|
$page->source = $path_parts['basename']; // need for book only |
|
|
$page->source = $pathparts['basename']; // Need for book only. |
|
|
|
|
|
|
|
|
// this foreach keeps the style intact. Found it doesn't help much. But if you want back uncomment |
|
|
/* This foreach keeps the style intact. |
|
|
// this foreach and uncomment the line with the comment imgstyle in it. Also need to comment out |
|
|
* Found it doesn't help much. But if you want back uncomment |
|
|
// the $page->images[]... line in the next foreach |
|
|
* this foreach and uncomment the line with the comment imgstyle in it. |
|
|
/*foreach ($imgs[1] as $img) { |
|
|
* Also need to comment out |
|
|
$page->images[] = '<img '.str_replace('src="', "src=\"$imagelink/", $img).' />'; |
|
|
* the $page->images[]... line in the next foreach |
|
|
}*/ |
|
|
*/ |
|
|
foreach ($imgs[2] as $img) { |
|
|
foreach ($imgs[2] as $img) { |
|
|
copy($path_parts['dirname'].'/'.$img, $imagedir.'/'.$img); |
|
|
copy($pathparts['dirname'].'/'.$img, $imagedir.'/'.$img); |
|
|
$page->images[] = "<img src=\"$imagelink/$img\" title=\"$img\" />"; // comment out this line if you are using the above foreach loop |
|
|
// Comment out this line if you are using the above foreach loop. |
|
|
|
|
|
$page->images[] = "<img src=\"$imagelink/$img\" title=\"$img\" />"; |
|
|
} |
|
|
} |
|
|
for($i = 0; $i < count($matches[1]); $i++) { // go through all of our div matches |
|
|
for ($i = 0; $i < count($matches[1]); $i++) { // Go through all of our div matches. |
|
|
|
|
|
$class = isolate_class($matches[1][$i]); // First step in isolating the class. |
|
|
|
|
|
|
|
|
$class = isolate_class($matches[1][$i]); // first step in isolating the class |
|
|
// Check for any static classes. |
|
|
|
|
|
|
|
|
// check for any static classes |
|
|
|
|
|
switch ($class) { |
|
|
switch ($class) { |
|
|
case 'T': // class T is used for Titles |
|
|
case 'T': // Class T is used for Titles. |
|
|
$page->title = $matches[3][$i]; |
|
|
$page->title = $matches[3][$i]; |
|
|
break; |
|
|
break; |
|
|
case 'B': // I would guess that all bullet lists would start with B then go to B1, B2, etc |
|
|
// I would guess that all bullet lists would start with B then go to B1, B2, etc. |
|
|
case 'B1': // B1-B4 are just insurance, should just hit B and all be taken care of |
|
|
case 'B': |
|
|
|
|
|
// B1-B4 are just insurance, should just hit B and all be taken care of. |
|
|
|
|
|
case 'B1': |
|
|
case 'B2': |
|
|
case 'B2': |
|
|
case 'B3': |
|
|
case 'B3': |
|
|
case 'B4': |
|
|
case 'B4': |
|
|
$page->contents[] = build_list('<ul>', $i, 0); // this is a recursive function that will grab all the bullets and rebuild the list in html |
|
|
// This is a recursive function that will grab all the bullets and rebuild the list in html. |
|
|
|
|
|
$page->contents[] = build_list('<ul>', $i, 0); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
if ($matches[3][$i] != ' ') { // odd crap generated... sigh |
|
|
if ($matches[3][$i] != ' ') { // Odd crap generated... sigh. |
|
|
if (substr($matches[3][$i], 0, 1) == ':') { // check for leading : ... hate MS ... |
|
|
if (substr($matches[3][$i], 0, 1) == ':') {// Check for leading : ..hate MS . |
|
|
$page->contents[] = substr($matches[3][$i], 1); // get rid of : |
|
|
$page->contents[] = substr($matches[3][$i], 1); // Get rid of :. |
|
|
} else { |
|
|
} else { |
|
|
$page->contents[] = $matches[3][$i]; |
|
|
$page->contents[] = $matches[3][$i]; |
|
|
} |
|
|
} |
|
@ -284,91 +310,86 @@ function extract_data($pages, $courseid, $lessonname, $modname) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// add the page to the array; |
|
|
// Add the page to the array. |
|
|
$extratedpages[] = $page; |
|
|
$extratedpages[] = $page; |
|
|
|
|
|
|
|
|
} // end $pages foreach loop |
|
|
} // End $pages foreach loop. |
|
|
|
|
|
|
|
|
return $extratedpages; |
|
|
return $extratedpages; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// A recursive function to build a html list. |
|
|
A recursive function to build a html list |
|
|
|
|
|
*/ |
|
|
|
|
|
function build_list($list, &$i, $depth) { |
|
|
function build_list($list, &$i, $depth) { |
|
|
global $matches; // not sure why I global this... |
|
|
global $matches; // Not sure why I global this... |
|
|
|
|
|
|
|
|
while($i < count($matches[1])) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ($i < count($matches[1])) { |
|
|
$class = isolate_class($matches[1][$i]); |
|
|
$class = isolate_class($matches[1][$i]); |
|
|
|
|
|
|
|
|
if (strstr($class, 'B')) { // make sure we are still working with bullet classes |
|
|
if (strstr($class, 'B')) { // Make sure we are still working with bullet classes. |
|
|
if ($class == 'B') { |
|
|
if ($class == 'B') { |
|
|
$this_depth = 0; // calling class B depth 0 |
|
|
$thisdepth = 0; // Calling class B depth 0. |
|
|
} else { |
|
|
} else { |
|
|
// set the depth number. So B1 is depth 1 and B2 is depth 2 and so on |
|
|
// Set the depth number. So B1 is depth 1 and B2 is depth 2 and so on. |
|
|
$this_depth = substr($class, 1); |
|
|
$thisdepth = substr($class, 1); |
|
|
if (!is_numeric($this_depth)) { |
|
|
if (!is_numeric($thisdepth)) { |
|
|
print_error( 'Depth not parsed!'); |
|
|
print_error( 'Depth not parsed!'); |
|
|
} |
|
|
} |
|
|
} |
|
|
if ($thisdepth < $depth) { |
|
|
if ($this_depth < $depth) { |
|
|
// We are moving back a level in the nesting. |
|
|
// we are moving back a level in the nesting |
|
|
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
if ($this_depth > $depth) { |
|
|
if ($thisdepth > $depth) { |
|
|
// we are moving in a lvl in nesting |
|
|
// We are moving in a lvl in nesting. |
|
|
$list .= '<ul>'; |
|
|
$list .= '<ul>'; |
|
|
$list = build_list($list, $i, $this_depth); |
|
|
$list = build_list($list, $i, $thisdepth); |
|
|
// once we return back, should go to the start of the while |
|
|
// Once we return back, should go to the start of the while. |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
// no depth changes, so add the match to our list |
|
|
// No depth changes, so add the match to our list. |
|
|
if ($cleanstring = ppt_clean_text($matches[3][$i])) { |
|
|
if ($cleanstring = ppt_clean_text($matches[3][$i])) { |
|
|
$list .= '<li>'.ppt_clean_text($matches[3][$i]).'</li>'; |
|
|
$list .= '<li>'.ppt_clean_text($matches[3][$i]).'</li>'; |
|
|
} |
|
|
} |
|
|
$i++; |
|
|
$i++; |
|
|
} else { |
|
|
} else { |
|
|
// not a B class, so get out of here... |
|
|
// Not a B class, so get out of here... |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// end the list and return it |
|
|
|
|
|
|
|
|
// End the list and return it. |
|
|
$list .= '</ul>'; |
|
|
$list .= '</ul>'; |
|
|
return $list; |
|
|
return $list; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// Given an html tag, this function will. |
|
|
Given an html tag, this function will |
|
|
|
|
|
*/ |
|
|
|
|
|
function isolate_class($string) { |
|
|
function isolate_class($string) { |
|
|
if($class = strstr($string, 'class=')) { // first step in isolating the class |
|
|
if ($class = strstr($string, 'class=')) { |
|
|
$class = substr($class, strpos($class, '=')+1); // this gets rid of <div blawblaw class= there are no "" or '' around the class name ...sigh... |
|
|
// First step in isolating the class. |
|
|
|
|
|
// This gets rid of <div blawblaw class= there are no "" or '' around the clas name ...sigh... |
|
|
|
|
|
$class = substr($class, strpos($class, '=') + 1); |
|
|
if (strstr($class, ' ')) { |
|
|
if (strstr($class, ' ')) { |
|
|
// spaces found, so cut off everything off after the first space |
|
|
// Spaces found, so cut off everything off after the first space. |
|
|
return substr($class, 0, strpos($class, ' ')); |
|
|
return substr($class, 0, strpos($class, ' ')); |
|
|
} else { |
|
|
} else { |
|
|
// no spaces so nothing else in the div tag, cut off the > |
|
|
// No spaces so nothing else in the div tag, cut off the >. |
|
|
return substr($class, 0, strpos($class, '>')); |
|
|
return substr($class, 0, strpos($class, '>')); |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
// no class defined in the tag |
|
|
// No class defined in the tag. |
|
|
return ''; |
|
|
return ''; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// This function strips off the random chars that ppt puts infront of bullet lists. |
|
|
This function strips off the random chars that ppt puts infront of bullet lists |
|
|
|
|
|
*/ |
|
|
|
|
|
function ppt_clean_text($string) { |
|
|
function ppt_clean_text($string) { |
|
|
$chop = 1; // default: just a single char infront of the content |
|
|
$chop = 1; // Default: just a single char infront of the content. |
|
|
|
|
|
|
|
|
// look for any other crazy things that may be infront of the content |
|
|
// Look for any other crazy things that may be infront of the content. |
|
|
if (strstr($string, '<') and strpos($string, '<') == 0) { // look for the < in the sting and make sure it is in the front |
|
|
if (strstr($string, '<') and strpos($string, '<') == 0) { |
|
|
$chop = 4; // increase the $chop |
|
|
// Look for the < in the sting and make sure it is in the front. |
|
|
|
|
|
$chop = 4; // Increase the $chop. |
|
|
} |
|
|
} |
|
|
// may need to add more later.... |
|
|
// May need to add more later.... |
|
|
|
|
|
|
|
|
$string = substr($string, $chop); |
|
|
$string = substr($string, $chop); |
|
|
|
|
|
|
|
@ -379,41 +400,36 @@ function ppt_clean_text($string) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// Clean up the temp directory. |
|
|
Clean up the temp directory |
|
|
|
|
|
*/ |
|
|
|
|
|
function clean_temp() { |
|
|
function clean_temp() { |
|
|
global $CFG; |
|
|
global $CFG; |
|
|
// this function is broken, use it to clean up later |
|
|
/* this function is broken, use it to clean up later |
|
|
// should only clean up what we made as well because someone else could be importing ppt as well |
|
|
* should only clean up what we made as well because someone else could be importing ppt as well |
|
|
//delDirContents($CFG->dataroot.'/temp/lesson'); |
|
|
* delDirContents($CFG->dataroot.'/temp/lesson'); |
|
|
|
|
|
*/ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Creates objects an chapter object that is to be inserted into the database. |
|
|
/** |
|
|
|
|
|
Creates objects an chapter object that is to be inserted into the database |
|
|
|
|
|
*/ |
|
|
|
|
|
function book_create_objects($pageobjects, $bookid) { |
|
|
function book_create_objects($pageobjects, $bookid) { |
|
|
|
|
|
|
|
|
$chapters = array(); |
|
|
$chapters = array(); |
|
|
$chapter = new stdClass; |
|
|
$chapter = new stdClass; |
|
|
|
|
|
|
|
|
// same for all chapters |
|
|
// Same for all chapters. |
|
|
$chapter->bookid = $bookid; |
|
|
$chapter->bookid = $bookid; |
|
|
$chapter->pagenum = $DB->count_records('book_chapters', array( 'bookid' => $bookid))+1; |
|
|
$chapter->pagenum = $DB->count_records('book_chapters', array( 'bookid' => $bookid)) + 1; |
|
|
$chapter->timecreated = time(); |
|
|
$chapter->timecreated = time(); |
|
|
$chapter->timemodified = time(); |
|
|
$chapter->timemodified = time(); |
|
|
$chapter->subchapter = 0; |
|
|
$chapter->subchapter = 0; |
|
|
|
|
|
|
|
|
$i = 1; |
|
|
$i = 1; |
|
|
foreach ($pageobjects as $pageobject) { |
|
|
foreach ($pageobjects as $pageobject) { |
|
|
$page = prep_page($pageobject, $i); // get title and contents |
|
|
$page = prep_page($pageobject, $i); // Get title and contents. |
|
|
$chapter->importsrc = addslashes($pageobject->source); // add the source |
|
|
$chapter->importsrc = addslashes($pageobject->source); // Add the source. |
|
|
$chapter->title = $page->title; |
|
|
$chapter->title = $page->title; |
|
|
$chapter->content = $page->contents; |
|
|
$chapter->content = $page->contents; |
|
|
$chapters[] = $chapter; |
|
|
$chapters[] = $chapter; |
|
|
|
|
|
|
|
|
// increment our page number and our counter |
|
|
// Increment our page number and our counter. |
|
|
$chapter->pagenum = $chapter->pagenum + 1; |
|
|
$chapter->pagenum = $chapter->pagenum + 1; |
|
|
$i++; |
|
|
$i++; |
|
|
} |
|
|
} |
|
@ -421,44 +437,40 @@ function book_create_objects($pageobjects, $bookid) { |
|
|
return $chapters; |
|
|
return $chapters; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// Builds the title and content strings from an object. |
|
|
Builds the title and content strings from an object |
|
|
|
|
|
*/ |
|
|
|
|
|
function prep_page($pageobject, $count) { |
|
|
function prep_page($pageobject, $count) { |
|
|
if ($pageobject->title == '') { |
|
|
if ($pageobject->title == '') { |
|
|
$page->title = "Page $count"; // no title set so make a generic one |
|
|
$page->title = "Page $count"; // No title set so make a generic one. |
|
|
} else { |
|
|
} else { |
|
|
$page->title = addslashes($pageobject->title); |
|
|
$page->title = addslashes($pageobject->title); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$page->contents = ''; |
|
|
$page->contents = ''; |
|
|
|
|
|
|
|
|
// nab all the images first |
|
|
// Nab all the images first. |
|
|
foreach ($pageobject->images as $image) { |
|
|
foreach ($pageobject->images as $image) { |
|
|
$image = str_replace("\n", '', $image); |
|
|
$image = str_replace("\n", '', $image); |
|
|
$image = str_replace("\r", '', $image); |
|
|
$image = str_replace("\r", '', $image); |
|
|
$image = str_replace("'", '"', $image); // imgstyle |
|
|
$image = str_replace("'", '"', $image); // Imgstyle. |
|
|
|
|
|
|
|
|
$page->contents .= addslashes($image); |
|
|
$page->contents .= addslashes($image); |
|
|
} |
|
|
} |
|
|
// go through the contents array and put <p> tags around each element and strip out \n which I have found to be uneccessary |
|
|
// Go through the contents array and put <p> tags around each element and strip out \n which I have found to be uneccessary. |
|
|
foreach ($pageobject->contents as $content) { |
|
|
foreach ($pageobject->contents as $content) { |
|
|
$content = str_replace("\n", '', $content); |
|
|
$content = str_replace("\n", '', $content); |
|
|
$content = str_replace("\r", '', $content); |
|
|
$content = str_replace("\r", '', $content); |
|
|
$content = str_replace(' ', '', $content); // puts in returns? |
|
|
$content = str_replace(' ', '', $content); // Puts in returns? |
|
|
$content = '<p>'.$content.'</p>'; |
|
|
$content = '<p>'.$content.'</p>'; |
|
|
$page->contents .= addslashes($content); |
|
|
$page->contents .= addslashes($content); |
|
|
} |
|
|
} |
|
|
return $page; |
|
|
return $page; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
// Save the chapter objects to the database. |
|
|
Save the chapter objects to the database |
|
|
|
|
|
*/ |
|
|
|
|
|
function book_save_objects($chapters, $bookid, $pageid='0') { |
|
|
function book_save_objects($chapters, $bookid, $pageid='0') { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
// nothing fancy, just save them all in order |
|
|
// Nothing fancy, just save them all in order. |
|
|
foreach ($chapters as $chapter) { |
|
|
foreach ($chapters as $chapter) { |
|
|
if (!$chapter->id = $DB->insert_record('book_chapters', $chapter)) { |
|
|
if (!$chapter->id = $DB->insert_record('book_chapters', $chapter)) { |
|
|
print_error('Could not update your book'); |
|
|
print_error('Could not update your book'); |
|
|