Overview

Packages

  • Text
    • Filter

Classes

  • Horde_Text_Filter
  • Horde_Text_Filter_Base
  • Horde_Text_Filter_Bbcode
  • Horde_Text_Filter_Cleanascii
  • Horde_Text_Filter_Cleanhtml
  • Horde_Text_Filter_Dimsignature
  • Horde_Text_Filter_Emails
  • Horde_Text_Filter_Emoticons
  • Horde_Text_Filter_Environment
  • Horde_Text_Filter_Exception
  • Horde_Text_Filter_Highlightquotes
  • Horde_Text_Filter_Html2text
  • Horde_Text_Filter_JavascriptMinify
  • Horde_Text_Filter_JavascriptMinify_JsMin
  • Horde_Text_Filter_Linkurls
  • Horde_Text_Filter_Simplemarkup
  • Horde_Text_Filter_Space2html
  • Horde_Text_Filter_Tabs2spaces
  • Horde_Text_Filter_Text2html
  • Horde_Text_Filter_Translation
  • Horde_Text_Filter_Words
  • Horde_Text_Filter_Xss
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Removes some common entities and high-ascii or otherwise nonstandard
 4:  * characters common in text pasted from Microsoft Word into a browser.
 5:  *
 6:  * This function should NOT be used on non-ASCII text; it may and probably
 7:  * will butcher other character sets indescriminately.  Use it only to clean
 8:  * US-ASCII (7-bit) text which you suspect (or know) may have invalid or
 9:  * non-printing characters in it.
10:  *
11:  * Copyright 2004-2012 Horde LLC (http://www.horde.org/)
12:  *
13:  * See the enclosed file COPYING for license information (LGPL). If you
14:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
15:  *
16:  * @author   Jan Schneider <jan@horde.org>
17:  * @category Horde
18:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
19:  * @package  Text_Filter
20:  */
21: class Horde_Text_Filter_Cleanascii extends Horde_Text_Filter_Base
22: {
23:     /**
24:      * Executes any code necessary before applying the filter patterns.
25:      *
26:      * @param string $text  The text before the filtering.
27:      *
28:      * @return string  The modified text.
29:      */
30:     public function preProcess($text)
31:     {
32:         if (preg_match('/|([^#]*)#.*/', $text, $regs)) {
33:             $text = $regs[1];
34: 
35:             if (!empty($text)) {
36:                 $text = $text . "\n";
37:             }
38:         }
39: 
40:         return $text;
41:     }
42: 
43:     /**
44:      * Returns a hash with replace patterns.
45:      *
46:      * @return array  Patterns hash.
47:      */
48:     public function getPatterns()
49:     {
50:         /* Remove control characters. */
51:         $regexp = array('/[\x00-\x1f]+/' => '');
52: 
53:         /*
54:          * but it's not - that's not really a single quote. */
55:         $replace = array(
56:             chr(150) => '-',
57:             chr(167) => '*',
58:             '' => '*',
59:             '' => '...',
60:             '' => "'",
61:             '' => "'",
62:             '' => '"',
63:             '' => '"',
64:             '' => '*',
65:             '' => '-',
66:             '' => '-',
67:             '' => '*',
68:             '&#61479;' => '.',
69:             '&#61572;' => '*',
70:             '&#61594;' => '*',
71:             '&#61640;' => '-',
72:             '&#61623;' => '-',
73:             '&#61607;' => '*',
74:             '&#61553;' => '*',
75:             '&#61558;' => '*',
76:             '&#8226;' => '*',
77:             '&#9658;' => '>',
78:         );
79: 
80:         return array('regexp' => $regexp, 'replace' => $replace);
81:     }
82: 
83: }
84: 
API documentation generated by ApiGen