Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Moodle Qtype Moopt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elc
Moodle Qtype Moopt
Commits
073af36b
Commit
073af36b
authored
1 year ago
by
Isabel Uffinger
Browse files
Options
Downloads
Patches
Plain Diff
first test to encode to utf8
parent
ecf997c3
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
externallib.php
+4
-2
4 additions, 2 deletions
externallib.php
locallib.php
+17
-2
17 additions, 2 deletions
locallib.php
with
23 additions
and
5 deletions
.gitignore
+
2
−
1
View file @
073af36b
*.min.js.map
.idea/
.vscode
\ No newline at end of file
This diff is collapsed.
Click to expand it.
externallib.php
+
4
−
2
View file @
073af36b
...
...
@@ -192,8 +192,9 @@ class qtype_moopt_external extends external_api {
break
;
}
else
if
(
$child
->
localName
==
'attached-txt-file'
)
{
$pathinfo
=
pathinfo
(
'/'
.
$child
->
nodeValue
);
$encoding
=
$child
->
attributes
->
getNamedItem
(
'encoding'
)
->
nodeValue
;
$filecontent
=
get_text_content_from_file
(
$usercontext
,
$draftid
,
$keepfilename
,
$pathinfo
[
'dirname'
]
.
'/'
,
$pathinfo
[
'basename'
]);
$pathinfo
[
'dirname'
]
.
'/'
,
$pathinfo
[
'basename'
]
,
true
,
$encoding
);
$defaultfilename
=
basename
(
$child
->
nodeValue
);
$fileid
=
$file
->
attributes
->
getNamedItem
(
'id'
)
->
nodeValue
;
$enablefreetext
=
true
;
...
...
@@ -259,8 +260,9 @@ class qtype_moopt_external extends external_api {
}
else
if
(
$child
->
localName
==
'attached-txt-file'
)
{
$pathinfo
=
pathinfo
(
'/'
.
$child
->
nodeValue
);
$filename
=
basename
(
$child
->
nodeValue
);
$encoding
=
$child
->
attributes
->
getNamedItem
(
'encoding'
)
->
nodeValue
;
$filecontent
=
get_text_content_from_file
(
$usercontext
,
$draftid
,
$keepfilename
,
$pathinfo
[
'dirname'
]
.
'/'
,
$pathinfo
[
'basename'
]);
$pathinfo
[
'dirname'
]
.
'/'
,
$pathinfo
[
'basename'
]
,
true
,
$encoding
);
}
if
(
!
empty
(
$filecontent
))
...
...
This diff is collapsed.
Click to expand it.
locallib.php
+
17
−
2
View file @
073af36b
...
...
@@ -282,7 +282,7 @@ function create_domdocument_from_task_xml($usercontext, $draftareaid, $xmlfilena
* @return string
* @throws invalid_parameter_exception
*/
function
get_text_content_from_file
(
$usercontext
,
$draftareaid
,
$keepfilename
,
$filepath
,
$filename
)
function
get_text_content_from_file
(
$usercontext
,
$draftareaid
,
$keepfilename
,
$filepath
,
$filename
,
$attached
,
$encoding
)
{
$fs
=
get_file_storage
();
$file
=
$fs
->
get_file
(
$usercontext
->
id
,
'user'
,
'draft'
,
$draftareaid
,
$filepath
,
$filename
);
...
...
@@ -294,7 +294,22 @@ function get_text_content_from_file($usercontext, $draftareaid, $keepfilename, $
// TODO: make sure the mimetype is plain text
// even task.xmls may contain mistakes (eg PDF )
return
$file
->
get_content
();
//check if encoding of attached ist utf-8 else convert
$content
=
$file
->
get_content
();
if
(
$encoding
!==
false
){
$enc
=
$encoding
;
}
else
{
$enc
=
mb_detect_encoding
(
$content
,
mb_detect_order
(),
true
);
if
(
$enc
===
false
){
throw
new
invalid_parameter_exception
(
'Encoding of attached file '
.
$filepath
.
$filename
.
'could\'nt be detectet.'
);
}
}
$content
=
mb_convert_encoding
(
$content
,
$enc
,
'UTF-8'
);
if
(
$enc
!==
'UTF-8'
){
$content
=
mb_convert_encoding
(
$content
,
'UTF-8'
,
$enc
);
}
return
$content
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment