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
6edd2334
Commit
6edd2334
authored
11 years ago
by
Jared Hancock
Browse files
Options
Downloads
Patches
Plain Diff
Use strongly typed ThreadBody instances for output
parent
67ae49cf
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/class.thread.php
+67
-31
67 additions, 31 deletions
include/class.thread.php
include/client/view.inc.php
+1
-1
1 addition, 1 deletion
include/client/view.inc.php
include/staff/ticket-view.inc.php
+1
-1
1 addition, 1 deletion
include/staff/ticket-view.inc.php
with
69 additions
and
33 deletions
include/class.thread.php
+
67
−
31
View file @
6edd2334
...
...
@@ -140,7 +140,7 @@ class Thread {
$entries
=
array
();
if
((
$res
=
db_query
(
$sql
))
&&
db_num_rows
(
$res
))
{
while
(
$rec
=
db_fetch_array
(
$res
))
{
$rec
[
'body'
]
=
new
ThreadBody
(
$rec
[
'body'
],
$rec
[
'format'
]);
$rec
[
'body'
]
=
ThreadBody
::
fromFormattedText
(
$rec
[
'body'
],
$rec
[
'format'
]);
$entries
[]
=
$rec
;
}
}
...
...
@@ -308,7 +308,7 @@ Class ThreadEntry {
}
function
getBody
()
{
return
$this
->
ht
[
'body'
]
;
return
ThreadBody
::
fromFormattedText
(
$this
->
ht
[
'body'
],
$this
->
ht
[
'format'
])
;
}
function
setBody
(
$body
)
{
...
...
@@ -770,7 +770,7 @@ Class ThreadEntry {
/* variables */
function
__toString
()
{
return
$this
->
getBody
();
return
(
string
)
$this
->
getBody
();
}
function
asVar
()
{
...
...
@@ -1002,7 +1002,7 @@ Class ThreadEntry {
}
}
if
(
!
(
$body
=
(
string
)
$vars
[
'body'
]))
if
(
!
(
$body
=
$vars
[
'body'
]
->
getClean
()
))
$body
=
'-'
;
//Special tag used to signify empty message as stored.
$poster
=
$vars
[
'poster'
];
...
...
@@ -1259,36 +1259,23 @@ class ThreadBody /* extends SplString */ {
var
$type
;
var
$stripped_images
=
array
();
var
$embedded_images
=
array
();
var
$options
=
array
(
'strip-embedded'
=>
true
);
function
__construct
(
$body
,
$type
=
'text'
)
{
function
__construct
(
$body
,
$type
=
'text'
,
$options
=
array
()
)
{
$type
=
strtolower
(
$type
);
if
(
!
in_array
(
$type
,
static
::
$types
))
throw
new
Exception
(
$type
.
': Unsupported ThreadBody type'
);
$this
->
body
=
(
string
)
$body
;
$this
->
type
=
$type
;
$this
->
options
=
array_merge
(
$this
->
options
,
$options
);
}
function
isEmpty
()
{
return
!
$this
->
body
||
$this
->
body
==
'-'
;
}
function
display
(
$output
=
false
)
{
if
(
$this
->
isEmpty
())
return
'(empty)'
;
switch
(
strtolower
(
$this
->
type
))
{
case
'text'
:
return
'<div style="white-space:pre-wrap">'
.
$this
->
body
.
'</div>'
;
case
'html'
:
switch
(
$output
)
{
case
'pdf'
:
return
Format
::
clickableurls
(
$this
->
body
,
false
);
default
:
return
Format
::
display
(
$this
->
body
);
}
}
}
function
convertTo
(
$type
)
{
if
(
$type
===
$this
->
type
)
return
$this
;
...
...
@@ -1340,21 +1327,58 @@ class ThreadBody /* extends SplString */ {
return
$this
->
type
;
}
function
getClean
()
{
return
trim
(
$this
->
body
);
}
function
__toString
()
{
return
$this
->
body
;
return
$this
->
display
();
}
function
toHtml
()
{
return
$this
->
display
(
'html'
);
}
static
function
fromFormattedText
(
$text
,
$format
=
false
)
{
switch
(
$format
)
{
case
'text'
:
return
new
TextThreadBody
(
$text
);
case
'html'
:
return
new
HtmlThreadBody
(
$text
,
array
(
'strip-embedded'
=>
false
));
default
:
return
new
ThreadBody
(
$text
);
}
}
}
class
TextThreadBody
extends
ThreadBody
{
function
__construct
(
$body
)
{
parent
::
__construct
(
Format
::
stripEmptyLines
(
$body
),
'text'
);
function
__construct
(
$body
,
$options
=
array
())
{
parent
::
__construct
(
$body
,
'text'
,
$options
);
}
function
getClean
()
{
return
Format
::
stripEmptyLines
(
$this
->
body
);
}
function
display
(
$output
=
false
)
{
if
(
$this
->
isEmpty
())
return
'(empty)'
;
switch
(
$output
)
{
case
'html'
:
return
'<div style="white-space:pre-wrap">'
.
$this
->
body
.
'</div>'
;
case
'pdf'
:
return
nl2br
(
$this
->
body
);
default
:
return
'<pre>'
.
$this
->
body
.
'</pre>'
;
}
}
}
class
HtmlThreadBody
extends
ThreadBody
{
function
__construct
(
$body
)
{
$body
=
$this
->
ex
tr
a
ct
EmbeddedHtmlImages
(
$body
);
$body
=
trim
(
$body
,
" <>br/
\t\n\r
"
)
?
Format
::
safe_html
(
$body
)
:
''
;
parent
::
__cons
tr
u
ct
(
$body
,
'html'
);
function
__construct
(
$body
,
$options
=
array
()
)
{
parent
::
__cons
tr
u
ct
(
$body
,
'html'
,
$options
);
if
(
$this
->
options
[
'strip-embedded'
])
$this
->
body
=
$this
->
ex
tr
a
ct
EmbeddedHtmlImages
(
$this
->
body
);
}
function
extractEmbeddedHtmlImages
(
$body
)
{
...
...
@@ -1370,8 +1394,20 @@ class HtmlThreadBody extends ThreadBody {
},
$body
);
}
function
__toString
()
{
return
Format
::
sanitize
(
$this
->
body
);
function
getClean
()
{
return
trim
(
$body
,
" <>br/
\t\n\r
"
)
?
Format
::
sanitize
(
$body
)
:
''
;
}
function
display
(
$output
=
false
)
{
if
(
$this
->
isEmpty
())
return
'(empty)'
;
switch
(
$output
)
{
case
'pdf'
:
return
Format
::
clickableurls
(
$this
->
body
,
false
);
default
:
return
Format
::
display
(
$this
->
body
);
}
}
}
?>
This diff is collapsed.
Click to expand it.
include/client/view.inc.php
+
1
−
1
View file @
6edd2334
...
...
@@ -110,7 +110,7 @@ if($ticket->getThreadCount() && ($thread=$ticket->getClientThread())) {
?>
<table
class=
"thread-entry
<?php
echo
$threadType
[
$entry
[
'thread_type'
]];
?>
"
cellspacing=
"0"
cellpadding=
"1"
width=
"800"
border=
"0"
>
<tr><th>
<?php
echo
Format
::
db_datetime
(
$entry
[
'created'
]);
?>
<span
class=
"textra"
></span><span>
<?php
echo
$poster
;
?>
</span></th></tr>
<tr><td
class=
"thread-body"
><div>
<?php
echo
$entry
[
'body'
]
->
display
();
?>
</div></td></tr>
<tr><td
class=
"thread-body"
><div>
<?php
echo
$entry
[
'body'
]
->
toHtml
();
?>
</div></td></tr>
<?php
if
(
$entry
[
'attachments'
]
&&
(
$tentry
=
$ticket
->
getThreadEntry
(
$entry
[
'id'
]))
...
...
This diff is collapsed.
Click to expand it.
include/staff/ticket-view.inc.php
+
1
−
1
View file @
6edd2334
...
...
@@ -362,7 +362,7 @@ $tcount+= $ticket->getNumNotes();
</tr>
<tr><td
colspan=
"4"
class=
"thread-body"
id=
"thread-id-
<?php
echo
$entry
[
'id'
];
?>
"
><div>
<?php
echo
$entry
[
'body'
]
->
display
();
?>
</div></td></tr>
echo
$entry
[
'body'
]
->
toHtml
();
?>
</div></td></tr>
<?php
if
(
$entry
[
'attachments'
]
&&
(
$tentry
=
$ticket
->
getThreadEntry
(
$entry
[
'id'
]))
...
...
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