| 1 | <?php |
|---|
| 2 | $xoopsOption['nocommon'] = true ; |
|---|
| 3 | require '../../mainfile.php' ; |
|---|
| 4 | $mydirpath = dirname(__FILE__); |
|---|
| 5 | $mydirname = basename(dirname(__FILE__)); |
|---|
| 6 | $icon_cache_limit = 3600 ; // default 3600sec == 1hour |
|---|
| 7 | |
|---|
| 8 | session_cache_limiter('public'); |
|---|
| 9 | header("Expires: ".date('r',intval(time()/$icon_cache_limit)*$icon_cache_limit+$icon_cache_limit)); |
|---|
| 10 | header("Cache-Control: public, max-age=$icon_cache_limit"); |
|---|
| 11 | header("Last-Modified: ".date('r',intval(time()/$icon_cache_limit)*$icon_cache_limit)); |
|---|
| 12 | header("Content-type: image/png"); |
|---|
| 13 | |
|---|
| 14 | // file name |
|---|
| 15 | if( ! empty( $_GET['file'] ) ) { |
|---|
| 16 | $file_base = preg_replace( '/[^0-9a-z_]/' , '' , $_GET['file'] ) ; |
|---|
| 17 | } else { |
|---|
| 18 | $file_base = 'module_icon' ; |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | // branches by cores |
|---|
| 22 | if( defined( 'ICMS_TRUST_PATH' ) ) { |
|---|
| 23 | $draw_dirname = false ; |
|---|
| 24 | $file_base .= '_icms' ; |
|---|
| 25 | } else if( defined( 'XOOPS_CUBE_LEGACY' ) ) { |
|---|
| 26 | $draw_dirname = true ; |
|---|
| 27 | $file_base .= '_xcl' ; |
|---|
| 28 | $title = '('.$mydirname.')'; |
|---|
| 29 | $px = ( 112 - 6 * strlen( $title ) ) ; |
|---|
| 30 | $py = 14; |
|---|
| 31 | $font = 3; |
|---|
| 32 | |
|---|
| 33 | } else { |
|---|
| 34 | $draw_dirname = true ; |
|---|
| 35 | $title = $mydirname; |
|---|
| 36 | $px = ( 92 - 6 * strlen( $title ) ) / 2 ; |
|---|
| 37 | $py = 34; |
|---|
| 38 | $font = 3; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | // icon files must be PNG |
|---|
| 42 | $file = $file_base . '.png' ; |
|---|
| 43 | |
|---|
| 44 | // custom icon |
|---|
| 45 | if( file_exists( $mydirpath.'/'.$file ) ) { |
|---|
| 46 | $draw_dirname = false ; |
|---|
| 47 | $icon_fullpath = $mydirpath.'/module_icon.png' ; |
|---|
| 48 | } else { |
|---|
| 49 | $icon_fullpath = dirname(__FILE__).'/images/'.$file ; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if( $draw_dirname && function_exists( 'imagecreatefrompng' ) && function_exists( 'imagecolorallocate' ) && function_exists( 'imagestring' ) && function_exists( 'imagepng' ) ) { |
|---|
| 53 | |
|---|
| 54 | $im = imagecreatefrompng( $icon_fullpath ) ; |
|---|
| 55 | |
|---|
| 56 | $color = imagecolorallocate( $im , 0 , 0 , 0 ) ; // black |
|---|
| 57 | imagestring( $im , $font , $px , $py , $title , $color ) ; |
|---|
| 58 | imagepng( $im ) ; |
|---|
| 59 | imagedestroy( $im ) ; |
|---|
| 60 | |
|---|
| 61 | } else { |
|---|
| 62 | |
|---|
| 63 | readfile( $icon_fullpath ) ; |
|---|
| 64 | |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | ?> |
|---|