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
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 final class t3lib_iconWorks {
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 public static function getIconImage($table, $row = array(), $backPath, $params = '', $shaded = FALSE) {
00101 $str = '<img'.t3lib_iconWorks::skinImg($backPath, t3lib_iconWorks::getIcon($table, $row, $shaded), 'width="18" height="16"').(trim($params)?' '.trim($params):'');
00102 if (!stristr($str, 'alt="')) {
00103 $str.=' alt=""';
00104 }
00105 $str.=' />';
00106 return $str;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 public static function getIcon($table, $row = array(), $shaded = FALSE) {
00121 global $TCA, $PAGES_TYPES, $ICON_TYPES;
00122
00123 // Flags:
00124 $doNotGenerateIcon = $GLOBALS['TYPO3_CONF_VARS']['GFX']['noIconProc']; // If set, the icon will NOT be generated with GDlib. Rather the icon will be looked for as [iconfilename]_X.[extension]
00125 $doNotRenderUserGroupNumber = TRUE; // If set, then the usergroup number will NOT be printed unto the icon. NOTICE. the icon is generated only if a default icon for groups is not found... So effectively this is ineffective...
00126
00127 // Shadow:
00128 if ($TCA[$table]['ctrl']['versioningWS']) {
00129 switch((int)$row['t3ver_state']) {
00130 case 1:
00131 return 'gfx/i/shadow_hide.png';
00132 break;
00133 case 2:
00134 return 'gfx/i/shadow_delete.png';
00135 break;
00136 case 3:
00137 return 'gfx/i/shadow_moveto_plh.png';
00138 break;
00139 case 4:
00140 return 'gfx/i/shadow_moveto_pointer.png';
00141 break;
00142 }
00143 }
00144
00145 // First, find the icon file name. This can depend on configuration in TCA, field values and more:
00146 if ($table=='pages') {
00147 // @TODO: RFC #7370: doktype 2&5 are deprecated since TYPO3 4.2-beta1
00148 if ($row['nav_hide'] && ($row['doktype']==1||$row['doktype']==2)) $row['doktype'] = 5; // Workaround to change the icon if "Hide in menu" was set
00149
00150 if (!$iconfile = $PAGES_TYPES[$row['doktype']]['icon']) {
00151 $iconfile = $PAGES_TYPES['default']['icon'];
00152 }
00153 if ($row['module'] && $ICON_TYPES[$row['module']]['icon']) {
00154 $iconfile = $ICON_TYPES[$row['module']]['icon'];
00155 }
00156 } else {
00157 if (!$iconfile = $TCA[$table]['ctrl']['typeicons'][$row[$TCA[$table]['ctrl']['typeicon_column']]]) {
00158 $iconfile = (($TCA[$table]['ctrl']['iconfile']) ? $TCA[$table]['ctrl']['iconfile'] : $table.'.gif');
00159 }
00160 }
00161
00162 // Setting path of iconfile if not already set. Default is "gfx/i/"
00163 if (!strstr($iconfile, '/')) {
00164 $iconfile = 'gfx/i/'.$iconfile;
00165 }
00166
00167 // Setting the absolute path where the icon should be found as a file:
00168 if (substr($iconfile, 0, 3)=='../') {
00169 $absfile = PATH_site.substr($iconfile, 3);
00170 } else {
00171 $absfile = PATH_typo3.$iconfile;
00172 }
00173
00174 // Initializing variables, all booleans except otherwise stated:
00175 $hidden = FALSE;
00176 $timing = FALSE;
00177 $futuretiming = FALSE;
00178 $user = FALSE; // In fact an integer value...
00179 $deleted = FALSE;
00180 $protectSection = FALSE; // Set, if a page-record (only pages!) has the extend-to-subpages flag set.
00181 $noIconFound = $row['_NO_ICON_FOUND'] ? TRUE : FALSE;
00182 // + $shaded which is also boolean!
00183
00184 // Icon state based on "enableFields":
00185 if (is_array($TCA[$table]['ctrl']['enablecolumns'])) {
00186 $enCols = $TCA[$table]['ctrl']['enablecolumns'];
00187 // If "hidden" is enabled:
00188 if ($enCols['disabled']) { if ($row[$enCols['disabled']]) { $hidden = TRUE; }}
00189 // If a "starttime" is set and higher than current time:
00190 if ($enCols['starttime']) { if (time() < intval($row[$enCols['starttime']])) { $timing = TRUE; }}
00191 // If an "endtime" is set:
00192 if ($enCols['endtime']) {
00193 if (intval($row[$enCols['endtime']]) > 0) {
00194 if (intval($row[$enCols['endtime']]) < time()) {
00195 $timing = TRUE; // End-timing applies at this point.
00196 } else {
00197 $futuretiming = TRUE; // End-timing WILL apply in the future for this element.
00198 }
00199 }
00200 }
00201 // If a user-group field is set:
00202 if ($enCols['fe_group']) {
00203 $user = $row[$enCols['fe_group']];
00204 if ($user && $doNotRenderUserGroupNumber) $user = 100; // Limit for user number rendering!
00205 }
00206 }
00207
00208 // If "deleted" flag is set (only when listing records which are also deleted!)
00209 if ($col = $row[$TCA[$table]['ctrl']['delete']]) {
00210 $deleted = TRUE;
00211 }
00212 // Detecting extendToSubpages (for pages only)
00213 if ($table=='pages' && $row['extendToSubpages'] && ($hidden || $timing || $futuretiming || $user)) {
00214 $protectSection = TRUE;
00215 }
00216
00217 // If ANY of the booleans are set it means we have to alter the icon:
00218 if ($hidden || $timing || $futuretiming || $user || $deleted || $shaded || $noIconFound) {
00219 $flags = '';
00220 $string = '';
00221 if ($deleted) {
00222 $string = 'deleted';
00223 $flags = 'd';
00224 } elseif ($noIconFound) { // This is ONLY for creating icons with "?" on easily...
00225 $string = 'no_icon_found';
00226 $flags = 'x';
00227 } else {
00228 if ($hidden) $string.='hidden';
00229 if ($timing) $string.='timing';
00230 if (!$string && $futuretiming) {
00231 $string = 'futuretiming';
00232 }
00233
00234 $flags.=
00235 ($hidden ? 'h' : '').
00236 ($timing ? 't' : '').
00237 ($futuretiming ? 'f' : '').
00238 ($user ? 'u' : '').
00239 ($protectSection ? 'p' : '').
00240 ($shaded ? 's' : '');
00241 }
00242
00243 // Create tagged icon file name:
00244 $iconFileName_stateTagged = ereg_replace('.([[:alnum:]]+)$', '__'.$flags.'.\1', basename($iconfile));
00245
00246 // Check if tagged icon file name exists (a tagget icon means the icon base name with the flags added between body and extension of the filename, prefixed with underscore)
00247 if (@is_file(dirname($absfile).'/'.$iconFileName_stateTagged)) { // Look for [iconname]_xxxx.[ext]
00248 return dirname($iconfile).'/'.$iconFileName_stateTagged;
00249 } elseif ($doNotGenerateIcon) { // If no icon generation can be done, try to look for the _X icon:
00250 $iconFileName_X = ereg_replace('.([[:alnum:]]+)$', '__x.\1', basename($iconfile));
00251 if (@is_file(dirname($absfile).'/'.$iconFileName_X)) {
00252 return dirname($iconfile).'/'.$iconFileName_X;
00253 } else {
00254 return 'gfx/i/no_icon_found.gif';
00255 }
00256 } else { // Otherwise, create the icon:
00257 $theRes = t3lib_iconWorks::makeIcon($GLOBALS['BACK_PATH'].$iconfile, $string, $user, $protectSection, $absfile, $iconFileName_stateTagged);
00258 return $theRes;
00259 }
00260 } else {
00261 return $iconfile;
00262 }
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 public static function skinImg($backPath, $src, $wHattribs = '', $outputMode = 0) {
00278
00279 // Setting source key. If the icon is refered to inside an extension, we homogenize the prefix to "ext/":
00280 $srcKey = ereg_replace('^(\.\.\/typo3conf\/ext|sysext|ext)\/', 'ext/', $src);
00281 #if ($src!=$srcKey)debug(array($src, $srcKey));
00282
00283 // LOOKING for alternative icons:
00284 if ($GLOBALS['TBE_STYLES']['skinImg'][$srcKey]) { // Slower or faster with is_array()? Could be used.
00285 list($src, $wHattribs) = $GLOBALS['TBE_STYLES']['skinImg'][$srcKey];
00286 } elseif ($GLOBALS['TBE_STYLES']['skinImgAutoCfg']) { // Otherwise, test if auto-detection is enabled:
00287
00288 // Search for alternative icon automatically:
00289 $fExt = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['forceFileExtension'];
00290 $scaleFactor = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] : 1; // Scaling factor
00291 $lookUpName = $fExt ? ereg_replace('\.[[:alnum:]]+$', '', $srcKey).'.'.$fExt : $srcKey; // Set filename to look for
00292
00293 if ($fExt && !@is_file($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'] . $lookUpName)) {
00294 // fallback to original filename if icon with forced extension doesn't exists
00295 $lookUpName = $srcKey;
00296 }
00297 // If file is found:
00298 if (@is_file($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'].$lookUpName)) { // If there is a file...
00299 $iInfo = @getimagesize($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'].$lookUpName); // Get width/height:
00300
00301 // Set $src and $wHattribs:
00302 $src = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'].$lookUpName;
00303 $wHattribs = 'width="'.round($iInfo[0]*$scaleFactor).'" height="'.round($iInfo[1]*$scaleFactor).'"';
00304 }
00305
00306
00307 $GLOBALS['TBE_STYLES']['skinImg'][$srcKey] = array($src, $wHattribs);
00308 }
00309
00310
00311 # if (ereg('^width="([0-9]+)" height="([0-9]+)"$', $wHattribs, $reg)) $wHattribs='width="'.($reg[1]*2).'" height="'.($reg[2]*2).'"';
00312
00313
00314
00315 $matches = array();
00316 $srcBasename = basename($src);
00317 if (preg_match('/(.*)_i(\....)$/', $srcBasename, $matches)) {
00318 $temp_path = dirname(PATH_thisScript).'/';
00319 if(!@is_file($temp_path.$backPath.$src)) {
00320 $srcOrg = preg_replace('/_i'.preg_quote($matches[2]).'$/', $matches[2], $src);
00321 $src = t3lib_iconWorks::makeIcon($backPath.$srcOrg, 'disabled', 0, false, $temp_path.$backPath.$srcOrg, $srcBasename);
00322 }
00323 }
00324
00325
00326
00327 $output = '';
00328 switch($outputMode) {
00329 case 0:
00330 $output = ' src="'.$backPath.$src.'" '.$wHattribs;
00331 break;
00332 case 1:
00333 $output = $backPath.$src;
00334 break;
00335 case 2:
00336 $output = $wHattribs;
00337 break;
00338 }
00339 return $output;
00340 }
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 public static function makeIcon($iconfile, $mode, $user, $protectSection, $absFile, $iconFileName_stateTagged) {
00371 $iconFileName = 'icon_'.t3lib_div::shortMD5($iconfile.'|'.$mode.'|-'.$user.'|'.$protectSection).'_'.$iconFileName_stateTagged.'.'.($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']?'png':'gif');
00372 $mainpath = '../typo3temp/'.$iconFileName;
00373 $path = PATH_site.'typo3temp/'.$iconFileName;
00374
00375
00376 if (file_exists(PATH_typo3.'icons/'.$iconFileName)) {
00377 return 'icons/'.$iconFileName;
00378 } elseif (file_exists($path)) {
00379 return $mainpath;
00380 } else {
00381 if (file_exists($absFile)) {
00382 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
00383
00384
00385 $im = t3lib_iconworks::imagecreatefrom($absFile);
00386 if ($im<0) return $iconfile;
00387
00388
00389 if (($mode=='disabled') OR ($mode!='futuretiming' && $mode!='no_icon_found' && !(!$mode && $user))) {
00390 for ($c = 0; $c<ImageColorsTotal($im); $c++) {
00391 $cols = ImageColorsForIndex($im, $c);
00392 $newcol = round(($cols['red']+$cols['green']+$cols['blue'])/3);
00393 $lighten = ($mode=='disabled') ? 2.5 : 2;
00394 $newcol = round(255-((255-$newcol)/$lighten));
00395 ImageColorSet($im, $c, $newcol, $newcol, $newcol);
00396 }
00397 }
00398
00399 if ($user) {
00400 if ($user < 100) {
00401 $black = ImageColorAllocate($im, 0, 0, 0);
00402 imagefilledrectangle($im, 0, 0, (($user>10)?9:5), 8, $black);
00403
00404 $white = ImageColorAllocate($im, 255, 255, 255);
00405 imagestring($im, 1, 1, 1, $user, $white);
00406 }
00407
00408 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_group.gif');
00409 if ($ol_im<0) return $iconfile;
00410
00411 t3lib_iconworks::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
00412 }
00413
00414 if ($mode) {
00415 unset($ol_im);
00416 switch($mode) {
00417 case 'deleted':
00418 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_deleted.gif');
00419 break;
00420 case 'futuretiming':
00421 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_timing.gif');
00422 break;
00423 case 'timing':
00424 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_timing.gif');
00425 break;
00426 case 'hiddentiming':
00427 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_hidden_timing.gif');
00428 break;
00429 case 'no_icon_found':
00430 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_no_icon_found.gif');
00431 break;
00432 case 'disabled':
00433
00434 $ol_im = 0;
00435 break;
00436 case 'hidden':
00437 default:
00438 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_hidden.gif');
00439 break;
00440 }
00441 if ($ol_im<0) return $iconfile;
00442 if ($ol_im) {
00443 t3lib_iconworks::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
00444 }
00445 }
00446
00447 if ($protectSection) {
00448 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_sub5.gif');
00449 if ($ol_im<0) return $iconfile;
00450 t3lib_iconworks::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
00451 }
00452
00453
00454 @t3lib_iconWorks::imagemake($im, $path);
00455 t3lib_div::gif_compress($path, 'IM');
00456 ImageDestroy($im);
00457 return $mainpath;
00458 } else {
00459 return $iconfile;
00460 }
00461 } else {
00462 return $GLOBALS['BACK_PATH'].'gfx/fileicons/default.gif';
00463 }
00464 }
00465 }
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 public static function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
00493 imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
00494 }
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504 public static function imagecreatefrom($file) {
00505 $file = t3lib_div::read_png_gif($file, $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']);
00506 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
00507 return $file ? imagecreatefrompng($file) : -1;
00508 } else {
00509 return $file ? imagecreatefromgif($file) : -1;
00510 }
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521 public static function imagemake($im, $path) {
00522 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
00523 @ImagePng($im, $path);
00524 } else {
00525 @ImageGif($im, $path);
00526 }
00527 }
00528 }
00529 ?>