PageRenderTime 74ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/user_guide/public/tinymce/jscripts/tiny_mce/plugins/ibrowser/scripts/rfiles.php

https://github.com/bwghughes/houghandco
PHP | 543 lines | 458 code | 22 blank | 63 comment | 84 complexity | 848f97ba1c042fe49af59755f6800911 MD5 | raw file
  1. <?php
  2. // ================================================
  3. // PHP image browser - iBrowser
  4. // ================================================
  5. // iBrowser dialog - file functions
  6. // ================================================
  7. // Developed: net4visions.com
  8. // Copyright: net4visions.com
  9. // License: GPL - see license.txt
  10. // (c)2005 All rights reserved.
  11. // ================================================
  12. // Revision: 1.0 Date: 09/11/2006
  13. // ================================================
  14. //-------------------------------------------------------------------------
  15. // include configuration settings
  16. include dirname(__FILE__) . '/../config/config.inc.php';
  17. include dirname(__FILE__) . '/../langs/lang.class.php';
  18. //-------------------------------------------------------------------------
  19. // language settings
  20. $l = (isset($_REQUEST['lang']) ? new PLUG_Lang($_REQUEST['lang']) : new PLUG_Lang($cfg['lang']));
  21. $l->setBlock('ibrowser');
  22. //-------------------------------------------------------------------------
  23. // parameters
  24. $param = (isset($_REQUEST['param']) ? $_REQUEST['param'] : '');
  25. if (isset($param)) {
  26. $param = explode('|', $param);
  27. }
  28. // set action
  29. $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : '');
  30. // set image library
  31. $clib = (isset($_REQUEST['clib']) ? $_REQUEST['clib'] : (isset($_REQUEST['ilibs']) ? $_REQUEST['ilibs'] : $cfg['ilibs'][0]['value']));
  32. // set current file
  33. $cfile = (isset($_REQUEST['cfile']) ? $_REQUEST['cfile'] : '');
  34. // set new file
  35. $nfile = (isset($_REQUEST['nfile']) ? $_REQUEST['nfile'] : '');
  36. // set list view
  37. $list = (isset($_REQUEST['flist']) ? $_REQUEST['flist'] : $cfg['list']);
  38. $list = false;
  39. //-------------------------------------------------------------------------
  40. // file/directory actions
  41. if ($param[0] == 'delete') { // ACTION: delete image
  42. $action = $param[0];
  43. $cfile = $param[1]; // current filename
  44. if(!deleteImg($clib, $cfile)) {
  45. echo $l->m('er_001') . ': ' . $l->m('er_030');
  46. };
  47. } else if ($param[0] == 'rename') { // ACTION: rename image
  48. $action = $param[0];
  49. $cfile = $param[1]; // current filename
  50. $nfile = $param[2]; // new filename
  51. if(!$nfile = renameImg($clib, $cfile, $nfile)) {
  52. echo $l->m('er_001') . ': ' . $l->m('er_033');
  53. };
  54. } else if ($param[0] == 'upload') { // ACTION: upload image
  55. $action = $param[0];
  56. $chkT = (isset($_REQUEST['chkThumbSize']) ? $_REQUEST['chkThumbSize'] : Array() ); // thumb-sizes in Array
  57. $selR = (isset($_REQUEST['selRotate']) ? $_REQUEST['selRotate'] : ''); // auto rotate
  58. if (isset($_FILES['nfile']['name'][0])) {
  59. if (!$nfile = uploadImg($clib, $chkT, $selR)) {
  60. echo $l->m('er_001') . ': ' . $l->m('er_028');
  61. }
  62. };
  63. } else if ($param[0] == 'create') { // ACTION: create directory
  64. $action = $param[0];
  65. $nfile = $param[1]; // new filename
  66. if(!createDir($clib, $nfile)) {
  67. echo $l->m('er_001') . ': ' . $l->m('er_034');
  68. };
  69. } else if ($param[0] == 'update') { // ACTION: update image list and select current image
  70. $action = $param[0];
  71. $cfile = $param[1]; // current filename
  72. } else if ($param[0] == 'switch') { // ACTION: switch image list view (list or thumbnails)
  73. $action = $param[0];
  74. $cfile = $param[1]; // current filename
  75. }
  76. ?>
  77. <!-- do not delete this line - it's need for proper working of the resizeDialogToContent() function -->
  78. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  79. <html xmlns="http://www.w3.org/1999/xhtml">
  80. <head>
  81. <title><?php echo $l->m('im_002'); ?></title>
  82. <meta http-equiv="Pragma" content="no-cache">
  83. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $l->getCharset(); ?>">
  84. <style type="text/css">
  85. <!--
  86. @import url("../css/style.css");
  87. html, body {
  88. margin: 0px;
  89. padding: 0px;
  90. }
  91. -->
  92. </style>
  93. <?php if ($list == false) { // thumbnail view ?>
  94. <style type="text/css">
  95. <!--
  96. div#iselDiv li {
  97. margin: 5px;
  98. padding: 5px;
  99. display: block;
  100. border: 1px solid #cccccc;
  101. float: left;
  102. }
  103. -->
  104. </style>
  105. <?php } else { // list view ?>
  106. <style type="text/css">
  107. <!--
  108. div#iselDiv li {
  109. margin: 0px;
  110. padding: 0px;
  111. display: block;
  112. padding-left: 5px;
  113. padding-right: 5px;
  114. }
  115. -->
  116. </style>
  117. <?php }; ?>
  118. <script language="JavaScript" type="text/JavaScript">
  119. <!--
  120. // ============================================================
  121. // = image list item V 1.0, date: 01/21/2005 =
  122. // ============================================================
  123. // list item hover
  124. function li_over() {
  125. if (this.className != 'cimgdown') {
  126. this.className = 'cimgover';
  127. }
  128. }
  129. // list item out
  130. function li_out() {
  131. if (this.className != 'cimgdown') {
  132. this.className = 'cimgup';
  133. }
  134. }
  135. // list item down
  136. function li_down() {
  137. if (this.className != 'cimgdown') {
  138. this.className = 'cimgdown';
  139. }
  140. }
  141. // list item click
  142. function li_click() {
  143. x = document.getElementById('iselDiv').getElementsByTagName('li');
  144. for (var i = 0; i < x.length; i++) {
  145. if (x[i].className == 'cimgdown') {
  146. if (x[i] != this) {
  147. x[i].className = 'cimgup';
  148. }
  149. }
  150. }
  151. imageChangeClick(this);
  152. }
  153. // ============================================================
  154. // = init filelist - set attributes V 1.0, date: 04/18/2005 =
  155. // ============================================================
  156. function init() {
  157. var formObj = document.forms[0];
  158. // init mouse events on image list <li>
  159. var x = document.getElementById('iselDiv').getElementsByTagName('li');
  160. for (var i = 0; i < x.length; i++) {
  161. if (x[i].className == 'cimgup') {
  162. x[i].onmouseover = li_over;
  163. x[i].onmouseout = li_out;
  164. x[i].onmousedown = li_down;
  165. x[i].onclick = li_click;
  166. }
  167. }
  168. // actions
  169. var action = formObj.action.value;
  170. if (action == 'upload') {
  171. var tfile = '<?php echo $nfile; ?>';
  172. getObject(tfile);
  173. self.parent.hideloadmessage();
  174. } else if (action == 'rename') {
  175. var tfile = '<?php echo $nfile; ?>';
  176. getObject(tfile);
  177. } else if (action == 'update') {
  178. var tfile = '<?php echo $cfile; ?>';
  179. getObject(tfile);
  180. } else if (action == 'switch') {
  181. var tfile = '<?php echo $cfile; ?>';
  182. getObject(tfile);
  183. } else if (action == 'delete') {
  184. imageChangeClick();
  185. } else if (formObj.action.value == 'create') {
  186. // parent needs to be refreshed if directory got created
  187. parent.document.location.reload();
  188. }
  189. }
  190. // ============================================================
  191. // = image change - set attributes V 1.0, date: 04/18/2005 =
  192. // ============================================================
  193. function imageChangeClick(obj) {
  194. var formObj = document.forms[0];
  195. var action = formObj.action.value;
  196. if (obj) {
  197. parent.document.getElementById('cimg').attributes['cfile'].value = obj.attributes['ifile'].value;
  198. parent.document.getElementById('cimg').attributes['csize'].value = obj.attributes['isize'].value;
  199. parent.document.getElementById('cimg').attributes['cheight'].value = obj.attributes['iheight'].value;
  200. parent.document.getElementById('cimg').attributes['cwidth'].value = obj.attributes['iwidth'].value;
  201. parent.document.getElementById('cimg').attributes['ctype'].value = obj.attributes['itype'].value;
  202. parent.document.getElementById('cimg').attributes['cmdate'].value = obj.attributes['imdate'].value;
  203. parent.document.getElementById('cimg').attributes['ccdate'].value = obj.attributes['icdate'].value;
  204. }
  205. self.parent.imageChange(action);
  206. formObj.action.value = null; // resetting action status
  207. }
  208. // ============================================================
  209. // = get current file - set attrib V 1.0, date: 04/18/2005 =
  210. // ============================================================
  211. function getObject(tfile) {
  212. var x = document.getElementById('iselDiv').getElementsByTagName('li');
  213. for (var i = 0; i < x.length; i++) {
  214. if (x[i].attributes['ifile'].value == tfile) {
  215. x[i].className = 'cimgdown';
  216. imageChangeClick(x[i]);
  217. }
  218. }
  219. }
  220. // ============================================================
  221. // = load/hide message, date: 02/08/2005 =
  222. // ============================================================
  223. function hideloadmessage() {
  224. document.getElementById('dialogLoadMessage').style.display = 'none'
  225. }
  226. -->
  227. </script>
  228. <title>Image list</title>
  229. <meta http-equiv="Pragma" content="no-cache">
  230. <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $l->getCharset(); ?>">
  231. </head>
  232. <body onload="init(); hideloadmessage();" dir="<?php echo $l->getDir(); ?>">
  233. <?php include 'loadmsg.php'; ?>
  234. <form id="rfiles" name="rfiles" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" target="_self">
  235. <input type="hidden" name="lang" value="<?php echo $l->lang; ?>" />
  236. <input type="hidden" id= "action" name="action" value="<?php echo $action; ?>" />
  237. <div id="iselDiv">
  238. <ul>
  239. <?php echo getItems($cfg['root_dir'] . $clib, $cfg['valid'], $list); ?>
  240. </ul>
  241. </div>
  242. </form>
  243. </body>
  244. </html>
  245. <?php
  246. // get images
  247. function getItems($path, $valid, $list) {
  248. global $cfg;
  249. global $l;
  250. $path = str_replace('//','/', $path); // remove double slash in path if any
  251. $retstr = '';
  252. if ($handle = @opendir($path)) {
  253. $files = array();
  254. $valids = implode('|', $valid);
  255. while (($file = readdir($handle)) !== false) {
  256. if (is_file($path . $file) && eregi('\.(' . $valids . ')$', $file, $matches)) {
  257. $files[$path . $file] = $matches[0];
  258. }
  259. }
  260. closedir($handle);
  261. ksort($files);
  262. $dfmt = "m-d-Y";
  263. foreach ($files as $filename => $ext) {
  264. $size = @getimagesize($path . basename($filename));
  265. if( $size === false ) {
  266. continue;
  267. }
  268. $fsize = filesize($path . basename($filename));
  269. $modified = date($dfmt, filemtime($path . basename($filename)));
  270. $created = date($dfmt, filectime($path . basename($filename)));
  271. $ctype = iType($size[2]);
  272. if ($list == true || $list == 1) {
  273. $retstr .= '<li class="cimgup" ifile="' . basename($filename) . '" iwidth="' . htmlentities($size[0], ENT_QUOTES) . '" iheight="' . htmlentities($size[1], ENT_QUOTES) . '" itype="' . htmlentities($size[2] . '|' . $ctype, ENT_QUOTES) . '" imdate="' . htmlentities($modified, ENT_QUOTES) . '" icdate="' . htmlentities($created, ENT_QUOTES) . '" isize="' .filesize_h($fsize,2) . '">' . htmlentities(basename($filename), ENT_QUOTES,$l->getCharset()) . '</li>' . "\n";
  274. } else {
  275. $src = 'phpThumb/phpThumb.php?src=' . absPath(str_replace($cfg['root_dir'],'', $path)) . basename($filename) . '&w=48&h=48&far=1&bg=ffffff&f=jpg';
  276. $retstr .= '<li class="cimgup" ifile="' . basename($filename) . '" iwidth="' . htmlentities($size[0], ENT_QUOTES) . '" iheight="' . htmlentities($size[1], ENT_QUOTES) . '" itype="' . htmlentities($size[2] . '|' . $ctype, ENT_QUOTES) . '" imdate="' . htmlentities($modified, ENT_QUOTES) . '" icdate="' . htmlentities($created, ENT_QUOTES) . '" isize="' .filesize_h($fsize,2) . '">' . '<img src="' . $src . '" width="48" height="48" alt="' . basename($filename) . '; ' . htmlentities($size[0], ENT_QUOTES) . ' x ' . htmlentities($size[1], ENT_QUOTES) . 'px;' . '" title="' . basename($filename) . '; ' . htmlentities($size[0], ENT_QUOTES) . ' x ' . htmlentities($size[1], ENT_QUOTES) . 'px;' . '"/>' . '</li>' . "\n";
  277. }
  278. }
  279. return $retstr;
  280. }
  281. echo $l->m('er_036');
  282. return false;
  283. }
  284. // get image types
  285. function iType($type) {
  286. switch ($type) {
  287. case 1:
  288. $str = 'GIF'; break;
  289. case 2:
  290. $str = 'JPG'; break;
  291. case 3:
  292. $str = 'PNG'; break;
  293. case 4:
  294. $str = 'SWF'; break;
  295. case 5:
  296. $str = 'PSD'; break;
  297. case 6:
  298. $str = 'BMP'; break;
  299. case 7:
  300. $str = 'TIFF'; break;
  301. case 8:
  302. $str = 'TIFF'; break;
  303. case 15:
  304. $str = 'WBMP'; break;
  305. default:
  306. $str = 'n/a'; break;
  307. }
  308. return $str;
  309. }
  310. //-------------------------------------------------------------------------
  311. // Return the human readable size of a file
  312. // @param int $size a file size
  313. // @param int $dec a number of decimal places
  314. function filesize_h($size, $dec = 1) {
  315. $sizes = array('b', 'kb', 'mb', 'gb');
  316. $count = count($sizes);
  317. $i = 0;
  318. while ($size >= 1024 && ($i < $count - 1)) {
  319. $size /= 1024;
  320. $i++;
  321. }
  322. return round($size, $dec) . '|' . $sizes[$i];
  323. }
  324. //-------------------------------------------------------------------------
  325. // delete image
  326. function deleteImg($clib, $cfile) {
  327. global $cfg;
  328. global $l;
  329. if (!$cfg['delete']) {
  330. return false;
  331. }
  332. $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path
  333. return @unlink($path . $cfile); // returns true or false
  334. }
  335. //-------------------------------------------------------------------------
  336. // rename image
  337. function renameImg($clib, $cfile, $nfile) {
  338. global $cfg;
  339. global $l;
  340. if (!$cfg['rename']) {
  341. return false;
  342. }
  343. // check new file extension
  344. $ext = strtolower(substr($nfile,strrpos($nfile, '.')+1));
  345. if (!in_array($ext, $cfg['valid'])) { // invalid image / file extension
  346. echo $l->m('er_029');
  347. return false;
  348. }
  349. $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path
  350. if (file_exists($path . $cfile)) {
  351. $nfile = fixFileName($nfile); // remove invalid characters in file name
  352. $nfile = chkFileName($path, $nfile); // rename if file already exists
  353. @rename($path . $cfile, $path . $nfile);
  354. return $nfile;
  355. }
  356. return false;
  357. }
  358. //-------------------------------------------------------------------------
  359. // create directory
  360. function createDir($clib, $nfile) {
  361. global $cfg;
  362. global $l;
  363. if (!$cfg['create']) {
  364. return false;
  365. }
  366. $nfile = fixFileName($nfile);
  367. $tfile = $nfile;
  368. $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path
  369. // renaming directory if it already exists
  370. // keep looping and incrementing _i filenumber until a non-existing one is found
  371. $i = 1;
  372. while (file_exists($path . $nfile)) {
  373. $nfile = $tfile . '_' . $i;
  374. $i++;
  375. }
  376. $perm = 0777;
  377. $oumask = umask(0);
  378. umask();
  379. if(@mkdir($path . $nfile, $perm)) {
  380. umask($oumask);
  381. return true;
  382. }
  383. umask($oumask);
  384. return false;
  385. }
  386. //-------------------------------------------------------------------------
  387. // upload image
  388. function uploadImg($clib, $chkT, $selR) {
  389. global $cfg;
  390. global $l;
  391. if (!$cfg['upload']) {
  392. return false;
  393. }
  394. foreach ($_FILES['nfile']['size'] as $key => $size) {
  395. if ($size > 0) {
  396. // get file extension and check for validity
  397. $ext = pathinfo($_FILES['nfile']['name'][$key]);
  398. $ext = strtolower($ext['extension']);
  399. if (!in_array($ext, $cfg['valid'])) { // invalid image
  400. echo $l->m('er_029');
  401. return false;
  402. }
  403. $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path
  404. $nfile = fixFileName($_FILES['nfile']['name'][$key]); // remove invalid characters in filename
  405. // move file to temp directory for processing
  406. if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $cfg['temp'] . '/' . $nfile)) { // upload image to temp dir
  407. echo $l->m('er_028');
  408. return false;
  409. }
  410. $size = getimagesize($cfg['temp'] . '/' . $nfile);
  411. // process (thumbnail) images
  412. $arr = $cfg['thumbs'];
  413. foreach($arr as $key => $thumb) {
  414. if (in_array($key, $chkT)) {
  415. // create new phpThumb() object
  416. require_once(dirname(__FILE__) . '/phpThumb/phpthumb.class.php');
  417. $phpThumb = new phpThumb(); // create object
  418. // parameters
  419. $phpThumb->config_cache_disable_warning = true; // disable cache warning
  420. $phpThumb->config_output_format = $ext; // output format
  421. $phpThumb->src = $cfg['temp'] . '/' . $nfile; // destination
  422. $phpThumb->q = 95; // compression level for jpeg
  423. if ($selR != '') { // set auto rotate
  424. $phpThumb->ar = $selR;
  425. };
  426. //-------------------------------------------------------------------------
  427. if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) { // size value is set -> RESIZING and source image is larger than preset sizes
  428. // resize parameters
  429. if ($size[0] < $size[1]) { // portrait
  430. $phpThumb->h = $thumb['size']; // max. height
  431. } else {
  432. $phpThumb->w = $thumb['size']; // max. width
  433. }
  434. // crop parameters
  435. if($thumb['crop'] == true) {
  436. $phpThumb->zc = 1; // set zoom crop
  437. $phpThumb->w = $thumb['size']; // width
  438. $phpThumb->h = $thumb['size']; // height
  439. }
  440. // create file suffix
  441. if ($thumb['ext'] == '*') { // image size is used
  442. $dim = '_' . $thumb['size']; // e.g. _1280
  443. } else if ($thumb['ext'] == '') { // no suffix is created
  444. $dim = '';
  445. } else { // suffix is set to $thumb['ext']
  446. $dim = '_'. $thumb['ext'];
  447. }
  448. //-------------------------------------------------------------------------
  449. } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') { // size value is set to '0' -> NO RESIZING
  450. // crop parameters
  451. if ($thumb['crop'] == true) {
  452. $phpThumb->zc = 1; // set zoom crop
  453. if($size[0] < $size[1]) { // portrait
  454. $phpThumb->w = $size[0]; // getimagesize width value
  455. $phpThumb->h = $size[0]; // getimagesize width value
  456. } else { // landscape
  457. $phpThumb->w = $size[1]; // getimagesize height value
  458. $phpThumb->h = $size[1]; // getimagesize height value
  459. }
  460. }
  461. // create file suffix
  462. if ($thumb['ext'] == '*') { // image size is used
  463. $dim = '_' . (($size[0] <= $size[1]) ? $size[1] : $size[0]); // source height or width - e.g. _1280
  464. } else if ($thumb['ext'] == '') { // no suffix is created
  465. $dim = '';
  466. } else { // suffix is set to $thumb['ext']
  467. $dim = '_'. $thumb['ext'];
  468. }
  469. //-------------------------------------------------------------------------
  470. } else { // default setting - images smaller than predefined sizes
  471. $dim = ''; // no file suffix is used
  472. }
  473. //-------------------------------------------------------------------------
  474. $nthumb = fixFileName(basename($nfile, '.' . $ext) . $dim . '.' . $ext);
  475. $nthumb = chkFileName($path, $nthumb); // rename if file already exists
  476. if ($phpThumb->GenerateThumbnail()) {
  477. $phpThumb->RenderToFile($path . $nthumb);
  478. @chmod($path . $nthumb, 0755) or die($l->m('er_028'));
  479. } else { // error
  480. echo $l->m('er_028');
  481. return false;
  482. }
  483. unset($phpThumb);
  484. }
  485. }
  486. @unlink($cfg['temp'] . '/' . $nfile); // delete temporary file
  487. }
  488. }
  489. return $nthumb;
  490. }
  491. //-------------------------------------------------------------------------
  492. // escape and clean up file name (only lowercase letters, numbers and underscores are allowed)
  493. function fixFileName($file) {
  494. $file = ereg_replace("[^a-z0-9._-]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($file))));
  495. return $file;
  496. }
  497. //-------------------------------------------------------------------------
  498. // check whether file already exists; rename file if filename already exists
  499. // keep looping and incrementing _i filenumber until a non-existing filename is found
  500. function chkFileName($path, $nfile) {
  501. $tfile = $nfile;
  502. $i = 1;
  503. while (file_exists($path . $nfile)) {
  504. $nfile = ereg_replace('(.*)(\.[a-zA-Z]+)$', '\1_' . sprintf('%02d',$i) . '\2', $tfile);
  505. $i++;
  506. }
  507. return $nfile;
  508. }
  509. // ============================================================
  510. // = abs path - add slashes V 1.0, date: 05/10/2005 =
  511. // ============================================================
  512. function absPath($path) {
  513. if(substr($path,-1) != '/') $path .= '/';
  514. if(substr($path,0,1) != '/') $path = '/' . $path;
  515. return $path;
  516. }
  517. ?>