Namespaces

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • BaseTemplate
  • CachingHelper
  • CurlyBracketsMacros
  • LatteFilter
  • LatteMacros
  • SnippetHelper
  • Template
  • TemplateCacheStorage
  • TemplateFilters
  • TemplateHelpers

Interfaces

  • IFileTemplate
  • ITemplate
  • Overview
  • Namespace
  • Class
  • Tree
  • Other releases
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (https://nette.org)
  5:  *
  6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
  7:  *
  8:  * For the full copyright and license information, please view
  9:  * the file license.txt that was distributed with this source code.
 10:  */
 11: 
 12: namespace Nette\Templates;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * Standard template compile-time filters shipped with Nette Framework (https://nette.org)
 20:  *
 21:  * @author     David Grudl
 22:  */
 23: final class TemplateFilters
 24: {
 25: 
 26:     /**
 27:      * Static class - cannot be instantiated.
 28:      */
 29:     final public function __construct()
 30:     {
 31:         throw new \LogicException("Cannot instantiate static class " . get_class($this));
 32:     }
 33: 
 34: 
 35: 
 36:     /********************* Filter removePhp ****************d*g**/
 37: 
 38: 
 39: 
 40:     /**
 41:      * Filters out PHP code.
 42:      * @param  string
 43:      * @return string
 44:      */
 45:     public static function removePhp($s)
 46:     {
 47:         return preg_replace('#\x01@php:p\d+@\x02#', '<?php ?>', $s); // Template hides PHP code in these snippets
 48:     }
 49: 
 50: 
 51: 
 52:     /********************* Filter relativeLinks ****************d*g**/
 53: 
 54: 
 55: 
 56:     /**
 57:      * Filter relativeLinks: prepends root to relative links.
 58:      * @param  string
 59:      * @return string
 60:      */
 61:     public static function relativeLinks($s)
 62:     {
 63:         return preg_replace(
 64:             '#(src|href|action)\s*=\s*(["\'])(?![a-z]+:|[\x01/\\#])#', // \x01 is PHP snippet
 65:             '$1=$2<?php echo \\$baseUri ?>',
 66:             $s
 67:         );
 68:     }
 69: 
 70: 
 71: 
 72:     /********************* Filter netteLinks ****************d*g**/
 73: 
 74: 
 75: 
 76:     /**
 77:      * Filter netteLinks: translates links "nette:...".
 78:      *   nette:destination?arg
 79:      * @param  string
 80:      * @return string
 81:      */
 82:     public static function netteLinks($s)
 83:     {
 84:         return preg_replace_callback(
 85:             '#(src|href|action)\s*=\s*(["\'])(nette:.*?)([\#"\'])#',
 86:             array(__CLASS__, 'netteLinksCb'),
 87:             $s
 88:         );
 89:     }
 90: 
 91: 
 92: 
 93:     /**
 94:      * Callback for self::netteLinks.
 95:      * Parses a "nette" URI (scheme is 'nette') and converts to real URI
 96:      */
 97:     private static function netteLinksCb($m)
 98:     {
 99:         list(, $attr, $quote, $uri, $fragment) = $m;
100: 
101:         $parts = parse_url($uri);
102:         if (isset($parts['scheme']) && $parts['scheme'] === 'nette') {
103:             return $attr . '=' . $quote . '<?php echo $template->escape($control->'
104:                 . "link('"
105:                 . (isset($parts['path']) ? $parts['path'] : 'this!')
106:                 . (isset($parts['query']) ? '?' . $parts['query'] : '')
107:                 . '\'))?>'
108:                 . $fragment;
109:         } else {
110:             return $m[0];
111:         }
112:     }
113: 
114: 
115: 
116:     /********************* Filter texyElements ****************d*g**/
117: 
118: 
119: 
120:     /** @var Texy */
121:     public static $texy;
122: 
123: 
124: 
125:     /**
126:      * Process <texy>...</texy> elements.
127:      * @param  string
128:      * @return string
129:      */
130:     public static function texyElements($s)
131:     {
132:         return preg_replace_callback(
133:             '#<texy([^>]*)>(.*?)</texy>#s',
134:             array(__CLASS__, 'texyCb'),
135:             $s
136:         );
137:     }
138: 
139: 
140: 
141:     /**
142:      * Callback for self::texyBlocks.
143:      */
144:     private static function texyCb($m)
145:     {
146:         list(, $mAttrs, $mContent) = $m;
147: 
148:         // parse attributes
149:         $attrs = array();
150:         if ($mAttrs) {
151:             preg_match_all(
152:                 '#([a-z0-9:-]+)\s*(?:=\s*(\'[^\']*\'|"[^"]*"|[^\'"\s]+))?()#isu',
153:                 $mAttrs,
154:                 $arr,
155:                 PREG_SET_ORDER
156:             );
157: 
158:             foreach ($arr as $m) {
159:                 $key = strtolower($m[1]);
160:                 $val = $m[2];
161:                 if ($val == NULL) $attrs[$key] = TRUE;
162:                 elseif ($val{0} === '\'' || $val{0} === '"') $attrs[$key] = html_entity_decode(substr($val, 1, -1), ENT_QUOTES, 'UTF-8');
163:                 else $attrs[$key] = html_entity_decode($val, ENT_QUOTES, 'UTF-8');
164:             }
165:         }
166: 
167:         return self::$texy->process($m[2]);
168:     }
169: 
170: }
171: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0