Apache Zeta Components Manual :: File Source for leet_filter.php

Source for file leet_filter.php

Documentation is available at leet_filter.php

  1. <?php
  2. /**
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  *
  21.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22.  * @version //autogentag//
  23.  * @filesource
  24.  * @package Translation
  25.  */
  26.  
  27. /**
  28.  * Implements the Leet translation filter.
  29.  *
  30.  * The leet filter mangles translations to old skool 1337 73x7.
  31.  *
  32.  * @package Translation
  33.  * @version //autogentag//
  34.  */
  35. class ezcTranslationLeetFilter implements ezcTranslationFilter
  36. {
  37.     /**
  38.      * @param ezcTranslationLeetFilter Instance
  39.      */
  40.     static private $instance null;
  41.  
  42.     /**
  43.      * Private constructor to prevent non-singleton use
  44.      */
  45.     private function __construct()
  46.     {
  47.     }
  48.  
  49.     /**
  50.      * Returns an instance of the class ezcTranslationFilterLeet
  51.      *
  52.      * @return ezcTranslationFilterLeet Instance of ezcTranslationFilterLeet
  53.      */
  54.     public static function getInstance()
  55.     
  56.         if is_nullself::$instance ) ) 
  57.         
  58.             self::$instance new ezcTranslationLeetFilter()
  59.         
  60.         return self::$instance
  61.     }
  62.  
  63.     /**
  64.      * This "leetify" the $text.
  65.      *
  66.      * @param string $text 
  67.      * @return string 
  68.      */
  69.     static private function leetify$text )
  70.     {
  71.         $searchMap array'/to/i''/for/i''/ate/i''/your/i''/you/i''/l/i''/e/i''/o/i''/a/i''/t/i' );
  72.         $replaceMap array'2''4''8''ur''u''1''3''0''4''7' );
  73.  
  74.         $textBlocks preg_split'/(%[^ ]+)/'$text-1PREG_SPLIT_DELIM_CAPTURE );
  75.         $newTextBlocks array();
  76.         foreach $textBlocks as $text )
  77.         {
  78.             if strlen$text && $text[0== '%' )
  79.             {
  80.                 $newTextBlocks[= (string) $text;
  81.                 continue;
  82.             }
  83.             $text preg_replace$searchMap$replaceMap$text );
  84.  
  85.             $newTextBlocks[= (string) $text;
  86.         }
  87.         $text implode''$newTextBlocks );
  88.         return $text;
  89.     }
  90.  
  91.     /**
  92.      * Filters a context
  93.      *
  94.      * Applies the "1337" filter on the given context. This filter leetifies
  95.      * text old skool. It is, of course, just an example.
  96.      *
  97.      * @param array[ezcTranslationData] $context 
  98.      * @return void 
  99.      */
  100.     public function runFilterarray $context )
  101.     {
  102.         foreach $context as $element )
  103.         {
  104.             $element->translation self::leetify$element->translation );
  105.         }
  106.     }
  107. }
  108. ?>
Documentation generated by phpDocumentor 1.4.3