|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00028 defined('MOODLE_INTERNAL') || die(); 00029 00039 function lesson_importppt_build_list(array &$matches, $list, &$i, $depth) { 00040 while($i < count($matches[1])) { 00041 00042 $class = lesson_importppt_isolate_class($matches[1][$i]); 00043 00044 if (strstr($class, 'B')) { // make sure we are still working with bullet classes 00045 if ($class == 'B') { 00046 $this_depth = 0; // calling class B depth 0 00047 } else { 00048 // set the depth number. So B1 is depth 1 and B2 is depth 2 and so on 00049 $this_depth = substr($class, 1); 00050 if (!is_numeric($this_depth)) { 00051 print_error('invalidnum'); 00052 } 00053 } 00054 if ($this_depth < $depth) { 00055 // we are moving back a level in the nesting 00056 break; 00057 } 00058 if ($this_depth > $depth) { 00059 // we are moving in a lvl in nesting 00060 $list .= '<ul>'; 00061 $list = lesson_importppt_build_list($matches, $list, $i, $this_depth); 00062 // once we return back, should go to the start of the while 00063 continue; 00064 } 00065 // no depth changes, so add the match to our list 00066 if ($cleanstring = lesson_importppt_clean_text($matches[3][$i])) { 00067 $list .= '<li>'.lesson_importppt_clean_text($matches[3][$i]).'</li>'; 00068 } 00069 $i++; 00070 } else { 00071 // not a B class, so get out of here... 00072 break; 00073 } 00074 } 00075 // end the list and return it 00076 $list .= '</ul>'; 00077 return $list; 00078 00079 } 00080 00087 function lesson_importppt_isolate_class($string) { 00088 if($class = strstr($string, 'class=')) { // first step in isolating the class 00089 $class = substr($class, strpos($class, '=')+1); // this gets rid of <div blawblaw class= there are no "" or '' around the class name ...sigh... 00090 if (strstr($class, ' ')) { 00091 // spaces found, so cut off everything off after the first space 00092 return substr($class, 0, strpos($class, ' ')); 00093 } else { 00094 // no spaces so nothing else in the div tag, cut off the > 00095 return substr($class, 0, strpos($class, '>')); 00096 } 00097 } else { 00098 // no class defined in the tag 00099 return ''; 00100 } 00101 } 00102 00109 function lesson_importppt_clean_text($string) { 00110 $chop = 1; // default: just a single char infront of the content 00111 00112 // look for any other crazy things that may be infront of the content 00113 if (strstr($string, '<') and strpos($string, '<') == 0) { // look for the < in the sting and make sure it is in the front 00114 $chop = 4; // increase the $chop 00115 } 00116 // may need to add more later.... 00117 00118 $string = substr($string, $chop); 00119 00120 if ($string != ' ') { 00121 return $string; 00122 } else { 00123 return false; 00124 } 00125 } 00126 00134 function lesson_create_objects($pageobjects, $lessonid) { 00135 00136 $branchtables = array(); 00137 $branchtable = new stdClass; 00138 00139 // all pages have this info 00140 $page = new stdClass(); 00141 $page->lessonid = $lessonid; 00142 $page->prevpageid = 0; 00143 $page->nextpageid = 0; 00144 $page->qtype = LESSON_PAGE_BRANCHTABLE; 00145 $page->qoption = 0; 00146 $page->layout = 1; 00147 $page->display = 1; 00148 $page->timecreated = time(); 00149 $page->timemodified = 0; 00150 00151 // all answers are the same 00152 $answer = new stdClass(); 00153 $answer->lessonid = $lessonid; 00154 $answer->jumpto = LESSON_NEXTPAGE; 00155 $answer->grade = 0; 00156 $answer->score = 0; 00157 $answer->flags = 0; 00158 $answer->timecreated = time(); 00159 $answer->timemodified = 0; 00160 $answer->answer = "Next"; 00161 $answer->response = ""; 00162 00163 $answers[] = clone($answer); 00164 00165 $answer->jumpto = LESSON_PREVIOUSPAGE; 00166 $answer->answer = "Previous"; 00167 00168 $answers[] = clone($answer); 00169 00170 $branchtable->answers = $answers; 00171 00172 $i = 1; 00173 00174 foreach ($pageobjects as $pageobject) { 00175 if ($pageobject->title == '') { 00176 $page->title = "Page $i"; // no title set so make a generic one 00177 } else { 00178 $page->title = $pageobject->title; 00179 } 00180 $page->contents = ''; 00181 00182 // nab all the images first 00183 $page->images = $pageobject->images; 00184 foreach ($page->images as $image) { 00185 $imagetag = '<img src="@@PLUGINFILE@@'.$image->get_filepath().$image->get_filename().'" title="'.$image->get_filename().'" />'; 00186 $imagetag = str_replace("\n", '', $imagetag); 00187 $imagetag = str_replace("\r", '', $imagetag); 00188 $imagetag = str_replace("'", '"', $imagetag); // imgstyle 00189 $page->contents .= $imagetag; 00190 } 00191 // go through the contents array and put <p> tags around each element and strip out \n which I have found to be unneccessary 00192 foreach ($pageobject->contents as $content) { 00193 $content = str_replace("\n", '', $content); 00194 $content = str_replace("\r", '', $content); 00195 $content = str_replace(' ', '', $content); // puts in returns? 00196 $content = '<p>'.$content.'</p>'; 00197 $page->contents .= $content; 00198 } 00199 00200 $branchtable->page = clone($page); // add the page 00201 $branchtables[] = clone($branchtable); // add it all to our array 00202 $i++; 00203 } 00204 00205 return $branchtables; 00206 } 00207 00214 class lesson_importppt_form extends moodleform { 00215 00216 public function definition() { 00217 global $COURSE; 00218 00219 $mform = $this->_form; 00220 00221 $mform->addElement('hidden', 'id'); 00222 $mform->setType('id', PARAM_INT); 00223 00224 $mform->addElement('hidden', 'pageid'); 00225 $mform->setType('pageid', PARAM_INT); 00226 00227 $filepickeroptions = array(); 00228 $filepickeroptions['filetypes'] = array('*.zip'); 00229 $filepickeroptions['maxbytes'] = $COURSE->maxbytes; 00230 $mform->addElement('filepicker', 'pptzip', get_string('upload'), null, $filepickeroptions); 00231 $mform->addRule('pptzip', null, 'required', null, 'client'); 00232 00233 $this->add_action_buttons(null, get_string("uploadthisfile")); 00234 } 00235 00236 }