Javascript Tooltips, Popups, Captions - BoxOver  

Go Back   Javascript Tooltips, Popups, Captions - BoxOver > BoxOver > Suggestions
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2007, 01:37 AM
gilgamesh gilgamesh is offline
Junior Member
 
Join Date: Mar 2007
Posts: 3
Default Implemented: Automatic formatting in Smarty

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;
    }

    
$assignnull;

    
$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.

Last edited by gilgamesh : 03-30-2007 at 03:39 AM.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 10:58 AM.