本文整理汇总了PHP中xmlize函数的典型用法代码示例。如果您正苦于以下问题:PHP xmlize函数的具体用法?PHP xmlize怎么用?PHP xmlize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: readquestions
/**
* Parse the array of lines into an array of questions
* this *could* burn memory - but it won't happen that much
* so fingers crossed!
* @param array of lines from the input file.
* @param stdClass $context
* @return array (of objects) question objects.
*/
protected function readquestions($lines) {
$text = implode($lines, ' ');
unset($lines);
// This converts xml to big nasty data structure,
// the 0 means keep white space as it is.
try {
$xml = xmlize($text, 0, 'UTF-8', true);
} catch (xml_format_exception $e) {
$this->error($e->getMessage(), '');
return false;
}
$questions = array();
$this->process_tf($xml, $questions);
$this->process_mc($xml, $questions);
$this->process_ma($xml, $questions);
$this->process_fib($xml, $questions);
$this->process_matching($xml, $questions);
$this->process_essay($xml, $questions);
return $questions;
}
开发者ID:netspotau,项目名称:moodle-mod_assign,代码行数:33,代码来源:format.php
示例2: import
/**
* import
*
* @param string $xml
* @param object $block_instance
* @param object $course
* @return boolean true if import was successful, false otherwise
*/
public function import($xml, $block_instance, $course)
{
global $DB;
if (!($xml = xmlize($xml, 0))) {
return false;
}
// set main XML tag name for this block's config settings
$BLOCK = strtoupper($block_instance->blockname);
$BLOCK = strtr($BLOCK, array('_' => '')) . 'BLOCK';
if (!isset($xml[$BLOCK]['#']['CONFIGFIELDS'][0]['#']['CONFIGFIELD'])) {
return false;
}
$configfield =& $xml[$BLOCK]['#']['CONFIGFIELDS'][0]['#']['CONFIGFIELD'];
$config = unserialize(base64_decode($block_instance->configdata));
if (empty($config)) {
$config = new stdClass();
}
$i = 0;
while (isset($configfield[$i]['#'])) {
$name = $configfield[$i]['#']['NAME'][0]['#'];
$value = $configfield[$i]['#']['VALUE'][0]['#'];
$config->{$name} = $value;
$i++;
}
if ($i == 0) {
return false;
}
$block_instance->configdata = base64_encode(serialize($config));
$DB->set_field('block_instances', 'configdata', $block_instance->configdata, array('id' => $block_instance->id));
return true;
}
开发者ID:gbateson,项目名称:moodle-block_taskchain_navigation,代码行数:39,代码来源:import_form.php
示例3: readquestions
/**
* Parse the xml document into an array of questions
* this *could* burn memory - but it won't happen that much
* so fingers crossed!
* @param array of lines from the input file.
* @param stdClass $context
* @return array (of objects) questions objects.
*/
protected function readquestions($text) {
// This converts xml to big nasty data structure,
// the 0 means keep white space as it is.
try {
$xml = xmlize($text, 0, 'UTF-8', true);
} catch (xml_format_exception $e) {
$this->error($e->getMessage(), '');
return false;
}
$questions = array();
// Treat the assessment title as a category title.
$this->process_category($xml, $questions);
// First step : we are only interested in the <item> tags.
$rawquestions = $this->getpath($xml,
array('questestinterop', '#', 'assessment', 0, '#', 'section', 0, '#', 'item'),
array(), false);
// Each <item> tag contains data related to a single question.
foreach ($rawquestions as $quest) {
// Second step : parse each question data into the intermediate
// rawquestion structure array.
// Warning : rawquestions are not Moodle questions.
$question = $this->create_raw_question($quest);
// Third step : convert a rawquestion into a Moodle question.
switch($question->qtype) {
case "Matching":
$this->process_matching($question, $questions);
break;
case "Multiple Choice":
$this->process_mc($question, $questions);
break;
case "Essay":
$this->process_essay($question, $questions);
break;
case "Multiple Answer":
$this->process_ma($question, $questions);
break;
case "True/False":
$this->process_tf($question, $questions);
break;
case 'Fill in the Blank':
$this->process_fblank($question, $questions);
break;
case 'Short Response':
$this->process_essay($question, $questions);
break;
default:
$this->error(get_string('unknownorunhandledtype', 'question', $question->qtype));
break;
}
}
return $questions;
}
开发者ID:rwijaya,项目名称:moodle,代码行数:64,代码来源:formatqti.php
示例4: rss
function rss($a)
{
// $a deve ser o caminho para o rss
// Primeiro armazenamos o xml
$data = file_get_contents($a);
$info = xmlize($data, 1, 'ISO-8859-1');
$this->title = $info["rss"]["#"]["channel"][0]["#"]["title"][0]["#"];
// Titulo do RSS
$this->link = $info["rss"]["#"]["channel"][0]["#"]["link"][0]["#"];
// Link para a pagina
$this->itens = $info["rss"]["#"]["channel"][0]["#"]["item"];
// Conteudo do RSS
}
开发者ID:alencarmo,项目名称:OCF,代码行数:13,代码来源:class.rss.php
示例5: readquestions
function readquestions($lines)
{
/// Parses an array of lines into an array of questions,
/// where each item is a question object as defined by
/// readquestion().
$text = implode($lines, " ");
$xml = xmlize($text, 0);
$questions = array();
$this->process_tf($xml, $questions);
$this->process_mc($xml, $questions);
$this->process_ma($xml, $questions);
$this->process_fib($xml, $questions);
$this->process_matching($xml, $questions);
return $questions;
}
开发者ID:veritech,项目名称:pare-project,代码行数:15,代码来源:format.php
示例6: validation
function validation($data, $files) {
$errors = array();
if($file = $this->get_draft_files('importfile')){
$file = reset($file);
$content = $file->get_content();
$xml = xmlize($content);
if(empty($content)){
$errors['importfile'] = get_string('error_emptyfile', 'report_rolesmigration');
}else if(!$xml || !roles_migration_get_incoming_roles($xml)){
$errors['importfile'] = get_string('error_badxml', 'report_rolesmigration');
}
}
return $errors;
}
开发者ID:ncsu-delta,项目名称:moodle-report_rolesmigration,代码行数:16,代码来源:importroles_form.php
示例7: loadXMLStructure
/**
* Load and the XMLDB structure from file
*/
function loadXMLStructure()
{
if ($this->fileExists()) {
/// File exists, so let's process it
/// Load everything to a big array
$contents = file_get_contents($this->path);
if (function_exists('local_xmldb_contents_sub')) {
local_xmldb_contents_sub($contents);
}
$xmlarr = xmlize($contents);
/// Convert array to xmldb structure
$this->xmldb_structure = $this->arr2XMLDBStructure($xmlarr);
/// Analize results
if ($this->xmldb_structure->isLoaded()) {
$this->loaded = true;
return true;
} else {
return false;
}
}
return true;
}
开发者ID:Br3nda,项目名称:mahara,代码行数:25,代码来源:XMLDBFile.class.php
示例8: get_preset_settings
/**
* Gets the preset settings
* @global moodle_database $DB
* @return stdClass
*/
public function get_preset_settings() {
global $DB;
$fs = $fileobj = null;
if (!is_directory_a_preset($this->directory)) {
//maybe the user requested a preset stored in the Moodle file storage
$fs = get_file_storage();
$files = $fs->get_area_files(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA);
//preset name to find will be the final element of the directory
$presettofind = end(explode('/',$this->directory));
//now go through the available files available and see if we can find it
foreach ($files as $file) {
if (($file->is_directory() && $file->get_filepath()=='/') || !$file->is_directory()) {
continue;
}
$presetname = trim($file->get_filepath(), '/');
if ($presetname==$presettofind) {
$this->directory = $presetname;
$fileobj = $file;
}
}
if (empty($fileobj)) {
print_error('invalidpreset', 'data', '', $this->directory);
}
}
$allowed_settings = array(
'intro',
'comments',
'requiredentries',
'requiredentriestoview',
'maxentries',
'rssarticles',
'approval',
'defaultsortdir',
'defaultsort');
$result = new stdClass;
$result->settings = new stdClass;
$result->importfields = array();
$result->currentfields = $DB->get_records('data_fields', array('dataid'=>$this->module->id));
if (!$result->currentfields) {
$result->currentfields = array();
}
/* Grab XML */
$presetxml = $this->data_preset_get_file_contents($fs, $fileobj, $this->directory,'preset.xml');
$parsedxml = xmlize($presetxml, 0);
/* First, do settings. Put in user friendly array. */
$settingsarray = $parsedxml['preset']['#']['settings'][0]['#'];
$result->settings = new StdClass();
foreach ($settingsarray as $setting => $value) {
if (!is_array($value) || !in_array($setting, $allowed_settings)) {
// unsupported setting
continue;
}
$result->settings->$setting = $value[0]['#'];
}
/* Now work out fields to user friendly array */
$fieldsarray = $parsedxml['preset']['#']['field'];
foreach ($fieldsarray as $field) {
if (!is_array($field)) {
continue;
}
$f = new StdClass();
foreach ($field['#'] as $param => $value) {
if (!is_array($value)) {
continue;
}
$f->$param = $value[0]['#'];
}
$f->dataid = $this->module->id;
$f->type = clean_param($f->type, PARAM_ALPHA);
$result->importfields[] = $f;
}
/* Now add the HTML templates to the settings array so we can update d */
$result->settings->singletemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"singletemplate.html");
$result->settings->listtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplate.html");
$result->settings->listtemplateheader = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplateheader.html");
$result->settings->listtemplatefooter = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"listtemplatefooter.html");
$result->settings->addtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"addtemplate.html");
$result->settings->rsstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstemplate.html");
$result->settings->rsstitletemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstitletemplate.html");
$result->settings->csstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"csstemplate.css");
$result->settings->jstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"jstemplate.js");
//optional
if (file_exists($this->directory."/asearchtemplate.html")) {
//.........这里部分代码省略.........
开发者ID:nottmoo,项目名称:moodle,代码行数:101,代码来源:lib.php
示例9: readquestions
/**
* Parse the array of lines into an array of questions
* this *could* burn memory - but it won't happen that much
* so fingers crossed!
* @param array of lines from the input file.
* @param stdClass $context
* @return array (of objects) question objects.
*/
protected function readquestions($lines)
{
// We just need it as one big string
$lines = implode('', $lines);
// This converts xml to big nasty data structure
// the 0 means keep white space as it is (important for markdown format)
try {
$xml = xmlize($lines, 0, 'UTF-8', true);
} catch (xml_format_exception $e) {
$this->error($e->getMessage(), '');
return false;
}
unset($lines);
// No need to keep this in memory.
// Set up array to hold all our questions
$questions = array();
// Iterate through questions
foreach ($xml['quiz']['#']['question'] as $question) {
$questiontype = $question['@']['type'];
if ($questiontype == 'multichoice') {
$qo = $this->import_multichoice($question);
} else {
if ($questiontype == 'truefalse') {
$qo = $this->import_truefalse($question);
} else {
if ($questiontype == 'shortanswer') {
$qo = $this->import_shortanswer($question);
} else {
if ($questiontype == 'numerical') {
$qo = $this->import_numerical($question);
} else {
if ($questiontype == 'description') {
$qo = $this->import_description($question);
} else {
if ($questiontype == 'matching' || $questiontype == 'match') {
$qo = $this->import_match($question);
} else {
if ($questiontype == 'cloze' || $questiontype == 'multianswer') {
$qo = $this->import_multianswer($question);
} else {
if ($questiontype == 'essay') {
$qo = $this->import_essay($question);
} else {
if ($questiontype == 'calculated') {
$qo = $this->import_calculated($question);
} else {
if ($questiontype == 'calculatedsimple') {
$qo = $this->import_calculated($question);
$qo->qtype = 'calculatedsimple';
} else {
if ($questiontype == 'calculatedmulti') {
$qo = $this->import_calculated($question);
$qo->qtype = 'calculatedmulti';
} else {
if ($questiontype == 'category') {
$qo = $this->import_category($question);
} else {
// Not a type we handle ourselves. See if the question type wants
// to handle it.
if (!($qo = $this->try_importing_using_qtypes($question, null, null, $questiontype))) {
$this->error(get_string('xmltypeunsupported', 'qformat_xml', $questiontype));
$qo = null;
}
}
}
}
}
}
}
}
}
}
}
}
}
// Stick the result in the $questions array
if ($qo) {
$questions[] = $qo;
}
}
return $questions;
}
开发者ID:saurabh947,项目名称:MoodleLearning,代码行数:90,代码来源:format.php
示例10: endElementLogs
function endElementLogs($parser, $tagName)
{
//Check if we are into LOGS zone
if ($this->tree[3] == "LOGS") {
//if (trim($this->content)) //Debug
// echo "C".str_repeat(" ",($this->level+2)*2).$this->getContents()."<br />\n"; //Debug
//echo $this->level.str_repeat(" ",$this->level*2)."</".$tagName."><br />\n"; //Debug
//Acumulate data to info (content + close tag)
//Reconvert: strip htmlchars again and trim to generate xml data
if (!isset($this->temp)) {
$this->temp = "";
}
$this->temp .= htmlspecialchars(trim($this->content)) . "</" . $tagName . ">";
//If we've finished a log, xmlize it an save to db
if ($this->level == 4 and $tagName == "LOG") {
//Prepend XML standard header to info gathered
$xml_data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . $this->temp;
//Call to xmlize for this portion of xml data (one LOG)
//echo "-XMLIZE: ".strftime ("%X",time()),"-"; //Debug
$data = xmlize($xml_data, 0);
//echo strftime ("%X",time())."<p>"; //Debug
//traverse_xmlize($data); //Debug
//print_object ($GLOBALS['traverse_array']); //Debug
//$GLOBALS['traverse_array']=""; //Debug
//Now, save data to db. We'll use it later
//Get id and modtype from data
$log_id = $data["LOG"]["#"]["ID"]["0"]["#"];
$log_module = $data["LOG"]["#"]["MODULE"]["0"]["#"];
//We only save log entries from backup file if they are:
// - Course logs
// - User logs
// - Module logs about one restored module
if ($log_module == "course" or $log_module == "user" or $this->preferences->mods[$log_module]->restore) {
//Increment counter
$this->counter++;
//Save to db
$status = backup_putid($this->preferences->backup_unique_code, "log", $log_id, null, $data);
//echo "<p>id: ".$mod_id."-".$mod_type." len.: ".strlen($sla_mod_temp)." to_db: ".$status."<p>"; //Debug
//Create returning info
$this->info = $this->counter;
}
//Reset temp
unset($this->temp);
}
}
//Stop parsing if todo = LOGS and tagName = LOGS (en of the tag, of course)
//Speed up a lot (avoid parse all)
if ($tagName == "LOGS" and $this->level == 3) {
$this->finished = true;
$this->counter = 0;
}
//Clear things
$this->tree[$this->level] = "";
$this->level--;
$this->content = "";
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:56,代码来源:restorelib.php
示例11: ping_init
function ping_init(&$a)
{
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n\t\t<result>";
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if (local_user()) {
$tags = array();
$comments = array();
$likes = array();
$dislikes = array();
$friends = array();
$posts = array();
$cit = array();
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, \n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, `item`.`body`, \n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` \n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 \n\t\t\t\tORDER BY `item`.`created` DESC", intval(local_user()));
$network = count($r);
foreach ($r as $it) {
switch ($it['verb']) {
case ACTIVITY_TAG:
$obj = parse_xml_string($xmlhead . $it['object']);
$it['tname'] = $obj->content;
$tags[] = $it;
break;
case ACTIVITY_LIKE:
$likes[] = $it;
break;
case ACTIVITY_DISLIKE:
$dislikes[] = $it;
break;
case ACTIVITY_FRIEND:
$obj = parse_xml_string($xmlhead . $it['object']);
$it['fname'] = $obj->title;
$friends[] = $it;
break;
default:
$reg = "|@\\[url=" . $a->get_baseurl() . "/profile/" . $a->user['nickname'] . "|";
if ($it['parent'] != $it['id']) {
$comments[] = $it;
} else {
if (preg_match($reg, $it['body'])) {
$cit[] = $it;
} else {
$posts[] = $it;
}
}
}
}
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, \n\t\t\t\t`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object`, \n\t\t\t\t`pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` \n\t\t\t\tFROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent`\n\t\t\t\tWHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND\n\t\t\t\t `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1", intval(local_user()));
$home = count($r);
foreach ($r as $it) {
switch ($it['verb']) {
case ACTIVITY_TAG:
$obj = parse_xml_string($xmlhead . $it['object']);
$it['tname'] = $obj->content;
$tags[] = $it;
break;
case ACTIVITY_LIKE:
$likes[] = $it;
break;
case ACTIVITY_DISLIKE:
$dislikes[] = $it;
break;
case ACTIVITY_FRIEND:
$obj = parse_xml_string($xmlhead . $it['object']);
$it['fname'] = $obj->title;
$friends[] = $it;
break;
default:
if ($it['parent'] != $it['id']) {
$comments[] = $it;
}
if (preg_match("/@\\[[^]]*\\]" . $a->user['username'] . "/", $it['body'])) {
$cit[] = $it;
}
}
}
$intros1 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, \n\t\t\t`fcontact`.`name`, `fcontact`.`url`, `fcontact`.`photo` \n\t\t\tFROM `intro` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`fid`!=0", intval(local_user()));
$intros2 = q("SELECT COUNT(`intro`.`id`) AS `total`, `intro`.`id`, `intro`.`datetime`, \n\t\t\t`contact`.`name`, `contact`.`url`, `contact`.`photo` \n\t\t\tFROM `intro` LEFT JOIN `contact` ON `intro`.`contact-id` = `contact`.`id`\n\t\t\tWHERE `intro`.`uid` = %d AND `intro`.`blocked` = 0 AND `intro`.`ignore` = 0 AND `intro`.`contact-id`!=0", intval(local_user()));
$intro = $intros1[0]['total'] + $intros2[0]['total'];
if ($intros1[0]['total'] == 0) {
$intros1 = array();
}
if ($intros2[0]['total'] == 0) {
$intros2 = array();
}
$intros = $intros1 + $intros2;
$myurl = $a->get_baseurl() . '/profile/' . $a->user['nickname'];
$mails = q("SELECT *, COUNT(*) AS `total` FROM `mail`\n\t\t\tWHERE `uid` = %d AND `seen` = 0 AND `from-url` != '%s' ", intval(local_user()), dbesc($myurl));
$mail = $mails[0]['total'];
if ($a->config['register_policy'] == REGISTER_APPROVE && is_site_admin()) {
$regs = q("SELECT `contact`.`name`, `contact`.`url`, `contact`.`micro`, `register`.`created`, COUNT(*) as `total` FROM `contact` RIGHT JOIN `register` ON `register`.`uid`=`contact`.`uid` WHERE `contact`.`self`=1");
$register = $regs[0]['total'];
} else {
$register = "0";
}
function xmlize($href, $name, $url, $photo, $date, $message)
{
$notsxml = '<note href="%s" name="%s" url="%s" photo="%s" date="%s">%s</note>';
return sprintf($notsxml, xmlify($href), xmlify($name), xmlify($url), xmlify($photo), xmlify($date), xmlify($message));
}
echo "<intro>{$intro}</intro>\n\t\t\t\t<mail>{$mail}</mail>\n\t\t\t\t<net>{$network}</net>\n\t\t\t\t<home>{$home}</home>";
//.........这里部分代码省略.........
开发者ID:ryivhnn,项目名称:friendica,代码行数:101,代码来源:ping.php
示例12: file_get_contents
<?php
//====================================================
// FileName: .php
// Summary: 描述
// Author: millken(迷路林肯)
// LastModifed:2007-08-10
// copyright (c)2007 [email protected]
//====================================================
include 'common.inc.php';
include ROOT_PATH . 'include/xmlize.inc.php';
$xmldata = file_get_contents(ROOT_PATH . 'cache/top500.xml');
$xml = xmlize($xmldata);
foreach ($xml['result']['#']['data'] as $x) {
$temp = explode('$$', $x['#']['name']['0']['#']);
$list_array[] = array('id' => $x['#']['id']['0']['#'], 'songname' => $temp[0], 'singer' => $temp[1]);
}
//print_r($list_array);
//$lines = file('temp.txt');
//foreach($lines as $l){
// $newContent .= " <Keyword>".trim($l)."</Keyword>\n";
//}
//file_put_contents('new.txt',$newContent);
function &a($a = '')
{
echo func_num_args();
}
a();
print_r(ini_get_all());
开发者ID:haseok86,项目名称:millkencode,代码行数:29,代码来源:test.php
示例13: load_environment_xml
/**
* This function will load the environment.xml file and xmlize it
*
* @global object
* @staticvar mixed $data
* @uses ENV_SELECT_NEWER
* @uses ENV_SELECT_DATAROOT
* @uses ENV_SELECT_RELEASE
* @param int $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. Default ENV_SELECT_NEWER (BC)
* @return mixed the xmlized structure or false on error
*/
function load_environment_xml($env_select = ENV_SELECT_NEWER)
{
global $CFG;
static $data;
//Only load and xmlize once by request
if (!empty($data)) {
return $data;
}
/// First of all, take a look inside $CFG->dataroot/environment/environment.xml
$file = $CFG->dataroot . '/environment/environment.xml';
$internalfile = $CFG->dirroot . '/' . $CFG->admin . '/environment.xml';
switch ($env_select) {
case ENV_SELECT_NEWER:
if (!is_file($file) || !is_readable($file) || filemtime($file) < filemtime($internalfile) || !($contents = file_get_contents($file))) {
/// Fallback to fixed $CFG->admin/environment.xml
if (!is_file($internalfile) || !is_readable($internalfile) || !($contents = file_get_contents($internalfile))) {
return false;
}
}
break;
case ENV_SELECT_DATAROOT:
if (!is_file($file) || !is_readable($file) || !($contents = file_get_contents($file))) {
return false;
}
break;
case ENV_SELECT_RELEASE:
if (!is_file($internalfile) || !is_readable($internalfile) || !($contents = file_get_contents($internalfile))) {
return false;
}
break;
}
/// XML the whole file
$data = xmlize($contents);
return $data;
}
开发者ID:masaterutakeno,项目名称:MoodleMobile,代码行数:46,代码来源:environmentlib.php
示例14: feedback_load_xml_data
function feedback_load_xml_data($filename)
{
global $CFG;
require_once $CFG->dirroot . '/lib/xmlize.php';
$datei = file_get_contents($filename);
if (!($datei = feedback_check_xml_utf8($datei))) {
return false;
}
$data = xmlize($datei, 1, 'UTF-8');
if (intval($data['FEEDBACK']['@']['VERSION']) != 200701) {
return false;
}
$data = $data['FEEDBACK']['#']['ITEMS'][0]['#']['ITEM'];
return $data;
}
开发者ID:ajv,项目名称:Offline-Caching,代码行数:15,代码来源:import.php
示例15: test_import_files_as_draft
public function test_import_files_as_draft() {
$this->resetAfterTest();
$this->setAdminUser();
$xml = <<<END
<questiontext format="html">
<text><![CDATA[<p><a href="@@PLUGINFILE@@/moodle.txt">This text file</a> contains the word 'Moodle'.</p>]]></text>
<file name="moodle.txt" encoding="base64">TW9vZGxl</file>
</questiontext>
END;
$textxml = xmlize($xml);
$qo = new stdClass();
$importer = new qformat_xml();
$draftitemid = $importer->import_files_as_draft($textxml['questiontext']['#']['file']);
$files = file_get_drafarea_files($draftitemid);
$this->assertEquals(1, count($files->list));
$file = $files->list[0];
$this->assertEquals('moodle.txt', $file->filename);
$this->assertEquals('/', $file->filepath);
$this->assertEquals(6, $file->size);
}
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:25,代码来源:xmlformat_test.php
示例16: test_import_multianswer
public function test_import_multianswer() {
$xml = ' <question type="cloze">
<name>
<text>Simple multianswer</text>
</name>
<questiontext format="html">
<text><![CDATA[Complete this opening line of verse: "The {1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer} and the {1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!~Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!} went to sea".]]></text>
</questiontext>
<generalfeedback format="html">
<text><![CDATA[General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: "The owl and the pussycat went to sea".]]></text>
</generalfeedback>
<penalty>0.5</penalty>
<hidden>0</hidden>
<hint format="html">
<text>Hint 1</text>
</hint>
<hint format="html">
<text>Hint 2</text>
</hint>
</question>
';
$xmldata = xmlize($xml);
$importer = new qformat_xml();
$q = $importer->import_multianswer($xmldata['question']);
// Annoyingly, import works in a weird way (it duplicates code, rather
// than just calling save_question) so we cannot use
// test_question_maker::get_question_form_data('multianswer', 'twosubq').
$expectedqa = new stdClass();
$expectedqa->name = 'Simple multianswer';
$expectedqa->qtype = 'multianswer';
$expectedqa->questiontext = 'Complete this opening line of verse: "The {#1} and the {#2} went to sea".';
$expectedqa->generalfeedback = 'General feedback: It\'s from "The Owl and the Pussy-cat" by Lear: "The owl and the pussycat went to sea".';
$expectedqa->defaultmark = 2;
$expectedqa->penalty = 0.5;
$expectedqa->hint = array(
array('text' => 'Hint 1', 'format' => FORMAT_HTML, 'files' => array()),
array('text' => 'Hint 2', 'format' => FORMAT_HTML, 'files' => array()),
);
$sa = new stdClass();
$sa->questiontext = array('text' => '{1:SHORTANSWER:Dog#Wrong, silly!~=Owl#Well done!~*#Wrong answer}',
'format' => FORMAT_HTML, 'itemid' => null);
$sa->generalfeedback = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => null);
$sa->defaultmark = 1.0;
$sa->qtype = 'shortanswer';
$sa->usecase = 0;
$sa->answer = array('Dog', 'Owl', '*');
$sa->fraction = array(0, 1, 0);
$sa->feedback = array(
array('text' => 'Wrong, silly!', 'format' => FORMAT_HTML, 'itemid' => null),
array('text' => 'Well done!', 'format' => FORMAT_HTML, 'itemid' => null),
array('text' => 'Wrong answer', 'format' => FORMAT_HTML, 'itemid' => null),
);
$mc = new stdClass();
$mc->generalfeedback = '';
$mc->questiontext = array('text' => '{1:MULTICHOICE:Bow-wow#You seem to have a dog obsessions!~' .
'Wiggly worm#Now you are just being ridiculous!~=Pussy-cat#Well done!}',
'format' => FORMAT_HTML, 'itemid' => null);
$mc->generalfeedback = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => null);
$mc->defaultmark = 1.0;
$mc->qtype = 'multichoice';
$mc->layout = 0;
$mc->single = 1;
$mc->shuffleanswers = 1;
$mc->correctfeedback = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => null);
$mc->partiallycorrectfeedback = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => null);
$mc->incorrectfeedback = array('text' => '', 'format' => FORMAT_HTML, 'itemid' => null);
$mc->answernumbering = 0;
$mc->answer = array(
array('text' => 'Bow-wow', 'format' => FORMAT_HTML, 'itemid' => null),
array('text' => 'Wiggly worm', 'format' => FORMAT_HTML, 'itemid' => null),
array('text' => 'Pussy-cat', 'format' => FORMAT_HTML, 'itemid' => null),
);
$mc->fraction = array(0, 0, 1);
$mc->feedback = array(
array('text' => 'You seem to have a dog obsessions!', 'format' => FORMAT_HTML, 'itemid' => null),
array('text' => 'Now you are just being ridiculous!', 'format' => FORMAT_HTML, 'itemid' => null),
array('text' => 'Well done!', 'format' => FORMAT_HTML, 'itemid' => null),
);
$expectedqa->options = new stdClass();
$expectedqa->options->questions = array(
1 => $sa,
2 => $mc,
);
$this->assertEqual($expectedqa->hint, $q->hint);
$this->assertEqual($expectedqa->options->questions[1], $q->options->questions[1]);
$this->assertEqual($expectedqa->options->questions[2], $q->options->questions[2]);
$this->assert(new CheckSpecifiedFieldsExpectation($expectedqa), $q);
}
开发者ID:robadobdob,项目名称:moodle,代码行数:100,代码来源:testxmlformat.php
示例17: test_parse_matching_groups
public function test_parse_matching_groups()
{
$lines = $this->make_test_xml();
$importer = new qformat_examview();
$text = implode($lines, ' ');
$xml = xmlize($text, 0);
$importer->parse_matching_groups($xml['examview']['#']['matching-group']);
$matching = $importer->matching_questions;
$group = new stdClass();
$group->questiontext = 'Classify the animals.';
$group->subchoices = array('A' => 'insect', 'B' => 'amphibian', 'C' => 'mammal');
$group->subquestions = array();
$group->subanswers = array();
$expectedmatching = array('Matching 1' => $group);
$this->assertEquals($matching, $expectedmatching);
}
开发者ID:evltuma,项目名称:moodle,代码行数:16,代码来源:examviewformat_test.php
示例18: readquestions
function readquestions($lines)
{
/// Parses an array of lines into an array of questions,
/// where each item is a question object as defined by
/// readquestion().
$text = implode($lines, " ");
$xml = xmlize($text, 0);
$raw_questions = $xml['questestinterop']['#']['assessment'][0]['#']['section'][0]['#']['item'];
$questions = array();
foreach ($raw_questions as $quest) {
$question = $this->create_raw_question($quest);
switch ($question->qtype) {
case "Matching":
$this->process_matching($question, $questions);
break;
case "Multiple Choice":
$this->process_mc($question, $questions);
break;
case "Essay":
$this->process_essay($question, $questions);
break;
case "Multiple Answer":
$this->process_ma($question, $questions);
break;
case "True/False":
$this->process_tf($question, $questions);
break;
case 'Fill in the Blank':
$this->process_fblank($question, $questions);
break;
case 'Short Response':
$this->process_essay($question, $questions);
break;
default:
print "Unknown or unhandled question type: \"{$question->qtype}\"<br />";
break;
}
}
return $questions;
}
开发者ID:kai707,项目名称:ITSA-backup,代码行数:40,代码来源:format.php
|
请发表评论