Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
51c5ef9e
Commit
51c5ef9e
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Extract embedded images to separate attachments
parent
d32ad09c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/class.thread.php
+30
-0
30 additions, 0 deletions
include/class.thread.php
with
30 additions
and
0 deletions
include/class.thread.php
+
30
−
0
View file @
51c5ef9e
...
...
@@ -979,6 +979,17 @@ Class ThreadEntry {
}
}
// Handle extracted embedded images (<img src="data:base64,..." />).
// The extraction has already been performed in the ThreadBody
// class. Here they should simply be added to the attachments list
if
(
$atts
=
$vars
[
'body'
]
->
getEmbeddedHtmlImages
())
{
if
(
!
is_array
(
$vars
[
'attachments'
]))
$vars
[
'attachments'
]
=
array
();
foreach
(
$atts
as
$info
)
{
$vars
[
'attachments'
][]
=
$info
;
}
}
if
(
!
(
$body
=
Format
::
sanitize
(
(
string
)
$vars
[
'body'
]
->
convertTo
(
'html'
))))
$body
=
'-'
;
//Special tag used to signify empty message as stored.
...
...
@@ -1230,6 +1241,7 @@ class ThreadBody /* extends SplString */ {
var
$body
;
var
$type
;
var
$stripped_images
=
array
();
var
$embedded_images
=
array
();
function
__construct
(
$body
,
$type
=
'text'
)
{
$type
=
strtolower
(
$type
);
...
...
@@ -1282,6 +1294,10 @@ class ThreadBody /* extends SplString */ {
return
$this
->
stripped_images
;
}
function
getEmbeddedHtmlImages
()
{
return
$this
->
embedded_images
;
}
function
__toString
()
{
return
$this
->
body
;
}
...
...
@@ -1294,8 +1310,22 @@ class TextThreadBody extends ThreadBody {
}
class
HtmlThreadBody
extends
ThreadBody
{
function
__construct
(
$body
)
{
$body
=
$this
->
extractEmbeddedHtmlImages
(
$body
);
$body
=
trim
(
$body
,
" <>br/
\t\n\r
"
)
?
Format
::
safe_html
(
$body
)
:
''
;
parent
::
__construct
(
$body
,
'html'
);
}
function
extractEmbeddedHtmlImages
(
$body
)
{
$self
=
$this
;
return
preg_replace_callback
(
'/src="(data:[^"]+)"/'
,
function
(
$m
)
use
(
$self
)
{
$info
=
Format
::
parseRfc2397
(
$m
[
1
],
false
,
false
);
$info
[
'cid'
]
=
'img'
.
Misc
::
randCode
(
12
);
list
(,
$type
)
=
explode
(
'/'
,
$info
[
'type'
],
2
);
$info
[
'name'
]
=
'image'
.
Misc
::
randCode
(
4
)
.
'.'
.
$type
;
$self
->
embedded_images
[]
=
$info
;
return
'src="cid:'
.
$info
[
'cid'
]
.
'"'
;
},
$body
);
}
}
?>
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