function process()
 {
     global $DB, $CFG, $MOBILE_LANGS, $DEFAULT_LANG, $MEDIA;
     $cm = get_coursemodule_from_id('url', $this->id);
     $this->url = $DB->get_record('url', array('id' => $cm->instance), '*', MUST_EXIST);
     $context = context_module::instance($cm->id);
     $this->md5 = md5($this->url->externalurl) . $this->id;
     $eiffilename = extractImageFile($this->url->intro, 'mod_url', 'intro', '0', $context->id, $this->courseroot, $cm->id);
     if ($eiffilename) {
         $this->resource_image = "/images/" . resizeImage($this->courseroot . "/" . $eiffilename, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
         //delete original image
         unlink($this->courseroot . "/" . $eiffilename) or die(get_string('error_file_delete', 'block_oppia_mobile_export'));
     }
     unset($eiffilename);
 }
 function export2print()
 {
     global $DB, $CFG, $MOBILE_LANGS, $DEFAULT_LANG, $MEDIA;
     $cm = get_coursemodule_from_id('page', $this->id);
     $page = $DB->get_record('page', array('id' => $cm->instance), '*', MUST_EXIST);
     $context = context_module::instance($cm->id);
     $content = $this->extractFiles($page->content, 'mod_page', 'content', 0, $context->id, $this->courseroot);
     $langs = extractLangs($content);
     // get the image from the intro section
     $eiffilename = extractImageFile($page->intro, 'mod_page', 'intro', 0, $context->id, $this->courseroot, $cm->id);
     if ($eiffilename) {
         $this->page_image = $eiffilename;
         $this->page_image = "/images/" . resizeImage($this->courseroot . "/" . $this->page_image, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
         //delete original image
         unlink($this->courseroot . "/" . $eiffilename) or die(get_string('error_file_delete', 'block_oppia_mobile_export'));
     }
     unset($eiffilename);
     $return_content = "";
     if (is_array($langs) && count($langs) > 0) {
         foreach ($langs as $l => $t) {
             $pre_content = $t;
             $t = $this->extractMedia($t);
             // if page has media and no special icon for page, extract the image for first video
             if (count($this->page_media) > 0 && $this->page_image == null) {
                 if ($this->extractMediaImage($pre_content, 'mod_page', 'content', 0, $context->id)) {
                     $this->page_image = "/images/" . resizeImage($this->courseroot . "/" . $this->page_image, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
                 }
             }
             $return_content .= $t;
         }
     } else {
         $pre_content = $content;
         $content = $this->extractMedia($content);
         // if page has media and no special icon for page, extract the image for first video
         if (count($this->page_media) > 0 && $this->page_image == null) {
             if ($this->extractMediaImage($pre_content, 'mod_page', 'content', 0, $context->id)) {
                 $this->page_image = "/images/" . resizeImage($this->courseroot . "/" . $this->page_image, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
             }
         } else {
             if ($this->page_image == null) {
                 $piffilename = extractImageFile($page->content, 'mod_page', 'content', 0, $context->id, $this->courseroot, $cm->id);
                 if ($piffilename) {
                     $this->page_image = $piffilename;
                     $this->page_image = "/images/" . resizeImage($this->courseroot . "/" . $this->page_image, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
                     unlink($this->courseroot . "/" . $piffilename) or die(get_string('error_file_delete', 'block_oppia_mobile_export'));
                 }
             }
         }
         $return_content = $content;
     }
     return $return_content;
 }
 function exportQuestionImages()
 {
     global $DB, $CFG, $USER, $QUIZ_CACHE, $CFG;
     $cm = get_coursemodule_from_id('quiz', $this->id);
     $context = context_module::instance($cm->id);
     $quiz = $DB->get_record('quiz', array('id' => $cm->instance), '*', MUST_EXIST);
     $quizobj = quiz::create($cm->instance, $USER->id);
     try {
         $quizobj->preload_questions();
         $quizobj->load_questions();
         $qs = $quizobj->get_questions();
         foreach ($qs as $q) {
             extractImageFile($q->questiontext, 'question', 'questiontext', $q->id, $q->contextid, $this->courseroot, $cm->id);
         }
     } catch (moodle_exception $me) {
         return;
     }
 }
 $section = $xmlDoc->createElement("section");
 $section->appendChild($xmlDoc->createAttribute("order"))->appendChild($xmlDoc->createTextNode($sect_orderno));
 $title = extractLangs($sect->summary);
 if (is_array($title) && count($title) > 0) {
     foreach ($title as $l => $t) {
         $temp = $xmlDoc->createElement("title", strip_tags($t));
         $temp->appendChild($xmlDoc->createAttribute("lang"))->appendChild($xmlDoc->createTextNode($l));
         $section->appendChild($temp);
     }
 } else {
     $temp = $xmlDoc->createElement("title", strip_tags($sect->summary));
     $temp->appendChild($xmlDoc->createAttribute("lang"))->appendChild($xmlDoc->createTextNode($DEFAULT_LANG));
     $section->appendChild($temp);
 }
 // get image for this section
 $filename = extractImageFile($sect->summary, 'course', 'section', $sect->id, $context->id, $course_root, 0);
 if ($filename) {
     $temp = $xmlDoc->createElement("image");
     $temp->appendChild($xmlDoc->createAttribute("filename"))->appendChild($xmlDoc->createTextNode($filename));
     $section->appendChild($temp);
 }
 $act_orderno = 1;
 $activities = $xmlDoc->createElement("activities");
 foreach ($sectionmods as $modnumber) {
     if ($modnumber == "" || $modnumber === false) {
         continue;
     }
     $mod = $mods[$modnumber];
     if ($mod->modname == 'page' && $mod->visible == 1) {
         echo $mod->name . "<br/>";
         $page = new mobile_activity_page();
 function process()
 {
     global $DB, $CFG, $USER;
     $cm = get_coursemodule_from_id('feedback', $this->id);
     $context = context_module::instance($cm->id);
     $feedback = $DB->get_record('feedback', array('id' => $cm->instance), '*', MUST_EXIST);
     $select = 'feedback = ?';
     $params = array($feedback->id);
     $feedbackitems = $DB->get_records_select('feedback_item', $select, $params, 'position');
     $mQH = new QuizHelper();
     $mQH->init($this->server_connection);
     $this->md5 = md5(serialize($feedbackitems)) . $this->id;
     // find if this quiz already exists
     $resp = $mQH->exec('quizprops/digest/' . $this->md5, array(), 'get');
     if (!isset($resp->quizzes)) {
         echo get_string('error_connection', 'block_oppia_mobile_export');
         die;
     }
     $filename = extractImageFile($feedback->intro, 'mod_feedback', 'intro', '0', $context->id, $this->courseroot, $cm->id);
     if ($filename) {
         $this->feedback_image = "/images/" . resizeImage($this->courseroot . "/" . $filename, $this->courseroot . "/images/" . $cm->id, $CFG->block_oppia_mobile_export_thumb_width, $CFG->block_oppia_mobile_export_thumb_height);
         //delete original image
         unlink($this->courseroot . "/" . $filename) or die(get_string('error_file_delete', 'block_oppia_mobile_export'));
     }
     if (count($resp->quizzes) > 0) {
         $quiz_id = $resp->quizzes[0]->quiz_id;
         $quiz = $mQH->exec('quiz/' . $quiz_id, array(), 'get');
         $this->content = json_encode($quiz);
         return;
     }
     $props = array();
     $props[0] = array('name' => "digest", 'value' => $this->md5);
     $props[1] = array('name' => "courseversion", 'value' => $this->courseversion);
     $nameJSON = extractLangs($cm->name, true);
     $descJSON = extractLangs($this->summary, true);
     //create the quiz
     $post = array('title' => $nameJSON, 'description' => $descJSON, 'questions' => array(), 'props' => $props);
     $resp = $mQH->exec('quiz', $post);
     $quiz_uri = $resp->resource_uri;
     $quiz_id = $resp->id;
     $i = 1;
     foreach ($feedbackitems as $fi) {
         if (!in_array($fi->typ, $this->supported_types)) {
             continue;
         }
         if ($fi->required) {
             $value = "true";
         } else {
             $value = "false";
         }
         $props = array();
         $props[0] = array('name' => "required", 'value' => $value);
         $qtitle = extractLangs($fi->name, true);
         // create the question
         if (strpos($fi->presentation, 'r') === 0 && ($fi->typ == "multichoice" || $fi->typ == "multichoicerated")) {
             $post = array('title' => $qtitle, 'type' => "multichoice", 'responses' => array(), 'props' => $props);
             $resp = $mQH->exec('question', $post);
             $question_uri = $resp->resource_uri;
         }
         if (strpos($fi->presentation, 'c') === 0 && $fi->typ == "multichoice") {
             $post = array('title' => $qtitle, 'type' => "multiselect", 'responses' => array(), 'props' => $props);
             $resp = $mQH->exec('question', $post);
             $question_uri = $resp->resource_uri;
         }
         if ($fi->typ == "textarea") {
             $post = array('title' => $qtitle, 'type' => "essay", 'responses' => array(), 'props' => $props);
             $resp = $mQH->exec('question', $post);
             $question_uri = $resp->resource_uri;
         }
         if ($fi->typ == "numeric") {
             $post = array('title' => $qtitle, 'type' => "numerical", 'responses' => array(), 'props' => $props);
             $resp = $mQH->exec('question', $post);
             $question_uri = $resp->resource_uri;
         }
         if ($fi->typ == "textfield") {
             $post = array('title' => $qtitle, 'type' => "shortanswer", 'responses' => array(), 'props' => $props);
             $resp = $mQH->exec('question', $post);
             $question_uri = $resp->resource_uri;
         }
         // add the response options
         if ($fi->typ == "multichoice") {
             $j = 1;
             $presentation = preg_replace("(r[>]+)", '', $fi->presentation);
             $presentation = preg_replace("(c[>]+)", '', $presentation);
             $response_options = explode("|", $presentation);
             foreach ($response_options as $ro) {
                 $responseopt = extractLangs($ro, true);
                 $post = array('question' => $question_uri, 'order' => $j, 'title' => $responseopt, 'score' => 0, 'props' => array());
                 $resp = $mQH->exec('response', $post);
                 $j++;
             }
         }
         if ($fi->typ == "multichoicerated") {
             $j = 1;
             $presentation = preg_replace("(r[>>]+)", '', $fi->presentation);
             $response_options = explode("|", $presentation);
             foreach ($response_options as $ro) {
                 $new_ro = preg_replace("([0-9]+[#]+)", '', $ro);
                 $responseopt = extractLangs($new_ro, true);
                 $post = array('question' => $question_uri, 'order' => $j, 'title' => $responseopt, 'score' => 0, 'props' => array());
                 $resp = $mQH->exec('response', $post);
                 $j++;
             }
         }
         // add question to quiz
         $post = array('quiz' => $quiz_uri, 'question' => $question_uri, 'order' => $i);
         $resp = $mQH->exec('quizquestion', $post);
         $i++;
     }
     // get the final quiz object
     $feedback = $mQH->exec('quiz/' . $quiz_id, array(), 'get');
     $this->content = json_encode($feedback);
 }