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
00085 class t3lib_iconWorks {
00086
00100 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="')) $str.=' alt=""';
00103 $str.=' />';
00104 return $str;
00105 }
00106
00118 function getIcon($table,$row=array(),$shaded=FALSE) {
00119 global $TCA, $PAGES_TYPES, $ICON_TYPES;
00120
00121 // Flags:
00122 $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]
00123 $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...
00124
00125 // Shadow:
00126 if ($TCA[$table]['ctrl']['versioningWS']) {
00127 switch((int)$row['t3ver_state']) {
00128 case 1:
00129 return 'gfx/i/shadow_hide.png';
00130 break;
00131 case 2:
00132 return 'gfx/i/shadow_delete.png';
00133 break;
00134 case 3:
00135 return 'gfx/i/shadow_moveto_plh.png';
00136 break;
00137 case 4:
00138 return 'gfx/i/shadow_moveto_pointer.png';
00139 break;
00140 }
00141 }
00142
00143 // First, find the icon file name. This can depend on configuration in TCA, field values and more:
00144 if ($table=='pages') {
00145 if ($row['nav_hide'] && ($row['doktype']==1||$row['doktype']==2)) $row['doktype']=5; // Workaround to change the icon if "Hide in menu" was set
00146
00147 if (!$iconfile = $PAGES_TYPES[$row['doktype']]['icon']) {
00148 $iconfile = $PAGES_TYPES['default']['icon'];
00149 }
00150 if ($row['module'] && $ICON_TYPES[$row['module']]['icon']) {
00151 $iconfile = $ICON_TYPES[$row['module']]['icon'];
00152 }
00153 } else {
00154 if (!$iconfile = $TCA[$table]['ctrl']['typeicons'][$row[$TCA[$table]['ctrl']['typeicon_column']]]) {
00155 $iconfile = (($TCA[$table]['ctrl']['iconfile']) ? $TCA[$table]['ctrl']['iconfile'] : $table.'.gif');
00156 }
00157 }
00158
00159 // Setting path of iconfile if not already set. Default is "gfx/i/"
00160 if (!strstr($iconfile,'/')) {
00161 $iconfile = 'gfx/i/'.$iconfile;
00162 }
00163
00164 // Setting the absolute path where the icon should be found as a file:
00165 if (substr($iconfile,0,3)=='../') {
00166 $absfile=PATH_site.substr($iconfile,3);
00167 } else {
00168 $absfile=PATH_typo3.$iconfile;
00169 }
00170
00171 // Initializing variables, all booleans except otherwise stated:
00172 $hidden = FALSE;
00173 $timing = FALSE;
00174 $futuretiming = FALSE;
00175 $user = FALSE; // In fact an integer value...
00176 $deleted = FALSE;
00177 $protectSection = FALSE; // Set, if a page-record (only pages!) has the extend-to-subpages flag set.
00178 $noIconFound = $row['_NO_ICON_FOUND'] ? TRUE : FALSE;
00179 // + $shaded which is also boolean!
00180
00181 // Icon state based on "enableFields":
00182 if (is_array($TCA[$table]['ctrl']['enablecolumns'])) {
00183 $enCols = $TCA[$table]['ctrl']['enablecolumns'];
00184 // If "hidden" is enabled:
00185 if ($enCols['disabled']) { if ($row[$enCols['disabled']]) { $hidden = TRUE; }}
00186 // If a "starttime" is set and higher than current time:
00187 if ($enCols['starttime']) { if (time() < intval($row[$enCols['starttime']])) { $timing = TRUE; }}
00188 // If an "endtime" is set:
00189 if ($enCols['endtime']) {
00190 if (intval($row[$enCols['endtime']]) > 0) {
00191 if (intval($row[$enCols['endtime']]) < time()) {
00192 $timing = TRUE; // End-timing applies at this point.
00193 } else {
00194 $futuretiming = TRUE; // End-timing WILL apply in the future for this element.
00195 }
00196 }
00197 }
00198 // If a user-group field is set:
00199 if ($enCols['fe_group']) {
00200 $user = $row[$enCols['fe_group']];
00201 if ($user && $doNotRenderUserGroupNumber) $user=100; // Limit for user number rendering!
00202 }
00203 }
00204
00205 // If "deleted" flag is set (only when listing records which are also deleted!)
00206 if ($col=$row[$TCA[$table]['ctrl']['delete']]) {
00207 $deleted = TRUE;
00208 }
00209 // Detecting extendToSubpages (for pages only)
00210 if ($table=='pages' && $row['extendToSubpages'] && ($hidden || $timing || $futuretiming || $user)) {
00211 $protectSection = TRUE;
00212 }
00213
00214 // If ANY of the booleans are set it means we have to alter the icon:
00215 if ($hidden || $timing || $futuretiming || $user || $deleted || $shaded || $noIconFound) {
00216 $flags='';
00217 $string='';
00218 if ($deleted) {
00219 $string='deleted';
00220 $flags='d';
00221 } elseif ($noIconFound) { // This is ONLY for creating icons with "?" on easily...
00222 $string='no_icon_found';
00223 $flags='x';
00224 } else {
00225 if ($hidden) $string.='hidden';
00226 if ($timing) $string.='timing';
00227 if (!$string && $futuretiming) {
00228 $string='futuretiming';
00229 }
00230
00231 $flags.=
00232 ($hidden ? 'h' : '').
00233 ($timing ? 't' : '').
00234 ($futuretiming ? 'f' : '').
00235 ($user ? 'u' : '').
00236 ($protectSection ? 'p' : '').
00237 ($shaded ? 's' : '');
00238 }
00239
00240 // Create tagged icon file name:
00241 $iconFileName_stateTagged = ereg_replace('.([[:alnum:]]+)$','__'.$flags.'.\1',basename($iconfile));
00242
00243 // 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)
00244 if (@is_file(dirname($absfile).'/'.$iconFileName_stateTagged)) { // Look for [iconname]_xxxx.[ext]
00245 return dirname($iconfile).'/'.$iconFileName_stateTagged;
00246 } elseif ($doNotGenerateIcon) { // If no icon generation can be done, try to look for the _X icon:
00247 $iconFileName_X = ereg_replace('.([[:alnum:]]+)$','__x.\1',basename($iconfile));
00248 if (@is_file(dirname($absfile).'/'.$iconFileName_X)) {
00249 return dirname($iconfile).'/'.$iconFileName_X;
00250 } else {
00251 return 'gfx/i/no_icon_found.gif';
00252 }
00253 } else { // Otherwise, create the icon:
00254 $theRes = t3lib_iconWorks::makeIcon($GLOBALS['BACK_PATH'].$iconfile, $string, $user, $protectSection, $absfile, $iconFileName_stateTagged);
00255 return $theRes;
00256 }
00257 } else {
00258 return $iconfile;
00259 }
00260 }
00261
00274 function skinImg($backPath,$src,$wHattribs='',$outputMode=0) {
00275
00276 // Setting source key. If the icon is refered to inside an extension, we homogenize the prefix to "ext/":
00277 $srcKey = ereg_replace('^(\.\.\/typo3conf\/ext|sysext|ext)\/','ext/',$src);
00278 #if ($src!=$srcKey)debug(array($src,$srcKey));
00279
00280 // LOOKING for alternative icons:
00281 if ($GLOBALS['TBE_STYLES']['skinImg'][$srcKey]) { // Slower or faster with is_array()? Could be used.
00282 list($src,$wHattribs) = $GLOBALS['TBE_STYLES']['skinImg'][$srcKey];
00283 } elseif ($GLOBALS['TBE_STYLES']['skinImgAutoCfg']) { // Otherwise, test if auto-detection is enabled:
00284
00285 // Search for alternative icon automatically:
00286 $fExt = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['forceFileExtension'];
00287 $scaleFactor = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] ? $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['scaleFactor'] : 1; // Scaling factor
00288 $lookUpName = $fExt ? ereg_replace('\.[[:alnum:]]+$','',$srcKey).'.'.$fExt : $srcKey; // Set filename to look for
00289
00290 // If file is found:
00291 if (@is_file($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'].$lookUpName)) { // If there is a file...
00292 $iInfo = @getimagesize($GLOBALS['TBE_STYLES']['skinImgAutoCfg']['absDir'].$lookUpName); // Get width/height:
00293
00294 // Set $src and $wHattribs:
00295 $src = $GLOBALS['TBE_STYLES']['skinImgAutoCfg']['relDir'].$lookUpName;
00296 $wHattribs = 'width="'.round($iInfo[0]*$scaleFactor).'" height="'.round($iInfo[1]*$scaleFactor).'"';
00297 }
00298
00299
00300 $GLOBALS['TBE_STYLES']['skinImg'][$srcKey] = array($src,$wHattribs);
00301 }
00302
00303
00304 # if (ereg('^width="([0-9]+)" height="([0-9]+)"$',$wHattribs,$reg)) $wHattribs='width="'.($reg[1]*2).'" height="'.($reg[2]*2).'"';
00305
00306
00307
00308 $matches = array();
00309 $srcBasename = basename($src);
00310 if (preg_match('/(.*)_i(\....)$/', $srcBasename, $matches)) {
00311 $temp_path = dirname(PATH_thisScript).'/';
00312 if(!@is_file($temp_path.$backPath.$src)) {
00313 $srcOrg = preg_replace('/_i'.preg_quote($matches[2]).'$/', $matches[2], $src);
00314 $src = t3lib_iconWorks::makeIcon($backPath.$srcOrg, 'disabled', 0, false, $temp_path.$backPath.$srcOrg, $srcBasename);
00315 }
00316 }
00317
00318
00319
00320 $output = '';
00321 switch($outputMode) {
00322 case 0:
00323 $output = ' src="'.$backPath.$src.'" '.$wHattribs;
00324 break;
00325 case 1:
00326 $output = $backPath.$src;
00327 break;
00328 case 2:
00329 $output = $wHattribs;
00330 break;
00331 }
00332 return $output;
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00363 function makeIcon($iconfile,$mode, $user, $protectSection,$absFile,$iconFileName_stateTagged) {
00364 $iconFileName = 'icon_'.t3lib_div::shortMD5($iconfile.'|'.$mode.'|-'.$user.'|'.$protectSection).'_'.$iconFileName_stateTagged.'.'.($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']?'png':'gif');
00365 $mainpath = '../typo3temp/'.$iconFileName;
00366 $path = PATH_site.'typo3temp/'.$iconFileName;
00367
00368
00369 if (@file_exists(PATH_typo3.'icons/'.$iconFileName)) {
00370 return 'icons/'.$iconFileName;
00371 } elseif (@file_exists($path)) {
00372 return $mainpath;
00373 } else {
00374 if (@file_exists($absFile)) {
00375 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib']) {
00376
00377
00378 $im = t3lib_iconworks::imagecreatefrom($absFile);
00379 if ($im<0) return $iconfile;
00380
00381
00382 if (($mode=='disabled') OR ($mode!='futuretiming' && $mode!='no_icon_found' && !(!$mode && $user))) {
00383 for ($c=0; $c<ImageColorsTotal($im); $c++) {
00384 $cols = ImageColorsForIndex($im,$c);
00385 $newcol = round(($cols['red']+$cols['green']+$cols['blue'])/3);
00386 $lighten = ($mode=='disabled') ? 2.5 : 2;
00387 $newcol = round(255-((255-$newcol)/$lighten));
00388 ImageColorSet($im,$c,$newcol,$newcol,$newcol);
00389 }
00390 }
00391
00392 if ($user) {
00393 if ($user < 100) {
00394 $black = ImageColorAllocate($im, 0,0,0);
00395 imagefilledrectangle($im, 0,0,(($user>10)?9:5),8,$black);
00396
00397 $white = ImageColorAllocate($im, 255,255,255);
00398 imagestring($im, 1, 1, 1, $user, $white);
00399 }
00400
00401 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_group.gif');
00402 if ($ol_im<0) return $iconfile;
00403
00404 t3lib_iconworks::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
00405 }
00406
00407 if ($mode) {
00408 unset($ol_im);
00409 switch($mode) {
00410 case 'deleted':
00411 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_deleted.gif');
00412 break;
00413 case 'futuretiming':
00414 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_timing.gif');
00415 break;
00416 case 'timing':
00417 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_timing.gif');
00418 break;
00419 case 'hiddentiming':
00420 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_hidden_timing.gif');
00421 break;
00422 case 'no_icon_found':
00423 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_no_icon_found.gif');
00424 break;
00425 case 'disabled':
00426
00427 $ol_im = 0;
00428 break;
00429 case 'hidden':
00430 default:
00431 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_hidden.gif');
00432 break;
00433 }
00434 if ($ol_im<0) return $iconfile;
00435 if ($ol_im) {
00436 t3lib_iconworks::imagecopyresized($im, $ol_im, 0, 0, 0, 0, imagesx($ol_im), imagesy($ol_im), imagesx($ol_im), imagesy($ol_im));
00437 }
00438 }
00439
00440 if ($protectSection) {
00441 $ol_im = t3lib_iconworks::imagecreatefrom($GLOBALS['BACK_PATH'].'gfx/overlay_sub5.gif');
00442 if ($ol_im<0) return $iconfile;
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 @t3lib_iconWorks::imagemake($im, $path);
00448 t3lib_div::gif_compress($path, 'IM');
00449 ImageDestroy($im);
00450 return $mainpath;
00451 } else {
00452 return $iconfile;
00453 }
00454 } else {
00455 return $GLOBALS['BACK_PATH'].'gfx/fileicons/default.gif';
00456 }
00457 }
00458 }
00459
00485 function imagecopyresized(&$im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h) {
00486 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_2'] && $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
00487 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['im_path']) {
00488
00489 $tempBaseName = PATH_site.'typo3temp/ICRZ_'.md5(uniqid('.'));
00490
00491 ImagePng($im, $tempBaseName.'_im.png');
00492 ImagePng($cpImg, $tempBaseName.'_cpImg.png');
00493
00494 $cmd = t3lib_div::imageMagickCommand('combine', '-compose over '.$tempBaseName.'_cpImg.png '.$tempBaseName.'_im.png '.$tempBaseName.'_out.png ');
00495 exec($cmd);
00496
00497 $im = imagecreatefrompng($tempBaseName.'_out.png');
00498 unlink($tempBaseName.'_im.png');
00499 unlink($tempBaseName.'_cpImg.png');
00500 unlink($tempBaseName.'_out.png');
00501 }
00502 } else {
00503 imagecopyresized($im, $cpImg, $Xstart, $Ystart, $cpImgCutX, $cpImgCutY, $w, $h, $w, $h);
00504 }
00505 }
00506
00515 function imagecreatefrom($file) {
00516 $file = t3lib_div::read_png_gif($file,$GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']);
00517 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
00518 return $file ? imagecreatefrompng($file) : -1;
00519 } else {
00520 return $file ? imagecreatefromgif($file) : -1;
00521 }
00522 }
00523
00532 function imagemake($im, $path) {
00533 if ($GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib_png']) {
00534 @ImagePng($im, $path);
00535 } else {
00536 @ImageGif($im, $path);
00537 }
00538 }
00539 }
00540 ?>