For my own personal usage having to strip out special characters and new lines for BoxOver really made maintaining the boxover HTML insert code difficult. I have complicated popup boxes that often have forms and DIV tables inside them.
So I put together a simple Smarty plugin(for PHP developers using Smarty) that I use to allow for the plain HTML to be kept intact but stripped out and converted into a BoxOver friendly HTML format ready for the end user. The code isn't the prettiest, but it works.
USAGE:
(making sure there is no newline before or after the escapestrip tags within the SPAN/DIV)
HTML Code:
<span class="popup" title="cssbody=[contextbox_body] cssheader=[contextbox_header] header=[Update Comments] body=[ {escapestrip}
<form action='{#root_script#}' method=post>
<textarea name='Comments' rows=4 cols=30>{$prospect->Comments}</textarea><br>
<input type='hidden' name='ProspectId' value='{$prospect->ProspectId}'>
<input type='hidden' name='action' value='prospect_updatecomments'>
<input type='submit' value='Update'>
</form>
{/escapestrip}] singleclickstop=[on] fixedrelx=[0] fixedrely=[10]">
Stick this in a file called: block.escapestrip.php in smarty/plugins folder
PHP Code:
<?php
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty {escapestrip}{/escapestrip} block plugin
*
* Type: block function<br>
* Name: escapestrip<br>
* Purpose: strips the input of new lines and html-unfriendly code
* <br>
* @param array
* <pre>
* Params: none
* </pre>
* @author Greg Nelson <gregnelson at iypf dot org>
* @param string contents of the block
* @param Smarty clever simulation of a method
* @return string string $content re-formatted
*/
function smarty_block_escapestrip($params, $content, &$smarty)
{
if (is_null($content)) {
return;
}
$assign= null;
$pat[0] = "/^\s+/";
$pat[1] = "/\s{2,}/";
$pat[2] = "/\s+\$/";
$rep[0] = "";
$rep[1] = " ";
$rep[2] = "";
$_output = $content;
$_output = preg_replace($pat,$rep,$_output);
// protect '->'
$_output = str_replace("->", '#--#', $_output);
// remove bad characters
$_output = str_replace("<", "<", $_output);
$_output = str_replace(">", ">", $_output);
$_output = str_replace("\"", "'", $_output);
$_output = str_replace("\\'", "'", $_output);
$_output = trim($_output);
// boxover issue - square brackets are reserved
$_output = str_replace("[", "[[", $_output);
$_output = str_replace("]", "]]", $_output);
// return the ->'s
$_output = str_replace("#--#", '->', $_output);
return $assign ? $smarty->assign($assign, $_output) : $_output;
}
?>
Now, all I need to find is a way to template the HTML code used in BoxOver so that my pages aren't soo huge.