|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
altendew Smarty Rookie
Joined: 07 Mar 2008 Posts: 19
|
Posted: Fri Mar 07, 2008 2:08 pm Post subject: Warn user of uploaded javascript/css code =) |
|
|
This is a work in progress but I have some users that don't listen to my directions to place the {literal} tags around the javascript so I made a script that will check for javascript code and warn them about it.
Let me know what you think..
Ideas? Improvements?
Code: |
$val = 'SMARTY CODE HERE';
// Setup regex patters
$m1 = array(
'function(\s+[A-z0-9]+)?(\([^\)]*\))?\s*\{([^\}]*\})?',
'(\}\s*)?(else|else\s*if)\s*(\([^\{]*\))?(\s*\/\/[^\{]*)?\s*\{([^\{\}]*\})?',
'(if|for|foreach|while)\s*(\([^\{]*\))(\s*\/\/[^\{]*)?\s*\{([^\{\}]*\})?',
'\}\s*(if|else|else\s*if)',
'\{((\s+([^\}]*\})?)|[^\}]*$)',
'(\s+|^)\}');
$m2 = array();
foreach($m1 as $v)
$m2[] = '/('.$v.')/i';
// Strip out literal tags and replace with newlines
$val = preg_replace_callback(
'/\{\s*literal\s*\}(.*)\{\s*\/literal\s*\}/sU',
create_function(
'$matches',
'$count = explode("\n",$matches[1]);$count = count($count)-1;return str_repeat(" ..\n.. ",$count);'
),
$val);
// Get each line
$lines = explode("\n",$val);
if(!count($lines))
return;
// Run through each line
$warn = array();
foreach($lines as $n=>$line)
{
if(preg_match('/'.implode('|',$m1).'/i',$line))
$warn[$n] = preg_replace($m2,'<span style="background-color:#FFD9DA">\\1</span>',$line);
$n++;
}
|
This will give you an array called warn where the index is the line number and the value is the line.. highlighted in red is where the problem is.
Remeber I am just warning the user I have a box where they can fix the code or ignore.
What do you think?
=)
please know this means u couldnt do this..
{ if 1=1 } { /if }
It would have to be
{if 1=1} {/if}
..but seriously why would u put spaces anyways lol |
|
Back to top |
|
flijten Smarty Rookie
Joined: 07 Jan 2009 Posts: 7
|
Posted: Wed Jan 07, 2009 2:59 pm Post subject: |
|
|
This is for your own hosting or something? |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|