Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezwordtoimageoperator.php
Go to the documentation of this file.
1 <?php
16 class eZWordToImageOperator
17 {
21 public function __construct()
22 {
23 $this->Operators = array( "wordtoimage",
24 "mimetype_icon", "class_icon", "classgroup_icon", "action_icon", "icon",
25 "flag_icon", "icon_info" );
26 $this->IconInfo = array();
27 }
28
32 function operatorList()
33 {
34 return $this->Operators;
35 }
36
37 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
38 {
39 switch ( $operatorName )
40 {
41 case "wordtoimage":
42 {
43 $ini = eZINI::instance("wordtoimage.ini");
44 $iconRoot = $ini->variable( 'WordToImageSettings', 'IconRoot' );
45
46 $replaceText = $ini->variable( 'WordToImageSettings', 'ReplaceText' );
47 $replaceIcon = $ini->variable( 'WordToImageSettings', 'ReplaceIcon' );
48
49 $wwwDirPrefix = "";
50 if ( strlen( eZSys::wwwDir() ) > 0 )
51 $wwwDirPrefix = eZSys::wwwDir() . "/";
52 foreach( $replaceIcon as $icon )
53 {
54 // Issue 015718, constructing alt text from icon name
55 $aReplaceIconName = explode( '.', $icon );
56 $altText = htmlspecialchars( $aReplaceIconName[0], ENT_COMPAT, 'UTF-8' );
57 $icons[] = '<img src="' . htmlspecialchars( $wwwDirPrefix . $iconRoot .'/' . $icon, ENT_COMPAT, 'UTF-8' ) . '" alt="'.$altText.'"/>';
58 }
59
60 $operatorValue = str_replace( $replaceText, $icons, $operatorValue );
61 } break;
62
63 // icon_info( <type> ) => array() containing:
64 // - repository - Repository path
65 // - theme - Theme name
66 // - theme_path - Theme path
67 // - size_path_list - Associative array of size paths
68 // - size_info_list - Associative array of size info (width and height)
69 // - icons - Array of icon files, relative to theme and size path
70 // - default - Default icon file, relative to theme and size path
71 case 'icon_info':
72 {
73 if ( !isset( $operatorParameters[0] ) )
74 {
75 $tpl->missingParameter( $operatorName, 'type' );
76 return;
77 }
78 $type = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
79
80 // Check if we have it cached
81 if ( isset( $this->IconInfo[$type] ) )
82 {
83 $operatorValue = $this->IconInfo[$type];
84 return;
85 }
86
87 $ini = eZINI::instance( 'icon.ini' );
88 $repository = $ini->variable( 'IconSettings', 'Repository' );
89 $theme = $ini->variable( 'IconSettings', 'Theme' );
90 $groups = array( 'mimetype' => 'MimeIcons',
91 'class' => 'ClassIcons',
92 'classgroup' => 'ClassGroupIcons',
93 'action' => 'ActionIcons',
94 'icon' => 'Icons' );
95 $configGroup = $groups[$type];
96 $mapNames = array( 'mimetype' => 'MimeMap',
97 'class' => 'ClassMap',
98 'classgroup' => 'ClassGroupMap',
99 'action' => 'ActionMap',
100 'icon' => 'IconMap' );
101 $mapName = $mapNames[$type];
102
103 // Check if the specific icon type has a theme setting
104 if ( $ini->hasVariable( $configGroup, 'Theme' ) )
105 {
106 $theme = $ini->variable( $configGroup, 'Theme' );
107 }
108
109 // Load icon settings from the theme
110 $themeINI = eZINI::instance( 'icon.ini', $repository . '/' . $theme );
111
112 $sizes = $themeINI->variable( 'IconSettings', 'Sizes' );
113 if ( $ini->hasVariable( 'IconSettings', 'Sizes' ) )
114 {
115 $sizes = array_merge( $sizes,
116 $ini->variable( 'IconSettings', 'Sizes' ) );
117 }
118
119 $sizePathList = array();
120 $sizeInfoList = array();
121
122 if ( is_array( $sizes ) )
123 {
124 foreach ( $sizes as $key => $size )
125 {
126 $pathDivider = strpos( $size, ';' );
127 if ( $pathDivider !== false )
128 {
129 $sizePath = substr( $size, $pathDivider + 1 );
130 $size = substr( $size, 0, $pathDivider );
131 }
132 else
133 {
134 $sizePath = $size;
135 }
136
137 $width = false;
138 $height = false;
139 $xDivider = strpos( $size, 'x' );
140 if ( $xDivider !== false )
141 {
142 $width = (int)substr( $size, 0, $xDivider );
143 $height = (int)substr( $size, $xDivider + 1 );
144 }
145 $sizePathList[$key] = $sizePath;
146 $sizeInfoList[$key] = array( $width, $height );
147 }
148 }
149
150 $map = array();
151
152 // Load mapping from theme
153 if ( $themeINI->hasVariable( $configGroup, $mapName ) )
154 {
155 $map = array_merge( $map,
156 $themeINI->variable( $configGroup, $mapName ) );
157 }
158 // Load override mappings if they exist
159 if ( $ini->hasVariable( $configGroup, $mapName ) )
160 {
161 $map = array_merge( $map,
162 $ini->variable( $configGroup, $mapName ) );
163 }
164
165 $default = false;
166 if ( $themeINI->hasVariable( $configGroup, 'Default' ) )
167 $default = $themeINI->variable( $configGroup, 'Default' );
168 if ( $ini->hasVariable( $configGroup, 'Default' ) )
169 $default = $ini->variable( $configGroup, 'Default' );
170
171 // Build return value
172 $iconInfo = array( 'repository' => $repository,
173 'theme' => $theme,
174 'theme_path' => $repository . '/' . $theme,
175 'size_path_list' => $sizePathList,
176 'size_info_list' => $sizeInfoList,
177 'icons' => $map,
178 'default' => $default );
179
180 $this->IconInfo[$type] = $iconInfo;
181 $operatorValue = $iconInfo;
182 } break;
183
184 case 'flag_icon':
185 {
186 $ini = eZINI::instance( 'icon.ini' );
187 $repository = $ini->variable( 'FlagIcons', 'Repository' );
188 $theme = $ini->variable( 'FlagIcons', 'Theme' );
189
190 // Load icon settings from the theme
191 $themeINI = eZINI::instance( 'icon.ini', $repository . '/' . $theme );
192
193 $iconFormat = $themeINI->variable( 'FlagIcons', 'IconFormat' );
194 if ( $ini->hasVariable( 'FlagIcons', 'IconFormat' ) )
195 {
196 $iconFormat = $ini->variable( 'FlagIcons', 'IconFormat' );
197 }
198
199 $icon = $operatorValue . '.' . $iconFormat;
200 $iconPath = $repository . '/' . $theme . '/' . $icon;
201 if ( !is_readable( $iconPath ) )
202 {
203 $defaultIcon = $themeINI->variable( 'FlagIcons', 'DefaultIcon' );
204 $iconPath = $repository . '/' . $theme . '/' . $defaultIcon . '.' . $iconFormat;
205 }
206 if ( strlen( eZSys::wwwDir() ) > 0 )
207 $wwwDirPrefix = htmlspecialchars( eZSys::wwwDir(), ENT_COMPAT, 'UTF-8' ) . '/';
208 else
209 $wwwDirPrefix = '/';
210 $operatorValue = $wwwDirPrefix . $iconPath;
211 } break;
212
213 case 'mimetype_icon':
214 case 'class_icon':
215 case 'classgroup_icon':
216 case 'action_icon':
217 case 'icon':
218 {
219 // Determine whether we should return only the image URI instead of the whole HTML code.
220 if ( isset( $operatorParameters[2] ) )
221 $returnURIOnly = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
222 else
223 $returnURIOnly = false;
224
225 $ini = eZINI::instance( 'icon.ini' );
226 $repository = $ini->variable( 'IconSettings', 'Repository' );
227 $theme = $ini->variable( 'IconSettings', 'Theme' );
228 $groups = array( 'mimetype_icon' => 'MimeIcons',
229 'class_icon' => 'ClassIcons',
230 'classgroup_icon' => 'ClassGroupIcons',
231 'action_icon' => 'ActionIcons',
232 'icon' => 'Icons' );
233 $configGroup = $groups[$operatorName];
234
235 // Check if the specific icon type has a theme setting
236 if ( $ini->hasVariable( $configGroup, 'Theme' ) )
237 {
238 $theme = $ini->variable( $configGroup, 'Theme' );
239 }
240
241 // Load icon settings from the theme
242 $themeINI = eZINI::instance( 'icon.ini', $repository . '/' . $theme );
243
244 if ( isset( $operatorParameters[0] ) )
245 {
246 $sizeName = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
247 }
248 else
249 {
250 $sizeName = $ini->variable( 'IconSettings', 'Size' );
251 // Check if the specific icon type has a size setting
252 if ( $ini->hasVariable( $configGroup, 'Size' ) )
253 {
254 $theme = $ini->variable( $configGroup, 'Size' );
255 }
256 }
257
258 $sizes = $themeINI->variable( 'IconSettings', 'Sizes' );
259 if ( $ini->hasVariable( 'IconSettings', 'Sizes' ) )
260 {
261 $sizes = array_merge( $sizes,
262 $ini->variable( 'IconSettings', 'Sizes' ) );
263 }
264
265 if ( isset( $sizes[$sizeName] ) )
266 {
267 $size = $sizes[$sizeName];
268 }
269 else
270 {
271 $size = reset($sizes);
272 }
273
274 $pathDivider = strpos( $size, ';' );
275 if ( $pathDivider !== false )
276 {
277 $sizePath = substr( $size, $pathDivider + 1 );
278 $size = substr( $size, 0, $pathDivider );
279 }
280 else
281 {
282 $sizePath = $size;
283 }
284
285 $width = false;
286 $height = false;
287 $xDivider = strpos( $size, 'x' );
288 if ( $xDivider !== false )
289 {
290 $width = (int)substr( $size, 0, $xDivider );
291 $height = (int)substr( $size, $xDivider + 1 );
292 }
293
294 if ( isset( $operatorParameters[1] ) )
295 {
296 $altText = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
297 }
298 else
299 {
300 $altText = $operatorValue;
301 }
302
303 if ( $operatorName == 'mimetype_icon' )
304 {
305 $icon = $this->iconGroupMapping( $ini, $themeINI,
306 'MimeIcons', 'MimeMap',
307 strtolower( $operatorValue ) );
308 }
309 else if ( $operatorName == 'class_icon' )
310 {
311 $icon = $this->iconDirectMapping( $ini, $themeINI,
312 'ClassIcons', 'ClassMap',
313 strtolower( $operatorValue ) );
314 }
315 else if ( $operatorName == 'classgroup_icon' )
316 {
317 $icon = $this->iconDirectMapping( $ini, $themeINI,
318 'ClassGroupIcons', 'ClassGroupMap',
319 strtolower( $operatorValue ) );
320 }
321 else if ( $operatorName == 'action_icon' )
322 {
323 $icon = $this->iconDirectMapping( $ini, $themeINI,
324 'ActionIcons', 'ActionMap',
325 strtolower( $operatorValue ) );
326 }
327 else if ( $operatorName == 'icon' )
328 {
329 $icon = $this->iconDirectMapping( $ini, $themeINI,
330 'Icons', 'IconMap',
331 strtolower( $operatorValue ) );
332 }
333
334 $iconPath = '/' . $repository . '/' . $theme;
335 $iconPath .= '/' . $sizePath;
336 $iconPath .= '/' . $icon;
337
338 $wwwDirPrefix = "";
339 if ( strlen( eZSys::wwwDir() ) > 0 )
340 $wwwDirPrefix = eZSys::wwwDir();
341 $sizeText = '';
342 if ( $width !== false and $height !== false )
343 {
344 $sizeText = ' width="' . $width . '" height="' . $height . '"';
345 }
346
347 // The class will be detected by ezpngfix.js, which will force alpha blending in IE.
348 if ( ( !isset( $sizeName ) || $sizeName == 'normal' || $sizeName == 'original' ) && strstr( strtolower( $iconPath ), ".png" ) )
349 {
350 $class = 'class="transparent-png-icon" ';
351 }
352 else
353 {
354 $class = '';
355 }
356
357 if ( $returnURIOnly )
358 $operatorValue = $wwwDirPrefix . $iconPath;
359 else
360 $operatorValue = '<img ' . $class . 'src="' . htmlspecialchars( $wwwDirPrefix . $iconPath, ENT_COMPAT, 'UTF-8' ) . '"' . $sizeText . ' alt="' . htmlspecialchars( $altText, ENT_COMPAT, 'UTF-8' ) . '" title="' . htmlspecialchars( $altText ) . '" />';
361 } break;
362
363 default:
364 {
365 eZDebug::writeError( "Unknown operator: $operatorName", "ezwordtoimageoperator.php" );
366 }
367
368 }
369
370 }
371
387 function iconDirectMapping( &$ini, &$themeINI, $iniGroup, $mapName, $matchItem )
388 {
389 $map = array();
390
391 // Load mapping from theme
392 if ( $themeINI->hasVariable( $iniGroup, $mapName ) )
393 {
394 $map = array_merge( $map,
395 $themeINI->variable( $iniGroup, $mapName ) );
396 }
397 // Load override mappings if they exist
398 if ( $ini->hasVariable( $iniGroup, $mapName ) )
399 {
400 $map = array_merge( $map,
401 $ini->variable( $iniGroup, $mapName ) );
402 }
403
404 $icon = false;
405 if ( isset( $map[$matchItem] ) )
406 {
407 $icon = $map[$matchItem];
408 }
409 if ( $icon === false )
410 {
411 if ( $themeINI->hasVariable( $iniGroup, 'Default' ) )
412 $icon = $themeINI->variable( $iniGroup, 'Default' );
413 if ( $ini->hasVariable( $iniGroup, 'Default' ) )
414 $icon = $ini->variable( $iniGroup, 'Default' );
415 }
416 return $icon;
417 }
418
436 function iconGroupMapping( &$ini, &$themeINI, $iniGroup, $mapName, $matchItem )
437 {
438 $map = array();
439
440 // Load mapping from theme
441 if ( $themeINI->hasVariable( $iniGroup, $mapName ) )
442 {
443 $map = array_merge( $map,
444 $themeINI->variable( $iniGroup, $mapName ) );
445 }
446 // Load override mappings if they exist
447 if ( $ini->hasVariable( $iniGroup, $mapName ) )
448 {
449 $map = array_merge( $map,
450 $ini->variable( $iniGroup, $mapName ) );
451 }
452
453 $icon = false;
454 // See if we have a match for the whole match item
455 if ( isset( $map[$matchItem] ) )
456 {
457 $icon = $map[$matchItem];
458 }
459 else
460 {
461 // If not we have to check the group (first part)
462 $pos = strpos( $matchItem, '/' );
463 if ( $pos !== false )
464 {
465 $mimeGroup = substr( $matchItem, 0, $pos );
466 if ( isset( $map[$mimeGroup] ) )
467 {
468 $icon = $map[$mimeGroup];
469 }
470 }
471 }
472
473 // No icon? If so use default
474 if ( $icon === false )
475 {
476 if ( $themeINI->hasVariable( $iniGroup, 'Default' ) )
477 $icon = $themeINI->variable( $iniGroup, 'Default' );
478 if ( $ini->hasVariable( $iniGroup, 'Default' ) )
479 $icon = $ini->variable( $iniGroup, 'Default' );
480 }
481 return $icon;
482 }
483
485 public $Operators;
486 public $IconInfo;
487 }
488 ?>
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZSys\wwwDir
static wwwDir()
Definition: ezsys.php:582
eZWordToImageOperator
The class eZWordToImageOperator does.
Definition: ezwordtoimageoperator.php:17
eZWordToImageOperator\iconDirectMapping
iconDirectMapping(&$ini, &$themeINI, $iniGroup, $mapName, $matchItem)
Definition: ezwordtoimageoperator.php:387
eZWordToImageOperator\operatorList
operatorList()
Definition: ezwordtoimageoperator.php:32
eZWordToImageOperator\$IconInfo
$IconInfo
Definition: ezwordtoimageoperator.php:486
eZWordToImageOperator\iconGroupMapping
iconGroupMapping(&$ini, &$themeINI, $iniGroup, $mapName, $matchItem)
Definition: ezwordtoimageoperator.php:436
eZWordToImageOperator\$Operators
$Operators
Definition: ezwordtoimageoperator.php:485
eZWordToImageOperator\__construct
__construct()
Definition: ezwordtoimageoperator.php:21
eZWordToImageOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezwordtoimageoperator.php:37
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.