PageRenderTime 32ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/storecommander/ead6f6fce09/SC/lib/js/ckeditor/kcfinder/lib/helper_dir.php

https://gitlab.com/ptisky/API_prestashop
PHP | 179 lines | 101 code | 25 blank | 53 comment | 35 complexity | 96cf7b11a019d361c147a7f217a8d798 MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2015-09-15
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2015-09-15 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6.1
  21. *
  22. **/
  23. /** This file is part of KCFinder project
  24. *
  25. * @desc Directory helper class
  26. * @package KCFinder
  27. * @version 3.12
  28. * @author Pavel Tzonkov <sunhater@sunhater.com>
  29. * @copyright 2010-2014 KCFinder Project
  30. * @license http://opensource.org/licenses/GPL-3.0 GPLv3
  31. * @license http://opensource.org/licenses/LGPL-3.0 LGPLv3
  32. * @link http://kcfinder.sunhater.com
  33. */
  34. namespace kcfinder;
  35. class dir {
  36. /** Checks if the given directory is really writable. The standard PHP
  37. * function is_writable() does not work properly on Windows servers
  38. * @param string $dir
  39. * @return bool */
  40. static function isWritable($dir) {
  41. $dir = path::normalize($dir);
  42. if (!is_dir($dir))
  43. return false;
  44. $i = 0;
  45. do {
  46. $file = "$dir/is_writable_" . md5($i++);
  47. } while (file_exists($file));
  48. if (!@touch($file))
  49. return false;
  50. unlink($file);
  51. return true;
  52. }
  53. /** Recursively delete the given directory. Returns TRUE on success.
  54. * If $firstFailExit parameter is true (default), the method returns the
  55. * path to the first failed file or directory which cannot be deleted.
  56. * If $firstFailExit is false, the method returns an array with failed
  57. * files and directories which cannot be deleted. The third parameter
  58. * $failed is used for internal use only.
  59. * @param string $dir
  60. * @param bool $firstFailExit
  61. * @param array $failed
  62. * @return mixed */
  63. static function prune($dir, $firstFailExit=true, array $failed=null) {
  64. if ($failed === null) $failed = array();
  65. $files = self::content($dir);
  66. if ($files === false) {
  67. if ($firstFailExit)
  68. return $dir;
  69. $failed[] = $dir;
  70. return $failed;
  71. }
  72. foreach ($files as $file) {
  73. if (is_dir($file)) {
  74. $failed_in = self::prune($file, $firstFailExit, $failed);
  75. if ($failed_in !== true) {
  76. if ($firstFailExit)
  77. return $failed_in;
  78. if (is_array($failed_in))
  79. $failed = array_merge($failed, $failed_in);
  80. else
  81. $failed[] = $failed_in;
  82. }
  83. } elseif (!@unlink($file)) {
  84. if ($firstFailExit)
  85. return $file;
  86. $failed[] = $file;
  87. }
  88. }
  89. if (!@rmdir($dir)) {
  90. if ($firstFailExit)
  91. return $dir;
  92. $failed[] = $dir;
  93. }
  94. return count($failed) ? $failed : true;
  95. }
  96. /** Get the content of the given directory. Returns an array with filenames
  97. * or FALSE on failure
  98. * @param string $dir
  99. * @param array $options
  100. * @return mixed */
  101. static function content($dir, array $options=null) {
  102. $defaultOptions = array(
  103. 'types' => "all", // Allowed: "all" or possible return values
  104. // of filetype(), or an array with them
  105. 'addPath' => true, // Whether to add directory path to filenames
  106. 'pattern' => '/./', // Regular expression pattern for filename
  107. 'followLinks' => true
  108. );
  109. if (!is_dir($dir) || !is_readable($dir))
  110. return false;
  111. if (strtoupper(substr(PHP_OS, 0, 3)) == "WIN")
  112. $dir = str_replace("\\", "/", $dir);
  113. $dir = rtrim($dir, "/");
  114. $dh = @opendir($dir);
  115. if ($dh === false)
  116. return false;
  117. if ($options === null)
  118. $options = $defaultOptions;
  119. foreach ($defaultOptions as $key => $val)
  120. if (!isset($options[$key]))
  121. $options[$key] = $val;
  122. $files = array();
  123. while (($file = @readdir($dh)) !== false) {
  124. if (($file == '.') || ($file == '..') ||
  125. !preg_match($options['pattern'], $file)
  126. )
  127. continue;
  128. $fullpath = "$dir/$file";
  129. $type = filetype($fullpath);
  130. // If file is a symlink, get the true type of its destination
  131. if ($options['followLinks'] && ($type == "link"))
  132. $type = filetype(realpath($fullpath));
  133. if (($options['types'] === "all") || ($type === $options['types']) ||
  134. (is_array($options['types']) && in_array($type, $options['types']))
  135. )
  136. $files[] = $options['addPath'] ? $fullpath : $file;
  137. }
  138. closedir($dh);
  139. usort($files, array(__NAMESPACE__ . "\\dir", "fileSort"));
  140. return $files;
  141. }
  142. static function fileSort($a, $b) {
  143. if (function_exists("mb_strtolower")) {
  144. $a = mb_strtolower($a);
  145. $b = mb_strtolower($b);
  146. } else {
  147. $a = strtolower($a);
  148. $b = strtolower($b);
  149. }
  150. if ($a == $b) return 0;
  151. return ($a < $b) ? -1 : 1;
  152. }
  153. }
  154. ?>