00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 class eZWordToImageOperator
00040 {
00041
00042
00043
00044 function eZWordToImageOperator()
00045 {
00046 $this->Operators = array( "wordtoimage",
00047 "mimetype_icon", "class_icon", "classgroup_icon", "action_icon", "icon",
00048 "flag_icon", "icon_info" );
00049 $this->IconInfo = array();
00050 }
00051
00052
00053
00054
00055 function &operatorList()
00056 {
00057 return $this->Operators;
00058 }
00059
00060 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
00061 {
00062 switch ( $operatorName )
00063 {
00064 case "wordtoimage":
00065 {
00066 include_once( "lib/ezutils/classes/ezini.php" );
00067 $ini =& eZINI::instance("wordtoimage.ini");
00068 $iconRoot = $ini->variable( 'WordToImageSettings', 'IconRoot' );
00069
00070 $replaceText = $ini->variable( 'WordToImageSettings', 'ReplaceText' );
00071 $replaceIcon = $ini->variable( 'WordToImageSettings', 'ReplaceIcon' );
00072
00073 $wwwDirPrefix = "";
00074 if ( strlen( eZSys::wwwDir() ) > 0 )
00075 $wwwDirPrefix = eZSys::wwwDir() . "/";
00076 foreach( $replaceIcon as $icon )
00077 {
00078 $icons[] = '<img src="' . $wwwDirPrefix . $iconRoot .'/' . $icon . '"/>';
00079 }
00080
00081 $operatorValue = str_replace( $replaceText, $icons, $operatorValue );
00082 } break;
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 case 'icon_info':
00093 {
00094 if ( !isset( $operatorParameters[0] ) )
00095 {
00096 $tpl->missingParameter( $operatorName, 'type' );
00097 return;
00098 }
00099 $type = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00100
00101
00102 if ( isset( $this->IconInfo[$type] ) )
00103 {
00104 $operatorValue = $this->IconInfo[$type];
00105 return;
00106 }
00107
00108 $ini =& eZINI::instance( 'icon.ini' );
00109 $repository = $ini->variable( 'IconSettings', 'Repository' );
00110 $theme = $ini->variable( 'IconSettings', 'Theme' );
00111 $groups = array( 'mimetype' => 'MimeIcons',
00112 'class' => 'ClassIcons',
00113 'classgroup' => 'ClassGroupIcons',
00114 'action' => 'ActionIcons',
00115 'icon' => 'Icons' );
00116 $configGroup = $groups[$type];
00117 $mapNames = array( 'mimetype' => 'MimeMap',
00118 'class' => 'ClassMap',
00119 'classgroup' => 'ClassGroupMap',
00120 'action' => 'ActionMap',
00121 'icon' => 'IconMap' );
00122 $mapName = $mapNames[$type];
00123
00124
00125 if ( $ini->hasVariable( $configGroup, 'Theme' ) )
00126 {
00127 $theme = $ini->variable( $configGroup, 'Theme' );
00128 }
00129
00130
00131 $themeINI =& eZINI::instance( 'icon.ini', $repository . '/' . $theme );
00132
00133 $sizes = $themeINI->variable( 'IconSettings', 'Sizes' );
00134 if ( $ini->hasVariable( 'IconSettings', 'Sizes' ) )
00135 {
00136 $sizes = array_merge( $sizes,
00137 $ini->variable( 'IconSettings', 'Sizes' ) );
00138 }
00139
00140 $sizePathList = array();
00141 $sizeInfoList = array();
00142
00143 if ( is_array( $sizes ) )
00144 {
00145 foreach ( $sizes as $key => $size )
00146 {
00147 $pathDivider = strpos( $size, ';' );
00148 if ( $pathDivider !== false )
00149 {
00150 $sizePath = substr( $size, $pathDivider + 1 );
00151 $size = substr( $size, 0, $pathDivider );
00152 }
00153 else
00154 {
00155 $sizePath = $size;
00156 }
00157
00158 $width = false;
00159 $height = false;
00160 $xDivider = strpos( $size, 'x' );
00161 if ( $xDivider !== false )
00162 {
00163 $width = (int)substr( $size, 0, $xDivider );
00164 $height = (int)substr( $size, $xDivider + 1 );
00165 }
00166 $sizePathList[$key] = $sizePath;
00167 $sizeInfoList[$key] = array( $width, $height );
00168 }
00169 }
00170
00171 $map = array();
00172
00173
00174 if ( $themeINI->hasVariable( $configGroup, $mapName ) )
00175 {
00176 $map = array_merge( $map,
00177 $themeINI->variable( $configGroup, $mapName ) );
00178 }
00179
00180 if ( $ini->hasVariable( $configGroup, $mapName ) )
00181 {
00182 $map = array_merge( $map,
00183 $ini->variable( $configGroup, $mapName ) );
00184 }
00185
00186 $default = false;
00187 if ( $themeINI->hasVariable( $configGroup, 'Default' ) )
00188 $default = $themeINI->variable( $configGroup, 'Default' );
00189 if ( $ini->hasVariable( $configGroup, 'Default' ) )
00190 $default = $ini->variable( $configGroup, 'Default' );
00191
00192
00193 $iconInfo = array( 'repository' => $repository,
00194 'theme' => $theme,
00195 'theme_path' => $repository . '/' . $theme,
00196 'size_path_list' => $sizePathList,
00197 'size_info_list' => $sizeInfoList,
00198 'icons' => $map,
00199 'default' => $default );
00200
00201 $this->IconInfo[$type] = $iconInfo;
00202 $operatorValue = $iconInfo;
00203 } break;
00204
00205 case 'flag_icon':
00206 {
00207 $ini =& eZINI::instance( 'icon.ini' );
00208 $repository = $ini->variable( 'IconSettings', 'Repository' );
00209 $theme = $ini->variable( 'FlagIcons', 'Theme' );
00210
00211
00212 $themeINI =& eZINI::instance( 'icon.ini', $repository . '/' . $theme );
00213
00214 $iconFormat = $themeINI->variable( 'FlagIcons', 'IconFormat' );
00215 if ( $ini->hasVariable( 'FlagIcons', 'IconFormat' ) )
00216 {
00217 $iconFormat = $ini->variable( 'FlagIcons', 'IconFormat' );
00218 }
00219
00220 $icon = $operatorValue . '.' . $iconFormat;
00221 $iconPath = $repository . '/' . $theme . '/' . $icon;
00222 if ( !is_readable( $iconPath ) )
00223 {
00224 $defaultIcon = $themeINI->variable( 'FlagIcons', 'DefaultIcon' );
00225 $iconPath = $repository . '/' . $theme . '/' . $defaultIcon . '.' . $iconFormat;
00226 }
00227 if ( strlen( eZSys::wwwDir() ) > 0 )
00228 $wwwDirPrefix = eZSys::wwwDir() . '/';
00229 else
00230 $wwwDirPrefix = '/';
00231 $operatorValue = $wwwDirPrefix . $iconPath;
00232 } break;
00233
00234 case 'mimetype_icon':
00235 case 'class_icon':
00236 case 'classgroup_icon':
00237 case 'action_icon':
00238 case 'icon':
00239 {
00240
00241 if ( isset( $operatorParameters[2] ) )
00242 $returnURIOnly = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
00243 else
00244 $returnURIOnly = false;
00245
00246 $ini =& eZINI::instance( 'icon.ini' );
00247 $repository = $ini->variable( 'IconSettings', 'Repository' );
00248 $theme = $ini->variable( 'IconSettings', 'Theme' );
00249 $groups = array( 'mimetype_icon' => 'MimeIcons',
00250 'class_icon' => 'ClassIcons',
00251 'classgroup_icon' => 'ClassGroupIcons',
00252 'action_icon' => 'ActionIcons',
00253 'icon' => 'Icons' );
00254 $configGroup = $groups[$operatorName];
00255
00256
00257 if ( $ini->hasVariable( $configGroup, 'Theme' ) )
00258 {
00259 $theme = $ini->variable( $configGroup, 'Theme' );
00260 }
00261
00262
00263 $themeINI =& eZINI::instance( 'icon.ini', $repository . '/' . $theme );
00264
00265 if ( isset( $operatorParameters[0] ) )
00266 {
00267 $sizeName = $tpl->elementValue( $operatorParameters[0], $rootNamespace, $currentNamespace );
00268 }
00269 else
00270 {
00271 $sizeName = $ini->variable( 'IconSettings', 'Size' );
00272
00273 if ( $ini->hasVariable( $configGroup, 'Size' ) )
00274 {
00275 $theme = $ini->variable( $configGroup, 'Size' );
00276 }
00277 }
00278
00279 $sizes = $themeINI->variable( 'IconSettings', 'Sizes' );
00280 if ( $ini->hasVariable( 'IconSettings', 'Sizes' ) )
00281 {
00282 $sizes = array_merge( $sizes,
00283 $ini->variable( 'IconSettings', 'Sizes' ) );
00284 }
00285
00286 if ( isset( $sizes[$sizeName] ) )
00287 {
00288 $size = $sizes[$sizeName];
00289 }
00290 else
00291 {
00292 $size = $sizes[0];
00293 }
00294
00295 $pathDivider = strpos( $size, ';' );
00296 if ( $pathDivider !== false )
00297 {
00298 $sizePath = substr( $size, $pathDivider + 1 );
00299 $size = substr( $size, 0, $pathDivider );
00300 }
00301 else
00302 {
00303 $sizePath = $size;
00304 }
00305
00306 $width = false;
00307 $height = false;
00308 $xDivider = strpos( $size, 'x' );
00309 if ( $xDivider !== false )
00310 {
00311 $width = (int)substr( $size, 0, $xDivider );
00312 $height = (int)substr( $size, $xDivider + 1 );
00313 }
00314
00315 if ( isset( $operatorParameters[1] ) )
00316 {
00317 $altText = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
00318 }
00319 else
00320 {
00321 $altText = $operatorValue;
00322 }
00323
00324 if ( $operatorName == 'mimetype_icon' )
00325 {
00326 $icon = $this->iconGroupMapping( $ini, $themeINI,
00327 'MimeIcons', 'MimeMap',
00328 strtolower( $operatorValue ) );
00329 }
00330 else if ( $operatorName == 'class_icon' )
00331 {
00332 $icon = $this->iconDirectMapping( $ini, $themeINI,
00333 'ClassIcons', 'ClassMap',
00334 strtolower( $operatorValue ) );
00335 }
00336 else if ( $operatorName == 'classgroup_icon' )
00337 {
00338 $icon = $this->iconDirectMapping( $ini, $themeINI,
00339 'ClassGroupIcons', 'ClassGroupMap',
00340 strtolower( $operatorValue ) );
00341 }
00342 else if ( $operatorName == 'action_icon' )
00343 {
00344 $icon = $this->iconDirectMapping( $ini, $themeINI,
00345 'ActionIcons', 'ActionMap',
00346 strtolower( $operatorValue ) );
00347 }
00348 else if ( $operatorName == 'icon' )
00349 {
00350 $icon = $this->iconDirectMapping( $ini, $themeINI,
00351 'Icons', 'IconMap',
00352 strtolower( $operatorValue ) );
00353 }
00354
00355 $iconPath = '/' . $repository . '/' . $theme;
00356 $iconPath .= '/' . $sizePath;
00357 $iconPath .= '/' . $icon;
00358
00359 $wwwDirPrefix = "";
00360 if ( strlen( eZSys::wwwDir() ) > 0 )
00361 $wwwDirPrefix = eZSys::wwwDir();
00362 $sizeText = '';
00363 if ( $width !== false and $height !== false )
00364 {
00365 $sizeText = ' width="' . $width . '" height="' . $height . '"';
00366 }
00367
00368
00369 if ( ( !isset( $sizeName ) || $sizeName == 'normal' || $sizeName == 'original' ) && strstr( strtolower( $iconPath ), ".png" ) )
00370 {
00371 $class = 'class="transparent-png-icon" ';
00372 }
00373 else
00374 {
00375 $class = '';
00376 }
00377
00378 if ( $returnURIOnly )
00379 $operatorValue = $wwwDirPrefix . $iconPath;
00380 else
00381 $operatorValue = '<img ' . $class . 'src="' . $wwwDirPrefix . $iconPath . '"' . $sizeText . ' alt="' . htmlspecialchars( $altText ) . '" title="' . htmlspecialchars( $altText ) . '" />';
00382 } break;
00383
00384 default:
00385 {
00386 eZDebug::writeError( "Unknown operator: $operatorName", "ezwordtoimageoperator.php" );
00387 }
00388
00389 }
00390
00391 }
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408 function iconDirectMapping( &$ini, &$themeINI, $iniGroup, $mapName, $matchItem )
00409 {
00410 $map = array();
00411
00412
00413 if ( $themeINI->hasVariable( $iniGroup, $mapName ) )
00414 {
00415 $map = array_merge( $map,
00416 $themeINI->variable( $iniGroup, $mapName ) );
00417 }
00418
00419 if ( $ini->hasVariable( $iniGroup, $mapName ) )
00420 {
00421 $map = array_merge( $map,
00422 $ini->variable( $iniGroup, $mapName ) );
00423 }
00424
00425 $icon = false;
00426 if ( isset( $map[$matchItem] ) )
00427 {
00428 $icon = $map[$matchItem];
00429 }
00430 if ( $icon === false )
00431 {
00432 if ( $themeINI->hasVariable( $iniGroup, 'Default' ) )
00433 $icon = $themeINI->variable( $iniGroup, 'Default' );
00434 if ( $ini->hasVariable( $iniGroup, 'Default' ) )
00435 $icon = $ini->variable( $iniGroup, 'Default' );
00436 }
00437 return $icon;
00438 }
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 function iconGroupMapping( &$ini, &$themeINI, $iniGroup, $mapName, $matchItem )
00458 {
00459 $map = array();
00460
00461
00462 if ( $themeINI->hasVariable( $iniGroup, $mapName ) )
00463 {
00464 $map = array_merge( $map,
00465 $themeINI->variable( $iniGroup, $mapName ) );
00466 }
00467
00468 if ( $ini->hasVariable( $iniGroup, $mapName ) )
00469 {
00470 $map = array_merge( $map,
00471 $ini->variable( $iniGroup, $mapName ) );
00472 }
00473
00474 $icon = false;
00475
00476 if ( isset( $map[$matchItem] ) )
00477 {
00478 $icon = $map[$matchItem];
00479 }
00480 else
00481 {
00482
00483 $pos = strpos( $matchItem, '/' );
00484 if ( $pos !== false )
00485 {
00486 $mimeGroup = substr( $matchItem, 0, $pos );
00487 if ( isset( $map[$mimeGroup] ) )
00488 {
00489 $icon = $map[$mimeGroup];
00490 }
00491 }
00492 }
00493
00494
00495 if ( $icon === false )
00496 {
00497 if ( $themeINI->hasVariable( $iniGroup, 'Default' ) )
00498 $icon = $themeINI->variable( $iniGroup, 'Default' );
00499 if ( $ini->hasVariable( $iniGroup, 'Default' ) )
00500 $icon = $ini->variable( $iniGroup, 'Default' );
00501 }
00502 return $icon;
00503 }
00504
00505
00506 var $Operators;
00507 var $IconInfo;
00508 }
00509 ?>