diff --git a/lib/documentmanagement/documentmetadataversion.inc.php b/lib/documentmanagement/documentmetadataversion.inc.php index 12ed6d9..0d39e50 100644 --- a/lib/documentmanagement/documentmetadataversion.inc.php +++ b/lib/documentmanagement/documentmetadataversion.inc.php @@ -95,8 +95,8 @@ class KTDocumentMetadataVersion extends KTEntity { function setContentVersion($iNewValue) { $this->iContentVersion = $iNewValue; } function getDocumentTypeId() { return $this->iDocumentTypeId; } function setDocumentTypeId($iNewValue) { $this->iDocumentTypeId = $iNewValue; } - function getName() { return $this->sName; } - function setName($sNewValue) { $this->sName = $sNewValue; } + function getName() { return sanitizeForSQLtoHTML($this->sName); } + function setName($sNewValue) { $this->sName = sanitizeForSQL($sNewValue); } function getDescription() { return $this->sDescription; } function setDescription($sNewValue) { $this->sDescription = $sNewValue; } function getStatusId() { return $this->iStatusId; } diff --git a/lib/sanitize.inc b/lib/sanitize.inc deleted file mode 100644 index ae283f3..0000000 --- a/lib/sanitize.inc +++ /dev/null @@ -1,53 +0,0 @@ - diff --git a/lib/util/sanitize.inc b/lib/util/sanitize.inc index e8b7b1c..96a169b 100644 --- a/lib/util/sanitize.inc +++ b/lib/util/sanitize.inc @@ -52,11 +52,12 @@ function sanitize($string) { function sanitizeForSQL($string, $min='', $max='') { + $string = trim($string); + if(get_magic_quotes_gpc()) $string = stripslashes($string); + $len = strlen($string); if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return false; - if(get_magic_quotes_gpc()) $string = stripslashes($string); - if(function_exists("mysql_real_escape_string")) { return mysql_real_escape_string($string); } else { @@ -64,38 +65,54 @@ function sanitizeForSQL($string, $min='', $max='') { } } +function sanitizeForSQLtoHTML($string, $min='', $max='') { + + return stripslashes(trim($string)); + +} + function sanitizeForHTML($string, $min='', $max='') { + $string = trim($string); + if(get_magic_quotes_gpc()) $string = stripslashes($string); + $len = strlen($string); if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return false; - $pattern[0] = '/\&/'; - $pattern[1] = '//"; - $pattern[3] = '/\n/'; - $pattern[4] = '/"/'; - $pattern[5] = "/'/"; - $pattern[6] = "/%/"; - $pattern[7] = '/\( /'; - $pattern[8] = '/\)/'; - $pattern[9] = '/\+/'; - $pattern[10] = '/-/'; - $replacement[0] = '&'; - $replacement[1] = '<'; - $replacement[2] = '>'; - $replacement[3] = '
'; - $replacement[4] = '"'; - $replacement[5] = '''; - $replacement[6] = '%'; - $replacement[7] = '('; - $replacement[8] = ')'; - $replacement[9] = '+'; - $replacement[10] = '-'; - return preg_replace( $pattern, $replacement, $string); + if(function_exists("htmlspecialchars")) { + return htmlspecialchars($string); + } else { + $pattern[0] = '/\&/'; + $pattern[1] = '//"; + $pattern[3] = '/\n/'; + $pattern[4] = '/"/'; + $pattern[5] = "/'/"; + $pattern[6] = "/%/"; + $pattern[7] = '/\( /'; + $pattern[8] = '/\)/'; + $pattern[9] = '/\+/'; + $pattern[10] = '/-/'; + $replacement[0] = '&'; + $replacement[1] = '<'; + $replacement[2] = '>'; + $replacement[3] = '
'; + $replacement[4] = '"'; + $replacement[5] = '''; + $replacement[6] = '%'; + $replacement[7] = '('; + $replacement[8] = ')'; + $replacement[9] = '+'; + $replacement[10] = '-'; + return preg_replace( $pattern, $replacement, $string); + } } function sanitizeForSYSTEM($string, $min='', $max='') { + $string = trim($string); + if(get_magic_quotes_gpc()) $string = stripslashes($string); + $len = strlen($string); if((($min != '') && ($len < $min)) || (($max != '') && ($len > $max))) return false; diff --git a/plugins/ktcore/document/edit.php b/plugins/ktcore/document/edit.php index dd6863f..f854ebc 100644 --- a/plugins/ktcore/document/edit.php +++ b/plugins/ktcore/document/edit.php @@ -96,7 +96,7 @@ class KTDocumentEditAction extends KTDocumentAction { 'description' => sprintf(_kt("The document title is used as the main name of a document throughout %s™."), APP_NAME), 'name' => 'document_title', 'required' => true, - 'value' => $this->oDocument->getName(), + 'value' => sanitizeForHTML($this->oDocument->getName()), )), ); $validators = array( @@ -191,7 +191,8 @@ class KTDocumentEditAction extends KTDocumentAction { if ($this->oDocument->getDocumentTypeId() != $doctypeid) { $this->oDocument->setDocumentTypeId($doctypeid); } - $this->oDocument->setName(sanitize($data['document_title'])); + $this->oDocument->setName(($data['document_title'])); + $res = $this->oDocument->update(); if (PEAR::isError($res)) { $oForm->handleError(sprintf(_kt("Unexpected failure to update document title: %s"), $res->getMessage())); diff --git a/templates/kt3/document/view.smarty b/templates/kt3/document/view.smarty index 39d321a..ef1a4e8 100644 --- a/templates/kt3/document/view.smarty +++ b/templates/kt3/document/view.smarty @@ -1,6 +1,5 @@

{$document->getName()}

- {capture assign=version} {$document->getMajorVersionNumber()}.{$document->getMinorVersionNumber()} {/capture} diff --git a/templates/kt3/fieldsets/simple_versioned.smarty b/templates/kt3/fieldsets/simple_versioned.smarty index dfc279a..0a39a0d 100644 --- a/templates/kt3/fieldsets/simple_versioned.smarty +++ b/templates/kt3/fieldsets/simple_versioned.smarty @@ -13,10 +13,10 @@ {$aFieldPair.field->getName()} - {if ($aFieldPair.current_value !== null)}{$aFieldPair.current_value|escape:"htmlall"} + {if ($aFieldPair.current_value !== null)}{$aFieldPair.current_value} {else}{i18n}no value in this version{/i18n}{/if} - {if ($aFieldPair.previous_value !== null)}{$aFieldPair.previous_value|escape:"htmlall"} + {if ($aFieldPair.previous_value !== null)}{$aFieldPair.previous_value} {else}{i18n}no value in this version{/i18n}{/if} {/foreach} diff --git a/templates/kt3/standard_page.smarty b/templates/kt3/standard_page.smarty index e9ace3c..197d5cd 100644 --- a/templates/kt3/standard_page.smarty +++ b/templates/kt3/standard_page.smarty @@ -132,9 +132,9 @@ {if ($page->breadcrumbs !== false)} {foreach item=aCrumb from=$page->breadcrumbs name=bc} {if ($aCrumb.url) } - {$aCrumb.label|escape} + {$aCrumb.label} {else} - {$aCrumb.label|escape|truncate:40:"...":true} + {$aCrumb.label|mb_truncate:40:"...":true} {/if} {if (!$smarty.foreach.bc.last)} » diff --git a/templates/ktcore/action/checkout_final.smarty b/templates/ktcore/action/checkout_final.smarty index 0724945..4006a44 100644 --- a/templates/ktcore/action/checkout_final.smarty +++ b/templates/ktcore/action/checkout_final.smarty @@ -3,7 +3,7 @@ {$context->oPage->requireJSResource("thirdpartyjs/MochiKit/Iter.js")} {$context->oPage->requireJSResource("thirdpartyjs/MochiKit/DOM.js")} -{capture assign=sLocation}action=checkout_final&fDocumentId={$context->oDocument->getId()}&reason={$reason|escape}{/capture} +{capture assign=sLocation}action=checkout_final&fDocumentId={$context->oDocument->getId()}&reason={$reason}{/capture} {capture assign=sJavascript} function doCheckout () {ldelim} diff --git a/templates/ktcore/document/cleanup.smarty b/templates/ktcore/document/cleanup.smarty index 3f95fab..d83d471 100644 --- a/templates/ktcore/document/cleanup.smarty +++ b/templates/ktcore/document/cleanup.smarty @@ -28,7 +28,7 @@ which you should investigate.{/i18n}

{i18n}The following files are present in the repository, but do not exist in the database.{/i18n}:

{/if} diff --git a/templates/ktcore/document/cleanup_script.smarty b/templates/ktcore/document/cleanup_script.smarty index ca6e131..90bca9b 100644 --- a/templates/ktcore/document/cleanup_script.smarty +++ b/templates/ktcore/document/cleanup_script.smarty @@ -29,7 +29,7 @@ {i18n}The following files are present in the repository, but do not exist in the database.{/i18n}: {foreach from=$aFilesToRemove item=sFile} - {$sFile|escape} + {$sFile} {/foreach} {/if} diff --git a/templates/ktcore/document/edit.smarty b/templates/ktcore/document/edit.smarty index 5904675..7b9e420 100644 --- a/templates/ktcore/document/edit.smarty +++ b/templates/ktcore/document/edit.smarty @@ -11,7 +11,7 @@ {$context->oPage->requireCSSResource('resources/css/kt-treewidget.css')} -

{i18n}Editing{/i18n}: {$document->getName()}

+

{i18n}Editing{/i18n}: {$document->getName()|wordwrap:40:"
\n":true}

{capture assign=link}{addQS}action=selectType&fDocumentId={$document->getId()}{/addQS}{/capture}

{i18n arg_link=$link arg_name=$type_name}Change the document type. The current type is "#name#"{/i18n}

diff --git a/templates/ktcore/document/view.smarty b/templates/ktcore/document/view.smarty index 2630cde..4385ab3 100644 --- a/templates/ktcore/document/view.smarty +++ b/templates/ktcore/document/view.smarty @@ -1,4 +1,4 @@ -

get("ui/morphTo")}/title_bullet.png{else}{$rootUrl}/resources/graphics/title_bullet.png{/if}"/>{$document->getName()|escape|wordwrap:40:"\n":true}

+

get("ui/morphTo")}/title_bullet.png{else}{$rootUrl}/resources/graphics/title_bullet.png{/if}"/>{$document->getName()|mb_wordwrap:40:"
\n":true}

{if ($document->getIsCheckedOut() == 1)} {capture assign=checkout_user}{$sCheckoutUser}{/capture} diff --git a/templates/ktcore/documenttypes/edit.smarty b/templates/ktcore/documenttypes/edit.smarty index 26d07e1..b46227d 100644 --- a/templates/ktcore/documenttypes/edit.smarty +++ b/templates/ktcore/documenttypes/edit.smarty @@ -3,7 +3,7 @@
- +
diff --git a/templates/ktcore/fields/edit.smarty b/templates/ktcore/fields/edit.smarty index 0f03b9b..81fa6c0 100644 --- a/templates/ktcore/fields/edit.smarty +++ b/templates/ktcore/fields/edit.smarty @@ -1,4 +1,4 @@ -

{i18n}Fieldset{/i18n}: {$oFieldset->getName()|escape}

+

{i18n}Fieldset{/i18n}: {$oFieldset->getName()}

@@ -9,11 +9,11 @@ - + - +
{i18n}Name{/i18n}
{i18n}Namespace{/i18n}
@@ -30,7 +30,7 @@ {foreach from=$oFieldset->getFields() item=oField}
  • +value="{$oField->getId()}" />{$oField->getName()} {/foreach} diff --git a/templates/ktcore/login.smarty b/templates/ktcore/login.smarty index d5f9199..aabb741 100644 --- a/templates/ktcore/login.smarty +++ b/templates/ktcore/login.smarty @@ -21,7 +21,7 @@ - + {if $config->get("ui/mainLogo") != ''} {$config->get(
    {else} diff --git a/templates/ktcore/manage_help_item.smarty b/templates/ktcore/manage_help_item.smarty index 5cd539f..d3852c1 100644 --- a/templates/ktcore/manage_help_item.smarty +++ b/templates/ktcore/manage_help_item.smarty @@ -13,9 +13,9 @@ tinyMCE.init({

    {i18n}Title{/i18n}

    - +

    {i18n}Help content{/i18n}

    - +
    diff --git a/templates/ktcore/metadata/admin/basic_overview.smarty b/templates/ktcore/metadata/admin/basic_overview.smarty index 8227ca1..f4e39b3 100644 --- a/templates/ktcore/metadata/admin/basic_overview.smarty +++ b/templates/ktcore/metadata/admin/basic_overview.smarty @@ -18,7 +18,7 @@ of related information.{/i18n}

    {foreach from=$fields item=oField} - {$oField->getName()|escape} + {$oField->getName()} {i18n}edit{/i18n} diff --git a/templates/ktcore/metadata/admin/manage_lookups.smarty b/templates/ktcore/metadata/admin/manage_lookups.smarty index 4ec002a..763663d 100644 --- a/templates/ktcore/metadata/admin/manage_lookups.smarty +++ b/templates/ktcore/metadata/admin/manage_lookups.smarty @@ -37,7 +37,7 @@ that are possible for a given lookup:{/i18n}

    {foreach from=$lookups item=oLookup} - {$oLookup->getName()|escape} + {$oLookup->getName()} {if (!$oLookup->getDisabled())}{i18n}Yes{/i18n}{else}{i18n}No{/i18n}{/if} {if ($oLookup->getIsStuck())}{i18n}Yes{/i18n}{else} {/if} diff --git a/templates/ktcore/metadata/chooseFromMetadataLookup.smarty b/templates/ktcore/metadata/chooseFromMetadataLookup.smarty index 2a7c2b2..65de114 100644 --- a/templates/ktcore/metadata/chooseFromMetadataLookup.smarty +++ b/templates/ktcore/metadata/chooseFromMetadataLookup.smarty @@ -3,7 +3,7 @@ {assign var="aLookups" value=$aFieldInfo.values}
    - +

    FIXME

    diff --git a/templates/ktcore/metadata/conditional/ajax_complex_get_behaviour_list.smarty b/templates/ktcore/metadata/conditional/ajax_complex_get_behaviour_list.smarty index e9b629f..55b60ba 100644 --- a/templates/ktcore/metadata/conditional/ajax_complex_get_behaviour_list.smarty +++ b/templates/ktcore/metadata/conditional/ajax_complex_get_behaviour_list.smarty @@ -1,5 +1,5 @@ {foreach from=$aBehaviours item=oBehaviour} - + {/foreach} diff --git a/templates/ktcore/metadata/conditional/conditional_admin_overview.smarty b/templates/ktcore/metadata/conditional/conditional_admin_overview.smarty index 1ace2d8..17aeb48 100644 --- a/templates/ktcore/metadata/conditional/conditional_admin_overview.smarty +++ b/templates/ktcore/metadata/conditional/conditional_admin_overview.smarty @@ -71,7 +71,7 @@ ordering!{/i18n}

    {foreach from=$fields item=oField} - {$oField->getName()|escape} + {$oField->getName()} {i18n}edit{/i18n} diff --git a/templates/ktcore/metadata/conditional/editsimple.smarty b/templates/ktcore/metadata/conditional/editsimple.smarty index 13df1a8..48dc91a 100644 --- a/templates/ktcore/metadata/conditional/editsimple.smarty +++ b/templates/ktcore/metadata/conditional/editsimple.smarty @@ -96,7 +96,7 @@ refresh the page.{/i18n}

    diff --git a/templates/ktcore/metadata/conditional/manageConditional.smarty b/templates/ktcore/metadata/conditional/manageConditional.smarty index 4318ea4..c878bc5 100644 --- a/templates/ktcore/metadata/conditional/manageConditional.smarty +++ b/templates/ktcore/metadata/conditional/manageConditional.smarty @@ -27,7 +27,7 @@ the issues identified below.{/i18n} {if $sIncomplete}
    {i18n}This error prevents this fieldset from being set -to complete{/i18n}: {$sIncomplete|escape} +to complete{/i18n}: {$sIncomplete}
    {/if} {/if} @@ -127,9 +127,9 @@ $this->assign("oParentField", DocumentField::get($this->_tpl_vars['aRow']['paren $this->assign("oChildField", DocumentField::get($this->_tpl_vars['aRow']['child_field_id'])); {/php}
  • - {$oParentField->getName()|escape} + {$oParentField->getName()} {i18n}controls the values available in{/i18n} - {$oChildField->getName()|escape} + {$oChildField->getName()}
  • {/foreach} diff --git a/templates/ktcore/metadata/conditional/manage_ordering.smarty b/templates/ktcore/metadata/conditional/manage_ordering.smarty index 2ac47fd..2b01bc1 100644 --- a/templates/ktcore/metadata/conditional/manage_ordering.smarty +++ b/templates/ktcore/metadata/conditional/manage_ordering.smarty @@ -12,9 +12,9 @@ $this->assign("oParentField", DocumentField::get($this->_tpl_vars['aRow']['paren $this->assign("oChildField", DocumentField::get($this->_tpl_vars['aRow']['child_field_id'])); {/php}
  • - {$oParentField->getName()|escape} + {$oParentField->getName()} {i18n}controls the values available in{/i18n} - {$oChildField->getName()|escape} + {$oChildField->getName()}
  • {/foreach} diff --git a/templates/ktcore/metadata/edit.smarty b/templates/ktcore/metadata/edit.smarty index 96b8b8a..697dad2 100644 --- a/templates/ktcore/metadata/edit.smarty +++ b/templates/ktcore/metadata/edit.smarty @@ -1,4 +1,4 @@ -

    {i18n}Fieldset{/i18n}: {$oFieldset->getName()|escape}

    +

    {i18n}Fieldset{/i18n}: {$oFieldset->getName()}

    {i18n}Fieldset properties{/i18n}

    @@ -7,11 +7,11 @@ - + - +
    {i18n}Name{/i18n}
    {i18n}Namespace{/i18n}
    @@ -27,7 +27,7 @@ {foreach from=$oFieldset->getFields() item=oField}
  • +value="{$oField->getId()}">{$oField->getName()} {/foreach} diff --git a/templates/ktcore/metadata/editField.smarty b/templates/ktcore/metadata/editField.smarty index 0e05cb1..9cc24a3 100644 --- a/templates/ktcore/metadata/editField.smarty +++ b/templates/ktcore/metadata/editField.smarty @@ -1,4 +1,4 @@ -

    {i18n}Edit Field{/i18n}: {$oField->getName()|escape}

    +

    {i18n}Edit Field{/i18n}: {$oField->getName()}

    @@ -9,15 +9,15 @@ - + - + - + @@ -71,7 +71,7 @@
      {foreach from=$aEnabledMetadata item=oMetaData}
    {i18n}Name{/i18n}
    {i18n}Description{/i18n}
    {i18n}Type{/i18n}{$oField->getType()|escape}{$oField->getType()}
    {i18n}Required{/i18n}
    -{$oField->getName()|escape} +{$oField->getName()} {i18n}edit{/i18n} diff --git a/templates/ktcore/workflow/editState.smarty b/templates/ktcore/workflow/editState.smarty index 4c1e4e4..2932ddc 100644 --- a/templates/ktcore/workflow/editState.smarty +++ b/templates/ktcore/workflow/editState.smarty @@ -20,7 +20,7 @@ td.false { background-color: #ffaaaa; text-align: centre } {/literal}{/capture} {$context->oPage->requireCSSStandalone($sCSS)} -

    {i18n}State{/i18n}: {$oState->getName()|escape}

    +

    {i18n}State{/i18n}: {$oState->getName()}

    {i18n}As documents move through their lifecycle, they are placed in certain states. For example, an invoice @@ -106,7 +106,7 @@ with a specific role (e.g. Manager) or part of a specific group

  • {$oTransition->getName()|escape}
  • +{$oTransition->getId()}">{$oTransition->getName()} {/foreach} diff --git a/templates/ktcore/workflow/editTransition.smarty b/templates/ktcore/workflow/editTransition.smarty index b5e074b..951e46b 100644 --- a/templates/ktcore/workflow/editTransition.smarty +++ b/templates/ktcore/workflow/editTransition.smarty @@ -1,4 +1,4 @@ -

    {i18n}Transition{/i18n}: {$oTransition->getName()|escape}

    +

    {i18n}Transition{/i18n}: {$oTransition->getName()}

    diff --git a/templates/ktcore/workflow/editWorkflow.smarty b/templates/ktcore/workflow/editWorkflow.smarty index ef4ca98..05aa801 100644 --- a/templates/ktcore/workflow/editWorkflow.smarty +++ b/templates/ktcore/workflow/editWorkflow.smarty @@ -1,6 +1,6 @@ {$context->oPage->requireCSSResource('resources/css/workflow-admin.css')} -

    {i18n}Workflow Overview{/i18n}: {$oWorkflow->getName()|escape}

    +

    {i18n}Workflow Overview{/i18n}: {$oWorkflow->getName()}

    diff --git a/templates/ktstandard/disclaimers/manage_disclaimers_item.smarty b/templates/ktstandard/disclaimers/manage_disclaimers_item.smarty index 1cb66a6..9c0e59d 100644 --- a/templates/ktstandard/disclaimers/manage_disclaimers_item.smarty +++ b/templates/ktstandard/disclaimers/manage_disclaimers_item.smarty @@ -14,7 +14,7 @@ tinyMCE.init({ -

    {$help->getTitle()|escape}

    - +

    {$help->getTitle()}

    + diff --git a/thirdparty/Smarty/plugins/modifier.mb_truncate.php b/thirdparty/Smarty/plugins/modifier.mb_truncate.php new file mode 100644 index 0000000..6118b86 --- /dev/null +++ b/thirdparty/Smarty/plugins/modifier.mb_truncate.php @@ -0,0 +1,38 @@ + + * Name: mb_truncate
    + * Purpose: Truncate a multibyte string to a certain length if necessary, + * optionally splitting in the middle of a word, and + * appending the $etc string. + * @param string + * @param integer + * @param string + * @param boolean + * @return string + */ +function smarty_modifier_mb_truncate($string, $length = 80, $etc = '...', + $break_words = false) +{ + if ($length == 0) + return ''; + + if (mb_strlen($string) > $length) { + $length -= mb_strlen($etc); + if (!$break_words) + $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length+1)); + + return mb_substr($string, 0, $length).$etc; + } else + return $string; +} +?> \ No newline at end of file diff --git a/thirdparty/Smarty/plugins/modifier.mb_wordwrap.php b/thirdparty/Smarty/plugins/modifier.mb_wordwrap.php new file mode 100644 index 0000000..605c23d --- /dev/null +++ b/thirdparty/Smarty/plugins/modifier.mb_wordwrap.php @@ -0,0 +1,33 @@ + + * Name: mb_wordwrap
    + * Purpose: wrap a multibyte string of text at a given length + * @param string + * @param integer + * @param string + * @param boolean + * @return string + */ +function smarty_modifier_mb_wordwrap($string,$length=80,$break="\n",$cut=false) +{ + + $newString = ""; + $index = 0; + while(mb_strlen($newString) < mb_strlen($string)){ + $newString .= mb_strcut($string, $index, $length, "UTF8") . $break; + $index += $length; + } + return $newString; + +} +?> \ No newline at end of file