Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob
  • Smarty
    • Cacher
    • Compiler
    • Config
    • Debug
    • PluginsBlock
    • PluginsFilter
    • PluginsFunction
    • PluginsInternal
    • PluginsModifier
    • PluginsModifierCompiler
    • PluginsShared
    • Security
    • Template
    • TemplateResources
  • Swift
    • ByteStream
    • CharacterStream
    • Encoder
    • Events
    • KeyCache
    • Mailer
    • Mime
    • Plugins
    • Transport

Classes

  • Swift_FailoverTransport
  • Swift_LoadBalancedTransport
  • Swift_MailTransport
  • Swift_Plugins_Loggers_ArrayLogger
  • Swift_Plugins_Loggers_EchoLogger
  • Swift_SendmailTransport
  • Swift_SmtpTransport
  • Swift_Transport_AbstractSmtpTransport
  • Swift_Transport_Esmtp_Auth_CramMd5Authenticator
  • Swift_Transport_Esmtp_Auth_LoginAuthenticator
  • Swift_Transport_Esmtp_Auth_PlainAuthenticator
  • Swift_Transport_Esmtp_AuthHandler
  • Swift_Transport_EsmtpTransport
  • Swift_Transport_FailoverTransport
  • Swift_Transport_LoadBalancedTransport
  • Swift_Transport_MailTransport
  • Swift_Transport_SendmailTransport
  • Swift_Transport_SimpleMailInvoker
  • Swift_Transport_StreamBuffer

Interfaces

  • Swift_Plugins_Logger
  • Swift_Plugins_Pop_Pop3Exception
  • Swift_Transport
  • Swift_Transport_Esmtp_Authenticator
  • Swift_Transport_EsmtpHandler
  • Swift_Transport_IoBuffer
  • Swift_Transport_MailInvoker
  • Swift_Transport_SmtpAgent
  • Swift_TransportException
  • Overview
  • Package
  • Function
  • Todo
  • Download
  1: <?php
  2: 
  3: /*
  4:  * This file is part of SwiftMailer.
  5:  * (c) 2004-2009 Chris Corbyn
  6:  *
  7:  * For the full copyright and license information, please view the LICENSE
  8:  * file that was distributed with this source code.
  9:  */
 10: 
 11: /**
 12:  * Processes bytes as they pass through a buffer and replaces sequences in it.
 13:  * This stream filter deals with Byte arrays rather than simple strings.
 14:  * @package Swift
 15:  * @author Chris Corbyn
 16:  */
 17: class Swift_StreamFilters_ByteArrayReplacementFilter implements Swift_StreamFilter
 18: {
 19:     /** The needle(s) to search for */
 20:     private $_search;
 21: 
 22:     /** The replacement(s) to make */
 23:     private $_replace;
 24: 
 25:     /** The Index for searching */
 26:     private $_index;
 27: 
 28:     /** The Search Tree */
 29:     private $_tree = array();
 30: 
 31:     /**  Gives the size of the largest search */
 32:     private $_treeMaxLen = 0;
 33: 
 34:     private $_repSize;
 35: 
 36:     /**
 37:      * Create a new ByteArrayReplacementFilter with $search and $replace.
 38:      * @param array $search
 39:      * @param array $replace
 40:      */
 41:     public function __construct($search, $replace)
 42:     {
 43:         $this->_search = $search;
 44:         $this->_index = array();
 45:         $this->_tree = array();
 46:         $this->_replace = array();
 47:         $this->_repSize = array();
 48: 
 49:         $tree = null;
 50:         $i = null;
 51:         $last_size = $size = 0;
 52:         foreach ($search as $i => $search_element) {
 53:             if ($tree !== null) {
 54:                 $tree[-1] = min (count($replace) - 1, $i - 1);
 55:                 $tree[-2] = $last_size;
 56:             }
 57:             $tree = &$this->_tree;
 58:             if (is_array ($search_element)) {
 59:                 foreach ($search_element as $k => $char) {
 60:                     $this->_index[$char] = true;
 61:                     if (!isset($tree[$char])) {
 62:                         $tree[$char] = array();
 63:                     }
 64:                     $tree = &$tree[$char];
 65:                 }
 66:                 $last_size = $k+1;
 67:                 $size = max($size, $last_size);
 68:             } else {
 69:                 $last_size = 1;
 70:                 if (!isset($tree[$search_element])) {
 71:                     $tree[$search_element] = array();
 72:                 }
 73:                 $tree = &$tree[$search_element];
 74:                 $size = max($last_size, $size);
 75:                 $this->_index[$search_element] = true;
 76:             }
 77:         }
 78:         if ($i !== null) {
 79:             $tree[-1] = min (count ($replace) - 1, $i);
 80:             $tree[-2] = $last_size;
 81:             $this->_treeMaxLen = $size;
 82:         }
 83:         foreach ($replace as $rep) {
 84:             if (!is_array($rep)) {
 85:                 $rep = array ($rep);
 86:             }
 87:             $this->_replace[] = $rep;
 88:         }
 89:         for ($i = count($this->_replace) - 1; $i >= 0; --$i) {
 90:             $this->_replace[$i] = $rep = $this->filter($this->_replace[$i], $i);
 91:             $this->_repSize[$i] = count($rep);
 92:         }
 93:     }
 94: 
 95:     /**
 96:      * Returns true if based on the buffer passed more bytes should be buffered.
 97:      * @param  array   $buffer
 98:      * @return boolean
 99:      */
100:     public function shouldBuffer($buffer)
101:     {
102:         $endOfBuffer = end($buffer);
103: 
104:         return isset ($this->_index[$endOfBuffer]);
105:     }
106: 
107:     /**
108:      * Perform the actual replacements on $buffer and return the result.
109:      * @param  array $buffer
110:      * @return array
111:      */
112:     public function filter($buffer, $_minReplaces = -1)
113:     {
114:         if ($this->_treeMaxLen == 0) {
115:             return $buffer;
116:         }
117: 
118:         $newBuffer = array();
119:         $buf_size = count($buffer);
120:         for ($i = 0; $i < $buf_size; ++$i) {
121:             $search_pos = $this->_tree;
122:             $last_found = PHP_INT_MAX;
123:             // We try to find if the next byte is part of a search pattern
124:             for ($j = 0; $j <= $this->_treeMaxLen; ++$j) {
125:                 // We have a new byte for a search pattern
126:                 if (isset ($buffer [$p = $i + $j]) && isset($search_pos[$buffer[$p]])) {
127:                     $search_pos = $search_pos[$buffer[$p]];
128:                     // We have a complete pattern, save, in case we don't find a better match later
129:                     if (isset($search_pos[- 1]) && $search_pos[-1] < $last_found
130:                         && $search_pos[-1] > $_minReplaces)
131:                     {
132:                         $last_found = $search_pos[-1];
133:                         $last_size = $search_pos[-2];
134:                     }
135:                 }
136:                 // We got a complete pattern
137:                 elseif ($last_found !== PHP_INT_MAX) {
138:                     // Adding replacement datas to output buffer
139:                     $rep_size = $this->_repSize[$last_found];
140:                     for ($j = 0; $j < $rep_size; ++$j) {
141:                         $newBuffer[] = $this->_replace[$last_found][$j];
142:                     }
143:                     // We Move cursor forward
144:                     $i += $last_size - 1;
145:                     // Edge Case, last position in buffer
146:                     if ($i >= $buf_size) {
147:                         $newBuffer[] = $buffer[$i];
148:                     }
149: 
150:                     // We start the next loop
151:                     continue 2;
152:                 } else {
153:                     // this byte is not in a pattern and we haven't found another pattern
154:                     break;
155:                 }
156:             }
157:             // Normal byte, move it to output buffer
158:             $newBuffer[] = $buffer[$i];
159:         }
160: 
161:         return $newBuffer;
162:     }
163: }
164: 
CMS CONTENIDO 4.9.7 API documentation generated by ApiGen