PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/KljUploader.php

https://github.com/phpfalcon/Kleeja-2.0.0-alpha
PHP | 845 lines | 596 code | 118 blank | 131 comment | 124 complexity | 28d87ca1b370f0224d765d920e4b393f MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. *
  4. * @package Kleeja
  5. * @version $Id$
  6. * @copyright (c) 2007 Kleeja.com
  7. * @license ./docs/license.txt
  8. *
  9. */
  10. //no for directly open
  11. if (!defined('IN_COMMON'))
  12. {
  13. exit();
  14. }
  15. class KljUploader
  16. {
  17. var $folder;
  18. var $action; //page action
  19. var $filesnum; //number of fields
  20. var $types; // filetypes
  21. var $ansaqimages; // imagestypes
  22. var $filename; // filename
  23. var $total = 0; //total files
  24. //var $sizes;
  25. var $typet;
  26. var $sizet;
  27. var $id_for_url;
  28. var $name_for_url;
  29. var $filename2; //alternative file name
  30. var $linksite; //site link
  31. var $decode; // decoding name with md5 or time or no
  32. var $id_user;
  33. var $errs = array();
  34. var $safe_code; // captcha is on or off
  35. var $user_is_adm; //check if user is administrator
  36. /**
  37. // watermark
  38. // source : php.net
  39. */
  40. function watermark($name, $ext)
  41. {
  42. ($hook = kleeja_run_hook('watermark_func_kljuploader')) ? eval($hook) : null; //run hook
  43. if(!file_exists($name))
  44. {
  45. return;
  46. }
  47. if (strpos($ext, 'jp') !== false)
  48. {
  49. $src_img = @imagecreatefromjpeg($name);
  50. }
  51. elseif (strpos($ext, 'png') !== false)
  52. {
  53. $src_img = @imagecreatefrompng($name);
  54. }
  55. #todo : try to use some avilable php library to make gif thumb
  56. elseif (strpos($ext, 'gif') !== false)
  57. {
  58. $src_img = @imagecreatefromgif($name);
  59. }
  60. else
  61. {
  62. return;
  63. }
  64. if(file_exists('images/watermark.gif'))
  65. {
  66. $src_logo = imagecreatefromgif('images/watermark.gif');
  67. }
  68. elseif(file_exists('images/watermark.png'))
  69. {
  70. $src_logo = imagecreatefrompng('images/watermark.png');
  71. }
  72. $bwidth = @imageSX($src_img);
  73. $bheight = @imageSY($src_img);
  74. $lwidth = @imageSX($src_logo);
  75. $lheight = @imageSY($src_logo);
  76. //fix bug for 1beta3
  77. if ($bwidth > 160 && $bheight > 130)
  78. {
  79. $src_x = $bwidth - ($lwidth + 5);
  80. $src_y = $bheight - ($lheight + 5);
  81. @ImageAlphaBlending($src_img, true);
  82. @ImageCopy($src_img,$src_logo,$src_x,$src_y,0,0,$lwidth,$lheight);
  83. if (strpos($ext, 'jp') !== false)
  84. {
  85. @imagejpeg($src_img, $name);
  86. }
  87. elseif (strpos($ext, 'png') !== false)
  88. {
  89. @imagepng($src_img, $name);
  90. }
  91. elseif (strpos($ext, 'gif') !== false)
  92. {
  93. @imagegif($src_img, $name);
  94. }
  95. }# < 150
  96. else
  97. {
  98. return false;
  99. }
  100. }
  101. //
  102. //check for gif image is animated or not !
  103. //(c) http://us2.php.net/manual/en/function.imagecreatefromgif.php#88005
  104. // todo: need more and more improvments
  105. //
  106. function is_ani($filename)
  107. {
  108. return (bool)preg_match('#(\x00\x21\xF9\x04.{4}\x00\x2C.*){2,}#s', file_get_contents($filename));
  109. }
  110. //
  111. //check exts inside file to be safe
  112. //
  113. function ext_check_safe ($filename)
  114. {
  115. $not_allowed = array('php', 'php3' ,'php5', 'php4', 'asp' ,'shtml' , 'html' ,'htm' ,'xhtml' ,'phtml', 'pl', 'cgi', 'htaccess', 'ini');
  116. $tmp = explode(".", $filename);
  117. $before_last_ext = $tmp[sizeof($tmp)-2];
  118. if (in_array(strtolower($before_last_ext), $not_allowed))
  119. {
  120. return false;
  121. }
  122. else
  123. {
  124. return true;
  125. }
  126. }
  127. /*
  128. Function createthumb($name,$filename,$new_w,$new_h)
  129. example : createthumb('pics/apple.jpg','thumbs/tn_apple.jpg',100,100);
  130. creates a resized image
  131. source :http://icant.co.uk/articles/phpthumbnails/
  132. */
  133. function createthumb($name, $ext, $filename, $new_w, $new_h)
  134. {
  135. ($hook = kleeja_run_hook('createthumb_func_kljuploader')) ? eval($hook) : null; //run hook
  136. if(!file_exists($name))
  137. {
  138. return;
  139. }
  140. if (strpos($ext, 'jp') !== false)
  141. {
  142. $src_img = @imagecreatefromjpeg($name);
  143. }
  144. elseif (strpos($ext, 'png') !== false)
  145. {
  146. $src_img = @imagecreatefrompng($name);
  147. }
  148. #todo : try to use some avilable php library to make gif thumb
  149. elseif (strpos($ext, 'gif') !== false)
  150. {
  151. $src_img = @imagecreatefromgif($name);
  152. }
  153. else
  154. {
  155. return;
  156. }
  157. $old_x = @imageSX($src_img);
  158. $old_y = @imageSY($src_img);
  159. if ($old_x > $old_y)
  160. {
  161. $thumb_w=$new_w;
  162. $thumb_h=$old_y*($new_h/$old_x);
  163. }
  164. elseif ($old_x < $old_y)
  165. {
  166. $thumb_w=$old_x*($new_w/$old_y);
  167. $thumb_h=$new_h;
  168. }
  169. elseif ($old_x == $old_y)
  170. {
  171. $thumb_w=$new_w;
  172. $thumb_h=$new_h;
  173. }
  174. $dst_img = @ImageCreateTrueColor($thumb_w, $thumb_h);
  175. @imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
  176. if (strpos($ext, 'jp') !== false)
  177. {
  178. @imagejpeg($dst_img, $filename);
  179. }
  180. elseif (strpos($ext, 'png') !== false)
  181. {
  182. @imagepng($dst_img, $filename);
  183. }
  184. elseif (strpos($ext, 'gif') !== false)
  185. {
  186. @imagegif($dst_img, $filename);
  187. }
  188. @imagedestroy($dst_img);
  189. @imagedestroy($src_img);
  190. }
  191. //
  192. // prorcess
  193. //
  194. function process ()
  195. {
  196. global $SQL,$dbprefix,$config,$lang;
  197. global $use_ftp,$ftp_server,$ftp_user,$ftp_pass,$ch;
  198. ($hook = kleeja_run_hook('start_process_kljuploader')) ? eval($hook) : null; //run hook
  199. //check prefix
  200. if (preg_match("/{rand:([0-9]+)}/i", $this->filename, $m))
  201. {
  202. $this->filename = preg_replace("/{rand:([0-9]+)}/i", substr(md5(time()), 0, $m[1]), $this->filename);
  203. }
  204. if (preg_match("/{date:([a-zA-Z-_]+)}/i", $this->filename, $m))
  205. {
  206. $this->filename = preg_replace("/{date:([a-zA-Z-_]+)}/i", date($m[1]), $this->filename);
  207. }
  208. ($hook = kleeja_run_hook('no_folder_check_kljuploader')) ? eval($hook) : null; //run hook
  209. // check folder
  210. if(!file_exists($this->folder))
  211. {
  212. ($hook = kleeja_run_hook('no_uploadfolder_kljuploader')) ? eval($hook) : null; //run hook
  213. $jadid = mkdir($this->folder);
  214. $jadid2 = mkdir($this->folder . '/thumbs');
  215. if($jadid)
  216. {
  217. $this->errs[] = array($lang['NEW_DIR_CRT'], 'index_info');
  218. $htaccess_data = "<Files ~ \"^.*\.(php|php*|cgi|pl|phtml|shtml|sql|asp|aspx)\">\nOrder allow,deny\nDeny from all\n</Files>\n<IfModule mod_php4.c>\nphp_flag engine off\n</IfModule>\n<IfModule mod_php5.c>\nphp_flag engine off\n</IfModule>\nRemoveType .php .php* .phtml .pl .cgi .asp .aspx .sql";
  219. $fo = @fopen($this->folder . "/index.html","w");
  220. $fo2 = @fopen($this->folder . "/thumbs/index.html","w");
  221. $fw = @fwrite($fo,'<a href="http://kleeja.com"><p>KLEEJA ..</p></a>');
  222. $fw2 = @fwrite($fo2,'<a href="http://kleeja.com"><p>KLEEJA ..</p></a>');
  223. $fi = @fopen($this->folder . "/.htaccess", "w");
  224. $fi2 = @fopen($this->folder . "/thumbs/.htaccess","w");
  225. $fy = @fwrite($fi, $htaccess_data);
  226. $fy2 = @fwrite($fi2, $htaccess_data);
  227. $chmod = @chmod($this->folder, 0777);
  228. $chmod2 = @chmod($this->folder . '/thumbs/', 0777);
  229. if(!$chmod)
  230. {
  231. $this->errs[] = array($lang['PR_DIR_CRT'], 'index_err');
  232. }
  233. }
  234. else
  235. {
  236. $this->errs[] = array($lang['CANT_DIR_CRT'], 'index_err');
  237. }
  238. }
  239. //then wut did u click
  240. $wut = false;
  241. //clicked, _file uploading
  242. if (isset($_POST['submitr']))
  243. {
  244. $wut = 1;
  245. }
  246. //clicked ,urls uloading
  247. elseif(isset($_POST['submittxt']))
  248. {
  249. $wut = 2;
  250. }
  251. //add your clicked actions
  252. ($hook = kleeja_run_hook('another_wut_kljuploader')) ? eval($hook) : null; //run hook
  253. if(!$wut)
  254. {
  255. //no uploading yet, or just go to index.php, so we have make a new session
  256. unset($_SESSION['FIILES_NOT_DUPLI'], $_SESSION['FIILES_NOT_DUPLI_LINKS']);
  257. }
  258. //safe_code .. captcha is on
  259. if($this->safe_code && $wut)
  260. {
  261. if(!kleeja_check_captcha())
  262. {
  263. ($hook = kleeja_run_hook('wrong_captcha_kljuploader_w1')) ? eval($hook) : null; //run hook
  264. return $this->errs[] = array($lang['WRONG_VERTY_CODE'], 'index_err');
  265. }
  266. }
  267. if(!$this->user_is_adm && $this->user_is_flooding())
  268. {
  269. return $this->errs[] = array(sprintf($lang['YOU_HAVE_TO_WAIT'], ($this->id_user == '-1') ? $config['guestsectoupload'] : $config['usersectoupload']), 'index_err');
  270. }
  271. if ($wut == 1 && isset($_SESSION['FIILES_NOT_DUPLI']))
  272. {
  273. for($i=0;$i<=$this->filesnum;$i++)
  274. {
  275. if((!empty($_SESSION['FIILES_NOT_DUPLI']['file_' . $i . '_']['name']) && !empty($_FILES['file_' . $i . '_']['name'])) && ($_SESSION['FIILES_NOT_DUPLI']['file_' . $i . '_']['name'] == $_FILES['file_' . $i . '_']['name']))
  276. {
  277. redirect('./');
  278. //return $this->errs[] = array($lang['NO_REPEATING_UPLOADING'], 'index_err');
  279. }
  280. }
  281. }
  282. if ($wut == 2 && isset($_SESSION['FIILES_NOT_DUPLI_LINKS']))
  283. {
  284. for($i=0;$i<=$this->filesnum;$i++)
  285. {
  286. if((!empty($_SESSION['FIILES_NOT_DUPLI_LINKS']['file_' . $i . '_']) && !empty($_POST['file_' . $i . '_']) && trim($_POST['file_' . $i . '_']) != $lang['PAST_URL_HERE'] && trim($_SESSION['FIILES_NOT_DUPLI_LINKS']['file_' . $i . '_']) != $lang['PAST_URL_HERE']) && ($_SESSION['FIILES_NOT_DUPLI_LINKS']['file_' . $i . '_']) == ($_POST['file_' . $i . '_']))
  287. {
  288. redirect('./');
  289. //return $this->errs[] = array($lang['NO_REPEATING_UPLOADING'], 'index_err');
  290. }
  291. }
  292. }
  293. // uploading process
  294. $check = false;
  295. //add your hook here, if wut == 'my_action' ...
  296. ($hook = kleeja_run_hook('wuts_processes_kljuploader')) ? eval($hook) : null; //run hook
  297. if ($wut == 1)
  298. {
  299. ($hook = kleeja_run_hook('submit_filesupload_kljuploader')) ? eval($hook) : null; //run hook
  300. for($i=0;$i<=$this->filesnum;$i++)
  301. {
  302. $check .= isset($_FILES['file_' . $i . '_']['name']) ? $_FILES['file_' . $i . '_']['name'] : '';
  303. $this->filename2 = @explode(".", $_FILES['file_' . $i . '_']['name']);
  304. $this->filename2 = strtolower($this->filename2[sizeof($this->filename2)-1]);
  305. $this->typet = $this->filename2;
  306. $this->sizet = !empty($_FILES['file_' . $i . '_']['size']) ? $_FILES['file_' . $i . '_']['size'] : null;
  307. ($hook = kleeja_run_hook('for_wut1_filesupload_kljuploader')) ? eval($hook) : null; //run hook
  308. // decoding
  309. if($this->decode == "time")
  310. {
  311. $zaid = time();
  312. $this->filename2 = $this->filename . $zaid . $i . "." . $this->filename2;
  313. }
  314. elseif($this->decode == "md5")
  315. {
  316. $zaid = md5(time());
  317. $zaid = substr($zaid, 0, 10);
  318. $this->filename2 = $this->filename . $zaid . $i . "." . $this->filename2;
  319. }
  320. else
  321. {
  322. //real name of file
  323. $filename = substr(@$_FILES['file_' . $i . '_']['name'], 0, -strlen($this->typet)-1);
  324. $this->filename2 = $this->filename . preg_replace('/[,.?\/*&^\\\$%#@()_!|"\~\'><=+}{; ]/', '-', $filename) . '.' . $this->typet;
  325. $this->filename2 = preg_replace('/-+/', '-', $this->filename2);
  326. ($hook = kleeja_run_hook('another_decode_type_kljuploader')) ? eval($hook) : null; //run hook
  327. }
  328. if(empty($_FILES['file_' . $i . '_']['tmp_name']))
  329. {
  330. //if no file ? natin to do ,, why ? becuase its multiple fields
  331. }
  332. elseif(file_exists($this->folder . '/' . $this->filename2))
  333. {
  334. $this->errs[] = array(sprintf($lang['SAME_FILE_EXIST'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err');
  335. }
  336. elseif(preg_match ("#[\\\/\:\*\?\<\>\|\"]#", $this->filename2))
  337. {
  338. $this->errs[] = array(sprintf($lang['WRONG_F_NAME'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err');
  339. }
  340. elseif($this->ext_check_safe($_FILES['file_' . $i . '_']['name']) == false)
  341. {
  342. $this->errs[] = array(sprintf($lang['WRONG_F_NAME'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err');
  343. }
  344. elseif(!in_array(strtolower($this->typet), array_keys($this->types)))
  345. {
  346. //guest
  347. if($this->id_user == '-1')
  348. {
  349. $this->errs[] = array(sprintf($lang['FORBID_EXT'], $this->typet) . '<br /> <a href="' . ($config['mod_writer'] ? "register.html" : "ucp.php?go=register") . '" title="' . htmlspecialchars($lang['REGISTER']) . '">' . $lang['REGISTER'] . '</a>', 'index_err');
  350. }
  351. //not guest
  352. else
  353. {
  354. $this->errs[] = array(sprintf($lang['FORBID_EXT'], $this->typet), 'index_err');
  355. }
  356. }
  357. elseif(kleeja_check_mime($_FILES['file_' . $i . '_']['type'], $this->types[strtolower($this->typet)]['group_id'], $_FILES['file_' . $i . '_']['tmp_name']) == false)
  358. {
  359. $this->errs[] = array(sprintf($lang['NOT_SAFE_FILE'], htmlspecialchars($_FILES['file_' . $i . '_']['name'])), 'index_err');
  360. }
  361. elseif($this->types[strtolower($this->typet)]['size'] > 0 && $this->sizet >= $this->types[strtolower($this->typet)]['size'])
  362. {
  363. $this->errs[] = array(sprintf($lang['SIZE_F_BIG'], htmlspecialchars($_FILES['file_' . $i . '_']['name']), Customfile_size($this->types[strtolower($this->typet)]['size'])), 'index_err');
  364. }
  365. else
  366. {
  367. //
  368. // no errors , so uploading
  369. //
  370. //if (!$use_ftp)
  371. //{
  372. ($hook = kleeja_run_hook('move_uploaded_file_kljuploader')) ? eval($hook) : null; //run hook
  373. $file = move_uploaded_file($_FILES['file_' . $i . '_']['tmp_name'], $this->folder . "/" . $this->filename2);
  374. /*}
  375. else // use ftp account
  376. {
  377. ($hook = kleeja_run_hook('ftp_connect_kljuploader')) ? eval($hook) : null; //run hook
  378. // set up a connection or die
  379. $conn_id = ftp_connect($ftp_server);
  380. // Login with username and password
  381. $login_result = ftp_login($conn_id, $ftp_user, $ftp_pass);
  382. ftp_pasv($conn_id,false);
  383. // Check the connection
  384. if ((!$conn_id) || (!$login_result))
  385. {
  386. $this->errs[]= array($lang['CANT_CON_FTP'] . $ftp_server, 'index_err');
  387. }
  388. //ftp method
  389. if (in_array(strtolower($this->typet), array('png','gif','jpg','jpeg','tif','tiff')))
  390. {
  391. $ftp_method = FTP_BINARY;
  392. }
  393. else
  394. {
  395. $ftp_method = FTP_ASCII;
  396. }
  397. // Upload the file
  398. $file = ftp_put($conn_id, $this->folder . "/" . $this->filename2, $_FILES['file_' . $i . '_']['tmp_name'], $ftp_method);
  399. ftp_close($conn_id);
  400. }*/
  401. if ($file)
  402. {
  403. $this->saveit ($this->filename2, $this->folder, $this->sizet, $this->typet, $_FILES['file_' . $i . '_']['name']);
  404. }
  405. else
  406. {
  407. $this->errs[] = array(sprintf($lang['CANT_UPLAOD'], $this->filename2), 'index_err');
  408. }
  409. }
  410. }#for ... lmean loop
  411. if(!isset($check) || empty($check))
  412. {
  413. $this->errs[] = array($lang['CHOSE_F'], 'index_err');
  414. }
  415. }#wut=1
  416. elseif ($wut == 2 && $config['www_url'] == '1')
  417. {
  418. ($hook = kleeja_run_hook('submit_urlupload_kljuploader')) ? eval($hook) : null; //run hook
  419. //looop text inputs
  420. for($i=0;$i<$this->filesnum;$i++)
  421. {
  422. $check .= (isset($_POST['file_' . $i . '_']) && trim($_POST['file_' . $i . '_']) != $lang['PAST_URL_HERE']) ? $_POST['file_' . $i . '_'] : '';
  423. $filename = (isset($_POST['file_' . $i . '_'])) ? basename($_POST['file_' . $i . '_']) : '';
  424. $this->filename2 = explode(".", $filename);
  425. ($hook = kleeja_run_hook('for_wut2_filesupload_kljuploader')) ? eval($hook) : null; //run hook
  426. if(in_array($this->filename2[count($this->filename2)-1], array('html', 'php', 'html')))
  427. {
  428. $this->filename2 = $this->typet = strtolower($this->filename2[count($this->filename2)-2]);
  429. }
  430. else
  431. {
  432. $this->filename2 = $this->typet = strtolower($this->filename2[count($this->filename2)-1]);
  433. }
  434. //transfer [decode]
  435. if($this->decode == "time")
  436. {
  437. $zaid = time();
  438. $this->filename2 = $this->filename . $zaid . $i . "." . $this->filename2;
  439. }
  440. elseif($this->decode == "md5")
  441. {
  442. $zaid=md5(time());
  443. $zaid=substr($zaid, 0, 10);
  444. $this->filename2 = $this->filename . $zaid . $i . "." . $this->filename2;
  445. }
  446. else
  447. {
  448. // real name of file
  449. $this->filename2 = $this->filename . preg_replace('/[,.?\/*&^\\\$%#@()_!|"\~\'><=+}{; ]/', '-', $filename) . '.' . $this->typet;
  450. $this->filename2 = preg_replace('/-+/', '-', $this->filename2);
  451. ($hook = kleeja_run_hook('another_decode_type_kljuploader')) ? eval($hook) : null; //run hook
  452. }
  453. //end tashfer
  454. if(empty($_POST['file_' . $i . '_']) || trim($_POST['file_' . $i . '_']) == $lang['PAST_URL_HERE'])
  455. {
  456. //nathin
  457. }
  458. else//big else
  459. {
  460. if(file_exists($this->folder . '/' . $filename))
  461. {
  462. $this->errs[] = array(sprintf($lang['SAME_FILE_EXIST'], htmlspecialchars($_POST['file_' . $i . '_'])), 'index_err');
  463. }
  464. //elseif( preg_match ("#[\\\/\:\*\?\<\>\|\"]#", $this->filename2))
  465. //{
  466. // $this->errs[] = array(sprintf($lang['WRONG_F_NAME'], htmlspecialchars($_POST['file_' . $i . '_'])), 'index_err');
  467. //}
  468. //elseif($this->ext_check_safe($_POST['file_' . $i . '_']) == false)
  469. //{
  470. // $this->errs[] = array(sprintf($lang['WRONG_F_NAME'], htmlspecialchars($_POST['file_' . $i . '_'])), 'index_err');
  471. //}
  472. //elseif(kleeja_check_mime($_POST['file_' . $i . '_'], $this->types[strtolower($this->typet)]['group_id'], $_FILES['file_' . $i . '_']['tmp_name']) == false)
  473. //{
  474. // $this->errs[] = array(sprintf($lang['FORBID_EXT'], htmlspecialchars($_POST['file_' . $i . '_'])), 'index_err');
  475. //}
  476. elseif(!in_array(strtolower($this->typet),array_keys($this->types)))
  477. {
  478. $this->errs[] = array(sprintf($lang['FORBID_EXT'], htmlspecialchars($_POST['file_' . $i . '_']), $this->typet), 'index_err');
  479. }
  480. else
  481. {
  482. ($hook = kleeja_run_hook('start_upload_wut2_kljuploader')) ? eval($hook) : null; //run hook
  483. //
  484. //end err .. start upload from url
  485. //
  486. if(!in_array(substr($_POST['file_' . $i . '_'], 0, 4), array('http', 'ftp:')))
  487. {
  488. $_POST['file_' . $i . '_'] = 'http://' . $_POST['file_' . $i . '_'];
  489. }
  490. if(function_exists("curl_init"))
  491. {
  492. $data = fetch_remote_file($_POST['file_' . $i . '_']);
  493. if($data != false)
  494. {
  495. $this->sizet = strlen($data);
  496. if($this->types[strtolower($this->typet)]['size'] > 0 && $this->sizet >= $this->types[strtolower($this->typet)]['size'])
  497. {
  498. $this->errs[] = array(sprintf($lang['SIZE_F_BIG'], htmlspecialchars($_POST['file_' . $i . '_']), Customfile_size($this->types[strtolower($this->typet)]['size'])), 'index_err');
  499. }
  500. else
  501. {
  502. //then ..write new file
  503. $fp2 = @fopen($this->folder . "/" . $this->filename2, "w");
  504. @fwrite($fp2, $data);
  505. @fclose($fp2);
  506. $this->saveit ($this->filename2, $this->folder, $this->sizet, $this->typet);
  507. }
  508. }
  509. else
  510. {
  511. $this->errs[] = array($lang['URL_CANT_GET'], 'index_err');
  512. }
  513. }
  514. else //OTHER FUNCTION
  515. {
  516. $this->sizet = $this->get_remote_file_size($_POST['file_' . $i . '_']);
  517. if($this->types[strtolower($this->typet)]['size'] > 0 && $this->sizet >= $this->types[strtolower($this->typet)]['size'])
  518. {
  519. $this->errs[] = array(sprintf($lang['SIZE_F_BIG'], htmlspecialchars($_POST['file_' . $i . '_']), Customfile_size($this->types[strtolower($this->typet)]['size'])), 'index_err');
  520. }
  521. else
  522. {
  523. $data = fetch_remote_file($_POST['file_' . $i . '_'], $this->folder . "/" . $this->filename2);
  524. if($data === false)
  525. {
  526. $this->errs[] = array($lang['URL_CANT_GET'], 'index_err');
  527. }
  528. else
  529. {
  530. $this->saveit ($this->filename2, $this->folder, $this->sizet, $this->typet);
  531. }
  532. }
  533. }
  534. }#else
  535. }//big else
  536. }#end loop
  537. if(!isset($check) || empty($check))
  538. {
  539. $this->errs[] = array($lang['CHOSE_F'], 'index_err');
  540. }
  541. }#end wut2
  542. }#END process
  543. //
  544. // save data and insert in the database
  545. //
  546. function saveit ($filname, $folderee, $sizeee, $typeee, $real_filename = '')
  547. {
  548. global $SQL, $dbprefix, $config, $lang;
  549. // sometime cant see file after uploading.. but ..
  550. @chmod($folderee . '/' . $filname , 0644); //0644
  551. $name = (string) $SQL->escape($filname);
  552. $size = (int) $sizeee;
  553. $type = (string) strtolower($SQL->escape($typeee));
  554. $folder = (string) $SQL->escape($folderee);
  555. $timeww = (int) time();
  556. $user = (int) $this->id_user;
  557. $code_del=(string) md5(time());
  558. $ip = get_ip();
  559. $realf = (string) $SQL->escape($real_filename);
  560. $insert_query = array(
  561. 'INSERT' => '`name` ,`size` ,`time` ,`folder` ,`type`,`user`,`code_del`,`user_ip`, `real_filename`',
  562. 'INTO' => "`{$dbprefix}files`",
  563. 'VALUES' => "'$name', '$size', '$timeww', '$folder','$type', '$user', '$code_del', '$ip', '$realf'"
  564. );
  565. ($hook = kleeja_run_hook('qr_insert_new_file_kljuploader')) ? eval($hook) : null; //run hook
  566. $SQL->build($insert_query);
  567. $this->name_for_url = $name;
  568. $this->id_for_url = $SQL->insert_id();
  569. //calculate stats ..s
  570. $update_query = array(
  571. 'UPDATE' => "{$dbprefix}stats",
  572. 'SET' => "`files`=files+1,`sizes`=sizes+" . $size . ",`last_file`='" . $folder . "/" . $name . "'"
  573. );
  574. ($hook = kleeja_run_hook('qr_update_no_files_kljuploader')) ? eval($hook) : null; //run hook
  575. $SQL->build($update_query);
  576. //delete cache of stats !
  577. delete_cache('data_stats');
  578. //inforantion of file
  579. $file_info = array('::ID::'=>$this->id_for_url, '::NAME::'=>$this->name_for_url, '::DIR::'=> $folderee, '::FNAME::'=>$realf);
  580. //show del code link
  581. $extra_del = '';
  582. if ($config['del_url_file'])
  583. {
  584. $extra_del = get_up_tpl_box('del_file_code', array('b_title'=> $lang['URL_F_DEL'], 'b_code_link'=> kleeja_get_link('del', array('::CODE::'=>$code_del))));
  585. }
  586. //show imgs
  587. if (in_array(strtolower($this->typet), array('png','gif','jpg','jpeg','tif','tiff')))
  588. {
  589. //make thumbs
  590. $img_html_result = '';
  591. if( ($config['thumbs_imgs'] != 0) && in_array(strtolower($this->typet), array('png','jpg','jpeg','gif')))
  592. {
  593. list($thmb_dim_w, $thmb_dim_h) = @explode('*', $config['thmb_dims']);
  594. $this->createthumb($folderee . '/' . $filname, strtolower($this->typet), $folderee . '/thumbs/' . $filname, $thmb_dim_w, $thmb_dim_h);
  595. $img_html_result .= get_up_tpl_box('image_thumb', array(
  596. 'b_title' => $lang['URL_F_THMB'],
  597. 'b_url_link'=> kleeja_get_link('image', $file_info),
  598. 'b_img_link'=> kleeja_get_link('thumb', $file_info)
  599. ));
  600. }
  601. //write on image
  602. if( ($config['write_imgs'] != 0) && in_array(strtolower($this->typet), array('gif', 'png', 'jpg', 'jpeg')))
  603. {
  604. $this->watermark($folderee . "/" . $filname,strtolower($this->typet));
  605. }
  606. //then show
  607. $img_html_result .= get_up_tpl_box('image', array(
  608. 'b_title' => $lang['URL_F_IMG'],
  609. 'b_bbc_title'=> $lang['URL_F_BBC'],
  610. 'b_url_link'=> kleeja_get_link('image', $file_info),
  611. ));
  612. $img_html_result .= $extra_del;
  613. ($hook = kleeja_run_hook('saveit_func_img_res_kljuploader')) ? eval($hook) : null; //run hook
  614. $this->total++;
  615. $this->errs[] = array($lang['IMG_DOWNLAODED'] . '<br />' . $img_html_result, 'index_info');
  616. }
  617. else
  618. {
  619. //then show other files
  620. $else_html_result = get_up_tpl_box('file', array(
  621. 'b_title' => $lang['URL_F_FILE'],
  622. 'b_bbc_title'=> $lang['URL_F_BBC'],
  623. 'b_url_link'=> kleeja_get_link('file', $file_info),
  624. ));
  625. $else_html_result .= $extra_del;
  626. ($hook = kleeja_run_hook('saveit_func_else_res_kljuploader')) ? eval($hook) : null; //run hook
  627. $this->total++;
  628. $this->errs[] = array($lang['FILE_DOWNLAODED'] . '<br />' . $else_html_result, 'index_info');
  629. }
  630. ($hook = kleeja_run_hook('saveit_func_kljuploader')) ? eval($hook) : null; //run hook
  631. if (isset($_POST['submitr']))
  632. {
  633. if(isset($_SESSION['FIILES_NOT_DUPLI']))
  634. {
  635. unset($_SESSION['FIILES_NOT_DUPLI']);
  636. }
  637. $_SESSION['FIILES_NOT_DUPLI'] = $_FILES;
  638. }
  639. elseif(isset($_POST['submittxt']))
  640. {
  641. if(isset($_SESSION['FIILES_NOT_DUPLI_LINKS']))
  642. {
  643. unset($_SESSION['FIILES_NOT_DUPLI_LINKS']);
  644. }
  645. $_SESSION['FIILES_NOT_DUPLI_LINKS'] = $_POST;
  646. }
  647. unset ($filename, $folderee, $sizeee, $typeee);
  648. //unset ($_SESSION['NO_UPLOADING_YET']);
  649. }#save it
  650. //
  651. //get file size
  652. //source : http://nopaste.planerd.net/1139
  653. function get_remote_file_size($url, $method = "GET", $data = "", $redirect = 10)
  654. {
  655. $url = parse_url($url);
  656. $fp = @fsockopen ($url['host'], (!empty($url['port']) ? (int)$url['port'] : 80), $errno, $errstr, 30);
  657. if ($fp)
  658. {
  659. $path = (!empty($url['path']) ? $url['path'] : "/").(!empty($url['query']) ? "?" . $url['query'] : "");
  660. $header = "\r\nHost: ".$url['host'];
  661. if("post" == strtolower($method))
  662. {
  663. $header .= "\r\nContent-Length: " . strlen($data);
  664. }
  665. fputs ($fp, $method." ".$path." HTTP/1.0" . $header . "\r\n\r\n". ("post" == strtolower($method) ? $data : ""));
  666. if(!feof($fp))
  667. {
  668. $scheme = fgets($fp);
  669. list(, $code ) = explode(" ", $scheme);
  670. $headers = array("Scheme" => $scheme);
  671. }
  672. while ( !feof($fp) )
  673. {
  674. $h = fgets($fp);
  675. if($h == "\r\n" OR $h == "\n") break;
  676. list($key, $value) = explode(":", $h, 2);
  677. $headers[$key] = trim($value);
  678. if($code >= 300 AND $code < 400 AND strtolower($key) == "location" AND $redirect > 0)
  679. {
  680. return $this->get_remote_file_size($headers[$key], $method, $data, --$redirect);
  681. }
  682. }
  683. $body = "";
  684. /*while ( !feof($fp) ) $body .= fgets($fp);*/
  685. fclose($fp);
  686. }
  687. else
  688. {
  689. return (array("error" => array("errno" => $errno, "errstr" => $errstr)));
  690. }
  691. return (string) $headers["Content-Length"];
  692. }
  693. //prevent flooding
  694. function user_is_flooding()
  695. {
  696. global $SQL, $dbprefix, $config;
  697. $return = 'empty';
  698. ($hook = kleeja_run_hook('user_is_flooding_func_kljuploader')) ? eval($hook) : null; //run
  699. if($return != 'empty')
  700. {
  701. return $return;
  702. }
  703. //if the value is zero (means that the function is disabled) then return false immediately
  704. if(($this->id_user == '-1' && $config['guestsectoupload'] == 0) OR $this->id_user != '-1' && $config['usersectoupload'] == 0)
  705. {
  706. return false;
  707. }
  708. //In my point of view I see 30 seconds is not bad rate to stop flooding ..
  709. //even though this minimum rate sometime isn't enough to protect Kleeja from flooding attacks
  710. $time = time() - (($this->id_user == '-1') ? $config['guestsectoupload'] : $config['usersectoupload']);
  711. $query = array(
  712. 'SELECT' => 'f.time',
  713. 'FROM' => "{$dbprefix}files f",
  714. 'WHERE' => 'f.time >= \'' . $time . '\' AND f.user_ip = \'' . get_ip() . '\'',
  715. );
  716. if ($SQL->num_rows($SQL->build($query)) != 0)
  717. {
  718. return true;
  719. }
  720. return false;
  721. }
  722. }#end class
  723. //<-- EOF