function wiki_upload_config(&$WS) { global $CFG, $COURSE; $dir = make_mod_upload_directory($COURSE->id); $WS->dfdir->name = $dir . '/wiki' . $WS->cm->id; //generate uploaded file list $WS->dfdir->content = get_directory_list($WS->dfdir->name); $WS->dfdir->www = $CFG->wwwroot . '/file.php/' . substr($WS->dfdir->name, strlen($CFG->dataroot) + 1); $WS->dfdir->error = array(); }
function assignment_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality global $CFG; if ($oldversion < 2002080500) { execute_sql("\n CREATE TABLE `assignment` (\n `id` int(10) unsigned NOT NULL auto_increment,\n `course` int(10) unsigned NOT NULL default '0',\n `name` varchar(255) NOT NULL default '',\n `description` text NOT NULL,\n `type` int(10) unsigned NOT NULL default '1',\n `maxbytes` int(10) unsigned NOT NULL default '100000',\n `timedue` int(10) unsigned NOT NULL default '0',\n `grade` int(10) NOT NULL default '0',\n `timemodified` int(10) unsigned NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) COMMENT='Defines assignments'\n "); execute_sql("\n CREATE TABLE `assignment_submissions` (\n `id` int(10) unsigned NOT NULL default '0',\n `assignment` int(10) unsigned NOT NULL default '0',\n `user` int(10) unsigned NOT NULL default '0',\n `timecreated` int(10) unsigned NOT NULL default '0',\n `timemodified` int(10) unsigned NOT NULL default '0',\n `numfiles` int(10) unsigned NOT NULL default '0',\n `grade` int(11) NOT NULL default '0',\n `comment` text NOT NULL,\n `teacher` int(10) unsigned NOT NULL default '0',\n `timemarked` int(10) unsigned NOT NULL default '0',\n `mailed` tinyint(1) unsigned NOT NULL default '0',\n PRIMARY KEY (`id`)\n ) COMMENT='Info about submitted assignments'\n "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'view', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'add', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'update', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'view submissions', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'upload', 'assignment', 'name') "); } if ($oldversion < 2002080701) { execute_sql(" ALTER TABLE `assignment_submissions` CHANGE `id` `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT "); } if ($oldversion < 2002082806) { // assignment file area was moved, so rename all the directories in existing courses notify("Moving location of assignment files..."); $basedir = opendir("{$CFG->dataroot}"); while (false !== ($dir = readdir($basedir))) { if ($dir == "." || $dir == ".." || $dir == "users") { continue; } if (filetype("{$CFG->dataroot}/{$dir}") != "dir") { continue; } $coursedir = "{$CFG->dataroot}/{$dir}"; if (!($coursemoddata = make_mod_upload_directory($dir))) { echo "Error: could not create mod upload directory: {$coursemoddata}"; continue; } if (file_exists("{$coursedir}/assignment")) { if (!rename("{$coursedir}/assignment", "{$coursemoddata}/assignment")) { echo "Error: could not move {$coursedir}/assignment to {$coursemoddata}/assignment\n"; } } } } if ($oldversion < 2002101600) { execute_sql(" ALTER TABLE `assignment` ADD `format` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `description` "); } if ($oldversion < 2002110302) { execute_sql(" UPDATE `assignment` SET `type` = '1'"); } if ($oldversion < 2002111500) { execute_sql(" ALTER TABLE `assignment` ADD `resubmit` TINYINT(2) UNSIGNED DEFAULT '0' NOT NULL AFTER `format` "); } if ($oldversion < 2002122300) { execute_sql("ALTER TABLE `assignment_submissions` CHANGE `user` `userid` INT(10) UNSIGNED DEFAULT '0' NOT NULL "); } if ($oldversion < 2004021700) { set_field("log_display", "action", "view submission", "module", "assignment", "action", "view submissions"); } if ($oldversion < 2004040100) { include_once "{$CFG->dirroot}/mod/assignment/lib.php"; assignment_refresh_events(); } if ($oldversion < 2004111200) { execute_sql("ALTER TABLE {$CFG->prefix}assignment DROP INDEX course;", false); execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX assignment;", false); execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX userid;", false); execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX mailed;", false); execute_sql("ALTER TABLE {$CFG->prefix}assignment_submissions DROP INDEX timemarked;", false); modify_database('', 'ALTER TABLE prefix_assignment ADD INDEX course (course);'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX assignment(assignment);'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX userid (userid);'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX mailed (mailed);'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ADD INDEX timemarked (timemarked);'); } if ($oldversion < 2005010500) { // New field for sending out mail to teachers table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit'); } if ($oldversion < 2005041100) { // replace wiki-like with markdown include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php"; $wtm = new WikiToMarkdown(); $wtm->update('assignment', 'description', 'format'); } if ($oldversion < 2005041400) { // Add new fields for the new refactored version of assignment table_column('assignment', '', 'timeavailable', 'integer', '10', 'unsigned', 0, 'not null', 'timedue'); table_column('assignment', '', 'assignmenttype', 'varchar', '50', '', '', 'not null', 'format'); execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'offline' WHERE type = '0';"); execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'uploadsingle' WHERE type = '1';"); execute_sql('ALTER TABLE ' . $CFG->prefix . 'assignment DROP type;'); } if ($oldversion < 2005041501) { // Add two new fields for general data handling, // so most assignment types won't need new fields and backups stay simple table_column('assignment_submissions', '', 'data2', 'MEDIUMTEXT', '', '', '', 'not null', 'numfiles'); table_column('assignment_submissions', '', 'data1', 'MEDIUMTEXT', '', '', '', 'not null', 'numfiles'); } if ($oldversion < 2005041600) { // Add five new fields for general assignment parameters // so most assignment types won't need new fields and backups stay simple table_column('assignment', '', 'var5', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var4', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var3', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var2', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var1', 'integer', '10', '', 0, 'null', 'emailteachers'); } if ($oldversion < 2005041700) { // Allow comments to have a formatting table_column('assignment_submissions', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'comment'); } if ($oldversion < 2005041800) { // Prevent late submissions? (default no) table_column('assignment', '', 'preventlate', 'integer', '2', 'unsigned', '0', 'not null', 'resubmit'); } if ($oldversion < 2005060100) { include_once "{$CFG->dirroot}/mod/assignment/lib.php"; assignment_refresh_events(); } if ($oldversion < 2006092100) { table_column('assignment_submissions', 'comment', 'submissioncomment', 'text', '', '', ''); } ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions. return true; }
} else { error(get_string('error_linking', 'studynotes')); } } $auth = new MediabirdMoodleAuth($mbuser); //set up config MediabirdConfig::$latex_path = $CFG->studynotes_latex_path; MediabirdConfig::$convert_path = $CFG->studynotes_dvipng_path; //set up proxy if (isset($CFG->proxyhost) && strlen($CFG->proxyhost) > 0 && (!isset($CFG->proxytype) || $CFG->proxytype == 'HTTP')) { MediabirdConfig::$proxy_address = $CFG->proxyhost; MediabirdConfig::$proxy_port = $CFG->proxyport; } MediabirdConfig::$uploads_folder = $CFG->dataroot . DIRECTORY_SEPARATOR . "1" . DIRECTORY_SEPARATOR . "moddata" . DIRECTORY_SEPARATOR . "studynotes" . DIRECTORY_SEPARATOR . "uploads" . DIRECTORY_SEPARATOR; if (!file_exists(MediabirdConfig::$uploads_folder . $auth->userId)) { make_mod_upload_directory(1); make_upload_directory("1/moddata/studynotes/uploads/" . $auth->userId); // we store our images in a subfolder in here } MediabirdConfig::$cache_folder = $CFG->dataroot . DIRECTORY_SEPARATOR . "temp" . DIRECTORY_SEPARATOR . "studynotes" . DIRECTORY_SEPARATOR; if (!file_exists(MediabirdConfig::$cache_folder)) { make_upload_directory("temp/studynotes"); } if (isset($action)) { if ($action == "changePass" || $action == "deleteAccount") { exit; } if ($action == "load") { $urlToLoad = MediabirdUtility::getArgNoSlashes($_GET['url']); $html = MediabirdUtility::loadUrl($urlToLoad); if ($html == null) {
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 $matches; $extratedpages = array(); // directory for images 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 $imagedir = $CFG->dataroot . '/' . $courseid . '/moddata/' . $modname; if ($CFG->slasharguments) { $imagelink = $CFG->wwwroot . '/file.php/' . $courseid . '/moddata/' . $modname; } else { $imagelink = $CFG->wwwroot . '/file.php?file=/' . $courseid . '/moddata/' . $modname; } // try to make a unique subfolder to store the images $lessonname = str_replace(' ', '_', $lessonname); // get rid of spaces $i = 0; while (true) { if (!file_exists($imagedir . '/' . $lessonname . $i)) { // ok doesnt exist so make the directory and update our paths mkdir($imagedir . '/' . $lessonname . $i); $imagedir = $imagedir . '/' . $lessonname . $i; $imagelink = $imagelink . '/' . $lessonname . $i; break; } $i++; } foreach ($pages as $file => $content) { // 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 // can identify the content in the div based on the div's class $tags = '<div><img>'; // should also allow <b><i> $string = strip_tags($content, $tags); //echo s($string); $matches = array(); // this will look for a non nested tag that is closed // want to allow <b><i>(maybe more) tags but when we do that // the preg_match messes up. preg_match_all("/(<([\\w]+)[^>]*>)([^<\\2>]*)(<\\/\\2>)/", $string, $matches); //(<([\w]+)[^>]*>)([^<\\2>]*)(<\/\\2>) original pattern //(<(div+)[^>]*>)[^(<div*)](<\/div>) work in progress $path_parts = pathinfo($file); $file = substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.')); // get rid of the extension $imgs = array(); // this preg matches all images preg_match_all("/<img[^>]*(src\\=\"(" . $file . "\\_image[^>^\"]*)\"[^>]*)>/i", $string, $imgs); // start building our page $page = new stdClass(); $page->title = ''; $page->contents = array(); $page->images = array(); $page->source = $path_parts['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 and uncomment the line with the comment imgstyle in it. Also need to comment out // the $page->images[]... line in the next foreach /*foreach ($imgs[1] as $img) { $page->images[] = '<img '.str_replace('src="', "src=\"$imagelink/", $img).' />'; }*/ foreach ($imgs[2] as $img) { copy($path_parts['dirname'] . '/' . $img, $imagedir . '/' . $img); $page->images[] = "<img src=\"{$imagelink}/{$img}\" title=\"{$img}\" />"; // comment out this line if you are using the above foreach loop } 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 // check for any static classes switch ($class) { case 'T': // class T is used for Titles $page->title = $matches[3][$i]; 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 // B1-B4 are just insurance, should just hit B and all be taken care of case 'B2': case 'B3': 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 break; default: if ($matches[3][$i] != ' ') { // odd crap generated... sigh if (substr($matches[3][$i], 0, 1) == ':') { // check for leading : ... hate MS ... $page->contents[] = substr($matches[3][$i], 1); // get rid of : } else { $page->contents[] = $matches[3][$i]; } } break; } } /*if (count($page->contents) == 0) { // didnt find anything, grab everything // potential to pull in a lot of crap for($i = 0; $i < count($matches[1]); $i++) { //if($class = isolate_class($matches[1][$i])) { //if ($class == 'O') { if ($matches[3][$i] != ' ') { // odd crap generated... sigh if (substr($matches[3][$i], 0, 1) == ':') { // check for leading : ... hate MS ... $page->contents[] = substr($matches[3][$i], 1); // get rid of : } else { $page->contents[] = $matches[3][$i]; } } //} //} } }*/ // add the page to the array; $extratedpages[] = $page; } // end $pages foreach loop return $extratedpages; }
<?php // $Id: uploadsound.php,v 3.0 2008/08/13 00:00:00 gibson Exp $ // Handle uploading of sound require "../../config.php"; require_once $CFG->libdir . '/filelib.php'; require_once $CFG->dirroot . '/lib/uploadlib.php'; $id = required_param('id', PARAM_INT); if (!($course = get_record("course", "id", $id))) { error("That's an invalid course id"); } require_login($id); make_mod_upload_directory($id); if (!($basedir = make_upload_directory("{$id}/moddata/nanogong"))) { error("The site administrator needs to fix the file permissions"); } $baseweb = $CFG->wwwroot; if (confirm_sesskey()) { // remove the annoying warning from upload manager $el = error_reporting(0); // hardcode the file name if (isset($_FILES['userfile']['name'])) { $oldname = $_FILES['userfile']['name']; $ext = preg_replace("/.*(\\.[^\\.]*)\$/", "\$1", $oldname); $newname = date("Y-m-d") . "_" . date("His") . $ext; $_FILES['userfile']['name'] = $newname; } // handle the upload $um = new upload_manager('userfile', false, true, $course, false, 0, true); $wdir = "/{$USER->id}"; $dir = "{$basedir}{$wdir}";
function assignment_upgrade($oldversion) { // This function does anything necessary to upgrade // older versions to match current functionality global $CFG; if ($oldversion < 2002080500) { execute_sql("\n CREATE TABLE `assignment` (\n `id` SERIAL PRIMARY KEY,\n `course` integer NOT NULL default '0',\n `name` varchar(255) NOT NULL default '',\n `description` text NOT NULL,\n `type` integer NOT NULL default '1',\n `maxbytes` integer NOT NULL default '100000',\n `timedue` integer NOT NULL default '0',\n `grade` integer NOT NULL default '0',\n `timemodified` integer NOT NULL default '0'\n )\n "); execute_sql("\n CREATE TABLE `assignment_submissions` (\n `id` integer NOT NULL PRIMARY KEY default '0',\n `assignment` integer NOT NULL default '0',\n `user` integer NOT NULL default '0',\n `timecreated` integer NOT NULL default '0',\n `timemodified` integer NOT NULL default '0',\n `numfiles` integer NOT NULL default '0',\n `grade` integer NOT NULL default '0',\n `comment` text NOT NULL,\n `teacher` integer NOT NULL default '0',\n `timemarked` integer NOT NULL default '0',\n `mailed` integer NOT NULL default '0'\n )\n "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'view', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'add', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'update', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'view submissions', 'assignment', 'name') "); execute_sql(" INSERT INTO log_display (module, action, mtable, field) VALUES ('assignment', 'upload', 'assignment', 'name') "); } if ($oldversion < 2002080701) { execute_sql(" ALTER TABLE `assignment_submissions` CHANGE `id` `id` SERIAL PRIMARY KEY "); } if ($oldversion < 2002082806) { // assignment file area was moved, so rename all the directories in existing courses notify("Moving location of assignment files..."); $basedir = opendir("{$CFG->dataroot}"); while (false !== ($dir = readdir($basedir))) { if ($dir == "." || $dir == ".." || $dir == "users") { continue; } if (filetype("{$CFG->dataroot}/{$dir}") != "dir") { continue; } $coursedir = "{$CFG->dataroot}/{$dir}"; if (!($coursemoddata = make_mod_upload_directory($dir))) { echo "Error: could not create mod upload directory: {$coursemoddata}"; continue; } if (file_exists("{$coursedir}/assignment")) { if (!rename("{$coursedir}/assignment", "{$coursemoddata}/assignment")) { echo "Error: could not move {$coursedir}/assignment to {$coursemoddata}/assignment\n"; } } } } if ($oldversion < 2002101600) { execute_sql(" ALTER TABLE `assignment` ADD `format` INTEGER DEFAULT '0' NOT NULL AFTER `description` "); } if ($oldversion < 2002110302) { execute_sql(" UPDATE `assignment` SET `type` = '1'"); } if ($oldversion < 2003091000) { # Old field that was never added! table_column("assignment", "", "resubmit", "integer", "2", "unsigned", "0", "", "format"); } if ($oldversion < 2004021700) { set_field("log_display", "action", "view submission", "module", "assignment", "action", "view submissions"); } if ($oldversion < 2004040100) { include_once "{$CFG->dirroot}/mod/assignment/lib.php"; assignment_refresh_events(); } if ($oldversion < 2004111200) { execute_sql("DROP INDEX {$CFG->prefix}assignment_course_idx;", false); execute_sql("DROP INDEX {$CFG->prefix}assignment_submissions_assignment_idx;", false); execute_sql("DROP INDEX {$CFG->prefix}assignment_submissions_userid_idx;", false); execute_sql("DROP INDEX {$CFG->prefix}assignment_submissions_mailed_idx;", false); execute_sql("DROP INDEX {$CFG->prefix}assignment_submissions_timemarked_idx;", false); modify_database('', 'CREATE INDEX prefix_assignment_course_idx ON prefix_assignment (course);'); modify_database('', 'CREATE INDEX prefix_assignment_submissions_assignment_idx ON prefix_assignment_submissions (assignment);'); modify_database('', 'CREATE INDEX prefix_assignment_submissions_userid_idx ON prefix_assignment_submissions (userid);'); modify_database('', 'CREATE INDEX prefix_assignment_submissions_mailed_idx ON prefix_assignment_submissions (mailed);'); modify_database('', 'CREATE INDEX prefix_assignment_submissions_timemarked_idx ON prefix_assignment_submissions (timemarked);'); } if ($oldversion < 2005010500) { table_column('assignment', '', 'emailteachers', 'integer', '2', 'unsigned', 0, 'not null', 'resubmit'); } if ($oldversion < 2005041100) { // replace wiki-like with markdown include_once "{$CFG->dirroot}/lib/wiki_to_markdown.php"; $wtm = new WikiToMarkdown(); $wtm->update('assignment', 'description', 'format'); } if ($oldversion < 2005041400) { // Add new fields for the new refactored version of assignment table_column('assignment', '', 'timeavailable', 'integer', '10', 'unsigned', 0, 'not null', 'timedue'); table_column('assignment', '', 'assignmenttype', 'varchar', '50', '', '', 'not null', 'format'); execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'offline' WHERE type = '0';", false); execute_sql("UPDATE {$CFG->prefix}assignment SET assignmenttype = 'uploadsingle' WHERE type = '1';", false); execute_sql('ALTER TABLE ' . $CFG->prefix . 'assignment DROP type;'); } if ($oldversion < 2005041501) { // Add two new fields for general data handling, // so most assignment types won't need new fields and backups stay simple table_column('assignment_submissions', '', 'data2', 'TEXT', '', '', '', 'not null', 'numfiles'); table_column('assignment_submissions', '', 'data1', 'TEXT', '', '', '', 'not null', 'numfiles'); } if ($oldversion < 2005041600) { // Add five new fields for general assignment parameters // so most assignment types won't need new fields and backups stay simple table_column('assignment', '', 'var5', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var4', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var3', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var2', 'integer', '10', '', 0, 'null', 'emailteachers'); table_column('assignment', '', 'var1', 'integer', '10', '', 0, 'null', 'emailteachers'); } if ($oldversion < 2005041700) { // Allow comments to have a formatting table_column('assignment_submissions', '', 'format', 'integer', '4', 'unsigned', '0', 'not null', 'comment'); } if ($oldversion < 2005041800) { // Prevent late submissions? (default no) table_column('assignment', '', 'preventlate', 'integer', '2', 'unsigned', '0', 'not null', 'resubmit'); } if ($oldversion < 2005060100) { include_once "{$CFG->dirroot}/mod/assignment/lib.php"; assignment_refresh_events(); } if ($oldversion < 2005060101) { // Mass cleanup of bad upgrade scripts modify_database('', 'ALTER TABLE prefix_assignment ALTER assignmenttype SET NOT NULL'); modify_database('', 'ALTER TABLE prefix_assignment ALTER emailteachers SET NOT NULL'); modify_database('', 'ALTER TABLE prefix_assignment ALTER preventlate SET NOT NULL'); modify_database('', 'ALTER TABLE prefix_assignment ALTER timeavailable SET NOT NULL'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ALTER data1 SET NOT NULL'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ALTER data2 SET NOT NULL'); modify_database('', 'ALTER TABLE prefix_assignment_submissions ALTER format SET NOT NULL'); } if ($oldversion < 2006092100) { table_column('assignment_submissions', 'comment', 'submissioncomment', 'text', '', '', ''); } /// These lines ALWAYS need to be here at the end of this file. Don't mess with them. :-) include_once "{$CFG->dirroot}/mod/assignment/lib.php"; assignment_upgrade_submodules(); ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions. return true; }
function extract_data($courseid, $modname, $id, $basedir, $subchapter, $levels, $titles, $texts) { global $CFG; global $matches; $dirtemp = $CFG->dataroot . '/temp/' . $basedir; for ($i = 0; $i < count($levels); $i++) { echo $levels[$i] . " " . $titles[$i] . "<BR>"; } $extractedpages = array(); // directory for images make_mod_upload_directory($courseid); // make sure moddata is made make_upload_directory($courseid . '/moddata/' . $modname, false); make_upload_directory($courseid . '/moddata/' . $modname . "/" . $id, false); // we store our images in a subfolder in here $imagedir = $CFG->dataroot . '/' . $courseid . '/moddata/' . $modname . "/" . $id; if ($CFG->slasharguments) { $imagelink = $CFG->wwwroot . '/file.php/' . $courseid . '/moddata/' . $modname . "/" . $id; } else { $imagelink = $CFG->wwwroot . '/file.php?file=/' . $courseid . '/moddata/' . $modname . "/" . $id; } // try to make a unique subfolder to store the images $i = 1; while (true) { $newdir = $imagedir . '/' . $i; if (!file_exists($newdir)) { // ok doesnt exist so make the directory and update our paths mkdir($newdir); $imagedir = $newdir; $imagelink = $imagelink . '/' . $i; break; } $i++; } for ($i = 0; $i < count($titles); $i++) { // start building our page $page = new stdClass(); $page->title = $titles[$i]; $page->content = $texts[$i]; //$page->source = $path_parts['basename']; // need for book only $page->subchapter = $levels[$i] >= 2; //check if the nexts are subchapters for ($j = $i + 1; $j < count($titles); $j++) { if ($levels[$j] > 2) { $page->content .= '<br><b><u>' . $titles[$j] . '</u></b><br>' . $texts[$j]; $i = $j; continue; } break; } preg_match_all('#="Pictures/([a-z .A-Z_0-9]*)"#es', $page->content, $imgs); foreach ($imgs[1] as $img) { $src = $dirtemp . '/Pictures/' . $img; $dest = $imagedir . '/' . $img; rename($src, $dest); $page->content = str_replace("Pictures/{$img}", $imagelink . "/" . $img, $page->content); } // add the page to the array; $extractedpages[] = $page; } // end $pages foreach loop return $extractedpages; }