PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/html/modules/fileManager/admin/include/functions.php

http://xoopscube-modules.googlecode.com/
PHP | 224 lines | 158 code | 22 blank | 44 comment | 28 complexity | 948f29fb3726e714a7370311b983f958 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  1. <?php
  2. /**
  3. * Filemaneger
  4. * (C)2007-2009 BeaBo Japan by Hiroki Seike
  5. * http://beabo.net/
  6. **/
  7. if (!defined('XOOPS_ROOT_PATH')) exit();
  8. // template header module infomation
  9. function getModuleInfo() {
  10. $moduleHader = array();
  11. $root =& XCube_Root::getSingleton();
  12. $moduleHader['module_id'] = $root->mContext->mXoopsModule->getvar('mid');
  13. $moduleHader['module_name'] = $root->mContext->mXoopsModule->get('name');
  14. $moduleHader['module_path'] = $root->mContext->mXoopsModule->get('dirname');
  15. return $moduleHader;
  16. }
  17. // get XCL system using images for hide files
  18. function getSyetemImages($hideFile) {
  19. $root =& XCube_Root::getSingleton();
  20. // image
  21. $root->mController->executeHeader();
  22. $handler =& xoops_getmodulehandler('image','legacy');
  23. $mObjects =& $handler->getObjects();
  24. foreach ($mObjects as $key => $val) {
  25. foreach ( array_keys($val->gets()) as $var_name ) {
  26. $hideFile[] = $val->getShow('image_name');
  27. }
  28. }
  29. // smailes
  30. $handler =& xoops_getmodulehandler('smiles','legacy');
  31. $mObjects =& $handler->getObjects();
  32. foreach ($mObjects as $key => $val) {
  33. foreach ( array_keys($val->gets()) as $var_name ) {
  34. $hideFile[] = $val->getShow('smile_url');
  35. }
  36. }
  37. // user users
  38. $handler =& xoops_getmodulehandler('users','user');
  39. $mCriteria =new CriteriaCompo();
  40. $mCriteria->add(new Criteria('user_avatar', 'blank.gif','<>' ));
  41. $mObjects =$handler->getObjects($mCriteria);
  42. foreach ($mObjects as $key => $val) {
  43. foreach ( array_keys($val->gets()) as $var_name ) {
  44. $hideFile[] = $val->getShow('user_avatar');
  45. }
  46. }
  47. // user ranks
  48. $handler =& xoops_getmodulehandler('ranks','user');
  49. $mObjects =& $handler->getObjects();
  50. foreach ($mObjects as $key => $val) {
  51. foreach ( array_keys($val->gets()) as $var_name ) {
  52. $hideFile[] = $val->getShow('rank_image');
  53. }
  54. }
  55. // user avater
  56. $handler =& xoops_getmodulehandler('avatar','user');
  57. $mObjects =& $handler->getObjects();
  58. foreach ($mObjects as $key => $val) {
  59. foreach ( array_keys($val->gets()) as $var_name ) {
  60. $hideFile[] = $val->getShow('avatar_file');
  61. }
  62. }
  63. return $hideFile;
  64. }
  65. // FileSystemUtilty is filepath , filename utility
  66. Class FileSystemUtilty {
  67. // base -> http://labs.uechoco.com/blog/2007/08/page/2
  68. // get file size
  69. function bytes($filesize) {
  70. if (!$filesize) {
  71. return null;
  72. }
  73. $unim = array("Bytes","KB","MB","GB","TB","PB");
  74. $count = 0;
  75. while ($filesize>=1024) {
  76. $count++;
  77. $filesize = $filesize/1024;
  78. }
  79. return number_format($filesize,($count ? 2 : 0),".",",")." ".$unim[$count];
  80. }
  81. // NOT USE
  82. // get_file_size is set direct file
  83. function get_file_size($filename) {
  84. if (!file_exists($filename)) {
  85. return null;
  86. }
  87. $size = filesize($filename);
  88. $sizes = array('Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
  89. $ext = $sizes[0];
  90. for ($i=1; (($i <count($sizes)) && ($size>= 1024)); $i++) {
  91. $size = $size / 1024;
  92. $ext = $sizes[$i];
  93. }
  94. return round($size, 2). $ext;
  95. }
  96. // check dirctory name and permission
  97. function checkFolder($folderPath='') {
  98. $isWriteble = false; // default
  99. if ($folderPath!='') {
  100. // is exists ?
  101. if (!file_exists($folderPath)) {
  102. return false;
  103. }
  104. // is directory ?
  105. if (!is_dir($folderPath)) {
  106. return false;
  107. }
  108. // directory permission is 777 ?
  109. if ( fileperms($folderPath) == '16895') {
  110. return true;
  111. }
  112. } else {
  113. return false;
  114. }
  115. }
  116. // NOT USE
  117. // file name check
  118. function is_filename($text) {
  119. if (preg_match("/^[a-zA-Z0-9_~\-]+$/",$text)) {
  120. return true;
  121. } else {
  122. return false;
  123. }
  124. }
  125. // file name
  126. function getFileName($fileName='') {
  127. $fileNameCount = strlen($fileName) - strlen(strrchr( $fileName, "." )) ;
  128. return substr($fileName, 0, $fileNameCount);
  129. }
  130. // file extension
  131. function getFileExtension($fileName='') {
  132. return substr( strrchr( $fileName, "." ), 1);
  133. }
  134. // get folder List
  135. //
  136. // $dirpath ?AgfBNg??pX???pXBK?XbV?svB
  137. // $invisible : check invisible files (s?t@CXg???)
  138. function getDirlLst($dirpath='' , $invisible = true ){
  139. if ( strcmp($dirpath,'')==0 ) {
  140. $file_list = array();
  141. $dir_list = array();
  142. if( ($dir = @opendir($dirpath) ) == FALSE ) {
  143. die( "dir {$dirpath} not found.");
  144. }
  145. while ( ($file=readdir( $dir )) !== FALSE ){
  146. if ( is_dir( "$dirpath/$file" ) ){
  147. if( strpos( $file ,'.' ) !== 0 ){
  148. $dir_list["$file"] = getdirlist( "$dirpath/$file" , $invisible );
  149. }
  150. }else {
  151. if( $invisible ){
  152. array_push($file_list, $file);
  153. }else{
  154. if( strpos( $file , '.' )!==0 ) array_push( $file_list , $file);
  155. }
  156. }
  157. }
  158. return array( "file"=>$file_list , "dir"=>$dir_list);
  159. } else {
  160. return false;
  161. }
  162. }
  163. // NOT USE
  164. // make new file name
  165. // check file name and length
  166. function getNewFileName($fileName = '',$maxLength = 200 ){
  167. // filename is null
  168. if (is_null($fileName)) {
  169. return false;
  170. }
  171. // Allowed file extensions
  172. $extension_whitelist = "flv|avi|mwv|mov|MOV|mpg|qt|mov|3gp|3gp2|mp4";
  173. $fileName = htmlSpecialChars(trim($fileName), ENT_QUOTES );
  174. // trim path name
  175. $baseFaileName = basename($fileName);
  176. // replace word 'x'
  177. $newFileName = preg_replace('/[^.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-]|\.+$/i', "x", $baseFaileName);
  178. // get extension
  179. $fileExtension = substr( strrchr( $newFileName, "." ), 1);
  180. // extension type check
  181. if ( ereg("[ \t]",$fileExtension) or is_null($fileExtension)) {
  182. // extension is tab or space or null
  183. return false;
  184. } else {
  185. if (!eregi($extension_whitelist, $fileExtension)) {
  186. // extension is no math white list
  187. return false;
  188. }
  189. }
  190. // file name length check
  191. if (strlen($newFileName) > $maxLength) {
  192. // rename file name
  193. $trimName = substr($newFileName, 0, strlen($newFileName) - strlen(strrchr( $newFileName, "." )));
  194. // trim to timestamp space
  195. $trimName = substr($trimName , 0 ,$maxLength - 13);
  196. // insert timestamp
  197. $newFileName = $trimName. "_". date("YmdHi"). '.'. $fileExtension;
  198. }
  199. return $newFileName;
  200. }
  201. }
  202. ?>