Skip to content

Xml entity fixes #2778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"ext-xml": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-libxml": "*",
"ext-dom": "*",
"twig/twig": "1.*",
"twig/extensions": "~1.0",
"doctrine/orm": "~2.4",
Expand Down Expand Up @@ -109,7 +111,8 @@
"culqi/culqi-php": "1.3.4",
"knplabs/knp-components": "~1.3",
"guzzlehttp/guzzle": "~6.0",
"onelogin/php-saml": "^3.0"
"onelogin/php-saml": "^3.0",
"symfony/dom-crawler": "~3.4"
},
"require-dev": {
"behat/behat": "@stable",
Expand Down
97 changes: 2 additions & 95 deletions main/admin/skills_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,76 +98,6 @@ function parse_csv_data($file)
return $skills;
}

/**
* XML-parser: handle start of element.
*/
function element_start($parser, $data)
{
$data = api_utf8_decode($data);
global $skill;
global $current_tag;
switch ($data) {
case 'Skill':
$skill = [];
break;
default:
$current_tag = $data;
}
}

/**
* XML-parser: handle end of element.
*/
function element_end($parser, $data)
{
$data = api_utf8_decode($data);
global $skill;
global $skills;
global $current_value;
switch ($data) {
case 'Skill':
$skills[] = $skill;
break;
default:
$skill[$data] = $current_value;
break;
}
}

/**
* XML-parser: handle character data.
*/
function character_data($parser, $data)
{
$data = trim(api_utf8_decode($data));
global $current_value;
$current_value = $data;
}

/**
* Read the XML-file.
*
* @param string $file Path to the XML-file
*
* @return array All userinformation read from the file
*/
function parse_xml_data($file)
{
global $current_tag;
global $current_value;
global $skill;
global $skills;
$skills = [];
$parser = xml_parser_create('UTF-8');
xml_set_element_handler($parser, 'element_start', 'element_end');
xml_set_character_data_handler($parser, 'character_data');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_parse($parser, api_utf8_encode_xml(file_get_contents($file)));
xml_parser_free($parser);

return $skills;
}

$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);

Expand All @@ -183,7 +113,7 @@ function parse_xml_data($file)
$file_type = $_POST['file_type'];
Security::clear_token();
$tok = Security::get_token();
$allowed_file_mimetype = ['csv', 'xml'];
$allowed_file_mimetype = ['csv'];
$error_kind_file = false;
$error_message = '';

Expand All @@ -194,10 +124,6 @@ function parse_xml_data($file)
$skills = parse_csv_data($_FILES['import_file']['tmp_name']);
$errors = validate_data($skills);
$error_kind_file = false;
} elseif (strcmp($file_type, 'xml') === 0 && $ext_import_file == $allowed_file_mimetype[1]) {
$skills = parse_xml_data($_FILES['import_file']['tmp_name']);
$errors = validate_data($skills);
$error_kind_file = false;
} else {
$error_kind_file = true;
}
Expand All @@ -222,8 +148,6 @@ function parse_xml_data($file)

if (strcmp($file_type, 'csv') === 0) {
save_data($skills_to_insert);
} elseif (strcmp($file_type, 'xml') === 0) {
save_data($skills_to_insert);
} else {
$error_message = get_lang('YouMustImportAFileAccordingToSelectedOption');
}
Expand Down Expand Up @@ -272,7 +196,7 @@ function parse_xml_data($file)
'radio',
'file_type',
'',
'CSV (<a href="skill_example.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>)',
'CSV (<a href="skill_example.csv" target="_blank" download>'.get_lang('ExampleCSVFile').'</a>)',
'csv'
);
$form->addGroup($group, '', get_lang('FileType'));
Expand All @@ -283,23 +207,6 @@ function parse_xml_data($file)
$form->setDefaults($defaults);
$form->display();

$list = [];
$list_reponse = [];
$result_xml = '';
$i = 0;
$count_fields = count($extra_fields);
if ($count_fields > 0) {
foreach ($extra_fields as $extra) {
$list[] = $extra[1];
$list_reponse[] = 'xxx';
$spaces = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
$result_xml .= $spaces.'&lt;'.$extra[1].'&gt;xxx&lt;/'.$extra[1].'&gt;';
if ($i != $count_fields - 1) {
$result_xml .= '<br/>';
}
$i++;
}
}
?>
<p><?php echo get_lang('CSVMustLookLike').' ('.get_lang('MandatoryFields').')'; ?> :</p>

Expand Down
89 changes: 18 additions & 71 deletions main/admin/user_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,66 +307,6 @@ function parse_csv_data($file)

return $users;
}
/**
* XML-parser: handle start of element.
*
* @param string $parser Deprecated?
* @param string $data The data to be parsed
*/
function element_start($parser, $data)
{
$data = api_utf8_decode($data);
global $user;
global $current_tag;
switch ($data) {
case 'Contact':
$user = [];
break;
default:
$current_tag = $data;
}
}

/**
* XML-parser: handle end of element.
*
* @param string $parser Deprecated?
* @param string $data The data to be parsed
*/
function element_end($parser, $data)
{
$data = api_utf8_decode($data);
global $user;
global $users;
global $current_value;
switch ($data) {
case 'Contact':
if ($user['Status'] == '5') {
$user['Status'] = STUDENT;
}
if ($user['Status'] == '1') {
$user['Status'] = COURSEMANAGER;
}
$users[] = $user;
break;
default:
$user[$data] = $current_value;
break;
}
}

/**
* XML-parser: handle character data.
*
* @param string $parser Parser (deprecated?)
* @param string $data The data to be parsed
*/
function character_data($parser, $data)
{
$data = trim(api_utf8_decode($data));
global $current_value;
$current_value = $data;
}

/**
* Read the XML-file.
Expand All @@ -377,16 +317,23 @@ function character_data($parser, $data)
*/
function parse_xml_data($file)
{
global $users;
$users = [];
$parser = xml_parser_create('UTF-8');
xml_set_element_handler($parser, 'element_start', 'element_end');
xml_set_character_data_handler($parser, 'character_data');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_parse($parser, api_utf8_encode_xml(file_get_contents($file)));
xml_parser_free($parser);
$crawler = new \Symfony\Component\DomCrawler\Crawler();
$crawler->addXmlContent(file_get_contents($file));
$crawler = $crawler->filter('Contacts > Contact ');
$array = [];
foreach ($crawler as $domElement) {
$row = [];
foreach ($domElement->childNodes as $node) {
if ($node->nodeName != '#text') {
$row[$node->nodeName] = $node->nodeValue;
}
}
if (!empty($row)) {
$array[] = $row;
}
}

return $users;
return $array;
}

$this_section = SECTION_PLATFORM_ADMIN;
Expand Down Expand Up @@ -520,14 +467,14 @@ function parse_xml_data($file)
'radio',
'file_type',
'',
'CSV (<a href="example.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>)',
'CSV (<a href="example.csv" target="_blank" download>'.get_lang('ExampleCSVFile').'</a>)',
'csv'
),
$form->createElement(
'radio',
'file_type',
null,
'XML (<a href="example.xml" target="_blank">'.get_lang('ExampleXMLFile').'</a>)',
'XML (<a href="example.xml" target="_blank" download>'.get_lang('ExampleXMLFile').'</a>)',
'xml'
),
];
Expand Down
92 changes: 16 additions & 76 deletions main/admin/user_update_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,86 +254,26 @@ function parse_csv_data($file)

return $users;
}
/**
* XML-parser: handle start of element.
*
* @param string $parser Deprecated?
* @param string $data The data to be parsed
*/
function element_start($parser, $data)
{
$data = api_utf8_decode($data);
global $user;
global $current_tag;
switch ($data) {
case 'Contact':
$user = [];
break;
default:
$current_tag = $data;
}
}

/**
* XML-parser: handle end of element.
*
* @param string $parser Deprecated?
* @param string $data The data to be parsed
*/
function element_end($parser, $data)
function parse_xml_data($file)
{
$data = api_utf8_decode($data);
global $user;
global $users;
global $current_value;
switch ($data) {
case 'Contact':
if ($user['Status'] == '5') {
$user['Status'] = STUDENT;
}
if ($user['Status'] == '1') {
$user['Status'] = COURSEMANAGER;
$crawler = new \Symfony\Component\DomCrawler\Crawler();
$crawler->addXmlContent(file_get_contents($file));
$crawler = $crawler->filter('Contacts > Contact ');
$array = [];
foreach ($crawler as $domElement) {
$row = [];
foreach ($domElement->childNodes as $node) {
if ($node->nodeName != '#text') {
$row[$node->nodeName] = $node->nodeValue;
}
$users[] = $user;
break;
default:
$user[$data] = $current_value;
break;
}
if (!empty($row)) {
$array[] = $row;
}
}
}

/**
* XML-parser: handle character data.
*
* @param string $parser Parser (deprecated?)
* @param string $data The data to be parsed
*/
function character_data($parser, $data)
{
$data = trim(api_utf8_decode($data));
global $current_value;
$current_value = $data;
}

/**
* Read the XML-file.
*
* @param string $file Path to the XML-file
*
* @return array All user information read from the file
*/
function parse_xml_data($file)
{
global $users;
$users = [];
$parser = xml_parser_create('UTF-8');
xml_set_element_handler($parser, 'element_start', 'element_end');
xml_set_character_data_handler($parser, 'character_data');
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_parse($parser, api_utf8_encode_xml(file_get_contents($file)));
xml_parser_free($parser);

return $users;
return $array;
}

$this_section = SECTION_PLATFORM_ADMIN;
Expand Down Expand Up @@ -429,7 +369,7 @@ function parse_xml_data($file)
exit;
}
}
Display :: display_header($tool_name);
Display::display_header($tool_name);

if (!empty($error_message)) {
echo Display::return_message($error_message, 'error');
Expand Down
2 changes: 1 addition & 1 deletion main/admin/usergroup_import.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function save_data($classes)
'radio',
'file_type',
'',
'CSV (<a href="example_class.csv" target="_blank">'.get_lang('ExampleCSVFile').'</a>)',
'CSV (<a href="example_class.csv" target="_blank" download>'.get_lang('ExampleCSVFile').'</a>)',
'csv'
);
$form->addGroup($group, '', get_lang('FileType'), null);
Expand Down
Loading