<div dir="ltr">Hi Alan,<br><br>Thank you very much for your contribution on to_html() function calls to improve performance.<br>After
analyzing to_html() function, we got that some of those checks what we
are checking in that are not required any more in Vtiger6.<br>
<br>at line 366<br><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><i>if($_REQUEST['module']
!= 'Settings' && $_REQUEST['file'] != 'ListView' &&
$_REQUEST['module'] != 'Portal' && $_REQUEST['module'] !=
"Reports")// && $_REQUEST['module'] != 'Emails')</i><br>
<i> $ajax_action = $_REQUEST['module'].'Ajax';</i><br></blockquote>The above check is to identify whether the current request is AJAX or not. If so, we are setting that as <i>$_REQUEST['module'].'Ajax'. </i>But, there are not AJAX file in Vtiger6 in that structure. So, we don't need this.<br>
<br></div><div>at line 371<br></div><div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><i>if($action
!= 'CustomView' && $action != 'Export' && $action !=
$ajax_action && $action != 'LeadConvertToEntities' &&
$action != 'CreatePDF' && $action != 'ConvertAsFAQ' &&
$_REQUEST['module'] != 'Dashboard' && $action != 'CreateSOPDF'
&& $action != 'SendPDFMail' &&
(!isset($_REQUEST['submode'])) )</i><br>
<i> {</i><br><i> $doconvert = true;</i><br><i> }</i></blockquote><div>In
this check, except "Export" we don't have any actions like what we are
comparing, so no need of this comparision. Earlier there is an action
called Export for Exporting record in Vtiger5.4.0, but now we are using
ExportData.php for this action. While Exporting record, at <b>modules/Vtiger/actions/ExportData.php</b>
we are sanitizing all values which will decode those values with
decode_html() on line 243. So, there is no use of encoding with
to_html() for Export as well. We can remove this also. Else, we need to
add this here and remove decode_html() where we are doing in sanitize
values.<br>
<br><br></div><div>After doing all these modification, finally my code is like this.<br><br><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><i>/**</i><br>
<i> * Function to decide whether to_html should convert values or not for a request</i><br><i> * @global type $doconvert</i><br><i> * @global type $inUTF8</i><br><i> * @global type $default_charset</i><br><i> */</i><br><i>function decide_to_html(){</i><br>
<i> global $doconvert,$inUTF8,$default_charset; </i><br><i> $action = $_REQUEST['action']; </i><br><i> </i><br><i> $inUTF8 = (strtoupper($default_charset) == 'UTF-8'); </i><br><br><i> $doconvert = true; </i><br>
<i> <br></i></blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div> // Need to remove decode_html() which we are doing while exporting records from list/Detail view on ExportData.php line 243<br>
</div></blockquote><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div><i> if($action == 'ExportData'){</i><br><i> $doconvert = false; </i><br>
<i> }</i><br><i>}</i><br></div>// Execute this function when this file got included<br><div><div><i>decide_to_html();</i><br><br><i>/** Function to convert the given string to html</i><br><i> * @param $string -- string:: Type string</i><br>
<i> * @param $ecnode -- boolean:: Type boolean</i><br><i> * @returns $string -- string:: Type string</i><br><i> */</i><br><i>function to_html($string, $encode=true) {</i><br><i> // For optimization - default_charset can be either upper / lower case.</i><br>
<i> global $doconvert,$inUTF8,$default_charset,$htmlCache;</i><br><i> </i><br><i> if(is_string($string)) {</i><br><i> // In vtiger5 ajax request are treated specially and the data is encoded</i><br><i> if ($doconvert == true) {</i><br>
<i> if(isset($htmlCache[$string])){</i><br><i> $string = $htmlCache[$string];</i><br><i> }else{</i><br><i> if($inUTF8)</i><br><i> $string = htmlentities($string, ENT_QUOTES, $default_charset);</i><br>
<i> else</i><br><i> $string =
preg_replace(array('/</', '/>/', '/"/'), array('<',
'>', '"'), $string);</i><br>
<i> </i><br><i> $htmlCache[$string] = $string;</i><br><i> }</i><br><i> }</i><br><i> }</i><br><i> return $string;</i><br><i>}</i></div></div></blockquote></div><div><br>
</div><div>Please let me know if I missed any thing in here.<br></div><div>Thank you<br></div><div><br></div></div><br><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jul 18, 2014 at 6:34 PM, Alan Bell <span dir="ltr"><<a href="mailto:alan.bell@libertus.co.uk" target="_blank">alan.bell@libertus.co.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">turns out that most of what to_html is processing is very repetitive, if it just populates an array as it goes along and then checks in that array it is a lot faster than doing htmlentities on the string every time.<br>
<br>
global $htmlcache;//store the stripped HTML as we go along, a lot of the time we are processing the same strings<br>
function to_html($string, $encode=true)<br>
{<br>
global $doconvert;<br>
global $default_charset;<br>
global $htmlcache;<br>
if($doconvert){<br>
if(isset($htmlcache[$string]))<u></u>{<br>
return $htmlcache[$string];<br>
}else{<br>
$clean= htmlentities($string, ENT_QUOTES, $default_charset);//we don't care if it is a string or not, faster not to care<br>
$htmlcache[$string]=$clean;<br>
return $clean;<br>
}<br>
}else{<br>
return $string;<br>
}<br>
<br>
<br>
}<br>
<br>
______________________________<u></u>_________________<br>
<a href="http://www.vtiger.com/" target="_blank">http://www.vtiger.com/</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Regards,<br>Siva<br>Vtiger<br>
</div>