Просмотр файла download/include/theme.php

Размер файла: 3.89Kb
  1. <?php
  2.  
  3.  
  4. $theme = urldecode(htmlspecialchars($_GET['file']));
  5. $format = explode('.', $theme);
  6. $type = '.' . strtolower($format[count($format) - 1]);
  7. $name = 'screen/' . time() . '.gif';
  8. $location = 'http://' . str_replace(array('\\', '//'), array('/', '/'), $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/' . $name);
  9.  
  10.  
  11. if (file_exists($name)) {
  12. header('Location: ' . $location, true, 301);
  13. exit;
  14. }
  15.  
  16.  
  17. $size = explode('*', $setup['prev_size']);
  18. $g_preview_image_w = 100; // ширина картинки
  19. $g_preview_image_h = 100; // высота картинки
  20.  
  21.  
  22. if ($type == '.nth') {
  23. include '../incfiles/pclzip.php';
  24.  
  25. $nth = &new PclZip($theme);
  26.  
  27. $content = $nth->extract(PCLZIP_OPT_BY_NAME, 'theme_descriptor.xml', PCLZIP_OPT_EXTRACT_AS_STRING);
  28. if (!$content) {
  29. $content = $nth->extract(PCLZIP_OPT_BY_PREG, '\.xml$', PCLZIP_OPT_EXTRACT_AS_STRING);
  30. }
  31.  
  32.  
  33. $teg = simplexml_load_string($content[0]['content'])->wallpaper['src'] or $teg = simplexml_load_string($content[0]['content'])->wallpaper['main_display_graphics'];
  34. $image = $nth->extract(PCLZIP_OPT_BY_NAME, trim($teg), PCLZIP_OPT_EXTRACT_AS_STRING);
  35.  
  36.  
  37. $im = array_reverse(explode('.', $teg));
  38. $im = 'imageCreateFrom' . str_ireplace('jpg', 'jpeg', trim($im[0]));
  39.  
  40. file_put_contents($name, $image[0]['content']);
  41. $f = $im($name);
  42.  
  43. $h = imagesy($f);
  44. $w = imagesx($f);
  45.  
  46. $ratio = $w / $h;
  47. if ($g_preview_image_w / $g_preview_image_h > $ratio) {
  48. $g_preview_image_w = $g_preview_image_h * $ratio;
  49. }
  50. else {
  51. $g_preview_image_h = $g_preview_image_w / $ratio;
  52. }
  53.  
  54.  
  55. $new = imagecreatetruecolor($g_preview_image_w, $g_preview_image_h);
  56. imagecopyresampled($new, $f, 0, 0, 0, 0, $g_preview_image_w, $g_preview_image_h, $w, $h);
  57.  
  58. imageGif($new, $name);
  59. } elseif ($type == '.thm') {
  60. include 'include/class_tar.php';
  61.  
  62. $thm = &new Archive_Tar($theme);
  63. if (!$file = $thm->extractInString('Theme.xml') or !$file = $thm->extractInString(pathinfo($theme, PATHINFO_FILENAME) . '.xml')) {
  64.  
  65. $list = $thm->listContent();
  66.  
  67. $all = sizeof($list);
  68. for ($i = 0; $i < $all; ++$i) {
  69. if (pathinfo($list[$i]['filename'], PATHINFO_EXTENSION) == 'xml') {
  70. $file = $thm->extractInString($list[$i]['filename']);
  71. break;
  72. }
  73. }
  74.  
  75. }
  76.  
  77. // fix bug in tar.php
  78. if (!$file) {
  79. preg_match('/<\?\s*xml\s*version\s*=\s*"1\.0"\s*\?>(.*)<\/.+>/isU', file_get_contents($theme), $arr);
  80. $file = trim($arr[0]);
  81. }
  82.  
  83.  
  84. $load = trim((string )simplexml_load_string($file)->Standby_image['Source']);
  85.  
  86. if (strtolower(strrchr($load, '.')) == '.swf') {
  87. $load = '';
  88. }
  89.  
  90. if (!$load) {
  91. $load = trim((string )simplexml_load_string($file)->Desktop_image['Source']);
  92. }
  93.  
  94. if (strtolower(strrchr($load, '.')) == '.swf') {
  95. $load = '';
  96. }
  97.  
  98.  
  99. if (!$load) {
  100. $load = trim((string )simplexml_load_string($file)->Desktop_image['Source']);
  101. }
  102.  
  103. if (strtolower(strrchr($load, '.')) == '.swf') {
  104. $load = '';
  105. }
  106.  
  107. if (!$load) {
  108. exit;
  109. }
  110.  
  111.  
  112. $image = $thm->extractInString($load);
  113.  
  114.  
  115. $im = array_reverse(explode('.', $load));
  116. $im = 'imageCreateFrom' . str_ireplace('jpg', 'jpeg', trim($im[0]));
  117.  
  118. file_put_contents($name, $image);
  119. $f = $im($name);
  120.  
  121. $h = imagesy($f);
  122. $w = imagesx($f);
  123.  
  124. $ratio = $w / $h;
  125. if ($g_preview_image_w / $g_preview_image_h > $ratio) {
  126. $g_preview_image_w = $g_preview_image_h * $ratio;
  127. }
  128. else {
  129. $g_preview_image_h = $g_preview_image_w / $ratio;
  130. }
  131.  
  132.  
  133. $new = imagecreatetruecolor($g_preview_image_w, $g_preview_image_h);
  134. imagecopyresampled($new, $f, 0, 0, 0, 0, $g_preview_image_w, $g_preview_image_h, $w, $h);
  135.  
  136. imageGif($new, $name);
  137. }
  138.  
  139. ?>