PageRenderTime 23ms CodeModel.GetById 37ms RepoModel.GetById 0ms app.codeStats 0ms

/core/components/janitor/model/janitor/libraries/linkchecker/path.php

https://github.com/shamblett/janitor
PHP | 269 lines | 240 code | 20 blank | 9 comment | 37 complexity | e42230feaefef2dfcbafd7c95bd20b84 MD5 | raw file
  1. <?php
  2. // Path Class
  3. // Scriptol - (c) 2001-2008 Denis Sureau
  4. // www.scriptol.com
  5. // Licence: OSS
  6. // This is a set of static functions related to files in directory
  7. // The path separator is "/" under Unix and Windows
  8. //
  9. // Modified for use in the Janitor 3PC for MODx Revolution
  10. // S. Hamblett Sep 2010
  11. class Path
  12. {
  13. function exists($dname)
  14. {
  15. return file_exists($dname);
  16. }
  17. function size($fname)
  18. {
  19. return filesize($fname);
  20. }
  21. function type($fname)
  22. {
  23. return filetype($fname);
  24. }
  25. function created($fname)
  26. {
  27. $t=filemtime($fname);
  28. return date("",$t);
  29. }
  30. function isFile($fname)
  31. {
  32. return filetype($fname)==="file";
  33. }
  34. function isDir($fname)
  35. {
  36. $t=filetype($fname);
  37. if($t==="link")
  38. {
  39. return false;
  40. }
  41. if($t!="dir")
  42. {
  43. return false;
  44. }
  45. return true;
  46. }
  47. function ren($oldname,$newname)
  48. {
  49. $b=true;
  50. rename($oldname,$newname);
  51. return $b;
  52. }
  53. function erase($fname)
  54. {
  55. return unlink($fname);
  56. }
  57. static function merge($path,$filename)
  58. {
  59. if($path==="")
  60. {
  61. return $filename;
  62. }
  63. if($filename==="")
  64. {
  65. return $path;
  66. }
  67. if(($path{strlen($path)-1}!="/")&&($filename{0}!="/"))
  68. {
  69. if(($path{strlen($path)-1}!="\\")&&($filename{0}!="\\"))
  70. {
  71. $path.="/";
  72. }
  73. }
  74. return $path.$filename;
  75. }
  76. function make($name)
  77. {
  78. return mkdir($name);
  79. }
  80. function splitExt($path)
  81. {
  82. $l=strlen($path);
  83. if($l===0)
  84. {
  85. return array("","");
  86. }
  87. for($x=$l-1;$x>=0;$x+=-1)
  88. {
  89. if($path{$x}===".")
  90. {
  91. return array(substr($path,0,$x),substr($path,$x+1));
  92. }
  93. }
  94. return array($path,"");
  95. }
  96. var $nullarr=array();
  97. function hasExtension($path,$extlist=array())
  98. {
  99. $extension="";
  100. $aext="";
  101. $i=0;
  102. $l=strlen($path);
  103. for($i=$l-1;$i>=0;$i+=-1)
  104. {
  105. if($path{$i}===".")
  106. {
  107. $extension=substr($path,$i+1);
  108. break;
  109. }
  110. }
  111. if($i>0)
  112. {
  113. if($extlist!=false)
  114. {
  115. return true;
  116. }
  117. $extension=substr($path,$i+1);
  118. reset($extlist);
  119. do
  120. {
  121. $aext=trim(strval(current($extlist)));
  122. if(strlen($aext)<1)
  123. {
  124. continue;
  125. }
  126. $i=0;
  127. if($aext{0}===".")
  128. {
  129. $i=1;
  130. }
  131. if(($i>0)&&(strlen($aext)===1))
  132. {
  133. continue;
  134. }
  135. if($extension===substr($aext,$i))
  136. {
  137. return true;
  138. }
  139. }
  140. while(!(next($extlist)===false));
  141. }
  142. return false;
  143. }
  144. static function getExtension($path)
  145. {
  146. $ext=strrchr($path,".");
  147. if($ext!=false)
  148. {
  149. return $ext;
  150. }
  151. return "";
  152. }
  153. function changeExt($path,$newext)
  154. {
  155. $l=strlen($path);
  156. if($l===0)
  157. {
  158. return $newext;
  159. }
  160. for($x=$l-1;$x>=0;$x+=-1)
  161. {
  162. if($path{$x}===".")
  163. {
  164. $path=substr($path,0,$x);
  165. break;
  166. }
  167. }
  168. if(strlen($newext)>0)
  169. {
  170. if($newext{0}!=".")
  171. {
  172. $newext=".".$newext;
  173. }
  174. }
  175. return $path.$newext;
  176. }
  177. function hasDir($path)
  178. {
  179. $l=strlen($path);
  180. if($l===0)
  181. {
  182. return false;
  183. }
  184. if($l>1)
  185. {
  186. if($path{1}===":")
  187. {
  188. return true;
  189. }
  190. }
  191. if(strpos($path,"/")!=false)
  192. {
  193. return true;
  194. }
  195. if(strpos($path,"\\")!=false)
  196. {
  197. return true;
  198. }
  199. return false;
  200. }
  201. function splitFile($path)
  202. {
  203. $l=strlen($path);
  204. if($l===0)
  205. {
  206. return array("","");
  207. }
  208. for($x=$l-1;$x>=0;$x+=-1)
  209. {
  210. if(($path{$x}==="/")||($path{$x}==="\\"))
  211. {
  212. return array(substr($path,0,$x+1),substr($path,$x+1));
  213. }
  214. }
  215. return array("",$path);
  216. }
  217. function getDir()
  218. {
  219. return getcwd();
  220. }
  221. function compare($a,$b)
  222. {
  223. $l=strlen($a);
  224. if($l!=strlen($b))
  225. {
  226. return false;
  227. }
  228. for($i=0;$i<$l;$i++)
  229. {
  230. if(($a{$i}==="\\")||($a{$i}==="/"))
  231. {
  232. if($b{$i}==="/")
  233. {
  234. continue;
  235. }
  236. if($b{$i}==="\\")
  237. {
  238. continue;
  239. }
  240. return false;
  241. }
  242. if($a{$i}!=$b{$i})
  243. {
  244. return false;
  245. }
  246. }
  247. return true;
  248. }
  249. }