PageRenderTime 72ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/wordpress-flash-uploader/tfu/tfu_helper.php

https://bitbucket.org/sidi09/aryans
PHP | 2663 lines | 2286 code | 163 blank | 214 comment | 633 complexity | 7771ab0174e4ff16a1de50286d71e374 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1, GPL-3.0, GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * TWG Flash uploader 2.14.x
  4. *
  5. * Copyright (c) 2004-2011 TinyWebGallery
  6. * written by Michael Dempfle
  7. *
  8. *
  9. * This file has all the helper functions.
  10. * Normally you don't have to modify anything here.
  11. * Only the timezone can be interesting for you: $timezone
  12. */
  13. /**
  14. * * ensure this file is being included by a parent file
  15. */
  16. defined('_VALID_TWG') or die('Direct Access to this location is not allowed.');
  17. $tfu_help_version = '2.14';
  18. // some globals you can change
  19. $check_safemode = true; // New 2.12.x - By default TFU checks if you have a safe mode problem. On some server this test does not work. There you can try to turn it off and test if you can e.g. create directories, upload files to new created directories.
  20. $session_double_fix = false; // this is only needed if you get errors because of corrupt sessions. If you turn this on a backup is made and checked if the first one is corrupt
  21. $timezone = ''; // Please set your timezone here if you have problems with timezones - if you need exact times - enter your timezone - see http://www.dynamicwebpages.de/php/timezones.php
  22. if (function_exists('date_default_timezone_set')) { // php 5.1.x
  23. if ($timezone != '') {
  24. @date_default_timezone_set($timezone);
  25. } else if (function_exists('date_default_timezone_get')) {
  26. set_error_handler('on_error_no_output');
  27. @date_default_timezone_set(@date_default_timezone_get());
  28. set_error_handler('on_error');
  29. } else {
  30. @date_default_timezone_set('Europe/Berlin');
  31. }
  32. }
  33. // default settings you should normally not change.
  34. $bg_color_preview_R = 255;
  35. $bg_color_preview_G = 255;
  36. $bg_color_preview_B = 255;
  37. $input_invalid = false;
  38. $old_error_handler = false;
  39. $master_profile = false;
  40. $debug_file = dirname(__FILE__) . "/tfu.log"; // can be overwritten in the config!
  41. tfu_setHeader();
  42. @ob_start();
  43. include dirname(__FILE__) . '/tfu_zip.class.php';
  44. // check if all included files have the same version to avoid problems during update!
  45. if ($tfu_zip_version != '2.14') {
  46. tfu_debug('Not all files belong to this version. Please update all files.');
  47. }
  48. /**
  49. * * Needed for Https and IE!
  50. */
  51. function tfu_setHeader()
  52. {
  53. // header("Pragma: public");
  54. // header("Expires: 0");
  55. // header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  56. // header('Pragma: I-hate-internet-explorer');
  57. // header('Cache-Control:no-store');
  58. if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE"))
  59. {
  60. header('Pragma: private');
  61. header('Cache-Control: private');
  62. }
  63. else
  64. {
  65. header('Pragma: public');
  66. header('Cache-Control: no-store, no-cache, must-revalidate' );
  67. header('Cache-Control: post-check=0, pre-check=0', false );
  68. }
  69. header('Expires: Sat, 26 Jul 1997 05:00:00 GMT' );
  70. header('Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
  71. header('Vary: User-Agent');
  72. }
  73. /**
  74. * function:tfu_debug()
  75. */
  76. function tfu_debug($data)
  77. {
  78. global $debug_file; // set in the tfu_config.php or is overwritten by the twg config
  79. global $enable_enhanced_debug;
  80. $data = replaceInput($data); // we check output data too - you never know!
  81. $input_invalid = false;
  82. if(stristr($data, 'called statically') === false && stristr($data, 'deprecated') === false) { // This error can happen in Joomla and can be ignored
  83. $debug_string = date('m.d.Y G:i:s') . ' - ' . $data . "\n";
  84. if ($enable_enhanced_debug) {
  85. $debug_string .= ' Request: ' . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . "\n";
  86. foreach (debug_backtrace() as $element) {
  87. $debug_string .= ' Stack: ' . basename($element['file']) . ":" . $element['line'] . ":" . $element['function'];
  88. foreach ($element['args'] as $par) {
  89. if (is_array($par)) {
  90. $par = str_replace("\n", "", print_r($par, true));
  91. }
  92. $debug_string .= ":" . substr($par, 0, 100); // max 100 chars
  93. }
  94. $debug_string .= "\n";
  95. }
  96. }
  97. if ($debug_file == '') {
  98. @ob_start();
  99. @error_log($debug_string, 0);
  100. @ob_end_clean();
  101. return;
  102. }
  103. if (file_exists($debug_file)) {
  104. if (filesize($debug_file) > 2000000) { // debug file max = 2MB !
  105. // we move the old one and start a new one - but only once!
  106. rename (dirname(__FILE__) . '/tfu.log', dirname(__FILE__) . '/tfu.log.bak');
  107. $debug_file_local = fopen($debug_file, 'w');
  108. } else {
  109. $debug_file_local = fopen($debug_file, 'a');
  110. }
  111. fputs($debug_file_local, $debug_string);
  112. fclose($debug_file_local);
  113. } else {
  114. if (is_writeable(dirname(__FILE__))) {
  115. if (!isset($debug_file)) { // if helper is included somewhere else!
  116. $debug_file = dirname(__FILE__) . "/tfu.log";
  117. }
  118. $debug_file_local = @fopen($debug_file, 'a');
  119. @fputs($debug_file_local, $debug_string);
  120. @fclose($debug_file_local);
  121. clearstatcache();
  122. } else {
  123. @ob_start();
  124. @error_log($debug_string, 0);
  125. @ob_end_clean();
  126. }
  127. }
  128. }
  129. }
  130. function on_error($num, $str, $file, $line)
  131. {
  132. if ((strpos ($file, 'email.inc.php') === false) && (strpos ($str, 'fopen') === false) && (strpos ($str, 'Deprecated') === false)) {
  133. tfu_debug("ERROR $num in " . substr($file, -40) . ", line $line: $str");
  134. }
  135. }
  136. function on_error_no_output($num, $str, $file, $line)
  137. {
  138. }
  139. if (!isset($skip_error_handling)) {
  140. @ini_set('display_errors','On');
  141. $old_error_handler = set_error_handler("on_error");
  142. }
  143. /**
  144. * Resizes a jpg/png/gif file if needed and stores it back to the original location
  145. * Needs gdlib > 2.0!
  146. * All other files are untouched
  147. * 1 = ok
  148. * 0 = failed
  149. * 2 = unknown - we retry after the save later.
  150. *
  151. */
  152. function resize_file($image, $size, $compression, $image_name, $dest_image = false)
  153. {
  154. global $use_image_magic, $image_magic_path, $enable_upload_debug, $store;
  155. if (!isset($store)) {
  156. $store = 0;
  157. }
  158. set_error_handler('on_error_no_output');
  159. ini_set('gd.jpeg_ignore_warning', 1); // since php 5.1.3 this leads that corrupt jpgs are read much better!
  160. set_error_handler('on_error');
  161. // we can do some caching here! - nice for 2.6 ;).
  162. if ($size == 'undefined') {
  163. tfu_debug('Resize: ERROR - No size is sent from the flash. Make sure that you have at least one value entered in the config. The image is NOT resized.');
  164. return 1;
  165. }
  166. $srcx = 0;
  167. $srcy = 0;
  168. if ($enable_upload_debug) { tfu_debug('Resize: Preparing to resize "' . $image . ' with size: '.$size.'"'); }
  169. if (file_exists($image)) {
  170. $oldsize = getimagesize($image);
  171. if ($oldsize[0] == 0) {
  172. // for broken images we try to read the exif data!
  173. $oldsize = get_exif_size($image, $image_name);
  174. }
  175. $oldsizex = $oldsize[0];
  176. $oldsizey = $oldsize[1];
  177. if (strpos($size, "x") !== false) {
  178. $s = explode("x", $size);
  179. $width = $s[0];
  180. $height = $s[1] ;
  181. } else {
  182. if (($oldsizex < $size) && ($oldsizey < $size)) {
  183. if ($enable_upload_debug) { tfu_debug('Resize: Image ('. $oldsizex .'x' .$oldsizey. ') is not resized with setting "' . $size . '"'); }
  184. return 1;
  185. }
  186. if ($oldsizex > $oldsizey) { // querformat - this keeps the dimension between horzonal and vertical
  187. $width = $size;
  188. $height = ($width / $oldsizex) * $oldsizey;
  189. } else { // hochformat - this keeps the dimension between horzonal an vertical
  190. $height = $size;
  191. $width = ($height / $oldsizey) * $oldsizex;
  192. }
  193. $width = round($width);
  194. $height = round($height);
  195. }
  196. if ($use_image_magic) {
  197. if ($enable_upload_debug) {
  198. tfu_debug("Resize: Image magick is used");
  199. }
  200. $ima = $loc_ima = realpath($image);
  201. $resize = $width . 'x' . $height;
  202. if ($dest_image) {
  203. $store = 1;
  204. $loc_ima = $dest_image;
  205. } else {
  206. if ($store == 2) { // 1st attempt was not o.k. - we try it with a backup name.
  207. $loc_ima = $ima . '.bak';
  208. }
  209. }
  210. $command = $image_magic_path . ' "' . $ima . '" -quality ' . $compression . ' -resize ' . $resize . ' "' . $loc_ima . '"';
  211. if ($enable_upload_debug) {
  212. tfu_debug("Resize: Image magick command: " . $command);
  213. }
  214. execute_command ($command);
  215. // we check if the resize was o.k.
  216. if ($store == 0) { // we do the resize to the same image again
  217. // we check if the resize was o.k.
  218. $newsize = getimagesize($ima);
  219. if ($width != $newsize[0]) { // resize failed for unknown reasons.
  220. if ($enable_upload_debug) { tfu_debug("Resize: Image could not be resized."); }
  221. return 2; // we try to resize again later!
  222. } else {
  223. return 1;
  224. }
  225. } else { // we resize to a temp file
  226. if (file_exists($ima . '.bak')) {
  227. $newsize = getimagesize($ima . '.bak');
  228. if ($width != $newsize[0]) { // resize failed for unknown reasons.
  229. if ($enable_upload_debug) { tfu_debug("Resize: Image could not be resized - wrong size"); }
  230. unlink($ima . '.bak');
  231. return 2; // we try to resize again later!
  232. } else { // resize is o.k.
  233. unlink($ima);
  234. rename($ima . '.bak',$ima);
  235. return 1;
  236. }
  237. } else {
  238. if ($enable_upload_debug) { tfu_debug("Resize: Image could not be resized in temp upload dir. Retry after move to final destination."); }
  239. return 2;
  240. }
  241. }
  242. } else {
  243. if ($enable_upload_debug) { tfu_debug("Resize: gd-lib is used."); }
  244. if (!isMemoryOk($oldsize, $size, $image_name, true)) {
  245. return 0;
  246. }
  247. if ($enable_upload_debug) { tfu_debug("Resize: memory seems o.k."); }
  248. $src = get_image_src($image, $oldsize[2]);
  249. if (!$src) {
  250. tfu_debug('File ' . $image_name . ' cannot be resized!');
  251. return false;
  252. }
  253. $dst = ImageCreateTrueColor($width, $height);
  254. imagecopyresampled($dst, $src, 0, 0, $srcx, $srcy , $width, $height, $oldsizex, $oldsizey);
  255. @imagedestroy($src);
  256. if ($dest_image) {
  257. $image = $dest_image;
  258. }
  259. if ($enable_upload_debug) { tfu_debug("Resize: image was resampled."); }
  260. if ($oldsize[2] == 1) { // gif
  261. $res = imagegif($dst, $image);
  262. } else if ($oldsize[2] == 2) { // jpg
  263. $res = imagejpeg($dst, $image, $compression);
  264. } else if ($oldsize[2] == 3) { // png
  265. $res = imagepng($dst, $image);
  266. } else {
  267. $res = imagejpeg($dst, $image, $compression);
  268. }
  269. if ($res) {
  270. // we check if the resize was o.k.
  271. $newsize = getimagesize($image);
  272. if ($width != $newsize[0]) { // resize failed for unknown reasons.
  273. if ($enable_upload_debug) { tfu_debug("Resize: Image could not be resized."); }
  274. return 2;
  275. }
  276. if ($enable_upload_debug) { tfu_debug("Resize: Image was saved and resized."); }
  277. @imagedestroy($dst);
  278. return 1;
  279. } else {
  280. tfu_debug('cannot save: ' . $image);
  281. return 0;
  282. }
  283. }
  284. } else
  285. return 2;
  286. }
  287. /**
  288. * resizes a file and writes it back to the user! - can do jpg, png and gif if the support is there !
  289. * renamed png's (that that are actually jpg's are handled as well!)
  290. * Needs gdlib > 2.0!
  291. */
  292. function send_thumb($image, $compression, $sizex, $sizey, $generateOnly = false)
  293. {
  294. global $bg_color_preview_R, $bg_color_preview_G, $bg_color_preview_B;
  295. global $info_text, $info_textcolor_R, $info_textcolor_G, $info_textcolor_B, $info_font, $info_fontsize;
  296. set_error_handler('on_error_no_output');
  297. ini_set('gd.jpeg_ignore_warning', 1); // since php 5.1.3 this leads that corrupt jpgs are read much better!
  298. set_error_handler('on_error');
  299. $srcx = 0;
  300. $srcy = 0;
  301. $dimx = $sizex;
  302. $dimy = $sizey;
  303. $usethumbs = false;
  304. if (file_exists(dirname(__FILE__) . '/thumbs') && is_writable(dirname(__FILE__) . '/thumbs')) { // is a caching dir available and writeable?
  305. $cachename = dirname(__FILE__) . '/thumbs/' . sha1($image . $sizex) . '.jpg';
  306. $usethumbs = true;
  307. }
  308. if ($usethumbs && file_exists($cachename)) {
  309. // we return the jpg!
  310. header('Content-type: image/jpg');
  311. header('Content-Length: ' . filesize($cachename));
  312. $fp = fopen($cachename, 'rb');
  313. while ($content = fread($fp, 8192)) {
  314. print $content;
  315. }
  316. fclose($fp);
  317. return true;
  318. } else if (file_exists($image)) {
  319. if (filesize($image) == 0) {
  320. return false;
  321. }
  322. $oldsize = getimagesize($image);
  323. // for broken images we try to read the exif data!
  324. if ($oldsize[0] == 0) {
  325. $oldsize = get_exif_size($image, $image);
  326. }
  327. $oldsizex = $oldsize[0];
  328. $oldsizey = $oldsize[1];
  329. if ($oldsizex < $sizex && $oldsizey < $sizey) {
  330. $sizex = $oldsizex;
  331. $sizey = $oldsizey;
  332. }
  333. $height = $sizey;
  334. $width = ($height / $oldsizey) * $oldsizex;
  335. if ($width > $sizex) {
  336. $width = $sizex;
  337. $height = ($width / $oldsizex) * $oldsizey;
  338. }
  339. if (isMemoryOk($oldsize, $sizex, '')) {
  340. $src = get_image_src($image, $oldsize[2]);
  341. if (!$src) { // error in image!
  342. if ($sizex < 100) {
  343. // we return an empty white one ;).
  344. $src = ImageCreateTrueColor($oldsizex, $oldsizey);
  345. $back = imagecolorallocate($src, 255, 255, 255);
  346. imagefilledrectangle($src, 0, 0, $oldsizex, $oldsizex, $back);
  347. }
  348. tfu_debug($image . ' is not a valid image - please check the file.');
  349. return false;
  350. }
  351. // $dst = ImageCreateTrueColor($width, $height);
  352. $dst = ImageCreateTrueColor($dimx, $dimy);
  353. if ($dimx < 100) { // white bg for small preview
  354. $back = imagecolorallocate($dst, $bg_color_preview_R, $bg_color_preview_G, $bg_color_preview_B);
  355. } else { // gray bg for big preview
  356. $back = imagecolorallocate($dst, 245, 245, 245);
  357. }
  358. imagefilledrectangle($dst, 0, 0, $dimx, $dimy, $back);
  359. if ($dimx > 100) { // border
  360. imagerectangle ($dst, 0, 0, $dimx-1, $dimy-1, imagecolorallocate($dst, 160, 160, 160));
  361. }
  362. $offsetx = 0;
  363. $offsetx_b = 0;
  364. if ($dimx > $width) { // we have to center!
  365. $offsetx = floor(($dimx - $width) / 2);
  366. } else if ($dimx > 100) {
  367. $offsetx = 4;
  368. $offsetx_b = 8;
  369. }
  370. $offsety = 0;
  371. $offsety_b = 0;
  372. if ($dimy > $height) { // we have to center!
  373. $offsety = floor(($dimy - $height) / 2);
  374. } else if ($dimx > 100) {
  375. $offsety = 4;
  376. $offsety_b = 8;
  377. }
  378. $trans = imagecolortransparent ($src);
  379. imagecolorset ($src, $trans, 255, 255, 255);
  380. imagecolortransparent($src, imagecolorallocate($src, 0, 0, 0));
  381. imagecopyresampled($dst, $src, $offsetx, $offsety, $srcx, $srcy, $width - $offsetx_b, $height - $offsety_b, $oldsizex, $oldsizey);
  382. if (function_exists("imagettftext") && $dimx > 100 && $info_text != '' ) {
  383. // some extra info at the bottom of the image. Available parameters: {date} {size} {dimension}
  384. $text = str_replace('{dimension}', $oldsizex."x".$oldsizey, $info_text);
  385. $text = str_replace('{size}', formatSize(filesize($image)), $text);
  386. $text = str_replace('{date}', date("d.m.Y",filemtime($image)), $text);
  387. $color = imagecolorclosest ($dst, $info_textcolor_R, $info_textcolor_G, $info_textcolor_B);
  388. imagettftext($dst, $info_fontsize, 0, 8, $dimy-8, $color, $info_font, $text);
  389. }
  390. header('Content-type: image/jpg');
  391. if ($usethumbs) { // we save the thumb
  392. imagejpeg($dst, $cachename, $compression);
  393. }
  394. if (!$generateOnly) {
  395. ob_start();
  396. if (imagejpeg($dst, '', $compression)) {
  397. $buffer = ob_get_contents();
  398. header('Content-Length: ' . strlen($buffer));
  399. ob_end_clean();
  400. echo $buffer;
  401. @imagedestroy($dst);
  402. return true;
  403. } else {
  404. ob_end_flush();
  405. tfu_debug('cannot save: ' . $image);
  406. @imagedestroy($src);
  407. }
  408. }
  409. }
  410. }
  411. return false;
  412. }
  413. // we check if we can get a memory problem!
  414. function isMemoryOk($oldsize, $newsize, $image_name, $debug = true)
  415. {
  416. $memory_read = (($oldsize[0] * $oldsize[1] * 6) + 2048576) * 1.1; // mem and we add 2 MB + 10% for safty
  417. $memory_orig = ($newsize * $newsize * 6) * 1.1; // 10% overhead.
  418. $memory = $memory_read + $memory_orig;
  419. // I try to increase the memory if more is needed and if it is possible.
  420. if (function_exists("memory_get_usage")) {
  421. $InUse=memory_get_usage();
  422. if ($memory > return_kbytes(ini_get('memory_limit')*1024) - $InUse)
  423. {
  424. @ini_set('memory_limit',$memory + $InUse + 5000000); // 5 MB for processing extra!
  425. }
  426. }
  427. $memory_limit = return_kbytes(ini_get('memory_limit')) * 1024;
  428. if ($memory > $memory_limit && $memory_limit > 0) { // we store the number of images that have a size problem in the session and output this in the readDir file
  429. $mem_errors = 0;
  430. if (isset($_SESSION['upload_memory_limit'])) {
  431. $mem_errors = $_SESSION['upload_memory_limit'];
  432. }
  433. $_SESSION['upload_memory_limit'] = ($mem_errors + 1);
  434. if ($debug) {
  435. tfu_debug('File ' . $image_name . ' cannot be processed because not enough memory is available! Needed: ~' . $memory . '. Available: ' . $memory_limit);
  436. }
  437. return false;
  438. } else {
  439. return true;
  440. }
  441. }
  442. $sn = get_server_name();
  443. function get_image_src($image, $type)
  444. {
  445. set_error_handler('on_error_no_output'); // No error shown because we handle this error!
  446. if ($type == 1) { // gif
  447. $src = imagecreatefromgif($image);
  448. } else if ($type == 2) { // jpg
  449. $src = imagecreatefromjpeg($image);
  450. } else if ($type == 3) { // png
  451. $src = @imagecreatefrompng($image);
  452. } else {
  453. $src = imagecreatefromjpeg($image); // if error we try read an jpg!
  454. }
  455. set_error_handler('on_error');
  456. return $src;
  457. }
  458. /**
  459. * A small helper function !
  460. */
  461. function return_kbytes($val)
  462. {
  463. $val = trim($val);
  464. if (strlen($val) == 0) {
  465. return 0;
  466. }
  467. $last = strtolower($val{strlen($val)-1});
  468. switch ($last) {
  469. // The 'G' modifier is available since PHP 5.1.0
  470. case 'g':
  471. $val *= 1024;
  472. case 'm':
  473. $val *= 1024;
  474. case 'k':
  475. $val *= 1;
  476. }
  477. return $val;
  478. }
  479. $m = is_renameable();
  480. /**
  481. * get maximum upload size
  482. */
  483. function getMaximumUploadSize()
  484. {
  485. $upload_max = return_kbytes(ini_get('upload_max_filesize'));
  486. $post_max = return_kbytes(ini_get('post_max_size'));
  487. return $upload_max < $post_max ? $upload_max : $post_max;
  488. }
  489. /**
  490. * compares caseinsensitive - normally this could be done with natcasesort -
  491. * but this seems to be buggy on my test system!
  492. */
  493. function mycmp ($a, $b)
  494. {
  495. return strnatcasecmp ($a, $b);
  496. }
  497. /**
  498. * compares caseinsensitive - ascending for date
  499. */
  500. function mycmp_date ($a, $b)
  501. {
  502. return strnatcasecmp ($b, $a);
  503. }
  504. function cmp_dec ($a, $b)
  505. {
  506. return mycmp(urldecode($a), urldecode($b));
  507. }
  508. function cmp_dir_dec ($a, $b)
  509. {
  510. $a = substr($a, 0);
  511. $b = substr($b, 0);
  512. return mycmp(urldecode($a), urldecode($b));
  513. }
  514. function cmp_date_dec ($a, $b)
  515. {
  516. return mycmp_date(urldecode($a), urldecode($b));
  517. }
  518. /**
  519. * deletes everything from the starting dir on! tfu deletes only one level by default - but this
  520. * is triggered by the endableing/disabling of the delete Folder status! not by this function!
  521. */
  522. function remove($item) // remove file / dir
  523. {
  524. $item = realpath($item);
  525. $ok = true;
  526. if (is_link($item) || is_file($item))
  527. $ok = @unlink($item);
  528. elseif (is_dir($item)) {
  529. if (($handle = opendir($item)) === false)
  530. return false;
  531. while (($file = readdir($handle)) !== false) {
  532. if (($file == '..' || $file == '.')) continue;
  533. $new_item = $item . '/' . $file;
  534. if (!file_exists($new_item))
  535. return false;
  536. if (is_dir($new_item)) {
  537. $ok = remove($new_item);
  538. } else {
  539. $ok = @unlink($new_item);
  540. }
  541. }
  542. closedir($handle);
  543. $ok = @rmdir($item);
  544. }
  545. return $ok;
  546. }
  547. function is_tfu_deletable($file)
  548. {
  549. $isWindows = substr(PHP_OS, 0, 3) == 'WIN';
  550. set_error_handler('on_error_no_output');
  551. $owner = @fileowner($file);
  552. set_error_handler('on_error');
  553. // if we cannot read the owner we assume that the safemode is on and we cannot access this file!
  554. if ($owner === false) {
  555. return false;
  556. }
  557. // if dir owner not same as effective uid of this process, then perms must be full 777.
  558. // No other perms combo seems reliable across system implementations
  559. if (function_exists('posix_getpwuid')) {
  560. if (!$isWindows && posix_geteuid() !== $owner) {
  561. return (substr(decoct(@fileperms($file)), -3) == '777' || @is_writable(dirname($file)));
  562. }
  563. }
  564. if ($isWindows && getmyuid() != $owner) {
  565. return (substr(decoct(fileperms($file)), -3) == '777');
  566. }
  567. // otherwise if this process owns the directory, we can chmod it ourselves to delete it
  568. return is_writable(dirname($file));
  569. }
  570. function replaceInput($input)
  571. {
  572. global $input_invalid;
  573. $output = str_replace('<', '_', $input);
  574. $output = str_replace('>', '_', $output);
  575. $output = str_replace('?', '_Q_', $input);
  576. // we check some other settings too :)
  577. if (strpos($output, 'cookie(') || strpos($output, 'popup(') || strpos($output, 'open(') || strpos($output, 'alert(') || strpos($output, 'reload(') || strpos($output, 'refresh(')) {
  578. $output = 'XSS';
  579. }
  580. // we check for security if a .. is in the path we remove this! and .// like in http:// is invalid too!
  581. $output = str_replace("..", "__", $output);
  582. $output = str_replace("//", "__", $output);
  583. return $output;
  584. }
  585. function getCurrentDir()
  586. {
  587. // we read the dir - first session, then parameter, then default!
  588. if (isset($_SESSION['TFU_DIR'])) {
  589. $dir = $_SESSION['TFU_DIR'];
  590. } else {
  591. $dir = 'upload';
  592. }
  593. return $dir;
  594. }
  595. function getFileName($dir)
  596. {
  597. global $fix_utf8, $exclude_directories, $sort_files_by_date, $hide_hidden_files, $enable_enhanced_debug;
  598. if (!isset($_GET['index']) || $_GET['index'] == '') {
  599. return '';
  600. }
  601. $index = parseInputParameter($_GET['index']);
  602. // All files are sorted in the array myFiles
  603. $dirhandle = opendir($dir);
  604. $myFiles = array();
  605. while (($file = readdir($dirhandle)) !== false) {
  606. if ($file != '.' && $file != '..' && !in_array($file, $exclude_directories)&& (!($hide_hidden_files && (strpos($file, '.') === 0)))) {
  607. if (!is_dir($dir . '/' . $file) && check_view_extension($file)) {
  608. if ($sort_files_by_date) {
  609. $file = filemtime(($dir . '/' . $file)) . $file;
  610. }
  611. array_push($myFiles, fix_encoding($file, $fix_utf8));
  612. }
  613. }
  614. }
  615. closedir ($dirhandle);
  616. if ($sort_files_by_date) {
  617. usort ($myFiles, 'mycmp_date');
  618. } else {
  619. usort ($myFiles, 'mycmp');
  620. }
  621. // now we have the same order as in the listing and check if we have one or multiple indexes !
  622. if (strpos($index, ',') === false) { // only 1 selection
  623. if (isset($myFiles[$index])) {
  624. return get_decoded_string($dir, $myFiles[$index]);
  625. } else {
  626. if ($enable_enhanced_debug) {
  627. tfu_debug("File index not found.");
  628. }
  629. return "_FILE_NOT_FOUND";
  630. }
  631. } else { // we return an array !
  632. // we need the offset
  633. $offset = parseInputParameter($_GET['offset']);
  634. $filenames = array();
  635. $index = trim($index, ',');
  636. $indices = explode(',', $index);
  637. foreach ($indices as $ind) {
  638. $filenames[] = get_decoded_string($dir, $myFiles[$ind - $offset]);
  639. }
  640. return $filenames;
  641. }
  642. }
  643. function get_decoded_string($dir, $string)
  644. {
  645. global $fix_utf8;
  646. if ($fix_utf8 == 'none') {
  647. return $dir . '/' . $string;
  648. } else if ($fix_utf8 == '') {
  649. return $dir . '/' . utf8_decode(remove_sort_prefix($string));
  650. } else {
  651. return $dir . '/' . iconv('UTF-8', $fix_utf8, remove_sort_prefix($string));
  652. }
  653. }
  654. function remove_sort_prefix($string) {
  655. global $sort_files_by_date;
  656. if ($sort_files_by_date) {
  657. return substr($string, 10);
  658. } else {
  659. return $string;
  660. }
  661. }
  662. function getRootUrl() {
  663. if (isset($_SERVER)) {
  664. $GLOBALS['__SERVER'] = &$_SERVER;
  665. } elseif (isset($HTTP_SERVER_VARS)) {
  666. $GLOBALS['__SERVER'] = &$HTTP_SERVER_VARS;
  667. }
  668. $dirn = dirname ($GLOBALS['__SERVER']['PHP_SELF']);
  669. if ($dirn == '\\' || $dirn == '/') $dirn = '';
  670. return 'http' . (isset($GLOBALS['__SERVER']['HTTPS']) ? 's' : '') . '://' . $GLOBALS['__SERVER']['HTTP_HOST'] . $dirn . '/';
  671. }
  672. function tfu_checkSession()
  673. {
  674. }
  675. if (isset($_SESSION['TF' . 'U_RN'])) {
  676. $s = $_SESSION['TF' . 'U_RN'];
  677. $t = substr($s, 0, 3) . substr($s, 21, 3) . substr($s, 10, 4);
  678. if (time() > ($t + (6 * 12 * 2 * 1000))) $_SESSION['TF' . 'U_RN'] = '0';
  679. }
  680. /**
  681. * * removes ../ in a pathname!
  682. */
  683. function fixUrl($url)
  684. {
  685. $pos = strpos ($url, '../');
  686. while ($pos !== false && $pos != 0) {
  687. $before = substr($url, 0, $pos-1);
  688. $after = substr($url, $pos + 3);
  689. $before = substr($before, 0, strrpos($before, '/') + 1);
  690. $url = $before . $after;
  691. $pos = strpos ($url, '../');
  692. }
  693. return $url;
  694. }
  695. function runsNotAsCgi()
  696. {
  697. $no_cgi = true;
  698. if (isset($_SERVER['SERVER_SOFTWARE'])) {
  699. $mystring = $_SERVER['SERVER_SOFTWARE'];
  700. $pos = strpos ($mystring, 'CGI');
  701. if ($pos === false) {
  702. // nicht gefunden...
  703. } else {
  704. $no_cgi = false;
  705. }
  706. $mystring = $_SERVER['SERVER_SOFTWARE'];
  707. $pos = strpos ($mystring, 'cgi');
  708. if ($pos === false) {
  709. // nicht gefunden...
  710. } else {
  711. $no_cgi = false;
  712. }
  713. }
  714. return $no_cgi;
  715. }
  716. function has_safemode_problem_global()
  717. {
  718. $isWindows = substr(PHP_OS, 0, 3) == 'WIN';
  719. $no_cgi = runsNotAsCgi();
  720. if (function_exists('posix_getpwuid') && function_exists('posix_getpwuid')) {
  721. if (!isset($_SESSION['tfu_posix_geteuid_works'])) {
  722. $_SESSION['tfu_posix_geteuid_works'] = 'check';
  723. $userid = @posix_geteuid();
  724. $userinfo = @posix_getpwuid($userid);
  725. $def_user = array ('apache', 'nobody', 'www');
  726. if (in_array ($userinfo['name'], $def_user)) {
  727. $no_cgi = true;
  728. }
  729. unset($_SESSION['tfu_posix_geteuid_works']);
  730. }
  731. }
  732. if (ini_get('safe_mode') == 1 && $no_cgi && !$isWindows) {
  733. return true;
  734. }
  735. return false;
  736. }
  737. // set a umask that makes the files deletable again!
  738. if ($check_safemode && (has_safemode_problem_global() || runsNotAsCgi())) {
  739. umask(0000); // otherwise you cannot delete files anymore with ftp if you are no the owner!
  740. } else {
  741. umask(0022); // Added to make created files/dirs group writable
  742. }
  743. function gd_version()
  744. {
  745. static $gd_version_number = null;
  746. if ($gd_version_number === null) {
  747. if (function_exists('gd_info')) {
  748. $info = gd_info();
  749. $module_info = $info['GD Version'];
  750. if (preg_match("/[^\d\n\r]*?([\d\.]+)/i",
  751. $module_info, $matches)) {
  752. $gd_version_number = $matches[1];
  753. } else {
  754. $gd_version_number = 0;
  755. }
  756. } else { // needed before 4.3 !
  757. ob_start();
  758. phpinfo(8);
  759. $module_info = ob_get_contents();
  760. @ob_end_clean();
  761. if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i",
  762. $module_info, $matches)) {
  763. $gd_version_number = $matches[1];
  764. } else {
  765. $gd_version_number = 0;
  766. }
  767. }
  768. }
  769. return $gd_version_number;
  770. }
  771. function is_gd_version_min_20()
  772. {
  773. if (gd_version() >= 2) {
  774. return 'true';
  775. } else {
  776. return 'false';
  777. }
  778. }
  779. function restore_split_files($items)
  780. {
  781. $split_array = array();
  782. // first we check if files are split and group he splited files
  783. foreach ($items as $filename) {
  784. if (is_part($filename)) {
  785. $split_array[removeExtension($filename)][] = $filename;
  786. }
  787. }
  788. foreach ($split_array as $restore => $parts) {
  789. $totsize = 0;
  790. // sorting of parts is important!
  791. usort($parts, 'mycmp');
  792. // we open the destination
  793. $dest_file = fopen($restore, 'wb');
  794. foreach ($parts as $parts_name) {
  795. $totsize += filesize($parts_name);
  796. $fp = fopen($parts_name, 'rb');
  797. while ($content = fread($fp, 8192)) {
  798. fputs($dest_file, $content);
  799. flush();
  800. ob_flush();
  801. }
  802. fclose($fp);
  803. }
  804. fclose($dest_file);
  805. // if o.k. we delete the .part files! - check the filesize maybe?
  806. if (filesize($restore) == $totsize) {
  807. array_map('unlink', $parts);
  808. }
  809. }
  810. }
  811. function resize_merged_files($items, $size)
  812. {
  813. global $compression;
  814. $split_array = array();
  815. // first we check if files are split and group the splited files
  816. foreach ($items as $filename) {
  817. if (is_part($filename)) {
  818. $split_array[removeExtension($filename)][] = $filename;
  819. }
  820. }
  821. foreach ($split_array as $restore => $parts) {
  822. if (is_supported_tfu_image(my_basename($restore), $restore) && $size < 100000) {
  823. resize_file($restore, $size, $compression, my_basename($restore));
  824. }
  825. }
  826. }
  827. function is_part($str)
  828. {
  829. global $split_extension;
  830. $ex = substr (strrchr ($str, '.'), 1);
  831. $pos = strpos ($ex, $split_extension);
  832. if ($pos === false) {
  833. return false;
  834. } else if ($pos == 0) {
  835. return true;
  836. } else {
  837. return false;
  838. }
  839. }
  840. function is_supported_tfu_image($image,$current)
  841. {
  842. global $scan_images;
  843. $image = strtolower ($image);
  844. $isimage = preg_match('/.*\.(jp)(e){0,1}(g)$/', $image) ||
  845. preg_match('/.*\.(gif)$/', $image) ||
  846. preg_match('/.*\.(png)$/', $image) ;
  847. if ($isimage) {
  848. // we check if this is really an image - if we cannot read the size we assume it could be a php fake
  849. set_error_handler('on_error_no_output');
  850. if (file_exists($current)) {
  851. $size = @getimagesize ($current);
  852. if ($size === false || $scan_images) {
  853. // seems not to be an image - now we we replace the <?php with <_php
  854. $data = file_get_contents($current);
  855. $data2 = str_replace("<?php","<_php",$data);
  856. if ($data2 != $data) {
  857. file_put_contents($current, $data2);
  858. tfu_debug("SECURITY WARNING: Please check the file ".$image.". It was uploaded with an image extensions but included php code. The php start of this file was changed because of security issues!" );
  859. }
  860. }
  861. }
  862. set_error_handler('on_error');
  863. }
  864. return $isimage;
  865. }
  866. if (!isset($skip_error_handling)) {
  867. set_error_handler("on_error_no_output"); // 4.x gives depreciated errors here but if I change it it does only work with 5.x - therefore I don't show any errors here !
  868. }
  869. if (file_exists('tfu_exifReader.php')) {
  870. include 'tfu_exifReader.php';
  871. }
  872. if (!isset($skip_error_handling)) {
  873. set_error_handler("on_error");
  874. }
  875. function get_exif_size($filename, $image_name)
  876. {
  877. set_error_handler('on_error_no_output'); // is needed because error are most likly but we don't care about fields we don't even know
  878. $er = new phpExifReader($filename);
  879. $er->processFile();
  880. $exif_info = $er->getImageInfo();
  881. set_error_handler('on_error');
  882. $size_array = array();
  883. $size_array[2] = 2;
  884. if (isset($er->ImageInfo[TAG_EXIF_IMAGEWIDTH])) {
  885. $size_array[0] = $er->ImageInfo[TAG_EXIF_IMAGEWIDTH];
  886. } else {
  887. $size_array[0] = 1024;
  888. tfu_debug('Size of image ' . $image_name . ' cannot be detected using 1024x768.');
  889. }
  890. if (isset($er->ImageInfo[TAG_EXIF_IMAGELENGTH])) {
  891. $size_array[1] = $er->ImageInfo[TAG_EXIF_IMAGELENGTH];
  892. } else {
  893. $size_array[1] = 768;
  894. }
  895. return $size_array;
  896. }
  897. function removeCacheThumb($filename)
  898. {
  899. $thumbsdir = dirname(__FILE__) . '/thumbs';
  900. if (file_exists($thumbsdir) && is_writable($thumbsdir)) { // is a caching dir available and writeable?
  901. $cachename = $thumbsdir . '/' . sha1($filename . '160') . '.jpg'; // small
  902. if (file_exists($cachename)) {
  903. @unlink($cachename);
  904. }
  905. $cachename = $thumbsdir . '/' . sha1($filename . '400') . '.jpg'; // big
  906. if (file_exists($cachename)) {
  907. @unlink($cachename);
  908. }
  909. }
  910. cleanup_thumbs_cache();
  911. }
  912. function cleanup_thumbs_cache()
  913. {
  914. if (isset($_SESSION['checkcache'])) { // we only check once per session!
  915. return;
  916. }
  917. $_SESSION['checkcache'] = 'TRUE';
  918. $cache_time = 10; // in days !!
  919. $thumbsdir = dirname(__FILE__) . '/thumbs';
  920. $cache_time = $cache_time * 86400;
  921. $del_time = time() - $cache_time;
  922. if (file_exists($thumbsdir) && is_writable($thumbsdir)) {
  923. $d = opendir($thumbsdir);
  924. $i = 0;
  925. while (false !== ($entry = readdir($d))) {
  926. if ($entry != '.' && $entry != '..') {
  927. $atime = fileatime($thumbsdir . '/' . $entry);
  928. if ($atime < $del_time) {
  929. @unlink($thumbsdir . '/' . $entry);
  930. }
  931. }
  932. }
  933. closedir($d);
  934. }
  935. }
  936. function removeExtension($name)
  937. {
  938. return substr($name, 0, strrpos ($name, '.'));
  939. }
  940. /**
  941. * * create a unique directory - 1 st is year, 2 and 3 rd is month - rest is unique up to length
  942. */
  943. function createUniqueDir($basedir, $length = 10)
  944. {
  945. $dir = '';
  946. $prefix = substr(date('Ym'), 3);
  947. while ($dir == '') {
  948. $start = pow (10, $length-3);
  949. $stop = pow (10, $length-2)-1;
  950. $value = rand($start, $stop);
  951. $tempdir = $basedir . $prefix . $value;
  952. if (!file_exists($tempdir)) {
  953. mkdir($tempdir);
  954. $dir = $tempdir;
  955. break;
  956. }
  957. }
  958. return $dir;
  959. }
  960. /**
  961. * Finds the destination folder depending on the id - the id has the format 1,2,0
  962. * means folder 2 in level 1, 3 rd folder in level 2, 1st folder in level 3.....
  963. * empty means root!
  964. */
  965. function getDestinationFolder($id_list)
  966. {
  967. global $exclude_directories, $hide_hidden_files;
  968. $base_dir = $_SESSION['TFU_ROOT_DIR'];
  969. if ($id_list == '') return $base_dir;
  970. $ids = explode(',', $id_list);
  971. $dir = $base_dir;
  972. foreach ($ids as $id) {
  973. // read the dir - get the directory and set the base to the new level.
  974. $dirhandle = opendir($dir);
  975. $myDirs = array();
  976. while (false !== ($filed = readdir($dirhandle))) {
  977. if ($filed != '.' && $filed != '..' && !in_array($filed, $exclude_directories) && (!($hide_hidden_files && (strpos($filed, '.') === 0)))) {
  978. if (is_dir($dir . '/' . $filed)) {
  979. array_push($myDirs, $filed);
  980. }
  981. }
  982. }
  983. usort ($myDirs, 'mycmp');
  984. $dir = $dir . '/' . $myDirs[$id];
  985. }
  986. return $dir;
  987. }
  988. function get_tree_xml()
  989. {
  990. if (isset($_SESSION["TREE_" . $_SESSION['TFU_ROOT_DIR']])) {
  991. return $_SESSION["TREE_" . $_SESSION['TFU_ROOT_DIR']];
  992. } else {
  993. $tree = '<node><node label="/" id="">' . show_dir_xml($_SESSION['TFU_ROOT_DIR']) . '</node></node>';
  994. $_SESSION["TREE_" . $_SESSION['TFU_ROOT_DIR']] = $tree;
  995. return $tree;
  996. }
  997. }
  998. function show_dir_xml($myDir = '.', $indent = 0, $levelStr = '')
  999. {
  1000. global $exclude_directories, $hide_hidden_files;
  1001. $dir = opendir($myDir);
  1002. $einrueckung = str_repeat(' ', $indent * 4);
  1003. if ($levelStr != '') {
  1004. $levelStr .= ',';
  1005. }
  1006. $foo = '';
  1007. $counter = 0;
  1008. $dirlist = array();
  1009. while ($file = readdir($dir)) {
  1010. $dirlist[] = $file;
  1011. }
  1012. usort ($dirlist, 'mycmp');
  1013. foreach ($dirlist as $file) {
  1014. $newDir = $myDir . '/' . $file;
  1015. if ($file == '.' || $file == '..' || in_array($file, $exclude_directories)&& (!($hide_hidden_files && (strpos($file, '.') === 0))))
  1016. continue;
  1017. if (is_dir($newDir)) {
  1018. $curLevelStr = $levelStr . '' . $counter++;
  1019. $foo .= '<node id="' . $curLevelStr . '" label="' . $file . '">' . "\n" . show_dir_xml($newDir . '/', 1, $curLevelStr) . "</node>\n";
  1020. }
  1021. }
  1022. return $foo;
  1023. }
  1024. function get_unique_filename($dir, $image)
  1025. {
  1026. $i = 1;
  1027. $probeer = $image;
  1028. while (file_exists($dir . $probeer)) {
  1029. $punt = strrpos($image, '.');
  1030. if (substr($image, ($punt-3), 1) !== ('(') && substr($image, ($punt-1), 1) !== (')')) {
  1031. $probeer = substr($image, 0, $punt) . '(' . $i . ')' .
  1032. substr($image, ($punt), strlen($image) - $punt);
  1033. } else {
  1034. $probeer = substr($image, 0, ($punt-3)) . '(' . $i . ')' .
  1035. substr($image, ($punt), strlen($image) - $punt);
  1036. }
  1037. $i++;
  1038. }
  1039. return $probeer;
  1040. }
  1041. /**
  1042. * Needed for loading saving text files
  1043. */
  1044. $cp1252_map = array(
  1045. '\xc2\x80' => '\xe2\x82\xac', /* EURO SIGN */
  1046. '\xc2\x82' => '\xe2\x80\x9a', /* SINGLE LOW-9 QUOTATION MARK */
  1047. '\xc2\x83' => '\xc6\x92', /* LATIN SMALL LETTER F WITH HOOK */
  1048. '\xc2\x84' => '\xe2\x80\x9e', /* DOUBLE LOW-9 QUOTATION MARK */
  1049. '\xc2\x85' => '\xe2\x80\xa6', /* HORIZONTAL ELLIPSIS */
  1050. '\xc2\x86' => '\xe2\x80\xa0', /* DAGGER */
  1051. '\xc2\x87' => '\xe2\x80\xa1', /* DOUBLE DAGGER */
  1052. '\xc2\x88' => '\xcb\x86', /* MODIFIER LETTER CIRCUMFLEX ACCENT */
  1053. '\xc2\x89' => '\xe2\x80\xb0', /* PER MILLE SIGN */
  1054. '\xc2\x8a' => '\xc5\xa0', /* LATIN CAPITAL LETTER S WITH CARON */
  1055. '\xc2\x8b' => '\xe2\x80\xb9', /* SINGLE LEFT-POINTING ANGLE QUOTATION */
  1056. '\xc2\x8c' => '\xc5\x92', /* LATIN CAPITAL LIGATURE OE */
  1057. '\xc2\x8e' => '\xc5\xbd', /* LATIN CAPITAL LETTER Z WITH CARON */
  1058. '\xc2\x91' => '\xe2\x80\x98', /* LEFT SINGLE QUOTATION MARK */
  1059. '\xc2\x92' => '\xe2\x80\x99', /* RIGHT SINGLE QUOTATION MARK */
  1060. '\xc2\x93' => '\xe2\x80\x9c', /* LEFT DOUBLE QUOTATION MARK */
  1061. '\xc2\x94' => '\xe2\x80\x9d', /* RIGHT DOUBLE QUOTATION MARK */
  1062. '\xc2\x95' => '\xe2\x80\xa2', /* BULLET */
  1063. '\xc2\x96' => '\xe2\x80\x93', /* EN DASH */
  1064. '\xc2\x97' => '\xe2\x80\x94', /* EM DASH */
  1065. '\xc2\x98' => '\xcb\x9c', /* SMALL TILDE */
  1066. '\xc2\x99' => '\xe2\x84\xa2', /* TRADE MARK SIGN */
  1067. '\xc2\x9a' => '\xc5\xa1', /* LATIN SMALL LETTER S WITH CARON */
  1068. '\xc2\x9b' => '\xe2\x80\xba', /* SINGLE RIGHT-POINTING ANGLE QUOTATION*/
  1069. '\xc2\x9c' => '\xc5\x93', /* LATIN SMALL LIGATURE OE */
  1070. '\xc2\x9e' => '\xc5\xbe', /* LATIN SMALL LETTER Z WITH CARON */
  1071. '\xc2\x9f' => '\xc5\xb8' /* LATIN CAPITAL LETTER Y WITH DIAERESIS*/
  1072. );
  1073. function tfu_seems_utf8($Str)
  1074. {
  1075. for ($i = 0; $i < strlen($Str); $i++) {
  1076. if (ord($Str[$i]) < 0x80) $n = 0; # 0bbbbbbb
  1077. elseif ((ord($Str[$i]) &0xE0) == 0xC0) $n = 1; # 110bbbbb
  1078. elseif ((ord($Str[$i]) &0xF0) == 0xE0) $n = 2; # 1110bbbb
  1079. elseif ((ord($Str[$i]) &0xF0) == 0xF0) $n = 3; # 1111bbbb
  1080. else return false; # Does not match any model
  1081. for ($j = 0; $j < $n; $j++) { // n octets that match 10bbbbbb follow ?
  1082. if ((++$i == strlen($Str)) || ((ord($Str[$i]) &0xC0) != 0x80)) return false;
  1083. }
  1084. }
  1085. return true;
  1086. }
  1087. function cp1252_to_utf8($str)
  1088. {
  1089. global $cp1252_map;
  1090. return strtr(utf8_encode($str), $cp1252_map);
  1091. }
  1092. function utf8_to_cp1252($str)
  1093. {
  1094. global $cp1252_map;
  1095. return utf8_decode(strtr($str, array_flip($cp1252_map)));
  1096. }
  1097. function getExtension($name)
  1098. {
  1099. $name = rtrim($name, ".,; \t\n\r\0\x0B");
  1100. return substr (strrchr ($name, '.'), 1);
  1101. }
  1102. function space_enc($string) {
  1103. global $description_mode;
  1104. if ($description_mode == 'true') { // - description is added at the end - we don't encode ' : ' and the rest.
  1105. $teile = explode(" : ", $string,2);
  1106. $teile[0] = str_replace(" ", "%20", $teile[0]);
  1107. $string = implode(" : ", $teile);
  1108. } else {
  1109. $string = str_replace(" ", "%20", $string);
  1110. }
  1111. return $string;
  1112. }
  1113. /**
  1114. * This does a nice character exchange with a random crypt key!
  1115. * If you need a 100% secure connection please use https!
  1116. */
  1117. function tfu_enc($str, $id, $length = false)
  1118. {
  1119. if ($length) {
  1120. $str = substr($str, 0, $length);
  1121. }
  1122. for ($i = 0; $i < strlen($id); $i++) {
  1123. if (ord($id{$i}) > 127) {
  1124. tfu_debug('The crypt key at position ' . $i . ' is not valid - please change the implementation.');
  1125. return $str;
  1126. }
  1127. }
  1128. $code = '';
  1129. $keylen = strlen($id);
  1130. for ($i = 0; $i < strlen($str); $i++) {
  1131. $code .= chr(ord($str{$i}) + ord($id{$i%$keylen}));
  1132. }
  1133. return utf8_encode($code);
  1134. }
  1135. function setSessionVariables()
  1136. {
  1137. global $folder, $user, $login;
  1138. // this settings are needed in the other php files too!
  1139. if ($login == 'true') {
  1140. $_SESSION['TFU_LOGIN'] = 'true';
  1141. if (!isset($_SESSION['TFU_USER'])) { // can be set by the Joomla wrapper and we don't overwrite it with a dummy value!
  1142. $_SESSION['TFU_USER'] = ($user != '' && $user != '__empty__') ? $user : $_SERVER['REMOTE_ADDR'];
  1143. }
  1144. } else {
  1145. unset($_SESSION['TFU_USER']);
  1146. }
  1147. $_SESSION['TFU_RN'] = parseInputParameter($_POST['twg_rn']);
  1148. $_SESSION['TFU_ROOT_DIR'] = $_SESSION['TFU_DIR'] = $folder;
  1149. store_temp_session();
  1150. }
  1151. /**
  1152. * All parameters a sent to the flash
  1153. * First I wanted to introduce a Config class but this is the only place where they
  1154. * have to be passed globaly - therefore no class is used now.
  1155. */
  1156. function sendConfigData()
  1157. {
  1158. global $login, $rn, $maxfilesize, $resize_show, $resize_data, $resize_label, $resize_default, $allowed_file_extensions;
  1159. global $forbidden_file_extensions, $show_delete, $enable_folder_browsing, $enable_folder_creation;
  1160. global $enable_folder_deletion, $enable_file_download, $keep_file_extension, $show_preview, $show_big_preview;
  1161. global $enable_file_rename, $enable_folder_rename, $enable_folder_move, $enable_file_copymove, $language_dropdown;
  1162. global $preview_textfile_extensions, $edit_textfile_extensions;
  1163. //, $maxfilesize_split;
  1164. // optional settings
  1165. global $reg_infos, $login_text, $relogin_text, $upload_file, $base_dir, $titel;
  1166. global $warning_setting, $hide_remote_view, $directory_file_limit, $remote_label;
  1167. global $preview_label, $show_full_url_for_selected_file, $upload_finished_js_url;
  1168. global $preview_select_js_url, $delete_js_url, $js_change_folder, $js_create_folder;
  1169. global $js_rename_folder, $js_delete_folder, $js_copymove, $queue_file_limit, $show_size;
  1170. global $queue_file_limit_size, $split_extension, $hide_help_button, $direct_download;
  1171. global $description_mode_show_default, $description_mode, $download_multiple_files_as_zip;
  1172. global $overwrite_files, $description_mode_mandatory, $post_upload_panel, $form_fields;
  1173. global $big_progressbar,$img_progressbar,$img_progressbar_back,$img_progressbar_anim, $big_server_view;
  1174. global $zip_file_pattern, $is_jfu_plugin, $has_post_processing, $directory_file_limit_size;
  1175. global $show_server_date_instead_size, $enable_file_creation, $enable_file_creation_extensions;
  1176. // the sessionid is mandatory because upload in flash and Firefox would create a new session otherwise - sessionhandled login would fail then!
  1177. $output = '&login=' . $login . '&maxfilesize=' . '' . $maxfilesize;
  1178. // $output .= '&maxfilesize_split=' . tfu_enc('' . $maxfilesize_split, $rn);
  1179. // $output .= '&maxfilesize_php=' . getMaximumUploadSize();
  1180. $output .= '&resize_show=' . $resize_show . '&resize_data=' . $resize_data;
  1181. $output .= '&resize_label=' . urlencode($resize_label) . '&resize_default=' . $resize_default;
  1182. $output .= '&allowed_file_extensions=' . $allowed_file_extensions . '&forbidden_file_extensions=' . $forbidden_file_extensions;
  1183. $output .= '&show_delete=' . $show_delete . '&enable_folder_browsing=' . $enable_folder_browsing;
  1184. $output .= '&enable_folder_creation=' . $enable_folder_creation . '&enable_folder_deletion=' . $enable_folder_deletion ;
  1185. $output .= '&enable_file_download=' . $enable_file_download . '&keep_file_extension=' . $keep_file_extension;
  1186. $output .= '&show_preview=' . $show_preview . '&show_big_preview=' . $show_big_preview ;
  1187. $output .= '&enable_file_rename=' . $enable_file_rename . '&enable_folder_rename=' . $enable_folder_rename;
  1188. $output .= '&enable_folder_copy=' . $enable_folder_move . '&enable_file_copy=' . $enable_file_copymove;
  1189. $output .= '&language_dropdown=' . $language_dropdown;
  1190. $output .= '&preview_textfile_extensions=' . $preview_textfile_extensions . '&edit_textfile_extensions=' . $edit_textfile_extensions;
  1191. // optional settings
  1192. $output .= $reg_infos . '&login_text=' . $login_text;
  1193. $output .= '&relogin_text=' . $relogin_text . '&upload_file=' . $upload_file;
  1194. $output .= '&base_dir=' . $base_dir . '&titel=' . urlencode($titel);
  1195. $output .= '&warning_setting=' . $warning_setting . '&hide_remote_view=' . $hide_remote_view;
  1196. $output .= '&directory_file_limit=' . $directory_file_limit;
  1197. $output .= '&remote_label=' . urlencode($remote_label) . '&preview_label=' . $preview_label;
  1198. $output .= '&show_full_url_for_selected_file=' . $show_full_url_for_selected_file;
  1199. $output .= '&upload_finished_js_url=' . urlencode($upload_finished_js_url) . '&preview_select_js_url=' . urlencode($preview_select_js_url);
  1200. $output .= '&delete_js_url=' . urlencode($delete_js_url) . '&js_change_folder=' . urlencode($js_change_folder);
  1201. $output .= '&js_create_folder=' . urlencode($js_create_folder) . '&js_rename_folder=' . urlencode($js_rename_folder);
  1202. $output .= '&js_delete_folder=' . urlencode($js_delete_folder) . '&js_copymove=' . urlencode($js_copymove);
  1203. $output .= '&queue_file_limit=' . $queue_file_limit . '&queue_file_limit_size=' . $queue_file_limit_size;
  1204. $output .= '&split_extension=' . $split_extension . '&hide_help_button=' . $hide_help_button;
  1205. $output .= '&direct_download=' . $direct_download . '&show_size=' . $show_size;
  1206. $output .= '&description_mode=' . $description_mode . '&description_mode_show_default=' . $description_mode_show_default;
  1207. $output .= '&multiple_zip_download=' . $download_multiple_files_as_zip;
  1208. $output .= '&overwrite_files=' . $overwrit

Large files files are truncated, but you can click here to view the full file