Kayako logo
Will Implement (V3) Feature requests in this forum will be implemented in Version 3 of the product line (the current version).

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  (#1) Old
Sheep Offline
Member
 
Sheep's Avatar
 
Posts: 345
Join Date: Feb 2007
Location: Lyon, France
Unhappy Code -> strip_tags is such a pain - 03-08-2007, 11:34 AM

I was playing arround with improving striping in tickets (default configuration = remove all tags, you should add a server setting option, like the mail parser tag, where only some tags aren't stripped)
and then i found out that the php function strip_tags doesn't handle self closing tags like <br/> (and then <br /> used in the wysiwyg editor that i've inserted back to tickets)

kayako should use this function (found in php.net comments, and improved to match kayako's current code)
PHP Code:
    function strip_tags_except($text$allowed_tags="") {
        
$allowed_tags=explode(";",$allowed_tags);
        if (!
is_array($allowed_tags))
        return 
$text;
        if (!
count($allowed_tags))
        return 
$text;
        
preg_match_all('!<\s*(/)?\s*([a-zA-Z]+)[^>]*>!',
        
$text$all_tags);
        
array_shift($all_tags);
        
$slashes $all_tags[0];
        
$all_tags $all_tags[1];
        foreach (
$all_tags as $i => $tag) {
          
        if (
in_array($tag$allowed_tags))
          continue;
        
$text =
          
preg_replace('!<(\s*' $slashes[$i] . '\s*'.$tag '[^>]*)>!',
           
'',
            
$text);
        }
        return 
$text;
    } 
Then replace all strip_tags with strip_tags_except (function redefinition not allowed)


Antoine "Sheep" BERMON
-- Lurking around there --
   
Reply With Quote
  (#2) Old
Jamie Edwards Online
Operations Manager
 
Jamie Edwards's Avatar
 
Posts: 5,270
Join Date: Jan 2006
Location: United Kingdom
03-08-2007, 12:03 PM

Good find Sheep, thank you


Jamie Edwards (jamie.edwards ]at[ kayako.com)
----------------------------------------------------------------
---
  • Submit bug reports here.
  • Submit support tickets via the members area.
  • Submit sales queries either via live chat or via e-mail.
  • There is no official ETA on Version 4.
  • This is not an official support forum - submit a support ticket.
   
Reply With Quote
  (#3) Old
Sheep Offline
Member
 
Sheep's Avatar
 
Posts: 345
Join Date: Feb 2007
Location: Lyon, France
03-08-2007, 12:17 PM

oh btw: now the admin setting mailparser "allowed tags" have to be "i;u;br" and no longer "<i><u><br>"


Antoine "Sheep" BERMON
-- Lurking around there --
   
Reply With Quote
  (#4) Old
Siora Offline
Member
 
Siora's Avatar
 
Posts: 1,308
Join Date: Apr 2007
Location: Toronto Canada
03-08-2007, 12:58 PM

Okay so how do us common folks fix this for our setups?


Siora Solutions Inc.
www.sioraIT.com
   
Reply With Quote
  (#5) Old
Sheep Offline
Member
 
Sheep's Avatar
 
Posts: 345
Join Date: Feb 2007
Location: Lyon, France
03-08-2007, 01:17 PM

create a new file includes/functions_PHPenhanced.php
PHP Code:
<?php
    
function strip_tags_except($text$allowed_tags="") {
        
$allowed_tags=explode(";",$allowed_tags);
        if (!
is_array($allowed_tags))
        return 
$text;
        if (!
count($allowed_tags))
        return 
$text;
        
preg_match_all('!<\s*(/)?\s*([a-zA-Z]+)[^>]*>!',
        
$text$all_tags);
        
array_shift($all_tags);
        
$slashes $all_tags[0];
        
$all_tags $all_tags[1];
        foreach (
$all_tags as $i => $tag) {
 
        if (
in_array($tag$allowed_tags))
          continue;
        
$text =
          
preg_replace('!<(\s*' $slashes[$i] . '\s*'.$tag '[^>]*)>!',
           
'',
            
$text);
        }
        return 
$text;
    }
?>
open config/config.php
add before the closing ?>
PHP Code:
require_once ("./includes/functions_PHPenhanced.php"); 
in all esupport files rename all the strip_tags to strip_tags_except (18 occurences)
if a call doesn't have a second argument add it (in red):
Quote:
strip_tags_except($firstargument,$_SWIFT["settings"]["pr_allowabletags"]);


Antoine "Sheep" BERMON
-- Lurking around there --

Last edited by Sheep; 11-08-2007 at 01:33 PM.
   
Reply With Quote
  (#6) Old
Siora Offline
Member
 
Siora's Avatar
 
Posts: 1,308
Join Date: Apr 2007
Location: Toronto Canada
09-08-2007, 02:44 PM

Does anyone know how to go about finding the occurences of this call? I would think that there has be be a better way than opening up every file and doing a search.


Siora Solutions Inc.
www.sioraIT.com
   
Reply With Quote
  (#7) Old
bear Offline
Community Moderator
 
Posts: 688
Join Date: Jan 2005
09-08-2007, 08:55 PM

Quote:
Originally Posted by Siora View Post
Does anyone know how to go about finding the occurences of this call? I would think that there has be be a better way than opening up every file and doing a search.
Best way I know of is to use a good text editor like UltraEdit that can search in files that aren't open, recursively, right on your local hard drive. I've attached the results.
Attached Files
File Type: txt striptags.txt (3.9 KB, 20 views)
   
Reply With Quote
  (#8) Old
Jamie Edwards Online
Operations Manager
 
Jamie Edwards's Avatar
 
Posts: 5,270
Join Date: Jan 2006
Location: United Kingdom
09-08-2007, 09:03 PM

Nice on, bear - thank you for sharing.


Jamie Edwards (jamie.edwards ]at[ kayako.com)
----------------------------------------------------------------
---
  • Submit bug reports here.
  • Submit support tickets via the members area.
  • Submit sales queries either via live chat or via e-mail.
  • There is no official ETA on Version 4.
  • This is not an official support forum - submit a support ticket.
   
Reply With Quote
  (#9) Old
Siora Offline
Member
 
Siora's Avatar
 
Posts: 1,308
Join Date: Apr 2007
Location: Toronto Canada
09-08-2007, 09:08 PM

Yes Bear, much appreciated. I'm sure that will help many out who want to apply this fix.


Siora Solutions Inc.
www.sioraIT.com
   
Reply With Quote
  (#10) Old
Siora Offline
Member
 
Siora's Avatar
 
Posts: 1,308
Join Date: Apr 2007
Location: Toronto Canada
09-08-2007, 10:58 PM

After doing this mod I get the attached error. Anyone know what it is or how to fix it? After about 2 seconds the error disappears and logs in correctly but you can see it between page loads.

EDIT: I also get fatal errors when trying use the IRS from with the staff CP. Not sure if I'm liking this.
Attached Images
File Type: bmp Strip Tags Error.bmp (573.5 KB, 13 views)


Siora Solutions Inc.
www.sioraIT.com

Last edited by Siora; 09-08-2007 at 11:27 PM.
   
Reply With Quote
  (#11) Old
Sheep Offline
Member
 
Sheep's Avatar
 
Posts: 345
Join Date: Feb 2007
Location: Lyon, France
11-08-2007, 12:26 PM

Make sure that there's no spaces before <? or after ?>
in includes/functions/functions_PHPenhanced.php (and maybe functions.php?)

Greetings,
antoine


Antoine "Sheep" BERMON
-- Lurking around there --
   
Reply With Quote
  (#12) Old
Siora Offline
Member
 
Siora's Avatar
 
Posts: 1,308
Join Date: Apr 2007
Location: Toronto Canada
11-08-2007, 01:22 PM

I don't have an includes/functions folder. For me its just includes/functions_phpenhanced.php. Am I supposed to create a functions folder? Attached is my php file that I created.

The functions.php file looks scrambled, its not plain text.

I think the problem is with my config file. Here is how I put the line at the very bottom. Is this correct?

Code:
$_MODULES[MODULE_PURCHASE] = dirname(__FILE__)."/../modules/purchase/purchase.php";
$_MODULES[MODULE_SERVERS] = dirname(__FILE__)."/../modules/servers/servers.php";
$_MODULES[MODULE_REPORTS] = dirname(__FILE__)."/../modules/reports/reports.php";
require_once ("./includes/functions_PHPenhanced.php");
?>
Attached Files
File Type: php functions_PHPenhanced.php (721 Bytes, 6 views)


Siora Solutions Inc.
www.sioraIT.com

Last edited by Siora; 11-08-2007 at 01:27 PM.
   
Reply With Quote
  (#13) Old
Sheep Offline
Member
 
Sheep's Avatar
 
Posts: 345
Join Date: Feb 2007
Location: Lyon, France
11-08-2007, 01:32 PM

Ho right,

i wrote
Quote:
create a new file includes/functions/functions_PHPenhanced.php
it's in fact (as you're stating)
Quote:
create a new file includes/functions_PHPenhanced.php
Did you check the "maybe something before the ?>" bug?





Quote:
The functions.php file looks scrambled, its not plain text.
it's encrypted, so this file isn't the problem (just though about it when you stated it)

Edit: contact me via MSN if you're still having problems I'll be online this afternoon


Antoine "Sheep" BERMON
-- Lurking around there --

Last edited by Sheep; 11-08-2007 at 01:36 PM.
   
Reply With Quote
  (#14) Old
Siora Offline
Member
 
Siora's Avatar
 
Posts: 1,308
Join Date: Apr 2007
Location: Toronto Canada
11-08-2007, 01:37 PM

If you look at my attached file it doesn't appear as though anything is before the ?> like you stated. Maybe i'm not understanding.


Siora Solutions Inc.
www.sioraIT.com
   
Reply With Quote
  (#15) Old
Sheep Offline
Member
 
Sheep's Avatar
 
Posts: 345
Join Date: Feb 2007
Location: Lyon, France
11-08-2007, 01:39 PM

Remove the one at the end after ?>


Antoine "Sheep" BERMON
-- Lurking around there --
   
Reply With Quote
Reply

Tags
>, code, pain, striptags

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
ISO Code for Japanese Admin Language ganymean SupportSuite, eSupport and LiveResponse 0 02-01-2007 04:17 AM



Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vBulletin Skin developed by: vBStyles.com


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46