mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 02:58:43 +02:00
ormCaseLog: Introduce class constants for formats
This commit is contained in:
@@ -33,6 +33,17 @@ define('CASELOG_SEPARATOR', "\n".'========== %1$s : %2$s (%3$d) ============'."\
|
|||||||
* @license http://opensource.org/licenses/AGPL-3.0
|
* @license http://opensource.org/licenses/AGPL-3.0
|
||||||
*/
|
*/
|
||||||
class ormCaseLog {
|
class ormCaseLog {
|
||||||
|
/**
|
||||||
|
* @var string "plain text" format for the log
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
public const ENUM_FORMAT_TEXT = 'text';
|
||||||
|
/**
|
||||||
|
* @var string "HTML" format for the log
|
||||||
|
* @since 3.0.0
|
||||||
|
*/
|
||||||
|
public const ENUM_FORMAT_HTML = 'html';
|
||||||
|
|
||||||
protected $m_sLog;
|
protected $m_sLog;
|
||||||
protected $m_aIndex;
|
protected $m_aIndex;
|
||||||
protected $m_bModified;
|
protected $m_bModified;
|
||||||
@@ -53,7 +64,7 @@ class ormCaseLog {
|
|||||||
{
|
{
|
||||||
if ($bConvertToPlainText)
|
if ($bConvertToPlainText)
|
||||||
{
|
{
|
||||||
// Rebuild the log, but filtering any HTML markup for the all 'html' entries in the log
|
// Rebuild the log, but filtering any HTML markup for the all {@see static::ENUM_FORMAT_HTML} entries in the log
|
||||||
return $this->GetAsPlainText();
|
return $this->GetAsPlainText();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -136,14 +147,14 @@ class ormCaseLog {
|
|||||||
$sDate = '';
|
$sDate = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sFormat = array_key_exists('format', $this->m_aIndex[$index]) ? $this->m_aIndex[$index]['format'] : 'text';
|
$sFormat = array_key_exists('format', $this->m_aIndex[$index]) ? $this->m_aIndex[$index]['format'] : static::ENUM_FORMAT_TEXT;
|
||||||
switch($sFormat)
|
switch($sFormat)
|
||||||
{
|
{
|
||||||
case 'text':
|
case static::ENUM_FORMAT_TEXT:
|
||||||
$sHtmlEntry = utils::TextToHtml($sTextEntry);
|
$sHtmlEntry = utils::TextToHtml($sTextEntry);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'html':
|
case static::ENUM_FORMAT_HTML:
|
||||||
$sHtmlEntry = $sTextEntry;
|
$sHtmlEntry = $sTextEntry;
|
||||||
$sTextEntry = utils::HtmlToText($sHtmlEntry);
|
$sTextEntry = utils::HtmlToText($sHtmlEntry);
|
||||||
break;
|
break;
|
||||||
@@ -175,7 +186,8 @@ class ormCaseLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a "plain text" version of the log (equivalent to $this->m_sLog) where all the HTML markup from the 'html' entries have been removed
|
* Returns a "plain text" version of the log (equivalent to $this->m_sLog) where all the HTML markup from the {@see static::ENUM_FORMAT_HTML} entries have been removed
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function GetAsPlainText()
|
public function GetAsPlainText()
|
||||||
@@ -237,7 +249,7 @@ class ormCaseLog {
|
|||||||
$iPos += $aIndex[$index]['separator_length'];
|
$iPos += $aIndex[$index]['separator_length'];
|
||||||
$sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
$sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
||||||
$sCSSClass = 'caselog_entry_html';
|
$sCSSClass = 'caselog_entry_html';
|
||||||
if (!array_key_exists('format', $aIndex[$index]) || ($aIndex[$index]['format'] == 'text'))
|
if (!array_key_exists('format', $aIndex[$index]) || ($aIndex[$index]['format'] == static::ENUM_FORMAT_TEXT))
|
||||||
{
|
{
|
||||||
$sCSSClass = 'caselog_entry';
|
$sCSSClass = 'caselog_entry';
|
||||||
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
||||||
@@ -320,7 +332,7 @@ class ormCaseLog {
|
|||||||
$iPos += $aIndex[$index]['separator_length'];
|
$iPos += $aIndex[$index]['separator_length'];
|
||||||
$sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
$sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
||||||
$sCSSClass = 'case_log_simple_html_entry_html';
|
$sCSSClass = 'case_log_simple_html_entry_html';
|
||||||
if (!array_key_exists('format', $aIndex[$index]) || ($aIndex[$index]['format'] == 'text'))
|
if (!array_key_exists('format', $aIndex[$index]) || ($aIndex[$index]['format'] == static::ENUM_FORMAT_TEXT))
|
||||||
{
|
{
|
||||||
$sCSSClass = 'case_log_simple_html_entry';
|
$sCSSClass = 'case_log_simple_html_entry';
|
||||||
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
||||||
@@ -425,7 +437,7 @@ class ormCaseLog {
|
|||||||
}
|
}
|
||||||
$iPos += $aIndex[$index]['separator_length'];
|
$iPos += $aIndex[$index]['separator_length'];
|
||||||
$sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
$sTextEntry = substr($this->m_sLog, $iPos, $aIndex[$index]['text_length']);
|
||||||
if (!array_key_exists('format', $aIndex[$index]) || ($aIndex[$index]['format'] == 'text'))
|
if (!array_key_exists('format', $aIndex[$index]) || ($aIndex[$index]['format'] == static::ENUM_FORMAT_TEXT))
|
||||||
{
|
{
|
||||||
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
$sTextEntry = str_replace(array("\r\n", "\n", "\r"), "<br/>", htmlentities($sTextEntry, ENT_QUOTES, 'UTF-8'));
|
||||||
if (!is_null($aTransfoHandler))
|
if (!is_null($aTransfoHandler))
|
||||||
@@ -590,7 +602,7 @@ class ormCaseLog {
|
|||||||
'date' => time(),
|
'date' => time(),
|
||||||
'text_length' => $iTextlength,
|
'text_length' => $iTextlength,
|
||||||
'separator_length' => $iSepLength,
|
'separator_length' => $iSepLength,
|
||||||
'format' => 'html',
|
'format' => static::ENUM_FORMAT_HTML,
|
||||||
);
|
);
|
||||||
$this->m_bModified = true;
|
$this->m_bModified = true;
|
||||||
}
|
}
|
||||||
@@ -644,11 +656,11 @@ class ormCaseLog {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// The default is HTML
|
// The default is HTML
|
||||||
$sFormat = 'html';
|
$sFormat = static::ENUM_FORMAT_HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sText = isset($oJson->message) ? $oJson->message : '';
|
$sText = isset($oJson->message) ? $oJson->message : '';
|
||||||
if ($sFormat == 'html')
|
if ($sFormat == static::ENUM_FORMAT_HTML)
|
||||||
{
|
{
|
||||||
$sText = HTMLSanitizer::Sanitize($sText);
|
$sText = HTMLSanitizer::Sanitize($sText);
|
||||||
}
|
}
|
||||||
@@ -671,7 +683,7 @@ class ormCaseLog {
|
|||||||
$this->m_bModified = true;
|
$this->m_bModified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetModifiedEntry($sFormat = 'text')
|
public function GetModifiedEntry($sFormat = self::ENUM_FORMAT_TEXT)
|
||||||
{
|
{
|
||||||
$sModifiedEntry = '';
|
$sModifiedEntry = '';
|
||||||
if ($this->m_bModified)
|
if ($this->m_bModified)
|
||||||
@@ -686,15 +698,15 @@ class ormCaseLog {
|
|||||||
* @param string The expected output format text|html
|
* @param string The expected output format text|html
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function GetLatestEntry($sFormat = 'text')
|
public function GetLatestEntry($sFormat = self::ENUM_FORMAT_TEXT)
|
||||||
{
|
{
|
||||||
$sRes = '';
|
$sRes = '';
|
||||||
$aLastEntry = end($this->m_aIndex);
|
$aLastEntry = end($this->m_aIndex);
|
||||||
$sRaw = substr($this->m_sLog, $aLastEntry['separator_length'], $aLastEntry['text_length']);
|
$sRaw = substr($this->m_sLog, $aLastEntry['separator_length'], $aLastEntry['text_length']);
|
||||||
switch($sFormat)
|
switch($sFormat)
|
||||||
{
|
{
|
||||||
case 'text':
|
case static::ENUM_FORMAT_TEXT:
|
||||||
if ($aLastEntry['format'] == 'text')
|
if ($aLastEntry['format'] == static::ENUM_FORMAT_TEXT)
|
||||||
{
|
{
|
||||||
$sRes = $sRaw;
|
$sRes = $sRaw;
|
||||||
}
|
}
|
||||||
@@ -704,8 +716,8 @@ class ormCaseLog {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'html':
|
case static::ENUM_FORMAT_HTML:
|
||||||
if ($aLastEntry['format'] == 'text')
|
if ($aLastEntry['format'] == static::ENUM_FORMAT_TEXT)
|
||||||
{
|
{
|
||||||
$sRes = utils::TextToHtml($sRaw);
|
$sRes = utils::TextToHtml($sRaw);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user